From 14909f6c2f742dee09d74d37d53927bb941c4643 Mon Sep 17 00:00:00 2001 From: Grzegorz Piwowarek Date: Fri, 14 Apr 2017 11:26:51 +0200 Subject: [PATCH 01/19] Refactor ContactInfoValidator (#1647) * Refactor ContactInfoValidator * Refactor ContactInfoValidator --- .../ContactInfoValidator.java | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/spring-boot/src/main/java/com/baeldung/dynamicvalidation/ContactInfoValidator.java b/spring-boot/src/main/java/com/baeldung/dynamicvalidation/ContactInfoValidator.java index 53fb418ad6..81345eac83 100644 --- a/spring-boot/src/main/java/com/baeldung/dynamicvalidation/ContactInfoValidator.java +++ b/spring-boot/src/main/java/com/baeldung/dynamicvalidation/ContactInfoValidator.java @@ -1,16 +1,14 @@ package com.baeldung.dynamicvalidation; -import java.util.regex.Pattern; - -import javax.validation.ConstraintValidator; -import javax.validation.ConstraintValidatorContext; - +import com.baeldung.dynamicvalidation.dao.ContactInfoExpressionRepository; +import com.baeldung.dynamicvalidation.model.ContactInfoExpression; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.thymeleaf.util.StringUtils; -import com.baeldung.dynamicvalidation.dao.ContactInfoExpressionRepository; -import com.baeldung.dynamicvalidation.model.ContactInfoExpression; +import javax.validation.ConstraintValidator; +import javax.validation.ConstraintValidatorContext; +import java.util.regex.Pattern; public class ContactInfoValidator implements ConstraintValidator { @@ -26,12 +24,15 @@ public class ContactInfoValidator implements ConstraintValidator Pattern.matches(p, value)) + .orElse(false); } } From 389927d901394d13cb6e1db3d14fd3a50206b99b Mon Sep 17 00:00:00 2001 From: Anton Date: Sat, 15 Apr 2017 04:40:39 +0300 Subject: [PATCH 02/19] BAEL-748 quick guide to @Value (#1577) * BAEL-748 quick guide to @Value * BAEL-748 changes from review --- .../java/com/baeldung/value/SomeBean.java | 17 +++++ .../java/com/baeldung/value/ValuesApp.java | 68 +++++++++++++++++++ .../src/main/resources/values.properties | 3 + 3 files changed, 88 insertions(+) create mode 100644 spring-core/src/main/java/com/baeldung/value/SomeBean.java create mode 100644 spring-core/src/main/java/com/baeldung/value/ValuesApp.java create mode 100644 spring-core/src/main/resources/values.properties diff --git a/spring-core/src/main/java/com/baeldung/value/SomeBean.java b/spring-core/src/main/java/com/baeldung/value/SomeBean.java new file mode 100644 index 0000000000..39d5245049 --- /dev/null +++ b/spring-core/src/main/java/com/baeldung/value/SomeBean.java @@ -0,0 +1,17 @@ +package com.baeldung.value; + +public class SomeBean { + private int someValue; + + public SomeBean(int someValue) { + this.someValue = someValue; + } + + public int getSomeValue() { + return someValue; + } + + public void setSomeValue(int someValue) { + this.someValue = someValue; + } +} diff --git a/spring-core/src/main/java/com/baeldung/value/ValuesApp.java b/spring-core/src/main/java/com/baeldung/value/ValuesApp.java new file mode 100644 index 0000000000..25f4b9fb9c --- /dev/null +++ b/spring-core/src/main/java/com/baeldung/value/ValuesApp.java @@ -0,0 +1,68 @@ +package com.baeldung.value; + +import java.util.List; + +import javax.annotation.PostConstruct; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.ApplicationContext; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.PropertySource; + +@Configuration +@PropertySource(name = "myProperties", value = "values.properties") +public class ValuesApp { + + @Value("string value") + private String stringValue; + + @Value("${value.from.file}") + private String valueFromFile; + + @Value("${systemValue}") + private String systemValue; + + @Value("${unknown_param:some default}") + private String someDefault; + + @Value("${priority}") + private String prioritySystemProperty; + + @Value("#{systemProperties['priority']}") + private String spelValue; + + @Value("#{systemProperties['unknown'] ?: 'some default'}") + private String spelSomeDefault; + + @Value("#{someBean.someValue}") + private Integer someBeanValue; + + @Value("#{'${listOfValues}'.split(',')}") + private List valuesList; + + public static void main(String[] args) { + System.setProperty("systemValue", "Some system parameter value"); + System.setProperty("priority", "System property"); + ApplicationContext applicationContext = new AnnotationConfigApplicationContext(ValuesApp.class); + } + + @Bean + public SomeBean someBean() { + return new SomeBean(10); + } + + @PostConstruct + public void afterInitialize() { + System.out.println(stringValue); + System.out.println(valueFromFile); + System.out.println(systemValue); + System.out.println(someDefault); + System.out.println(prioritySystemProperty); + System.out.println(spelValue); + System.out.println(spelSomeDefault); + System.out.println(someBeanValue); + System.out.println(valuesList); + } +} diff --git a/spring-core/src/main/resources/values.properties b/spring-core/src/main/resources/values.properties new file mode 100644 index 0000000000..d7d61b8ee8 --- /dev/null +++ b/spring-core/src/main/resources/values.properties @@ -0,0 +1,3 @@ +value.from.file=Value got from the file +priority=Properties file +listOfValues=A,B,C \ No newline at end of file From 2dbca951cbef70bf3bf11aba3408ac4ccfd7676a Mon Sep 17 00:00:00 2001 From: KevinGilmore Date: Sat, 15 Apr 2017 10:00:58 -0500 Subject: [PATCH 03/19] BAEL-736 Update README (#1651) * Add files via upload * Update pom.xml * Update RunGuice.java * Update Communication.java * Update CommunicationMode.java * Update DefaultCommunicator.java * Update EmailCommunicationMode.java * Update IMCommunicationMode.java * Update SMSCommunicationMode.java * Update MessageLogger.java * Update MessageSentLoggable.java * Update AOPModule.java * Update BasicModule.java * Update CommunicationModel.java * Update Communicator.java * Update BasicModule.java * Update RunGuice.java * Update MessageLogger.java * Update Communicator.java * Update pom.xml * BAEL-278: Updated README.md * BAEL-554: Add and update README.md files * Update pom.xml * Update pom.xml * Update pom.xml * BAEL-345: fixed assertion * BAEL-109: Updated README.md * BAEL-345: Added README.md * Reinstating reactor-core module in root-level pom * BAEL-393: Adding guide-intro module to root pom * BAEL-9: Updated README.md * BAEL-157: README.md updated * Changed project name * Update RunGuice.java Removed references to message logging and output * Update Communication.java Removed message logging-related code * BAEL-566: Updated README.md * New project name * BAEL-393: removing guice-intro directory * BAEL-393: renamed module guice-intro to guice in root pom.xml * BAEL-393 and BAEL-541 README.md files * BAEL-731: Updated README.md * BAEL-680: renamed test methods * BAEL-714: Updated README.md * BAEL-737: Updated README.md * BAEL-680 and BAEL-756 README.md updates * BAEL-666: Updated README * BAEL-415: Custom Scope * BAEL-415: Custom Scope - renamed classes to reflect TenantScope * README file updates for BAEL-723, BAEL-763, and BAEL-415 * BAEL-735: README * BAEL-567: README * BAEL-736: README --- spring-boot/README.MD | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-boot/README.MD b/spring-boot/README.MD index 1874f621b5..bb15ffc8cc 100644 --- a/spring-boot/README.MD +++ b/spring-boot/README.MD @@ -17,4 +17,4 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [Guide to Internationalization in Spring Boot](http://www.baeldung.com/spring-boot-internationalization) - [Create a Custom FailureAnalyzer with Spring Boot](http://www.baeldung.com/spring-boot-failure-analyzer) - [Configuring Separate Spring DataSource for Tests](http://www.baeldung.com/spring-testing-separate-data-source) - +- [Dynamic DTO Validation Config Retrieved from DB](http://www.baeldung.com/spring-dynamic-dto-validation) From 5e0d1e88ef20cb7965a726bed4a4f9b567b68a4f Mon Sep 17 00:00:00 2001 From: Tomasz Lelek Date: Sat, 15 Apr 2017 17:34:56 +0200 Subject: [PATCH 04/19] BAEL-814 unsafe (#1645) * code for the unsafe article * more descriptive example * proper eng * better test name * free memory call * java 8 style --- .../java/com/baeldung/unsafe/CASCounter.java | 33 +++++ .../com/baeldung/unsafe/OffHeapArray.java | 39 ++++++ .../java/com/baeldung/unsafe/UnsafeTest.java | 118 ++++++++++++++++++ 3 files changed, 190 insertions(+) create mode 100644 core-java/src/test/java/com/baeldung/unsafe/CASCounter.java create mode 100644 core-java/src/test/java/com/baeldung/unsafe/OffHeapArray.java create mode 100644 core-java/src/test/java/com/baeldung/unsafe/UnsafeTest.java diff --git a/core-java/src/test/java/com/baeldung/unsafe/CASCounter.java b/core-java/src/test/java/com/baeldung/unsafe/CASCounter.java new file mode 100644 index 0000000000..f7f3b340c2 --- /dev/null +++ b/core-java/src/test/java/com/baeldung/unsafe/CASCounter.java @@ -0,0 +1,33 @@ +package com.baeldung.unsafe; + +import sun.misc.Unsafe; + +import java.lang.reflect.Field; + +class CASCounter { + private final Unsafe unsafe; + private volatile long counter = 0; + private long offset; + + private Unsafe getUnsafe() throws IllegalAccessException, NoSuchFieldException { + Field f = Unsafe.class.getDeclaredField("theUnsafe"); + f.setAccessible(true); + return (Unsafe) f.get(null); + } + + public CASCounter() throws Exception { + unsafe = getUnsafe(); + offset = unsafe.objectFieldOffset(CASCounter.class.getDeclaredField("counter")); + } + + public void increment() { + long before = counter; + while (!unsafe.compareAndSwapLong(this, offset, before, before + 1)) { + before = counter; + } + } + + public long getCounter() { + return counter; + } +} \ No newline at end of file diff --git a/core-java/src/test/java/com/baeldung/unsafe/OffHeapArray.java b/core-java/src/test/java/com/baeldung/unsafe/OffHeapArray.java new file mode 100644 index 0000000000..f5cab88f3d --- /dev/null +++ b/core-java/src/test/java/com/baeldung/unsafe/OffHeapArray.java @@ -0,0 +1,39 @@ +package com.baeldung.unsafe; + +import sun.misc.Unsafe; + +import java.lang.reflect.Field; + +class OffHeapArray { + private final static int BYTE = 1; + private long size; + private long address; + + private Unsafe getUnsafe() throws IllegalAccessException, NoSuchFieldException { + Field f = Unsafe.class.getDeclaredField("theUnsafe"); + f.setAccessible(true); + return (Unsafe) f.get(null); + } + + public OffHeapArray(long size) throws NoSuchFieldException, IllegalAccessException { + this.size = size; + address = getUnsafe().allocateMemory(size * BYTE); + } + + public void set(long i, byte value) throws NoSuchFieldException, IllegalAccessException { + getUnsafe().putByte(address + i * BYTE, value); + } + + public int get(long idx) throws NoSuchFieldException, IllegalAccessException { + return getUnsafe().getByte(address + idx * BYTE); + } + + public long size() { + return size; + } + + public void freeMemory() throws NoSuchFieldException, IllegalAccessException { + getUnsafe().freeMemory(address); + } + +} diff --git a/core-java/src/test/java/com/baeldung/unsafe/UnsafeTest.java b/core-java/src/test/java/com/baeldung/unsafe/UnsafeTest.java new file mode 100644 index 0000000000..6aa4973ee7 --- /dev/null +++ b/core-java/src/test/java/com/baeldung/unsafe/UnsafeTest.java @@ -0,0 +1,118 @@ +package com.baeldung.unsafe; + +import org.junit.Before; +import org.junit.Test; +import sun.misc.Unsafe; + +import java.io.IOException; +import java.lang.reflect.Field; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; +import java.util.stream.IntStream; + +import static junit.framework.Assert.assertTrue; +import static junit.framework.TestCase.assertEquals; + +public class UnsafeTest { + + private Unsafe unsafe; + + @Before + public void setup() throws NoSuchFieldException, IllegalAccessException { + Field f = Unsafe.class.getDeclaredField("theUnsafe"); + f.setAccessible(true); + unsafe = (Unsafe) f.get(null); + } + + + @Test + public void givenClass_whenInitializeIt_thenShouldHaveDifferentStateWhenUseUnsafe() throws IllegalAccessException, InstantiationException { + //when + InitializationOrdering o1 = new InitializationOrdering(); + assertEquals(o1.getA(), 1); + + //when + InitializationOrdering o3 = (InitializationOrdering) unsafe.allocateInstance(InitializationOrdering.class); + assertEquals(o3.getA(), 0); + } + + @Test + public void givenPrivateMethod_whenUsingUnsafe_thenCanModifyPrivateField() throws NoSuchFieldException { + //given + SecretHolder secretHolder = new SecretHolder(); + + //when + Field f = secretHolder.getClass().getDeclaredField("SECRET_VALUE"); + unsafe.putInt(secretHolder, unsafe.objectFieldOffset(f), 1); + + //then + assertTrue(secretHolder.secretIsDisclosed()); + } + + @Test(expected = IOException.class) + public void givenUnsafeThrowException_whenThrowCheckedException_thenNotNeedToCatchIt() { + unsafe.throwException(new IOException()); + } + + @Test + public void givenArrayBiggerThatMaxInt_whenAllocateItOffHeapMemory_thenSuccess() throws NoSuchFieldException, IllegalAccessException { + //given + long SUPER_SIZE = (long) Integer.MAX_VALUE * 2; + OffHeapArray array = new OffHeapArray(SUPER_SIZE); + + //when + int sum = 0; + for (int i = 0; i < 100; i++) { + array.set((long) Integer.MAX_VALUE + i, (byte) 3); + sum += array.get((long) Integer.MAX_VALUE + i); + } + + //then + assertEquals(array.size(), SUPER_SIZE); + assertEquals(sum, 300); + } + + @Test + public void givenUnsafeCompareAndSwap_whenUseIt_thenCounterYildCorrectLockFreeResults() throws Exception { + //given + int NUM_OF_THREADS = 1_000; + int NUM_OF_INCREMENTS = 10_000; + ExecutorService service = Executors.newFixedThreadPool(NUM_OF_THREADS); + CASCounter casCounter = new CASCounter(); + + //when + IntStream.rangeClosed(0, NUM_OF_THREADS - 1) + .forEach(i -> service.submit(() -> IntStream + .rangeClosed(0, NUM_OF_INCREMENTS - 1) + .forEach(j -> casCounter.increment()))); + + service.shutdown(); + service.awaitTermination(1, TimeUnit.MINUTES); + + //then + assertEquals(NUM_OF_INCREMENTS * NUM_OF_THREADS, casCounter.getCounter()); + + } + + class InitializationOrdering { + private long a; + + public InitializationOrdering() { + this.a = 1; + } + + public long getA() { + return this.a; + } + } + + class SecretHolder { + private int SECRET_VALUE = 0; + + public boolean secretIsDisclosed() { + return SECRET_VALUE == 1; + } + } + +} From b7d64875471623c5b7b25bd68402d02adc7c4a06 Mon Sep 17 00:00:00 2001 From: Yasin Date: Sat, 15 Apr 2017 21:15:26 +0530 Subject: [PATCH 05/19] BAEL-88 Testing in Spring Boot (#1653) * yasin.bhojawala@gmail.com Evaluation article on Different Types of Bean Injection in Spring * Revert "yasin.bhojawala@gmail.com" This reverts commit 963cc51a7a15b75b550108fe4e198cd65a274032. * Fixing compilation error and removing unused import * Introduction to Java9 StackWalking API - yasin.bhojawala@gmail.com Code examples for the article "Introduction to Java9 StackWalking API" * BAEL-608 Introduction to Java9 StackWalking API * BAEL-608 Introduction to Java9 StackWalking API changing the test names to BDD style * BAEL-608 Introduction to Java9 StackWalking API correcting the typo * BAEL-608 Introduction to Java9 StackWalking API improving method names * BAEL-608 Introduction to Java9 StackWalking API test method names improvements * BAEL-718 Quick intro to javatuples * merging pom from master * BAEL-722 Intro to JSONassert * BAEL-722 Intro to JSONassert Updated to 1.5.0 * BAEL-745 Quick Math.pow example * BAEL-729 Adding custom info to actuator's /info endpoint * BAEL-88 Testing in Spring Boot * BAEL-88 Testing in Spring Boot --- .../org/baeldung/boot/boottest/Employee.java | 43 ++++++ .../boot/boottest/EmployeeRepository.java | 21 +++ .../boot/boottest/EmployeeRestController.java | 32 ++++ .../boot/boottest/EmployeeService.java | 17 ++ .../boot/boottest/EmployeeServiceImpl.java | 45 ++++++ .../boot/boottest/EmployeeRepositoryTest.java | 78 ++++++++++ .../EmployeeRestControllerIntTest.java | 78 ++++++++++ .../boottest/EmployeeRestControllerTest.java | 78 ++++++++++ .../boottest/EmployeeServiceImplTest.java | 145 ++++++++++++++++++ .../org/baeldung/boot/boottest/JsonUtil.java | 14 ++ .../application-integrationtest.properties | 2 + 11 files changed, 553 insertions(+) create mode 100644 spring-boot/src/main/java/org/baeldung/boot/boottest/Employee.java create mode 100644 spring-boot/src/main/java/org/baeldung/boot/boottest/EmployeeRepository.java create mode 100644 spring-boot/src/main/java/org/baeldung/boot/boottest/EmployeeRestController.java create mode 100644 spring-boot/src/main/java/org/baeldung/boot/boottest/EmployeeService.java create mode 100644 spring-boot/src/main/java/org/baeldung/boot/boottest/EmployeeServiceImpl.java create mode 100644 spring-boot/src/test/java/org/baeldung/boot/boottest/EmployeeRepositoryTest.java create mode 100644 spring-boot/src/test/java/org/baeldung/boot/boottest/EmployeeRestControllerIntTest.java create mode 100644 spring-boot/src/test/java/org/baeldung/boot/boottest/EmployeeRestControllerTest.java create mode 100644 spring-boot/src/test/java/org/baeldung/boot/boottest/EmployeeServiceImplTest.java create mode 100644 spring-boot/src/test/java/org/baeldung/boot/boottest/JsonUtil.java create mode 100644 spring-boot/src/test/resources/application-integrationtest.properties diff --git a/spring-boot/src/main/java/org/baeldung/boot/boottest/Employee.java b/spring-boot/src/main/java/org/baeldung/boot/boottest/Employee.java new file mode 100644 index 0000000000..a805e8f5fe --- /dev/null +++ b/spring-boot/src/main/java/org/baeldung/boot/boottest/Employee.java @@ -0,0 +1,43 @@ +package org.baeldung.boot.boottest; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; +import javax.validation.constraints.Size; + +@Entity +@Table(name = "person") +public class Employee { + + public Employee() { + } + + public Employee(String name) { + this.name = name; + } + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private Long id; + + @Size(min = 3, max = 20) + private String name; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} \ No newline at end of file diff --git a/spring-boot/src/main/java/org/baeldung/boot/boottest/EmployeeRepository.java b/spring-boot/src/main/java/org/baeldung/boot/boottest/EmployeeRepository.java new file mode 100644 index 0000000000..fa234f0e3a --- /dev/null +++ b/spring-boot/src/main/java/org/baeldung/boot/boottest/EmployeeRepository.java @@ -0,0 +1,21 @@ +package org.baeldung.boot.boottest; + +import java.util.List; +import java.util.Optional; + +import javax.transaction.Transactional; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +@Transactional +public interface EmployeeRepository extends JpaRepository { + + public Optional findByName(String name); + + public Optional findById(Long id); + + public List findAll(); + +} diff --git a/spring-boot/src/main/java/org/baeldung/boot/boottest/EmployeeRestController.java b/spring-boot/src/main/java/org/baeldung/boot/boottest/EmployeeRestController.java new file mode 100644 index 0000000000..8442fc03a3 --- /dev/null +++ b/spring-boot/src/main/java/org/baeldung/boot/boottest/EmployeeRestController.java @@ -0,0 +1,32 @@ +package org.baeldung.boot.boottest; + +import java.util.List; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/api") +public class EmployeeRestController { + + @Autowired + EmployeeService employeeService; + + @RequestMapping(value = "/employees", method = RequestMethod.POST) + public ResponseEntity createEmployee(@RequestBody Employee employee) { + HttpStatus status = HttpStatus.CREATED; + Employee saved = employeeService.save(employee); + return new ResponseEntity<>(saved, status); + } + + @RequestMapping(value = "/employees", method = RequestMethod.GET) + public List getAllEmployees() { + return employeeService.getAllEmployees(); + } + +} diff --git a/spring-boot/src/main/java/org/baeldung/boot/boottest/EmployeeService.java b/spring-boot/src/main/java/org/baeldung/boot/boottest/EmployeeService.java new file mode 100644 index 0000000000..f0ed49e699 --- /dev/null +++ b/spring-boot/src/main/java/org/baeldung/boot/boottest/EmployeeService.java @@ -0,0 +1,17 @@ +package org.baeldung.boot.boottest; + +import java.util.List; +import java.util.Optional; + +public interface EmployeeService { + + public Optional getEmployeeById(Long id); + + public Optional getEmployeeByName(String name); + + public List getAllEmployees(); + + public boolean exists(String email); + + public Employee save(Employee employee); +} diff --git a/spring-boot/src/main/java/org/baeldung/boot/boottest/EmployeeServiceImpl.java b/spring-boot/src/main/java/org/baeldung/boot/boottest/EmployeeServiceImpl.java new file mode 100644 index 0000000000..21936255e0 --- /dev/null +++ b/spring-boot/src/main/java/org/baeldung/boot/boottest/EmployeeServiceImpl.java @@ -0,0 +1,45 @@ +package org.baeldung.boot.boottest; + +import java.util.List; +import java.util.Optional; + +import javax.transaction.Transactional; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +@Transactional +public class EmployeeServiceImpl implements EmployeeService { + + @Autowired + EmployeeRepository employeeRepository; + + @Override + public Optional getEmployeeById(Long id) { + return employeeRepository.findById(id); + } + + @Override + public Optional getEmployeeByName(String name) { + return employeeRepository.findByName(name); + } + + @Override + public boolean exists(String name) { + if (employeeRepository.findByName(name) != null) { + return true; + } + return false; + } + + @Override + public Employee save(Employee employee) { + return employeeRepository.save(employee); + } + + @Override + public List getAllEmployees() { + return employeeRepository.findAll(); + } +} diff --git a/spring-boot/src/test/java/org/baeldung/boot/boottest/EmployeeRepositoryTest.java b/spring-boot/src/test/java/org/baeldung/boot/boottest/EmployeeRepositoryTest.java new file mode 100644 index 0000000000..f47e28a7e1 --- /dev/null +++ b/spring-boot/src/test/java/org/baeldung/boot/boottest/EmployeeRepositoryTest.java @@ -0,0 +1,78 @@ +package org.baeldung.boot.boottest; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.List; +import java.util.NoSuchElementException; +import java.util.Optional; + +import org.baeldung.boot.boottest.Employee; +import org.baeldung.boot.boottest.EmployeeRepository; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; +import org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@DataJpaTest +public class EmployeeRepositoryTest { + + @Autowired + TestEntityManager entityManager; + + @Autowired + EmployeeRepository employeeRepository; + + @Test + public void whenFindByName_thenReturnEmployee() { + Employee emp = new Employee("test"); + entityManager.persistAndFlush(emp); + + Optional fromDb = employeeRepository.findByName(emp.getName()); + assertThat(fromDb.get() + .getName()).isEqualTo(emp.getName()); + } + + @Test(expected = NoSuchElementException.class) + public void whenInvalidName_thenNoSuchElementException() { + Optional fromDb = employeeRepository.findByName("doesNotExist"); + fromDb.get(); + } + + @Test + public void whenFindById_thenReturnEmployee() { + Employee emp = new Employee("test"); + entityManager.persistAndFlush(emp); + + Optional fromDb = employeeRepository.findById(emp.getId()); + assertThat(fromDb.get() + .getName()).isEqualTo(emp.getName()); + } + + @Test(expected = NoSuchElementException.class) + public void whenInvalidId_thenNoSuchElementException() { + Optional fromDb = employeeRepository.findById(-11L); + fromDb.get(); + } + + @Test + public void givenSetOfEmployees_whenFindAll_thenReturnAllEmployees() { + Employee alex = new Employee("alex"); + Employee ron = new Employee("ron"); + Employee bob = new Employee("bob"); + + entityManager.persist(alex); + entityManager.persist(bob); + entityManager.persist(ron); + entityManager.flush(); + + List allEmployees = employeeRepository.findAll(); + + assertThat(allEmployees).hasSize(3) + .extracting(Employee::getName) + .containsOnly(alex.getName(), ron.getName(), bob.getName()); + } + +} diff --git a/spring-boot/src/test/java/org/baeldung/boot/boottest/EmployeeRestControllerIntTest.java b/spring-boot/src/test/java/org/baeldung/boot/boottest/EmployeeRestControllerIntTest.java new file mode 100644 index 0000000000..6360970345 --- /dev/null +++ b/spring-boot/src/test/java/org/baeldung/boot/boottest/EmployeeRestControllerIntTest.java @@ -0,0 +1,78 @@ +package org.baeldung.boot.boottest; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.Matchers.greaterThanOrEqualTo; +import static org.hamcrest.Matchers.hasSize; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import java.io.IOException; +import java.util.List; + +import org.baeldung.boot.DemoApplication; +import org.junit.After; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.http.MediaType; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.web.servlet.MockMvc; + +@RunWith(SpringRunner.class) +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, classes = DemoApplication.class) +@AutoConfigureMockMvc +@TestPropertySource(locations = "classpath:application-integrationtest.properties") +public class EmployeeRestControllerIntTest { + + @Autowired + MockMvc mvc; + + @Autowired + EmployeeRepository repository; + + @After + public void resetDb() { + repository.deleteAll(); + } + + @Test + public void whenValidInput_thenCreateEmployee() throws IOException, Exception { + Employee bob = new Employee("bob"); + mvc.perform(post("/api/employees").contentType(MediaType.APPLICATION_JSON) + .content(JsonUtil.toJson(bob))); + + List found = repository.findAll(); + assertThat(found).extracting(Employee::getName) + .containsOnly("bob"); + } + + @Test + public void givenEmployees_whenGetEmployees_thenStatus200() throws Exception { + + createTestEmployee("bob"); + createTestEmployee("alex"); + + mvc.perform(get("/api/employees").contentType(MediaType.APPLICATION_JSON)) + .andDo(print()) + .andExpect(status().isOk()) + .andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) + .andExpect(jsonPath("$", hasSize(greaterThanOrEqualTo(2)))) + .andExpect(jsonPath("$[0].name", is("bob"))) + .andExpect(jsonPath("$[1].name", is("alex"))); + } + + private void createTestEmployee(String name) { + Employee emp = new Employee(name); + repository.saveAndFlush(emp); + } + +} diff --git a/spring-boot/src/test/java/org/baeldung/boot/boottest/EmployeeRestControllerTest.java b/spring-boot/src/test/java/org/baeldung/boot/boottest/EmployeeRestControllerTest.java new file mode 100644 index 0000000000..0187ba9969 --- /dev/null +++ b/spring-boot/src/test/java/org/baeldung/boot/boottest/EmployeeRestControllerTest.java @@ -0,0 +1,78 @@ +package org.baeldung.boot.boottest; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.Matchers.hasSize; +import static org.mockito.BDDMockito.given; +import static org.mockito.Mockito.reset; +import static org.mockito.Mockito.verify; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import java.util.Arrays; +import java.util.List; + +import org.baeldung.boot.boottest.Employee; +import org.baeldung.boot.boottest.EmployeeRestController; +import org.baeldung.boot.boottest.EmployeeService; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.mockito.internal.verification.VerificationModeFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.http.MediaType; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.web.servlet.MockMvc; + +@RunWith(SpringRunner.class) +@WebMvcTest(EmployeeRestController.class) +public class EmployeeRestControllerTest { + + @Autowired + MockMvc mvc; + + @MockBean + EmployeeService service; + + @Before + public void setUp() throws Exception { + } + + @Test + public void whenPostEmployee_thenCreateEmployee() throws Exception { + Employee alex = new Employee("alex"); + given(service.save(Mockito.anyObject())).willReturn(alex); + + mvc.perform(post("/api/employees").contentType(MediaType.APPLICATION_JSON) + .content(JsonUtil.toJson(alex))) + .andExpect(status().isCreated()) + .andExpect(jsonPath("$.name", is("alex"))); + verify(service, VerificationModeFactory.times(1)).save(Mockito.anyObject()); + reset(service); + } + + @Test + public void givenEmployees_whenGetEmployees_thenReturnJsonArray() throws Exception { + Employee alex = new Employee("alex"); + Employee john = new Employee("john"); + Employee bob = new Employee("bob"); + + List allEmployees = Arrays.asList(alex, john, bob); + + given(service.getAllEmployees()).willReturn(allEmployees); + + mvc.perform(get("/api/employees").contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$", hasSize(3))) + .andExpect(jsonPath("$[0].name", is(alex.getName()))) + .andExpect(jsonPath("$[1].name", is(john.getName()))) + .andExpect(jsonPath("$[2].name", is(bob.getName()))); + verify(service, VerificationModeFactory.times(1)).getAllEmployees(); + reset(service); + } + +} \ No newline at end of file diff --git a/spring-boot/src/test/java/org/baeldung/boot/boottest/EmployeeServiceImplTest.java b/spring-boot/src/test/java/org/baeldung/boot/boottest/EmployeeServiceImplTest.java new file mode 100644 index 0000000000..345cc29e02 --- /dev/null +++ b/spring-boot/src/test/java/org/baeldung/boot/boottest/EmployeeServiceImplTest.java @@ -0,0 +1,145 @@ +package org.baeldung.boot.boottest; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.Arrays; +import java.util.List; +import java.util.NoSuchElementException; +import java.util.Optional; + +import org.baeldung.boot.boottest.Employee; +import org.baeldung.boot.boottest.EmployeeRepository; +import org.baeldung.boot.boottest.EmployeeService; +import org.baeldung.boot.boottest.EmployeeServiceImpl; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.mockito.internal.verification.VerificationModeFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.TestConfiguration; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.context.annotation.Bean; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +public class EmployeeServiceImplTest { + + @TestConfiguration + static class EmployeeServiceImplTestContextConfiguration { + @Bean + public EmployeeService employeeService() { + return new EmployeeServiceImpl(); + } + } + + @Autowired + EmployeeService employeeService; + + @MockBean + EmployeeRepository employeeRepository; + + @Before + public void setUp() { + Employee john = new Employee("john"); + john.setId(11L); + + Optional emp = Optional.of(john); + + Employee bob = new Employee("bob"); + Employee alex = new Employee("alex"); + + List allEmployees = Arrays.asList(john, bob, alex); + + Mockito.when(employeeRepository.findByName(john.getName())) + .thenReturn(emp); + Mockito.when(employeeRepository.findByName("wrong_name")) + .thenReturn(Optional.empty()); + Mockito.when(employeeRepository.findById(john.getId())) + .thenReturn(emp); + Mockito.when(employeeRepository.findAll()) + .thenReturn(allEmployees); + Mockito.when(employeeRepository.findById(-99L)) + .thenReturn(Optional.empty()); + } + + @Test + public void whenValidName_thenEmployeeShouldBeFound() { + Optional fromDb = employeeService.getEmployeeByName("john"); + assertThat(fromDb.get() + .getName()).isEqualTo("john"); + + verifyFindByNameIsCalledOnce("john"); + } + + @Test(expected = NoSuchElementException.class) + public void whenInValidName_thenEmployeeShouldNotBeFound() { + Optional fromDb = employeeService.getEmployeeByName("wrong_name"); + fromDb.get(); + + verifyFindByNameIsCalledOnce("wrong_name"); + } + + @Test + public void whenValidName_thenEmployeeShouldExist() { + boolean doesEmployeeExist = employeeService.exists("john"); + assertThat(doesEmployeeExist).isEqualTo(true); + + verifyFindByNameIsCalledOnce("john"); + } + + @Test + public void whenNonExistingName_thenEmployeeShouldNotExist() { + boolean doesEmployeeExist = employeeService.exists("some_name"); + assertThat(doesEmployeeExist).isEqualTo(false); + + verifyFindByNameIsCalledOnce("some_name"); + } + + @Test + public void whenValidI_thendEmployeeShouldBeFound() { + Optional fromDb = employeeService.getEmployeeById(11L); + assertThat(fromDb.get() + .getName()).isEqualTo("john"); + + verifyFindByIdIsCalledOnce(); + } + + @Test(expected = NoSuchElementException.class) + public void whenInValidId_thenEmployeeShouldNotBeFound() { + Optional fromDb = employeeService.getEmployeeById(-99L); + verifyFindByIdIsCalledOnce(); + fromDb.get(); + } + + @Test + public void given3Employees_whengetAll_thenReturn3Records() { + Employee alex = new Employee("alex"); + Employee john = new Employee("john"); + Employee bob = new Employee("bob"); + + List allEmployees = employeeService.getAllEmployees(); + verifyFindAllEmployeesIsCalledOnce(); + assertThat(allEmployees).hasSize(3) + .extracting(Employee::getName) + .contains(alex.getName(), john.getName(), bob.getName()); + } + + private void verifyFindByNameIsCalledOnce(String name) { + Mockito.verify(employeeRepository, VerificationModeFactory.times(1)) + .findByName(name); + Mockito.reset(employeeRepository); + } + + private void verifyFindByIdIsCalledOnce() { + Mockito.verify(employeeRepository, VerificationModeFactory.times(1)) + .findById(Mockito.anyLong()); + Mockito.reset(employeeRepository); + } + + private void verifyFindAllEmployeesIsCalledOnce() { + Mockito.verify(employeeRepository, VerificationModeFactory.times(1)) + .findAll(); + Mockito.reset(employeeRepository); + } +} diff --git a/spring-boot/src/test/java/org/baeldung/boot/boottest/JsonUtil.java b/spring-boot/src/test/java/org/baeldung/boot/boottest/JsonUtil.java new file mode 100644 index 0000000000..3d532ce54a --- /dev/null +++ b/spring-boot/src/test/java/org/baeldung/boot/boottest/JsonUtil.java @@ -0,0 +1,14 @@ +package org.baeldung.boot.boottest; + +import java.io.IOException; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.databind.ObjectMapper; + +public class JsonUtil { + public static byte[] toJson(Object object) throws IOException { + ObjectMapper mapper = new ObjectMapper(); + mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); + return mapper.writeValueAsBytes(object); + } +} diff --git a/spring-boot/src/test/resources/application-integrationtest.properties b/spring-boot/src/test/resources/application-integrationtest.properties new file mode 100644 index 0000000000..508acf45e0 --- /dev/null +++ b/spring-boot/src/test/resources/application-integrationtest.properties @@ -0,0 +1,2 @@ +spring.datasource.url = jdbc:h2:mem:test +spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.H2Dialect \ No newline at end of file From 99a0b6e2f1f51236276785fdb59e4050c8f545d9 Mon Sep 17 00:00:00 2001 From: pedja4 Date: Sat, 15 Apr 2017 18:32:41 +0200 Subject: [PATCH 06/19] Update UnsafeTest.java (#1655) --- .../src/test/java/com/baeldung/unsafe/UnsafeTest.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/core-java/src/test/java/com/baeldung/unsafe/UnsafeTest.java b/core-java/src/test/java/com/baeldung/unsafe/UnsafeTest.java index 6aa4973ee7..9f53e38969 100644 --- a/core-java/src/test/java/com/baeldung/unsafe/UnsafeTest.java +++ b/core-java/src/test/java/com/baeldung/unsafe/UnsafeTest.java @@ -68,9 +68,14 @@ public class UnsafeTest { sum += array.get((long) Integer.MAX_VALUE + i); } + long arraySize = array.size(); + + array.freeMemory(); + //then - assertEquals(array.size(), SUPER_SIZE); + assertEquals(arraySize, SUPER_SIZE); assertEquals(sum, 300); + } @Test From c313256e8e34245eeb6f058329e33f7dbaeb211b Mon Sep 17 00:00:00 2001 From: Abhinab Kanrar Date: Sun, 16 Apr 2017 14:14:56 +0530 Subject: [PATCH 07/19] log forging (#1659) * jvm log forging * jvm log forging * jvm log forging * log forging --- .../main/java/com/baeldung/logforging/LogForgingDemo.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core-java/src/main/java/com/baeldung/logforging/LogForgingDemo.java b/core-java/src/main/java/com/baeldung/logforging/LogForgingDemo.java index 84c069a746..0a9a5df850 100644 --- a/core-java/src/main/java/com/baeldung/logforging/LogForgingDemo.java +++ b/core-java/src/main/java/com/baeldung/logforging/LogForgingDemo.java @@ -14,9 +14,9 @@ public class LogForgingDemo { public static void main(String[] args) { LogForgingDemo demo = new LogForgingDemo(); - demo.addLog(String.valueOf(300)); - demo.addLog(String.valueOf(300 + "\n\nweb - 2017-04-12 17:47:08,957 [main] INFO Amount reversed successfully")); - demo.addLog(String.valueOf(encode(300 + "\n\nweb - 2017-04-12 17:47:08,957 [main] INFO Amount reversed successfully"))); + demo.addLog("300"); + demo.addLog("300 \n\nweb - 2017-04-12 17:47:08,957 [main] INFO Amount reversed successfully"); + demo.addLog(encode("300 \n\nweb - 2017-04-12 17:47:08,957 [main] INFO Amount reversed successfully")); } public static String encode(String message) { From 76409e6d53b9b4a428dfbc5b4f1294bc7e21ca63 Mon Sep 17 00:00:00 2001 From: baljeet20 Date: Sun, 16 Apr 2017 21:57:01 +0530 Subject: [PATCH 08/19] BAEL-788 Added java config (#1660) * BAEL-788 Added java config * BAEL-788 Removed XML config --- .../baeldung/mybatis/utils/MyBatisUtil.java | 33 ++++++++++++++----- mybatis/src/main/resources/mybatis-config.xml | 21 ------------ .../mybatis/mapper/PersonMapperTest.java | 2 +- 3 files changed, 25 insertions(+), 31 deletions(-) delete mode 100644 mybatis/src/main/resources/mybatis-config.xml diff --git a/mybatis/src/main/java/com/baeldung/mybatis/utils/MyBatisUtil.java b/mybatis/src/main/java/com/baeldung/mybatis/utils/MyBatisUtil.java index a045e70333..cd5291f2d2 100644 --- a/mybatis/src/main/java/com/baeldung/mybatis/utils/MyBatisUtil.java +++ b/mybatis/src/main/java/com/baeldung/mybatis/utils/MyBatisUtil.java @@ -1,24 +1,39 @@ package com.baeldung.mybatis.utils; + +import com.baeldung.mybatis.mapper.AddressMapper; +import com.baeldung.mybatis.mapper.PersonMapper; +import org.apache.ibatis.datasource.pooled.PooledDataSource; import org.apache.ibatis.io.Resources; import org.apache.ibatis.jdbc.SQL; +import org.apache.ibatis.mapping.Environment; +import org.apache.ibatis.session.Configuration; import org.apache.ibatis.session.SqlSessionFactory; import org.apache.ibatis.session.SqlSessionFactoryBuilder; +import org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory; +import javax.sql.DataSource; import java.io.IOException; import java.io.InputStream; public class MyBatisUtil { + public static final String DRIVER = "org.apache.derby.jdbc.EmbeddedDriver"; + public static final String URL = "jdbc:derby:testdb1;create=true"; + public static final String USERNAME = "sa"; + public static final String PASSWORD = "pass123"; private static SqlSessionFactory sqlSessionFactory; - static { - String resource = "mybatis-config.xml"; - InputStream inputStream; - try { - inputStream = Resources.getResourceAsStream(resource); - sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream); - } catch (IOException e) { - e.printStackTrace(); - } + + public static SqlSessionFactory buildqlSessionFactory(){ + DataSource dataSource=new PooledDataSource(DRIVER, URL, USERNAME, PASSWORD); + Environment environment=new Environment("Development",new JdbcTransactionFactory(),dataSource); + Configuration configuration = new Configuration(environment); + configuration.addMapper(PersonMapper.class); + configuration.addMapper(AddressMapper.class); + SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder(); + SqlSessionFactory factory = builder.build(configuration); + return factory; + } + public static SqlSessionFactory getSqlSessionFactory(){ return sqlSessionFactory; } diff --git a/mybatis/src/main/resources/mybatis-config.xml b/mybatis/src/main/resources/mybatis-config.xml deleted file mode 100644 index 6987797068..0000000000 --- a/mybatis/src/main/resources/mybatis-config.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/mybatis/src/test/java/com/baeldung/mybatis/mapper/PersonMapperTest.java b/mybatis/src/test/java/com/baeldung/mybatis/mapper/PersonMapperTest.java index 8724aaa545..51888043e9 100644 --- a/mybatis/src/test/java/com/baeldung/mybatis/mapper/PersonMapperTest.java +++ b/mybatis/src/test/java/com/baeldung/mybatis/mapper/PersonMapperTest.java @@ -23,7 +23,7 @@ public class PersonMapperTest { @Before public void setup() throws SQLException { - session = MyBatisUtil.getSqlSessionFactory().openSession(); + session = MyBatisUtil.buildqlSessionFactory().openSession(); createTables(session); } From 64ce09db48600bff35cd82b705f849a7fabc60dd Mon Sep 17 00:00:00 2001 From: Doha2012 Date: Sun, 16 Apr 2017 20:01:02 +0200 Subject: [PATCH 09/19] remove log4j properties (#1662) * upgrade to spring boot 1.5.2 * add full update to REST API * modify ratings controller * upgrade herold * fix integration test * fix integration test * minor fix * fix integration test * fix integration test * minor cleanup * minor cleanup * remove log4j properties --- aspectj/pom.xml | 5 ----- aspectj/src/main/resources/log4j.properties | 10 ---------- rest-assured/pom.xml | 12 ------------ rest-assured/src/test/resources/log4j.properties | 16 ---------------- xstream/pom.xml | 6 ------ xstream/src/main/resources/log4j.properties | 14 -------------- 6 files changed, 63 deletions(-) delete mode 100644 aspectj/src/main/resources/log4j.properties delete mode 100644 rest-assured/src/test/resources/log4j.properties delete mode 100644 xstream/src/main/resources/log4j.properties diff --git a/aspectj/pom.xml b/aspectj/pom.xml index 90b527c14f..cbc98dac81 100644 --- a/aspectj/pom.xml +++ b/aspectj/pom.xml @@ -70,11 +70,6 @@ spring-aop 4.3.4.RELEASE - - log4j - log4j - 1.2.17 - diff --git a/aspectj/src/main/resources/log4j.properties b/aspectj/src/main/resources/log4j.properties deleted file mode 100644 index 9e2afcd5b0..0000000000 --- a/aspectj/src/main/resources/log4j.properties +++ /dev/null @@ -1,10 +0,0 @@ -log4j.rootLogger=TRACE, stdout - -# Redirect log messages to console -log4j.appender.stdout=org.apache.log4j.ConsoleAppender -log4j.appender.stdout.Target=System.out -log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n - -log4j.logger.org.springframework.aop.interceptor.PerformanceMonitorInterceptor=TRACE, stdout -log4j.logger.com.baeldung.performancemonitor.MyPerformanceMonitorInterceptor=INFO, stdout \ No newline at end of file diff --git a/rest-assured/pom.xml b/rest-assured/pom.xml index bbeef8bb9c..1d4dba4cbf 100644 --- a/rest-assured/pom.xml +++ b/rest-assured/pom.xml @@ -59,17 +59,6 @@ ${slf4j.version} - - log4j - log4j - ${log4j.version} - - - org.slf4j - slf4j-log4j12 - ${slf4j.version} - - commons-logging commons-logging @@ -276,7 +265,6 @@ 1.4.7 9.4.0.v20161208 - 1.2.17 1.7.21 3.5 diff --git a/rest-assured/src/test/resources/log4j.properties b/rest-assured/src/test/resources/log4j.properties deleted file mode 100644 index d3c6b9e783..0000000000 --- a/rest-assured/src/test/resources/log4j.properties +++ /dev/null @@ -1,16 +0,0 @@ -## Logger configure -datestamp=yyyy-MM-dd HH:mm:ss -log4j.rootLogger=TRACE, file, console - -log4j.appender.file=org.apache.log4j.RollingFileAppender -log4j.appender.file.maxFileSize=1GB -log4j.appender.file.maxBackupIndex=5 -log4j.appender.file.File=log/rest-assured.log -log4j.appender.file.threshold=TRACE -log4j.appender.file.layout=org.apache.log4j.PatternLayout -log4j.appender.file.layout.ConversionPattern=%d{${datestamp}} %5p: [%c] - %m%n - -log4j.appender.console=org.apache.log4j.ConsoleAppender -log4j.appender.console.Threshold=INFO -log4j.appender.console.layout=org.apache.log4j.PatternLayout -log4j.appender.console.layout.ConversionPattern=%d{${datestamp}} %5p\: [%c] - %m%n \ No newline at end of file diff --git a/xstream/pom.xml b/xstream/pom.xml index 7af8efa659..3e8aaafc06 100644 --- a/xstream/pom.xml +++ b/xstream/pom.xml @@ -26,11 +26,6 @@ ${junit.version} - - log4j - log4j - ${log4j.version} - @@ -51,7 +46,6 @@ 1.4.9 1.3.8 - 1.2.17 4.12 diff --git a/xstream/src/main/resources/log4j.properties b/xstream/src/main/resources/log4j.properties deleted file mode 100644 index 03d8c51aa0..0000000000 --- a/xstream/src/main/resources/log4j.properties +++ /dev/null @@ -1,14 +0,0 @@ -# Root logger option -log4j.rootLogger=DEBUG, file -# Redirect log messages to console -# log4j.appender.stdout=org.apache.log4j.ConsoleAppender -# log4j.appender.stdout.Target=System.out -# log4j.appender.stdout.layout=org.apache.log4j.PatternLayout -# log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n -# Redirect log messages to a log file, support file rolling. -log4j.appender.file=org.apache.log4j.RollingFileAppender -log4j.appender.file.File=D:\\Test\\xstream-application.log -log4j.appender.file.MaxFileSize=5MB -log4j.appender.file.MaxBackupIndex=10 -log4j.appender.file.layout=org.apache.log4j.PatternLayout -log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n \ No newline at end of file From cdab6acdbf3b4732818e32bc341d62774d3936ad Mon Sep 17 00:00:00 2001 From: yetanotherallisonf Date: Sun, 16 Apr 2017 13:01:32 -0500 Subject: [PATCH 10/19] Update README.md (#1657) --- core-java/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-java/README.md b/core-java/README.md index a7c8b0e855..45695f13f6 100644 --- a/core-java/README.md +++ b/core-java/README.md @@ -91,4 +91,4 @@ - [Avoiding ConcurrentModificationException when iterating and removing](http://www.baeldung.com/avoiding-concurrentmodificationexception-when-iterating-and-removing) - [Removing all nulls from a List in Java](http://www.baeldung.com/java-remove-nulls-from-list) - [Removing all duplicates from a List in Java](http://www.baeldung.com/java-remove-duplicates-from-list) - +- [An Introduction to ThreadLocal in Java](http://www.baeldung.com/java-threadlocal) From 7525544e0941d25609c69beea2e640bb2149eb9a Mon Sep 17 00:00:00 2001 From: Doha2012 Date: Mon, 17 Apr 2017 18:41:23 +0200 Subject: [PATCH 11/19] use standard logback.xml (#1666) * upgrade to spring boot 1.5.2 * add full update to REST API * modify ratings controller * upgrade herold * fix integration test * fix integration test * minor fix * fix integration test * fix integration test * minor cleanup * minor cleanup * remove log4j properties * use standard logbook.xml --- apache-fop/src/main/resources/logback.xml | 9 +++-- .../src/main/resources/logback.xml | 30 +++++++-------- aspectj/src/main/resources/logback.xml | 25 ++++++------ core-java-9/src/main/resources/logback.xml | 11 ++++-- core-java/src/main/resources/logback.xml | 9 +++-- couchbase-sdk/src/main/resources/logback.xml | 8 ++-- couchbase-sdk/src/test/resources/logback.xml | 8 ++-- gson/src/main/resources/logback.xml | 29 +++++++------- guava/src/main/resources/logback.xml | 29 +++++++------- .../src/main/resources/logback.xml | 29 +++++++------- hazelcast/src/main/resources/logback.xml | 25 ++++++------ httpclient/src/main/resources/logback.xml | 10 +++-- jackson/src/main/resources/logback.xml | 29 +++++++------- jaxb/src/main/resources/logback.xml | 25 ++++++------ jsf/src/main/resources/logback.xml | 9 ++++- mockito/src/main/resources/logback.xml | 29 +++++++------- querydsl/src/main/resources/logback.xml | 38 +++++-------------- rest-assured/pom.xml | 14 +++++++ rest-assured/src/test/resources/logback.xml | 19 ++++++++++ rest-testing/src/main/resources/logback.xml | 10 +++-- .../main/webapp/WEB-INF/classes/logback.xml | 18 ++++++++- .../main/webapp/WEB-INF/classes/logback.xml | 18 ++++++++- spring-all/src/main/resources/logback.xml | 31 +++++++-------- spring-boot/src/main/resources/logback.xml | 23 ++++++----- .../src/main/resources/logback.xml | 23 ++++++----- .../src/main/resources/logback.xml | 3 +- .../src/main/resources/logback.xml | 8 ++-- .../src/test/resources/logback.xml | 8 ++-- .../src/main/resources/logback.xml | 25 +++++++----- .../src/main/resources/logback.xml | 11 +++--- .../src/main/resources/logback.xml | 3 +- .../src/main/resources/logback.xml | 3 +- .../src/test/resources/logback.xml | 19 ++++++---- .../src/main/resources/logback.xml | 3 +- .../src/main/resources/logback.xml | 31 +++++++-------- .../src/main/resources/logback.xml | 29 +++++++------- .../src/main/resources/logback.xml | 31 +++++++-------- .../src/main/resources/logback.xml | 31 +++++++-------- spring-jersey/src/main/resources/logback.xml | 12 ++++-- spring-jpa/src/main/resources/logback.xml | 29 +++++++------- spring-ldap/src/main/resources/logback.xml | 12 ++++-- .../src/main/resources/logback.xml | 30 +++++++-------- spring-mvc-xml/src/main/resources/logback.xml | 29 +++++++------- spring-quartz/src/main/resources/logback.xml | 25 ++++++------ spring-rest/src/main/resources/logback.xml | 29 +++++++------- .../src/main/resources/logback.xml | 29 +++++++------- .../src/main/resources/logback.xml | 29 +++++++------- .../src/main/resources/logback.xml | 31 +++++++-------- .../src/main/resources/logback.xml | 29 +++++++------- .../src/main/resources/logback.xml | 29 +++++++------- .../src/main/resources/logback.xml | 29 +++++++------- .../src/main/resources/logback.xml | 31 +++++++-------- .../src/main/resources/logback.xml | 29 +++++++------- .../src/main/resources/logback.xml | 31 +++++++-------- .../src/main/resources/logback.xml | 29 +++++++------- .../src/main/resources/logback.xml | 29 +++++++------- .../src/main/resources/logback.xml | 29 +++++++------- testng/src/test/resources/logback.xml | 9 ++++- vertx/src/main/resources/logback.xml | 9 ++++- xstream/pom.xml | 21 ++++++++++ xstream/src/main/resources/logback.xml | 19 ++++++++++ 61 files changed, 698 insertions(+), 593 deletions(-) create mode 100644 rest-assured/src/test/resources/logback.xml create mode 100644 xstream/src/main/resources/logback.xml diff --git a/apache-fop/src/main/resources/logback.xml b/apache-fop/src/main/resources/logback.xml index 62d0ea5037..ec0dc2469a 100644 --- a/apache-fop/src/main/resources/logback.xml +++ b/apache-fop/src/main/resources/logback.xml @@ -1,5 +1,5 @@ + - web - %date [%thread] %-5level %logger{36} - %message%n @@ -7,10 +7,13 @@ - + + + + + - \ No newline at end of file diff --git a/apache-velocity/src/main/resources/logback.xml b/apache-velocity/src/main/resources/logback.xml index 70a420a57a..ec0dc2469a 100644 --- a/apache-velocity/src/main/resources/logback.xml +++ b/apache-velocity/src/main/resources/logback.xml @@ -1,23 +1,19 @@ - - - + + + web - %date [%thread] %-5level %logger{36} - %message%n + + + - - %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n - + + - - - - - - - - - - + + + + + \ No newline at end of file diff --git a/aspectj/src/main/resources/logback.xml b/aspectj/src/main/resources/logback.xml index 8b566286b8..ec0dc2469a 100644 --- a/aspectj/src/main/resources/logback.xml +++ b/aspectj/src/main/resources/logback.xml @@ -1,18 +1,19 @@ + + + web - %date [%thread] %-5level %logger{36} - %message%n + + + - - - %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg %n - - + + - - - + + - - - - + + + \ No newline at end of file diff --git a/core-java-9/src/main/resources/logback.xml b/core-java-9/src/main/resources/logback.xml index eefdc7a337..ec0dc2469a 100644 --- a/core-java-9/src/main/resources/logback.xml +++ b/core-java-9/src/main/resources/logback.xml @@ -1,5 +1,5 @@ + - web - %date [%thread] %-5level %logger{36} - %message%n @@ -7,10 +7,13 @@ - + + + + + - + - \ No newline at end of file diff --git a/core-java/src/main/resources/logback.xml b/core-java/src/main/resources/logback.xml index 62d0ea5037..ec0dc2469a 100644 --- a/core-java/src/main/resources/logback.xml +++ b/core-java/src/main/resources/logback.xml @@ -1,5 +1,5 @@ + - web - %date [%thread] %-5level %logger{36} - %message%n @@ -7,10 +7,13 @@ - + + + + + - \ No newline at end of file diff --git a/couchbase-sdk/src/main/resources/logback.xml b/couchbase-sdk/src/main/resources/logback.xml index efcc6fb4c7..ec0dc2469a 100644 --- a/couchbase-sdk/src/main/resources/logback.xml +++ b/couchbase-sdk/src/main/resources/logback.xml @@ -1,5 +1,5 @@ + - web - %date [%thread] %-5level %logger{36} - %message%n @@ -8,10 +8,12 @@ - + + + + - \ No newline at end of file diff --git a/couchbase-sdk/src/test/resources/logback.xml b/couchbase-sdk/src/test/resources/logback.xml index efcc6fb4c7..ec0dc2469a 100644 --- a/couchbase-sdk/src/test/resources/logback.xml +++ b/couchbase-sdk/src/test/resources/logback.xml @@ -1,5 +1,5 @@ + - web - %date [%thread] %-5level %logger{36} - %message%n @@ -8,10 +8,12 @@ - + + + + - \ No newline at end of file diff --git a/gson/src/main/resources/logback.xml b/gson/src/main/resources/logback.xml index 1146dade63..ec0dc2469a 100644 --- a/gson/src/main/resources/logback.xml +++ b/gson/src/main/resources/logback.xml @@ -1,20 +1,19 @@ + + + + web - %date [%thread] %-5level %logger{36} - %message%n + + + - - - web - %date [%thread] %-5level %logger{36} - %message%n - - - + + - - - - - - - - - + + + + + \ No newline at end of file diff --git a/guava/src/main/resources/logback.xml b/guava/src/main/resources/logback.xml index 1146dade63..ec0dc2469a 100644 --- a/guava/src/main/resources/logback.xml +++ b/guava/src/main/resources/logback.xml @@ -1,20 +1,19 @@ + + + + web - %date [%thread] %-5level %logger{36} - %message%n + + + - - - web - %date [%thread] %-5level %logger{36} - %message%n - - - + + - - - - - - - - - + + + + + \ No newline at end of file diff --git a/handling-spring-static-resources/src/main/resources/logback.xml b/handling-spring-static-resources/src/main/resources/logback.xml index 1146dade63..ec0dc2469a 100644 --- a/handling-spring-static-resources/src/main/resources/logback.xml +++ b/handling-spring-static-resources/src/main/resources/logback.xml @@ -1,20 +1,19 @@ + + + + web - %date [%thread] %-5level %logger{36} - %message%n + + + - - - web - %date [%thread] %-5level %logger{36} - %message%n - - - + + - - - - - - - - - + + + + + \ No newline at end of file diff --git a/hazelcast/src/main/resources/logback.xml b/hazelcast/src/main/resources/logback.xml index 8b566286b8..ec0dc2469a 100644 --- a/hazelcast/src/main/resources/logback.xml +++ b/hazelcast/src/main/resources/logback.xml @@ -1,18 +1,19 @@ + + + web - %date [%thread] %-5level %logger{36} - %message%n + + + - - - %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg %n - - + + - - - + + - - - - + + + \ No newline at end of file diff --git a/httpclient/src/main/resources/logback.xml b/httpclient/src/main/resources/logback.xml index aa1e9cd522..ec0dc2469a 100644 --- a/httpclient/src/main/resources/logback.xml +++ b/httpclient/src/main/resources/logback.xml @@ -1,5 +1,5 @@ + - web - %date [%thread] %-5level %logger{36} - %message%n @@ -7,11 +7,13 @@ - - + + + + + - \ No newline at end of file diff --git a/jackson/src/main/resources/logback.xml b/jackson/src/main/resources/logback.xml index 1146dade63..ec0dc2469a 100644 --- a/jackson/src/main/resources/logback.xml +++ b/jackson/src/main/resources/logback.xml @@ -1,20 +1,19 @@ + + + + web - %date [%thread] %-5level %logger{36} - %message%n + + + - - - web - %date [%thread] %-5level %logger{36} - %message%n - - - + + - - - - - - - - - + + + + + \ No newline at end of file diff --git a/jaxb/src/main/resources/logback.xml b/jaxb/src/main/resources/logback.xml index 8b566286b8..ec0dc2469a 100644 --- a/jaxb/src/main/resources/logback.xml +++ b/jaxb/src/main/resources/logback.xml @@ -1,18 +1,19 @@ + + + web - %date [%thread] %-5level %logger{36} - %message%n + + + - - - %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg %n - - + + - - - + + - - - - + + + \ No newline at end of file diff --git a/jsf/src/main/resources/logback.xml b/jsf/src/main/resources/logback.xml index e9ae1894a6..ec0dc2469a 100644 --- a/jsf/src/main/resources/logback.xml +++ b/jsf/src/main/resources/logback.xml @@ -1,5 +1,5 @@ + - web - %date [%thread] %-5level %logger{36} - %message%n @@ -7,8 +7,13 @@ + + + + + + - \ No newline at end of file diff --git a/mockito/src/main/resources/logback.xml b/mockito/src/main/resources/logback.xml index 1146dade63..ec0dc2469a 100644 --- a/mockito/src/main/resources/logback.xml +++ b/mockito/src/main/resources/logback.xml @@ -1,20 +1,19 @@ + + + + web - %date [%thread] %-5level %logger{36} - %message%n + + + - - - web - %date [%thread] %-5level %logger{36} - %message%n - - - + + - - - - - - - - - + + + + + \ No newline at end of file diff --git a/querydsl/src/main/resources/logback.xml b/querydsl/src/main/resources/logback.xml index d0a1dc06ac..ec0dc2469a 100644 --- a/querydsl/src/main/resources/logback.xml +++ b/querydsl/src/main/resources/logback.xml @@ -1,37 +1,19 @@ - - - %d{yyyy-MM-dd HH:mm:ss} [%t] %-5p: %c - %m%n - + + web - %date [%thread] %-5level %logger{36} - %message%n + + - - - - + + - - - - + + - - - - - - - - - - - - - - - + + - \ No newline at end of file diff --git a/rest-assured/pom.xml b/rest-assured/pom.xml index 1d4dba4cbf..2c8039401e 100644 --- a/rest-assured/pom.xml +++ b/rest-assured/pom.xml @@ -59,6 +59,18 @@ ${slf4j.version} + + ch.qos.logback + logback-classic + ${logback.version} + + + + ch.qos.logback + logback-core + ${logback.version} + + commons-logging commons-logging @@ -266,6 +278,8 @@ 9.4.0.v20161208 1.7.21 + 1.1.7 + 3.5 1.2 diff --git a/rest-assured/src/test/resources/logback.xml b/rest-assured/src/test/resources/logback.xml new file mode 100644 index 0000000000..ec0dc2469a --- /dev/null +++ b/rest-assured/src/test/resources/logback.xml @@ -0,0 +1,19 @@ + + + + + web - %date [%thread] %-5level %logger{36} - %message%n + + + + + + + + + + + + + + \ No newline at end of file diff --git a/rest-testing/src/main/resources/logback.xml b/rest-testing/src/main/resources/logback.xml index aa1e9cd522..ec0dc2469a 100644 --- a/rest-testing/src/main/resources/logback.xml +++ b/rest-testing/src/main/resources/logback.xml @@ -1,5 +1,5 @@ + - web - %date [%thread] %-5level %logger{36} - %message%n @@ -7,11 +7,13 @@ - - + + + + + - \ No newline at end of file diff --git a/resteasy/bin/src/main/webapp/WEB-INF/classes/logback.xml b/resteasy/bin/src/main/webapp/WEB-INF/classes/logback.xml index d94e9f71ab..ec0dc2469a 100644 --- a/resteasy/bin/src/main/webapp/WEB-INF/classes/logback.xml +++ b/resteasy/bin/src/main/webapp/WEB-INF/classes/logback.xml @@ -1,3 +1,19 @@ - + + + + + web - %date [%thread] %-5level %logger{36} - %message%n + + + + + + + + + + + + \ No newline at end of file diff --git a/resteasy/src/main/webapp/WEB-INF/classes/logback.xml b/resteasy/src/main/webapp/WEB-INF/classes/logback.xml index d94e9f71ab..ec0dc2469a 100644 --- a/resteasy/src/main/webapp/WEB-INF/classes/logback.xml +++ b/resteasy/src/main/webapp/WEB-INF/classes/logback.xml @@ -1,3 +1,19 @@ - + + + + + web - %date [%thread] %-5level %logger{36} - %message%n + + + + + + + + + + + + \ No newline at end of file diff --git a/spring-all/src/main/resources/logback.xml b/spring-all/src/main/resources/logback.xml index 45c9697f77..ec0dc2469a 100644 --- a/spring-all/src/main/resources/logback.xml +++ b/spring-all/src/main/resources/logback.xml @@ -1,22 +1,19 @@ + + + + web - %date [%thread] %-5level %logger{36} - %message%n + + + - - - web - %date [%thread] %-5level %logger{36} - %message%n - - - + + - - - - - - - - - - - + + + + + \ No newline at end of file diff --git a/spring-boot/src/main/resources/logback.xml b/spring-boot/src/main/resources/logback.xml index 78913ee76f..ec0dc2469a 100644 --- a/spring-boot/src/main/resources/logback.xml +++ b/spring-boot/src/main/resources/logback.xml @@ -1,14 +1,19 @@ + + + + web - %date [%thread] %-5level %logger{36} - %message%n + + + - - - web - %date [%thread] %-5level %logger{36} - %message%n - - - + + - - - + + + + + \ No newline at end of file diff --git a/spring-custom-aop/spring-custom-aop/src/main/resources/logback.xml b/spring-custom-aop/spring-custom-aop/src/main/resources/logback.xml index 78913ee76f..ec0dc2469a 100644 --- a/spring-custom-aop/spring-custom-aop/src/main/resources/logback.xml +++ b/spring-custom-aop/spring-custom-aop/src/main/resources/logback.xml @@ -1,14 +1,19 @@ + + + + web - %date [%thread] %-5level %logger{36} - %message%n + + + - - - web - %date [%thread] %-5level %logger{36} - %message%n - - - + + - - - + + + + + \ No newline at end of file diff --git a/spring-data-cassandra/src/main/resources/logback.xml b/spring-data-cassandra/src/main/resources/logback.xml index 215eeede64..ec0dc2469a 100644 --- a/spring-data-cassandra/src/main/resources/logback.xml +++ b/spring-data-cassandra/src/main/resources/logback.xml @@ -1,5 +1,5 @@ + - web - %date [%thread] %-5level %logger{36} - %message%n @@ -16,5 +16,4 @@ - \ No newline at end of file diff --git a/spring-data-couchbase-2/src/main/resources/logback.xml b/spring-data-couchbase-2/src/main/resources/logback.xml index d9067fd1da..ec0dc2469a 100644 --- a/spring-data-couchbase-2/src/main/resources/logback.xml +++ b/spring-data-couchbase-2/src/main/resources/logback.xml @@ -1,5 +1,5 @@ + - web - %date [%thread] %-5level %logger{36} - %message%n @@ -8,10 +8,12 @@ - + + + + - \ No newline at end of file diff --git a/spring-data-couchbase-2/src/test/resources/logback.xml b/spring-data-couchbase-2/src/test/resources/logback.xml index d9067fd1da..ec0dc2469a 100644 --- a/spring-data-couchbase-2/src/test/resources/logback.xml +++ b/spring-data-couchbase-2/src/test/resources/logback.xml @@ -1,5 +1,5 @@ + - web - %date [%thread] %-5level %logger{36} - %message%n @@ -8,10 +8,12 @@ - + + + + - \ No newline at end of file diff --git a/spring-data-dynamodb/src/main/resources/logback.xml b/spring-data-dynamodb/src/main/resources/logback.xml index c0bc602910..ec0dc2469a 100644 --- a/spring-data-dynamodb/src/main/resources/logback.xml +++ b/spring-data-dynamodb/src/main/resources/logback.xml @@ -1,14 +1,19 @@ + - - - web - %date [%thread] %-5level %logger{36} - %message%n - - - + + web - %date [%thread] %-5level %logger{36} - %message%n + + + - - - + + - + + + + + + + \ No newline at end of file diff --git a/spring-data-elasticsearch/src/main/resources/logback.xml b/spring-data-elasticsearch/src/main/resources/logback.xml index db75fcbe40..ec0dc2469a 100644 --- a/spring-data-elasticsearch/src/main/resources/logback.xml +++ b/spring-data-elasticsearch/src/main/resources/logback.xml @@ -1,20 +1,19 @@ + - - elasticsearch - %date [%thread] %-5level %logger{36} - %message%n + web - %date [%thread] %-5level %logger{36} - %message%n + - - - + + - \ No newline at end of file diff --git a/spring-data-mongodb/src/main/resources/logback.xml b/spring-data-mongodb/src/main/resources/logback.xml index 215eeede64..ec0dc2469a 100644 --- a/spring-data-mongodb/src/main/resources/logback.xml +++ b/spring-data-mongodb/src/main/resources/logback.xml @@ -1,5 +1,5 @@ + - web - %date [%thread] %-5level %logger{36} - %message%n @@ -16,5 +16,4 @@ - \ No newline at end of file diff --git a/spring-data-neo4j/src/main/resources/logback.xml b/spring-data-neo4j/src/main/resources/logback.xml index 215eeede64..ec0dc2469a 100644 --- a/spring-data-neo4j/src/main/resources/logback.xml +++ b/spring-data-neo4j/src/main/resources/logback.xml @@ -1,5 +1,5 @@ + - web - %date [%thread] %-5level %logger{36} - %message%n @@ -16,5 +16,4 @@ - \ No newline at end of file diff --git a/spring-data-neo4j/src/test/resources/logback.xml b/spring-data-neo4j/src/test/resources/logback.xml index 39a6538324..ec0dc2469a 100644 --- a/spring-data-neo4j/src/test/resources/logback.xml +++ b/spring-data-neo4j/src/test/resources/logback.xml @@ -1,16 +1,19 @@ - - + - %d %5p %40.40c:%4L - %m%n + web - %date [%thread] %-5level %logger{36} - %message%n + - + + - - + + + + + - - + \ No newline at end of file diff --git a/spring-data-redis/src/main/resources/logback.xml b/spring-data-redis/src/main/resources/logback.xml index 215eeede64..ec0dc2469a 100644 --- a/spring-data-redis/src/main/resources/logback.xml +++ b/spring-data-redis/src/main/resources/logback.xml @@ -1,5 +1,5 @@ + - web - %date [%thread] %-5level %logger{36} - %message%n @@ -16,5 +16,4 @@ - \ No newline at end of file diff --git a/spring-exceptions/src/main/resources/logback.xml b/spring-exceptions/src/main/resources/logback.xml index 45c9697f77..ec0dc2469a 100644 --- a/spring-exceptions/src/main/resources/logback.xml +++ b/spring-exceptions/src/main/resources/logback.xml @@ -1,22 +1,19 @@ + + + + web - %date [%thread] %-5level %logger{36} - %message%n + + + - - - web - %date [%thread] %-5level %logger{36} - %message%n - - - + + - - - - - - - - - - - + + + + + \ No newline at end of file diff --git a/spring-hibernate3/src/main/resources/logback.xml b/spring-hibernate3/src/main/resources/logback.xml index 1146dade63..ec0dc2469a 100644 --- a/spring-hibernate3/src/main/resources/logback.xml +++ b/spring-hibernate3/src/main/resources/logback.xml @@ -1,20 +1,19 @@ + + + + web - %date [%thread] %-5level %logger{36} - %message%n + + + - - - web - %date [%thread] %-5level %logger{36} - %message%n - - - + + - - - - - - - - - + + + + + \ No newline at end of file diff --git a/spring-hibernate4/src/main/resources/logback.xml b/spring-hibernate4/src/main/resources/logback.xml index 71a6d50a58..ec0dc2469a 100644 --- a/spring-hibernate4/src/main/resources/logback.xml +++ b/spring-hibernate4/src/main/resources/logback.xml @@ -1,22 +1,19 @@ + + + + web - %date [%thread] %-5level %logger{36} - %message%n + + + - - - web - %date [%thread] %-5level %logger{36} - %message%n - - - + + - - - - - - - - - - - + + + + + \ No newline at end of file diff --git a/spring-hibernate5/src/main/resources/logback.xml b/spring-hibernate5/src/main/resources/logback.xml index 71a6d50a58..ec0dc2469a 100644 --- a/spring-hibernate5/src/main/resources/logback.xml +++ b/spring-hibernate5/src/main/resources/logback.xml @@ -1,22 +1,19 @@ + + + + web - %date [%thread] %-5level %logger{36} - %message%n + + + - - - web - %date [%thread] %-5level %logger{36} - %message%n - - - + + - - - - - - - - - - - + + + + + \ No newline at end of file diff --git a/spring-jersey/src/main/resources/logback.xml b/spring-jersey/src/main/resources/logback.xml index 788096686a..ec0dc2469a 100644 --- a/spring-jersey/src/main/resources/logback.xml +++ b/spring-jersey/src/main/resources/logback.xml @@ -1,15 +1,19 @@ + - - web - %date [%thread] %-5level %logger{36} - - %message%n + web - %date [%thread] %-5level %logger{36} - %message%n + + + + + + - \ No newline at end of file diff --git a/spring-jpa/src/main/resources/logback.xml b/spring-jpa/src/main/resources/logback.xml index 1146dade63..ec0dc2469a 100644 --- a/spring-jpa/src/main/resources/logback.xml +++ b/spring-jpa/src/main/resources/logback.xml @@ -1,20 +1,19 @@ + + + + web - %date [%thread] %-5level %logger{36} - %message%n + + + - - - web - %date [%thread] %-5level %logger{36} - %message%n - - - + + - - - - - - - - - + + + + + \ No newline at end of file diff --git a/spring-ldap/src/main/resources/logback.xml b/spring-ldap/src/main/resources/logback.xml index 788096686a..ec0dc2469a 100644 --- a/spring-ldap/src/main/resources/logback.xml +++ b/spring-ldap/src/main/resources/logback.xml @@ -1,15 +1,19 @@ + - - web - %date [%thread] %-5level %logger{36} - - %message%n + web - %date [%thread] %-5level %logger{36} - %message%n + + + + + + - \ No newline at end of file diff --git a/spring-mvc-java/src/main/resources/logback.xml b/spring-mvc-java/src/main/resources/logback.xml index e0721aa890..ec0dc2469a 100644 --- a/spring-mvc-java/src/main/resources/logback.xml +++ b/spring-mvc-java/src/main/resources/logback.xml @@ -1,21 +1,19 @@ + + + + web - %date [%thread] %-5level %logger{36} - %message%n + + + - - - - %date [%thread] %-5level %logger{6} - %message%n - - - + + - - - - - - - - - + + + + + \ No newline at end of file diff --git a/spring-mvc-xml/src/main/resources/logback.xml b/spring-mvc-xml/src/main/resources/logback.xml index 1146dade63..ec0dc2469a 100644 --- a/spring-mvc-xml/src/main/resources/logback.xml +++ b/spring-mvc-xml/src/main/resources/logback.xml @@ -1,20 +1,19 @@ + + + + web - %date [%thread] %-5level %logger{36} - %message%n + + + - - - web - %date [%thread] %-5level %logger{36} - %message%n - - - + + - - - - - - - - - + + + + + \ No newline at end of file diff --git a/spring-quartz/src/main/resources/logback.xml b/spring-quartz/src/main/resources/logback.xml index be0937fefe..ec0dc2469a 100644 --- a/spring-quartz/src/main/resources/logback.xml +++ b/spring-quartz/src/main/resources/logback.xml @@ -1,16 +1,19 @@ + + + + web - %date [%thread] %-5level %logger{36} - %message%n + + + - - - %date [%thread] %-5level %logger{36} - %message%n - - - + + - - - - - + + + + + \ No newline at end of file diff --git a/spring-rest/src/main/resources/logback.xml b/spring-rest/src/main/resources/logback.xml index 1146dade63..ec0dc2469a 100644 --- a/spring-rest/src/main/resources/logback.xml +++ b/spring-rest/src/main/resources/logback.xml @@ -1,20 +1,19 @@ + + + + web - %date [%thread] %-5level %logger{36} - %message%n + + + - - - web - %date [%thread] %-5level %logger{36} - %message%n - - - + + - - - - - - - - - + + + + + \ No newline at end of file diff --git a/spring-security-mvc-custom/src/main/resources/logback.xml b/spring-security-mvc-custom/src/main/resources/logback.xml index 1146dade63..ec0dc2469a 100644 --- a/spring-security-mvc-custom/src/main/resources/logback.xml +++ b/spring-security-mvc-custom/src/main/resources/logback.xml @@ -1,20 +1,19 @@ + + + + web - %date [%thread] %-5level %logger{36} - %message%n + + + - - - web - %date [%thread] %-5level %logger{36} - %message%n - - - + + - - - - - - - - - + + + + + \ No newline at end of file diff --git a/spring-security-mvc-digest-auth/src/main/resources/logback.xml b/spring-security-mvc-digest-auth/src/main/resources/logback.xml index 1146dade63..ec0dc2469a 100644 --- a/spring-security-mvc-digest-auth/src/main/resources/logback.xml +++ b/spring-security-mvc-digest-auth/src/main/resources/logback.xml @@ -1,20 +1,19 @@ + + + + web - %date [%thread] %-5level %logger{36} - %message%n + + + - - - web - %date [%thread] %-5level %logger{36} - %message%n - - - + + - - - - - - - - - + + + + + \ No newline at end of file diff --git a/spring-security-mvc-ldap/src/main/resources/logback.xml b/spring-security-mvc-ldap/src/main/resources/logback.xml index 2dc76c96f3..ec0dc2469a 100644 --- a/spring-security-mvc-ldap/src/main/resources/logback.xml +++ b/spring-security-mvc-ldap/src/main/resources/logback.xml @@ -1,22 +1,19 @@ + + + + web - %date [%thread] %-5level %logger{36} - %message%n + + + - - - web - %date [%thread] %-5level %logger{36} - %message%n - - - + + - - - - - - - - - - - + + + + + \ No newline at end of file diff --git a/spring-security-mvc-login/src/main/resources/logback.xml b/spring-security-mvc-login/src/main/resources/logback.xml index 1146dade63..ec0dc2469a 100644 --- a/spring-security-mvc-login/src/main/resources/logback.xml +++ b/spring-security-mvc-login/src/main/resources/logback.xml @@ -1,20 +1,19 @@ + + + + web - %date [%thread] %-5level %logger{36} - %message%n + + + - - - web - %date [%thread] %-5level %logger{36} - %message%n - - - + + - - - - - - - - - + + + + + \ No newline at end of file diff --git a/spring-security-mvc-persisted-remember-me/src/main/resources/logback.xml b/spring-security-mvc-persisted-remember-me/src/main/resources/logback.xml index 1146dade63..ec0dc2469a 100644 --- a/spring-security-mvc-persisted-remember-me/src/main/resources/logback.xml +++ b/spring-security-mvc-persisted-remember-me/src/main/resources/logback.xml @@ -1,20 +1,19 @@ + + + + web - %date [%thread] %-5level %logger{36} - %message%n + + + - - - web - %date [%thread] %-5level %logger{36} - %message%n - - - + + - - - - - - - - - + + + + + \ No newline at end of file diff --git a/spring-security-mvc-session/src/main/resources/logback.xml b/spring-security-mvc-session/src/main/resources/logback.xml index 1146dade63..ec0dc2469a 100644 --- a/spring-security-mvc-session/src/main/resources/logback.xml +++ b/spring-security-mvc-session/src/main/resources/logback.xml @@ -1,20 +1,19 @@ + + + + web - %date [%thread] %-5level %logger{36} - %message%n + + + - - - web - %date [%thread] %-5level %logger{36} - %message%n - - - + + - - - - - - - - - + + + + + \ No newline at end of file diff --git a/spring-security-rest-basic-auth/src/main/resources/logback.xml b/spring-security-rest-basic-auth/src/main/resources/logback.xml index 90f61a95bc..ec0dc2469a 100644 --- a/spring-security-rest-basic-auth/src/main/resources/logback.xml +++ b/spring-security-rest-basic-auth/src/main/resources/logback.xml @@ -1,22 +1,19 @@ + + + + web - %date [%thread] %-5level %logger{36} - %message%n + + + - - - web - %date [%thread] %-5level %logger{36} - %message%n - - - + + - - - - - - - - - - - + + + + + \ No newline at end of file diff --git a/spring-security-rest-custom/src/main/resources/logback.xml b/spring-security-rest-custom/src/main/resources/logback.xml index 1146dade63..ec0dc2469a 100644 --- a/spring-security-rest-custom/src/main/resources/logback.xml +++ b/spring-security-rest-custom/src/main/resources/logback.xml @@ -1,20 +1,19 @@ + + + + web - %date [%thread] %-5level %logger{36} - %message%n + + + - - - web - %date [%thread] %-5level %logger{36} - %message%n - - - + + - - - - - - - - - + + + + + \ No newline at end of file diff --git a/spring-security-rest-digest-auth/src/main/resources/logback.xml b/spring-security-rest-digest-auth/src/main/resources/logback.xml index 90f61a95bc..ec0dc2469a 100644 --- a/spring-security-rest-digest-auth/src/main/resources/logback.xml +++ b/spring-security-rest-digest-auth/src/main/resources/logback.xml @@ -1,22 +1,19 @@ + + + + web - %date [%thread] %-5level %logger{36} - %message%n + + + - - - web - %date [%thread] %-5level %logger{36} - %message%n - - - + + - - - - - - - - - - - + + + + + \ No newline at end of file diff --git a/spring-security-rest-full/src/main/resources/logback.xml b/spring-security-rest-full/src/main/resources/logback.xml index 1146dade63..ec0dc2469a 100644 --- a/spring-security-rest-full/src/main/resources/logback.xml +++ b/spring-security-rest-full/src/main/resources/logback.xml @@ -1,20 +1,19 @@ + + + + web - %date [%thread] %-5level %logger{36} - %message%n + + + - - - web - %date [%thread] %-5level %logger{36} - %message%n - - - + + - - - - - - - - - + + + + + \ No newline at end of file diff --git a/spring-security-rest/src/main/resources/logback.xml b/spring-security-rest/src/main/resources/logback.xml index 1146dade63..ec0dc2469a 100644 --- a/spring-security-rest/src/main/resources/logback.xml +++ b/spring-security-rest/src/main/resources/logback.xml @@ -1,20 +1,19 @@ + + + + web - %date [%thread] %-5level %logger{36} - %message%n + + + - - - web - %date [%thread] %-5level %logger{36} - %message%n - - - + + - - - - - - - - - + + + + + \ No newline at end of file diff --git a/spring-thymeleaf/src/main/resources/logback.xml b/spring-thymeleaf/src/main/resources/logback.xml index 1146dade63..ec0dc2469a 100644 --- a/spring-thymeleaf/src/main/resources/logback.xml +++ b/spring-thymeleaf/src/main/resources/logback.xml @@ -1,20 +1,19 @@ + + + + web - %date [%thread] %-5level %logger{36} - %message%n + + + - - - web - %date [%thread] %-5level %logger{36} - %message%n - - - + + - - - - - - - - - + + + + + \ No newline at end of file diff --git a/testng/src/test/resources/logback.xml b/testng/src/test/resources/logback.xml index 346682f033..035520aa15 100644 --- a/testng/src/test/resources/logback.xml +++ b/testng/src/test/resources/logback.xml @@ -1,5 +1,5 @@ + - web - %date [%thread] %-5level %logger{36} - %message%n @@ -7,8 +7,13 @@ + + + + + + - \ No newline at end of file diff --git a/vertx/src/main/resources/logback.xml b/vertx/src/main/resources/logback.xml index e9ae1894a6..ec0dc2469a 100644 --- a/vertx/src/main/resources/logback.xml +++ b/vertx/src/main/resources/logback.xml @@ -1,5 +1,5 @@ + - web - %date [%thread] %-5level %logger{36} - %message%n @@ -7,8 +7,13 @@ + + + + + + - \ No newline at end of file diff --git a/xstream/pom.xml b/xstream/pom.xml index 3e8aaafc06..ee1882850a 100644 --- a/xstream/pom.xml +++ b/xstream/pom.xml @@ -26,6 +26,24 @@ ${junit.version} + + org.slf4j + slf4j-api + ${org.slf4j.version} + + + + ch.qos.logback + logback-classic + ${logback.version} + + + + ch.qos.logback + logback-core + ${logback.version} + + @@ -46,6 +64,9 @@ 1.4.9 1.3.8 + 1.7.21 + 1.1.7 + 4.12 diff --git a/xstream/src/main/resources/logback.xml b/xstream/src/main/resources/logback.xml new file mode 100644 index 0000000000..ec0dc2469a --- /dev/null +++ b/xstream/src/main/resources/logback.xml @@ -0,0 +1,19 @@ + + + + + web - %date [%thread] %-5level %logger{36} - %message%n + + + + + + + + + + + + + + \ No newline at end of file From 576298dc7b4ce73322ed1929e3dfa078c68886ed Mon Sep 17 00:00:00 2001 From: Tomasz Lelek Date: Mon, 17 Apr 2017 20:32:03 +0200 Subject: [PATCH 12/19] Bael 779 kotlin generics (#1614) * Kotlin Generics code * wrote rest of the tests * sorting impl * proper val name * fix typo --- .../com/baeldung/kotlin/GenericsTest.kt | 148 ++++++++++++++++++ 1 file changed, 148 insertions(+) create mode 100644 kotlin/src/test/kotlin/com/baeldung/kotlin/GenericsTest.kt diff --git a/kotlin/src/test/kotlin/com/baeldung/kotlin/GenericsTest.kt b/kotlin/src/test/kotlin/com/baeldung/kotlin/GenericsTest.kt new file mode 100644 index 0000000000..c2e5ca4195 --- /dev/null +++ b/kotlin/src/test/kotlin/com/baeldung/kotlin/GenericsTest.kt @@ -0,0 +1,148 @@ +package com.baeldung.kotlin + +import org.junit.Test +import kotlin.test.assertEquals +import kotlin.test.assertTrue + +class GenericsTest { + + @Test + fun givenParametrizeClass_whenInitializeItWithSpecificType_thenShouldBeParameterized() { + //given + val parameterizedClass = ParameterizedClass("string-value") + + //when + val res = parameterizedClass.getValue() + + //then + assertTrue(res is String) + } + + @Test + fun givenParametrizeClass_whenInitializeIt_thenShouldBeParameterizedByInferredType() { + //given + val parameterizedClass = ParameterizedClass("string-value") + + //when + val res = parameterizedClass.getValue() + + //then + assertTrue(res is String) + } + + @Test + fun givenParameterizedProducerByOutKeyword_whenGetValue_thenCanAssignItToSuperType() { + //given + val parameterizedProducer = ParameterizedProducer("string") + + //when + val ref: ParameterizedProducer = parameterizedProducer + + //then + assertTrue(ref is ParameterizedProducer) + } + + @Test + fun givenParameterizedConsumerByInKeyword_whenGetValue_thenCanAssignItToSubType() { + //given + val parameterizedConsumer = ParameterizedConsumer() + + //when + val ref: ParameterizedConsumer = parameterizedConsumer + + //then + assertTrue(ref is ParameterizedConsumer) + } + + @Test + fun givenTypeProjections_whenOperateOnTwoList_thenCanAcceptListOfSubtypes() { + //given + val ints: Array = arrayOf(1, 2, 3) + val any: Array = arrayOfNulls(3) + + //when + copy(ints, any) + + //then + assertEquals(any[0], 1) + assertEquals(any[1], 2) + assertEquals(any[2], 3) + + } + + fun copy(from: Array, to: Array) { + assert(from.size == to.size) + for (i in from.indices) + to[i] = from[i] + } + + @Test + fun givenTypeProjection_whenHaveArrayOfIn_thenShouldAddElementsOfSubtypesToIt() { + //given + val objects: Array = arrayOfNulls(1) + + //when + fill(objects, 1) + + //then + assertEquals(objects[0], 1) + } + + fun fill(dest: Array, value: Int) { + dest[0] = value + } + + @Test + fun givenStartProjection_whenPassAnyType_thenCompile() { + //given + val array = arrayOf(1,2,3) + + //then + printArray(array) + + } + + fun printArray(array: Array<*>) { + array.forEach { println(it) } + } + + @Test + fun givenFunctionWithDefinedGenericConstraints_whenCallWithProperType_thenCompile(){ + //given + val listOfInts = listOf(5,2,3,4,1) + + //when + val sorted = sort(listOfInts) + + //then + assertEquals(sorted[0], 1) + assertEquals(sorted[1], 2) + assertEquals(sorted[2], 3) + assertEquals(sorted[3], 4) + assertEquals(sorted[4], 5) + + } + + fun > sort(list: List): List{ + return list.sorted() + } + + class ParameterizedClass(private val value: A) { + + fun getValue(): A { + return value + } + } + + class ParameterizedProducer(private val value: T) { + fun get(): T { + return value + } + } + + class ParameterizedConsumer { + fun toString(value: T): String { + return value.toString() + } + } +} From a1e7463a4243bcf8a6b2914826527bfe56165616 Mon Sep 17 00:00:00 2001 From: Tehreem Date: Mon, 17 Apr 2017 23:59:38 +0500 Subject: [PATCH 13/19] Spring Cloud Zookeeper Updated (#1665) * Spring Cloud Zookeeper * Spring Cloud Zookeeper Updated * Spring Cloud Zookeeper Updated * Spring Cloud Zookeeper Updated --- .../baeldung/spring/cloud/greeting/GreetingController.java | 6 ++---- .../spring/cloud/helloworld/HelloWorldController.java | 5 ++--- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/spring-cloud/spring-cloud-zookeeper/Greeting/src/main/java/com/baeldung/spring/cloud/greeting/GreetingController.java b/spring-cloud/spring-cloud-zookeeper/Greeting/src/main/java/com/baeldung/spring/cloud/greeting/GreetingController.java index d98e22f822..84792deed1 100644 --- a/spring-cloud/spring-cloud-zookeeper/Greeting/src/main/java/com/baeldung/spring/cloud/greeting/GreetingController.java +++ b/spring-cloud/spring-cloud-zookeeper/Greeting/src/main/java/com/baeldung/spring/cloud/greeting/GreetingController.java @@ -6,8 +6,7 @@ package com.baeldung.spring.cloud.greeting; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @RestController @@ -16,8 +15,7 @@ public class GreetingController { @Autowired private HelloWorldClient helloWorldClient; - @RequestMapping(value = "/get-greeting", method = RequestMethod.GET) - + @GetMapping("/get-greeting") public String greeting() { return helloWorldClient.HelloWorld(); diff --git a/spring-cloud/spring-cloud-zookeeper/HelloWorld/src/main/java/com/baeldung/spring/cloud/helloworld/HelloWorldController.java b/spring-cloud/spring-cloud-zookeeper/HelloWorld/src/main/java/com/baeldung/spring/cloud/helloworld/HelloWorldController.java index 9048e6bed8..6c662e1111 100644 --- a/spring-cloud/spring-cloud-zookeeper/HelloWorld/src/main/java/com/baeldung/spring/cloud/helloworld/HelloWorldController.java +++ b/spring-cloud/spring-cloud-zookeeper/HelloWorld/src/main/java/com/baeldung/spring/cloud/helloworld/HelloWorldController.java @@ -5,14 +5,13 @@ */ package com.baeldung.spring.cloud.helloworld; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @RestController public class HelloWorldController { - @RequestMapping(path = "/helloworld", method = RequestMethod.GET) + @GetMapping("/helloworld") public String HelloWorld() { return "Hello World!"; } From 874f3a09291a2c395328eca8e6666c0c78379aa6 Mon Sep 17 00:00:00 2001 From: KevinGilmore Date: Mon, 17 Apr 2017 21:20:20 -0500 Subject: [PATCH 14/19] BAEL-766 README.md update (#1668) * Add files via upload * Update pom.xml * Update RunGuice.java * Update Communication.java * Update CommunicationMode.java * Update DefaultCommunicator.java * Update EmailCommunicationMode.java * Update IMCommunicationMode.java * Update SMSCommunicationMode.java * Update MessageLogger.java * Update MessageSentLoggable.java * Update AOPModule.java * Update BasicModule.java * Update CommunicationModel.java * Update Communicator.java * Update BasicModule.java * Update RunGuice.java * Update MessageLogger.java * Update Communicator.java * Update pom.xml * BAEL-278: Updated README.md * BAEL-554: Add and update README.md files * Update pom.xml * Update pom.xml * Update pom.xml * BAEL-345: fixed assertion * BAEL-109: Updated README.md * BAEL-345: Added README.md * Reinstating reactor-core module in root-level pom * BAEL-393: Adding guide-intro module to root pom * BAEL-9: Updated README.md * BAEL-157: README.md updated * Changed project name * Update RunGuice.java Removed references to message logging and output * Update Communication.java Removed message logging-related code * BAEL-566: Updated README.md * New project name * BAEL-393: removing guice-intro directory * BAEL-393: renamed module guice-intro to guice in root pom.xml * BAEL-393 and BAEL-541 README.md files * BAEL-731: Updated README.md * BAEL-680: renamed test methods * BAEL-714: Updated README.md * BAEL-737: Updated README.md * BAEL-680 and BAEL-756 README.md updates * BAEL-666: Updated README * BAEL-415: Custom Scope * BAEL-415: Custom Scope - renamed classes to reflect TenantScope * README file updates for BAEL-723, BAEL-763, and BAEL-415 * BAEL-735: README * BAEL-567: README * BAEL-736: README * BAEL-766: Update README --- libraries/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libraries/README.md b/libraries/README.md index 7d95caa6b1..8a32a8b0e7 100644 --- a/libraries/README.md +++ b/libraries/README.md @@ -5,7 +5,8 @@ - [String Processing with Apache Commons Lang 3](http://www.baeldung.com/string-processing-commons-lang) - [Introduction to Javatuples](http://www.baeldung.com/java-tuples) - [Introduction to Javassist](http://www.baeldung.com/javassist) -- [Embedded Jetty Server in Java](http://www.baeldung.com/jetty-embedded) +- [Embedded Jetty Server in Java](http://www.baeldung.com/jetty-embedded) +- [Introduction to Apache Flink with Java](http://www.baeldung.com/apache-flink) The libraries module contains examples related to small libraries that are relatively easy to use and does not require any separate module of its own. From 7d6bf2909254f1b01ae44fea697b06819d24e569 Mon Sep 17 00:00:00 2001 From: Mohamed Sanaulla Date: Tue, 18 Apr 2017 10:10:39 +0300 Subject: [PATCH 15/19] sample code for update to BAEL-743 (#1669) --- spring-rest/pom.xml | 9 ++- .../BazzNewMappingsExampleController.java | 55 +++++++++++++ .../main/java/org/baeldung/web/dto/Bazz.java | 22 +++++ .../BazzNewMappingsExampleControllerTest.java | 80 +++++++++++++++++++ 4 files changed, 165 insertions(+), 1 deletion(-) create mode 100644 spring-rest/src/main/java/org/baeldung/web/controller/BazzNewMappingsExampleController.java create mode 100644 spring-rest/src/main/java/org/baeldung/web/dto/Bazz.java create mode 100644 spring-rest/src/test/java/org/baeldung/web/test/BazzNewMappingsExampleControllerTest.java diff --git a/spring-rest/pom.xml b/spring-rest/pom.xml index a9b208bcd2..6afe4004c3 100644 --- a/spring-rest/pom.xml +++ b/spring-rest/pom.xml @@ -188,6 +188,12 @@ kryo ${kryo.version} + + + com.jayway.jsonpath + json-path + + @@ -358,7 +364,8 @@ 3.4.1 - + + 2.2.0 diff --git a/spring-rest/src/main/java/org/baeldung/web/controller/BazzNewMappingsExampleController.java b/spring-rest/src/main/java/org/baeldung/web/controller/BazzNewMappingsExampleController.java new file mode 100644 index 0000000000..4bcafc04fc --- /dev/null +++ b/spring-rest/src/main/java/org/baeldung/web/controller/BazzNewMappingsExampleController.java @@ -0,0 +1,55 @@ +package org.baeldung.web.controller; + +import java.util.Arrays; +import java.util.List; + +import org.baeldung.web.dto.Bazz; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import com.fasterxml.jackson.core.JsonProcessingException; + +@RestController +@RequestMapping("/bazz") +public class BazzNewMappingsExampleController { + + @GetMapping + public ResponseEntity getBazzs() throws JsonProcessingException{ + List data = Arrays.asList( + new Bazz("1", "Bazz1"), + new Bazz("2", "Bazz2"), + new Bazz("3", "Bazz3"), + new Bazz("4", "Bazz4")); + return new ResponseEntity<>(data, HttpStatus.OK); + } + + @GetMapping("/{id}") + public ResponseEntity getBazz(@PathVariable String id){ + return new ResponseEntity<>(new Bazz(id, "Bazz"+id), HttpStatus.OK); + } + + @PostMapping + public ResponseEntity newBazz(@RequestParam("name") String name){ + return new ResponseEntity<>(new Bazz("5", name), HttpStatus.OK); + } + + @PutMapping("/{id}") + public ResponseEntity updateBazz(@PathVariable String id, + @RequestParam("name") String name){ + return new ResponseEntity<>(new Bazz(id, name), HttpStatus.OK); + } + + @DeleteMapping("/{id}") + public ResponseEntity deleteBazz(@PathVariable String id){ + return new ResponseEntity<>(new Bazz(id), HttpStatus.OK); + } + +} diff --git a/spring-rest/src/main/java/org/baeldung/web/dto/Bazz.java b/spring-rest/src/main/java/org/baeldung/web/dto/Bazz.java new file mode 100644 index 0000000000..d9a495b726 --- /dev/null +++ b/spring-rest/src/main/java/org/baeldung/web/dto/Bazz.java @@ -0,0 +1,22 @@ +package org.baeldung.web.dto; + +public class Bazz { + + + public String id; + public String name; + + public Bazz(String id){ + this.id = id; + } + public Bazz(String id, String name) { + this.id = id; + this.name = name; + } + + @Override + public String toString() { + return "Bazz [id=" + id + ", name=" + name + "]"; + } + +} diff --git a/spring-rest/src/test/java/org/baeldung/web/test/BazzNewMappingsExampleControllerTest.java b/spring-rest/src/test/java/org/baeldung/web/test/BazzNewMappingsExampleControllerTest.java new file mode 100644 index 0000000000..f2f00a40d8 --- /dev/null +++ b/spring-rest/src/test/java/org/baeldung/web/test/BazzNewMappingsExampleControllerTest.java @@ -0,0 +1,80 @@ + +package org.baeldung.web.test; + +import static org.hamcrest.Matchers.hasSize; +import static org.hamcrest.Matchers.is; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import org.baeldung.config.WebConfig; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.web.WebAppConfiguration; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.setup.MockMvcBuilders; +import org.springframework.web.context.WebApplicationContext; + + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(classes = WebConfig.class) +@WebAppConfiguration +public class BazzNewMappingsExampleControllerTest { + + private MockMvc mockMvc; + + @Autowired + private WebApplicationContext webApplicationContext; + + @Before + public void setUp() { + mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build(); + } + + @Test + public void whenGettingAllBazz_thenSuccess() throws Exception{ + mockMvc.perform(get("/bazz")) + .andExpect(status().isOk()) + .andExpect(jsonPath("$", hasSize(4))) + .andExpect(jsonPath("$[1].id", is("2"))) + .andExpect(jsonPath("$[1].name", is("Bazz2"))); + } + + @Test + public void whenGettingABazz_thenSuccess() throws Exception{ + mockMvc.perform(get("/bazz/1")) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.id", is("1"))) + .andExpect(jsonPath("$.name", is("Bazz1"))); + } + + @Test + public void whenAddingABazz_thenSuccess() throws Exception{ + mockMvc.perform(post("/bazz").param("name", "Bazz5")) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.id", is("5"))) + .andExpect(jsonPath("$.name", is("Bazz5"))); + } + + @Test + public void whenUpdatingABazz_thenSuccess() throws Exception{ + mockMvc.perform(put("/bazz/5").param("name", "Bazz6")) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.id", is("5"))) + .andExpect(jsonPath("$.name", is("Bazz6"))); + } + + @Test + public void whenDeletingABazz_thenSuccess() throws Exception{ + mockMvc.perform(delete("/bazz/5")) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.id", is("5"))); + } +} From 1aff8ca17d18c5a0c1c95f9c4e53474bea00a898 Mon Sep 17 00:00:00 2001 From: Alexandre Lombard Date: Tue, 18 Apr 2017 09:58:26 +0200 Subject: [PATCH 16/19] BAEL 767 - Introduction to Apache Commons Math (update) (#1670) * BAEL 767 - Introduction to apache commons math * BAEL 767 - Moving examples to test classes * BAEL 767 - Renaming tests with BDD convention --- apache-commons-math/pom.xml | 44 +++++++++++++++++++ .../baeldung/commons/math/ComplexTests.java | 20 +++++++++ .../baeldung/commons/math/FractionTests.java | 20 +++++++++ .../baeldung/commons/math/GeometryTests.java | 21 +++++++++ .../commons/math/IntegrationTests.java | 21 +++++++++ .../commons/math/LinearAlgebraTests.java | 25 +++++++++++ .../commons/math/ProbabilitiesTests.java | 15 +++++++ .../commons/math/RootFindingTests.java | 20 +++++++++ .../commons/math/StatisticsTests.java | 38 ++++++++++++++++ 9 files changed, 224 insertions(+) create mode 100644 apache-commons-math/pom.xml create mode 100644 apache-commons-math/src/test/java/com/baeldung/commons/math/ComplexTests.java create mode 100644 apache-commons-math/src/test/java/com/baeldung/commons/math/FractionTests.java create mode 100644 apache-commons-math/src/test/java/com/baeldung/commons/math/GeometryTests.java create mode 100644 apache-commons-math/src/test/java/com/baeldung/commons/math/IntegrationTests.java create mode 100644 apache-commons-math/src/test/java/com/baeldung/commons/math/LinearAlgebraTests.java create mode 100644 apache-commons-math/src/test/java/com/baeldung/commons/math/ProbabilitiesTests.java create mode 100644 apache-commons-math/src/test/java/com/baeldung/commons/math/RootFindingTests.java create mode 100644 apache-commons-math/src/test/java/com/baeldung/commons/math/StatisticsTests.java diff --git a/apache-commons-math/pom.xml b/apache-commons-math/pom.xml new file mode 100644 index 0000000000..98c6953120 --- /dev/null +++ b/apache-commons-math/pom.xml @@ -0,0 +1,44 @@ + + + 4.0.0 + + com.baeldung + apache-commons-math + 1.0-SNAPSHOT + + + 3.6.0 + + + + + + org.apache.maven.plugins + maven-compiler-plugin + ${maven-compiler-plugin.version} + + 1.8 + 1.8 + + + + + + + + org.apache.commons + commons-math3 + 3.6.1 + + + + junit + junit + 4.12 + test + + + + \ No newline at end of file diff --git a/apache-commons-math/src/test/java/com/baeldung/commons/math/ComplexTests.java b/apache-commons-math/src/test/java/com/baeldung/commons/math/ComplexTests.java new file mode 100644 index 0000000000..2e5074453e --- /dev/null +++ b/apache-commons-math/src/test/java/com/baeldung/commons/math/ComplexTests.java @@ -0,0 +1,20 @@ +package com.baeldung.commons.math; + +import org.apache.commons.math3.complex.Complex; +import org.junit.Assert; +import org.junit.Test; + +public class ComplexTests { + + @Test + public void whenComplexPow_thenCorrect() { + Complex first = new Complex(1.0, 3.0); + Complex second = new Complex(2.0, 5.0); + + Complex power = first.pow(second); + + Assert.assertEquals(-0.007563724861696302, power.getReal(), 1e-7); + Assert.assertEquals(0.01786136835085382, power.getImaginary(), 1e-7); + } + +} diff --git a/apache-commons-math/src/test/java/com/baeldung/commons/math/FractionTests.java b/apache-commons-math/src/test/java/com/baeldung/commons/math/FractionTests.java new file mode 100644 index 0000000000..6efef79b23 --- /dev/null +++ b/apache-commons-math/src/test/java/com/baeldung/commons/math/FractionTests.java @@ -0,0 +1,20 @@ +package com.baeldung.commons.math; + +import org.apache.commons.math3.fraction.Fraction; +import org.apache.commons.math3.fraction.FractionFormat; +import org.junit.Assert; +import org.junit.Test; + +public class FractionTests { + + @Test + public void whenFractionAdd_thenCorrect() { + Fraction lhs = new Fraction(1, 3); + Fraction rhs = new Fraction(2, 5); + Fraction sum = lhs.add(rhs); + + Assert.assertEquals(11, sum.getNumerator()); + Assert.assertEquals(15, sum.getDenominator()); + } + +} diff --git a/apache-commons-math/src/test/java/com/baeldung/commons/math/GeometryTests.java b/apache-commons-math/src/test/java/com/baeldung/commons/math/GeometryTests.java new file mode 100644 index 0000000000..17cbb607d6 --- /dev/null +++ b/apache-commons-math/src/test/java/com/baeldung/commons/math/GeometryTests.java @@ -0,0 +1,21 @@ +package com.baeldung.commons.math; + +import org.apache.commons.math3.geometry.euclidean.twod.Line; +import org.apache.commons.math3.geometry.euclidean.twod.Vector2D; +import org.junit.Assert; +import org.junit.Test; + +public class GeometryTests { + + @Test + public void whenLineIntersection_thenCorrect() { + Line l1 = new Line(new Vector2D(0, 0), new Vector2D(1, 1), 0); + Line l2 = new Line(new Vector2D(0, 1), new Vector2D(1, 1.5), 0); + + Vector2D intersection = l1.intersection(l2); + + Assert.assertEquals(2, intersection.getX(), 1e-7); + Assert.assertEquals(2, intersection.getY(), 1e-7); + } + +} diff --git a/apache-commons-math/src/test/java/com/baeldung/commons/math/IntegrationTests.java b/apache-commons-math/src/test/java/com/baeldung/commons/math/IntegrationTests.java new file mode 100644 index 0000000000..62ae898fa8 --- /dev/null +++ b/apache-commons-math/src/test/java/com/baeldung/commons/math/IntegrationTests.java @@ -0,0 +1,21 @@ +package com.baeldung.commons.math; + +import org.apache.commons.math3.analysis.UnivariateFunction; +import org.apache.commons.math3.analysis.integration.SimpsonIntegrator; +import org.apache.commons.math3.analysis.integration.UnivariateIntegrator; +import org.junit.Assert; +import org.junit.Test; + +public class IntegrationTests { + + @Test + public void whenUnivariateIntegratorIntegrate_thenCorrect() { + final UnivariateFunction function = v -> v; + final UnivariateIntegrator integrator = new SimpsonIntegrator(1.0e-12, 1.0e-8, 1, 32); + + final double i = integrator.integrate(100, function, 0, 10); + + Assert.assertEquals(16 + 2d/3d, i, 1e-7); + } + +} diff --git a/apache-commons-math/src/test/java/com/baeldung/commons/math/LinearAlgebraTests.java b/apache-commons-math/src/test/java/com/baeldung/commons/math/LinearAlgebraTests.java new file mode 100644 index 0000000000..981f839280 --- /dev/null +++ b/apache-commons-math/src/test/java/com/baeldung/commons/math/LinearAlgebraTests.java @@ -0,0 +1,25 @@ +package com.baeldung.commons.math; + +import org.apache.commons.math3.linear.*; +import org.junit.Assert; +import org.junit.Test; + +public class LinearAlgebraTests { + + @Test + public void whenDecompositionSolverSolve_thenCorrect() { + RealMatrix a = + new Array2DRowRealMatrix(new double[][] { { 2, 3, -2 }, { -1, 7, 6 }, { 4, -3, -5 } }, + false); + RealVector b = new ArrayRealVector(new double[] { 1, -2, 1 }, false); + + DecompositionSolver solver = new LUDecomposition(a).getSolver(); + + RealVector solution = solver.solve(b); + + Assert.assertEquals(-0.3698630137, solution.getEntry(0), 1e-7); + Assert.assertEquals(0.1780821918, solution.getEntry(1), 1e-7); + Assert.assertEquals(-0.602739726, solution.getEntry(2), 1e-7); + } + +} diff --git a/apache-commons-math/src/test/java/com/baeldung/commons/math/ProbabilitiesTests.java b/apache-commons-math/src/test/java/com/baeldung/commons/math/ProbabilitiesTests.java new file mode 100644 index 0000000000..41ccb16c5a --- /dev/null +++ b/apache-commons-math/src/test/java/com/baeldung/commons/math/ProbabilitiesTests.java @@ -0,0 +1,15 @@ +package com.baeldung.commons.math; + +import org.apache.commons.math3.distribution.NormalDistribution; +import org.junit.Test; + +public class ProbabilitiesTests { + + @Test + public void whenNormalDistributionSample_thenSuccess() { + final NormalDistribution normalDistribution = new NormalDistribution(10, 3); + + System.out.println(normalDistribution.sample()); + } + +} diff --git a/apache-commons-math/src/test/java/com/baeldung/commons/math/RootFindingTests.java b/apache-commons-math/src/test/java/com/baeldung/commons/math/RootFindingTests.java new file mode 100644 index 0000000000..3e6b542c01 --- /dev/null +++ b/apache-commons-math/src/test/java/com/baeldung/commons/math/RootFindingTests.java @@ -0,0 +1,20 @@ +package com.baeldung.commons.math; + +import org.apache.commons.math3.analysis.UnivariateFunction; +import org.apache.commons.math3.analysis.solvers.BracketingNthOrderBrentSolver; +import org.apache.commons.math3.analysis.solvers.UnivariateSolver; +import org.junit.Assert; +import org.junit.Test; + +public class RootFindingTests { + + @Test + public void whenUnivariateSolverSolver_thenCorrect() { + final UnivariateFunction function = v -> Math.pow(v, 2) - 2; + UnivariateSolver solver = new BracketingNthOrderBrentSolver(1.0e-12, 1.0e-8, 5); + double c = solver.solve(100, function, -10.0, 10.0, 0); + + Assert.assertEquals(-Math.sqrt(2), c, 1e-7); + } + +} diff --git a/apache-commons-math/src/test/java/com/baeldung/commons/math/StatisticsTests.java b/apache-commons-math/src/test/java/com/baeldung/commons/math/StatisticsTests.java new file mode 100644 index 0000000000..c1b0619b11 --- /dev/null +++ b/apache-commons-math/src/test/java/com/baeldung/commons/math/StatisticsTests.java @@ -0,0 +1,38 @@ +package com.baeldung.commons.math; + +import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +public class StatisticsTests { + + private double[] values; + private DescriptiveStatistics descriptiveStatistics; + + @Before + public void setUp() { + values = new double[] {65, 51 , 16, 11 , 6519, 191 ,0 , 98, 19854, 1, 32}; + + descriptiveStatistics = new DescriptiveStatistics(); + for(double v : values) { + descriptiveStatistics.addValue(v); + } + } + + @Test + public void whenDescriptiveStatisticsGetMean_thenCorrect() { + Assert.assertEquals(2439.8181818181815, descriptiveStatistics.getMean(), 1e-7); + } + + @Test + public void whenDescriptiveStatisticsGetMedian_thenCorrect() { + Assert.assertEquals(51, descriptiveStatistics.getPercentile(50), 1e-7); + } + + @Test + public void whenDescriptiveStatisticsGetStandardDeviation_thenCorrect() { + Assert.assertEquals(6093.054649651221, descriptiveStatistics.getStandardDeviation(), 1e-7); + } + +} From 6c181db567681349d135c8076be4abbcaaed3a45 Mon Sep 17 00:00:00 2001 From: eugenp Date: Tue, 18 Apr 2017 11:27:58 +0300 Subject: [PATCH 17/19] minor formatting cleanuop --- .../mybatis/mapper/AddressMapper.java | 23 +- .../baeldung/mybatis/mapper/PersonMapper.java | 51 ++--- .../com/baeldung/mybatis/model/Address.java | 63 +++--- .../com/baeldung/mybatis/model/Person.java | 52 ++--- .../baeldung/mybatis/utils/MyBatisUtil.java | 52 ++--- .../mybatis/mapper/PersonMapperTest.java | 202 +++++++++--------- 6 files changed, 215 insertions(+), 228 deletions(-) diff --git a/mybatis/src/main/java/com/baeldung/mybatis/mapper/AddressMapper.java b/mybatis/src/main/java/com/baeldung/mybatis/mapper/AddressMapper.java index 588707383b..e96a4837db 100644 --- a/mybatis/src/main/java/com/baeldung/mybatis/mapper/AddressMapper.java +++ b/mybatis/src/main/java/com/baeldung/mybatis/mapper/AddressMapper.java @@ -4,21 +4,18 @@ import com.baeldung.mybatis.model.Address; import com.baeldung.mybatis.model.Person; import org.apache.ibatis.annotations.*; - public interface AddressMapper { - @Insert("Insert into address (streetAddress,personId) values(#{streetAddress},#{personId})") - @Options(useGeneratedKeys = true,flushCache=true ) - public Integer saveAddress(Address address); + @Insert("Insert into address (streetAddress,personId) values(#{streetAddress},#{personId})") + @Options(useGeneratedKeys = true, flushCache = true) + public Integer saveAddress(Address address); - @Select("SELECT addressId, streetAddress FROM Address WHERE addressId = #{addressId}") - @Results(value = { - @Result(property = "addressId", column = "addressId"), - @Result(property = "streetAddress", column = "streetAddress"), - @Result(property = "person", column = "personId",javaType =Person.class,one=@One(select = "getPerson")) - }) - Address getAddresses(Integer addressID); + @Select("SELECT addressId, streetAddress FROM Address WHERE addressId = #{addressId}") + @Results(value = { @Result(property = "addressId", column = "addressId"), + @Result(property = "streetAddress", column = "streetAddress"), + @Result(property = "person", column = "personId", javaType = Person.class, one = @One(select = "getPerson")) }) + Address getAddresses(Integer addressID); - @Select("SELECT personId FROM address WHERE addressId = #{addressId})") - Person getPerson(Integer personId); + @Select("SELECT personId FROM address WHERE addressId = #{addressId})") + Person getPerson(Integer personId); } diff --git a/mybatis/src/main/java/com/baeldung/mybatis/mapper/PersonMapper.java b/mybatis/src/main/java/com/baeldung/mybatis/mapper/PersonMapper.java index ab207325ad..7021777ed1 100644 --- a/mybatis/src/main/java/com/baeldung/mybatis/mapper/PersonMapper.java +++ b/mybatis/src/main/java/com/baeldung/mybatis/mapper/PersonMapper.java @@ -9,44 +9,39 @@ import org.apache.ibatis.mapping.StatementType; import java.util.List; import java.util.Map; - public interface PersonMapper { - @Insert("Insert into person(name) values (#{name})") - public Integer save(Person person); + @Insert("Insert into person(name) values (#{name})") + public Integer save(Person person); - @Update("Update Person set name= #{name} where personId=#{personId}") - public void updatePerson(Person person); + @Update("Update Person set name= #{name} where personId=#{personId}") + public void updatePerson(Person person); - @Delete("Delete from Person where personId=#{personId}") - public void deletePersonById(Integer personId); + @Delete("Delete from Person where personId=#{personId}") + public void deletePersonById(Integer personId); - @Select("SELECT person.personId, person.name FROM person WHERE person.personId = #{personId}") - Person getPerson(Integer personId); + @Select("SELECT person.personId, person.name FROM person WHERE person.personId = #{personId}") + Person getPerson(Integer personId); - @Select("Select personId,name from Person where personId=#{personId}") - @Results(value ={ - @Result(property = "personId", column = "personId"), - @Result(property="name", column = "name"), - @Result(property = "addresses",javaType = List.class,column = "personId", - many=@Many(select = "getAddresses")) + @Select("Select personId,name from Person where personId=#{personId}") + @Results(value = { @Result(property = "personId", column = "personId"), @Result(property = "name", column = "name"), + @Result(property = "addresses", javaType = List.class, column = "personId", many = @Many(select = "getAddresses")) - }) - public Person getPersonById(Integer personId); + }) + public Person getPersonById(Integer personId); - @Select("select addressId,streetAddress,personId from address where personId=#{personId}") - public Address getAddresses(Integer personId); + @Select("select addressId,streetAddress,personId from address where personId=#{personId}") + public Address getAddresses(Integer personId); - @Select("select * from Person ") - @MapKey("personId") - Map getAllPerson(); + @Select("select * from Person ") + @MapKey("personId") + Map getAllPerson(); - @SelectProvider(type=MyBatisUtil.class,method="getPersonByName") - public Person getPersonByName(String name); + @SelectProvider(type = MyBatisUtil.class, method = "getPersonByName") + public Person getPersonByName(String name); - - @Select(value= "{ CALL getPersonByProc( #{personId, mode=IN, jdbcType=INTEGER})}") - @Options(statementType = StatementType.CALLABLE) - public Person getPersonByProc(Integer personId); + @Select(value = "{ CALL getPersonByProc( #{personId, mode=IN, jdbcType=INTEGER})}") + @Options(statementType = StatementType.CALLABLE) + public Person getPersonByProc(Integer personId); } diff --git a/mybatis/src/main/java/com/baeldung/mybatis/model/Address.java b/mybatis/src/main/java/com/baeldung/mybatis/model/Address.java index f32e47aef2..ea9a91c666 100644 --- a/mybatis/src/main/java/com/baeldung/mybatis/model/Address.java +++ b/mybatis/src/main/java/com/baeldung/mybatis/model/Address.java @@ -1,49 +1,46 @@ package com.baeldung.mybatis.model; - public class Address { - private Integer addressId; - private String streetAddress; - private Integer personId; + private Integer addressId; + private String streetAddress; + private Integer personId; - public Address() { - } + public Address() { + } - public Integer getPersonId() { - return personId; - } + public Integer getPersonId() { + return personId; + } - public void setPersonId(Integer personId) { - this.personId = personId; - } + public void setPersonId(Integer personId) { + this.personId = personId; + } + public Address(String streetAddress) { + this.streetAddress = streetAddress; + } + public Person getPerson() { + return person; + } - public Address(String streetAddress) { - this.streetAddress =streetAddress; - } + public void setPerson(Person person) { + this.person = person; + } - public Person getPerson() { - return person; - } + private Person person; - public void setPerson(Person person) { - this.person = person; - } + public Address(int i, String name) { + this.streetAddress = name; + } - private Person person; + public Integer getAddressId() { + return addressId; + } - public Address(int i, String name) { - this.streetAddress = name; - } - - public Integer getAddressId() { - return addressId; - } - - public String getStreetAddress() { - return streetAddress; - } + public String getStreetAddress() { + return streetAddress; + } } diff --git a/mybatis/src/main/java/com/baeldung/mybatis/model/Person.java b/mybatis/src/main/java/com/baeldung/mybatis/model/Person.java index 248e3ca7a1..2de08a9f7c 100644 --- a/mybatis/src/main/java/com/baeldung/mybatis/model/Person.java +++ b/mybatis/src/main/java/com/baeldung/mybatis/model/Person.java @@ -3,38 +3,38 @@ package com.baeldung.mybatis.model; import java.util.ArrayList; import java.util.List; - public class Person { - private Integer personId; - private String name; - private List
addresses; + private Integer personId; + private String name; + private List
addresses; - public Person() { - } + public Person() { + } - public Person(Integer personId, String name) { - this.personId=personId; - this.name = name; - addresses = new ArrayList
(); - } + public Person(Integer personId, String name) { + this.personId = personId; + this.name = name; + addresses = new ArrayList
(); + } - public Person(String name) { - this.name=name; - } + public Person(String name) { + this.name = name; + } - public Integer getPersonId() { - return personId; - } + public Integer getPersonId() { + return personId; + } - public String getName() { - return name; - } - public void addAddress(Address address){ - addresses.add(address); - } + public String getName() { + return name; + } - public List
getAddresses() { - return addresses; - } + public void addAddress(Address address) { + addresses.add(address); + } + + public List
getAddresses() { + return addresses; + } } diff --git a/mybatis/src/main/java/com/baeldung/mybatis/utils/MyBatisUtil.java b/mybatis/src/main/java/com/baeldung/mybatis/utils/MyBatisUtil.java index cd5291f2d2..fb8e15245a 100644 --- a/mybatis/src/main/java/com/baeldung/mybatis/utils/MyBatisUtil.java +++ b/mybatis/src/main/java/com/baeldung/mybatis/utils/MyBatisUtil.java @@ -16,33 +16,35 @@ import java.io.IOException; import java.io.InputStream; public class MyBatisUtil { - public static final String DRIVER = "org.apache.derby.jdbc.EmbeddedDriver"; - public static final String URL = "jdbc:derby:testdb1;create=true"; - public static final String USERNAME = "sa"; - public static final String PASSWORD = "pass123"; - private static SqlSessionFactory sqlSessionFactory; + public static final String DRIVER = "org.apache.derby.jdbc.EmbeddedDriver"; + public static final String URL = "jdbc:derby:testdb1;create=true"; + public static final String USERNAME = "sa"; + public static final String PASSWORD = "pass123"; + private static SqlSessionFactory sqlSessionFactory; - public static SqlSessionFactory buildqlSessionFactory(){ - DataSource dataSource=new PooledDataSource(DRIVER, URL, USERNAME, PASSWORD); - Environment environment=new Environment("Development",new JdbcTransactionFactory(),dataSource); - Configuration configuration = new Configuration(environment); - configuration.addMapper(PersonMapper.class); - configuration.addMapper(AddressMapper.class); - SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder(); - SqlSessionFactory factory = builder.build(configuration); - return factory; + public static SqlSessionFactory buildqlSessionFactory() { + DataSource dataSource = new PooledDataSource(DRIVER, URL, USERNAME, PASSWORD); + Environment environment = new Environment("Development", new JdbcTransactionFactory(), dataSource); + Configuration configuration = new Configuration(environment); + configuration.addMapper(PersonMapper.class); + configuration.addMapper(AddressMapper.class); + SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder(); + SqlSessionFactory factory = builder.build(configuration); + return factory; - } + } - public static SqlSessionFactory getSqlSessionFactory(){ - return sqlSessionFactory; - } + public static SqlSessionFactory getSqlSessionFactory() { + return sqlSessionFactory; + } - public String getPersonByName(String name){ - return new SQL(){{ - SELECT("*"); - FROM("person"); - WHERE("name like #{name} || '%'"); - }}.toString(); - } + public String getPersonByName(String name) { + return new SQL() { + { + SELECT("*"); + FROM("person"); + WHERE("name like #{name} || '%'"); + } + }.toString(); + } } diff --git a/mybatis/src/test/java/com/baeldung/mybatis/mapper/PersonMapperTest.java b/mybatis/src/test/java/com/baeldung/mybatis/mapper/PersonMapperTest.java index 51888043e9..8dbf7d2589 100644 --- a/mybatis/src/test/java/com/baeldung/mybatis/mapper/PersonMapperTest.java +++ b/mybatis/src/test/java/com/baeldung/mybatis/mapper/PersonMapperTest.java @@ -18,132 +18,128 @@ import static junit.framework.TestCase.assertEquals; public class PersonMapperTest { - SqlSession session; + SqlSession session; - @Before - public void setup() throws SQLException { + @Before + public void setup() throws SQLException { - session = MyBatisUtil.buildqlSessionFactory().openSession(); - createTables(session); + session = MyBatisUtil.buildqlSessionFactory().openSession(); + createTables(session); - } + } - private void createTables(SqlSession session) throws SQLException { + private void createTables(SqlSession session) throws SQLException { - String createPersonTable = "create table person (" - + "personId integer not null generated always as" - + " identity (start with 1, increment by 1), " - + "name varchar(30) not null, " - + "constraint primary_key_person primary key (personId))"; + String createPersonTable = "create table person (" + "personId integer not null generated always as" + + " identity (start with 1, increment by 1), " + "name varchar(30) not null, " + + "constraint primary_key_person primary key (personId))"; - String createAddressTable = "create table address (" - + "addressId integer not null generated always as" - + " identity (start with 1, increment by 1), " - + "streetAddress varchar(300), personId integer, " - + "constraint primary_key_address primary key (addressId))"; + String createAddressTable = "create table address (" + "addressId integer not null generated always as" + + " identity (start with 1, increment by 1), " + "streetAddress varchar(300), personId integer, " + + "constraint primary_key_address primary key (addressId))"; - String alterTable="ALTER TABLE " + - " address ADD CONSTRAINT fk_person FOREIGN KEY (personId) REFERENCES person (personId)"; + String alterTable = "ALTER TABLE " + + " address ADD CONSTRAINT fk_person FOREIGN KEY (personId) REFERENCES person (personId)"; + session.getConnection().createStatement().execute(createPersonTable); + session.getConnection().createStatement().execute(createAddressTable); + session.getConnection().createStatement().execute(alterTable); - session.getConnection().createStatement().execute(createPersonTable); - session.getConnection().createStatement().execute(createAddressTable); - session.getConnection().createStatement().execute(alterTable); + } - } + @Test + public void whenPersonAdressSaved_ThenPersonAddressCanBeQueried() { + Person person = new Person("Baljeet S"); + Address address = new Address("Pune"); + PersonMapper personMapper = session.getMapper(PersonMapper.class); + Integer id = personMapper.save(person); + address.setPersonId(id); + AddressMapper addressMapper = session.getMapper(AddressMapper.class); + addressMapper.saveAddress(address); - @Test - public void whenPersonAdressSaved_ThenPersonAddressCanBeQueried(){ - Person person=new Person("Baljeet S"); - Address address = new Address("Pune"); - PersonMapper personMapper=session.getMapper(PersonMapper.class); - Integer id =personMapper.save(person); - address.setPersonId(id); - AddressMapper addressMapper=session.getMapper(AddressMapper.class); - addressMapper.saveAddress(address); + Person returnedPerson = personMapper.getPersonById(id); + assertEquals("Baljeet S", returnedPerson.getName()); + assertEquals("Pune", returnedPerson.getAddresses().get(0).getStreetAddress()); + } - Person returnedPerson= personMapper.getPersonById(id); - assertEquals("Baljeet S", returnedPerson.getName()); - assertEquals("Pune", returnedPerson.getAddresses().get(0).getStreetAddress()); - } + @Test + public void whenPersonSaved_ThenPersonCanBeQueried() { + Person person = new Person("Baljeet S"); + Address address = new Address("Pune"); + PersonMapper personMapper = session.getMapper(PersonMapper.class); + Integer id = personMapper.save(person); + address.setPersonId(id); + AddressMapper addressMapper = session.getMapper(AddressMapper.class); + addressMapper.saveAddress(address); - @Test - public void whenPersonSaved_ThenPersonCanBeQueried(){ - Person person=new Person("Baljeet S"); - Address address = new Address("Pune"); - PersonMapper personMapper=session.getMapper(PersonMapper.class); - Integer id =personMapper.save(person); - address.setPersonId(id); - AddressMapper addressMapper=session.getMapper(AddressMapper.class); - addressMapper.saveAddress(address); + Person returnedPerson = personMapper.getPerson(id); + assertEquals("Baljeet S", returnedPerson.getName()); + } - Person returnedPerson= personMapper.getPerson(id); - assertEquals("Baljeet S", returnedPerson.getName()); - } + @Test + public void whenPersonUpdated_ThenPersonIsChanged() { + Person person = new Person("Baljeet S"); + Address address = new Address("Pune"); + PersonMapper personMapper = session.getMapper(PersonMapper.class); + Integer id = personMapper.save(person); + address.setPersonId(id); + AddressMapper addressMapper = session.getMapper(AddressMapper.class); + addressMapper.saveAddress(address); - @Test - public void whenPersonUpdated_ThenPersonIsChanged(){ - Person person=new Person("Baljeet S"); - Address address = new Address("Pune"); - PersonMapper personMapper=session.getMapper(PersonMapper.class); - Integer id =personMapper.save(person); - address.setPersonId(id); - AddressMapper addressMapper=session.getMapper(AddressMapper.class); - addressMapper.saveAddress(address); + personMapper.updatePerson(new Person(id, "Baljeet1")); + Person returnedPerson = personMapper.getPerson(id); + assertEquals("Baljeet1", returnedPerson.getName()); + } - personMapper.updatePerson(new Person(id,"Baljeet1")); - Person returnedPerson= personMapper.getPerson(id); - assertEquals("Baljeet1", returnedPerson.getName()); - } - @Test - public void whenPersoSaved_ThenMapIsReturned(){ - Person person=new Person("Baljeet S"); - Address address = new Address("Pune"); - PersonMapper personMapper=session.getMapper(PersonMapper.class); - Integer id =personMapper.save(person); - address.setPersonId(id); - AddressMapper addressMapper=session.getMapper(AddressMapper.class); - addressMapper.saveAddress(address); + @Test + public void whenPersoSaved_ThenMapIsReturned() { + Person person = new Person("Baljeet S"); + Address address = new Address("Pune"); + PersonMapper personMapper = session.getMapper(PersonMapper.class); + Integer id = personMapper.save(person); + address.setPersonId(id); + AddressMapper addressMapper = session.getMapper(AddressMapper.class); + addressMapper.saveAddress(address); - Map returnedPerson= personMapper.getAllPerson(); - assertEquals(1, returnedPerson.size()); - } + Map returnedPerson = personMapper.getAllPerson(); + assertEquals(1, returnedPerson.size()); + } - @Test - public void whenPersonSearched_ThenResultIsReturned(){ - Person person=new Person("Baljeet S"); - Address address = new Address("Pune"); - PersonMapper personMapper=session.getMapper(PersonMapper.class); - Integer id =personMapper.save(person); - address.setPersonId(id); - AddressMapper addressMapper=session.getMapper(AddressMapper.class); - addressMapper.saveAddress(address); + @Test + public void whenPersonSearched_ThenResultIsReturned() { + Person person = new Person("Baljeet S"); + Address address = new Address("Pune"); + PersonMapper personMapper = session.getMapper(PersonMapper.class); + Integer id = personMapper.save(person); + address.setPersonId(id); + AddressMapper addressMapper = session.getMapper(AddressMapper.class); + addressMapper.saveAddress(address); - Person returnedPerson= personMapper.getPersonByName("Baljeet S"); - assertEquals("Baljeet S", returnedPerson.getName()); - } + Person returnedPerson = personMapper.getPersonByName("Baljeet S"); + assertEquals("Baljeet S", returnedPerson.getName()); + } - @Test - public void whenAddressSearched_ThenResultIsReturned(){ - Person person=new Person("Baljeet S"); - Address address = new Address("Pune"); - PersonMapper personMapper=session.getMapper(PersonMapper.class); - Integer id =personMapper.save(person); - address.setPersonId(id); - AddressMapper addressMapper=session.getMapper(AddressMapper.class); - Integer addressId=addressMapper.saveAddress(address); - Address returnedAddress=addressMapper.getAddresses(addressId); + @Test + public void whenAddressSearched_ThenResultIsReturned() { + Person person = new Person("Baljeet S"); + Address address = new Address("Pune"); + PersonMapper personMapper = session.getMapper(PersonMapper.class); + Integer id = personMapper.save(person); + address.setPersonId(id); + AddressMapper addressMapper = session.getMapper(AddressMapper.class); + Integer addressId = addressMapper.saveAddress(address); + Address returnedAddress = addressMapper.getAddresses(addressId); - assertEquals("Pune", returnedAddress.getStreetAddress()); - } + assertEquals("Pune", returnedAddress.getStreetAddress()); + } - @After - public void cleanup() throws SQLException { - session.getConnection().createStatement().execute("drop table address"); - session.getConnection().createStatement().execute("drop table person"); + @After + public void cleanup() throws SQLException { + session.getConnection().createStatement().execute("drop table address"); + session.getConnection().createStatement().execute("drop table person"); - session.close(); + session.close(); - } + } } From f204b6167dcc0272badc0824648e535d4b13607f Mon Sep 17 00:00:00 2001 From: Tomasz Lelek Date: Tue, 18 Apr 2017 13:29:18 +0200 Subject: [PATCH 18/19] Bael 779 kotlin generics (#1671) * Kotlin Generics code * wrote rest of the tests * sorting impl * proper val name * fix typo * better assert --- kotlin/src/test/kotlin/com/baeldung/kotlin/GenericsTest.kt | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/kotlin/src/test/kotlin/com/baeldung/kotlin/GenericsTest.kt b/kotlin/src/test/kotlin/com/baeldung/kotlin/GenericsTest.kt index c2e5ca4195..b189d0f483 100644 --- a/kotlin/src/test/kotlin/com/baeldung/kotlin/GenericsTest.kt +++ b/kotlin/src/test/kotlin/com/baeldung/kotlin/GenericsTest.kt @@ -115,12 +115,7 @@ class GenericsTest { val sorted = sort(listOfInts) //then - assertEquals(sorted[0], 1) - assertEquals(sorted[1], 2) - assertEquals(sorted[2], 3) - assertEquals(sorted[3], 4) - assertEquals(sorted[4], 5) - + assertEquals(sorted, listOf(1,2,3,4,5)) } fun > sort(list: List): List{ From 63c842305132308a04673edc5ddf45bb09e5b843 Mon Sep 17 00:00:00 2001 From: lor6 Date: Tue, 18 Apr 2017 15:15:35 +0300 Subject: [PATCH 19/19] update security config (#1674) --- .../src/main/java/org/baeldung/config/SecurityConfig.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-security-mvc-boot/src/main/java/org/baeldung/config/SecurityConfig.java b/spring-security-mvc-boot/src/main/java/org/baeldung/config/SecurityConfig.java index 8cc9d45823..acb7e6820a 100644 --- a/spring-security-mvc-boot/src/main/java/org/baeldung/config/SecurityConfig.java +++ b/spring-security-mvc-boot/src/main/java/org/baeldung/config/SecurityConfig.java @@ -24,7 +24,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter { @Override protected void configure(final AuthenticationManagerBuilder auth) throws Exception { - auth.userDetailsService(userDetailsService); + auth.authenticationProvider(authenticationProvider()); } @Override