From 164853187bef6fcb966527828ba5221fed11719c Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Fri, 18 May 2018 17:40:47 +0300 Subject: [PATCH 01/84] Update README.md --- spring-5-reactive-client/README.md | 9 --------- 1 file changed, 9 deletions(-) diff --git a/spring-5-reactive-client/README.md b/spring-5-reactive-client/README.md index 400e343263..f94bd0b0c1 100644 --- a/spring-5-reactive-client/README.md +++ b/spring-5-reactive-client/README.md @@ -4,12 +4,3 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring ### Relevant Articles - -- [Concurrent Test Execution in Spring 5](http://www.baeldung.com/spring-5-concurrent-tests) -- [Introduction to the Functional Web Framework in Spring 5](http://www.baeldung.com/spring-5-functional-web) -- [Exploring the Spring 5 MVC URL Matching Improvements](http://www.baeldung.com/spring-5-mvc-url-matching) -- [Spring 5 WebClient](http://www.baeldung.com/spring-5-webclient) -- [Spring 5 Functional Bean Registration](http://www.baeldung.com/spring-5-functional-beans) -- [The SpringJUnitConfig and SpringJUnitWebConfig Annotations in Spring 5](http://www.baeldung.com/spring-5-junit-config) -- [Spring Security 5 for Reactive Applications](http://www.baeldung.com/spring-security-5-reactive) -- [Spring 5 Testing with @EnabledIf Annotation](https://github.com/eugenp/tutorials/tree/master/spring-5) From 750674b2cd817dd4c128bd77548a685ccd25744b Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Tue, 22 May 2018 14:47:53 +0300 Subject: [PATCH 02/84] update spring boot ctx app, rename classes --- pom.xml | 1 + spring-boot-ctx-fluent/pom.xml | 23 ++++++++++--------- .../src/main/java/com/baeldung/App.java | 22 ------------------ .../WebConfig.java => ctx1/Ctx1Config.java} | 11 +++++---- .../Ctx1Controller.java} | 6 ++--- .../{web => ctx1}/GreetingService.java | 4 ++-- .../RestConfig.java => ctx2/Ctx2Config.java} | 8 +++---- .../Ctx2Controller.java} | 6 ++--- .../main/java/com/baeldung/parent/App.java | 19 +++++++++++++++ .../{services => parent}/HomeService.java | 2 +- .../{services => parent}/IHomeService.java | 2 +- .../ParentConfig.java} | 6 ++--- .../src/main/resources/application.properties | 0 .../{rest-app.properties => ctx1.properties} | 2 +- .../{web-app.properties => ctx2.properties} | 4 +++- 15 files changed, 59 insertions(+), 57 deletions(-) delete mode 100644 spring-boot-ctx-fluent/src/main/java/com/baeldung/App.java rename spring-boot-ctx-fluent/src/main/java/com/baeldung/{web/WebConfig.java => ctx1/Ctx1Config.java} (71%) rename spring-boot-ctx-fluent/src/main/java/com/baeldung/{web/HomeController.java => ctx1/Ctx1Controller.java} (80%) rename spring-boot-ctx-fluent/src/main/java/com/baeldung/{web => ctx1}/GreetingService.java (74%) rename spring-boot-ctx-fluent/src/main/java/com/baeldung/{rest/RestConfig.java => ctx2/Ctx2Config.java} (68%) rename spring-boot-ctx-fluent/src/main/java/com/baeldung/{rest/GreetingController.java => ctx2/Ctx2Controller.java} (79%) create mode 100644 spring-boot-ctx-fluent/src/main/java/com/baeldung/parent/App.java rename spring-boot-ctx-fluent/src/main/java/com/baeldung/{services => parent}/HomeService.java (85%) rename spring-boot-ctx-fluent/src/main/java/com/baeldung/{services => parent}/IHomeService.java (66%) rename spring-boot-ctx-fluent/src/main/java/com/baeldung/{services/ServiceConfig.java => parent/ParentConfig.java} (57%) delete mode 100644 spring-boot-ctx-fluent/src/main/resources/application.properties rename spring-boot-ctx-fluent/src/main/resources/{rest-app.properties => ctx1.properties} (83%) rename spring-boot-ctx-fluent/src/main/resources/{web-app.properties => ctx2.properties} (72%) diff --git a/pom.xml b/pom.xml index 452c7838f7..bca9f953c1 100644 --- a/pom.xml +++ b/pom.xml @@ -259,6 +259,7 @@ java-spi performance-tests twilio + spring-boot-ctx-fluent diff --git a/spring-boot-ctx-fluent/pom.xml b/spring-boot-ctx-fluent/pom.xml index 5e308a0134..6d767f9ef7 100644 --- a/spring-boot-ctx-fluent/pom.xml +++ b/spring-boot-ctx-fluent/pom.xml @@ -3,25 +3,26 @@ 4.0.0 com.baeldung - ctxexample + spring-boot-ctx-fluent 0.0.1-SNAPSHOT jar - ctxexample - http://maven.apache.org + + parent-boot-2 + com.baeldung + 0.0.1-SNAPSHOT + ../parent-boot-2 + - - UTF-8 - - - org.springframework.boot - spring-boot-starter-parent - 2.0.0.RELEASE - org.springframework.boot spring-boot-starter-web + + + UTF-8 + + diff --git a/spring-boot-ctx-fluent/src/main/java/com/baeldung/App.java b/spring-boot-ctx-fluent/src/main/java/com/baeldung/App.java deleted file mode 100644 index da552a264b..0000000000 --- a/spring-boot-ctx-fluent/src/main/java/com/baeldung/App.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.baeldung; - -import org.springframework.boot.WebApplicationType; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.builder.SpringApplicationBuilder; - -import com.baeldung.rest.RestConfig; -import com.baeldung.services.ServiceConfig; -import com.baeldung.web.WebConfig; - -@SpringBootApplication -public class App { - public static void main(String[] args) { - new SpringApplicationBuilder().parent(ServiceConfig.class) - .web(WebApplicationType.NONE) - .child(WebConfig.class) - .web(WebApplicationType.SERVLET) - .sibling(RestConfig.class) - .web(WebApplicationType.SERVLET) - .run(args); - } -} diff --git a/spring-boot-ctx-fluent/src/main/java/com/baeldung/web/WebConfig.java b/spring-boot-ctx-fluent/src/main/java/com/baeldung/ctx1/Ctx1Config.java similarity index 71% rename from spring-boot-ctx-fluent/src/main/java/com/baeldung/web/WebConfig.java rename to spring-boot-ctx-fluent/src/main/java/com/baeldung/ctx1/Ctx1Config.java index 0b0a9a18f6..0bacc5e8fe 100644 --- a/spring-boot-ctx-fluent/src/main/java/com/baeldung/web/WebConfig.java +++ b/spring-boot-ctx-fluent/src/main/java/com/baeldung/ctx1/Ctx1Config.java @@ -1,4 +1,4 @@ -package com.baeldung.web; +package com.baeldung.ctx1; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.context.annotation.Bean; @@ -6,16 +6,17 @@ import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.PropertySource; -import com.baeldung.services.IHomeService; +import com.baeldung.parent.IHomeService; @Configuration -@ComponentScan("com.baeldung.web") +@ComponentScan("com.baeldung.ctx1") +@PropertySource("classpath:ctx1.properties") @EnableAutoConfiguration -@PropertySource("classpath:web-app.properties") -public class WebConfig { +public class Ctx1Config { @Bean public IHomeService homeService() { return new GreetingService(); } + } diff --git a/spring-boot-ctx-fluent/src/main/java/com/baeldung/web/HomeController.java b/spring-boot-ctx-fluent/src/main/java/com/baeldung/ctx1/Ctx1Controller.java similarity index 80% rename from spring-boot-ctx-fluent/src/main/java/com/baeldung/web/HomeController.java rename to spring-boot-ctx-fluent/src/main/java/com/baeldung/ctx1/Ctx1Controller.java index 622470107d..9c7667db35 100644 --- a/spring-boot-ctx-fluent/src/main/java/com/baeldung/web/HomeController.java +++ b/spring-boot-ctx-fluent/src/main/java/com/baeldung/ctx1/Ctx1Controller.java @@ -1,14 +1,14 @@ -package com.baeldung.web; +package com.baeldung.ctx1; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.ResponseBody; -import com.baeldung.services.IHomeService; +import com.baeldung.parent.IHomeService; @Controller -public class HomeController { +public class Ctx1Controller { @Autowired IHomeService homeService; diff --git a/spring-boot-ctx-fluent/src/main/java/com/baeldung/web/GreetingService.java b/spring-boot-ctx-fluent/src/main/java/com/baeldung/ctx1/GreetingService.java similarity index 74% rename from spring-boot-ctx-fluent/src/main/java/com/baeldung/web/GreetingService.java rename to spring-boot-ctx-fluent/src/main/java/com/baeldung/ctx1/GreetingService.java index 1782b35489..a0f1f16288 100644 --- a/spring-boot-ctx-fluent/src/main/java/com/baeldung/web/GreetingService.java +++ b/spring-boot-ctx-fluent/src/main/java/com/baeldung/ctx1/GreetingService.java @@ -1,8 +1,8 @@ -package com.baeldung.web; +package com.baeldung.ctx1; import org.springframework.stereotype.Service; -import com.baeldung.services.IHomeService; +import com.baeldung.parent.IHomeService; @Service public class GreetingService implements IHomeService { diff --git a/spring-boot-ctx-fluent/src/main/java/com/baeldung/rest/RestConfig.java b/spring-boot-ctx-fluent/src/main/java/com/baeldung/ctx2/Ctx2Config.java similarity index 68% rename from spring-boot-ctx-fluent/src/main/java/com/baeldung/rest/RestConfig.java rename to spring-boot-ctx-fluent/src/main/java/com/baeldung/ctx2/Ctx2Config.java index 77b78d01b6..fc08b741f3 100644 --- a/spring-boot-ctx-fluent/src/main/java/com/baeldung/rest/RestConfig.java +++ b/spring-boot-ctx-fluent/src/main/java/com/baeldung/ctx2/Ctx2Config.java @@ -1,4 +1,4 @@ -package com.baeldung.rest; +package com.baeldung.ctx2; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.context.annotation.ComponentScan; @@ -6,9 +6,9 @@ import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.PropertySource; @Configuration -@ComponentScan("com.baeldung.rest") +@ComponentScan("com.baeldung.ctx2") @EnableAutoConfiguration -@PropertySource("classpath:rest-app.properties") -public class RestConfig { +@PropertySource("classpath:ctx2.properties") +public class Ctx2Config { } diff --git a/spring-boot-ctx-fluent/src/main/java/com/baeldung/rest/GreetingController.java b/spring-boot-ctx-fluent/src/main/java/com/baeldung/ctx2/Ctx2Controller.java similarity index 79% rename from spring-boot-ctx-fluent/src/main/java/com/baeldung/rest/GreetingController.java rename to spring-boot-ctx-fluent/src/main/java/com/baeldung/ctx2/Ctx2Controller.java index 563a374dd1..850fd8021c 100644 --- a/spring-boot-ctx-fluent/src/main/java/com/baeldung/rest/GreetingController.java +++ b/spring-boot-ctx-fluent/src/main/java/com/baeldung/ctx2/Ctx2Controller.java @@ -1,13 +1,13 @@ -package com.baeldung.rest; +package com.baeldung.ctx2; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; -import com.baeldung.services.IHomeService; +import com.baeldung.parent.IHomeService; @RestController -public class GreetingController { +public class Ctx2Controller { @Autowired IHomeService homeService; diff --git a/spring-boot-ctx-fluent/src/main/java/com/baeldung/parent/App.java b/spring-boot-ctx-fluent/src/main/java/com/baeldung/parent/App.java new file mode 100644 index 0000000000..609751bc0f --- /dev/null +++ b/spring-boot-ctx-fluent/src/main/java/com/baeldung/parent/App.java @@ -0,0 +1,19 @@ +package com.baeldung.parent; + +import org.springframework.boot.WebApplicationType; +import org.springframework.boot.builder.SpringApplicationBuilder; + +import com.baeldung.ctx1.Ctx1Config; +import com.baeldung.ctx2.Ctx2Config; + +public class App { + public static void main(String[] args) { + new SpringApplicationBuilder().parent(ParentConfig.class) + .web(WebApplicationType.NONE) + .child(Ctx1Config.class) + .web(WebApplicationType.SERVLET) + .sibling(Ctx2Config.class) + .web(WebApplicationType.SERVLET) + .run(args); + } +} diff --git a/spring-boot-ctx-fluent/src/main/java/com/baeldung/services/HomeService.java b/spring-boot-ctx-fluent/src/main/java/com/baeldung/parent/HomeService.java similarity index 85% rename from spring-boot-ctx-fluent/src/main/java/com/baeldung/services/HomeService.java rename to spring-boot-ctx-fluent/src/main/java/com/baeldung/parent/HomeService.java index c1cbe027ee..0d23e26cce 100644 --- a/spring-boot-ctx-fluent/src/main/java/com/baeldung/services/HomeService.java +++ b/spring-boot-ctx-fluent/src/main/java/com/baeldung/parent/HomeService.java @@ -1,4 +1,4 @@ -package com.baeldung.services; +package com.baeldung.parent; import org.springframework.stereotype.Service; diff --git a/spring-boot-ctx-fluent/src/main/java/com/baeldung/services/IHomeService.java b/spring-boot-ctx-fluent/src/main/java/com/baeldung/parent/IHomeService.java similarity index 66% rename from spring-boot-ctx-fluent/src/main/java/com/baeldung/services/IHomeService.java rename to spring-boot-ctx-fluent/src/main/java/com/baeldung/parent/IHomeService.java index 0386e13c0b..264e49861a 100644 --- a/spring-boot-ctx-fluent/src/main/java/com/baeldung/services/IHomeService.java +++ b/spring-boot-ctx-fluent/src/main/java/com/baeldung/parent/IHomeService.java @@ -1,4 +1,4 @@ -package com.baeldung.services; +package com.baeldung.parent; public interface IHomeService { diff --git a/spring-boot-ctx-fluent/src/main/java/com/baeldung/services/ServiceConfig.java b/spring-boot-ctx-fluent/src/main/java/com/baeldung/parent/ParentConfig.java similarity index 57% rename from spring-boot-ctx-fluent/src/main/java/com/baeldung/services/ServiceConfig.java rename to spring-boot-ctx-fluent/src/main/java/com/baeldung/parent/ParentConfig.java index 6f98bb0457..484d020cc0 100644 --- a/spring-boot-ctx-fluent/src/main/java/com/baeldung/services/ServiceConfig.java +++ b/spring-boot-ctx-fluent/src/main/java/com/baeldung/parent/ParentConfig.java @@ -1,8 +1,8 @@ -package com.baeldung.services; +package com.baeldung.parent; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; @Configuration -@ComponentScan("com.baeldung.services") -public class ServiceConfig {} +@ComponentScan("com.baeldung.parent") +public class ParentConfig {} diff --git a/spring-boot-ctx-fluent/src/main/resources/application.properties b/spring-boot-ctx-fluent/src/main/resources/application.properties deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/spring-boot-ctx-fluent/src/main/resources/rest-app.properties b/spring-boot-ctx-fluent/src/main/resources/ctx1.properties similarity index 83% rename from spring-boot-ctx-fluent/src/main/resources/rest-app.properties rename to spring-boot-ctx-fluent/src/main/resources/ctx1.properties index dc5a463238..2b618d4177 100644 --- a/spring-boot-ctx-fluent/src/main/resources/rest-app.properties +++ b/spring-boot-ctx-fluent/src/main/resources/ctx1.properties @@ -1,5 +1,5 @@ server.port=8081 -server.servlet.context-path=/rest +server.servlet.context-path=/ctx1 #logging.level=debug spring.application.admin.enabled=false spring.application.admin.jmx-name=org.springframework.boot:type=AdminRest,name=SpringRestApplication \ No newline at end of file diff --git a/spring-boot-ctx-fluent/src/main/resources/web-app.properties b/spring-boot-ctx-fluent/src/main/resources/ctx2.properties similarity index 72% rename from spring-boot-ctx-fluent/src/main/resources/web-app.properties rename to spring-boot-ctx-fluent/src/main/resources/ctx2.properties index 2b81875901..f3599e17e0 100644 --- a/spring-boot-ctx-fluent/src/main/resources/web-app.properties +++ b/spring-boot-ctx-fluent/src/main/resources/ctx2.properties @@ -1,3 +1,5 @@ -server.port=8080 +server.port=8082 +server.servlet.context-path=/ctx2 + spring.application.admin.enabled=false spring.application.admin.jmx-name=org.springframework.boot:type=WebAdmin,name=SpringWebApplication \ No newline at end of file From 11ae9c438c26c6496149bce02867dbcee75eef2f Mon Sep 17 00:00:00 2001 From: Karan Khanna Date: Thu, 7 Jun 2018 21:29:38 +0200 Subject: [PATCH 03/84] resolved conflicts --- .../src/main/java/com/baeldung/model/Employee.java | 8 ++++---- .../java/com/baeldung/servlets/EmployeeServlet.java | 13 +++++-------- .../servlets/EmployeeServletIntegrationTest.java | 10 ++-------- 3 files changed, 11 insertions(+), 20 deletions(-) diff --git a/javax-servlets/src/main/java/com/baeldung/model/Employee.java b/javax-servlets/src/main/java/com/baeldung/model/Employee.java index 9a85a69fff..698a598962 100644 --- a/javax-servlets/src/main/java/com/baeldung/model/Employee.java +++ b/javax-servlets/src/main/java/com/baeldung/model/Employee.java @@ -5,9 +5,9 @@ public class Employee { private int id; private String name; private String department; - private Double salary; + private long salary; - public Employee(int id, String name, String department, Double salary) { + public Employee(int id, String name, String department, long salary) { super(); this.id = id; this.name = name; @@ -61,11 +61,11 @@ public class Employee { this.department = department; } - public Double getSalary() { + public long getSalary() { return salary; } - public void setSalary(Double salary) { + public void setSalary(long salary) { this.salary = salary; } diff --git a/javax-servlets/src/main/java/com/baeldung/servlets/EmployeeServlet.java b/javax-servlets/src/main/java/com/baeldung/servlets/EmployeeServlet.java index ea82ca5055..dbc1a010f7 100644 --- a/javax-servlets/src/main/java/com/baeldung/servlets/EmployeeServlet.java +++ b/javax-servlets/src/main/java/com/baeldung/servlets/EmployeeServlet.java @@ -14,18 +14,15 @@ import com.google.gson.Gson; @WebServlet(name = "EmployeeServlet", urlPatterns = "/employeeServlet") public class EmployeeServlet extends HttpServlet { + + private Gson gson = new Gson(); @Override - protected void doPost(HttpServletRequest request, HttpServletResponse response) + public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { - int id = Integer.parseInt(request.getParameter("id")); - String name = request.getParameter("name"); - String department = request.getParameter("department"); - Double salary = Double.parseDouble(request.getParameter("salary")); - - Employee employee = new Employee(id, name, department, salary); - String employeeJsonString = new Gson().toJson(employee); + Employee employee = new Employee(1, "Karan", "IT", 5000); + String employeeJsonString = this.gson.toJson(employee); PrintWriter out = response.getWriter(); response.setContentType("application/json"); diff --git a/javax-servlets/src/test/java/com/baeldung/servlets/EmployeeServletIntegrationTest.java b/javax-servlets/src/test/java/com/baeldung/servlets/EmployeeServletIntegrationTest.java index c96ad0a858..4fe4908075 100644 --- a/javax-servlets/src/test/java/com/baeldung/servlets/EmployeeServletIntegrationTest.java +++ b/javax-servlets/src/test/java/com/baeldung/servlets/EmployeeServletIntegrationTest.java @@ -36,21 +36,15 @@ public class EmployeeServletIntegrationTest { int id = 1; String name = "Karan Khanna"; String department = "IT"; - Double salary = 5000.0; + long salary = 5000; employee = new Employee(id, name, department, salary); - //when - when(httpServletRequest.getParameter("id")).thenReturn(String.valueOf(id)); - when(httpServletRequest.getParameter("name")).thenReturn(name); - when(httpServletRequest.getParameter("department")).thenReturn(department); - when(httpServletRequest.getParameter("salary")).thenReturn(String.valueOf(salary)); - StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); when(httpServletResponse.getWriter()).thenReturn(pw); EmployeeServlet employeeServlet = new EmployeeServlet(); - employeeServlet.doPost(httpServletRequest, httpServletResponse); + employeeServlet.doGet(httpServletRequest, httpServletResponse); String employeeJsonString = sw.getBuffer().toString().trim(); Employee fetchedEmployee = new Gson().fromJson(employeeJsonString, Employee.class); From 0a3d212a2a32a3bef5d0304fcb3e821b43366ca8 Mon Sep 17 00:00:00 2001 From: Marcos Lopez Gonzalez Date: Fri, 8 Jun 2018 07:35:46 +0200 Subject: [PATCH 04/84] BAEL-1773 Find the middle element of a Linked List. (#4425) * BAEL-1773 - find middle element of linked list * changes from review * changes from review * find middle element in linked list * typo --- .../linkedlist/MiddleElementLookup.java | 18 ++++-- .../java/com/baeldung/linkedlist/Node.java | 34 ++++++++++ .../MiddleElementLookupUnitTest.java | 62 +++++++++++-------- 3 files changed, 83 insertions(+), 31 deletions(-) create mode 100644 core-java/src/main/java/com/baeldung/linkedlist/Node.java diff --git a/core-java/src/main/java/com/baeldung/linkedlist/MiddleElementLookup.java b/core-java/src/main/java/com/baeldung/linkedlist/MiddleElementLookup.java index 27684c93d2..2caf17fd0c 100644 --- a/core-java/src/main/java/com/baeldung/linkedlist/MiddleElementLookup.java +++ b/core-java/src/main/java/com/baeldung/linkedlist/MiddleElementLookup.java @@ -1,10 +1,20 @@ package com.baeldung.linkedlist; -import com.baeldung.linkedlist.LinkedList.Node; +import java.util.LinkedList; + +import com.baeldung.linkedlist.Node; public class MiddleElementLookup { - public static String findMiddleElement(Node head) { + public static String findMiddleElementLinkedList(LinkedList linkedList) { + if (linkedList == null || linkedList.isEmpty()) { + return null; + } + + return linkedList.get((linkedList.size() - 1) / 2); + } + + public static String findMiddleElementFromHead(Node head) { if (head == null) { return null; } @@ -26,7 +36,7 @@ public class MiddleElementLookup { return current.data(); } - public static String findMiddleElement1PassRecursively(Node head) { + public static String findMiddleElementFromHead1PassRecursively(Node head) { if (head == null) { return null; } @@ -53,7 +63,7 @@ public class MiddleElementLookup { middleAux.length--; } - public static String findMiddleElement1PassIteratively(Node head) { + public static String findMiddleElementFromHead1PassIteratively(Node head) { if (head == null) { return null; } diff --git a/core-java/src/main/java/com/baeldung/linkedlist/Node.java b/core-java/src/main/java/com/baeldung/linkedlist/Node.java new file mode 100644 index 0000000000..daceaffdcd --- /dev/null +++ b/core-java/src/main/java/com/baeldung/linkedlist/Node.java @@ -0,0 +1,34 @@ +package com.baeldung.linkedlist; + +public class Node { + private Node next; + private String data; + + public Node(String data) { + this.data = data; + } + + public String data() { + return data; + } + + public void setData(String data) { + this.data = data; + } + + public boolean hasNext() { + return next != null; + } + + public Node next() { + return next; + } + + public void setNext(Node next) { + this.next = next; + } + + public String toString() { + return this.data; + } +} diff --git a/core-java/src/test/java/com/baeldung/linkedlist/MiddleElementLookupUnitTest.java b/core-java/src/test/java/com/baeldung/linkedlist/MiddleElementLookupUnitTest.java index d456259612..08a4e52ff9 100644 --- a/core-java/src/test/java/com/baeldung/linkedlist/MiddleElementLookupUnitTest.java +++ b/core-java/src/test/java/com/baeldung/linkedlist/MiddleElementLookupUnitTest.java @@ -2,51 +2,46 @@ package com.baeldung.linkedlist; import static org.junit.Assert.assertEquals; +import java.util.LinkedList; + import org.junit.Test; public class MiddleElementLookupUnitTest { @Test - public void whenFindingMiddle_thenMiddleFound() { - String middle = MiddleElementLookup.findMiddleElement(createList(5).head()); - assertEquals("3", middle); - - middle = MiddleElementLookup.findMiddleElement(createList(4).head()); - assertEquals("2", middle); + public void whenFindingMiddleLinkedList_thenMiddleFound() { + assertEquals("3", MiddleElementLookup.findMiddleElementLinkedList(createLinkedList(5))); + assertEquals("2", MiddleElementLookup.findMiddleElementLinkedList(createLinkedList(4))); } @Test - public void whenFindingMiddle1PassRecursively_thenMiddleFound() { - String middle = MiddleElementLookup.findMiddleElement1PassRecursively(createList(5).head()); - assertEquals("3", middle); - - middle = MiddleElementLookup.findMiddleElement1PassRecursively(createList(4).head()); - assertEquals("2", middle); + public void whenFindingMiddleFromHead_thenMiddleFound() { + assertEquals("3", MiddleElementLookup.findMiddleElementFromHead(createNodesList(5))); + assertEquals("2", MiddleElementLookup.findMiddleElementFromHead(createNodesList(4))); } @Test - public void whenFindingMiddle1PassIteratively_thenMiddleFound() { - String middle = MiddleElementLookup.findMiddleElement1PassIteratively(createList(5).head()); - assertEquals("3", middle); + public void whenFindingMiddleFromHead1PassRecursively_thenMiddleFound() { + assertEquals("3", MiddleElementLookup.findMiddleElementFromHead1PassRecursively(createNodesList(5))); + assertEquals("2", MiddleElementLookup.findMiddleElementFromHead1PassRecursively(createNodesList(4))); + } - middle = MiddleElementLookup.findMiddleElement1PassIteratively(createList(4).head()); - assertEquals("2", middle); + @Test + public void whenFindingMiddleFromHead1PassIteratively_thenMiddleFound() { + assertEquals("3", MiddleElementLookup.findMiddleElementFromHead1PassIteratively(createNodesList(5))); + assertEquals("2", MiddleElementLookup.findMiddleElementFromHead1PassIteratively(createNodesList(4))); } @Test public void whenListEmptyOrNull_thenMiddleNull() { - String middle = MiddleElementLookup.findMiddleElement(null); - assertEquals(null, middle); - - middle = MiddleElementLookup.findMiddleElement1PassIteratively(null); - assertEquals(null, middle); - - middle = MiddleElementLookup.findMiddleElement1PassRecursively(null); - assertEquals(null, middle); + assertEquals(null, MiddleElementLookup.findMiddleElementLinkedList(null)); + assertEquals(null, MiddleElementLookup.findMiddleElementFromHead(null)); + assertEquals(null, MiddleElementLookup.findMiddleElementFromHead1PassIteratively(null)); + assertEquals(null, MiddleElementLookup.findMiddleElementFromHead1PassRecursively(null)); } - private static LinkedList createList(int n) { - LinkedList list = new LinkedList(); + private static LinkedList createLinkedList(int n) { + LinkedList list = new LinkedList<>(); for (int i = 1; i <= n; i++) { list.add(String.valueOf(i)); @@ -55,4 +50,17 @@ public class MiddleElementLookupUnitTest { return list; } + private static Node createNodesList(int n) { + Node head = new Node("1"); + Node current = head; + + for (int i = 2; i <= n; i++) { + Node newNode = new Node(String.valueOf(i)); + current.setNext(newNode); + current = newNode; + } + + return head; + } + } From 749611e3142b90f48dd0bb66191d6f7c59c028a2 Mon Sep 17 00:00:00 2001 From: Seun Matt Date: Fri, 8 Jun 2018 08:05:37 +0100 Subject: [PATCH 05/84] updated example code for BAEL-1425 (#4424) --- .../com/baeldung/commons/math3/Histogram.java | 34 ++++++++++--------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/libraries/src/main/java/com/baeldung/commons/math3/Histogram.java b/libraries/src/main/java/com/baeldung/commons/math3/Histogram.java index 5b4097b1e4..a8c15887be 100644 --- a/libraries/src/main/java/com/baeldung/commons/math3/Histogram.java +++ b/libraries/src/main/java/com/baeldung/commons/math3/Histogram.java @@ -47,27 +47,29 @@ public class Histogram { private Map processRawData() { - List datasetList = Arrays.asList(36, 25, 38, 46, 55, 68, 72, 55, 36, 38, 67, 45, 22, 48, 91, 46, 52, 61, 58, 55); + List datasetList = Arrays.asList( + 36, 25, 38, 46, 55, 68, 72, + 55, 36, 38, 67, 45, 22, 48, + 91, 46, 52, 61, 58, 55); Frequency frequency = new Frequency(); datasetList.forEach(d -> frequency.addValue(Double.parseDouble(d.toString()))); - List processed = new ArrayList(); - datasetList.forEach(d -> { - double observation = Double.parseDouble(d.toString()); + datasetList.stream() + .map(d -> Double.parseDouble(d.toString())) + .distinct() + .forEach(observation -> { + long observationFrequency = frequency.getCount(observation); + int upperBoundary = (observation > classWidth) + ? Math.multiplyExact( (int) Math.ceil(observation / classWidth), classWidth) + : classWidth; + int lowerBoundary = (upperBoundary > classWidth) + ? Math.subtractExact(upperBoundary, classWidth) + : 0; + String bin = lowerBoundary + "-" + upperBoundary; - if(processed.contains(observation)) - return; + updateDistributionMap(lowerBoundary, bin, observationFrequency); - long observationFrequency = frequency.getCount(observation); - int upperBoundary = (observation > classWidth) ? Math.multiplyExact( (int) Math.ceil(observation / classWidth), classWidth) : classWidth; - int lowerBoundary = (upperBoundary > classWidth) ? Math.subtractExact(upperBoundary, classWidth) : 0; - String bin = lowerBoundary + "-" + upperBoundary; - - updateDistributionMap(lowerBoundary, bin, observationFrequency); - - processed.add(observation); - - }); + }); return distributionMap; } From d28ffe5982171f7e13d642acf74664cd4e362194 Mon Sep 17 00:00:00 2001 From: Doha2012 Date: Fri, 8 Jun 2018 16:22:55 +0000 Subject: [PATCH 06/84] upgrade katharsis 3 (#4429) --- spring-katharsis/pom.xml | 2 +- .../main/java/org/baeldung/Application.java | 4 ++ .../persistence/katharsis/JsonApiFilter.java | 40 ------------------- .../katharsis/RoleResourceRepository.java | 28 +++++++++---- .../katharsis/UserResourceRepository.java | 27 +++++++++---- .../UserToRoleRelationshipRepository.java | 24 ++++++++--- .../org/baeldung/persistence/model/Role.java | 25 +++++++----- .../org/baeldung/persistence/model/User.java | 19 +++++---- .../src/main/resources/application.properties | 5 ++- 9 files changed, 93 insertions(+), 81 deletions(-) delete mode 100644 spring-katharsis/src/main/java/org/baeldung/persistence/katharsis/JsonApiFilter.java diff --git a/spring-katharsis/pom.xml b/spring-katharsis/pom.xml index 27075de747..8bc75d97b3 100644 --- a/spring-katharsis/pom.xml +++ b/spring-katharsis/pom.xml @@ -33,7 +33,7 @@ io.katharsis - katharsis-servlet + katharsis-spring ${katharsis.version} diff --git a/spring-katharsis/src/main/java/org/baeldung/Application.java b/spring-katharsis/src/main/java/org/baeldung/Application.java index ee072305d8..5ce4ac7e08 100644 --- a/spring-katharsis/src/main/java/org/baeldung/Application.java +++ b/spring-katharsis/src/main/java/org/baeldung/Application.java @@ -1,10 +1,14 @@ package org.baeldung; +import io.katharsis.spring.boot.v3.KatharsisConfigV3; + import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.web.support.SpringBootServletInitializer; +import org.springframework.context.annotation.Import; @SpringBootApplication +@Import(KatharsisConfigV3.class) public class Application extends SpringBootServletInitializer { public static void main(String[] args) { diff --git a/spring-katharsis/src/main/java/org/baeldung/persistence/katharsis/JsonApiFilter.java b/spring-katharsis/src/main/java/org/baeldung/persistence/katharsis/JsonApiFilter.java deleted file mode 100644 index 3d0d441357..0000000000 --- a/spring-katharsis/src/main/java/org/baeldung/persistence/katharsis/JsonApiFilter.java +++ /dev/null @@ -1,40 +0,0 @@ -package org.baeldung.persistence.katharsis; - -import io.katharsis.invoker.internal.legacy.KatharsisInvokerBuilder; -import io.katharsis.legacy.locator.JsonServiceLocator; -import io.katharsis.servlet.legacy.AbstractKatharsisFilter; - -import org.springframework.beans.BeansException; -import org.springframework.beans.factory.BeanFactory; -import org.springframework.beans.factory.BeanFactoryAware; -import org.springframework.stereotype.Component; - -@Component -public class JsonApiFilter extends AbstractKatharsisFilter implements BeanFactoryAware { - - private static final String DEFAULT_RESOURCE_SEARCH_PACKAGE = "org.baeldung.persistence"; - - private static final String RESOURCE_DEFAULT_DOMAIN = "http://localhost:8080"; - - private BeanFactory beanFactory; - - @Override - public void setBeanFactory(BeanFactory beanFactory) throws BeansException { - this.beanFactory = beanFactory; - } - - @Override - protected KatharsisInvokerBuilder createKatharsisInvokerBuilder() { - final KatharsisInvokerBuilder builder = new KatharsisInvokerBuilder(); - - builder.resourceSearchPackage(DEFAULT_RESOURCE_SEARCH_PACKAGE).resourceDefaultDomain(RESOURCE_DEFAULT_DOMAIN).jsonServiceLocator(new JsonServiceLocator() { - @Override - public T getInstance(Class clazz) { - return beanFactory.getBean(clazz); - } - }); - - return builder; - } - -} diff --git a/spring-katharsis/src/main/java/org/baeldung/persistence/katharsis/RoleResourceRepository.java b/spring-katharsis/src/main/java/org/baeldung/persistence/katharsis/RoleResourceRepository.java index 52ca40e26e..1998c414bb 100644 --- a/spring-katharsis/src/main/java/org/baeldung/persistence/katharsis/RoleResourceRepository.java +++ b/spring-katharsis/src/main/java/org/baeldung/persistence/katharsis/RoleResourceRepository.java @@ -1,7 +1,9 @@ package org.baeldung.persistence.katharsis; -import io.katharsis.legacy.queryParams.QueryParams; -import io.katharsis.legacy.repository.ResourceRepository; + +import io.katharsis.queryspec.QuerySpec; +import io.katharsis.repository.ResourceRepositoryV2; +import io.katharsis.resource.list.ResourceList; import org.baeldung.persistence.dao.RoleRepository; import org.baeldung.persistence.model.Role; @@ -9,23 +11,23 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @Component -public class RoleResourceRepository implements ResourceRepository { +public class RoleResourceRepository implements ResourceRepositoryV2 { @Autowired private RoleRepository roleRepository; @Override - public Role findOne(Long id, QueryParams params) { + public Role findOne(Long id, QuerySpec querySpec) { return roleRepository.findOne(id); } @Override - public Iterable findAll(QueryParams params) { - return roleRepository.findAll(); + public ResourceList findAll(QuerySpec querySpec) { + return querySpec.apply(roleRepository.findAll()); } @Override - public Iterable findAll(Iterable ids, QueryParams params) { - return roleRepository.findAll(ids); + public ResourceList findAll(Iterable ids, QuerySpec querySpec) { + return querySpec.apply(roleRepository.findAll(ids)); } @Override @@ -38,4 +40,14 @@ public class RoleResourceRepository implements ResourceRepository { roleRepository.delete(id); } + @Override + public Class getResourceClass() { + return Role.class; + } + + @Override + public S create(S entity) { + return save(entity); + } + } diff --git a/spring-katharsis/src/main/java/org/baeldung/persistence/katharsis/UserResourceRepository.java b/spring-katharsis/src/main/java/org/baeldung/persistence/katharsis/UserResourceRepository.java index a36c3c3c0a..9b3de31601 100644 --- a/spring-katharsis/src/main/java/org/baeldung/persistence/katharsis/UserResourceRepository.java +++ b/spring-katharsis/src/main/java/org/baeldung/persistence/katharsis/UserResourceRepository.java @@ -1,7 +1,8 @@ package org.baeldung.persistence.katharsis; -import io.katharsis.legacy.queryParams.QueryParams; -import io.katharsis.legacy.repository.ResourceRepository; +import io.katharsis.queryspec.QuerySpec; +import io.katharsis.repository.ResourceRepositoryV2; +import io.katharsis.resource.list.ResourceList; import org.baeldung.persistence.dao.UserRepository; import org.baeldung.persistence.model.User; @@ -9,24 +10,24 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @Component -public class UserResourceRepository implements ResourceRepository { +public class UserResourceRepository implements ResourceRepositoryV2 { @Autowired private UserRepository userRepository; @Override - public User findOne(Long id, QueryParams params) { + public User findOne(Long id, QuerySpec querySpec) { return userRepository.findOne(id); } @Override - public Iterable findAll(QueryParams params) { - return userRepository.findAll(); + public ResourceList findAll(QuerySpec querySpec) { + return querySpec.apply(userRepository.findAll()); } @Override - public Iterable findAll(Iterable ids, QueryParams params) { - return userRepository.findAll(ids); + public ResourceList findAll(Iterable ids, QuerySpec querySpec) { + return querySpec.apply(userRepository.findAll(ids)); } @Override @@ -39,4 +40,14 @@ public class UserResourceRepository implements ResourceRepository { userRepository.delete(id); } + @Override + public Class getResourceClass() { + return User.class; + } + + @Override + public S create(S entity) { + return save(entity); + } + } diff --git a/spring-katharsis/src/main/java/org/baeldung/persistence/katharsis/UserToRoleRelationshipRepository.java b/spring-katharsis/src/main/java/org/baeldung/persistence/katharsis/UserToRoleRelationshipRepository.java index 19007a285f..dbeb769fac 100644 --- a/spring-katharsis/src/main/java/org/baeldung/persistence/katharsis/UserToRoleRelationshipRepository.java +++ b/spring-katharsis/src/main/java/org/baeldung/persistence/katharsis/UserToRoleRelationshipRepository.java @@ -1,7 +1,8 @@ package org.baeldung.persistence.katharsis; -import io.katharsis.legacy.queryParams.QueryParams; -import io.katharsis.legacy.repository.RelationshipRepository; +import io.katharsis.queryspec.QuerySpec; +import io.katharsis.repository.RelationshipRepositoryV2; +import io.katharsis.resource.list.ResourceList; import java.util.HashSet; import java.util.Set; @@ -14,7 +15,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @Component -public class UserToRoleRelationshipRepository implements RelationshipRepository { +public class UserToRoleRelationshipRepository implements RelationshipRepositoryV2 { @Autowired private UserRepository userRepository; @@ -52,14 +53,25 @@ public class UserToRoleRelationshipRepository implements RelationshipRepository< } @Override - public Role findOneTarget(Long sourceId, String fieldName, QueryParams QueryParams) { + public Role findOneTarget(Long sourceId, String fieldName, QuerySpec querySpec) { // not for many-to-many return null; } @Override - public Iterable findManyTargets(Long sourceId, String fieldName, QueryParams QueryParams) { + public ResourceList findManyTargets(Long sourceId, String fieldName, QuerySpec querySpec) { final User user = userRepository.findOne(sourceId); - return user.getRoles(); + return querySpec.apply(user.getRoles()); } + + @Override + public Class getSourceResourceClass() { + return User.class; + } + + @Override + public Class getTargetResourceClass() { + return Role.class; + } + } diff --git a/spring-katharsis/src/main/java/org/baeldung/persistence/model/Role.java b/spring-katharsis/src/main/java/org/baeldung/persistence/model/Role.java index fcaf40ac2c..f391efd37c 100644 --- a/spring-katharsis/src/main/java/org/baeldung/persistence/model/Role.java +++ b/spring-katharsis/src/main/java/org/baeldung/persistence/model/Role.java @@ -1,8 +1,8 @@ package org.baeldung.persistence.model; import io.katharsis.resource.annotations.JsonApiId; +import io.katharsis.resource.annotations.JsonApiRelation; import io.katharsis.resource.annotations.JsonApiResource; -import io.katharsis.resource.annotations.JsonApiToMany; import java.util.Set; @@ -25,7 +25,7 @@ public class Role { private String name; @ManyToMany(mappedBy = "roles") - @JsonApiToMany + @JsonApiRelation private Set users; // @@ -66,23 +66,30 @@ public class Role { @Override public boolean equals(Object obj) { - if (this == obj) + if (this == obj) { return true; - if (obj == null) + } + if (obj == null) { return false; - if (getClass() != obj.getClass()) + } + if (getClass() != obj.getClass()) { return false; + } final Role other = (Role) obj; if (id == null) { - if (other.id != null) + if (other.id != null) { return false; - } else if (!id.equals(other.id)) + } + } else if (!id.equals(other.id)) { return false; + } if (name == null) { - if (other.name != null) + if (other.name != null) { return false; - } else if (!name.equals(other.name)) + } + } else if (!name.equals(other.name)) { return false; + } return true; } diff --git a/spring-katharsis/src/main/java/org/baeldung/persistence/model/User.java b/spring-katharsis/src/main/java/org/baeldung/persistence/model/User.java index 58a92002c8..7c55e29599 100644 --- a/spring-katharsis/src/main/java/org/baeldung/persistence/model/User.java +++ b/spring-katharsis/src/main/java/org/baeldung/persistence/model/User.java @@ -1,9 +1,9 @@ package org.baeldung.persistence.model; import io.katharsis.resource.annotations.JsonApiId; -import io.katharsis.resource.annotations.JsonApiIncludeByDefault; +import io.katharsis.resource.annotations.JsonApiRelation; import io.katharsis.resource.annotations.JsonApiResource; -import io.katharsis.resource.annotations.JsonApiToMany; +import io.katharsis.resource.annotations.SerializeType; import java.util.Set; @@ -31,8 +31,7 @@ public class User { @ManyToMany(fetch = FetchType.EAGER) @JoinTable(name = "users_roles", joinColumns = @JoinColumn(name = "user_id", referencedColumnName = "id"), inverseJoinColumns = @JoinColumn(name = "role_id", referencedColumnName = "id")) - @JsonApiToMany - @JsonApiIncludeByDefault + @JsonApiRelation(serialize=SerializeType.EAGER) private Set roles; public User() { @@ -87,15 +86,19 @@ public class User { @Override public boolean equals(final Object obj) { - if (this == obj) + if (this == obj) { return true; - if (obj == null) + } + if (obj == null) { return false; - if (getClass() != obj.getClass()) + } + if (getClass() != obj.getClass()) { return false; + } final User user = (User) obj; - if (!email.equals(user.email)) + if (!email.equals(user.email)) { return false; + } return true; } diff --git a/spring-katharsis/src/main/resources/application.properties b/spring-katharsis/src/main/resources/application.properties index b55fdbba03..120b3c62ee 100644 --- a/spring-katharsis/src/main/resources/application.properties +++ b/spring-katharsis/src/main/resources/application.properties @@ -6,4 +6,7 @@ spring.jpa.hibernate.ddl-auto = create-drop spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.H2Dialect server.port=8082 -server.context-path=/spring-katharsis \ No newline at end of file +server.context-path=/spring-katharsis + +katharsis.domainName=http://localhost:8082/spring-katharsis +katharsis.pathPrefix=/ \ No newline at end of file From b22cd9e63bf3e35d8fac1b9351dc729388c04b48 Mon Sep 17 00:00:00 2001 From: jjangga0214 Date: Sat, 9 Jun 2018 01:24:04 +0900 Subject: [PATCH 07/84] fix mistyped word (#4408) --- .../main/java/com/baeldung/algorithms/mcts/tictactoe/Board.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/algorithms/src/main/java/com/baeldung/algorithms/mcts/tictactoe/Board.java b/algorithms/src/main/java/com/baeldung/algorithms/mcts/tictactoe/Board.java index 8b47fa0fdf..5ca2d626f1 100644 --- a/algorithms/src/main/java/com/baeldung/algorithms/mcts/tictactoe/Board.java +++ b/algorithms/src/main/java/com/baeldung/algorithms/mcts/tictactoe/Board.java @@ -148,7 +148,7 @@ public class Board { System.out.println("Game Draw"); break; case IN_PROGRESS: - System.out.println("Game In rogress"); + System.out.println("Game In Progress"); break; } } From 8bba7874b027c4c6db710cb2d29fcad01e34f386 Mon Sep 17 00:00:00 2001 From: Grzegorz Piwowarek Date: Fri, 8 Jun 2018 18:24:22 +0200 Subject: [PATCH 08/84] Update JavaReadFromFileUnitTest.java (#4404) --- .../java/org/baeldung/java/io/JavaReadFromFileUnitTest.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core-java-io/src/test/java/org/baeldung/java/io/JavaReadFromFileUnitTest.java b/core-java-io/src/test/java/org/baeldung/java/io/JavaReadFromFileUnitTest.java index 0945a21b1b..a96232d66c 100644 --- a/core-java-io/src/test/java/org/baeldung/java/io/JavaReadFromFileUnitTest.java +++ b/core-java-io/src/test/java/org/baeldung/java/io/JavaReadFromFileUnitTest.java @@ -1,6 +1,7 @@ package org.baeldung.java.io; import org.junit.Test; +import org.junit.Ignore; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -105,6 +106,7 @@ public class JavaReadFromFileUnitTest { } @Test + @Ignore // TODO public void whenReadUTFEncodedFile_thenCorrect() throws IOException { final String expected_value = "青空"; final BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream("src/test/resources/test_read7.in"), "UTF-8")); From 2aa540db03360746350563274afd38436dfb0caf Mon Sep 17 00:00:00 2001 From: Tom Hombergs Date: Fri, 8 Jun 2018 18:24:38 +0200 Subject: [PATCH 09/84] added article link (#4393) --- kotlin-js/README.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 kotlin-js/README.md diff --git a/kotlin-js/README.md b/kotlin-js/README.md new file mode 100644 index 0000000000..9ef8a999b4 --- /dev/null +++ b/kotlin-js/README.md @@ -0,0 +1,3 @@ +### Relevant articles + +- [Kotlin and Javascript](http://www.baeldung.com/kotlin-javascript) From ff967a62b73e1f909b0bb15c04b8790ecd1441be Mon Sep 17 00:00:00 2001 From: Tom Hombergs Date: Fri, 8 Jun 2018 18:24:54 +0200 Subject: [PATCH 10/84] added link (#4357) --- core-java/README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/core-java/README.md b/core-java/README.md index 9bc7d9f7ee..484b788974 100644 --- a/core-java/README.md +++ b/core-java/README.md @@ -141,6 +141,7 @@ - [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) +- [Infinite Loops in Java](http://www.baeldung.com/infinite-loops-java) - [Using Java Assertions](http://www.baeldung.com/java-assert) - [Pass-By-Value as a Parameter Passing Mechanism in Java](http://www.baeldung.com/java-pass-by-value-or-pass-by-reference) - [Check If a String Is Numeric in Java](http://www.baeldung.com/java-check-string-number) @@ -149,5 +150,3 @@ - [NaN in Java](http://www.baeldung.com/java-not-a-number) - [Infinite Loops in Java](http://www.baeldung.com/infinite-loops-java) - [Why Use char[] Array Over a String for Storing Passwords in Java?](http://www.baeldung.com/java-storing-passwords) - - From b2fc0d7bde41c834708ff395ed81658f081d484f Mon Sep 17 00:00:00 2001 From: Grzegorz Piwowarek Date: Fri, 8 Jun 2018 18:25:08 +0200 Subject: [PATCH 11/84] Update README.md (#4330) --- README.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/README.md b/README.md index 6dff78aa7a..62d2d5b55e 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,3 @@ 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) -- [Java Service Provider Interface](http://www.baeldung.com/java-spi) -- [Java Streams vs Vavr Streams](http://www.baeldung.com/vavr-java-streams) From f88d03500040481240ec826bad15ba62ef391ba9 Mon Sep 17 00:00:00 2001 From: Eugen Paraschiv Date: Fri, 8 Jun 2018 20:43:24 +0300 Subject: [PATCH 12/84] alinging the module name, artifact id and folder name (and some minor cleanup) --- animal-sniffer-mvn-plugin/pom.xml | 2 +- camel-api/pom.xml | 1 - ejb/ejb-client/pom.xml | 1 - grpc/pom.xml | 2 -- guest/spring-mvc/pom.xml | 22 ---------------------- guest/spring-security/pom.xml | 22 ---------------------- java-websocket/pom.xml | 2 -- xmlunit-2/pom.xml | 1 - 8 files changed, 1 insertion(+), 52 deletions(-) diff --git a/animal-sniffer-mvn-plugin/pom.xml b/animal-sniffer-mvn-plugin/pom.xml index ab7b38f6e0..9ccc7354af 100644 --- a/animal-sniffer-mvn-plugin/pom.xml +++ b/animal-sniffer-mvn-plugin/pom.xml @@ -5,7 +5,7 @@ animal-sniffer-mvn-plugin jar 1.0-SNAPSHOT - example-animal-sniffer-mvn-plugin + animal-sniffer-mvn-plugin http://maven.apache.org diff --git a/camel-api/pom.xml b/camel-api/pom.xml index 86f6713cd6..4e50828b96 100644 --- a/camel-api/pom.xml +++ b/camel-api/pom.xml @@ -5,7 +5,6 @@ com.example spring-boot-camel 0.0.1-SNAPSHOT - Spring-Boot - Camel API com.baeldung diff --git a/ejb/ejb-client/pom.xml b/ejb/ejb-client/pom.xml index 83dd0aef30..88116f8003 100755 --- a/ejb/ejb-client/pom.xml +++ b/ejb/ejb-client/pom.xml @@ -3,7 +3,6 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 4.0.0 ejb-client - EJB3 Client Maven EJB3 Client Maven diff --git a/grpc/pom.xml b/grpc/pom.xml index ad563f16fd..fb8312e8df 100644 --- a/grpc/pom.xml +++ b/grpc/pom.xml @@ -5,8 +5,6 @@ grpc-demo 0.0.1-SNAPSHOT jar - grpc-demo - http://maven.apache.org com.baeldung diff --git a/guest/spring-mvc/pom.xml b/guest/spring-mvc/pom.xml index 169b216ff9..da4d27b14d 100644 --- a/guest/spring-mvc/pom.xml +++ b/guest/spring-mvc/pom.xml @@ -27,28 +27,6 @@ - - - spring-milestones - Spring Milestones - https://repo.spring.io/milestone - - false - - - - - - - spring-milestones - Spring Milestones - https://repo.spring.io/milestone - - false - - - - UTF-8 UTF-8 diff --git a/guest/spring-security/pom.xml b/guest/spring-security/pom.xml index 16e946d108..793df750de 100644 --- a/guest/spring-security/pom.xml +++ b/guest/spring-security/pom.xml @@ -45,28 +45,6 @@ - - - spring-milestones - Spring Milestones - https://repo.spring.io/milestone - - false - - - - - - - spring-milestones - Spring Milestones - https://repo.spring.io/milestone - - false - - - - UTF-8 UTF-8 diff --git a/java-websocket/pom.xml b/java-websocket/pom.xml index 461182e504..85078bd696 100644 --- a/java-websocket/pom.xml +++ b/java-websocket/pom.xml @@ -5,8 +5,6 @@ java-websocket war 0.0.1-SNAPSHOT - java-websocket Maven Webapp - http://maven.apache.org com.baeldung diff --git a/xmlunit-2/pom.xml b/xmlunit-2/pom.xml index 171f3de03c..0a32b90af5 100644 --- a/xmlunit-2/pom.xml +++ b/xmlunit-2/pom.xml @@ -4,7 +4,6 @@ com.baeldung xmlunit-2 1.0 - XMLUnit-2 com.baeldung From 2efdeed00f9db12eedc5ab7165cc8661359317a6 Mon Sep 17 00:00:00 2001 From: Eugen Paraschiv Date: Fri, 8 Jun 2018 21:04:03 +0300 Subject: [PATCH 13/84] changing parent name --- ethereumj/pom.xml | 4 ++-- flips/pom.xml | 4 ++-- flyway/pom.xml | 4 ++-- hystrix/pom.xml | 4 ++-- jhipster/jhipster-microservice/car-app/pom.xml | 4 ++-- jhipster/jhipster-microservice/dealer-app/pom.xml | 4 ++-- jhipster/jhipster-microservice/gateway-app/pom.xml | 4 ++-- jhipster/jhipster-monolithic/pom.xml | 4 ++-- jjwt/pom.xml | 4 ++-- jmeter/pom.xml | 4 ++-- mesos-marathon/pom.xml | 4 ++-- mvn-wrapper/pom.xml | 4 ++-- {parent-boot-5 => parent-boot-1}/README.md | 0 {parent-boot-5 => parent-boot-1}/pom.xml | 7 +++---- persistence-modules/spring-data-dynamodb/pom.xml | 4 ++-- pom.xml | 2 +- spring-all/pom.xml | 4 ++-- spring-amqp-simple/pom.xml | 4 ++-- spring-aop/pom.xml | 4 ++-- .../greeter-spring-boot-autoconfigure/pom.xml | 4 ++-- .../greeter-spring-boot-sample-app/pom.xml | 4 ++-- .../greeter-spring-boot-starter/pom.xml | 4 ++-- spring-boot-custom-starter/greeter/pom.xml | 4 ++-- spring-boot-keycloak/pom.xml | 4 ++-- .../property-exp-default-config/pom.xml | 4 ++-- spring-cloud-data-flow/batch-job/pom.xml | 4 ++-- spring-cloud-data-flow/data-flow-server/pom.xml | 4 ++-- spring-cloud-data-flow/data-flow-shell/pom.xml | 4 ++-- spring-cloud-data-flow/log-sink/pom.xml | 4 ++-- spring-cloud-data-flow/time-processor/pom.xml | 4 ++-- spring-cloud-data-flow/time-source/pom.xml | 4 ++-- spring-cloud/spring-cloud-bootstrap/config/pom.xml | 4 ++-- spring-cloud/spring-cloud-bootstrap/discovery/pom.xml | 4 ++-- spring-cloud/spring-cloud-bootstrap/gateway/pom.xml | 4 ++-- spring-cloud/spring-cloud-bootstrap/svc-book/pom.xml | 4 ++-- spring-cloud/spring-cloud-bootstrap/svc-rating/pom.xml | 4 ++-- spring-cloud/spring-cloud-bootstrap/zipkin/pom.xml | 4 ++-- spring-cloud/spring-cloud-config/pom.xml | 4 ++-- spring-cloud/spring-cloud-kubernetes/pom.xml | 4 ++-- .../spring-cloud-rest/spring-cloud-rest-books-api/pom.xml | 4 ++-- .../spring-cloud-rest-config-server/pom.xml | 4 ++-- .../spring-cloud-rest-discovery-server/pom.xml | 4 ++-- .../spring-cloud-rest-reviews-api/pom.xml | 4 ++-- spring-cloud/spring-cloud-ribbon-client/pom.xml | 4 ++-- spring-cucumber/pom.xml | 4 ++-- spring-custom-aop/pom.xml | 4 ++-- spring-data-rest/pom.xml | 4 ++-- spring-data-spring-security/pom.xml | 4 ++-- spring-ejb/spring-ejb-client/pom.xml | 4 ++-- spring-jenkins-pipeline/pom.xml | 4 ++-- spring-kafka/pom.xml | 4 ++-- spring-katharsis/pom.xml | 4 ++-- spring-mobile/pom.xml | 4 ++-- spring-mockito/pom.xml | 4 ++-- spring-mvc-email/pom.xml | 4 ++-- spring-mvc-java/pom.xml | 4 ++-- spring-protobuf/pom.xml | 4 ++-- spring-quartz/pom.xml | 4 ++-- spring-reactor/pom.xml | 4 ++-- spring-remoting/pom.xml | 4 ++-- spring-rest-angular/pom.xml | 4 ++-- spring-rest-full/pom.xml | 4 ++-- spring-rest-query-language/pom.xml | 4 ++-- spring-security-acl/pom.xml | 4 ++-- spring-security-cache-control/pom.xml | 4 ++-- .../spring-security-jsp-authentication/pom.xml | 4 ++-- .../spring-security-jsp-authorize/pom.xml | 4 ++-- spring-security-client/spring-security-jsp-config/pom.xml | 4 ++-- spring-security-client/spring-security-mvc/pom.xml | 4 ++-- .../spring-security-thymeleaf-authentication/pom.xml | 4 ++-- .../spring-security-thymeleaf-authorize/pom.xml | 4 ++-- .../spring-security-thymeleaf-config/pom.xml | 4 ++-- spring-security-core/pom.xml | 4 ++-- spring-security-mvc-ldap/pom.xml | 4 ++-- spring-security-rest-custom/pom.xml | 4 ++-- spring-security-sso/pom.xml | 4 ++-- spring-security-stormpath/pom.xml | 4 ++-- spring-security-thymeleaf/pom.xml | 4 ++-- spring-security-x509/pom.xml | 4 ++-- spring-session/pom.xml | 4 ++-- spring-sleuth/pom.xml | 4 ++-- spring-social-login/pom.xml | 4 ++-- spring-zuul/pom.xml | 4 ++-- stripe/pom.xml | 4 ++-- 84 files changed, 166 insertions(+), 167 deletions(-) rename {parent-boot-5 => parent-boot-1}/README.md (100%) rename {parent-boot-5 => parent-boot-1}/pom.xml (96%) diff --git a/ethereumj/pom.xml b/ethereumj/pom.xml index 611b7b09eb..6917505f1b 100644 --- a/ethereumj/pom.xml +++ b/ethereumj/pom.xml @@ -10,10 +10,10 @@ ethereumj - parent-boot-5 + parent-boot-1 com.baeldung 0.0.1-SNAPSHOT - ../parent-boot-5 + ../parent-boot-1 diff --git a/flips/pom.xml b/flips/pom.xml index be9f584114..34cbab7035 100644 --- a/flips/pom.xml +++ b/flips/pom.xml @@ -8,10 +8,10 @@ flips - parent-boot-5 + parent-boot-1 com.baeldung 0.0.1-SNAPSHOT - ../parent-boot-5 + ../parent-boot-1 diff --git a/flyway/pom.xml b/flyway/pom.xml index 3637f1de28..018f9b7f86 100644 --- a/flyway/pom.xml +++ b/flyway/pom.xml @@ -8,10 +8,10 @@ Flyway Callbacks Demo - parent-boot-5 + parent-boot-1 com.baeldung 0.0.1-SNAPSHOT - ../parent-boot-5 + ../parent-boot-1 diff --git a/hystrix/pom.xml b/hystrix/pom.xml index 8e4a9b28b7..b17ca2bfd9 100644 --- a/hystrix/pom.xml +++ b/hystrix/pom.xml @@ -6,10 +6,10 @@ hystrix - parent-boot-5 + parent-boot-1 com.baeldung 0.0.1-SNAPSHOT - ../parent-boot-5 + ../parent-boot-1 diff --git a/jhipster/jhipster-microservice/car-app/pom.xml b/jhipster/jhipster-microservice/car-app/pom.xml index 77e214234e..e5593bdbb9 100644 --- a/jhipster/jhipster-microservice/car-app/pom.xml +++ b/jhipster/jhipster-microservice/car-app/pom.xml @@ -3,10 +3,10 @@ 4.0.0 - parent-boot-5 + parent-boot-1 com.baeldung 0.0.1-SNAPSHOT - ../../../parent-boot-5 + ../../../parent-boot-1 com.car.app diff --git a/jhipster/jhipster-microservice/dealer-app/pom.xml b/jhipster/jhipster-microservice/dealer-app/pom.xml index beada8f064..3c21e0042f 100644 --- a/jhipster/jhipster-microservice/dealer-app/pom.xml +++ b/jhipster/jhipster-microservice/dealer-app/pom.xml @@ -3,10 +3,10 @@ 4.0.0 - parent-boot-5 + parent-boot-1 com.baeldung 0.0.1-SNAPSHOT - ../../../parent-boot-5 + ../../../parent-boot-1 com.dealer.app diff --git a/jhipster/jhipster-microservice/gateway-app/pom.xml b/jhipster/jhipster-microservice/gateway-app/pom.xml index d90addf51b..42808e26ce 100644 --- a/jhipster/jhipster-microservice/gateway-app/pom.xml +++ b/jhipster/jhipster-microservice/gateway-app/pom.xml @@ -3,10 +3,10 @@ 4.0.0 - parent-boot-5 + parent-boot-1 com.baeldung 0.0.1-SNAPSHOT - ../../../parent-boot-5 + ../../../parent-boot-1 com.gateway diff --git a/jhipster/jhipster-monolithic/pom.xml b/jhipster/jhipster-monolithic/pom.xml index fc8e8353b4..c8c9578fd6 100644 --- a/jhipster/jhipster-monolithic/pom.xml +++ b/jhipster/jhipster-monolithic/pom.xml @@ -3,10 +3,10 @@ 4.0.0 - parent-boot-5 + parent-boot-1 com.baeldung 0.0.1-SNAPSHOT - ../../parent-boot-5 + ../../parent-boot-1 com.baeldung diff --git a/jjwt/pom.xml b/jjwt/pom.xml index 51d4dcf1c0..2aa52b8818 100644 --- a/jjwt/pom.xml +++ b/jjwt/pom.xml @@ -10,10 +10,10 @@ Exercising the JJWT - parent-boot-5 + parent-boot-1 com.baeldung 0.0.1-SNAPSHOT - ../parent-boot-5 + ../parent-boot-1 diff --git a/jmeter/pom.xml b/jmeter/pom.xml index bb5769ef57..5f9509f0be 100644 --- a/jmeter/pom.xml +++ b/jmeter/pom.xml @@ -9,10 +9,10 @@ Intro to Performance testing using JMeter - parent-boot-5 + parent-boot-1 com.baeldung 0.0.1-SNAPSHOT - ../parent-boot-5 + ../parent-boot-1 diff --git a/mesos-marathon/pom.xml b/mesos-marathon/pom.xml index 2b7a238ee8..77d13cd5c6 100644 --- a/mesos-marathon/pom.xml +++ b/mesos-marathon/pom.xml @@ -7,10 +7,10 @@ 0.0.1-SNAPSHOT - parent-boot-5 + parent-boot-1 com.baeldung 0.0.1-SNAPSHOT - ../parent-boot-5 + ../parent-boot-1 diff --git a/mvn-wrapper/pom.xml b/mvn-wrapper/pom.xml index 6fb9bfeffc..e26df81139 100644 --- a/mvn-wrapper/pom.xml +++ b/mvn-wrapper/pom.xml @@ -9,10 +9,10 @@ Setting up the Maven Wrapper - parent-boot-5 + parent-boot-1 com.baeldung 0.0.1-SNAPSHOT - ../parent-boot-5 + ../parent-boot-1 diff --git a/parent-boot-5/README.md b/parent-boot-1/README.md similarity index 100% rename from parent-boot-5/README.md rename to parent-boot-1/README.md diff --git a/parent-boot-5/pom.xml b/parent-boot-1/pom.xml similarity index 96% rename from parent-boot-5/pom.xml rename to parent-boot-1/pom.xml index 32bb2eab04..af14d88aff 100644 --- a/parent-boot-5/pom.xml +++ b/parent-boot-1/pom.xml @@ -2,16 +2,15 @@ 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 - parent-boot-5 + parent-boot-1 0.0.1-SNAPSHOT pom - Parent Boot 5 - Parent for all spring boot 1.5 modules + Parent for all Spring Boot 1.x modules org.springframework.boot spring-boot-starter-parent - 1.5.10.RELEASE + 1.5.13.RELEASE diff --git a/persistence-modules/spring-data-dynamodb/pom.xml b/persistence-modules/spring-data-dynamodb/pom.xml index b115c0e087..b1b7c8237b 100644 --- a/persistence-modules/spring-data-dynamodb/pom.xml +++ b/persistence-modules/spring-data-dynamodb/pom.xml @@ -9,10 +9,10 @@ This is simple boot application for Spring boot actuator test - parent-boot-5 + parent-boot-1 com.baeldung 0.0.1-SNAPSHOT - ../../parent-boot-5 + ../../parent-boot-1 diff --git a/pom.xml b/pom.xml index ed724f7142..f7b065722f 100644 --- a/pom.xml +++ b/pom.xml @@ -9,7 +9,7 @@ pom - parent-boot-5 + parent-boot-1 parent-boot-2 parent-spring-4 parent-spring-5 diff --git a/spring-all/pom.xml b/spring-all/pom.xml index f9ced963e7..c509622fca 100644 --- a/spring-all/pom.xml +++ b/spring-all/pom.xml @@ -8,10 +8,10 @@ war - parent-boot-5 + parent-boot-1 com.baeldung 0.0.1-SNAPSHOT - ../parent-boot-5 + ../parent-boot-1 diff --git a/spring-amqp-simple/pom.xml b/spring-amqp-simple/pom.xml index f3dfbccaec..eb0f25d1a7 100644 --- a/spring-amqp-simple/pom.xml +++ b/spring-amqp-simple/pom.xml @@ -8,10 +8,10 @@ Spring AMQP Simple App - parent-boot-5 + parent-boot-1 com.baeldung 0.0.1-SNAPSHOT - ../parent-boot-5 + ../parent-boot-1 diff --git a/spring-aop/pom.xml b/spring-aop/pom.xml index 7cdf9bd7cc..0f4e08baa3 100644 --- a/spring-aop/pom.xml +++ b/spring-aop/pom.xml @@ -8,10 +8,10 @@ spring-aop - parent-boot-5 + parent-boot-1 com.baeldung 0.0.1-SNAPSHOT - ../parent-boot-5 + ../parent-boot-1 diff --git a/spring-boot-custom-starter/greeter-spring-boot-autoconfigure/pom.xml b/spring-boot-custom-starter/greeter-spring-boot-autoconfigure/pom.xml index 6ae6572ca9..96647ea0f1 100644 --- a/spring-boot-custom-starter/greeter-spring-boot-autoconfigure/pom.xml +++ b/spring-boot-custom-starter/greeter-spring-boot-autoconfigure/pom.xml @@ -6,10 +6,10 @@ greeter-spring-boot-autoconfigure 0.0.1-SNAPSHOT - parent-boot-5 + parent-boot-1 com.baeldung 0.0.1-SNAPSHOT - ../../parent-boot-5 + ../../parent-boot-1 UTF-8 diff --git a/spring-boot-custom-starter/greeter-spring-boot-sample-app/pom.xml b/spring-boot-custom-starter/greeter-spring-boot-sample-app/pom.xml index 9db76759ec..a2c96a8555 100644 --- a/spring-boot-custom-starter/greeter-spring-boot-sample-app/pom.xml +++ b/spring-boot-custom-starter/greeter-spring-boot-sample-app/pom.xml @@ -7,10 +7,10 @@ 0.0.1-SNAPSHOT - parent-boot-5 + parent-boot-1 com.baeldung 0.0.1-SNAPSHOT - ../../parent-boot-5 + ../../parent-boot-1 diff --git a/spring-boot-custom-starter/greeter-spring-boot-starter/pom.xml b/spring-boot-custom-starter/greeter-spring-boot-starter/pom.xml index e771cbaa8d..7bf13eebc8 100644 --- a/spring-boot-custom-starter/greeter-spring-boot-starter/pom.xml +++ b/spring-boot-custom-starter/greeter-spring-boot-starter/pom.xml @@ -6,10 +6,10 @@ greeter-spring-boot-starter 0.0.1-SNAPSHOT - parent-boot-5 + parent-boot-1 com.baeldung 0.0.1-SNAPSHOT - ../../parent-boot-5 + ../../parent-boot-1 UTF-8 diff --git a/spring-boot-custom-starter/greeter/pom.xml b/spring-boot-custom-starter/greeter/pom.xml index 6143992088..aa45b8e6a4 100644 --- a/spring-boot-custom-starter/greeter/pom.xml +++ b/spring-boot-custom-starter/greeter/pom.xml @@ -6,9 +6,9 @@ greeter 0.0.1-SNAPSHOT - parent-boot-5 + parent-boot-1 com.baeldung 0.0.1-SNAPSHOT - ../../parent-boot-5 + ../../parent-boot-1 \ No newline at end of file diff --git a/spring-boot-keycloak/pom.xml b/spring-boot-keycloak/pom.xml index d2df261b2f..b7b15935ec 100644 --- a/spring-boot-keycloak/pom.xml +++ b/spring-boot-keycloak/pom.xml @@ -11,9 +11,9 @@ com.baeldung - parent-boot-5 + parent-boot-1 0.0.1-SNAPSHOT - ../parent-boot-5 + ../parent-boot-1 diff --git a/spring-boot-property-exp/property-exp-default-config/pom.xml b/spring-boot-property-exp/property-exp-default-config/pom.xml index e4cbaebf56..0ac4a31c7c 100644 --- a/spring-boot-property-exp/property-exp-default-config/pom.xml +++ b/spring-boot-property-exp/property-exp-default-config/pom.xml @@ -8,10 +8,10 @@ jar - parent-boot-5 + parent-boot-1 com.baeldung 0.0.1-SNAPSHOT - ../../parent-boot-5 + ../../parent-boot-1 diff --git a/spring-cloud-data-flow/batch-job/pom.xml b/spring-cloud-data-flow/batch-job/pom.xml index 123c4aeda6..08439065a4 100644 --- a/spring-cloud-data-flow/batch-job/pom.xml +++ b/spring-cloud-data-flow/batch-job/pom.xml @@ -12,10 +12,10 @@ Demo project for Spring Boot - parent-boot-5 + parent-boot-1 com.baeldung 0.0.1-SNAPSHOT - ../../parent-boot-5 + ../../parent-boot-1 diff --git a/spring-cloud-data-flow/data-flow-server/pom.xml b/spring-cloud-data-flow/data-flow-server/pom.xml index f0d513ce4d..1b81e1ba2d 100644 --- a/spring-cloud-data-flow/data-flow-server/pom.xml +++ b/spring-cloud-data-flow/data-flow-server/pom.xml @@ -12,10 +12,10 @@ Demo project for Spring Boot - parent-boot-5 + parent-boot-1 com.baeldung 0.0.1-SNAPSHOT - ../../parent-boot-5 + ../../parent-boot-1 diff --git a/spring-cloud-data-flow/data-flow-shell/pom.xml b/spring-cloud-data-flow/data-flow-shell/pom.xml index debbe44a4a..0166aa79c2 100644 --- a/spring-cloud-data-flow/data-flow-shell/pom.xml +++ b/spring-cloud-data-flow/data-flow-shell/pom.xml @@ -12,10 +12,10 @@ Demo project for Spring Boot - parent-boot-5 + parent-boot-1 com.baeldung 0.0.1-SNAPSHOT - ../../parent-boot-5 + ../../parent-boot-1 diff --git a/spring-cloud-data-flow/log-sink/pom.xml b/spring-cloud-data-flow/log-sink/pom.xml index 6e541ae3fa..ab367fadd7 100644 --- a/spring-cloud-data-flow/log-sink/pom.xml +++ b/spring-cloud-data-flow/log-sink/pom.xml @@ -12,10 +12,10 @@ Demo project for Spring Boot - parent-boot-5 + parent-boot-1 com.baeldung 0.0.1-SNAPSHOT - ../../parent-boot-5 + ../../parent-boot-1 diff --git a/spring-cloud-data-flow/time-processor/pom.xml b/spring-cloud-data-flow/time-processor/pom.xml index 42d0fa434f..79bae89857 100644 --- a/spring-cloud-data-flow/time-processor/pom.xml +++ b/spring-cloud-data-flow/time-processor/pom.xml @@ -12,10 +12,10 @@ Demo project for Spring Boot - parent-boot-5 + parent-boot-1 com.baeldung 0.0.1-SNAPSHOT - ../../parent-boot-5 + ../../parent-boot-1 diff --git a/spring-cloud-data-flow/time-source/pom.xml b/spring-cloud-data-flow/time-source/pom.xml index 2a50c9b0d0..17d2f5c693 100644 --- a/spring-cloud-data-flow/time-source/pom.xml +++ b/spring-cloud-data-flow/time-source/pom.xml @@ -12,10 +12,10 @@ Demo project for Spring Boot - parent-boot-5 + parent-boot-1 com.baeldung 0.0.1-SNAPSHOT - ../../parent-boot-5 + ../../parent-boot-1 diff --git a/spring-cloud/spring-cloud-bootstrap/config/pom.xml b/spring-cloud/spring-cloud-bootstrap/config/pom.xml index ace46395c0..14a926fc2c 100644 --- a/spring-cloud/spring-cloud-bootstrap/config/pom.xml +++ b/spring-cloud/spring-cloud-bootstrap/config/pom.xml @@ -6,10 +6,10 @@ 1.0.0-SNAPSHOT - parent-boot-5 + parent-boot-1 com.baeldung 0.0.1-SNAPSHOT - ../../../parent-boot-5 + ../../../parent-boot-1 diff --git a/spring-cloud/spring-cloud-bootstrap/discovery/pom.xml b/spring-cloud/spring-cloud-bootstrap/discovery/pom.xml index 7a3ffd81cd..f94d8829f6 100644 --- a/spring-cloud/spring-cloud-bootstrap/discovery/pom.xml +++ b/spring-cloud/spring-cloud-bootstrap/discovery/pom.xml @@ -7,10 +7,10 @@ 1.0.0-SNAPSHOT - parent-boot-5 + parent-boot-1 com.baeldung 0.0.1-SNAPSHOT - ../../../parent-boot-5 + ../../../parent-boot-1 diff --git a/spring-cloud/spring-cloud-bootstrap/gateway/pom.xml b/spring-cloud/spring-cloud-bootstrap/gateway/pom.xml index 5001b35fb5..fc69c16738 100644 --- a/spring-cloud/spring-cloud-bootstrap/gateway/pom.xml +++ b/spring-cloud/spring-cloud-bootstrap/gateway/pom.xml @@ -6,10 +6,10 @@ 1.0.0-SNAPSHOT - parent-boot-5 + parent-boot-1 com.baeldung 0.0.1-SNAPSHOT - ../../../parent-boot-5 + ../../../parent-boot-1 diff --git a/spring-cloud/spring-cloud-bootstrap/svc-book/pom.xml b/spring-cloud/spring-cloud-bootstrap/svc-book/pom.xml index 2552752e29..c0d920d373 100644 --- a/spring-cloud/spring-cloud-bootstrap/svc-book/pom.xml +++ b/spring-cloud/spring-cloud-bootstrap/svc-book/pom.xml @@ -8,10 +8,10 @@ 1.0.0-SNAPSHOT - parent-boot-5 + parent-boot-1 com.baeldung 0.0.1-SNAPSHOT - ../../../parent-boot-5 + ../../../parent-boot-1 diff --git a/spring-cloud/spring-cloud-bootstrap/svc-rating/pom.xml b/spring-cloud/spring-cloud-bootstrap/svc-rating/pom.xml index 857ee486c0..3aa2db8f65 100644 --- a/spring-cloud/spring-cloud-bootstrap/svc-rating/pom.xml +++ b/spring-cloud/spring-cloud-bootstrap/svc-rating/pom.xml @@ -8,10 +8,10 @@ 1.0.0-SNAPSHOT - parent-boot-5 + parent-boot-1 com.baeldung 0.0.1-SNAPSHOT - ../../../parent-boot-5 + ../../../parent-boot-1 diff --git a/spring-cloud/spring-cloud-bootstrap/zipkin/pom.xml b/spring-cloud/spring-cloud-bootstrap/zipkin/pom.xml index 743281d346..8735e24d48 100644 --- a/spring-cloud/spring-cloud-bootstrap/zipkin/pom.xml +++ b/spring-cloud/spring-cloud-bootstrap/zipkin/pom.xml @@ -6,10 +6,10 @@ 1.0.0-SNAPSHOT - parent-boot-5 + parent-boot-1 com.baeldung 0.0.1-SNAPSHOT - ../../../parent-boot-5 + ../../../parent-boot-1 diff --git a/spring-cloud/spring-cloud-config/pom.xml b/spring-cloud/spring-cloud-config/pom.xml index 100b421a55..0a8f4f9dc3 100644 --- a/spring-cloud/spring-cloud-config/pom.xml +++ b/spring-cloud/spring-cloud-config/pom.xml @@ -9,10 +9,10 @@ pom - parent-boot-5 + parent-boot-1 com.baeldung 0.0.1-SNAPSHOT - ../../parent-boot-5 + ../../parent-boot-1 diff --git a/spring-cloud/spring-cloud-kubernetes/pom.xml b/spring-cloud/spring-cloud-kubernetes/pom.xml index 96388c3672..61fd84ca27 100644 --- a/spring-cloud/spring-cloud-kubernetes/pom.xml +++ b/spring-cloud/spring-cloud-kubernetes/pom.xml @@ -14,10 +14,10 @@ - parent-boot-5 + parent-boot-1 com.baeldung 0.0.1-SNAPSHOT - ../../parent-boot-5 + ../../parent-boot-1 4.0.0 diff --git a/spring-cloud/spring-cloud-rest/spring-cloud-rest-books-api/pom.xml b/spring-cloud/spring-cloud-rest/spring-cloud-rest-books-api/pom.xml index 8da8ef6141..664ab96576 100644 --- a/spring-cloud/spring-cloud-rest/spring-cloud-rest-books-api/pom.xml +++ b/spring-cloud/spring-cloud-rest/spring-cloud-rest-books-api/pom.xml @@ -10,10 +10,10 @@ Simple books API - parent-boot-5 + parent-boot-1 com.baeldung 0.0.1-SNAPSHOT - ../../../parent-boot-5 + ../../../parent-boot-1 diff --git a/spring-cloud/spring-cloud-rest/spring-cloud-rest-config-server/pom.xml b/spring-cloud/spring-cloud-rest/spring-cloud-rest-config-server/pom.xml index e083986890..814f5edfcb 100644 --- a/spring-cloud/spring-cloud-rest/spring-cloud-rest-config-server/pom.xml +++ b/spring-cloud/spring-cloud-rest/spring-cloud-rest-config-server/pom.xml @@ -12,10 +12,10 @@ Spring Cloud REST configuration server - parent-boot-5 + parent-boot-1 com.baeldung 0.0.1-SNAPSHOT - ../../../parent-boot-5 + ../../../parent-boot-1 diff --git a/spring-cloud/spring-cloud-rest/spring-cloud-rest-discovery-server/pom.xml b/spring-cloud/spring-cloud-rest/spring-cloud-rest-discovery-server/pom.xml index c7d647a154..f3ce213540 100644 --- a/spring-cloud/spring-cloud-rest/spring-cloud-rest-discovery-server/pom.xml +++ b/spring-cloud/spring-cloud-rest/spring-cloud-rest-discovery-server/pom.xml @@ -10,10 +10,10 @@ Spring Cloud REST server - parent-boot-5 + parent-boot-1 com.baeldung 0.0.1-SNAPSHOT - ../../../parent-boot-5 + ../../../parent-boot-1 diff --git a/spring-cloud/spring-cloud-rest/spring-cloud-rest-reviews-api/pom.xml b/spring-cloud/spring-cloud-rest/spring-cloud-rest-reviews-api/pom.xml index d97ab43bfe..27e327110a 100644 --- a/spring-cloud/spring-cloud-rest/spring-cloud-rest-reviews-api/pom.xml +++ b/spring-cloud/spring-cloud-rest/spring-cloud-rest-reviews-api/pom.xml @@ -10,10 +10,10 @@ Simple reviews API - parent-boot-5 + parent-boot-1 com.baeldung 0.0.1-SNAPSHOT - ../../../parent-boot-5 + ../../../parent-boot-1 diff --git a/spring-cloud/spring-cloud-ribbon-client/pom.xml b/spring-cloud/spring-cloud-ribbon-client/pom.xml index cada10ec35..64682c6173 100644 --- a/spring-cloud/spring-cloud-ribbon-client/pom.xml +++ b/spring-cloud/spring-cloud-ribbon-client/pom.xml @@ -9,10 +9,10 @@ Introduction to Spring Cloud Rest Client with Netflix Ribbon - parent-boot-5 + parent-boot-1 com.baeldung 0.0.1-SNAPSHOT - ../../parent-boot-5 + ../../parent-boot-1 diff --git a/spring-cucumber/pom.xml b/spring-cucumber/pom.xml index cabd1a9020..1da4c8a124 100644 --- a/spring-cucumber/pom.xml +++ b/spring-cucumber/pom.xml @@ -10,10 +10,10 @@ Demo project for Spring Boot - parent-boot-5 + parent-boot-1 com.baeldung 0.0.1-SNAPSHOT - ../parent-boot-5 + ../parent-boot-1 diff --git a/spring-custom-aop/pom.xml b/spring-custom-aop/pom.xml index 76d8e7c344..4e95d175e7 100644 --- a/spring-custom-aop/pom.xml +++ b/spring-custom-aop/pom.xml @@ -9,10 +9,10 @@ This is simple boot application for Spring boot actuator test - parent-boot-5 + parent-boot-1 com.baeldung 0.0.1-SNAPSHOT - ../parent-boot-5 + ../parent-boot-1 diff --git a/spring-data-rest/pom.xml b/spring-data-rest/pom.xml index bad7a38281..0e525474e3 100644 --- a/spring-data-rest/pom.xml +++ b/spring-data-rest/pom.xml @@ -10,10 +10,10 @@ Intro to Spring Data REST - parent-boot-5 + parent-boot-1 com.baeldung 0.0.1-SNAPSHOT - ../parent-boot-5 + ../parent-boot-1 diff --git a/spring-data-spring-security/pom.xml b/spring-data-spring-security/pom.xml index afdf3c332c..467c38284d 100644 --- a/spring-data-spring-security/pom.xml +++ b/spring-data-spring-security/pom.xml @@ -11,10 +11,10 @@ Spring Data with Spring Security - parent-boot-5 + parent-boot-1 com.baeldung 0.0.1-SNAPSHOT - ../parent-boot-5 + ../parent-boot-1 diff --git a/spring-ejb/spring-ejb-client/pom.xml b/spring-ejb/spring-ejb-client/pom.xml index f7b42212be..941105a220 100644 --- a/spring-ejb/spring-ejb-client/pom.xml +++ b/spring-ejb/spring-ejb-client/pom.xml @@ -11,9 +11,9 @@ com.baeldung - parent-boot-5 + parent-boot-1 0.0.1-SNAPSHOT - ../../parent-boot-5 + ../../parent-boot-1 diff --git a/spring-jenkins-pipeline/pom.xml b/spring-jenkins-pipeline/pom.xml index c43952e277..6d26d18f96 100644 --- a/spring-jenkins-pipeline/pom.xml +++ b/spring-jenkins-pipeline/pom.xml @@ -9,10 +9,10 @@ Intro to Jenkins 2 and the power of pipelines - parent-boot-5 + parent-boot-1 com.baeldung 0.0.1-SNAPSHOT - ../parent-boot-5 + ../parent-boot-1 diff --git a/spring-kafka/pom.xml b/spring-kafka/pom.xml index 3891be1ec3..db0d7e6df9 100644 --- a/spring-kafka/pom.xml +++ b/spring-kafka/pom.xml @@ -8,10 +8,10 @@ Intro to Kafka with Spring - parent-boot-5 + parent-boot-1 com.baeldung 0.0.1-SNAPSHOT - ../parent-boot-5 + ../parent-boot-1 diff --git a/spring-katharsis/pom.xml b/spring-katharsis/pom.xml index 8bc75d97b3..6addb614f5 100644 --- a/spring-katharsis/pom.xml +++ b/spring-katharsis/pom.xml @@ -7,10 +7,10 @@ war - parent-boot-5 + parent-boot-1 com.baeldung 0.0.1-SNAPSHOT - ../parent-boot-5 + ../parent-boot-1 diff --git a/spring-mobile/pom.xml b/spring-mobile/pom.xml index 6916bb9320..3d47bb106b 100644 --- a/spring-mobile/pom.xml +++ b/spring-mobile/pom.xml @@ -11,10 +11,10 @@ http://maven.apache.org - parent-boot-5 + parent-boot-1 com.baeldung 0.0.1-SNAPSHOT - ../parent-boot-5 + ../parent-boot-1 diff --git a/spring-mockito/pom.xml b/spring-mockito/pom.xml index 3ddf0fb058..e27e25b4c8 100644 --- a/spring-mockito/pom.xml +++ b/spring-mockito/pom.xml @@ -12,10 +12,10 @@ Injecting Mockito Mocks into Spring Beans - parent-boot-5 + parent-boot-1 com.baeldung 0.0.1-SNAPSHOT - ../parent-boot-5 + ../parent-boot-1 diff --git a/spring-mvc-email/pom.xml b/spring-mvc-email/pom.xml index 436b4155fa..40d83046ef 100644 --- a/spring-mvc-email/pom.xml +++ b/spring-mvc-email/pom.xml @@ -10,10 +10,10 @@ war - parent-boot-5 + parent-boot-1 com.baeldung 0.0.1-SNAPSHOT - ../parent-boot-5 + ../parent-boot-1 diff --git a/spring-mvc-java/pom.xml b/spring-mvc-java/pom.xml index f8d1d32f63..bc81a89bec 100644 --- a/spring-mvc-java/pom.xml +++ b/spring-mvc-java/pom.xml @@ -7,10 +7,10 @@ spring-mvc-java - parent-boot-5 + parent-boot-1 com.baeldung 0.0.1-SNAPSHOT - ../parent-boot-5 + ../parent-boot-1 diff --git a/spring-protobuf/pom.xml b/spring-protobuf/pom.xml index 5081634d9b..1dce122f27 100644 --- a/spring-protobuf/pom.xml +++ b/spring-protobuf/pom.xml @@ -7,10 +7,10 @@ spring-protobuf - parent-boot-5 + parent-boot-1 com.baeldung 0.0.1-SNAPSHOT - ../parent-boot-5 + ../parent-boot-1 diff --git a/spring-quartz/pom.xml b/spring-quartz/pom.xml index 435e571180..2a449ce494 100644 --- a/spring-quartz/pom.xml +++ b/spring-quartz/pom.xml @@ -11,10 +11,10 @@ Demo project for Scheduling in Spring with Quartz - parent-boot-5 + parent-boot-1 com.baeldung 0.0.1-SNAPSHOT - ../parent-boot-5 + ../parent-boot-1 diff --git a/spring-reactor/pom.xml b/spring-reactor/pom.xml index 1098f8b60d..cedaa5e381 100644 --- a/spring-reactor/pom.xml +++ b/spring-reactor/pom.xml @@ -9,10 +9,10 @@ http://maven.apache.org - parent-boot-5 + parent-boot-1 com.baeldung 0.0.1-SNAPSHOT - ../parent-boot-5 + ../parent-boot-1 diff --git a/spring-remoting/pom.xml b/spring-remoting/pom.xml index aac8357c10..150c1a771c 100644 --- a/spring-remoting/pom.xml +++ b/spring-remoting/pom.xml @@ -11,10 +11,10 @@ Parent for all projects related to Spring Remoting. - parent-boot-5 + parent-boot-1 com.baeldung 0.0.1-SNAPSHOT - ../parent-boot-5 + ../parent-boot-1 diff --git a/spring-rest-angular/pom.xml b/spring-rest-angular/pom.xml index 7f3c21801c..090f09de3b 100644 --- a/spring-rest-angular/pom.xml +++ b/spring-rest-angular/pom.xml @@ -9,10 +9,10 @@ war - parent-boot-5 + parent-boot-1 com.baeldung 0.0.1-SNAPSHOT - ../parent-boot-5 + ../parent-boot-1 diff --git a/spring-rest-full/pom.xml b/spring-rest-full/pom.xml index fd2c485eaf..2beff519c0 100644 --- a/spring-rest-full/pom.xml +++ b/spring-rest-full/pom.xml @@ -9,10 +9,10 @@ war - parent-boot-5 + parent-boot-1 com.baeldung 0.0.1-SNAPSHOT - ../parent-boot-5 + ../parent-boot-1 diff --git a/spring-rest-query-language/pom.xml b/spring-rest-query-language/pom.xml index d20a97268b..c16c6b583d 100644 --- a/spring-rest-query-language/pom.xml +++ b/spring-rest-query-language/pom.xml @@ -9,10 +9,10 @@ war - parent-boot-5 + parent-boot-1 com.baeldung 0.0.1-SNAPSHOT - ../parent-boot-5 + ../parent-boot-1 diff --git a/spring-security-acl/pom.xml b/spring-security-acl/pom.xml index 7ddbf66365..88502bd268 100644 --- a/spring-security-acl/pom.xml +++ b/spring-security-acl/pom.xml @@ -11,10 +11,10 @@ Spring Security ACL - parent-boot-5 + parent-boot-1 com.baeldung 0.0.1-SNAPSHOT - ../parent-boot-5 + ../parent-boot-1 diff --git a/spring-security-cache-control/pom.xml b/spring-security-cache-control/pom.xml index 890ff5bd3f..85b8b5a203 100644 --- a/spring-security-cache-control/pom.xml +++ b/spring-security-cache-control/pom.xml @@ -8,10 +8,10 @@ 1.0-SNAPSHOT - parent-boot-5 + parent-boot-1 com.baeldung 0.0.1-SNAPSHOT - ../parent-boot-5 + ../parent-boot-1 diff --git a/spring-security-client/spring-security-jsp-authentication/pom.xml b/spring-security-client/spring-security-jsp-authentication/pom.xml index 9b1ebc6fdc..637fd3dbdb 100644 --- a/spring-security-client/spring-security-jsp-authentication/pom.xml +++ b/spring-security-client/spring-security-jsp-authentication/pom.xml @@ -12,10 +12,10 @@ Spring Security JSP Authentication tag sample - parent-boot-5 + parent-boot-1 com.baeldung 0.0.1-SNAPSHOT - ../../parent-boot-5 + ../../parent-boot-1 diff --git a/spring-security-client/spring-security-jsp-authorize/pom.xml b/spring-security-client/spring-security-jsp-authorize/pom.xml index ee8c9bacbd..94f70ed5f0 100644 --- a/spring-security-client/spring-security-jsp-authorize/pom.xml +++ b/spring-security-client/spring-security-jsp-authorize/pom.xml @@ -12,10 +12,10 @@ Spring Security JSP Authorize tag sample - parent-boot-5 + parent-boot-1 com.baeldung 0.0.1-SNAPSHOT - ../../parent-boot-5 + ../../parent-boot-1 diff --git a/spring-security-client/spring-security-jsp-config/pom.xml b/spring-security-client/spring-security-jsp-config/pom.xml index 0ec72c3527..54dc2fe947 100644 --- a/spring-security-client/spring-security-jsp-config/pom.xml +++ b/spring-security-client/spring-security-jsp-config/pom.xml @@ -12,10 +12,10 @@ Spring Security JSP configuration - parent-boot-5 + parent-boot-1 com.baeldung 0.0.1-SNAPSHOT - ../../parent-boot-5 + ../../parent-boot-1 diff --git a/spring-security-client/spring-security-mvc/pom.xml b/spring-security-client/spring-security-mvc/pom.xml index a6c3065cc8..5064aec7e8 100644 --- a/spring-security-client/spring-security-mvc/pom.xml +++ b/spring-security-client/spring-security-mvc/pom.xml @@ -12,10 +12,10 @@ Spring Security MVC - parent-boot-5 + parent-boot-1 com.baeldung 0.0.1-SNAPSHOT - ../../parent-boot-5 + ../../parent-boot-1 diff --git a/spring-security-client/spring-security-thymeleaf-authentication/pom.xml b/spring-security-client/spring-security-thymeleaf-authentication/pom.xml index 345daa9570..7bea8124e7 100644 --- a/spring-security-client/spring-security-thymeleaf-authentication/pom.xml +++ b/spring-security-client/spring-security-thymeleaf-authentication/pom.xml @@ -12,10 +12,10 @@ Spring Security thymeleaf authentication tag sample - parent-boot-5 + parent-boot-1 com.baeldung 0.0.1-SNAPSHOT - ../../parent-boot-5 + ../../parent-boot-1 diff --git a/spring-security-client/spring-security-thymeleaf-authorize/pom.xml b/spring-security-client/spring-security-thymeleaf-authorize/pom.xml index 3e66e9f613..b03464877a 100644 --- a/spring-security-client/spring-security-thymeleaf-authorize/pom.xml +++ b/spring-security-client/spring-security-thymeleaf-authorize/pom.xml @@ -12,10 +12,10 @@ Spring Security thymeleaf authorize tag sample - parent-boot-5 + parent-boot-1 com.baeldung 0.0.1-SNAPSHOT - ../../parent-boot-5 + ../../parent-boot-1 diff --git a/spring-security-client/spring-security-thymeleaf-config/pom.xml b/spring-security-client/spring-security-thymeleaf-config/pom.xml index f5d4306754..3abe9d8c8b 100644 --- a/spring-security-client/spring-security-thymeleaf-config/pom.xml +++ b/spring-security-client/spring-security-thymeleaf-config/pom.xml @@ -12,10 +12,10 @@ Spring Security thymeleaf configuration sample project - parent-boot-5 + parent-boot-1 com.baeldung 0.0.1-SNAPSHOT - ../../parent-boot-5 + ../../parent-boot-1 diff --git a/spring-security-core/pom.xml b/spring-security-core/pom.xml index 27c6741790..a11743d9fa 100644 --- a/spring-security-core/pom.xml +++ b/spring-security-core/pom.xml @@ -9,10 +9,10 @@ war - parent-boot-5 + parent-boot-1 com.baeldung 0.0.1-SNAPSHOT - ../parent-boot-5 + ../parent-boot-1 diff --git a/spring-security-mvc-ldap/pom.xml b/spring-security-mvc-ldap/pom.xml index 286b189d87..6a9aa5eebe 100644 --- a/spring-security-mvc-ldap/pom.xml +++ b/spring-security-mvc-ldap/pom.xml @@ -9,10 +9,10 @@ war - parent-boot-5 + parent-boot-1 com.baeldung 0.0.1-SNAPSHOT - ../parent-boot-5 + ../parent-boot-1 diff --git a/spring-security-rest-custom/pom.xml b/spring-security-rest-custom/pom.xml index cfa3ad4b99..1ee324bcdb 100644 --- a/spring-security-rest-custom/pom.xml +++ b/spring-security-rest-custom/pom.xml @@ -9,10 +9,10 @@ war - parent-boot-5 + parent-boot-1 com.baeldung 0.0.1-SNAPSHOT - ../parent-boot-5 + ../parent-boot-1 diff --git a/spring-security-sso/pom.xml b/spring-security-sso/pom.xml index 938636ff18..f68b9addac 100644 --- a/spring-security-sso/pom.xml +++ b/spring-security-sso/pom.xml @@ -9,10 +9,10 @@ pom - parent-boot-5 + parent-boot-1 com.baeldung 0.0.1-SNAPSHOT - ../parent-boot-5 + ../parent-boot-1 diff --git a/spring-security-stormpath/pom.xml b/spring-security-stormpath/pom.xml index 17973165ea..71a7123c2c 100644 --- a/spring-security-stormpath/pom.xml +++ b/spring-security-stormpath/pom.xml @@ -9,10 +9,10 @@ http://maven.apache.org - parent-boot-5 + parent-boot-1 com.baeldung 0.0.1-SNAPSHOT - ../parent-boot-5 + ../parent-boot-1 diff --git a/spring-security-thymeleaf/pom.xml b/spring-security-thymeleaf/pom.xml index aa36e5f59a..d9dea95e21 100644 --- a/spring-security-thymeleaf/pom.xml +++ b/spring-security-thymeleaf/pom.xml @@ -10,10 +10,10 @@ Spring Security with Thymeleaf tutorial - parent-boot-5 + parent-boot-1 com.baeldung 0.0.1-SNAPSHOT - ../parent-boot-5 + ../parent-boot-1 diff --git a/spring-security-x509/pom.xml b/spring-security-x509/pom.xml index 89fed39920..d6a4b5693b 100644 --- a/spring-security-x509/pom.xml +++ b/spring-security-x509/pom.xml @@ -9,10 +9,10 @@ pom - parent-boot-5 + parent-boot-1 com.baeldung 0.0.1-SNAPSHOT - ../parent-boot-5 + ../parent-boot-1 diff --git a/spring-session/pom.xml b/spring-session/pom.xml index c1c872ca74..4c256663b0 100644 --- a/spring-session/pom.xml +++ b/spring-session/pom.xml @@ -7,10 +7,10 @@ jar - parent-boot-5 + parent-boot-1 com.baeldung 0.0.1-SNAPSHOT - ../parent-boot-5 + ../parent-boot-1 diff --git a/spring-sleuth/pom.xml b/spring-sleuth/pom.xml index 2fee474dbe..418edeaec7 100644 --- a/spring-sleuth/pom.xml +++ b/spring-sleuth/pom.xml @@ -8,10 +8,10 @@ jar - parent-boot-5 + parent-boot-1 com.baeldung 0.0.1-SNAPSHOT - ../parent-boot-5 + ../parent-boot-1 diff --git a/spring-social-login/pom.xml b/spring-social-login/pom.xml index d2e9497bcf..d08600a8e4 100644 --- a/spring-social-login/pom.xml +++ b/spring-social-login/pom.xml @@ -6,10 +6,10 @@ war - parent-boot-5 + parent-boot-1 com.baeldung 0.0.1-SNAPSHOT - ../parent-boot-5 + ../parent-boot-1 diff --git a/spring-zuul/pom.xml b/spring-zuul/pom.xml index b1036c9a8a..37bdb09367 100644 --- a/spring-zuul/pom.xml +++ b/spring-zuul/pom.xml @@ -8,10 +8,10 @@ pom - parent-boot-5 + parent-boot-1 com.baeldung 0.0.1-SNAPSHOT - ../parent-boot-5 + ../parent-boot-1 diff --git a/stripe/pom.xml b/stripe/pom.xml index b6dae6e680..ca165934a0 100644 --- a/stripe/pom.xml +++ b/stripe/pom.xml @@ -10,10 +10,10 @@ Demo project for Stripe API - parent-boot-5 + parent-boot-1 com.baeldung 0.0.1-SNAPSHOT - ../parent-boot-5 + ../parent-boot-1 From a023f014d0a4605c33be3d84ddc05602b0489bde Mon Sep 17 00:00:00 2001 From: Pello Altadill Date: Fri, 8 Jun 2018 20:54:58 +0200 Subject: [PATCH 14/84] BAEL-1388 Introduction to Java MSF4J Microservices (#4192) * BAEL-1562 - Thymeleaf sample working * BAEL-1562 Code added for Fragments sample * BAEL-1562 - Last correction for the test * BAEL-1562 - Thymeleaf sample working * BAEL-1562 Code added for Fragments sample * BAEL-1562 - Last correction for the test * Updates Thymeleaf version to 3.0.9.RELEASE * Added msf4j projects * updated msf4j project folder * fixed issue with spring-thymeleaf/pom.xml * Removed depedency-reduced-pom.xml * Whitespacing fix --- msf4j/pom.xml | 32 ++++++++ .../baeldung/msf4j/msf4japi/Application.java | 11 +++ .../com/baeldung/msf4j/msf4japi/Meal.java | 20 +++++ .../baeldung/msf4j/msf4japi/MenuService.java | 78 +++++++++++++++++++ .../msf4j/msf4jintro/Application.java | 11 +++ .../msf4j/msf4jintro/SimpleService.java | 21 +++++ .../msf4j/msf4jspring/Application.java | 10 +++ .../configuration/PortConfiguration.java | 15 ++++ .../msf4j/msf4jspring/domain/Meal.java | 20 +++++ .../repositories/MealRepository.java | 37 +++++++++ .../msf4jspring/resources/MealResource.java | 47 +++++++++++ .../msf4jspring/services/MealService.java | 27 +++++++ .../src/main/resources/application.properties | 0 .../main/resources/templates/meals.mustache | 13 ++++ pom.xml | 1 + spring-thymeleaf/pom.xml | 2 +- 16 files changed, 344 insertions(+), 1 deletion(-) create mode 100644 msf4j/pom.xml create mode 100644 msf4j/src/main/java/com/baeldung/msf4j/msf4japi/Application.java create mode 100644 msf4j/src/main/java/com/baeldung/msf4j/msf4japi/Meal.java create mode 100644 msf4j/src/main/java/com/baeldung/msf4j/msf4japi/MenuService.java create mode 100644 msf4j/src/main/java/com/baeldung/msf4j/msf4jintro/Application.java create mode 100644 msf4j/src/main/java/com/baeldung/msf4j/msf4jintro/SimpleService.java create mode 100644 msf4j/src/main/java/com/baeldung/msf4j/msf4jspring/Application.java create mode 100644 msf4j/src/main/java/com/baeldung/msf4j/msf4jspring/configuration/PortConfiguration.java create mode 100644 msf4j/src/main/java/com/baeldung/msf4j/msf4jspring/domain/Meal.java create mode 100644 msf4j/src/main/java/com/baeldung/msf4j/msf4jspring/repositories/MealRepository.java create mode 100644 msf4j/src/main/java/com/baeldung/msf4j/msf4jspring/resources/MealResource.java create mode 100644 msf4j/src/main/java/com/baeldung/msf4j/msf4jspring/services/MealService.java create mode 100644 msf4j/src/main/resources/application.properties create mode 100644 msf4j/src/main/resources/templates/meals.mustache diff --git a/msf4j/pom.xml b/msf4j/pom.xml new file mode 100644 index 0000000000..f691d746b7 --- /dev/null +++ b/msf4j/pom.xml @@ -0,0 +1,32 @@ + + + + org.wso2.msf4j + msf4j-service + 2.6.0 + + 4.0.0 + + com.baeldung.msf4j + msf4j + 0.0.1-SNAPSHOT + WSO2 MSF4J Microservice + + + com.baeldung.msf4j.msf4jintro.Application + + + + org.wso2.msf4j + msf4j-spring + 2.6.1 + + + org.wso2.msf4j + msf4j-mustache-template + 2.6.1 + + + + \ No newline at end of file diff --git a/msf4j/src/main/java/com/baeldung/msf4j/msf4japi/Application.java b/msf4j/src/main/java/com/baeldung/msf4j/msf4japi/Application.java new file mode 100644 index 0000000000..c4cf136536 --- /dev/null +++ b/msf4j/src/main/java/com/baeldung/msf4j/msf4japi/Application.java @@ -0,0 +1,11 @@ +package com.baeldung.msf4j.msf4japi; + +import org.wso2.msf4j.MicroservicesRunner; + +public class Application { + public static void main(String[] args) { + new MicroservicesRunner() + .deploy(new MenuService()) + .start(); + } +} \ No newline at end of file diff --git a/msf4j/src/main/java/com/baeldung/msf4j/msf4japi/Meal.java b/msf4j/src/main/java/com/baeldung/msf4j/msf4japi/Meal.java new file mode 100644 index 0000000000..d17a7a1034 --- /dev/null +++ b/msf4j/src/main/java/com/baeldung/msf4j/msf4japi/Meal.java @@ -0,0 +1,20 @@ +package com.baeldung.msf4j.msf4japi; + +public class Meal { + private String name; + private Float price; + + public Meal(String name, Float price) { + this.name = name; + this.price = price; + } + + public String getName() { + return name; + } + + public Float getPrice() { + return price; + } + +} diff --git a/msf4j/src/main/java/com/baeldung/msf4j/msf4japi/MenuService.java b/msf4j/src/main/java/com/baeldung/msf4j/msf4japi/MenuService.java new file mode 100644 index 0000000000..4f880a1393 --- /dev/null +++ b/msf4j/src/main/java/com/baeldung/msf4j/msf4japi/MenuService.java @@ -0,0 +1,78 @@ +package com.baeldung.msf4j.msf4japi; + +import java.util.ArrayList; +import java.util.List; + +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Response; + +import com.google.gson.Gson; + +@Path("/menu") +public class MenuService { + + private List meals = new ArrayList(); + + public MenuService() { + meals.add(new Meal("Java beans",42.0f)); + } + + @GET + @Path("/") + @Produces({ "application/json" }) + public Response index() { + return Response.ok() + .entity(meals) + .build(); + } + + @GET + @Path("/{id}") + @Produces({ "application/json" }) + public Response meal(@PathParam("id") int id) { + return Response.ok() + .entity(meals.get(id)) + .build(); + } + + + @POST + @Path("/") + @Consumes("application/json") + @Produces({ "application/json" }) + public Response create(Meal meal) { + meals.add(meal); + return Response.ok() + .entity(meal) + .build(); + } + + @PUT + @Path("/{id}") + @Consumes("application/json") + @Produces({ "application/json" }) + public Response update(@PathParam("id") int id, Meal meal) { + meals.set(id, meal); + return Response.ok() + .entity(meal) + .build(); + } + + @DELETE + @Path("/{id}") + @Produces({ "application/json" }) + public Response delete(@PathParam("id") int id) { + Meal meal = meals.get(id); + meals.remove(id); + return Response.ok() + .entity(meal) + .build(); + } +} diff --git a/msf4j/src/main/java/com/baeldung/msf4j/msf4jintro/Application.java b/msf4j/src/main/java/com/baeldung/msf4j/msf4jintro/Application.java new file mode 100644 index 0000000000..dc4a060056 --- /dev/null +++ b/msf4j/src/main/java/com/baeldung/msf4j/msf4jintro/Application.java @@ -0,0 +1,11 @@ +package com.baeldung.msf4j.msf4jintro; + +import org.wso2.msf4j.MicroservicesRunner; + +public class Application { + public static void main(String[] args) { + new MicroservicesRunner() + .deploy(new SimpleService()) + .start(); + } +} \ No newline at end of file diff --git a/msf4j/src/main/java/com/baeldung/msf4j/msf4jintro/SimpleService.java b/msf4j/src/main/java/com/baeldung/msf4j/msf4jintro/SimpleService.java new file mode 100644 index 0000000000..bcb52859b5 --- /dev/null +++ b/msf4j/src/main/java/com/baeldung/msf4j/msf4jintro/SimpleService.java @@ -0,0 +1,21 @@ +package com.baeldung.msf4j.msf4jintro; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; + +@Path("/") +public class SimpleService { + + @GET + public String index() { + return "Default content"; + } + + @GET + @Path("/say/{name}") + public String say(@PathParam("name") String name) { + return "Hello " + name; + } + +} diff --git a/msf4j/src/main/java/com/baeldung/msf4j/msf4jspring/Application.java b/msf4j/src/main/java/com/baeldung/msf4j/msf4jspring/Application.java new file mode 100644 index 0000000000..2a5232a7e6 --- /dev/null +++ b/msf4j/src/main/java/com/baeldung/msf4j/msf4jspring/Application.java @@ -0,0 +1,10 @@ +package com.baeldung.msf4j.msf4jspring; + +import org.wso2.msf4j.spring.MSF4JSpringApplication; + +public class Application { + + public static void main(String[] args) { + MSF4JSpringApplication.run(Application.class, args); + } +} \ No newline at end of file diff --git a/msf4j/src/main/java/com/baeldung/msf4j/msf4jspring/configuration/PortConfiguration.java b/msf4j/src/main/java/com/baeldung/msf4j/msf4jspring/configuration/PortConfiguration.java new file mode 100644 index 0000000000..c3313fc3b1 --- /dev/null +++ b/msf4j/src/main/java/com/baeldung/msf4j/msf4jspring/configuration/PortConfiguration.java @@ -0,0 +1,15 @@ +package com.baeldung.msf4j.msf4jspring.configuration; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.wso2.msf4j.spring.transport.HTTPTransportConfig; + +@Configuration +public class PortConfiguration { + + @Bean + public HTTPTransportConfig http() { + return new HTTPTransportConfig(9090); + } + +} \ No newline at end of file diff --git a/msf4j/src/main/java/com/baeldung/msf4j/msf4jspring/domain/Meal.java b/msf4j/src/main/java/com/baeldung/msf4j/msf4jspring/domain/Meal.java new file mode 100644 index 0000000000..99de0abc4c --- /dev/null +++ b/msf4j/src/main/java/com/baeldung/msf4j/msf4jspring/domain/Meal.java @@ -0,0 +1,20 @@ +package com.baeldung.msf4j.msf4jspring.domain; + +public class Meal { + private String name; + private Float price; + + public Meal(String name, Float price) { + this.name = name; + this.price = price; + } + + public String getName() { + return name; + } + + public Float getPrice() { + return price; + } + +} diff --git a/msf4j/src/main/java/com/baeldung/msf4j/msf4jspring/repositories/MealRepository.java b/msf4j/src/main/java/com/baeldung/msf4j/msf4jspring/repositories/MealRepository.java new file mode 100644 index 0000000000..4d9e54348e --- /dev/null +++ b/msf4j/src/main/java/com/baeldung/msf4j/msf4jspring/repositories/MealRepository.java @@ -0,0 +1,37 @@ +package com.baeldung.msf4j.msf4jspring.repositories; + +import java.util.ArrayList; +import java.util.List; +import org.springframework.stereotype.Component; +import com.baeldung.msf4j.msf4jspring.domain.Meal; + +@Component +public class MealRepository { + + private List meals = new ArrayList(); + + public MealRepository() { + meals.add(new Meal("Salad", 4.2f)); + meals.add(new Meal("Litre of cola", 2.99f)); + } + + public void create(Meal meal) { + meals.add(meal); + } + + public void remove(Meal meal) { + meals.remove(meal); + } + + public Meal find(int id) { + return meals.get(id); + } + + public List findAll() { + return meals; + } + + public void update(int id, Meal meal) { + meals.set(id, meal); + } +} \ No newline at end of file diff --git a/msf4j/src/main/java/com/baeldung/msf4j/msf4jspring/resources/MealResource.java b/msf4j/src/main/java/com/baeldung/msf4j/msf4jspring/resources/MealResource.java new file mode 100644 index 0000000000..9c617257cb --- /dev/null +++ b/msf4j/src/main/java/com/baeldung/msf4j/msf4jspring/resources/MealResource.java @@ -0,0 +1,47 @@ +package com.baeldung.msf4j.msf4jspring.resources; + +import java.util.Collections; +import java.util.Map; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import org.wso2.msf4j.template.MustacheTemplateEngine; + +import com.baeldung.msf4j.msf4jspring.services.MealService; + +@Component +@Path("/meal") +public class MealResource { + + @Autowired + private MealService mealService; + + @GET + @Path("/") + public Response all() { + Map map = Collections.singletonMap("meals", mealService.findAll()); + String html = MustacheTemplateEngine.instance() + .render("meals.mustache", map); + return Response.ok() + .type(MediaType.TEXT_HTML) + .entity(html) + .build(); + } + + @GET + @Path("/{id}") + @Produces({ "text/xml" }) + public Response meal(@PathParam("id") int id) { + return Response.ok() + .entity(mealService.find(id)) + .build(); + } + +} diff --git a/msf4j/src/main/java/com/baeldung/msf4j/msf4jspring/services/MealService.java b/msf4j/src/main/java/com/baeldung/msf4j/msf4jspring/services/MealService.java new file mode 100644 index 0000000000..fd6a519999 --- /dev/null +++ b/msf4j/src/main/java/com/baeldung/msf4j/msf4jspring/services/MealService.java @@ -0,0 +1,27 @@ +package com.baeldung.msf4j.msf4jspring.services; + +import java.util.List; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import com.baeldung.msf4j.msf4jspring.domain.Meal; +import com.baeldung.msf4j.msf4jspring.repositories.MealRepository; + +@Service +public class MealService { + @Autowired + private MealRepository mealRepository; + + public Meal find(int id) { + return mealRepository.find(id); + } + + public List findAll() { + return mealRepository.findAll(); + } + + public void create(Meal meal) { + mealRepository.create(meal); + } +} diff --git a/msf4j/src/main/resources/application.properties b/msf4j/src/main/resources/application.properties new file mode 100644 index 0000000000..e69de29bb2 diff --git a/msf4j/src/main/resources/templates/meals.mustache b/msf4j/src/main/resources/templates/meals.mustache new file mode 100644 index 0000000000..f4bdfaccf9 --- /dev/null +++ b/msf4j/src/main/resources/templates/meals.mustache @@ -0,0 +1,13 @@ + + + Meals + + +
+

Today's Meals

+ {{#meals}} +
{{name}}: {{price}}$
+ {{/meals}} +
+ + \ No newline at end of file diff --git a/pom.xml b/pom.xml index f7b065722f..d42c3ac617 100644 --- a/pom.xml +++ b/pom.xml @@ -102,6 +102,7 @@ metrics maven mesos-marathon + msf4j testing-modules/mockito testing-modules/mockito-2 testing-modules/mocks diff --git a/spring-thymeleaf/pom.xml b/spring-thymeleaf/pom.xml index d13356b3d7..6e0b7f6545 100644 --- a/spring-thymeleaf/pom.xml +++ b/spring-thymeleaf/pom.xml @@ -173,4 +173,4 @@ 2.2
- \ No newline at end of file + From b3fd2117636afb9051056a43defa5c6101d14546 Mon Sep 17 00:00:00 2001 From: Jorge Collado Date: Fri, 4 May 2018 12:24:28 +0200 Subject: [PATCH 15/84] [BAEL-1686] - Initial commit --- spring-data-rest-querydsl/pom.xml | 236 ++++++++++++++++++ .../main/java/com/baeldung/Application.java | 39 +++ .../baeldung/controller/QueryController.java | 22 ++ .../repository/AddressRepository.java | 18 ++ .../repository/PersonRepository.java | 18 ++ .../java/com/baeldung/entity/Address.java | 45 ++++ .../main/java/com/baeldung/entity/Person.java | 48 ++++ .../src/main/resources/application.yml | 13 + .../SpringBootIntegrationTests.java | 43 ++++ 9 files changed, 482 insertions(+) create mode 100644 spring-data-rest-querydsl/pom.xml create mode 100644 spring-data-rest-querydsl/src/main/java/com/baeldung/Application.java create mode 100644 spring-data-rest-querydsl/src/main/java/com/baeldung/controller/QueryController.java create mode 100644 spring-data-rest-querydsl/src/main/java/com/baeldung/controller/repository/AddressRepository.java create mode 100644 spring-data-rest-querydsl/src/main/java/com/baeldung/controller/repository/PersonRepository.java create mode 100644 spring-data-rest-querydsl/src/main/java/com/baeldung/entity/Address.java create mode 100644 spring-data-rest-querydsl/src/main/java/com/baeldung/entity/Person.java create mode 100644 spring-data-rest-querydsl/src/main/resources/application.yml create mode 100644 spring-data-rest-querydsl/src/test/java/com/baeldung/springdatarestquerydsl/SpringBootIntegrationTests.java diff --git a/spring-data-rest-querydsl/pom.xml b/spring-data-rest-querydsl/pom.xml new file mode 100644 index 0000000000..f9d5d27773 --- /dev/null +++ b/spring-data-rest-querydsl/pom.xml @@ -0,0 +1,236 @@ + + + 4.0.0 + + com.vivelibre + VLCore + 2.0.31-SNAPSHOT + + + VLCore + Vivelibre API - Microservices + + + org.springframework.boot + spring-boot-starter-parent + 1.5.9.RELEASE + + + + + + org.springframework.cloud + spring-cloud-netflix + 1.3.4.RELEASE + pom + import + + + + + + + org.springframework.boot + spring-boot-starter-data-rest + + + org.springframework.cloud + spring-cloud-starter-eureka + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-data-jpa + + + mysql + mysql-connector-java + + + org.mariadb.jdbc + mariadb-java-client + + + org.springframework.cloud + spring-cloud-starter-ribbon + + + org.springframework.cloud + spring-cloud-starter-hystrix + + + org.springframework.boot + spring-boot-autoconfigure + + + org.springframework.boot + spring-boot-actuator + + + org.springframework.boot + spring-boot-devtools + true + + + org.springframework.restdocs + spring-restdocs-mockmvc + test + + + org.springframework.data + spring-data-rest-hal-browser + + + org.springframework.boot + spring-boot-starter-hateoas + + + com.querydsl + querydsl-apt + + + com.querydsl + querydsl-jpa + + + org.slf4j + slf4j-log4j12 + 1.6.1 + + + junit + junit + test + + + io.rest-assured + rest-assured + 3.0.6 + test + + + javax.ws.rs + jsr311-api + 1.1.1 + + + com.google.code.gson + gson + 2.8.2 + + + org.springframework.boot + spring-boot-configuration-processor + true + + + org.apache.httpcomponents + httpcore + 4.4.8 + + + org.apache.httpcomponents + httpclient + 4.5.3 + + + com.google.guava + guava + 23.6-jre + + + net.sf.dozer + dozer + 5.5.1 + + + org.apache.xmlrpc + xmlrpc-client + 3.1.3 + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + org.springframework.boot + spring-boot-maven-plugin + + ${start-class} + ZIP + + + + + repackage + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.8 + 1.8 + + -verbose + -parameters + + + + + com.mysema.maven + apt-maven-plugin + 1.1.3 + + + generate-sources + + process + + + ${project.build.directory}/generated-sources + com.querydsl.apt.jpa.JPAAnnotationProcessor + + + + + + maven-release-plugin + 2.5.1 + + + + + + scm:git:http://jcollado@192.169.170.109:7990/scm/viv/vivelibre-backendside-core-vlcore.git + http://192.169.170.109:7990/projects/VIV/repos/vivelibre-backendside-core-vlcore + scm:git:http://jcollado@192.169.170.109:7990/scm/viv/vivelibre-backendside-core-vlcore.git + + VLCore-2.0.28 + + + + + releases + http://192.169.170.109:3000/nexus/content/repositories/releases + + + + + + nexus-releases + nexus + http://192.169.170.109:3000/nexus/content/repositories/releases/ + + + + diff --git a/spring-data-rest-querydsl/src/main/java/com/baeldung/Application.java b/spring-data-rest-querydsl/src/main/java/com/baeldung/Application.java new file mode 100644 index 0000000000..db87e920e1 --- /dev/null +++ b/spring-data-rest-querydsl/src/main/java/com/baeldung/Application.java @@ -0,0 +1,39 @@ +package com.baeldung; + +import com.baeldung.controller.repository.AddressRepository; +import com.baeldung.controller.repository.PersonRepository; +import com.baeldung.entity.Address; +import com.baeldung.entity.Person; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.domain.EntityScan; +import org.springframework.data.jpa.repository.config.EnableJpaRepositories; + +import javax.annotation.PostConstruct; +import java.util.UUID; + +@SpringBootApplication @EntityScan("com.baeldung.entity") @EnableJpaRepositories("com.baeldung.controller.repository") +public class Application { + + @Autowired private PersonRepository personRepository; + @Autowired private AddressRepository addressRepository; + + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } + + @PostConstruct private void initializeData() { + // Create John + final Address johnsAddress = new Address(UUID.randomUUID().toString(), "Fake Street 1", "Fake country"); + addressRepository.save(johnsAddress); + final Person john = new Person(UUID.randomUUID().toString(), "John", johnsAddress); + personRepository.save(john); + + // Create Lisa + final Address lisasAddress = new Address(UUID.randomUUID().toString(), "Real Street 1", "Real country"); + addressRepository.save(lisasAddress); + final Person lisa = new Person(UUID.randomUUID().toString(), "Lisa", lisasAddress); + personRepository.save(lisa); + } +} diff --git a/spring-data-rest-querydsl/src/main/java/com/baeldung/controller/QueryController.java b/spring-data-rest-querydsl/src/main/java/com/baeldung/controller/QueryController.java new file mode 100644 index 0000000000..753250e638 --- /dev/null +++ b/spring-data-rest-querydsl/src/main/java/com/baeldung/controller/QueryController.java @@ -0,0 +1,22 @@ +package com.baeldung.controller; + +import com.baeldung.controller.repository.PersonRepository; +import com.baeldung.entity.Person; +import com.querydsl.core.BooleanBuilder; +import com.querydsl.core.types.Predicate; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.querydsl.binding.QuerydslPredicate; +import org.springframework.http.MediaType; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController public class QueryController { + + @Autowired private PersonRepository personRepository; + + @GetMapping(value = "/personQuery", produces = MediaType.APPLICATION_JSON_VALUE) + public Iterable getFilteredEvents(@QuerydslPredicate(root = Person.class) Predicate predicate) { + final BooleanBuilder builder = new BooleanBuilder(); + return personRepository.findAll(builder.and(predicate)); + } +} diff --git a/spring-data-rest-querydsl/src/main/java/com/baeldung/controller/repository/AddressRepository.java b/spring-data-rest-querydsl/src/main/java/com/baeldung/controller/repository/AddressRepository.java new file mode 100644 index 0000000000..aa42ca6779 --- /dev/null +++ b/spring-data-rest-querydsl/src/main/java/com/baeldung/controller/repository/AddressRepository.java @@ -0,0 +1,18 @@ +package com.baeldung.controller.repository; + +import com.baeldung.entity.Address; +import com.baeldung.entity.QAddress; +import com.querydsl.core.types.dsl.StringExpression; +import com.querydsl.core.types.dsl.StringPath; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.querydsl.QueryDslPredicateExecutor; +import org.springframework.data.querydsl.binding.QuerydslBinderCustomizer; +import org.springframework.data.querydsl.binding.QuerydslBindings; +import org.springframework.data.querydsl.binding.SingleValueBinding; + +public interface AddressRepository + extends JpaRepository, QueryDslPredicateExecutor
, QuerydslBinderCustomizer { + @Override default void customize(final QuerydslBindings bindings, final QAddress root) { + bindings.bind(String.class).first((SingleValueBinding) StringExpression::eq); + } +} diff --git a/spring-data-rest-querydsl/src/main/java/com/baeldung/controller/repository/PersonRepository.java b/spring-data-rest-querydsl/src/main/java/com/baeldung/controller/repository/PersonRepository.java new file mode 100644 index 0000000000..7c37fb6b15 --- /dev/null +++ b/spring-data-rest-querydsl/src/main/java/com/baeldung/controller/repository/PersonRepository.java @@ -0,0 +1,18 @@ +package com.baeldung.controller.repository; + +import com.baeldung.entity.Person; +import com.baeldung.entity.QPerson; +import com.querydsl.core.types.dsl.StringExpression; +import com.querydsl.core.types.dsl.StringPath; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.querydsl.QueryDslPredicateExecutor; +import org.springframework.data.querydsl.binding.QuerydslBinderCustomizer; +import org.springframework.data.querydsl.binding.QuerydslBindings; +import org.springframework.data.querydsl.binding.SingleValueBinding; + +public interface PersonRepository + extends JpaRepository, QueryDslPredicateExecutor, QuerydslBinderCustomizer { + @Override default void customize(final QuerydslBindings bindings, final QPerson root) { + bindings.bind(String.class).first((SingleValueBinding) StringExpression::eq); + } +} diff --git a/spring-data-rest-querydsl/src/main/java/com/baeldung/entity/Address.java b/spring-data-rest-querydsl/src/main/java/com/baeldung/entity/Address.java new file mode 100644 index 0000000000..4f92031473 --- /dev/null +++ b/spring-data-rest-querydsl/src/main/java/com/baeldung/entity/Address.java @@ -0,0 +1,45 @@ +package com.baeldung.entity; + + +import javax.persistence.Entity; +import javax.persistence.Id; + +@Entity public class Address { + + @Id private String id; + private String address; + private String country; + + public Address() { + } + + public Address(String id, String address, String country) { + this.id = id; + this.address = address; + this.country = country; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + public String getCountry() { + return country; + } + + public void setCountry(String country) { + this.country = country; + } +} diff --git a/spring-data-rest-querydsl/src/main/java/com/baeldung/entity/Person.java b/spring-data-rest-querydsl/src/main/java/com/baeldung/entity/Person.java new file mode 100644 index 0000000000..779b1f84a9 --- /dev/null +++ b/spring-data-rest-querydsl/src/main/java/com/baeldung/entity/Person.java @@ -0,0 +1,48 @@ +package com.baeldung.entity; + + +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.OneToOne; + + +@Entity public class Person { + + @Id private String id; + private String name; + @OneToOne @JoinColumn(name = "address") private com.baeldung.entity.Address address; + + public Person() { + } + + public Person(String id, String name, com.baeldung.entity.Address address) { + this.id = id; + this.name = name; + this.address = address; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public com.baeldung.entity.Address getAddress() { + return address; + } + + public void setAddress(com.baeldung.entity.Address address) { + this.address = address; + } +} diff --git a/spring-data-rest-querydsl/src/main/resources/application.yml b/spring-data-rest-querydsl/src/main/resources/application.yml new file mode 100644 index 0000000000..c04c9d9ca0 --- /dev/null +++ b/spring-data-rest-querydsl/src/main/resources/application.yml @@ -0,0 +1,13 @@ +spring: + datasource: + driver-class-name: com.mysql.jdbc.Driver + hikari: + connection-timeout: 60000 + maximum-pool-size: 5 + pool-name: hikari-pool + url: jdbc:mysql://localhost:3306/baeldung?verifyServerCertificate=false&useSSL=false&requireSSL=false + username: root + password: admin + jpa: + hibernate: + ddl-auto: create-drop diff --git a/spring-data-rest-querydsl/src/test/java/com/baeldung/springdatarestquerydsl/SpringBootIntegrationTests.java b/spring-data-rest-querydsl/src/test/java/com/baeldung/springdatarestquerydsl/SpringBootIntegrationTests.java new file mode 100644 index 0000000000..803f0834bb --- /dev/null +++ b/spring-data-rest-querydsl/src/test/java/com/baeldung/springdatarestquerydsl/SpringBootIntegrationTests.java @@ -0,0 +1,43 @@ +package com.baeldung.springdatarestquerydsl; + +import com.baeldung.Application; +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.http.MediaType; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.web.WebAppConfiguration; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; +import org.springframework.test.web.servlet.result.MockMvcResultMatchers; +import org.springframework.test.web.servlet.setup.MockMvcBuilders; +import org.springframework.web.context.WebApplicationContext; + +import java.nio.charset.Charset; + +import static org.hamcrest.Matchers.hasSize; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; + +@RunWith(SpringJUnit4ClassRunner.class) @SpringBootTest(classes = Application.class) @WebAppConfiguration +public class SpringBootIntegrationTests { + + @Autowired private WebApplicationContext webApplicationContext; + + private MockMvc mockMvc; + + @Before public void setupMockMvc() { + mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build(); + } + + @Test public void givenRequestHasBeenMade_whenMeetsAllOfGivenConditions_thenCorrect() throws Exception { + MediaType contentType = new MediaType(MediaType.APPLICATION_JSON.getType(), MediaType.APPLICATION_JSON.getSubtype(), + Charset.forName("utf8")); + + mockMvc.perform(MockMvcRequestBuilders.get("/personQuery?name=john")).andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.content().contentType(contentType)).andExpect(jsonPath("$", hasSize(4))); + } +} + + From 8a5ff707c5fe6b7dd58696749a1b44a901b0c628 Mon Sep 17 00:00:00 2001 From: Jorge Collado Date: Mon, 7 May 2018 18:27:48 +0200 Subject: [PATCH 16/84] [BAEL-1686] - Added integration testing --- .../main/java/com/baeldung/Application.java | 4 +- .../IntegrationTest.java | 66 +++++++++++++++++++ .../SpringBootIntegrationTests.java | 43 ------------ 3 files changed, 68 insertions(+), 45 deletions(-) create mode 100644 spring-data-rest-querydsl/src/test/java/com/baeldung/springdatarestquerydsl/IntegrationTest.java delete mode 100644 spring-data-rest-querydsl/src/test/java/com/baeldung/springdatarestquerydsl/SpringBootIntegrationTests.java diff --git a/spring-data-rest-querydsl/src/main/java/com/baeldung/Application.java b/spring-data-rest-querydsl/src/main/java/com/baeldung/Application.java index db87e920e1..cae2d62f05 100644 --- a/spring-data-rest-querydsl/src/main/java/com/baeldung/Application.java +++ b/spring-data-rest-querydsl/src/main/java/com/baeldung/Application.java @@ -25,13 +25,13 @@ public class Application { @PostConstruct private void initializeData() { // Create John - final Address johnsAddress = new Address(UUID.randomUUID().toString(), "Fake Street 1", "Fake country"); + final Address johnsAddress = new Address(UUID.randomUUID().toString(), "Fake Street 1", "Fake Country"); addressRepository.save(johnsAddress); final Person john = new Person(UUID.randomUUID().toString(), "John", johnsAddress); personRepository.save(john); // Create Lisa - final Address lisasAddress = new Address(UUID.randomUUID().toString(), "Real Street 1", "Real country"); + final Address lisasAddress = new Address(UUID.randomUUID().toString(), "Real Street 1", "Real Country"); addressRepository.save(lisasAddress); final Person lisa = new Person(UUID.randomUUID().toString(), "Lisa", lisasAddress); personRepository.save(lisa); diff --git a/spring-data-rest-querydsl/src/test/java/com/baeldung/springdatarestquerydsl/IntegrationTest.java b/spring-data-rest-querydsl/src/test/java/com/baeldung/springdatarestquerydsl/IntegrationTest.java new file mode 100644 index 0000000000..63d0f56651 --- /dev/null +++ b/spring-data-rest-querydsl/src/test/java/com/baeldung/springdatarestquerydsl/IntegrationTest.java @@ -0,0 +1,66 @@ +package com.baeldung.springdatarestquerydsl; + +import com.baeldung.Application; +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.http.MediaType; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.web.WebAppConfiguration; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.setup.MockMvcBuilders; +import org.springframework.web.context.WebApplicationContext; + +import java.nio.charset.Charset; + +import static org.hamcrest.Matchers.hasSize; +import static org.hamcrest.Matchers.is; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; + +@RunWith(SpringJUnit4ClassRunner.class) @SpringBootTest(classes = Application.class) @WebAppConfiguration +public class IntegrationTest { + + final MediaType contentType = + new MediaType(MediaType.APPLICATION_JSON.getType(), MediaType.APPLICATION_JSON.getSubtype(), Charset.forName("utf8")); + + @Autowired private WebApplicationContext webApplicationContext; + + private MockMvc mockMvc; + + @Before public void setupMockMvc() { + mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build(); + } + + @Test public void givenRequestHasBeenMade_whenQueryOverNameAttribute_thenGetJohn() throws Exception { + // Get John + mockMvc.perform(get("/personQuery?name=John")).andExpect(status().isOk()).andExpect(content().contentType(contentType)) + .andExpect(jsonPath("$", hasSize(1))).andExpect(jsonPath("$[0].name", is("John"))) + .andExpect(jsonPath("$[0].address.address", is("Fake Street 1"))) + .andExpect(jsonPath("$[0].address.country", is("Fake Country"))); + } + + @Test public void givenRequestHasBeenMade_whenQueryOverNameAttribute_thenGetLisa() throws Exception { + // Get Lisa + mockMvc.perform(get("/personQuery?name=Lisa")).andExpect(status().isOk()).andExpect(content().contentType(contentType)) + .andExpect(jsonPath("$", hasSize(1))).andExpect(jsonPath("$[0].name", is("Lisa"))) + .andExpect(jsonPath("$[0].address.address", is("Real Street 1"))) + .andExpect(jsonPath("$[0].address.country", is("Real Country"))); + } + + @Test public void givenRequestHasBeenMade_whenQueryWithoutAttribute_thenCorrect() throws Exception { + final MediaType contentType = new MediaType(MediaType.APPLICATION_JSON.getType(), MediaType.APPLICATION_JSON.getSubtype(), + Charset.forName("utf8")); + + mockMvc.perform(get("/personQuery")).andExpect(status().isOk()).andExpect(content().contentType(contentType)) + .andExpect(jsonPath("$", hasSize(2))) + // Get John + .andExpect(jsonPath("$[0].name", is("John"))).andExpect(jsonPath("$[0].address.address", is("Fake Street 1"))) + .andExpect(jsonPath("$[0].address.country", is("Fake Country"))) + // Get Lisa + .andExpect(jsonPath("$[1].name", is("Lisa"))).andExpect(jsonPath("$[1].address.address", is("Real Street 1"))) + .andExpect(jsonPath("$[1].address.country", is("Real Country"))); + } +} diff --git a/spring-data-rest-querydsl/src/test/java/com/baeldung/springdatarestquerydsl/SpringBootIntegrationTests.java b/spring-data-rest-querydsl/src/test/java/com/baeldung/springdatarestquerydsl/SpringBootIntegrationTests.java deleted file mode 100644 index 803f0834bb..0000000000 --- a/spring-data-rest-querydsl/src/test/java/com/baeldung/springdatarestquerydsl/SpringBootIntegrationTests.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.baeldung.springdatarestquerydsl; - -import com.baeldung.Application; -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.http.MediaType; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.test.context.web.WebAppConfiguration; -import org.springframework.test.web.servlet.MockMvc; -import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; -import org.springframework.test.web.servlet.result.MockMvcResultMatchers; -import org.springframework.test.web.servlet.setup.MockMvcBuilders; -import org.springframework.web.context.WebApplicationContext; - -import java.nio.charset.Charset; - -import static org.hamcrest.Matchers.hasSize; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; - -@RunWith(SpringJUnit4ClassRunner.class) @SpringBootTest(classes = Application.class) @WebAppConfiguration -public class SpringBootIntegrationTests { - - @Autowired private WebApplicationContext webApplicationContext; - - private MockMvc mockMvc; - - @Before public void setupMockMvc() { - mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build(); - } - - @Test public void givenRequestHasBeenMade_whenMeetsAllOfGivenConditions_thenCorrect() throws Exception { - MediaType contentType = new MediaType(MediaType.APPLICATION_JSON.getType(), MediaType.APPLICATION_JSON.getSubtype(), - Charset.forName("utf8")); - - mockMvc.perform(MockMvcRequestBuilders.get("/personQuery?name=john")).andExpect(MockMvcResultMatchers.status().isOk()) - .andExpect(MockMvcResultMatchers.content().contentType(contentType)).andExpect(jsonPath("$", hasSize(4))); - } -} - - From f8b9555e4260104cdaf815efabfc93863d0bb7c6 Mon Sep 17 00:00:00 2001 From: Jorge Collado Date: Wed, 9 May 2018 18:35:14 +0200 Subject: [PATCH 17/84] [BAEL-1686] - Commiting final changes --- spring-data-rest-querydsl/pom.xml | 151 +----------------- .../main/java/com/baeldung/Application.java | 30 ++-- .../baeldung/controller/QueryController.java | 29 +++- .../AddressAvailabilityRepository.java | 19 +++ ...sonRepository.java => UserRepository.java} | 10 +- .../java/com/baeldung/entity/Address.java | 33 ++-- .../baeldung/entity/AddressAvailability.java | 114 +++++++++++++ .../main/java/com/baeldung/entity/Person.java | 48 ------ .../main/java/com/baeldung/entity/User.java | 46 ++++++ .../src/main/resources/application.yml | 4 +- .../IntegrationTest.java | 66 -------- .../QuerydslIntegrationTest.java | 52 ++++++ 12 files changed, 309 insertions(+), 293 deletions(-) create mode 100644 spring-data-rest-querydsl/src/main/java/com/baeldung/controller/repository/AddressAvailabilityRepository.java rename spring-data-rest-querydsl/src/main/java/com/baeldung/controller/repository/{PersonRepository.java => UserRepository.java} (72%) create mode 100644 spring-data-rest-querydsl/src/main/java/com/baeldung/entity/AddressAvailability.java delete mode 100644 spring-data-rest-querydsl/src/main/java/com/baeldung/entity/Person.java create mode 100644 spring-data-rest-querydsl/src/main/java/com/baeldung/entity/User.java delete mode 100644 spring-data-rest-querydsl/src/test/java/com/baeldung/springdatarestquerydsl/IntegrationTest.java create mode 100644 spring-data-rest-querydsl/src/test/java/com/baeldung/springdatarestquerydsl/QuerydslIntegrationTest.java diff --git a/spring-data-rest-querydsl/pom.xml b/spring-data-rest-querydsl/pom.xml index f9d5d27773..3b31e1835c 100644 --- a/spring-data-rest-querydsl/pom.xml +++ b/spring-data-rest-querydsl/pom.xml @@ -1,14 +1,13 @@ - + 4.0.0 - com.vivelibre - VLCore - 2.0.31-SNAPSHOT + com.baeldung + spring-data-rest-querydsl + 1.0 - - VLCore - Vivelibre API - Microservices + spring-data-rest-querydsl org.springframework.boot @@ -16,27 +15,11 @@ 1.5.9.RELEASE - - - - org.springframework.cloud - spring-cloud-netflix - 1.3.4.RELEASE - pom - import - - - - org.springframework.boot spring-boot-starter-data-rest - - org.springframework.cloud - spring-cloud-starter-eureka - org.springframework.boot spring-boot-starter-web @@ -49,44 +32,6 @@ mysql mysql-connector-java - - org.mariadb.jdbc - mariadb-java-client - - - org.springframework.cloud - spring-cloud-starter-ribbon - - - org.springframework.cloud - spring-cloud-starter-hystrix - - - org.springframework.boot - spring-boot-autoconfigure - - - org.springframework.boot - spring-boot-actuator - - - org.springframework.boot - spring-boot-devtools - true - - - org.springframework.restdocs - spring-restdocs-mockmvc - test - - - org.springframework.data - spring-data-rest-hal-browser - - - org.springframework.boot - spring-boot-starter-hateoas - com.querydsl querydsl-apt @@ -95,62 +40,6 @@ com.querydsl querydsl-jpa - - org.slf4j - slf4j-log4j12 - 1.6.1 - - - junit - junit - test - - - io.rest-assured - rest-assured - 3.0.6 - test - - - javax.ws.rs - jsr311-api - 1.1.1 - - - com.google.code.gson - gson - 2.8.2 - - - org.springframework.boot - spring-boot-configuration-processor - true - - - org.apache.httpcomponents - httpcore - 4.4.8 - - - org.apache.httpcomponents - httpclient - 4.5.3 - - - com.google.guava - guava - 23.6-jre - - - net.sf.dozer - dozer - 5.5.1 - - - org.apache.xmlrpc - xmlrpc-client - 3.1.3 - org.springframework.boot spring-boot-starter-test @@ -203,34 +92,6 @@ - - maven-release-plugin - 2.5.1 - - - - scm:git:http://jcollado@192.169.170.109:7990/scm/viv/vivelibre-backendside-core-vlcore.git - http://192.169.170.109:7990/projects/VIV/repos/vivelibre-backendside-core-vlcore - scm:git:http://jcollado@192.169.170.109:7990/scm/viv/vivelibre-backendside-core-vlcore.git - - VLCore-2.0.28 - - - - - releases - http://192.169.170.109:3000/nexus/content/repositories/releases - - - - - - nexus-releases - nexus - http://192.169.170.109:3000/nexus/content/repositories/releases/ - - - diff --git a/spring-data-rest-querydsl/src/main/java/com/baeldung/Application.java b/spring-data-rest-querydsl/src/main/java/com/baeldung/Application.java index cae2d62f05..24e4cee057 100644 --- a/spring-data-rest-querydsl/src/main/java/com/baeldung/Application.java +++ b/spring-data-rest-querydsl/src/main/java/com/baeldung/Application.java @@ -1,23 +1,26 @@ package com.baeldung; +import com.baeldung.controller.repository.AddressAvailabilityRepository; import com.baeldung.controller.repository.AddressRepository; -import com.baeldung.controller.repository.PersonRepository; +import com.baeldung.controller.repository.UserRepository; import com.baeldung.entity.Address; -import com.baeldung.entity.Person; +import com.baeldung.entity.AddressAvailability; +import com.baeldung.entity.User; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.domain.EntityScan; import org.springframework.data.jpa.repository.config.EnableJpaRepositories; import javax.annotation.PostConstruct; -import java.util.UUID; @SpringBootApplication @EntityScan("com.baeldung.entity") @EnableJpaRepositories("com.baeldung.controller.repository") -public class Application { +@EnableAutoConfiguration public class Application { - @Autowired private PersonRepository personRepository; + @Autowired private UserRepository personRepository; @Autowired private AddressRepository addressRepository; + @Autowired private AddressAvailabilityRepository addressAvailabilityRepository; public static void main(String[] args) { SpringApplication.run(Application.class, args); @@ -25,15 +28,18 @@ public class Application { @PostConstruct private void initializeData() { // Create John - final Address johnsAddress = new Address(UUID.randomUUID().toString(), "Fake Street 1", "Fake Country"); - addressRepository.save(johnsAddress); - final Person john = new Person(UUID.randomUUID().toString(), "John", johnsAddress); + final AddressAvailability addressOneAvailability = new AddressAvailability(true, true, false, false, false, true, true); + addressAvailabilityRepository.save(addressOneAvailability); + final User john = new User("John"); personRepository.save(john); - + final Address addressOne = new Address("Fake Street 1", "Fake Country", addressOneAvailability, john); + addressRepository.save(addressOne); // Create Lisa - final Address lisasAddress = new Address(UUID.randomUUID().toString(), "Real Street 1", "Real Country"); - addressRepository.save(lisasAddress); - final Person lisa = new Person(UUID.randomUUID().toString(), "Lisa", lisasAddress); + final AddressAvailability addressTwoAvailability = new AddressAvailability(false, false, false, false, false, true, true); + addressAvailabilityRepository.save(addressTwoAvailability); + final User lisa = new User("Lisa"); personRepository.save(lisa); + final Address addressTwo = new Address("Real Street 1", "Real Country", addressTwoAvailability, lisa); + addressRepository.save(addressTwo); } } diff --git a/spring-data-rest-querydsl/src/main/java/com/baeldung/controller/QueryController.java b/spring-data-rest-querydsl/src/main/java/com/baeldung/controller/QueryController.java index 753250e638..4b3818e5f1 100644 --- a/spring-data-rest-querydsl/src/main/java/com/baeldung/controller/QueryController.java +++ b/spring-data-rest-querydsl/src/main/java/com/baeldung/controller/QueryController.java @@ -1,7 +1,11 @@ package com.baeldung.controller; -import com.baeldung.controller.repository.PersonRepository; -import com.baeldung.entity.Person; +import com.baeldung.controller.repository.AddressAvailabilityRepository; +import com.baeldung.controller.repository.AddressRepository; +import com.baeldung.controller.repository.UserRepository; +import com.baeldung.entity.Address; +import com.baeldung.entity.AddressAvailability; +import com.baeldung.entity.User; import com.querydsl.core.BooleanBuilder; import com.querydsl.core.types.Predicate; import org.springframework.beans.factory.annotation.Autowired; @@ -12,11 +16,26 @@ import org.springframework.web.bind.annotation.RestController; @RestController public class QueryController { - @Autowired private PersonRepository personRepository; + @Autowired private UserRepository personRepository; + @Autowired private AddressRepository addressRepository; + @Autowired private AddressAvailabilityRepository addressAvailabilityRepository; - @GetMapping(value = "/personQuery", produces = MediaType.APPLICATION_JSON_VALUE) - public Iterable getFilteredEvents(@QuerydslPredicate(root = Person.class) Predicate predicate) { + @GetMapping(value = "/users", produces = MediaType.APPLICATION_JSON_VALUE) + public Iterable queryOverUser(@QuerydslPredicate(root = User.class) Predicate predicate) { final BooleanBuilder builder = new BooleanBuilder(); return personRepository.findAll(builder.and(predicate)); } + + @GetMapping(value = "/addresses", produces = MediaType.APPLICATION_JSON_VALUE) + public Iterable
queryOverAddress(@QuerydslPredicate(root = Address.class) Predicate predicate) { + final BooleanBuilder builder = new BooleanBuilder(); + return addressRepository.findAll(builder.and(predicate)); + } + + @GetMapping(value = "/addressAvailabilities", produces = MediaType.APPLICATION_JSON_VALUE) + public Iterable queryOverAddressAvailability( + @QuerydslPredicate(root = AddressAvailability.class) Predicate predicate) { + final BooleanBuilder builder = new BooleanBuilder(); + return addressAvailabilityRepository.findAll(builder.and(predicate)); + } } diff --git a/spring-data-rest-querydsl/src/main/java/com/baeldung/controller/repository/AddressAvailabilityRepository.java b/spring-data-rest-querydsl/src/main/java/com/baeldung/controller/repository/AddressAvailabilityRepository.java new file mode 100644 index 0000000000..f396695d56 --- /dev/null +++ b/spring-data-rest-querydsl/src/main/java/com/baeldung/controller/repository/AddressAvailabilityRepository.java @@ -0,0 +1,19 @@ +package com.baeldung.controller.repository; + +import com.baeldung.entity.AddressAvailability; +import com.baeldung.entity.QAddressAvailability; +import com.querydsl.core.types.dsl.StringExpression; +import com.querydsl.core.types.dsl.StringPath; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.querydsl.QueryDslPredicateExecutor; +import org.springframework.data.querydsl.binding.QuerydslBinderCustomizer; +import org.springframework.data.querydsl.binding.QuerydslBindings; +import org.springframework.data.querydsl.binding.SingleValueBinding; + +public interface AddressAvailabilityRepository + extends JpaRepository, QueryDslPredicateExecutor, + QuerydslBinderCustomizer { + @Override default void customize(final QuerydslBindings bindings, final QAddressAvailability root) { + bindings.bind(String.class).first((SingleValueBinding) StringExpression::eq); + } +} diff --git a/spring-data-rest-querydsl/src/main/java/com/baeldung/controller/repository/PersonRepository.java b/spring-data-rest-querydsl/src/main/java/com/baeldung/controller/repository/UserRepository.java similarity index 72% rename from spring-data-rest-querydsl/src/main/java/com/baeldung/controller/repository/PersonRepository.java rename to spring-data-rest-querydsl/src/main/java/com/baeldung/controller/repository/UserRepository.java index 7c37fb6b15..13d33cdac6 100644 --- a/spring-data-rest-querydsl/src/main/java/com/baeldung/controller/repository/PersonRepository.java +++ b/spring-data-rest-querydsl/src/main/java/com/baeldung/controller/repository/UserRepository.java @@ -1,7 +1,7 @@ package com.baeldung.controller.repository; -import com.baeldung.entity.Person; -import com.baeldung.entity.QPerson; +import com.baeldung.entity.QUser; +import com.baeldung.entity.User; import com.querydsl.core.types.dsl.StringExpression; import com.querydsl.core.types.dsl.StringPath; import org.springframework.data.jpa.repository.JpaRepository; @@ -10,9 +10,9 @@ import org.springframework.data.querydsl.binding.QuerydslBinderCustomizer; import org.springframework.data.querydsl.binding.QuerydslBindings; import org.springframework.data.querydsl.binding.SingleValueBinding; -public interface PersonRepository - extends JpaRepository, QueryDslPredicateExecutor, QuerydslBinderCustomizer { - @Override default void customize(final QuerydslBindings bindings, final QPerson root) { +public interface UserRepository + extends JpaRepository, QueryDslPredicateExecutor, QuerydslBinderCustomizer { + @Override default void customize(final QuerydslBindings bindings, final QUser root) { bindings.bind(String.class).first((SingleValueBinding) StringExpression::eq); } } diff --git a/spring-data-rest-querydsl/src/main/java/com/baeldung/entity/Address.java b/spring-data-rest-querydsl/src/main/java/com/baeldung/entity/Address.java index 4f92031473..5d37431ea3 100644 --- a/spring-data-rest-querydsl/src/main/java/com/baeldung/entity/Address.java +++ b/spring-data-rest-querydsl/src/main/java/com/baeldung/entity/Address.java @@ -1,29 +1,36 @@ package com.baeldung.entity; -import javax.persistence.Entity; -import javax.persistence.Id; +import com.fasterxml.jackson.annotation.JsonBackReference; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -@Entity public class Address { +import javax.persistence.*; - @Id private String id; - private String address; - private String country; +@Entity @JsonIgnoreProperties({"hibernateLazyInitializer", "handler"}) public class Address { + + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "id", unique = true, nullable = false) private Long id; + @Column private String address; + @Column private String country; + @OneToOne(fetch = FetchType.LAZY) @JoinColumn(name = "address_id") @JsonBackReference private AddressAvailability + addressAvailability; + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "user_id") @JsonBackReference private User user; public Address() { } - public Address(String id, String address, String country) { + public Address(String address, String country, AddressAvailability addressAvailability, User user) { this.id = id; this.address = address; this.country = country; + this.addressAvailability = addressAvailability; + this.user = user; } - public String getId() { + public Long getId() { return id; } - public void setId(String id) { + public void setId(Long id) { this.id = id; } @@ -42,4 +49,12 @@ import javax.persistence.Id; public void setCountry(String country) { this.country = country; } + + public AddressAvailability getAddressAvailability() { + return addressAvailability; + } + + public void setAddressAvailability(AddressAvailability addressAvailability) { + this.addressAvailability = addressAvailability; + } } diff --git a/spring-data-rest-querydsl/src/main/java/com/baeldung/entity/AddressAvailability.java b/spring-data-rest-querydsl/src/main/java/com/baeldung/entity/AddressAvailability.java new file mode 100644 index 0000000000..c731c72636 --- /dev/null +++ b/spring-data-rest-querydsl/src/main/java/com/baeldung/entity/AddressAvailability.java @@ -0,0 +1,114 @@ +package com.baeldung.entity; + + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonManagedReference; + +import javax.persistence.*; + +@Table(name = "address_availability") @Entity @JsonIgnoreProperties({"hibernateLazyInitializer", "handler"}) +public class AddressAvailability { + + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "id", unique = true, nullable = false) private Long id; + @Column private Boolean monday; + @Column private Boolean tuesday; + @Column private Boolean wednesday; + @Column private Boolean thursday; + @Column private Boolean friday; + @Column private Boolean saturday; + @Column private Boolean sunday; + @OneToOne(mappedBy = "addressAvailability") @JsonManagedReference private Address address; + + public AddressAvailability() { + } + + public AddressAvailability(Boolean monday, Boolean tuesday, Boolean wednesday, Boolean thursday, Boolean friday, + Boolean saturday, Boolean sunday) { + this.monday = monday; + this.tuesday = tuesday; + this.wednesday = wednesday; + this.thursday = thursday; + this.friday = friday; + this.saturday = saturday; + this.sunday = sunday; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + + public Boolean getMonday() { + return monday; + } + + public void setMonday(Boolean monday) { + this.monday = monday; + } + + + public Boolean getTuesday() { + return tuesday; + } + + public void setTuesday(Boolean tuesday) { + this.tuesday = tuesday; + } + + + public Boolean getWednesday() { + return wednesday; + } + + public void setWednesday(Boolean wednesday) { + this.wednesday = wednesday; + } + + + public Boolean getThursday() { + return thursday; + } + + public void setThursday(Boolean thursday) { + this.thursday = thursday; + } + + + public Boolean getFriday() { + return friday; + } + + public void setFriday(Boolean friday) { + this.friday = friday; + } + + + public Boolean getSaturday() { + return saturday; + } + + public void setSaturday(Boolean saturday) { + this.saturday = saturday; + } + + + public Boolean getSunday() { + return sunday; + } + + public void setSunday(Boolean sunday) { + this.sunday = sunday; + } + + public Address getAddress() { + return address; + } + + public void setAddress(Address address) { + this.address = address; + } +} diff --git a/spring-data-rest-querydsl/src/main/java/com/baeldung/entity/Person.java b/spring-data-rest-querydsl/src/main/java/com/baeldung/entity/Person.java deleted file mode 100644 index 779b1f84a9..0000000000 --- a/spring-data-rest-querydsl/src/main/java/com/baeldung/entity/Person.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.baeldung.entity; - - -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.JoinColumn; -import javax.persistence.OneToOne; - - -@Entity public class Person { - - @Id private String id; - private String name; - @OneToOne @JoinColumn(name = "address") private com.baeldung.entity.Address address; - - public Person() { - } - - public Person(String id, String name, com.baeldung.entity.Address address) { - this.id = id; - this.name = name; - this.address = address; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public com.baeldung.entity.Address getAddress() { - return address; - } - - public void setAddress(com.baeldung.entity.Address address) { - this.address = address; - } -} diff --git a/spring-data-rest-querydsl/src/main/java/com/baeldung/entity/User.java b/spring-data-rest-querydsl/src/main/java/com/baeldung/entity/User.java new file mode 100644 index 0000000000..adc6da724a --- /dev/null +++ b/spring-data-rest-querydsl/src/main/java/com/baeldung/entity/User.java @@ -0,0 +1,46 @@ +package com.baeldung.entity; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonManagedReference; + +import javax.persistence.*; +import java.util.List; + + +@Entity @JsonIgnoreProperties({"hibernateLazyInitializer", "handler"}) public class User { + + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "id", unique = true, nullable = false) private Long id; + @Column private String name; + @OneToMany(fetch = FetchType.LAZY, mappedBy = "user") @JsonManagedReference private List
addresses; + + public User() { + } + + public User(String name) { + this.name = name; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public List
getAddresses() { + return addresses; + } + + public void setAddresses(List
addresses) { + this.addresses = addresses; + } +} diff --git a/spring-data-rest-querydsl/src/main/resources/application.yml b/spring-data-rest-querydsl/src/main/resources/application.yml index c04c9d9ca0..fe9dae345d 100644 --- a/spring-data-rest-querydsl/src/main/resources/application.yml +++ b/spring-data-rest-querydsl/src/main/resources/application.yml @@ -2,12 +2,10 @@ spring: datasource: driver-class-name: com.mysql.jdbc.Driver hikari: - connection-timeout: 60000 - maximum-pool-size: 5 pool-name: hikari-pool url: jdbc:mysql://localhost:3306/baeldung?verifyServerCertificate=false&useSSL=false&requireSSL=false username: root password: admin jpa: hibernate: - ddl-auto: create-drop + ddl-auto: create diff --git a/spring-data-rest-querydsl/src/test/java/com/baeldung/springdatarestquerydsl/IntegrationTest.java b/spring-data-rest-querydsl/src/test/java/com/baeldung/springdatarestquerydsl/IntegrationTest.java deleted file mode 100644 index 63d0f56651..0000000000 --- a/spring-data-rest-querydsl/src/test/java/com/baeldung/springdatarestquerydsl/IntegrationTest.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.baeldung.springdatarestquerydsl; - -import com.baeldung.Application; -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.http.MediaType; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.test.context.web.WebAppConfiguration; -import org.springframework.test.web.servlet.MockMvc; -import org.springframework.test.web.servlet.setup.MockMvcBuilders; -import org.springframework.web.context.WebApplicationContext; - -import java.nio.charset.Charset; - -import static org.hamcrest.Matchers.hasSize; -import static org.hamcrest.Matchers.is; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; - -@RunWith(SpringJUnit4ClassRunner.class) @SpringBootTest(classes = Application.class) @WebAppConfiguration -public class IntegrationTest { - - final MediaType contentType = - new MediaType(MediaType.APPLICATION_JSON.getType(), MediaType.APPLICATION_JSON.getSubtype(), Charset.forName("utf8")); - - @Autowired private WebApplicationContext webApplicationContext; - - private MockMvc mockMvc; - - @Before public void setupMockMvc() { - mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build(); - } - - @Test public void givenRequestHasBeenMade_whenQueryOverNameAttribute_thenGetJohn() throws Exception { - // Get John - mockMvc.perform(get("/personQuery?name=John")).andExpect(status().isOk()).andExpect(content().contentType(contentType)) - .andExpect(jsonPath("$", hasSize(1))).andExpect(jsonPath("$[0].name", is("John"))) - .andExpect(jsonPath("$[0].address.address", is("Fake Street 1"))) - .andExpect(jsonPath("$[0].address.country", is("Fake Country"))); - } - - @Test public void givenRequestHasBeenMade_whenQueryOverNameAttribute_thenGetLisa() throws Exception { - // Get Lisa - mockMvc.perform(get("/personQuery?name=Lisa")).andExpect(status().isOk()).andExpect(content().contentType(contentType)) - .andExpect(jsonPath("$", hasSize(1))).andExpect(jsonPath("$[0].name", is("Lisa"))) - .andExpect(jsonPath("$[0].address.address", is("Real Street 1"))) - .andExpect(jsonPath("$[0].address.country", is("Real Country"))); - } - - @Test public void givenRequestHasBeenMade_whenQueryWithoutAttribute_thenCorrect() throws Exception { - final MediaType contentType = new MediaType(MediaType.APPLICATION_JSON.getType(), MediaType.APPLICATION_JSON.getSubtype(), - Charset.forName("utf8")); - - mockMvc.perform(get("/personQuery")).andExpect(status().isOk()).andExpect(content().contentType(contentType)) - .andExpect(jsonPath("$", hasSize(2))) - // Get John - .andExpect(jsonPath("$[0].name", is("John"))).andExpect(jsonPath("$[0].address.address", is("Fake Street 1"))) - .andExpect(jsonPath("$[0].address.country", is("Fake Country"))) - // Get Lisa - .andExpect(jsonPath("$[1].name", is("Lisa"))).andExpect(jsonPath("$[1].address.address", is("Real Street 1"))) - .andExpect(jsonPath("$[1].address.country", is("Real Country"))); - } -} diff --git a/spring-data-rest-querydsl/src/test/java/com/baeldung/springdatarestquerydsl/QuerydslIntegrationTest.java b/spring-data-rest-querydsl/src/test/java/com/baeldung/springdatarestquerydsl/QuerydslIntegrationTest.java new file mode 100644 index 0000000000..ae972bcfcf --- /dev/null +++ b/spring-data-rest-querydsl/src/test/java/com/baeldung/springdatarestquerydsl/QuerydslIntegrationTest.java @@ -0,0 +1,52 @@ +package com.baeldung.springdatarestquerydsl; + +import com.baeldung.Application; +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.http.MediaType; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.web.WebAppConfiguration; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.setup.MockMvcBuilders; +import org.springframework.web.context.WebApplicationContext; + +import java.nio.charset.Charset; + +import static org.hamcrest.Matchers.hasSize; +import static org.hamcrest.Matchers.is; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; + +@RunWith(SpringJUnit4ClassRunner.class) @SpringBootTest(classes = Application.class) @WebAppConfiguration +public class QuerydslIntegrationTest { + + final MediaType contentType = + new MediaType(MediaType.APPLICATION_JSON.getType(), MediaType.APPLICATION_JSON.getSubtype(), Charset.forName("utf8")); + + @Autowired private WebApplicationContext webApplicationContext; + + private MockMvc mockMvc; + + @Before public void setupMockMvc() { + mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build(); + } + + @Test public void givenRequestHasBeenMade_whenQueryAddressFilteringByUserName_thenGetJohn() throws Exception { + mockMvc.perform(get("/addresses?user.name=John")).andExpect(status().isOk()).andExpect(content().contentType(contentType)) + .andExpect(jsonPath("$", hasSize(1))).andExpect(jsonPath("$[0].address", is("Fake Street 1"))) + .andExpect(jsonPath("$[0].country", is("Fake Country"))); + } + + @Test public void givenRequestHasBeenMade_whenQueryOverAddressAvailabilityFilteringByAddressCountry_thenGetAvailability() + throws Exception { + mockMvc.perform(get("/addressAvailabilities?address.country=Real Country")).andExpect(status().isOk()) + .andExpect(content().contentType(contentType)).andExpect(jsonPath("$", hasSize(1))) + .andExpect(jsonPath("$[0].monday", is(false))).andExpect(jsonPath("$[0].tuesday", is(false))) + .andExpect(jsonPath("$[0].wednesday", is(false))).andExpect(jsonPath("$[0].thursday", is(false))) + .andExpect(jsonPath("$[0].friday", is(false))).andExpect(jsonPath("$[0].saturday", is(true))) + .andExpect(jsonPath("$[0].sunday", is(true))); + } +} From 2b08d2c7ceac8b6a3344b14604e36d4311b6564f Mon Sep 17 00:00:00 2001 From: Jorge Collado Date: Tue, 22 May 2018 18:20:10 +0200 Subject: [PATCH 18/84] [BAEL-1686] - Update project after editor's article review --- .../main/java/com/baeldung/Application.java | 27 ++--- .../baeldung/controller/QueryController.java | 19 +-- .../AddressAvailabilityRepository.java | 19 --- .../repository/AddressRepository.java | 3 +- .../controller/repository/UserRepository.java | 3 +- .../java/com/baeldung/entity/Address.java | 33 +++-- .../baeldung/entity/AddressAvailability.java | 114 ------------------ .../main/java/com/baeldung/entity/User.java | 25 ++-- .../QuerydslIntegrationTest.java | 43 ++++--- 9 files changed, 81 insertions(+), 205 deletions(-) delete mode 100644 spring-data-rest-querydsl/src/main/java/com/baeldung/controller/repository/AddressAvailabilityRepository.java delete mode 100644 spring-data-rest-querydsl/src/main/java/com/baeldung/entity/AddressAvailability.java diff --git a/spring-data-rest-querydsl/src/main/java/com/baeldung/Application.java b/spring-data-rest-querydsl/src/main/java/com/baeldung/Application.java index 24e4cee057..28d084a4dc 100644 --- a/spring-data-rest-querydsl/src/main/java/com/baeldung/Application.java +++ b/spring-data-rest-querydsl/src/main/java/com/baeldung/Application.java @@ -1,10 +1,8 @@ package com.baeldung; -import com.baeldung.controller.repository.AddressAvailabilityRepository; import com.baeldung.controller.repository.AddressRepository; import com.baeldung.controller.repository.UserRepository; import com.baeldung.entity.Address; -import com.baeldung.entity.AddressAvailability; import com.baeldung.entity.User; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.SpringApplication; @@ -15,31 +13,32 @@ import org.springframework.data.jpa.repository.config.EnableJpaRepositories; import javax.annotation.PostConstruct; -@SpringBootApplication @EntityScan("com.baeldung.entity") @EnableJpaRepositories("com.baeldung.controller.repository") -@EnableAutoConfiguration public class Application { +@SpringBootApplication +@EntityScan("com.baeldung.entity") +@EnableJpaRepositories("com.baeldung.controller.repository") +@EnableAutoConfiguration +public class Application { - @Autowired private UserRepository personRepository; - @Autowired private AddressRepository addressRepository; - @Autowired private AddressAvailabilityRepository addressAvailabilityRepository; + @Autowired + private UserRepository personRepository; + @Autowired + private AddressRepository addressRepository; public static void main(String[] args) { SpringApplication.run(Application.class, args); } - @PostConstruct private void initializeData() { + @PostConstruct + private void initializeData() { // Create John - final AddressAvailability addressOneAvailability = new AddressAvailability(true, true, false, false, false, true, true); - addressAvailabilityRepository.save(addressOneAvailability); final User john = new User("John"); personRepository.save(john); - final Address addressOne = new Address("Fake Street 1", "Fake Country", addressOneAvailability, john); + final Address addressOne = new Address("Fake Street 1", "Spain", john); addressRepository.save(addressOne); // Create Lisa - final AddressAvailability addressTwoAvailability = new AddressAvailability(false, false, false, false, false, true, true); - addressAvailabilityRepository.save(addressTwoAvailability); final User lisa = new User("Lisa"); personRepository.save(lisa); - final Address addressTwo = new Address("Real Street 1", "Real Country", addressTwoAvailability, lisa); + final Address addressTwo = new Address("Real Street 1", "Germany", lisa); addressRepository.save(addressTwo); } } diff --git a/spring-data-rest-querydsl/src/main/java/com/baeldung/controller/QueryController.java b/spring-data-rest-querydsl/src/main/java/com/baeldung/controller/QueryController.java index 4b3818e5f1..e29932657f 100644 --- a/spring-data-rest-querydsl/src/main/java/com/baeldung/controller/QueryController.java +++ b/spring-data-rest-querydsl/src/main/java/com/baeldung/controller/QueryController.java @@ -1,10 +1,8 @@ package com.baeldung.controller; -import com.baeldung.controller.repository.AddressAvailabilityRepository; import com.baeldung.controller.repository.AddressRepository; import com.baeldung.controller.repository.UserRepository; import com.baeldung.entity.Address; -import com.baeldung.entity.AddressAvailability; import com.baeldung.entity.User; import com.querydsl.core.BooleanBuilder; import com.querydsl.core.types.Predicate; @@ -14,11 +12,13 @@ import org.springframework.http.MediaType; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; -@RestController public class QueryController { +@RestController +public class QueryController { - @Autowired private UserRepository personRepository; - @Autowired private AddressRepository addressRepository; - @Autowired private AddressAvailabilityRepository addressAvailabilityRepository; + @Autowired + private UserRepository personRepository; + @Autowired + private AddressRepository addressRepository; @GetMapping(value = "/users", produces = MediaType.APPLICATION_JSON_VALUE) public Iterable queryOverUser(@QuerydslPredicate(root = User.class) Predicate predicate) { @@ -31,11 +31,4 @@ import org.springframework.web.bind.annotation.RestController; final BooleanBuilder builder = new BooleanBuilder(); return addressRepository.findAll(builder.and(predicate)); } - - @GetMapping(value = "/addressAvailabilities", produces = MediaType.APPLICATION_JSON_VALUE) - public Iterable queryOverAddressAvailability( - @QuerydslPredicate(root = AddressAvailability.class) Predicate predicate) { - final BooleanBuilder builder = new BooleanBuilder(); - return addressAvailabilityRepository.findAll(builder.and(predicate)); - } } diff --git a/spring-data-rest-querydsl/src/main/java/com/baeldung/controller/repository/AddressAvailabilityRepository.java b/spring-data-rest-querydsl/src/main/java/com/baeldung/controller/repository/AddressAvailabilityRepository.java deleted file mode 100644 index f396695d56..0000000000 --- a/spring-data-rest-querydsl/src/main/java/com/baeldung/controller/repository/AddressAvailabilityRepository.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.baeldung.controller.repository; - -import com.baeldung.entity.AddressAvailability; -import com.baeldung.entity.QAddressAvailability; -import com.querydsl.core.types.dsl.StringExpression; -import com.querydsl.core.types.dsl.StringPath; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.querydsl.QueryDslPredicateExecutor; -import org.springframework.data.querydsl.binding.QuerydslBinderCustomizer; -import org.springframework.data.querydsl.binding.QuerydslBindings; -import org.springframework.data.querydsl.binding.SingleValueBinding; - -public interface AddressAvailabilityRepository - extends JpaRepository, QueryDslPredicateExecutor, - QuerydslBinderCustomizer { - @Override default void customize(final QuerydslBindings bindings, final QAddressAvailability root) { - bindings.bind(String.class).first((SingleValueBinding) StringExpression::eq); - } -} diff --git a/spring-data-rest-querydsl/src/main/java/com/baeldung/controller/repository/AddressRepository.java b/spring-data-rest-querydsl/src/main/java/com/baeldung/controller/repository/AddressRepository.java index aa42ca6779..2e88820c98 100644 --- a/spring-data-rest-querydsl/src/main/java/com/baeldung/controller/repository/AddressRepository.java +++ b/spring-data-rest-querydsl/src/main/java/com/baeldung/controller/repository/AddressRepository.java @@ -12,7 +12,8 @@ import org.springframework.data.querydsl.binding.SingleValueBinding; public interface AddressRepository extends JpaRepository, QueryDslPredicateExecutor
, QuerydslBinderCustomizer { - @Override default void customize(final QuerydslBindings bindings, final QAddress root) { + @Override + default void customize(final QuerydslBindings bindings, final QAddress root) { bindings.bind(String.class).first((SingleValueBinding) StringExpression::eq); } } diff --git a/spring-data-rest-querydsl/src/main/java/com/baeldung/controller/repository/UserRepository.java b/spring-data-rest-querydsl/src/main/java/com/baeldung/controller/repository/UserRepository.java index 13d33cdac6..98ff2ac5e3 100644 --- a/spring-data-rest-querydsl/src/main/java/com/baeldung/controller/repository/UserRepository.java +++ b/spring-data-rest-querydsl/src/main/java/com/baeldung/controller/repository/UserRepository.java @@ -12,7 +12,8 @@ import org.springframework.data.querydsl.binding.SingleValueBinding; public interface UserRepository extends JpaRepository, QueryDslPredicateExecutor, QuerydslBinderCustomizer { - @Override default void customize(final QuerydslBindings bindings, final QUser root) { + @Override + default void customize(final QuerydslBindings bindings, final QUser root) { bindings.bind(String.class).first((SingleValueBinding) StringExpression::eq); } } diff --git a/spring-data-rest-querydsl/src/main/java/com/baeldung/entity/Address.java b/spring-data-rest-querydsl/src/main/java/com/baeldung/entity/Address.java index 5d37431ea3..b01194adb7 100644 --- a/spring-data-rest-querydsl/src/main/java/com/baeldung/entity/Address.java +++ b/spring-data-rest-querydsl/src/main/java/com/baeldung/entity/Address.java @@ -1,28 +1,33 @@ package com.baeldung.entity; -import com.fasterxml.jackson.annotation.JsonBackReference; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import javax.persistence.*; -@Entity @JsonIgnoreProperties({"hibernateLazyInitializer", "handler"}) public class Address { +@Entity +@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"}) +public class Address { - @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "id", unique = true, nullable = false) private Long id; - @Column private String address; - @Column private String country; - @OneToOne(fetch = FetchType.LAZY) @JoinColumn(name = "address_id") @JsonBackReference private AddressAvailability - addressAvailability; - @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "user_id") @JsonBackReference private User user; + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "id", unique = true, nullable = false) + private Long id; + @Column + private String address; + @Column + private String country; + @OneToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "user_id") + private User user; public Address() { } - public Address(String address, String country, AddressAvailability addressAvailability, User user) { + public Address(String address, String country, User user) { this.id = id; this.address = address; this.country = country; - this.addressAvailability = addressAvailability; this.user = user; } @@ -49,12 +54,4 @@ import javax.persistence.*; public void setCountry(String country) { this.country = country; } - - public AddressAvailability getAddressAvailability() { - return addressAvailability; - } - - public void setAddressAvailability(AddressAvailability addressAvailability) { - this.addressAvailability = addressAvailability; - } } diff --git a/spring-data-rest-querydsl/src/main/java/com/baeldung/entity/AddressAvailability.java b/spring-data-rest-querydsl/src/main/java/com/baeldung/entity/AddressAvailability.java deleted file mode 100644 index c731c72636..0000000000 --- a/spring-data-rest-querydsl/src/main/java/com/baeldung/entity/AddressAvailability.java +++ /dev/null @@ -1,114 +0,0 @@ -package com.baeldung.entity; - - -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonManagedReference; - -import javax.persistence.*; - -@Table(name = "address_availability") @Entity @JsonIgnoreProperties({"hibernateLazyInitializer", "handler"}) -public class AddressAvailability { - - @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "id", unique = true, nullable = false) private Long id; - @Column private Boolean monday; - @Column private Boolean tuesday; - @Column private Boolean wednesday; - @Column private Boolean thursday; - @Column private Boolean friday; - @Column private Boolean saturday; - @Column private Boolean sunday; - @OneToOne(mappedBy = "addressAvailability") @JsonManagedReference private Address address; - - public AddressAvailability() { - } - - public AddressAvailability(Boolean monday, Boolean tuesday, Boolean wednesday, Boolean thursday, Boolean friday, - Boolean saturday, Boolean sunday) { - this.monday = monday; - this.tuesday = tuesday; - this.wednesday = wednesday; - this.thursday = thursday; - this.friday = friday; - this.saturday = saturday; - this.sunday = sunday; - } - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - - public Boolean getMonday() { - return monday; - } - - public void setMonday(Boolean monday) { - this.monday = monday; - } - - - public Boolean getTuesday() { - return tuesday; - } - - public void setTuesday(Boolean tuesday) { - this.tuesday = tuesday; - } - - - public Boolean getWednesday() { - return wednesday; - } - - public void setWednesday(Boolean wednesday) { - this.wednesday = wednesday; - } - - - public Boolean getThursday() { - return thursday; - } - - public void setThursday(Boolean thursday) { - this.thursday = thursday; - } - - - public Boolean getFriday() { - return friday; - } - - public void setFriday(Boolean friday) { - this.friday = friday; - } - - - public Boolean getSaturday() { - return saturday; - } - - public void setSaturday(Boolean saturday) { - this.saturday = saturday; - } - - - public Boolean getSunday() { - return sunday; - } - - public void setSunday(Boolean sunday) { - this.sunday = sunday; - } - - public Address getAddress() { - return address; - } - - public void setAddress(Address address) { - this.address = address; - } -} diff --git a/spring-data-rest-querydsl/src/main/java/com/baeldung/entity/User.java b/spring-data-rest-querydsl/src/main/java/com/baeldung/entity/User.java index adc6da724a..cfd484bb7a 100644 --- a/spring-data-rest-querydsl/src/main/java/com/baeldung/entity/User.java +++ b/spring-data-rest-querydsl/src/main/java/com/baeldung/entity/User.java @@ -1,17 +1,22 @@ package com.baeldung.entity; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonManagedReference; import javax.persistence.*; -import java.util.List; -@Entity @JsonIgnoreProperties({"hibernateLazyInitializer", "handler"}) public class User { +@Entity +@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"}) +public class User { - @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "id", unique = true, nullable = false) private Long id; - @Column private String name; - @OneToMany(fetch = FetchType.LAZY, mappedBy = "user") @JsonManagedReference private List
addresses; + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "id", unique = true, nullable = false) + private Long id; + @Column + private String name; + @OneToOne(fetch = FetchType.LAZY, mappedBy = "user") + private Address address; public User() { } @@ -36,11 +41,11 @@ import java.util.List; this.name = name; } - public List
getAddresses() { - return addresses; + public Address getAddress() { + return address; } - public void setAddresses(List
addresses) { - this.addresses = addresses; + public void setAddress(Address address) { + this.address = address; } } diff --git a/spring-data-rest-querydsl/src/test/java/com/baeldung/springdatarestquerydsl/QuerydslIntegrationTest.java b/spring-data-rest-querydsl/src/test/java/com/baeldung/springdatarestquerydsl/QuerydslIntegrationTest.java index ae972bcfcf..11e5ffca05 100644 --- a/spring-data-rest-querydsl/src/test/java/com/baeldung/springdatarestquerydsl/QuerydslIntegrationTest.java +++ b/spring-data-rest-querydsl/src/test/java/com/baeldung/springdatarestquerydsl/QuerydslIntegrationTest.java @@ -20,33 +20,46 @@ import static org.hamcrest.Matchers.is; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; -@RunWith(SpringJUnit4ClassRunner.class) @SpringBootTest(classes = Application.class) @WebAppConfiguration +@RunWith(SpringJUnit4ClassRunner.class) +@SpringBootTest(classes = Application.class) +@WebAppConfiguration public class QuerydslIntegrationTest { final MediaType contentType = new MediaType(MediaType.APPLICATION_JSON.getType(), MediaType.APPLICATION_JSON.getSubtype(), Charset.forName("utf8")); - @Autowired private WebApplicationContext webApplicationContext; + @Autowired + private WebApplicationContext webApplicationContext; private MockMvc mockMvc; - @Before public void setupMockMvc() { + @Before + public void setupMockMvc() { mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build(); } - @Test public void givenRequestHasBeenMade_whenQueryAddressFilteringByUserName_thenGetJohn() throws Exception { - mockMvc.perform(get("/addresses?user.name=John")).andExpect(status().isOk()).andExpect(content().contentType(contentType)) - .andExpect(jsonPath("$", hasSize(1))).andExpect(jsonPath("$[0].address", is("Fake Street 1"))) - .andExpect(jsonPath("$[0].country", is("Fake Country"))); + @Test + public void givenRequest_whenQueryUserFilteringByCountrySpain_thenGetJohn() throws Exception { + mockMvc.perform(get("/users?address.country=Spain")).andExpect(status().isOk()).andExpect(content() + .contentType + (contentType)) + .andExpect(jsonPath("$", hasSize(1))) + .andExpect(jsonPath("$[0].name", is("John"))) + .andExpect(jsonPath("$[0].address.address", is("Fake Street 1"))) + .andExpect(jsonPath("$[0].address.country", is("Spain"))); } - @Test public void givenRequestHasBeenMade_whenQueryOverAddressAvailabilityFilteringByAddressCountry_thenGetAvailability() - throws Exception { - mockMvc.perform(get("/addressAvailabilities?address.country=Real Country")).andExpect(status().isOk()) - .andExpect(content().contentType(contentType)).andExpect(jsonPath("$", hasSize(1))) - .andExpect(jsonPath("$[0].monday", is(false))).andExpect(jsonPath("$[0].tuesday", is(false))) - .andExpect(jsonPath("$[0].wednesday", is(false))).andExpect(jsonPath("$[0].thursday", is(false))) - .andExpect(jsonPath("$[0].friday", is(false))).andExpect(jsonPath("$[0].saturday", is(true))) - .andExpect(jsonPath("$[0].sunday", is(true))); + @Test + public void givenRequest_whenQueryUserWithoutFilter_thenGetJohnAndLisa() throws Exception { + mockMvc.perform(get("/users")).andExpect(status().isOk()).andExpect(content() + .contentType + (contentType)) + .andExpect(jsonPath("$", hasSize(2))) + .andExpect(jsonPath("$[0].name", is("John"))) + .andExpect(jsonPath("$[0].address.address", is("Fake Street 1"))) + .andExpect(jsonPath("$[0].address.country", is("Spain"))) + .andExpect(jsonPath("$[1].name", is("Lisa"))) + .andExpect(jsonPath("$[1].address.address", is("Real Street 1"))) + .andExpect(jsonPath("$[1].address.country", is("Germany"))); } } From 3e2d5441445a4e72c6941eaa0b36f5360cdd8803 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Collado=20Garc=C3=ADa?= Date: Fri, 8 Jun 2018 20:18:21 +0200 Subject: [PATCH 19/84] [BAEL-1686] - Updating test considerations --- spring-data-rest-querydsl/pom.xml | 4 ++ .../src/main/resources/application.yml | 2 +- .../IntegrationTest.java | 52 +++++++++++++++++++ 3 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 spring-data-rest-querydsl/src/test/java/com/baeldung/springdatarestquerydsl/IntegrationTest.java diff --git a/spring-data-rest-querydsl/pom.xml b/spring-data-rest-querydsl/pom.xml index 3b31e1835c..e4832e1552 100644 --- a/spring-data-rest-querydsl/pom.xml +++ b/spring-data-rest-querydsl/pom.xml @@ -94,4 +94,8 @@ +<<<<<<< HEAD +======= + +>>>>>>> 19a1633c35d6d49f9c51b8ecc3dbe127c91d75c3 diff --git a/spring-data-rest-querydsl/src/main/resources/application.yml b/spring-data-rest-querydsl/src/main/resources/application.yml index fe9dae345d..f25c6ea0e3 100644 --- a/spring-data-rest-querydsl/src/main/resources/application.yml +++ b/spring-data-rest-querydsl/src/main/resources/application.yml @@ -5,7 +5,7 @@ spring: pool-name: hikari-pool url: jdbc:mysql://localhost:3306/baeldung?verifyServerCertificate=false&useSSL=false&requireSSL=false username: root - password: admin + jpa: hibernate: ddl-auto: create diff --git a/spring-data-rest-querydsl/src/test/java/com/baeldung/springdatarestquerydsl/IntegrationTest.java b/spring-data-rest-querydsl/src/test/java/com/baeldung/springdatarestquerydsl/IntegrationTest.java new file mode 100644 index 0000000000..ef86c2f36d --- /dev/null +++ b/spring-data-rest-querydsl/src/test/java/com/baeldung/springdatarestquerydsl/IntegrationTest.java @@ -0,0 +1,52 @@ +package com.baeldung.springdatarestquerydsl; + +import com.baeldung.Application; +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.http.MediaType; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.web.WebAppConfiguration; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.setup.MockMvcBuilders; +import org.springframework.web.context.WebApplicationContext; + +import java.nio.charset.Charset; + +import static org.hamcrest.Matchers.hasSize; +import static org.hamcrest.Matchers.is; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; + +@RunWith(SpringJUnit4ClassRunner.class) @SpringBootTest(classes = Application.class) @WebAppConfiguration +public class IntegrationTest { + + final MediaType contentType = + new MediaType(MediaType.APPLICATION_JSON.getType(), MediaType.APPLICATION_JSON.getSubtype(), Charset.forName("utf8")); + + @Autowired private WebApplicationContext webApplicationContext; + + private MockMvc mockMvc; + + @Before public void setupMockMvc() { + mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build(); + } + + @Test public void givenRequestHasBeenMade_whenQueryOverNameAttribute_thenGetJohn() throws Exception { + // Get John + mockMvc.perform(get("/personQuery?name=John")).andExpect(status().isOk()).andExpect(content().contentType(contentType)) + .andExpect(jsonPath("$", hasSize(1))).andExpect(jsonPath("$[0].name", is("John"))) + .andExpect(jsonPath("$[0].address.address", is("Fake Street 1"))) + .andExpect(jsonPath("$[0].address.country", is("Fake Country"))); + } + + @Test public void givenRequestHasBeenMade_whenQueryOverNameAttribute_thenGetLisa() throws Exception { + // Get Lisa + mockMvc.perform(get("/personQuery?name=Lisa")).andExpect(status().isOk()).andExpect(content().contentType(contentType)) + .andExpect(jsonPath("$", hasSize(1))).andExpect(jsonPath("$[0].name", is("Lisa"))) + .andExpect(jsonPath("$[0].address.address", is("Real Street 1"))) + .andExpect(jsonPath("$[0].address.country", is("Real Country"))); + } +} From aaa9202883840f46f3f3230ea5553834a649beba Mon Sep 17 00:00:00 2001 From: Alessio Stalla Date: Fri, 8 Jun 2018 22:47:00 +0200 Subject: [PATCH 20/84] Code for BAEL-1812 (#4432) * Thin jar option for Spring Boot bootstrap and gradle projects. * .gitignore for spring-boot-gradle project. * Maven and Gradle 'thin' Boot builds (optional) * Rename 'wrapper' to 'thin' and shorten some lines of code to fit the article. --- parent-boot-2/pom.xml | 20 +++++++++++++ spring-boot-bootstrap/pom.xml | 22 ++++++++++++++ spring-boot-gradle/.gitignore | 2 ++ spring-boot-gradle/build.gradle | 29 +++++++++++++++++-- .../gradle/wrapper/gradle-wrapper.properties | 4 +-- 5 files changed, 72 insertions(+), 5 deletions(-) create mode 100644 spring-boot-gradle/.gitignore diff --git a/parent-boot-2/pom.xml b/parent-boot-2/pom.xml index a9c54dece9..625a96ff9d 100644 --- a/parent-boot-2/pom.xml +++ b/parent-boot-2/pom.xml @@ -105,6 +105,25 @@ + + thin-jar + + + + org.springframework.boot + spring-boot-maven-plugin + + + + org.springframework.boot.experimental + spring-boot-thin-layout + ${thin.version} + + + + + + @@ -115,6 +134,7 @@ 1.8 1.8 + 1.0.11.RELEASE \ No newline at end of file diff --git a/spring-boot-bootstrap/pom.xml b/spring-boot-bootstrap/pom.xml index ecc72c85f5..ff5bca615b 100644 --- a/spring-boot-bootstrap/pom.xml +++ b/spring-boot-bootstrap/pom.xml @@ -88,6 +88,28 @@ + + thin-jar + + + + org.springframework.boot.experimental + spring-boot-thin-maven-plugin + ${thin.version} + + + + resolve + + resolve + + false + + + + + + diff --git a/spring-boot-gradle/.gitignore b/spring-boot-gradle/.gitignore new file mode 100644 index 0000000000..192221b47d --- /dev/null +++ b/spring-boot-gradle/.gitignore @@ -0,0 +1,2 @@ +.gradle/ +build/ \ No newline at end of file diff --git a/spring-boot-gradle/build.gradle b/spring-boot-gradle/build.gradle index e602c485a9..96055536c3 100644 --- a/spring-boot-gradle/build.gradle +++ b/spring-boot-gradle/build.gradle @@ -1,12 +1,16 @@ buildscript { ext { - springBootVersion = '2.0.0.RELEASE' + springBootPlugin = 'org.springframework.boot:spring-boot-gradle-plugin' + springBootVersion = '2.0.2.RELEASE' + thinPlugin = 'org.springframework.boot.experimental:spring-boot-thin-gradle-plugin' + thinVersion = '1.0.11.RELEASE' } repositories { mavenCentral() } dependencies { - classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") + classpath("${springBootPlugin}:${springBootVersion}") + classpath("${thinPlugin}:${thinVersion}") } } @@ -14,6 +18,8 @@ apply plugin: 'java' apply plugin: 'eclipse' apply plugin: 'org.springframework.boot' apply plugin: 'io.spring.dependency-management' +//add tasks thinJar and thinResolve for thin JAR deployments +apply plugin: 'org.springframework.boot.experimental.thin-launcher' group = 'org.baeldung' version = '0.0.1-SNAPSHOT' @@ -23,7 +29,6 @@ repositories { mavenCentral() } - dependencies { compile('org.springframework.boot:spring-boot-starter') testCompile('org.springframework.boot:spring-boot-starter-test') @@ -42,3 +47,21 @@ bootJar { // attributes 'Start-Class': 'org.baeldung.DemoApplication' // } } + +//Enable this to generate and use a pom.xml file +apply plugin: 'maven' + +//If you want to customize the generated pom.xml you can edit this task and add it as a dependency to the bootJar task +task createPom { + def basePath = 'build/resources/main/META-INF/maven' + doLast { + pom { + withXml(dependencyManagement.pomConfigurer) + }.writeTo("${basePath}/${project.group}/${project.name}/pom.xml") + } +} +//Uncomment the following to use your custom generated pom.xml +bootJar.dependsOn = [createPom] + +//Enable this to generate and use a thin.properties file +//bootJar.dependsOn = [thinProperties] \ No newline at end of file diff --git a/spring-boot-gradle/gradle/wrapper/gradle-wrapper.properties b/spring-boot-gradle/gradle/wrapper/gradle-wrapper.properties index 44d9d03d80..a8868a918a 100644 --- a/spring-boot-gradle/gradle/wrapper/gradle-wrapper.properties +++ b/spring-boot-gradle/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Tue Feb 06 12:27:20 CET 2018 +#Fri Jun 01 20:39:48 CEST 2018 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.5.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-4.5.1-all.zip From 625ae336815891649f53210e8fc0a72284aea9bc Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Sat, 9 Jun 2018 10:36:09 +0300 Subject: [PATCH 21/84] upgrade to boot 2 --- spring-security-thymeleaf/pom.xml | 4 ++-- .../SecurityConfiguration.java | 11 +++++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/spring-security-thymeleaf/pom.xml b/spring-security-thymeleaf/pom.xml index aa36e5f59a..28d6126b55 100644 --- a/spring-security-thymeleaf/pom.xml +++ b/spring-security-thymeleaf/pom.xml @@ -10,10 +10,10 @@ Spring Security with Thymeleaf tutorial - parent-boot-5 + parent-boot-2 com.baeldung 0.0.1-SNAPSHOT - ../parent-boot-5 + ../parent-boot-2 diff --git a/spring-security-thymeleaf/src/main/java/com/baeldung/springsecuritythymeleaf/SecurityConfiguration.java b/spring-security-thymeleaf/src/main/java/com/baeldung/springsecuritythymeleaf/SecurityConfiguration.java index 687c0c2e39..0a4344db4d 100644 --- a/spring-security-thymeleaf/src/main/java/com/baeldung/springsecuritythymeleaf/SecurityConfiguration.java +++ b/spring-security-thymeleaf/src/main/java/com/baeldung/springsecuritythymeleaf/SecurityConfiguration.java @@ -1,11 +1,13 @@ package com.baeldung.springsecuritythymeleaf; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.security.web.util.matcher.AntPathRequestMatcher; @Configuration @@ -33,11 +35,16 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter { public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { auth.inMemoryAuthentication() .withUser("user") - .password("password") + .password(passwordEncoder().encode("password")) .roles("USER") .and() .withUser("admin") - .password("admin") + .password(passwordEncoder().encode("admin")) .roles("ADMIN"); } + + @Bean + public BCryptPasswordEncoder passwordEncoder() { + return new BCryptPasswordEncoder(); + } } From 6dad233602f252a07cefdf5b2a406e304f11c43b Mon Sep 17 00:00:00 2001 From: Grzegorz Piwowarek Date: Sat, 9 Jun 2018 11:29:35 +0200 Subject: [PATCH 22/84] BAEL-1758 Idiomatic Kotlin usage in enum (#4434) --- .../kotlin/com/baeldung/enums/CardType.kt | 41 ++++--------------- 1 file changed, 8 insertions(+), 33 deletions(-) diff --git a/core-kotlin/src/main/kotlin/com/baeldung/enums/CardType.kt b/core-kotlin/src/main/kotlin/com/baeldung/enums/CardType.kt index 013c8070bf..69cfce5601 100644 --- a/core-kotlin/src/main/kotlin/com/baeldung/enums/CardType.kt +++ b/core-kotlin/src/main/kotlin/com/baeldung/enums/CardType.kt @@ -2,46 +2,21 @@ package com.baeldung.enums enum class CardType(val color: String) : ICardLimit { SILVER("gray") { - override fun getCreditLimit(): Int { - return 100000 - } - - override fun calculateCashbackPercent(): Float { - return 0.25f - } + override fun getCreditLimit() = 100000 + override fun calculateCashbackPercent() = 0.25f }, GOLD("yellow") { - override fun getCreditLimit(): Int { - return 200000 - } - - override fun calculateCashbackPercent(): Float { - return 0.5f - } + override fun getCreditLimit() = 200000 + override fun calculateCashbackPercent(): Float = 0.5f }, PLATINUM("black") { - override fun getCreditLimit(): Int { - return 300000 - } - - override fun calculateCashbackPercent(): Float { - return 0.75f - } + override fun getCreditLimit() = 300000 + override fun calculateCashbackPercent() = 0.75f }; companion object { - fun getCardTypeByColor(color: String): CardType? { - for (cardType in CardType.values()) { - if (cardType.color.equals(color)) { - return cardType; - } - } - return null - } - - fun getCardTypeByName(name: String): CardType { - return CardType.valueOf(name.toUpperCase()) - } + fun getCardTypeByColor(color: String) = values().firstOrNull { it.color == color } + fun getCardTypeByName(name: String) = valueOf(name.toUpperCase()) } abstract fun calculateCashbackPercent(): Float From df85f99c981985a7b29120454bc9a3807560c724 Mon Sep 17 00:00:00 2001 From: KevinGilmore Date: Sat, 9 Jun 2018 10:53:21 -0500 Subject: [PATCH 23/84] BAEL-1766: Update README (#4435) --- spring-rest/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-rest/README.md b/spring-rest/README.md index c1183b500a..d1dcf554a5 100644 --- a/spring-rest/README.md +++ b/spring-rest/README.md @@ -22,4 +22,5 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [Guide to DeferredResult in Spring](http://www.baeldung.com/spring-deferred-result) - [Spring Custom Property Editor](http://www.baeldung.com/spring-mvc-custom-property-editor) - [Using the Spring RestTemplate Interceptor](http://www.baeldung.com/spring-rest-template-interceptor) +- [Configure a RestTemplate with RestTemplateBuilder](http://www.baeldung.com/spring-rest-template-builder) From eeb7d1c68e0b8e63558dc0099bb01e50d825dedd Mon Sep 17 00:00:00 2001 From: Alejandro Gervasio Date: Sat, 9 Jun 2018 21:56:29 -0300 Subject: [PATCH 24/84] Initial Commit (#4427) --- .../jpabootstrap/application/Application.java | 34 +++++ .../config/HibernatePersistenceUnitInfo.java | 131 ++++++++++++++++++ .../config/JpaEntityManagerFactory.java | 69 +++++++++ .../hibernate/jpabootstrap/entities/User.java | 45 ++++++ 4 files changed, 279 insertions(+) create mode 100644 hibernate5/src/main/java/com/baeldung/hibernate/jpabootstrap/application/Application.java create mode 100644 hibernate5/src/main/java/com/baeldung/hibernate/jpabootstrap/config/HibernatePersistenceUnitInfo.java create mode 100644 hibernate5/src/main/java/com/baeldung/hibernate/jpabootstrap/config/JpaEntityManagerFactory.java create mode 100644 hibernate5/src/main/java/com/baeldung/hibernate/jpabootstrap/entities/User.java diff --git a/hibernate5/src/main/java/com/baeldung/hibernate/jpabootstrap/application/Application.java b/hibernate5/src/main/java/com/baeldung/hibernate/jpabootstrap/application/Application.java new file mode 100644 index 0000000000..f7b8e6bf6d --- /dev/null +++ b/hibernate5/src/main/java/com/baeldung/hibernate/jpabootstrap/application/Application.java @@ -0,0 +1,34 @@ +package com.baeldung.hibernate.jpabootstrap.application; + +import com.baeldung.hibernate.jpabootstrap.config.JpaEntityManagerFactory; +import com.baeldung.hibernate.jpabootstrap.entities.User; +import javax.persistence.EntityManager; + +public class Application { + + public static void main(String[] args) { + EntityManager entityManager = getJpaEntityManager(); + User user = entityManager.find(User.class, 1); + System.out.println(user); + entityManager.getTransaction().begin(); + user.setName("John"); + user.setEmail("john@domain.com"); + entityManager.merge(user); + entityManager.getTransaction().commit(); + entityManager.getTransaction().begin(); + entityManager.persist(new User("Monica", "monica@domain.com")); + entityManager.getTransaction().commit(); + + // additional CRUD operations + + } + + private static class EntityManagerHolder { + private static final EntityManager ENTITY_MANAGER = new JpaEntityManagerFactory( + new Class[]{User.class}).getEntityManager(); + } + + public static EntityManager getJpaEntityManager() { + return EntityManagerHolder.ENTITY_MANAGER; + } +} \ No newline at end of file diff --git a/hibernate5/src/main/java/com/baeldung/hibernate/jpabootstrap/config/HibernatePersistenceUnitInfo.java b/hibernate5/src/main/java/com/baeldung/hibernate/jpabootstrap/config/HibernatePersistenceUnitInfo.java new file mode 100644 index 0000000000..3852b44b64 --- /dev/null +++ b/hibernate5/src/main/java/com/baeldung/hibernate/jpabootstrap/config/HibernatePersistenceUnitInfo.java @@ -0,0 +1,131 @@ +package com.baeldung.hibernate.jpabootstrap.config; + +import java.net.URL; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Properties; +import javax.sql.DataSource; +import javax.persistence.SharedCacheMode; +import javax.persistence.ValidationMode; +import javax.persistence.spi.ClassTransformer; +import javax.persistence.spi.PersistenceUnitInfo; +import javax.persistence.spi.PersistenceUnitTransactionType; +import org.hibernate.jpa.HibernatePersistenceProvider; + +public class HibernatePersistenceUnitInfo implements PersistenceUnitInfo { + + public static final String JPA_VERSION = "2.1"; + private final String persistenceUnitName; + private PersistenceUnitTransactionType transactionType = PersistenceUnitTransactionType.RESOURCE_LOCAL; + private final List managedClassNames; + private final List mappingFileNames = new ArrayList<>(); + private final Properties properties; + private DataSource jtaDataSource; + private DataSource nonjtaDataSource; + private final List transformers = new ArrayList<>(); + + public HibernatePersistenceUnitInfo(String persistenceUnitName, List managedClassNames, Properties properties) { + this.persistenceUnitName = persistenceUnitName; + this.managedClassNames = managedClassNames; + this.properties = properties; + } + + @Override + public String getPersistenceUnitName() { + return persistenceUnitName; + } + + @Override + public String getPersistenceProviderClassName() { + return HibernatePersistenceProvider.class.getName(); + } + + @Override + public PersistenceUnitTransactionType getTransactionType() { + return transactionType; + } + + public HibernatePersistenceUnitInfo setJtaDataSource(DataSource jtaDataSource) { + this.jtaDataSource = jtaDataSource; + this.nonjtaDataSource = null; + transactionType = PersistenceUnitTransactionType.JTA; + return this; + } + + @Override + public DataSource getJtaDataSource() { + return jtaDataSource; + } + + public HibernatePersistenceUnitInfo setNonJtaDataSource(DataSource nonJtaDataSource) { + this.nonjtaDataSource = nonJtaDataSource; + this.jtaDataSource = null; + transactionType = PersistenceUnitTransactionType.RESOURCE_LOCAL; + return this; + } + + @Override + public DataSource getNonJtaDataSource() { + return nonjtaDataSource; + } + + @Override + public List getMappingFileNames() { + return mappingFileNames; + } + + @Override + public List getJarFileUrls() { + return Collections.emptyList(); + } + + @Override + public URL getPersistenceUnitRootUrl() { + return null; + } + + @Override + public List getManagedClassNames() { + return managedClassNames; + } + + @Override + public boolean excludeUnlistedClasses() { + return false; + } + + @Override + public SharedCacheMode getSharedCacheMode() { + return SharedCacheMode.UNSPECIFIED; + } + + @Override + public ValidationMode getValidationMode() { + return ValidationMode.AUTO; + } + + public Properties getProperties() { + return properties; + } + + @Override + public String getPersistenceXMLSchemaVersion() { + return JPA_VERSION; + } + + @Override + public ClassLoader getClassLoader() { + return Thread.currentThread().getContextClassLoader(); + } + + @Override + public void addTransformer(ClassTransformer transformer) { + transformers.add(transformer); + } + + @Override + public ClassLoader getNewTempClassLoader() { + return null; + } +} \ No newline at end of file diff --git a/hibernate5/src/main/java/com/baeldung/hibernate/jpabootstrap/config/JpaEntityManagerFactory.java b/hibernate5/src/main/java/com/baeldung/hibernate/jpabootstrap/config/JpaEntityManagerFactory.java new file mode 100644 index 0000000000..bc1932af6f --- /dev/null +++ b/hibernate5/src/main/java/com/baeldung/hibernate/jpabootstrap/config/JpaEntityManagerFactory.java @@ -0,0 +1,69 @@ +package com.baeldung.hibernate.jpabootstrap.config; + +import com.mysql.cj.jdbc.MysqlDataSource; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.stream.Collectors; +import javax.persistence.EntityManager; +import javax.sql.DataSource; +import javax.persistence.EntityManagerFactory; +import javax.persistence.spi.PersistenceUnitInfo; +import org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl; +import org.hibernate.jpa.boot.internal.PersistenceUnitInfoDescriptor; + +public class JpaEntityManagerFactory { + + private final String DB_URL = "jdbc:mysql://databaseurl"; + private final String DB_USER_NAME = "username"; + private final String DB_PASSWORD = "password"; + private final Class[] entityClasses; + + public JpaEntityManagerFactory(Class[] entityClasses) { + this.entityClasses = entityClasses; + } + + public EntityManager getEntityManager() { + return getEntityManagerFactory().createEntityManager(); + } + + protected EntityManagerFactory getEntityManagerFactory() { + PersistenceUnitInfo persistenceUnitInfo = getPersistenceUnitInfo(getClass().getSimpleName()); + Map configuration = new HashMap<>(); + return new EntityManagerFactoryBuilderImpl(new PersistenceUnitInfoDescriptor(persistenceUnitInfo), configuration) + .build(); + } + + protected HibernatePersistenceUnitInfo getPersistenceUnitInfo(String name) { + return new HibernatePersistenceUnitInfo(name, getEntityClassNames(), getProperties()); + } + + protected List getEntityClassNames() { + return Arrays.asList(getEntities()) + .stream() + .map(Class::getName) + .collect(Collectors.toList()); + } + + protected Properties getProperties() { + Properties properties = new Properties(); + properties.put("hibernate.dialect", "org.hibernate.dialect.MySQLDialect"); + properties.put("hibernate.id.new_generator_mappings", false); + properties.put("hibernate.connection.datasource", getMysqlDataSource()); + return properties; + } + + protected Class[] getEntities() { + return entityClasses; + } + + protected DataSource getMysqlDataSource() { + MysqlDataSource mysqlDataSource = new MysqlDataSource(); + mysqlDataSource.setURL(DB_URL); + mysqlDataSource.setUser(DB_USER_NAME); + mysqlDataSource.setPassword(DB_PASSWORD); + return mysqlDataSource; + } +} \ No newline at end of file diff --git a/hibernate5/src/main/java/com/baeldung/hibernate/jpabootstrap/entities/User.java b/hibernate5/src/main/java/com/baeldung/hibernate/jpabootstrap/entities/User.java new file mode 100644 index 0000000000..86ca1dfa19 --- /dev/null +++ b/hibernate5/src/main/java/com/baeldung/hibernate/jpabootstrap/entities/User.java @@ -0,0 +1,45 @@ +package com.baeldung.hibernate.jpabootstrap.entities; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; + +@Entity +@Table(name = "users") +public class User { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private long id; + private String name; + private String email; + + public User(){} + + public User(String name, String email) { + this.name = name; + this.email = email; + } + + public void setName(String name) { + this.name = name; + } + + public void setEmail(String email) { + this.email = email; + } + + public long getId() { + return id; + } + + public String getName() { + return name; + } + + public String getEmail() { + return email; + } +} \ No newline at end of file From 8767e923a4e02ac72d9e1459bd7c13a475d7069d Mon Sep 17 00:00:00 2001 From: Grzegorz Piwowarek Date: Sun, 10 Jun 2018 08:02:41 +0200 Subject: [PATCH 25/84] Refactor MappingFrameworksPerfomance (#4436) * Refactor MappingFrameworksPerfomance * Increase warmups * Simplify tests --- .../MappingFrameworksPerformance.java | 158 +++++++----------- 1 file changed, 64 insertions(+), 94 deletions(-) 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 index 9a45f032a6..fe770aef24 100644 --- a/performance-tests/src/test/java/com/baeldung/performancetests/benchmark/MappingFrameworksPerformance.java +++ b/performance-tests/src/test/java/com/baeldung/performancetests/benchmark/MappingFrameworksPerformance.java @@ -4,13 +4,32 @@ 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.model.source.AccountStatus; +import com.baeldung.performancetests.model.source.Address; +import com.baeldung.performancetests.model.source.DeliveryData; +import com.baeldung.performancetests.model.source.Discount; +import com.baeldung.performancetests.model.source.OrderStatus; +import com.baeldung.performancetests.model.source.PaymentType; +import com.baeldung.performancetests.model.source.Product; +import com.baeldung.performancetests.model.source.RefundPolicy; +import com.baeldung.performancetests.model.source.Review; +import com.baeldung.performancetests.model.source.Shop; +import com.baeldung.performancetests.model.source.SourceCode; +import com.baeldung.performancetests.model.source.SourceOrder; +import com.baeldung.performancetests.model.source.User; 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.annotations.Benchmark; +import org.openjdk.jmh.annotations.BenchmarkMode; +import org.openjdk.jmh.annotations.Fork; +import org.openjdk.jmh.annotations.Group; +import org.openjdk.jmh.annotations.Measurement; +import org.openjdk.jmh.annotations.Mode; +import org.openjdk.jmh.annotations.OutputTimeUnit; +import org.openjdk.jmh.annotations.Scope; +import org.openjdk.jmh.annotations.Setup; +import org.openjdk.jmh.annotations.State; import org.openjdk.jmh.runner.RunnerException; import java.io.IOException; @@ -21,14 +40,24 @@ import java.util.Collections; import java.util.List; import java.util.concurrent.TimeUnit; +@Fork(value = 1, warmups = 5) +@OutputTimeUnit(TimeUnit.MILLISECONDS) +@BenchmarkMode(Mode.All) +@Measurement(iterations = 5) @State(Scope.Group) public class MappingFrameworksPerformance { - SourceOrder sourceOrder = null; - SourceCode sourceCode = null; + private SourceOrder sourceOrder = null; + private SourceCode sourceCode = null; + private static final OrikaConverter ORIKA_CONVERTER = new OrikaConverter(); + private static final JMapperConverter JMAPPER_CONVERTER = new JMapperConverter(); + private static final ModelMapperConverter MODEL_MAPPER_CONVERTER = new ModelMapperConverter(); + private static final DozerConverter DOZER_CONVERTER = new DozerConverter(); + @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!")); + RefundPolicy refundPolicy = new RefundPolicy(true, 30, Collections + .singletonList("Refundable only if not used!")); Product product = new Product(BigDecimal.valueOf(10.99), 100, @@ -51,7 +80,7 @@ public class MappingFrameworksPerformance { List reviewList = new ArrayList<>(); reviewList.add(review); reviewList.add(negativeReview); - Shop shop = new Shop("Super Shop", shopAddress,"www.super-shop.com",reviewList); + Shop shop = new Shop("Super Shop", shopAddress, "www.super-shop.com", reviewList); sourceOrder = new SourceOrder(OrderStatus.CONFIRMED, Instant.now().toString(), @@ -68,126 +97,67 @@ public class MappingFrameworksPerformance { 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); - + public Order orikaMapperRealLifeBenchmark() { + return ORIKA_CONVERTER.convert(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); + public Order jmapperRealLifeBenchmark() { + return JMAPPER_CONVERTER.convert(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); - + public Order modelMapperRealLifeBenchmark() { + return MODEL_MAPPER_CONVERTER.convert(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); + public Order dozerMapperRealLifeBenchmark() { + return DOZER_CONVERTER.convert(sourceOrder); + } + + @Benchmark + @Group("realLifeTest") + public Order mapStructRealLifeMapperBenchmark() { + return MapStructConverter.MAPPER.convert(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()); - + public DestinationCode orikaMapperSimpleBenchmark() { + return ORIKA_CONVERTER.convert(sourceCode); } @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()); + public DestinationCode jmapperSimpleBenchmark() { + return JMAPPER_CONVERTER.convert(sourceCode); } @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); - + public DestinationCode modelMapperBenchmark() { + return MODEL_MAPPER_CONVERTER.convert(sourceCode); } @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()); + public Order dozerMapperSimpleBenchmark() { + return DOZER_CONVERTER.convert(sourceOrder); } - + @Benchmark + @Group("simpleTest") + public DestinationCode mapStructMapperSimpleBenchmark() { + return MapStructConverter.MAPPER.convert(sourceCode); + } } From 28dae18f5b7c507a2fd50ce1e5435ea02b6346ce Mon Sep 17 00:00:00 2001 From: Tom Hombergs Date: Sun, 10 Jun 2018 08:02:54 +0200 Subject: [PATCH 26/84] Create README.md (#4422) --- spring-boot-ops/README.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 spring-boot-ops/README.md diff --git a/spring-boot-ops/README.md b/spring-boot-ops/README.md new file mode 100644 index 0000000000..02c4c100aa --- /dev/null +++ b/spring-boot-ops/README.md @@ -0,0 +1,3 @@ +### Relevant articles + +- [Deploy a Spring Boot WAR into a Tomcat Server](http://www.baeldung.com/spring-boot-war-tomcat-deploy) From ce4b42926f76e985f04375b3f429f47a88ac0ca5 Mon Sep 17 00:00:00 2001 From: charlesgonzales <39999268+charlesgonzales@users.noreply.github.com> Date: Sun, 10 Jun 2018 14:41:07 +0800 Subject: [PATCH 27/84] Add back-links and created new readme.md for the relevant articles (#4428) * Update README.md * Create README.MD add relevant article * Update README.MD * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Create README.md --- core-java/README.md | 6 ++++++ ethereumj/README.md | 1 + gson/README.md | 1 + javax-servlets/README.md | 1 + kotlin-js/README.md | 2 +- persistence-modules/spring-jpa/README.md | 1 + spring-boot-ops/README.MD | 3 +++ spring-boot/README.MD | 1 + spring-data-mongodb/README.md | 1 + spring-data-rest/README.md | 1 + spring-mvc-java/README.md | 1 + 11 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 spring-boot-ops/README.MD diff --git a/core-java/README.md b/core-java/README.md index 484b788974..79f7b4169e 100644 --- a/core-java/README.md +++ b/core-java/README.md @@ -150,3 +150,9 @@ - [NaN in Java](http://www.baeldung.com/java-not-a-number) - [Infinite Loops in Java](http://www.baeldung.com/infinite-loops-java) - [Why Use char[] Array Over a String for Storing Passwords in Java?](http://www.baeldung.com/java-storing-passwords) +- [Introduction to Creational Design Patterns](http://www.baeldung.com/creational-design-patterns) +- [Proxy, Decorator, Adapter and Bridge Patterns](http://www.baeldung.com/java-structural-design-patterns) +- [Singletons in Java](http://www.baeldung.com/java-singleton) +- [Flyweight Pattern in Java](http://www.baeldung.com/java-flyweight) +- [The Observer Pattern in Java](http://www.baeldung.com/java-observer-pattern) +- [Service Locator Pattern](http://www.baeldung.com/java-service-locator-pattern) diff --git a/ethereumj/README.md b/ethereumj/README.md index 5a0be0bd16..320ae8c9f8 100644 --- a/ethereumj/README.md +++ b/ethereumj/README.md @@ -3,3 +3,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) +- [Lightweight Ethereum Clients Using Web3j](http://www.baeldung.com/web3j) diff --git a/gson/README.md b/gson/README.md index 60c80477b1..bedfbd206c 100644 --- a/gson/README.md +++ b/gson/README.md @@ -6,3 +6,4 @@ ### Relevant Articles: - [Gson Deserialization Cookbook](http://www.baeldung.com/gson-deserialization-guide) - [Jackson vs Gson](http://www.baeldung.com/jackson-vs-gson) +- [Exclude Fields from Serialization in Gson](http://www.baeldung.com/gson-exclude-fields-serialization) diff --git a/javax-servlets/README.md b/javax-servlets/README.md index ef8ec168cf..de8a8e4498 100644 --- a/javax-servlets/README.md +++ b/javax-servlets/README.md @@ -3,3 +3,4 @@ - [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) - [Uploading Files with Servlets and JSP](http://www.baeldung.com/upload-file-servlet) +- [Example of Downloading File in a Servlet](http://www.baeldung.com/servlet-download-file) diff --git a/kotlin-js/README.md b/kotlin-js/README.md index 9ef8a999b4..445ad6da9a 100644 --- a/kotlin-js/README.md +++ b/kotlin-js/README.md @@ -1,3 +1,3 @@ -### Relevant articles +### Relevant Articles: - [Kotlin and Javascript](http://www.baeldung.com/kotlin-javascript) diff --git a/persistence-modules/spring-jpa/README.md b/persistence-modules/spring-jpa/README.md index cb71d386e2..02d4306ecb 100644 --- a/persistence-modules/spring-jpa/README.md +++ b/persistence-modules/spring-jpa/README.md @@ -22,6 +22,7 @@ - [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) +- [Spring Data Annotations](http://www.baeldung.com/spring-data-annotations) ### Eclipse Config After importing the project into Eclipse, you may see the following error: diff --git a/spring-boot-ops/README.MD b/spring-boot-ops/README.MD new file mode 100644 index 0000000000..26caccb727 --- /dev/null +++ b/spring-boot-ops/README.MD @@ -0,0 +1,3 @@ +### Relevant Articles: + +- [Deploy a Spring Boot WAR into a Tomcat Server](http://www.baeldung.com/spring-boot-war-tomcat-deploy) diff --git a/spring-boot/README.MD b/spring-boot/README.MD index dd3f930126..595e13cd9f 100644 --- a/spring-boot/README.MD +++ b/spring-boot/README.MD @@ -32,3 +32,4 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [How to Define a Spring Boot Filter?](http://www.baeldung.com/spring-boot-add-filter) - [How to Change the Default Port in Spring Boot](http://www.baeldung.com/spring-boot-change-port) - [Spring Boot Exit Codes](http://www.baeldung.com/spring-boot-exit-codes) +- [Guide to the Favicon in Spring Boot](http://www.baeldung.com/spring-boot-favicon) diff --git a/spring-data-mongodb/README.md b/spring-data-mongodb/README.md index c2a1f703b5..4e12a2218a 100644 --- a/spring-data-mongodb/README.md +++ b/spring-data-mongodb/README.md @@ -10,3 +10,4 @@ - [GridFS in Spring Data MongoDB](http://www.baeldung.com/spring-data-mongodb-gridfs) - [Introduction to Spring Data MongoDB](http://www.baeldung.com/spring-data-mongodb-tutorial) - [Spring Data MongoDB: Projections and Aggregations](http://www.baeldung.com/spring-data-mongodb-projections-aggregations) +- [Spring Data Annotations](http://www.baeldung.com/spring-data-annotations) diff --git a/spring-data-rest/README.md b/spring-data-rest/README.md index 445557d10b..09f8391406 100644 --- a/spring-data-rest/README.md +++ b/spring-data-rest/README.md @@ -19,3 +19,4 @@ To view the running application, visit [http://localhost:8080](http://localhost: - [AngularJS CRUD Application with Spring Data REST](http://www.baeldung.com/angularjs-crud-with-spring-data-rest) - [List of In-Memory Databases](http://www.baeldung.com/java-in-memory-databases) - [Projections and Excerpts in Spring Data REST](http://www.baeldung.com/spring-data-rest-projections-excerpts) +- [Spring Data REST Events with @RepositoryEventHandler](http://www.baeldung.com/spring-data-rest-events) diff --git a/spring-mvc-java/README.md b/spring-mvc-java/README.md index 1fd416d19f..877439145d 100644 --- a/spring-mvc-java/README.md +++ b/spring-mvc-java/README.md @@ -28,3 +28,4 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [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) - [A Quick Example of Spring Websockets’ @SendToUser Annotation](http://www.baeldung.com/spring-websockets-sendtouser) +- [Spring Boot Annotations](http://www.baeldung.com/spring-boot-annotations) From 8ebe69f176a827d805f7f055b08a9ed93f8efd24 Mon Sep 17 00:00:00 2001 From: psysane Date: Mon, 11 Jun 2018 00:19:21 +0530 Subject: [PATCH 28/84] Example unit test for the article "Count with JsonPath" --- .../src/main/resources/online_store.json | 21 +++++++++ .../introduction/JsonPathUnitTest.java | 46 +++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 json-path/src/main/resources/online_store.json create mode 100644 json-path/src/test/java/com/baeldung/jsonpath/introduction/JsonPathUnitTest.java diff --git a/json-path/src/main/resources/online_store.json b/json-path/src/main/resources/online_store.json new file mode 100644 index 0000000000..d8e2402b25 --- /dev/null +++ b/json-path/src/main/resources/online_store.json @@ -0,0 +1,21 @@ +{ + "items": { + "book": [ + { + "author": "Arthur Conan Doyle", + "title": "Sherlock Holmes", + "price": 8.99 + }, + { + "author": "J. R. R. Tolkien", + "title": "The Lord of the Rings", + "isbn": "0-395-19395-8", + "price": 22.99 + } + ], + "bicycle": { + "color": "red", + "price": 19.95 + } + } +} diff --git a/json-path/src/test/java/com/baeldung/jsonpath/introduction/JsonPathUnitTest.java b/json-path/src/test/java/com/baeldung/jsonpath/introduction/JsonPathUnitTest.java new file mode 100644 index 0000000000..6b780c9c10 --- /dev/null +++ b/json-path/src/test/java/com/baeldung/jsonpath/introduction/JsonPathUnitTest.java @@ -0,0 +1,46 @@ +package com.baeldung.jsonpath.introduction; + +import static org.junit.Assert.assertEquals; + +import java.io.File; +import java.io.IOException; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.util.Map; + +import org.junit.BeforeClass; +import org.junit.Test; + +import com.jayway.jsonpath.JsonPath; + +import net.minidev.json.JSONArray; + +public class JsonPathUnitTest { + + private static String json; + private static File jsonFile = new File("src/main/resources/online_store.json"); + + private static String readFile(File file, Charset charset) throws IOException { + return new String(Files.readAllBytes(file.toPath()), charset); + } + + @BeforeClass + public static void init() throws IOException { + json = readFile(jsonFile, StandardCharsets.UTF_8); + } + + @Test + public void shouldMatchCountOfObjects() { + Map objectMap = JsonPath.read(json, "$"); + assertEquals(1, objectMap.keySet() + .size()); + } + + @Test + public void shouldMatchCountOfArrays() { + JSONArray jsonArray = JsonPath.read(json, "$.items.book[*]"); + assertEquals(2, jsonArray.size()); + } + +} From 7f2c4e5535d742322b32ea7c746aecefba6967f6 Mon Sep 17 00:00:00 2001 From: Chandra Prakash Date: Sun, 10 Jun 2018 15:26:03 -0400 Subject: [PATCH 29/84] Added sample code for type inference. (#4443) --- .../typeinference/TypeInferenceUnitTest.java | 87 +++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 core-java-8/src/test/java/com/baeldung/typeinference/TypeInferenceUnitTest.java diff --git a/core-java-8/src/test/java/com/baeldung/typeinference/TypeInferenceUnitTest.java b/core-java-8/src/test/java/com/baeldung/typeinference/TypeInferenceUnitTest.java new file mode 100644 index 0000000000..b9600a18cb --- /dev/null +++ b/core-java-8/src/test/java/com/baeldung/typeinference/TypeInferenceUnitTest.java @@ -0,0 +1,87 @@ +package com.baeldung.typeinference; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.junit.Test; + +public class TypeInferenceUnitTest { + + @Test + public void givenNoTypeInference_whenInvokingGenericMethodsWithTypeParameters_ObjectsAreCreated() { + // Without type inference. code is verbose. + Map> mapOfMaps = new HashMap>(); + List strList = Collections. emptyList(); + List intList = Collections. emptyList(); + + assertTrue(mapOfMaps.isEmpty()); + assertTrue(strList.isEmpty()); + assertTrue(intList.isEmpty()); + } + + @Test + public void givenTypeInference_whenInvokingGenericMethodsWithoutTypeParameters_ObjectsAreCreated() { + // With type inference. code is concise. + List strListInferred = Collections.emptyList(); + List intListInferred = Collections.emptyList(); + + assertTrue(strListInferred.isEmpty()); + assertTrue(intListInferred.isEmpty()); + } + + @Test + public void givenJava7_whenInvokingCostructorWithoutTypeParameters_ObjectsAreCreated() { + // Type Inference for constructor using diamond operator. + Map> mapOfMapsInferred = new HashMap<>(); + + assertTrue(mapOfMapsInferred.isEmpty()); + assertEquals("public class java.util.HashMap", mapOfMapsInferred.getClass() + .toGenericString()); + } + + static List add(List list, T a, T b) { + list.add(a); + list.add(b); + return list; + } + + @Test + public void givenGenericMethod_WhenInvokedWithoutExplicitTypes_TypesAreInferred() { + // Generalized target-type inference + List strListGeneralized = add(new ArrayList<>(), "abc", "def"); + List intListGeneralized = add(new ArrayList<>(), 1, 2); + List numListGeneralized = add(new ArrayList<>(), 1, 2.0); + + assertEquals("public class java.util.ArrayList", strListGeneralized.getClass() + .toGenericString()); + assertFalse(intListGeneralized.isEmpty()); + assertEquals(2, numListGeneralized.size()); + } + + @Test + public void givenLambdaExpressions_whenParameterTypesNotSpecified_ParameterTypesAreInferred() { + // Type Inference and Lambda Expressions. + List intList = Arrays.asList(5, 3, 4, 2, 1); + Collections.sort(intList, (a, b) -> { + assertEquals("java.lang.Integer", a.getClass().getName()); + return a.compareTo(b); + }); + assertEquals("[1, 2, 3, 4, 5]", Arrays.toString(intList.toArray())); + + List strList = Arrays.asList("Red", "Blue", "Green"); + Collections.sort(strList, (a, b) -> { + assertEquals("java.lang.String", a.getClass().getName()); + return a.compareTo(b); + }); + assertEquals("[Blue, Green, Red]", Arrays.toString(strList.toArray())); + } + +} From 272497eaaf2641d2ddd4e1d59b8cc2ff6f524b3b Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Sun, 10 Jun 2018 22:30:59 +0300 Subject: [PATCH 30/84] pattern config filter --- .../bootcustomfilters/FilterConfig.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 spring-boot/src/main/java/com/baeldung/bootcustomfilters/FilterConfig.java diff --git a/spring-boot/src/main/java/com/baeldung/bootcustomfilters/FilterConfig.java b/spring-boot/src/main/java/com/baeldung/bootcustomfilters/FilterConfig.java new file mode 100644 index 0000000000..1946babc0e --- /dev/null +++ b/spring-boot/src/main/java/com/baeldung/bootcustomfilters/FilterConfig.java @@ -0,0 +1,25 @@ +package com.baeldung.bootcustomfilters; + +import org.springframework.boot.web.servlet.FilterRegistrationBean; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import com.baeldung.bootcustomfilters.filters.RequestResponseLoggingFilter; + +// uncomment this and comment the @Component in the filter class definition to register only for a url pattern +//@Configuration +public class FilterConfig { + + //@Bean + public FilterRegistrationBean loggingFilter(){ + FilterRegistrationBean registrationBean = new FilterRegistrationBean<>(); + + registrationBean.setFilter(new RequestResponseLoggingFilter()); + + registrationBean.addUrlPatterns("/users/*"); + + return registrationBean; + + } + +} From 45b74012530881ca8141b0885fa6d445f042efd0 Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Sun, 10 Jun 2018 22:36:58 +0300 Subject: [PATCH 31/84] text fix --- .../bootcustomfilters/FilterConfig.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/spring-boot/src/main/java/com/baeldung/bootcustomfilters/FilterConfig.java b/spring-boot/src/main/java/com/baeldung/bootcustomfilters/FilterConfig.java index 1946babc0e..aa794182de 100644 --- a/spring-boot/src/main/java/com/baeldung/bootcustomfilters/FilterConfig.java +++ b/spring-boot/src/main/java/com/baeldung/bootcustomfilters/FilterConfig.java @@ -6,20 +6,20 @@ import org.springframework.context.annotation.Configuration; import com.baeldung.bootcustomfilters.filters.RequestResponseLoggingFilter; -// uncomment this and comment the @Component in the filter class definition to register only for a url pattern -//@Configuration +@Configuration public class FilterConfig { - //@Bean - public FilterRegistrationBean loggingFilter(){ + // uncomment this and comment the @Component in the filter class definition to register only for a url pattern + // @Bean + public FilterRegistrationBean loggingFilter() { FilterRegistrationBean registrationBean = new FilterRegistrationBean<>(); - + registrationBean.setFilter(new RequestResponseLoggingFilter()); - + registrationBean.addUrlPatterns("/users/*"); - + return registrationBean; - + } - + } From c62b0a12a67bc91d23ca7264226a241654e6c72f Mon Sep 17 00:00:00 2001 From: Djordje Cvijetic Date: Sun, 10 Jun 2018 23:00:18 +0200 Subject: [PATCH 32/84] BAEL-1661 - Binding a List in Thymeleaf --- spring-mvc-forms-thymeleaf/pom.xml | 1 + .../com/baeldung/listbindingexample/Book.java | 73 +++++++++++++++++++ .../listbindingexample/BookService.java | 10 +++ .../listbindingexample/BooksCreationDto.java | 29 ++++++++ .../baeldung/listbindingexample/Config.java | 33 +++++++++ .../InMemoryBookService.java | 44 +++++++++++ .../ListBindingApplication.java | 16 ++++ .../MultipleBooksController.java | 59 +++++++++++++++ .../resources/templates/books/allBooks.html | 40 ++++++++++ .../templates/books/createBooksForm.html | 45 ++++++++++++ .../templates/books/editBooksForm.html | 49 +++++++++++++ .../main/resources/templates/books/index.html | 22 ++++++ 12 files changed, 421 insertions(+) create mode 100644 spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/Book.java create mode 100644 spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/BookService.java create mode 100644 spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/BooksCreationDto.java create mode 100644 spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/Config.java create mode 100644 spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/InMemoryBookService.java create mode 100644 spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/ListBindingApplication.java create mode 100644 spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/MultipleBooksController.java create mode 100644 spring-mvc-forms-thymeleaf/src/main/resources/templates/books/allBooks.html create mode 100644 spring-mvc-forms-thymeleaf/src/main/resources/templates/books/createBooksForm.html create mode 100644 spring-mvc-forms-thymeleaf/src/main/resources/templates/books/editBooksForm.html create mode 100644 spring-mvc-forms-thymeleaf/src/main/resources/templates/books/index.html diff --git a/spring-mvc-forms-thymeleaf/pom.xml b/spring-mvc-forms-thymeleaf/pom.xml index 408e7643d2..59130a0133 100644 --- a/spring-mvc-forms-thymeleaf/pom.xml +++ b/spring-mvc-forms-thymeleaf/pom.xml @@ -69,6 +69,7 @@ UTF-8 UTF-8 3.0.9.RELEASE + com.baeldung.sessionattrs.SessionAttrsApplication diff --git a/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/Book.java b/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/Book.java new file mode 100644 index 0000000000..823ff436fb --- /dev/null +++ b/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/Book.java @@ -0,0 +1,73 @@ +package com.baeldung.listbindingexample; + +public class Book { + + private long id; + + private String title; + + private String author; + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getAuthor() { + return author; + } + + public void setAuthor(String author) { + this.author = author; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((author == null) ? 0 : author.hashCode()); + result = prime * result + (int) (id ^ (id >>> 32)); + result = prime * result + ((title == null) ? 0 : title.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Book other = (Book) obj; + if (author == null) { + if (other.author != null) + return false; + } else if (!author.equals(other.author)) + return false; + if (id != other.id) + return false; + if (title == null) { + if (other.title != null) + return false; + } else if (!title.equals(other.title)) + return false; + return true; + } + + @Override + public String toString() { + return "Book [id=" + id + ", title=" + title + ", author=" + author + "]"; + } +} diff --git a/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/BookService.java b/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/BookService.java new file mode 100644 index 0000000000..770e86ad68 --- /dev/null +++ b/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/BookService.java @@ -0,0 +1,10 @@ +package com.baeldung.listbindingexample; + +import java.util.List; + +public interface BookService { + + List findAll(); + + void saveAll(List books); +} diff --git a/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/BooksCreationDto.java b/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/BooksCreationDto.java new file mode 100644 index 0000000000..8e5654143a --- /dev/null +++ b/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/BooksCreationDto.java @@ -0,0 +1,29 @@ +package com.baeldung.listbindingexample; + +import java.util.ArrayList; +import java.util.List; + +public class BooksCreationDto { + + private List books; + + public BooksCreationDto() { + this.books = new ArrayList<>(); + } + + public BooksCreationDto(List books) { + this.books = books; + } + + public List getBooks() { + return books; + } + + public void setBooks(List books) { + this.books = books; + } + + public void addBook(Book book) { + this.books.add(book); + } +} diff --git a/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/Config.java b/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/Config.java new file mode 100644 index 0000000000..ffba2cea2c --- /dev/null +++ b/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/Config.java @@ -0,0 +1,33 @@ +package com.baeldung.listbindingexample; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.Ordered; +import org.springframework.web.servlet.config.annotation.EnableWebMvc; +import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; +import org.thymeleaf.templatemode.TemplateMode; +import org.thymeleaf.templateresolver.ClassLoaderTemplateResolver; +import org.thymeleaf.templateresolver.ITemplateResolver; + +@EnableWebMvc +@Configuration +public class Config implements WebMvcConfigurer { + + @Override + public void addViewControllers(ViewControllerRegistry registry) { + registry.addViewController("/").setViewName("index"); + registry.setOrder(Ordered.HIGHEST_PRECEDENCE); + } + + @Bean + public ITemplateResolver templateResolver() { + ClassLoaderTemplateResolver resolver + = new ClassLoaderTemplateResolver(); + resolver.setPrefix("templates/books/"); + resolver.setSuffix(".html"); + resolver.setTemplateMode(TemplateMode.HTML); + resolver.setCharacterEncoding("UTF-8"); + return resolver; + } +} diff --git a/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/InMemoryBookService.java b/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/InMemoryBookService.java new file mode 100644 index 0000000000..56ca41c51f --- /dev/null +++ b/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/InMemoryBookService.java @@ -0,0 +1,44 @@ +package com.baeldung.listbindingexample; + +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.function.Function; +import java.util.stream.Collectors; + +@Service +public class InMemoryBookService implements BookService { + + static Map booksDB = new HashMap<>(); + + @Override + public List findAll() { + return new ArrayList(booksDB.values()); + } + + @Override + public void saveAll(List books) { + long nextId = getNextId(); + for (Book book : books) { + if (book.getId() == 0) { + book.setId(nextId++); + } + } + + Map bookMap = books.stream() + .collect(Collectors.toMap( + Book::getId, Function.identity())); + + booksDB.putAll(bookMap); + } + + private Long getNextId(){ + return booksDB.keySet().stream() + .mapToLong(value -> value) + .max() + .orElse(0) + 1; + } +} diff --git a/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/ListBindingApplication.java b/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/ListBindingApplication.java new file mode 100644 index 0000000000..af8608704b --- /dev/null +++ b/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/ListBindingApplication.java @@ -0,0 +1,16 @@ +package com.baeldung.listbindingexample; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; +import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration; + +@SpringBootApplication( + exclude = {SecurityAutoConfiguration.class, + DataSourceAutoConfiguration.class}) +public class ListBindingApplication { + + public static void main(String[] args) { + SpringApplication.run(ListBindingApplication.class, args); + } +} diff --git a/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/MultipleBooksController.java b/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/MultipleBooksController.java new file mode 100644 index 0000000000..2e177c7bbf --- /dev/null +++ b/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/MultipleBooksController.java @@ -0,0 +1,59 @@ +package com.baeldung.listbindingexample; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; + +import java.util.ArrayList; +import java.util.List; + +@Controller +@RequestMapping("/books") +public class MultipleBooksController { + + @Autowired + private BookService bookService; + + @GetMapping(value = "/all") + public String showAll(Model model) { + model.addAttribute("books", bookService.findAll()); + + return "allBooks"; + } + + @GetMapping(value = "/create") + public String showCreateForm(Model model) { + BooksCreationDto booksForm = new BooksCreationDto(); + + for (int i = 1; i <= 3; i++) { + booksForm.addBook(new Book()); + } + + model.addAttribute("form", booksForm); + + return "createBooksForm"; + } + + @GetMapping(value = "/edit") + public String showEditForm(Model model) { + List books = new ArrayList<>(); + bookService.findAll().iterator().forEachRemaining(books::add); + + model.addAttribute("form", new BooksCreationDto(books)); + + return "editBooksForm"; + } + + @PostMapping(value = "/save") + public String saveBooks(@ModelAttribute BooksCreationDto form, Model model) { + bookService.saveAll(form.getBooks()); + + model.addAttribute("books", bookService.findAll()); + + return "redirect:/books/all"; + } +} diff --git a/spring-mvc-forms-thymeleaf/src/main/resources/templates/books/allBooks.html b/spring-mvc-forms-thymeleaf/src/main/resources/templates/books/allBooks.html new file mode 100644 index 0000000000..9f75bec8bd --- /dev/null +++ b/spring-mvc-forms-thymeleaf/src/main/resources/templates/books/allBooks.html @@ -0,0 +1,40 @@ + + + All Books + + + +
+
+
+

Books

+
+
+
+
+ + + + + + + + + + + + + + + + +
Title Author
No Books Available
Title Author
+
+ +
+
+ + diff --git a/spring-mvc-forms-thymeleaf/src/main/resources/templates/books/createBooksForm.html b/spring-mvc-forms-thymeleaf/src/main/resources/templates/books/createBooksForm.html new file mode 100644 index 0000000000..9f88762882 --- /dev/null +++ b/spring-mvc-forms-thymeleaf/src/main/resources/templates/books/createBooksForm.html @@ -0,0 +1,45 @@ + + + Add Books + + + +
+
+
+

Add Books

+
+
+
+
+ Back to All Books +
+
+ + + + + + + + + + + + + + + + + +
Title Author
+
+
+
+
+
+ + diff --git a/spring-mvc-forms-thymeleaf/src/main/resources/templates/books/editBooksForm.html b/spring-mvc-forms-thymeleaf/src/main/resources/templates/books/editBooksForm.html new file mode 100644 index 0000000000..9278d98018 --- /dev/null +++ b/spring-mvc-forms-thymeleaf/src/main/resources/templates/books/editBooksForm.html @@ -0,0 +1,49 @@ + + + Edit Books + + + +
+
+
+

Add Books

+
+
+
+
+ Back to All Books +
+
+ + + + + + + + + + + + + + + + + + + +
Title Author
+
+
+
+
+
+ + diff --git a/spring-mvc-forms-thymeleaf/src/main/resources/templates/books/index.html b/spring-mvc-forms-thymeleaf/src/main/resources/templates/books/index.html new file mode 100644 index 0000000000..59780b84aa --- /dev/null +++ b/spring-mvc-forms-thymeleaf/src/main/resources/templates/books/index.html @@ -0,0 +1,22 @@ + + + + Binding a List in Thymeleaf + + + + + + + +
+

+

Binding a List in Thymeleaf - Example

+

+
+ + + From 40d3b968206e958bd185f095bb2763d9965b53bb Mon Sep 17 00:00:00 2001 From: sachinp054 Date: Mon, 11 Jun 2018 04:36:27 +0530 Subject: [PATCH 33/84] BAEL-1715- Control Bean Creation Order with @DependsOn annotation (#4028) * removing Bean injection * BAEL-1715- Control Bean Creation Order with @DependsOn annotation * BAEL-1715- Formatting changes, test case improvement * Created new Config file for UnitTest * Corrected test case- from BeanCreationException to NoSuchBeanDefinitionException * correcting error- for circular dependency expected exception is- BeanCreationException --- .../baeldung/dependson/DriverApplication.java | 14 +++++ .../com/baeldung/dependson/config/Config.java | 38 ++++++++++++ .../file/processor/FileProcessor.java | 19 ++++++ .../dependson/file/reader/FileReader.java | 12 ++++ .../dependson/file/writer/FileWriter.java | 13 ++++ .../com/baeldung/dependson/shared/File.java | 17 ++++++ .../baeldung/dependson/config/TestConfig.java | 59 +++++++++++++++++++ .../processor/FileProcessorTest.java | 42 +++++++++++++ 8 files changed, 214 insertions(+) create mode 100644 spring-core/src/main/java/com/baeldung/dependson/DriverApplication.java create mode 100644 spring-core/src/main/java/com/baeldung/dependson/config/Config.java create mode 100644 spring-core/src/main/java/com/baeldung/dependson/file/processor/FileProcessor.java create mode 100644 spring-core/src/main/java/com/baeldung/dependson/file/reader/FileReader.java create mode 100644 spring-core/src/main/java/com/baeldung/dependson/file/writer/FileWriter.java create mode 100644 spring-core/src/main/java/com/baeldung/dependson/shared/File.java create mode 100644 spring-core/src/test/java/com/baeldung/dependson/config/TestConfig.java create mode 100644 spring-core/src/test/java/com/baeldung/dependson/processor/FileProcessorTest.java diff --git a/spring-core/src/main/java/com/baeldung/dependson/DriverApplication.java b/spring-core/src/main/java/com/baeldung/dependson/DriverApplication.java new file mode 100644 index 0000000000..166f388aa3 --- /dev/null +++ b/spring-core/src/main/java/com/baeldung/dependson/DriverApplication.java @@ -0,0 +1,14 @@ +package com.baeldung.dependson; + +import org.springframework.context.annotation.AnnotationConfigApplicationContext; + +import com.baeldung.dependson.config.Config; +import com.baeldung.dependson.file.processor.FileProcessor; + +public class DriverApplication { + public static void main(String[] args) { + AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(Config.class); + ctx.getBean(FileProcessor.class); + ctx.close(); + } +} diff --git a/spring-core/src/main/java/com/baeldung/dependson/config/Config.java b/spring-core/src/main/java/com/baeldung/dependson/config/Config.java new file mode 100644 index 0000000000..8d96707ba6 --- /dev/null +++ b/spring-core/src/main/java/com/baeldung/dependson/config/Config.java @@ -0,0 +1,38 @@ +package com.baeldung.dependson.config; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.DependsOn; +import org.springframework.context.annotation.Lazy; + +import com.baeldung.dependson.file.processor.FileProcessor; +import com.baeldung.dependson.file.reader.FileReader; +import com.baeldung.dependson.file.writer.FileWriter; +import com.baeldung.dependson.shared.File; + +@Configuration +@ComponentScan("com.baeldung.dependson") +public class Config { + + @Autowired + File file; + + @Bean("fileProcessor") + @DependsOn({"fileReader","fileWriter"}) + @Lazy + public FileProcessor fileProcessor(){ + return new FileProcessor(file); + } + + @Bean("fileReader") + public FileReader fileReader(){ + return new FileReader(file); + } + + @Bean("fileWriter") + public FileWriter fileWriter(){ + return new FileWriter(file); + } +} diff --git a/spring-core/src/main/java/com/baeldung/dependson/file/processor/FileProcessor.java b/spring-core/src/main/java/com/baeldung/dependson/file/processor/FileProcessor.java new file mode 100644 index 0000000000..f5d55dc032 --- /dev/null +++ b/spring-core/src/main/java/com/baeldung/dependson/file/processor/FileProcessor.java @@ -0,0 +1,19 @@ +package com.baeldung.dependson.file.processor; + +import org.springframework.beans.factory.annotation.Autowired; + +import com.baeldung.dependson.file.reader.FileReader; +import com.baeldung.dependson.file.writer.FileWriter; +import com.baeldung.dependson.shared.File; + +public class FileProcessor { + + File file; + + public FileProcessor(File file){ + this.file = file; + if(file.getText().contains("write") && file.getText().contains("read")){ + file.setText("processed"); + } + } +} \ No newline at end of file diff --git a/spring-core/src/main/java/com/baeldung/dependson/file/reader/FileReader.java b/spring-core/src/main/java/com/baeldung/dependson/file/reader/FileReader.java new file mode 100644 index 0000000000..b6ff446534 --- /dev/null +++ b/spring-core/src/main/java/com/baeldung/dependson/file/reader/FileReader.java @@ -0,0 +1,12 @@ +package com.baeldung.dependson.file.reader; + +import com.baeldung.dependson.shared.File; + +public class FileReader { + + public FileReader(File file) { + file.setText("read"); + } + + public void readFile() {} +} diff --git a/spring-core/src/main/java/com/baeldung/dependson/file/writer/FileWriter.java b/spring-core/src/main/java/com/baeldung/dependson/file/writer/FileWriter.java new file mode 100644 index 0000000000..f251166c80 --- /dev/null +++ b/spring-core/src/main/java/com/baeldung/dependson/file/writer/FileWriter.java @@ -0,0 +1,13 @@ +package com.baeldung.dependson.file.writer; + +import com.baeldung.dependson.shared.File; + + +public class FileWriter { + + public FileWriter(File file){ + file.setText("write"); + } + + public void writeFile(){} +} diff --git a/spring-core/src/main/java/com/baeldung/dependson/shared/File.java b/spring-core/src/main/java/com/baeldung/dependson/shared/File.java new file mode 100644 index 0000000000..c1b1badc43 --- /dev/null +++ b/spring-core/src/main/java/com/baeldung/dependson/shared/File.java @@ -0,0 +1,17 @@ +package com.baeldung.dependson.shared; + +import org.springframework.stereotype.Service; + +@Service +public class File { + + private String text = ""; + + public String getText() { + return text; + } + + public void setText(String text) { + this.text = this.text+text; + } +} diff --git a/spring-core/src/test/java/com/baeldung/dependson/config/TestConfig.java b/spring-core/src/test/java/com/baeldung/dependson/config/TestConfig.java new file mode 100644 index 0000000000..f4b2e39ebc --- /dev/null +++ b/spring-core/src/test/java/com/baeldung/dependson/config/TestConfig.java @@ -0,0 +1,59 @@ +package com.baeldung.dependson.config; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.DependsOn; +import org.springframework.context.annotation.Lazy; + +import com.baeldung.dependson.file.processor.FileProcessor; +import com.baeldung.dependson.file.reader.FileReader; +import com.baeldung.dependson.file.writer.FileWriter; +import com.baeldung.dependson.shared.File; + +@Configuration +@ComponentScan("com.baeldung.dependson") +public class TestConfig { + + @Autowired + File file; + + @Bean("fileProcessor") + @DependsOn({"fileReader","fileWriter"}) + @Lazy + public FileProcessor fileProcessor(){ + return new FileProcessor(file); + } + + @Bean("fileReader") + public FileReader fileReader(){ + return new FileReader(file); + } + + @Bean("fileWriter") + public FileWriter fileWriter(){ + return new FileWriter(file); + } + + @Bean("dummyFileProcessor") + @DependsOn({"dummyfileWriter"}) + @Lazy + public FileProcessor dummyFileProcessor(){ + return new FileProcessor(file); + } + + @Bean("dummyFileProcessorCircular") + @DependsOn({"dummyFileReaderCircular"}) + @Lazy + public FileProcessor dummyFileProcessorCircular(){ + return new FileProcessor(file); + } + + @Bean("dummyFileReaderCircular") + @DependsOn({"dummyFileProcessorCircular"}) + @Lazy + public FileReader dummyFileReaderCircular(){ + return new FileReader(file); + } +} diff --git a/spring-core/src/test/java/com/baeldung/dependson/processor/FileProcessorTest.java b/spring-core/src/test/java/com/baeldung/dependson/processor/FileProcessorTest.java new file mode 100644 index 0000000000..b54ac16125 --- /dev/null +++ b/spring-core/src/test/java/com/baeldung/dependson/processor/FileProcessorTest.java @@ -0,0 +1,42 @@ +package com.baeldung.dependson.processor; + +import static org.junit.Assert.assertTrue; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.BeanCreationException; +import org.springframework.beans.factory.NoSuchBeanDefinitionException; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationContext; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +import com.baeldung.dependson.config.TestConfig; +import com.baeldung.dependson.shared.File; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(classes = TestConfig.class) +public class FileProcessorTest { + + @Autowired + ApplicationContext context; + + @Autowired + File file; + + @Test + public void whenAllBeansCreated_FileTextEndsWithProcessed() { + context.getBean("fileProcessor"); + assertTrue(file.getText().endsWith("processed")); + } + + @Test(expected=NoSuchBeanDefinitionException.class) + public void whenDependentBeanNotAvailable_ThrowsNoSuchBeanDefinitionException(){ + context.getBean("dummyFileProcessor"); + } + + @Test(expected=BeanCreationException.class) + public void whenCircularDependency_ThrowsBeanCreationException(){ + context.getBean("dummyFileReaderCircular"); + } +} From ea37ada296b721892d5c2fb4a37a6413fac8f70b Mon Sep 17 00:00:00 2001 From: Eric Goebelbecker Date: Sun, 10 Jun 2018 22:00:21 -0400 Subject: [PATCH 34/84] BAEL-1614 - additions for docker (#4455) --- spring-boot-ops/docker/Dockerfile | 16 ++++++++++++++++ spring-boot-ops/docker/logback.xml | 15 +++++++++++++++ spring-boot-ops/docker/run.sh | 4 ++++ spring-boot-ops/pom.xml | 3 ++- 4 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 spring-boot-ops/docker/Dockerfile create mode 100644 spring-boot-ops/docker/logback.xml create mode 100755 spring-boot-ops/docker/run.sh diff --git a/spring-boot-ops/docker/Dockerfile b/spring-boot-ops/docker/Dockerfile new file mode 100644 index 0000000000..85db5c7bed --- /dev/null +++ b/spring-boot-ops/docker/Dockerfile @@ -0,0 +1,16 @@ +# Alpine Linux with OpenJDK JRE +FROM openjdk:8-jre-alpine +RUN apk add --no-cache bash + +# copy fat WAR +COPY spring-boot-ops.war /app.war + +# copy fat WAR +COPY logback.xml /logback.xml + +COPY run.sh /run.sh + +# runs application +#CMD ["/usr/bin/java", "-jar", "-Dspring.profiles.active=default", "-Dlogging.config=/logback.xml", "/app.war"] + +ENTRYPOINT ["/run.sh"] diff --git a/spring-boot-ops/docker/logback.xml b/spring-boot-ops/docker/logback.xml new file mode 100644 index 0000000000..aad6d3fcb3 --- /dev/null +++ b/spring-boot-ops/docker/logback.xml @@ -0,0 +1,15 @@ + + + + + /var/log/WebjarsdemoApplication/application.log + true + + %-7d{yyyy-MM-dd HH:mm:ss:SSS} %m%n + + + + + + + diff --git a/spring-boot-ops/docker/run.sh b/spring-boot-ops/docker/run.sh new file mode 100755 index 0000000000..aeecc29371 --- /dev/null +++ b/spring-boot-ops/docker/run.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +java -Dspring.profiles.active=$1 -Dlogging.config=/logback.xml -jar /app.war + diff --git a/spring-boot-ops/pom.xml b/spring-boot-ops/pom.xml index b6adb27fb2..b34fef8e6f 100644 --- a/spring-boot-ops/pom.xml +++ b/spring-boot-ops/pom.xml @@ -137,7 +137,8 @@ repackage - org.baeldung.boot.Application + com.baeldung.webjar.WebjarsdemoApplication + ${project.basedir}/docker From 7e66e1b9191c70af81b9b95b21210579e8a5a9ea Mon Sep 17 00:00:00 2001 From: nguyennamthai Date: Mon, 11 Jun 2018 09:44:29 +0700 Subject: [PATCH 35/84] BAEL-1801 Add tests for unsigned arithmetic (#4442) --- .../java8/UnsignedArithmeticUnitTest.java | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 core-java-8/src/test/java/com/baeldung/java8/UnsignedArithmeticUnitTest.java diff --git a/core-java-8/src/test/java/com/baeldung/java8/UnsignedArithmeticUnitTest.java b/core-java-8/src/test/java/com/baeldung/java8/UnsignedArithmeticUnitTest.java new file mode 100644 index 0000000000..e79c90b684 --- /dev/null +++ b/core-java-8/src/test/java/com/baeldung/java8/UnsignedArithmeticUnitTest.java @@ -0,0 +1,60 @@ +package com.baeldung.java8; + +import org.junit.Test; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.catchThrowable; +import static org.junit.Assert.assertEquals; + +public class UnsignedArithmeticUnitTest { + @Test + public void whenDoublingALargeByteNumber_thenOverflow() { + byte b1 = 100; + byte b2 = (byte) (b1 << 1); + + assertEquals(-56, b2); + } + + @Test + public void whenComparingNumbers_thenNegativeIsInterpretedAsUnsigned() { + int positive = Integer.MAX_VALUE; + int negative = Integer.MIN_VALUE; + + int signedComparison = Integer.compare(positive, negative); + assertEquals(1, signedComparison); + + int unsignedComparison = Integer.compareUnsigned(positive, negative); + assertEquals(-1, unsignedComparison); + + assertEquals(negative, positive + 1); + } + + @Test + public void whenDividingNumbers_thenNegativeIsInterpretedAsUnsigned() { + int positive = Integer.MAX_VALUE; + int negative = Integer.MIN_VALUE; + + assertEquals(-1, negative / positive); + assertEquals(1, Integer.divideUnsigned(negative, positive)); + + assertEquals(-1, negative % positive); + assertEquals(1, Integer.divideUnsigned(negative, positive)); + } + + @Test + public void whenParsingNumbers_thenNegativeIsInterpretedAsUnsigned() { + Throwable thrown = catchThrowable(() -> Integer.parseInt("2147483648")); + assertThat(thrown).isInstanceOf(NumberFormatException.class); + + assertEquals(Integer.MAX_VALUE + 1, Integer.parseUnsignedInt("2147483648")); + } + + @Test + public void whenFormattingNumbers_thenNegativeIsInterpretedAsUnsigned() { + String signedString = Integer.toString(Integer.MIN_VALUE); + assertEquals("-2147483648", signedString); + + String unsignedString = Integer.toUnsignedString(Integer.MIN_VALUE); + assertEquals("2147483648", unsignedString); + } +} From 293d4bc9aaa067f382d186f98c26f88734dbe9b3 Mon Sep 17 00:00:00 2001 From: charlesgonzales <39999268+charlesgonzales@users.noreply.github.com> Date: Mon, 11 Jun 2018 12:37:23 +0800 Subject: [PATCH 36/84] Create README.md (#4454) * Update README.md * Create README.MD add relevant article * Update README.MD * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Create README.md * Create README.md --- msf4j/README.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 msf4j/README.md diff --git a/msf4j/README.md b/msf4j/README.md new file mode 100644 index 0000000000..19e611832c --- /dev/null +++ b/msf4j/README.md @@ -0,0 +1,3 @@ +### Relevant Articles: + +- [Introduction to Java Microservices with MSF4J](http://www.baeldung.com/spring-boot-war-tomcat-deploy) From a54c9e0c9eb5103685b5a4aa41c0950ca1714942 Mon Sep 17 00:00:00 2001 From: Amit Pandey Date: Mon, 11 Jun 2018 13:48:30 +0530 Subject: [PATCH 37/84] Bael 4461 2 (#4444) * [BAEL-4462] - Fixed integration tests * [BAEL-4462] - Fixed integration tests * [BAEL-4462] - Fixed integration tests * [BAEL-4462] - Fixed integration tests * [BAEL-4462] - Fixed integration tests * [BAEL-4462] - Fixed integration tests * [BAEL-4462] - Fixed integration tests * [BAEL-4462] - Fixed integration tests * [BAEL-4462] - Fixed integration tests * [BAEL-4462] - Fixed integration tests * [BAEL-4462] - Fixed integration tests * [BAEL-4462] - Fixed integration tests * [BAEL-4462] - Fixed integration tests * [BAEL-4462] - Fixed integration tests * Fix verification times --- .../powerpoint/PowerPointIntegrationTest.java | 13 +++-- .../baeldung/array/JaggedArrayUnitTest.java | 2 +- .../money/JavaMoneyUnitManualTest.java | 2 +- .../baeldung/scripting/NashornUnitTest.java | 2 +- .../async/service/ClusterServiceImpl.java | 6 ++ .../async/service/TutorialBucketService.java | 1 + ...ersonCrudServiceIntegrationTestConfig.java | 24 ++++++++ ...st.java => PersonCrudServiceLiveTest.java} | 22 +++++--- ...nTest.java => ClusterServiceLiveTest.java} | 2 +- ....java => StudentGradeServiceLiveTest.java} | 4 +- ...IntegrationTest.java => N1QLLiveTest.java} | 37 ++++++------ ...st.java => PersonCrudServiceLiveTest.java} | 2 +- ...nTest.java => ClusterServiceLiveTest.java} | 2 +- jaxb/pom.xml | 5 ++ .../resources/log4jstructuraldp.properties | 9 +++ .../jaxb/test/JaxbIntegrationTest.java | 2 +- jaxb/src/test/resources/book.xml | 5 ++ ...tionTest.java => ConvListValLiveTest.java} | 2 +- ...t.java => AutomaticTimerBeanLiveTest.java} | 2 +- ...rammaticAtFixedRateTimerBeanLiveTest.java} | 2 +- ...ava => ProgrammaticTimerBeanLiveTest.java} | 2 +- ...maticWithFixedDelayTimerBeanLiveTest.java} | 2 +- ...st.java => ScheduleTimerBeanLiveTest.java} | 2 +- ...Test.java => StoredProcedureLiveTest.java} | 2 +- .../jcache/EntryProcessorIntegrationTest.java | 5 +- .../jcache/EventListenerIntegrationTest.java | 5 +- .../jcache/JCacheIntegrationTest.java | 2 +- .../resources/reladomo/ReladomoTestConfig.xml | 2 +- .../tests/JSONLayoutIntegrationTest.java | 1 + .../resources/log4jstructuraldp.properties | 9 +++ .../RedissonConfigurationIntegrationTest.java | 4 +- .../com/baeldung/RedissonIntegrationTest.java | 4 +- .../jdbc/AutomapInterfaceIntegrationTest.java | 15 ++--- .../jdbc/BasicQueryTypesIntegrationTest.java | 16 +++--- .../jdbc/InsertClobIntegrationTest.java | 8 +-- .../jdbc/ReturnKeysIntegrationTest.java | 6 +- .../jdbc/TransactionIntegrationTest.java | 5 +- .../PowerMockitoIntegrationTest.java | 8 ++- .../mockito/MockitoMockIntegrationTest.java | 2 +- .../JUnitManagedIntegrationTest.java | 56 ++++++++++++------- 40 files changed, 201 insertions(+), 101 deletions(-) create mode 100644 couchbase/src/test/java/com/baeldung/couchbase/async/person/PersonCrudServiceIntegrationTestConfig.java rename couchbase/src/test/java/com/baeldung/couchbase/async/person/{PersonCrudServiceIntegrationTest.java => PersonCrudServiceLiveTest.java} (90%) rename couchbase/src/test/java/com/baeldung/couchbase/async/service/{ClusterServiceIntegrationTest.java => ClusterServiceLiveTest.java} (94%) rename couchbase/src/test/java/com/baeldung/couchbase/mapreduce/{StudentGradeServiceIntegrationTest.java => StudentGradeServiceLiveTest.java} (98%) rename couchbase/src/test/java/com/baeldung/couchbase/n1ql/{N1QLIntegrationTest.java => N1QLLiveTest.java} (97%) rename couchbase/src/test/java/com/baeldung/couchbase/spring/person/{PersonCrudServiceIntegrationTest.java => PersonCrudServiceLiveTest.java} (97%) rename couchbase/src/test/java/com/baeldung/couchbase/spring/service/{ClusterServiceIntegrationTest.java => ClusterServiceLiveTest.java} (94%) create mode 100644 jaxb/src/main/resources/log4jstructuraldp.properties create mode 100644 jaxb/src/test/resources/book.xml rename jee-7/src/test/java/com/baeldung/convListVal/{ConvListValIntegrationTest.java => ConvListValLiveTest.java} (98%) rename jee-7/src/test/java/com/baeldung/timer/{AutomaticTimerBeanIntegrationTest.java => AutomaticTimerBeanLiveTest.java} (98%) rename jee-7/src/test/java/com/baeldung/timer/{ProgrammaticAtFixedRateTimerBeanIntegrationTest.java => ProgrammaticAtFixedRateTimerBeanLiveTest.java} (96%) rename jee-7/src/test/java/com/baeldung/timer/{ProgrammaticTimerBeanIntegrationTest.java => ProgrammaticTimerBeanLiveTest.java} (97%) rename jee-7/src/test/java/com/baeldung/timer/{ProgrammaticWithFixedDelayTimerBeanIntegrationTest.java => ProgrammaticWithFixedDelayTimerBeanLiveTest.java} (97%) rename jee-7/src/test/java/com/baeldung/timer/{ScheduleTimerBeanIntegrationTest.java => ScheduleTimerBeanLiveTest.java} (97%) rename jpa-storedprocedure/src/test/java/com/baeldung/jpa/storedprocedure/{StoredProcedureIntegrationTest.java => StoredProcedureLiveTest.java} (98%) create mode 100644 patterns/design-patterns/src/main/resources/log4jstructuraldp.properties diff --git a/apache-poi/src/test/java/com/baeldung/poi/powerpoint/PowerPointIntegrationTest.java b/apache-poi/src/test/java/com/baeldung/poi/powerpoint/PowerPointIntegrationTest.java index 5319208e85..7253238e80 100644 --- a/apache-poi/src/test/java/com/baeldung/poi/powerpoint/PowerPointIntegrationTest.java +++ b/apache-poi/src/test/java/com/baeldung/poi/powerpoint/PowerPointIntegrationTest.java @@ -1,25 +1,30 @@ package com.baeldung.poi.powerpoint; +import java.io.File; +import java.util.List; + import org.apache.poi.xslf.usermodel.XMLSlideShow; import org.apache.poi.xslf.usermodel.XSLFShape; import org.apache.poi.xslf.usermodel.XSLFSlide; import org.junit.After; import org.junit.Assert; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; - -import java.io.File; -import java.util.List; +import org.junit.rules.TemporaryFolder; public class PowerPointIntegrationTest { private PowerPointHelper pph; private String fileLocation; private static final String FILE_NAME = "presentation.pptx"; + + @Rule + public TemporaryFolder tempFolder = new TemporaryFolder(); @Before public void setUp() throws Exception { - File currDir = new File("."); + File currDir = tempFolder.newFolder(); String path = currDir.getAbsolutePath(); fileLocation = path.substring(0, path.length() - 1) + FILE_NAME; diff --git a/core-java/src/test/java/com/baeldung/array/JaggedArrayUnitTest.java b/core-java/src/test/java/com/baeldung/array/JaggedArrayUnitTest.java index f432436190..a4dd7e25c3 100644 --- a/core-java/src/test/java/com/baeldung/array/JaggedArrayUnitTest.java +++ b/core-java/src/test/java/com/baeldung/array/JaggedArrayUnitTest.java @@ -46,7 +46,7 @@ public class JaggedArrayUnitTest { ByteArrayOutputStream outContent = new ByteArrayOutputStream(); System.setOut(new PrintStream(outContent)); obj.printElements(jaggedArr); - assertEquals("[1, 2]\n[3, 4, 5]\n[6, 7, 8, 9]\n", outContent.toString()); + assertEquals("[1, 2][3, 4, 5][6, 7, 8, 9]", outContent.toString().replace("\r", "").replace("\n", "")); System.setOut(System.out); } diff --git a/core-java/src/test/java/com/baeldung/money/JavaMoneyUnitManualTest.java b/core-java/src/test/java/com/baeldung/money/JavaMoneyUnitManualTest.java index fe2747bcee..04d2886a82 100644 --- a/core-java/src/test/java/com/baeldung/money/JavaMoneyUnitManualTest.java +++ b/core-java/src/test/java/com/baeldung/money/JavaMoneyUnitManualTest.java @@ -179,7 +179,7 @@ public class JavaMoneyUnitManualTest { MonetaryAmountFormat customFormat = MonetaryFormats.getAmountFormat(AmountFormatQueryBuilder .of(Locale.US) .set(CurrencyStyle.NAME) - .set("pattern", "00000.00 �") + .set("pattern", "00000.00 US Dollar") .build()); String customFormatted = customFormat.format(oneDollar); diff --git a/core-java/src/test/java/com/baeldung/scripting/NashornUnitTest.java b/core-java/src/test/java/com/baeldung/scripting/NashornUnitTest.java index 7f165cec86..9abe8a927c 100644 --- a/core-java/src/test/java/com/baeldung/scripting/NashornUnitTest.java +++ b/core-java/src/test/java/com/baeldung/scripting/NashornUnitTest.java @@ -104,7 +104,7 @@ public class NashornUnitTest { public void loadExamples() throws ScriptException { Object loadResult = engine.eval("load('classpath:js/script.js');" + "increment(5)"); - Assert.assertEquals(6.0, loadResult); + Assert.assertEquals(6, ((Double) loadResult).intValue()); Object math = engine.eval("var math = loadWithNewGlobal('classpath:js/math_module.js');" + "math.increment(5);"); diff --git a/couchbase/src/main/java/com/baeldung/couchbase/async/service/ClusterServiceImpl.java b/couchbase/src/main/java/com/baeldung/couchbase/async/service/ClusterServiceImpl.java index e708922988..3100f0c70b 100644 --- a/couchbase/src/main/java/com/baeldung/couchbase/async/service/ClusterServiceImpl.java +++ b/couchbase/src/main/java/com/baeldung/couchbase/async/service/ClusterServiceImpl.java @@ -5,6 +5,7 @@ import java.util.concurrent.ConcurrentHashMap; import javax.annotation.PostConstruct; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.couchbase.client.java.Bucket; @@ -18,6 +19,11 @@ public class ClusterServiceImpl implements ClusterService { private Cluster cluster; private Map buckets = new ConcurrentHashMap<>(); + + @Autowired + public ClusterServiceImpl(Cluster cluster) { + this.cluster = cluster; + } @PostConstruct private void init() { diff --git a/couchbase/src/main/java/com/baeldung/couchbase/async/service/TutorialBucketService.java b/couchbase/src/main/java/com/baeldung/couchbase/async/service/TutorialBucketService.java index 459585d995..75a196ff5d 100644 --- a/couchbase/src/main/java/com/baeldung/couchbase/async/service/TutorialBucketService.java +++ b/couchbase/src/main/java/com/baeldung/couchbase/async/service/TutorialBucketService.java @@ -18,6 +18,7 @@ public class TutorialBucketService extends AbstractBucketService { @Autowired public TutorialBucketService(ClusterService clusterService) { super(clusterService); + openBucket(); } @Override diff --git a/couchbase/src/test/java/com/baeldung/couchbase/async/person/PersonCrudServiceIntegrationTestConfig.java b/couchbase/src/test/java/com/baeldung/couchbase/async/person/PersonCrudServiceIntegrationTestConfig.java new file mode 100644 index 0000000000..9e650752d2 --- /dev/null +++ b/couchbase/src/test/java/com/baeldung/couchbase/async/person/PersonCrudServiceIntegrationTestConfig.java @@ -0,0 +1,24 @@ +package com.baeldung.couchbase.async.person; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; + +import com.couchbase.client.java.Cluster; +import com.couchbase.client.java.CouchbaseCluster; +import com.couchbase.client.java.env.CouchbaseEnvironment; +import com.couchbase.client.java.env.DefaultCouchbaseEnvironment; + +@Configuration +@ComponentScan(basePackages = {"com.baeldung.couchbase.async.service", "com.baeldung.couchbase.n1ql"}) +public class PersonCrudServiceIntegrationTestConfig { + + @Bean + public Cluster cluster() { + CouchbaseEnvironment env = DefaultCouchbaseEnvironment.builder() + .connectTimeout(60000) + .build(); + return CouchbaseCluster.create(env, "127.0.0.1"); + } + +} diff --git a/couchbase/src/test/java/com/baeldung/couchbase/async/person/PersonCrudServiceIntegrationTest.java b/couchbase/src/test/java/com/baeldung/couchbase/async/person/PersonCrudServiceLiveTest.java similarity index 90% rename from couchbase/src/test/java/com/baeldung/couchbase/async/person/PersonCrudServiceIntegrationTest.java rename to couchbase/src/test/java/com/baeldung/couchbase/async/person/PersonCrudServiceLiveTest.java index 565aaed5da..267071ab35 100644 --- a/couchbase/src/test/java/com/baeldung/couchbase/async/person/PersonCrudServiceIntegrationTest.java +++ b/couchbase/src/test/java/com/baeldung/couchbase/async/person/PersonCrudServiceLiveTest.java @@ -1,27 +1,31 @@ package com.baeldung.couchbase.async.person; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; import java.util.ArrayList; import java.util.List; import java.util.UUID; -import javax.annotation.PostConstruct; - import org.apache.commons.lang3.RandomStringUtils; +import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import com.baeldung.couchbase.async.AsyncIntegrationTest; -import com.baeldung.couchbase.async.person.Person; -import com.baeldung.couchbase.async.person.PersonCrudService; -import com.baeldung.couchbase.async.person.PersonDocumentConverter; import com.baeldung.couchbase.async.service.BucketService; import com.couchbase.client.java.Bucket; import com.couchbase.client.java.document.JsonDocument; -public class PersonCrudServiceIntegrationTest extends AsyncIntegrationTest { +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(classes = {PersonCrudServiceIntegrationTestConfig.class}) +public class PersonCrudServiceLiveTest extends AsyncIntegrationTest { @Autowired private PersonCrudService personService; @@ -35,8 +39,8 @@ public class PersonCrudServiceIntegrationTest extends AsyncIntegrationTest { private Bucket bucket; - @PostConstruct - private void init() { + @Before + public void init() { bucket = bucketService.getBucket(); } diff --git a/couchbase/src/test/java/com/baeldung/couchbase/async/service/ClusterServiceIntegrationTest.java b/couchbase/src/test/java/com/baeldung/couchbase/async/service/ClusterServiceLiveTest.java similarity index 94% rename from couchbase/src/test/java/com/baeldung/couchbase/async/service/ClusterServiceIntegrationTest.java rename to couchbase/src/test/java/com/baeldung/couchbase/async/service/ClusterServiceLiveTest.java index d0db5d37a3..5f478ae788 100644 --- a/couchbase/src/test/java/com/baeldung/couchbase/async/service/ClusterServiceIntegrationTest.java +++ b/couchbase/src/test/java/com/baeldung/couchbase/async/service/ClusterServiceLiveTest.java @@ -18,7 +18,7 @@ import com.couchbase.client.java.Bucket; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = { AsyncIntegrationTestConfig.class }) @TestExecutionListeners(listeners = { DependencyInjectionTestExecutionListener.class }) -public class ClusterServiceIntegrationTest extends AsyncIntegrationTest { +public class ClusterServiceLiveTest extends AsyncIntegrationTest { @Autowired private ClusterService couchbaseService; diff --git a/couchbase/src/test/java/com/baeldung/couchbase/mapreduce/StudentGradeServiceIntegrationTest.java b/couchbase/src/test/java/com/baeldung/couchbase/mapreduce/StudentGradeServiceLiveTest.java similarity index 98% rename from couchbase/src/test/java/com/baeldung/couchbase/mapreduce/StudentGradeServiceIntegrationTest.java rename to couchbase/src/test/java/com/baeldung/couchbase/mapreduce/StudentGradeServiceLiveTest.java index 00d462e32a..d260795ed3 100644 --- a/couchbase/src/test/java/com/baeldung/couchbase/mapreduce/StudentGradeServiceIntegrationTest.java +++ b/couchbase/src/test/java/com/baeldung/couchbase/mapreduce/StudentGradeServiceLiveTest.java @@ -14,8 +14,8 @@ import com.couchbase.client.java.document.JsonDocument; import com.couchbase.client.java.view.ViewResult; import com.couchbase.client.java.view.ViewRow; -public class StudentGradeServiceIntegrationTest { - private static final Logger logger = LoggerFactory.getLogger(StudentGradeServiceIntegrationTest.class); +public class StudentGradeServiceLiveTest { + private static final Logger logger = LoggerFactory.getLogger(StudentGradeServiceLiveTest.class); static StudentGradeService studentGradeService; static Set gradeIds = new HashSet<>(); diff --git a/couchbase/src/test/java/com/baeldung/couchbase/n1ql/N1QLIntegrationTest.java b/couchbase/src/test/java/com/baeldung/couchbase/n1ql/N1QLLiveTest.java similarity index 97% rename from couchbase/src/test/java/com/baeldung/couchbase/n1ql/N1QLIntegrationTest.java rename to couchbase/src/test/java/com/baeldung/couchbase/n1ql/N1QLLiveTest.java index 8112d7d222..602bb5b8a5 100644 --- a/couchbase/src/test/java/com/baeldung/couchbase/n1ql/N1QLIntegrationTest.java +++ b/couchbase/src/test/java/com/baeldung/couchbase/n1ql/N1QLLiveTest.java @@ -1,5 +1,23 @@ package com.baeldung.couchbase.n1ql; +import static com.baeldung.couchbase.n1ql.CodeSnippets.extractJsonResult; +import static com.couchbase.client.java.query.Select.select; +import static com.couchbase.client.java.query.dsl.Expression.i; +import static com.couchbase.client.java.query.dsl.Expression.s; +import static com.couchbase.client.java.query.dsl.Expression.x; +import static org.junit.Assert.assertNotNull; + +import java.util.List; +import java.util.UUID; +import java.util.stream.Collectors; +import java.util.stream.IntStream; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + import com.couchbase.client.java.Bucket; import com.couchbase.client.java.Cluster; import com.couchbase.client.java.document.JsonDocument; @@ -10,28 +28,13 @@ import com.couchbase.client.java.query.N1qlQueryResult; import com.couchbase.client.java.query.N1qlQueryRow; import com.couchbase.client.java.query.Statement; import com.fasterxml.jackson.databind.JsonNode; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + import rx.Observable; -import java.util.List; -import java.util.UUID; -import java.util.stream.Collectors; -import java.util.stream.IntStream; -import java.util.stream.Stream; - -import static com.baeldung.couchbase.n1ql.CodeSnippets.extractJsonResult; -import static com.couchbase.client.java.query.Select.select; -import static com.couchbase.client.java.query.dsl.Expression.*; -import static org.junit.Assert.assertNotNull; - @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = { IntegrationTestConfig.class }) -public class N1QLIntegrationTest { +public class N1QLLiveTest { @Autowired diff --git a/couchbase/src/test/java/com/baeldung/couchbase/spring/person/PersonCrudServiceIntegrationTest.java b/couchbase/src/test/java/com/baeldung/couchbase/spring/person/PersonCrudServiceLiveTest.java similarity index 97% rename from couchbase/src/test/java/com/baeldung/couchbase/spring/person/PersonCrudServiceIntegrationTest.java rename to couchbase/src/test/java/com/baeldung/couchbase/spring/person/PersonCrudServiceLiveTest.java index ec15be1acc..493b326d49 100644 --- a/couchbase/src/test/java/com/baeldung/couchbase/spring/person/PersonCrudServiceIntegrationTest.java +++ b/couchbase/src/test/java/com/baeldung/couchbase/spring/person/PersonCrudServiceLiveTest.java @@ -10,7 +10,7 @@ import org.springframework.beans.factory.annotation.Autowired; import com.baeldung.couchbase.spring.IntegrationTest; -public class PersonCrudServiceIntegrationTest extends IntegrationTest { +public class PersonCrudServiceLiveTest extends IntegrationTest { private static final String CLARK_KENT = "Clark Kent"; private static final String SMALLVILLE = "Smallville"; diff --git a/couchbase/src/test/java/com/baeldung/couchbase/spring/service/ClusterServiceIntegrationTest.java b/couchbase/src/test/java/com/baeldung/couchbase/spring/service/ClusterServiceLiveTest.java similarity index 94% rename from couchbase/src/test/java/com/baeldung/couchbase/spring/service/ClusterServiceIntegrationTest.java rename to couchbase/src/test/java/com/baeldung/couchbase/spring/service/ClusterServiceLiveTest.java index ead247dfbc..7a89a208f7 100644 --- a/couchbase/src/test/java/com/baeldung/couchbase/spring/service/ClusterServiceIntegrationTest.java +++ b/couchbase/src/test/java/com/baeldung/couchbase/spring/service/ClusterServiceLiveTest.java @@ -17,7 +17,7 @@ import com.couchbase.client.java.Bucket; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = { IntegrationTestConfig.class }) @TestExecutionListeners(listeners = { DependencyInjectionTestExecutionListener.class }) -public class ClusterServiceIntegrationTest extends IntegrationTest { +public class ClusterServiceLiveTest extends IntegrationTest { @Autowired private ClusterService couchbaseService; diff --git a/jaxb/pom.xml b/jaxb/pom.xml index 26d7c8d362..f8e5ec0977 100644 --- a/jaxb/pom.xml +++ b/jaxb/pom.xml @@ -39,6 +39,11 @@ commons-lang3 ${commons-lang3.version} + + javax.activation + activation + 1.1 + diff --git a/jaxb/src/main/resources/log4jstructuraldp.properties b/jaxb/src/main/resources/log4jstructuraldp.properties new file mode 100644 index 0000000000..5bc2bfe4b9 --- /dev/null +++ b/jaxb/src/main/resources/log4jstructuraldp.properties @@ -0,0 +1,9 @@ + +# Root logger +log4j.rootLogger=INFO, file, stdout + +# Write to console +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.Target=System.out +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n \ No newline at end of file diff --git a/jaxb/src/test/java/com/baeldung/jaxb/test/JaxbIntegrationTest.java b/jaxb/src/test/java/com/baeldung/jaxb/test/JaxbIntegrationTest.java index b2dde85c0f..77b7f1a0b3 100644 --- a/jaxb/src/test/java/com/baeldung/jaxb/test/JaxbIntegrationTest.java +++ b/jaxb/src/test/java/com/baeldung/jaxb/test/JaxbIntegrationTest.java @@ -44,7 +44,7 @@ public class JaxbIntegrationTest { File bookFile = new File(this.getClass().getResource("/book.xml").getFile()); String sampleBookXML = FileUtils.readFileToString(sampleBookFile, "UTF-8"); String marshallerBookXML = FileUtils.readFileToString(bookFile, "UTF-8"); - Assert.assertEquals(sampleBookXML, marshallerBookXML); + Assert.assertEquals(sampleBookXML.replace("\r", "").replace("\n", ""), marshallerBookXML.replace("\r", "").replace("\n", "")); } @Test diff --git a/jaxb/src/test/resources/book.xml b/jaxb/src/test/resources/book.xml new file mode 100644 index 0000000000..605d531b16 --- /dev/null +++ b/jaxb/src/test/resources/book.xml @@ -0,0 +1,5 @@ + + + Book1 + 2016-12-16T17:28:49.718Z + diff --git a/jee-7/src/test/java/com/baeldung/convListVal/ConvListValIntegrationTest.java b/jee-7/src/test/java/com/baeldung/convListVal/ConvListValLiveTest.java similarity index 98% rename from jee-7/src/test/java/com/baeldung/convListVal/ConvListValIntegrationTest.java rename to jee-7/src/test/java/com/baeldung/convListVal/ConvListValLiveTest.java index caeba95e45..0d6fd295e6 100644 --- a/jee-7/src/test/java/com/baeldung/convListVal/ConvListValIntegrationTest.java +++ b/jee-7/src/test/java/com/baeldung/convListVal/ConvListValLiveTest.java @@ -22,7 +22,7 @@ import org.openqa.selenium.WebElement; import org.openqa.selenium.support.FindBy; @RunWith(Arquillian.class) -public class ConvListValIntegrationTest { +public class ConvListValLiveTest { @ArquillianResource private URL deploymentUrl; diff --git a/jee-7/src/test/java/com/baeldung/timer/AutomaticTimerBeanIntegrationTest.java b/jee-7/src/test/java/com/baeldung/timer/AutomaticTimerBeanLiveTest.java similarity index 98% rename from jee-7/src/test/java/com/baeldung/timer/AutomaticTimerBeanIntegrationTest.java rename to jee-7/src/test/java/com/baeldung/timer/AutomaticTimerBeanLiveTest.java index 0e4c91ad67..41dde6549d 100644 --- a/jee-7/src/test/java/com/baeldung/timer/AutomaticTimerBeanIntegrationTest.java +++ b/jee-7/src/test/java/com/baeldung/timer/AutomaticTimerBeanLiveTest.java @@ -21,7 +21,7 @@ import static org.hamcrest.Matchers.equalTo; @RunWith(Arquillian.class) -public class AutomaticTimerBeanIntegrationTest { +public class AutomaticTimerBeanLiveTest { //the @AutomaticTimerBean has a method called every 10 seconds //testing the difference ==> 100000 diff --git a/jee-7/src/test/java/com/baeldung/timer/ProgrammaticAtFixedRateTimerBeanIntegrationTest.java b/jee-7/src/test/java/com/baeldung/timer/ProgrammaticAtFixedRateTimerBeanLiveTest.java similarity index 96% rename from jee-7/src/test/java/com/baeldung/timer/ProgrammaticAtFixedRateTimerBeanIntegrationTest.java rename to jee-7/src/test/java/com/baeldung/timer/ProgrammaticAtFixedRateTimerBeanLiveTest.java index 13cd1729db..350c094f38 100644 --- a/jee-7/src/test/java/com/baeldung/timer/ProgrammaticAtFixedRateTimerBeanIntegrationTest.java +++ b/jee-7/src/test/java/com/baeldung/timer/ProgrammaticAtFixedRateTimerBeanLiveTest.java @@ -21,7 +21,7 @@ import static org.hamcrest.Matchers.is; @RunWith(Arquillian.class) -public class ProgrammaticAtFixedRateTimerBeanIntegrationTest { +public class ProgrammaticAtFixedRateTimerBeanLiveTest { final static long TIMEOUT = 1000; final static long TOLERANCE = 500l; diff --git a/jee-7/src/test/java/com/baeldung/timer/ProgrammaticTimerBeanIntegrationTest.java b/jee-7/src/test/java/com/baeldung/timer/ProgrammaticTimerBeanLiveTest.java similarity index 97% rename from jee-7/src/test/java/com/baeldung/timer/ProgrammaticTimerBeanIntegrationTest.java rename to jee-7/src/test/java/com/baeldung/timer/ProgrammaticTimerBeanLiveTest.java index b90cb6d909..ad079c131b 100644 --- a/jee-7/src/test/java/com/baeldung/timer/ProgrammaticTimerBeanIntegrationTest.java +++ b/jee-7/src/test/java/com/baeldung/timer/ProgrammaticTimerBeanLiveTest.java @@ -19,7 +19,7 @@ import static org.hamcrest.Matchers.is; @RunWith(Arquillian.class) -public class ProgrammaticTimerBeanIntegrationTest { +public class ProgrammaticTimerBeanLiveTest { final static long TIMEOUT = 5000l; final static long TOLERANCE = 1000l; diff --git a/jee-7/src/test/java/com/baeldung/timer/ProgrammaticWithFixedDelayTimerBeanIntegrationTest.java b/jee-7/src/test/java/com/baeldung/timer/ProgrammaticWithFixedDelayTimerBeanLiveTest.java similarity index 97% rename from jee-7/src/test/java/com/baeldung/timer/ProgrammaticWithFixedDelayTimerBeanIntegrationTest.java rename to jee-7/src/test/java/com/baeldung/timer/ProgrammaticWithFixedDelayTimerBeanLiveTest.java index e2e660f79b..974f0a285f 100644 --- a/jee-7/src/test/java/com/baeldung/timer/ProgrammaticWithFixedDelayTimerBeanIntegrationTest.java +++ b/jee-7/src/test/java/com/baeldung/timer/ProgrammaticWithFixedDelayTimerBeanLiveTest.java @@ -21,7 +21,7 @@ import static org.hamcrest.Matchers.is; @RunWith(Arquillian.class) -public class ProgrammaticWithFixedDelayTimerBeanIntegrationTest { +public class ProgrammaticWithFixedDelayTimerBeanLiveTest { final static long TIMEOUT = 15000l; final static long TOLERANCE = 1000l; diff --git a/jee-7/src/test/java/com/baeldung/timer/ScheduleTimerBeanIntegrationTest.java b/jee-7/src/test/java/com/baeldung/timer/ScheduleTimerBeanLiveTest.java similarity index 97% rename from jee-7/src/test/java/com/baeldung/timer/ScheduleTimerBeanIntegrationTest.java rename to jee-7/src/test/java/com/baeldung/timer/ScheduleTimerBeanLiveTest.java index 580edade77..a4ed9ceb68 100644 --- a/jee-7/src/test/java/com/baeldung/timer/ScheduleTimerBeanIntegrationTest.java +++ b/jee-7/src/test/java/com/baeldung/timer/ScheduleTimerBeanLiveTest.java @@ -20,7 +20,7 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; @RunWith(Arquillian.class) -public class ScheduleTimerBeanIntegrationTest { +public class ScheduleTimerBeanLiveTest { private final static long TIMEOUT = 5000l; private final static long TOLERANCE = 1000l; diff --git a/jpa-storedprocedure/src/test/java/com/baeldung/jpa/storedprocedure/StoredProcedureIntegrationTest.java b/jpa-storedprocedure/src/test/java/com/baeldung/jpa/storedprocedure/StoredProcedureLiveTest.java similarity index 98% rename from jpa-storedprocedure/src/test/java/com/baeldung/jpa/storedprocedure/StoredProcedureIntegrationTest.java rename to jpa-storedprocedure/src/test/java/com/baeldung/jpa/storedprocedure/StoredProcedureLiveTest.java index c0fb5485aa..8bc8c854da 100644 --- a/jpa-storedprocedure/src/test/java/com/baeldung/jpa/storedprocedure/StoredProcedureIntegrationTest.java +++ b/jpa-storedprocedure/src/test/java/com/baeldung/jpa/storedprocedure/StoredProcedureLiveTest.java @@ -15,7 +15,7 @@ import org.junit.Test; import com.baeldung.jpa.model.Car; -public class StoredProcedureIntegrationTest { +public class StoredProcedureLiveTest { private static EntityManagerFactory factory = null; private static EntityManager entityManager = null; diff --git a/libraries-data/src/test/java/com/baeldung/jcache/EntryProcessorIntegrationTest.java b/libraries-data/src/test/java/com/baeldung/jcache/EntryProcessorIntegrationTest.java index 61c98d0126..fd1e9c29a9 100644 --- a/libraries-data/src/test/java/com/baeldung/jcache/EntryProcessorIntegrationTest.java +++ b/libraries-data/src/test/java/com/baeldung/jcache/EntryProcessorIntegrationTest.java @@ -15,12 +15,13 @@ import static org.junit.Assert.assertEquals; public class EntryProcessorIntegrationTest { private static final String CACHE_NAME = "MyCache"; + private static final String CACHE_PROVIDER_NAME = "com.hazelcast.cache.HazelcastCachingProvider"; private Cache cache; @Before public void instantiateCache() { - CachingProvider cachingProvider = Caching.getCachingProvider(); + CachingProvider cachingProvider = Caching.getCachingProvider(CACHE_PROVIDER_NAME); CacheManager cacheManager = cachingProvider.getCacheManager(); MutableConfiguration config = new MutableConfiguration<>(); this.cache = cacheManager.createCache(CACHE_NAME, config); @@ -29,7 +30,7 @@ public class EntryProcessorIntegrationTest { @After public void tearDown() { - Caching.getCachingProvider().getCacheManager().destroyCache(CACHE_NAME); + Caching.getCachingProvider(CACHE_PROVIDER_NAME).getCacheManager().destroyCache(CACHE_NAME); } @Test diff --git a/libraries-data/src/test/java/com/baeldung/jcache/EventListenerIntegrationTest.java b/libraries-data/src/test/java/com/baeldung/jcache/EventListenerIntegrationTest.java index fcbfbe6111..512a75ec61 100644 --- a/libraries-data/src/test/java/com/baeldung/jcache/EventListenerIntegrationTest.java +++ b/libraries-data/src/test/java/com/baeldung/jcache/EventListenerIntegrationTest.java @@ -17,6 +17,7 @@ import static org.junit.Assert.assertEquals; public class EventListenerIntegrationTest { private static final String CACHE_NAME = "MyCache"; + private static final String CACHE_PROVIDER_NAME = "com.hazelcast.cache.HazelcastCachingProvider"; private Cache cache; private SimpleCacheEntryListener listener; @@ -24,7 +25,7 @@ public class EventListenerIntegrationTest { @Before public void setup() { - CachingProvider cachingProvider = Caching.getCachingProvider(); + CachingProvider cachingProvider = Caching.getCachingProvider(CACHE_PROVIDER_NAME); CacheManager cacheManager = cachingProvider.getCacheManager(); MutableConfiguration config = new MutableConfiguration(); this.cache = cacheManager.createCache("MyCache", config); @@ -33,7 +34,7 @@ public class EventListenerIntegrationTest { @After public void tearDown() { - Caching.getCachingProvider().getCacheManager().destroyCache(CACHE_NAME); + Caching.getCachingProvider(CACHE_PROVIDER_NAME).getCacheManager().destroyCache(CACHE_NAME); } @Test diff --git a/libraries-data/src/test/java/com/baeldung/jcache/JCacheIntegrationTest.java b/libraries-data/src/test/java/com/baeldung/jcache/JCacheIntegrationTest.java index fac3d32bcb..33521469fa 100644 --- a/libraries-data/src/test/java/com/baeldung/jcache/JCacheIntegrationTest.java +++ b/libraries-data/src/test/java/com/baeldung/jcache/JCacheIntegrationTest.java @@ -14,7 +14,7 @@ public class JCacheIntegrationTest { @Test public void instantiateCache() { - CachingProvider cachingProvider = Caching.getCachingProvider(); + CachingProvider cachingProvider = Caching.getCachingProvider("com.hazelcast.cache.HazelcastCachingProvider"); CacheManager cacheManager = cachingProvider.getCacheManager(); MutableConfiguration config = new MutableConfiguration<>(); Cache cache = cacheManager.createCache("simpleCache", config); diff --git a/libraries-data/src/test/resources/reladomo/ReladomoTestConfig.xml b/libraries-data/src/test/resources/reladomo/ReladomoTestConfig.xml index a1951f09b7..6e5d212fb8 100644 --- a/libraries-data/src/test/resources/reladomo/ReladomoTestConfig.xml +++ b/libraries-data/src/test/resources/reladomo/ReladomoTestConfig.xml @@ -2,6 +2,6 @@ - + \ No newline at end of file diff --git a/logging-modules/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/JSONLayoutIntegrationTest.java b/logging-modules/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/JSONLayoutIntegrationTest.java index e4404a6528..53634002a0 100644 --- a/logging-modules/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/JSONLayoutIntegrationTest.java +++ b/logging-modules/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/JSONLayoutIntegrationTest.java @@ -12,6 +12,7 @@ import org.apache.logging.log4j.Logger; import org.junit.Before; import org.junit.Test; + import com.fasterxml.jackson.databind.ObjectMapper; public class JSONLayoutIntegrationTest extends Log4j2BaseIntegrationTest { diff --git a/patterns/design-patterns/src/main/resources/log4jstructuraldp.properties b/patterns/design-patterns/src/main/resources/log4jstructuraldp.properties new file mode 100644 index 0000000000..5bc2bfe4b9 --- /dev/null +++ b/patterns/design-patterns/src/main/resources/log4jstructuraldp.properties @@ -0,0 +1,9 @@ + +# Root logger +log4j.rootLogger=INFO, file, stdout + +# Write to console +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.Target=System.out +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n \ No newline at end of file diff --git a/persistence-modules/redis/src/test/java/com/baeldung/RedissonConfigurationIntegrationTest.java b/persistence-modules/redis/src/test/java/com/baeldung/RedissonConfigurationIntegrationTest.java index 1862d6b035..860ca0927a 100644 --- a/persistence-modules/redis/src/test/java/com/baeldung/RedissonConfigurationIntegrationTest.java +++ b/persistence-modules/redis/src/test/java/com/baeldung/RedissonConfigurationIntegrationTest.java @@ -27,7 +27,9 @@ public class RedissonConfigurationIntegrationTest { @AfterClass public static void destroy() { redisServer.stop(); - client.shutdown(); + if (client != null) { + client.shutdown(); + } } @Test diff --git a/persistence-modules/redis/src/test/java/com/baeldung/RedissonIntegrationTest.java b/persistence-modules/redis/src/test/java/com/baeldung/RedissonIntegrationTest.java index 766963e5cf..53d77c2699 100644 --- a/persistence-modules/redis/src/test/java/com/baeldung/RedissonIntegrationTest.java +++ b/persistence-modules/redis/src/test/java/com/baeldung/RedissonIntegrationTest.java @@ -37,7 +37,9 @@ public class RedissonIntegrationTest { @AfterClass public static void destroy() { redisServer.stop(); - client.shutdown(); + if (client != null) { + client.shutdown(); + } } @Test diff --git a/rxjava/src/test/java/com/baeldung/rxjava/jdbc/AutomapInterfaceIntegrationTest.java b/rxjava/src/test/java/com/baeldung/rxjava/jdbc/AutomapInterfaceIntegrationTest.java index 477a2a1cb8..ec766ac7ac 100644 --- a/rxjava/src/test/java/com/baeldung/rxjava/jdbc/AutomapInterfaceIntegrationTest.java +++ b/rxjava/src/test/java/com/baeldung/rxjava/jdbc/AutomapInterfaceIntegrationTest.java @@ -18,26 +18,27 @@ public class AutomapInterfaceIntegrationTest { private ConnectionProvider connectionProvider = Connector.connectionProvider; private Database db = Database.from(connectionProvider); - private Observable create = null; + private Observable truncate = null; private Observable insert1, insert2 = null; @Before public void setup() { - create = db.update("CREATE TABLE IF NOT EXISTS EMPLOYEE(id int primary key, name varchar(255))") + Observable create = db.update("CREATE TABLE IF NOT EXISTS EMPLOYEE(id int primary key, name varchar(255))") .count(); + truncate = db.update("TRUNCATE TABLE EMPLOYEE") + .dependsOn(create) + .count(); insert1 = db.update("INSERT INTO EMPLOYEE(id, name) VALUES(1, 'Alan')") - .dependsOn(create) + .dependsOn(truncate) .count(); insert2 = db.update("INSERT INTO EMPLOYEE(id, name) VALUES(2, 'Sarah')") - .dependsOn(create) + .dependsOn(insert1) .count(); } @Test public void whenSelectFromTableAndAutomap_thenCorrect() { List employees = db.select("select id, name from EMPLOYEE") - .dependsOn(create) - .dependsOn(insert1) .dependsOn(insert2) .autoMap(Employee.class) .toList() @@ -57,7 +58,7 @@ public class AutomapInterfaceIntegrationTest { @After public void close() { db.update("DROP TABLE EMPLOYEE") - .dependsOn(create); + .dependsOn(truncate); connectionProvider.close(); } } diff --git a/rxjava/src/test/java/com/baeldung/rxjava/jdbc/BasicQueryTypesIntegrationTest.java b/rxjava/src/test/java/com/baeldung/rxjava/jdbc/BasicQueryTypesIntegrationTest.java index 5f445234d7..2fb3b3abd7 100644 --- a/rxjava/src/test/java/com/baeldung/rxjava/jdbc/BasicQueryTypesIntegrationTest.java +++ b/rxjava/src/test/java/com/baeldung/rxjava/jdbc/BasicQueryTypesIntegrationTest.java @@ -22,24 +22,24 @@ public class BasicQueryTypesIntegrationTest { @Test public void whenCreateTableAndInsertRecords_thenCorrect() { - create = db.update("CREATE TABLE IF NOT EXISTS EMPLOYEE(id int primary key, name varchar(255))") + create = db.update("CREATE TABLE IF NOT EXISTS EMPLOYEE_TABLE(id int primary key, name varchar(255))") .count(); - Observable insert1 = db.update("INSERT INTO EMPLOYEE(id, name) VALUES(1, 'John')") + Observable insert1 = db.update("INSERT INTO EMPLOYEE_TABLE(id, name) VALUES(1, 'John')") .dependsOn(create) .count(); - Observable update = db.update("UPDATE EMPLOYEE SET name = 'Alan' WHERE id = 1") + Observable update = db.update("UPDATE EMPLOYEE_TABLE SET name = 'Alan' WHERE id = 1") .dependsOn(create) .count(); - Observable insert2 = db.update("INSERT INTO EMPLOYEE(id, name) VALUES(2, 'Sarah')") + Observable insert2 = db.update("INSERT INTO EMPLOYEE_TABLE(id, name) VALUES(2, 'Sarah')") .dependsOn(create) .count(); - Observable insert3 = db.update("INSERT INTO EMPLOYEE(id, name) VALUES(3, 'Mike')") + Observable insert3 = db.update("INSERT INTO EMPLOYEE_TABLE(id, name) VALUES(3, 'Mike')") .dependsOn(create) .count(); - Observable delete = db.update("DELETE FROM EMPLOYEE WHERE id = 2") + Observable delete = db.update("DELETE FROM EMPLOYEE_TABLE WHERE id = 2") .dependsOn(create) .count(); - List names = db.select("select name from EMPLOYEE where id < ?") + List names = db.select("select name from EMPLOYEE_TABLE where id < ?") .parameter(3) .dependsOn(create) .dependsOn(insert1) @@ -57,7 +57,7 @@ public class BasicQueryTypesIntegrationTest { @After public void close() { - db.update("DROP TABLE EMPLOYEE") + db.update("DROP TABLE EMPLOYEE_TABLE") .dependsOn(create); connectionProvider.close(); } diff --git a/rxjava/src/test/java/com/baeldung/rxjava/jdbc/InsertClobIntegrationTest.java b/rxjava/src/test/java/com/baeldung/rxjava/jdbc/InsertClobIntegrationTest.java index 189bca4adb..284ecc4078 100644 --- a/rxjava/src/test/java/com/baeldung/rxjava/jdbc/InsertClobIntegrationTest.java +++ b/rxjava/src/test/java/com/baeldung/rxjava/jdbc/InsertClobIntegrationTest.java @@ -27,7 +27,7 @@ public class InsertClobIntegrationTest { @Before public void setup() throws IOException { - create = db.update("CREATE TABLE IF NOT EXISTS SERVERLOG (id int primary key, document CLOB)") + create = db.update("CREATE TABLE IF NOT EXISTS SERVERLOG_TABLE (id int primary key, document CLOB)") .count(); InputStream actualInputStream = new FileInputStream("src/test/resources/actual_clob"); @@ -35,7 +35,7 @@ public class InsertClobIntegrationTest { InputStream expectedInputStream = new FileInputStream("src/test/resources/expected_clob"); this.expectedDocument = Utils.getStringFromInputStream(expectedInputStream); - this.insert = db.update("insert into SERVERLOG(id,document) values(?,?)") + this.insert = db.update("insert into SERVERLOG_TABLE(id,document) values(?,?)") .parameter(1) .parameter(Database.toSentinelIfNull(actualDocument)) .dependsOn(create) @@ -44,7 +44,7 @@ public class InsertClobIntegrationTest { @Test public void whenSelectCLOB_thenCorrect() throws IOException { - db.select("select document from SERVERLOG where id = 1") + db.select("select document from SERVERLOG_TABLE where id = 1") .dependsOn(create) .dependsOn(insert) .getAs(String.class) @@ -56,7 +56,7 @@ public class InsertClobIntegrationTest { @After public void close() { - db.update("DROP TABLE SERVERLOG") + db.update("DROP TABLE SERVERLOG_TABLE") .dependsOn(create); connectionProvider.close(); } diff --git a/rxjava/src/test/java/com/baeldung/rxjava/jdbc/ReturnKeysIntegrationTest.java b/rxjava/src/test/java/com/baeldung/rxjava/jdbc/ReturnKeysIntegrationTest.java index 2018a9427c..c9e06a347f 100644 --- a/rxjava/src/test/java/com/baeldung/rxjava/jdbc/ReturnKeysIntegrationTest.java +++ b/rxjava/src/test/java/com/baeldung/rxjava/jdbc/ReturnKeysIntegrationTest.java @@ -22,14 +22,14 @@ public class ReturnKeysIntegrationTest { @Before public void setup() { begin = db.beginTransaction(); - createStatement = db.update("CREATE TABLE IF NOT EXISTS EMPLOYEE(id int auto_increment primary key, name varchar(255))") + createStatement = db.update("CREATE TABLE IF NOT EXISTS EMPLOYEE_SAMPLE(id int auto_increment primary key, name varchar(255))") .dependsOn(begin) .count(); } @Test public void whenInsertAndReturnGeneratedKey_thenCorrect() { - Integer key = db.update("INSERT INTO EMPLOYEE(name) VALUES('John')") + Integer key = db.update("INSERT INTO EMPLOYEE_SAMPLE(name) VALUES('John')") .dependsOn(createStatement) .returnGeneratedKeys() .getAs(Integer.class) @@ -41,7 +41,7 @@ public class ReturnKeysIntegrationTest { @After public void close() { - db.update("DROP TABLE EMPLOYEE") + db.update("DROP TABLE EMPLOYEE_SAMPLE") .dependsOn(createStatement); connectionProvider.close(); } diff --git a/rxjava/src/test/java/com/baeldung/rxjava/jdbc/TransactionIntegrationTest.java b/rxjava/src/test/java/com/baeldung/rxjava/jdbc/TransactionIntegrationTest.java index 4e24d7f10e..d5f09be23c 100644 --- a/rxjava/src/test/java/com/baeldung/rxjava/jdbc/TransactionIntegrationTest.java +++ b/rxjava/src/test/java/com/baeldung/rxjava/jdbc/TransactionIntegrationTest.java @@ -24,8 +24,11 @@ public class TransactionIntegrationTest { .update("CREATE TABLE IF NOT EXISTS EMPLOYEE(id int primary key, name varchar(255))") .dependsOn(begin) .count(); + Observable truncateStatement = db.update("TRUNCATE TABLE EMPLOYEE") + .dependsOn(createStatement) + .count(); Observable insertStatement = db.update("INSERT INTO EMPLOYEE(id, name) VALUES(1, 'John')") - .dependsOn(createStatement) + .dependsOn(truncateStatement) .count(); Observable updateStatement = db.update("UPDATE EMPLOYEE SET name = 'Tom' WHERE id = 1") .dependsOn(insertStatement) diff --git a/testing-modules/mockito/src/test/java/com/baeldung/powermockito/introduction/PowerMockitoIntegrationTest.java b/testing-modules/mockito/src/test/java/com/baeldung/powermockito/introduction/PowerMockitoIntegrationTest.java index 4a98bbcb87..1b6431f0c2 100644 --- a/testing-modules/mockito/src/test/java/com/baeldung/powermockito/introduction/PowerMockitoIntegrationTest.java +++ b/testing-modules/mockito/src/test/java/com/baeldung/powermockito/introduction/PowerMockitoIntegrationTest.java @@ -7,6 +7,8 @@ import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; import static org.powermock.api.mockito.PowerMockito.*; @RunWith(PowerMockRunner.class) @@ -23,7 +25,7 @@ public class PowerMockitoIntegrationTest { when(collaborator.helloMethod()).thenReturn("Hello Baeldung!"); String welcome = collaborator.helloMethod(); - Mockito.verify(collaborator).helloMethod(); + verify(collaborator).helloMethod(); assertEquals("Hello Baeldung!", welcome); } @@ -42,7 +44,7 @@ public class PowerMockitoIntegrationTest { assertEquals("Hello Baeldung!", firstWelcome); assertEquals("Hello Baeldung!", secondWelcome); - verifyStatic(Mockito.times(2)); + verifyStatic(times(2)); CollaboratorWithStaticMethods.firstMethod(Mockito.anyString()); verifyStatic(Mockito.never()); @@ -67,7 +69,7 @@ public class PowerMockitoIntegrationTest { when(mock.finalMethod()).thenReturn("I am a final mock method."); returnValue = mock.finalMethod(); - Mockito.verify(mock).finalMethod(); + verify(mock,times(3)).finalMethod(); assertEquals("I am a final mock method.", returnValue); when(mock, "privateMethod").thenReturn("I am a private mock method."); diff --git a/testing-modules/mockito/src/test/java/org/baeldung/mockito/MockitoMockIntegrationTest.java b/testing-modules/mockito/src/test/java/org/baeldung/mockito/MockitoMockIntegrationTest.java index f846907fd7..6ec3b34db5 100644 --- a/testing-modules/mockito/src/test/java/org/baeldung/mockito/MockitoMockIntegrationTest.java +++ b/testing-modules/mockito/src/test/java/org/baeldung/mockito/MockitoMockIntegrationTest.java @@ -24,7 +24,7 @@ public class MockitoMockIntegrationTest { } @Rule - private ExpectedException thrown = ExpectedException.none(); + public ExpectedException thrown = ExpectedException.none(); @Test public void whenUsingSimpleMock_thenCorrect() { diff --git a/testing-modules/rest-testing/src/test/java/com/baeldung/rest/wiremock/introduction/JUnitManagedIntegrationTest.java b/testing-modules/rest-testing/src/test/java/com/baeldung/rest/wiremock/introduction/JUnitManagedIntegrationTest.java index aa0c6696a4..834d266cc6 100644 --- a/testing-modules/rest-testing/src/test/java/com/baeldung/rest/wiremock/introduction/JUnitManagedIntegrationTest.java +++ b/testing-modules/rest-testing/src/test/java/com/baeldung/rest/wiremock/introduction/JUnitManagedIntegrationTest.java @@ -1,19 +1,5 @@ package com.baeldung.rest.wiremock.introduction; -import com.github.tomakehurst.wiremock.junit.WireMockRule; -import org.apache.http.HttpResponse; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.client.methods.HttpPost; -import org.apache.http.entity.StringEntity; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClients; -import org.junit.Rule; -import org.junit.Test; - -import java.io.IOException; -import java.io.InputStream; -import java.util.Scanner; - import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; import static com.github.tomakehurst.wiremock.client.WireMock.containing; import static com.github.tomakehurst.wiremock.client.WireMock.equalTo; @@ -29,16 +15,46 @@ import static com.github.tomakehurst.wiremock.client.WireMock.urlPathMatching; import static com.github.tomakehurst.wiremock.client.WireMock.verify; import static org.junit.Assert.assertEquals; +import java.io.IOException; +import java.io.InputStream; +import java.net.ServerSocket; +import java.util.Scanner; + +import org.apache.http.HttpResponse; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.junit.Rule; +import org.junit.Test; +import com.github.tomakehurst.wiremock.junit.WireMockRule; + public class JUnitManagedIntegrationTest { private static final String BAELDUNG_WIREMOCK_PATH = "/baeldung/wiremock"; private static final String APPLICATION_JSON = "application/json"; - + static int port; + + static { + + try { + // Get a free port + ServerSocket s = new ServerSocket(0); + port = s.getLocalPort(); + s.close(); + + } catch (IOException e) { + // No OPS + } + } + @Rule - public WireMockRule wireMockRule = new WireMockRule(); + public WireMockRule wireMockRule = new WireMockRule(port); @Test public void givenJUnitManagedServer_whenMatchingURL_thenCorrect() throws IOException { + stubFor(get(urlPathMatching("/baeldung/.*")) .willReturn(aResponse() .withStatus(200) @@ -46,7 +62,7 @@ public class JUnitManagedIntegrationTest { .withBody("\"testing-library\": \"WireMock\""))); CloseableHttpClient httpClient = HttpClients.createDefault(); - HttpGet request = new HttpGet("http://localhost:8080/baeldung/wiremock"); + HttpGet request = new HttpGet(String.format("http://localhost:%s/baeldung/wiremock", port)); HttpResponse httpResponse = httpClient.execute(request); String stringResponse = convertHttpResponseToString(httpResponse); @@ -66,7 +82,7 @@ public class JUnitManagedIntegrationTest { .withBody("!!! Service Unavailable !!!"))); CloseableHttpClient httpClient = HttpClients.createDefault(); - HttpGet request = new HttpGet("http://localhost:8080/baeldung/wiremock"); + HttpGet request = new HttpGet(String.format("http://localhost:%s/baeldung/wiremock", port)); request.addHeader("Accept", "text/html"); HttpResponse httpResponse = httpClient.execute(request); String stringResponse = convertHttpResponseToString(httpResponse); @@ -91,7 +107,7 @@ public class JUnitManagedIntegrationTest { StringEntity entity = new StringEntity(jsonString); CloseableHttpClient httpClient = HttpClients.createDefault(); - HttpPost request = new HttpPost("http://localhost:8080/baeldung/wiremock"); + HttpPost request = new HttpPost(String.format("http://localhost:%s/baeldung/wiremock", port)); request.addHeader("Content-Type", APPLICATION_JSON); request.setEntity(entity); HttpResponse response = httpClient.execute(request); @@ -137,7 +153,7 @@ public class JUnitManagedIntegrationTest { private HttpResponse generateClientAndReceiveResponseForPriorityTests() throws IOException { CloseableHttpClient httpClient = HttpClients.createDefault(); - HttpGet request = new HttpGet("http://localhost:8080/baeldung/wiremock"); + HttpGet request = new HttpGet(String.format("http://localhost:%s/baeldung/wiremock", port)); request.addHeader("Accept", "text/xml"); return httpClient.execute(request); } From 1fe7dc32aa4659c53ea8b1ee7e72d5b975c87b38 Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Mon, 11 Jun 2018 12:35:24 +0300 Subject: [PATCH 38/84] formatting --- .../listbindingexample/BookService.java | 4 +- .../listbindingexample/BooksCreationDto.java | 32 +++++----- .../baeldung/listbindingexample/Config.java | 6 +- .../InMemoryBookService.java | 28 ++++----- .../ListBindingApplication.java | 4 +- .../MultipleBooksController.java | 60 ++++++++++--------- 6 files changed, 67 insertions(+), 67 deletions(-) diff --git a/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/BookService.java b/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/BookService.java index 770e86ad68..c72d8fe70d 100644 --- a/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/BookService.java +++ b/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/BookService.java @@ -4,7 +4,7 @@ import java.util.List; public interface BookService { - List findAll(); + List findAll(); - void saveAll(List books); + void saveAll(List books); } diff --git a/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/BooksCreationDto.java b/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/BooksCreationDto.java index 8e5654143a..a25418815b 100644 --- a/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/BooksCreationDto.java +++ b/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/BooksCreationDto.java @@ -5,25 +5,25 @@ import java.util.List; public class BooksCreationDto { - private List books; + private List books; - public BooksCreationDto() { - this.books = new ArrayList<>(); - } + public BooksCreationDto() { + this.books = new ArrayList<>(); + } - public BooksCreationDto(List books) { - this.books = books; - } + public BooksCreationDto(List books) { + this.books = books; + } - public List getBooks() { - return books; - } + public List getBooks() { + return books; + } - public void setBooks(List books) { - this.books = books; - } + public void setBooks(List books) { + this.books = books; + } - public void addBook(Book book) { - this.books.add(book); - } + public void addBook(Book book) { + this.books.add(book); + } } diff --git a/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/Config.java b/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/Config.java index ffba2cea2c..00e1a0393e 100644 --- a/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/Config.java +++ b/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/Config.java @@ -16,14 +16,14 @@ public class Config implements WebMvcConfigurer { @Override public void addViewControllers(ViewControllerRegistry registry) { - registry.addViewController("/").setViewName("index"); + registry.addViewController("/") + .setViewName("index"); registry.setOrder(Ordered.HIGHEST_PRECEDENCE); } @Bean public ITemplateResolver templateResolver() { - ClassLoaderTemplateResolver resolver - = new ClassLoaderTemplateResolver(); + ClassLoaderTemplateResolver resolver = new ClassLoaderTemplateResolver(); resolver.setPrefix("templates/books/"); resolver.setSuffix(".html"); resolver.setTemplateMode(TemplateMode.HTML); diff --git a/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/InMemoryBookService.java b/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/InMemoryBookService.java index 56ca41c51f..b35522a3ee 100644 --- a/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/InMemoryBookService.java +++ b/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/InMemoryBookService.java @@ -12,16 +12,16 @@ import java.util.stream.Collectors; @Service public class InMemoryBookService implements BookService { - static Map booksDB = new HashMap<>(); + static Map booksDB = new HashMap<>(); - @Override - public List findAll() { - return new ArrayList(booksDB.values()); - } + @Override + public List findAll() { + return new ArrayList<>(booksDB.values()); + } - @Override - public void saveAll(List books) { - long nextId = getNextId(); + @Override + public void saveAll(List books) { + long nextId = getNextId(); for (Book book : books) { if (book.getId() == 0) { book.setId(nextId++); @@ -29,14 +29,14 @@ public class InMemoryBookService implements BookService { } Map bookMap = books.stream() - .collect(Collectors.toMap( - Book::getId, Function.identity())); + .collect(Collectors.toMap(Book::getId, Function.identity())); - booksDB.putAll(bookMap); - } + booksDB.putAll(bookMap); + } - private Long getNextId(){ - return booksDB.keySet().stream() + private Long getNextId() { + return booksDB.keySet() + .stream() .mapToLong(value -> value) .max() .orElse(0) + 1; diff --git a/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/ListBindingApplication.java b/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/ListBindingApplication.java index af8608704b..261954fcff 100644 --- a/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/ListBindingApplication.java +++ b/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/ListBindingApplication.java @@ -5,9 +5,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration; -@SpringBootApplication( - exclude = {SecurityAutoConfiguration.class, - DataSourceAutoConfiguration.class}) +@SpringBootApplication(exclude = { SecurityAutoConfiguration.class, DataSourceAutoConfiguration.class }) public class ListBindingApplication { public static void main(String[] args) { diff --git a/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/MultipleBooksController.java b/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/MultipleBooksController.java index 2e177c7bbf..1ed44778c6 100644 --- a/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/MultipleBooksController.java +++ b/spring-mvc-forms-thymeleaf/src/main/java/com/baeldung/listbindingexample/MultipleBooksController.java @@ -15,45 +15,47 @@ import java.util.List; @RequestMapping("/books") public class MultipleBooksController { - @Autowired - private BookService bookService; + @Autowired + private BookService bookService; - @GetMapping(value = "/all") - public String showAll(Model model) { - model.addAttribute("books", bookService.findAll()); + @GetMapping(value = "/all") + public String showAll(Model model) { + model.addAttribute("books", bookService.findAll()); - return "allBooks"; - } + return "allBooks"; + } - @GetMapping(value = "/create") - public String showCreateForm(Model model) { - BooksCreationDto booksForm = new BooksCreationDto(); + @GetMapping(value = "/create") + public String showCreateForm(Model model) { + BooksCreationDto booksForm = new BooksCreationDto(); - for (int i = 1; i <= 3; i++) { - booksForm.addBook(new Book()); - } + for (int i = 1; i <= 3; i++) { + booksForm.addBook(new Book()); + } - model.addAttribute("form", booksForm); + model.addAttribute("form", booksForm); - return "createBooksForm"; - } + return "createBooksForm"; + } - @GetMapping(value = "/edit") - public String showEditForm(Model model) { - List books = new ArrayList<>(); - bookService.findAll().iterator().forEachRemaining(books::add); + @GetMapping(value = "/edit") + public String showEditForm(Model model) { + List books = new ArrayList<>(); + bookService.findAll() + .iterator() + .forEachRemaining(books::add); - model.addAttribute("form", new BooksCreationDto(books)); + model.addAttribute("form", new BooksCreationDto(books)); - return "editBooksForm"; - } + return "editBooksForm"; + } - @PostMapping(value = "/save") - public String saveBooks(@ModelAttribute BooksCreationDto form, Model model) { - bookService.saveAll(form.getBooks()); + @PostMapping(value = "/save") + public String saveBooks(@ModelAttribute BooksCreationDto form, Model model) { + bookService.saveAll(form.getBooks()); - model.addAttribute("books", bookService.findAll()); + model.addAttribute("books", bookService.findAll()); - return "redirect:/books/all"; - } + return "redirect:/books/all"; + } } From 3d602e63988f8d90083ef279ae71ecd705b9bf52 Mon Sep 17 00:00:00 2001 From: Timoteo Ponce Date: Mon, 11 Jun 2018 09:48:24 -0400 Subject: [PATCH 39/84] Added error handling policies for javax-servlets module --- .../servlets/ErrorHandlerServlet.java | 34 +++++++++++++++++++ .../baeldung/servlets/RandomErrorServlet.java | 13 +++++++ .../src/main/webapp/WEB-INF/web.xml | 16 +++++++++ javax-servlets/src/main/webapp/error-404.html | 14 ++++++++ spring-boot-ops/README.MD | 3 -- 5 files changed, 77 insertions(+), 3 deletions(-) create mode 100644 javax-servlets/src/main/java/com/baeldung/servlets/ErrorHandlerServlet.java create mode 100644 javax-servlets/src/main/java/com/baeldung/servlets/RandomErrorServlet.java create mode 100644 javax-servlets/src/main/webapp/WEB-INF/web.xml create mode 100644 javax-servlets/src/main/webapp/error-404.html delete mode 100644 spring-boot-ops/README.MD diff --git a/javax-servlets/src/main/java/com/baeldung/servlets/ErrorHandlerServlet.java b/javax-servlets/src/main/java/com/baeldung/servlets/ErrorHandlerServlet.java new file mode 100644 index 0000000000..0008e837c0 --- /dev/null +++ b/javax-servlets/src/main/java/com/baeldung/servlets/ErrorHandlerServlet.java @@ -0,0 +1,34 @@ +package com.baeldung.servlets; + +import javax.servlet.annotation.*; +import javax.servlet.http.*; +import java.io.*; +import java.util.*; + +import static javax.servlet.RequestDispatcher.*; + +@WebServlet(urlPatterns = "/errorHandler") +public class ErrorHandlerServlet extends HttpServlet { + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) + throws IOException { + resp.setContentType("text/html; charset=utf-8"); + try (PrintWriter writer = resp.getWriter()) { + writer.write("Error description"); + writer.write("

Error description

"); + writer.write("
    "); + Arrays.asList(ERROR_STATUS_CODE, ERROR_EXCEPTION_TYPE, ERROR_MESSAGE) + .forEach(e -> + writer.write("
  • " + e + ":" + req.getAttribute(e) + "
  • ") + ); + writer.write("
"); + writer.write(""); + } + + Exception exception = (Exception) req.getAttribute(ERROR_EXCEPTION); + if (IllegalArgumentException.class.isInstance(exception)) { + getServletContext().log("Error on an application argument", exception); + } + } +} \ No newline at end of file diff --git a/javax-servlets/src/main/java/com/baeldung/servlets/RandomErrorServlet.java b/javax-servlets/src/main/java/com/baeldung/servlets/RandomErrorServlet.java new file mode 100644 index 0000000000..c95bd2cec0 --- /dev/null +++ b/javax-servlets/src/main/java/com/baeldung/servlets/RandomErrorServlet.java @@ -0,0 +1,13 @@ +package com.baeldung.servlets; + +import javax.servlet.annotation.*; +import javax.servlet.http.*; + +@WebServlet(urlPatterns = "/randomError") +public class RandomErrorServlet extends HttpServlet { + + @Override + protected void doGet(HttpServletRequest req, final HttpServletResponse resp) { + throw new IllegalStateException("Random error"); + } +} \ No newline at end of file diff --git a/javax-servlets/src/main/webapp/WEB-INF/web.xml b/javax-servlets/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000000..c9a06ac52d --- /dev/null +++ b/javax-servlets/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,16 @@ + + + + 404 + /error-404.html + + + + java.lang.Exception + /errorHandler + + \ No newline at end of file diff --git a/javax-servlets/src/main/webapp/error-404.html b/javax-servlets/src/main/webapp/error-404.html new file mode 100644 index 0000000000..b36fc44160 --- /dev/null +++ b/javax-servlets/src/main/webapp/error-404.html @@ -0,0 +1,14 @@ + + + + + Error page + + + +

Error: Page not found

+ +Go back home + + + \ No newline at end of file diff --git a/spring-boot-ops/README.MD b/spring-boot-ops/README.MD deleted file mode 100644 index 26caccb727..0000000000 --- a/spring-boot-ops/README.MD +++ /dev/null @@ -1,3 +0,0 @@ -### Relevant Articles: - -- [Deploy a Spring Boot WAR into a Tomcat Server](http://www.baeldung.com/spring-boot-war-tomcat-deploy) From b5dc7fa1af4d514f5308f1eadfe3ad2d44fafbcd Mon Sep 17 00:00:00 2001 From: smokeyrobot Date: Mon, 11 Jun 2018 10:10:38 -0400 Subject: [PATCH 40/84] Bael 1765 (#4342) Guide to java.util.Arrays Issue: BAEL-1765 --- .../com/baeldung/arrays/ArraysUnitTest.java | 153 ++++++++++++++++++ 1 file changed, 153 insertions(+) create mode 100644 core-java/src/test/java/com/baeldung/arrays/ArraysUnitTest.java diff --git a/core-java/src/test/java/com/baeldung/arrays/ArraysUnitTest.java b/core-java/src/test/java/com/baeldung/arrays/ArraysUnitTest.java new file mode 100644 index 0000000000..9e6d3d6131 --- /dev/null +++ b/core-java/src/test/java/com/baeldung/arrays/ArraysUnitTest.java @@ -0,0 +1,153 @@ +package com.baeldung.arrays; + +import static org.junit.Assert.*; + +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +import java.util.Arrays; +import java.util.List; +import java.util.stream.Stream; + +public class ArraysUnitTest { + private String[] intro; + + @Rule + public final ExpectedException exception = ExpectedException.none(); + + @Before + public void setup() { + intro = new String[] { "once", "upon", "a", "time" }; + } + + @Test + public void whenCopyOfRange_thenAbridgedArray() { + String[] abridgement = Arrays.copyOfRange(intro, 0, 3); + + assertArrayEquals(new String[] { "once", "upon", "a" }, abridgement); + assertFalse(Arrays.equals(intro, abridgement)); + } + + @Test + public void whenCopyOf_thenNullElement() { + String[] revised = Arrays.copyOf(intro, 3); + String[] expanded = Arrays.copyOf(intro, 5); + + assertArrayEquals(Arrays.copyOfRange(intro, 0, 3), revised); + assertNull(expanded[4]); + } + + @Test + public void whenFill_thenAllMatch() { + String[] stutter = new String[3]; + Arrays.fill(stutter, "once"); + + assertTrue(Stream.of(stutter).allMatch(el -> "once".equals(el))); + } + + @Test + public void whenEqualsContent_thenMatch() { + assertTrue(Arrays.equals(new String[] { "once", "upon", "a", "time" }, intro)); + assertFalse(Arrays.equals(new String[] { "once", "upon", "a", null }, intro)); + } + + @Test + public void whenNestedArrays_thenDeepEqualsPass() { + String[] end = { "the", "end" }; + Object[] story = new Object[] { intro, new String[] { "chapter one", "chapter two" }, end }; + Object[] copy = new Object[] { intro, new String[] { "chapter one", "chapter two" }, end }; + + assertTrue(Arrays.deepEquals(story, copy)); + assertFalse(Arrays.equals(story, copy)); + } + + @Test + public void whenSort_thenArraySorted() { + String[] sorted = Arrays.copyOf(intro, 4); + Arrays.sort(sorted); + + assertArrayEquals(new String[] { "a", "once", "time", "upon" }, sorted); + } + + @Test + public void whenBinarySearch_thenFindElements() { + String[] sorted = Arrays.copyOf(intro, 4); + Arrays.sort(sorted); + int exact = Arrays.binarySearch(sorted, "time"); + int caseInsensitive = Arrays.binarySearch(sorted, "TiMe", String::compareToIgnoreCase); + + assertEquals("time", sorted[exact]); + assertEquals(2, exact); + assertEquals(exact, caseInsensitive); + } + + @Test + public void whenNullElement_thenArraysHashCodeNotEqual() { + int beforeChange = Arrays.hashCode(intro); + int before = intro.hashCode(); + intro[3] = null; + int after = intro.hashCode(); + int afterChange = Arrays.hashCode(intro); + + assertNotEquals(beforeChange, afterChange); + assertEquals(before, after); + } + + @Test + public void whenNestedArrayNullElement_thenEqualsFailDeepHashPass() { + Object[] looping = new Object[] { intro, intro }; + int deepHashBefore = Arrays.deepHashCode(looping); + int hashBefore = Arrays.hashCode(looping); + + intro[3] = null; + + int hashAfter = Arrays.hashCode(looping); + int deepHashAfter = Arrays.deepHashCode(looping); + + assertEquals(hashAfter, hashBefore); + assertNotEquals(deepHashAfter, deepHashBefore); + } + + @Test + public void whenStreamBadIndex_thenException() { + assertEquals(Arrays.stream(intro).count(), 4); + + exception.expect(ArrayIndexOutOfBoundsException.class); + Arrays.stream(intro, 2, 1).count(); + } + + @Test + public void whenSetAllToUpper_thenAppliedToAllElements() { + String[] longAgo = new String[4]; + Arrays.setAll(longAgo, i -> intro[i].toUpperCase()); + + assertArrayEquals(longAgo, new String[] { "ONCE", "UPON", "A", "TIME" }); + } + + @Test + public void whenToString_thenFormattedArrayString() { + assertEquals("[once, upon, a, time]", Arrays.toString(intro)); + } + + @Test + public void whenNestedArrayDeepString_thenFormattedArraysString() { + String[] end = { "the", "end" }; + Object[] story = new Object[] { intro, new String[] { "chapter one", "chapter two" }, end }; + + assertEquals("[[once, upon, a, time], [chapter one, chapter two], [the, end]]", Arrays.deepToString(story)); + } + + @Test + public void whenAsList_thenImmutableArray() { + List rets = Arrays.asList(intro); + + assertTrue(rets.contains("upon")); + assertTrue(rets.contains("time")); + assertEquals(rets.size(), 4); + + exception.expect(UnsupportedOperationException.class); + rets.add("the"); + } +} From b62c35bd7a1f2c6c5b926d41c5d149982b4501fb Mon Sep 17 00:00:00 2001 From: charlesgonzales <39999268+charlesgonzales@users.noreply.github.com> Date: Mon, 11 Jun 2018 22:50:27 +0800 Subject: [PATCH 41/84] Delete README.MD (#4461) duplicate file vs README.md --- spring-boot-ops/README.MD | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 spring-boot-ops/README.MD diff --git a/spring-boot-ops/README.MD b/spring-boot-ops/README.MD deleted file mode 100644 index 26caccb727..0000000000 --- a/spring-boot-ops/README.MD +++ /dev/null @@ -1,3 +0,0 @@ -### Relevant Articles: - -- [Deploy a Spring Boot WAR into a Tomcat Server](http://www.baeldung.com/spring-boot-war-tomcat-deploy) From 36eacfb3c3cf5e56e6c845ce7ab98190f4b3d915 Mon Sep 17 00:00:00 2001 From: psysane Date: Mon, 11 Jun 2018 21:25:53 +0530 Subject: [PATCH 42/84] Update json data --- .../src/main/resources/online_store.json | 42 ++++++++++--------- .../introduction/JsonPathUnitTest.java | 2 +- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/json-path/src/main/resources/online_store.json b/json-path/src/main/resources/online_store.json index d8e2402b25..c0ddf274d8 100644 --- a/json-path/src/main/resources/online_store.json +++ b/json-path/src/main/resources/online_store.json @@ -1,21 +1,23 @@ { - "items": { - "book": [ - { - "author": "Arthur Conan Doyle", - "title": "Sherlock Holmes", - "price": 8.99 - }, - { - "author": "J. R. R. Tolkien", - "title": "The Lord of the Rings", - "isbn": "0-395-19395-8", - "price": 22.99 - } - ], - "bicycle": { - "color": "red", - "price": 19.95 - } - } -} + "items":{ + "book":[ + { + "author":"Arthur Conan Doyle", + "title":"Sherlock Holmes", + "price":8.99 + }, + { + "author":"J. R. R. Tolkien", + "title":"The Lord of the Rings", + "isbn":"0-395-19395-8", + "price":22.99 + } + ], + "bicycle":{ + "color":"red", + "price":19.95 + } + }, + "url":"mystore.com", + "owner":"baeldung" +} \ No newline at end of file diff --git a/json-path/src/test/java/com/baeldung/jsonpath/introduction/JsonPathUnitTest.java b/json-path/src/test/java/com/baeldung/jsonpath/introduction/JsonPathUnitTest.java index 6b780c9c10..3408629a6d 100644 --- a/json-path/src/test/java/com/baeldung/jsonpath/introduction/JsonPathUnitTest.java +++ b/json-path/src/test/java/com/baeldung/jsonpath/introduction/JsonPathUnitTest.java @@ -33,7 +33,7 @@ public class JsonPathUnitTest { @Test public void shouldMatchCountOfObjects() { Map objectMap = JsonPath.read(json, "$"); - assertEquals(1, objectMap.keySet() + assertEquals(3, objectMap.keySet() .size()); } From 2a07b03b699a20547d183529678202e703b81453 Mon Sep 17 00:00:00 2001 From: Marcos Lopez Gonzalez Date: Tue, 12 Jun 2018 03:12:07 +0200 Subject: [PATCH 43/84] BAEL-1773 Find the middle element of a Linked List (#4463) * BAEL-1773 - find middle element of linked list * changes from review * changes from review * find middle element in linked list * typo * changes from CR * BAEL-1773 formatting --- .../com/baeldung/linkedlist/LinkedList.java | 58 -------------- .../linkedlist/MiddleElementLookup.java | 25 +++--- .../MiddleElementLookupUnitTest.java | 76 +++++++++++++++---- 3 files changed, 76 insertions(+), 83 deletions(-) delete mode 100644 core-java/src/main/java/com/baeldung/linkedlist/LinkedList.java diff --git a/core-java/src/main/java/com/baeldung/linkedlist/LinkedList.java b/core-java/src/main/java/com/baeldung/linkedlist/LinkedList.java deleted file mode 100644 index 12c73f2489..0000000000 --- a/core-java/src/main/java/com/baeldung/linkedlist/LinkedList.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.baeldung.linkedlist; - -/** - * Implementation of a singly linked list. - */ -public class LinkedList { - private Node head; - private Node tail; - - public Node head() { - return head; - } - - public void add(String data) { - Node newNode = new Node(data); - - if (head == null) { - head = newNode; - tail = newNode; - } else { - tail.next = newNode; - tail = newNode; - } - } - - public static class Node { - private Node next; - private String data; - - public Node(String data) { - this.data = data; - } - - public String data() { - return data; - } - - public void setData(String data) { - this.data = data; - } - - public boolean hasNext() { - return next != null; - } - - public Node next() { - return next; - } - - public void setNext(Node next) { - this.next = next; - } - - public String toString() { - return this.data; - } - } -} diff --git a/core-java/src/main/java/com/baeldung/linkedlist/MiddleElementLookup.java b/core-java/src/main/java/com/baeldung/linkedlist/MiddleElementLookup.java index 2caf17fd0c..4cfa0d411b 100644 --- a/core-java/src/main/java/com/baeldung/linkedlist/MiddleElementLookup.java +++ b/core-java/src/main/java/com/baeldung/linkedlist/MiddleElementLookup.java @@ -1,22 +1,23 @@ package com.baeldung.linkedlist; import java.util.LinkedList; +import java.util.Optional; import com.baeldung.linkedlist.Node; public class MiddleElementLookup { - public static String findMiddleElementLinkedList(LinkedList linkedList) { + public static Optional findMiddleElementLinkedList(LinkedList linkedList) { if (linkedList == null || linkedList.isEmpty()) { - return null; + return Optional.empty(); } - return linkedList.get((linkedList.size() - 1) / 2); + return Optional.ofNullable(linkedList.get((linkedList.size() - 1) / 2)); } - public static String findMiddleElementFromHead(Node head) { + public static Optional findMiddleElementFromHead(Node head) { if (head == null) { - return null; + return Optional.empty(); } // calculate the size of the list @@ -33,17 +34,17 @@ public class MiddleElementLookup { current = current.next(); } - return current.data(); + return Optional.ofNullable(current.data()); } - public static String findMiddleElementFromHead1PassRecursively(Node head) { + public static Optional findMiddleElementFromHead1PassRecursively(Node head) { if (head == null) { - return null; + return Optional.empty(); } MiddleAuxRecursion middleAux = new MiddleAuxRecursion(); findMiddleRecursively(head, middleAux); - return middleAux.middle.data(); + return Optional.ofNullable(middleAux.middle.data()); } private static void findMiddleRecursively(Node node, MiddleAuxRecursion middleAux) { @@ -63,9 +64,9 @@ public class MiddleElementLookup { middleAux.length--; } - public static String findMiddleElementFromHead1PassIteratively(Node head) { + public static Optional findMiddleElementFromHead1PassIteratively(Node head) { if (head == null) { - return null; + return Optional.empty(); } Node slowPointer = head; @@ -78,7 +79,7 @@ public class MiddleElementLookup { slowPointer = slowPointer.next(); } - return slowPointer.data(); + return Optional.ofNullable(slowPointer.data()); } private static class MiddleAuxRecursion { diff --git a/core-java/src/test/java/com/baeldung/linkedlist/MiddleElementLookupUnitTest.java b/core-java/src/test/java/com/baeldung/linkedlist/MiddleElementLookupUnitTest.java index 08a4e52ff9..2801bbfc9e 100644 --- a/core-java/src/test/java/com/baeldung/linkedlist/MiddleElementLookupUnitTest.java +++ b/core-java/src/test/java/com/baeldung/linkedlist/MiddleElementLookupUnitTest.java @@ -1,6 +1,7 @@ package com.baeldung.linkedlist; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import java.util.LinkedList; @@ -10,34 +11,83 @@ public class MiddleElementLookupUnitTest { @Test public void whenFindingMiddleLinkedList_thenMiddleFound() { - assertEquals("3", MiddleElementLookup.findMiddleElementLinkedList(createLinkedList(5))); - assertEquals("2", MiddleElementLookup.findMiddleElementLinkedList(createLinkedList(4))); + assertEquals("3", MiddleElementLookup + .findMiddleElementLinkedList(createLinkedList(5)) + .get()); + assertEquals("2", MiddleElementLookup + .findMiddleElementLinkedList(createLinkedList(4)) + .get()); } @Test public void whenFindingMiddleFromHead_thenMiddleFound() { - assertEquals("3", MiddleElementLookup.findMiddleElementFromHead(createNodesList(5))); - assertEquals("2", MiddleElementLookup.findMiddleElementFromHead(createNodesList(4))); + assertEquals("3", MiddleElementLookup + .findMiddleElementFromHead(createNodesList(5)) + .get()); + assertEquals("2", MiddleElementLookup + .findMiddleElementFromHead(createNodesList(4)) + .get()); } @Test public void whenFindingMiddleFromHead1PassRecursively_thenMiddleFound() { - assertEquals("3", MiddleElementLookup.findMiddleElementFromHead1PassRecursively(createNodesList(5))); - assertEquals("2", MiddleElementLookup.findMiddleElementFromHead1PassRecursively(createNodesList(4))); + assertEquals("3", MiddleElementLookup + .findMiddleElementFromHead1PassRecursively(createNodesList(5)) + .get()); + assertEquals("2", MiddleElementLookup + .findMiddleElementFromHead1PassRecursively(createNodesList(4)) + .get()); } @Test public void whenFindingMiddleFromHead1PassIteratively_thenMiddleFound() { - assertEquals("3", MiddleElementLookup.findMiddleElementFromHead1PassIteratively(createNodesList(5))); - assertEquals("2", MiddleElementLookup.findMiddleElementFromHead1PassIteratively(createNodesList(4))); + assertEquals("3", MiddleElementLookup + .findMiddleElementFromHead1PassIteratively(createNodesList(5)) + .get()); + assertEquals("2", MiddleElementLookup + .findMiddleElementFromHead1PassIteratively(createNodesList(4)) + .get()); } @Test - public void whenListEmptyOrNull_thenMiddleNull() { - assertEquals(null, MiddleElementLookup.findMiddleElementLinkedList(null)); - assertEquals(null, MiddleElementLookup.findMiddleElementFromHead(null)); - assertEquals(null, MiddleElementLookup.findMiddleElementFromHead1PassIteratively(null)); - assertEquals(null, MiddleElementLookup.findMiddleElementFromHead1PassRecursively(null)); + public void whenListEmptyOrNull_thenMiddleNotFound() { + // null list + assertFalse(MiddleElementLookup + .findMiddleElementLinkedList(null) + .isPresent()); + assertFalse(MiddleElementLookup + .findMiddleElementFromHead(null) + .isPresent()); + assertFalse(MiddleElementLookup + .findMiddleElementFromHead1PassIteratively(null) + .isPresent()); + assertFalse(MiddleElementLookup + .findMiddleElementFromHead1PassRecursively(null) + .isPresent()); + + // empty LinkedList + assertFalse(MiddleElementLookup + .findMiddleElementLinkedList(new LinkedList<>()) + .isPresent()); + + // LinkedList with nulls + LinkedList nullsList = new LinkedList<>(); + nullsList.add(null); + nullsList.add(null); + assertFalse(MiddleElementLookup + .findMiddleElementLinkedList(nullsList) + .isPresent()); + + // nodes with null values + assertFalse(MiddleElementLookup + .findMiddleElementFromHead(new Node(null)) + .isPresent()); + assertFalse(MiddleElementLookup + .findMiddleElementFromHead1PassIteratively(new Node(null)) + .isPresent()); + assertFalse(MiddleElementLookup + .findMiddleElementFromHead1PassRecursively(new Node(null)) + .isPresent()); } private static LinkedList createLinkedList(int n) { From b59da11c6661d79f0ad76ebed6bf1be3f7f55f2c Mon Sep 17 00:00:00 2001 From: psevestre Date: Wed, 13 Jun 2018 02:12:05 -0300 Subject: [PATCH 44/84] Code for BAEL-1474 (#4472) * Code for BAEL-1474 * Renamed test to conform to PMD rules --- pom.xml | 1 + ...java => FileProcessorIntegrationTest.java} | 2 +- spring-webflux-amqp/.gitignore | 25 ++ spring-webflux-amqp/pom.xml | 92 ++++++ .../src/docker/docker-compose.yml | 23 ++ .../spring/amqp/DestinationsConfig.java | 59 ++++ .../amqp/SpringWebfluxAmqpApplication.java | 270 ++++++++++++++++++ .../src/main/resources/application.yml | 27 ++ .../amqp/SpringWebfluxAmqpLiveTest.java | 26 ++ 9 files changed, 524 insertions(+), 1 deletion(-) rename spring-core/src/test/java/com/baeldung/dependson/processor/{FileProcessorTest.java => FileProcessorIntegrationTest.java} (96%) create mode 100755 spring-webflux-amqp/.gitignore create mode 100755 spring-webflux-amqp/pom.xml create mode 100755 spring-webflux-amqp/src/docker/docker-compose.yml create mode 100755 spring-webflux-amqp/src/main/java/org/baeldung/spring/amqp/DestinationsConfig.java create mode 100755 spring-webflux-amqp/src/main/java/org/baeldung/spring/amqp/SpringWebfluxAmqpApplication.java create mode 100755 spring-webflux-amqp/src/main/resources/application.yml create mode 100755 spring-webflux-amqp/src/test/java/org/baeldung/spring/amqp/SpringWebfluxAmqpLiveTest.java diff --git a/pom.xml b/pom.xml index d42c3ac617..38f88a2784 100644 --- a/pom.xml +++ b/pom.xml @@ -263,6 +263,7 @@ performance-tests twilio java-ee-8-security-api + spring-webflux-amqp diff --git a/spring-core/src/test/java/com/baeldung/dependson/processor/FileProcessorTest.java b/spring-core/src/test/java/com/baeldung/dependson/processor/FileProcessorIntegrationTest.java similarity index 96% rename from spring-core/src/test/java/com/baeldung/dependson/processor/FileProcessorTest.java rename to spring-core/src/test/java/com/baeldung/dependson/processor/FileProcessorIntegrationTest.java index b54ac16125..11d9daf3bf 100644 --- a/spring-core/src/test/java/com/baeldung/dependson/processor/FileProcessorTest.java +++ b/spring-core/src/test/java/com/baeldung/dependson/processor/FileProcessorIntegrationTest.java @@ -16,7 +16,7 @@ import com.baeldung.dependson.shared.File; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = TestConfig.class) -public class FileProcessorTest { +public class FileProcessorIntegrationTest { @Autowired ApplicationContext context; diff --git a/spring-webflux-amqp/.gitignore b/spring-webflux-amqp/.gitignore new file mode 100755 index 0000000000..82eca336e3 --- /dev/null +++ b/spring-webflux-amqp/.gitignore @@ -0,0 +1,25 @@ +/target/ +!.mvn/wrapper/maven-wrapper.jar + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/build/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ \ No newline at end of file diff --git a/spring-webflux-amqp/pom.xml b/spring-webflux-amqp/pom.xml new file mode 100755 index 0000000000..75fafd7b10 --- /dev/null +++ b/spring-webflux-amqp/pom.xml @@ -0,0 +1,92 @@ + + + 4.0.0 + + org.baeldung.spring + spring-webflux-amqp + 1.0.0-SNAPSHOT + jar + + spring-webflux-amqp + Spring WebFlux AMQP Sample + + + parent-boot-2 + com.baeldung + 0.0.1-SNAPSHOT + ../parent-boot-2 + + + + + + UTF-8 + UTF-8 + 1.8 + + + + + org.springframework.boot + spring-boot-starter-amqp + + + org.springframework.boot + spring-boot-starter-webflux + + + + org.springframework.boot + spring-boot-configuration-processor + true + + + + org.springframework.boot + spring-boot-starter-test + test + + + + io.projectreactor + reactor-test + test + + + + org.springframework.boot + spring-boot-starter-integration + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + + + spring-snapshots + Spring Snapshots + https://repo.spring.io/libs-snapshot + + true + + + + + + + spring-releases + Spring Releases + https://repo.spring.io/libs-release + + + + + diff --git a/spring-webflux-amqp/src/docker/docker-compose.yml b/spring-webflux-amqp/src/docker/docker-compose.yml new file mode 100755 index 0000000000..03292aeb63 --- /dev/null +++ b/spring-webflux-amqp/src/docker/docker-compose.yml @@ -0,0 +1,23 @@ +## +## Create a simple RabbitMQ environment with multiple clients +## +version: "3" + +services: + +## +## RabitMQ server +## + rabbitmq: + image: rabbitmq:3 + hostname: rabbit + environment: + RABBITMQ_ERLANG_COOKIE: test + ports: + - "5672:5672" + volumes: + - rabbitmq-data:/var/lib/rabbitmq + +volumes: + rabbitmq-data: + diff --git a/spring-webflux-amqp/src/main/java/org/baeldung/spring/amqp/DestinationsConfig.java b/spring-webflux-amqp/src/main/java/org/baeldung/spring/amqp/DestinationsConfig.java new file mode 100755 index 0000000000..410b87c764 --- /dev/null +++ b/spring-webflux-amqp/src/main/java/org/baeldung/spring/amqp/DestinationsConfig.java @@ -0,0 +1,59 @@ +package org.baeldung.spring.amqp; + +import java.util.HashMap; +import java.util.Map; + +import org.springframework.boot.context.properties.ConfigurationProperties; + +@ConfigurationProperties("destinations") +public class DestinationsConfig { + + + private Map queues = new HashMap<>(); + + private Map topics = new HashMap<>(); + + + + public Map getQueues() { + return queues; + } + + public void setQueues(Map queues) { + this.queues = queues; + } + + public Map getTopics() { + return topics; + } + + public void setTopics(Map topics) { + this.topics = topics; + } + + // DestinationInfo stores the Exchange name and routing key used + // by our producers when posting messages + static class DestinationInfo { + + private String exchange; + private String routingKey; + + + public String getExchange() { + return exchange; + } + public void setExchange(String exchange) { + this.exchange = exchange; + } + public String getRoutingKey() { + return routingKey; + } + public void setRoutingKey(String routingKey) { + this.routingKey = routingKey; + } + + + + } + +} diff --git a/spring-webflux-amqp/src/main/java/org/baeldung/spring/amqp/SpringWebfluxAmqpApplication.java b/spring-webflux-amqp/src/main/java/org/baeldung/spring/amqp/SpringWebfluxAmqpApplication.java new file mode 100755 index 0000000000..eb3b858ddc --- /dev/null +++ b/spring-webflux-amqp/src/main/java/org/baeldung/spring/amqp/SpringWebfluxAmqpApplication.java @@ -0,0 +1,270 @@ +package org.baeldung.spring.amqp; + +import java.util.stream.Stream; + +import org.baeldung.spring.amqp.DestinationsConfig.DestinationInfo; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.amqp.AmqpException; +import org.springframework.amqp.core.AmqpAdmin; +import org.springframework.amqp.core.AmqpTemplate; +import org.springframework.amqp.core.Binding; +import org.springframework.amqp.core.BindingBuilder; +import org.springframework.amqp.core.Exchange; +import org.springframework.amqp.core.ExchangeBuilder; +import org.springframework.amqp.core.Queue; +import org.springframework.amqp.core.QueueBuilder; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.CommandLineRunner; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.http.MediaType; +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.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RestController; + +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; +import reactor.core.scheduler.Schedulers; + +@SpringBootApplication +@EnableConfigurationProperties(DestinationsConfig.class) +@RestController +public class SpringWebfluxAmqpApplication { + + private static Logger log = LoggerFactory.getLogger(SpringWebfluxAmqpApplication.class); + + @Autowired + private AmqpTemplate amqpTemplate; + + @Autowired + private AmqpAdmin amqpAdmin; + + @Autowired + private DestinationsConfig destinationsConfig; + + + public static void main(String[] args) { + SpringApplication.run(SpringWebfluxAmqpApplication.class, args); + } + + @Bean + public CommandLineRunner setupQueueDestinations(AmqpAdmin amqpAdmin,DestinationsConfig destinationsConfig) { + + return (args) -> { + + log.info("[I48] Creating Destinations..."); + + destinationsConfig.getQueues() + .forEach((key, destination) -> { + + log.info("[I54] Creating directExchange: key={}, name={}, routingKey={}", key, destination.getExchange(), destination.getRoutingKey()); + + Exchange ex = ExchangeBuilder + .directExchange(destination.getExchange()) + .durable(true) + .build(); + + amqpAdmin.declareExchange(ex); + + Queue q = QueueBuilder + .durable(destination.getRoutingKey()) + .build(); + + amqpAdmin.declareQueue(q); + + Binding b = BindingBuilder.bind(q) + .to(ex) + .with(destination.getRoutingKey()) + .noargs(); + amqpAdmin.declareBinding(b); + + log.info("[I70] Binding successfully created."); + + }); + + }; + + } + + @Bean + public CommandLineRunner setupTopicDestinations(AmqpAdmin amqpAdmin, DestinationsConfig destinationsConfig) { + + return (args) -> { + + // For topic each consumer will have its own Queue, so no binding + destinationsConfig.getTopics() + .forEach((key, destination) -> { + + log.info("[I98] Creating TopicExchange: name={}, exchange={}", key, destination.getExchange()); + + Exchange ex = ExchangeBuilder.topicExchange(destination.getExchange()) + .durable(true) + .build(); + + amqpAdmin.declareExchange(ex); + + log.info("[I107] Topic Exchange successfully created."); + + }); + }; + } + + @PostMapping(value = "/queue/{name}") + public Mono> sendMessageToQueue(@PathVariable String name, @RequestBody String payload) { + + // Lookup exchange details + final DestinationInfo d = destinationsConfig.getQueues() + .get(name); + if (d == null) { + // Destination not found. + return Mono.just(ResponseEntity.notFound().build()); + } + + return Mono.fromCallable(() -> { + + log.info("[I51] sendMessageToQueue: queue={}, routingKey={}", d.getExchange(), d.getRoutingKey()); + amqpTemplate.convertAndSend(d.getExchange(), d.getRoutingKey(), payload); + + return ResponseEntity.accepted().build(); + + }); + + } + + + /** + * Receive messages for the given queue + * @param name + * @return + */ + @GetMapping(value = "/queue/{name}", produces = MediaType.TEXT_EVENT_STREAM_VALUE) + public Flux receiveMessagesFromQueue(@PathVariable String name) { + + final DestinationInfo d = destinationsConfig.getQueues().get(name); + + if (d == null) { + return Flux.just(ResponseEntity.notFound().build()); + } + + Stream s = Stream.generate(() -> { + String queueName = d.getRoutingKey(); + + log.info("[I137] Polling {}", queueName); + + Object payload = amqpTemplate.receiveAndConvert(queueName,5000); + if ( payload == null ) { + payload = "No news is good news..."; + } + + return payload.toString(); + }); + + + return Flux + .fromStream(s) + .subscribeOn(Schedulers.elastic()); + + } + + /** + * send message to a given topic + * @param name + * @param payload + * @return + */ + @PostMapping(value = "/topic/{name}") + public Mono> sendMessageToTopic(@PathVariable String name, @RequestBody String payload) { + + // Lookup exchange details + final DestinationInfo d = destinationsConfig.getTopics().get(name); + if (d == null) { + // Destination not found. + return Mono.just(ResponseEntity.notFound().build()); + } + + return Mono.fromCallable(() -> { + + log.info("[I51] sendMessageToTopic: topic={}, routingKey={}", d.getExchange(), d.getRoutingKey()); + amqpTemplate.convertAndSend(d.getExchange(), d.getRoutingKey(), payload); + + return ResponseEntity.accepted().build(); + + }); + } + + + @GetMapping(value = "/topic/{name}", produces = MediaType.TEXT_EVENT_STREAM_VALUE) + public Flux receiveMessagesFromTopic(@PathVariable String name) { + + DestinationInfo d = destinationsConfig.getTopics().get(name); + + if (d == null) { + return Flux.just(ResponseEntity.notFound().build()); + } + + final Queue topicQueue = createTopicQueue(d); + + Stream s = Stream.generate(() -> { + String queueName = topicQueue.getName(); + + log.info("[I137] Polling {}", queueName); + + try { + Object payload = amqpTemplate.receiveAndConvert(queueName,5000); + if ( payload == null ) { + payload = "No news is good news..."; + } + + return payload.toString(); + } + catch(AmqpException ex) { + log.warn("[W247] Received an AMQP Exception: {}", ex.getMessage()); + return null; + } + }); + + + return Flux.fromStream(s) + .doOnCancel(() -> { + log.info("[I250] doOnCancel()"); + amqpAdmin.deleteQueue(topicQueue.getName()); + }) + .subscribeOn(Schedulers.elastic()); + + + } + + + private Queue createTopicQueue(DestinationInfo destination) { + + Exchange ex = ExchangeBuilder.topicExchange(destination.getExchange()) + .durable(true) + .build(); + + amqpAdmin.declareExchange(ex); + + // Create a durable queue + Queue q = QueueBuilder + .durable() + .build(); + + amqpAdmin.declareQueue(q); + + Binding b = BindingBuilder.bind(q) + .to(ex) + .with(destination.getRoutingKey()) + .noargs(); + + amqpAdmin.declareBinding(b); + + return q; + } + + +} diff --git a/spring-webflux-amqp/src/main/resources/application.yml b/spring-webflux-amqp/src/main/resources/application.yml new file mode 100755 index 0000000000..3f527ce4c5 --- /dev/null +++ b/spring-webflux-amqp/src/main/resources/application.yml @@ -0,0 +1,27 @@ +spring: + rabbitmq: + host: 192.168.99.100 + port: 5672 + username: guest + password: guest + +destinations: + queues: + NYSE: + exchange: nyse + routing-key: NYSE + IBOV: + exchange: ibov + routing-key: IBOV + + + topics: + weather: + exchange: alerts + routing-key: WEATHER + + + + + + diff --git a/spring-webflux-amqp/src/test/java/org/baeldung/spring/amqp/SpringWebfluxAmqpLiveTest.java b/spring-webflux-amqp/src/test/java/org/baeldung/spring/amqp/SpringWebfluxAmqpLiveTest.java new file mode 100755 index 0000000000..bda490c189 --- /dev/null +++ b/spring-webflux-amqp/src/test/java/org/baeldung/spring/amqp/SpringWebfluxAmqpLiveTest.java @@ -0,0 +1,26 @@ +package org.baeldung.spring.amqp; + +import org.junit.Test; +import org.springframework.test.web.reactive.server.WebTestClient; + + +public class SpringWebfluxAmqpLiveTest { + + @Test + public void whenSendingAMessageToQueue_thenAcceptedReturnCode() { + + WebTestClient client = WebTestClient.bindToServer() + .baseUrl("http://localhost:8080") + .build(); + + client.post() + .uri("/queue/NYSE") + .syncBody("Test Message") + .exchange() + .expectStatus().isAccepted(); + + } + + + +} From 272f018f90673a5d7e86a7742aadb8a58d4cd33e Mon Sep 17 00:00:00 2001 From: Eric Goebelbecker Date: Wed, 13 Jun 2018 11:15:57 -0400 Subject: [PATCH 45/84] BAEL-1614 - Docker with Java Guest Post (#4474) * BAEL-1614 - additions for docker * BAEL-1614 - move docker project to guest module --- .../WebContent/META-INF/MANIFEST.MF | 1 - guest/spring-boot-app/docker/Dockerfile | 16 ++++++++++++++++ guest/spring-boot-app/docker/logback.xml | 15 +++++++++++++++ guest/spring-boot-app/docker/run.sh | 4 ++++ guest/spring-boot-app/pom.xml | 18 +++++++++++++++++- spring-boot-ops/pom.xml | 1 - 6 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 guest/spring-boot-app/docker/Dockerfile create mode 100644 guest/spring-boot-app/docker/logback.xml create mode 100755 guest/spring-boot-app/docker/run.sh diff --git a/guest/spring-boot-app/WebContent/META-INF/MANIFEST.MF b/guest/spring-boot-app/WebContent/META-INF/MANIFEST.MF index 254272e1c0..e3c07ab38a 100644 --- a/guest/spring-boot-app/WebContent/META-INF/MANIFEST.MF +++ b/guest/spring-boot-app/WebContent/META-INF/MANIFEST.MF @@ -1,3 +1,2 @@ Manifest-Version: 1.0 Class-Path: - diff --git a/guest/spring-boot-app/docker/Dockerfile b/guest/spring-boot-app/docker/Dockerfile new file mode 100644 index 0000000000..211e8927a3 --- /dev/null +++ b/guest/spring-boot-app/docker/Dockerfile @@ -0,0 +1,16 @@ +# Alpine Linux with OpenJDK JRE +FROM openjdk:8-jre-alpine +RUN apk add --no-cache bash + +# copy fat WAR +COPY spring-boot-app-0.0.1-SNAPSHOT.war /app.war + +# copy fat WAR +COPY logback.xml /logback.xml + +COPY run.sh /run.sh + +# runs application +#CMD ["/usr/bin/java", "-jar", "-Dspring.profiles.active=default", "-Dlogging.config=/logback.xml", "/app.war"] + +ENTRYPOINT ["/run.sh"] diff --git a/guest/spring-boot-app/docker/logback.xml b/guest/spring-boot-app/docker/logback.xml new file mode 100644 index 0000000000..7e03ddc827 --- /dev/null +++ b/guest/spring-boot-app/docker/logback.xml @@ -0,0 +1,15 @@ + + + + + /var/log/Application/application.log + true + + %-7d{yyyy-MM-dd HH:mm:ss:SSS} %m%n + + + + + + + diff --git a/guest/spring-boot-app/docker/run.sh b/guest/spring-boot-app/docker/run.sh new file mode 100755 index 0000000000..aeecc29371 --- /dev/null +++ b/guest/spring-boot-app/docker/run.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +java -Dspring.profiles.active=$1 -Dlogging.config=/logback.xml -jar /app.war + diff --git a/guest/spring-boot-app/pom.xml b/guest/spring-boot-app/pom.xml index ba57bbd5c5..c02eef7ef3 100644 --- a/guest/spring-boot-app/pom.xml +++ b/guest/spring-boot-app/pom.xml @@ -51,6 +51,22 @@ WebContent + + org.springframework.boot + spring-boot-maven-plugin + + + + repackage + + + com.stackify.Application + ${project.basedir}/docker + + + + +
@@ -58,4 +74,4 @@ 8.0.43 - \ No newline at end of file + diff --git a/spring-boot-ops/pom.xml b/spring-boot-ops/pom.xml index b34fef8e6f..dce826dbb5 100644 --- a/spring-boot-ops/pom.xml +++ b/spring-boot-ops/pom.xml @@ -138,7 +138,6 @@ com.baeldung.webjar.WebjarsdemoApplication - ${project.basedir}/docker From 2b0c6ed6550fda9ae77fd500382ef9ea905e102e Mon Sep 17 00:00:00 2001 From: Grzegorz Piwowarek Date: Wed, 13 Jun 2018 17:19:03 +0200 Subject: [PATCH 46/84] Kiview ftpclient (#4456) * Add example for FTP client Using Apache Commons Net * Add missing resource * Fix wrong file download in integration test * Add example for using FTP support in JDK * Close input stream after copy * Fix test name --- libraries/pom.xml | 16 ++++ .../main/java/com/baeldung/ftp/FtpClient.java | 63 ++++++++++++++++ .../baeldung/javalin/User/UserController.java | 2 +- .../ftp/FtpClientIntegrationTest.java | 73 +++++++++++++++++++ .../ftp/JdkFtpClientIntegrationTest.java | 63 ++++++++++++++++ libraries/src/test/resources/ftp/baz.txt | 0 spring-boot-ops/README.md | 2 +- 7 files changed, 217 insertions(+), 2 deletions(-) create mode 100644 libraries/src/main/java/com/baeldung/ftp/FtpClient.java create mode 100644 libraries/src/test/java/com/baeldung/ftp/FtpClientIntegrationTest.java create mode 100644 libraries/src/test/java/com/baeldung/ftp/JdkFtpClientIntegrationTest.java create mode 100644 libraries/src/test/resources/ftp/baz.txt diff --git a/libraries/pom.xml b/libraries/pom.xml index 4f90d63d93..663b9e68bb 100644 --- a/libraries/pom.xml +++ b/libraries/pom.xml @@ -709,6 +709,20 @@ xchart ${xchart-version} + + + commons-net + commons-net + ${commons-net.version} + + + org.mockftpserver + MockFtpServer + ${mockftpserver.version} + test + + + @@ -923,6 +937,8 @@ 2.5.11 3.6.1 3.5.2 + 3.6 + 2.7.1 \ No newline at end of file diff --git a/libraries/src/main/java/com/baeldung/ftp/FtpClient.java b/libraries/src/main/java/com/baeldung/ftp/FtpClient.java new file mode 100644 index 0000000000..209bed35f0 --- /dev/null +++ b/libraries/src/main/java/com/baeldung/ftp/FtpClient.java @@ -0,0 +1,63 @@ +package com.baeldung.ftp; + +import org.apache.commons.net.PrintCommandListener; +import org.apache.commons.net.ftp.FTPClient; +import org.apache.commons.net.ftp.FTPFile; +import org.apache.commons.net.ftp.FTPReply; + +import java.io.*; +import java.util.Arrays; +import java.util.Collection; +import java.util.stream.Collectors; + +class FtpClient { + + private final String server; + private final int port; + private final String user; + private final String password; + private FTPClient ftp; + + FtpClient(String server, int port, String user, String password) { + this.server = server; + this.port = port; + this.user = user; + this.password = password; + } + + void open() throws IOException { + ftp = new FTPClient(); + + ftp.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out))); + + ftp.connect(server, port); + int reply = ftp.getReplyCode(); + if (!FTPReply.isPositiveCompletion(reply)) { + ftp.disconnect(); + throw new IOException("Exception in connecting to FTP Server"); + } + + ftp.login(user, password); + } + + void close() throws IOException { + ftp.disconnect(); + } + + Collection listFiles(String path) throws IOException { + FTPFile[] files = ftp.listFiles(path); + + return Arrays.stream(files) + .map(FTPFile::getName) + .collect(Collectors.toList()); + } + + void putFileToPath(File file, String path) throws IOException { + ftp.storeFile(path, new FileInputStream(file)); + } + + void downloadFile(String source, String destination) throws IOException { + FileOutputStream out = new FileOutputStream(destination); + ftp.retrieveFile(source, out); + } +} diff --git a/libraries/src/main/java/com/baeldung/javalin/User/UserController.java b/libraries/src/main/java/com/baeldung/javalin/User/UserController.java index fd713606cf..685890c6d7 100644 --- a/libraries/src/main/java/com/baeldung/javalin/User/UserController.java +++ b/libraries/src/main/java/com/baeldung/javalin/User/UserController.java @@ -14,7 +14,7 @@ public class UserController { public static Handler fetchById = ctx -> { int id = Integer.parseInt(Objects.requireNonNull(ctx.param("id"))); UserDao dao = UserDao.instance(); - User user = dao.getUserById(id); + User user = dao.getUserById(id).get(); if (user == null) { ctx.html("Not Found"); } else { diff --git a/libraries/src/test/java/com/baeldung/ftp/FtpClientIntegrationTest.java b/libraries/src/test/java/com/baeldung/ftp/FtpClientIntegrationTest.java new file mode 100644 index 0000000000..43da69f96d --- /dev/null +++ b/libraries/src/test/java/com/baeldung/ftp/FtpClientIntegrationTest.java @@ -0,0 +1,73 @@ +package com.baeldung.ftp; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.mockftpserver.fake.FakeFtpServer; +import org.mockftpserver.fake.UserAccount; +import org.mockftpserver.fake.filesystem.DirectoryEntry; +import org.mockftpserver.fake.filesystem.FileEntry; +import org.mockftpserver.fake.filesystem.FileSystem; +import org.mockftpserver.fake.filesystem.UnixFakeFileSystem; + +import java.io.File; +import java.io.IOException; +import java.net.URISyntaxException; +import java.util.Collection; + +import static org.assertj.core.api.Assertions.assertThat; + +public class FtpClientIntegrationTest { + + private FakeFtpServer fakeFtpServer; + + private FtpClient ftpClient; + + @Before + public void setup() throws IOException { + fakeFtpServer = new FakeFtpServer(); + fakeFtpServer.addUserAccount(new UserAccount("user", "password", "/data")); + + FileSystem fileSystem = new UnixFakeFileSystem(); + fileSystem.add(new DirectoryEntry("/data")); + fileSystem.add(new FileEntry("/data/foobar.txt", "abcdef 1234567890")); + fakeFtpServer.setFileSystem(fileSystem); + fakeFtpServer.setServerControlPort(0); + + fakeFtpServer.start(); + + ftpClient = new FtpClient("localhost", fakeFtpServer.getServerControlPort(), "user", "password"); + ftpClient.open(); + } + + @After + public void teardown() throws IOException { + ftpClient.close(); + fakeFtpServer.stop(); + } + + @Test + public void givenRemoteFile_whenListingRemoteFiles_thenItIsContainedInList() throws IOException { + Collection files = ftpClient.listFiles(""); + + assertThat(files).contains("foobar.txt"); + } + + @Test + public void givenRemoteFile_whenDownloading_thenItIsOnTheLocalFilesystem() throws IOException { + ftpClient.downloadFile("/foobar.txt", "downloaded_buz.txt"); + + assertThat(new File("downloaded_buz.txt")).exists(); + new File("downloaded_buz.txt").delete(); // cleanup + } + + @Test + public void givenLocalFile_whenUploadingIt_thenItExistsOnRemoteLocation() throws URISyntaxException, IOException { + File file = new File(getClass().getClassLoader().getResource("ftp/baz.txt").toURI()); + + ftpClient.putFileToPath(file, "/buz.txt"); + + assertThat(fakeFtpServer.getFileSystem().exists("/buz.txt")).isTrue(); + } + +} diff --git a/libraries/src/test/java/com/baeldung/ftp/JdkFtpClientIntegrationTest.java b/libraries/src/test/java/com/baeldung/ftp/JdkFtpClientIntegrationTest.java new file mode 100644 index 0000000000..ef6809b02d --- /dev/null +++ b/libraries/src/test/java/com/baeldung/ftp/JdkFtpClientIntegrationTest.java @@ -0,0 +1,63 @@ +package com.baeldung.ftp; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.mockftpserver.fake.FakeFtpServer; +import org.mockftpserver.fake.UserAccount; +import org.mockftpserver.fake.filesystem.DirectoryEntry; +import org.mockftpserver.fake.filesystem.FileEntry; +import org.mockftpserver.fake.filesystem.FileSystem; +import org.mockftpserver.fake.filesystem.UnixFakeFileSystem; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.net.URISyntaxException; +import java.net.URL; +import java.net.URLConnection; +import java.nio.file.Files; +import java.util.Collection; + +import static org.assertj.core.api.Assertions.assertThat; + +public class JdkFtpClientIntegrationTest { + + private FakeFtpServer fakeFtpServer; + + + @Before + public void setup() throws IOException { + fakeFtpServer = new FakeFtpServer(); + fakeFtpServer.addUserAccount(new UserAccount("user", "password", "/data")); + + FileSystem fileSystem = new UnixFakeFileSystem(); + fileSystem.add(new DirectoryEntry("/data")); + fileSystem.add(new FileEntry("/data/foobar.txt", "abcdef 1234567890")); + fakeFtpServer.setFileSystem(fileSystem); + fakeFtpServer.setServerControlPort(0); + + fakeFtpServer.start(); + } + + @After + public void teardown() throws IOException { + fakeFtpServer.stop(); + } + + @Test + public void givenRemoteFile_whenDownloading_thenItIsOnTheLocalFilesystem() throws IOException { + String ftpUrl = String.format("ftp://user:password@localhost:%d/foobar.txt", fakeFtpServer.getServerControlPort()); + + URLConnection urlConnection = new URL(ftpUrl).openConnection(); + InputStream inputStream = urlConnection.getInputStream(); + Files.copy(inputStream, new File("downloaded_buz.txt").toPath()); + inputStream.close(); + + assertThat(new File("downloaded_buz.txt")).exists(); + + new File("downloaded_buz.txt").delete(); // cleanup + } + +} diff --git a/libraries/src/test/resources/ftp/baz.txt b/libraries/src/test/resources/ftp/baz.txt new file mode 100644 index 0000000000..e69de29bb2 diff --git a/spring-boot-ops/README.md b/spring-boot-ops/README.md index 02c4c100aa..26caccb727 100644 --- a/spring-boot-ops/README.md +++ b/spring-boot-ops/README.md @@ -1,3 +1,3 @@ -### Relevant articles +### Relevant Articles: - [Deploy a Spring Boot WAR into a Tomcat Server](http://www.baeldung.com/spring-boot-war-tomcat-deploy) From 2fe0dee64e97c1f7babf228cfaea89b8653cc1c3 Mon Sep 17 00:00:00 2001 From: charlesgonzales <39999268+charlesgonzales@users.noreply.github.com> Date: Thu, 14 Jun 2018 01:50:33 +0800 Subject: [PATCH 47/84] Update 13 README.md and create 2 README.md (#4468) * 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 * Create README.md * Create README.md --- README.md | 1 + core-java-8/README.md | 2 +- core-java-9/README.md | 1 + core-java/README.md | 4 ++++ javax-servlets/README.md | 1 + msf4j/README.md | 2 +- patterns/design-patterns/README.md | 2 +- performance-tests/README.md | 3 +++ spring-5-reactive/README.md | 1 + spring-boot-ops/README.md | 7 +++++++ spring-core/README.md | 1 + spring-data-rest-querydsl/README.md | 2 ++ spring-mockito/README.md | 1 + spring-mvc-java/README.md | 3 +++ testing-modules/junit-5/README.md | 3 +-- 15 files changed, 29 insertions(+), 5 deletions(-) create mode 100644 performance-tests/README.md create mode 100644 spring-data-rest-querydsl/README.md 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/core-java-8/README.md b/core-java-8/README.md index df6d50ad30..2eb8d49983 100644 --- a/core-java-8/README.md +++ b/core-java-8/README.md @@ -52,4 +52,4 @@ - [Measure Elapsed Time in Java](http://www.baeldung.com/java-measure-elapsed-time) - [Java Optional – orElse() vs orElseGet()](http://www.baeldung.com/java-optional-or-else-vs-or-else-get) - [An Introduction to Java.util.Hashtable Class](http://www.baeldung.com/java-hash-table) - +- [Method Parameter Reflection in Java](http://www.baeldung.com/java-parameter-reflection) diff --git a/core-java-9/README.md b/core-java-9/README.md index 4223e57d4b..a76dcefc69 100644 --- a/core-java-9/README.md +++ b/core-java-9/README.md @@ -25,3 +25,4 @@ - [Introduction to Chronicle Queue](http://www.baeldung.com/java-chronicle-queue) - [A Guide to Java 9 Modularity](http://www.baeldung.com/java-9-modularity) - [Optional orElse Optional](http://www.baeldung.com/java-optional-or-else-optional) +- [Java 9 java.lang.Module API](http://www.baeldung.com/java-9-module-api) diff --git a/core-java/README.md b/core-java/README.md index 79f7b4169e..fa2d7e4cf0 100644 --- a/core-java/README.md +++ b/core-java/README.md @@ -156,3 +156,7 @@ - [Flyweight Pattern in Java](http://www.baeldung.com/java-flyweight) - [The Observer Pattern in Java](http://www.baeldung.com/java-observer-pattern) - [Service Locator Pattern](http://www.baeldung.com/java-service-locator-pattern) +- [The Thread.join() Method in Java](http://www.baeldung.com/java-thread-join) +- [Guide to the super Java Keyword](http://www.baeldung.com/java-super) +- [Guide to the this Java Keyword](http://www.baeldung.com/java-this) +- [Jagged Arrays In Java](http://www.baeldung.com/java-jagged-arrays) diff --git a/javax-servlets/README.md b/javax-servlets/README.md index de8a8e4498..55ca1116aa 100644 --- a/javax-servlets/README.md +++ b/javax-servlets/README.md @@ -4,3 +4,4 @@ - [Handling Cookies and a Session in a Java Servlet](http://www.baeldung.com/java-servlet-cookies-session) - [Uploading Files with Servlets and JSP](http://www.baeldung.com/upload-file-servlet) - [Example of Downloading File in a Servlet](http://www.baeldung.com/servlet-download-file) +- [Returning a JSON Response from a Servlet](http://www.baeldung.com/servlet-json-response) diff --git a/msf4j/README.md b/msf4j/README.md index 19e611832c..7c66b8dc5f 100644 --- a/msf4j/README.md +++ b/msf4j/README.md @@ -1,3 +1,3 @@ ### Relevant Articles: -- [Introduction to Java Microservices with MSF4J](http://www.baeldung.com/spring-boot-war-tomcat-deploy) +- [Introduction to Java Microservices with MSF4J](http://www.baeldung.com/msf4j) diff --git a/patterns/design-patterns/README.md b/patterns/design-patterns/README.md index fb80f4bd6a..77ead0b317 100644 --- a/patterns/design-patterns/README.md +++ b/patterns/design-patterns/README.md @@ -8,4 +8,4 @@ - [Service Locator Pattern](http://www.baeldung.com/java-service-locator-pattern) - [Double-Checked Locking with Singleton](http://www.baeldung.com/java-singleton-double-checked-locking) - [Composite Design Pattern in Java](http://www.baeldung.com/java-composite-pattern) - +- [Visitor Design Pattern in Java](http://www.baeldung.com/java-visitor-pattern) diff --git a/performance-tests/README.md b/performance-tests/README.md new file mode 100644 index 0000000000..5af735b708 --- /dev/null +++ b/performance-tests/README.md @@ -0,0 +1,3 @@ +### Relevant Articles: + +- [Performance of Java Mapping Frameworks](http://www.baeldung.com/java-performance-mapping-frameworks) diff --git a/spring-5-reactive/README.md b/spring-5-reactive/README.md index 9998dbf751..df96d933ba 100644 --- a/spring-5-reactive/README.md +++ b/spring-5-reactive/README.md @@ -17,3 +17,4 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [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) +- [Spring Data Reactive Repositories with MongoDB](http://www.baeldung.com/spring-data-mongodb-reactive) diff --git a/spring-boot-ops/README.md b/spring-boot-ops/README.md index 26caccb727..7eca307924 100644 --- a/spring-boot-ops/README.md +++ b/spring-boot-ops/README.md @@ -1,3 +1,10 @@ ### Relevant Articles: - [Deploy a Spring Boot WAR into a Tomcat Server](http://www.baeldung.com/spring-boot-war-tomcat-deploy) +- [Spring Boot Dependency Management with a Custom Parent](http://www.baeldung.com/spring-boot-dependency-management-custom-parent) +- [A Custom Data Binder in Spring MVC](http://www.baeldung.com/spring-mvc-custom-data-binder) +- [Create a Fat Jar App with Spring Boot](http://www.baeldung.com/deployable-fat-jar-spring-boot) +- [Introduction to WebJars](http://www.baeldung.com/maven-webjars) +- [Intro to Spring Boot Starters](http://www.baeldung.com/spring-boot-starters) +- [A Quick Guide to Maven Wrapper](http://www.baeldung.com/maven-wrapper) +- [Shutdown a Spring Boot Application](http://www.baeldung.com/spring-boot-shutdown) diff --git a/spring-core/README.md b/spring-core/README.md index cec85534f5..3684c7f6e9 100644 --- a/spring-core/README.md +++ b/spring-core/README.md @@ -15,3 +15,4 @@ - [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) - [BeanNameAware and BeanFactoryAware Interfaces in Spring](http://www.baeldung.com/spring-bean-name-factory-aware) +- [Spring – Injecting Collections](http://www.baeldung.com/spring-injecting-collections) diff --git a/spring-data-rest-querydsl/README.md b/spring-data-rest-querydsl/README.md new file mode 100644 index 0000000000..03b5fee06a --- /dev/null +++ b/spring-data-rest-querydsl/README.md @@ -0,0 +1,2 @@ +### Relevant Articles: +- [REST Query Language Over Multiple Tables with Querydsl Web Support](http://www.baeldung.com/rest-querydsl-multiple-tables) diff --git a/spring-mockito/README.md b/spring-mockito/README.md index 3ced7161fa..969954c15e 100644 --- a/spring-mockito/README.md +++ b/spring-mockito/README.md @@ -5,3 +5,4 @@ ### Relevant Articles: - [Injecting Mockito Mocks into Spring Beans](http://www.baeldung.com/injecting-mocks-in-spring) +- [Mockito ArgumentMatchers](http://www.baeldung.com/mockito-argument-matchers) diff --git a/spring-mvc-java/README.md b/spring-mvc-java/README.md index 877439145d..b97b961e60 100644 --- a/spring-mvc-java/README.md +++ b/spring-mvc-java/README.md @@ -29,3 +29,6 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [Spring MVC @PathVariable with a dot (.) gets truncated](http://www.baeldung.com/spring-mvc-pathvariable-dot) - [A Quick Example of Spring Websockets’ @SendToUser Annotation](http://www.baeldung.com/spring-websockets-sendtouser) - [Spring Boot Annotations](http://www.baeldung.com/spring-boot-annotations) +- [Spring Scheduling Annotations](http://www.baeldung.com/spring-scheduling-annotations) +- [Spring Web Annotations](http://www.baeldung.com/spring-mvc-annotations) +- [Spring Core Annotations](http://www.baeldung.com/spring-core-annotations) diff --git a/testing-modules/junit-5/README.md b/testing-modules/junit-5/README.md index 6ab00e58d5..2292c3272a 100644 --- a/testing-modules/junit-5/README.md +++ b/testing-modules/junit-5/README.md @@ -12,5 +12,4 @@ - [JUnit Assert an Exception is Thrown](http://www.baeldung.com/junit-assert-exception) - [@Before vs @BeforeClass vs @BeforeEach vs @BeforeAll](http://www.baeldung.com/junit-before-beforeclass-beforeeach-beforeall) - [Migrating from JUnit 4 to JUnit 5](http://www.baeldung.com/junit-5-migration) - - +- [JUnit5 Programmatic Extension Registration with @RegisterExtension](http://www.baeldung.com/junit-5-registerextension-annotation) From 7afbfb69686bd378ac7538a0516e01077d36ac0f Mon Sep 17 00:00:00 2001 From: Orry Date: Wed, 13 Jun 2018 21:44:30 +0200 Subject: [PATCH 48/84] BAEL-1755: Big O Notation Explained (#4440) * BAEL-1701: Create SQSApplication, add most functionality (still need to format, and add queue monitoring) * BAEL-1701: Complete examples * BAEL-1755: Big O Explained * BAEL-1755: Move code to test folder * BAEL-1755: Remove main() method from test class * BAEL-1755: BBD stylify the unit tests and separate them into their own methods --- .../analysis/AnalysisRunnerLiveTest.java | 139 ++++++++++++++++++ 1 file changed, 139 insertions(+) create mode 100644 algorithms/src/test/java/com/baeldung/algorithms/analysis/AnalysisRunnerLiveTest.java diff --git a/algorithms/src/test/java/com/baeldung/algorithms/analysis/AnalysisRunnerLiveTest.java b/algorithms/src/test/java/com/baeldung/algorithms/analysis/AnalysisRunnerLiveTest.java new file mode 100644 index 0000000000..1e9188f726 --- /dev/null +++ b/algorithms/src/test/java/com/baeldung/algorithms/analysis/AnalysisRunnerLiveTest.java @@ -0,0 +1,139 @@ +package com.baeldung.algorithms.analysis; + +import org.junit.Test; + +public class AnalysisRunnerLiveTest { + + int n = 10; + int total = 0; + + @Test + public void whenConstantComplexity_thenConstantRuntime() { + + System.out.println("**** n = " + n + " ****"); + System.out.println(); + + // Constant Time + System.out.println("**** Constant time ****"); + + System.out.println("Hey - your input is: " + n); + System.out.println("Running time not dependent on input size!"); + System.out.println(); + } + + @Test + public void whenLogarithmicComplexity_thenLogarithmicRuntime() { + // Logarithmic Time + System.out.println("**** Logarithmic Time ****"); + for (int i = 1; i < n; i = i * 2) { + // System.out.println("Hey - I'm busy looking at: " + i); + total++; + } + System.out.println("Total amount of times run: " + total); + System.out.println(); + } + + @Test + public void whenLinearComplexity_thenLinearRuntime() { + // Linear Time + System.out.println("**** Linear Time ****"); + for (int i = 0; i < n; i++) { + // System.out.println("Hey - I'm busy looking at: " + i); + total++; + } + System.out.println("Total amount of times run: " + total); + System.out.println(); + + } + + @Test + public void whenNLogNComplexity_thenNLogNRuntime() { + // N Log N Time + System.out.println("**** nlogn Time ****"); + total = 0; + for ( + + int i = 1; i <= n; i++) { + for (int j = 1; j < n; j = j * 2) { + // System.out.println("Hey - I'm busy looking at: " + i + " and " + j); + total++; + } + } + System.out.println("Total amount of times run: " + total); + System.out.println(); + } + + @Test + public void whenQuadraticComplexity_thenQuadraticRuntime() { + // Quadratic Time + System.out.println("**** Quadratic Time ****"); + total = 0; + for ( + + int i = 1; i <= n; i++) { + for (int j = 1; j <= n; j++) { + // System.out.println("Hey - I'm busy looking at: " + i + " and " + j); + total++; + } + } + System.out.println("Total amount of times run: " + total); + System.out.println(); + } + + @Test + public void whenCubicComplexity_thenCubicRuntime() { + // Cubic Time + System.out.println("**** Cubic Time ****"); + total = 0; + for ( + + int i = 1; i <= n; i++) { + for (int j = 1; j <= n; j++) { + for (int k = 1; k <= n; k++) { + // System.out.println("Hey - I'm busy looking at: " + i + " and " + j + " and " + k); + total++; + } + } + } + System.out.println("Total amount of times run: " + total); + System.out.println(); + } + + @Test + public void whenExponentialComplexity_thenExponentialRuntime() { + // Exponential Time + System.out.println("**** Exponential Time ****"); + total = 0; + for ( + + int i = 1; i <= Math.pow(2, n); i++) { + // System.out.println("Hey - I'm busy looking at: " + i); + total++; + } + System.out.println("Total amount of times run: " + total); + System.out.println(); + } + + @Test + public void whenFactorialComplexity_thenFactorialRuntime() { + // Factorial Time + System.out.println("**** Factorial Time ****"); + total = 0; + for ( + + int i = 1; i <= + + factorial(n); i++) { + // System.out.println("Hey - I'm busy looking at: " + i); + total++; + } + System.out.println("Total amount of times run: " + total); + } + + static int factorial(int n) { + if (n == 0 || n == 1) + return 1; + else + return n * factorial(n - 1); + } +} From 0da637d1f970c9ef5c3c6cf4f217ad5922bb3d49 Mon Sep 17 00:00:00 2001 From: Tino M Thomas Date: Wed, 13 Jun 2018 22:51:53 +0300 Subject: [PATCH 49/84] Spring shutdown callback methodologies - BAEL 1831 --- .../ShutdownHookApplication.java | 14 +++++++++++ .../baeldung/shutdownhooks/beans/Bean1.java | 14 +++++++++++ .../baeldung/shutdownhooks/beans/Bean2.java | 14 +++++++++++ .../baeldung/shutdownhooks/beans/Bean3.java | 8 ++++++ .../config/ExampleServletContextListener.java | 18 +++++++++++++ .../config/ShutdownHookConfiguration.java | 25 +++++++++++++++++++ 6 files changed, 93 insertions(+) create mode 100644 spring-boot/src/main/java/com/baeldung/shutdownhooks/ShutdownHookApplication.java create mode 100644 spring-boot/src/main/java/com/baeldung/shutdownhooks/beans/Bean1.java create mode 100644 spring-boot/src/main/java/com/baeldung/shutdownhooks/beans/Bean2.java create mode 100644 spring-boot/src/main/java/com/baeldung/shutdownhooks/beans/Bean3.java create mode 100644 spring-boot/src/main/java/com/baeldung/shutdownhooks/config/ExampleServletContextListener.java create mode 100644 spring-boot/src/main/java/com/baeldung/shutdownhooks/config/ShutdownHookConfiguration.java diff --git a/spring-boot/src/main/java/com/baeldung/shutdownhooks/ShutdownHookApplication.java b/spring-boot/src/main/java/com/baeldung/shutdownhooks/ShutdownHookApplication.java new file mode 100644 index 0000000000..7cce34a06c --- /dev/null +++ b/spring-boot/src/main/java/com/baeldung/shutdownhooks/ShutdownHookApplication.java @@ -0,0 +1,14 @@ +package com.baeldung.shutdownhooks; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +@EnableAutoConfiguration +public class ShutdownHookApplication { + + public static void main(String args[]) { + SpringApplication.run(ShutdownHookApplication.class, args); + } +} diff --git a/spring-boot/src/main/java/com/baeldung/shutdownhooks/beans/Bean1.java b/spring-boot/src/main/java/com/baeldung/shutdownhooks/beans/Bean1.java new file mode 100644 index 0000000000..e85b9395d3 --- /dev/null +++ b/spring-boot/src/main/java/com/baeldung/shutdownhooks/beans/Bean1.java @@ -0,0 +1,14 @@ +package com.baeldung.shutdownhooks.beans; + +import javax.annotation.PreDestroy; + +import org.springframework.stereotype.Component; + +@Component +public class Bean1 { + + @PreDestroy + public void destroy() { + System.out.println("Shutdown triggered using @PreDestroy."); + } +} diff --git a/spring-boot/src/main/java/com/baeldung/shutdownhooks/beans/Bean2.java b/spring-boot/src/main/java/com/baeldung/shutdownhooks/beans/Bean2.java new file mode 100644 index 0000000000..e85d12e791 --- /dev/null +++ b/spring-boot/src/main/java/com/baeldung/shutdownhooks/beans/Bean2.java @@ -0,0 +1,14 @@ +package com.baeldung.shutdownhooks.beans; + +import org.springframework.beans.factory.DisposableBean; +import org.springframework.stereotype.Component; + +@Component +public class Bean2 implements DisposableBean { + + @Override + public void destroy() throws Exception { + System.out.println("Shutdown triggered using DisposableBean."); + } + +} diff --git a/spring-boot/src/main/java/com/baeldung/shutdownhooks/beans/Bean3.java b/spring-boot/src/main/java/com/baeldung/shutdownhooks/beans/Bean3.java new file mode 100644 index 0000000000..bed1d50ee7 --- /dev/null +++ b/spring-boot/src/main/java/com/baeldung/shutdownhooks/beans/Bean3.java @@ -0,0 +1,8 @@ +package com.baeldung.shutdownhooks.beans; + +public class Bean3 { + + public void destroy() { + System.out.println("Shutdown triggered using bean destroy method."); + } +} diff --git a/spring-boot/src/main/java/com/baeldung/shutdownhooks/config/ExampleServletContextListener.java b/spring-boot/src/main/java/com/baeldung/shutdownhooks/config/ExampleServletContextListener.java new file mode 100644 index 0000000000..07d729cb83 --- /dev/null +++ b/spring-boot/src/main/java/com/baeldung/shutdownhooks/config/ExampleServletContextListener.java @@ -0,0 +1,18 @@ +package com.baeldung.shutdownhooks.config; + +import javax.servlet.ServletContextEvent; +import javax.servlet.ServletContextListener; + +public class ExampleServletContextListener implements ServletContextListener { + + @Override + public void contextDestroyed(ServletContextEvent event) { + System.out.println("Shutdown triggered using ServletContextListener."); + } + + @Override + public void contextInitialized(ServletContextEvent event) { + // Triggers when context initializes + } + +} diff --git a/spring-boot/src/main/java/com/baeldung/shutdownhooks/config/ShutdownHookConfiguration.java b/spring-boot/src/main/java/com/baeldung/shutdownhooks/config/ShutdownHookConfiguration.java new file mode 100644 index 0000000000..2d0712e19b --- /dev/null +++ b/spring-boot/src/main/java/com/baeldung/shutdownhooks/config/ShutdownHookConfiguration.java @@ -0,0 +1,25 @@ +package com.baeldung.shutdownhooks.config; + +import javax.servlet.ServletContextListener; + +import org.springframework.boot.web.servlet.ServletListenerRegistrationBean; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import com.baeldung.shutdownhooks.beans.Bean3; + +@Configuration +public class ShutdownHookConfiguration { + + @Bean(destroyMethod = "destroy") + public Bean3 initializeBean3() { + return new Bean3(); + } + + @Bean + ServletListenerRegistrationBean servletListener() { + ServletListenerRegistrationBean srb = new ServletListenerRegistrationBean<>(); + srb.setListener(new ExampleServletContextListener()); + return srb; + } +} From fc14d426c5589bf4caa4ae380759b814bc8a8980 Mon Sep 17 00:00:00 2001 From: Patryk Kucharz Date: Tue, 12 Jun 2018 18:22:32 +0200 Subject: [PATCH 50/84] BAEL-1730: Optimistic Locking in JPA Tests for the article. --- .../com/baeldung/hibernate/HibernateUtil.java | 4 + .../OptimisticLockingCourse.java | 48 +++++++ .../OptimisticLockingStudent.java | 70 +++++++++ .../OptimisticLockingIntegrationTest.java | 134 ++++++++++++++++++ 4 files changed, 256 insertions(+) create mode 100644 hibernate5/src/main/java/com/baeldung/hibernate/optimisticlocking/OptimisticLockingCourse.java create mode 100644 hibernate5/src/main/java/com/baeldung/hibernate/optimisticlocking/OptimisticLockingStudent.java create mode 100644 hibernate5/src/test/java/com/baeldung/hibernate/optimisticlocking/OptimisticLockingIntegrationTest.java diff --git a/hibernate5/src/main/java/com/baeldung/hibernate/HibernateUtil.java b/hibernate5/src/main/java/com/baeldung/hibernate/HibernateUtil.java index e8fdabebbc..23d7d2e201 100644 --- a/hibernate5/src/main/java/com/baeldung/hibernate/HibernateUtil.java +++ b/hibernate5/src/main/java/com/baeldung/hibernate/HibernateUtil.java @@ -1,5 +1,7 @@ package com.baeldung.hibernate; +import com.baeldung.hibernate.optimisticlocking.OptimisticLockingCourse; +import com.baeldung.hibernate.optimisticlocking.OptimisticLockingStudent; import com.baeldung.hibernate.pessimisticlocking.Individual; import com.baeldung.hibernate.pessimisticlocking.PessimisticLockingCourse; import com.baeldung.hibernate.pessimisticlocking.PessimisticLockingEmployee; @@ -70,6 +72,8 @@ public class HibernateUtil { metadataSources.addAnnotatedClass(PessimisticLockingCourse.class); metadataSources.addAnnotatedClass(com.baeldung.hibernate.pessimisticlocking.Customer.class); metadataSources.addAnnotatedClass(com.baeldung.hibernate.pessimisticlocking.Address.class); + metadataSources.addAnnotatedClass(OptimisticLockingCourse.class); + metadataSources.addAnnotatedClass(OptimisticLockingStudent.class); Metadata metadata = metadataSources.buildMetadata(); return metadata.getSessionFactoryBuilder() diff --git a/hibernate5/src/main/java/com/baeldung/hibernate/optimisticlocking/OptimisticLockingCourse.java b/hibernate5/src/main/java/com/baeldung/hibernate/optimisticlocking/OptimisticLockingCourse.java new file mode 100644 index 0000000000..1af3e3e21b --- /dev/null +++ b/hibernate5/src/main/java/com/baeldung/hibernate/optimisticlocking/OptimisticLockingCourse.java @@ -0,0 +1,48 @@ +package com.baeldung.hibernate.optimisticlocking; + +import javax.persistence.*; + +@Entity +public class OptimisticLockingCourse { + + @Id + private Long id; + + private String name; + + @ManyToOne + @JoinTable(name = "optimistic_student_course") + private OptimisticLockingStudent student; + + public OptimisticLockingCourse(Long id, String name) { + this.id = id; + this.name = name; + } + + public OptimisticLockingCourse() { + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public OptimisticLockingStudent getStudent() { + return student; + } + + public void setStudent(OptimisticLockingStudent student) { + this.student = student; + } +} diff --git a/hibernate5/src/main/java/com/baeldung/hibernate/optimisticlocking/OptimisticLockingStudent.java b/hibernate5/src/main/java/com/baeldung/hibernate/optimisticlocking/OptimisticLockingStudent.java new file mode 100644 index 0000000000..b79212ae8d --- /dev/null +++ b/hibernate5/src/main/java/com/baeldung/hibernate/optimisticlocking/OptimisticLockingStudent.java @@ -0,0 +1,70 @@ +package com.baeldung.hibernate.optimisticlocking; + +import javax.persistence.*; +import java.util.List; + +@Entity +public class OptimisticLockingStudent { + + @Id + private Long id; + + private String name; + + private String lastName; + @Version + private Integer version; + + @OneToMany(mappedBy = "student") + private List courses; + + public OptimisticLockingStudent(Long id, String name, String lastName, List courses) { + this.id = id; + this.name = name; + this.lastName = lastName; + this.courses = courses; + } + + public OptimisticLockingStudent() { + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Integer getVersion() { + return version; + } + + public void setVersion(Integer version) { + this.version = version; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + public List getCourses() { + return courses; + } + + public void setCourses(List courses) { + this.courses = courses; + } +} diff --git a/hibernate5/src/test/java/com/baeldung/hibernate/optimisticlocking/OptimisticLockingIntegrationTest.java b/hibernate5/src/test/java/com/baeldung/hibernate/optimisticlocking/OptimisticLockingIntegrationTest.java new file mode 100644 index 0000000000..68b51764e4 --- /dev/null +++ b/hibernate5/src/test/java/com/baeldung/hibernate/optimisticlocking/OptimisticLockingIntegrationTest.java @@ -0,0 +1,134 @@ +package com.baeldung.hibernate.optimisticlocking; + +import com.baeldung.hibernate.HibernateUtil; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import javax.persistence.EntityManager; +import javax.persistence.LockModeType; +import javax.persistence.OptimisticLockException; +import java.io.IOException; +import java.util.Arrays; + +public class OptimisticLockingIntegrationTest { + + @Before + public void setUp() throws IOException { + EntityManager entityManager = getEntityManagerWithOpenTransaction(); + OptimisticLockingCourse course = new OptimisticLockingCourse(1L, "MATH"); + OptimisticLockingStudent student = new OptimisticLockingStudent(1L, "John", "Doe", Arrays.asList(course)); + course.setStudent(student); + entityManager.persist(course); + entityManager.persist(student); + entityManager.getTransaction() + .commit(); + entityManager.close(); + } + + @After + public void clean() throws IOException { + EntityManager entityManager = getEntityManagerWithOpenTransaction(); + OptimisticLockingCourse course = entityManager.find(OptimisticLockingCourse.class, 1L); + OptimisticLockingStudent student = entityManager.find(OptimisticLockingStudent.class, 1L); + entityManager.remove(course); + entityManager.remove(student); + entityManager.getTransaction() + .commit(); + entityManager.close(); + } + + @Test(expected = OptimisticLockException.class) + public void givenVersionedEntities_whenConcurrentUpdate_thenOptimisticLockException() throws IOException { + EntityManager em = getEntityManagerWithOpenTransaction(); + OptimisticLockingStudent student = em.find(OptimisticLockingStudent.class, 1L); + + EntityManager em2 = getEntityManagerWithOpenTransaction(); + OptimisticLockingStudent student2 = em2.find(OptimisticLockingStudent.class, 1L); + student2.setName("RICHARD"); + em2.persist(student2); + em2.getTransaction() + .commit(); + em2.close(); + + student.setName("JOHN"); + em.persist(student); + em.getTransaction() + .commit(); + em.close(); + } + + @Test(expected = OptimisticLockException.class) + public void givenVersionedEntitiesWithLockByFindMethod_whenConcurrentUpdate_thenOptimisticLockException() throws IOException { + EntityManager em = getEntityManagerWithOpenTransaction(); + OptimisticLockingStudent student = em.find(OptimisticLockingStudent.class, 1L, LockModeType.OPTIMISTIC); + + EntityManager em2 = getEntityManagerWithOpenTransaction(); + OptimisticLockingStudent student2 = em2.find(OptimisticLockingStudent.class, 1L, LockModeType.OPTIMISTIC_FORCE_INCREMENT); + student2.setName("RICHARD"); + em2.persist(student2); + em2.getTransaction() + .commit(); + em2.close(); + + student.setName("JOHN"); + em.persist(student); + em.getTransaction() + .commit(); + em.close(); + } + + @Test(expected = OptimisticLockException.class) + public void givenVersionedEntitiesWithLockByRefreshMethod_whenConcurrentUpdate_thenOptimisticLockException() throws IOException { + EntityManager em = getEntityManagerWithOpenTransaction(); + OptimisticLockingStudent student = em.find(OptimisticLockingStudent.class, 1L); + em.refresh(student, LockModeType.OPTIMISTIC); + + EntityManager em2 = getEntityManagerWithOpenTransaction(); + OptimisticLockingStudent student2 = em2.find(OptimisticLockingStudent.class, 1L); + em.refresh(student, LockModeType.OPTIMISTIC_FORCE_INCREMENT); + student2.setName("RICHARD"); + em2.persist(student2); + em2.getTransaction() + .commit(); + em2.close(); + + student.setName("JOHN"); + em.persist(student); + em.getTransaction() + .commit(); + em.close(); + } + + @Test(expected = OptimisticLockException.class) + public void givenVersionedEntitiesWithLockByLockMethod_whenConcurrentUpdate_thenOptimisticLockException() throws IOException { + EntityManager em = getEntityManagerWithOpenTransaction(); + OptimisticLockingStudent student = em.find(OptimisticLockingStudent.class, 1L); + em.lock(student, LockModeType.OPTIMISTIC); + + EntityManager em2 = getEntityManagerWithOpenTransaction(); + OptimisticLockingStudent student2 = em2.find(OptimisticLockingStudent.class, 1L); + em.lock(student, LockModeType.OPTIMISTIC_FORCE_INCREMENT); + student2.setName("RICHARD"); + em2.persist(student2); + em2.getTransaction() + .commit(); + em2.close(); + + student.setName("JOHN"); + em.persist(student); + em.getTransaction() + .commit(); + em.close(); + } + + protected static EntityManager getEntityManagerWithOpenTransaction() throws IOException { + String propertyFileName = "hibernate-pessimistic-locking.properties"; + EntityManager entityManager = HibernateUtil.getSessionFactory(propertyFileName) + .openSession(); + entityManager.getTransaction() + .begin(); + + return entityManager; + } +} From 01521b9f5bbdf210ed67e6c85229920e4c803042 Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Thu, 14 Jun 2018 13:10:29 +0300 Subject: [PATCH 51/84] Update README.md --- spring-mvc-forms-thymeleaf/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-mvc-forms-thymeleaf/README.md b/spring-mvc-forms-thymeleaf/README.md index 450b10433c..f0f7e35a98 100644 --- a/spring-mvc-forms-thymeleaf/README.md +++ b/spring-mvc-forms-thymeleaf/README.md @@ -1,3 +1,4 @@ ### Relevant articles - [Session Attributes in Spring MVC](http://www.baeldung.com/spring-mvc-session-attributes) +- [Binding a List in Thymeleaf](http://www.baeldung.com/thymeleaf-list) From 29ce574439bc079f4b2064e346565a6b90c995be Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Thu, 14 Jun 2018 13:11:45 +0300 Subject: [PATCH 52/84] Create README.md --- java-ee-8-security-api/README.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 java-ee-8-security-api/README.md diff --git a/java-ee-8-security-api/README.md b/java-ee-8-security-api/README.md new file mode 100644 index 0000000000..1735419236 --- /dev/null +++ b/java-ee-8-security-api/README.md @@ -0,0 +1,3 @@ +### Relevant articles + + - [Java EE 8 Security API](http://www.baeldung.com/java-ee-8-security) From 2cb8d357f43138db03a2721ae423ca784f9915c5 Mon Sep 17 00:00:00 2001 From: iaforek Date: Fri, 15 Jun 2018 08:03:09 +0200 Subject: [PATCH 53/84] BAEL-1737, BAEL-1667 (#4251) * BAEL-1737 - Access Modifiers examples * BAEL-1737 - Corrected constructors * BAEL-1737 - Smaller formatting fixes * BAEL-1737 - Updated comments * BAEL-1667 - Select and Option examples. * BAEL-1667 - Corrected typo - closing select tag - that actually made the code to work. COrrected solution works well too and produces valid HTML --- .../com/baeldung/accessmodifiers/Public.java | 9 +++++ .../baeldung/accessmodifiers/SubClass.java | 9 +++++ .../baeldung/accessmodifiers/SuperPublic.java | 39 +++++++++++++++++++ .../another/AnotherPublic.java | 9 +++++ .../another/AnotherSubClass.java | 10 +++++ .../another/AnotherSuperPublic.java | 9 +++++ .../main/webapp/WEB-INF/views/addStudent.html | 4 +- 7 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 core-java/src/main/java/com/baeldung/accessmodifiers/Public.java create mode 100644 core-java/src/main/java/com/baeldung/accessmodifiers/SubClass.java create mode 100644 core-java/src/main/java/com/baeldung/accessmodifiers/SuperPublic.java create mode 100644 core-java/src/main/java/com/baeldung/accessmodifiers/another/AnotherPublic.java create mode 100644 core-java/src/main/java/com/baeldung/accessmodifiers/another/AnotherSubClass.java create mode 100644 core-java/src/main/java/com/baeldung/accessmodifiers/another/AnotherSuperPublic.java diff --git a/core-java/src/main/java/com/baeldung/accessmodifiers/Public.java b/core-java/src/main/java/com/baeldung/accessmodifiers/Public.java new file mode 100644 index 0000000000..9a64c1d4c4 --- /dev/null +++ b/core-java/src/main/java/com/baeldung/accessmodifiers/Public.java @@ -0,0 +1,9 @@ +package com.baeldung.accessmodifiers; + +public class Public { + public Public() { + SuperPublic.publicMethod(); // Available everywhere. + SuperPublic.protectedMethod(); // Available in the same package or subclass. + SuperPublic.defaultMethod(); // Available in the same package. + } +} diff --git a/core-java/src/main/java/com/baeldung/accessmodifiers/SubClass.java b/core-java/src/main/java/com/baeldung/accessmodifiers/SubClass.java new file mode 100644 index 0000000000..545f48c9ca --- /dev/null +++ b/core-java/src/main/java/com/baeldung/accessmodifiers/SubClass.java @@ -0,0 +1,9 @@ +package com.baeldung.accessmodifiers; + +public class SubClass extends SuperPublic { + public SubClass() { + SuperPublic.publicMethod(); // Available everywhere. + SuperPublic.protectedMethod(); // Available in the same package or subclass. + SuperPublic.defaultMethod(); // Available in the same package. + } +} diff --git a/core-java/src/main/java/com/baeldung/accessmodifiers/SuperPublic.java b/core-java/src/main/java/com/baeldung/accessmodifiers/SuperPublic.java new file mode 100644 index 0000000000..7c9554f2c7 --- /dev/null +++ b/core-java/src/main/java/com/baeldung/accessmodifiers/SuperPublic.java @@ -0,0 +1,39 @@ +package com.baeldung.accessmodifiers; + +//Only public or default access modifiers are permitted +public class SuperPublic { + // Always available from anywhere + static public void publicMethod() { + System.out.println(SuperPublic.class.getName() + " publicMethod()"); + } + + // Available within the same package + static void defaultMethod() { + System.out.println(SuperPublic.class.getName() + " defaultMethod()"); + } + + // Available within the same package and subclasses + static protected void protectedMethod() { + System.out.println(SuperPublic.class.getName() + " protectedMethod()"); + } + + // Available within the same class only + static private void privateMethod() { + System.out.println(SuperPublic.class.getName() + " privateMethod()"); + } + + // Method in the same class = has access to all members within the same class + private void anotherPrivateMethod() { + privateMethod(); + defaultMethod(); + protectedMethod(); + publicMethod(); // Available in the same class only. + } +} + +// Only public or default access modifiers are permitted +class SuperDefault { + public void publicMethod() { + System.out.println(this.getClass().getName() + " publicMethod()"); + } +} diff --git a/core-java/src/main/java/com/baeldung/accessmodifiers/another/AnotherPublic.java b/core-java/src/main/java/com/baeldung/accessmodifiers/another/AnotherPublic.java new file mode 100644 index 0000000000..32eea36854 --- /dev/null +++ b/core-java/src/main/java/com/baeldung/accessmodifiers/another/AnotherPublic.java @@ -0,0 +1,9 @@ +package com.baeldung.accessmodifiers.another; + +import com.baeldung.accessmodifiers.SuperPublic; + +public class AnotherPublic { + public AnotherPublic() { + SuperPublic.publicMethod(); // Available everywhere. + } +} diff --git a/core-java/src/main/java/com/baeldung/accessmodifiers/another/AnotherSubClass.java b/core-java/src/main/java/com/baeldung/accessmodifiers/another/AnotherSubClass.java new file mode 100644 index 0000000000..3d9dc3f119 --- /dev/null +++ b/core-java/src/main/java/com/baeldung/accessmodifiers/another/AnotherSubClass.java @@ -0,0 +1,10 @@ +package com.baeldung.accessmodifiers.another; + +import com.baeldung.accessmodifiers.SuperPublic; + +public class AnotherSubClass extends SuperPublic { + public AnotherSubClass() { + SuperPublic.publicMethod(); // Available everywhere. + SuperPublic.protectedMethod(); // Available in subclass. Let's note different package. + } +} diff --git a/core-java/src/main/java/com/baeldung/accessmodifiers/another/AnotherSuperPublic.java b/core-java/src/main/java/com/baeldung/accessmodifiers/another/AnotherSuperPublic.java new file mode 100644 index 0000000000..3932e6f990 --- /dev/null +++ b/core-java/src/main/java/com/baeldung/accessmodifiers/another/AnotherSuperPublic.java @@ -0,0 +1,9 @@ +package com.baeldung.accessmodifiers.another; + +import com.baeldung.accessmodifiers.SuperPublic; + +public class AnotherSuperPublic { + public AnotherSuperPublic() { + SuperPublic.publicMethod(); // Available everywhere. Let's note different package. + } +} diff --git a/spring-thymeleaf/src/main/webapp/WEB-INF/views/addStudent.html b/spring-thymeleaf/src/main/webapp/WEB-INF/views/addStudent.html index f3d28d7ef4..34a6dec4da 100644 --- a/spring-thymeleaf/src/main/webapp/WEB-INF/views/addStudent.html +++ b/spring-thymeleaf/src/main/webapp/WEB-INF/views/addStudent.html @@ -32,7 +32,9 @@