From e9e7aace3164288dfa17113140d69f9bbf974ec0 Mon Sep 17 00:00:00 2001 From: emanueltrandafir1993 Date: Sun, 8 Jan 2023 16:59:46 +0100 Subject: [PATCH 01/13] BAEL-6058: extracting request header --- .../requestheader/BuzzController.java | 21 ++++++ .../requestheader/FooBarController.java | 22 +++++++ .../HeaderInterceptorApplication.java | 15 +++++ .../config/HeaderInterceptorConfig.java | 33 ++++++++++ .../interceptor/OperatorHolder.java | 13 ++++ .../interceptor/OperatorInterceptor.java | 22 +++++++ .../HeaderInterceptorApplicationTest.java | 66 +++++++++++++++++++ 7 files changed, 192 insertions(+) create mode 100644 spring-boot-modules/spring-boot-mvc-5/src/main/java/com/baeldung/requestheader/BuzzController.java create mode 100644 spring-boot-modules/spring-boot-mvc-5/src/main/java/com/baeldung/requestheader/FooBarController.java create mode 100644 spring-boot-modules/spring-boot-mvc-5/src/main/java/com/baeldung/requestheader/HeaderInterceptorApplication.java create mode 100644 spring-boot-modules/spring-boot-mvc-5/src/main/java/com/baeldung/requestheader/config/HeaderInterceptorConfig.java create mode 100644 spring-boot-modules/spring-boot-mvc-5/src/main/java/com/baeldung/requestheader/interceptor/OperatorHolder.java create mode 100644 spring-boot-modules/spring-boot-mvc-5/src/main/java/com/baeldung/requestheader/interceptor/OperatorInterceptor.java create mode 100644 spring-boot-modules/spring-boot-mvc-5/src/test/java/com/baeldung/requestheader/HeaderInterceptorApplicationTest.java diff --git a/spring-boot-modules/spring-boot-mvc-5/src/main/java/com/baeldung/requestheader/BuzzController.java b/spring-boot-modules/spring-boot-mvc-5/src/main/java/com/baeldung/requestheader/BuzzController.java new file mode 100644 index 0000000000..09bf16f008 --- /dev/null +++ b/spring-boot-modules/spring-boot-mvc-5/src/main/java/com/baeldung/requestheader/BuzzController.java @@ -0,0 +1,21 @@ +package com.baeldung.requestheader; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +import com.baeldung.requestheader.interceptor.OperatorHolder; + +@RestController +public class BuzzController { + private final OperatorHolder operatorHolder; + + public BuzzController(OperatorHolder operatorHolder) { + this.operatorHolder = operatorHolder; + } + + @GetMapping("buzz") + public String buzz() { + return "hello, " + operatorHolder.getOperator(); + } + +} diff --git a/spring-boot-modules/spring-boot-mvc-5/src/main/java/com/baeldung/requestheader/FooBarController.java b/spring-boot-modules/spring-boot-mvc-5/src/main/java/com/baeldung/requestheader/FooBarController.java new file mode 100644 index 0000000000..e0fd5f2f64 --- /dev/null +++ b/spring-boot-modules/spring-boot-mvc-5/src/main/java/com/baeldung/requestheader/FooBarController.java @@ -0,0 +1,22 @@ +package com.baeldung.requestheader; + +import javax.servlet.http.HttpServletRequest; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class FooBarController { + + @GetMapping("foo") + public String foo(HttpServletRequest request) { + String operator = request.getHeader("operator"); + return "hello, " + operator; + } + + @GetMapping("bar") + public String bar(@RequestHeader("operator") String operator) { + return "hello, " + operator; + } +} diff --git a/spring-boot-modules/spring-boot-mvc-5/src/main/java/com/baeldung/requestheader/HeaderInterceptorApplication.java b/spring-boot-modules/spring-boot-mvc-5/src/main/java/com/baeldung/requestheader/HeaderInterceptorApplication.java new file mode 100644 index 0000000000..f2e9aaca12 --- /dev/null +++ b/spring-boot-modules/spring-boot-mvc-5/src/main/java/com/baeldung/requestheader/HeaderInterceptorApplication.java @@ -0,0 +1,15 @@ +package com.baeldung.requestheader; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.web.servlet.config.annotation.EnableWebMvc; + +@SpringBootApplication +@EnableWebMvc +public class HeaderInterceptorApplication { + + public static void main(String[] args) { + SpringApplication.run(HeaderInterceptorApplication.class, args); + } + +} diff --git a/spring-boot-modules/spring-boot-mvc-5/src/main/java/com/baeldung/requestheader/config/HeaderInterceptorConfig.java b/spring-boot-modules/spring-boot-mvc-5/src/main/java/com/baeldung/requestheader/config/HeaderInterceptorConfig.java new file mode 100644 index 0000000000..07fb5b5184 --- /dev/null +++ b/spring-boot-modules/spring-boot-mvc-5/src/main/java/com/baeldung/requestheader/config/HeaderInterceptorConfig.java @@ -0,0 +1,33 @@ +package com.baeldung.requestheader.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Scope; +import org.springframework.context.annotation.ScopedProxyMode; +import org.springframework.web.context.WebApplicationContext; +import org.springframework.web.servlet.config.annotation.InterceptorRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; + +import com.baeldung.requestheader.interceptor.OperatorHolder; +import com.baeldung.requestheader.interceptor.OperatorInterceptor; + +@Configuration +public class HeaderInterceptorConfig implements WebMvcConfigurer { + + @Override + public void addInterceptors(final InterceptorRegistry registry) { + registry.addInterceptor(operatorInterceptor()); + } + + @Bean + public OperatorInterceptor operatorInterceptor() { + return new OperatorInterceptor(operatorHolder()); + } + + @Bean + @Scope(value = WebApplicationContext.SCOPE_REQUEST, proxyMode = ScopedProxyMode.TARGET_CLASS) + public OperatorHolder operatorHolder() { + return new OperatorHolder(); + } + +} diff --git a/spring-boot-modules/spring-boot-mvc-5/src/main/java/com/baeldung/requestheader/interceptor/OperatorHolder.java b/spring-boot-modules/spring-boot-mvc-5/src/main/java/com/baeldung/requestheader/interceptor/OperatorHolder.java new file mode 100644 index 0000000000..31d36c0b59 --- /dev/null +++ b/spring-boot-modules/spring-boot-mvc-5/src/main/java/com/baeldung/requestheader/interceptor/OperatorHolder.java @@ -0,0 +1,13 @@ +package com.baeldung.requestheader.interceptor; + +public class OperatorHolder { + private String operator; + + public String getOperator() { + return operator; + } + + public void setOperator(String operator) { + this.operator = operator; + } +} diff --git a/spring-boot-modules/spring-boot-mvc-5/src/main/java/com/baeldung/requestheader/interceptor/OperatorInterceptor.java b/spring-boot-modules/spring-boot-mvc-5/src/main/java/com/baeldung/requestheader/interceptor/OperatorInterceptor.java new file mode 100644 index 0000000000..0d0a0c7405 --- /dev/null +++ b/spring-boot-modules/spring-boot-mvc-5/src/main/java/com/baeldung/requestheader/interceptor/OperatorInterceptor.java @@ -0,0 +1,22 @@ +package com.baeldung.requestheader.interceptor; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.springframework.web.servlet.HandlerInterceptor; + +public class OperatorInterceptor implements HandlerInterceptor { + + private final OperatorHolder operatorHolder; + + @Override + public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { + String operator = request.getHeader("operator"); + operatorHolder.setOperator(operator); + return true; + } + + public OperatorInterceptor(OperatorHolder operatorHolder) { + this.operatorHolder = operatorHolder; + } +} diff --git a/spring-boot-modules/spring-boot-mvc-5/src/test/java/com/baeldung/requestheader/HeaderInterceptorApplicationTest.java b/spring-boot-modules/spring-boot-mvc-5/src/test/java/com/baeldung/requestheader/HeaderInterceptorApplicationTest.java new file mode 100644 index 0000000000..77b48fbe99 --- /dev/null +++ b/spring-boot-modules/spring-boot-mvc-5/src/test/java/com/baeldung/requestheader/HeaderInterceptorApplicationTest.java @@ -0,0 +1,66 @@ +package com.baeldung.requestheader; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; + +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.mock.web.MockHttpServletResponse; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit.jupiter.SpringExtension; +import org.springframework.test.context.web.WebAppConfiguration; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.setup.MockMvcBuilders; +import org.springframework.web.context.WebApplicationContext; + +@ExtendWith(SpringExtension.class) +@ContextConfiguration(classes = { HeaderInterceptorApplication.class }) +@WebAppConfiguration +public class HeaderInterceptorApplicationTest { + + @Autowired + private WebApplicationContext webApplicationContext; + + private MockMvc mockMvc; + + @BeforeEach + public void setup() { + this.mockMvc = MockMvcBuilders.webAppContextSetup(this.webApplicationContext) + .build(); + } + + @Test + public void givenARequestWithOperatorHeader_whenWeCallFooEndpoint_thenOperatorIsExtracted() throws Exception { + MockHttpServletResponse response = this.mockMvc.perform(get("/foo").header("operator", "John.Doe")) + .andDo(print()) + .andReturn() + .getResponse(); + + assertThat(response.getContentAsString()).isEqualTo("hello, John.Doe"); + } + + @Test + public void givenARequestWithOperatorHeader_whenWeCallBarEndpoint_thenOperatorIsExtracted() throws Exception { + MockHttpServletResponse response = this.mockMvc.perform(get("/bar").header("operator", "John.Doe")) + .andDo(print()) + .andReturn() + .getResponse(); + + assertThat(response.getContentAsString()).isEqualTo("hello, John.Doe"); + } + + @Test + public void givenARequestWithOperatorHeader_whenWeCallBuzzEndpoint_thenOperatorIsIntercepted() throws Exception { + MockHttpServletResponse response = this.mockMvc.perform(get("/buzz").header("operator", "John.Doe")) + .andDo(print()) + .andReturn() + .getResponse(); + + assertThat(response.getContentAsString()).isEqualTo("hello, John.Doe"); + } + +} \ No newline at end of file From 77d6a987a8684460c91460e4499e6b0e295e09e0 Mon Sep 17 00:00:00 2001 From: emanueltrandafir1993 Date: Tue, 17 Jan 2023 20:47:07 +0100 Subject: [PATCH 02/13] BAEL-6058: renamed test class --- ...licationTest.java => HeaderInterceptorIntegrationTest.java} | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) rename spring-boot-modules/spring-boot-mvc-5/src/test/java/com/baeldung/requestheader/{HeaderInterceptorApplicationTest.java => HeaderInterceptorIntegrationTest.java} (96%) diff --git a/spring-boot-modules/spring-boot-mvc-5/src/test/java/com/baeldung/requestheader/HeaderInterceptorApplicationTest.java b/spring-boot-modules/spring-boot-mvc-5/src/test/java/com/baeldung/requestheader/HeaderInterceptorIntegrationTest.java similarity index 96% rename from spring-boot-modules/spring-boot-mvc-5/src/test/java/com/baeldung/requestheader/HeaderInterceptorApplicationTest.java rename to spring-boot-modules/spring-boot-mvc-5/src/test/java/com/baeldung/requestheader/HeaderInterceptorIntegrationTest.java index 77b48fbe99..9343a608e4 100644 --- a/spring-boot-modules/spring-boot-mvc-5/src/test/java/com/baeldung/requestheader/HeaderInterceptorApplicationTest.java +++ b/spring-boot-modules/spring-boot-mvc-5/src/test/java/com/baeldung/requestheader/HeaderInterceptorIntegrationTest.java @@ -4,7 +4,6 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; -import org.assertj.core.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -20,7 +19,7 @@ import org.springframework.web.context.WebApplicationContext; @ExtendWith(SpringExtension.class) @ContextConfiguration(classes = { HeaderInterceptorApplication.class }) @WebAppConfiguration -public class HeaderInterceptorApplicationTest { +public class HeaderInterceptorIntegrationTest { @Autowired private WebApplicationContext webApplicationContext; From fd1c28657032e30d25840730519a238fe24e52f3 Mon Sep 17 00:00:00 2001 From: Bhaskar Ghosh Dastidar Date: Thu, 19 Jan 2023 08:23:05 +0530 Subject: [PATCH 03/13] [JAVA-5730] convert list of objects to list of strings (#13166) * [JAVA-5730] convert list of objects to list of strings * [JAVA-5730] added new unit tests with null and non-null lists. modified pom.xml with java version to 16 * [JAVA-5730] simplified User class and formatted the codebase * [JAVA-5730] added module in jdk-9 and above profile * [JAVA-5730] removed arraylist module from other profiles of core-java pom * [JAVA-5730] java util opened for reflection surefire plugin Co-authored-by: Bhaskar --- .../core-java-collections-array-list/pom.xml | 33 +++++++ .../listofobjectstolistofstring/Node.java | 17 ++++ .../listofobjectstolistofstring/User.java | 14 +++ ...ConvertObjectListToStringListUnitTest.java | 92 +++++++++++++++++++ core-java-modules/pom.xml | 1 - pom.xml | 1 + 6 files changed, 157 insertions(+), 1 deletion(-) create mode 100644 core-java-modules/core-java-collections-array-list/src/main/java/com/baeldung/listofobjectstolistofstring/Node.java create mode 100644 core-java-modules/core-java-collections-array-list/src/main/java/com/baeldung/listofobjectstolistofstring/User.java create mode 100644 core-java-modules/core-java-collections-array-list/src/test/java/com/baeldung/listofobjectstolistofstring/ConvertObjectListToStringListUnitTest.java diff --git a/core-java-modules/core-java-collections-array-list/pom.xml b/core-java-modules/core-java-collections-array-list/pom.xml index 6b040739e8..e3a115854c 100644 --- a/core-java-modules/core-java-collections-array-list/pom.xml +++ b/core-java-modules/core-java-collections-array-list/pom.xml @@ -5,6 +5,33 @@ 4.0.0 core-java-collections-array-list 0.1.0-SNAPSHOT + + + + org.apache.maven.plugins + maven-compiler-plugin + + ${maven-compiler-plugin.source} + ${maven-compiler-plugin.target} + + + + org.apache.maven.plugins + maven-surefire-plugin + ${surefire.plugin.version} + + + --add-opens java.base/java.util=ALL-UNNAMED + + + + + + + 16 + 16 + 3.0.0-M3 + core-java-collections-array-list jar @@ -20,6 +47,12 @@ commons-collections4 ${commons-collections4.version} + + com.google.guava + guava + 31.1-jre + test + \ No newline at end of file diff --git a/core-java-modules/core-java-collections-array-list/src/main/java/com/baeldung/listofobjectstolistofstring/Node.java b/core-java-modules/core-java-collections-array-list/src/main/java/com/baeldung/listofobjectstolistofstring/Node.java new file mode 100644 index 0000000000..3e2c5693de --- /dev/null +++ b/core-java-modules/core-java-collections-array-list/src/main/java/com/baeldung/listofobjectstolistofstring/Node.java @@ -0,0 +1,17 @@ +package com.baeldung.listofobjectstolistofstring; + +public class Node { + + private final int x; + private final int y; + + public Node(int x, int y) { + this.x = x; + this.y = y; + } + + @Override + public String toString() { + return "Node (" + "x=" + x + ", y=" + y + ')'; + } +} diff --git a/core-java-modules/core-java-collections-array-list/src/main/java/com/baeldung/listofobjectstolistofstring/User.java b/core-java-modules/core-java-collections-array-list/src/main/java/com/baeldung/listofobjectstolistofstring/User.java new file mode 100644 index 0000000000..eb9298bce0 --- /dev/null +++ b/core-java-modules/core-java-collections-array-list/src/main/java/com/baeldung/listofobjectstolistofstring/User.java @@ -0,0 +1,14 @@ +package com.baeldung.listofobjectstolistofstring; + +public class User { + private final String fullName; + + public User(String fullName) { + this.fullName = fullName; + } + + @Override + public String toString() { + return "User (" + "full name='" + fullName + ')'; + } +} \ No newline at end of file diff --git a/core-java-modules/core-java-collections-array-list/src/test/java/com/baeldung/listofobjectstolistofstring/ConvertObjectListToStringListUnitTest.java b/core-java-modules/core-java-collections-array-list/src/test/java/com/baeldung/listofobjectstolistofstring/ConvertObjectListToStringListUnitTest.java new file mode 100644 index 0000000000..1d393a2945 --- /dev/null +++ b/core-java-modules/core-java-collections-array-list/src/test/java/com/baeldung/listofobjectstolistofstring/ConvertObjectListToStringListUnitTest.java @@ -0,0 +1,92 @@ +package com.baeldung.listofobjectstolistofstring; + +import com.google.common.collect.Lists; + +import org.junit.Assert; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; + +public class ConvertObjectListToStringListUnitTest { + + @Test + public void givenObjectList_whenForEachUsedToConvert_thenReturnSuccess() { + List outputList = new ArrayList<>(objectListWithNull().size()); + for (Object obj : objectListWithNull()) { + outputList.add(Objects.toString(obj, null)); + } + Assert.assertEquals(expectedStringListWithNull(), outputList); + } + + @Test + public void givenObjectList_whenUsingStreamsToConvert_thenReturnSuccess() { + List outputList; + outputList = objectListWithNull().stream() + .map((obj) -> Objects.toString(obj, null)) + .collect(Collectors.toList()); + Assert.assertEquals(expectedStringListWithNull(), outputList); + + } + + @Test + public void givenObjectList_whenUsingStreamsUnmodifiableListToConvert_thenReturnSuccess() { + List outputList; + outputList = objectListWithNull().stream() + .filter(Objects::nonNull) + .map((obj) -> Objects.toString(obj, null)) + .collect(Collectors.toUnmodifiableList()); + Assert.assertEquals(expectedStringListWithoutNull(), outputList); + + } + + @Test + public void givenObjectList_whenUsingGuavaTransform_thenReturnSuccess() { + List outputList; + outputList = Lists.transform(objectListWithNull(), obj -> Objects.toString(obj, null)); + Assert.assertEquals(expectedStringListWithNull(), outputList); + } + + @Test + public void givenObjectListWithNoNull_whenUsingToList_thenReturnSuccess() { + List outputList; + outputList = objectListWithoutNull().stream() + .map((obj) -> Objects.toString(obj, null)) + .toList(); + Assert.assertEquals(expectedStringListWithoutNull(), outputList); + } + + private List expectedStringListWithNull() { + List listOfStrings = new ArrayList<>(); + listOfStrings.add("1"); + listOfStrings.add("true"); + listOfStrings.add("hello"); + listOfStrings.add(Double.toString(273773.98)); + listOfStrings.add(null); + listOfStrings.add(new Node(2, 4).toString()); + listOfStrings.add(new User("John Doe").toString()); + return listOfStrings; + } + + private List objectListWithNull() { + List listOfStrings = new ArrayList<>(); + listOfStrings.add(1); + listOfStrings.add(true); + listOfStrings.add("hello"); + listOfStrings.add(Double.valueOf(273773.98)); + listOfStrings.add(null); + listOfStrings.add(new Node(2, 4)); + listOfStrings.add(new User("John Doe")); + return listOfStrings; + } + + private List expectedStringListWithoutNull() { + return List.of("1", "true", "hello", Double.toString(273773.98), new Node(2, 4).toString(), new User("John Doe").toString()); + } + + private List objectListWithoutNull() { + return List.of(1, true, "hello", Double.valueOf(273773.98), new Node(2, 4), new User("John Doe")); + } +} diff --git a/core-java-modules/pom.xml b/core-java-modules/pom.xml index cc137d08b6..bbbca6adf5 100644 --- a/core-java-modules/pom.xml +++ b/core-java-modules/pom.xml @@ -31,7 +31,6 @@ core-java-collections-2 core-java-collections-3 core-java-collections-4 - core-java-collections-array-list core-java-collections-conversions core-java-collections-conversions-2 core-java-collections-set-2 diff --git a/pom.xml b/pom.xml index c4e5c25d9d..0b19c6eee6 100644 --- a/pom.xml +++ b/pom.xml @@ -1133,6 +1133,7 @@ core-java-modules/core-java-collections-set core-java-modules/core-java-collections-list-4 + core-java-modules/core-java-collections-array-list core-java-modules/core-java-collections-maps-4 core-java-modules/core-java-collections-maps-5 core-java-modules/core-java-concurrency-simple From caa663239f09d534e08686a2933525833ce8524f Mon Sep 17 00:00:00 2001 From: Muhammad Asif Date: Thu, 19 Jan 2023 10:32:40 +0500 Subject: [PATCH 04/13] muasif80@gmail.com (#13262) * BAEL-6063 * Updated the unit test class name * Fixed the test * Made updates to method names for tests and some refactor of code * Updated the formatting using Baeldung formatter for Java * Removed the space around = and made line continuations 2 spaces --- .../data/persistence/search/Student.java | 75 +++++++++++++ .../search/StudentApplication.java | 16 +++ .../persistence/search/StudentRepository.java | 31 ++++++ .../src/main/resources/application.properties | 1 + .../search/StudentApplicationUnitTest.java | 100 ++++++++++++++++++ 5 files changed, 223 insertions(+) create mode 100644 persistence-modules/spring-data-jpa-repo-2/src/main/java/com/baeldung/spring/data/persistence/search/Student.java create mode 100644 persistence-modules/spring-data-jpa-repo-2/src/main/java/com/baeldung/spring/data/persistence/search/StudentApplication.java create mode 100644 persistence-modules/spring-data-jpa-repo-2/src/main/java/com/baeldung/spring/data/persistence/search/StudentRepository.java create mode 100644 persistence-modules/spring-data-jpa-repo-2/src/test/java/com/baeldung/spring/data/persistence/search/StudentApplicationUnitTest.java diff --git a/persistence-modules/spring-data-jpa-repo-2/src/main/java/com/baeldung/spring/data/persistence/search/Student.java b/persistence-modules/spring-data-jpa-repo-2/src/main/java/com/baeldung/spring/data/persistence/search/Student.java new file mode 100644 index 0000000000..1d6eaa3b33 --- /dev/null +++ b/persistence-modules/spring-data-jpa-repo-2/src/main/java/com/baeldung/spring/data/persistence/search/Student.java @@ -0,0 +1,75 @@ +package com.baeldung.spring.data.persistence.search; + +import java.util.Objects; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; + +@Entity +public class Student { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private long id; + + private String name; + private int score; + + public Student() { + } + + public Student(String name, int score) { + + this.name = name; + this.score = score; + } + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getScore() { + return score; + } + + public void setScore(int score) { + this.score = score; + } + + @Override + public String toString() { + return "Student [id=" + id + ", name=" + name + ", score=" + score + "]"; + } + + @Override + public int hashCode() { + return Objects.hash(id, name, score); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Student other = (Student) obj; + return id == other.id && Objects.equals(name, other.name) && score == other.score; + } + +} \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-repo-2/src/main/java/com/baeldung/spring/data/persistence/search/StudentApplication.java b/persistence-modules/spring-data-jpa-repo-2/src/main/java/com/baeldung/spring/data/persistence/search/StudentApplication.java new file mode 100644 index 0000000000..6aa895d067 --- /dev/null +++ b/persistence-modules/spring-data-jpa-repo-2/src/main/java/com/baeldung/spring/data/persistence/search/StudentApplication.java @@ -0,0 +1,16 @@ +package com.baeldung.spring.data.persistence.search; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class StudentApplication { + + private static final Logger log = LoggerFactory.getLogger(StudentApplication.class); + + public static void main(String[] args) { + SpringApplication.run(StudentApplication.class, args); + } +} \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-repo-2/src/main/java/com/baeldung/spring/data/persistence/search/StudentRepository.java b/persistence-modules/spring-data-jpa-repo-2/src/main/java/com/baeldung/spring/data/persistence/search/StudentRepository.java new file mode 100644 index 0000000000..29aade5886 --- /dev/null +++ b/persistence-modules/spring-data-jpa-repo-2/src/main/java/com/baeldung/spring/data/persistence/search/StudentRepository.java @@ -0,0 +1,31 @@ +package com.baeldung.spring.data.persistence.search; + +import java.util.List; + +import org.springframework.data.domain.Sort; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface StudentRepository extends JpaRepository { + + Student findFirstByOrderByScoreDesc(); + + Student findFirstBy(Sort sort); + + Student findFirstByNameLike(String name, Sort sort); + + List findFirst3ByOrderByScoreDesc(); + + List findFirst2ByScoreBetween(int startScore, int endScore, Sort sort); + + Student findTopByOrderByScoreDesc(); + + Student findTopBy(Sort sort); + + Student findTopByNameLike(String name, Sort sort); + + List findTop3ByOrderByScoreDesc(); + + List findTop2ByScoreBetween(int startScore, int endScore, Sort sort); +} diff --git a/persistence-modules/spring-data-jpa-repo-2/src/main/resources/application.properties b/persistence-modules/spring-data-jpa-repo-2/src/main/resources/application.properties index 30cc5abbcc..3ca0cc1242 100644 --- a/persistence-modules/spring-data-jpa-repo-2/src/main/resources/application.properties +++ b/persistence-modules/spring-data-jpa-repo-2/src/main/resources/application.properties @@ -3,3 +3,4 @@ spring.datasource.username=sa spring.datasource.password=sa spring.jpa.properties.hibernate.globally_quoted_identifiers=true +logging.level.com.baeldung.spring.data.persistence.search=debug \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-repo-2/src/test/java/com/baeldung/spring/data/persistence/search/StudentApplicationUnitTest.java b/persistence-modules/spring-data-jpa-repo-2/src/test/java/com/baeldung/spring/data/persistence/search/StudentApplicationUnitTest.java new file mode 100644 index 0000000000..ea16b3597d --- /dev/null +++ b/persistence-modules/spring-data-jpa-repo-2/src/test/java/com/baeldung/spring/data/persistence/search/StudentApplicationUnitTest.java @@ -0,0 +1,100 @@ +package com.baeldung.spring.data.persistence.search; + +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; + +import java.util.ArrayList; +import java.util.Comparator; +import java.util.List; +import java.util.Random; +import java.util.stream.Collectors; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.data.domain.Sort; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest +public class StudentApplicationUnitTest { + + @Autowired + private StudentRepository studentRepo; + private List students; + + @Before + public void fillData() { + students = new ArrayList<>(); + int count = 10; + Random r = new Random(); + List scores = r.ints(0, 101) + .distinct() + .limit(count) + .boxed() + .collect(Collectors.toList()); + + for (int i = 0; i < count; i++) { + Integer score = scores.get(i); + Student s = new Student("Student-" + i, score); + students.add(s); + } + + studentRepo.saveAll(students); + Comparator c = Comparator.comparing(a -> a.getScore()); + c = c.reversed(); + students.sort(c); + } + + @After + public void clearData() { + studentRepo.deleteAll(); + } + + @Test + public void givenStudentScores_whenMoreThanOne_thenFindFirst() { + + Student student = studentRepo.findFirstByOrderByScoreDesc(); + Student s = students.get(0); + assertEquals(student, s); + } + + @Test + public void givenStudentScores_whenMoreThan3_thenFindFirstThree() { + + List firstThree = studentRepo.findFirst3ByOrderByScoreDesc(); + List sList = students.subList(0, 3); + assertArrayEquals(firstThree.toArray(), sList.toArray()); + } + + @Test + public void givenStudentScores_whenNameMatches_thenFindFirstStudent() { + + String matchString = "3"; + Student student = studentRepo.findFirstByNameLike("%" + matchString + "%", Sort.by("score") + .descending()); + Student s = students.stream() + .filter(a -> a.getName() + .contains(matchString)) + .findFirst() + .orElse(null); + assertEquals(student, s); + } + + @Test + public void givenStudentScores_whenBetweenRange_thenFindFirstTwoStudents() { + + List topTwoBetweenRange = studentRepo.findFirst2ByScoreBetween(50, 60, Sort.by("score") + .descending()); + List _students = students.stream() + .filter(a -> a.getScore() >= 50 && a.getScore() <= 60) + .limit(2) + .collect(Collectors.toList()); + assertArrayEquals(_students.toArray(), topTwoBetweenRange.toArray()); + } +} From a844943283f4998e8b991850406e2329256e356d Mon Sep 17 00:00:00 2001 From: etrandafir93 <75391049+etrandafir93@users.noreply.github.com> Date: Thu, 19 Jan 2023 09:59:49 +0100 Subject: [PATCH 05/13] BAEL-6058: fixed formatting for line continuation --- .../HeaderInterceptorIntegrationTest.java | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/spring-boot-modules/spring-boot-mvc-5/src/test/java/com/baeldung/requestheader/HeaderInterceptorIntegrationTest.java b/spring-boot-modules/spring-boot-mvc-5/src/test/java/com/baeldung/requestheader/HeaderInterceptorIntegrationTest.java index 9343a608e4..ee053a4c36 100644 --- a/spring-boot-modules/spring-boot-mvc-5/src/test/java/com/baeldung/requestheader/HeaderInterceptorIntegrationTest.java +++ b/spring-boot-modules/spring-boot-mvc-5/src/test/java/com/baeldung/requestheader/HeaderInterceptorIntegrationTest.java @@ -29,15 +29,15 @@ public class HeaderInterceptorIntegrationTest { @BeforeEach public void setup() { this.mockMvc = MockMvcBuilders.webAppContextSetup(this.webApplicationContext) - .build(); + .build(); } @Test public void givenARequestWithOperatorHeader_whenWeCallFooEndpoint_thenOperatorIsExtracted() throws Exception { MockHttpServletResponse response = this.mockMvc.perform(get("/foo").header("operator", "John.Doe")) - .andDo(print()) - .andReturn() - .getResponse(); + .andDo(print()) + .andReturn() + .getResponse(); assertThat(response.getContentAsString()).isEqualTo("hello, John.Doe"); } @@ -45,9 +45,9 @@ public class HeaderInterceptorIntegrationTest { @Test public void givenARequestWithOperatorHeader_whenWeCallBarEndpoint_thenOperatorIsExtracted() throws Exception { MockHttpServletResponse response = this.mockMvc.perform(get("/bar").header("operator", "John.Doe")) - .andDo(print()) - .andReturn() - .getResponse(); + .andDo(print()) + .andReturn() + .getResponse(); assertThat(response.getContentAsString()).isEqualTo("hello, John.Doe"); } @@ -55,11 +55,11 @@ public class HeaderInterceptorIntegrationTest { @Test public void givenARequestWithOperatorHeader_whenWeCallBuzzEndpoint_thenOperatorIsIntercepted() throws Exception { MockHttpServletResponse response = this.mockMvc.perform(get("/buzz").header("operator", "John.Doe")) - .andDo(print()) - .andReturn() - .getResponse(); + .andDo(print()) + .andReturn() + .getResponse(); assertThat(response.getContentAsString()).isEqualTo("hello, John.Doe"); } -} \ No newline at end of file +} From 845ed7690e92bc398bcfdacd0a73e1b3c03a2c70 Mon Sep 17 00:00:00 2001 From: anuragkumawat Date: Thu, 19 Jan 2023 21:30:18 +0530 Subject: [PATCH 06/13] JAVA-16308 Potential issue in Introduction to Spring Data Elasticsearch article (#13286) * JAVA-16308 Potential issue in Introduction to Spring Data Elasticsearch article * JAVA-16308 Update code as per Review Comments --- .../spring/data/es/config/Config.java | 13 ++++------ .../data/es/ElasticSearchManualTest.java | 12 +++++----- .../data/es/ElasticSearchQueryManualTest.java | 24 +++++++++---------- 3 files changed, 22 insertions(+), 27 deletions(-) diff --git a/persistence-modules/spring-data-elasticsearch/src/main/java/com/baeldung/spring/data/es/config/Config.java b/persistence-modules/spring-data-elasticsearch/src/main/java/com/baeldung/spring/data/es/config/Config.java index 51bbe73e9e..7f6653d7a8 100644 --- a/persistence-modules/spring-data-elasticsearch/src/main/java/com/baeldung/spring/data/es/config/Config.java +++ b/persistence-modules/spring-data-elasticsearch/src/main/java/com/baeldung/spring/data/es/config/Config.java @@ -6,17 +6,17 @@ import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.data.elasticsearch.client.ClientConfiguration; import org.springframework.data.elasticsearch.client.RestClients; -import org.springframework.data.elasticsearch.core.ElasticsearchOperations; -import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate; +import org.springframework.data.elasticsearch.config.AbstractElasticsearchConfiguration; import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories; @Configuration @EnableElasticsearchRepositories(basePackages = "com.baeldung.spring.data.es.repository") @ComponentScan(basePackages = { "com.baeldung.spring.data.es.service" }) -public class Config { +public class Config extends AbstractElasticsearchConfiguration { @Bean - RestHighLevelClient client() { + @Override + public RestHighLevelClient elasticsearchClient() { ClientConfiguration clientConfiguration = ClientConfiguration.builder() .connectedTo("localhost:9200") .build(); @@ -24,9 +24,4 @@ public class Config { return RestClients.create(clientConfiguration) .rest(); } - - @Bean - public ElasticsearchOperations elasticsearchTemplate() { - return new ElasticsearchRestTemplate(client()); - } } diff --git a/persistence-modules/spring-data-elasticsearch/src/test/java/com/baeldung/spring/data/es/ElasticSearchManualTest.java b/persistence-modules/spring-data-elasticsearch/src/test/java/com/baeldung/spring/data/es/ElasticSearchManualTest.java index 412cd04e09..cc38acc41c 100644 --- a/persistence-modules/spring-data-elasticsearch/src/test/java/com/baeldung/spring/data/es/ElasticSearchManualTest.java +++ b/persistence-modules/spring-data-elasticsearch/src/test/java/com/baeldung/spring/data/es/ElasticSearchManualTest.java @@ -22,7 +22,7 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; -import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate; +import org.springframework.data.elasticsearch.core.ElasticsearchOperations; import org.springframework.data.elasticsearch.core.SearchHits; import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates; import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder; @@ -41,7 +41,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; public class ElasticSearchManualTest { @Autowired - private ElasticsearchRestTemplate elasticsearchTemplate; + private ElasticsearchOperations elasticsearchOperations; @Autowired private ArticleRepository articleRepository; @@ -117,7 +117,7 @@ public class ElasticSearchManualTest { final Query searchQuery = new NativeSearchQueryBuilder().withFilter(regexpQuery("title", ".*data.*")) .build(); - final SearchHits
articles = elasticsearchTemplate.search(searchQuery, Article.class, IndexCoordinates.of("blog")); + final SearchHits
articles = elasticsearchOperations.search(searchQuery, Article.class, IndexCoordinates.of("blog")); assertEquals(1, articles.getTotalHits()); } @@ -126,7 +126,7 @@ public class ElasticSearchManualTest { public void givenSavedDoc_whenTitleUpdated_thenCouldFindByUpdatedTitle() { final Query searchQuery = new NativeSearchQueryBuilder().withQuery(fuzzyQuery("title", "serch")) .build(); - final SearchHits
articles = elasticsearchTemplate.search(searchQuery, Article.class, IndexCoordinates.of("blog")); + final SearchHits
articles = elasticsearchOperations.search(searchQuery, Article.class, IndexCoordinates.of("blog")); assertEquals(1, articles.getTotalHits()); @@ -147,7 +147,7 @@ public class ElasticSearchManualTest { final Query searchQuery = new NativeSearchQueryBuilder().withQuery(matchQuery("title", articleTitle).minimumShouldMatch("75%")) .build(); - final SearchHits
articles = elasticsearchTemplate.search(searchQuery, Article.class, IndexCoordinates.of("blog")); + final SearchHits
articles = elasticsearchOperations.search(searchQuery, Article.class, IndexCoordinates.of("blog")); assertEquals(1, articles.getTotalHits()); final long count = articleRepository.count(); @@ -162,7 +162,7 @@ public class ElasticSearchManualTest { public void givenSavedDoc_whenOneTermMatches_thenFindByTitle() { final Query searchQuery = new NativeSearchQueryBuilder().withQuery(matchQuery("title", "Search engines").operator(AND)) .build(); - final SearchHits
articles = elasticsearchTemplate.search(searchQuery, Article.class, IndexCoordinates.of("blog")); + final SearchHits
articles = elasticsearchOperations.search(searchQuery, Article.class, IndexCoordinates.of("blog")); assertEquals(1, articles.getTotalHits()); } } diff --git a/persistence-modules/spring-data-elasticsearch/src/test/java/com/baeldung/spring/data/es/ElasticSearchQueryManualTest.java b/persistence-modules/spring-data-elasticsearch/src/test/java/com/baeldung/spring/data/es/ElasticSearchQueryManualTest.java index aaf0c80097..03c8da80c9 100644 --- a/persistence-modules/spring-data-elasticsearch/src/test/java/com/baeldung/spring/data/es/ElasticSearchQueryManualTest.java +++ b/persistence-modules/spring-data-elasticsearch/src/test/java/com/baeldung/spring/data/es/ElasticSearchQueryManualTest.java @@ -39,7 +39,7 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate; +import org.springframework.data.elasticsearch.core.ElasticsearchOperations; import org.springframework.data.elasticsearch.core.SearchHits; import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates; import org.springframework.data.elasticsearch.core.query.NativeSearchQuery; @@ -58,7 +58,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; public class ElasticSearchQueryManualTest { @Autowired - private ElasticsearchRestTemplate elasticsearchTemplate; + private ElasticsearchOperations elasticsearchOperations; @Autowired private ArticleRepository articleRepository; @@ -101,7 +101,7 @@ public class ElasticSearchQueryManualTest { public void givenFullTitle_whenRunMatchQuery_thenDocIsFound() { final NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchQuery("title", "Search engines").operator(Operator.AND)) .build(); - final SearchHits
articles = elasticsearchTemplate.search(searchQuery, Article.class, IndexCoordinates.of("blog")); + final SearchHits
articles = elasticsearchOperations.search(searchQuery, Article.class, IndexCoordinates.of("blog")); assertEquals(1, articles.getTotalHits()); } @@ -110,7 +110,7 @@ public class ElasticSearchQueryManualTest { final NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchQuery("title", "Engines Solutions")) .build(); - final SearchHits
articles = elasticsearchTemplate.search(searchQuery, Article.class, IndexCoordinates.of("blog")); + final SearchHits
articles = elasticsearchOperations.search(searchQuery, Article.class, IndexCoordinates.of("blog")); assertEquals(1, articles.getTotalHits()); assertEquals("Search engines", articles.getSearchHit(0) @@ -123,7 +123,7 @@ public class ElasticSearchQueryManualTest { final NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchQuery("title", "elasticsearch data")) .build(); - final SearchHits
articles = elasticsearchTemplate.search(searchQuery, Article.class, IndexCoordinates.of("blog")); + final SearchHits
articles = elasticsearchOperations.search(searchQuery, Article.class, IndexCoordinates.of("blog")); assertEquals(3, articles.getTotalHits()); } @@ -133,14 +133,14 @@ public class ElasticSearchQueryManualTest { NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchQuery("title.verbatim", "Second Article About Elasticsearch")) .build(); - SearchHits
articles = elasticsearchTemplate.search(searchQuery, Article.class, IndexCoordinates.of("blog")); + SearchHits
articles = elasticsearchOperations.search(searchQuery, Article.class, IndexCoordinates.of("blog")); assertEquals(1, articles.getTotalHits()); searchQuery = new NativeSearchQueryBuilder().withQuery(matchQuery("title.verbatim", "Second Article About")) .build(); - articles = elasticsearchTemplate.search(searchQuery, Article.class, IndexCoordinates.of("blog")); + articles = elasticsearchOperations.search(searchQuery, Article.class, IndexCoordinates.of("blog")); assertEquals(0, articles.getTotalHits()); } @@ -150,7 +150,7 @@ public class ElasticSearchQueryManualTest { final NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(builder) .build(); - final SearchHits
articles = elasticsearchTemplate.search(searchQuery, Article.class, IndexCoordinates.of("blog")); + final SearchHits
articles = elasticsearchOperations.search(searchQuery, Article.class, IndexCoordinates.of("blog")); assertEquals(2, articles.getTotalHits()); } @@ -205,7 +205,7 @@ public class ElasticSearchQueryManualTest { final NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchPhraseQuery("title", "spring elasticsearch").slop(1)) .build(); - final SearchHits
articles = elasticsearchTemplate.search(searchQuery, Article.class, IndexCoordinates.of("blog")); + final SearchHits
articles = elasticsearchOperations.search(searchQuery, Article.class, IndexCoordinates.of("blog")); assertEquals(1, articles.getTotalHits()); } @@ -217,7 +217,7 @@ public class ElasticSearchQueryManualTest { .prefixLength(3)) .build(); - final SearchHits
articles = elasticsearchTemplate.search(searchQuery, Article.class, IndexCoordinates.of("blog")); + final SearchHits
articles = elasticsearchOperations.search(searchQuery, Article.class, IndexCoordinates.of("blog")); assertEquals(1, articles.getTotalHits()); } @@ -229,7 +229,7 @@ public class ElasticSearchQueryManualTest { .type(MultiMatchQueryBuilder.Type.BEST_FIELDS)) .build(); - final SearchHits
articles = elasticsearchTemplate.search(searchQuery, Article.class, IndexCoordinates.of("blog")); + final SearchHits
articles = elasticsearchOperations.search(searchQuery, Article.class, IndexCoordinates.of("blog")); assertEquals(2, articles.getTotalHits()); } @@ -241,7 +241,7 @@ public class ElasticSearchQueryManualTest { final NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(builder) .build(); - final SearchHits
articles = elasticsearchTemplate.search(searchQuery, Article.class, IndexCoordinates.of("blog")); + final SearchHits
articles = elasticsearchOperations.search(searchQuery, Article.class, IndexCoordinates.of("blog")); assertEquals(2, articles.getTotalHits()); } From aa53dde12729407d9999dc42610d9969a73d1125 Mon Sep 17 00:00:00 2001 From: anuragkumawat Date: Thu, 19 Jan 2023 21:36:54 +0530 Subject: [PATCH 07/13] JAVA-14179 Potential issue in Keycloak Integration - OAuth article (#13305) --- .../src/main/resources/application.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/spring-boot-modules/spring-boot-swagger-keycloak/src/main/resources/application.yml b/spring-boot-modules/spring-boot-swagger-keycloak/src/main/resources/application.yml index e4bcdb5888..5d3c8b3af5 100644 --- a/spring-boot-modules/spring-boot-swagger-keycloak/src/main/resources/application.yml +++ b/spring-boot-modules/spring-boot-swagger-keycloak/src/main/resources/application.yml @@ -2,7 +2,6 @@ keycloak: auth-server-url: https://api.example.com/auth # Keycloak server url realm: todos-service-realm # Keycloak Realm resource: todos-service-clients # Keycloak Client - public-client: true principal-attribute: preferred_username ssl-required: external credentials: From edd27fda3ba06dcb11e9e55bb9ec92eb59302056 Mon Sep 17 00:00:00 2001 From: panos-kakos <102670093+panos-kakos@users.noreply.github.com> Date: Thu, 19 Jan 2023 16:21:21 +0000 Subject: [PATCH 08/13] [JAVA-15021] Upgraded to apache httpclient 5.2 (#13309) Co-authored-by: panagiotiskakos --- httpclient-simple/pom.xml | 13 ++ .../httpclient/HttpClientPostingLiveTest.java | 183 +++++++++++------- .../httpclient/ProgressEntityWrapper.java | 4 +- 3 files changed, 125 insertions(+), 75 deletions(-) diff --git a/httpclient-simple/pom.xml b/httpclient-simple/pom.xml index 45da1e7a39..c39983564f 100644 --- a/httpclient-simple/pom.xml +++ b/httpclient-simple/pom.xml @@ -112,6 +112,18 @@ + + + org.apache.httpcomponents.client5 + httpclient5-fluent + ${httpclient5-fluent.version} + + + commons-logging + commons-logging + + + org.apache.commons @@ -308,6 +320,7 @@ 5.2 5.2 + 5.2 1.6.1 diff --git a/httpclient-simple/src/test/java/com/baeldung/httpclient/HttpClientPostingLiveTest.java b/httpclient-simple/src/test/java/com/baeldung/httpclient/HttpClientPostingLiveTest.java index f5dff8d757..b30921c990 100644 --- a/httpclient-simple/src/test/java/com/baeldung/httpclient/HttpClientPostingLiveTest.java +++ b/httpclient-simple/src/test/java/com/baeldung/httpclient/HttpClientPostingLiveTest.java @@ -1,74 +1,88 @@ package com.baeldung.httpclient; -import org.apache.http.HttpEntity; -import org.apache.http.HttpResponse; -import org.apache.http.NameValuePair; -import org.apache.http.auth.AuthenticationException; -import org.apache.http.auth.UsernamePasswordCredentials; -import org.apache.http.client.entity.UrlEncodedFormEntity; -import org.apache.http.client.fluent.Form; -import org.apache.http.client.fluent.Request; -import org.apache.http.client.methods.CloseableHttpResponse; -import org.apache.http.client.methods.HttpPost; -import org.apache.http.entity.ContentType; -import org.apache.http.entity.StringEntity; -import org.apache.http.entity.mime.MultipartEntityBuilder; -import org.apache.http.impl.auth.BasicScheme; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClients; -import org.apache.http.message.BasicNameValuePair; -import org.junit.Test; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; +import static org.junit.jupiter.api.Assertions.assertFalse; + +import org.junit.jupiter.api.Test; + +import org.apache.hc.client5.http.auth.AuthScope; +import org.apache.hc.client5.http.auth.UsernamePasswordCredentials; +import org.apache.hc.client5.http.classic.methods.HttpPost; +import org.apache.hc.client5.http.entity.UrlEncodedFormEntity; +import org.apache.hc.client5.http.entity.mime.MultipartEntityBuilder; +import org.apache.hc.client5.http.fluent.Form; +import org.apache.hc.client5.http.impl.auth.BasicCredentialsProvider; +import org.apache.hc.client5.http.impl.classic.CloseableHttpClient; +import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; +import org.apache.hc.client5.http.impl.classic.HttpClients; +import org.apache.hc.core5.http.ContentType; +import org.apache.hc.core5.http.HttpEntity; +import org.apache.hc.core5.http.HttpResponse; +import org.apache.hc.core5.http.HttpStatus; +import org.apache.hc.core5.http.NameValuePair; +import org.apache.hc.client5.http.fluent.Request; +import org.apache.hc.core5.http.io.entity.StringEntity; +import org.apache.hc.core5.http.message.BasicNameValuePair; import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.List; -import static org.hamcrest.Matchers.equalTo; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertThat; +import com.baeldung.handler.CustomHttpClientResponseHandler; /* * NOTE : Need module spring-rest to be running */ -public class HttpClientPostingLiveTest { +class HttpClientPostingLiveTest { private static final String SAMPLE_URL = "http://www.example.com"; private static final String URL_SECURED_BY_BASIC_AUTHENTICATION = "http://browserspy.dk/password-ok.php"; private static final String DEFAULT_USER = "test"; private static final String DEFAULT_PASS = "test"; @Test - public void whenSendPostRequestUsingHttpClient_thenCorrect() throws IOException { - final CloseableHttpClient client = HttpClients.createDefault(); + void whenSendPostRequestUsingHttpClient_thenCorrect() throws IOException { final HttpPost httpPost = new HttpPost(SAMPLE_URL); - final List params = new ArrayList(); params.add(new BasicNameValuePair("username", DEFAULT_USER)); params.add(new BasicNameValuePair("password", DEFAULT_PASS)); httpPost.setEntity(new UrlEncodedFormEntity(params)); - final CloseableHttpResponse response = client.execute(httpPost); - assertThat(response.getStatusLine().getStatusCode(), equalTo(200)); - client.close(); + try (CloseableHttpClient client = HttpClients.createDefault(); + CloseableHttpResponse response = (CloseableHttpResponse) client + .execute(httpPost, new CustomHttpClientResponseHandler())) { + + final int statusCode = response.getCode(); + assertThat(statusCode, equalTo(HttpStatus.SC_OK)); + } } @Test - public void whenSendPostRequestWithAuthorizationUsingHttpClient_thenCorrect() throws IOException, AuthenticationException { - final CloseableHttpClient client = HttpClients.createDefault(); + void whenSendPostRequestWithAuthorizationUsingHttpClient_thenCorrect() throws IOException { final HttpPost httpPost = new HttpPost(URL_SECURED_BY_BASIC_AUTHENTICATION); - httpPost.setEntity(new StringEntity("test post")); - final UsernamePasswordCredentials creds = new UsernamePasswordCredentials(DEFAULT_USER, DEFAULT_PASS); - httpPost.addHeader(new BasicScheme().authenticate(creds, httpPost, null)); - final CloseableHttpResponse response = client.execute(httpPost); - assertThat(response.getStatusLine().getStatusCode(), equalTo(200)); - client.close(); + final BasicCredentialsProvider credsProvider = new BasicCredentialsProvider(); + final UsernamePasswordCredentials credentials = + new UsernamePasswordCredentials(DEFAULT_USER, DEFAULT_PASS.toCharArray()); + + credsProvider.setCredentials(new AuthScope(URL_SECURED_BY_BASIC_AUTHENTICATION, 80) ,credentials); + + try (CloseableHttpClient client = HttpClients.custom() + .setDefaultCredentialsProvider(credsProvider) + .build(); + + CloseableHttpResponse response = (CloseableHttpResponse) client + .execute(httpPost, new CustomHttpClientResponseHandler())) { + + final int statusCode = response.getCode(); + assertThat(statusCode, equalTo(HttpStatus.SC_OK)); + } } @Test - public void whenPostJsonUsingHttpClient_thenCorrect() throws IOException { - final CloseableHttpClient client = HttpClients.createDefault(); + void whenPostJsonUsingHttpClient_thenCorrect() throws IOException { final HttpPost httpPost = new HttpPost(SAMPLE_URL); final String json = "{\"id\":1,\"name\":\"John\"}"; @@ -77,68 +91,91 @@ public class HttpClientPostingLiveTest { httpPost.setHeader("Accept", "application/json"); httpPost.setHeader("Content-type", "application/json"); - final CloseableHttpResponse response = client.execute(httpPost); - assertThat(response.getStatusLine().getStatusCode(), equalTo(200)); - client.close(); + try (CloseableHttpClient client = HttpClients.createDefault(); + CloseableHttpResponse response = (CloseableHttpResponse) client + .execute(httpPost, new CustomHttpClientResponseHandler())) { + + final int statusCode = response.getCode(); + assertThat(statusCode, equalTo(HttpStatus.SC_OK)); + } } @Test - public void whenPostFormUsingHttpClientFluentAPI_thenCorrect() throws IOException { - final HttpResponse response = Request.Post(SAMPLE_URL).bodyForm(Form.form().add("username", DEFAULT_USER).add("password", DEFAULT_PASS).build()).execute().returnResponse(); + void whenPostFormUsingHttpClientFluentAPI_thenCorrect() throws IOException { + Request request = Request.post(SAMPLE_URL) + .bodyForm(Form.form() + .add("username", DEFAULT_USER) + .add("password", DEFAULT_PASS) + .build()); - assertThat(response.getStatusLine().getStatusCode(), equalTo(200)); + HttpResponse response = request.execute() + .returnResponse(); + assertThat(response.getCode(), equalTo(HttpStatus.SC_OK)); } @Test - public void whenSendMultipartRequestUsingHttpClient_thenCorrect() throws IOException { - final CloseableHttpClient client = HttpClients.createDefault(); + void whenSendMultipartRequestUsingHttpClient_thenCorrect() throws IOException { final HttpPost httpPost = new HttpPost(SAMPLE_URL); final MultipartEntityBuilder builder = MultipartEntityBuilder.create(); builder.addTextBody("username", DEFAULT_USER); builder.addTextBody("password", DEFAULT_PASS); - builder.addBinaryBody("file", new File("src/test/resources/test.in"), ContentType.APPLICATION_OCTET_STREAM, "file.ext"); + builder.addBinaryBody( + "file", new File("src/test/resources/test.in"), ContentType.APPLICATION_OCTET_STREAM, "file.ext"); + + final HttpEntity multipart = builder.build(); + httpPost.setEntity(multipart); + + try (CloseableHttpClient client = HttpClients.createDefault(); + CloseableHttpResponse response = (CloseableHttpResponse) client + .execute(httpPost, new CustomHttpClientResponseHandler())) { + + final int statusCode = response.getCode(); + assertThat(statusCode, equalTo(HttpStatus.SC_OK)); + } + } + + @Test + void whenUploadFileUsingHttpClient_thenCorrect() throws IOException { + final HttpPost httpPost = new HttpPost(SAMPLE_URL); + + final MultipartEntityBuilder builder = MultipartEntityBuilder.create(); + builder.addBinaryBody( + "file", new File("src/test/resources/test.in"), ContentType.APPLICATION_OCTET_STREAM, "file.ext"); final HttpEntity multipart = builder.build(); httpPost.setEntity(multipart); - final CloseableHttpResponse response = client.execute(httpPost); - assertThat(response.getStatusLine().getStatusCode(), equalTo(200)); - client.close(); + try (CloseableHttpClient client = HttpClients.createDefault(); + CloseableHttpResponse response = (CloseableHttpResponse) client + .execute(httpPost, new CustomHttpClientResponseHandler())) { + + final int statusCode = response.getCode(); + assertThat(statusCode, equalTo(HttpStatus.SC_OK)); + } } @Test - public void whenUploadFileUsingHttpClient_thenCorrect() throws IOException { - final CloseableHttpClient client = HttpClients.createDefault(); + void whenGetUploadFileProgressUsingHttpClient_thenCorrect() throws IOException { final HttpPost httpPost = new HttpPost(SAMPLE_URL); final MultipartEntityBuilder builder = MultipartEntityBuilder.create(); - builder.addBinaryBody("file", new File("src/test/resources/test.in"), ContentType.APPLICATION_OCTET_STREAM, "file.ext"); + builder.addBinaryBody( + "file", new File("src/test/resources/test.in"), ContentType.APPLICATION_OCTET_STREAM, "file.ext"); final HttpEntity multipart = builder.build(); - httpPost.setEntity(multipart); - - final CloseableHttpResponse response = client.execute(httpPost); - assertThat(response.getStatusLine().getStatusCode(), equalTo(200)); - client.close(); - } - - @Test - public void whenGetUploadFileProgressUsingHttpClient_thenCorrect() throws IOException { - final CloseableHttpClient client = HttpClients.createDefault(); - final HttpPost httpPost = new HttpPost(SAMPLE_URL); - - final MultipartEntityBuilder builder = MultipartEntityBuilder.create(); - builder.addBinaryBody("file", new File("src/test/resources/test.in"), ContentType.APPLICATION_OCTET_STREAM, "file.ext"); - final HttpEntity multipart = builder.build(); - - final ProgressEntityWrapper.ProgressListener pListener = percentage -> assertFalse(Float.compare(percentage, 100) > 0); + final ProgressEntityWrapper.ProgressListener pListener = + percentage -> assertFalse(Float.compare(percentage, 100) > 0); httpPost.setEntity(new ProgressEntityWrapper(multipart, pListener)); - final CloseableHttpResponse response = client.execute(httpPost); - assertThat(response.getStatusLine().getStatusCode(), equalTo(200)); - client.close(); + try (CloseableHttpClient client = HttpClients.createDefault(); + CloseableHttpResponse response = (CloseableHttpResponse) client + .execute(httpPost, new CustomHttpClientResponseHandler())) { + + final int statusCode = response.getCode(); + assertThat(statusCode, equalTo(HttpStatus.SC_OK)); + } } } \ No newline at end of file diff --git a/httpclient-simple/src/test/java/com/baeldung/httpclient/ProgressEntityWrapper.java b/httpclient-simple/src/test/java/com/baeldung/httpclient/ProgressEntityWrapper.java index c7adf51b3e..0fbc6e5dcd 100644 --- a/httpclient-simple/src/test/java/com/baeldung/httpclient/ProgressEntityWrapper.java +++ b/httpclient-simple/src/test/java/com/baeldung/httpclient/ProgressEntityWrapper.java @@ -4,8 +4,8 @@ import java.io.FilterOutputStream; import java.io.IOException; import java.io.OutputStream; -import org.apache.http.HttpEntity; -import org.apache.http.entity.HttpEntityWrapper; +import org.apache.hc.core5.http.HttpEntity; +import org.apache.hc.core5.http.io.entity.HttpEntityWrapper; public class ProgressEntityWrapper extends HttpEntityWrapper { private final ProgressListener listener; From 947f992d84457c19029378ef3c1594f2ac7dcb02 Mon Sep 17 00:00:00 2001 From: Anastasios Ioannidis <121166333+anastasiosioannidis@users.noreply.github.com> Date: Thu, 19 Jan 2023 19:58:20 +0200 Subject: [PATCH 09/13] JAVA-15609 Fixed failing tests (#13304) --- ....java => ApiControllerDocTesterUnitTest.java} | 6 +++--- ...nTest.java => ApiControllerMockUnitTest.java} | 16 ++++++++-------- 2 files changed, 11 insertions(+), 11 deletions(-) rename web-modules/ninja/src/test/java/controllers/{ApiControllerDocTesterIntegrationTest.java => ApiControllerDocTesterUnitTest.java} (90%) rename web-modules/ninja/src/test/java/controllers/{ApiControllerMockIntegrationTest.java => ApiControllerMockUnitTest.java} (68%) diff --git a/web-modules/ninja/src/test/java/controllers/ApiControllerDocTesterIntegrationTest.java b/web-modules/ninja/src/test/java/controllers/ApiControllerDocTesterUnitTest.java similarity index 90% rename from web-modules/ninja/src/test/java/controllers/ApiControllerDocTesterIntegrationTest.java rename to web-modules/ninja/src/test/java/controllers/ApiControllerDocTesterUnitTest.java index a075497dc8..64812f6935 100644 --- a/web-modules/ninja/src/test/java/controllers/ApiControllerDocTesterIntegrationTest.java +++ b/web-modules/ninja/src/test/java/controllers/ApiControllerDocTesterUnitTest.java @@ -7,11 +7,11 @@ import org.doctester.testbrowser.Response; import org.junit.Test; import ninja.NinjaDocTester; -public class ApiControllerDocTesterIntegrationTest extends NinjaDocTester { +public class ApiControllerDocTesterUnitTest extends NinjaDocTester { String URL_INDEX = "/"; String URL_HELLO = "/hello"; - + @Test public void testGetIndex() { Response response = makeRequest(Request.GET().url(testServerUrl().path(URL_INDEX))); @@ -23,5 +23,5 @@ public class ApiControllerDocTesterIntegrationTest extends NinjaDocTester { Response response = makeRequest(Request.GET().url(testServerUrl().path(URL_HELLO))); assertThat(response.payload, containsString("Bonjour, bienvenue dans Ninja Framework!")); } - + } diff --git a/web-modules/ninja/src/test/java/controllers/ApiControllerMockIntegrationTest.java b/web-modules/ninja/src/test/java/controllers/ApiControllerMockUnitTest.java similarity index 68% rename from web-modules/ninja/src/test/java/controllers/ApiControllerMockIntegrationTest.java rename to web-modules/ninja/src/test/java/controllers/ApiControllerMockUnitTest.java index 53a760aadc..8534fa0b0f 100644 --- a/web-modules/ninja/src/test/java/controllers/ApiControllerMockIntegrationTest.java +++ b/web-modules/ninja/src/test/java/controllers/ApiControllerMockUnitTest.java @@ -1,23 +1,23 @@ package controllers; import static org.junit.Assert.assertEquals; -import javax.inject.Inject; + import org.junit.Before; import org.junit.Test; -import org.junit.runner.RunWith; -import ninja.NinjaRunner; + +import ninja.NinjaTest; import ninja.Result; import services.UserService; -@RunWith(NinjaRunner.class) -public class ApiControllerMockIntegrationTest { +public class ApiControllerMockUnitTest extends NinjaTest { - @Inject private UserService userService; + private UserService userService; - ApplicationController applicationController; + private ApplicationController applicationController; @Before public void setupTest() { + userService = this.ninjaTestServer.getInjector().getInstance(UserService.class); applicationController = new ApplicationController(); applicationController.userService = userService; } @@ -28,5 +28,5 @@ public class ApiControllerMockIntegrationTest { System.out.println(result.getRenderable()); assertEquals(userService.getUserMap().toString(), result.getRenderable().toString()); } - + } From 58069ea225fe025432c4da0443570c66fbb5505a Mon Sep 17 00:00:00 2001 From: Anastasios Ioannidis <121166333+anastasiosioannidis@users.noreply.github.com> Date: Thu, 19 Jan 2023 20:07:14 +0200 Subject: [PATCH 10/13] JAVA-12390 Enabled CORS (#13208) --- .../basicauth/config/BasicAuthConfiguration.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/spring-security-modules/spring-security-web-angular/spring-security-web-angular-server/src/main/java/com/baeldung/springbootsecurityrest/basicauth/config/BasicAuthConfiguration.java b/spring-security-modules/spring-security-web-angular/spring-security-web-angular-server/src/main/java/com/baeldung/springbootsecurityrest/basicauth/config/BasicAuthConfiguration.java index 504dbf63e3..5f4b82a191 100644 --- a/spring-security-modules/spring-security-web-angular/spring-security-web-angular-server/src/main/java/com/baeldung/springbootsecurityrest/basicauth/config/BasicAuthConfiguration.java +++ b/spring-security-modules/spring-security-web-angular/spring-security-web-angular-server/src/main/java/com/baeldung/springbootsecurityrest/basicauth/config/BasicAuthConfiguration.java @@ -1,5 +1,7 @@ package com.baeldung.springbootsecurityrest.basicauth.config; +import static org.springframework.security.config.Customizer.withDefaults; + import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.http.HttpMethod; @@ -27,6 +29,7 @@ public class BasicAuthConfiguration { public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { http.csrf() .disable() + .cors(withDefaults()) .authorizeRequests() .antMatchers(HttpMethod.OPTIONS, "/**") .permitAll() From 1b25127d899fb85b25a3f8b8eb03b110261284eb Mon Sep 17 00:00:00 2001 From: Kapil Khandelwal Date: Fri, 20 Jan 2023 00:24:58 +0530 Subject: [PATCH 11/13] LNX-453:- Prevent Jenkins build from failing when execute shell step fails (#13300) --- .../pipeline-prevent-build-failure-job | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 jenkins-modules/jenkins-jobs/prevent-build-failure-job/pipeline-prevent-build-failure-job diff --git a/jenkins-modules/jenkins-jobs/prevent-build-failure-job/pipeline-prevent-build-failure-job b/jenkins-modules/jenkins-jobs/prevent-build-failure-job/pipeline-prevent-build-failure-job new file mode 100644 index 0000000000..b143f31dc7 --- /dev/null +++ b/jenkins-modules/jenkins-jobs/prevent-build-failure-job/pipeline-prevent-build-failure-job @@ -0,0 +1,16 @@ +pipeline { + agent any + stages { + stage('tryCatch') { + steps { + script { + try { + sh 'test_script.sh' + } catch (e) { + echo "An error occurred: ${e}" + } + } + } + } + } +} From 305b369f5d1fd62c5b9cd5ee651ff9e60f1c9327 Mon Sep 17 00:00:00 2001 From: Iniubong LA Date: Thu, 19 Jan 2023 19:03:51 +0000 Subject: [PATCH 12/13] arthurshur@gmail.com (#13275) * Creating a deep vs shallow copy of an object in Java * Creating a deep vs shallow copy of an object in Java * Baeldung article converting number bases * Baeldung article converting number bases * edits made to Converting a Number from One Base to Another in Java * added braces to oneliners * added precondition to check input --- .../ConvertNumberBases.java | 52 +++++++++++-------- .../ConvertNumberBasesUnitTest.java | 12 +++++ 2 files changed, 42 insertions(+), 22 deletions(-) diff --git a/core-java-modules/core-java-lang-5/src/main/java/com/baeldung/convertnumberbases/ConvertNumberBases.java b/core-java-modules/core-java-lang-5/src/main/java/com/baeldung/convertnumberbases/ConvertNumberBases.java index 405504a965..09b880cd19 100644 --- a/core-java-modules/core-java-lang-5/src/main/java/com/baeldung/convertnumberbases/ConvertNumberBases.java +++ b/core-java-modules/core-java-lang-5/src/main/java/com/baeldung/convertnumberbases/ConvertNumberBases.java @@ -2,68 +2,76 @@ package com.baeldung.convertnumberbases; public class ConvertNumberBases { - public static String convertNumberToNewBase(String number, int base, int newBase){ + public static String convertNumberToNewBase(String number, int base, int newBase) { return Integer.toString(Integer.parseInt(number, base), newBase); } + public static String convertNumberToNewBaseCustom(String num, int base, int newBase) { int decimalNumber = convertFromAnyBaseToDecimal(num, base); - return convertFromDecimalToBaseX(decimalNumber, newBase); + String targetBase = ""; + try { + targetBase = convertFromDecimalToBaseX(decimalNumber, newBase); + } catch (IllegalArgumentException e) { + e.printStackTrace(); + } + return targetBase; } - public static String convertFromDecimalToBaseX(int num, int newBase) { + public static String convertFromDecimalToBaseX(int num, int newBase) throws IllegalArgumentException { + if ((newBase < 2 || newBase > 10) && newBase != 16) { + throw new IllegalArgumentException("New base must be from 2 - 10 or 16"); + } String result = ""; int remainder; while (num > 0) { remainder = num % newBase; if (newBase == 16) { - if (remainder == 10) + if (remainder == 10) { result += 'A'; - else if (remainder == 11) + } else if (remainder == 11) { result += 'B'; - else if (remainder == 12) + } else if (remainder == 12) { result += 'C'; - else if (remainder == 13) + } else if (remainder == 13) { result += 'D'; - else if (remainder == 14) + } else if (remainder == 14) { result += 'E'; - else if (remainder == 15) + } else if (remainder == 15) { result += 'F'; - else + } else { result += remainder; - } else + } + } else { result += remainder; - + } num /= newBase; } return new StringBuffer(result).reverse().toString(); } public static int convertFromAnyBaseToDecimal(String num, int base) { - - if (base < 2 || (base > 10 && base != 16)) + if (base < 2 || (base > 10 && base != 16)) { return -1; - + } int val = 0; int power = 1; - for (int i = num.length() - 1; i >= 0; i--) { int digit = charToDecimal(num.charAt(i)); - - if (digit < 0 || digit >= base) + if (digit < 0 || digit >= base) { return -1; - + } val += digit * power; power = power * base; } - return val; } public static int charToDecimal(char c) { - if (c >= '0' && c <= '9') + if (c >= '0' && c <= '9') { return (int) c - '0'; - else + } else { return (int) c - 'A' + 10; + } } } diff --git a/core-java-modules/core-java-lang-5/src/test/java/com/baeldung/convertnumberbases/ConvertNumberBasesUnitTest.java b/core-java-modules/core-java-lang-5/src/test/java/com/baeldung/convertnumberbases/ConvertNumberBasesUnitTest.java index 109e1da1b2..a666346b1a 100644 --- a/core-java-modules/core-java-lang-5/src/test/java/com/baeldung/convertnumberbases/ConvertNumberBasesUnitTest.java +++ b/core-java-modules/core-java-lang-5/src/test/java/com/baeldung/convertnumberbases/ConvertNumberBasesUnitTest.java @@ -1,5 +1,6 @@ package com.baeldung.convertnumberbases; +import static com.baeldung.convertnumberbases.ConvertNumberBases.convertFromDecimalToBaseX; import static com.baeldung.convertnumberbases.ConvertNumberBases.convertNumberToNewBase; import static com.baeldung.convertnumberbases.ConvertNumberBases.convertNumberToNewBaseCustom; import static org.junit.jupiter.api.Assertions.*; @@ -17,4 +18,15 @@ class ConvertNumberBasesUnitTest { assertEquals(convertNumberToNewBaseCustom("11001000", 2, 8), "310"); } + @Test + void whenInputIsOutOfRange_thenIllegalArgumentExceptionIsThrown() { + Exception exception = assertThrows(IllegalArgumentException.class, ()-> { + convertFromDecimalToBaseX(100, 12); + }); + String expectedMessage = "New base must be from 2 - 10 or 16"; + String actualMessage = exception.getMessage(); + + assertTrue(actualMessage.contains(expectedMessage)); + } + } \ No newline at end of file From cf5eeaa1765bf4b22f1593d7ba0d6b78360ac4ba Mon Sep 17 00:00:00 2001 From: Dhawal Kapil Date: Fri, 20 Jan 2023 07:39:27 +0530 Subject: [PATCH 13/13] Updated Readme to include info on building modules from the root (#13312) --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index 1ae225b1f3..aecd561645 100644 --- a/README.md +++ b/README.md @@ -72,6 +72,13 @@ Building a single module To build a specific module, run the command: `mvn clean install` in the module directory. +Building modules from the root of the repository +==================== +To build specific modules from the root of the repository, run the command: `mvn clean install --pl asm,atomikos -Pdefault-first` in the root directory. + +Here `asm` and `atomikos` are the modules that we want to build and `default-first` is the maven profile in which these modules are present. + + Running a Spring Boot module ==================== To run a Spring Boot module, run the command: `mvn spring-boot:run` in the module directory.