From 24833b7e92ef4511f50d94a5e4f865f5b60d3002 Mon Sep 17 00:00:00 2001 From: "alex.peptan" Date: Mon, 13 Apr 2020 17:23:23 +0300 Subject: [PATCH 001/140] BAEL-3896: OpenAPI JSON Objects in Query Params --- spring-rest-http/README.md | 1 + .../jsonparam/JsonParamController.java | 55 +++++++++++++++++++ .../baeldung/jsonparam/ParamObjectDTO.java | 33 +++++++++++ 3 files changed, 89 insertions(+) create mode 100644 spring-rest-http/src/main/java/com/baeldung/jsonparam/JsonParamController.java create mode 100644 spring-rest-http/src/main/java/com/baeldung/jsonparam/ParamObjectDTO.java diff --git a/spring-rest-http/README.md b/spring-rest-http/README.md index 35793cb281..cba017eb74 100644 --- a/spring-rest-http/README.md +++ b/spring-rest-http/README.md @@ -13,3 +13,4 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [Spring RequestMapping](https://www.baeldung.com/spring-requestmapping) - [Guide to DeferredResult in Spring](https://www.baeldung.com/spring-deferred-result) - [Using JSON Patch in Spring REST APIs](https://www.baeldung.com/spring-rest-json-patch) +- [OpenAPI JSON Objects in Query Params](https://www.baeldung.com/openapi-json-objects-in-query-params) diff --git a/spring-rest-http/src/main/java/com/baeldung/jsonparam/JsonParamController.java b/spring-rest-http/src/main/java/com/baeldung/jsonparam/JsonParamController.java new file mode 100644 index 0000000000..60797cf104 --- /dev/null +++ b/spring-rest-http/src/main/java/com/baeldung/jsonparam/JsonParamController.java @@ -0,0 +1,55 @@ +package com.baeldung.jsonparam; + +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.*; + +import java.io.IOException; + +@Controller +@RestController +@RequestMapping("/api") +public class JsonParamController { + + @GetMapping(value = "/something") + public String testQueryParamApi(@RequestParam("params") String params) { + // params={"type":"foo","color":"green"} + ParamObjectDTO paramObjectDTO; + ObjectMapper objectMapper = new ObjectMapper(); + try { + paramObjectDTO = objectMapper.readValue(params, ParamObjectDTO.class); + System.out.println(paramObjectDTO); + // use paramObjectDTO where you have {"type":"foo","color":"green"} JSON data as Object + } catch (JsonParseException e) { + e.printStackTrace(); + } catch (JsonMappingException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + return params; + } + + + @PostMapping(value = "/something") + public String testBodyParamApi(@RequestBody String params) { + // params={"type":"foo","color":"green"} + ParamObjectDTO paramObjectDTO; + ObjectMapper objectMapper = new ObjectMapper(); + try { + paramObjectDTO = objectMapper.readValue(params, ParamObjectDTO.class); + System.out.println(paramObjectDTO); + // use paramObjectDTO where you have {"type":"foo","color":"green"} JSON data as Object + } catch (JsonParseException e) { + e.printStackTrace(); + } catch (JsonMappingException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + return params; + } + +} diff --git a/spring-rest-http/src/main/java/com/baeldung/jsonparam/ParamObjectDTO.java b/spring-rest-http/src/main/java/com/baeldung/jsonparam/ParamObjectDTO.java new file mode 100644 index 0000000000..a738180fa6 --- /dev/null +++ b/spring-rest-http/src/main/java/com/baeldung/jsonparam/ParamObjectDTO.java @@ -0,0 +1,33 @@ +package com.baeldung.jsonparam; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; + +@JsonIgnoreProperties(ignoreUnknown = true) +public class ParamObjectDTO { + private String type; + private String color; + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getColor() { + return color; + } + + public void setColor(String color) { + this.color = color; + } + + @Override + public String toString() { + return "ParamObjectDTO{" + + "type='" + type + '\'' + + ", color='" + color + '\'' + + '}'; + } +} From f0bdbde7a4634cee6e6575a785234674eb12ddf8 Mon Sep 17 00:00:00 2001 From: "alex.peptan" Date: Tue, 21 Apr 2020 19:05:42 +0300 Subject: [PATCH 002/140] BAEL-3896: OpenAPI JSON Objects in Query Params v2 --- .../jsonparam/JsonParamController.java | 43 +++++++++++-------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/spring-rest-http/src/main/java/com/baeldung/jsonparam/JsonParamController.java b/spring-rest-http/src/main/java/com/baeldung/jsonparam/JsonParamController.java index 60797cf104..d2a09296c2 100644 --- a/spring-rest-http/src/main/java/com/baeldung/jsonparam/JsonParamController.java +++ b/spring-rest-http/src/main/java/com/baeldung/jsonparam/JsonParamController.java @@ -1,19 +1,20 @@ package com.baeldung.jsonparam; -import com.fasterxml.jackson.core.JsonParseException; -import com.fasterxml.jackson.databind.JsonMappingException; +import com.baeldung.controllers.DeferredResultController; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.*; -import java.io.IOException; - @Controller @RestController @RequestMapping("/api") public class JsonParamController { + private final static Logger LOG = LoggerFactory.getLogger(DeferredResultController.class); - @GetMapping(value = "/something") + @GetMapping(value = "/tickets") public String testQueryParamApi(@RequestParam("params") String params) { // params={"type":"foo","color":"green"} ParamObjectDTO paramObjectDTO; @@ -22,18 +23,28 @@ public class JsonParamController { paramObjectDTO = objectMapper.readValue(params, ParamObjectDTO.class); System.out.println(paramObjectDTO); // use paramObjectDTO where you have {"type":"foo","color":"green"} JSON data as Object - } catch (JsonParseException e) { - e.printStackTrace(); - } catch (JsonMappingException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); + } catch (JsonProcessingException e) { + LOG.info("Json Processing Exception"); } return params; } + @GetMapping(value = "/tickets2") + public String testGetBodyParamApi(@RequestBody String params) { + // params={"type":"foo","color":"green"} + ParamObjectDTO paramObjectDTO; + ObjectMapper objectMapper = new ObjectMapper(); + try { + paramObjectDTO = objectMapper.readValue(params, ParamObjectDTO.class); + System.out.println(paramObjectDTO); + // use paramObjectDTO where you have {"type":"foo","color":"green"} JSON data as Object + } catch (JsonProcessingException e) { + LOG.info("Json Processing Exception"); + } + return params; + } - @PostMapping(value = "/something") + @PostMapping(value = "/tickets") public String testBodyParamApi(@RequestBody String params) { // params={"type":"foo","color":"green"} ParamObjectDTO paramObjectDTO; @@ -42,12 +53,8 @@ public class JsonParamController { paramObjectDTO = objectMapper.readValue(params, ParamObjectDTO.class); System.out.println(paramObjectDTO); // use paramObjectDTO where you have {"type":"foo","color":"green"} JSON data as Object - } catch (JsonParseException e) { - e.printStackTrace(); - } catch (JsonMappingException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); + } catch (JsonProcessingException e) { + LOG.info("Json Processing Exception"); } return params; } From 7241496289f39ec18a381d76c6747f09fb28ad0a Mon Sep 17 00:00:00 2001 From: Thomas Turrell-Croft Date: Mon, 27 Apr 2020 18:44:09 +0200 Subject: [PATCH 003/140] Fix controllers to use Post/Redirect/Get Forms should use Post/Redirect/Get pattern. --- .../java/com/baeldung/crud/controllers/UserController.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spring-boot-modules/spring-boot-crud/src/main/java/com/baeldung/crud/controllers/UserController.java b/spring-boot-modules/spring-boot-crud/src/main/java/com/baeldung/crud/controllers/UserController.java index 726be6a384..8a7ef96f1e 100644 --- a/spring-boot-modules/spring-boot-crud/src/main/java/com/baeldung/crud/controllers/UserController.java +++ b/spring-boot-modules/spring-boot-crud/src/main/java/com/baeldung/crud/controllers/UserController.java @@ -36,7 +36,7 @@ public class UserController { userRepository.save(user); model.addAttribute("users", userRepository.findAll()); - return "index"; + return "redirect:/index"; } @GetMapping("/edit/{id}") @@ -55,7 +55,7 @@ public class UserController { userRepository.save(user); model.addAttribute("users", userRepository.findAll()); - return "index"; + return "redirect:/index"; } @GetMapping("/delete/{id}") From 1077dc82a5575bf5dc856016c6f0a32c4ab475a9 Mon Sep 17 00:00:00 2001 From: Thomas Turrell-Croft Date: Tue, 28 Apr 2020 10:54:49 +0200 Subject: [PATCH 004/140] Fix tests to check for forward to index --- .../test/java/com/baeldung/crud/UserControllerUnitTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spring-boot-modules/spring-boot-crud/src/test/java/com/baeldung/crud/UserControllerUnitTest.java b/spring-boot-modules/spring-boot-crud/src/test/java/com/baeldung/crud/UserControllerUnitTest.java index 033108c195..f1455f7a73 100644 --- a/spring-boot-modules/spring-boot-crud/src/test/java/com/baeldung/crud/UserControllerUnitTest.java +++ b/spring-boot-modules/spring-boot-crud/src/test/java/com/baeldung/crud/UserControllerUnitTest.java @@ -41,7 +41,7 @@ public class UserControllerUnitTest { when(mockedBindingResult.hasErrors()).thenReturn(false); - assertThat(userController.addUser(user, mockedBindingResult, mockedModel)).isEqualTo("index"); + assertThat(userController.addUser(user, mockedBindingResult, mockedModel)).isEqualTo("redirect:/index"); } @Test @@ -64,7 +64,7 @@ public class UserControllerUnitTest { when(mockedBindingResult.hasErrors()).thenReturn(false); - assertThat(userController.updateUser(1l, user, mockedBindingResult, mockedModel)).isEqualTo("index"); + assertThat(userController.updateUser(1l, user, mockedBindingResult, mockedModel)).isEqualTo("redirect:/index"); } @Test From a6fc46e3f6ed643215ae21ca28d22b095c4a839c Mon Sep 17 00:00:00 2001 From: Gergo Petrik Date: Mon, 4 May 2020 16:40:20 +0200 Subject: [PATCH 005/140] ABA problem in concurrency --- .../java/com/baeldung/abaproblem/Account.java | 34 +++++++ .../baeldung/abaproblem/AccountUnitTest.java | 93 +++++++++++++++++++ 2 files changed, 127 insertions(+) create mode 100644 core-java-modules/core-java-concurrency-advanced-3/src/main/java/com/baeldung/abaproblem/Account.java create mode 100644 core-java-modules/core-java-concurrency-advanced-3/src/test/java/com/baeldung/abaproblem/AccountUnitTest.java diff --git a/core-java-modules/core-java-concurrency-advanced-3/src/main/java/com/baeldung/abaproblem/Account.java b/core-java-modules/core-java-concurrency-advanced-3/src/main/java/com/baeldung/abaproblem/Account.java new file mode 100644 index 0000000000..0204c31fea --- /dev/null +++ b/core-java-modules/core-java-concurrency-advanced-3/src/main/java/com/baeldung/abaproblem/Account.java @@ -0,0 +1,34 @@ +package com.baeldung.abaproblem; + +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicInteger; + +public class Account { + + private AtomicInteger balance = new AtomicInteger(0); + + public int getBalance() { + return balance.get(); + } + + public boolean withdraw(int amount) throws InterruptedException { + int current = getBalance(); + if (current < amount) { + throw new RuntimeException("Not sufficient balance"); + } + precessBalance(); + return balance.compareAndSet(current, current - amount); + } + + private void precessBalance() throws InterruptedException { + if ("thread 1".equals(Thread.currentThread().getName())) { + TimeUnit.SECONDS.sleep(2); + } + } + + public boolean deposit(int amount) { + int current = balance.get(); + return balance.compareAndSet(current, current + amount); + } + +} diff --git a/core-java-modules/core-java-concurrency-advanced-3/src/test/java/com/baeldung/abaproblem/AccountUnitTest.java b/core-java-modules/core-java-concurrency-advanced-3/src/test/java/com/baeldung/abaproblem/AccountUnitTest.java new file mode 100644 index 0000000000..ab88a0f447 --- /dev/null +++ b/core-java-modules/core-java-concurrency-advanced-3/src/test/java/com/baeldung/abaproblem/AccountUnitTest.java @@ -0,0 +1,93 @@ +package com.baeldung.abaproblem; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class AccountUnitTest { + + private Account account; + + @BeforeEach + public void setUp() { + account = new Account(); + } + + @Test + public void zeroBalanceInitializationTest() { + assertEquals(0, account.getBalance()); + } + + @Test + public void depositTest() { + final int moneyToDeposit = 50; + + assertTrue(account.deposit(moneyToDeposit)); + + assertEquals(moneyToDeposit, account.getBalance()); + } + + @Test + public void withdrawTest() throws InterruptedException { + final int defaultBalance = 50; + final int moneyToWithdraw = 20; + + account.deposit(defaultBalance); + + assertTrue(account.withdraw(moneyToWithdraw)); + + assertEquals(defaultBalance - moneyToWithdraw, account.getBalance()); + } + + @Test + public void withdrawWithoutSufficientBalanceTest() { + assertThrows(RuntimeException.class, () -> account.withdraw(10)); + } + + @Test + public void abaProblemTest() throws InterruptedException { + final int defaultBalance = 50; + + final int amountToWithdrawByThreadA = 20; + final int amountToWithdrawByThreadB = 10; + final int amountToDepositByThreadB = 10; + + account.deposit(defaultBalance); + + Thread threadA = new Thread(() -> { + try { + // this will take longer due to the name of the thread + assertTrue(account.withdraw(amountToWithdrawByThreadA)); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + }, "tread 1"); + + Thread threadB = new Thread(() -> { + + assertTrue(account.deposit(amountToDepositByThreadB)); + assertEquals(defaultBalance + amountToDepositByThreadB, account.getBalance()); + try { + // this will be fast due to the name of the thread + assertTrue(account.withdraw(amountToWithdrawByThreadB)); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + + // thread 1 didn't finish yet, so the original value will be in place for it + assertEquals(defaultBalance, account.getBalance()); + + }, "thread 2"); + + threadA.start(); + threadB.start(); + threadA.join(); + threadB.join(); + + // compareAndSet operation succeeds for thread 1 + assertEquals(defaultBalance - amountToWithdrawByThreadA, account.getBalance()); + } +} From 68dc88528e488db5aef951d8578bcfb33c46cd81 Mon Sep 17 00:00:00 2001 From: Gergo Petrik Date: Thu, 7 May 2020 11:45:40 +0200 Subject: [PATCH 006/140] added transaction recording --- .../java/com/baeldung/abaproblem/Account.java | 21 ++++++++++++++++--- .../baeldung/abaproblem/AccountUnitTest.java | 14 +++++++++++-- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/core-java-modules/core-java-concurrency-advanced-3/src/main/java/com/baeldung/abaproblem/Account.java b/core-java-modules/core-java-concurrency-advanced-3/src/main/java/com/baeldung/abaproblem/Account.java index 0204c31fea..558245283a 100644 --- a/core-java-modules/core-java-concurrency-advanced-3/src/main/java/com/baeldung/abaproblem/Account.java +++ b/core-java-modules/core-java-concurrency-advanced-3/src/main/java/com/baeldung/abaproblem/Account.java @@ -1,34 +1,49 @@ package com.baeldung.abaproblem; +import java.util.ArrayList; +import java.util.List; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; public class Account { private AtomicInteger balance = new AtomicInteger(0); + private List transactionDates = new ArrayList<>(); public int getBalance() { return balance.get(); } + public List getTransactionDates() { + return transactionDates; + } + public boolean withdraw(int amount) throws InterruptedException { int current = getBalance(); if (current < amount) { throw new RuntimeException("Not sufficient balance"); } precessBalance(); - return balance.compareAndSet(current, current - amount); + boolean result = balance.compareAndSet(current, current - amount); + if (result) { + transactionDates.add(System.currentTimeMillis()); + } + return result; } private void precessBalance() throws InterruptedException { - if ("thread 1".equals(Thread.currentThread().getName())) { + if ("thread1".equals(Thread.currentThread().getName())) { TimeUnit.SECONDS.sleep(2); } } public boolean deposit(int amount) { int current = balance.get(); - return balance.compareAndSet(current, current + amount); + boolean result = balance.compareAndSet(current, current + amount); + if (result) { + transactionDates.add(System.currentTimeMillis()); + } + return result; } } diff --git a/core-java-modules/core-java-concurrency-advanced-3/src/test/java/com/baeldung/abaproblem/AccountUnitTest.java b/core-java-modules/core-java-concurrency-advanced-3/src/test/java/com/baeldung/abaproblem/AccountUnitTest.java index ab88a0f447..457580b96c 100644 --- a/core-java-modules/core-java-concurrency-advanced-3/src/test/java/com/baeldung/abaproblem/AccountUnitTest.java +++ b/core-java-modules/core-java-concurrency-advanced-3/src/test/java/com/baeldung/abaproblem/AccountUnitTest.java @@ -4,6 +4,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -19,6 +20,7 @@ public class AccountUnitTest { @Test public void zeroBalanceInitializationTest() { assertEquals(0, account.getBalance()); + assertTrue(account.getTransactionDates().isEmpty()); } @Test @@ -55,7 +57,9 @@ public class AccountUnitTest { final int amountToWithdrawByThreadB = 10; final int amountToDepositByThreadB = 10; + assertTrue(account.getTransactionDates().isEmpty()); account.deposit(defaultBalance); + assertEquals(1, account.getTransactionDates().size()); Thread threadA = new Thread(() -> { try { @@ -64,7 +68,7 @@ public class AccountUnitTest { } catch (InterruptedException e) { throw new RuntimeException(e); } - }, "tread 1"); + }, "thread1"); Thread threadB = new Thread(() -> { @@ -80,7 +84,7 @@ public class AccountUnitTest { // thread 1 didn't finish yet, so the original value will be in place for it assertEquals(defaultBalance, account.getBalance()); - }, "thread 2"); + }, "thread2"); threadA.start(); threadB.start(); @@ -89,5 +93,11 @@ public class AccountUnitTest { // compareAndSet operation succeeds for thread 1 assertEquals(defaultBalance - amountToWithdrawByThreadA, account.getBalance()); + + //but there are other transactions + assertNotEquals(2, account.getTransactionDates().size()); + + // thread 2 did two modifications as well + assertEquals(4, account.getTransactionDates().size()); } } From 69c50660de908d542a87bb2f9ca3896ba7c3f5ca Mon Sep 17 00:00:00 2001 From: Justin Albano Date: Sun, 10 May 2020 09:47:28 -0400 Subject: [PATCH 007/140] BAEL-3951: Added JDK 14 record example and associated tests. --- .../com/baeldung/java14/record/Person.java | 22 +++ .../baeldung/java14/record/PersonTest.java | 150 ++++++++++++++++++ 2 files changed, 172 insertions(+) create mode 100644 core-java-modules/core-java-14/src/main/java/com/baeldung/java14/record/Person.java create mode 100644 core-java-modules/core-java-14/src/test/java/com/baeldung/java14/record/PersonTest.java diff --git a/core-java-modules/core-java-14/src/main/java/com/baeldung/java14/record/Person.java b/core-java-modules/core-java-14/src/main/java/com/baeldung/java14/record/Person.java new file mode 100644 index 0000000000..33243c4ecf --- /dev/null +++ b/core-java-modules/core-java-14/src/main/java/com/baeldung/java14/record/Person.java @@ -0,0 +1,22 @@ +package com.baeldung.java14.record; + +import java.util.Objects; + +public record Person (String name, String address) { + + public static String UNKWOWN_ADDRESS = "Unknown"; + public static String UNNAMED = "Unnamed"; + + public Person { + Objects.requireNonNull(name); + Objects.requireNonNull(address); + } + + public Person(String name) { + this(name, UNKWOWN_ADDRESS); + } + + public static Person unnamed(String address) { + return new Person(UNNAMED, address); + } +} diff --git a/core-java-modules/core-java-14/src/test/java/com/baeldung/java14/record/PersonTest.java b/core-java-modules/core-java-14/src/test/java/com/baeldung/java14/record/PersonTest.java new file mode 100644 index 0000000000..4a7d4ede5f --- /dev/null +++ b/core-java-modules/core-java-14/src/test/java/com/baeldung/java14/record/PersonTest.java @@ -0,0 +1,150 @@ +package com.baeldung.java14.record; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +public class PersonTest { + + @Test + public void givenSameNameAndAddress_whenEquals_thenPersonsEqual() { + + String name = "John Doe"; + String address = "100 Linda Ln."; + + Person person1 = new Person(name, address); + Person person2 = new Person(name, address); + + assertTrue(person1.equals(person2)); + } + + @Test + public void givenDifferentObject_whenEquals_thenNotEqual() { + + Person person = new Person("John Doe", "100 Linda Ln."); + + assertFalse(person.equals(new Object())); + } + + @Test + public void givenDifferentName_whenEquals_thenPersonsNotEqual() { + + String address = "100 Linda Ln."; + + Person person1 = new Person("Jane Doe", address); + Person person2 = new Person("John Doe", address); + + assertFalse(person1.equals(person2)); + } + + @Test + public void givenDifferentAddress_whenEquals_thenPersonsNotEqual() { + + String name = "John Doe"; + + Person person1 = new Person(name, "100 Linda Ln."); + Person person2 = new Person(name, "200 London Ave."); + + assertFalse(person1.equals(person2)); + } + + @Test + public void givenSameNameAndAddress_whenHashCode_thenPersonsEqual() { + + String name = "John Doe"; + String address = "100 Linda Ln."; + + Person person1 = new Person(name, address); + Person person2 = new Person(name, address); + + assertEquals(person1.hashCode(), person2.hashCode()); + } + + @Test + public void givenDifferentObject_whenHashCode_thenNotEqual() { + + Person person = new Person("John Doe", "100 Linda Ln."); + + assertNotEquals(person.hashCode(), new Object().hashCode()); + } + + @Test + public void givenDifferentName_whenHashCode_thenPersonsNotEqual() { + + String address = "100 Linda Ln."; + + Person person1 = new Person("Jane Doe", address); + Person person2 = new Person("John Doe", address); + + assertNotEquals(person1.hashCode(), person2.hashCode()); + } + + @Test + public void givenDifferentAddress_whenHashCode_thenPersonsNotEqual() { + + String name = "John Doe"; + + Person person1 = new Person(name, "100 Linda Ln."); + Person person2 = new Person(name, "200 London Ave."); + + assertNotEquals(person1.hashCode(), person2.hashCode()); + } + + @Test + public void givenValidNameAndAddress_whenGetNameAndAddress_thenExpectedValuesReturned() { + + String name = "John Doe"; + String address = "100 Linda Ln."; + + Person person = new Person(name, address); + + assertEquals(name, person.name()); + assertEquals(address, person.address()); + } + + @Test + public void givenValidNameAndAddress_whenToString_thenCorrectStringReturned() { + + String name = "John Doe"; + String address = "100 Linda Ln."; + + Person person = new Person(name, address); + + assertEquals("Person[name=" + name + ", address=" + address + "]", person.toString()); + } + + @Test(expected = NullPointerException.class) + public void givenNullName_whenConstruct_thenErrorThrown() { + new Person(null, "100 Linda Ln."); + } + + @Test(expected = NullPointerException.class) + public void givenNullAddress_whenConstruct_thenErrorThrown() { + new Person("John Doe", null); + } + + @Test + public void givenUnknownAddress_whenConstructing_thenAddressPopulated() { + + String name = "John Doe"; + + Person person = new Person(name); + + assertEquals(name, person.name()); + assertEquals(Person.UNKWOWN_ADDRESS, person.address()); + } + + @Test + public void givenUnnamed_whenConstructingThroughFactory_thenNamePopulated() { + + String address = "100 Linda Ln."; + + Person person = Person.unnamed(address); + + assertEquals(Person.UNNAMED, person.name()); + assertEquals(address, person.address()); + } +} From 4f7b0d6a645625d115293133f48eb993a6d7b733 Mon Sep 17 00:00:00 2001 From: Michele Guarnaccia Date: Sun, 10 May 2020 18:40:27 +0200 Subject: [PATCH 008/140] First commit --- persistence-modules/spring-data-jpa-5/pom.xml | 58 +++++++++++++++++++ .../main/java/com/baeldung/Application.java | 58 +++++++++++++++++++ .../java/com/baeldung/model/Customer.java | 27 +++++++++ .../java/com/baeldung/model/CustomerDto.java | 34 +++++++++++ .../repository/CustomerRepository.java | 13 +++++ .../com/baeldung/service/CustomerService.java | 50 ++++++++++++++++ .../com/baeldung/util/CustomerMapper.java | 15 +++++ 7 files changed, 255 insertions(+) create mode 100644 persistence-modules/spring-data-jpa-5/pom.xml create mode 100644 persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/Application.java create mode 100644 persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/model/Customer.java create mode 100644 persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/model/CustomerDto.java create mode 100644 persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/repository/CustomerRepository.java create mode 100644 persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/service/CustomerService.java create mode 100644 persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/util/CustomerMapper.java diff --git a/persistence-modules/spring-data-jpa-5/pom.xml b/persistence-modules/spring-data-jpa-5/pom.xml new file mode 100644 index 0000000000..df1cc6c0c4 --- /dev/null +++ b/persistence-modules/spring-data-jpa-5/pom.xml @@ -0,0 +1,58 @@ + + + 4.0.0 + spring-data-jpa-5 + spring-data-jpa-5 + + + com.baeldung + parent-boot-2 + 0.0.1-SNAPSHOT + ../../parent-boot-2 + + + + + org.springframework.boot + spring-boot-starter-data-jpa + + + com.h2database + h2 + + + org.mapstruct + mapstruct-jdk8 + 1.3.1.Final + provided + + + org.springframework.boot + spring-boot-starter-cache + + + + + src/main/java + + + maven-compiler-plugin + 3.8.1 + + 1.8 + 1.8 + + + org.mapstruct + mapstruct-processor + 1.3.1.Final + + + + + + + \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/Application.java b/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/Application.java new file mode 100644 index 0000000000..64d0a5e6c6 --- /dev/null +++ b/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/Application.java @@ -0,0 +1,58 @@ +package com.baeldung; + +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.CommandLineRunner; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cache.CacheManager; +import org.springframework.cache.annotation.EnableCaching; +import org.springframework.context.ApplicationContext; +import org.springframework.context.annotation.Bean; + +import com.baeldung.model.Customer; +import com.baeldung.model.CustomerDto; +import com.baeldung.service.CustomerService; + +@SpringBootApplication @EnableCaching +public class Application { + + @Autowired CustomerService service; + @Autowired CacheManager cacheManager; + private static final org.slf4j.Logger logger = LoggerFactory.getLogger(Application.class); + + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } + + @Bean public CommandLineRunner commandLineRunner(ApplicationContext ctx) throws Exception { + logger.info("-- BASIC LOAD AND SAVE --"); + basicLoadAndSave(); + logger.info("-- BASIC LOAD AND SAVE + MAPPER --"); + basicLoadAndSaveWithMapper(); + return null; + } + + private void basicLoadAndSave() { + Customer myCustomer = service.addCustomer("John", "Doe"); + logger.info("Insert -- " + myCustomer.toString()); + myCustomer = service.updateCustomer(myCustomer.id, "john@doe.com", "+00", "Route 66"); + logger.info("Update -- " + myCustomer.toString()); + } + + private void basicLoadAndSaveWithMapper() { + CustomerDto dto = new CustomerDto(); + dto.firstName = "Johnny"; + dto.lastName = "Doe"; + Customer entity = service.addCustomer(dto); + logger.info("Insert -- " + entity.toString()); + CustomerDto dto2 = new CustomerDto(); + dto2.id = entity.id; + dto2.address = "Mountain View"; + dto2.email = "doe@mail.com"; + dto2.phone = "+44"; + entity = service.updateCustomer(dto2); + logger.info("Update -- " + entity.toString()); + } + +} diff --git a/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/model/Customer.java b/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/model/Customer.java new file mode 100644 index 0000000000..91808e7971 --- /dev/null +++ b/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/model/Customer.java @@ -0,0 +1,27 @@ +package com.baeldung.model; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; + +@Entity +public class Customer { + + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) + public long id; + public String firstName; + public String lastName; + public String address; + public String email; + public String phone; + //... + public String phone99; + + public Customer() {} + + @Override public String toString() { + return String.format("Customer %s %s, Address: %s, Email: %s, Phone: %s", + this.firstName, this.lastName, this.address, this.email, this.phone); + } +} diff --git a/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/model/CustomerDto.java b/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/model/CustomerDto.java new file mode 100644 index 0000000000..8f7803fc32 --- /dev/null +++ b/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/model/CustomerDto.java @@ -0,0 +1,34 @@ +package com.baeldung.model; + +public class CustomerDto { + public long id; + public String firstName; + public String lastName; + public String address; + public String email; + public String phone; + //... + public String phone99; + + public CustomerDto() {} + + public CustomerDto(Customer c) { + this.id = c.id; + this.firstName = c.firstName; + this.lastName = c.lastName; + this.address = c.address; + this.email = c.email; + this.phone = c.phone; + } + + public Customer convertToEntity() { + Customer c = new Customer(); + c.id = id; + c.firstName = firstName; + c.lastName = lastName; + c.address = address; + c.email = email; + c.phone = phone; + return c; + } +} diff --git a/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/repository/CustomerRepository.java b/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/repository/CustomerRepository.java new file mode 100644 index 0000000000..dcde6c3b46 --- /dev/null +++ b/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/repository/CustomerRepository.java @@ -0,0 +1,13 @@ +package com.baeldung.repository; + +import org.springframework.cache.annotation.Cacheable; +import org.springframework.data.repository.CrudRepository; +import org.springframework.stereotype.Repository; + +import com.baeldung.model.Customer; + +@Repository +public interface CustomerRepository extends CrudRepository { + @Cacheable("customers") + Customer findById(long id); +} \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/service/CustomerService.java b/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/service/CustomerService.java new file mode 100644 index 0000000000..56afc9e80d --- /dev/null +++ b/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/service/CustomerService.java @@ -0,0 +1,50 @@ +package com.baeldung.service; + +import javax.transaction.Transactional; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import com.baeldung.model.Customer; +import com.baeldung.model.CustomerDto; +import com.baeldung.repository.CustomerRepository; +import com.baeldung.util.CustomerMapper; + +@Service @Transactional +public class CustomerService { + + @Autowired CustomerRepository repo; + @Autowired CustomerMapper mapper; + + public Customer addCustomer(String firstName, String lastName) { + Customer myCustomer = new Customer(); + myCustomer.firstName = firstName; + myCustomer.lastName = lastName; + repo.save(myCustomer); + return myCustomer; + } + + public Customer updateCustomer(long id, String email, String phone, String address) { + Customer myCustomer = repo.findById(id); + myCustomer.address = address; + myCustomer.email = email; + myCustomer.phone = phone; + repo.save(myCustomer); + return myCustomer; + } + + public Customer addCustomer(CustomerDto dto) { + Customer myCustomer = new Customer(); + mapper.updateCustomerFromDto(dto, myCustomer); + repo.save(myCustomer); + return myCustomer; + } + + public Customer updateCustomer(CustomerDto dto) { + Customer myCustomer = repo.findById(dto.id); + mapper.updateCustomerFromDto(dto, myCustomer); + repo.save(myCustomer); + return myCustomer; + } + +} diff --git a/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/util/CustomerMapper.java b/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/util/CustomerMapper.java new file mode 100644 index 0000000000..d4f264e33a --- /dev/null +++ b/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/util/CustomerMapper.java @@ -0,0 +1,15 @@ +package com.baeldung.util; + +import org.mapstruct.BeanMapping; +import org.mapstruct.Mapper; +import org.mapstruct.MappingTarget; +import org.mapstruct.NullValuePropertyMappingStrategy; + +import com.baeldung.model.Customer; +import com.baeldung.model.CustomerDto; + +@Mapper(componentModel = "spring") +public interface CustomerMapper { + @BeanMapping(nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE) + void updateCustomerFromDto(CustomerDto dto, @MappingTarget Customer entity); +} From 48d1c94dc0942a5b2e111c1af02260adc19df174 Mon Sep 17 00:00:00 2001 From: Justin Albano Date: Wed, 13 May 2020 06:06:58 -0400 Subject: [PATCH 009/140] BAEL-3951: Corrected misspelling. --- .../com/baeldung/java14/record/Person.java | 44 +-- .../baeldung/java14/record/PersonTest.java | 300 +++++++++--------- 2 files changed, 172 insertions(+), 172 deletions(-) diff --git a/core-java-modules/core-java-14/src/main/java/com/baeldung/java14/record/Person.java b/core-java-modules/core-java-14/src/main/java/com/baeldung/java14/record/Person.java index 33243c4ecf..56cc9f30d9 100644 --- a/core-java-modules/core-java-14/src/main/java/com/baeldung/java14/record/Person.java +++ b/core-java-modules/core-java-14/src/main/java/com/baeldung/java14/record/Person.java @@ -1,22 +1,22 @@ -package com.baeldung.java14.record; - -import java.util.Objects; - -public record Person (String name, String address) { - - public static String UNKWOWN_ADDRESS = "Unknown"; - public static String UNNAMED = "Unnamed"; - - public Person { - Objects.requireNonNull(name); - Objects.requireNonNull(address); - } - - public Person(String name) { - this(name, UNKWOWN_ADDRESS); - } - - public static Person unnamed(String address) { - return new Person(UNNAMED, address); - } -} +package com.baeldung.java14.record; + +import java.util.Objects; + +public record Person (String name, String address) { + + public static String UNKNOWN_ADDRESS = "Unknown"; + public static String UNNAMED = "Unnamed"; + + public Person { + Objects.requireNonNull(name); + Objects.requireNonNull(address); + } + + public Person(String name) { + this(name, UNKNOWN_ADDRESS); + } + + public static Person unnamed(String address) { + return new Person(UNNAMED, address); + } +} diff --git a/core-java-modules/core-java-14/src/test/java/com/baeldung/java14/record/PersonTest.java b/core-java-modules/core-java-14/src/test/java/com/baeldung/java14/record/PersonTest.java index 4a7d4ede5f..2a5195efc1 100644 --- a/core-java-modules/core-java-14/src/test/java/com/baeldung/java14/record/PersonTest.java +++ b/core-java-modules/core-java-14/src/test/java/com/baeldung/java14/record/PersonTest.java @@ -1,150 +1,150 @@ -package com.baeldung.java14.record; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertTrue; - -import org.junit.Test; - -public class PersonTest { - - @Test - public void givenSameNameAndAddress_whenEquals_thenPersonsEqual() { - - String name = "John Doe"; - String address = "100 Linda Ln."; - - Person person1 = new Person(name, address); - Person person2 = new Person(name, address); - - assertTrue(person1.equals(person2)); - } - - @Test - public void givenDifferentObject_whenEquals_thenNotEqual() { - - Person person = new Person("John Doe", "100 Linda Ln."); - - assertFalse(person.equals(new Object())); - } - - @Test - public void givenDifferentName_whenEquals_thenPersonsNotEqual() { - - String address = "100 Linda Ln."; - - Person person1 = new Person("Jane Doe", address); - Person person2 = new Person("John Doe", address); - - assertFalse(person1.equals(person2)); - } - - @Test - public void givenDifferentAddress_whenEquals_thenPersonsNotEqual() { - - String name = "John Doe"; - - Person person1 = new Person(name, "100 Linda Ln."); - Person person2 = new Person(name, "200 London Ave."); - - assertFalse(person1.equals(person2)); - } - - @Test - public void givenSameNameAndAddress_whenHashCode_thenPersonsEqual() { - - String name = "John Doe"; - String address = "100 Linda Ln."; - - Person person1 = new Person(name, address); - Person person2 = new Person(name, address); - - assertEquals(person1.hashCode(), person2.hashCode()); - } - - @Test - public void givenDifferentObject_whenHashCode_thenNotEqual() { - - Person person = new Person("John Doe", "100 Linda Ln."); - - assertNotEquals(person.hashCode(), new Object().hashCode()); - } - - @Test - public void givenDifferentName_whenHashCode_thenPersonsNotEqual() { - - String address = "100 Linda Ln."; - - Person person1 = new Person("Jane Doe", address); - Person person2 = new Person("John Doe", address); - - assertNotEquals(person1.hashCode(), person2.hashCode()); - } - - @Test - public void givenDifferentAddress_whenHashCode_thenPersonsNotEqual() { - - String name = "John Doe"; - - Person person1 = new Person(name, "100 Linda Ln."); - Person person2 = new Person(name, "200 London Ave."); - - assertNotEquals(person1.hashCode(), person2.hashCode()); - } - - @Test - public void givenValidNameAndAddress_whenGetNameAndAddress_thenExpectedValuesReturned() { - - String name = "John Doe"; - String address = "100 Linda Ln."; - - Person person = new Person(name, address); - - assertEquals(name, person.name()); - assertEquals(address, person.address()); - } - - @Test - public void givenValidNameAndAddress_whenToString_thenCorrectStringReturned() { - - String name = "John Doe"; - String address = "100 Linda Ln."; - - Person person = new Person(name, address); - - assertEquals("Person[name=" + name + ", address=" + address + "]", person.toString()); - } - - @Test(expected = NullPointerException.class) - public void givenNullName_whenConstruct_thenErrorThrown() { - new Person(null, "100 Linda Ln."); - } - - @Test(expected = NullPointerException.class) - public void givenNullAddress_whenConstruct_thenErrorThrown() { - new Person("John Doe", null); - } - - @Test - public void givenUnknownAddress_whenConstructing_thenAddressPopulated() { - - String name = "John Doe"; - - Person person = new Person(name); - - assertEquals(name, person.name()); - assertEquals(Person.UNKWOWN_ADDRESS, person.address()); - } - - @Test - public void givenUnnamed_whenConstructingThroughFactory_thenNamePopulated() { - - String address = "100 Linda Ln."; - - Person person = Person.unnamed(address); - - assertEquals(Person.UNNAMED, person.name()); - assertEquals(address, person.address()); - } -} +package com.baeldung.java14.record; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +public class PersonTest { + + @Test + public void givenSameNameAndAddress_whenEquals_thenPersonsEqual() { + + String name = "John Doe"; + String address = "100 Linda Ln."; + + Person person1 = new Person(name, address); + Person person2 = new Person(name, address); + + assertTrue(person1.equals(person2)); + } + + @Test + public void givenDifferentObject_whenEquals_thenNotEqual() { + + Person person = new Person("John Doe", "100 Linda Ln."); + + assertFalse(person.equals(new Object())); + } + + @Test + public void givenDifferentName_whenEquals_thenPersonsNotEqual() { + + String address = "100 Linda Ln."; + + Person person1 = new Person("Jane Doe", address); + Person person2 = new Person("John Doe", address); + + assertFalse(person1.equals(person2)); + } + + @Test + public void givenDifferentAddress_whenEquals_thenPersonsNotEqual() { + + String name = "John Doe"; + + Person person1 = new Person(name, "100 Linda Ln."); + Person person2 = new Person(name, "200 London Ave."); + + assertFalse(person1.equals(person2)); + } + + @Test + public void givenSameNameAndAddress_whenHashCode_thenPersonsEqual() { + + String name = "John Doe"; + String address = "100 Linda Ln."; + + Person person1 = new Person(name, address); + Person person2 = new Person(name, address); + + assertEquals(person1.hashCode(), person2.hashCode()); + } + + @Test + public void givenDifferentObject_whenHashCode_thenNotEqual() { + + Person person = new Person("John Doe", "100 Linda Ln."); + + assertNotEquals(person.hashCode(), new Object().hashCode()); + } + + @Test + public void givenDifferentName_whenHashCode_thenPersonsNotEqual() { + + String address = "100 Linda Ln."; + + Person person1 = new Person("Jane Doe", address); + Person person2 = new Person("John Doe", address); + + assertNotEquals(person1.hashCode(), person2.hashCode()); + } + + @Test + public void givenDifferentAddress_whenHashCode_thenPersonsNotEqual() { + + String name = "John Doe"; + + Person person1 = new Person(name, "100 Linda Ln."); + Person person2 = new Person(name, "200 London Ave."); + + assertNotEquals(person1.hashCode(), person2.hashCode()); + } + + @Test + public void givenValidNameAndAddress_whenGetNameAndAddress_thenExpectedValuesReturned() { + + String name = "John Doe"; + String address = "100 Linda Ln."; + + Person person = new Person(name, address); + + assertEquals(name, person.name()); + assertEquals(address, person.address()); + } + + @Test + public void givenValidNameAndAddress_whenToString_thenCorrectStringReturned() { + + String name = "John Doe"; + String address = "100 Linda Ln."; + + Person person = new Person(name, address); + + assertEquals("Person[name=" + name + ", address=" + address + "]", person.toString()); + } + + @Test(expected = NullPointerException.class) + public void givenNullName_whenConstruct_thenErrorThrown() { + new Person(null, "100 Linda Ln."); + } + + @Test(expected = NullPointerException.class) + public void givenNullAddress_whenConstruct_thenErrorThrown() { + new Person("John Doe", null); + } + + @Test + public void givenUnknownAddress_whenConstructing_thenAddressPopulated() { + + String name = "John Doe"; + + Person person = new Person(name); + + assertEquals(name, person.name()); + assertEquals(Person.UNKNOWN_ADDRESS, person.address()); + } + + @Test + public void givenUnnamed_whenConstructingThroughFactory_thenNamePopulated() { + + String address = "100 Linda Ln."; + + Person person = Person.unnamed(address); + + assertEquals(Person.UNNAMED, person.name()); + assertEquals(address, person.address()); + } +} From 9ea4e4f04ef90d3267f0c2ab7dd6f8431f6a03e1 Mon Sep 17 00:00:00 2001 From: Michele Guarnaccia Date: Sat, 16 May 2020 17:56:00 +0200 Subject: [PATCH 010/140] Simplified + refactored --- .../main/java/com/baeldung/Application.java | 14 ++++------- .../java/com/baeldung/model/Customer.java | 9 +++----- .../java/com/baeldung/model/CustomerDto.java | 23 +++++++------------ .../com/baeldung/service/CustomerService.java | 9 +++----- 4 files changed, 19 insertions(+), 36 deletions(-) diff --git a/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/Application.java b/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/Application.java index 64d0a5e6c6..34e86fe135 100644 --- a/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/Application.java +++ b/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/Application.java @@ -34,22 +34,18 @@ public class Application { } private void basicLoadAndSave() { - Customer myCustomer = service.addCustomer("John", "Doe"); + Customer myCustomer = service.addCustomer("John"); logger.info("Insert -- " + myCustomer.toString()); - myCustomer = service.updateCustomer(myCustomer.id, "john@doe.com", "+00", "Route 66"); + myCustomer = service.updateCustomer(myCustomer.id, "+00"); logger.info("Update -- " + myCustomer.toString()); } private void basicLoadAndSaveWithMapper() { - CustomerDto dto = new CustomerDto(); - dto.firstName = "Johnny"; - dto.lastName = "Doe"; + CustomerDto dto = new CustomerDto(null); + dto.name = "Johnny"; Customer entity = service.addCustomer(dto); logger.info("Insert -- " + entity.toString()); - CustomerDto dto2 = new CustomerDto(); - dto2.id = entity.id; - dto2.address = "Mountain View"; - dto2.email = "doe@mail.com"; + CustomerDto dto2 = new CustomerDto(entity.id); dto2.phone = "+44"; entity = service.updateCustomer(dto2); logger.info("Update -- " + entity.toString()); diff --git a/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/model/Customer.java b/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/model/Customer.java index 91808e7971..28c5d5c76c 100644 --- a/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/model/Customer.java +++ b/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/model/Customer.java @@ -10,10 +10,7 @@ public class Customer { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) public long id; - public String firstName; - public String lastName; - public String address; - public String email; + public String name; public String phone; //... public String phone99; @@ -21,7 +18,7 @@ public class Customer { public Customer() {} @Override public String toString() { - return String.format("Customer %s %s, Address: %s, Email: %s, Phone: %s", - this.firstName, this.lastName, this.address, this.email, this.phone); + return String.format("Customer %s, Phone: %s", + this.name, this.phone); } } diff --git a/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/model/CustomerDto.java b/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/model/CustomerDto.java index 8f7803fc32..c4601d5b81 100644 --- a/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/model/CustomerDto.java +++ b/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/model/CustomerDto.java @@ -1,33 +1,26 @@ package com.baeldung.model; public class CustomerDto { - public long id; - public String firstName; - public String lastName; - public String address; - public String email; + private long id; + public String name; public String phone; //... - public String phone99; + private String phone99; - public CustomerDto() {} + public CustomerDto(long id) { + this.id = id; + } public CustomerDto(Customer c) { this.id = c.id; - this.firstName = c.firstName; - this.lastName = c.lastName; - this.address = c.address; - this.email = c.email; + this.name = c.name; this.phone = c.phone; } public Customer convertToEntity() { Customer c = new Customer(); c.id = id; - c.firstName = firstName; - c.lastName = lastName; - c.address = address; - c.email = email; + c.name = name; c.phone = phone; return c; } diff --git a/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/service/CustomerService.java b/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/service/CustomerService.java index 56afc9e80d..3101cd8ece 100644 --- a/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/service/CustomerService.java +++ b/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/service/CustomerService.java @@ -16,18 +16,15 @@ public class CustomerService { @Autowired CustomerRepository repo; @Autowired CustomerMapper mapper; - public Customer addCustomer(String firstName, String lastName) { + public Customer addCustomer(String name) { Customer myCustomer = new Customer(); - myCustomer.firstName = firstName; - myCustomer.lastName = lastName; + myCustomer.name = name; repo.save(myCustomer); return myCustomer; } - public Customer updateCustomer(long id, String email, String phone, String address) { + public Customer updateCustomer(long id, String phone) { Customer myCustomer = repo.findById(id); - myCustomer.address = address; - myCustomer.email = email; myCustomer.phone = phone; repo.save(myCustomer); return myCustomer; From 12ef94be3959112f2b177c570b33c77cc09264b2 Mon Sep 17 00:00:00 2001 From: Gergo Petrik Date: Sun, 17 May 2020 10:07:47 +0200 Subject: [PATCH 011/140] added revision number and cas failure count --- .../java/com/baeldung/abaproblem/Account.java | 47 +++++++++++++------ 1 file changed, 32 insertions(+), 15 deletions(-) diff --git a/core-java-modules/core-java-concurrency-advanced-3/src/main/java/com/baeldung/abaproblem/Account.java b/core-java-modules/core-java-concurrency-advanced-3/src/main/java/com/baeldung/abaproblem/Account.java index 558245283a..ee1bdcd55b 100644 --- a/core-java-modules/core-java-concurrency-advanced-3/src/main/java/com/baeldung/abaproblem/Account.java +++ b/core-java-modules/core-java-concurrency-advanced-3/src/main/java/com/baeldung/abaproblem/Account.java @@ -1,39 +1,53 @@ package com.baeldung.abaproblem; -import java.util.ArrayList; -import java.util.List; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; public class Account { - private AtomicInteger balance = new AtomicInteger(0); - private List transactionDates = new ArrayList<>(); + private AtomicInteger balance; + private AtomicInteger transactionCount; + private ThreadLocal currentThreadCASFailureCount; + + public Account() { + this.balance = new AtomicInteger(0); + this.transactionCount = new AtomicInteger(0); + this.currentThreadCASFailureCount = new ThreadLocal<>(); + this.currentThreadCASFailureCount.set(0); + } public int getBalance() { return balance.get(); } - public List getTransactionDates() { - return transactionDates; + public int getTransactionCount() { + return transactionCount.get(); } - public boolean withdraw(int amount) throws InterruptedException { + public int getCurrentThreadCASFailureCount() { + return currentThreadCASFailureCount.get(); + } + + public boolean withdraw(int amount) { int current = getBalance(); - if (current < amount) { - throw new RuntimeException("Not sufficient balance"); - } - precessBalance(); + maybeWait(); boolean result = balance.compareAndSet(current, current - amount); if (result) { - transactionDates.add(System.currentTimeMillis()); + transactionCount.incrementAndGet(); + } else { + int currentCASFailureCount = currentThreadCASFailureCount.get(); + currentThreadCASFailureCount.set(currentCASFailureCount + 1); } return result; } - private void precessBalance() throws InterruptedException { + private void maybeWait() { if ("thread1".equals(Thread.currentThread().getName())) { - TimeUnit.SECONDS.sleep(2); + try { + TimeUnit.SECONDS.sleep(2); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + } } } @@ -41,7 +55,10 @@ public class Account { int current = balance.get(); boolean result = balance.compareAndSet(current, current + amount); if (result) { - transactionDates.add(System.currentTimeMillis()); + transactionCount.incrementAndGet(); + } else { + int currentCASFailureCount = currentThreadCASFailureCount.get(); + currentThreadCASFailureCount.set(currentCASFailureCount + 1); } return result; } From 5b0097f698047fd89ed157439f9403f8cea73f13 Mon Sep 17 00:00:00 2001 From: "alex.peptan" Date: Mon, 18 May 2020 09:52:39 +0300 Subject: [PATCH 012/140] BAEL-3896: OpenAPI JSON Objects in Query Params - Swagger file --- .../jsonparam/JsonParamController.java | 62 ------- .../baeldung/jsonparam/ParamObjectDTO.java | 33 ---- .../jsonParamOpenApiSwaggerDefinition | 154 ++++++++++++++++++ 3 files changed, 154 insertions(+), 95 deletions(-) delete mode 100644 spring-rest-http/src/main/java/com/baeldung/jsonparam/JsonParamController.java delete mode 100644 spring-rest-http/src/main/java/com/baeldung/jsonparam/ParamObjectDTO.java create mode 100644 spring-rest-http/src/main/java/com/baeldung/jsonparam/jsonParamOpenApiSwaggerDefinition diff --git a/spring-rest-http/src/main/java/com/baeldung/jsonparam/JsonParamController.java b/spring-rest-http/src/main/java/com/baeldung/jsonparam/JsonParamController.java deleted file mode 100644 index d2a09296c2..0000000000 --- a/spring-rest-http/src/main/java/com/baeldung/jsonparam/JsonParamController.java +++ /dev/null @@ -1,62 +0,0 @@ -package com.baeldung.jsonparam; - -import com.baeldung.controllers.DeferredResultController; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.*; - -@Controller -@RestController -@RequestMapping("/api") -public class JsonParamController { - private final static Logger LOG = LoggerFactory.getLogger(DeferredResultController.class); - - @GetMapping(value = "/tickets") - public String testQueryParamApi(@RequestParam("params") String params) { - // params={"type":"foo","color":"green"} - ParamObjectDTO paramObjectDTO; - ObjectMapper objectMapper = new ObjectMapper(); - try { - paramObjectDTO = objectMapper.readValue(params, ParamObjectDTO.class); - System.out.println(paramObjectDTO); - // use paramObjectDTO where you have {"type":"foo","color":"green"} JSON data as Object - } catch (JsonProcessingException e) { - LOG.info("Json Processing Exception"); - } - return params; - } - - @GetMapping(value = "/tickets2") - public String testGetBodyParamApi(@RequestBody String params) { - // params={"type":"foo","color":"green"} - ParamObjectDTO paramObjectDTO; - ObjectMapper objectMapper = new ObjectMapper(); - try { - paramObjectDTO = objectMapper.readValue(params, ParamObjectDTO.class); - System.out.println(paramObjectDTO); - // use paramObjectDTO where you have {"type":"foo","color":"green"} JSON data as Object - } catch (JsonProcessingException e) { - LOG.info("Json Processing Exception"); - } - return params; - } - - @PostMapping(value = "/tickets") - public String testBodyParamApi(@RequestBody String params) { - // params={"type":"foo","color":"green"} - ParamObjectDTO paramObjectDTO; - ObjectMapper objectMapper = new ObjectMapper(); - try { - paramObjectDTO = objectMapper.readValue(params, ParamObjectDTO.class); - System.out.println(paramObjectDTO); - // use paramObjectDTO where you have {"type":"foo","color":"green"} JSON data as Object - } catch (JsonProcessingException e) { - LOG.info("Json Processing Exception"); - } - return params; - } - -} diff --git a/spring-rest-http/src/main/java/com/baeldung/jsonparam/ParamObjectDTO.java b/spring-rest-http/src/main/java/com/baeldung/jsonparam/ParamObjectDTO.java deleted file mode 100644 index a738180fa6..0000000000 --- a/spring-rest-http/src/main/java/com/baeldung/jsonparam/ParamObjectDTO.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.baeldung.jsonparam; - -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; - -@JsonIgnoreProperties(ignoreUnknown = true) -public class ParamObjectDTO { - private String type; - private String color; - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public String getColor() { - return color; - } - - public void setColor(String color) { - this.color = color; - } - - @Override - public String toString() { - return "ParamObjectDTO{" + - "type='" + type + '\'' + - ", color='" + color + '\'' + - '}'; - } -} diff --git a/spring-rest-http/src/main/java/com/baeldung/jsonparam/jsonParamOpenApiSwaggerDefinition b/spring-rest-http/src/main/java/com/baeldung/jsonparam/jsonParamOpenApiSwaggerDefinition new file mode 100644 index 0000000000..9f9bcb788a --- /dev/null +++ b/spring-rest-http/src/main/java/com/baeldung/jsonparam/jsonParamOpenApiSwaggerDefinition @@ -0,0 +1,154 @@ +swagger: '2.0' +... +paths: + /tickets: + get: + parameters: + - in: query + name: params + required: true + description: A JSON object with the `type` and `color` properties + type: string + example: '{"type":"foo","color":"green"}' + +swagger: '2.0' +... +paths: + /tickets: + post: + requestBody: + description: Parameter is an object that should be serialized as JSON + content: + application/json: + schema: + type: string + example: '{"type":"foo","color":"green"}' + responses: + '200': + description: successful process + +"/api/tickets": { + "get": { + "tags": [ + "account-resource" + ], + "summary": "testQueryParamApi", + "operationId": "testQueryParamApiUsingGET", + "produces": [ + "*/*" + ], + "parameters": [ + { + "name": "params", + "in": "query", + "description": "params", + "required": true, + "type": "string" + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "string" + } + }, + "401": { + "description": "Unauthorized" + }, + "403": { + "description": "Forbidden" + }, + "404": { + "description": "Not Found" + } + }, + "deprecated": false + }, + "post": { + "tags": [ + "account-resource" + ], + "summary": "testBodyParamApi", + "operationId": "testBodyParamApiUsingPOST", + "consumes": [ + "application/json" + ], + "produces": [ + "*/*" + ], + "parameters": [ + { + "in": "body", + "name": "params", + "description": "params", + "required": true, + "schema": { + "type": "string" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "string" + } + }, + "201": { + "description": "Created" + }, + "401": { + "description": "Unauthorized" + }, + "403": { + "description": "Forbidden" + }, + "404": { + "description": "Not Found" + } + }, + "deprecated": false + } +}, +"/api/tickets2": { + "get": { + "tags": [ + "account-resource" + ], + "summary": "testGetBodyParamApi", + "operationId": "testGetBodyParamApiUsingGET", + "produces": [ + "*/*" + ], + "parameters": [ + { + "in": "body", + "name": "params", + "description": "params", + "required": true, + "schema": { + "type": "string" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "string" + } + }, + "401": { + "description": "Unauthorized" + }, + "403": { + "description": "Forbidden" + }, + "404": { + "description": "Not Found" + } + }, + "deprecated": false + } +} From c9453fe33a0a296e6d41161b9fb4b6e27ecd3bef Mon Sep 17 00:00:00 2001 From: Gergo Petrik Date: Mon, 18 May 2020 16:33:03 +0200 Subject: [PATCH 013/140] adding account unit test --- .../baeldung/abaproblem/AccountUnitTest.java | 65 +++++++++---------- 1 file changed, 30 insertions(+), 35 deletions(-) diff --git a/core-java-modules/core-java-concurrency-advanced-3/src/test/java/com/baeldung/abaproblem/AccountUnitTest.java b/core-java-modules/core-java-concurrency-advanced-3/src/test/java/com/baeldung/abaproblem/AccountUnitTest.java index 457580b96c..aa5f0f7997 100644 --- a/core-java-modules/core-java-concurrency-advanced-3/src/test/java/com/baeldung/abaproblem/AccountUnitTest.java +++ b/core-java-modules/core-java-concurrency-advanced-3/src/test/java/com/baeldung/abaproblem/AccountUnitTest.java @@ -5,7 +5,6 @@ import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; public class AccountUnitTest { @@ -20,7 +19,8 @@ public class AccountUnitTest { @Test public void zeroBalanceInitializationTest() { assertEquals(0, account.getBalance()); - assertTrue(account.getTransactionDates().isEmpty()); + assertEquals(0, account.getTransactionCount()); + assertEquals(0, account.getCurrentThreadCASFailureCount()); } @Test @@ -44,60 +44,55 @@ public class AccountUnitTest { assertEquals(defaultBalance - moneyToWithdraw, account.getBalance()); } - @Test - public void withdrawWithoutSufficientBalanceTest() { - assertThrows(RuntimeException.class, () -> account.withdraw(10)); - } - @Test public void abaProblemTest() throws InterruptedException { final int defaultBalance = 50; - final int amountToWithdrawByThreadA = 20; - final int amountToWithdrawByThreadB = 10; - final int amountToDepositByThreadB = 10; + final int amountToWithdrawByThread1 = 20; + final int amountToWithdrawByThread2 = 10; + final int amountToDepositByThread2 = 10; - assertTrue(account.getTransactionDates().isEmpty()); + assertEquals(0, account.getTransactionCount()); + assertEquals(0, account.getCurrentThreadCASFailureCount()); account.deposit(defaultBalance); - assertEquals(1, account.getTransactionDates().size()); + assertEquals(1, account.getTransactionCount()); + + Thread thread1 = new Thread(() -> { + + // this will take longer due to the name of the thread + assertTrue(account.withdraw(amountToWithdrawByThread1)); + + // thread 1 fails to capture ABA problem + assertNotEquals(1, account.getCurrentThreadCASFailureCount()); - Thread threadA = new Thread(() -> { - try { - // this will take longer due to the name of the thread - assertTrue(account.withdraw(amountToWithdrawByThreadA)); - } catch (InterruptedException e) { - throw new RuntimeException(e); - } }, "thread1"); - Thread threadB = new Thread(() -> { + Thread thread2 = new Thread(() -> { - assertTrue(account.deposit(amountToDepositByThreadB)); - assertEquals(defaultBalance + amountToDepositByThreadB, account.getBalance()); - try { - // this will be fast due to the name of the thread - assertTrue(account.withdraw(amountToWithdrawByThreadB)); - } catch (InterruptedException e) { - throw new RuntimeException(e); - } + assertTrue(account.deposit(amountToDepositByThread2)); + assertEquals(defaultBalance + amountToDepositByThread2, account.getBalance()); + + // this will be fast due to the name of the thread + assertTrue(account.withdraw(amountToWithdrawByThread2)); // thread 1 didn't finish yet, so the original value will be in place for it assertEquals(defaultBalance, account.getBalance()); + assertEquals(0, account.getCurrentThreadCASFailureCount()); }, "thread2"); - threadA.start(); - threadB.start(); - threadA.join(); - threadB.join(); + thread1.start(); + thread2.start(); + thread1.join(); + thread2.join(); // compareAndSet operation succeeds for thread 1 - assertEquals(defaultBalance - amountToWithdrawByThreadA, account.getBalance()); + assertEquals(defaultBalance - amountToWithdrawByThread1, account.getBalance()); //but there are other transactions - assertNotEquals(2, account.getTransactionDates().size()); + assertNotEquals(2, account.getTransactionCount()); // thread 2 did two modifications as well - assertEquals(4, account.getTransactionDates().size()); + assertEquals(4, account.getTransactionCount()); } } From cd51e118df520c67f9e2c58b13c3c1bfca494d82 Mon Sep 17 00:00:00 2001 From: Michele Guarnaccia Date: Mon, 18 May 2020 19:15:18 +0200 Subject: [PATCH 014/140] Fixed compilation error --- .../src/main/java/com/baeldung/model/CustomerDto.java | 4 ++++ .../src/main/java/com/baeldung/service/CustomerService.java | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/model/CustomerDto.java b/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/model/CustomerDto.java index c4601d5b81..74b909aad8 100644 --- a/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/model/CustomerDto.java +++ b/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/model/CustomerDto.java @@ -17,6 +17,10 @@ public class CustomerDto { this.phone = c.phone; } + public long getId() { + return this.id; + } + public Customer convertToEntity() { Customer c = new Customer(); c.id = id; diff --git a/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/service/CustomerService.java b/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/service/CustomerService.java index 3101cd8ece..9ebbb0c814 100644 --- a/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/service/CustomerService.java +++ b/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/service/CustomerService.java @@ -38,7 +38,7 @@ public class CustomerService { } public Customer updateCustomer(CustomerDto dto) { - Customer myCustomer = repo.findById(dto.id); + Customer myCustomer = repo.findById(dto.getId()); mapper.updateCustomerFromDto(dto, myCustomer); repo.save(myCustomer); return myCustomer; From 745d5edda1c1018fad25e4e076f54f1fda89b464 Mon Sep 17 00:00:00 2001 From: Mathieu Fortin Date: Sun, 12 Apr 2020 16:20:59 -0400 Subject: [PATCH 015/140] upgraded libs, moved to RestHighLevelClient --- .../spring-data-elasticsearch/pom.xml | 32 ++-- .../spring/data/es/config/Config.java | 47 ++---- .../ElasticSearchManualTest.java | 141 +++++++++--------- .../elasticsearch/GeoQueriesManualTest.java | 17 +-- .../data/es/ElasticSearchQueryManualTest.java | 3 +- 5 files changed, 107 insertions(+), 133 deletions(-) diff --git a/persistence-modules/spring-data-elasticsearch/pom.xml b/persistence-modules/spring-data-elasticsearch/pom.xml index 3446528323..f322e46c0e 100644 --- a/persistence-modules/spring-data-elasticsearch/pom.xml +++ b/persistence-modules/spring-data-elasticsearch/pom.xml @@ -25,6 +25,12 @@ ${spring.version} + + org.springframework + spring-web + ${spring.version} + + org.springframework.data spring-data-elasticsearch @@ -32,8 +38,8 @@ - org.elasticsearch - elasticsearch + org.elasticsearch.client + elasticsearch-rest-high-level-client ${elasticsearch.version} @@ -49,15 +55,9 @@ - com.vividsolutions - jts - ${jts.version} - - - xerces - xercesImpl - - + org.locationtech.jts + jts-core + 1.16.1 @@ -66,12 +66,6 @@ ${log4j.version} - - org.elasticsearch.client - transport - ${elasticsearch.version} - - org.springframework spring-test @@ -88,9 +82,9 @@ - 3.0.8.RELEASE + 3.2.6.RELEASE 4.5.2 - 5.6.0 + 7.6.2 1.2.47 0.6 1.13 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 e6ce795b45..f98342486f 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 @@ -1,19 +1,13 @@ package com.baeldung.spring.data.es.config; -import java.net.InetAddress; -import java.net.UnknownHostException; - -import org.elasticsearch.client.Client; -import org.elasticsearch.client.transport.TransportClient; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.transport.InetSocketTransportAddress; -import org.elasticsearch.transport.client.PreBuiltTransportClient; -import org.springframework.beans.factory.annotation.Value; +import org.elasticsearch.client.RestHighLevelClient; import org.springframework.context.annotation.Bean; 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.ElasticsearchTemplate; +import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate; import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories; @Configuration @@ -21,30 +15,15 @@ import org.springframework.data.elasticsearch.repository.config.EnableElasticsea @ComponentScan(basePackages = { "com.baeldung.spring.data.es.service" }) public class Config { - @Value("${elasticsearch.home:/usr/local/Cellar/elasticsearch/5.6.0}") - private String elasticsearchHome; + @Bean + RestHighLevelClient client() { + ClientConfiguration clientConfiguration = ClientConfiguration.builder().connectedTo("localhost:9200").build(); - @Value("${elasticsearch.cluster.name:elasticsearch}") - private String clusterName; + return RestClients.create(clientConfiguration).rest(); + } - @Bean - public Client client() { - TransportClient client = null; - try { - final Settings elasticsearchSettings = Settings.builder() - .put("client.transport.sniff", true) - .put("path.home", elasticsearchHome) - .put("cluster.name", clusterName).build(); - client = new PreBuiltTransportClient(elasticsearchSettings); - client.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("127.0.0.1"), 9300)); - } catch (UnknownHostException e) { - e.printStackTrace(); - } - return client; - } - - @Bean - public ElasticsearchOperations elasticsearchTemplate() { - return new ElasticsearchTemplate(client()); - } + @Bean + public ElasticsearchOperations elasticsearchTemplate() { + return new ElasticsearchRestTemplate(client()); + } } diff --git a/persistence-modules/spring-data-elasticsearch/src/test/java/com/baeldung/elasticsearch/ElasticSearchManualTest.java b/persistence-modules/spring-data-elasticsearch/src/test/java/com/baeldung/elasticsearch/ElasticSearchManualTest.java index e43dcdf43e..6dc1c42dc1 100644 --- a/persistence-modules/spring-data-elasticsearch/src/test/java/com/baeldung/elasticsearch/ElasticSearchManualTest.java +++ b/persistence-modules/spring-data-elasticsearch/src/test/java/com/baeldung/elasticsearch/ElasticSearchManualTest.java @@ -3,7 +3,6 @@ package com.baeldung.elasticsearch; import static org.junit.Assert.assertEquals; import java.io.IOException; -import java.net.InetAddress; import java.net.UnknownHostException; import java.util.ArrayList; import java.util.Arrays; @@ -11,24 +10,28 @@ import java.util.Date; import java.util.List; import java.util.stream.Collectors; +import com.alibaba.fastjson.JSON; + import org.elasticsearch.action.DocWriteResponse.Result; +import org.elasticsearch.action.delete.DeleteRequest; import org.elasticsearch.action.delete.DeleteResponse; +import org.elasticsearch.action.index.IndexRequest; import org.elasticsearch.action.index.IndexResponse; +import org.elasticsearch.action.search.SearchRequest; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.action.search.SearchType; -import org.elasticsearch.client.Client; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.transport.InetSocketTransportAddress; +import org.elasticsearch.client.RequestOptions; +import org.elasticsearch.client.RestHighLevelClient; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.search.SearchHit; -import org.elasticsearch.transport.client.PreBuiltTransportClient; +import org.elasticsearch.search.builder.SearchSourceBuilder; import org.junit.Before; import org.junit.Test; - -import com.alibaba.fastjson.JSON; +import org.springframework.data.elasticsearch.client.ClientConfiguration; +import org.springframework.data.elasticsearch.client.RestClients; /** * @@ -39,7 +42,7 @@ import com.alibaba.fastjson.JSON; */ public class ElasticSearchManualTest { private List listOfPersons = new ArrayList<>(); - private Client client = null; + private RestHighLevelClient client = null; @Before public void setUp() throws UnknownHostException { @@ -48,47 +51,44 @@ public class ElasticSearchManualTest { listOfPersons.add(person1); listOfPersons.add(person2); - client = new PreBuiltTransportClient(Settings.builder().put("client.transport.sniff", true) - .put("cluster.name","elasticsearch").build()) - .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("127.0.0.1"), 9300)); + ClientConfiguration clientConfiguration = ClientConfiguration.builder().connectedTo("localhost:9200").build(); + client = RestClients.create(clientConfiguration).rest(); } @Test - public void givenJsonString_whenJavaObject_thenIndexDocument() { + public void givenJsonString_whenJavaObject_thenIndexDocument() throws Exception { String jsonObject = "{\"age\":20,\"dateOfBirth\":1471466076564,\"fullName\":\"John Doe\"}"; - IndexResponse response = client - .prepareIndex("people", "Doe") - .setSource(jsonObject, XContentType.JSON) - .get(); - String index = response.getIndex(); - String type = response.getType(); + IndexRequest request = new IndexRequest("people"); + request.source(jsonObject, XContentType.JSON); + IndexResponse response = client.index(request, RequestOptions.DEFAULT); + String index = response.getIndex(); + assertEquals(Result.CREATED, response.getResult()); assertEquals(index, "people"); - assertEquals(type, "Doe"); } @Test - public void givenDocumentId_whenJavaObject_thenDeleteDocument() { + public void givenDocumentId_whenJavaObject_thenDeleteDocument() throws Exception { String jsonObject = "{\"age\":10,\"dateOfBirth\":1471455886564,\"fullName\":\"Johan Doe\"}"; - IndexResponse response = client - .prepareIndex("people", "Doe") - .setSource(jsonObject, XContentType.JSON) - .get(); + IndexRequest indexRequest = new IndexRequest("people"); + indexRequest.source(jsonObject, XContentType.JSON); + + IndexResponse response = client.index(indexRequest, RequestOptions.DEFAULT); String id = response.getId(); - DeleteResponse deleteResponse = client - .prepareDelete("people", "Doe", id) - .get(); + + DeleteRequest deleteRequest = new DeleteRequest("people"); + deleteRequest.id(id); + + DeleteResponse deleteResponse = client.delete(deleteRequest, RequestOptions.DEFAULT); assertEquals(Result.DELETED,deleteResponse.getResult()); } @Test - public void givenSearchRequest_whenMatchAll_thenReturnAllResults() { - SearchResponse response = client - .prepareSearch() - .execute() - .actionGet(); + public void givenSearchRequest_whenMatchAll_thenReturnAllResults() throws Exception { + SearchRequest searchRequest = new SearchRequest(); + SearchResponse response = client.search(searchRequest, RequestOptions.DEFAULT); SearchHit[] searchHits = response .getHits() .getHits(); @@ -98,42 +98,42 @@ public class ElasticSearchManualTest { } @Test - public void givenSearchParameters_thenReturnResults() { - SearchResponse response = client - .prepareSearch() - .setTypes() - .setSearchType(SearchType.DFS_QUERY_THEN_FETCH) - .setPostFilter(QueryBuilders - .rangeQuery("age") - .from(5) - .to(15)) - .setFrom(0) - .setSize(60) - .setExplain(true) - .execute() - .actionGet(); + public void givenSearchParameters_thenReturnResults() throws Exception { + SearchSourceBuilder builder = new SearchSourceBuilder() + .postFilter(QueryBuilders.rangeQuery("age").from(5).to(15)) + .from(0) + .size(60) + .explain(true); + + SearchRequest searchRequest = new SearchRequest(); + searchRequest.searchType(SearchType.DFS_QUERY_THEN_FETCH); + searchRequest.source(builder); + + SearchResponse response = client.search(searchRequest, RequestOptions.DEFAULT); - SearchResponse response2 = client - .prepareSearch() - .setTypes() - .setSearchType(SearchType.DFS_QUERY_THEN_FETCH) - .setPostFilter(QueryBuilders.simpleQueryStringQuery("+John -Doe OR Janette")) - .setFrom(0) - .setSize(60) - .setExplain(true) - .execute() - .actionGet(); + builder = new SearchSourceBuilder() + .postFilter(QueryBuilders.simpleQueryStringQuery("+John -Doe OR Janette")) + .from(0) + .size(60) + .explain(true); + + searchRequest = new SearchRequest(); + searchRequest.searchType(SearchType.DFS_QUERY_THEN_FETCH); + searchRequest.source(builder); + + SearchResponse response2 = client.search(searchRequest, RequestOptions.DEFAULT); + + builder = new SearchSourceBuilder() + .postFilter(QueryBuilders.matchQuery("John", "Name*")) + .from(0) + .size(60) + .explain(true); + searchRequest = new SearchRequest(); + searchRequest.searchType(SearchType.DFS_QUERY_THEN_FETCH); + searchRequest.source(builder); + + SearchResponse response3 = client.search(searchRequest, RequestOptions.DEFAULT); - SearchResponse response3 = client - .prepareSearch() - .setTypes() - .setSearchType(SearchType.DFS_QUERY_THEN_FETCH) - .setPostFilter(QueryBuilders.matchQuery("John", "Name*")) - .setFrom(0) - .setSize(60) - .setExplain(true) - .execute() - .actionGet(); response2.getHits(); response3.getHits(); @@ -151,10 +151,11 @@ public class ElasticSearchManualTest { .field("salary", "11500") .field("age", "10") .endObject(); - IndexResponse response = client - .prepareIndex("people", "Doe") - .setSource(builder) - .get(); + + IndexRequest indexRequest = new IndexRequest("people"); + indexRequest.source(builder); + + IndexResponse response = client.index(indexRequest, RequestOptions.DEFAULT); assertEquals(Result.CREATED, response.getResult()); } diff --git a/persistence-modules/spring-data-elasticsearch/src/test/java/com/baeldung/elasticsearch/GeoQueriesManualTest.java b/persistence-modules/spring-data-elasticsearch/src/test/java/com/baeldung/elasticsearch/GeoQueriesManualTest.java index f9a42050b6..698f605eeb 100644 --- a/persistence-modules/spring-data-elasticsearch/src/test/java/com/baeldung/elasticsearch/GeoQueriesManualTest.java +++ b/persistence-modules/spring-data-elasticsearch/src/test/java/com/baeldung/elasticsearch/GeoQueriesManualTest.java @@ -1,4 +1,5 @@ package com.baeldung.elasticsearch; + import static org.junit.Assert.assertTrue; import java.io.IOException; @@ -12,8 +13,7 @@ import org.elasticsearch.action.index.IndexResponse; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.client.Client; import org.elasticsearch.common.geo.GeoPoint; -import org.elasticsearch.common.geo.ShapeRelation; -import org.elasticsearch.common.geo.builders.ShapeBuilders; +import org.elasticsearch.common.geo.builders.EnvelopeBuilder; import org.elasticsearch.common.unit.DistanceUnit; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.index.query.QueryBuilder; @@ -23,13 +23,13 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; +import org.locationtech.jts.geom.Coordinate; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.elasticsearch.core.ElasticsearchTemplate; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import com.baeldung.spring.data.es.config.Config; -import com.vividsolutions.jts.geom.Coordinate; /** * @@ -75,13 +75,12 @@ public class GeoQueriesManualTest { .indices() .prepareRefresh(WONDERS_OF_WORLD) .get(); - - Coordinate topLeft =new Coordinate(74, 31.2); - Coordinate bottomRight =new Coordinate(81.1, 24); + + Coordinate topLeft = new Coordinate(74, 31.2); + Coordinate bottomRight = new Coordinate(81.1, 24); QueryBuilder qb = QueryBuilders - .geoShapeQuery("region", ShapeBuilders.newEnvelope(topLeft, bottomRight)) - .relation(ShapeRelation.WITHIN); - + .geoShapeQuery("region", new EnvelopeBuilder(topLeft, bottomRight).buildGeometry()); + //.relation(ShapeRelation.WITHIN)); SearchResponse searchResponse = client.prepareSearch(WONDERS_OF_WORLD) .setTypes(WONDERS) 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 5e24d8398c..0125a4b624 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 @@ -22,6 +22,7 @@ import org.elasticsearch.index.query.MultiMatchQueryBuilder; import org.elasticsearch.index.query.QueryBuilder; import org.elasticsearch.search.aggregations.Aggregation; import org.elasticsearch.search.aggregations.AggregationBuilders; +import org.elasticsearch.search.aggregations.BucketOrder; import org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation; import org.elasticsearch.search.aggregations.bucket.terms.StringTerms; import org.elasticsearch.search.aggregations.bucket.terms.Terms; @@ -159,7 +160,7 @@ public class ElasticSearchQueryManualTest { @Test public void givenNotAnalyzedQuery_whenMakeAggregationOnTermCount_thenEachTermCountsIndividually() { final TermsAggregationBuilder aggregation = AggregationBuilders.terms("top_tags").field("tags") - .order(Terms.Order.count(false)); + .order(BucketOrder.count(false)); final SearchResponse response = client.prepareSearch("blog").setTypes("article").addAggregation(aggregation) .execute().actionGet(); From c1d547c5f0a43e79497d3e80f349bc7d1f5467e5 Mon Sep 17 00:00:00 2001 From: Mathieu Fortin Date: Mon, 13 Apr 2020 13:02:12 -0400 Subject: [PATCH 016/140] fixed tests --- .../spring-data-elasticsearch/pom.xml | 2 +- .../elasticsearch/ElasticSearchManualTest.java | 10 +++++++--- .../elasticsearch/GeoQueriesManualTest.java | 3 +-- .../spring/data/es/ElasticSearchManualTest.java | 14 +++++++------- .../data/es/ElasticSearchQueryManualTest.java | 15 +++++++-------- 5 files changed, 23 insertions(+), 21 deletions(-) diff --git a/persistence-modules/spring-data-elasticsearch/pom.xml b/persistence-modules/spring-data-elasticsearch/pom.xml index f322e46c0e..36cd2d4171 100644 --- a/persistence-modules/spring-data-elasticsearch/pom.xml +++ b/persistence-modules/spring-data-elasticsearch/pom.xml @@ -84,7 +84,7 @@ 3.2.6.RELEASE 4.5.2 - 7.6.2 + 6.8.8 1.2.47 0.6 1.13 diff --git a/persistence-modules/spring-data-elasticsearch/src/test/java/com/baeldung/elasticsearch/ElasticSearchManualTest.java b/persistence-modules/spring-data-elasticsearch/src/test/java/com/baeldung/elasticsearch/ElasticSearchManualTest.java index 6dc1c42dc1..5928b0ef8e 100644 --- a/persistence-modules/spring-data-elasticsearch/src/test/java/com/baeldung/elasticsearch/ElasticSearchManualTest.java +++ b/persistence-modules/spring-data-elasticsearch/src/test/java/com/baeldung/elasticsearch/ElasticSearchManualTest.java @@ -58,7 +58,7 @@ public class ElasticSearchManualTest { @Test public void givenJsonString_whenJavaObject_thenIndexDocument() throws Exception { String jsonObject = "{\"age\":20,\"dateOfBirth\":1471466076564,\"fullName\":\"John Doe\"}"; - IndexRequest request = new IndexRequest("people"); + IndexRequest request = new IndexRequest("people", "Doe"); request.source(jsonObject, XContentType.JSON); IndexResponse response = client.index(request, RequestOptions.DEFAULT); @@ -71,7 +71,7 @@ public class ElasticSearchManualTest { @Test public void givenDocumentId_whenJavaObject_thenDeleteDocument() throws Exception { String jsonObject = "{\"age\":10,\"dateOfBirth\":1471455886564,\"fullName\":\"Johan Doe\"}"; - IndexRequest indexRequest = new IndexRequest("people"); + IndexRequest indexRequest = new IndexRequest("people", "Doe"); indexRequest.source(jsonObject, XContentType.JSON); IndexResponse response = client.index(indexRequest, RequestOptions.DEFAULT); @@ -79,6 +79,7 @@ public class ElasticSearchManualTest { DeleteRequest deleteRequest = new DeleteRequest("people"); deleteRequest.id(id); + deleteRequest.type("Doe"); DeleteResponse deleteResponse = client.delete(deleteRequest, RequestOptions.DEFAULT); @@ -95,6 +96,8 @@ public class ElasticSearchManualTest { List results = Arrays.stream(searchHits) .map(hit -> JSON.parseObject(hit.getSourceAsString(), Person.class)) .collect(Collectors.toList()); + + results.forEach(System.out::println); } @Test @@ -140,6 +143,7 @@ public class ElasticSearchManualTest { final List results = Arrays.stream(response.getHits().getHits()) .map(hit -> JSON.parseObject(hit.getSourceAsString(), Person.class)) .collect(Collectors.toList()); + results.forEach(System.out::println); } @Test @@ -152,7 +156,7 @@ public class ElasticSearchManualTest { .field("age", "10") .endObject(); - IndexRequest indexRequest = new IndexRequest("people"); + IndexRequest indexRequest = new IndexRequest("people", "Doe"); indexRequest.source(builder); IndexResponse response = client.index(indexRequest, RequestOptions.DEFAULT); diff --git a/persistence-modules/spring-data-elasticsearch/src/test/java/com/baeldung/elasticsearch/GeoQueriesManualTest.java b/persistence-modules/spring-data-elasticsearch/src/test/java/com/baeldung/elasticsearch/GeoQueriesManualTest.java index 698f605eeb..45c643b636 100644 --- a/persistence-modules/spring-data-elasticsearch/src/test/java/com/baeldung/elasticsearch/GeoQueriesManualTest.java +++ b/persistence-modules/spring-data-elasticsearch/src/test/java/com/baeldung/elasticsearch/GeoQueriesManualTest.java @@ -79,8 +79,7 @@ public class GeoQueriesManualTest { Coordinate topLeft = new Coordinate(74, 31.2); Coordinate bottomRight = new Coordinate(81.1, 24); QueryBuilder qb = QueryBuilders - .geoShapeQuery("region", new EnvelopeBuilder(topLeft, bottomRight).buildGeometry()); - //.relation(ShapeRelation.WITHIN)); + .geoShapeQuery("region", new EnvelopeBuilder(topLeft, bottomRight)); SearchResponse searchResponse = client.prepareSearch(WONDERS_OF_WORLD) .setTypes(WONDERS) 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 bed2e2ff25..7c60c98ab7 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 @@ -10,23 +10,23 @@ import static org.junit.Assert.assertNotNull; import java.util.List; +import com.baeldung.spring.data.es.config.Config; +import com.baeldung.spring.data.es.model.Article; +import com.baeldung.spring.data.es.model.Author; +import com.baeldung.spring.data.es.service.ArticleService; + import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; -import org.springframework.data.elasticsearch.core.ElasticsearchTemplate; +import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate; import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder; import org.springframework.data.elasticsearch.core.query.SearchQuery; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import com.baeldung.spring.data.es.config.Config; -import com.baeldung.spring.data.es.model.Article; -import com.baeldung.spring.data.es.model.Author; -import com.baeldung.spring.data.es.service.ArticleService; - /** * * This Manual test requires: @@ -39,7 +39,7 @@ import com.baeldung.spring.data.es.service.ArticleService; public class ElasticSearchManualTest { @Autowired - private ElasticsearchTemplate elasticsearchTemplate; + private ElasticsearchRestTemplate elasticsearchTemplate; @Autowired private ArticleService articleService; 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 0125a4b624..b6146ac415 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 @@ -14,6 +14,11 @@ import static org.junit.Assert.assertEquals; import java.util.List; import java.util.Map; +import com.baeldung.spring.data.es.config.Config; +import com.baeldung.spring.data.es.model.Article; +import com.baeldung.spring.data.es.model.Author; +import com.baeldung.spring.data.es.service.ArticleService; + import org.apache.lucene.search.join.ScoreMode; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.client.Client; @@ -25,23 +30,17 @@ import org.elasticsearch.search.aggregations.AggregationBuilders; import org.elasticsearch.search.aggregations.BucketOrder; import org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation; import org.elasticsearch.search.aggregations.bucket.terms.StringTerms; -import org.elasticsearch.search.aggregations.bucket.terms.Terms; import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder; 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.ElasticsearchTemplate; +import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate; import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder; import org.springframework.data.elasticsearch.core.query.SearchQuery; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import com.baeldung.spring.data.es.config.Config; -import com.baeldung.spring.data.es.model.Article; -import com.baeldung.spring.data.es.model.Author; -import com.baeldung.spring.data.es.service.ArticleService; - /** * * This Manual test requires: @@ -54,7 +53,7 @@ import com.baeldung.spring.data.es.service.ArticleService; public class ElasticSearchQueryManualTest { @Autowired - private ElasticsearchTemplate elasticsearchTemplate; + private ElasticsearchRestTemplate elasticsearchTemplate; @Autowired private ArticleService articleService; From 2c5c556fedd3610ca3c146bbd58b67a4421e87d4 Mon Sep 17 00:00:00 2001 From: Mathieu Fortin Date: Mon, 13 Apr 2020 13:35:47 -0400 Subject: [PATCH 017/140] fixed tests --- .../spring-data-elasticsearch/pom.xml | 5 - .../com/baeldung/SpringContextManualTest.java | 3 +- .../ElasticSearchManualTest.java | 195 ++++++++-------- .../elasticsearch/GeoQueriesManualTest.java | 213 +++++++----------- .../data/es/ElasticSearchManualTest.java | 24 +- .../data/es/ElasticSearchQueryManualTest.java | 36 ++- 6 files changed, 211 insertions(+), 265 deletions(-) diff --git a/persistence-modules/spring-data-elasticsearch/pom.xml b/persistence-modules/spring-data-elasticsearch/pom.xml index 36cd2d4171..7d7ffb525d 100644 --- a/persistence-modules/spring-data-elasticsearch/pom.xml +++ b/persistence-modules/spring-data-elasticsearch/pom.xml @@ -37,11 +37,6 @@ ${spring-data-elasticsearch.version} - - org.elasticsearch.client - elasticsearch-rest-high-level-client - ${elasticsearch.version} - com.alibaba fastjson diff --git a/persistence-modules/spring-data-elasticsearch/src/test/java/com/baeldung/SpringContextManualTest.java b/persistence-modules/spring-data-elasticsearch/src/test/java/com/baeldung/SpringContextManualTest.java index c69deeb77c..2e9352b081 100644 --- a/persistence-modules/spring-data-elasticsearch/src/test/java/com/baeldung/SpringContextManualTest.java +++ b/persistence-modules/spring-data-elasticsearch/src/test/java/com/baeldung/SpringContextManualTest.java @@ -9,8 +9,7 @@ import com.baeldung.spring.data.es.config.Config; /** * - * This Manual test requires: - * * Elasticsearch instance running on host + * This Manual test requires: * Elasticsearch instance running on host * */ @RunWith(SpringJUnit4ClassRunner.class) diff --git a/persistence-modules/spring-data-elasticsearch/src/test/java/com/baeldung/elasticsearch/ElasticSearchManualTest.java b/persistence-modules/spring-data-elasticsearch/src/test/java/com/baeldung/elasticsearch/ElasticSearchManualTest.java index 5928b0ef8e..f8f70c58a4 100644 --- a/persistence-modules/spring-data-elasticsearch/src/test/java/com/baeldung/elasticsearch/ElasticSearchManualTest.java +++ b/persistence-modules/spring-data-elasticsearch/src/test/java/com/baeldung/elasticsearch/ElasticSearchManualTest.java @@ -35,132 +35,113 @@ import org.springframework.data.elasticsearch.client.RestClients; /** * - * This Manual test requires: - * * Elasticsearch instance running on host - * * with cluster name = elasticsearch + * This Manual test requires: * Elasticsearch instance running on host * with + * cluster name = elasticsearch * */ public class ElasticSearchManualTest { - private List listOfPersons = new ArrayList<>(); - private RestHighLevelClient client = null; + private List listOfPersons = new ArrayList<>(); + private RestHighLevelClient client = null; - @Before - public void setUp() throws UnknownHostException { - Person person1 = new Person(10, "John Doe", new Date()); - Person person2 = new Person(25, "Janette Doe", new Date()); - listOfPersons.add(person1); - listOfPersons.add(person2); - - ClientConfiguration clientConfiguration = ClientConfiguration.builder().connectedTo("localhost:9200").build(); - client = RestClients.create(clientConfiguration).rest(); - } + @Before + public void setUp() throws UnknownHostException { + Person person1 = new Person(10, "John Doe", new Date()); + Person person2 = new Person(25, "Janette Doe", new Date()); + listOfPersons.add(person1); + listOfPersons.add(person2); - @Test - public void givenJsonString_whenJavaObject_thenIndexDocument() throws Exception { - String jsonObject = "{\"age\":20,\"dateOfBirth\":1471466076564,\"fullName\":\"John Doe\"}"; - IndexRequest request = new IndexRequest("people", "Doe"); - request.source(jsonObject, XContentType.JSON); + ClientConfiguration clientConfiguration = ClientConfiguration.builder().connectedTo("localhost:9200").build(); + client = RestClients.create(clientConfiguration).rest(); + } - IndexResponse response = client.index(request, RequestOptions.DEFAULT); - String index = response.getIndex(); - - assertEquals(Result.CREATED, response.getResult()); - assertEquals(index, "people"); - } + @Test + public void givenJsonString_whenJavaObject_thenIndexDocument() throws Exception { + String jsonObject = "{\"age\":20,\"dateOfBirth\":1471466076564,\"fullName\":\"John Doe\"}"; + IndexRequest request = new IndexRequest("people", "Doe"); + request.source(jsonObject, XContentType.JSON); - @Test - public void givenDocumentId_whenJavaObject_thenDeleteDocument() throws Exception { - String jsonObject = "{\"age\":10,\"dateOfBirth\":1471455886564,\"fullName\":\"Johan Doe\"}"; - IndexRequest indexRequest = new IndexRequest("people", "Doe"); - indexRequest.source(jsonObject, XContentType.JSON); + IndexResponse response = client.index(request, RequestOptions.DEFAULT); + String index = response.getIndex(); - IndexResponse response = client.index(indexRequest, RequestOptions.DEFAULT); - String id = response.getId(); + assertEquals(Result.CREATED, response.getResult()); + assertEquals(index, "people"); + } - DeleteRequest deleteRequest = new DeleteRequest("people"); - deleteRequest.id(id); - deleteRequest.type("Doe"); + @Test + public void givenDocumentId_whenJavaObject_thenDeleteDocument() throws Exception { + String jsonObject = "{\"age\":10,\"dateOfBirth\":1471455886564,\"fullName\":\"Johan Doe\"}"; + IndexRequest indexRequest = new IndexRequest("people", "Doe"); + indexRequest.source(jsonObject, XContentType.JSON); - DeleteResponse deleteResponse = client.delete(deleteRequest, RequestOptions.DEFAULT); + IndexResponse response = client.index(indexRequest, RequestOptions.DEFAULT); + String id = response.getId(); - assertEquals(Result.DELETED,deleteResponse.getResult()); - } + DeleteRequest deleteRequest = new DeleteRequest("people"); + deleteRequest.id(id); + deleteRequest.type("Doe"); - @Test - public void givenSearchRequest_whenMatchAll_thenReturnAllResults() throws Exception { - SearchRequest searchRequest = new SearchRequest(); - SearchResponse response = client.search(searchRequest, RequestOptions.DEFAULT); - SearchHit[] searchHits = response - .getHits() - .getHits(); - List results = Arrays.stream(searchHits) - .map(hit -> JSON.parseObject(hit.getSourceAsString(), Person.class)) - .collect(Collectors.toList()); - - results.forEach(System.out::println); - } + DeleteResponse deleteResponse = client.delete(deleteRequest, RequestOptions.DEFAULT); - @Test - public void givenSearchParameters_thenReturnResults() throws Exception { - SearchSourceBuilder builder = new SearchSourceBuilder() - .postFilter(QueryBuilders.rangeQuery("age").from(5).to(15)) - .from(0) - .size(60) + assertEquals(Result.DELETED, deleteResponse.getResult()); + } + + @Test + public void givenSearchRequest_whenMatchAll_thenReturnAllResults() throws Exception { + SearchRequest searchRequest = new SearchRequest(); + SearchResponse response = client.search(searchRequest, RequestOptions.DEFAULT); + SearchHit[] searchHits = response.getHits().getHits(); + List results = Arrays.stream(searchHits).map(hit -> JSON.parseObject(hit.getSourceAsString(), Person.class)) + .collect(Collectors.toList()); + + results.forEach(System.out::println); + } + + @Test + public void givenSearchParameters_thenReturnResults() throws Exception { + SearchSourceBuilder builder = new SearchSourceBuilder().postFilter(QueryBuilders.rangeQuery("age").from(5).to(15)) + .from(0).size(60).explain(true); + + SearchRequest searchRequest = new SearchRequest(); + searchRequest.searchType(SearchType.DFS_QUERY_THEN_FETCH); + searchRequest.source(builder); + + SearchResponse response = client.search(searchRequest, RequestOptions.DEFAULT); + + builder = new SearchSourceBuilder().postFilter(QueryBuilders.simpleQueryStringQuery("+John -Doe OR Janette")) + .from(0).size(60).explain(true); + + searchRequest = new SearchRequest(); + searchRequest.searchType(SearchType.DFS_QUERY_THEN_FETCH); + searchRequest.source(builder); + + SearchResponse response2 = client.search(searchRequest, RequestOptions.DEFAULT); + + builder = new SearchSourceBuilder().postFilter(QueryBuilders.matchQuery("John", "Name*")).from(0).size(60) .explain(true); - - SearchRequest searchRequest = new SearchRequest(); - searchRequest.searchType(SearchType.DFS_QUERY_THEN_FETCH); - searchRequest.source(builder); - - SearchResponse response = client.search(searchRequest, RequestOptions.DEFAULT); + searchRequest = new SearchRequest(); + searchRequest.searchType(SearchType.DFS_QUERY_THEN_FETCH); + searchRequest.source(builder); - builder = new SearchSourceBuilder() - .postFilter(QueryBuilders.simpleQueryStringQuery("+John -Doe OR Janette")) - .from(0) - .size(60) - .explain(true); + SearchResponse response3 = client.search(searchRequest, RequestOptions.DEFAULT); - searchRequest = new SearchRequest(); - searchRequest.searchType(SearchType.DFS_QUERY_THEN_FETCH); - searchRequest.source(builder); + response2.getHits(); + response3.getHits(); - SearchResponse response2 = client.search(searchRequest, RequestOptions.DEFAULT); + final List results = Arrays.stream(response.getHits().getHits()) + .map(hit -> JSON.parseObject(hit.getSourceAsString(), Person.class)).collect(Collectors.toList()); + results.forEach(System.out::println); + } - builder = new SearchSourceBuilder() - .postFilter(QueryBuilders.matchQuery("John", "Name*")) - .from(0) - .size(60) - .explain(true); - searchRequest = new SearchRequest(); - searchRequest.searchType(SearchType.DFS_QUERY_THEN_FETCH); - searchRequest.source(builder); + @Test + public void givenContentBuilder_whenHelpers_thanIndexJson() throws IOException { + XContentBuilder builder = XContentFactory.jsonBuilder().startObject().field("fullName", "Test") + .field("salary", "11500").field("age", "10").endObject(); - SearchResponse response3 = client.search(searchRequest, RequestOptions.DEFAULT); + IndexRequest indexRequest = new IndexRequest("people", "Doe"); + indexRequest.source(builder); - response2.getHits(); - response3.getHits(); + IndexResponse response = client.index(indexRequest, RequestOptions.DEFAULT); - final List results = Arrays.stream(response.getHits().getHits()) - .map(hit -> JSON.parseObject(hit.getSourceAsString(), Person.class)) - .collect(Collectors.toList()); - results.forEach(System.out::println); - } - - @Test - public void givenContentBuilder_whenHelpers_thanIndexJson() throws IOException { - XContentBuilder builder = XContentFactory - .jsonBuilder() - .startObject() - .field("fullName", "Test") - .field("salary", "11500") - .field("age", "10") - .endObject(); - - IndexRequest indexRequest = new IndexRequest("people", "Doe"); - indexRequest.source(builder); - - IndexResponse response = client.index(indexRequest, RequestOptions.DEFAULT); - - assertEquals(Result.CREATED, response.getResult()); - } + assertEquals(Result.CREATED, response.getResult()); + } } diff --git a/persistence-modules/spring-data-elasticsearch/src/test/java/com/baeldung/elasticsearch/GeoQueriesManualTest.java b/persistence-modules/spring-data-elasticsearch/src/test/java/com/baeldung/elasticsearch/GeoQueriesManualTest.java index 45c643b636..e373fef7a6 100644 --- a/persistence-modules/spring-data-elasticsearch/src/test/java/com/baeldung/elasticsearch/GeoQueriesManualTest.java +++ b/persistence-modules/spring-data-elasticsearch/src/test/java/com/baeldung/elasticsearch/GeoQueriesManualTest.java @@ -33,155 +33,110 @@ import com.baeldung.spring.data.es.config.Config; /** * - * This Manual test requires: - * * Elasticsearch instance running on host - * * with cluster name = elasticsearch - * * and further configurations + * This Manual test requires: * Elasticsearch instance running on host * with + * cluster name = elasticsearch * and further configurations * */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = Config.class) public class GeoQueriesManualTest { - private static final String WONDERS_OF_WORLD = "wonders-of-world"; - private static final String WONDERS = "Wonders"; + private static final String WONDERS_OF_WORLD = "wonders-of-world"; + private static final String WONDERS = "Wonders"; - @Autowired - private ElasticsearchTemplate elasticsearchTemplate; + @Autowired + private ElasticsearchTemplate elasticsearchTemplate; - @Autowired - private Client client; + @Autowired + private Client client; - @Before - public void setUp() { - String jsonObject = "{\"Wonders\":{\"properties\":{\"name\":{\"type\":\"string\",\"index\":\"not_analyzed\"},\"region\":{\"type\":\"geo_shape\",\"tree\":\"quadtree\",\"precision\":\"1m\"},\"location\":{\"type\":\"geo_point\"}}}}"; - CreateIndexRequest req = new CreateIndexRequest(WONDERS_OF_WORLD); - req.mapping(WONDERS, jsonObject, XContentType.JSON); - client.admin() - .indices() - .create(req) - .actionGet(); - } + @Before + public void setUp() { + String jsonObject = "{\"Wonders\":{\"properties\":{\"name\":{\"type\":\"string\",\"index\":\"not_analyzed\"},\"region\":{\"type\":\"geo_shape\",\"tree\":\"quadtree\",\"precision\":\"1m\"},\"location\":{\"type\":\"geo_point\"}}}}"; + CreateIndexRequest req = new CreateIndexRequest(WONDERS_OF_WORLD); + req.mapping(WONDERS, jsonObject, XContentType.JSON); + client.admin().indices().create(req).actionGet(); + } - @Test - public void givenGeoShapeData_whenExecutedGeoShapeQuery_thenResultNonEmpty() throws IOException{ - String jsonObject = "{\"name\":\"Agra\",\"region\":{\"type\":\"envelope\",\"coordinates\":[[75,30.2],[80.1, 25]]}}"; - IndexResponse response = client.prepareIndex(WONDERS_OF_WORLD, WONDERS) - .setSource(jsonObject, XContentType.JSON) - .get(); - - String tajMahalId = response.getId(); - client.admin() - .indices() - .prepareRefresh(WONDERS_OF_WORLD) - .get(); - - Coordinate topLeft = new Coordinate(74, 31.2); - Coordinate bottomRight = new Coordinate(81.1, 24); - QueryBuilder qb = QueryBuilders - .geoShapeQuery("region", new EnvelopeBuilder(topLeft, bottomRight)); + @Test + public void givenGeoShapeData_whenExecutedGeoShapeQuery_thenResultNonEmpty() throws IOException { + String jsonObject = "{\"name\":\"Agra\",\"region\":{\"type\":\"envelope\",\"coordinates\":[[75,30.2],[80.1, 25]]}}"; + IndexResponse response = client.prepareIndex(WONDERS_OF_WORLD, WONDERS).setSource(jsonObject, XContentType.JSON) + .get(); - SearchResponse searchResponse = client.prepareSearch(WONDERS_OF_WORLD) - .setTypes(WONDERS) - .setQuery(qb) - .execute() - .actionGet(); + String tajMahalId = response.getId(); + client.admin().indices().prepareRefresh(WONDERS_OF_WORLD).get(); - List ids = Arrays.stream(searchResponse.getHits() - .getHits()) - .map(SearchHit::getId) - .collect(Collectors.toList()); + Coordinate topLeft = new Coordinate(74, 31.2); + Coordinate bottomRight = new Coordinate(81.1, 24); + QueryBuilder qb = QueryBuilders.geoShapeQuery("region", new EnvelopeBuilder(topLeft, bottomRight)); - assertTrue(ids.contains(tajMahalId)); - } + SearchResponse searchResponse = client.prepareSearch(WONDERS_OF_WORLD).setTypes(WONDERS).setQuery(qb).execute() + .actionGet(); - @Test - public void givenGeoPointData_whenExecutedGeoBoundingBoxQuery_thenResultNonEmpty() { - String jsonObject = "{\"name\":\"Pyramids of Giza\",\"location\":[31.131302,29.976480]}"; - IndexResponse response = client.prepareIndex(WONDERS_OF_WORLD, WONDERS) - .setSource(jsonObject, XContentType.JSON) - .get(); - String pyramidsOfGizaId = response.getId(); - client.admin() - .indices() - .prepareRefresh(WONDERS_OF_WORLD) - .get(); + List ids = Arrays.stream(searchResponse.getHits().getHits()).map(SearchHit::getId) + .collect(Collectors.toList()); - QueryBuilder qb = QueryBuilders.geoBoundingBoxQuery("location") - .setCorners(31,30,28,32); - - SearchResponse searchResponse = client.prepareSearch(WONDERS_OF_WORLD) - .setTypes(WONDERS) - .setQuery(qb) - .execute() - .actionGet(); - List ids = Arrays.stream(searchResponse.getHits() - .getHits()) - .map(SearchHit::getId) - .collect(Collectors.toList()); - assertTrue(ids.contains(pyramidsOfGizaId)); - } + assertTrue(ids.contains(tajMahalId)); + } - @Test - public void givenGeoPointData_whenExecutedGeoDistanceQuery_thenResultNonEmpty() { - String jsonObject = "{\"name\":\"Lighthouse of alexandria\",\"location\":[31.131302,29.976480]}"; - IndexResponse response = client.prepareIndex(WONDERS_OF_WORLD, WONDERS) - .setSource(jsonObject, XContentType.JSON) - .get(); - String lighthouseOfAlexandriaId = response.getId(); - client.admin() - .indices() - .prepareRefresh(WONDERS_OF_WORLD) - .get(); + @Test + public void givenGeoPointData_whenExecutedGeoBoundingBoxQuery_thenResultNonEmpty() { + String jsonObject = "{\"name\":\"Pyramids of Giza\",\"location\":[31.131302,29.976480]}"; + IndexResponse response = client.prepareIndex(WONDERS_OF_WORLD, WONDERS).setSource(jsonObject, XContentType.JSON) + .get(); + String pyramidsOfGizaId = response.getId(); + client.admin().indices().prepareRefresh(WONDERS_OF_WORLD).get(); - QueryBuilder qb = QueryBuilders.geoDistanceQuery("location") - .point(29.976, 31.131) - .distance(10, DistanceUnit.MILES); + QueryBuilder qb = QueryBuilders.geoBoundingBoxQuery("location").setCorners(31, 30, 28, 32); - SearchResponse searchResponse = client.prepareSearch(WONDERS_OF_WORLD) - .setTypes(WONDERS) - .setQuery(qb) - .execute() - .actionGet(); - List ids = Arrays.stream(searchResponse.getHits() - .getHits()) - .map(SearchHit::getId) - .collect(Collectors.toList()); - assertTrue(ids.contains(lighthouseOfAlexandriaId)); - } + SearchResponse searchResponse = client.prepareSearch(WONDERS_OF_WORLD).setTypes(WONDERS).setQuery(qb).execute() + .actionGet(); + List ids = Arrays.stream(searchResponse.getHits().getHits()).map(SearchHit::getId) + .collect(Collectors.toList()); + assertTrue(ids.contains(pyramidsOfGizaId)); + } - @Test - public void givenGeoPointData_whenExecutedGeoPolygonQuery_thenResultNonEmpty() { - String jsonObject = "{\"name\":\"The Great Rann of Kutch\",\"location\":[69.859741,23.733732]}"; - IndexResponse response = client.prepareIndex(WONDERS_OF_WORLD, WONDERS) - .setSource(jsonObject, XContentType.JSON) - .get(); - String greatRannOfKutchid = response.getId(); - client.admin() - .indices() - .prepareRefresh(WONDERS_OF_WORLD) - .get(); + @Test + public void givenGeoPointData_whenExecutedGeoDistanceQuery_thenResultNonEmpty() { + String jsonObject = "{\"name\":\"Lighthouse of alexandria\",\"location\":[31.131302,29.976480]}"; + IndexResponse response = client.prepareIndex(WONDERS_OF_WORLD, WONDERS).setSource(jsonObject, XContentType.JSON) + .get(); + String lighthouseOfAlexandriaId = response.getId(); + client.admin().indices().prepareRefresh(WONDERS_OF_WORLD).get(); - List allPoints = new ArrayList(); - allPoints.add(new GeoPoint(22.733, 68.859)); - allPoints.add(new GeoPoint(24.733, 68.859)); - allPoints.add(new GeoPoint(23, 70.859)); - QueryBuilder qb = QueryBuilders.geoPolygonQuery("location", allPoints); + QueryBuilder qb = QueryBuilders.geoDistanceQuery("location").point(29.976, 31.131).distance(10, DistanceUnit.MILES); - SearchResponse searchResponse = client.prepareSearch(WONDERS_OF_WORLD) - .setTypes(WONDERS) - .setQuery(qb) - .execute() - .actionGet(); - List ids = Arrays.stream(searchResponse.getHits() - .getHits()) - .map(SearchHit::getId) - .collect(Collectors.toList()); - assertTrue(ids.contains(greatRannOfKutchid)); - } + SearchResponse searchResponse = client.prepareSearch(WONDERS_OF_WORLD).setTypes(WONDERS).setQuery(qb).execute() + .actionGet(); + List ids = Arrays.stream(searchResponse.getHits().getHits()).map(SearchHit::getId) + .collect(Collectors.toList()); + assertTrue(ids.contains(lighthouseOfAlexandriaId)); + } - @After - public void destroy() { - elasticsearchTemplate.deleteIndex(WONDERS_OF_WORLD); - } + @Test + public void givenGeoPointData_whenExecutedGeoPolygonQuery_thenResultNonEmpty() { + String jsonObject = "{\"name\":\"The Great Rann of Kutch\",\"location\":[69.859741,23.733732]}"; + IndexResponse response = client.prepareIndex(WONDERS_OF_WORLD, WONDERS).setSource(jsonObject, XContentType.JSON) + .get(); + String greatRannOfKutchid = response.getId(); + client.admin().indices().prepareRefresh(WONDERS_OF_WORLD).get(); + + List allPoints = new ArrayList(); + allPoints.add(new GeoPoint(22.733, 68.859)); + allPoints.add(new GeoPoint(24.733, 68.859)); + allPoints.add(new GeoPoint(23, 70.859)); + QueryBuilder qb = QueryBuilders.geoPolygonQuery("location", allPoints); + + SearchResponse searchResponse = client.prepareSearch(WONDERS_OF_WORLD).setTypes(WONDERS).setQuery(qb).execute() + .actionGet(); + List ids = Arrays.stream(searchResponse.getHits().getHits()).map(SearchHit::getId) + .collect(Collectors.toList()); + assertTrue(ids.contains(greatRannOfKutchid)); + } + + @After + public void destroy() { + elasticsearchTemplate.deleteIndex(WONDERS_OF_WORLD); + } } 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 7c60c98ab7..751755689f 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 @@ -29,9 +29,8 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * - * This Manual test requires: - * * Elasticsearch instance running on host - * * with cluster name = elasticsearch + * This Manual test requires: * Elasticsearch instance running on host * with + * cluster name = elasticsearch * */ @RunWith(SpringJUnit4ClassRunner.class) @@ -88,26 +87,29 @@ public class ElasticSearchManualTest { @Test public void givenPersistedArticles_whenSearchByAuthorsName_thenRightFound() { - final Page
articleByAuthorName = articleService - .findByAuthorName(johnSmith.getName(), PageRequest.of(0, 10)); + final Page
articleByAuthorName = articleService.findByAuthorName(johnSmith.getName(), + PageRequest.of(0, 10)); assertEquals(2L, articleByAuthorName.getTotalElements()); } @Test public void givenCustomQuery_whenSearchByAuthorsName_thenArticleIsFound() { - final Page
articleByAuthorName = articleService.findByAuthorNameUsingCustomQuery("Smith", PageRequest.of(0, 10)); + final Page
articleByAuthorName = articleService.findByAuthorNameUsingCustomQuery("Smith", + PageRequest.of(0, 10)); assertEquals(2L, articleByAuthorName.getTotalElements()); } @Test public void givenTagFilterQuery_whenSearchByTag_thenArticleIsFound() { - final Page
articleByAuthorName = articleService.findByFilteredTagQuery("elasticsearch", PageRequest.of(0, 10)); + final Page
articleByAuthorName = articleService.findByFilteredTagQuery("elasticsearch", + PageRequest.of(0, 10)); assertEquals(3L, articleByAuthorName.getTotalElements()); } @Test public void givenTagFilterQuery_whenSearchByAuthorsName_thenArticleIsFound() { - final Page
articleByAuthorName = articleService.findByAuthorsNameAndFilteredTagQuery("Doe", "elasticsearch", PageRequest.of(0, 10)); + final Page
articleByAuthorName = articleService.findByAuthorsNameAndFilteredTagQuery("Doe", + "elasticsearch", PageRequest.of(0, 10)); assertEquals(2L, articleByAuthorName.getTotalElements()); } @@ -115,7 +117,7 @@ public class ElasticSearchManualTest { public void givenPersistedArticles_whenUseRegexQuery_thenRightArticlesFound() { final SearchQuery searchQuery = new NativeSearchQueryBuilder().withFilter(regexpQuery("title", ".*data.*")) - .build(); + .build(); final List
articles = elasticsearchTemplate.queryForList(searchQuery, Article.class); assertEquals(1, articles.size()); @@ -142,7 +144,7 @@ public class ElasticSearchManualTest { final String articleTitle = "Spring Data Elasticsearch"; final SearchQuery searchQuery = new NativeSearchQueryBuilder() - .withQuery(matchQuery("title", articleTitle).minimumShouldMatch("75%")).build(); + .withQuery(matchQuery("title", articleTitle).minimumShouldMatch("75%")).build(); final List
articles = elasticsearchTemplate.queryForList(searchQuery, Article.class); assertEquals(1, articles.size()); final long count = articleService.count(); @@ -155,7 +157,7 @@ public class ElasticSearchManualTest { @Test public void givenSavedDoc_whenOneTermMatches_thenFindByTitle() { final SearchQuery searchQuery = new NativeSearchQueryBuilder() - .withQuery(matchQuery("title", "Search engines").operator(AND)).build(); + .withQuery(matchQuery("title", "Search engines").operator(AND)).build(); final List
articles = elasticsearchTemplate.queryForList(searchQuery, Article.class); assertEquals(1, articles.size()); } 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 b6146ac415..629f89f3f1 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 @@ -20,8 +20,10 @@ import com.baeldung.spring.data.es.model.Author; import com.baeldung.spring.data.es.service.ArticleService; import org.apache.lucene.search.join.ScoreMode; +import org.elasticsearch.action.search.SearchRequest; import org.elasticsearch.action.search.SearchResponse; -import org.elasticsearch.client.Client; +import org.elasticsearch.client.RequestOptions; +import org.elasticsearch.client.RestHighLevelClient; import org.elasticsearch.common.unit.Fuzziness; import org.elasticsearch.index.query.MultiMatchQueryBuilder; import org.elasticsearch.index.query.QueryBuilder; @@ -29,8 +31,9 @@ import org.elasticsearch.search.aggregations.Aggregation; import org.elasticsearch.search.aggregations.AggregationBuilders; import org.elasticsearch.search.aggregations.BucketOrder; import org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation; -import org.elasticsearch.search.aggregations.bucket.terms.StringTerms; +import org.elasticsearch.search.aggregations.bucket.terms.ParsedStringTerms; import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder; +import org.elasticsearch.search.builder.SearchSourceBuilder; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -59,7 +62,7 @@ public class ElasticSearchQueryManualTest { private ArticleService articleService; @Autowired - private Client client; + private RestHighLevelClient client; private final Author johnSmith = new Author("John Smith"); private final Author johnDoe = new Author("John Doe"); @@ -141,13 +144,18 @@ public class ElasticSearchQueryManualTest { } @Test - public void givenAnalyzedQuery_whenMakeAggregationOnTermCount_thenEachTokenCountsSeparately() { + public void givenAnalyzedQuery_whenMakeAggregationOnTermCount_thenEachTokenCountsSeparately() throws Exception { final TermsAggregationBuilder aggregation = AggregationBuilders.terms("top_tags").field("title"); - final SearchResponse response = client.prepareSearch("blog").setTypes("article").addAggregation(aggregation) - .execute().actionGet(); + + final SearchSourceBuilder builder = new SearchSourceBuilder().aggregation(aggregation); + final SearchRequest searchRequest = new SearchRequest("blog") + .types("article") + .source(builder); + final SearchResponse response = client.search(searchRequest, RequestOptions.DEFAULT); + final Map results = response.getAggregations().asMap(); - final StringTerms topTags = (StringTerms) results.get("top_tags"); + final ParsedStringTerms topTags = (ParsedStringTerms) results.get("top_tags"); final List keys = topTags.getBuckets().stream() .map(MultiBucketsAggregation.Bucket::getKeyAsString) @@ -157,14 +165,20 @@ public class ElasticSearchQueryManualTest { } @Test - public void givenNotAnalyzedQuery_whenMakeAggregationOnTermCount_thenEachTermCountsIndividually() { + public void givenNotAnalyzedQuery_whenMakeAggregationOnTermCount_thenEachTermCountsIndividually() throws Exception { final TermsAggregationBuilder aggregation = AggregationBuilders.terms("top_tags").field("tags") .order(BucketOrder.count(false)); - final SearchResponse response = client.prepareSearch("blog").setTypes("article").addAggregation(aggregation) - .execute().actionGet(); + + final SearchSourceBuilder builder = new SearchSourceBuilder().aggregation(aggregation); + final SearchRequest searchRequest = new SearchRequest() + .indices("blog") + .types("article") + .source(builder); + + final SearchResponse response = client.search(searchRequest, RequestOptions.DEFAULT); final Map results = response.getAggregations().asMap(); - final StringTerms topTags = (StringTerms) results.get("top_tags"); + final ParsedStringTerms topTags = (ParsedStringTerms) results.get("top_tags"); final List keys = topTags.getBuckets().stream() .map(MultiBucketsAggregation.Bucket::getKeyAsString) From 58e44705b28db75112fe6a65b065e365d6a37b82 Mon Sep 17 00:00:00 2001 From: Mathieu Fortin Date: Mon, 13 Apr 2020 13:47:17 -0400 Subject: [PATCH 018/140] fixed format --- .../spring-data-elasticsearch/pom.xml | 1 - .../data/es/ElasticSearchQueryManualTest.java | 277 +++++++++--------- 2 files changed, 136 insertions(+), 142 deletions(-) diff --git a/persistence-modules/spring-data-elasticsearch/pom.xml b/persistence-modules/spring-data-elasticsearch/pom.xml index 7d7ffb525d..e2089eb8b1 100644 --- a/persistence-modules/spring-data-elasticsearch/pom.xml +++ b/persistence-modules/spring-data-elasticsearch/pom.xml @@ -79,7 +79,6 @@ 3.2.6.RELEASE 4.5.2 - 6.8.8 1.2.47 0.6 1.13 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 629f89f3f1..438d3adf02 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 @@ -46,183 +46,178 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * - * This Manual test requires: - * * Elasticsearch instance running on host - * * with cluster name = elasticsearch + * This Manual test requires: * Elasticsearch instance running on host * with + * cluster name = elasticsearch * */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = Config.class) public class ElasticSearchQueryManualTest { - @Autowired - private ElasticsearchRestTemplate elasticsearchTemplate; + @Autowired + private ElasticsearchRestTemplate elasticsearchTemplate; - @Autowired - private ArticleService articleService; + @Autowired + private ArticleService articleService; - @Autowired - private RestHighLevelClient client; + @Autowired + private RestHighLevelClient client; - private final Author johnSmith = new Author("John Smith"); - private final Author johnDoe = new Author("John Doe"); + private final Author johnSmith = new Author("John Smith"); + private final Author johnDoe = new Author("John Doe"); - @Before - public void before() { - elasticsearchTemplate.deleteIndex(Article.class); - elasticsearchTemplate.createIndex(Article.class); - elasticsearchTemplate.putMapping(Article.class); - elasticsearchTemplate.refresh(Article.class); + @Before + public void before() { + elasticsearchTemplate.deleteIndex(Article.class); + elasticsearchTemplate.createIndex(Article.class); + elasticsearchTemplate.putMapping(Article.class); + elasticsearchTemplate.refresh(Article.class); - Article article = new Article("Spring Data Elasticsearch"); - article.setAuthors(asList(johnSmith, johnDoe)); - article.setTags("elasticsearch", "spring data"); - articleService.save(article); + Article article = new Article("Spring Data Elasticsearch"); + article.setAuthors(asList(johnSmith, johnDoe)); + article.setTags("elasticsearch", "spring data"); + articleService.save(article); - article = new Article("Search engines"); - article.setAuthors(asList(johnDoe)); - article.setTags("search engines", "tutorial"); - articleService.save(article); + article = new Article("Search engines"); + article.setAuthors(asList(johnDoe)); + article.setTags("search engines", "tutorial"); + articleService.save(article); - article = new Article("Second Article About Elasticsearch"); - article.setAuthors(asList(johnSmith)); - article.setTags("elasticsearch", "spring data"); - articleService.save(article); + article = new Article("Second Article About Elasticsearch"); + article.setAuthors(asList(johnSmith)); + article.setTags("elasticsearch", "spring data"); + articleService.save(article); - article = new Article("Elasticsearch Tutorial"); - article.setAuthors(asList(johnDoe)); - article.setTags("elasticsearch"); - articleService.save(article); - } + article = new Article("Elasticsearch Tutorial"); + article.setAuthors(asList(johnDoe)); + article.setTags("elasticsearch"); + articleService.save(article); + } - @Test - public void givenFullTitle_whenRunMatchQuery_thenDocIsFound() { - final SearchQuery searchQuery = new NativeSearchQueryBuilder() - .withQuery(matchQuery("title", "Search engines").operator(AND)).build(); - final List
articles = elasticsearchTemplate.queryForList(searchQuery, Article.class); - assertEquals(1, articles.size()); - } + @Test + public void givenFullTitle_whenRunMatchQuery_thenDocIsFound() { + final SearchQuery searchQuery = new NativeSearchQueryBuilder() + .withQuery(matchQuery("title", "Search engines").operator(AND)).build(); + final List
articles = elasticsearchTemplate.queryForList(searchQuery, Article.class); + assertEquals(1, articles.size()); + } - @Test - public void givenOneTermFromTitle_whenRunMatchQuery_thenDocIsFound() { - final SearchQuery searchQuery = new NativeSearchQueryBuilder() - .withQuery(matchQuery("title", "Engines Solutions")).build(); - final List
articles = elasticsearchTemplate.queryForList(searchQuery, Article.class); - assertEquals(1, articles.size()); - assertEquals("Search engines", articles.get(0).getTitle()); - } + @Test + public void givenOneTermFromTitle_whenRunMatchQuery_thenDocIsFound() { + final SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchQuery("title", "Engines Solutions")) + .build(); + final List
articles = elasticsearchTemplate.queryForList(searchQuery, Article.class); + assertEquals(1, articles.size()); + assertEquals("Search engines", articles.get(0).getTitle()); + } - @Test - public void givenPartTitle_whenRunMatchQuery_thenDocIsFound() { - final SearchQuery searchQuery = new NativeSearchQueryBuilder() - .withQuery(matchQuery("title", "elasticsearch data")).build(); - final List
articles = elasticsearchTemplate.queryForList(searchQuery, Article.class); - assertEquals(3, articles.size()); - } + @Test + public void givenPartTitle_whenRunMatchQuery_thenDocIsFound() { + final SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchQuery("title", "elasticsearch data")) + .build(); + final List
articles = elasticsearchTemplate.queryForList(searchQuery, Article.class); + assertEquals(3, articles.size()); + } - @Test - public void givenFullTitle_whenRunMatchQueryOnVerbatimField_thenDocIsFound() { - SearchQuery searchQuery = new NativeSearchQueryBuilder() - .withQuery(matchQuery("title.verbatim", "Second Article About Elasticsearch")).build(); - List
articles = elasticsearchTemplate.queryForList(searchQuery, Article.class); - assertEquals(1, articles.size()); + @Test + public void givenFullTitle_whenRunMatchQueryOnVerbatimField_thenDocIsFound() { + SearchQuery searchQuery = new NativeSearchQueryBuilder() + .withQuery(matchQuery("title.verbatim", "Second Article About Elasticsearch")).build(); + List
articles = elasticsearchTemplate.queryForList(searchQuery, Article.class); + assertEquals(1, articles.size()); - searchQuery = new NativeSearchQueryBuilder().withQuery(matchQuery("title.verbatim", "Second Article About")) - .build(); - articles = elasticsearchTemplate.queryForList(searchQuery, Article.class); - assertEquals(0, articles.size()); - } + searchQuery = new NativeSearchQueryBuilder().withQuery(matchQuery("title.verbatim", "Second Article About")) + .build(); + articles = elasticsearchTemplate.queryForList(searchQuery, Article.class); + assertEquals(0, articles.size()); + } - @Test - public void givenNestedObject_whenQueryByAuthorsName_thenFoundArticlesByThatAuthor() { - final QueryBuilder builder = nestedQuery("authors", boolQuery().must(termQuery("authors.name", "smith")), ScoreMode.None); + @Test + public void givenNestedObject_whenQueryByAuthorsName_thenFoundArticlesByThatAuthor() { + final QueryBuilder builder = nestedQuery("authors", boolQuery().must(termQuery("authors.name", "smith")), + ScoreMode.None); - final SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(builder).build(); - final List
articles = elasticsearchTemplate.queryForList(searchQuery, Article.class); + final SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(builder).build(); + final List
articles = elasticsearchTemplate.queryForList(searchQuery, Article.class); - assertEquals(2, articles.size()); - } + assertEquals(2, articles.size()); + } - @Test - public void givenAnalyzedQuery_whenMakeAggregationOnTermCount_thenEachTokenCountsSeparately() throws Exception { - final TermsAggregationBuilder aggregation = AggregationBuilders.terms("top_tags").field("title"); - - final SearchSourceBuilder builder = new SearchSourceBuilder().aggregation(aggregation); - final SearchRequest searchRequest = new SearchRequest("blog") - .types("article") - .source(builder); + @Test + public void givenAnalyzedQuery_whenMakeAggregationOnTermCount_thenEachTokenCountsSeparately() throws Exception { + final TermsAggregationBuilder aggregation = AggregationBuilders.terms("top_tags").field("title"); - final SearchResponse response = client.search(searchRequest, RequestOptions.DEFAULT); - - final Map results = response.getAggregations().asMap(); - final ParsedStringTerms topTags = (ParsedStringTerms) results.get("top_tags"); + final SearchSourceBuilder builder = new SearchSourceBuilder().aggregation(aggregation); + final SearchRequest searchRequest = new SearchRequest("blog").types("article").source(builder); - final List keys = topTags.getBuckets().stream() - .map(MultiBucketsAggregation.Bucket::getKeyAsString) - .sorted() - .collect(toList()); - assertEquals(asList("about", "article", "data", "elasticsearch", "engines", "search", "second", "spring", "tutorial"), keys); - } + final SearchResponse response = client.search(searchRequest, RequestOptions.DEFAULT); - @Test - public void givenNotAnalyzedQuery_whenMakeAggregationOnTermCount_thenEachTermCountsIndividually() throws Exception { - final TermsAggregationBuilder aggregation = AggregationBuilders.terms("top_tags").field("tags") - .order(BucketOrder.count(false)); + final Map results = response.getAggregations().asMap(); + final ParsedStringTerms topTags = (ParsedStringTerms) results.get("top_tags"); - final SearchSourceBuilder builder = new SearchSourceBuilder().aggregation(aggregation); - final SearchRequest searchRequest = new SearchRequest() - .indices("blog") - .types("article") - .source(builder); + final List keys = topTags.getBuckets().stream().map(MultiBucketsAggregation.Bucket::getKeyAsString).sorted() + .collect(toList()); + assertEquals( + asList("about", "article", "data", "elasticsearch", "engines", "search", "second", "spring", "tutorial"), keys); + } - final SearchResponse response = client.search(searchRequest, RequestOptions.DEFAULT); + @Test + public void givenNotAnalyzedQuery_whenMakeAggregationOnTermCount_thenEachTermCountsIndividually() throws Exception { + final TermsAggregationBuilder aggregation = AggregationBuilders.terms("top_tags").field("tags") + .order(BucketOrder.count(false)); - final Map results = response.getAggregations().asMap(); - final ParsedStringTerms topTags = (ParsedStringTerms) results.get("top_tags"); + final SearchSourceBuilder builder = new SearchSourceBuilder().aggregation(aggregation); + final SearchRequest searchRequest = new SearchRequest().indices("blog").types("article").source(builder); - final List keys = topTags.getBuckets().stream() - .map(MultiBucketsAggregation.Bucket::getKeyAsString) - .collect(toList()); - assertEquals(asList("elasticsearch", "spring data", "search engines", "tutorial"), keys); - } + final SearchResponse response = client.search(searchRequest, RequestOptions.DEFAULT); - @Test - public void givenNotExactPhrase_whenUseSlop_thenQueryMatches() { - final SearchQuery searchQuery = new NativeSearchQueryBuilder() - .withQuery(matchPhraseQuery("title", "spring elasticsearch").slop(1)).build(); - final List
articles = elasticsearchTemplate.queryForList(searchQuery, Article.class); - assertEquals(1, articles.size()); - } + final Map results = response.getAggregations().asMap(); + final ParsedStringTerms topTags = (ParsedStringTerms) results.get("top_tags"); - @Test - public void givenPhraseWithType_whenUseFuzziness_thenQueryMatches() { - final SearchQuery searchQuery = new NativeSearchQueryBuilder() - .withQuery(matchQuery("title", "spring date elasticserch").operator(AND).fuzziness(Fuzziness.ONE) - .prefixLength(3)).build(); + final List keys = topTags.getBuckets().stream().map(MultiBucketsAggregation.Bucket::getKeyAsString) + .collect(toList()); + assertEquals(asList("elasticsearch", "spring data", "search engines", "tutorial"), keys); + } - final List
articles = elasticsearchTemplate.queryForList(searchQuery, Article.class); - assertEquals(1, articles.size()); - } + @Test + public void givenNotExactPhrase_whenUseSlop_thenQueryMatches() { + final SearchQuery searchQuery = new NativeSearchQueryBuilder() + .withQuery(matchPhraseQuery("title", "spring elasticsearch").slop(1)).build(); + final List
articles = elasticsearchTemplate.queryForList(searchQuery, Article.class); + assertEquals(1, articles.size()); + } - @Test - public void givenMultimatchQuery_whenDoSearch_thenAllProvidedFieldsMatch() { - final SearchQuery searchQuery = new NativeSearchQueryBuilder() - .withQuery(multiMatchQuery("tutorial").field("title").field("tags") - .type(MultiMatchQueryBuilder.Type.BEST_FIELDS)).build(); + @Test + public void givenPhraseWithType_whenUseFuzziness_thenQueryMatches() { + final SearchQuery searchQuery = new NativeSearchQueryBuilder() + .withQuery( + matchQuery("title", "spring date elasticserch").operator(AND).fuzziness(Fuzziness.ONE).prefixLength(3)) + .build(); - final List
articles = elasticsearchTemplate.queryForList(searchQuery, Article.class); - assertEquals(2, articles.size()); - } + final List
articles = elasticsearchTemplate.queryForList(searchQuery, Article.class); + assertEquals(1, articles.size()); + } - @Test - public void givenBoolQuery_whenQueryByAuthorsName_thenFoundArticlesByThatAuthorAndFilteredTag() { - final QueryBuilder builder = boolQuery().must(nestedQuery("authors", boolQuery().must(termQuery("authors.name", "doe")), ScoreMode.None)) - .filter(termQuery("tags", "elasticsearch")); + @Test + public void givenMultimatchQuery_whenDoSearch_thenAllProvidedFieldsMatch() { + final SearchQuery searchQuery = new NativeSearchQueryBuilder() + .withQuery( + multiMatchQuery("tutorial").field("title").field("tags").type(MultiMatchQueryBuilder.Type.BEST_FIELDS)) + .build(); - final SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(builder) - .build(); - final List
articles = elasticsearchTemplate.queryForList(searchQuery, Article.class); + final List
articles = elasticsearchTemplate.queryForList(searchQuery, Article.class); + assertEquals(2, articles.size()); + } - assertEquals(2, articles.size()); - } + @Test + public void givenBoolQuery_whenQueryByAuthorsName_thenFoundArticlesByThatAuthorAndFilteredTag() { + final QueryBuilder builder = boolQuery() + .must(nestedQuery("authors", boolQuery().must(termQuery("authors.name", "doe")), ScoreMode.None)) + .filter(termQuery("tags", "elasticsearch")); + + final SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(builder).build(); + final List
articles = elasticsearchTemplate.queryForList(searchQuery, Article.class); + + assertEquals(2, articles.size()); + } } From 95e4e7326d8cd504f0c749e460fd887b6734a53c Mon Sep 17 00:00:00 2001 From: Mathieu Fortin Date: Mon, 20 Apr 2020 20:29:21 -0400 Subject: [PATCH 019/140] removed ArticleService --- .../data/es/service/ArticleService.java | 28 -------- .../data/es/service/ArticleServiceImpl.java | 67 ------------------- .../data/es/ElasticSearchManualTest.java | 32 ++++----- .../data/es/ElasticSearchQueryManualTest.java | 12 ++-- 4 files changed, 22 insertions(+), 117 deletions(-) delete mode 100644 persistence-modules/spring-data-elasticsearch/src/main/java/com/baeldung/spring/data/es/service/ArticleService.java delete mode 100644 persistence-modules/spring-data-elasticsearch/src/main/java/com/baeldung/spring/data/es/service/ArticleServiceImpl.java diff --git a/persistence-modules/spring-data-elasticsearch/src/main/java/com/baeldung/spring/data/es/service/ArticleService.java b/persistence-modules/spring-data-elasticsearch/src/main/java/com/baeldung/spring/data/es/service/ArticleService.java deleted file mode 100644 index a0f72aa5f7..0000000000 --- a/persistence-modules/spring-data-elasticsearch/src/main/java/com/baeldung/spring/data/es/service/ArticleService.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.baeldung.spring.data.es.service; - -import java.util.Optional; - -import org.springframework.data.domain.Page; -import org.springframework.data.domain.Pageable; - -import com.baeldung.spring.data.es.model.Article; - -public interface ArticleService { - Article save(Article article); - - Optional
findOne(String id); - - Iterable
findAll(); - - Page
findByAuthorName(String name, Pageable pageable); - - Page
findByAuthorNameUsingCustomQuery(String name, Pageable pageable); - - Page
findByFilteredTagQuery(String tag, Pageable pageable); - - Page
findByAuthorsNameAndFilteredTagQuery(String name, String tag, Pageable pageable); - - long count(); - - void delete(Article article); -} diff --git a/persistence-modules/spring-data-elasticsearch/src/main/java/com/baeldung/spring/data/es/service/ArticleServiceImpl.java b/persistence-modules/spring-data-elasticsearch/src/main/java/com/baeldung/spring/data/es/service/ArticleServiceImpl.java deleted file mode 100644 index 5064f16508..0000000000 --- a/persistence-modules/spring-data-elasticsearch/src/main/java/com/baeldung/spring/data/es/service/ArticleServiceImpl.java +++ /dev/null @@ -1,67 +0,0 @@ -package com.baeldung.spring.data.es.service; - -import java.util.Optional; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.Pageable; -import org.springframework.stereotype.Service; - -import com.baeldung.spring.data.es.model.Article; -import com.baeldung.spring.data.es.repository.ArticleRepository; - -@Service -public class ArticleServiceImpl implements ArticleService { - - private final ArticleRepository articleRepository; - - @Autowired - public ArticleServiceImpl(ArticleRepository articleRepository) { - this.articleRepository = articleRepository; - } - - @Override - public Article save(Article article) { - return articleRepository.save(article); - } - - @Override - public Optional
findOne(String id) { - return articleRepository.findById(id); - } - - @Override - public Iterable
findAll() { - return articleRepository.findAll(); - } - - @Override - public Page
findByAuthorName(String name, Pageable pageable) { - return articleRepository.findByAuthorsName(name, pageable); - } - - @Override - public Page
findByAuthorNameUsingCustomQuery(String name, Pageable pageable) { - return articleRepository.findByAuthorsNameUsingCustomQuery(name, pageable); - } - - @Override - public Page
findByFilteredTagQuery(String tag, Pageable pageable) { - return articleRepository.findByFilteredTagQuery(tag, pageable); - } - - @Override - public Page
findByAuthorsNameAndFilteredTagQuery(String name, String tag, Pageable pageable) { - return articleRepository.findByAuthorsNameAndFilteredTagQuery(name, tag, pageable); - } - - @Override - public long count() { - return articleRepository.count(); - } - - @Override - public void delete(Article article) { - articleRepository.delete(article); - } -} 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 751755689f..6e1d7d1b7d 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 @@ -13,7 +13,7 @@ import java.util.List; import com.baeldung.spring.data.es.config.Config; import com.baeldung.spring.data.es.model.Article; import com.baeldung.spring.data.es.model.Author; -import com.baeldung.spring.data.es.service.ArticleService; +import com.baeldung.spring.data.es.repository.ArticleRepository; import org.junit.Before; import org.junit.Test; @@ -41,7 +41,7 @@ public class ElasticSearchManualTest { private ElasticsearchRestTemplate elasticsearchTemplate; @Autowired - private ArticleService articleService; + private ArticleRepository articleRepository; private final Author johnSmith = new Author("John Smith"); private final Author johnDoe = new Author("John Doe"); @@ -55,22 +55,22 @@ public class ElasticSearchManualTest { Article article = new Article("Spring Data Elasticsearch"); article.setAuthors(asList(johnSmith, johnDoe)); article.setTags("elasticsearch", "spring data"); - articleService.save(article); + articleRepository.save(article); article = new Article("Search engines"); article.setAuthors(asList(johnDoe)); article.setTags("search engines", "tutorial"); - articleService.save(article); + articleRepository.save(article); article = new Article("Second Article About Elasticsearch"); article.setAuthors(asList(johnSmith)); article.setTags("elasticsearch", "spring data"); - articleService.save(article); + articleRepository.save(article); article = new Article("Elasticsearch Tutorial"); article.setAuthors(asList(johnDoe)); article.setTags("elasticsearch"); - articleService.save(article); + articleRepository.save(article); } @Test @@ -80,35 +80,35 @@ public class ElasticSearchManualTest { Article article = new Article("Making Search Elastic"); article.setAuthors(authors); - article = articleService.save(article); + article = articleRepository.save(article); assertNotNull(article.getId()); } @Test public void givenPersistedArticles_whenSearchByAuthorsName_thenRightFound() { - final Page
articleByAuthorName = articleService.findByAuthorName(johnSmith.getName(), + final Page
articleByAuthorName = articleRepository.findByAuthorsName(johnSmith.getName(), PageRequest.of(0, 10)); assertEquals(2L, articleByAuthorName.getTotalElements()); } @Test public void givenCustomQuery_whenSearchByAuthorsName_thenArticleIsFound() { - final Page
articleByAuthorName = articleService.findByAuthorNameUsingCustomQuery("Smith", + final Page
articleByAuthorName = articleRepository.findByAuthorsNameUsingCustomQuery("Smith", PageRequest.of(0, 10)); assertEquals(2L, articleByAuthorName.getTotalElements()); } @Test public void givenTagFilterQuery_whenSearchByTag_thenArticleIsFound() { - final Page
articleByAuthorName = articleService.findByFilteredTagQuery("elasticsearch", + final Page
articleByAuthorName = articleRepository.findByFilteredTagQuery("elasticsearch", PageRequest.of(0, 10)); assertEquals(3L, articleByAuthorName.getTotalElements()); } @Test public void givenTagFilterQuery_whenSearchByAuthorsName_thenArticleIsFound() { - final Page
articleByAuthorName = articleService.findByAuthorsNameAndFilteredTagQuery("Doe", + final Page
articleByAuthorName = articleRepository.findByAuthorsNameAndFilteredTagQuery("Doe", "elasticsearch", PageRequest.of(0, 10)); assertEquals(2L, articleByAuthorName.getTotalElements()); } @@ -133,9 +133,9 @@ public class ElasticSearchManualTest { final Article article = articles.get(0); final String newTitle = "Getting started with Search Engines"; article.setTitle(newTitle); - articleService.save(article); + articleRepository.save(article); - assertEquals(newTitle, articleService.findOne(article.getId()).get().getTitle()); + assertEquals(newTitle, articleRepository.findById(article.getId()).get().getTitle()); } @Test @@ -147,11 +147,11 @@ public class ElasticSearchManualTest { .withQuery(matchQuery("title", articleTitle).minimumShouldMatch("75%")).build(); final List
articles = elasticsearchTemplate.queryForList(searchQuery, Article.class); assertEquals(1, articles.size()); - final long count = articleService.count(); + final long count = articleRepository.count(); - articleService.delete(articles.get(0)); + articleRepository.delete(articles.get(0)); - assertEquals(count - 1, articleService.count()); + assertEquals(count - 1, articleRepository.count()); } @Test 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 438d3adf02..ff804daa20 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 @@ -17,7 +17,7 @@ import java.util.Map; import com.baeldung.spring.data.es.config.Config; import com.baeldung.spring.data.es.model.Article; import com.baeldung.spring.data.es.model.Author; -import com.baeldung.spring.data.es.service.ArticleService; +import com.baeldung.spring.data.es.repository.ArticleRepository; import org.apache.lucene.search.join.ScoreMode; import org.elasticsearch.action.search.SearchRequest; @@ -58,7 +58,7 @@ public class ElasticSearchQueryManualTest { private ElasticsearchRestTemplate elasticsearchTemplate; @Autowired - private ArticleService articleService; + private ArticleRepository articleRepository; @Autowired private RestHighLevelClient client; @@ -76,22 +76,22 @@ public class ElasticSearchQueryManualTest { Article article = new Article("Spring Data Elasticsearch"); article.setAuthors(asList(johnSmith, johnDoe)); article.setTags("elasticsearch", "spring data"); - articleService.save(article); + articleRepository.save(article); article = new Article("Search engines"); article.setAuthors(asList(johnDoe)); article.setTags("search engines", "tutorial"); - articleService.save(article); + articleRepository.save(article); article = new Article("Second Article About Elasticsearch"); article.setAuthors(asList(johnSmith)); article.setTags("elasticsearch", "spring data"); - articleService.save(article); + articleRepository.save(article); article = new Article("Elasticsearch Tutorial"); article.setAuthors(asList(johnDoe)); article.setTags("elasticsearch"); - articleService.save(article); + articleRepository.save(article); } @Test From 6f9e27dc5957a4a30549b8828d619ccda813e365 Mon Sep 17 00:00:00 2001 From: Mathieu Fortin Date: Wed, 29 Apr 2020 21:23:48 -0400 Subject: [PATCH 020/140] fixed most tests --- .../spring-data-elasticsearch/pom.xml | 27 ++-- .../com/baeldung/SpringContextManualTest.java | 6 +- .../ElasticSearchManualTest.java | 53 ++++--- .../elasticsearch/GeoQueriesManualTest.java | 136 ++++++++++++------ .../data/es/ElasticSearchManualTest.java | 51 +++---- .../data/es/ElasticSearchQueryManualTest.java | 114 +++++++++------ 6 files changed, 237 insertions(+), 150 deletions(-) diff --git a/persistence-modules/spring-data-elasticsearch/pom.xml b/persistence-modules/spring-data-elasticsearch/pom.xml index e2089eb8b1..72860cb136 100644 --- a/persistence-modules/spring-data-elasticsearch/pom.xml +++ b/persistence-modules/spring-data-elasticsearch/pom.xml @@ -52,13 +52,13 @@ org.locationtech.jts jts-core - 1.16.1 - - - - org.apache.logging.log4j - log4j-core - ${log4j.version} + 1.15.0 + + + xerces + xercesImpl + + @@ -77,12 +77,19 @@ - 3.2.6.RELEASE + 4.0.0.RC1 4.5.2 1.2.47 - 0.6 + 0.7 1.13 - 2.9.1 + + + repository.spring.milestone + Spring Milestone Repository + https://repo.spring.io/milestone + + + \ No newline at end of file diff --git a/persistence-modules/spring-data-elasticsearch/src/test/java/com/baeldung/SpringContextManualTest.java b/persistence-modules/spring-data-elasticsearch/src/test/java/com/baeldung/SpringContextManualTest.java index 2e9352b081..5087862061 100644 --- a/persistence-modules/spring-data-elasticsearch/src/test/java/com/baeldung/SpringContextManualTest.java +++ b/persistence-modules/spring-data-elasticsearch/src/test/java/com/baeldung/SpringContextManualTest.java @@ -8,9 +8,9 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import com.baeldung.spring.data.es.config.Config; /** - * - * This Manual test requires: * Elasticsearch instance running on host - * + * This Manual test requires: * Elasticsearch instance running on localhost:9200. + * The following docker command can be used: + * docker run -d --name es761 -p 9200:9200 -e "discovery.type=single-node" elasticsearch:7.6.1 */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = Config.class) diff --git a/persistence-modules/spring-data-elasticsearch/src/test/java/com/baeldung/elasticsearch/ElasticSearchManualTest.java b/persistence-modules/spring-data-elasticsearch/src/test/java/com/baeldung/elasticsearch/ElasticSearchManualTest.java index f8f70c58a4..3402a10b81 100644 --- a/persistence-modules/spring-data-elasticsearch/src/test/java/com/baeldung/elasticsearch/ElasticSearchManualTest.java +++ b/persistence-modules/spring-data-elasticsearch/src/test/java/com/baeldung/elasticsearch/ElasticSearchManualTest.java @@ -9,12 +9,15 @@ import java.util.Arrays; import java.util.Date; import java.util.List; import java.util.stream.Collectors; +import java.util.stream.Stream; import com.alibaba.fastjson.JSON; import org.elasticsearch.action.DocWriteResponse.Result; import org.elasticsearch.action.delete.DeleteRequest; import org.elasticsearch.action.delete.DeleteResponse; +import org.elasticsearch.action.get.GetRequest; +import org.elasticsearch.action.get.GetResponse; import org.elasticsearch.action.index.IndexRequest; import org.elasticsearch.action.index.IndexResponse; import org.elasticsearch.action.search.SearchRequest; @@ -34,10 +37,9 @@ import org.springframework.data.elasticsearch.client.ClientConfiguration; import org.springframework.data.elasticsearch.client.RestClients; /** - * - * This Manual test requires: * Elasticsearch instance running on host * with - * cluster name = elasticsearch - * + * This Manual test requires: * Elasticsearch instance running on localhost:9200. + * The following docker command can be used: + * docker run -d --name es761 -p 9200:9200 -e "discovery.type=single-node" elasticsearch:7.6.1 */ public class ElasticSearchManualTest { private List listOfPersons = new ArrayList<>(); @@ -57,28 +59,35 @@ public class ElasticSearchManualTest { @Test public void givenJsonString_whenJavaObject_thenIndexDocument() throws Exception { String jsonObject = "{\"age\":20,\"dateOfBirth\":1471466076564,\"fullName\":\"John Doe\"}"; - IndexRequest request = new IndexRequest("people", "Doe"); + IndexRequest request = new IndexRequest("people"); request.source(jsonObject, XContentType.JSON); - + IndexResponse response = client.index(request, RequestOptions.DEFAULT); String index = response.getIndex(); - + long version = response.getVersion(); + assertEquals(Result.CREATED, response.getResult()); - assertEquals(index, "people"); + assertEquals(1, version); + assertEquals("people", index); } @Test public void givenDocumentId_whenJavaObject_thenDeleteDocument() throws Exception { String jsonObject = "{\"age\":10,\"dateOfBirth\":1471455886564,\"fullName\":\"Johan Doe\"}"; - IndexRequest indexRequest = new IndexRequest("people", "Doe"); + IndexRequest indexRequest = new IndexRequest("people"); indexRequest.source(jsonObject, XContentType.JSON); IndexResponse response = client.index(indexRequest, RequestOptions.DEFAULT); String id = response.getId(); + GetRequest getRequest = new GetRequest("people"); + getRequest.id(id); + + GetResponse getResponse = client.get(getRequest, RequestOptions.DEFAULT); + System.out.println(getResponse.getSourceAsString()); + DeleteRequest deleteRequest = new DeleteRequest("people"); deleteRequest.id(id); - deleteRequest.type("Doe"); DeleteResponse deleteResponse = client.delete(deleteRequest, RequestOptions.DEFAULT); @@ -98,8 +107,8 @@ public class ElasticSearchManualTest { @Test public void givenSearchParameters_thenReturnResults() throws Exception { - SearchSourceBuilder builder = new SearchSourceBuilder().postFilter(QueryBuilders.rangeQuery("age").from(5).to(15)) - .from(0).size(60).explain(true); + SearchSourceBuilder builder = + new SearchSourceBuilder().postFilter(QueryBuilders.rangeQuery("age").from(5).to(15)); SearchRequest searchRequest = new SearchRequest(); searchRequest.searchType(SearchType.DFS_QUERY_THEN_FETCH); @@ -107,8 +116,7 @@ public class ElasticSearchManualTest { SearchResponse response = client.search(searchRequest, RequestOptions.DEFAULT); - builder = new SearchSourceBuilder().postFilter(QueryBuilders.simpleQueryStringQuery("+John -Doe OR Janette")) - .from(0).size(60).explain(true); + builder = new SearchSourceBuilder().postFilter(QueryBuilders.simpleQueryStringQuery("+John -Doe OR Janette")); searchRequest = new SearchRequest(); searchRequest.searchType(SearchType.DFS_QUERY_THEN_FETCH); @@ -116,8 +124,7 @@ public class ElasticSearchManualTest { SearchResponse response2 = client.search(searchRequest, RequestOptions.DEFAULT); - builder = new SearchSourceBuilder().postFilter(QueryBuilders.matchQuery("John", "Name*")).from(0).size(60) - .explain(true); + builder = new SearchSourceBuilder().postFilter(QueryBuilders.matchQuery("John", "Name*")); searchRequest = new SearchRequest(); searchRequest.searchType(SearchType.DFS_QUERY_THEN_FETCH); searchRequest.source(builder); @@ -126,9 +133,15 @@ public class ElasticSearchManualTest { response2.getHits(); response3.getHits(); - - final List results = Arrays.stream(response.getHits().getHits()) - .map(hit -> JSON.parseObject(hit.getSourceAsString(), Person.class)).collect(Collectors.toList()); + + final List results = + Stream.of(response.getHits().getHits(), + response2.getHits().getHits(), + response3.getHits().getHits()) + .flatMap(Arrays::stream) + .map(hit -> JSON.parseObject(hit.getSourceAsString(), Person.class)) + .collect(Collectors.toList()); + results.forEach(System.out::println); } @@ -137,7 +150,7 @@ public class ElasticSearchManualTest { XContentBuilder builder = XContentFactory.jsonBuilder().startObject().field("fullName", "Test") .field("salary", "11500").field("age", "10").endObject(); - IndexRequest indexRequest = new IndexRequest("people", "Doe"); + IndexRequest indexRequest = new IndexRequest("people"); indexRequest.source(builder); IndexResponse response = client.index(indexRequest, RequestOptions.DEFAULT); diff --git a/persistence-modules/spring-data-elasticsearch/src/test/java/com/baeldung/elasticsearch/GeoQueriesManualTest.java b/persistence-modules/spring-data-elasticsearch/src/test/java/com/baeldung/elasticsearch/GeoQueriesManualTest.java index e373fef7a6..bd54183263 100644 --- a/persistence-modules/spring-data-elasticsearch/src/test/java/com/baeldung/elasticsearch/GeoQueriesManualTest.java +++ b/persistence-modules/spring-data-elasticsearch/src/test/java/com/baeldung/elasticsearch/GeoQueriesManualTest.java @@ -8,71 +8,84 @@ import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; -import org.elasticsearch.action.admin.indices.create.CreateIndexRequest; +import com.baeldung.spring.data.es.config.Config; + +import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest; +import org.elasticsearch.action.admin.indices.refresh.RefreshRequest; +import org.elasticsearch.action.index.IndexRequest; import org.elasticsearch.action.index.IndexResponse; +import org.elasticsearch.action.search.SearchRequest; import org.elasticsearch.action.search.SearchResponse; -import org.elasticsearch.client.Client; +import org.elasticsearch.client.RequestOptions; +import org.elasticsearch.client.RestHighLevelClient; +import org.elasticsearch.client.indices.CreateIndexRequest; import org.elasticsearch.common.geo.GeoPoint; +import org.elasticsearch.common.geo.ShapeRelation; import org.elasticsearch.common.geo.builders.EnvelopeBuilder; import org.elasticsearch.common.unit.DistanceUnit; import org.elasticsearch.common.xcontent.XContentType; +import org.elasticsearch.index.query.GeoShapeQueryBuilder; import org.elasticsearch.index.query.QueryBuilder; import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.search.SearchHit; +import org.elasticsearch.search.builder.SearchSourceBuilder; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.locationtech.jts.geom.Coordinate; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.elasticsearch.core.ElasticsearchTemplate; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import com.baeldung.spring.data.es.config.Config; - /** - * - * This Manual test requires: * Elasticsearch instance running on host * with - * cluster name = elasticsearch * and further configurations - * + * This Manual test requires: * Elasticsearch instance running on localhost:9200. + * The following docker command can be used: + * docker run -d --name es761 -p 9200:9200 -e "discovery.type=single-node" elasticsearch:7.6.1 */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = Config.class) public class GeoQueriesManualTest { private static final String WONDERS_OF_WORLD = "wonders-of-world"; - private static final String WONDERS = "Wonders"; @Autowired - private ElasticsearchTemplate elasticsearchTemplate; - - @Autowired - private Client client; + private RestHighLevelClient client; @Before - public void setUp() { - String jsonObject = "{\"Wonders\":{\"properties\":{\"name\":{\"type\":\"string\",\"index\":\"not_analyzed\"},\"region\":{\"type\":\"geo_shape\",\"tree\":\"quadtree\",\"precision\":\"1m\"},\"location\":{\"type\":\"geo_point\"}}}}"; + public void setUp() throws Exception { + String jsonObject = "{\"properties\":{\"name\":{\"type\":\"text\",\"index\":false},\"region\":{\"type\":\"geo_shape\"},\"location\":{\"type\":\"geo_point\"}}}"; + CreateIndexRequest req = new CreateIndexRequest(WONDERS_OF_WORLD); - req.mapping(WONDERS, jsonObject, XContentType.JSON); - client.admin().indices().create(req).actionGet(); + req.mapping(jsonObject, XContentType.JSON); + + client.indices().create(req, RequestOptions.DEFAULT); } @Test public void givenGeoShapeData_whenExecutedGeoShapeQuery_thenResultNonEmpty() throws IOException { String jsonObject = "{\"name\":\"Agra\",\"region\":{\"type\":\"envelope\",\"coordinates\":[[75,30.2],[80.1, 25]]}}"; - IndexResponse response = client.prepareIndex(WONDERS_OF_WORLD, WONDERS).setSource(jsonObject, XContentType.JSON) - .get(); + IndexRequest indexRequest = new IndexRequest(WONDERS_OF_WORLD); + indexRequest.source(jsonObject, XContentType.JSON); + IndexResponse response = client.index(indexRequest, RequestOptions.DEFAULT); String tajMahalId = response.getId(); - client.admin().indices().prepareRefresh(WONDERS_OF_WORLD).get(); + + RefreshRequest refreshRequest = new RefreshRequest(WONDERS_OF_WORLD); + client.indices().refresh(refreshRequest, RequestOptions.DEFAULT); Coordinate topLeft = new Coordinate(74, 31.2); Coordinate bottomRight = new Coordinate(81.1, 24); - QueryBuilder qb = QueryBuilders.geoShapeQuery("region", new EnvelopeBuilder(topLeft, bottomRight)); + + GeoShapeQueryBuilder qb = QueryBuilders.geoShapeQuery("region", + new EnvelopeBuilder(topLeft, bottomRight).buildGeometry()); + qb.relation(ShapeRelation.INTERSECTS); - SearchResponse searchResponse = client.prepareSearch(WONDERS_OF_WORLD).setTypes(WONDERS).setQuery(qb).execute() - .actionGet(); + SearchSourceBuilder source = new SearchSourceBuilder().query(qb); + SearchRequest searchRequest = new SearchRequest(WONDERS_OF_WORLD); + searchRequest.source(source); + + SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT); List ids = Arrays.stream(searchResponse.getHits().getHits()).map(SearchHit::getId) .collect(Collectors.toList()); @@ -81,62 +94,93 @@ public class GeoQueriesManualTest { } @Test - public void givenGeoPointData_whenExecutedGeoBoundingBoxQuery_thenResultNonEmpty() { + public void givenGeoPointData_whenExecutedGeoBoundingBoxQuery_thenResultNonEmpty() throws Exception { String jsonObject = "{\"name\":\"Pyramids of Giza\",\"location\":[31.131302,29.976480]}"; - IndexResponse response = client.prepareIndex(WONDERS_OF_WORLD, WONDERS).setSource(jsonObject, XContentType.JSON) - .get(); + + IndexRequest indexRequest = new IndexRequest(WONDERS_OF_WORLD); + indexRequest.source(jsonObject, XContentType.JSON); + IndexResponse response = client.index(indexRequest, RequestOptions.DEFAULT); + String pyramidsOfGizaId = response.getId(); - client.admin().indices().prepareRefresh(WONDERS_OF_WORLD).get(); + + RefreshRequest refreshRequest = new RefreshRequest(WONDERS_OF_WORLD); + client.indices().refresh(refreshRequest, RequestOptions.DEFAULT); QueryBuilder qb = QueryBuilders.geoBoundingBoxQuery("location").setCorners(31, 30, 28, 32); - SearchResponse searchResponse = client.prepareSearch(WONDERS_OF_WORLD).setTypes(WONDERS).setQuery(qb).execute() - .actionGet(); + SearchSourceBuilder source = new SearchSourceBuilder().query(qb); + SearchRequest searchRequest = new SearchRequest(WONDERS_OF_WORLD); + searchRequest.source(source); + + SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT); + List ids = Arrays.stream(searchResponse.getHits().getHits()).map(SearchHit::getId) .collect(Collectors.toList()); assertTrue(ids.contains(pyramidsOfGizaId)); } @Test - public void givenGeoPointData_whenExecutedGeoDistanceQuery_thenResultNonEmpty() { + public void givenGeoPointData_whenExecutedGeoDistanceQuery_thenResultNonEmpty() throws Exception { String jsonObject = "{\"name\":\"Lighthouse of alexandria\",\"location\":[31.131302,29.976480]}"; - IndexResponse response = client.prepareIndex(WONDERS_OF_WORLD, WONDERS).setSource(jsonObject, XContentType.JSON) - .get(); + + IndexRequest indexRequest = new IndexRequest(WONDERS_OF_WORLD); + indexRequest.source(jsonObject, XContentType.JSON); + IndexResponse response = client.index(indexRequest, RequestOptions.DEFAULT); + String lighthouseOfAlexandriaId = response.getId(); - client.admin().indices().prepareRefresh(WONDERS_OF_WORLD).get(); - QueryBuilder qb = QueryBuilders.geoDistanceQuery("location").point(29.976, 31.131).distance(10, DistanceUnit.MILES); + RefreshRequest refreshRequest = new RefreshRequest(WONDERS_OF_WORLD); + client.indices().refresh(refreshRequest, RequestOptions.DEFAULT); + + QueryBuilder qb = + QueryBuilders.geoDistanceQuery("location") + .point(29.976, 31.131) + .distance(10, DistanceUnit.MILES); + + SearchSourceBuilder source = new SearchSourceBuilder().query(qb); + SearchRequest searchRequest = new SearchRequest(WONDERS_OF_WORLD); + searchRequest.source(source); + + SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT); - SearchResponse searchResponse = client.prepareSearch(WONDERS_OF_WORLD).setTypes(WONDERS).setQuery(qb).execute() - .actionGet(); List ids = Arrays.stream(searchResponse.getHits().getHits()).map(SearchHit::getId) .collect(Collectors.toList()); assertTrue(ids.contains(lighthouseOfAlexandriaId)); } @Test - public void givenGeoPointData_whenExecutedGeoPolygonQuery_thenResultNonEmpty() { + public void givenGeoPointData_whenExecutedGeoPolygonQuery_thenResultNonEmpty() throws Exception { String jsonObject = "{\"name\":\"The Great Rann of Kutch\",\"location\":[69.859741,23.733732]}"; - IndexResponse response = client.prepareIndex(WONDERS_OF_WORLD, WONDERS).setSource(jsonObject, XContentType.JSON) - .get(); - String greatRannOfKutchid = response.getId(); - client.admin().indices().prepareRefresh(WONDERS_OF_WORLD).get(); + IndexRequest indexRequest = new IndexRequest(WONDERS_OF_WORLD); + indexRequest.source(jsonObject, XContentType.JSON); + IndexResponse response = client.index(indexRequest, RequestOptions.DEFAULT); + + String greatRannOfKutchid = response.getId(); + + RefreshRequest refreshRequest = new RefreshRequest(WONDERS_OF_WORLD); + client.indices().refresh(refreshRequest, RequestOptions.DEFAULT); + List allPoints = new ArrayList(); allPoints.add(new GeoPoint(22.733, 68.859)); allPoints.add(new GeoPoint(24.733, 68.859)); allPoints.add(new GeoPoint(23, 70.859)); QueryBuilder qb = QueryBuilders.geoPolygonQuery("location", allPoints); - SearchResponse searchResponse = client.prepareSearch(WONDERS_OF_WORLD).setTypes(WONDERS).setQuery(qb).execute() - .actionGet(); + SearchSourceBuilder source = new SearchSourceBuilder().query(qb); + SearchRequest searchRequest = new SearchRequest(WONDERS_OF_WORLD); + searchRequest.source(source); + + SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT); + List ids = Arrays.stream(searchResponse.getHits().getHits()).map(SearchHit::getId) .collect(Collectors.toList()); assertTrue(ids.contains(greatRannOfKutchid)); } @After - public void destroy() { - elasticsearchTemplate.deleteIndex(WONDERS_OF_WORLD); + public void destroy() throws Exception { + DeleteIndexRequest deleteIndex = new DeleteIndexRequest(WONDERS_OF_WORLD); + client.indices().delete(deleteIndex, RequestOptions.DEFAULT); } } 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 6e1d7d1b7d..e1c0994d3e 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,16 +22,17 @@ 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.SearchHits; +import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates; import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder; -import org.springframework.data.elasticsearch.core.query.SearchQuery; +import org.springframework.data.elasticsearch.core.query.Query; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** - * - * This Manual test requires: * Elasticsearch instance running on host * with - * cluster name = elasticsearch - * + * This Manual test requires: * Elasticsearch instance running on localhost:9200. + * The following docker command can be used: + * docker run -d --name es761 -p 9200:9200 -e "discovery.type=single-node" elasticsearch:7.6.1 */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = Config.class) @@ -48,8 +49,8 @@ public class ElasticSearchManualTest { @Before public void before() { - elasticsearchTemplate.deleteIndex(Article.class); - elasticsearchTemplate.createIndex(Article.class); + elasticsearchTemplate.indexOps(Article.class).delete(); + elasticsearchTemplate.indexOps(Article.class).create(); // don't call putMapping() to test the default mappings Article article = new Article("Spring Data Elasticsearch"); @@ -86,7 +87,6 @@ public class ElasticSearchManualTest { @Test public void givenPersistedArticles_whenSearchByAuthorsName_thenRightFound() { - final Page
articleByAuthorName = articleRepository.findByAuthorsName(johnSmith.getName(), PageRequest.of(0, 10)); assertEquals(2L, articleByAuthorName.getTotalElements()); @@ -115,22 +115,23 @@ public class ElasticSearchManualTest { @Test public void givenPersistedArticles_whenUseRegexQuery_thenRightArticlesFound() { - - final SearchQuery searchQuery = new NativeSearchQueryBuilder().withFilter(regexpQuery("title", ".*data.*")) + final Query searchQuery = new NativeSearchQueryBuilder().withFilter(regexpQuery("title", ".*data.*")) .build(); - final List
articles = elasticsearchTemplate.queryForList(searchQuery, Article.class); - assertEquals(1, articles.size()); + final SearchHits
articles = + elasticsearchTemplate.search(searchQuery, Article.class, IndexCoordinates.of("blog")); + + assertEquals(1, articles.getTotalHits()); } @Test public void givenSavedDoc_whenTitleUpdated_thenCouldFindByUpdatedTitle() { - final SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(fuzzyQuery("title", "serch")).build(); - final List
articles = elasticsearchTemplate.queryForList(searchQuery, Article.class); + final Query searchQuery = new NativeSearchQueryBuilder().withQuery(fuzzyQuery("title", "serch")).build(); + final SearchHits
articles = elasticsearchTemplate.search(searchQuery, Article.class, IndexCoordinates.of("blog")); - assertEquals(1, articles.size()); + assertEquals(1, articles.getTotalHits()); - final Article article = articles.get(0); + final Article article = articles.getSearchHit(0).getContent(); final String newTitle = "Getting started with Search Engines"; article.setTitle(newTitle); articleRepository.save(article); @@ -140,25 +141,27 @@ public class ElasticSearchManualTest { @Test public void givenSavedDoc_whenDelete_thenRemovedFromIndex() { - final String articleTitle = "Spring Data Elasticsearch"; - final SearchQuery searchQuery = new NativeSearchQueryBuilder() + final Query searchQuery = new NativeSearchQueryBuilder() .withQuery(matchQuery("title", articleTitle).minimumShouldMatch("75%")).build(); - final List
articles = elasticsearchTemplate.queryForList(searchQuery, Article.class); - assertEquals(1, articles.size()); + final SearchHits
articles = + elasticsearchTemplate.search(searchQuery, Article.class, IndexCoordinates.of("blog")); + + assertEquals(1, articles.getTotalHits()); final long count = articleRepository.count(); - articleRepository.delete(articles.get(0)); + articleRepository.delete(articles.getSearchHit(0).getContent()); assertEquals(count - 1, articleRepository.count()); } @Test public void givenSavedDoc_whenOneTermMatches_thenFindByTitle() { - final SearchQuery searchQuery = new NativeSearchQueryBuilder() + final Query searchQuery = new NativeSearchQueryBuilder() .withQuery(matchQuery("title", "Search engines").operator(AND)).build(); - final List
articles = elasticsearchTemplate.queryForList(searchQuery, Article.class); - assertEquals(1, articles.size()); + final SearchHits
articles = + elasticsearchTemplate.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 ff804daa20..2300ff50db 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 @@ -2,7 +2,6 @@ package com.baeldung.spring.data.es; import static java.util.Arrays.asList; import static java.util.stream.Collectors.toList; -import static org.elasticsearch.index.query.Operator.AND; import static org.elasticsearch.index.query.QueryBuilders.boolQuery; import static org.elasticsearch.index.query.QueryBuilders.matchPhraseQuery; import static org.elasticsearch.index.query.QueryBuilders.matchQuery; @@ -26,6 +25,7 @@ import org.elasticsearch.client.RequestOptions; import org.elasticsearch.client.RestHighLevelClient; import org.elasticsearch.common.unit.Fuzziness; import org.elasticsearch.index.query.MultiMatchQueryBuilder; +import org.elasticsearch.index.query.Operator; import org.elasticsearch.index.query.QueryBuilder; import org.elasticsearch.search.aggregations.Aggregation; import org.elasticsearch.search.aggregations.AggregationBuilders; @@ -39,16 +39,17 @@ 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.SearchHits; +import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates; +import org.springframework.data.elasticsearch.core.query.NativeSearchQuery; import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder; -import org.springframework.data.elasticsearch.core.query.SearchQuery; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** - * - * This Manual test requires: * Elasticsearch instance running on host * with - * cluster name = elasticsearch - * + * This Manual test requires: * Elasticsearch instance running on localhost:9200. + * The following docker command can be used: + * docker run -d --name es761 -p 9200:9200 -e "discovery.type=single-node" elasticsearch:7.6.1 */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = Config.class) @@ -68,10 +69,10 @@ public class ElasticSearchQueryManualTest { @Before public void before() { - elasticsearchTemplate.deleteIndex(Article.class); - elasticsearchTemplate.createIndex(Article.class); - elasticsearchTemplate.putMapping(Article.class); - elasticsearchTemplate.refresh(Article.class); + elasticsearchTemplate.indexOps(Article.class).delete(); + elasticsearchTemplate.indexOps(Article.class).create(); + elasticsearchTemplate.indexOps(Article.class).createMapping(); + elasticsearchTemplate.indexOps(Article.class).refresh();; Article article = new Article("Spring Data Elasticsearch"); article.setAuthors(asList(johnSmith, johnDoe)); @@ -96,40 +97,55 @@ public class ElasticSearchQueryManualTest { @Test public void givenFullTitle_whenRunMatchQuery_thenDocIsFound() { - final SearchQuery searchQuery = new NativeSearchQueryBuilder() - .withQuery(matchQuery("title", "Search engines").operator(AND)).build(); - final List
articles = elasticsearchTemplate.queryForList(searchQuery, Article.class); - assertEquals(1, articles.size()); + 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")); + assertEquals(1, articles.getTotalHits()); } @Test public void givenOneTermFromTitle_whenRunMatchQuery_thenDocIsFound() { - final SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchQuery("title", "Engines Solutions")) + final NativeSearchQuery searchQuery = + new NativeSearchQueryBuilder().withQuery(matchQuery("title", "Engines Solutions")) .build(); - final List
articles = elasticsearchTemplate.queryForList(searchQuery, Article.class); - assertEquals(1, articles.size()); - assertEquals("Search engines", articles.get(0).getTitle()); + + final SearchHits
articles = + elasticsearchTemplate.search(searchQuery, Article.class, IndexCoordinates.of("blog")); + + assertEquals(1, articles.getTotalHits()); + assertEquals("Search engines", articles.getSearchHit(0).getContent().getTitle()); } @Test public void givenPartTitle_whenRunMatchQuery_thenDocIsFound() { - final SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchQuery("title", "elasticsearch data")) + final NativeSearchQuery searchQuery = + new NativeSearchQueryBuilder().withQuery(matchQuery("title", "elasticsearch data")) .build(); - final List
articles = elasticsearchTemplate.queryForList(searchQuery, Article.class); - assertEquals(3, articles.size()); + + final SearchHits
articles = + elasticsearchTemplate.search(searchQuery, Article.class, IndexCoordinates.of("blog")); + + assertEquals(3, articles.getTotalHits()); } @Test public void givenFullTitle_whenRunMatchQueryOnVerbatimField_thenDocIsFound() { - SearchQuery searchQuery = new NativeSearchQueryBuilder() - .withQuery(matchQuery("title.verbatim", "Second Article About Elasticsearch")).build(); - List
articles = elasticsearchTemplate.queryForList(searchQuery, Article.class); - assertEquals(1, articles.size()); + NativeSearchQuery searchQuery = new NativeSearchQueryBuilder() + .withQuery(matchQuery("title.verbatim", "Second Article About Elasticsearch")) + .build(); - searchQuery = new NativeSearchQueryBuilder().withQuery(matchQuery("title.verbatim", "Second Article About")) - .build(); - articles = elasticsearchTemplate.queryForList(searchQuery, Article.class); - assertEquals(0, articles.size()); + SearchHits
articles = + elasticsearchTemplate.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")); + assertEquals(0, articles.getTotalHits()); } @Test @@ -137,10 +153,10 @@ public class ElasticSearchQueryManualTest { final QueryBuilder builder = nestedQuery("authors", boolQuery().must(termQuery("authors.name", "smith")), ScoreMode.None); - final SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(builder).build(); - final List
articles = elasticsearchTemplate.queryForList(searchQuery, Article.class); + final NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(builder).build(); + final SearchHits
articles = elasticsearchTemplate.search(searchQuery, Article.class, IndexCoordinates.of("blog")); - assertEquals(2, articles.size()); + assertEquals(2, articles.getTotalHits()); } @Test @@ -148,7 +164,7 @@ public class ElasticSearchQueryManualTest { final TermsAggregationBuilder aggregation = AggregationBuilders.terms("top_tags").field("title"); final SearchSourceBuilder builder = new SearchSourceBuilder().aggregation(aggregation); - final SearchRequest searchRequest = new SearchRequest("blog").types("article").source(builder); + final SearchRequest searchRequest = new SearchRequest("blog").source(builder); final SearchResponse response = client.search(searchRequest, RequestOptions.DEFAULT); @@ -167,7 +183,7 @@ public class ElasticSearchQueryManualTest { .order(BucketOrder.count(false)); final SearchSourceBuilder builder = new SearchSourceBuilder().aggregation(aggregation); - final SearchRequest searchRequest = new SearchRequest().indices("blog").types("article").source(builder); + final SearchRequest searchRequest = new SearchRequest().indices("blog").source(builder); final SearchResponse response = client.search(searchRequest, RequestOptions.DEFAULT); @@ -181,32 +197,36 @@ public class ElasticSearchQueryManualTest { @Test public void givenNotExactPhrase_whenUseSlop_thenQueryMatches() { - final SearchQuery searchQuery = new NativeSearchQueryBuilder() + final NativeSearchQuery searchQuery = new NativeSearchQueryBuilder() .withQuery(matchPhraseQuery("title", "spring elasticsearch").slop(1)).build(); - final List
articles = elasticsearchTemplate.queryForList(searchQuery, Article.class); - assertEquals(1, articles.size()); + + final SearchHits
articles = elasticsearchTemplate.search(searchQuery, Article.class, IndexCoordinates.of("blog")); + + assertEquals(1, articles.getTotalHits()); } @Test public void givenPhraseWithType_whenUseFuzziness_thenQueryMatches() { - final SearchQuery searchQuery = new NativeSearchQueryBuilder() + final NativeSearchQuery searchQuery = new NativeSearchQueryBuilder() .withQuery( - matchQuery("title", "spring date elasticserch").operator(AND).fuzziness(Fuzziness.ONE).prefixLength(3)) + matchQuery("title", "spring date elasticserch").operator(Operator.AND).fuzziness(Fuzziness.ONE).prefixLength(3)) .build(); - final List
articles = elasticsearchTemplate.queryForList(searchQuery, Article.class); - assertEquals(1, articles.size()); + final SearchHits
articles = elasticsearchTemplate.search(searchQuery, Article.class, IndexCoordinates.of("blog")); + + assertEquals(1, articles.getTotalHits()); } @Test public void givenMultimatchQuery_whenDoSearch_thenAllProvidedFieldsMatch() { - final SearchQuery searchQuery = new NativeSearchQueryBuilder() + final NativeSearchQuery searchQuery = new NativeSearchQueryBuilder() .withQuery( multiMatchQuery("tutorial").field("title").field("tags").type(MultiMatchQueryBuilder.Type.BEST_FIELDS)) .build(); - final List
articles = elasticsearchTemplate.queryForList(searchQuery, Article.class); - assertEquals(2, articles.size()); + final SearchHits
articles = elasticsearchTemplate.search(searchQuery, Article.class, IndexCoordinates.of("blog")); + + assertEquals(2, articles.getTotalHits()); } @Test @@ -215,9 +235,9 @@ public class ElasticSearchQueryManualTest { .must(nestedQuery("authors", boolQuery().must(termQuery("authors.name", "doe")), ScoreMode.None)) .filter(termQuery("tags", "elasticsearch")); - final SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(builder).build(); - final List
articles = elasticsearchTemplate.queryForList(searchQuery, Article.class); + final NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(builder).build(); + final SearchHits
articles = elasticsearchTemplate.search(searchQuery, Article.class, IndexCoordinates.of("blog")); - assertEquals(2, articles.size()); + assertEquals(2, articles.getTotalHits()); } } From 1ed9c7db328be10c999c321f3dbca82f29b011dc Mon Sep 17 00:00:00 2001 From: Mathieu Fortin Date: Tue, 12 May 2020 21:41:51 -0400 Subject: [PATCH 021/140] fixed mapping and tests --- .../com/baeldung/spring/data/es/model/Author.java | 5 +++++ .../com/baeldung/SpringContextManualTest.java | 4 +++- .../elasticsearch/ElasticSearchManualTest.java | 4 +++- .../elasticsearch/GeoQueriesManualTest.java | 4 +++- .../spring/data/es/ElasticSearchManualTest.java | 14 +++++++++----- .../data/es/ElasticSearchQueryManualTest.java | 15 +++++++++------ 6 files changed, 32 insertions(+), 14 deletions(-) diff --git a/persistence-modules/spring-data-elasticsearch/src/main/java/com/baeldung/spring/data/es/model/Author.java b/persistence-modules/spring-data-elasticsearch/src/main/java/com/baeldung/spring/data/es/model/Author.java index 38f50e1614..1d596cd92b 100644 --- a/persistence-modules/spring-data-elasticsearch/src/main/java/com/baeldung/spring/data/es/model/Author.java +++ b/persistence-modules/spring-data-elasticsearch/src/main/java/com/baeldung/spring/data/es/model/Author.java @@ -1,7 +1,12 @@ package com.baeldung.spring.data.es.model; +import static org.springframework.data.elasticsearch.annotations.FieldType.Text; + +import org.springframework.data.elasticsearch.annotations.Field; + public class Author { + @Field(type = Text) private String name; public Author() { diff --git a/persistence-modules/spring-data-elasticsearch/src/test/java/com/baeldung/SpringContextManualTest.java b/persistence-modules/spring-data-elasticsearch/src/test/java/com/baeldung/SpringContextManualTest.java index 5087862061..27b41649ee 100644 --- a/persistence-modules/spring-data-elasticsearch/src/test/java/com/baeldung/SpringContextManualTest.java +++ b/persistence-modules/spring-data-elasticsearch/src/test/java/com/baeldung/SpringContextManualTest.java @@ -8,7 +8,9 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import com.baeldung.spring.data.es.config.Config; /** - * This Manual test requires: * Elasticsearch instance running on localhost:9200. + * This Manual test requires: + * Elasticsearch instance running on localhost:9200. + * * The following docker command can be used: * docker run -d --name es761 -p 9200:9200 -e "discovery.type=single-node" elasticsearch:7.6.1 */ diff --git a/persistence-modules/spring-data-elasticsearch/src/test/java/com/baeldung/elasticsearch/ElasticSearchManualTest.java b/persistence-modules/spring-data-elasticsearch/src/test/java/com/baeldung/elasticsearch/ElasticSearchManualTest.java index 3402a10b81..d19a7a379f 100644 --- a/persistence-modules/spring-data-elasticsearch/src/test/java/com/baeldung/elasticsearch/ElasticSearchManualTest.java +++ b/persistence-modules/spring-data-elasticsearch/src/test/java/com/baeldung/elasticsearch/ElasticSearchManualTest.java @@ -37,7 +37,9 @@ import org.springframework.data.elasticsearch.client.ClientConfiguration; import org.springframework.data.elasticsearch.client.RestClients; /** - * This Manual test requires: * Elasticsearch instance running on localhost:9200. + * This Manual test requires: + * Elasticsearch instance running on localhost:9200. + * * The following docker command can be used: * docker run -d --name es761 -p 9200:9200 -e "discovery.type=single-node" elasticsearch:7.6.1 */ diff --git a/persistence-modules/spring-data-elasticsearch/src/test/java/com/baeldung/elasticsearch/GeoQueriesManualTest.java b/persistence-modules/spring-data-elasticsearch/src/test/java/com/baeldung/elasticsearch/GeoQueriesManualTest.java index bd54183263..ed67818d6c 100644 --- a/persistence-modules/spring-data-elasticsearch/src/test/java/com/baeldung/elasticsearch/GeoQueriesManualTest.java +++ b/persistence-modules/spring-data-elasticsearch/src/test/java/com/baeldung/elasticsearch/GeoQueriesManualTest.java @@ -39,7 +39,9 @@ import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** - * This Manual test requires: * Elasticsearch instance running on localhost:9200. + * This Manual test requires: + * Elasticsearch instance running on localhost:9200. + * * The following docker command can be used: * docker run -d --name es761 -p 9200:9200 -e "discovery.type=single-node" elasticsearch:7.6.1 */ 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 e1c0994d3e..87eab00da0 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 @@ -15,6 +15,7 @@ import com.baeldung.spring.data.es.model.Article; import com.baeldung.spring.data.es.model.Author; import com.baeldung.spring.data.es.repository.ArticleRepository; +import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -30,7 +31,9 @@ import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** - * This Manual test requires: * Elasticsearch instance running on localhost:9200. + * This Manual test requires: + * Elasticsearch instance running on localhost:9200. + * * The following docker command can be used: * docker run -d --name es761 -p 9200:9200 -e "discovery.type=single-node" elasticsearch:7.6.1 */ @@ -49,10 +52,6 @@ public class ElasticSearchManualTest { @Before public void before() { - elasticsearchTemplate.indexOps(Article.class).delete(); - elasticsearchTemplate.indexOps(Article.class).create(); - // don't call putMapping() to test the default mappings - Article article = new Article("Spring Data Elasticsearch"); article.setAuthors(asList(johnSmith, johnDoe)); article.setTags("elasticsearch", "spring data"); @@ -74,6 +73,11 @@ public class ElasticSearchManualTest { articleRepository.save(article); } + @After + public void after() { + articleRepository.deleteAll(); + } + @Test public void givenArticleService_whenSaveArticle_thenIdIsAssigned() { final List authors = asList(new Author("John Smith"), johnDoe); 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 2300ff50db..b9de9d51af 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 @@ -34,6 +34,7 @@ import org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation; import org.elasticsearch.search.aggregations.bucket.terms.ParsedStringTerms; import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder; import org.elasticsearch.search.builder.SearchSourceBuilder; +import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -47,7 +48,9 @@ import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** - * This Manual test requires: * Elasticsearch instance running on localhost:9200. + * This Manual test requires: + * Elasticsearch instance running on localhost:9200. + * * The following docker command can be used: * docker run -d --name es761 -p 9200:9200 -e "discovery.type=single-node" elasticsearch:7.6.1 */ @@ -69,11 +72,6 @@ public class ElasticSearchQueryManualTest { @Before public void before() { - elasticsearchTemplate.indexOps(Article.class).delete(); - elasticsearchTemplate.indexOps(Article.class).create(); - elasticsearchTemplate.indexOps(Article.class).createMapping(); - elasticsearchTemplate.indexOps(Article.class).refresh();; - Article article = new Article("Spring Data Elasticsearch"); article.setAuthors(asList(johnSmith, johnDoe)); article.setTags("elasticsearch", "spring data"); @@ -95,6 +93,11 @@ public class ElasticSearchQueryManualTest { articleRepository.save(article); } + @After + public void after() { + articleRepository.deleteAll(); + } + @Test public void givenFullTitle_whenRunMatchQuery_thenDocIsFound() { final NativeSearchQuery searchQuery = new NativeSearchQueryBuilder() From 40aa75eec10e32fd16237a5f0fbb3f583ca012c2 Mon Sep 17 00:00:00 2001 From: Mathieu Fortin Date: Tue, 19 May 2020 19:21:51 -0400 Subject: [PATCH 022/140] fixed formatting according to eclipse formatter --- .../spring/data/es/config/Config.java | 21 +- .../com/baeldung/SpringContextManualTest.java | 7 +- .../ElasticSearchManualTest.java | 199 ++++++------ .../elasticsearch/GeoQueriesManualTest.java | 228 ++++++------- .../data/es/ElasticSearchManualTest.java | 55 ++-- .../data/es/ElasticSearchQueryManualTest.java | 304 +++++++++--------- 6 files changed, 419 insertions(+), 395 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 f98342486f..51bbe73e9e 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 @@ -15,15 +15,18 @@ import org.springframework.data.elasticsearch.repository.config.EnableElasticsea @ComponentScan(basePackages = { "com.baeldung.spring.data.es.service" }) public class Config { - @Bean - RestHighLevelClient client() { - ClientConfiguration clientConfiguration = ClientConfiguration.builder().connectedTo("localhost:9200").build(); + @Bean + RestHighLevelClient client() { + ClientConfiguration clientConfiguration = ClientConfiguration.builder() + .connectedTo("localhost:9200") + .build(); - return RestClients.create(clientConfiguration).rest(); - } + return RestClients.create(clientConfiguration) + .rest(); + } - @Bean - public ElasticsearchOperations elasticsearchTemplate() { - return new ElasticsearchRestTemplate(client()); - } + @Bean + public ElasticsearchOperations elasticsearchTemplate() { + return new ElasticsearchRestTemplate(client()); + } } diff --git a/persistence-modules/spring-data-elasticsearch/src/test/java/com/baeldung/SpringContextManualTest.java b/persistence-modules/spring-data-elasticsearch/src/test/java/com/baeldung/SpringContextManualTest.java index 27b41649ee..bff910cf93 100644 --- a/persistence-modules/spring-data-elasticsearch/src/test/java/com/baeldung/SpringContextManualTest.java +++ b/persistence-modules/spring-data-elasticsearch/src/test/java/com/baeldung/SpringContextManualTest.java @@ -8,11 +8,10 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import com.baeldung.spring.data.es.config.Config; /** - * This Manual test requires: - * Elasticsearch instance running on localhost:9200. + * This Manual test requires: Elasticsearch instance running on localhost:9200. * - * The following docker command can be used: - * docker run -d --name es761 -p 9200:9200 -e "discovery.type=single-node" elasticsearch:7.6.1 + * The following docker command can be used: docker run -d --name es761 -p + * 9200:9200 -e "discovery.type=single-node" elasticsearch:7.6.1 */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = Config.class) diff --git a/persistence-modules/spring-data-elasticsearch/src/test/java/com/baeldung/elasticsearch/ElasticSearchManualTest.java b/persistence-modules/spring-data-elasticsearch/src/test/java/com/baeldung/elasticsearch/ElasticSearchManualTest.java index d19a7a379f..e4b3f6d801 100644 --- a/persistence-modules/spring-data-elasticsearch/src/test/java/com/baeldung/elasticsearch/ElasticSearchManualTest.java +++ b/persistence-modules/spring-data-elasticsearch/src/test/java/com/baeldung/elasticsearch/ElasticSearchManualTest.java @@ -37,126 +37,137 @@ import org.springframework.data.elasticsearch.client.ClientConfiguration; import org.springframework.data.elasticsearch.client.RestClients; /** - * This Manual test requires: - * Elasticsearch instance running on localhost:9200. + * This Manual test requires: Elasticsearch instance running on localhost:9200. * - * The following docker command can be used: - * docker run -d --name es761 -p 9200:9200 -e "discovery.type=single-node" elasticsearch:7.6.1 + * The following docker command can be used: docker run -d --name es761 -p + * 9200:9200 -e "discovery.type=single-node" elasticsearch:7.6.1 */ public class ElasticSearchManualTest { - private List listOfPersons = new ArrayList<>(); - private RestHighLevelClient client = null; + private List listOfPersons = new ArrayList<>(); + private RestHighLevelClient client = null; - @Before - public void setUp() throws UnknownHostException { - Person person1 = new Person(10, "John Doe", new Date()); - Person person2 = new Person(25, "Janette Doe", new Date()); - listOfPersons.add(person1); - listOfPersons.add(person2); + @Before + public void setUp() throws UnknownHostException { + Person person1 = new Person(10, "John Doe", new Date()); + Person person2 = new Person(25, "Janette Doe", new Date()); + listOfPersons.add(person1); + listOfPersons.add(person2); - ClientConfiguration clientConfiguration = ClientConfiguration.builder().connectedTo("localhost:9200").build(); - client = RestClients.create(clientConfiguration).rest(); - } + ClientConfiguration clientConfiguration = ClientConfiguration.builder() + .connectedTo("localhost:9200") + .build(); + client = RestClients.create(clientConfiguration) + .rest(); + } - @Test - public void givenJsonString_whenJavaObject_thenIndexDocument() throws Exception { - String jsonObject = "{\"age\":20,\"dateOfBirth\":1471466076564,\"fullName\":\"John Doe\"}"; - IndexRequest request = new IndexRequest("people"); - request.source(jsonObject, XContentType.JSON); - - IndexResponse response = client.index(request, RequestOptions.DEFAULT); - String index = response.getIndex(); - long version = response.getVersion(); - - assertEquals(Result.CREATED, response.getResult()); - assertEquals(1, version); - assertEquals("people", index); - } + @Test + public void givenJsonString_whenJavaObject_thenIndexDocument() throws Exception { + String jsonObject = "{\"age\":20,\"dateOfBirth\":1471466076564,\"fullName\":\"John Doe\"}"; + IndexRequest request = new IndexRequest("people"); + request.source(jsonObject, XContentType.JSON); - @Test - public void givenDocumentId_whenJavaObject_thenDeleteDocument() throws Exception { - String jsonObject = "{\"age\":10,\"dateOfBirth\":1471455886564,\"fullName\":\"Johan Doe\"}"; - IndexRequest indexRequest = new IndexRequest("people"); - indexRequest.source(jsonObject, XContentType.JSON); + IndexResponse response = client.index(request, RequestOptions.DEFAULT); + String index = response.getIndex(); + long version = response.getVersion(); - IndexResponse response = client.index(indexRequest, RequestOptions.DEFAULT); - String id = response.getId(); + assertEquals(Result.CREATED, response.getResult()); + assertEquals(1, version); + assertEquals("people", index); + } - GetRequest getRequest = new GetRequest("people"); - getRequest.id(id); + @Test + public void givenDocumentId_whenJavaObject_thenDeleteDocument() throws Exception { + String jsonObject = "{\"age\":10,\"dateOfBirth\":1471455886564,\"fullName\":\"Johan Doe\"}"; + IndexRequest indexRequest = new IndexRequest("people"); + indexRequest.source(jsonObject, XContentType.JSON); - GetResponse getResponse = client.get(getRequest, RequestOptions.DEFAULT); - System.out.println(getResponse.getSourceAsString()); + IndexResponse response = client.index(indexRequest, RequestOptions.DEFAULT); + String id = response.getId(); - DeleteRequest deleteRequest = new DeleteRequest("people"); - deleteRequest.id(id); + GetRequest getRequest = new GetRequest("people"); + getRequest.id(id); - DeleteResponse deleteResponse = client.delete(deleteRequest, RequestOptions.DEFAULT); + GetResponse getResponse = client.get(getRequest, RequestOptions.DEFAULT); + System.out.println(getResponse.getSourceAsString()); - assertEquals(Result.DELETED, deleteResponse.getResult()); - } + DeleteRequest deleteRequest = new DeleteRequest("people"); + deleteRequest.id(id); - @Test - public void givenSearchRequest_whenMatchAll_thenReturnAllResults() throws Exception { - SearchRequest searchRequest = new SearchRequest(); - SearchResponse response = client.search(searchRequest, RequestOptions.DEFAULT); - SearchHit[] searchHits = response.getHits().getHits(); - List results = Arrays.stream(searchHits).map(hit -> JSON.parseObject(hit.getSourceAsString(), Person.class)) - .collect(Collectors.toList()); + DeleteResponse deleteResponse = client.delete(deleteRequest, RequestOptions.DEFAULT); - results.forEach(System.out::println); - } + assertEquals(Result.DELETED, deleteResponse.getResult()); + } - @Test - public void givenSearchParameters_thenReturnResults() throws Exception { - SearchSourceBuilder builder = - new SearchSourceBuilder().postFilter(QueryBuilders.rangeQuery("age").from(5).to(15)); + @Test + public void givenSearchRequest_whenMatchAll_thenReturnAllResults() throws Exception { + SearchRequest searchRequest = new SearchRequest(); + SearchResponse response = client.search(searchRequest, RequestOptions.DEFAULT); + SearchHit[] searchHits = response.getHits() + .getHits(); + List results = Arrays.stream(searchHits) + .map(hit -> JSON.parseObject(hit.getSourceAsString(), Person.class)) + .collect(Collectors.toList()); - SearchRequest searchRequest = new SearchRequest(); - searchRequest.searchType(SearchType.DFS_QUERY_THEN_FETCH); - searchRequest.source(builder); + results.forEach(System.out::println); + } - SearchResponse response = client.search(searchRequest, RequestOptions.DEFAULT); + @Test + public void givenSearchParameters_thenReturnResults() throws Exception { + SearchSourceBuilder builder = new SearchSourceBuilder().postFilter(QueryBuilders.rangeQuery("age") + .from(5) + .to(15)); - builder = new SearchSourceBuilder().postFilter(QueryBuilders.simpleQueryStringQuery("+John -Doe OR Janette")); + SearchRequest searchRequest = new SearchRequest(); + searchRequest.searchType(SearchType.DFS_QUERY_THEN_FETCH); + searchRequest.source(builder); - searchRequest = new SearchRequest(); - searchRequest.searchType(SearchType.DFS_QUERY_THEN_FETCH); - searchRequest.source(builder); + SearchResponse response = client.search(searchRequest, RequestOptions.DEFAULT); - SearchResponse response2 = client.search(searchRequest, RequestOptions.DEFAULT); + builder = new SearchSourceBuilder().postFilter(QueryBuilders.simpleQueryStringQuery("+John -Doe OR Janette")); - builder = new SearchSourceBuilder().postFilter(QueryBuilders.matchQuery("John", "Name*")); - searchRequest = new SearchRequest(); - searchRequest.searchType(SearchType.DFS_QUERY_THEN_FETCH); - searchRequest.source(builder); + searchRequest = new SearchRequest(); + searchRequest.searchType(SearchType.DFS_QUERY_THEN_FETCH); + searchRequest.source(builder); - SearchResponse response3 = client.search(searchRequest, RequestOptions.DEFAULT); + SearchResponse response2 = client.search(searchRequest, RequestOptions.DEFAULT); - response2.getHits(); - response3.getHits(); - - final List results = - Stream.of(response.getHits().getHits(), - response2.getHits().getHits(), - response3.getHits().getHits()) - .flatMap(Arrays::stream) - .map(hit -> JSON.parseObject(hit.getSourceAsString(), Person.class)) - .collect(Collectors.toList()); - - results.forEach(System.out::println); - } + builder = new SearchSourceBuilder().postFilter(QueryBuilders.matchQuery("John", "Name*")); + searchRequest = new SearchRequest(); + searchRequest.searchType(SearchType.DFS_QUERY_THEN_FETCH); + searchRequest.source(builder); - @Test - public void givenContentBuilder_whenHelpers_thanIndexJson() throws IOException { - XContentBuilder builder = XContentFactory.jsonBuilder().startObject().field("fullName", "Test") - .field("salary", "11500").field("age", "10").endObject(); + SearchResponse response3 = client.search(searchRequest, RequestOptions.DEFAULT); - IndexRequest indexRequest = new IndexRequest("people"); - indexRequest.source(builder); + response2.getHits(); + response3.getHits(); - IndexResponse response = client.index(indexRequest, RequestOptions.DEFAULT); + final List results = Stream.of(response.getHits() + .getHits(), + response2.getHits() + .getHits(), + response3.getHits() + .getHits()) + .flatMap(Arrays::stream) + .map(hit -> JSON.parseObject(hit.getSourceAsString(), Person.class)) + .collect(Collectors.toList()); - assertEquals(Result.CREATED, response.getResult()); - } + results.forEach(System.out::println); + } + + @Test + public void givenContentBuilder_whenHelpers_thanIndexJson() throws IOException { + XContentBuilder builder = XContentFactory.jsonBuilder() + .startObject() + .field("fullName", "Test") + .field("salary", "11500") + .field("age", "10") + .endObject(); + + IndexRequest indexRequest = new IndexRequest("people"); + indexRequest.source(builder); + + IndexResponse response = client.index(indexRequest, RequestOptions.DEFAULT); + + assertEquals(Result.CREATED, response.getResult()); + } } diff --git a/persistence-modules/spring-data-elasticsearch/src/test/java/com/baeldung/elasticsearch/GeoQueriesManualTest.java b/persistence-modules/spring-data-elasticsearch/src/test/java/com/baeldung/elasticsearch/GeoQueriesManualTest.java index ed67818d6c..a36e08d6d2 100644 --- a/persistence-modules/spring-data-elasticsearch/src/test/java/com/baeldung/elasticsearch/GeoQueriesManualTest.java +++ b/persistence-modules/spring-data-elasticsearch/src/test/java/com/baeldung/elasticsearch/GeoQueriesManualTest.java @@ -39,150 +39,162 @@ import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** - * This Manual test requires: - * Elasticsearch instance running on localhost:9200. + * This Manual test requires: Elasticsearch instance running on localhost:9200. * - * The following docker command can be used: - * docker run -d --name es761 -p 9200:9200 -e "discovery.type=single-node" elasticsearch:7.6.1 + * The following docker command can be used: docker run -d --name es761 -p + * 9200:9200 -e "discovery.type=single-node" elasticsearch:7.6.1 */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = Config.class) public class GeoQueriesManualTest { - private static final String WONDERS_OF_WORLD = "wonders-of-world"; + private static final String WONDERS_OF_WORLD = "wonders-of-world"; - @Autowired - private RestHighLevelClient client; + @Autowired + private RestHighLevelClient client; - @Before - public void setUp() throws Exception { - String jsonObject = "{\"properties\":{\"name\":{\"type\":\"text\",\"index\":false},\"region\":{\"type\":\"geo_shape\"},\"location\":{\"type\":\"geo_point\"}}}"; - - CreateIndexRequest req = new CreateIndexRequest(WONDERS_OF_WORLD); - req.mapping(jsonObject, XContentType.JSON); + @Before + public void setUp() throws Exception { + String jsonObject = "{\"properties\":{\"name\":{\"type\":\"text\",\"index\":false},\"region\":{\"type\":\"geo_shape\"},\"location\":{\"type\":\"geo_point\"}}}"; - client.indices().create(req, RequestOptions.DEFAULT); - } + CreateIndexRequest req = new CreateIndexRequest(WONDERS_OF_WORLD); + req.mapping(jsonObject, XContentType.JSON); - @Test - public void givenGeoShapeData_whenExecutedGeoShapeQuery_thenResultNonEmpty() throws IOException { - String jsonObject = "{\"name\":\"Agra\",\"region\":{\"type\":\"envelope\",\"coordinates\":[[75,30.2],[80.1, 25]]}}"; - IndexRequest indexRequest = new IndexRequest(WONDERS_OF_WORLD); - indexRequest.source(jsonObject, XContentType.JSON); - IndexResponse response = client.index(indexRequest, RequestOptions.DEFAULT); + client.indices() + .create(req, RequestOptions.DEFAULT); + } - String tajMahalId = response.getId(); + @Test + public void givenGeoShapeData_whenExecutedGeoShapeQuery_thenResultNonEmpty() throws IOException { + String jsonObject = "{\"name\":\"Agra\",\"region\":{\"type\":\"envelope\",\"coordinates\":[[75,30.2],[80.1, 25]]}}"; + IndexRequest indexRequest = new IndexRequest(WONDERS_OF_WORLD); + indexRequest.source(jsonObject, XContentType.JSON); + IndexResponse response = client.index(indexRequest, RequestOptions.DEFAULT); - RefreshRequest refreshRequest = new RefreshRequest(WONDERS_OF_WORLD); - client.indices().refresh(refreshRequest, RequestOptions.DEFAULT); + String tajMahalId = response.getId(); - Coordinate topLeft = new Coordinate(74, 31.2); - Coordinate bottomRight = new Coordinate(81.1, 24); - - GeoShapeQueryBuilder qb = QueryBuilders.geoShapeQuery("region", - new EnvelopeBuilder(topLeft, bottomRight).buildGeometry()); - qb.relation(ShapeRelation.INTERSECTS); + RefreshRequest refreshRequest = new RefreshRequest(WONDERS_OF_WORLD); + client.indices() + .refresh(refreshRequest, RequestOptions.DEFAULT); - SearchSourceBuilder source = new SearchSourceBuilder().query(qb); - SearchRequest searchRequest = new SearchRequest(WONDERS_OF_WORLD); - searchRequest.source(source); - - SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT); + Coordinate topLeft = new Coordinate(74, 31.2); + Coordinate bottomRight = new Coordinate(81.1, 24); - List ids = Arrays.stream(searchResponse.getHits().getHits()).map(SearchHit::getId) - .collect(Collectors.toList()); + GeoShapeQueryBuilder qb = QueryBuilders.geoShapeQuery("region", new EnvelopeBuilder(topLeft, bottomRight).buildGeometry()); + qb.relation(ShapeRelation.INTERSECTS); - assertTrue(ids.contains(tajMahalId)); - } + SearchSourceBuilder source = new SearchSourceBuilder().query(qb); + SearchRequest searchRequest = new SearchRequest(WONDERS_OF_WORLD); + searchRequest.source(source); - @Test - public void givenGeoPointData_whenExecutedGeoBoundingBoxQuery_thenResultNonEmpty() throws Exception { - String jsonObject = "{\"name\":\"Pyramids of Giza\",\"location\":[31.131302,29.976480]}"; + SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT); - IndexRequest indexRequest = new IndexRequest(WONDERS_OF_WORLD); - indexRequest.source(jsonObject, XContentType.JSON); - IndexResponse response = client.index(indexRequest, RequestOptions.DEFAULT); + List ids = Arrays.stream(searchResponse.getHits() + .getHits()) + .map(SearchHit::getId) + .collect(Collectors.toList()); - String pyramidsOfGizaId = response.getId(); + assertTrue(ids.contains(tajMahalId)); + } - RefreshRequest refreshRequest = new RefreshRequest(WONDERS_OF_WORLD); - client.indices().refresh(refreshRequest, RequestOptions.DEFAULT); + @Test + public void givenGeoPointData_whenExecutedGeoBoundingBoxQuery_thenResultNonEmpty() throws Exception { + String jsonObject = "{\"name\":\"Pyramids of Giza\",\"location\":[31.131302,29.976480]}"; - QueryBuilder qb = QueryBuilders.geoBoundingBoxQuery("location").setCorners(31, 30, 28, 32); + IndexRequest indexRequest = new IndexRequest(WONDERS_OF_WORLD); + indexRequest.source(jsonObject, XContentType.JSON); + IndexResponse response = client.index(indexRequest, RequestOptions.DEFAULT); - SearchSourceBuilder source = new SearchSourceBuilder().query(qb); - SearchRequest searchRequest = new SearchRequest(WONDERS_OF_WORLD); - searchRequest.source(source); + String pyramidsOfGizaId = response.getId(); - SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT); + RefreshRequest refreshRequest = new RefreshRequest(WONDERS_OF_WORLD); + client.indices() + .refresh(refreshRequest, RequestOptions.DEFAULT); - List ids = Arrays.stream(searchResponse.getHits().getHits()).map(SearchHit::getId) - .collect(Collectors.toList()); - assertTrue(ids.contains(pyramidsOfGizaId)); - } + QueryBuilder qb = QueryBuilders.geoBoundingBoxQuery("location") + .setCorners(31, 30, 28, 32); - @Test - public void givenGeoPointData_whenExecutedGeoDistanceQuery_thenResultNonEmpty() throws Exception { - String jsonObject = "{\"name\":\"Lighthouse of alexandria\",\"location\":[31.131302,29.976480]}"; - - IndexRequest indexRequest = new IndexRequest(WONDERS_OF_WORLD); - indexRequest.source(jsonObject, XContentType.JSON); - IndexResponse response = client.index(indexRequest, RequestOptions.DEFAULT); + SearchSourceBuilder source = new SearchSourceBuilder().query(qb); + SearchRequest searchRequest = new SearchRequest(WONDERS_OF_WORLD); + searchRequest.source(source); - String lighthouseOfAlexandriaId = response.getId(); + SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT); - RefreshRequest refreshRequest = new RefreshRequest(WONDERS_OF_WORLD); - client.indices().refresh(refreshRequest, RequestOptions.DEFAULT); + List ids = Arrays.stream(searchResponse.getHits() + .getHits()) + .map(SearchHit::getId) + .collect(Collectors.toList()); + assertTrue(ids.contains(pyramidsOfGizaId)); + } - QueryBuilder qb = - QueryBuilders.geoDistanceQuery("location") - .point(29.976, 31.131) - .distance(10, DistanceUnit.MILES); + @Test + public void givenGeoPointData_whenExecutedGeoDistanceQuery_thenResultNonEmpty() throws Exception { + String jsonObject = "{\"name\":\"Lighthouse of alexandria\",\"location\":[31.131302,29.976480]}"; - SearchSourceBuilder source = new SearchSourceBuilder().query(qb); - SearchRequest searchRequest = new SearchRequest(WONDERS_OF_WORLD); - searchRequest.source(source); + IndexRequest indexRequest = new IndexRequest(WONDERS_OF_WORLD); + indexRequest.source(jsonObject, XContentType.JSON); + IndexResponse response = client.index(indexRequest, RequestOptions.DEFAULT); - SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT); + String lighthouseOfAlexandriaId = response.getId(); - List ids = Arrays.stream(searchResponse.getHits().getHits()).map(SearchHit::getId) - .collect(Collectors.toList()); - assertTrue(ids.contains(lighthouseOfAlexandriaId)); - } + RefreshRequest refreshRequest = new RefreshRequest(WONDERS_OF_WORLD); + client.indices() + .refresh(refreshRequest, RequestOptions.DEFAULT); - @Test - public void givenGeoPointData_whenExecutedGeoPolygonQuery_thenResultNonEmpty() throws Exception { - String jsonObject = "{\"name\":\"The Great Rann of Kutch\",\"location\":[69.859741,23.733732]}"; + QueryBuilder qb = QueryBuilders.geoDistanceQuery("location") + .point(29.976, 31.131) + .distance(10, DistanceUnit.MILES); - IndexRequest indexRequest = new IndexRequest(WONDERS_OF_WORLD); - indexRequest.source(jsonObject, XContentType.JSON); - IndexResponse response = client.index(indexRequest, RequestOptions.DEFAULT); - - String greatRannOfKutchid = response.getId(); + SearchSourceBuilder source = new SearchSourceBuilder().query(qb); + SearchRequest searchRequest = new SearchRequest(WONDERS_OF_WORLD); + searchRequest.source(source); - RefreshRequest refreshRequest = new RefreshRequest(WONDERS_OF_WORLD); - client.indices().refresh(refreshRequest, RequestOptions.DEFAULT); - - List allPoints = new ArrayList(); - allPoints.add(new GeoPoint(22.733, 68.859)); - allPoints.add(new GeoPoint(24.733, 68.859)); - allPoints.add(new GeoPoint(23, 70.859)); - QueryBuilder qb = QueryBuilders.geoPolygonQuery("location", allPoints); + SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT); - SearchSourceBuilder source = new SearchSourceBuilder().query(qb); - SearchRequest searchRequest = new SearchRequest(WONDERS_OF_WORLD); - searchRequest.source(source); + List ids = Arrays.stream(searchResponse.getHits() + .getHits()) + .map(SearchHit::getId) + .collect(Collectors.toList()); + assertTrue(ids.contains(lighthouseOfAlexandriaId)); + } - SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT); + @Test + public void givenGeoPointData_whenExecutedGeoPolygonQuery_thenResultNonEmpty() throws Exception { + String jsonObject = "{\"name\":\"The Great Rann of Kutch\",\"location\":[69.859741,23.733732]}"; - List ids = Arrays.stream(searchResponse.getHits().getHits()).map(SearchHit::getId) - .collect(Collectors.toList()); - assertTrue(ids.contains(greatRannOfKutchid)); - } + IndexRequest indexRequest = new IndexRequest(WONDERS_OF_WORLD); + indexRequest.source(jsonObject, XContentType.JSON); + IndexResponse response = client.index(indexRequest, RequestOptions.DEFAULT); - @After - public void destroy() throws Exception { - DeleteIndexRequest deleteIndex = new DeleteIndexRequest(WONDERS_OF_WORLD); - client.indices().delete(deleteIndex, RequestOptions.DEFAULT); - } + String greatRannOfKutchid = response.getId(); + + RefreshRequest refreshRequest = new RefreshRequest(WONDERS_OF_WORLD); + client.indices() + .refresh(refreshRequest, RequestOptions.DEFAULT); + + List allPoints = new ArrayList(); + allPoints.add(new GeoPoint(22.733, 68.859)); + allPoints.add(new GeoPoint(24.733, 68.859)); + allPoints.add(new GeoPoint(23, 70.859)); + QueryBuilder qb = QueryBuilders.geoPolygonQuery("location", allPoints); + + SearchSourceBuilder source = new SearchSourceBuilder().query(qb); + SearchRequest searchRequest = new SearchRequest(WONDERS_OF_WORLD); + searchRequest.source(source); + + SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT); + + List ids = Arrays.stream(searchResponse.getHits() + .getHits()) + .map(SearchHit::getId) + .collect(Collectors.toList()); + assertTrue(ids.contains(greatRannOfKutchid)); + } + + @After + public void destroy() throws Exception { + DeleteIndexRequest deleteIndex = new DeleteIndexRequest(WONDERS_OF_WORLD); + client.indices() + .delete(deleteIndex, RequestOptions.DEFAULT); + } } 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 87eab00da0..9f713a276f 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 @@ -31,11 +31,10 @@ import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** - * This Manual test requires: - * Elasticsearch instance running on localhost:9200. + * This Manual test requires: Elasticsearch instance running on localhost:9200. * - * The following docker command can be used: - * docker run -d --name es761 -p 9200:9200 -e "discovery.type=single-node" elasticsearch:7.6.1 + * The following docker command can be used: docker run -d --name es761 -p + * 9200:9200 -e "discovery.type=single-node" elasticsearch:7.6.1 */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = Config.class) @@ -77,7 +76,7 @@ public class ElasticSearchManualTest { public void after() { articleRepository.deleteAll(); } - + @Test public void givenArticleService_whenSaveArticle_thenIdIsAssigned() { final List authors = asList(new Author("John Smith"), johnDoe); @@ -91,81 +90,79 @@ public class ElasticSearchManualTest { @Test public void givenPersistedArticles_whenSearchByAuthorsName_thenRightFound() { - final Page
articleByAuthorName = articleRepository.findByAuthorsName(johnSmith.getName(), - PageRequest.of(0, 10)); + final Page
articleByAuthorName = articleRepository.findByAuthorsName(johnSmith.getName(), PageRequest.of(0, 10)); assertEquals(2L, articleByAuthorName.getTotalElements()); } @Test public void givenCustomQuery_whenSearchByAuthorsName_thenArticleIsFound() { - final Page
articleByAuthorName = articleRepository.findByAuthorsNameUsingCustomQuery("Smith", - PageRequest.of(0, 10)); + final Page
articleByAuthorName = articleRepository.findByAuthorsNameUsingCustomQuery("Smith", PageRequest.of(0, 10)); assertEquals(2L, articleByAuthorName.getTotalElements()); } @Test public void givenTagFilterQuery_whenSearchByTag_thenArticleIsFound() { - final Page
articleByAuthorName = articleRepository.findByFilteredTagQuery("elasticsearch", - PageRequest.of(0, 10)); + final Page
articleByAuthorName = articleRepository.findByFilteredTagQuery("elasticsearch", PageRequest.of(0, 10)); assertEquals(3L, articleByAuthorName.getTotalElements()); } @Test public void givenTagFilterQuery_whenSearchByAuthorsName_thenArticleIsFound() { - final Page
articleByAuthorName = articleRepository.findByAuthorsNameAndFilteredTagQuery("Doe", - "elasticsearch", PageRequest.of(0, 10)); + final Page
articleByAuthorName = articleRepository.findByAuthorsNameAndFilteredTagQuery("Doe", "elasticsearch", PageRequest.of(0, 10)); assertEquals(2L, articleByAuthorName.getTotalElements()); } @Test public void givenPersistedArticles_whenUseRegexQuery_thenRightArticlesFound() { final Query searchQuery = new NativeSearchQueryBuilder().withFilter(regexpQuery("title", ".*data.*")) - .build(); + .build(); - final SearchHits
articles = - elasticsearchTemplate.search(searchQuery, Article.class, IndexCoordinates.of("blog")); + final SearchHits
articles = elasticsearchTemplate.search(searchQuery, Article.class, IndexCoordinates.of("blog")); assertEquals(1, articles.getTotalHits()); } @Test public void givenSavedDoc_whenTitleUpdated_thenCouldFindByUpdatedTitle() { - final Query searchQuery = new NativeSearchQueryBuilder().withQuery(fuzzyQuery("title", "serch")).build(); + final Query searchQuery = new NativeSearchQueryBuilder().withQuery(fuzzyQuery("title", "serch")) + .build(); final SearchHits
articles = elasticsearchTemplate.search(searchQuery, Article.class, IndexCoordinates.of("blog")); assertEquals(1, articles.getTotalHits()); - final Article article = articles.getSearchHit(0).getContent(); + final Article article = articles.getSearchHit(0) + .getContent(); final String newTitle = "Getting started with Search Engines"; article.setTitle(newTitle); articleRepository.save(article); - assertEquals(newTitle, articleRepository.findById(article.getId()).get().getTitle()); + assertEquals(newTitle, articleRepository.findById(article.getId()) + .get() + .getTitle()); } @Test public void givenSavedDoc_whenDelete_thenRemovedFromIndex() { final String articleTitle = "Spring Data Elasticsearch"; - final Query searchQuery = new NativeSearchQueryBuilder() - .withQuery(matchQuery("title", articleTitle).minimumShouldMatch("75%")).build(); - final SearchHits
articles = - elasticsearchTemplate.search(searchQuery, Article.class, IndexCoordinates.of("blog")); - + final Query searchQuery = new NativeSearchQueryBuilder().withQuery(matchQuery("title", articleTitle).minimumShouldMatch("75%")) + .build(); + final SearchHits
articles = elasticsearchTemplate.search(searchQuery, Article.class, IndexCoordinates.of("blog")); + assertEquals(1, articles.getTotalHits()); final long count = articleRepository.count(); - articleRepository.delete(articles.getSearchHit(0).getContent()); + articleRepository.delete(articles.getSearchHit(0) + .getContent()); assertEquals(count - 1, articleRepository.count()); } @Test 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 Query searchQuery = new NativeSearchQueryBuilder().withQuery(matchQuery("title", "Search engines").operator(AND)) + .build(); + final SearchHits
articles = elasticsearchTemplate.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 b9de9d51af..3cedab00e4 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 @@ -48,199 +48,201 @@ import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** - * This Manual test requires: - * Elasticsearch instance running on localhost:9200. + * This Manual test requires: Elasticsearch instance running on localhost:9200. * - * The following docker command can be used: - * docker run -d --name es761 -p 9200:9200 -e "discovery.type=single-node" elasticsearch:7.6.1 + * The following docker command can be used: docker run -d --name es761 -p + * 9200:9200 -e "discovery.type=single-node" elasticsearch:7.6.1 */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = Config.class) public class ElasticSearchQueryManualTest { - @Autowired - private ElasticsearchRestTemplate elasticsearchTemplate; + @Autowired + private ElasticsearchRestTemplate elasticsearchTemplate; - @Autowired - private ArticleRepository articleRepository; + @Autowired + private ArticleRepository articleRepository; - @Autowired - private RestHighLevelClient client; + @Autowired + private RestHighLevelClient client; - private final Author johnSmith = new Author("John Smith"); - private final Author johnDoe = new Author("John Doe"); + private final Author johnSmith = new Author("John Smith"); + private final Author johnDoe = new Author("John Doe"); - @Before - public void before() { - Article article = new Article("Spring Data Elasticsearch"); - article.setAuthors(asList(johnSmith, johnDoe)); - article.setTags("elasticsearch", "spring data"); - articleRepository.save(article); + @Before + public void before() { + Article article = new Article("Spring Data Elasticsearch"); + article.setAuthors(asList(johnSmith, johnDoe)); + article.setTags("elasticsearch", "spring data"); + articleRepository.save(article); - article = new Article("Search engines"); - article.setAuthors(asList(johnDoe)); - article.setTags("search engines", "tutorial"); - articleRepository.save(article); + article = new Article("Search engines"); + article.setAuthors(asList(johnDoe)); + article.setTags("search engines", "tutorial"); + articleRepository.save(article); - article = new Article("Second Article About Elasticsearch"); - article.setAuthors(asList(johnSmith)); - article.setTags("elasticsearch", "spring data"); - articleRepository.save(article); + article = new Article("Second Article About Elasticsearch"); + article.setAuthors(asList(johnSmith)); + article.setTags("elasticsearch", "spring data"); + articleRepository.save(article); - article = new Article("Elasticsearch Tutorial"); - article.setAuthors(asList(johnDoe)); - article.setTags("elasticsearch"); - articleRepository.save(article); - } + article = new Article("Elasticsearch Tutorial"); + article.setAuthors(asList(johnDoe)); + article.setTags("elasticsearch"); + articleRepository.save(article); + } - @After - public void after() { - articleRepository.deleteAll(); - } + @After + public void after() { + articleRepository.deleteAll(); + } - @Test - 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")); - assertEquals(1, articles.getTotalHits()); - } + @Test + 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")); + assertEquals(1, articles.getTotalHits()); + } - @Test - public void givenOneTermFromTitle_whenRunMatchQuery_thenDocIsFound() { - final NativeSearchQuery searchQuery = - new NativeSearchQueryBuilder().withQuery(matchQuery("title", "Engines Solutions")) - .build(); - - final SearchHits
articles = - elasticsearchTemplate.search(searchQuery, Article.class, IndexCoordinates.of("blog")); - - assertEquals(1, articles.getTotalHits()); - assertEquals("Search engines", articles.getSearchHit(0).getContent().getTitle()); - } + @Test + public void givenOneTermFromTitle_whenRunMatchQuery_thenDocIsFound() { + final NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchQuery("title", "Engines Solutions")) + .build(); - @Test - public void givenPartTitle_whenRunMatchQuery_thenDocIsFound() { - 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 = - elasticsearchTemplate.search(searchQuery, Article.class, IndexCoordinates.of("blog")); - - assertEquals(3, articles.getTotalHits()); - } + assertEquals(1, articles.getTotalHits()); + assertEquals("Search engines", articles.getSearchHit(0) + .getContent() + .getTitle()); + } - @Test - public void givenFullTitle_whenRunMatchQueryOnVerbatimField_thenDocIsFound() { - NativeSearchQuery searchQuery = new NativeSearchQueryBuilder() - .withQuery(matchQuery("title.verbatim", "Second Article About Elasticsearch")) - .build(); + @Test + public void givenPartTitle_whenRunMatchQuery_thenDocIsFound() { + final NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchQuery("title", "elasticsearch data")) + .build(); - SearchHits
articles = - elasticsearchTemplate.search(searchQuery, Article.class, IndexCoordinates.of("blog")); - - assertEquals(1, articles.getTotalHits()); + final SearchHits
articles = elasticsearchTemplate.search(searchQuery, Article.class, IndexCoordinates.of("blog")); - searchQuery = new NativeSearchQueryBuilder() - .withQuery(matchQuery("title.verbatim", "Second Article About")) - .build(); - - articles = elasticsearchTemplate.search(searchQuery, Article.class, IndexCoordinates.of("blog")); - assertEquals(0, articles.getTotalHits()); - } + assertEquals(3, articles.getTotalHits()); + } - @Test - public void givenNestedObject_whenQueryByAuthorsName_thenFoundArticlesByThatAuthor() { - final QueryBuilder builder = nestedQuery("authors", boolQuery().must(termQuery("authors.name", "smith")), - ScoreMode.None); + @Test + public void givenFullTitle_whenRunMatchQueryOnVerbatimField_thenDocIsFound() { + NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchQuery("title.verbatim", "Second Article About Elasticsearch")) + .build(); - final NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(builder).build(); - final SearchHits
articles = elasticsearchTemplate.search(searchQuery, Article.class, IndexCoordinates.of("blog")); + SearchHits
articles = elasticsearchTemplate.search(searchQuery, Article.class, IndexCoordinates.of("blog")); - assertEquals(2, articles.getTotalHits()); - } + assertEquals(1, articles.getTotalHits()); - @Test - public void givenAnalyzedQuery_whenMakeAggregationOnTermCount_thenEachTokenCountsSeparately() throws Exception { - final TermsAggregationBuilder aggregation = AggregationBuilders.terms("top_tags").field("title"); + searchQuery = new NativeSearchQueryBuilder().withQuery(matchQuery("title.verbatim", "Second Article About")) + .build(); - final SearchSourceBuilder builder = new SearchSourceBuilder().aggregation(aggregation); - final SearchRequest searchRequest = new SearchRequest("blog").source(builder); + articles = elasticsearchTemplate.search(searchQuery, Article.class, IndexCoordinates.of("blog")); + assertEquals(0, articles.getTotalHits()); + } - final SearchResponse response = client.search(searchRequest, RequestOptions.DEFAULT); + @Test + public void givenNestedObject_whenQueryByAuthorsName_thenFoundArticlesByThatAuthor() { + final QueryBuilder builder = nestedQuery("authors", boolQuery().must(termQuery("authors.name", "smith")), ScoreMode.None); - final Map results = response.getAggregations().asMap(); - final ParsedStringTerms topTags = (ParsedStringTerms) results.get("top_tags"); + final NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(builder) + .build(); + final SearchHits
articles = elasticsearchTemplate.search(searchQuery, Article.class, IndexCoordinates.of("blog")); - final List keys = topTags.getBuckets().stream().map(MultiBucketsAggregation.Bucket::getKeyAsString).sorted() - .collect(toList()); - assertEquals( - asList("about", "article", "data", "elasticsearch", "engines", "search", "second", "spring", "tutorial"), keys); - } + assertEquals(2, articles.getTotalHits()); + } - @Test - public void givenNotAnalyzedQuery_whenMakeAggregationOnTermCount_thenEachTermCountsIndividually() throws Exception { - final TermsAggregationBuilder aggregation = AggregationBuilders.terms("top_tags").field("tags") - .order(BucketOrder.count(false)); + @Test + public void givenAnalyzedQuery_whenMakeAggregationOnTermCount_thenEachTokenCountsSeparately() throws Exception { + final TermsAggregationBuilder aggregation = AggregationBuilders.terms("top_tags") + .field("title"); - final SearchSourceBuilder builder = new SearchSourceBuilder().aggregation(aggregation); - final SearchRequest searchRequest = new SearchRequest().indices("blog").source(builder); + final SearchSourceBuilder builder = new SearchSourceBuilder().aggregation(aggregation); + final SearchRequest searchRequest = new SearchRequest("blog").source(builder); - final SearchResponse response = client.search(searchRequest, RequestOptions.DEFAULT); + final SearchResponse response = client.search(searchRequest, RequestOptions.DEFAULT); - final Map results = response.getAggregations().asMap(); - final ParsedStringTerms topTags = (ParsedStringTerms) results.get("top_tags"); + final Map results = response.getAggregations() + .asMap(); + final ParsedStringTerms topTags = (ParsedStringTerms) results.get("top_tags"); - final List keys = topTags.getBuckets().stream().map(MultiBucketsAggregation.Bucket::getKeyAsString) - .collect(toList()); - assertEquals(asList("elasticsearch", "spring data", "search engines", "tutorial"), keys); - } + final List keys = topTags.getBuckets() + .stream() + .map(MultiBucketsAggregation.Bucket::getKeyAsString) + .sorted() + .collect(toList()); + assertEquals(asList("about", "article", "data", "elasticsearch", "engines", "search", "second", "spring", "tutorial"), keys); + } - @Test - public void givenNotExactPhrase_whenUseSlop_thenQueryMatches() { - final NativeSearchQuery searchQuery = new NativeSearchQueryBuilder() - .withQuery(matchPhraseQuery("title", "spring elasticsearch").slop(1)).build(); + @Test + public void givenNotAnalyzedQuery_whenMakeAggregationOnTermCount_thenEachTermCountsIndividually() throws Exception { + final TermsAggregationBuilder aggregation = AggregationBuilders.terms("top_tags") + .field("tags") + .order(BucketOrder.count(false)); - final SearchHits
articles = elasticsearchTemplate.search(searchQuery, Article.class, IndexCoordinates.of("blog")); - - assertEquals(1, articles.getTotalHits()); - } + final SearchSourceBuilder builder = new SearchSourceBuilder().aggregation(aggregation); + final SearchRequest searchRequest = new SearchRequest().indices("blog") + .source(builder); - @Test - public void givenPhraseWithType_whenUseFuzziness_thenQueryMatches() { - final NativeSearchQuery searchQuery = new NativeSearchQueryBuilder() - .withQuery( - matchQuery("title", "spring date elasticserch").operator(Operator.AND).fuzziness(Fuzziness.ONE).prefixLength(3)) - .build(); + final SearchResponse response = client.search(searchRequest, RequestOptions.DEFAULT); - final SearchHits
articles = elasticsearchTemplate.search(searchQuery, Article.class, IndexCoordinates.of("blog")); - - assertEquals(1, articles.getTotalHits()); - } + final Map results = response.getAggregations() + .asMap(); + final ParsedStringTerms topTags = (ParsedStringTerms) results.get("top_tags"); - @Test - public void givenMultimatchQuery_whenDoSearch_thenAllProvidedFieldsMatch() { - final NativeSearchQuery searchQuery = new NativeSearchQueryBuilder() - .withQuery( - multiMatchQuery("tutorial").field("title").field("tags").type(MultiMatchQueryBuilder.Type.BEST_FIELDS)) - .build(); + final List keys = topTags.getBuckets() + .stream() + .map(MultiBucketsAggregation.Bucket::getKeyAsString) + .collect(toList()); + assertEquals(asList("elasticsearch", "spring data", "search engines", "tutorial"), keys); + } - final SearchHits
articles = elasticsearchTemplate.search(searchQuery, Article.class, IndexCoordinates.of("blog")); + @Test + public void givenNotExactPhrase_whenUseSlop_thenQueryMatches() { + final NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchPhraseQuery("title", "spring elasticsearch").slop(1)) + .build(); - assertEquals(2, articles.getTotalHits()); - } + final SearchHits
articles = elasticsearchTemplate.search(searchQuery, Article.class, IndexCoordinates.of("blog")); - @Test - public void givenBoolQuery_whenQueryByAuthorsName_thenFoundArticlesByThatAuthorAndFilteredTag() { - final QueryBuilder builder = boolQuery() - .must(nestedQuery("authors", boolQuery().must(termQuery("authors.name", "doe")), ScoreMode.None)) - .filter(termQuery("tags", "elasticsearch")); + assertEquals(1, articles.getTotalHits()); + } - final NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(builder).build(); - final SearchHits
articles = elasticsearchTemplate.search(searchQuery, Article.class, IndexCoordinates.of("blog")); + @Test + public void givenPhraseWithType_whenUseFuzziness_thenQueryMatches() { + final NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchQuery("title", "spring date elasticserch").operator(Operator.AND) + .fuzziness(Fuzziness.ONE) + .prefixLength(3)) + .build(); - assertEquals(2, articles.getTotalHits()); - } + final SearchHits
articles = elasticsearchTemplate.search(searchQuery, Article.class, IndexCoordinates.of("blog")); + + assertEquals(1, articles.getTotalHits()); + } + + @Test + public void givenMultimatchQuery_whenDoSearch_thenAllProvidedFieldsMatch() { + final NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(multiMatchQuery("tutorial").field("title") + .field("tags") + .type(MultiMatchQueryBuilder.Type.BEST_FIELDS)) + .build(); + + final SearchHits
articles = elasticsearchTemplate.search(searchQuery, Article.class, IndexCoordinates.of("blog")); + + assertEquals(2, articles.getTotalHits()); + } + + @Test + public void givenBoolQuery_whenQueryByAuthorsName_thenFoundArticlesByThatAuthorAndFilteredTag() { + final QueryBuilder builder = boolQuery().must(nestedQuery("authors", boolQuery().must(termQuery("authors.name", "doe")), ScoreMode.None)) + .filter(termQuery("tags", "elasticsearch")); + + final NativeSearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(builder) + .build(); + final SearchHits
articles = elasticsearchTemplate.search(searchQuery, Article.class, IndexCoordinates.of("blog")); + + assertEquals(2, articles.getTotalHits()); + } } From 3fc4ed23a46468dd0c9d257c4f4356f0a1347b49 Mon Sep 17 00:00:00 2001 From: Mathieu Fortin Date: Tue, 19 May 2020 19:44:42 -0400 Subject: [PATCH 023/140] upgrade to 4.0.0.RELEASE --- .../spring-data-elasticsearch/pom.xml | 23 +++---------------- .../com/baeldung/SpringContextManualTest.java | 4 ++-- .../ElasticSearchManualTest.java | 4 ++-- .../elasticsearch/GeoQueriesManualTest.java | 4 ++-- .../data/es/ElasticSearchManualTest.java | 4 ++-- .../data/es/ElasticSearchQueryManualTest.java | 4 ++-- 6 files changed, 13 insertions(+), 30 deletions(-) diff --git a/persistence-modules/spring-data-elasticsearch/pom.xml b/persistence-modules/spring-data-elasticsearch/pom.xml index 72860cb136..fc435b1f48 100644 --- a/persistence-modules/spring-data-elasticsearch/pom.xml +++ b/persistence-modules/spring-data-elasticsearch/pom.xml @@ -52,7 +52,7 @@ org.locationtech.jts jts-core - 1.15.0 + ${jts.version} xerces @@ -67,29 +67,12 @@ ${spring.version} test - - - net.java.dev.jna - jna - ${jna.version} - test - - 4.0.0.RC1 - 4.5.2 + 4.0.0.RELEASE 1.2.47 0.7 - 1.13 + 1.15.0 - - - - repository.spring.milestone - Spring Milestone Repository - https://repo.spring.io/milestone - - - \ No newline at end of file diff --git a/persistence-modules/spring-data-elasticsearch/src/test/java/com/baeldung/SpringContextManualTest.java b/persistence-modules/spring-data-elasticsearch/src/test/java/com/baeldung/SpringContextManualTest.java index bff910cf93..6572896eca 100644 --- a/persistence-modules/spring-data-elasticsearch/src/test/java/com/baeldung/SpringContextManualTest.java +++ b/persistence-modules/spring-data-elasticsearch/src/test/java/com/baeldung/SpringContextManualTest.java @@ -10,8 +10,8 @@ import com.baeldung.spring.data.es.config.Config; /** * This Manual test requires: Elasticsearch instance running on localhost:9200. * - * The following docker command can be used: docker run -d --name es761 -p - * 9200:9200 -e "discovery.type=single-node" elasticsearch:7.6.1 + * The following docker command can be used: docker run -d --name es762 -p + * 9200:9200 -e "discovery.type=single-node" elasticsearch:7.6.2 */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = Config.class) diff --git a/persistence-modules/spring-data-elasticsearch/src/test/java/com/baeldung/elasticsearch/ElasticSearchManualTest.java b/persistence-modules/spring-data-elasticsearch/src/test/java/com/baeldung/elasticsearch/ElasticSearchManualTest.java index e4b3f6d801..2ca5f28f13 100644 --- a/persistence-modules/spring-data-elasticsearch/src/test/java/com/baeldung/elasticsearch/ElasticSearchManualTest.java +++ b/persistence-modules/spring-data-elasticsearch/src/test/java/com/baeldung/elasticsearch/ElasticSearchManualTest.java @@ -39,8 +39,8 @@ import org.springframework.data.elasticsearch.client.RestClients; /** * This Manual test requires: Elasticsearch instance running on localhost:9200. * - * The following docker command can be used: docker run -d --name es761 -p - * 9200:9200 -e "discovery.type=single-node" elasticsearch:7.6.1 + * The following docker command can be used: docker run -d --name es762 -p + * 9200:9200 -e "discovery.type=single-node" elasticsearch:7.6.2 */ public class ElasticSearchManualTest { private List listOfPersons = new ArrayList<>(); diff --git a/persistence-modules/spring-data-elasticsearch/src/test/java/com/baeldung/elasticsearch/GeoQueriesManualTest.java b/persistence-modules/spring-data-elasticsearch/src/test/java/com/baeldung/elasticsearch/GeoQueriesManualTest.java index a36e08d6d2..64b2ea2437 100644 --- a/persistence-modules/spring-data-elasticsearch/src/test/java/com/baeldung/elasticsearch/GeoQueriesManualTest.java +++ b/persistence-modules/spring-data-elasticsearch/src/test/java/com/baeldung/elasticsearch/GeoQueriesManualTest.java @@ -41,8 +41,8 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * This Manual test requires: Elasticsearch instance running on localhost:9200. * - * The following docker command can be used: docker run -d --name es761 -p - * 9200:9200 -e "discovery.type=single-node" elasticsearch:7.6.1 + * The following docker command can be used: docker run -d --name es762 -p + * 9200:9200 -e "discovery.type=single-node" elasticsearch:7.6.2 */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = Config.class) 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 9f713a276f..412cd04e09 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 @@ -33,8 +33,8 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * This Manual test requires: Elasticsearch instance running on localhost:9200. * - * The following docker command can be used: docker run -d --name es761 -p - * 9200:9200 -e "discovery.type=single-node" elasticsearch:7.6.1 + * The following docker command can be used: docker run -d --name es762 -p + * 9200:9200 -e "discovery.type=single-node" elasticsearch:7.6.2 */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = Config.class) 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 3cedab00e4..aaf0c80097 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 @@ -50,8 +50,8 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * This Manual test requires: Elasticsearch instance running on localhost:9200. * - * The following docker command can be used: docker run -d --name es761 -p - * 9200:9200 -e "discovery.type=single-node" elasticsearch:7.6.1 + * The following docker command can be used: docker run -d --name es762 -p + * 9200:9200 -e "discovery.type=single-node" elasticsearch:7.6.2 */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = Config.class) From 458699cb5bc2e83be818a62bf86e784512832ede Mon Sep 17 00:00:00 2001 From: Mathieu Fortin Date: Tue, 19 May 2020 19:48:11 -0400 Subject: [PATCH 024/140] added back elasticsearch dependency --- persistence-modules/spring-data-elasticsearch/pom.xml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/persistence-modules/spring-data-elasticsearch/pom.xml b/persistence-modules/spring-data-elasticsearch/pom.xml index fc435b1f48..cf77f858d0 100644 --- a/persistence-modules/spring-data-elasticsearch/pom.xml +++ b/persistence-modules/spring-data-elasticsearch/pom.xml @@ -37,6 +37,12 @@ ${spring-data-elasticsearch.version} + + org.elasticsearch + elasticsearch + ${elasticsearch.version} + + com.alibaba fastjson @@ -71,6 +77,7 @@ 4.0.0.RELEASE + 7.6.2 1.2.47 0.7 1.15.0 From cffeff11abde9ba1ff2d912bde9cf60d33444bf6 Mon Sep 17 00:00:00 2001 From: Mathieu Fortin Date: Tue, 19 May 2020 19:53:23 -0400 Subject: [PATCH 025/140] removed unecessary dependencies --- persistence-modules/spring-data-elasticsearch/pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/persistence-modules/spring-data-elasticsearch/pom.xml b/persistence-modules/spring-data-elasticsearch/pom.xml index cf77f858d0..79363d7352 100644 --- a/persistence-modules/spring-data-elasticsearch/pom.xml +++ b/persistence-modules/spring-data-elasticsearch/pom.xml @@ -13,7 +13,7 @@ - + org.springframework From 177bb9c8977909e585c4dbcc92522709073e95d3 Mon Sep 17 00:00:00 2001 From: Mathieu Fortin Date: Tue, 19 May 2020 19:54:29 -0400 Subject: [PATCH 026/140] removed unecessary dependencies --- .../spring-data-elasticsearch/pom.xml | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/persistence-modules/spring-data-elasticsearch/pom.xml b/persistence-modules/spring-data-elasticsearch/pom.xml index 79363d7352..6a983145ee 100644 --- a/persistence-modules/spring-data-elasticsearch/pom.xml +++ b/persistence-modules/spring-data-elasticsearch/pom.xml @@ -13,18 +13,6 @@ - - org.springframework spring-web From 658835bfe850d598462331509c8c7745f816f6eb Mon Sep 17 00:00:00 2001 From: Kirill Vlasov Date: Tue, 19 May 2020 15:53:40 +0500 Subject: [PATCH 027/140] BAEL-3824 Circular view path exception --- .../spring-boot-mvc-3/.gitignore | 25 ++++++++++++++++ .../spring-boot-mvc-3/README.md | 5 ++++ spring-boot-modules/spring-boot-mvc-3/pom.xml | 29 +++++++++++++++++++ .../CircularViewPathApplication.java | 21 ++++++++++++++ .../CircularViewPathController.java | 16 ++++++++++ .../src/main/resources/logback.xml | 13 +++++++++ .../src/main/resources/templates/path.html | 13 +++++++++ 7 files changed, 122 insertions(+) create mode 100644 spring-boot-modules/spring-boot-mvc-3/.gitignore create mode 100644 spring-boot-modules/spring-boot-mvc-3/README.md create mode 100644 spring-boot-modules/spring-boot-mvc-3/pom.xml create mode 100644 spring-boot-modules/spring-boot-mvc-3/src/main/java/com/baeldung/circularviewpath/CircularViewPathApplication.java create mode 100644 spring-boot-modules/spring-boot-mvc-3/src/main/java/com/baeldung/controller/circularviewpath/CircularViewPathController.java create mode 100644 spring-boot-modules/spring-boot-mvc-3/src/main/resources/logback.xml create mode 100644 spring-boot-modules/spring-boot-mvc-3/src/main/resources/templates/path.html diff --git a/spring-boot-modules/spring-boot-mvc-3/.gitignore b/spring-boot-modules/spring-boot-mvc-3/.gitignore new file mode 100644 index 0000000000..82eca336e3 --- /dev/null +++ b/spring-boot-modules/spring-boot-mvc-3/.gitignore @@ -0,0 +1,25 @@ +/target/ +!.mvn/wrapper/maven-wrapper.jar + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/build/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-mvc-3/README.md b/spring-boot-modules/spring-boot-mvc-3/README.md new file mode 100644 index 0000000000..1050adb2d6 --- /dev/null +++ b/spring-boot-modules/spring-boot-mvc-3/README.md @@ -0,0 +1,5 @@ +## Spring Boot MVC + +This module contains articles about Spring Web MVC in Spring Boot projects. + +### Relevant Articles: diff --git a/spring-boot-modules/spring-boot-mvc-3/pom.xml b/spring-boot-modules/spring-boot-mvc-3/pom.xml new file mode 100644 index 0000000000..64e8a99c6c --- /dev/null +++ b/spring-boot-modules/spring-boot-mvc-3/pom.xml @@ -0,0 +1,29 @@ + + + 4.0.0 + spring-boot-mvc-3 + spring-boot-mvc-3 + jar + Module For Spring Boot MVC Web + + + com.baeldung + parent-boot-2 + 0.0.1-SNAPSHOT + ../../parent-boot-2 + + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-thymeleaf + + + + \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-mvc-3/src/main/java/com/baeldung/circularviewpath/CircularViewPathApplication.java b/spring-boot-modules/spring-boot-mvc-3/src/main/java/com/baeldung/circularviewpath/CircularViewPathApplication.java new file mode 100644 index 0000000000..deb50e2ed7 --- /dev/null +++ b/spring-boot-modules/spring-boot-mvc-3/src/main/java/com/baeldung/circularviewpath/CircularViewPathApplication.java @@ -0,0 +1,21 @@ +package com.baeldung.circularviewpath; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +/** + * Spring Boot launcher for an application + * + */ +@SpringBootApplication(scanBasePackages = "com.baeldung.controller.circularviewpath") +public class CircularViewPathApplication { + + /** + * Launches a Spring Boot application + * + * @param args null + */ + public static void main(String[] args) { + SpringApplication.run(CircularViewPathApplication.class, args); + } +} diff --git a/spring-boot-modules/spring-boot-mvc-3/src/main/java/com/baeldung/controller/circularviewpath/CircularViewPathController.java b/spring-boot-modules/spring-boot-mvc-3/src/main/java/com/baeldung/controller/circularviewpath/CircularViewPathController.java new file mode 100644 index 0000000000..a4d6a97f7d --- /dev/null +++ b/spring-boot-modules/spring-boot-mvc-3/src/main/java/com/baeldung/controller/circularviewpath/CircularViewPathController.java @@ -0,0 +1,16 @@ +package com.baeldung.controller.circularviewpath; + +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; + +@Controller +public class CircularViewPathController { + + /** + * A request mapping which may cause circular view path exception + */ + @GetMapping("/path") + public String path() { + return "path"; + } +} diff --git a/spring-boot-modules/spring-boot-mvc-3/src/main/resources/logback.xml b/spring-boot-modules/spring-boot-mvc-3/src/main/resources/logback.xml new file mode 100644 index 0000000000..7d900d8ea8 --- /dev/null +++ b/spring-boot-modules/spring-boot-mvc-3/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/spring-boot-modules/spring-boot-mvc-3/src/main/resources/templates/path.html b/spring-boot-modules/spring-boot-mvc-3/src/main/resources/templates/path.html new file mode 100644 index 0000000000..b329797275 --- /dev/null +++ b/spring-boot-modules/spring-boot-mvc-3/src/main/resources/templates/path.html @@ -0,0 +1,13 @@ + + + + + + + path.html + + + +

path.html

+ + \ No newline at end of file From 020fcd9229cf29513632bf816b1faea171c35db3 Mon Sep 17 00:00:00 2001 From: musibs Date: Sat, 23 May 2020 15:23:26 +0530 Subject: [PATCH 028/140] BAEL 4064 Out of Memory Error --- .../error/oom/TestExecutorService.java | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 core-java-modules/core-java-lang/src/test/java/com/baeldung/error/oom/TestExecutorService.java diff --git a/core-java-modules/core-java-lang/src/test/java/com/baeldung/error/oom/TestExecutorService.java b/core-java-modules/core-java-lang/src/test/java/com/baeldung/error/oom/TestExecutorService.java new file mode 100644 index 0000000000..d51faa055d --- /dev/null +++ b/core-java-modules/core-java-lang/src/test/java/com/baeldung/error/oom/TestExecutorService.java @@ -0,0 +1,39 @@ +package com.baeldung.error.oom; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; +import java.util.stream.IntStream; + +import org.junit.jupiter.api.Test; + +public class TestExecutorService { + + @Test + public void givenAnExecutorService_WhenMoreTasksSubmitted_ThenAdditionalTasksWait() { + + //Given + int noOfThreads = 5; + ExecutorService executorService = Executors.newFixedThreadPool(noOfThreads); + + Runnable runnableTask = () -> { + try { + TimeUnit.HOURS.sleep(1); + } catch (InterruptedException e) { + e.printStackTrace(); + } + }; + + //When + IntStream.rangeClosed(1, 10) + .forEach(i -> executorService.submit(runnableTask)); + + //Then + assertThat(((ThreadPoolExecutor )executorService).getQueue().size(), is(equalTo(5))); + } +} From 59afec1c00dcdabcdd3110d3815c0840a6bcc9a2 Mon Sep 17 00:00:00 2001 From: "alex.peptan" Date: Sat, 23 May 2020 20:06:43 +0300 Subject: [PATCH 029/140] BAEL-3896: OpenAPI JSON Objects in Query Params - README file revert + required changes --- spring-rest-http/README.md | 1 - .../jsonParamOpenApiSwagger3Definition | 32 ++ .../jsonParamOpenApiSwaggerDefinition | 276 ++++++++++-------- 3 files changed, 179 insertions(+), 130 deletions(-) create mode 100644 spring-rest-http/src/main/java/com/baeldung/jsonparam/jsonParamOpenApiSwagger3Definition diff --git a/spring-rest-http/README.md b/spring-rest-http/README.md index cba017eb74..35793cb281 100644 --- a/spring-rest-http/README.md +++ b/spring-rest-http/README.md @@ -13,4 +13,3 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [Spring RequestMapping](https://www.baeldung.com/spring-requestmapping) - [Guide to DeferredResult in Spring](https://www.baeldung.com/spring-deferred-result) - [Using JSON Patch in Spring REST APIs](https://www.baeldung.com/spring-rest-json-patch) -- [OpenAPI JSON Objects in Query Params](https://www.baeldung.com/openapi-json-objects-in-query-params) diff --git a/spring-rest-http/src/main/java/com/baeldung/jsonparam/jsonParamOpenApiSwagger3Definition b/spring-rest-http/src/main/java/com/baeldung/jsonparam/jsonParamOpenApiSwagger3Definition new file mode 100644 index 0000000000..218e24b12b --- /dev/null +++ b/spring-rest-http/src/main/java/com/baeldung/jsonparam/jsonParamOpenApiSwagger3Definition @@ -0,0 +1,32 @@ +swagger: '3.0' +info: + title: Sample API to send JSON objects as query parameters using OpenAPI 3 + description: API description. + version: 1.0.0 + +paths: + /tickets: + get: + parameters: + - in: query + name: params + required: true + # Parameter is an object that should be serialized as JSON + content: + application/json: + schema: + type: object + properties: + type: + type: string + name: + color: string + responses: + '200': + description: successful process + '401': + description: Unauthorized + '403': + description: Forbidden + '404': + description: Not Found diff --git a/spring-rest-http/src/main/java/com/baeldung/jsonparam/jsonParamOpenApiSwaggerDefinition b/spring-rest-http/src/main/java/com/baeldung/jsonparam/jsonParamOpenApiSwaggerDefinition index 9f9bcb788a..3261736e15 100644 --- a/spring-rest-http/src/main/java/com/baeldung/jsonparam/jsonParamOpenApiSwaggerDefinition +++ b/spring-rest-http/src/main/java/com/baeldung/jsonparam/jsonParamOpenApiSwaggerDefinition @@ -1,5 +1,9 @@ swagger: '2.0' -... +info: + title: Sample API to send JSON objects as query parameters using OpenAPI 2 + description: API description. + version: 1.0.0 + paths: /tickets: get: @@ -10,10 +14,16 @@ paths: description: A JSON object with the `type` and `color` properties type: string example: '{"type":"foo","color":"green"}' + responses: + '200': + description: successful process + '401': + description: Unauthorized + '403': + description: Forbidden + '404': + description: Not Found -swagger: '2.0' -... -paths: /tickets: post: requestBody: @@ -26,129 +36,137 @@ paths: responses: '200': description: successful process + '201': + description: Created + '401': + description: Unauthorized + '403': + description: Forbidden + '404': + description: Not Found -"/api/tickets": { - "get": { - "tags": [ - "account-resource" - ], - "summary": "testQueryParamApi", - "operationId": "testQueryParamApiUsingGET", - "produces": [ - "*/*" - ], - "parameters": [ - { - "name": "params", - "in": "query", - "description": "params", - "required": true, - "type": "string" - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "type": "string" - } - }, - "401": { - "description": "Unauthorized" - }, - "403": { - "description": "Forbidden" - }, - "404": { - "description": "Not Found" - } - }, - "deprecated": false - }, - "post": { - "tags": [ - "account-resource" - ], - "summary": "testBodyParamApi", - "operationId": "testBodyParamApiUsingPOST", - "consumes": [ - "application/json" - ], - "produces": [ - "*/*" - ], - "parameters": [ - { - "in": "body", - "name": "params", - "description": "params", - "required": true, - "schema": { - "type": "string" - } - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "type": "string" - } - }, - "201": { - "description": "Created" - }, - "401": { - "description": "Unauthorized" - }, - "403": { - "description": "Forbidden" - }, - "404": { - "description": "Not Found" - } - }, - "deprecated": false - } -}, -"/api/tickets2": { - "get": { - "tags": [ - "account-resource" - ], - "summary": "testGetBodyParamApi", - "operationId": "testGetBodyParamApiUsingGET", - "produces": [ - "*/*" - ], - "parameters": [ - { - "in": "body", - "name": "params", - "description": "params", - "required": true, - "schema": { - "type": "string" - } - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "type": "string" - } - }, - "401": { - "description": "Unauthorized" - }, - "403": { - "description": "Forbidden" - }, - "404": { - "description": "Not Found" - } - }, - "deprecated": false - } -} + /api/tickets: { + get: { + tags: [ + "account-resource" + ], + summary: "testQueryParamApi", + operationId: "testQueryParamApiUsingGET", + produces: [ + "*/*" + ], + parameters: [ + { + name: "params", + in: "query", + description: "params", + required: true, + type: "string" + } + ], + responses: { + 200: { + description: "OK", + schema: { + type: "string" + } + }, + 401: { + description: "Unauthorized" + }, + 403: { + description: "Forbidden" + }, + 404: { + description: "Not Found" + } + }, + deprecated: false + }, + post: { + tags: [ + "account-resource" + ], + summary: "testBodyParamApi", + operationId: "testBodyParamApiUsingPOST", + consumes: [ + "application/json" + ], + produces: [ + "*/*" + ], + parameters: [ + { + in: "body", + name: "params", + description: "params", + required: true, + schema: { + type: "string" + } + } + ], + responses: { + 200: { + description: "OK", + schema: { + type: "string" + } + }, + 201: { + description: "Created" + }, + 401: { + description: "Unauthorized" + }, + 403: { + description: "Forbidden" + }, + 404: { + description: "Not Found" + } + }, + deprecated: false + } + }, + /api/tickets2: { + get: { + tags: [ + "account-resource" + ], + summary: "testGetBodyParamApi", + operationId: "testGetBodyParamApiUsingGET", + produces: [ + "*/*" + ], + parameters: [ + { + in: "body", + name: "params", + description: "params", + required: true, + schema: { + type: "string" + } + } + ], + responses: { + 200: { + description: "OK", + schema: { + type: "string" + } + }, + 401: { + description: "Unauthorized" + }, + 403: { + description: "Forbidden" + }, + 404: { + description: "Not Found" + } + }, + deprecated: false + } + } From 05a4d4e188c1242b72675332df77bcc0769841a3 Mon Sep 17 00:00:00 2001 From: Vikas Ramsingh Rajput Date: Sun, 24 May 2020 10:33:17 +0300 Subject: [PATCH 030/140] BAEL-3067: Article - Convert BufferedReader to JSONObject - Completed --- .../core-java-io-conversions-2/pom.xml | 5 ++ ...avaBufferedReaderToJSONObjectUnitTest.java | 48 +++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 core-java-modules/core-java-io-conversions-2/src/test/java/com/baeldung/bufferedreadertojsonobject/JavaBufferedReaderToJSONObjectUnitTest.java diff --git a/core-java-modules/core-java-io-conversions-2/pom.xml b/core-java-modules/core-java-io-conversions-2/pom.xml index e95d1f4b67..7a83d4b502 100644 --- a/core-java-modules/core-java-io-conversions-2/pom.xml +++ b/core-java-modules/core-java-io-conversions-2/pom.xml @@ -22,6 +22,11 @@ commons-lang3 ${commons-lang3.version}
+ + org.json + json + 20190722 +
diff --git a/core-java-modules/core-java-io-conversions-2/src/test/java/com/baeldung/bufferedreadertojsonobject/JavaBufferedReaderToJSONObjectUnitTest.java b/core-java-modules/core-java-io-conversions-2/src/test/java/com/baeldung/bufferedreadertojsonobject/JavaBufferedReaderToJSONObjectUnitTest.java new file mode 100644 index 0000000000..d42c3975db --- /dev/null +++ b/core-java-modules/core-java-io-conversions-2/src/test/java/com/baeldung/bufferedreadertojsonobject/JavaBufferedReaderToJSONObjectUnitTest.java @@ -0,0 +1,48 @@ +package com.baeldung.bufferedreadertojsonobject; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.io.BufferedReader; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; + +import org.json.JSONObject; +import org.json.JSONTokener; +import org.junit.Test; + +public class JavaBufferedReaderToJSONObjectUnitTest { + + @Test + public void givenUsingNewVersion_whenConvertBufferedReaderToJSONObject_thenCorrect() { + byte[] b = "{ \"name\" : \"John\", \"age\" : 18 }".getBytes(StandardCharsets.UTF_8); + InputStream is = new ByteArrayInputStream(b); + BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(is)); + JSONTokener tokener = new JSONTokener(bufferedReader); + JSONObject json = new JSONObject(tokener); + + assertNotNull(json); + assertEquals("John", json.get("name")); + assertEquals(18, json.get("age")); + } + + @Test + public void givenUsingOldVersion_whenConvertBufferedReaderToJSONObject_thenCorrect() throws IOException { + byte[] b = "{ \"name\" : \"John\", \"age\" : 18 }".getBytes(StandardCharsets.UTF_8); + InputStream is = new ByteArrayInputStream(b); + BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(is)); + StringBuilder sb = new StringBuilder(); + String line; + while ((line = bufferedReader.readLine()) != null) { + sb.append(line); + } + JSONObject json = new JSONObject(sb.toString()); + + assertNotNull(json); + assertEquals("John", json.get("name")); + assertEquals(18, json.get("age")); + } +} From 8f1de1c3b702a07307e172b8745ece9c116f5f05 Mon Sep 17 00:00:00 2001 From: Chirag Dewan Date: Sun, 24 May 2020 13:58:50 +0530 Subject: [PATCH 031/140] BAEL3889 - Kafka Mock Producer --- .../baeldung/kafka/EvenOddPartitioner.java | 16 +++ .../com/baeldung/kafka/KafkaProducer.java | 40 ++++++ .../baeldung/kafka/KafkaProducerUnitTest.java | 114 ++++++++++++++++++ 3 files changed, 170 insertions(+) create mode 100644 libraries/src/main/java/com/baeldung/kafka/EvenOddPartitioner.java create mode 100644 libraries/src/main/java/com/baeldung/kafka/KafkaProducer.java create mode 100644 libraries/src/test/java/com/baeldung/kafka/KafkaProducerUnitTest.java diff --git a/libraries/src/main/java/com/baeldung/kafka/EvenOddPartitioner.java b/libraries/src/main/java/com/baeldung/kafka/EvenOddPartitioner.java new file mode 100644 index 0000000000..12c86828dd --- /dev/null +++ b/libraries/src/main/java/com/baeldung/kafka/EvenOddPartitioner.java @@ -0,0 +1,16 @@ +package com.baeldung.kafka; + +import org.apache.kafka.clients.producer.internals.DefaultPartitioner; +import org.apache.kafka.common.Cluster; + +public class EvenOddPartitioner extends DefaultPartitioner { + + @Override + public int partition(String topic, Object key, byte[] keyBytes, Object value, byte[] valueBytes, Cluster cluster) { + + if (((String)key).length() % 2 == 0) + return 0; + + return 1; + } +} diff --git a/libraries/src/main/java/com/baeldung/kafka/KafkaProducer.java b/libraries/src/main/java/com/baeldung/kafka/KafkaProducer.java new file mode 100644 index 0000000000..8574cd1c40 --- /dev/null +++ b/libraries/src/main/java/com/baeldung/kafka/KafkaProducer.java @@ -0,0 +1,40 @@ +package com.baeldung.kafka; + +import org.apache.kafka.clients.producer.Producer; +import org.apache.kafka.clients.producer.ProducerRecord; +import org.apache.kafka.clients.producer.RecordMetadata; + +import java.util.concurrent.Future; + +public class KafkaProducer { + + private final Producer producer; + + public KafkaProducer(Producer producer) { + this.producer = producer; + } + + public Future send(String key, String value) { + ProducerRecord record = new ProducerRecord("topic_sports_news", + key, value); + return producer.send(record); + } + + public void flush() { + producer.flush(); + } + + public void beginTransaction() { + producer.beginTransaction(); + } + + public void initTransaction() { + producer.initTransactions(); + } + + public void commitTransaction() { + producer.commitTransaction(); + } + + +} diff --git a/libraries/src/test/java/com/baeldung/kafka/KafkaProducerUnitTest.java b/libraries/src/test/java/com/baeldung/kafka/KafkaProducerUnitTest.java new file mode 100644 index 0000000000..ce3803322c --- /dev/null +++ b/libraries/src/test/java/com/baeldung/kafka/KafkaProducerUnitTest.java @@ -0,0 +1,114 @@ +package com.baeldung.kafka; + +import org.apache.kafka.clients.producer.MockProducer; +import org.apache.kafka.clients.producer.RecordMetadata; +import org.apache.kafka.common.Cluster; +import org.apache.kafka.common.Node; +import org.apache.kafka.common.PartitionInfo; +import org.apache.kafka.common.serialization.StringSerializer; +import org.junit.jupiter.api.Test; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Future; + +import static java.util.Collections.emptySet; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +class KafkaProducerUnitTest { + + private final String TOPIC_NAME = "topic_sports_news"; + + private KafkaProducer kafkaProducer; + private MockProducer mockProducer; + + private void buildMockProducer(boolean autoComplete) { + this.mockProducer = new MockProducer<>(autoComplete, new StringSerializer(), new StringSerializer()); + } + + @Test + void givenKeyValue_whenSend_thenVerifyHistory() throws ExecutionException, InterruptedException { + + buildMockProducer(true); + //when + kafkaProducer = new KafkaProducer(mockProducer); + Future recordMetadataFuture = kafkaProducer.send("data", "{\"site\" : \"baeldung\"}"); + + //then + assertTrue(mockProducer.history().size() == 1); + assertTrue(mockProducer.history().get(0).key().equalsIgnoreCase("data")); + assertTrue(recordMetadataFuture.get().partition() == 0); + + } + + @Test + void givenKeyValue_whenSend_thenSendOnlyAfterFlush() { + + buildMockProducer(false); + //when + kafkaProducer = new KafkaProducer(mockProducer); + Future record = kafkaProducer.send("data", "{\"site\" : \"baeldung\"}"); + assertFalse(record.isDone()); + + //then + kafkaProducer.flush(); + assertTrue(record.isDone()); + } + + @Test + void givenKeyValue_whenSend_thenReturnException() { + + buildMockProducer(false); + //when + kafkaProducer = new KafkaProducer(mockProducer); + Future record = kafkaProducer.send("site", "{\"site\" : \"baeldung\"}"); + RuntimeException e = new RuntimeException(); + mockProducer.errorNext(e); + //then + try { + record.get(); + } catch (ExecutionException | InterruptedException ex) { + assertEquals(e, ex.getCause()); + } + assertTrue(record.isDone()); + } + + @Test + void givenKeyValue_whenSendWithTxn_thenSendOnlyOnTxnCommit() { + + buildMockProducer(true); + //when + kafkaProducer = new KafkaProducer(mockProducer); + kafkaProducer.initTransaction(); + kafkaProducer.beginTransaction(); + Future record = kafkaProducer.send("data", "{\"site\" : \"baeldung\"}"); + + //then + assertTrue(mockProducer.history().isEmpty()); + kafkaProducer.commitTransaction(); + assertTrue(mockProducer.history().size() == 1); + } + + @Test + void givenKeyValue_whenSendWithPartitioning_thenVerifyPartitionNumber() throws ExecutionException, InterruptedException { + + PartitionInfo partitionInfo0 = new PartitionInfo(TOPIC_NAME, 0, null, null, null); + PartitionInfo partitionInfo1 = new PartitionInfo(TOPIC_NAME, 1, null, null, null); + List list = new ArrayList<>(); + list.add(partitionInfo0); + list.add(partitionInfo1); + Cluster cluster = new Cluster("kafkab", new ArrayList(), list, emptySet(), emptySet()); + this.mockProducer = new MockProducer<>(cluster, true, new EvenOddPartitioner(), new StringSerializer(), new StringSerializer()); + //when + kafkaProducer = new KafkaProducer(mockProducer); + Future recordMetadataFuture = kafkaProducer.send("partition", "{\"site\" : \"baeldung\"}"); + + //then + assertTrue(recordMetadataFuture.get().partition() == 1); + + } + +} \ No newline at end of file From 715147e7dc2ef0f13cf8b9845b2de049bc66073f Mon Sep 17 00:00:00 2001 From: Michele Guarnaccia Date: Sun, 24 May 2020 11:44:26 +0200 Subject: [PATCH 032/140] Refactored packages, added test cases, added structured class case --- .../main/java/com/baeldung/Application.java | 54 ------------- .../PartialUpdateApplication.java | 20 +++++ .../partialupdate/model/ContactPhone.java | 22 ++++++ .../{ => partialupdate}/model/Customer.java | 0 .../model/CustomerDto.java | 0 .../model/CustomerStructured.java | 26 ++++++ .../repository/ContactPhoneRepository.java | 12 +++ .../repository/CustomerRepository.java | 4 +- .../CustomerStructuredRepository.java | 11 +++ .../service/CustomerService.java | 79 +++++++++++++++++++ .../util/CustomerMapper.java | 6 +- .../com/baeldung/service/CustomerService.java | 47 ----------- .../partialupdate/PartialUpdateUnitTest.java | 56 +++++++++++++ 13 files changed, 231 insertions(+), 106 deletions(-) delete mode 100644 persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/Application.java create mode 100644 persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/PartialUpdateApplication.java create mode 100644 persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/model/ContactPhone.java rename persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/{ => partialupdate}/model/Customer.java (100%) rename persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/{ => partialupdate}/model/CustomerDto.java (100%) create mode 100644 persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/model/CustomerStructured.java create mode 100644 persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/repository/ContactPhoneRepository.java rename persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/{ => partialupdate}/repository/CustomerRepository.java (76%) create mode 100644 persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/repository/CustomerStructuredRepository.java create mode 100644 persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/service/CustomerService.java rename persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/{ => partialupdate}/util/CustomerMapper.java (73%) delete mode 100644 persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/service/CustomerService.java create mode 100644 persistence-modules/spring-data-jpa-5/src/test/java/com/baeldung/partialupdate/PartialUpdateUnitTest.java diff --git a/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/Application.java b/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/Application.java deleted file mode 100644 index 34e86fe135..0000000000 --- a/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/Application.java +++ /dev/null @@ -1,54 +0,0 @@ -package com.baeldung; - -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.CommandLineRunner; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.cache.CacheManager; -import org.springframework.cache.annotation.EnableCaching; -import org.springframework.context.ApplicationContext; -import org.springframework.context.annotation.Bean; - -import com.baeldung.model.Customer; -import com.baeldung.model.CustomerDto; -import com.baeldung.service.CustomerService; - -@SpringBootApplication @EnableCaching -public class Application { - - @Autowired CustomerService service; - @Autowired CacheManager cacheManager; - private static final org.slf4j.Logger logger = LoggerFactory.getLogger(Application.class); - - public static void main(String[] args) { - SpringApplication.run(Application.class, args); - } - - @Bean public CommandLineRunner commandLineRunner(ApplicationContext ctx) throws Exception { - logger.info("-- BASIC LOAD AND SAVE --"); - basicLoadAndSave(); - logger.info("-- BASIC LOAD AND SAVE + MAPPER --"); - basicLoadAndSaveWithMapper(); - return null; - } - - private void basicLoadAndSave() { - Customer myCustomer = service.addCustomer("John"); - logger.info("Insert -- " + myCustomer.toString()); - myCustomer = service.updateCustomer(myCustomer.id, "+00"); - logger.info("Update -- " + myCustomer.toString()); - } - - private void basicLoadAndSaveWithMapper() { - CustomerDto dto = new CustomerDto(null); - dto.name = "Johnny"; - Customer entity = service.addCustomer(dto); - logger.info("Insert -- " + entity.toString()); - CustomerDto dto2 = new CustomerDto(entity.id); - dto2.phone = "+44"; - entity = service.updateCustomer(dto2); - logger.info("Update -- " + entity.toString()); - } - -} diff --git a/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/PartialUpdateApplication.java b/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/PartialUpdateApplication.java new file mode 100644 index 0000000000..30f5dfa03d --- /dev/null +++ b/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/PartialUpdateApplication.java @@ -0,0 +1,20 @@ +package com.baeldung.partialupdate; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cache.CacheManager; +import org.springframework.cache.annotation.EnableCaching; + +@SpringBootApplication +@EnableCaching +public class PartialUpdateApplication { + + @Autowired + CacheManager cacheManager; + + public static void main(String[] args) { + SpringApplication.run(PartialUpdateApplication.class, args); + } + +} diff --git a/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/model/ContactPhone.java b/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/model/ContactPhone.java new file mode 100644 index 0000000000..9d611fa755 --- /dev/null +++ b/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/model/ContactPhone.java @@ -0,0 +1,22 @@ +package com.baeldung.partialupdate.model; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; + +@Entity +public class ContactPhone { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + public long id; + @Column(nullable=false) + public long customerId; + public String phone; + + @Override + public String toString() { + return phone; + } +} diff --git a/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/model/Customer.java b/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/model/Customer.java similarity index 100% rename from persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/model/Customer.java rename to persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/model/Customer.java diff --git a/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/model/CustomerDto.java b/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/model/CustomerDto.java similarity index 100% rename from persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/model/CustomerDto.java rename to persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/model/CustomerDto.java diff --git a/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/model/CustomerStructured.java b/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/model/CustomerStructured.java new file mode 100644 index 0000000000..67b534add2 --- /dev/null +++ b/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/model/CustomerStructured.java @@ -0,0 +1,26 @@ +package com.baeldung.partialupdate.model; + +import java.util.List; + +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.OneToMany; + +@Entity +public class CustomerStructured { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + public long id; + public String name; + @OneToMany(fetch = FetchType.EAGER, targetEntity=ContactPhone.class, mappedBy="customerId") + public List contactPhones; + + @Override public String toString() { + return String.format("Customer %s, Phone: %s", + this.name, this.contactPhones.stream().map(e -> e.toString()).reduce("", String::concat)); + } +} diff --git a/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/repository/ContactPhoneRepository.java b/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/repository/ContactPhoneRepository.java new file mode 100644 index 0000000000..2e0b687227 --- /dev/null +++ b/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/repository/ContactPhoneRepository.java @@ -0,0 +1,12 @@ +package com.baeldung.partialupdate.repository; + +import org.springframework.data.repository.CrudRepository; +import org.springframework.stereotype.Repository; + +import com.baeldung.partialupdate.model.ContactPhone; + +@Repository +public interface ContactPhoneRepository extends CrudRepository { + ContactPhone findById(long id); + ContactPhone findByCustomerId(long id); +} \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/repository/CustomerRepository.java b/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/repository/CustomerRepository.java similarity index 76% rename from persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/repository/CustomerRepository.java rename to persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/repository/CustomerRepository.java index dcde6c3b46..bd33c03b6b 100644 --- a/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/repository/CustomerRepository.java +++ b/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/repository/CustomerRepository.java @@ -1,10 +1,10 @@ -package com.baeldung.repository; +package com.baeldung.partialupdate.repository; import org.springframework.cache.annotation.Cacheable; import org.springframework.data.repository.CrudRepository; import org.springframework.stereotype.Repository; -import com.baeldung.model.Customer; +import com.baeldung.partialupdate.model.Customer; @Repository public interface CustomerRepository extends CrudRepository { diff --git a/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/repository/CustomerStructuredRepository.java b/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/repository/CustomerStructuredRepository.java new file mode 100644 index 0000000000..0f9fd1e92e --- /dev/null +++ b/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/repository/CustomerStructuredRepository.java @@ -0,0 +1,11 @@ +package com.baeldung.partialupdate.repository; + +import org.springframework.data.repository.CrudRepository; +import org.springframework.stereotype.Repository; + +import com.baeldung.partialupdate.model.CustomerStructured; + +@Repository +public interface CustomerStructuredRepository extends CrudRepository { + CustomerStructured findById(long id); +} \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/service/CustomerService.java b/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/service/CustomerService.java new file mode 100644 index 0000000000..f3a1c65ef1 --- /dev/null +++ b/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/service/CustomerService.java @@ -0,0 +1,79 @@ +package com.baeldung.partialupdate.service; + +import javax.transaction.Transactional; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import com.baeldung.partialupdate.model.ContactPhone; +import com.baeldung.partialupdate.model.Customer; +import com.baeldung.partialupdate.model.CustomerDto; +import com.baeldung.partialupdate.model.CustomerStructured; +import com.baeldung.partialupdate.repository.ContactPhoneRepository; +import com.baeldung.partialupdate.repository.CustomerRepository; +import com.baeldung.partialupdate.repository.CustomerStructuredRepository; +import com.baeldung.partialupdate.util.CustomerMapper; + +@Service +@Transactional +public class CustomerService { + + @Autowired + CustomerRepository repo; + @Autowired + CustomerStructuredRepository repo2; + @Autowired + ContactPhoneRepository repo3; + @Autowired + CustomerMapper mapper; + + public Customer addCustomer(String name) { + Customer myCustomer = new Customer(); + myCustomer.name = name; + repo.save(myCustomer); + return myCustomer; + } + + public Customer updateCustomer(long id, String phone) { + Customer myCustomer = repo.findById(id); + myCustomer.phone = phone; + repo.save(myCustomer); + return myCustomer; + } + + public Customer addCustomer(CustomerDto dto) { + Customer myCustomer = new Customer(); + mapper.updateCustomerFromDto(dto, myCustomer); + repo.save(myCustomer); + return myCustomer; + } + + public Customer updateCustomer(CustomerDto dto) { + Customer myCustomer = repo.findById(dto.getId()); + mapper.updateCustomerFromDto(dto, myCustomer); + repo.save(myCustomer); + return myCustomer; + } + + public CustomerStructured addCustomerStructured(String name) { + CustomerStructured myCustomer = new CustomerStructured(); + myCustomer.name = name; + repo2.save(myCustomer); + return myCustomer; + } + + public void addCustomerPhone(long customerId, String phone) { + ContactPhone myPhone = new ContactPhone(); + myPhone.phone = phone; + myPhone.customerId = customerId; + repo3.save(myPhone); + } + + public CustomerStructured updateCustomerStructured(long id, String name) { + CustomerStructured myCustomer = repo2.findById(id); + myCustomer.name = name; + repo2.save(myCustomer); + return myCustomer; + } + +} diff --git a/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/util/CustomerMapper.java b/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/util/CustomerMapper.java similarity index 73% rename from persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/util/CustomerMapper.java rename to persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/util/CustomerMapper.java index d4f264e33a..8a666e3e6c 100644 --- a/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/util/CustomerMapper.java +++ b/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/util/CustomerMapper.java @@ -1,12 +1,12 @@ -package com.baeldung.util; +package com.baeldung.partialupdate.util; import org.mapstruct.BeanMapping; import org.mapstruct.Mapper; import org.mapstruct.MappingTarget; import org.mapstruct.NullValuePropertyMappingStrategy; -import com.baeldung.model.Customer; -import com.baeldung.model.CustomerDto; +import com.baeldung.partialupdate.model.Customer; +import com.baeldung.partialupdate.model.CustomerDto; @Mapper(componentModel = "spring") public interface CustomerMapper { diff --git a/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/service/CustomerService.java b/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/service/CustomerService.java deleted file mode 100644 index 9ebbb0c814..0000000000 --- a/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/service/CustomerService.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.baeldung.service; - -import javax.transaction.Transactional; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -import com.baeldung.model.Customer; -import com.baeldung.model.CustomerDto; -import com.baeldung.repository.CustomerRepository; -import com.baeldung.util.CustomerMapper; - -@Service @Transactional -public class CustomerService { - - @Autowired CustomerRepository repo; - @Autowired CustomerMapper mapper; - - public Customer addCustomer(String name) { - Customer myCustomer = new Customer(); - myCustomer.name = name; - repo.save(myCustomer); - return myCustomer; - } - - public Customer updateCustomer(long id, String phone) { - Customer myCustomer = repo.findById(id); - myCustomer.phone = phone; - repo.save(myCustomer); - return myCustomer; - } - - public Customer addCustomer(CustomerDto dto) { - Customer myCustomer = new Customer(); - mapper.updateCustomerFromDto(dto, myCustomer); - repo.save(myCustomer); - return myCustomer; - } - - public Customer updateCustomer(CustomerDto dto) { - Customer myCustomer = repo.findById(dto.getId()); - mapper.updateCustomerFromDto(dto, myCustomer); - repo.save(myCustomer); - return myCustomer; - } - -} diff --git a/persistence-modules/spring-data-jpa-5/src/test/java/com/baeldung/partialupdate/PartialUpdateUnitTest.java b/persistence-modules/spring-data-jpa-5/src/test/java/com/baeldung/partialupdate/PartialUpdateUnitTest.java new file mode 100644 index 0000000000..dc9c8821ac --- /dev/null +++ b/persistence-modules/spring-data-jpa-5/src/test/java/com/baeldung/partialupdate/PartialUpdateUnitTest.java @@ -0,0 +1,56 @@ +package com.baeldung.partialupdate; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +import com.baeldung.partialupdate.model.Customer; +import com.baeldung.partialupdate.model.CustomerDto; +import com.baeldung.partialupdate.model.CustomerStructured; +import com.baeldung.partialupdate.service.CustomerService; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = PartialUpdateApplication.class) +public class PartialUpdateUnitTest { + + @Autowired + CustomerService service; + + @Test + public void loadAndSave_whenUpdate_thenSuccess() { + Customer myCustomer = service.addCustomer("John"); + myCustomer = service.updateCustomer(myCustomer.id, "+00"); + + assertEquals("+00", myCustomer.phone); + } + + @Test + public void loadAndSaveWithMapper_whenUpdate_thenSuccess() { + CustomerDto dto = new CustomerDto(new Customer()); + dto.name = "Johnny"; + Customer entity = service.addCustomer(dto); + + CustomerDto dto2 = new CustomerDto(entity.id); + dto2.phone = "+44"; + entity = service.updateCustomer(dto2); + + assertEquals("Johnny", entity.name); + } + + @Test + public void loadAndSaveStructuredEntity_whenUpdate_thenSuccess() { + CustomerStructured myCustomer = service.addCustomerStructured("John"); + assertEquals(null, myCustomer.contactPhones); + + service.addCustomerPhone(myCustomer.id, "+44"); + myCustomer = service.updateCustomerStructured(myCustomer.id, "Mr. John"); + + assertNotEquals(null, myCustomer.contactPhones); + assertEquals(1, myCustomer.contactPhones.size()); + } +} From ab1114fb7de6d78811c84132e461c0855255cf74 Mon Sep 17 00:00:00 2001 From: Michele Guarnaccia Date: Sun, 24 May 2020 11:45:17 +0200 Subject: [PATCH 033/140] Refactored packages --- .../java/com/baeldung/partialupdate/model/Customer.java | 7 +++---- .../java/com/baeldung/partialupdate/model/CustomerDto.java | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/model/Customer.java b/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/model/Customer.java index 28c5d5c76c..b19d0b7952 100644 --- a/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/model/Customer.java +++ b/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/model/Customer.java @@ -1,4 +1,4 @@ -package com.baeldung.model; +package com.baeldung.partialupdate.model; import javax.persistence.Entity; import javax.persistence.GeneratedValue; @@ -8,15 +8,14 @@ import javax.persistence.Id; @Entity public class Customer { - @Id @GeneratedValue(strategy = GenerationType.IDENTITY) + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) public long id; public String name; public String phone; //... public String phone99; - public Customer() {} - @Override public String toString() { return String.format("Customer %s, Phone: %s", this.name, this.phone); diff --git a/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/model/CustomerDto.java b/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/model/CustomerDto.java index 74b909aad8..4087838f9a 100644 --- a/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/model/CustomerDto.java +++ b/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/model/CustomerDto.java @@ -1,4 +1,4 @@ -package com.baeldung.model; +package com.baeldung.partialupdate.model; public class CustomerDto { private long id; From ce8d289cd9abdaadcf38225e25e747c62b309c51 Mon Sep 17 00:00:00 2001 From: musibs Date: Mon, 25 May 2020 09:45:10 +0530 Subject: [PATCH 034/140] Moved the testcase to core-java-lang-2 module --- .../src/test/java/com/baeldung/error/oom/TestExecutorService.java | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename core-java-modules/{core-java-lang => core-java-lang-2}/src/test/java/com/baeldung/error/oom/TestExecutorService.java (100%) diff --git a/core-java-modules/core-java-lang/src/test/java/com/baeldung/error/oom/TestExecutorService.java b/core-java-modules/core-java-lang-2/src/test/java/com/baeldung/error/oom/TestExecutorService.java similarity index 100% rename from core-java-modules/core-java-lang/src/test/java/com/baeldung/error/oom/TestExecutorService.java rename to core-java-modules/core-java-lang-2/src/test/java/com/baeldung/error/oom/TestExecutorService.java From 17d2a2f052e13b053d3cee3ac5897e9f237e8b59 Mon Sep 17 00:00:00 2001 From: Juan Moreno Date: Mon, 25 May 2020 01:43:34 -0300 Subject: [PATCH 035/140] FEAT Added sample code for BAEL-3494 --- .../core-java-9-new-features/pom.xml | 69 ++++++++++++++++++- .../com/baeldung/multireleaseapp/App.java | 14 ++++ .../multireleaseapp/DefaultVersion.java | 9 +++ .../com/baeldung/multireleaseapp/Version.java | 5 ++ .../multireleaseapp/DefaultVersion.java | 9 +++ 5 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 core-java-modules/core-java-9-new-features/src/main/java8/com/baeldung/multireleaseapp/App.java create mode 100644 core-java-modules/core-java-9-new-features/src/main/java8/com/baeldung/multireleaseapp/DefaultVersion.java create mode 100644 core-java-modules/core-java-9-new-features/src/main/java8/com/baeldung/multireleaseapp/Version.java create mode 100644 core-java-modules/core-java-9-new-features/src/main/java9/com/baeldung/multireleaseapp/DefaultVersion.java 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 b0fb6ab7f9..029d0ca2de 100644 --- a/core-java-modules/core-java-9-new-features/pom.xml +++ b/core-java-modules/core-java-9-new-features/pom.xml @@ -29,7 +29,73 @@ test
- + + + mrjar-generation + + + + org.apache.maven.plugins + maven-compiler-plugin + + + compile-java-8 + + compile + + + 1.8 + 1.8 + + ${project.basedir}/src/main/java8 + + + + + compile-java-9 + compile + + compile + + + 9 + + ${project.basedir}/src/main/java9 + + ${project.build.outputDirectory}/META-INF/versions/9 + + + + default-testCompile + test-compile + + testCompile + + + true + + + + + + org.apache.maven.plugins + maven-jar-plugin + ${maven-jar-plugin.version} + + + + true + + + com.baeldung.multireleaseapp.App + + + + + + + + core-java-9-new-features @@ -58,6 +124,7 @@ 1.2.0 1.9 1.9 + 3.2.0
diff --git a/core-java-modules/core-java-9-new-features/src/main/java8/com/baeldung/multireleaseapp/App.java b/core-java-modules/core-java-9-new-features/src/main/java8/com/baeldung/multireleaseapp/App.java new file mode 100644 index 0000000000..cc00223e05 --- /dev/null +++ b/core-java-modules/core-java-9-new-features/src/main/java8/com/baeldung/multireleaseapp/App.java @@ -0,0 +1,14 @@ +package com.baeldung.multireleaseapp; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class App { + + private static final Logger logger = LoggerFactory.getLogger(App.class); + + public static void main(String[] args) { + logger.info(String.format("Running on %s", new DefaultVersion().version())); + } + +} diff --git a/core-java-modules/core-java-9-new-features/src/main/java8/com/baeldung/multireleaseapp/DefaultVersion.java b/core-java-modules/core-java-9-new-features/src/main/java8/com/baeldung/multireleaseapp/DefaultVersion.java new file mode 100644 index 0000000000..b24be606de --- /dev/null +++ b/core-java-modules/core-java-9-new-features/src/main/java8/com/baeldung/multireleaseapp/DefaultVersion.java @@ -0,0 +1,9 @@ +package com.baeldung.multireleaseapp; + +public class DefaultVersion implements Version { + + @Override + public String version() { + return System.getProperty("java.version"); + } +} diff --git a/core-java-modules/core-java-9-new-features/src/main/java8/com/baeldung/multireleaseapp/Version.java b/core-java-modules/core-java-9-new-features/src/main/java8/com/baeldung/multireleaseapp/Version.java new file mode 100644 index 0000000000..ef95f08205 --- /dev/null +++ b/core-java-modules/core-java-9-new-features/src/main/java8/com/baeldung/multireleaseapp/Version.java @@ -0,0 +1,5 @@ +package com.baeldung.multireleaseapp; + +interface Version { + public String version(); +} \ No newline at end of file diff --git a/core-java-modules/core-java-9-new-features/src/main/java9/com/baeldung/multireleaseapp/DefaultVersion.java b/core-java-modules/core-java-9-new-features/src/main/java9/com/baeldung/multireleaseapp/DefaultVersion.java new file mode 100644 index 0000000000..0842f578dd --- /dev/null +++ b/core-java-modules/core-java-9-new-features/src/main/java9/com/baeldung/multireleaseapp/DefaultVersion.java @@ -0,0 +1,9 @@ +package com.baeldung.multireleaseapp; + +public class DefaultVersion implements Version { + + @Override + public String version() { + return Runtime.version().toString(); + } +} From 102a487aaa3288280e595dd7c623c0eea66207d3 Mon Sep 17 00:00:00 2001 From: Juan Moreno Date: Mon, 25 May 2020 02:09:21 -0300 Subject: [PATCH 036/140] FIX PMD bugs, dependency missing, compilation incubator features, fix awaitility asserts --- .../core-java-9-new-features/pom.xml | 31 +++++++++++++++++ ...st.java => HttpClientIntegrationTest.java} | 4 +-- ...t.java => HttpRequestIntegrationTest.java} | 2 +- ....java => HttpResponseIntegrationTest.java} | 2 +- ...Test.java => ReactiveStreamsUnitTest.java} | 12 ++++--- ...Test.java => VariableHandlesUnitTest.java} | 34 +++++++++---------- 6 files changed, 59 insertions(+), 26 deletions(-) rename core-java-modules/core-java-9-new-features/src/test/java/com/baeldung/java9/httpclient/{HttpClientTest.java => HttpClientIntegrationTest.java} (98%) rename core-java-modules/core-java-9-new-features/src/test/java/com/baeldung/java9/httpclient/{HttpRequestTest.java => HttpRequestIntegrationTest.java} (99%) rename core-java-modules/core-java-9-new-features/src/test/java/com/baeldung/java9/httpclient/{HttpResponseTest.java => HttpResponseIntegrationTest.java} (97%) rename core-java-modules/core-java-9-new-features/src/test/java/com/baeldung/java9/streams.reactive/{ReactiveStreamsTest.java => ReactiveStreamsUnitTest.java} (86%) rename core-java-modules/core-java-9-new-features/src/test/java/com/baeldung/java9/varhandles/{VariableHandlesTest.java => VariableHandlesUnitTest.java} (75%) 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 029d0ca2de..70fae73bd5 100644 --- a/core-java-modules/core-java-9-new-features/pom.xml +++ b/core-java-modules/core-java-9-new-features/pom.xml @@ -28,8 +28,38 @@ ${junit.platform.version} test
+ + org.awaitility + awaitility + ${awaitility.version} + test + + + incubator-features + + core-java-9-new-features + + + org.apache.maven.plugins + maven-compiler-plugin + ${maven-compiler-plugin.version} + + ${maven.compiler.source} + ${maven.compiler.target} + --add-modules=jdk.incubator.httpclient + + + + maven-surefire-plugin + + --add-modules=jdk.incubator.httpclient + + + + + mrjar-generation @@ -122,6 +152,7 @@ 3.10.0 1.2.0 + 4.0.2 1.9 1.9 3.2.0 diff --git a/core-java-modules/core-java-9-new-features/src/test/java/com/baeldung/java9/httpclient/HttpClientTest.java b/core-java-modules/core-java-9-new-features/src/test/java/com/baeldung/java9/httpclient/HttpClientIntegrationTest.java similarity index 98% rename from core-java-modules/core-java-9-new-features/src/test/java/com/baeldung/java9/httpclient/HttpClientTest.java rename to core-java-modules/core-java-9-new-features/src/test/java/com/baeldung/java9/httpclient/HttpClientIntegrationTest.java index 5cf3b9098f..fc59ae8d8d 100644 --- a/core-java-modules/core-java-9-new-features/src/test/java/com/baeldung/java9/httpclient/HttpClientTest.java +++ b/core-java-modules/core-java-9-new-features/src/test/java/com/baeldung/java9/httpclient/HttpClientIntegrationTest.java @@ -24,7 +24,7 @@ import static org.junit.Assert.assertThat; /** * Created by adam. */ -public class HttpClientTest { +public class HttpClientIntegrationTest { @Test public void shouldReturnSampleDataContentWhenConnectViaSystemProxy() throws IOException, InterruptedException, URISyntaxException { @@ -55,7 +55,7 @@ public class HttpClientTest { .send(request, HttpResponse.BodyHandler.asString()); assertThat(response.statusCode(), equalTo(HttpURLConnection.HTTP_MOVED_PERM)); - assertThat(response.body(), containsString("https://stackoverflow.com/")); + assertThat(response.body(), containsString("")); } @Test diff --git a/core-java-modules/core-java-9-new-features/src/test/java/com/baeldung/java9/httpclient/HttpRequestTest.java b/core-java-modules/core-java-9-new-features/src/test/java/com/baeldung/java9/httpclient/HttpRequestIntegrationTest.java similarity index 99% rename from core-java-modules/core-java-9-new-features/src/test/java/com/baeldung/java9/httpclient/HttpRequestTest.java rename to core-java-modules/core-java-9-new-features/src/test/java/com/baeldung/java9/httpclient/HttpRequestIntegrationTest.java index 7c0e9a90e0..17af7bd8ba 100644 --- a/core-java-modules/core-java-9-new-features/src/test/java/com/baeldung/java9/httpclient/HttpRequestTest.java +++ b/core-java-modules/core-java-9-new-features/src/test/java/com/baeldung/java9/httpclient/HttpRequestIntegrationTest.java @@ -22,7 +22,7 @@ import static org.junit.Assert.assertThat; /** * Created by adam. */ -public class HttpRequestTest { +public class HttpRequestIntegrationTest { @Test public void shouldReturnStatusOKWhenSendGetRequest() throws IOException, InterruptedException, URISyntaxException { diff --git a/core-java-modules/core-java-9-new-features/src/test/java/com/baeldung/java9/httpclient/HttpResponseTest.java b/core-java-modules/core-java-9-new-features/src/test/java/com/baeldung/java9/httpclient/HttpResponseIntegrationTest.java similarity index 97% rename from core-java-modules/core-java-9-new-features/src/test/java/com/baeldung/java9/httpclient/HttpResponseTest.java rename to core-java-modules/core-java-9-new-features/src/test/java/com/baeldung/java9/httpclient/HttpResponseIntegrationTest.java index 80295ff34c..5c6f9c8a52 100644 --- a/core-java-modules/core-java-9-new-features/src/test/java/com/baeldung/java9/httpclient/HttpResponseTest.java +++ b/core-java-modules/core-java-9-new-features/src/test/java/com/baeldung/java9/httpclient/HttpResponseIntegrationTest.java @@ -18,7 +18,7 @@ import static org.junit.Assert.assertThat; /** * Created by adam. */ -public class HttpResponseTest { +public class HttpResponseIntegrationTest { @Test public void shouldReturnStatusOKWhenSendGetRequest() throws IOException, InterruptedException, URISyntaxException { diff --git a/core-java-modules/core-java-9-new-features/src/test/java/com/baeldung/java9/streams.reactive/ReactiveStreamsTest.java b/core-java-modules/core-java-9-new-features/src/test/java/com/baeldung/java9/streams.reactive/ReactiveStreamsUnitTest.java similarity index 86% rename from core-java-modules/core-java-9-new-features/src/test/java/com/baeldung/java9/streams.reactive/ReactiveStreamsTest.java rename to core-java-modules/core-java-9-new-features/src/test/java/com/baeldung/java9/streams.reactive/ReactiveStreamsUnitTest.java index 647557532d..92cdc1c074 100644 --- a/core-java-modules/core-java-9-new-features/src/test/java/com/baeldung/java9/streams.reactive/ReactiveStreamsTest.java +++ b/core-java-modules/core-java-9-new-features/src/test/java/com/baeldung/java9/streams.reactive/ReactiveStreamsUnitTest.java @@ -5,10 +5,12 @@ import org.junit.Test; import java.util.List; import java.util.concurrent.SubmissionPublisher; +import java.util.concurrent.TimeUnit; -import static org.assertj.core.api.Java6Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThat; +import static org.awaitility.Awaitility.await; -public class ReactiveStreamsTest { +public class ReactiveStreamsUnitTest { @Test public void givenPublisher_whenSubscribeToIt_thenShouldConsumeAllElements() throws InterruptedException { @@ -25,7 +27,7 @@ public class ReactiveStreamsTest { //then - await().atMost(1000, TimeUnit.MILLISECONDS).until( + await().atMost(1000, TimeUnit.MILLISECONDS).untilAsserted( () -> assertThat(subscriber.consumedElements).containsExactlyElementsOf(items) ); } @@ -46,7 +48,7 @@ public class ReactiveStreamsTest { publisher.close(); //then - await().atMost(1000, TimeUnit.MILLISECONDS).until( + await().atMost(1000, TimeUnit.MILLISECONDS).untilAsserted( () -> assertThat(subscriber.consumedElements).containsExactlyElementsOf(expectedResult) ); } @@ -66,7 +68,7 @@ public class ReactiveStreamsTest { publisher.close(); //then - await().atMost(1000, TimeUnit.MILLISECONDS).until( + await().atMost(1000, TimeUnit.MILLISECONDS).untilAsserted( () -> assertThat(subscriber.consumedElements).containsExactlyElementsOf(expected) ); } diff --git a/core-java-modules/core-java-9-new-features/src/test/java/com/baeldung/java9/varhandles/VariableHandlesTest.java b/core-java-modules/core-java-9-new-features/src/test/java/com/baeldung/java9/varhandles/VariableHandlesUnitTest.java similarity index 75% rename from core-java-modules/core-java-9-new-features/src/test/java/com/baeldung/java9/varhandles/VariableHandlesTest.java rename to core-java-modules/core-java-9-new-features/src/test/java/com/baeldung/java9/varhandles/VariableHandlesUnitTest.java index 50766502ec..56e34f06a0 100644 --- a/core-java-modules/core-java-9-new-features/src/test/java/com/baeldung/java9/varhandles/VariableHandlesTest.java +++ b/core-java-modules/core-java-9-new-features/src/test/java/com/baeldung/java9/varhandles/VariableHandlesUnitTest.java @@ -7,7 +7,7 @@ import java.lang.invoke.VarHandle; import static org.assertj.core.api.Assertions.assertThat; -public class VariableHandlesTest { +public class VariableHandlesUnitTest { public int publicTestVariable = 1; private int privateTestVariable = 1; @@ -20,22 +20,22 @@ public class VariableHandlesTest { public void whenVariableHandleForPublicVariableIsCreated_ThenItIsInitializedProperly() throws NoSuchFieldException, IllegalAccessException { VarHandle publicIntHandle = MethodHandles .lookup() - .in(VariableHandlesTest.class) - .findVarHandle(VariableHandlesTest.class, "publicTestVariable", int.class); + .in(VariableHandlesUnitTest.class) + .findVarHandle(VariableHandlesUnitTest.class, "publicTestVariable", int.class); assertThat(publicIntHandle.coordinateTypes().size() == 1); - assertThat(publicIntHandle.coordinateTypes().get(0) == VariableHandles.class); + assertThat(publicIntHandle.coordinateTypes().get(0) == VariableHandlesUnitTest.class); } @Test public void whenVariableHandleForPrivateVariableIsCreated_ThenItIsInitializedProperly() throws NoSuchFieldException, IllegalAccessException { VarHandle privateIntHandle = MethodHandles - .privateLookupIn(VariableHandlesTest.class, MethodHandles.lookup()) - .findVarHandle(VariableHandlesTest.class, "privateTestVariable", int.class); + .privateLookupIn(VariableHandlesUnitTest.class, MethodHandles.lookup()) + .findVarHandle(VariableHandlesUnitTest.class, "privateTestVariable", int.class); assertThat(privateIntHandle.coordinateTypes().size() == 1); - assertThat(privateIntHandle.coordinateTypes().get(0) == VariableHandlesTest.class); + assertThat(privateIntHandle.coordinateTypes().get(0) == VariableHandlesUnitTest.class); } @@ -52,8 +52,8 @@ public class VariableHandlesTest { public void givenVarHandle_whenGetIsInvoked_ThenValueOfVariableIsReturned() throws NoSuchFieldException, IllegalAccessException { VarHandle publicIntHandle = MethodHandles .lookup() - .in(VariableHandlesTest.class) - .findVarHandle(VariableHandlesTest.class, "publicTestVariable", int.class); + .in(VariableHandlesUnitTest.class) + .findVarHandle(VariableHandlesUnitTest.class, "publicTestVariable", int.class); assertThat((int) publicIntHandle.get(this) == 1); } @@ -62,8 +62,8 @@ public class VariableHandlesTest { public void givenVarHandle_whenSetIsInvoked_ThenValueOfVariableIsChanged() throws NoSuchFieldException, IllegalAccessException { VarHandle publicIntHandle = MethodHandles .lookup() - .in(VariableHandlesTest.class) - .findVarHandle(VariableHandlesTest.class, "variableToSet", int.class); + .in(VariableHandlesUnitTest.class) + .findVarHandle(VariableHandlesUnitTest.class, "variableToSet", int.class); publicIntHandle.set(this, 15); assertThat((int) publicIntHandle.get(this) == 15); @@ -73,8 +73,8 @@ public class VariableHandlesTest { public void givenVarHandle_whenCompareAndSetIsInvoked_ThenValueOfVariableIsChanged() throws NoSuchFieldException, IllegalAccessException { VarHandle publicIntHandle = MethodHandles .lookup() - .in(VariableHandlesTest.class) - .findVarHandle(VariableHandlesTest.class, "variableToCompareAndSet", int.class); + .in(VariableHandlesUnitTest.class) + .findVarHandle(VariableHandlesUnitTest.class, "variableToCompareAndSet", int.class); publicIntHandle.compareAndSet(this, 1, 100); assertThat((int) publicIntHandle.get(this) == 100); @@ -84,8 +84,8 @@ public class VariableHandlesTest { public void givenVarHandle_whenGetAndAddIsInvoked_ThenValueOfVariableIsChanged() throws NoSuchFieldException, IllegalAccessException { VarHandle publicIntHandle = MethodHandles .lookup() - .in(VariableHandlesTest.class) - .findVarHandle(VariableHandlesTest.class, "variableToGetAndAdd", int.class); + .in(VariableHandlesUnitTest.class) + .findVarHandle(VariableHandlesUnitTest.class, "variableToGetAndAdd", int.class); int before = (int) publicIntHandle.getAndAdd(this, 200); assertThat(before == 0); @@ -96,8 +96,8 @@ public class VariableHandlesTest { public void givenVarHandle_whenGetAndBitwiseOrIsInvoked_ThenValueOfVariableIsChanged() throws NoSuchFieldException, IllegalAccessException { VarHandle publicIntHandle = MethodHandles .lookup() - .in(VariableHandlesTest.class) - .findVarHandle(VariableHandlesTest.class, "variableToBitwiseOr", byte.class); + .in(VariableHandlesUnitTest.class) + .findVarHandle(VariableHandlesUnitTest.class, "variableToBitwiseOr", byte.class); byte before = (byte) publicIntHandle.getAndBitwiseOr(this, (byte) 127); assertThat(before == 0); From 8a771a8b467baf06aca796296fe5e85bafbd1421 Mon Sep 17 00:00:00 2001 From: Ashley Frieze Date: Fri, 22 May 2020 12:42:39 +0100 Subject: [PATCH 037/140] Rework the delete everything in Redis example --- persistence-modules/redis/README.md | 1 + persistence-modules/redis/pom.xml | 3 +- ...eleteEverythingInRedisIntegrationTest.java | 91 ++++++++++++++++++ .../spring-data-redis/README.md | 2 - .../spring/data/redis/config/RedisConfig.java | 12 --- .../RedisFlushDatabaseIntegrationTest.java | 92 ------------------- 6 files changed, 94 insertions(+), 107 deletions(-) create mode 100644 persistence-modules/redis/src/test/java/com/baeldung/redis/deleteeverything/DeleteEverythingInRedisIntegrationTest.java delete mode 100644 persistence-modules/spring-data-redis/src/test/java/com/baeldung/spring/data/redis/delete/RedisFlushDatabaseIntegrationTest.java diff --git a/persistence-modules/redis/README.md b/persistence-modules/redis/README.md index 71d009241a..75c1c18de4 100644 --- a/persistence-modules/redis/README.md +++ b/persistence-modules/redis/README.md @@ -4,3 +4,4 @@ - [Introduction to Lettuce – the Java Redis Client](https://www.baeldung.com/java-redis-lettuce) - [List All Available Redis Keys](https://www.baeldung.com/redis-list-available-keys) - [Spring Data Redis’s Property-Based Configuration](https://www.baeldung.com/spring-data-redis-properties) +- [Delete Everything in Redis](https://www.baeldung.com/redis-delete-data) diff --git a/persistence-modules/redis/pom.xml b/persistence-modules/redis/pom.xml index c9206e5f92..dab7fc5654 100644 --- a/persistence-modules/redis/pom.xml +++ b/persistence-modules/redis/pom.xml @@ -33,7 +33,8 @@ redis.clients jedis - + 3.3.0 + com.github.kstyrc embedded-redis diff --git a/persistence-modules/redis/src/test/java/com/baeldung/redis/deleteeverything/DeleteEverythingInRedisIntegrationTest.java b/persistence-modules/redis/src/test/java/com/baeldung/redis/deleteeverything/DeleteEverythingInRedisIntegrationTest.java new file mode 100644 index 0000000000..e0376fc6a5 --- /dev/null +++ b/persistence-modules/redis/src/test/java/com/baeldung/redis/deleteeverything/DeleteEverythingInRedisIntegrationTest.java @@ -0,0 +1,91 @@ +package com.baeldung.redis.deleteeverything; + +import org.junit.*; +import redis.clients.jedis.Jedis; +import redis.embedded.RedisServer; + +import java.io.IOException; +import java.net.ServerSocket; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +public class DeleteEverythingInRedisIntegrationTest { + private Jedis jedis; + private RedisServer redisServer; + private int port; + + @Before + public void setUp() throws IOException { + + // Take an available port + ServerSocket s = new ServerSocket(0); + port = s.getLocalPort(); + s.close(); + + redisServer = new RedisServer(port); + redisServer.start(); + + // Configure JEDIS + jedis = new Jedis("localhost", port); + } + + @After + public void destroy() { + redisServer.stop(); + } + + @Test + public void whenPutDataIntoRedis_thenCanBeFound() { + String key = "key"; + String value = "value"; + + jedis.set(key, value); + String received = jedis.get(key); + + assertEquals(value, received); + } + + @Test + public void whenPutDataIntoRedisAndThenFlush_thenCannotBeFound() { + String key = "key"; + String value = "value"; + + jedis.set(key, value); + + jedis.flushDB(); + + String received = jedis.get(key); + + assertNull(received); + } + + @Test + public void whenPutDataIntoMultipleDatabases_thenFlushAllRemovesAll() { + // add keys in different databases + jedis.select(0); + jedis.set("key1", "value1"); + jedis.select(1); + jedis.set("key2", "value2"); + + // we'll find the correct keys in the correct dbs + jedis.select(0); + assertEquals("value1", jedis.get("key1")); + assertNull(jedis.get("key2")); + + jedis.select(1); + assertEquals("value2", jedis.get("key2")); + assertNull(jedis.get("key1")); + + // then, when we flush + jedis.flushAll(); + + // the keys will have gone + jedis.select(0); + assertNull(jedis.get("key1")); + assertNull(jedis.get("key2")); + jedis.select(1); + assertNull(jedis.get("key1")); + assertNull(jedis.get("key2")); + } +} diff --git a/persistence-modules/spring-data-redis/README.md b/persistence-modules/spring-data-redis/README.md index 175634376b..95cba2c159 100644 --- a/persistence-modules/spring-data-redis/README.md +++ b/persistence-modules/spring-data-redis/README.md @@ -4,7 +4,6 @@ - [Introduction to Spring Data Redis](https://www.baeldung.com/spring-data-redis-tutorial) - [PubSub Messaging with Spring Data Redis](https://www.baeldung.com/spring-data-redis-pub-sub) - [An Introduction to Spring Data Redis Reactive](https://www.baeldung.com/spring-data-redis-reactive) -- [Delete Everything in Redis](https://www.baeldung.com/redis-delete-data) ### Build the Project with Tests Running ``` @@ -15,4 +14,3 @@ mvn clean install ``` mvn test ``` - diff --git a/persistence-modules/spring-data-redis/src/main/java/com/baeldung/spring/data/redis/config/RedisConfig.java b/persistence-modules/spring-data-redis/src/main/java/com/baeldung/spring/data/redis/config/RedisConfig.java index fdc279be42..497e1506bd 100644 --- a/persistence-modules/spring-data-redis/src/main/java/com/baeldung/spring/data/redis/config/RedisConfig.java +++ b/persistence-modules/spring-data-redis/src/main/java/com/baeldung/spring/data/redis/config/RedisConfig.java @@ -35,18 +35,6 @@ public class RedisConfig { template.setValueSerializer(new GenericToStringSerializer(Object.class)); return template; } - - @Bean - public LettuceConnectionFactory lettuceConnectionFactory() { - return new LettuceConnectionFactory(); - } - - @Bean(name = "flushRedisTemplate") - public RedisTemplate flushRedisTemplate() { - RedisTemplate template = new RedisTemplate<>(); - template.setConnectionFactory(lettuceConnectionFactory()); - return template; - } @Bean MessageListenerAdapter messageListener() { diff --git a/persistence-modules/spring-data-redis/src/test/java/com/baeldung/spring/data/redis/delete/RedisFlushDatabaseIntegrationTest.java b/persistence-modules/spring-data-redis/src/test/java/com/baeldung/spring/data/redis/delete/RedisFlushDatabaseIntegrationTest.java deleted file mode 100644 index 1f56cbb25d..0000000000 --- a/persistence-modules/spring-data-redis/src/test/java/com/baeldung/spring/data/redis/delete/RedisFlushDatabaseIntegrationTest.java +++ /dev/null @@ -1,92 +0,0 @@ -package com.baeldung.spring.data.redis.delete; - -import static org.assertj.core.api.Assertions.assertThat; - -import java.io.IOException; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.dao.DataAccessException; -import org.springframework.data.redis.connection.RedisConnection; -import org.springframework.data.redis.core.RedisCallback; -import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.data.redis.core.ValueOperations; -import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.annotation.DirtiesContext.ClassMode; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -import com.baeldung.spring.data.redis.config.RedisConfig; - -import redis.embedded.RedisServer; - -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = { RedisConfig.class }) -@DirtiesContext(classMode = ClassMode.BEFORE_CLASS) -public class RedisFlushDatabaseIntegrationTest { - - private RedisServer redisServer; - - @Autowired - @Qualifier("flushRedisTemplate") - private RedisTemplate flushRedisTemplate; - - @Before - public void setup() throws IOException { - redisServer = new RedisServer(6390); - redisServer.start(); - } - - @After - public void tearDown() { - redisServer.stop(); - } - - @Test - public void whenFlushDB_thenAllKeysInDatabaseAreCleared() { - - ValueOperations simpleValues = flushRedisTemplate.opsForValue(); - String key = "key"; - String value = "value"; - simpleValues.set(key, value); - assertThat(simpleValues.get(key)).isEqualTo(value); - - flushRedisTemplate.execute(new RedisCallback() { - - @Override - public Void doInRedis(RedisConnection connection) throws DataAccessException { - connection.flushDb(); - return null; - } - }); - - assertThat(simpleValues.get(key)).isNull(); - - } - - @Test - public void whenFlushAll_thenAllKeysInDatabasesAreCleared() { - - ValueOperations simpleValues = flushRedisTemplate.opsForValue(); - String key = "key"; - String value = "value"; - simpleValues.set(key, value); - assertThat(simpleValues.get(key)).isEqualTo(value); - - flushRedisTemplate.execute(new RedisCallback() { - - @Override - public Void doInRedis(RedisConnection connection) throws DataAccessException { - connection.flushAll(); - return null; - } - }); - - assertThat(simpleValues.get(key)).isNull(); - - } -} \ No newline at end of file From 11d0ab1b4984095d52a379c16aad81d19af2a7fe Mon Sep 17 00:00:00 2001 From: Vikas Ramsingh Rajput Date: Tue, 26 May 2020 12:59:40 +0300 Subject: [PATCH 038/140] BAEL-3067: Changed method name and added latest maven dependency of org.json --- core-java-modules/core-java-io-conversions-2/pom.xml | 2 +- .../JavaBufferedReaderToJSONObjectUnitTest.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/core-java-modules/core-java-io-conversions-2/pom.xml b/core-java-modules/core-java-io-conversions-2/pom.xml index 7a83d4b502..c1148509f3 100644 --- a/core-java-modules/core-java-io-conversions-2/pom.xml +++ b/core-java-modules/core-java-io-conversions-2/pom.xml @@ -25,7 +25,7 @@ org.json json - 20190722 + 20200518 diff --git a/core-java-modules/core-java-io-conversions-2/src/test/java/com/baeldung/bufferedreadertojsonobject/JavaBufferedReaderToJSONObjectUnitTest.java b/core-java-modules/core-java-io-conversions-2/src/test/java/com/baeldung/bufferedreadertojsonobject/JavaBufferedReaderToJSONObjectUnitTest.java index d42c3975db..80007e9c2f 100644 --- a/core-java-modules/core-java-io-conversions-2/src/test/java/com/baeldung/bufferedreadertojsonobject/JavaBufferedReaderToJSONObjectUnitTest.java +++ b/core-java-modules/core-java-io-conversions-2/src/test/java/com/baeldung/bufferedreadertojsonobject/JavaBufferedReaderToJSONObjectUnitTest.java @@ -17,7 +17,7 @@ import org.junit.Test; public class JavaBufferedReaderToJSONObjectUnitTest { @Test - public void givenUsingNewVersion_whenConvertBufferedReaderToJSONObject_thenCorrect() { + public void givenValidJson_whenUsingBufferedReader_thenJSONTokenerConverts() { byte[] b = "{ \"name\" : \"John\", \"age\" : 18 }".getBytes(StandardCharsets.UTF_8); InputStream is = new ByteArrayInputStream(b); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(is)); @@ -30,7 +30,7 @@ public class JavaBufferedReaderToJSONObjectUnitTest { } @Test - public void givenUsingOldVersion_whenConvertBufferedReaderToJSONObject_thenCorrect() throws IOException { + public void givenValidJson_whenUsingString_thenJSONObjectConverts() throws IOException { byte[] b = "{ \"name\" : \"John\", \"age\" : 18 }".getBytes(StandardCharsets.UTF_8); InputStream is = new ByteArrayInputStream(b); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(is)); From 7943a59707c9534e2f24c90106b32efdcc771dbe Mon Sep 17 00:00:00 2001 From: Chirag Dewan Date: Tue, 26 May 2020 17:23:59 +0530 Subject: [PATCH 039/140] BAEL3889 - Kafka Mock Producer --- .../src/main/java/com/baeldung/kafka/EvenOddPartitioner.java | 0 .../src/main/java/com/baeldung/kafka/KafkaProducer.java | 0 .../src/test/java/com/baeldung/kafka/KafkaProducerUnitTest.java | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename {libraries => libraries-6}/src/main/java/com/baeldung/kafka/EvenOddPartitioner.java (100%) rename {libraries => libraries-6}/src/main/java/com/baeldung/kafka/KafkaProducer.java (100%) rename {libraries => libraries-6}/src/test/java/com/baeldung/kafka/KafkaProducerUnitTest.java (100%) diff --git a/libraries/src/main/java/com/baeldung/kafka/EvenOddPartitioner.java b/libraries-6/src/main/java/com/baeldung/kafka/EvenOddPartitioner.java similarity index 100% rename from libraries/src/main/java/com/baeldung/kafka/EvenOddPartitioner.java rename to libraries-6/src/main/java/com/baeldung/kafka/EvenOddPartitioner.java diff --git a/libraries/src/main/java/com/baeldung/kafka/KafkaProducer.java b/libraries-6/src/main/java/com/baeldung/kafka/KafkaProducer.java similarity index 100% rename from libraries/src/main/java/com/baeldung/kafka/KafkaProducer.java rename to libraries-6/src/main/java/com/baeldung/kafka/KafkaProducer.java diff --git a/libraries/src/test/java/com/baeldung/kafka/KafkaProducerUnitTest.java b/libraries-6/src/test/java/com/baeldung/kafka/KafkaProducerUnitTest.java similarity index 100% rename from libraries/src/test/java/com/baeldung/kafka/KafkaProducerUnitTest.java rename to libraries-6/src/test/java/com/baeldung/kafka/KafkaProducerUnitTest.java From 18d00eae62ea63c5d489f9dcb8eb96f196f424d2 Mon Sep 17 00:00:00 2001 From: "alex.peptan" Date: Wed, 27 May 2020 11:57:14 +0300 Subject: [PATCH 040/140] BAEL-3896: OpenAPI JSON Objects in Query Params - swagger definitions moved in resources --- .../jsonParamOpenApiSwagger3Definition | 32 ---- .../jsonParamOpenApiSwaggerDefinition | 172 ------------------ .../openapi-2.json | 75 ++++++++ .../openapi-3.json | 37 ++++ 4 files changed, 112 insertions(+), 204 deletions(-) delete mode 100644 spring-rest-http/src/main/java/com/baeldung/jsonparam/jsonParamOpenApiSwagger3Definition delete mode 100644 spring-rest-http/src/main/java/com/baeldung/jsonparam/jsonParamOpenApiSwaggerDefinition create mode 100644 spring-rest-http/src/main/resources/openapi-queryparam-definitions/openapi-2.json create mode 100644 spring-rest-http/src/main/resources/openapi-queryparam-definitions/openapi-3.json diff --git a/spring-rest-http/src/main/java/com/baeldung/jsonparam/jsonParamOpenApiSwagger3Definition b/spring-rest-http/src/main/java/com/baeldung/jsonparam/jsonParamOpenApiSwagger3Definition deleted file mode 100644 index 218e24b12b..0000000000 --- a/spring-rest-http/src/main/java/com/baeldung/jsonparam/jsonParamOpenApiSwagger3Definition +++ /dev/null @@ -1,32 +0,0 @@ -swagger: '3.0' -info: - title: Sample API to send JSON objects as query parameters using OpenAPI 3 - description: API description. - version: 1.0.0 - -paths: - /tickets: - get: - parameters: - - in: query - name: params - required: true - # Parameter is an object that should be serialized as JSON - content: - application/json: - schema: - type: object - properties: - type: - type: string - name: - color: string - responses: - '200': - description: successful process - '401': - description: Unauthorized - '403': - description: Forbidden - '404': - description: Not Found diff --git a/spring-rest-http/src/main/java/com/baeldung/jsonparam/jsonParamOpenApiSwaggerDefinition b/spring-rest-http/src/main/java/com/baeldung/jsonparam/jsonParamOpenApiSwaggerDefinition deleted file mode 100644 index 3261736e15..0000000000 --- a/spring-rest-http/src/main/java/com/baeldung/jsonparam/jsonParamOpenApiSwaggerDefinition +++ /dev/null @@ -1,172 +0,0 @@ -swagger: '2.0' -info: - title: Sample API to send JSON objects as query parameters using OpenAPI 2 - description: API description. - version: 1.0.0 - -paths: - /tickets: - get: - parameters: - - in: query - name: params - required: true - description: A JSON object with the `type` and `color` properties - type: string - example: '{"type":"foo","color":"green"}' - responses: - '200': - description: successful process - '401': - description: Unauthorized - '403': - description: Forbidden - '404': - description: Not Found - - /tickets: - post: - requestBody: - description: Parameter is an object that should be serialized as JSON - content: - application/json: - schema: - type: string - example: '{"type":"foo","color":"green"}' - responses: - '200': - description: successful process - '201': - description: Created - '401': - description: Unauthorized - '403': - description: Forbidden - '404': - description: Not Found - - /api/tickets: { - get: { - tags: [ - "account-resource" - ], - summary: "testQueryParamApi", - operationId: "testQueryParamApiUsingGET", - produces: [ - "*/*" - ], - parameters: [ - { - name: "params", - in: "query", - description: "params", - required: true, - type: "string" - } - ], - responses: { - 200: { - description: "OK", - schema: { - type: "string" - } - }, - 401: { - description: "Unauthorized" - }, - 403: { - description: "Forbidden" - }, - 404: { - description: "Not Found" - } - }, - deprecated: false - }, - post: { - tags: [ - "account-resource" - ], - summary: "testBodyParamApi", - operationId: "testBodyParamApiUsingPOST", - consumes: [ - "application/json" - ], - produces: [ - "*/*" - ], - parameters: [ - { - in: "body", - name: "params", - description: "params", - required: true, - schema: { - type: "string" - } - } - ], - responses: { - 200: { - description: "OK", - schema: { - type: "string" - } - }, - 201: { - description: "Created" - }, - 401: { - description: "Unauthorized" - }, - 403: { - description: "Forbidden" - }, - 404: { - description: "Not Found" - } - }, - deprecated: false - } - }, - /api/tickets2: { - get: { - tags: [ - "account-resource" - ], - summary: "testGetBodyParamApi", - operationId: "testGetBodyParamApiUsingGET", - produces: [ - "*/*" - ], - parameters: [ - { - in: "body", - name: "params", - description: "params", - required: true, - schema: { - type: "string" - } - } - ], - responses: { - 200: { - description: "OK", - schema: { - type: "string" - } - }, - 401: { - description: "Unauthorized" - }, - 403: { - description: "Forbidden" - }, - 404: { - description: "Not Found" - } - }, - deprecated: false - } - } diff --git a/spring-rest-http/src/main/resources/openapi-queryparam-definitions/openapi-2.json b/spring-rest-http/src/main/resources/openapi-queryparam-definitions/openapi-2.json new file mode 100644 index 0000000000..53272c9cdb --- /dev/null +++ b/spring-rest-http/src/main/resources/openapi-queryparam-definitions/openapi-2.json @@ -0,0 +1,75 @@ +swagger: "2.0" +info: + description: "This is a sample server." + version: "1.0.0" + title: "Sample API to send JSON objects as query parameters using OpenAPI 2" +tags: +- name: "tickets" + description: "Send Tickets as JSON Objects" +schemes: +- "https" +- "http" +paths: + /tickets: + get: + tags: + - "tickets" + summary: "Send an JSON Object as a query param" + parameters: + - name: "params" + in: "path" + description: "{\"type\":\"foo\",\"color\":\"green\"}" + required: true + type: "string" + responses: + "200": + description: "Successful operation" + "401": + description: "Unauthorized" + "403": + description: "Forbidden" + "404": + description: "Not found" + post: + tags: + - "tickets" + summary: "Send an JSON Object in body" + parameters: + - name: "params" + in: "body" + description: "Parameter is an JSON object with the `type` and `color` properties that should be serialized as JSON {\"type\":\"foo\",\"color\":\"green\"}" + required: true + schema: + type: string + responses: + "200": + description: "Successful operation" + "401": + description: "Unauthorized" + "403": + description: "Forbidden" + "404": + description: "Not found" + "405": + description: "Invalid input" + /tickets2: + get: + tags: + - "tickets" + summary: "Send an JSON Object in body of get reqest" + parameters: + - name: "params" + in: "body" + description: "Parameter is an JSON object with the `type` and `color` properties that should be serialized as JSON {\"type\":\"foo\",\"color\":\"green\"}" + required: true + schema: + type: string + responses: + "200": + description: "Successful operation" + "401": + description: "Unauthorized" + "403": + description: "Forbidden" + "404": + description: "Not found" diff --git a/spring-rest-http/src/main/resources/openapi-queryparam-definitions/openapi-3.json b/spring-rest-http/src/main/resources/openapi-queryparam-definitions/openapi-3.json new file mode 100644 index 0000000000..a0ed147b9d --- /dev/null +++ b/spring-rest-http/src/main/resources/openapi-queryparam-definitions/openapi-3.json @@ -0,0 +1,37 @@ +openapi: 3.0.1 +info: + title: Sample API to send JSON objects as query parameters using OpenAPI 3 + description: This is a sample server. + version: 1.0.0 +servers: +- url: /api +tags: +- name: tickets + description: Send Tickets as JSON Objects +paths: + /tickets: + get: + tags: + - tickets + summary: Send an JSON Object as a query param + parameters: + - name: params + in: query + description: '{"type":"foo","color":"green"}' + required: true + schema: + type: object + properties: + type: + type: "string" + color: + type: "string" + responses: + 200: + description: Successful operation + 401: + description: Unauthorized + 403: + description: Forbidden + 404: + description: Not found From e1c3aed23b75c41a28e479ad01a31dcdfc051c66 Mon Sep 17 00:00:00 2001 From: Michele Guarnaccia Date: Wed, 27 May 2020 19:43:04 +0200 Subject: [PATCH 041/140] Added @Query method + clean --- .../PartialUpdateApplication.java | 8 ------- .../partialupdate/model/ContactPhone.java | 4 ++-- .../partialupdate/model/CustomerDto.java | 12 +++++----- .../model/CustomerStructured.java | 7 +++--- .../repository/ContactPhoneRepository.java | 4 ++-- .../repository/CustomerRepository.java | 9 ++++++-- .../service/CustomerService.java | 8 +++++++ .../partialupdate/PartialUpdateUnitTest.java | 23 ++++++++++++------- 8 files changed, 44 insertions(+), 31 deletions(-) diff --git a/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/PartialUpdateApplication.java b/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/PartialUpdateApplication.java index 30f5dfa03d..a750fcadf7 100644 --- a/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/PartialUpdateApplication.java +++ b/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/PartialUpdateApplication.java @@ -1,20 +1,12 @@ package com.baeldung.partialupdate; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.cache.CacheManager; -import org.springframework.cache.annotation.EnableCaching; @SpringBootApplication -@EnableCaching public class PartialUpdateApplication { - @Autowired - CacheManager cacheManager; - public static void main(String[] args) { SpringApplication.run(PartialUpdateApplication.class, args); } - } diff --git a/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/model/ContactPhone.java b/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/model/ContactPhone.java index 9d611fa755..352e361bd9 100644 --- a/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/model/ContactPhone.java +++ b/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/model/ContactPhone.java @@ -8,11 +8,11 @@ import javax.persistence.Id; @Entity public class ContactPhone { - @Id + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) public long id; @Column(nullable=false) - public long customerId; + public long customerId; public String phone; @Override diff --git a/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/model/CustomerDto.java b/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/model/CustomerDto.java index 4087838f9a..0ecf206d9a 100644 --- a/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/model/CustomerDto.java +++ b/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/model/CustomerDto.java @@ -6,21 +6,21 @@ public class CustomerDto { public String phone; //... private String phone99; - + public CustomerDto(long id) { - this.id = id; + this.id = id; } - + public CustomerDto(Customer c) { this.id = c.id; this.name = c.name; this.phone = c.phone; } - + public long getId() { - return this.id; + return this.id; } - + public Customer convertToEntity() { Customer c = new Customer(); c.id = id; diff --git a/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/model/CustomerStructured.java b/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/model/CustomerStructured.java index 67b534add2..dd053a963d 100644 --- a/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/model/CustomerStructured.java +++ b/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/model/CustomerStructured.java @@ -16,11 +16,12 @@ public class CustomerStructured { @GeneratedValue(strategy = GenerationType.IDENTITY) public long id; public String name; - @OneToMany(fetch = FetchType.EAGER, targetEntity=ContactPhone.class, mappedBy="customerId") + @OneToMany(fetch = FetchType.EAGER, targetEntity = ContactPhone.class, mappedBy = "customerId") public List contactPhones; - + @Override public String toString() { return String.format("Customer %s, Phone: %s", - this.name, this.contactPhones.stream().map(e -> e.toString()).reduce("", String::concat)); + this.name, this.contactPhones.stream() + .map(e -> e.toString()).reduce("", String::concat)); } } diff --git a/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/repository/ContactPhoneRepository.java b/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/repository/ContactPhoneRepository.java index 2e0b687227..4668181e05 100644 --- a/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/repository/ContactPhoneRepository.java +++ b/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/repository/ContactPhoneRepository.java @@ -7,6 +7,6 @@ import com.baeldung.partialupdate.model.ContactPhone; @Repository public interface ContactPhoneRepository extends CrudRepository { - ContactPhone findById(long id); - ContactPhone findByCustomerId(long id); + ContactPhone findById(long id); + ContactPhone findByCustomerId(long id); } \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/repository/CustomerRepository.java b/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/repository/CustomerRepository.java index bd33c03b6b..43e61df8ab 100644 --- a/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/repository/CustomerRepository.java +++ b/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/repository/CustomerRepository.java @@ -1,13 +1,18 @@ package com.baeldung.partialupdate.repository; -import org.springframework.cache.annotation.Cacheable; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.CrudRepository; +import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import com.baeldung.partialupdate.model.Customer; @Repository public interface CustomerRepository extends CrudRepository { - @Cacheable("customers") Customer findById(long id); + + @Modifying + @Query("update Customer u set u.phone = :phone where u.id = :id") + void updatePhone(@Param(value = "id") long id, @Param(value = "phone") String phone); } \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/service/CustomerService.java b/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/service/CustomerService.java index f3a1c65ef1..9da97a7775 100644 --- a/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/service/CustomerService.java +++ b/persistence-modules/spring-data-jpa-5/src/main/java/com/baeldung/partialupdate/service/CustomerService.java @@ -27,6 +27,14 @@ public class CustomerService { @Autowired CustomerMapper mapper; + public Customer getCustomer(long id) { + return repo.findById(id); + } + + public void updateCustomerWithCustomQuery(long id, String phone) { + repo.updatePhone(id, phone); + } + public Customer addCustomer(String name) { Customer myCustomer = new Customer(); myCustomer.name = name; diff --git a/persistence-modules/spring-data-jpa-5/src/test/java/com/baeldung/partialupdate/PartialUpdateUnitTest.java b/persistence-modules/spring-data-jpa-5/src/test/java/com/baeldung/partialupdate/PartialUpdateUnitTest.java index dc9c8821ac..7eea3a87e9 100644 --- a/persistence-modules/spring-data-jpa-5/src/test/java/com/baeldung/partialupdate/PartialUpdateUnitTest.java +++ b/persistence-modules/spring-data-jpa-5/src/test/java/com/baeldung/partialupdate/PartialUpdateUnitTest.java @@ -25,11 +25,18 @@ public class PartialUpdateUnitTest { public void loadAndSave_whenUpdate_thenSuccess() { Customer myCustomer = service.addCustomer("John"); myCustomer = service.updateCustomer(myCustomer.id, "+00"); - assertEquals("+00", myCustomer.phone); } - @Test + @Test + public void customQuery_whenUpdate_thenSuccess() { + Customer myCustomer = service.addCustomer("John"); + service.updateCustomerWithCustomQuery(myCustomer.id, "+88"); + myCustomer = service.getCustomer(myCustomer.id); + assertEquals("+88", myCustomer.phone); + } + + @Test public void loadAndSaveWithMapper_whenUpdate_thenSuccess() { CustomerDto dto = new CustomerDto(new Customer()); dto.name = "Johnny"; @@ -38,19 +45,19 @@ public class PartialUpdateUnitTest { CustomerDto dto2 = new CustomerDto(entity.id); dto2.phone = "+44"; entity = service.updateCustomer(dto2); - + assertEquals("Johnny", entity.name); } - - @Test - public void loadAndSaveStructuredEntity_whenUpdate_thenSuccess() { + + @Test + public void loadAndSaveStructuredEntity_whenUpdate_thenSuccess() { CustomerStructured myCustomer = service.addCustomerStructured("John"); assertEquals(null, myCustomer.contactPhones); service.addCustomerPhone(myCustomer.id, "+44"); myCustomer = service.updateCustomerStructured(myCustomer.id, "Mr. John"); - + assertNotEquals(null, myCustomer.contactPhones); assertEquals(1, myCustomer.contactPhones.size()); - } + } } From 020aff116095c4a2d5546948ce617d5eeb1f71e6 Mon Sep 17 00:00:00 2001 From: Roque Santos Date: Wed, 27 May 2020 21:32:31 -0300 Subject: [PATCH 042/140] BAEL-3844 : Send request to a proxy using RestTemplate --- .../proxy/RequestFactoryLiveTest.java | 38 +++++++++++++ .../proxy/RestTemplateCustomizerLiveTest.java | 55 +++++++++++++++++++ 2 files changed, 93 insertions(+) create mode 100644 spring-resttemplate/src/test/java/com/baeldung/resttemplate/proxy/RequestFactoryLiveTest.java create mode 100644 spring-resttemplate/src/test/java/com/baeldung/resttemplate/proxy/RestTemplateCustomizerLiveTest.java diff --git a/spring-resttemplate/src/test/java/com/baeldung/resttemplate/proxy/RequestFactoryLiveTest.java b/spring-resttemplate/src/test/java/com/baeldung/resttemplate/proxy/RequestFactoryLiveTest.java new file mode 100644 index 0000000000..f9ca66f14d --- /dev/null +++ b/spring-resttemplate/src/test/java/com/baeldung/resttemplate/proxy/RequestFactoryLiveTest.java @@ -0,0 +1,38 @@ +package com.baeldung.resttemplate.proxy; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +import java.net.InetSocketAddress; +import java.net.Proxy; +import java.net.Proxy.Type; + +import org.junit.Before; +import org.junit.Test; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.http.client.SimpleClientHttpRequestFactory; +import org.springframework.web.client.RestTemplate; + +public class RequestFactoryLiveTest { + + RestTemplate restTemplate; + + @Before + public void setUp() { + Proxy proxy = new Proxy(Type.HTTP, new InetSocketAddress("201.91.82.155", 3128)); + + SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory(); + requestFactory.setProxy(proxy); + + restTemplate = new RestTemplate(requestFactory); + } + + @Test + public void givenRestTemplate_whenRequestedWithProxy_thenResponseBodyIsOk() { + ResponseEntity responseEntity = restTemplate.getForEntity("http://httpbin.org/get", String.class); + + assertThat(responseEntity.getStatusCode(), is(equalTo(HttpStatus.OK))); + } +} diff --git a/spring-resttemplate/src/test/java/com/baeldung/resttemplate/proxy/RestTemplateCustomizerLiveTest.java b/spring-resttemplate/src/test/java/com/baeldung/resttemplate/proxy/RestTemplateCustomizerLiveTest.java new file mode 100644 index 0000000000..8f318b758b --- /dev/null +++ b/spring-resttemplate/src/test/java/com/baeldung/resttemplate/proxy/RestTemplateCustomizerLiveTest.java @@ -0,0 +1,55 @@ +package com.baeldung.resttemplate.proxy; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +import org.apache.http.HttpException; +import org.apache.http.HttpHost; +import org.apache.http.HttpRequest; +import org.apache.http.client.HttpClient; +import org.apache.http.impl.client.HttpClientBuilder; +import org.apache.http.impl.conn.DefaultProxyRoutePlanner; +import org.apache.http.protocol.HttpContext; +import org.junit.Before; +import org.junit.Test; +import org.springframework.boot.web.client.RestTemplateBuilder; +import org.springframework.boot.web.client.RestTemplateCustomizer; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; +import org.springframework.web.client.RestTemplate; + +public class RestTemplateCustomizerLiveTest { + + RestTemplate restTemplate; + + @Before + public void setUp() { + restTemplate = new RestTemplateBuilder(new ProxyCustomizer()).build(); + } + + @Test + public void givenRestTemplate_whenRequestedWithProxy_thenResponseBodyIsOk() { + ResponseEntity responseEntity = restTemplate.getForEntity("http://httpbin.org/get", String.class); + + assertThat(responseEntity.getStatusCode(), is(equalTo(HttpStatus.OK))); + } + + private static class ProxyCustomizer implements RestTemplateCustomizer { + + @Override + public void customize(RestTemplate restTemplate) { + HttpHost proxy = new HttpHost("201.91.82.155", 3128); + HttpClient httpClient = HttpClientBuilder.create() + .setRoutePlanner(new DefaultProxyRoutePlanner(proxy) { + @Override + public HttpHost determineProxy(HttpHost target, HttpRequest request, HttpContext context) throws HttpException { + return super.determineProxy(target, request, context); + } + }) + .build(); + restTemplate.setRequestFactory(new HttpComponentsClientHttpRequestFactory(httpClient)); + } + } +} From 6fb0ebb95c81069a318ff7a017866dcef19d7efa Mon Sep 17 00:00:00 2001 From: Ali Dehghani Date: Thu, 28 May 2020 20:00:23 +0430 Subject: [PATCH 043/140] Dependency Upgrade for HikariCP --- libraries-data-db/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries-data-db/pom.xml b/libraries-data-db/pom.xml index f028ffe8c3..d51580ccbc 100644 --- a/libraries-data-db/pom.xml +++ b/libraries-data-db/pom.xml @@ -211,7 +211,7 @@ 5.0.2 5.0.4 3.2.0-m7 - 2.7.2 + 3.4.5 11.22.4 From 470d047e8dd21a4055e78d079666475075375296 Mon Sep 17 00:00:00 2001 From: Ali Dehghani Date: Fri, 29 May 2020 00:29:27 +0430 Subject: [PATCH 044/140] Introducing Constant Folding & Dead Code Elimination --- jmh/src/main/java/com/baeldung/BenchMark.java | 46 ++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/jmh/src/main/java/com/baeldung/BenchMark.java b/jmh/src/main/java/com/baeldung/BenchMark.java index b0e1caf4dc..55157848ab 100644 --- a/jmh/src/main/java/com/baeldung/BenchMark.java +++ b/jmh/src/main/java/com/baeldung/BenchMark.java @@ -1,14 +1,20 @@ package com.baeldung; -import com.google.common.hash.HashFunction; import com.google.common.hash.Hasher; import com.google.common.hash.Hashing; import org.openjdk.jmh.annotations.*; +import org.openjdk.jmh.infra.Blackhole; import java.nio.charset.Charset; +import java.util.concurrent.TimeUnit; public class BenchMark { + @State(Scope.Benchmark) + public static class Log { + public int x = 8; + } + @State(Scope.Benchmark) public static class ExecutionPlan { @@ -45,4 +51,42 @@ public class BenchMark { // Do nothing } + @Benchmark + @OutputTimeUnit(TimeUnit.NANOSECONDS) + @BenchmarkMode(Mode.AverageTime) + public void doNothing() {} + + @Benchmark + @OutputTimeUnit(TimeUnit.NANOSECONDS) + @BenchmarkMode(Mode.AverageTime) + public void objectCreation() { + new Object(); + } + + @Benchmark + @OutputTimeUnit(TimeUnit.NANOSECONDS) + @BenchmarkMode(Mode.AverageTime) + public Object pillarsOfCreation() { + return new Object(); + } + + @Benchmark + @OutputTimeUnit(TimeUnit.NANOSECONDS) + @BenchmarkMode(Mode.AverageTime) + public void blackHole(Blackhole blackhole) { + blackhole.consume(new Object()); + } + + @Benchmark + public double foldedLog() { + int x = 8; + + return Math.log(x); + } + + @Benchmark + public double log(Log input) { + return Math.log(input.x); + } + } From 1a44c81de42d3d1d9b1b7364f0df7ec33c7d54a5 Mon Sep 17 00:00:00 2001 From: Gergo Petrik Date: Fri, 29 May 2020 16:04:02 +0200 Subject: [PATCH 045/140] using accessors for balance and stamp --- .../com/baeldung/atomicstampedreference/StampedAccount.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/core-java-modules/core-java-concurrency-advanced-3/src/main/java/com/baeldung/atomicstampedreference/StampedAccount.java b/core-java-modules/core-java-concurrency-advanced-3/src/main/java/com/baeldung/atomicstampedreference/StampedAccount.java index 1a46e1ba52..415b24738a 100644 --- a/core-java-modules/core-java-concurrency-advanced-3/src/main/java/com/baeldung/atomicstampedreference/StampedAccount.java +++ b/core-java-modules/core-java-concurrency-advanced-3/src/main/java/com/baeldung/atomicstampedreference/StampedAccount.java @@ -9,13 +9,11 @@ public class StampedAccount { private AtomicStampedReference account = new AtomicStampedReference<>(0, 0); public int getBalance() { - return this.account.get(new int[1]); + return account.getReference(); } public int getStamp() { - int[] stamps = new int[1]; - this.account.get(stamps); - return stamps[0]; + return account.getStamp(); } public boolean deposit(int funds) { From 0986bbcd622c6fd284b674bf85b65223b0c328e9 Mon Sep 17 00:00:00 2001 From: Ali Dehghani Date: Sat, 30 May 2020 09:23:53 +0430 Subject: [PATCH 046/140] On the next line --- jmh/src/main/java/com/baeldung/BenchMark.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/jmh/src/main/java/com/baeldung/BenchMark.java b/jmh/src/main/java/com/baeldung/BenchMark.java index 55157848ab..3c5c840db2 100644 --- a/jmh/src/main/java/com/baeldung/BenchMark.java +++ b/jmh/src/main/java/com/baeldung/BenchMark.java @@ -54,7 +54,9 @@ public class BenchMark { @Benchmark @OutputTimeUnit(TimeUnit.NANOSECONDS) @BenchmarkMode(Mode.AverageTime) - public void doNothing() {} + public void doNothing() { + + } @Benchmark @OutputTimeUnit(TimeUnit.NANOSECONDS) From c5267db45296b59072477ad6d2be51a1911baaf7 Mon Sep 17 00:00:00 2001 From: Ali Dehghani Date: Sat, 30 May 2020 13:05:26 +0430 Subject: [PATCH 047/140] Added Elvis Operator --- .../kotlin/com/baeldung/ternary/TernaryOperatorTest.kt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/core-kotlin-modules/core-kotlin-2/src/test/kotlin/com/baeldung/ternary/TernaryOperatorTest.kt b/core-kotlin-modules/core-kotlin-2/src/test/kotlin/com/baeldung/ternary/TernaryOperatorTest.kt index 21dfdd2ae0..347290de72 100644 --- a/core-kotlin-modules/core-kotlin-2/src/test/kotlin/com/baeldung/ternary/TernaryOperatorTest.kt +++ b/core-kotlin-modules/core-kotlin-2/src/test/kotlin/com/baeldung/ternary/TernaryOperatorTest.kt @@ -21,4 +21,12 @@ class TernaryOperatorTest { } assertEquals("yes", result) } + + @Test + fun `using elvis`() { + val a: String? = null + val result = a ?: "Default" + + assertEquals("Default", result) + } } \ No newline at end of file From 6b3b45923b0843a857391cc5887065e3fb64ce1e Mon Sep 17 00:00:00 2001 From: Ali Dehghani Date: Sat, 30 May 2020 21:58:48 +0430 Subject: [PATCH 048/140] Using Retrieve instead of AwaitExchange --- .../controller/ProductControllerCoroutines.kt | 8 +++----- .../nonblockingcoroutines/handlers/ProductsHandler.kt | 3 +-- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/spring-boot-modules/spring-boot-kotlin/src/main/kotlin/com/baeldung/nonblockingcoroutines/controller/ProductControllerCoroutines.kt b/spring-boot-modules/spring-boot-kotlin/src/main/kotlin/com/baeldung/nonblockingcoroutines/controller/ProductControllerCoroutines.kt index 363090abac..464ed2773a 100644 --- a/spring-boot-modules/spring-boot-kotlin/src/main/kotlin/com/baeldung/nonblockingcoroutines/controller/ProductControllerCoroutines.kt +++ b/spring-boot-modules/spring-boot-kotlin/src/main/kotlin/com/baeldung/nonblockingcoroutines/controller/ProductControllerCoroutines.kt @@ -2,12 +2,11 @@ package com.baeldung.nonblockingcoroutines.controller import com.baeldung.nonblockingcoroutines.model.Product import com.baeldung.nonblockingcoroutines.repository.ProductRepositoryCoroutines +import kotlinx.coroutines.CoroutineStart import kotlinx.coroutines.Deferred import kotlinx.coroutines.FlowPreview -import kotlinx.coroutines.GlobalScope -import kotlinx.coroutines.CoroutineStart -import kotlinx.coroutines.coroutineScope import kotlinx.coroutines.async +import kotlinx.coroutines.coroutineScope import kotlinx.coroutines.flow.Flow import org.springframework.beans.factory.annotation.Autowired import org.springframework.http.MediaType.APPLICATION_JSON @@ -15,7 +14,6 @@ import org.springframework.web.bind.annotation.GetMapping import org.springframework.web.bind.annotation.PathVariable import org.springframework.web.reactive.function.client.WebClient import org.springframework.web.reactive.function.client.awaitBody -import org.springframework.web.reactive.function.client.awaitExchange class ProductControllerCoroutines { @Autowired @@ -38,7 +36,7 @@ class ProductControllerCoroutines { webClient.get() .uri("/stock-service/product/$id/quantity") .accept(APPLICATION_JSON) - .awaitExchange().awaitBody() + .retrieve().awaitBody() } ProductStockView(product.await()!!, quantity.await()) } diff --git a/spring-boot-modules/spring-boot-kotlin/src/main/kotlin/com/baeldung/nonblockingcoroutines/handlers/ProductsHandler.kt b/spring-boot-modules/spring-boot-kotlin/src/main/kotlin/com/baeldung/nonblockingcoroutines/handlers/ProductsHandler.kt index 41c4510e0d..e05b718e64 100644 --- a/spring-boot-modules/spring-boot-kotlin/src/main/kotlin/com/baeldung/nonblockingcoroutines/handlers/ProductsHandler.kt +++ b/spring-boot-modules/spring-boot-kotlin/src/main/kotlin/com/baeldung/nonblockingcoroutines/handlers/ProductsHandler.kt @@ -12,7 +12,6 @@ import org.springframework.http.MediaType import org.springframework.stereotype.Component import org.springframework.web.reactive.function.client.WebClient import org.springframework.web.reactive.function.client.awaitBody -import org.springframework.web.reactive.function.client.awaitExchange import org.springframework.web.reactive.function.server.ServerRequest import org.springframework.web.reactive.function.server.ServerResponse import org.springframework.web.reactive.function.server.bodyAndAwait @@ -37,7 +36,7 @@ class ProductsHandler( webClient.get() .uri("/stock-service/product/$id/quantity") .accept(MediaType.APPLICATION_JSON) - .awaitExchange().awaitBody() + .retrieve().awaitBody() } return ServerResponse.ok().json().bodyAndAwait(ProductStockView(product.await()!!, quantity.await())) } From 75a44b99652b87b3c3c7781a50dd8b6767e24ce7 Mon Sep 17 00:00:00 2001 From: Chirag Dewan Date: Sun, 31 May 2020 18:39:20 +0530 Subject: [PATCH 049/140] BAEL3889 - Kafka Mock Producer --- libraries-data-2/pom.xml | 7 +++++++ .../main/java/com/baeldung/kafka/EvenOddPartitioner.java | 0 .../src/main/java/com/baeldung/kafka/KafkaProducer.java | 0 .../java/com/baeldung/kafka/KafkaProducerUnitTest.java | 0 4 files changed, 7 insertions(+) rename {libraries-6 => libraries-data-2}/src/main/java/com/baeldung/kafka/EvenOddPartitioner.java (100%) rename {libraries-6 => libraries-data-2}/src/main/java/com/baeldung/kafka/KafkaProducer.java (100%) rename {libraries-6 => libraries-data-2}/src/test/java/com/baeldung/kafka/KafkaProducerUnitTest.java (100%) diff --git a/libraries-data-2/pom.xml b/libraries-data-2/pom.xml index bdfb2c5ed6..2d27ec2107 100644 --- a/libraries-data-2/pom.xml +++ b/libraries-data-2/pom.xml @@ -153,6 +153,13 @@ renjin-script-engine ${renjin.version} + + org.apache.kafka + kafka-clients + ${kafka.version} + test + test + diff --git a/libraries-6/src/main/java/com/baeldung/kafka/EvenOddPartitioner.java b/libraries-data-2/src/main/java/com/baeldung/kafka/EvenOddPartitioner.java similarity index 100% rename from libraries-6/src/main/java/com/baeldung/kafka/EvenOddPartitioner.java rename to libraries-data-2/src/main/java/com/baeldung/kafka/EvenOddPartitioner.java diff --git a/libraries-6/src/main/java/com/baeldung/kafka/KafkaProducer.java b/libraries-data-2/src/main/java/com/baeldung/kafka/KafkaProducer.java similarity index 100% rename from libraries-6/src/main/java/com/baeldung/kafka/KafkaProducer.java rename to libraries-data-2/src/main/java/com/baeldung/kafka/KafkaProducer.java diff --git a/libraries-6/src/test/java/com/baeldung/kafka/KafkaProducerUnitTest.java b/libraries-data-2/src/test/java/com/baeldung/kafka/KafkaProducerUnitTest.java similarity index 100% rename from libraries-6/src/test/java/com/baeldung/kafka/KafkaProducerUnitTest.java rename to libraries-data-2/src/test/java/com/baeldung/kafka/KafkaProducerUnitTest.java From e245b2eca3347f02e0ab45011ffc8b1c880f01f3 Mon Sep 17 00:00:00 2001 From: Chirag Dewan Date: Sun, 31 May 2020 18:59:54 +0530 Subject: [PATCH 050/140] BAEL3889 - Changing the package structure --- .../com/baeldung/kafka/{ => producer}/EvenOddPartitioner.java | 0 .../java/com/baeldung/kafka/{ => producer}/KafkaProducer.java | 0 .../com/baeldung/kafka/{ => producer}/KafkaProducerUnitTest.java | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename libraries-data-2/src/main/java/com/baeldung/kafka/{ => producer}/EvenOddPartitioner.java (100%) rename libraries-data-2/src/main/java/com/baeldung/kafka/{ => producer}/KafkaProducer.java (100%) rename libraries-data-2/src/test/java/com/baeldung/kafka/{ => producer}/KafkaProducerUnitTest.java (100%) diff --git a/libraries-data-2/src/main/java/com/baeldung/kafka/EvenOddPartitioner.java b/libraries-data-2/src/main/java/com/baeldung/kafka/producer/EvenOddPartitioner.java similarity index 100% rename from libraries-data-2/src/main/java/com/baeldung/kafka/EvenOddPartitioner.java rename to libraries-data-2/src/main/java/com/baeldung/kafka/producer/EvenOddPartitioner.java diff --git a/libraries-data-2/src/main/java/com/baeldung/kafka/KafkaProducer.java b/libraries-data-2/src/main/java/com/baeldung/kafka/producer/KafkaProducer.java similarity index 100% rename from libraries-data-2/src/main/java/com/baeldung/kafka/KafkaProducer.java rename to libraries-data-2/src/main/java/com/baeldung/kafka/producer/KafkaProducer.java diff --git a/libraries-data-2/src/test/java/com/baeldung/kafka/KafkaProducerUnitTest.java b/libraries-data-2/src/test/java/com/baeldung/kafka/producer/KafkaProducerUnitTest.java similarity index 100% rename from libraries-data-2/src/test/java/com/baeldung/kafka/KafkaProducerUnitTest.java rename to libraries-data-2/src/test/java/com/baeldung/kafka/producer/KafkaProducerUnitTest.java From 5a2bf2d09ff11800802ff6bbcdb762c4daf6a1e3 Mon Sep 17 00:00:00 2001 From: Mark Thomas Date: Sun, 31 May 2020 11:46:32 -0500 Subject: [PATCH 051/140] BAEL-3768 - spatialguru.net@gmail.com (#9402) * Add implementation of BeanPostProcessor and BeanFactoryPostProcessor for ticket * Continue processing beans if annotation not found on one or more * Add integration test * Simplify code * Rename package --- .../{postprocessor => beanpostprocessor}/GlobalEventBus.java | 2 +- .../GuavaEventBusBeanFactoryPostProcessor.java | 2 +- .../GuavaEventBusBeanPostProcessor.java | 2 +- .../{postprocessor => beanpostprocessor}/StockTrade.java | 2 +- .../StockTradeListener.java | 2 +- .../StockTradePublisher.java | 2 +- .../{postprocessor => beanpostprocessor}/Subscriber.java | 2 +- .../PostProcessorConfiguration.java | 2 +- .../StockTradeIntegrationTest.java | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) rename spring-core-4/src/main/java/com/baeldung/{postprocessor => beanpostprocessor}/GlobalEventBus.java (96%) rename spring-core-4/src/main/java/com/baeldung/{postprocessor => beanpostprocessor}/GuavaEventBusBeanFactoryPostProcessor.java (98%) rename spring-core-4/src/main/java/com/baeldung/{postprocessor => beanpostprocessor}/GuavaEventBusBeanPostProcessor.java (98%) rename spring-core-4/src/main/java/com/baeldung/{postprocessor => beanpostprocessor}/StockTrade.java (94%) rename spring-core-4/src/main/java/com/baeldung/{postprocessor => beanpostprocessor}/StockTradeListener.java (73%) rename spring-core-4/src/main/java/com/baeldung/{postprocessor => beanpostprocessor}/StockTradePublisher.java (96%) rename spring-core-4/src/main/java/com/baeldung/{postprocessor => beanpostprocessor}/Subscriber.java (93%) rename spring-core-4/src/test/java/com/baeldung/{postprocessor => beanpostprocessor}/PostProcessorConfiguration.java (92%) rename spring-core-4/src/test/java/com/baeldung/{postprocessor => beanpostprocessor}/StockTradeIntegrationTest.java (97%) diff --git a/spring-core-4/src/main/java/com/baeldung/postprocessor/GlobalEventBus.java b/spring-core-4/src/main/java/com/baeldung/beanpostprocessor/GlobalEventBus.java similarity index 96% rename from spring-core-4/src/main/java/com/baeldung/postprocessor/GlobalEventBus.java rename to spring-core-4/src/main/java/com/baeldung/beanpostprocessor/GlobalEventBus.java index 8b95ea7c6f..8b3c528c4d 100644 --- a/spring-core-4/src/main/java/com/baeldung/postprocessor/GlobalEventBus.java +++ b/spring-core-4/src/main/java/com/baeldung/beanpostprocessor/GlobalEventBus.java @@ -1,4 +1,4 @@ -package com.baeldung.postprocessor; +package com.baeldung.beanpostprocessor; import com.google.common.eventbus.AsyncEventBus; import com.google.common.eventbus.EventBus; diff --git a/spring-core-4/src/main/java/com/baeldung/postprocessor/GuavaEventBusBeanFactoryPostProcessor.java b/spring-core-4/src/main/java/com/baeldung/beanpostprocessor/GuavaEventBusBeanFactoryPostProcessor.java similarity index 98% rename from spring-core-4/src/main/java/com/baeldung/postprocessor/GuavaEventBusBeanFactoryPostProcessor.java rename to spring-core-4/src/main/java/com/baeldung/beanpostprocessor/GuavaEventBusBeanFactoryPostProcessor.java index fba31fde6a..e0108655cf 100644 --- a/spring-core-4/src/main/java/com/baeldung/postprocessor/GuavaEventBusBeanFactoryPostProcessor.java +++ b/spring-core-4/src/main/java/com/baeldung/beanpostprocessor/GuavaEventBusBeanFactoryPostProcessor.java @@ -1,4 +1,4 @@ -package com.baeldung.postprocessor; +package com.baeldung.beanpostprocessor; import com.google.common.eventbus.EventBus; diff --git a/spring-core-4/src/main/java/com/baeldung/postprocessor/GuavaEventBusBeanPostProcessor.java b/spring-core-4/src/main/java/com/baeldung/beanpostprocessor/GuavaEventBusBeanPostProcessor.java similarity index 98% rename from spring-core-4/src/main/java/com/baeldung/postprocessor/GuavaEventBusBeanPostProcessor.java rename to spring-core-4/src/main/java/com/baeldung/beanpostprocessor/GuavaEventBusBeanPostProcessor.java index 677c839444..be3800c40a 100644 --- a/spring-core-4/src/main/java/com/baeldung/postprocessor/GuavaEventBusBeanPostProcessor.java +++ b/spring-core-4/src/main/java/com/baeldung/beanpostprocessor/GuavaEventBusBeanPostProcessor.java @@ -1,4 +1,4 @@ -package com.baeldung.postprocessor; +package com.baeldung.beanpostprocessor; import com.google.common.eventbus.EventBus; diff --git a/spring-core-4/src/main/java/com/baeldung/postprocessor/StockTrade.java b/spring-core-4/src/main/java/com/baeldung/beanpostprocessor/StockTrade.java similarity index 94% rename from spring-core-4/src/main/java/com/baeldung/postprocessor/StockTrade.java rename to spring-core-4/src/main/java/com/baeldung/beanpostprocessor/StockTrade.java index 7711cf7101..f27f9e7c9b 100644 --- a/spring-core-4/src/main/java/com/baeldung/postprocessor/StockTrade.java +++ b/spring-core-4/src/main/java/com/baeldung/beanpostprocessor/StockTrade.java @@ -1,4 +1,4 @@ -package com.baeldung.postprocessor; +package com.baeldung.beanpostprocessor; import java.util.Date; diff --git a/spring-core-4/src/main/java/com/baeldung/postprocessor/StockTradeListener.java b/spring-core-4/src/main/java/com/baeldung/beanpostprocessor/StockTradeListener.java similarity index 73% rename from spring-core-4/src/main/java/com/baeldung/postprocessor/StockTradeListener.java rename to spring-core-4/src/main/java/com/baeldung/beanpostprocessor/StockTradeListener.java index bf34d66f24..a0ee293293 100644 --- a/spring-core-4/src/main/java/com/baeldung/postprocessor/StockTradeListener.java +++ b/spring-core-4/src/main/java/com/baeldung/beanpostprocessor/StockTradeListener.java @@ -1,4 +1,4 @@ -package com.baeldung.postprocessor; +package com.baeldung.beanpostprocessor; @FunctionalInterface public interface StockTradeListener { diff --git a/spring-core-4/src/main/java/com/baeldung/postprocessor/StockTradePublisher.java b/spring-core-4/src/main/java/com/baeldung/beanpostprocessor/StockTradePublisher.java similarity index 96% rename from spring-core-4/src/main/java/com/baeldung/postprocessor/StockTradePublisher.java rename to spring-core-4/src/main/java/com/baeldung/beanpostprocessor/StockTradePublisher.java index bf339872d9..0058944b53 100644 --- a/spring-core-4/src/main/java/com/baeldung/postprocessor/StockTradePublisher.java +++ b/spring-core-4/src/main/java/com/baeldung/beanpostprocessor/StockTradePublisher.java @@ -1,4 +1,4 @@ -package com.baeldung.postprocessor; +package com.baeldung.beanpostprocessor; import com.google.common.eventbus.AllowConcurrentEvents; import com.google.common.eventbus.Subscribe; diff --git a/spring-core-4/src/main/java/com/baeldung/postprocessor/Subscriber.java b/spring-core-4/src/main/java/com/baeldung/beanpostprocessor/Subscriber.java similarity index 93% rename from spring-core-4/src/main/java/com/baeldung/postprocessor/Subscriber.java rename to spring-core-4/src/main/java/com/baeldung/beanpostprocessor/Subscriber.java index bef38333d6..1aca507555 100644 --- a/spring-core-4/src/main/java/com/baeldung/postprocessor/Subscriber.java +++ b/spring-core-4/src/main/java/com/baeldung/beanpostprocessor/Subscriber.java @@ -1,4 +1,4 @@ -package com.baeldung.postprocessor; +package com.baeldung.beanpostprocessor; import java.lang.annotation.ElementType; import java.lang.annotation.Inherited; diff --git a/spring-core-4/src/test/java/com/baeldung/postprocessor/PostProcessorConfiguration.java b/spring-core-4/src/test/java/com/baeldung/beanpostprocessor/PostProcessorConfiguration.java similarity index 92% rename from spring-core-4/src/test/java/com/baeldung/postprocessor/PostProcessorConfiguration.java rename to spring-core-4/src/test/java/com/baeldung/beanpostprocessor/PostProcessorConfiguration.java index b28e36663a..842283f563 100644 --- a/spring-core-4/src/test/java/com/baeldung/postprocessor/PostProcessorConfiguration.java +++ b/spring-core-4/src/test/java/com/baeldung/beanpostprocessor/PostProcessorConfiguration.java @@ -1,4 +1,4 @@ -package com.baeldung.postprocessor; +package com.baeldung.beanpostprocessor; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; diff --git a/spring-core-4/src/test/java/com/baeldung/postprocessor/StockTradeIntegrationTest.java b/spring-core-4/src/test/java/com/baeldung/beanpostprocessor/StockTradeIntegrationTest.java similarity index 97% rename from spring-core-4/src/test/java/com/baeldung/postprocessor/StockTradeIntegrationTest.java rename to spring-core-4/src/test/java/com/baeldung/beanpostprocessor/StockTradeIntegrationTest.java index ae3cd968dc..74d6765ecd 100644 --- a/spring-core-4/src/test/java/com/baeldung/postprocessor/StockTradeIntegrationTest.java +++ b/spring-core-4/src/test/java/com/baeldung/beanpostprocessor/StockTradeIntegrationTest.java @@ -1,4 +1,4 @@ -package com.baeldung.postprocessor; +package com.baeldung.beanpostprocessor; import java.time.Duration; import java.util.Date; From 5e0be5450473949a78b2d4b110f30d44124698aa Mon Sep 17 00:00:00 2001 From: "alex.peptan" Date: Sun, 31 May 2020 21:55:46 +0300 Subject: [PATCH 052/140] BAEL-3896: OpenAPI JSON Objects in Query Params - swagger definitions files changed to yaml --- .../{openapi-2.json => openapi-2.yaml} | 0 .../{openapi-3.json => openapi-3.yaml} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename spring-rest-http/src/main/resources/openapi-queryparam-definitions/{openapi-2.json => openapi-2.yaml} (100%) rename spring-rest-http/src/main/resources/openapi-queryparam-definitions/{openapi-3.json => openapi-3.yaml} (100%) diff --git a/spring-rest-http/src/main/resources/openapi-queryparam-definitions/openapi-2.json b/spring-rest-http/src/main/resources/openapi-queryparam-definitions/openapi-2.yaml similarity index 100% rename from spring-rest-http/src/main/resources/openapi-queryparam-definitions/openapi-2.json rename to spring-rest-http/src/main/resources/openapi-queryparam-definitions/openapi-2.yaml diff --git a/spring-rest-http/src/main/resources/openapi-queryparam-definitions/openapi-3.json b/spring-rest-http/src/main/resources/openapi-queryparam-definitions/openapi-3.yaml similarity index 100% rename from spring-rest-http/src/main/resources/openapi-queryparam-definitions/openapi-3.json rename to spring-rest-http/src/main/resources/openapi-queryparam-definitions/openapi-3.yaml From 00b67725ea441900eb1810d7e1717c3a45f3762b Mon Sep 17 00:00:00 2001 From: dupirefr Date: Sat, 30 May 2020 17:27:37 +0200 Subject: [PATCH 053/140] [JAVA-1659] Upgraded Maven Surefire Plugin and JUnit versions * Upgraded Maven Surefire Plugin version to 2.22.2 * Upgraded JUnit version to 5.6.2 * Imported JUnit BOM before Spring Boot Dependencies BOM (as explained [here](https://docs.spring.io/spring-boot/docs/2.3.0.RELEASE/maven-plugin/reference/html/#using)) --- ddd/pom.xml | 54 +++++++++++++++++++++++++++++++++-------------------- 1 file changed, 34 insertions(+), 20 deletions(-) diff --git a/ddd/pom.xml b/ddd/pom.xml index 1253f2ac48..422f9ccd15 100644 --- a/ddd/pom.xml +++ b/ddd/pom.xml @@ -17,6 +17,35 @@ ../parent-boot-2 + + + + org.apache.maven.plugins + maven-surefire-plugin + ${maven-surefire-plugin.version} + + + + + + + + org.junit + junit-bom + ${junit-jupiter.version} + pom + import + + + org.springframework.boot + spring-boot-dependencies + ${spring-boot.version} + pom + import + + + + org.springframework.boot @@ -26,24 +55,6 @@ org.springframework.boot spring-boot-starter-data-cassandra - - org.junit.jupiter - junit-jupiter-api - test - - - org.junit.jupiter - junit-jupiter-engine - test - - - - - org.junit.platform - junit-platform-launcher - ${junit-platform.version} - test - org.joda joda-money @@ -95,7 +106,10 @@ - 1.0.1 - + 2.22.2 + 1.0.1 + + 5.6.2 + From 8477fd927913b5fceabdba4e367e54def66c4fae Mon Sep 17 00:00:00 2001 From: Michele Guarnaccia Date: Mon, 1 Jun 2020 11:09:35 +0200 Subject: [PATCH 054/140] Renamed test methods --- .../com/baeldung/partialupdate/PartialUpdateUnitTest.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/persistence-modules/spring-data-jpa-5/src/test/java/com/baeldung/partialupdate/PartialUpdateUnitTest.java b/persistence-modules/spring-data-jpa-5/src/test/java/com/baeldung/partialupdate/PartialUpdateUnitTest.java index 7eea3a87e9..874e18c4ad 100644 --- a/persistence-modules/spring-data-jpa-5/src/test/java/com/baeldung/partialupdate/PartialUpdateUnitTest.java +++ b/persistence-modules/spring-data-jpa-5/src/test/java/com/baeldung/partialupdate/PartialUpdateUnitTest.java @@ -22,14 +22,14 @@ public class PartialUpdateUnitTest { CustomerService service; @Test - public void loadAndSave_whenUpdate_thenSuccess() { + public void givenCustomer_whenUpdate_thenSuccess() { Customer myCustomer = service.addCustomer("John"); myCustomer = service.updateCustomer(myCustomer.id, "+00"); assertEquals("+00", myCustomer.phone); } @Test - public void customQuery_whenUpdate_thenSuccess() { + public void givenCustomer_whenUpdateWithQuery_thenSuccess() { Customer myCustomer = service.addCustomer("John"); service.updateCustomerWithCustomQuery(myCustomer.id, "+88"); myCustomer = service.getCustomer(myCustomer.id); @@ -37,7 +37,7 @@ public class PartialUpdateUnitTest { } @Test - public void loadAndSaveWithMapper_whenUpdate_thenSuccess() { + public void givenCustomerDto_whenUpdateWithMapper_thenSuccess() { CustomerDto dto = new CustomerDto(new Customer()); dto.name = "Johnny"; Customer entity = service.addCustomer(dto); @@ -50,7 +50,7 @@ public class PartialUpdateUnitTest { } @Test - public void loadAndSaveStructuredEntity_whenUpdate_thenSuccess() { + public void givenCustomerStructured_whenUpdateCustomerPhone_thenSuccess() { CustomerStructured myCustomer = service.addCustomerStructured("John"); assertEquals(null, myCustomer.contactPhones); From 3086da7d127b92c19b51d9a829c08055bccefd54 Mon Sep 17 00:00:00 2001 From: dupirefr Date: Mon, 1 Jun 2020 11:11:12 +0200 Subject: [PATCH 055/140] [JAVA-1659] Upgraded Maven Surefire Plugin and JUnit versions * Fixed sub-modules parent poms names * Added relative paths to sub-modules poms * Configured Maven Surefire Plugin so that it works with the dummy test * Upgraded Maven Surefire Plugin version to 2.22.2 * Upgraded JUnit version to 5.6.2 --- ddd-modules/infrastructure/pom.xml | 3 ++- ddd-modules/mainapp/pom.xml | 3 ++- ddd-modules/ordercontext/pom.xml | 3 ++- ddd-modules/pom.xml | 34 ++++++++++++++++++++++++----- ddd-modules/sharedkernel/pom.xml | 3 ++- ddd-modules/shippingcontext/pom.xml | 3 ++- 6 files changed, 38 insertions(+), 11 deletions(-) diff --git a/ddd-modules/infrastructure/pom.xml b/ddd-modules/infrastructure/pom.xml index c301eaa92a..abf90935c3 100644 --- a/ddd-modules/infrastructure/pom.xml +++ b/ddd-modules/infrastructure/pom.xml @@ -12,8 +12,9 @@ com.baeldung.dddmodules - dddmodules + ddd-modules 1.0 + ../ diff --git a/ddd-modules/mainapp/pom.xml b/ddd-modules/mainapp/pom.xml index a048263d37..59d2ad7d3a 100644 --- a/ddd-modules/mainapp/pom.xml +++ b/ddd-modules/mainapp/pom.xml @@ -11,8 +11,9 @@ com.baeldung.dddmodules - dddmodules + ddd-modules 1.0 + ../ diff --git a/ddd-modules/ordercontext/pom.xml b/ddd-modules/ordercontext/pom.xml index abd166fb69..8dee3a5148 100644 --- a/ddd-modules/ordercontext/pom.xml +++ b/ddd-modules/ordercontext/pom.xml @@ -11,8 +11,9 @@ com.baeldung.dddmodules - dddmodules + ddd-modules 1.0 + ../ diff --git a/ddd-modules/pom.xml b/ddd-modules/pom.xml index c6dd6e1f25..6ab1829198 100644 --- a/ddd-modules/pom.xml +++ b/ddd-modules/pom.xml @@ -28,9 +28,15 @@ - junit - junit - ${junit.version} + org.junit.jupiter + junit-jupiter + ${junit-jupiter.version} + test + + + org.junit.vintage + junit-vintage-engine + ${junit-jupiter.version} test @@ -56,15 +62,31 @@ + + + org.apache.maven.plugins + maven-surefire-plugin + ${maven-surefire-plugin.version} + + 0 + + + - 3.8.1 + UTF-8 + 9 9 - UTF-8 - 3.12.2 + + 3.8.1 + 2.22.2 + 1.0 + + 5.6.2 + 3.12.2 diff --git a/ddd-modules/sharedkernel/pom.xml b/ddd-modules/sharedkernel/pom.xml index a61f03a494..1afddf1e22 100644 --- a/ddd-modules/sharedkernel/pom.xml +++ b/ddd-modules/sharedkernel/pom.xml @@ -11,8 +11,9 @@ com.baeldung.dddmodules - dddmodules + ddd-modules 1.0 + ../ diff --git a/ddd-modules/shippingcontext/pom.xml b/ddd-modules/shippingcontext/pom.xml index 2096923f90..25b5882ef1 100644 --- a/ddd-modules/shippingcontext/pom.xml +++ b/ddd-modules/shippingcontext/pom.xml @@ -11,8 +11,9 @@ com.baeldung.dddmodules - dddmodules + ddd-modules 1.0 + ../ From ec34dde27b22dec40854966c9ca8550e3157f35e Mon Sep 17 00:00:00 2001 From: Juan Moreno Date: Mon, 1 Jun 2020 09:06:57 -0300 Subject: [PATCH 056/140] FIX Package Name --- .../reactive}/ReactiveStreamsUnitTest.java | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename core-java-modules/core-java-9-new-features/src/test/java/com/baeldung/java9/{streams.reactive => streams/reactive}/ReactiveStreamsUnitTest.java (100%) diff --git a/core-java-modules/core-java-9-new-features/src/test/java/com/baeldung/java9/streams.reactive/ReactiveStreamsUnitTest.java b/core-java-modules/core-java-9-new-features/src/test/java/com/baeldung/java9/streams/reactive/ReactiveStreamsUnitTest.java similarity index 100% rename from core-java-modules/core-java-9-new-features/src/test/java/com/baeldung/java9/streams.reactive/ReactiveStreamsUnitTest.java rename to core-java-modules/core-java-9-new-features/src/test/java/com/baeldung/java9/streams/reactive/ReactiveStreamsUnitTest.java From ef13de20619da164951d49ae04f1f555188b584e Mon Sep 17 00:00:00 2001 From: Josh Cummings Date: Mon, 1 Jun 2020 09:38:52 -0600 Subject: [PATCH 057/140] Update README.md Issue BAEL-3067 --- core-java-modules/core-java-io-conversions-2/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-modules/core-java-io-conversions-2/README.md b/core-java-modules/core-java-io-conversions-2/README.md index 5cb9c21c54..9ce36e7437 100644 --- a/core-java-modules/core-java-io-conversions-2/README.md +++ b/core-java-modules/core-java-io-conversions-2/README.md @@ -5,4 +5,5 @@ This module contains articles about core Java input/output(IO) conversions. ### Relevant Articles: - [Java InputStream to String](https://www.baeldung.com/convert-input-stream-to-string) - [Java – Write an InputStream to a File](https://www.baeldung.com/convert-input-stream-to-a-file) +- [Converting a BufferedReader to a JSONObject](https://www.baeldung.com/java-bufferedreader-to-jsonobject) - More articles: [[<-- prev]](/core-java-modules/core-java-io-conversions) From 1627873f8810b14fe4ef772ae8e3f49478956c23 Mon Sep 17 00:00:00 2001 From: Josh Cummings Date: Mon, 1 Jun 2020 09:41:50 -0600 Subject: [PATCH 058/140] Update README.md Issue BAEL-3494 --- core-java-modules/core-java-9-new-features/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-modules/core-java-9-new-features/README.md b/core-java-modules/core-java-9-new-features/README.md index d547b9a221..c2ef63a530 100644 --- a/core-java-modules/core-java-9-new-features/README.md +++ b/core-java-modules/core-java-9-new-features/README.md @@ -12,3 +12,4 @@ This module contains articles about core Java features that have been introduced - [Introduction to Java 9 StackWalking API](https://www.baeldung.com/java-9-stackwalking-api) - [Java 9 Platform Logging API](https://www.baeldung.com/java-9-logging-api) - [Java 9 Reactive Streams](https://www.baeldung.com/java-9-reactive-streams) +- [Multi-Release JAR Files with Maven](https://www.baeldung.com/maven-multi-release-jars) From 5b68d315b86a415178a6de8fcaac47ac0166bd3a Mon Sep 17 00:00:00 2001 From: Ankur Gupta Date: Mon, 1 Jun 2020 22:29:02 +0530 Subject: [PATCH 059/140] Updating Test Class name for multiplecachemanager module (#9399) * Java Example of Hexagonal Architecture * removing unnecessary maven files from pull request and spaces in code * Removing unnecessary lines * Example code for using Multiple Cache Manager in SpringBoot * BAEL-3963:Using multiple cache managers in Spring * removing new module created in last pull request * Fixes as per editor Suggestions * fixing spacing issue in pom.xml * Fixing spacing issue in pom.xml * Fixing spacing issue 2 * Formatting space issues in pom.xml * Changing the Test class name from IntegrationUnitTest to IntegrationTest Co-authored-by: Ankur Gupta --- ...onUnitTest.java => MultipleCacheManagerIntegrationTest.java} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename spring-caching/src/test/java/com/baeldung/multiplecachemanager/{MultipleCacheManagerIntegrationUnitTest.java => MultipleCacheManagerIntegrationTest.java} (97%) diff --git a/spring-caching/src/test/java/com/baeldung/multiplecachemanager/MultipleCacheManagerIntegrationUnitTest.java b/spring-caching/src/test/java/com/baeldung/multiplecachemanager/MultipleCacheManagerIntegrationTest.java similarity index 97% rename from spring-caching/src/test/java/com/baeldung/multiplecachemanager/MultipleCacheManagerIntegrationUnitTest.java rename to spring-caching/src/test/java/com/baeldung/multiplecachemanager/MultipleCacheManagerIntegrationTest.java index e02e5da246..c83d4f9e96 100644 --- a/spring-caching/src/test/java/com/baeldung/multiplecachemanager/MultipleCacheManagerIntegrationUnitTest.java +++ b/spring-caching/src/test/java/com/baeldung/multiplecachemanager/MultipleCacheManagerIntegrationTest.java @@ -17,7 +17,7 @@ import com.baeldung.multiplecachemanager.repository.OrderDetailRepository; @SpringBootApplication @SpringBootTest -public class MultipleCacheManagerIntegrationUnitTest { +public class MultipleCacheManagerIntegrationTest { @MockBean private OrderDetailRepository orderDetailRepository; From 88a899a283a15b022ba93915ff95e6c8d660e682 Mon Sep 17 00:00:00 2001 From: Cristian Rosu Date: Mon, 1 Jun 2020 23:32:38 +0300 Subject: [PATCH 060/140] BAEL-4070: Injecting List or Arrays from a Spring properties file --- .../lists/ListsPropertiesIntegrationTest.java | 88 +++++++++++++++++++ .../SpringListPropertiesApplication.java | 10 +++ .../src/test/resources/lists.properties | 6 ++ 3 files changed, 104 insertions(+) create mode 100644 spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/lists/ListsPropertiesIntegrationTest.java create mode 100644 spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/lists/SpringListPropertiesApplication.java create mode 100644 spring-boot-modules/spring-boot-properties/src/test/resources/lists.properties diff --git a/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/lists/ListsPropertiesIntegrationTest.java b/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/lists/ListsPropertiesIntegrationTest.java new file mode 100644 index 0000000000..4047e1ea95 --- /dev/null +++ b/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/lists/ListsPropertiesIntegrationTest.java @@ -0,0 +1,88 @@ +package com.baeldung.properties.lists; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.core.env.Environment; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import static org.junit.Assert.assertEquals; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(classes = {SpringListPropertiesApplication.class}) +public class ListsPropertiesIntegrationTest { + + @Value("${arrayOfStrings}") + private String[] arrayOfStrings; + + @Value("${arrayOfStrings}") + private List unexpectedListOfStrings; + + @Value("#{'${arrayOfStrings}'.split(',')}") + private List listOfStrings; + + @Value("#{${listOfStrings}}") + private List listOfStringsV2; + + @Value("#{'${listOfStringsWithCustomDelimiter}'.split(';')}") + private List listOfStringsWithCustomDelimiter; + + @Value("#{'${listOfBooleans}'.split(',')}") + private List listOfBooleans; + + @Value("#{'${listOfIntegers}'.split(',')}") + private List listOfIntegers; + + @Value("#{'${listOfCharacters}'.split(',')}") + private List listOfCharacters; + + @Autowired + private Environment environment; + + @Test + public void givenContextIsInitialized_ThenInjectedArrayContainsExpectedValues() { + assertEquals(arrayOfStrings, new String[] {"Baeldung", "dot", "com"}); + } + + @Test + public void givenContextIsInitialized_ThenInjectedListContainsUnexpectedValues() { + assertEquals(unexpectedListOfStrings, Collections.singletonList("Baeldung,dot,com")); + } + + @Test + public void givenContextIsInitialized_ThenInjectedListContainsExpectedValues() { + assertEquals(listOfStrings, Arrays.asList("Baeldung", "dot", "com")); + } + + @Test + public void givenContextIsInitialized_ThenInjectedListV2ContainsExpectedValues() { + assertEquals(listOfStringsV2, Arrays.asList("Baeldung", "dot", "com")); + } + + @Test + public void givenContextIsInitialized_ThenInjectedListWithCustomDelimiterContainsExpectedValues() { + assertEquals(listOfStringsWithCustomDelimiter, Arrays.asList("Baeldung", "dot", "com")); + } + + @Test + public void givenContextIsInitialized_ThenInjectedListOfBasicTypesContainsExpectedValues() { + assertEquals(listOfBooleans, Arrays.asList(false, false, true)); + assertEquals(listOfIntegers, Arrays.asList(1, 2, 3, 4)); + assertEquals(listOfCharacters, Arrays.asList('a', 'b', 'c')); + } + + @Test + public void givenContextIsInitialized_WhenReadingFromEnvironment_ThenPropertiesHaveExpectedValues() { + String[] arrayOfStrings = environment.getProperty("arrayOfStrings", String[].class); + List listOfStrings = (List)environment.getProperty("arrayOfStrings", List.class); + + assertEquals(arrayOfStrings, new String[] {"Baeldung", "dot", "com"}); + assertEquals(listOfStrings, Arrays.asList("Baeldung", "dot", "com")); + } +} diff --git a/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/lists/SpringListPropertiesApplication.java b/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/lists/SpringListPropertiesApplication.java new file mode 100644 index 0000000000..8a66079201 --- /dev/null +++ b/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/lists/SpringListPropertiesApplication.java @@ -0,0 +1,10 @@ +package com.baeldung.properties.lists; + +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.PropertySource; + +@Configuration +@PropertySource(value = "lists.properties") +public class SpringListPropertiesApplication { + +} diff --git a/spring-boot-modules/spring-boot-properties/src/test/resources/lists.properties b/spring-boot-modules/spring-boot-properties/src/test/resources/lists.properties new file mode 100644 index 0000000000..cc54d699a7 --- /dev/null +++ b/spring-boot-modules/spring-boot-properties/src/test/resources/lists.properties @@ -0,0 +1,6 @@ +arrayOfStrings=Baeldung,dot,com +listOfStrings={'Baeldung','dot','com'} +listOfStringsWithCustomDelimiter=Baeldung;dot;com +listOfBooleans=false,false,true +listOfIntegers=1,2,3,4 +listOfCharacters=a,b,c \ No newline at end of file From 6d1ecdd735456d58c32fb67b5d0a88454c4fc616 Mon Sep 17 00:00:00 2001 From: Anshul BANSAL Date: Tue, 2 Jun 2020 10:07:54 +0300 Subject: [PATCH 061/140] BAEL-4049 - view bytecode of a class file in java --- core-java-modules/core-java-jvm/pom.xml | 25 ++++++++ .../bytecode/ViewBytecodeUnitTest.java | 58 +++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 core-java-modules/core-java-jvm/src/test/java/com/baeldung/bytecode/ViewBytecodeUnitTest.java diff --git a/core-java-modules/core-java-jvm/pom.xml b/core-java-modules/core-java-jvm/pom.xml index f3e5470a61..f35efaa26b 100644 --- a/core-java-modules/core-java-jvm/pom.xml +++ b/core-java-modules/core-java-jvm/pom.xml @@ -51,6 +51,31 @@ system ${java.home}/../lib/tools.jar + + org.ow2.asm + asm + 8.0.1 + + + org.ow2.asm + asm-util + 8.0.1 + + + org.apache.bcel + bcel + 6.4.1 + + + cglib + cglib + 3.3.0 + + + org.javassist + javassist + 3.27.0-GA + diff --git a/core-java-modules/core-java-jvm/src/test/java/com/baeldung/bytecode/ViewBytecodeUnitTest.java b/core-java-modules/core-java-jvm/src/test/java/com/baeldung/bytecode/ViewBytecodeUnitTest.java new file mode 100644 index 0000000000..37ea6894c6 --- /dev/null +++ b/core-java-modules/core-java-jvm/src/test/java/com/baeldung/bytecode/ViewBytecodeUnitTest.java @@ -0,0 +1,58 @@ +package com.baeldung.bytecode; + +import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import java.io.IOException; +import java.io.PrintWriter; +import java.io.StringWriter; +import org.apache.bcel.Repository; +import org.apache.bcel.classfile.JavaClass; +import org.junit.Test; +import org.objectweb.asm.ClassReader; +import org.objectweb.asm.util.TraceClassVisitor; +import javassist.ClassPool; +import javassist.NotFoundException; +import javassist.bytecode.ClassFile; +import net.sf.cglib.reflect.FastClass; + +public class ViewBytecodeUnitTest { + + @Test + public void whenUsingASM_thenReadBytecode() throws IOException { + ClassReader reader = new ClassReader("java.lang.Object"); + StringWriter sw = new StringWriter(); + TraceClassVisitor tcv = new TraceClassVisitor(new PrintWriter(sw)); + reader.accept(tcv, 0); + + assertTrue(sw.toString().contains("public class java/lang/Object")); + } + + @Test + public void whenUsingBCEL_thenReadBytecode() throws ClassNotFoundException { + JavaClass objectClazz = Repository.lookupClass("java.lang.Object"); + + assertEquals(objectClazz.getClassName(), "java.lang.Object"); + assertEquals(objectClazz.getMethods().length, 14); + assertTrue(objectClazz.toString().contains("public class java.lang.Object")); + } + + @Test + public void whenUsingCglib_thenReadBytecode() { + FastClass fastClass = FastClass.create(java.lang.Object.class); + Class clazz = fastClass.getJavaClass(); + + assertEquals(clazz.toString(), "class java.lang.Object"); + } + + @Test + public void whenUsingJavassist_thenReadBytecode() throws NotFoundException { + ClassPool cp = ClassPool.getDefault(); + ClassFile cf = cp.get("java.lang.Object").getClassFile(); + + assertEquals(cf.getName(), "java.lang.Object"); + assertEquals(cf.getMethods().size(), 14); + } + +} + + From 41a09bbf23c7bf1a7677dfc69bd51faf42df68a0 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Tue, 2 Jun 2020 15:46:57 +0530 Subject: [PATCH 062/140] JAVA-937: Migrate spring-cloud-bus to parent-boot-2 --- spring-cloud-bus/pom.xml | 6 +++--- spring-cloud-bus/spring-cloud-config-client/pom.xml | 5 +++++ .../src/main/resources/application.yml | 12 +++++++++++- .../src/main/resources/application.properties | 9 +++------ .../src/main/resources/bootstrap.properties | 4 ++++ 5 files changed, 26 insertions(+), 10 deletions(-) create mode 100644 spring-cloud-bus/spring-cloud-config-server/src/main/resources/bootstrap.properties diff --git a/spring-cloud-bus/pom.xml b/spring-cloud-bus/pom.xml index 513c8bade6..ec56e23ac7 100644 --- a/spring-cloud-bus/pom.xml +++ b/spring-cloud-bus/pom.xml @@ -11,9 +11,9 @@ com.baeldung - parent-boot-1 + parent-boot-2 0.0.1-SNAPSHOT - ../parent-boot-1 + ../parent-boot-2 @@ -34,7 +34,7 @@ - Brixton.SR7 + Hoxton.SR4 diff --git a/spring-cloud-bus/spring-cloud-config-client/pom.xml b/spring-cloud-bus/spring-cloud-config-client/pom.xml index 7e1185415b..cc1c237646 100644 --- a/spring-cloud-bus/spring-cloud-config-client/pom.xml +++ b/spring-cloud-bus/spring-cloud-config-client/pom.xml @@ -33,6 +33,11 @@ org.springframework.boot spring-boot-actuator + + + org.springframework.boot + spring-boot-actuator-autoconfigure + org.springframework.cloud diff --git a/spring-cloud-bus/spring-cloud-config-client/src/main/resources/application.yml b/spring-cloud-bus/spring-cloud-config-client/src/main/resources/application.yml index 547e0284f3..fbbc6d138f 100644 --- a/spring-cloud-bus/spring-cloud-config-client/src/main/resources/application.yml +++ b/spring-cloud-bus/spring-cloud-config-client/src/main/resources/application.yml @@ -4,4 +4,14 @@ spring: host: localhost port: 5672 username: guest - password: guest \ No newline at end of file + password: guest + cloud: + bus: + enabled: true + refresh: + enabled: true +management: + endpoints: + web: + exposure: + include: "*" \ No newline at end of file diff --git a/spring-cloud-bus/spring-cloud-config-server/src/main/resources/application.properties b/spring-cloud-bus/spring-cloud-config-server/src/main/resources/application.properties index 4c18c192c0..6d7a945612 100644 --- a/spring-cloud-bus/spring-cloud-config-server/src/main/resources/application.properties +++ b/spring-cloud-bus/spring-cloud-config-server/src/main/resources/application.properties @@ -1,11 +1,8 @@ server.port=8888 spring.cloud.config.server.git.uri= -security.user.name=root -security.user.password=s3cr3t -encrypt.key-store.location=classpath:/config-server.jks -encrypt.key-store.password=my-s70r3-s3cr3t -encrypt.key-store.alias=config-server-key -encrypt.key-store.secret=my-k34-s3cr3t +spring.cloud.bus.enabled=true +spring.security.user.name=root +spring.security.user.password=s3cr3t spring.rabbitmq.host=localhost spring.rabbitmq.port=5672 spring.rabbitmq.username=guest diff --git a/spring-cloud-bus/spring-cloud-config-server/src/main/resources/bootstrap.properties b/spring-cloud-bus/spring-cloud-config-server/src/main/resources/bootstrap.properties new file mode 100644 index 0000000000..b0c35c72a6 --- /dev/null +++ b/spring-cloud-bus/spring-cloud-config-server/src/main/resources/bootstrap.properties @@ -0,0 +1,4 @@ +encrypt.key-store.location=classpath:/config-server.jks +encrypt.key-store.password=my-s70r3-s3cr3t +encrypt.key-store.alias=config-server-key +encrypt.key-store.secret=my-k34-s3cr3t \ No newline at end of file From 4998662d45be50bbf79f84b6f14c52b638039bdc Mon Sep 17 00:00:00 2001 From: musibs Date: Tue, 2 Jun 2020 17:58:52 +0530 Subject: [PATCH 063/140] Moved the testcase to core-java-jvm module --- .../error/oom/ExecutorServiceUnitTest.java} | 28 +++++++++++++++---- 1 file changed, 22 insertions(+), 6 deletions(-) rename core-java-modules/{core-java-lang-2/src/test/java/com/baeldung/error/oom/TestExecutorService.java => core-java-jvm/src/test/java/com/baeldung/error/oom/ExecutorServiceUnitTest.java} (62%) diff --git a/core-java-modules/core-java-lang-2/src/test/java/com/baeldung/error/oom/TestExecutorService.java b/core-java-modules/core-java-jvm/src/test/java/com/baeldung/error/oom/ExecutorServiceUnitTest.java similarity index 62% rename from core-java-modules/core-java-lang-2/src/test/java/com/baeldung/error/oom/TestExecutorService.java rename to core-java-modules/core-java-jvm/src/test/java/com/baeldung/error/oom/ExecutorServiceUnitTest.java index d51faa055d..4e7dea370e 100644 --- a/core-java-modules/core-java-lang-2/src/test/java/com/baeldung/error/oom/TestExecutorService.java +++ b/core-java-modules/core-java-jvm/src/test/java/com/baeldung/error/oom/ExecutorServiceUnitTest.java @@ -12,12 +12,12 @@ import java.util.stream.IntStream; import org.junit.jupiter.api.Test; -public class TestExecutorService { +public class ExecutorServiceUnitTest { @Test public void givenAnExecutorService_WhenMoreTasksSubmitted_ThenAdditionalTasksWait() { - //Given + // Given int noOfThreads = 5; ExecutorService executorService = Executors.newFixedThreadPool(noOfThreads); @@ -29,11 +29,27 @@ public class TestExecutorService { } }; - //When + // When IntStream.rangeClosed(1, 10) .forEach(i -> executorService.submit(runnableTask)); - - //Then - assertThat(((ThreadPoolExecutor )executorService).getQueue().size(), is(equalTo(5))); + + // Then + assertThat(((ThreadPoolExecutor) executorService).getQueue() + .size(), is(equalTo(5))); + } + + @Test + public void givenAnExecutorService() throws Exception { + + while (true) { + TimeUnit.SECONDS.sleep(5); + new Thread(() -> { + try { + TimeUnit.HOURS.sleep(1); + } catch (InterruptedException e) { + e.printStackTrace(); + } + }).start(); + } } } From 6c6dbd6e96eacfeee56176bf2ad45ad5ad350b20 Mon Sep 17 00:00:00 2001 From: musibs Date: Tue, 2 Jun 2020 18:13:56 +0530 Subject: [PATCH 064/140] Removed the long running test case --- .../error/oom/ExecutorServiceUnitTest.java | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/core-java-modules/core-java-jvm/src/test/java/com/baeldung/error/oom/ExecutorServiceUnitTest.java b/core-java-modules/core-java-jvm/src/test/java/com/baeldung/error/oom/ExecutorServiceUnitTest.java index 4e7dea370e..47bb668727 100644 --- a/core-java-modules/core-java-jvm/src/test/java/com/baeldung/error/oom/ExecutorServiceUnitTest.java +++ b/core-java-modules/core-java-jvm/src/test/java/com/baeldung/error/oom/ExecutorServiceUnitTest.java @@ -37,19 +37,4 @@ public class ExecutorServiceUnitTest { assertThat(((ThreadPoolExecutor) executorService).getQueue() .size(), is(equalTo(5))); } - - @Test - public void givenAnExecutorService() throws Exception { - - while (true) { - TimeUnit.SECONDS.sleep(5); - new Thread(() -> { - try { - TimeUnit.HOURS.sleep(1); - } catch (InterruptedException e) { - e.printStackTrace(); - } - }).start(); - } - } } From 5b7dde1ae8c592c12161429037f81254748ddf0b Mon Sep 17 00:00:00 2001 From: Ali Dehghani Date: Sun, 31 May 2020 23:20:10 +0430 Subject: [PATCH 065/140] Adapting the VarHandle Code to Best Practices --- .../varhandles/VariableHandlesUnitTest.java | 82 +++++++++---------- 1 file changed, 41 insertions(+), 41 deletions(-) diff --git a/core-java-modules/core-java-9-new-features/src/test/java/com/baeldung/java9/varhandles/VariableHandlesUnitTest.java b/core-java-modules/core-java-9-new-features/src/test/java/com/baeldung/java9/varhandles/VariableHandlesUnitTest.java index 56e34f06a0..78a1ae3162 100644 --- a/core-java-modules/core-java-9-new-features/src/test/java/com/baeldung/java9/varhandles/VariableHandlesUnitTest.java +++ b/core-java-modules/core-java-9-new-features/src/test/java/com/baeldung/java9/varhandles/VariableHandlesUnitTest.java @@ -6,8 +6,9 @@ import java.lang.invoke.MethodHandles; import java.lang.invoke.VarHandle; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.Assert.*; -public class VariableHandlesUnitTest { +public class VariableHandlesTest { public int publicTestVariable = 1; private int privateTestVariable = 1; @@ -18,25 +19,23 @@ public class VariableHandlesUnitTest { @Test public void whenVariableHandleForPublicVariableIsCreated_ThenItIsInitializedProperly() throws NoSuchFieldException, IllegalAccessException { - VarHandle publicIntHandle = MethodHandles + VarHandle PUBLIC_TEST_VARIABLE = MethodHandles .lookup() - .in(VariableHandlesUnitTest.class) - .findVarHandle(VariableHandlesUnitTest.class, "publicTestVariable", int.class); - - assertThat(publicIntHandle.coordinateTypes().size() == 1); - assertThat(publicIntHandle.coordinateTypes().get(0) == VariableHandlesUnitTest.class); + .in(VariableHandlesTest.class) + .findVarHandle(VariableHandlesTest.class, "publicTestVariable", int.class); + assertEquals(1, PUBLIC_TEST_VARIABLE.coordinateTypes().size()); + assertEquals(VariableHandlesTest.class, PUBLIC_TEST_VARIABLE.coordinateTypes().get(0)); } @Test public void whenVariableHandleForPrivateVariableIsCreated_ThenItIsInitializedProperly() throws NoSuchFieldException, IllegalAccessException { - VarHandle privateIntHandle = MethodHandles - .privateLookupIn(VariableHandlesUnitTest.class, MethodHandles.lookup()) - .findVarHandle(VariableHandlesUnitTest.class, "privateTestVariable", int.class); - - assertThat(privateIntHandle.coordinateTypes().size() == 1); - assertThat(privateIntHandle.coordinateTypes().get(0) == VariableHandlesUnitTest.class); + VarHandle PRIVATE_TEST_VARIABLE = MethodHandles + .privateLookupIn(VariableHandlesTest.class, MethodHandles.lookup()) + .findVarHandle(VariableHandlesTest.class, "privateTestVariable", int.class); + assertEquals(1, PRIVATE_TEST_VARIABLE.coordinateTypes().size()); + assertEquals(VariableHandlesTest.class, PRIVATE_TEST_VARIABLE.coordinateTypes().get(0)); } @Test @@ -44,63 +43,64 @@ public class VariableHandlesUnitTest { VarHandle arrayVarHandle = MethodHandles .arrayElementVarHandle(int[].class); - assertThat(arrayVarHandle.coordinateTypes().size() == 2); - assertThat(arrayVarHandle.coordinateTypes().get(0) == int[].class); + assertEquals(2, arrayVarHandle.coordinateTypes().size()); + assertEquals(int[].class, arrayVarHandle.coordinateTypes().get(0)); } @Test public void givenVarHandle_whenGetIsInvoked_ThenValueOfVariableIsReturned() throws NoSuchFieldException, IllegalAccessException { - VarHandle publicIntHandle = MethodHandles + VarHandle PUBLIC_TEST_VARIABLE = MethodHandles .lookup() - .in(VariableHandlesUnitTest.class) - .findVarHandle(VariableHandlesUnitTest.class, "publicTestVariable", int.class); + .in(VariableHandlesTest.class) + .findVarHandle(VariableHandlesTest.class, "publicTestVariable", int.class); - assertThat((int) publicIntHandle.get(this) == 1); + assertEquals(1, (int) PUBLIC_TEST_VARIABLE.get(this)); } @Test public void givenVarHandle_whenSetIsInvoked_ThenValueOfVariableIsChanged() throws NoSuchFieldException, IllegalAccessException { - VarHandle publicIntHandle = MethodHandles + VarHandle VARIABLE_TO_SET = MethodHandles .lookup() - .in(VariableHandlesUnitTest.class) - .findVarHandle(VariableHandlesUnitTest.class, "variableToSet", int.class); - publicIntHandle.set(this, 15); + .in(VariableHandlesTest.class) + .findVarHandle(VariableHandlesTest.class, "variableToSet", int.class); - assertThat((int) publicIntHandle.get(this) == 15); + VARIABLE_TO_SET.set(this, 15); + assertEquals(15, (int) VARIABLE_TO_SET.get(this)); } @Test public void givenVarHandle_whenCompareAndSetIsInvoked_ThenValueOfVariableIsChanged() throws NoSuchFieldException, IllegalAccessException { - VarHandle publicIntHandle = MethodHandles + VarHandle VARIABLE_TO_COMPARE_AND_SET = MethodHandles .lookup() - .in(VariableHandlesUnitTest.class) - .findVarHandle(VariableHandlesUnitTest.class, "variableToCompareAndSet", int.class); - publicIntHandle.compareAndSet(this, 1, 100); + .in(VariableHandlesTest.class) + .findVarHandle(VariableHandlesTest.class, "variableToCompareAndSet", int.class); - assertThat((int) publicIntHandle.get(this) == 100); + VARIABLE_TO_COMPARE_AND_SET.compareAndSet(this, 1, 100); + assertEquals(100, (int) VARIABLE_TO_COMPARE_AND_SET.get(this)); } @Test public void givenVarHandle_whenGetAndAddIsInvoked_ThenValueOfVariableIsChanged() throws NoSuchFieldException, IllegalAccessException { - VarHandle publicIntHandle = MethodHandles + VarHandle VARIABLE_TO_GET_AND_ADD = MethodHandles .lookup() - .in(VariableHandlesUnitTest.class) - .findVarHandle(VariableHandlesUnitTest.class, "variableToGetAndAdd", int.class); - int before = (int) publicIntHandle.getAndAdd(this, 200); + .in(VariableHandlesTest.class) + .findVarHandle(VariableHandlesTest.class, "variableToGetAndAdd", int.class); - assertThat(before == 0); - assertThat((int) publicIntHandle.get(this) == 200); + int before = (int) VARIABLE_TO_GET_AND_ADD.getAndAdd(this, 200); + + assertEquals(0, before); + assertEquals(200, (int) VARIABLE_TO_GET_AND_ADD.get(this)); } @Test public void givenVarHandle_whenGetAndBitwiseOrIsInvoked_ThenValueOfVariableIsChanged() throws NoSuchFieldException, IllegalAccessException { - VarHandle publicIntHandle = MethodHandles + VarHandle VARIABLE_TO_BITWISE_OR = MethodHandles .lookup() - .in(VariableHandlesUnitTest.class) - .findVarHandle(VariableHandlesUnitTest.class, "variableToBitwiseOr", byte.class); - byte before = (byte) publicIntHandle.getAndBitwiseOr(this, (byte) 127); + .in(VariableHandlesTest.class) + .findVarHandle(VariableHandlesTest.class, "variableToBitwiseOr", byte.class); + byte before = (byte) VARIABLE_TO_BITWISE_OR.getAndBitwiseOr(this, (byte) 127); - assertThat(before == 0); - assertThat(variableToBitwiseOr == 127); + assertEquals(0, before); + assertEquals(127, (byte) VARIABLE_TO_BITWISE_OR.get(this)); } } From 756f70b29f1de78ce0f8af5761a1b7819b18d6bf Mon Sep 17 00:00:00 2001 From: Ali Dehghani Date: Tue, 2 Jun 2020 21:07:48 +0430 Subject: [PATCH 066/140] Rename the Class --- .../varhandles/VariableHandlesUnitTest.java | 37 +++++++++---------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/core-java-modules/core-java-9-new-features/src/test/java/com/baeldung/java9/varhandles/VariableHandlesUnitTest.java b/core-java-modules/core-java-9-new-features/src/test/java/com/baeldung/java9/varhandles/VariableHandlesUnitTest.java index 78a1ae3162..a7263f0bb2 100644 --- a/core-java-modules/core-java-9-new-features/src/test/java/com/baeldung/java9/varhandles/VariableHandlesUnitTest.java +++ b/core-java-modules/core-java-9-new-features/src/test/java/com/baeldung/java9/varhandles/VariableHandlesUnitTest.java @@ -5,10 +5,9 @@ import org.junit.Test; import java.lang.invoke.MethodHandles; import java.lang.invoke.VarHandle; -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; -public class VariableHandlesTest { +public class VariableHandlesUnitTest { public int publicTestVariable = 1; private int privateTestVariable = 1; @@ -21,21 +20,21 @@ public class VariableHandlesTest { public void whenVariableHandleForPublicVariableIsCreated_ThenItIsInitializedProperly() throws NoSuchFieldException, IllegalAccessException { VarHandle PUBLIC_TEST_VARIABLE = MethodHandles .lookup() - .in(VariableHandlesTest.class) - .findVarHandle(VariableHandlesTest.class, "publicTestVariable", int.class); + .in(VariableHandlesUnitTest.class) + .findVarHandle(VariableHandlesUnitTest.class, "publicTestVariable", int.class); assertEquals(1, PUBLIC_TEST_VARIABLE.coordinateTypes().size()); - assertEquals(VariableHandlesTest.class, PUBLIC_TEST_VARIABLE.coordinateTypes().get(0)); + assertEquals(VariableHandlesUnitTest.class, PUBLIC_TEST_VARIABLE.coordinateTypes().get(0)); } @Test public void whenVariableHandleForPrivateVariableIsCreated_ThenItIsInitializedProperly() throws NoSuchFieldException, IllegalAccessException { VarHandle PRIVATE_TEST_VARIABLE = MethodHandles - .privateLookupIn(VariableHandlesTest.class, MethodHandles.lookup()) - .findVarHandle(VariableHandlesTest.class, "privateTestVariable", int.class); + .privateLookupIn(VariableHandlesUnitTest.class, MethodHandles.lookup()) + .findVarHandle(VariableHandlesUnitTest.class, "privateTestVariable", int.class); assertEquals(1, PRIVATE_TEST_VARIABLE.coordinateTypes().size()); - assertEquals(VariableHandlesTest.class, PRIVATE_TEST_VARIABLE.coordinateTypes().get(0)); + assertEquals(VariableHandlesUnitTest.class, PRIVATE_TEST_VARIABLE.coordinateTypes().get(0)); } @Test @@ -51,8 +50,8 @@ public class VariableHandlesTest { public void givenVarHandle_whenGetIsInvoked_ThenValueOfVariableIsReturned() throws NoSuchFieldException, IllegalAccessException { VarHandle PUBLIC_TEST_VARIABLE = MethodHandles .lookup() - .in(VariableHandlesTest.class) - .findVarHandle(VariableHandlesTest.class, "publicTestVariable", int.class); + .in(VariableHandlesUnitTest.class) + .findVarHandle(VariableHandlesUnitTest.class, "publicTestVariable", int.class); assertEquals(1, (int) PUBLIC_TEST_VARIABLE.get(this)); } @@ -61,8 +60,8 @@ public class VariableHandlesTest { public void givenVarHandle_whenSetIsInvoked_ThenValueOfVariableIsChanged() throws NoSuchFieldException, IllegalAccessException { VarHandle VARIABLE_TO_SET = MethodHandles .lookup() - .in(VariableHandlesTest.class) - .findVarHandle(VariableHandlesTest.class, "variableToSet", int.class); + .in(VariableHandlesUnitTest.class) + .findVarHandle(VariableHandlesUnitTest.class, "variableToSet", int.class); VARIABLE_TO_SET.set(this, 15); assertEquals(15, (int) VARIABLE_TO_SET.get(this)); @@ -72,8 +71,8 @@ public class VariableHandlesTest { public void givenVarHandle_whenCompareAndSetIsInvoked_ThenValueOfVariableIsChanged() throws NoSuchFieldException, IllegalAccessException { VarHandle VARIABLE_TO_COMPARE_AND_SET = MethodHandles .lookup() - .in(VariableHandlesTest.class) - .findVarHandle(VariableHandlesTest.class, "variableToCompareAndSet", int.class); + .in(VariableHandlesUnitTest.class) + .findVarHandle(VariableHandlesUnitTest.class, "variableToCompareAndSet", int.class); VARIABLE_TO_COMPARE_AND_SET.compareAndSet(this, 1, 100); assertEquals(100, (int) VARIABLE_TO_COMPARE_AND_SET.get(this)); @@ -83,8 +82,8 @@ public class VariableHandlesTest { public void givenVarHandle_whenGetAndAddIsInvoked_ThenValueOfVariableIsChanged() throws NoSuchFieldException, IllegalAccessException { VarHandle VARIABLE_TO_GET_AND_ADD = MethodHandles .lookup() - .in(VariableHandlesTest.class) - .findVarHandle(VariableHandlesTest.class, "variableToGetAndAdd", int.class); + .in(VariableHandlesUnitTest.class) + .findVarHandle(VariableHandlesUnitTest.class, "variableToGetAndAdd", int.class); int before = (int) VARIABLE_TO_GET_AND_ADD.getAndAdd(this, 200); @@ -96,8 +95,8 @@ public class VariableHandlesTest { public void givenVarHandle_whenGetAndBitwiseOrIsInvoked_ThenValueOfVariableIsChanged() throws NoSuchFieldException, IllegalAccessException { VarHandle VARIABLE_TO_BITWISE_OR = MethodHandles .lookup() - .in(VariableHandlesTest.class) - .findVarHandle(VariableHandlesTest.class, "variableToBitwiseOr", byte.class); + .in(VariableHandlesUnitTest.class) + .findVarHandle(VariableHandlesUnitTest.class, "variableToBitwiseOr", byte.class); byte before = (byte) VARIABLE_TO_BITWISE_OR.getAndBitwiseOr(this, (byte) 127); assertEquals(0, before); From be292ec3f22c4ca82e7154718d89595c9cd1c9c6 Mon Sep 17 00:00:00 2001 From: Ali Dehghani Date: Tue, 2 Jun 2020 21:32:45 +0430 Subject: [PATCH 067/140] Avoid Using newInstance on Class --- .../reflection/java/reflection/ReflectionUnitTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core-java-modules/core-java-reflection/src/test/java/com/baeldung/reflection/java/reflection/ReflectionUnitTest.java b/core-java-modules/core-java-reflection/src/test/java/com/baeldung/reflection/java/reflection/ReflectionUnitTest.java index 0c090901e7..a791d64874 100644 --- a/core-java-modules/core-java-reflection/src/test/java/com/baeldung/reflection/java/reflection/ReflectionUnitTest.java +++ b/core-java-modules/core-java-reflection/src/test/java/com/baeldung/reflection/java/reflection/ReflectionUnitTest.java @@ -200,7 +200,7 @@ public class ReflectionUnitTest { @Test public void givenClassField_whenSetsAndGetsValue_thenCorrect() throws Exception { final Class birdClass = Class.forName("com.baeldung.java.reflection.Bird"); - final Bird bird = (Bird) birdClass.newInstance(); + final Bird bird = (Bird) birdClass.getConstructor().newInstance(); final Field field = birdClass.getDeclaredField("walks"); field.setAccessible(true); @@ -266,7 +266,7 @@ public class ReflectionUnitTest { @Test public void givenMethod_whenInvokes_thenCorrect() throws Exception { final Class birdClass = Class.forName("com.baeldung.java.reflection.Bird"); - final Bird bird = (Bird) birdClass.newInstance(); + final Bird bird = (Bird) birdClass.getConstructor().newInstance(); final Method setWalksMethod = birdClass.getDeclaredMethod("setWalks", boolean.class); final Method walksMethod = birdClass.getDeclaredMethod("walks"); final boolean walks = (boolean) walksMethod.invoke(bird); From 6dbd0c1d6cd61d81bf10413a09af83270eca69f2 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Tue, 2 Jun 2020 22:41:01 +0530 Subject: [PATCH 068/140] JAVA-932: Migrate spring-cloud-kubernetes to parent-boot-2 --- .../kubernetes-selfhealing/liveness-example/pom.xml | 9 ++++----- .../kubernetes-selfhealing/readiness-example/pom.xml | 9 ++++----- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/spring-cloud/spring-cloud-kubernetes/kubernetes-selfhealing/liveness-example/pom.xml b/spring-cloud/spring-cloud-kubernetes/kubernetes-selfhealing/liveness-example/pom.xml index 66d8f096ce..f0d34d2231 100644 --- a/spring-cloud/spring-cloud-kubernetes/kubernetes-selfhealing/liveness-example/pom.xml +++ b/spring-cloud/spring-cloud-kubernetes/kubernetes-selfhealing/liveness-example/pom.xml @@ -8,10 +8,10 @@ 1.0-SNAPSHOT - com.baeldung - parent-boot-1 - 0.0.1-SNAPSHOT - ../../../../parent-boot-1 + com.baeldung.spring.cloud + spring-cloud-kubernetes + 1.0-SNAPSHOT + ../../../spring-cloud-kubernetes @@ -44,7 +44,6 @@ UTF-8 UTF-8 - 1.5.17.RELEASE \ No newline at end of file diff --git a/spring-cloud/spring-cloud-kubernetes/kubernetes-selfhealing/readiness-example/pom.xml b/spring-cloud/spring-cloud-kubernetes/kubernetes-selfhealing/readiness-example/pom.xml index fbb9e09d07..8bfd4d305d 100644 --- a/spring-cloud/spring-cloud-kubernetes/kubernetes-selfhealing/readiness-example/pom.xml +++ b/spring-cloud/spring-cloud-kubernetes/kubernetes-selfhealing/readiness-example/pom.xml @@ -8,10 +8,10 @@ 1.0-SNAPSHOT - com.baeldung - parent-boot-1 - 0.0.1-SNAPSHOT - ../../../../parent-boot-1 + com.baeldung.spring.cloud + spring-cloud-kubernetes + 1.0-SNAPSHOT + ../../../spring-cloud-kubernetes @@ -44,7 +44,6 @@ UTF-8 UTF-8 - 1.5.17.RELEASE \ No newline at end of file From 89ea700e24631a695118e02ecf1e4ef831a00a08 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Tue, 2 Jun 2020 22:55:10 +0530 Subject: [PATCH 069/140] JAVA-39: Removed module spring-security-kerberos --- .../spring-security-kerberos/README.md | 13 --- .../spring-security-kerberos/pom.xml | 69 --------------- .../main/java/com/baeldung/Application.java | 13 --- .../baeldung/config/WebSecurityConfig.java | 87 ------------------- .../security/DummyUserDetailsService.java | 16 ---- 5 files changed, 198 deletions(-) delete mode 100644 spring-security-modules/spring-security-kerberos/README.md delete mode 100644 spring-security-modules/spring-security-kerberos/pom.xml delete mode 100644 spring-security-modules/spring-security-kerberos/src/main/java/com/baeldung/Application.java delete mode 100644 spring-security-modules/spring-security-kerberos/src/main/java/com/baeldung/config/WebSecurityConfig.java delete mode 100644 spring-security-modules/spring-security-kerberos/src/main/java/com/baeldung/security/DummyUserDetailsService.java diff --git a/spring-security-modules/spring-security-kerberos/README.md b/spring-security-modules/spring-security-kerberos/README.md deleted file mode 100644 index a868fb86b7..0000000000 --- a/spring-security-modules/spring-security-kerberos/README.md +++ /dev/null @@ -1,13 +0,0 @@ -## Spring Security Kerberos - -This module contains articles about Spring Security Kerberos - -### Relevant Articles: - -- [Introduction to SPNEGO/Kerberos Authentication in Spring](https://www.baeldung.com/spring-security-kerberos) - -### @PreFilter and @PostFilter annotations - -### Build the Project ### - -`mvn clean install` \ No newline at end of file diff --git a/spring-security-modules/spring-security-kerberos/pom.xml b/spring-security-modules/spring-security-kerberos/pom.xml deleted file mode 100644 index 51a48a78c6..0000000000 --- a/spring-security-modules/spring-security-kerberos/pom.xml +++ /dev/null @@ -1,69 +0,0 @@ - - - 4.0.0 - spring-security-kerberos - 0.1-SNAPSHOT - spring-security-kerberos - war - - - com.baeldung - parent-boot-2 - 0.0.1-SNAPSHOT - ../../parent-boot-2 - - - - - org.springframework.boot - spring-boot-starter-web - - - org.springframework.boot - spring-boot-starter-security - - - - org.springframework.security.kerberos - spring-security-kerberos-core - ${spring-security-kerberos.version} - - - org.springframework.security.kerberos - spring-security-kerberos-web - ${spring-security-kerberos.version} - - - org.springframework.security.kerberos - spring-security-kerberos-client - ${spring-security-kerberos.version} - - - - org.springframework.boot - spring-boot-starter-test - test - - - org.springframework.security - spring-security-test - test - - - - - - - org.apache.maven.plugins - maven-war-plugin - - - - - - 1.0.1.RELEASE - - - diff --git a/spring-security-modules/spring-security-kerberos/src/main/java/com/baeldung/Application.java b/spring-security-modules/spring-security-kerberos/src/main/java/com/baeldung/Application.java deleted file mode 100644 index 37dbe7dab8..0000000000 --- a/spring-security-modules/spring-security-kerberos/src/main/java/com/baeldung/Application.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.baeldung; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class Application { - - public static void main(String[] args) { - SpringApplication.run(Application.class, args); - } - -} diff --git a/spring-security-modules/spring-security-kerberos/src/main/java/com/baeldung/config/WebSecurityConfig.java b/spring-security-modules/spring-security-kerberos/src/main/java/com/baeldung/config/WebSecurityConfig.java deleted file mode 100644 index c1c206e5c9..0000000000 --- a/spring-security-modules/spring-security-kerberos/src/main/java/com/baeldung/config/WebSecurityConfig.java +++ /dev/null @@ -1,87 +0,0 @@ -package com.baeldung.config; - -import com.baeldung.security.DummyUserDetailsService; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.core.io.FileSystemResource; -import org.springframework.security.authentication.AuthenticationManager; -import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; -import org.springframework.security.config.annotation.web.builders.HttpSecurity; -import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; -import org.springframework.security.kerberos.authentication.KerberosAuthenticationProvider; -import org.springframework.security.kerberos.authentication.KerberosServiceAuthenticationProvider; -import org.springframework.security.kerberos.authentication.sun.SunJaasKerberosClient; -import org.springframework.security.kerberos.authentication.sun.SunJaasKerberosTicketValidator; -import org.springframework.security.kerberos.web.authentication.SpnegoAuthenticationProcessingFilter; -import org.springframework.security.kerberos.web.authentication.SpnegoEntryPoint; -import org.springframework.security.web.authentication.www.BasicAuthenticationFilter; - -@Configuration -public class WebSecurityConfig extends WebSecurityConfigurerAdapter { - - @Override - protected void configure(HttpSecurity http) throws Exception { - http.authorizeRequests() - .anyRequest() - .authenticated() - .and() - .addFilterBefore(spnegoAuthenticationProcessingFilter(authenticationManagerBean()), BasicAuthenticationFilter.class); - } - - @Override - @Bean - public AuthenticationManager authenticationManagerBean() throws Exception { - return super.authenticationManagerBean(); - } - - @Override - protected void configure(AuthenticationManagerBuilder auth) throws Exception { - auth.authenticationProvider(kerberosAuthenticationProvider()) - .authenticationProvider(kerberosServiceAuthenticationProvider()); - } - - @Bean - public KerberosAuthenticationProvider kerberosAuthenticationProvider() { - KerberosAuthenticationProvider provider = new KerberosAuthenticationProvider(); - SunJaasKerberosClient client = new SunJaasKerberosClient(); - client.setDebug(true); - provider.setKerberosClient(client); - provider.setUserDetailsService(dummyUserDetailsService()); - return provider; - } - - @Bean - public SpnegoEntryPoint spnegoEntryPoint() { - return new SpnegoEntryPoint("/login"); - } - - @Bean - public SpnegoAuthenticationProcessingFilter spnegoAuthenticationProcessingFilter(AuthenticationManager authenticationManager) { - SpnegoAuthenticationProcessingFilter filter = new SpnegoAuthenticationProcessingFilter(); - filter.setAuthenticationManager(authenticationManager); - return filter; - } - - @Bean - public KerberosServiceAuthenticationProvider kerberosServiceAuthenticationProvider() { - KerberosServiceAuthenticationProvider provider = new KerberosServiceAuthenticationProvider(); - provider.setTicketValidator(sunJaasKerberosTicketValidator()); - provider.setUserDetailsService(dummyUserDetailsService()); - return provider; - } - - @Bean - public SunJaasKerberosTicketValidator sunJaasKerberosTicketValidator() { - SunJaasKerberosTicketValidator ticketValidator = new SunJaasKerberosTicketValidator(); - ticketValidator.setServicePrincipal("HTTP/demo.kerberos.bealdung.com@baeldung.com"); - ticketValidator.setKeyTabLocation(new FileSystemResource("baeldung.keytab")); - ticketValidator.setDebug(true); - return ticketValidator; - } - - @Bean - public DummyUserDetailsService dummyUserDetailsService() { - return new DummyUserDetailsService(); - } - -} \ No newline at end of file diff --git a/spring-security-modules/spring-security-kerberos/src/main/java/com/baeldung/security/DummyUserDetailsService.java b/spring-security-modules/spring-security-kerberos/src/main/java/com/baeldung/security/DummyUserDetailsService.java deleted file mode 100644 index 6ddd6c8969..0000000000 --- a/spring-security-modules/spring-security-kerberos/src/main/java/com/baeldung/security/DummyUserDetailsService.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.baeldung.security; - -import org.springframework.security.core.authority.AuthorityUtils; -import org.springframework.security.core.userdetails.User; -import org.springframework.security.core.userdetails.UserDetails; -import org.springframework.security.core.userdetails.UserDetailsService; -import org.springframework.security.core.userdetails.UsernameNotFoundException; - -public class DummyUserDetailsService implements UserDetailsService { - - @Override - public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { - return new User(username, "notUsed", true, true, true, true, AuthorityUtils.createAuthorityList("ROLE_USER")); - } - -} \ No newline at end of file From 97fa800bbdb54d81923fc224cac4c312ad808f88 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Tue, 2 Jun 2020 22:56:31 +0530 Subject: [PATCH 070/140] JAVA-39: Moved article from spring-security kerberos module to spring-security-sso/spring-security-sso-kerberos --- .../spring-security-sso-kerberos/README.md | 1 + .../java/com/baeldung/intro/Application.java | 13 +++ .../intro/config/WebSecurityConfig.java | 88 +++++++++++++++++++ .../security/DummyUserDetailsService.java | 16 ++++ 4 files changed, 118 insertions(+) create mode 100644 spring-security-modules/spring-security-sso/spring-security-sso-kerberos/src/main/java/com/baeldung/intro/Application.java create mode 100644 spring-security-modules/spring-security-sso/spring-security-sso-kerberos/src/main/java/com/baeldung/intro/config/WebSecurityConfig.java create mode 100644 spring-security-modules/spring-security-sso/spring-security-sso-kerberos/src/main/java/com/baeldung/intro/security/DummyUserDetailsService.java diff --git a/spring-security-modules/spring-security-sso/spring-security-sso-kerberos/README.md b/spring-security-modules/spring-security-sso/spring-security-sso-kerberos/README.md index 3aa092edb8..4bb0eea16c 100644 --- a/spring-security-modules/spring-security-sso/spring-security-sso-kerberos/README.md +++ b/spring-security-modules/spring-security-sso/spring-security-sso-kerberos/README.md @@ -1,3 +1,4 @@ ## Relevant articles: - [Spring Security Kerberos Integration](https://www.baeldung.com/spring-security-kerberos-integration) +- [Introduction to SPNEGO/Kerberos Authentication in Spring](https://www.baeldung.com/spring-security-kerberos) diff --git a/spring-security-modules/spring-security-sso/spring-security-sso-kerberos/src/main/java/com/baeldung/intro/Application.java b/spring-security-modules/spring-security-sso/spring-security-sso-kerberos/src/main/java/com/baeldung/intro/Application.java new file mode 100644 index 0000000000..2cddbf0f22 --- /dev/null +++ b/spring-security-modules/spring-security-sso/spring-security-sso-kerberos/src/main/java/com/baeldung/intro/Application.java @@ -0,0 +1,13 @@ +package com.baeldung.intro; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class Application { + + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } + +} diff --git a/spring-security-modules/spring-security-sso/spring-security-sso-kerberos/src/main/java/com/baeldung/intro/config/WebSecurityConfig.java b/spring-security-modules/spring-security-sso/spring-security-sso-kerberos/src/main/java/com/baeldung/intro/config/WebSecurityConfig.java new file mode 100644 index 0000000000..cc694a3b83 --- /dev/null +++ b/spring-security-modules/spring-security-sso/spring-security-sso-kerberos/src/main/java/com/baeldung/intro/config/WebSecurityConfig.java @@ -0,0 +1,88 @@ +package com.baeldung.intro.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.io.FileSystemResource; +import org.springframework.security.authentication.AuthenticationManager; +import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; +import org.springframework.security.kerberos.authentication.KerberosAuthenticationProvider; +import org.springframework.security.kerberos.authentication.KerberosServiceAuthenticationProvider; +import org.springframework.security.kerberos.authentication.sun.SunJaasKerberosClient; +import org.springframework.security.kerberos.authentication.sun.SunJaasKerberosTicketValidator; +import org.springframework.security.kerberos.web.authentication.SpnegoAuthenticationProcessingFilter; +import org.springframework.security.kerberos.web.authentication.SpnegoEntryPoint; +import org.springframework.security.web.authentication.www.BasicAuthenticationFilter; + +import com.baeldung.intro.security.DummyUserDetailsService; + +@Configuration +public class WebSecurityConfig extends WebSecurityConfigurerAdapter { + + @Override + protected void configure(HttpSecurity http) throws Exception { + http.authorizeRequests() + .anyRequest() + .authenticated() + .and() + .addFilterBefore(spnegoAuthenticationProcessingFilter(authenticationManagerBean()), BasicAuthenticationFilter.class); + } + + @Override + @Bean + public AuthenticationManager authenticationManagerBean() throws Exception { + return super.authenticationManagerBean(); + } + + @Override + protected void configure(AuthenticationManagerBuilder auth) throws Exception { + auth.authenticationProvider(kerberosAuthenticationProvider()) + .authenticationProvider(kerberosServiceAuthenticationProvider()); + } + + @Bean + public KerberosAuthenticationProvider kerberosAuthenticationProvider() { + KerberosAuthenticationProvider provider = new KerberosAuthenticationProvider(); + SunJaasKerberosClient client = new SunJaasKerberosClient(); + client.setDebug(true); + provider.setKerberosClient(client); + provider.setUserDetailsService(dummyUserDetailsService()); + return provider; + } + + @Bean + public SpnegoEntryPoint spnegoEntryPoint() { + return new SpnegoEntryPoint("/login"); + } + + @Bean + public SpnegoAuthenticationProcessingFilter spnegoAuthenticationProcessingFilter(AuthenticationManager authenticationManager) { + SpnegoAuthenticationProcessingFilter filter = new SpnegoAuthenticationProcessingFilter(); + filter.setAuthenticationManager(authenticationManager); + return filter; + } + + @Bean + public KerberosServiceAuthenticationProvider kerberosServiceAuthenticationProvider() { + KerberosServiceAuthenticationProvider provider = new KerberosServiceAuthenticationProvider(); + provider.setTicketValidator(sunJaasKerberosTicketValidator()); + provider.setUserDetailsService(dummyUserDetailsService()); + return provider; + } + + @Bean + public SunJaasKerberosTicketValidator sunJaasKerberosTicketValidator() { + SunJaasKerberosTicketValidator ticketValidator = new SunJaasKerberosTicketValidator(); + ticketValidator.setServicePrincipal("HTTP/demo.kerberos.bealdung.com@baeldung.com"); + ticketValidator.setKeyTabLocation(new FileSystemResource("baeldung.keytab")); + ticketValidator.setDebug(true); + return ticketValidator; + } + + @Bean + public DummyUserDetailsService dummyUserDetailsService() { + return new DummyUserDetailsService(); + } + +} \ No newline at end of file diff --git a/spring-security-modules/spring-security-sso/spring-security-sso-kerberos/src/main/java/com/baeldung/intro/security/DummyUserDetailsService.java b/spring-security-modules/spring-security-sso/spring-security-sso-kerberos/src/main/java/com/baeldung/intro/security/DummyUserDetailsService.java new file mode 100644 index 0000000000..f564c9f756 --- /dev/null +++ b/spring-security-modules/spring-security-sso/spring-security-sso-kerberos/src/main/java/com/baeldung/intro/security/DummyUserDetailsService.java @@ -0,0 +1,16 @@ +package com.baeldung.intro.security; + +import org.springframework.security.core.authority.AuthorityUtils; +import org.springframework.security.core.userdetails.User; +import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.security.core.userdetails.UserDetailsService; +import org.springframework.security.core.userdetails.UsernameNotFoundException; + +public class DummyUserDetailsService implements UserDetailsService { + + @Override + public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { + return new User(username, "notUsed", true, true, true, true, AuthorityUtils.createAuthorityList("ROLE_USER")); + } + +} \ No newline at end of file From d214da3cb1deeba6a17d48973605cf25da8392d2 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Tue, 2 Jun 2020 22:57:22 +0530 Subject: [PATCH 071/140] JAVA-39: Updated parent module pom to remove deleted module --- spring-security-modules/pom.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/spring-security-modules/pom.xml b/spring-security-modules/pom.xml index 60a662781f..954b9335e4 100644 --- a/spring-security-modules/pom.xml +++ b/spring-security-modules/pom.xml @@ -20,7 +20,6 @@ spring-security-cache-control spring-security-core spring-security-cors - spring-security-kerberos spring-security-mvc spring-security-mvc-boot-1 spring-security-mvc-boot-2 From b07bcce7efcdf939dd336b2dceabbb88449b89b9 Mon Sep 17 00:00:00 2001 From: Ali Dehghani Date: Tue, 2 Jun 2020 22:03:54 +0430 Subject: [PATCH 072/140] Introducing Integer Cache --- .../stringtoint/StringToIntOrIntegerUnitTest.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/core-java-modules/core-java-string-conversions/src/test/java/com/baeldung/stringtoint/StringToIntOrIntegerUnitTest.java b/core-java-modules/core-java-string-conversions/src/test/java/com/baeldung/stringtoint/StringToIntOrIntegerUnitTest.java index 106f1fc974..336b2ac324 100644 --- a/core-java-modules/core-java-string-conversions/src/test/java/com/baeldung/stringtoint/StringToIntOrIntegerUnitTest.java +++ b/core-java-modules/core-java-string-conversions/src/test/java/com/baeldung/stringtoint/StringToIntOrIntegerUnitTest.java @@ -26,6 +26,17 @@ public class StringToIntOrIntegerUnitTest { assertThat(result).isEqualTo(new Integer(42)); } + @Test + public void givenString_whenCallingValueOf_shouldCacheSomeValues() { + for (int i = -128; i <= 127; i++) { + String value = i + ""; + Integer first = Integer.valueOf(value); + Integer second = Integer.valueOf(value); + + assertThat(first).isSameAs(second); + } + } + @Test public void givenString_whenCallingIntegerConstructor_shouldConvertToInt() { String givenString = "42"; From 2af1e30a8f70394d6914a4a2b43aa9b0b68ca78b Mon Sep 17 00:00:00 2001 From: Mona Mohamadinia Date: Tue, 2 Jun 2020 23:01:56 +0430 Subject: [PATCH 073/140] KTLN-141: Not-Null Assertion (!!) Operator in Kotlin (#9371) * Added the Test Samples * Renamed the Class --- .../nullassertion/NotNullAssertionUnitTest.kt | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 core-kotlin-modules/core-kotlin-2/src/test/kotlin/com/baeldung/nullassertion/NotNullAssertionUnitTest.kt diff --git a/core-kotlin-modules/core-kotlin-2/src/test/kotlin/com/baeldung/nullassertion/NotNullAssertionUnitTest.kt b/core-kotlin-modules/core-kotlin-2/src/test/kotlin/com/baeldung/nullassertion/NotNullAssertionUnitTest.kt new file mode 100644 index 0000000000..434f177927 --- /dev/null +++ b/core-kotlin-modules/core-kotlin-2/src/test/kotlin/com/baeldung/nullassertion/NotNullAssertionUnitTest.kt @@ -0,0 +1,20 @@ +package com.baeldung.nullassertion + +import org.junit.Test +import kotlin.test.assertEquals + +class NotNullAssertionUnitTest { + + @Test + fun givenNullableValue_WhenNotNull_ShouldExtractTheValue() { + val answer: String? = "42" + + assertEquals(42, answer!!.toInt()) + } + + @Test(expected = KotlinNullPointerException::class) + fun givenNullableValue_WhenIsNull_ThenShouldThrow() { + val noAnswer: String? = null + noAnswer!! + } +} From d59d2e3793d951853fea5b7e5ae67cd8c1f3f695 Mon Sep 17 00:00:00 2001 From: kwoyke Date: Tue, 2 Jun 2020 21:04:09 +0200 Subject: [PATCH 074/140] BAEL-4171: Add SecurityAdviceTrait to the ExceptionTranslator (#9418) --- .../jhipster/gateway/web/rest/errors/ExceptionTranslator.java | 3 ++- .../jhipster/quotes/web/rest/errors/ExceptionTranslator.java | 3 ++- .../jhipster/uaa/web/rest/errors/ExceptionTranslator.java | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/jhipster/jhipster-uaa/gateway/src/main/java/com/baeldung/jhipster/gateway/web/rest/errors/ExceptionTranslator.java b/jhipster/jhipster-uaa/gateway/src/main/java/com/baeldung/jhipster/gateway/web/rest/errors/ExceptionTranslator.java index d5c9e577a6..fd6e04dadc 100644 --- a/jhipster/jhipster-uaa/gateway/src/main/java/com/baeldung/jhipster/gateway/web/rest/errors/ExceptionTranslator.java +++ b/jhipster/jhipster-uaa/gateway/src/main/java/com/baeldung/jhipster/gateway/web/rest/errors/ExceptionTranslator.java @@ -14,6 +14,7 @@ import org.zalando.problem.Problem; import org.zalando.problem.ProblemBuilder; import org.zalando.problem.Status; import org.zalando.problem.spring.web.advice.ProblemHandling; +import org.zalando.problem.spring.web.advice.security.SecurityAdviceTrait; import org.zalando.problem.violations.ConstraintViolationProblem; import javax.annotation.Nonnull; @@ -28,7 +29,7 @@ import java.util.stream.Collectors; * The error response follows RFC7807 - Problem Details for HTTP APIs (https://tools.ietf.org/html/rfc7807) */ @ControllerAdvice -public class ExceptionTranslator implements ProblemHandling { +public class ExceptionTranslator implements ProblemHandling, SecurityAdviceTrait { /** * Post-process the Problem payload to add the message key for the front-end if needed diff --git a/jhipster/jhipster-uaa/quotes/src/main/java/com/baeldung/jhipster/quotes/web/rest/errors/ExceptionTranslator.java b/jhipster/jhipster-uaa/quotes/src/main/java/com/baeldung/jhipster/quotes/web/rest/errors/ExceptionTranslator.java index 18baa42736..3bf4995405 100644 --- a/jhipster/jhipster-uaa/quotes/src/main/java/com/baeldung/jhipster/quotes/web/rest/errors/ExceptionTranslator.java +++ b/jhipster/jhipster-uaa/quotes/src/main/java/com/baeldung/jhipster/quotes/web/rest/errors/ExceptionTranslator.java @@ -14,6 +14,7 @@ import org.zalando.problem.Problem; import org.zalando.problem.ProblemBuilder; import org.zalando.problem.Status; import org.zalando.problem.spring.web.advice.ProblemHandling; +import org.zalando.problem.spring.web.advice.security.SecurityAdviceTrait; import org.zalando.problem.violations.ConstraintViolationProblem; import javax.annotation.Nonnull; @@ -28,7 +29,7 @@ import java.util.stream.Collectors; * The error response follows RFC7807 - Problem Details for HTTP APIs (https://tools.ietf.org/html/rfc7807) */ @ControllerAdvice -public class ExceptionTranslator implements ProblemHandling { +public class ExceptionTranslator implements ProblemHandling, SecurityAdviceTrait { /** * Post-process the Problem payload to add the message key for the front-end if needed diff --git a/jhipster/jhipster-uaa/uaa/src/main/java/com/baeldung/jhipster/uaa/web/rest/errors/ExceptionTranslator.java b/jhipster/jhipster-uaa/uaa/src/main/java/com/baeldung/jhipster/uaa/web/rest/errors/ExceptionTranslator.java index 320636c51d..6af9fd126c 100644 --- a/jhipster/jhipster-uaa/uaa/src/main/java/com/baeldung/jhipster/uaa/web/rest/errors/ExceptionTranslator.java +++ b/jhipster/jhipster-uaa/uaa/src/main/java/com/baeldung/jhipster/uaa/web/rest/errors/ExceptionTranslator.java @@ -14,6 +14,7 @@ import org.zalando.problem.Problem; import org.zalando.problem.ProblemBuilder; import org.zalando.problem.Status; import org.zalando.problem.spring.web.advice.ProblemHandling; +import org.zalando.problem.spring.web.advice.security.SecurityAdviceTrait; import org.zalando.problem.violations.ConstraintViolationProblem; import javax.annotation.Nonnull; @@ -28,7 +29,7 @@ import java.util.stream.Collectors; * The error response follows RFC7807 - Problem Details for HTTP APIs (https://tools.ietf.org/html/rfc7807) */ @ControllerAdvice -public class ExceptionTranslator implements ProblemHandling { +public class ExceptionTranslator implements ProblemHandling, SecurityAdviceTrait { /** * Post-process the Problem payload to add the message key for the front-end if needed From 9d4a0b1f516dbe591c1d62c7f404826c72ef7a4c Mon Sep 17 00:00:00 2001 From: kwoyke Date: Tue, 2 Jun 2020 21:15:49 +0200 Subject: [PATCH 075/140] BAEL-4100: Move HTTP/2 in Jetty to the new libraries-server-2 module (#9394) --- libraries-server-2/.gitignore | 9 ++ libraries-server-2/README.md | 8 ++ libraries-server-2/pom.xml | 77 ++++++++++++++++++ .../src/main/config/jetty.xml | 0 .../jetty/http2/Http2JettyServlet.java | 0 .../src/main/resources/keystore.jks | Bin .../src/main/resources/logback.xml | 13 +++ .../src/main/resources/truststore.jks | Bin .../src/main/webapp/WEB-INF/web.xml | 0 .../src/main/webapp/http2.html | 0 .../images/homepage-latest_articles.jpg | Bin .../images/homepage-rest_with_spring.jpg | Bin .../webapp/images/homepage-weekly_reviews.jpg | Bin .../src/main/webapp/index.html | 0 libraries-server/README.md | 2 +- libraries-server/pom.xml | 40 --------- pom.xml | 2 + 17 files changed, 110 insertions(+), 41 deletions(-) create mode 100644 libraries-server-2/.gitignore create mode 100644 libraries-server-2/README.md create mode 100644 libraries-server-2/pom.xml rename {libraries-server => libraries-server-2}/src/main/config/jetty.xml (100%) rename {libraries-server => libraries-server-2}/src/main/java/com/baeldung/jetty/http2/Http2JettyServlet.java (100%) rename {libraries-server => libraries-server-2}/src/main/resources/keystore.jks (100%) create mode 100644 libraries-server-2/src/main/resources/logback.xml rename {libraries-server => libraries-server-2}/src/main/resources/truststore.jks (100%) rename {libraries-server => libraries-server-2}/src/main/webapp/WEB-INF/web.xml (100%) rename {libraries-server => libraries-server-2}/src/main/webapp/http2.html (100%) rename {libraries-server => libraries-server-2}/src/main/webapp/images/homepage-latest_articles.jpg (100%) rename {libraries-server => libraries-server-2}/src/main/webapp/images/homepage-rest_with_spring.jpg (100%) rename {libraries-server => libraries-server-2}/src/main/webapp/images/homepage-weekly_reviews.jpg (100%) rename {libraries-server => libraries-server-2}/src/main/webapp/index.html (100%) diff --git a/libraries-server-2/.gitignore b/libraries-server-2/.gitignore new file mode 100644 index 0000000000..e594daf27a --- /dev/null +++ b/libraries-server-2/.gitignore @@ -0,0 +1,9 @@ +*.class + +# Folders # +/gensrc +/target + +# Packaged files # +*.jar +/bin/ diff --git a/libraries-server-2/README.md b/libraries-server-2/README.md new file mode 100644 index 0000000000..38166bcd77 --- /dev/null +++ b/libraries-server-2/README.md @@ -0,0 +1,8 @@ +## Server + +This module contains articles about server libraries. + +### Relevant Articles: + +- [HTTP/2 in Jetty](https://www.baeldung.com/jetty-http-2) +- More articles: [[<-- prev]](../libraries-server) diff --git a/libraries-server-2/pom.xml b/libraries-server-2/pom.xml new file mode 100644 index 0000000000..5f500a7ced --- /dev/null +++ b/libraries-server-2/pom.xml @@ -0,0 +1,77 @@ + + + 4.0.0 + libraries-server-2 + 0.0.1-SNAPSHOT + libraries-server-2 + war + + + com.baeldung + parent-modules + 1.0.0-SNAPSHOT + + + + + org.eclipse.jetty + jetty-server + ${jetty.version} + + + org.eclipse.jetty + jetty-servlet + ${jetty.version} + + + org.eclipse.jetty + jetty-webapp + ${jetty.version} + + + + + + + org.eclipse.jetty + jetty-maven-plugin + ${jetty.version} + + 8888 + quit + + -Xbootclasspath/p:${settings.localRepository}/org/mortbay/jetty/alpn/alpn-boot/${alpn.version}/alpn-boot-${alpn.version}.jar + + ${basedir}/src/main/config/jetty.xml + + / + + + + + org.eclipse.jetty.http2 + http2-server + ${jetty.version} + + + org.eclipse.jetty + jetty-alpn-openjdk8-server + ${jetty.version} + + + org.eclipse.jetty + jetty-servlets + ${jetty.version} + + + + + + + + 9.4.27.v20200227 + 8.1.11.v20170118 + + + \ No newline at end of file diff --git a/libraries-server/src/main/config/jetty.xml b/libraries-server-2/src/main/config/jetty.xml similarity index 100% rename from libraries-server/src/main/config/jetty.xml rename to libraries-server-2/src/main/config/jetty.xml diff --git a/libraries-server/src/main/java/com/baeldung/jetty/http2/Http2JettyServlet.java b/libraries-server-2/src/main/java/com/baeldung/jetty/http2/Http2JettyServlet.java similarity index 100% rename from libraries-server/src/main/java/com/baeldung/jetty/http2/Http2JettyServlet.java rename to libraries-server-2/src/main/java/com/baeldung/jetty/http2/Http2JettyServlet.java diff --git a/libraries-server/src/main/resources/keystore.jks b/libraries-server-2/src/main/resources/keystore.jks similarity index 100% rename from libraries-server/src/main/resources/keystore.jks rename to libraries-server-2/src/main/resources/keystore.jks diff --git a/libraries-server-2/src/main/resources/logback.xml b/libraries-server-2/src/main/resources/logback.xml new file mode 100644 index 0000000000..7d900d8ea8 --- /dev/null +++ b/libraries-server-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/libraries-server/src/main/resources/truststore.jks b/libraries-server-2/src/main/resources/truststore.jks similarity index 100% rename from libraries-server/src/main/resources/truststore.jks rename to libraries-server-2/src/main/resources/truststore.jks diff --git a/libraries-server/src/main/webapp/WEB-INF/web.xml b/libraries-server-2/src/main/webapp/WEB-INF/web.xml similarity index 100% rename from libraries-server/src/main/webapp/WEB-INF/web.xml rename to libraries-server-2/src/main/webapp/WEB-INF/web.xml diff --git a/libraries-server/src/main/webapp/http2.html b/libraries-server-2/src/main/webapp/http2.html similarity index 100% rename from libraries-server/src/main/webapp/http2.html rename to libraries-server-2/src/main/webapp/http2.html diff --git a/libraries-server/src/main/webapp/images/homepage-latest_articles.jpg b/libraries-server-2/src/main/webapp/images/homepage-latest_articles.jpg similarity index 100% rename from libraries-server/src/main/webapp/images/homepage-latest_articles.jpg rename to libraries-server-2/src/main/webapp/images/homepage-latest_articles.jpg diff --git a/libraries-server/src/main/webapp/images/homepage-rest_with_spring.jpg b/libraries-server-2/src/main/webapp/images/homepage-rest_with_spring.jpg similarity index 100% rename from libraries-server/src/main/webapp/images/homepage-rest_with_spring.jpg rename to libraries-server-2/src/main/webapp/images/homepage-rest_with_spring.jpg diff --git a/libraries-server/src/main/webapp/images/homepage-weekly_reviews.jpg b/libraries-server-2/src/main/webapp/images/homepage-weekly_reviews.jpg similarity index 100% rename from libraries-server/src/main/webapp/images/homepage-weekly_reviews.jpg rename to libraries-server-2/src/main/webapp/images/homepage-weekly_reviews.jpg diff --git a/libraries-server/src/main/webapp/index.html b/libraries-server-2/src/main/webapp/index.html similarity index 100% rename from libraries-server/src/main/webapp/index.html rename to libraries-server-2/src/main/webapp/index.html diff --git a/libraries-server/README.md b/libraries-server/README.md index 7e41f33a0c..570806611f 100644 --- a/libraries-server/README.md +++ b/libraries-server/README.md @@ -13,4 +13,4 @@ This module contains articles about server libraries. - [MQTT Client in Java](https://www.baeldung.com/java-mqtt-client) - [Guide to XMPP Smack Client](https://www.baeldung.com/xmpp-smack-chat-client) - [A Guide to NanoHTTPD](https://www.baeldung.com/nanohttpd) -- [HTTP/2 in Jetty](https://www.baeldung.com/jetty-http-2) +- More articles: [[more -->]](../libraries-server-2) \ No newline at end of file diff --git a/libraries-server/pom.xml b/libraries-server/pom.xml index eb9cb61e56..d9546f1678 100644 --- a/libraries-server/pom.xml +++ b/libraries-server/pom.xml @@ -5,7 +5,6 @@ libraries-server 0.0.1-SNAPSHOT libraries-server - war com.baeldung @@ -107,50 +106,11 @@ - - - - org.eclipse.jetty - jetty-maven-plugin - ${jetty.version} - - 8888 - quit - - -Xbootclasspath/p:${settings.localRepository}/org/mortbay/jetty/alpn/alpn-boot/${alpn.version}/alpn-boot-${alpn.version}.jar - - ${basedir}/src/main/config/jetty.xml - - / - - - - - org.eclipse.jetty.http2 - http2-server - ${jetty.version} - - - org.eclipse.jetty - jetty-alpn-openjdk8-server - ${jetty.version} - - - org.eclipse.jetty - jetty-servlets - ${jetty.version} - - - - - - 3.6.2 4.5.3 9.4.27.v20200227 4.1.20.Final - 8.1.11.v20170118 8.5.24 4.3.1 1.2.0 diff --git a/pom.xml b/pom.xml index 2efea40c91..f797f1bbce 100644 --- a/pom.xml +++ b/pom.xml @@ -513,6 +513,7 @@ libraries-rpc libraries-security libraries-server + libraries-server-2 libraries-testing linkrest logging-modules @@ -1032,6 +1033,7 @@ libraries-primitive libraries-security libraries-server + libraries-server-2 libraries-testing linkrest logging-modules From dd5e1190fa445295e61b46d35f9fdf5f9b8e56ce Mon Sep 17 00:00:00 2001 From: Cristian Rosu Date: Tue, 2 Jun 2020 22:53:54 +0300 Subject: [PATCH 076/140] BAEL-4070: updated test names to match Baeldung's guidelines + makred test as Unit Test instead of Integration Test --- ...ionTest.java => ListsPropertiesUnitTest.java} | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) rename spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/lists/{ListsPropertiesIntegrationTest.java => ListsPropertiesUnitTest.java} (79%) diff --git a/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/lists/ListsPropertiesIntegrationTest.java b/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/lists/ListsPropertiesUnitTest.java similarity index 79% rename from spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/lists/ListsPropertiesIntegrationTest.java rename to spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/lists/ListsPropertiesUnitTest.java index 4047e1ea95..8c1835a0a9 100644 --- a/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/lists/ListsPropertiesIntegrationTest.java +++ b/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/lists/ListsPropertiesUnitTest.java @@ -16,7 +16,7 @@ import static org.junit.Assert.assertEquals; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = {SpringListPropertiesApplication.class}) -public class ListsPropertiesIntegrationTest { +public class ListsPropertiesUnitTest { @Value("${arrayOfStrings}") private String[] arrayOfStrings; @@ -46,39 +46,39 @@ public class ListsPropertiesIntegrationTest { private Environment environment; @Test - public void givenContextIsInitialized_ThenInjectedArrayContainsExpectedValues() { + public void whenContextIsInitialized_ThenInjectedArrayContainsExpectedValues() { assertEquals(arrayOfStrings, new String[] {"Baeldung", "dot", "com"}); } @Test - public void givenContextIsInitialized_ThenInjectedListContainsUnexpectedValues() { + public void whenContextIsInitialized_ThenInjectedListContainsUnexpectedValues() { assertEquals(unexpectedListOfStrings, Collections.singletonList("Baeldung,dot,com")); } @Test - public void givenContextIsInitialized_ThenInjectedListContainsExpectedValues() { + public void whenContextIsInitialized_ThenInjectedListContainsExpectedValues() { assertEquals(listOfStrings, Arrays.asList("Baeldung", "dot", "com")); } @Test - public void givenContextIsInitialized_ThenInjectedListV2ContainsExpectedValues() { + public void whenContextIsInitialized_ThenInjectedListV2ContainsExpectedValues() { assertEquals(listOfStringsV2, Arrays.asList("Baeldung", "dot", "com")); } @Test - public void givenContextIsInitialized_ThenInjectedListWithCustomDelimiterContainsExpectedValues() { + public void whenContextIsInitialized_ThenInjectedListWithCustomDelimiterContainsExpectedValues() { assertEquals(listOfStringsWithCustomDelimiter, Arrays.asList("Baeldung", "dot", "com")); } @Test - public void givenContextIsInitialized_ThenInjectedListOfBasicTypesContainsExpectedValues() { + public void whenContextIsInitialized_ThenInjectedListOfBasicTypesContainsExpectedValues() { assertEquals(listOfBooleans, Arrays.asList(false, false, true)); assertEquals(listOfIntegers, Arrays.asList(1, 2, 3, 4)); assertEquals(listOfCharacters, Arrays.asList('a', 'b', 'c')); } @Test - public void givenContextIsInitialized_WhenReadingFromEnvironment_ThenPropertiesHaveExpectedValues() { + public void WhenReadingFromSpringEnvironment_ThenPropertiesHaveExpectedValues() { String[] arrayOfStrings = environment.getProperty("arrayOfStrings", String[].class); List listOfStrings = (List)environment.getProperty("arrayOfStrings", List.class); From f0befa0f8b9d263dfc167b1eac30389c7ca04898 Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Wed, 3 Jun 2020 09:00:03 +0200 Subject: [PATCH 077/140] JAVA-1644: Remove overriden spring-boot.version property --- persistence-modules/spring-boot-persistence/pom.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/persistence-modules/spring-boot-persistence/pom.xml b/persistence-modules/spring-boot-persistence/pom.xml index c58e8dbf86..cc26ff58d5 100644 --- a/persistence-modules/spring-boot-persistence/pom.xml +++ b/persistence-modules/spring-boot-persistence/pom.xml @@ -77,7 +77,6 @@ UTF-8 2.23.0 2.0.1.Final - 2.1.7.RELEASE From 8623df615bd3b3cc9e660297d5f2018318aaedaf Mon Sep 17 00:00:00 2001 From: Anshul BANSAL Date: Wed, 3 Jun 2020 12:36:24 +0300 Subject: [PATCH 078/140] BAEL-4049 - removed cglib --- core-java-modules/core-java-jvm/pom.xml | 5 ----- .../com/baeldung/bytecode/ViewBytecodeUnitTest.java | 11 ++--------- 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/core-java-modules/core-java-jvm/pom.xml b/core-java-modules/core-java-jvm/pom.xml index f35efaa26b..0d6cc5c454 100644 --- a/core-java-modules/core-java-jvm/pom.xml +++ b/core-java-modules/core-java-jvm/pom.xml @@ -66,11 +66,6 @@ bcel 6.4.1 - - cglib - cglib - 3.3.0 - org.javassist javassist diff --git a/core-java-modules/core-java-jvm/src/test/java/com/baeldung/bytecode/ViewBytecodeUnitTest.java b/core-java-modules/core-java-jvm/src/test/java/com/baeldung/bytecode/ViewBytecodeUnitTest.java index 37ea6894c6..5b0fdf26d4 100644 --- a/core-java-modules/core-java-jvm/src/test/java/com/baeldung/bytecode/ViewBytecodeUnitTest.java +++ b/core-java-modules/core-java-jvm/src/test/java/com/baeldung/bytecode/ViewBytecodeUnitTest.java @@ -2,9 +2,11 @@ package com.baeldung.bytecode; import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertEquals; + import java.io.IOException; import java.io.PrintWriter; import java.io.StringWriter; + import org.apache.bcel.Repository; import org.apache.bcel.classfile.JavaClass; import org.junit.Test; @@ -13,7 +15,6 @@ import org.objectweb.asm.util.TraceClassVisitor; import javassist.ClassPool; import javassist.NotFoundException; import javassist.bytecode.ClassFile; -import net.sf.cglib.reflect.FastClass; public class ViewBytecodeUnitTest { @@ -36,14 +37,6 @@ public class ViewBytecodeUnitTest { assertTrue(objectClazz.toString().contains("public class java.lang.Object")); } - @Test - public void whenUsingCglib_thenReadBytecode() { - FastClass fastClass = FastClass.create(java.lang.Object.class); - Class clazz = fastClass.getJavaClass(); - - assertEquals(clazz.toString(), "class java.lang.Object"); - } - @Test public void whenUsingJavassist_thenReadBytecode() throws NotFoundException { ClassPool cp = ClassPool.getDefault(); From a2b1be69fea729630b42fe77a329db1f87e39ca6 Mon Sep 17 00:00:00 2001 From: Anshul BANSAL Date: Wed, 3 Jun 2020 12:40:32 +0300 Subject: [PATCH 079/140] BAEL-4049 - indentation fix --- core-java-modules/core-java-jvm/pom.xml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/core-java-modules/core-java-jvm/pom.xml b/core-java-modules/core-java-jvm/pom.xml index 0d6cc5c454..6663671579 100644 --- a/core-java-modules/core-java-jvm/pom.xml +++ b/core-java-modules/core-java-jvm/pom.xml @@ -52,9 +52,9 @@ ${java.home}/../lib/tools.jar - org.ow2.asm - asm - 8.0.1 + org.ow2.asm + asm + 8.0.1 org.ow2.asm @@ -67,9 +67,9 @@ 6.4.1 - org.javassist - javassist - 3.27.0-GA + org.javassist + javassist + 3.27.0-GA From 829140d488d33795b1c5b674cc4865f116391ba4 Mon Sep 17 00:00:00 2001 From: Ali Dehghani Date: Wed, 3 Jun 2020 14:10:58 +0430 Subject: [PATCH 080/140] Polluting the Heap --- .../varargs/HeapPollutionUnitTest.java | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 core-java-modules/core-java-lang-syntax/src/test/java/com/baeldung/varargs/HeapPollutionUnitTest.java diff --git a/core-java-modules/core-java-lang-syntax/src/test/java/com/baeldung/varargs/HeapPollutionUnitTest.java b/core-java-modules/core-java-lang-syntax/src/test/java/com/baeldung/varargs/HeapPollutionUnitTest.java new file mode 100644 index 0000000000..ced2c00bea --- /dev/null +++ b/core-java-modules/core-java-lang-syntax/src/test/java/com/baeldung/varargs/HeapPollutionUnitTest.java @@ -0,0 +1,40 @@ +package com.baeldung.varargs; + +import org.junit.Test; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import static org.junit.Assert.assertEquals; + +public class HeapPollutionUnitTest { + + @Test(expected = ClassCastException.class) + public void givenGenericVararg_whenUsedUnsafe_shouldThrowClassCastException() { + String one = firstOfFirst(Arrays.asList("one", "two"), Collections.emptyList()); + + assertEquals("one", one); + } + + @Test(expected = ClassCastException.class) + public void givenGenericVararg_whenRefEscapes_mayCauseSubtleBugs() { + String[] args = returnAsIs("One", "Two"); + } + + private static String firstOfFirst(List... strings) { + List ints = Collections.singletonList(42); + Object[] objects = strings; + objects[0] = ints; + + return strings[0].get(0); + } + + private static T[] toArray(T... arguments) { + return arguments; + } + + private static T[] returnAsIs(T a, T b) { + return toArray(a, b); + } +} From b9105d78911c9bf1a8c308d12e994b42a5f3e703 Mon Sep 17 00:00:00 2001 From: Anshul BANSAL Date: Wed, 3 Jun 2020 12:44:22 +0300 Subject: [PATCH 081/140] BAEL-4049 - indentation fix --- core-java-modules/core-java-jvm/pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core-java-modules/core-java-jvm/pom.xml b/core-java-modules/core-java-jvm/pom.xml index 6663671579..55290bd292 100644 --- a/core-java-modules/core-java-jvm/pom.xml +++ b/core-java-modules/core-java-jvm/pom.xml @@ -55,9 +55,9 @@ org.ow2.asm asm 8.0.1 - - - org.ow2.asm + + + org.ow2.asm asm-util 8.0.1 From bc40ab12d750c967060001e8a35302940209a3e8 Mon Sep 17 00:00:00 2001 From: Anshul BANSAL Date: Wed, 3 Jun 2020 12:46:28 +0300 Subject: [PATCH 082/140] BAEL-4049 - indentation --- core-java-modules/core-java-jvm/pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core-java-modules/core-java-jvm/pom.xml b/core-java-modules/core-java-jvm/pom.xml index 55290bd292..a2c35c154c 100644 --- a/core-java-modules/core-java-jvm/pom.xml +++ b/core-java-modules/core-java-jvm/pom.xml @@ -58,9 +58,9 @@ org.ow2.asm - asm-util - 8.0.1 - + asm-util + 8.0.1 + org.apache.bcel bcel From 078481781f3a45c175a5024bebd9e5705cd294ce Mon Sep 17 00:00:00 2001 From: Yavuz Tas <12643010+yavuztas@users.noreply.github.com> Date: Wed, 3 Jun 2020 14:59:42 +0200 Subject: [PATCH 083/140] Module for BAEL-3280 (#9329) * Module for BAEL-3280 * update comment to make it more clear * remove .gitignore file * remove name tag * fix typo * change module name to a generic one * add module to parent --- spring-boot-modules/pom.xml | 1 + .../.mvn/wrapper/maven-wrapper.properties | 1 + spring-boot-modules/spring-boot-1/README.md | 6 + spring-boot-modules/spring-boot-1/mvnw | 234 ++++++++++++++++++ spring-boot-modules/spring-boot-1/mvnw.cmd | 143 +++++++++++ spring-boot-modules/spring-boot-1/pom.xml | 45 ++++ .../com/baeldung/actuator/CustomEndpoint.java | 35 +++ .../com/baeldung/actuator/HealthCheck.java | 23 ++ .../baeldung/actuator/LoginServiceImpl.java | 28 +++ .../com/baeldung/actuator/SpringBoot.java | 13 + .../src/main/resources/application.properties | 19 ++ .../CustomEndpointIntegrationTest.java | 46 ++++ .../actuator/HealthCheckIntegrationTest.java | 49 ++++ .../actuator/HealthCheckUnitTest.java | 35 +++ .../actuator/LoginServiceIntegrationTest.java | 61 +++++ .../actuator/LoginServiceUnitTest.java | 41 +++ 16 files changed, 780 insertions(+) create mode 100644 spring-boot-modules/spring-boot-1/.mvn/wrapper/maven-wrapper.properties create mode 100644 spring-boot-modules/spring-boot-1/README.md create mode 100755 spring-boot-modules/spring-boot-1/mvnw create mode 100644 spring-boot-modules/spring-boot-1/mvnw.cmd create mode 100644 spring-boot-modules/spring-boot-1/pom.xml create mode 100644 spring-boot-modules/spring-boot-1/src/main/java/com/baeldung/actuator/CustomEndpoint.java create mode 100644 spring-boot-modules/spring-boot-1/src/main/java/com/baeldung/actuator/HealthCheck.java create mode 100644 spring-boot-modules/spring-boot-1/src/main/java/com/baeldung/actuator/LoginServiceImpl.java create mode 100644 spring-boot-modules/spring-boot-1/src/main/java/com/baeldung/actuator/SpringBoot.java create mode 100644 spring-boot-modules/spring-boot-1/src/main/resources/application.properties create mode 100644 spring-boot-modules/spring-boot-1/src/test/java/com/baeldung/actuator/CustomEndpointIntegrationTest.java create mode 100644 spring-boot-modules/spring-boot-1/src/test/java/com/baeldung/actuator/HealthCheckIntegrationTest.java create mode 100644 spring-boot-modules/spring-boot-1/src/test/java/com/baeldung/actuator/HealthCheckUnitTest.java create mode 100644 spring-boot-modules/spring-boot-1/src/test/java/com/baeldung/actuator/LoginServiceIntegrationTest.java create mode 100644 spring-boot-modules/spring-boot-1/src/test/java/com/baeldung/actuator/LoginServiceUnitTest.java diff --git a/spring-boot-modules/pom.xml b/spring-boot-modules/pom.xml index 6caa93158a..7992c0ce12 100644 --- a/spring-boot-modules/pom.xml +++ b/spring-boot-modules/pom.xml @@ -15,6 +15,7 @@ spring-boot + spring-boot-1 spring-boot-admin spring-boot-angular spring-boot-annotations diff --git a/spring-boot-modules/spring-boot-1/.mvn/wrapper/maven-wrapper.properties b/spring-boot-modules/spring-boot-1/.mvn/wrapper/maven-wrapper.properties new file mode 100644 index 0000000000..9dda3b659b --- /dev/null +++ b/spring-boot-modules/spring-boot-1/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1 @@ +distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.2/apache-maven-3.5.2-bin.zip diff --git a/spring-boot-modules/spring-boot-1/README.md b/spring-boot-modules/spring-boot-1/README.md new file mode 100644 index 0000000000..a818f60fb5 --- /dev/null +++ b/spring-boot-modules/spring-boot-1/README.md @@ -0,0 +1,6 @@ +## Spring Boot 1.x Actuator + +This module contains articles about Spring Boot Actuator in Spring Boot version 1.x. + +## Relevant articles: +- [Spring Boot Actuator](https://www.baeldung.com/spring-boot-actuators) diff --git a/spring-boot-modules/spring-boot-1/mvnw b/spring-boot-modules/spring-boot-1/mvnw new file mode 100755 index 0000000000..b74391fdf4 --- /dev/null +++ b/spring-boot-modules/spring-boot-1/mvnw @@ -0,0 +1,234 @@ +#!/bin/sh +# ---------------------------------------------------------------------------- +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Maven2 Start Up Batch script +# +# Required ENV vars: +# ------------------ +# JAVA_HOME - location of a JDK home dir +# +# Optional ENV vars +# ----------------- +# M2_HOME - location of maven2's installed home dir +# MAVEN_OPTS - parameters passed to the Java VM when running Maven +# e.g. to debug Maven itself, use +# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +# MAVEN_SKIP_RC - flag to disable loading of mavenrc files +# ---------------------------------------------------------------------------- + +if [ -z "$MAVEN_SKIP_RC" ]; then + + if [ -f /etc/mavenrc ]; then + . /etc/mavenrc + fi + + if [ -f "$HOME/.mavenrc" ]; then + . "$HOME/.mavenrc" + fi + +fi + +# OS specific support. $var _must_ be set to either true or false. +cygwin=false +darwin=false +mingw=false +case "$(uname)" in +CYGWIN*) cygwin=true ;; +MINGW*) mingw=true ;; +Darwin*) + darwin=true + # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home + # See https://developer.apple.com/library/mac/qa/qa1170/_index.html + if [ -z "$JAVA_HOME" ]; then + if [ -x "/usr/libexec/java_home" ]; then + export JAVA_HOME="$(/usr/libexec/java_home)" + else + export JAVA_HOME="/Library/Java/Home" + fi + fi + ;; +esac + +if [ -z "$JAVA_HOME" ]; then + if [ -r /etc/gentoo-release ]; then + JAVA_HOME=$(java-config --jre-home) + fi +fi + +if [ -z "$M2_HOME" ]; then + ## resolve links - $0 may be a link to maven's home + PRG="$0" + + # need this for relative symlinks + while [ -h "$PRG" ]; do + ls=$(ls -ld "$PRG") + link=$(expr "$ls" : '.*-> \(.*\)$') + if expr "$link" : '/.*' >/dev/null; then + PRG="$link" + else + PRG="$(dirname "$PRG")/$link" + fi + done + + saveddir=$(pwd) + + M2_HOME=$(dirname "$PRG")/.. + + # make it fully qualified + M2_HOME=$(cd "$M2_HOME" && pwd) + + cd "$saveddir" + # echo Using m2 at $M2_HOME +fi + +# For Cygwin, ensure paths are in UNIX format before anything is touched +if $cygwin; then + [ -n "$M2_HOME" ] && + M2_HOME=$(cygpath --unix "$M2_HOME") + [ -n "$JAVA_HOME" ] && + JAVA_HOME=$(cygpath --unix "$JAVA_HOME") + [ -n "$CLASSPATH" ] && + CLASSPATH=$(cygpath --path --unix "$CLASSPATH") +fi + +# For Migwn, ensure paths are in UNIX format before anything is touched +if $mingw; then + [ -n "$M2_HOME" ] && + M2_HOME="$( ( + cd "$M2_HOME" + pwd + ))" + [ -n "$JAVA_HOME" ] && + JAVA_HOME="$( ( + cd "$JAVA_HOME" + pwd + ))" + # TODO classpath? +fi + +if [ -z "$JAVA_HOME" ]; then + javaExecutable="$(which javac)" + if [ -n "$javaExecutable" ] && ! [ "$(expr \"$javaExecutable\" : '\([^ ]*\)')" = "no" ]; then + # readlink(1) is not available as standard on Solaris 10. + readLink=$(which readlink) + if [ ! $(expr "$readLink" : '\([^ ]*\)') = "no" ]; then + if $darwin; then + javaHome="$(dirname \"$javaExecutable\")" + javaExecutable="$(cd \"$javaHome\" && pwd -P)/javac" + else + javaExecutable="$(readlink -f \"$javaExecutable\")" + fi + javaHome="$(dirname \"$javaExecutable\")" + javaHome=$(expr "$javaHome" : '\(.*\)/bin') + JAVA_HOME="$javaHome" + export JAVA_HOME + fi + fi +fi + +if [ -z "$JAVACMD" ]; then + if [ -n "$JAVA_HOME" ]; then + if [ -x "$JAVA_HOME/jre/sh/java" ]; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + else + JAVACMD="$(which java)" + fi +fi + +if [ ! -x "$JAVACMD" ]; then + echo "Error: JAVA_HOME is not defined correctly." >&2 + echo " We cannot execute $JAVACMD" >&2 + exit 1 +fi + +if [ -z "$JAVA_HOME" ]; then + echo "Warning: JAVA_HOME environment variable is not set." +fi + +CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher + +# traverses directory structure from process work directory to filesystem root +# first directory with .mvn subdirectory is considered project base directory +find_maven_basedir() { + + if [ -z "$1" ]; then + echo "Path not specified to find_maven_basedir" + return 1 + fi + + basedir="$1" + wdir="$1" + while [ "$wdir" != '/' ]; do + if [ -d "$wdir"/.mvn ]; then + basedir=$wdir + break + fi + # workaround for JBEAP-8937 (on Solaris 10/Sparc) + if [ -d "${wdir}" ]; then + wdir=$( + cd "$wdir/.." + pwd + ) + fi + # end of workaround + done + echo "${basedir}" +} + +# concatenates all lines of a file +concat_lines() { + if [ -f "$1" ]; then + echo "$(tr -s '\n' ' ' <"$1")" + fi +} + +BASE_DIR=$(find_maven_basedir "$(pwd)") +if [ -z "$BASE_DIR" ]; then + exit 1 +fi + +export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} +echo $MAVEN_PROJECTBASEDIR +MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" + +# For Cygwin, switch paths to Windows format before running java +if $cygwin; then + [ -n "$M2_HOME" ] && + M2_HOME=$(cygpath --path --windows "$M2_HOME") + [ -n "$JAVA_HOME" ] && + JAVA_HOME=$(cygpath --path --windows "$JAVA_HOME") + [ -n "$CLASSPATH" ] && + CLASSPATH=$(cygpath --path --windows "$CLASSPATH") + [ -n "$MAVEN_PROJECTBASEDIR" ] && + MAVEN_PROJECTBASEDIR=$(cygpath --path --windows "$MAVEN_PROJECTBASEDIR") +fi + +WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +exec "$JAVACMD" \ + $MAVEN_OPTS \ + -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ + "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ + ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/spring-boot-modules/spring-boot-1/mvnw.cmd b/spring-boot-modules/spring-boot-1/mvnw.cmd new file mode 100644 index 0000000000..019bd74d76 --- /dev/null +++ b/spring-boot-modules/spring-boot-1/mvnw.cmd @@ -0,0 +1,143 @@ +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM http://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Maven2 Start Up Batch script +@REM +@REM Required ENV vars: +@REM JAVA_HOME - location of a JDK home dir +@REM +@REM Optional ENV vars +@REM M2_HOME - location of maven2's installed home dir +@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands +@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending +@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven +@REM e.g. to debug Maven itself, use +@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files +@REM ---------------------------------------------------------------------------- + +@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' +@echo off +@REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' +@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% + +@REM set %HOME% to equivalent of $HOME +if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") + +@REM Execute a user defined script before this one +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre +@REM check for pre script, once with legacy .bat ending and once with .cmd ending +if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" +if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" +:skipRcPre + +@setlocal + +set ERROR_CODE=0 + +@REM To isolate internal variables from possible post scripts, we use another setlocal +@setlocal + +@REM ==== START VALIDATION ==== +if not "%JAVA_HOME%" == "" goto OkJHome + +echo. +echo Error: JAVA_HOME not found in your environment. >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +:OkJHome +if exist "%JAVA_HOME%\bin\java.exe" goto init + +echo. +echo Error: JAVA_HOME is set to an invalid directory. >&2 +echo JAVA_HOME = "%JAVA_HOME%" >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +@REM ==== END VALIDATION ==== + +:init + +@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". +@REM Fallback to current working directory if not found. + +set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% +IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir + +set EXEC_DIR=%CD% +set WDIR=%EXEC_DIR% +:findBaseDir +IF EXIST "%WDIR%"\.mvn goto baseDirFound +cd .. +IF "%WDIR%"=="%CD%" goto baseDirNotFound +set WDIR=%CD% +goto findBaseDir + +:baseDirFound +set MAVEN_PROJECTBASEDIR=%WDIR% +cd "%EXEC_DIR%" +goto endDetectBaseDir + +:baseDirNotFound +set MAVEN_PROJECTBASEDIR=%EXEC_DIR% +cd "%EXEC_DIR%" + +:endDetectBaseDir + +IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig + +@setlocal EnableExtensions EnableDelayedExpansion +for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a +@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% + +:endReadAdditionalConfig + +SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" + +set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" +set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* +if ERRORLEVEL 1 goto error +goto end + +:error +set ERROR_CODE=1 + +:end +@endlocal & set ERROR_CODE=%ERROR_CODE% + +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost +@REM check for post script, once with legacy .bat ending and once with .cmd ending +if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" +if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" +:skipRcPost + +@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' +if "%MAVEN_BATCH_PAUSE%" == "on" pause + +if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% + +exit /B %ERROR_CODE% diff --git a/spring-boot-modules/spring-boot-1/pom.xml b/spring-boot-modules/spring-boot-1/pom.xml new file mode 100644 index 0000000000..145bb221e0 --- /dev/null +++ b/spring-boot-modules/spring-boot-1/pom.xml @@ -0,0 +1,45 @@ + + + 4.0.0 + spring-boot-1 + jar + Module for Spring Boot version 1.x + + + com.baeldung + parent-boot-1 + 0.0.1-SNAPSHOT + ../../parent-boot-1 + + + + + org.springframework.boot + spring-boot-starter + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-actuator + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + diff --git a/spring-boot-modules/spring-boot-1/src/main/java/com/baeldung/actuator/CustomEndpoint.java b/spring-boot-modules/spring-boot-1/src/main/java/com/baeldung/actuator/CustomEndpoint.java new file mode 100644 index 0000000000..f48fc87640 --- /dev/null +++ b/spring-boot-modules/spring-boot-1/src/main/java/com/baeldung/actuator/CustomEndpoint.java @@ -0,0 +1,35 @@ +package com.baeldung.actuator; + +import org.springframework.boot.actuate.endpoint.Endpoint; +import org.springframework.stereotype.Component; + +import java.util.ArrayList; +import java.util.List; + +@Component +public class CustomEndpoint implements Endpoint> { + + @Override + public String getId() { + return "customEndpoint"; + } + + @Override + public boolean isEnabled() { + return true; + } + + @Override + public boolean isSensitive() { + return true; + } + + @Override + public List invoke() { + // Custom logic to build the output + List messages = new ArrayList<>(); + messages.add("This is message 1"); + messages.add("This is message 2"); + return messages; + } +} \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-1/src/main/java/com/baeldung/actuator/HealthCheck.java b/spring-boot-modules/spring-boot-1/src/main/java/com/baeldung/actuator/HealthCheck.java new file mode 100644 index 0000000000..45db408465 --- /dev/null +++ b/spring-boot-modules/spring-boot-1/src/main/java/com/baeldung/actuator/HealthCheck.java @@ -0,0 +1,23 @@ +package com.baeldung.actuator; + +import org.springframework.boot.actuate.health.Health; +import org.springframework.boot.actuate.health.HealthIndicator; +import org.springframework.stereotype.Component; + +@Component("myHealthCheck") +public class HealthCheck implements HealthIndicator { + + @Override + public Health health() { + int errorCode = check(); // perform some specific health check + if (errorCode != 0) { + return Health.down().withDetail("Error Code", errorCode).build(); + } + return Health.up().build(); + } + + public int check() { + // Our logic to check health + return 0; + } +} \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-1/src/main/java/com/baeldung/actuator/LoginServiceImpl.java b/spring-boot-modules/spring-boot-1/src/main/java/com/baeldung/actuator/LoginServiceImpl.java new file mode 100644 index 0000000000..925ce69a39 --- /dev/null +++ b/spring-boot-modules/spring-boot-1/src/main/java/com/baeldung/actuator/LoginServiceImpl.java @@ -0,0 +1,28 @@ +package com.baeldung.actuator; + +import org.springframework.boot.actuate.metrics.CounterService; +import org.springframework.stereotype.Service; + +import java.util.Arrays; + +@Service +public class LoginServiceImpl { + + private final CounterService counterService; + + public LoginServiceImpl(CounterService counterService) { + this.counterService = counterService; + } + + public boolean login(String userName, char[] password) { + boolean success; + if (userName.equals("admin") && Arrays.equals("secret".toCharArray(), password)) { + counterService.increment("counter.login.success"); + success = true; + } else { + counterService.increment("counter.login.failure"); + success = false; + } + return success; + } +} \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-1/src/main/java/com/baeldung/actuator/SpringBoot.java b/spring-boot-modules/spring-boot-1/src/main/java/com/baeldung/actuator/SpringBoot.java new file mode 100644 index 0000000000..bdf28e49cb --- /dev/null +++ b/spring-boot-modules/spring-boot-1/src/main/java/com/baeldung/actuator/SpringBoot.java @@ -0,0 +1,13 @@ +package com.baeldung.actuator; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SpringBoot { + + public static void main(String[] args) { + SpringApplication.run(SpringBoot.class, args); + } + +} diff --git a/spring-boot-modules/spring-boot-1/src/main/resources/application.properties b/spring-boot-modules/spring-boot-1/src/main/resources/application.properties new file mode 100644 index 0000000000..ac095e1cab --- /dev/null +++ b/spring-boot-modules/spring-boot-1/src/main/resources/application.properties @@ -0,0 +1,19 @@ +### server port +server.port=8080 +#port used to expose actuator +management.port=8081 +#CIDR allowed to hit actuator +management.address=127.0.0.1 +# Actuator Configuration +# customize /beans endpoint +endpoints.beans.id=springbeans +endpoints.beans.sensitive=false +endpoints.beans.enabled=true +# for the Spring Boot version 1.5.0 and above, we have to disable security to expose the health endpoint fully for unauthorized access. +# see: https://docs.spring.io/spring-boot/docs/1.5.x/reference/html/production-ready-monitoring.html +management.security.enabled=false +endpoints.health.sensitive=false +# customize /info endpoint +info.app.name=Spring Sample Application +info.app.description=This is my first spring boot application +info.app.version=1.0.0 \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-1/src/test/java/com/baeldung/actuator/CustomEndpointIntegrationTest.java b/spring-boot-modules/spring-boot-1/src/test/java/com/baeldung/actuator/CustomEndpointIntegrationTest.java new file mode 100644 index 0000000000..663e6055c7 --- /dev/null +++ b/spring-boot-modules/spring-boot-1/src/test/java/com/baeldung/actuator/CustomEndpointIntegrationTest.java @@ -0,0 +1,46 @@ +package com.baeldung.actuator; + +import com.fasterxml.jackson.core.type.TypeReference; +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.actuate.autoconfigure.LocalManagementPort; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.web.client.RestTemplate; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import static org.hamcrest.CoreMatchers.hasItems; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; + +@RunWith(SpringRunner.class) +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, properties = "management.port=0") +public class CustomEndpointIntegrationTest { + + @LocalManagementPort + private int port; + + private RestTemplate restTemplate = new RestTemplate(); + + @Autowired + private ObjectMapper objectMapper; + + @Test + public void whenSpringContextIsBootstrapped_thenActuatorCustomEndpointWorks() throws IOException { + ResponseEntity entity = restTemplate.getForEntity("http://localhost:" + port + "/customEndpoint", String.class); + + assertThat(entity.getStatusCode(), is(HttpStatus.OK)); + + List response = objectMapper.readValue(entity.getBody(), new TypeReference>() { + }); + + assertThat(response, hasItems("This is message 1", "This is message 2")); + } +} diff --git a/spring-boot-modules/spring-boot-1/src/test/java/com/baeldung/actuator/HealthCheckIntegrationTest.java b/spring-boot-modules/spring-boot-1/src/test/java/com/baeldung/actuator/HealthCheckIntegrationTest.java new file mode 100644 index 0000000000..f80e2745a0 --- /dev/null +++ b/spring-boot-modules/spring-boot-1/src/test/java/com/baeldung/actuator/HealthCheckIntegrationTest.java @@ -0,0 +1,49 @@ +package com.baeldung.actuator; + +import com.fasterxml.jackson.core.type.TypeReference; +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.actuate.autoconfigure.LocalManagementPort; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.web.client.RestTemplate; + +import java.io.IOException; +import java.util.LinkedHashMap; +import java.util.Map; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.collection.IsMapContaining.hasEntry; +import static org.hamcrest.collection.IsMapContaining.hasKey; + +@RunWith(SpringRunner.class) +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, properties = "management.port=0") +public class HealthCheckIntegrationTest { + + @LocalManagementPort + private int port; + + private RestTemplate restTemplate = new RestTemplate(); + + @Autowired + private ObjectMapper objectMapper; + + @Test + public void whenSpringContextIsBootstrapped_thenActuatorHealthEndpointWorks() throws IOException { + ResponseEntity entity = restTemplate.getForEntity("http://localhost:" + port + "/health", String.class); + + assertThat(entity.getStatusCode(), is(HttpStatus.OK)); + + Map response = objectMapper.readValue(entity.getBody(), new TypeReference>() { + }); + + assertThat(response, hasEntry("status", "UP")); + assertThat(response, hasKey("myHealthCheck")); + assertThat(response, hasKey("diskSpace")); + } +} diff --git a/spring-boot-modules/spring-boot-1/src/test/java/com/baeldung/actuator/HealthCheckUnitTest.java b/spring-boot-modules/spring-boot-1/src/test/java/com/baeldung/actuator/HealthCheckUnitTest.java new file mode 100644 index 0000000000..a464e51b1f --- /dev/null +++ b/spring-boot-modules/spring-boot-1/src/test/java/com/baeldung/actuator/HealthCheckUnitTest.java @@ -0,0 +1,35 @@ +package com.baeldung.actuator; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; +import org.springframework.boot.actuate.health.Health; +import org.springframework.boot.actuate.health.Status; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.mockito.Mockito.when; + +@RunWith(MockitoJUnitRunner.class) +public class HealthCheckUnitTest { + + @Test + public void whenCheckMethodReturnsZero_thenHealthMethodReturnsStatusUP() { + HealthCheck healthCheck = Mockito.spy(new HealthCheck()); + when(healthCheck.check()).thenReturn(0); + Health health = healthCheck.health(); + + assertThat(health.getStatus(), is(Status.UP)); + } + + @Test + public void whenCheckMethodReturnsOtherThanZero_thenHealthMethodReturnsStatusDOWN() { + HealthCheck healthCheck = Mockito.spy(new HealthCheck()); + when(healthCheck.check()).thenReturn(-1); + Health health = healthCheck.health(); + + assertThat(health.getStatus(), is(Status.DOWN)); + } + +} diff --git a/spring-boot-modules/spring-boot-1/src/test/java/com/baeldung/actuator/LoginServiceIntegrationTest.java b/spring-boot-modules/spring-boot-1/src/test/java/com/baeldung/actuator/LoginServiceIntegrationTest.java new file mode 100644 index 0000000000..851de81d7f --- /dev/null +++ b/spring-boot-modules/spring-boot-1/src/test/java/com/baeldung/actuator/LoginServiceIntegrationTest.java @@ -0,0 +1,61 @@ +package com.baeldung.actuator; + +import com.fasterxml.jackson.core.type.TypeReference; +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.actuate.autoconfigure.LocalManagementPort; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.web.client.RestTemplate; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.hasEntry; + +@RunWith(SpringRunner.class) +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, properties = "management.port=0") +public class LoginServiceIntegrationTest { + + @LocalManagementPort + private int port; + + @Autowired + private LoginServiceImpl loginService; + + private RestTemplate restTemplate = new RestTemplate(); + + @Autowired + private ObjectMapper objectMapper; + + @Test + public void whenLoginIsAdmin_thenSuccessCounterIsIncremented() throws IOException { + boolean success = loginService.login("admin", "secret".toCharArray()); + ResponseEntity entity = restTemplate.getForEntity("http://localhost:" + port + "/metrics", String.class); + Map response = objectMapper.readValue(entity.getBody(), new TypeReference>() { + }); + + assertThat(success, is(true)); + assertThat(entity.getStatusCode(), is(HttpStatus.OK)); + assertThat(response, hasEntry("counter.login.success", 1)); + } + + @Test + public void whenLoginIsNotAdmin_thenFailureCounterIsIncremented() throws IOException { + boolean success = loginService.login("user", "notsecret".toCharArray()); + ResponseEntity entity = restTemplate.getForEntity("http://localhost:" + port + "/metrics", String.class); + Map response = objectMapper.readValue(entity.getBody(), new TypeReference>() { + }); + + assertThat(success, is(false)); + assertThat(entity.getStatusCode(), is(HttpStatus.OK)); + assertThat(response, hasEntry("counter.login.failure", 1)); + } +} diff --git a/spring-boot-modules/spring-boot-1/src/test/java/com/baeldung/actuator/LoginServiceUnitTest.java b/spring-boot-modules/spring-boot-1/src/test/java/com/baeldung/actuator/LoginServiceUnitTest.java new file mode 100644 index 0000000000..489d005782 --- /dev/null +++ b/spring-boot-modules/spring-boot-1/src/test/java/com/baeldung/actuator/LoginServiceUnitTest.java @@ -0,0 +1,41 @@ +package com.baeldung.actuator; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.actuate.metrics.CounterService; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.test.context.junit4.SpringRunner; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = LoginServiceImpl.class) +public class LoginServiceUnitTest { + + @MockBean + CounterService counterService; + + @Autowired + LoginServiceImpl loginService; + + @Test + public void whenLoginUserIsAdmin_thenSuccessCounterIsIncremented() { + boolean loginResult = loginService.login("admin", "secret".toCharArray()); + assertThat(loginResult, is(true)); + verify(counterService, times(1)).increment("counter.login.success"); + } + + @Test + public void whenLoginUserIsNotAdmin_thenFailureCounterIsIncremented() { + boolean loginResult = loginService.login("user", "notsecret".toCharArray()); + assertThat(loginResult, is(false)); + verify(counterService, times(1)).increment("counter.login.failure"); + } + +} From 6df3b2b6fb708428537f54d72baa9eba9543bcb8 Mon Sep 17 00:00:00 2001 From: Eduard Ardeleanu Date: Wed, 3 Jun 2020 16:04:45 +0300 Subject: [PATCH 084/140] BAEL-4026: Spring Cloud Open Service Broker (#9365) * BAEL-4026: Spring Cloud Open Service Broker * add unit tests * fix review comments --- spring-cloud/pom.xml | 1 + .../README.md | 1 + .../spring-cloud-open-service-broker/pom.xml | 41 ++++ .../ServiceBrokerApplication.java | 13 ++ .../config/CatalogConfiguration.java | 34 +++ .../mail/MailController.java | 19 ++ .../openservicebroker/mail/MailService.java | 95 +++++++++ .../mail/MailServiceBinding.java | 22 ++ .../mail/MailServiceInstance.java | 32 +++ .../MailServiceInstanceBindingService.java | 77 +++++++ .../services/MailServiceInstanceService.java | 72 +++++++ .../src/main/resources/application.yml | 10 + ...ServiceInstanceBindingServiceUnitTest.java | 201 ++++++++++++++++++ .../MailServiceInstanceServiceUnitTest.java | 166 +++++++++++++++ 14 files changed, 784 insertions(+) create mode 100644 spring-cloud/spring-cloud-open-service-broker/README.md create mode 100644 spring-cloud/spring-cloud-open-service-broker/pom.xml create mode 100644 spring-cloud/spring-cloud-open-service-broker/src/main/java/com/baeldung/spring/cloud/openservicebroker/ServiceBrokerApplication.java create mode 100644 spring-cloud/spring-cloud-open-service-broker/src/main/java/com/baeldung/spring/cloud/openservicebroker/config/CatalogConfiguration.java create mode 100644 spring-cloud/spring-cloud-open-service-broker/src/main/java/com/baeldung/spring/cloud/openservicebroker/mail/MailController.java create mode 100644 spring-cloud/spring-cloud-open-service-broker/src/main/java/com/baeldung/spring/cloud/openservicebroker/mail/MailService.java create mode 100644 spring-cloud/spring-cloud-open-service-broker/src/main/java/com/baeldung/spring/cloud/openservicebroker/mail/MailServiceBinding.java create mode 100644 spring-cloud/spring-cloud-open-service-broker/src/main/java/com/baeldung/spring/cloud/openservicebroker/mail/MailServiceInstance.java create mode 100644 spring-cloud/spring-cloud-open-service-broker/src/main/java/com/baeldung/spring/cloud/openservicebroker/services/MailServiceInstanceBindingService.java create mode 100644 spring-cloud/spring-cloud-open-service-broker/src/main/java/com/baeldung/spring/cloud/openservicebroker/services/MailServiceInstanceService.java create mode 100644 spring-cloud/spring-cloud-open-service-broker/src/main/resources/application.yml create mode 100644 spring-cloud/spring-cloud-open-service-broker/src/test/java/com/baeldung/spring/cloud/openservicebroker/services/MailServiceInstanceBindingServiceUnitTest.java create mode 100644 spring-cloud/spring-cloud-open-service-broker/src/test/java/com/baeldung/spring/cloud/openservicebroker/services/MailServiceInstanceServiceUnitTest.java diff --git a/spring-cloud/pom.xml b/spring-cloud/pom.xml index c4e606e190..3de527c33b 100644 --- a/spring-cloud/pom.xml +++ b/spring-cloud/pom.xml @@ -32,6 +32,7 @@ spring-cloud-zuul-eureka-integration spring-cloud-contract spring-cloud-kubernetes + spring-cloud-open-service-broker spring-cloud-archaius spring-cloud-functions spring-cloud-vault diff --git a/spring-cloud/spring-cloud-open-service-broker/README.md b/spring-cloud/spring-cloud-open-service-broker/README.md new file mode 100644 index 0000000000..f09469076b --- /dev/null +++ b/spring-cloud/spring-cloud-open-service-broker/README.md @@ -0,0 +1 @@ +### Relevant Articles: diff --git a/spring-cloud/spring-cloud-open-service-broker/pom.xml b/spring-cloud/spring-cloud-open-service-broker/pom.xml new file mode 100644 index 0000000000..7acd302dc1 --- /dev/null +++ b/spring-cloud/spring-cloud-open-service-broker/pom.xml @@ -0,0 +1,41 @@ + + + 4.0.0 + com.baeldung + spring-cloud-open-service-broker + jar + + + com.baeldung.spring.cloud + spring-cloud + 1.0.0-SNAPSHOT + + + + 3.1.1.RELEASE + 2.2.7.RELEASE + 3.3.5.RELEASE + + + + + org.springframework.cloud + spring-cloud-starter-open-service-broker + ${spring-cloud-starter-open-service-broker.version} + + + org.springframework.boot + spring-boot-starter-web + ${spring-boot-starter-web.version} + + + io.projectreactor + reactor-test + ${reactor-test.version} + test + + + + diff --git a/spring-cloud/spring-cloud-open-service-broker/src/main/java/com/baeldung/spring/cloud/openservicebroker/ServiceBrokerApplication.java b/spring-cloud/spring-cloud-open-service-broker/src/main/java/com/baeldung/spring/cloud/openservicebroker/ServiceBrokerApplication.java new file mode 100644 index 0000000000..2dbb4bc546 --- /dev/null +++ b/spring-cloud/spring-cloud-open-service-broker/src/main/java/com/baeldung/spring/cloud/openservicebroker/ServiceBrokerApplication.java @@ -0,0 +1,13 @@ +package com.baeldung.spring.cloud.openservicebroker; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class ServiceBrokerApplication { + + public static void main(String[] args) { + SpringApplication.run(ServiceBrokerApplication.class, args); + } + +} diff --git a/spring-cloud/spring-cloud-open-service-broker/src/main/java/com/baeldung/spring/cloud/openservicebroker/config/CatalogConfiguration.java b/spring-cloud/spring-cloud-open-service-broker/src/main/java/com/baeldung/spring/cloud/openservicebroker/config/CatalogConfiguration.java new file mode 100644 index 0000000000..e9e9452785 --- /dev/null +++ b/spring-cloud/spring-cloud-open-service-broker/src/main/java/com/baeldung/spring/cloud/openservicebroker/config/CatalogConfiguration.java @@ -0,0 +1,34 @@ +package com.baeldung.spring.cloud.openservicebroker.config; + +import org.springframework.cloud.servicebroker.model.catalog.Catalog; +import org.springframework.cloud.servicebroker.model.catalog.Plan; +import org.springframework.cloud.servicebroker.model.catalog.ServiceDefinition; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class CatalogConfiguration { + + @Bean + public Catalog catalog() { + Plan mailFreePlan = Plan.builder() + .id("fd81196c-a414-43e5-bd81-1dbb082a3c55") + .name("mail-free-plan") + .description("Mail Service Free Plan") + .free(true) + .build(); + + ServiceDefinition serviceDefinition = ServiceDefinition.builder() + .id("b92c0ca7-c162-4029-b567-0d92978c0a97") + .name("mail-service") + .description("Mail Service") + .bindable(true) + .tags("mail", "service") + .plans(mailFreePlan) + .build(); + + return Catalog.builder() + .serviceDefinitions(serviceDefinition) + .build(); + } +} diff --git a/spring-cloud/spring-cloud-open-service-broker/src/main/java/com/baeldung/spring/cloud/openservicebroker/mail/MailController.java b/spring-cloud/spring-cloud-open-service-broker/src/main/java/com/baeldung/spring/cloud/openservicebroker/mail/MailController.java new file mode 100644 index 0000000000..e0c0b36428 --- /dev/null +++ b/spring-cloud/spring-cloud-open-service-broker/src/main/java/com/baeldung/spring/cloud/openservicebroker/mail/MailController.java @@ -0,0 +1,19 @@ +package com.baeldung.spring.cloud.openservicebroker.mail; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class MailController { + + @GetMapping("/mail-dashboard/{mailSystemId}") + public String dashboard(@PathVariable("mailSystemId") String mailSystemId) { + return "Mail Dashboard - " + mailSystemId; + } + + @GetMapping("/mail-system/{mailSystemId}") + public String mailSystem(@PathVariable("mailSystemId") String mailSystemId) { + return "Mail System - " + mailSystemId; + } +} diff --git a/spring-cloud/spring-cloud-open-service-broker/src/main/java/com/baeldung/spring/cloud/openservicebroker/mail/MailService.java b/spring-cloud/spring-cloud-open-service-broker/src/main/java/com/baeldung/spring/cloud/openservicebroker/mail/MailService.java new file mode 100644 index 0000000000..07b7ad9a38 --- /dev/null +++ b/spring-cloud/spring-cloud-open-service-broker/src/main/java/com/baeldung/spring/cloud/openservicebroker/mail/MailService.java @@ -0,0 +1,95 @@ +package com.baeldung.spring.cloud.openservicebroker.mail; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; +import reactor.core.publisher.Mono; + +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +@Service +public class MailService { + + public static final String URI_KEY = "uri"; + public static final String USERNAME_KEY = "username"; + public static final String PASSWORD_KEY = "password"; + + private final String mailDashboardBaseURL; + private final String mailSystemBaseURL; + + private Map mailServices = new HashMap<>(); + + private Map mailServiceBindings = new HashMap<>(); + + public MailService(@Value("${mail.system.dashboard.base-url}") String mailDashboardBaseURL, + @Value("${mail.system.base-url}") String mailSystemBaseURL) { + this.mailDashboardBaseURL = mailDashboardBaseURL; + this.mailSystemBaseURL = mailSystemBaseURL; + } + + public Mono createServiceInstance(String instanceId, String serviceDefinitionId, String planId) { + MailServiceInstance mailServiceInstance = new MailServiceInstance( + instanceId, serviceDefinitionId, planId, mailDashboardBaseURL + instanceId); + mailServices.put(instanceId, mailServiceInstance); + return Mono.just(mailServiceInstance); + } + + public Mono serviceInstanceExists(String instanceId) { + return Mono.just(mailServices.containsKey(instanceId)); + } + + public Mono getServiceInstance(String instanceId) { + if (mailServices.containsKey(instanceId)) { + return Mono.just(mailServices.get(instanceId)); + } + return Mono.empty(); + } + + public Mono deleteServiceInstance(String instanceId) { + mailServices.remove(instanceId); + mailServiceBindings.remove(instanceId); + return Mono.empty(); + } + + public Mono createServiceBinding(String instanceId, String bindingId) { + return this.serviceInstanceExists(instanceId) + .flatMap(exists -> { + if (exists) { + MailServiceBinding mailServiceBinding = + new MailServiceBinding(bindingId, buildCredentials(instanceId, bindingId)); + mailServiceBindings.put(instanceId, mailServiceBinding); + return Mono.just(mailServiceBinding); + } else { + return Mono.empty(); + } + }); + } + + public Mono serviceBindingExists(String instanceId, String bindingId) { + return Mono.just(mailServiceBindings.containsKey(instanceId) && + mailServiceBindings.get(instanceId).getBindingId().equalsIgnoreCase(bindingId)); + } + + public Mono getServiceBinding(String instanceId, String bindingId) { + if (mailServiceBindings.containsKey(instanceId) && + mailServiceBindings.get(instanceId).getBindingId().equalsIgnoreCase(bindingId)) { + return Mono.just(mailServiceBindings.get(instanceId)); + } + return Mono.empty(); + } + + public Mono deleteServiceBinding(String instanceId) { + mailServiceBindings.remove(instanceId); + return Mono.empty(); + } + + private Map buildCredentials(String instanceId, String bindingId) { + Map credentials = new HashMap<>(); + credentials.put(URI_KEY, mailSystemBaseURL + instanceId); + credentials.put(USERNAME_KEY, bindingId); + credentials.put(PASSWORD_KEY, UUID.randomUUID().toString()); + return credentials; + } + +} diff --git a/spring-cloud/spring-cloud-open-service-broker/src/main/java/com/baeldung/spring/cloud/openservicebroker/mail/MailServiceBinding.java b/spring-cloud/spring-cloud-open-service-broker/src/main/java/com/baeldung/spring/cloud/openservicebroker/mail/MailServiceBinding.java new file mode 100644 index 0000000000..a72d4f7372 --- /dev/null +++ b/spring-cloud/spring-cloud-open-service-broker/src/main/java/com/baeldung/spring/cloud/openservicebroker/mail/MailServiceBinding.java @@ -0,0 +1,22 @@ +package com.baeldung.spring.cloud.openservicebroker.mail; + +import java.util.Map; + +public class MailServiceBinding { + + private String bindingId; + private Map credentials; + + public MailServiceBinding(String bindingId, Map credentials) { + this.bindingId = bindingId; + this.credentials = credentials; + } + + public String getBindingId() { + return bindingId; + } + + public Map getCredentials() { + return credentials; + } +} diff --git a/spring-cloud/spring-cloud-open-service-broker/src/main/java/com/baeldung/spring/cloud/openservicebroker/mail/MailServiceInstance.java b/spring-cloud/spring-cloud-open-service-broker/src/main/java/com/baeldung/spring/cloud/openservicebroker/mail/MailServiceInstance.java new file mode 100644 index 0000000000..d4dbbe5657 --- /dev/null +++ b/spring-cloud/spring-cloud-open-service-broker/src/main/java/com/baeldung/spring/cloud/openservicebroker/mail/MailServiceInstance.java @@ -0,0 +1,32 @@ +package com.baeldung.spring.cloud.openservicebroker.mail; + +public class MailServiceInstance { + + private String instanceId; + private String serviceDefinitionId; + private String planId; + private String dashboardUrl; + + public MailServiceInstance(String instanceId, String serviceDefinitionId, String planId, String dashboardUrl) { + this.instanceId = instanceId; + this.serviceDefinitionId = serviceDefinitionId; + this.planId = planId; + this.dashboardUrl = dashboardUrl; + } + + public String getInstanceId() { + return instanceId; + } + + public String getServiceDefinitionId() { + return serviceDefinitionId; + } + + public String getPlanId() { + return planId; + } + + public String getDashboardUrl() { + return dashboardUrl; + } +} diff --git a/spring-cloud/spring-cloud-open-service-broker/src/main/java/com/baeldung/spring/cloud/openservicebroker/services/MailServiceInstanceBindingService.java b/spring-cloud/spring-cloud-open-service-broker/src/main/java/com/baeldung/spring/cloud/openservicebroker/services/MailServiceInstanceBindingService.java new file mode 100644 index 0000000000..847b309f2c --- /dev/null +++ b/spring-cloud/spring-cloud-open-service-broker/src/main/java/com/baeldung/spring/cloud/openservicebroker/services/MailServiceInstanceBindingService.java @@ -0,0 +1,77 @@ +package com.baeldung.spring.cloud.openservicebroker.services; + +import com.baeldung.spring.cloud.openservicebroker.mail.MailService; +import org.springframework.cloud.servicebroker.exception.ServiceInstanceBindingDoesNotExistException; +import org.springframework.cloud.servicebroker.exception.ServiceInstanceDoesNotExistException; +import org.springframework.cloud.servicebroker.model.binding.CreateServiceInstanceAppBindingResponse; +import org.springframework.cloud.servicebroker.model.binding.CreateServiceInstanceBindingRequest; +import org.springframework.cloud.servicebroker.model.binding.CreateServiceInstanceBindingResponse; +import org.springframework.cloud.servicebroker.model.binding.DeleteServiceInstanceBindingRequest; +import org.springframework.cloud.servicebroker.model.binding.DeleteServiceInstanceBindingResponse; +import org.springframework.cloud.servicebroker.model.binding.GetServiceInstanceAppBindingResponse; +import org.springframework.cloud.servicebroker.model.binding.GetServiceInstanceBindingRequest; +import org.springframework.cloud.servicebroker.model.binding.GetServiceInstanceBindingResponse; +import org.springframework.cloud.servicebroker.service.ServiceInstanceBindingService; +import org.springframework.stereotype.Service; +import reactor.core.publisher.Mono; + +@Service +public class MailServiceInstanceBindingService implements ServiceInstanceBindingService { + + private final MailService mailService; + + public MailServiceInstanceBindingService(MailService mailService) { + this.mailService = mailService; + } + + @Override + public Mono createServiceInstanceBinding( + CreateServiceInstanceBindingRequest request) { + return Mono.just(CreateServiceInstanceAppBindingResponse.builder()) + .flatMap(responseBuilder -> mailService.serviceBindingExists( + request.getServiceInstanceId(), request.getBindingId()) + .flatMap(exists -> { + if (exists) { + return mailService.getServiceBinding( + request.getServiceInstanceId(), request.getBindingId()) + .flatMap(serviceBinding -> Mono.just(responseBuilder + .bindingExisted(true) + .credentials(serviceBinding.getCredentials()) + .build())); + } else { + return mailService.createServiceBinding( + request.getServiceInstanceId(), request.getBindingId()) + .switchIfEmpty(Mono.error( + new ServiceInstanceDoesNotExistException( + request.getServiceInstanceId()))) + .flatMap(mailServiceBinding -> Mono.just(responseBuilder + .bindingExisted(false) + .credentials(mailServiceBinding.getCredentials()) + .build())); + } + })); + } + + @Override + public Mono getServiceInstanceBinding(GetServiceInstanceBindingRequest request) { + return mailService.getServiceBinding(request.getServiceInstanceId(), request.getBindingId()) + .switchIfEmpty(Mono.error(new ServiceInstanceBindingDoesNotExistException(request.getBindingId()))) + .flatMap(mailServiceBinding -> Mono.just(GetServiceInstanceAppBindingResponse.builder() + .credentials(mailServiceBinding.getCredentials()) + .build())); + } + + @Override + public Mono deleteServiceInstanceBinding( + DeleteServiceInstanceBindingRequest request) { + return mailService.serviceBindingExists(request.getServiceInstanceId(), request.getBindingId()) + .flatMap(exists -> { + if (exists) { + return mailService.deleteServiceBinding(request.getServiceInstanceId()) + .thenReturn(DeleteServiceInstanceBindingResponse.builder().build()); + } else { + return Mono.error(new ServiceInstanceBindingDoesNotExistException(request.getBindingId())); + } + }); + } +} diff --git a/spring-cloud/spring-cloud-open-service-broker/src/main/java/com/baeldung/spring/cloud/openservicebroker/services/MailServiceInstanceService.java b/spring-cloud/spring-cloud-open-service-broker/src/main/java/com/baeldung/spring/cloud/openservicebroker/services/MailServiceInstanceService.java new file mode 100644 index 0000000000..8c757c3f25 --- /dev/null +++ b/spring-cloud/spring-cloud-open-service-broker/src/main/java/com/baeldung/spring/cloud/openservicebroker/services/MailServiceInstanceService.java @@ -0,0 +1,72 @@ +package com.baeldung.spring.cloud.openservicebroker.services; + +import com.baeldung.spring.cloud.openservicebroker.mail.MailService; +import org.springframework.cloud.servicebroker.exception.ServiceInstanceDoesNotExistException; +import org.springframework.cloud.servicebroker.model.instance.CreateServiceInstanceRequest; +import org.springframework.cloud.servicebroker.model.instance.CreateServiceInstanceResponse; +import org.springframework.cloud.servicebroker.model.instance.DeleteServiceInstanceRequest; +import org.springframework.cloud.servicebroker.model.instance.DeleteServiceInstanceResponse; +import org.springframework.cloud.servicebroker.model.instance.GetServiceInstanceRequest; +import org.springframework.cloud.servicebroker.model.instance.GetServiceInstanceResponse; +import org.springframework.cloud.servicebroker.service.ServiceInstanceService; +import org.springframework.stereotype.Service; +import reactor.core.publisher.Mono; + +@Service +public class MailServiceInstanceService implements ServiceInstanceService { + + private final MailService mailService; + + public MailServiceInstanceService(MailService mailService) { + this.mailService = mailService; + } + + @Override + public Mono createServiceInstance(CreateServiceInstanceRequest request) { + return Mono.just(request.getServiceInstanceId()) + .flatMap(instanceId -> Mono.just(CreateServiceInstanceResponse.builder()) + .flatMap(responseBuilder -> mailService.serviceInstanceExists(instanceId) + .flatMap(exists -> { + if (exists) { + return mailService.getServiceInstance(instanceId) + .flatMap(mailServiceInstance -> Mono.just(responseBuilder + .instanceExisted(true) + .dashboardUrl(mailServiceInstance.getDashboardUrl()) + .build())); + } else { + return mailService.createServiceInstance( + instanceId, request.getServiceDefinitionId(), request.getPlanId()) + .flatMap(mailServiceInstance -> Mono.just(responseBuilder + .instanceExisted(false) + .dashboardUrl(mailServiceInstance.getDashboardUrl()) + .build())); + } + }))); + } + + @Override + public Mono deleteServiceInstance(DeleteServiceInstanceRequest request) { + return Mono.just(request.getServiceInstanceId()) + .flatMap(instanceId -> mailService.serviceInstanceExists(instanceId) + .flatMap(exists -> { + if (exists) { + return mailService.deleteServiceInstance(instanceId) + .thenReturn(DeleteServiceInstanceResponse.builder().build()); + } else { + return Mono.error(new ServiceInstanceDoesNotExistException(instanceId)); + } + })); + } + + @Override + public Mono getServiceInstance(GetServiceInstanceRequest request) { + return Mono.just(request.getServiceInstanceId()) + .flatMap(instanceId -> mailService.getServiceInstance(instanceId) + .switchIfEmpty(Mono.error(new ServiceInstanceDoesNotExistException(instanceId))) + .flatMap(serviceInstance -> Mono.just(GetServiceInstanceResponse.builder() + .serviceDefinitionId(serviceInstance.getServiceDefinitionId()) + .planId(serviceInstance.getPlanId()) + .dashboardUrl(serviceInstance.getDashboardUrl()) + .build()))); + } +} diff --git a/spring-cloud/spring-cloud-open-service-broker/src/main/resources/application.yml b/spring-cloud/spring-cloud-open-service-broker/src/main/resources/application.yml new file mode 100644 index 0000000000..d863b513b0 --- /dev/null +++ b/spring-cloud/spring-cloud-open-service-broker/src/main/resources/application.yml @@ -0,0 +1,10 @@ +spring: + cloud: + openservicebroker: + base-path: /broker + +mail: + system: + base-url: http://localhost:8080/mail-system/ + dashboard: + base-url: http://localhost:8080/mail-dashboard/ \ No newline at end of file diff --git a/spring-cloud/spring-cloud-open-service-broker/src/test/java/com/baeldung/spring/cloud/openservicebroker/services/MailServiceInstanceBindingServiceUnitTest.java b/spring-cloud/spring-cloud-open-service-broker/src/test/java/com/baeldung/spring/cloud/openservicebroker/services/MailServiceInstanceBindingServiceUnitTest.java new file mode 100644 index 0000000000..5b50d44600 --- /dev/null +++ b/spring-cloud/spring-cloud-open-service-broker/src/test/java/com/baeldung/spring/cloud/openservicebroker/services/MailServiceInstanceBindingServiceUnitTest.java @@ -0,0 +1,201 @@ +package com.baeldung.spring.cloud.openservicebroker.services; + +import com.baeldung.spring.cloud.openservicebroker.mail.MailService; +import com.baeldung.spring.cloud.openservicebroker.mail.MailServiceBinding; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.Mock; +import org.springframework.cloud.servicebroker.exception.ServiceInstanceBindingDoesNotExistException; +import org.springframework.cloud.servicebroker.model.binding.CreateServiceInstanceAppBindingResponse; +import org.springframework.cloud.servicebroker.model.binding.CreateServiceInstanceBindingRequest; +import org.springframework.cloud.servicebroker.model.binding.DeleteServiceInstanceBindingRequest; +import org.springframework.cloud.servicebroker.model.binding.GetServiceInstanceAppBindingResponse; +import org.springframework.cloud.servicebroker.model.binding.GetServiceInstanceBindingRequest; +import reactor.core.publisher.Mono; +import reactor.test.StepVerifier; + +import java.util.HashMap; +import java.util.Map; + +import static com.baeldung.spring.cloud.openservicebroker.mail.MailService.PASSWORD_KEY; +import static com.baeldung.spring.cloud.openservicebroker.mail.MailService.URI_KEY; +import static com.baeldung.spring.cloud.openservicebroker.mail.MailService.USERNAME_KEY; +import static java.util.UUID.randomUUID; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.when; +import static org.mockito.MockitoAnnotations.initMocks; + +public class MailServiceInstanceBindingServiceUnitTest { + + private static final String MAIL_SERVICE_INSTANCE_ID = "test@baeldung.com"; + private static final String MAIL_SERVICE_BINDING_ID = "test"; + private static final String MAIL_SYSTEM_URL = "http://localhost:8080/mail-system/test@baeldung.com"; + + @Mock + private MailService mailService; + + private MailServiceInstanceBindingService mailServiceInstanceBindingService; + + @BeforeEach + public void setUp() { + initMocks(this); + + this.mailServiceInstanceBindingService = new MailServiceInstanceBindingService(mailService); + } + + @Test + public void givenServiceBindingDoesNotExist_whenCreateServiceBinding_thenNewBindingIsCreated() { + // given service binding does not exist + when(mailService.serviceBindingExists(MAIL_SERVICE_INSTANCE_ID, MAIL_SERVICE_BINDING_ID)).thenReturn(Mono.just(false)); + + Map credentials = generateCredentials(); + MailServiceBinding serviceBinding = new MailServiceBinding(MAIL_SERVICE_BINDING_ID, credentials); + when(mailService.createServiceBinding(MAIL_SERVICE_INSTANCE_ID, MAIL_SERVICE_BINDING_ID)) + .thenReturn(Mono.just(serviceBinding)); + + // when create service binding + CreateServiceInstanceBindingRequest request = CreateServiceInstanceBindingRequest.builder() + .serviceInstanceId(MAIL_SERVICE_INSTANCE_ID) + .bindingId(MAIL_SERVICE_BINDING_ID) + .build(); + + // then a new service binding is provisioned + StepVerifier.create(mailServiceInstanceBindingService.createServiceInstanceBinding(request)) + .consumeNextWith(response -> { + assertTrue(response instanceof CreateServiceInstanceAppBindingResponse); + CreateServiceInstanceAppBindingResponse bindingResponse = (CreateServiceInstanceAppBindingResponse) response; + assertFalse(bindingResponse.isBindingExisted()); + validateBindingCredentials(bindingResponse.getCredentials()); + }) + .verifyComplete(); + } + + @Test + public void givenServiceBindingExists_whenCreateServiceBinding_thenExistingBindingIsRetrieved() { + // given service binding exists + when(mailService.serviceBindingExists(MAIL_SERVICE_INSTANCE_ID, MAIL_SERVICE_BINDING_ID)).thenReturn(Mono.just(true)); + + Map credentials = generateCredentials(); + MailServiceBinding serviceBinding = new MailServiceBinding(MAIL_SERVICE_BINDING_ID, credentials); + when(mailService.getServiceBinding(MAIL_SERVICE_INSTANCE_ID, MAIL_SERVICE_BINDING_ID)) + .thenReturn(Mono.just(serviceBinding)); + + // when create service binding + CreateServiceInstanceBindingRequest request = CreateServiceInstanceBindingRequest.builder() + .serviceInstanceId(MAIL_SERVICE_INSTANCE_ID) + .bindingId(MAIL_SERVICE_BINDING_ID) + .build(); + + // then a new service binding is provisioned + StepVerifier.create(mailServiceInstanceBindingService.createServiceInstanceBinding(request)) + .consumeNextWith(response -> { + assertTrue(response instanceof CreateServiceInstanceAppBindingResponse); + CreateServiceInstanceAppBindingResponse bindingResponse = (CreateServiceInstanceAppBindingResponse) response; + assertTrue(bindingResponse.isBindingExisted()); + validateBindingCredentials(bindingResponse.getCredentials()); + }) + .verifyComplete(); + } + + @Test + public void givenServiceBindingDoesNotExist_whenGetServiceBinding_thenException() { + // given service binding does not exist + when(mailService.getServiceBinding(MAIL_SERVICE_INSTANCE_ID, MAIL_SERVICE_BINDING_ID)).thenReturn(Mono.empty()); + + // when get service binding + GetServiceInstanceBindingRequest request = GetServiceInstanceBindingRequest.builder() + .serviceInstanceId(MAIL_SERVICE_INSTANCE_ID) + .bindingId(MAIL_SERVICE_BINDING_ID) + .build(); + + // then ServiceInstanceBindingDoesNotExistException is thrown + StepVerifier.create(mailServiceInstanceBindingService.getServiceInstanceBinding(request)) + .expectErrorMatches(ex -> ex instanceof ServiceInstanceBindingDoesNotExistException) + .verify(); + } + + @Test + public void givenServiceBindingExists_whenGetServiceBinding_thenExistingBindingIsRetrieved() { + // given service binding exists + Map credentials = generateCredentials(); + MailServiceBinding serviceBinding = new MailServiceBinding(MAIL_SERVICE_BINDING_ID, credentials); + when(mailService.getServiceBinding(MAIL_SERVICE_INSTANCE_ID, MAIL_SERVICE_BINDING_ID)) + .thenReturn(Mono.just(serviceBinding)); + + // when get service binding + GetServiceInstanceBindingRequest request = GetServiceInstanceBindingRequest.builder() + .serviceInstanceId(MAIL_SERVICE_INSTANCE_ID) + .bindingId(MAIL_SERVICE_BINDING_ID) + .build(); + + // then the existing service binding is retrieved + StepVerifier.create(mailServiceInstanceBindingService.getServiceInstanceBinding(request)) + .consumeNextWith(response -> { + assertTrue(response instanceof GetServiceInstanceAppBindingResponse); + GetServiceInstanceAppBindingResponse bindingResponse = (GetServiceInstanceAppBindingResponse) response; + validateBindingCredentials(bindingResponse.getCredentials()); + }) + .verifyComplete(); + } + + @Test + public void givenServiceBindingDoesNotExist_whenDeleteServiceBinding_thenException() { + // given service binding does not exist + when(mailService.serviceBindingExists(MAIL_SERVICE_INSTANCE_ID, MAIL_SERVICE_BINDING_ID)).thenReturn(Mono.just(false)); + + // when delete service binding + DeleteServiceInstanceBindingRequest request = DeleteServiceInstanceBindingRequest.builder() + .serviceInstanceId(MAIL_SERVICE_INSTANCE_ID) + .bindingId(MAIL_SERVICE_BINDING_ID) + .build(); + + // then ServiceInstanceBindingDoesNotExistException is thrown + StepVerifier.create(mailServiceInstanceBindingService.deleteServiceInstanceBinding(request)) + .expectErrorMatches(ex -> ex instanceof ServiceInstanceBindingDoesNotExistException) + .verify(); + } + + @Test + public void givenServiceBindingExists_whenDeleteServiceBinding_thenExistingBindingIsDeleted() { + // given service binding exists + when(mailService.serviceBindingExists(MAIL_SERVICE_INSTANCE_ID, MAIL_SERVICE_BINDING_ID)).thenReturn(Mono.just(true)); + when(mailService.deleteServiceBinding(MAIL_SERVICE_INSTANCE_ID)).thenReturn(Mono.empty()); + + // when delete service binding + DeleteServiceInstanceBindingRequest request = DeleteServiceInstanceBindingRequest.builder() + .serviceInstanceId(MAIL_SERVICE_INSTANCE_ID) + .bindingId(MAIL_SERVICE_BINDING_ID) + .build(); + + // then the existing service binding is retrieved + StepVerifier.create(mailServiceInstanceBindingService.deleteServiceInstanceBinding(request)) + .consumeNextWith(response -> { + assertFalse(response.isAsync()); + assertNull(response.getOperation()); + }) + .verifyComplete(); + } + + private void validateBindingCredentials(Map bindingCredentials) { + assertNotNull(bindingCredentials); + assertEquals(3, bindingCredentials.size()); + assertTrue(bindingCredentials.containsKey(URI_KEY)); + assertTrue(bindingCredentials.containsKey(USERNAME_KEY)); + assertTrue(bindingCredentials.containsKey(PASSWORD_KEY)); + assertEquals(MAIL_SYSTEM_URL, bindingCredentials.get(URI_KEY)); + assertEquals(MAIL_SERVICE_BINDING_ID, bindingCredentials.get(USERNAME_KEY)); + assertNotNull(bindingCredentials.get(PASSWORD_KEY)); + } + + private Map generateCredentials() { + Map credentials = new HashMap<>(); + credentials.put(URI_KEY, MAIL_SYSTEM_URL); + credentials.put(USERNAME_KEY, MAIL_SERVICE_BINDING_ID); + credentials.put(PASSWORD_KEY, randomUUID().toString()); + return credentials; + } +} diff --git a/spring-cloud/spring-cloud-open-service-broker/src/test/java/com/baeldung/spring/cloud/openservicebroker/services/MailServiceInstanceServiceUnitTest.java b/spring-cloud/spring-cloud-open-service-broker/src/test/java/com/baeldung/spring/cloud/openservicebroker/services/MailServiceInstanceServiceUnitTest.java new file mode 100644 index 0000000000..1302cad42e --- /dev/null +++ b/spring-cloud/spring-cloud-open-service-broker/src/test/java/com/baeldung/spring/cloud/openservicebroker/services/MailServiceInstanceServiceUnitTest.java @@ -0,0 +1,166 @@ +package com.baeldung.spring.cloud.openservicebroker.services; + +import com.baeldung.spring.cloud.openservicebroker.mail.MailService; +import com.baeldung.spring.cloud.openservicebroker.mail.MailServiceInstance; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.Mock; +import org.springframework.cloud.servicebroker.exception.ServiceInstanceDoesNotExistException; +import org.springframework.cloud.servicebroker.model.instance.CreateServiceInstanceRequest; +import org.springframework.cloud.servicebroker.model.instance.DeleteServiceInstanceRequest; +import org.springframework.cloud.servicebroker.model.instance.GetServiceInstanceRequest; +import reactor.core.publisher.Mono; +import reactor.test.StepVerifier; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.when; +import static org.mockito.MockitoAnnotations.initMocks; + +public class MailServiceInstanceServiceUnitTest { + + private static final String MAIL_SERVICE_INSTANCE_ID = "test@baeldung.com"; + private static final String MAIL_SERVICE_DEFINITION_ID = "mock-service-definition-id"; + private static final String MAIL_SERVICE_PLAN_ID = "mock-service-plan-id"; + private static final String MAIL_DASHBOARD_URL = "http://localhost:8080/mail-dashboard/test@baeldung.com"; + + @Mock + private MailService mailService; + + private MailServiceInstanceService mailServiceInstanceService; + + @BeforeEach + public void setUp() { + initMocks(this); + + this.mailServiceInstanceService = new MailServiceInstanceService(mailService); + } + + @Test + public void givenServiceInstanceDoesNotExist_whenCreateServiceInstance_thenProvisionNewService() { + // given service instance does not exist + when(mailService.serviceInstanceExists(MAIL_SERVICE_INSTANCE_ID)).thenReturn(Mono.just(false)); + + MailServiceInstance serviceInstance = new MailServiceInstance(MAIL_SERVICE_INSTANCE_ID, MAIL_SERVICE_DEFINITION_ID, + MAIL_SERVICE_PLAN_ID, MAIL_DASHBOARD_URL); + when(mailService.createServiceInstance(MAIL_SERVICE_INSTANCE_ID, MAIL_SERVICE_DEFINITION_ID, MAIL_SERVICE_PLAN_ID)) + .thenReturn(Mono.just(serviceInstance)); + + // when create service instance + CreateServiceInstanceRequest request = CreateServiceInstanceRequest.builder() + .serviceInstanceId(MAIL_SERVICE_INSTANCE_ID) + .serviceDefinitionId(MAIL_SERVICE_DEFINITION_ID) + .planId(MAIL_SERVICE_PLAN_ID) + .build(); + + // then a new service instance is provisioned + StepVerifier.create(mailServiceInstanceService.createServiceInstance(request)) + .consumeNextWith(response -> { + assertFalse(response.isInstanceExisted()); + assertEquals(MAIL_DASHBOARD_URL, response.getDashboardUrl()); + }) + .verifyComplete(); + } + + @Test + public void givenServiceInstanceExists_whenCreateServiceInstance_thenExistingServiceInstanceIsRetrieved() { + // given service instance exists + when(mailService.serviceInstanceExists(MAIL_SERVICE_INSTANCE_ID)).thenReturn(Mono.just(true)); + + MailServiceInstance serviceInstance = new MailServiceInstance(MAIL_SERVICE_INSTANCE_ID, MAIL_SERVICE_DEFINITION_ID, + MAIL_SERVICE_PLAN_ID, MAIL_DASHBOARD_URL); + when(mailService.getServiceInstance(MAIL_SERVICE_INSTANCE_ID)).thenReturn(Mono.just(serviceInstance)); + + // when create service instance + CreateServiceInstanceRequest request = CreateServiceInstanceRequest.builder() + .serviceInstanceId(MAIL_SERVICE_INSTANCE_ID) + .serviceDefinitionId(MAIL_SERVICE_DEFINITION_ID) + .planId(MAIL_SERVICE_PLAN_ID) + .build(); + + // then the existing one is retrieved + StepVerifier.create(mailServiceInstanceService.createServiceInstance(request)) + .consumeNextWith(response -> { + assertTrue(response.isInstanceExisted()); + assertEquals(MAIL_DASHBOARD_URL, response.getDashboardUrl()); + }) + .verifyComplete(); + } + + @Test + public void givenServiceInstanceDoesNotExist_whenDeleteServiceInstance_thenException() { + // given service instance does not exist + when(mailService.serviceInstanceExists(MAIL_SERVICE_INSTANCE_ID)).thenReturn(Mono.just(false)); + + // when delete service instance + DeleteServiceInstanceRequest request = DeleteServiceInstanceRequest.builder() + .serviceInstanceId(MAIL_SERVICE_INSTANCE_ID) + .build(); + + // then ServiceInstanceDoesNotExistException is thrown + StepVerifier.create(mailServiceInstanceService.deleteServiceInstance(request)) + .expectErrorMatches(ex -> ex instanceof ServiceInstanceDoesNotExistException) + .verify(); + } + + @Test + public void givenServiceInstanceExists_whenDeleteServiceInstance_thenSuccess() { + // given service instance exists + when(mailService.serviceInstanceExists(MAIL_SERVICE_INSTANCE_ID)).thenReturn(Mono.just(true)); + + // when delete service instance + when(mailService.deleteServiceInstance(MAIL_SERVICE_INSTANCE_ID)).thenReturn(Mono.empty()); + + DeleteServiceInstanceRequest request = DeleteServiceInstanceRequest.builder() + .serviceInstanceId(MAIL_SERVICE_INSTANCE_ID) + .build(); + + // then success + StepVerifier.create(mailServiceInstanceService.deleteServiceInstance(request)) + .consumeNextWith(response -> { + assertFalse(response.isAsync()); + assertNull(response.getOperation()); + }) + .verifyComplete(); + } + + @Test + public void givenServiceInstanceDoesNotExist_whenGetServiceInstance_thenException() { + // given service instance does not exist + when(mailService.getServiceInstance(MAIL_SERVICE_INSTANCE_ID)).thenReturn(Mono.empty()); + + // when get service instance + GetServiceInstanceRequest request = GetServiceInstanceRequest.builder() + .serviceInstanceId(MAIL_SERVICE_INSTANCE_ID) + .build(); + + // then ServiceInstanceDoesNotExistException is thrown + StepVerifier.create(mailServiceInstanceService.getServiceInstance(request)) + .expectErrorMatches(ex -> ex instanceof ServiceInstanceDoesNotExistException) + .verify(); + } + + @Test + public void givenServiceInstanceExists_whenGetServiceInstance_thenExistingServiceInstanceIsRetrieved() { + // given service instance exists + MailServiceInstance serviceInstance = new MailServiceInstance(MAIL_SERVICE_INSTANCE_ID, MAIL_SERVICE_DEFINITION_ID, + MAIL_SERVICE_PLAN_ID, MAIL_DASHBOARD_URL); + when(mailService.getServiceInstance(MAIL_SERVICE_INSTANCE_ID)).thenReturn(Mono.just(serviceInstance)); + + // when get service instance + GetServiceInstanceRequest request = GetServiceInstanceRequest.builder() + .serviceInstanceId(MAIL_SERVICE_INSTANCE_ID) + .build(); + + // then the existing service instance is retrieved + StepVerifier.create(mailServiceInstanceService.getServiceInstance(request)) + .consumeNextWith(response -> { + assertEquals(MAIL_SERVICE_DEFINITION_ID, response.getServiceDefinitionId()); + assertEquals(MAIL_SERVICE_PLAN_ID, response.getPlanId()); + assertEquals(MAIL_DASHBOARD_URL, response.getDashboardUrl()); + }) + .verifyComplete(); + } +} From 0d2076f299bf28c919e5640e15c8359d3d134e75 Mon Sep 17 00:00:00 2001 From: Roque Santos Date: Wed, 3 Jun 2020 19:51:49 -0300 Subject: [PATCH 085/140] BAEL-3844 - Suggested adjustements --- ...estFactoryLiveTest.java => RequestFactoryUnitTest.java} | 7 +++++-- ...erLiveTest.java => RestTemplateCustomizerUnitTest.java} | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) rename spring-resttemplate/src/test/java/com/baeldung/resttemplate/proxy/{RequestFactoryLiveTest.java => RequestFactoryUnitTest.java} (85%) rename spring-resttemplate/src/test/java/com/baeldung/resttemplate/proxy/{RestTemplateCustomizerLiveTest.java => RestTemplateCustomizerUnitTest.java} (89%) diff --git a/spring-resttemplate/src/test/java/com/baeldung/resttemplate/proxy/RequestFactoryLiveTest.java b/spring-resttemplate/src/test/java/com/baeldung/resttemplate/proxy/RequestFactoryUnitTest.java similarity index 85% rename from spring-resttemplate/src/test/java/com/baeldung/resttemplate/proxy/RequestFactoryLiveTest.java rename to spring-resttemplate/src/test/java/com/baeldung/resttemplate/proxy/RequestFactoryUnitTest.java index f9ca66f14d..6959aa8d47 100644 --- a/spring-resttemplate/src/test/java/com/baeldung/resttemplate/proxy/RequestFactoryLiveTest.java +++ b/spring-resttemplate/src/test/java/com/baeldung/resttemplate/proxy/RequestFactoryUnitTest.java @@ -15,13 +15,16 @@ import org.springframework.http.ResponseEntity; import org.springframework.http.client.SimpleClientHttpRequestFactory; import org.springframework.web.client.RestTemplate; -public class RequestFactoryLiveTest { +public class RequestFactoryUnitTest { + + private static final String PROXY_SERVER_HOST = "127.0.0.1"; + private static final int PROXY_SERVER_PORT = 8080; RestTemplate restTemplate; @Before public void setUp() { - Proxy proxy = new Proxy(Type.HTTP, new InetSocketAddress("201.91.82.155", 3128)); + Proxy proxy = new Proxy(Type.HTTP, new InetSocketAddress(PROXY_SERVER_HOST, PROXY_SERVER_PORT)); SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory(); requestFactory.setProxy(proxy); diff --git a/spring-resttemplate/src/test/java/com/baeldung/resttemplate/proxy/RestTemplateCustomizerLiveTest.java b/spring-resttemplate/src/test/java/com/baeldung/resttemplate/proxy/RestTemplateCustomizerUnitTest.java similarity index 89% rename from spring-resttemplate/src/test/java/com/baeldung/resttemplate/proxy/RestTemplateCustomizerLiveTest.java rename to spring-resttemplate/src/test/java/com/baeldung/resttemplate/proxy/RestTemplateCustomizerUnitTest.java index 8f318b758b..b35283bdcf 100644 --- a/spring-resttemplate/src/test/java/com/baeldung/resttemplate/proxy/RestTemplateCustomizerLiveTest.java +++ b/spring-resttemplate/src/test/java/com/baeldung/resttemplate/proxy/RestTemplateCustomizerUnitTest.java @@ -20,7 +20,10 @@ import org.springframework.http.ResponseEntity; import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; import org.springframework.web.client.RestTemplate; -public class RestTemplateCustomizerLiveTest { +public class RestTemplateCustomizerUnitTest { + + private static final String PROXY_SERVER_HOST = "127.0.0.1"; + private static final int PROXY_SERVER_PORT = 8080; RestTemplate restTemplate; @@ -40,7 +43,7 @@ public class RestTemplateCustomizerLiveTest { @Override public void customize(RestTemplate restTemplate) { - HttpHost proxy = new HttpHost("201.91.82.155", 3128); + HttpHost proxy = new HttpHost(PROXY_SERVER_HOST, PROXY_SERVER_PORT); HttpClient httpClient = HttpClientBuilder.create() .setRoutePlanner(new DefaultProxyRoutePlanner(proxy) { @Override From 6e9f4d80a5ab19fd6572c4dda3ce78675fd9110e Mon Sep 17 00:00:00 2001 From: Roque Santos Date: Wed, 3 Jun 2020 19:58:40 -0300 Subject: [PATCH 086/140] BAEL-3844 : Back to LiveTest to bypass te CI build since the proxy address is dynamic --- ...{RequestFactoryUnitTest.java => RequestFactoryLiveTest.java} | 2 +- ...tomizerUnitTest.java => RestTemplateCustomizerLiveTest.java} | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename spring-resttemplate/src/test/java/com/baeldung/resttemplate/proxy/{RequestFactoryUnitTest.java => RequestFactoryLiveTest.java} (97%) rename spring-resttemplate/src/test/java/com/baeldung/resttemplate/proxy/{RestTemplateCustomizerUnitTest.java => RestTemplateCustomizerLiveTest.java} (98%) diff --git a/spring-resttemplate/src/test/java/com/baeldung/resttemplate/proxy/RequestFactoryUnitTest.java b/spring-resttemplate/src/test/java/com/baeldung/resttemplate/proxy/RequestFactoryLiveTest.java similarity index 97% rename from spring-resttemplate/src/test/java/com/baeldung/resttemplate/proxy/RequestFactoryUnitTest.java rename to spring-resttemplate/src/test/java/com/baeldung/resttemplate/proxy/RequestFactoryLiveTest.java index 6959aa8d47..8c13bef05f 100644 --- a/spring-resttemplate/src/test/java/com/baeldung/resttemplate/proxy/RequestFactoryUnitTest.java +++ b/spring-resttemplate/src/test/java/com/baeldung/resttemplate/proxy/RequestFactoryLiveTest.java @@ -15,7 +15,7 @@ import org.springframework.http.ResponseEntity; import org.springframework.http.client.SimpleClientHttpRequestFactory; import org.springframework.web.client.RestTemplate; -public class RequestFactoryUnitTest { +public class RequestFactoryLiveTest { private static final String PROXY_SERVER_HOST = "127.0.0.1"; private static final int PROXY_SERVER_PORT = 8080; diff --git a/spring-resttemplate/src/test/java/com/baeldung/resttemplate/proxy/RestTemplateCustomizerUnitTest.java b/spring-resttemplate/src/test/java/com/baeldung/resttemplate/proxy/RestTemplateCustomizerLiveTest.java similarity index 98% rename from spring-resttemplate/src/test/java/com/baeldung/resttemplate/proxy/RestTemplateCustomizerUnitTest.java rename to spring-resttemplate/src/test/java/com/baeldung/resttemplate/proxy/RestTemplateCustomizerLiveTest.java index b35283bdcf..547428ec9f 100644 --- a/spring-resttemplate/src/test/java/com/baeldung/resttemplate/proxy/RestTemplateCustomizerUnitTest.java +++ b/spring-resttemplate/src/test/java/com/baeldung/resttemplate/proxy/RestTemplateCustomizerLiveTest.java @@ -20,7 +20,7 @@ import org.springframework.http.ResponseEntity; import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; import org.springframework.web.client.RestTemplate; -public class RestTemplateCustomizerUnitTest { +public class RestTemplateCustomizerLiveTest { private static final String PROXY_SERVER_HOST = "127.0.0.1"; private static final int PROXY_SERVER_PORT = 8080; From ee146f5a136ec1b3e0e4a469d671bfcd7faf5f7e Mon Sep 17 00:00:00 2001 From: Sampada <46674082+sampada07@users.noreply.github.com> Date: Thu, 4 Jun 2020 08:18:57 +0530 Subject: [PATCH 087/140] BAEL-4061: Implementing a Simple HTTP Server with Netty (#9416) * BAEL-4061: Implementing a Simple HTTP Server with Netty * BAEL-4061: Added live test * BAEL-4061: moved helper class from test to main folder * BAEL-4061: updated tests to follow BDD --- .../http/server/CustomHttpServerHandler.java | 116 +++++++++++ .../com/baeldung/http/server/HttpServer.java | 64 +++++++ .../baeldung/http/server/ResponseBuilder.java | 120 ++++++++++++ .../http/server/HttpServerLiveTest.java | 180 ++++++++++++++++++ .../http/server/ResponseAggregator.java | 52 +++++ 5 files changed, 532 insertions(+) create mode 100644 netty/src/main/java/com/baeldung/http/server/CustomHttpServerHandler.java create mode 100644 netty/src/main/java/com/baeldung/http/server/HttpServer.java create mode 100644 netty/src/main/java/com/baeldung/http/server/ResponseBuilder.java create mode 100644 netty/src/test/java/com/baeldung/http/server/HttpServerLiveTest.java create mode 100644 netty/src/test/java/com/baeldung/http/server/ResponseAggregator.java diff --git a/netty/src/main/java/com/baeldung/http/server/CustomHttpServerHandler.java b/netty/src/main/java/com/baeldung/http/server/CustomHttpServerHandler.java new file mode 100644 index 0000000000..038f559329 --- /dev/null +++ b/netty/src/main/java/com/baeldung/http/server/CustomHttpServerHandler.java @@ -0,0 +1,116 @@ +package com.baeldung.http.server; + +import static io.netty.handler.codec.http.HttpResponseStatus.BAD_REQUEST; +import static io.netty.handler.codec.http.HttpResponseStatus.CONTINUE; +import static io.netty.handler.codec.http.HttpResponseStatus.OK; +import static io.netty.handler.codec.http.HttpVersion.HTTP_1_1; + +import java.util.Set; + +import io.netty.buffer.Unpooled; +import io.netty.channel.ChannelFutureListener; +import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.SimpleChannelInboundHandler; +import io.netty.handler.codec.http.DefaultFullHttpResponse; +import io.netty.handler.codec.http.FullHttpResponse; +import io.netty.handler.codec.http.HttpContent; +import io.netty.handler.codec.http.HttpHeaderNames; +import io.netty.handler.codec.http.HttpHeaderValues; +import io.netty.handler.codec.http.HttpObject; +import io.netty.handler.codec.http.HttpRequest; +import io.netty.handler.codec.http.HttpUtil; +import io.netty.handler.codec.http.LastHttpContent; +import io.netty.handler.codec.http.cookie.Cookie; +import io.netty.handler.codec.http.cookie.ServerCookieDecoder; +import io.netty.handler.codec.http.cookie.ServerCookieEncoder; +import io.netty.util.CharsetUtil; + +public class CustomHttpServerHandler extends SimpleChannelInboundHandler { + + private HttpRequest request; + StringBuilder responseData = new StringBuilder(); + + @Override + public void channelReadComplete(ChannelHandlerContext ctx) { + ctx.flush(); + } + + @Override + protected void channelRead0(ChannelHandlerContext ctx, Object msg) { + if (msg instanceof HttpRequest) { + HttpRequest request = this.request = (HttpRequest) msg; + + if (HttpUtil.is100ContinueExpected(request)) { + writeResponse(ctx); + } + + responseData.setLength(0); + responseData.append(ResponseBuilder.addRequestAttributes(request)); + responseData.append(ResponseBuilder.addHeaders(request)); + responseData.append(ResponseBuilder.addParams(request)); + } + + responseData.append(ResponseBuilder.addDecoderResult(request)); + + if (msg instanceof HttpContent) { + HttpContent httpContent = (HttpContent) msg; + + responseData.append(ResponseBuilder.addBody(httpContent)); + responseData.append(ResponseBuilder.addDecoderResult(request)); + + if (msg instanceof LastHttpContent) { + LastHttpContent trailer = (LastHttpContent) msg; + responseData.append(ResponseBuilder.addLastResponse(request, trailer)); + writeResponse(ctx, trailer, responseData); + } + } + } + + private void writeResponse(ChannelHandlerContext ctx) { + FullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, CONTINUE, Unpooled.EMPTY_BUFFER); + ctx.write(response); + } + + private void writeResponse(ChannelHandlerContext ctx, LastHttpContent trailer, StringBuilder responseData) { + boolean keepAlive = HttpUtil.isKeepAlive(request); + + FullHttpResponse httpResponse = new DefaultFullHttpResponse(HTTP_1_1, ((HttpObject) trailer).decoderResult() + .isSuccess() ? OK : BAD_REQUEST, Unpooled.copiedBuffer(responseData.toString(), CharsetUtil.UTF_8)); + + httpResponse.headers() + .set(HttpHeaderNames.CONTENT_TYPE, "text/plain; charset=UTF-8"); + + if (keepAlive) { + httpResponse.headers() + .setInt(HttpHeaderNames.CONTENT_LENGTH, httpResponse.content() + .readableBytes()); + httpResponse.headers() + .set(HttpHeaderNames.CONNECTION, HttpHeaderValues.KEEP_ALIVE); + } + + String cookieString = request.headers() + .get(HttpHeaderNames.COOKIE); + if (cookieString != null) { + Set cookies = ServerCookieDecoder.STRICT.decode(cookieString); + if (!cookies.isEmpty()) { + for (Cookie cookie : cookies) { + httpResponse.headers() + .add(HttpHeaderNames.SET_COOKIE, ServerCookieEncoder.STRICT.encode(cookie)); + } + } + } + + ctx.write(httpResponse); + + if (!keepAlive) { + ctx.writeAndFlush(Unpooled.EMPTY_BUFFER) + .addListener(ChannelFutureListener.CLOSE); + } + } + + @Override + public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { + cause.printStackTrace(); + ctx.close(); + } +} diff --git a/netty/src/main/java/com/baeldung/http/server/HttpServer.java b/netty/src/main/java/com/baeldung/http/server/HttpServer.java new file mode 100644 index 0000000000..529d14f0fd --- /dev/null +++ b/netty/src/main/java/com/baeldung/http/server/HttpServer.java @@ -0,0 +1,64 @@ +package com.baeldung.http.server; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import io.netty.bootstrap.ServerBootstrap; +import io.netty.channel.ChannelFuture; +import io.netty.channel.ChannelInitializer; +import io.netty.channel.ChannelPipeline; +import io.netty.channel.EventLoopGroup; +import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.socket.SocketChannel; +import io.netty.channel.socket.nio.NioServerSocketChannel; +import io.netty.handler.codec.http.HttpRequestDecoder; +import io.netty.handler.codec.http.HttpResponseEncoder; +import io.netty.handler.logging.LogLevel; +import io.netty.handler.logging.LoggingHandler; + +public class HttpServer { + + private int port; + static Logger logger = LoggerFactory.getLogger(HttpServer.class); + + public HttpServer(int port) { + this.port = port; + } + + public static void main(String[] args) throws Exception { + + int port = args.length > 0 ? Integer.parseInt(args[0]) : 8080; + + new HttpServer(port).run(); + } + + public void run() throws Exception { + EventLoopGroup bossGroup = new NioEventLoopGroup(1); + EventLoopGroup workerGroup = new NioEventLoopGroup(); + try { + ServerBootstrap b = new ServerBootstrap(); + b.group(bossGroup, workerGroup) + .channel(NioServerSocketChannel.class) + .handler(new LoggingHandler(LogLevel.INFO)) + .childHandler(new ChannelInitializer() { + @Override + protected void initChannel(SocketChannel ch) throws Exception { + ChannelPipeline p = ch.pipeline(); + p.addLast(new HttpRequestDecoder()); + p.addLast(new HttpResponseEncoder()); + p.addLast(new CustomHttpServerHandler()); + } + }); + + ChannelFuture f = b.bind(port) + .sync(); + f.channel() + .closeFuture() + .sync(); + + } finally { + bossGroup.shutdownGracefully(); + workerGroup.shutdownGracefully(); + } + } +} diff --git a/netty/src/main/java/com/baeldung/http/server/ResponseBuilder.java b/netty/src/main/java/com/baeldung/http/server/ResponseBuilder.java new file mode 100644 index 0000000000..6d4e7845da --- /dev/null +++ b/netty/src/main/java/com/baeldung/http/server/ResponseBuilder.java @@ -0,0 +1,120 @@ +package com.baeldung.http.server; + +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import io.netty.buffer.ByteBuf; +import io.netty.handler.codec.DecoderResult; +import io.netty.handler.codec.http.HttpContent; +import io.netty.handler.codec.http.HttpHeaderNames; +import io.netty.handler.codec.http.HttpHeaders; +import io.netty.handler.codec.http.HttpObject; +import io.netty.handler.codec.http.HttpRequest; +import io.netty.handler.codec.http.LastHttpContent; +import io.netty.handler.codec.http.QueryStringDecoder; +import io.netty.util.CharsetUtil; + +class ResponseBuilder { + + static StringBuilder addRequestAttributes(HttpRequest request) { + StringBuilder responseData = new StringBuilder(); + responseData.append("Version: ") + .append(request.protocolVersion()) + .append("\r\n"); + responseData.append("Host: ") + .append(request.headers() + .get(HttpHeaderNames.HOST, "unknown")) + .append("\r\n"); + responseData.append("URI: ") + .append(request.uri()) + .append("\r\n\r\n"); + return responseData; + } + + static StringBuilder addParams(HttpRequest request) { + StringBuilder responseData = new StringBuilder(); + QueryStringDecoder queryStringDecoder = new QueryStringDecoder(request.uri()); + Map> params = queryStringDecoder.parameters(); + if (!params.isEmpty()) { + for (Entry> p : params.entrySet()) { + String key = p.getKey(); + List vals = p.getValue(); + for (String val : vals) { + responseData.append("Parameter: ") + .append(key) + .append(" = ") + .append(val) + .append("\r\n"); + } + } + responseData.append("\r\n"); + } + return responseData; + } + + static StringBuilder addHeaders(HttpRequest request) { + StringBuilder responseData = new StringBuilder(); + HttpHeaders headers = request.headers(); + if (!headers.isEmpty()) { + for (Map.Entry header : headers) { + CharSequence key = header.getKey(); + CharSequence value = header.getValue(); + responseData.append(key) + .append(" = ") + .append(value) + .append("\r\n"); + } + responseData.append("\r\n"); + } + return responseData; + } + + static StringBuilder addBody(HttpContent httpContent) { + StringBuilder responseData = new StringBuilder(); + ByteBuf content = httpContent.content(); + if (content.isReadable()) { + responseData.append(content.toString(CharsetUtil.UTF_8) + .toUpperCase()); + responseData.append("\r\n"); + } + return responseData; + } + + static StringBuilder addDecoderResult(HttpObject o) { + StringBuilder responseData = new StringBuilder(); + DecoderResult result = o.decoderResult(); + + if (!result.isSuccess()) { + responseData.append("..Decoder Failure: "); + responseData.append(result.cause()); + responseData.append("\r\n"); + } + + return responseData; + } + + static StringBuilder addLastResponse(HttpRequest request, LastHttpContent trailer) { + StringBuilder responseData = new StringBuilder(); + responseData.append("Good Bye!\r\n"); + + if (!trailer.trailingHeaders() + .isEmpty()) { + responseData.append("\r\n"); + for (CharSequence name : trailer.trailingHeaders() + .names()) { + for (CharSequence value : trailer.trailingHeaders() + .getAll(name)) { + responseData.append("P.S. Trailing Header: "); + responseData.append(name) + .append(" = ") + .append(value) + .append("\r\n"); + } + } + responseData.append("\r\n"); + } + return responseData; + } + +} diff --git a/netty/src/test/java/com/baeldung/http/server/HttpServerLiveTest.java b/netty/src/test/java/com/baeldung/http/server/HttpServerLiveTest.java new file mode 100644 index 0000000000..7a0f884724 --- /dev/null +++ b/netty/src/test/java/com/baeldung/http/server/HttpServerLiveTest.java @@ -0,0 +1,180 @@ +package com.baeldung.http.server; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.util.HashMap; +import java.util.Map; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import io.netty.bootstrap.Bootstrap; +import io.netty.buffer.Unpooled; +import io.netty.channel.Channel; +import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.ChannelInitializer; +import io.netty.channel.ChannelPipeline; +import io.netty.channel.EventLoopGroup; +import io.netty.channel.SimpleChannelInboundHandler; +import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.socket.SocketChannel; +import io.netty.channel.socket.nio.NioSocketChannel; +import io.netty.handler.codec.http.DefaultFullHttpRequest; +import io.netty.handler.codec.http.HttpClientCodec; +import io.netty.handler.codec.http.HttpContent; +import io.netty.handler.codec.http.HttpContentDecompressor; +import io.netty.handler.codec.http.HttpHeaderNames; +import io.netty.handler.codec.http.HttpHeaderValues; +import io.netty.handler.codec.http.HttpMethod; +import io.netty.handler.codec.http.HttpObject; +import io.netty.handler.codec.http.HttpResponse; +import io.netty.handler.codec.http.HttpUtil; +import io.netty.handler.codec.http.HttpVersion; +import io.netty.handler.codec.http.LastHttpContent; +import io.netty.handler.codec.http.cookie.ClientCookieEncoder; +import io.netty.handler.codec.http.cookie.DefaultCookie; +import io.netty.util.CharsetUtil; + +//Ensure the server class - HttpServer.java is already started before running this test +public class HttpServerLiveTest { + + private static final String HOST = "127.0.0.1"; + private static final int PORT = 8080; + private Channel channel; + private EventLoopGroup group = new NioEventLoopGroup(); + ResponseAggregator response = new ResponseAggregator(); + + @Before + public void setup() throws Exception { + Bootstrap b = new Bootstrap(); + b.group(group) + .channel(NioSocketChannel.class) + .handler(new ChannelInitializer() { + + @Override + protected void initChannel(SocketChannel ch) throws Exception { + ChannelPipeline p = ch.pipeline(); + p.addLast(new HttpClientCodec()); + p.addLast(new HttpContentDecompressor()); + p.addLast(new SimpleChannelInboundHandler() { + @Override + protected void channelRead0(ChannelHandlerContext ctx, HttpObject msg) throws Exception { + response = prepareResponse(ctx, msg, response); + } + }); + } + }); + + channel = b.connect(HOST, PORT) + .sync() + .channel(); + } + + @Test + public void whenPostSent_thenContentReceivedInUppercase() throws Exception { + String body = "Hello World!"; + + DefaultFullHttpRequest request = createRequest(body); + + channel.writeAndFlush(request); + Thread.sleep(200); + + assertEquals(200, response.getStatus()); + assertEquals("HTTP/1.1", response.getVersion()); + + assertTrue(response.getContent() + .contains(body.toUpperCase())); + } + + @Test + public void whenGetSent_thenCookieReceivedInResponse() throws Exception { + DefaultFullHttpRequest request = createRequest(null); + + channel.writeAndFlush(request); + Thread.sleep(200); + + assertEquals(200, response.getStatus()); + assertEquals("HTTP/1.1", response.getVersion()); + + Map headers = response.getHeaders(); + String cookies = headers.get("set-cookie"); + assertTrue(cookies.contains("my-cookie")); + } + + @After + public void cleanup() throws InterruptedException { + channel.closeFuture() + .sync(); + group.shutdownGracefully(); + } + + private static DefaultFullHttpRequest createRequest(final CharSequence body) throws Exception { + DefaultFullHttpRequest request; + if (body != null) { + request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/"); + request.content() + .writeBytes(body.toString() + .getBytes(CharsetUtil.UTF_8.name())); + request.headers() + .set(HttpHeaderNames.CONTENT_TYPE, "application/json"); + request.headers() + .set(HttpHeaderNames.CONTENT_LENGTH, request.content() + .readableBytes()); + } else { + request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/", Unpooled.EMPTY_BUFFER); + request.headers() + .set(HttpHeaderNames.COOKIE, ClientCookieEncoder.STRICT.encode(new DefaultCookie("my-cookie", "foo"))); + } + + request.headers() + .set(HttpHeaderNames.HOST, HOST); + request.headers() + .set(HttpHeaderNames.CONNECTION, HttpHeaderValues.KEEP_ALIVE); + + return request; + } + + private static ResponseAggregator prepareResponse(ChannelHandlerContext ctx, HttpObject msg, ResponseAggregator responseAgg) { + + if (msg instanceof HttpResponse) { + HttpResponse response = (HttpResponse) msg; + + responseAgg.setStatus(response.status() + .code()); + + responseAgg.setVersion(response.protocolVersion() + .text()); + + if (!response.headers() + .isEmpty()) { + Map headers = new HashMap(); + for (CharSequence name : response.headers() + .names()) { + for (CharSequence value : response.headers() + .getAll(name)) { + headers.put(name.toString(), value.toString()); + } + } + responseAgg.setHeaders(headers); + } + if (HttpUtil.isTransferEncodingChunked(response)) { + responseAgg.setChunked(true); + } else { + responseAgg.setChunked(false); + } + } + if (msg instanceof HttpContent) { + HttpContent content = (HttpContent) msg; + String responseData = content.content() + .toString(CharsetUtil.UTF_8); + + if (content instanceof LastHttpContent) { + responseAgg.setContent(responseData + "} End Of Content"); + ctx.close(); + } + } + return responseAgg; + } +} diff --git a/netty/src/test/java/com/baeldung/http/server/ResponseAggregator.java b/netty/src/test/java/com/baeldung/http/server/ResponseAggregator.java new file mode 100644 index 0000000000..9f6e5e9823 --- /dev/null +++ b/netty/src/test/java/com/baeldung/http/server/ResponseAggregator.java @@ -0,0 +1,52 @@ +package com.baeldung.http.server; + +import java.util.Map; + +public class ResponseAggregator { + int status; + String version; + Map headers; + boolean isChunked; + String content; + + public int getStatus() { + return status; + } + + public void setStatus(int status) { + this.status = status; + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + public Map getHeaders() { + return headers; + } + + public void setHeaders(Map headers) { + this.headers = headers; + } + + public boolean isChunked() { + return isChunked; + } + + public void setChunked(boolean isChunked) { + this.isChunked = isChunked; + } + + public String getContent() { + return content; + } + + public void setContent(String content) { + this.content = content; + } + +} From c122add13e331e0c9cf9e01f264baa52f378ffa1 Mon Sep 17 00:00:00 2001 From: KevinGilmore Date: Wed, 3 Jun 2020 22:20:43 -0500 Subject: [PATCH 088/140] Bael 4026 (#9433) * BAEL-3336 BAEL-3058 add links * BAEL-3319: add link * BAEL-3284: add link * BAEL-3198: add link to article * BAEL-3479: add link to article * BAEL-3485: add article link * SCALA-38: move to new package and add link back to article * SCALA-38: add imports back into unit test * BAEL-3908: add link back to article * BAEL-2893 BAEL-3927 add link back to article * BAEL-4026: update README.md --- spring-cloud/spring-cloud-open-service-broker/README.md | 2 ++ testing-modules/mockito-2/README.md | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/spring-cloud/spring-cloud-open-service-broker/README.md b/spring-cloud/spring-cloud-open-service-broker/README.md index f09469076b..4084e8ebb2 100644 --- a/spring-cloud/spring-cloud-open-service-broker/README.md +++ b/spring-cloud/spring-cloud-open-service-broker/README.md @@ -1 +1,3 @@ ### Relevant Articles: + +- [Quick Guide to Spring Cloud Open Service Broker](https://www.baeldung.com/spring-cloud-open-service-broker) diff --git a/testing-modules/mockito-2/README.md b/testing-modules/mockito-2/README.md index 329228186f..1a013f5de3 100644 --- a/testing-modules/mockito-2/README.md +++ b/testing-modules/mockito-2/README.md @@ -5,4 +5,4 @@ - [Mockito Strict Stubbing and The UnnecessaryStubbingException](https://www.baeldung.com/mockito-unnecessary-stubbing-exception) - [Mockito and Fluent APIs](https://www.baeldung.com/mockito-fluent-apis) - [Mocking the ObjectMapper readValue() Method](https://www.baeldung.com/mockito-mock-jackson-read-value) -- [Introduction to Mockito’s AdditionalAnswers](https://www.baeldung.com/mockito-additionalanswers) +- [Introduction to Mockito’s AdditionalAnswers](https://www.baeldung.com/mockito-additionalanswers) \ No newline at end of file From e4d59f4874bfd432a894f6e98fc70dd847cf3f79 Mon Sep 17 00:00:00 2001 From: Roque Santos Date: Thu, 4 Jun 2020 02:23:10 -0300 Subject: [PATCH 089/140] BAEL-3844 : Documenting the LiveTests using JavaDoc. --- .../resttemplate/proxy/RequestFactoryLiveTest.java | 9 +++++++++ .../proxy/RestTemplateCustomizerLiveTest.java | 11 +++++++++++ 2 files changed, 20 insertions(+) diff --git a/spring-resttemplate/src/test/java/com/baeldung/resttemplate/proxy/RequestFactoryLiveTest.java b/spring-resttemplate/src/test/java/com/baeldung/resttemplate/proxy/RequestFactoryLiveTest.java index 8c13bef05f..93949e52a3 100644 --- a/spring-resttemplate/src/test/java/com/baeldung/resttemplate/proxy/RequestFactoryLiveTest.java +++ b/spring-resttemplate/src/test/java/com/baeldung/resttemplate/proxy/RequestFactoryLiveTest.java @@ -15,6 +15,15 @@ import org.springframework.http.ResponseEntity; import org.springframework.http.client.SimpleClientHttpRequestFactory; import org.springframework.web.client.RestTemplate; +/** + * This class is used to test a request using {@link RestTemplate} with {@link Proxy} + * using a {@link SimpleClientHttpRequestFactory} as configuration. + *
+ *
+ * + * Before running the test we should change the PROXY_SERVER_HOST + * and PROXY_SERVER_PORT constants in our class to match our preferred proxy configuration. + */ public class RequestFactoryLiveTest { private static final String PROXY_SERVER_HOST = "127.0.0.1"; diff --git a/spring-resttemplate/src/test/java/com/baeldung/resttemplate/proxy/RestTemplateCustomizerLiveTest.java b/spring-resttemplate/src/test/java/com/baeldung/resttemplate/proxy/RestTemplateCustomizerLiveTest.java index 547428ec9f..faeb49537a 100644 --- a/spring-resttemplate/src/test/java/com/baeldung/resttemplate/proxy/RestTemplateCustomizerLiveTest.java +++ b/spring-resttemplate/src/test/java/com/baeldung/resttemplate/proxy/RestTemplateCustomizerLiveTest.java @@ -4,6 +4,8 @@ import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; +import java.net.Proxy; + import org.apache.http.HttpException; import org.apache.http.HttpHost; import org.apache.http.HttpRequest; @@ -20,6 +22,15 @@ import org.springframework.http.ResponseEntity; import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; import org.springframework.web.client.RestTemplate; +/** + * This class is used to test a request using {@link RestTemplate} with {@link Proxy} + * using a {@link RestTemplateCustomizer} as configuration. + *
+ *
+ * + * Before running the test we should change the PROXY_SERVER_HOST + * and PROXY_SERVER_PORT constants in our class to match our preferred proxy configuration. + */ public class RestTemplateCustomizerLiveTest { private static final String PROXY_SERVER_HOST = "127.0.0.1"; From bc2c23ae9e229be2ba0c05d2784a6a86aea50c52 Mon Sep 17 00:00:00 2001 From: Cristian Rosu Date: Thu, 4 Jun 2020 12:18:03 +0300 Subject: [PATCH 090/140] BAEL-4070: removed unnecessary curly brace, fixed test name --- .../baeldung/properties/lists/ListsPropertiesUnitTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/lists/ListsPropertiesUnitTest.java b/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/lists/ListsPropertiesUnitTest.java index 8c1835a0a9..80cb8e9ea0 100644 --- a/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/lists/ListsPropertiesUnitTest.java +++ b/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/lists/ListsPropertiesUnitTest.java @@ -15,7 +15,7 @@ import java.util.List; import static org.junit.Assert.assertEquals; @RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = {SpringListPropertiesApplication.class}) +@ContextConfiguration(classes = SpringListPropertiesApplication.class) public class ListsPropertiesUnitTest { @Value("${arrayOfStrings}") @@ -78,7 +78,7 @@ public class ListsPropertiesUnitTest { } @Test - public void WhenReadingFromSpringEnvironment_ThenPropertiesHaveExpectedValues() { + public void whenReadingFromSpringEnvironment_ThenPropertiesHaveExpectedValues() { String[] arrayOfStrings = environment.getProperty("arrayOfStrings", String[].class); List listOfStrings = (List)environment.getProperty("arrayOfStrings", List.class); From 3078464b95757ebb304abb35f9b13f982572b9be Mon Sep 17 00:00:00 2001 From: bragilev Date: Thu, 4 Jun 2020 16:58:48 +0200 Subject: [PATCH 091/140] Bael-3386 (#9231) * bragilev * Delete ShoppingListApplication.java * BAEL-3386 * Revert "bragilev" This reverts commit dbf2a21ba4fe2a60c518beecda7ab33746977252. * Revert "Delete ShoppingListApplication.java" This reverts commit 640bb544e6cd8eda6d1fe6a38607323871ddb957. * Revert "Revert "Delete ShoppingListApplication.java"" This reverts commit f56864e46db92c4f981bdc38f78fbabade72156c. --- .../hibernate-exceptions/pom.xml | 39 +++++++++ .../lazyinitialization/HibernateUtil.java | 42 +++++++++ .../lazyinitialization/entity/Role.java | 45 ++++++++++ .../lazyinitialization/entity/User.java | 55 ++++++++++++ .../HibernateNoSessionUnitTest.java | 85 +++++++++++++++++++ 5 files changed, 266 insertions(+) create mode 100644 persistence-modules/hibernate-exceptions/pom.xml create mode 100644 persistence-modules/hibernate-exceptions/src/main/java/com/baeldung/hibernate/exception/lazyinitialization/HibernateUtil.java create mode 100644 persistence-modules/hibernate-exceptions/src/main/java/com/baeldung/hibernate/exception/lazyinitialization/entity/Role.java create mode 100644 persistence-modules/hibernate-exceptions/src/main/java/com/baeldung/hibernate/exception/lazyinitialization/entity/User.java create mode 100644 persistence-modules/hibernate-exceptions/src/test/java/com/baeldung/hibernate/exception/lazyinitialization/HibernateNoSessionUnitTest.java diff --git a/persistence-modules/hibernate-exceptions/pom.xml b/persistence-modules/hibernate-exceptions/pom.xml new file mode 100644 index 0000000000..e5217e83bd --- /dev/null +++ b/persistence-modules/hibernate-exceptions/pom.xml @@ -0,0 +1,39 @@ + + + 4.0.0 + hibernate-exceptions + 0.0.1-SNAPSHOT + hibernate-exceptions + + + com.baeldung + persistence-modules + 1.0.0-SNAPSHOT + + + + + org.hsqldb + hsqldb + ${hsqldb.version} + + + org.hibernate + hibernate-core + ${hibernate.version} + + + javax.xml.bind + jaxb-api + ${jaxb.version} + + + + + 2.4.0 + 2.3.0 + 5.3.7.Final + + + diff --git a/persistence-modules/hibernate-exceptions/src/main/java/com/baeldung/hibernate/exception/lazyinitialization/HibernateUtil.java b/persistence-modules/hibernate-exceptions/src/main/java/com/baeldung/hibernate/exception/lazyinitialization/HibernateUtil.java new file mode 100644 index 0000000000..b84a512fd4 --- /dev/null +++ b/persistence-modules/hibernate-exceptions/src/main/java/com/baeldung/hibernate/exception/lazyinitialization/HibernateUtil.java @@ -0,0 +1,42 @@ +package com.baeldung.hibernate.exception.lazyinitialization; + +import java.util.Properties; + +import org.hibernate.SessionFactory; +import org.hibernate.boot.registry.StandardServiceRegistryBuilder; +import org.hibernate.cfg.Configuration; +import org.hibernate.cfg.Environment; +import org.hibernate.service.ServiceRegistry; + +import com.baeldung.hibernate.exception.lazyinitialization.entity.Role; +import com.baeldung.hibernate.exception.lazyinitialization.entity.User; + +public class HibernateUtil { + private static SessionFactory sessionFactory; + + public static SessionFactory getSessionFactory() { + if (sessionFactory == null) { + try { + Configuration configuration = new Configuration(); + Properties settings = new Properties(); + settings.put(Environment.DRIVER, "org.hsqldb.jdbcDriver"); + settings.put(Environment.URL, "jdbc:hsqldb:mem:userrole"); + settings.put(Environment.USER, "sa"); + settings.put(Environment.PASS, ""); + settings.put(Environment.DIALECT, "org.hibernate.dialect.HSQLDialect"); + settings.put(Environment.SHOW_SQL, "true"); + settings.put(Environment.HBM2DDL_AUTO, "update"); + configuration.setProperties(settings); + configuration.addAnnotatedClass(User.class); + configuration.addAnnotatedClass(Role.class); + + ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder() + .applySettings(configuration.getProperties()).build(); + sessionFactory = configuration.buildSessionFactory(serviceRegistry); + } catch (Exception e) { + e.printStackTrace(); + } + } + return sessionFactory; + } +} \ No newline at end of file diff --git a/persistence-modules/hibernate-exceptions/src/main/java/com/baeldung/hibernate/exception/lazyinitialization/entity/Role.java b/persistence-modules/hibernate-exceptions/src/main/java/com/baeldung/hibernate/exception/lazyinitialization/entity/Role.java new file mode 100644 index 0000000000..c15e674c52 --- /dev/null +++ b/persistence-modules/hibernate-exceptions/src/main/java/com/baeldung/hibernate/exception/lazyinitialization/entity/Role.java @@ -0,0 +1,45 @@ +package com.baeldung.hibernate.exception.lazyinitialization.entity; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; + +@Entity +@Table(name = "role") +public class Role { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "id") + private int id; + + @Column(name = "role_name") + private String roleName; + + public Role() { + + } + + public Role(String roleName) { + this.roleName = roleName; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getRoleName() { + return roleName; + } + + public void setRoleName(String roleName) { + this.roleName = roleName; + } + +} diff --git a/persistence-modules/hibernate-exceptions/src/main/java/com/baeldung/hibernate/exception/lazyinitialization/entity/User.java b/persistence-modules/hibernate-exceptions/src/main/java/com/baeldung/hibernate/exception/lazyinitialization/entity/User.java new file mode 100644 index 0000000000..5bd7e00801 --- /dev/null +++ b/persistence-modules/hibernate-exceptions/src/main/java/com/baeldung/hibernate/exception/lazyinitialization/entity/User.java @@ -0,0 +1,55 @@ +package com.baeldung.hibernate.exception.lazyinitialization.entity; + +import java.util.HashSet; +import java.util.Set; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.OneToMany; +import javax.persistence.Table; + +@Entity +@Table(name = "user") +public class User { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "id") + private int id; + + @Column(name = "first_name") + private String firstName; + + @Column(name = "last_name") + private String lastName; + + @OneToMany + @JoinColumn(name = "user_id") + private Set roles = new HashSet<>(); + + public User() { + + } + + public User(String firstName, String lastName) { + this.firstName = firstName; + this.lastName = lastName; + } + + public int getId() { + return id; + } + + public Set getRoles() { + return roles; + } + + public void addRole(Role role) { + roles.add(role); + } + +} diff --git a/persistence-modules/hibernate-exceptions/src/test/java/com/baeldung/hibernate/exception/lazyinitialization/HibernateNoSessionUnitTest.java b/persistence-modules/hibernate-exceptions/src/test/java/com/baeldung/hibernate/exception/lazyinitialization/HibernateNoSessionUnitTest.java new file mode 100644 index 0000000000..672c438c88 --- /dev/null +++ b/persistence-modules/hibernate-exceptions/src/test/java/com/baeldung/hibernate/exception/lazyinitialization/HibernateNoSessionUnitTest.java @@ -0,0 +1,85 @@ +package com.baeldung.hibernate.exception.lazyinitialization; + +import org.hibernate.LazyInitializationException; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +import com.baeldung.hibernate.exception.lazyinitialization.entity.Role; +import com.baeldung.hibernate.exception.lazyinitialization.entity.User; + +public class HibernateNoSessionUnitTest { + + private static SessionFactory sessionFactory; + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + @BeforeClass + public static void init() { + sessionFactory = HibernateUtil.getSessionFactory(); + } + + @Test + public void whenAccessUserRolesInsideSession_thenSuccess() { + + User detachedUser = createUserWithRoles(); + + Session session = sessionFactory.openSession(); + session.beginTransaction(); + + User persistentUser = session.find(User.class, detachedUser.getId()); + + Assert.assertEquals(2, persistentUser.getRoles().size()); + + session.getTransaction().commit(); + session.close(); + } + + @Test + public void whenAccessUserRolesOutsideSession_thenThrownException() { + + User detachedUser = createUserWithRoles(); + + Session session = sessionFactory.openSession(); + session.beginTransaction(); + + User persistentUser = session.find(User.class, detachedUser.getId()); + + session.getTransaction().commit(); + session.close(); + + thrown.expect(LazyInitializationException.class); + System.out.println(persistentUser.getRoles().size()); + } + + private User createUserWithRoles() { + + Role admin = new Role("Admin"); + Role dba = new Role("DBA"); + + User user = new User("Bob", "Smith"); + + user.addRole(admin); + user.addRole(dba); + + Session session = sessionFactory.openSession(); + session.beginTransaction(); + user.getRoles().forEach(role -> session.save(role)); + session.save(user); + session.getTransaction().commit(); + session.close(); + + return user; + } + + @AfterClass + public static void cleanUp() { + sessionFactory.close(); + } +} From 829b4975c4cd6269fd6744d8b5b800efe7559470 Mon Sep 17 00:00:00 2001 From: Josh Cummings Date: Thu, 4 Jun 2020 10:06:16 -0600 Subject: [PATCH 092/140] Update README.md Issue BAEL-3896 --- spring-rest-http/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-rest-http/README.md b/spring-rest-http/README.md index 35793cb281..f78f8784b0 100644 --- a/spring-rest-http/README.md +++ b/spring-rest-http/README.md @@ -13,3 +13,4 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [Spring RequestMapping](https://www.baeldung.com/spring-requestmapping) - [Guide to DeferredResult in Spring](https://www.baeldung.com/spring-deferred-result) - [Using JSON Patch in Spring REST APIs](https://www.baeldung.com/spring-rest-json-patch) +- [Using OpenAPI and JSON Request Parameters](https://www.baeldung.com/openapi-json-query-parameters) From 07751eeea2af16605d98ecf2bed47ed2ac0cf230 Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Fri, 5 Jun 2020 15:10:58 +0200 Subject: [PATCH 093/140] JAVA-1782: Add byte-buddy to parent-boot-2 --- parent-boot-2/pom.xml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/parent-boot-2/pom.xml b/parent-boot-2/pom.xml index c7bb11b1d5..631d8a0581 100644 --- a/parent-boot-2/pom.xml +++ b/parent-boot-2/pom.xml @@ -32,6 +32,11 @@ io.rest-assured rest-assured + + net.bytebuddy + byte-buddy + ${byte-buddy.version} + org.springframework.boot spring-boot-starter-test From b8a3dd7a687fb7e8c6a751aa9a214e4f84bbf99f Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Fri, 5 Jun 2020 15:38:09 +0200 Subject: [PATCH 094/140] JAVA-1782: Remove byte-buddy dep from parent-boot-2's children --- persistence-modules/spring-boot-persistence-h2/pom.xml | 5 ----- spring-5-mvc/pom.xml | 5 ----- spring-boot-groovy/pom.xml | 5 ----- spring-boot-modules/spring-boot-keycloak/pom.xml | 4 ---- spring-boot-rest/pom.xml | 5 ----- spring-jinq/pom.xml | 7 ------- spring-rest-hal-browser/pom.xml | 6 ------ spring-security-modules/spring-security-mvc-boot-1/pom.xml | 4 ---- spring-social-login/pom.xml | 7 ------- 9 files changed, 48 deletions(-) diff --git a/persistence-modules/spring-boot-persistence-h2/pom.xml b/persistence-modules/spring-boot-persistence-h2/pom.xml index 7070b5e674..9e6c780931 100644 --- a/persistence-modules/spring-boot-persistence-h2/pom.xml +++ b/persistence-modules/spring-boot-persistence-h2/pom.xml @@ -40,11 +40,6 @@ db-util ${db-util.version} - - net.bytebuddy - byte-buddy - ${byte-buddy.version} - diff --git a/spring-5-mvc/pom.xml b/spring-5-mvc/pom.xml index 4b42528d0f..945ddef5e1 100644 --- a/spring-5-mvc/pom.xml +++ b/spring-5-mvc/pom.xml @@ -42,11 +42,6 @@ org.slf4j jcl-over-slf4j - - net.bytebuddy - byte-buddy - ${byte-buddy.version} - org.jetbrains.kotlin diff --git a/spring-boot-groovy/pom.xml b/spring-boot-groovy/pom.xml index f61398c5d6..9ea8d7b2a9 100644 --- a/spring-boot-groovy/pom.xml +++ b/spring-boot-groovy/pom.xml @@ -41,11 +41,6 @@ h2 runtime - - net.bytebuddy - byte-buddy-dep - 1.10.9 - diff --git a/spring-boot-modules/spring-boot-keycloak/pom.xml b/spring-boot-modules/spring-boot-keycloak/pom.xml index 8e917df2b7..68d4ec4b8f 100644 --- a/spring-boot-modules/spring-boot-keycloak/pom.xml +++ b/spring-boot-modules/spring-boot-keycloak/pom.xml @@ -41,10 +41,6 @@ org.springframework.boot spring-boot-starter-data-jpa - - net.bytebuddy - byte-buddy - org.springframework.boot diff --git a/spring-boot-rest/pom.xml b/spring-boot-rest/pom.xml index a8500d50f2..10dacf99e8 100644 --- a/spring-boot-rest/pom.xml +++ b/spring-boot-rest/pom.xml @@ -79,11 +79,6 @@ modelmapper ${modelmapper.version} - - net.bytebuddy - byte-buddy - ${byte-buddy.version} - diff --git a/spring-jinq/pom.xml b/spring-jinq/pom.xml index 073808823c..647c0907a7 100644 --- a/spring-jinq/pom.xml +++ b/spring-jinq/pom.xml @@ -37,12 +37,6 @@ spring-boot-starter-data-jpa - - net.bytebuddy - byte-buddy-dep - ${bytebuddy.version} - - org.springframework @@ -73,7 +67,6 @@ 1.8.29 - 1.10.10 diff --git a/spring-rest-hal-browser/pom.xml b/spring-rest-hal-browser/pom.xml index 32a0b52875..7b629dba44 100644 --- a/spring-rest-hal-browser/pom.xml +++ b/spring-rest-hal-browser/pom.xml @@ -35,11 +35,6 @@ com.h2database h2 - - net.bytebuddy - byte-buddy-dep - ${bytebuddy.version} - @@ -56,7 +51,6 @@ - 1.10.10 1.8 1.8 diff --git a/spring-security-modules/spring-security-mvc-boot-1/pom.xml b/spring-security-modules/spring-security-mvc-boot-1/pom.xml index b00b7bab32..7ad18376ec 100644 --- a/spring-security-modules/spring-security-mvc-boot-1/pom.xml +++ b/spring-security-modules/spring-security-mvc-boot-1/pom.xml @@ -106,10 +106,6 @@ ${ehcache-core.version} jar - - net.bytebuddy - byte-buddy - diff --git a/spring-social-login/pom.xml b/spring-social-login/pom.xml index 628f439cc0..0de20cd087 100644 --- a/spring-social-login/pom.xml +++ b/spring-social-login/pom.xml @@ -62,12 +62,6 @@ h2 - - net.bytebuddy - byte-buddy-dep - ${bytebuddy.version} - - @@ -102,7 +96,6 @@ - 1.10.9 2.0.3.RELEASE From de8acfd6e02afec5e466823b73865caab01c6f88 Mon Sep 17 00:00:00 2001 From: Chirag Dewan Date: Sun, 7 Jun 2020 15:29:59 +0530 Subject: [PATCH 095/140] BAEL3889 - Adding braces in EvenOddPartitioner --- .../java/com/baeldung/kafka/producer/EvenOddPartitioner.java | 5 +++-- .../main/java/com/baeldung/kafka/producer/KafkaProducer.java | 2 +- .../com/baeldung/kafka/producer/KafkaProducerUnitTest.java | 4 +++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/libraries-data-2/src/main/java/com/baeldung/kafka/producer/EvenOddPartitioner.java b/libraries-data-2/src/main/java/com/baeldung/kafka/producer/EvenOddPartitioner.java index 12c86828dd..1c77226037 100644 --- a/libraries-data-2/src/main/java/com/baeldung/kafka/producer/EvenOddPartitioner.java +++ b/libraries-data-2/src/main/java/com/baeldung/kafka/producer/EvenOddPartitioner.java @@ -1,4 +1,4 @@ -package com.baeldung.kafka; +package com.baeldung.kafka.producer; import org.apache.kafka.clients.producer.internals.DefaultPartitioner; import org.apache.kafka.common.Cluster; @@ -8,8 +8,9 @@ public class EvenOddPartitioner extends DefaultPartitioner { @Override public int partition(String topic, Object key, byte[] keyBytes, Object value, byte[] valueBytes, Cluster cluster) { - if (((String)key).length() % 2 == 0) + if (((String) key).length() % 2 == 0) { return 0; + } return 1; } diff --git a/libraries-data-2/src/main/java/com/baeldung/kafka/producer/KafkaProducer.java b/libraries-data-2/src/main/java/com/baeldung/kafka/producer/KafkaProducer.java index 8574cd1c40..911c9ed3d7 100644 --- a/libraries-data-2/src/main/java/com/baeldung/kafka/producer/KafkaProducer.java +++ b/libraries-data-2/src/main/java/com/baeldung/kafka/producer/KafkaProducer.java @@ -1,4 +1,4 @@ -package com.baeldung.kafka; +package com.baeldung.kafka.producer; import org.apache.kafka.clients.producer.Producer; import org.apache.kafka.clients.producer.ProducerRecord; diff --git a/libraries-data-2/src/test/java/com/baeldung/kafka/producer/KafkaProducerUnitTest.java b/libraries-data-2/src/test/java/com/baeldung/kafka/producer/KafkaProducerUnitTest.java index ce3803322c..a7156ed886 100644 --- a/libraries-data-2/src/test/java/com/baeldung/kafka/producer/KafkaProducerUnitTest.java +++ b/libraries-data-2/src/test/java/com/baeldung/kafka/producer/KafkaProducerUnitTest.java @@ -1,5 +1,7 @@ -package com.baeldung.kafka; +package com.baeldung.kafka.producer; +import com.baeldung.kafka.producer.EvenOddPartitioner; +import com.baeldung.kafka.producer.KafkaProducer; import org.apache.kafka.clients.producer.MockProducer; import org.apache.kafka.clients.producer.RecordMetadata; import org.apache.kafka.common.Cluster; From 6f21d2eb744f49decc035abd12bf25835b7a2f7e Mon Sep 17 00:00:00 2001 From: mikr Date: Sun, 7 Jun 2020 12:13:32 +0200 Subject: [PATCH 096/140] JAVA-1749 Update UUID article and code --- .../java/com/baeldung/uuid/UUIDGenerator.java | 134 ++++++++++++------ .../baeldung/uuid/UUIDGeneratorUnitTest.java | 64 +++++++++ 2 files changed, 156 insertions(+), 42 deletions(-) create mode 100644 core-java-modules/core-java/src/test/java/com/baeldung/uuid/UUIDGeneratorUnitTest.java diff --git a/core-java-modules/core-java/src/main/java/com/baeldung/uuid/UUIDGenerator.java b/core-java-modules/core-java/src/main/java/com/baeldung/uuid/UUIDGenerator.java index 2659b29491..cb43a26929 100644 --- a/core-java-modules/core-java/src/main/java/com/baeldung/uuid/UUIDGenerator.java +++ b/core-java-modules/core-java/src/main/java/com/baeldung/uuid/UUIDGenerator.java @@ -3,30 +3,57 @@ package com.baeldung.uuid; import java.io.UnsupportedEncodingException; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; +import java.time.Duration; +import java.time.LocalDateTime; import java.util.Arrays; +import java.util.Random; import java.util.UUID; public class UUIDGenerator { - /** - * These are predefined UUID for name spaces - */ - private static final String NAMESPACE_DNS = "6ba7b810-9dad-11d1-80b4-00c04fd430c8"; - private static final String NAMESPACE_URL = "6ba7b811-9dad-11d1-80b4-00c04fd430c8"; - private static final String NAMESPACE_OID = "6ba7b812-9dad-11d1-80b4-00c04fd430c8"; - private static final String NAMESPACE_X500 = "6ba7b814-9dad-11d1-80b4-00c04fd430c8"; - private static final char[] hexArray = "0123456789ABCDEF".toCharArray(); - public static void main(String[] args) { - try { - System.out.println("Type 3 : " + generateType3UUID(NAMESPACE_DNS, "google.com")); - System.out.println("Type 4 : " + generateType4UUID()); - System.out.println("Type 5 : " + generateType5UUID(NAMESPACE_URL, "google.com")); - System.out.println("Unique key : " + generateUniqueKeysWithUUIDAndMessageDigest()); - } catch (NoSuchAlgorithmException | UnsupportedEncodingException e) { - e.printStackTrace(); - } + /** + * Type 1 UUID Generation + */ + public static UUID generateType1UUID() { + + long most64SigBits = get64MostSignificantBitsForVersion1(); + long least64SigBits = get64LeastSignificantBitsForVersion1(); + + return new UUID(most64SigBits, least64SigBits); + } + + private static long get64LeastSignificantBitsForVersion1() { + Random random = new Random(); + long random63BitLong = random.nextLong() & 0x3FFFFFFFFFFFFFFFL; + long variant3BitFlag = 0x8000000000000000L; + return random63BitLong + variant3BitFlag; + } + + private static long get64MostSignificantBitsForVersion1() { + LocalDateTime start = LocalDateTime.of(1582, 10, 15, 0, 0, 0); + Duration duration = Duration.between(start, LocalDateTime.now()); + long seconds = duration.getSeconds(); + long nanos = duration.getNano(); + long timeForUuidIn100Nanos = seconds * 10000000 + nanos * 100; + long least12SignificatBitOfTime = (timeForUuidIn100Nanos & 0x000000000000FFFFL) >> 4; + long version = 1 << 12; + return (timeForUuidIn100Nanos & 0xFFFFFFFFFFFF0000L) + version + least12SignificatBitOfTime; + } + + /** + * Type 3 UUID Generation + * + * @throws UnsupportedEncodingException + */ + public static UUID generateType3UUID(String namespace, String name) throws UnsupportedEncodingException { + + byte[] nameSpaceBytes = bytesFromUUID(namespace); + byte[] nameBytes = name.getBytes("UTF-8"); + byte[] result = joinBytes(nameSpaceBytes, nameBytes); + + return UUID.nameUUIDFromBytes(result); } /** @@ -37,28 +64,18 @@ public class UUIDGenerator { return uuid; } - /** - * Type 3 UUID Generation - * - * @throws UnsupportedEncodingException - */ - public static UUID generateType3UUID(String namespace, String name) throws UnsupportedEncodingException { - String source = namespace + name; - byte[] bytes = source.getBytes("UTF-8"); - UUID uuid = UUID.nameUUIDFromBytes(bytes); - return uuid; - } - /** * Type 5 UUID Generation - * - * @throws UnsupportedEncodingException + * + * @throws UnsupportedEncodingException */ public static UUID generateType5UUID(String namespace, String name) throws UnsupportedEncodingException { - String source = namespace + name; - byte[] bytes = source.getBytes("UTF-8"); - UUID uuid = type5UUIDFromBytes(bytes); - return uuid; + + byte[] nameSpaceBytes = bytesFromUUID(namespace); + byte[] nameBytes = name.getBytes("UTF-8"); + byte[] result = joinBytes(nameSpaceBytes, nameBytes); + + return type5UUIDFromBytes(result); } public static UUID type5UUIDFromBytes(byte[] name) { @@ -91,20 +108,20 @@ public class UUIDGenerator { /** * Unique Keys Generation Using Message Digest and Type 4 UUID - * - * @throws NoSuchAlgorithmException - * @throws UnsupportedEncodingException + * + * @throws NoSuchAlgorithmException + * @throws UnsupportedEncodingException */ public static String generateUniqueKeysWithUUIDAndMessageDigest() throws NoSuchAlgorithmException, UnsupportedEncodingException { MessageDigest salt = MessageDigest.getInstance("SHA-256"); salt.update(UUID.randomUUID() - .toString() - .getBytes("UTF-8")); + .toString() + .getBytes("UTF-8")); String digest = bytesToHex(salt.digest()); return digest; } - public static String bytesToHex(byte[] bytes) { + private static String bytesToHex(byte[] bytes) { char[] hexChars = new char[bytes.length * 2]; for (int j = 0; j < bytes.length; j++) { int v = bytes[j] & 0xFF; @@ -114,4 +131,37 @@ public class UUIDGenerator { return new String(hexChars); } -} + private static byte[] bytesFromUUID(String uuidHexString) { + String normalizedUUIDHexString = uuidHexString.replace("-",""); + + assert normalizedUUIDHexString.length() == 32; + + byte[] bytes = new byte[16]; + for (int i = 0; i < 16; i++) { + byte b = hexToByte(normalizedUUIDHexString.substring(i*2, i*2+2)); + bytes[i] = b; + } + return bytes; + } + + public static byte hexToByte(String hexString) { + int firstDigit = Character.digit(hexString.charAt(0),16); + int secondDigit = Character.digit(hexString.charAt(1),16); + return (byte) ((firstDigit << 4) + secondDigit); + } + + public static byte[] joinBytes(byte[] byteArray1, byte[] byteArray2) { + int finalLength = byteArray1.length + byteArray2.length; + byte[] result = new byte[finalLength]; + + for(int i = 0; i < byteArray1.length; i++) { + result[i] = byteArray1[i]; + } + + for(int i = 0; i < byteArray2.length; i++) { + result[byteArray1.length+i] = byteArray2[i]; + } + + return result; + } +} \ No newline at end of file diff --git a/core-java-modules/core-java/src/test/java/com/baeldung/uuid/UUIDGeneratorUnitTest.java b/core-java-modules/core-java/src/test/java/com/baeldung/uuid/UUIDGeneratorUnitTest.java new file mode 100644 index 0000000000..9e08363a63 --- /dev/null +++ b/core-java-modules/core-java/src/test/java/com/baeldung/uuid/UUIDGeneratorUnitTest.java @@ -0,0 +1,64 @@ +package com.baeldung.uuid; + +import org.junit.jupiter.api.Test; + +import java.io.UnsupportedEncodingException; +import java.util.UUID; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +class UUIDGeneratorUnitTest { + + private static final String NAMESPACE_URL = "6ba7b811-9dad-11d1-80b4-00c04fd430c8"; + private static final String NAMESPACE_DNS = "6ba7b810-9dad-11d1-80b4-00c04fd430c8"; + + @Test + public void version_1_UUID_is_generated_with_correct_length_version_and_variant() { + + UUID uuid = UUIDGenerator.generateType1UUID(); + + assertEquals(36, uuid.toString().length()); + assertEquals(1, uuid.version()); + assertEquals(2, uuid.variant()); + } + + @Test + public void version_3_UUID_is_correctly_generated_for_domain_baeldung_com() throws UnsupportedEncodingException { + + UUID uuid = UUIDGenerator.generateType3UUID(NAMESPACE_DNS, "baeldung.com"); + + assertEquals("23785b78-0132-3ac6-aff6-cfd5be162139", uuid.toString()); + assertEquals(3, uuid.version()); + assertEquals(2, uuid.variant()); + } + + @Test + public void version_3_UUID_is_correctly_generated_for_domain_d() throws UnsupportedEncodingException { + + UUID uuid = UUIDGenerator.generateType3UUID(NAMESPACE_DNS, "d"); + + assertEquals("dbd41ecb-f466-33de-b309-1468addfc63b", uuid.toString()); + assertEquals(3, uuid.version()); + assertEquals(2, uuid.variant()); + } + + @Test + public void version_4_UUID_is_generated_with_correct_length_version_and_variant() { + + UUID uuid = UUIDGenerator.generateType4UUID(); + + assertEquals(36, uuid.toString().length()); + assertEquals(4, uuid.version()); + assertEquals(2, uuid.variant()); + } + + @Test + public void version_5_UUID_is_correctly_generated_for_domain_baeldung_com() throws UnsupportedEncodingException { + + UUID uuid = UUIDGenerator.generateType5UUID(NAMESPACE_URL, "baeldung.com"); + + assertEquals("aeff44a5-8a61-52b6-bcbe-c8e5bd7d0300", uuid.toString()); + assertEquals(5, uuid.version()); + assertEquals(2, uuid.variant()); + } +} \ No newline at end of file From 46ebcba3a04c72b526fabdf90801319c87c9016c Mon Sep 17 00:00:00 2001 From: mikr Date: Sun, 7 Jun 2020 13:22:16 +0200 Subject: [PATCH 097/140] JAVA-1749 Move modules language interop and console --- core-java-modules/core-java-console/README.md | 5 + core-java-modules/core-java-console/pom.xml | 142 ++++++++++++++++++ .../java/com/baeldung/asciiart/AsciiArt.java | 0 .../baeldung/console/ConsoleConsoleClass.java | 0 .../baeldung/console/ConsoleScannerClass.java | 0 .../com/baeldung/printf/PrintfExamples.java | 0 .../asciiart/AsciiArtIntegrationTest.java | 7 +- core-java-modules/core-java/README.md | 60 ++++++++ language-interop/README.md | 1 + .../src/main/resources/js/bind.js | 0 .../src/main/resources/js/locations.js | 0 .../src/main/resources/js/math_module.js | 0 .../src/main/resources/js/no_such.js | 0 .../src/main/resources/js/script.js | 0 .../src/main/resources/js/trim.js | 0 .../src/main/resources/js/typed_arrays.js | 0 .../interop/javascript}/NashornUnitTest.java | 8 +- 17 files changed, 214 insertions(+), 9 deletions(-) create mode 100644 core-java-modules/core-java-console/README.md create mode 100644 core-java-modules/core-java-console/pom.xml rename core-java-modules/{core-java => core-java-console}/src/main/java/com/baeldung/asciiart/AsciiArt.java (100%) rename core-java-modules/{core-java => core-java-console}/src/main/java/com/baeldung/console/ConsoleConsoleClass.java (100%) rename core-java-modules/{core-java => core-java-console}/src/main/java/com/baeldung/console/ConsoleScannerClass.java (100%) rename core-java-modules/{core-java => core-java-console}/src/main/java/com/baeldung/printf/PrintfExamples.java (100%) rename core-java-modules/{core-java => core-java-console}/src/test/java/com/baeldung/asciiart/AsciiArtIntegrationTest.java (89%) rename {core-java-modules/core-java => language-interop}/src/main/resources/js/bind.js (100%) rename {core-java-modules/core-java => language-interop}/src/main/resources/js/locations.js (100%) rename {core-java-modules/core-java => language-interop}/src/main/resources/js/math_module.js (100%) rename {core-java-modules/core-java => language-interop}/src/main/resources/js/no_such.js (100%) rename {core-java-modules/core-java => language-interop}/src/main/resources/js/script.js (100%) rename {core-java-modules/core-java => language-interop}/src/main/resources/js/trim.js (100%) rename {core-java-modules/core-java => language-interop}/src/main/resources/js/typed_arrays.js (100%) rename {core-java-modules/core-java/src/test/java/com/baeldung/scripting => language-interop/src/test/java/com/baeldung/language/interop/javascript}/NashornUnitTest.java (94%) diff --git a/core-java-modules/core-java-console/README.md b/core-java-modules/core-java-console/README.md new file mode 100644 index 0000000000..725e2482bb --- /dev/null +++ b/core-java-modules/core-java-console/README.md @@ -0,0 +1,5 @@ +#Core Java Console + +[Read and Write User Input in Java](http://www.baeldung.com/java-console-input-output) +[Formatting with printf() in Java](https://www.baeldung.com/java-printstream-printf) +[ASCII Art in Java](http://www.baeldung.com/ascii-art-in-java) \ No newline at end of file diff --git a/core-java-modules/core-java-console/pom.xml b/core-java-modules/core-java-console/pom.xml new file mode 100644 index 0000000000..1d58d8c253 --- /dev/null +++ b/core-java-modules/core-java-console/pom.xml @@ -0,0 +1,142 @@ + + + 4.0.0 + core-java-console + 0.1.0-SNAPSHOT + core-java-console + jar + + com.baeldung.core-java-modules + core-java-modules + 0.0.1-SNAPSHOT + ../ + + + + core-java-console + + + src/main/resources + true + + + + + + org.apache.maven.plugins + maven-dependency-plugin + + + copy-dependencies + prepare-package + + copy-dependencies + + + ${project.build.directory}/libs + + + + + + + org.codehaus.mojo + exec-maven-plugin + ${exec-maven-plugin.version} + + java + com.baeldung.outofmemoryerror.OutOfMemoryGCLimitExceed + + -Xmx300m + -XX:+UseParallelGC + -classpath + + com.baeldung.outofmemoryerror.OutOfMemoryGCLimitExceed + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + ${maven-javadoc-plugin.version} + + ${source.version} + ${target.version} + + + + + + + + integration + + + + org.apache.maven.plugins + maven-surefire-plugin + + + integration-test + + test + + + + **/*ManualTest.java + + + **/*IntegrationTest.java + **/*IntTest.java + + + + + + + json + + + + + org.codehaus.mojo + exec-maven-plugin + ${exec-maven-plugin.version} + + + run-benchmarks + + none + + exec + + + test + java + + -classpath + + org.openjdk.jmh.Main + .* + + + + + + + + + + + + 3.0.0-M1 + 1.6.0 + 1.8 + 1.8 + + + diff --git a/core-java-modules/core-java/src/main/java/com/baeldung/asciiart/AsciiArt.java b/core-java-modules/core-java-console/src/main/java/com/baeldung/asciiart/AsciiArt.java similarity index 100% rename from core-java-modules/core-java/src/main/java/com/baeldung/asciiart/AsciiArt.java rename to core-java-modules/core-java-console/src/main/java/com/baeldung/asciiart/AsciiArt.java diff --git a/core-java-modules/core-java/src/main/java/com/baeldung/console/ConsoleConsoleClass.java b/core-java-modules/core-java-console/src/main/java/com/baeldung/console/ConsoleConsoleClass.java similarity index 100% rename from core-java-modules/core-java/src/main/java/com/baeldung/console/ConsoleConsoleClass.java rename to core-java-modules/core-java-console/src/main/java/com/baeldung/console/ConsoleConsoleClass.java diff --git a/core-java-modules/core-java/src/main/java/com/baeldung/console/ConsoleScannerClass.java b/core-java-modules/core-java-console/src/main/java/com/baeldung/console/ConsoleScannerClass.java similarity index 100% rename from core-java-modules/core-java/src/main/java/com/baeldung/console/ConsoleScannerClass.java rename to core-java-modules/core-java-console/src/main/java/com/baeldung/console/ConsoleScannerClass.java diff --git a/core-java-modules/core-java/src/main/java/com/baeldung/printf/PrintfExamples.java b/core-java-modules/core-java-console/src/main/java/com/baeldung/printf/PrintfExamples.java similarity index 100% rename from core-java-modules/core-java/src/main/java/com/baeldung/printf/PrintfExamples.java rename to core-java-modules/core-java-console/src/main/java/com/baeldung/printf/PrintfExamples.java diff --git a/core-java-modules/core-java/src/test/java/com/baeldung/asciiart/AsciiArtIntegrationTest.java b/core-java-modules/core-java-console/src/test/java/com/baeldung/asciiart/AsciiArtIntegrationTest.java similarity index 89% rename from core-java-modules/core-java/src/test/java/com/baeldung/asciiart/AsciiArtIntegrationTest.java rename to core-java-modules/core-java-console/src/test/java/com/baeldung/asciiart/AsciiArtIntegrationTest.java index 8ab1695395..4bfcbe5a36 100644 --- a/core-java-modules/core-java/src/test/java/com/baeldung/asciiart/AsciiArtIntegrationTest.java +++ b/core-java-modules/core-java-console/src/test/java/com/baeldung/asciiart/AsciiArtIntegrationTest.java @@ -1,10 +1,9 @@ package com.baeldung.asciiart; -import java.awt.Font; - +import com.baeldung.asciiart.AsciiArt.Settings; import org.junit.Test; -import com.baeldung.asciiart.AsciiArt.Settings; +import java.awt.*; public class AsciiArtIntegrationTest { @@ -15,6 +14,8 @@ public class AsciiArtIntegrationTest { Settings settings = asciiArt.new Settings(new Font("SansSerif", Font.BOLD, 24), text.length() * 30, 30); // 30 pixel width per character asciiArt.drawString(text, "*", settings); + + throw new NullPointerException(); } } diff --git a/core-java-modules/core-java/README.md b/core-java-modules/core-java/README.md index bffb88cafb..2123a61499 100644 --- a/core-java-modules/core-java/README.md +++ b/core-java-modules/core-java/README.md @@ -33,3 +33,63 @@ - [Making a JSON POST Request With HttpURLConnection](https://www.baeldung.com/httpurlconnection-post) - [How to Find an Exception’s Root Cause in Java](https://www.baeldung.com/java-exception-root-cause) - [Convert Hex to ASCII in Java](https://www.baeldung.com/java-convert-hex-to-ascii) + + +#New module structure +########################### + +#Leave in core-java: +[Getting Started with Java Properties](http://www.baeldung.com/java-properties) +[Java Money and the Currency API](http://www.baeldung.com/java-money-and-currency) +[Introduction to Java Serialization](http://www.baeldung.com/java-serialization) +[Guide to UUID in Java](http://www.baeldung.com/java-uuid) +[Compiling Java *.class Files with javac](http://www.baeldung.com/javac) +[Introduction to Javadoc](http://www.baeldung.com/javadoc) +[Guide to the Externalizable Interface in Java](http://www.baeldung.com/java-externalizable) +[What is the serialVersionUID?](http://www.baeldung.com/java-serial-version-uid) +[A Guide to the ResourceBundle](http://www.baeldung.com/java-resourcebundle) +[Merging java.util.Properties Objects](https://www.baeldung.com/java-merging-properties) + +#Move to language interop (Done) +[Introduction to Nashorn](http://www.baeldung.com/java-nashorn) + +#Move to new new package: core-java-console (Done) +[Read and Write User Input in Java](http://www.baeldung.com/java-console-input-output) +[Formatting with printf() in Java](https://www.baeldung.com/java-printstream-printf) +[ASCII Art in Java](http://www.baeldung.com/ascii-art-in-java) + +#Move to core-java-string-operations-2 +[Guide to Character Encoding](https://www.baeldung.com/java-char-encoding) +[Convert Hex to ASCII in Java](https://www.baeldung.com/java-convert-hex-to-ascii) #remove additional readme file + +#Move to core-javadatetime-operations-2 +[Finding Leap Years in Java](https://www.baeldung.com/java-leap-year) + +#Move to core-java-time-measurements +[Java Timer](http://www.baeldung.com/java-timer-and-timertask) + +#Move to core-java-reflection +[How to Get a Name of a Method Being Executed?](http://www.baeldung.com/java-name-of-executing-method) + +#Move to core-java-streams +[How to Find all Getters Returning Null](http://www.baeldung.com/java-getters-returning-null) + +#Move to core-java-jvm +[How to Get the Size of an Object in Java](http://www.baeldung.com/java-size-of-object) + +#Move to data-structures module +[Graphs in Java](https://www.baeldung.com/java-graphs) + +#Move to core-java-collections-3 +[Quick Guide to the Java Stack](https://www.baeldung.com/java-stack) + +#These are already in another module +[Using Curl in Java](https://www.baeldung.com/java-curl) #Core Java Networking (Part 2) +[Creating a Java Compiler Plugin](http://www.baeldung.com/java-build-compiler-plugin) # Core Java Sun +[Java Global Exception Handler](http://www.baeldung.com/java-global-exception-handler) #Core Java Exceptions +[Java – Try with Resources](https://www.baeldung.com/java-try-with-resources) #Core Java Exceptions +[How to Find an Exception’s Root Cause in Java](https://www.baeldung.com/java-exception-root-cause) #Core Java Exceptions +[JVM Log Forging](http://www.baeldung.com/jvm-log-forging) #Core Java JVM +[Making a JSON POST Request With HttpURLConnection](https://www.baeldung.com/httpurlconnection-post) #Core Java Networking (Part 2) +[Common Java Exceptions](http://www.baeldung.com/java-common-exceptions) #Core Java Exceptions +[Retrieve Fields from a Java Class Using Reflection](https://www.baeldung.com/java-reflection-class-fields) #Core Java Reflection \ No newline at end of file diff --git a/language-interop/README.md b/language-interop/README.md index 458f34a119..f4f2fc0816 100644 --- a/language-interop/README.md +++ b/language-interop/README.md @@ -5,3 +5,4 @@ This module contains articles about Java interop with other language integration ### Relevant Articles: - [How to Call Python From Java](https://www.baeldung.com/java-working-with-python) +- [Introduction to Nashorn](http://www.baeldung.com/java-nashorn) diff --git a/core-java-modules/core-java/src/main/resources/js/bind.js b/language-interop/src/main/resources/js/bind.js similarity index 100% rename from core-java-modules/core-java/src/main/resources/js/bind.js rename to language-interop/src/main/resources/js/bind.js diff --git a/core-java-modules/core-java/src/main/resources/js/locations.js b/language-interop/src/main/resources/js/locations.js similarity index 100% rename from core-java-modules/core-java/src/main/resources/js/locations.js rename to language-interop/src/main/resources/js/locations.js diff --git a/core-java-modules/core-java/src/main/resources/js/math_module.js b/language-interop/src/main/resources/js/math_module.js similarity index 100% rename from core-java-modules/core-java/src/main/resources/js/math_module.js rename to language-interop/src/main/resources/js/math_module.js diff --git a/core-java-modules/core-java/src/main/resources/js/no_such.js b/language-interop/src/main/resources/js/no_such.js similarity index 100% rename from core-java-modules/core-java/src/main/resources/js/no_such.js rename to language-interop/src/main/resources/js/no_such.js diff --git a/core-java-modules/core-java/src/main/resources/js/script.js b/language-interop/src/main/resources/js/script.js similarity index 100% rename from core-java-modules/core-java/src/main/resources/js/script.js rename to language-interop/src/main/resources/js/script.js diff --git a/core-java-modules/core-java/src/main/resources/js/trim.js b/language-interop/src/main/resources/js/trim.js similarity index 100% rename from core-java-modules/core-java/src/main/resources/js/trim.js rename to language-interop/src/main/resources/js/trim.js diff --git a/core-java-modules/core-java/src/main/resources/js/typed_arrays.js b/language-interop/src/main/resources/js/typed_arrays.js similarity index 100% rename from core-java-modules/core-java/src/main/resources/js/typed_arrays.js rename to language-interop/src/main/resources/js/typed_arrays.js diff --git a/core-java-modules/core-java/src/test/java/com/baeldung/scripting/NashornUnitTest.java b/language-interop/src/test/java/com/baeldung/language/interop/javascript/NashornUnitTest.java similarity index 94% rename from core-java-modules/core-java/src/test/java/com/baeldung/scripting/NashornUnitTest.java rename to language-interop/src/test/java/com/baeldung/language/interop/javascript/NashornUnitTest.java index 9abe8a927c..a9e4243f9d 100644 --- a/core-java-modules/core-java/src/test/java/com/baeldung/scripting/NashornUnitTest.java +++ b/language-interop/src/test/java/com/baeldung/language/interop/javascript/NashornUnitTest.java @@ -1,14 +1,10 @@ -package com.baeldung.scripting; +package com.baeldung.language.interop.javascript; import org.junit.Assert; import org.junit.Before; import org.junit.Test; -import javax.script.Bindings; -import javax.script.Invocable; -import javax.script.ScriptEngine; -import javax.script.ScriptEngineManager; -import javax.script.ScriptException; +import javax.script.*; import java.io.InputStreamReader; import java.util.List; import java.util.Map; From 978a32d0a21d6b53264327b634063e4caab721be Mon Sep 17 00:00:00 2001 From: Ricardo Caldas Date: Sun, 7 Jun 2020 10:00:48 -0300 Subject: [PATCH 098/140] [BAEL-4136] What is this: [Ljava.lang.Object;? Code article --- .../JavaArraysToStringUnitTest.java | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 core-java-modules/core-java-io-conversions-2/src/test/java/com/baeldung/arraystostring/JavaArraysToStringUnitTest.java diff --git a/core-java-modules/core-java-io-conversions-2/src/test/java/com/baeldung/arraystostring/JavaArraysToStringUnitTest.java b/core-java-modules/core-java-io-conversions-2/src/test/java/com/baeldung/arraystostring/JavaArraysToStringUnitTest.java new file mode 100644 index 0000000000..2c81b1358b --- /dev/null +++ b/core-java-modules/core-java-io-conversions-2/src/test/java/com/baeldung/arraystostring/JavaArraysToStringUnitTest.java @@ -0,0 +1,36 @@ +package com.baeldung.arraystostring; + +import org.junit.Test; + +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +public class JavaArraysToStringUnitTest { + + @Test public void givenInstanceOfArray_whenTryingToConvertToString_thenNameOfClassIsShown() { + Object[] arrayOfObjects = { "John", 2, true }; + assertTrue(arrayOfObjects.toString().startsWith("[Ljava.lang.Object;")); + } + + @Test public void givenInstanceOfArray_useArraysToStringToConvert_thenValueOfObjectsAreShown() { + Object[] arrayOfObjects = { "John", 2, true }; + assertEquals(Arrays.toString(arrayOfObjects), "[John, 2, true]"); + } + + @Test public void givenInstanceOfDeepArray_userArraysDeepToStringToConvert_thenValueOfInnerObjectsAreShown() { + Object[] innerArray = { "We", "Are", "Inside" }; + Object[] arrayOfObjects = { "John", 2, innerArray }; + assertEquals(Arrays.deepToString(arrayOfObjects), "[John, 2, [We, Are, Inside]]"); + } + + @Test public void givenInstanceOfDeepArray_useStreamsToConvert_thenValueOfObjectsAreShown() { + Object[] arrayOfObjects = { "John", 2, true }; + List listOfString = Stream.of(arrayOfObjects).map(Object::toString).collect(Collectors.toList()); + assertEquals(listOfString.toString(), "[John, 2, true]"); + } +} From 5a753ba3842c44462d49ec546979ad57bf8f16c0 Mon Sep 17 00:00:00 2001 From: mikr Date: Sun, 7 Jun 2020 16:52:25 +0200 Subject: [PATCH 099/140] JAVA-1522 Split core-java-modules/core-java module --- .../core-java-collections-3/README.md | 1 + .../collections}/stack/StackUnitTest.java | 0 .../asciiart/AsciiArtIntegrationTest.java | 3 - .../core-java-date-operations-2/README.md | 1 + .../baeldung/leapyear/LeapYearUnitTest.java | 0 core-java-modules/core-java-jvm/README.md | 1 + .../objectsize/InstrumentationAgent.java | 0 .../objectsize/InstrumentationExample.java | 0 .../java/com/baeldung/objectsize/MANIFEST.MF | 0 .../core-java-reflection/README.MD | 2 + ...CurrentlyExecutedMethodFinderUnitTest.java | 0 .../core-java-string-operations-2/README.md | 2 + .../encoding/CharacterEncodingExamples.java | 0 .../hexToAscii/HexToAsciiUnitTest.java | 0 .../java/com/baeldung/hexToAscii/README.md | 0 .../src/test/resources/output.pdf | Bin 0 -> 142786 bytes .../core-java-time-measurements/README.md | 1 + .../baeldung/timer/DatabaseMigrationTask.java | 0 .../com/baeldung/timer/NewsletterTask.java | 0 .../{java => }/clock/ClockUnitTest.java | 2 +- .../timer/DatabaseMigrationTaskUnitTest.java | 0 .../timer/JavaTimerLongRunningUnitTest.java | 0 .../timer/NewsletterTaskUnitTest.java | 0 core-java-modules/core-java/README.md | 82 ------------------ data-structures/README.md | 1 + .../main/java/com/baeldung/graph/Graph.java | 0 .../com/baeldung/graph/GraphTraversal.java | 0 .../com/baeldung/graph/GraphUnitTest.java | 0 28 files changed, 10 insertions(+), 86 deletions(-) rename core-java-modules/{core-java/src/test/java/com/baeldung => core-java-collections-3/src/test/java/com/baeldung/collections}/stack/StackUnitTest.java (100%) rename core-java-modules/{core-java => core-java-date-operations-2}/src/test/java/com/baeldung/leapyear/LeapYearUnitTest.java (100%) rename core-java-modules/{core-java => core-java-jvm}/src/main/java/com/baeldung/objectsize/InstrumentationAgent.java (100%) rename core-java-modules/{core-java => core-java-jvm}/src/main/java/com/baeldung/objectsize/InstrumentationExample.java (100%) rename core-java-modules/{core-java => core-java-jvm}/src/main/java/com/baeldung/objectsize/MANIFEST.MF (100%) rename core-java-modules/{core-java/src/test/java/com/baeldung/java => core-java-reflection/src/test/java/com/baeldung}/currentmethod/CurrentlyExecutedMethodFinderUnitTest.java (100%) rename core-java-modules/{core-java => core-java-string-operations-2}/src/main/java/com/baeldung/encoding/CharacterEncodingExamples.java (100%) rename core-java-modules/{core-java => core-java-string-operations-2}/src/test/java/com/baeldung/hexToAscii/HexToAsciiUnitTest.java (100%) rename core-java-modules/{core-java => core-java-string-operations-2}/src/test/java/com/baeldung/hexToAscii/README.md (100%) create mode 100644 core-java-modules/core-java-string-operations-2/src/test/resources/output.pdf rename core-java-modules/{core-java => core-java-time-measurements}/src/main/java/com/baeldung/timer/DatabaseMigrationTask.java (100%) rename core-java-modules/{core-java => core-java-time-measurements}/src/main/java/com/baeldung/timer/NewsletterTask.java (100%) rename core-java-modules/core-java-time-measurements/src/test/java/com/baeldung/{java => }/clock/ClockUnitTest.java (99%) rename core-java-modules/{core-java => core-java-time-measurements}/src/test/java/com/baeldung/timer/DatabaseMigrationTaskUnitTest.java (100%) rename core-java-modules/{core-java => core-java-time-measurements}/src/test/java/com/baeldung/timer/JavaTimerLongRunningUnitTest.java (100%) rename core-java-modules/{core-java => core-java-time-measurements}/src/test/java/com/baeldung/timer/NewsletterTaskUnitTest.java (100%) rename {core-java-modules/core-java => data-structures}/src/main/java/com/baeldung/graph/Graph.java (100%) rename {core-java-modules/core-java => data-structures}/src/main/java/com/baeldung/graph/GraphTraversal.java (100%) rename {core-java-modules/core-java => data-structures}/src/test/java/com/baeldung/graph/GraphUnitTest.java (100%) diff --git a/core-java-modules/core-java-collections-3/README.md b/core-java-modules/core-java-collections-3/README.md index 9218384640..fb983d9abc 100644 --- a/core-java-modules/core-java-collections-3/README.md +++ b/core-java-modules/core-java-collections-3/README.md @@ -9,3 +9,4 @@ - [Differences Between Collection.clear() and Collection.removeAll()](https://www.baeldung.com/java-collection-clear-vs-removeall) - [Performance of contains() in a HashSet vs ArrayList](https://www.baeldung.com/java-hashset-arraylist-contains-performance) - [Fail-Safe Iterator vs Fail-Fast Iterator](https://www.baeldung.com/java-fail-safe-vs-fail-fast-iterator) +- [Quick Guide to the Java Stack](https://www.baeldung.com/java-stack) diff --git a/core-java-modules/core-java/src/test/java/com/baeldung/stack/StackUnitTest.java b/core-java-modules/core-java-collections-3/src/test/java/com/baeldung/collections/stack/StackUnitTest.java similarity index 100% rename from core-java-modules/core-java/src/test/java/com/baeldung/stack/StackUnitTest.java rename to core-java-modules/core-java-collections-3/src/test/java/com/baeldung/collections/stack/StackUnitTest.java diff --git a/core-java-modules/core-java-console/src/test/java/com/baeldung/asciiart/AsciiArtIntegrationTest.java b/core-java-modules/core-java-console/src/test/java/com/baeldung/asciiart/AsciiArtIntegrationTest.java index 4bfcbe5a36..a8c42fbeb1 100644 --- a/core-java-modules/core-java-console/src/test/java/com/baeldung/asciiart/AsciiArtIntegrationTest.java +++ b/core-java-modules/core-java-console/src/test/java/com/baeldung/asciiart/AsciiArtIntegrationTest.java @@ -14,8 +14,5 @@ public class AsciiArtIntegrationTest { Settings settings = asciiArt.new Settings(new Font("SansSerif", Font.BOLD, 24), text.length() * 30, 30); // 30 pixel width per character asciiArt.drawString(text, "*", settings); - - throw new NullPointerException(); } - } diff --git a/core-java-modules/core-java-date-operations-2/README.md b/core-java-modules/core-java-date-operations-2/README.md index 19c7b98d30..6dc1302d99 100644 --- a/core-java-modules/core-java-date-operations-2/README.md +++ b/core-java-modules/core-java-date-operations-2/README.md @@ -8,4 +8,5 @@ This module contains articles about date operations in Java. - [Converting Java Date to OffsetDateTime](https://www.baeldung.com/java-convert-date-to-offsetdatetime) - [How to Set the JVM Time Zone](https://www.baeldung.com/java-jvm-time-zone) - [How to determine day of week by passing specific date in Java?](https://www.baeldung.com/java-get-day-of-week) +- [Finding Leap Years in Java](https://www.baeldung.com/java-leap-year) - [[<-- Prev]](/core-java-modules/core-java-date-operations-1) diff --git a/core-java-modules/core-java/src/test/java/com/baeldung/leapyear/LeapYearUnitTest.java b/core-java-modules/core-java-date-operations-2/src/test/java/com/baeldung/leapyear/LeapYearUnitTest.java similarity index 100% rename from core-java-modules/core-java/src/test/java/com/baeldung/leapyear/LeapYearUnitTest.java rename to core-java-modules/core-java-date-operations-2/src/test/java/com/baeldung/leapyear/LeapYearUnitTest.java diff --git a/core-java-modules/core-java-jvm/README.md b/core-java-modules/core-java-jvm/README.md index 2f80ea7372..0dae790ec0 100644 --- a/core-java-modules/core-java-jvm/README.md +++ b/core-java-modules/core-java-jvm/README.md @@ -12,3 +12,4 @@ This module contains articles about working with the Java Virtual Machine (JVM). - [Guide to System.gc()](https://www.baeldung.com/java-system-gc) - [Runtime.getRuntime().halt() vs System.exit() in Java](https://www.baeldung.com/java-runtime-halt-vs-system-exit) - [Adding Shutdown Hooks for JVM Applications](https://www.baeldung.com/jvm-shutdown-hooks) +- [How to Get the Size of an Object in Java](http://www.baeldung.com/java-size-of-object) diff --git a/core-java-modules/core-java/src/main/java/com/baeldung/objectsize/InstrumentationAgent.java b/core-java-modules/core-java-jvm/src/main/java/com/baeldung/objectsize/InstrumentationAgent.java similarity index 100% rename from core-java-modules/core-java/src/main/java/com/baeldung/objectsize/InstrumentationAgent.java rename to core-java-modules/core-java-jvm/src/main/java/com/baeldung/objectsize/InstrumentationAgent.java diff --git a/core-java-modules/core-java/src/main/java/com/baeldung/objectsize/InstrumentationExample.java b/core-java-modules/core-java-jvm/src/main/java/com/baeldung/objectsize/InstrumentationExample.java similarity index 100% rename from core-java-modules/core-java/src/main/java/com/baeldung/objectsize/InstrumentationExample.java rename to core-java-modules/core-java-jvm/src/main/java/com/baeldung/objectsize/InstrumentationExample.java diff --git a/core-java-modules/core-java/src/main/java/com/baeldung/objectsize/MANIFEST.MF b/core-java-modules/core-java-jvm/src/main/java/com/baeldung/objectsize/MANIFEST.MF similarity index 100% rename from core-java-modules/core-java/src/main/java/com/baeldung/objectsize/MANIFEST.MF rename to core-java-modules/core-java-jvm/src/main/java/com/baeldung/objectsize/MANIFEST.MF diff --git a/core-java-modules/core-java-reflection/README.MD b/core-java-modules/core-java-reflection/README.MD index 5aed62b378..d6b3a02e6a 100644 --- a/core-java-modules/core-java-reflection/README.MD +++ b/core-java-modules/core-java-reflection/README.MD @@ -8,3 +8,5 @@ - [Changing Annotation Parameters At Runtime](http://www.baeldung.com/java-reflection-change-annotation-params) - [Dynamic Proxies in Java](http://www.baeldung.com/java-dynamic-proxies) - [What Causes java.lang.reflect.InvocationTargetException?](https://www.baeldung.com/java-lang-reflect-invocationtargetexception) +- [How to Find all Getters Returning Null](http://www.baeldung.com/java-getters-returning-null) +- [How to Get a Name of a Method Being Executed?](http://www.baeldung.com/java-name-of-executing-method) diff --git a/core-java-modules/core-java/src/test/java/com/baeldung/java/currentmethod/CurrentlyExecutedMethodFinderUnitTest.java b/core-java-modules/core-java-reflection/src/test/java/com/baeldung/currentmethod/CurrentlyExecutedMethodFinderUnitTest.java similarity index 100% rename from core-java-modules/core-java/src/test/java/com/baeldung/java/currentmethod/CurrentlyExecutedMethodFinderUnitTest.java rename to core-java-modules/core-java-reflection/src/test/java/com/baeldung/currentmethod/CurrentlyExecutedMethodFinderUnitTest.java diff --git a/core-java-modules/core-java-string-operations-2/README.md b/core-java-modules/core-java-string-operations-2/README.md index 2f54aa9467..cafb3b9017 100644 --- a/core-java-modules/core-java-string-operations-2/README.md +++ b/core-java-modules/core-java-string-operations-2/README.md @@ -12,4 +12,6 @@ This module contains articles about string operations. - [L-Trim and R-Trim Alternatives in Java](https://www.baeldung.com/java-trim-alternatives) - [Java Convert PDF to Base64](https://www.baeldung.com/java-convert-pdf-to-base64) - [Encode a String to UTF-8 in Java](https://www.baeldung.com/java-string-encode-utf-8) +- [Guide to Character Encoding](https://www.baeldung.com/java-char-encoding) +- [Convert Hex to ASCII in Java](https://www.baeldung.com/java-convert-hex-to-ascii) #remove additional readme file - More articles: [[<-- prev]](../core-java-string-operations) diff --git a/core-java-modules/core-java/src/main/java/com/baeldung/encoding/CharacterEncodingExamples.java b/core-java-modules/core-java-string-operations-2/src/main/java/com/baeldung/encoding/CharacterEncodingExamples.java similarity index 100% rename from core-java-modules/core-java/src/main/java/com/baeldung/encoding/CharacterEncodingExamples.java rename to core-java-modules/core-java-string-operations-2/src/main/java/com/baeldung/encoding/CharacterEncodingExamples.java diff --git a/core-java-modules/core-java/src/test/java/com/baeldung/hexToAscii/HexToAsciiUnitTest.java b/core-java-modules/core-java-string-operations-2/src/test/java/com/baeldung/hexToAscii/HexToAsciiUnitTest.java similarity index 100% rename from core-java-modules/core-java/src/test/java/com/baeldung/hexToAscii/HexToAsciiUnitTest.java rename to core-java-modules/core-java-string-operations-2/src/test/java/com/baeldung/hexToAscii/HexToAsciiUnitTest.java diff --git a/core-java-modules/core-java/src/test/java/com/baeldung/hexToAscii/README.md b/core-java-modules/core-java-string-operations-2/src/test/java/com/baeldung/hexToAscii/README.md similarity index 100% rename from core-java-modules/core-java/src/test/java/com/baeldung/hexToAscii/README.md rename to core-java-modules/core-java-string-operations-2/src/test/java/com/baeldung/hexToAscii/README.md diff --git a/core-java-modules/core-java-string-operations-2/src/test/resources/output.pdf b/core-java-modules/core-java-string-operations-2/src/test/resources/output.pdf new file mode 100644 index 0000000000000000000000000000000000000000..94d947797464aa493ba9634f4e5f38ad2ca4717a GIT binary patch literal 142786 zcmb4qb8u!)w{C3PlVoD^jh(!)ZQGvMwr$(CZF6FqlVmcv^E=-;_p7?+RNZ^m?&?~* zSNE#5`j4*l?0z=6f+&!lnSl+Ce5iP+d#H6N4~~VHiP+xA3XYeTQO4BH+{J>J_3wxh zBhb>u#ng!rXk+MNDr#zMZ(_>N59jRSWNK&&_anOoPd18<<7T(7a5mt)rTZg=n`vG1E^t7%8Cp1U4Sdh1jp*`;9&C`qHyKjJln<%@e$h2y9 zydx6TjE&KdvEJDmZ5^a1APfJqcOkN9p$pak0c`%S5|gKg`x4`3#@i&>%mNOQbNq0> zg{4dvxrYvGXflavNeUZ`lHGxZmZW(4wHGm*q6kfzamK|WIXxd1+>gn^88AVnS(tW~ zi>Q|?5uEzf1<#M~N74}*WscfKXJj!X`gMM)<*WA#*KAyUmtP-_9~msE(bo>QM%Crl zKo;?1H%jiz$1yCvxajIKbNV#cqw33TBJC8y`B_97Wa;>{0bhk)45EPG2px1EqByWc z=J(dDKoimr(DFc3l`NKt_>{p`Fu?FQf)+hH@sH|*eRP0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8-YTqANTo-Oo>CsY7|T)*h!C zV$UetV;Ft=UV}(?Wvz`y+*6PS_I)g71ZJ&`7x!(~zO!c~;xUVm4@S&>v0h+?+jj-< zi+dhx5kB~ibU4~+>^7hd+g=uNc0DK`b>Z&7T4ASw5l~(4_Iib~?e$WWhwsP_PnX`V zOm~WaOr~&!O`1Lj_4(uC(#B`9?C$QkOpZT>O^;KaPk-< zrJv?8Yi$r|9qIw?P+7a0FujCyZoDMjofo*ctM$TGYl1pPA5Mtnov`*_q7rC{v7jJ@ zbu+MzYLUp@V+0r!Z3u^p6C;zs=|L-aSGe?Xuu|y$ z?Cp?Ov_Y-aK+hK%9DvXJ@diV(-i;)ab=sJeXoKEW8ygGFpKG)>i4-*BQuO2kP%;V( zbFdBXJUwhvs^Dv#HV#gzIA}ygkHMWcC|S^06>?fh@ty z6X_vqSgZw@!T2B!GYH_ASqx?}WEq39M3vwdSh%*xXbDKN{eiod4DK7Tgb1SsG}@)JdSj@+htB`Lm2053&%(~XInUilRNtvzCFM# zwWkgREu);}0Sqs!J#10X9NrLn!lV=rTiyxA(9ZIBntwtEz@E^-OX;V;WbnK zgH8p1`=G6zCnJH{{bklq)`9> literal 0 HcmV?d00001 diff --git a/core-java-modules/core-java-time-measurements/README.md b/core-java-modules/core-java-time-measurements/README.md index 1bd277b6b1..a3e8b71ae8 100644 --- a/core-java-modules/core-java-time-measurements/README.md +++ b/core-java-modules/core-java-time-measurements/README.md @@ -6,3 +6,4 @@ This module contains articles about the measurement of time in Java. - [Guide to the Java Clock Class](http://www.baeldung.com/java-clock) - [Measure Elapsed Time in Java](http://www.baeldung.com/java-measure-elapsed-time) - [Overriding System Time for Testing in Java](https://www.baeldung.com/java-override-system-time) +- [Java Timer](http://www.baeldung.com/java-timer-and-timertask) diff --git a/core-java-modules/core-java/src/main/java/com/baeldung/timer/DatabaseMigrationTask.java b/core-java-modules/core-java-time-measurements/src/main/java/com/baeldung/timer/DatabaseMigrationTask.java similarity index 100% rename from core-java-modules/core-java/src/main/java/com/baeldung/timer/DatabaseMigrationTask.java rename to core-java-modules/core-java-time-measurements/src/main/java/com/baeldung/timer/DatabaseMigrationTask.java diff --git a/core-java-modules/core-java/src/main/java/com/baeldung/timer/NewsletterTask.java b/core-java-modules/core-java-time-measurements/src/main/java/com/baeldung/timer/NewsletterTask.java similarity index 100% rename from core-java-modules/core-java/src/main/java/com/baeldung/timer/NewsletterTask.java rename to core-java-modules/core-java-time-measurements/src/main/java/com/baeldung/timer/NewsletterTask.java diff --git a/core-java-modules/core-java-time-measurements/src/test/java/com/baeldung/java/clock/ClockUnitTest.java b/core-java-modules/core-java-time-measurements/src/test/java/com/baeldung/clock/ClockUnitTest.java similarity index 99% rename from core-java-modules/core-java-time-measurements/src/test/java/com/baeldung/java/clock/ClockUnitTest.java rename to core-java-modules/core-java-time-measurements/src/test/java/com/baeldung/clock/ClockUnitTest.java index e83ba7afc8..4e34271214 100644 --- a/core-java-modules/core-java-time-measurements/src/test/java/com/baeldung/java/clock/ClockUnitTest.java +++ b/core-java-modules/core-java-time-measurements/src/test/java/com/baeldung/clock/ClockUnitTest.java @@ -1,4 +1,4 @@ -package com.baeldung.java.clock; +package com.baeldung.clock; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; diff --git a/core-java-modules/core-java/src/test/java/com/baeldung/timer/DatabaseMigrationTaskUnitTest.java b/core-java-modules/core-java-time-measurements/src/test/java/com/baeldung/timer/DatabaseMigrationTaskUnitTest.java similarity index 100% rename from core-java-modules/core-java/src/test/java/com/baeldung/timer/DatabaseMigrationTaskUnitTest.java rename to core-java-modules/core-java-time-measurements/src/test/java/com/baeldung/timer/DatabaseMigrationTaskUnitTest.java diff --git a/core-java-modules/core-java/src/test/java/com/baeldung/timer/JavaTimerLongRunningUnitTest.java b/core-java-modules/core-java-time-measurements/src/test/java/com/baeldung/timer/JavaTimerLongRunningUnitTest.java similarity index 100% rename from core-java-modules/core-java/src/test/java/com/baeldung/timer/JavaTimerLongRunningUnitTest.java rename to core-java-modules/core-java-time-measurements/src/test/java/com/baeldung/timer/JavaTimerLongRunningUnitTest.java diff --git a/core-java-modules/core-java/src/test/java/com/baeldung/timer/NewsletterTaskUnitTest.java b/core-java-modules/core-java-time-measurements/src/test/java/com/baeldung/timer/NewsletterTaskUnitTest.java similarity index 100% rename from core-java-modules/core-java/src/test/java/com/baeldung/timer/NewsletterTaskUnitTest.java rename to core-java-modules/core-java-time-measurements/src/test/java/com/baeldung/timer/NewsletterTaskUnitTest.java diff --git a/core-java-modules/core-java/README.md b/core-java-modules/core-java/README.md index 2123a61499..7781382ae5 100644 --- a/core-java-modules/core-java/README.md +++ b/core-java-modules/core-java/README.md @@ -1,44 +1,6 @@ ## Core Java Cookbooks and Examples ### Relevant Articles: -- [Java Timer](http://www.baeldung.com/java-timer-and-timertask) -- [Getting Started with Java Properties](http://www.baeldung.com/java-properties) -- [Introduction to Nashorn](http://www.baeldung.com/java-nashorn) -- [Java Money and the Currency API](http://www.baeldung.com/java-money-and-currency) -- [JVM Log Forging](http://www.baeldung.com/jvm-log-forging) -- [How to Find all Getters Returning Null](http://www.baeldung.com/java-getters-returning-null) -- [How to Get a Name of a Method Being Executed?](http://www.baeldung.com/java-name-of-executing-method) -- [Introduction to Java Serialization](http://www.baeldung.com/java-serialization) -- [Guide to UUID in Java](http://www.baeldung.com/java-uuid) -- [Creating a Java Compiler Plugin](http://www.baeldung.com/java-build-compiler-plugin) -- [Quick Guide to the Java Stack](https://www.baeldung.com/java-stack) -- [Compiling Java *.class Files with javac](http://www.baeldung.com/javac) -- [Introduction to Javadoc](http://www.baeldung.com/javadoc) -- [Guide to the Externalizable Interface in Java](http://www.baeldung.com/java-externalizable) -- [ASCII Art in Java](http://www.baeldung.com/ascii-art-in-java) -- [What is the serialVersionUID?](http://www.baeldung.com/java-serial-version-uid) -- [A Guide to the ResourceBundle](http://www.baeldung.com/java-resourcebundle) -- [Java Global Exception Handler](http://www.baeldung.com/java-global-exception-handler) -- [How to Get the Size of an Object in Java](http://www.baeldung.com/java-size-of-object) -- [Common Java Exceptions](http://www.baeldung.com/java-common-exceptions) -- [Merging java.util.Properties Objects](https://www.baeldung.com/java-merging-properties) -- [Java – Try with Resources](https://www.baeldung.com/java-try-with-resources) -- [Guide to Character Encoding](https://www.baeldung.com/java-char-encoding) -- [Graphs in Java](https://www.baeldung.com/java-graphs) -- [Read and Write User Input in Java](http://www.baeldung.com/java-console-input-output) -- [Formatting with printf() in Java](https://www.baeldung.com/java-printstream-printf) -- [Retrieve Fields from a Java Class Using Reflection](https://www.baeldung.com/java-reflection-class-fields) -- [Using Curl in Java](https://www.baeldung.com/java-curl) -- [Finding Leap Years in Java](https://www.baeldung.com/java-leap-year) -- [Making a JSON POST Request With HttpURLConnection](https://www.baeldung.com/httpurlconnection-post) -- [How to Find an Exception’s Root Cause in Java](https://www.baeldung.com/java-exception-root-cause) -- [Convert Hex to ASCII in Java](https://www.baeldung.com/java-convert-hex-to-ascii) - - -#New module structure -########################### - -#Leave in core-java: [Getting Started with Java Properties](http://www.baeldung.com/java-properties) [Java Money and the Currency API](http://www.baeldung.com/java-money-and-currency) [Introduction to Java Serialization](http://www.baeldung.com/java-serialization) @@ -49,47 +11,3 @@ [What is the serialVersionUID?](http://www.baeldung.com/java-serial-version-uid) [A Guide to the ResourceBundle](http://www.baeldung.com/java-resourcebundle) [Merging java.util.Properties Objects](https://www.baeldung.com/java-merging-properties) - -#Move to language interop (Done) -[Introduction to Nashorn](http://www.baeldung.com/java-nashorn) - -#Move to new new package: core-java-console (Done) -[Read and Write User Input in Java](http://www.baeldung.com/java-console-input-output) -[Formatting with printf() in Java](https://www.baeldung.com/java-printstream-printf) -[ASCII Art in Java](http://www.baeldung.com/ascii-art-in-java) - -#Move to core-java-string-operations-2 -[Guide to Character Encoding](https://www.baeldung.com/java-char-encoding) -[Convert Hex to ASCII in Java](https://www.baeldung.com/java-convert-hex-to-ascii) #remove additional readme file - -#Move to core-javadatetime-operations-2 -[Finding Leap Years in Java](https://www.baeldung.com/java-leap-year) - -#Move to core-java-time-measurements -[Java Timer](http://www.baeldung.com/java-timer-and-timertask) - -#Move to core-java-reflection -[How to Get a Name of a Method Being Executed?](http://www.baeldung.com/java-name-of-executing-method) - -#Move to core-java-streams -[How to Find all Getters Returning Null](http://www.baeldung.com/java-getters-returning-null) - -#Move to core-java-jvm -[How to Get the Size of an Object in Java](http://www.baeldung.com/java-size-of-object) - -#Move to data-structures module -[Graphs in Java](https://www.baeldung.com/java-graphs) - -#Move to core-java-collections-3 -[Quick Guide to the Java Stack](https://www.baeldung.com/java-stack) - -#These are already in another module -[Using Curl in Java](https://www.baeldung.com/java-curl) #Core Java Networking (Part 2) -[Creating a Java Compiler Plugin](http://www.baeldung.com/java-build-compiler-plugin) # Core Java Sun -[Java Global Exception Handler](http://www.baeldung.com/java-global-exception-handler) #Core Java Exceptions -[Java – Try with Resources](https://www.baeldung.com/java-try-with-resources) #Core Java Exceptions -[How to Find an Exception’s Root Cause in Java](https://www.baeldung.com/java-exception-root-cause) #Core Java Exceptions -[JVM Log Forging](http://www.baeldung.com/jvm-log-forging) #Core Java JVM -[Making a JSON POST Request With HttpURLConnection](https://www.baeldung.com/httpurlconnection-post) #Core Java Networking (Part 2) -[Common Java Exceptions](http://www.baeldung.com/java-common-exceptions) #Core Java Exceptions -[Retrieve Fields from a Java Class Using Reflection](https://www.baeldung.com/java-reflection-class-fields) #Core Java Reflection \ No newline at end of file diff --git a/data-structures/README.md b/data-structures/README.md index f9ca78679a..e3436695ce 100644 --- a/data-structures/README.md +++ b/data-structures/README.md @@ -10,3 +10,4 @@ This module contains articles about data structures in Java - [How to Print a Binary Tree Diagram](https://www.baeldung.com/java-print-binary-tree-diagram) - [Introduction to Big Queue](https://www.baeldung.com/java-big-queue) - [Guide to AVL Trees in Java](https://www.baeldung.com/java-avl-trees) +- [Graphs in Java](https://www.baeldung.com/java-graphs) diff --git a/core-java-modules/core-java/src/main/java/com/baeldung/graph/Graph.java b/data-structures/src/main/java/com/baeldung/graph/Graph.java similarity index 100% rename from core-java-modules/core-java/src/main/java/com/baeldung/graph/Graph.java rename to data-structures/src/main/java/com/baeldung/graph/Graph.java diff --git a/core-java-modules/core-java/src/main/java/com/baeldung/graph/GraphTraversal.java b/data-structures/src/main/java/com/baeldung/graph/GraphTraversal.java similarity index 100% rename from core-java-modules/core-java/src/main/java/com/baeldung/graph/GraphTraversal.java rename to data-structures/src/main/java/com/baeldung/graph/GraphTraversal.java diff --git a/core-java-modules/core-java/src/test/java/com/baeldung/graph/GraphUnitTest.java b/data-structures/src/test/java/com/baeldung/graph/GraphUnitTest.java similarity index 100% rename from core-java-modules/core-java/src/test/java/com/baeldung/graph/GraphUnitTest.java rename to data-structures/src/test/java/com/baeldung/graph/GraphUnitTest.java From 4fa2ffb229c34b608657121b48eb552c9bfe7fbb Mon Sep 17 00:00:00 2001 From: "amit.pandey" Date: Sun, 7 Jun 2020 20:28:16 +0530 Subject: [PATCH 100/140] pom formatting - make artifact name same as module name --- core-java-modules/core-java-8-datetime-2/pom.xml | 3 +-- maven-all/versions-maven-plugin/original/pom.xml | 2 +- persistence-modules/r2dbc/pom.xml | 2 +- quarkus-extension/quarkus-liquibase/pom.xml | 2 +- twitter4j/pom.xml | 2 +- 5 files changed, 5 insertions(+), 6 deletions(-) diff --git a/core-java-modules/core-java-8-datetime-2/pom.xml b/core-java-modules/core-java-8-datetime-2/pom.xml index 629ce5234d..f66a89ca55 100644 --- a/core-java-modules/core-java-8-datetime-2/pom.xml +++ b/core-java-modules/core-java-8-datetime-2/pom.xml @@ -4,7 +4,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 - core-java-8-datetime + core-java-8-datetime-2 ${project.parent.version} core-java-8-datetime jar @@ -41,7 +41,6 @@ - core-java-datetime-java8 src/main/resources diff --git a/maven-all/versions-maven-plugin/original/pom.xml b/maven-all/versions-maven-plugin/original/pom.xml index 54140aec9b..f81596661e 100644 --- a/maven-all/versions-maven-plugin/original/pom.xml +++ b/maven-all/versions-maven-plugin/original/pom.xml @@ -4,7 +4,7 @@ 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 - versions-maven-plugin-example + original 0.0.1-SNAPSHOT diff --git a/persistence-modules/r2dbc/pom.xml b/persistence-modules/r2dbc/pom.xml index 70ff8d6a87..b1de88e9ea 100644 --- a/persistence-modules/r2dbc/pom.xml +++ b/persistence-modules/r2dbc/pom.xml @@ -4,7 +4,7 @@ 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.examples.r2dbc - r2dbc-example + r2dbc 0.0.1-SNAPSHOT r2dbc Sample R2DBC Project diff --git a/quarkus-extension/quarkus-liquibase/pom.xml b/quarkus-extension/quarkus-liquibase/pom.xml index 8ed6555ed7..fdede2000e 100644 --- a/quarkus-extension/quarkus-liquibase/pom.xml +++ b/quarkus-extension/quarkus-liquibase/pom.xml @@ -4,7 +4,7 @@ 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.quarkus.liquibase - quarkus-liquibase-parent + quarkus-liquibase quarkus-liquibase pom diff --git a/twitter4j/pom.xml b/twitter4j/pom.xml index 274b5c75c3..0c36e72892 100644 --- a/twitter4j/pom.xml +++ b/twitter4j/pom.xml @@ -2,7 +2,7 @@ 4.0.0 - twitter4J + twitter4j twitter4J jar From ea59a08f4fa1c0df1c527d0d29bdc4d28ff78c10 Mon Sep 17 00:00:00 2001 From: Krzysiek Date: Sun, 7 Jun 2020 17:53:06 +0200 Subject: [PATCH 101/140] JAVA-1782: Remove byte-buddy dep from the main pom.xml --- parent-boot-2/pom.xml | 5 ----- pom.xml | 6 ------ 2 files changed, 11 deletions(-) diff --git a/parent-boot-2/pom.xml b/parent-boot-2/pom.xml index 631d8a0581..c7bb11b1d5 100644 --- a/parent-boot-2/pom.xml +++ b/parent-boot-2/pom.xml @@ -32,11 +32,6 @@ io.rest-assured rest-assured - - net.bytebuddy - byte-buddy - ${byte-buddy.version} - org.springframework.boot spring-boot-starter-test diff --git a/pom.xml b/pom.xml index f797f1bbce..20adc4bfef 100644 --- a/pom.xml +++ b/pom.xml @@ -69,12 +69,6 @@ ${hamcrest-all.version} test - - net.bytebuddy - byte-buddy - ${byte-buddy.version} - test - org.mockito mockito-core From 1a5e943886db4b0234c674605cc09504d0384784 Mon Sep 17 00:00:00 2001 From: "amit.pandey" Date: Sun, 7 Jun 2020 21:28:59 +0530 Subject: [PATCH 102/140] updated the child pom as quarkus-extension/quarkus-liquibase pom artifactId is changed --- quarkus-extension/quarkus-liquibase/deployment/pom.xml | 2 +- quarkus-extension/quarkus-liquibase/runtime/pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/quarkus-extension/quarkus-liquibase/deployment/pom.xml b/quarkus-extension/quarkus-liquibase/deployment/pom.xml index 5c6b56e152..d7f1f995ff 100644 --- a/quarkus-extension/quarkus-liquibase/deployment/pom.xml +++ b/quarkus-extension/quarkus-liquibase/deployment/pom.xml @@ -8,7 +8,7 @@ com.baeldung.quarkus.liquibase - quarkus-liquibase-parent + quarkus-liquibase 1.0-SNAPSHOT diff --git a/quarkus-extension/quarkus-liquibase/runtime/pom.xml b/quarkus-extension/quarkus-liquibase/runtime/pom.xml index 760e6ab719..5d3b05ef92 100644 --- a/quarkus-extension/quarkus-liquibase/runtime/pom.xml +++ b/quarkus-extension/quarkus-liquibase/runtime/pom.xml @@ -7,7 +7,7 @@ com.baeldung.quarkus.liquibase - quarkus-liquibase-parent + quarkus-liquibase 1.0-SNAPSHOT From 0ad021f13402a31a27d2204dad7d4401e6bfa3ba Mon Sep 17 00:00:00 2001 From: Krzysiek Date: Sun, 7 Jun 2020 18:17:05 +0200 Subject: [PATCH 103/140] JAVA-1782: Add byte-buddy explicitly to avoid versions confilict --- jhipster-5/bookstore-monolith/pom.xml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/jhipster-5/bookstore-monolith/pom.xml b/jhipster-5/bookstore-monolith/pom.xml index 233765e0f3..4e4c82f327 100644 --- a/jhipster-5/bookstore-monolith/pom.xml +++ b/jhipster-5/bookstore-monolith/pom.xml @@ -225,6 +225,12 @@ io.dropwizard.metrics metrics-core + + net.bytebuddy + byte-buddy + ${byte-buddy.version} + test + From fdcf192cbe13f85507ab18e45f78c8367da5f6f5 Mon Sep 17 00:00:00 2001 From: mikr Date: Sun, 7 Jun 2020 18:17:43 +0200 Subject: [PATCH 104/140] JAVA-1522 Fix integration test for encoding package --- .../com/baeldung/encoding/CharacterEncodingExamplesUnitTest.java | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename core-java-modules/{core-java => core-java-string-operations-2}/src/test/java/com/baeldung/encoding/CharacterEncodingExamplesUnitTest.java (100%) diff --git a/core-java-modules/core-java/src/test/java/com/baeldung/encoding/CharacterEncodingExamplesUnitTest.java b/core-java-modules/core-java-string-operations-2/src/test/java/com/baeldung/encoding/CharacterEncodingExamplesUnitTest.java similarity index 100% rename from core-java-modules/core-java/src/test/java/com/baeldung/encoding/CharacterEncodingExamplesUnitTest.java rename to core-java-modules/core-java-string-operations-2/src/test/java/com/baeldung/encoding/CharacterEncodingExamplesUnitTest.java From 7b8b9390c737a12a5d6e228f0b50f7c37b5fde9d Mon Sep 17 00:00:00 2001 From: mikr Date: Sun, 7 Jun 2020 21:46:55 +0200 Subject: [PATCH 105/140] JAVA-1522 Fix integration test for encoding package (2) --- .../src/test/resources/encoding.txt | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename core-java-modules/{core-java => core-java-string-operations-2}/src/test/resources/encoding.txt (100%) diff --git a/core-java-modules/core-java/src/test/resources/encoding.txt b/core-java-modules/core-java-string-operations-2/src/test/resources/encoding.txt similarity index 100% rename from core-java-modules/core-java/src/test/resources/encoding.txt rename to core-java-modules/core-java-string-operations-2/src/test/resources/encoding.txt From a1742fc8561afa455d1de4890ecf9db4719e53c1 Mon Sep 17 00:00:00 2001 From: Krzysiek Date: Sun, 7 Jun 2020 22:48:02 +0200 Subject: [PATCH 106/140] JAVA-1782: Add byte-buddy explicitly to avoid versions confilict --- libraries-data-2/pom.xml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libraries-data-2/pom.xml b/libraries-data-2/pom.xml index bdfb2c5ed6..bc2f2c77a1 100644 --- a/libraries-data-2/pom.xml +++ b/libraries-data-2/pom.xml @@ -153,6 +153,12 @@ renjin-script-engine ${renjin.version} + + net.bytebuddy + byte-buddy + ${byte-buddy.version} + test + From aa5551bd9ba043060b58597bca9086db5d58accc Mon Sep 17 00:00:00 2001 From: GilvanOrnelas Date: Sun, 7 Jun 2020 19:18:58 -0300 Subject: [PATCH 107/140] Spring Import Annotation - initial commit (#9424) Co-authored-by: Gilvan Ornelas Fernandes Filho --- .../animal/AnimalConfiguration.java | 9 +++++ .../animal/AnimalScanConfiguration.java | 9 +++++ .../importannotation/animal/Bird.java | 4 +++ .../importannotation/animal/BirdConfig.java | 13 ++++++++ .../baeldung/importannotation/animal/Bug.java | 7 ++++ .../importannotation/animal/BugConfig.java | 9 +++++ .../baeldung/importannotation/animal/Cat.java | 4 +++ .../importannotation/animal/CatConfig.java | 13 ++++++++ .../baeldung/importannotation/animal/Dog.java | 4 +++ .../importannotation/animal/DogConfig.java | 13 ++++++++ .../animal/MammalConfiguration.java | 9 +++++ .../importannotation/zoo/ZooApplication.java | 11 +++++++ .../animal/AnimalConfigUnitTest.java | 31 +++++++++++++++++ .../animal/BugConfigUnitTest.java | 25 ++++++++++++++ .../animal/ConfigUnitTest.java | 31 +++++++++++++++++ .../animal/MammalConfigUnitTest.java | 33 +++++++++++++++++++ .../zoo/ZooApplicationUnitTest.java | 26 +++++++++++++++ 17 files changed, 251 insertions(+) create mode 100644 spring-core-4/src/main/java/com/baeldung/importannotation/animal/AnimalConfiguration.java create mode 100644 spring-core-4/src/main/java/com/baeldung/importannotation/animal/AnimalScanConfiguration.java create mode 100644 spring-core-4/src/main/java/com/baeldung/importannotation/animal/Bird.java create mode 100644 spring-core-4/src/main/java/com/baeldung/importannotation/animal/BirdConfig.java create mode 100644 spring-core-4/src/main/java/com/baeldung/importannotation/animal/Bug.java create mode 100644 spring-core-4/src/main/java/com/baeldung/importannotation/animal/BugConfig.java create mode 100644 spring-core-4/src/main/java/com/baeldung/importannotation/animal/Cat.java create mode 100644 spring-core-4/src/main/java/com/baeldung/importannotation/animal/CatConfig.java create mode 100644 spring-core-4/src/main/java/com/baeldung/importannotation/animal/Dog.java create mode 100644 spring-core-4/src/main/java/com/baeldung/importannotation/animal/DogConfig.java create mode 100644 spring-core-4/src/main/java/com/baeldung/importannotation/animal/MammalConfiguration.java create mode 100644 spring-core-4/src/main/java/com/baeldung/importannotation/zoo/ZooApplication.java create mode 100644 spring-core-4/src/test/java/com/baeldung/importannotation/animal/AnimalConfigUnitTest.java create mode 100644 spring-core-4/src/test/java/com/baeldung/importannotation/animal/BugConfigUnitTest.java create mode 100644 spring-core-4/src/test/java/com/baeldung/importannotation/animal/ConfigUnitTest.java create mode 100644 spring-core-4/src/test/java/com/baeldung/importannotation/animal/MammalConfigUnitTest.java create mode 100644 spring-core-4/src/test/java/com/baeldung/importannotation/zoo/ZooApplicationUnitTest.java diff --git a/spring-core-4/src/main/java/com/baeldung/importannotation/animal/AnimalConfiguration.java b/spring-core-4/src/main/java/com/baeldung/importannotation/animal/AnimalConfiguration.java new file mode 100644 index 0000000000..94f22788b8 --- /dev/null +++ b/spring-core-4/src/main/java/com/baeldung/importannotation/animal/AnimalConfiguration.java @@ -0,0 +1,9 @@ +package com.baeldung.importannotation.animal; + +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Import; + +@Configuration +@Import({ MammalConfiguration.class, BirdConfig.class }) +class AnimalConfiguration { +} diff --git a/spring-core-4/src/main/java/com/baeldung/importannotation/animal/AnimalScanConfiguration.java b/spring-core-4/src/main/java/com/baeldung/importannotation/animal/AnimalScanConfiguration.java new file mode 100644 index 0000000000..9b4310b6d3 --- /dev/null +++ b/spring-core-4/src/main/java/com/baeldung/importannotation/animal/AnimalScanConfiguration.java @@ -0,0 +1,9 @@ +package com.baeldung.importannotation.animal; + +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; + +@Configuration +@ComponentScan +public class AnimalScanConfiguration { +} diff --git a/spring-core-4/src/main/java/com/baeldung/importannotation/animal/Bird.java b/spring-core-4/src/main/java/com/baeldung/importannotation/animal/Bird.java new file mode 100644 index 0000000000..a785cf7641 --- /dev/null +++ b/spring-core-4/src/main/java/com/baeldung/importannotation/animal/Bird.java @@ -0,0 +1,4 @@ +package com.baeldung.importannotation.animal; + +class Bird { +} diff --git a/spring-core-4/src/main/java/com/baeldung/importannotation/animal/BirdConfig.java b/spring-core-4/src/main/java/com/baeldung/importannotation/animal/BirdConfig.java new file mode 100644 index 0000000000..c5cefe8b22 --- /dev/null +++ b/spring-core-4/src/main/java/com/baeldung/importannotation/animal/BirdConfig.java @@ -0,0 +1,13 @@ +package com.baeldung.importannotation.animal; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +class BirdConfig { + + @Bean + Bird bird() { + return new Bird(); + } +} diff --git a/spring-core-4/src/main/java/com/baeldung/importannotation/animal/Bug.java b/spring-core-4/src/main/java/com/baeldung/importannotation/animal/Bug.java new file mode 100644 index 0000000000..6abe08e393 --- /dev/null +++ b/spring-core-4/src/main/java/com/baeldung/importannotation/animal/Bug.java @@ -0,0 +1,7 @@ +package com.baeldung.importannotation.animal; + +import org.springframework.stereotype.Component; + +@Component(value = "bug") +class Bug { +} diff --git a/spring-core-4/src/main/java/com/baeldung/importannotation/animal/BugConfig.java b/spring-core-4/src/main/java/com/baeldung/importannotation/animal/BugConfig.java new file mode 100644 index 0000000000..9bea16413a --- /dev/null +++ b/spring-core-4/src/main/java/com/baeldung/importannotation/animal/BugConfig.java @@ -0,0 +1,9 @@ +package com.baeldung.importannotation.animal; + +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Import; + +@Configuration +@Import(Bug.class) +class BugConfig { +} diff --git a/spring-core-4/src/main/java/com/baeldung/importannotation/animal/Cat.java b/spring-core-4/src/main/java/com/baeldung/importannotation/animal/Cat.java new file mode 100644 index 0000000000..7eb36c81ce --- /dev/null +++ b/spring-core-4/src/main/java/com/baeldung/importannotation/animal/Cat.java @@ -0,0 +1,4 @@ +package com.baeldung.importannotation.animal; + +class Cat { +} \ No newline at end of file diff --git a/spring-core-4/src/main/java/com/baeldung/importannotation/animal/CatConfig.java b/spring-core-4/src/main/java/com/baeldung/importannotation/animal/CatConfig.java new file mode 100644 index 0000000000..ebb35ffc11 --- /dev/null +++ b/spring-core-4/src/main/java/com/baeldung/importannotation/animal/CatConfig.java @@ -0,0 +1,13 @@ +package com.baeldung.importannotation.animal; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +class CatConfig { + + @Bean + Cat cat() { + return new Cat(); + } +} diff --git a/spring-core-4/src/main/java/com/baeldung/importannotation/animal/Dog.java b/spring-core-4/src/main/java/com/baeldung/importannotation/animal/Dog.java new file mode 100644 index 0000000000..00374c1bc0 --- /dev/null +++ b/spring-core-4/src/main/java/com/baeldung/importannotation/animal/Dog.java @@ -0,0 +1,4 @@ +package com.baeldung.importannotation.animal; + +class Dog { +} diff --git a/spring-core-4/src/main/java/com/baeldung/importannotation/animal/DogConfig.java b/spring-core-4/src/main/java/com/baeldung/importannotation/animal/DogConfig.java new file mode 100644 index 0000000000..c11ee44623 --- /dev/null +++ b/spring-core-4/src/main/java/com/baeldung/importannotation/animal/DogConfig.java @@ -0,0 +1,13 @@ +package com.baeldung.importannotation.animal; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +class DogConfig { + + @Bean + Dog dog() { + return new Dog(); + } +} diff --git a/spring-core-4/src/main/java/com/baeldung/importannotation/animal/MammalConfiguration.java b/spring-core-4/src/main/java/com/baeldung/importannotation/animal/MammalConfiguration.java new file mode 100644 index 0000000000..3d77ac878c --- /dev/null +++ b/spring-core-4/src/main/java/com/baeldung/importannotation/animal/MammalConfiguration.java @@ -0,0 +1,9 @@ +package com.baeldung.importannotation.animal; + +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Import; + +@Configuration +@Import({ DogConfig.class, CatConfig.class }) +class MammalConfiguration { +} diff --git a/spring-core-4/src/main/java/com/baeldung/importannotation/zoo/ZooApplication.java b/spring-core-4/src/main/java/com/baeldung/importannotation/zoo/ZooApplication.java new file mode 100644 index 0000000000..01aa36a796 --- /dev/null +++ b/spring-core-4/src/main/java/com/baeldung/importannotation/zoo/ZooApplication.java @@ -0,0 +1,11 @@ +package com.baeldung.importannotation.zoo; + +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Import; + +import com.baeldung.importannotation.animal.AnimalScanConfiguration; + +@Configuration +@Import(AnimalScanConfiguration.class) +class ZooApplication { +} diff --git a/spring-core-4/src/test/java/com/baeldung/importannotation/animal/AnimalConfigUnitTest.java b/spring-core-4/src/test/java/com/baeldung/importannotation/animal/AnimalConfigUnitTest.java new file mode 100644 index 0000000000..7f4795da25 --- /dev/null +++ b/spring-core-4/src/test/java/com/baeldung/importannotation/animal/AnimalConfigUnitTest.java @@ -0,0 +1,31 @@ +package com.baeldung.importannotation.animal; + +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationContext; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit.jupiter.SpringExtension; + +@ExtendWith(SpringExtension.class) +@ContextConfiguration(classes = { AnimalConfiguration.class }) +class AnimalConfigUnitTest { + + @Autowired + ApplicationContext context; + + @Test + void givenImportedBeans_whenGettingEach_shallFindOnlyTheImportedBeans() { + assertThatBeanExists("dog", Dog.class); + assertThatBeanExists("cat", Cat.class); + assertThatBeanExists("bird", Cat.class); + } + + private void assertThatBeanExists(String beanName, Class beanClass) { + assertTrue(context.containsBean(beanName)); + assertNotNull(context.getBean(beanClass)); + } +} diff --git a/spring-core-4/src/test/java/com/baeldung/importannotation/animal/BugConfigUnitTest.java b/spring-core-4/src/test/java/com/baeldung/importannotation/animal/BugConfigUnitTest.java new file mode 100644 index 0000000000..2a2e0b332a --- /dev/null +++ b/spring-core-4/src/test/java/com/baeldung/importannotation/animal/BugConfigUnitTest.java @@ -0,0 +1,25 @@ +package com.baeldung.importannotation.animal; + +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationContext; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit.jupiter.SpringExtension; + +@ExtendWith(SpringExtension.class) +@ContextConfiguration(classes = BugConfig.class) +class BugConfigUnitTest { + + @Autowired + ApplicationContext context; + + @Test + void givenImportInComponent_whenLookForBean_shallFindIt() { + assertTrue(context.containsBean("bug")); + assertNotNull(context.getBean(Bug.class)); + } +} diff --git a/spring-core-4/src/test/java/com/baeldung/importannotation/animal/ConfigUnitTest.java b/spring-core-4/src/test/java/com/baeldung/importannotation/animal/ConfigUnitTest.java new file mode 100644 index 0000000000..dadd2abae6 --- /dev/null +++ b/spring-core-4/src/test/java/com/baeldung/importannotation/animal/ConfigUnitTest.java @@ -0,0 +1,31 @@ +package com.baeldung.importannotation.animal; + +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationContext; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit.jupiter.SpringExtension; + +@ExtendWith(SpringExtension.class) +@ContextConfiguration(classes = { BirdConfig.class, CatConfig.class, DogConfig.class }) +class ConfigUnitTest { + + @Autowired + ApplicationContext context; + + @Test + void givenImportedBeans_whenGettingEach_shallFindIt() { + assertThatBeanExists("dog", Dog.class); + assertThatBeanExists("cat", Cat.class); + assertThatBeanExists("bird", Bird.class); + } + + private void assertThatBeanExists(String beanName, Class beanClass) { + assertTrue(context.containsBean(beanName)); + assertNotNull(context.getBean(beanClass)); + } +} diff --git a/spring-core-4/src/test/java/com/baeldung/importannotation/animal/MammalConfigUnitTest.java b/spring-core-4/src/test/java/com/baeldung/importannotation/animal/MammalConfigUnitTest.java new file mode 100644 index 0000000000..5e1596253c --- /dev/null +++ b/spring-core-4/src/test/java/com/baeldung/importannotation/animal/MammalConfigUnitTest.java @@ -0,0 +1,33 @@ +package com.baeldung.importannotation.animal; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationContext; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit.jupiter.SpringExtension; + +@ExtendWith(SpringExtension.class) +@ContextConfiguration(classes = { MammalConfiguration.class }) +class MammalConfigUnitTest { + + @Autowired + ApplicationContext context; + + @Test + void givenImportedBeans_whenGettingEach_shallFindOnlyTheImportedBeans() { + assertThatBeanExists("dog", Dog.class); + assertThatBeanExists("cat", Cat.class); + + assertFalse(context.containsBean("bird")); + } + + private void assertThatBeanExists(String beanName, Class beanClass) { + assertTrue(context.containsBean(beanName)); + assertNotNull(context.getBean(beanClass)); + } +} diff --git a/spring-core-4/src/test/java/com/baeldung/importannotation/zoo/ZooApplicationUnitTest.java b/spring-core-4/src/test/java/com/baeldung/importannotation/zoo/ZooApplicationUnitTest.java new file mode 100644 index 0000000000..e832e27b28 --- /dev/null +++ b/spring-core-4/src/test/java/com/baeldung/importannotation/zoo/ZooApplicationUnitTest.java @@ -0,0 +1,26 @@ +package com.baeldung.importannotation.zoo; + +import static org.junit.jupiter.api.Assertions.assertNotNull; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationContext; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit.jupiter.SpringExtension; + +@ExtendWith(SpringExtension.class) +@ContextConfiguration(classes = ZooApplication.class) +class ZooApplicationUnitTest { + + @Autowired + ApplicationContext context; + + @Test + void givenTheScanInTheAnimalPackage_whenGettingAnyAnimal_shallFindItInTheContext() { + assertNotNull(context.getBean("dog")); + assertNotNull(context.getBean("bird")); + assertNotNull(context.getBean("cat")); + assertNotNull(context.getBean("bug")); + } +} From 2a6533cb96384b2c9aa94a52c66e8d5199263822 Mon Sep 17 00:00:00 2001 From: mikr Date: Mon, 8 Jun 2020 00:22:04 +0200 Subject: [PATCH 108/140] JAVA-101 Split Core Kotlin --- core-kotlin-modules/core-kotlin-2/README.md | 9 ----- .../core-kotlin-collections/README.md | 1 + .../com/baeldung/sorting/SortingExample.kt | 0 .../baeldung/sorting/SortingExampleKtTest.kt | 0 .../core-kotlin-datastructures/README.md | 6 ++++ .../core-kotlin-datastructures/pom.xml | 29 +++++++++++++++ .../kotlin/com/baeldung/binarytree/Main.kt | 0 .../kotlin/com/baeldung/binarytree/Node.kt | 0 .../test/kotlin/com}/binarytree/NodeTest.kt | 2 +- .../core-kotlin-date-time/README.md | 6 ++++ .../core-kotlin-date-time/pom.xml | 36 +++++++++++++++++++ .../baeldung/dates/datetime/UseDuration.kt | 0 .../baeldung/dates/datetime/UseLocalDate.kt | 0 .../dates/datetime/UseLocalDateTime.kt | 0 .../baeldung/dates/datetime/UseLocalTime.kt | 0 .../com/baeldung/dates/datetime/UsePeriod.kt | 0 .../dates/datetime/UseZonedDateTime.kt | 0 .../com/baeldung/dates/CreateDateUnitTest.kt | 0 .../com/baeldung/dates/ExtractDateUnitTest.kt | 0 .../com/baeldung/dates/FormatDateUnitTest.kt | 0 .../com/baeldung/dates/PeriodDateUnitTest.kt | 0 .../datetime/UseLocalDateTimeUnitTest.kt | 0 .../dates/datetime/UseLocalDateUnitTest.kt | 0 .../dates/datetime/UseLocalTimeUnitTest.kt | 0 .../dates/datetime/UsePeriodUnitTest.kt | 0 .../datetime/UseZonedDateTimeUnitTest.kt | 0 .../core-kotlin-design-patterns/README.md | 6 ++++ .../core-kotlin-design-patterns/pom.xml | 29 +++++++++++++++ .../kotlin/com/baeldung/builder/FoodOrder.kt | 0 .../com/baeldung/builder/FoodOrderApply.kt | 0 .../com/baeldung/builder/FoodOrderNamed.kt | 0 .../main/kotlin/com/baeldung/builder/Main.kt | 0 .../builder/BuilderPatternUnitTest.kt | 0 .../core-kotlin-lang-2/README.md | 1 + .../com/baeldung/scope/ScopeFunctions.kt | 0 .../baeldung/scope/ScopeFunctionsUnitTest.kt | 0 .../core-kotlin-testing/README.md | 6 ++++ .../pom.xml | 14 +++++--- .../kotlin/com/baeldung/junit5/Calculator.kt | 0 .../com/baeldung/junit5/CalculatorUnitTest.kt | 0 .../baeldung/junit5/DivideByZeroException.kt | 0 .../com/baeldung/junit5/SimpleUnitTest.kt | 0 core-kotlin-modules/core-kotlin/README.md | 12 ++----- .../nullassertion/NotNullAssertionUnitTest.kt | 0 .../com/baeldung/sequences/SequencesTest.kt | 0 .../baeldung/ternary/TernaryOperatorTest.kt | 0 core-kotlin-modules/pom.xml | 6 ++-- .../kotlin/com/baeldung/gson/GsonUnitTest.kt | 0 48 files changed, 136 insertions(+), 27 deletions(-) delete mode 100644 core-kotlin-modules/core-kotlin-2/README.md rename core-kotlin-modules/{core-kotlin => core-kotlin-collections}/src/main/kotlin/com/baeldung/sorting/SortingExample.kt (100%) rename core-kotlin-modules/{core-kotlin => core-kotlin-collections}/src/test/kotlin/com/baeldung/sorting/SortingExampleKtTest.kt (100%) create mode 100644 core-kotlin-modules/core-kotlin-datastructures/README.md create mode 100644 core-kotlin-modules/core-kotlin-datastructures/pom.xml rename core-kotlin-modules/{core-kotlin => core-kotlin-datastructures}/src/main/kotlin/com/baeldung/binarytree/Main.kt (100%) rename core-kotlin-modules/{core-kotlin => core-kotlin-datastructures}/src/main/kotlin/com/baeldung/binarytree/Node.kt (100%) rename core-kotlin-modules/{core-kotlin/src/test/kotlin/com/baeldung => core-kotlin-datastructures/src/test/kotlin/com}/binarytree/NodeTest.kt (99%) create mode 100644 core-kotlin-modules/core-kotlin-date-time/README.md create mode 100644 core-kotlin-modules/core-kotlin-date-time/pom.xml rename core-kotlin-modules/{core-kotlin-2 => core-kotlin-date-time}/src/main/kotlin/com/baeldung/dates/datetime/UseDuration.kt (100%) rename core-kotlin-modules/{core-kotlin-2 => core-kotlin-date-time}/src/main/kotlin/com/baeldung/dates/datetime/UseLocalDate.kt (100%) rename core-kotlin-modules/{core-kotlin-2 => core-kotlin-date-time}/src/main/kotlin/com/baeldung/dates/datetime/UseLocalDateTime.kt (100%) rename core-kotlin-modules/{core-kotlin-2 => core-kotlin-date-time}/src/main/kotlin/com/baeldung/dates/datetime/UseLocalTime.kt (100%) rename core-kotlin-modules/{core-kotlin-2 => core-kotlin-date-time}/src/main/kotlin/com/baeldung/dates/datetime/UsePeriod.kt (100%) rename core-kotlin-modules/{core-kotlin-2 => core-kotlin-date-time}/src/main/kotlin/com/baeldung/dates/datetime/UseZonedDateTime.kt (100%) rename core-kotlin-modules/{core-kotlin-2 => core-kotlin-date-time}/src/test/kotlin/com/baeldung/dates/CreateDateUnitTest.kt (100%) rename core-kotlin-modules/{core-kotlin-2 => core-kotlin-date-time}/src/test/kotlin/com/baeldung/dates/ExtractDateUnitTest.kt (100%) rename core-kotlin-modules/{core-kotlin-2 => core-kotlin-date-time}/src/test/kotlin/com/baeldung/dates/FormatDateUnitTest.kt (100%) rename core-kotlin-modules/{core-kotlin-2 => core-kotlin-date-time}/src/test/kotlin/com/baeldung/dates/PeriodDateUnitTest.kt (100%) rename core-kotlin-modules/{core-kotlin-2 => core-kotlin-date-time}/src/test/kotlin/com/baeldung/dates/datetime/UseLocalDateTimeUnitTest.kt (100%) rename core-kotlin-modules/{core-kotlin-2 => core-kotlin-date-time}/src/test/kotlin/com/baeldung/dates/datetime/UseLocalDateUnitTest.kt (100%) rename core-kotlin-modules/{core-kotlin-2 => core-kotlin-date-time}/src/test/kotlin/com/baeldung/dates/datetime/UseLocalTimeUnitTest.kt (100%) rename core-kotlin-modules/{core-kotlin-2 => core-kotlin-date-time}/src/test/kotlin/com/baeldung/dates/datetime/UsePeriodUnitTest.kt (100%) rename core-kotlin-modules/{core-kotlin-2 => core-kotlin-date-time}/src/test/kotlin/com/baeldung/dates/datetime/UseZonedDateTimeUnitTest.kt (100%) create mode 100644 core-kotlin-modules/core-kotlin-design-patterns/README.md create mode 100644 core-kotlin-modules/core-kotlin-design-patterns/pom.xml rename core-kotlin-modules/{core-kotlin => core-kotlin-design-patterns}/src/main/kotlin/com/baeldung/builder/FoodOrder.kt (100%) rename core-kotlin-modules/{core-kotlin => core-kotlin-design-patterns}/src/main/kotlin/com/baeldung/builder/FoodOrderApply.kt (100%) rename core-kotlin-modules/{core-kotlin => core-kotlin-design-patterns}/src/main/kotlin/com/baeldung/builder/FoodOrderNamed.kt (100%) rename core-kotlin-modules/{core-kotlin => core-kotlin-design-patterns}/src/main/kotlin/com/baeldung/builder/Main.kt (100%) rename core-kotlin-modules/{core-kotlin => core-kotlin-design-patterns}/src/test/kotlin/com/baeldung/builder/BuilderPatternUnitTest.kt (100%) rename core-kotlin-modules/{core-kotlin => core-kotlin-lang-2}/src/main/kotlin/com/baeldung/scope/ScopeFunctions.kt (100%) rename core-kotlin-modules/{core-kotlin => core-kotlin-lang-2}/src/test/kotlin/com/baeldung/scope/ScopeFunctionsUnitTest.kt (100%) create mode 100644 core-kotlin-modules/core-kotlin-testing/README.md rename core-kotlin-modules/{core-kotlin-2 => core-kotlin-testing}/pom.xml (64%) rename core-kotlin-modules/{core-kotlin => core-kotlin-testing}/src/test/kotlin/com/baeldung/junit5/Calculator.kt (100%) rename core-kotlin-modules/{core-kotlin => core-kotlin-testing}/src/test/kotlin/com/baeldung/junit5/CalculatorUnitTest.kt (100%) rename core-kotlin-modules/{core-kotlin => core-kotlin-testing}/src/test/kotlin/com/baeldung/junit5/DivideByZeroException.kt (100%) rename core-kotlin-modules/{core-kotlin => core-kotlin-testing}/src/test/kotlin/com/baeldung/junit5/SimpleUnitTest.kt (100%) rename core-kotlin-modules/{core-kotlin-2 => core-kotlin}/src/test/kotlin/com/baeldung/nullassertion/NotNullAssertionUnitTest.kt (100%) rename core-kotlin-modules/{core-kotlin-2 => core-kotlin}/src/test/kotlin/com/baeldung/sequences/SequencesTest.kt (100%) rename core-kotlin-modules/{core-kotlin-2 => core-kotlin}/src/test/kotlin/com/baeldung/ternary/TernaryOperatorTest.kt (100%) rename {core-kotlin-modules/core-kotlin => kotlin-libraries-2}/src/test/kotlin/com/baeldung/gson/GsonUnitTest.kt (100%) diff --git a/core-kotlin-modules/core-kotlin-2/README.md b/core-kotlin-modules/core-kotlin-2/README.md deleted file mode 100644 index d6d6b2f706..0000000000 --- a/core-kotlin-modules/core-kotlin-2/README.md +++ /dev/null @@ -1,9 +0,0 @@ -## Core Kotlin 2 - -This module contains articles about Kotlin core features. - -### Relevant articles: -- [Working with Dates in Kotlin](https://www.baeldung.com/kotlin-dates) -- [Kotlin Ternary Conditional Operator](https://www.baeldung.com/kotlin-ternary-operator) -- [Sequences in Kotlin](https://www.baeldung.com/kotlin/sequences) -- [[<-- Prev]](/core-kotlin-modules/core-kotlin) diff --git a/core-kotlin-modules/core-kotlin-collections/README.md b/core-kotlin-modules/core-kotlin-collections/README.md index 66f15e7419..997680c2bc 100644 --- a/core-kotlin-modules/core-kotlin-collections/README.md +++ b/core-kotlin-modules/core-kotlin-collections/README.md @@ -10,3 +10,4 @@ This module contains articles about core Kotlin collections. - [Filtering Kotlin Collections](https://www.baeldung.com/kotlin-filter-collection) - [Collection Transformations in Kotlin](https://www.baeldung.com/kotlin-collection-transformations) - [Difference between fold and reduce in Kotlin](https://www.baeldung.com/kotlin/fold-vs-reduce) +- [Guide to Sorting in Kotlin](https://www.baeldung.com/kotlin-sort) diff --git a/core-kotlin-modules/core-kotlin/src/main/kotlin/com/baeldung/sorting/SortingExample.kt b/core-kotlin-modules/core-kotlin-collections/src/main/kotlin/com/baeldung/sorting/SortingExample.kt similarity index 100% rename from core-kotlin-modules/core-kotlin/src/main/kotlin/com/baeldung/sorting/SortingExample.kt rename to core-kotlin-modules/core-kotlin-collections/src/main/kotlin/com/baeldung/sorting/SortingExample.kt diff --git a/core-kotlin-modules/core-kotlin/src/test/kotlin/com/baeldung/sorting/SortingExampleKtTest.kt b/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/sorting/SortingExampleKtTest.kt similarity index 100% rename from core-kotlin-modules/core-kotlin/src/test/kotlin/com/baeldung/sorting/SortingExampleKtTest.kt rename to core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/sorting/SortingExampleKtTest.kt diff --git a/core-kotlin-modules/core-kotlin-datastructures/README.md b/core-kotlin-modules/core-kotlin-datastructures/README.md new file mode 100644 index 0000000000..3b22730a76 --- /dev/null +++ b/core-kotlin-modules/core-kotlin-datastructures/README.md @@ -0,0 +1,6 @@ +## Core Kotlin + +This module contains articles about data structures in Kotlin + +### Relevant articles: +[Implementing a Binary Tree in Kotlin](https://www.baeldung.com/kotlin-binary-tree) diff --git a/core-kotlin-modules/core-kotlin-datastructures/pom.xml b/core-kotlin-modules/core-kotlin-datastructures/pom.xml new file mode 100644 index 0000000000..eae11c17cf --- /dev/null +++ b/core-kotlin-modules/core-kotlin-datastructures/pom.xml @@ -0,0 +1,29 @@ + + + 4.0.0 + core-kotlin-datastructures + core-kotlin-datastructures + jar + + + com.baeldung.core-kotlin-modules + core-kotlin-modules + 1.0.0-SNAPSHOT + + + + + org.junit.platform + junit-platform-runner + ${junit.platform.version} + test + + + + + 1.1.1 + + + \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin/src/main/kotlin/com/baeldung/binarytree/Main.kt b/core-kotlin-modules/core-kotlin-datastructures/src/main/kotlin/com/baeldung/binarytree/Main.kt similarity index 100% rename from core-kotlin-modules/core-kotlin/src/main/kotlin/com/baeldung/binarytree/Main.kt rename to core-kotlin-modules/core-kotlin-datastructures/src/main/kotlin/com/baeldung/binarytree/Main.kt diff --git a/core-kotlin-modules/core-kotlin/src/main/kotlin/com/baeldung/binarytree/Node.kt b/core-kotlin-modules/core-kotlin-datastructures/src/main/kotlin/com/baeldung/binarytree/Node.kt similarity index 100% rename from core-kotlin-modules/core-kotlin/src/main/kotlin/com/baeldung/binarytree/Node.kt rename to core-kotlin-modules/core-kotlin-datastructures/src/main/kotlin/com/baeldung/binarytree/Node.kt diff --git a/core-kotlin-modules/core-kotlin/src/test/kotlin/com/baeldung/binarytree/NodeTest.kt b/core-kotlin-modules/core-kotlin-datastructures/src/test/kotlin/com/binarytree/NodeTest.kt similarity index 99% rename from core-kotlin-modules/core-kotlin/src/test/kotlin/com/baeldung/binarytree/NodeTest.kt rename to core-kotlin-modules/core-kotlin-datastructures/src/test/kotlin/com/binarytree/NodeTest.kt index 9414d7dde9..5a7f7fc50f 100644 --- a/core-kotlin-modules/core-kotlin/src/test/kotlin/com/baeldung/binarytree/NodeTest.kt +++ b/core-kotlin-modules/core-kotlin-datastructures/src/test/kotlin/com/binarytree/NodeTest.kt @@ -1,4 +1,4 @@ -package com.baeldung.binarytree +package com.binarytree import org.junit.After import org.junit.Assert.assertEquals diff --git a/core-kotlin-modules/core-kotlin-date-time/README.md b/core-kotlin-modules/core-kotlin-date-time/README.md new file mode 100644 index 0000000000..a3e358d4e3 --- /dev/null +++ b/core-kotlin-modules/core-kotlin-date-time/README.md @@ -0,0 +1,6 @@ +## Core Kotlin Date and Time + +This module contains articles about Kotlin core date/time features. + +### Relevant articles: +[Working with Dates in Kotlin](https://www.baeldung.com/kotlin-dates) diff --git a/core-kotlin-modules/core-kotlin-date-time/pom.xml b/core-kotlin-modules/core-kotlin-date-time/pom.xml new file mode 100644 index 0000000000..f3cacefc19 --- /dev/null +++ b/core-kotlin-modules/core-kotlin-date-time/pom.xml @@ -0,0 +1,36 @@ + + + 4.0.0 + core-kotlin-date-time + core-kotlin-date-time + jar + + + com.baeldung.core-kotlin-modules + core-kotlin-modules + 1.0.0-SNAPSHOT + + + + + org.assertj + assertj-core + ${org.assertj.core.version} + test + + + org.junit.platform + junit-platform-runner + ${junit.platform.version} + test + + + + + 1.1.1 + 3.9.0 + + + \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-2/src/main/kotlin/com/baeldung/dates/datetime/UseDuration.kt b/core-kotlin-modules/core-kotlin-date-time/src/main/kotlin/com/baeldung/dates/datetime/UseDuration.kt similarity index 100% rename from core-kotlin-modules/core-kotlin-2/src/main/kotlin/com/baeldung/dates/datetime/UseDuration.kt rename to core-kotlin-modules/core-kotlin-date-time/src/main/kotlin/com/baeldung/dates/datetime/UseDuration.kt diff --git a/core-kotlin-modules/core-kotlin-2/src/main/kotlin/com/baeldung/dates/datetime/UseLocalDate.kt b/core-kotlin-modules/core-kotlin-date-time/src/main/kotlin/com/baeldung/dates/datetime/UseLocalDate.kt similarity index 100% rename from core-kotlin-modules/core-kotlin-2/src/main/kotlin/com/baeldung/dates/datetime/UseLocalDate.kt rename to core-kotlin-modules/core-kotlin-date-time/src/main/kotlin/com/baeldung/dates/datetime/UseLocalDate.kt diff --git a/core-kotlin-modules/core-kotlin-2/src/main/kotlin/com/baeldung/dates/datetime/UseLocalDateTime.kt b/core-kotlin-modules/core-kotlin-date-time/src/main/kotlin/com/baeldung/dates/datetime/UseLocalDateTime.kt similarity index 100% rename from core-kotlin-modules/core-kotlin-2/src/main/kotlin/com/baeldung/dates/datetime/UseLocalDateTime.kt rename to core-kotlin-modules/core-kotlin-date-time/src/main/kotlin/com/baeldung/dates/datetime/UseLocalDateTime.kt diff --git a/core-kotlin-modules/core-kotlin-2/src/main/kotlin/com/baeldung/dates/datetime/UseLocalTime.kt b/core-kotlin-modules/core-kotlin-date-time/src/main/kotlin/com/baeldung/dates/datetime/UseLocalTime.kt similarity index 100% rename from core-kotlin-modules/core-kotlin-2/src/main/kotlin/com/baeldung/dates/datetime/UseLocalTime.kt rename to core-kotlin-modules/core-kotlin-date-time/src/main/kotlin/com/baeldung/dates/datetime/UseLocalTime.kt diff --git a/core-kotlin-modules/core-kotlin-2/src/main/kotlin/com/baeldung/dates/datetime/UsePeriod.kt b/core-kotlin-modules/core-kotlin-date-time/src/main/kotlin/com/baeldung/dates/datetime/UsePeriod.kt similarity index 100% rename from core-kotlin-modules/core-kotlin-2/src/main/kotlin/com/baeldung/dates/datetime/UsePeriod.kt rename to core-kotlin-modules/core-kotlin-date-time/src/main/kotlin/com/baeldung/dates/datetime/UsePeriod.kt diff --git a/core-kotlin-modules/core-kotlin-2/src/main/kotlin/com/baeldung/dates/datetime/UseZonedDateTime.kt b/core-kotlin-modules/core-kotlin-date-time/src/main/kotlin/com/baeldung/dates/datetime/UseZonedDateTime.kt similarity index 100% rename from core-kotlin-modules/core-kotlin-2/src/main/kotlin/com/baeldung/dates/datetime/UseZonedDateTime.kt rename to core-kotlin-modules/core-kotlin-date-time/src/main/kotlin/com/baeldung/dates/datetime/UseZonedDateTime.kt diff --git a/core-kotlin-modules/core-kotlin-2/src/test/kotlin/com/baeldung/dates/CreateDateUnitTest.kt b/core-kotlin-modules/core-kotlin-date-time/src/test/kotlin/com/baeldung/dates/CreateDateUnitTest.kt similarity index 100% rename from core-kotlin-modules/core-kotlin-2/src/test/kotlin/com/baeldung/dates/CreateDateUnitTest.kt rename to core-kotlin-modules/core-kotlin-date-time/src/test/kotlin/com/baeldung/dates/CreateDateUnitTest.kt diff --git a/core-kotlin-modules/core-kotlin-2/src/test/kotlin/com/baeldung/dates/ExtractDateUnitTest.kt b/core-kotlin-modules/core-kotlin-date-time/src/test/kotlin/com/baeldung/dates/ExtractDateUnitTest.kt similarity index 100% rename from core-kotlin-modules/core-kotlin-2/src/test/kotlin/com/baeldung/dates/ExtractDateUnitTest.kt rename to core-kotlin-modules/core-kotlin-date-time/src/test/kotlin/com/baeldung/dates/ExtractDateUnitTest.kt diff --git a/core-kotlin-modules/core-kotlin-2/src/test/kotlin/com/baeldung/dates/FormatDateUnitTest.kt b/core-kotlin-modules/core-kotlin-date-time/src/test/kotlin/com/baeldung/dates/FormatDateUnitTest.kt similarity index 100% rename from core-kotlin-modules/core-kotlin-2/src/test/kotlin/com/baeldung/dates/FormatDateUnitTest.kt rename to core-kotlin-modules/core-kotlin-date-time/src/test/kotlin/com/baeldung/dates/FormatDateUnitTest.kt diff --git a/core-kotlin-modules/core-kotlin-2/src/test/kotlin/com/baeldung/dates/PeriodDateUnitTest.kt b/core-kotlin-modules/core-kotlin-date-time/src/test/kotlin/com/baeldung/dates/PeriodDateUnitTest.kt similarity index 100% rename from core-kotlin-modules/core-kotlin-2/src/test/kotlin/com/baeldung/dates/PeriodDateUnitTest.kt rename to core-kotlin-modules/core-kotlin-date-time/src/test/kotlin/com/baeldung/dates/PeriodDateUnitTest.kt diff --git a/core-kotlin-modules/core-kotlin-2/src/test/kotlin/com/baeldung/dates/datetime/UseLocalDateTimeUnitTest.kt b/core-kotlin-modules/core-kotlin-date-time/src/test/kotlin/com/baeldung/dates/datetime/UseLocalDateTimeUnitTest.kt similarity index 100% rename from core-kotlin-modules/core-kotlin-2/src/test/kotlin/com/baeldung/dates/datetime/UseLocalDateTimeUnitTest.kt rename to core-kotlin-modules/core-kotlin-date-time/src/test/kotlin/com/baeldung/dates/datetime/UseLocalDateTimeUnitTest.kt diff --git a/core-kotlin-modules/core-kotlin-2/src/test/kotlin/com/baeldung/dates/datetime/UseLocalDateUnitTest.kt b/core-kotlin-modules/core-kotlin-date-time/src/test/kotlin/com/baeldung/dates/datetime/UseLocalDateUnitTest.kt similarity index 100% rename from core-kotlin-modules/core-kotlin-2/src/test/kotlin/com/baeldung/dates/datetime/UseLocalDateUnitTest.kt rename to core-kotlin-modules/core-kotlin-date-time/src/test/kotlin/com/baeldung/dates/datetime/UseLocalDateUnitTest.kt diff --git a/core-kotlin-modules/core-kotlin-2/src/test/kotlin/com/baeldung/dates/datetime/UseLocalTimeUnitTest.kt b/core-kotlin-modules/core-kotlin-date-time/src/test/kotlin/com/baeldung/dates/datetime/UseLocalTimeUnitTest.kt similarity index 100% rename from core-kotlin-modules/core-kotlin-2/src/test/kotlin/com/baeldung/dates/datetime/UseLocalTimeUnitTest.kt rename to core-kotlin-modules/core-kotlin-date-time/src/test/kotlin/com/baeldung/dates/datetime/UseLocalTimeUnitTest.kt diff --git a/core-kotlin-modules/core-kotlin-2/src/test/kotlin/com/baeldung/dates/datetime/UsePeriodUnitTest.kt b/core-kotlin-modules/core-kotlin-date-time/src/test/kotlin/com/baeldung/dates/datetime/UsePeriodUnitTest.kt similarity index 100% rename from core-kotlin-modules/core-kotlin-2/src/test/kotlin/com/baeldung/dates/datetime/UsePeriodUnitTest.kt rename to core-kotlin-modules/core-kotlin-date-time/src/test/kotlin/com/baeldung/dates/datetime/UsePeriodUnitTest.kt diff --git a/core-kotlin-modules/core-kotlin-2/src/test/kotlin/com/baeldung/dates/datetime/UseZonedDateTimeUnitTest.kt b/core-kotlin-modules/core-kotlin-date-time/src/test/kotlin/com/baeldung/dates/datetime/UseZonedDateTimeUnitTest.kt similarity index 100% rename from core-kotlin-modules/core-kotlin-2/src/test/kotlin/com/baeldung/dates/datetime/UseZonedDateTimeUnitTest.kt rename to core-kotlin-modules/core-kotlin-date-time/src/test/kotlin/com/baeldung/dates/datetime/UseZonedDateTimeUnitTest.kt diff --git a/core-kotlin-modules/core-kotlin-design-patterns/README.md b/core-kotlin-modules/core-kotlin-design-patterns/README.md new file mode 100644 index 0000000000..4bdc164a47 --- /dev/null +++ b/core-kotlin-modules/core-kotlin-design-patterns/README.md @@ -0,0 +1,6 @@ +## Core Kotlin Design Patterns + +This module contains articles about design patterns in Kotlin + +### Relevant articles: +- [Creational Design Patterns in Kotlin: Builder](https://www.baeldung.com/kotlin-builder-pattern) diff --git a/core-kotlin-modules/core-kotlin-design-patterns/pom.xml b/core-kotlin-modules/core-kotlin-design-patterns/pom.xml new file mode 100644 index 0000000000..c112602bc2 --- /dev/null +++ b/core-kotlin-modules/core-kotlin-design-patterns/pom.xml @@ -0,0 +1,29 @@ + + + 4.0.0 + core-kotlin-design-patterns + core-kotlin-design-patterns + jar + + + com.baeldung.core-kotlin-modules + core-kotlin-modules + 1.0.0-SNAPSHOT + + + + + org.junit.platform + junit-platform-runner + ${junit.platform.version} + test + + + + + 1.1.1 + + + \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin/src/main/kotlin/com/baeldung/builder/FoodOrder.kt b/core-kotlin-modules/core-kotlin-design-patterns/src/main/kotlin/com/baeldung/builder/FoodOrder.kt similarity index 100% rename from core-kotlin-modules/core-kotlin/src/main/kotlin/com/baeldung/builder/FoodOrder.kt rename to core-kotlin-modules/core-kotlin-design-patterns/src/main/kotlin/com/baeldung/builder/FoodOrder.kt diff --git a/core-kotlin-modules/core-kotlin/src/main/kotlin/com/baeldung/builder/FoodOrderApply.kt b/core-kotlin-modules/core-kotlin-design-patterns/src/main/kotlin/com/baeldung/builder/FoodOrderApply.kt similarity index 100% rename from core-kotlin-modules/core-kotlin/src/main/kotlin/com/baeldung/builder/FoodOrderApply.kt rename to core-kotlin-modules/core-kotlin-design-patterns/src/main/kotlin/com/baeldung/builder/FoodOrderApply.kt diff --git a/core-kotlin-modules/core-kotlin/src/main/kotlin/com/baeldung/builder/FoodOrderNamed.kt b/core-kotlin-modules/core-kotlin-design-patterns/src/main/kotlin/com/baeldung/builder/FoodOrderNamed.kt similarity index 100% rename from core-kotlin-modules/core-kotlin/src/main/kotlin/com/baeldung/builder/FoodOrderNamed.kt rename to core-kotlin-modules/core-kotlin-design-patterns/src/main/kotlin/com/baeldung/builder/FoodOrderNamed.kt diff --git a/core-kotlin-modules/core-kotlin/src/main/kotlin/com/baeldung/builder/Main.kt b/core-kotlin-modules/core-kotlin-design-patterns/src/main/kotlin/com/baeldung/builder/Main.kt similarity index 100% rename from core-kotlin-modules/core-kotlin/src/main/kotlin/com/baeldung/builder/Main.kt rename to core-kotlin-modules/core-kotlin-design-patterns/src/main/kotlin/com/baeldung/builder/Main.kt diff --git a/core-kotlin-modules/core-kotlin/src/test/kotlin/com/baeldung/builder/BuilderPatternUnitTest.kt b/core-kotlin-modules/core-kotlin-design-patterns/src/test/kotlin/com/baeldung/builder/BuilderPatternUnitTest.kt similarity index 100% rename from core-kotlin-modules/core-kotlin/src/test/kotlin/com/baeldung/builder/BuilderPatternUnitTest.kt rename to core-kotlin-modules/core-kotlin-design-patterns/src/test/kotlin/com/baeldung/builder/BuilderPatternUnitTest.kt diff --git a/core-kotlin-modules/core-kotlin-lang-2/README.md b/core-kotlin-modules/core-kotlin-lang-2/README.md index e64a39cb9b..76d490226f 100644 --- a/core-kotlin-modules/core-kotlin-lang-2/README.md +++ b/core-kotlin-modules/core-kotlin-lang-2/README.md @@ -10,4 +10,5 @@ This module contains articles about core features in the Kotlin language. - [Initializing Arrays in Kotlin](https://www.baeldung.com/kotlin-initialize-array) - [Lazy Initialization in Kotlin](https://www.baeldung.com/kotlin-lazy-initialization) - [Comprehensive Guide to Null Safety in Kotlin](https://www.baeldung.com/kotlin-null-safety) +- [Kotlin Scope Functions](https://www.baeldung.com/kotlin-scope-functions) - [[<-- Prev]](/core-kotlin-modules/core-kotlin-lang) diff --git a/core-kotlin-modules/core-kotlin/src/main/kotlin/com/baeldung/scope/ScopeFunctions.kt b/core-kotlin-modules/core-kotlin-lang-2/src/main/kotlin/com/baeldung/scope/ScopeFunctions.kt similarity index 100% rename from core-kotlin-modules/core-kotlin/src/main/kotlin/com/baeldung/scope/ScopeFunctions.kt rename to core-kotlin-modules/core-kotlin-lang-2/src/main/kotlin/com/baeldung/scope/ScopeFunctions.kt diff --git a/core-kotlin-modules/core-kotlin/src/test/kotlin/com/baeldung/scope/ScopeFunctionsUnitTest.kt b/core-kotlin-modules/core-kotlin-lang-2/src/test/kotlin/com/baeldung/scope/ScopeFunctionsUnitTest.kt similarity index 100% rename from core-kotlin-modules/core-kotlin/src/test/kotlin/com/baeldung/scope/ScopeFunctionsUnitTest.kt rename to core-kotlin-modules/core-kotlin-lang-2/src/test/kotlin/com/baeldung/scope/ScopeFunctionsUnitTest.kt diff --git a/core-kotlin-modules/core-kotlin-testing/README.md b/core-kotlin-modules/core-kotlin-testing/README.md new file mode 100644 index 0000000000..f4d89593a7 --- /dev/null +++ b/core-kotlin-modules/core-kotlin-testing/README.md @@ -0,0 +1,6 @@ +## Core Kotlin Testing + +This module contains articles about testing in Kotlin + +### Relevant articles: +- [JUnit 5 for Kotlin Developers](https://www.baeldung.com/junit-5-kotlin) \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-2/pom.xml b/core-kotlin-modules/core-kotlin-testing/pom.xml similarity index 64% rename from core-kotlin-modules/core-kotlin-2/pom.xml rename to core-kotlin-modules/core-kotlin-testing/pom.xml index ae6e2d175a..d38bc62409 100644 --- a/core-kotlin-modules/core-kotlin-2/pom.xml +++ b/core-kotlin-modules/core-kotlin-testing/pom.xml @@ -3,8 +3,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 - core-kotlin-2 - core-kotlin-2 + core-kotlin-testing + core-kotlin-testing jar @@ -15,11 +15,15 @@ - org.assertj - assertj-core - ${assertj.version} + org.junit.platform + junit-platform-runner + ${junit.platform.version} test + + 1.1.1 + + \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin/src/test/kotlin/com/baeldung/junit5/Calculator.kt b/core-kotlin-modules/core-kotlin-testing/src/test/kotlin/com/baeldung/junit5/Calculator.kt similarity index 100% rename from core-kotlin-modules/core-kotlin/src/test/kotlin/com/baeldung/junit5/Calculator.kt rename to core-kotlin-modules/core-kotlin-testing/src/test/kotlin/com/baeldung/junit5/Calculator.kt diff --git a/core-kotlin-modules/core-kotlin/src/test/kotlin/com/baeldung/junit5/CalculatorUnitTest.kt b/core-kotlin-modules/core-kotlin-testing/src/test/kotlin/com/baeldung/junit5/CalculatorUnitTest.kt similarity index 100% rename from core-kotlin-modules/core-kotlin/src/test/kotlin/com/baeldung/junit5/CalculatorUnitTest.kt rename to core-kotlin-modules/core-kotlin-testing/src/test/kotlin/com/baeldung/junit5/CalculatorUnitTest.kt diff --git a/core-kotlin-modules/core-kotlin/src/test/kotlin/com/baeldung/junit5/DivideByZeroException.kt b/core-kotlin-modules/core-kotlin-testing/src/test/kotlin/com/baeldung/junit5/DivideByZeroException.kt similarity index 100% rename from core-kotlin-modules/core-kotlin/src/test/kotlin/com/baeldung/junit5/DivideByZeroException.kt rename to core-kotlin-modules/core-kotlin-testing/src/test/kotlin/com/baeldung/junit5/DivideByZeroException.kt diff --git a/core-kotlin-modules/core-kotlin/src/test/kotlin/com/baeldung/junit5/SimpleUnitTest.kt b/core-kotlin-modules/core-kotlin-testing/src/test/kotlin/com/baeldung/junit5/SimpleUnitTest.kt similarity index 100% rename from core-kotlin-modules/core-kotlin/src/test/kotlin/com/baeldung/junit5/SimpleUnitTest.kt rename to core-kotlin-modules/core-kotlin-testing/src/test/kotlin/com/baeldung/junit5/SimpleUnitTest.kt diff --git a/core-kotlin-modules/core-kotlin/README.md b/core-kotlin-modules/core-kotlin/README.md index 90caccf5c8..48d19c987a 100644 --- a/core-kotlin-modules/core-kotlin/README.md +++ b/core-kotlin-modules/core-kotlin/README.md @@ -7,13 +7,5 @@ This module contains articles about Kotlin core features. - [Kotlin Java Interoperability](https://www.baeldung.com/kotlin-java-interoperability) - [Get a Random Number in Kotlin](https://www.baeldung.com/kotlin-random-number) - [Create a Java and Kotlin Project with Maven](https://www.baeldung.com/kotlin-maven-java-project) -- [Guide to Sorting in Kotlin](https://www.baeldung.com/kotlin-sort) -- [Creational Design Patterns in Kotlin: Builder](https://www.baeldung.com/kotlin-builder-pattern) -- [Kotlin Scope Functions](https://www.baeldung.com/kotlin-scope-functions) -- [Implementing a Binary Tree in Kotlin](https://www.baeldung.com/kotlin-binary-tree) -- [JUnit 5 for Kotlin Developers](https://www.baeldung.com/junit-5-kotlin) -- [Converting Kotlin Data Class from JSON using GSON](https://www.baeldung.com/kotlin-json-convert-data-class) -- [Fuel HTTP Library with Kotlin](https://www.baeldung.com/kotlin-fuel) -- [Introduction to Kovenant Library for Kotlin](https://www.baeldung.com/kotlin-kovenant) -- [Dependency Injection for Kotlin with Injekt](https://www.baeldung.com/kotlin-dependency-injection-with-injekt) -- [[More --> ]](/core-kotlin-modules/core-kotlin-2) +- [Kotlin Ternary Conditional Operator](https://www.baeldung.com/kotlin-ternary-operator) +- [Sequences in Kotlin](https://www.baeldung.com/kotlin/sequences) diff --git a/core-kotlin-modules/core-kotlin-2/src/test/kotlin/com/baeldung/nullassertion/NotNullAssertionUnitTest.kt b/core-kotlin-modules/core-kotlin/src/test/kotlin/com/baeldung/nullassertion/NotNullAssertionUnitTest.kt similarity index 100% rename from core-kotlin-modules/core-kotlin-2/src/test/kotlin/com/baeldung/nullassertion/NotNullAssertionUnitTest.kt rename to core-kotlin-modules/core-kotlin/src/test/kotlin/com/baeldung/nullassertion/NotNullAssertionUnitTest.kt diff --git a/core-kotlin-modules/core-kotlin-2/src/test/kotlin/com/baeldung/sequences/SequencesTest.kt b/core-kotlin-modules/core-kotlin/src/test/kotlin/com/baeldung/sequences/SequencesTest.kt similarity index 100% rename from core-kotlin-modules/core-kotlin-2/src/test/kotlin/com/baeldung/sequences/SequencesTest.kt rename to core-kotlin-modules/core-kotlin/src/test/kotlin/com/baeldung/sequences/SequencesTest.kt diff --git a/core-kotlin-modules/core-kotlin-2/src/test/kotlin/com/baeldung/ternary/TernaryOperatorTest.kt b/core-kotlin-modules/core-kotlin/src/test/kotlin/com/baeldung/ternary/TernaryOperatorTest.kt similarity index 100% rename from core-kotlin-modules/core-kotlin-2/src/test/kotlin/com/baeldung/ternary/TernaryOperatorTest.kt rename to core-kotlin-modules/core-kotlin/src/test/kotlin/com/baeldung/ternary/TernaryOperatorTest.kt diff --git a/core-kotlin-modules/pom.xml b/core-kotlin-modules/pom.xml index de41aecf73..8b626e1c1b 100644 --- a/core-kotlin-modules/pom.xml +++ b/core-kotlin-modules/pom.xml @@ -18,17 +18,19 @@ core-kotlin - core-kotlin-2 core-kotlin-advanced core-kotlin-annotations core-kotlin-collections core-kotlin-concurrency + core-kotlin-date-time + core-kotlin-design-patterns core-kotlin-io core-kotlin-lang core-kotlin-lang-2 - core-kotlin-strings core-kotlin-lang-oop core-kotlin-lang-oop-2 + core-kotlin-strings + core-kotlin-testing diff --git a/core-kotlin-modules/core-kotlin/src/test/kotlin/com/baeldung/gson/GsonUnitTest.kt b/kotlin-libraries-2/src/test/kotlin/com/baeldung/gson/GsonUnitTest.kt similarity index 100% rename from core-kotlin-modules/core-kotlin/src/test/kotlin/com/baeldung/gson/GsonUnitTest.kt rename to kotlin-libraries-2/src/test/kotlin/com/baeldung/gson/GsonUnitTest.kt From 694261868d0eab7d9e4271e7b32bb107adbf896b Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Mon, 8 Jun 2020 12:59:01 +0530 Subject: [PATCH 109/140] JAVA-931: Migrate spring-cloud-connectors-heroku to parent-boot-2 --- .../spring-cloud-connectors-heroku/pom.xml | 14 ++++++++++---- .../connectors/heroku/book/BookController.java | 4 +++- .../cloud/connectors/heroku/book/BookService.java | 6 ++++-- .../heroku/product/ProductController.java | 4 +++- .../connectors/heroku/product/ProductService.java | 6 ++++-- 5 files changed, 24 insertions(+), 10 deletions(-) diff --git a/spring-cloud/spring-cloud-connectors-heroku/pom.xml b/spring-cloud/spring-cloud-connectors-heroku/pom.xml index 1dad3ddcb7..c09a282197 100644 --- a/spring-cloud/spring-cloud-connectors-heroku/pom.xml +++ b/spring-cloud/spring-cloud-connectors-heroku/pom.xml @@ -9,9 +9,9 @@ com.baeldung - parent-boot-1 + parent-boot-2 0.0.1-SNAPSHOT - ../../parent-boot-1 + ../../parent-boot-2 @@ -35,6 +35,11 @@ org.postgresql postgresql + + net.bytebuddy + byte-buddy-dep + ${bytebuddy.version} + com.h2database h2 @@ -55,8 +60,9 @@ - Brixton.SR7 - 9.4-1201-jdbc4 + Hoxton.SR4 + 42.2.10 + 1.10.10 \ No newline at end of file diff --git a/spring-cloud/spring-cloud-connectors-heroku/src/main/java/com/baeldung/spring/cloud/connectors/heroku/book/BookController.java b/spring-cloud/spring-cloud-connectors-heroku/src/main/java/com/baeldung/spring/cloud/connectors/heroku/book/BookController.java index eb2972f35a..f998059028 100644 --- a/spring-cloud/spring-cloud-connectors-heroku/src/main/java/com/baeldung/spring/cloud/connectors/heroku/book/BookController.java +++ b/spring-cloud/spring-cloud-connectors-heroku/src/main/java/com/baeldung/spring/cloud/connectors/heroku/book/BookController.java @@ -1,5 +1,7 @@ package com.baeldung.spring.cloud.connectors.heroku.book; +import java.util.Optional; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; @@ -15,7 +17,7 @@ public class BookController { } @GetMapping("/{bookId}") - public Book findBook(@PathVariable Long bookId) { + public Optional findBook(@PathVariable Long bookId) { return bookService.findBookById(bookId); } diff --git a/spring-cloud/spring-cloud-connectors-heroku/src/main/java/com/baeldung/spring/cloud/connectors/heroku/book/BookService.java b/spring-cloud/spring-cloud-connectors-heroku/src/main/java/com/baeldung/spring/cloud/connectors/heroku/book/BookService.java index 4978ded65f..a83dfe64b7 100644 --- a/spring-cloud/spring-cloud-connectors-heroku/src/main/java/com/baeldung/spring/cloud/connectors/heroku/book/BookService.java +++ b/spring-cloud/spring-cloud-connectors-heroku/src/main/java/com/baeldung/spring/cloud/connectors/heroku/book/BookService.java @@ -1,5 +1,7 @@ package com.baeldung.spring.cloud.connectors.heroku.book; +import java.util.Optional; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Propagation; @@ -15,8 +17,8 @@ public class BookService { this.bookRepository = bookRepository; } - public Book findBookById(Long bookId) { - return bookRepository.findOne(bookId); + public Optional findBookById(Long bookId) { + return bookRepository.findById(bookId); } @Transactional(propagation = Propagation.REQUIRED) diff --git a/spring-cloud/spring-cloud-connectors-heroku/src/main/java/com/baeldung/spring/cloud/connectors/heroku/product/ProductController.java b/spring-cloud/spring-cloud-connectors-heroku/src/main/java/com/baeldung/spring/cloud/connectors/heroku/product/ProductController.java index 51cf4412bf..7875c712f9 100644 --- a/spring-cloud/spring-cloud-connectors-heroku/src/main/java/com/baeldung/spring/cloud/connectors/heroku/product/ProductController.java +++ b/spring-cloud/spring-cloud-connectors-heroku/src/main/java/com/baeldung/spring/cloud/connectors/heroku/product/ProductController.java @@ -1,5 +1,7 @@ package com.baeldung.spring.cloud.connectors.heroku.product; +import java.util.Optional; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; @@ -15,7 +17,7 @@ public class ProductController { } @GetMapping("/{productId}") - public Product findProduct(@PathVariable Long productId) { + public Optional findProduct(@PathVariable Long productId) { return productService.findProductById(productId); } diff --git a/spring-cloud/spring-cloud-connectors-heroku/src/main/java/com/baeldung/spring/cloud/connectors/heroku/product/ProductService.java b/spring-cloud/spring-cloud-connectors-heroku/src/main/java/com/baeldung/spring/cloud/connectors/heroku/product/ProductService.java index f25b4ecf7b..bdd13e9863 100644 --- a/spring-cloud/spring-cloud-connectors-heroku/src/main/java/com/baeldung/spring/cloud/connectors/heroku/product/ProductService.java +++ b/spring-cloud/spring-cloud-connectors-heroku/src/main/java/com/baeldung/spring/cloud/connectors/heroku/product/ProductService.java @@ -1,5 +1,7 @@ package com.baeldung.spring.cloud.connectors.heroku.product; +import java.util.Optional; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Propagation; @@ -15,8 +17,8 @@ public class ProductService { this.productRepository = productRepository; } - public Product findProductById(Long productId) { - return productRepository.findOne(productId); + public Optional findProductById(Long productId) { + return productRepository.findById(productId); } @Transactional(propagation = Propagation.REQUIRED) From 03903e9ee50b9eabc084e8884465966a9e28a514 Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Mon, 8 Jun 2020 10:35:11 +0200 Subject: [PATCH 110/140] JAVA-1782: Add byte-buddy explicitly to avoid versions confilict --- libraries-testing/pom.xml | 7 +++++++ persistence-modules/hibernate-enterprise/pom.xml | 6 ++++++ .../data-flow-server/pom.xml | 6 ++++++ 3 files changed, 19 insertions(+) diff --git a/libraries-testing/pom.xml b/libraries-testing/pom.xml index 89cb0bd494..5a5cb99238 100644 --- a/libraries-testing/pom.xml +++ b/libraries-testing/pom.xml @@ -151,6 +151,13 @@ test + + net.bytebuddy + byte-buddy + ${byte-buddy.version} + test + + diff --git a/persistence-modules/hibernate-enterprise/pom.xml b/persistence-modules/hibernate-enterprise/pom.xml index 060cb4c904..ae58e409c4 100644 --- a/persistence-modules/hibernate-enterprise/pom.xml +++ b/persistence-modules/hibernate-enterprise/pom.xml @@ -55,6 +55,12 @@ hibernate-testing ${hibernate.version} + + net.bytebuddy + byte-buddy + ${byte-buddy.version} + test + diff --git a/spring-cloud-data-flow/spring-cloud-data-flow-stream-processing/data-flow-server/pom.xml b/spring-cloud-data-flow/spring-cloud-data-flow-stream-processing/data-flow-server/pom.xml index ba108dc5c7..34da489cd1 100644 --- a/spring-cloud-data-flow/spring-cloud-data-flow-stream-processing/data-flow-server/pom.xml +++ b/spring-cloud-data-flow/spring-cloud-data-flow-stream-processing/data-flow-server/pom.xml @@ -50,6 +50,12 @@ hibernate-entitymanager ${hibernate.compatible.version} + + net.bytebuddy + byte-buddy + ${byte-buddy.version} + test + From 051ed8f03511547e3714852237dd3c8acf2bde35 Mon Sep 17 00:00:00 2001 From: Ricardo Caldas Date: Mon, 8 Jun 2020 08:49:36 -0300 Subject: [PATCH 111/140] Code indentation fix --- .../JavaArraysToStringUnitTest.java | 43 +++++++++++-------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/core-java-modules/core-java-io-conversions-2/src/test/java/com/baeldung/arraystostring/JavaArraysToStringUnitTest.java b/core-java-modules/core-java-io-conversions-2/src/test/java/com/baeldung/arraystostring/JavaArraysToStringUnitTest.java index 2c81b1358b..146e04df1a 100644 --- a/core-java-modules/core-java-io-conversions-2/src/test/java/com/baeldung/arraystostring/JavaArraysToStringUnitTest.java +++ b/core-java-modules/core-java-io-conversions-2/src/test/java/com/baeldung/arraystostring/JavaArraysToStringUnitTest.java @@ -12,25 +12,32 @@ import static org.junit.Assert.assertTrue; public class JavaArraysToStringUnitTest { - @Test public void givenInstanceOfArray_whenTryingToConvertToString_thenNameOfClassIsShown() { - Object[] arrayOfObjects = { "John", 2, true }; - assertTrue(arrayOfObjects.toString().startsWith("[Ljava.lang.Object;")); - } + @Test + public void givenInstanceOfArray_whenTryingToConvertToString_thenNameOfClassIsShown() { + Object[] arrayOfObjects = { "John", 2, true }; + assertTrue(arrayOfObjects.toString() + .startsWith("[Ljava.lang.Object;")); + } - @Test public void givenInstanceOfArray_useArraysToStringToConvert_thenValueOfObjectsAreShown() { - Object[] arrayOfObjects = { "John", 2, true }; - assertEquals(Arrays.toString(arrayOfObjects), "[John, 2, true]"); - } + @Test + public void givenInstanceOfArray_useArraysToStringToConvert_thenValueOfObjectsAreShown() { + Object[] arrayOfObjects = { "John", 2, true }; + assertEquals(Arrays.toString(arrayOfObjects), "[John, 2, true]"); + } - @Test public void givenInstanceOfDeepArray_userArraysDeepToStringToConvert_thenValueOfInnerObjectsAreShown() { - Object[] innerArray = { "We", "Are", "Inside" }; - Object[] arrayOfObjects = { "John", 2, innerArray }; - assertEquals(Arrays.deepToString(arrayOfObjects), "[John, 2, [We, Are, Inside]]"); - } + @Test + public void givenInstanceOfDeepArray_userArraysDeepToStringToConvert_thenValueOfInnerObjectsAreShown() { + Object[] innerArray = { "We", "Are", "Inside" }; + Object[] arrayOfObjects = { "John", 2, innerArray }; + assertEquals(Arrays.deepToString(arrayOfObjects), "[John, 2, [We, Are, Inside]]"); + } - @Test public void givenInstanceOfDeepArray_useStreamsToConvert_thenValueOfObjectsAreShown() { - Object[] arrayOfObjects = { "John", 2, true }; - List listOfString = Stream.of(arrayOfObjects).map(Object::toString).collect(Collectors.toList()); - assertEquals(listOfString.toString(), "[John, 2, true]"); - } + @Test + public void givenInstanceOfDeepArray_useStreamsToConvert_thenValueOfObjectsAreShown() { + Object[] arrayOfObjects = { "John", 2, true }; + List listOfString = Stream.of(arrayOfObjects) + .map(Object::toString) + .collect(Collectors.toList()); + assertEquals(listOfString.toString(), "[John, 2, true]"); + } } From c098ffa7e940490889261bf9e4918848ea12f92f Mon Sep 17 00:00:00 2001 From: Cristian Rosu Date: Mon, 8 Jun 2020 15:01:46 +0300 Subject: [PATCH 112/140] BAEL-4070: updated test names and parameter ordering + moved code to spring-boot-properties-2 --- .../lists/ListsPropertiesUnitTest.java | 34 +++++++++---------- .../SpringListPropertiesApplication.java | 0 .../src/test/resources/lists.properties | 0 3 files changed, 17 insertions(+), 17 deletions(-) rename spring-boot-modules/{spring-boot-properties => spring-boot-properties-2}/src/test/java/com/baeldung/properties/lists/ListsPropertiesUnitTest.java (61%) rename spring-boot-modules/{spring-boot-properties => spring-boot-properties-2}/src/test/java/com/baeldung/properties/lists/SpringListPropertiesApplication.java (100%) rename spring-boot-modules/{spring-boot-properties => spring-boot-properties-2}/src/test/resources/lists.properties (100%) diff --git a/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/lists/ListsPropertiesUnitTest.java b/spring-boot-modules/spring-boot-properties-2/src/test/java/com/baeldung/properties/lists/ListsPropertiesUnitTest.java similarity index 61% rename from spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/lists/ListsPropertiesUnitTest.java rename to spring-boot-modules/spring-boot-properties-2/src/test/java/com/baeldung/properties/lists/ListsPropertiesUnitTest.java index 80cb8e9ea0..60ba4cc108 100644 --- a/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/lists/ListsPropertiesUnitTest.java +++ b/spring-boot-modules/spring-boot-properties-2/src/test/java/com/baeldung/properties/lists/ListsPropertiesUnitTest.java @@ -46,43 +46,43 @@ public class ListsPropertiesUnitTest { private Environment environment; @Test - public void whenContextIsInitialized_ThenInjectedArrayContainsExpectedValues() { - assertEquals(arrayOfStrings, new String[] {"Baeldung", "dot", "com"}); + public void whenContextIsInitialized_thenInjectedArrayContainsExpectedValues() { + assertEquals(new String[] {"Baeldung", "dot", "com"}, arrayOfStrings); } @Test - public void whenContextIsInitialized_ThenInjectedListContainsUnexpectedValues() { - assertEquals(unexpectedListOfStrings, Collections.singletonList("Baeldung,dot,com")); + public void whenContextIsInitialized_thenInjectedListContainsUnexpectedValues() { + assertEquals(Collections.singletonList("Baeldung,dot,com"), unexpectedListOfStrings); } @Test - public void whenContextIsInitialized_ThenInjectedListContainsExpectedValues() { - assertEquals(listOfStrings, Arrays.asList("Baeldung", "dot", "com")); + public void whenContextIsInitialized_thenInjectedListContainsExpectedValues() { + assertEquals(Arrays.asList("Baeldung", "dot", "com"), listOfStrings); } @Test - public void whenContextIsInitialized_ThenInjectedListV2ContainsExpectedValues() { - assertEquals(listOfStringsV2, Arrays.asList("Baeldung", "dot", "com")); + public void whenContextIsInitialized_thenInjectedListV2ContainsExpectedValues() { + assertEquals(Arrays.asList("Baeldung", "dot", "com"), listOfStringsV2); } @Test - public void whenContextIsInitialized_ThenInjectedListWithCustomDelimiterContainsExpectedValues() { - assertEquals(listOfStringsWithCustomDelimiter, Arrays.asList("Baeldung", "dot", "com")); + public void whenContextIsInitialized_thenInjectedListWithCustomDelimiterContainsExpectedValues() { + assertEquals(Arrays.asList("Baeldung", "dot", "com"), listOfStringsWithCustomDelimiter); } @Test - public void whenContextIsInitialized_ThenInjectedListOfBasicTypesContainsExpectedValues() { - assertEquals(listOfBooleans, Arrays.asList(false, false, true)); - assertEquals(listOfIntegers, Arrays.asList(1, 2, 3, 4)); - assertEquals(listOfCharacters, Arrays.asList('a', 'b', 'c')); + public void whenContextIsInitialized_thenInjectedListOfBasicTypesContainsExpectedValues() { + assertEquals(Arrays.asList(false, false, true), listOfBooleans); + assertEquals(Arrays.asList(1, 2, 3, 4), listOfIntegers); + assertEquals(Arrays.asList('a', 'b', 'c'), listOfCharacters); } @Test - public void whenReadingFromSpringEnvironment_ThenPropertiesHaveExpectedValues() { + public void whenReadingFromSpringEnvironment_thenPropertiesHaveExpectedValues() { String[] arrayOfStrings = environment.getProperty("arrayOfStrings", String[].class); List listOfStrings = (List)environment.getProperty("arrayOfStrings", List.class); - assertEquals(arrayOfStrings, new String[] {"Baeldung", "dot", "com"}); - assertEquals(listOfStrings, Arrays.asList("Baeldung", "dot", "com")); + assertEquals(new String[] {"Baeldung", "dot", "com"}, arrayOfStrings); + assertEquals(Arrays.asList("Baeldung", "dot", "com"), listOfStrings); } } diff --git a/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/lists/SpringListPropertiesApplication.java b/spring-boot-modules/spring-boot-properties-2/src/test/java/com/baeldung/properties/lists/SpringListPropertiesApplication.java similarity index 100% rename from spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/properties/lists/SpringListPropertiesApplication.java rename to spring-boot-modules/spring-boot-properties-2/src/test/java/com/baeldung/properties/lists/SpringListPropertiesApplication.java diff --git a/spring-boot-modules/spring-boot-properties/src/test/resources/lists.properties b/spring-boot-modules/spring-boot-properties-2/src/test/resources/lists.properties similarity index 100% rename from spring-boot-modules/spring-boot-properties/src/test/resources/lists.properties rename to spring-boot-modules/spring-boot-properties-2/src/test/resources/lists.properties From facf0c3929d7140880a14b18434e83fc6ca6b749 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Mon, 8 Jun 2020 18:22:26 +0530 Subject: [PATCH 113/140] JAVA-936: Migrate spring-cloud-task to parent-boot-2 --- spring-cloud/spring-cloud-task/pom.xml | 8 ++++---- .../spring-cloud-task/springcloudtaskbatch/pom.xml | 8 ++++++++ .../src/test/resources/application.yml | 2 +- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/spring-cloud/spring-cloud-task/pom.xml b/spring-cloud/spring-cloud-task/pom.xml index 377d16a999..e2006ee9d3 100644 --- a/spring-cloud/spring-cloud-task/pom.xml +++ b/spring-cloud/spring-cloud-task/pom.xml @@ -10,9 +10,9 @@ com.baeldung - parent-boot-1 + parent-boot-2 0.0.1-SNAPSHOT - ../../parent-boot-1 + ../../parent-boot-2 @@ -40,8 +40,8 @@ - Brixton.SR7 - 1.2.2.RELEASE + Hoxton.SR4 + 2.2.3.RELEASE diff --git a/spring-cloud/spring-cloud-task/springcloudtaskbatch/pom.xml b/spring-cloud/spring-cloud-task/springcloudtaskbatch/pom.xml index fd10322efb..4e6b8b8b6c 100644 --- a/spring-cloud/spring-cloud-task/springcloudtaskbatch/pom.xml +++ b/spring-cloud/spring-cloud-task/springcloudtaskbatch/pom.xml @@ -45,6 +45,13 @@ org.springframework.cloud spring-cloud-task-batch + + + net.bytebuddy + byte-buddy-dep + ${bytebuddy.version} + + com.h2database h2 @@ -63,6 +70,7 @@ com.baeldung.TaskDemo + 1.10.10 diff --git a/spring-cloud/spring-cloud-task/springcloudtaskbatch/src/test/resources/application.yml b/spring-cloud/spring-cloud-task/springcloudtaskbatch/src/test/resources/application.yml index 794ac4d247..8a6e4fc172 100644 --- a/spring-cloud/spring-cloud-task/springcloudtaskbatch/src/test/resources/application.yml +++ b/spring-cloud/spring-cloud-task/springcloudtaskbatch/src/test/resources/application.yml @@ -1,6 +1,6 @@ spring: datasource: - url: jdbc:h2:mem:springcloud + url: jdbc:h2:mem:springcloud;DB_CLOSE_ON_EXIT=FALSE username: sa password: jpa: From db295e33871b7f2d7f728e472a62ef87405bc093 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Mon, 8 Jun 2020 18:33:45 +0530 Subject: [PATCH 114/140] JAVA-936: Migrate spring-cloud-task to parent-boot-2 --- spring-cloud/spring-cloud-task/springcloudtasksink/pom.xml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/spring-cloud/spring-cloud-task/springcloudtasksink/pom.xml b/spring-cloud/spring-cloud-task/springcloudtasksink/pom.xml index 93255959e4..33f6ccde74 100644 --- a/spring-cloud/spring-cloud-task/springcloudtasksink/pom.xml +++ b/spring-cloud/spring-cloud-task/springcloudtasksink/pom.xml @@ -50,8 +50,7 @@ - 1.2.2.RELEASE - 1.3.0.RELEASE + 2.3.1.RELEASE From 78d3c27e1f98df5d5acda9c11d9fff26291e21ab Mon Sep 17 00:00:00 2001 From: Ricardo Caldas Date: Mon, 8 Jun 2020 12:21:05 -0300 Subject: [PATCH 115/140] Code indentation fix --- .../baeldung/arraystostring/JavaArraysToStringUnitTest.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/core-java-modules/core-java-io-conversions-2/src/test/java/com/baeldung/arraystostring/JavaArraysToStringUnitTest.java b/core-java-modules/core-java-io-conversions-2/src/test/java/com/baeldung/arraystostring/JavaArraysToStringUnitTest.java index 146e04df1a..68cd90e7b4 100644 --- a/core-java-modules/core-java-io-conversions-2/src/test/java/com/baeldung/arraystostring/JavaArraysToStringUnitTest.java +++ b/core-java-modules/core-java-io-conversions-2/src/test/java/com/baeldung/arraystostring/JavaArraysToStringUnitTest.java @@ -15,8 +15,7 @@ public class JavaArraysToStringUnitTest { @Test public void givenInstanceOfArray_whenTryingToConvertToString_thenNameOfClassIsShown() { Object[] arrayOfObjects = { "John", 2, true }; - assertTrue(arrayOfObjects.toString() - .startsWith("[Ljava.lang.Object;")); + assertTrue(arrayOfObjects.toString().startsWith("[Ljava.lang.Object;")); } @Test From 32259e7caf765879ac2a9eba2ab6c39f03ef2908 Mon Sep 17 00:00:00 2001 From: Amit Pandey Date: Tue, 9 Jun 2020 00:26:31 +0530 Subject: [PATCH 116/140] Java 1687 1 (#9450) * used password encoder over plaintext password * used password encoder over plaintext password --- .../loginextrafieldscustom/CustomUserRepository.java | 9 ++++++++- .../baeldung/loginextrafieldscustom/SecurityConfig.java | 2 ++ .../baeldung/loginextrafieldssimple/SecurityConfig.java | 2 ++ .../loginextrafieldssimple/SimpleUserRepository.java | 9 ++++++++- 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/spring-5-security/src/main/java/com/baeldung/loginextrafieldscustom/CustomUserRepository.java b/spring-5-security/src/main/java/com/baeldung/loginextrafieldscustom/CustomUserRepository.java index 428c8bf532..effc750940 100644 --- a/spring-5-security/src/main/java/com/baeldung/loginextrafieldscustom/CustomUserRepository.java +++ b/spring-5-security/src/main/java/com/baeldung/loginextrafieldscustom/CustomUserRepository.java @@ -5,11 +5,18 @@ import java.util.Collection; import org.apache.commons.lang3.StringUtils; import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.stereotype.Repository; @Repository("userRepository") public class CustomUserRepository implements UserRepository { + private PasswordEncoder passwordEncoder; + + public CustomUserRepository(PasswordEncoder passwordEncoder) { + this.passwordEncoder = passwordEncoder; + } + @Override public User findUser(String username, String domain) { if (StringUtils.isAnyBlank(username, domain)) { @@ -17,7 +24,7 @@ public class CustomUserRepository implements UserRepository { } else { Collection authorities = new ArrayList<>(); User user = new User(username, domain, - "$2a$10$U3GhSMpsMSOE8Kqsbn58/edxDBKlVuYMh7qk/7ErApYFjJzi2VG5K", true, + passwordEncoder.encode("secret"), true, true, true, true, authorities); return user; } diff --git a/spring-5-security/src/main/java/com/baeldung/loginextrafieldscustom/SecurityConfig.java b/spring-5-security/src/main/java/com/baeldung/loginextrafieldscustom/SecurityConfig.java index def85ab978..88380f1ed6 100644 --- a/spring-5-security/src/main/java/com/baeldung/loginextrafieldscustom/SecurityConfig.java +++ b/spring-5-security/src/main/java/com/baeldung/loginextrafieldscustom/SecurityConfig.java @@ -1,6 +1,7 @@ package com.baeldung.loginextrafieldscustom; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.PropertySource; import org.springframework.security.authentication.AuthenticationProvider; import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; @@ -56,6 +57,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter { return new SimpleUrlAuthenticationFailureHandler("/login?error=true"); } + @Bean public PasswordEncoder passwordEncoder() { return new BCryptPasswordEncoder(); } diff --git a/spring-5-security/src/main/java/com/baeldung/loginextrafieldssimple/SecurityConfig.java b/spring-5-security/src/main/java/com/baeldung/loginextrafieldssimple/SecurityConfig.java index d8c5ea8147..48ca53c0b2 100644 --- a/spring-5-security/src/main/java/com/baeldung/loginextrafieldssimple/SecurityConfig.java +++ b/spring-5-security/src/main/java/com/baeldung/loginextrafieldssimple/SecurityConfig.java @@ -1,6 +1,7 @@ package com.baeldung.loginextrafieldssimple; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.PropertySource; import org.springframework.security.authentication.AuthenticationProvider; import org.springframework.security.authentication.dao.DaoAuthenticationProvider; @@ -59,6 +60,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter { return new SimpleUrlAuthenticationFailureHandler("/login?error=true"); } + @Bean public PasswordEncoder passwordEncoder() { return new BCryptPasswordEncoder(); } diff --git a/spring-5-security/src/main/java/com/baeldung/loginextrafieldssimple/SimpleUserRepository.java b/spring-5-security/src/main/java/com/baeldung/loginextrafieldssimple/SimpleUserRepository.java index e8aaa774a1..44929c6189 100644 --- a/spring-5-security/src/main/java/com/baeldung/loginextrafieldssimple/SimpleUserRepository.java +++ b/spring-5-security/src/main/java/com/baeldung/loginextrafieldssimple/SimpleUserRepository.java @@ -5,11 +5,18 @@ import java.util.Collection; import org.apache.commons.lang3.StringUtils; import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.stereotype.Repository; @Repository("userRepository") public class SimpleUserRepository implements UserRepository { + private PasswordEncoder passwordEncoder; + + public SimpleUserRepository(PasswordEncoder passwordEncoder) { + this.passwordEncoder = passwordEncoder; + } + @Override public User findUser(String username, String domain) { if (StringUtils.isAnyBlank(username, domain)) { @@ -17,7 +24,7 @@ public class SimpleUserRepository implements UserRepository { } else { Collection authorities = new ArrayList<>(); User user = new User(username, domain, - "$2a$10$U3GhSMpsMSOE8Kqsbn58/edxDBKlVuYMh7qk/7ErApYFjJzi2VG5K", true, + passwordEncoder.encode("secret"), true, true, true, true, authorities); return user; } From 8076eebbf8e40e659879a96fc2cacf3bd3b19e0d Mon Sep 17 00:00:00 2001 From: KevinGilmore Date: Mon, 8 Jun 2020 17:59:52 -0500 Subject: [PATCH 117/140] Bael 4082 - update README (#9465) * BAEL-3336 BAEL-3058 add links * BAEL-3319: add link * BAEL-3284: add link * BAEL-3198: add link to article * BAEL-3479: add link to article * BAEL-3485: add article link * SCALA-38: move to new package and add link back to article * SCALA-38: add imports back into unit test * BAEL-3908: add link back to article * BAEL-2893 BAEL-3927 add link back to article * BAEL-4082: add link back to article --- spring-core-4/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-core-4/README.md b/spring-core-4/README.md index 592f4cd011..11a966f23d 100644 --- a/spring-core-4/README.md +++ b/spring-core-4/README.md @@ -6,4 +6,5 @@ This module contains articles about core Spring functionality - [Creating Spring Beans Through Factory Methods](https://www.baeldung.com/spring-beans-factory-methods) - [How to dynamically Autowire a Bean in Spring](https://www.baeldung.com/spring-dynamic-autowire) +- [Spring @Import Annotation](https://www.baeldung.com/spring-import-annotation) - More articles: [[<-- prev]](/spring-core-3) From 5f55b2bbbac9989e668ae447cecdd7ee55f8176c Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Tue, 9 Jun 2020 15:01:40 +0530 Subject: [PATCH 118/140] JAVA-935: Migrate spring-cloud-stream-starters to parent-boot-2 --- .../twitterhdfs/pom.xml | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/spring-cloud/spring-cloud-stream-starters/twitterhdfs/pom.xml b/spring-cloud/spring-cloud-stream-starters/twitterhdfs/pom.xml index 1cfbf7e7c8..c9a73b9aa1 100644 --- a/spring-cloud/spring-cloud-stream-starters/twitterhdfs/pom.xml +++ b/spring-cloud/spring-cloud-stream-starters/twitterhdfs/pom.xml @@ -9,10 +9,10 @@ jar - com.baeldung - parent-boot-1 - 0.0.1-SNAPSHOT - ../../../parent-boot-1 + org.springframework.boot + spring-boot-starter-parent + 2.1.13.RELEASE + @@ -32,6 +32,11 @@ javax.servlet jstl + + org.springframework.boot + spring-boot-starter-test + test + @@ -45,7 +50,7 @@ - 1.3.1.RELEASE + 2.1.2.RELEASE \ No newline at end of file From c387fe5dd604120243e131636533839dc7c8212b Mon Sep 17 00:00:00 2001 From: kwoyke Date: Tue, 9 Jun 2020 21:44:45 +0200 Subject: [PATCH 119/140] BAEL-3979: Get rid of the Spring Snapshots & Milestones repos (#9434) --- .../spring-boot-kotlin/pom.xml | 38 ++----------------- .../repository/ProductRepository.kt | 7 ++-- .../repository/ProductRepositoryCoroutines.kt | 7 ++-- 3 files changed, 9 insertions(+), 43 deletions(-) diff --git a/spring-boot-modules/spring-boot-kotlin/pom.xml b/spring-boot-modules/spring-boot-kotlin/pom.xml index 79d62645da..7ee048546a 100644 --- a/spring-boot-modules/spring-boot-kotlin/pom.xml +++ b/spring-boot-modules/spring-boot-kotlin/pom.xml @@ -14,38 +14,6 @@ ../../parent-kotlin - - - spring-snapshots - Spring Snapshots - https://repo.spring.io/snapshot - - true - - - - spring-milestones - Spring Milestones - https://repo.spring.io/milestone - - - - - - spring-snapshots - Spring Snapshots - https://repo.spring.io/snapshot - - true - - - - spring-milestones - Spring Milestones - https://repo.spring.io/milestone - - - org.jetbrains.kotlin @@ -142,9 +110,9 @@ 1.3.31 - 1.0.0.M1 - 1.0.0.M7 - 1.0.0.BUILD-SNAPSHOT + 1.0.0.RELEASE + 0.8.2.RELEASE + 0.8.4.RELEASE 1.2.1 diff --git a/spring-boot-modules/spring-boot-kotlin/src/main/kotlin/com/baeldung/nonblockingcoroutines/repository/ProductRepository.kt b/spring-boot-modules/spring-boot-kotlin/src/main/kotlin/com/baeldung/nonblockingcoroutines/repository/ProductRepository.kt index 20c3827c26..64ffd014ad 100644 --- a/spring-boot-modules/spring-boot-kotlin/src/main/kotlin/com/baeldung/nonblockingcoroutines/repository/ProductRepository.kt +++ b/spring-boot-modules/spring-boot-kotlin/src/main/kotlin/com/baeldung/nonblockingcoroutines/repository/ProductRepository.kt @@ -1,7 +1,7 @@ package com.baeldung.nonblockingcoroutines.repository import com.baeldung.nonblockingcoroutines.model.Product -import org.springframework.data.r2dbc.function.DatabaseClient +import org.springframework.data.r2dbc.core.DatabaseClient import org.springframework.stereotype.Repository import reactor.core.publisher.Flux import reactor.core.publisher.Mono @@ -10,7 +10,7 @@ import reactor.core.publisher.Mono class ProductRepository(private val client: DatabaseClient) { fun getProductById(id: Int): Mono { - return client.execute().sql("SELECT * FROM products WHERE id = $1") + return client.execute("SELECT * FROM products WHERE id = $1") .bind(0, id) .`as`(Product::class.java) .fetch() @@ -18,8 +18,7 @@ class ProductRepository(private val client: DatabaseClient) { } fun addNewProduct(name: String, price: Float): Mono { - return client.execute() - .sql("INSERT INTO products (name, price) VALUES($1, $2)") + return client.execute("INSERT INTO products (name, price) VALUES($1, $2)") .bind(0, name) .bind(1, price) .then() diff --git a/spring-boot-modules/spring-boot-kotlin/src/main/kotlin/com/baeldung/nonblockingcoroutines/repository/ProductRepositoryCoroutines.kt b/spring-boot-modules/spring-boot-kotlin/src/main/kotlin/com/baeldung/nonblockingcoroutines/repository/ProductRepositoryCoroutines.kt index 60a19d4d00..f2667ec033 100644 --- a/spring-boot-modules/spring-boot-kotlin/src/main/kotlin/com/baeldung/nonblockingcoroutines/repository/ProductRepositoryCoroutines.kt +++ b/spring-boot-modules/spring-boot-kotlin/src/main/kotlin/com/baeldung/nonblockingcoroutines/repository/ProductRepositoryCoroutines.kt @@ -6,14 +6,14 @@ import kotlinx.coroutines.FlowPreview import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.reactive.awaitFirstOrNull import kotlinx.coroutines.reactive.flow.asFlow -import org.springframework.data.r2dbc.function.DatabaseClient +import org.springframework.data.r2dbc.core.DatabaseClient import org.springframework.stereotype.Repository @Repository class ProductRepositoryCoroutines(private val client: DatabaseClient) { suspend fun getProductById(id: Int): Product? = - client.execute().sql("SELECT * FROM products WHERE id = $1") + client.execute("SELECT * FROM products WHERE id = $1") .bind(0, id) .`as`(Product::class.java) .fetch() @@ -21,8 +21,7 @@ class ProductRepositoryCoroutines(private val client: DatabaseClient) { .awaitFirstOrNull() suspend fun addNewProduct(name: String, price: Float) = - client.execute() - .sql("INSERT INTO products (name, price) VALUES($1, $2)") + client.execute("INSERT INTO products (name, price) VALUES($1, $2)") .bind(0, name) .bind(1, price) .then() From 26c11b3e85981879f8248b5bdfb89a88f352e17d Mon Sep 17 00:00:00 2001 From: Mihai238 Date: Tue, 9 Jun 2020 21:49:03 +0200 Subject: [PATCH 120/140] add example for security with profiles (#9185) Co-authored-by: Mihai Lepadat --- .../baeldung/securityprofile/Application.java | 14 ++++++++++ .../ApplicationNoSecurity.java | 17 +++++++++++ .../securityprofile/ApplicationSecurity.java | 16 +++++++++++ .../securityprofile/EmployeeController.java | 16 +++++++++++ .../EmployeeControllerNoSecurityUnitTest.java | 28 +++++++++++++++++++ .../EmployeeControllerUnitTest.java | 28 +++++++++++++++++++ 6 files changed, 119 insertions(+) create mode 100644 spring-5-security/src/main/java/com/baeldung/securityprofile/Application.java create mode 100644 spring-5-security/src/main/java/com/baeldung/securityprofile/ApplicationNoSecurity.java create mode 100644 spring-5-security/src/main/java/com/baeldung/securityprofile/ApplicationSecurity.java create mode 100644 spring-5-security/src/main/java/com/baeldung/securityprofile/EmployeeController.java create mode 100644 spring-5-security/src/test/java/com/baeldung/securityprofile/EmployeeControllerNoSecurityUnitTest.java create mode 100644 spring-5-security/src/test/java/com/baeldung/securityprofile/EmployeeControllerUnitTest.java diff --git a/spring-5-security/src/main/java/com/baeldung/securityprofile/Application.java b/spring-5-security/src/main/java/com/baeldung/securityprofile/Application.java new file mode 100644 index 0000000000..5f17227777 --- /dev/null +++ b/spring-5-security/src/main/java/com/baeldung/securityprofile/Application.java @@ -0,0 +1,14 @@ +package com.baeldung.securityprofile; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; + +@SpringBootApplication +@EnableWebSecurity +public class Application { + + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } +} diff --git a/spring-5-security/src/main/java/com/baeldung/securityprofile/ApplicationNoSecurity.java b/spring-5-security/src/main/java/com/baeldung/securityprofile/ApplicationNoSecurity.java new file mode 100644 index 0000000000..c899eb9268 --- /dev/null +++ b/spring-5-security/src/main/java/com/baeldung/securityprofile/ApplicationNoSecurity.java @@ -0,0 +1,17 @@ +package com.baeldung.securityprofile; + +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Profile; +import org.springframework.security.config.annotation.web.builders.WebSecurity; +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; + +@Configuration +@Profile("test") +public class ApplicationNoSecurity extends WebSecurityConfigurerAdapter { + + @Override + public void configure(WebSecurity web) { + web.ignoring().antMatchers("/**"); + } + +} diff --git a/spring-5-security/src/main/java/com/baeldung/securityprofile/ApplicationSecurity.java b/spring-5-security/src/main/java/com/baeldung/securityprofile/ApplicationSecurity.java new file mode 100644 index 0000000000..51a8d6aa11 --- /dev/null +++ b/spring-5-security/src/main/java/com/baeldung/securityprofile/ApplicationSecurity.java @@ -0,0 +1,16 @@ +package com.baeldung.securityprofile; + +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Profile; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; + +@Configuration +@Profile("prod") +public class ApplicationSecurity extends WebSecurityConfigurerAdapter { + + @Override + protected void configure(HttpSecurity http) throws Exception { + http.authorizeRequests().anyRequest().authenticated(); + } +} diff --git a/spring-5-security/src/main/java/com/baeldung/securityprofile/EmployeeController.java b/spring-5-security/src/main/java/com/baeldung/securityprofile/EmployeeController.java new file mode 100644 index 0000000000..a28a5129ca --- /dev/null +++ b/spring-5-security/src/main/java/com/baeldung/securityprofile/EmployeeController.java @@ -0,0 +1,16 @@ +package com.baeldung.securityprofile; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.Collections; +import java.util.List; + +@RestController +public class EmployeeController { + + @GetMapping("/employees") + public List getEmployees() { + return Collections.singletonList("Adam Johnson"); + } +} diff --git a/spring-5-security/src/test/java/com/baeldung/securityprofile/EmployeeControllerNoSecurityUnitTest.java b/spring-5-security/src/test/java/com/baeldung/securityprofile/EmployeeControllerNoSecurityUnitTest.java new file mode 100644 index 0000000000..7112392412 --- /dev/null +++ b/spring-5-security/src/test/java/com/baeldung/securityprofile/EmployeeControllerNoSecurityUnitTest.java @@ -0,0 +1,28 @@ +package com.baeldung.securityprofile; + +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.test.context.ActiveProfiles; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.web.servlet.MockMvc; + +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +@RunWith(SpringRunner.class) +@WebMvcTest(value = EmployeeController.class) +@ActiveProfiles("test") +public class EmployeeControllerNoSecurityUnitTest { + + @Autowired + private MockMvc mockMvc; + + @Test + public void whenSecurityDisabled_shouldBeOk() throws Exception { + this.mockMvc.perform(get("/employees")) + .andExpect(status().isOk()); + } + +} \ No newline at end of file diff --git a/spring-5-security/src/test/java/com/baeldung/securityprofile/EmployeeControllerUnitTest.java b/spring-5-security/src/test/java/com/baeldung/securityprofile/EmployeeControllerUnitTest.java new file mode 100644 index 0000000000..b8c8b79eb5 --- /dev/null +++ b/spring-5-security/src/test/java/com/baeldung/securityprofile/EmployeeControllerUnitTest.java @@ -0,0 +1,28 @@ +package com.baeldung.securityprofile; + +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.test.context.ActiveProfiles; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.web.servlet.MockMvc; + +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +@RunWith(SpringRunner.class) +@WebMvcTest(value = EmployeeController.class) +@ActiveProfiles("prod") +public class EmployeeControllerUnitTest { + + @Autowired + private MockMvc mockMvc; + + @Test + public void whenSecurityEnabled_shouldBeForbidden() throws Exception { + this.mockMvc.perform(get("/employees")) + .andExpect(status().isForbidden()); + } + +} \ No newline at end of file From bb2d9b400ebc9f918fb3d3f3e82ced4b50ac13b2 Mon Sep 17 00:00:00 2001 From: Greg Martin Date: Tue, 9 Jun 2020 16:03:05 -0400 Subject: [PATCH 121/140] Moved Thymeleaf code into it's own package. --- .../com/baeldung/{pdf => pdfthymeleaf}/PDFThymeleafExample.java | 2 +- .../baeldung/{pdf => pdfthymeleaf}/PDFThymeleafUnitTest.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename pdf/src/main/java/com/baeldung/{pdf => pdfthymeleaf}/PDFThymeleafExample.java (97%) rename pdf/src/test/java/com/baeldung/{pdf => pdfthymeleaf}/PDFThymeleafUnitTest.java (98%) diff --git a/pdf/src/main/java/com/baeldung/pdf/PDFThymeleafExample.java b/pdf/src/main/java/com/baeldung/pdfthymeleaf/PDFThymeleafExample.java similarity index 97% rename from pdf/src/main/java/com/baeldung/pdf/PDFThymeleafExample.java rename to pdf/src/main/java/com/baeldung/pdfthymeleaf/PDFThymeleafExample.java index 2e1df1d320..28879b8958 100644 --- a/pdf/src/main/java/com/baeldung/pdf/PDFThymeleafExample.java +++ b/pdf/src/main/java/com/baeldung/pdfthymeleaf/PDFThymeleafExample.java @@ -1,4 +1,4 @@ -package com.baeldung.pdf; +package com.baeldung.pdfthymeleaf; import com.lowagie.text.DocumentException; import org.thymeleaf.TemplateEngine; diff --git a/pdf/src/test/java/com/baeldung/pdf/PDFThymeleafUnitTest.java b/pdf/src/test/java/com/baeldung/pdfthymeleaf/PDFThymeleafUnitTest.java similarity index 98% rename from pdf/src/test/java/com/baeldung/pdf/PDFThymeleafUnitTest.java rename to pdf/src/test/java/com/baeldung/pdfthymeleaf/PDFThymeleafUnitTest.java index e253dce06c..75d38fbf22 100644 --- a/pdf/src/test/java/com/baeldung/pdf/PDFThymeleafUnitTest.java +++ b/pdf/src/test/java/com/baeldung/pdfthymeleaf/PDFThymeleafUnitTest.java @@ -1,4 +1,4 @@ -package com.baeldung.pdf; +package com.baeldung.pdfthymeleaf; import com.lowagie.text.DocumentException; import org.junit.Test; From f01c29efe0eb113f6d7586fbee3aea8065d0f0dd Mon Sep 17 00:00:00 2001 From: Kirill Vlasov Date: Wed, 10 Jun 2020 14:37:14 +0500 Subject: [PATCH 122/140] BAEL-3824 code review fixes --- .../spring-boot-mvc-3/.gitignore | 25 ------------------- .../spring-boot-mvc-3/README.md | 2 ++ 2 files changed, 2 insertions(+), 25 deletions(-) delete mode 100644 spring-boot-modules/spring-boot-mvc-3/.gitignore diff --git a/spring-boot-modules/spring-boot-mvc-3/.gitignore b/spring-boot-modules/spring-boot-mvc-3/.gitignore deleted file mode 100644 index 82eca336e3..0000000000 --- a/spring-boot-modules/spring-boot-mvc-3/.gitignore +++ /dev/null @@ -1,25 +0,0 @@ -/target/ -!.mvn/wrapper/maven-wrapper.jar - -### STS ### -.apt_generated -.classpath -.factorypath -.project -.settings -.springBeans -.sts4-cache - -### IntelliJ IDEA ### -.idea -*.iws -*.iml -*.ipr - -### NetBeans ### -/nbproject/private/ -/build/ -/nbbuild/ -/dist/ -/nbdist/ -/.nb-gradle/ \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-mvc-3/README.md b/spring-boot-modules/spring-boot-mvc-3/README.md index 1050adb2d6..c220c6c405 100644 --- a/spring-boot-modules/spring-boot-mvc-3/README.md +++ b/spring-boot-modules/spring-boot-mvc-3/README.md @@ -3,3 +3,5 @@ This module contains articles about Spring Web MVC in Spring Boot projects. ### Relevant Articles: + +- More articles: [[prev -->]](/spring-boot-modules/spring-boot-mvc-2) \ No newline at end of file From e2fb7160107e3e205bfa9008c3da1b2e7d80879d Mon Sep 17 00:00:00 2001 From: Ricardo Caldas Date: Wed, 10 Jun 2020 08:03:34 -0300 Subject: [PATCH 123/140] change method names, move package --- .../baeldung/arrays}/JavaArraysToStringUnitTest.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) rename core-java-modules/{core-java-io-conversions-2/src/test/java/com/baeldung/arraystostring => core-java-arrays-guides/src/test/java/com/baeldung/arrays}/JavaArraysToStringUnitTest.java (72%) diff --git a/core-java-modules/core-java-io-conversions-2/src/test/java/com/baeldung/arraystostring/JavaArraysToStringUnitTest.java b/core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/arrays/JavaArraysToStringUnitTest.java similarity index 72% rename from core-java-modules/core-java-io-conversions-2/src/test/java/com/baeldung/arraystostring/JavaArraysToStringUnitTest.java rename to core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/arrays/JavaArraysToStringUnitTest.java index 68cd90e7b4..064803465d 100644 --- a/core-java-modules/core-java-io-conversions-2/src/test/java/com/baeldung/arraystostring/JavaArraysToStringUnitTest.java +++ b/core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/arrays/JavaArraysToStringUnitTest.java @@ -1,4 +1,4 @@ -package com.baeldung.arraystostring; +package com.baeldung.arrays; import org.junit.Test; @@ -19,24 +19,24 @@ public class JavaArraysToStringUnitTest { } @Test - public void givenInstanceOfArray_useArraysToStringToConvert_thenValueOfObjectsAreShown() { + public void givenInstanceOfArray_whenUsingArraysToStringToConvert_thenValueOfObjectsAreShown() { Object[] arrayOfObjects = { "John", 2, true }; assertEquals(Arrays.toString(arrayOfObjects), "[John, 2, true]"); } @Test - public void givenInstanceOfDeepArray_userArraysDeepToStringToConvert_thenValueOfInnerObjectsAreShown() { + public void givenInstanceOfDeepArray_whenUsingArraysDeepToStringToConvert_thenValueOfInnerObjectsAreShown() { Object[] innerArray = { "We", "Are", "Inside" }; Object[] arrayOfObjects = { "John", 2, innerArray }; assertEquals(Arrays.deepToString(arrayOfObjects), "[John, 2, [We, Are, Inside]]"); } @Test - public void givenInstanceOfDeepArray_useStreamsToConvert_thenValueOfObjectsAreShown() { + public void givenInstanceOfDeepArray_whenUsingStreamsToConvert_thenValueOfObjectsAreShown() { Object[] arrayOfObjects = { "John", 2, true }; List listOfString = Stream.of(arrayOfObjects) - .map(Object::toString) - .collect(Collectors.toList()); + .map(Object::toString) + .collect(Collectors.toList()); assertEquals(listOfString.toString(), "[John, 2, true]"); } } From 8f20c9cca45200d22860bb0b23d0539d1ac17e78 Mon Sep 17 00:00:00 2001 From: Catalin Burcea Date: Wed, 10 Jun 2020 16:15:57 +0300 Subject: [PATCH 124/140] BAEL-1362 - Retry with Spring Cloud Ribbon (#9237) --- spring-cloud/pom.xml | 1 + .../spring-cloud-ribbon-retry/pom.xml | 40 ++++++++++++++ .../ribbon-client-service/pom.xml | 39 ++++++++++++++ .../cloud/ribbon/retry/RibbonClientApp.java | 12 +++++ .../ExponentialBackoffRetryFactory.java | 26 ++++++++++ .../ExponentialRandomBackoffRetryFactory.java | 26 ++++++++++ .../backoff/FixedBackoffRetryFactory.java | 24 +++++++++ .../retry/config/RibbonConfiguration.java | 20 +++++++ .../WeatherClientRibbonConfiguration.java | 19 +++++++ .../controller/RibbonClientController.java | 21 ++++++++ .../src/main/resources/application.yml | 17 ++++++ .../RibbonRetryFailureIntegrationTest.java | 50 ++++++++++++++++++ .../RibbonRetrySuccessIntegrationTest.java | 52 +++++++++++++++++++ .../ribbon-weather-service/pom.xml | 21 ++++++++ .../ribbon/retry/RibbonWeatherServiceApp.java | 12 +++++ .../cloud/ribbon/retry/WeatherController.java | 39 ++++++++++++++ .../src/main/resources/application.properties | 2 + 17 files changed, 421 insertions(+) create mode 100644 spring-cloud/spring-cloud-ribbon-retry/pom.xml create mode 100644 spring-cloud/spring-cloud-ribbon-retry/ribbon-client-service/pom.xml create mode 100644 spring-cloud/spring-cloud-ribbon-retry/ribbon-client-service/src/main/java/com/baeldung/spring/cloud/ribbon/retry/RibbonClientApp.java create mode 100644 spring-cloud/spring-cloud-ribbon-retry/ribbon-client-service/src/main/java/com/baeldung/spring/cloud/ribbon/retry/backoff/ExponentialBackoffRetryFactory.java create mode 100644 spring-cloud/spring-cloud-ribbon-retry/ribbon-client-service/src/main/java/com/baeldung/spring/cloud/ribbon/retry/backoff/ExponentialRandomBackoffRetryFactory.java create mode 100644 spring-cloud/spring-cloud-ribbon-retry/ribbon-client-service/src/main/java/com/baeldung/spring/cloud/ribbon/retry/backoff/FixedBackoffRetryFactory.java create mode 100644 spring-cloud/spring-cloud-ribbon-retry/ribbon-client-service/src/main/java/com/baeldung/spring/cloud/ribbon/retry/config/RibbonConfiguration.java create mode 100644 spring-cloud/spring-cloud-ribbon-retry/ribbon-client-service/src/main/java/com/baeldung/spring/cloud/ribbon/retry/config/WeatherClientRibbonConfiguration.java create mode 100644 spring-cloud/spring-cloud-ribbon-retry/ribbon-client-service/src/main/java/com/baeldung/spring/cloud/ribbon/retry/controller/RibbonClientController.java create mode 100644 spring-cloud/spring-cloud-ribbon-retry/ribbon-client-service/src/main/resources/application.yml create mode 100644 spring-cloud/spring-cloud-ribbon-retry/ribbon-client-service/src/test/java/com/baeldung/spring/cloud/ribbon/retry/RibbonRetryFailureIntegrationTest.java create mode 100644 spring-cloud/spring-cloud-ribbon-retry/ribbon-client-service/src/test/java/com/baeldung/spring/cloud/ribbon/retry/RibbonRetrySuccessIntegrationTest.java create mode 100644 spring-cloud/spring-cloud-ribbon-retry/ribbon-weather-service/pom.xml create mode 100644 spring-cloud/spring-cloud-ribbon-retry/ribbon-weather-service/src/main/java/com/baeldung/spring/cloud/ribbon/retry/RibbonWeatherServiceApp.java create mode 100644 spring-cloud/spring-cloud-ribbon-retry/ribbon-weather-service/src/main/java/com/baeldung/spring/cloud/ribbon/retry/WeatherController.java create mode 100644 spring-cloud/spring-cloud-ribbon-retry/ribbon-weather-service/src/main/resources/application.properties diff --git a/spring-cloud/pom.xml b/spring-cloud/pom.xml index 3de527c33b..6fddb1693f 100644 --- a/spring-cloud/pom.xml +++ b/spring-cloud/pom.xml @@ -40,6 +40,7 @@ spring-cloud-task spring-cloud-zuul spring-cloud-zuul-fallback + spring-cloud-ribbon-retry diff --git a/spring-cloud/spring-cloud-ribbon-retry/pom.xml b/spring-cloud/spring-cloud-ribbon-retry/pom.xml new file mode 100644 index 0000000000..5318ea6913 --- /dev/null +++ b/spring-cloud/spring-cloud-ribbon-retry/pom.xml @@ -0,0 +1,40 @@ + + + 4.0.0 + com.baeldung.spring.cloud + spring-cloud-ribbon-retry + 0.0.1-SNAPSHOT + spring-cloud-ribbon-retry + pom + + + com.baeldung + parent-boot-2 + 0.0.1-SNAPSHOT + ../../parent-boot-2 + + + + ribbon-client-service + ribbon-weather-service + + + + + + org.springframework.cloud + spring-cloud-starter-parent + ${spring-cloud.version} + pom + import + + + + + + Hoxton.SR3 + + + \ No newline at end of file diff --git a/spring-cloud/spring-cloud-ribbon-retry/ribbon-client-service/pom.xml b/spring-cloud/spring-cloud-ribbon-retry/ribbon-client-service/pom.xml new file mode 100644 index 0000000000..ad47eb6c84 --- /dev/null +++ b/spring-cloud/spring-cloud-ribbon-retry/ribbon-client-service/pom.xml @@ -0,0 +1,39 @@ + + + 4.0.0 + ribbon-client-service + + + com.baeldung.spring.cloud + spring-cloud-ribbon-retry + 0.0.1-SNAPSHOT + + + + + org.springframework.cloud + spring-cloud-starter-netflix-ribbon + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.retry + spring-retry + + + com.baeldung.spring.cloud + ribbon-weather-service + 0.0.1-SNAPSHOT + test + + + + + Hoxton.SR3 + + + \ No newline at end of file diff --git a/spring-cloud/spring-cloud-ribbon-retry/ribbon-client-service/src/main/java/com/baeldung/spring/cloud/ribbon/retry/RibbonClientApp.java b/spring-cloud/spring-cloud-ribbon-retry/ribbon-client-service/src/main/java/com/baeldung/spring/cloud/ribbon/retry/RibbonClientApp.java new file mode 100644 index 0000000000..e06d4a93a1 --- /dev/null +++ b/spring-cloud/spring-cloud-ribbon-retry/ribbon-client-service/src/main/java/com/baeldung/spring/cloud/ribbon/retry/RibbonClientApp.java @@ -0,0 +1,12 @@ +package com.baeldung.spring.cloud.ribbon.retry; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class RibbonClientApp { + + public static void main(String[] args) { + SpringApplication.run(RibbonClientApp.class, args); + } +} \ No newline at end of file diff --git a/spring-cloud/spring-cloud-ribbon-retry/ribbon-client-service/src/main/java/com/baeldung/spring/cloud/ribbon/retry/backoff/ExponentialBackoffRetryFactory.java b/spring-cloud/spring-cloud-ribbon-retry/ribbon-client-service/src/main/java/com/baeldung/spring/cloud/ribbon/retry/backoff/ExponentialBackoffRetryFactory.java new file mode 100644 index 0000000000..c70ee71b7d --- /dev/null +++ b/spring-cloud/spring-cloud-ribbon-retry/ribbon-client-service/src/main/java/com/baeldung/spring/cloud/ribbon/retry/backoff/ExponentialBackoffRetryFactory.java @@ -0,0 +1,26 @@ +package com.baeldung.spring.cloud.ribbon.retry.backoff; + +import org.springframework.cloud.netflix.ribbon.RibbonLoadBalancedRetryFactory; +import org.springframework.cloud.netflix.ribbon.SpringClientFactory; +import org.springframework.context.annotation.Profile; +import org.springframework.retry.backoff.BackOffPolicy; +import org.springframework.retry.backoff.ExponentialBackOffPolicy; +import org.springframework.stereotype.Component; + +@Component +@Profile("exponential-backoff") +class ExponentialBackoffRetryFactory extends RibbonLoadBalancedRetryFactory { + + public ExponentialBackoffRetryFactory(SpringClientFactory clientFactory) { + super(clientFactory); + } + + @Override + public BackOffPolicy createBackOffPolicy(String service) { + ExponentialBackOffPolicy exponentialBackOffPolicy = new ExponentialBackOffPolicy(); + exponentialBackOffPolicy.setInitialInterval(1000); + exponentialBackOffPolicy.setMultiplier(2); + exponentialBackOffPolicy.setMaxInterval(10000); + return exponentialBackOffPolicy; + } +} \ No newline at end of file diff --git a/spring-cloud/spring-cloud-ribbon-retry/ribbon-client-service/src/main/java/com/baeldung/spring/cloud/ribbon/retry/backoff/ExponentialRandomBackoffRetryFactory.java b/spring-cloud/spring-cloud-ribbon-retry/ribbon-client-service/src/main/java/com/baeldung/spring/cloud/ribbon/retry/backoff/ExponentialRandomBackoffRetryFactory.java new file mode 100644 index 0000000000..c1fad4d1a0 --- /dev/null +++ b/spring-cloud/spring-cloud-ribbon-retry/ribbon-client-service/src/main/java/com/baeldung/spring/cloud/ribbon/retry/backoff/ExponentialRandomBackoffRetryFactory.java @@ -0,0 +1,26 @@ +package com.baeldung.spring.cloud.ribbon.retry.backoff; + +import org.springframework.cloud.netflix.ribbon.RibbonLoadBalancedRetryFactory; +import org.springframework.cloud.netflix.ribbon.SpringClientFactory; +import org.springframework.context.annotation.Profile; +import org.springframework.retry.backoff.BackOffPolicy; +import org.springframework.retry.backoff.ExponentialRandomBackOffPolicy; +import org.springframework.stereotype.Component; + +@Component +@Profile("exponential-random-backoff") +class ExponentialRandomBackoffRetryFactory extends RibbonLoadBalancedRetryFactory { + + public ExponentialRandomBackoffRetryFactory(SpringClientFactory clientFactory) { + super(clientFactory); + } + + @Override + public BackOffPolicy createBackOffPolicy(String service) { + ExponentialRandomBackOffPolicy exponentialRandomBackOffPolicy = new ExponentialRandomBackOffPolicy(); + exponentialRandomBackOffPolicy.setInitialInterval(1000); + exponentialRandomBackOffPolicy.setMultiplier(2); + exponentialRandomBackOffPolicy.setMaxInterval(10000); + return exponentialRandomBackOffPolicy; + } +} \ No newline at end of file diff --git a/spring-cloud/spring-cloud-ribbon-retry/ribbon-client-service/src/main/java/com/baeldung/spring/cloud/ribbon/retry/backoff/FixedBackoffRetryFactory.java b/spring-cloud/spring-cloud-ribbon-retry/ribbon-client-service/src/main/java/com/baeldung/spring/cloud/ribbon/retry/backoff/FixedBackoffRetryFactory.java new file mode 100644 index 0000000000..6dab5d15b4 --- /dev/null +++ b/spring-cloud/spring-cloud-ribbon-retry/ribbon-client-service/src/main/java/com/baeldung/spring/cloud/ribbon/retry/backoff/FixedBackoffRetryFactory.java @@ -0,0 +1,24 @@ +package com.baeldung.spring.cloud.ribbon.retry.backoff; + +import org.springframework.cloud.netflix.ribbon.RibbonLoadBalancedRetryFactory; +import org.springframework.cloud.netflix.ribbon.SpringClientFactory; +import org.springframework.context.annotation.Profile; +import org.springframework.retry.backoff.BackOffPolicy; +import org.springframework.retry.backoff.FixedBackOffPolicy; +import org.springframework.stereotype.Component; + +@Component +@Profile("fixed-backoff") +class FixedBackoffRetryFactory extends RibbonLoadBalancedRetryFactory { + + public FixedBackoffRetryFactory(SpringClientFactory clientFactory) { + super(clientFactory); + } + + @Override + public BackOffPolicy createBackOffPolicy(String service) { + FixedBackOffPolicy fixedBackOffPolicy = new FixedBackOffPolicy(); + fixedBackOffPolicy.setBackOffPeriod(2000); + return fixedBackOffPolicy; + } +} \ No newline at end of file diff --git a/spring-cloud/spring-cloud-ribbon-retry/ribbon-client-service/src/main/java/com/baeldung/spring/cloud/ribbon/retry/config/RibbonConfiguration.java b/spring-cloud/spring-cloud-ribbon-retry/ribbon-client-service/src/main/java/com/baeldung/spring/cloud/ribbon/retry/config/RibbonConfiguration.java new file mode 100644 index 0000000000..c493b4dbe2 --- /dev/null +++ b/spring-cloud/spring-cloud-ribbon-retry/ribbon-client-service/src/main/java/com/baeldung/spring/cloud/ribbon/retry/config/RibbonConfiguration.java @@ -0,0 +1,20 @@ +package com.baeldung.spring.cloud.ribbon.retry.config; + +import com.netflix.loadbalancer.IPing; +import com.netflix.loadbalancer.IRule; +import com.netflix.loadbalancer.PingUrl; +import com.netflix.loadbalancer.WeightedResponseTimeRule; +import org.springframework.context.annotation.Bean; + +public class RibbonConfiguration { + + @Bean + public IPing ribbonPing() { + return new PingUrl(); + } + + @Bean + public IRule ribbonRule() { + return new WeightedResponseTimeRule(); + } +} \ No newline at end of file diff --git a/spring-cloud/spring-cloud-ribbon-retry/ribbon-client-service/src/main/java/com/baeldung/spring/cloud/ribbon/retry/config/WeatherClientRibbonConfiguration.java b/spring-cloud/spring-cloud-ribbon-retry/ribbon-client-service/src/main/java/com/baeldung/spring/cloud/ribbon/retry/config/WeatherClientRibbonConfiguration.java new file mode 100644 index 0000000000..88955db025 --- /dev/null +++ b/spring-cloud/spring-cloud-ribbon-retry/ribbon-client-service/src/main/java/com/baeldung/spring/cloud/ribbon/retry/config/WeatherClientRibbonConfiguration.java @@ -0,0 +1,19 @@ +package com.baeldung.spring.cloud.ribbon.retry.config; + +import org.springframework.cloud.client.loadbalancer.LoadBalanced; +import org.springframework.cloud.netflix.ribbon.RibbonClient; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.client.RestTemplate; + +@Configuration +@RibbonClient(name = "weather-service", configuration = RibbonConfiguration.class) +public class WeatherClientRibbonConfiguration { + + @LoadBalanced + @Bean + RestTemplate getRestTemplate() { + return new RestTemplate(); + } + +} diff --git a/spring-cloud/spring-cloud-ribbon-retry/ribbon-client-service/src/main/java/com/baeldung/spring/cloud/ribbon/retry/controller/RibbonClientController.java b/spring-cloud/spring-cloud-ribbon-retry/ribbon-client-service/src/main/java/com/baeldung/spring/cloud/ribbon/retry/controller/RibbonClientController.java new file mode 100644 index 0000000000..ebe5b58386 --- /dev/null +++ b/spring-cloud/spring-cloud-ribbon-retry/ribbon-client-service/src/main/java/com/baeldung/spring/cloud/ribbon/retry/controller/RibbonClientController.java @@ -0,0 +1,21 @@ +package com.baeldung.spring.cloud.ribbon.retry.controller; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.client.RestTemplate; + +@RestController +public class RibbonClientController { + + private static final String WEATHER_SERVICE = "weather-service"; + + @Autowired + private RestTemplate restTemplate; + + @GetMapping("/client/weather") + public String weather() { + String result = restTemplate.getForObject("http://" + WEATHER_SERVICE + "/weather", String.class); + return "Weather Service Response: " + result; + } +} diff --git a/spring-cloud/spring-cloud-ribbon-retry/ribbon-client-service/src/main/resources/application.yml b/spring-cloud/spring-cloud-ribbon-retry/ribbon-client-service/src/main/resources/application.yml new file mode 100644 index 0000000000..3199f38dce --- /dev/null +++ b/spring-cloud/spring-cloud-ribbon-retry/ribbon-client-service/src/main/resources/application.yml @@ -0,0 +1,17 @@ +spring: + profiles: + # fixed-backoff, exponential-backoff, exponential-random-backoff + active: fixed-backoff + application: + name: ribbon-client + +weather-service: + ribbon: + eureka: + enabled: false + listOfServers: http://localhost:8081, http://localhost:8082 + ServerListRefreshInterval: 5000 + MaxAutoRetries: 3 + MaxAutoRetriesNextServer: 1 + OkToRetryOnAllOperations: true + retryableStatusCodes: 503, 408 diff --git a/spring-cloud/spring-cloud-ribbon-retry/ribbon-client-service/src/test/java/com/baeldung/spring/cloud/ribbon/retry/RibbonRetryFailureIntegrationTest.java b/spring-cloud/spring-cloud-ribbon-retry/ribbon-client-service/src/test/java/com/baeldung/spring/cloud/ribbon/retry/RibbonRetryFailureIntegrationTest.java new file mode 100644 index 0000000000..0e72bdbb86 --- /dev/null +++ b/spring-cloud/spring-cloud-ribbon-retry/ribbon-client-service/src/test/java/com/baeldung/spring/cloud/ribbon/retry/RibbonRetryFailureIntegrationTest.java @@ -0,0 +1,50 @@ +package com.baeldung.spring.cloud.ribbon.retry; + +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.boot.web.server.LocalServerPort; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.http.ResponseEntity; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = RibbonClientApp.class) +public class RibbonRetryFailureIntegrationTest { + + private static ConfigurableApplicationContext weatherServiceInstance1; + private static ConfigurableApplicationContext weatherServiceInstance2; + + @LocalServerPort + private int port; + private TestRestTemplate restTemplate = new TestRestTemplate(); + + @BeforeAll + public static void setup() { + weatherServiceInstance1 = startApp(8081); + weatherServiceInstance2 = startApp(8082); + } + + @AfterAll + public static void cleanup() { + weatherServiceInstance1.close(); + weatherServiceInstance2.close(); + } + + private static ConfigurableApplicationContext startApp(int port) { + return SpringApplication.run(RibbonWeatherServiceApp.class, "--server.port=" + port, "--successful.call.divisor=6"); + } + + @Test + public void whenRibbonClientIsCalledAndServiceUnavailable_thenFailure() { + String url = "http://localhost:" + port + "/client/weather"; + + ResponseEntity response = restTemplate.getForEntity(url, String.class); + + assertTrue(response.getStatusCode().is5xxServerError()); + } + +} diff --git a/spring-cloud/spring-cloud-ribbon-retry/ribbon-client-service/src/test/java/com/baeldung/spring/cloud/ribbon/retry/RibbonRetrySuccessIntegrationTest.java b/spring-cloud/spring-cloud-ribbon-retry/ribbon-client-service/src/test/java/com/baeldung/spring/cloud/ribbon/retry/RibbonRetrySuccessIntegrationTest.java new file mode 100644 index 0000000000..2055159117 --- /dev/null +++ b/spring-cloud/spring-cloud-ribbon-retry/ribbon-client-service/src/test/java/com/baeldung/spring/cloud/ribbon/retry/RibbonRetrySuccessIntegrationTest.java @@ -0,0 +1,52 @@ +package com.baeldung.spring.cloud.ribbon.retry; + +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.boot.web.server.LocalServerPort; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.http.ResponseEntity; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = RibbonClientApp.class) +public class RibbonRetrySuccessIntegrationTest { + + private static ConfigurableApplicationContext weatherServiceInstance1; + private static ConfigurableApplicationContext weatherServiceInstance2; + + @LocalServerPort + private int port; + private TestRestTemplate restTemplate = new TestRestTemplate(); + + @BeforeAll + public static void setup() { + weatherServiceInstance1 = startApp(8081); + weatherServiceInstance2 = startApp(8082); + } + + private static ConfigurableApplicationContext startApp(int port) { + return SpringApplication.run(RibbonWeatherServiceApp.class, "--server.port=" + port, "--successful.call.divisor=3"); + } + + @AfterAll + public static void cleanup() { + weatherServiceInstance1.close(); + weatherServiceInstance2.close(); + } + + @Test + public void whenRibbonClientIsCalledAndServiceAvailable_thenSuccess() { + String url = "http://localhost:" + port + "/client/weather"; + + ResponseEntity response = restTemplate.getForEntity(url, String.class); + + assertTrue(response.getStatusCode().is2xxSuccessful()); + assertEquals(response.getBody(), "Weather Service Response: Today's a sunny day"); + } + +} diff --git a/spring-cloud/spring-cloud-ribbon-retry/ribbon-weather-service/pom.xml b/spring-cloud/spring-cloud-ribbon-retry/ribbon-weather-service/pom.xml new file mode 100644 index 0000000000..f091341025 --- /dev/null +++ b/spring-cloud/spring-cloud-ribbon-retry/ribbon-weather-service/pom.xml @@ -0,0 +1,21 @@ + + + 4.0.0 + ribbon-weather-service + + + com.baeldung.spring.cloud + spring-cloud-ribbon-retry + 0.0.1-SNAPSHOT + + + + + org.springframework.boot + spring-boot-starter-web + + + + \ No newline at end of file diff --git a/spring-cloud/spring-cloud-ribbon-retry/ribbon-weather-service/src/main/java/com/baeldung/spring/cloud/ribbon/retry/RibbonWeatherServiceApp.java b/spring-cloud/spring-cloud-ribbon-retry/ribbon-weather-service/src/main/java/com/baeldung/spring/cloud/ribbon/retry/RibbonWeatherServiceApp.java new file mode 100644 index 0000000000..ceeacbd426 --- /dev/null +++ b/spring-cloud/spring-cloud-ribbon-retry/ribbon-weather-service/src/main/java/com/baeldung/spring/cloud/ribbon/retry/RibbonWeatherServiceApp.java @@ -0,0 +1,12 @@ +package com.baeldung.spring.cloud.ribbon.retry; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class RibbonWeatherServiceApp { + + public static void main(String[] args) { + SpringApplication.run(RibbonWeatherServiceApp.class, args); + } +} diff --git a/spring-cloud/spring-cloud-ribbon-retry/ribbon-weather-service/src/main/java/com/baeldung/spring/cloud/ribbon/retry/WeatherController.java b/spring-cloud/spring-cloud-ribbon-retry/ribbon-weather-service/src/main/java/com/baeldung/spring/cloud/ribbon/retry/WeatherController.java new file mode 100644 index 0000000000..ec0b94e505 --- /dev/null +++ b/spring-cloud/spring-cloud-ribbon-retry/ribbon-weather-service/src/main/java/com/baeldung/spring/cloud/ribbon/retry/WeatherController.java @@ -0,0 +1,39 @@ +package com.baeldung.spring.cloud.ribbon.retry; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class WeatherController { + + private static final Logger LOGGER = LoggerFactory.getLogger(WeatherController.class); + + private int nrOfCalls = 0; + + @Value("${successful.call.divisor}") + private int divisor; + + @GetMapping("/") + public String health() { + return "I am Ok"; + } + + @GetMapping("/weather") + public ResponseEntity weather() { + LOGGER.info("Providing today's weather information"); + if (isServiceUnavailable()) { + return new ResponseEntity<>(HttpStatus.SERVICE_UNAVAILABLE); + } + LOGGER.info("Today's a sunny day"); + return new ResponseEntity<>("Today's a sunny day", HttpStatus.OK); + } + + private boolean isServiceUnavailable() { + return ++nrOfCalls % divisor != 0; + } +} diff --git a/spring-cloud/spring-cloud-ribbon-retry/ribbon-weather-service/src/main/resources/application.properties b/spring-cloud/spring-cloud-ribbon-retry/ribbon-weather-service/src/main/resources/application.properties new file mode 100644 index 0000000000..ea25e8f2da --- /dev/null +++ b/spring-cloud/spring-cloud-ribbon-retry/ribbon-weather-service/src/main/resources/application.properties @@ -0,0 +1,2 @@ +spring.application.name=weather-service +successful.call.divisor=3 From 265bfbfe103156818f8846f22eb5bb40c3597cfc Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Wed, 10 Jun 2020 19:14:45 +0530 Subject: [PATCH 125/140] JAVA-622: Moved code from core-java-lang to core-java-lang-oop-types --- .../src/main/java/com/baeldung/enums/values/Element1.java | 0 .../src/main/java/com/baeldung/enums/values/Element2.java | 0 .../src/main/java/com/baeldung/enums/values/Element3.java | 0 .../src/main/java/com/baeldung/enums/values/Element4.java | 0 .../src/main/java/com/baeldung/enums/values/Labeled.java | 0 .../test/java/com/baeldung/enums/iteration/DaysOfWeekEnum.java | 0 .../java/com/baeldung/enums/iteration/EnumIterationExamples.java | 0 .../src/test/java/com/baeldung/enums/values/Element1UnitTest.java | 0 .../src/test/java/com/baeldung/enums/values/Element2UnitTest.java | 0 .../src/test/java/com/baeldung/enums/values/Element3UnitTest.java | 0 .../src/test/java/com/baeldung/enums/values/Element4UnitTest.java | 0 11 files changed, 0 insertions(+), 0 deletions(-) rename core-java-modules/{core-java-lang => core-java-lang-oop-types}/src/main/java/com/baeldung/enums/values/Element1.java (100%) rename core-java-modules/{core-java-lang => core-java-lang-oop-types}/src/main/java/com/baeldung/enums/values/Element2.java (100%) rename core-java-modules/{core-java-lang => core-java-lang-oop-types}/src/main/java/com/baeldung/enums/values/Element3.java (100%) rename core-java-modules/{core-java-lang => core-java-lang-oop-types}/src/main/java/com/baeldung/enums/values/Element4.java (100%) rename core-java-modules/{core-java-lang => core-java-lang-oop-types}/src/main/java/com/baeldung/enums/values/Labeled.java (100%) rename core-java-modules/{core-java-lang => core-java-lang-oop-types}/src/test/java/com/baeldung/enums/iteration/DaysOfWeekEnum.java (100%) rename core-java-modules/{core-java-lang => core-java-lang-oop-types}/src/test/java/com/baeldung/enums/iteration/EnumIterationExamples.java (100%) rename core-java-modules/{core-java-lang => core-java-lang-oop-types}/src/test/java/com/baeldung/enums/values/Element1UnitTest.java (100%) rename core-java-modules/{core-java-lang => core-java-lang-oop-types}/src/test/java/com/baeldung/enums/values/Element2UnitTest.java (100%) rename core-java-modules/{core-java-lang => core-java-lang-oop-types}/src/test/java/com/baeldung/enums/values/Element3UnitTest.java (100%) rename core-java-modules/{core-java-lang => core-java-lang-oop-types}/src/test/java/com/baeldung/enums/values/Element4UnitTest.java (100%) diff --git a/core-java-modules/core-java-lang/src/main/java/com/baeldung/enums/values/Element1.java b/core-java-modules/core-java-lang-oop-types/src/main/java/com/baeldung/enums/values/Element1.java similarity index 100% rename from core-java-modules/core-java-lang/src/main/java/com/baeldung/enums/values/Element1.java rename to core-java-modules/core-java-lang-oop-types/src/main/java/com/baeldung/enums/values/Element1.java diff --git a/core-java-modules/core-java-lang/src/main/java/com/baeldung/enums/values/Element2.java b/core-java-modules/core-java-lang-oop-types/src/main/java/com/baeldung/enums/values/Element2.java similarity index 100% rename from core-java-modules/core-java-lang/src/main/java/com/baeldung/enums/values/Element2.java rename to core-java-modules/core-java-lang-oop-types/src/main/java/com/baeldung/enums/values/Element2.java diff --git a/core-java-modules/core-java-lang/src/main/java/com/baeldung/enums/values/Element3.java b/core-java-modules/core-java-lang-oop-types/src/main/java/com/baeldung/enums/values/Element3.java similarity index 100% rename from core-java-modules/core-java-lang/src/main/java/com/baeldung/enums/values/Element3.java rename to core-java-modules/core-java-lang-oop-types/src/main/java/com/baeldung/enums/values/Element3.java diff --git a/core-java-modules/core-java-lang/src/main/java/com/baeldung/enums/values/Element4.java b/core-java-modules/core-java-lang-oop-types/src/main/java/com/baeldung/enums/values/Element4.java similarity index 100% rename from core-java-modules/core-java-lang/src/main/java/com/baeldung/enums/values/Element4.java rename to core-java-modules/core-java-lang-oop-types/src/main/java/com/baeldung/enums/values/Element4.java diff --git a/core-java-modules/core-java-lang/src/main/java/com/baeldung/enums/values/Labeled.java b/core-java-modules/core-java-lang-oop-types/src/main/java/com/baeldung/enums/values/Labeled.java similarity index 100% rename from core-java-modules/core-java-lang/src/main/java/com/baeldung/enums/values/Labeled.java rename to core-java-modules/core-java-lang-oop-types/src/main/java/com/baeldung/enums/values/Labeled.java diff --git a/core-java-modules/core-java-lang/src/test/java/com/baeldung/enums/iteration/DaysOfWeekEnum.java b/core-java-modules/core-java-lang-oop-types/src/test/java/com/baeldung/enums/iteration/DaysOfWeekEnum.java similarity index 100% rename from core-java-modules/core-java-lang/src/test/java/com/baeldung/enums/iteration/DaysOfWeekEnum.java rename to core-java-modules/core-java-lang-oop-types/src/test/java/com/baeldung/enums/iteration/DaysOfWeekEnum.java diff --git a/core-java-modules/core-java-lang/src/test/java/com/baeldung/enums/iteration/EnumIterationExamples.java b/core-java-modules/core-java-lang-oop-types/src/test/java/com/baeldung/enums/iteration/EnumIterationExamples.java similarity index 100% rename from core-java-modules/core-java-lang/src/test/java/com/baeldung/enums/iteration/EnumIterationExamples.java rename to core-java-modules/core-java-lang-oop-types/src/test/java/com/baeldung/enums/iteration/EnumIterationExamples.java diff --git a/core-java-modules/core-java-lang/src/test/java/com/baeldung/enums/values/Element1UnitTest.java b/core-java-modules/core-java-lang-oop-types/src/test/java/com/baeldung/enums/values/Element1UnitTest.java similarity index 100% rename from core-java-modules/core-java-lang/src/test/java/com/baeldung/enums/values/Element1UnitTest.java rename to core-java-modules/core-java-lang-oop-types/src/test/java/com/baeldung/enums/values/Element1UnitTest.java diff --git a/core-java-modules/core-java-lang/src/test/java/com/baeldung/enums/values/Element2UnitTest.java b/core-java-modules/core-java-lang-oop-types/src/test/java/com/baeldung/enums/values/Element2UnitTest.java similarity index 100% rename from core-java-modules/core-java-lang/src/test/java/com/baeldung/enums/values/Element2UnitTest.java rename to core-java-modules/core-java-lang-oop-types/src/test/java/com/baeldung/enums/values/Element2UnitTest.java diff --git a/core-java-modules/core-java-lang/src/test/java/com/baeldung/enums/values/Element3UnitTest.java b/core-java-modules/core-java-lang-oop-types/src/test/java/com/baeldung/enums/values/Element3UnitTest.java similarity index 100% rename from core-java-modules/core-java-lang/src/test/java/com/baeldung/enums/values/Element3UnitTest.java rename to core-java-modules/core-java-lang-oop-types/src/test/java/com/baeldung/enums/values/Element3UnitTest.java diff --git a/core-java-modules/core-java-lang/src/test/java/com/baeldung/enums/values/Element4UnitTest.java b/core-java-modules/core-java-lang-oop-types/src/test/java/com/baeldung/enums/values/Element4UnitTest.java similarity index 100% rename from core-java-modules/core-java-lang/src/test/java/com/baeldung/enums/values/Element4UnitTest.java rename to core-java-modules/core-java-lang-oop-types/src/test/java/com/baeldung/enums/values/Element4UnitTest.java From da319363e8ca7b0ffe3a938eab9dfa0ee36c9c4b Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Wed, 10 Jun 2020 19:16:13 +0530 Subject: [PATCH 126/140] JAVA-622: Move from core-java-lang-syntax to core-java-lang-oop-types --- .../src/main/java/com/baeldung/enums/Pizza.java | 0 .../src/main/java/com/baeldung/enums/PizzaDeliveryStrategy.java | 0 .../java/com/baeldung/enums/PizzaDeliverySystemConfiguration.java | 0 .../src/test/java/com/baeldung/enums/PizzaUnitTest.java | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename core-java-modules/{core-java-lang-syntax => core-java-lang-oop-types}/src/main/java/com/baeldung/enums/Pizza.java (100%) rename core-java-modules/{core-java-lang-syntax => core-java-lang-oop-types}/src/main/java/com/baeldung/enums/PizzaDeliveryStrategy.java (100%) rename core-java-modules/{core-java-lang-syntax => core-java-lang-oop-types}/src/main/java/com/baeldung/enums/PizzaDeliverySystemConfiguration.java (100%) rename core-java-modules/{core-java-lang-syntax => core-java-lang-oop-types}/src/test/java/com/baeldung/enums/PizzaUnitTest.java (100%) diff --git a/core-java-modules/core-java-lang-syntax/src/main/java/com/baeldung/enums/Pizza.java b/core-java-modules/core-java-lang-oop-types/src/main/java/com/baeldung/enums/Pizza.java similarity index 100% rename from core-java-modules/core-java-lang-syntax/src/main/java/com/baeldung/enums/Pizza.java rename to core-java-modules/core-java-lang-oop-types/src/main/java/com/baeldung/enums/Pizza.java diff --git a/core-java-modules/core-java-lang-syntax/src/main/java/com/baeldung/enums/PizzaDeliveryStrategy.java b/core-java-modules/core-java-lang-oop-types/src/main/java/com/baeldung/enums/PizzaDeliveryStrategy.java similarity index 100% rename from core-java-modules/core-java-lang-syntax/src/main/java/com/baeldung/enums/PizzaDeliveryStrategy.java rename to core-java-modules/core-java-lang-oop-types/src/main/java/com/baeldung/enums/PizzaDeliveryStrategy.java diff --git a/core-java-modules/core-java-lang-syntax/src/main/java/com/baeldung/enums/PizzaDeliverySystemConfiguration.java b/core-java-modules/core-java-lang-oop-types/src/main/java/com/baeldung/enums/PizzaDeliverySystemConfiguration.java similarity index 100% rename from core-java-modules/core-java-lang-syntax/src/main/java/com/baeldung/enums/PizzaDeliverySystemConfiguration.java rename to core-java-modules/core-java-lang-oop-types/src/main/java/com/baeldung/enums/PizzaDeliverySystemConfiguration.java diff --git a/core-java-modules/core-java-lang-syntax/src/test/java/com/baeldung/enums/PizzaUnitTest.java b/core-java-modules/core-java-lang-oop-types/src/test/java/com/baeldung/enums/PizzaUnitTest.java similarity index 100% rename from core-java-modules/core-java-lang-syntax/src/test/java/com/baeldung/enums/PizzaUnitTest.java rename to core-java-modules/core-java-lang-oop-types/src/test/java/com/baeldung/enums/PizzaUnitTest.java From b90191c5bc68f8a01f425512be89c85cc99d984e Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Wed, 10 Jun 2020 19:17:01 +0530 Subject: [PATCH 127/140] JAVA-622: readme changes, moved all enum articles to core-java-lang-oop-types --- core-java-modules/core-java-lang-oop-types/README.md | 3 +++ core-java-modules/core-java-lang/README.md | 3 --- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/core-java-modules/core-java-lang-oop-types/README.md b/core-java-modules/core-java-lang-oop-types/README.md index 80344c70fa..449a0f59cc 100644 --- a/core-java-modules/core-java-lang-oop-types/README.md +++ b/core-java-modules/core-java-lang-oop-types/README.md @@ -7,3 +7,6 @@ This module contains articles about types in Java - [Guide to the this Java Keyword](https://www.baeldung.com/java-this) - [Nested Classes in Java](https://www.baeldung.com/java-nested-classes) - [Marker Interfaces in Java](https://www.baeldung.com/java-marker-interfaces) +- [Iterating Over Enum Values in Java](https://www.baeldung.com/java-enum-iteration) +- [Attaching Values to Java Enum](https://www.baeldung.com/java-enum-values) +- [A Guide to Java Enums](https://www.baeldung.com/a-guide-to-java-enums) diff --git a/core-java-modules/core-java-lang/README.md b/core-java-modules/core-java-lang/README.md index 9e98bb849b..9166b93b7f 100644 --- a/core-java-modules/core-java-lang/README.md +++ b/core-java-modules/core-java-lang/README.md @@ -4,7 +4,6 @@ This module contains articles about core features in the Java language ### Relevant Articles: - [Generate equals() and hashCode() with Eclipse](https://www.baeldung.com/java-eclipse-equals-and-hashcode) -- [Iterating Over Enum Values in Java](https://www.baeldung.com/java-enum-iteration) - [Comparator and Comparable in Java](https://www.baeldung.com/java-comparator-comparable) - [Recursion In Java](https://www.baeldung.com/java-recursion) - [A Guide to the finalize Method in Java](https://www.baeldung.com/java-finalize) @@ -12,8 +11,6 @@ This module contains articles about core features in the Java language - [Using Java Assertions](https://www.baeldung.com/java-assert) - [Synthetic Constructs in Java](https://www.baeldung.com/java-synthetic) - [Retrieving a Class Name in Java](https://www.baeldung.com/java-class-name) -- [Attaching Values to Java Enum](https://www.baeldung.com/java-enum-values) - [The Java continue and break Keywords](https://www.baeldung.com/java-continue-and-break) -- [A Guide to Java Enums](https://www.baeldung.com/a-guide-to-java-enums) - [Infinite Loops in Java](https://www.baeldung.com/infinite-loops-java) - [[More --> ]](/core-java-modules/core-java-lang-2) From 2b928b04ce9ee002e3a515129444e7b59442b96d Mon Sep 17 00:00:00 2001 From: Usman Mohyuddin Date: Wed, 10 Jun 2020 20:21:22 +0500 Subject: [PATCH 128/140] Dev determine groovy datatype (#9235) * add code files for "How to groovy data types" add code files for "How to groovy data types" * added Tests in example * Update pom.xml change tab into spaces * remove the package determine-datatype as per comments * Update pom.xml add dependency for tests * remvoe the unwanted junit5 dependency and refine the structure of code remvoe the unwanted junit5 dependency and refine the structure of code * add missing "()" * correct the package as per sugesstion --- .../baeldung/determinedatatype/Person.groovy | 14 +++++ .../determinedatatype/PersonTest.groovy | 56 +++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 core-groovy-2/src/main/groovy/com/baeldung/determinedatatype/Person.groovy create mode 100644 core-groovy-2/src/test/groovy/com/baeldung/determinedatatype/PersonTest.groovy diff --git a/core-groovy-2/src/main/groovy/com/baeldung/determinedatatype/Person.groovy b/core-groovy-2/src/main/groovy/com/baeldung/determinedatatype/Person.groovy new file mode 100644 index 0000000000..3ac88b7952 --- /dev/null +++ b/core-groovy-2/src/main/groovy/com/baeldung/determinedatatype/Person.groovy @@ -0,0 +1,14 @@ +package com.baeldung.determinedatatype + +class Person { + + private int ageAsInt + private Double ageAsDouble + private String ageAsString + + Person() {} + Person(int ageAsInt) { this.ageAsInt = ageAsInt} + Person(Double ageAsDouble) { this.ageAsDouble = ageAsDouble} + Person(String ageAsString) { this.ageAsString = ageAsString} +} +class Student extends Person {} diff --git a/core-groovy-2/src/test/groovy/com/baeldung/determinedatatype/PersonTest.groovy b/core-groovy-2/src/test/groovy/com/baeldung/determinedatatype/PersonTest.groovy new file mode 100644 index 0000000000..4c6589f207 --- /dev/null +++ b/core-groovy-2/src/test/groovy/com/baeldung/determinedatatype/PersonTest.groovy @@ -0,0 +1,56 @@ +package com.baeldung.determinedatatype + +import org.junit.Assert +import org.junit.Test +import com.baeldung.determinedatatype.Person + +public class PersonTest { + + @Test + public void givenWhenParameterTypeIsInteger_thenReturnTrue() { + Person personObj = new Person(10) + Assert.assertTrue(personObj.ageAsInt instanceof Integer) + } + + @Test + public void givenWhenParameterTypeIsDouble_thenReturnTrue() { + Person personObj = new Person(10.0) + Assert.assertTrue((personObj.ageAsDouble).getClass() == Double) + } + + @Test + public void givenWhenParameterTypeIsString_thenReturnTrue() { + Person personObj = new Person("10 years") + Assert.assertTrue(personObj.ageAsString.class == String) + } + + @Test + public void givenClassName_WhenParameterIsInteger_thenReturnTrue() { + Assert.assertTrue(Person.class.getDeclaredField('ageAsInt').type == int.class) + } + + @Test + public void givenWhenObjectIsInstanceOfType_thenReturnTrue() { + Person personObj = new Person() + Assert.assertTrue(personObj instanceof Person) + } + + @Test + public void givenWhenInstanceIsOfSubtype_thenReturnTrue() { + Student studentObj = new Student() + Assert.assertTrue(studentObj in Person) + } + + @Test + public void givenGroovyList_WhenFindClassName_thenReturnTrue() { + def ageList = ['ageAsString','ageAsDouble', 10] + Assert.assertTrue(ageList.class == ArrayList) + Assert.assertTrue(ageList.getClass() == ArrayList) + } + + @Test + public void givenGrooyMap_WhenFindClassName_thenReturnTrue() { + def ageMap = [ageAsString: '10 years', ageAsDouble: 10.0] + Assert.assertFalse(ageMap.class == LinkedHashMap) + } +} \ No newline at end of file From 5d9b41411d0682f3e5dff0f7667fdeebd3b76fbb Mon Sep 17 00:00:00 2001 From: Anshul BANSAL Date: Thu, 11 Jun 2020 07:34:34 +0300 Subject: [PATCH 129/140] bcel version updated --- core-java-modules/core-java-jvm/pom.xml | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/core-java-modules/core-java-jvm/pom.xml b/core-java-modules/core-java-jvm/pom.xml index a2c35c154c..5e731363ae 100644 --- a/core-java-modules/core-java-jvm/pom.xml +++ b/core-java-modules/core-java-jvm/pom.xml @@ -54,31 +54,28 @@ org.ow2.asm asm - 8.0.1 + ${asm.version} org.ow2.asm asm-util - 8.0.1 + ${asm.version} org.apache.bcel bcel - 6.4.1 - - - org.javassist - javassist - 3.27.0-GA - + ${bcel.version} + 3.6.1 - 3.21.0-GA + 3.27.0-GA 2.1.0.1 1.8.0 + 8.0.1 + 6.5.0 From 1bd8a0b90c58753bd290a000d2ac163f5f6cea4d Mon Sep 17 00:00:00 2001 From: Graham Cox Date: Thu, 11 Jun 2020 12:39:13 +0100 Subject: [PATCH 130/140] BAEL-4041: Simulate playing 2048 (#9439) * Set up the ability to play the game * Actually able to play the game --- .../baeldung/algorithms/play2048/Board.java | 208 ++++++++++++++++++ .../baeldung/algorithms/play2048/Cell.java | 26 +++ .../algorithms/play2048/Computer.java | 27 +++ .../baeldung/algorithms/play2048/Human.java | 126 +++++++++++ .../baeldung/algorithms/play2048/Move.java | 8 + .../algorithms/play2048/Play2048.java | 73 ++++++ 6 files changed, 468 insertions(+) create mode 100644 algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/play2048/Board.java create mode 100644 algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/play2048/Cell.java create mode 100644 algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/play2048/Computer.java create mode 100644 algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/play2048/Human.java create mode 100644 algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/play2048/Move.java create mode 100644 algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/play2048/Play2048.java diff --git a/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/play2048/Board.java b/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/play2048/Board.java new file mode 100644 index 0000000000..ddb5901682 --- /dev/null +++ b/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/play2048/Board.java @@ -0,0 +1,208 @@ +package com.baeldung.algorithms.play2048; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.LinkedList; +import java.util.List; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class Board { + private static final Logger LOG = LoggerFactory.getLogger(Board.class); + + private final int[][] board; + + private final int score; + + public Board(int size) { + assert(size > 0); + + this.board = new int[size][]; + this.score = 0; + + for (int x = 0; x < size; ++x) { + this.board[x] = new int[size]; + for (int y = 0; y < size; ++y) { + board[x][y] = 0; + } + } + } + + private Board(int[][] board, int score) { + this.score = score; + this.board = new int[board.length][]; + + for (int x = 0; x < board.length; ++x) { + this.board[x] = Arrays.copyOf(board[x], board[x].length); + } + } + + public int getSize() { + return board.length; + } + + public int getScore() { + return score; + } + + public int getCell(Cell cell) { + int x = cell.getX(); + int y = cell.getY(); + assert(x >= 0 && x < board.length); + assert(y >= 0 && y < board.length); + + return board[x][y]; + } + + public boolean isEmpty(Cell cell) { + return getCell(cell) == 0; + } + + public List emptyCells() { + List result = new ArrayList<>(); + for (int x = 0; x < board.length; ++x) { + for (int y = 0; y < board[x].length; ++y) { + Cell cell = new Cell(x, y); + if (isEmpty(cell)) { + result.add(cell); + } + } + } + return result; + } + + public Board placeTile(Cell cell, int number) { + if (!isEmpty(cell)) { + throw new IllegalArgumentException("That cell is not empty"); + } + + Board result = new Board(this.board, this.score); + result.board[cell.getX()][cell.getY()] = number; + return result; + } + + public Board move(Move move) { + // Clone the board + int[][] tiles = new int[this.board.length][]; + for (int x = 0; x < this.board.length; ++x) { + tiles[x] = Arrays.copyOf(this.board[x], this.board[x].length); + } + + LOG.debug("Before move: {}", Arrays.deepToString(tiles)); + // If we're doing an Left/Right move then transpose the board to make it a Up/Down move + if (move == Move.LEFT || move == Move.RIGHT) { + tiles = transpose(tiles); + LOG.debug("After transpose: {}", Arrays.deepToString(tiles)); + } + // If we're doing a Right/Down move then reverse the board. + // With the above we're now always doing an Up move + if (move == Move.DOWN || move == Move.RIGHT) { + tiles = reverse(tiles); + LOG.debug("After reverse: {}", Arrays.deepToString(tiles)); + } + LOG.debug("Ready to move: {}", Arrays.deepToString(tiles)); + + // Shift everything up + int[][] result = new int[tiles.length][]; + int newScore = 0; + for (int x = 0; x < tiles.length; ++x) { + LinkedList thisRow = new LinkedList<>(); + for (int y = 0; y < tiles[0].length; ++y) { + if (tiles[x][y] > 0) { + thisRow.add(tiles[x][y]); + } + } + + LOG.debug("Unmerged row: {}", thisRow); + LinkedList newRow = new LinkedList<>(); + while (thisRow.size() >= 2) { + int first = thisRow.pop(); + int second = thisRow.peek(); + LOG.debug("Looking at numbers {} and {}", first, second); + if (second == first) { + LOG.debug("Numbers match, combining"); + int newNumber = first * 2; + newRow.add(newNumber); + newScore += newNumber; + thisRow.pop(); + } else { + LOG.debug("Numbers don't match"); + newRow.add(first); + } + } + newRow.addAll(thisRow); + LOG.debug("Merged row: {}", newRow); + + result[x] = new int[tiles[0].length]; + for (int y = 0; y < tiles[0].length; ++y) { + if (newRow.isEmpty()) { + result[x][y] = 0; + } else { + result[x][y] = newRow.pop(); + } + } + } + LOG.debug("After moves: {}", Arrays.deepToString(result)); + + // Un-reverse the board + if (move == Move.DOWN || move == Move.RIGHT) { + result = reverse(result); + LOG.debug("After reverse: {}", Arrays.deepToString(result)); + } + // Un-transpose the board + if (move == Move.LEFT || move == Move.RIGHT) { + result = transpose(result); + LOG.debug("After transpose: {}", Arrays.deepToString(result)); + } + return new Board(result, this.score + newScore); + } + + private static int[][] transpose(int[][] input) { + int[][] result = new int[input.length][]; + + for (int x = 0; x < input.length; ++x) { + result[x] = new int[input[0].length]; + for (int y = 0; y < input[0].length; ++y) { + result[x][y] = input[y][x]; + } + } + + return result; + } + + private static int[][] reverse(int[][] input) { + int[][] result = new int[input.length][]; + + for (int x = 0; x < input.length; ++x) { + result[x] = new int[input[0].length]; + for (int y = 0; y < input[0].length; ++y) { + result[x][y] = input[x][input.length - y - 1]; + } + } + + return result; + } + + @Override + public String toString() { + return Arrays.deepToString(board); + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + Board board1 = (Board) o; + return Arrays.deepEquals(board, board1.board); + } + + @Override + public int hashCode() { + return Arrays.deepHashCode(board); + } +} diff --git a/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/play2048/Cell.java b/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/play2048/Cell.java new file mode 100644 index 0000000000..98ee23ac90 --- /dev/null +++ b/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/play2048/Cell.java @@ -0,0 +1,26 @@ +package com.baeldung.algorithms.play2048; + +import java.util.StringJoiner; + +public class Cell { + private int x; + private int y; + + public Cell(int x, int y) { + this.x = x; + this.y = y; + } + + public int getX() { + return x; + } + + public int getY() { + return y; + } + + @Override + public String toString() { + return new StringJoiner(", ", Cell.class.getSimpleName() + "[", "]").add("x=" + x).add("y=" + y).toString(); + } +} diff --git a/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/play2048/Computer.java b/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/play2048/Computer.java new file mode 100644 index 0000000000..5ef1d04368 --- /dev/null +++ b/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/play2048/Computer.java @@ -0,0 +1,27 @@ +package com.baeldung.algorithms.play2048; + +import java.security.SecureRandom; +import java.util.List; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class Computer { + private static final Logger LOG = LoggerFactory.getLogger(Computer.class); + + private final SecureRandom rng = new SecureRandom(); + + public Board makeMove(Board input) { + List emptyCells = input.emptyCells(); + LOG.info("Number of empty cells: {}", emptyCells.size()); + + double numberToPlace = rng.nextDouble(); + LOG.info("New number probability: {}", numberToPlace); + + int indexToPlace = rng.nextInt(emptyCells.size()); + Cell cellToPlace = emptyCells.get(indexToPlace); + LOG.info("Placing number into empty cell: {}", cellToPlace); + + return input.placeTile(cellToPlace, numberToPlace >= 0.9 ? 4 : 2); + } +} diff --git a/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/play2048/Human.java b/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/play2048/Human.java new file mode 100644 index 0000000000..d1b32f0309 --- /dev/null +++ b/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/play2048/Human.java @@ -0,0 +1,126 @@ +package com.baeldung.algorithms.play2048; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Comparator; +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import org.apache.commons.math3.util.Pair; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class Human { + private static final Logger LOG = LoggerFactory.getLogger(Human.class); + + public Board makeMove(Board input) { + // For each move in MOVE + // Generate board from move + // Generate Score for Board + // Return board with the best score + // + // Generate Score + // If Depth Limit + // Return Final Score + // Total Score = 0 + // For every empty square in new board + // Generate board with "2" in square + // Calculate Score + // Total Score += (Score * 0.9) + // Generate board with "4" in square + // Calculate Score + // Total Score += (Score * 0.1) + // + // Calculate Score + // For each move in MOVE + // Generate board from move + // Generate score for board + // Return the best generated score + + return Arrays.stream(Move.values()) + .parallel() + .map(input::move) + .filter(board -> !board.equals(input)) + .max(Comparator.comparingInt(board -> generateScore(board, 0))) + .orElse(input); + } + + private int generateScore(Board board, int depth) { + if (depth >= 3) { + int finalScore = calculateFinalScore(board); + LOG.debug("Final score for board {}: {}", board,finalScore); + return finalScore; + } + + return board.emptyCells().stream() + .parallel() + .flatMap(cell -> Stream.of(new Pair<>(cell, 2), new Pair<>(cell, 4))) + .mapToInt(move -> { + LOG.debug("Simulating move {} at depth {}", move, depth); + Board newBoard = board.placeTile(move.getFirst(), move.getSecond()); + int boardScore = calculateScore(newBoard, depth + 1); + int calculatedScore = (int) (boardScore * (move.getSecond() == 2 ? 0.9 : 0.1)); + LOG.debug("Calculated score for board {} and move {} at depth {}: {}", newBoard, move, depth, calculatedScore); + return calculatedScore; + }) + .sum(); + } + + private int calculateScore(Board board, int depth) { + return Arrays.stream(Move.values()) + .parallel() + .map(board::move) + .filter(moved -> !moved.equals(board)) + .mapToInt(newBoard -> generateScore(newBoard, depth)) + .max() + .orElse(0); + } + + private int calculateFinalScore(Board board) { + List> rowsToScore = new ArrayList<>(); + for (int i = 0; i < board.getSize(); ++i) { + List row = new ArrayList<>(); + List col = new ArrayList<>(); + + for (int j = 0; j < board.getSize(); ++j) { + row.add(board.getCell(new Cell(i, j))); + col.add(board.getCell(new Cell(j, i))); + } + + rowsToScore.add(row); + rowsToScore.add(col); + } + + return rowsToScore.stream() + .parallel() + .mapToInt(row -> { + List preMerged = row.stream() + .filter(value -> value != 0) + .collect(Collectors.toList()); + + int numMerges = 0; + int monotonicityLeft = 0; + int monotonicityRight = 0; + for (int i = 0; i < preMerged.size() - 1; ++i) { + Integer first = preMerged.get(i); + Integer second = preMerged.get(i + 1); + if (first.equals(second)) { + ++numMerges; + } else if (first > second) { + monotonicityLeft += first - second; + } else { + monotonicityRight += second - first; + } + } + + int score = 1000; + score += 250 * row.stream().filter(value -> value == 0).count(); + score += 750 * numMerges; + score -= 10 * row.stream().mapToInt(value -> value).sum(); + score -= 50 * Math.min(monotonicityLeft, monotonicityRight); + return score; + }) + .sum(); + } +} diff --git a/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/play2048/Move.java b/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/play2048/Move.java new file mode 100644 index 0000000000..8678cec833 --- /dev/null +++ b/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/play2048/Move.java @@ -0,0 +1,8 @@ +package com.baeldung.algorithms.play2048; + +public enum Move { + UP, + DOWN, + LEFT, + RIGHT +} diff --git a/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/play2048/Play2048.java b/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/play2048/Play2048.java new file mode 100644 index 0000000000..ec5b3dca40 --- /dev/null +++ b/algorithms-miscellaneous-2/src/main/java/com/baeldung/algorithms/play2048/Play2048.java @@ -0,0 +1,73 @@ +package com.baeldung.algorithms.play2048; + +public class Play2048 { + private static final int SIZE = 3; + private static final int INITIAL_NUMBERS = 2; + + public static void main(String[] args) { + // The board and players + Board board = new Board(SIZE); + Computer computer = new Computer(); + Human human = new Human(); + + // The computer has two moves first + System.out.println("Setup"); + System.out.println("====="); + for (int i = 0; i < INITIAL_NUMBERS; ++i) { + board = computer.makeMove(board); + } + + printBoard(board); + do { + board = human.makeMove(board); + System.out.println("Human move"); + System.out.println("=========="); + printBoard(board); + + board = computer.makeMove(board); + System.out.println("Computer move"); + System.out.println("============="); + printBoard(board); + } while (!board.emptyCells().isEmpty()); + + System.out.println("Final Score: " + board.getScore()); + + } + + private static void printBoard(Board board) { + StringBuilder topLines = new StringBuilder(); + StringBuilder midLines = new StringBuilder(); + for (int x = 0; x < board.getSize(); ++x) { + topLines.append("+--------"); + midLines.append("| "); + } + topLines.append("+"); + midLines.append("|"); + + + for (int y = 0; y < board.getSize(); ++y) { + System.out.println(topLines); + System.out.println(midLines); + for (int x = 0; x < board.getSize(); ++x) { + Cell cell = new Cell(x, y); + System.out.print("|"); + if (board.isEmpty(cell)) { + System.out.print(" "); + } else { + StringBuilder output = new StringBuilder(Integer.toString(board.getCell(cell))); + while (output.length() < 8) { + output.append(" "); + if (output.length() < 8) { + output.insert(0, " "); + } + } + System.out.print(output); + } + } + System.out.println("|"); + System.out.println(midLines); + } + System.out.println(topLines); + System.out.println("Score: " + board.getScore()); + } +} From d804f6b2944db819c5aa6b3d167e6a1080305330 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Thu, 11 Jun 2020 18:59:09 +0530 Subject: [PATCH 131/140] JAVA-938: Migrate spring-cloud-data-flow to parent-boot-2 --- spring-cloud-data-flow/apache-spark-job/pom.xml | 10 ---------- .../com/baeldung/spring/cloud/PiApproximation.java | 2 +- spring-cloud-data-flow/batch-job/pom.xml | 10 ++++------ spring-cloud-data-flow/pom.xml | 5 +++-- .../customer-mongodb-sink/pom.xml | 5 ++--- .../customer-transform/pom.xml | 5 ++--- 6 files changed, 12 insertions(+), 25 deletions(-) diff --git a/spring-cloud-data-flow/apache-spark-job/pom.xml b/spring-cloud-data-flow/apache-spark-job/pom.xml index 65a57671ea..a4816a30ba 100644 --- a/spring-cloud-data-flow/apache-spark-job/pom.xml +++ b/spring-cloud-data-flow/apache-spark-job/pom.xml @@ -22,16 +22,6 @@ org.apache.spark spark-core_${scala.version} ${spark.version} - - - log4j - log4j - - - org.slf4j - slf4j-log4j12 - - diff --git a/spring-cloud-data-flow/apache-spark-job/src/main/java/com/baeldung/spring/cloud/PiApproximation.java b/spring-cloud-data-flow/apache-spark-job/src/main/java/com/baeldung/spring/cloud/PiApproximation.java index dfead21728..3f7c3be678 100644 --- a/spring-cloud-data-flow/apache-spark-job/src/main/java/com/baeldung/spring/cloud/PiApproximation.java +++ b/spring-cloud-data-flow/apache-spark-job/src/main/java/com/baeldung/spring/cloud/PiApproximation.java @@ -13,7 +13,7 @@ import java.util.stream.IntStream; public class PiApproximation { public static void main(String[] args) { - SparkConf conf = new SparkConf().setAppName("BaeldungPIApproximation"); + SparkConf conf = new SparkConf().setAppName("BaeldungPIApproximation").setMaster("local[2]"); JavaSparkContext context = new JavaSparkContext(conf); int slices = args.length >= 1 ? Integer.valueOf(args[0]) : 2; int n = (100000L * slices) > Integer.MAX_VALUE ? Integer.MAX_VALUE : 100000 * slices; diff --git a/spring-cloud-data-flow/batch-job/pom.xml b/spring-cloud-data-flow/batch-job/pom.xml index e11df0df8e..6b02b000e1 100644 --- a/spring-cloud-data-flow/batch-job/pom.xml +++ b/spring-cloud-data-flow/batch-job/pom.xml @@ -11,9 +11,8 @@ com.baeldung - parent-boot-1 + spring-cloud-data-flow 0.0.1-SNAPSHOT - ../../parent-boot-1 @@ -21,7 +20,7 @@ org.springframework.cloud spring-cloud-dependencies - Brixton.SR5 + Hoxton.SR4 pom import @@ -31,8 +30,7 @@ org.springframework.cloud - spring-cloud-task-starter - ${spring-cloud-task-starter.version} + spring-cloud-starter-task @@ -48,7 +46,7 @@ - 1.0.3.RELEASE + 2.2.3.RELEASE diff --git a/spring-cloud-data-flow/pom.xml b/spring-cloud-data-flow/pom.xml index e2a0664f30..5b516146ae 100644 --- a/spring-cloud-data-flow/pom.xml +++ b/spring-cloud-data-flow/pom.xml @@ -9,8 +9,9 @@ com.baeldung - parent-modules - 1.0.0-SNAPSHOT + parent-boot-2 + 0.0.1-SNAPSHOT + ../parent-boot-2 diff --git a/spring-cloud-data-flow/spring-cloud-data-flow-etl/customer-mongodb-sink/pom.xml b/spring-cloud-data-flow/spring-cloud-data-flow-etl/customer-mongodb-sink/pom.xml index 9fd378b171..43772505a4 100644 --- a/spring-cloud-data-flow/spring-cloud-data-flow-etl/customer-mongodb-sink/pom.xml +++ b/spring-cloud-data-flow/spring-cloud-data-flow-etl/customer-mongodb-sink/pom.xml @@ -9,9 +9,8 @@ com.baeldung - parent-boot-2 + spring-cloud-data-flow-etl 0.0.1-SNAPSHOT - ../../../parent-boot-2 @@ -63,7 +62,7 @@ UTF-8 UTF-8 - Greenwich.RELEASE + Hoxton.SR4 diff --git a/spring-cloud-data-flow/spring-cloud-data-flow-etl/customer-transform/pom.xml b/spring-cloud-data-flow/spring-cloud-data-flow-etl/customer-transform/pom.xml index fdec22f3b3..f0d18a1c4f 100644 --- a/spring-cloud-data-flow/spring-cloud-data-flow-etl/customer-transform/pom.xml +++ b/spring-cloud-data-flow/spring-cloud-data-flow-etl/customer-transform/pom.xml @@ -9,9 +9,8 @@ com.baeldung - parent-boot-2 + spring-cloud-data-flow-etl 0.0.1-SNAPSHOT - ../../../parent-boot-2 @@ -55,7 +54,7 @@ UTF-8 UTF-8 - Greenwich.RELEASE + Hoxton.SR4 From adb04983e7b505b2b827f4cd50a1ebd2da566a35 Mon Sep 17 00:00:00 2001 From: Sampada <46674082+sampada07@users.noreply.github.com> Date: Thu, 11 Jun 2020 21:27:04 +0530 Subject: [PATCH 132/140] BAEL-4061: Removed request mirroring (#9448) * BAEL-4061: Removed request mirroring * BAEL-4061: Code refactoring * BAEL-4061: more refactoring * BAEL-4061: renamed methods --- .../http/server/CustomHttpServerHandler.java | 29 ++--------- ...ResponseBuilder.java => RequestUtils.java} | 48 +++---------------- .../http/server/HttpServerLiveTest.java | 5 +- 3 files changed, 13 insertions(+), 69 deletions(-) rename netty/src/main/java/com/baeldung/http/server/{ResponseBuilder.java => RequestUtils.java} (61%) diff --git a/netty/src/main/java/com/baeldung/http/server/CustomHttpServerHandler.java b/netty/src/main/java/com/baeldung/http/server/CustomHttpServerHandler.java index 038f559329..abefbed0d9 100644 --- a/netty/src/main/java/com/baeldung/http/server/CustomHttpServerHandler.java +++ b/netty/src/main/java/com/baeldung/http/server/CustomHttpServerHandler.java @@ -5,8 +5,6 @@ import static io.netty.handler.codec.http.HttpResponseStatus.CONTINUE; import static io.netty.handler.codec.http.HttpResponseStatus.OK; import static io.netty.handler.codec.http.HttpVersion.HTTP_1_1; -import java.util.Set; - import io.netty.buffer.Unpooled; import io.netty.channel.ChannelFutureListener; import io.netty.channel.ChannelHandlerContext; @@ -20,9 +18,6 @@ import io.netty.handler.codec.http.HttpObject; import io.netty.handler.codec.http.HttpRequest; import io.netty.handler.codec.http.HttpUtil; import io.netty.handler.codec.http.LastHttpContent; -import io.netty.handler.codec.http.cookie.Cookie; -import io.netty.handler.codec.http.cookie.ServerCookieDecoder; -import io.netty.handler.codec.http.cookie.ServerCookieEncoder; import io.netty.util.CharsetUtil; public class CustomHttpServerHandler extends SimpleChannelInboundHandler { @@ -45,22 +40,20 @@ public class CustomHttpServerHandler extends SimpleChannelInboundHandler } responseData.setLength(0); - responseData.append(ResponseBuilder.addRequestAttributes(request)); - responseData.append(ResponseBuilder.addHeaders(request)); - responseData.append(ResponseBuilder.addParams(request)); + responseData.append(RequestUtils.formatParams(request)); } - responseData.append(ResponseBuilder.addDecoderResult(request)); + responseData.append(RequestUtils.evaluateDecoderResult(request)); if (msg instanceof HttpContent) { HttpContent httpContent = (HttpContent) msg; - responseData.append(ResponseBuilder.addBody(httpContent)); - responseData.append(ResponseBuilder.addDecoderResult(request)); + responseData.append(RequestUtils.formatBody(httpContent)); + responseData.append(RequestUtils.evaluateDecoderResult(request)); if (msg instanceof LastHttpContent) { LastHttpContent trailer = (LastHttpContent) msg; - responseData.append(ResponseBuilder.addLastResponse(request, trailer)); + responseData.append(RequestUtils.prepareLastResponse(request, trailer)); writeResponse(ctx, trailer, responseData); } } @@ -88,18 +81,6 @@ public class CustomHttpServerHandler extends SimpleChannelInboundHandler .set(HttpHeaderNames.CONNECTION, HttpHeaderValues.KEEP_ALIVE); } - String cookieString = request.headers() - .get(HttpHeaderNames.COOKIE); - if (cookieString != null) { - Set cookies = ServerCookieDecoder.STRICT.decode(cookieString); - if (!cookies.isEmpty()) { - for (Cookie cookie : cookies) { - httpResponse.headers() - .add(HttpHeaderNames.SET_COOKIE, ServerCookieEncoder.STRICT.encode(cookie)); - } - } - } - ctx.write(httpResponse); if (!keepAlive) { diff --git a/netty/src/main/java/com/baeldung/http/server/ResponseBuilder.java b/netty/src/main/java/com/baeldung/http/server/RequestUtils.java similarity index 61% rename from netty/src/main/java/com/baeldung/http/server/ResponseBuilder.java rename to netty/src/main/java/com/baeldung/http/server/RequestUtils.java index 6d4e7845da..92ec2242f3 100644 --- a/netty/src/main/java/com/baeldung/http/server/ResponseBuilder.java +++ b/netty/src/main/java/com/baeldung/http/server/RequestUtils.java @@ -7,32 +7,15 @@ import java.util.Map.Entry; import io.netty.buffer.ByteBuf; import io.netty.handler.codec.DecoderResult; import io.netty.handler.codec.http.HttpContent; -import io.netty.handler.codec.http.HttpHeaderNames; -import io.netty.handler.codec.http.HttpHeaders; import io.netty.handler.codec.http.HttpObject; import io.netty.handler.codec.http.HttpRequest; import io.netty.handler.codec.http.LastHttpContent; import io.netty.handler.codec.http.QueryStringDecoder; import io.netty.util.CharsetUtil; -class ResponseBuilder { +class RequestUtils { - static StringBuilder addRequestAttributes(HttpRequest request) { - StringBuilder responseData = new StringBuilder(); - responseData.append("Version: ") - .append(request.protocolVersion()) - .append("\r\n"); - responseData.append("Host: ") - .append(request.headers() - .get(HttpHeaderNames.HOST, "unknown")) - .append("\r\n"); - responseData.append("URI: ") - .append(request.uri()) - .append("\r\n\r\n"); - return responseData; - } - - static StringBuilder addParams(HttpRequest request) { + static StringBuilder formatParams(HttpRequest request) { StringBuilder responseData = new StringBuilder(); QueryStringDecoder queryStringDecoder = new QueryStringDecoder(request.uri()); Map> params = queryStringDecoder.parameters(); @@ -42,9 +25,9 @@ class ResponseBuilder { List vals = p.getValue(); for (String val : vals) { responseData.append("Parameter: ") - .append(key) + .append(key.toUpperCase()) .append(" = ") - .append(val) + .append(val.toUpperCase()) .append("\r\n"); } } @@ -53,24 +36,7 @@ class ResponseBuilder { return responseData; } - static StringBuilder addHeaders(HttpRequest request) { - StringBuilder responseData = new StringBuilder(); - HttpHeaders headers = request.headers(); - if (!headers.isEmpty()) { - for (Map.Entry header : headers) { - CharSequence key = header.getKey(); - CharSequence value = header.getValue(); - responseData.append(key) - .append(" = ") - .append(value) - .append("\r\n"); - } - responseData.append("\r\n"); - } - return responseData; - } - - static StringBuilder addBody(HttpContent httpContent) { + static StringBuilder formatBody(HttpContent httpContent) { StringBuilder responseData = new StringBuilder(); ByteBuf content = httpContent.content(); if (content.isReadable()) { @@ -81,7 +47,7 @@ class ResponseBuilder { return responseData; } - static StringBuilder addDecoderResult(HttpObject o) { + static StringBuilder evaluateDecoderResult(HttpObject o) { StringBuilder responseData = new StringBuilder(); DecoderResult result = o.decoderResult(); @@ -94,7 +60,7 @@ class ResponseBuilder { return responseData; } - static StringBuilder addLastResponse(HttpRequest request, LastHttpContent trailer) { + static StringBuilder prepareLastResponse(HttpRequest request, LastHttpContent trailer) { StringBuilder responseData = new StringBuilder(); responseData.append("Good Bye!\r\n"); diff --git a/netty/src/test/java/com/baeldung/http/server/HttpServerLiveTest.java b/netty/src/test/java/com/baeldung/http/server/HttpServerLiveTest.java index 7a0f884724..77f1288838 100644 --- a/netty/src/test/java/com/baeldung/http/server/HttpServerLiveTest.java +++ b/netty/src/test/java/com/baeldung/http/server/HttpServerLiveTest.java @@ -89,7 +89,7 @@ public class HttpServerLiveTest { } @Test - public void whenGetSent_thenCookieReceivedInResponse() throws Exception { + public void whenGetSent_thenResponseOK() throws Exception { DefaultFullHttpRequest request = createRequest(null); channel.writeAndFlush(request); @@ -98,9 +98,6 @@ public class HttpServerLiveTest { assertEquals(200, response.getStatus()); assertEquals("HTTP/1.1", response.getVersion()); - Map headers = response.getHeaders(); - String cookies = headers.get("set-cookie"); - assertTrue(cookies.contains("my-cookie")); } @After From c529170a43ef9074f63d1657e7807a1030377d35 Mon Sep 17 00:00:00 2001 From: Joe Zhang Date: Fri, 12 Jun 2020 22:18:54 +0800 Subject: [PATCH 133/140] Leasy Zhang/shiwangzhihe@gmail.com (#9445) * add primary key demo * add primary key * use eclipse link * update unit test * refact package name * format code with space Co-authored-by: joe zhang --- .../baeldung/jpa/generateidvalue/Admin.java | 36 +++++++++ .../baeldung/jpa/generateidvalue/Article.java | 39 +++++++++ .../jpa/generateidvalue/IdGenerator.java | 48 +++++++++++ .../baeldung/jpa/generateidvalue/Task.java | 39 +++++++++ .../baeldung/jpa/generateidvalue/User.java | 37 +++++++++ .../main/resources/META-INF/persistence.xml | 25 ++++++ .../main/resources/primary_key_generator.sql | 4 + .../generateidvalue/PrimaryKeyUnitTest.java | 81 +++++++++++++++++++ 8 files changed, 309 insertions(+) create mode 100644 persistence-modules/java-jpa-2/src/main/java/com/baeldung/jpa/generateidvalue/Admin.java create mode 100644 persistence-modules/java-jpa-2/src/main/java/com/baeldung/jpa/generateidvalue/Article.java create mode 100644 persistence-modules/java-jpa-2/src/main/java/com/baeldung/jpa/generateidvalue/IdGenerator.java create mode 100644 persistence-modules/java-jpa-2/src/main/java/com/baeldung/jpa/generateidvalue/Task.java create mode 100644 persistence-modules/java-jpa-2/src/main/java/com/baeldung/jpa/generateidvalue/User.java create mode 100644 persistence-modules/java-jpa-2/src/main/resources/primary_key_generator.sql create mode 100644 persistence-modules/java-jpa-2/src/test/java/com/baeldung/jpa/generateidvalue/PrimaryKeyUnitTest.java diff --git a/persistence-modules/java-jpa-2/src/main/java/com/baeldung/jpa/generateidvalue/Admin.java b/persistence-modules/java-jpa-2/src/main/java/com/baeldung/jpa/generateidvalue/Admin.java new file mode 100644 index 0000000000..1c59b33ab8 --- /dev/null +++ b/persistence-modules/java-jpa-2/src/main/java/com/baeldung/jpa/generateidvalue/Admin.java @@ -0,0 +1,36 @@ +package com.baeldung.jpa.generateidvalue; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.Table; + +@Entity +@Table(name = "app_admin") +public class Admin { + + @Id + @GeneratedValue + private Long id; + + @Column(name = "admin_name") + private String name; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + +} \ No newline at end of file diff --git a/persistence-modules/java-jpa-2/src/main/java/com/baeldung/jpa/generateidvalue/Article.java b/persistence-modules/java-jpa-2/src/main/java/com/baeldung/jpa/generateidvalue/Article.java new file mode 100644 index 0000000000..06465de179 --- /dev/null +++ b/persistence-modules/java-jpa-2/src/main/java/com/baeldung/jpa/generateidvalue/Article.java @@ -0,0 +1,39 @@ +package com.baeldung.jpa.generateidvalue; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.SequenceGenerator; +import javax.persistence.Table; + +@Entity +@Table(name = "article") +public class Article { + + @Id + @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "article_gen") + @SequenceGenerator(name = "article_gen", sequenceName = "article_seq") + private Long id; + + @Column(name = "article_name") + private String name; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + +} \ No newline at end of file diff --git a/persistence-modules/java-jpa-2/src/main/java/com/baeldung/jpa/generateidvalue/IdGenerator.java b/persistence-modules/java-jpa-2/src/main/java/com/baeldung/jpa/generateidvalue/IdGenerator.java new file mode 100644 index 0000000000..0fac86747f --- /dev/null +++ b/persistence-modules/java-jpa-2/src/main/java/com/baeldung/jpa/generateidvalue/IdGenerator.java @@ -0,0 +1,48 @@ +package com.baeldung.jpa.generateidvalue; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; + +@Table(name = "id_gen") +@Entity +public class IdGenerator { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @Column(name = "gen_name") + private String gen_name; + + @Column(name = "gen_value") + private Long gen_value; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getGen_name() { + return gen_name; + } + + public void setGen_name(String gen_name) { + this.gen_name = gen_name; + } + + public Long getGen_value() { + return gen_value; + } + + public void setGen_value(Long gen_value) { + this.gen_value = gen_value; + } + +} \ No newline at end of file diff --git a/persistence-modules/java-jpa-2/src/main/java/com/baeldung/jpa/generateidvalue/Task.java b/persistence-modules/java-jpa-2/src/main/java/com/baeldung/jpa/generateidvalue/Task.java new file mode 100644 index 0000000000..a51ec53418 --- /dev/null +++ b/persistence-modules/java-jpa-2/src/main/java/com/baeldung/jpa/generateidvalue/Task.java @@ -0,0 +1,39 @@ +package com.baeldung.jpa.generateidvalue; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; +import javax.persistence.TableGenerator; + +@Entity +@Table(name = "task") +public class Task { + + @Id + @TableGenerator(name = "id_generator", table = "id_gen", pkColumnName = "gen_name", valueColumnName = "gen_value", pkColumnValue = "task_gen", initialValue = 10000, allocationSize = 10) + @GeneratedValue(strategy = GenerationType.TABLE, generator = "id_generator") + private Long id; + + @Column(name = "name") + private String name; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + +} \ No newline at end of file diff --git a/persistence-modules/java-jpa-2/src/main/java/com/baeldung/jpa/generateidvalue/User.java b/persistence-modules/java-jpa-2/src/main/java/com/baeldung/jpa/generateidvalue/User.java new file mode 100644 index 0000000000..88fefe7ba6 --- /dev/null +++ b/persistence-modules/java-jpa-2/src/main/java/com/baeldung/jpa/generateidvalue/User.java @@ -0,0 +1,37 @@ +package com.baeldung.jpa.generateidvalue; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; + +@Entity +@Table(name = "app_user") +public class User { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @Column(name = "user_name") + private String name; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + +} \ No newline at end of file diff --git a/persistence-modules/java-jpa-2/src/main/resources/META-INF/persistence.xml b/persistence-modules/java-jpa-2/src/main/resources/META-INF/persistence.xml index eec7f7cf6e..3bc81910d9 100644 --- a/persistence-modules/java-jpa-2/src/main/resources/META-INF/persistence.xml +++ b/persistence-modules/java-jpa-2/src/main/resources/META-INF/persistence.xml @@ -184,4 +184,29 @@ value="false" /> + + + org.eclipse.persistence.jpa.PersistenceProvider + com.baeldung.jpa.generateidvalue.Admin + com.baeldung.jpa.generateidvalue.Article + com.baeldung.jpa.generateidvalue.IdGenerator + com.baeldung.jpa.generateidvalue.Task + com.baeldung.jpa.generateidvalue.User + true + + + + + + + + + + + + + diff --git a/persistence-modules/java-jpa-2/src/main/resources/primary_key_generator.sql b/persistence-modules/java-jpa-2/src/main/resources/primary_key_generator.sql new file mode 100644 index 0000000000..9acd1bc11b --- /dev/null +++ b/persistence-modules/java-jpa-2/src/main/resources/primary_key_generator.sql @@ -0,0 +1,4 @@ +CREATE SEQUENCE article_seq MINVALUE 1 START WITH 50 INCREMENT BY 50; + +INSERT INTO id_gen (gen_name, gen_val) VALUES ('id_generator', 0); +INSERT INTO id_gen (gen_name, gen_val) VALUES ('task_gen', 10000); \ No newline at end of file diff --git a/persistence-modules/java-jpa-2/src/test/java/com/baeldung/jpa/generateidvalue/PrimaryKeyUnitTest.java b/persistence-modules/java-jpa-2/src/test/java/com/baeldung/jpa/generateidvalue/PrimaryKeyUnitTest.java new file mode 100644 index 0000000000..eead56dbff --- /dev/null +++ b/persistence-modules/java-jpa-2/src/test/java/com/baeldung/jpa/generateidvalue/PrimaryKeyUnitTest.java @@ -0,0 +1,81 @@ +package com.baeldung.jpa.generateidvalue; + +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; +import javax.persistence.Persistence; + +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * PrimaryKeyGeneratorTest class + * + * @author shiwangzhihe@gmail.com + */ +public class PrimaryKeyUnitTest { + private static EntityManager entityManager; + + @BeforeClass + public static void setup() { + EntityManagerFactory factory = Persistence.createEntityManagerFactory("jpa-h2-primarykey"); + entityManager = factory.createEntityManager(); + } + + @Test + public void givenIdentityStrategy_whenCommitTransction_thenReturnPrimaryKey() { + User user = new User(); + user.setName("TestName"); + + entityManager.getTransaction() + .begin(); + entityManager.persist(user); + Assert.assertNull(user.getId()); + entityManager.getTransaction() + .commit(); + + Long expectPrimaryKey = 1L; + Assert.assertEquals(expectPrimaryKey, user.getId()); + } + + @Test + public void givenTableStrategy_whenPersist_thenReturnPrimaryKey() { + Task task = new Task(); + task.setName("Test Task"); + + entityManager.getTransaction() + .begin(); + entityManager.persist(task); + Long expectPrimaryKey = 10000L; + Assert.assertEquals(expectPrimaryKey, task.getId()); + + entityManager.getTransaction() + .commit(); + } + + @Test + public void givenSequenceStrategy_whenPersist_thenReturnPrimaryKey() { + Article article = new Article(); + article.setName("Test Name"); + + entityManager.getTransaction() + .begin(); + entityManager.persist(article); + Long expectPrimaryKey = 51L; + Assert.assertEquals(expectPrimaryKey, article.getId()); + + entityManager.getTransaction() + .commit(); + } + + @Test + public void givenAutoStrategy_whenPersist_thenReturnPrimaryKey() { + Admin admin = new Admin(); + admin.setName("Test Name"); + + entityManager.persist(admin); + + Long expectPrimaryKey = 1L; + Assert.assertEquals(expectPrimaryKey, admin.getId()); + } +} \ No newline at end of file From 3a99a52d11eda6d4537c381f7a48879fa44dd79a Mon Sep 17 00:00:00 2001 From: Mark Thomas Date: Fri, 12 Jun 2020 09:37:48 -0500 Subject: [PATCH 134/140] Fix default SpEL expression (#9489) --- .../java/com/baeldung/beanpostprocessor/GlobalEventBus.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-core-4/src/main/java/com/baeldung/beanpostprocessor/GlobalEventBus.java b/spring-core-4/src/main/java/com/baeldung/beanpostprocessor/GlobalEventBus.java index 8b3c528c4d..fff9eb8a0f 100644 --- a/spring-core-4/src/main/java/com/baeldung/beanpostprocessor/GlobalEventBus.java +++ b/spring-core-4/src/main/java/com/baeldung/beanpostprocessor/GlobalEventBus.java @@ -8,7 +8,7 @@ import java.util.concurrent.Executors; @SuppressWarnings("ALL") public final class GlobalEventBus { - public static final String GLOBAL_EVENT_BUS_EXPRESSION = "T(com.baeldung.postprocessor.GlobalEventBus).getEventBus()"; + public static final String GLOBAL_EVENT_BUS_EXPRESSION = "T(com.baeldung.beanpostprocessor.GlobalEventBus).getEventBus()"; private static final String IDENTIFIER = "global-event-bus"; From edd28c1b43c07adb7a84029aa5a1c24ac26d50b4 Mon Sep 17 00:00:00 2001 From: Carlos Cavero Date: Fri, 12 Jun 2020 19:40:14 +0200 Subject: [PATCH 135/140] BAEL-3756-Spring-YAML-vs-Properties (#9482) * Remove Dockerfile because it is not longer needed in the article * Add different YAML configurations and process into POJO * Remove .dockerignore file because it is not longer needed in the article * Add default Spring profile to test and force also in the Unit tests --- .../spring-boot-properties/.dockerignore | 13 -- .../spring-boot-properties/Dockerfile | 10 -- .../java/com/baeldung/yaml/MyApplication.java | 20 ++++ .../java/com/baeldung/yaml/YAMLConfig.java | 112 ++++++++++++++++++ .../src/main/resources/application.yml | 34 ++++-- .../baeldung/yaml/YAMLIntegrationTest.java | 2 + 6 files changed, 161 insertions(+), 30 deletions(-) delete mode 100644 spring-boot-modules/spring-boot-properties/.dockerignore delete mode 100644 spring-boot-modules/spring-boot-properties/Dockerfile diff --git a/spring-boot-modules/spring-boot-properties/.dockerignore b/spring-boot-modules/spring-boot-properties/.dockerignore deleted file mode 100644 index df36044e46..0000000000 --- a/spring-boot-modules/spring-boot-properties/.dockerignore +++ /dev/null @@ -1,13 +0,0 @@ -# Logs -logs -*.log - -# Git -.git -.cache - -# Classes -**/*.class - -# Ignore md files -*.md diff --git a/spring-boot-modules/spring-boot-properties/Dockerfile b/spring-boot-modules/spring-boot-properties/Dockerfile deleted file mode 100644 index d6bd2a95ae..0000000000 --- a/spring-boot-modules/spring-boot-properties/Dockerfile +++ /dev/null @@ -1,10 +0,0 @@ -FROM maven:3.6.0-jdk-11 -WORKDIR /code/spring-boot-modules/spring-boot-properties/ -COPY ./spring-boot-modules/spring-boot-properties/pom.xml . -COPY ./spring-boot-modules/spring-boot-properties/src ./src -COPY ./parent-boot-2/pom.xml /code/parent-boot-2/pom.xml -COPY ./pom.xml /code/pom.xml -COPY ./custom-pmd-0.0.1.jar /code/custom-pmd-0.0.1.jar -COPY ./baeldung-pmd-rules.xml /code/baeldung-pmd-rules.xml -RUN mvn dependency:resolve -CMD ["mvn", "spring-boot:run"] \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/yaml/MyApplication.java b/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/yaml/MyApplication.java index d42b731213..f3cfff57b7 100644 --- a/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/yaml/MyApplication.java +++ b/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/yaml/MyApplication.java @@ -11,6 +11,9 @@ import org.springframework.boot.CommandLineRunner; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import com.baeldung.yaml.YAMLConfig.Idm; +import com.baeldung.yaml.YAMLConfig.Service; + @SpringBootApplication public class MyApplication implements CommandLineRunner { @@ -26,6 +29,23 @@ public class MyApplication implements CommandLineRunner { System.out.println("using environment:" + myConfig.getEnvironment()); System.out.println("name:" + myConfig.getName()); System.out.println("servers:" + myConfig.getServers()); + + if ("testing".equalsIgnoreCase(myConfig.getEnvironment())) { + System.out.println("external:" + myConfig.getExternal()); + System.out.println("map:" + myConfig.getMap()); + + Idm idm = myConfig.getComponent().getIdm(); + Service service = myConfig.getComponent().getService(); + System.out.println("Idm:"); + System.out.println(" Url: " + idm.getUrl()); + System.out.println(" User: " + idm.getUser()); + System.out.println(" Password: " + idm.getPassword()); + System.out.println(" Description: " + idm.getDescription()); + System.out.println("Service:"); + System.out.println(" Url: " + service.getUrl()); + System.out.println(" Token: " + service.getToken()); + System.out.println(" Description: " + service.getDescription()); + } } } diff --git a/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/yaml/YAMLConfig.java b/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/yaml/YAMLConfig.java index ad633c4b56..83c083734c 100644 --- a/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/yaml/YAMLConfig.java +++ b/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/yaml/YAMLConfig.java @@ -1,7 +1,10 @@ package com.baeldung.yaml; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; + import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Configuration; @@ -13,6 +16,9 @@ public class YAMLConfig { private String name; private String environment; private List servers = new ArrayList(); + private List external = new ArrayList(); + private Map map = new HashMap(); + private Component component = new Component(); public List getServers() { return servers; @@ -37,5 +43,111 @@ public class YAMLConfig { public void setEnvironment(String environment) { this.environment = environment; } + + public Component getComponent() { + return component; + } + + public void setComponent(Component component) { + this.component = component; + } + + public Map getMap() { + return map; + } + + public void setMap(Map map) { + this.map = map; + } + + public List getExternal() { + return external; + } + + public void setExternal(List external) { + this.external = external; + } + + public class Component { + private Idm idm = new Idm(); + private Service service = new Service(); + + public Idm getIdm() { + return idm; + } + public void setIdm(Idm idm) { + this.idm = idm; + } + + public Service getService() { + return service; + } + public void setService(Service service) { + this.service = service; + } + + } + + public class Idm { + private String url; + private String user; + private String password; + private String description; + + public String getUrl() { + return url; + } + public void setUrl(String url) { + this.url = url; + } + + public String getUser() { + return user; + } + public void setUser(String user) { + this.user = user; + } + + public String getPassword() { + return password; + } + public void setPassword(String password) { + this.password = password; + } + + public String getDescription() { + return description; + } + public void setDescription(String description) { + this.description = description; + } + } + + public class Service { + private String url; + private String token; + private String description; + + public String getUrl() { + return url; + } + public void setUrl(String url) { + this.url = url; + } + + public String getToken() { + return token; + } + public void setToken(String token) { + this.token = token; + } + + public String getDescription() { + return description; + } + public void setDescription(String description) { + this.description = description; + } + } } diff --git a/spring-boot-modules/spring-boot-properties/src/main/resources/application.yml b/spring-boot-modules/spring-boot-properties/src/main/resources/application.yml index 4914ff15f7..30e64f9d35 100644 --- a/spring-boot-modules/spring-boot-properties/src/main/resources/application.yml +++ b/spring-boot-modules/spring-boot-properties/src/main/resources/application.yml @@ -6,22 +6,42 @@ spring: --- spring: - profiles: test + profiles: test name: test-YAML environment: testing servers: - - www.abc.test.com - - www.xyz.test.com - + - www.abc.test.com + - www.xyz.test.com + +external: [www.abc.test.com, www.xyz.test.com] + +map: + firstkey: key1 + secondkey: key2 + +component: + idm: + url: myurl + user: user + password: password + description: > + this should be a long + description + service: + url: myurlservice + token: token + description: > + this should be another long + description --- spring: - profiles: prod + profiles: prod name: prod-YAML environment: production servers: - - www.abc.com - - www.xyz.com + - www.abc.com + - www.xyz.com --- diff --git a/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/yaml/YAMLIntegrationTest.java b/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/yaml/YAMLIntegrationTest.java index 090d5c592e..19412c91f5 100644 --- a/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/yaml/YAMLIntegrationTest.java +++ b/spring-boot-modules/spring-boot-properties/src/test/java/com/baeldung/yaml/YAMLIntegrationTest.java @@ -11,6 +11,7 @@ import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) @SpringBootTest(classes = MyApplication.class) +@TestPropertySource(properties = {"spring.profiles.active = test"}) class YAMLIntegrationTest { @Autowired @@ -20,5 +21,6 @@ class YAMLIntegrationTest { void whenProfileTest_thenNameTesting() { assertTrue("testing".equalsIgnoreCase(config.getEnvironment())); assertTrue("test-YAML".equalsIgnoreCase(config.getName())); + assertTrue("myurl".equalsIgnoreCase(config.getComponent().getIdm().getUrl())); } } From ca9ab77e7c60ae57997be58c90bf4cdeac38b0b1 Mon Sep 17 00:00:00 2001 From: KevinGilmore Date: Fri, 12 Jun 2020 20:32:04 -0500 Subject: [PATCH 136/140] Bael 3766 update README (#9493) * BAEL-3336 BAEL-3058 add links * BAEL-3319: add link * BAEL-3284: add link * BAEL-3198: add link to article * BAEL-3479: add link to article * BAEL-3485: add article link * SCALA-38: move to new package and add link back to article * SCALA-38: add imports back into unit test * BAEL-3908: add link back to article * BAEL-2893 BAEL-3927 add link back to article * BAEL-3766: add link back to article --- persistence-modules/java-jpa-2/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/persistence-modules/java-jpa-2/README.md b/persistence-modules/java-jpa-2/README.md index 4b822c4782..d711eef1b0 100644 --- a/persistence-modules/java-jpa-2/README.md +++ b/persistence-modules/java-jpa-2/README.md @@ -13,4 +13,5 @@ This module contains articles about the Java Persistence API (JPA) in Java. - [JPA Annotation for the PostgreSQL TEXT Type](https://www.baeldung.com/jpa-annotation-postgresql-text-type) - [Mapping a Single Entity to Multiple Tables in JPA](https://www.baeldung.com/jpa-mapping-single-entity-to-multiple-tables) - [Constructing a JPA Query Between Unrelated Entities](https://www.baeldung.com/jpa-query-unrelated-entities) +- [When Does JPA Set the Primary Key](https://www.baeldung.com/jpa-strategies-when-set-primary-key) - More articles: [[<-- prev]](/java-jpa) From 3e6f576265c72c701360760c9ddb253bb96ab89e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Dupire?= Date: Sat, 13 Jun 2020 11:11:35 +0200 Subject: [PATCH 137/140] [JAVA-1660] Upgrade JUnit and Maven Surefire Plugin in guava modules (#9477) * [JAVA-1660] Upgrade JUnit and Maven Surefire Plugin versions in guava-modules * Set guava-modules parent pom's parent to parent-java and submodules' parent to guava-modules parent * Upgraded Maven Surefire Plugin version to 2.22.2 * Upgraded JUnit version to 5.6.2 * [JAVA-1660] Upgrade JUnit and Maven Surefire Plugin versions in guava * Upgraded Maven Surefire Plugin version to 2.22.2 * Upgraded JUnit version to 5.6.2 * [JAVA-1660] Upgrade JUnit and Maven Surefire Plugin versions in guava-collections * Upgraded Maven Surefire Plugin version to 2.22.2 * Upgraded JUnit version to 5.6.2 * [JAVA-1660] Upgrade JUnit and Maven Surefire Plugin versions in guava-collections-map * Upgraded Maven Surefire Plugin version to 2.22.2 * Upgraded JUnit version to 5.6.2 * [JAVA-1660] Upgrade JUnit and Maven Surefire Plugin versions in guava-collections-set * Upgraded Maven Surefire Plugin version to 2.22.2 * Upgraded JUnit version to 5.6.2 * [JAVA-1660] Upgraded JUnit and Maven Surefire Plugin in guava-io module * Fixed project structure and added missing resources to make tests work * Upgraded Maven Surefire Plugin to version 2.22.2 * Upgraded JUnit version to 5.6.2 --- guava-collections-map/pom.xml | 27 ++++++++++++ guava-collections-set/pom.xml | 29 +++++++++++-- guava-collections/pom.xml | 43 ++++++++++++++----- guava-io/pom.xml | 26 +++++++++++ .../GuavaCountingOutputStreamUnitTest.java | 0 .../com/baeldung/guava/GuavaIOUnitTest.java | 19 +++++++- guava-io/src/test/resources/test1.in | 1 + guava-io/src/test/resources/test1_1.in | 1 + guava-io/src/test/resources/test2.in | 4 ++ guava-modules/guava-18/pom.xml | 4 +- guava-modules/guava-19/pom.xml | 4 +- guava-modules/guava-21/pom.xml | 4 +- guava-modules/pom.xml | 33 ++++++++++++-- guava/pom.xml | 43 ++++++++++++++----- 14 files changed, 204 insertions(+), 34 deletions(-) rename guava-io/src/{main => }/test/java/com/baeldung/guava/GuavaCountingOutputStreamUnitTest.java (100%) rename guava-io/src/{main => }/test/java/com/baeldung/guava/GuavaIOUnitTest.java (93%) create mode 100644 guava-io/src/test/resources/test1.in create mode 100644 guava-io/src/test/resources/test1_1.in create mode 100644 guava-io/src/test/resources/test2.in diff --git a/guava-collections-map/pom.xml b/guava-collections-map/pom.xml index ee8ceb10f3..06537d26bd 100644 --- a/guava-collections-map/pom.xml +++ b/guava-collections-map/pom.xml @@ -16,12 +16,39 @@ guava-collections-map + src/main/resources true + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.22.2 + + + + + org.junit.jupiter + junit-jupiter + ${junit-jupiter.version} + test + + + org.junit.vintage + junit-vintage-engine + ${junit-jupiter.version} + test + + + + + 5.6.2 + \ No newline at end of file diff --git a/guava-collections-set/pom.xml b/guava-collections-set/pom.xml index 8bb0b924f9..49d96965a7 100644 --- a/guava-collections-set/pom.xml +++ b/guava-collections-set/pom.xml @@ -13,8 +13,32 @@ ../parent-java + + guava-collections-set + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.22.2 + + + + + + org.junit.jupiter + junit-jupiter + ${junit-jupiter.version} + test + + + org.junit.vintage + junit-vintage-engine + ${junit-jupiter.version} + test + org.assertj assertj-core @@ -23,13 +47,10 @@ - - guava-collections-set - - 3.6.1 + 5.6.2 diff --git a/guava-collections/pom.xml b/guava-collections/pom.xml index c6019362c5..744eba1a38 100644 --- a/guava-collections/pom.xml +++ b/guava-collections/pom.xml @@ -15,6 +15,25 @@ ../parent-java + + guava-collections + + + + src/main/resources + true + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.22.2 + + + + @@ -27,7 +46,20 @@ commons-lang3 ${commons-lang3.version} + + + org.junit.jupiter + junit-jupiter + ${junit-jupiter.version} + test + + + org.junit.vintage + junit-vintage-engine + ${junit-jupiter.version} + test + org.assertj assertj-core @@ -44,16 +76,6 @@ - - guava-collections - - - src/main/resources - true - - - - 4.1 @@ -61,6 +83,7 @@ 3.6.1 2.0.0.0 + 5.6.2 \ No newline at end of file diff --git a/guava-io/pom.xml b/guava-io/pom.xml index 7517d442b0..fd637f2474 100644 --- a/guava-io/pom.xml +++ b/guava-io/pom.xml @@ -4,6 +4,9 @@ 4.0.0 guava-io 0.1.0-SNAPSHOT + + 5.6.2 + guava-io @@ -15,12 +18,35 @@ guava-io + src/main/resources true + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.22.2 + + + + + org.junit.jupiter + junit-jupiter + ${junit-jupiter.version} + test + + + org.junit.vintage + junit-vintage-engine + ${junit-jupiter.version} + test + + \ No newline at end of file diff --git a/guava-io/src/main/test/java/com/baeldung/guava/GuavaCountingOutputStreamUnitTest.java b/guava-io/src/test/java/com/baeldung/guava/GuavaCountingOutputStreamUnitTest.java similarity index 100% rename from guava-io/src/main/test/java/com/baeldung/guava/GuavaCountingOutputStreamUnitTest.java rename to guava-io/src/test/java/com/baeldung/guava/GuavaCountingOutputStreamUnitTest.java diff --git a/guava-io/src/main/test/java/com/baeldung/guava/GuavaIOUnitTest.java b/guava-io/src/test/java/com/baeldung/guava/GuavaIOUnitTest.java similarity index 93% rename from guava-io/src/main/test/java/com/baeldung/guava/GuavaIOUnitTest.java rename to guava-io/src/test/java/com/baeldung/guava/GuavaIOUnitTest.java index 7d7b0ea04d..4d7c688f58 100644 --- a/guava-io/src/main/test/java/com/baeldung/guava/GuavaIOUnitTest.java +++ b/guava-io/src/test/java/com/baeldung/guava/GuavaIOUnitTest.java @@ -11,8 +11,11 @@ import java.io.FileOutputStream; import java.io.FileReader; import java.io.IOException; import java.net.URL; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.List; +import org.junit.After; import org.junit.Test; import com.google.common.base.Charsets; @@ -31,6 +34,21 @@ import com.google.common.io.Resources; public class GuavaIOUnitTest { + @After + public void afterEach() throws Exception { + deleteProducedFiles(); + } + + private void deleteProducedFiles() throws IOException { + deleteIfExists("test.out"); + deleteIfExists("test_copy.in"); + deleteIfExists("test_le.txt"); + } + + private void deleteIfExists(String fileName) throws IOException { + java.nio.file.Files.deleteIfExists(Paths.get("src", "test", "resources", fileName)); + } + @Test public void whenWriteUsingFiles_thenWritten() throws IOException { final String expectedValue = "Hello world"; @@ -206,5 +224,4 @@ public class GuavaIOUnitTest { assertEquals(value, result); } - } diff --git a/guava-io/src/test/resources/test1.in b/guava-io/src/test/resources/test1.in new file mode 100644 index 0000000000..70c379b63f --- /dev/null +++ b/guava-io/src/test/resources/test1.in @@ -0,0 +1 @@ +Hello world \ No newline at end of file diff --git a/guava-io/src/test/resources/test1_1.in b/guava-io/src/test/resources/test1_1.in new file mode 100644 index 0000000000..8318c86b35 --- /dev/null +++ b/guava-io/src/test/resources/test1_1.in @@ -0,0 +1 @@ +Test \ No newline at end of file diff --git a/guava-io/src/test/resources/test2.in b/guava-io/src/test/resources/test2.in new file mode 100644 index 0000000000..622efea9e6 --- /dev/null +++ b/guava-io/src/test/resources/test2.in @@ -0,0 +1,4 @@ +John +Jane +Adam +Tom \ No newline at end of file diff --git a/guava-modules/guava-18/pom.xml b/guava-modules/guava-18/pom.xml index 30d9f953ac..d65fab1e57 100644 --- a/guava-modules/guava-18/pom.xml +++ b/guava-modules/guava-18/pom.xml @@ -8,9 +8,9 @@ com.baeldung - parent-java + guava-modules 0.0.1-SNAPSHOT - ../../parent-java + ../ diff --git a/guava-modules/guava-19/pom.xml b/guava-modules/guava-19/pom.xml index 0060afd426..20a405cff4 100644 --- a/guava-modules/guava-19/pom.xml +++ b/guava-modules/guava-19/pom.xml @@ -8,9 +8,9 @@ com.baeldung - parent-java + guava-modules 0.0.1-SNAPSHOT - ../../parent-java + ../ diff --git a/guava-modules/guava-21/pom.xml b/guava-modules/guava-21/pom.xml index 7932cfa6d8..b126df99cb 100644 --- a/guava-modules/guava-21/pom.xml +++ b/guava-modules/guava-21/pom.xml @@ -8,9 +8,9 @@ com.baeldung - parent-java + guava-modules 0.0.1-SNAPSHOT - ../../parent-java + ../ diff --git a/guava-modules/pom.xml b/guava-modules/pom.xml index 2b899df162..4e7282364d 100644 --- a/guava-modules/pom.xml +++ b/guava-modules/pom.xml @@ -4,13 +4,16 @@ 4.0.0 guava-modules guava-modules + + 5.6.2 + pom com.baeldung - parent-modules - 1.0.0-SNAPSHOT - .. + parent-java + 0.0.1-SNAPSHOT + ../parent-java @@ -19,4 +22,28 @@ guava-21 + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.22.2 + + + + + + + org.junit.jupiter + junit-jupiter + ${junit-jupiter.version} + test + + + org.junit.vintage + junit-vintage-engine + ${junit-jupiter.version} + test + + diff --git a/guava/pom.xml b/guava/pom.xml index df6d57bd09..881390ae73 100644 --- a/guava/pom.xml +++ b/guava/pom.xml @@ -15,13 +15,45 @@ ../parent-java + + guava + + + + src/main/resources + true + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.22.2 + + + + org.apache.commons commons-lang3 ${commons-lang3.version} + + + org.junit.jupiter + junit-jupiter + ${junit-jupiter.version} + test + + + org.junit.vintage + junit-vintage-engine + ${junit-jupiter.version} + test + org.assertj assertj-core @@ -30,18 +62,9 @@ - - guava - - - src/main/resources - true - - - - + 5.6.2 3.6.1 From a6d6edb4947b10d8e3e7c186cd1f70882752c565 Mon Sep 17 00:00:00 2001 From: Mona Mohamadinia Date: Sat, 13 Jun 2020 14:23:32 +0430 Subject: [PATCH 138/140] BAEL-4125: How to get the insert ID in JDBC? (#9437) * Added the Code Samples * Refactor * Latest H2 Version * Avoid using * imports * Using givenXXX_whenYYY_thenZZZ Naming Convention --- .../core-java-persistence/pom.xml | 1 + .../genkeys/JdbcInsertIdIntegrationTest.java | 93 +++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 persistence-modules/core-java-persistence/src/test/java/com/baeldung/genkeys/JdbcInsertIdIntegrationTest.java diff --git a/persistence-modules/core-java-persistence/pom.xml b/persistence-modules/core-java-persistence/pom.xml index 1224523ac7..3dd8da1b7a 100644 --- a/persistence-modules/core-java-persistence/pom.xml +++ b/persistence-modules/core-java-persistence/pom.xml @@ -60,6 +60,7 @@ + 1.4.200 42.2.5.jre7 3.10.0 2.4.0 diff --git a/persistence-modules/core-java-persistence/src/test/java/com/baeldung/genkeys/JdbcInsertIdIntegrationTest.java b/persistence-modules/core-java-persistence/src/test/java/com/baeldung/genkeys/JdbcInsertIdIntegrationTest.java new file mode 100644 index 0000000000..f1ea5bfbb4 --- /dev/null +++ b/persistence-modules/core-java-persistence/src/test/java/com/baeldung/genkeys/JdbcInsertIdIntegrationTest.java @@ -0,0 +1,93 @@ +package com.baeldung.genkeys; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; + +import static org.assertj.core.api.Assertions.assertThat; + +public class JdbcInsertIdIntegrationTest { + + private static final String QUERY = "insert into persons (name) values (?)"; + + private static Connection connection; + + @BeforeClass + public static void setUp() throws Exception { + connection = DriverManager.getConnection("jdbc:h2:mem:generated-keys", "sa", ""); + connection + .createStatement() + .execute("create table persons(id bigint auto_increment, name varchar(255))"); + } + + @AfterClass + public static void tearDown() throws SQLException { + connection + .createStatement() + .execute("drop table persons"); + connection.close(); + } + + @Test + public void givenInsert_whenUsingAutoGenFlag_thenBeAbleToFetchTheIdAfterward() throws SQLException { + try (PreparedStatement statement = connection.prepareStatement(QUERY, Statement.RETURN_GENERATED_KEYS)) { + statement.setString(1, "Foo"); + int affectedRows = statement.executeUpdate(); + assertThat(affectedRows).isPositive(); + + try (ResultSet keys = statement.getGeneratedKeys()) { + assertThat(keys.next()).isTrue(); + assertThat(keys.getLong(1)).isGreaterThanOrEqualTo(1); + } + } + } + + @Test + public void givenInsert_whenUsingAutoGenFlagViaExecute_thenBeAbleToFetchTheIdAfterward() throws SQLException { + try (Statement statement = connection.createStatement()) { + String query = "insert into persons (name) values ('Foo')"; + int affectedRows = statement.executeUpdate(query, Statement.RETURN_GENERATED_KEYS); + assertThat(affectedRows).isPositive(); + + try (ResultSet keys = statement.getGeneratedKeys()) { + assertThat(keys.next()).isTrue(); + assertThat(keys.getLong(1)).isGreaterThanOrEqualTo(1); + } + } + } + + @Test + public void givenInsert_whenUsingReturningCols_thenBeAbleToFetchTheIdAfterward() throws SQLException { + try (PreparedStatement statement = connection.prepareStatement(QUERY, new String[] { "id" })) { + statement.setString(1, "Foo"); + int affectedRows = statement.executeUpdate(); + assertThat(affectedRows).isPositive(); + + try (ResultSet keys = statement.getGeneratedKeys()) { + assertThat(keys.next()).isTrue(); + assertThat(keys.getLong(1)).isGreaterThanOrEqualTo(1); + } + } + } + + @Test + public void givenInsert_whenUsingReturningColsViaExecute_thenBeAbleToFetchTheIdAfterward() throws SQLException { + try (Statement statement = connection.createStatement()) { + String query = "insert into persons (name) values ('Foo')"; + int affectedRows = statement.executeUpdate(query, new String[] { "id" }); + assertThat(affectedRows).isPositive(); + + try (ResultSet keys = statement.getGeneratedKeys()) { + assertThat(keys.next()).isTrue(); + assertThat(keys.getLong(1)).isGreaterThanOrEqualTo(1); + } + } + } +} From 4744f3d4d2145e17788bc263d3f582304dd6a7a6 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Sat, 13 Jun 2020 17:29:06 +0530 Subject: [PATCH 139/140] JAVA-938: Migrate spring-cloud-data-flow-stream-processing to parent-boot-2 --- .../log-sink/pom.xml | 5 ++--- .../pom.xml | 14 +++++++++++--- .../time-processor/pom.xml | 5 ++--- .../time-source/pom.xml | 6 +++--- 4 files changed, 18 insertions(+), 12 deletions(-) diff --git a/spring-cloud-data-flow/spring-cloud-data-flow-stream-processing/log-sink/pom.xml b/spring-cloud-data-flow/spring-cloud-data-flow-stream-processing/log-sink/pom.xml index 02d572aeb7..186e5b1886 100644 --- a/spring-cloud-data-flow/spring-cloud-data-flow-stream-processing/log-sink/pom.xml +++ b/spring-cloud-data-flow/spring-cloud-data-flow-stream-processing/log-sink/pom.xml @@ -10,9 +10,8 @@ com.baeldung - parent-boot-1 + spring-cloud-data-flow-stream-processing 0.0.1-SNAPSHOT - ../../../parent-boot-1 @@ -35,7 +34,7 @@ - Brixton.SR7 + Hoxton.SR4 diff --git a/spring-cloud-data-flow/spring-cloud-data-flow-stream-processing/pom.xml b/spring-cloud-data-flow/spring-cloud-data-flow-stream-processing/pom.xml index 5342049d73..e794287e10 100644 --- a/spring-cloud-data-flow/spring-cloud-data-flow-stream-processing/pom.xml +++ b/spring-cloud-data-flow/spring-cloud-data-flow-stream-processing/pom.xml @@ -2,6 +2,7 @@ 4.0.0 + com.baeldung spring-cloud-data-flow-stream-processing 0.0.1-SNAPSHOT spring-cloud-data-flow-stream-processing @@ -9,9 +10,8 @@ com.baeldung - parent-modules - 1.0.0-SNAPSHOT - ../../ + spring-cloud-data-flow + 0.0.1-SNAPSHOT @@ -21,5 +21,13 @@ time-processor log-sink + + + + org.springframework.boot + spring-boot-starter-test + test + + diff --git a/spring-cloud-data-flow/spring-cloud-data-flow-stream-processing/time-processor/pom.xml b/spring-cloud-data-flow/spring-cloud-data-flow-stream-processing/time-processor/pom.xml index f8db434423..b4ad84cfe9 100644 --- a/spring-cloud-data-flow/spring-cloud-data-flow-stream-processing/time-processor/pom.xml +++ b/spring-cloud-data-flow/spring-cloud-data-flow-stream-processing/time-processor/pom.xml @@ -10,9 +10,8 @@ com.baeldung - parent-boot-1 + spring-cloud-data-flow-stream-processing 0.0.1-SNAPSHOT - ../../../parent-boot-1 @@ -35,7 +34,7 @@ - Brixton.SR7 + Hoxton.SR4 diff --git a/spring-cloud-data-flow/spring-cloud-data-flow-stream-processing/time-source/pom.xml b/spring-cloud-data-flow/spring-cloud-data-flow-stream-processing/time-source/pom.xml index 8194755814..05908d3c52 100644 --- a/spring-cloud-data-flow/spring-cloud-data-flow-stream-processing/time-source/pom.xml +++ b/spring-cloud-data-flow/spring-cloud-data-flow-stream-processing/time-source/pom.xml @@ -2,6 +2,7 @@ 4.0.0 + com.baeldung.spring.cloud time-source 0.0.1-SNAPSHOT time-source @@ -10,9 +11,8 @@ com.baeldung - parent-boot-1 + spring-cloud-data-flow-stream-processing 0.0.1-SNAPSHOT - ../../../parent-boot-1 @@ -35,7 +35,7 @@ - Brixton.SR7 + Hoxton.SR4 From 4456caf9d7fc30c7bfdb01e0f3aacf10b3731b63 Mon Sep 17 00:00:00 2001 From: Benjamin Caure Date: Sat, 13 Jun 2020 14:54:57 +0200 Subject: [PATCH 140/140] BAEL-4078 Rest template logging (#9430) --- spring-resttemplate-2/README.md | 7 +++ spring-resttemplate-2/pom.xml | 63 +++++++++++++++++++ .../RestTemplateConfigurationApplication.java | 14 +++++ .../web/controller/PersonController.java | 17 +++++ .../src/main/resources/application.properties | 2 + .../logging/LoggingInterceptor.java | 29 +++++++++ .../logging/RestTemplateLoggingLiveTest.java | 50 +++++++++++++++ .../src/test/resources/application.properties | 5 ++ 8 files changed, 187 insertions(+) create mode 100644 spring-resttemplate-2/README.md create mode 100644 spring-resttemplate-2/pom.xml create mode 100644 spring-resttemplate-2/src/main/java/com/baeldung/resttemplate/logging/RestTemplateConfigurationApplication.java create mode 100644 spring-resttemplate-2/src/main/java/com/baeldung/resttemplate/logging/web/controller/PersonController.java create mode 100644 spring-resttemplate-2/src/main/resources/application.properties create mode 100644 spring-resttemplate-2/src/test/java/com/baeldung/resttemplate/logging/LoggingInterceptor.java create mode 100644 spring-resttemplate-2/src/test/java/com/baeldung/resttemplate/logging/RestTemplateLoggingLiveTest.java create mode 100644 spring-resttemplate-2/src/test/resources/application.properties diff --git a/spring-resttemplate-2/README.md b/spring-resttemplate-2/README.md new file mode 100644 index 0000000000..e0a394c642 --- /dev/null +++ b/spring-resttemplate-2/README.md @@ -0,0 +1,7 @@ +## Spring RestTemplate + +This module contains articles about Spring RestTemplate + +### Relevant Articles: + + diff --git a/spring-resttemplate-2/pom.xml b/spring-resttemplate-2/pom.xml new file mode 100644 index 0000000000..1a594fd21e --- /dev/null +++ b/spring-resttemplate-2/pom.xml @@ -0,0 +1,63 @@ + + + 4.0.0 + spring-resttemplate + 0.1-SNAPSHOT + spring-resttemplate-2 + war + + + com.baeldung + parent-boot-2 + 0.0.1-SNAPSHOT + ../parent-boot-2 + + + + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-test + + + + + + org.springframework + spring-web + + + commons-logging + commons-logging + + + + + + + org.slf4j + slf4j-api + + + ch.qos.logback + logback-classic + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + diff --git a/spring-resttemplate-2/src/main/java/com/baeldung/resttemplate/logging/RestTemplateConfigurationApplication.java b/spring-resttemplate-2/src/main/java/com/baeldung/resttemplate/logging/RestTemplateConfigurationApplication.java new file mode 100644 index 0000000000..4fa14edda1 --- /dev/null +++ b/spring-resttemplate-2/src/main/java/com/baeldung/resttemplate/logging/RestTemplateConfigurationApplication.java @@ -0,0 +1,14 @@ +package com.baeldung.resttemplate.logging; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +@EnableAutoConfiguration +public class RestTemplateConfigurationApplication { + + public static void main(String[] args) { + SpringApplication.run(RestTemplateConfigurationApplication.class, args); + } +} diff --git a/spring-resttemplate-2/src/main/java/com/baeldung/resttemplate/logging/web/controller/PersonController.java b/spring-resttemplate-2/src/main/java/com/baeldung/resttemplate/logging/web/controller/PersonController.java new file mode 100644 index 0000000000..8436c52a4a --- /dev/null +++ b/spring-resttemplate-2/src/main/java/com/baeldung/resttemplate/logging/web/controller/PersonController.java @@ -0,0 +1,17 @@ +package com.baeldung.resttemplate.logging.web.controller; + +import java.util.Arrays; +import java.util.List; + +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class PersonController { + + @PostMapping("/persons") + public List getPersons() { + return Arrays.asList(new String[] { "Lucie", "Jackie", "Danesh", "Tao" }); + } + +} \ No newline at end of file diff --git a/spring-resttemplate-2/src/main/resources/application.properties b/spring-resttemplate-2/src/main/resources/application.properties new file mode 100644 index 0000000000..ea4f7c866d --- /dev/null +++ b/spring-resttemplate-2/src/main/resources/application.properties @@ -0,0 +1,2 @@ +server.port=8080 +server.servlet.context-path=/spring-rest \ No newline at end of file diff --git a/spring-resttemplate-2/src/test/java/com/baeldung/resttemplate/logging/LoggingInterceptor.java b/spring-resttemplate-2/src/test/java/com/baeldung/resttemplate/logging/LoggingInterceptor.java new file mode 100644 index 0000000000..17ce390d8a --- /dev/null +++ b/spring-resttemplate-2/src/test/java/com/baeldung/resttemplate/logging/LoggingInterceptor.java @@ -0,0 +1,29 @@ +package com.baeldung.resttemplate.logging; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; +import java.util.stream.Collectors; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.http.HttpRequest; +import org.springframework.http.client.ClientHttpRequestExecution; +import org.springframework.http.client.ClientHttpRequestInterceptor; +import org.springframework.http.client.ClientHttpResponse; + +public class LoggingInterceptor implements ClientHttpRequestInterceptor { + + final static Logger log = LoggerFactory.getLogger(LoggingInterceptor.class); + + @Override + public ClientHttpResponse intercept(HttpRequest req, byte[] reqBody, ClientHttpRequestExecution ex) throws IOException { + log.debug("Request body: {}", new String(reqBody, StandardCharsets.UTF_8)); + ClientHttpResponse response = ex.execute(req, reqBody); + InputStreamReader isr = new InputStreamReader(response.getBody(), StandardCharsets.UTF_8); + String body = new BufferedReader(isr).lines() + .collect(Collectors.joining("\n")); + log.debug("Response body: {}", body); + return response; + } +} diff --git a/spring-resttemplate-2/src/test/java/com/baeldung/resttemplate/logging/RestTemplateLoggingLiveTest.java b/spring-resttemplate-2/src/test/java/com/baeldung/resttemplate/logging/RestTemplateLoggingLiveTest.java new file mode 100644 index 0000000000..99d0201eff --- /dev/null +++ b/spring-resttemplate-2/src/test/java/com/baeldung/resttemplate/logging/RestTemplateLoggingLiveTest.java @@ -0,0 +1,50 @@ +package com.baeldung.resttemplate.logging; + +import static org.hamcrest.CoreMatchers.equalTo; + +import static org.hamcrest.MatcherAssert.assertThat; + +import java.util.ArrayList; +import java.util.List; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.http.client.ClientHttpRequestInterceptor; +import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.util.CollectionUtils; +import org.springframework.web.client.RestTemplate; + +@RunWith(SpringRunner.class) +@SpringBootTest +public class RestTemplateLoggingLiveTest { + + private static final String baseUrl = "http://localhost:8080/spring-rest"; + + @Test + public void givenHttpClientConfiguration_whenSendGetForRequestEntity_thenRequestResponseFullLog() { + + RestTemplate restTemplate = new RestTemplate(); + restTemplate.setRequestFactory(new HttpComponentsClientHttpRequestFactory()); + + final ResponseEntity response = restTemplate.postForEntity(baseUrl + "/persons", "my request body", String.class); + assertThat(response.getStatusCode(), equalTo(HttpStatus.OK)); + } + + @Test + public void givenLoggingInterceptorConfiguration_whenSendGetForRequestEntity_thenRequestResponseCustomLog() { + + RestTemplate restTemplate = new RestTemplate(); + List interceptors = restTemplate.getInterceptors(); + if (CollectionUtils.isEmpty(interceptors)) { + interceptors = new ArrayList<>(); + } + interceptors.add(new LoggingInterceptor()); + restTemplate.setInterceptors(interceptors); + + final ResponseEntity response = restTemplate.postForEntity(baseUrl + "/persons", "my request body", String.class); + assertThat(response.getStatusCode(), equalTo(HttpStatus.OK)); + } +} diff --git a/spring-resttemplate-2/src/test/resources/application.properties b/spring-resttemplate-2/src/test/resources/application.properties new file mode 100644 index 0000000000..7bc9e56041 --- /dev/null +++ b/spring-resttemplate-2/src/test/resources/application.properties @@ -0,0 +1,5 @@ +logging.level.org.springframework.web.client.RestTemplate=DEBUG +logging.level.com.baeldung.resttemplate.logging.LoggingInterceptor=DEBUG +logging.level.org.apache.http=DEBUG +logging.level.httpclient.wire=DEBUG +logging.pattern.console=%20logger{20} - %msg%n