From de6d367e413f3ec302ac19030030e20c11fabe06 Mon Sep 17 00:00:00 2001 From: sanitaso Date: Fri, 25 Feb 2022 12:54:20 +0100 Subject: [PATCH 01/12] add files to springdoc --- .../swaggerResponseAPI/.gitignore | 33 ++++++++ .../swaggerResponseAPI/pom.xml | 69 +++++++++++++++++ .../SwaggerResponseApiApplication.java | 13 ++++ .../controller/ProductController.java | 39 ++++++++++ .../swaggerresponseapi/model/Product.java | 15 ++++ .../service/ProductService.java | 21 +++++ .../src/main/resources/application.properties | 1 + .../ProductIntegrationTest.java | 76 +++++++++++++++++++ .../SwaggerResponseApiApplicationTests.java | 13 ++++ 9 files changed, 280 insertions(+) create mode 100644 spring-boot-modules/spring-boot-springdoc/swaggerResponseAPI/.gitignore create mode 100644 spring-boot-modules/spring-boot-springdoc/swaggerResponseAPI/pom.xml create mode 100644 spring-boot-modules/spring-boot-springdoc/swaggerResponseAPI/src/main/java/com/baeldung/swaggerresponseapi/SwaggerResponseApiApplication.java create mode 100644 spring-boot-modules/spring-boot-springdoc/swaggerResponseAPI/src/main/java/com/baeldung/swaggerresponseapi/controller/ProductController.java create mode 100644 spring-boot-modules/spring-boot-springdoc/swaggerResponseAPI/src/main/java/com/baeldung/swaggerresponseapi/model/Product.java create mode 100644 spring-boot-modules/spring-boot-springdoc/swaggerResponseAPI/src/main/java/com/baeldung/swaggerresponseapi/service/ProductService.java create mode 100644 spring-boot-modules/spring-boot-springdoc/swaggerResponseAPI/src/main/resources/application.properties create mode 100644 spring-boot-modules/spring-boot-springdoc/swaggerResponseAPI/src/test/java/com/baeldung/swaggerresponseapi/ProductIntegrationTest.java create mode 100644 spring-boot-modules/spring-boot-springdoc/swaggerResponseAPI/src/test/java/com/baeldung/swaggerresponseapi/SwaggerResponseApiApplicationTests.java diff --git a/spring-boot-modules/spring-boot-springdoc/swaggerResponseAPI/.gitignore b/spring-boot-modules/spring-boot-springdoc/swaggerResponseAPI/.gitignore new file mode 100644 index 0000000000..f60f3beecd --- /dev/null +++ b/spring-boot-modules/spring-boot-springdoc/swaggerResponseAPI/.gitignore @@ -0,0 +1,33 @@ +HELP.md +target/ +.mvn/wrapper/ +!**/src/main/**/target/ +!**/src/test/**/target/ +mvnv* + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ diff --git a/spring-boot-modules/spring-boot-springdoc/swaggerResponseAPI/pom.xml b/spring-boot-modules/spring-boot-springdoc/swaggerResponseAPI/pom.xml new file mode 100644 index 0000000000..17544290e4 --- /dev/null +++ b/spring-boot-modules/spring-boot-springdoc/swaggerResponseAPI/pom.xml @@ -0,0 +1,69 @@ + + + 4.0.0 + + com.baeldung.spring-boot-modules + spring-boot-disable-logging + 1.0.0-SNAPSHOT + + com.baeldung + swaggerResponseAPI + 0.0.1-SNAPSHOT + swaggerResponseAPI + swaggerResponseAPI + + 11 + + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-test + test + + + org.projectlombok + lombok + true + + + org.springdoc + springdoc-openapi-ui + 1.6.6 + + + junit + junit + 4.13.2 + test + + + com.fasterxml.jackson.core + jackson-databind + 2.13.0 + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + org.projectlombok + lombok + + + + + + + + diff --git a/spring-boot-modules/spring-boot-springdoc/swaggerResponseAPI/src/main/java/com/baeldung/swaggerresponseapi/SwaggerResponseApiApplication.java b/spring-boot-modules/spring-boot-springdoc/swaggerResponseAPI/src/main/java/com/baeldung/swaggerresponseapi/SwaggerResponseApiApplication.java new file mode 100644 index 0000000000..913544b459 --- /dev/null +++ b/spring-boot-modules/spring-boot-springdoc/swaggerResponseAPI/src/main/java/com/baeldung/swaggerresponseapi/SwaggerResponseApiApplication.java @@ -0,0 +1,13 @@ +package com.baeldung.swaggerresponseapi; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SwaggerResponseApiApplication { + + public static void main(String[] args) { + SpringApplication.run(SwaggerResponseApiApplication.class, args); + } + +} diff --git a/spring-boot-modules/spring-boot-springdoc/swaggerResponseAPI/src/main/java/com/baeldung/swaggerresponseapi/controller/ProductController.java b/spring-boot-modules/spring-boot-springdoc/swaggerResponseAPI/src/main/java/com/baeldung/swaggerresponseapi/controller/ProductController.java new file mode 100644 index 0000000000..3e9a3291d9 --- /dev/null +++ b/spring-boot-modules/spring-boot-springdoc/swaggerResponseAPI/src/main/java/com/baeldung/swaggerresponseapi/controller/ProductController.java @@ -0,0 +1,39 @@ +package com.baeldung.swaggerresponseapi.controller; + +import com.baeldung.swaggerresponseapi.model.Product; +import com.baeldung.swaggerresponseapi.service.ProductService; + +import io.swagger.v3.oas.annotations.media.ArraySchema; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +@RestController +public class ProductController { + private final ProductService productService; + + public ProductController(ProductService productService) { + this.productService = productService; + } + + @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "Product successfully added!") }) + @PostMapping("/create") + public Product addProduct(@RequestBody Product product) { + return productService.addProducts(product); + } + + @ApiResponses(value = { @ApiResponse(content = { @Content(mediaType = "application/json", + array = @ArraySchema(schema = @Schema(implementation = Product.class))) }) }) + @GetMapping("/products") + public List getProductsList() { + return productService.getProductsList(); + } +} diff --git a/spring-boot-modules/spring-boot-springdoc/swaggerResponseAPI/src/main/java/com/baeldung/swaggerresponseapi/model/Product.java b/spring-boot-modules/spring-boot-springdoc/swaggerResponseAPI/src/main/java/com/baeldung/swaggerresponseapi/model/Product.java new file mode 100644 index 0000000000..0a100582fc --- /dev/null +++ b/spring-boot-modules/spring-boot-springdoc/swaggerResponseAPI/src/main/java/com/baeldung/swaggerresponseapi/model/Product.java @@ -0,0 +1,15 @@ +package com.baeldung.swaggerresponseapi.model; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Getter +@Setter +@AllArgsConstructor +@NoArgsConstructor +public class Product { + String code; + String name; +} diff --git a/spring-boot-modules/spring-boot-springdoc/swaggerResponseAPI/src/main/java/com/baeldung/swaggerresponseapi/service/ProductService.java b/spring-boot-modules/spring-boot-springdoc/swaggerResponseAPI/src/main/java/com/baeldung/swaggerresponseapi/service/ProductService.java new file mode 100644 index 0000000000..5e7533d6f4 --- /dev/null +++ b/spring-boot-modules/spring-boot-springdoc/swaggerResponseAPI/src/main/java/com/baeldung/swaggerresponseapi/service/ProductService.java @@ -0,0 +1,21 @@ +package com.baeldung.swaggerresponseapi.service; + +import com.baeldung.swaggerresponseapi.model.Product; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.List; + +@Service +public class ProductService { + List productsList = new ArrayList<>(); + + public Product addProducts(Product product) { + productsList.add(product); + return product; + } + + public List getProductsList() { + return productsList; + } +} diff --git a/spring-boot-modules/spring-boot-springdoc/swaggerResponseAPI/src/main/resources/application.properties b/spring-boot-modules/spring-boot-springdoc/swaggerResponseAPI/src/main/resources/application.properties new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/spring-boot-modules/spring-boot-springdoc/swaggerResponseAPI/src/main/resources/application.properties @@ -0,0 +1 @@ + diff --git a/spring-boot-modules/spring-boot-springdoc/swaggerResponseAPI/src/test/java/com/baeldung/swaggerresponseapi/ProductIntegrationTest.java b/spring-boot-modules/spring-boot-springdoc/swaggerResponseAPI/src/test/java/com/baeldung/swaggerresponseapi/ProductIntegrationTest.java new file mode 100644 index 0000000000..ef6a8953e2 --- /dev/null +++ b/spring-boot-modules/spring-boot-springdoc/swaggerResponseAPI/src/test/java/com/baeldung/swaggerresponseapi/ProductIntegrationTest.java @@ -0,0 +1,76 @@ +package com.baeldung.swaggerresponseapi; + +import com.baeldung.swaggerresponseapi.controller.ProductController; +import com.baeldung.swaggerresponseapi.model.Product; +import com.baeldung.swaggerresponseapi.service.ProductService; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.http.MediaType; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.result.MockMvcResultMatchers; + +import java.util.Arrays; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.BDDMockito.given; +import static org.mockito.Mockito.reset; +import static org.hamcrest.CoreMatchers.is; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +@RunWith(SpringRunner.class) +@WebMvcTest(ProductController.class) +public class ProductIntegrationTest { + + @Autowired + MockMvc mock; + + @MockBean + private ProductService productService; + + @Test + public void givenProduct_whenAddNewProduct_thenReturnValidStatusCode() throws Exception { + Product product = new Product("1001", "Milk"); + given(productService.addProducts(any(Product.class))).willReturn(product); + + mock.perform(post("/create").contentType(MediaType.APPLICATION_JSON) + .content(toJsonString(product))) + .andDo(print()) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value("1001")); + + reset(productService); + } + + @Test + public void givenProductsList_whenGetAllProducts_thenReturnValidProducts() throws Exception { + Product product1 = new Product("1001", "Milk"); + Product product2 = new Product("2002", "Butter"); + + given(productService.getProductsList()).willReturn(Arrays.asList(product1, product2)); + + mock.perform(get("/products").contentType(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andDo(print()) + .andExpect(jsonPath("$[0].code", is(product1.getCode()))) + .andExpect(jsonPath("$[1].name", is(product2.getName()))); + + reset(productService); + } + + public String toJsonString(Product product) throws JsonProcessingException { + ObjectMapper om = new ObjectMapper(); + String json = om.writeValueAsString(product); + return json; + } +} diff --git a/spring-boot-modules/spring-boot-springdoc/swaggerResponseAPI/src/test/java/com/baeldung/swaggerresponseapi/SwaggerResponseApiApplicationTests.java b/spring-boot-modules/spring-boot-springdoc/swaggerResponseAPI/src/test/java/com/baeldung/swaggerresponseapi/SwaggerResponseApiApplicationTests.java new file mode 100644 index 0000000000..9e8c6ee0fa --- /dev/null +++ b/spring-boot-modules/spring-boot-springdoc/swaggerResponseAPI/src/test/java/com/baeldung/swaggerresponseapi/SwaggerResponseApiApplicationTests.java @@ -0,0 +1,13 @@ +package com.baeldung.swaggerresponseapi; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class SwaggerResponseApiApplicationTests { + + @Test + void contextLoads() { + } + +} From f62de535543e8f04bfaa073ae2eaf185492fd0cd Mon Sep 17 00:00:00 2001 From: sanitaso Date: Fri, 25 Feb 2022 15:25:38 +0100 Subject: [PATCH 02/12] modify pom --- .../spring-boot-springdoc/swaggerResponseAPI/pom.xml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/spring-boot-modules/spring-boot-springdoc/swaggerResponseAPI/pom.xml b/spring-boot-modules/spring-boot-springdoc/swaggerResponseAPI/pom.xml index 17544290e4..c168248df2 100644 --- a/spring-boot-modules/spring-boot-springdoc/swaggerResponseAPI/pom.xml +++ b/spring-boot-modules/spring-boot-springdoc/swaggerResponseAPI/pom.xml @@ -3,9 +3,10 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - com.baeldung.spring-boot-modules - spring-boot-disable-logging - 1.0.0-SNAPSHOT + org.springframework.boot + spring-boot-starter-parent + 2.6.3 + com.baeldung swaggerResponseAPI From a735229a8433bea1ab0f3076b18a774caddfcd92 Mon Sep 17 00:00:00 2001 From: sanitaso Date: Tue, 8 Mar 2022 15:10:36 +0100 Subject: [PATCH 03/12] change the module directory --- .../SwaggerResponseApiApplication.java | 0 .../controller/ProductController.java | 1 - .../swaggerresponseapi/model/Product.java | 28 +++++++ .../service/ProductService.java | 0 .../swaggerResponseAPI/.gitignore | 33 -------- .../swaggerResponseAPI/pom.xml | 70 ----------------- .../swaggerresponseapi/model/Product.java | 15 ---- .../src/main/resources/application.properties | 1 - .../ProductIntegrationTest.java | 76 ------------------- .../SwaggerResponseApiApplicationTests.java | 13 ---- 10 files changed, 28 insertions(+), 209 deletions(-) rename spring-boot-modules/spring-boot-springdoc/{swaggerResponseAPI => }/src/main/java/com/baeldung/swaggerresponseapi/SwaggerResponseApiApplication.java (100%) rename spring-boot-modules/spring-boot-springdoc/{swaggerResponseAPI => }/src/main/java/com/baeldung/swaggerresponseapi/controller/ProductController.java (92%) create mode 100644 spring-boot-modules/spring-boot-springdoc/src/main/java/com/baeldung/swaggerresponseapi/model/Product.java rename spring-boot-modules/spring-boot-springdoc/{swaggerResponseAPI => }/src/main/java/com/baeldung/swaggerresponseapi/service/ProductService.java (100%) delete mode 100644 spring-boot-modules/spring-boot-springdoc/swaggerResponseAPI/.gitignore delete mode 100644 spring-boot-modules/spring-boot-springdoc/swaggerResponseAPI/pom.xml delete mode 100644 spring-boot-modules/spring-boot-springdoc/swaggerResponseAPI/src/main/java/com/baeldung/swaggerresponseapi/model/Product.java delete mode 100644 spring-boot-modules/spring-boot-springdoc/swaggerResponseAPI/src/main/resources/application.properties delete mode 100644 spring-boot-modules/spring-boot-springdoc/swaggerResponseAPI/src/test/java/com/baeldung/swaggerresponseapi/ProductIntegrationTest.java delete mode 100644 spring-boot-modules/spring-boot-springdoc/swaggerResponseAPI/src/test/java/com/baeldung/swaggerresponseapi/SwaggerResponseApiApplicationTests.java diff --git a/spring-boot-modules/spring-boot-springdoc/swaggerResponseAPI/src/main/java/com/baeldung/swaggerresponseapi/SwaggerResponseApiApplication.java b/spring-boot-modules/spring-boot-springdoc/src/main/java/com/baeldung/swaggerresponseapi/SwaggerResponseApiApplication.java similarity index 100% rename from spring-boot-modules/spring-boot-springdoc/swaggerResponseAPI/src/main/java/com/baeldung/swaggerresponseapi/SwaggerResponseApiApplication.java rename to spring-boot-modules/spring-boot-springdoc/src/main/java/com/baeldung/swaggerresponseapi/SwaggerResponseApiApplication.java diff --git a/spring-boot-modules/spring-boot-springdoc/swaggerResponseAPI/src/main/java/com/baeldung/swaggerresponseapi/controller/ProductController.java b/spring-boot-modules/spring-boot-springdoc/src/main/java/com/baeldung/swaggerresponseapi/controller/ProductController.java similarity index 92% rename from spring-boot-modules/spring-boot-springdoc/swaggerResponseAPI/src/main/java/com/baeldung/swaggerresponseapi/controller/ProductController.java rename to spring-boot-modules/spring-boot-springdoc/src/main/java/com/baeldung/swaggerresponseapi/controller/ProductController.java index 3e9a3291d9..364a7e8a66 100644 --- a/spring-boot-modules/spring-boot-springdoc/swaggerResponseAPI/src/main/java/com/baeldung/swaggerresponseapi/controller/ProductController.java +++ b/spring-boot-modules/spring-boot-springdoc/src/main/java/com/baeldung/swaggerresponseapi/controller/ProductController.java @@ -24,7 +24,6 @@ public class ProductController { this.productService = productService; } - @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "Product successfully added!") }) @PostMapping("/create") public Product addProduct(@RequestBody Product product) { return productService.addProducts(product); diff --git a/spring-boot-modules/spring-boot-springdoc/src/main/java/com/baeldung/swaggerresponseapi/model/Product.java b/spring-boot-modules/spring-boot-springdoc/src/main/java/com/baeldung/swaggerresponseapi/model/Product.java new file mode 100644 index 0000000000..036ecbc853 --- /dev/null +++ b/spring-boot-modules/spring-boot-springdoc/src/main/java/com/baeldung/swaggerresponseapi/model/Product.java @@ -0,0 +1,28 @@ +package com.baeldung.swaggerresponseapi.model; + +public class Product { + String code; + String name; + + public Product(String code, String name) { + this.code = code; + this.name = name; + } + + public String getCode() { + return code; + } + + public void setCode(String code) { + this.code = code; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} + diff --git a/spring-boot-modules/spring-boot-springdoc/swaggerResponseAPI/src/main/java/com/baeldung/swaggerresponseapi/service/ProductService.java b/spring-boot-modules/spring-boot-springdoc/src/main/java/com/baeldung/swaggerresponseapi/service/ProductService.java similarity index 100% rename from spring-boot-modules/spring-boot-springdoc/swaggerResponseAPI/src/main/java/com/baeldung/swaggerresponseapi/service/ProductService.java rename to spring-boot-modules/spring-boot-springdoc/src/main/java/com/baeldung/swaggerresponseapi/service/ProductService.java diff --git a/spring-boot-modules/spring-boot-springdoc/swaggerResponseAPI/.gitignore b/spring-boot-modules/spring-boot-springdoc/swaggerResponseAPI/.gitignore deleted file mode 100644 index f60f3beecd..0000000000 --- a/spring-boot-modules/spring-boot-springdoc/swaggerResponseAPI/.gitignore +++ /dev/null @@ -1,33 +0,0 @@ -HELP.md -target/ -.mvn/wrapper/ -!**/src/main/**/target/ -!**/src/test/**/target/ -mvnv* - -### STS ### -.apt_generated -.classpath -.factorypath -.project -.settings -.springBeans -.sts4-cache - -### IntelliJ IDEA ### -.idea -*.iws -*.iml -*.ipr -### NetBeans ### -/nbproject/private/ -/nbbuild/ -/dist/ -/nbdist/ -/.nb-gradle/ -build/ -!**/src/main/**/build/ -!**/src/test/**/build/ - -### VS Code ### -.vscode/ diff --git a/spring-boot-modules/spring-boot-springdoc/swaggerResponseAPI/pom.xml b/spring-boot-modules/spring-boot-springdoc/swaggerResponseAPI/pom.xml deleted file mode 100644 index c168248df2..0000000000 --- a/spring-boot-modules/spring-boot-springdoc/swaggerResponseAPI/pom.xml +++ /dev/null @@ -1,70 +0,0 @@ - - - 4.0.0 - - org.springframework.boot - spring-boot-starter-parent - 2.6.3 - - - com.baeldung - swaggerResponseAPI - 0.0.1-SNAPSHOT - swaggerResponseAPI - swaggerResponseAPI - - 11 - - - - - org.springframework.boot - spring-boot-starter-web - - - org.springframework.boot - spring-boot-starter-test - test - - - org.projectlombok - lombok - true - - - org.springdoc - springdoc-openapi-ui - 1.6.6 - - - junit - junit - 4.13.2 - test - - - com.fasterxml.jackson.core - jackson-databind - 2.13.0 - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - org.projectlombok - lombok - - - - - - - - diff --git a/spring-boot-modules/spring-boot-springdoc/swaggerResponseAPI/src/main/java/com/baeldung/swaggerresponseapi/model/Product.java b/spring-boot-modules/spring-boot-springdoc/swaggerResponseAPI/src/main/java/com/baeldung/swaggerresponseapi/model/Product.java deleted file mode 100644 index 0a100582fc..0000000000 --- a/spring-boot-modules/spring-boot-springdoc/swaggerResponseAPI/src/main/java/com/baeldung/swaggerresponseapi/model/Product.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.baeldung.swaggerresponseapi.model; - -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; - -@Getter -@Setter -@AllArgsConstructor -@NoArgsConstructor -public class Product { - String code; - String name; -} diff --git a/spring-boot-modules/spring-boot-springdoc/swaggerResponseAPI/src/main/resources/application.properties b/spring-boot-modules/spring-boot-springdoc/swaggerResponseAPI/src/main/resources/application.properties deleted file mode 100644 index 8b13789179..0000000000 --- a/spring-boot-modules/spring-boot-springdoc/swaggerResponseAPI/src/main/resources/application.properties +++ /dev/null @@ -1 +0,0 @@ - diff --git a/spring-boot-modules/spring-boot-springdoc/swaggerResponseAPI/src/test/java/com/baeldung/swaggerresponseapi/ProductIntegrationTest.java b/spring-boot-modules/spring-boot-springdoc/swaggerResponseAPI/src/test/java/com/baeldung/swaggerresponseapi/ProductIntegrationTest.java deleted file mode 100644 index ef6a8953e2..0000000000 --- a/spring-boot-modules/spring-boot-springdoc/swaggerResponseAPI/src/test/java/com/baeldung/swaggerresponseapi/ProductIntegrationTest.java +++ /dev/null @@ -1,76 +0,0 @@ -package com.baeldung.swaggerresponseapi; - -import com.baeldung.swaggerresponseapi.controller.ProductController; -import com.baeldung.swaggerresponseapi.model.Product; -import com.baeldung.swaggerresponseapi.service.ProductService; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.http.MediaType; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.test.web.servlet.MockMvc; -import org.springframework.test.web.servlet.result.MockMvcResultMatchers; - -import java.util.Arrays; - -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.reset; -import static org.hamcrest.CoreMatchers.is; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; -import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - -@RunWith(SpringRunner.class) -@WebMvcTest(ProductController.class) -public class ProductIntegrationTest { - - @Autowired - MockMvc mock; - - @MockBean - private ProductService productService; - - @Test - public void givenProduct_whenAddNewProduct_thenReturnValidStatusCode() throws Exception { - Product product = new Product("1001", "Milk"); - given(productService.addProducts(any(Product.class))).willReturn(product); - - mock.perform(post("/create").contentType(MediaType.APPLICATION_JSON) - .content(toJsonString(product))) - .andDo(print()) - .andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value("1001")); - - reset(productService); - } - - @Test - public void givenProductsList_whenGetAllProducts_thenReturnValidProducts() throws Exception { - Product product1 = new Product("1001", "Milk"); - Product product2 = new Product("2002", "Butter"); - - given(productService.getProductsList()).willReturn(Arrays.asList(product1, product2)); - - mock.perform(get("/products").contentType(MediaType.APPLICATION_JSON)) - .andExpect(status().isOk()) - .andDo(print()) - .andExpect(jsonPath("$[0].code", is(product1.getCode()))) - .andExpect(jsonPath("$[1].name", is(product2.getName()))); - - reset(productService); - } - - public String toJsonString(Product product) throws JsonProcessingException { - ObjectMapper om = new ObjectMapper(); - String json = om.writeValueAsString(product); - return json; - } -} diff --git a/spring-boot-modules/spring-boot-springdoc/swaggerResponseAPI/src/test/java/com/baeldung/swaggerresponseapi/SwaggerResponseApiApplicationTests.java b/spring-boot-modules/spring-boot-springdoc/swaggerResponseAPI/src/test/java/com/baeldung/swaggerresponseapi/SwaggerResponseApiApplicationTests.java deleted file mode 100644 index 9e8c6ee0fa..0000000000 --- a/spring-boot-modules/spring-boot-springdoc/swaggerResponseAPI/src/test/java/com/baeldung/swaggerresponseapi/SwaggerResponseApiApplicationTests.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.baeldung.swaggerresponseapi; - -import org.junit.jupiter.api.Test; -import org.springframework.boot.test.context.SpringBootTest; - -@SpringBootTest -class SwaggerResponseApiApplicationTests { - - @Test - void contextLoads() { - } - -} From bc543e9c79f33db2a671a2555fede3dd842ebe38 Mon Sep 17 00:00:00 2001 From: sanitaso Date: Tue, 8 Mar 2022 15:13:42 +0100 Subject: [PATCH 04/12] remove dir --- .../SwaggerResponseApiApplication.java | 13 ------- .../controller/ProductController.java | 38 ------------------- .../swaggerresponseapi/model/Product.java | 28 -------------- .../service/ProductService.java | 21 ---------- 4 files changed, 100 deletions(-) delete mode 100644 spring-boot-modules/spring-boot-springdoc/src/main/java/com/baeldung/swaggerresponseapi/SwaggerResponseApiApplication.java delete mode 100644 spring-boot-modules/spring-boot-springdoc/src/main/java/com/baeldung/swaggerresponseapi/controller/ProductController.java delete mode 100644 spring-boot-modules/spring-boot-springdoc/src/main/java/com/baeldung/swaggerresponseapi/model/Product.java delete mode 100644 spring-boot-modules/spring-boot-springdoc/src/main/java/com/baeldung/swaggerresponseapi/service/ProductService.java diff --git a/spring-boot-modules/spring-boot-springdoc/src/main/java/com/baeldung/swaggerresponseapi/SwaggerResponseApiApplication.java b/spring-boot-modules/spring-boot-springdoc/src/main/java/com/baeldung/swaggerresponseapi/SwaggerResponseApiApplication.java deleted file mode 100644 index 913544b459..0000000000 --- a/spring-boot-modules/spring-boot-springdoc/src/main/java/com/baeldung/swaggerresponseapi/SwaggerResponseApiApplication.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.baeldung.swaggerresponseapi; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class SwaggerResponseApiApplication { - - public static void main(String[] args) { - SpringApplication.run(SwaggerResponseApiApplication.class, args); - } - -} diff --git a/spring-boot-modules/spring-boot-springdoc/src/main/java/com/baeldung/swaggerresponseapi/controller/ProductController.java b/spring-boot-modules/spring-boot-springdoc/src/main/java/com/baeldung/swaggerresponseapi/controller/ProductController.java deleted file mode 100644 index 364a7e8a66..0000000000 --- a/spring-boot-modules/spring-boot-springdoc/src/main/java/com/baeldung/swaggerresponseapi/controller/ProductController.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.baeldung.swaggerresponseapi.controller; - -import com.baeldung.swaggerresponseapi.model.Product; -import com.baeldung.swaggerresponseapi.service.ProductService; - -import io.swagger.v3.oas.annotations.media.ArraySchema; -import io.swagger.v3.oas.annotations.media.Content; -import io.swagger.v3.oas.annotations.media.Schema; -import io.swagger.v3.oas.annotations.responses.ApiResponse; -import io.swagger.v3.oas.annotations.responses.ApiResponses; - -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RestController; - -import java.util.List; - -@RestController -public class ProductController { - private final ProductService productService; - - public ProductController(ProductService productService) { - this.productService = productService; - } - - @PostMapping("/create") - public Product addProduct(@RequestBody Product product) { - return productService.addProducts(product); - } - - @ApiResponses(value = { @ApiResponse(content = { @Content(mediaType = "application/json", - array = @ArraySchema(schema = @Schema(implementation = Product.class))) }) }) - @GetMapping("/products") - public List getProductsList() { - return productService.getProductsList(); - } -} diff --git a/spring-boot-modules/spring-boot-springdoc/src/main/java/com/baeldung/swaggerresponseapi/model/Product.java b/spring-boot-modules/spring-boot-springdoc/src/main/java/com/baeldung/swaggerresponseapi/model/Product.java deleted file mode 100644 index 036ecbc853..0000000000 --- a/spring-boot-modules/spring-boot-springdoc/src/main/java/com/baeldung/swaggerresponseapi/model/Product.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.baeldung.swaggerresponseapi.model; - -public class Product { - String code; - String name; - - public Product(String code, String name) { - this.code = code; - this.name = name; - } - - public String getCode() { - return code; - } - - public void setCode(String code) { - this.code = code; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } -} - diff --git a/spring-boot-modules/spring-boot-springdoc/src/main/java/com/baeldung/swaggerresponseapi/service/ProductService.java b/spring-boot-modules/spring-boot-springdoc/src/main/java/com/baeldung/swaggerresponseapi/service/ProductService.java deleted file mode 100644 index 5e7533d6f4..0000000000 --- a/spring-boot-modules/spring-boot-springdoc/src/main/java/com/baeldung/swaggerresponseapi/service/ProductService.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.baeldung.swaggerresponseapi.service; - -import com.baeldung.swaggerresponseapi.model.Product; -import org.springframework.stereotype.Service; - -import java.util.ArrayList; -import java.util.List; - -@Service -public class ProductService { - List productsList = new ArrayList<>(); - - public Product addProducts(Product product) { - productsList.add(product); - return product; - } - - public List getProductsList() { - return productsList; - } -} From e3966f2efde01da3696cb110aefaae9c2e75becd Mon Sep 17 00:00:00 2001 From: sanitaso Date: Tue, 8 Mar 2022 15:15:11 +0100 Subject: [PATCH 05/12] add dir --- .../SwaggerResponseApiApplication.java | 13 +++++++ .../controller/ProductController.java | 38 +++++++++++++++++++ .../swaggerresponseapi/model/Product.java | 28 ++++++++++++++ .../service/ProductService.java | 21 ++++++++++ 4 files changed, 100 insertions(+) create mode 100644 spring-boot-modules/spring-boot-springdoc/src/main/java/com/baeldung/swaggerresponseapi/SwaggerResponseApiApplication.java create mode 100644 spring-boot-modules/spring-boot-springdoc/src/main/java/com/baeldung/swaggerresponseapi/controller/ProductController.java create mode 100644 spring-boot-modules/spring-boot-springdoc/src/main/java/com/baeldung/swaggerresponseapi/model/Product.java create mode 100644 spring-boot-modules/spring-boot-springdoc/src/main/java/com/baeldung/swaggerresponseapi/service/ProductService.java diff --git a/spring-boot-modules/spring-boot-springdoc/src/main/java/com/baeldung/swaggerresponseapi/SwaggerResponseApiApplication.java b/spring-boot-modules/spring-boot-springdoc/src/main/java/com/baeldung/swaggerresponseapi/SwaggerResponseApiApplication.java new file mode 100644 index 0000000000..913544b459 --- /dev/null +++ b/spring-boot-modules/spring-boot-springdoc/src/main/java/com/baeldung/swaggerresponseapi/SwaggerResponseApiApplication.java @@ -0,0 +1,13 @@ +package com.baeldung.swaggerresponseapi; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SwaggerResponseApiApplication { + + public static void main(String[] args) { + SpringApplication.run(SwaggerResponseApiApplication.class, args); + } + +} diff --git a/spring-boot-modules/spring-boot-springdoc/src/main/java/com/baeldung/swaggerresponseapi/controller/ProductController.java b/spring-boot-modules/spring-boot-springdoc/src/main/java/com/baeldung/swaggerresponseapi/controller/ProductController.java new file mode 100644 index 0000000000..364a7e8a66 --- /dev/null +++ b/spring-boot-modules/spring-boot-springdoc/src/main/java/com/baeldung/swaggerresponseapi/controller/ProductController.java @@ -0,0 +1,38 @@ +package com.baeldung.swaggerresponseapi.controller; + +import com.baeldung.swaggerresponseapi.model.Product; +import com.baeldung.swaggerresponseapi.service.ProductService; + +import io.swagger.v3.oas.annotations.media.ArraySchema; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +@RestController +public class ProductController { + private final ProductService productService; + + public ProductController(ProductService productService) { + this.productService = productService; + } + + @PostMapping("/create") + public Product addProduct(@RequestBody Product product) { + return productService.addProducts(product); + } + + @ApiResponses(value = { @ApiResponse(content = { @Content(mediaType = "application/json", + array = @ArraySchema(schema = @Schema(implementation = Product.class))) }) }) + @GetMapping("/products") + public List getProductsList() { + return productService.getProductsList(); + } +} diff --git a/spring-boot-modules/spring-boot-springdoc/src/main/java/com/baeldung/swaggerresponseapi/model/Product.java b/spring-boot-modules/spring-boot-springdoc/src/main/java/com/baeldung/swaggerresponseapi/model/Product.java new file mode 100644 index 0000000000..036ecbc853 --- /dev/null +++ b/spring-boot-modules/spring-boot-springdoc/src/main/java/com/baeldung/swaggerresponseapi/model/Product.java @@ -0,0 +1,28 @@ +package com.baeldung.swaggerresponseapi.model; + +public class Product { + String code; + String name; + + public Product(String code, String name) { + this.code = code; + this.name = name; + } + + public String getCode() { + return code; + } + + public void setCode(String code) { + this.code = code; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} + diff --git a/spring-boot-modules/spring-boot-springdoc/src/main/java/com/baeldung/swaggerresponseapi/service/ProductService.java b/spring-boot-modules/spring-boot-springdoc/src/main/java/com/baeldung/swaggerresponseapi/service/ProductService.java new file mode 100644 index 0000000000..5e7533d6f4 --- /dev/null +++ b/spring-boot-modules/spring-boot-springdoc/src/main/java/com/baeldung/swaggerresponseapi/service/ProductService.java @@ -0,0 +1,21 @@ +package com.baeldung.swaggerresponseapi.service; + +import com.baeldung.swaggerresponseapi.model.Product; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.List; + +@Service +public class ProductService { + List productsList = new ArrayList<>(); + + public Product addProducts(Product product) { + productsList.add(product); + return product; + } + + public List getProductsList() { + return productsList; + } +} From 612dc0be7c8c8a1ba46c565a8ef114f151ed74d3 Mon Sep 17 00:00:00 2001 From: Gaetano Piazzolla Date: Sat, 12 Mar 2022 19:21:34 +0100 Subject: [PATCH 06/12] BAEL-5358 - Case Insensitive Sorting in MongoDB (#11815) * [BAEL-5358] - MongoDB Case Insensitive Ordering. * [BAEL-5358] - removed comment, indent * [BAEL-5358] - using junit5 and testcontainers * [BAEL-5358] - fixed issues for PR * [BAEL-5358] - removed method-> inline --- persistence-modules/java-mongodb/pom.xml | 12 ++ .../CaseInsensitiveOrderingLiveTest.java | 108 ++++++++++++++++++ 2 files changed, 120 insertions(+) create mode 100644 persistence-modules/java-mongodb/src/test/java/com/baeldung/ordering/caseinsensitive/CaseInsensitiveOrderingLiveTest.java diff --git a/persistence-modules/java-mongodb/pom.xml b/persistence-modules/java-mongodb/pom.xml index 03229e72bd..88f0d18a5b 100644 --- a/persistence-modules/java-mongodb/pom.xml +++ b/persistence-modules/java-mongodb/pom.xml @@ -30,6 +30,18 @@ core ${morphia.version} + + org.testcontainers + mongodb + 1.16.3 + test + + + org.testcontainers + junit-jupiter + 1.16.3 + test + diff --git a/persistence-modules/java-mongodb/src/test/java/com/baeldung/ordering/caseinsensitive/CaseInsensitiveOrderingLiveTest.java b/persistence-modules/java-mongodb/src/test/java/com/baeldung/ordering/caseinsensitive/CaseInsensitiveOrderingLiveTest.java new file mode 100644 index 0000000000..ec2c332018 --- /dev/null +++ b/persistence-modules/java-mongodb/src/test/java/com/baeldung/ordering/caseinsensitive/CaseInsensitiveOrderingLiveTest.java @@ -0,0 +1,108 @@ +package com.baeldung.ordering.caseinsensitive; + +import com.mongodb.MongoClient; +import com.mongodb.client.*; +import com.mongodb.client.model.Collation; +import com.mongodb.client.model.Projections; +import com.mongodb.client.model.Sorts; +import org.bson.Document; +import org.bson.conversions.Bson; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.testcontainers.containers.MongoDBContainer; +import org.testcontainers.junit.jupiter.Container; +import org.testcontainers.junit.jupiter.Testcontainers; +import org.testcontainers.utility.DockerImageName; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import static com.mongodb.client.model.Aggregates.project; +import static com.mongodb.client.model.Aggregates.sort; +import static com.mongodb.client.model.Sorts.ascending; +import static org.junit.Assert.assertEquals; + +@Testcontainers +class CaseInsensitiveOrderingLiveTest { + + private static MongoCollection userCollections; + + @Container + private static final MongoDBContainer mongoDBContainer = new MongoDBContainer(DockerImageName.parse("mongo:4.0.10")); + + @BeforeAll + private static void setup() { + + MongoClient mongoClient = new MongoClient(mongoDBContainer.getContainerIpAddress(), mongoDBContainer.getMappedPort(27017)); + MongoDatabase database = mongoClient.getDatabase("test"); + userCollections = database.getCollection("users"); + + List list = new ArrayList<>(); + list.add(Document.parse("{'name': 'ben', surname: 'ThisField' }")); + list.add(Document.parse("{'name': 'aen', surname: 'Does' }")); + list.add(Document.parse("{'name': 'Ben', surname: 'Not' }")); + list.add(Document.parse("{'name': 'cen', surname: 'Matter' }")); + list.add(Document.parse("{'name': 'Aen', surname: 'Really' }")); + list.add(Document.parse("{'name': 'Cen', surname: 'TrustMe' }")); + + userCollections.insertMany(list); + } + + @Test + void givenMongoCollection_whenUsingFindWithSort_caseIsConsideredByDefault() { + FindIterable nameDoc = userCollections.find().sort(ascending("name")); + MongoCursor cursor = nameDoc.cursor(); + + List expectedNamesOrdering = Arrays.asList("Aen", "Ben", "Cen", "aen", "ben", "cen"); + List actualNamesOrdering = new ArrayList<>(); + while (cursor.hasNext()) { + Document document = cursor.next(); + actualNamesOrdering.add(document.get("name").toString()); + } + + assertEquals(expectedNamesOrdering, actualNamesOrdering); + } + + @Test + void givenMongoCollection_whenUsingFindWithSortAndCollation_caseIsNotConsidered() { + FindIterable nameDoc = userCollections.find().sort(ascending("name")) + .collation(Collation.builder().locale("en").build()); + MongoCursor cursor = nameDoc.cursor(); + List expectedNamesOrdering = Arrays.asList("aen", "Aen", "ben", "Ben", "cen", "Cen"); + List actualNamesOrdering = new ArrayList<>(); + while (cursor.hasNext()) { + Document document = cursor.next(); + actualNamesOrdering.add(document.get("name").toString()); + } + + assertEquals(expectedNamesOrdering, actualNamesOrdering); + + } + + @Test + void givenMongoCollection_whenUsingFindWithSortAndAggregate_caseIsNotConsidered() { + + Bson projectBson = project( + Projections.fields( + Projections.include("name", "surname"), + Projections.computed("lowerName", Projections.computed("$toLower", "$name")))); + + AggregateIterable nameDoc = userCollections.aggregate( + Arrays.asList(projectBson, + sort(Sorts.ascending("lowerName")))); + + MongoCursor cursor = nameDoc.cursor(); + + List expectedNamesOrdering = Arrays.asList("aen", "Aen", "ben", "Ben", "cen", "Cen"); + List actualNamesOrdering = new ArrayList<>(); + while (cursor.hasNext()) { + Document document = cursor.next(); + actualNamesOrdering.add(document.get("name").toString()); + } + + assertEquals(expectedNamesOrdering, actualNamesOrdering); + } + + +} From d30c353d35339d74b9b883045e21728435368266 Mon Sep 17 00:00:00 2001 From: Kai Yuan Date: Sat, 12 Mar 2022 20:09:18 +0100 Subject: [PATCH 07/12] pretty-print xml in java (#11899) * pretty-print xml in java * simplified pom.xml --- pom.xml | 1 + xml-2/.gitignore | 1 + xml-2/README.md | 5 + xml-2/pom.xml | 50 ++++++++++ .../xml/prettyprint/XmlPrettyPrinter.java | 91 +++++++++++++++++++ xml-2/src/main/resources/logback.xml | 13 +++ xml-2/src/main/resources/xml/emails.xml | 4 + xml-2/src/main/resources/xml/prettyprint.xsl | 11 +++ 8 files changed, 176 insertions(+) create mode 100644 xml-2/.gitignore create mode 100644 xml-2/README.md create mode 100644 xml-2/pom.xml create mode 100644 xml-2/src/main/java/com/baeldung/xml/prettyprint/XmlPrettyPrinter.java create mode 100644 xml-2/src/main/resources/logback.xml create mode 100644 xml-2/src/main/resources/xml/emails.xml create mode 100644 xml-2/src/main/resources/xml/prettyprint.xsl diff --git a/pom.xml b/pom.xml index a6202230d4..daaf9db6d2 100644 --- a/pom.xml +++ b/pom.xml @@ -1206,6 +1206,7 @@ wicket wildfly xml + xml-2 xstream diff --git a/xml-2/.gitignore b/xml-2/.gitignore new file mode 100644 index 0000000000..68b918851c --- /dev/null +++ b/xml-2/.gitignore @@ -0,0 +1 @@ +xml/.idea diff --git a/xml-2/README.md b/xml-2/README.md new file mode 100644 index 0000000000..e3c6ed6443 --- /dev/null +++ b/xml-2/README.md @@ -0,0 +1,5 @@ +## XML + +This module contains articles about eXtensible Markup Language (XML) + +### Relevant Articles: \ No newline at end of file diff --git a/xml-2/pom.xml b/xml-2/pom.xml new file mode 100644 index 0000000000..025ad682ad --- /dev/null +++ b/xml-2/pom.xml @@ -0,0 +1,50 @@ + + + 4.0.0 + xml-2 + 0.1-SNAPSHOT + xml-2 + + + com.baeldung + parent-modules + 1.0.0-SNAPSHOT + + + + + + org.dom4j + dom4j + ${dom4j.version} + + + + + xml-2 + + + src/main/resources + true + + + + + maven-compiler-plugin + ${maven-compiler-plugin.version} + + + org.apache.maven.plugins + maven-surefire-plugin + + + + + + + 2.1.3 + + + \ No newline at end of file diff --git a/xml-2/src/main/java/com/baeldung/xml/prettyprint/XmlPrettyPrinter.java b/xml-2/src/main/java/com/baeldung/xml/prettyprint/XmlPrettyPrinter.java new file mode 100644 index 0000000000..85fd751325 --- /dev/null +++ b/xml-2/src/main/java/com/baeldung/xml/prettyprint/XmlPrettyPrinter.java @@ -0,0 +1,91 @@ +package com.baeldung.xml.prettyprint; + +import org.dom4j.DocumentHelper; +import org.dom4j.io.OutputFormat; +import org.dom4j.io.XMLWriter; +import org.w3c.dom.Document; +import org.xml.sax.InputSource; + +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.transform.OutputKeys; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; +import javax.xml.transform.stream.StreamSource; +import java.io.*; + +public class XmlPrettyPrinter { + + public static String prettyPrintByTransformer(String xmlString, int indent, boolean ignoreDeclaration) { + + try { + final InputSource src = new InputSource(new StringReader(xmlString)); + final Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(src); + + TransformerFactory transformerFactory = TransformerFactory.newInstance(); + transformerFactory.setAttribute("indent-number", indent); + Transformer transformer = transformerFactory.newTransformer(new StreamSource(new StringReader(readPrettyPrintXslt()))); + // Using the default transformer will create empty lines in Java9+ +// Transformer transformer = transformerFactory.newTransformer(); + transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); + transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, ignoreDeclaration ? "yes" : "no"); + transformer.setOutputProperty(OutputKeys.INDENT, "yes"); + // Alternatively, we can set indent-size on the transformer object + // transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", String.valueOf(indent)); + Writer out = new StringWriter(); + transformer.transform(new DOMSource(document), new StreamResult(out)); + return out.toString(); + } catch (Exception e) { + throw new RuntimeException("Error occurs when pretty-printing xml:\n" + xmlString, e); + } + } + + + public static String prettyPrintByDom4j(String xmlString, int indent, boolean skipDeclaration) { + try { + final OutputFormat format = OutputFormat.createPrettyPrint(); + format.setEncoding("UTF-8"); + format.setIndentSize(indent); + format.setSuppressDeclaration(skipDeclaration); + + final org.dom4j.Document document = DocumentHelper.parseText(xmlString); + final StringWriter sw = new StringWriter(); + final XMLWriter writer = new XMLWriter(sw, format); + writer.write(document); + return sw.toString(); + } catch (Exception e) { + throw new RuntimeException("Error occurs when pretty-printing xml:\n" + xmlString, e); + } + } + + public static void main(String[] args) throws IOException { + InputStream inputStream = XmlPrettyPrinter.class.getResourceAsStream("/xml/emails.xml"); + String xmlString = readFromInputStream(inputStream); + System.out.println("Pretty printing by Transformer"); + System.out.println("============================================="); + System.out.println(prettyPrintByTransformer(xmlString, 2, true)); + System.out.println("============================================="); + System.out.println("Pretty printing by Dom4j"); + System.out.println("============================================="); + System.out.println(prettyPrintByDom4j(xmlString, 8, false)); + System.out.println("============================================="); + } + + + private static String readPrettyPrintXslt() throws IOException { + InputStream inputStream = XmlPrettyPrinter.class.getResourceAsStream("/xml/prettyprint.xsl"); + return readFromInputStream(inputStream); + } + + private static String readFromInputStream(InputStream inputStream) throws IOException { + StringBuilder resultStringBuilder = new StringBuilder(); + try (BufferedReader br = new BufferedReader(new InputStreamReader(inputStream))) { + String line; + while ((line = br.readLine()) != null) { + resultStringBuilder.append(line).append("\n"); + } + } + return resultStringBuilder.toString(); + } +} diff --git a/xml-2/src/main/resources/logback.xml b/xml-2/src/main/resources/logback.xml new file mode 100644 index 0000000000..7d900d8ea8 --- /dev/null +++ b/xml-2/src/main/resources/logback.xml @@ -0,0 +1,13 @@ + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + + \ No newline at end of file diff --git a/xml-2/src/main/resources/xml/emails.xml b/xml-2/src/main/resources/xml/emails.xml new file mode 100644 index 0000000000..03338a28fc --- /dev/null +++ b/xml-2/src/main/resources/xml/emails.xml @@ -0,0 +1,4 @@ + Kai Amanda +I am flying to you +Jerry Tom Hey Tom, catch me if you can! + \ No newline at end of file diff --git a/xml-2/src/main/resources/xml/prettyprint.xsl b/xml-2/src/main/resources/xml/prettyprint.xsl new file mode 100644 index 0000000000..3941269f40 --- /dev/null +++ b/xml-2/src/main/resources/xml/prettyprint.xsl @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file From b8176a265a2bf1bd7f32ee34a3059347409d86d0 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Sun, 13 Mar 2022 14:48:44 +0530 Subject: [PATCH 08/12] JAVA-10138 - Fix formatting of POMs --- apache-olingo/pom.xml | 2 +- .../core-java-9-new-features/pom.xml | 44 +++++----- .../core-java-concurrency-basic-3/pom.xml | 2 +- .../core-java-date-operations-1/pom.xml | 1 - core-java-modules/core-java-jar/pom.xml | 2 +- core-java-modules/core-java-jvm/pom.xml | 15 ++-- .../core-java-serialization/pom.xml | 1 - .../core-java-string-algorithms-3/pom.xml | 1 + core-java-modules/core-java/pom.xml | 1 - core-java-modules/pom.xml | 2 +- ddd-modules/infrastructure/pom.xml | 4 +- ddd-modules/mainapp/pom.xml | 3 +- ddd-modules/ordercontext/pom.xml | 4 +- ddd-modules/pom.xml | 8 +- ddd-modules/sharedkernel/pom.xml | 4 +- ddd-modules/shippingcontext/pom.xml | 4 +- geotools/pom.xml | 16 ++-- graphql/graphql-dgs/pom.xml | 6 +- httpclient-2/pom.xml | 5 +- java-collections-maps-3/pom.xml | 1 - javax-servlets-2/pom.xml | 3 +- javaxval/pom.xml | 38 ++------- jta/pom.xml | 2 +- ksqldb/pom.xml | 1 - libraries-concurrency/pom.xml | 6 +- lombok-2/pom.xml | 2 +- lombok/pom.xml | 15 +--- .../maven-classifier-example-consumer/pom.xml | 38 ++++----- .../maven-classifier-example-provider/pom.xml | 81 ++++++++++--------- maven-modules/maven-classifier/pom.xml | 7 +- maven-modules/maven-generate-war/pom.xml | 2 +- .../maven-simple/parent-project/core/pom.xml | 2 +- .../maven-simple/parent-project/pom.xml | 3 +- .../parent-project/service/pom.xml | 2 +- .../parent-project/webapp/pom.xml | 2 +- metrics/pom.xml | 2 +- netty/pom.xml | 11 ++- patterns/enterprise-patterns/pom.xml | 40 ++++----- .../hibernate-mapping-2/pom.xml | 32 ++++---- persistence-modules/java-cassandra/pom.xml | 2 +- persistence-modules/spring-data-jdbc/pom.xml | 2 +- .../spring-data-jpa-query-3/pom.xml | 2 +- .../spring-hibernate-5/pom.xml | 32 ++++---- .../pom.xml | 2 +- spring-5-data-reactive/pom.xml | 2 +- spring-5-reactive-3/pom.xml | 1 + spring-activiti/pom.xml | 2 +- .../spring-boot-multiple-datasources/pom.xml | 6 +- .../spring-boot-swagger-keycloak/pom.xml | 2 +- .../spring-boot-swagger/pom.xml | 2 +- .../zookeeper-config/pom.xml | 2 +- .../pom.xml | 12 +-- spring-cloud/spring-cloud-eureka/pom.xml | 16 ++-- spring-cloud/spring-cloud-functions/pom.xml | 2 +- spring-cloud/spring-cloud-gateway/pom.xml | 43 +++++----- spring-cloud/spring-cloud-kubernetes/pom.xml | 18 ++--- .../spring-cloud-load-balancer/pom.xml | 6 +- .../spring-cloud-loadbalancer-client/pom.xml | 36 +++++---- .../spring-cloud-loadbalancer-server/pom.xml | 15 ++-- .../eureka-client/pom.xml | 2 +- .../eureka-server/pom.xml | 2 +- .../zuul-server/pom.xml | 4 +- .../spring-zuul-rate-limiting/pom.xml | 2 +- spring-ejb/ejb-beans/pom.xml | 1 - spring-reactive/pom.xml | 7 +- .../spring-5-security-oauth/pom.xml | 7 +- .../spring-security-legacy-oidc/pom.xml | 6 +- .../spring-security-web-boot-1/pom.xml | 1 - .../spring-security-web-boot-3/pom.xml | 5 +- spring-web-modules/pom.xml | 2 +- .../spring-mvc-basics-5/pom.xml | 2 +- testing-modules/cucumber/pom.xml | 1 - testing-modules/testng_command_line/pom.xml | 7 +- 73 files changed, 308 insertions(+), 361 deletions(-) diff --git a/apache-olingo/pom.xml b/apache-olingo/pom.xml index 5de0dfd511..25aab0ec97 100644 --- a/apache-olingo/pom.xml +++ b/apache-olingo/pom.xml @@ -83,4 +83,4 @@ 2.0.11 - + \ No newline at end of file diff --git a/core-java-modules/core-java-9-new-features/pom.xml b/core-java-modules/core-java-9-new-features/pom.xml index ce90a0f04a..78ffaff010 100644 --- a/core-java-modules/core-java-9-new-features/pom.xml +++ b/core-java-modules/core-java-9-new-features/pom.xml @@ -34,6 +34,28 @@ + + core-java-9-new-features + + + org.apache.maven.plugins + maven-compiler-plugin + ${maven-compiler-plugin.version} + + ${maven.compiler.source} + ${maven.compiler.target} + + + + + + + + apache.snapshots + https://repository.apache.org/snapshots/ + + + incubator-features @@ -126,28 +148,6 @@ - - core-java-9-new-features - - - org.apache.maven.plugins - maven-compiler-plugin - ${maven-compiler-plugin.version} - - ${maven.compiler.source} - ${maven.compiler.target} - - - - - - - - apache.snapshots - https://repository.apache.org/snapshots/ - - - 3.0.0 4.0.2 diff --git a/core-java-modules/core-java-concurrency-basic-3/pom.xml b/core-java-modules/core-java-concurrency-basic-3/pom.xml index 20615e3250..7771d1200c 100644 --- a/core-java-modules/core-java-concurrency-basic-3/pom.xml +++ b/core-java-modules/core-java-concurrency-basic-3/pom.xml @@ -24,4 +24,4 @@ - + \ No newline at end of file diff --git a/core-java-modules/core-java-date-operations-1/pom.xml b/core-java-modules/core-java-date-operations-1/pom.xml index ea9f94fa56..c5d46723d8 100644 --- a/core-java-modules/core-java-date-operations-1/pom.xml +++ b/core-java-modules/core-java-date-operations-1/pom.xml @@ -25,7 +25,6 @@ commons-lang3 ${commons-lang3.version} - com.darwinsys hirondelle-date4j diff --git a/core-java-modules/core-java-jar/pom.xml b/core-java-modules/core-java-jar/pom.xml index 714a370287..19da9b8a56 100644 --- a/core-java-modules/core-java-jar/pom.xml +++ b/core-java-modules/core-java-jar/pom.xml @@ -259,7 +259,7 @@ - + diff --git a/core-java-modules/core-java-jvm/pom.xml b/core-java-modules/core-java-jvm/pom.xml index e4c0f949c2..d26c72323f 100644 --- a/core-java-modules/core-java-jvm/pom.xml +++ b/core-java-modules/core-java-jvm/pom.xml @@ -64,13 +64,6 @@ - - 3.27.0-GA - 1.8.0 - 0.10 - 8.0.1 - 6.5.0 - @@ -181,4 +174,12 @@ + + 3.27.0-GA + 1.8.0 + 0.10 + 8.0.1 + 6.5.0 + + \ No newline at end of file diff --git a/core-java-modules/core-java-serialization/pom.xml b/core-java-modules/core-java-serialization/pom.xml index 315ed8cdad..c82ae9d1d6 100644 --- a/core-java-modules/core-java-serialization/pom.xml +++ b/core-java-modules/core-java-serialization/pom.xml @@ -64,7 +64,6 @@ true - org.apache.maven.plugins diff --git a/core-java-modules/core-java-string-algorithms-3/pom.xml b/core-java-modules/core-java-string-algorithms-3/pom.xml index dc8ad3851d..147ea22375 100644 --- a/core-java-modules/core-java-string-algorithms-3/pom.xml +++ b/core-java-modules/core-java-string-algorithms-3/pom.xml @@ -54,4 +54,5 @@ 1.7 3.12.0 + \ No newline at end of file diff --git a/core-java-modules/core-java/pom.xml b/core-java-modules/core-java/pom.xml index 188c6a6f63..bb19b525d0 100644 --- a/core-java-modules/core-java/pom.xml +++ b/core-java-modules/core-java/pom.xml @@ -69,7 +69,6 @@ true - org.apache.maven.plugins diff --git a/core-java-modules/pom.xml b/core-java-modules/pom.xml index 60319b4de4..2f684beea0 100644 --- a/core-java-modules/pom.xml +++ b/core-java-modules/pom.xml @@ -137,4 +137,4 @@ - + \ No newline at end of file diff --git a/ddd-modules/infrastructure/pom.xml b/ddd-modules/infrastructure/pom.xml index abf90935c3..232e5ff4b4 100644 --- a/ddd-modules/infrastructure/pom.xml +++ b/ddd-modules/infrastructure/pom.xml @@ -1,13 +1,11 @@ - 4.0.0 com.baeldung.dddmodules.infrastructure infrastructure 1.0 - jar diff --git a/ddd-modules/mainapp/pom.xml b/ddd-modules/mainapp/pom.xml index 6b913df979..a2d3b8f3ea 100644 --- a/ddd-modules/mainapp/pom.xml +++ b/ddd-modules/mainapp/pom.xml @@ -1,6 +1,5 @@ - 4.0.0 diff --git a/ddd-modules/ordercontext/pom.xml b/ddd-modules/ordercontext/pom.xml index 8dee3a5148..eaf44badd3 100644 --- a/ddd-modules/ordercontext/pom.xml +++ b/ddd-modules/ordercontext/pom.xml @@ -1,6 +1,5 @@ - 4.0.0 @@ -13,7 +12,6 @@ com.baeldung.dddmodules ddd-modules 1.0 - ../ diff --git a/ddd-modules/pom.xml b/ddd-modules/pom.xml index 134a9d0566..d2932ee515 100644 --- a/ddd-modules/pom.xml +++ b/ddd-modules/pom.xml @@ -1,6 +1,5 @@ - 4.0.0 @@ -14,7 +13,6 @@ com.baeldung parent-modules 1.0.0-SNAPSHOT - ../ @@ -70,10 +68,8 @@ 9 9 - 3.8.1 - 1.0 - + \ No newline at end of file diff --git a/ddd-modules/sharedkernel/pom.xml b/ddd-modules/sharedkernel/pom.xml index 1afddf1e22..3966e1c26e 100644 --- a/ddd-modules/sharedkernel/pom.xml +++ b/ddd-modules/sharedkernel/pom.xml @@ -1,6 +1,5 @@ - 4.0.0 @@ -13,7 +12,6 @@ com.baeldung.dddmodules ddd-modules 1.0 - ../ diff --git a/ddd-modules/shippingcontext/pom.xml b/ddd-modules/shippingcontext/pom.xml index 25b5882ef1..a6e6167b69 100644 --- a/ddd-modules/shippingcontext/pom.xml +++ b/ddd-modules/shippingcontext/pom.xml @@ -1,6 +1,5 @@ - 4.0.0 @@ -13,7 +12,6 @@ com.baeldung.dddmodules ddd-modules 1.0 - ../ diff --git a/geotools/pom.xml b/geotools/pom.xml index b9a6a7c91f..05cae922a4 100644 --- a/geotools/pom.xml +++ b/geotools/pom.xml @@ -15,6 +15,14 @@ 1.0.0-SNAPSHOT + + + osgeo-release + OSGeo Repository + https://repo.osgeo.org/repository/release/ + + + org.geotools @@ -33,14 +41,6 @@ - - - osgeo-release - OSGeo Repository - https://repo.osgeo.org/repository/release/ - - - 15.2 15.2 diff --git a/graphql/graphql-dgs/pom.xml b/graphql/graphql-dgs/pom.xml index 1dc3630276..6165ae839f 100644 --- a/graphql/graphql-dgs/pom.xml +++ b/graphql/graphql-dgs/pom.xml @@ -33,26 +33,22 @@ spring-boot-starter 2.6.2 - org.springframework.boot spring-boot-starter-test 2.6.2 test - com.netflix.graphql.dgs.codegen graphql-dgs-codegen-client-core 5.1.14 - org.springframework.boot spring-boot-starter-web 2.6.2 - com.netflix.graphql.dgs graphql-dgs-spring-boot-starter @@ -88,4 +84,4 @@ - + \ No newline at end of file diff --git a/httpclient-2/pom.xml b/httpclient-2/pom.xml index 85fc1d87e7..287ff27e35 100644 --- a/httpclient-2/pom.xml +++ b/httpclient-2/pom.xml @@ -1,6 +1,7 @@ - + 4.0.0 httpclient-2 0.1-SNAPSHOT diff --git a/java-collections-maps-3/pom.xml b/java-collections-maps-3/pom.xml index a54061404d..729b357b76 100644 --- a/java-collections-maps-3/pom.xml +++ b/java-collections-maps-3/pom.xml @@ -22,7 +22,6 @@ junit-jupiter-api 5.8.1 - org.springframework spring-core diff --git a/javax-servlets-2/pom.xml b/javax-servlets-2/pom.xml index 34c00c3d05..5d8310f2b2 100644 --- a/javax-servlets-2/pom.xml +++ b/javax-servlets-2/pom.xml @@ -57,4 +57,5 @@ 4.5.13 4.0.1 - + + \ No newline at end of file diff --git a/javaxval/pom.xml b/javaxval/pom.xml index 4131ddeb97..e6ecee6cfb 100644 --- a/javaxval/pom.xml +++ b/javaxval/pom.xml @@ -37,35 +37,13 @@ - + 6.0.13.Final @@ -77,4 +55,4 @@ 5.0.2.RELEASE - + \ No newline at end of file diff --git a/jta/pom.xml b/jta/pom.xml index e62c480c81..906d28a7ea 100644 --- a/jta/pom.xml +++ b/jta/pom.xml @@ -15,7 +15,7 @@ 0.0.1-SNAPSHOT ../parent-boot-2 - + diff --git a/ksqldb/pom.xml b/ksqldb/pom.xml index ee4906090f..e55398d635 100644 --- a/ksqldb/pom.xml +++ b/ksqldb/pom.xml @@ -11,7 +11,6 @@ com.baeldung parent-modules 1.0.0-SNAPSHOT - ../pom.xml diff --git a/libraries-concurrency/pom.xml b/libraries-concurrency/pom.xml index d8f48a1959..eb581ce3a0 100644 --- a/libraries-concurrency/pom.xml +++ b/libraries-concurrency/pom.xml @@ -1,7 +1,7 @@ + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 libraries-concurrency libraries-concurrency @@ -78,5 +78,5 @@ 0.8.0 - + \ No newline at end of file diff --git a/lombok-2/pom.xml b/lombok-2/pom.xml index 3c67e959a4..bde328444e 100644 --- a/lombok-2/pom.xml +++ b/lombok-2/pom.xml @@ -22,4 +22,4 @@ - + \ No newline at end of file diff --git a/lombok/pom.xml b/lombok/pom.xml index d4f89ab4f2..24a04783d1 100644 --- a/lombok/pom.xml +++ b/lombok/pom.xml @@ -62,18 +62,9 @@ false - + diff --git a/maven-modules/maven-classifier/maven-classifier-example-consumer/pom.xml b/maven-modules/maven-classifier/maven-classifier-example-consumer/pom.xml index cbf046ed5a..b280f21b4b 100644 --- a/maven-modules/maven-classifier/maven-classifier-example-consumer/pom.xml +++ b/maven-modules/maven-classifier/maven-classifier-example-consumer/pom.xml @@ -1,22 +1,16 @@ + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 + maven-classifier-example-consumer + maven-classifier com.baeldung 0.0.1-SNAPSHOT - 4.0.0 - - maven-classifier-example-consumer - - - 8 - 8 - - com.baeldung @@ -29,13 +23,14 @@ 0.0.1-SNAPSHOT arbitrary - - - - - - - + + + + + + + com.baeldung maven-classifier-example-provider @@ -50,4 +45,9 @@ - + + 8 + 8 + + + \ No newline at end of file diff --git a/maven-modules/maven-classifier/maven-classifier-example-provider/pom.xml b/maven-modules/maven-classifier/maven-classifier-example-provider/pom.xml index 12cb4fa1a2..111996c995 100644 --- a/maven-modules/maven-classifier/maven-classifier-example-provider/pom.xml +++ b/maven-modules/maven-classifier/maven-classifier-example-provider/pom.xml @@ -1,9 +1,10 @@ - + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 + maven-classifier-example-provider + 0.0.1-SNAPSHOT maven-classifier @@ -11,15 +12,6 @@ 0.0.1-SNAPSHOT - maven-classifier-example-provider - 0.0.1-SNAPSHOT - - - 8 - 8 - - - @@ -39,21 +31,22 @@ true - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + @@ -76,18 +69,19 @@ test-jar - - - - - - - - - - - - + + + + + + + + + + + + @@ -119,4 +113,11 @@ - + + + 8 + 8 + + + + \ No newline at end of file diff --git a/maven-modules/maven-classifier/pom.xml b/maven-modules/maven-classifier/pom.xml index 6b75f60893..ba5f248ff6 100644 --- a/maven-modules/maven-classifier/pom.xml +++ b/maven-modules/maven-classifier/pom.xml @@ -1,9 +1,8 @@ + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - maven-classifier pom 0.0.1-SNAPSHOT @@ -24,4 +23,4 @@ 8 - + \ No newline at end of file diff --git a/maven-modules/maven-generate-war/pom.xml b/maven-modules/maven-generate-war/pom.xml index b388cfdadd..51eb54846c 100644 --- a/maven-modules/maven-generate-war/pom.xml +++ b/maven-modules/maven-generate-war/pom.xml @@ -6,8 +6,8 @@ com.baeldung maven-generate-war 0.0.1-SNAPSHOT - war maven-generate-war + war Spring boot project to demonstrate war file generation diff --git a/maven-modules/maven-simple/parent-project/core/pom.xml b/maven-modules/maven-simple/parent-project/core/pom.xml index ec25c9ace5..963f8edf6c 100644 --- a/maven-modules/maven-simple/parent-project/core/pom.xml +++ b/maven-modules/maven-simple/parent-project/core/pom.xml @@ -13,4 +13,4 @@ 1.0-SNAPSHOT - + \ No newline at end of file diff --git a/maven-modules/maven-simple/parent-project/pom.xml b/maven-modules/maven-simple/parent-project/pom.xml index a68f8e63bc..0b8fbdffab 100644 --- a/maven-modules/maven-simple/parent-project/pom.xml +++ b/maven-modules/maven-simple/parent-project/pom.xml @@ -19,4 +19,5 @@ service webapp - + + \ No newline at end of file diff --git a/maven-modules/maven-simple/parent-project/service/pom.xml b/maven-modules/maven-simple/parent-project/service/pom.xml index 1953ec8638..04cb1151e1 100644 --- a/maven-modules/maven-simple/parent-project/service/pom.xml +++ b/maven-modules/maven-simple/parent-project/service/pom.xml @@ -13,4 +13,4 @@ 1.0-SNAPSHOT - + \ No newline at end of file diff --git a/maven-modules/maven-simple/parent-project/webapp/pom.xml b/maven-modules/maven-simple/parent-project/webapp/pom.xml index bd13c5aeb8..ece8a0dd11 100644 --- a/maven-modules/maven-simple/parent-project/webapp/pom.xml +++ b/maven-modules/maven-simple/parent-project/webapp/pom.xml @@ -13,4 +13,4 @@ 1.0-SNAPSHOT - + \ No newline at end of file diff --git a/metrics/pom.xml b/metrics/pom.xml index abdfb14dc6..37b10ef484 100644 --- a/metrics/pom.xml +++ b/metrics/pom.xml @@ -92,4 +92,4 @@ 1.1.0 - + \ No newline at end of file diff --git a/netty/pom.xml b/netty/pom.xml index 817b1f2e70..c235ec9f4a 100644 --- a/netty/pom.xml +++ b/netty/pom.xml @@ -1,6 +1,7 @@ - + 4.0.0 netty 0.0.1-SNAPSHOT @@ -11,20 +12,18 @@ parent-modules 1.0.0-SNAPSHOT - + io.netty netty-all ${netty.version} - - + org.conscrypt conscrypt-openjdk-uber ${conscrypt-openjdk-uber.version} - diff --git a/patterns/enterprise-patterns/pom.xml b/patterns/enterprise-patterns/pom.xml index 999b359170..2228cc9505 100644 --- a/patterns/enterprise-patterns/pom.xml +++ b/patterns/enterprise-patterns/pom.xml @@ -16,6 +16,25 @@ wire-tap + + + + org.apache.camel.springboot + camel-spring-boot-dependencies + ${camel.version} + pom + import + + + org.apache.logging.log4j + log4j-bom + ${log4j2.version} + import + pom + + + + org.apache.camel.springboot @@ -39,25 +58,6 @@ - - - - org.apache.camel.springboot - camel-spring-boot-dependencies - ${camel.version} - pom - import - - - org.apache.logging.log4j - log4j-bom - ${log4j2.version} - import - pom - - - - @@ -70,7 +70,7 @@ 3.7.4 2.2.2.RELEASE - 2.17.1 + 2.17.1 \ No newline at end of file diff --git a/persistence-modules/hibernate-mapping-2/pom.xml b/persistence-modules/hibernate-mapping-2/pom.xml index 10c07c95eb..47b00797bc 100644 --- a/persistence-modules/hibernate-mapping-2/pom.xml +++ b/persistence-modules/hibernate-mapping-2/pom.xml @@ -54,22 +54,22 @@ com.h2database h2 ${h2.version} - - - com.sun.xml.bind - jaxb-core - ${com.sun.xml.version} - - - javax.xml.bind - jaxb-api - ${javax.xml.bind.version} - - - com.sun.xml.bind - jaxb-impl - ${com.sun.xml.version} - + + + com.sun.xml.bind + jaxb-core + ${com.sun.xml.version} + + + javax.xml.bind + jaxb-api + ${javax.xml.bind.version} + + + com.sun.xml.bind + jaxb-impl + ${com.sun.xml.version} + diff --git a/persistence-modules/java-cassandra/pom.xml b/persistence-modules/java-cassandra/pom.xml index b0b98b040a..0dd148e528 100644 --- a/persistence-modules/java-cassandra/pom.xml +++ b/persistence-modules/java-cassandra/pom.xml @@ -77,4 +77,4 @@ 4.1.71.Final - + \ No newline at end of file diff --git a/persistence-modules/spring-data-jdbc/pom.xml b/persistence-modules/spring-data-jdbc/pom.xml index 168b171337..630fe141b3 100644 --- a/persistence-modules/spring-data-jdbc/pom.xml +++ b/persistence-modules/spring-data-jdbc/pom.xml @@ -36,4 +36,4 @@ - + \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-query-3/pom.xml b/persistence-modules/spring-data-jpa-query-3/pom.xml index 66a4486bc8..135d31aaba 100644 --- a/persistence-modules/spring-data-jpa-query-3/pom.xml +++ b/persistence-modules/spring-data-jpa-query-3/pom.xml @@ -29,4 +29,4 @@ - + \ No newline at end of file diff --git a/persistence-modules/spring-hibernate-5/pom.xml b/persistence-modules/spring-hibernate-5/pom.xml index ba18c5a221..3f5d00733d 100644 --- a/persistence-modules/spring-hibernate-5/pom.xml +++ b/persistence-modules/spring-hibernate-5/pom.xml @@ -107,22 +107,22 @@ com.h2database h2 ${h2.version} - - - com.sun.xml.bind - jaxb-core - ${com.sun.xml.version} - - - javax.xml.bind - jaxb-api - ${javax.xml.bind.version} - - - com.sun.xml.bind - jaxb-impl - ${com.sun.xml.version} - + + + com.sun.xml.bind + jaxb-core + ${com.sun.xml.version} + + + javax.xml.bind + jaxb-api + ${javax.xml.bind.version} + + + com.sun.xml.bind + jaxb-impl + ${com.sun.xml.version} + diff --git a/quarkus-jandex/hello-sender-application-properties/pom.xml b/quarkus-jandex/hello-sender-application-properties/pom.xml index f63bb9be81..6658123bee 100644 --- a/quarkus-jandex/hello-sender-application-properties/pom.xml +++ b/quarkus-jandex/hello-sender-application-properties/pom.xml @@ -23,4 +23,4 @@ - + \ No newline at end of file diff --git a/spring-5-data-reactive/pom.xml b/spring-5-data-reactive/pom.xml index 023eda856b..24971c0289 100644 --- a/spring-5-data-reactive/pom.xml +++ b/spring-5-data-reactive/pom.xml @@ -13,7 +13,7 @@ 0.0.1-SNAPSHOT ../parent-boot-2 - + diff --git a/spring-5-reactive-3/pom.xml b/spring-5-reactive-3/pom.xml index 89af34732f..fea72cc736 100644 --- a/spring-5-reactive-3/pom.xml +++ b/spring-5-reactive-3/pom.xml @@ -41,4 +41,5 @@ 1.0.1.RELEASE + \ No newline at end of file diff --git a/spring-activiti/pom.xml b/spring-activiti/pom.xml index 2ede13a152..898f88285b 100644 --- a/spring-activiti/pom.xml +++ b/spring-activiti/pom.xml @@ -16,7 +16,7 @@ 0.0.1-SNAPSHOT ../parent-boot-1 - + diff --git a/spring-boot-modules/spring-boot-multiple-datasources/pom.xml b/spring-boot-modules/spring-boot-multiple-datasources/pom.xml index d66095bc2c..9355de8a36 100644 --- a/spring-boot-modules/spring-boot-multiple-datasources/pom.xml +++ b/spring-boot-modules/spring-boot-multiple-datasources/pom.xml @@ -1,7 +1,7 @@ + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 spring-boot-multiple-datasources 0.1.0-SNAPSHOT @@ -55,4 +55,4 @@ 2.6.3 - + \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-swagger-keycloak/pom.xml b/spring-boot-modules/spring-boot-swagger-keycloak/pom.xml index a7f3e01014..de2c8c68c4 100644 --- a/spring-boot-modules/spring-boot-swagger-keycloak/pom.xml +++ b/spring-boot-modules/spring-boot-swagger-keycloak/pom.xml @@ -72,4 +72,4 @@ 2.17.1 - + \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-swagger/pom.xml b/spring-boot-modules/spring-boot-swagger/pom.xml index b6ed50534e..749442c225 100644 --- a/spring-boot-modules/spring-boot-swagger/pom.xml +++ b/spring-boot-modules/spring-boot-swagger/pom.xml @@ -84,4 +84,4 @@ 3.1.1 - + \ No newline at end of file diff --git a/spring-cloud/spring-cloud-archaius/zookeeper-config/pom.xml b/spring-cloud/spring-cloud-archaius/zookeeper-config/pom.xml index bdd75d0635..7700a2219d 100644 --- a/spring-cloud/spring-cloud-archaius/zookeeper-config/pom.xml +++ b/spring-cloud/spring-cloud-archaius/zookeeper-config/pom.xml @@ -45,7 +45,7 @@ 2.0.0.RELEASE 3.4.13 - 2.17.1 + 2.17.1 \ No newline at end of file diff --git a/spring-cloud/spring-cloud-eureka-self-preservation/pom.xml b/spring-cloud/spring-cloud-eureka-self-preservation/pom.xml index e22ad6b7c9..5000adc164 100644 --- a/spring-cloud/spring-cloud-eureka-self-preservation/pom.xml +++ b/spring-cloud/spring-cloud-eureka-self-preservation/pom.xml @@ -14,7 +14,12 @@ spring-cloud 1.0.0-SNAPSHOT - + + + spring-cloud-eureka-server + spring-cloud-eureka-client + + @@ -27,11 +32,6 @@ - - spring-cloud-eureka-server - spring-cloud-eureka-client - - org.springframework.boot diff --git a/spring-cloud/spring-cloud-eureka/pom.xml b/spring-cloud/spring-cloud-eureka/pom.xml index 795eab7d6e..63190f7f20 100644 --- a/spring-cloud/spring-cloud-eureka/pom.xml +++ b/spring-cloud/spring-cloud-eureka/pom.xml @@ -14,7 +14,14 @@ spring-cloud 1.0.0-SNAPSHOT - + + + spring-cloud-eureka-server + spring-cloud-eureka-client + spring-cloud-eureka-feign-client + spring-cloud-eureka-feign-client-integration-test + + @@ -27,13 +34,6 @@ - - spring-cloud-eureka-server - spring-cloud-eureka-client - spring-cloud-eureka-feign-client - spring-cloud-eureka-feign-client-integration-test - - org.springframework.boot diff --git a/spring-cloud/spring-cloud-functions/pom.xml b/spring-cloud/spring-cloud-functions/pom.xml index 3dc68e2824..d9f90c7a56 100644 --- a/spring-cloud/spring-cloud-functions/pom.xml +++ b/spring-cloud/spring-cloud-functions/pom.xml @@ -10,7 +10,7 @@ jar Demo project for Spring Cloud Function - + com.baeldung.spring.cloud spring-cloud 1.0.0-SNAPSHOT diff --git a/spring-cloud/spring-cloud-gateway/pom.xml b/spring-cloud/spring-cloud-gateway/pom.xml index a352bbd4e4..e8949cc039 100644 --- a/spring-cloud/spring-cloud-gateway/pom.xml +++ b/spring-cloud/spring-cloud-gateway/pom.xml @@ -83,31 +83,28 @@ org.springframework.boot spring-boot-devtools - org.springframework.boot spring-boot-starter-oauth2-resource-server - org.springframework.boot spring-boot-starter-oauth2-client - - - org.apache.maven.plugins - maven-compiler-plugin - 3.8.1 - - ${java.version} - ${java.version} - - + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + ${java.version} + ${java.version} + + org.springframework.boot spring-boot-maven-plugin @@ -123,15 +120,6 @@ - - - - 6.0.2.Final - 0.7.2 - 9.19 - - - quotes-application @@ -177,7 +165,6 @@ - gateway-url-rewrite @@ -192,6 +179,16 @@ - + + + + + + 6.0.2.Final + 0.7.2 + 9.19 + + + \ No newline at end of file diff --git a/spring-cloud/spring-cloud-kubernetes/pom.xml b/spring-cloud/spring-cloud-kubernetes/pom.xml index c41c500a1b..698bdce1e5 100644 --- a/spring-cloud/spring-cloud-kubernetes/pom.xml +++ b/spring-cloud/spring-cloud-kubernetes/pom.xml @@ -15,6 +15,15 @@ 1.0.0-SNAPSHOT + + kubernetes-minikube/demo-frontend + kubernetes-minikube/demo-backend + kubernetes-selfhealing/liveness-example + kubernetes-selfhealing/readiness-example + kubernetes-guide/client-service + kubernetes-guide/travel-agency-service + + @@ -27,15 +36,6 @@ - - kubernetes-minikube/demo-frontend - kubernetes-minikube/demo-backend - kubernetes-selfhealing/liveness-example - kubernetes-selfhealing/readiness-example - kubernetes-guide/client-service - kubernetes-guide/travel-agency-service - - 2021.0.0 diff --git a/spring-cloud/spring-cloud-load-balancer/pom.xml b/spring-cloud/spring-cloud-load-balancer/pom.xml index 65cf83de09..3b81def641 100644 --- a/spring-cloud/spring-cloud-load-balancer/pom.xml +++ b/spring-cloud/spring-cloud-load-balancer/pom.xml @@ -19,7 +19,7 @@ spring-cloud-loadbalancer-server spring-cloud-loadbalancer-client - + @@ -44,7 +44,7 @@ 2.6.1 2021.0.0 - 2.17.1 + 2.17.1 - + \ No newline at end of file diff --git a/spring-cloud/spring-cloud-load-balancer/spring-cloud-loadbalancer-client/pom.xml b/spring-cloud/spring-cloud-load-balancer/spring-cloud-loadbalancer-client/pom.xml index fc6e2854aa..c141452695 100644 --- a/spring-cloud/spring-cloud-load-balancer/spring-cloud-loadbalancer-client/pom.xml +++ b/spring-cloud/spring-cloud-load-balancer/spring-cloud-loadbalancer-client/pom.xml @@ -3,17 +3,30 @@ xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 + com.baeldung.springcloud.loadbalancer + spring-cloud-loadbalancer-client + 0.0.1-SNAPSHOT + spring-cloud-loadbalancer-client + Spring Cloud Load Balancer Demo - Client + com.baeldung.spring.cloud spring-cloud-loadbalancer 1.0.0-SNAPSHOT - com.baeldung.springcloud.loadbalancer - spring-cloud-loadbalancer-client - 0.0.1-SNAPSHOT - spring-cloud-loadbalancer-client - Spring Cloud Load Balancer Demo - Client + + + + org.springframework.cloud + spring-cloud-dependencies + ${spring-cloud.version} + pom + import + + + + org.springframework.boot @@ -30,17 +43,6 @@ test - - - - org.springframework.cloud - spring-cloud-dependencies - ${spring-cloud.version} - pom - import - - - @@ -51,4 +53,4 @@ - + \ No newline at end of file diff --git a/spring-cloud/spring-cloud-load-balancer/spring-cloud-loadbalancer-server/pom.xml b/spring-cloud/spring-cloud-load-balancer/spring-cloud-loadbalancer-server/pom.xml index 139996994d..3e61ecc90d 100644 --- a/spring-cloud/spring-cloud-load-balancer/spring-cloud-loadbalancer-server/pom.xml +++ b/spring-cloud/spring-cloud-load-balancer/spring-cloud-loadbalancer-server/pom.xml @@ -3,24 +3,23 @@ xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - - com.baeldung.spring.cloud - spring-cloud-loadbalancer - 1.0.0-SNAPSHOT - - com.baeldung.spring.cloud.loadbalancer spring-cloud-loadbalancer-server 0.0.1-SNAPSHOT spring-cloud-loadbalancer-server Spring Cloud Load Balancer Demo - Server + + com.baeldung.spring.cloud + spring-cloud-loadbalancer + 1.0.0-SNAPSHOT + + org.springframework.boot spring-boot-starter-web - org.springframework.boot spring-boot-starter-test @@ -37,4 +36,4 @@ - + \ No newline at end of file diff --git a/spring-cloud/spring-cloud-zuul-eureka-integration/eureka-client/pom.xml b/spring-cloud/spring-cloud-zuul-eureka-integration/eureka-client/pom.xml index b2cb66744b..3960cfde5d 100644 --- a/spring-cloud/spring-cloud-zuul-eureka-integration/eureka-client/pom.xml +++ b/spring-cloud/spring-cloud-zuul-eureka-integration/eureka-client/pom.xml @@ -52,7 +52,7 @@ test - + 2.17.1 diff --git a/spring-cloud/spring-cloud-zuul-eureka-integration/eureka-server/pom.xml b/spring-cloud/spring-cloud-zuul-eureka-integration/eureka-server/pom.xml index 466291650c..c9bc120e4d 100644 --- a/spring-cloud/spring-cloud-zuul-eureka-integration/eureka-server/pom.xml +++ b/spring-cloud/spring-cloud-zuul-eureka-integration/eureka-server/pom.xml @@ -52,7 +52,7 @@ test - + 2.17.1 diff --git a/spring-cloud/spring-cloud-zuul-eureka-integration/zuul-server/pom.xml b/spring-cloud/spring-cloud-zuul-eureka-integration/zuul-server/pom.xml index 27afc3eb69..76d899447f 100644 --- a/spring-cloud/spring-cloud-zuul-eureka-integration/zuul-server/pom.xml +++ b/spring-cloud/spring-cloud-zuul-eureka-integration/zuul-server/pom.xml @@ -60,8 +60,8 @@ test - - + + 2.17.1 diff --git a/spring-cloud/spring-cloud-zuul/spring-zuul-rate-limiting/pom.xml b/spring-cloud/spring-cloud-zuul/spring-zuul-rate-limiting/pom.xml index 4727859ea2..5df22c78c8 100644 --- a/spring-cloud/spring-cloud-zuul/spring-zuul-rate-limiting/pom.xml +++ b/spring-cloud/spring-cloud-zuul/spring-zuul-rate-limiting/pom.xml @@ -13,7 +13,7 @@ spring-cloud-zuul 0.0.1-SNAPSHOT - + diff --git a/spring-ejb/ejb-beans/pom.xml b/spring-ejb/ejb-beans/pom.xml index 6f20d949b0..37b67beec4 100644 --- a/spring-ejb/ejb-beans/pom.xml +++ b/spring-ejb/ejb-beans/pom.xml @@ -38,7 +38,6 @@ tomee-embedded ${tomee-embedded.version} - org.springframework spring-context diff --git a/spring-reactive/pom.xml b/spring-reactive/pom.xml index d31ee04d82..d755c03ae0 100644 --- a/spring-reactive/pom.xml +++ b/spring-reactive/pom.xml @@ -1,8 +1,9 @@ + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 + spring-reactive com.baeldung @@ -11,8 +12,6 @@ ../parent-boot-2 - spring-reactive - org.springframework.boot diff --git a/spring-security-modules/spring-5-security-oauth/pom.xml b/spring-security-modules/spring-5-security-oauth/pom.xml index 706cdb3082..8449b01ec0 100644 --- a/spring-security-modules/spring-5-security-oauth/pom.xml +++ b/spring-security-modules/spring-5-security-oauth/pom.xml @@ -15,8 +15,8 @@ 0.0.1-SNAPSHOT ../../parent-boot-2 - - + + org.apache.logging.log4j @@ -27,7 +27,6 @@ - @@ -85,7 +84,7 @@ is available --> 2.5.2 com.baeldung.oauth2.SpringOAuthApplication - 2.17.1 + 2.17.1 \ No newline at end of file diff --git a/spring-security-modules/spring-security-legacy-oidc/pom.xml b/spring-security-modules/spring-security-legacy-oidc/pom.xml index 9dd898f9dd..e98486b0ff 100644 --- a/spring-security-modules/spring-security-legacy-oidc/pom.xml +++ b/spring-security-modules/spring-security-legacy-oidc/pom.xml @@ -14,8 +14,8 @@ 0.0.1-SNAPSHOT ../../parent-boot-2 - - + + org.apache.logging.log4j @@ -62,7 +62,7 @@ 1.0.9.RELEASE 0.3.0 2.4.7 - 2.17.1 + 2.17.1 \ No newline at end of file diff --git a/spring-security-modules/spring-security-web-boot-1/pom.xml b/spring-security-modules/spring-security-web-boot-1/pom.xml index 3f6001686d..18cdd0ae5c 100644 --- a/spring-security-modules/spring-security-web-boot-1/pom.xml +++ b/spring-security-modules/spring-security-web-boot-1/pom.xml @@ -179,7 +179,6 @@ - entryPoints diff --git a/spring-security-modules/spring-security-web-boot-3/pom.xml b/spring-security-modules/spring-security-web-boot-3/pom.xml index 5f2a455294..59fcf9949f 100644 --- a/spring-security-modules/spring-security-web-boot-3/pom.xml +++ b/spring-security-modules/spring-security-web-boot-3/pom.xml @@ -1,5 +1,7 @@ - + 4.0.0 spring-security-web-boot-3 0.0.1-SNAPSHOT @@ -63,5 +65,4 @@ 3.6.0 - \ No newline at end of file diff --git a/spring-web-modules/pom.xml b/spring-web-modules/pom.xml index d66d9cb35a..a5c23c1649 100644 --- a/spring-web-modules/pom.xml +++ b/spring-web-modules/pom.xml @@ -50,4 +50,4 @@ spring-web-url - + \ No newline at end of file diff --git a/spring-web-modules/spring-mvc-basics-5/pom.xml b/spring-web-modules/spring-mvc-basics-5/pom.xml index 3b64f15c4b..5e8cd1b44e 100644 --- a/spring-web-modules/spring-mvc-basics-5/pom.xml +++ b/spring-web-modules/spring-mvc-basics-5/pom.xml @@ -41,7 +41,7 @@ - spring-mvc-basics + spring-mvc-basics-5 org.springframework.boot diff --git a/testing-modules/cucumber/pom.xml b/testing-modules/cucumber/pom.xml index 531b16ddec..ffa5c0d250 100644 --- a/testing-modules/cucumber/pom.xml +++ b/testing-modules/cucumber/pom.xml @@ -12,7 +12,6 @@ parent-boot-2 0.0.1-SNAPSHOT ../../parent-boot-2 - diff --git a/testing-modules/testng_command_line/pom.xml b/testing-modules/testng_command_line/pom.xml index 4c3af7621c..0f3201a432 100644 --- a/testing-modules/testng_command_line/pom.xml +++ b/testing-modules/testng_command_line/pom.xml @@ -3,10 +3,10 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 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.testing_modules testng_command_line 1.0.0-SNAPSHOT + com.baeldung testing-modules @@ -78,7 +78,6 @@ - ExecuteTestSuite @@ -101,6 +100,7 @@ + UTF-8 1.8 @@ -112,4 +112,5 @@ 3.8.0 2.22.1 - + + \ No newline at end of file From d2cea2ef063383ec62b3cb85f496c1154a63fd6d Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Sun, 13 Mar 2022 14:53:36 +0530 Subject: [PATCH 09/12] resolve conflicts --- spring-security-modules/spring-security-web-boot-3/pom.xml | 5 ++--- testing-modules/testng_command_line/pom.xml | 7 +++---- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/spring-security-modules/spring-security-web-boot-3/pom.xml b/spring-security-modules/spring-security-web-boot-3/pom.xml index 59fcf9949f..5f2a455294 100644 --- a/spring-security-modules/spring-security-web-boot-3/pom.xml +++ b/spring-security-modules/spring-security-web-boot-3/pom.xml @@ -1,7 +1,5 @@ - + 4.0.0 spring-security-web-boot-3 0.0.1-SNAPSHOT @@ -65,4 +63,5 @@ 3.6.0 + \ No newline at end of file diff --git a/testing-modules/testng_command_line/pom.xml b/testing-modules/testng_command_line/pom.xml index 0f3201a432..4c3af7621c 100644 --- a/testing-modules/testng_command_line/pom.xml +++ b/testing-modules/testng_command_line/pom.xml @@ -3,10 +3,10 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 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.testing_modules testng_command_line 1.0.0-SNAPSHOT - com.baeldung testing-modules @@ -78,6 +78,7 @@ + ExecuteTestSuite @@ -100,7 +101,6 @@ - UTF-8 1.8 @@ -112,5 +112,4 @@ 3.8.0 2.22.1 - - \ No newline at end of file + From aa35c80c419bb4c4829583e0504a4d007d594a84 Mon Sep 17 00:00:00 2001 From: Ralf Ueberfuhr <40685729+ueberfuhr@users.noreply.github.com> Date: Mon, 14 Mar 2022 20:23:35 +0100 Subject: [PATCH 10/12] BAEL-5457: Add Hikari configuration to datasource (#11923) --- .../todos/TodoDatasourceConfiguration.java | 1 + .../main/resources/application-multipledatasources.properties | 1 + 2 files changed, 2 insertions(+) diff --git a/persistence-modules/spring-data-jdbc/src/main/java/com/baeldung/springmultipledatasources/todos/TodoDatasourceConfiguration.java b/persistence-modules/spring-data-jdbc/src/main/java/com/baeldung/springmultipledatasources/todos/TodoDatasourceConfiguration.java index b6a16eb7e4..c599c26d01 100644 --- a/persistence-modules/spring-data-jdbc/src/main/java/com/baeldung/springmultipledatasources/todos/TodoDatasourceConfiguration.java +++ b/persistence-modules/spring-data-jdbc/src/main/java/com/baeldung/springmultipledatasources/todos/TodoDatasourceConfiguration.java @@ -19,6 +19,7 @@ public class TodoDatasourceConfiguration { @Bean @Primary + @ConfigurationProperties("spring.datasource.todos.hikari") public DataSource todosDataSource() { return todosDataSourceProperties() .initializeDataSourceBuilder() diff --git a/persistence-modules/spring-data-jdbc/src/main/resources/application-multipledatasources.properties b/persistence-modules/spring-data-jdbc/src/main/resources/application-multipledatasources.properties index 0f2b643498..d9f859ea40 100644 --- a/persistence-modules/spring-data-jdbc/src/main/resources/application-multipledatasources.properties +++ b/persistence-modules/spring-data-jdbc/src/main/resources/application-multipledatasources.properties @@ -3,6 +3,7 @@ spring.datasource.todos.url=jdbc:h2:mem:todos spring.datasource.todos.username=sa spring.datasource.todos.password=null spring.datasource.todos.driverClassName=org.h2.Driver +spring.datasource.todos.hikari.connectionTimeout=44444 spring.datasource.topics.url=jdbc:h2:mem:topics spring.datasource.topics.username=sa spring.datasource.topics.password=null From f74056e1d78537e1eb1bceadefa23d9101a4deec Mon Sep 17 00:00:00 2001 From: Kapil Khandelwal Date: Tue, 15 Mar 2022 01:04:49 +0530 Subject: [PATCH 11/12] BAEL-5371: Create a new module java-mongodb-2 in persistence-modules and add push and set operations in Same MongoDB Update (#11924) --- persistence-modules/java-mongodb-2/.gitignore | 5 ++ persistence-modules/java-mongodb-2/README.md | 5 ++ persistence-modules/java-mongodb-2/pom.xml | 53 ++++++++++++++++++ .../mongo/update/PustSetOperation.java | 54 +++++++++++++++++++ .../src/main/resources/logback.xml | 13 +++++ .../update/PustSetOperationLiveTest.java | 53 ++++++++++++++++++ persistence-modules/pom.xml | 3 +- 7 files changed, 185 insertions(+), 1 deletion(-) create mode 100644 persistence-modules/java-mongodb-2/.gitignore create mode 100644 persistence-modules/java-mongodb-2/README.md create mode 100644 persistence-modules/java-mongodb-2/pom.xml create mode 100644 persistence-modules/java-mongodb-2/src/main/java/com/baeldung/mongo/update/PustSetOperation.java create mode 100644 persistence-modules/java-mongodb-2/src/main/resources/logback.xml create mode 100644 persistence-modules/java-mongodb-2/src/test/java/com/baeldung/mongo/update/PustSetOperationLiveTest.java diff --git a/persistence-modules/java-mongodb-2/.gitignore b/persistence-modules/java-mongodb-2/.gitignore new file mode 100644 index 0000000000..79ba317cb5 --- /dev/null +++ b/persistence-modules/java-mongodb-2/.gitignore @@ -0,0 +1,5 @@ +.classpath +.project +.settings +target +build \ No newline at end of file diff --git a/persistence-modules/java-mongodb-2/README.md b/persistence-modules/java-mongodb-2/README.md new file mode 100644 index 0000000000..1b49e11499 --- /dev/null +++ b/persistence-modules/java-mongodb-2/README.md @@ -0,0 +1,5 @@ +## MongoDB + +This module contains articles about MongoDB in Java. + + diff --git a/persistence-modules/java-mongodb-2/pom.xml b/persistence-modules/java-mongodb-2/pom.xml new file mode 100644 index 0000000000..ffc8da0b64 --- /dev/null +++ b/persistence-modules/java-mongodb-2/pom.xml @@ -0,0 +1,53 @@ + + + 4.0.0 + java-mongodb-2 + 1.0-SNAPSHOT + java-mongodb-2 + + + com.baeldung + persistence-modules + 1.0.0-SNAPSHOT + + + + + de.flapdoodle.embedmongo + de.flapdoodle.embedmongo + ${flapdoodle.version} + test + + + org.mongodb + mongo-java-driver + ${mongo.version} + + + dev.morphia.morphia + core + ${morphia.version} + + + org.testcontainers + mongodb + 1.16.3 + test + + + org.testcontainers + junit-jupiter + 1.16.3 + test + + + + + 3.12.1 + 1.11 + 1.5.3 + + + diff --git a/persistence-modules/java-mongodb-2/src/main/java/com/baeldung/mongo/update/PustSetOperation.java b/persistence-modules/java-mongodb-2/src/main/java/com/baeldung/mongo/update/PustSetOperation.java new file mode 100644 index 0000000000..bb7eca4f23 --- /dev/null +++ b/persistence-modules/java-mongodb-2/src/main/java/com/baeldung/mongo/update/PustSetOperation.java @@ -0,0 +1,54 @@ +package com.baeldung.mongo.update; + +import org.bson.Document; + +import com.mongodb.MongoClient; +import com.mongodb.client.MongoCollection; +import com.mongodb.client.MongoDatabase; +import com.mongodb.client.model.Filters; +import com.mongodb.client.model.Updates; +import com.mongodb.client.result.UpdateResult; + +public class PustSetOperation { + + private static MongoClient mongoClient; + + private static String testCollectionName; + private static String databaseName; + + public static void setUp() { + if (mongoClient == null) { + mongoClient = new MongoClient("localhost", 27017); + } + databaseName = "baeldung"; + testCollectionName = "marks"; + } + + public static void pushSetSolution() { + + MongoDatabase database = mongoClient.getDatabase(databaseName); + MongoCollection collection = database.getCollection(testCollectionName); + + Document subjectData = new Document().append("subjectId", 126) + .append("subjectName", "Java Programming") + .append("marks", 70); + UpdateResult updateQueryResult = collection.updateOne(Filters.eq("studentId", 1023), Updates.combine(Updates.set("totalMarks", 170), Updates.push("subjectDetails", subjectData))); + System.out.println("updateQueryResult:- " + updateQueryResult); + + } + + public static void main(String args[]) { + + // + // Connect to cluster (default is localhost:27017) + // + setUp(); + + // + // Push document into the array and set a field + // + pushSetSolution(); + + } +} + diff --git a/persistence-modules/java-mongodb-2/src/main/resources/logback.xml b/persistence-modules/java-mongodb-2/src/main/resources/logback.xml new file mode 100644 index 0000000000..7d900d8ea8 --- /dev/null +++ b/persistence-modules/java-mongodb-2/src/main/resources/logback.xml @@ -0,0 +1,13 @@ + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + + \ No newline at end of file diff --git a/persistence-modules/java-mongodb-2/src/test/java/com/baeldung/mongo/update/PustSetOperationLiveTest.java b/persistence-modules/java-mongodb-2/src/test/java/com/baeldung/mongo/update/PustSetOperationLiveTest.java new file mode 100644 index 0000000000..6279747429 --- /dev/null +++ b/persistence-modules/java-mongodb-2/src/test/java/com/baeldung/mongo/update/PustSetOperationLiveTest.java @@ -0,0 +1,53 @@ +package com.baeldung.update; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; + +import org.bson.Document; +import org.junit.BeforeClass; +import org.junit.Test; + +import com.mongodb.MongoClient; +import com.mongodb.client.MongoCollection; +import com.mongodb.client.MongoDatabase; +import com.mongodb.client.model.Filters; +import com.mongodb.client.model.Updates; +import com.mongodb.client.result.UpdateResult; + +public class PustSetOperationLiveTest { + + private static MongoClient mongoClient; + private static MongoDatabase db; + private static MongoCollection collection; + + @BeforeClass + public static void setup() { + if (mongoClient == null) { + mongoClient = new MongoClient("localhost", 27017); + db = mongoClient.getDatabase("baeldung"); + collection = db.getCollection("marks"); + + collection.insertOne(Document.parse("{\n" + " \"studentId\": 1023,\n" + " \"studentName\":\"James Broad\",\n" + " \"joiningYear\":\"2018\",\n" + " \"totalMarks\":100,\n" + " \"subjectDetails\":[\n" + + " {\n" + " \"subjectId\":123,\n" + " \"subjectName\":\"Operating Systems Concepts\",\n" + " \"marks\":4,\n" + " },\n" + " {\n" + + " \"subjectId\":124,\n" + " \"subjectName\":\"Numerical Analysis\",\n" + " \"marks\":60\n" + " }\n" + " ]\n" + " }")); + + } + } + + @Test + public void givenMarksCollection_whenPushSetOperation_thenCheckingForDocument() { + + Document subjectData = new Document().append("subjectId", 126) + .append("subjectName", "Java Programming") + .append("marks", 70); + UpdateResult updateQueryResult = collection.updateOne(Filters.eq("studentId", 1023), Updates.combine(Updates.set("totalMarks", 170), Updates.push("subjectDetails", subjectData))); + + Document studentDetail = collection.find(Filters.eq("studentId", 1023)) + .first(); + assertNotNull(studentDetail); + assertFalse(studentDetail.isEmpty()); + + } + +} + diff --git a/persistence-modules/pom.xml b/persistence-modules/pom.xml index 64a9519a8b..f8e3cb05e8 100644 --- a/persistence-modules/pom.xml +++ b/persistence-modules/pom.xml @@ -43,6 +43,7 @@ java-jpa-2 java-jpa-3 java-mongodb + java-mongodb-2 jnosql jooq jpa-hibernate-cascade-type @@ -104,4 +105,4 @@ 42.2.20 - \ No newline at end of file + From 7681cb2d65bc94120998be2848d53f70f7ed4c91 Mon Sep 17 00:00:00 2001 From: Jonathan Cook Date: Mon, 14 Mar 2022 23:35:32 +0100 Subject: [PATCH 12/12] BAEL-5234 - Apache Camel Routes Testing in Spring Boot (#11925) * BAEL-4706 - Spring Boot with Spring Batch * BAEL-3948 - Fix test(s) in spring-batch which leaves repository.sqlite changed * BAEL-4736 - Convert JSONArray to List of Object using camel-jackson * BAEL-4756 - Mockito MockSettings * BAEL-4756 - Mockito MockSettings - fix spelling * BAEL-2674 - Upgrade the Okhttp article * BAEL-4204 - Adding Interceptors in OkHTTP * BAEL-4836 - Mocking Static Methods with Mockito * BAEL-4205 - A Guide to Events in OkHTTP * BAEL-5408 - Update Camel version in spring-boot-camel module * BAEL-5234 - Apache Camel Routes Testing in Spring Boot * BAEL-5234 - Apache Camel Routes Testing in Spring Boot Co-authored-by: Jonathan Cook --- .../spring-boot-camel/.gitignore | 1 + spring-boot-modules/spring-boot-camel/pom.xml | 9 ++++++ .../boot/testing/GreetingsFileRouter.java | 19 +++++++++++ .../GreetingsFileSpringApplication.java | 13 ++++++++ .../testing/GreetingsFileRouterUnitTest.java | 32 +++++++++++++++++++ 5 files changed, 74 insertions(+) create mode 100644 spring-boot-modules/spring-boot-camel/.gitignore create mode 100644 spring-boot-modules/spring-boot-camel/src/main/java/com/baeldung/camel/boot/testing/GreetingsFileRouter.java create mode 100644 spring-boot-modules/spring-boot-camel/src/main/java/com/baeldung/camel/boot/testing/GreetingsFileSpringApplication.java create mode 100644 spring-boot-modules/spring-boot-camel/src/test/java/com/baeldung/camel/boot/testing/GreetingsFileRouterUnitTest.java diff --git a/spring-boot-modules/spring-boot-camel/.gitignore b/spring-boot-modules/spring-boot-camel/.gitignore new file mode 100644 index 0000000000..16be8f2193 --- /dev/null +++ b/spring-boot-modules/spring-boot-camel/.gitignore @@ -0,0 +1 @@ +/output/ diff --git a/spring-boot-modules/spring-boot-camel/pom.xml b/spring-boot-modules/spring-boot-camel/pom.xml index 5bda1b2351..ecf7143808 100644 --- a/spring-boot-modules/spring-boot-camel/pom.xml +++ b/spring-boot-modules/spring-boot-camel/pom.xml @@ -44,6 +44,12 @@ spring-boot-starter-test test + + org.apache.camel + camel-test-spring-junit5 + ${camel.version} + test + @@ -57,6 +63,9 @@ repackage + + com.baeldung.camel.boot.testing.GreetingsFileSpringApplication + diff --git a/spring-boot-modules/spring-boot-camel/src/main/java/com/baeldung/camel/boot/testing/GreetingsFileRouter.java b/spring-boot-modules/spring-boot-camel/src/main/java/com/baeldung/camel/boot/testing/GreetingsFileRouter.java new file mode 100644 index 0000000000..670af5e08c --- /dev/null +++ b/spring-boot-modules/spring-boot-camel/src/main/java/com/baeldung/camel/boot/testing/GreetingsFileRouter.java @@ -0,0 +1,19 @@ +package com.baeldung.camel.boot.testing; + +import org.apache.camel.builder.RouteBuilder; +import org.springframework.stereotype.Component; + +@Component +public class GreetingsFileRouter extends RouteBuilder { + + @Override + public void configure() throws Exception { + + from("direct:start") + .routeId("greetings-route") + .setBody(constant("Hello Baeldung Readers!")) + .to("file:output"); + + } + +} diff --git a/spring-boot-modules/spring-boot-camel/src/main/java/com/baeldung/camel/boot/testing/GreetingsFileSpringApplication.java b/spring-boot-modules/spring-boot-camel/src/main/java/com/baeldung/camel/boot/testing/GreetingsFileSpringApplication.java new file mode 100644 index 0000000000..a4e862e65d --- /dev/null +++ b/spring-boot-modules/spring-boot-camel/src/main/java/com/baeldung/camel/boot/testing/GreetingsFileSpringApplication.java @@ -0,0 +1,13 @@ +package com.baeldung.camel.boot.testing; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class GreetingsFileSpringApplication { + + public static void main(String[] args) { + SpringApplication.run(GreetingsFileSpringApplication.class, args); + } + +} diff --git a/spring-boot-modules/spring-boot-camel/src/test/java/com/baeldung/camel/boot/testing/GreetingsFileRouterUnitTest.java b/spring-boot-modules/spring-boot-camel/src/test/java/com/baeldung/camel/boot/testing/GreetingsFileRouterUnitTest.java new file mode 100644 index 0000000000..baeb1fd39c --- /dev/null +++ b/spring-boot-modules/spring-boot-camel/src/test/java/com/baeldung/camel/boot/testing/GreetingsFileRouterUnitTest.java @@ -0,0 +1,32 @@ +package com.baeldung.camel.boot.testing; + +import org.apache.camel.EndpointInject; +import org.apache.camel.ProducerTemplate; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.test.spring.junit5.CamelSpringBootTest; +import org.apache.camel.test.spring.junit5.MockEndpoints; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +@CamelSpringBootTest +@MockEndpoints("file:output") +class GreetingsFileRouterUnitTest { + + @Autowired + private ProducerTemplate template; + + @EndpointInject("mock:file:output") + private MockEndpoint mock; + + @Test + void whenSendBody_thenGreetingReceivedSuccessfully() throws InterruptedException { + mock.expectedBodiesReceived("Hello Baeldung Readers!"); + + template.sendBody("direct:start", null); + + mock.assertIsSatisfied(); + } + +}