From 5db1c3d8f352ba308ffcab29cba8a11ce2f8e4a3 Mon Sep 17 00:00:00 2001 From: Siben Nayak Date: Tue, 3 Apr 2018 15:28:38 +0530 Subject: [PATCH 01/66] [BAEL-1675] Write to a File in Kotlin --- .../com/baeldung/filesystem/FileWriter.kt | 19 +++++++++++ .../com/baeldung/filesystem/FileWriterTest.kt | 33 +++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 core-kotlin/src/main/kotlin/com/baeldung/filesystem/FileWriter.kt create mode 100644 core-kotlin/src/test/kotlin/com/baeldung/filesystem/FileWriterTest.kt diff --git a/core-kotlin/src/main/kotlin/com/baeldung/filesystem/FileWriter.kt b/core-kotlin/src/main/kotlin/com/baeldung/filesystem/FileWriter.kt new file mode 100644 index 0000000000..20d9c963c7 --- /dev/null +++ b/core-kotlin/src/main/kotlin/com/baeldung/filesystem/FileWriter.kt @@ -0,0 +1,19 @@ +package com.baeldung.filesystem + +import java.io.File + +class FileWriter { + + fun writeFileUsingPrintWriter(fileName: String, fileContent: String) = + File(fileName).printWriter().use { out -> out.println(fileContent) } + + fun writeFileUsingBufferedWriter(fileName: String, fileContent: String) = + File(fileName).bufferedWriter().use { out -> out.write(fileContent) } + + fun writeFileDirectly(fileName: String, fileContent: String) = + File(fileName).writeText(fileContent) + + fun writeFileDirectlyAsBytes(fileName: String, fileContent: String) = + File(fileName).writeBytes(fileContent.toByteArray()) + +} \ No newline at end of file diff --git a/core-kotlin/src/test/kotlin/com/baeldung/filesystem/FileWriterTest.kt b/core-kotlin/src/test/kotlin/com/baeldung/filesystem/FileWriterTest.kt new file mode 100644 index 0000000000..43a9957de1 --- /dev/null +++ b/core-kotlin/src/test/kotlin/com/baeldung/filesystem/FileWriterTest.kt @@ -0,0 +1,33 @@ +package com.baeldung.filesystem + +import org.junit.jupiter.api.Test + +internal class FileWriterTest { + + private val fileName = "src/test/resources/Kotlin.out" + + private val fileContent = "Kotlin\nConcise, Safe, Interoperable, Tool-friendly" + + private val fileWriter = FileWriter() + + @Test + fun whenWrittenWithPrintWriter_thenCorrect() { + fileWriter.writeFileUsingPrintWriter(fileName, fileContent) + } + + @Test + fun whenWrittenWithBufferedWriter_thenCorrect() { + fileWriter.writeFileUsingBufferedWriter(fileName, fileContent) + } + + @Test + fun whenWrittenDirectly_thenCorrect() { + fileWriter.writeFileDirectly(fileName, fileContent) + } + + @Test + fun whenWrittenDirectlyAsBytes_thenCorrect() { + fileWriter.writeFileDirectlyAsBytes(fileName, fileContent) + } + +} \ No newline at end of file From c1e0b884de333e7f1623f1b04c78830f61d57dc5 Mon Sep 17 00:00:00 2001 From: mherbaghinyan Date: Tue, 24 Apr 2018 22:28:20 +0400 Subject: [PATCH 02/66] aware --- .../src/main/java/com/baeldung/aware/AwareExample.java | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 spring-core/src/main/java/com/baeldung/aware/AwareExample.java diff --git a/spring-core/src/main/java/com/baeldung/aware/AwareExample.java b/spring-core/src/main/java/com/baeldung/aware/AwareExample.java new file mode 100644 index 0000000000..90e2ccf074 --- /dev/null +++ b/spring-core/src/main/java/com/baeldung/aware/AwareExample.java @@ -0,0 +1,7 @@ +package com.baeldung.aware; + +/** + * Created by Gebruiker on 4/24/2018. + */ +public class AwareExample { +} From 0da695fba58b4da8e3a6fa60b073c713b5fbc746 Mon Sep 17 00:00:00 2001 From: Erdem Date: Wed, 25 Apr 2018 00:59:56 +0300 Subject: [PATCH 03/66] tutorial real time event streaming with spring webflux --- .../com/baeldung/reactive/webflux/Event.java | 13 ++++++ .../webflux/EventStreamController.java | 20 +++++++++ .../webflux/WebfluxDemoApplication.java | 12 +++++ .../static/webflux/client-event-stream.html | 45 +++++++++++++++++++ 4 files changed, 90 insertions(+) create mode 100644 spring-5-reactive/src/main/java/com/baeldung/reactive/webflux/Event.java create mode 100644 spring-5-reactive/src/main/java/com/baeldung/reactive/webflux/EventStreamController.java create mode 100644 spring-5-reactive/src/main/java/com/baeldung/reactive/webflux/WebfluxDemoApplication.java create mode 100644 spring-5-reactive/src/main/resources/static/webflux/client-event-stream.html diff --git a/spring-5-reactive/src/main/java/com/baeldung/reactive/webflux/Event.java b/spring-5-reactive/src/main/java/com/baeldung/reactive/webflux/Event.java new file mode 100644 index 0000000000..03e80e915e --- /dev/null +++ b/spring-5-reactive/src/main/java/com/baeldung/reactive/webflux/Event.java @@ -0,0 +1,13 @@ +package com.baeldung.reactive.webflux; + +import lombok.AllArgsConstructor; +import lombok.Data; + +@Data +@AllArgsConstructor +public class Event { + + private Long id; + private String body; + +} diff --git a/spring-5-reactive/src/main/java/com/baeldung/reactive/webflux/EventStreamController.java b/spring-5-reactive/src/main/java/com/baeldung/reactive/webflux/EventStreamController.java new file mode 100644 index 0000000000..5a88f6823e --- /dev/null +++ b/spring-5-reactive/src/main/java/com/baeldung/reactive/webflux/EventStreamController.java @@ -0,0 +1,20 @@ +package com.baeldung.reactive.webflux; + +import java.time.Duration; + +import org.springframework.http.MediaType; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +import reactor.core.publisher.Flux; + +@RestController +public class EventStreamController { + + @GetMapping(value = "/events", produces = MediaType.TEXT_EVENT_STREAM_VALUE) + public Flux getMessages() { + return Flux.interval(Duration.ofMillis(1000)) + .map(tick -> new Event(tick, "This is Message #" + tick)); + } + +} diff --git a/spring-5-reactive/src/main/java/com/baeldung/reactive/webflux/WebfluxDemoApplication.java b/spring-5-reactive/src/main/java/com/baeldung/reactive/webflux/WebfluxDemoApplication.java new file mode 100644 index 0000000000..70cad0ad22 --- /dev/null +++ b/spring-5-reactive/src/main/java/com/baeldung/reactive/webflux/WebfluxDemoApplication.java @@ -0,0 +1,12 @@ +package com.baeldung.reactive.webflux; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class WebfluxDemoApplication { + + public static void main(String[] args) { + SpringApplication.run(WebfluxDemoApplication.class, args); + } +} diff --git a/spring-5-reactive/src/main/resources/static/webflux/client-event-stream.html b/spring-5-reactive/src/main/resources/static/webflux/client-event-stream.html new file mode 100644 index 0000000000..d7631f9217 --- /dev/null +++ b/spring-5-reactive/src/main/resources/static/webflux/client-event-stream.html @@ -0,0 +1,45 @@ + + + + + Baeldung: Spring 5 Reactive Webflux - real time event streaming + + + + + + +

Events streamed...

+ + + + + + + + + +
Event IdEvent Body
+ + + + + \ No newline at end of file From 6cbe92600d3da221a3b1a1324f953898d7ef16b7 Mon Sep 17 00:00:00 2001 From: Erdem Date: Wed, 25 Apr 2018 01:37:08 +0300 Subject: [PATCH 04/66] fix some type and change spring boot version to 2.0.1 from 2.0.0 --- spring-5-reactive/pom.xml | 2 +- .../baeldung/reactive/webflux/EventStreamController.java | 4 ++-- .../resources/static/webflux/client-event-stream.html | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/spring-5-reactive/pom.xml b/spring-5-reactive/pom.xml index 96378c60de..324fb13dd2 100644 --- a/spring-5-reactive/pom.xml +++ b/spring-5-reactive/pom.xml @@ -13,7 +13,7 @@ org.springframework.boot spring-boot-starter-parent - 2.0.0.RELEASE + 2.0.1.RELEASE diff --git a/spring-5-reactive/src/main/java/com/baeldung/reactive/webflux/EventStreamController.java b/spring-5-reactive/src/main/java/com/baeldung/reactive/webflux/EventStreamController.java index 5a88f6823e..f3d10437e2 100644 --- a/spring-5-reactive/src/main/java/com/baeldung/reactive/webflux/EventStreamController.java +++ b/spring-5-reactive/src/main/java/com/baeldung/reactive/webflux/EventStreamController.java @@ -12,9 +12,9 @@ import reactor.core.publisher.Flux; public class EventStreamController { @GetMapping(value = "/events", produces = MediaType.TEXT_EVENT_STREAM_VALUE) - public Flux getMessages() { + public Flux getEvents() { return Flux.interval(Duration.ofMillis(1000)) - .map(tick -> new Event(tick, "This is Message #" + tick)); + .map(tick -> new Event(tick, "This is Event #" + tick)); } } diff --git a/spring-5-reactive/src/main/resources/static/webflux/client-event-stream.html b/spring-5-reactive/src/main/resources/static/webflux/client-event-stream.html index d7631f9217..e44cbf0746 100644 --- a/spring-5-reactive/src/main/resources/static/webflux/client-event-stream.html +++ b/spring-5-reactive/src/main/resources/static/webflux/client-event-stream.html @@ -32,12 +32,12 @@ var data = JSON.parse(event.data); var table = document.getElementById("events-table"); var row = table.insertRow(1); - var cell1 = row.insertCell(0); - var cell2 = row.insertCell(1); + var cellId = row.insertCell(0); + var cellBody = row.insertCell(1); - cell1.innerHTML = '' + data.id + ''; - cell2.innerHTML = '' + data.body + ''; + cellId.innerHTML = '' + data.id + ''; + cellBody.innerHTML = '' + data.body + ''; } From 4b91a76d8f80db511e9951e7a13eba5181edd3f4 Mon Sep 17 00:00:00 2001 From: mherbaghinyan Date: Wed, 25 Apr 2018 22:13:50 +0400 Subject: [PATCH 05/66] BeanNameAware and BeanFactoryAware --- spring-core/pom.xml | 5 +++++ .../java/com/baeldung/aware/AwareExample.java | 4 ++++ .../main/java/com/baeldung/aware/Config.java | 7 +++++++ .../com/baeldung/aware/MyBeanFactory.java | 20 +++++++++++++++++++ .../java/com/baeldung/aware/MyBeanName.java | 14 +++++++++++++ 5 files changed, 50 insertions(+) create mode 100644 spring-core/src/main/java/com/baeldung/aware/Config.java create mode 100644 spring-core/src/main/java/com/baeldung/aware/MyBeanFactory.java create mode 100644 spring-core/src/main/java/com/baeldung/aware/MyBeanName.java diff --git a/spring-core/pom.xml b/spring-core/pom.xml index ae1b93a403..b80e78162d 100644 --- a/spring-core/pom.xml +++ b/spring-core/pom.xml @@ -74,6 +74,11 @@ commons-io ${commons.io.version} + + org.springframework + spring-beans + ${spring.version} + diff --git a/spring-core/src/main/java/com/baeldung/aware/AwareExample.java b/spring-core/src/main/java/com/baeldung/aware/AwareExample.java index 90e2ccf074..bbb57f1464 100644 --- a/spring-core/src/main/java/com/baeldung/aware/AwareExample.java +++ b/spring-core/src/main/java/com/baeldung/aware/AwareExample.java @@ -4,4 +4,8 @@ package com.baeldung.aware; * Created by Gebruiker on 4/24/2018. */ public class AwareExample { + + public static void main(String[] args) { + + } } diff --git a/spring-core/src/main/java/com/baeldung/aware/Config.java b/spring-core/src/main/java/com/baeldung/aware/Config.java new file mode 100644 index 0000000000..fc40bdf61b --- /dev/null +++ b/spring-core/src/main/java/com/baeldung/aware/Config.java @@ -0,0 +1,7 @@ +package com.baeldung.aware; + +import org.springframework.context.annotation.Configuration; + +@Configuration +public class Config { +} diff --git a/spring-core/src/main/java/com/baeldung/aware/MyBeanFactory.java b/spring-core/src/main/java/com/baeldung/aware/MyBeanFactory.java new file mode 100644 index 0000000000..047e1372be --- /dev/null +++ b/spring-core/src/main/java/com/baeldung/aware/MyBeanFactory.java @@ -0,0 +1,20 @@ +package com.baeldung.aware; + +import org.springframework.beans.BeansException; +import org.springframework.beans.factory.BeanFactory; +import org.springframework.beans.factory.BeanFactoryAware; + +/** + * Created by Gebruiker on 4/25/2018. + */ +public class MyBeanFactory implements BeanFactoryAware { + + private BeanFactory beanFactory; + + @Override + public void setBeanFactory(BeanFactory beanFactory) throws BeansException { + + this.beanFactory = beanFactory; + System.out.println(beanFactory); + } +} diff --git a/spring-core/src/main/java/com/baeldung/aware/MyBeanName.java b/spring-core/src/main/java/com/baeldung/aware/MyBeanName.java new file mode 100644 index 0000000000..91a3fc9a16 --- /dev/null +++ b/spring-core/src/main/java/com/baeldung/aware/MyBeanName.java @@ -0,0 +1,14 @@ +package com.baeldung.aware; + +import org.springframework.beans.factory.BeanNameAware; + +/** + * Created by Gebruiker on 4/25/2018. + */ +public class MyBeanName implements BeanNameAware { + + @Override + public void setBeanName(String beanName) { + System.out.println(beanName); + } +} From 5dc1b18c29899a29e5698c309b0c86efc9a15616 Mon Sep 17 00:00:00 2001 From: mherbaghinyan Date: Sat, 28 Apr 2018 12:02:06 +0400 Subject: [PATCH 06/66] BeanNameAware test the result --- .../src/main/java/com/baeldung/aware/AwareExample.java | 6 ++++++ spring-core/src/main/java/com/baeldung/aware/Config.java | 6 ++++++ .../src/main/java/com/baeldung/aware/MyBeanFactory.java | 2 ++ .../src/main/java/com/baeldung/aware/MyBeanName.java | 3 --- 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/spring-core/src/main/java/com/baeldung/aware/AwareExample.java b/spring-core/src/main/java/com/baeldung/aware/AwareExample.java index bbb57f1464..20770c7f08 100644 --- a/spring-core/src/main/java/com/baeldung/aware/AwareExample.java +++ b/spring-core/src/main/java/com/baeldung/aware/AwareExample.java @@ -1,5 +1,7 @@ package com.baeldung.aware; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; + /** * Created by Gebruiker on 4/24/2018. */ @@ -7,5 +9,9 @@ public class AwareExample { public static void main(String[] args) { + AnnotationConfigApplicationContext context + = new AnnotationConfigApplicationContext(Config.class); + + MyBeanName myBeanName = context.getBean(MyBeanName.class); } } diff --git a/spring-core/src/main/java/com/baeldung/aware/Config.java b/spring-core/src/main/java/com/baeldung/aware/Config.java index fc40bdf61b..547d02a60b 100644 --- a/spring-core/src/main/java/com/baeldung/aware/Config.java +++ b/spring-core/src/main/java/com/baeldung/aware/Config.java @@ -1,7 +1,13 @@ package com.baeldung.aware; +import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @Configuration public class Config { + + @Bean(name = "myCustomBeanName") + public MyBeanName getMyBeanName() { + return new MyBeanName(); + } } diff --git a/spring-core/src/main/java/com/baeldung/aware/MyBeanFactory.java b/spring-core/src/main/java/com/baeldung/aware/MyBeanFactory.java index 047e1372be..8bc5de9e45 100644 --- a/spring-core/src/main/java/com/baeldung/aware/MyBeanFactory.java +++ b/spring-core/src/main/java/com/baeldung/aware/MyBeanFactory.java @@ -17,4 +17,6 @@ public class MyBeanFactory implements BeanFactoryAware { this.beanFactory = beanFactory; System.out.println(beanFactory); } + + } diff --git a/spring-core/src/main/java/com/baeldung/aware/MyBeanName.java b/spring-core/src/main/java/com/baeldung/aware/MyBeanName.java index 91a3fc9a16..cfd6a5765d 100644 --- a/spring-core/src/main/java/com/baeldung/aware/MyBeanName.java +++ b/spring-core/src/main/java/com/baeldung/aware/MyBeanName.java @@ -2,9 +2,6 @@ package com.baeldung.aware; import org.springframework.beans.factory.BeanNameAware; -/** - * Created by Gebruiker on 4/25/2018. - */ public class MyBeanName implements BeanNameAware { @Override From 79ab39d9f18024cb5696da31ebe5a12f4ce22982 Mon Sep 17 00:00:00 2001 From: DOHA Date: Sat, 28 Apr 2018 15:52:27 +0300 Subject: [PATCH 07/66] spring data rest projections --- .../java/com/baeldung/config/RestConfig.java | 17 ++++ .../main/java/com/baeldung/models/Book.java | 16 +++- .../com/baeldung/projections/CustomBook.java | 22 +++++ .../baeldung/repositories/BookRepository.java | 7 +- .../SpringDataProjectionIntegrationTest.java | 92 +++++++++++++++++++ 5 files changed, 149 insertions(+), 5 deletions(-) create mode 100644 spring-data-rest/src/main/java/com/baeldung/config/RestConfig.java create mode 100644 spring-data-rest/src/main/java/com/baeldung/projections/CustomBook.java create mode 100644 spring-data-rest/src/test/java/com/baeldung/projection/SpringDataProjectionIntegrationTest.java diff --git a/spring-data-rest/src/main/java/com/baeldung/config/RestConfig.java b/spring-data-rest/src/main/java/com/baeldung/config/RestConfig.java new file mode 100644 index 0000000000..7434dde394 --- /dev/null +++ b/spring-data-rest/src/main/java/com/baeldung/config/RestConfig.java @@ -0,0 +1,17 @@ +package com.baeldung.config; + +import org.springframework.context.annotation.Configuration; +import org.springframework.data.rest.core.config.RepositoryRestConfiguration; +import org.springframework.data.rest.webmvc.config.RepositoryRestConfigurerAdapter; + +import com.baeldung.projections.CustomBook; + + +@Configuration +public class RestConfig extends RepositoryRestConfigurerAdapter{ + + @Override + public void configureRepositoryRestConfiguration(RepositoryRestConfiguration repositoryRestConfiguration){ + repositoryRestConfiguration.getProjectionConfiguration().addProjection(CustomBook.class); + } +} diff --git a/spring-data-rest/src/main/java/com/baeldung/models/Book.java b/spring-data-rest/src/main/java/com/baeldung/models/Book.java index 06abfb8f4d..002a64e738 100644 --- a/spring-data-rest/src/main/java/com/baeldung/models/Book.java +++ b/spring-data-rest/src/main/java/com/baeldung/models/Book.java @@ -4,6 +4,7 @@ import java.util.List; import javax.persistence.Column; import javax.persistence.Entity; +import javax.persistence.FetchType; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; @@ -20,12 +21,14 @@ public class Book { @Column(nullable = false) private String title; - + + private String isbn; + @ManyToOne @JoinColumn(name = "library_id") private Library library; - @ManyToMany(mappedBy = "books") + @ManyToMany(mappedBy = "books", fetch = FetchType.EAGER) private List authors; public Book() { @@ -52,6 +55,15 @@ public class Book { this.id = id; } + public String getIsbn() { + return isbn; + } + + public void setIsbn(String isbn) { + this.isbn = isbn; + } + + public Library getLibrary() { return library; } diff --git a/spring-data-rest/src/main/java/com/baeldung/projections/CustomBook.java b/spring-data-rest/src/main/java/com/baeldung/projections/CustomBook.java new file mode 100644 index 0000000000..1cd9c01383 --- /dev/null +++ b/spring-data-rest/src/main/java/com/baeldung/projections/CustomBook.java @@ -0,0 +1,22 @@ +package com.baeldung.projections; + +import java.util.List; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.data.rest.core.config.Projection; + +import com.baeldung.models.Author; +import com.baeldung.models.Book; + +@Projection(name = "customBook", types = { Book.class }) +public interface CustomBook { + @Value("#{target.id}") + long getId(); + + String getTitle(); + + List getAuthors(); + + @Value("#{target.getAuthors().size()}") + int getAuthorCount(); +} diff --git a/spring-data-rest/src/main/java/com/baeldung/repositories/BookRepository.java b/spring-data-rest/src/main/java/com/baeldung/repositories/BookRepository.java index f9176032ab..34019a9d91 100644 --- a/spring-data-rest/src/main/java/com/baeldung/repositories/BookRepository.java +++ b/spring-data-rest/src/main/java/com/baeldung/repositories/BookRepository.java @@ -1,9 +1,10 @@ package com.baeldung.repositories; import org.springframework.data.repository.CrudRepository; +import org.springframework.data.rest.core.annotation.RepositoryRestResource; import com.baeldung.models.Book; +import com.baeldung.projections.CustomBook; -public interface BookRepository extends CrudRepository { - -} +@RepositoryRestResource(excerptProjection = CustomBook.class) +public interface BookRepository extends CrudRepository {} diff --git a/spring-data-rest/src/test/java/com/baeldung/projection/SpringDataProjectionIntegrationTest.java b/spring-data-rest/src/test/java/com/baeldung/projection/SpringDataProjectionIntegrationTest.java new file mode 100644 index 0000000000..4091fdf154 --- /dev/null +++ b/spring-data-rest/src/test/java/com/baeldung/projection/SpringDataProjectionIntegrationTest.java @@ -0,0 +1,92 @@ +package com.baeldung.projection; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import io.restassured.RestAssured; +import io.restassured.response.Response; + +import java.util.Arrays; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.test.context.junit4.SpringRunner; + +import com.baeldung.SpringDataRestApplication; +import com.baeldung.models.Author; +import com.baeldung.models.Book; +import com.baeldung.repositories.AuthorRepository; +import com.baeldung.repositories.BookRepository; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = SpringDataRestApplication.class, webEnvironment = WebEnvironment.DEFINED_PORT) + +public class SpringDataProjectionIntegrationTest { + private static final String BOOK_ENDPOINT = "http://localhost:8080/books"; + private static final String AUTHOR_ENDPOINT = "http://localhost:8080/authors"; + + + @Autowired + private BookRepository bookRepo; + + @Autowired + private AuthorRepository authorRepo; + + @Before + public void setup(){ + if(bookRepo.findOne(1L) == null){ + Book book = new Book("Animal Farm"); + book.setIsbn("978-1943138425"); + book = bookRepo.save(book); + Author author = new Author("George Orwell"); + author = authorRepo.save(author); + author.setBooks(Arrays.asList(book)); + author = authorRepo.save(author); + } + } + + @Test + public void whenGetBook_thenOK(){ + final Response response = RestAssured.get(BOOK_ENDPOINT+"/1"); + + assertEquals(200, response.getStatusCode()); + assertTrue(response.asString().contains("isbn")); + assertFalse(response.asString().contains("authorCount")); +// System.out.println(response.asString()); + } + + + @Test + public void whenGetBookProjection_thenOK(){ + final Response response = RestAssured.get(BOOK_ENDPOINT+"/1?projection=customBook"); + + assertEquals(200, response.getStatusCode()); + assertFalse(response.asString().contains("isbn")); + assertTrue(response.asString().contains("authorCount")); +// System.out.println(response.asString()); + } + + @Test + public void whenGetAllBooks_thenOK(){ + final Response response = RestAssured.get(BOOK_ENDPOINT); + + assertEquals(200, response.getStatusCode()); + assertFalse(response.asString().contains("isbn")); + assertTrue(response.asString().contains("authorCount")); + // System.out.println(response.asString()); + } + + @Test + public void whenGetAuthorBooks_thenOK(){ + final Response response = RestAssured.get(AUTHOR_ENDPOINT+"/1/books"); + + assertEquals(200, response.getStatusCode()); + assertFalse(response.asString().contains("isbn")); + assertTrue(response.asString().contains("authorCount")); + System.out.println(response.asString()); + } +} From 2146aa2be17aed5075bc0a8d5507f5049ea69c65 Mon Sep 17 00:00:00 2001 From: mherbaghinyan Date: Sun, 29 Apr 2018 11:26:56 +0400 Subject: [PATCH 08/66] BeanFactoryAware example tested --- .../src/main/java/com/baeldung/aware/AwareExample.java | 3 +++ spring-core/src/main/java/com/baeldung/aware/Config.java | 5 +++++ .../src/main/java/com/baeldung/aware/MyBeanFactory.java | 6 ++++-- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/spring-core/src/main/java/com/baeldung/aware/AwareExample.java b/spring-core/src/main/java/com/baeldung/aware/AwareExample.java index 20770c7f08..575d0d1792 100644 --- a/spring-core/src/main/java/com/baeldung/aware/AwareExample.java +++ b/spring-core/src/main/java/com/baeldung/aware/AwareExample.java @@ -13,5 +13,8 @@ public class AwareExample { = new AnnotationConfigApplicationContext(Config.class); MyBeanName myBeanName = context.getBean(MyBeanName.class); + + MyBeanFactory myBeanFactory = context.getBean(MyBeanFactory.class); + myBeanFactory.getMyBeanName(); } } diff --git a/spring-core/src/main/java/com/baeldung/aware/Config.java b/spring-core/src/main/java/com/baeldung/aware/Config.java index 547d02a60b..c75adc9335 100644 --- a/spring-core/src/main/java/com/baeldung/aware/Config.java +++ b/spring-core/src/main/java/com/baeldung/aware/Config.java @@ -10,4 +10,9 @@ public class Config { public MyBeanName getMyBeanName() { return new MyBeanName(); } + + @Bean + public MyBeanFactory getMyBeanFactory() { + return new MyBeanFactory(); + } } diff --git a/spring-core/src/main/java/com/baeldung/aware/MyBeanFactory.java b/spring-core/src/main/java/com/baeldung/aware/MyBeanFactory.java index 8bc5de9e45..6cdbd3dd7d 100644 --- a/spring-core/src/main/java/com/baeldung/aware/MyBeanFactory.java +++ b/spring-core/src/main/java/com/baeldung/aware/MyBeanFactory.java @@ -13,10 +13,12 @@ public class MyBeanFactory implements BeanFactoryAware { @Override public void setBeanFactory(BeanFactory beanFactory) throws BeansException { - this.beanFactory = beanFactory; - System.out.println(beanFactory); } + public void getMyBeanName() { + MyBeanName myBeanName = beanFactory.getBean(MyBeanName.class); + System.out.println(beanFactory.isSingleton("myCustomBeanName")); + } } From 54d37ea0dc9facef9248e52c78c9cf9a690d9c08 Mon Sep 17 00:00:00 2001 From: aietcn Date: Wed, 2 May 2018 05:50:19 +0800 Subject: [PATCH 09/66] BAEL-658 (#4150) --- autovalue/pom.xml | 19 ++++++++++ .../java/com/baeldung/autofactory/App.java | 21 ++++++++++ .../baeldung/autofactory/CustomStorage.java | 12 ++++++ .../autofactory/custom/AbstractFactory.java | 10 +++++ .../autofactory/custom/CustomPhone.java | 16 ++++++++ .../autofactory/custom/SmartPhone.java | 18 +++++++++ .../baeldung/autofactory/model/Camera.java | 24 ++++++++++++ .../autofactory/model/ClassicPhone.java | 38 +++++++++++++++++++ .../com/baeldung/autofactory/model/Phone.java | 34 +++++++++++++++++ .../autofactory/modules/SonyCameraModule.java | 22 +++++++++++ .../provided/IntermediateAssembler.java | 22 +++++++++++ .../provider/SonyCameraProvider.java | 18 +++++++++ 12 files changed, 254 insertions(+) create mode 100644 autovalue/src/main/java/com/baeldung/autofactory/App.java create mode 100644 autovalue/src/main/java/com/baeldung/autofactory/CustomStorage.java create mode 100644 autovalue/src/main/java/com/baeldung/autofactory/custom/AbstractFactory.java create mode 100644 autovalue/src/main/java/com/baeldung/autofactory/custom/CustomPhone.java create mode 100644 autovalue/src/main/java/com/baeldung/autofactory/custom/SmartPhone.java create mode 100644 autovalue/src/main/java/com/baeldung/autofactory/model/Camera.java create mode 100644 autovalue/src/main/java/com/baeldung/autofactory/model/ClassicPhone.java create mode 100644 autovalue/src/main/java/com/baeldung/autofactory/model/Phone.java create mode 100644 autovalue/src/main/java/com/baeldung/autofactory/modules/SonyCameraModule.java create mode 100644 autovalue/src/main/java/com/baeldung/autofactory/provided/IntermediateAssembler.java create mode 100644 autovalue/src/main/java/com/baeldung/autofactory/provider/SonyCameraProvider.java diff --git a/autovalue/pom.xml b/autovalue/pom.xml index e5b0841807..3aa645002b 100644 --- a/autovalue/pom.xml +++ b/autovalue/pom.xml @@ -18,10 +18,29 @@ auto-value ${auto-value.version} + + com.google.auto.factory + auto-factory + ${auto-factory.version} + + + com.google.guava + guava + + + + + + com.google.inject + guice + ${guice.version} + 1.3 + 1.0-beta5 + 4.2.0 diff --git a/autovalue/src/main/java/com/baeldung/autofactory/App.java b/autovalue/src/main/java/com/baeldung/autofactory/App.java new file mode 100644 index 0000000000..8e911e222a --- /dev/null +++ b/autovalue/src/main/java/com/baeldung/autofactory/App.java @@ -0,0 +1,21 @@ +package com.baeldung.autofactory; + +import com.baeldung.autofactory.model.Camera; +import com.baeldung.autofactory.model.Phone; +import com.baeldung.autofactory.model.PhoneFactory; +import com.baeldung.autofactory.modules.SonyCameraModule; +import com.google.inject.Guice; +import com.google.inject.Injector; + +public class App { + + public static void main(String[] args) { + PhoneFactory phoneFactory = new PhoneFactory(() -> new Camera("Unknown", "XXX")); + Phone simplePhone = phoneFactory.create("other parts"); + + Injector injector = Guice.createInjector(new SonyCameraModule()); + PhoneFactory injectedFactory = injector.getInstance(PhoneFactory.class); + Phone xperia = injectedFactory.create("Xperia"); + } + +} diff --git a/autovalue/src/main/java/com/baeldung/autofactory/CustomStorage.java b/autovalue/src/main/java/com/baeldung/autofactory/CustomStorage.java new file mode 100644 index 0000000000..924a23ebfe --- /dev/null +++ b/autovalue/src/main/java/com/baeldung/autofactory/CustomStorage.java @@ -0,0 +1,12 @@ +package com.baeldung.autofactory; + +import com.baeldung.autofactory.custom.SmartPhone; + +/** + * @author aiet + */ +public interface CustomStorage { + + SmartPhone customROMInGB(int romSize); + +} diff --git a/autovalue/src/main/java/com/baeldung/autofactory/custom/AbstractFactory.java b/autovalue/src/main/java/com/baeldung/autofactory/custom/AbstractFactory.java new file mode 100644 index 0000000000..f4c430e953 --- /dev/null +++ b/autovalue/src/main/java/com/baeldung/autofactory/custom/AbstractFactory.java @@ -0,0 +1,10 @@ +package com.baeldung.autofactory.custom; + +/** + * @author aiet + */ +public abstract class AbstractFactory { + + abstract CustomPhone newInstance(String brand); + +} diff --git a/autovalue/src/main/java/com/baeldung/autofactory/custom/CustomPhone.java b/autovalue/src/main/java/com/baeldung/autofactory/custom/CustomPhone.java new file mode 100644 index 0000000000..b1e2fdef54 --- /dev/null +++ b/autovalue/src/main/java/com/baeldung/autofactory/custom/CustomPhone.java @@ -0,0 +1,16 @@ +package com.baeldung.autofactory.custom; + +import com.google.auto.factory.AutoFactory; + +/** + * @author aiet + */ +@AutoFactory(extending = AbstractFactory.class) +public class CustomPhone { + + private final String brand; + + public CustomPhone(String brand) { + this.brand = brand; + } +} diff --git a/autovalue/src/main/java/com/baeldung/autofactory/custom/SmartPhone.java b/autovalue/src/main/java/com/baeldung/autofactory/custom/SmartPhone.java new file mode 100644 index 0000000000..d94576ecc6 --- /dev/null +++ b/autovalue/src/main/java/com/baeldung/autofactory/custom/SmartPhone.java @@ -0,0 +1,18 @@ +package com.baeldung.autofactory.custom; + +import com.baeldung.autofactory.CustomStorage; +import com.google.auto.factory.AutoFactory; + +/** + * @author aiet + */ +@AutoFactory(className = "SamsungFactory", allowSubclasses = true, implementing = CustomStorage.class) +public class SmartPhone { + + private int romSize; + + public SmartPhone(int romSize) { + this.romSize = romSize; + } + +} diff --git a/autovalue/src/main/java/com/baeldung/autofactory/model/Camera.java b/autovalue/src/main/java/com/baeldung/autofactory/model/Camera.java new file mode 100644 index 0000000000..269148b690 --- /dev/null +++ b/autovalue/src/main/java/com/baeldung/autofactory/model/Camera.java @@ -0,0 +1,24 @@ +package com.baeldung.autofactory.model; + +/** + * @author aiet + */ +public class Camera { + + private final String manufacturer; + private final String serial; + + public Camera(String manufacturer, String serial) { + this.manufacturer = manufacturer; + this.serial = serial; + } + + public String getManufacturer() { + return manufacturer; + } + + public String getSerial() { + return serial; + } + +} diff --git a/autovalue/src/main/java/com/baeldung/autofactory/model/ClassicPhone.java b/autovalue/src/main/java/com/baeldung/autofactory/model/ClassicPhone.java new file mode 100644 index 0000000000..9ec6413e1c --- /dev/null +++ b/autovalue/src/main/java/com/baeldung/autofactory/model/ClassicPhone.java @@ -0,0 +1,38 @@ +package com.baeldung.autofactory.model; + +import com.google.auto.factory.AutoFactory; +import com.google.auto.factory.Provided; + +/** + * @author aiet + */ +public class ClassicPhone { + + private final String dialpad; + private final String ringer; + private String otherParts; + + @AutoFactory + public ClassicPhone(@Provided String dialpad, @Provided String ringer) { + this.dialpad = dialpad; + this.ringer = ringer; + } + + @AutoFactory + public ClassicPhone(String otherParts) { + this("defaultDialPad", "defaultRinger"); + this.otherParts = otherParts; + } + + public String getDialpad() { + return dialpad; + } + + public String getRinger() { + return ringer; + } + + public String getOtherParts() { + return otherParts; + } +} diff --git a/autovalue/src/main/java/com/baeldung/autofactory/model/Phone.java b/autovalue/src/main/java/com/baeldung/autofactory/model/Phone.java new file mode 100644 index 0000000000..83c2ba4a0e --- /dev/null +++ b/autovalue/src/main/java/com/baeldung/autofactory/model/Phone.java @@ -0,0 +1,34 @@ +package com.baeldung.autofactory.model; + +import com.google.auto.factory.AutoFactory; +import com.google.auto.factory.Provided; + +import javax.inject.Named; + +/** + * @author aiet + */ +@AutoFactory +public class Phone { + + private Camera camera; + private String otherParts; + + public Phone(@Provided @Named("Sony") Camera camera, String otherParts) { + this.camera = camera; + this.otherParts = otherParts; + } + + /* required when used as a base class for AutoFactory */ + public Phone() { + } + + public Camera getCamera() { + return camera; + } + + public String getOtherParts() { + return otherParts; + } + +} diff --git a/autovalue/src/main/java/com/baeldung/autofactory/modules/SonyCameraModule.java b/autovalue/src/main/java/com/baeldung/autofactory/modules/SonyCameraModule.java new file mode 100644 index 0000000000..dc04ac4a0a --- /dev/null +++ b/autovalue/src/main/java/com/baeldung/autofactory/modules/SonyCameraModule.java @@ -0,0 +1,22 @@ +package com.baeldung.autofactory.modules; + +import com.baeldung.autofactory.model.Camera; +import com.google.inject.AbstractModule; +import com.google.inject.Provides; + +import javax.inject.Named; + +/** + * @author aiet + */ +public class SonyCameraModule extends AbstractModule { + + private static int SONY_CAMERA_SERIAL = 1; + + @Named("Sony") + @Provides + Camera cameraProvider() { + return new Camera("Sony", String.format("%03d", SONY_CAMERA_SERIAL++)); + } + +} diff --git a/autovalue/src/main/java/com/baeldung/autofactory/provided/IntermediateAssembler.java b/autovalue/src/main/java/com/baeldung/autofactory/provided/IntermediateAssembler.java new file mode 100644 index 0000000000..e0ee8879a5 --- /dev/null +++ b/autovalue/src/main/java/com/baeldung/autofactory/provided/IntermediateAssembler.java @@ -0,0 +1,22 @@ +package com.baeldung.autofactory.provided; + +import com.google.auto.factory.AutoFactory; +import com.google.auto.factory.Provided; +import javafx.scene.Camera; + +import javax.inject.Provider; + +/** + * @author aiet + */ +@AutoFactory +public class IntermediateAssembler { + + private final Provider camera; + private final String otherParts; + + public IntermediateAssembler(@Provided Provider camera, String otherParts) { + this.camera = camera; + this.otherParts = otherParts; + } +} diff --git a/autovalue/src/main/java/com/baeldung/autofactory/provider/SonyCameraProvider.java b/autovalue/src/main/java/com/baeldung/autofactory/provider/SonyCameraProvider.java new file mode 100644 index 0000000000..cc304b7c9e --- /dev/null +++ b/autovalue/src/main/java/com/baeldung/autofactory/provider/SonyCameraProvider.java @@ -0,0 +1,18 @@ +package com.baeldung.autofactory.provider; + +import com.baeldung.autofactory.model.Camera; +import com.google.inject.Provider; + +/** + * @author aiet + */ +public class SonyCameraProvider implements Provider { + + private static int sonyCameraSerial = 1; + + @Override + public Camera get() { + return new Camera("Sony", String.format("%03d", sonyCameraSerial++)); + } + +} From 7b92a38bedd5969b2b1f1901bdaa22d007ab0a17 Mon Sep 17 00:00:00 2001 From: abialas Date: Wed, 2 May 2018 03:42:52 +0200 Subject: [PATCH 10/66] BAEL-1679 (#4149) * BAEL-1412 add java 8 spring data features * BAEL-21 new HTTP API overview * BAEL-21 fix executor * BAEL-1432 add custom gradle task * BAEL-1567 add samples of cookie and session in serlvet * BAEL-1567 use stream api * BAEL-1567 fix optional * BAEL-1679 add query annotation jpa spring data * BAEL-1679 added new junits * BAEL-1679 use assertJ, use givenWhenThen naming convention * BAEL-1679 move query annotation examples to persistence modules * BAEL-1679 fix formatting --- .../config/PersistenceJPAConfigL2Cache.java | 2 +- .../org/baeldung/persistence/model/User.java | 49 +++ .../repository/UserRepository.java | 69 ++++ .../UserRepositoryIntegrationTest.java | 319 ++++++++++++++++++ .../UserRepositoryIntegrationTest.java | 285 +--------------- 5 files changed, 447 insertions(+), 277 deletions(-) create mode 100644 persistence-modules/spring-jpa/src/main/java/org/baeldung/persistence/model/User.java create mode 100644 persistence-modules/spring-jpa/src/main/java/org/baeldung/persistence/repository/UserRepository.java create mode 100644 persistence-modules/spring-jpa/src/test/java/org/baeldung/persistence/repository/UserRepositoryIntegrationTest.java diff --git a/persistence-modules/spring-jpa/src/main/java/org/baeldung/config/PersistenceJPAConfigL2Cache.java b/persistence-modules/spring-jpa/src/main/java/org/baeldung/config/PersistenceJPAConfigL2Cache.java index 8768bac58c..a236cf2331 100644 --- a/persistence-modules/spring-jpa/src/main/java/org/baeldung/config/PersistenceJPAConfigL2Cache.java +++ b/persistence-modules/spring-jpa/src/main/java/org/baeldung/config/PersistenceJPAConfigL2Cache.java @@ -24,7 +24,7 @@ import java.util.Properties; @EnableTransactionManagement @PropertySource({ "classpath:persistence-h2.properties" }) @ComponentScan({ "org.baeldung.persistence" }) -@EnableJpaRepositories(basePackages = "org.baeldung.persistence.dao") +@EnableJpaRepositories(basePackages = { "org.baeldung.persistence.dao", "org.baeldung.persistence.repository" }) public class PersistenceJPAConfigL2Cache { @Autowired diff --git a/persistence-modules/spring-jpa/src/main/java/org/baeldung/persistence/model/User.java b/persistence-modules/spring-jpa/src/main/java/org/baeldung/persistence/model/User.java new file mode 100644 index 0000000000..f84a10cf76 --- /dev/null +++ b/persistence-modules/spring-jpa/src/main/java/org/baeldung/persistence/model/User.java @@ -0,0 +1,49 @@ +package org.baeldung.persistence.model; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.Table; + +@Entity +@Table(name = "users") +public class User { + + @Id + @GeneratedValue + private Integer id; + private String name; + private Integer status; + + public User() { + } + + public User(String name, Integer status) { + this.name = name; + this.status = status; + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Integer getStatus() { + return status; + } + + public void setStatus(Integer status) { + this.status = status; + } +} diff --git a/persistence-modules/spring-jpa/src/main/java/org/baeldung/persistence/repository/UserRepository.java b/persistence-modules/spring-jpa/src/main/java/org/baeldung/persistence/repository/UserRepository.java new file mode 100644 index 0000000000..eadac9a0d7 --- /dev/null +++ b/persistence-modules/spring-jpa/src/main/java/org/baeldung/persistence/repository/UserRepository.java @@ -0,0 +1,69 @@ +package org.baeldung.persistence.repository; + +import org.baeldung.persistence.model.User; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Sort; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; +import org.springframework.stereotype.Repository; + +import java.util.Collection; +import java.util.List; + +@Repository("userRepository") +public interface UserRepository extends JpaRepository { + + @Query("SELECT u FROM User u WHERE u.status = 1") + Collection findAllActiveUsers(); + + @Query(value = "SELECT * FROM USERS u WHERE u.status = 1", nativeQuery = true) + Collection findAllActiveUsersNative(); + + @Query("SELECT u FROM User u WHERE u.status = ?1") + User findUserByStatus(Integer status); + + @Query(value = "SELECT * FROM Users u WHERE u.status = ?1", nativeQuery = true) + User findUserByStatusNative(Integer status); + + @Query("SELECT u FROM User u WHERE u.status = ?1 and u.name = ?2") + User findUserByStatusAndName(Integer status, String name); + + @Query("SELECT u FROM User u WHERE u.status = :status and u.name = :name") + User findUserByStatusAndNameNamedParams(@Param("status") Integer status, @Param("name") String name); + + @Query(value = "SELECT * FROM Users u WHERE u.status = :status AND u.name = :name", nativeQuery = true) + User findUserByStatusAndNameNamedParamsNative(@Param("status") Integer status, @Param("name") String name); + + @Query("SELECT u FROM User u WHERE u.status = :status and u.name = :name") + User findUserByUserStatusAndUserName(@Param("status") Integer userStatus, @Param("name") String userName); + + @Query("SELECT u FROM User u WHERE u.name like ?1%") + User findUserByNameLike(String name); + + @Query("SELECT u FROM User u WHERE u.name like :name%") + User findUserByNameLikeNamedParam(@Param("name") String name); + + @Query(value = "SELECT * FROM users u WHERE u.name LIKE ?1%", nativeQuery = true) + User findUserByNameLikeNative(String name); + + @Query(value = "SELECT u FROM User u") + List findAllUsers(Sort sort); + + @Query(value = "SELECT u FROM User u ORDER BY id") + Page findAllUsersWithPagination(Pageable pageable); + + @Query(value = "SELECT * FROM Users ORDER BY id \n-- #pageable\n", countQuery = "SELECT count(*) FROM Users", nativeQuery = true) + Page findAllUsersWithPaginationNative(Pageable pageable); + + @Modifying + @Query("update User u set u.status = :status where u.name = :name") + int updateUserSetStatusForName(@Param("status") Integer status, @Param("name") String name); + + @Modifying + @Query(value = "UPDATE Users u SET u.status = ? WHERE u.name = ?", nativeQuery = true) + int updateUserSetStatusForNameNative(Integer status, String name); + +} diff --git a/persistence-modules/spring-jpa/src/test/java/org/baeldung/persistence/repository/UserRepositoryIntegrationTest.java b/persistence-modules/spring-jpa/src/test/java/org/baeldung/persistence/repository/UserRepositoryIntegrationTest.java new file mode 100644 index 0000000000..90db9f4e74 --- /dev/null +++ b/persistence-modules/spring-jpa/src/test/java/org/baeldung/persistence/repository/UserRepositoryIntegrationTest.java @@ -0,0 +1,319 @@ +package org.baeldung.persistence.repository; + +import org.baeldung.config.PersistenceJPAConfigL2Cache; +import org.baeldung.persistence.model.User; +import org.junit.After; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Sort; +import org.springframework.data.jpa.domain.JpaSort; +import org.springframework.data.mapping.PropertyReferenceException; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.transaction.annotation.Transactional; + +import java.util.Collection; +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Created by adam. + */ +@RunWith(SpringRunner.class) +@ContextConfiguration(classes = PersistenceJPAConfigL2Cache.class) +public class UserRepositoryIntegrationTest { + + private final String USER_NAME_ADAM = "Adam"; + private final String USER_NAME_PETER = "Peter"; + private final Integer INACTIVE_STATUS = 0; + private final Integer ACTIVE_STATUS = 1; + + @Autowired + private UserRepository userRepository; + + @Test + public void givenUsersInDBWhenFindAllWithQueryAnnotationThenReturnCollectionWithActiveUsers() { + User user1 = new User(); + user1.setName(USER_NAME_ADAM); + user1.setStatus(ACTIVE_STATUS); + userRepository.save(user1); + + User user2 = new User(); + user2.setName(USER_NAME_ADAM); + user2.setStatus(ACTIVE_STATUS); + userRepository.save(user2); + + User user3 = new User(); + user3.setName(USER_NAME_ADAM); + user3.setStatus(INACTIVE_STATUS); + userRepository.save(user3); + + Collection allActiveUsers = userRepository.findAllActiveUsers(); + + assertThat(allActiveUsers.size()).isEqualTo(2); + } + + @Test + public void givenUsersInDBWhenFindAllWithQueryAnnotationNativeThenReturnCollectionWithActiveUsers() { + User user1 = new User(); + user1.setName(USER_NAME_ADAM); + user1.setStatus(ACTIVE_STATUS); + userRepository.save(user1); + + User user2 = new User(); + user2.setName(USER_NAME_ADAM); + user2.setStatus(ACTIVE_STATUS); + userRepository.save(user2); + + User user3 = new User(); + user3.setName(USER_NAME_ADAM); + user3.setStatus(INACTIVE_STATUS); + userRepository.save(user3); + + Collection allActiveUsers = userRepository.findAllActiveUsersNative(); + + assertThat(allActiveUsers.size()).isEqualTo(2); + } + + @Test + public void givenUserInDBWhenFindUserByStatusWithQueryAnnotationThenReturnActiveUser() { + User user = new User(); + user.setName(USER_NAME_ADAM); + user.setStatus(ACTIVE_STATUS); + userRepository.save(user); + + User userByStatus = userRepository.findUserByStatus(ACTIVE_STATUS); + + assertThat(userByStatus.getName()).isEqualTo(USER_NAME_ADAM); + } + + @Test + public void givenUserInDBWhenFindUserByStatusWithQueryAnnotationNativeThenReturnActiveUser() { + User user = new User(); + user.setName(USER_NAME_ADAM); + user.setStatus(ACTIVE_STATUS); + userRepository.save(user); + + User userByStatus = userRepository.findUserByStatusNative(ACTIVE_STATUS); + + assertThat(userByStatus.getName()).isEqualTo(USER_NAME_ADAM); + } + + @Test + public void givenUsersInDBWhenFindUserByStatusAndNameWithQueryAnnotationIndexedParamsThenReturnOneUser() { + User user = new User(); + user.setName(USER_NAME_ADAM); + user.setStatus(ACTIVE_STATUS); + userRepository.save(user); + + User user2 = new User(); + user2.setName(USER_NAME_PETER); + user2.setStatus(ACTIVE_STATUS); + userRepository.save(user2); + + User userByStatus = userRepository.findUserByStatusAndName(ACTIVE_STATUS, USER_NAME_ADAM); + + assertThat(userByStatus.getName()).isEqualTo(USER_NAME_ADAM); + } + + @Test + public void givenUsersInDBWhenFindUserByStatusAndNameWithQueryAnnotationNamedParamsThenReturnOneUser() { + User user = new User(); + user.setName(USER_NAME_ADAM); + user.setStatus(ACTIVE_STATUS); + userRepository.save(user); + + User user2 = new User(); + user2.setName(USER_NAME_PETER); + user2.setStatus(ACTIVE_STATUS); + userRepository.save(user2); + + User userByStatus = userRepository.findUserByStatusAndNameNamedParams(ACTIVE_STATUS, USER_NAME_ADAM); + + assertThat(userByStatus.getName()).isEqualTo(USER_NAME_ADAM); + } + + @Test + public void givenUsersInDBWhenFindUserByStatusAndNameWithQueryAnnotationNativeNamedParamsThenReturnOneUser() { + User user = new User(); + user.setName(USER_NAME_ADAM); + user.setStatus(ACTIVE_STATUS); + userRepository.save(user); + + User user2 = new User(); + user2.setName(USER_NAME_PETER); + user2.setStatus(ACTIVE_STATUS); + userRepository.save(user2); + + User userByStatus = userRepository.findUserByStatusAndNameNamedParamsNative(ACTIVE_STATUS, USER_NAME_ADAM); + + assertThat(userByStatus.getName()).isEqualTo(USER_NAME_ADAM); + } + + @Test + public void givenUsersInDBWhenFindUserByStatusAndNameWithQueryAnnotationNamedParamsCustomNamesThenReturnOneUser() { + User user = new User(); + user.setName(USER_NAME_ADAM); + user.setStatus(ACTIVE_STATUS); + userRepository.save(user); + + User user2 = new User(); + user2.setName(USER_NAME_PETER); + user2.setStatus(ACTIVE_STATUS); + userRepository.save(user2); + + User userByStatus = userRepository.findUserByUserStatusAndUserName(ACTIVE_STATUS, USER_NAME_ADAM); + + assertThat(userByStatus.getName()).isEqualTo(USER_NAME_ADAM); + } + + @Test + public void givenUsersInDBWhenFindUserByNameLikeWithQueryAnnotationIndexedParamsThenReturnUser() { + User user = new User(); + user.setName(USER_NAME_ADAM); + user.setStatus(ACTIVE_STATUS); + userRepository.save(user); + + User userByStatus = userRepository.findUserByNameLike("Ad"); + + assertThat(userByStatus.getName()).isEqualTo(USER_NAME_ADAM); + } + + @Test + public void givenUsersInDBWhenFindUserByNameLikeWithQueryAnnotationNamedParamsThenReturnUser() { + User user = new User(); + user.setName(USER_NAME_ADAM); + user.setStatus(ACTIVE_STATUS); + userRepository.save(user); + + User userByStatus = userRepository.findUserByNameLikeNamedParam("Ad"); + + assertThat(userByStatus.getName()).isEqualTo(USER_NAME_ADAM); + } + + @Test + public void givenUsersInDBWhenFindUserByNameLikeWithQueryAnnotationNativeThenReturnUser() { + User user = new User(); + user.setName(USER_NAME_ADAM); + user.setStatus(ACTIVE_STATUS); + userRepository.save(user); + + User userByStatus = userRepository.findUserByNameLikeNative("Ad"); + + assertThat(userByStatus.getName()).isEqualTo(USER_NAME_ADAM); + } + + @Test + public void givenUsersInDBWhenFindAllWithSortByNameThenReturnUsersSorted() { + userRepository.save(new User(USER_NAME_ADAM, ACTIVE_STATUS)); + userRepository.save(new User(USER_NAME_PETER, ACTIVE_STATUS)); + userRepository.save(new User("SAMPLE", INACTIVE_STATUS)); + + List usersSortByName = userRepository.findAll(new Sort(Sort.Direction.ASC, "name")); + + assertThat(usersSortByName + .get(0) + .getName()).isEqualTo(USER_NAME_ADAM); + } + + @Test(expected = PropertyReferenceException.class) + public void givenUsersInDBWhenFindAllSortWithFunctionThenThrowException() { + userRepository.save(new User(USER_NAME_ADAM, ACTIVE_STATUS)); + userRepository.save(new User(USER_NAME_PETER, ACTIVE_STATUS)); + userRepository.save(new User("SAMPLE", INACTIVE_STATUS)); + + userRepository.findAll(new Sort(Sort.Direction.ASC, "name")); + + List usersSortByNameLength = userRepository.findAll(new Sort("LENGTH(name)")); + + assertThat(usersSortByNameLength + .get(0) + .getName()).isEqualTo(USER_NAME_ADAM); + } + + @Test + public void givenUsersInDBWhenFindAllSortWithFunctionQueryAnnotationJPQLThenReturnUsersSorted() { + userRepository.save(new User(USER_NAME_ADAM, ACTIVE_STATUS)); + userRepository.save(new User(USER_NAME_PETER, ACTIVE_STATUS)); + userRepository.save(new User("SAMPLE", INACTIVE_STATUS)); + + userRepository.findAllUsers(new Sort("name")); + + List usersSortByNameLength = userRepository.findAllUsers(JpaSort.unsafe("LENGTH(name)")); + + assertThat(usersSortByNameLength + .get(0) + .getName()).isEqualTo(USER_NAME_ADAM); + } + + @Test + public void givenUsersInDBWhenFindAllWithPageRequestQueryAnnotationJPQLThenReturnPageOfUsers() { + userRepository.save(new User(USER_NAME_ADAM, ACTIVE_STATUS)); + userRepository.save(new User(USER_NAME_PETER, ACTIVE_STATUS)); + userRepository.save(new User("SAMPLE", INACTIVE_STATUS)); + userRepository.save(new User("SAMPLE1", INACTIVE_STATUS)); + userRepository.save(new User("SAMPLE2", INACTIVE_STATUS)); + userRepository.save(new User("SAMPLE3", INACTIVE_STATUS)); + + Page usersPage = userRepository.findAllUsersWithPagination(new PageRequest(1, 3)); + + assertThat(usersPage + .getContent() + .get(0) + .getName()).isEqualTo("SAMPLE1"); + } + + @Test + public void givenUsersInDBWhenFindAllWithPageRequestQueryAnnotationNativeThenReturnPageOfUsers() { + userRepository.save(new User(USER_NAME_ADAM, ACTIVE_STATUS)); + userRepository.save(new User(USER_NAME_PETER, ACTIVE_STATUS)); + userRepository.save(new User("SAMPLE", INACTIVE_STATUS)); + userRepository.save(new User("SAMPLE1", INACTIVE_STATUS)); + userRepository.save(new User("SAMPLE2", INACTIVE_STATUS)); + userRepository.save(new User("SAMPLE3", INACTIVE_STATUS)); + + Page usersSortByNameLength = userRepository.findAllUsersWithPaginationNative(new PageRequest(1, 3)); + + assertThat(usersSortByNameLength + .getContent() + .get(0) + .getName()).isEqualTo("SAMPLE1"); + } + + @Test + @Transactional + public void givenUsersInDBWhenUpdateStatusForNameModifyingQueryAnnotationJPQLThenModifyMatchingUsers() { + userRepository.save(new User("SAMPLE", ACTIVE_STATUS)); + userRepository.save(new User("SAMPLE1", ACTIVE_STATUS)); + userRepository.save(new User("SAMPLE", ACTIVE_STATUS)); + userRepository.save(new User("SAMPLE3", ACTIVE_STATUS)); + + int updatedUsersSize = userRepository.updateUserSetStatusForName(INACTIVE_STATUS, "SAMPLE"); + + assertThat(updatedUsersSize).isEqualTo(2); + } + + @Test + @Transactional + public void givenUsersInDBWhenUpdateStatusForNameModifyingQueryAnnotationNativeThenModifyMatchingUsers() { + userRepository.save(new User("SAMPLE", ACTIVE_STATUS)); + userRepository.save(new User("SAMPLE1", ACTIVE_STATUS)); + userRepository.save(new User("SAMPLE", ACTIVE_STATUS)); + userRepository.save(new User("SAMPLE3", ACTIVE_STATUS)); + userRepository.flush(); + + int updatedUsersSize = userRepository.updateUserSetStatusForNameNative(INACTIVE_STATUS, "SAMPLE"); + + assertThat(updatedUsersSize).isEqualTo(2); + } + + @After + public void cleanUp() { + userRepository.deleteAll(); + } + +} diff --git a/spring-boot/src/test/java/org/baeldung/repository/UserRepositoryIntegrationTest.java b/spring-boot/src/test/java/org/baeldung/repository/UserRepositoryIntegrationTest.java index f1e1ecce55..72d204820e 100644 --- a/spring-boot/src/test/java/org/baeldung/repository/UserRepositoryIntegrationTest.java +++ b/spring-boot/src/test/java/org/baeldung/repository/UserRepositoryIntegrationTest.java @@ -7,16 +7,9 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.domain.Sort; -import org.springframework.data.jpa.domain.JpaSort; -import org.springframework.data.mapping.PropertyReferenceException; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.transaction.annotation.Transactional; -import java.util.Collection; -import java.util.List; import java.util.Optional; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; @@ -32,11 +25,10 @@ import static org.assertj.core.api.Assertions.assertThat; public class UserRepositoryIntegrationTest { private final String USER_NAME_ADAM = "Adam"; - private final String USER_NAME_PETER = "Peter"; - private final Integer INACTIVE_STATUS = 0; private final Integer ACTIVE_STATUS = 1; - @Autowired private UserRepository userRepository; + @Autowired + private UserRepository userRepository; @Test public void givenEmptyDBWhenFindOneByNameThenReturnEmptyOptional() { @@ -54,7 +46,10 @@ public class UserRepositoryIntegrationTest { Optional foundUser = userRepository.findOneByName(USER_NAME_ADAM); assertThat(foundUser.isPresent()).isEqualTo(true); - assertThat(foundUser.get().getName()).isEqualTo(USER_NAME_ADAM); + + assertThat(foundUser + .get() + .getName()).isEqualTo(USER_NAME_ADAM); } @Test @@ -90,271 +85,9 @@ public class UserRepositoryIntegrationTest { CompletableFuture userByStatus = userRepository.findOneByStatus(ACTIVE_STATUS); - assertThat(userByStatus.get().getName()).isEqualTo(USER_NAME_ADAM); - } - - @Test - public void givenUsersInDBWhenFindAllWithQueryAnnotationThenReturnCollectionWithActiveUsers() { - User user1 = new User(); - user1.setName(USER_NAME_ADAM); - user1.setStatus(ACTIVE_STATUS); - userRepository.save(user1); - - User user2 = new User(); - user2.setName(USER_NAME_ADAM); - user2.setStatus(ACTIVE_STATUS); - userRepository.save(user2); - - User user3 = new User(); - user3.setName(USER_NAME_ADAM); - user3.setStatus(INACTIVE_STATUS); - userRepository.save(user3); - - Collection allActiveUsers = userRepository.findAllActiveUsers(); - - assertThat(allActiveUsers.size()).isEqualTo(2); - } - - @Test - public void givenUsersInDBWhenFindAllWithQueryAnnotationNativeThenReturnCollectionWithActiveUsers() { - User user1 = new User(); - user1.setName(USER_NAME_ADAM); - user1.setStatus(ACTIVE_STATUS); - userRepository.save(user1); - - User user2 = new User(); - user2.setName(USER_NAME_ADAM); - user2.setStatus(ACTIVE_STATUS); - userRepository.save(user2); - - User user3 = new User(); - user3.setName(USER_NAME_ADAM); - user3.setStatus(INACTIVE_STATUS); - userRepository.save(user3); - - Collection allActiveUsers = userRepository.findAllActiveUsersNative(); - - assertThat(allActiveUsers.size()).isEqualTo(2); - } - - @Test - public void givenUserInDBWhenFindUserByStatusWithQueryAnnotationThenReturnActiveUser() { - User user = new User(); - user.setName(USER_NAME_ADAM); - user.setStatus(ACTIVE_STATUS); - userRepository.save(user); - - User userByStatus = userRepository.findUserByStatus(ACTIVE_STATUS); - - assertThat(userByStatus.getName()).isEqualTo(USER_NAME_ADAM); - } - - @Test - public void givenUserInDBWhenFindUserByStatusWithQueryAnnotationNativeThenReturnActiveUser() { - User user = new User(); - user.setName(USER_NAME_ADAM); - user.setStatus(ACTIVE_STATUS); - userRepository.save(user); - - User userByStatus = userRepository.findUserByStatusNative(ACTIVE_STATUS); - - assertThat(userByStatus.getName()).isEqualTo(USER_NAME_ADAM); - } - - @Test - public void givenUsersInDBWhenFindUserByStatusAndNameWithQueryAnnotationIndexedParamsThenReturnOneUser() { - User user = new User(); - user.setName(USER_NAME_ADAM); - user.setStatus(ACTIVE_STATUS); - userRepository.save(user); - - User user2 = new User(); - user2.setName(USER_NAME_PETER); - user2.setStatus(ACTIVE_STATUS); - userRepository.save(user2); - - User userByStatus = userRepository.findUserByStatusAndName(ACTIVE_STATUS, USER_NAME_ADAM); - - assertThat(userByStatus.getName()).isEqualTo(USER_NAME_ADAM); - } - - @Test - public void givenUsersInDBWhenFindUserByStatusAndNameWithQueryAnnotationNamedParamsThenReturnOneUser() { - User user = new User(); - user.setName(USER_NAME_ADAM); - user.setStatus(ACTIVE_STATUS); - userRepository.save(user); - - User user2 = new User(); - user2.setName(USER_NAME_PETER); - user2.setStatus(ACTIVE_STATUS); - userRepository.save(user2); - - User userByStatus = userRepository.findUserByStatusAndNameNamedParams(ACTIVE_STATUS, USER_NAME_ADAM); - - assertThat(userByStatus.getName()).isEqualTo(USER_NAME_ADAM); - } - - @Test - public void givenUsersInDBWhenFindUserByStatusAndNameWithQueryAnnotationNativeNamedParamsThenReturnOneUser() { - User user = new User(); - user.setName(USER_NAME_ADAM); - user.setStatus(ACTIVE_STATUS); - userRepository.save(user); - - User user2 = new User(); - user2.setName(USER_NAME_PETER); - user2.setStatus(ACTIVE_STATUS); - userRepository.save(user2); - - User userByStatus = userRepository.findUserByStatusAndNameNamedParamsNative(ACTIVE_STATUS, USER_NAME_ADAM); - - assertThat(userByStatus.getName()).isEqualTo(USER_NAME_ADAM); - } - - @Test - public void givenUsersInDBWhenFindUserByStatusAndNameWithQueryAnnotationNamedParamsCustomNamesThenReturnOneUser() { - User user = new User(); - user.setName(USER_NAME_ADAM); - user.setStatus(ACTIVE_STATUS); - userRepository.save(user); - - User user2 = new User(); - user2.setName(USER_NAME_PETER); - user2.setStatus(ACTIVE_STATUS); - userRepository.save(user2); - - User userByStatus = userRepository.findUserByUserStatusAndUserName(ACTIVE_STATUS, USER_NAME_ADAM); - - assertThat(userByStatus.getName()).isEqualTo(USER_NAME_ADAM); - } - - @Test - public void givenUsersInDBWhenFindUserByNameLikeWithQueryAnnotationIndexedParamsThenReturnUser() { - User user = new User(); - user.setName(USER_NAME_ADAM); - user.setStatus(ACTIVE_STATUS); - userRepository.save(user); - - User userByStatus = userRepository.findUserByNameLike("Ad"); - - assertThat(userByStatus.getName()).isEqualTo(USER_NAME_ADAM); - } - - @Test - public void givenUsersInDBWhenFindUserByNameLikeWithQueryAnnotationNamedParamsThenReturnUser() { - User user = new User(); - user.setName(USER_NAME_ADAM); - user.setStatus(ACTIVE_STATUS); - userRepository.save(user); - - User userByStatus = userRepository.findUserByNameLikeNamedParam("Ad"); - - assertThat(userByStatus.getName()).isEqualTo(USER_NAME_ADAM); - } - - @Test - public void givenUsersInDBWhenFindUserByNameLikeWithQueryAnnotationNativeThenReturnUser() { - User user = new User(); - user.setName(USER_NAME_ADAM); - user.setStatus(ACTIVE_STATUS); - userRepository.save(user); - - User userByStatus = userRepository.findUserByNameLikeNative("Ad"); - - assertThat(userByStatus.getName()).isEqualTo(USER_NAME_ADAM); - } - - @Test - public void givenUsersInDBWhenFindAllWithSortByNameThenReturnUsersSorted() { - userRepository.save(new User(USER_NAME_ADAM, ACTIVE_STATUS)); - userRepository.save(new User(USER_NAME_PETER, ACTIVE_STATUS)); - userRepository.save(new User("SAMPLE", INACTIVE_STATUS)); - - List usersSortByName = userRepository.findAll(new Sort(Sort.Direction.ASC, "name")); - - assertThat(usersSortByName.get(0).getName()).isEqualTo(USER_NAME_ADAM); - } - - @Test(expected = PropertyReferenceException.class) - public void givenUsersInDBWhenFindAllSortWithFunctionThenThrowException() { - userRepository.save(new User(USER_NAME_ADAM, ACTIVE_STATUS)); - userRepository.save(new User(USER_NAME_PETER, ACTIVE_STATUS)); - userRepository.save(new User("SAMPLE", INACTIVE_STATUS)); - - userRepository.findAll(new Sort(Sort.Direction.ASC, "name")); - - List usersSortByNameLength = userRepository.findAll(new Sort("LENGTH(name)")); - - assertThat(usersSortByNameLength.get(0).getName()).isEqualTo(USER_NAME_ADAM); - } - - @Test - public void givenUsersInDBWhenFindAllSortWithFunctionQueryAnnotationJPQLThenReturnUsersSorted() { - userRepository.save(new User(USER_NAME_ADAM, ACTIVE_STATUS)); - userRepository.save(new User(USER_NAME_PETER, ACTIVE_STATUS)); - userRepository.save(new User("SAMPLE", INACTIVE_STATUS)); - - userRepository.findAllUsers(new Sort("name")); - - List usersSortByNameLength = userRepository.findAllUsers(JpaSort.unsafe("LENGTH(name)")); - - assertThat(usersSortByNameLength.get(0).getName()).isEqualTo(USER_NAME_ADAM); - } - - @Test - public void givenUsersInDBWhenFindAllWithPageRequestQueryAnnotationJPQLThenReturnPageOfUsers() { - userRepository.save(new User(USER_NAME_ADAM, ACTIVE_STATUS)); - userRepository.save(new User(USER_NAME_PETER, ACTIVE_STATUS)); - userRepository.save(new User("SAMPLE", INACTIVE_STATUS)); - userRepository.save(new User("SAMPLE1", INACTIVE_STATUS)); - userRepository.save(new User("SAMPLE2", INACTIVE_STATUS)); - userRepository.save(new User("SAMPLE3", INACTIVE_STATUS)); - - Page usersPage = userRepository.findAllUsersWithPagination(new PageRequest(1, 3)); - - assertThat(usersPage.getContent().get(0).getName()).isEqualTo("SAMPLE1"); - } - - @Test - public void givenUsersInDBWhenFindAllWithPageRequestQueryAnnotationNativeThenReturnPageOfUsers() { - userRepository.save(new User(USER_NAME_ADAM, ACTIVE_STATUS)); - userRepository.save(new User(USER_NAME_PETER, ACTIVE_STATUS)); - userRepository.save(new User("SAMPLE", INACTIVE_STATUS)); - userRepository.save(new User("SAMPLE1", INACTIVE_STATUS)); - userRepository.save(new User("SAMPLE2", INACTIVE_STATUS)); - userRepository.save(new User("SAMPLE3", INACTIVE_STATUS)); - - Page usersSortByNameLength = userRepository.findAllUsersWithPaginationNative(new PageRequest(1, 3)); - - assertThat(usersSortByNameLength.getContent().get(0).getName()).isEqualTo("SAMPLE1"); - } - - @Test - @Transactional - public void givenUsersInDBWhenUpdateStatusForNameModifyingQueryAnnotationJPQLThenModifyMatchingUsers() { - userRepository.save(new User("SAMPLE", ACTIVE_STATUS)); - userRepository.save(new User("SAMPLE1", ACTIVE_STATUS)); - userRepository.save(new User("SAMPLE", ACTIVE_STATUS)); - userRepository.save(new User("SAMPLE3", ACTIVE_STATUS)); - - int updatedUsersSize = userRepository.updateUserSetStatusForName(INACTIVE_STATUS, "SAMPLE"); - - assertThat(updatedUsersSize).isEqualTo(2); - } - - @Test - @Transactional - public void givenUsersInDBWhenUpdateStatusForNameModifyingQueryAnnotationNativeThenModifyMatchingUsers() { - userRepository.save(new User("SAMPLE", ACTIVE_STATUS)); - userRepository.save(new User("SAMPLE1", ACTIVE_STATUS)); - userRepository.save(new User("SAMPLE", ACTIVE_STATUS)); - userRepository.save(new User("SAMPLE3", ACTIVE_STATUS)); - userRepository.flush(); - - int updatedUsersSize = userRepository.updateUserSetStatusForNameNative(INACTIVE_STATUS, "SAMPLE"); - - assertThat(updatedUsersSize).isEqualTo(2); + assertThat(userByStatus + .get() + .getName()).isEqualTo(USER_NAME_ADAM); } @After From 3a5715cf4af443525767f807824ac9f32f016d08 Mon Sep 17 00:00:00 2001 From: Grzegorz Piwowarek Date: Wed, 2 May 2018 07:26:27 +0200 Subject: [PATCH 11/66] Update README.md (#4154) --- libraries/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/libraries/README.md b/libraries/README.md index b421c1d41b..268db7bd56 100644 --- a/libraries/README.md +++ b/libraries/README.md @@ -75,6 +75,7 @@ - [A Guide to Apache Commons Collections CollectionUtils](http://www.baeldung.com/apache-commons-collection-utils) - [A Guide to Byte Buddy](http://www.baeldung.com/byte-buddy) - [Java Concurrency Utility with JCTools](http://www.baeldung.com/java-concurrency-jc-tools) +- [Apache Commons Collections MapUtils](http://www.baeldung.com/apache-commons-map-utils) 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 2ff50cca98977aae31ca903f4f9942960f6bba84 Mon Sep 17 00:00:00 2001 From: Grzegorz Piwowarek Date: Wed, 2 May 2018 07:26:40 +0200 Subject: [PATCH 12/66] Update README.md (#4153) --- core-java/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java/README.md b/core-java/README.md index c1fef3e4f2..44bc6d0ee5 100644 --- a/core-java/README.md +++ b/core-java/README.md @@ -128,3 +128,4 @@ - [Finding Max/Min of a List or Collection](http://www.baeldung.com/java-collection-min-max) - [The "final" Keyword in Java](http://www.baeldung.com/java-final) - [Service Locator Pattern](http://www.baeldung.com/java-service-locator-pattern) +- [Type Erasure in Java Explained](http://www.baeldung.com/java-type-erasure) From b77aa2252775672ec89fe7ca354591bdcfc4cb7c Mon Sep 17 00:00:00 2001 From: Grzegorz Piwowarek Date: Wed, 2 May 2018 07:26:49 +0200 Subject: [PATCH 13/66] Update README.md (#4152) --- core-java-io/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-io/README.md b/core-java-io/README.md index 84720e7b77..a77d526aba 100644 --- a/core-java-io/README.md +++ b/core-java-io/README.md @@ -25,3 +25,4 @@ - [Zipping and Unzipping in Java](http://www.baeldung.com/java-compress-and-uncompress) - [Java NIO2 Path API](http://www.baeldung.com/java-nio-2-path) - [A Guide to WatchService in Java NIO2](http://www.baeldung.com/java-nio2-watchservice) +- [Guide to Java NIO2 Asynchronous Channel APIs](http://www.baeldung.com/java-nio-2-async-channels) From e7672c79f0e74eaac1026ebbc856bfab61a885b0 Mon Sep 17 00:00:00 2001 From: Grzegorz Piwowarek Date: Wed, 2 May 2018 09:20:16 +0200 Subject: [PATCH 14/66] Update README.md (#4156) --- core-java/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core-java/README.md b/core-java/README.md index 44bc6d0ee5..7b32b38b0f 100644 --- a/core-java/README.md +++ b/core-java/README.md @@ -129,3 +129,5 @@ - [The "final" Keyword in Java](http://www.baeldung.com/java-final) - [Service Locator Pattern](http://www.baeldung.com/java-service-locator-pattern) - [Type Erasure in Java Explained](http://www.baeldung.com/java-type-erasure) +- [BigDecimal and BigInteger in Java](http://www.baeldung.com/java-bigdecimal-biginteger) +- [Display All Time Zones With GMT And UTC in Java](http://www.baeldung.com/java-time-zones) From fdd80a278fad611be1e79c6f64e71071ef513a6b Mon Sep 17 00:00:00 2001 From: Grzegorz Piwowarek Date: Wed, 2 May 2018 09:20:30 +0200 Subject: [PATCH 15/66] Update README.md (#4155) --- core-java-io/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-io/README.md b/core-java-io/README.md index a77d526aba..1354854e1f 100644 --- a/core-java-io/README.md +++ b/core-java-io/README.md @@ -26,3 +26,4 @@ - [Java NIO2 Path API](http://www.baeldung.com/java-nio-2-path) - [A Guide to WatchService in Java NIO2](http://www.baeldung.com/java-nio2-watchservice) - [Guide to Java NIO2 Asynchronous Channel APIs](http://www.baeldung.com/java-nio-2-async-channels) +- [A Guide to NIO2 Asynchronous Socket Channel](http://www.baeldung.com/java-nio2-async-socket-channel) From fad99fe44b91fc4c519f049554f15fb63cf75615 Mon Sep 17 00:00:00 2001 From: collaboratewithakash <38683470+collaboratewithakash@users.noreply.github.com> Date: Wed, 2 May 2018 13:11:09 +0530 Subject: [PATCH 16/66] Back-links added (#4119) * Back-link added * Back-link added * Back-link added * Back-link added * Back-link added * Back-link added * Back-link added * Back-link added * Back-link added * Back-link added * Back-link added * Back-link corrected * Back-link added * Back-link added * Back-link added * Back-link added * Back-link added * Back-link added * Back-link added * Back-link added * Back-link added * Back-link added * Back-link added * Back-link added * Back-link added * Back-link corrected * Back-link corrected * Back-link corrected * Back-link correct * Back-link corrected * Back-link added * Back-link added * Back-link added * Back-link added * Back-link added * Back-link added * Back-link added * Back-link added * Back-link added * Back-link added * Back-link added * Back-link added * Back-link added * Back-link added * Back-link added * Back-link added * Back-link added * Back-link added * Back-link added * Back-link added * Back-link added * Back-link added * Back-link added * Back-link added * Back-link added * Back-link added * Back-link added * Back-link added * Back-link added * Back-link added * Back-link added * Back-link corrected * Back-link added * Back-link corrected * Back-link corrected * Back-link corrected --- aws/README.md | 3 +++ cas/cas-secured-app/README.md | 1 + core-java-8/README.md | 3 +++ core-java-9/README.md | 1 + core-java/README.md | 11 ++++++++++- core-kotlin/README.md | 1 + ethereumj/README.md | 1 + guava/src/test/java/org/baeldung/hamcrest/README.md | 1 + influxdb/README.md | 3 ++- javax-servlets/README.md | 1 + json/README.md | 3 ++- libraries-data/README.md | 2 +- libraries/README.md | 6 ++++++ persistence-modules/querydsl/README.md | 1 + persistence-modules/spring-jpa/README.md | 3 +++ rxjava/README.md | 1 + spring-5-security/README.md | 3 ++- spring-all/README.md | 2 ++ spring-boot/README.MD | 4 ++-- spring-core/README.md | 1 + spring-data-spring-security/README.md | 2 +- spring-exceptions/README.md | 1 + spring-hibernate4/README.md | 2 +- spring-mvc-forms-jsp/README.md | 1 + spring-mvc-java/README.md | 5 +++-- spring-mvc-kotlin/README.md | 2 +- spring-mvc-simple/README.md | 1 + spring-mvc-xml/README.md | 1 + spring-quartz/README.md | 6 +++++- spring-rest-angular/README.md | 1 + spring-rest-full/README.md | 9 +++++---- spring-thymeleaf/README.md | 1 + testing-modules/mockito/README.md | 1 + testing-modules/mocks/mock-comparisons/README.md | 1 + vavr/README.md | 2 +- xml/README.md | 1 + 36 files changed, 71 insertions(+), 18 deletions(-) diff --git a/aws/README.md b/aws/README.md index 3ec2f1d82b..95de3c8464 100644 --- a/aws/README.md +++ b/aws/README.md @@ -5,4 +5,7 @@ - [AWS Lambda With Java](http://www.baeldung.com/java-aws-lambda) - [Managing EC2 Instances in Java](http://www.baeldung.com/ec2-java) - [http://www.baeldung.com/aws-s3-multipart-upload](https://github.com/eugenp/tutorials/tree/master/aws) +- [Multipart Uploads in Amazon S3 with Java](http://www.baeldung.com/aws-s3-multipart-upload) +- [Integration Testing with a Local DynamoDB Instance](http://www.baeldung.com/dynamodb-local-integration-tests) +- [Using the JetS3t Java Client With Amazon S3](http://www.baeldung.com/jets3t-amazon-s3) diff --git a/cas/cas-secured-app/README.md b/cas/cas-secured-app/README.md index 01c5f91988..b2f6dac99a 100644 --- a/cas/cas-secured-app/README.md +++ b/cas/cas-secured-app/README.md @@ -1,2 +1,3 @@ ## Relevant articles: - [CAS SSO With Spring Security](http://www.baeldung.com/spring-security-cas-sso) +- [Code Analysis with SonarQube](http://www.baeldung.com/sonar-qube) diff --git a/core-java-8/README.md b/core-java-8/README.md index cba83d28fb..f3287651e1 100644 --- a/core-java-8/README.md +++ b/core-java-8/README.md @@ -44,3 +44,6 @@ - [Java 8 StringJoiner](http://www.baeldung.com/java-string-joiner) - [Introduction to Spliterator in Java](http://www.baeldung.com/java-spliterator) - [Java 8 Math New Methods](http://www.baeldung.com/java-8-math) +- [Overview of Java Built-in Annotations](http://www.baeldung.com/java-default-annotations) +- [Finding Min/Max in an Array with Java](http://www.baeldung.com/java-array-min-max) +- [Internationalization and Localization in Java 8](http://www.baeldung.com/java-8-localization) diff --git a/core-java-9/README.md b/core-java-9/README.md index d0758d585b..59b0929871 100644 --- a/core-java-9/README.md +++ b/core-java-9/README.md @@ -23,3 +23,4 @@ - [Exploring the New HTTP Client in Java 9](http://www.baeldung.com/java-9-http-client) - [Method Handles in Java](http://www.baeldung.com/java-method-handles) - [Introduction to Chronicle Queue](http://www.baeldung.com/java-chronicle-queue) +- [A Guide to Java 9 Modularity](http://www.baeldung.com/java-9-modularity) diff --git a/core-java/README.md b/core-java/README.md index 7b32b38b0f..14bd26e821 100644 --- a/core-java/README.md +++ b/core-java/README.md @@ -116,7 +116,7 @@ - [Comparing Strings in Java](http://www.baeldung.com/java-compare-strings) - [Guide to Inheritance in Java](http://www.baeldung.com/java-inheritance) - [Guide to Externalizable Interface in Java](http://www.baeldung.com/java-externalizable) -- [The Observer Pattern in Java](https://github.com/eugenp/tutorials/tree/master/core-java) +- [The Observer Pattern in Java](http://www.baeldung.com/java-observer-pattern) - [Flyweight Pattern in Java](http://www.baeldung.com/java-flyweight) - [Object Type Casting in Java](http://www.baeldung.com/java-type-casting) - [A Practical Guide to DecimalFormat](http://www.baeldung.com/java-decimalformat) @@ -127,6 +127,15 @@ - [Inheritance and Composition (Is-a vs Has-a relationship) in Java](http://www.baeldung.com/java-inheritance-composition) - [Finding Max/Min of a List or Collection](http://www.baeldung.com/java-collection-min-max) - [The "final" Keyword in Java](http://www.baeldung.com/java-final) +- [What is the serialVersionUID?](http://www.baeldung.com/java-serial-version-uid) +- [A Guide To UDP In Java](http://www.baeldung.com/udp-in-java) +- [A Guide to the Java LinkedList](http://www.baeldung.com/java-linkedlist) +- [A Guide to Java Enums](http://www.baeldung.com/a-guide-to-java-enums) +- [A Guide to the ResourceBundle](http://www.baeldung.com/java-resourcebundle) +- [Quick Guide to java.lang.System](http://www.baeldung.com/java-lang-system) +- [Class Loaders in Java](http://www.baeldung.com/java-classloaders) +- [Find Sum and Average in a Java Array](http://www.baeldung.com/java-array-sum-average) +- [Java List UnsupportedOperationException](http://www.baeldung.com/java-list-unsupported-operation-exception) - [Service Locator Pattern](http://www.baeldung.com/java-service-locator-pattern) - [Type Erasure in Java Explained](http://www.baeldung.com/java-type-erasure) - [BigDecimal and BigInteger in Java](http://www.baeldung.com/java-bigdecimal-biginteger) diff --git a/core-kotlin/README.md b/core-kotlin/README.md index 630d4c7436..ce47cc2541 100644 --- a/core-kotlin/README.md +++ b/core-kotlin/README.md @@ -25,3 +25,4 @@ - [Objects in Kotlin](http://www.baeldung.com/kotlin-objects) - [Reading from a File in Kotlin](http://www.baeldung.com/kotlin-read-file) - [Guide to Kotlin @JvmField](http://www.baeldung.com/kotlin-jvm-field-annotation) +- [Filtering Kotlin Collections](http://www.baeldung.com/kotlin-filter-collection) diff --git a/ethereumj/README.md b/ethereumj/README.md index d2e2753438..5a0be0bd16 100644 --- a/ethereumj/README.md +++ b/ethereumj/README.md @@ -2,3 +2,4 @@ ### Relevant Articles: - [Introduction to EthereumJ](http://www.baeldung.com/ethereumj) +- [Creating and Deploying Smart Contracts with Solidity](http://www.baeldung.com/smart-contracts-ethereum-solidity) diff --git a/guava/src/test/java/org/baeldung/hamcrest/README.md b/guava/src/test/java/org/baeldung/hamcrest/README.md index 7266ecda3a..456108d78a 100644 --- a/guava/src/test/java/org/baeldung/hamcrest/README.md +++ b/guava/src/test/java/org/baeldung/hamcrest/README.md @@ -1,2 +1,3 @@ ### Relevant Articles: - [Testing with Hamcrest](http://www.baeldung.com/java-junit-hamcrest-guide) +- [Hamcrest File Matchers](http://www.baeldung.com/hamcrest-file-matchers) diff --git a/influxdb/README.md b/influxdb/README.md index f2c421580e..a24b2a08ad 100644 --- a/influxdb/README.md +++ b/influxdb/README.md @@ -1,7 +1,8 @@ ## Influx SDK Tutorial Project ### Relevant Article: -- [Introduction to using InfluxDB with Java](http://www.baeldung.com/using-influxdb-with-java/) +- [Using InfluxDB with Java](http://www.baeldung.com/java-influxdb) + ### Overview This Maven project contains the Java code for the article linked above. diff --git a/javax-servlets/README.md b/javax-servlets/README.md index ff2256b3c0..84330ac94c 100644 --- a/javax-servlets/README.md +++ b/javax-servlets/README.md @@ -1,3 +1,4 @@ ### Relevant Articles: - [Introduction to Java Servlets](http://www.baeldung.com/intro-to-servlets) - [An MVC Example with Servlets and JSP](http://www.baeldung.com/mvc-servlet-jsp) +- [Handling Cookies and a Session in a Java Servlet](http://www.baeldung.com/java-servlet-cookies-session) diff --git a/json/README.md b/json/README.md index e217da170f..1317ada8be 100644 --- a/json/README.md +++ b/json/README.md @@ -4,6 +4,7 @@ ### Relevant Articles: - [Introduction to JSON Schema in Java](http://www.baeldung.com/introduction-to-json-schema-in-java) -- [A Guide to FastJson](http://www.baeldung.com/????????) +- [A Guide to FastJson](http://www.baeldung.com/fastjson) - [Introduction to JSONForms](http://www.baeldung.com/introduction-to-jsonforms) - [Introduction to JsonPath](http://www.baeldung.com/guide-to-jayway-jsonpath) +- [Introduction to JSON-Java (org.json)](http://www.baeldung.com/java-org-json) diff --git a/libraries-data/README.md b/libraries-data/README.md index c63aefb698..1d7078d203 100644 --- a/libraries-data/README.md +++ b/libraries-data/README.md @@ -3,5 +3,5 @@ - [Introduction to ORMLite](http://www.baeldung.com/ormlite) - [Introduction To Kryo](http://www.baeldung.com/kryo) - [Introduction to KafkaStreams in Java](http://www.baeldung.com/java-kafka-streams) +- [A Guide to Apache Ignite](http://www.baeldung.com/apache-ignite) - [Apache Ignite with Spring Data](http://www.baeldung.com/apache-ignite-spring-data) - diff --git a/libraries/README.md b/libraries/README.md index 268db7bd56..bf8c075663 100644 --- a/libraries/README.md +++ b/libraries/README.md @@ -74,6 +74,12 @@ - [Introduction to Akka Actors in Java](http://www.baeldung.com/akka-actors-java) - [A Guide to Apache Commons Collections CollectionUtils](http://www.baeldung.com/apache-commons-collection-utils) - [A Guide to Byte Buddy](http://www.baeldung.com/byte-buddy) +- [Introduction to jOOL](http://www.baeldung.com/jool) +- [Consumer Driven Contracts with Pact](http://www.baeldung.com/pact-junit-consumer-driven-contracts) +- [Apache Commons BeanUtils](http://www.baeldung.com/apache-commons-beanutils) +- [Apache Commons Collections BidiMap](http://www.baeldung.com/commons-collections-bidi-map) +- [Introduction to Atlassian Fugue](http://www.baeldung.com/java-fugue) +- [Publish and Receive Messages with Nats Java Client](http://www.baeldung.com/nats-java-client) - [Java Concurrency Utility with JCTools](http://www.baeldung.com/java-concurrency-jc-tools) - [Apache Commons Collections MapUtils](http://www.baeldung.com/apache-commons-map-utils) diff --git a/persistence-modules/querydsl/README.md b/persistence-modules/querydsl/README.md index ef9f8f894c..77b9fd6baf 100644 --- a/persistence-modules/querydsl/README.md +++ b/persistence-modules/querydsl/README.md @@ -1,2 +1,3 @@ ### Relevant Articles: - [Intro to Querydsl](http://www.baeldung.com/intro-to-querydsl) +- [A Guide to Querydsl with JPA](http://www.baeldung.com/querydsl-with-jpa-tutorial) diff --git a/persistence-modules/spring-jpa/README.md b/persistence-modules/spring-jpa/README.md index bd406e8d6e..6a7153b524 100644 --- a/persistence-modules/spring-jpa/README.md +++ b/persistence-modules/spring-jpa/README.md @@ -17,6 +17,9 @@ - [Spring Data JPA – Adding a Method in All Repositories](http://www.baeldung.com/spring-data-jpa-method-in-all-repositories) - [A Guide to Spring AbstractRoutingDatasource](http://www.baeldung.com/spring-abstract-routing-data-source) - [Advanced Tagging Implementation with JPA] (http://www.baeldung.com/jpa-tagging-advanced) +- [A Guide to Hibernate with Spring 4](http://www.baeldung.com/the-persistence-layer-with-spring-and-jpa) +- [Testing REST with multiple MIME types](http://www.baeldung.com/testing-rest-api-with-multiple-media-types) +- [Obtaining Auto-generated Keys in Spring JDBC](http://www.baeldung.com/spring-jdbc-autogenerated-keys) ### Eclipse Config After importing the project into Eclipse, you may see the following error: diff --git a/rxjava/README.md b/rxjava/README.md index b92e7deaae..3376c49426 100644 --- a/rxjava/README.md +++ b/rxjava/README.md @@ -14,3 +14,4 @@ - [RxJava StringObservable](http://www.baeldung.com/rxjava-string) - [RxJava Maybe](http://www.baeldung.com/rxjava-maybe) - [Introduction to RxRelay for RxJava](http://www.baeldung.com/rx-relay) +- [Filtering Observables in RxJava](http://www.baeldung.com/rxjava-filtering) diff --git a/spring-5-security/README.md b/spring-5-security/README.md index 6e9f3ab1e5..94a8f83281 100644 --- a/spring-5-security/README.md +++ b/spring-5-security/README.md @@ -1,6 +1,7 @@ ## Relevant articles: - [Spring Security 5 -OAuth2 Login](http://www.baeldung.com/spring-security-5-oauth2-login) -- [Extra Login Fields with Spring Security](https://github.com/eugenp/tutorials/tree/master/spring-5-security) +- [Extra Login Fields with Spring Security](http://www.baeldung.com/spring-security-extra-login-fields) - [A Custom Spring SecurityConfigurer](http://www.baeldung.com/spring-security-custom-configurer) +- [New Password Storage In Spring Security 5](http://www.baeldung.com/spring-security-5-password-storage) diff --git a/spring-all/README.md b/spring-all/README.md index e1504a66db..0902a11a77 100644 --- a/spring-all/README.md +++ b/spring-all/README.md @@ -24,3 +24,5 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [A CLI with Spring Shell](http://www.baeldung.com/spring-shell-cli) - [JasperReports with Spring](http://www.baeldung.com/spring-jasper) - [Model, ModelMap, and ModelView in Spring MVC](http://www.baeldung.com/spring-mvc-model-model-map-model-view) +- [A Guide To Caching in Spring](http://www.baeldung.com/spring-cache-tutorial) +- [How To Do @Async in Spring](http://www.baeldung.com/spring-async) diff --git a/spring-boot/README.MD b/spring-boot/README.MD index 365b120971..7e68e30a47 100644 --- a/spring-boot/README.MD +++ b/spring-boot/README.MD @@ -34,5 +34,5 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [An Introduction to Kong](http://www.baeldung.com/kong) - [Spring Boot Customize Whitelabel Error Page](http://www.baeldung.com/spring-boot-custom-error-page) - [Spring Boot: Configuring a Main Class](http://www.baeldung.com/spring-boot-main-class) -- [A Quick Intro to the SpringBootServletInitializer](http://www.baeldung.com/spring-boot-servlet-initializer) - +- [Shutdown a Spring Boot Application](http://www.baeldung.com/spring-boot-shutdown) +- [A Quick Intro to the SpringBootServletInitializer](http://www.baeldung.com/spring-boot-servlet-initializer) \ No newline at end of file diff --git a/spring-core/README.md b/spring-core/README.md index b6804a4ce0..5f50b35553 100644 --- a/spring-core/README.md +++ b/spring-core/README.md @@ -13,3 +13,4 @@ - [A Quick Guide to the Spring @Lazy Annotation](http://www.baeldung.com/spring-lazy-annotation) - [Injecting Prototype Beans into a Singleton Instance in Spring](http://www.baeldung.com/spring-inject-prototype-bean-into-singleton) - [How to Inject a Property Value Into a Class Not Managed by Spring?](http://www.baeldung.com/inject-properties-value-non-spring-class) +- [@Lookup Annotation in Spring](http://www.baeldung.com/spring-lookup) diff --git a/spring-data-spring-security/README.md b/spring-data-spring-security/README.md index 15b4b50870..da65527a8a 100644 --- a/spring-data-spring-security/README.md +++ b/spring-data-spring-security/README.md @@ -11,4 +11,4 @@ The application uses [Spring Boot](http://projects.spring.io/spring-boot/), so i To view the running application, visit [http://localhost:8080](http://localhost:8080) in your browser ###Relevant Articles: -- [Spring Data with Spring Security](http://www.baeldung.com/spring-data-with-spring-security) +- [Spring Data with Spring Security](http://www.baeldung.com/spring-data-security) diff --git a/spring-exceptions/README.md b/spring-exceptions/README.md index fd9250c6da..b9472c4cca 100644 --- a/spring-exceptions/README.md +++ b/spring-exceptions/README.md @@ -11,3 +11,4 @@ This project is used to replicate Spring Exceptions only. - [Spring BeanDefinitionStoreException](http://www.baeldung.com/spring-beandefinitionstoreexception) - [Spring NoSuchBeanDefinitionException](http://www.baeldung.com/spring-nosuchbeandefinitionexception) - [Guide to Spring NonTransientDataAccessException](http://www.baeldung.com/nontransientdataaccessexception) +- [Hibernate Mapping Exception – Unknown Entity](http://www.baeldung.com/hibernate-mappingexception-unknown-entity) diff --git a/spring-hibernate4/README.md b/spring-hibernate4/README.md index 08cfe2b538..4284a253cc 100644 --- a/spring-hibernate4/README.md +++ b/spring-hibernate4/README.md @@ -4,7 +4,7 @@ ### Relevant Articles: - [Hibernate 4 with Spring](http://www.baeldung.com/hibernate-4-spring) -- [The DAO with Spring 3 and Hibernate](http://www.baeldung.com/2011/12/02/the-persistence-layer-with-spring-3-1-and-hibernate/) +- [The DAO with Spring 3 and Hibernate](http://www.baeldung.com/persistence-layer-with-spring-and-hibernate) - [Hibernate Pagination](http://www.baeldung.com/hibernate-pagination) - [Sorting with Hibernate](http://www.baeldung.com/hibernate-sort) - [Auditing with JPA, Hibernate, and Spring Data JPA](http://www.baeldung.com/database-auditing-jpa) diff --git a/spring-mvc-forms-jsp/README.md b/spring-mvc-forms-jsp/README.md index 826be378b1..44786d5ec7 100644 --- a/spring-mvc-forms-jsp/README.md +++ b/spring-mvc-forms-jsp/README.md @@ -5,3 +5,4 @@ - [Getting Started with Forms in Spring MVC](http://www.baeldung.com/spring-mvc-form-tutorial) - [Form Validation with AngularJS and Spring MVC](http://www.baeldung.com/validation-angularjs-spring-mvc) - [Guide to JSTL](http://www.baeldung.com/guide-to-jstl) +- [A Guide to the JSTL Library](http://www.baeldung.com/jstl) diff --git a/spring-mvc-java/README.md b/spring-mvc-java/README.md index fd6002be62..5f62f71211 100644 --- a/spring-mvc-java/README.md +++ b/spring-mvc-java/README.md @@ -24,5 +24,6 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [Spring MVC Custom Validation](http://www.baeldung.com/spring-mvc-custom-validator) - [web.xml vs Initializer with Spring](http://www.baeldung.com/spring-xml-vs-java-config) - [The HttpMediaTypeNotAcceptableException in Spring MVC](http://www.baeldung.com/spring-httpmediatypenotacceptable) -- [Spring MVC @PathVariable with a dot (.) gets truncated](http://www.baeldung.com/spring-mvc-pathvariable-dot) - +- [Spring MVC and the @ModelAttribute Annotation](http://www.baeldung.com/spring-mvc-and-the-modelattribute-annotation) +- [The Spring @Controller and @RestController Annotations](http://www.baeldung.com/spring-controller-vs-restcontroller) +- [Spring MVC @PathVariable with a dot (.) gets truncated](http://www.baeldung.com/spring-mvc-pathvariable-dot) \ No newline at end of file diff --git a/spring-mvc-kotlin/README.md b/spring-mvc-kotlin/README.md index 4e92117c52..e5167f69fc 100644 --- a/spring-mvc-kotlin/README.md +++ b/spring-mvc-kotlin/README.md @@ -1,4 +1,4 @@ ### Relevant articles - [Spring MVC Setup with Kotlin](http://www.baeldung.com/spring-mvc-kotlin) -- [Working with Kotlin and JPA](https://github.com/eugenp/tutorials/tree/master/spring-mvc-kotlin) +- [Working with Kotlin and JPA](http://www.baeldung.com/kotlin-jpa) - [Kotlin-allopen and Spring](http://www.baeldung.com/kotlin-allopen-spring) diff --git a/spring-mvc-simple/README.md b/spring-mvc-simple/README.md index 69a9027280..600a448076 100644 --- a/spring-mvc-simple/README.md +++ b/spring-mvc-simple/README.md @@ -3,3 +3,4 @@ - [HandlerAdapters in Spring MVC](http://www.baeldung.com/spring-mvc-handler-adapters) - [Template Engines for Spring](http://www.baeldung.com/spring-template-engines) - [Spring 5 and Servlet 4 – The PushBuilder](http://www.baeldung.com/spring-5-push) +- [Servlet Redirect vs Forward](http://www.baeldung.com/servlet-redirect-forward) diff --git a/spring-mvc-xml/README.md b/spring-mvc-xml/README.md index 7a5e8c75e9..6333b20e11 100644 --- a/spring-mvc-xml/README.md +++ b/spring-mvc-xml/README.md @@ -15,3 +15,4 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [Geolocation by IP in Java](http://www.baeldung.com/geolocation-by-ip-with-maxmind) - [Guide to JavaServer Pages (JSP)](http://www.baeldung.com/jsp) - [Exploring SpringMVC’s Form Tag Library](http://www.baeldung.com/spring-mvc-form-tags) +- [web.xml vs Initializer with Spring](http://www.baeldung.com/spring-xml-vs-java-config) diff --git a/spring-quartz/README.md b/spring-quartz/README.md index caac75e5d4..5d32e65053 100644 --- a/spring-quartz/README.md +++ b/spring-quartz/README.md @@ -19,4 +19,8 @@ org.baeldung.springquartz.SpringQuartzApp - To configure scheduler using Quartz API: ``` using.spring.schedulerFactory=false - ``` \ No newline at end of file + ``` + +### Relevant Articles: +- [Scheduling in Spring with Quartz](http://www.baeldung.com/spring-quartz-schedule) + diff --git a/spring-rest-angular/README.md b/spring-rest-angular/README.md index dcbbd048ba..7ead9442fd 100644 --- a/spring-rest-angular/README.md +++ b/spring-rest-angular/README.md @@ -3,3 +3,4 @@ ### Relevant Articles: - [Spring’s RequestBody and ResponseBody Annotations](http://www.baeldung.com/spring-request-response-body) +- [Pagination with Spring REST and AngularJS table](http://www.baeldung.com/pagination-with-a-spring-rest-api-and-an-angularjs-table) diff --git a/spring-rest-full/README.md b/spring-rest-full/README.md index a1fea806ef..b1917fb225 100644 --- a/spring-rest-full/README.md +++ b/spring-rest-full/README.md @@ -8,17 +8,18 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring The "Learn Spring Security" Classes: http://github.learnspringsecurity.com ### Relevant Articles: -- [REST Pagination in Spring](http://www.baeldung.com/2012/01/18/rest-pagination-in-spring/) +- [REST Pagination in Spring](http://www.baeldung.com/rest-api-pagination-in-spring) - [HATEOAS for a Spring REST Service](http://www.baeldung.com/2011/11/13/rest-service-discoverability-with-spring-part-5/) -- [REST API Discoverability and HATEOAS](http://www.baeldung.com/2011/11/06/restful-web-service-discoverability-part-4/) +- [REST API Discoverability and HATEOAS](http://www.baeldung.com/restful-web-service-discoverability) - [ETags for REST with Spring](http://www.baeldung.com/2013/01/11/etags-for-rest-with-spring/) -- [Integration Testing with the Maven Cargo plugin](http://www.baeldung.com/2011/10/16/how-to-set-up-integration-testing-with-the-maven-cargo-plugin/) +- [Integration Testing with the Maven Cargo plugin](http://www.baeldung.com/integration-testing-with-the-maven-cargo-plugin) - [Introduction to Spring Data JPA](http://www.baeldung.com/2011/12/22/the-persistence-layer-with-spring-data-jpa/) - [Project Configuration with Spring](http://www.baeldung.com/2012/03/12/project-configuration-with-spring/) - [Metrics for your Spring REST API](http://www.baeldung.com/spring-rest-api-metrics) - [Spring RestTemplate Tutorial](http://www.baeldung.com/rest-template) - [Bootstrap a Web Application with Spring 4](http://www.baeldung.com/bootstraping-a-web-application-with-spring-and-java-based-configuration) - +- [Build a REST API with Spring 4 and Java Config](http://www.baeldung.com/building-a-restful-web-service-with-spring-and-java-based-configuration) +- [Error Handling for REST with Spring](http://www.baeldung.com/exception-handling-for-rest-with-spring) diff --git a/spring-thymeleaf/README.md b/spring-thymeleaf/README.md index 9210186a98..44393ac281 100644 --- a/spring-thymeleaf/README.md +++ b/spring-thymeleaf/README.md @@ -12,6 +12,7 @@ - [How to Create an Executable JAR with Maven](http://www.baeldung.com/executable-jar-with-maven) - [Working with Booleans in Thymeleaf](http://www.baeldung.com/working-with-booleans-in-thymeleaf) - [Working with Fragments in Thymeleaf](http://www.baeldung.com/spring-thymeleaf-fragments) +- [Conditionals in Thymeleaf](http://www.baeldung.com/spring-thymeleaf-conditionals) ### Build the Project diff --git a/testing-modules/mockito/README.md b/testing-modules/mockito/README.md index e158820769..72c769ce4f 100644 --- a/testing-modules/mockito/README.md +++ b/testing-modules/mockito/README.md @@ -16,3 +16,4 @@ - [Mock Final Classes and Methods with Mockito](http://www.baeldung.com/mockito-final) - [Hamcrest Text Matchers] (http://www.baeldung.com/hamcrest-text-matchers) - [Hamcrest File Matchers] (http://www.baeldung.com/hamcrest-file-matchers) +- [Hamcrest Custom Matchers](http://www.baeldung.com/hamcrest-custom-matchers) diff --git a/testing-modules/mocks/mock-comparisons/README.md b/testing-modules/mocks/mock-comparisons/README.md index 7795487b77..20c13ecd72 100644 --- a/testing-modules/mocks/mock-comparisons/README.md +++ b/testing-modules/mocks/mock-comparisons/README.md @@ -5,3 +5,4 @@ ### Relevant Articles: - [Mockito vs EasyMock vs JMockit](http://www.baeldung.com/mockito-vs-easymock-vs-jmockit) +- [Introduction to EasyMock](http://www.baeldung.com/easymock) diff --git a/vavr/README.md b/vavr/README.md index 4bef25b625..c8570db04c 100644 --- a/vavr/README.md +++ b/vavr/README.md @@ -10,4 +10,4 @@ - [Collection Factory Methods for Vavr](http://www.baeldung.com/vavr-collection-factory-methods) - [Introduction to Future in Vavr](http://www.baeldung.com/vavr-future) - [Introduction to VRaptor in Java](http://www.baeldung.com/vraptor) - +- [Introduction to Vavr’s Either](http://www.baeldung.com/vavr-either) diff --git a/xml/README.md b/xml/README.md index 320089b088..7c3ebccac6 100644 --- a/xml/README.md +++ b/xml/README.md @@ -1,3 +1,4 @@ ### Relevant Articles: - [Intro to XPath with Java](http://www.baeldung.com/java-xpath) - [Introduction to JiBX](http://www.baeldung.com/jibx) +- [XML Libraries Support in Java](http://www.baeldung.com/java-xml-libraries) From ad5389cf6d7b468ecd4fe6d2936b28740c26fb4b Mon Sep 17 00:00:00 2001 From: Nikhil Khatwani Date: Wed, 2 May 2018 14:39:57 +0530 Subject: [PATCH 17/66] Changes for BAEL-1657 --- .../servlets/DeferredResultController.java | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 spring-boot/src/main/java/com/baeldung/servlets/DeferredResultController.java diff --git a/spring-boot/src/main/java/com/baeldung/servlets/DeferredResultController.java b/spring-boot/src/main/java/com/baeldung/servlets/DeferredResultController.java new file mode 100644 index 0000000000..c43b0e6dc0 --- /dev/null +++ b/spring-boot/src/main/java/com/baeldung/servlets/DeferredResultController.java @@ -0,0 +1,71 @@ +package com.baeldung.servlets; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.context.request.async.DeferredResult; + +@RestController +public class DeferredResultController { + + private final static Logger LOG = LoggerFactory.getLogger(DeferredResultController.class); + + @GetMapping("/async-deferredresult") + public DeferredResult> handleReqDefResult(Model model) { + LOG.info("Received async-deferredresult request"); + DeferredResult> output = new DeferredResult<>(); + new Thread(() -> { + LOG.info("Processing in separate thread"); + output.setResult(ResponseEntity.ok("ok")); + }).start(); + LOG.info("servlet thread freed"); + return output; + } + + public DeferredResult> handleReqWithTimeouts(Model model) { + LOG.info("Received async request with a configured timeout"); + DeferredResult> deferredResult = new DeferredResult<>(500l); + deferredResult.onTimeout(new Runnable() { + @Override + public void run() { + deferredResult.setErrorResult( + ResponseEntity.status(HttpStatus.REQUEST_TIMEOUT).body("Request timeout occurred.")); + } + }); + + new Thread(() -> { + LOG.info("Processing in separate thread"); + try { + Thread.sleep(600l); + deferredResult.setResult(ResponseEntity.ok("ok")); + } catch (InterruptedException e) { + LOG.info("Request processing interrupted"); + deferredResult.setErrorResult(ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) + .body("INTERNAL_SERVER_ERROR occurred.")); + } + + }).start(); + LOG.info("servlet thread freed"); + return deferredResult; + } + + public DeferredResult> handleAsyncFailedRequest(Model model) { + DeferredResult> deferredResult = new DeferredResult<>(); + new Thread(() -> { + try { + // Exception occurred in processing + throw new Exception(); + } catch (Exception e) { + LOG.info("Request processing failed"); + deferredResult.setErrorResult(ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) + .body("INTERNAL_SERVER_ERROR occurred.")); + } + }).start(); + return deferredResult; + } + +} From 7d41c7edb7fcb1d057aa85b0bde9c17fdaee3d3a Mon Sep 17 00:00:00 2001 From: ShyamVeda Date: Wed, 2 May 2018 18:41:59 +0530 Subject: [PATCH 18/66] Log4j 2 Programmatic Configuration BAEL 1338 (#4057) --- .../modify-xml-configuration/pom.xml | 19 ++++ .../config/CustomXMLConfigurationFactory.java | 29 ++++++ .../log4j2/config/MyXMLConfiguration.java | 35 +++++++ .../src/main/resources/log4j2.xml | 17 ++++ .../com/baeldung/log4j2/logtest/LogTest.java | 23 +++++ .../log4j2-programmatic-configuration/pom.xml | 34 +++++++ .../set-configuration-factory/pom.xml | 10 ++ .../config/CustomConfigurationFactory.java | 88 +++++++++++++++++ .../com/baeldung/log4j2/logtest/LogTest.java | 33 +++++++ .../simple-configuration-xml/pom.xml | 17 ++++ .../src/main/resources/log4j2.xml | 32 +++++++ .../com/baeldung/log4j2/logtest/LogTest.java | 30 ++++++ .../simple-configuration/pom.xml | 10 ++ .../config/CustomConfigurationFactory.java | 94 +++++++++++++++++++ .../com/baeldung/log4j2/logtest/LogTest.java | 22 +++++ .../simple-configurator/pom.xml | 10 ++ .../baeldung/log4j2/configure/LogTest.java | 40 ++++++++ .../baeldung/log4j2/logtest/LogPrinter.java | 15 +++ pom.xml | 1 + 19 files changed, 559 insertions(+) create mode 100644 logging-modules/log4j2-programmatic-configuration/modify-xml-configuration/pom.xml create mode 100644 logging-modules/log4j2-programmatic-configuration/modify-xml-configuration/src/main/java/com/baeldung/log4j2/config/CustomXMLConfigurationFactory.java create mode 100644 logging-modules/log4j2-programmatic-configuration/modify-xml-configuration/src/main/java/com/baeldung/log4j2/config/MyXMLConfiguration.java create mode 100644 logging-modules/log4j2-programmatic-configuration/modify-xml-configuration/src/main/resources/log4j2.xml create mode 100644 logging-modules/log4j2-programmatic-configuration/modify-xml-configuration/src/test/java/com/baeldung/log4j2/logtest/LogTest.java create mode 100644 logging-modules/log4j2-programmatic-configuration/pom.xml create mode 100644 logging-modules/log4j2-programmatic-configuration/set-configuration-factory/pom.xml create mode 100644 logging-modules/log4j2-programmatic-configuration/set-configuration-factory/src/main/java/com/baeldung/log4j2/config/CustomConfigurationFactory.java create mode 100644 logging-modules/log4j2-programmatic-configuration/set-configuration-factory/src/test/java/com/baeldung/log4j2/logtest/LogTest.java create mode 100644 logging-modules/log4j2-programmatic-configuration/simple-configuration-xml/pom.xml create mode 100644 logging-modules/log4j2-programmatic-configuration/simple-configuration-xml/src/main/resources/log4j2.xml create mode 100644 logging-modules/log4j2-programmatic-configuration/simple-configuration-xml/src/test/java/com/baeldung/log4j2/logtest/LogTest.java create mode 100644 logging-modules/log4j2-programmatic-configuration/simple-configuration/pom.xml create mode 100644 logging-modules/log4j2-programmatic-configuration/simple-configuration/src/main/java/com/baeldung/log4j2/config/CustomConfigurationFactory.java create mode 100644 logging-modules/log4j2-programmatic-configuration/simple-configuration/src/test/java/com/baeldung/log4j2/logtest/LogTest.java create mode 100644 logging-modules/log4j2-programmatic-configuration/simple-configurator/pom.xml create mode 100644 logging-modules/log4j2-programmatic-configuration/simple-configurator/src/test/java/com/baeldung/log4j2/configure/LogTest.java create mode 100644 logging-modules/log4j2-programmatic-configuration/simple-configurator/src/test/java/com/baeldung/log4j2/logtest/LogPrinter.java diff --git a/logging-modules/log4j2-programmatic-configuration/modify-xml-configuration/pom.xml b/logging-modules/log4j2-programmatic-configuration/modify-xml-configuration/pom.xml new file mode 100644 index 0000000000..74464a9631 --- /dev/null +++ b/logging-modules/log4j2-programmatic-configuration/modify-xml-configuration/pom.xml @@ -0,0 +1,19 @@ + + + 4.0.0 + + com.baeldung.log4j2 + log4j2-programmatic-configuration + 0.0.1-SNAPSHOT + + com.baeldung.log4j2 + modify-xml-configuration + 0.0.1-SNAPSHOT + modify-xml-configuration + http://maven.apache.org + + UTF-8 + + diff --git a/logging-modules/log4j2-programmatic-configuration/modify-xml-configuration/src/main/java/com/baeldung/log4j2/config/CustomXMLConfigurationFactory.java b/logging-modules/log4j2-programmatic-configuration/modify-xml-configuration/src/main/java/com/baeldung/log4j2/config/CustomXMLConfigurationFactory.java new file mode 100644 index 0000000000..e92c66f168 --- /dev/null +++ b/logging-modules/log4j2-programmatic-configuration/modify-xml-configuration/src/main/java/com/baeldung/log4j2/config/CustomXMLConfigurationFactory.java @@ -0,0 +1,29 @@ +/** + This class demonstrates on modifying the loaded xml configuration by + extending XMLConfigurationFactory as defined in section 4.4 of + "Programmatic Configuration with Log4j 2" +**/ +package com.baeldung.log4j2.config; + +import org.apache.logging.log4j.core.LoggerContext; +import org.apache.logging.log4j.core.config.Configuration; +import org.apache.logging.log4j.core.config.ConfigurationFactory; +import org.apache.logging.log4j.core.config.ConfigurationSource; +import org.apache.logging.log4j.core.config.Order; +import org.apache.logging.log4j.core.config.plugins.Plugin; +import org.apache.logging.log4j.core.config.xml.XmlConfigurationFactory; + +@Plugin(name = "CustomConfigurationFactory", category = ConfigurationFactory.CATEGORY) +@Order(50) +public class CustomXMLConfigurationFactory extends XmlConfigurationFactory { + + @Override + public Configuration getConfiguration(LoggerContext loggerContext, ConfigurationSource source) { + return new MyXMLConfiguration(loggerContext, source); + } + + @Override + public String[] getSupportedTypes() { + return new String[] { ".xml", "*" }; + } +} diff --git a/logging-modules/log4j2-programmatic-configuration/modify-xml-configuration/src/main/java/com/baeldung/log4j2/config/MyXMLConfiguration.java b/logging-modules/log4j2-programmatic-configuration/modify-xml-configuration/src/main/java/com/baeldung/log4j2/config/MyXMLConfiguration.java new file mode 100644 index 0000000000..45ee421316 --- /dev/null +++ b/logging-modules/log4j2-programmatic-configuration/modify-xml-configuration/src/main/java/com/baeldung/log4j2/config/MyXMLConfiguration.java @@ -0,0 +1,35 @@ +/** + This class demonstrates on overriding the configuration loaded through xml + as defined in section 4.4 of "Programmatic Configuration with Log4j 2" +**/ +package com.baeldung.log4j2.config; + +import org.apache.logging.log4j.Level; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.core.Appender; +import org.apache.logging.log4j.core.Layout; +import org.apache.logging.log4j.core.LoggerContext; +import org.apache.logging.log4j.core.appender.FileAppender; +import org.apache.logging.log4j.core.config.Configuration; +import org.apache.logging.log4j.core.config.ConfigurationSource; +import org.apache.logging.log4j.core.config.LoggerConfig; +import org.apache.logging.log4j.core.config.xml.XmlConfiguration; +import org.apache.logging.log4j.core.layout.PatternLayout; + +public class MyXMLConfiguration extends XmlConfiguration { + public MyXMLConfiguration(LoggerContext loggerContext, ConfigurationSource source) { + super(loggerContext, source); + } + + @Override + protected void doConfigure() { + super.doConfigure(); + final LoggerContext ctx = (LoggerContext) LogManager.getContext(false); + Configuration config = ctx.getConfiguration(); + LoggerConfig loggerConfig = config.getLoggerConfig("com"); + final Layout layout = PatternLayout.createLayout("[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n", null, config, null, null, false, false, null, null); + Appender appender = FileAppender.createAppender("target/test.log", "false", "false", "File", "true", "false", "false", "4000", layout, null, "false", null, config); + loggerConfig.addAppender(appender, Level.DEBUG, null); + addAppender(appender); + } +} diff --git a/logging-modules/log4j2-programmatic-configuration/modify-xml-configuration/src/main/resources/log4j2.xml b/logging-modules/log4j2-programmatic-configuration/modify-xml-configuration/src/main/resources/log4j2.xml new file mode 100644 index 0000000000..36823c8122 --- /dev/null +++ b/logging-modules/log4j2-programmatic-configuration/modify-xml-configuration/src/main/resources/log4j2.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/logging-modules/log4j2-programmatic-configuration/modify-xml-configuration/src/test/java/com/baeldung/log4j2/logtest/LogTest.java b/logging-modules/log4j2-programmatic-configuration/modify-xml-configuration/src/test/java/com/baeldung/log4j2/logtest/LogTest.java new file mode 100644 index 0000000000..993c0d0648 --- /dev/null +++ b/logging-modules/log4j2-programmatic-configuration/modify-xml-configuration/src/test/java/com/baeldung/log4j2/logtest/LogTest.java @@ -0,0 +1,23 @@ +package com.baeldung.log4j2.logtest; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.core.LoggerContext; +import org.apache.logging.log4j.core.config.plugins.util.PluginManager; +import org.junit.Test; + + +public class LogTest { + static{ + PluginManager.addPackage("com.baeldung.log4j2.config"); + } + + @Test + public void simpleProgrammaticConfiguration() { + Logger logger = LogManager.getLogger(); + LoggerContext ctx = (LoggerContext) LogManager.getContext(); + logger.debug("Debug log message"); + logger.info("Info log message"); + logger.error("Error log message"); + } +} diff --git a/logging-modules/log4j2-programmatic-configuration/pom.xml b/logging-modules/log4j2-programmatic-configuration/pom.xml new file mode 100644 index 0000000000..cd3aced397 --- /dev/null +++ b/logging-modules/log4j2-programmatic-configuration/pom.xml @@ -0,0 +1,34 @@ + + + 4.0.0 + com.baeldung.log4j2 + log4j2-programmatic-configuration + 0.0.1-SNAPSHOT + pom + + simple-configuration + set-configuration-factory + simple-configurator + simple-configuration-xml + modify-xml-configuration + + + + junit + junit + 4.12 + test + + + org.apache.logging.log4j + log4j-core + 2.11.0 + + + org.apache.logging.log4j + log4j-slf4j-impl + 2.11.0 + + + diff --git a/logging-modules/log4j2-programmatic-configuration/set-configuration-factory/pom.xml b/logging-modules/log4j2-programmatic-configuration/set-configuration-factory/pom.xml new file mode 100644 index 0000000000..f2a72563e9 --- /dev/null +++ b/logging-modules/log4j2-programmatic-configuration/set-configuration-factory/pom.xml @@ -0,0 +1,10 @@ + + 4.0.0 + + com.baeldung.log4j2 + log4j2-programmatic-configuration + 0.0.1-SNAPSHOT + + set-configuration-factory + \ No newline at end of file diff --git a/logging-modules/log4j2-programmatic-configuration/set-configuration-factory/src/main/java/com/baeldung/log4j2/config/CustomConfigurationFactory.java b/logging-modules/log4j2-programmatic-configuration/set-configuration-factory/src/main/java/com/baeldung/log4j2/config/CustomConfigurationFactory.java new file mode 100644 index 0000000000..9c48702ba0 --- /dev/null +++ b/logging-modules/log4j2-programmatic-configuration/set-configuration-factory/src/main/java/com/baeldung/log4j2/config/CustomConfigurationFactory.java @@ -0,0 +1,88 @@ +/** + This class demonstrates how to build the components of + the configuration factory, as described in Section 3 of + "Programmatic Configuration with Log4j 2" +**/ +package com.baeldung.log4j2.config; + +import java.io.IOException; +import java.net.URI; + +import org.apache.logging.log4j.Level; +import org.apache.logging.log4j.core.Filter; +import org.apache.logging.log4j.core.LoggerContext; +import org.apache.logging.log4j.core.config.Configuration; +import org.apache.logging.log4j.core.config.ConfigurationFactory; +import org.apache.logging.log4j.core.config.ConfigurationSource; +import org.apache.logging.log4j.core.config.builder.api.AppenderComponentBuilder; +import org.apache.logging.log4j.core.config.builder.api.ComponentBuilder; +import org.apache.logging.log4j.core.config.builder.api.ConfigurationBuilder; +import org.apache.logging.log4j.core.config.builder.api.FilterComponentBuilder; +import org.apache.logging.log4j.core.config.builder.api.LayoutComponentBuilder; +import org.apache.logging.log4j.core.config.builder.api.LoggerComponentBuilder; +import org.apache.logging.log4j.core.config.builder.api.RootLoggerComponentBuilder; +import org.apache.logging.log4j.core.config.builder.impl.BuiltConfiguration; + +public class CustomConfigurationFactory extends ConfigurationFactory { + + static Configuration createConfiguration(final String name, ConfigurationBuilder builder) { + AppenderComponentBuilder console = builder.newAppender("Stdout", "Console"); + LayoutComponentBuilder layout = builder.newLayout("PatternLayout") + .addAttribute("pattern", "%d [%t] %-5level: %msg%n%throwable"); + console.add(layout); + FilterComponentBuilder filter = builder.newFilter("MarkerFilter", Filter.Result.ACCEPT, Filter.Result.DENY); + filter.addAttribute("marker", "FLOW"); + console.add(filter); + builder.add(console); + ComponentBuilder triggeringPolicies = builder.newComponent("Policies") + .addComponent(builder.newComponent("CronTriggeringPolicy") + .addAttribute("schedule", "0 0 0 * * ?")) + .addComponent(builder.newComponent("SizeBasedTriggeringPolicy") + .addAttribute("size", "100M")); + AppenderComponentBuilder rollingFile = builder.newAppender("rolling", "RollingFile"); + rollingFile.addAttribute("fileName", "target/rolling.log"); + rollingFile.addAttribute("filePattern", "target/archive/rolling-%d{MM-dd-yy}.log.gz"); + rollingFile.add(layout); + rollingFile.addComponent(triggeringPolicies); + builder.add(rollingFile); + AppenderComponentBuilder file = builder.newAppender("FileSystem", "File"); + file.addAttribute("fileName", "target/logging.log"); + file.add(layout); + builder.add(file); + LoggerComponentBuilder logger = builder.newLogger("com", Level.DEBUG); + logger.add(builder.newAppenderRef("Stdout")); + logger.add(builder.newAppenderRef("rolling")); + logger.add(builder.newAppenderRef("FileSystem")); + logger.addAttribute("additivity", false); + builder.add(logger); + RootLoggerComponentBuilder rootLogger = builder.newRootLogger(Level.ERROR); + rootLogger.add(builder.newAppenderRef("Stdout")); + rootLogger.add(builder.newAppenderRef("rolling")); + rootLogger.add(builder.newAppenderRef("FileSystem")); + rootLogger.addAttribute("additivity", false); + builder.add(rootLogger); + try { + builder.writeXmlConfiguration(System.out); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return builder.build(); + } + + public Configuration getConfiguration(final LoggerContext loggerContext, final String name, final URI configLocation) { + ConfigurationBuilder builder = newConfigurationBuilder(); + return createConfiguration(name, builder); + } + + @Override + protected String[] getSupportedTypes() { + return new String[] { "*" }; + } + + @Override + public Configuration getConfiguration(LoggerContext loggerContext, ConfigurationSource source) { + return getConfiguration(loggerContext, source.toString(), null); + } + +} diff --git a/logging-modules/log4j2-programmatic-configuration/set-configuration-factory/src/test/java/com/baeldung/log4j2/logtest/LogTest.java b/logging-modules/log4j2-programmatic-configuration/set-configuration-factory/src/test/java/com/baeldung/log4j2/logtest/LogTest.java new file mode 100644 index 0000000000..bf78a04dc4 --- /dev/null +++ b/logging-modules/log4j2-programmatic-configuration/set-configuration-factory/src/test/java/com/baeldung/log4j2/logtest/LogTest.java @@ -0,0 +1,33 @@ +/** + This class invokes the configuration factory with static initialization, + as defined in section 4.1 of the "Programmatic Configuration with Log4j 2" +**/ +package com.baeldung.log4j2.logtest; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.Marker; +import org.apache.logging.log4j.MarkerManager; +import org.apache.logging.log4j.core.config.ConfigurationFactory; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +import com.baeldung.log4j2.config.CustomConfigurationFactory; + +@RunWith(JUnit4.class) +public class LogTest { + static { + CustomConfigurationFactory customConfigurationFactory = new CustomConfigurationFactory(); + ConfigurationFactory.setConfigurationFactory(customConfigurationFactory); + } + + @Test + public void simpleProgrammaticConfiguration() { + Logger logger = LogManager.getLogger(); + Marker markerContent = MarkerManager.getMarker("FLOW"); + logger.debug(markerContent, "Debug log message"); + logger.info(markerContent, "Info log message"); + logger.error(markerContent, "Error log message"); + } +} diff --git a/logging-modules/log4j2-programmatic-configuration/simple-configuration-xml/pom.xml b/logging-modules/log4j2-programmatic-configuration/simple-configuration-xml/pom.xml new file mode 100644 index 0000000000..de8c1ff70b --- /dev/null +++ b/logging-modules/log4j2-programmatic-configuration/simple-configuration-xml/pom.xml @@ -0,0 +1,17 @@ + + + 4.0.0 + + com.baeldung.log4j2 + log4j2-programmatic-configuration + 0.0.1-SNAPSHOT + + simple-configuration-xml + simple-configuration-xml + http://maven.apache.org + + UTF-8 + + diff --git a/logging-modules/log4j2-programmatic-configuration/simple-configuration-xml/src/main/resources/log4j2.xml b/logging-modules/log4j2-programmatic-configuration/simple-configuration-xml/src/main/resources/log4j2.xml new file mode 100644 index 0000000000..4c49d85471 --- /dev/null +++ b/logging-modules/log4j2-programmatic-configuration/simple-configuration-xml/src/main/resources/log4j2.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/logging-modules/log4j2-programmatic-configuration/simple-configuration-xml/src/test/java/com/baeldung/log4j2/logtest/LogTest.java b/logging-modules/log4j2-programmatic-configuration/simple-configuration-xml/src/test/java/com/baeldung/log4j2/logtest/LogTest.java new file mode 100644 index 0000000000..f32e0796b6 --- /dev/null +++ b/logging-modules/log4j2-programmatic-configuration/simple-configuration-xml/src/test/java/com/baeldung/log4j2/logtest/LogTest.java @@ -0,0 +1,30 @@ +/** + This class loads the logging configuration from the xml defined in + src/main/resources and uses the same configuration generated through + programmatic configuration as defined in simple-configuration example. +**/ + +package com.baeldung.log4j2.logtest; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.Marker; +import org.apache.logging.log4j.MarkerManager; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + + +@RunWith(JUnit4.class) +public class LogTest { + + @Test + public void simpleProgrammaticConfiguration(){ + Logger logger = LogManager.getLogger(); + Marker markerContent = MarkerManager.getMarker("FLOW"); + logger.debug(markerContent, "Debug log message"); + logger.info(markerContent, "Info log message"); + logger.error(markerContent, "Error log message"); + } + +} diff --git a/logging-modules/log4j2-programmatic-configuration/simple-configuration/pom.xml b/logging-modules/log4j2-programmatic-configuration/simple-configuration/pom.xml new file mode 100644 index 0000000000..0f9e5be3ff --- /dev/null +++ b/logging-modules/log4j2-programmatic-configuration/simple-configuration/pom.xml @@ -0,0 +1,10 @@ + + 4.0.0 + + com.baeldung.log4j2 + log4j2-programmatic-configuration + 0.0.1-SNAPSHOT + + simple-configuration + \ No newline at end of file diff --git a/logging-modules/log4j2-programmatic-configuration/simple-configuration/src/main/java/com/baeldung/log4j2/config/CustomConfigurationFactory.java b/logging-modules/log4j2-programmatic-configuration/simple-configuration/src/main/java/com/baeldung/log4j2/config/CustomConfigurationFactory.java new file mode 100644 index 0000000000..ca3cfa142d --- /dev/null +++ b/logging-modules/log4j2-programmatic-configuration/simple-configuration/src/main/java/com/baeldung/log4j2/config/CustomConfigurationFactory.java @@ -0,0 +1,94 @@ +/** + This class demonstrates how to build the components of + the configuration factory, as described in Section 3 of + "Programmatic Configuration with Log4j 2" +**/ + +package com.baeldung.log4j2.config; + +import java.io.IOException; +import java.net.URI; + +import org.apache.logging.log4j.Level; +import org.apache.logging.log4j.core.Filter; +import org.apache.logging.log4j.core.LoggerContext; +import org.apache.logging.log4j.core.config.Configuration; +import org.apache.logging.log4j.core.config.ConfigurationFactory; +import org.apache.logging.log4j.core.config.ConfigurationSource; +import org.apache.logging.log4j.core.config.Order; +import org.apache.logging.log4j.core.config.builder.api.AppenderComponentBuilder; +import org.apache.logging.log4j.core.config.builder.api.ComponentBuilder; +import org.apache.logging.log4j.core.config.builder.api.ConfigurationBuilder; +import org.apache.logging.log4j.core.config.builder.api.FilterComponentBuilder; +import org.apache.logging.log4j.core.config.builder.api.LayoutComponentBuilder; +import org.apache.logging.log4j.core.config.builder.api.LoggerComponentBuilder; +import org.apache.logging.log4j.core.config.builder.api.RootLoggerComponentBuilder; +import org.apache.logging.log4j.core.config.builder.impl.BuiltConfiguration; +import org.apache.logging.log4j.core.config.plugins.Plugin; + +@Plugin(name = "CustomConfigurationFactory", category = ConfigurationFactory.CATEGORY) +@Order(50) +public class CustomConfigurationFactory extends ConfigurationFactory { + + static Configuration createConfiguration(final String name, ConfigurationBuilder builder) { + AppenderComponentBuilder console = builder.newAppender("Stdout", "Console"); + LayoutComponentBuilder layout = builder.newLayout("PatternLayout") + .addAttribute("pattern", "%d [%t] %-5level: %msg%n%throwable"); + console.add(layout); + FilterComponentBuilder filter = builder.newFilter("MarkerFilter", Filter.Result.ACCEPT, Filter.Result.DENY); + filter.addAttribute("marker", "FLOW"); + console.add(filter); + builder.add(console); + ComponentBuilder triggeringPolicies = builder.newComponent("Policies") + .addComponent(builder.newComponent("CronTriggeringPolicy") + .addAttribute("schedule", "0 0 0 * * ?")) + .addComponent(builder.newComponent("SizeBasedTriggeringPolicy") + .addAttribute("size", "100M")); + AppenderComponentBuilder rollingFile = builder.newAppender("rolling", "RollingFile"); + rollingFile.addAttribute("fileName", "target/rolling.log"); + rollingFile.addAttribute("filePattern", "target/archive/rolling-%d{MM-dd-yy}.log.gz"); + rollingFile.add(layout); + rollingFile.addComponent(triggeringPolicies); + builder.add(rollingFile); + AppenderComponentBuilder file = builder.newAppender("FileSystem", "File"); + file.addAttribute("fileName", "target/logging.log"); + file.add(layout); + builder.add(file); + LoggerComponentBuilder logger = builder.newLogger("com", Level.DEBUG); + logger.add(builder.newAppenderRef("Stdout")); + logger.add(builder.newAppenderRef("rolling")); + logger.add(builder.newAppenderRef("FileSystem")); + logger.addAttribute("additivity", false); + builder.add(logger); + RootLoggerComponentBuilder rootLogger = builder.newRootLogger(Level.ERROR); + rootLogger.add(builder.newAppenderRef("Stdout")); + rootLogger.add(builder.newAppenderRef("rolling")); + // rootLogger.add(builder.newAppenderRef("syslogAppender")); + rootLogger.add(builder.newAppenderRef("FileSystem")); + rootLogger.addAttribute("additivity", false); + builder.add(rootLogger); + try { + builder.writeXmlConfiguration(System.out); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return builder.build(); + + } + + @Override + public Configuration getConfiguration(LoggerContext loggerContext, ConfigurationSource source) { + return getConfiguration(loggerContext, source.toString(), null); + } + + public Configuration getConfiguration(final LoggerContext loggerContext, final String name, final URI configLocation) { + ConfigurationBuilder builder = newConfigurationBuilder(); + return createConfiguration(name, builder); + } + + @Override + protected String[] getSupportedTypes() { + return new String[] { "*" }; + } +} diff --git a/logging-modules/log4j2-programmatic-configuration/simple-configuration/src/test/java/com/baeldung/log4j2/logtest/LogTest.java b/logging-modules/log4j2-programmatic-configuration/simple-configuration/src/test/java/com/baeldung/log4j2/logtest/LogTest.java new file mode 100644 index 0000000000..5637a16508 --- /dev/null +++ b/logging-modules/log4j2-programmatic-configuration/simple-configuration/src/test/java/com/baeldung/log4j2/logtest/LogTest.java @@ -0,0 +1,22 @@ +/** + This class invokes the configuration factory through the run time property, + as defined in section 4.2 of the "Programmatic Configuration with Log4j 2" +**/ +package com.baeldung.log4j2.logtest; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.Marker; +import org.apache.logging.log4j.MarkerManager; +import org.junit.Test; + +public class LogTest { + @Test + public void simpleProgrammaticConfiguration() { + Logger logger = LogManager.getLogger(); + Marker markerContent = MarkerManager.getMarker("FLOW"); + logger.debug(markerContent, "Debug log message"); + logger.info(markerContent, "Info log message"); + logger.error(markerContent, "Error log message"); + } +} diff --git a/logging-modules/log4j2-programmatic-configuration/simple-configurator/pom.xml b/logging-modules/log4j2-programmatic-configuration/simple-configurator/pom.xml new file mode 100644 index 0000000000..4e7350f785 --- /dev/null +++ b/logging-modules/log4j2-programmatic-configuration/simple-configurator/pom.xml @@ -0,0 +1,10 @@ + + 4.0.0 + + com.baeldung.log4j2 + log4j2-programmatic-configuration + 0.0.1-SNAPSHOT + + simple-configurator + \ No newline at end of file diff --git a/logging-modules/log4j2-programmatic-configuration/simple-configurator/src/test/java/com/baeldung/log4j2/configure/LogTest.java b/logging-modules/log4j2-programmatic-configuration/simple-configurator/src/test/java/com/baeldung/log4j2/configure/LogTest.java new file mode 100644 index 0000000000..a5a10426ac --- /dev/null +++ b/logging-modules/log4j2-programmatic-configuration/simple-configurator/src/test/java/com/baeldung/log4j2/configure/LogTest.java @@ -0,0 +1,40 @@ +/** + This class demonstrates how to use ConfigurationBuilderFactory directly, + as described in Section 3 of "Programmatic Configuration with Log4j 2" +**/ + +package com.baeldung.log4j2.configure; + +import org.apache.logging.log4j.Level; +import org.apache.logging.log4j.core.appender.ConsoleAppender; +import org.apache.logging.log4j.core.config.Configurator; +import org.apache.logging.log4j.core.config.builder.api.AppenderComponentBuilder; +import org.apache.logging.log4j.core.config.builder.api.ConfigurationBuilder; +import org.apache.logging.log4j.core.config.builder.api.ConfigurationBuilderFactory; +import org.apache.logging.log4j.core.config.builder.impl.BuiltConfiguration; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +import com.baeldung.log4j2.logtest.LogPrinter; + +@RunWith(JUnit4.class) +public class LogTest { + @Test + public void simpleProgrammaticConfiguration() { + ConfigurationBuilder builder = ConfigurationBuilderFactory.newConfigurationBuilder(); + AppenderComponentBuilder console = builder.newAppender("Stdout", "CONSOLE") + .addAttribute("target", ConsoleAppender.Target.SYSTEM_OUT); + console.add(builder.newLayout("PatternLayout") + .addAttribute("pattern", "%d [%t] %-5level: %msg%n%throwable")); + builder.add(console); + builder.add(builder.newLogger("com", Level.DEBUG) + .add(builder.newAppenderRef("Stdout")) + .addAttribute("additivity", false)); + builder.add(builder.newRootLogger(Level.ERROR) + .add(builder.newAppenderRef("Stdout"))); + Configurator.initialize(builder.build()); + LogPrinter logPrinter = new LogPrinter(); + logPrinter.printlog(); + } +} diff --git a/logging-modules/log4j2-programmatic-configuration/simple-configurator/src/test/java/com/baeldung/log4j2/logtest/LogPrinter.java b/logging-modules/log4j2-programmatic-configuration/simple-configurator/src/test/java/com/baeldung/log4j2/logtest/LogPrinter.java new file mode 100644 index 0000000000..d96808c105 --- /dev/null +++ b/logging-modules/log4j2-programmatic-configuration/simple-configurator/src/test/java/com/baeldung/log4j2/logtest/LogPrinter.java @@ -0,0 +1,15 @@ +package com.baeldung.log4j2.logtest; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + + +public class LogPrinter { + private Logger logger = LogManager.getLogger(); + + public void printlog() { + logger.debug("Debug log message"); + logger.info("Info log message"); + logger.error("Error log message"); + } +} diff --git a/pom.xml b/pom.xml index 5c89660e78..98e7f76e86 100644 --- a/pom.xml +++ b/pom.xml @@ -91,6 +91,7 @@ logging-modules/log-mdc logging-modules/log4j logging-modules/log4j2 + logging-modules/log4j2-programmatic-configuration logging-modules/logback lombok mapstruct From 0b8f6175feec7fa973d05311669f97f8824cf416 Mon Sep 17 00:00:00 2001 From: Ganesh Date: Wed, 2 May 2018 19:39:01 +0530 Subject: [PATCH 19/66] java 10 features (#4147) --- .../java10/Java10FeaturesUnitTest.java | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 core-java-10/src/test/java/com/baeldung/java10/Java10FeaturesUnitTest.java diff --git a/core-java-10/src/test/java/com/baeldung/java10/Java10FeaturesUnitTest.java b/core-java-10/src/test/java/com/baeldung/java10/Java10FeaturesUnitTest.java new file mode 100644 index 0000000000..60e55ef422 --- /dev/null +++ b/core-java-10/src/test/java/com/baeldung/java10/Java10FeaturesUnitTest.java @@ -0,0 +1,61 @@ +package com.baeldung.java10; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +import org.junit.Before; +import org.junit.Test; + +public class Java10FeaturesUnitTest { + + private List someIntList; + + @Before + public void setup() { + someIntList = new ArrayList<>(); + + someIntList.add(1); + someIntList.add(2); + someIntList.add(3); + } + + @Test + public void whenVarInitWithString_thenGetStringTypeVar() { + var message = "Hello, Java 10"; + assertTrue(message instanceof String); + } + + @Test + public void whenVarInitWithAnonymous_thenGetAnonymousType() { + var obj = new Object() {}; + assertFalse(obj.getClass().equals(Object.class)); + } + + @Test(expected = UnsupportedOperationException.class) + public void whenModifyCopyOfList_thenThrowsException() { + List copyList = List.copyOf(someIntList); + copyList.add(4); + } + + @Test(expected = UnsupportedOperationException.class) + public void whenModifyToUnmodifiableList_thenThrowsException() { + List evenList = someIntList.stream() + .filter(i -> i % 2 == 0) + .collect(Collectors.toUnmodifiableList()); + evenList.add(4); + } + + @Test + public void whenListContainsInteger_OrElseThrowReturnsInteger() { + Integer firstEven = someIntList.stream() + .filter(i -> i % 2 == 0) + .findFirst() + .orElseThrow(); + is(firstEven).equals(Integer.valueOf(2)); + } +} From 29d9b564349606f76b6abdecdbb9d26fff969eac Mon Sep 17 00:00:00 2001 From: tinomthomas <38363530+tinomthomas@users.noreply.github.com> Date: Wed, 2 May 2018 18:35:06 +0300 Subject: [PATCH 20/66] BAEL-1749 Spring @Order * A new rest controller has been added to demonstrate the real-time event streaming using Spring WebFlux * delete * Delete WebfluxController.java * BAEL-658 (#4150) * Review changes * BAEL-1749 Test name change --- .../main/java/org/baeldung/order/Average.java | 15 ++++++++ .../java/org/baeldung/order/Excellent.java | 14 +++++++ .../main/java/org/baeldung/order/Good.java | 14 +++++++ .../main/java/org/baeldung/order/Rating.java | 6 +++ .../order/RatingRetrieverUnitTest.java | 37 +++++++++++++++++++ 5 files changed, 86 insertions(+) create mode 100644 spring-all/src/main/java/org/baeldung/order/Average.java create mode 100644 spring-all/src/main/java/org/baeldung/order/Excellent.java create mode 100644 spring-all/src/main/java/org/baeldung/order/Good.java create mode 100644 spring-all/src/main/java/org/baeldung/order/Rating.java create mode 100644 spring-all/src/test/java/org/baeldung/order/RatingRetrieverUnitTest.java diff --git a/spring-all/src/main/java/org/baeldung/order/Average.java b/spring-all/src/main/java/org/baeldung/order/Average.java new file mode 100644 index 0000000000..d1d9117fb1 --- /dev/null +++ b/spring-all/src/main/java/org/baeldung/order/Average.java @@ -0,0 +1,15 @@ +package org.baeldung.order; + +import org.springframework.core.Ordered; +import org.springframework.core.annotation.Order; +import org.springframework.stereotype.Component; + +@Component +@Order(Ordered.LOWEST_PRECEDENCE) +public class Average implements Rating { + + @Override + public int getRating() { + return 3; + } +} diff --git a/spring-all/src/main/java/org/baeldung/order/Excellent.java b/spring-all/src/main/java/org/baeldung/order/Excellent.java new file mode 100644 index 0000000000..e5f125593f --- /dev/null +++ b/spring-all/src/main/java/org/baeldung/order/Excellent.java @@ -0,0 +1,14 @@ +package org.baeldung.order; + +import org.springframework.stereotype.Component; +import org.springframework.core.annotation.Order; + +@Component +@Order(1) +public class Excellent implements Rating { + + @Override + public int getRating() { + return 1; + } +} diff --git a/spring-all/src/main/java/org/baeldung/order/Good.java b/spring-all/src/main/java/org/baeldung/order/Good.java new file mode 100644 index 0000000000..3dd9852cc4 --- /dev/null +++ b/spring-all/src/main/java/org/baeldung/order/Good.java @@ -0,0 +1,14 @@ +package org.baeldung.order; + +import org.springframework.core.annotation.Order; +import org.springframework.stereotype.Component; + +@Component +@Order(2) +public class Good implements Rating { + + @Override + public int getRating() { + return 2; + } +} diff --git a/spring-all/src/main/java/org/baeldung/order/Rating.java b/spring-all/src/main/java/org/baeldung/order/Rating.java new file mode 100644 index 0000000000..dd0391a3d9 --- /dev/null +++ b/spring-all/src/main/java/org/baeldung/order/Rating.java @@ -0,0 +1,6 @@ +package org.baeldung.order; + +public interface Rating { + + int getRating(); +} diff --git a/spring-all/src/test/java/org/baeldung/order/RatingRetrieverUnitTest.java b/spring-all/src/test/java/org/baeldung/order/RatingRetrieverUnitTest.java new file mode 100644 index 0000000000..a624f757fc --- /dev/null +++ b/spring-all/src/test/java/org/baeldung/order/RatingRetrieverUnitTest.java @@ -0,0 +1,37 @@ +package org.baeldung.order; + + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +import java.util.List; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.support.AnnotationConfigContextLoader; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(loader = AnnotationConfigContextLoader.class) +public class RatingRetrieverUnitTest { + + @Configuration + @ComponentScan(basePackages = {"org.baeldung.order"}) + static class ContextConfiguration {} + + @Autowired + private List ratings; + + @Test + public void givenOrderOnComponents_whenInjected_thenAutowireByOrderValue() { + assertThat(ratings.get(0).getRating(), is(equalTo(1))); + assertThat(ratings.get(1).getRating(), is(equalTo(2))); + assertThat(ratings.get(2).getRating(), is(equalTo(3))); + } + +} From 9a496e0d258c8d125ee6b62da8bdc69fbe75eab4 Mon Sep 17 00:00:00 2001 From: mherbaghinyan Date: Thu, 3 May 2018 12:13:12 +0400 Subject: [PATCH 21/66] Composite design pattern --- .../composite/CompositeDemo.java | 11 ++++++ .../designpatterns/composite/Department.java | 9 +++++ .../composite/FinancialDepartment.java | 35 +++++++++++++++++++ .../composite/GeneralDepartment.java | 33 +++++++++++++++++ .../composite/SalesDepartment.java | 35 +++++++++++++++++++ 5 files changed, 123 insertions(+) create mode 100644 core-java/src/main/java/com/baeldung/designpatterns/composite/CompositeDemo.java create mode 100644 core-java/src/main/java/com/baeldung/designpatterns/composite/Department.java create mode 100644 core-java/src/main/java/com/baeldung/designpatterns/composite/FinancialDepartment.java create mode 100644 core-java/src/main/java/com/baeldung/designpatterns/composite/GeneralDepartment.java create mode 100644 core-java/src/main/java/com/baeldung/designpatterns/composite/SalesDepartment.java diff --git a/core-java/src/main/java/com/baeldung/designpatterns/composite/CompositeDemo.java b/core-java/src/main/java/com/baeldung/designpatterns/composite/CompositeDemo.java new file mode 100644 index 0000000000..83024b7d21 --- /dev/null +++ b/core-java/src/main/java/com/baeldung/designpatterns/composite/CompositeDemo.java @@ -0,0 +1,11 @@ +package com.baeldung.designpatterns.composite; + +/** + * Created by Gebruiker on 5/3/2018. + */ +public class CompositeDemo { + + public static void main(String args[]) { + Department salesDepartment = new SalesDepartment(); + } +} diff --git a/core-java/src/main/java/com/baeldung/designpatterns/composite/Department.java b/core-java/src/main/java/com/baeldung/designpatterns/composite/Department.java new file mode 100644 index 0000000000..82fa3a3efc --- /dev/null +++ b/core-java/src/main/java/com/baeldung/designpatterns/composite/Department.java @@ -0,0 +1,9 @@ +package com.baeldung.designpatterns.composite; + +/** + * Created by Gebruiker on 5/1/2018. + */ +public interface Department { + + void printDepartmentName(); +} diff --git a/core-java/src/main/java/com/baeldung/designpatterns/composite/FinancialDepartment.java b/core-java/src/main/java/com/baeldung/designpatterns/composite/FinancialDepartment.java new file mode 100644 index 0000000000..dc5a2bb9d9 --- /dev/null +++ b/core-java/src/main/java/com/baeldung/designpatterns/composite/FinancialDepartment.java @@ -0,0 +1,35 @@ +package com.baeldung.designpatterns.composite; + +/** + * Created by Gebruiker on 5/1/2018. + */ +public class FinancialDepartment implements Department { + + private Integer id; + private String name; + + public FinancialDepartment(Integer id, String name) { + this.id = id; + this.name = name; + } + + public void printDepartmentName() { + System.out.println(getClass().getSimpleName()); + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} diff --git a/core-java/src/main/java/com/baeldung/designpatterns/composite/GeneralDepartment.java b/core-java/src/main/java/com/baeldung/designpatterns/composite/GeneralDepartment.java new file mode 100644 index 0000000000..15c5bc9494 --- /dev/null +++ b/core-java/src/main/java/com/baeldung/designpatterns/composite/GeneralDepartment.java @@ -0,0 +1,33 @@ +package com.baeldung.designpatterns.composite; + +import java.util.ArrayList; +import java.util.List; + +/** + * Created by Gebruiker on 5/1/2018. + */ +public class GeneralDepartment implements Department { + + private Integer id; + private String name; + + private List childDepartments; + + public GeneralDepartment(Integer id, String name) { + this.id = id; + this.name = name; + this.childDepartments = new ArrayList(); + } + + public void printDepartmentName() { + childDepartments.stream().forEach(Department::printDepartmentName); + } + + public void addDepartMent(Department department) { + childDepartments.add(department); + } + + public void removeDepartment(Department department) { + childDepartments.remove(department); + } +} diff --git a/core-java/src/main/java/com/baeldung/designpatterns/composite/SalesDepartment.java b/core-java/src/main/java/com/baeldung/designpatterns/composite/SalesDepartment.java new file mode 100644 index 0000000000..af234b4915 --- /dev/null +++ b/core-java/src/main/java/com/baeldung/designpatterns/composite/SalesDepartment.java @@ -0,0 +1,35 @@ +package com.baeldung.designpatterns.composite; + +/** + * Created by Gebruiker on 5/1/2018. + */ +public class SalesDepartment implements Department { + + private Integer id; + private String name; + + public SalesDepartment(Integer id, String name) { + this.id = id; + this.name = name; + } + + public void printDepartmentName() { + System.out.println(getClass().getSimpleName()); + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} From f00a66af6962063cc75a74c347166c7c52d70b9f Mon Sep 17 00:00:00 2001 From: Rokon Uddin Ahmed Date: Thu, 3 May 2018 19:44:44 +0600 Subject: [PATCH 22/66] 03.05.2018 (#4161) * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.MD * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md --- README.md | 5 +++++ algorithms/README.md | 3 ++- asciidoctor/README.md | 1 + aws/README.md | 2 ++ core-java-8/README.md | 4 ++++ core-java/README.md | 6 ++++++ hibernate5/README.md | 1 + jsf/README.md | 1 + libraries/README.md | 2 ++ persistence-modules/spring-jpa/README.md | 1 + spring-5-reactive/README.md | 1 + spring-5/README.md | 1 + spring-boot-admin/README.md | 7 ++++++- spring-hibernate4/README.md | 1 + spring-remoting/README.md | 1 + spring-security-rest/README.md | 1 + spring-security-thymeleaf/README.MD | 6 +++++- testing-modules/mockito/README.md | 4 ++-- vraptor/README.md | 5 +++++ 19 files changed, 48 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 8ff04d8fc5..62d2d5b55e 100644 --- a/README.md +++ b/README.md @@ -34,3 +34,8 @@ CI - Jenkins ================================ This tutorials project is being built **[>> HERE](https://rest-security.ci.cloudbees.com/job/tutorials-unit/)** +### Relevant Articles: +================================ + +- [Apache Maven Standard Directory Layout](http://www.baeldung.com/maven-directory-structure) +- [Apache Maven Tutorial](http://www.baeldung.com/maven) diff --git a/algorithms/README.md b/algorithms/README.md index b3e11de6c5..50cdfbbd4f 100644 --- a/algorithms/README.md +++ b/algorithms/README.md @@ -20,4 +20,5 @@ - [A Maze Solver in Java](http://www.baeldung.com/java-solve-maze) - [Create a Sudoku Solver in Java](http://www.baeldung.com/java-sudoku) - [Displaying Money Amounts in Words](http://www.baeldung.com/java-money-into-words) -- [A Collaborative Filtering Recommendation System in Java](http://www.baeldung.com/java-collaborative-filtering-recommendations) \ No newline at end of file +- [A Collaborative Filtering Recommendation System in Java](http://www.baeldung.com/java-collaborative-filtering-recommendations) +- [Find All Pairs of Numbers in an Array That Add Up to a Given Sum](http://www.baeldung.com/java-algorithm-number-pairs-sum) diff --git a/asciidoctor/README.md b/asciidoctor/README.md index 3c602b6abd..aafd0bca17 100644 --- a/asciidoctor/README.md +++ b/asciidoctor/README.md @@ -2,3 +2,4 @@ - [Introduction to Asciidoctor](http://www.baeldung.com/introduction-to-asciidoctor) - [Generating a Book with Asciidoctor](http://www.baeldung.com/asciidoctor-book) +- [Introduction to Asciidoctor in Java](http://www.baeldung.com/asciidoctor) diff --git a/aws/README.md b/aws/README.md index 95de3c8464..5737222c93 100644 --- a/aws/README.md +++ b/aws/README.md @@ -8,4 +8,6 @@ - [Multipart Uploads in Amazon S3 with Java](http://www.baeldung.com/aws-s3-multipart-upload) - [Integration Testing with a Local DynamoDB Instance](http://www.baeldung.com/dynamodb-local-integration-tests) - [Using the JetS3t Java Client With Amazon S3](http://www.baeldung.com/jets3t-amazon-s3) +- [Iteration in Thymeleaf](http://www.baeldung.com/thymeleaf-iteration) +- [Working with Boolean in Thymeleaf](http://www.baeldung.com/thymeleaf-boolean) diff --git a/core-java-8/README.md b/core-java-8/README.md index f3287651e1..f0d7818f5b 100644 --- a/core-java-8/README.md +++ b/core-java-8/README.md @@ -47,3 +47,7 @@ - [Overview of Java Built-in Annotations](http://www.baeldung.com/java-default-annotations) - [Finding Min/Max in an Array with Java](http://www.baeldung.com/java-array-min-max) - [Internationalization and Localization in Java 8](http://www.baeldung.com/java-8-localization) +- [Filtering Kotlin Collections](http://www.baeldung.com/kotlin-filter-collection) +- [How to Find an Element in a List with Java](http://www.baeldung.com/find-list-element-java) +- [Measure Elapsed Time in Java](http://www.baeldung.com/java-measure-elapsed-time) + diff --git a/core-java/README.md b/core-java/README.md index 14bd26e821..8a94c9de8e 100644 --- a/core-java/README.md +++ b/core-java/README.md @@ -140,3 +140,9 @@ - [Type Erasure in Java Explained](http://www.baeldung.com/java-type-erasure) - [BigDecimal and BigInteger in Java](http://www.baeldung.com/java-bigdecimal-biginteger) - [Display All Time Zones With GMT And UTC in Java](http://www.baeldung.com/java-time-zones) +- [Join and Split Arrays and Collections in Java](http://www.baeldung.com/java-join-and-split) +- [Check If Two Lists are Equal in Java](http://www.baeldung.com/java-test-a-list-for-ordinality-and-equality) +- [Sending Emails with Java](http://www.baeldung.com/java-email) +- [Introduction to SSL in Java](http://www.baeldung.com/java-ssl) +- [Java KeyStore API](http://www.baeldung.com/java-keystore) +- [Double-Checked Locking with Singleton](http://www.baeldung.com/java-singleton-double-checked-locking) diff --git a/hibernate5/README.md b/hibernate5/README.md index 4b7912056a..fb1319ed57 100644 --- a/hibernate5/README.md +++ b/hibernate5/README.md @@ -9,3 +9,4 @@ - [Hibernate Interceptors](http://www.baeldung.com/hibernate-interceptor) - [JPA Attribute Converters](http://www.baeldung.com/jpa-attribute-converters) - [Mapping LOB Data in Hibernate](http://www.baeldung.com/hibernate-lob) +- [@Immutable in Hibernate](http://www.baeldung.com/hibernate-immutable) diff --git a/jsf/README.md b/jsf/README.md index ae92ffc42f..6e0891182d 100644 --- a/jsf/README.md +++ b/jsf/README.md @@ -2,3 +2,4 @@ - [Introduction to JSF Expression Language 3.0](http://www.baeldung.com/jsf-expression-language-el-3) - [Introduction to JSF EL 2](http://www.baeldung.com/intro-to-jsf-expression-language) - [JavaServer Faces (JSF) with Spring](http://www.baeldung.com/spring-jsf) +- [Introduction to Primefaces](http://www.baeldung.com/jsf-primefaces) diff --git a/libraries/README.md b/libraries/README.md index bf8c075663..0080c2ad39 100644 --- a/libraries/README.md +++ b/libraries/README.md @@ -82,6 +82,8 @@ - [Publish and Receive Messages with Nats Java Client](http://www.baeldung.com/nats-java-client) - [Java Concurrency Utility with JCTools](http://www.baeldung.com/java-concurrency-jc-tools) - [Apache Commons Collections MapUtils](http://www.baeldung.com/apache-commons-map-utils) +- [Testing Netty with EmbeddedChannel](http://www.baeldung.com/testing-netty-embedded-channel) + 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. diff --git a/persistence-modules/spring-jpa/README.md b/persistence-modules/spring-jpa/README.md index 6a7153b524..2a717417d7 100644 --- a/persistence-modules/spring-jpa/README.md +++ b/persistence-modules/spring-jpa/README.md @@ -20,6 +20,7 @@ - [A Guide to Hibernate with Spring 4](http://www.baeldung.com/the-persistence-layer-with-spring-and-jpa) - [Testing REST with multiple MIME types](http://www.baeldung.com/testing-rest-api-with-multiple-media-types) - [Obtaining Auto-generated Keys in Spring JDBC](http://www.baeldung.com/spring-jdbc-autogenerated-keys) +- [Transactions with Spring 4 and JPA](http://www.baeldung.com/transaction-configuration-with-jpa-and-spring) ### Eclipse Config After importing the project into Eclipse, you may see the following error: diff --git a/spring-5-reactive/README.md b/spring-5-reactive/README.md index 7c078a8f92..9998dbf751 100644 --- a/spring-5-reactive/README.md +++ b/spring-5-reactive/README.md @@ -16,3 +16,4 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [Reactive WebSockets with Spring 5](http://www.baeldung.com/spring-5-reactive-websockets) - [Spring Boot Actuator](http://www.baeldung.com/spring-boot-actuators) - [Spring Webflux Filters](http://www.baeldung.com/spring-webflux-filters) +- [Reactive Flow with MongoDB, Kotlin, and Spring WebFlux](http://www.baeldung.com/kotlin-mongodb-spring-webflux) diff --git a/spring-5/README.md b/spring-5/README.md index d37927cfc7..de42d965f5 100644 --- a/spring-5/README.md +++ b/spring-5/README.md @@ -16,3 +16,4 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [Introduction to Spring REST Docs](http://www.baeldung.com/spring-rest-docs) - [Spring Security 5 – OAuth2 Login](http://www.baeldung.com/spring-security-5-oauth2-login) - [Spring ResponseStatusException](http://www.baeldung.com/spring-response-status-exception) +- [Spring Assert Statements](http://www.baeldung.com/spring-assert) diff --git a/spring-boot-admin/README.md b/spring-boot-admin/README.md index 622533a6ad..73ce857059 100644 --- a/spring-boot-admin/README.md +++ b/spring-boot-admin/README.md @@ -14,4 +14,9 @@ and the mail configuration from application.properties * mvn clean install * mvn spring-boot:run * starts on port 8081 -* basic auth client/client \ No newline at end of file +* basic auth client/client + + +### Relevant Articles: + +- [A Guide to Spring Boot Admin](http://www.baeldung.com/spring-boot-admin) diff --git a/spring-hibernate4/README.md b/spring-hibernate4/README.md index 4284a253cc..2165fb67bc 100644 --- a/spring-hibernate4/README.md +++ b/spring-hibernate4/README.md @@ -14,6 +14,7 @@ - [Hibernate Criteria Queries](http://www.baeldung.com/hibernate-criteria-queries) - [Hibernate One to Many Annotation Tutorial](http://www.baeldung.com/hibernate-one-to-many) - [Guide to @Immutable Annotation in Hibernate](http://www.baeldung.com/hibernate-immutable) +- [The DAO with Spring and Hibernate](http://www.baeldung.com/persistence-layer-with-spring-and-hibernate) ### Quick Start diff --git a/spring-remoting/README.md b/spring-remoting/README.md index da8238b034..7d344a3f27 100644 --- a/spring-remoting/README.md +++ b/spring-remoting/README.md @@ -5,6 +5,7 @@ - [Spring Remoting with Hessian and Burlap](http://www.baeldung.com/spring-remoting-hessian-burlap) - [Spring Remoting with AMQP](http://www.baeldung.com/spring-remoting-amqp) - [Spring Remoting with JMS](http://www.baeldung.com/spring-remoting-jms) +- [Spring Remoting with RMI](http://www.baeldung.com/spring-remoting-rmi) ### Overview This Maven project contains the Java source code for various modules used in the Spring Remoting series of articles. diff --git a/spring-security-rest/README.md b/spring-security-rest/README.md index 5898ba248e..d9b6a760b2 100644 --- a/spring-security-rest/README.md +++ b/spring-security-rest/README.md @@ -17,3 +17,4 @@ The "Learn Spring Security" Classes: http://github.learnspringsecurity.com - [Intro to Spring Security Expressions](http://www.baeldung.com/spring-security-expressions) - [Spring Security Expressions - hasRole Example](http://www.baeldung.com/spring-security-expressions-basic) - [Error Handling for REST with Spring 3](http://www.baeldung.com/2013/01/31/exception-handling-for-rest-with-spring-3-2/) +- [Spring Security for a REST API](http://www.baeldung.com/securing-a-restful-web-service-with-spring-security) diff --git a/spring-security-thymeleaf/README.MD b/spring-security-thymeleaf/README.MD index 44d118f8a8..36007bce62 100644 --- a/spring-security-thymeleaf/README.MD +++ b/spring-security-thymeleaf/README.MD @@ -1,2 +1,6 @@ This module is for Spring Security Thymeleaf tutorial. -Jira BAEL-1556 \ No newline at end of file +Jira BAEL-1556 + +### Relevant Articles: + +- [Spring Security with Thymeleaf](http://www.baeldung.com/spring-security-thymeleaf) diff --git a/testing-modules/mockito/README.md b/testing-modules/mockito/README.md index 72c769ce4f..5a8d2289a4 100644 --- a/testing-modules/mockito/README.md +++ b/testing-modules/mockito/README.md @@ -14,6 +14,6 @@ - [Mocking Void Methods with Mockito](http://www.baeldung.com/mockito-void-methods) - [Mocking of Private Methods Using PowerMock](http://www.baeldung.com/powermock-private-method) - [Mock Final Classes and Methods with Mockito](http://www.baeldung.com/mockito-final) -- [Hamcrest Text Matchers] (http://www.baeldung.com/hamcrest-text-matchers) -- [Hamcrest File Matchers] (http://www.baeldung.com/hamcrest-file-matchers) +- [Hamcrest Text Matchers](http://www.baeldung.com/hamcrest-text-matchers) +- [Hamcrest File Matchers](http://www.baeldung.com/hamcrest-file-matchers) - [Hamcrest Custom Matchers](http://www.baeldung.com/hamcrest-custom-matchers) diff --git a/vraptor/README.md b/vraptor/README.md index d547fc1274..0dc531ba8d 100644 --- a/vraptor/README.md +++ b/vraptor/README.md @@ -11,3 +11,8 @@ mvn tomcat7:run ``` Cuidado para *jamais* executar `mvn tomcat:run` pois ele usará um tomcat6 (incompatível). + + +### Relevant Article: + +- [Introduction to VRaptor in Java](http://www.baeldung.com/vraptor) From 997c2a4ddfa3acae69e0d04f0248db8adf691b54 Mon Sep 17 00:00:00 2001 From: Tom Hombergs Date: Thu, 3 May 2018 15:45:16 +0200 Subject: [PATCH 23/66] added article link (#4093) --- core-java/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java/README.md b/core-java/README.md index 8a94c9de8e..8b20eebf57 100644 --- a/core-java/README.md +++ b/core-java/README.md @@ -125,6 +125,7 @@ - [An Advanced Tagging Implementation with JPA](http://www.baeldung.com/jpa-tagging-advanced) - [Handling Daylight Savings Time in Java](http://www.baeldung.com/java-daylight-savings) - [Inheritance and Composition (Is-a vs Has-a relationship) in Java](http://www.baeldung.com/java-inheritance-composition) +- [Double-Checked Locking with Singleton](http://www.baeldung.com/java-singleton-double-checked-locking) - [Finding Max/Min of a List or Collection](http://www.baeldung.com/java-collection-min-max) - [The "final" Keyword in Java](http://www.baeldung.com/java-final) - [What is the serialVersionUID?](http://www.baeldung.com/java-serial-version-uid) From ef481d19ee865911ed5ec5c9423c79d9242e4631 Mon Sep 17 00:00:00 2001 From: Erdem Date: Thu, 3 May 2018 22:02:16 +0300 Subject: [PATCH 24/66] BAEL-1746 added property editor implementation --- .../baeldung/propertyeditor/CreditCard.java | 41 +++++++++++++++++++ .../propertyeditor/CreditCardEditor.java | 39 ++++++++++++++++++ .../CreditCardRestController.java | 17 ++++++++ .../PropertyEditorApplication.java | 12 ++++++ .../propertyeditor/CreditCardEditorTest.java | 41 +++++++++++++++++++ 5 files changed, 150 insertions(+) create mode 100644 spring-rest/src/main/java/com/baeldung/propertyeditor/CreditCard.java create mode 100644 spring-rest/src/main/java/com/baeldung/propertyeditor/CreditCardEditor.java create mode 100644 spring-rest/src/main/java/com/baeldung/propertyeditor/CreditCardRestController.java create mode 100644 spring-rest/src/main/java/com/baeldung/propertyeditor/PropertyEditorApplication.java create mode 100644 spring-rest/src/test/java/com/baeldung/propertyeditor/CreditCardEditorTest.java diff --git a/spring-rest/src/main/java/com/baeldung/propertyeditor/CreditCard.java b/spring-rest/src/main/java/com/baeldung/propertyeditor/CreditCard.java new file mode 100644 index 0000000000..2b1fbb9b6c --- /dev/null +++ b/spring-rest/src/main/java/com/baeldung/propertyeditor/CreditCard.java @@ -0,0 +1,41 @@ +package com.baeldung.propertyeditor; + +public class CreditCard { + + private String rawCardNumber; + + private Integer bankIdNo; + + private Integer accountNo; + + private Integer checkCode; + + public String getRawCardNumber() { + return rawCardNumber; + } + public void setRawCardNumber(String rawCardNumber) { + this.rawCardNumber = rawCardNumber; + } + + public Integer getBankIdNo() { + return bankIdNo; + } + public void setBankIdNo(Integer bankIdNo) { + this.bankIdNo = bankIdNo; + } + + public Integer getAccountNo() { + return accountNo; + } + public void setAccountNo(Integer accountNo) { + this.accountNo = accountNo; + } + + public Integer getCheckCode() { + return checkCode; + } + public void setCheckCode(Integer checkCode) { + this.checkCode = checkCode; + } + +} diff --git a/spring-rest/src/main/java/com/baeldung/propertyeditor/CreditCardEditor.java b/spring-rest/src/main/java/com/baeldung/propertyeditor/CreditCardEditor.java new file mode 100644 index 0000000000..4b1374a76a --- /dev/null +++ b/spring-rest/src/main/java/com/baeldung/propertyeditor/CreditCardEditor.java @@ -0,0 +1,39 @@ +package com.baeldung.propertyeditor; + +import java.beans.PropertyEditorSupport; + +import org.springframework.util.StringUtils; + +public class CreditCardEditor extends PropertyEditorSupport { + + @Override + public String getAsText() { + CreditCard creditCard = (CreditCard) getValue(); + + return creditCard == null ? "" : creditCard.getRawCardNumber(); + } + + @Override + public void setAsText(String text) throws IllegalArgumentException { + if (StringUtils.isEmpty(text)) { + setValue(null); + } else { + CreditCard creditCard = new CreditCard(); + creditCard.setRawCardNumber(text); + + String cardNo = text.replaceAll("-", ""); + if (cardNo.length() != 16) + throw new IllegalArgumentException("Credit card format should be xxxx-xxxx-xxxx-xxxx"); + + try { + creditCard.setBankIdNo( Integer.valueOf(cardNo.substring(0, 6)) ); + creditCard.setAccountNo( Integer.valueOf(cardNo.substring(6, cardNo.length() - 1)) ); + creditCard.setCheckCode( Integer.valueOf(cardNo.substring(cardNo.length() - 1)) ); + } catch (NumberFormatException nfe) { + throw new IllegalArgumentException(nfe); + } + + setValue(creditCard); + } + } +} diff --git a/spring-rest/src/main/java/com/baeldung/propertyeditor/CreditCardRestController.java b/spring-rest/src/main/java/com/baeldung/propertyeditor/CreditCardRestController.java new file mode 100644 index 0000000000..bf8e0586f8 --- /dev/null +++ b/spring-rest/src/main/java/com/baeldung/propertyeditor/CreditCardRestController.java @@ -0,0 +1,17 @@ +package com.baeldung.propertyeditor; + +import org.springframework.http.MediaType; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping(value = "/credit-card") +public class CreditCardRestController { + + @GetMapping(value = "/parse/{card-no}", produces = MediaType.APPLICATION_JSON_UTF8_VALUE) + public CreditCard parseCreditCardNumber(@PathVariable("card-no") CreditCard creditCard) { + return creditCard; + } +} diff --git a/spring-rest/src/main/java/com/baeldung/propertyeditor/PropertyEditorApplication.java b/spring-rest/src/main/java/com/baeldung/propertyeditor/PropertyEditorApplication.java new file mode 100644 index 0000000000..b0d75cd072 --- /dev/null +++ b/spring-rest/src/main/java/com/baeldung/propertyeditor/PropertyEditorApplication.java @@ -0,0 +1,12 @@ +package com.baeldung.propertyeditor; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class PropertyEditorApplication { + + public static void main(String[] args) { + SpringApplication.run(PropertyEditorApplication.class, args); + } +} diff --git a/spring-rest/src/test/java/com/baeldung/propertyeditor/CreditCardEditorTest.java b/spring-rest/src/test/java/com/baeldung/propertyeditor/CreditCardEditorTest.java new file mode 100644 index 0000000000..b7da905f13 --- /dev/null +++ b/spring-rest/src/test/java/com/baeldung/propertyeditor/CreditCardEditorTest.java @@ -0,0 +1,41 @@ +package com.baeldung.propertyeditor; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.runners.MockitoJUnitRunner; + +@RunWith(MockitoJUnitRunner.class) +public class CreditCardEditorTest { + + private CreditCardEditor creditCardEditor; + + @Before + public void setup() { + creditCardEditor = new CreditCardEditor(); + } + + @Test(expected=IllegalArgumentException.class) + public void whenInvalidCardNoWithLessDigits_thenThrowsException() { + creditCardEditor.setAsText("123-123-123-123"); + } + + @Test(expected=IllegalArgumentException.class) + public void whenInvalidCardNoWithNonDigits_thenThrowsException() { + creditCardEditor.setAsText("1234-1234-xxxx-yyyy"); + } + + @Test + public void whenCardNoWithNonDigits_parseCreditCard() { + creditCardEditor.setAsText("1234-5678-9123-4560"); + + CreditCard creditCard = (CreditCard) creditCardEditor.getValue(); + Assert.assertNotNull(creditCard); + + Assert.assertEquals(123456, creditCard.getBankIdNo().intValue()); + Assert.assertEquals(789123456, creditCard.getAccountNo().intValue()); + Assert.assertEquals(0, creditCard.getCheckCode().intValue()); + } + +} From 043f6bade7aea7004907e2495b945b23dd7c9381 Mon Sep 17 00:00:00 2001 From: Erdem Date: Thu, 3 May 2018 23:27:12 +0300 Subject: [PATCH 25/66] BAEL-1746 added custom property editor implementation --- .../CreditCardRestController.java | 17 ---------- .../PropertyEditorApplication.java | 6 ++-- .../PropertyEditorRestController.java | 34 +++++++++++++++++++ .../{ => creditcard}/CreditCard.java | 2 +- .../{ => creditcard}/CreditCardEditor.java | 2 +- .../editor/CustomExoticTypeEditor.java | 23 +++++++++++++ .../exotictype/model/ExoticType.java | 14 ++++++++ .../src/main/resources/application.properties | 2 +- .../CreditCardEditorTest.java | 5 ++- 9 files changed, 81 insertions(+), 24 deletions(-) delete mode 100644 spring-rest/src/main/java/com/baeldung/propertyeditor/CreditCardRestController.java create mode 100644 spring-rest/src/main/java/com/baeldung/propertyeditor/PropertyEditorRestController.java rename spring-rest/src/main/java/com/baeldung/propertyeditor/{ => creditcard}/CreditCard.java (94%) rename spring-rest/src/main/java/com/baeldung/propertyeditor/{ => creditcard}/CreditCardEditor.java (96%) create mode 100644 spring-rest/src/main/java/com/baeldung/propertyeditor/exotictype/editor/CustomExoticTypeEditor.java create mode 100644 spring-rest/src/main/java/com/baeldung/propertyeditor/exotictype/model/ExoticType.java rename spring-rest/src/test/java/com/baeldung/propertyeditor/{ => creditcard}/CreditCardEditorTest.java (88%) diff --git a/spring-rest/src/main/java/com/baeldung/propertyeditor/CreditCardRestController.java b/spring-rest/src/main/java/com/baeldung/propertyeditor/CreditCardRestController.java deleted file mode 100644 index bf8e0586f8..0000000000 --- a/spring-rest/src/main/java/com/baeldung/propertyeditor/CreditCardRestController.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.baeldung.propertyeditor; - -import org.springframework.http.MediaType; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -@RestController -@RequestMapping(value = "/credit-card") -public class CreditCardRestController { - - @GetMapping(value = "/parse/{card-no}", produces = MediaType.APPLICATION_JSON_UTF8_VALUE) - public CreditCard parseCreditCardNumber(@PathVariable("card-no") CreditCard creditCard) { - return creditCard; - } -} diff --git a/spring-rest/src/main/java/com/baeldung/propertyeditor/PropertyEditorApplication.java b/spring-rest/src/main/java/com/baeldung/propertyeditor/PropertyEditorApplication.java index b0d75cd072..f98648c6b2 100644 --- a/spring-rest/src/main/java/com/baeldung/propertyeditor/PropertyEditorApplication.java +++ b/spring-rest/src/main/java/com/baeldung/propertyeditor/PropertyEditorApplication.java @@ -6,7 +6,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class PropertyEditorApplication { - public static void main(String[] args) { - SpringApplication.run(PropertyEditorApplication.class, args); - } + public static void main(String[] args) { + SpringApplication.run(PropertyEditorApplication.class, args); + } } diff --git a/spring-rest/src/main/java/com/baeldung/propertyeditor/PropertyEditorRestController.java b/spring-rest/src/main/java/com/baeldung/propertyeditor/PropertyEditorRestController.java new file mode 100644 index 0000000000..24f1b33471 --- /dev/null +++ b/spring-rest/src/main/java/com/baeldung/propertyeditor/PropertyEditorRestController.java @@ -0,0 +1,34 @@ +package com.baeldung.propertyeditor; + +import org.springframework.http.MediaType; +import org.springframework.web.bind.WebDataBinder; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.InitBinder; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import com.baeldung.propertyeditor.creditcard.CreditCard; +import com.baeldung.propertyeditor.exotictype.editor.CustomExoticTypeEditor; +import com.baeldung.propertyeditor.exotictype.model.ExoticType; + +@RestController +@RequestMapping(value = "/property-editor") +public class PropertyEditorRestController { + + @GetMapping(value = "/credit-card/{card-no}", produces = MediaType.APPLICATION_JSON_UTF8_VALUE) + public CreditCard parseCreditCardNumber(@PathVariable("card-no") CreditCard creditCard) { + return creditCard; + } + + @GetMapping(value = "/exotic-type/{value}", produces = MediaType.APPLICATION_JSON_UTF8_VALUE) + public ExoticType parseCreditCardNumber(@PathVariable("value") ExoticType exoticType) { + return exoticType; + } + + @InitBinder + public void initBinder(WebDataBinder binder) { + binder.registerCustomEditor(ExoticType.class, new CustomExoticTypeEditor()); + } + +} diff --git a/spring-rest/src/main/java/com/baeldung/propertyeditor/CreditCard.java b/spring-rest/src/main/java/com/baeldung/propertyeditor/creditcard/CreditCard.java similarity index 94% rename from spring-rest/src/main/java/com/baeldung/propertyeditor/CreditCard.java rename to spring-rest/src/main/java/com/baeldung/propertyeditor/creditcard/CreditCard.java index 2b1fbb9b6c..f3adfb5d9f 100644 --- a/spring-rest/src/main/java/com/baeldung/propertyeditor/CreditCard.java +++ b/spring-rest/src/main/java/com/baeldung/propertyeditor/creditcard/CreditCard.java @@ -1,4 +1,4 @@ -package com.baeldung.propertyeditor; +package com.baeldung.propertyeditor.creditcard; public class CreditCard { diff --git a/spring-rest/src/main/java/com/baeldung/propertyeditor/CreditCardEditor.java b/spring-rest/src/main/java/com/baeldung/propertyeditor/creditcard/CreditCardEditor.java similarity index 96% rename from spring-rest/src/main/java/com/baeldung/propertyeditor/CreditCardEditor.java rename to spring-rest/src/main/java/com/baeldung/propertyeditor/creditcard/CreditCardEditor.java index 4b1374a76a..d413afee85 100644 --- a/spring-rest/src/main/java/com/baeldung/propertyeditor/CreditCardEditor.java +++ b/spring-rest/src/main/java/com/baeldung/propertyeditor/creditcard/CreditCardEditor.java @@ -1,4 +1,4 @@ -package com.baeldung.propertyeditor; +package com.baeldung.propertyeditor.creditcard; import java.beans.PropertyEditorSupport; diff --git a/spring-rest/src/main/java/com/baeldung/propertyeditor/exotictype/editor/CustomExoticTypeEditor.java b/spring-rest/src/main/java/com/baeldung/propertyeditor/exotictype/editor/CustomExoticTypeEditor.java new file mode 100644 index 0000000000..08dbceae3d --- /dev/null +++ b/spring-rest/src/main/java/com/baeldung/propertyeditor/exotictype/editor/CustomExoticTypeEditor.java @@ -0,0 +1,23 @@ +package com.baeldung.propertyeditor.exotictype.editor; + +import java.beans.PropertyEditorSupport; + +import com.baeldung.propertyeditor.exotictype.model.ExoticType; + +public class CustomExoticTypeEditor extends PropertyEditorSupport { + + @Override + public String getAsText() { + ExoticType exoticType = (ExoticType) getValue(); + + return exoticType == null ? "" : exoticType.getName(); + } + + @Override + public void setAsText(String text) throws IllegalArgumentException { + ExoticType exoticType = new ExoticType(); + exoticType.setName(text.toUpperCase()); + + setValue(exoticType); + } +} diff --git a/spring-rest/src/main/java/com/baeldung/propertyeditor/exotictype/model/ExoticType.java b/spring-rest/src/main/java/com/baeldung/propertyeditor/exotictype/model/ExoticType.java new file mode 100644 index 0000000000..95ba95643d --- /dev/null +++ b/spring-rest/src/main/java/com/baeldung/propertyeditor/exotictype/model/ExoticType.java @@ -0,0 +1,14 @@ +package com.baeldung.propertyeditor.exotictype.model; + +public class ExoticType { + + private String name; + + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } + +} diff --git a/spring-rest/src/main/resources/application.properties b/spring-rest/src/main/resources/application.properties index 300589f561..c4722f3c36 100644 --- a/spring-rest/src/main/resources/application.properties +++ b/spring-rest/src/main/resources/application.properties @@ -1,2 +1,2 @@ -server.port= 8082 +server.port= 8080 server.context-path=/spring-rest \ No newline at end of file diff --git a/spring-rest/src/test/java/com/baeldung/propertyeditor/CreditCardEditorTest.java b/spring-rest/src/test/java/com/baeldung/propertyeditor/creditcard/CreditCardEditorTest.java similarity index 88% rename from spring-rest/src/test/java/com/baeldung/propertyeditor/CreditCardEditorTest.java rename to spring-rest/src/test/java/com/baeldung/propertyeditor/creditcard/CreditCardEditorTest.java index b7da905f13..e87adbc712 100644 --- a/spring-rest/src/test/java/com/baeldung/propertyeditor/CreditCardEditorTest.java +++ b/spring-rest/src/test/java/com/baeldung/propertyeditor/creditcard/CreditCardEditorTest.java @@ -1,4 +1,4 @@ -package com.baeldung.propertyeditor; +package com.baeldung.propertyeditor.creditcard; import org.junit.Assert; import org.junit.Before; @@ -6,6 +6,9 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.runners.MockitoJUnitRunner; +import com.baeldung.propertyeditor.creditcard.CreditCard; +import com.baeldung.propertyeditor.creditcard.CreditCardEditor; + @RunWith(MockitoJUnitRunner.class) public class CreditCardEditorTest { From 1fe62a811cd311c2fd1c5153114dd090cba6e473 Mon Sep 17 00:00:00 2001 From: Erdem Date: Fri, 4 May 2018 00:26:37 +0300 Subject: [PATCH 26/66] BAEL-1746 added custom property editor implementation --- .../propertyeditor/PropertyEditorRestController.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/spring-rest/src/main/java/com/baeldung/propertyeditor/PropertyEditorRestController.java b/spring-rest/src/main/java/com/baeldung/propertyeditor/PropertyEditorRestController.java index 24f1b33471..02edc96cf6 100644 --- a/spring-rest/src/main/java/com/baeldung/propertyeditor/PropertyEditorRestController.java +++ b/spring-rest/src/main/java/com/baeldung/propertyeditor/PropertyEditorRestController.java @@ -16,13 +16,15 @@ import com.baeldung.propertyeditor.exotictype.model.ExoticType; @RequestMapping(value = "/property-editor") public class PropertyEditorRestController { - @GetMapping(value = "/credit-card/{card-no}", produces = MediaType.APPLICATION_JSON_UTF8_VALUE) + @GetMapping(value = "/credit-card/{card-no}", + produces = MediaType.APPLICATION_JSON_UTF8_VALUE) public CreditCard parseCreditCardNumber(@PathVariable("card-no") CreditCard creditCard) { return creditCard; } - @GetMapping(value = "/exotic-type/{value}", produces = MediaType.APPLICATION_JSON_UTF8_VALUE) - public ExoticType parseCreditCardNumber(@PathVariable("value") ExoticType exoticType) { + @GetMapping(value = "/exotic-type/{value}", + produces = MediaType.APPLICATION_JSON_UTF8_VALUE) + public ExoticType parseExoticType(@PathVariable("value") ExoticType exoticType) { return exoticType; } From c8b44cc141a0db743e52f19c87995b349e65ef11 Mon Sep 17 00:00:00 2001 From: Erdem Date: Fri, 4 May 2018 00:53:01 +0300 Subject: [PATCH 27/66] remove weblux files --- .../com/baeldung/reactive/webflux/Event.java | 13 ------ .../webflux/EventStreamController.java | 20 --------- .../webflux/WebfluxDemoApplication.java | 12 ----- .../static/webflux/client-event-stream.html | 45 ------------------- 4 files changed, 90 deletions(-) delete mode 100644 spring-5-reactive/src/main/java/com/baeldung/reactive/webflux/Event.java delete mode 100644 spring-5-reactive/src/main/java/com/baeldung/reactive/webflux/EventStreamController.java delete mode 100644 spring-5-reactive/src/main/java/com/baeldung/reactive/webflux/WebfluxDemoApplication.java delete mode 100644 spring-5-reactive/src/main/resources/static/webflux/client-event-stream.html diff --git a/spring-5-reactive/src/main/java/com/baeldung/reactive/webflux/Event.java b/spring-5-reactive/src/main/java/com/baeldung/reactive/webflux/Event.java deleted file mode 100644 index 03e80e915e..0000000000 --- a/spring-5-reactive/src/main/java/com/baeldung/reactive/webflux/Event.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.baeldung.reactive.webflux; - -import lombok.AllArgsConstructor; -import lombok.Data; - -@Data -@AllArgsConstructor -public class Event { - - private Long id; - private String body; - -} diff --git a/spring-5-reactive/src/main/java/com/baeldung/reactive/webflux/EventStreamController.java b/spring-5-reactive/src/main/java/com/baeldung/reactive/webflux/EventStreamController.java deleted file mode 100644 index f3d10437e2..0000000000 --- a/spring-5-reactive/src/main/java/com/baeldung/reactive/webflux/EventStreamController.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.baeldung.reactive.webflux; - -import java.time.Duration; - -import org.springframework.http.MediaType; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RestController; - -import reactor.core.publisher.Flux; - -@RestController -public class EventStreamController { - - @GetMapping(value = "/events", produces = MediaType.TEXT_EVENT_STREAM_VALUE) - public Flux getEvents() { - return Flux.interval(Duration.ofMillis(1000)) - .map(tick -> new Event(tick, "This is Event #" + tick)); - } - -} diff --git a/spring-5-reactive/src/main/java/com/baeldung/reactive/webflux/WebfluxDemoApplication.java b/spring-5-reactive/src/main/java/com/baeldung/reactive/webflux/WebfluxDemoApplication.java deleted file mode 100644 index 70cad0ad22..0000000000 --- a/spring-5-reactive/src/main/java/com/baeldung/reactive/webflux/WebfluxDemoApplication.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.baeldung.reactive.webflux; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class WebfluxDemoApplication { - - public static void main(String[] args) { - SpringApplication.run(WebfluxDemoApplication.class, args); - } -} diff --git a/spring-5-reactive/src/main/resources/static/webflux/client-event-stream.html b/spring-5-reactive/src/main/resources/static/webflux/client-event-stream.html deleted file mode 100644 index e44cbf0746..0000000000 --- a/spring-5-reactive/src/main/resources/static/webflux/client-event-stream.html +++ /dev/null @@ -1,45 +0,0 @@ - - - - - Baeldung: Spring 5 Reactive Webflux - real time event streaming - - - - - - -

Events streamed...

- - - - - - - - - -
Event IdEvent Body
- - - - - \ No newline at end of file From 8d8010cd2e36f51115f4705127f6dd33fa43ac31 Mon Sep 17 00:00:00 2001 From: Erdem Date: Fri, 4 May 2018 00:53:57 +0300 Subject: [PATCH 28/66] remove weblux files --- spring-5-reactive/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-5-reactive/pom.xml b/spring-5-reactive/pom.xml index 324fb13dd2..96378c60de 100644 --- a/spring-5-reactive/pom.xml +++ b/spring-5-reactive/pom.xml @@ -13,7 +13,7 @@ org.springframework.boot spring-boot-starter-parent - 2.0.1.RELEASE + 2.0.0.RELEASE From 86498b66d842d4d905f1839ec70e7d7779997184 Mon Sep 17 00:00:00 2001 From: KevinGilmore Date: Fri, 4 May 2018 07:44:28 -0500 Subject: [PATCH 29/66] Update README files (#4170) * BAEL-1612: Update README * BAEL-1562: Update README * BAEL-1562: Update README * BAEL-1679: Update README --- core-java/README.md | 1 - persistence-modules/spring-jpa/README.md | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core-java/README.md b/core-java/README.md index 8b20eebf57..8a94c9de8e 100644 --- a/core-java/README.md +++ b/core-java/README.md @@ -125,7 +125,6 @@ - [An Advanced Tagging Implementation with JPA](http://www.baeldung.com/jpa-tagging-advanced) - [Handling Daylight Savings Time in Java](http://www.baeldung.com/java-daylight-savings) - [Inheritance and Composition (Is-a vs Has-a relationship) in Java](http://www.baeldung.com/java-inheritance-composition) -- [Double-Checked Locking with Singleton](http://www.baeldung.com/java-singleton-double-checked-locking) - [Finding Max/Min of a List or Collection](http://www.baeldung.com/java-collection-min-max) - [The "final" Keyword in Java](http://www.baeldung.com/java-final) - [What is the serialVersionUID?](http://www.baeldung.com/java-serial-version-uid) diff --git a/persistence-modules/spring-jpa/README.md b/persistence-modules/spring-jpa/README.md index 2a717417d7..cb71d386e2 100644 --- a/persistence-modules/spring-jpa/README.md +++ b/persistence-modules/spring-jpa/README.md @@ -16,11 +16,12 @@ - [Self-Contained Testing Using an In-Memory Database](http://www.baeldung.com/spring-jpa-test-in-memory-database) - [Spring Data JPA – Adding a Method in All Repositories](http://www.baeldung.com/spring-data-jpa-method-in-all-repositories) - [A Guide to Spring AbstractRoutingDatasource](http://www.baeldung.com/spring-abstract-routing-data-source) -- [Advanced Tagging Implementation with JPA] (http://www.baeldung.com/jpa-tagging-advanced) +- [Advanced Tagging Implementation with JPA](http://www.baeldung.com/jpa-tagging-advanced) - [A Guide to Hibernate with Spring 4](http://www.baeldung.com/the-persistence-layer-with-spring-and-jpa) - [Testing REST with multiple MIME types](http://www.baeldung.com/testing-rest-api-with-multiple-media-types) - [Obtaining Auto-generated Keys in Spring JDBC](http://www.baeldung.com/spring-jdbc-autogenerated-keys) - [Transactions with Spring 4 and JPA](http://www.baeldung.com/transaction-configuration-with-jpa-and-spring) +- [Spring Data JPA @Query](http://www.baeldung.com/spring-data-jpa-query) ### Eclipse Config After importing the project into Eclipse, you may see the following error: From 88e49ebda5d44713bc23bcd872eac147afe163a6 Mon Sep 17 00:00:00 2001 From: Tom Hombergs Date: Fri, 4 May 2018 20:53:53 +0200 Subject: [PATCH 30/66] added article link --- core-java/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java/README.md b/core-java/README.md index 8a94c9de8e..b40298abe4 100644 --- a/core-java/README.md +++ b/core-java/README.md @@ -146,3 +146,4 @@ - [Introduction to SSL in Java](http://www.baeldung.com/java-ssl) - [Java KeyStore API](http://www.baeldung.com/java-keystore) - [Double-Checked Locking with Singleton](http://www.baeldung.com/java-singleton-double-checked-locking) +- [Guide to Java Clock Class](http://www.baeldung.com/java-clock) From 58612d0fb87459feaf8c10ea4cc7234bea14d150 Mon Sep 17 00:00:00 2001 From: Alessio Stalla Date: Fri, 4 May 2018 21:30:53 +0200 Subject: [PATCH 31/66] BAEL-82 (#4109) * BAEL-82 revised example code * Fix the build --- spring-all/pom.xml | 1 + ...BasedApplicationAndServletInitializer.java | 28 ++++++++ ...nnotationsBasedApplicationInitializer.java | 16 +++++ .../config/ApplicationInitializer.java | 24 +++---- .../src/main/webapp/WEB-INF/greeting.xml | 11 +++ .../src/main/webapp/WEB-INF/mvc-servlet.xml | 6 -- .../webapp/WEB-INF/rootApplicationContext.xml | 4 +- spring-all/src/main/webapp/WEB-INF/web.xml | 72 ++++++++++++------- 8 files changed, 115 insertions(+), 47 deletions(-) create mode 100644 spring-all/src/main/java/com/baeldung/contexts/config/AnnotationsBasedApplicationAndServletInitializer.java create mode 100644 spring-all/src/main/java/com/baeldung/contexts/config/AnnotationsBasedApplicationInitializer.java create mode 100644 spring-all/src/main/webapp/WEB-INF/greeting.xml delete mode 100644 spring-all/src/main/webapp/WEB-INF/mvc-servlet.xml diff --git a/spring-all/pom.xml b/spring-all/pom.xml index ac66ecdad8..f9ced963e7 100644 --- a/spring-all/pom.xml +++ b/spring-all/pom.xml @@ -170,6 +170,7 @@ org.springframework.boot spring-boot-starter-thymeleaf + ${org.springframework.version} diff --git a/spring-all/src/main/java/com/baeldung/contexts/config/AnnotationsBasedApplicationAndServletInitializer.java b/spring-all/src/main/java/com/baeldung/contexts/config/AnnotationsBasedApplicationAndServletInitializer.java new file mode 100644 index 0000000000..8ec35515a3 --- /dev/null +++ b/spring-all/src/main/java/com/baeldung/contexts/config/AnnotationsBasedApplicationAndServletInitializer.java @@ -0,0 +1,28 @@ +package com.baeldung.contexts.config; + +import org.springframework.web.context.AbstractContextLoaderInitializer; +import org.springframework.web.context.WebApplicationContext; +import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; +import org.springframework.web.servlet.support.AbstractDispatcherServletInitializer; + +public class AnnotationsBasedApplicationAndServletInitializer extends AbstractDispatcherServletInitializer { + + @Override + protected WebApplicationContext createRootApplicationContext() { + AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); + rootContext.register(RootApplicationConfig.class); + return rootContext; + } + + @Override + protected WebApplicationContext createServletApplicationContext() { + AnnotationConfigWebApplicationContext secureWebAppContext = new AnnotationConfigWebApplicationContext(); + secureWebAppContext.register(SecureWebAppConfig.class); + return secureWebAppContext; + } + + @Override + protected String[] getServletMappings() { + return new String[] { "/s/api/*" }; + } +} diff --git a/spring-all/src/main/java/com/baeldung/contexts/config/AnnotationsBasedApplicationInitializer.java b/spring-all/src/main/java/com/baeldung/contexts/config/AnnotationsBasedApplicationInitializer.java new file mode 100644 index 0000000000..0d2674d4f3 --- /dev/null +++ b/spring-all/src/main/java/com/baeldung/contexts/config/AnnotationsBasedApplicationInitializer.java @@ -0,0 +1,16 @@ +package com.baeldung.contexts.config; + +import org.springframework.web.context.AbstractContextLoaderInitializer; +import org.springframework.web.context.WebApplicationContext; +import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; + +public class AnnotationsBasedApplicationInitializer extends AbstractContextLoaderInitializer { + + @Override + protected WebApplicationContext createRootApplicationContext() { + AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); + rootContext.register(RootApplicationConfig.class); + return rootContext; + } + +} \ No newline at end of file diff --git a/spring-all/src/main/java/com/baeldung/contexts/config/ApplicationInitializer.java b/spring-all/src/main/java/com/baeldung/contexts/config/ApplicationInitializer.java index c3ff90cf39..babad90598 100644 --- a/spring-all/src/main/java/com/baeldung/contexts/config/ApplicationInitializer.java +++ b/spring-all/src/main/java/com/baeldung/contexts/config/ApplicationInitializer.java @@ -5,31 +5,31 @@ import javax.servlet.ServletException; import javax.servlet.ServletRegistration; import org.springframework.context.annotation.Configuration; +import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.web.WebApplicationInitializer; import org.springframework.web.context.ContextLoaderListener; import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; +import org.springframework.web.context.support.XmlWebApplicationContext; import org.springframework.web.servlet.DispatcherServlet; -@Configuration public class ApplicationInitializer implements WebApplicationInitializer { @Override public void onStartup(ServletContext servletContext) throws ServletException { - AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); - rootContext.register(RootApplicationConfig.class); - servletContext.addListener(new ContextLoaderListener(rootContext)); + //XML Context + //XmlWebApplicationContext rootContext = new XmlWebApplicationContext(); + //rootContext.setConfigLocations("/WEB-INF/rootApplicationContext.xml"); + //Annotations Context + //AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); + //rootContext.register(RootApplicationConfig.class); + //Registration + //servletContext.addListener(new ContextLoaderListener(rootContext)); - AnnotationConfigWebApplicationContext normalWebAppContext = new AnnotationConfigWebApplicationContext(); - normalWebAppContext.register(NormalWebAppConfig.class); + XmlWebApplicationContext normalWebAppContext = new XmlWebApplicationContext(); + normalWebAppContext.setConfigLocation("/WEB-INF/normal-webapp-servlet.xml"); ServletRegistration.Dynamic normal = servletContext.addServlet("normal-webapp", new DispatcherServlet(normalWebAppContext)); normal.setLoadOnStartup(1); normal.addMapping("/api/*"); - - AnnotationConfigWebApplicationContext secureWebAppContext = new AnnotationConfigWebApplicationContext(); - secureWebAppContext.register(SecureWebAppConfig.class); - ServletRegistration.Dynamic secure = servletContext.addServlet("secure-webapp", new DispatcherServlet(secureWebAppContext)); - secure.setLoadOnStartup(1); - secure.addMapping("/s/api/*"); } } diff --git a/spring-all/src/main/webapp/WEB-INF/greeting.xml b/spring-all/src/main/webapp/WEB-INF/greeting.xml new file mode 100644 index 0000000000..3f0ae83455 --- /dev/null +++ b/spring-all/src/main/webapp/WEB-INF/greeting.xml @@ -0,0 +1,11 @@ + + + + + + + + \ No newline at end of file diff --git a/spring-all/src/main/webapp/WEB-INF/mvc-servlet.xml b/spring-all/src/main/webapp/WEB-INF/mvc-servlet.xml deleted file mode 100644 index 4ba9642448..0000000000 --- a/spring-all/src/main/webapp/WEB-INF/mvc-servlet.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - \ No newline at end of file diff --git a/spring-all/src/main/webapp/WEB-INF/rootApplicationContext.xml b/spring-all/src/main/webapp/WEB-INF/rootApplicationContext.xml index cd79c64e79..af03661ebc 100644 --- a/spring-all/src/main/webapp/WEB-INF/rootApplicationContext.xml +++ b/spring-all/src/main/webapp/WEB-INF/rootApplicationContext.xml @@ -10,7 +10,5 @@ - - - + \ No newline at end of file diff --git a/spring-all/src/main/webapp/WEB-INF/web.xml b/spring-all/src/main/webapp/WEB-INF/web.xml index 2050f28f81..55c2ccd62a 100644 --- a/spring-all/src/main/webapp/WEB-INF/web.xml +++ b/spring-all/src/main/webapp/WEB-INF/web.xml @@ -3,37 +3,54 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0"> + + + - + + + + + - + - + + - test-mvc + normal-webapp-annotations org.springframework.web.servlet.DispatcherServlet + + contextClass + org.springframework.web.context.support.AnnotationConfigWebApplicationContext + contextConfigLocation - /WEB-INF/test-mvc.xml + com.baeldung.contexts.config.NormalWebAppConfig 1 - - test-mvc - /test/* + normal-webapp-annotations + /api-ann/* From 258d5c09f0c0e690153dd38a7c4636e7e0b3e34f Mon Sep 17 00:00:00 2001 From: KevinGilmore Date: Fri, 4 May 2018 19:03:46 -0500 Subject: [PATCH 32/66] BAEL-1701 Update README (#4174) * BAEL-1612: Update README * BAEL-1562: Update README * BAEL-1562: Update README * BAEL-1679: Update README * BAEL-1701: Update README --- aws/README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/aws/README.md b/aws/README.md index 5737222c93..d23937a419 100644 --- a/aws/README.md +++ b/aws/README.md @@ -8,6 +8,5 @@ - [Multipart Uploads in Amazon S3 with Java](http://www.baeldung.com/aws-s3-multipart-upload) - [Integration Testing with a Local DynamoDB Instance](http://www.baeldung.com/dynamodb-local-integration-tests) - [Using the JetS3t Java Client With Amazon S3](http://www.baeldung.com/jets3t-amazon-s3) -- [Iteration in Thymeleaf](http://www.baeldung.com/thymeleaf-iteration) -- [Working with Boolean in Thymeleaf](http://www.baeldung.com/thymeleaf-boolean) +- [Managing Amazon SQS Queues in Java](http://www.baeldung.com/aws-queues-java) From e22750ffe1ac9fbe992925ed5996bfb74a1fe42a Mon Sep 17 00:00:00 2001 From: Felipe Santiago Corro Date: Sat, 5 May 2018 02:40:37 -0300 Subject: [PATCH 33/66] Spring cache: custom key generator (#4166) --- .../java/com/baeldung/cache/BookService.java | 21 ++++++++++++ .../baeldung/cache/CustomKeyGenerator.java | 14 ++++++++ .../main/java/com/baeldung/model/Book.java | 9 ++++++ .../web/config/ApplicationCacheConfig.java | 32 +++++++++++++++++++ 4 files changed, 76 insertions(+) create mode 100644 spring-mvc-java/src/main/java/com/baeldung/cache/BookService.java create mode 100644 spring-mvc-java/src/main/java/com/baeldung/cache/CustomKeyGenerator.java create mode 100644 spring-mvc-java/src/main/java/com/baeldung/spring/web/config/ApplicationCacheConfig.java diff --git a/spring-mvc-java/src/main/java/com/baeldung/cache/BookService.java b/spring-mvc-java/src/main/java/com/baeldung/cache/BookService.java new file mode 100644 index 0000000000..91c37ce5b6 --- /dev/null +++ b/spring-mvc-java/src/main/java/com/baeldung/cache/BookService.java @@ -0,0 +1,21 @@ +package com.baeldung.cache; + +import com.baeldung.model.Book; +import org.springframework.cache.annotation.Cacheable; +import org.springframework.stereotype.Component; + +import java.util.ArrayList; +import java.util.List; + +@Component +public class BookService { + + @Cacheable(value="books", keyGenerator="customKeyGenerator") + public List getBooks() { + List books = new ArrayList(); + books.add(new Book(1, "The Counterfeiters", "André Gide")); + books.add(new Book(2, "Peer Gynt and Hedda Gabler", "Henrik Ibsen")); + return books; + } + +} diff --git a/spring-mvc-java/src/main/java/com/baeldung/cache/CustomKeyGenerator.java b/spring-mvc-java/src/main/java/com/baeldung/cache/CustomKeyGenerator.java new file mode 100644 index 0000000000..2cb4bba95f --- /dev/null +++ b/spring-mvc-java/src/main/java/com/baeldung/cache/CustomKeyGenerator.java @@ -0,0 +1,14 @@ +package com.baeldung.cache; + +import org.springframework.cache.interceptor.KeyGenerator; +import org.springframework.util.StringUtils; + +import java.lang.reflect.Method; + +public class CustomKeyGenerator implements KeyGenerator { + + public Object generate(Object target, Method method, Object... params) { + return target.getClass().getSimpleName() + "_" + method.getName() + "_" + + StringUtils.arrayToDelimitedString(params, "_"); + } +} diff --git a/spring-mvc-java/src/main/java/com/baeldung/model/Book.java b/spring-mvc-java/src/main/java/com/baeldung/model/Book.java index b0cabe0125..bdfa1d835a 100644 --- a/spring-mvc-java/src/main/java/com/baeldung/model/Book.java +++ b/spring-mvc-java/src/main/java/com/baeldung/model/Book.java @@ -6,6 +6,15 @@ public class Book { private String author; private String title; + public Book() { + } + + public Book(int id, String author, String title) { + this.id = id; + this.author = author; + this.title = title; + } + public int getId() { return id; } diff --git a/spring-mvc-java/src/main/java/com/baeldung/spring/web/config/ApplicationCacheConfig.java b/spring-mvc-java/src/main/java/com/baeldung/spring/web/config/ApplicationCacheConfig.java new file mode 100644 index 0000000000..e78506deaa --- /dev/null +++ b/spring-mvc-java/src/main/java/com/baeldung/spring/web/config/ApplicationCacheConfig.java @@ -0,0 +1,32 @@ +package com.baeldung.spring.web.config; + +import com.baeldung.cache.CustomKeyGenerator; +import org.springframework.cache.Cache; +import org.springframework.cache.CacheManager; +import org.springframework.cache.annotation.CachingConfigurerSupport; +import org.springframework.cache.annotation.EnableCaching; +import org.springframework.cache.concurrent.ConcurrentMapCache; +import org.springframework.cache.interceptor.KeyGenerator; +import org.springframework.cache.support.SimpleCacheManager; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import java.util.Arrays; + +@EnableCaching +@Configuration +public class ApplicationCacheConfig extends CachingConfigurerSupport { + + @Bean + public CacheManager cacheManager() { + SimpleCacheManager cacheManager = new SimpleCacheManager(); + Cache booksCache = new ConcurrentMapCache("books"); + cacheManager.setCaches(Arrays.asList(booksCache)); + return cacheManager; + } + + @Bean("customKeyGenerator") + public KeyGenerator keyGenerator() { + return new CustomKeyGenerator(); + } +} From 4ad804252205ef5b0e6a0e60d4302a087917eceb Mon Sep 17 00:00:00 2001 From: mherbaghinyan Date: Sat, 5 May 2018 10:26:51 +0400 Subject: [PATCH 34/66] test the results --- .../designpatterns/composite/CompositeDemo.java | 10 +++++++++- .../{GeneralDepartment.java => HeadDepartment.java} | 4 ++-- 2 files changed, 11 insertions(+), 3 deletions(-) rename core-java/src/main/java/com/baeldung/designpatterns/composite/{GeneralDepartment.java => HeadDepartment.java} (86%) diff --git a/core-java/src/main/java/com/baeldung/designpatterns/composite/CompositeDemo.java b/core-java/src/main/java/com/baeldung/designpatterns/composite/CompositeDemo.java index 83024b7d21..9537dd0d2b 100644 --- a/core-java/src/main/java/com/baeldung/designpatterns/composite/CompositeDemo.java +++ b/core-java/src/main/java/com/baeldung/designpatterns/composite/CompositeDemo.java @@ -6,6 +6,14 @@ package com.baeldung.designpatterns.composite; public class CompositeDemo { public static void main(String args[]) { - Department salesDepartment = new SalesDepartment(); + Department salesDepartment = new SalesDepartment(1, "Sales department"); + Department financialDepartment = new FinancialDepartment(2, "Financial department"); + + HeadDepartment headDepartment = new HeadDepartment(3, "Head department"); + + headDepartment.addDepartMent(salesDepartment); + headDepartment.addDepartMent(financialDepartment); + + headDepartment.printDepartmentName(); } } diff --git a/core-java/src/main/java/com/baeldung/designpatterns/composite/GeneralDepartment.java b/core-java/src/main/java/com/baeldung/designpatterns/composite/HeadDepartment.java similarity index 86% rename from core-java/src/main/java/com/baeldung/designpatterns/composite/GeneralDepartment.java rename to core-java/src/main/java/com/baeldung/designpatterns/composite/HeadDepartment.java index 15c5bc9494..8854fce5b3 100644 --- a/core-java/src/main/java/com/baeldung/designpatterns/composite/GeneralDepartment.java +++ b/core-java/src/main/java/com/baeldung/designpatterns/composite/HeadDepartment.java @@ -6,14 +6,14 @@ import java.util.List; /** * Created by Gebruiker on 5/1/2018. */ -public class GeneralDepartment implements Department { +public class HeadDepartment implements Department { private Integer id; private String name; private List childDepartments; - public GeneralDepartment(Integer id, String name) { + public HeadDepartment(Integer id, String name) { this.id = id; this.name = name; this.childDepartments = new ArrayList(); From c2d89c8679444fa72fa8b6a00729ee5d33149e11 Mon Sep 17 00:00:00 2001 From: Siben Nayak Date: Sat, 5 May 2018 18:24:13 +0530 Subject: [PATCH 35/66] Fixed unit test cases and formatting --- .../main/kotlin/com/baeldung/filesystem/FileWriter.kt | 6 +++--- .../kotlin/com/baeldung/filesystem/FileWriterTest.kt | 10 ++++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/core-kotlin/src/main/kotlin/com/baeldung/filesystem/FileWriter.kt b/core-kotlin/src/main/kotlin/com/baeldung/filesystem/FileWriter.kt index 20d9c963c7..6dc9b95f1f 100644 --- a/core-kotlin/src/main/kotlin/com/baeldung/filesystem/FileWriter.kt +++ b/core-kotlin/src/main/kotlin/com/baeldung/filesystem/FileWriter.kt @@ -5,13 +5,13 @@ import java.io.File class FileWriter { fun writeFileUsingPrintWriter(fileName: String, fileContent: String) = - File(fileName).printWriter().use { out -> out.println(fileContent) } + File(fileName).printWriter().use { out -> out.print(fileContent) } fun writeFileUsingBufferedWriter(fileName: String, fileContent: String) = - File(fileName).bufferedWriter().use { out -> out.write(fileContent) } + File(fileName).bufferedWriter().use { out -> out.write(fileContent) } fun writeFileDirectly(fileName: String, fileContent: String) = - File(fileName).writeText(fileContent) + File(fileName).writeText(fileContent) fun writeFileDirectlyAsBytes(fileName: String, fileContent: String) = File(fileName).writeBytes(fileContent.toByteArray()) diff --git a/core-kotlin/src/test/kotlin/com/baeldung/filesystem/FileWriterTest.kt b/core-kotlin/src/test/kotlin/com/baeldung/filesystem/FileWriterTest.kt index 43a9957de1..91c66a4fee 100644 --- a/core-kotlin/src/test/kotlin/com/baeldung/filesystem/FileWriterTest.kt +++ b/core-kotlin/src/test/kotlin/com/baeldung/filesystem/FileWriterTest.kt @@ -1,6 +1,8 @@ package com.baeldung.filesystem import org.junit.jupiter.api.Test +import java.io.File +import kotlin.test.assertEquals internal class FileWriterTest { @@ -13,21 +15,29 @@ internal class FileWriterTest { @Test fun whenWrittenWithPrintWriter_thenCorrect() { fileWriter.writeFileUsingPrintWriter(fileName, fileContent) + + assertEquals(fileContent, File(fileName).readText()) } @Test fun whenWrittenWithBufferedWriter_thenCorrect() { fileWriter.writeFileUsingBufferedWriter(fileName, fileContent) + + assertEquals(fileContent, File(fileName).readText()) } @Test fun whenWrittenDirectly_thenCorrect() { fileWriter.writeFileDirectly(fileName, fileContent) + + assertEquals(fileContent, File(fileName).readText()) } @Test fun whenWrittenDirectlyAsBytes_thenCorrect() { fileWriter.writeFileDirectlyAsBytes(fileName, fileContent) + + assertEquals(fileContent, File(fileName).readText()) } } \ No newline at end of file From 05b7e933bd4535376f4e860b4aca589bbb082ffc Mon Sep 17 00:00:00 2001 From: amit2103 Date: Sun, 6 May 2018 02:00:00 +0530 Subject: [PATCH 36/66] Bael 5247 (#4175) * Added parent module on poms that have no parent defined * Removed dependency reduced pom from undertow module * Added new parent pom * initial clean up of child poms * Added new parent pom * [BAEL-5247] - New Parents in the tutorials repo --- cdi/pom.xml | 10 +- core-groovy/pom.xml | 6 - core-java-8/pom.xml | 11 +- core-java-collections/pom.xml | 15 +- core-java-concurrency/pom.xml | 11 +- core-java-io/pom.xml | 10 +- core-java-sun/pom.xml | 10 +- core-java/pom.xml | 12 +- core-kotlin/pom.xml | 6 - drools/pom.xml | 16 +- gson/pom.xml | 10 +- guava-modules/guava-18/pom.xml | 14 +- guava-modules/guava-19/pom.xml | 14 +- guava-modules/guava-21/pom.xml | 12 +- guava/pom.xml | 10 +- guest/junit5-example/pom.xml | 9 +- handling-spring-static-resources/pom.xml | 5 +- httpclient/pom.xml | 10 +- jackson/pom.xml | 11 +- jmh/pom.xml | 16 +- jsonb/pom.xml | 6 - logging-modules/log-mdc/pom.xml | 24 +- parent-java/README.md | 1 + parent-java/pom.xml | 30 ++ parent-spring/README.md | 1 + parent-spring/pom.xml | 36 ++ persistence-modules/java-cassandra/pom.xml | 13 +- .../spring-data-cassandra/pom.xml | 6 +- persistence-modules/spring-data-redis/pom.xml | 6 +- persistence-modules/spring-data-solr/pom.xml | 6 +- pom.xml | 9 + rxjava/pom.xml | 11 +- saas/pom.xml | 10 +- spring-core/pom.xml | 194 +++++---- spring-data-elasticsearch/pom.xml | 5 +- spring-data-mongodb/pom.xml | 5 +- spring-dispatcher-servlet/pom.xml | 184 +++++---- spring-groovy/pom.xml | 27 +- spring-mvc-simple/pom.xml | 12 +- spring-mvc-tiles/pom.xml | 9 +- spring-mvc-velocity/pom.xml | 248 ++++++------ spring-rest-embedded-tomcat/pom.xml | 20 +- spring-security-mvc-custom/pom.xml | 380 +++++++++--------- spring-security-mvc-digest-auth/pom.xml | 9 +- spring-security-mvc-login/pom.xml | 9 +- .../pom.xml | 9 +- spring-security-mvc-session/pom.xml | 9 +- spring-security-mvc-socket/pom.xml | 9 +- spring-security-rest-basic-auth/pom.xml | 9 +- spring-security-rest/pom.xml | 9 +- spring-userservice/pom.xml | 9 +- struts-2/pom.xml | 9 +- testing-modules/junit-5/pom.xml | 42 +- testing-modules/mockito/pom.xml | 12 +- testing-modules/rest-assured/pom.xml | 11 +- testing-modules/rest-testing/pom.xml | 12 +- testing-modules/testing/pom.xml | 11 +- undertow/dependency-reduced-pom.xml | 90 +++++ video-tutorials/jackson-annotations/pom.xml | 6 - video-tutorials/pom.xml | 5 +- 60 files changed, 854 insertions(+), 877 deletions(-) create mode 100644 parent-java/README.md create mode 100644 parent-java/pom.xml create mode 100644 parent-spring/README.md create mode 100644 parent-spring/pom.xml create mode 100644 undertow/dependency-reduced-pom.xml diff --git a/cdi/pom.xml b/cdi/pom.xml index 74ba52ea8d..00cc96a7ed 100644 --- a/cdi/pom.xml +++ b/cdi/pom.xml @@ -8,16 +8,12 @@ com.baeldung - parent-modules - 1.0.0-SNAPSHOT + parent-spring + 0.0.1-SNAPSHOT + ../parent-spring - - org.springframework - spring-core - ${spring.version} - org.springframework spring-context diff --git a/core-groovy/pom.xml b/core-groovy/pom.xml index 0126e96758..9076e63642 100644 --- a/core-groovy/pom.xml +++ b/core-groovy/pom.xml @@ -28,12 +28,6 @@ groovy-sql ${groovy-sql.version} - - org.junit.jupiter - junit-jupiter-engine - ${junit.jupiter.version} - test - org.junit.platform junit-platform-runner diff --git a/core-java-8/pom.xml b/core-java-8/pom.xml index 7b49772309..aab349781a 100644 --- a/core-java-8/pom.xml +++ b/core-java-8/pom.xml @@ -9,17 +9,12 @@ com.baeldung - parent-modules - 1.0.0-SNAPSHOT + parent-java + 0.0.1-SNAPSHOT + ../parent-java - - - com.google.guava - guava - ${guava.version} - org.apache.commons commons-collections4 diff --git a/core-java-collections/pom.xml b/core-java-collections/pom.xml index 4973b8e837..c5d3396642 100644 --- a/core-java-collections/pom.xml +++ b/core-java-collections/pom.xml @@ -8,10 +8,11 @@ core-java-collections - com.baeldung - parent-modules - 1.0.0-SNAPSHOT - + com.baeldung + parent-java + 0.0.1-SNAPSHOT + ../parent-java + @@ -25,11 +26,6 @@ collections-generic ${collections-generic.version} - - com.google.guava - guava - ${guava.version} - org.apache.commons commons-collections4 @@ -55,7 +51,6 @@ - 22.0 3.5 4.1 4.01 diff --git a/core-java-concurrency/pom.xml b/core-java-concurrency/pom.xml index 829c511143..7e162abc64 100644 --- a/core-java-concurrency/pom.xml +++ b/core-java-concurrency/pom.xml @@ -9,17 +9,12 @@ com.baeldung - parent-modules - 1.0.0-SNAPSHOT + parent-java + 0.0.1-SNAPSHOT + ../parent-java - - - com.google.guava - guava - ${guava.version} - org.apache.commons commons-collections4 diff --git a/core-java-io/pom.xml b/core-java-io/pom.xml index 9fcca6c590..1437b85ac2 100644 --- a/core-java-io/pom.xml +++ b/core-java-io/pom.xml @@ -9,8 +9,9 @@ com.baeldung - parent-modules - 1.0.0-SNAPSHOT + parent-java + 0.0.1-SNAPSHOT + ../parent-java @@ -20,11 +21,6 @@ collections-generic ${collections-generic.version} - - com.google.guava - guava - ${guava.version} - org.apache.commons commons-collections4 diff --git a/core-java-sun/pom.xml b/core-java-sun/pom.xml index aaffac5e38..3fd8e80296 100644 --- a/core-java-sun/pom.xml +++ b/core-java-sun/pom.xml @@ -8,8 +8,9 @@ com.baeldung - parent-modules - 1.0.0-SNAPSHOT + parent-java + 0.0.1-SNAPSHOT + ../parent-java @@ -19,11 +20,6 @@ collections-generic ${collections-generic.version} - - com.google.guava - guava - ${guava.version} - org.apache.commons commons-collections4 diff --git a/core-java/pom.xml b/core-java/pom.xml index 74a4fa1f75..88fae5edea 100644 --- a/core-java/pom.xml +++ b/core-java/pom.xml @@ -9,17 +9,12 @@ com.baeldung - parent-modules - 1.0.0-SNAPSHOT + parent-java + 0.0.1-SNAPSHOT + ../parent-java - - - com.google.guava - guava - ${guava.version} - commons-io commons-io @@ -438,7 +433,6 @@ 1.2.17 - 22.0 3.5 1.55 1.10 diff --git a/core-kotlin/pom.xml b/core-kotlin/pom.xml index d923ec698c..00c3ac188d 100644 --- a/core-kotlin/pom.xml +++ b/core-kotlin/pom.xml @@ -25,12 +25,6 @@ commons-math3 ${commons-math3.version} - - org.junit.jupiter - junit-jupiter-engine - ${junit.jupiter.version} - test - org.junit.platform junit-platform-runner diff --git a/drools/pom.xml b/drools/pom.xml index c1e8b34b06..60df7157f2 100644 --- a/drools/pom.xml +++ b/drools/pom.xml @@ -5,10 +5,11 @@ drools - com.baeldung - parent-modules - 1.0.0-SNAPSHOT - + com.baeldung + parent-spring + 0.0.1-SNAPSHOT + ../parent-spring + @@ -47,18 +48,13 @@ poi-ooxml ${apache-poi-version} - - org.springframework - spring-core - ${spring-core.version} - 4.4.6 7.4.1.Final 3.13 - 4.3.6.RELEASE + 4.3.6.RELEASE diff --git a/gson/pom.xml b/gson/pom.xml index 3e0bafee2c..912111374d 100644 --- a/gson/pom.xml +++ b/gson/pom.xml @@ -8,8 +8,9 @@ com.baeldung - parent-modules - 1.0.0-SNAPSHOT + parent-java + 0.0.1-SNAPSHOT + ../parent-java @@ -19,11 +20,6 @@ joda-time ${joda-time.version} - - com.google.guava - guava - ${guava.version} - commons-io commons-io diff --git a/guava-modules/guava-18/pom.xml b/guava-modules/guava-18/pom.xml index d2ddcc3fac..b3deb305f2 100644 --- a/guava-modules/guava-18/pom.xml +++ b/guava-modules/guava-18/pom.xml @@ -8,19 +8,11 @@ com.baeldung - parent-modules - 1.0.0-SNAPSHOT - ../../ + parent-java + 0.0.1-SNAPSHOT + ../../parent-java - - - com.google.guava - guava - ${guava.version} - - - 18.0 diff --git a/guava-modules/guava-19/pom.xml b/guava-modules/guava-19/pom.xml index 225dc9e9e3..9eb20d5bbe 100644 --- a/guava-modules/guava-19/pom.xml +++ b/guava-modules/guava-19/pom.xml @@ -8,19 +8,11 @@ com.baeldung - parent-modules - 1.0.0-SNAPSHOT - ../../ + parent-java + 0.0.1-SNAPSHOT + ../../parent-java - - - com.google.guava - guava - ${guava.version} - - - 19.0 diff --git a/guava-modules/guava-21/pom.xml b/guava-modules/guava-21/pom.xml index 42b66d84c8..7038810d24 100644 --- a/guava-modules/guava-21/pom.xml +++ b/guava-modules/guava-21/pom.xml @@ -7,18 +7,12 @@ com.baeldung - parent-modules - 1.0.0-SNAPSHOT - ../../ + parent-java + 0.0.1-SNAPSHOT + ../../parent-java - - com.google.guava - guava - ${guava.version} - - org.jooq jool diff --git a/guava/pom.xml b/guava/pom.xml index 3ad3220f21..da880cc995 100644 --- a/guava/pom.xml +++ b/guava/pom.xml @@ -8,17 +8,13 @@ com.baeldung - parent-modules - 1.0.0-SNAPSHOT + parent-java + 0.0.1-SNAPSHOT + ../parent-java - - com.google.guava - guava - ${guava.version} - org.apache.commons commons-collections4 diff --git a/guest/junit5-example/pom.xml b/guest/junit5-example/pom.xml index a63ccdee35..93ce207940 100644 --- a/guest/junit5-example/pom.xml +++ b/guest/junit5-example/pom.xml @@ -11,11 +11,6 @@ ../../ - - org.junit.jupiter - junit-jupiter-engine - 5.0.0-M4 - org.junit.jupiter junit-jupiter-params @@ -62,4 +57,8 @@
+ + + + \ No newline at end of file diff --git a/handling-spring-static-resources/pom.xml b/handling-spring-static-resources/pom.xml index a3c714514e..da8f88ee22 100644 --- a/handling-spring-static-resources/pom.xml +++ b/handling-spring-static-resources/pom.xml @@ -10,8 +10,9 @@ com.baeldung - parent-modules - 1.0.0-SNAPSHOT + parent-spring + 0.0.1-SNAPSHOT + ../parent-spring diff --git a/httpclient/pom.xml b/httpclient/pom.xml index af50f38ebe..2f9b511133 100644 --- a/httpclient/pom.xml +++ b/httpclient/pom.xml @@ -8,17 +8,13 @@ com.baeldung - parent-modules - 1.0.0-SNAPSHOT + parent-java + 0.0.1-SNAPSHOT + ../parent-java - - com.google.guava - guava - ${guava.version} - org.apache.commons commons-lang3 diff --git a/jackson/pom.xml b/jackson/pom.xml index fb2d48d4af..ea66f27833 100644 --- a/jackson/pom.xml +++ b/jackson/pom.xml @@ -8,18 +8,13 @@ com.baeldung - parent-modules - 1.0.0-SNAPSHOT + parent-java + 0.0.1-SNAPSHOT + ../parent-java - - com.google.guava - guava - ${guava.version} - - commons-io commons-io diff --git a/jmh/pom.xml b/jmh/pom.xml index 2b82b7a9d5..60b59262b4 100644 --- a/jmh/pom.xml +++ b/jmh/pom.xml @@ -10,8 +10,9 @@ com.baeldung - parent-modules - 1.0.0-SNAPSHOT + parent-java + 0.0.1-SNAPSHOT + ../parent-java @@ -25,17 +26,6 @@ jmh-generator-annprocess ${openjdk.jmh.version} - - junit - junit - ${junit.version} - test - - - com.google.guava - guava - ${guava.version} - diff --git a/jsonb/pom.xml b/jsonb/pom.xml index f9db831fe3..c4ef1efed6 100644 --- a/jsonb/pom.xml +++ b/jsonb/pom.xml @@ -34,12 +34,6 @@ junit-jupiter-api ${junit.jupiter.version} - - org.junit.jupiter - junit-jupiter-engine - ${junit.jupiter.version} - test - org.junit.platform junit-platform-surefire-provider diff --git a/logging-modules/log-mdc/pom.xml b/logging-modules/log-mdc/pom.xml index 16eeff43cf..7628c708e9 100644 --- a/logging-modules/log-mdc/pom.xml +++ b/logging-modules/log-mdc/pom.xml @@ -9,28 +9,22 @@ tutorial on logging with MDC and NDC - com.baeldung - parent-modules - 1.0.0-SNAPSHOT - ../../ - + com.baeldung + parent-spring + 0.0.1-SNAPSHOT + ../../parent-spring + - - - org.springframework - spring-core - ${springframework.version} - org.springframework spring-web - ${springframework.version} + ${spring.version} org.springframework spring-webmvc - ${springframework.version} + ${spring.version} javax.servlet @@ -79,14 +73,14 @@ org.springframework spring-test - ${springframework.version} + ${spring.version} test - 4.3.4.RELEASE + 4.3.4.RELEASE 1.2.17 2.7 3.3.6 diff --git a/parent-java/README.md b/parent-java/README.md new file mode 100644 index 0000000000..ff12555376 --- /dev/null +++ b/parent-java/README.md @@ -0,0 +1 @@ +## Relevant articles: diff --git a/parent-java/pom.xml b/parent-java/pom.xml new file mode 100644 index 0000000000..40df31d1c7 --- /dev/null +++ b/parent-java/pom.xml @@ -0,0 +1,30 @@ + + 4.0.0 + com.baeldung + parent-java + 0.0.1-SNAPSHOT + pom + parent-java + Parent for all java modules + + + com.baeldung + parent-modules + 1.0.0-SNAPSHOT + + + + + + com.google.guava + guava + ${guava.version} + + + + + 22.0 + + + \ No newline at end of file diff --git a/parent-spring/README.md b/parent-spring/README.md new file mode 100644 index 0000000000..ff12555376 --- /dev/null +++ b/parent-spring/README.md @@ -0,0 +1 @@ +## Relevant articles: diff --git a/parent-spring/pom.xml b/parent-spring/pom.xml new file mode 100644 index 0000000000..547c43dc27 --- /dev/null +++ b/parent-spring/pom.xml @@ -0,0 +1,36 @@ + + 4.0.0 + com.baeldung + parent-spring + 0.0.1-SNAPSHOT + pom + parent-spring + Parent for all spring core modules + + + com.baeldung + parent-modules + 1.0.0-SNAPSHOT + + + + + org.springframework + spring-core + ${spring.version} + + + org.junit.jupiter + junit-jupiter-engine + ${junit.jupiter.version} + test + + + + + 4.3.6.RELEASE + 5.0.2 + + + \ No newline at end of file diff --git a/persistence-modules/java-cassandra/pom.xml b/persistence-modules/java-cassandra/pom.xml index 015fdc84de..610d6b8f09 100644 --- a/persistence-modules/java-cassandra/pom.xml +++ b/persistence-modules/java-cassandra/pom.xml @@ -8,9 +8,9 @@ com.baeldung - parent-modules - 1.0.0-SNAPSHOT - ../../ + parent-java + 0.0.1-SNAPSHOT + ../../parent-java @@ -29,13 +29,6 @@ ${cassandra-unit.version} - - - com.google.guava - guava - ${guava.version} - - diff --git a/persistence-modules/spring-data-cassandra/pom.xml b/persistence-modules/spring-data-cassandra/pom.xml index 540b7ad7b9..84165564ba 100644 --- a/persistence-modules/spring-data-cassandra/pom.xml +++ b/persistence-modules/spring-data-cassandra/pom.xml @@ -9,9 +9,9 @@ com.baeldung - parent-modules - 1.0.0-SNAPSHOT - ../../ + parent-spring + 0.0.1-SNAPSHOT + ../../parent-spring diff --git a/persistence-modules/spring-data-redis/pom.xml b/persistence-modules/spring-data-redis/pom.xml index 55f1124531..26d5c6bddf 100644 --- a/persistence-modules/spring-data-redis/pom.xml +++ b/persistence-modules/spring-data-redis/pom.xml @@ -9,9 +9,9 @@ com.baeldung - parent-modules - 1.0.0-SNAPSHOT - ../../ + parent-spring + 0.0.1-SNAPSHOT + ../../parent-spring diff --git a/persistence-modules/spring-data-solr/pom.xml b/persistence-modules/spring-data-solr/pom.xml index e687ee5f1f..f1c20344c1 100644 --- a/persistence-modules/spring-data-solr/pom.xml +++ b/persistence-modules/spring-data-solr/pom.xml @@ -10,9 +10,9 @@ com.baeldung - parent-modules - 1.0.0-SNAPSHOT - ../../ + parent-spring + 0.0.1-SNAPSHOT + ../../parent-spring diff --git a/pom.xml b/pom.xml index 98e7f76e86..22f1a82643 100644 --- a/pom.xml +++ b/pom.xml @@ -10,6 +10,8 @@ parent-boot-5 + parent-spring + parent-java asm atomix apache-cayenne @@ -285,6 +287,12 @@ ${junit.version} test + + org.junit.jupiter + junit-jupiter-engine + ${junit.jupiter.version} + test + org.hamcrest hamcrest-core @@ -516,6 +524,7 @@ 1.2 2.5.0 1.3 + 5.0.2 \ No newline at end of file diff --git a/rxjava/pom.xml b/rxjava/pom.xml index 41f2c3f6f6..72d2859330 100644 --- a/rxjava/pom.xml +++ b/rxjava/pom.xml @@ -8,8 +8,9 @@ com.baeldung - parent-modules - 1.0.0-SNAPSHOT + parent-java + 0.0.1-SNAPSHOT + ../parent-java @@ -65,12 +66,6 @@ assertj-core ${assertj.version} - - com.google.guava - guava - 22.0 - test - com.jakewharton.rxrelay2 rxrelay diff --git a/saas/pom.xml b/saas/pom.xml index 6b34b99a5d..bb951ceda8 100644 --- a/saas/pom.xml +++ b/saas/pom.xml @@ -9,8 +9,9 @@ com.baeldung - parent-modules - 1.0.0-SNAPSHOT + parent-java + 0.0.1-SNAPSHOT + ../parent-java @@ -24,11 +25,6 @@ fugue ${atlassian.fugue.version} - - com.google.guava - guava - ${guava.version} - diff --git a/spring-core/pom.xml b/spring-core/pom.xml index 2fa66a7929..93ff73bb37 100644 --- a/spring-core/pom.xml +++ b/spring-core/pom.xml @@ -1,108 +1,104 @@ + xmlns="http://maven.apache.org/POM/4.0.0" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - 4.0.0 - com.baeldung - spring-core - 0.0.1-SNAPSHOT - war - spring-core + 4.0.0 + com.baeldung + spring-core + 0.0.1-SNAPSHOT + war + spring-core - - com.baeldung - parent-modules - 1.0.0-SNAPSHOT - + + com.baeldung + parent-spring + 0.0.1-SNAPSHOT + ../parent-spring + - - - org.mockito - mockito-all - ${mockito.version} - - - org.springframework - spring-test - ${spring.version} - - - org.springframework - spring-core - ${spring.version} - - - org.springframework - spring-beans - ${spring.version} - - - org.springframework - spring-context - ${spring.version} - - - javax.inject - javax.inject - ${javax.inject.version} - - - com.google.guava - guava - ${guava.version} - - - org.projectlombok - lombok - ${lombok.version} - - - org.springframework.boot - spring-boot-starter - 1.5.2.RELEASE - - - org.springframework.boot - spring-boot-test - ${mockito.spring.boot.version} - test - - - commons-io - commons-io - ${commons.io.version} - - + + + org.mockito + mockito-all + ${mockito.version} + + + org.springframework + spring-test + ${spring.version} + + + org.springframework + spring-beans + ${spring.version} + + + org.springframework + spring-context + ${spring.version} + + + javax.inject + javax.inject + ${javax.inject.version} + + + com.google.guava + guava + ${guava.version} + + + org.projectlombok + lombok + ${lombok.version} + + + org.springframework.boot + spring-boot-starter + 1.5.2.RELEASE + + + org.springframework.boot + spring-boot-test + ${mockito.spring.boot.version} + test + + + commons-io + commons-io + ${commons.io.version} + + - - - - org.apache.maven.plugins - maven-war-plugin - ${maven-war-plugin.version} - - false - - - - + + + + org.apache.maven.plugins + maven-war-plugin + ${maven-war-plugin.version} + + false + + + + - - 1.10.19 - 1.4.4.RELEASE - 4.3.4.RELEASE - 1 - 20.0 - 2.6 - 1.16.12 - 2.5 - + + 1.10.19 + 1.4.4.RELEASE + 4.3.4.RELEASE + 1 + 20.0 + 2.6 + 1.16.12 + 2.5 + - - - java.net - https://maven.java.net/content/repositories/releases/ - - + + + java.net + https://maven.java.net/content/repositories/releases/ + + \ No newline at end of file diff --git a/spring-data-elasticsearch/pom.xml b/spring-data-elasticsearch/pom.xml index e314e7870e..804cf23a69 100644 --- a/spring-data-elasticsearch/pom.xml +++ b/spring-data-elasticsearch/pom.xml @@ -9,8 +9,9 @@ com.baeldung - parent-modules - 1.0.0-SNAPSHOT + parent-spring + 0.0.1-SNAPSHOT + ../parent-spring diff --git a/spring-data-mongodb/pom.xml b/spring-data-mongodb/pom.xml index 0ff8f3e9fd..24847aaec6 100644 --- a/spring-data-mongodb/pom.xml +++ b/spring-data-mongodb/pom.xml @@ -8,8 +8,9 @@ com.baeldung - parent-modules - 1.0.0-SNAPSHOT + parent-spring + 0.0.1-SNAPSHOT + ../parent-spring diff --git a/spring-dispatcher-servlet/pom.xml b/spring-dispatcher-servlet/pom.xml index 1d4d2b0d71..9fa02f157d 100644 --- a/spring-dispatcher-servlet/pom.xml +++ b/spring-dispatcher-servlet/pom.xml @@ -1,102 +1,98 @@ - 4.0.0 - com.baeldung - spring-dispatcher-servlet - war - 1.0.0 - spring-dispatcher-servlet + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" + xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + 4.0.0 + com.baeldung + spring-dispatcher-servlet + war + 1.0.0 + spring-dispatcher-servlet - - com.baeldung - parent-modules - 1.0.0-SNAPSHOT - + + com.baeldung + parent-spring + 0.0.1-SNAPSHOT + ../parent-spring + - - - org.springframework - spring-core - ${springframework.version} - - - org.springframework - spring-web - ${springframework.version} - - - org.springframework - spring-webmvc - ${springframework.version} - - - javax.servlet - javax.servlet-api - ${javax.servlet-api.version} - - - javax.servlet.jsp.jstl - jstl-api - ${jstl-api.version} - - - javax.servlet.jsp - javax.servlet.jsp-api - ${javax.servlet.jsp-api.version} - - - org.codehaus.jackson - jackson-mapper-asl - ${jackson-mapper-asl.version} - - - javax.servlet - jstl - ${jstl.version} - - - com.fasterxml.jackson.core - jackson-databind - ${jackson-databind.version} - - - commons-fileupload - commons-fileupload - ${commons-fileupload.version} - - + + + org.springframework + spring-web + ${spring.version} + + + org.springframework + spring-webmvc + ${spring.version} + + + javax.servlet + javax.servlet-api + ${javax.servlet-api.version} + + + javax.servlet.jsp.jstl + jstl-api + ${jstl-api.version} + + + javax.servlet.jsp + javax.servlet.jsp-api + ${javax.servlet.jsp-api.version} + + + org.codehaus.jackson + jackson-mapper-asl + ${jackson-mapper-asl.version} + + + javax.servlet + jstl + ${jstl.version} + + + com.fasterxml.jackson.core + jackson-databind + ${jackson-databind.version} + + + commons-fileupload + commons-fileupload + ${commons-fileupload.version} + + - - spring-dispatcher-servlet - - - - org.apache.tomcat.maven - tomcat8-maven-plugin - ${tomcat8-maven-plugin.version} - - /springdispatcherservlet - - - - org.apache.maven.plugins - maven-war-plugin - ${maven-war-plugin.version} - - src/main/webapp - false - - - - - + + spring-dispatcher-servlet + + + + org.apache.tomcat.maven + tomcat8-maven-plugin + ${tomcat8-maven-plugin.version} + + /springdispatcherservlet + + + + org.apache.maven.plugins + maven-war-plugin + ${maven-war-plugin.version} + + src/main/webapp + false + + + + + - - 4.3.7.RELEASE - 3.0-r1655215 - 3.0.0 - + + 4.3.7.RELEASE + 3.0-r1655215 + 3.0.0 + \ No newline at end of file diff --git a/spring-groovy/pom.xml b/spring-groovy/pom.xml index f36d6cd22a..eec78d21a6 100644 --- a/spring-groovy/pom.xml +++ b/spring-groovy/pom.xml @@ -12,26 +12,12 @@ com.baeldung - parent-modules - 1.0.0-SNAPSHOT + parent-spring + 0.0.1-SNAPSHOT + ../parent-spring - - - UTF-8 - - + - - junit - junit - 3.8.1 - test - - - org.springframework - spring-core - 4.3.6.RELEASE - org.springframework.integration spring-integration-groovy @@ -71,4 +57,9 @@ + + + UTF-8 + + diff --git a/spring-mvc-simple/pom.xml b/spring-mvc-simple/pom.xml index 2f2d1e9dca..07d7221048 100644 --- a/spring-mvc-simple/pom.xml +++ b/spring-mvc-simple/pom.xml @@ -9,8 +9,9 @@ com.baeldung - parent-modules - 1.0.0-SNAPSHOT + parent-spring + 0.0.1-SNAPSHOT + ../parent-spring @@ -95,12 +96,6 @@ ${springframework.version} test - - org.junit.jupiter - junit-jupiter-engine - ${junit.jupiter.version} - test - com.rometools rome @@ -180,7 +175,6 @@ 2.3.27-incubating 1.2.5 5.0.2 - 5.0.2 1.0.2 1.9.0 2.9.4 diff --git a/spring-mvc-tiles/pom.xml b/spring-mvc-tiles/pom.xml index a62a92aad8..94908d5d8b 100644 --- a/spring-mvc-tiles/pom.xml +++ b/spring-mvc-tiles/pom.xml @@ -9,10 +9,11 @@ Integrating Spring MVC with Apache Tiles - com.baeldung - parent-modules - 1.0.0-SNAPSHOT - + com.baeldung + parent-spring + 0.0.1-SNAPSHOT + ../parent-spring + diff --git a/spring-mvc-velocity/pom.xml b/spring-mvc-velocity/pom.xml index 1a1ee66a1a..07d7182b7d 100644 --- a/spring-mvc-velocity/pom.xml +++ b/spring-mvc-velocity/pom.xml @@ -1,154 +1,150 @@ - 4.0.0 - com.baeldung - 0.1-SNAPSHOT - spring-mvc-velocity + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 + com.baeldung + 0.1-SNAPSHOT + spring-mvc-velocity - spring-mvc-velocity - war + spring-mvc-velocity + war - - com.baeldung - parent-modules - 1.0.0-SNAPSHOT - + + com.baeldung + parent-spring + 0.0.1-SNAPSHOT + ../parent-spring + - + - + - - org.springframework - spring-web - ${org.springframework.version} - - - org.springframework - spring-webmvc - ${org.springframework.version} - - - org.springframework - spring-core - ${org.springframework.version} - - - org.springframework - spring-context-support - ${org.springframework.version} - + + org.springframework + spring-web + ${spring.version} + + + org.springframework + spring-webmvc + ${spring.version} + + + org.springframework + spring-context-support + ${spring.version} + - + - - javax.servlet - javax.servlet-api - ${javax.servlet-api.version} - provided - + + javax.servlet + javax.servlet-api + ${javax.servlet-api.version} + provided + - - org.apache.velocity - velocity - ${velocity.version} - + + org.apache.velocity + velocity + ${velocity.version} + - - org.apache.velocity - velocity-tools - ${velocity-tools.version} - - - commons-logging - commons-logging - - - + + org.apache.velocity + velocity-tools + ${velocity-tools.version} + + + commons-logging + commons-logging + + + - - - org.powermock - powermock-module-junit4 - ${powermock.version} - test - - - org.powermock - powermock-api-mockito - ${powermock.version} - test - - - org.springframework - spring-test - ${org.springframework.version} - test - + + + org.powermock + powermock-module-junit4 + ${powermock.version} + test + + + org.powermock + powermock-api-mockito + ${powermock.version} + test + + + org.springframework + spring-test + ${spring.version} + test + - + - - spring-mvc-velocity - - - src/main/resources - true - - + + spring-mvc-velocity + + + src/main/resources + true + + - + - - org.apache.maven.plugins - maven-war-plugin - ${maven-war-plugin.version} - - false - - + + org.apache.maven.plugins + maven-war-plugin + ${maven-war-plugin.version} + + false + + - - org.apache.maven.plugins - maven-surefire-plugin - - 3 - true - - **/*IntegrationTest.java - - - - - - + + org.apache.maven.plugins + maven-surefire-plugin + + 3 + true + + **/*IntegrationTest.java + + + + + + - + - + - - - 4.3.4.RELEASE + + + 4.3.4.RELEASE - - 1.6.6 + + 1.6.6 - 4.4.5 - 4.5.2 + 4.4.5 + 4.5.2 - 3.1.0 - 1.7 - 2.0 - 2.9.0 + 3.1.0 + 1.7 + 2.0 + 2.9.0 - - 2.6 - 2.7 - 1.6.1 + + 2.6 + 2.7 + 1.6.1 - + \ No newline at end of file diff --git a/spring-rest-embedded-tomcat/pom.xml b/spring-rest-embedded-tomcat/pom.xml index 97fc3274af..9ab9b4b718 100644 --- a/spring-rest-embedded-tomcat/pom.xml +++ b/spring-rest-embedded-tomcat/pom.xml @@ -7,24 +7,15 @@ spring-rest-embedded-tomcat war + com.baeldung - parent-modules - 1.0.0-SNAPSHOT + parent-spring + 0.0.1-SNAPSHOT + ../parent-spring + - - junit - junit - ${junit.version} - test - - - - org.springframework - spring-core - ${spring.version} - org.springframework spring-webmvc @@ -96,7 +87,6 @@ 5.0.2.RELEASE 2.19.1 - 4.12 2.9.2 1.8 1.8 diff --git a/spring-security-mvc-custom/pom.xml b/spring-security-mvc-custom/pom.xml index 2ca383bdab..a320f6b137 100644 --- a/spring-security-mvc-custom/pom.xml +++ b/spring-security-mvc-custom/pom.xml @@ -1,225 +1,225 @@ - 4.0.0 - com.baeldung - spring-security-mvc-custom - 0.1-SNAPSHOT + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 + com.baeldung + spring-security-mvc-custom + 0.1-SNAPSHOT + spring-security-mvc-custom + war - spring-security-mvc-custom - war + + com.baeldung + parent-spring + 0.0.1-SNAPSHOT + ../parent-spring + - - com.baeldung - parent-modules - 1.0.0-SNAPSHOT - + - + - + + org.springframework.security + spring-security-web + ${org.springframework.security.version} + + + org.springframework.security + spring-security-config + ${org.springframework.security.version} + + + org.springframework.security + spring-security-taglibs + ${org.springframework.security.version} + - - org.springframework.security - spring-security-web - ${org.springframework.security.version} - - - org.springframework.security - spring-security-config - ${org.springframework.security.version} - - - org.springframework.security - spring-security-taglibs - ${org.springframework.security.version} - + - + + org.springframework + spring-core + ${spring.version} + + + commons-logging + commons-logging + + + + + org.springframework + spring-context + ${spring.version} + + + org.springframework + spring-jdbc + ${spring.version} + + + org.springframework + spring-beans + ${spring.version} + + + org.springframework + spring-aop + ${spring.version} + + + org.springframework + spring-tx + ${spring.version} + + + org.springframework + spring-expression + ${spring.version} + - - org.springframework - spring-core - ${org.springframework.version} - - - commons-logging - commons-logging - - - - - org.springframework - spring-context - ${org.springframework.version} - - - org.springframework - spring-jdbc - ${org.springframework.version} - - - org.springframework - spring-beans - ${org.springframework.version} - - - org.springframework - spring-aop - ${org.springframework.version} - - - org.springframework - spring-tx - ${org.springframework.version} - - - org.springframework - spring-expression - ${org.springframework.version} - + + org.springframework + spring-web + ${spring.version} + + + org.springframework + spring-webmvc + ${spring.version} + - - org.springframework - spring-web - ${org.springframework.version} - - - org.springframework - spring-webmvc - ${org.springframework.version} - + - + + javax.servlet + javax.servlet-api + ${javax.servlet.version} + provided + - - javax.servlet - javax.servlet-api - ${javax.servlet.version} - provided - + + javax.servlet + jstl + ${jstl.version} + runtime + - - javax.servlet - jstl - ${jstl.version} - runtime - + - + + + + + - - - - - + + + com.fasterxml.jackson.core + jackson-databind + ${jackson-databind.version} + - - - com.fasterxml.jackson.core - jackson-databind - ${jackson-databind.version} - + + org.apache.commons + commons-lang3 + ${commons-lang3.version} + - - org.apache.commons - commons-lang3 - ${commons-lang3.version} - + + com.google.guava + guava + ${guava.version} + - - com.google.guava - guava - ${guava.version} - + - + + org.springframework + spring-test + ${spring.version} + test + - - org.springframework - spring-test - ${org.springframework.version} - test - + + org.springframework.security + spring-security-test + ${org.springframework.security.version} + test + + - - org.springframework.security - spring-security-test - ${org.springframework.security.version} - test - - + + spring-security-mvc-custom + + + src/main/resources + true + + - - spring-security-mvc-custom - - - src/main/resources - true - - + - + + org.apache.maven.plugins + maven-war-plugin + ${maven-war-plugin.version} + - - org.apache.maven.plugins - maven-war-plugin - ${maven-war-plugin.version} - + + org.codehaus.cargo + cargo-maven2-plugin + ${cargo-maven2-plugin.version} + + true + + jetty8x + embedded + + + + + + + 8082 + + + + - - org.codehaus.cargo - cargo-maven2-plugin - ${cargo-maven2-plugin.version} - - true - - jetty8x - embedded - - - - - - - 8082 - - - - + - + - + + + 4.3.4.RELEASE + 4.2.0.RELEASE - - - 4.3.4.RELEASE - 4.2.0.RELEASE + + 5.2.5.Final + 5.1.40 - - 5.2.5.Final - 5.1.40 + + 5.3.3.Final + 3.1.0 + 1.2 - - 5.3.3.Final - 3.1.0 - 1.2 + + 19.0 + 3.5 + 2.9.1 - - 19.0 - 3.5 - 2.9.1 + 4.5.2 + 4.4.5 - 4.5.2 - 4.4.5 + 2.9.0 - 2.9.0 + + 2.6 + 2.7 + 1.6.1 - - 2.6 - 2.7 - 1.6.1 - - + \ No newline at end of file diff --git a/spring-security-mvc-digest-auth/pom.xml b/spring-security-mvc-digest-auth/pom.xml index 8ea270cc9d..9387220b2a 100644 --- a/spring-security-mvc-digest-auth/pom.xml +++ b/spring-security-mvc-digest-auth/pom.xml @@ -9,10 +9,11 @@ war - com.baeldung - parent-modules - 1.0.0-SNAPSHOT - + com.baeldung + parent-spring + 0.0.1-SNAPSHOT + ../parent-spring + diff --git a/spring-security-mvc-login/pom.xml b/spring-security-mvc-login/pom.xml index e391bdfb60..ee11bf067c 100644 --- a/spring-security-mvc-login/pom.xml +++ b/spring-security-mvc-login/pom.xml @@ -9,10 +9,11 @@ war - com.baeldung - parent-modules - 1.0.0-SNAPSHOT - + com.baeldung + parent-spring + 0.0.1-SNAPSHOT + ../parent-spring + diff --git a/spring-security-mvc-persisted-remember-me/pom.xml b/spring-security-mvc-persisted-remember-me/pom.xml index e5c5e78bd4..5c3ac4b7c4 100644 --- a/spring-security-mvc-persisted-remember-me/pom.xml +++ b/spring-security-mvc-persisted-remember-me/pom.xml @@ -9,10 +9,11 @@ war - com.baeldung - parent-modules - 1.0.0-SNAPSHOT - + com.baeldung + parent-spring + 0.0.1-SNAPSHOT + ../parent-spring + diff --git a/spring-security-mvc-session/pom.xml b/spring-security-mvc-session/pom.xml index 995f089d37..130778151f 100644 --- a/spring-security-mvc-session/pom.xml +++ b/spring-security-mvc-session/pom.xml @@ -9,10 +9,11 @@ war - com.baeldung - parent-modules - 1.0.0-SNAPSHOT - + com.baeldung + parent-spring + 0.0.1-SNAPSHOT + ../parent-spring + diff --git a/spring-security-mvc-socket/pom.xml b/spring-security-mvc-socket/pom.xml index 931528811a..6168740cb7 100644 --- a/spring-security-mvc-socket/pom.xml +++ b/spring-security-mvc-socket/pom.xml @@ -9,10 +9,11 @@ war - com.baeldung - parent-modules - 1.0.0-SNAPSHOT - + com.baeldung + parent-spring + 0.0.1-SNAPSHOT + ../parent-spring + diff --git a/spring-security-rest-basic-auth/pom.xml b/spring-security-rest-basic-auth/pom.xml index bfa8c1c7b9..bed3cd033d 100644 --- a/spring-security-rest-basic-auth/pom.xml +++ b/spring-security-rest-basic-auth/pom.xml @@ -9,10 +9,11 @@ war - com.baeldung - parent-modules - 1.0.0-SNAPSHOT - + com.baeldung + parent-spring + 0.0.1-SNAPSHOT + ../parent-spring + diff --git a/spring-security-rest/pom.xml b/spring-security-rest/pom.xml index 242b104c4a..e29012a3a5 100644 --- a/spring-security-rest/pom.xml +++ b/spring-security-rest/pom.xml @@ -9,10 +9,11 @@ war - com.baeldung - parent-modules - 1.0.0-SNAPSHOT - + com.baeldung + parent-spring + 0.0.1-SNAPSHOT + ../parent-spring + diff --git a/spring-userservice/pom.xml b/spring-userservice/pom.xml index 9cbc3d7ed2..872b8ed352 100644 --- a/spring-userservice/pom.xml +++ b/spring-userservice/pom.xml @@ -7,10 +7,11 @@ war - com.baeldung - parent-modules - 1.0.0-SNAPSHOT - + com.baeldung + parent-spring + 0.0.1-SNAPSHOT + ../parent-spring + diff --git a/struts-2/pom.xml b/struts-2/pom.xml index 44cb6dae3d..bb23600446 100644 --- a/struts-2/pom.xml +++ b/struts-2/pom.xml @@ -8,10 +8,11 @@ struts - com.baeldung - parent-modules - 1.0.0-SNAPSHOT - + com.baeldung + parent-spring + 0.0.1-SNAPSHOT + ../parent-spring + src/main/java diff --git a/testing-modules/junit-5/pom.xml b/testing-modules/junit-5/pom.xml index dd1486be1d..cfffa29aec 100644 --- a/testing-modules/junit-5/pom.xml +++ b/testing-modules/junit-5/pom.xml @@ -17,21 +17,6 @@ ../../ - - UTF-8 - 1.8 - 5.1.0 - 1.0.1 - 4.12.1 - 2.8.2 - 1.4.196 - 2.11.0 - - 3.7.0 - 2.19.1 - 4.12 - 5.0.1.RELEASE - @@ -71,12 +56,6 @@ - - org.junit.jupiter - junit-jupiter-engine - ${junit.jupiter.version} - test - org.junit.platform junit-platform-runner @@ -99,12 +78,6 @@ h2 ${h2.version} - - junit - junit - ${junit4.version} - test - org.springframework spring-test @@ -119,4 +92,19 @@ + + UTF-8 + 1.8 + 5.1.0 + 1.0.1 + 4.12.1 + 2.8.2 + 1.4.196 + 2.11.0 + + 3.7.0 + 2.19.1 + 5.0.1.RELEASE + + diff --git a/testing-modules/mockito/pom.xml b/testing-modules/mockito/pom.xml index 3ba9fd0385..c2e5b4bf31 100644 --- a/testing-modules/mockito/pom.xml +++ b/testing-modules/mockito/pom.xml @@ -8,21 +8,15 @@ com.baeldung - parent-modules - 1.0.0-SNAPSHOT - ../../ + parent-java + 0.0.1-SNAPSHOT + ../../parent-java - - com.google.guava - guava - ${guava.version} - - org.apache.commons commons-lang3 diff --git a/testing-modules/rest-assured/pom.xml b/testing-modules/rest-assured/pom.xml index dc577b647b..3452cdae22 100644 --- a/testing-modules/rest-assured/pom.xml +++ b/testing-modules/rest-assured/pom.xml @@ -8,9 +8,9 @@ com.baeldung - parent-modules - 1.0.0-SNAPSHOT - ../../ + parent-java + 0.0.1-SNAPSHOT + ../../parent-java @@ -119,11 +119,6 @@ ${jackson-coreutils.version} - - com.google.guava - guava - ${guava.version} - com.github.fge btf diff --git a/testing-modules/rest-testing/pom.xml b/testing-modules/rest-testing/pom.xml index f9866496a4..8ebe86b9bb 100644 --- a/testing-modules/rest-testing/pom.xml +++ b/testing-modules/rest-testing/pom.xml @@ -9,21 +9,15 @@ com.baeldung - parent-modules - 1.0.0-SNAPSHOT - ../../ + parent-java + 0.0.1-SNAPSHOT + ../../parent-java - - com.google.guava - guava - ${guava.version} - - commons-io commons-io diff --git a/testing-modules/testing/pom.xml b/testing-modules/testing/pom.xml index ecef105b01..6cf7ee223f 100644 --- a/testing-modules/testing/pom.xml +++ b/testing-modules/testing/pom.xml @@ -8,9 +8,9 @@ com.baeldung - parent-modules - 1.0.0-SNAPSHOT - ../../ + parent-java + 0.0.1-SNAPSHOT + ../../parent-java @@ -19,11 +19,6 @@ lambda-behave 0.4 - - com.google.guava - guava - ${guava.version} - org.assertj assertj-guava diff --git a/undertow/dependency-reduced-pom.xml b/undertow/dependency-reduced-pom.xml new file mode 100644 index 0000000000..a4a17f94d6 --- /dev/null +++ b/undertow/dependency-reduced-pom.xml @@ -0,0 +1,90 @@ + + + + parent-modules + com.baeldung + 1.0.0-SNAPSHOT + + 4.0.0 + com.baeldung.undertow + undertow + undertow + 1.0-SNAPSHOT + http://maven.apache.org + + ${project.artifactId} + + + maven-shade-plugin + + + package + + shade + + + + + + maven-jar-plugin + + + + com.baeldung.undertow.SimpleServer + + + + + + + + + junit + junit + 4.12 + test + + + org.hamcrest + hamcrest-core + 1.3 + test + + + org.hamcrest + hamcrest-library + 1.3 + test + + + org.hamcrest + hamcrest-all + 1.3 + test + + + org.mockito + mockito-core + 2.8.9 + test + + + byte-buddy + net.bytebuddy + + + byte-buddy-agent + net.bytebuddy + + + objenesis + org.objenesis + + + + + + 1.8 + 1.8 + + diff --git a/video-tutorials/jackson-annotations/pom.xml b/video-tutorials/jackson-annotations/pom.xml index 59e14810dd..c315efa713 100644 --- a/video-tutorials/jackson-annotations/pom.xml +++ b/video-tutorials/jackson-annotations/pom.xml @@ -15,12 +15,6 @@ - - com.google.guava - guava - ${guava.version} - - commons-io commons-io diff --git a/video-tutorials/pom.xml b/video-tutorials/pom.xml index ceabfa6a3b..cbaf5e3680 100644 --- a/video-tutorials/pom.xml +++ b/video-tutorials/pom.xml @@ -10,8 +10,9 @@ com.baeldung - parent-modules - 1.0.0-SNAPSHOT + parent-java + 0.0.1-SNAPSHOT + ../parent-java From fd76b01251518f6ce0c667f8654accfe21f9969c Mon Sep 17 00:00:00 2001 From: Eric Goebelbecker Date: Sat, 5 May 2018 17:57:19 -0400 Subject: [PATCH 37/66] BAEL-1710 - A Guide to Logback (#4178) --- logging-modules/README.md | 1 + .../com/baeldung/logback/LogbackTests.java | 89 +++++++++++++++++++ .../src/test/resources/logback-guide.xml | 32 +++++++ 3 files changed, 122 insertions(+) create mode 100644 logging-modules/logback/src/test/java/com/baeldung/logback/LogbackTests.java create mode 100644 logging-modules/logback/src/test/resources/logback-guide.xml diff --git a/logging-modules/README.md b/logging-modules/README.md index 6de71adb43..a589b1245c 100644 --- a/logging-modules/README.md +++ b/logging-modules/README.md @@ -5,3 +5,4 @@ - [Creating a Custom Logback Appender](http://www.baeldung.com/custom-logback-appender) - [Get Log Output in JSON Format](http://www.baeldung.com/java-log-json-output) +- [A Guide To Logback](http://www.baeldung.com/a-guide-to-logback) diff --git a/logging-modules/logback/src/test/java/com/baeldung/logback/LogbackTests.java b/logging-modules/logback/src/test/java/com/baeldung/logback/LogbackTests.java new file mode 100644 index 0000000000..85201965dc --- /dev/null +++ b/logging-modules/logback/src/test/java/com/baeldung/logback/LogbackTests.java @@ -0,0 +1,89 @@ +package com.baeldung.logback; + +import ch.qos.logback.classic.Level; +import org.junit.Test; + +import ch.qos.logback.classic.Logger; +import org.slf4j.LoggerFactory; + +public class LogbackTests { + + @Test + public void givenLogHierarchy_MessagesFiltered() { + + ch.qos.logback.classic.Logger parentLogger = + (ch.qos.logback.classic.Logger) LoggerFactory.getLogger("com.baeldung.logback"); + + parentLogger.setLevel(Level.INFO); + + Logger childlogger = (ch.qos.logback.classic.Logger)LoggerFactory.getLogger("com.baeldung.logback.tests"); + + parentLogger.warn("This message is logged because WARN > INFO."); + + // This request is disabled, because DEBUG < INFO. + parentLogger.debug("This message is not logged because DEBUG < INFO."); + + childlogger.info("INFO == INFO"); + + childlogger.debug("DEBUG < INFO"); + + } + + @Test + public void givenRootLevel_MessagesFiltered() { + + ch.qos.logback.classic.Logger logger = + (ch.qos.logback.classic.Logger) LoggerFactory.getLogger("com.baeldung.logback"); + + logger.debug("Hi there!"); + + Logger rootLogger = (ch.qos.logback.classic.Logger)LoggerFactory.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME); + + logger.debug("This message is logged because DEBUG == DEBUG."); + + rootLogger.setLevel(Level.ERROR); + logger.warn("This message is not logged because WARN < ERROR."); + + logger.error("This is logged."); + + } + + @Test + public void givenParameters_ValuesLogged() { + + Logger logger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(LogbackTests.class); + + String message = "This is a String"; + Integer zero = 0; + + try { + logger.debug("Logging message: {}", message); + logger.debug("Going to divide {} by {}", 42, zero); + int result = 42 / zero; + } catch (Exception e) { + logger.error("Error dividing {} by {} ", 42, zero, e); + } + } + + @Test + public void givenConfig_MessageFiltered() { + + Logger foobar = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger("com.baeldung.foobar"); + Logger logger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger("com.baeldung.logback"); + Logger testslogger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger("com.baeldung.logback.tests"); + + foobar.debug("This is logged from foobar"); + logger.debug("This is not logged from logger"); + logger.info("This is logged from logger"); + testslogger.info("This is not logged from tests"); + testslogger.warn("This is logged from tests"); + + + } + + + + + + +} diff --git a/logging-modules/logback/src/test/resources/logback-guide.xml b/logging-modules/logback/src/test/resources/logback-guide.xml new file mode 100644 index 0000000000..8331f1cb93 --- /dev/null +++ b/logging-modules/logback/src/test/resources/logback-guide.xml @@ -0,0 +1,32 @@ + + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + tests.log + true + + true + + + %-4relative [%thread] %-5level %logger{35} - %msg%n + + + + + + + + + + + + + \ No newline at end of file From 1e1142b14596756cb5790062e6302e31d73b756b Mon Sep 17 00:00:00 2001 From: Alejandro Gervasio Date: Sat, 5 May 2018 23:41:08 -0300 Subject: [PATCH 38/66] The Command Pattern in Java - BAEL-1722 (#4048) * Initial Commit * Update pom.xml * Fix unit tests format * Fix unit test class name * Update OpenTextFileOPerationUnitTest.java * Delete OpenTextFileOPerationUnitTest.java * Delete OpenTextFileOPerationUnitTest.java * Add unit test class * Update TextFileOperationExecutorUnitTest.java * Update TextFileUnitTest.java --- patterns/behavioral-patterns/pom.xml | 14 +++- .../command/client/TextFileApplication.java | 19 ++++++ .../command/OpenTextFileOperation.java | 17 +++++ .../command/SaveTextFileOperation.java | 17 +++++ .../command/command/TextFileOperation.java | 8 +++ .../invoker/TextFileOperationExecutor.java | 15 ++++ .../pattern/command/receiver/TextFile.java | 34 ++++++++++ .../test/OpenTextFileOperationUnitTest.java | 16 +++++ .../test/SaveTextFileOperationUnitTest.java | 16 +++++ .../TextFileOperationExecutorUnitTest.java | 68 +++++++++++++++++++ .../command/test/TextFileUnitTest.java | 42 ++++++++++++ 11 files changed, 265 insertions(+), 1 deletion(-) create mode 100644 patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/command/client/TextFileApplication.java create mode 100644 patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/command/command/OpenTextFileOperation.java create mode 100644 patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/command/command/SaveTextFileOperation.java create mode 100644 patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/command/command/TextFileOperation.java create mode 100644 patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/command/invoker/TextFileOperationExecutor.java create mode 100644 patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/command/receiver/TextFile.java create mode 100644 patterns/behavioral-patterns/src/test/java/com/baeldung/pattern/command/test/OpenTextFileOperationUnitTest.java create mode 100644 patterns/behavioral-patterns/src/test/java/com/baeldung/pattern/command/test/SaveTextFileOperationUnitTest.java create mode 100644 patterns/behavioral-patterns/src/test/java/com/baeldung/pattern/command/test/TextFileOperationExecutorUnitTest.java create mode 100644 patterns/behavioral-patterns/src/test/java/com/baeldung/pattern/command/test/TextFileUnitTest.java diff --git a/patterns/behavioral-patterns/pom.xml b/patterns/behavioral-patterns/pom.xml index 03b138dfc4..435f07aa98 100644 --- a/patterns/behavioral-patterns/pom.xml +++ b/patterns/behavioral-patterns/pom.xml @@ -19,10 +19,22 @@ 4.12 test + + org.hamcrest + hamcrest-core + 1.3 + test + + + org.assertj + assertj-core + 3.8.0 + test + UTF-8 1.8 1.8 - + \ No newline at end of file diff --git a/patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/command/client/TextFileApplication.java b/patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/command/client/TextFileApplication.java new file mode 100644 index 0000000000..30dcf08e89 --- /dev/null +++ b/patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/command/client/TextFileApplication.java @@ -0,0 +1,19 @@ +package com.baeldung.pattern.command.client; + +import com.baeldung.pattern.command.command.OpenTextFileOperation; +import com.baeldung.pattern.command.command.SaveTextFileOperation; +import com.baeldung.pattern.command.command.TextFileOperation; +import com.baeldung.pattern.command.invoker.TextFileOperationExecutor; +import com.baeldung.pattern.command.receiver.TextFile; + +public class TextFileApplication { + + public static void main(String[] args) { + + TextFileOperation openTextFileOperation = new OpenTextFileOperation(new TextFile("file1.txt")); + TextFileOperation saveTextFileOperation = new SaveTextFileOperation(new TextFile("file2.txt")); + TextFileOperationExecutor textFileOperationExecutor = new TextFileOperationExecutor(); + System.out.println(textFileOperationExecutor.executeOperation(openTextFileOperation)); + System.out.println(textFileOperationExecutor.executeOperation(saveTextFileOperation)); + } +} diff --git a/patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/command/command/OpenTextFileOperation.java b/patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/command/command/OpenTextFileOperation.java new file mode 100644 index 0000000000..c90a162b88 --- /dev/null +++ b/patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/command/command/OpenTextFileOperation.java @@ -0,0 +1,17 @@ +package com.baeldung.pattern.command.command; + +import com.baeldung.pattern.command.receiver.TextFile; + +public class OpenTextFileOperation implements TextFileOperation { + + private final TextFile textFile; + + public OpenTextFileOperation(TextFile textFile) { + this.textFile = textFile; + } + + @Override + public String execute() { + return textFile.open(); + } +} diff --git a/patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/command/command/SaveTextFileOperation.java b/patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/command/command/SaveTextFileOperation.java new file mode 100644 index 0000000000..b908e2c44c --- /dev/null +++ b/patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/command/command/SaveTextFileOperation.java @@ -0,0 +1,17 @@ +package com.baeldung.pattern.command.command; + +import com.baeldung.pattern.command.receiver.TextFile; + +public class SaveTextFileOperation implements TextFileOperation { + + private final TextFile textFile; + + public SaveTextFileOperation(TextFile textFile) { + this.textFile = textFile; + } + + @Override + public String execute() { + return textFile.save(); + } +} diff --git a/patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/command/command/TextFileOperation.java b/patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/command/command/TextFileOperation.java new file mode 100644 index 0000000000..506bb23d99 --- /dev/null +++ b/patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/command/command/TextFileOperation.java @@ -0,0 +1,8 @@ +package com.baeldung.pattern.command.command; + +@FunctionalInterface +public interface TextFileOperation { + + String execute(); + +} diff --git a/patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/command/invoker/TextFileOperationExecutor.java b/patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/command/invoker/TextFileOperationExecutor.java new file mode 100644 index 0000000000..bd2213706e --- /dev/null +++ b/patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/command/invoker/TextFileOperationExecutor.java @@ -0,0 +1,15 @@ +package com.baeldung.pattern.command.invoker; + +import com.baeldung.pattern.command.command.TextFileOperation; +import java.util.ArrayList; +import java.util.List; + +public class TextFileOperationExecutor { + + private final List textFileOperations = new ArrayList<>(); + + public String executeOperation(TextFileOperation textFileOperation) { + textFileOperations.add(textFileOperation); + return textFileOperation.execute(); + } +} diff --git a/patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/command/receiver/TextFile.java b/patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/command/receiver/TextFile.java new file mode 100644 index 0000000000..c0b2d3c41e --- /dev/null +++ b/patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/command/receiver/TextFile.java @@ -0,0 +1,34 @@ +package com.baeldung.pattern.command.receiver; + +public class TextFile { + + private final String name; + + public TextFile(String name) { + this.name = name; + } + + public String open() { + return "Opening file " + name; + } + + public String read() { + return "Reading file " + name; + } + + public String write() { + return "Writing to file " + name; + } + + public String save() { + return "Saving file " + name; + } + + public String copy() { + return "Copying file " + name; + } + + public String paste() { + return "Pasting file " + name; + } +} diff --git a/patterns/behavioral-patterns/src/test/java/com/baeldung/pattern/command/test/OpenTextFileOperationUnitTest.java b/patterns/behavioral-patterns/src/test/java/com/baeldung/pattern/command/test/OpenTextFileOperationUnitTest.java new file mode 100644 index 0000000000..1c72bfdd2f --- /dev/null +++ b/patterns/behavioral-patterns/src/test/java/com/baeldung/pattern/command/test/OpenTextFileOperationUnitTest.java @@ -0,0 +1,16 @@ +package com.baeldung.pattern.command.test; + +import com.baeldung.pattern.command.command.OpenTextFileOperation; +import com.baeldung.pattern.command.command.TextFileOperation; +import com.baeldung.pattern.command.receiver.TextFile; +import org.junit.Test; +import static org.assertj.core.api.Assertions.*; + +public class OpenTextFileOperationUnitTest { + + @Test + public void givenOpenTextFileOperationIntance_whenCalledExecuteMethod_thenOneAssertion() { + TextFileOperation openTextFileOperation = new OpenTextFileOperation(new TextFile("file1.txt")); + assertThat(openTextFileOperation.execute()).isEqualTo("Opening file file1.txt"); + } +} diff --git a/patterns/behavioral-patterns/src/test/java/com/baeldung/pattern/command/test/SaveTextFileOperationUnitTest.java b/patterns/behavioral-patterns/src/test/java/com/baeldung/pattern/command/test/SaveTextFileOperationUnitTest.java new file mode 100644 index 0000000000..a7bc1f3025 --- /dev/null +++ b/patterns/behavioral-patterns/src/test/java/com/baeldung/pattern/command/test/SaveTextFileOperationUnitTest.java @@ -0,0 +1,16 @@ +package com.baeldung.pattern.command.test; + +import com.baeldung.pattern.command.command.SaveTextFileOperation; +import com.baeldung.pattern.command.command.TextFileOperation; +import com.baeldung.pattern.command.receiver.TextFile; +import org.junit.Test; +import static org.assertj.core.api.Assertions.*; + +public class SaveTextFileOperationUnitTest { + + @Test + public void givenSaveTextFileOperationIntance_whenCalledExecuteMethod_thenOneAssertion() { + TextFileOperation openTextFileOperation = new SaveTextFileOperation(new TextFile("file1.txt")); + assertThat(openTextFileOperation.execute()).isEqualTo("Saving file file1.txt"); + } +} diff --git a/patterns/behavioral-patterns/src/test/java/com/baeldung/pattern/command/test/TextFileOperationExecutorUnitTest.java b/patterns/behavioral-patterns/src/test/java/com/baeldung/pattern/command/test/TextFileOperationExecutorUnitTest.java new file mode 100644 index 0000000000..efafa0d8a2 --- /dev/null +++ b/patterns/behavioral-patterns/src/test/java/com/baeldung/pattern/command/test/TextFileOperationExecutorUnitTest.java @@ -0,0 +1,68 @@ +package com.baeldung.pattern.command.test; + +import com.baeldung.pattern.command.command.OpenTextFileOperation; +import com.baeldung.pattern.command.command.SaveTextFileOperation; +import com.baeldung.pattern.command.command.TextFileOperation; +import com.baeldung.pattern.command.invoker.TextFileOperationExecutor; +import com.baeldung.pattern.command.receiver.TextFile; +import java.util.function.Function; +import org.junit.Test; +import static org.assertj.core.api.Assertions.*; +import org.junit.BeforeClass; + +public class TextFileOperationExecutorUnitTest { + + private static TextFileOperationExecutor textFileOperationExecutor; + + + @BeforeClass + public static void setUpTextFileOperationExecutor() { + textFileOperationExecutor = new TextFileOperationExecutor(); + } + + @Test + public void givenTextFileOPerationExecutorInstance_whenCalledexecuteOperationWithOpenTextOperation_thenOneAssertion() { + TextFileOperation textFileOperation = new OpenTextFileOperation(new TextFile("file1.txt")); + assertThat(textFileOperationExecutor.executeOperation(textFileOperation)).isEqualTo("Opening file file1.txt"); + } + + @Test + public void givenTextFileOPerationExecutorInstance_whenCalledexecuteOperationWithSaveTextOperation_thenOneAssertion() { + TextFileOperation textFileOperation = new SaveTextFileOperation(new TextFile("file1.txt")); + assertThat(textFileOperationExecutor.executeOperation(textFileOperation)).isEqualTo("Saving file file1.txt"); + } + + @Test + public void givenTextFileOperationExecutorInstance_whenCalledexecuteOperationWithTextFileOpenLambda_thenOneAssertion() { + assertThat(textFileOperationExecutor.executeOperation(() -> {return "Opening file file1.txt";})).isEqualTo("Opening file file1.txt"); + } + + @Test + public void givenTextFileOperationExecutorInstance_whenCalledexecuteOperationWithTextFileSaveLambda_thenOneAssertion() { + assertThat(textFileOperationExecutor.executeOperation(() -> {return "Saving file file1.txt";})).isEqualTo("Saving file file1.txt"); + } + + @Test + public void givenTextFileOperationExecutorInstance_whenCalledexecuteOperationWithTextFileOpenMethodReferenceOfExistingObject_thenOneAssertion() { + TextFile textFile = new TextFile("file1.txt"); + assertThat(textFileOperationExecutor.executeOperation(textFile::open)).isEqualTo("Opening file file1.txt"); + } + + @Test + public void givenTextFileOperationExecutorInstance_whenCalledexecuteOperationWithTextFileSaveMethodReferenceOfExistingObject_thenOneAssertion() { + TextFile textFile = new TextFile("file1.txt"); + assertThat(textFileOperationExecutor.executeOperation(textFile::save)).isEqualTo("Saving file file1.txt"); + } + + @Test + public void givenOpenTextFileOperationExecuteMethodReference_whenCalledApplyMethod_thenOneAssertion() { + Function executeMethodReference = OpenTextFileOperation::execute; + assertThat(executeMethodReference.apply(new OpenTextFileOperation(new TextFile("file1.txt")))).isEqualTo("Opening file file1.txt"); + } + + @Test + public void givenSaveTextFileOperationExecuteMethodReference_whenCalledApplyMethod_thenOneAssertion() { + Function executeMethodReference = SaveTextFileOperation::execute; + assertThat(executeMethodReference.apply(new SaveTextFileOperation(new TextFile("file1.txt")))).isEqualTo("Saving file file1.txt"); + } +} diff --git a/patterns/behavioral-patterns/src/test/java/com/baeldung/pattern/command/test/TextFileUnitTest.java b/patterns/behavioral-patterns/src/test/java/com/baeldung/pattern/command/test/TextFileUnitTest.java new file mode 100644 index 0000000000..32b83897c9 --- /dev/null +++ b/patterns/behavioral-patterns/src/test/java/com/baeldung/pattern/command/test/TextFileUnitTest.java @@ -0,0 +1,42 @@ +package com.baeldung.pattern.command.test; + +import com.baeldung.pattern.command.receiver.TextFile; +import org.junit.Test; +import static org.assertj.core.api.Assertions.*; +import org.junit.BeforeClass; + +public class TextFileUnitTest { + + private static TextFile textFile; + + + @BeforeClass + public static void setUpTextFileInstance() { + textFile = new TextFile("file1.txt"); + } + + @Test + public void givenTextFileInstance_whenCalledopenMethod_thenOneAssertion() { + assertThat(textFile.open()).isEqualTo("Opening file file1.txt"); + } + + @Test + public void givenTextFileInstance_whenCalledwriteMethod_thenOneAssertion() { + assertThat(textFile.write()).isEqualTo("Writing to file file1.txt"); + } + + @Test + public void givenTextFileInstance_whenCalledsaveMethod_thenOneAssertion() { + assertThat(textFile.save()).isEqualTo("Saving file file1.txt"); + } + + @Test + public void givenTextFileInstance_whenCalledcopyMethod_thenOneAssertion() { + assertThat(textFile.copy()).isEqualTo("Copying file file1.txt"); + } + + @Test + public void givenTextFileInstance_whenCalledpasteMethod_thenOneAssertion() { + assertThat(textFile.paste()).isEqualTo("Pasting file file1.txt"); + } +} From 79b5b211c96c6f3fa1cb1123a716c277d351daf8 Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Sun, 6 May 2018 10:53:26 +0300 Subject: [PATCH 39/66] new parent project --- parent-boot-2/README.md | 1 + parent-boot-2/pom.xml | 120 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 121 insertions(+) create mode 100644 parent-boot-2/README.md create mode 100644 parent-boot-2/pom.xml diff --git a/parent-boot-2/README.md b/parent-boot-2/README.md new file mode 100644 index 0000000000..ff12555376 --- /dev/null +++ b/parent-boot-2/README.md @@ -0,0 +1 @@ +## Relevant articles: diff --git a/parent-boot-2/pom.xml b/parent-boot-2/pom.xml new file mode 100644 index 0000000000..a9c54dece9 --- /dev/null +++ b/parent-boot-2/pom.xml @@ -0,0 +1,120 @@ + + 4.0.0 + com.baeldung + parent-boot-2 + 0.0.1-SNAPSHOT + pom + Parent Boot 2 + Parent for all spring boot 2 modules + + + org.springframework.boot + spring-boot-starter-parent + 2.0.1.RELEASE + + + + + + junit + junit + test + + + io.rest-assured + rest-assured + ${rest-assured.version} + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + org.apache.maven.plugins + maven-surefire-plugin + ${maven-surefire-plugin.version} + + 3 + true + + **/*IntegrationTest.java + **/*LongRunningUnitTest.java + **/*ManualTest.java + **/*LiveTest.java + + + + + org.apache.maven.plugins + maven-compiler-plugin + ${maven-compiler-plugin.version} + + ${maven.compiler.source} + ${maven.compiler.target} + + + + + + + + integration + + + + org.apache.maven.plugins + maven-surefire-plugin + + + integration-test + + test + + + + **/*ManualTest.java + **/*LiveTest.java + **/AutoconfigurationTest.java + **/*UnitTest.java + + + **/*IntegrationTest.java + */EthControllerTestOne.java + **/*IntTest.java + **/*EntryPointsTest.java + + + + + + + json + + + + + + + + + + UTF-8 + UTF-8 + 1.8 + 3.1.0 + + 1.8 + 1.8 + + + \ No newline at end of file From 4c861454c127030fb8f767cdbba679d08c12d6a2 Mon Sep 17 00:00:00 2001 From: collaboratewithakash <38683470+collaboratewithakash@users.noreply.github.com> Date: Sun, 6 May 2018 19:15:23 +0530 Subject: [PATCH 40/66] Back-link corrected (#4184) * Back-link corrected * Back-link corrected * Back-link corrected * Back-link corrected * Back-link corrected * Back-link corrected * Back-link corrected * Back-link corrected * Back-link corrected * Back-link added * Back-link corrected * Back-link added --- README.md | 1 + libraries/README.md | 2 +- spring-all/README.md | 2 +- spring-boot-cli/README.md | 2 +- spring-hibernate4/README.md | 2 +- spring-rest-full/README.md | 8 ++++---- spring-thymeleaf/README.md | 3 ++- testing-modules/rest-testing/README.md | 2 +- 8 files changed, 12 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 62d2d5b55e..1d916c8409 100644 --- a/README.md +++ b/README.md @@ -39,3 +39,4 @@ This tutorials project is being built **[>> HERE](https://rest-security.ci.cloud - [Apache Maven Standard Directory Layout](http://www.baeldung.com/maven-directory-structure) - [Apache Maven Tutorial](http://www.baeldung.com/maven) +- [Designing a User Friendly Java Library](http://www.baeldung.com/design-a-user-friendly-java-library) diff --git a/libraries/README.md b/libraries/README.md index 0080c2ad39..f197ab1270 100644 --- a/libraries/README.md +++ b/libraries/README.md @@ -65,7 +65,7 @@ - [Creating and Configuring Jetty 9 Server in Java](http://www.baeldung.com/jetty-java-programmatic) - [Introduction To OpenCSV](http://www.baeldung.com/opencsv) - [Introduction to Akka Actors in Java](http://www.baeldung.com/akka-actors-java) -- [Asynchronous HTTP with async-http-client in Java](https://github.com/eugenp/tutorials/tree/master/libraries) +- [Asynchronous HTTP with async-http-client in Java](http://www.baeldung.com/async-http-client) - [Introduction to Smooks](http://www.baeldung.com/smooks) - [WebSockets with AsyncHttpClient](http://www.baeldung.com/async-http-client-websockets) - [A Guide to Infinispan in Java](http://www.baeldung.com/infinispan) diff --git a/spring-all/README.md b/spring-all/README.md index 0902a11a77..e561eb265d 100644 --- a/spring-all/README.md +++ b/spring-all/README.md @@ -12,7 +12,7 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [Properties with Spring](http://www.baeldung.com/properties-with-spring) - checkout the `org.baeldung.properties` package for all scenarios of properties injection and usage - [Spring Profiles](http://www.baeldung.com/spring-profiles) - [A Spring Custom Annotation for a Better DAO](http://www.baeldung.com/spring-annotation-bean-pre-processor) -- [What's New in Spring 4.3?](http://www.baeldung.com/whats-new-in-spring-4-3/) +- [What's New in Spring 4.3?](http://www.baeldung.com/whats-new-in-spring-4-3) - [Guide To Running Logic on Startup in Spring](http://www.baeldung.com/running-setup-logic-on-startup-in-spring) - [Quick Guide to Spring Controllers](http://www.baeldung.com/spring-controllers) - [Quick Guide to Spring Bean Scopes](http://www.baeldung.com/spring-bean-scopes) diff --git a/spring-boot-cli/README.md b/spring-boot-cli/README.md index 4185415b39..85323da9b4 100644 --- a/spring-boot-cli/README.md +++ b/spring-boot-cli/README.md @@ -3,4 +3,4 @@ ## Spring Boot CLI ### Relevant Articles: -- [Introduction to Spring Boot CLI](http://www.baeldung.com/) +- [Introduction to Spring Boot CLI](http://www.baeldung.com/spring-boot-cli) diff --git a/spring-hibernate4/README.md b/spring-hibernate4/README.md index 2165fb67bc..88ee7fadd3 100644 --- a/spring-hibernate4/README.md +++ b/spring-hibernate4/README.md @@ -9,7 +9,7 @@ - [Sorting with Hibernate](http://www.baeldung.com/hibernate-sort) - [Auditing with JPA, Hibernate, and Spring Data JPA](http://www.baeldung.com/database-auditing-jpa) - [Stored Procedures with Hibernate](http://www.baeldung.com/stored-procedures-with-hibernate-tutorial) -- [Hibernate: save, persist, update, merge, saveOrUpdate](http://www.baeldung.com/hibernate-save-persist-update-merge-saveorupdate/) +- [Hibernate: save, persist, update, merge, saveOrUpdate](http://www.baeldung.com/hibernate-save-persist-update-merge-saveorupdate) - [Eager/Lazy Loading In Hibernate](http://www.baeldung.com/hibernate-lazy-eager-loading) - [Hibernate Criteria Queries](http://www.baeldung.com/hibernate-criteria-queries) - [Hibernate One to Many Annotation Tutorial](http://www.baeldung.com/hibernate-one-to-many) diff --git a/spring-rest-full/README.md b/spring-rest-full/README.md index b1917fb225..23b0b0435b 100644 --- a/spring-rest-full/README.md +++ b/spring-rest-full/README.md @@ -9,12 +9,12 @@ The "Learn Spring Security" Classes: http://github.learnspringsecurity.com ### Relevant Articles: - [REST Pagination in Spring](http://www.baeldung.com/rest-api-pagination-in-spring) -- [HATEOAS for a Spring REST Service](http://www.baeldung.com/2011/11/13/rest-service-discoverability-with-spring-part-5/) +- [HATEOAS for a Spring REST Service](http://www.baeldung.com/rest-api-discoverability-with-spring) - [REST API Discoverability and HATEOAS](http://www.baeldung.com/restful-web-service-discoverability) -- [ETags for REST with Spring](http://www.baeldung.com/2013/01/11/etags-for-rest-with-spring/) +- [ETags for REST with Spring](http://www.baeldung.com/etags-for-rest-with-spring) - [Integration Testing with the Maven Cargo plugin](http://www.baeldung.com/integration-testing-with-the-maven-cargo-plugin) -- [Introduction to Spring Data JPA](http://www.baeldung.com/2011/12/22/the-persistence-layer-with-spring-data-jpa/) -- [Project Configuration with Spring](http://www.baeldung.com/2012/03/12/project-configuration-with-spring/) +- [Introduction to Spring Data JPA](http://www.baeldung.com/the-persistence-layer-with-spring-data-jpa) +- [Project Configuration with Spring](http://www.baeldung.com/project-configuration-with-spring) - [Metrics for your Spring REST API](http://www.baeldung.com/spring-rest-api-metrics) - [Spring RestTemplate Tutorial](http://www.baeldung.com/rest-template) - [Bootstrap a Web Application with Spring 4](http://www.baeldung.com/bootstraping-a-web-application-with-spring-and-java-based-configuration) diff --git a/spring-thymeleaf/README.md b/spring-thymeleaf/README.md index 44393ac281..9346b74c89 100644 --- a/spring-thymeleaf/README.md +++ b/spring-thymeleaf/README.md @@ -10,9 +10,10 @@ - [Spring MVC + Thymeleaf 3.0: New Features](http://www.baeldung.com/spring-thymeleaf-3) - [How to Work with Dates in Thymeleaef](http://www.baeldung.com/dates-in-thymeleaf) - [How to Create an Executable JAR with Maven](http://www.baeldung.com/executable-jar-with-maven) -- [Working with Booleans in Thymeleaf](http://www.baeldung.com/working-with-booleans-in-thymeleaf) +- [Working with Boolean in Thymeleaf](http://www.baeldung.com/thymeleaf-boolean) - [Working with Fragments in Thymeleaf](http://www.baeldung.com/spring-thymeleaf-fragments) - [Conditionals in Thymeleaf](http://www.baeldung.com/spring-thymeleaf-conditionals) +- [Iteration in Thymeleaf](http://www.baeldung.com/thymeleaf-iteration) ### Build the Project diff --git a/testing-modules/rest-testing/README.md b/testing-modules/rest-testing/README.md index c6185de05f..ab038807bc 100644 --- a/testing-modules/rest-testing/README.md +++ b/testing-modules/rest-testing/README.md @@ -6,7 +6,7 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring ### Relevant Articles: -- [Test a REST API with Java](http://www.baeldung.com/2011/10/13/integration-testing-a-rest-api/) +- [Test a REST API with Java](http://www.baeldung.com/integration-testing-a-rest-api) - [Introduction to WireMock](http://www.baeldung.com/introduction-to-wiremock) - [REST API Testing with Cucumber](http://www.baeldung.com/cucumber-rest-api-testing) - [Testing a REST API with JBehave](http://www.baeldung.com/jbehave-rest-testing) From c0131fdd8a416b1dcecc50aa2d8bb28fa8f445a9 Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Sun, 6 May 2018 19:00:41 +0300 Subject: [PATCH 41/66] upgrade spring-rest module --- spring-rest/pom.xml | 7 ++- .../web/log/config/TaxiFareMVCConfig.java | 4 +- .../java/org/baeldung/config/WebConfig.java | 57 +++++++++++-------- 3 files changed, 38 insertions(+), 30 deletions(-) diff --git a/spring-rest/pom.xml b/spring-rest/pom.xml index 58d974cdba..d56eb9949b 100644 --- a/spring-rest/pom.xml +++ b/spring-rest/pom.xml @@ -8,9 +8,10 @@ war - spring-boot-starter-parent - org.springframework.boot - 2.0.1.RELEASE + parent-boot-2 + com.baeldung + 0.0.1-SNAPSHOT + ../parent-boot-2 diff --git a/spring-rest/src/main/java/com/baeldung/web/log/config/TaxiFareMVCConfig.java b/spring-rest/src/main/java/com/baeldung/web/log/config/TaxiFareMVCConfig.java index f433b4f3c7..8f1a000acc 100644 --- a/spring-rest/src/main/java/com/baeldung/web/log/config/TaxiFareMVCConfig.java +++ b/spring-rest/src/main/java/com/baeldung/web/log/config/TaxiFareMVCConfig.java @@ -4,10 +4,10 @@ import com.baeldung.web.log.app.TaxiFareRequestInterceptor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.config.annotation.InterceptorRegistry; -import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; @Configuration -public class TaxiFareMVCConfig extends WebMvcConfigurerAdapter { +public class TaxiFareMVCConfig implements WebMvcConfigurer { @Autowired private TaxiFareRequestInterceptor taxiFareRequestInterceptor; diff --git a/spring-rest/src/main/java/org/baeldung/config/WebConfig.java b/spring-rest/src/main/java/org/baeldung/config/WebConfig.java index 5a6f906204..b3e3cd179a 100644 --- a/spring-rest/src/main/java/org/baeldung/config/WebConfig.java +++ b/spring-rest/src/main/java/org/baeldung/config/WebConfig.java @@ -1,7 +1,15 @@ package org.baeldung.config; +import java.text.SimpleDateFormat; +import java.util.List; + import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; +import org.springframework.http.converter.HttpMessageConverter; +import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; +import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; +import org.springframework.http.converter.xml.MarshallingHttpMessageConverter; +import org.springframework.oxm.xstream.XStreamMarshaller; import org.springframework.web.servlet.config.annotation.EnableWebMvc; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; @@ -17,31 +25,30 @@ public class WebConfig implements WebMvcConfigurer { super(); } - // /* - @Override - public void configureMessageConverters(final List> messageConverters) { - final Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder(); - builder.indentOutput(true) - .dateFormat(new SimpleDateFormat("dd-MM-yyyy hh:mm")); - messageConverters.add(new MappingJackson2HttpMessageConverter(builder.build())); - // messageConverters.add(new MappingJackson2XmlHttpMessageConverter(builder.createXmlMapper(true).build())); - - // messageConverters.add(createXmlHttpMessageConverter()); - // messageConverters.add(new MappingJackson2HttpMessageConverter()); - - // messageConverters.add(new ProtobufHttpMessageConverter()); - super.configureMessageConverters(messageConverters); - } - - private HttpMessageConverter createXmlHttpMessageConverter() { - final MarshallingHttpMessageConverter xmlConverter = new MarshallingHttpMessageConverter(); - - final XStreamMarshaller xstreamMarshaller = new XStreamMarshaller(); - xmlConverter.setMarshaller(xstreamMarshaller); - xmlConverter.setUnmarshaller(xstreamMarshaller); - - return xmlConverter; - } + @Override + public void configureMessageConverters(final List> messageConverters) { + final Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder(); + builder.indentOutput(true) + .dateFormat(new SimpleDateFormat("dd-MM-yyyy hh:mm")); + messageConverters.add(new MappingJackson2HttpMessageConverter(builder.build())); + // messageConverters.add(new MappingJackson2XmlHttpMessageConverter(builder.createXmlMapper(true).build())); + + // messageConverters.add(createXmlHttpMessageConverter()); + // messageConverters.add(new MappingJackson2HttpMessageConverter()); + + // messageConverters.add(new ProtobufHttpMessageConverter()); + + } + + private HttpMessageConverter createXmlHttpMessageConverter() { + final MarshallingHttpMessageConverter xmlConverter = new MarshallingHttpMessageConverter(); + + final XStreamMarshaller xstreamMarshaller = new XStreamMarshaller(); + xmlConverter.setMarshaller(xstreamMarshaller); + xmlConverter.setUnmarshaller(xstreamMarshaller); + + return xmlConverter; + } */ } From b4d4d4ec08c15f1036fb683c21e0545570a5aa59 Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Sun, 6 May 2018 21:19:41 +0300 Subject: [PATCH 42/66] upgrade spring-boot project, extract auto-config, remove security --- pom.xml | 5 +- spring-boot-autoconfiguration/.gitignore | 5 + spring-boot-autoconfiguration/README.MD | 6 + spring-boot-autoconfiguration/pom.xml | 108 +++++++++ .../MySQLAutoconfiguration.java | 0 .../example/AutoconfigurationApplication.java | 5 +- .../autoconfiguration/example/MyUser.java | 0 .../example/MyUserRepository.java | 0 .../main/resources/META-INF/spring.factories | 0 .../src/main/resources/application.properties | 4 + .../src/main/resources/mysql.properties | 2 +- .../AutoconfigurationIntegrationTest.java | 0 spring-boot/.factorypath | 210 ++++++++++-------- spring-boot/pom.xml | 23 +- .../SpringBootAnnotatedApp.java | 4 +- .../SpringBootPlainApp.java | 4 +- .../ContactInfoValidator.java | 6 +- .../DynamicValidationApp.java | 4 +- .../ErrorHandlingApplication.java | 13 +- .../controllers/MyErrorController.java | 2 +- .../FailureAnalyzerApplication.java | 4 +- .../com/baeldung/git/CommitIdApplication.java | 4 +- .../InternationalizationApp.java | 4 +- .../config/MvcConfig.java | 4 +- .../src/main/java/com/baeldung/intro/App.java | 4 +- .../com/baeldung/rss/CustomContainer.java | 13 +- .../main/java/com/baeldung/rss/RssApp.java | 3 +- .../WarInitializerApplication.java | 2 +- .../baeldung/servlets/ApplicationMain.java | 6 +- .../configuration/WebMvcConfigure.java | 6 +- .../SpringRegistrationBeanServlet.java | 4 +- .../embedded/EmbeddedTomcatExample.java | 8 +- .../com/baeldung/shutdown/Application.java | 15 +- .../com/baeldung/toggle/FeaturesAspect.java | 5 +- .../com/baeldung/toggle/SalaryService.java | 2 +- .../baeldung/toggle/ToggleApplication.java | 4 +- .../com/baeldung/utils/UtilsApplication.java | 4 +- .../webjar/WebjarsdemoApplication.java | 4 +- .../java/org/baeldung/boot/Application.java | 4 +- .../org/baeldung/boot/config/WebConfig.java | 4 +- .../common/error/MyCustomErrorController.java | 2 +- .../MyServletContainerCustomizationBean.java | 10 +- .../org/baeldung/demo/DemoApplication.java | 3 +- .../demo/boottest/EmployeeRepository.java | 5 +- .../demo/boottest/EmployeeServiceImpl.java | 5 +- .../baeldung/demo/components/FooService.java | 2 +- .../baeldung/endpoints/CustomEndpoint.java | 35 --- .../org/baeldung/endpoints/ListEndpoints.java | 23 -- .../org/baeldung/endpoints/MyHealthCheck.java | 22 -- .../baeldung/main/SpringBootApplication.java | 9 +- .../ConfigPropertiesDemoApplication.java | 4 +- .../org/baeldung/service/LoginService.java | 5 - .../baeldung/service/LoginServiceImpl.java | 29 --- .../session/exception/Application.java | 4 +- .../client/MyStompSessionHandler.java | 5 +- .../DisplayBeanIntegrationTest.java | 2 +- ...nitializerApplicationIntegrationTest.java} | 2 +- .../toggle/ToggleIntegrationTest.java | 4 +- .../baeldung/SpringBootH2IntegrationTest.java | 2 +- .../SpringBootJPAIntegrationTest.java | 2 +- .../SpringBootProfileIntegrationTest.java | 2 +- .../EmployeeRepositoryIntegrationTest.java | 4 +- .../EmployeeServiceImplIntegrationTest.java | 4 +- 63 files changed, 321 insertions(+), 369 deletions(-) create mode 100644 spring-boot-autoconfiguration/.gitignore create mode 100644 spring-boot-autoconfiguration/README.MD create mode 100644 spring-boot-autoconfiguration/pom.xml rename {spring-boot => spring-boot-autoconfiguration}/src/main/java/com/baeldung/autoconfiguration/MySQLAutoconfiguration.java (100%) rename {spring-boot => spring-boot-autoconfiguration}/src/main/java/com/baeldung/autoconfiguration/example/AutoconfigurationApplication.java (73%) rename {spring-boot => spring-boot-autoconfiguration}/src/main/java/com/baeldung/autoconfiguration/example/MyUser.java (100%) rename {spring-boot => spring-boot-autoconfiguration}/src/main/java/com/baeldung/autoconfiguration/example/MyUserRepository.java (100%) rename {spring-boot => spring-boot-autoconfiguration}/src/main/resources/META-INF/spring.factories (100%) create mode 100644 spring-boot-autoconfiguration/src/main/resources/application.properties rename {spring-boot => spring-boot-autoconfiguration}/src/main/resources/mysql.properties (58%) rename {spring-boot => spring-boot-autoconfiguration}/src/test/java/com/baeldung/autoconfiguration/AutoconfigurationIntegrationTest.java (100%) delete mode 100644 spring-boot/src/main/java/org/baeldung/endpoints/CustomEndpoint.java delete mode 100644 spring-boot/src/main/java/org/baeldung/endpoints/ListEndpoints.java delete mode 100644 spring-boot/src/main/java/org/baeldung/endpoints/MyHealthCheck.java delete mode 100644 spring-boot/src/main/java/org/baeldung/service/LoginService.java delete mode 100644 spring-boot/src/main/java/org/baeldung/service/LoginServiceImpl.java rename spring-boot/src/test/java/com/baeldung/servletinitializer/{WarInitializerApplicationTest.java => WarInitializerApplicationIntegrationTest.java} (95%) diff --git a/pom.xml b/pom.xml index 22f1a82643..3ba6b0c8df 100644 --- a/pom.xml +++ b/pom.xml @@ -10,8 +10,9 @@ parent-boot-5 - parent-spring - parent-java + parent-boot-2 + parent-spring + parent-java asm atomix apache-cayenne diff --git a/spring-boot-autoconfiguration/.gitignore b/spring-boot-autoconfiguration/.gitignore new file mode 100644 index 0000000000..da7c2c5c0a --- /dev/null +++ b/spring-boot-autoconfiguration/.gitignore @@ -0,0 +1,5 @@ +/target/ +.settings/ +.classpath +.project + diff --git a/spring-boot-autoconfiguration/README.MD b/spring-boot-autoconfiguration/README.MD new file mode 100644 index 0000000000..a71af54dff --- /dev/null +++ b/spring-boot-autoconfiguration/README.MD @@ -0,0 +1,6 @@ +### The Course +The "REST With Spring" Classes: http://bit.ly/restwithspring + +### Relevant Articles: + +- [Create a Custom Auto-Configuration with Spring Boot](http://www.baeldung.com/spring-boot-custom-auto-configuration) \ No newline at end of file diff --git a/spring-boot-autoconfiguration/pom.xml b/spring-boot-autoconfiguration/pom.xml new file mode 100644 index 0000000000..2687fcd969 --- /dev/null +++ b/spring-boot-autoconfiguration/pom.xml @@ -0,0 +1,108 @@ + + 4.0.0 + com.baeldung + spring-boot-autoconfiguration + 0.0.1-SNAPSHOT + war + spring-boot-auto-configuration + This is simple boot application demonstrating a custom auto-configuration + + + parent-boot-2 + com.baeldung + 0.0.1-SNAPSHOT + ../parent-boot-2 + + + + + org.springframework.boot + spring-boot-starter-thymeleaf + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-data-jpa + + + org.springframework.boot + spring-boot-starter-test + test + + + + mysql + mysql-connector-java + 8.0.11 + + + + + spring-boot + + + src/main/resources + true + + + + + + + org.apache.maven.plugins + maven-war-plugin + + + + + + + + + autoconfiguration + + + + org.apache.maven.plugins + maven-surefire-plugin + + + integration-test + + test + + + + **/*LiveTest.java + **/*IntegrationTest.java + + + **/AutoconfigurationTest.java + + + + + + + json + + + + + + + + + + + 3.1.1 + 3.3.7-1 + 3.1.7 + 8.5.11 + + + \ No newline at end of file diff --git a/spring-boot/src/main/java/com/baeldung/autoconfiguration/MySQLAutoconfiguration.java b/spring-boot-autoconfiguration/src/main/java/com/baeldung/autoconfiguration/MySQLAutoconfiguration.java similarity index 100% rename from spring-boot/src/main/java/com/baeldung/autoconfiguration/MySQLAutoconfiguration.java rename to spring-boot-autoconfiguration/src/main/java/com/baeldung/autoconfiguration/MySQLAutoconfiguration.java diff --git a/spring-boot/src/main/java/com/baeldung/autoconfiguration/example/AutoconfigurationApplication.java b/spring-boot-autoconfiguration/src/main/java/com/baeldung/autoconfiguration/example/AutoconfigurationApplication.java similarity index 73% rename from spring-boot/src/main/java/com/baeldung/autoconfiguration/example/AutoconfigurationApplication.java rename to spring-boot-autoconfiguration/src/main/java/com/baeldung/autoconfiguration/example/AutoconfigurationApplication.java index f419dbf4fd..0c9d7060dd 100644 --- a/spring-boot/src/main/java/com/baeldung/autoconfiguration/example/AutoconfigurationApplication.java +++ b/spring-boot-autoconfiguration/src/main/java/com/baeldung/autoconfiguration/example/AutoconfigurationApplication.java @@ -1,15 +1,12 @@ package com.baeldung.autoconfiguration.example; -import javax.annotation.security.RolesAllowed; - import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class AutoconfigurationApplication { - @RolesAllowed("*") + public static void main(String[] args) { - System.setProperty("security.basic.enabled", "false"); SpringApplication.run(AutoconfigurationApplication.class, args); } } diff --git a/spring-boot/src/main/java/com/baeldung/autoconfiguration/example/MyUser.java b/spring-boot-autoconfiguration/src/main/java/com/baeldung/autoconfiguration/example/MyUser.java similarity index 100% rename from spring-boot/src/main/java/com/baeldung/autoconfiguration/example/MyUser.java rename to spring-boot-autoconfiguration/src/main/java/com/baeldung/autoconfiguration/example/MyUser.java diff --git a/spring-boot/src/main/java/com/baeldung/autoconfiguration/example/MyUserRepository.java b/spring-boot-autoconfiguration/src/main/java/com/baeldung/autoconfiguration/example/MyUserRepository.java similarity index 100% rename from spring-boot/src/main/java/com/baeldung/autoconfiguration/example/MyUserRepository.java rename to spring-boot-autoconfiguration/src/main/java/com/baeldung/autoconfiguration/example/MyUserRepository.java diff --git a/spring-boot/src/main/resources/META-INF/spring.factories b/spring-boot-autoconfiguration/src/main/resources/META-INF/spring.factories similarity index 100% rename from spring-boot/src/main/resources/META-INF/spring.factories rename to spring-boot-autoconfiguration/src/main/resources/META-INF/spring.factories diff --git a/spring-boot-autoconfiguration/src/main/resources/application.properties b/spring-boot-autoconfiguration/src/main/resources/application.properties new file mode 100644 index 0000000000..09df3b8f02 --- /dev/null +++ b/spring-boot-autoconfiguration/src/main/resources/application.properties @@ -0,0 +1,4 @@ +server.port=9090 + +spring.jpa.show-sql=true +spring.jpa.hibernate.ddl-auto = update diff --git a/spring-boot/src/main/resources/mysql.properties b/spring-boot-autoconfiguration/src/main/resources/mysql.properties similarity index 58% rename from spring-boot/src/main/resources/mysql.properties rename to spring-boot-autoconfiguration/src/main/resources/mysql.properties index 27092f852f..74f1ee1373 100644 --- a/spring-boot/src/main/resources/mysql.properties +++ b/spring-boot-autoconfiguration/src/main/resources/mysql.properties @@ -1,5 +1,5 @@ usemysql=local -mysql-hibernate.dialect=org.hibernate.dialect.MySQLDialect +mysql-hibernate.dialect=org.hibernate.dialect.MySQL5Dialect mysql-hibernate.show_sql=true mysql-hibernate.hbm2ddl.auto=create-drop \ No newline at end of file diff --git a/spring-boot/src/test/java/com/baeldung/autoconfiguration/AutoconfigurationIntegrationTest.java b/spring-boot-autoconfiguration/src/test/java/com/baeldung/autoconfiguration/AutoconfigurationIntegrationTest.java similarity index 100% rename from spring-boot/src/test/java/com/baeldung/autoconfiguration/AutoconfigurationIntegrationTest.java rename to spring-boot-autoconfiguration/src/test/java/com/baeldung/autoconfiguration/AutoconfigurationIntegrationTest.java diff --git a/spring-boot/.factorypath b/spring-boot/.factorypath index 60dbd696eb..88c3910e93 100644 --- a/spring-boot/.factorypath +++ b/spring-boot/.factorypath @@ -1,51 +1,50 @@ - - - - - - - - - + + + + + + + + + + + + + - - - - - - - + + + + + + - - - - - + + + + - + - + - - - - - - - - - - - - - - + + + + + + + + + + + - + @@ -53,53 +52,59 @@ - + - - - - + + + + + - - - - - - - - - - - + + + + + + + + + + + + + - + - - - - - - - - - - + + + + + + + + + + + + + + - - - - - - - - - + + + + + + + + @@ -108,47 +113,56 @@ - - - - + + + - - - + + + + + + + + + - - - - - - + + + + + + - + + + + + - - - + + + - + - - - - - - + + + + + + diff --git a/spring-boot/pom.xml b/spring-boot/pom.xml index 127ac455e1..afc80eb68b 100644 --- a/spring-boot/pom.xml +++ b/spring-boot/pom.xml @@ -9,10 +9,10 @@ This is simple boot application for Spring boot actuator test - parent-boot-5 + parent-boot-2 com.baeldung 0.0.1-SNAPSHOT - ../parent-boot-5 + ../parent-boot-2 @@ -33,11 +33,6 @@ spring-boot-starter-actuator - - org.springframework.boot - spring-boot-starter-security - - com.graphql-java graphql-spring-boot-starter @@ -78,7 +73,6 @@ com.h2database h2 - ${h2.version} @@ -125,22 +119,14 @@ provided - - mysql - mysql-connector-java - ${mysql-connector-java.version} - - org.springframework spring-websocket - ${spring.version} org.springframework spring-messaging - ${spring.version} @@ -186,7 +172,6 @@ pl.project13.maven git-commit-id-plugin - ${git-commit-id-plugin.version} @@ -233,16 +218,12 @@ org.baeldung.demo.DemoApplication - 4.3.4.RELEASE - 2.2.1 3.1.1 3.3.7-1 3.1.7 8.5.11 - 1.4.194 2.4.1.Final 1.9.0 - 6.0.6 \ No newline at end of file diff --git a/spring-boot/src/main/java/com/baeldung/annotation/servletcomponentscan/SpringBootAnnotatedApp.java b/spring-boot/src/main/java/com/baeldung/annotation/servletcomponentscan/SpringBootAnnotatedApp.java index 774eb69889..b4d416dd96 100644 --- a/spring-boot/src/main/java/com/baeldung/annotation/servletcomponentscan/SpringBootAnnotatedApp.java +++ b/spring-boot/src/main/java/com/baeldung/annotation/servletcomponentscan/SpringBootAnnotatedApp.java @@ -4,8 +4,6 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.web.servlet.ServletComponentScan; -import com.baeldung.autoconfiguration.MySQLAutoconfiguration; - /** * using the following annotations are equivalent: *
  • @@ -16,7 +14,7 @@ import com.baeldung.autoconfiguration.MySQLAutoconfiguration; * @ServletComponentScan(basePackageClasses = {AttrListener.class, HelloFilter.class, HelloServlet.class, EchoServlet.class}) *
*/ -@SpringBootApplication(exclude = MySQLAutoconfiguration.class) +@SpringBootApplication @ServletComponentScan("com.baeldung.annotation.servletcomponentscan.components") public class SpringBootAnnotatedApp { diff --git a/spring-boot/src/main/java/com/baeldung/annotation/servletcomponentscan/SpringBootPlainApp.java b/spring-boot/src/main/java/com/baeldung/annotation/servletcomponentscan/SpringBootPlainApp.java index 580498e831..8a39078aac 100644 --- a/spring-boot/src/main/java/com/baeldung/annotation/servletcomponentscan/SpringBootPlainApp.java +++ b/spring-boot/src/main/java/com/baeldung/annotation/servletcomponentscan/SpringBootPlainApp.java @@ -3,9 +3,7 @@ package com.baeldung.annotation.servletcomponentscan; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.ComponentScan; -import com.baeldung.autoconfiguration.MySQLAutoconfiguration; - -@SpringBootApplication(exclude = MySQLAutoconfiguration.class) +@SpringBootApplication @ComponentScan(basePackages = "com.baeldung.annotation.servletcomponentscan.components") public class SpringBootPlainApp { 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 0f8300a797..e079b9a665 100644 --- a/spring-boot/src/main/java/com/baeldung/dynamicvalidation/ContactInfoValidator.java +++ b/spring-boot/src/main/java/com/baeldung/dynamicvalidation/ContactInfoValidator.java @@ -2,7 +2,9 @@ package com.baeldung.dynamicvalidation; import com.baeldung.dynamicvalidation.dao.ContactInfoExpressionRepository; import com.baeldung.dynamicvalidation.model.ContactInfoExpression; -import org.apache.log4j.Logger; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.thymeleaf.util.StringUtils; @@ -13,7 +15,7 @@ import java.util.regex.Pattern; public class ContactInfoValidator implements ConstraintValidator { - private static final Logger LOG = Logger.getLogger(ContactInfoValidator.class); + private static final Logger LOG = LogManager.getLogger(ContactInfoValidator.class); @Autowired private ContactInfoExpressionRepository expressionRepository; diff --git a/spring-boot/src/main/java/com/baeldung/dynamicvalidation/DynamicValidationApp.java b/spring-boot/src/main/java/com/baeldung/dynamicvalidation/DynamicValidationApp.java index acdd836c8c..361a7b1c03 100644 --- a/spring-boot/src/main/java/com/baeldung/dynamicvalidation/DynamicValidationApp.java +++ b/spring-boot/src/main/java/com/baeldung/dynamicvalidation/DynamicValidationApp.java @@ -5,9 +5,7 @@ import javax.annotation.security.RolesAllowed; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -import com.baeldung.autoconfiguration.MySQLAutoconfiguration; - -@SpringBootApplication(exclude = MySQLAutoconfiguration.class) +@SpringBootApplication public class DynamicValidationApp { @RolesAllowed("*") public static void main(String[] args) { diff --git a/spring-boot/src/main/java/com/baeldung/errorhandling/ErrorHandlingApplication.java b/spring-boot/src/main/java/com/baeldung/errorhandling/ErrorHandlingApplication.java index 45f9de78e4..5dd55ef077 100644 --- a/spring-boot/src/main/java/com/baeldung/errorhandling/ErrorHandlingApplication.java +++ b/spring-boot/src/main/java/com/baeldung/errorhandling/ErrorHandlingApplication.java @@ -1,14 +1,10 @@ package com.baeldung.errorhandling; -import com.baeldung.autoconfiguration.MySQLAutoconfiguration; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.context.ApplicationContext; -import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; -import org.springframework.web.servlet.handler.HandlerMappingIntrospector; -@SpringBootApplication(exclude = {MySQLAutoconfiguration.class}) +@SpringBootApplication @ComponentScan(basePackages = "com.baeldung.errorhandling") public class ErrorHandlingApplication { @@ -16,11 +12,4 @@ public class ErrorHandlingApplication { System.setProperty("spring.profiles.active", "errorhandling"); SpringApplication.run(ErrorHandlingApplication.class, args); } - - @Bean(name = "mvcHandlerMappingIntrospector") - public HandlerMappingIntrospector mvcHandlerMappingIntrospector(ApplicationContext context) { - return new HandlerMappingIntrospector(context); - } - - } diff --git a/spring-boot/src/main/java/com/baeldung/errorhandling/controllers/MyErrorController.java b/spring-boot/src/main/java/com/baeldung/errorhandling/controllers/MyErrorController.java index caa335ed23..8bdfea74cd 100644 --- a/spring-boot/src/main/java/com/baeldung/errorhandling/controllers/MyErrorController.java +++ b/spring-boot/src/main/java/com/baeldung/errorhandling/controllers/MyErrorController.java @@ -1,6 +1,6 @@ package com.baeldung.errorhandling.controllers; -import org.springframework.boot.autoconfigure.web.ErrorController; +import org.springframework.boot.web.servlet.error.ErrorController; import org.springframework.http.HttpStatus; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; diff --git a/spring-boot/src/main/java/com/baeldung/failureanalyzer/FailureAnalyzerApplication.java b/spring-boot/src/main/java/com/baeldung/failureanalyzer/FailureAnalyzerApplication.java index 84c96feb92..3489732b6f 100644 --- a/spring-boot/src/main/java/com/baeldung/failureanalyzer/FailureAnalyzerApplication.java +++ b/spring-boot/src/main/java/com/baeldung/failureanalyzer/FailureAnalyzerApplication.java @@ -5,9 +5,7 @@ import javax.annotation.security.RolesAllowed; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -import com.baeldung.autoconfiguration.MySQLAutoconfiguration; - -@SpringBootApplication(exclude = MySQLAutoconfiguration.class) +@SpringBootApplication public class FailureAnalyzerApplication { @RolesAllowed("*") public static void main(String[] args) { diff --git a/spring-boot/src/main/java/com/baeldung/git/CommitIdApplication.java b/spring-boot/src/main/java/com/baeldung/git/CommitIdApplication.java index 4655e36f83..cd696eae70 100644 --- a/spring-boot/src/main/java/com/baeldung/git/CommitIdApplication.java +++ b/spring-boot/src/main/java/com/baeldung/git/CommitIdApplication.java @@ -6,9 +6,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; import org.springframework.core.io.ClassPathResource; -import com.baeldung.autoconfiguration.MySQLAutoconfiguration; - -@SpringBootApplication(scanBasePackages = { "com.baeldung.git" }, exclude = MySQLAutoconfiguration.class) +@SpringBootApplication(scanBasePackages = { "com.baeldung.git" }) public class CommitIdApplication { public static void main(String[] args) { SpringApplication.run(CommitIdApplication.class, args); diff --git a/spring-boot/src/main/java/com/baeldung/internationalization/InternationalizationApp.java b/spring-boot/src/main/java/com/baeldung/internationalization/InternationalizationApp.java index ca56437392..c92d1c32e6 100644 --- a/spring-boot/src/main/java/com/baeldung/internationalization/InternationalizationApp.java +++ b/spring-boot/src/main/java/com/baeldung/internationalization/InternationalizationApp.java @@ -5,9 +5,7 @@ import javax.annotation.security.RolesAllowed; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -import com.baeldung.autoconfiguration.MySQLAutoconfiguration; - -@SpringBootApplication(exclude = MySQLAutoconfiguration.class) +@SpringBootApplication public class InternationalizationApp { @RolesAllowed("*") public static void main(String[] args) { diff --git a/spring-boot/src/main/java/com/baeldung/internationalization/config/MvcConfig.java b/spring-boot/src/main/java/com/baeldung/internationalization/config/MvcConfig.java index 8a0b709e69..d93c826cfa 100644 --- a/spring-boot/src/main/java/com/baeldung/internationalization/config/MvcConfig.java +++ b/spring-boot/src/main/java/com/baeldung/internationalization/config/MvcConfig.java @@ -7,13 +7,13 @@ import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.LocaleResolver; import org.springframework.web.servlet.config.annotation.InterceptorRegistry; -import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; import org.springframework.web.servlet.i18n.LocaleChangeInterceptor; import org.springframework.web.servlet.i18n.SessionLocaleResolver; @Configuration @ComponentScan(basePackages = "com.baeldung.internationalization.config") -public class MvcConfig extends WebMvcConfigurerAdapter { +public class MvcConfig implements WebMvcConfigurer { @Bean public LocaleResolver localeResolver() { diff --git a/spring-boot/src/main/java/com/baeldung/intro/App.java b/spring-boot/src/main/java/com/baeldung/intro/App.java index b865deea29..b5d53f0da3 100644 --- a/spring-boot/src/main/java/com/baeldung/intro/App.java +++ b/spring-boot/src/main/java/com/baeldung/intro/App.java @@ -3,9 +3,7 @@ package com.baeldung.intro; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -import com.baeldung.autoconfiguration.MySQLAutoconfiguration; - -@SpringBootApplication(exclude = MySQLAutoconfiguration.class) +@SpringBootApplication public class App { public static void main(String[] args) { SpringApplication.run(App.class, args); diff --git a/spring-boot/src/main/java/com/baeldung/rss/CustomContainer.java b/spring-boot/src/main/java/com/baeldung/rss/CustomContainer.java index ee36ecdc51..aaa3188010 100644 --- a/spring-boot/src/main/java/com/baeldung/rss/CustomContainer.java +++ b/spring-boot/src/main/java/com/baeldung/rss/CustomContainer.java @@ -1,16 +1,17 @@ package com.baeldung.rss; -import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer; -import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer; +import org.springframework.boot.web.server.WebServerFactoryCustomizer; +import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory; import org.springframework.stereotype.Component; @Component -public class CustomContainer implements EmbeddedServletContainerCustomizer { +public class CustomContainer implements WebServerFactoryCustomizer { @Override - public void customize(ConfigurableEmbeddedServletContainer container) { - container.setPort(8080); - container.setContextPath(""); + public void customize(ConfigurableServletWebServerFactory factory) { + factory.setContextPath(""); + factory.setPort(8080); + } } \ No newline at end of file diff --git a/spring-boot/src/main/java/com/baeldung/rss/RssApp.java b/spring-boot/src/main/java/com/baeldung/rss/RssApp.java index 2add7ed421..d3d3d0241f 100644 --- a/spring-boot/src/main/java/com/baeldung/rss/RssApp.java +++ b/spring-boot/src/main/java/com/baeldung/rss/RssApp.java @@ -1,13 +1,12 @@ package com.baeldung.rss; -import com.baeldung.autoconfiguration.MySQLAutoconfiguration; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.ComponentScan; import javax.annotation.security.RolesAllowed; -@SpringBootApplication(exclude = MySQLAutoconfiguration.class) +@SpringBootApplication @ComponentScan(basePackages = "com.baeldung.rss") public class RssApp { diff --git a/spring-boot/src/main/java/com/baeldung/servletinitializer/WarInitializerApplication.java b/spring-boot/src/main/java/com/baeldung/servletinitializer/WarInitializerApplication.java index 237026780c..1faee5c488 100644 --- a/spring-boot/src/main/java/com/baeldung/servletinitializer/WarInitializerApplication.java +++ b/spring-boot/src/main/java/com/baeldung/servletinitializer/WarInitializerApplication.java @@ -5,7 +5,7 @@ import java.time.LocalDateTime; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; -import org.springframework.boot.web.support.SpringBootServletInitializer; +import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; diff --git a/spring-boot/src/main/java/com/baeldung/servlets/ApplicationMain.java b/spring-boot/src/main/java/com/baeldung/servlets/ApplicationMain.java index c8461e4efc..482e6f4b5a 100644 --- a/spring-boot/src/main/java/com/baeldung/servlets/ApplicationMain.java +++ b/spring-boot/src/main/java/com/baeldung/servlets/ApplicationMain.java @@ -3,11 +3,9 @@ package com.baeldung.servlets; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; -import org.springframework.boot.web.support.SpringBootServletInitializer; +import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; -import com.baeldung.autoconfiguration.MySQLAutoconfiguration; - -@SpringBootApplication(exclude = MySQLAutoconfiguration.class) +@SpringBootApplication public class ApplicationMain extends SpringBootServletInitializer { public static void main(String[] args) { diff --git a/spring-boot/src/main/java/com/baeldung/servlets/configuration/WebMvcConfigure.java b/spring-boot/src/main/java/com/baeldung/servlets/configuration/WebMvcConfigure.java index 8dea814bc7..e026f5c732 100644 --- a/spring-boot/src/main/java/com/baeldung/servlets/configuration/WebMvcConfigure.java +++ b/spring-boot/src/main/java/com/baeldung/servlets/configuration/WebMvcConfigure.java @@ -1,17 +1,17 @@ package com.baeldung.servlets.configuration; -import org.springframework.boot.web.support.ErrorPageFilter; +import org.springframework.boot.web.servlet.support.ErrorPageFilter; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.ViewResolver; import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer; import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; -import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; import org.springframework.web.servlet.resource.PathResourceResolver; import org.springframework.web.servlet.view.InternalResourceViewResolver; @Configuration -public class WebMvcConfigure extends WebMvcConfigurerAdapter { +public class WebMvcConfigure implements WebMvcConfigurer { @Bean public ViewResolver getViewResolver() { diff --git a/spring-boot/src/main/java/com/baeldung/servlets/servlets/springboot/SpringRegistrationBeanServlet.java b/spring-boot/src/main/java/com/baeldung/servlets/servlets/springboot/SpringRegistrationBeanServlet.java index e3c225d429..b34690b75e 100644 --- a/spring-boot/src/main/java/com/baeldung/servlets/servlets/springboot/SpringRegistrationBeanServlet.java +++ b/spring-boot/src/main/java/com/baeldung/servlets/servlets/springboot/SpringRegistrationBeanServlet.java @@ -9,8 +9,8 @@ import org.springframework.context.annotation.Configuration; public class SpringRegistrationBeanServlet { @Bean - public ServletRegistrationBean genericCustomServlet() { - ServletRegistrationBean bean = new ServletRegistrationBean(new GenericCustomServlet(), "/springregistrationbeanservlet/*"); + public ServletRegistrationBean genericCustomServlet() { + ServletRegistrationBean bean = new ServletRegistrationBean<>(new GenericCustomServlet(), "/springregistrationbeanservlet/*"); bean.setLoadOnStartup(1); return bean; } diff --git a/spring-boot/src/main/java/com/baeldung/servlets/servlets/springboot/embedded/EmbeddedTomcatExample.java b/spring-boot/src/main/java/com/baeldung/servlets/servlets/springboot/embedded/EmbeddedTomcatExample.java index 9e460d03a8..2e7a0d756a 100644 --- a/spring-boot/src/main/java/com/baeldung/servlets/servlets/springboot/embedded/EmbeddedTomcatExample.java +++ b/spring-boot/src/main/java/com/baeldung/servlets/servlets/springboot/embedded/EmbeddedTomcatExample.java @@ -1,7 +1,7 @@ package com.baeldung.servlets.servlets.springboot.embedded; -import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory; -import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory; +import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory; +import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -9,8 +9,8 @@ import org.springframework.context.annotation.Configuration; public class EmbeddedTomcatExample { @Bean - public EmbeddedServletContainerFactory servletContainer() { - TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory(); + public ConfigurableServletWebServerFactory servletContainer() { + TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory(); return tomcat; } } diff --git a/spring-boot/src/main/java/com/baeldung/shutdown/Application.java b/spring-boot/src/main/java/com/baeldung/shutdown/Application.java index 3d9c71a7b9..2225df8b34 100644 --- a/spring-boot/src/main/java/com/baeldung/shutdown/Application.java +++ b/spring-boot/src/main/java/com/baeldung/shutdown/Application.java @@ -1,16 +1,13 @@ package com.baeldung.shutdown; -import com.baeldung.autoconfiguration.MySQLAutoconfiguration; -import org.springframework.boot.ExitCodeGenerator; import org.springframework.boot.SpringApplication; +import org.springframework.boot.WebApplicationType; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; -import org.springframework.boot.system.ApplicationPidFileWriter; +import org.springframework.boot.context.ApplicationPidFileWriter; import org.springframework.context.ConfigurableApplicationContext; -import javax.annotation.security.RolesAllowed; - -@SpringBootApplication(exclude = MySQLAutoconfiguration.class) +@SpringBootApplication public class Application { public static void main(String[] args) { @@ -24,7 +21,7 @@ public class Application { private static void closeApplication() { - ConfigurableApplicationContext ctx = new SpringApplicationBuilder(Application.class).web(false).run(); + ConfigurableApplicationContext ctx = new SpringApplicationBuilder(Application.class).web(WebApplicationType.NONE).run(); System.out.println("Spring Boot application started"); ctx.getBean(TerminateBean.class); ctx.close(); @@ -32,7 +29,7 @@ public class Application { private static void exitApplication() { - ConfigurableApplicationContext ctx = new SpringApplicationBuilder(Application.class).web(false).run(); + ConfigurableApplicationContext ctx = new SpringApplicationBuilder(Application.class).web(WebApplicationType.NONE).run(); int exitCode = SpringApplication.exit(ctx, () -> { // return the error code @@ -45,7 +42,7 @@ public class Application { } private static void writePID() { - SpringApplicationBuilder app = new SpringApplicationBuilder(Application.class).web(false); + SpringApplicationBuilder app = new SpringApplicationBuilder(Application.class).web(WebApplicationType.NONE); app.build().addListeners(new ApplicationPidFileWriter("./bin/shutdown.pid")); app.run(); } diff --git a/spring-boot/src/main/java/com/baeldung/toggle/FeaturesAspect.java b/spring-boot/src/main/java/com/baeldung/toggle/FeaturesAspect.java index ed99f65006..04c6305780 100644 --- a/spring-boot/src/main/java/com/baeldung/toggle/FeaturesAspect.java +++ b/spring-boot/src/main/java/com/baeldung/toggle/FeaturesAspect.java @@ -1,6 +1,7 @@ package com.baeldung.toggle; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Aspect; @@ -10,7 +11,7 @@ import org.springframework.stereotype.Component; @Component public class FeaturesAspect { - private static final Logger LOG = Logger.getLogger(FeaturesAspect.class); + private static final Logger LOG = LogManager.getLogger(FeaturesAspect.class); @Around(value = "@within(featureAssociation) || @annotation(featureAssociation)") public Object checkAspect(ProceedingJoinPoint joinPoint, FeatureAssociation featureAssociation) throws Throwable { diff --git a/spring-boot/src/main/java/com/baeldung/toggle/SalaryService.java b/spring-boot/src/main/java/com/baeldung/toggle/SalaryService.java index df65033d6b..48a1ddf8d8 100644 --- a/spring-boot/src/main/java/com/baeldung/toggle/SalaryService.java +++ b/spring-boot/src/main/java/com/baeldung/toggle/SalaryService.java @@ -11,7 +11,7 @@ public class SalaryService { @FeatureAssociation(value = MyFeatures.EMPLOYEE_MANAGEMENT_FEATURE) public void increaseSalary(long id) { - Employee employee = employeeRepository.findOne(id); + Employee employee = employeeRepository.findById(id).orElse(null); employee.setSalary(employee.getSalary() + employee.getSalary() * 0.1); employeeRepository.save(employee); } diff --git a/spring-boot/src/main/java/com/baeldung/toggle/ToggleApplication.java b/spring-boot/src/main/java/com/baeldung/toggle/ToggleApplication.java index c269262ab2..27be6b7cca 100644 --- a/spring-boot/src/main/java/com/baeldung/toggle/ToggleApplication.java +++ b/spring-boot/src/main/java/com/baeldung/toggle/ToggleApplication.java @@ -5,9 +5,7 @@ import javax.annotation.security.RolesAllowed; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -import com.baeldung.autoconfiguration.MySQLAutoconfiguration; - -@SpringBootApplication(exclude = MySQLAutoconfiguration.class) +@SpringBootApplication public class ToggleApplication { @RolesAllowed("*") public static void main(String[] args) { diff --git a/spring-boot/src/main/java/com/baeldung/utils/UtilsApplication.java b/spring-boot/src/main/java/com/baeldung/utils/UtilsApplication.java index 4b00247c4a..ce3eae7ce0 100644 --- a/spring-boot/src/main/java/com/baeldung/utils/UtilsApplication.java +++ b/spring-boot/src/main/java/com/baeldung/utils/UtilsApplication.java @@ -6,9 +6,7 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.ComponentScan; -import com.baeldung.autoconfiguration.MySQLAutoconfiguration; - -@SpringBootApplication(exclude = MySQLAutoconfiguration.class) +@SpringBootApplication @ComponentScan(basePackages = "com.baeldung.utils") public class UtilsApplication { diff --git a/spring-boot/src/main/java/com/baeldung/webjar/WebjarsdemoApplication.java b/spring-boot/src/main/java/com/baeldung/webjar/WebjarsdemoApplication.java index 5038c7e5f7..2397861f1d 100644 --- a/spring-boot/src/main/java/com/baeldung/webjar/WebjarsdemoApplication.java +++ b/spring-boot/src/main/java/com/baeldung/webjar/WebjarsdemoApplication.java @@ -3,9 +3,7 @@ package com.baeldung.webjar; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -import com.baeldung.autoconfiguration.MySQLAutoconfiguration; - -@SpringBootApplication(exclude = MySQLAutoconfiguration.class) +@SpringBootApplication public class WebjarsdemoApplication { public static void main(String[] args) { diff --git a/spring-boot/src/main/java/org/baeldung/boot/Application.java b/spring-boot/src/main/java/org/baeldung/boot/Application.java index 78e95455b8..c1b6558b26 100644 --- a/spring-boot/src/main/java/org/baeldung/boot/Application.java +++ b/spring-boot/src/main/java/org/baeldung/boot/Application.java @@ -4,9 +4,7 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.ApplicationContext; -import com.baeldung.autoconfiguration.MySQLAutoconfiguration; - -@SpringBootApplication(exclude = MySQLAutoconfiguration.class) +@SpringBootApplication public class Application { private static ApplicationContext applicationContext; diff --git a/spring-boot/src/main/java/org/baeldung/boot/config/WebConfig.java b/spring-boot/src/main/java/org/baeldung/boot/config/WebConfig.java index caf88c3be7..6d8708b06a 100644 --- a/spring-boot/src/main/java/org/baeldung/boot/config/WebConfig.java +++ b/spring-boot/src/main/java/org/baeldung/boot/config/WebConfig.java @@ -7,12 +7,12 @@ import org.baeldung.boot.web.resolver.HeaderVersionArgumentResolver; import org.springframework.context.annotation.Configuration; import org.springframework.format.FormatterRegistry; import org.springframework.web.method.support.HandlerMethodArgumentResolver; -import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; import java.util.List; @Configuration -public class WebConfig extends WebMvcConfigurerAdapter { +public class WebConfig implements WebMvcConfigurer { @Override public void addArgumentResolvers(final List argumentResolvers) { diff --git a/spring-boot/src/main/java/org/baeldung/common/error/MyCustomErrorController.java b/spring-boot/src/main/java/org/baeldung/common/error/MyCustomErrorController.java index 510e607dfa..a826a604d3 100644 --- a/spring-boot/src/main/java/org/baeldung/common/error/MyCustomErrorController.java +++ b/spring-boot/src/main/java/org/baeldung/common/error/MyCustomErrorController.java @@ -1,6 +1,6 @@ package org.baeldung.common.error; -import org.springframework.boot.autoconfigure.web.ErrorController; +import org.springframework.boot.web.servlet.error.ErrorController; import org.springframework.web.bind.annotation.RequestMapping; public class MyCustomErrorController implements ErrorController { diff --git a/spring-boot/src/main/java/org/baeldung/common/properties/MyServletContainerCustomizationBean.java b/spring-boot/src/main/java/org/baeldung/common/properties/MyServletContainerCustomizationBean.java index 9b5a0aa948..2d955bac9b 100644 --- a/spring-boot/src/main/java/org/baeldung/common/properties/MyServletContainerCustomizationBean.java +++ b/spring-boot/src/main/java/org/baeldung/common/properties/MyServletContainerCustomizationBean.java @@ -1,20 +1,20 @@ package org.baeldung.common.properties; -import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer; -import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer; -import org.springframework.boot.web.servlet.ErrorPage; +import org.springframework.boot.web.server.ErrorPage; +import org.springframework.boot.web.server.WebServerFactoryCustomizer; +import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory; import org.springframework.http.HttpStatus; import org.springframework.stereotype.Component; @Component -public class MyServletContainerCustomizationBean implements EmbeddedServletContainerCustomizer { +public class MyServletContainerCustomizationBean implements WebServerFactoryCustomizer { public MyServletContainerCustomizationBean() { } @Override - public void customize(ConfigurableEmbeddedServletContainer container) { + public void customize(ConfigurableServletWebServerFactory container) { container.setPort(8084); container.setContextPath("/springbootapp"); diff --git a/spring-boot/src/main/java/org/baeldung/demo/DemoApplication.java b/spring-boot/src/main/java/org/baeldung/demo/DemoApplication.java index c4b0d48244..4a88fcea07 100644 --- a/spring-boot/src/main/java/org/baeldung/demo/DemoApplication.java +++ b/spring-boot/src/main/java/org/baeldung/demo/DemoApplication.java @@ -4,10 +4,9 @@ import com.baeldung.graphql.GraphqlConfiguration; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -import com.baeldung.autoconfiguration.MySQLAutoconfiguration; import org.springframework.context.annotation.Import; -@SpringBootApplication(exclude = MySQLAutoconfiguration.class) +@SpringBootApplication @Import(GraphqlConfiguration.class) public class DemoApplication { diff --git a/spring-boot/src/main/java/org/baeldung/demo/boottest/EmployeeRepository.java b/spring-boot/src/main/java/org/baeldung/demo/boottest/EmployeeRepository.java index d991d9a8a9..00fdbfaae4 100644 --- a/spring-boot/src/main/java/org/baeldung/demo/boottest/EmployeeRepository.java +++ b/spring-boot/src/main/java/org/baeldung/demo/boottest/EmployeeRepository.java @@ -2,10 +2,9 @@ package org.baeldung.demo.boottest; import java.util.List; -import javax.transaction.Transactional; - import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; +import org.springframework.transaction.annotation.Transactional; @Repository @Transactional @@ -13,8 +12,6 @@ public interface EmployeeRepository extends JpaRepository { public Employee findByName(String name); - public Employee findById(Long id); - public List findAll(); } diff --git a/spring-boot/src/main/java/org/baeldung/demo/boottest/EmployeeServiceImpl.java b/spring-boot/src/main/java/org/baeldung/demo/boottest/EmployeeServiceImpl.java index bd85234e02..a1639b29cc 100644 --- a/spring-boot/src/main/java/org/baeldung/demo/boottest/EmployeeServiceImpl.java +++ b/spring-boot/src/main/java/org/baeldung/demo/boottest/EmployeeServiceImpl.java @@ -2,10 +2,9 @@ package org.baeldung.demo.boottest; import java.util.List; -import javax.transaction.Transactional; - import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; @Service @Transactional @@ -16,7 +15,7 @@ public class EmployeeServiceImpl implements EmployeeService { @Override public Employee getEmployeeById(Long id) { - return employeeRepository.findById(id); + return employeeRepository.findById(id).orElse(null); } @Override diff --git a/spring-boot/src/main/java/org/baeldung/demo/components/FooService.java b/spring-boot/src/main/java/org/baeldung/demo/components/FooService.java index 334730ccb0..66943f6461 100644 --- a/spring-boot/src/main/java/org/baeldung/demo/components/FooService.java +++ b/spring-boot/src/main/java/org/baeldung/demo/components/FooService.java @@ -12,7 +12,7 @@ public class FooService { private FooRepository fooRepository; public Foo getFooWithId(Integer id) throws Exception { - return fooRepository.findOne(id); + return fooRepository.findById(id).orElse(null); } public Foo getFooWithName(String name) { diff --git a/spring-boot/src/main/java/org/baeldung/endpoints/CustomEndpoint.java b/spring-boot/src/main/java/org/baeldung/endpoints/CustomEndpoint.java deleted file mode 100644 index 222a54c6ef..0000000000 --- a/spring-boot/src/main/java/org/baeldung/endpoints/CustomEndpoint.java +++ /dev/null @@ -1,35 +0,0 @@ -package org.baeldung.endpoints; - -import java.util.ArrayList; -import java.util.List; - -import org.springframework.boot.actuate.endpoint.Endpoint; -import org.springframework.stereotype.Component; - -@Component -public class CustomEndpoint implements Endpoint> { - - public CustomEndpoint() { - - } - - public String getId() { - return "customEndpoint"; - } - - public boolean isEnabled() { - return true; - } - - public boolean isSensitive() { - return true; - } - - public List invoke() { - // Your logic to display the output - List messages = new ArrayList(); - messages.add("This is message 1"); - messages.add("This is message 2"); - return messages; - } -} diff --git a/spring-boot/src/main/java/org/baeldung/endpoints/ListEndpoints.java b/spring-boot/src/main/java/org/baeldung/endpoints/ListEndpoints.java deleted file mode 100644 index 61571b4adf..0000000000 --- a/spring-boot/src/main/java/org/baeldung/endpoints/ListEndpoints.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.baeldung.endpoints; - -import java.util.List; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.actuate.endpoint.AbstractEndpoint; -import org.springframework.boot.actuate.endpoint.Endpoint; -import org.springframework.stereotype.Component; - -@Component -public class ListEndpoints extends AbstractEndpoint> { - private List endpoints; - - @Autowired - public ListEndpoints(List endpoints) { - super("listEndpoints"); - this.endpoints = endpoints; - } - - public List invoke() { - return this.endpoints; - } -} \ No newline at end of file diff --git a/spring-boot/src/main/java/org/baeldung/endpoints/MyHealthCheck.java b/spring-boot/src/main/java/org/baeldung/endpoints/MyHealthCheck.java deleted file mode 100644 index 1a175aed48..0000000000 --- a/spring-boot/src/main/java/org/baeldung/endpoints/MyHealthCheck.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.baeldung.endpoints; - -import org.springframework.boot.actuate.health.Health; -import org.springframework.boot.actuate.health.HealthIndicator; -import org.springframework.stereotype.Component; - -@Component -public class MyHealthCheck implements HealthIndicator { - - public Health health() { - int errorCode = check(); // perform some specific health check - if (errorCode != 0) { - return Health.down().withDetail("Error Code", errorCode).withDetail("Description", "You custom MyHealthCheck endpoint is down").build(); - } - return Health.up().build(); - } - - public int check() { - // Your logic to check health - return 1; - } -} diff --git a/spring-boot/src/main/java/org/baeldung/main/SpringBootApplication.java b/spring-boot/src/main/java/org/baeldung/main/SpringBootApplication.java index 5cc697be65..7d13173be0 100644 --- a/spring-boot/src/main/java/org/baeldung/main/SpringBootApplication.java +++ b/spring-boot/src/main/java/org/baeldung/main/SpringBootApplication.java @@ -4,7 +4,6 @@ import org.baeldung.boot.controller.servlet.HelloWorldServlet; import org.baeldung.boot.controller.servlet.SpringHelloWorldServlet; import org.baeldung.common.error.SpringHelloServletRegistrationBean; import org.baeldung.common.resources.ExecutorServiceExitCodeGenerator; -import org.baeldung.service.LoginService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; @@ -14,24 +13,18 @@ import org.springframework.context.annotation.ComponentScan; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -import com.baeldung.autoconfiguration.MySQLAutoconfiguration; - import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @RestController -@EnableAutoConfiguration(exclude = MySQLAutoconfiguration.class) +@EnableAutoConfiguration @ComponentScan({ "org.baeldung.common.error", "org.baeldung.common.error.controller", "org.baeldung.common.properties", "org.baeldung.common.resources", "org.baeldung.endpoints", "org.baeldung.service", "org.baeldung.monitor.jmx", "org.baeldung.boot.config" }) public class SpringBootApplication { private static ApplicationContext applicationContext; - @Autowired - private LoginService service; - @RequestMapping("/") String home() { - service.login("admin", "admin".toCharArray()); return "TADA!!! You are in Spring Boot Actuator test application."; } diff --git a/spring-boot/src/main/java/org/baeldung/properties/ConfigPropertiesDemoApplication.java b/spring-boot/src/main/java/org/baeldung/properties/ConfigPropertiesDemoApplication.java index 8ebda17f7d..cb0304fc41 100644 --- a/spring-boot/src/main/java/org/baeldung/properties/ConfigPropertiesDemoApplication.java +++ b/spring-boot/src/main/java/org/baeldung/properties/ConfigPropertiesDemoApplication.java @@ -4,9 +4,7 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.context.annotation.ComponentScan; -import com.baeldung.autoconfiguration.MySQLAutoconfiguration; - -@EnableAutoConfiguration(exclude = MySQLAutoconfiguration.class) +@EnableAutoConfiguration @ComponentScan(basePackageClasses = ConfigProperties.class) public class ConfigPropertiesDemoApplication { public static void main(String[] args) { diff --git a/spring-boot/src/main/java/org/baeldung/service/LoginService.java b/spring-boot/src/main/java/org/baeldung/service/LoginService.java deleted file mode 100644 index 4f38e9cf09..0000000000 --- a/spring-boot/src/main/java/org/baeldung/service/LoginService.java +++ /dev/null @@ -1,5 +0,0 @@ -package org.baeldung.service; - -public interface LoginService { - public boolean login(String userName, char[] password); -} diff --git a/spring-boot/src/main/java/org/baeldung/service/LoginServiceImpl.java b/spring-boot/src/main/java/org/baeldung/service/LoginServiceImpl.java deleted file mode 100644 index ed0090f8e4..0000000000 --- a/spring-boot/src/main/java/org/baeldung/service/LoginServiceImpl.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.baeldung.service; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.actuate.metrics.CounterService; -import org.springframework.stereotype.Service; - -@Service -public class LoginServiceImpl implements LoginService { - - private CounterService counterService; - - @Autowired - public LoginServiceImpl(CounterService counterService) { - this.counterService = counterService; - } - - public boolean login(String userName, char[] password) { - boolean success; - if (userName.equals("admin") && "secret".toCharArray().equals(password)) { - counterService.increment("counter.login.success"); - success = true; - } else { - counterService.increment("counter.login.failure"); - success = false; - } - return success; - } - -} diff --git a/spring-boot/src/main/java/org/baeldung/session/exception/Application.java b/spring-boot/src/main/java/org/baeldung/session/exception/Application.java index 70c68368b5..9132e710d1 100644 --- a/spring-boot/src/main/java/org/baeldung/session/exception/Application.java +++ b/spring-boot/src/main/java/org/baeldung/session/exception/Application.java @@ -7,10 +7,8 @@ import org.springframework.boot.autoconfigure.domain.EntityScan; import org.springframework.context.annotation.Bean; import org.springframework.orm.jpa.vendor.HibernateJpaSessionFactoryBean; -import com.baeldung.autoconfiguration.MySQLAutoconfiguration; - @EntityScan(basePackageClasses = Foo.class) -@SpringBootApplication(exclude = MySQLAutoconfiguration.class) +@SpringBootApplication public class Application { public static void main(String[] args) { System.setProperty("spring.config.name", "exception"); diff --git a/spring-boot/src/main/java/org/baeldung/websocket/client/MyStompSessionHandler.java b/spring-boot/src/main/java/org/baeldung/websocket/client/MyStompSessionHandler.java index 45fbf2b623..92beab9430 100644 --- a/spring-boot/src/main/java/org/baeldung/websocket/client/MyStompSessionHandler.java +++ b/spring-boot/src/main/java/org/baeldung/websocket/client/MyStompSessionHandler.java @@ -1,6 +1,7 @@ package org.baeldung.websocket.client; -import org.apache.log4j.Logger; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.springframework.messaging.simp.stomp.StompCommand; import org.springframework.messaging.simp.stomp.StompHeaders; import org.springframework.messaging.simp.stomp.StompSession; @@ -18,7 +19,7 @@ import java.lang.reflect.Type; */ public class MyStompSessionHandler extends StompSessionHandlerAdapter { - private Logger logger = Logger.getLogger(MyStompSessionHandler.class); + private Logger logger = LogManager.getLogger(MyStompSessionHandler.class); @Override public void afterConnected(StompSession session, StompHeaders connectedHeaders) { diff --git a/spring-boot/src/test/java/com/baeldung/displayallbeans/DisplayBeanIntegrationTest.java b/spring-boot/src/test/java/com/baeldung/displayallbeans/DisplayBeanIntegrationTest.java index afe7f8df31..aab4836b6f 100644 --- a/spring-boot/src/test/java/com/baeldung/displayallbeans/DisplayBeanIntegrationTest.java +++ b/spring-boot/src/test/java/com/baeldung/displayallbeans/DisplayBeanIntegrationTest.java @@ -4,9 +4,9 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.context.embedded.LocalServerPort; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.boot.web.server.LocalServerPort; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.test.context.TestPropertySource; diff --git a/spring-boot/src/test/java/com/baeldung/servletinitializer/WarInitializerApplicationTest.java b/spring-boot/src/test/java/com/baeldung/servletinitializer/WarInitializerApplicationIntegrationTest.java similarity index 95% rename from spring-boot/src/test/java/com/baeldung/servletinitializer/WarInitializerApplicationTest.java rename to spring-boot/src/test/java/com/baeldung/servletinitializer/WarInitializerApplicationIntegrationTest.java index a3ee30ef49..2361f422f3 100644 --- a/spring-boot/src/test/java/com/baeldung/servletinitializer/WarInitializerApplicationTest.java +++ b/spring-boot/src/test/java/com/baeldung/servletinitializer/WarInitializerApplicationIntegrationTest.java @@ -16,7 +16,7 @@ import com.baeldung.servletinitializer.WarInitializerApplication.WarInitializerC @RunWith(SpringRunner.class) @WebMvcTest(controllers = WarInitializerController.class) -public class WarInitializerApplicationTest { +public class WarInitializerApplicationIntegrationTest { @Autowired private MockMvc mockMvc; diff --git a/spring-boot/src/test/java/com/baeldung/toggle/ToggleIntegrationTest.java b/spring-boot/src/test/java/com/baeldung/toggle/ToggleIntegrationTest.java index ca6230e8f5..471565b1c6 100644 --- a/spring-boot/src/test/java/com/baeldung/toggle/ToggleIntegrationTest.java +++ b/spring-boot/src/test/java/com/baeldung/toggle/ToggleIntegrationTest.java @@ -47,7 +47,7 @@ public class ToggleIntegrationTest { mockMvc.perform(post("/increaseSalary").param("id", emp.getId() + "")).andExpect(status().is(200)); - emp = employeeRepository.findOne(1L); + emp = employeeRepository.findById(1L).orElse(null); assertEquals("salary incorrect", 2000, emp.getSalary(), 0.5); } @@ -60,7 +60,7 @@ public class ToggleIntegrationTest { mockMvc.perform(post("/increaseSalary").param("id", emp.getId() + "")).andExpect(status().is(200)); - emp = employeeRepository.findOne(1L); + emp = employeeRepository.findById(1L).orElse(null); assertEquals("salary incorrect", 2200, emp.getSalary(), 0.5); } } diff --git a/spring-boot/src/test/java/org/baeldung/SpringBootH2IntegrationTest.java b/spring-boot/src/test/java/org/baeldung/SpringBootH2IntegrationTest.java index 2cb2f4dc10..290cfbe081 100644 --- a/spring-boot/src/test/java/org/baeldung/SpringBootH2IntegrationTest.java +++ b/spring-boot/src/test/java/org/baeldung/SpringBootH2IntegrationTest.java @@ -22,7 +22,7 @@ public class SpringBootH2IntegrationTest { @Test public void givenGenericEntityRepository_whenSaveAndRetreiveEntity_thenOK() { GenericEntity genericEntity = genericEntityRepository.save(new GenericEntity("test")); - GenericEntity foundEntity = genericEntityRepository.findOne(genericEntity.getId()); + GenericEntity foundEntity = genericEntityRepository.findById(genericEntity.getId()).orElse(null); assertNotNull(foundEntity); assertEquals(genericEntity.getValue(), foundEntity.getValue()); } diff --git a/spring-boot/src/test/java/org/baeldung/SpringBootJPAIntegrationTest.java b/spring-boot/src/test/java/org/baeldung/SpringBootJPAIntegrationTest.java index d9c30c67da..c368cf5219 100644 --- a/spring-boot/src/test/java/org/baeldung/SpringBootJPAIntegrationTest.java +++ b/spring-boot/src/test/java/org/baeldung/SpringBootJPAIntegrationTest.java @@ -21,7 +21,7 @@ public class SpringBootJPAIntegrationTest { @Test public void givenGenericEntityRepository_whenSaveAndRetreiveEntity_thenOK() { GenericEntity genericEntity = genericEntityRepository.save(new GenericEntity("test")); - GenericEntity foundEntity = genericEntityRepository.findOne(genericEntity.getId()); + GenericEntity foundEntity = genericEntityRepository.findById(genericEntity.getId()).orElse(null); assertNotNull(foundEntity); assertEquals(genericEntity.getValue(), foundEntity.getValue()); } diff --git a/spring-boot/src/test/java/org/baeldung/SpringBootProfileIntegrationTest.java b/spring-boot/src/test/java/org/baeldung/SpringBootProfileIntegrationTest.java index 1d4ee262b0..128a05f103 100644 --- a/spring-boot/src/test/java/org/baeldung/SpringBootProfileIntegrationTest.java +++ b/spring-boot/src/test/java/org/baeldung/SpringBootProfileIntegrationTest.java @@ -24,7 +24,7 @@ public class SpringBootProfileIntegrationTest { @Test public void givenGenericEntityRepository_whenSaveAndRetreiveEntity_thenOK() { GenericEntity genericEntity = genericEntityRepository.save(new GenericEntity("test")); - GenericEntity foundEntity = genericEntityRepository.findOne(genericEntity.getId()); + GenericEntity foundEntity = genericEntityRepository.findById(genericEntity.getId()).orElse(null); assertNotNull(foundEntity); assertEquals(genericEntity.getValue(), foundEntity.getValue()); } diff --git a/spring-boot/src/test/java/org/baeldung/demo/boottest/EmployeeRepositoryIntegrationTest.java b/spring-boot/src/test/java/org/baeldung/demo/boottest/EmployeeRepositoryIntegrationTest.java index f581052596..3042f95a46 100644 --- a/spring-boot/src/test/java/org/baeldung/demo/boottest/EmployeeRepositoryIntegrationTest.java +++ b/spring-boot/src/test/java/org/baeldung/demo/boottest/EmployeeRepositoryIntegrationTest.java @@ -43,13 +43,13 @@ public class EmployeeRepositoryIntegrationTest { Employee emp = new Employee("test"); entityManager.persistAndFlush(emp); - Employee fromDb = employeeRepository.findById(emp.getId()); + Employee fromDb = employeeRepository.findById(emp.getId()).orElse(null); assertThat(fromDb.getName()).isEqualTo(emp.getName()); } @Test public void whenInvalidId_thenReturnNull() { - Employee fromDb = employeeRepository.findById(-11L); + Employee fromDb = employeeRepository.findById(-11l).orElse(null); assertThat(fromDb).isNull(); } diff --git a/spring-boot/src/test/java/org/baeldung/demo/boottest/EmployeeServiceImplIntegrationTest.java b/spring-boot/src/test/java/org/baeldung/demo/boottest/EmployeeServiceImplIntegrationTest.java index f004536c49..4eec62db13 100644 --- a/spring-boot/src/test/java/org/baeldung/demo/boottest/EmployeeServiceImplIntegrationTest.java +++ b/spring-boot/src/test/java/org/baeldung/demo/boottest/EmployeeServiceImplIntegrationTest.java @@ -50,9 +50,9 @@ public class EmployeeServiceImplIntegrationTest { Mockito.when(employeeRepository.findByName(john.getName())).thenReturn(john); Mockito.when(employeeRepository.findByName(alex.getName())).thenReturn(alex); Mockito.when(employeeRepository.findByName("wrong_name")).thenReturn(null); - Mockito.when(employeeRepository.findById(john.getId())).thenReturn(john); + Mockito.when(employeeRepository.findById(john.getId()).orElse(null)).thenReturn(john); Mockito.when(employeeRepository.findAll()).thenReturn(allEmployees); - Mockito.when(employeeRepository.findById(-99L)).thenReturn(null); + Mockito.when(employeeRepository.findById(-99L).orElse(null)).thenReturn(null); } @Test From 88a3f6c0fe20f4a1da6e3329b3e9bf338accf5c9 Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Sun, 6 May 2018 23:02:49 +0300 Subject: [PATCH 43/66] replace requestmapping, update properties --- .../src/main/resources/application.properties | 2 -- spring-boot/README.MD | 1 - .../controller/UserController.java | 3 +- .../controller/FooController.java | 4 +-- .../controllers/MyErrorController.java | 4 +-- .../baeldung/git/CommitInfoController.java | 4 +-- .../intro/controller/HomeController.java | 6 ++-- .../baeldung/rss/ArticleRssController.java | 4 +-- .../WarInitializerApplication.java | 4 +-- .../com/baeldung/webjar/TestController.java | 4 +-- .../controller/GenericEntityController.java | 9 +++-- .../common/error/MyCustomErrorController.java | 4 +-- .../error/controller/ErrorController.java | 6 ++-- .../baeldung/main/SpringBootApplication.java | 4 +-- .../src/main/resources/application.properties | 36 ++++++++----------- 15 files changed, 43 insertions(+), 52 deletions(-) diff --git a/spring-boot-autoconfiguration/src/main/resources/application.properties b/spring-boot-autoconfiguration/src/main/resources/application.properties index 09df3b8f02..4456c78e5d 100644 --- a/spring-boot-autoconfiguration/src/main/resources/application.properties +++ b/spring-boot-autoconfiguration/src/main/resources/application.properties @@ -1,4 +1,2 @@ -server.port=9090 - spring.jpa.show-sql=true spring.jpa.hibernate.ddl-auto = update diff --git a/spring-boot/README.MD b/spring-boot/README.MD index 7e68e30a47..72da255b95 100644 --- a/spring-boot/README.MD +++ b/spring-boot/README.MD @@ -20,7 +20,6 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [Dynamic DTO Validation Config Retrieved from DB](http://www.baeldung.com/spring-dynamic-dto-validation) - [Custom Information in Spring Boot Info Endpoint](http://www.baeldung.com/spring-boot-info-actuator-custom) - [Using @JsonComponent in Spring Boot](http://www.baeldung.com/spring-boot-jsoncomponent) -- [Create a Custom Auto-Configuration with Spring Boot](http://www.baeldung.com/spring-boot-custom-auto-configuration) - [Testing in Spring Boot](http://www.baeldung.com/spring-boot-testing) - [Guide to @ConfigurationProperties in Spring Boot](http://www.baeldung.com/configuration-properties-in-spring-boot) - [How to Get All Spring-Managed Beans?](http://www.baeldung.com/spring-show-all-beans) diff --git a/spring-boot/src/main/java/com/baeldung/bootcustomfilters/controller/UserController.java b/spring-boot/src/main/java/com/baeldung/bootcustomfilters/controller/UserController.java index 9dfab1192d..97165f2cf3 100644 --- a/spring-boot/src/main/java/com/baeldung/bootcustomfilters/controller/UserController.java +++ b/spring-boot/src/main/java/com/baeldung/bootcustomfilters/controller/UserController.java @@ -6,6 +6,7 @@ import java.util.UUID; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -22,7 +23,7 @@ public class UserController { private static final Logger LOG = LoggerFactory.getLogger(UserController.class); - @RequestMapping("") + @GetMapping("") public List getAllUsers() { LOG.info("Fetching all the users"); return Arrays.asList( diff --git a/spring-boot/src/main/java/com/baeldung/displayallbeans/controller/FooController.java b/spring-boot/src/main/java/com/baeldung/displayallbeans/controller/FooController.java index 26f0a60bff..c4a83cc2d9 100644 --- a/spring-boot/src/main/java/com/baeldung/displayallbeans/controller/FooController.java +++ b/spring-boot/src/main/java/com/baeldung/displayallbeans/controller/FooController.java @@ -4,7 +4,7 @@ import java.util.Map; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.GetMapping; import com.baeldung.displayallbeans.service.FooService; @@ -13,7 +13,7 @@ public class FooController { @Autowired private FooService fooService; - @RequestMapping(value = "/displayallbeans") + @GetMapping(value = "/displayallbeans") public String getHeaderAndBody(Map model) { model.put("header", fooService.getHeader()); model.put("message", fooService.getBody()); diff --git a/spring-boot/src/main/java/com/baeldung/errorhandling/controllers/MyErrorController.java b/spring-boot/src/main/java/com/baeldung/errorhandling/controllers/MyErrorController.java index 8bdfea74cd..e002ac045d 100644 --- a/spring-boot/src/main/java/com/baeldung/errorhandling/controllers/MyErrorController.java +++ b/spring-boot/src/main/java/com/baeldung/errorhandling/controllers/MyErrorController.java @@ -3,7 +3,7 @@ package com.baeldung.errorhandling.controllers; import org.springframework.boot.web.servlet.error.ErrorController; import org.springframework.http.HttpStatus; import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.GetMapping; import javax.servlet.RequestDispatcher; import javax.servlet.http.HttpServletRequest; @@ -13,7 +13,7 @@ public class MyErrorController implements ErrorController { public MyErrorController() {} - @RequestMapping(value = "/error") + @GetMapping(value = "/error") public String handleError(HttpServletRequest request) { Object status = request.getAttribute(RequestDispatcher.ERROR_STATUS_CODE); diff --git a/spring-boot/src/main/java/com/baeldung/git/CommitInfoController.java b/spring-boot/src/main/java/com/baeldung/git/CommitInfoController.java index 6d44e02ec2..9dca749319 100644 --- a/spring-boot/src/main/java/com/baeldung/git/CommitInfoController.java +++ b/spring-boot/src/main/java/com/baeldung/git/CommitInfoController.java @@ -1,7 +1,7 @@ package com.baeldung.git; import org.springframework.beans.factory.annotation.Value; -import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; import java.util.HashMap; @@ -19,7 +19,7 @@ public class CommitInfoController { @Value("${git.commit.id}") private String commitId; - @RequestMapping("/commitId") + @GetMapping("/commitId") public Map getCommitId() { Map result = new HashMap<>(); result.put("Commit message", commitMessage); diff --git a/spring-boot/src/main/java/com/baeldung/intro/controller/HomeController.java b/spring-boot/src/main/java/com/baeldung/intro/controller/HomeController.java index 2a82e58829..32f22f2cae 100644 --- a/spring-boot/src/main/java/com/baeldung/intro/controller/HomeController.java +++ b/spring-boot/src/main/java/com/baeldung/intro/controller/HomeController.java @@ -1,17 +1,17 @@ package com.baeldung.intro.controller; -import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @RestController public class HomeController { - @RequestMapping("/") + @GetMapping("/") public String root() { return "Index Page"; } - @RequestMapping("/local") + @GetMapping("/local") public String local() { return "/local"; } diff --git a/spring-boot/src/main/java/com/baeldung/rss/ArticleRssController.java b/spring-boot/src/main/java/com/baeldung/rss/ArticleRssController.java index a3fbc4a37e..daaeb8159b 100644 --- a/spring-boot/src/main/java/com/baeldung/rss/ArticleRssController.java +++ b/spring-boot/src/main/java/com/baeldung/rss/ArticleRssController.java @@ -1,14 +1,14 @@ package com.baeldung.rss; import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; @Controller @RequestMapping(value = "/rss", produces = "application/*") public class ArticleRssController { - @RequestMapping(method = RequestMethod.GET) + @GetMapping public String articleFeed() { return "articleFeedView"; } diff --git a/spring-boot/src/main/java/com/baeldung/servletinitializer/WarInitializerApplication.java b/spring-boot/src/main/java/com/baeldung/servletinitializer/WarInitializerApplication.java index 1faee5c488..5b9ce1271e 100644 --- a/spring-boot/src/main/java/com/baeldung/servletinitializer/WarInitializerApplication.java +++ b/spring-boot/src/main/java/com/baeldung/servletinitializer/WarInitializerApplication.java @@ -7,7 +7,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; import org.springframework.ui.Model; -import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @SpringBootApplication @@ -27,7 +27,7 @@ public class WarInitializerApplication extends SpringBootServletInitializer { @RestController public static class WarInitializerController { - @RequestMapping("/") + @GetMapping("/") public String handler(Model model) { model.addAttribute("date", LocalDateTime.now()); return "WarInitializerApplication is up and running!"; diff --git a/spring-boot/src/main/java/com/baeldung/webjar/TestController.java b/spring-boot/src/main/java/com/baeldung/webjar/TestController.java index e8e7fd5ce9..e5404c7c7c 100644 --- a/spring-boot/src/main/java/com/baeldung/webjar/TestController.java +++ b/spring-boot/src/main/java/com/baeldung/webjar/TestController.java @@ -2,12 +2,12 @@ package com.baeldung.webjar; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; -import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.GetMapping; @Controller public class TestController { - @RequestMapping(value = "/") + @GetMapping(value = "/") public String welcome(Model model) { return "index"; } diff --git a/spring-boot/src/main/java/org/baeldung/boot/controller/GenericEntityController.java b/spring-boot/src/main/java/org/baeldung/boot/controller/GenericEntityController.java index 817bae8d01..17457f4c20 100644 --- a/spring-boot/src/main/java/org/baeldung/boot/controller/GenericEntityController.java +++ b/spring-boot/src/main/java/org/baeldung/boot/controller/GenericEntityController.java @@ -7,8 +7,7 @@ import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RestController; import java.time.LocalDateTime; @@ -26,18 +25,18 @@ public class GenericEntityController { entityList.add(new GenericEntity(4l, "entity_4")); } - @RequestMapping("/entity/all") + @GetMapping("/entity/all") public List findAll() { return entityList; } - @RequestMapping(value = "/entity", method = RequestMethod.POST) + @PostMapping("/entity") public GenericEntity addEntity(GenericEntity entity) { entityList.add(entity); return entity; } - @RequestMapping("/entity/findby/{id}") + @GetMapping("/entity/findby/{id}") public GenericEntity findById(@PathVariable Long id) { return entityList.stream().filter(entity -> entity.getId().equals(id)).findFirst().get(); } diff --git a/spring-boot/src/main/java/org/baeldung/common/error/MyCustomErrorController.java b/spring-boot/src/main/java/org/baeldung/common/error/MyCustomErrorController.java index a826a604d3..e4e20de671 100644 --- a/spring-boot/src/main/java/org/baeldung/common/error/MyCustomErrorController.java +++ b/spring-boot/src/main/java/org/baeldung/common/error/MyCustomErrorController.java @@ -1,7 +1,7 @@ package org.baeldung.common.error; import org.springframework.boot.web.servlet.error.ErrorController; -import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.GetMapping; public class MyCustomErrorController implements ErrorController { @@ -11,7 +11,7 @@ public class MyCustomErrorController implements ErrorController { // TODO Auto-generated constructor stub } - @RequestMapping(value = PATH) + @GetMapping(value = PATH) public String error() { return "Error heaven"; } diff --git a/spring-boot/src/main/java/org/baeldung/common/error/controller/ErrorController.java b/spring-boot/src/main/java/org/baeldung/common/error/controller/ErrorController.java index ecabde7d9d..d503f5da6d 100644 --- a/spring-boot/src/main/java/org/baeldung/common/error/controller/ErrorController.java +++ b/spring-boot/src/main/java/org/baeldung/common/error/controller/ErrorController.java @@ -1,6 +1,6 @@ package org.baeldung.common.error.controller; -import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @RestController @@ -9,12 +9,12 @@ public class ErrorController { public ErrorController() { } - @RequestMapping("/400") + @GetMapping("/400") String error400() { return "Error Code: 400 occured."; } - @RequestMapping("/errorHeaven") + @GetMapping("/errorHeaven") String errorHeaven() { return "You have reached the heaven of errors!!!"; } diff --git a/spring-boot/src/main/java/org/baeldung/main/SpringBootApplication.java b/spring-boot/src/main/java/org/baeldung/main/SpringBootApplication.java index 7d13173be0..30ac94221b 100644 --- a/spring-boot/src/main/java/org/baeldung/main/SpringBootApplication.java +++ b/spring-boot/src/main/java/org/baeldung/main/SpringBootApplication.java @@ -10,7 +10,7 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; -import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; import java.util.concurrent.ExecutorService; @@ -23,7 +23,7 @@ public class SpringBootApplication { private static ApplicationContext applicationContext; - @RequestMapping("/") + @GetMapping("/") String home() { return "TADA!!! You are in Spring Boot Actuator test application."; } diff --git a/spring-boot/src/main/resources/application.properties b/spring-boot/src/main/resources/application.properties index 203f0ee3c5..04a4fbf9de 100644 --- a/spring-boot/src/main/resources/application.properties +++ b/spring-boot/src/main/resources/application.properties @@ -1,21 +1,22 @@ server.port=9090 -server.contextPath=/springbootapp -management.port=8081 -management.address=127.0.0.1 +server.servlet.contextPath=/springbootapp +management.server.port=8081 +management.server.address=127.0.0.1 #debug=true spring.jpa.show-sql=true spring.jpa.hibernate.ddl-auto = update -endpoints.shutdown.enabled=true -endpoints.jmx.domain=Spring Sample Application -endpoints.jmx.uniqueNames=true +management.endpoints.jmx.domain=Spring Sample Application +management.endpoints.jmx.uniqueNames=true + +management.endpoint.shutdown.enabled=true ##jolokia.config.debug=true ##endpoints.jolokia.enabled=true ##endpoints.jolokia.path=jolokia spring.jmx.enabled=true -endpoints.jmx.enabled=true +management.endpoints.jmx.enabled=true ## for pretty printing of json when endpoints accessed over HTTP http.mappers.jsonPrettyPrint=true @@ -26,11 +27,7 @@ info.app.description=This is my first spring boot application G1 info.app.version=1.0.0 info.java-vendor = ${java.specification.vendor} -## Spring Security Configurations -security.user.name=admin1 -security.user.password=secret1 management.security.role=SUPERUSER -management.endpoint.shutdown.enabled=true logging.level.org.springframework=INFO @@ -38,15 +35,12 @@ logging.level.org.springframework=INFO servlet.name=dispatcherExample servlet.mapping=/dispatcherExampleURL -#banner.charset=UTF-8 -#banner.location=classpath:banner.txt -#banner.image.location=classpath:banner.gif -#banner.image.width= //TODO -#banner.image.height= //TODO -#banner.image.margin= //TODO -#banner.image.invert= //TODO +#spring.banner.charset=UTF-8 +#spring.banner.location=classpath:banner.txt +#spring.banner.image.location=classpath:banner.gif +#spring.banner.image.width= //TODO +#spring.banner.image.height= //TODO +#spring.banner.image.margin= //TODO +#spring.banner.image.invert= //TODO contactInfoType=email - -endpoints.beans.id=springbeans -endpoints.beans.sensitive=false From daafd33aacaf6e40510d930322c1de11c6124b9e Mon Sep 17 00:00:00 2001 From: collaboratewithakash <38683470+collaboratewithakash@users.noreply.github.com> Date: Tue, 8 May 2018 01:25:46 +0530 Subject: [PATCH 44/66] One back-link added (#4195) --- spring-all/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-all/README.md b/spring-all/README.md index e561eb265d..a3e1ca5464 100644 --- a/spring-all/README.md +++ b/spring-all/README.md @@ -26,3 +26,4 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [Model, ModelMap, and ModelView in Spring MVC](http://www.baeldung.com/spring-mvc-model-model-map-model-view) - [A Guide To Caching in Spring](http://www.baeldung.com/spring-cache-tutorial) - [How To Do @Async in Spring](http://www.baeldung.com/spring-async) +- [Quick Guide to the Spring @Order Annotation](http://www.baeldung.com/spring-order) From 1d0a6248e5ef85ea581eff57d696646622bcc8ce Mon Sep 17 00:00:00 2001 From: Felipe Santiago Corro Date: Tue, 8 May 2018 01:19:57 -0300 Subject: [PATCH 45/66] Spring Cache Custom KeyGenerator in module spring-all (#4196) --- .../config/ApplicationCacheConfig.java | 30 ++++++++++++++ .../caching/config/CustomKeyGenerator.java | 14 +++++++ .../baeldung/caching/example/BookService.java | 21 ++++++++++ .../main/java/org/baeldung/model/Book.java | 41 +++++++++++++++++++ 4 files changed, 106 insertions(+) create mode 100644 spring-all/src/main/java/org/baeldung/caching/config/ApplicationCacheConfig.java create mode 100644 spring-all/src/main/java/org/baeldung/caching/config/CustomKeyGenerator.java create mode 100644 spring-all/src/main/java/org/baeldung/caching/example/BookService.java create mode 100644 spring-all/src/main/java/org/baeldung/model/Book.java diff --git a/spring-all/src/main/java/org/baeldung/caching/config/ApplicationCacheConfig.java b/spring-all/src/main/java/org/baeldung/caching/config/ApplicationCacheConfig.java new file mode 100644 index 0000000000..8bf23de2cc --- /dev/null +++ b/spring-all/src/main/java/org/baeldung/caching/config/ApplicationCacheConfig.java @@ -0,0 +1,30 @@ +package org.baeldung.caching.config; + +import org.springframework.cache.Cache; +import org.springframework.cache.CacheManager; +import org.springframework.cache.annotation.EnableCaching; +import org.springframework.cache.concurrent.ConcurrentMapCache; +import org.springframework.cache.interceptor.KeyGenerator; +import org.springframework.cache.support.SimpleCacheManager; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import java.util.Arrays; + +@EnableCaching +@Configuration +public class ApplicationCacheConfig { + + @Bean + public CacheManager cacheManager() { + SimpleCacheManager cacheManager = new SimpleCacheManager(); + Cache booksCache = new ConcurrentMapCache("books"); + cacheManager.setCaches(Arrays.asList(booksCache)); + return cacheManager; + } + + @Bean("customKeyGenerator") + public KeyGenerator keyGenerator() { + return new CustomKeyGenerator(); + } +} diff --git a/spring-all/src/main/java/org/baeldung/caching/config/CustomKeyGenerator.java b/spring-all/src/main/java/org/baeldung/caching/config/CustomKeyGenerator.java new file mode 100644 index 0000000000..c1da9493e0 --- /dev/null +++ b/spring-all/src/main/java/org/baeldung/caching/config/CustomKeyGenerator.java @@ -0,0 +1,14 @@ +package org.baeldung.caching.config; + +import org.springframework.cache.interceptor.KeyGenerator; +import org.springframework.util.StringUtils; + +import java.lang.reflect.Method; + +public class CustomKeyGenerator implements KeyGenerator { + + public Object generate(Object target, Method method, Object... params) { + return target.getClass().getSimpleName() + "_" + method.getName() + "_" + + StringUtils.arrayToDelimitedString(params, "_"); + } +} diff --git a/spring-all/src/main/java/org/baeldung/caching/example/BookService.java b/spring-all/src/main/java/org/baeldung/caching/example/BookService.java new file mode 100644 index 0000000000..26118d61de --- /dev/null +++ b/spring-all/src/main/java/org/baeldung/caching/example/BookService.java @@ -0,0 +1,21 @@ +package org.baeldung.caching.example; + +import org.baeldung.model.Book; +import org.springframework.cache.annotation.Cacheable; +import org.springframework.stereotype.Component; + +import java.util.ArrayList; +import java.util.List; + +@Component +public class BookService { + + @Cacheable(value="books", keyGenerator="customKeyGenerator") + public List getBooks() { + List books = new ArrayList(); + books.add(new Book(1, "The Counterfeiters", "André Gide")); + books.add(new Book(2, "Peer Gynt and Hedda Gabler", "Henrik Ibsen")); + return books; + } + +} diff --git a/spring-all/src/main/java/org/baeldung/model/Book.java b/spring-all/src/main/java/org/baeldung/model/Book.java new file mode 100644 index 0000000000..9305ce9653 --- /dev/null +++ b/spring-all/src/main/java/org/baeldung/model/Book.java @@ -0,0 +1,41 @@ +package org.baeldung.model; + +public class Book { + + private int id; + private String author; + private String title; + + public Book() { + } + + public Book(int id, String author, String title) { + this.id = id; + this.author = author; + this.title = title; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getAuthor() { + return author; + } + + public void setAuthor(String author) { + this.author = author; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } +} From 2a92926cad3c7502a4391b09713ddfde8e9e51a0 Mon Sep 17 00:00:00 2001 From: mherbaghinyan Date: Tue, 8 May 2018 09:15:51 +0400 Subject: [PATCH 46/66] remove stream --- .../com/baeldung/designpatterns/composite/HeadDepartment.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-java/src/main/java/com/baeldung/designpatterns/composite/HeadDepartment.java b/core-java/src/main/java/com/baeldung/designpatterns/composite/HeadDepartment.java index 8854fce5b3..119b9c76b5 100644 --- a/core-java/src/main/java/com/baeldung/designpatterns/composite/HeadDepartment.java +++ b/core-java/src/main/java/com/baeldung/designpatterns/composite/HeadDepartment.java @@ -20,7 +20,7 @@ public class HeadDepartment implements Department { } public void printDepartmentName() { - childDepartments.stream().forEach(Department::printDepartmentName); + childDepartments.forEach(Department::printDepartmentName); } public void addDepartMent(Department department) { From 0dfaafac5c7b1209aa06a79f28ebae32f5148d36 Mon Sep 17 00:00:00 2001 From: Wosin Date: Tue, 8 May 2018 10:50:53 +0200 Subject: [PATCH 47/66] BAEL-430: Added performance tests for mapping frameworks (#4092) * BAEL-430: Added performance tests for mapping frameworks * Fixes * Removed @Test annotation. --- performance-tests/pom.xml | 79 +++++++ .../baeldung/performancetests/Converter.java | 11 + .../dozer/DozerConverter.java | 29 +++ .../jmapper/JMapperConverter.java | 30 +++ .../mapstruct/MapStructConverter.java | 22 ++ .../model/destination/AccountStatus.java | 5 + .../model/destination/Address.java | 83 +++++++ .../model/destination/DeliveryData.java | 83 +++++++ .../model/destination/DestinationCode.java | 23 ++ .../model/destination/Discount.java | 70 ++++++ .../model/destination/Order.java | 210 ++++++++++++++++++ .../model/destination/OrderStatus.java | 5 + .../model/destination/PaymentType.java | 5 + .../model/destination/Product.java | 107 +++++++++ .../model/destination/RefundPolicy.java | 72 ++++++ .../model/destination/Review.java | 67 ++++++ .../model/destination/Shop.java | 57 +++++ .../model/destination/User.java | 87 ++++++++ .../model/source/AccountStatus.java | 7 + .../model/source/Address.java | 54 +++++ .../model/source/DeliveryData.java | 54 +++++ .../model/source/Discount.java | 44 ++++ .../model/source/OrderStatus.java | 7 + .../model/source/PaymentType.java | 7 + .../model/source/Product.java | 76 +++++++ .../model/source/RefundPolicy.java | 48 ++++ .../performancetests/model/source/Review.java | 63 ++++++ .../performancetests/model/source/Shop.java | 55 +++++ .../model/source/SourceCode.java | 22 ++ .../model/source/SourceOrder.java | 118 ++++++++++ .../performancetests/model/source/User.java | 42 ++++ .../modelmapper/ModelMapperConverter.java | 26 +++ .../orika/OrikaConverter.java | 31 +++ .../src/main/resources/dozer-mapping.xml | 25 +++ .../MappingFrameworksPerformance.java | 193 ++++++++++++++++ .../src/test/resources/dozer-mapping.xml | 21 ++ pom.xml | 1 + 37 files changed, 1939 insertions(+) create mode 100644 performance-tests/pom.xml create mode 100644 performance-tests/src/main/java/com/baeldung/performancetests/Converter.java create mode 100644 performance-tests/src/main/java/com/baeldung/performancetests/dozer/DozerConverter.java create mode 100644 performance-tests/src/main/java/com/baeldung/performancetests/jmapper/JMapperConverter.java create mode 100644 performance-tests/src/main/java/com/baeldung/performancetests/mapstruct/MapStructConverter.java create mode 100644 performance-tests/src/main/java/com/baeldung/performancetests/model/destination/AccountStatus.java create mode 100644 performance-tests/src/main/java/com/baeldung/performancetests/model/destination/Address.java create mode 100644 performance-tests/src/main/java/com/baeldung/performancetests/model/destination/DeliveryData.java create mode 100644 performance-tests/src/main/java/com/baeldung/performancetests/model/destination/DestinationCode.java create mode 100644 performance-tests/src/main/java/com/baeldung/performancetests/model/destination/Discount.java create mode 100644 performance-tests/src/main/java/com/baeldung/performancetests/model/destination/Order.java create mode 100644 performance-tests/src/main/java/com/baeldung/performancetests/model/destination/OrderStatus.java create mode 100644 performance-tests/src/main/java/com/baeldung/performancetests/model/destination/PaymentType.java create mode 100644 performance-tests/src/main/java/com/baeldung/performancetests/model/destination/Product.java create mode 100644 performance-tests/src/main/java/com/baeldung/performancetests/model/destination/RefundPolicy.java create mode 100644 performance-tests/src/main/java/com/baeldung/performancetests/model/destination/Review.java create mode 100644 performance-tests/src/main/java/com/baeldung/performancetests/model/destination/Shop.java create mode 100644 performance-tests/src/main/java/com/baeldung/performancetests/model/destination/User.java create mode 100644 performance-tests/src/main/java/com/baeldung/performancetests/model/source/AccountStatus.java create mode 100644 performance-tests/src/main/java/com/baeldung/performancetests/model/source/Address.java create mode 100644 performance-tests/src/main/java/com/baeldung/performancetests/model/source/DeliveryData.java create mode 100644 performance-tests/src/main/java/com/baeldung/performancetests/model/source/Discount.java create mode 100644 performance-tests/src/main/java/com/baeldung/performancetests/model/source/OrderStatus.java create mode 100644 performance-tests/src/main/java/com/baeldung/performancetests/model/source/PaymentType.java create mode 100644 performance-tests/src/main/java/com/baeldung/performancetests/model/source/Product.java create mode 100644 performance-tests/src/main/java/com/baeldung/performancetests/model/source/RefundPolicy.java create mode 100644 performance-tests/src/main/java/com/baeldung/performancetests/model/source/Review.java create mode 100644 performance-tests/src/main/java/com/baeldung/performancetests/model/source/Shop.java create mode 100644 performance-tests/src/main/java/com/baeldung/performancetests/model/source/SourceCode.java create mode 100644 performance-tests/src/main/java/com/baeldung/performancetests/model/source/SourceOrder.java create mode 100644 performance-tests/src/main/java/com/baeldung/performancetests/model/source/User.java create mode 100644 performance-tests/src/main/java/com/baeldung/performancetests/modelmapper/ModelMapperConverter.java create mode 100644 performance-tests/src/main/java/com/baeldung/performancetests/orika/OrikaConverter.java create mode 100644 performance-tests/src/main/resources/dozer-mapping.xml create mode 100644 performance-tests/src/test/java/com/baeldung/performancetests/benchmark/MappingFrameworksPerformance.java create mode 100644 performance-tests/src/test/resources/dozer-mapping.xml diff --git a/performance-tests/pom.xml b/performance-tests/pom.xml new file mode 100644 index 0000000000..3f25796516 --- /dev/null +++ b/performance-tests/pom.xml @@ -0,0 +1,79 @@ + + + + parent-modules + com.baeldung + 1.0.0-SNAPSHOT + + 4.0.0 + + performancetests + + + + ma.glasnost.orika + orika-core + 1.5.2 + + + net.sf.dozer + dozer + 5.5.1 + + + io.craftsman + dozer-jdk8-support + 1.0.2 + + + org.mapstruct + mapstruct-jdk8 + 1.2.0.Final + + + org.modelmapper + modelmapper + 1.1.0 + + + com.googlecode.jmapper-framework + jmapper-core + 1.6.0.1 + + + org.openjdk.jmh + jmh-core + 1.20 + + + org.openjdk.jmh + jmh-generator-annprocess + 1.20 + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.5.1 + + 1.8 + 1.8 + + + org.mapstruct + mapstruct-processor + 1.2.0.Final + + + + + + + + + \ No newline at end of file diff --git a/performance-tests/src/main/java/com/baeldung/performancetests/Converter.java b/performance-tests/src/main/java/com/baeldung/performancetests/Converter.java new file mode 100644 index 0000000000..097600849b --- /dev/null +++ b/performance-tests/src/main/java/com/baeldung/performancetests/Converter.java @@ -0,0 +1,11 @@ +package com.baeldung.performancetests; + +import com.baeldung.performancetests.model.destination.DestinationCode; +import com.baeldung.performancetests.model.source.SourceCode; +import com.baeldung.performancetests.model.source.SourceOrder; +import com.baeldung.performancetests.model.destination.Order; + +public interface Converter { + Order convert(SourceOrder sourceOrder); + DestinationCode convert(SourceCode sourceCode); +} diff --git a/performance-tests/src/main/java/com/baeldung/performancetests/dozer/DozerConverter.java b/performance-tests/src/main/java/com/baeldung/performancetests/dozer/DozerConverter.java new file mode 100644 index 0000000000..710145ec58 --- /dev/null +++ b/performance-tests/src/main/java/com/baeldung/performancetests/dozer/DozerConverter.java @@ -0,0 +1,29 @@ +package com.baeldung.performancetests.dozer; + +import com.baeldung.performancetests.Converter; +import com.baeldung.performancetests.model.destination.DestinationCode; +import com.baeldung.performancetests.model.source.SourceCode; +import com.baeldung.performancetests.model.source.SourceOrder; +import com.baeldung.performancetests.model.destination.Order; +import org.dozer.DozerBeanMapper; +import org.dozer.Mapper; + + public class DozerConverter implements Converter { + private final Mapper mapper; + + public DozerConverter() { + DozerBeanMapper mapper = new DozerBeanMapper(); + mapper.addMapping(DozerConverter.class.getResourceAsStream("/dozer-mapping.xml")); + this.mapper = mapper; + } + + @Override + public Order convert(SourceOrder sourceOrder) { + return mapper.map(sourceOrder,Order.class); + } + + @Override + public DestinationCode convert(SourceCode sourceCode) { + return mapper.map(sourceCode, DestinationCode.class); + } + } diff --git a/performance-tests/src/main/java/com/baeldung/performancetests/jmapper/JMapperConverter.java b/performance-tests/src/main/java/com/baeldung/performancetests/jmapper/JMapperConverter.java new file mode 100644 index 0000000000..b61cfbb771 --- /dev/null +++ b/performance-tests/src/main/java/com/baeldung/performancetests/jmapper/JMapperConverter.java @@ -0,0 +1,30 @@ +package com.baeldung.performancetests.jmapper; + +import com.baeldung.performancetests.Converter; +import com.baeldung.performancetests.model.destination.DestinationCode; +import com.baeldung.performancetests.model.source.SourceCode; +import com.baeldung.performancetests.model.source.SourceOrder; +import com.baeldung.performancetests.model.destination.Order; +import com.googlecode.jmapper.JMapper; +import com.googlecode.jmapper.api.JMapperAPI; + +public class JMapperConverter implements Converter { + JMapper realLifeMapper; + JMapper simpleMapper; + public JMapperConverter() { + JMapperAPI api = new JMapperAPI().add(JMapperAPI.mappedClass(Order.class)); + realLifeMapper = new JMapper(Order.class, SourceOrder.class, api); + JMapperAPI simpleApi = new JMapperAPI().add(JMapperAPI.mappedClass(DestinationCode.class)); + simpleMapper = new JMapper(DestinationCode.class, SourceCode.class, simpleApi); + } + + @Override + public Order convert(SourceOrder sourceOrder) { + return (Order) realLifeMapper.getDestination(sourceOrder); + } + + @Override + public DestinationCode convert(SourceCode sourceCode) { + return (DestinationCode) simpleMapper.getDestination(sourceCode); + } +} diff --git a/performance-tests/src/main/java/com/baeldung/performancetests/mapstruct/MapStructConverter.java b/performance-tests/src/main/java/com/baeldung/performancetests/mapstruct/MapStructConverter.java new file mode 100644 index 0000000000..27ec6e6c83 --- /dev/null +++ b/performance-tests/src/main/java/com/baeldung/performancetests/mapstruct/MapStructConverter.java @@ -0,0 +1,22 @@ +package com.baeldung.performancetests.mapstruct; + +import com.baeldung.performancetests.Converter; +import com.baeldung.performancetests.model.destination.DestinationCode; +import com.baeldung.performancetests.model.source.SourceCode; +import com.baeldung.performancetests.model.source.SourceOrder; +import com.baeldung.performancetests.model.destination.Order; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; +import org.mapstruct.factory.Mappers; + +@Mapper +public interface MapStructConverter extends Converter { + MapStructConverter MAPPER = Mappers.getMapper(MapStructConverter.class); + + @Mapping(source = "status", target = "orderStatus") + @Override + Order convert(SourceOrder sourceOrder); + + @Override + DestinationCode convert(SourceCode sourceCode); +} diff --git a/performance-tests/src/main/java/com/baeldung/performancetests/model/destination/AccountStatus.java b/performance-tests/src/main/java/com/baeldung/performancetests/model/destination/AccountStatus.java new file mode 100644 index 0000000000..c435a73b56 --- /dev/null +++ b/performance-tests/src/main/java/com/baeldung/performancetests/model/destination/AccountStatus.java @@ -0,0 +1,5 @@ +package com.baeldung.performancetests.model.destination; + +public enum AccountStatus { + ACTIVE, NOT_ACTIVE, BANNED +} diff --git a/performance-tests/src/main/java/com/baeldung/performancetests/model/destination/Address.java b/performance-tests/src/main/java/com/baeldung/performancetests/model/destination/Address.java new file mode 100644 index 0000000000..9107f47455 --- /dev/null +++ b/performance-tests/src/main/java/com/baeldung/performancetests/model/destination/Address.java @@ -0,0 +1,83 @@ +package com.baeldung.performancetests.model.destination; + +import com.googlecode.jmapper.annotations.JGlobalMap; + +import java.util.Objects; + +@JGlobalMap +public class Address { + private String street; + private String city; + private String postalCode; + + public Address() { + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null) return false; + if(o.getClass() == com.baeldung.performancetests.model.source.Address.class) { + com.baeldung.performancetests.model.source.Address address = + (com.baeldung.performancetests.model.source.Address) o; + return Objects.equals(street, address.getStreet()) && + Objects.equals(city, address.getCity()) && + Objects.equals(postalCode, address.getPostalCode()) && + Objects.equals(country, address.getCountry()); + } + if(o.getClass() != getClass()) return false; + Address address = (Address) o; + return Objects.equals(street, address.street) && + Objects.equals(city, address.city) && + Objects.equals(postalCode, address.postalCode) && + Objects.equals(country, address.country); + } + + @Override + public int hashCode() { + + return Objects.hash(street, city, postalCode, country); + } + + private String country; + + public String getStreet() { + return street; + } + + public void setStreet(String street) { + this.street = street; + } + + public String getCity() { + return city; + } + + public void setCity(String city) { + this.city = city; + } + + public String getPostalCode() { + return postalCode; + } + + public void setPostalCode(String postalCode) { + this.postalCode = postalCode; + } + + public String getCountry() { + return country; + } + + public void setCountry(String country) { + this.country = country; + } + + public Address(String street, String city, String postalCode, String country) { + + this.street = street; + this.city = city; + this.postalCode = postalCode; + this.country = country; + } +} diff --git a/performance-tests/src/main/java/com/baeldung/performancetests/model/destination/DeliveryData.java b/performance-tests/src/main/java/com/baeldung/performancetests/model/destination/DeliveryData.java new file mode 100644 index 0000000000..1d9bde1088 --- /dev/null +++ b/performance-tests/src/main/java/com/baeldung/performancetests/model/destination/DeliveryData.java @@ -0,0 +1,83 @@ +package com.baeldung.performancetests.model.destination; + +import com.googlecode.jmapper.annotations.JGlobalMap; +import com.googlecode.jmapper.annotations.JMapAccessor; + +import java.util.Objects; + +@JGlobalMap +public class DeliveryData { + private Address deliveryAddress; + @JMapAccessor(get = "isPrePaid", set = "setPrePaid") + private boolean isPrePaid; + private String trackingCode; + private int expectedDeliveryTimeInDays; + + public DeliveryData() { + } + + public Address getDeliveryAddress() { + return deliveryAddress; + } + + public void setDeliveryAddress(Address deliveryAddress) { + this.deliveryAddress = deliveryAddress; + } + + public boolean isPrePaid() { + return isPrePaid; + } + + public void setPrePaid(boolean prePaid) { + isPrePaid = prePaid; + } + + public String getTrackingCode() { + return trackingCode; + } + + public void setTrackingCode(String trackingCode) { + this.trackingCode = trackingCode; + } + + public int getExpectedDeliveryTimeInDays() { + return expectedDeliveryTimeInDays; + } + + public void setExpectedDeliveryTimeInDays(int expectedDeliveryTimeInDays) { + this.expectedDeliveryTimeInDays = expectedDeliveryTimeInDays; + } + + public DeliveryData(Address deliveryAddress, boolean isPrePaid, String trackingCode, int expectedDeliveryTimeInDays) { + this.deliveryAddress = deliveryAddress; + this.isPrePaid = isPrePaid; + this.trackingCode = trackingCode; + this.expectedDeliveryTimeInDays = expectedDeliveryTimeInDays; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null) return false; + if(o.getClass() == com.baeldung.performancetests.model.source.DeliveryData.class) { + com.baeldung.performancetests.model.source.DeliveryData deliveryData = + (com.baeldung.performancetests.model.source.DeliveryData) o; + return isPrePaid == deliveryData.isPrePaid() && + expectedDeliveryTimeInDays == deliveryData.getExpectedDeliveryTimeInDays() && + Objects.equals(deliveryAddress, deliveryData.getDeliveryAddress()) && + Objects.equals(trackingCode, deliveryData.getTrackingCode()); + } + if (o.getClass() != getClass()) return false; + DeliveryData that = (DeliveryData) o; + return isPrePaid == that.isPrePaid && + expectedDeliveryTimeInDays == that.expectedDeliveryTimeInDays && + Objects.equals(deliveryAddress, that.deliveryAddress) && + Objects.equals(trackingCode, that.trackingCode); + } + + @Override + public int hashCode() { + + return Objects.hash(deliveryAddress, isPrePaid, trackingCode, expectedDeliveryTimeInDays); + } +} diff --git a/performance-tests/src/main/java/com/baeldung/performancetests/model/destination/DestinationCode.java b/performance-tests/src/main/java/com/baeldung/performancetests/model/destination/DestinationCode.java new file mode 100644 index 0000000000..d0a7985db8 --- /dev/null +++ b/performance-tests/src/main/java/com/baeldung/performancetests/model/destination/DestinationCode.java @@ -0,0 +1,23 @@ +package com.baeldung.performancetests.model.destination; + +import com.googlecode.jmapper.annotations.JMap; + +public class DestinationCode { + @JMap + String code; + + public DestinationCode(String code) { + this.code = code; + } + + public DestinationCode() { + } + + public String getCode() { + return code; + } + + public void setCode(String code) { + this.code = code; + } +} diff --git a/performance-tests/src/main/java/com/baeldung/performancetests/model/destination/Discount.java b/performance-tests/src/main/java/com/baeldung/performancetests/model/destination/Discount.java new file mode 100644 index 0000000000..920cc71a7e --- /dev/null +++ b/performance-tests/src/main/java/com/baeldung/performancetests/model/destination/Discount.java @@ -0,0 +1,70 @@ +package com.baeldung.performancetests.model.destination; + +import com.google.common.base.Objects; +import com.googlecode.jmapper.annotations.JGlobalMap; + +import java.math.BigDecimal; + +@JGlobalMap +public class Discount { + private String startTime; + private String endTime; + private BigDecimal discountPrice; + + public Discount() { + } + + public String getStartTime() { + return startTime; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null) return false; + if (o.getClass() == com.baeldung.performancetests.model.source.Discount.class) { + com.baeldung.performancetests.model.source.Discount discount = + (com.baeldung.performancetests.model.source.Discount) o; + return Objects.equal(startTime, discount.getStartTime()) && + Objects.equal(endTime, discount.getEndTime()) && + Objects.equal(discountPrice, discount.getDiscountPrice()); + } + if(o.getClass() != getClass()) return false; + Discount discount = (Discount) o; + return Objects.equal(startTime, discount.startTime) && + Objects.equal(endTime, discount.endTime) && + Objects.equal(discountPrice, discount.discountPrice); + } + + @Override + public int hashCode() { + return Objects.hashCode(startTime, endTime, discountPrice); + } + + public void setStartTime(String startTime) { + this.startTime = startTime; + } + + public String getEndTime() { + return endTime; + } + + public void setEndTime(String endTime) { + this.endTime = endTime; + } + + public BigDecimal getDiscountPrice() { + return discountPrice; + } + + public void setDiscountPrice(BigDecimal discountPrice) { + this.discountPrice = discountPrice; + } + + public Discount(String startTime, String endTime, BigDecimal discountPrice) { + + this.startTime = startTime; + this.endTime = endTime; + this.discountPrice = discountPrice; + } +} diff --git a/performance-tests/src/main/java/com/baeldung/performancetests/model/destination/Order.java b/performance-tests/src/main/java/com/baeldung/performancetests/model/destination/Order.java new file mode 100644 index 0000000000..cbce84efc4 --- /dev/null +++ b/performance-tests/src/main/java/com/baeldung/performancetests/model/destination/Order.java @@ -0,0 +1,210 @@ +package com.baeldung.performancetests.model.destination; + +import com.baeldung.performancetests.model.source.SourceOrder; +import com.google.common.base.Objects; +import com.googlecode.jmapper.annotations.JMap; +import com.googlecode.jmapper.annotations.JMapConversion; + +import java.util.List; +public class Order { + @JMap + private User orderingUser; + @JMap + private List orderedProducts; + @JMap("status") + private OrderStatus orderStatus; + @JMap + private String orderDate; + @JMap + private String orderFinishDate; + @JMap + private PaymentType paymentType; + @JMap + private Discount discount; + @JMap + private int orderId; + @JMap + private DeliveryData deliveryData; + @JMap + private Shop offeringShop; + + public Order() { + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null) return false; + if (o.getClass() == SourceOrder.class) { + SourceOrder order = + (SourceOrder) o; + return Objects.equal(orderingUser, order.getOrderingUser()) && + Objects.equal(orderedProducts, order.getOrderedProducts()) && + orderStatus.ordinal() == order.getStatus().ordinal() && + Objects.equal(orderDate, order.getOrderDate()) && + Objects.equal(orderFinishDate, order.getOrderFinishDate()) && + paymentType.ordinal() == order.getPaymentType().ordinal() && + Objects.equal(discount, order.getDiscount()) && + Objects.equal(deliveryData, order.getDeliveryData()); + } + if (o.getClass() != getClass()) return false; + Order order = (Order) o; + return Objects.equal(orderingUser, order.orderingUser) && + Objects.equal(orderedProducts, order.orderedProducts) && + orderStatus == order.orderStatus && + Objects.equal(orderDate, order.orderDate) && + Objects.equal(orderFinishDate, order.orderFinishDate) && + paymentType == order.paymentType && + Objects.equal(discount, order.discount) && + Objects.equal(deliveryData, order.deliveryData); + } + + @Override + public int hashCode() { + return Objects.hashCode(orderingUser, orderedProducts, orderStatus, orderDate, orderFinishDate, paymentType, discount, deliveryData); + } + + public User getOrderingUser() { + return orderingUser; + } + + public void setOrderingUser(User orderingUser) { + this.orderingUser = orderingUser; + } + + public List getOrderedProducts() { + return orderedProducts; + } + + public void setOrderedProducts(List orderedProducts) { + this.orderedProducts = orderedProducts; + } + + public OrderStatus getOrderStatus() { + return orderStatus; + } + + public void setOrderStatus(OrderStatus status) { + this.orderStatus = status; + } + + public String getOrderDate() { + return orderDate; + } + + public void setOrderDate(String orderDate) { + this.orderDate = orderDate; + } + + public String getOrderFinishDate() { + return orderFinishDate; + } + + public void setOrderFinishDate(String orderFinishDate) { + this.orderFinishDate = orderFinishDate; + } + + public PaymentType getPaymentType() { + return paymentType; + } + + public void setPaymentType(PaymentType paymentType) { + this.paymentType = paymentType; + } + + public Discount getDiscount() { + return discount; + } + + public void setDiscount(Discount discount) { + this.discount = discount; + } + + public DeliveryData getDeliveryData() { + return deliveryData; + } + + public void setDeliveryData(DeliveryData deliveryData) { + this.deliveryData = deliveryData; + } + + + public int getOrderId() { + return orderId; + } + + public void setOrderId(int orderId) { + this.orderId = orderId; + } + + public Order(User orderingUser, List orderedProducts, OrderStatus orderStatus, String orderDate, String orderFinishDate, PaymentType paymentType, Discount discount, int orderId, DeliveryData deliveryData, Shop offeringShop) { + + this.orderingUser = orderingUser; + this.orderedProducts = orderedProducts; + this.orderStatus = orderStatus; + this.orderDate = orderDate; + this.orderFinishDate = orderFinishDate; + this.paymentType = paymentType; + this.discount = discount; + this.orderId = orderId; + this.deliveryData = deliveryData; + this.offeringShop = offeringShop; + } + + public Shop getOfferingShop() { + return offeringShop; + } + + public void setOfferingShop(Shop offeringShop) { + this.offeringShop = offeringShop; + } + + + + @JMapConversion(from = "status", to = "orderStatus") + public OrderStatus conversion(com.baeldung.performancetests.model.source.OrderStatus status) { + OrderStatus orderStatus = null; + switch(status) { + case CREATED: + orderStatus = OrderStatus.CREATED; + break; + case FINISHED: + orderStatus = OrderStatus.FINISHED; + break; + + case CONFIRMED: + orderStatus = OrderStatus.CONFIRMED; + break; + + case COLLECTING: + orderStatus = OrderStatus.COLLECTING; + break; + + case IN_TRANSPORT: + orderStatus = OrderStatus.IN_TRANSPORT; + break; + } + return orderStatus; + } + + @JMapConversion(from = "paymentType", to = "paymentType") + public PaymentType conversion(com.baeldung.performancetests.model.source.PaymentType type) { + PaymentType paymentType = null; + switch(type) { + case CARD: + paymentType = PaymentType.CARD; + break; + + case CASH: + paymentType = PaymentType.CASH; + break; + + case TRANSFER: + paymentType = PaymentType.TRANSFER; + break; + } + return paymentType; + } + + +} diff --git a/performance-tests/src/main/java/com/baeldung/performancetests/model/destination/OrderStatus.java b/performance-tests/src/main/java/com/baeldung/performancetests/model/destination/OrderStatus.java new file mode 100644 index 0000000000..48118201e1 --- /dev/null +++ b/performance-tests/src/main/java/com/baeldung/performancetests/model/destination/OrderStatus.java @@ -0,0 +1,5 @@ +package com.baeldung.performancetests.model.destination; + +public enum OrderStatus { + CREATED, CONFIRMED, COLLECTING, IN_TRANSPORT, FINISHED +} diff --git a/performance-tests/src/main/java/com/baeldung/performancetests/model/destination/PaymentType.java b/performance-tests/src/main/java/com/baeldung/performancetests/model/destination/PaymentType.java new file mode 100644 index 0000000000..441e275b18 --- /dev/null +++ b/performance-tests/src/main/java/com/baeldung/performancetests/model/destination/PaymentType.java @@ -0,0 +1,5 @@ +package com.baeldung.performancetests.model.destination; + +public enum PaymentType { + CASH, CARD, TRANSFER +} diff --git a/performance-tests/src/main/java/com/baeldung/performancetests/model/destination/Product.java b/performance-tests/src/main/java/com/baeldung/performancetests/model/destination/Product.java new file mode 100644 index 0000000000..bc1e95e2c0 --- /dev/null +++ b/performance-tests/src/main/java/com/baeldung/performancetests/model/destination/Product.java @@ -0,0 +1,107 @@ +package com.baeldung.performancetests.model.destination; + +import com.google.common.base.Objects; +import com.googlecode.jmapper.annotations.JGlobalMap; + +import java.math.BigDecimal; + +@JGlobalMap +public class Product { + private BigDecimal price; + private int quantity; + + public Product() { + } + + public BigDecimal getPrice() { + return price; + } + + public void setPrice(BigDecimal price) { + this.price = price; + } + + public int getQuantity() { + return quantity; + } + + public void setQuantity(int quantity) { + this.quantity = quantity; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public boolean isAvailable() { + return available; + } + + public void setAvailable(boolean available) { + this.available = available; + } + + public RefundPolicy getRefundPolicy() { + return refundPolicy; + } + + public void setRefundPolicy(RefundPolicy refundPolicy) { + this.refundPolicy = refundPolicy; + } + + private String name; + + public Product(BigDecimal price, int quantity, String name, String description, boolean available, RefundPolicy refundPolicy) { + this.price = price; + this.quantity = quantity; + this.name = name; + this.description = description; + this.available = available; + this.refundPolicy = refundPolicy; + } + + String description; + boolean available; + private RefundPolicy refundPolicy; + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null) return false; + if (o.getClass() == com.baeldung.performancetests.model.source.Product.class) { + com.baeldung.performancetests.model.source.Product product = + (com.baeldung.performancetests.model.source.Product) o; + return quantity == product.getQuantity() && + available == product.isAvailable() && + Objects.equal(price, product.getPrice()) && + Objects.equal(name, product.getName()) && + Objects.equal(description, product.getDescription()) && + Objects.equal(refundPolicy, product.getRefundPolicy()); + } + if(o.getClass() != getClass()) return false; + Product product = (Product) o; + return quantity == product.quantity && + available == product.available && + Objects.equal(price, product.price) && + Objects.equal(name, product.name) && + Objects.equal(description, product.description) && + Objects.equal(refundPolicy, product.refundPolicy); + } + + @Override + public int hashCode() { + return Objects.hashCode(price, quantity, name, description, available, refundPolicy); + } +} diff --git a/performance-tests/src/main/java/com/baeldung/performancetests/model/destination/RefundPolicy.java b/performance-tests/src/main/java/com/baeldung/performancetests/model/destination/RefundPolicy.java new file mode 100644 index 0000000000..523957596c --- /dev/null +++ b/performance-tests/src/main/java/com/baeldung/performancetests/model/destination/RefundPolicy.java @@ -0,0 +1,72 @@ +package com.baeldung.performancetests.model.destination; + +import com.google.common.base.Objects; +import com.googlecode.jmapper.annotations.JGlobalMap; +import com.googlecode.jmapper.annotations.JMapAccessor; + +import java.util.List; + +@JGlobalMap +public class RefundPolicy { + @JMapAccessor(get = "isRefundable", set = "setRefundable") + private boolean isRefundable; + private int refundTimeInDays; + + public RefundPolicy() { + } + + public boolean isRefundable() { + return isRefundable; + } + + public void setRefundable(boolean refundable) { + isRefundable = refundable; + } + + public int getRefundTimeInDays() { + return refundTimeInDays; + } + + public void setRefundTimeInDays(int refundTimeInDays) { + this.refundTimeInDays = refundTimeInDays; + } + + public List getNotes() { + return notes; + } + + public void setNotes(List notes) { + this.notes = notes; + } + + public RefundPolicy(boolean isRefundable, int refundTimeInDays, List notes) { + + this.isRefundable = isRefundable; + this.refundTimeInDays = refundTimeInDays; + this.notes = notes; + } + + private List notes; + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null) return false; + if (o.getClass() == com.baeldung.performancetests.model.source.RefundPolicy.class) { + com.baeldung.performancetests.model.source.RefundPolicy that = (com.baeldung.performancetests.model.source.RefundPolicy) o; + return isRefundable == that.isRefundable() && + refundTimeInDays == that.getRefundTimeInDays() && + Objects.equal(notes, that.getNotes()); + } + if (o.getClass() != getClass()) return false; + RefundPolicy that = (RefundPolicy) o; + return isRefundable == that.isRefundable && + refundTimeInDays == that.refundTimeInDays && + Objects.equal(notes, that.notes); + } + + @Override + public int hashCode() { + return Objects.hashCode(isRefundable, refundTimeInDays, notes); + } +} diff --git a/performance-tests/src/main/java/com/baeldung/performancetests/model/destination/Review.java b/performance-tests/src/main/java/com/baeldung/performancetests/model/destination/Review.java new file mode 100644 index 0000000000..d1794d4913 --- /dev/null +++ b/performance-tests/src/main/java/com/baeldung/performancetests/model/destination/Review.java @@ -0,0 +1,67 @@ +package com.baeldung.performancetests.model.destination; + +import com.baeldung.performancetests.model.source.User; +import com.googlecode.jmapper.annotations.JGlobalMap; + +@JGlobalMap +public class Review { + + int shippingGrade; + int pricingGrade; + int serviceGrade; + User reviewingUser; + String note; + + public int getShippingGrade() { + return shippingGrade; + } + + public void setShippingGrade(int shippingGrade) { + this.shippingGrade = shippingGrade; + } + + public int getPricingGrade() { + return pricingGrade; + } + + public void setPricingGrade(int pricingGrade) { + this.pricingGrade = pricingGrade; + } + + public int getServiceGrade() { + return serviceGrade; + } + + public void setServiceGrade(int serviceGrade) { + this.serviceGrade = serviceGrade; + } + + public User getReviewingUser() { + return reviewingUser; + } + + public void setReviewingUser(User reviewingUser) { + this.reviewingUser = reviewingUser; + } + + public String getNote() { + return note; + } + + public void setNote(String note) { + this.note = note; + } + + public Review() { + + } + + public Review(int shippingGrade, int pricingGrade, int serviceGrade, User reviewingUser, String note) { + + this.shippingGrade = shippingGrade; + this.pricingGrade = pricingGrade; + this.serviceGrade = serviceGrade; + this.reviewingUser = reviewingUser; + this.note = note; + } +} diff --git a/performance-tests/src/main/java/com/baeldung/performancetests/model/destination/Shop.java b/performance-tests/src/main/java/com/baeldung/performancetests/model/destination/Shop.java new file mode 100644 index 0000000000..75f37b8bba --- /dev/null +++ b/performance-tests/src/main/java/com/baeldung/performancetests/model/destination/Shop.java @@ -0,0 +1,57 @@ +package com.baeldung.performancetests.model.destination; + +import com.baeldung.performancetests.model.source.Address; +import com.googlecode.jmapper.annotations.JGlobalMap; + +import java.util.List; +@JGlobalMap +public class Shop { + + private String shopName; + private Address shopAddres; + private String shopUrl; + private List reviews; + + public String getShopName() { + return shopName; + } + + public void setShopName(String shopName) { + this.shopName = shopName; + } + + public Address getShopAddres() { + return shopAddres; + } + + public void setShopAddres(Address shopAddres) { + this.shopAddres = shopAddres; + } + + public String getShopUrl() { + return shopUrl; + } + + public void setShopUrl(String shopUrl) { + this.shopUrl = shopUrl; + } + + public Shop() { + } + + public List getReviews() { + return reviews; + } + + public void setReviews(List reviews) { + this.reviews = reviews; + } + + public Shop(String shopName, Address shopAddres, String shopUrl, List reviews) { + + this.shopName = shopName; + this.shopAddres = shopAddres; + this.shopUrl = shopUrl; + this.reviews = reviews; + } +} diff --git a/performance-tests/src/main/java/com/baeldung/performancetests/model/destination/User.java b/performance-tests/src/main/java/com/baeldung/performancetests/model/destination/User.java new file mode 100644 index 0000000000..6f604f64b3 --- /dev/null +++ b/performance-tests/src/main/java/com/baeldung/performancetests/model/destination/User.java @@ -0,0 +1,87 @@ +package com.baeldung.performancetests.model.destination; + +import com.google.common.base.Objects; +import com.googlecode.jmapper.annotations.JGlobalMap; +import com.googlecode.jmapper.annotations.JMapConversion; + +@JGlobalMap +public class User { + private String username; + private String email; + private AccountStatus userAccountStatus; + + public User(String username, String email, AccountStatus userAccountStatus) { + this.username = username; + this.email = email; + this.userAccountStatus = userAccountStatus; + } + + public User() { + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public AccountStatus getUserAccountStatus() { + return userAccountStatus; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null) return false; + if (o.getClass() == com.baeldung.performancetests.model.source.User.class) { + com.baeldung.performancetests.model.source.User user = + (com.baeldung.performancetests.model.source.User) o; + return Objects.equal(username, user.getUsername()) && + Objects.equal(email, user.getEmail()) && + userAccountStatus.ordinal() == user.getUserAccountStatus().ordinal(); + } + if (o.getClass() != getClass()) return false; + User user = (User) o; + return Objects.equal(username, user.username) && + Objects.equal(email, user.email) && + userAccountStatus == user.userAccountStatus; + } + + @Override + public int hashCode() { + return Objects.hashCode(username, email, userAccountStatus); + } + + public void setUserAccountStatus(AccountStatus userAccountStatus) { + this.userAccountStatus = userAccountStatus; + } + + + @JMapConversion(from = "userAccountStatus", to = "userAccountStatus") + public AccountStatus conversion(com.baeldung.performancetests.model.source.AccountStatus status) { + AccountStatus accountStatus = null; + switch(status) { + case ACTIVE: + accountStatus = AccountStatus.ACTIVE; + break; + case NOT_ACTIVE: + accountStatus = AccountStatus.NOT_ACTIVE; + break; + + case BANNED: + accountStatus = AccountStatus.BANNED; + break; + } + return accountStatus; + } +} diff --git a/performance-tests/src/main/java/com/baeldung/performancetests/model/source/AccountStatus.java b/performance-tests/src/main/java/com/baeldung/performancetests/model/source/AccountStatus.java new file mode 100644 index 0000000000..e3e7d7964c --- /dev/null +++ b/performance-tests/src/main/java/com/baeldung/performancetests/model/source/AccountStatus.java @@ -0,0 +1,7 @@ +package com.baeldung.performancetests.model.source; + +import com.googlecode.jmapper.annotations.JGlobalMap; + +public enum AccountStatus { + ACTIVE, NOT_ACTIVE, BANNED +} diff --git a/performance-tests/src/main/java/com/baeldung/performancetests/model/source/Address.java b/performance-tests/src/main/java/com/baeldung/performancetests/model/source/Address.java new file mode 100644 index 0000000000..2818fa0065 --- /dev/null +++ b/performance-tests/src/main/java/com/baeldung/performancetests/model/source/Address.java @@ -0,0 +1,54 @@ +package com.baeldung.performancetests.model.source; + +import com.googlecode.jmapper.annotations.JGlobalMap; + +public class Address { + private String street; + private String city; + private String postalCode; + + public Address() { + } + + private String country; + + public String getStreet() { + return street; + } + + public void setStreet(String street) { + this.street = street; + } + + public String getCity() { + return city; + } + + public void setCity(String city) { + this.city = city; + } + + public String getPostalCode() { + return postalCode; + } + + public void setPostalCode(String postalCode) { + this.postalCode = postalCode; + } + + public String getCountry() { + return country; + } + + public void setCountry(String country) { + this.country = country; + } + + public Address(String street, String city, String postalCode, String country) { + + this.street = street; + this.city = city; + this.postalCode = postalCode; + this.country = country; + } +} diff --git a/performance-tests/src/main/java/com/baeldung/performancetests/model/source/DeliveryData.java b/performance-tests/src/main/java/com/baeldung/performancetests/model/source/DeliveryData.java new file mode 100644 index 0000000000..9501649a05 --- /dev/null +++ b/performance-tests/src/main/java/com/baeldung/performancetests/model/source/DeliveryData.java @@ -0,0 +1,54 @@ +package com.baeldung.performancetests.model.source; + +import com.googlecode.jmapper.annotations.JGlobalMap; +import com.googlecode.jmapper.annotations.JMapAccessor; + +public class DeliveryData { + private Address deliveryAddress; + @JMapAccessor(get = "isPrePaid", set = "setPrePaid") + private boolean isPrePaid; + private String trackingCode; + private int expectedDeliveryTimeInDays; + + public DeliveryData() { + } + + public Address getDeliveryAddress() { + return deliveryAddress; + } + + public void setDeliveryAddress(Address deliveryAddress) { + this.deliveryAddress = deliveryAddress; + } + + public boolean isPrePaid() { + return isPrePaid; + } + + public void setPrePaid(boolean prePaid) { + isPrePaid = prePaid; + } + + public String getTrackingCode() { + return trackingCode; + } + + public void setTrackingCode(String trackingCode) { + this.trackingCode = trackingCode; + } + + public int getExpectedDeliveryTimeInDays() { + return expectedDeliveryTimeInDays; + } + + public void setExpectedDeliveryTimeInDays(int expectedDeliveryTimeInDays) { + this.expectedDeliveryTimeInDays = expectedDeliveryTimeInDays; + } + + public DeliveryData(Address deliveryAddress, boolean isPrePaid, String trackingCode, int expectedDeliveryTimeInDays) { + this.deliveryAddress = deliveryAddress; + this.isPrePaid = isPrePaid; + this.trackingCode = trackingCode; + this.expectedDeliveryTimeInDays = expectedDeliveryTimeInDays; + } +} diff --git a/performance-tests/src/main/java/com/baeldung/performancetests/model/source/Discount.java b/performance-tests/src/main/java/com/baeldung/performancetests/model/source/Discount.java new file mode 100644 index 0000000000..603432dfed --- /dev/null +++ b/performance-tests/src/main/java/com/baeldung/performancetests/model/source/Discount.java @@ -0,0 +1,44 @@ +package com.baeldung.performancetests.model.source; + +import com.googlecode.jmapper.annotations.JGlobalMap; + +import java.math.BigDecimal; +public class Discount { + private String startTime; + private String endTime; + private BigDecimal discountPrice; + + public Discount() { + } + + public String getStartTime() { + return startTime; + } + + public void setStartTime(String startTime) { + this.startTime = startTime; + } + + public String getEndTime() { + return endTime; + } + + public void setEndTime(String endTime) { + this.endTime = endTime; + } + + public BigDecimal getDiscountPrice() { + return discountPrice; + } + + public void setDiscountPrice(BigDecimal discountPrice) { + this.discountPrice = discountPrice; + } + + public Discount(String startTime, String endTime, BigDecimal discountPrice) { + + this.startTime = startTime; + this.endTime = endTime; + this.discountPrice = discountPrice; + } +} diff --git a/performance-tests/src/main/java/com/baeldung/performancetests/model/source/OrderStatus.java b/performance-tests/src/main/java/com/baeldung/performancetests/model/source/OrderStatus.java new file mode 100644 index 0000000000..962c91a6c4 --- /dev/null +++ b/performance-tests/src/main/java/com/baeldung/performancetests/model/source/OrderStatus.java @@ -0,0 +1,7 @@ +package com.baeldung.performancetests.model.source; + +import com.googlecode.jmapper.annotations.JGlobalMap; + +public enum OrderStatus { + CREATED, CONFIRMED, COLLECTING, IN_TRANSPORT, FINISHED +} diff --git a/performance-tests/src/main/java/com/baeldung/performancetests/model/source/PaymentType.java b/performance-tests/src/main/java/com/baeldung/performancetests/model/source/PaymentType.java new file mode 100644 index 0000000000..fbb4c82afc --- /dev/null +++ b/performance-tests/src/main/java/com/baeldung/performancetests/model/source/PaymentType.java @@ -0,0 +1,7 @@ +package com.baeldung.performancetests.model.source; + +import com.googlecode.jmapper.annotations.JGlobalMap; + +public enum PaymentType { + CASH, CARD, TRANSFER +} diff --git a/performance-tests/src/main/java/com/baeldung/performancetests/model/source/Product.java b/performance-tests/src/main/java/com/baeldung/performancetests/model/source/Product.java new file mode 100644 index 0000000000..5feccb97dc --- /dev/null +++ b/performance-tests/src/main/java/com/baeldung/performancetests/model/source/Product.java @@ -0,0 +1,76 @@ +package com.baeldung.performancetests.model.source; + +import com.googlecode.jmapper.annotations.JGlobalMap; + +import java.math.BigDecimal; + +public class Product { + private BigDecimal price; + private int quantity; + + public Product() { + } + + public BigDecimal getPrice() { + return price; + } + + public void setPrice(BigDecimal price) { + this.price = price; + } + + public int getQuantity() { + return quantity; + } + + public void setQuantity(int quantity) { + this.quantity = quantity; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public boolean isAvailable() { + return available; + } + + public void setAvailable(boolean available) { + this.available = available; + } + + public RefundPolicy getRefundPolicy() { + return refundPolicy; + } + + public void setRefundPolicy(RefundPolicy refundPolicy) { + this.refundPolicy = refundPolicy; + } + + private String name; + + public Product(BigDecimal price, int quantity, String name, String description, boolean available, RefundPolicy refundPolicy) { + this.price = price; + this.quantity = quantity; + this.name = name; + this.description = description; + this.available = available; + this.refundPolicy = refundPolicy; + } + + String description; + boolean available; + private RefundPolicy refundPolicy; +} diff --git a/performance-tests/src/main/java/com/baeldung/performancetests/model/source/RefundPolicy.java b/performance-tests/src/main/java/com/baeldung/performancetests/model/source/RefundPolicy.java new file mode 100644 index 0000000000..5111e27b54 --- /dev/null +++ b/performance-tests/src/main/java/com/baeldung/performancetests/model/source/RefundPolicy.java @@ -0,0 +1,48 @@ +package com.baeldung.performancetests.model.source; + +import com.googlecode.jmapper.annotations.JGlobalMap; +import com.googlecode.jmapper.annotations.JMapAccessor; + +import java.util.List; + +public class RefundPolicy { + @JMapAccessor(get = "isRefundable", set = "setRefundable") + private boolean isRefundable; + private int refundTimeInDays; + + public RefundPolicy() { + } + + public boolean isRefundable() { + return isRefundable; + } + + public void setRefundable(boolean refundable) { + isRefundable = refundable; + } + + public int getRefundTimeInDays() { + return refundTimeInDays; + } + + public void setRefundTimeInDays(int refundTimeInDays) { + this.refundTimeInDays = refundTimeInDays; + } + + public List getNotes() { + return notes; + } + + public void setNotes(List notes) { + this.notes = notes; + } + + public RefundPolicy(boolean isRefundable, int refundTimeInDays, List notes) { + + this.isRefundable = isRefundable; + this.refundTimeInDays = refundTimeInDays; + this.notes = notes; + } + + private List notes; +} diff --git a/performance-tests/src/main/java/com/baeldung/performancetests/model/source/Review.java b/performance-tests/src/main/java/com/baeldung/performancetests/model/source/Review.java new file mode 100644 index 0000000000..8e2630b672 --- /dev/null +++ b/performance-tests/src/main/java/com/baeldung/performancetests/model/source/Review.java @@ -0,0 +1,63 @@ +package com.baeldung.performancetests.model.source; + +public class Review { + + int shippingGrade; + int pricingGrade; + int serviceGrade; + User reviewingUser; + String note; + + public int getShippingGrade() { + return shippingGrade; + } + + public void setShippingGrade(int shippingGrade) { + this.shippingGrade = shippingGrade; + } + + public int getPricingGrade() { + return pricingGrade; + } + + public void setPricingGrade(int pricingGrade) { + this.pricingGrade = pricingGrade; + } + + public int getServiceGrade() { + return serviceGrade; + } + + public void setServiceGrade(int serviceGrade) { + this.serviceGrade = serviceGrade; + } + + public User getReviewingUser() { + return reviewingUser; + } + + public void setReviewingUser(User reviewingUser) { + this.reviewingUser = reviewingUser; + } + + public String getNote() { + return note; + } + + public void setNote(String note) { + this.note = note; + } + + public Review() { + + } + + public Review(int shippingGrade, int pricingGrade, int serviceGrade, User reviewingUser, String note) { + + this.shippingGrade = shippingGrade; + this.pricingGrade = pricingGrade; + this.serviceGrade = serviceGrade; + this.reviewingUser = reviewingUser; + this.note = note; + } +} diff --git a/performance-tests/src/main/java/com/baeldung/performancetests/model/source/Shop.java b/performance-tests/src/main/java/com/baeldung/performancetests/model/source/Shop.java new file mode 100644 index 0000000000..d35681933b --- /dev/null +++ b/performance-tests/src/main/java/com/baeldung/performancetests/model/source/Shop.java @@ -0,0 +1,55 @@ +package com.baeldung.performancetests.model.source; + +import java.util.List; + +public class Shop { + + private String shopName; + private Address shopAddres; + + public String getShopName() { + return shopName; + } + + public void setShopName(String shopName) { + this.shopName = shopName; + } + + public Address getShopAddres() { + return shopAddres; + } + + public void setShopAddres(Address shopAddres) { + this.shopAddres = shopAddres; + } + + public Shop() { + } + + public String getShopUrl() { + return shopUrl; + } + + public void setShopUrl(String shopUrl) { + this.shopUrl = shopUrl; + } + + public List getReviews() { + return reviews; + } + + public void setReviews(List reviews) { + this.reviews = reviews; + } + + public Shop(String shopName, Address shopAddres, String shopUrl, List reviews) { + + this.shopName = shopName; + this.shopAddres = shopAddres; + this.shopUrl = shopUrl; + this.reviews = reviews; + } + + private String shopUrl; + private List reviews; +} diff --git a/performance-tests/src/main/java/com/baeldung/performancetests/model/source/SourceCode.java b/performance-tests/src/main/java/com/baeldung/performancetests/model/source/SourceCode.java new file mode 100644 index 0000000000..52934d6e0b --- /dev/null +++ b/performance-tests/src/main/java/com/baeldung/performancetests/model/source/SourceCode.java @@ -0,0 +1,22 @@ +package com.baeldung.performancetests.model.source; + +public class SourceCode { + String code; + + public SourceCode() { + } + + public String getCode() { + + return code; + } + + public void setCode(String code) { + this.code = code; + } + + public SourceCode(String code) { + + this.code = code; + } +} diff --git a/performance-tests/src/main/java/com/baeldung/performancetests/model/source/SourceOrder.java b/performance-tests/src/main/java/com/baeldung/performancetests/model/source/SourceOrder.java new file mode 100644 index 0000000000..e83a145f6f --- /dev/null +++ b/performance-tests/src/main/java/com/baeldung/performancetests/model/source/SourceOrder.java @@ -0,0 +1,118 @@ +package com.baeldung.performancetests.model.source; + + +import java.util.List; +public class SourceOrder { + private String orderFinishDate; + private PaymentType paymentType; + private Discount discount; + private DeliveryData deliveryData; + private User orderingUser; + private List orderedProducts; + private Shop offeringShop; + private int orderId; + private OrderStatus status; + private String orderDate; + public SourceOrder() { + } + + public User getOrderingUser() { + return orderingUser; + } + + public void setOrderingUser(User orderingUser) { + this.orderingUser = orderingUser; + } + + public List getOrderedProducts() { + return orderedProducts; + } + + public void setOrderedProducts(List orderedProducts) { + this.orderedProducts = orderedProducts; + } + + public OrderStatus getStatus() { + return status; + } + + public void setStatus(OrderStatus status) { + this.status = status; + } + + public String getOrderDate() { + return orderDate; + } + + public void setOrderDate(String orderDate) { + this.orderDate = orderDate; + } + + public String getOrderFinishDate() { + return orderFinishDate; + } + + public void setOrderFinishDate(String orderFinishDate) { + this.orderFinishDate = orderFinishDate; + } + + public PaymentType getPaymentType() { + return paymentType; + } + + public void setPaymentType(PaymentType paymentType) { + this.paymentType = paymentType; + } + + public Discount getDiscount() { + return discount; + } + + public void setDiscount(Discount discount) { + this.discount = discount; + } + + public DeliveryData getDeliveryData() { + return deliveryData; + } + + public void setDeliveryData(DeliveryData deliveryData) { + this.deliveryData = deliveryData; + } + + public Shop getOfferingShop() { + return offeringShop; + } + + public void setOfferingShop(Shop offeringShop) { + this.offeringShop = offeringShop; + } + + + + + + public int getOrderId() { + return orderId; + } + + public void setOrderId(int orderId) { + this.orderId = orderId; + } + + public SourceOrder(OrderStatus status, String orderDate, String orderFinishDate, PaymentType paymentType, Discount discount, DeliveryData deliveryData, User orderingUser, List orderedProducts, Shop offeringShop, int orderId) { + + this.status = status; + this.orderDate = orderDate; + this.orderFinishDate = orderFinishDate; + this.paymentType = paymentType; + this.discount = discount; + this.deliveryData = deliveryData; + this.orderingUser = orderingUser; + this.orderedProducts = orderedProducts; + this.offeringShop = offeringShop; + this.orderId = orderId; + } + + +} diff --git a/performance-tests/src/main/java/com/baeldung/performancetests/model/source/User.java b/performance-tests/src/main/java/com/baeldung/performancetests/model/source/User.java new file mode 100644 index 0000000000..8c50acb560 --- /dev/null +++ b/performance-tests/src/main/java/com/baeldung/performancetests/model/source/User.java @@ -0,0 +1,42 @@ +package com.baeldung.performancetests.model.source; + +import com.googlecode.jmapper.annotations.JGlobalMap; + +public class User { + private String username; + private String email; + private AccountStatus userAccountStatus; + + public User(String username, String email, AccountStatus userAccountStatus) { + this.username = username; + this.email = email; + this.userAccountStatus = userAccountStatus; + } + + public User() { + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public AccountStatus getUserAccountStatus() { + return userAccountStatus; + } + + public void setUserAccountStatus(AccountStatus userAccountStatus) { + this.userAccountStatus = userAccountStatus; + } +} diff --git a/performance-tests/src/main/java/com/baeldung/performancetests/modelmapper/ModelMapperConverter.java b/performance-tests/src/main/java/com/baeldung/performancetests/modelmapper/ModelMapperConverter.java new file mode 100644 index 0000000000..e3f0426e39 --- /dev/null +++ b/performance-tests/src/main/java/com/baeldung/performancetests/modelmapper/ModelMapperConverter.java @@ -0,0 +1,26 @@ +package com.baeldung.performancetests.modelmapper; + +import com.baeldung.performancetests.Converter; +import com.baeldung.performancetests.model.destination.DestinationCode; +import com.baeldung.performancetests.model.source.SourceCode; +import com.baeldung.performancetests.model.source.SourceOrder; +import com.baeldung.performancetests.model.destination.Order; +import org.modelmapper.ModelMapper; + + public class ModelMapperConverter implements Converter { + private ModelMapper modelMapper; + + public ModelMapperConverter() { + modelMapper = new ModelMapper(); + } + + @Override + public Order convert(SourceOrder sourceOrder) { + return modelMapper.map(sourceOrder, Order.class); + } + + @Override + public DestinationCode convert(SourceCode sourceCode) { + return modelMapper.map(sourceCode, DestinationCode.class); + } + } diff --git a/performance-tests/src/main/java/com/baeldung/performancetests/orika/OrikaConverter.java b/performance-tests/src/main/java/com/baeldung/performancetests/orika/OrikaConverter.java new file mode 100644 index 0000000000..994a1830d5 --- /dev/null +++ b/performance-tests/src/main/java/com/baeldung/performancetests/orika/OrikaConverter.java @@ -0,0 +1,31 @@ +package com.baeldung.performancetests.orika; + +import com.baeldung.performancetests.Converter; +import com.baeldung.performancetests.model.destination.DestinationCode; +import com.baeldung.performancetests.model.source.SourceCode; +import com.baeldung.performancetests.model.source.SourceOrder; +import com.baeldung.performancetests.model.destination.Order; +import ma.glasnost.orika.MapperFacade; +import ma.glasnost.orika.MapperFactory; +import ma.glasnost.orika.impl.DefaultMapperFactory; + +public class OrikaConverter implements Converter{ + private MapperFacade mapperFacade; + + public OrikaConverter() { + MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build(); + + mapperFactory.classMap(Order.class, SourceOrder.class).field("orderStatus", "status").byDefault().register(); + mapperFacade = mapperFactory.getMapperFacade(); + } + + @Override + public Order convert(SourceOrder sourceOrder) { + return mapperFacade.map(sourceOrder, Order.class); + } + + @Override + public DestinationCode convert(SourceCode sourceCode) { + return mapperFacade.map(sourceCode, DestinationCode.class); + } +} diff --git a/performance-tests/src/main/resources/dozer-mapping.xml b/performance-tests/src/main/resources/dozer-mapping.xml new file mode 100644 index 0000000000..7fd7e78e9f --- /dev/null +++ b/performance-tests/src/main/resources/dozer-mapping.xml @@ -0,0 +1,25 @@ + + + + + true + MM/dd/yyyy HH:mm + true + + + + com.baeldung.performancetests.model.source.SourceOrder + com.baeldung.performancetests.model.destination.Order + + status + orderStatus + + + + com.baeldung.performancetests.model.source.SourceCode + com.baeldung.performancetests.model.destination.DestinationCode + + \ No newline at end of file diff --git a/performance-tests/src/test/java/com/baeldung/performancetests/benchmark/MappingFrameworksPerformance.java b/performance-tests/src/test/java/com/baeldung/performancetests/benchmark/MappingFrameworksPerformance.java new file mode 100644 index 0000000000..9a45f032a6 --- /dev/null +++ b/performance-tests/src/test/java/com/baeldung/performancetests/benchmark/MappingFrameworksPerformance.java @@ -0,0 +1,193 @@ +package com.baeldung.performancetests.benchmark; + +import com.baeldung.performancetests.dozer.DozerConverter; +import com.baeldung.performancetests.jmapper.JMapperConverter; +import com.baeldung.performancetests.mapstruct.MapStructConverter; +import com.baeldung.performancetests.model.destination.DestinationCode; +import com.baeldung.performancetests.model.source.*; +import com.baeldung.performancetests.model.destination.Order; +import com.baeldung.performancetests.modelmapper.ModelMapperConverter; +import com.baeldung.performancetests.orika.OrikaConverter; +import org.junit.Assert; +import org.junit.Test; +import org.openjdk.jmh.annotations.*; +import org.openjdk.jmh.runner.RunnerException; + +import java.io.IOException; +import java.math.BigDecimal; +import java.time.Instant; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.concurrent.TimeUnit; + +@State(Scope.Group) +public class MappingFrameworksPerformance { + SourceOrder sourceOrder = null; + SourceCode sourceCode = null; + @Setup + public void setUp() { + User user = new User("John", "John@doe.com", AccountStatus.ACTIVE); + RefundPolicy refundPolicy = new RefundPolicy(true, 30, Collections.singletonList("Refundable only if not used!")); + + Product product = new Product(BigDecimal.valueOf(10.99), + 100, + "Sample Product", + "Sample Product to be sold", + true, + refundPolicy + ); + + Discount discount = new Discount(Instant.now().toString(), Instant.now().toString(), BigDecimal.valueOf(5.99)); + Address deliveryAddress = new Address("Washington Street 5", "New York", "55045", "USA"); + DeliveryData deliveryData = new DeliveryData(deliveryAddress, true, "", 10); + Address shopAddress = new Address("Roosvelt Street 9", "Boston", "55042", "USA"); + User reviewingUser = new User("John", "Johhny@John.com", AccountStatus.ACTIVE); + User negativeReviewingUser = new User("Carl", "Carl@Coral.com", AccountStatus.ACTIVE); + Review review = new Review(5, 5, 5, reviewingUser, "The best shop I've ever bought things in"); + + Review negativeReview = new Review(1, 1, 1, negativeReviewingUser, "I will never buy anything again here!"); + + List reviewList = new ArrayList<>(); + reviewList.add(review); + reviewList.add(negativeReview); + Shop shop = new Shop("Super Shop", shopAddress,"www.super-shop.com",reviewList); + + sourceOrder = new SourceOrder(OrderStatus.CONFIRMED, + Instant.now().toString(), + Instant.MAX.toString(), + PaymentType.TRANSFER, + discount, + deliveryData, + user, + Collections.singletonList(product), + shop, + 1 + ); + + sourceCode = new SourceCode("This is source code!"); + } + + + public void main(String[] args) throws IOException, RunnerException { + org.openjdk.jmh.Main.main(args); + } + + + @Benchmark + @Group("realLifeTest") + @Fork(value = 1, warmups = 1) + @OutputTimeUnit(TimeUnit.MILLISECONDS) + @BenchmarkMode(Mode.All) + public void orikaMapperRealLifeBenchmark() { + OrikaConverter orikaConverter = new OrikaConverter(); + Order mappedOrder = orikaConverter.convert(sourceOrder); + Assert.assertEquals(mappedOrder, sourceOrder); + + } + + @Benchmark + @Group("realLifeTest") + @Fork(value = 1, warmups = 1) + @OutputTimeUnit(TimeUnit.MILLISECONDS) + @BenchmarkMode(Mode.All) + public void jmapperRealLifeBenchmark() { + JMapperConverter jmapperConverter = new JMapperConverter(); + Order mappedOrder = jmapperConverter.convert(sourceOrder); + Assert.assertEquals(mappedOrder, sourceOrder); + } + + @Benchmark + @Group("realLifeTest") + @Fork(value = 1, warmups = 1) + @OutputTimeUnit(TimeUnit.MILLISECONDS) + @BenchmarkMode(Mode.All) + public void modelMapperRealLifeBenchmark() { + ModelMapperConverter modelMapperConverter = new ModelMapperConverter(); + Order mappedOrder = modelMapperConverter.convert(sourceOrder); + Assert.assertEquals(mappedOrder, sourceOrder); + } + + + @Benchmark + @Group("realLifeTest") + @Fork(value = 1, warmups = 1) + @OutputTimeUnit(TimeUnit.MILLISECONDS) + @BenchmarkMode(Mode.All) + public void dozerMapperRealLifeBenchmark() { + DozerConverter dozerConverter = new DozerConverter(); + Order mappedOrder = dozerConverter.convert(sourceOrder); + Assert.assertEquals(mappedOrder, sourceOrder); + + } + + @Benchmark + @Group("realLifeTest") + @Fork(value = 1, warmups = 1) + @BenchmarkMode(Mode.All) + public void mapStructRealLifeMapperBenchmark() { + MapStructConverter converter = MapStructConverter.MAPPER; + Order mappedOrder = converter.convert(sourceOrder); + Assert.assertEquals(mappedOrder, sourceOrder); + } + + @Benchmark + @Group("simpleTest") + @Fork(value = 1, warmups = 1) + @OutputTimeUnit(TimeUnit.MILLISECONDS) + @BenchmarkMode(Mode.All) + public void orikaMapperSimpleBenchmark() { + OrikaConverter orikaConverter = new OrikaConverter(); + DestinationCode mappedCode = orikaConverter.convert(sourceCode); + Assert.assertEquals(mappedCode.getCode(), sourceCode.getCode()); + + } + + @Benchmark + @Group("simpleTest") + @Fork(value = 1, warmups = 1) + @OutputTimeUnit(TimeUnit.MILLISECONDS) + @BenchmarkMode(Mode.All) + public void jmapperSimpleBenchmark() { + JMapperConverter jmapperConverter = new JMapperConverter(); + DestinationCode mappedCode = jmapperConverter.convert(sourceCode); + Assert.assertEquals(mappedCode.getCode(), sourceCode.getCode()); + } + + @Benchmark + @Group("simpleTest") + @Fork(value = 1, warmups = 1) + @OutputTimeUnit(TimeUnit.MILLISECONDS) + @BenchmarkMode(Mode.All) + public void modelMapperBenchmark() { + ModelMapperConverter modelMapperConverter = new ModelMapperConverter(); + DestinationCode mappedCode = modelMapperConverter.convert(sourceCode); + Assert.assertEquals(mappedCode.getCode(), sourceCode.getCode()); + } + + + @Benchmark + @Group("simpleTest") + @Fork(value = 1, warmups = 1) + @OutputTimeUnit(TimeUnit.MILLISECONDS) + @BenchmarkMode(Mode.All) + public void dozerMapperSimpleBenchmark() { + DozerConverter dozerConverter = new DozerConverter(); + Order mappedOrder = dozerConverter.convert(sourceOrder); + Assert.assertEquals(mappedOrder, sourceOrder); + + } + + @Benchmark + @Group("simpleTest") + @Fork(value = 1, warmups = 1) + @OutputTimeUnit(TimeUnit.MILLISECONDS) + @BenchmarkMode(Mode.All) + public void mapStructMapperSimpleBenchmark() { + MapStructConverter converter = MapStructConverter.MAPPER; + DestinationCode mappedCode = converter.convert(sourceCode); + Assert.assertEquals(mappedCode.getCode(), sourceCode.getCode()); + } + + +} diff --git a/performance-tests/src/test/resources/dozer-mapping.xml b/performance-tests/src/test/resources/dozer-mapping.xml new file mode 100644 index 0000000000..7484812431 --- /dev/null +++ b/performance-tests/src/test/resources/dozer-mapping.xml @@ -0,0 +1,21 @@ + + + + + true + MM/dd/yyyy HH:mm + true + + + + com.baeldung.performancetests.model.source.SourceOrder + com.baeldung.performancetests.model.destination.Order + + status + orderStatus + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index 3ba6b0c8df..78e0fa925e 100644 --- a/pom.xml +++ b/pom.xml @@ -256,6 +256,7 @@ persistence-modules/java-jdbi jersey java-spi + performance-tests
From b2e489ca6460eb2316ff5f56830b2096685fb855 Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Tue, 8 May 2018 21:16:49 +0300 Subject: [PATCH 48/66] emptyiterable ex --- .../java/org/baeldung/hamcrest/HamcrestExamplesUnitTest.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/guava/src/test/java/org/baeldung/hamcrest/HamcrestExamplesUnitTest.java b/guava/src/test/java/org/baeldung/hamcrest/HamcrestExamplesUnitTest.java index 6b9cee1992..0ddeab90a1 100644 --- a/guava/src/test/java/org/baeldung/hamcrest/HamcrestExamplesUnitTest.java +++ b/guava/src/test/java/org/baeldung/hamcrest/HamcrestExamplesUnitTest.java @@ -12,6 +12,7 @@ import static org.hamcrest.Matchers.hasItems; import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.not; import static org.junit.Assert.assertThat; +import static org.hamcrest.Matchers.emptyIterable; import java.util.Collections; import java.util.List; @@ -56,6 +57,7 @@ public class HamcrestExamplesUnitTest { public final void givenCollectionIsEmpty_whenChecking_thenEmpty() { final List collection = Lists.newArrayList(); assertThat(collection, empty()); + assertThat(collection, emptyIterable()); } @Test From 4e7efb139583cc7c1ee8af748286bcda7103134a Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Tue, 8 May 2018 21:20:53 +0300 Subject: [PATCH 49/66] emptyiterable ex --- .../org/baeldung/hamcrest/HamcrestExamplesUnitTest.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/guava/src/test/java/org/baeldung/hamcrest/HamcrestExamplesUnitTest.java b/guava/src/test/java/org/baeldung/hamcrest/HamcrestExamplesUnitTest.java index 0ddeab90a1..efecc39bcd 100644 --- a/guava/src/test/java/org/baeldung/hamcrest/HamcrestExamplesUnitTest.java +++ b/guava/src/test/java/org/baeldung/hamcrest/HamcrestExamplesUnitTest.java @@ -59,6 +59,12 @@ public class HamcrestExamplesUnitTest { assertThat(collection, empty()); assertThat(collection, emptyIterable()); } + + @Test + public final void givenIterableIsEmpty_whenChecking_thenEmpty() { + final Iterable collection = Lists.newArrayList(); + assertThat(collection, emptyIterable()); + } @Test public final void givenCollectionIsNotEmpty_whenChecking_thenNotEmpty() { From 75afb5da3e4e0cecbbd93aca67997c0a2dfc5c82 Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Tue, 8 May 2018 21:21:22 +0300 Subject: [PATCH 50/66] emptyiterable ex --- .../java/org/baeldung/hamcrest/HamcrestExamplesUnitTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/guava/src/test/java/org/baeldung/hamcrest/HamcrestExamplesUnitTest.java b/guava/src/test/java/org/baeldung/hamcrest/HamcrestExamplesUnitTest.java index efecc39bcd..82b6b8c87c 100644 --- a/guava/src/test/java/org/baeldung/hamcrest/HamcrestExamplesUnitTest.java +++ b/guava/src/test/java/org/baeldung/hamcrest/HamcrestExamplesUnitTest.java @@ -57,7 +57,6 @@ public class HamcrestExamplesUnitTest { public final void givenCollectionIsEmpty_whenChecking_thenEmpty() { final List collection = Lists.newArrayList(); assertThat(collection, empty()); - assertThat(collection, emptyIterable()); } @Test From 08c0b590b04b5e23018fe5846cd282e81201731a Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Tue, 8 May 2018 22:04:21 +0300 Subject: [PATCH 51/66] upgrade bootstrap project --- spring-boot-bootstrap/pom.xml | 4 ++-- .../org/baeldung/config/SecurityConfig.java | 20 +++++++++++++++++++ .../persistence/repo/BookRepository.java | 1 - .../java/org/baeldung/web/BookController.java | 12 ++++++----- .../src/main/resources/application.properties | 6 ++---- .../SpringBootBootstrapIntegrationTest.java | 10 +++------- 6 files changed, 34 insertions(+), 19 deletions(-) create mode 100644 spring-boot-bootstrap/src/main/java/org/baeldung/config/SecurityConfig.java diff --git a/spring-boot-bootstrap/pom.xml b/spring-boot-bootstrap/pom.xml index 1ec9af8189..03ce9b6906 100644 --- a/spring-boot-bootstrap/pom.xml +++ b/spring-boot-bootstrap/pom.xml @@ -9,10 +9,10 @@ Demo project for Spring Boot - parent-boot-5 + parent-boot-2 com.baeldung 0.0.1-SNAPSHOT - ../parent-boot-5 + ../parent-boot-2 - - + + - - contextClass - - org.springframework.web.context.support.AnnotationConfigWebApplicationContext - - - - contextConfigLocation - org.baeldung.spring.web.config - - - - org.springframework.web.context.ContextLoaderListener - - - - - mvc - org.springframework.web.servlet.DispatcherServlet - 1 - - - mvc - / - - - - index.html - - - \ No newline at end of file From 8d05a42c30ddadae90f9877cee77ffd85fc5ff1a Mon Sep 17 00:00:00 2001 From: Nikhil Khatwani Date: Wed, 9 May 2018 18:03:35 +0530 Subject: [PATCH 54/66] Changes for BAEL-1657 --- .../DeferredResultController.java | 33 +++++++++++-------- 1 file changed, 19 insertions(+), 14 deletions(-) rename {spring-boot/src/main/java/com/baeldung/servlets => spring-rest/src/main/java/com/baeldung/controllers}/DeferredResultController.java (76%) diff --git a/spring-boot/src/main/java/com/baeldung/servlets/DeferredResultController.java b/spring-rest/src/main/java/com/baeldung/controllers/DeferredResultController.java similarity index 76% rename from spring-boot/src/main/java/com/baeldung/servlets/DeferredResultController.java rename to spring-rest/src/main/java/com/baeldung/controllers/DeferredResultController.java index c43b0e6dc0..c61d51e1af 100644 --- a/spring-boot/src/main/java/com/baeldung/servlets/DeferredResultController.java +++ b/spring-rest/src/main/java/com/baeldung/controllers/DeferredResultController.java @@ -1,4 +1,4 @@ -package com.baeldung.servlets; +package com.baeldung.controllers; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -9,6 +9,8 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.context.request.async.DeferredResult; +import java.util.concurrent.ForkJoinPool; + @RestController public class DeferredResultController { @@ -16,14 +18,18 @@ public class DeferredResultController { @GetMapping("/async-deferredresult") public DeferredResult> handleReqDefResult(Model model) { - LOG.info("Received async-deferredresult request"); - DeferredResult> output = new DeferredResult<>(); - new Thread(() -> { - LOG.info("Processing in separate thread"); - output.setResult(ResponseEntity.ok("ok")); - }).start(); - LOG.info("servlet thread freed"); - return output; + LOG.info("Received async-deferredresult request"); + DeferredResult> output = new DeferredResult<>(); + ForkJoinPool.commonPool().submit(() -> { + LOG.info("Processing in separate thread"); + try { + Thread.sleep(6000); + } catch (InterruptedException e) { + } + output.setResult(ResponseEntity.ok("ok")); + }); + LOG.info("servlet thread freed"); + return output; } public DeferredResult> handleReqWithTimeouts(Model model) { @@ -36,8 +42,7 @@ public class DeferredResultController { ResponseEntity.status(HttpStatus.REQUEST_TIMEOUT).body("Request timeout occurred.")); } }); - - new Thread(() -> { + ForkJoinPool.commonPool().submit(() -> { LOG.info("Processing in separate thread"); try { Thread.sleep(600l); @@ -48,14 +53,14 @@ public class DeferredResultController { .body("INTERNAL_SERVER_ERROR occurred.")); } - }).start(); + }); LOG.info("servlet thread freed"); return deferredResult; } public DeferredResult> handleAsyncFailedRequest(Model model) { DeferredResult> deferredResult = new DeferredResult<>(); - new Thread(() -> { + ForkJoinPool.commonPool().submit(() -> { try { // Exception occurred in processing throw new Exception(); @@ -64,7 +69,7 @@ public class DeferredResultController { deferredResult.setErrorResult(ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) .body("INTERNAL_SERVER_ERROR occurred.")); } - }).start(); + }); return deferredResult; } From 475931974b425314433df55bd8e032114b5021eb Mon Sep 17 00:00:00 2001 From: KevinGilmore Date: Thu, 10 May 2018 07:31:19 -0500 Subject: [PATCH 55/66] README links for BAEL-82 and BAEL-1722 (#4210) * BAEL-1612: Update README * BAEL-1562: Update README * BAEL-1562: Update README * BAEL-1679: Update README * BAEL-1701: Update README * Added article links to README files --- patterns/README.md | 1 + spring-all/README.md | 1 + 2 files changed, 2 insertions(+) diff --git a/patterns/README.md b/patterns/README.md index f00e7c351d..df39b39224 100644 --- a/patterns/README.md +++ b/patterns/README.md @@ -3,4 +3,5 @@ - [Introduction to Intercepting Filter Pattern in Java](http://www.baeldung.com/intercepting-filter-pattern-in-java) - [Implementing the Template Method Pattern in Java](http://www.baeldung.com/java-template-method-pattern) - [Chain of Responsibility Design Pattern in Java](http://www.baeldung.com/chain-of-responsibility-pattern) +- [The Command Pattern in Java](http://www.baeldung.com/java-command-pattern) diff --git a/spring-all/README.md b/spring-all/README.md index a3e1ca5464..173f410620 100644 --- a/spring-all/README.md +++ b/spring-all/README.md @@ -27,3 +27,4 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [A Guide To Caching in Spring](http://www.baeldung.com/spring-cache-tutorial) - [How To Do @Async in Spring](http://www.baeldung.com/spring-async) - [Quick Guide to the Spring @Order Annotation](http://www.baeldung.com/spring-order) +- [Spring Web Contexts](http://www.baeldung.com/spring-web-contexts) From d9ddaa8e0835462a9cb8b9d56fb86976b1862669 Mon Sep 17 00:00:00 2001 From: xenteros Date: Thu, 10 May 2018 17:32:20 +0300 Subject: [PATCH 56/66] Add sources for BAEL-468 (#4171) * Added POJO, * Added DTO, * Added Mapper --- .../java/com/baeldung/dto/TransactionDTO.java | 23 +++++++++++++++++++ .../java/com/baeldung/entity/Transaction.java | 23 +++++++++++++++++++ .../baeldung/mapper/TransactionMapper.java | 23 +++++++++++++++++++ 3 files changed, 69 insertions(+) create mode 100644 mapstruct/src/main/java/com/baeldung/dto/TransactionDTO.java create mode 100644 mapstruct/src/main/java/com/baeldung/entity/Transaction.java create mode 100644 mapstruct/src/main/java/com/baeldung/mapper/TransactionMapper.java diff --git a/mapstruct/src/main/java/com/baeldung/dto/TransactionDTO.java b/mapstruct/src/main/java/com/baeldung/dto/TransactionDTO.java new file mode 100644 index 0000000000..132607ddd6 --- /dev/null +++ b/mapstruct/src/main/java/com/baeldung/dto/TransactionDTO.java @@ -0,0 +1,23 @@ +package com.baeldung.dto; + +public class TransactionDTO { + + private String uuid; + private Long totalInCents; + + public String getUuid() { + return uuid; + } + + public void setUuid(String uuid) { + this.uuid = uuid; + } + + public Long getTotalInCents() { + return totalInCents; + } + + public void setTotalInCents(Long totalInCents) { + this.totalInCents = totalInCents; + } +} diff --git a/mapstruct/src/main/java/com/baeldung/entity/Transaction.java b/mapstruct/src/main/java/com/baeldung/entity/Transaction.java new file mode 100644 index 0000000000..fd2a09e7ce --- /dev/null +++ b/mapstruct/src/main/java/com/baeldung/entity/Transaction.java @@ -0,0 +1,23 @@ +package com.baeldung.entity; + +import java.math.BigDecimal; +import java.util.UUID; + +public class Transaction { + + private Long id; + private String uuid = UUID.randomUUID().toString(); + private BigDecimal total; + + public Long getId() { + return id; + } + + public String getUuid() { + return uuid; + } + + public BigDecimal getTotal() { + return total; + } +} diff --git a/mapstruct/src/main/java/com/baeldung/mapper/TransactionMapper.java b/mapstruct/src/main/java/com/baeldung/mapper/TransactionMapper.java new file mode 100644 index 0000000000..42957bff46 --- /dev/null +++ b/mapstruct/src/main/java/com/baeldung/mapper/TransactionMapper.java @@ -0,0 +1,23 @@ +package com.baeldung.mapper; + +import java.math.BigDecimal; +import java.util.Collection; +import java.util.List; + +import org.mapstruct.Mapper; + +import com.baeldung.dto.TransactionDTO; +import com.baeldung.entity.Transaction; + +@Mapper +abstract class TransactionMapper { + + public TransactionDTO toTransactionDTO(Transaction transaction) { + TransactionDTO transactionDTO = new TransactionDTO(); + transactionDTO.setUuid(transaction.getUuid()); + transactionDTO.setTotalInCents(transaction.getTotal().multiply(new BigDecimal("100")).longValue()); + return transactionDTO; + } + + public abstract List toTransactionDTO(Collection transactions); +} From db77297fa1db5879dcedad77b12c2a2ba3015b9e Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Thu, 10 May 2018 20:19:35 +0300 Subject: [PATCH 57/66] update charset class --- .../org/baeldung/httpclient/sec/HttpClientAuthLiveTest.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/httpclient/src/test/java/org/baeldung/httpclient/sec/HttpClientAuthLiveTest.java b/httpclient/src/test/java/org/baeldung/httpclient/sec/HttpClientAuthLiveTest.java index 7a75729ea5..c9956e5852 100644 --- a/httpclient/src/test/java/org/baeldung/httpclient/sec/HttpClientAuthLiveTest.java +++ b/httpclient/src/test/java/org/baeldung/httpclient/sec/HttpClientAuthLiveTest.java @@ -24,6 +24,7 @@ import org.junit.Test; import java.io.IOException; import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import static org.hamcrest.Matchers.equalTo; import static org.junit.Assert.assertThat; @@ -89,7 +90,7 @@ public class HttpClientAuthLiveTest { public final void givenAuthorizationHeaderIsSetManually_whenExecutingGetRequest_thenSuccess2() throws IOException { final HttpGet request = new HttpGet(URL_SECURED_BY_BASIC_AUTHENTICATION); final String auth = DEFAULT_USER + ":" + DEFAULT_PASS; - final byte[] encodedAuth = Base64.encodeBase64(auth.getBytes(Charset.forName("ISO-8859-1"))); + final byte[] encodedAuth = Base64.encodeBase64(auth.getBytes(StandardCharsets.ISO_8859_1)); final String authHeader = "Basic " + new String(encodedAuth); request.setHeader(HttpHeaders.AUTHORIZATION, authHeader); @@ -129,7 +130,7 @@ public class HttpClientAuthLiveTest { private String authorizationHeader(final String username, final String password) { final String auth = username + ":" + password; - final byte[] encodedAuth = Base64.encodeBase64(auth.getBytes(Charset.forName("ISO-8859-1"))); + final byte[] encodedAuth = Base64.encodeBase64(auth.getBytes(StandardCharsets.ISO_8859_1)); return "Basic " + new String(encodedAuth); } From 6fdd23bd3d8fbfcaa263d4279ef6c8c597b657b1 Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Thu, 10 May 2018 21:08:56 +0300 Subject: [PATCH 58/66] fix boot project --- .../boot/monitor/jmx/MonitoringConfig.java | 21 ------------------- spring-boot/src/test/resources/data.sql | 5 ----- spring-boot/src/test/resources/schema.sql | 5 ----- 3 files changed, 31 deletions(-) delete mode 100644 spring-boot/src/main/java/org/baeldung/boot/monitor/jmx/MonitoringConfig.java delete mode 100644 spring-boot/src/test/resources/data.sql delete mode 100644 spring-boot/src/test/resources/schema.sql diff --git a/spring-boot/src/main/java/org/baeldung/boot/monitor/jmx/MonitoringConfig.java b/spring-boot/src/main/java/org/baeldung/boot/monitor/jmx/MonitoringConfig.java deleted file mode 100644 index 28c6ac5953..0000000000 --- a/spring-boot/src/main/java/org/baeldung/boot/monitor/jmx/MonitoringConfig.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.baeldung.boot.monitor.jmx; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -import com.codahale.metrics.JmxReporter; -import com.codahale.metrics.MetricRegistry; - -@Configuration -public class MonitoringConfig { - @Autowired - private MetricRegistry registry; - - @Bean - public JmxReporter jmxReporter() { - JmxReporter reporter = JmxReporter.forRegistry(registry).build(); - reporter.start(); - return reporter; - } -} diff --git a/spring-boot/src/test/resources/data.sql b/spring-boot/src/test/resources/data.sql deleted file mode 100644 index f36e034ce1..0000000000 --- a/spring-boot/src/test/resources/data.sql +++ /dev/null @@ -1,5 +0,0 @@ -INSERT INTO country (name) VALUES ('India'); -INSERT INTO country (name) VALUES ('Brazil'); -INSERT INTO country (name) VALUES ('USA'); -INSERT INTO country (name) VALUES ('Italy'); -COMMIT; diff --git a/spring-boot/src/test/resources/schema.sql b/spring-boot/src/test/resources/schema.sql deleted file mode 100644 index 15d7788cd7..0000000000 --- a/spring-boot/src/test/resources/schema.sql +++ /dev/null @@ -1,5 +0,0 @@ -CREATE TABLE country ( - id INTEGER NOT NULL AUTO_INCREMENT, - name VARCHAR(128) NOT NULL, - PRIMARY KEY (id) -); From ea4b7a9bb54fcd4c6c17052f8cb0d74015c20244 Mon Sep 17 00:00:00 2001 From: DOHA Date: Thu, 10 May 2018 21:46:58 +0300 Subject: [PATCH 59/66] dom parsing --- .../com/baeldung/xml/XercesDomUnitTest.java | 139 ++++++++++++++++++ xml/src/test/resources/Xerces_dom.xml | 1 + 2 files changed, 140 insertions(+) create mode 100644 xml/src/test/java/com/baeldung/xml/XercesDomUnitTest.java create mode 100644 xml/src/test/resources/Xerces_dom.xml diff --git a/xml/src/test/java/com/baeldung/xml/XercesDomUnitTest.java b/xml/src/test/java/com/baeldung/xml/XercesDomUnitTest.java new file mode 100644 index 0000000000..a5091c62fc --- /dev/null +++ b/xml/src/test/java/com/baeldung/xml/XercesDomUnitTest.java @@ -0,0 +1,139 @@ +package com.baeldung.xml; + +import static org.junit.Assert.assertEquals; + +import java.io.File; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; + +import org.junit.Before; +import org.junit.Test; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NamedNodeMap; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +public class XercesDomUnitTest { + + final private String FILE_NAME = "src/test/resources/example_jdom.xml"; + final private String OUTPUT_DOM = "src/test/resources/Xerces_dom.xml"; + + private Document doc; + private DocumentBuilder builder; + + @Before + public void loadXmlFile() throws Exception { + if (doc == null) { + builder = DocumentBuilderFactory.newInstance() + .newDocumentBuilder(); + doc = builder.parse(new File(FILE_NAME)); + doc.getDocumentElement() + .normalize(); + } + } + + @Test + public void whenGetElementByTag_thenSuccess() { + NodeList nodeList = doc.getElementsByTagName("tutorial"); + Node first = nodeList.item(0); + + assertEquals(4, nodeList.getLength()); + assertEquals(Node.ELEMENT_NODE, first.getNodeType()); + assertEquals("tutorial", first.getNodeName()); + } + + @Test + public void whenGetFirstElementAttributes_thenSuccess() { + Node first = doc.getElementsByTagName("tutorial") + .item(0); + NamedNodeMap attrList = first.getAttributes(); + + assertEquals(2, attrList.getLength()); + + assertEquals("tutId", attrList.item(0) + .getNodeName()); + assertEquals("01", attrList.item(0) + .getNodeValue()); + + assertEquals("type", attrList.item(1) + .getNodeName()); + assertEquals("java", attrList.item(1) + .getNodeValue()); + } + + + @Test + public void whenTraverseChildNodes_thenSuccess() { + Node first = doc.getElementsByTagName("tutorial") + .item(0); + NodeList nodeList = first.getChildNodes(); + int n = nodeList.getLength(); + + Node current; + for (int i = 0; i < n; i++) { + current = nodeList.item(i); + if (current.getNodeType() == Node.ELEMENT_NODE) { + System.out.println(current.getNodeName() + ": " + current.getTextContent()); + } + } + } + + @Test + public void whenModifyElementAttribute_thenModified() { + NodeList nodeList = doc.getElementsByTagName("tutorial"); + Element first = (Element) nodeList.item(0); + assertEquals("java", first.getAttribute("type")); + + first.setAttribute("type", "other"); + assertEquals("other", first.getAttribute("type")); + } + + + @Test + public void whenCreateNewDocument_thenCreated() throws Exception { + Document newDoc = builder.newDocument(); + Element root = newDoc.createElement("users"); + newDoc.appendChild(root); + + Element first = newDoc.createElement("user"); + root.appendChild(first); + first.setAttribute("id", "1"); + + Element email = newDoc.createElement("email"); + email.appendChild(newDoc.createTextNode("john@example.com")); + first.appendChild(email); + + assertEquals(1, newDoc.getChildNodes() + .getLength()); + assertEquals("users", newDoc.getChildNodes() + .item(0) + .getNodeName()); + + printDom(newDoc); + saveDomToFile(newDoc, OUTPUT_DOM); + } + + private void printDom(Document document) throws Exception { + DOMSource dom = new DOMSource(document); + Transformer transformer = TransformerFactory.newInstance() + .newTransformer(); + + transformer.transform(dom, new StreamResult(System.out)); + } + + private void saveDomToFile(Document document, String fileName) throws Exception { + DOMSource dom = new DOMSource(document); + Transformer transformer = TransformerFactory.newInstance() + .newTransformer(); + + StreamResult result = new StreamResult(new File(fileName)); + transformer.transform(dom, result); + } + +} diff --git a/xml/src/test/resources/Xerces_dom.xml b/xml/src/test/resources/Xerces_dom.xml new file mode 100644 index 0000000000..5b148606af --- /dev/null +++ b/xml/src/test/resources/Xerces_dom.xml @@ -0,0 +1 @@ +john@example.com \ No newline at end of file From 07838a2d254bbfd934660ed90601b58b6d7eafe8 Mon Sep 17 00:00:00 2001 From: ramansahasi Date: Fri, 11 May 2018 02:11:33 +0530 Subject: [PATCH 60/66] BAEL-1739 - Check If a String is Numeric in Java (#4209) * BAEL-1725 Java Pass-by-reference vs Pass-by-value - First commit * updated test cases * First commit consisting only of test cases * First commit with test cases * Introduced JMH Michrobenchmarking * Minor corrections --- .../stringisnumeric/Benchmarking.java | 75 ++++++++++++++++++ .../baeldung/stringisnumeric/IsNumeric.java | 35 ++++++++ .../stringisnumeric/IsNumericDriver.java | 33 ++++++++ .../java/com/baeldung/stringisnumeric.zip | Bin 0 -> 3227 bytes .../CoreJavaIsNumericUnitTest.java | 31 ++++++++ .../NumberUtilsIsCreatableUnitTest.java | 28 +++++++ .../NumberUtilsIsParsableUnitTest.java | 26 ++++++ .../RegularExpressionsUnitTest.java | 22 +++++ .../StringUtilsIsNumericSpaceUnitTest.java | 23 ++++++ .../StringUtilsIsNumericUnitTest.java | 24 ++++++ 10 files changed, 297 insertions(+) create mode 100644 core-java/src/main/java/com/baeldung/stringisnumeric/Benchmarking.java create mode 100644 core-java/src/main/java/com/baeldung/stringisnumeric/IsNumeric.java create mode 100644 core-java/src/main/java/com/baeldung/stringisnumeric/IsNumericDriver.java create mode 100644 core-java/src/test/java/com/baeldung/stringisnumeric.zip create mode 100644 core-java/src/test/java/com/baeldung/stringisnumeric/CoreJavaIsNumericUnitTest.java create mode 100644 core-java/src/test/java/com/baeldung/stringisnumeric/NumberUtilsIsCreatableUnitTest.java create mode 100644 core-java/src/test/java/com/baeldung/stringisnumeric/NumberUtilsIsParsableUnitTest.java create mode 100644 core-java/src/test/java/com/baeldung/stringisnumeric/RegularExpressionsUnitTest.java create mode 100644 core-java/src/test/java/com/baeldung/stringisnumeric/StringUtilsIsNumericSpaceUnitTest.java create mode 100644 core-java/src/test/java/com/baeldung/stringisnumeric/StringUtilsIsNumericUnitTest.java diff --git a/core-java/src/main/java/com/baeldung/stringisnumeric/Benchmarking.java b/core-java/src/main/java/com/baeldung/stringisnumeric/Benchmarking.java new file mode 100644 index 0000000000..4ae1f5aa83 --- /dev/null +++ b/core-java/src/main/java/com/baeldung/stringisnumeric/Benchmarking.java @@ -0,0 +1,75 @@ +package com.baeldung.stringisnumeric; + +import java.util.concurrent.TimeUnit; + +import org.openjdk.jmh.annotations.Benchmark; +import org.openjdk.jmh.annotations.BenchmarkMode; +import org.openjdk.jmh.annotations.Mode; +import org.openjdk.jmh.annotations.OutputTimeUnit; +import org.openjdk.jmh.annotations.Scope; +import org.openjdk.jmh.annotations.State; +import org.openjdk.jmh.runner.Runner; +import org.openjdk.jmh.runner.RunnerException; +import org.openjdk.jmh.runner.options.Options; +import org.openjdk.jmh.runner.options.OptionsBuilder; + + +public class Benchmarking { + public static void main(String[] args) throws RunnerException { + Options opt = new OptionsBuilder() + .include(Benchmarking.class.getSimpleName()) + .forks(1) + .build(); + + new Runner(opt).run(); + } + + @State(Scope.Thread) + public static class ExecutionPlan { + public String number = Integer.toString(Integer.MAX_VALUE); + public boolean isNumber = false; + public IsNumeric isNumeric= new IsNumeric(); + } + + @Benchmark + @BenchmarkMode(Mode.AverageTime) + @OutputTimeUnit(TimeUnit.NANOSECONDS) + public void usingCoreJava(ExecutionPlan plan) { + plan.isNumber = plan.isNumeric.usingCoreJava(plan.number); + } + + @Benchmark + @BenchmarkMode(Mode.AverageTime) + @OutputTimeUnit(TimeUnit.NANOSECONDS) + public void usingRegularExpressions(ExecutionPlan plan) { + plan.isNumber = plan.isNumeric.usingRegularExpressions(plan.number); + } + + @Benchmark + @BenchmarkMode(Mode.AverageTime) + @OutputTimeUnit(TimeUnit.NANOSECONDS) + public void usingNumberUtils_isCreatable(ExecutionPlan plan) { + plan.isNumber = plan.isNumeric.usingNumberUtils_isCreatable(plan.number); + } + + @Benchmark + @BenchmarkMode(Mode.AverageTime) + @OutputTimeUnit(TimeUnit.NANOSECONDS) + public void usingNumberUtils_isParsable(ExecutionPlan plan) { + plan.isNumber = plan.isNumeric.usingNumberUtils_isParsable(plan.number); + } + + @Benchmark + @BenchmarkMode(Mode.AverageTime) + @OutputTimeUnit(TimeUnit.NANOSECONDS) + public void usingStringUtils_isNumeric(ExecutionPlan plan) { + plan.isNumber = plan.isNumeric.usingStringUtils_isNumeric(plan.number); + } + + @Benchmark + @BenchmarkMode(Mode.AverageTime) + @OutputTimeUnit(TimeUnit.NANOSECONDS) + public void usingStringUtils_isNumericSpace(ExecutionPlan plan) { + plan.isNumber = plan.isNumeric.usingStringUtils_isNumericSpace(plan.number); + } +} \ No newline at end of file diff --git a/core-java/src/main/java/com/baeldung/stringisnumeric/IsNumeric.java b/core-java/src/main/java/com/baeldung/stringisnumeric/IsNumeric.java new file mode 100644 index 0000000000..c438071e42 --- /dev/null +++ b/core-java/src/main/java/com/baeldung/stringisnumeric/IsNumeric.java @@ -0,0 +1,35 @@ +package com.baeldung.stringisnumeric; + +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.math.NumberUtils; + +public class IsNumeric { + public boolean usingCoreJava(String strNum) { + try { + double d = Double.parseDouble(strNum); + } catch (NumberFormatException | NullPointerException nfe) { + return false; + } + return true; + } + + public boolean usingRegularExpressions(String strNum) { + return strNum.matches("-?\\d+(\\.\\d+)?"); + } + + public boolean usingNumberUtils_isCreatable(String strNum) { + return NumberUtils.isCreatable(strNum); + } + + public boolean usingNumberUtils_isParsable(String strNum) { + return NumberUtils.isParsable(strNum); + } + + public boolean usingStringUtils_isNumeric(String strNum) { + return StringUtils.isNumeric(strNum); + } + + public boolean usingStringUtils_isNumericSpace(String strNum) { + return StringUtils.isNumericSpace(strNum); + } +} diff --git a/core-java/src/main/java/com/baeldung/stringisnumeric/IsNumericDriver.java b/core-java/src/main/java/com/baeldung/stringisnumeric/IsNumericDriver.java new file mode 100644 index 0000000000..3dc2b6632a --- /dev/null +++ b/core-java/src/main/java/com/baeldung/stringisnumeric/IsNumericDriver.java @@ -0,0 +1,33 @@ +package com.baeldung.stringisnumeric; + +import static com.baeldung.designpatterns.util.LogerUtil.LOG; + +public class IsNumericDriver { + private static IsNumeric isNumeric; + + static { + isNumeric =new IsNumeric(); + } + + public static void main(String[] args) { + LOG.info("Testing all methods..."); + + boolean res = isNumeric.usingCoreJava("1001"); + LOG.info("Using Core Java : " + res); + + res = isNumeric.usingRegularExpressions("1001"); + LOG.info("Using Regular Expressions : " + res); + + res =isNumeric.usingNumberUtils_isCreatable("1001"); + LOG.info("Using NumberUtils.isCreatable : " + res); + + res =isNumeric.usingNumberUtils_isParsable("1001"); + LOG.info("Using NumberUtils.isParsable : " + res); + + res =isNumeric.usingStringUtils_isNumeric("1001"); + LOG.info("Using StringUtils.isNumeric : " + res); + + res =isNumeric.usingStringUtils_isNumericSpace("1001"); + LOG.info("Using StringUtils.isNumericSpace : " + res); + } +} diff --git a/core-java/src/test/java/com/baeldung/stringisnumeric.zip b/core-java/src/test/java/com/baeldung/stringisnumeric.zip new file mode 100644 index 0000000000000000000000000000000000000000..b8a7b9b35a09fea091423fe1c08e771d6be48112 GIT binary patch literal 3227 zcmb7`3p|r;AIFE8Q#sT~iO3?$jHZaC7KOJ* zaw>Ajnb{*sN(|9UdG7V*(~9?fdar#x`|rL#*S-Ju{{61&fBg|wTwo}OHSRgxvi|nt z`qk&N1KdqG_QbNzKv>uDt^NjGc^=ySm$o9%`v@T?&+2AZwIeizN0te6c_{1Z@4cN(MNL$2~mO{t>34e+Fg4dh^c zmAlykHVhA)D&DR-aQ1%rdb1 z<{xhfi8NNB3GdHJIVtX#AGVl`q#ZK!QPev?do6Jr6G^^#O6aSg?zN%`hkef%3SS&7 z7?4P>TgsU0Kbuu&-hIaXWi5A4 zjgpB=-F}P#TTl|QIA5qzuzUHY(e(hz!W;Q#){r#r6>k5D%ohthKb(mGoOyC(gQ_Ut z%z3~WwRM~U{BXwN?FcweKMTLZcr1p1arVUiWKV9AzDJ#^aQz$cWl3X&;9Jh<1LttO z(8nY}{~lkIpd&?2BKN%@nO@D@amgw}K{`3GivDOpOZYlMc5}(NXr9(W;rQ!2u={eI z9u+pO7-5J_KnXE^yXNlW9v*_m?nBXW-8*C8%sRQo?w3q^*a&Lc`g6j@AoIzyhzQE{ zN=VN%&B@-~YL_TBEZNGZV3fPVvwJ?BDH6rB>g8{qa2MH*=Z)0cEiMt5;W`MJ7oj!fA9@zrVMI{@0Uo_J)kaugbM-YyRXB57_xXi~DcAn#h%KHJ8 z7df~GAb`pj0hJH@lgbDT-fykQ?YbaG6+R-q%O}1F{(|d zcrHnhyi!e-+?Kf)CpK{PW932=*_AhP&+myRJFmLCVFDjWF40(O zhurj+K)P9n;+Ik-;r<>f@{fgfyHw6?_FM7g5Ll3IPHSPIw+_V6ko#tIgQe2WfBBO7 zWzAoSpX=dxrd{Pb5XoQrJaz=bCgrsjaYheLKd_*x zOSC>-to1q^)0lQJc;+mKCJPtu2@!biwcn_}0WKymQ@l4vlL{^nlbDi|)Y^6Knrk+! z>rqdbfIYsl%0{a#vn2(I4$`gaB)&jWmSlvQJ60lgw$+;ld($&%K0ns+B%t^u(i2W~ zK=E`g5J+Pk#cjWx0^h5}_fl@_i*fm-U?f+2N2)@j-$>60+Mh_>pnf6##5TKP64}bA zr%_XEuuI%kLJJw1_26jzz#LOnUU9Rzd0u4gM=5%0oX|B(VUyNP%CE>ByYIE;!Q0;{ zWkTv(7ea()sj7nfX$Rm4g{?B@^7q-IiyZymXZ7Y&AGJ?-klV}CDyA|V8zf_$+)7|m zmKw56@t$;U^Kk}!_h{*D1nTlmOT}h}_wbXNd6Oih^)py$F62}VEzrC6t!^GMVvBis zMi707L9YGtvs#+g1E6fTCNk3~uY)@K#0)_n(J7H|`Ho(VN9kxf(OL6ANhYS^q_+li zp=JnN@fmkMr&eU6p(-IF|=lUufN7J)HG?D_OX3d=!X$?=v&r13NmgP07m2jM(qDhBYs-^xk=STgH6LH!jiW9xj{CpGvfqfoh4^csJqsRxgkf(K^*l@Gv3^T?!Pk$`gIF|JGDLo)@ z0jU#0#i56qur0&70t?DYa2)HNH`>m%OapiwbP)q-*n(gxeUR zudi?7WNCXjxne4dXqsZLs^53gVW+BB~erU z0-=iwUkIhhPC`q1b;xKL57)~We%Y)~jKJ-e_0ZzwPNDXgxy;}h-Jlwv5^-?qgZ^7T zBnMc+8m!KUHGb`m_(9U&?sI^|LE+8i;_2g^9IMd|cZrY;T>r?hUJtdJf%QNCe@Dfh zzr8}th&}%*2YddtodSFQMqnZS`i8&JH?Tuce83|l;H3);hHtP(c8IkHDLaHRuoM0# z#Ja~SJ3~b7o=dFUSS;gV8e3#%SbOZSGem*cGW^3K#15cWaR|(E;@uyzg)@Cg7M7vy7I{SAPt7WDuC literal 0 HcmV?d00001 diff --git a/core-java/src/test/java/com/baeldung/stringisnumeric/CoreJavaIsNumericUnitTest.java b/core-java/src/test/java/com/baeldung/stringisnumeric/CoreJavaIsNumericUnitTest.java new file mode 100644 index 0000000000..808d3c45b0 --- /dev/null +++ b/core-java/src/test/java/com/baeldung/stringisnumeric/CoreJavaIsNumericUnitTest.java @@ -0,0 +1,31 @@ +package com.baeldung.stringisnumeric; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.Test; + +public class CoreJavaIsNumericUnitTest { + public static boolean isNumeric(String strNum) { + try { + double d = Double.parseDouble(strNum); + } catch (NumberFormatException | NullPointerException nfe) { + return false; + } + return true; + } + + @Test + public void whenUsingCoreJava_thenTrue() { + // Valid Numbers + assertThat(isNumeric("22")).isTrue(); + assertThat(isNumeric("5.05")).isTrue(); + assertThat(isNumeric("-200")).isTrue(); + assertThat(isNumeric("10.0d")).isTrue(); + assertThat(isNumeric(" 22 ")).isTrue(); + + // Invalid Numbers + assertThat(isNumeric(null)).isFalse(); + assertThat(isNumeric("")).isFalse(); + assertThat(isNumeric("abc")).isFalse(); + } +} diff --git a/core-java/src/test/java/com/baeldung/stringisnumeric/NumberUtilsIsCreatableUnitTest.java b/core-java/src/test/java/com/baeldung/stringisnumeric/NumberUtilsIsCreatableUnitTest.java new file mode 100644 index 0000000000..467d58837a --- /dev/null +++ b/core-java/src/test/java/com/baeldung/stringisnumeric/NumberUtilsIsCreatableUnitTest.java @@ -0,0 +1,28 @@ +package com.baeldung.stringisnumeric; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.apache.commons.lang3.math.NumberUtils; +import org.junit.Test; + +public class NumberUtilsIsCreatableUnitTest { + @Test + public void givenApacheCommons_whenUsingIsParsable_thenTrue() { + // Valid Numbers + assertThat(NumberUtils.isCreatable("22")).isTrue(); + assertThat(NumberUtils.isCreatable("5.05")).isTrue(); + assertThat(NumberUtils.isCreatable("-200")).isTrue(); + assertThat(NumberUtils.isCreatable("10.0d")).isTrue(); + assertThat(NumberUtils.isCreatable("1000L")).isTrue(); + assertThat(NumberUtils.isCreatable("0xFF")).isTrue(); + assertThat(NumberUtils.isCreatable("07")).isTrue(); + assertThat(NumberUtils.isCreatable("2.99e+8")).isTrue(); + + // Invalid Numbers + assertThat(NumberUtils.isCreatable(null)).isFalse(); + assertThat(NumberUtils.isCreatable("")).isFalse(); + assertThat(NumberUtils.isCreatable("abc")).isFalse(); + assertThat(NumberUtils.isCreatable(" 22 ")).isFalse(); + assertThat(NumberUtils.isCreatable("09")).isFalse(); + } +} diff --git a/core-java/src/test/java/com/baeldung/stringisnumeric/NumberUtilsIsParsableUnitTest.java b/core-java/src/test/java/com/baeldung/stringisnumeric/NumberUtilsIsParsableUnitTest.java new file mode 100644 index 0000000000..141a761158 --- /dev/null +++ b/core-java/src/test/java/com/baeldung/stringisnumeric/NumberUtilsIsParsableUnitTest.java @@ -0,0 +1,26 @@ +package com.baeldung.stringisnumeric; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.apache.commons.lang3.math.NumberUtils; +import org.junit.Test; + +public class NumberUtilsIsParsableUnitTest { + @Test + public void givenApacheCommons_whenUsingIsParsable_thenTrue() { + // Valid Numbers + assertThat(NumberUtils.isParsable("22")).isTrue(); + assertThat(NumberUtils.isParsable("-23")).isTrue(); + assertThat(NumberUtils.isParsable("2.2")).isTrue(); + assertThat(NumberUtils.isParsable("09")).isTrue(); + + // Invalid Numbers + assertThat(NumberUtils.isParsable(null)).isFalse(); + assertThat(NumberUtils.isParsable("")).isFalse(); + assertThat(NumberUtils.isParsable("6.2f")).isFalse(); + assertThat(NumberUtils.isParsable("9.8d")).isFalse(); + assertThat(NumberUtils.isParsable("22L")).isFalse(); + assertThat(NumberUtils.isParsable("0xFF")).isFalse(); + assertThat(NumberUtils.isParsable("2.99e+8")).isFalse(); + } +} diff --git a/core-java/src/test/java/com/baeldung/stringisnumeric/RegularExpressionsUnitTest.java b/core-java/src/test/java/com/baeldung/stringisnumeric/RegularExpressionsUnitTest.java new file mode 100644 index 0000000000..c3aa43ac94 --- /dev/null +++ b/core-java/src/test/java/com/baeldung/stringisnumeric/RegularExpressionsUnitTest.java @@ -0,0 +1,22 @@ +package com.baeldung.stringisnumeric; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.Test; + +public class RegularExpressionsUnitTest { + public static boolean isNumeric(String strNum) { + return strNum.matches("-?\\d+(\\.\\d+)?"); + } + + @Test + public void whenUsingRegularExpressions_thenTrue() { + // Valid Numbers + assertThat(isNumeric("22")).isTrue(); + assertThat(isNumeric("5.05")).isTrue(); + assertThat(isNumeric("-200")).isTrue(); + + // Invalid Numbers + assertThat(isNumeric("abc")).isFalse(); + } +} diff --git a/core-java/src/test/java/com/baeldung/stringisnumeric/StringUtilsIsNumericSpaceUnitTest.java b/core-java/src/test/java/com/baeldung/stringisnumeric/StringUtilsIsNumericSpaceUnitTest.java new file mode 100644 index 0000000000..135780d9ad --- /dev/null +++ b/core-java/src/test/java/com/baeldung/stringisnumeric/StringUtilsIsNumericSpaceUnitTest.java @@ -0,0 +1,23 @@ +package com.baeldung.stringisnumeric; + +import org.apache.commons.lang3.StringUtils; +import org.junit.Test; +import static org.assertj.core.api.Assertions.assertThat; + +public class StringUtilsIsNumericSpaceUnitTest { + @Test + public void givenApacheCommons_whenUsingIsNumericSpace_thenTrue() { + // Valid Numbers + assertThat(StringUtils.isNumericSpace("123")).isTrue(); + assertThat(StringUtils.isNumericSpace("١٢٣")).isTrue(); + assertThat(StringUtils.isNumericSpace("")).isTrue(); + assertThat(StringUtils.isNumericSpace(" ")).isTrue(); + assertThat(StringUtils.isNumericSpace("12 3")).isTrue(); + + // Invalid Numbers + assertThat(StringUtils.isNumericSpace(null)).isFalse(); + assertThat(StringUtils.isNumericSpace("ab2c")).isFalse(); + assertThat(StringUtils.isNumericSpace("12.3")).isFalse(); + assertThat(StringUtils.isNumericSpace("-123")).isFalse(); + } +} diff --git a/core-java/src/test/java/com/baeldung/stringisnumeric/StringUtilsIsNumericUnitTest.java b/core-java/src/test/java/com/baeldung/stringisnumeric/StringUtilsIsNumericUnitTest.java new file mode 100644 index 0000000000..b667dda906 --- /dev/null +++ b/core-java/src/test/java/com/baeldung/stringisnumeric/StringUtilsIsNumericUnitTest.java @@ -0,0 +1,24 @@ +package com.baeldung.stringisnumeric; + +import org.apache.commons.lang3.StringUtils; +import org.junit.Test; +import static org.assertj.core.api.Assertions.assertThat; + +public class StringUtilsIsNumericUnitTest { + @Test + public void givenApacheCommons_whenUsingIsNumeric_thenTrue() { + // Valid Numbers + assertThat(StringUtils.isNumeric("123")).isTrue(); + assertThat(StringUtils.isNumeric("١٢٣")).isTrue(); + assertThat(StringUtils.isNumeric("१२३")).isTrue(); + + // Invalid Numbers + assertThat(StringUtils.isNumeric(null)).isFalse(); + assertThat(StringUtils.isNumeric("")).isFalse(); + assertThat(StringUtils.isNumeric(" ")).isFalse(); + assertThat(StringUtils.isNumeric("12 3")).isFalse(); + assertThat(StringUtils.isNumeric("ab2c")).isFalse(); + assertThat(StringUtils.isNumeric("12.3")).isFalse(); + assertThat(StringUtils.isNumeric("-123")).isFalse(); + } +} From e166f5d9c9777e07dbc9279cf6bb6914629b66ef Mon Sep 17 00:00:00 2001 From: Harsh Jain Date: Fri, 11 May 2018 08:40:46 +0530 Subject: [PATCH 61/66] BAEL - 1577 hamcrest core matchers 2.0 version examples as test cases (#4214) * BAEL-1577 : hamcrest core matchers examples added as test cases * BAEL-1577 : Hamcrest java library 2.0.0.0 examples updated as test cases * BAEL-1577 : changed test class name to HamcrestCoreMatchersTest to resolve conflicts --- guava/pom.xml | 9 + .../hamcrest/HamcrestCoreMatchersTest.java | 259 ++++++++++++++++++ 2 files changed, 268 insertions(+) create mode 100644 guava/src/test/java/org/baeldung/hamcrest/HamcrestCoreMatchersTest.java diff --git a/guava/pom.xml b/guava/pom.xml index da880cc995..b36506f87a 100644 --- a/guava/pom.xml +++ b/guava/pom.xml @@ -32,6 +32,14 @@ ${assertj.version} test + + + + org.hamcrest + java-hamcrest + ${java-hamcrest.version} + test + @@ -52,6 +60,7 @@ 3.6.1 + 2.0.0.0 \ No newline at end of file diff --git a/guava/src/test/java/org/baeldung/hamcrest/HamcrestCoreMatchersTest.java b/guava/src/test/java/org/baeldung/hamcrest/HamcrestCoreMatchersTest.java new file mode 100644 index 0000000000..8f3e96c956 --- /dev/null +++ b/guava/src/test/java/org/baeldung/hamcrest/HamcrestCoreMatchersTest.java @@ -0,0 +1,259 @@ +package org.baeldung.hamcrest; + + +import com.google.common.collect.Lists; +import org.junit.Test; + +import java.util.List; + +import static org.hamcrest.CoreMatchers.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.StringEndsWith.endsWith; +import static org.hamcrest.core.StringStartsWith.startsWith; + +public class HamcrestCoreMatchersTest { + + @Test + public void givenTestInput_WhenUsingIsForMatch() { + + // GIVEN + String testString = "hamcrest core"; + + // ASSERT + assertThat(testString, is("hamcrest core")); + assertThat(testString, is(equalTo("hamcrest core"))); + } + + @Test + public void givenDifferentStaticTypeTestInput_WhenUsingEqualToObject_ThenCorrect() { + + // GIVEN + Object original = 100; + + // ASSERT + assertThat(original, equalToObject(100)); + } + + @Test + public void givenTestInput_WhenUsingInstanceOfForClassTypeCheck() { + + assertThat("hamcrest", is(instanceOf(String.class))); + } + + @Test + public void givenTestInput_WhenUsingIsA_ThenAssertType() { + + assertThat("hamcrest core", isA(String.class)); + } + + @Test + public void givenTestInput_WhenUsingEqualToMatcherForEquality() { + + // GIVEN + String actualString = "Hamcrest Core"; + List actualList = Lists.newArrayList("hamcrest", "core"); + + // ASSERT + assertThat(actualString, is(equalTo("Hamcrest Core"))); + assertThat(actualList, is(equalTo(Lists.newArrayList("hamcrest", "core")))); + } + + @Test + public void givenTestInput_WhenUsingNotForMatch() { + + // GIVEN + String testString = "hamcrest"; + + // ASSERT + assertThat(testString, not("hamcrest core")); + assertThat(testString, is(not(equalTo("hamcrest core")))); + assertThat(testString, is(not(instanceOf(Integer.class)))); + } + + @Test + public void givenTestInput_WhenUsingNullValueForNullCheck() { + + // GIVEN + Integer nullObject = null; + + // ASSERT + assertThat(nullObject, is(nullValue())); + assertThat(nullObject, is(nullValue(Integer.class))); + } + + @Test + public void givenTestInput_WhenUsingNotNullValueForNotNullCheck() { + + // GIVEN + Integer testNumber = 123; + + // ASSERT + assertThat(testNumber, is(notNullValue())); + assertThat(testNumber, is(notNullValue(Integer.class))); + } + + @Test + public void givenString_WhenStartsWith_ThenCorrect() { + + // GIVEN + String testString = "hamcrest core"; + + // ASSERT + assertThat(testString, startsWith("hamcrest")); + } + + @Test + public void giveString_WhenStartsWithIgnoringCase_ThenCorrect() { + + // GIVEN + String testString = "hamcrest core"; + + // ASSERT + assertThat(testString, startsWithIgnoringCase("HAMCREST")); + } + + @Test + public void givenString_WhenEndsWith_ThenCorrect() { + + // GIVEN + String testString = "hamcrest core"; + + // ASSERT + assertThat(testString, endsWith("core")); + } + + @Test + public void givenString_WhenEndsWithIgnoringCase_ThenCorrect() { + + // GIVEN + String testString = "hamcrest core"; + + // ASSERT + assertThat(testString, endsWithIgnoringCase("CORE")); + } + + @Test + public void givenString_WhenContainsString_ThenCorrect() { + + // GIVEN + String testString = "hamcrest core"; + + // ASSERT + assertThat(testString, containsString("co")); + } + + @Test + public void givenString_WhenContainsStringIgnoringCase_ThenCorrect() { + + + // GIVEN + String testString = "hamcrest core"; + + // ASSERT + assertThat(testString, containsStringIgnoringCase("CO")); + } + + @Test + public void givenTestInput_WhenUsingHasItemInCollection() { + + // GIVEN + List list = Lists.newArrayList("java", "spring", "baeldung"); + + // ASSERT + assertThat(list, hasItem("java")); + assertThat(list, hasItem(isA(String.class))); + } + + + @Test + public void givenTestInput_WhenUsingHasItemsInCollection() { + + // GIVEN + List list = Lists.newArrayList("java", "spring", "baeldung"); + + // ASSERT + assertThat(list, hasItems("java", "baeldung")); + assertThat(list, hasItems(isA(String.class), endsWith("ing"))); + } + + @Test + public void givenTestInput_WhenUsingAnyForClassType() { + + assertThat("hamcrest", is(any(String.class))); + assertThat("hamcrest", is(any(Object.class))); + } + + @Test + public void givenTestInput_WhenUsingAllOfForAllMatchers() { + + // GIVEN + String testString = "Hamcrest Core"; + + // ASSERT + assertThat(testString, allOf(startsWith("Ham"), endsWith("ore"), containsString("Core"))); + } + + @Test + public void givenTestInput_WhenUsingAnyOfForAnyMatcher() { + + // GIVEN + String testString = "Hamcrest Core"; + + // ASSERT + assertThat(testString, anyOf(startsWith("Ham"), containsString("baeldung"))); + } + + @Test + public void givenTestInput_WhenUsingBothForMatcher() { + + // GIVEN + String testString = "Hamcrest Core Matchers"; + + // ASSERT + assertThat(testString, both(startsWith("Ham")).and(containsString("Core"))); + } + + @Test + public void givenTestInput_WhenUsingEitherForMatcher() { + + // GIVEN + String testString = "Hamcrest Core Matchers"; + + // ASSERT + assertThat(testString, either(startsWith("Bael")).or(containsString("Core"))); + } + + + @Test + public void givenTestInput_WhenUsingEveryItemForMatchInCollection() { + + // GIVEN + List testItems = Lists.newArrayList("Common", "Core", "Combinable"); + + // ASSERT + assertThat(testItems, everyItem(startsWith("Co"))); + } + + @Test + public void givenTwoTestInputs_WhenUsingSameInstanceForMatch() { + + // GIVEN + String string1 = "hamcrest"; + String string2 = string1; + + // ASSERT + assertThat(string1, is(sameInstance(string2))); + } + + @Test + public void givenTwoTestInputs_WhenUsingTheInstanceForMatch() { + // GIVEN + String string1 = "hamcrest"; + String string2 = string1; + + // ASSERT + assertThat(string1, is(theInstance(string2))); + } + +} + From 4a08fd1352dc2fafb2a51a6fecb5822af7f0811f Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Fri, 11 May 2018 10:07:57 +0300 Subject: [PATCH 62/66] update, move deferredresult controller (#4164) --- .../servlets/DeferredResultController.java | 71 ---------------- .../controller/DeferredResultController.java | 85 +++++++++++++++++++ 2 files changed, 85 insertions(+), 71 deletions(-) delete mode 100644 spring-boot/src/main/java/com/baeldung/servlets/DeferredResultController.java create mode 100644 spring-rest/src/main/java/org/baeldung/web/controller/DeferredResultController.java diff --git a/spring-boot/src/main/java/com/baeldung/servlets/DeferredResultController.java b/spring-boot/src/main/java/com/baeldung/servlets/DeferredResultController.java deleted file mode 100644 index c43b0e6dc0..0000000000 --- a/spring-boot/src/main/java/com/baeldung/servlets/DeferredResultController.java +++ /dev/null @@ -1,71 +0,0 @@ -package com.baeldung.servlets; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.ui.Model; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RestController; -import org.springframework.web.context.request.async.DeferredResult; - -@RestController -public class DeferredResultController { - - private final static Logger LOG = LoggerFactory.getLogger(DeferredResultController.class); - - @GetMapping("/async-deferredresult") - public DeferredResult> handleReqDefResult(Model model) { - LOG.info("Received async-deferredresult request"); - DeferredResult> output = new DeferredResult<>(); - new Thread(() -> { - LOG.info("Processing in separate thread"); - output.setResult(ResponseEntity.ok("ok")); - }).start(); - LOG.info("servlet thread freed"); - return output; - } - - public DeferredResult> handleReqWithTimeouts(Model model) { - LOG.info("Received async request with a configured timeout"); - DeferredResult> deferredResult = new DeferredResult<>(500l); - deferredResult.onTimeout(new Runnable() { - @Override - public void run() { - deferredResult.setErrorResult( - ResponseEntity.status(HttpStatus.REQUEST_TIMEOUT).body("Request timeout occurred.")); - } - }); - - new Thread(() -> { - LOG.info("Processing in separate thread"); - try { - Thread.sleep(600l); - deferredResult.setResult(ResponseEntity.ok("ok")); - } catch (InterruptedException e) { - LOG.info("Request processing interrupted"); - deferredResult.setErrorResult(ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) - .body("INTERNAL_SERVER_ERROR occurred.")); - } - - }).start(); - LOG.info("servlet thread freed"); - return deferredResult; - } - - public DeferredResult> handleAsyncFailedRequest(Model model) { - DeferredResult> deferredResult = new DeferredResult<>(); - new Thread(() -> { - try { - // Exception occurred in processing - throw new Exception(); - } catch (Exception e) { - LOG.info("Request processing failed"); - deferredResult.setErrorResult(ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) - .body("INTERNAL_SERVER_ERROR occurred.")); - } - }).start(); - return deferredResult; - } - -} diff --git a/spring-rest/src/main/java/org/baeldung/web/controller/DeferredResultController.java b/spring-rest/src/main/java/org/baeldung/web/controller/DeferredResultController.java new file mode 100644 index 0000000000..5d039d2d02 --- /dev/null +++ b/spring-rest/src/main/java/org/baeldung/web/controller/DeferredResultController.java @@ -0,0 +1,85 @@ +package org.baeldung.web.controller; + +import java.util.concurrent.CompletableFuture; +import java.util.function.Consumer; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.context.request.async.DeferredResult; + +@RestController +public class DeferredResultController { + + private final static Logger LOG = LoggerFactory.getLogger(DeferredResultController.class); + + @GetMapping("/async-deferredresult") + public DeferredResult> handleReqDefResult(Model model) { + LOG.info("Received request"); + DeferredResult> deferredResult = new DeferredResult<>(); + + deferredResult.onCompletion(() -> LOG.info("Processing complete")); + + CompletableFuture.supplyAsync(() -> { + LOG.info("Processing in separate thread"); + try { + Thread.sleep(6000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + return "OK"; + }) + .whenCompleteAsync((result, exc) -> deferredResult.setResult(ResponseEntity.ok(result))); + + LOG.info("Servlet thread freed"); + return deferredResult; + } + + @GetMapping("/process-blocking") + public ResponseEntity handleReqSync(Model model) { + // ... + return ResponseEntity.ok("ok"); + } + + @GetMapping("/async-deferredresult-timeout") + public DeferredResult> handleReqWithTimeouts(Model model) { + LOG.info("Received async request with a configured timeout"); + DeferredResult> deferredResult = new DeferredResult<>(500l); + deferredResult.onTimeout(() -> deferredResult.setErrorResult(ResponseEntity.status(HttpStatus.REQUEST_TIMEOUT) + .body("Request timeout occurred."))); + + CompletableFuture.supplyAsync(() -> { + LOG.info("Processing in separate thread"); + try { + Thread.sleep(6000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + return "error"; + }) + .whenCompleteAsync((result, exc) -> deferredResult.setResult(ResponseEntity.ok(result))); + LOG.info("servlet thread freed"); + return deferredResult; + } + + @GetMapping("/async-deferredresult-error") + public DeferredResult> handleAsyncFailedRequest(Model model) { + LOG.info("Received async request with a configured error handler"); + DeferredResult> deferredResult = new DeferredResult<>(); + deferredResult.onError(new Consumer() { + @Override + public void accept(Throwable t) { + deferredResult.setErrorResult(ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) + .body("An error occurred.")); + } + + }); + LOG.info("servlet thread freed"); + return deferredResult; + } + +} From 537c1d1150263154436c508e1cc17ea44f6cd70a Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Fri, 11 May 2018 10:11:13 +0300 Subject: [PATCH 63/66] move design patterns to new module (#4206) * move design patterns to new module * fix logger import --- .../creational/abstractfactory/Color.java | 5 ---- .../creational/factory/Polygon.java | 5 ---- .../numberofdigits/NumberOfDigitsDriver.java | 4 ++- .../{facade => design-patterns}/README.md | 0 .../pom.xml | 22 +++++++++++---- .../adapter/AdapterPatternDriver.java | 4 +-- .../com/baeldung}/adapter/AstonMartin.java | 16 +++++------ .../com/baeldung}/adapter/BugattiVeyron.java | 16 +++++------ .../java/com/baeldung}/adapter/McLaren.java | 16 +++++------ .../java/com/baeldung}/adapter/Movable.java | 10 +++---- .../com/baeldung}/adapter/MovableAdapter.java | 2 +- .../baeldung}/adapter/MovableAdapterImpl.java | 2 +- .../main/java/com/baeldung}/bridge/Blue.java | 2 +- .../baeldung}/bridge/BridgePatternDriver.java | 2 +- .../main/java/com/baeldung}/bridge/Color.java | 2 +- .../main/java/com/baeldung}/bridge/Red.java | 2 +- .../main/java/com/baeldung}/bridge/Shape.java | 2 +- .../java/com/baeldung}/bridge/Square.java | 2 +- .../java/com/baeldung}/bridge/Triangle.java | 2 +- .../AuthenticationProcessor.java | 0 .../AuthenticationProvider.java | 0 .../OAuthAuthenticationProcessor.java | 0 .../OAuthTokenProvider.java | 0 .../SamlAuthenticationProvider.java | 0 ...ernamePasswordAuthenticationProcessor.java | 0 .../UsernamePasswordProvider.java | 0 .../command/client/TextFileApplication.java | 0 .../command/OpenTextFileOperation.java | 0 .../command/SaveTextFileOperation.java | 0 .../command/command/TextFileOperation.java | 0 .../invoker/TextFileOperationExecutor.java | 0 .../baeldung}/command/receiver/TextFile.java | 0 .../baeldung}/composite/CompositeDemo.java | 2 +- .../com/baeldung}/composite/Department.java | 2 +- .../composite/FinancialDepartment.java | 2 +- .../baeldung}/composite/HeadDepartment.java | 2 +- .../baeldung}/composite/SalesDepartment.java | 2 +- .../abstractfactory/AbstractFactory.java | 2 +- .../AbstractPatternDriver.java | 2 +- .../creational/abstractfactory/Animal.java | 2 +- .../abstractfactory/AnimalFactory.java | 2 +- .../creational/abstractfactory/Brown.java | 2 +- .../creational/abstractfactory/Color.java | 5 ++++ .../abstractfactory/ColorFactory.java | 2 +- .../creational/abstractfactory/Dog.java | 2 +- .../creational/abstractfactory/Duck.java | 2 +- .../abstractfactory/FactoryProvider.java | 2 +- .../creational/abstractfactory/White.java | 2 +- .../creational/builder/BankAccount.java | 2 +- .../builder/BuilderPatternDriver.java | 2 +- .../creational/factory/FactoryDriver.java | 2 +- .../creational/factory/Heptagon.java | 2 +- .../baeldung}/creational/factory/Octagon.java | 2 +- .../creational/factory/Pentagon.java | 2 +- .../baeldung/creational/factory/Polygon.java | 5 ++++ .../creational/factory/PolygonFactory.java | 2 +- .../baeldung}/creational/factory/Square.java | 2 +- .../creational/factory/Triangle.java | 2 +- .../creational/singleton/Singleton.java | 2 +- .../creational/singleton/SingletonDriver.java | 2 +- .../com/baeldung}/decorator/BubbleLights.java | 2 +- .../baeldung}/decorator/ChristmasTree.java | 2 +- .../decorator/ChristmasTreeImpl.java | 2 +- .../decorator/DecoratorPatternDriver.java | 4 +-- .../java/com/baeldung}/decorator/Garland.java | 2 +- .../baeldung}/decorator/TreeDecorator.java | 2 +- .../com/baeldung}/facade/CarEngineFacade.java | 4 +-- .../facade/carsystem/AirFlowController.java | 2 +- .../facade/carsystem/AirFlowMeter.java | 4 +-- .../facade/carsystem/CatalyticConverter.java | 2 +- .../facade/carsystem/CoolingController.java | 4 +-- .../facade/carsystem/FuelInjector.java | 4 +-- .../baeldung}/facade/carsystem/FuelPump.java | 4 +-- .../baeldung}/facade/carsystem/Radiator.java | 2 +- .../baeldung}/facade/carsystem/Starter.java | 4 +-- .../facade/carsystem/TemperatureSensor.java | 4 +-- .../java/com/baeldung}/flyweight/Car.java | 8 +++--- .../java/com/baeldung}/flyweight/Engine.java | 2 +- .../java/com/baeldung}/flyweight/Vehicle.java | 2 +- .../baeldung}/flyweight/VehicleFactory.java | 2 +- .../java/com/baeldung}/observer/Channel.java | 2 +- .../com/baeldung}/observer/NewsAgency.java | 2 +- .../com/baeldung}/observer/NewsChannel.java | 2 +- .../com/baeldung}/observer/ONewsAgency.java | 2 +- .../com/baeldung}/observer/ONewsChannel.java | 2 +- .../com/baeldung}/observer/PCLNewsAgency.java | 2 +- .../baeldung}/observer/PCLNewsChannel.java | 2 +- .../com/baeldung}/proxy/ExpensiveObject.java | 2 +- .../baeldung}/proxy/ExpensiveObjectImpl.java | 6 ++-- .../baeldung}/proxy/ExpensiveObjectProxy.java | 2 +- .../baeldung}/proxy/ProxyPatternDriver.java | 2 +- .../com/baeldung}/service/locator/Cache.java | 2 +- .../service/locator/EmailService.java | 2 +- .../service/locator/InitialContext.java | 2 +- .../com/baeldung}/service/locator/Main.java | 2 +- .../service/locator/MessagingService.java | 2 +- .../baeldung}/service/locator/SMSService.java | 2 +- .../service/locator/ServiceLocator.java | 2 +- .../baeldung}/singleton/ClassSingleton.java | 2 +- .../baeldung}/singleton/EnumSingleton.java | 2 +- .../java/com/baeldung}/singleton/Sandbox.java | 2 +- .../synchronization/DclSingleton.java | 2 +- .../synchronization/DraconianSingleton.java | 2 +- .../synchronization/EarlyInitSingleton.java | 2 +- .../synchronization/EnumSingleton.java | 2 +- .../InitOnDemandSingleton.java | 2 +- .../application/Application.java | 0 .../templatemethod/model/Computer.java | 0 .../templatemethod/model/ComputerBuilder.java | 0 .../templatemethod/model/HighEndComputer.java | 0 .../model/HighEndComputerBuilder.java | 0 .../model/StandardComputer.java | 0 .../model/StandardComputerBuilder.java | 0 .../java/com/baeldung}/util/LogerUtil.java | 2 +- .../AdapterPatternIntegrationTest.java | 14 +++++----- .../BridgePatternIntegrationTest.java | 12 ++++---- .../DecoratorPatternIntegrationTest.java | 10 +++---- .../ProxyPatternIntegrationTest.java | 10 +++---- .../java/com/baeldung}/TestAppenderDP.java | 2 +- .../ChainOfResponsibilityTest.java | 0 .../test/OpenTextFileOperationUnitTest.java | 0 .../test/SaveTextFileOperationUnitTest.java | 0 .../TextFileOperationExecutorUnitTest.java | 0 .../command/test/TextFileUnitTest.java | 0 .../AbstractPatternIntegrationTest.java | 2 +- .../BuilderPatternIntegrationTest.java | 2 +- .../factory/FactoryIntegrationTest.java | 2 +- .../singleton/SingletonIntegrationTest.java | 2 +- .../baeldung}/facade/CarEngineFacadeTest.java | 14 +++++----- .../flyweight/FlyweightUnitTest.java | 2 +- .../observer/ObserverIntegrationTest.java | 6 ++-- .../SingletonSynchronizationUnitTest.java | 2 +- .../test/TemplateMethodPatternTest.java | 0 patterns/facade/pom.xml | 28 ------------------- patterns/front-controller/pom.xml | 2 +- patterns/intercepting-filter/pom.xml | 2 +- patterns/pom.xml | 4 +-- 137 files changed, 200 insertions(+), 214 deletions(-) delete mode 100644 core-java/src/main/java/com/baeldung/designpatterns/creational/abstractfactory/Color.java delete mode 100644 core-java/src/main/java/com/baeldung/designpatterns/creational/factory/Polygon.java rename patterns/{facade => design-patterns}/README.md (100%) rename patterns/{behavioral-patterns => design-patterns}/pom.xml (68%) rename {core-java/src/main/java/com/baeldung/designpatterns => patterns/design-patterns/src/main/java/com/baeldung}/adapter/AdapterPatternDriver.java (87%) rename {core-java/src/main/java/com/baeldung/designpatterns => patterns/design-patterns/src/main/java/com/baeldung}/adapter/AstonMartin.java (69%) rename {core-java/src/main/java/com/baeldung/designpatterns => patterns/design-patterns/src/main/java/com/baeldung}/adapter/BugattiVeyron.java (69%) rename {core-java/src/main/java/com/baeldung/designpatterns => patterns/design-patterns/src/main/java/com/baeldung}/adapter/McLaren.java (68%) rename {core-java/src/main/java/com/baeldung/designpatterns => patterns/design-patterns/src/main/java/com/baeldung}/adapter/Movable.java (61%) rename {core-java/src/main/java/com/baeldung/designpatterns => patterns/design-patterns/src/main/java/com/baeldung}/adapter/MovableAdapter.java (66%) rename {core-java/src/main/java/com/baeldung/designpatterns => patterns/design-patterns/src/main/java/com/baeldung}/adapter/MovableAdapterImpl.java (90%) rename {core-java/src/main/java/com/baeldung/designpatterns => patterns/design-patterns/src/main/java/com/baeldung}/bridge/Blue.java (73%) rename {core-java/src/main/java/com/baeldung/designpatterns => patterns/design-patterns/src/main/java/com/baeldung}/bridge/BridgePatternDriver.java (88%) rename {core-java/src/main/java/com/baeldung/designpatterns => patterns/design-patterns/src/main/java/com/baeldung}/bridge/Color.java (51%) rename {core-java/src/main/java/com/baeldung/designpatterns => patterns/design-patterns/src/main/java/com/baeldung}/bridge/Red.java (73%) rename {core-java/src/main/java/com/baeldung/designpatterns => patterns/design-patterns/src/main/java/com/baeldung}/bridge/Shape.java (79%) rename {core-java/src/main/java/com/baeldung/designpatterns => patterns/design-patterns/src/main/java/com/baeldung}/bridge/Square.java (81%) rename {core-java/src/main/java/com/baeldung/designpatterns => patterns/design-patterns/src/main/java/com/baeldung}/bridge/Triangle.java (82%) rename patterns/{behavioral-patterns/src/main/java/com/baeldung/pattern => design-patterns/src/main/java/com/baeldung}/chainofresponsibility/AuthenticationProcessor.java (100%) rename patterns/{behavioral-patterns/src/main/java/com/baeldung/pattern => design-patterns/src/main/java/com/baeldung}/chainofresponsibility/AuthenticationProvider.java (100%) rename patterns/{behavioral-patterns/src/main/java/com/baeldung/pattern => design-patterns/src/main/java/com/baeldung}/chainofresponsibility/OAuthAuthenticationProcessor.java (100%) rename patterns/{behavioral-patterns/src/main/java/com/baeldung/pattern => design-patterns/src/main/java/com/baeldung}/chainofresponsibility/OAuthTokenProvider.java (100%) rename patterns/{behavioral-patterns/src/main/java/com/baeldung/pattern => design-patterns/src/main/java/com/baeldung}/chainofresponsibility/SamlAuthenticationProvider.java (100%) rename patterns/{behavioral-patterns/src/main/java/com/baeldung/pattern => design-patterns/src/main/java/com/baeldung}/chainofresponsibility/UsernamePasswordAuthenticationProcessor.java (100%) rename patterns/{behavioral-patterns/src/main/java/com/baeldung/pattern => design-patterns/src/main/java/com/baeldung}/chainofresponsibility/UsernamePasswordProvider.java (100%) rename patterns/{behavioral-patterns/src/main/java/com/baeldung/pattern => design-patterns/src/main/java/com/baeldung}/command/client/TextFileApplication.java (100%) rename patterns/{behavioral-patterns/src/main/java/com/baeldung/pattern => design-patterns/src/main/java/com/baeldung}/command/command/OpenTextFileOperation.java (100%) rename patterns/{behavioral-patterns/src/main/java/com/baeldung/pattern => design-patterns/src/main/java/com/baeldung}/command/command/SaveTextFileOperation.java (100%) rename patterns/{behavioral-patterns/src/main/java/com/baeldung/pattern => design-patterns/src/main/java/com/baeldung}/command/command/TextFileOperation.java (100%) rename patterns/{behavioral-patterns/src/main/java/com/baeldung/pattern => design-patterns/src/main/java/com/baeldung}/command/invoker/TextFileOperationExecutor.java (100%) rename patterns/{behavioral-patterns/src/main/java/com/baeldung/pattern => design-patterns/src/main/java/com/baeldung}/command/receiver/TextFile.java (100%) rename {core-java/src/main/java/com/baeldung/designpatterns => patterns/design-patterns/src/main/java/com/baeldung}/composite/CompositeDemo.java (92%) rename {core-java/src/main/java/com/baeldung/designpatterns => patterns/design-patterns/src/main/java/com/baeldung}/composite/Department.java (70%) rename {core-java/src/main/java/com/baeldung/designpatterns => patterns/design-patterns/src/main/java/com/baeldung}/composite/FinancialDepartment.java (92%) rename {core-java/src/main/java/com/baeldung/designpatterns => patterns/design-patterns/src/main/java/com/baeldung}/composite/HeadDepartment.java (94%) rename {core-java/src/main/java/com/baeldung/designpatterns => patterns/design-patterns/src/main/java/com/baeldung}/composite/SalesDepartment.java (92%) rename {core-java/src/main/java/com/baeldung/designpatterns => patterns/design-patterns/src/main/java/com/baeldung}/creational/abstractfactory/AbstractFactory.java (64%) rename {core-java/src/main/java/com/baeldung/designpatterns => patterns/design-patterns/src/main/java/com/baeldung}/creational/abstractfactory/AbstractPatternDriver.java (90%) rename {core-java/src/main/java/com/baeldung/designpatterns => patterns/design-patterns/src/main/java/com/baeldung}/creational/abstractfactory/Animal.java (53%) rename {core-java/src/main/java/com/baeldung/designpatterns => patterns/design-patterns/src/main/java/com/baeldung}/creational/abstractfactory/AnimalFactory.java (87%) rename {core-java/src/main/java/com/baeldung/designpatterns => patterns/design-patterns/src/main/java/com/baeldung}/creational/abstractfactory/Brown.java (64%) create mode 100644 patterns/design-patterns/src/main/java/com/baeldung/creational/abstractfactory/Color.java rename {core-java/src/main/java/com/baeldung/designpatterns => patterns/design-patterns/src/main/java/com/baeldung}/creational/abstractfactory/ColorFactory.java (87%) rename {core-java/src/main/java/com/baeldung/designpatterns => patterns/design-patterns/src/main/java/com/baeldung}/creational/abstractfactory/Dog.java (74%) rename {core-java/src/main/java/com/baeldung/designpatterns => patterns/design-patterns/src/main/java/com/baeldung}/creational/abstractfactory/Duck.java (75%) rename {core-java/src/main/java/com/baeldung/designpatterns => patterns/design-patterns/src/main/java/com/baeldung}/creational/abstractfactory/FactoryProvider.java (83%) rename {core-java/src/main/java/com/baeldung/designpatterns => patterns/design-patterns/src/main/java/com/baeldung}/creational/abstractfactory/White.java (64%) rename {core-java/src/main/java/com/baeldung/designpatterns => patterns/design-patterns/src/main/java/com/baeldung}/creational/builder/BankAccount.java (96%) rename {core-java/src/main/java/com/baeldung/designpatterns => patterns/design-patterns/src/main/java/com/baeldung}/creational/builder/BuilderPatternDriver.java (90%) rename {core-java/src/main/java/com/baeldung/designpatterns => patterns/design-patterns/src/main/java/com/baeldung}/creational/factory/FactoryDriver.java (89%) rename {core-java/src/main/java/com/baeldung/designpatterns => patterns/design-patterns/src/main/java/com/baeldung}/creational/factory/Heptagon.java (69%) rename {core-java/src/main/java/com/baeldung/designpatterns => patterns/design-patterns/src/main/java/com/baeldung}/creational/factory/Octagon.java (68%) rename {core-java/src/main/java/com/baeldung/designpatterns => patterns/design-patterns/src/main/java/com/baeldung}/creational/factory/Pentagon.java (69%) create mode 100644 patterns/design-patterns/src/main/java/com/baeldung/creational/factory/Polygon.java rename {core-java/src/main/java/com/baeldung/designpatterns => patterns/design-patterns/src/main/java/com/baeldung}/creational/factory/PolygonFactory.java (89%) rename {core-java/src/main/java/com/baeldung/designpatterns => patterns/design-patterns/src/main/java/com/baeldung}/creational/factory/Square.java (68%) rename {core-java/src/main/java/com/baeldung/designpatterns => patterns/design-patterns/src/main/java/com/baeldung}/creational/factory/Triangle.java (69%) rename {core-java/src/main/java/com/baeldung/designpatterns => patterns/design-patterns/src/main/java/com/baeldung}/creational/singleton/Singleton.java (83%) rename {core-java/src/main/java/com/baeldung/designpatterns => patterns/design-patterns/src/main/java/com/baeldung}/creational/singleton/SingletonDriver.java (76%) rename {core-java/src/main/java/com/baeldung/designpatterns => patterns/design-patterns/src/main/java/com/baeldung}/decorator/BubbleLights.java (87%) rename {core-java/src/main/java/com/baeldung/designpatterns => patterns/design-patterns/src/main/java/com/baeldung}/decorator/ChristmasTree.java (55%) rename {core-java/src/main/java/com/baeldung/designpatterns => patterns/design-patterns/src/main/java/com/baeldung}/decorator/ChristmasTreeImpl.java (75%) rename {core-java/src/main/java/com/baeldung/designpatterns => patterns/design-patterns/src/main/java/com/baeldung}/decorator/DecoratorPatternDriver.java (80%) rename {core-java/src/main/java/com/baeldung/designpatterns => patterns/design-patterns/src/main/java/com/baeldung}/decorator/Garland.java (86%) rename {core-java/src/main/java/com/baeldung/designpatterns => patterns/design-patterns/src/main/java/com/baeldung}/decorator/TreeDecorator.java (85%) rename patterns/{facade/src/main/java/com/baeldung/pattern => design-patterns/src/main/java/com/baeldung}/facade/CarEngineFacade.java (92%) rename patterns/{facade/src/main/java/com/baeldung/pattern => design-patterns/src/main/java/com/baeldung}/facade/carsystem/AirFlowController.java (90%) rename patterns/{facade/src/main/java/com/baeldung/pattern => design-patterns/src/main/java/com/baeldung}/facade/carsystem/AirFlowMeter.java (68%) rename patterns/{facade/src/main/java/com/baeldung/pattern => design-patterns/src/main/java/com/baeldung}/facade/carsystem/CatalyticConverter.java (88%) rename patterns/{facade/src/main/java/com/baeldung/pattern => design-patterns/src/main/java/com/baeldung}/facade/carsystem/CoolingController.java (91%) rename patterns/{facade/src/main/java/com/baeldung/pattern => design-patterns/src/main/java/com/baeldung}/facade/carsystem/FuelInjector.java (82%) rename patterns/{facade/src/main/java/com/baeldung/pattern => design-patterns/src/main/java/com/baeldung}/facade/carsystem/FuelPump.java (66%) rename patterns/{facade/src/main/java/com/baeldung/pattern => design-patterns/src/main/java/com/baeldung}/facade/carsystem/Radiator.java (90%) rename patterns/{facade/src/main/java/com/baeldung/pattern => design-patterns/src/main/java/com/baeldung}/facade/carsystem/Starter.java (70%) rename patterns/{facade/src/main/java/com/baeldung/pattern => design-patterns/src/main/java/com/baeldung}/facade/carsystem/TemperatureSensor.java (67%) rename {core-java/src/main/java/com/baeldung/designpatterns => patterns/design-patterns/src/main/java/com/baeldung}/flyweight/Car.java (83%) rename {core-java/src/main/java/com/baeldung/designpatterns => patterns/design-patterns/src/main/java/com/baeldung}/flyweight/Engine.java (90%) rename {core-java/src/main/java/com/baeldung/designpatterns => patterns/design-patterns/src/main/java/com/baeldung}/flyweight/Vehicle.java (88%) rename {core-java/src/main/java/com/baeldung/designpatterns => patterns/design-patterns/src/main/java/com/baeldung}/flyweight/VehicleFactory.java (96%) rename {core-java/src/main/java/com/baeldung/designpatterns => patterns/design-patterns/src/main/java/com/baeldung}/observer/Channel.java (58%) rename {core-java/src/main/java/com/baeldung/designpatterns => patterns/design-patterns/src/main/java/com/baeldung}/observer/NewsAgency.java (91%) rename {core-java/src/main/java/com/baeldung/designpatterns => patterns/design-patterns/src/main/java/com/baeldung}/observer/NewsChannel.java (86%) rename {core-java/src/main/java/com/baeldung/designpatterns => patterns/design-patterns/src/main/java/com/baeldung}/observer/ONewsAgency.java (83%) rename {core-java/src/main/java/com/baeldung/designpatterns => patterns/design-patterns/src/main/java/com/baeldung}/observer/ONewsChannel.java (89%) rename {core-java/src/main/java/com/baeldung/designpatterns => patterns/design-patterns/src/main/java/com/baeldung}/observer/PCLNewsAgency.java (93%) rename {core-java/src/main/java/com/baeldung/designpatterns => patterns/design-patterns/src/main/java/com/baeldung}/observer/PCLNewsChannel.java (90%) rename {core-java/src/main/java/com/baeldung/designpatterns => patterns/design-patterns/src/main/java/com/baeldung}/proxy/ExpensiveObject.java (57%) rename {core-java/src/main/java/com/baeldung/designpatterns => patterns/design-patterns/src/main/java/com/baeldung}/proxy/ExpensiveObjectImpl.java (64%) rename {core-java/src/main/java/com/baeldung/designpatterns => patterns/design-patterns/src/main/java/com/baeldung}/proxy/ExpensiveObjectProxy.java (86%) rename {core-java/src/main/java/com/baeldung/designpatterns => patterns/design-patterns/src/main/java/com/baeldung}/proxy/ProxyPatternDriver.java (82%) rename {core-java/src/main/java/com/baeldung/designpatterns => patterns/design-patterns/src/main/java/com/baeldung}/service/locator/Cache.java (94%) rename {core-java/src/main/java/com/baeldung/designpatterns => patterns/design-patterns/src/main/java/com/baeldung}/service/locator/EmailService.java (82%) rename {core-java/src/main/java/com/baeldung/designpatterns => patterns/design-patterns/src/main/java/com/baeldung}/service/locator/InitialContext.java (87%) rename {core-java/src/main/java/com/baeldung/designpatterns => patterns/design-patterns/src/main/java/com/baeldung}/service/locator/Main.java (91%) rename {core-java/src/main/java/com/baeldung/designpatterns => patterns/design-patterns/src/main/java/com/baeldung}/service/locator/MessagingService.java (65%) rename {core-java/src/main/java/com/baeldung/designpatterns => patterns/design-patterns/src/main/java/com/baeldung}/service/locator/SMSService.java (82%) rename {core-java/src/main/java/com/baeldung/designpatterns => patterns/design-patterns/src/main/java/com/baeldung}/service/locator/ServiceLocator.java (91%) rename {core-java/src/main/java/com/baeldung/designpatterns => patterns/design-patterns/src/main/java/com/baeldung}/singleton/ClassSingleton.java (91%) rename {core-java/src/main/java/com/baeldung/designpatterns => patterns/design-patterns/src/main/java/com/baeldung}/singleton/EnumSingleton.java (90%) rename {core-java/src/main/java/com/baeldung/designpatterns => patterns/design-patterns/src/main/java/com/baeldung}/singleton/Sandbox.java (96%) rename {core-java/src/main/java/com/baeldung/designpatterns => patterns/design-patterns/src/main/java/com/baeldung}/singleton/synchronization/DclSingleton.java (91%) rename {core-java/src/main/java/com/baeldung/designpatterns => patterns/design-patterns/src/main/java/com/baeldung}/singleton/synchronization/DraconianSingleton.java (90%) rename {core-java/src/main/java/com/baeldung/designpatterns => patterns/design-patterns/src/main/java/com/baeldung}/singleton/synchronization/EarlyInitSingleton.java (90%) rename {core-java/src/main/java/com/baeldung/designpatterns => patterns/design-patterns/src/main/java/com/baeldung}/singleton/synchronization/EnumSingleton.java (77%) rename {core-java/src/main/java/com/baeldung/designpatterns => patterns/design-patterns/src/main/java/com/baeldung}/singleton/synchronization/InitOnDemandSingleton.java (92%) rename patterns/{behavioral-patterns/src/main/java/com/baeldung/pattern => design-patterns/src/main/java/com/baeldung}/templatemethod/application/Application.java (100%) rename patterns/{behavioral-patterns/src/main/java/com/baeldung/pattern => design-patterns/src/main/java/com/baeldung}/templatemethod/model/Computer.java (100%) rename patterns/{behavioral-patterns/src/main/java/com/baeldung/pattern => design-patterns/src/main/java/com/baeldung}/templatemethod/model/ComputerBuilder.java (100%) rename patterns/{behavioral-patterns/src/main/java/com/baeldung/pattern => design-patterns/src/main/java/com/baeldung}/templatemethod/model/HighEndComputer.java (100%) rename patterns/{behavioral-patterns/src/main/java/com/baeldung/pattern => design-patterns/src/main/java/com/baeldung}/templatemethod/model/HighEndComputerBuilder.java (100%) rename patterns/{behavioral-patterns/src/main/java/com/baeldung/pattern => design-patterns/src/main/java/com/baeldung}/templatemethod/model/StandardComputer.java (100%) rename patterns/{behavioral-patterns/src/main/java/com/baeldung/pattern => design-patterns/src/main/java/com/baeldung}/templatemethod/model/StandardComputerBuilder.java (100%) rename {core-java/src/main/java/com/baeldung/designpatterns => patterns/design-patterns/src/main/java/com/baeldung}/util/LogerUtil.java (94%) rename {core-java/src/test/java/com/baeldung/designpatterns => patterns/design-patterns/src/test/java/com/baeldung}/AdapterPatternIntegrationTest.java (68%) rename {core-java/src/test/java/com/baeldung/designpatterns => patterns/design-patterns/src/test/java/com/baeldung}/BridgePatternIntegrationTest.java (64%) rename {core-java/src/test/java/com/baeldung/designpatterns => patterns/design-patterns/src/test/java/com/baeldung}/DecoratorPatternIntegrationTest.java (69%) rename {core-java/src/test/java/com/baeldung/designpatterns => patterns/design-patterns/src/test/java/com/baeldung}/ProxyPatternIntegrationTest.java (80%) rename {core-java/src/test/java/com/baeldung/designpatterns => patterns/design-patterns/src/test/java/com/baeldung}/TestAppenderDP.java (94%) rename patterns/{behavioral-patterns/src/test/java/com/baeldung/pattern => design-patterns/src/test/java/com/baeldung}/chainofresponsibility/ChainOfResponsibilityTest.java (100%) rename patterns/{behavioral-patterns/src/test/java/com/baeldung/pattern => design-patterns/src/test/java/com/baeldung}/command/test/OpenTextFileOperationUnitTest.java (100%) rename patterns/{behavioral-patterns/src/test/java/com/baeldung/pattern => design-patterns/src/test/java/com/baeldung}/command/test/SaveTextFileOperationUnitTest.java (100%) rename patterns/{behavioral-patterns/src/test/java/com/baeldung/pattern => design-patterns/src/test/java/com/baeldung}/command/test/TextFileOperationExecutorUnitTest.java (100%) rename patterns/{behavioral-patterns/src/test/java/com/baeldung/pattern => design-patterns/src/test/java/com/baeldung}/command/test/TextFileUnitTest.java (100%) rename {core-java/src/test/java/com/baeldung/designpatterns => patterns/design-patterns/src/test/java/com/baeldung}/creational/abstractfactory/AbstractPatternIntegrationTest.java (91%) rename {core-java/src/test/java/com/baeldung/designpatterns => patterns/design-patterns/src/test/java/com/baeldung}/creational/builder/BuilderPatternIntegrationTest.java (95%) rename {core-java/src/test/java/com/baeldung/designpatterns => patterns/design-patterns/src/test/java/com/baeldung}/creational/factory/FactoryIntegrationTest.java (94%) rename {core-java/src/test/java/com/baeldung/designpatterns => patterns/design-patterns/src/test/java/com/baeldung}/creational/singleton/SingletonIntegrationTest.java (92%) rename patterns/{facade/src/test/java/com/baeldung/pattern => design-patterns/src/test/java/com/baeldung}/facade/CarEngineFacadeTest.java (94%) rename {core-java/src/test/java/com/baeldung/designpatterns => patterns/design-patterns/src/test/java/com/baeldung}/flyweight/FlyweightUnitTest.java (96%) rename {core-java/src/test/java/com/baeldung/designpatterns => patterns/design-patterns/src/test/java/com/baeldung}/observer/ObserverIntegrationTest.java (87%) rename {core-java/src/test/java/com/baeldung/designpatterns => patterns/design-patterns/src/test/java/com/baeldung}/singleton/synchronization/SingletonSynchronizationUnitTest.java (98%) rename patterns/{behavioral-patterns/src/test/java/com/baeldung/pattern => design-patterns/src/test/java/com/baeldung}/templatemethod/test/TemplateMethodPatternTest.java (100%) delete mode 100644 patterns/facade/pom.xml diff --git a/core-java/src/main/java/com/baeldung/designpatterns/creational/abstractfactory/Color.java b/core-java/src/main/java/com/baeldung/designpatterns/creational/abstractfactory/Color.java deleted file mode 100644 index 897bb71f38..0000000000 --- a/core-java/src/main/java/com/baeldung/designpatterns/creational/abstractfactory/Color.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.baeldung.designpatterns.creational.abstractfactory; - -public interface Color { - String getColor(); -} diff --git a/core-java/src/main/java/com/baeldung/designpatterns/creational/factory/Polygon.java b/core-java/src/main/java/com/baeldung/designpatterns/creational/factory/Polygon.java deleted file mode 100644 index 8364e546b0..0000000000 --- a/core-java/src/main/java/com/baeldung/designpatterns/creational/factory/Polygon.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.baeldung.designpatterns.creational.factory; - -public interface Polygon { - String getType(); -} diff --git a/core-java/src/main/java/com/baeldung/numberofdigits/NumberOfDigitsDriver.java b/core-java/src/main/java/com/baeldung/numberofdigits/NumberOfDigitsDriver.java index 32d3051327..c3cc567eaa 100755 --- a/core-java/src/main/java/com/baeldung/numberofdigits/NumberOfDigitsDriver.java +++ b/core-java/src/main/java/com/baeldung/numberofdigits/NumberOfDigitsDriver.java @@ -1,10 +1,12 @@ package com.baeldung.numberofdigits; -import static com.baeldung.designpatterns.util.LogerUtil.LOG; +import org.apache.log4j.Logger; public class NumberOfDigitsDriver { private static NumberOfDigits numberOfDigits; + private static Logger LOG = Logger.getLogger(NumberOfDigitsDriver.class); + static { numberOfDigits = new NumberOfDigits(); } diff --git a/patterns/facade/README.md b/patterns/design-patterns/README.md similarity index 100% rename from patterns/facade/README.md rename to patterns/design-patterns/README.md diff --git a/patterns/behavioral-patterns/pom.xml b/patterns/design-patterns/pom.xml similarity index 68% rename from patterns/behavioral-patterns/pom.xml rename to patterns/design-patterns/pom.xml index 435f07aa98..87db08ab32 100644 --- a/patterns/behavioral-patterns/pom.xml +++ b/patterns/design-patterns/pom.xml @@ -1,12 +1,12 @@ 4.0.0 - com.baeldung.pattern.templatemethod - pattern.templatemethod + com.baeldung + design-patterns 1.0 jar - com.baeldung.patterns + com.baeldung patterns-parent 1.0.0-SNAPSHOT .. @@ -19,7 +19,7 @@ 4.12 test - + org.hamcrest hamcrest-core 1.3 @@ -31,10 +31,22 @@ 3.8.0 test + + log4j + log4j + ${log4j.version} + + + com.googlecode.grep4j + grep4j + ${grep4j.version} + UTF-8 1.8 1.8 - + 1.2.17 + 1.8.7 + \ No newline at end of file diff --git a/core-java/src/main/java/com/baeldung/designpatterns/adapter/AdapterPatternDriver.java b/patterns/design-patterns/src/main/java/com/baeldung/adapter/AdapterPatternDriver.java similarity index 87% rename from core-java/src/main/java/com/baeldung/designpatterns/adapter/AdapterPatternDriver.java rename to patterns/design-patterns/src/main/java/com/baeldung/adapter/AdapterPatternDriver.java index 79f618d038..a4e10a0868 100644 --- a/core-java/src/main/java/com/baeldung/designpatterns/adapter/AdapterPatternDriver.java +++ b/patterns/design-patterns/src/main/java/com/baeldung/adapter/AdapterPatternDriver.java @@ -1,6 +1,6 @@ -package com.baeldung.designpatterns.adapter; +package com.baeldung.adapter; -import static com.baeldung.designpatterns.util.LogerUtil.LOG; +import static com.baeldung.util.LogerUtil.LOG; public class AdapterPatternDriver { diff --git a/core-java/src/main/java/com/baeldung/designpatterns/adapter/AstonMartin.java b/patterns/design-patterns/src/main/java/com/baeldung/adapter/AstonMartin.java similarity index 69% rename from core-java/src/main/java/com/baeldung/designpatterns/adapter/AstonMartin.java rename to patterns/design-patterns/src/main/java/com/baeldung/adapter/AstonMartin.java index 7dd83079a2..c6aa0c525a 100644 --- a/core-java/src/main/java/com/baeldung/designpatterns/adapter/AstonMartin.java +++ b/patterns/design-patterns/src/main/java/com/baeldung/adapter/AstonMartin.java @@ -1,8 +1,8 @@ -package com.baeldung.designpatterns.adapter; - -public class AstonMartin implements Movable { - @Override - public double getSpeed() { - return 220; - } -} +package com.baeldung.adapter; + +public class AstonMartin implements Movable { + @Override + public double getSpeed() { + return 220; + } +} diff --git a/core-java/src/main/java/com/baeldung/designpatterns/adapter/BugattiVeyron.java b/patterns/design-patterns/src/main/java/com/baeldung/adapter/BugattiVeyron.java similarity index 69% rename from core-java/src/main/java/com/baeldung/designpatterns/adapter/BugattiVeyron.java rename to patterns/design-patterns/src/main/java/com/baeldung/adapter/BugattiVeyron.java index a249d64b6f..e7d47d138a 100644 --- a/core-java/src/main/java/com/baeldung/designpatterns/adapter/BugattiVeyron.java +++ b/patterns/design-patterns/src/main/java/com/baeldung/adapter/BugattiVeyron.java @@ -1,8 +1,8 @@ -package com.baeldung.designpatterns.adapter; - -public class BugattiVeyron implements Movable { - @Override - public double getSpeed() { - return 268; - } -} +package com.baeldung.adapter; + +public class BugattiVeyron implements Movable { + @Override + public double getSpeed() { + return 268; + } +} diff --git a/core-java/src/main/java/com/baeldung/designpatterns/adapter/McLaren.java b/patterns/design-patterns/src/main/java/com/baeldung/adapter/McLaren.java similarity index 68% rename from core-java/src/main/java/com/baeldung/designpatterns/adapter/McLaren.java rename to patterns/design-patterns/src/main/java/com/baeldung/adapter/McLaren.java index c807df67db..4ca1cde856 100644 --- a/core-java/src/main/java/com/baeldung/designpatterns/adapter/McLaren.java +++ b/patterns/design-patterns/src/main/java/com/baeldung/adapter/McLaren.java @@ -1,8 +1,8 @@ -package com.baeldung.designpatterns.adapter; - -public class McLaren implements Movable { - @Override - public double getSpeed() { - return 241; - } -} +package com.baeldung.adapter; + +public class McLaren implements Movable { + @Override + public double getSpeed() { + return 241; + } +} diff --git a/core-java/src/main/java/com/baeldung/designpatterns/adapter/Movable.java b/patterns/design-patterns/src/main/java/com/baeldung/adapter/Movable.java similarity index 61% rename from core-java/src/main/java/com/baeldung/designpatterns/adapter/Movable.java rename to patterns/design-patterns/src/main/java/com/baeldung/adapter/Movable.java index ec94e90af0..bec0bee568 100644 --- a/core-java/src/main/java/com/baeldung/designpatterns/adapter/Movable.java +++ b/patterns/design-patterns/src/main/java/com/baeldung/adapter/Movable.java @@ -1,6 +1,6 @@ -package com.baeldung.designpatterns.adapter; - -public interface Movable { - // returns speed in MPH - double getSpeed(); +package com.baeldung.adapter; + +public interface Movable { + // returns speed in MPH + double getSpeed(); } \ No newline at end of file diff --git a/core-java/src/main/java/com/baeldung/designpatterns/adapter/MovableAdapter.java b/patterns/design-patterns/src/main/java/com/baeldung/adapter/MovableAdapter.java similarity index 66% rename from core-java/src/main/java/com/baeldung/designpatterns/adapter/MovableAdapter.java rename to patterns/design-patterns/src/main/java/com/baeldung/adapter/MovableAdapter.java index b9c7484446..8d529e7b13 100644 --- a/core-java/src/main/java/com/baeldung/designpatterns/adapter/MovableAdapter.java +++ b/patterns/design-patterns/src/main/java/com/baeldung/adapter/MovableAdapter.java @@ -1,4 +1,4 @@ -package com.baeldung.designpatterns.adapter; +package com.baeldung.adapter; public interface MovableAdapter { // returns speed in KMPH diff --git a/core-java/src/main/java/com/baeldung/designpatterns/adapter/MovableAdapterImpl.java b/patterns/design-patterns/src/main/java/com/baeldung/adapter/MovableAdapterImpl.java similarity index 90% rename from core-java/src/main/java/com/baeldung/designpatterns/adapter/MovableAdapterImpl.java rename to patterns/design-patterns/src/main/java/com/baeldung/adapter/MovableAdapterImpl.java index eb74641389..8f18cc9942 100644 --- a/core-java/src/main/java/com/baeldung/designpatterns/adapter/MovableAdapterImpl.java +++ b/patterns/design-patterns/src/main/java/com/baeldung/adapter/MovableAdapterImpl.java @@ -1,4 +1,4 @@ -package com.baeldung.designpatterns.adapter; +package com.baeldung.adapter; public class MovableAdapterImpl implements MovableAdapter { private Movable luxuryCars; diff --git a/core-java/src/main/java/com/baeldung/designpatterns/bridge/Blue.java b/patterns/design-patterns/src/main/java/com/baeldung/bridge/Blue.java similarity index 73% rename from core-java/src/main/java/com/baeldung/designpatterns/bridge/Blue.java rename to patterns/design-patterns/src/main/java/com/baeldung/bridge/Blue.java index da5d29617f..022905f30d 100644 --- a/core-java/src/main/java/com/baeldung/designpatterns/bridge/Blue.java +++ b/patterns/design-patterns/src/main/java/com/baeldung/bridge/Blue.java @@ -1,4 +1,4 @@ -package com.baeldung.designpatterns.bridge; +package com.baeldung.bridge; public class Blue implements Color { @Override diff --git a/core-java/src/main/java/com/baeldung/designpatterns/bridge/BridgePatternDriver.java b/patterns/design-patterns/src/main/java/com/baeldung/bridge/BridgePatternDriver.java similarity index 88% rename from core-java/src/main/java/com/baeldung/designpatterns/bridge/BridgePatternDriver.java rename to patterns/design-patterns/src/main/java/com/baeldung/bridge/BridgePatternDriver.java index e6a7fb41c1..31d18a2347 100644 --- a/core-java/src/main/java/com/baeldung/designpatterns/bridge/BridgePatternDriver.java +++ b/patterns/design-patterns/src/main/java/com/baeldung/bridge/BridgePatternDriver.java @@ -1,4 +1,4 @@ -package com.baeldung.designpatterns.bridge; +package com.baeldung.bridge; public class BridgePatternDriver { diff --git a/core-java/src/main/java/com/baeldung/designpatterns/bridge/Color.java b/patterns/design-patterns/src/main/java/com/baeldung/bridge/Color.java similarity index 51% rename from core-java/src/main/java/com/baeldung/designpatterns/bridge/Color.java rename to patterns/design-patterns/src/main/java/com/baeldung/bridge/Color.java index 05618e6d6e..9d38f407ba 100644 --- a/core-java/src/main/java/com/baeldung/designpatterns/bridge/Color.java +++ b/patterns/design-patterns/src/main/java/com/baeldung/bridge/Color.java @@ -1,4 +1,4 @@ -package com.baeldung.designpatterns.bridge; +package com.baeldung.bridge; public interface Color { String fill(); diff --git a/core-java/src/main/java/com/baeldung/designpatterns/bridge/Red.java b/patterns/design-patterns/src/main/java/com/baeldung/bridge/Red.java similarity index 73% rename from core-java/src/main/java/com/baeldung/designpatterns/bridge/Red.java rename to patterns/design-patterns/src/main/java/com/baeldung/bridge/Red.java index bc83199591..e7011096ce 100644 --- a/core-java/src/main/java/com/baeldung/designpatterns/bridge/Red.java +++ b/patterns/design-patterns/src/main/java/com/baeldung/bridge/Red.java @@ -1,4 +1,4 @@ -package com.baeldung.designpatterns.bridge; +package com.baeldung.bridge; public class Red implements Color { diff --git a/core-java/src/main/java/com/baeldung/designpatterns/bridge/Shape.java b/patterns/design-patterns/src/main/java/com/baeldung/bridge/Shape.java similarity index 79% rename from core-java/src/main/java/com/baeldung/designpatterns/bridge/Shape.java rename to patterns/design-patterns/src/main/java/com/baeldung/bridge/Shape.java index 75cd43dbc8..20085cf112 100644 --- a/core-java/src/main/java/com/baeldung/designpatterns/bridge/Shape.java +++ b/patterns/design-patterns/src/main/java/com/baeldung/bridge/Shape.java @@ -1,4 +1,4 @@ -package com.baeldung.designpatterns.bridge; +package com.baeldung.bridge; public abstract class Shape { protected Color color; diff --git a/core-java/src/main/java/com/baeldung/designpatterns/bridge/Square.java b/patterns/design-patterns/src/main/java/com/baeldung/bridge/Square.java similarity index 81% rename from core-java/src/main/java/com/baeldung/designpatterns/bridge/Square.java rename to patterns/design-patterns/src/main/java/com/baeldung/bridge/Square.java index 7397f4bd47..21a59247d5 100644 --- a/core-java/src/main/java/com/baeldung/designpatterns/bridge/Square.java +++ b/patterns/design-patterns/src/main/java/com/baeldung/bridge/Square.java @@ -1,4 +1,4 @@ -package com.baeldung.designpatterns.bridge; +package com.baeldung.bridge; public class Square extends Shape { diff --git a/core-java/src/main/java/com/baeldung/designpatterns/bridge/Triangle.java b/patterns/design-patterns/src/main/java/com/baeldung/bridge/Triangle.java similarity index 82% rename from core-java/src/main/java/com/baeldung/designpatterns/bridge/Triangle.java rename to patterns/design-patterns/src/main/java/com/baeldung/bridge/Triangle.java index 46db66ee42..1647e7106d 100644 --- a/core-java/src/main/java/com/baeldung/designpatterns/bridge/Triangle.java +++ b/patterns/design-patterns/src/main/java/com/baeldung/bridge/Triangle.java @@ -1,4 +1,4 @@ -package com.baeldung.designpatterns.bridge; +package com.baeldung.bridge; public class Triangle extends Shape { diff --git a/patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/chainofresponsibility/AuthenticationProcessor.java b/patterns/design-patterns/src/main/java/com/baeldung/chainofresponsibility/AuthenticationProcessor.java similarity index 100% rename from patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/chainofresponsibility/AuthenticationProcessor.java rename to patterns/design-patterns/src/main/java/com/baeldung/chainofresponsibility/AuthenticationProcessor.java diff --git a/patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/chainofresponsibility/AuthenticationProvider.java b/patterns/design-patterns/src/main/java/com/baeldung/chainofresponsibility/AuthenticationProvider.java similarity index 100% rename from patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/chainofresponsibility/AuthenticationProvider.java rename to patterns/design-patterns/src/main/java/com/baeldung/chainofresponsibility/AuthenticationProvider.java diff --git a/patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/chainofresponsibility/OAuthAuthenticationProcessor.java b/patterns/design-patterns/src/main/java/com/baeldung/chainofresponsibility/OAuthAuthenticationProcessor.java similarity index 100% rename from patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/chainofresponsibility/OAuthAuthenticationProcessor.java rename to patterns/design-patterns/src/main/java/com/baeldung/chainofresponsibility/OAuthAuthenticationProcessor.java diff --git a/patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/chainofresponsibility/OAuthTokenProvider.java b/patterns/design-patterns/src/main/java/com/baeldung/chainofresponsibility/OAuthTokenProvider.java similarity index 100% rename from patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/chainofresponsibility/OAuthTokenProvider.java rename to patterns/design-patterns/src/main/java/com/baeldung/chainofresponsibility/OAuthTokenProvider.java diff --git a/patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/chainofresponsibility/SamlAuthenticationProvider.java b/patterns/design-patterns/src/main/java/com/baeldung/chainofresponsibility/SamlAuthenticationProvider.java similarity index 100% rename from patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/chainofresponsibility/SamlAuthenticationProvider.java rename to patterns/design-patterns/src/main/java/com/baeldung/chainofresponsibility/SamlAuthenticationProvider.java diff --git a/patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/chainofresponsibility/UsernamePasswordAuthenticationProcessor.java b/patterns/design-patterns/src/main/java/com/baeldung/chainofresponsibility/UsernamePasswordAuthenticationProcessor.java similarity index 100% rename from patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/chainofresponsibility/UsernamePasswordAuthenticationProcessor.java rename to patterns/design-patterns/src/main/java/com/baeldung/chainofresponsibility/UsernamePasswordAuthenticationProcessor.java diff --git a/patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/chainofresponsibility/UsernamePasswordProvider.java b/patterns/design-patterns/src/main/java/com/baeldung/chainofresponsibility/UsernamePasswordProvider.java similarity index 100% rename from patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/chainofresponsibility/UsernamePasswordProvider.java rename to patterns/design-patterns/src/main/java/com/baeldung/chainofresponsibility/UsernamePasswordProvider.java diff --git a/patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/command/client/TextFileApplication.java b/patterns/design-patterns/src/main/java/com/baeldung/command/client/TextFileApplication.java similarity index 100% rename from patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/command/client/TextFileApplication.java rename to patterns/design-patterns/src/main/java/com/baeldung/command/client/TextFileApplication.java diff --git a/patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/command/command/OpenTextFileOperation.java b/patterns/design-patterns/src/main/java/com/baeldung/command/command/OpenTextFileOperation.java similarity index 100% rename from patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/command/command/OpenTextFileOperation.java rename to patterns/design-patterns/src/main/java/com/baeldung/command/command/OpenTextFileOperation.java diff --git a/patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/command/command/SaveTextFileOperation.java b/patterns/design-patterns/src/main/java/com/baeldung/command/command/SaveTextFileOperation.java similarity index 100% rename from patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/command/command/SaveTextFileOperation.java rename to patterns/design-patterns/src/main/java/com/baeldung/command/command/SaveTextFileOperation.java diff --git a/patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/command/command/TextFileOperation.java b/patterns/design-patterns/src/main/java/com/baeldung/command/command/TextFileOperation.java similarity index 100% rename from patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/command/command/TextFileOperation.java rename to patterns/design-patterns/src/main/java/com/baeldung/command/command/TextFileOperation.java diff --git a/patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/command/invoker/TextFileOperationExecutor.java b/patterns/design-patterns/src/main/java/com/baeldung/command/invoker/TextFileOperationExecutor.java similarity index 100% rename from patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/command/invoker/TextFileOperationExecutor.java rename to patterns/design-patterns/src/main/java/com/baeldung/command/invoker/TextFileOperationExecutor.java diff --git a/patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/command/receiver/TextFile.java b/patterns/design-patterns/src/main/java/com/baeldung/command/receiver/TextFile.java similarity index 100% rename from patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/command/receiver/TextFile.java rename to patterns/design-patterns/src/main/java/com/baeldung/command/receiver/TextFile.java diff --git a/core-java/src/main/java/com/baeldung/designpatterns/composite/CompositeDemo.java b/patterns/design-patterns/src/main/java/com/baeldung/composite/CompositeDemo.java similarity index 92% rename from core-java/src/main/java/com/baeldung/designpatterns/composite/CompositeDemo.java rename to patterns/design-patterns/src/main/java/com/baeldung/composite/CompositeDemo.java index 9537dd0d2b..2296912c76 100644 --- a/core-java/src/main/java/com/baeldung/designpatterns/composite/CompositeDemo.java +++ b/patterns/design-patterns/src/main/java/com/baeldung/composite/CompositeDemo.java @@ -1,4 +1,4 @@ -package com.baeldung.designpatterns.composite; +package com.baeldung.composite; /** * Created by Gebruiker on 5/3/2018. diff --git a/core-java/src/main/java/com/baeldung/designpatterns/composite/Department.java b/patterns/design-patterns/src/main/java/com/baeldung/composite/Department.java similarity index 70% rename from core-java/src/main/java/com/baeldung/designpatterns/composite/Department.java rename to patterns/design-patterns/src/main/java/com/baeldung/composite/Department.java index 82fa3a3efc..7e623a9337 100644 --- a/core-java/src/main/java/com/baeldung/designpatterns/composite/Department.java +++ b/patterns/design-patterns/src/main/java/com/baeldung/composite/Department.java @@ -1,4 +1,4 @@ -package com.baeldung.designpatterns.composite; +package com.baeldung.composite; /** * Created by Gebruiker on 5/1/2018. diff --git a/core-java/src/main/java/com/baeldung/designpatterns/composite/FinancialDepartment.java b/patterns/design-patterns/src/main/java/com/baeldung/composite/FinancialDepartment.java similarity index 92% rename from core-java/src/main/java/com/baeldung/designpatterns/composite/FinancialDepartment.java rename to patterns/design-patterns/src/main/java/com/baeldung/composite/FinancialDepartment.java index dc5a2bb9d9..173281f833 100644 --- a/core-java/src/main/java/com/baeldung/designpatterns/composite/FinancialDepartment.java +++ b/patterns/design-patterns/src/main/java/com/baeldung/composite/FinancialDepartment.java @@ -1,4 +1,4 @@ -package com.baeldung.designpatterns.composite; +package com.baeldung.composite; /** * Created by Gebruiker on 5/1/2018. diff --git a/core-java/src/main/java/com/baeldung/designpatterns/composite/HeadDepartment.java b/patterns/design-patterns/src/main/java/com/baeldung/composite/HeadDepartment.java similarity index 94% rename from core-java/src/main/java/com/baeldung/designpatterns/composite/HeadDepartment.java rename to patterns/design-patterns/src/main/java/com/baeldung/composite/HeadDepartment.java index 119b9c76b5..f54bcf303b 100644 --- a/core-java/src/main/java/com/baeldung/designpatterns/composite/HeadDepartment.java +++ b/patterns/design-patterns/src/main/java/com/baeldung/composite/HeadDepartment.java @@ -1,4 +1,4 @@ -package com.baeldung.designpatterns.composite; +package com.baeldung.composite; import java.util.ArrayList; import java.util.List; diff --git a/core-java/src/main/java/com/baeldung/designpatterns/composite/SalesDepartment.java b/patterns/design-patterns/src/main/java/com/baeldung/composite/SalesDepartment.java similarity index 92% rename from core-java/src/main/java/com/baeldung/designpatterns/composite/SalesDepartment.java rename to patterns/design-patterns/src/main/java/com/baeldung/composite/SalesDepartment.java index af234b4915..7f5e903100 100644 --- a/core-java/src/main/java/com/baeldung/designpatterns/composite/SalesDepartment.java +++ b/patterns/design-patterns/src/main/java/com/baeldung/composite/SalesDepartment.java @@ -1,4 +1,4 @@ -package com.baeldung.designpatterns.composite; +package com.baeldung.composite; /** * Created by Gebruiker on 5/1/2018. diff --git a/core-java/src/main/java/com/baeldung/designpatterns/creational/abstractfactory/AbstractFactory.java b/patterns/design-patterns/src/main/java/com/baeldung/creational/abstractfactory/AbstractFactory.java similarity index 64% rename from core-java/src/main/java/com/baeldung/designpatterns/creational/abstractfactory/AbstractFactory.java rename to patterns/design-patterns/src/main/java/com/baeldung/creational/abstractfactory/AbstractFactory.java index 46d97d1a15..5b4bf08006 100644 --- a/core-java/src/main/java/com/baeldung/designpatterns/creational/abstractfactory/AbstractFactory.java +++ b/patterns/design-patterns/src/main/java/com/baeldung/creational/abstractfactory/AbstractFactory.java @@ -1,4 +1,4 @@ -package com.baeldung.designpatterns.creational.abstractfactory; +package com.baeldung.creational.abstractfactory; public interface AbstractFactory { Animal getAnimal(String toyType) ; diff --git a/core-java/src/main/java/com/baeldung/designpatterns/creational/abstractfactory/AbstractPatternDriver.java b/patterns/design-patterns/src/main/java/com/baeldung/creational/abstractfactory/AbstractPatternDriver.java similarity index 90% rename from core-java/src/main/java/com/baeldung/designpatterns/creational/abstractfactory/AbstractPatternDriver.java rename to patterns/design-patterns/src/main/java/com/baeldung/creational/abstractfactory/AbstractPatternDriver.java index 7ab166e16a..68759d5aff 100644 --- a/core-java/src/main/java/com/baeldung/designpatterns/creational/abstractfactory/AbstractPatternDriver.java +++ b/patterns/design-patterns/src/main/java/com/baeldung/creational/abstractfactory/AbstractPatternDriver.java @@ -1,4 +1,4 @@ -package com.baeldung.designpatterns.creational.abstractfactory; +package com.baeldung.creational.abstractfactory; public class AbstractPatternDriver { public static void main(String[] args) { diff --git a/core-java/src/main/java/com/baeldung/designpatterns/creational/abstractfactory/Animal.java b/patterns/design-patterns/src/main/java/com/baeldung/creational/abstractfactory/Animal.java similarity index 53% rename from core-java/src/main/java/com/baeldung/designpatterns/creational/abstractfactory/Animal.java rename to patterns/design-patterns/src/main/java/com/baeldung/creational/abstractfactory/Animal.java index 59c1336053..52a8c83752 100644 --- a/core-java/src/main/java/com/baeldung/designpatterns/creational/abstractfactory/Animal.java +++ b/patterns/design-patterns/src/main/java/com/baeldung/creational/abstractfactory/Animal.java @@ -1,4 +1,4 @@ -package com.baeldung.designpatterns.creational.abstractfactory; +package com.baeldung.creational.abstractfactory; public interface Animal { String getType(); diff --git a/core-java/src/main/java/com/baeldung/designpatterns/creational/abstractfactory/AnimalFactory.java b/patterns/design-patterns/src/main/java/com/baeldung/creational/abstractfactory/AnimalFactory.java similarity index 87% rename from core-java/src/main/java/com/baeldung/designpatterns/creational/abstractfactory/AnimalFactory.java rename to patterns/design-patterns/src/main/java/com/baeldung/creational/abstractfactory/AnimalFactory.java index 49583c3a98..bbc3eb7a82 100644 --- a/core-java/src/main/java/com/baeldung/designpatterns/creational/abstractfactory/AnimalFactory.java +++ b/patterns/design-patterns/src/main/java/com/baeldung/creational/abstractfactory/AnimalFactory.java @@ -1,4 +1,4 @@ -package com.baeldung.designpatterns.creational.abstractfactory; +package com.baeldung.creational.abstractfactory; public class AnimalFactory implements AbstractFactory { diff --git a/core-java/src/main/java/com/baeldung/designpatterns/creational/abstractfactory/Brown.java b/patterns/design-patterns/src/main/java/com/baeldung/creational/abstractfactory/Brown.java similarity index 64% rename from core-java/src/main/java/com/baeldung/designpatterns/creational/abstractfactory/Brown.java rename to patterns/design-patterns/src/main/java/com/baeldung/creational/abstractfactory/Brown.java index f251285ebf..d395d9de33 100644 --- a/core-java/src/main/java/com/baeldung/designpatterns/creational/abstractfactory/Brown.java +++ b/patterns/design-patterns/src/main/java/com/baeldung/creational/abstractfactory/Brown.java @@ -1,4 +1,4 @@ -package com.baeldung.designpatterns.creational.abstractfactory; +package com.baeldung.creational.abstractfactory; public class Brown implements Color { diff --git a/patterns/design-patterns/src/main/java/com/baeldung/creational/abstractfactory/Color.java b/patterns/design-patterns/src/main/java/com/baeldung/creational/abstractfactory/Color.java new file mode 100644 index 0000000000..337760fa4d --- /dev/null +++ b/patterns/design-patterns/src/main/java/com/baeldung/creational/abstractfactory/Color.java @@ -0,0 +1,5 @@ +package com.baeldung.creational.abstractfactory; + +public interface Color { + String getColor(); +} diff --git a/core-java/src/main/java/com/baeldung/designpatterns/creational/abstractfactory/ColorFactory.java b/patterns/design-patterns/src/main/java/com/baeldung/creational/abstractfactory/ColorFactory.java similarity index 87% rename from core-java/src/main/java/com/baeldung/designpatterns/creational/abstractfactory/ColorFactory.java rename to patterns/design-patterns/src/main/java/com/baeldung/creational/abstractfactory/ColorFactory.java index 8f7559ff27..8b7e4f8086 100644 --- a/core-java/src/main/java/com/baeldung/designpatterns/creational/abstractfactory/ColorFactory.java +++ b/patterns/design-patterns/src/main/java/com/baeldung/creational/abstractfactory/ColorFactory.java @@ -1,4 +1,4 @@ -package com.baeldung.designpatterns.creational.abstractfactory; +package com.baeldung.creational.abstractfactory; public class ColorFactory implements AbstractFactory { diff --git a/core-java/src/main/java/com/baeldung/designpatterns/creational/abstractfactory/Dog.java b/patterns/design-patterns/src/main/java/com/baeldung/creational/abstractfactory/Dog.java similarity index 74% rename from core-java/src/main/java/com/baeldung/designpatterns/creational/abstractfactory/Dog.java rename to patterns/design-patterns/src/main/java/com/baeldung/creational/abstractfactory/Dog.java index 002b5665d3..38e90f34dc 100644 --- a/core-java/src/main/java/com/baeldung/designpatterns/creational/abstractfactory/Dog.java +++ b/patterns/design-patterns/src/main/java/com/baeldung/creational/abstractfactory/Dog.java @@ -1,4 +1,4 @@ -package com.baeldung.designpatterns.creational.abstractfactory; +package com.baeldung.creational.abstractfactory; public class Dog implements Animal { diff --git a/core-java/src/main/java/com/baeldung/designpatterns/creational/abstractfactory/Duck.java b/patterns/design-patterns/src/main/java/com/baeldung/creational/abstractfactory/Duck.java similarity index 75% rename from core-java/src/main/java/com/baeldung/designpatterns/creational/abstractfactory/Duck.java rename to patterns/design-patterns/src/main/java/com/baeldung/creational/abstractfactory/Duck.java index 5603ad6eee..678ae5ca0c 100644 --- a/core-java/src/main/java/com/baeldung/designpatterns/creational/abstractfactory/Duck.java +++ b/patterns/design-patterns/src/main/java/com/baeldung/creational/abstractfactory/Duck.java @@ -1,4 +1,4 @@ -package com.baeldung.designpatterns.creational.abstractfactory; +package com.baeldung.creational.abstractfactory; public class Duck implements Animal { diff --git a/core-java/src/main/java/com/baeldung/designpatterns/creational/abstractfactory/FactoryProvider.java b/patterns/design-patterns/src/main/java/com/baeldung/creational/abstractfactory/FactoryProvider.java similarity index 83% rename from core-java/src/main/java/com/baeldung/designpatterns/creational/abstractfactory/FactoryProvider.java rename to patterns/design-patterns/src/main/java/com/baeldung/creational/abstractfactory/FactoryProvider.java index fcbee1e6de..34ddbea545 100644 --- a/core-java/src/main/java/com/baeldung/designpatterns/creational/abstractfactory/FactoryProvider.java +++ b/patterns/design-patterns/src/main/java/com/baeldung/creational/abstractfactory/FactoryProvider.java @@ -1,4 +1,4 @@ -package com.baeldung.designpatterns.creational.abstractfactory; +package com.baeldung.creational.abstractfactory; public class FactoryProvider { public static AbstractFactory getFactory(String choice){ diff --git a/core-java/src/main/java/com/baeldung/designpatterns/creational/abstractfactory/White.java b/patterns/design-patterns/src/main/java/com/baeldung/creational/abstractfactory/White.java similarity index 64% rename from core-java/src/main/java/com/baeldung/designpatterns/creational/abstractfactory/White.java rename to patterns/design-patterns/src/main/java/com/baeldung/creational/abstractfactory/White.java index 62ef8048ea..6cb1e4cdd4 100644 --- a/core-java/src/main/java/com/baeldung/designpatterns/creational/abstractfactory/White.java +++ b/patterns/design-patterns/src/main/java/com/baeldung/creational/abstractfactory/White.java @@ -1,4 +1,4 @@ -package com.baeldung.designpatterns.creational.abstractfactory; +package com.baeldung.creational.abstractfactory; public class White implements Color { diff --git a/core-java/src/main/java/com/baeldung/designpatterns/creational/builder/BankAccount.java b/patterns/design-patterns/src/main/java/com/baeldung/creational/builder/BankAccount.java similarity index 96% rename from core-java/src/main/java/com/baeldung/designpatterns/creational/builder/BankAccount.java rename to patterns/design-patterns/src/main/java/com/baeldung/creational/builder/BankAccount.java index 355fa74895..1c6b0cc78e 100644 --- a/core-java/src/main/java/com/baeldung/designpatterns/creational/builder/BankAccount.java +++ b/patterns/design-patterns/src/main/java/com/baeldung/creational/builder/BankAccount.java @@ -1,4 +1,4 @@ -package com.baeldung.designpatterns.creational.builder; +package com.baeldung.creational.builder; public class BankAccount { private String name; diff --git a/core-java/src/main/java/com/baeldung/designpatterns/creational/builder/BuilderPatternDriver.java b/patterns/design-patterns/src/main/java/com/baeldung/creational/builder/BuilderPatternDriver.java similarity index 90% rename from core-java/src/main/java/com/baeldung/designpatterns/creational/builder/BuilderPatternDriver.java rename to patterns/design-patterns/src/main/java/com/baeldung/creational/builder/BuilderPatternDriver.java index d92a70e664..2d3a88a86b 100644 --- a/core-java/src/main/java/com/baeldung/designpatterns/creational/builder/BuilderPatternDriver.java +++ b/patterns/design-patterns/src/main/java/com/baeldung/creational/builder/BuilderPatternDriver.java @@ -1,4 +1,4 @@ -package com.baeldung.designpatterns.creational.builder; +package com.baeldung.creational.builder; public class BuilderPatternDriver { public static void main(String[] args) { diff --git a/core-java/src/main/java/com/baeldung/designpatterns/creational/factory/FactoryDriver.java b/patterns/design-patterns/src/main/java/com/baeldung/creational/factory/FactoryDriver.java similarity index 89% rename from core-java/src/main/java/com/baeldung/designpatterns/creational/factory/FactoryDriver.java rename to patterns/design-patterns/src/main/java/com/baeldung/creational/factory/FactoryDriver.java index 64ee307bb8..9261a5c0cb 100644 --- a/core-java/src/main/java/com/baeldung/designpatterns/creational/factory/FactoryDriver.java +++ b/patterns/design-patterns/src/main/java/com/baeldung/creational/factory/FactoryDriver.java @@ -1,4 +1,4 @@ -package com.baeldung.designpatterns.creational.factory; +package com.baeldung.creational.factory; public class FactoryDriver { public static void main(String[] args) { diff --git a/core-java/src/main/java/com/baeldung/designpatterns/creational/factory/Heptagon.java b/patterns/design-patterns/src/main/java/com/baeldung/creational/factory/Heptagon.java similarity index 69% rename from core-java/src/main/java/com/baeldung/designpatterns/creational/factory/Heptagon.java rename to patterns/design-patterns/src/main/java/com/baeldung/creational/factory/Heptagon.java index 935fc2f04c..9e6f04b951 100644 --- a/core-java/src/main/java/com/baeldung/designpatterns/creational/factory/Heptagon.java +++ b/patterns/design-patterns/src/main/java/com/baeldung/creational/factory/Heptagon.java @@ -1,4 +1,4 @@ -package com.baeldung.designpatterns.creational.factory; +package com.baeldung.creational.factory; public class Heptagon implements Polygon { diff --git a/core-java/src/main/java/com/baeldung/designpatterns/creational/factory/Octagon.java b/patterns/design-patterns/src/main/java/com/baeldung/creational/factory/Octagon.java similarity index 68% rename from core-java/src/main/java/com/baeldung/designpatterns/creational/factory/Octagon.java rename to patterns/design-patterns/src/main/java/com/baeldung/creational/factory/Octagon.java index fc62302dc8..b5c3be8a87 100644 --- a/core-java/src/main/java/com/baeldung/designpatterns/creational/factory/Octagon.java +++ b/patterns/design-patterns/src/main/java/com/baeldung/creational/factory/Octagon.java @@ -1,4 +1,4 @@ -package com.baeldung.designpatterns.creational.factory; +package com.baeldung.creational.factory; public class Octagon implements Polygon { diff --git a/core-java/src/main/java/com/baeldung/designpatterns/creational/factory/Pentagon.java b/patterns/design-patterns/src/main/java/com/baeldung/creational/factory/Pentagon.java similarity index 69% rename from core-java/src/main/java/com/baeldung/designpatterns/creational/factory/Pentagon.java rename to patterns/design-patterns/src/main/java/com/baeldung/creational/factory/Pentagon.java index 65d109b10b..0866de4f25 100644 --- a/core-java/src/main/java/com/baeldung/designpatterns/creational/factory/Pentagon.java +++ b/patterns/design-patterns/src/main/java/com/baeldung/creational/factory/Pentagon.java @@ -1,4 +1,4 @@ -package com.baeldung.designpatterns.creational.factory; +package com.baeldung.creational.factory; public class Pentagon implements Polygon { diff --git a/patterns/design-patterns/src/main/java/com/baeldung/creational/factory/Polygon.java b/patterns/design-patterns/src/main/java/com/baeldung/creational/factory/Polygon.java new file mode 100644 index 0000000000..ed3f13eed6 --- /dev/null +++ b/patterns/design-patterns/src/main/java/com/baeldung/creational/factory/Polygon.java @@ -0,0 +1,5 @@ +package com.baeldung.creational.factory; + +public interface Polygon { + String getType(); +} diff --git a/core-java/src/main/java/com/baeldung/designpatterns/creational/factory/PolygonFactory.java b/patterns/design-patterns/src/main/java/com/baeldung/creational/factory/PolygonFactory.java similarity index 89% rename from core-java/src/main/java/com/baeldung/designpatterns/creational/factory/PolygonFactory.java rename to patterns/design-patterns/src/main/java/com/baeldung/creational/factory/PolygonFactory.java index 9f34fe77b9..c9af0952da 100644 --- a/core-java/src/main/java/com/baeldung/designpatterns/creational/factory/PolygonFactory.java +++ b/patterns/design-patterns/src/main/java/com/baeldung/creational/factory/PolygonFactory.java @@ -1,4 +1,4 @@ -package com.baeldung.designpatterns.creational.factory; +package com.baeldung.creational.factory; public class PolygonFactory { public Polygon getPolygon(int numberOfSides) { diff --git a/core-java/src/main/java/com/baeldung/designpatterns/creational/factory/Square.java b/patterns/design-patterns/src/main/java/com/baeldung/creational/factory/Square.java similarity index 68% rename from core-java/src/main/java/com/baeldung/designpatterns/creational/factory/Square.java rename to patterns/design-patterns/src/main/java/com/baeldung/creational/factory/Square.java index 805c1c9ae3..5c19873f00 100644 --- a/core-java/src/main/java/com/baeldung/designpatterns/creational/factory/Square.java +++ b/patterns/design-patterns/src/main/java/com/baeldung/creational/factory/Square.java @@ -1,4 +1,4 @@ -package com.baeldung.designpatterns.creational.factory; +package com.baeldung.creational.factory; public class Square implements Polygon { diff --git a/core-java/src/main/java/com/baeldung/designpatterns/creational/factory/Triangle.java b/patterns/design-patterns/src/main/java/com/baeldung/creational/factory/Triangle.java similarity index 69% rename from core-java/src/main/java/com/baeldung/designpatterns/creational/factory/Triangle.java rename to patterns/design-patterns/src/main/java/com/baeldung/creational/factory/Triangle.java index 8a8832d8a1..2f84674ae5 100644 --- a/core-java/src/main/java/com/baeldung/designpatterns/creational/factory/Triangle.java +++ b/patterns/design-patterns/src/main/java/com/baeldung/creational/factory/Triangle.java @@ -1,4 +1,4 @@ -package com.baeldung.designpatterns.creational.factory; +package com.baeldung.creational.factory; public class Triangle implements Polygon { diff --git a/core-java/src/main/java/com/baeldung/designpatterns/creational/singleton/Singleton.java b/patterns/design-patterns/src/main/java/com/baeldung/creational/singleton/Singleton.java similarity index 83% rename from core-java/src/main/java/com/baeldung/designpatterns/creational/singleton/Singleton.java rename to patterns/design-patterns/src/main/java/com/baeldung/creational/singleton/Singleton.java index 1a5ac82c89..e914fbd4af 100644 --- a/core-java/src/main/java/com/baeldung/designpatterns/creational/singleton/Singleton.java +++ b/patterns/design-patterns/src/main/java/com/baeldung/creational/singleton/Singleton.java @@ -1,4 +1,4 @@ -package com.baeldung.designpatterns.creational.singleton; +package com.baeldung.creational.singleton; public class Singleton { private Singleton() {} diff --git a/core-java/src/main/java/com/baeldung/designpatterns/creational/singleton/SingletonDriver.java b/patterns/design-patterns/src/main/java/com/baeldung/creational/singleton/SingletonDriver.java similarity index 76% rename from core-java/src/main/java/com/baeldung/designpatterns/creational/singleton/SingletonDriver.java rename to patterns/design-patterns/src/main/java/com/baeldung/creational/singleton/SingletonDriver.java index 1955008d3e..555e751acb 100644 --- a/core-java/src/main/java/com/baeldung/designpatterns/creational/singleton/SingletonDriver.java +++ b/patterns/design-patterns/src/main/java/com/baeldung/creational/singleton/SingletonDriver.java @@ -1,4 +1,4 @@ -package com.baeldung.designpatterns.creational.singleton; +package com.baeldung.creational.singleton; public class SingletonDriver { public static void main(String[] args) { diff --git a/core-java/src/main/java/com/baeldung/designpatterns/decorator/BubbleLights.java b/patterns/design-patterns/src/main/java/com/baeldung/decorator/BubbleLights.java similarity index 87% rename from core-java/src/main/java/com/baeldung/designpatterns/decorator/BubbleLights.java rename to patterns/design-patterns/src/main/java/com/baeldung/decorator/BubbleLights.java index 881add8b21..fff5a95b4b 100644 --- a/core-java/src/main/java/com/baeldung/designpatterns/decorator/BubbleLights.java +++ b/patterns/design-patterns/src/main/java/com/baeldung/decorator/BubbleLights.java @@ -1,4 +1,4 @@ -package com.baeldung.designpatterns.decorator; +package com.baeldung.decorator; public class BubbleLights extends TreeDecorator { diff --git a/core-java/src/main/java/com/baeldung/designpatterns/decorator/ChristmasTree.java b/patterns/design-patterns/src/main/java/com/baeldung/decorator/ChristmasTree.java similarity index 55% rename from core-java/src/main/java/com/baeldung/designpatterns/decorator/ChristmasTree.java rename to patterns/design-patterns/src/main/java/com/baeldung/decorator/ChristmasTree.java index e5dca41dd8..be07f4faf2 100644 --- a/core-java/src/main/java/com/baeldung/designpatterns/decorator/ChristmasTree.java +++ b/patterns/design-patterns/src/main/java/com/baeldung/decorator/ChristmasTree.java @@ -1,4 +1,4 @@ -package com.baeldung.designpatterns.decorator; +package com.baeldung.decorator; public interface ChristmasTree { String decorate(); diff --git a/core-java/src/main/java/com/baeldung/designpatterns/decorator/ChristmasTreeImpl.java b/patterns/design-patterns/src/main/java/com/baeldung/decorator/ChristmasTreeImpl.java similarity index 75% rename from core-java/src/main/java/com/baeldung/designpatterns/decorator/ChristmasTreeImpl.java rename to patterns/design-patterns/src/main/java/com/baeldung/decorator/ChristmasTreeImpl.java index 9241fd59db..2b9e210eab 100644 --- a/core-java/src/main/java/com/baeldung/designpatterns/decorator/ChristmasTreeImpl.java +++ b/patterns/design-patterns/src/main/java/com/baeldung/decorator/ChristmasTreeImpl.java @@ -1,4 +1,4 @@ -package com.baeldung.designpatterns.decorator; +package com.baeldung.decorator; public class ChristmasTreeImpl implements ChristmasTree { diff --git a/core-java/src/main/java/com/baeldung/designpatterns/decorator/DecoratorPatternDriver.java b/patterns/design-patterns/src/main/java/com/baeldung/decorator/DecoratorPatternDriver.java similarity index 80% rename from core-java/src/main/java/com/baeldung/designpatterns/decorator/DecoratorPatternDriver.java rename to patterns/design-patterns/src/main/java/com/baeldung/decorator/DecoratorPatternDriver.java index 70b4f801cd..c20c23ff6e 100644 --- a/core-java/src/main/java/com/baeldung/designpatterns/decorator/DecoratorPatternDriver.java +++ b/patterns/design-patterns/src/main/java/com/baeldung/decorator/DecoratorPatternDriver.java @@ -1,6 +1,6 @@ -package com.baeldung.designpatterns.decorator; +package com.baeldung.decorator; -import static com.baeldung.designpatterns.util.LogerUtil.LOG; +import static com.baeldung.util.LogerUtil.LOG; public class DecoratorPatternDriver { diff --git a/core-java/src/main/java/com/baeldung/designpatterns/decorator/Garland.java b/patterns/design-patterns/src/main/java/com/baeldung/decorator/Garland.java similarity index 86% rename from core-java/src/main/java/com/baeldung/designpatterns/decorator/Garland.java rename to patterns/design-patterns/src/main/java/com/baeldung/decorator/Garland.java index d2efd6e451..d3cb28a9e9 100644 --- a/core-java/src/main/java/com/baeldung/designpatterns/decorator/Garland.java +++ b/patterns/design-patterns/src/main/java/com/baeldung/decorator/Garland.java @@ -1,4 +1,4 @@ -package com.baeldung.designpatterns.decorator; +package com.baeldung.decorator; public class Garland extends TreeDecorator { diff --git a/core-java/src/main/java/com/baeldung/designpatterns/decorator/TreeDecorator.java b/patterns/design-patterns/src/main/java/com/baeldung/decorator/TreeDecorator.java similarity index 85% rename from core-java/src/main/java/com/baeldung/designpatterns/decorator/TreeDecorator.java rename to patterns/design-patterns/src/main/java/com/baeldung/decorator/TreeDecorator.java index 5427d2ac7e..47385a1967 100644 --- a/core-java/src/main/java/com/baeldung/designpatterns/decorator/TreeDecorator.java +++ b/patterns/design-patterns/src/main/java/com/baeldung/decorator/TreeDecorator.java @@ -1,4 +1,4 @@ -package com.baeldung.designpatterns.decorator; +package com.baeldung.decorator; public abstract class TreeDecorator implements ChristmasTree { private ChristmasTree tree; diff --git a/patterns/facade/src/main/java/com/baeldung/pattern/facade/CarEngineFacade.java b/patterns/design-patterns/src/main/java/com/baeldung/facade/CarEngineFacade.java similarity index 92% rename from patterns/facade/src/main/java/com/baeldung/pattern/facade/CarEngineFacade.java rename to patterns/design-patterns/src/main/java/com/baeldung/facade/CarEngineFacade.java index 91f9b79738..27a1eb2729 100644 --- a/patterns/facade/src/main/java/com/baeldung/pattern/facade/CarEngineFacade.java +++ b/patterns/design-patterns/src/main/java/com/baeldung/facade/CarEngineFacade.java @@ -1,6 +1,6 @@ -package com.baeldung.pattern.facade; +package com.baeldung.facade; -import com.baeldung.pattern.facade.carsystem.*; +import com.baeldung.facade.carsystem.*; public class CarEngineFacade { private static final Integer DEFAULT_COOLING_TEMP = 90; diff --git a/patterns/facade/src/main/java/com/baeldung/pattern/facade/carsystem/AirFlowController.java b/patterns/design-patterns/src/main/java/com/baeldung/facade/carsystem/AirFlowController.java similarity index 90% rename from patterns/facade/src/main/java/com/baeldung/pattern/facade/carsystem/AirFlowController.java rename to patterns/design-patterns/src/main/java/com/baeldung/facade/carsystem/AirFlowController.java index 5ee846ea31..c9cf130e20 100644 --- a/patterns/facade/src/main/java/com/baeldung/pattern/facade/carsystem/AirFlowController.java +++ b/patterns/design-patterns/src/main/java/com/baeldung/facade/carsystem/AirFlowController.java @@ -1,4 +1,4 @@ -package com.baeldung.pattern.facade.carsystem; +package com.baeldung.facade.carsystem; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/patterns/facade/src/main/java/com/baeldung/pattern/facade/carsystem/AirFlowMeter.java b/patterns/design-patterns/src/main/java/com/baeldung/facade/carsystem/AirFlowMeter.java similarity index 68% rename from patterns/facade/src/main/java/com/baeldung/pattern/facade/carsystem/AirFlowMeter.java rename to patterns/design-patterns/src/main/java/com/baeldung/facade/carsystem/AirFlowMeter.java index b47f9cfc4a..4eb7ac3c44 100644 --- a/patterns/facade/src/main/java/com/baeldung/pattern/facade/carsystem/AirFlowMeter.java +++ b/patterns/design-patterns/src/main/java/com/baeldung/facade/carsystem/AirFlowMeter.java @@ -1,4 +1,4 @@ -package com.baeldung.pattern.facade.carsystem; +package com.baeldung.facade.carsystem; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -8,6 +8,6 @@ public class AirFlowMeter { private static final Logger LOGGER = LoggerFactory.getLogger(AirFlowMeter.class); public void getMeasurements() { - LOGGER.info("Getting air measurements..."); + LOGGER.info("Getting air measurements.."); } } diff --git a/patterns/facade/src/main/java/com/baeldung/pattern/facade/carsystem/CatalyticConverter.java b/patterns/design-patterns/src/main/java/com/baeldung/facade/carsystem/CatalyticConverter.java similarity index 88% rename from patterns/facade/src/main/java/com/baeldung/pattern/facade/carsystem/CatalyticConverter.java rename to patterns/design-patterns/src/main/java/com/baeldung/facade/carsystem/CatalyticConverter.java index 7d637cd444..0abc8c58ce 100644 --- a/patterns/facade/src/main/java/com/baeldung/pattern/facade/carsystem/CatalyticConverter.java +++ b/patterns/design-patterns/src/main/java/com/baeldung/facade/carsystem/CatalyticConverter.java @@ -1,4 +1,4 @@ -package com.baeldung.pattern.facade.carsystem; +package com.baeldung.facade.carsystem; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/patterns/facade/src/main/java/com/baeldung/pattern/facade/carsystem/CoolingController.java b/patterns/design-patterns/src/main/java/com/baeldung/facade/carsystem/CoolingController.java similarity index 91% rename from patterns/facade/src/main/java/com/baeldung/pattern/facade/carsystem/CoolingController.java rename to patterns/design-patterns/src/main/java/com/baeldung/facade/carsystem/CoolingController.java index ae556e685c..c13850d166 100644 --- a/patterns/facade/src/main/java/com/baeldung/pattern/facade/carsystem/CoolingController.java +++ b/patterns/design-patterns/src/main/java/com/baeldung/facade/carsystem/CoolingController.java @@ -1,4 +1,4 @@ -package com.baeldung.pattern.facade.carsystem; +package com.baeldung.facade.carsystem; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -28,7 +28,7 @@ public class CoolingController { } public void stop() { - LOGGER.info("Stopping Cooling Controller..."); + LOGGER.info("Stopping Cooling Controller.."); radiator.off(); } } diff --git a/patterns/facade/src/main/java/com/baeldung/pattern/facade/carsystem/FuelInjector.java b/patterns/design-patterns/src/main/java/com/baeldung/facade/carsystem/FuelInjector.java similarity index 82% rename from patterns/facade/src/main/java/com/baeldung/pattern/facade/carsystem/FuelInjector.java rename to patterns/design-patterns/src/main/java/com/baeldung/facade/carsystem/FuelInjector.java index c7905745e4..a619508e7a 100644 --- a/patterns/facade/src/main/java/com/baeldung/pattern/facade/carsystem/FuelInjector.java +++ b/patterns/design-patterns/src/main/java/com/baeldung/facade/carsystem/FuelInjector.java @@ -1,4 +1,4 @@ -package com.baeldung.pattern.facade.carsystem; +package com.baeldung.facade.carsystem; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -18,6 +18,6 @@ public class FuelInjector { } public void off() { - LOGGER.info("Stopping Fuel injector..."); + LOGGER.info("Stopping Fuel injector.."); } } diff --git a/patterns/facade/src/main/java/com/baeldung/pattern/facade/carsystem/FuelPump.java b/patterns/design-patterns/src/main/java/com/baeldung/facade/carsystem/FuelPump.java similarity index 66% rename from patterns/facade/src/main/java/com/baeldung/pattern/facade/carsystem/FuelPump.java rename to patterns/design-patterns/src/main/java/com/baeldung/facade/carsystem/FuelPump.java index 900358f8ff..0cd193558d 100644 --- a/patterns/facade/src/main/java/com/baeldung/pattern/facade/carsystem/FuelPump.java +++ b/patterns/design-patterns/src/main/java/com/baeldung/facade/carsystem/FuelPump.java @@ -1,4 +1,4 @@ -package com.baeldung.pattern.facade.carsystem; +package com.baeldung.facade.carsystem; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -8,6 +8,6 @@ public class FuelPump { private static final Logger LOGGER = LoggerFactory.getLogger(FuelPump.class); public void pump() { - LOGGER.info("Fuel Pump is pumping fuel..."); + LOGGER.info("Fuel Pump is pumping fuel.."); } } diff --git a/patterns/facade/src/main/java/com/baeldung/pattern/facade/carsystem/Radiator.java b/patterns/design-patterns/src/main/java/com/baeldung/facade/carsystem/Radiator.java similarity index 90% rename from patterns/facade/src/main/java/com/baeldung/pattern/facade/carsystem/Radiator.java rename to patterns/design-patterns/src/main/java/com/baeldung/facade/carsystem/Radiator.java index 6ca6cef9d9..c1004f561f 100644 --- a/patterns/facade/src/main/java/com/baeldung/pattern/facade/carsystem/Radiator.java +++ b/patterns/design-patterns/src/main/java/com/baeldung/facade/carsystem/Radiator.java @@ -1,4 +1,4 @@ -package com.baeldung.pattern.facade.carsystem; +package com.baeldung.facade.carsystem; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/patterns/facade/src/main/java/com/baeldung/pattern/facade/carsystem/Starter.java b/patterns/design-patterns/src/main/java/com/baeldung/facade/carsystem/Starter.java similarity index 70% rename from patterns/facade/src/main/java/com/baeldung/pattern/facade/carsystem/Starter.java rename to patterns/design-patterns/src/main/java/com/baeldung/facade/carsystem/Starter.java index b1f45a0be8..5f13d5726a 100644 --- a/patterns/facade/src/main/java/com/baeldung/pattern/facade/carsystem/Starter.java +++ b/patterns/design-patterns/src/main/java/com/baeldung/facade/carsystem/Starter.java @@ -1,4 +1,4 @@ -package com.baeldung.pattern.facade.carsystem; +package com.baeldung.facade.carsystem; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -8,6 +8,6 @@ public class Starter { private static final Logger LOGGER = LoggerFactory.getLogger(Starter.class); public void start() { - LOGGER.info("Starting..."); + LOGGER.info("Starting.."); } } diff --git a/patterns/facade/src/main/java/com/baeldung/pattern/facade/carsystem/TemperatureSensor.java b/patterns/design-patterns/src/main/java/com/baeldung/facade/carsystem/TemperatureSensor.java similarity index 67% rename from patterns/facade/src/main/java/com/baeldung/pattern/facade/carsystem/TemperatureSensor.java rename to patterns/design-patterns/src/main/java/com/baeldung/facade/carsystem/TemperatureSensor.java index d6a94858b4..5850a8a3be 100644 --- a/patterns/facade/src/main/java/com/baeldung/pattern/facade/carsystem/TemperatureSensor.java +++ b/patterns/design-patterns/src/main/java/com/baeldung/facade/carsystem/TemperatureSensor.java @@ -1,4 +1,4 @@ -package com.baeldung.pattern.facade.carsystem; +package com.baeldung.facade.carsystem; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -7,7 +7,7 @@ public class TemperatureSensor { private static final Logger LOGGER = LoggerFactory.getLogger(TemperatureSensor.class); public void getTemperature(){ - LOGGER.info("Getting temperature from the sensor..."); + LOGGER.info("Getting temperature from the sensor.."); } } diff --git a/core-java/src/main/java/com/baeldung/designpatterns/flyweight/Car.java b/patterns/design-patterns/src/main/java/com/baeldung/flyweight/Car.java similarity index 83% rename from core-java/src/main/java/com/baeldung/designpatterns/flyweight/Car.java rename to patterns/design-patterns/src/main/java/com/baeldung/flyweight/Car.java index 50f62cafaa..a0b1a7cdf5 100644 --- a/core-java/src/main/java/com/baeldung/designpatterns/flyweight/Car.java +++ b/patterns/design-patterns/src/main/java/com/baeldung/flyweight/Car.java @@ -1,4 +1,4 @@ -package com.baeldung.designpatterns.flyweight; +package com.baeldung.flyweight; import java.awt.Color; @@ -53,7 +53,7 @@ public class Car implements Vehicle { /* * (non-Javadoc) * - * @see com.baeldung.designpatterns.flyweight.Vehicle#start() + * @see com.baeldung.flyweight.Vehicle#start() */ @Override public void start() { @@ -64,7 +64,7 @@ public class Car implements Vehicle { /* * (non-Javadoc) * - * @see com.baeldung.designpatterns.flyweight.Vehicle#stop() + * @see com.baeldung.flyweight.Vehicle#stop() */ @Override public void stop() { @@ -75,7 +75,7 @@ public class Car implements Vehicle { /* * (non-Javadoc) * - * @see com.baeldung.designpatterns.flyweight.Vehicle#getColor() + * @see com.baeldung.flyweight.Vehicle#getColor() */ @Override public Color getColor() { diff --git a/core-java/src/main/java/com/baeldung/designpatterns/flyweight/Engine.java b/patterns/design-patterns/src/main/java/com/baeldung/flyweight/Engine.java similarity index 90% rename from core-java/src/main/java/com/baeldung/designpatterns/flyweight/Engine.java rename to patterns/design-patterns/src/main/java/com/baeldung/flyweight/Engine.java index 05d9ca98b8..2319f61a74 100644 --- a/core-java/src/main/java/com/baeldung/designpatterns/flyweight/Engine.java +++ b/patterns/design-patterns/src/main/java/com/baeldung/flyweight/Engine.java @@ -1,4 +1,4 @@ -package com.baeldung.designpatterns.flyweight; +package com.baeldung.flyweight; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/core-java/src/main/java/com/baeldung/designpatterns/flyweight/Vehicle.java b/patterns/design-patterns/src/main/java/com/baeldung/flyweight/Vehicle.java similarity index 88% rename from core-java/src/main/java/com/baeldung/designpatterns/flyweight/Vehicle.java rename to patterns/design-patterns/src/main/java/com/baeldung/flyweight/Vehicle.java index c285f9fcff..8cbb8e2896 100644 --- a/core-java/src/main/java/com/baeldung/designpatterns/flyweight/Vehicle.java +++ b/patterns/design-patterns/src/main/java/com/baeldung/flyweight/Vehicle.java @@ -1,4 +1,4 @@ -package com.baeldung.designpatterns.flyweight; +package com.baeldung.flyweight; import java.awt.Color; diff --git a/core-java/src/main/java/com/baeldung/designpatterns/flyweight/VehicleFactory.java b/patterns/design-patterns/src/main/java/com/baeldung/flyweight/VehicleFactory.java similarity index 96% rename from core-java/src/main/java/com/baeldung/designpatterns/flyweight/VehicleFactory.java rename to patterns/design-patterns/src/main/java/com/baeldung/flyweight/VehicleFactory.java index 2854b7dab1..ff0dbbdada 100644 --- a/core-java/src/main/java/com/baeldung/designpatterns/flyweight/VehicleFactory.java +++ b/patterns/design-patterns/src/main/java/com/baeldung/flyweight/VehicleFactory.java @@ -1,4 +1,4 @@ -package com.baeldung.designpatterns.flyweight; +package com.baeldung.flyweight; import java.awt.Color; import java.util.HashMap; diff --git a/core-java/src/main/java/com/baeldung/designpatterns/observer/Channel.java b/patterns/design-patterns/src/main/java/com/baeldung/observer/Channel.java similarity index 58% rename from core-java/src/main/java/com/baeldung/designpatterns/observer/Channel.java rename to patterns/design-patterns/src/main/java/com/baeldung/observer/Channel.java index 9ca2edac38..dcffe1a37d 100644 --- a/core-java/src/main/java/com/baeldung/designpatterns/observer/Channel.java +++ b/patterns/design-patterns/src/main/java/com/baeldung/observer/Channel.java @@ -1,4 +1,4 @@ -package com.baeldung.designpatterns.observer; +package com.baeldung.observer; public interface Channel { public void update(Object o); diff --git a/core-java/src/main/java/com/baeldung/designpatterns/observer/NewsAgency.java b/patterns/design-patterns/src/main/java/com/baeldung/observer/NewsAgency.java similarity index 91% rename from core-java/src/main/java/com/baeldung/designpatterns/observer/NewsAgency.java rename to patterns/design-patterns/src/main/java/com/baeldung/observer/NewsAgency.java index 0330fbdcdc..02e2872417 100644 --- a/core-java/src/main/java/com/baeldung/designpatterns/observer/NewsAgency.java +++ b/patterns/design-patterns/src/main/java/com/baeldung/observer/NewsAgency.java @@ -1,4 +1,4 @@ -package com.baeldung.designpatterns.observer; +package com.baeldung.observer; import java.util.ArrayList; import java.util.List; diff --git a/core-java/src/main/java/com/baeldung/designpatterns/observer/NewsChannel.java b/patterns/design-patterns/src/main/java/com/baeldung/observer/NewsChannel.java similarity index 86% rename from core-java/src/main/java/com/baeldung/designpatterns/observer/NewsChannel.java rename to patterns/design-patterns/src/main/java/com/baeldung/observer/NewsChannel.java index 09c22e0ad8..fd0178ca45 100644 --- a/core-java/src/main/java/com/baeldung/designpatterns/observer/NewsChannel.java +++ b/patterns/design-patterns/src/main/java/com/baeldung/observer/NewsChannel.java @@ -1,4 +1,4 @@ -package com.baeldung.designpatterns.observer; +package com.baeldung.observer; public class NewsChannel implements Channel { diff --git a/core-java/src/main/java/com/baeldung/designpatterns/observer/ONewsAgency.java b/patterns/design-patterns/src/main/java/com/baeldung/observer/ONewsAgency.java similarity index 83% rename from core-java/src/main/java/com/baeldung/designpatterns/observer/ONewsAgency.java rename to patterns/design-patterns/src/main/java/com/baeldung/observer/ONewsAgency.java index 2849820663..b567ad295a 100644 --- a/core-java/src/main/java/com/baeldung/designpatterns/observer/ONewsAgency.java +++ b/patterns/design-patterns/src/main/java/com/baeldung/observer/ONewsAgency.java @@ -1,4 +1,4 @@ -package com.baeldung.designpatterns.observer; +package com.baeldung.observer; import java.util.Observable; diff --git a/core-java/src/main/java/com/baeldung/designpatterns/observer/ONewsChannel.java b/patterns/design-patterns/src/main/java/com/baeldung/observer/ONewsChannel.java similarity index 89% rename from core-java/src/main/java/com/baeldung/designpatterns/observer/ONewsChannel.java rename to patterns/design-patterns/src/main/java/com/baeldung/observer/ONewsChannel.java index 3989fe0286..20cc1811bf 100644 --- a/core-java/src/main/java/com/baeldung/designpatterns/observer/ONewsChannel.java +++ b/patterns/design-patterns/src/main/java/com/baeldung/observer/ONewsChannel.java @@ -1,4 +1,4 @@ -package com.baeldung.designpatterns.observer; +package com.baeldung.observer; import java.util.Observable; import java.util.Observer; diff --git a/core-java/src/main/java/com/baeldung/designpatterns/observer/PCLNewsAgency.java b/patterns/design-patterns/src/main/java/com/baeldung/observer/PCLNewsAgency.java similarity index 93% rename from core-java/src/main/java/com/baeldung/designpatterns/observer/PCLNewsAgency.java rename to patterns/design-patterns/src/main/java/com/baeldung/observer/PCLNewsAgency.java index b05b97ab0b..df46731a85 100644 --- a/core-java/src/main/java/com/baeldung/designpatterns/observer/PCLNewsAgency.java +++ b/patterns/design-patterns/src/main/java/com/baeldung/observer/PCLNewsAgency.java @@ -1,4 +1,4 @@ -package com.baeldung.designpatterns.observer; +package com.baeldung.observer; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeSupport; diff --git a/core-java/src/main/java/com/baeldung/designpatterns/observer/PCLNewsChannel.java b/patterns/design-patterns/src/main/java/com/baeldung/observer/PCLNewsChannel.java similarity index 90% rename from core-java/src/main/java/com/baeldung/designpatterns/observer/PCLNewsChannel.java rename to patterns/design-patterns/src/main/java/com/baeldung/observer/PCLNewsChannel.java index ff8d35463c..d3e096f7e8 100644 --- a/core-java/src/main/java/com/baeldung/designpatterns/observer/PCLNewsChannel.java +++ b/patterns/design-patterns/src/main/java/com/baeldung/observer/PCLNewsChannel.java @@ -1,4 +1,4 @@ -package com.baeldung.designpatterns.observer; +package com.baeldung.observer; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; diff --git a/core-java/src/main/java/com/baeldung/designpatterns/proxy/ExpensiveObject.java b/patterns/design-patterns/src/main/java/com/baeldung/proxy/ExpensiveObject.java similarity index 57% rename from core-java/src/main/java/com/baeldung/designpatterns/proxy/ExpensiveObject.java rename to patterns/design-patterns/src/main/java/com/baeldung/proxy/ExpensiveObject.java index 256b31bc84..ae7820024c 100644 --- a/core-java/src/main/java/com/baeldung/designpatterns/proxy/ExpensiveObject.java +++ b/patterns/design-patterns/src/main/java/com/baeldung/proxy/ExpensiveObject.java @@ -1,4 +1,4 @@ -package com.baeldung.designpatterns.proxy; +package com.baeldung.proxy; public interface ExpensiveObject { void process(); diff --git a/core-java/src/main/java/com/baeldung/designpatterns/proxy/ExpensiveObjectImpl.java b/patterns/design-patterns/src/main/java/com/baeldung/proxy/ExpensiveObjectImpl.java similarity index 64% rename from core-java/src/main/java/com/baeldung/designpatterns/proxy/ExpensiveObjectImpl.java rename to patterns/design-patterns/src/main/java/com/baeldung/proxy/ExpensiveObjectImpl.java index de31e22b30..7ade31da88 100644 --- a/core-java/src/main/java/com/baeldung/designpatterns/proxy/ExpensiveObjectImpl.java +++ b/patterns/design-patterns/src/main/java/com/baeldung/proxy/ExpensiveObjectImpl.java @@ -1,6 +1,6 @@ -package com.baeldung.designpatterns.proxy; +package com.baeldung.proxy; -import static com.baeldung.designpatterns.util.LogerUtil.LOG;; +import static com.baeldung.util.LogerUtil.LOG;; public class ExpensiveObjectImpl implements ExpensiveObject { @@ -14,7 +14,7 @@ public class ExpensiveObjectImpl implements ExpensiveObject { } private void heavyInitialConfiguration() { - LOG.info("Loading initial configuration..."); + LOG.info("Loading initial configuration.."); } } \ No newline at end of file diff --git a/core-java/src/main/java/com/baeldung/designpatterns/proxy/ExpensiveObjectProxy.java b/patterns/design-patterns/src/main/java/com/baeldung/proxy/ExpensiveObjectProxy.java similarity index 86% rename from core-java/src/main/java/com/baeldung/designpatterns/proxy/ExpensiveObjectProxy.java rename to patterns/design-patterns/src/main/java/com/baeldung/proxy/ExpensiveObjectProxy.java index f36e688c90..f7985f331e 100644 --- a/core-java/src/main/java/com/baeldung/designpatterns/proxy/ExpensiveObjectProxy.java +++ b/patterns/design-patterns/src/main/java/com/baeldung/proxy/ExpensiveObjectProxy.java @@ -1,4 +1,4 @@ -package com.baeldung.designpatterns.proxy; +package com.baeldung.proxy; public class ExpensiveObjectProxy implements ExpensiveObject{ private static ExpensiveObject object; diff --git a/core-java/src/main/java/com/baeldung/designpatterns/proxy/ProxyPatternDriver.java b/patterns/design-patterns/src/main/java/com/baeldung/proxy/ProxyPatternDriver.java similarity index 82% rename from core-java/src/main/java/com/baeldung/designpatterns/proxy/ProxyPatternDriver.java rename to patterns/design-patterns/src/main/java/com/baeldung/proxy/ProxyPatternDriver.java index 088b069e28..02e4de96ea 100644 --- a/core-java/src/main/java/com/baeldung/designpatterns/proxy/ProxyPatternDriver.java +++ b/patterns/design-patterns/src/main/java/com/baeldung/proxy/ProxyPatternDriver.java @@ -1,4 +1,4 @@ -package com.baeldung.designpatterns.proxy; +package com.baeldung.proxy; public class ProxyPatternDriver { public static void main(String[] args) { diff --git a/core-java/src/main/java/com/baeldung/designpatterns/service/locator/Cache.java b/patterns/design-patterns/src/main/java/com/baeldung/service/locator/Cache.java similarity index 94% rename from core-java/src/main/java/com/baeldung/designpatterns/service/locator/Cache.java rename to patterns/design-patterns/src/main/java/com/baeldung/service/locator/Cache.java index 847d8a71e0..c215dda91f 100644 --- a/core-java/src/main/java/com/baeldung/designpatterns/service/locator/Cache.java +++ b/patterns/design-patterns/src/main/java/com/baeldung/service/locator/Cache.java @@ -1,4 +1,4 @@ -package com.baeldung.designpatterns.service.locator; +package com.baeldung.service.locator; import java.util.ArrayList; import java.util.List; diff --git a/core-java/src/main/java/com/baeldung/designpatterns/service/locator/EmailService.java b/patterns/design-patterns/src/main/java/com/baeldung/service/locator/EmailService.java similarity index 82% rename from core-java/src/main/java/com/baeldung/designpatterns/service/locator/EmailService.java rename to patterns/design-patterns/src/main/java/com/baeldung/service/locator/EmailService.java index 7ac7e05790..930312aecd 100644 --- a/core-java/src/main/java/com/baeldung/designpatterns/service/locator/EmailService.java +++ b/patterns/design-patterns/src/main/java/com/baeldung/service/locator/EmailService.java @@ -1,4 +1,4 @@ -package com.baeldung.designpatterns.service.locator; +package com.baeldung.service.locator; /** * Created by Gebruiker on 4/20/2018. diff --git a/core-java/src/main/java/com/baeldung/designpatterns/service/locator/InitialContext.java b/patterns/design-patterns/src/main/java/com/baeldung/service/locator/InitialContext.java similarity index 87% rename from core-java/src/main/java/com/baeldung/designpatterns/service/locator/InitialContext.java rename to patterns/design-patterns/src/main/java/com/baeldung/service/locator/InitialContext.java index d5234b39cd..3614b212f5 100644 --- a/core-java/src/main/java/com/baeldung/designpatterns/service/locator/InitialContext.java +++ b/patterns/design-patterns/src/main/java/com/baeldung/service/locator/InitialContext.java @@ -1,4 +1,4 @@ -package com.baeldung.designpatterns.service.locator; +package com.baeldung.service.locator; /** * Created by Gebruiker on 4/20/2018. diff --git a/core-java/src/main/java/com/baeldung/designpatterns/service/locator/Main.java b/patterns/design-patterns/src/main/java/com/baeldung/service/locator/Main.java similarity index 91% rename from core-java/src/main/java/com/baeldung/designpatterns/service/locator/Main.java rename to patterns/design-patterns/src/main/java/com/baeldung/service/locator/Main.java index 787f7e708c..984410a991 100644 --- a/core-java/src/main/java/com/baeldung/designpatterns/service/locator/Main.java +++ b/patterns/design-patterns/src/main/java/com/baeldung/service/locator/Main.java @@ -1,4 +1,4 @@ -package com.baeldung.designpatterns.service.locator; +package com.baeldung.service.locator; /** * Created by Gebruiker on 4/20/2018. diff --git a/core-java/src/main/java/com/baeldung/designpatterns/service/locator/MessagingService.java b/patterns/design-patterns/src/main/java/com/baeldung/service/locator/MessagingService.java similarity index 65% rename from core-java/src/main/java/com/baeldung/designpatterns/service/locator/MessagingService.java rename to patterns/design-patterns/src/main/java/com/baeldung/service/locator/MessagingService.java index 5853dfd7f7..0b48d9ea5e 100644 --- a/core-java/src/main/java/com/baeldung/designpatterns/service/locator/MessagingService.java +++ b/patterns/design-patterns/src/main/java/com/baeldung/service/locator/MessagingService.java @@ -1,4 +1,4 @@ -package com.baeldung.designpatterns.service.locator; +package com.baeldung.service.locator; public interface MessagingService { diff --git a/core-java/src/main/java/com/baeldung/designpatterns/service/locator/SMSService.java b/patterns/design-patterns/src/main/java/com/baeldung/service/locator/SMSService.java similarity index 82% rename from core-java/src/main/java/com/baeldung/designpatterns/service/locator/SMSService.java rename to patterns/design-patterns/src/main/java/com/baeldung/service/locator/SMSService.java index 87255ef658..d0bc13b847 100644 --- a/core-java/src/main/java/com/baeldung/designpatterns/service/locator/SMSService.java +++ b/patterns/design-patterns/src/main/java/com/baeldung/service/locator/SMSService.java @@ -1,4 +1,4 @@ -package com.baeldung.designpatterns.service.locator; +package com.baeldung.service.locator; /** * Created by Gebruiker on 4/20/2018. diff --git a/core-java/src/main/java/com/baeldung/designpatterns/service/locator/ServiceLocator.java b/patterns/design-patterns/src/main/java/com/baeldung/service/locator/ServiceLocator.java similarity index 91% rename from core-java/src/main/java/com/baeldung/designpatterns/service/locator/ServiceLocator.java rename to patterns/design-patterns/src/main/java/com/baeldung/service/locator/ServiceLocator.java index 7e1a2349a1..6da441d0aa 100644 --- a/core-java/src/main/java/com/baeldung/designpatterns/service/locator/ServiceLocator.java +++ b/patterns/design-patterns/src/main/java/com/baeldung/service/locator/ServiceLocator.java @@ -1,4 +1,4 @@ -package com.baeldung.designpatterns.service.locator; +package com.baeldung.service.locator; /** * Created by Gebruiker on 4/20/2018. diff --git a/core-java/src/main/java/com/baeldung/designpatterns/singleton/ClassSingleton.java b/patterns/design-patterns/src/main/java/com/baeldung/singleton/ClassSingleton.java similarity index 91% rename from core-java/src/main/java/com/baeldung/designpatterns/singleton/ClassSingleton.java rename to patterns/design-patterns/src/main/java/com/baeldung/singleton/ClassSingleton.java index 0fc86e30a7..d538e6dda3 100644 --- a/core-java/src/main/java/com/baeldung/designpatterns/singleton/ClassSingleton.java +++ b/patterns/design-patterns/src/main/java/com/baeldung/singleton/ClassSingleton.java @@ -1,4 +1,4 @@ -package com.baeldung.designpatterns.singleton; +package com.baeldung.singleton; public class ClassSingleton { diff --git a/core-java/src/main/java/com/baeldung/designpatterns/singleton/EnumSingleton.java b/patterns/design-patterns/src/main/java/com/baeldung/singleton/EnumSingleton.java similarity index 90% rename from core-java/src/main/java/com/baeldung/designpatterns/singleton/EnumSingleton.java rename to patterns/design-patterns/src/main/java/com/baeldung/singleton/EnumSingleton.java index f75484477b..89321a6b3f 100644 --- a/core-java/src/main/java/com/baeldung/designpatterns/singleton/EnumSingleton.java +++ b/patterns/design-patterns/src/main/java/com/baeldung/singleton/EnumSingleton.java @@ -1,4 +1,4 @@ -package com.baeldung.designpatterns.singleton; +package com.baeldung.singleton; public enum EnumSingleton { diff --git a/core-java/src/main/java/com/baeldung/designpatterns/singleton/Sandbox.java b/patterns/design-patterns/src/main/java/com/baeldung/singleton/Sandbox.java similarity index 96% rename from core-java/src/main/java/com/baeldung/designpatterns/singleton/Sandbox.java rename to patterns/design-patterns/src/main/java/com/baeldung/singleton/Sandbox.java index f8ca2ffa78..c7fb363336 100644 --- a/core-java/src/main/java/com/baeldung/designpatterns/singleton/Sandbox.java +++ b/patterns/design-patterns/src/main/java/com/baeldung/singleton/Sandbox.java @@ -1,4 +1,4 @@ -package com.baeldung.designpatterns.singleton; +package com.baeldung.singleton; public class Sandbox { diff --git a/core-java/src/main/java/com/baeldung/designpatterns/singleton/synchronization/DclSingleton.java b/patterns/design-patterns/src/main/java/com/baeldung/singleton/synchronization/DclSingleton.java similarity index 91% rename from core-java/src/main/java/com/baeldung/designpatterns/singleton/synchronization/DclSingleton.java rename to patterns/design-patterns/src/main/java/com/baeldung/singleton/synchronization/DclSingleton.java index e10f111a56..26cd9927b4 100644 --- a/core-java/src/main/java/com/baeldung/designpatterns/singleton/synchronization/DclSingleton.java +++ b/patterns/design-patterns/src/main/java/com/baeldung/singleton/synchronization/DclSingleton.java @@ -1,4 +1,4 @@ -package com.baeldung.designpatterns.singleton.synchronization; +package com.baeldung.singleton.synchronization; /** * Double-checked locking design pattern applied to a singleton. diff --git a/core-java/src/main/java/com/baeldung/designpatterns/singleton/synchronization/DraconianSingleton.java b/patterns/design-patterns/src/main/java/com/baeldung/singleton/synchronization/DraconianSingleton.java similarity index 90% rename from core-java/src/main/java/com/baeldung/designpatterns/singleton/synchronization/DraconianSingleton.java rename to patterns/design-patterns/src/main/java/com/baeldung/singleton/synchronization/DraconianSingleton.java index 1d01c49b13..9c51b4044b 100644 --- a/core-java/src/main/java/com/baeldung/designpatterns/singleton/synchronization/DraconianSingleton.java +++ b/patterns/design-patterns/src/main/java/com/baeldung/singleton/synchronization/DraconianSingleton.java @@ -1,4 +1,4 @@ -package com.baeldung.designpatterns.singleton.synchronization; +package com.baeldung.singleton.synchronization; /** * Draconian singleton. The method to get the instance is synchronized. diff --git a/core-java/src/main/java/com/baeldung/designpatterns/singleton/synchronization/EarlyInitSingleton.java b/patterns/design-patterns/src/main/java/com/baeldung/singleton/synchronization/EarlyInitSingleton.java similarity index 90% rename from core-java/src/main/java/com/baeldung/designpatterns/singleton/synchronization/EarlyInitSingleton.java rename to patterns/design-patterns/src/main/java/com/baeldung/singleton/synchronization/EarlyInitSingleton.java index 18c4b7cdce..22e1d3edab 100644 --- a/core-java/src/main/java/com/baeldung/designpatterns/singleton/synchronization/EarlyInitSingleton.java +++ b/patterns/design-patterns/src/main/java/com/baeldung/singleton/synchronization/EarlyInitSingleton.java @@ -1,4 +1,4 @@ -package com.baeldung.designpatterns.singleton.synchronization; +package com.baeldung.singleton.synchronization; /** * Singleton with early initialization. Inlines the singleton instance diff --git a/core-java/src/main/java/com/baeldung/designpatterns/singleton/synchronization/EnumSingleton.java b/patterns/design-patterns/src/main/java/com/baeldung/singleton/synchronization/EnumSingleton.java similarity index 77% rename from core-java/src/main/java/com/baeldung/designpatterns/singleton/synchronization/EnumSingleton.java rename to patterns/design-patterns/src/main/java/com/baeldung/singleton/synchronization/EnumSingleton.java index b7ff7f50b1..afa6911910 100644 --- a/core-java/src/main/java/com/baeldung/designpatterns/singleton/synchronization/EnumSingleton.java +++ b/patterns/design-patterns/src/main/java/com/baeldung/singleton/synchronization/EnumSingleton.java @@ -1,4 +1,4 @@ -package com.baeldung.designpatterns.singleton.synchronization; +package com.baeldung.singleton.synchronization; /** * Enum singleton pattern. Uses an enum to hold a reference to the singleton diff --git a/core-java/src/main/java/com/baeldung/designpatterns/singleton/synchronization/InitOnDemandSingleton.java b/patterns/design-patterns/src/main/java/com/baeldung/singleton/synchronization/InitOnDemandSingleton.java similarity index 92% rename from core-java/src/main/java/com/baeldung/designpatterns/singleton/synchronization/InitOnDemandSingleton.java rename to patterns/design-patterns/src/main/java/com/baeldung/singleton/synchronization/InitOnDemandSingleton.java index d76bada786..46feab6208 100644 --- a/core-java/src/main/java/com/baeldung/designpatterns/singleton/synchronization/InitOnDemandSingleton.java +++ b/patterns/design-patterns/src/main/java/com/baeldung/singleton/synchronization/InitOnDemandSingleton.java @@ -1,4 +1,4 @@ -package com.baeldung.designpatterns.singleton.synchronization; +package com.baeldung.singleton.synchronization; /** * Initialization on demand singleton pattern. Uses a nested static class to diff --git a/patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/templatemethod/application/Application.java b/patterns/design-patterns/src/main/java/com/baeldung/templatemethod/application/Application.java similarity index 100% rename from patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/templatemethod/application/Application.java rename to patterns/design-patterns/src/main/java/com/baeldung/templatemethod/application/Application.java diff --git a/patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/templatemethod/model/Computer.java b/patterns/design-patterns/src/main/java/com/baeldung/templatemethod/model/Computer.java similarity index 100% rename from patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/templatemethod/model/Computer.java rename to patterns/design-patterns/src/main/java/com/baeldung/templatemethod/model/Computer.java diff --git a/patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/templatemethod/model/ComputerBuilder.java b/patterns/design-patterns/src/main/java/com/baeldung/templatemethod/model/ComputerBuilder.java similarity index 100% rename from patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/templatemethod/model/ComputerBuilder.java rename to patterns/design-patterns/src/main/java/com/baeldung/templatemethod/model/ComputerBuilder.java diff --git a/patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/templatemethod/model/HighEndComputer.java b/patterns/design-patterns/src/main/java/com/baeldung/templatemethod/model/HighEndComputer.java similarity index 100% rename from patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/templatemethod/model/HighEndComputer.java rename to patterns/design-patterns/src/main/java/com/baeldung/templatemethod/model/HighEndComputer.java diff --git a/patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/templatemethod/model/HighEndComputerBuilder.java b/patterns/design-patterns/src/main/java/com/baeldung/templatemethod/model/HighEndComputerBuilder.java similarity index 100% rename from patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/templatemethod/model/HighEndComputerBuilder.java rename to patterns/design-patterns/src/main/java/com/baeldung/templatemethod/model/HighEndComputerBuilder.java diff --git a/patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/templatemethod/model/StandardComputer.java b/patterns/design-patterns/src/main/java/com/baeldung/templatemethod/model/StandardComputer.java similarity index 100% rename from patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/templatemethod/model/StandardComputer.java rename to patterns/design-patterns/src/main/java/com/baeldung/templatemethod/model/StandardComputer.java diff --git a/patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/templatemethod/model/StandardComputerBuilder.java b/patterns/design-patterns/src/main/java/com/baeldung/templatemethod/model/StandardComputerBuilder.java similarity index 100% rename from patterns/behavioral-patterns/src/main/java/com/baeldung/pattern/templatemethod/model/StandardComputerBuilder.java rename to patterns/design-patterns/src/main/java/com/baeldung/templatemethod/model/StandardComputerBuilder.java diff --git a/core-java/src/main/java/com/baeldung/designpatterns/util/LogerUtil.java b/patterns/design-patterns/src/main/java/com/baeldung/util/LogerUtil.java similarity index 94% rename from core-java/src/main/java/com/baeldung/designpatterns/util/LogerUtil.java rename to patterns/design-patterns/src/main/java/com/baeldung/util/LogerUtil.java index f7b6e4f3e9..7217a4bc40 100644 --- a/core-java/src/main/java/com/baeldung/designpatterns/util/LogerUtil.java +++ b/patterns/design-patterns/src/main/java/com/baeldung/util/LogerUtil.java @@ -1,4 +1,4 @@ -package com.baeldung.designpatterns.util; +package com.baeldung.util; import java.io.BufferedReader; import java.io.IOException; diff --git a/core-java/src/test/java/com/baeldung/designpatterns/AdapterPatternIntegrationTest.java b/patterns/design-patterns/src/test/java/com/baeldung/AdapterPatternIntegrationTest.java similarity index 68% rename from core-java/src/test/java/com/baeldung/designpatterns/AdapterPatternIntegrationTest.java rename to patterns/design-patterns/src/test/java/com/baeldung/AdapterPatternIntegrationTest.java index 8cad1290d9..78a1492d83 100644 --- a/core-java/src/test/java/com/baeldung/designpatterns/AdapterPatternIntegrationTest.java +++ b/patterns/design-patterns/src/test/java/com/baeldung/AdapterPatternIntegrationTest.java @@ -1,15 +1,15 @@ -package com.baeldung.designpatterns; +package com.baeldung; import static org.junit.Assert.assertEquals; import org.junit.Test; -import com.baeldung.designpatterns.adapter.AstonMartin; -import com.baeldung.designpatterns.adapter.BugattiVeyron; -import com.baeldung.designpatterns.adapter.McLaren; -import com.baeldung.designpatterns.adapter.Movable; -import com.baeldung.designpatterns.adapter.MovableAdapter; -import com.baeldung.designpatterns.adapter.MovableAdapterImpl; +import com.baeldung.adapter.AstonMartin; +import com.baeldung.adapter.BugattiVeyron; +import com.baeldung.adapter.McLaren; +import com.baeldung.adapter.Movable; +import com.baeldung.adapter.MovableAdapter; +import com.baeldung.adapter.MovableAdapterImpl; public class AdapterPatternIntegrationTest { @Test diff --git a/core-java/src/test/java/com/baeldung/designpatterns/BridgePatternIntegrationTest.java b/patterns/design-patterns/src/test/java/com/baeldung/BridgePatternIntegrationTest.java similarity index 64% rename from core-java/src/test/java/com/baeldung/designpatterns/BridgePatternIntegrationTest.java rename to patterns/design-patterns/src/test/java/com/baeldung/BridgePatternIntegrationTest.java index ed7eb0c453..adcb5cdd2c 100644 --- a/core-java/src/test/java/com/baeldung/designpatterns/BridgePatternIntegrationTest.java +++ b/patterns/design-patterns/src/test/java/com/baeldung/BridgePatternIntegrationTest.java @@ -1,14 +1,14 @@ -package com.baeldung.designpatterns; +package com.baeldung; import static org.junit.Assert.*; import org.junit.Test; -import com.baeldung.designpatterns.bridge.Blue; -import com.baeldung.designpatterns.bridge.Red; -import com.baeldung.designpatterns.bridge.Shape; -import com.baeldung.designpatterns.bridge.Square; -import com.baeldung.designpatterns.bridge.Triangle; +import com.baeldung.bridge.Blue; +import com.baeldung.bridge.Red; +import com.baeldung.bridge.Shape; +import com.baeldung.bridge.Square; +import com.baeldung.bridge.Triangle; public class BridgePatternIntegrationTest { diff --git a/core-java/src/test/java/com/baeldung/designpatterns/DecoratorPatternIntegrationTest.java b/patterns/design-patterns/src/test/java/com/baeldung/DecoratorPatternIntegrationTest.java similarity index 69% rename from core-java/src/test/java/com/baeldung/designpatterns/DecoratorPatternIntegrationTest.java rename to patterns/design-patterns/src/test/java/com/baeldung/DecoratorPatternIntegrationTest.java index de0ca8a135..23a717ae2e 100644 --- a/core-java/src/test/java/com/baeldung/designpatterns/DecoratorPatternIntegrationTest.java +++ b/patterns/design-patterns/src/test/java/com/baeldung/DecoratorPatternIntegrationTest.java @@ -1,13 +1,13 @@ -package com.baeldung.designpatterns; +package com.baeldung; import static org.junit.Assert.assertEquals; import org.junit.Test; -import com.baeldung.designpatterns.decorator.BubbleLights; -import com.baeldung.designpatterns.decorator.ChristmasTree; -import com.baeldung.designpatterns.decorator.ChristmasTreeImpl; -import com.baeldung.designpatterns.decorator.Garland; +import com.baeldung.decorator.BubbleLights; +import com.baeldung.decorator.ChristmasTree; +import com.baeldung.decorator.ChristmasTreeImpl; +import com.baeldung.decorator.Garland; public class DecoratorPatternIntegrationTest { @Test diff --git a/core-java/src/test/java/com/baeldung/designpatterns/ProxyPatternIntegrationTest.java b/patterns/design-patterns/src/test/java/com/baeldung/ProxyPatternIntegrationTest.java similarity index 80% rename from core-java/src/test/java/com/baeldung/designpatterns/ProxyPatternIntegrationTest.java rename to patterns/design-patterns/src/test/java/com/baeldung/ProxyPatternIntegrationTest.java index 7fa95b31d7..c035793b64 100644 --- a/core-java/src/test/java/com/baeldung/designpatterns/ProxyPatternIntegrationTest.java +++ b/patterns/design-patterns/src/test/java/com/baeldung/ProxyPatternIntegrationTest.java @@ -1,6 +1,6 @@ -package com.baeldung.designpatterns; +package com.baeldung; -import static com.baeldung.designpatterns.util.LogerUtil.LOG; +import static com.baeldung.util.LogerUtil.LOG; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; @@ -11,8 +11,8 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; -import com.baeldung.designpatterns.proxy.ExpensiveObject; -import com.baeldung.designpatterns.proxy.ExpensiveObjectProxy; +import com.baeldung.proxy.ExpensiveObject; +import com.baeldung.proxy.ExpensiveObjectProxy; public class ProxyPatternIntegrationTest { public static TestAppenderDP appender; @@ -31,7 +31,7 @@ public class ProxyPatternIntegrationTest { final List log = appender.getLog(); - assertThat((String) log.get(0).getMessage(), is("Loading initial configuration...")); + assertThat((String) log.get(0).getMessage(), is("Loading initial configuration..")); assertThat((String) log.get(1).getMessage(), is("processing complete.")); assertThat((String) log.get(2).getMessage(), is("processing complete.")); } diff --git a/core-java/src/test/java/com/baeldung/designpatterns/TestAppenderDP.java b/patterns/design-patterns/src/test/java/com/baeldung/TestAppenderDP.java similarity index 94% rename from core-java/src/test/java/com/baeldung/designpatterns/TestAppenderDP.java rename to patterns/design-patterns/src/test/java/com/baeldung/TestAppenderDP.java index 613c26fa13..2b3bc47292 100644 --- a/core-java/src/test/java/com/baeldung/designpatterns/TestAppenderDP.java +++ b/patterns/design-patterns/src/test/java/com/baeldung/TestAppenderDP.java @@ -1,4 +1,4 @@ -package com.baeldung.designpatterns; +package com.baeldung; import java.util.ArrayList; import java.util.List; diff --git a/patterns/behavioral-patterns/src/test/java/com/baeldung/pattern/chainofresponsibility/ChainOfResponsibilityTest.java b/patterns/design-patterns/src/test/java/com/baeldung/chainofresponsibility/ChainOfResponsibilityTest.java similarity index 100% rename from patterns/behavioral-patterns/src/test/java/com/baeldung/pattern/chainofresponsibility/ChainOfResponsibilityTest.java rename to patterns/design-patterns/src/test/java/com/baeldung/chainofresponsibility/ChainOfResponsibilityTest.java diff --git a/patterns/behavioral-patterns/src/test/java/com/baeldung/pattern/command/test/OpenTextFileOperationUnitTest.java b/patterns/design-patterns/src/test/java/com/baeldung/command/test/OpenTextFileOperationUnitTest.java similarity index 100% rename from patterns/behavioral-patterns/src/test/java/com/baeldung/pattern/command/test/OpenTextFileOperationUnitTest.java rename to patterns/design-patterns/src/test/java/com/baeldung/command/test/OpenTextFileOperationUnitTest.java diff --git a/patterns/behavioral-patterns/src/test/java/com/baeldung/pattern/command/test/SaveTextFileOperationUnitTest.java b/patterns/design-patterns/src/test/java/com/baeldung/command/test/SaveTextFileOperationUnitTest.java similarity index 100% rename from patterns/behavioral-patterns/src/test/java/com/baeldung/pattern/command/test/SaveTextFileOperationUnitTest.java rename to patterns/design-patterns/src/test/java/com/baeldung/command/test/SaveTextFileOperationUnitTest.java diff --git a/patterns/behavioral-patterns/src/test/java/com/baeldung/pattern/command/test/TextFileOperationExecutorUnitTest.java b/patterns/design-patterns/src/test/java/com/baeldung/command/test/TextFileOperationExecutorUnitTest.java similarity index 100% rename from patterns/behavioral-patterns/src/test/java/com/baeldung/pattern/command/test/TextFileOperationExecutorUnitTest.java rename to patterns/design-patterns/src/test/java/com/baeldung/command/test/TextFileOperationExecutorUnitTest.java diff --git a/patterns/behavioral-patterns/src/test/java/com/baeldung/pattern/command/test/TextFileUnitTest.java b/patterns/design-patterns/src/test/java/com/baeldung/command/test/TextFileUnitTest.java similarity index 100% rename from patterns/behavioral-patterns/src/test/java/com/baeldung/pattern/command/test/TextFileUnitTest.java rename to patterns/design-patterns/src/test/java/com/baeldung/command/test/TextFileUnitTest.java diff --git a/core-java/src/test/java/com/baeldung/designpatterns/creational/abstractfactory/AbstractPatternIntegrationTest.java b/patterns/design-patterns/src/test/java/com/baeldung/creational/abstractfactory/AbstractPatternIntegrationTest.java similarity index 91% rename from core-java/src/test/java/com/baeldung/designpatterns/creational/abstractfactory/AbstractPatternIntegrationTest.java rename to patterns/design-patterns/src/test/java/com/baeldung/creational/abstractfactory/AbstractPatternIntegrationTest.java index dc02b976a0..6d1a4ad8fd 100644 --- a/core-java/src/test/java/com/baeldung/designpatterns/creational/abstractfactory/AbstractPatternIntegrationTest.java +++ b/patterns/design-patterns/src/test/java/com/baeldung/creational/abstractfactory/AbstractPatternIntegrationTest.java @@ -1,4 +1,4 @@ -package com.baeldung.designpatterns.creational.abstractfactory; +package com.baeldung.creational.abstractfactory; import static org.junit.Assert.*; diff --git a/core-java/src/test/java/com/baeldung/designpatterns/creational/builder/BuilderPatternIntegrationTest.java b/patterns/design-patterns/src/test/java/com/baeldung/creational/builder/BuilderPatternIntegrationTest.java similarity index 95% rename from core-java/src/test/java/com/baeldung/designpatterns/creational/builder/BuilderPatternIntegrationTest.java rename to patterns/design-patterns/src/test/java/com/baeldung/creational/builder/BuilderPatternIntegrationTest.java index 898330b26e..03b0b3db90 100644 --- a/core-java/src/test/java/com/baeldung/designpatterns/creational/builder/BuilderPatternIntegrationTest.java +++ b/patterns/design-patterns/src/test/java/com/baeldung/creational/builder/BuilderPatternIntegrationTest.java @@ -1,4 +1,4 @@ -package com.baeldung.designpatterns.creational.builder; +package com.baeldung.creational.builder; import static org.junit.Assert.assertEquals; diff --git a/core-java/src/test/java/com/baeldung/designpatterns/creational/factory/FactoryIntegrationTest.java b/patterns/design-patterns/src/test/java/com/baeldung/creational/factory/FactoryIntegrationTest.java similarity index 94% rename from core-java/src/test/java/com/baeldung/designpatterns/creational/factory/FactoryIntegrationTest.java rename to patterns/design-patterns/src/test/java/com/baeldung/creational/factory/FactoryIntegrationTest.java index ed0419c16d..61cf83c1e7 100644 --- a/core-java/src/test/java/com/baeldung/designpatterns/creational/factory/FactoryIntegrationTest.java +++ b/patterns/design-patterns/src/test/java/com/baeldung/creational/factory/FactoryIntegrationTest.java @@ -1,4 +1,4 @@ -package com.baeldung.designpatterns.creational.factory; +package com.baeldung.creational.factory; import static org.junit.Assert.*; diff --git a/core-java/src/test/java/com/baeldung/designpatterns/creational/singleton/SingletonIntegrationTest.java b/patterns/design-patterns/src/test/java/com/baeldung/creational/singleton/SingletonIntegrationTest.java similarity index 92% rename from core-java/src/test/java/com/baeldung/designpatterns/creational/singleton/SingletonIntegrationTest.java rename to patterns/design-patterns/src/test/java/com/baeldung/creational/singleton/SingletonIntegrationTest.java index a3d5b7a14d..7c3d134ae6 100644 --- a/core-java/src/test/java/com/baeldung/designpatterns/creational/singleton/SingletonIntegrationTest.java +++ b/patterns/design-patterns/src/test/java/com/baeldung/creational/singleton/SingletonIntegrationTest.java @@ -1,4 +1,4 @@ -package com.baeldung.designpatterns.creational.singleton; +package com.baeldung.creational.singleton; import org.junit.Test; import static org.junit.Assert.*; diff --git a/patterns/facade/src/test/java/com/baeldung/pattern/facade/CarEngineFacadeTest.java b/patterns/design-patterns/src/test/java/com/baeldung/facade/CarEngineFacadeTest.java similarity index 94% rename from patterns/facade/src/test/java/com/baeldung/pattern/facade/CarEngineFacadeTest.java rename to patterns/design-patterns/src/test/java/com/baeldung/facade/CarEngineFacadeTest.java index 79c159319d..88c5d3c9bc 100644 --- a/patterns/facade/src/test/java/com/baeldung/pattern/facade/CarEngineFacadeTest.java +++ b/patterns/design-patterns/src/test/java/com/baeldung/facade/CarEngineFacadeTest.java @@ -1,4 +1,4 @@ -package com.baeldung.pattern.facade; +package com.baeldung.facade; import ch.qos.logback.classic.Logger; import ch.qos.logback.classic.spi.ILoggingEvent; @@ -35,12 +35,12 @@ public class CarEngineFacadeTest { CarEngineFacade carEngineFacade = new CarEngineFacade(); carEngineFacade.startEngine(); assertTrue(appender.logContains("Fuel injector ready to inject fuel.")); - assertTrue(appender.logContains("Getting air measurements...")); + assertTrue(appender.logContains("Getting air measurements..")); assertTrue(appender.logContains("Air provided!")); assertTrue(appender.logContains("Fuel injector ready to inject fuel.")); - assertTrue(appender.logContains("Fuel Pump is pumping fuel...")); + assertTrue(appender.logContains("Fuel Pump is pumping fuel..")); assertTrue(appender.logContains("Fuel injected.")); - assertTrue(appender.logContains("Starting...")); + assertTrue(appender.logContains("Starting..")); assertTrue(appender.logContains("Setting temperature upper limit to 90")); assertTrue(appender.logContains("Cooling Controller ready!")); assertTrue(appender.logContains("Setting radiator speed to 10")); @@ -52,12 +52,12 @@ public class CarEngineFacadeTest { public void whenStopEngine_thenAllNecessaryActionsPerformed() { CarEngineFacade carEngineFacade = new CarEngineFacade(); carEngineFacade.stopEngine(); - assertTrue(appender.logContains("Stopping Fuel injector...")); + assertTrue(appender.logContains("Stopping Fuel injector..")); assertTrue(appender.logContains("Catalytic Converter switched off!")); assertTrue(appender.logContains("Scheduled cooling with maximum allowed temperature 50")); - assertTrue(appender.logContains("Getting temperature from the sensor...")); + assertTrue(appender.logContains("Getting temperature from the sensor..")); assertTrue(appender.logContains("Radiator switched on!")); - assertTrue(appender.logContains("Stopping Cooling Controller...")); + assertTrue(appender.logContains("Stopping Cooling Controller..")); assertTrue(appender.logContains("Radiator switched off!")); assertTrue(appender.logContains("Air controller switched off.")); } diff --git a/core-java/src/test/java/com/baeldung/designpatterns/flyweight/FlyweightUnitTest.java b/patterns/design-patterns/src/test/java/com/baeldung/flyweight/FlyweightUnitTest.java similarity index 96% rename from core-java/src/test/java/com/baeldung/designpatterns/flyweight/FlyweightUnitTest.java rename to patterns/design-patterns/src/test/java/com/baeldung/flyweight/FlyweightUnitTest.java index 645e2fd459..ab8ed32b4e 100644 --- a/core-java/src/test/java/com/baeldung/designpatterns/flyweight/FlyweightUnitTest.java +++ b/patterns/design-patterns/src/test/java/com/baeldung/flyweight/FlyweightUnitTest.java @@ -1,4 +1,4 @@ -package com.baeldung.designpatterns.flyweight; +package com.baeldung.flyweight; import java.awt.Color; diff --git a/core-java/src/test/java/com/baeldung/designpatterns/observer/ObserverIntegrationTest.java b/patterns/design-patterns/src/test/java/com/baeldung/observer/ObserverIntegrationTest.java similarity index 87% rename from core-java/src/test/java/com/baeldung/designpatterns/observer/ObserverIntegrationTest.java rename to patterns/design-patterns/src/test/java/com/baeldung/observer/ObserverIntegrationTest.java index a8a0e29990..5590ecd717 100644 --- a/core-java/src/test/java/com/baeldung/designpatterns/observer/ObserverIntegrationTest.java +++ b/patterns/design-patterns/src/test/java/com/baeldung/observer/ObserverIntegrationTest.java @@ -1,11 +1,11 @@ -package com.baeldung.designpatterns.observer; +package com.baeldung.observer; import static org.junit.Assert.assertEquals; import org.junit.Test; -import com.baeldung.designpatterns.observer.NewsAgency; -import com.baeldung.designpatterns.observer.NewsChannel; +import com.baeldung.observer.NewsAgency; +import com.baeldung.observer.NewsChannel; public class ObserverIntegrationTest { diff --git a/core-java/src/test/java/com/baeldung/designpatterns/singleton/synchronization/SingletonSynchronizationUnitTest.java b/patterns/design-patterns/src/test/java/com/baeldung/singleton/synchronization/SingletonSynchronizationUnitTest.java similarity index 98% rename from core-java/src/test/java/com/baeldung/designpatterns/singleton/synchronization/SingletonSynchronizationUnitTest.java rename to patterns/design-patterns/src/test/java/com/baeldung/singleton/synchronization/SingletonSynchronizationUnitTest.java index 2c1a3fe093..08a70f6056 100644 --- a/core-java/src/test/java/com/baeldung/designpatterns/singleton/synchronization/SingletonSynchronizationUnitTest.java +++ b/patterns/design-patterns/src/test/java/com/baeldung/singleton/synchronization/SingletonSynchronizationUnitTest.java @@ -1,4 +1,4 @@ -package com.baeldung.designpatterns.singleton.synchronization; +package com.baeldung.singleton.synchronization; import java.util.Collections; import java.util.HashSet; diff --git a/patterns/behavioral-patterns/src/test/java/com/baeldung/pattern/templatemethod/test/TemplateMethodPatternTest.java b/patterns/design-patterns/src/test/java/com/baeldung/templatemethod/test/TemplateMethodPatternTest.java similarity index 100% rename from patterns/behavioral-patterns/src/test/java/com/baeldung/pattern/templatemethod/test/TemplateMethodPatternTest.java rename to patterns/design-patterns/src/test/java/com/baeldung/templatemethod/test/TemplateMethodPatternTest.java diff --git a/patterns/facade/pom.xml b/patterns/facade/pom.xml deleted file mode 100644 index 573e557eb6..0000000000 --- a/patterns/facade/pom.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - 4.0.0 - com.baeldung.pattern.facade - pattern.facade - 1.0 - jar - - com.baeldung.patterns - patterns-parent - 1.0.0-SNAPSHOT - .. - - - - - junit - junit - 4.12 - test - - - - UTF-8 - 1.8 - 1.8 - - \ No newline at end of file diff --git a/patterns/front-controller/pom.xml b/patterns/front-controller/pom.xml index 877277a062..a12d606165 100644 --- a/patterns/front-controller/pom.xml +++ b/patterns/front-controller/pom.xml @@ -7,7 +7,7 @@ patterns-parent - com.baeldung.patterns + com.baeldung 1.0.0-SNAPSHOT .. diff --git a/patterns/intercepting-filter/pom.xml b/patterns/intercepting-filter/pom.xml index b9916d9157..8c68302315 100644 --- a/patterns/intercepting-filter/pom.xml +++ b/patterns/intercepting-filter/pom.xml @@ -7,7 +7,7 @@ war - com.baeldung.patterns + com.baeldung patterns-parent 1.0.0-SNAPSHOT .. diff --git a/patterns/pom.xml b/patterns/pom.xml index 7ee2c749be..a811664b86 100644 --- a/patterns/pom.xml +++ b/patterns/pom.xml @@ -2,7 +2,7 @@ 4.0.0 - com.baeldung.patterns + com.baeldung patterns-parent pom @@ -16,7 +16,7 @@ front-controller intercepting-filter - behavioral-patterns + design-patterns From b677208899684e9326b23a8eab940dbb4ebb04b8 Mon Sep 17 00:00:00 2001 From: Graham Cox Date: Fri, 11 May 2018 13:35:04 +0100 Subject: [PATCH 64/66] Examples for Spek article (#4106) * Examples for BAEL-1169 * Examples for Spek --- core-kotlin/pom.xml | 18 ++++++ .../kotlin/spek/CalculatorSubjectTest5.kt | 19 ++++++ .../baeldung/kotlin/spek/CalculatorTest5.kt | 32 ++++++++++ .../baeldung/kotlin/spek/DataDrivenTest5.kt | 21 +++++++ .../com/baeldung/kotlin/spek/GroupTest5.kt | 62 +++++++++++++++++++ 5 files changed, 152 insertions(+) create mode 100644 core-kotlin/src/test/kotlin/com/baeldung/kotlin/spek/CalculatorSubjectTest5.kt create mode 100644 core-kotlin/src/test/kotlin/com/baeldung/kotlin/spek/CalculatorTest5.kt create mode 100644 core-kotlin/src/test/kotlin/com/baeldung/kotlin/spek/DataDrivenTest5.kt create mode 100644 core-kotlin/src/test/kotlin/com/baeldung/kotlin/spek/GroupTest5.kt diff --git a/core-kotlin/pom.xml b/core-kotlin/pom.xml index 00c3ac188d..24bfb302cf 100644 --- a/core-kotlin/pom.xml +++ b/core-kotlin/pom.xml @@ -63,6 +63,24 @@ kotlinx-coroutines-core ${kotlinx.version} + + org.jetbrains.spek + spek-api + 1.1.5 + test + + + org.jetbrains.spek + spek-subject-extension + 1.1.5 + test + + + org.jetbrains.spek + spek-junit-platform-engine + 1.1.5 + test + com.nhaarman mockito-kotlin diff --git a/core-kotlin/src/test/kotlin/com/baeldung/kotlin/spek/CalculatorSubjectTest5.kt b/core-kotlin/src/test/kotlin/com/baeldung/kotlin/spek/CalculatorSubjectTest5.kt new file mode 100644 index 0000000000..f595d65bf2 --- /dev/null +++ b/core-kotlin/src/test/kotlin/com/baeldung/kotlin/spek/CalculatorSubjectTest5.kt @@ -0,0 +1,19 @@ +package com.baeldung.kotlin.spek + +import com.baeldung.kotlin.junit5.Calculator +import org.jetbrains.spek.api.dsl.describe +import org.jetbrains.spek.api.dsl.it +import org.jetbrains.spek.subject.SubjectSpek +import org.junit.jupiter.api.Assertions.assertEquals + +class CalculatorSubjectTest5 : SubjectSpek({ + subject { Calculator() } + describe("A calculator") { + describe("Addition") { + val result = subject.add(3, 5) + it("Produces the correct answer") { + assertEquals(8, result) + } + } + } +}) diff --git a/core-kotlin/src/test/kotlin/com/baeldung/kotlin/spek/CalculatorTest5.kt b/core-kotlin/src/test/kotlin/com/baeldung/kotlin/spek/CalculatorTest5.kt new file mode 100644 index 0000000000..3c49d916e4 --- /dev/null +++ b/core-kotlin/src/test/kotlin/com/baeldung/kotlin/spek/CalculatorTest5.kt @@ -0,0 +1,32 @@ +package com.baeldung.kotlin.spek + +import com.baeldung.kotlin.junit5.Calculator +import org.jetbrains.spek.api.Spek +import org.jetbrains.spek.api.dsl.describe +import org.jetbrains.spek.api.dsl.given +import org.jetbrains.spek.api.dsl.it +import org.jetbrains.spek.api.dsl.on +import org.junit.jupiter.api.Assertions.assertEquals + +class CalculatorTest5 : Spek({ + given("A calculator") { + val calculator = Calculator() + on("Adding 3 and 5") { + val result = calculator.add(3, 5) + it("Produces 8") { + assertEquals(8, result) + } + } + } + + describe("A calculator") { + val calculator = Calculator() + describe("Addition") { + val result = calculator.add(3, 5) + it("Produces the correct answer") { + assertEquals(8, result) + } + } + } + +}) diff --git a/core-kotlin/src/test/kotlin/com/baeldung/kotlin/spek/DataDrivenTest5.kt b/core-kotlin/src/test/kotlin/com/baeldung/kotlin/spek/DataDrivenTest5.kt new file mode 100644 index 0000000000..bbcb36e8bb --- /dev/null +++ b/core-kotlin/src/test/kotlin/com/baeldung/kotlin/spek/DataDrivenTest5.kt @@ -0,0 +1,21 @@ +package com.baeldung.kotlin.spek + +import org.jetbrains.spek.api.Spek +import org.jetbrains.spek.api.dsl.describe +import org.jetbrains.spek.api.dsl.it +import org.junit.jupiter.api.Assertions + +class DataDrivenTest5 : Spek({ + describe("A data driven test") { + mapOf( + "hello" to "HELLO", + "world" to "WORLD" + ).forEach { input, expected -> + describe("Capitalising $input") { + it("Correctly returns $expected") { + Assertions.assertEquals(expected, input.toUpperCase()) + } + } + } + } +}) diff --git a/core-kotlin/src/test/kotlin/com/baeldung/kotlin/spek/GroupTest5.kt b/core-kotlin/src/test/kotlin/com/baeldung/kotlin/spek/GroupTest5.kt new file mode 100644 index 0000000000..5aeee622e4 --- /dev/null +++ b/core-kotlin/src/test/kotlin/com/baeldung/kotlin/spek/GroupTest5.kt @@ -0,0 +1,62 @@ +package com.baeldung.kotlin.spek + +import org.jetbrains.spek.api.Spek +import org.jetbrains.spek.api.dsl.describe +import org.jetbrains.spek.api.dsl.it + +class GroupTest5 : Spek({ + describe("Outer group") { + beforeEachTest { + System.out.println("BeforeEachTest 0") + } + beforeGroup { + System.out.println("BeforeGroup 0") + } + afterEachTest { + System.out.println("AfterEachTest 0") + } + afterGroup { + System.out.println("AfterGroup 0") + } + describe("Inner group 1") { + beforeEachTest { + System.out.println("BeforeEachTest 1") + } + beforeGroup { + System.out.println("BeforeGroup 1") + } + afterEachTest { + System.out.println("AfterEachTest 1") + } + afterGroup { + System.out.println("AfterGroup 1") + } + it("Test 1") { + System.out.println("Test 1") + } + it("Test 2") { + System.out.println("Test 2") + } + } + describe("Inner group 2") { + beforeEachTest { + System.out.println("BeforeEachTest 2") + } + beforeGroup { + System.out.println("BeforeGroup 2") + } + afterEachTest { + System.out.println("AfterEachTest 2") + } + afterGroup { + System.out.println("AfterGroup 2") + } + it("Test 3") { + System.out.println("Test 3") + } + it("Test 4") { + System.out.println("Test 4") + } + } + } +}) From 85f8404b402c2e463f3ed06ea801ea7a113eadff Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Sat, 12 May 2018 01:27:49 +0300 Subject: [PATCH 65/66] fix logger import --- .../java/com/baeldung/stringisnumeric/IsNumericDriver.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/core-java/src/main/java/com/baeldung/stringisnumeric/IsNumericDriver.java b/core-java/src/main/java/com/baeldung/stringisnumeric/IsNumericDriver.java index 3dc2b6632a..c0a6edae50 100644 --- a/core-java/src/main/java/com/baeldung/stringisnumeric/IsNumericDriver.java +++ b/core-java/src/main/java/com/baeldung/stringisnumeric/IsNumericDriver.java @@ -1,12 +1,13 @@ package com.baeldung.stringisnumeric; -import static com.baeldung.designpatterns.util.LogerUtil.LOG; +import org.apache.log4j.Logger; public class IsNumericDriver { private static IsNumeric isNumeric; - + private static Logger LOG = Logger.getLogger(IsNumericDriver.class); static { isNumeric =new IsNumeric(); + } public static void main(String[] args) { From ca5a7d2e40b2af728256927de309d039a3937c99 Mon Sep 17 00:00:00 2001 From: christopherfranklin Date: Sat, 12 May 2018 00:23:24 -0400 Subject: [PATCH 66/66] [BAEL-1659] Create REST microservices with javalin (#4145) * [BAEL-1615] Code to support article. * Adding example of provides...with * Adding uses to main module * [BAEL-1659] Creat REST microservices with javalin * [BAEL-1659] Update article code based on feedback * Revert parent pom change * Using Optional instead of null --- libraries/pom.xml | 6 ++++ .../java/com/baeldung/javalin/JavalinApp.java | 16 +++++++++ .../java/com/baeldung/javalin/User/User.java | 11 +++++++ .../baeldung/javalin/User/UserController.java | 24 ++++++++++++++ .../com/baeldung/javalin/User/UserDao.java | 33 +++++++++++++++++++ 5 files changed, 90 insertions(+) create mode 100644 libraries/src/main/java/com/baeldung/javalin/JavalinApp.java create mode 100644 libraries/src/main/java/com/baeldung/javalin/User/User.java create mode 100644 libraries/src/main/java/com/baeldung/javalin/User/UserController.java create mode 100644 libraries/src/main/java/com/baeldung/javalin/User/UserDao.java diff --git a/libraries/pom.xml b/libraries/pom.xml index f4bf994a58..678ba3279c 100644 --- a/libraries/pom.xml +++ b/libraries/pom.xml @@ -680,6 +680,12 @@ ${unirest.version} + + + io.javalin + javalin + 1.6.0 + io.atlassian.fugue diff --git a/libraries/src/main/java/com/baeldung/javalin/JavalinApp.java b/libraries/src/main/java/com/baeldung/javalin/JavalinApp.java new file mode 100644 index 0000000000..33d2c7083f --- /dev/null +++ b/libraries/src/main/java/com/baeldung/javalin/JavalinApp.java @@ -0,0 +1,16 @@ +package com.baeldung.javalin; + +import com.baeldung.javalin.User.UserController; +import io.javalin.Javalin; + +public class JavalinApp { + public static void main(String[] args) { + Javalin app = Javalin.create() + .port(7000) + .start(); + + app.get("/hello", ctx -> ctx.html("Hello, Javalin!")); + app.get("/users", UserController.fetchAllUsernames); + app.get("/users/:id", UserController.fetchById); + } +} diff --git a/libraries/src/main/java/com/baeldung/javalin/User/User.java b/libraries/src/main/java/com/baeldung/javalin/User/User.java new file mode 100644 index 0000000000..09f710453b --- /dev/null +++ b/libraries/src/main/java/com/baeldung/javalin/User/User.java @@ -0,0 +1,11 @@ +package com.baeldung.javalin.User; + +public class User { + public final int id; + public final String name; + + public User(int id, String name) { + this.id = id; + this.name = name; + } +} diff --git a/libraries/src/main/java/com/baeldung/javalin/User/UserController.java b/libraries/src/main/java/com/baeldung/javalin/User/UserController.java new file mode 100644 index 0000000000..fd713606cf --- /dev/null +++ b/libraries/src/main/java/com/baeldung/javalin/User/UserController.java @@ -0,0 +1,24 @@ +package com.baeldung.javalin.User; + +import io.javalin.Handler; + +import java.util.Objects; + +public class UserController { + public static Handler fetchAllUsernames = ctx -> { + UserDao dao = UserDao.instance(); + Iterable allUsers = dao.getAllUsernames(); + ctx.json(allUsers); + }; + + public static Handler fetchById = ctx -> { + int id = Integer.parseInt(Objects.requireNonNull(ctx.param("id"))); + UserDao dao = UserDao.instance(); + User user = dao.getUserById(id); + if (user == null) { + ctx.html("Not Found"); + } else { + ctx.json(user); + } + }; +} diff --git a/libraries/src/main/java/com/baeldung/javalin/User/UserDao.java b/libraries/src/main/java/com/baeldung/javalin/User/UserDao.java new file mode 100644 index 0000000000..1cbf3012a8 --- /dev/null +++ b/libraries/src/main/java/com/baeldung/javalin/User/UserDao.java @@ -0,0 +1,33 @@ +package com.baeldung.javalin.User; + +import java.util.Arrays; +import java.util.List; +import java.util.Optional; +import java.util.stream.Collectors; + +class UserDao { + + private final List users = Arrays.asList( + new User(0, "Steve Rogers"), + new User(1, "Tony Stark"), + new User(2, "Carol Danvers") + ); + + private static UserDao userDao = null; + + private UserDao() { + } + + static UserDao instance() { + if (userDao == null) { + userDao = new UserDao(); + } + return userDao; + } + + Optional getUserById(int id) { return users.stream().filter(u -> u.id == id).findFirst(); } + + Iterable getAllUsernames() { + return users.stream().map(user -> user.name).collect(Collectors.toList()); + } +}