From e5f43622bec8ee4be55a64f54ff889b24a7f3028 Mon Sep 17 00:00:00 2001 From: RanjeetKaur17 Date: Fri, 19 Oct 2018 19:58:50 +0400 Subject: [PATCH 001/146] Example to demonstrate differences between CyclicBarrier and CountDownLatch. --- .../CountdownLatchCountExample.java | 33 +++++++++++++ .../CountdownLatchResetExample.java | 41 ++++++++++++++++ .../CyclicBarrierCompletionMethodExample.java | 46 ++++++++++++++++++ .../CyclicBarrierCountExample.java | 32 +++++++++++++ .../CyclicBarrierResetExample.java | 47 +++++++++++++++++++ .../CountdownLatchCountExampleUnitTest.java | 15 ++++++ .../CountdownLatchResetExampleUnitTest.java | 17 +++++++ ...arrierCompletionMethodExampleUnitTest.java | 17 +++++++ .../CyclicBarrierCountExampleUnitTest.java | 15 ++++++ .../CyclicBarrierResetExampleUnitTest.java | 17 +++++++ 10 files changed, 280 insertions(+) create mode 100644 core-java-concurrency/src/main/java/com/baeldung/concurrent/countdownlatch/CountdownLatchCountExample.java create mode 100644 core-java-concurrency/src/main/java/com/baeldung/concurrent/countdownlatch/CountdownLatchResetExample.java create mode 100644 core-java-concurrency/src/main/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierCompletionMethodExample.java create mode 100644 core-java-concurrency/src/main/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierCountExample.java create mode 100644 core-java-concurrency/src/main/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierResetExample.java create mode 100644 core-java-concurrency/src/test/java/com/baeldung/concurrent/countdownlatch/CountdownLatchCountExampleUnitTest.java create mode 100644 core-java-concurrency/src/test/java/com/baeldung/concurrent/countdownlatch/CountdownLatchResetExampleUnitTest.java create mode 100644 core-java-concurrency/src/test/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierCompletionMethodExampleUnitTest.java create mode 100644 core-java-concurrency/src/test/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierCountExampleUnitTest.java create mode 100644 core-java-concurrency/src/test/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierResetExampleUnitTest.java diff --git a/core-java-concurrency/src/main/java/com/baeldung/concurrent/countdownlatch/CountdownLatchCountExample.java b/core-java-concurrency/src/main/java/com/baeldung/concurrent/countdownlatch/CountdownLatchCountExample.java new file mode 100644 index 0000000000..08c7eeec03 --- /dev/null +++ b/core-java-concurrency/src/main/java/com/baeldung/concurrent/countdownlatch/CountdownLatchCountExample.java @@ -0,0 +1,33 @@ +package com.baeldung.concurrent.countdownlatch; + +import java.util.concurrent.CountDownLatch; + +public class CountdownLatchCountExample { + + private int count; + + public CountdownLatchCountExample(int count) { + this.count = count; + } + + public boolean callTwiceInSameThread() { + CountDownLatch countDownLatch = new CountDownLatch(count); + Thread t = new Thread(() -> { + countDownLatch.countDown(); + countDownLatch.countDown(); + }); + t.start(); + + try { + countDownLatch.await(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + return countDownLatch.getCount() == 0; + } + + public static void main(String[] args) { + CountdownLatchCountExample ex = new CountdownLatchCountExample(2); + System.out.println("Is CountDown Completed : " + ex.callTwiceInSameThread()); + } +} diff --git a/core-java-concurrency/src/main/java/com/baeldung/concurrent/countdownlatch/CountdownLatchResetExample.java b/core-java-concurrency/src/main/java/com/baeldung/concurrent/countdownlatch/CountdownLatchResetExample.java new file mode 100644 index 0000000000..7effc9e374 --- /dev/null +++ b/core-java-concurrency/src/main/java/com/baeldung/concurrent/countdownlatch/CountdownLatchResetExample.java @@ -0,0 +1,41 @@ +package com.baeldung.concurrent.countdownlatch; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; + +public class CountdownLatchResetExample { + + private int count; + private int threadCount; + private final List outputScraper; + + CountdownLatchResetExample(final List outputScraper, int count, int threadCount) { + this.outputScraper = outputScraper; + this.count = count; + this.threadCount = threadCount; + } + + public int countWaits() { + CountDownLatch countDownLatch = new CountDownLatch(count); + ExecutorService es = Executors.newFixedThreadPool(threadCount); + for (int i = 0; i < threadCount; i++) { + es.execute(() -> { + if (countDownLatch.getCount() > 0) { + outputScraper.add("Count Left : " + countDownLatch.getCount()); + } + countDownLatch.countDown(); + }); + } + + es.shutdown(); + return outputScraper.size(); + } + + public static void main(String[] args) { + CountdownLatchResetExample ex = new CountdownLatchResetExample(new ArrayList<>(),5,20); + System.out.println("Count : " + ex.countWaits()); + } +} diff --git a/core-java-concurrency/src/main/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierCompletionMethodExample.java b/core-java-concurrency/src/main/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierCompletionMethodExample.java new file mode 100644 index 0000000000..b7a32e2c8d --- /dev/null +++ b/core-java-concurrency/src/main/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierCompletionMethodExample.java @@ -0,0 +1,46 @@ +package com.baeldung.concurrent.cyclicbarrier; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.BrokenBarrierException; +import java.util.concurrent.CyclicBarrier; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; + +public class CyclicBarrierCompletionMethodExample { + + private int count; + private int threadCount; + private final List outputScraper; + + CyclicBarrierCompletionMethodExample(final List outputScraper, int count, int threadCount) { + this.outputScraper = outputScraper; + this.count = count; + this.threadCount = threadCount; + } + + public int countTrips() { + + CyclicBarrier cyclicBarrier = new CyclicBarrier(count, () -> { + outputScraper.add("Barrier is Tripped"); + }); + + ExecutorService es = Executors.newFixedThreadPool(threadCount); + for (int i = 0; i < threadCount; i++) { + es.execute(() -> { + try { + cyclicBarrier.await(); + } catch (InterruptedException | BrokenBarrierException e) { + e.printStackTrace(); + } + }); + } + es.shutdown(); + return outputScraper.size(); + } + + public static void main(String[] args) { + CyclicBarrierCompletionMethodExample ex = new CyclicBarrierCompletionMethodExample(new ArrayList(), 5, 20); + System.out.println("Count : " + ex.countTrips()); + } +} diff --git a/core-java-concurrency/src/main/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierCountExample.java b/core-java-concurrency/src/main/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierCountExample.java new file mode 100644 index 0000000000..c7a9b20698 --- /dev/null +++ b/core-java-concurrency/src/main/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierCountExample.java @@ -0,0 +1,32 @@ +package com.baeldung.concurrent.cyclicbarrier; + +import java.util.concurrent.BrokenBarrierException; +import java.util.concurrent.CyclicBarrier; + +public class CyclicBarrierCountExample { + + private int count; + + public CyclicBarrierCountExample(int count) { + this.count = count; + } + + public boolean callTwiceInSameThread() { + CyclicBarrier cyclicBarrier = new CyclicBarrier(count); + Thread t = new Thread(() -> { + try { + cyclicBarrier.await(); + cyclicBarrier.await(); + } catch (InterruptedException | BrokenBarrierException e) { + e.printStackTrace(); + } + }); + t.start(); + return cyclicBarrier.isBroken(); + } + + public static void main(String[] args) { + CyclicBarrierCountExample ex = new CyclicBarrierCountExample(1); + System.out.println("Count : " + ex.callTwiceInSameThread()); + } +} diff --git a/core-java-concurrency/src/main/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierResetExample.java b/core-java-concurrency/src/main/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierResetExample.java new file mode 100644 index 0000000000..c355b7eead --- /dev/null +++ b/core-java-concurrency/src/main/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierResetExample.java @@ -0,0 +1,47 @@ +package com.baeldung.concurrent.cyclicbarrier; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.BrokenBarrierException; +import java.util.concurrent.CyclicBarrier; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; + +public class CyclicBarrierResetExample { + + private int count; + private int threadCount; + private final List outputScraper; + + CyclicBarrierResetExample(final List outputScraper, int count, int threadCount) { + this.outputScraper = outputScraper; + this.count = count; + this.threadCount = threadCount; + } + + public int countWaits() { + + CyclicBarrier cyclicBarrier = new CyclicBarrier(count); + + ExecutorService es = Executors.newFixedThreadPool(threadCount); + for (int i = 0; i < threadCount; i++) { + es.execute(() -> { + try { + if (cyclicBarrier.getNumberWaiting() > 0) { + outputScraper.add("Waiting Count : " + cyclicBarrier.getNumberWaiting()); + } + cyclicBarrier.await(); + } catch (InterruptedException | BrokenBarrierException e) { + e.printStackTrace(); + } + }); + } + es.shutdown(); + return outputScraper.size(); + } + + public static void main(String[] args) { + CyclicBarrierResetExample ex = new CyclicBarrierResetExample(new ArrayList(), 5, 20); + System.out.println("Count : " + ex.countWaits()); + } +} diff --git a/core-java-concurrency/src/test/java/com/baeldung/concurrent/countdownlatch/CountdownLatchCountExampleUnitTest.java b/core-java-concurrency/src/test/java/com/baeldung/concurrent/countdownlatch/CountdownLatchCountExampleUnitTest.java new file mode 100644 index 0000000000..835efa53f2 --- /dev/null +++ b/core-java-concurrency/src/test/java/com/baeldung/concurrent/countdownlatch/CountdownLatchCountExampleUnitTest.java @@ -0,0 +1,15 @@ +package com.baeldung.concurrent.countdownlatch; + +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +public class CountdownLatchCountExampleUnitTest { + + @Test + public void whenCountDownLatch_completed() { + CountdownLatchCountExample ex = new CountdownLatchCountExample(2); + boolean isCompleted = ex.callTwiceInSameThread(); + assertTrue(isCompleted); + } +} diff --git a/core-java-concurrency/src/test/java/com/baeldung/concurrent/countdownlatch/CountdownLatchResetExampleUnitTest.java b/core-java-concurrency/src/test/java/com/baeldung/concurrent/countdownlatch/CountdownLatchResetExampleUnitTest.java new file mode 100644 index 0000000000..2018c9168d --- /dev/null +++ b/core-java-concurrency/src/test/java/com/baeldung/concurrent/countdownlatch/CountdownLatchResetExampleUnitTest.java @@ -0,0 +1,17 @@ +package com.baeldung.concurrent.countdownlatch; + +import static org.junit.Assert.assertEquals; + +import java.util.ArrayList; + +import org.junit.Test; + +public class CountdownLatchResetExampleUnitTest { + + @Test + public void whenCountDownLatch_noReset() { + CountdownLatchResetExample ex = new CountdownLatchResetExample(new ArrayList<>(),5,20); + int lineCount = ex.countWaits(); + assertEquals(5, lineCount); + } +} diff --git a/core-java-concurrency/src/test/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierCompletionMethodExampleUnitTest.java b/core-java-concurrency/src/test/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierCompletionMethodExampleUnitTest.java new file mode 100644 index 0000000000..e8db84935a --- /dev/null +++ b/core-java-concurrency/src/test/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierCompletionMethodExampleUnitTest.java @@ -0,0 +1,17 @@ +package com.baeldung.concurrent.cyclicbarrier; + +import static org.junit.Assert.assertEquals; + +import java.util.ArrayList; + +import org.junit.Test; + +public class CyclicBarrierCompletionMethodExampleUnitTest { + + @Test + public void whenCyclicBarrier_countTrips() { + CyclicBarrierCompletionMethodExample ex = new CyclicBarrierCompletionMethodExample(new ArrayList<>(),5,20); + int lineCount = ex.countTrips(); + assertEquals(4, lineCount); + } +} diff --git a/core-java-concurrency/src/test/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierCountExampleUnitTest.java b/core-java-concurrency/src/test/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierCountExampleUnitTest.java new file mode 100644 index 0000000000..9b7f3d9945 --- /dev/null +++ b/core-java-concurrency/src/test/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierCountExampleUnitTest.java @@ -0,0 +1,15 @@ +package com.baeldung.concurrent.cyclicbarrier; + +import static org.junit.Assert.assertFalse; + +import org.junit.Test; + +public class CyclicBarrierCountExampleUnitTest { + + @Test + public void whenCyclicBarrier_notCompleted() { + CyclicBarrierCountExample ex = new CyclicBarrierCountExample(2); + boolean isCompleted = ex.callTwiceInSameThread(); + assertFalse(isCompleted); + } +} diff --git a/core-java-concurrency/src/test/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierResetExampleUnitTest.java b/core-java-concurrency/src/test/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierResetExampleUnitTest.java new file mode 100644 index 0000000000..2871d16348 --- /dev/null +++ b/core-java-concurrency/src/test/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierResetExampleUnitTest.java @@ -0,0 +1,17 @@ +package com.baeldung.concurrent.cyclicbarrier; + +import static org.junit.Assert.assertEquals; + +import java.util.ArrayList; + +import org.junit.Test; + +public class CyclicBarrierResetExampleUnitTest { + + @Test + public void whenCyclicBarrier_reset() { + CyclicBarrierResetExample ex = new CyclicBarrierResetExample(new ArrayList<>(),5,20); + int lineCount = ex.countWaits(); + assertEquals(16, lineCount); + } +} From eaadcf96e2b0d2ff4a518d85a7ae78848cf77a4a Mon Sep 17 00:00:00 2001 From: Krzysztof Majewski Date: Mon, 22 Oct 2018 16:36:27 +0200 Subject: [PATCH 002/146] BAEL-2292 --- .../com/baeldung/datetime/DateTimeConfig.java | 29 +++++++++++++++++++ .../baeldung/datetime/DateTimeController.java | 29 +++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 spring-mvc-java/src/main/java/com/baeldung/datetime/DateTimeConfig.java create mode 100644 spring-mvc-java/src/main/java/com/baeldung/datetime/DateTimeController.java diff --git a/spring-mvc-java/src/main/java/com/baeldung/datetime/DateTimeConfig.java b/spring-mvc-java/src/main/java/com/baeldung/datetime/DateTimeConfig.java new file mode 100644 index 0000000000..8a5d1c71af --- /dev/null +++ b/spring-mvc-java/src/main/java/com/baeldung/datetime/DateTimeConfig.java @@ -0,0 +1,29 @@ +package com.baeldung.datetime; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.format.datetime.standard.DateTimeFormatterRegistrar; +import org.springframework.format.number.NumberFormatAnnotationFormatterFactory; +import org.springframework.format.support.DefaultFormattingConversionService; +import org.springframework.format.support.FormattingConversionService; + +import java.time.format.DateTimeFormatter; + +@Configuration +class DateTimeConfig { + + @Bean + public FormattingConversionService conversionService() { + DefaultFormattingConversionService conversionService = new DefaultFormattingConversionService(false); + + conversionService.addFormatterForFieldAnnotation(new NumberFormatAnnotationFormatterFactory()); + + DateTimeFormatterRegistrar registrar = new DateTimeFormatterRegistrar(); + registrar.setDateFormatter(DateTimeFormatter.ofPattern("dd.MM.yyyy")); + registrar.setDateTimeFormatter(DateTimeFormatter.ofPattern("dd.MM.yyyy HH:mm:ss")); + registrar.registerFormatters(conversionService); + + return conversionService; + } + +} \ No newline at end of file diff --git a/spring-mvc-java/src/main/java/com/baeldung/datetime/DateTimeController.java b/spring-mvc-java/src/main/java/com/baeldung/datetime/DateTimeController.java new file mode 100644 index 0000000000..5741b35530 --- /dev/null +++ b/spring-mvc-java/src/main/java/com/baeldung/datetime/DateTimeController.java @@ -0,0 +1,29 @@ +package com.baeldung.datetime; + +import org.springframework.format.annotation.DateTimeFormat; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.util.Date; + +@RestController +public class DateTimeController { + + @PostMapping("/date") + public void date(@RequestParam("date") @DateTimeFormat(pattern = "dd.MM.yyyy") Date date) { + // ... + } + + @PostMapping("/localdate") + public void localDate(@RequestParam("localDate") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate localDate) { + // ... + } + + @PostMapping("/localdatetime") + public void dateTime(@RequestParam("localDateTime") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime localDateTime) { + // ... + } +} \ No newline at end of file From a559137c8c31028fc0b757f86f2656d49122b438 Mon Sep 17 00:00:00 2001 From: RanjeetKaur17 Date: Wed, 24 Oct 2018 23:05:27 +0400 Subject: [PATCH 003/146] Changes as per review comments --- .../countdownlatch/CountdownLatchResetExample.java | 7 ++++--- .../cyclicbarrier/CyclicBarrierCountExample.java | 2 +- .../cyclicbarrier/CyclicBarrierResetExample.java | 6 +++--- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/core-java-concurrency/src/main/java/com/baeldung/concurrent/countdownlatch/CountdownLatchResetExample.java b/core-java-concurrency/src/main/java/com/baeldung/concurrent/countdownlatch/CountdownLatchResetExample.java index 7effc9e374..55e509e374 100644 --- a/core-java-concurrency/src/main/java/com/baeldung/concurrent/countdownlatch/CountdownLatchResetExample.java +++ b/core-java-concurrency/src/main/java/com/baeldung/concurrent/countdownlatch/CountdownLatchResetExample.java @@ -23,10 +23,11 @@ public class CountdownLatchResetExample { ExecutorService es = Executors.newFixedThreadPool(threadCount); for (int i = 0; i < threadCount; i++) { es.execute(() -> { - if (countDownLatch.getCount() > 0) { - outputScraper.add("Count Left : " + countDownLatch.getCount()); - } + long prevValue = countDownLatch.getCount(); countDownLatch.countDown(); + if (countDownLatch.getCount() != prevValue) { + outputScraper.add("Count Updated"); + } }); } diff --git a/core-java-concurrency/src/main/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierCountExample.java b/core-java-concurrency/src/main/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierCountExample.java index c7a9b20698..9d637b428b 100644 --- a/core-java-concurrency/src/main/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierCountExample.java +++ b/core-java-concurrency/src/main/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierCountExample.java @@ -26,7 +26,7 @@ public class CyclicBarrierCountExample { } public static void main(String[] args) { - CyclicBarrierCountExample ex = new CyclicBarrierCountExample(1); + CyclicBarrierCountExample ex = new CyclicBarrierCountExample(7); System.out.println("Count : " + ex.callTwiceInSameThread()); } } diff --git a/core-java-concurrency/src/main/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierResetExample.java b/core-java-concurrency/src/main/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierResetExample.java index c355b7eead..febeb0978e 100644 --- a/core-java-concurrency/src/main/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierResetExample.java +++ b/core-java-concurrency/src/main/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierResetExample.java @@ -28,8 +28,8 @@ public class CyclicBarrierResetExample { es.execute(() -> { try { if (cyclicBarrier.getNumberWaiting() > 0) { - outputScraper.add("Waiting Count : " + cyclicBarrier.getNumberWaiting()); - } + outputScraper.add("Count Updated"); + } cyclicBarrier.await(); } catch (InterruptedException | BrokenBarrierException e) { e.printStackTrace(); @@ -41,7 +41,7 @@ public class CyclicBarrierResetExample { } public static void main(String[] args) { - CyclicBarrierResetExample ex = new CyclicBarrierResetExample(new ArrayList(), 5, 20); + CyclicBarrierResetExample ex = new CyclicBarrierResetExample(new ArrayList(), 7, 20); System.out.println("Count : " + ex.countWaits()); } } From 541fa8d5be14ed66591c1201ae4e010c870693d1 Mon Sep 17 00:00:00 2001 From: RanjeetKaur17 Date: Fri, 26 Oct 2018 20:50:07 +0400 Subject: [PATCH 004/146] Using AtomicInteger to avoid Race conditions --- .../CountdownLatchResetExample.java | 19 +++++++++---------- .../CyclicBarrierCompletionMethodExample.java | 15 +++++++-------- .../CyclicBarrierResetExample.java | 15 +++++++-------- .../CountdownLatchResetExampleUnitTest.java | 2 +- ...arrierCompletionMethodExampleUnitTest.java | 4 +--- .../CyclicBarrierResetExampleUnitTest.java | 4 +--- 6 files changed, 26 insertions(+), 33 deletions(-) diff --git a/core-java-concurrency/src/main/java/com/baeldung/concurrent/countdownlatch/CountdownLatchResetExample.java b/core-java-concurrency/src/main/java/com/baeldung/concurrent/countdownlatch/CountdownLatchResetExample.java index 55e509e374..1828b7f91e 100644 --- a/core-java-concurrency/src/main/java/com/baeldung/concurrent/countdownlatch/CountdownLatchResetExample.java +++ b/core-java-concurrency/src/main/java/com/baeldung/concurrent/countdownlatch/CountdownLatchResetExample.java @@ -1,23 +1,22 @@ package com.baeldung.concurrent.countdownlatch; -import java.util.ArrayList; -import java.util.List; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; +import java.util.concurrent.atomic.AtomicInteger; public class CountdownLatchResetExample { private int count; private int threadCount; - private final List outputScraper; - - CountdownLatchResetExample(final List outputScraper, int count, int threadCount) { - this.outputScraper = outputScraper; + private final AtomicInteger updateCount; + + CountdownLatchResetExample(int count, int threadCount) { + updateCount = new AtomicInteger(0); this.count = count; this.threadCount = threadCount; } - + public int countWaits() { CountDownLatch countDownLatch = new CountDownLatch(count); ExecutorService es = Executors.newFixedThreadPool(threadCount); @@ -26,17 +25,17 @@ public class CountdownLatchResetExample { long prevValue = countDownLatch.getCount(); countDownLatch.countDown(); if (countDownLatch.getCount() != prevValue) { - outputScraper.add("Count Updated"); + updateCount.incrementAndGet(); } }); } es.shutdown(); - return outputScraper.size(); + return updateCount.get(); } public static void main(String[] args) { - CountdownLatchResetExample ex = new CountdownLatchResetExample(new ArrayList<>(),5,20); + CountdownLatchResetExample ex = new CountdownLatchResetExample(5, 20); System.out.println("Count : " + ex.countWaits()); } } diff --git a/core-java-concurrency/src/main/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierCompletionMethodExample.java b/core-java-concurrency/src/main/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierCompletionMethodExample.java index b7a32e2c8d..7c1299da62 100644 --- a/core-java-concurrency/src/main/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierCompletionMethodExample.java +++ b/core-java-concurrency/src/main/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierCompletionMethodExample.java @@ -1,20 +1,19 @@ package com.baeldung.concurrent.cyclicbarrier; -import java.util.ArrayList; -import java.util.List; import java.util.concurrent.BrokenBarrierException; import java.util.concurrent.CyclicBarrier; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; +import java.util.concurrent.atomic.AtomicInteger; public class CyclicBarrierCompletionMethodExample { private int count; private int threadCount; - private final List outputScraper; + private final AtomicInteger updateCount; - CyclicBarrierCompletionMethodExample(final List outputScraper, int count, int threadCount) { - this.outputScraper = outputScraper; + CyclicBarrierCompletionMethodExample(int count, int threadCount) { + updateCount = new AtomicInteger(0); this.count = count; this.threadCount = threadCount; } @@ -22,7 +21,7 @@ public class CyclicBarrierCompletionMethodExample { public int countTrips() { CyclicBarrier cyclicBarrier = new CyclicBarrier(count, () -> { - outputScraper.add("Barrier is Tripped"); + updateCount.incrementAndGet(); }); ExecutorService es = Executors.newFixedThreadPool(threadCount); @@ -36,11 +35,11 @@ public class CyclicBarrierCompletionMethodExample { }); } es.shutdown(); - return outputScraper.size(); + return updateCount.get(); } public static void main(String[] args) { - CyclicBarrierCompletionMethodExample ex = new CyclicBarrierCompletionMethodExample(new ArrayList(), 5, 20); + CyclicBarrierCompletionMethodExample ex = new CyclicBarrierCompletionMethodExample(5, 20); System.out.println("Count : " + ex.countTrips()); } } diff --git a/core-java-concurrency/src/main/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierResetExample.java b/core-java-concurrency/src/main/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierResetExample.java index febeb0978e..76b6198bc4 100644 --- a/core-java-concurrency/src/main/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierResetExample.java +++ b/core-java-concurrency/src/main/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierResetExample.java @@ -1,20 +1,19 @@ package com.baeldung.concurrent.cyclicbarrier; -import java.util.ArrayList; -import java.util.List; import java.util.concurrent.BrokenBarrierException; import java.util.concurrent.CyclicBarrier; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; +import java.util.concurrent.atomic.AtomicInteger; public class CyclicBarrierResetExample { private int count; private int threadCount; - private final List outputScraper; + private final AtomicInteger updateCount; - CyclicBarrierResetExample(final List outputScraper, int count, int threadCount) { - this.outputScraper = outputScraper; + CyclicBarrierResetExample(int count, int threadCount) { + updateCount = new AtomicInteger(0); this.count = count; this.threadCount = threadCount; } @@ -28,7 +27,7 @@ public class CyclicBarrierResetExample { es.execute(() -> { try { if (cyclicBarrier.getNumberWaiting() > 0) { - outputScraper.add("Count Updated"); + updateCount.incrementAndGet(); } cyclicBarrier.await(); } catch (InterruptedException | BrokenBarrierException e) { @@ -37,11 +36,11 @@ public class CyclicBarrierResetExample { }); } es.shutdown(); - return outputScraper.size(); + return updateCount.get(); } public static void main(String[] args) { - CyclicBarrierResetExample ex = new CyclicBarrierResetExample(new ArrayList(), 7, 20); + CyclicBarrierResetExample ex = new CyclicBarrierResetExample(7, 20); System.out.println("Count : " + ex.countWaits()); } } diff --git a/core-java-concurrency/src/test/java/com/baeldung/concurrent/countdownlatch/CountdownLatchResetExampleUnitTest.java b/core-java-concurrency/src/test/java/com/baeldung/concurrent/countdownlatch/CountdownLatchResetExampleUnitTest.java index 2018c9168d..658ab5301a 100644 --- a/core-java-concurrency/src/test/java/com/baeldung/concurrent/countdownlatch/CountdownLatchResetExampleUnitTest.java +++ b/core-java-concurrency/src/test/java/com/baeldung/concurrent/countdownlatch/CountdownLatchResetExampleUnitTest.java @@ -10,7 +10,7 @@ public class CountdownLatchResetExampleUnitTest { @Test public void whenCountDownLatch_noReset() { - CountdownLatchResetExample ex = new CountdownLatchResetExample(new ArrayList<>(),5,20); + CountdownLatchResetExample ex = new CountdownLatchResetExample(5,20); int lineCount = ex.countWaits(); assertEquals(5, lineCount); } diff --git a/core-java-concurrency/src/test/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierCompletionMethodExampleUnitTest.java b/core-java-concurrency/src/test/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierCompletionMethodExampleUnitTest.java index e8db84935a..f76b51c100 100644 --- a/core-java-concurrency/src/test/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierCompletionMethodExampleUnitTest.java +++ b/core-java-concurrency/src/test/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierCompletionMethodExampleUnitTest.java @@ -2,15 +2,13 @@ package com.baeldung.concurrent.cyclicbarrier; import static org.junit.Assert.assertEquals; -import java.util.ArrayList; - import org.junit.Test; public class CyclicBarrierCompletionMethodExampleUnitTest { @Test public void whenCyclicBarrier_countTrips() { - CyclicBarrierCompletionMethodExample ex = new CyclicBarrierCompletionMethodExample(new ArrayList<>(),5,20); + CyclicBarrierCompletionMethodExample ex = new CyclicBarrierCompletionMethodExample(5,20); int lineCount = ex.countTrips(); assertEquals(4, lineCount); } diff --git a/core-java-concurrency/src/test/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierResetExampleUnitTest.java b/core-java-concurrency/src/test/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierResetExampleUnitTest.java index 2871d16348..413a17e9ff 100644 --- a/core-java-concurrency/src/test/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierResetExampleUnitTest.java +++ b/core-java-concurrency/src/test/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierResetExampleUnitTest.java @@ -2,15 +2,13 @@ package com.baeldung.concurrent.cyclicbarrier; import static org.junit.Assert.assertEquals; -import java.util.ArrayList; - import org.junit.Test; public class CyclicBarrierResetExampleUnitTest { @Test public void whenCyclicBarrier_reset() { - CyclicBarrierResetExample ex = new CyclicBarrierResetExample(new ArrayList<>(),5,20); + CyclicBarrierResetExample ex = new CyclicBarrierResetExample(5,20); int lineCount = ex.countWaits(); assertEquals(16, lineCount); } From 6ea369f248a8f0dad11a6efd9b9d30a566f6f4c6 Mon Sep 17 00:00:00 2001 From: RanjeetKaur17 Date: Fri, 26 Oct 2018 20:59:34 +0400 Subject: [PATCH 005/146] Fixing Test Cases --- .../CyclicBarrierCompletionMethodExampleUnitTest.java | 4 ++-- .../cyclicbarrier/CyclicBarrierResetExampleUnitTest.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/core-java-concurrency/src/test/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierCompletionMethodExampleUnitTest.java b/core-java-concurrency/src/test/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierCompletionMethodExampleUnitTest.java index f76b51c100..310063c86c 100644 --- a/core-java-concurrency/src/test/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierCompletionMethodExampleUnitTest.java +++ b/core-java-concurrency/src/test/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierCompletionMethodExampleUnitTest.java @@ -8,8 +8,8 @@ public class CyclicBarrierCompletionMethodExampleUnitTest { @Test public void whenCyclicBarrier_countTrips() { - CyclicBarrierCompletionMethodExample ex = new CyclicBarrierCompletionMethodExample(5,20); + CyclicBarrierCompletionMethodExample ex = new CyclicBarrierCompletionMethodExample(7,20); int lineCount = ex.countTrips(); - assertEquals(4, lineCount); + assertEquals(2, lineCount); } } diff --git a/core-java-concurrency/src/test/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierResetExampleUnitTest.java b/core-java-concurrency/src/test/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierResetExampleUnitTest.java index 413a17e9ff..7b6306df76 100644 --- a/core-java-concurrency/src/test/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierResetExampleUnitTest.java +++ b/core-java-concurrency/src/test/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierResetExampleUnitTest.java @@ -8,8 +8,8 @@ public class CyclicBarrierResetExampleUnitTest { @Test public void whenCyclicBarrier_reset() { - CyclicBarrierResetExample ex = new CyclicBarrierResetExample(5,20); + CyclicBarrierResetExample ex = new CyclicBarrierResetExample(7,20); int lineCount = ex.countWaits(); - assertEquals(16, lineCount); + assertEquals(17, lineCount); } } From 512a6e05a1dd24ec7caa6c0da53e3e278d40e674 Mon Sep 17 00:00:00 2001 From: RanjeetKaur17 Date: Fri, 26 Oct 2018 21:09:58 +0400 Subject: [PATCH 006/146] Fixing Test Cases --- .../cyclicbarrier/CyclicBarrierResetExampleUnitTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core-java-concurrency/src/test/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierResetExampleUnitTest.java b/core-java-concurrency/src/test/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierResetExampleUnitTest.java index 7b6306df76..913325f8e2 100644 --- a/core-java-concurrency/src/test/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierResetExampleUnitTest.java +++ b/core-java-concurrency/src/test/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierResetExampleUnitTest.java @@ -8,8 +8,8 @@ public class CyclicBarrierResetExampleUnitTest { @Test public void whenCyclicBarrier_reset() { - CyclicBarrierResetExample ex = new CyclicBarrierResetExample(7,20); + CyclicBarrierResetExample ex = new CyclicBarrierResetExample(7,10); int lineCount = ex.countWaits(); - assertEquals(17, lineCount); + assertEquals(8, lineCount); } } From 39a828fbc995ee452b363e21432a3c0118bfec98 Mon Sep 17 00:00:00 2001 From: RanjeetKaur17 Date: Sun, 28 Oct 2018 16:45:15 +0400 Subject: [PATCH 007/146] Fixing Test Cases --- .../CountdownLatchResetExampleUnitTest.java | 8 +++----- .../cyclicbarrier/CyclicBarrierResetExampleUnitTest.java | 6 +++--- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/core-java-concurrency/src/test/java/com/baeldung/concurrent/countdownlatch/CountdownLatchResetExampleUnitTest.java b/core-java-concurrency/src/test/java/com/baeldung/concurrent/countdownlatch/CountdownLatchResetExampleUnitTest.java index 658ab5301a..d2d43f6312 100644 --- a/core-java-concurrency/src/test/java/com/baeldung/concurrent/countdownlatch/CountdownLatchResetExampleUnitTest.java +++ b/core-java-concurrency/src/test/java/com/baeldung/concurrent/countdownlatch/CountdownLatchResetExampleUnitTest.java @@ -1,8 +1,6 @@ package com.baeldung.concurrent.countdownlatch; -import static org.junit.Assert.assertEquals; - -import java.util.ArrayList; +import static org.junit.Assert.assertTrue; import org.junit.Test; @@ -10,8 +8,8 @@ public class CountdownLatchResetExampleUnitTest { @Test public void whenCountDownLatch_noReset() { - CountdownLatchResetExample ex = new CountdownLatchResetExample(5,20); + CountdownLatchResetExample ex = new CountdownLatchResetExample(7,20); int lineCount = ex.countWaits(); - assertEquals(5, lineCount); + assertTrue(lineCount <= 7); } } diff --git a/core-java-concurrency/src/test/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierResetExampleUnitTest.java b/core-java-concurrency/src/test/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierResetExampleUnitTest.java index 913325f8e2..8d2b148f06 100644 --- a/core-java-concurrency/src/test/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierResetExampleUnitTest.java +++ b/core-java-concurrency/src/test/java/com/baeldung/concurrent/cyclicbarrier/CyclicBarrierResetExampleUnitTest.java @@ -1,6 +1,6 @@ package com.baeldung.concurrent.cyclicbarrier; -import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import org.junit.Test; @@ -8,8 +8,8 @@ public class CyclicBarrierResetExampleUnitTest { @Test public void whenCyclicBarrier_reset() { - CyclicBarrierResetExample ex = new CyclicBarrierResetExample(7,10); + CyclicBarrierResetExample ex = new CyclicBarrierResetExample(7,20); int lineCount = ex.countWaits(); - assertEquals(8, lineCount); + assertTrue(lineCount > 7); } } From a79f802038e3be1b59abef89b97a98d2644ee4a0 Mon Sep 17 00:00:00 2001 From: saikat Date: Sun, 28 Oct 2018 23:47:00 +0530 Subject: [PATCH 008/146] Add new module for restx-demo --- pom.xml | 1 + restx-demo/data/credentials.json | 12 ++ restx-demo/data/users.json | 4 + restx-demo/md.restx.json | 38 +++++ restx-demo/pom.xml | 156 ++++++++++++++++++ .../src/main/java/restx/demo/AppModule.java | 74 +++++++++ .../src/main/java/restx/demo/AppServer.java | 32 ++++ .../src/main/java/restx/demo/Roles.java | 10 ++ .../main/java/restx/demo/domain/Message.java | 21 +++ .../java/restx/demo/rest/HelloResource.java | 62 +++++++ restx-demo/src/main/resources/logback.xml | 94 +++++++++++ .../resources/restx/demo/settings.properties | 1 + restx-demo/src/main/webapp/WEB-INF/web.xml | 15 ++ .../demo/rest/HelloResourceSpecTest.java | 23 +++ .../hello/should_admin_say_hello.spec.yaml | 10 ++ .../hello/should_anyone_say_hello.spec.yaml | 8 + ..._value_triggers_validation_error.spec.yaml | 17 ++ .../hello/should_user1_say_hello.spec.yaml | 10 ++ .../should_user2_not_say_hello.spec.yaml | 10 ++ 19 files changed, 598 insertions(+) create mode 100644 restx-demo/data/credentials.json create mode 100644 restx-demo/data/users.json create mode 100644 restx-demo/md.restx.json create mode 100644 restx-demo/pom.xml create mode 100644 restx-demo/src/main/java/restx/demo/AppModule.java create mode 100644 restx-demo/src/main/java/restx/demo/AppServer.java create mode 100644 restx-demo/src/main/java/restx/demo/Roles.java create mode 100644 restx-demo/src/main/java/restx/demo/domain/Message.java create mode 100644 restx-demo/src/main/java/restx/demo/rest/HelloResource.java create mode 100644 restx-demo/src/main/resources/logback.xml create mode 100644 restx-demo/src/main/resources/restx/demo/settings.properties create mode 100644 restx-demo/src/main/webapp/WEB-INF/web.xml create mode 100644 restx-demo/src/test/java/restx/demo/rest/HelloResourceSpecTest.java create mode 100644 restx-demo/src/test/resources/specs/hello/should_admin_say_hello.spec.yaml create mode 100644 restx-demo/src/test/resources/specs/hello/should_anyone_say_hello.spec.yaml create mode 100644 restx-demo/src/test/resources/specs/hello/should_missing_value_triggers_validation_error.spec.yaml create mode 100644 restx-demo/src/test/resources/specs/hello/should_user1_say_hello.spec.yaml create mode 100644 restx-demo/src/test/resources/specs/hello/should_user2_not_say_hello.spec.yaml diff --git a/pom.xml b/pom.xml index 0b5cd16ea0..10e23da0ad 100644 --- a/pom.xml +++ b/pom.xml @@ -1608,6 +1608,7 @@ persistence-modules/spring-data-elasticsearch core-java-concurrency core-java-concurrency-collections + restx-demo diff --git a/restx-demo/data/credentials.json b/restx-demo/data/credentials.json new file mode 100644 index 0000000000..c1a4fcf531 --- /dev/null +++ b/restx-demo/data/credentials.json @@ -0,0 +1,12 @@ +{ + "//": "lines with // keys are just comments (we don't have real comments in json)", + "//": "this file stores password passed through md5+bcrypt hash", + "//": "you can use `restx hash md5+bcrypt {password}` shell command to get hashed passwords to put here", + + "//": "to help startup with restx, there are comments with clear text passwords,", + "//": "which should obviously not be stored here.", + "user1": "$2a$10$iZluFUJShbjb1ue68bLrDuGCeJL9EMLHelVIf8u0SUbCseDOvKnoe", + "//": "user 1 password is 'user1-pwd'", + "user2": "$2a$10$oym3SYMFXf/9gGfDKKHO4eM1vWNqAZMsRZCL.BORCaP4yp5cdiCXu", + "//": "user 2 password is 'user2-pwd'" +} \ No newline at end of file diff --git a/restx-demo/data/users.json b/restx-demo/data/users.json new file mode 100644 index 0000000000..834e03c4b4 --- /dev/null +++ b/restx-demo/data/users.json @@ -0,0 +1,4 @@ +[ + {"name":"user1", "roles": ["hello"]}, + {"name":"user2", "roles": []} +] \ No newline at end of file diff --git a/restx-demo/md.restx.json b/restx-demo/md.restx.json new file mode 100644 index 0000000000..c87244001c --- /dev/null +++ b/restx-demo/md.restx.json @@ -0,0 +1,38 @@ +{ + "module": "restx-demo:restx-demo:0.1-SNAPSHOT", + "packaging": "war", + + "properties": { + "java.version": "1.8", + "restx.version": "0.35-rc4" + }, + "fragments": { + "maven": [ + "classpath:///restx/build/fragments/maven/javadoc-apidoclet.xml" ] + }, + "dependencies": { + "compile": [ + "io.restx:restx-core:${restx.version}", + "io.restx:restx-security-basic:${restx.version}", + "io.restx:restx-core-annotation-processor:${restx.version}", + "io.restx:restx-factory:${restx.version}", + "io.restx:restx-factory-admin:${restx.version}", + "io.restx:restx-validation:${restx.version}", + "io.restx:restx-monitor-codahale:${restx.version}", + "io.restx:restx-monitor-admin:${restx.version}", + "io.restx:restx-log-admin:${restx.version}", + "io.restx:restx-i18n-admin:${restx.version}", + "io.restx:restx-stats-admin:${restx.version}", + "io.restx:restx-servlet:${restx.version}", + "io.restx:restx-server-jetty8:${restx.version}!optional", + "io.restx:restx-apidocs:${restx.version}", + "io.restx:restx-specs-admin:${restx.version}", + "io.restx:restx-admin:${restx.version}", + "ch.qos.logback:logback-classic:1.0.13" + ], + "test": [ + "io.restx:restx-specs-tests:${restx.version}", + "junit:junit:4.11" + ] + } +} diff --git a/restx-demo/pom.xml b/restx-demo/pom.xml new file mode 100644 index 0000000000..da106b8191 --- /dev/null +++ b/restx-demo/pom.xml @@ -0,0 +1,156 @@ + + + 4.0.0 + + restx-demo + restx-demo + 0.1-SNAPSHOT + war + restx-demo + + + 1.8 + 1.8 + 0.35-rc4 + + + + com.baeldung + parent-modules + 1.0.0-SNAPSHOT + + + + + io.restx + restx-core + ${restx.version} + + + io.restx + restx-security-basic + ${restx.version} + + + io.restx + restx-core-annotation-processor + ${restx.version} + + + io.restx + restx-factory + ${restx.version} + + + io.restx + restx-factory-admin + ${restx.version} + + + io.restx + restx-validation + ${restx.version} + + + io.restx + restx-monitor-codahale + ${restx.version} + + + io.restx + restx-monitor-admin + ${restx.version} + + + io.restx + restx-log-admin + ${restx.version} + + + io.restx + restx-i18n-admin + ${restx.version} + + + io.restx + restx-stats-admin + ${restx.version} + + + io.restx + restx-servlet + ${restx.version} + + + io.restx + restx-server-jetty8 + ${restx.version} + true + + + io.restx + restx-apidocs + ${restx.version} + + + io.restx + restx-specs-admin + ${restx.version} + + + io.restx + restx-admin + ${restx.version} + + + ch.qos.logback + logback-classic + 1.0.13 + + + io.restx + restx-specs-tests + ${restx.version} + test + + + junit + junit + 4.11 + test + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + + + attach-docs + + prepare-package + + jar + + + + + ${maven.compiler.source} + restx.apidocs.doclet.ApidocsDoclet + + io.restx + restx-apidocs-doclet + ${restx.version} + + -restx-target-dir ${project.basedir}/target/classes + + + + + diff --git a/restx-demo/src/main/java/restx/demo/AppModule.java b/restx-demo/src/main/java/restx/demo/AppModule.java new file mode 100644 index 0000000000..26bc681481 --- /dev/null +++ b/restx-demo/src/main/java/restx/demo/AppModule.java @@ -0,0 +1,74 @@ +package restx.demo; + +import restx.config.ConfigLoader; +import restx.config.ConfigSupplier; +import restx.factory.Provides; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.common.base.Charsets; +import com.google.common.collect.ImmutableSet; +import restx.security.*; +import restx.factory.Module; +import restx.factory.Provides; +import javax.inject.Named; + +import java.nio.file.Paths; + +@Module +public class AppModule { + @Provides + public SignatureKey signatureKey() { + return new SignatureKey("restx-demo -447494532235718370 restx-demo 801c9eaf-4116-48f2-906b-e979fba72757".getBytes(Charsets.UTF_8)); + } + + @Provides + @Named("restx.admin.password") + public String restxAdminPassword() { + return "4780"; + } + + @Provides + public ConfigSupplier appConfigSupplier(ConfigLoader configLoader) { + // Load settings.properties in restx.demo package as a set of config entries + return configLoader.fromResource("restx/demo/settings"); + } + + @Provides + public CredentialsStrategy credentialsStrategy() { + return new BCryptCredentialsStrategy(); + } + + @Provides + public BasicPrincipalAuthenticator basicPrincipalAuthenticator( + SecuritySettings securitySettings, CredentialsStrategy credentialsStrategy, + @Named("restx.admin.passwordHash") String defaultAdminPasswordHash, ObjectMapper mapper) { + return new StdBasicPrincipalAuthenticator(new StdUserService<>( + // use file based users repository. + // Developer's note: prefer another storage mechanism for your users if you need real user management + // and better perf + new FileBasedUserRepository<>( + StdUser.class, // this is the class for the User objects, that you can get in your app code + // with RestxSession.current().getPrincipal().get() + // it can be a custom user class, it just need to be json deserializable + mapper, + + // this is the default restx admin, useful to access the restx admin console. + // if one user with restx-admin role is defined in the repository, this default user won't be + // available anymore + new StdUser("admin", ImmutableSet.of("*")), + + // the path where users are stored + Paths.get("data/users.json"), + + // the path where credentials are stored. isolating both is a good practice in terms of security + // it is strongly recommended to follow this approach even if you use your own repository + Paths.get("data/credentials.json"), + + // tells that we want to reload the files dynamically if they are touched. + // this has a performance impact, if you know your users / credentials never change without a + // restart you can disable this to get better perfs + true), + credentialsStrategy, defaultAdminPasswordHash), + securitySettings); + } +} diff --git a/restx-demo/src/main/java/restx/demo/AppServer.java b/restx-demo/src/main/java/restx/demo/AppServer.java new file mode 100644 index 0000000000..d66aadac68 --- /dev/null +++ b/restx-demo/src/main/java/restx/demo/AppServer.java @@ -0,0 +1,32 @@ +package restx.demo; + +import com.google.common.base.Optional; +import restx.server.WebServer; +import restx.server.Jetty8WebServer; + +/** + * This class can be used to run the app. + * + * Alternatively, you can deploy the app as a war in a regular container like tomcat or jetty. + * + * Reading the port from system env PORT makes it compatible with heroku. + */ +public class AppServer { + public static final String WEB_INF_LOCATION = "src/main/webapp/WEB-INF/web.xml"; + public static final String WEB_APP_LOCATION = "src/main/webapp"; + + public static void main(String[] args) throws Exception { + int port = Integer.valueOf(Optional.fromNullable(System.getenv("PORT")).or("8080")); + WebServer server = new Jetty8WebServer(WEB_INF_LOCATION, WEB_APP_LOCATION, port, "0.0.0.0"); + + /* + * load mode from system property if defined, or default to dev + * be careful with that setting, if you use this class to launch your server in production, make sure to launch + * it with -Drestx.mode=prod or change the default here + */ + System.setProperty("restx.mode", System.getProperty("restx.mode", "dev")); + System.setProperty("restx.app.package", "restx.demo"); + + server.startAndAwait(); + } +} diff --git a/restx-demo/src/main/java/restx/demo/Roles.java b/restx-demo/src/main/java/restx/demo/Roles.java new file mode 100644 index 0000000000..1240da70d1 --- /dev/null +++ b/restx-demo/src/main/java/restx/demo/Roles.java @@ -0,0 +1,10 @@ +package restx.demo; + +/** + * A list of roles for the application. + * + * We don't use an enum here because it must be used inside an annotation. + */ +public final class Roles { + public static final String HELLO_ROLE = "hello"; +} diff --git a/restx-demo/src/main/java/restx/demo/domain/Message.java b/restx-demo/src/main/java/restx/demo/domain/Message.java new file mode 100644 index 0000000000..733c00deff --- /dev/null +++ b/restx-demo/src/main/java/restx/demo/domain/Message.java @@ -0,0 +1,21 @@ +package restx.demo.domain; + +public class Message { + private String message; + + public String getMessage() { + return message; + } + + public Message setMessage(final String message) { + this.message = message; + return this; + } + + @Override + public String toString() { + return "Message{" + + "message='" + message + '\'' + + '}'; + } +} diff --git a/restx-demo/src/main/java/restx/demo/rest/HelloResource.java b/restx-demo/src/main/java/restx/demo/rest/HelloResource.java new file mode 100644 index 0000000000..5cb2c2a5e6 --- /dev/null +++ b/restx-demo/src/main/java/restx/demo/rest/HelloResource.java @@ -0,0 +1,62 @@ +package restx.demo.rest; + +import restx.demo.domain.Message; +import restx.demo.Roles; +import org.joda.time.DateTime; +import restx.annotations.GET; +import restx.annotations.POST; +import restx.annotations.RestxResource; +import restx.factory.Component; +import restx.security.PermitAll; +import restx.security.RolesAllowed; +import restx.security.RestxSession; + +import javax.validation.constraints.NotNull; + +@Component @RestxResource +public class HelloResource { + + /** + * Say hello to currently logged in user. + * + * Authorized only for principals with Roles.HELLO_ROLE role. + * + * @return a Message to say hello + */ + @GET("/message") + @RolesAllowed(Roles.HELLO_ROLE) + public Message sayHello() { + return new Message().setMessage(String.format( + "hello %s, it's %s", + RestxSession.current().getPrincipal().get().getName(), + DateTime.now().toString("HH:mm:ss"))); + } + + /** + * Say hello to anybody. + * + * Does not require authentication. + * + * @return a Message to say hello + */ + @GET("/hello") + @PermitAll + public Message helloPublic(String who) { + return new Message().setMessage(String.format( + "hello %s, it's %s", + who, DateTime.now().toString("HH:mm:ss"))); + } + + public static class MyPOJO { + @NotNull + String value; + public String getValue(){ return value; } + public void setValue(String value){ this.value = value; } + } + @POST("/mypojo") + @PermitAll + public MyPOJO helloPojo(MyPOJO pojo){ + pojo.setValue("hello "+pojo.getValue()); + return pojo; + } +} diff --git a/restx-demo/src/main/resources/logback.xml b/restx-demo/src/main/resources/logback.xml new file mode 100644 index 0000000000..524bca6b1f --- /dev/null +++ b/restx-demo/src/main/resources/logback.xml @@ -0,0 +1,94 @@ + + + true + + + + + ${LOGS_FOLDER}/errors.log + + ERROR + + + %d [%-16thread] [%-10X{principal}] %-5level %logger{36} - %msg%n + + + ${LOGS_FOLDER}/errors.%d.log + 30 + + + + + + + + ${LOGS_FOLDER}/app.log + + INFO + + + %d [%-16thread] [%-10X{principal}] %-5level %logger{36} - %msg%n + + + ${LOGS_FOLDER}/app.%d.log + 10 + + + + ${LOGS_FOLDER}/debug.log + + %d [%-16thread] [%-10X{principal}] %-5level %logger{36} - %msg%n + + + ${LOGS_FOLDER}/debug.%i.log.zip + 1 + 3 + + + + 50MB + + + + + + + + + + + + %d [%-16thread] [%-10X{principal}] %-5level %logger{36} - %msg%n + + + + ${LOGS_FOLDER}/app.log + + %d [%-16thread] [%-10X{principal}] %-5level %logger{36} - %msg%n + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/restx-demo/src/main/resources/restx/demo/settings.properties b/restx-demo/src/main/resources/restx/demo/settings.properties new file mode 100644 index 0000000000..a03c2eea97 --- /dev/null +++ b/restx-demo/src/main/resources/restx/demo/settings.properties @@ -0,0 +1 @@ +app.name=restx-demo \ No newline at end of file diff --git a/restx-demo/src/main/webapp/WEB-INF/web.xml b/restx-demo/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000000..c651794526 --- /dev/null +++ b/restx-demo/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,15 @@ + + + + restx + restx.servlet.RestxMainRouterServlet + 1 + + + restx + /api/* + + diff --git a/restx-demo/src/test/java/restx/demo/rest/HelloResourceSpecTest.java b/restx-demo/src/test/java/restx/demo/rest/HelloResourceSpecTest.java new file mode 100644 index 0000000000..138a22d074 --- /dev/null +++ b/restx-demo/src/test/java/restx/demo/rest/HelloResourceSpecTest.java @@ -0,0 +1,23 @@ +package restx.demo.rest; + +import restx.demo.AppServer; +import org.junit.runner.RunWith; +import restx.tests.RestxSpecTestsRunner; +import restx.tests.FindSpecsIn; + +@RunWith(RestxSpecTestsRunner.class) +@FindSpecsIn("specs/hello") +public class HelloResourceSpecTest { + + /** + * Useless, thanks to both @RunWith(RestxSpecTestsRunner.class) & @FindSpecsIn() + * + * @Rule + * public RestxSpecRule rule = new RestxSpecRule(); + * + * @Test + * public void test_spec() throws Exception { + * rule.runTest(specTestPath); + * } + */ +} diff --git a/restx-demo/src/test/resources/specs/hello/should_admin_say_hello.spec.yaml b/restx-demo/src/test/resources/specs/hello/should_admin_say_hello.spec.yaml new file mode 100644 index 0000000000..1b7b8f0f90 --- /dev/null +++ b/restx-demo/src/test/resources/specs/hello/should_admin_say_hello.spec.yaml @@ -0,0 +1,10 @@ +title: should admin say hello +given: + - time: 2013-08-28T01:18:00.822+02:00 + - uuids: [ "e2b4430f-9541-4602-9a3a-413d17c56a6b" ] +wts: + - when: | + GET message + $RestxSession: {"_expires":"2013-09-27T01:18:00.822+02:00","principal":"admin","sessionKey":"e2b4430f-9541-4602-9a3a-413d17c56a6b"} + then: | + {"message":"hello admin, it's 01:18:00"} diff --git a/restx-demo/src/test/resources/specs/hello/should_anyone_say_hello.spec.yaml b/restx-demo/src/test/resources/specs/hello/should_anyone_say_hello.spec.yaml new file mode 100644 index 0000000000..29b6faca34 --- /dev/null +++ b/restx-demo/src/test/resources/specs/hello/should_anyone_say_hello.spec.yaml @@ -0,0 +1,8 @@ +title: should admin say hello +given: + - time: 2013-08-28T01:18:00.822+02:00 +wts: + - when: | + GET hello?who=xavier + then: | + {"message":"hello xavier, it's 01:18:00"} diff --git a/restx-demo/src/test/resources/specs/hello/should_missing_value_triggers_validation_error.spec.yaml b/restx-demo/src/test/resources/specs/hello/should_missing_value_triggers_validation_error.spec.yaml new file mode 100644 index 0000000000..d0c6323caf --- /dev/null +++ b/restx-demo/src/test/resources/specs/hello/should_missing_value_triggers_validation_error.spec.yaml @@ -0,0 +1,17 @@ +title: should missing post value triggers a validation error +given: + - time: 2013-08-28T01:18:00.822+02:00 + - uuids: [ "e2b4430f-9541-4602-9a3a-413d17c56a6b" ] +wts: + - when: | + POST mypojo + $RestxSession: {"_expires":"2013-09-27T01:18:00.822+02:00","principal":"user1","sessionKey":"e2b4430f-9541-4602-9a3a-413d17c56a6b"} + {} + then: | + 400 + - when: | + POST mypojo + $RestxSession: {"_expires":"2013-09-27T01:18:00.822+02:00","principal":"user1","sessionKey":"e2b4430f-9541-4602-9a3a-413d17c56a6b"} + {"value":"world"} + then: | + {"value":"hello world"} diff --git a/restx-demo/src/test/resources/specs/hello/should_user1_say_hello.spec.yaml b/restx-demo/src/test/resources/specs/hello/should_user1_say_hello.spec.yaml new file mode 100644 index 0000000000..791a3a2776 --- /dev/null +++ b/restx-demo/src/test/resources/specs/hello/should_user1_say_hello.spec.yaml @@ -0,0 +1,10 @@ +title: should user1 say hello +given: + - time: 2013-08-28T01:18:00.822+02:00 + - uuids: [ "e2b4430f-9541-4602-9a3a-413d17c56a6b" ] +wts: + - when: | + GET message + $RestxSession: {"_expires":"2013-09-27T01:18:00.822+02:00","principal":"user1","sessionKey":"e2b4430f-9541-4602-9a3a-413d17c56a6b"} + then: | + {"message":"hello user1, it's 01:18:00"} diff --git a/restx-demo/src/test/resources/specs/hello/should_user2_not_say_hello.spec.yaml b/restx-demo/src/test/resources/specs/hello/should_user2_not_say_hello.spec.yaml new file mode 100644 index 0000000000..ead5af8d0c --- /dev/null +++ b/restx-demo/src/test/resources/specs/hello/should_user2_not_say_hello.spec.yaml @@ -0,0 +1,10 @@ +title: should user2 not say hello +given: + - time: 2013-08-28T01:19:44.770+02:00 + - uuids: [ "56f71fcc-42d3-422f-9458-8ad37fc4a0b5" ] +wts: + - when: | + GET message + $RestxSession: {"_expires":"2013-09-27T01:19:44.770+02:00","principal":"user2","sessionKey":"56f71fcc-42d3-422f-9458-8ad37fc4a0b5"} + then: | + 403 From 8037776d9d73e54a3ee0254ffeb20689b56a5a55 Mon Sep 17 00:00:00 2001 From: Markus Gulden Date: Sun, 28 Oct 2018 20:53:10 +0100 Subject: [PATCH 009/146] BAEL-1658 --- .../connect-file-sink.properties | 20 +++++ .../connect-file-source.properties | 20 +++++ .../connect-standalone.properties | 44 ++++++++++ .../connect-distributed.properties | 88 +++++++++++++++++++ .../02_Distributed/connect-file-sink.json | 9 ++ .../02_Distributed/connect-file-source.json | 9 ++ .../connect-distributed.properties | 88 +++++++++++++++++++ .../connect-file-source-transform.json | 15 ++++ .../04_Custom/connect-distributed.properties | 88 +++++++++++++++++++ .../04_Custom/connect-mongodb-sink.json | 22 +++++ .../04_Custom/connect-mqtt-source.json | 11 +++ 11 files changed, 414 insertions(+) create mode 100644 libraries-data/src/main/kafka-connect/01_Quick_Start/connect-file-sink.properties create mode 100644 libraries-data/src/main/kafka-connect/01_Quick_Start/connect-file-source.properties create mode 100644 libraries-data/src/main/kafka-connect/01_Quick_Start/connect-standalone.properties create mode 100644 libraries-data/src/main/kafka-connect/02_Distributed/connect-distributed.properties create mode 100644 libraries-data/src/main/kafka-connect/02_Distributed/connect-file-sink.json create mode 100644 libraries-data/src/main/kafka-connect/02_Distributed/connect-file-source.json create mode 100644 libraries-data/src/main/kafka-connect/03_Transform/connect-distributed.properties create mode 100644 libraries-data/src/main/kafka-connect/03_Transform/connect-file-source-transform.json create mode 100644 libraries-data/src/main/kafka-connect/04_Custom/connect-distributed.properties create mode 100644 libraries-data/src/main/kafka-connect/04_Custom/connect-mongodb-sink.json create mode 100644 libraries-data/src/main/kafka-connect/04_Custom/connect-mqtt-source.json diff --git a/libraries-data/src/main/kafka-connect/01_Quick_Start/connect-file-sink.properties b/libraries-data/src/main/kafka-connect/01_Quick_Start/connect-file-sink.properties new file mode 100644 index 0000000000..594ccc6e95 --- /dev/null +++ b/libraries-data/src/main/kafka-connect/01_Quick_Start/connect-file-sink.properties @@ -0,0 +1,20 @@ +# 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. + +name=local-file-sink +connector.class=FileStreamSink +tasks.max=1 +file=test.sink.txt +topics=connect-test \ No newline at end of file diff --git a/libraries-data/src/main/kafka-connect/01_Quick_Start/connect-file-source.properties b/libraries-data/src/main/kafka-connect/01_Quick_Start/connect-file-source.properties new file mode 100644 index 0000000000..599cf4cb2a --- /dev/null +++ b/libraries-data/src/main/kafka-connect/01_Quick_Start/connect-file-source.properties @@ -0,0 +1,20 @@ +# 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. + +name=local-file-source +connector.class=FileStreamSource +tasks.max=1 +file=test.txt +topic=connect-test \ No newline at end of file diff --git a/libraries-data/src/main/kafka-connect/01_Quick_Start/connect-standalone.properties b/libraries-data/src/main/kafka-connect/01_Quick_Start/connect-standalone.properties new file mode 100644 index 0000000000..a2369fa144 --- /dev/null +++ b/libraries-data/src/main/kafka-connect/01_Quick_Start/connect-standalone.properties @@ -0,0 +1,44 @@ +# 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. + +# These are defaults. This file just demonstrates how to override some settings. +bootstrap.servers=localhost:9092 + +# The converters specify the format of data in Kafka and how to translate it into Connect data. Every Connect user will +# need to configure these based on the format they want their data in when loaded from or stored into Kafka +key.converter=org.apache.kafka.connect.json.JsonConverter +value.converter=org.apache.kafka.connect.json.JsonConverter +# Converter-specific settings can be passed in by prefixing the Converter's setting with the converter we want to apply +# it to +key.converter.schemas.enable=false +value.converter.schemas.enable=false + +offset.storage.file.filename=/tmp/connect.offsets +# Flush much faster than normal, which is useful for testing/debugging +offset.flush.interval.ms=10000 + +# Set to a list of filesystem paths separated by commas (,) to enable class loading isolation for plugins +# (connectors, converters, transformations). The list should consist of top level directories that include +# any combination of: +# a) directories immediately containing jars with plugins and their dependencies +# b) uber-jars with plugins and their dependencies +# c) directories immediately containing the package directory structure of classes of plugins and their dependencies +# Note: symlinks will be followed to discover dependencies or plugins. +# Examples: +# plugin.path=/usr/local/share/java,/usr/local/share/kafka/plugins,/opt/connectors, +# Replace the relative path below with an absolute path if you are planning to start Kafka Connect from within a +# directory other than the home directory of Confluent Platform. +plugin.path=C:\Software\confluent-5.0.0\share\java +#plugin.path=./share/java diff --git a/libraries-data/src/main/kafka-connect/02_Distributed/connect-distributed.properties b/libraries-data/src/main/kafka-connect/02_Distributed/connect-distributed.properties new file mode 100644 index 0000000000..5b91baddbd --- /dev/null +++ b/libraries-data/src/main/kafka-connect/02_Distributed/connect-distributed.properties @@ -0,0 +1,88 @@ +## +# 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. +## + +# This file contains some of the configurations for the Kafka Connect distributed worker. This file is intended +# to be used with the examples, and some settings may differ from those used in a production system, especially +# the `bootstrap.servers` and those specifying replication factors. + +# A list of host/port pairs to use for establishing the initial connection to the Kafka cluster. +bootstrap.servers=localhost:9092 + +# unique name for the cluster, used in forming the Connect cluster group. Note that this must not conflict with consumer group IDs +group.id=connect-cluster + +# The converters specify the format of data in Kafka and how to translate it into Connect data. Every Connect user will +# need to configure these based on the format they want their data in when loaded from or stored into Kafka +key.converter=org.apache.kafka.connect.json.JsonConverter +value.converter=org.apache.kafka.connect.json.JsonConverter +# Converter-specific settings can be passed in by prefixing the Converter's setting with the converter we want to apply +# it to +key.converter.schemas.enable=true +value.converter.schemas.enable=true + +# Topic to use for storing offsets. This topic should have many partitions and be replicated and compacted. +# Kafka Connect will attempt to create the topic automatically when needed, but you can always manually create +# the topic before starting Kafka Connect if a specific topic configuration is needed. +# Most users will want to use the built-in default replication factor of 3 or in some cases even specify a larger value. +# Since this means there must be at least as many brokers as the maximum replication factor used, we'd like to be able +# to run this example on a single-broker cluster and so here we instead set the replication factor to 1. +offset.storage.topic=connect-offsets +offset.storage.replication.factor=1 +#offset.storage.partitions=25 + +# Topic to use for storing connector and task configurations; note that this should be a single partition, highly replicated, +# and compacted topic. Kafka Connect will attempt to create the topic automatically when needed, but you can always manually create +# the topic before starting Kafka Connect if a specific topic configuration is needed. +# Most users will want to use the built-in default replication factor of 3 or in some cases even specify a larger value. +# Since this means there must be at least as many brokers as the maximum replication factor used, we'd like to be able +# to run this example on a single-broker cluster and so here we instead set the replication factor to 1. +config.storage.topic=connect-configs +config.storage.replication.factor=1 + +# Topic to use for storing statuses. This topic can have multiple partitions and should be replicated and compacted. +# Kafka Connect will attempt to create the topic automatically when needed, but you can always manually create +# the topic before starting Kafka Connect if a specific topic configuration is needed. +# Most users will want to use the built-in default replication factor of 3 or in some cases even specify a larger value. +# Since this means there must be at least as many brokers as the maximum replication factor used, we'd like to be able +# to run this example on a single-broker cluster and so here we instead set the replication factor to 1. +status.storage.topic=connect-status +status.storage.replication.factor=1 +#status.storage.partitions=5 + +# Flush much faster than normal, which is useful for testing/debugging +offset.flush.interval.ms=10000 + +# These are provided to inform the user about the presence of the REST host and port configs +# Hostname & Port for the REST API to listen on. If this is set, it will bind to the interface used to listen to requests. +#rest.host.name= +#rest.port=8083 + +# The Hostname & Port that will be given out to other workers to connect to i.e. URLs that are routable from other servers. +#rest.advertised.host.name= +#rest.advertised.port= + +# Set to a list of filesystem paths separated by commas (,) to enable class loading isolation for plugins +# (connectors, converters, transformations). The list should consist of top level directories that include +# any combination of: +# a) directories immediately containing jars with plugins and their dependencies +# b) uber-jars with plugins and their dependencies +# c) directories immediately containing the package directory structure of classes of plugins and their dependencies +# Examples: +# plugin.path=/usr/local/share/java,/usr/local/share/kafka/plugins,/opt/connectors, +# Replace the relative path below with an absolute path if you are planning to start Kafka Connect from within a +# directory other than the home directory of Confluent Platform. +plugin.path=./share/java diff --git a/libraries-data/src/main/kafka-connect/02_Distributed/connect-file-sink.json b/libraries-data/src/main/kafka-connect/02_Distributed/connect-file-sink.json new file mode 100644 index 0000000000..8902ecce52 --- /dev/null +++ b/libraries-data/src/main/kafka-connect/02_Distributed/connect-file-sink.json @@ -0,0 +1,9 @@ +{ + "name": "local-file-sink", + "config": { + "connector.class": "FileStreamSink", + "tasks.max": 1, + "file": "test-distributed.sink.txt", + "topics": "connect-distributed" + } +} diff --git a/libraries-data/src/main/kafka-connect/02_Distributed/connect-file-source.json b/libraries-data/src/main/kafka-connect/02_Distributed/connect-file-source.json new file mode 100644 index 0000000000..77e949c91b --- /dev/null +++ b/libraries-data/src/main/kafka-connect/02_Distributed/connect-file-source.json @@ -0,0 +1,9 @@ +{ + "name": "local-file-source", + "config": { + "connector.class": "FileStreamSource", + "tasks.max": 1, + "file": "test-distributed.txt", + "topic": "connect-distributed" + } +} diff --git a/libraries-data/src/main/kafka-connect/03_Transform/connect-distributed.properties b/libraries-data/src/main/kafka-connect/03_Transform/connect-distributed.properties new file mode 100644 index 0000000000..fa63be24b8 --- /dev/null +++ b/libraries-data/src/main/kafka-connect/03_Transform/connect-distributed.properties @@ -0,0 +1,88 @@ +## +# 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. +## + +# This file contains some of the configurations for the Kafka Connect distributed worker. This file is intended +# to be used with the examples, and some settings may differ from those used in a production system, especially +# the `bootstrap.servers` and those specifying replication factors. + +# A list of host/port pairs to use for establishing the initial connection to the Kafka cluster. +bootstrap.servers=localhost:9092 + +# unique name for the cluster, used in forming the Connect cluster group. Note that this must not conflict with consumer group IDs +group.id=connect-cluster + +# The converters specify the format of data in Kafka and how to translate it into Connect data. Every Connect user will +# need to configure these based on the format they want their data in when loaded from or stored into Kafka +key.converter=org.apache.kafka.connect.json.JsonConverter +value.converter=org.apache.kafka.connect.json.JsonConverter +# Converter-specific settings can be passed in by prefixing the Converter's setting with the converter we want to apply +# it to +key.converter.schemas.enable=false +value.converter.schemas.enable=false + +# Topic to use for storing offsets. This topic should have many partitions and be replicated and compacted. +# Kafka Connect will attempt to create the topic automatically when needed, but you can always manually create +# the topic before starting Kafka Connect if a specific topic configuration is needed. +# Most users will want to use the built-in default replication factor of 3 or in some cases even specify a larger value. +# Since this means there must be at least as many brokers as the maximum replication factor used, we'd like to be able +# to run this example on a single-broker cluster and so here we instead set the replication factor to 1. +offset.storage.topic=connect-offsets +offset.storage.replication.factor=1 +#offset.storage.partitions=25 + +# Topic to use for storing connector and task configurations; note that this should be a single partition, highly replicated, +# and compacted topic. Kafka Connect will attempt to create the topic automatically when needed, but you can always manually create +# the topic before starting Kafka Connect if a specific topic configuration is needed. +# Most users will want to use the built-in default replication factor of 3 or in some cases even specify a larger value. +# Since this means there must be at least as many brokers as the maximum replication factor used, we'd like to be able +# to run this example on a single-broker cluster and so here we instead set the replication factor to 1. +config.storage.topic=connect-configs +config.storage.replication.factor=1 + +# Topic to use for storing statuses. This topic can have multiple partitions and should be replicated and compacted. +# Kafka Connect will attempt to create the topic automatically when needed, but you can always manually create +# the topic before starting Kafka Connect if a specific topic configuration is needed. +# Most users will want to use the built-in default replication factor of 3 or in some cases even specify a larger value. +# Since this means there must be at least as many brokers as the maximum replication factor used, we'd like to be able +# to run this example on a single-broker cluster and so here we instead set the replication factor to 1. +status.storage.topic=connect-status +status.storage.replication.factor=1 +#status.storage.partitions=5 + +# Flush much faster than normal, which is useful for testing/debugging +offset.flush.interval.ms=10000 + +# These are provided to inform the user about the presence of the REST host and port configs +# Hostname & Port for the REST API to listen on. If this is set, it will bind to the interface used to listen to requests. +#rest.host.name= +#rest.port=8083 + +# The Hostname & Port that will be given out to other workers to connect to i.e. URLs that are routable from other servers. +#rest.advertised.host.name= +#rest.advertised.port= + +# Set to a list of filesystem paths separated by commas (,) to enable class loading isolation for plugins +# (connectors, converters, transformations). The list should consist of top level directories that include +# any combination of: +# a) directories immediately containing jars with plugins and their dependencies +# b) uber-jars with plugins and their dependencies +# c) directories immediately containing the package directory structure of classes of plugins and their dependencies +# Examples: +# plugin.path=/usr/local/share/java,/usr/local/share/kafka/plugins,/opt/connectors, +# Replace the relative path below with an absolute path if you are planning to start Kafka Connect from within a +# directory other than the home directory of Confluent Platform. +plugin.path=./share/java diff --git a/libraries-data/src/main/kafka-connect/03_Transform/connect-file-source-transform.json b/libraries-data/src/main/kafka-connect/03_Transform/connect-file-source-transform.json new file mode 100644 index 0000000000..e5e21a0608 --- /dev/null +++ b/libraries-data/src/main/kafka-connect/03_Transform/connect-file-source-transform.json @@ -0,0 +1,15 @@ +{ + "name": "local-file-source", + "config": { + "connector.class": "FileStreamSource", + "tasks.max": 1, + "file": "transformation.txt", + "topic": "connect-transformation", + "transforms": "MakeMap,InsertSource", + "transforms.MakeMap.type": "org.apache.kafka.connect.transforms.HoistField$Value", + "transforms.MakeMap.field": "line", + "transforms.InsertSource.type": "org.apache.kafka.connect.transforms.InsertField$Value", + "transforms.InsertSource.static.field": "data_source", + "transforms.InsertSource.static.value": "test-file-source" + } +} diff --git a/libraries-data/src/main/kafka-connect/04_Custom/connect-distributed.properties b/libraries-data/src/main/kafka-connect/04_Custom/connect-distributed.properties new file mode 100644 index 0000000000..5b91baddbd --- /dev/null +++ b/libraries-data/src/main/kafka-connect/04_Custom/connect-distributed.properties @@ -0,0 +1,88 @@ +## +# 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. +## + +# This file contains some of the configurations for the Kafka Connect distributed worker. This file is intended +# to be used with the examples, and some settings may differ from those used in a production system, especially +# the `bootstrap.servers` and those specifying replication factors. + +# A list of host/port pairs to use for establishing the initial connection to the Kafka cluster. +bootstrap.servers=localhost:9092 + +# unique name for the cluster, used in forming the Connect cluster group. Note that this must not conflict with consumer group IDs +group.id=connect-cluster + +# The converters specify the format of data in Kafka and how to translate it into Connect data. Every Connect user will +# need to configure these based on the format they want their data in when loaded from or stored into Kafka +key.converter=org.apache.kafka.connect.json.JsonConverter +value.converter=org.apache.kafka.connect.json.JsonConverter +# Converter-specific settings can be passed in by prefixing the Converter's setting with the converter we want to apply +# it to +key.converter.schemas.enable=true +value.converter.schemas.enable=true + +# Topic to use for storing offsets. This topic should have many partitions and be replicated and compacted. +# Kafka Connect will attempt to create the topic automatically when needed, but you can always manually create +# the topic before starting Kafka Connect if a specific topic configuration is needed. +# Most users will want to use the built-in default replication factor of 3 or in some cases even specify a larger value. +# Since this means there must be at least as many brokers as the maximum replication factor used, we'd like to be able +# to run this example on a single-broker cluster and so here we instead set the replication factor to 1. +offset.storage.topic=connect-offsets +offset.storage.replication.factor=1 +#offset.storage.partitions=25 + +# Topic to use for storing connector and task configurations; note that this should be a single partition, highly replicated, +# and compacted topic. Kafka Connect will attempt to create the topic automatically when needed, but you can always manually create +# the topic before starting Kafka Connect if a specific topic configuration is needed. +# Most users will want to use the built-in default replication factor of 3 or in some cases even specify a larger value. +# Since this means there must be at least as many brokers as the maximum replication factor used, we'd like to be able +# to run this example on a single-broker cluster and so here we instead set the replication factor to 1. +config.storage.topic=connect-configs +config.storage.replication.factor=1 + +# Topic to use for storing statuses. This topic can have multiple partitions and should be replicated and compacted. +# Kafka Connect will attempt to create the topic automatically when needed, but you can always manually create +# the topic before starting Kafka Connect if a specific topic configuration is needed. +# Most users will want to use the built-in default replication factor of 3 or in some cases even specify a larger value. +# Since this means there must be at least as many brokers as the maximum replication factor used, we'd like to be able +# to run this example on a single-broker cluster and so here we instead set the replication factor to 1. +status.storage.topic=connect-status +status.storage.replication.factor=1 +#status.storage.partitions=5 + +# Flush much faster than normal, which is useful for testing/debugging +offset.flush.interval.ms=10000 + +# These are provided to inform the user about the presence of the REST host and port configs +# Hostname & Port for the REST API to listen on. If this is set, it will bind to the interface used to listen to requests. +#rest.host.name= +#rest.port=8083 + +# The Hostname & Port that will be given out to other workers to connect to i.e. URLs that are routable from other servers. +#rest.advertised.host.name= +#rest.advertised.port= + +# Set to a list of filesystem paths separated by commas (,) to enable class loading isolation for plugins +# (connectors, converters, transformations). The list should consist of top level directories that include +# any combination of: +# a) directories immediately containing jars with plugins and their dependencies +# b) uber-jars with plugins and their dependencies +# c) directories immediately containing the package directory structure of classes of plugins and their dependencies +# Examples: +# plugin.path=/usr/local/share/java,/usr/local/share/kafka/plugins,/opt/connectors, +# Replace the relative path below with an absolute path if you are planning to start Kafka Connect from within a +# directory other than the home directory of Confluent Platform. +plugin.path=./share/java diff --git a/libraries-data/src/main/kafka-connect/04_Custom/connect-mongodb-sink.json b/libraries-data/src/main/kafka-connect/04_Custom/connect-mongodb-sink.json new file mode 100644 index 0000000000..333768e4b7 --- /dev/null +++ b/libraries-data/src/main/kafka-connect/04_Custom/connect-mongodb-sink.json @@ -0,0 +1,22 @@ +{ + "firstName": "John", + "lastName": "Smith", + "age": 25, + "address": { + "streetAddress": "21 2nd Street", + "city": "New York", + "state": "NY", + "postalCode": "10021" + }, + "phoneNumber": [{ + "type": "home", + "number": "212 555-1234" + }, { + "type": "fax", + "number": "646 555-4567" + } + ], + "gender": { + "type": "male" + } +} diff --git a/libraries-data/src/main/kafka-connect/04_Custom/connect-mqtt-source.json b/libraries-data/src/main/kafka-connect/04_Custom/connect-mqtt-source.json new file mode 100644 index 0000000000..02d87c5ad7 --- /dev/null +++ b/libraries-data/src/main/kafka-connect/04_Custom/connect-mqtt-source.json @@ -0,0 +1,11 @@ +{ + "name": "mqtt-source", + "config": { + "connector.class": "io.confluent.connect.mqtt.MqttSourceConnector", + "tasks.max": 1, + "mqtt.server.uri": "ws://broker.hivemq.com:8000/mqtt", + "mqtt.topics": "baeldung", + "kafka.topic": "connect-custom", + "value.converter": "org.apache.kafka.connect.converters.ByteArrayConverter" + } +} From aedf3b5cb570d0aba8cad215f4a40da9ba956623 Mon Sep 17 00:00:00 2001 From: Simon Massey Date: Tue, 30 Oct 2018 22:47:38 +0000 Subject: [PATCH 010/146] removed race condition between different requests --- .../thymeleaf/controller/BookController.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/controller/BookController.java b/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/controller/BookController.java index b8132cddc8..12e8e8bc41 100644 --- a/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/controller/BookController.java +++ b/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/controller/BookController.java @@ -2,6 +2,7 @@ package com.baeldung.thymeleaf.controller; import java.util.List; import java.util.Optional; +import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; import java.util.stream.IntStream; @@ -21,18 +22,18 @@ import com.baeldung.thymeleaf.service.BookService; @Controller public class BookController { - private static int currentPage = 1; - private static int pageSize = 5; @Autowired private BookService bookService; - + @RequestMapping(value = "/listBooks", method = RequestMethod.GET) public String listBooks(Model model, @RequestParam("page") Optional page, @RequestParam("size") Optional size) { - page.ifPresent(p -> currentPage = p); - size.ifPresent(s -> pageSize = s); + AtomicInteger currentPage = new AtomicInteger(1); + AtomicInteger pageSize = new AtomicInteger(5); + page.ifPresent(p -> currentPage.set(p)); + size.ifPresent(s -> pageSize.set(s)); - Page bookPage = bookService.findPaginated(PageRequest.of(currentPage - 1, pageSize)); + Page bookPage = bookService.findPaginated(PageRequest.of(currentPage.get() - 1, pageSize.get())); model.addAttribute("bookPage", bookPage); From e3fc47dd53de5cd1f8c6e5175aaff175daa9e974 Mon Sep 17 00:00:00 2001 From: Simon Massey Date: Tue, 30 Oct 2018 22:57:04 +0000 Subject: [PATCH 011/146] use of atomics way too verbose --- .../baeldung/thymeleaf/controller/BookController.java | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/controller/BookController.java b/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/controller/BookController.java index 12e8e8bc41..7ede80b01d 100644 --- a/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/controller/BookController.java +++ b/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/controller/BookController.java @@ -2,7 +2,6 @@ package com.baeldung.thymeleaf.controller; import java.util.List; import java.util.Optional; -import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; import java.util.stream.IntStream; @@ -22,18 +21,15 @@ import com.baeldung.thymeleaf.service.BookService; @Controller public class BookController { - @Autowired private BookService bookService; @RequestMapping(value = "/listBooks", method = RequestMethod.GET) public String listBooks(Model model, @RequestParam("page") Optional page, @RequestParam("size") Optional size) { - AtomicInteger currentPage = new AtomicInteger(1); - AtomicInteger pageSize = new AtomicInteger(5); - page.ifPresent(p -> currentPage.set(p)); - size.ifPresent(s -> pageSize.set(s)); + int currentPage = page.isPresent()?page.get():5; + int pageSize = size.isPresent()?size.get():1; - Page bookPage = bookService.findPaginated(PageRequest.of(currentPage.get() - 1, pageSize.get())); + Page bookPage = bookService.findPaginated(PageRequest.of(currentPage - 1, pageSize)); model.addAttribute("bookPage", bookPage); From 9663cc09a1d32ec338044c3d61ecd3a7289608d1 Mon Sep 17 00:00:00 2001 From: Simon Massey Date: Tue, 30 Oct 2018 23:03:08 +0000 Subject: [PATCH 012/146] orElse is cleaner --- .../com/baeldung/thymeleaf/controller/BookController.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/controller/BookController.java b/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/controller/BookController.java index 7ede80b01d..f30ae6e049 100644 --- a/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/controller/BookController.java +++ b/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/controller/BookController.java @@ -26,8 +26,8 @@ public class BookController { @RequestMapping(value = "/listBooks", method = RequestMethod.GET) public String listBooks(Model model, @RequestParam("page") Optional page, @RequestParam("size") Optional size) { - int currentPage = page.isPresent()?page.get():5; - int pageSize = size.isPresent()?size.get():1; + int currentPage = page.orElse(1); + int pageSize = size.orElse(5); Page bookPage = bookService.findPaginated(PageRequest.of(currentPage - 1, pageSize)); From 5d4d8ff977bf16874e475f9b7dc537140391a23f Mon Sep 17 00:00:00 2001 From: Simon Massey Date: Tue, 30 Oct 2018 23:06:12 +0000 Subject: [PATCH 013/146] may as well use final --- .../com/baeldung/thymeleaf/controller/BookController.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/controller/BookController.java b/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/controller/BookController.java index f30ae6e049..d10caee9e7 100644 --- a/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/controller/BookController.java +++ b/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/controller/BookController.java @@ -26,8 +26,8 @@ public class BookController { @RequestMapping(value = "/listBooks", method = RequestMethod.GET) public String listBooks(Model model, @RequestParam("page") Optional page, @RequestParam("size") Optional size) { - int currentPage = page.orElse(1); - int pageSize = size.orElse(5); + final int currentPage = page.orElse(1); + final int pageSize = size.orElse(5); Page bookPage = bookService.findPaginated(PageRequest.of(currentPage - 1, pageSize)); From 192c9443bd5ae800288a7dfaddae4e489fae471f Mon Sep 17 00:00:00 2001 From: Kevin Gilmore Date: Sun, 4 Nov 2018 13:04:05 -0600 Subject: [PATCH 014/146] BAEL-2015: add link back to article --- core-java/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java/README.md b/core-java/README.md index ce2d5b3e64..35fdcd9132 100644 --- a/core-java/README.md +++ b/core-java/README.md @@ -156,3 +156,4 @@ - [The Modulo Operator in Java](https://www.baeldung.com/modulo-java) - [Ternary Operator In Java](https://www.baeldung.com/java-ternary-operator) - [Merging java.util.Properties Objects](https://www.baeldung.com/java-merging-properties) +- [Understanding Memory Leaks in Java](https://www.baeldung.com/java-memory-leaks) From 8d745e684e6c40e425ddcc6e509e1d15584764c0 Mon Sep 17 00:00:00 2001 From: Marcos Lopez Gonzalez Date: Mon, 12 Nov 2018 19:54:39 +0100 Subject: [PATCH 015/146] DummyEntity renamed to Message --- .../{DummyEntity.java => Message.java} | 9 ++++----- .../src/main/resources/META-INF/persistence.xml | 2 +- .../jpa/stringcast/SpringCastUnitTest.java | 17 +++++++---------- .../java-jpa/src/test/resources/persistence.xml | 2 +- 4 files changed, 13 insertions(+), 17 deletions(-) rename persistence-modules/java-jpa/src/main/java/com/baeldung/jpa/stringcast/{DummyEntity.java => Message.java} (76%) diff --git a/persistence-modules/java-jpa/src/main/java/com/baeldung/jpa/stringcast/DummyEntity.java b/persistence-modules/java-jpa/src/main/java/com/baeldung/jpa/stringcast/Message.java similarity index 76% rename from persistence-modules/java-jpa/src/main/java/com/baeldung/jpa/stringcast/DummyEntity.java rename to persistence-modules/java-jpa/src/main/java/com/baeldung/jpa/stringcast/Message.java index 12b57ff112..fb521cfea6 100644 --- a/persistence-modules/java-jpa/src/main/java/com/baeldung/jpa/stringcast/DummyEntity.java +++ b/persistence-modules/java-jpa/src/main/java/com/baeldung/jpa/stringcast/Message.java @@ -3,13 +3,12 @@ package com.baeldung.jpa.stringcast; import javax.persistence.*; @SqlResultSetMapping(name = "textQueryMapping", classes = { - @ConstructorResult(targetClass = DummyEntity.class, columns = { + @ConstructorResult(targetClass = Message.class, columns = { @ColumnResult(name = "text") }) }) @Entity -@Table(name = "dummy") -public class DummyEntity { +public class Message { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @@ -17,11 +16,11 @@ public class DummyEntity { private String text; - public DummyEntity() { + public Message() { } - public DummyEntity(String text) { + public Message(String text) { this.text = text; } diff --git a/persistence-modules/java-jpa/src/main/resources/META-INF/persistence.xml b/persistence-modules/java-jpa/src/main/resources/META-INF/persistence.xml index 6345e7f364..3fdc8ce27c 100644 --- a/persistence-modules/java-jpa/src/main/resources/META-INF/persistence.xml +++ b/persistence-modules/java-jpa/src/main/resources/META-INF/persistence.xml @@ -23,7 +23,7 @@ org.hibernate.jpa.HibernatePersistenceProvider - com.baeldung.jpa.stringcast.DummyEntity + com.baeldung.jpa.stringcast.Message diff --git a/persistence-modules/java-jpa/src/test/java/com/baeldung/jpa/stringcast/SpringCastUnitTest.java b/persistence-modules/java-jpa/src/test/java/com/baeldung/jpa/stringcast/SpringCastUnitTest.java index d9c3adef26..0a11725fc3 100644 --- a/persistence-modules/java-jpa/src/test/java/com/baeldung/jpa/stringcast/SpringCastUnitTest.java +++ b/persistence-modules/java-jpa/src/test/java/com/baeldung/jpa/stringcast/SpringCastUnitTest.java @@ -3,10 +3,7 @@ package com.baeldung.jpa.stringcast; import org.junit.BeforeClass; import org.junit.Test; -import javax.persistence.EntityManager; -import javax.persistence.EntityManagerFactory; -import javax.persistence.EntityTransaction; -import javax.persistence.Persistence; +import javax.persistence.*; import java.util.List; import static org.junit.Assert.assertEquals; @@ -22,18 +19,18 @@ public class SpringCastUnitTest { em = emFactory.createEntityManager(); // insert an object into the db - DummyEntity dummyEntity = new DummyEntity(); - dummyEntity.setText("text"); + Message message = new Message(); + message.setText("text"); EntityTransaction tr = em.getTransaction(); tr.begin(); - em.persist(dummyEntity); + em.persist(message); tr.commit(); } @Test(expected = ClassCastException.class) public void givenExecutorNoCastCheck_whenQueryReturnsOneColumn_thenClassCastThrown() { - List results = QueryExecutor.executeNativeQueryNoCastCheck("select text from dummy", em); + List results = QueryExecutor.executeNativeQueryNoCastCheck("select text from message", em); // fails for (String[] row : results) { @@ -43,13 +40,13 @@ public class SpringCastUnitTest { @Test public void givenExecutorWithCastCheck_whenQueryReturnsOneColumn_thenNoClassCastThrown() { - List results = QueryExecutor.executeNativeQueryWithCastCheck("select text from dummy", em); + List results = QueryExecutor.executeNativeQueryWithCastCheck("select text from message", em); assertEquals("text", results.get(0)[0]); } @Test public void givenExecutorGeneric_whenQueryReturnsOneColumn_thenNoClassCastThrown() { - List results = QueryExecutor.executeNativeQueryGeneric("select text from dummy", "textQueryMapping", em); + List results = QueryExecutor.executeNativeQueryGeneric("select text from message", "textQueryMapping", em); assertEquals("text", results.get(0).getText()); } diff --git a/persistence-modules/java-jpa/src/test/resources/persistence.xml b/persistence-modules/java-jpa/src/test/resources/persistence.xml index b6cc51c3b3..c902e0a320 100644 --- a/persistence-modules/java-jpa/src/test/resources/persistence.xml +++ b/persistence-modules/java-jpa/src/test/resources/persistence.xml @@ -20,7 +20,7 @@ org.hibernate.jpa.HibernatePersistenceProvider - com.baeldung.jpa.stringcast.DummyEntity + com.baeldung.jpa.stringcast.Message From 7baa99bc34483f1d248ae21520590fdd938da9d5 Mon Sep 17 00:00:00 2001 From: amit2103 Date: Sun, 18 Nov 2018 18:05:41 +0530 Subject: [PATCH 016/146] [BAEL-10135] - Updated graphql code with latest version --- spring-boot/pom.xml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/spring-boot/pom.xml b/spring-boot/pom.xml index f16460b7c3..ac9873a770 100644 --- a/spring-boot/pom.xml +++ b/spring-boot/pom.xml @@ -70,6 +70,11 @@ graphql-java-tools ${graphql-java-tools.version} + + com.graphql-java + graphiql-spring-boot-starter + ${graphiql-spring-boot-starter.version} + org.springframework.boot @@ -220,8 +225,9 @@ 2.4.1.Final 1.9.0 2.0.0 - 3.6.0 - 3.2.0 + 5.0.2 + 5.0.2 + 5.2.4 18.0 2.2.4 From a98df2add7bb73f10d7a40253c24fe6d5a1ff96d Mon Sep 17 00:00:00 2001 From: amit2103 Date: Sun, 18 Nov 2018 20:09:03 +0530 Subject: [PATCH 017/146] [BAEL-10218] - Updated code to the latest version and modified code --- grpc/pom.xml | 6 +++--- grpc/src/main/java/org/baeldung/grpc/client/GrpcClient.java | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/grpc/pom.xml b/grpc/pom.xml index 949f26d376..bbdfe9bfb2 100644 --- a/grpc/pom.xml +++ b/grpc/pom.xml @@ -71,9 +71,9 @@ - 1.5.0 - 1.5.0.Final - 0.5.0 + 1.16.1 + 1.6.1 + 0.6.1 diff --git a/grpc/src/main/java/org/baeldung/grpc/client/GrpcClient.java b/grpc/src/main/java/org/baeldung/grpc/client/GrpcClient.java index 1a1809387f..f653e17910 100644 --- a/grpc/src/main/java/org/baeldung/grpc/client/GrpcClient.java +++ b/grpc/src/main/java/org/baeldung/grpc/client/GrpcClient.java @@ -10,7 +10,7 @@ import io.grpc.ManagedChannelBuilder; public class GrpcClient { public static void main(String[] args) throws InterruptedException { ManagedChannel channel = ManagedChannelBuilder.forAddress("localhost", 8080) - .usePlaintext(true) + .usePlaintext() .build(); HelloServiceGrpc.HelloServiceBlockingStub stub From ea1b7c45d4db33cb41774239bca534b565176376 Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Sun, 18 Nov 2018 19:54:11 +0200 Subject: [PATCH 018/146] Update pom.xml --- grpc/pom.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/grpc/pom.xml b/grpc/pom.xml index bbdfe9bfb2..725bec3e70 100644 --- a/grpc/pom.xml +++ b/grpc/pom.xml @@ -75,5 +75,4 @@ 1.6.1 0.6.1 - From cc48f3bdcf11d44c3e5c1bce100085dbd3592523 Mon Sep 17 00:00:00 2001 From: Loredana Date: Sun, 18 Nov 2018 20:07:29 +0200 Subject: [PATCH 019/146] update guava rangemap --- .../java/org/baeldung/guava/GuavaRangeMapUnitTest.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/guava-collections/src/test/java/org/baeldung/guava/GuavaRangeMapUnitTest.java b/guava-collections/src/test/java/org/baeldung/guava/GuavaRangeMapUnitTest.java index 81ba72373c..67a7d6a1f7 100644 --- a/guava-collections/src/test/java/org/baeldung/guava/GuavaRangeMapUnitTest.java +++ b/guava-collections/src/test/java/org/baeldung/guava/GuavaRangeMapUnitTest.java @@ -2,6 +2,9 @@ package org.baeldung.guava; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import java.util.Arrays; import java.util.Map; import org.junit.Test; import com.google.common.collect.ImmutableRangeMap; @@ -98,8 +101,8 @@ public class GuavaRangeMapUnitTest { final RangeMap experiencedSubRangeDesignationMap = experienceRangeDesignationMap.subRangeMap(Range.closed(4, 14)); assertNull(experiencedSubRangeDesignationMap.get(3)); - assertEquals("Executive Director", experiencedSubRangeDesignationMap.get(14)); - assertEquals("Vice President", experiencedSubRangeDesignationMap.get(7)); + assertTrue(experiencedSubRangeDesignationMap.asMapOfRanges().values().containsAll(Arrays.asList("Executive Director", "Vice President", "Executive Director"))); + } @Test From dad9467f97b8fac1a9d77ba0d53270320e40cbf2 Mon Sep 17 00:00:00 2001 From: Loredana Date: Sun, 18 Nov 2018 20:09:39 +0200 Subject: [PATCH 020/146] fix formatting --- .../test/java/org/baeldung/guava/GuavaRangeMapUnitTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/guava-collections/src/test/java/org/baeldung/guava/GuavaRangeMapUnitTest.java b/guava-collections/src/test/java/org/baeldung/guava/GuavaRangeMapUnitTest.java index 67a7d6a1f7..c0c5efea23 100644 --- a/guava-collections/src/test/java/org/baeldung/guava/GuavaRangeMapUnitTest.java +++ b/guava-collections/src/test/java/org/baeldung/guava/GuavaRangeMapUnitTest.java @@ -101,7 +101,8 @@ public class GuavaRangeMapUnitTest { final RangeMap experiencedSubRangeDesignationMap = experienceRangeDesignationMap.subRangeMap(Range.closed(4, 14)); assertNull(experiencedSubRangeDesignationMap.get(3)); - assertTrue(experiencedSubRangeDesignationMap.asMapOfRanges().values().containsAll(Arrays.asList("Executive Director", "Vice President", "Executive Director"))); + assertTrue(experiencedSubRangeDesignationMap.asMapOfRanges().values() + .containsAll(Arrays.asList("Executive Director", "Vice President", "Executive Director"))); } From 96d121bcae0f7925c6077c2299473a03ae6b8514 Mon Sep 17 00:00:00 2001 From: amit2103 Date: Mon, 19 Nov 2018 00:04:52 +0530 Subject: [PATCH 021/146] [BAEL-9712] - Created spring-5-security-oauth module --- pom.xml | 4 ++ spring-5-security-oauth/README.md | 3 + spring-5-security-oauth/pom.xml | 68 +++++++++++++++++++ .../com/baeldung/oauth2/LoginController.java | 0 .../java/com/baeldung/oauth2/MvcConfig.java | 0 .../com/baeldung/oauth2/SecurityConfig.java | 4 +- .../oauth2/SpringOAuthApplication.java | 0 .../ExtractorsApplication.java | 0 .../configuration/SecurityConfig.java | 0 .../custom/BaeldungAuthoritiesExtractor.java | 0 .../custom/BaeldungPrincipalExtractor.java | 0 .../github/GithubAuthoritiesExtractor.java | 0 .../github/GithubPrincipalExtractor.java | 0 ...tion-oauth2-extractors-baeldung.properties | 0 ...cation-oauth2-extractors-github.properties | 0 .../resources/application-oauth2.properties | 0 .../src/main/resources/application.properties | 5 ++ .../src/main/resources/logback.xml | 13 ++++ .../src/main/resources/static/css/main.css | 8 +++ .../src/main/resources/templates/index.html | 11 +++ .../resources/templates/loginFailure.html | 0 .../resources/templates/loginSuccess.html | 0 .../templates/oauth2_extractors.html | 0 .../main/resources/templates/oauth_login.html | 0 .../main/resources/templates/securedPage.html | 0 .../oauth2extractors/ExtractorsUnitTest.java | 0 spring-5-security/README.md | 1 - spring-5-security/pom.xml | 15 ---- 28 files changed, 114 insertions(+), 18 deletions(-) create mode 100644 spring-5-security-oauth/README.md create mode 100644 spring-5-security-oauth/pom.xml rename {spring-5-security => spring-5-security-oauth}/src/main/java/com/baeldung/oauth2/LoginController.java (100%) rename {spring-5-security => spring-5-security-oauth}/src/main/java/com/baeldung/oauth2/MvcConfig.java (100%) rename {spring-5-security => spring-5-security-oauth}/src/main/java/com/baeldung/oauth2/SecurityConfig.java (95%) rename {spring-5-security => spring-5-security-oauth}/src/main/java/com/baeldung/oauth2/SpringOAuthApplication.java (100%) rename {spring-5-security => spring-5-security-oauth}/src/main/java/com/baeldung/oauth2extractors/ExtractorsApplication.java (100%) rename {spring-5-security => spring-5-security-oauth}/src/main/java/com/baeldung/oauth2extractors/configuration/SecurityConfig.java (100%) rename {spring-5-security => spring-5-security-oauth}/src/main/java/com/baeldung/oauth2extractors/extractor/custom/BaeldungAuthoritiesExtractor.java (100%) rename {spring-5-security => spring-5-security-oauth}/src/main/java/com/baeldung/oauth2extractors/extractor/custom/BaeldungPrincipalExtractor.java (100%) rename {spring-5-security => spring-5-security-oauth}/src/main/java/com/baeldung/oauth2extractors/extractor/github/GithubAuthoritiesExtractor.java (100%) rename {spring-5-security => spring-5-security-oauth}/src/main/java/com/baeldung/oauth2extractors/extractor/github/GithubPrincipalExtractor.java (100%) rename {spring-5-security => spring-5-security-oauth}/src/main/resources/application-oauth2-extractors-baeldung.properties (100%) rename {spring-5-security => spring-5-security-oauth}/src/main/resources/application-oauth2-extractors-github.properties (100%) rename {spring-5-security => spring-5-security-oauth}/src/main/resources/application-oauth2.properties (100%) create mode 100644 spring-5-security-oauth/src/main/resources/application.properties create mode 100644 spring-5-security-oauth/src/main/resources/logback.xml create mode 100644 spring-5-security-oauth/src/main/resources/static/css/main.css create mode 100644 spring-5-security-oauth/src/main/resources/templates/index.html rename {spring-5-security => spring-5-security-oauth}/src/main/resources/templates/loginFailure.html (100%) rename {spring-5-security => spring-5-security-oauth}/src/main/resources/templates/loginSuccess.html (100%) rename {spring-5-security => spring-5-security-oauth}/src/main/resources/templates/oauth2_extractors.html (100%) rename {spring-5-security => spring-5-security-oauth}/src/main/resources/templates/oauth_login.html (100%) rename {spring-5-security => spring-5-security-oauth}/src/main/resources/templates/securedPage.html (100%) rename {spring-5-security => spring-5-security-oauth}/src/test/java/com/baeldung/oauth2extractors/ExtractorsUnitTest.java (100%) diff --git a/pom.xml b/pom.xml index 5ebf7ba4f3..0997d7ce88 100644 --- a/pom.xml +++ b/pom.xml @@ -466,6 +466,7 @@ spring-5-reactive-client spring-5-mvc spring-5-security + spring-5-security-oauth spring-5-reactive-oauth spring-activiti spring-akka @@ -768,6 +769,7 @@ spring-5-reactive-client spring-5-reactive-security spring-5-security + spring-5-security-oauth spring-activiti spring-akka spring-all @@ -994,6 +996,7 @@ spring-5-reactive-client spring-5-mvc spring-5-security + spring-5-security-oauth spring-activiti spring-akka spring-amqp @@ -1385,6 +1388,7 @@ spring-5-reactive-client spring-5-mvc spring-5-security + spring-5-security-oauth spring-activiti spring-akka spring-amqp diff --git a/spring-5-security-oauth/README.md b/spring-5-security-oauth/README.md new file mode 100644 index 0000000000..81d95c07d7 --- /dev/null +++ b/spring-5-security-oauth/README.md @@ -0,0 +1,3 @@ +## Relevant articles: + +- [Spring Security 5 -OAuth2 Login](http://www.baeldung.com/spring-security-5-oauth2-login) \ No newline at end of file diff --git a/spring-5-security-oauth/pom.xml b/spring-5-security-oauth/pom.xml new file mode 100644 index 0000000000..a741daaa18 --- /dev/null +++ b/spring-5-security-oauth/pom.xml @@ -0,0 +1,68 @@ + + 4.0.0 + com.baeldung + spring-5-security-oauth + 0.0.1-SNAPSHOT + jar + spring-5-security-oauth + spring 5 security oauth sample project + + + com.baeldung + parent-boot-2 + 0.0.1-SNAPSHOT + ../parent-boot-2 + + + + + + org.springframework.boot + spring-boot-starter-security + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-thymeleaf + + + org.thymeleaf.extras + thymeleaf-extras-springsecurity5 + + + + + org.springframework.security.oauth.boot + spring-security-oauth2-autoconfigure + ${oauth-auto.version} + + + org.springframework.security + spring-security-oauth2-client + + + org.springframework.security + spring-security-oauth2-jose + + + + org.springframework + spring-test + + + org.springframework.boot + spring-boot-starter-test + test + + + org.springframework.security + spring-security-test + test + + + + diff --git a/spring-5-security/src/main/java/com/baeldung/oauth2/LoginController.java b/spring-5-security-oauth/src/main/java/com/baeldung/oauth2/LoginController.java similarity index 100% rename from spring-5-security/src/main/java/com/baeldung/oauth2/LoginController.java rename to spring-5-security-oauth/src/main/java/com/baeldung/oauth2/LoginController.java diff --git a/spring-5-security/src/main/java/com/baeldung/oauth2/MvcConfig.java b/spring-5-security-oauth/src/main/java/com/baeldung/oauth2/MvcConfig.java similarity index 100% rename from spring-5-security/src/main/java/com/baeldung/oauth2/MvcConfig.java rename to spring-5-security-oauth/src/main/java/com/baeldung/oauth2/MvcConfig.java diff --git a/spring-5-security/src/main/java/com/baeldung/oauth2/SecurityConfig.java b/spring-5-security-oauth/src/main/java/com/baeldung/oauth2/SecurityConfig.java similarity index 95% rename from spring-5-security/src/main/java/com/baeldung/oauth2/SecurityConfig.java rename to spring-5-security-oauth/src/main/java/com/baeldung/oauth2/SecurityConfig.java index b45f325767..e08057d92f 100644 --- a/spring-5-security/src/main/java/com/baeldung/oauth2/SecurityConfig.java +++ b/spring-5-security-oauth/src/main/java/com/baeldung/oauth2/SecurityConfig.java @@ -12,7 +12,7 @@ import org.springframework.core.env.Environment; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; import org.springframework.security.config.oauth2.client.CommonOAuth2Provider; -import org.springframework.security.oauth2.client.endpoint.NimbusAuthorizationCodeTokenResponseClient; +import org.springframework.security.oauth2.client.endpoint.DefaultAuthorizationCodeTokenResponseClient; import org.springframework.security.oauth2.client.endpoint.OAuth2AccessTokenResponseClient; import org.springframework.security.oauth2.client.endpoint.OAuth2AuthorizationCodeGrantRequest; import org.springframework.security.oauth2.client.registration.ClientRegistration; @@ -54,7 +54,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter { @Bean public OAuth2AccessTokenResponseClient accessTokenResponseClient() { - return new NimbusAuthorizationCodeTokenResponseClient(); + return new DefaultAuthorizationCodeTokenResponseClient(); } diff --git a/spring-5-security/src/main/java/com/baeldung/oauth2/SpringOAuthApplication.java b/spring-5-security-oauth/src/main/java/com/baeldung/oauth2/SpringOAuthApplication.java similarity index 100% rename from spring-5-security/src/main/java/com/baeldung/oauth2/SpringOAuthApplication.java rename to spring-5-security-oauth/src/main/java/com/baeldung/oauth2/SpringOAuthApplication.java diff --git a/spring-5-security/src/main/java/com/baeldung/oauth2extractors/ExtractorsApplication.java b/spring-5-security-oauth/src/main/java/com/baeldung/oauth2extractors/ExtractorsApplication.java similarity index 100% rename from spring-5-security/src/main/java/com/baeldung/oauth2extractors/ExtractorsApplication.java rename to spring-5-security-oauth/src/main/java/com/baeldung/oauth2extractors/ExtractorsApplication.java diff --git a/spring-5-security/src/main/java/com/baeldung/oauth2extractors/configuration/SecurityConfig.java b/spring-5-security-oauth/src/main/java/com/baeldung/oauth2extractors/configuration/SecurityConfig.java similarity index 100% rename from spring-5-security/src/main/java/com/baeldung/oauth2extractors/configuration/SecurityConfig.java rename to spring-5-security-oauth/src/main/java/com/baeldung/oauth2extractors/configuration/SecurityConfig.java diff --git a/spring-5-security/src/main/java/com/baeldung/oauth2extractors/extractor/custom/BaeldungAuthoritiesExtractor.java b/spring-5-security-oauth/src/main/java/com/baeldung/oauth2extractors/extractor/custom/BaeldungAuthoritiesExtractor.java similarity index 100% rename from spring-5-security/src/main/java/com/baeldung/oauth2extractors/extractor/custom/BaeldungAuthoritiesExtractor.java rename to spring-5-security-oauth/src/main/java/com/baeldung/oauth2extractors/extractor/custom/BaeldungAuthoritiesExtractor.java diff --git a/spring-5-security/src/main/java/com/baeldung/oauth2extractors/extractor/custom/BaeldungPrincipalExtractor.java b/spring-5-security-oauth/src/main/java/com/baeldung/oauth2extractors/extractor/custom/BaeldungPrincipalExtractor.java similarity index 100% rename from spring-5-security/src/main/java/com/baeldung/oauth2extractors/extractor/custom/BaeldungPrincipalExtractor.java rename to spring-5-security-oauth/src/main/java/com/baeldung/oauth2extractors/extractor/custom/BaeldungPrincipalExtractor.java diff --git a/spring-5-security/src/main/java/com/baeldung/oauth2extractors/extractor/github/GithubAuthoritiesExtractor.java b/spring-5-security-oauth/src/main/java/com/baeldung/oauth2extractors/extractor/github/GithubAuthoritiesExtractor.java similarity index 100% rename from spring-5-security/src/main/java/com/baeldung/oauth2extractors/extractor/github/GithubAuthoritiesExtractor.java rename to spring-5-security-oauth/src/main/java/com/baeldung/oauth2extractors/extractor/github/GithubAuthoritiesExtractor.java diff --git a/spring-5-security/src/main/java/com/baeldung/oauth2extractors/extractor/github/GithubPrincipalExtractor.java b/spring-5-security-oauth/src/main/java/com/baeldung/oauth2extractors/extractor/github/GithubPrincipalExtractor.java similarity index 100% rename from spring-5-security/src/main/java/com/baeldung/oauth2extractors/extractor/github/GithubPrincipalExtractor.java rename to spring-5-security-oauth/src/main/java/com/baeldung/oauth2extractors/extractor/github/GithubPrincipalExtractor.java diff --git a/spring-5-security/src/main/resources/application-oauth2-extractors-baeldung.properties b/spring-5-security-oauth/src/main/resources/application-oauth2-extractors-baeldung.properties similarity index 100% rename from spring-5-security/src/main/resources/application-oauth2-extractors-baeldung.properties rename to spring-5-security-oauth/src/main/resources/application-oauth2-extractors-baeldung.properties diff --git a/spring-5-security/src/main/resources/application-oauth2-extractors-github.properties b/spring-5-security-oauth/src/main/resources/application-oauth2-extractors-github.properties similarity index 100% rename from spring-5-security/src/main/resources/application-oauth2-extractors-github.properties rename to spring-5-security-oauth/src/main/resources/application-oauth2-extractors-github.properties diff --git a/spring-5-security/src/main/resources/application-oauth2.properties b/spring-5-security-oauth/src/main/resources/application-oauth2.properties similarity index 100% rename from spring-5-security/src/main/resources/application-oauth2.properties rename to spring-5-security-oauth/src/main/resources/application-oauth2.properties diff --git a/spring-5-security-oauth/src/main/resources/application.properties b/spring-5-security-oauth/src/main/resources/application.properties new file mode 100644 index 0000000000..5912b0f755 --- /dev/null +++ b/spring-5-security-oauth/src/main/resources/application.properties @@ -0,0 +1,5 @@ +server.port=8081 + +logging.level.root=INFO + +logging.level.com.baeldung.dsl.ClientErrorLoggingFilter=DEBUG \ No newline at end of file diff --git a/spring-5-security-oauth/src/main/resources/logback.xml b/spring-5-security-oauth/src/main/resources/logback.xml new file mode 100644 index 0000000000..7d900d8ea8 --- /dev/null +++ b/spring-5-security-oauth/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-5-security-oauth/src/main/resources/static/css/main.css b/spring-5-security-oauth/src/main/resources/static/css/main.css new file mode 100644 index 0000000000..febc353af7 --- /dev/null +++ b/spring-5-security-oauth/src/main/resources/static/css/main.css @@ -0,0 +1,8 @@ +p.error { + font-weight: bold; + color: red; +} + +div.logout { + margin-right: 2em;; +} diff --git a/spring-5-security-oauth/src/main/resources/templates/index.html b/spring-5-security-oauth/src/main/resources/templates/index.html new file mode 100644 index 0000000000..4216d74037 --- /dev/null +++ b/spring-5-security-oauth/src/main/resources/templates/index.html @@ -0,0 +1,11 @@ + + + + Home + + + + Home + Welcome! + + \ No newline at end of file diff --git a/spring-5-security/src/main/resources/templates/loginFailure.html b/spring-5-security-oauth/src/main/resources/templates/loginFailure.html similarity index 100% rename from spring-5-security/src/main/resources/templates/loginFailure.html rename to spring-5-security-oauth/src/main/resources/templates/loginFailure.html diff --git a/spring-5-security/src/main/resources/templates/loginSuccess.html b/spring-5-security-oauth/src/main/resources/templates/loginSuccess.html similarity index 100% rename from spring-5-security/src/main/resources/templates/loginSuccess.html rename to spring-5-security-oauth/src/main/resources/templates/loginSuccess.html diff --git a/spring-5-security/src/main/resources/templates/oauth2_extractors.html b/spring-5-security-oauth/src/main/resources/templates/oauth2_extractors.html similarity index 100% rename from spring-5-security/src/main/resources/templates/oauth2_extractors.html rename to spring-5-security-oauth/src/main/resources/templates/oauth2_extractors.html diff --git a/spring-5-security/src/main/resources/templates/oauth_login.html b/spring-5-security-oauth/src/main/resources/templates/oauth_login.html similarity index 100% rename from spring-5-security/src/main/resources/templates/oauth_login.html rename to spring-5-security-oauth/src/main/resources/templates/oauth_login.html diff --git a/spring-5-security/src/main/resources/templates/securedPage.html b/spring-5-security-oauth/src/main/resources/templates/securedPage.html similarity index 100% rename from spring-5-security/src/main/resources/templates/securedPage.html rename to spring-5-security-oauth/src/main/resources/templates/securedPage.html diff --git a/spring-5-security/src/test/java/com/baeldung/oauth2extractors/ExtractorsUnitTest.java b/spring-5-security-oauth/src/test/java/com/baeldung/oauth2extractors/ExtractorsUnitTest.java similarity index 100% rename from spring-5-security/src/test/java/com/baeldung/oauth2extractors/ExtractorsUnitTest.java rename to spring-5-security-oauth/src/test/java/com/baeldung/oauth2extractors/ExtractorsUnitTest.java diff --git a/spring-5-security/README.md b/spring-5-security/README.md index 55fa7ab042..6e094e928f 100644 --- a/spring-5-security/README.md +++ b/spring-5-security/README.md @@ -1,6 +1,5 @@ ## Relevant articles: -- [Spring Security 5 -OAuth2 Login](http://www.baeldung.com/spring-security-5-oauth2-login) - [Extra Login Fields with Spring Security](http://www.baeldung.com/spring-security-extra-login-fields) - [A Custom Spring SecurityConfigurer](http://www.baeldung.com/spring-security-custom-configurer) - [New Password Storage In Spring Security 5](http://www.baeldung.com/spring-security-5-password-storage) diff --git a/spring-5-security/pom.xml b/spring-5-security/pom.xml index da62f39fa9..51ce822dc4 100644 --- a/spring-5-security/pom.xml +++ b/spring-5-security/pom.xml @@ -34,21 +34,6 @@ thymeleaf-extras-springsecurity5 - - - org.springframework.security.oauth.boot - spring-security-oauth2-autoconfigure - ${oauth-auto.version} - - - org.springframework.security - spring-security-oauth2-client - - - org.springframework.security - spring-security-oauth2-jose - - org.springframework spring-test From 31825c7b3bdcb5d35da481ecf65ca817d1d35232 Mon Sep 17 00:00:00 2001 From: geroza Date: Sun, 18 Nov 2018 19:29:38 -0200 Subject: [PATCH 022/146] Fixed one other scenario not working properly --- .../main/resources/META-INF/spring.factories | 1 + .../FailureAnalyzerAppIntegrationTest.java | 47 +++++++++++++++++++ .../failureanalyzer/utils/ListAppender.java | 25 ++++++++++ .../src/test/resources/logback-test.xml | 15 ++++++ 4 files changed, 88 insertions(+) create mode 100644 spring-boot/src/main/resources/META-INF/spring.factories create mode 100644 spring-boot/src/test/java/com/baeldung/failureanalyzer/FailureAnalyzerAppIntegrationTest.java create mode 100644 spring-boot/src/test/java/com/baeldung/failureanalyzer/utils/ListAppender.java create mode 100644 spring-boot/src/test/resources/logback-test.xml diff --git a/spring-boot/src/main/resources/META-INF/spring.factories b/spring-boot/src/main/resources/META-INF/spring.factories new file mode 100644 index 0000000000..e3d3aa4c8e --- /dev/null +++ b/spring-boot/src/main/resources/META-INF/spring.factories @@ -0,0 +1 @@ +org.springframework.boot.diagnostics.FailureAnalyzer=com.baeldung.failureanalyzer.MyBeanNotOfRequiredTypeFailureAnalyzer \ No newline at end of file diff --git a/spring-boot/src/test/java/com/baeldung/failureanalyzer/FailureAnalyzerAppIntegrationTest.java b/spring-boot/src/test/java/com/baeldung/failureanalyzer/FailureAnalyzerAppIntegrationTest.java new file mode 100644 index 0000000000..b3555f55da --- /dev/null +++ b/spring-boot/src/test/java/com/baeldung/failureanalyzer/FailureAnalyzerAppIntegrationTest.java @@ -0,0 +1,47 @@ +package com.baeldung.failureanalyzer; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.Collection; +import java.util.stream.Collectors; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.BeanCreationException; +import org.springframework.boot.SpringApplication; + +import com.baeldung.failureanalyzer.utils.ListAppender; + +import ch.qos.logback.classic.spi.ILoggingEvent; + +public class FailureAnalyzerAppIntegrationTest { + + private static final String EXPECTED_ANALYSIS_DESCRIPTION_TITLE = "Description:"; + private static final String EXPECTED_ANALYSIS_DESCRIPTION_CONTENT = "The bean myDAO could not be injected as com.baeldung.failureanalyzer.MyDAO because it is of type com.baeldung.failureanalyzer.MySecondDAO"; + private static final String EXPECTED_ANALYSIS_ACTION_TITLE = "Action:"; + private static final String EXPECTED_ANALYSIS_ACTION_CONTENT = "Consider creating a bean with name myDAO of type com.baeldung.failureanalyzer.MyDAO"; + + @BeforeEach + public void clearLogList() { + ListAppender.clearEventList(); + } + + @Test + public void givenBeanCreationErrorInContext_whenContextLoaded_thenFailureAnalyzerLogsReport() { + try { + SpringApplication.run(FailureAnalyzerApplication.class); + } catch (BeanCreationException e) { + Collection allLoggedEntries = ListAppender.getEvents() + .stream() + .map(ILoggingEvent::getFormattedMessage) + .collect(Collectors.toList()); + assertThat(allLoggedEntries).anyMatch(entry -> entry.contains(EXPECTED_ANALYSIS_DESCRIPTION_TITLE)) + .anyMatch(entry -> entry.contains(EXPECTED_ANALYSIS_DESCRIPTION_CONTENT)) + .anyMatch(entry -> entry.contains(EXPECTED_ANALYSIS_ACTION_TITLE)) + .anyMatch(entry -> entry.contains(EXPECTED_ANALYSIS_ACTION_CONTENT)); + return; + } + throw new IllegalStateException("Context load should be failing due to a BeanCreationException!"); + } + +} diff --git a/spring-boot/src/test/java/com/baeldung/failureanalyzer/utils/ListAppender.java b/spring-boot/src/test/java/com/baeldung/failureanalyzer/utils/ListAppender.java new file mode 100644 index 0000000000..a298f49ff5 --- /dev/null +++ b/spring-boot/src/test/java/com/baeldung/failureanalyzer/utils/ListAppender.java @@ -0,0 +1,25 @@ +package com.baeldung.failureanalyzer.utils; + +import java.util.ArrayList; +import java.util.List; + +import ch.qos.logback.classic.spi.ILoggingEvent; +import ch.qos.logback.core.AppenderBase; + +public class ListAppender extends AppenderBase { + + static private List events = new ArrayList<>(); + + @Override + protected void append(ILoggingEvent eventObject) { + events.add(eventObject); + } + + public static List getEvents() { + return events; + } + + public static void clearEventList() { + events.clear(); + } +} \ No newline at end of file diff --git a/spring-boot/src/test/resources/logback-test.xml b/spring-boot/src/test/resources/logback-test.xml new file mode 100644 index 0000000000..9e0f4e221f --- /dev/null +++ b/spring-boot/src/test/resources/logback-test.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + \ No newline at end of file From eba76ca5a2e8e6b9cb8081c3e2519513663cfbfb Mon Sep 17 00:00:00 2001 From: kyleandari <44148335+kyleandari@users.noreply.github.com> Date: Sun, 18 Nov 2018 22:56:37 -0500 Subject: [PATCH 023/146] BAEL-2330 (#5694) * Implementing Hexagonal Architecture in java * Removing duplicates from a string * Fix for the code review feedback - removing the hexagonal architecture code - removing the methods removeDuplicatesUsingCharArray - adding some meaningful sentences to test * Fix for the code review feedback - fix for removeDuplicatesUsingCharArray - adding unit testing - adding brackets around for loops * Fix for the code review feedback --- .../RemoveDuplicateFromString.java | 95 +++++++++++++++++++ .../RemoveDuplicateFromStringUnitTest.java | 58 +++++++++++ 2 files changed, 153 insertions(+) create mode 100644 java-strings/src/main/java/com/baeldung/stringduplicates/RemoveDuplicateFromString.java create mode 100644 java-strings/src/test/java/com/baeldung/stringduplicates/RemoveDuplicateFromStringUnitTest.java diff --git a/java-strings/src/main/java/com/baeldung/stringduplicates/RemoveDuplicateFromString.java b/java-strings/src/main/java/com/baeldung/stringduplicates/RemoveDuplicateFromString.java new file mode 100644 index 0000000000..eeba81f334 --- /dev/null +++ b/java-strings/src/main/java/com/baeldung/stringduplicates/RemoveDuplicateFromString.java @@ -0,0 +1,95 @@ +package com.baeldung.stringduplicates; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.LinkedHashSet; +import java.util.Set; + +public class RemoveDuplicateFromString { + + + String removeDuplicatesUsingCharArray(String str) { + + char[] chars = str.toCharArray(); + StringBuilder sb = new StringBuilder(); + int repeatedCtr; + for (int i = 0; i < chars.length; i++) { + repeatedCtr = 0; + for (int j = i + 1; j < chars.length; j++) { + if (chars[i] == chars[j]) { + repeatedCtr++; + } + } + if (repeatedCtr == 0) { + sb.append(chars[i]); + } + } + return sb.toString(); + } + + String removeDuplicatesUsinglinkedHashSet(String str) { + + StringBuilder sb = new StringBuilder(); + Set linkedHashSet = new LinkedHashSet<>(); + + for (int i = 0; i < str.length(); i++) { + linkedHashSet.add(str.charAt(i)); + } + + for (Character c : linkedHashSet) { + sb.append(c); + } + + return sb.toString(); + } + + String removeDuplicatesUsingSorting(String str) { + + char[] chars = str.toCharArray(); + + Arrays.sort(chars); + + StringBuilder sb = new StringBuilder(); + sb.append(chars[0]); + for (int i = 1; i < chars.length; i++) { + if (chars[i] != chars[i - 1]) { + sb.append(chars[i]); + } + } + + return sb.toString(); + } + + String removeDuplicatesUsingHashSet(String str) { + + StringBuilder sb = new StringBuilder(); + Set hashSet = new HashSet<>(); + + for (int i = 0; i < str.length(); i++) { + hashSet.add(str.charAt(i)); + } + + for (Character c : hashSet) { + sb.append(c); + } + + return sb.toString(); + } + + String removeDuplicatesUsingIndexOf(String str) { + + StringBuilder sb = new StringBuilder(); + int idx; + for (int i = 0; i < str.length(); i++) { + char c = str.charAt(i); + idx = str.indexOf(c, i + 1); + if (idx == -1) { + sb.append(c); + } + } + return sb.toString(); + } + +} + + diff --git a/java-strings/src/test/java/com/baeldung/stringduplicates/RemoveDuplicateFromStringUnitTest.java b/java-strings/src/test/java/com/baeldung/stringduplicates/RemoveDuplicateFromStringUnitTest.java new file mode 100644 index 0000000000..cf7819ced3 --- /dev/null +++ b/java-strings/src/test/java/com/baeldung/stringduplicates/RemoveDuplicateFromStringUnitTest.java @@ -0,0 +1,58 @@ +package com.baeldung.stringduplicates; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +public class RemoveDuplicateFromStringUnitTest { + + private final static String STR1 = "racecar"; + private final static String STR2 = "J2ee programming"; + private RemoveDuplicateFromString removeDuplicateFromString; + + @Before + public void executedBeforeEach() { + removeDuplicateFromString = new RemoveDuplicateFromString(); + } + + + @Test + public void whenUsingCharArray_DuplicatesShouldBeRemovedWithoutKeepingStringOrder() { + String str1 = removeDuplicateFromString.removeDuplicatesUsingCharArray(STR1); + String str2 = removeDuplicateFromString.removeDuplicatesUsingCharArray(STR2); + Assert.assertEquals("ecar", str1); + Assert.assertEquals("J2e poraming", str2); + } + + @Test + public void whenUsingLinkedHashSet_DuplicatesShouldBeRemovedAndItKeepStringOrder() { + String str1 = removeDuplicateFromString.removeDuplicatesUsinglinkedHashSet(STR1); + String str2 = removeDuplicateFromString.removeDuplicatesUsinglinkedHashSet(STR2); + Assert.assertEquals("race", str1); + Assert.assertEquals("J2e progamin", str2); + } + + @Test + public void whenUsingSorting_DuplicatesShouldBeRemovedWithoutKeepingStringOrder() { + String str1 = removeDuplicateFromString.removeDuplicatesUsingSorting(STR1); + String str2 = removeDuplicateFromString.removeDuplicatesUsingSorting(STR2); + Assert.assertEquals("acer", str1); + Assert.assertEquals(" 2Jaegimnopr", str2); + } + + @Test + public void whenUsingHashSet_DuplicatesShouldBeRemovedWithoutKeepingStringOrder() { + String str1 = removeDuplicateFromString.removeDuplicatesUsingHashSet(STR1); + String str2 = removeDuplicateFromString.removeDuplicatesUsingHashSet(STR2); + Assert.assertEquals("arce", str1); + Assert.assertEquals(" pa2regiJmno", str2); + } + + @Test + public void whenUsingIndexOf_DuplicatesShouldBeRemovedWithoutKeepingStringOrder() { + String str1 = removeDuplicateFromString.removeDuplicatesUsingIndexOf(STR1); + String str2 = removeDuplicateFromString.removeDuplicatesUsingIndexOf(STR2); + Assert.assertEquals("ecar", str1); + Assert.assertEquals("J2e poraming", str2); + } +} From ef541ac96a93f4d9b6236ee0393ecfa9f8faf165 Mon Sep 17 00:00:00 2001 From: Kevin Gilmore Date: Sun, 18 Nov 2018 22:46:55 -0600 Subject: [PATCH 024/146] BAEL-2166 BAEL-2302 add links back to articles --- java-strings/README.md | 1 + spring-data-rest/README.md | 1 + 2 files changed, 2 insertions(+) diff --git a/java-strings/README.md b/java-strings/README.md index 1b24a2b821..2847a0d0a8 100644 --- a/java-strings/README.md +++ b/java-strings/README.md @@ -36,3 +36,4 @@ - [String Performance Hints](https://www.baeldung.com/java-string-performance) - [Using indexOf to Find All Occurrences of a Word in a String](https://www.baeldung.com/java-indexOf-find-string-occurrences) - [Java Base64 Encoding and Decoding](https://www.baeldung.com/java-base64-encode-and-decode) +- [Generate a Secure Random Password in Java](https://www.baeldung.com/java-generate-secure-password) diff --git a/spring-data-rest/README.md b/spring-data-rest/README.md index 09f8391406..db94a86a6f 100644 --- a/spring-data-rest/README.md +++ b/spring-data-rest/README.md @@ -20,3 +20,4 @@ To view the running application, visit [http://localhost:8080](http://localhost: - [List of In-Memory Databases](http://www.baeldung.com/java-in-memory-databases) - [Projections and Excerpts in Spring Data REST](http://www.baeldung.com/spring-data-rest-projections-excerpts) - [Spring Data REST Events with @RepositoryEventHandler](http://www.baeldung.com/spring-data-rest-events) +- [Customizing HTTP Endpoints in Spring Data REST](https://www.baeldung.com/spring-data-rest-customize-http-endpoints) From d751dc2eae3ef58b02215b77c019cd210a7890cc Mon Sep 17 00:00:00 2001 From: KevinGilmore Date: Sun, 18 Nov 2018 22:55:50 -0600 Subject: [PATCH 025/146] BAEL-2166 BAEL-2302 update README (#5728) * BAEL-2015: add link back to article * BAEL-2166 BAEL-2302 add links back to articles --- java-strings/README.md | 1 + spring-data-rest/README.md | 1 + 2 files changed, 2 insertions(+) diff --git a/java-strings/README.md b/java-strings/README.md index 1b24a2b821..2847a0d0a8 100644 --- a/java-strings/README.md +++ b/java-strings/README.md @@ -36,3 +36,4 @@ - [String Performance Hints](https://www.baeldung.com/java-string-performance) - [Using indexOf to Find All Occurrences of a Word in a String](https://www.baeldung.com/java-indexOf-find-string-occurrences) - [Java Base64 Encoding and Decoding](https://www.baeldung.com/java-base64-encode-and-decode) +- [Generate a Secure Random Password in Java](https://www.baeldung.com/java-generate-secure-password) diff --git a/spring-data-rest/README.md b/spring-data-rest/README.md index 09f8391406..db94a86a6f 100644 --- a/spring-data-rest/README.md +++ b/spring-data-rest/README.md @@ -20,3 +20,4 @@ To view the running application, visit [http://localhost:8080](http://localhost: - [List of In-Memory Databases](http://www.baeldung.com/java-in-memory-databases) - [Projections and Excerpts in Spring Data REST](http://www.baeldung.com/spring-data-rest-projections-excerpts) - [Spring Data REST Events with @RepositoryEventHandler](http://www.baeldung.com/spring-data-rest-events) +- [Customizing HTTP Endpoints in Spring Data REST](https://www.baeldung.com/spring-data-rest-customize-http-endpoints) From ba98695605ce454c0e0ddeb98ee899e9c7054af4 Mon Sep 17 00:00:00 2001 From: Laurentiu Delcea Date: Mon, 19 Nov 2018 17:05:05 +0200 Subject: [PATCH 026/146] Convert between String and Timestamp Issue: BAEL-2325 --- .../StringToTimestampConverterUnitTest.java | 22 +++++++++++++++++++ .../TimestampToStringConverterTest.java | 19 ++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 java-dates/src/test/java/com/baeldung/timestamp/StringToTimestampConverterUnitTest.java create mode 100644 java-dates/src/test/java/com/baeldung/timestamp/TimestampToStringConverterTest.java diff --git a/java-dates/src/test/java/com/baeldung/timestamp/StringToTimestampConverterUnitTest.java b/java-dates/src/test/java/com/baeldung/timestamp/StringToTimestampConverterUnitTest.java new file mode 100644 index 0000000000..2be646eb51 --- /dev/null +++ b/java-dates/src/test/java/com/baeldung/timestamp/StringToTimestampConverterUnitTest.java @@ -0,0 +1,22 @@ +package com.baeldung.timestamp; + +import org.junit.Assert; +import org.junit.Test; + +import java.sql.Timestamp; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; + +public class StringToTimestampConverterUnitTest { + + @Test + public void givenDatePattern_whenParsing_thenTimestampIsCorrect() { + String pattern = "MMM dd, yyyy HH:mm:ss.SSSSSSSS"; + String timestampAsString = "Nov 12, 2018 13:02:56.12345678"; + DateTimeFormatter formatter = DateTimeFormatter.ofPattern(pattern); + LocalDateTime localDateTime = LocalDateTime.from(formatter.parse(timestampAsString)); + + Timestamp timestamp = Timestamp.valueOf(localDateTime); + Assert.assertEquals("2018-11-12 13:02:56.12345678", timestamp.toString()); + } +} \ No newline at end of file diff --git a/java-dates/src/test/java/com/baeldung/timestamp/TimestampToStringConverterTest.java b/java-dates/src/test/java/com/baeldung/timestamp/TimestampToStringConverterTest.java new file mode 100644 index 0000000000..b25ff2edb3 --- /dev/null +++ b/java-dates/src/test/java/com/baeldung/timestamp/TimestampToStringConverterTest.java @@ -0,0 +1,19 @@ +package com.baeldung.timestamp; + +import org.junit.Assert; +import org.junit.jupiter.api.Test; + +import java.sql.Timestamp; +import java.time.format.DateTimeFormatter; + +public class TimestampToStringConverterTest { + + @Test + public void givenDatePattern_whenFormatting_thenResultingStringIsCorrect() { + Timestamp timestamp = Timestamp.valueOf("2018-12-12 01:02:03.123456789"); + DateTimeFormatter formatter = DateTimeFormatter.ISO_LOCAL_DATE_TIME; + + String timestampAsString = formatter.format(timestamp.toLocalDateTime()); + Assert.assertEquals("2018-12-12T01:02:03.123456789", timestampAsString); + } +} \ No newline at end of file From 5145b900990719bc316fec5231bb797ba4542242 Mon Sep 17 00:00:00 2001 From: Seun Matt Date: Mon, 19 Nov 2018 18:37:13 +0100 Subject: [PATCH 027/146] added example code for BAEL-2366 (#5730) --- .../StringReplaceAndRemoveUnitTest.java | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 core-java/src/test/java/com/baeldung/string/StringReplaceAndRemoveUnitTest.java diff --git a/core-java/src/test/java/com/baeldung/string/StringReplaceAndRemoveUnitTest.java b/core-java/src/test/java/com/baeldung/string/StringReplaceAndRemoveUnitTest.java new file mode 100644 index 0000000000..d952d2383b --- /dev/null +++ b/core-java/src/test/java/com/baeldung/string/StringReplaceAndRemoveUnitTest.java @@ -0,0 +1,83 @@ +package com.baeldung.string; + + +import org.apache.commons.lang3.StringUtils; +import org.junit.Test; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +public class StringReplaceAndRemoveUnitTest { + + + @Test + public void givenTestStrings_whenReplace_thenProcessedString() { + + String master = "Hello World Baeldung!"; + String target = "Baeldung"; + String replacement = "Java"; + String processed = master.replace(target, replacement); + assertTrue(processed.contains(replacement)); + assertFalse(processed.contains(target)); + + } + + @Test + public void givenTestStrings_whenReplaceAll_thenProcessedString() { + + String master2 = "Welcome to Baeldung, Hello World Baeldung"; + String regexTarget= "(Baeldung)$"; + String replacement = "Java"; + String processed2 = master2.replaceAll(regexTarget, replacement); + assertTrue(processed2.endsWith("Java")); + + } + + @Test + public void givenTestStrings_whenStringBuilderMethods_thenProcessedString() { + + String master = "Hello World Baeldung!"; + String target = "Baeldung"; + String replacement = "Java"; + + int startIndex = master.indexOf(target); + int stopIndex = startIndex + target.length(); + + StringBuilder builder = new StringBuilder(master); + + + builder.delete(startIndex, stopIndex); + assertFalse(builder.toString().contains(target)); + + + builder.replace(startIndex, stopIndex, replacement); + assertTrue(builder.toString().contains(replacement)); + + + } + + + @Test + public void givenTestStrings_whenStringUtilsMethods_thenProcessedStrings() { + + String master = "Hello World Baeldung!"; + String target = "Baeldung"; + String replacement = "Java"; + + String processed = StringUtils.replace(master, target, replacement); + assertTrue(processed.contains(replacement)); + + String master2 = "Hello World Baeldung!"; + String target2 = "baeldung"; + String processed2 = StringUtils.replaceIgnoreCase(master2, target2, replacement); + assertFalse(processed2.contains(target)); + + } + + + + + + + +} From fcca31572b20af0e346beaef4d51ddcf598cda62 Mon Sep 17 00:00:00 2001 From: myluckagain Date: Mon, 19 Nov 2018 23:34:38 +0500 Subject: [PATCH 028/146] Spring Integration Subflows Issue: BAEL-2276 --- .../subflows/discardflow/FilterExample.java | 57 ++++++++++ .../PublishSubscibeChannelExample.java | 59 +++++------ .../RouteToRecipientsExample.java | 59 +++++------ .../separateflows/SeparateFlowsExample.java | 100 ++++++++---------- .../subflowchannel/FilterExample.java | 60 ----------- .../subflowmapping/RouterExample.java | 63 +++++------ .../subflows/discardflow/FilterUnitTest.java | 62 +++++++++++ .../PublishSubscribeChannelUnitTest.java | 62 +++++++++++ .../RouteToRecipientsUnitTest.java | 63 +++++++++++ .../separateflows/SeparateFlowsUnitTest.java | 75 +++++++++++++ .../subflowmapping/RouterUnitTest.java | 62 +++++++++++ 11 files changed, 517 insertions(+), 205 deletions(-) create mode 100644 spring-integration/src/main/java/com/baeldung/subflows/discardflow/FilterExample.java delete mode 100644 spring-integration/src/main/java/com/baeldung/subflows/subflowchannel/FilterExample.java create mode 100644 spring-integration/src/test/java/com/baeldung/subflows/discardflow/FilterUnitTest.java create mode 100644 spring-integration/src/test/java/com/baeldung/subflows/publishsubscribechannel/PublishSubscribeChannelUnitTest.java create mode 100644 spring-integration/src/test/java/com/baeldung/subflows/routetorecipients/RouteToRecipientsUnitTest.java create mode 100644 spring-integration/src/test/java/com/baeldung/subflows/separateflows/SeparateFlowsUnitTest.java create mode 100644 spring-integration/src/test/java/com/baeldung/subflows/subflowmapping/RouterUnitTest.java diff --git a/spring-integration/src/main/java/com/baeldung/subflows/discardflow/FilterExample.java b/spring-integration/src/main/java/com/baeldung/subflows/discardflow/FilterExample.java new file mode 100644 index 0000000000..f0e12f9333 --- /dev/null +++ b/spring-integration/src/main/java/com/baeldung/subflows/discardflow/FilterExample.java @@ -0,0 +1,57 @@ +package com.baeldung.subflows.discardflow; + +import java.util.Collection; +import org.springframework.context.annotation.Bean; +import org.springframework.integration.annotation.Gateway; +import org.springframework.integration.annotation.IntegrationComponentScan; +import org.springframework.integration.annotation.MessagingGateway; +import org.springframework.integration.channel.QueueChannel; +import org.springframework.integration.config.EnableIntegration; +import org.springframework.integration.dsl.IntegrationFlow; + +@EnableIntegration +@IntegrationComponentScan +public class FilterExample { + @MessagingGateway + public interface NumbersClassifier { + @Gateway(requestChannel = "classify.input") + void classify(Collection numbers); + } + + @Bean + QueueChannel multipleofThreeChannel() { + return new QueueChannel(); + } + + @Bean + QueueChannel remainderIsOneChannel() { + return new QueueChannel(); + } + + @Bean + QueueChannel remainderIsTwoChannel() { + return new QueueChannel(); + } + boolean isMultipleOfThree(Integer number) { + return number % 3 == 0; + } + + boolean isRemainderOne(Integer number) { + return number % 3 == 1; + } + + boolean isRemainderTwo(Integer number) { + return number % 3 == 2; + } + @Bean + public IntegrationFlow classify() { + return flow -> flow.split() + . filter(this::isMultipleOfThree, notMultiple -> notMultiple + .discardFlow(oneflow -> oneflow + . filter(this::isRemainderOne, + twoflow -> twoflow .discardChannel("remainderIsTwoChannel")) + .channel("remainderIsOneChannel"))) + .channel("multipleofThreeChannel"); + } + +} \ No newline at end of file diff --git a/spring-integration/src/main/java/com/baeldung/subflows/publishsubscribechannel/PublishSubscibeChannelExample.java b/spring-integration/src/main/java/com/baeldung/subflows/publishsubscribechannel/PublishSubscibeChannelExample.java index e26f938632..a1a448fc03 100644 --- a/spring-integration/src/main/java/com/baeldung/subflows/publishsubscribechannel/PublishSubscibeChannelExample.java +++ b/spring-integration/src/main/java/com/baeldung/subflows/publishsubscribechannel/PublishSubscibeChannelExample.java @@ -1,15 +1,13 @@ package com.baeldung.subflows.publishsubscribechannel; -import java.util.Arrays; import java.util.Collection; -import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.integration.annotation.Gateway; import org.springframework.integration.annotation.IntegrationComponentScan; import org.springframework.integration.annotation.MessagingGateway; -import org.springframework.integration.channel.DirectChannel; + +import org.springframework.integration.channel.QueueChannel; import org.springframework.integration.config.EnableIntegration; import org.springframework.integration.dsl.IntegrationFlow; @@ -18,46 +16,45 @@ import org.springframework.integration.dsl.IntegrationFlow; public class PublishSubscibeChannelExample { @MessagingGateway public interface NumbersClassifier { - @Gateway(requestChannel = "flow.input") - void flow(Collection numbers); + @Gateway(requestChannel = "classify.input") + void classify(Collection numbers); } @Bean - DirectChannel multipleof3Channel() { - return new DirectChannel(); + QueueChannel multipleofThreeChannel() { + return new QueueChannel(); } @Bean - DirectChannel remainderIs1Channel() { - return new DirectChannel(); + QueueChannel remainderIsOneChannel() { + return new QueueChannel(); } @Bean - DirectChannel remainderIs2Channel() { - return new DirectChannel(); + QueueChannel remainderIsTwoChannel() { + return new QueueChannel(); + } + boolean isMultipleOfThree(Integer number) { + return number % 3 == 0; } + boolean isRemainderOne(Integer number) { + return number % 3 == 1; + } + + boolean isRemainderTwo(Integer number) { + return number % 3 == 2; + } @Bean - public IntegrationFlow flow() { + public IntegrationFlow classify() { return flow -> flow.split() - .publishSubscribeChannel(s -> s.subscribe(f -> f. filter(p -> p % 3 == 0) - .channel("multipleof3Channel")) - .subscribe(f -> f. filter(p -> p % 3 == 1) - .channel("remainderIs1Channel")) - .subscribe(f -> f. filter(p -> p % 3 == 2) - .channel("remainderIs2Channel"))); + .publishSubscribeChannel(subscription -> subscription.subscribe(subflow -> subflow. filter(this::isMultipleOfThree) + .channel("multipleofThreeChannel")) + .subscribe(subflow -> subflow. filter(this::isRemainderOne) + .channel("remainderIsOneChannel")) + .subscribe(subflow -> subflow. filter(this::isRemainderTwo) + .channel("remainderIsTwoChannel"))); } + - public static void main(String[] args) { - final ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(PublishSubscibeChannelExample.class); - DirectChannel multipleof3Channel = ctx.getBean("multipleof3Channel", DirectChannel.class); - multipleof3Channel.subscribe(x -> System.out.println("multipleof3Channel: " + x)); - DirectChannel remainderIs1Channel = ctx.getBean("remainderIs1Channel", DirectChannel.class); - remainderIs1Channel.subscribe(x -> System.out.println("remainderIs1Channel: " + x)); - DirectChannel remainderIs2Channel = ctx.getBean("remainderIs2Channel", DirectChannel.class); - remainderIs2Channel.subscribe(x -> System.out.println("remainderIs2Channel: " + x)); - ctx.getBean(NumbersClassifier.class) - .flow(Arrays.asList(1, 2, 3, 4, 5, 6)); - ctx.close(); - } } diff --git a/spring-integration/src/main/java/com/baeldung/subflows/routeToRecipients/RouteToRecipientsExample.java b/spring-integration/src/main/java/com/baeldung/subflows/routeToRecipients/RouteToRecipientsExample.java index 04fdb87dfa..e0b4841736 100644 --- a/spring-integration/src/main/java/com/baeldung/subflows/routeToRecipients/RouteToRecipientsExample.java +++ b/spring-integration/src/main/java/com/baeldung/subflows/routeToRecipients/RouteToRecipientsExample.java @@ -1,15 +1,12 @@ -package com.baeldung.subflows.routeToRecipients; +package com.baeldung.subflows.routetorecipients; -import java.util.Arrays; import java.util.Collection; -import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.integration.annotation.Gateway; import org.springframework.integration.annotation.IntegrationComponentScan; import org.springframework.integration.annotation.MessagingGateway; -import org.springframework.integration.channel.DirectChannel; +import org.springframework.integration.channel.QueueChannel; import org.springframework.integration.config.EnableIntegration; import org.springframework.integration.dsl.IntegrationFlow; @@ -18,44 +15,46 @@ import org.springframework.integration.dsl.IntegrationFlow; public class RouteToRecipientsExample { @MessagingGateway public interface NumbersClassifier { - @Gateway(requestChannel = "flow.input") - void flow(Collection numbers); + @Gateway(requestChannel = "classify.input") + void classify(Collection numbers); } @Bean - DirectChannel multipleof3Channel() { - return new DirectChannel(); + QueueChannel multipleofThreeChannel() { + return new QueueChannel(); } @Bean - DirectChannel remainderIs1Channel() { - return new DirectChannel(); + QueueChannel remainderIsOneChannel() { + return new QueueChannel(); } @Bean - DirectChannel remainderIs2Channel() { - return new DirectChannel(); + QueueChannel remainderIsTwoChannel() { + return new QueueChannel(); + } + boolean isMultipleOfThree(Integer number) { + return number % 3 == 0; + } + + boolean isRemainderOne(Integer number) { + return number % 3 == 1; + } + + boolean isRemainderTwo(Integer number) { + return number % 3 == 2; } @Bean - public IntegrationFlow flow() { + public IntegrationFlow classify() { return flow -> flow.split() - .routeToRecipients(r -> r. recipient("multipleof3Channel", p -> p % 3 == 0)// filter - . recipient("remainderIs1Channel", p -> p % 3 == 1) - .recipientFlow(sf -> sf. filter(p -> p % 3 == 2) - .channel("remainderIs2Channel"))); + .routeToRecipients(route -> route + .recipientFlow(subflow -> subflow + . filter(this::isMultipleOfThree) + .channel("multipleofThreeChannel")) + . recipient("remainderIsOneChannel",this::isRemainderOne) + . recipient("remainderIsTwoChannel",this::isRemainderTwo)); } + - public static void main(String[] args) { - final ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(RouteToRecipientsExample.class); - DirectChannel multipleof3Channel = ctx.getBean("multipleof3Channel", DirectChannel.class); - multipleof3Channel.subscribe(x -> System.out.println("multipleof3Channel: " + x)); - DirectChannel remainderIs1Channel = ctx.getBean("remainderIs1Channel", DirectChannel.class); - remainderIs1Channel.subscribe(x -> System.out.println("remainderIs1Channel: " + x)); - DirectChannel remainderIs2Channel = ctx.getBean("remainderIs2Channel", DirectChannel.class); - remainderIs2Channel.subscribe(x -> System.out.println("remainderIs2Channel: " + x)); - ctx.getBean(NumbersClassifier.class) - .flow(Arrays.asList(1, 2, 3, 4, 5, 6)); - ctx.close(); - } } \ No newline at end of file diff --git a/spring-integration/src/main/java/com/baeldung/subflows/separateflows/SeparateFlowsExample.java b/spring-integration/src/main/java/com/baeldung/subflows/separateflows/SeparateFlowsExample.java index 8ed46ead87..457b8045c5 100644 --- a/spring-integration/src/main/java/com/baeldung/subflows/separateflows/SeparateFlowsExample.java +++ b/spring-integration/src/main/java/com/baeldung/subflows/separateflows/SeparateFlowsExample.java @@ -1,15 +1,13 @@ package com.baeldung.subflows.separateflows; -import java.util.Arrays; import java.util.Collection; -import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.integration.annotation.Gateway; import org.springframework.integration.annotation.IntegrationComponentScan; import org.springframework.integration.annotation.MessagingGateway; -import org.springframework.integration.channel.DirectChannel; + +import org.springframework.integration.channel.QueueChannel; import org.springframework.integration.config.EnableIntegration; import org.springframework.integration.dsl.IntegrationFlow; @@ -18,66 +16,62 @@ import org.springframework.integration.dsl.IntegrationFlow; public class SeparateFlowsExample { @MessagingGateway public interface NumbersClassifier { - @Gateway(requestChannel = "multipleof3Flow.input") - void multipleof3(Collection is); + @Gateway(requestChannel = "multipleOfThreeFlow.input") + void multipleofThree(Collection numbers); - @Gateway(requestChannel = "remainderIs1Flow.input") - void remainderIs1(Collection is); + @Gateway(requestChannel = "remainderIsOneFlow.input") + void remainderIsOne(Collection numbers); - @Gateway(requestChannel = "remainderIs2Flow.input") - void remainderIs2(Collection numbers); + @Gateway(requestChannel = "remainderIsTwoFlow.input") + void remainderIsTwo(Collection numbers); + } + + @Bean + QueueChannel multipleOfThreeChannel() { + return new QueueChannel(); + } + + @Bean + QueueChannel remainderIsOneChannel() { + return new QueueChannel(); + } + + @Bean + QueueChannel remainderIsTwoChannel() { + return new QueueChannel(); + } + + boolean isMultipleOfThree(Integer number) { + return number % 3 == 0; + } + + boolean isRemainderOne(Integer number) { + return number % 3 == 1; + } + + boolean isRemainderTwo(Integer number) { + return number % 3 == 2; } @Bean - DirectChannel multipleof3Channel() { - return new DirectChannel(); + public IntegrationFlow multipleOfThreeFlow() { + return flow -> flow.split() + . filter(this::isMultipleOfThree) + .channel("multipleOfThreeChannel"); } @Bean - DirectChannel remainderIs1Channel() { - return new DirectChannel(); + public IntegrationFlow remainderIsOneFlow() { + return flow -> flow.split() + . filter(this::isRemainderOne) + .channel("remainderIsOneChannel"); } @Bean - DirectChannel remainderIs2Channel() { - return new DirectChannel(); + public IntegrationFlow remainderIsTwoFlow() { + return flow -> flow.split() + . filter(this::isRemainderTwo) + .channel("remainderIsTwoChannel"); } - @Bean - public IntegrationFlow multipleof3Flow() { - return f -> f.split() - . filter(p -> p % 3 == 0) - .channel("multipleof3Channel"); - } - - @Bean - public IntegrationFlow remainderIs1Flow() { - return f -> f.split() - . filter(p -> p % 3 == 1) - .channel("remainderIs1Channel"); - } - - @Bean - public IntegrationFlow remainderIs2Flow() { - return f -> f.split() - . filter(p -> p % 3 == 2) - .channel("remainderIs2Channel"); - } - - public static void main(String[] args) { - final ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(SeparateFlowsExample.class); - DirectChannel multipleof3Channel = ctx.getBean("multipleof3Channel", DirectChannel.class); - multipleof3Channel.subscribe(x -> System.out.println("multipleof3Channel: " + x)); - DirectChannel remainderIs1Channel = ctx.getBean("remainderIs1Channel", DirectChannel.class); - remainderIs1Channel.subscribe(x -> System.out.println("remainderIs1Channel: " + x)); - DirectChannel remainderIs2Channel = ctx.getBean("remainderIs2Channel", DirectChannel.class); - remainderIs2Channel.subscribe(x -> System.out.println("remainderIs2Channel: " + x)); - ctx.getBean(NumbersClassifier.class) - .multipleof3(Arrays.asList(1, 2, 3, 4, 5, 6)); - ctx.getBean(NumbersClassifier.class) - .remainderIs1(Arrays.asList(1, 2, 3, 4, 5, 6)); - ctx.getBean(NumbersClassifier.class) - .remainderIs2(Arrays.asList(1, 2, 3, 4, 5, 6)); - ctx.close(); - } } \ No newline at end of file diff --git a/spring-integration/src/main/java/com/baeldung/subflows/subflowchannel/FilterExample.java b/spring-integration/src/main/java/com/baeldung/subflows/subflowchannel/FilterExample.java deleted file mode 100644 index 6db3741523..0000000000 --- a/spring-integration/src/main/java/com/baeldung/subflows/subflowchannel/FilterExample.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.baeldung.subflows.subflowchannel; - -import java.util.Arrays; -import java.util.Collection; - -import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; -import org.springframework.context.annotation.Bean; -import org.springframework.integration.annotation.Gateway; -import org.springframework.integration.annotation.IntegrationComponentScan; -import org.springframework.integration.annotation.MessagingGateway; -import org.springframework.integration.channel.DirectChannel; -import org.springframework.integration.config.EnableIntegration; -import org.springframework.integration.dsl.IntegrationFlow; - -@EnableIntegration -@IntegrationComponentScan -public class FilterExample { - @MessagingGateway - public interface NumbersClassifier { - @Gateway(requestChannel = "flow.input") - void flow(Collection numbers); - } - - @Bean - DirectChannel multipleof3Channel() { - return new DirectChannel(); - } - - @Bean - DirectChannel remainderIs1Channel() { - return new DirectChannel(); - } - - @Bean - DirectChannel remainderIs2Channel() { - return new DirectChannel(); - } - - @Bean - public IntegrationFlow flow() { - return flow -> flow.split() - . filter(x -> x % 3 == 0, sf -> sf.discardFlow(subf -> subf. filter(x -> x % 3 == 1, ssf -> ssf.discardChannel("remainderIs2Channel")) - .channel("remainderIs1Channel"))) - .channel("multipleof3Channel"); - } - - public static void main(String[] args) { - final ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(FilterExample.class); - DirectChannel multipleof3Channel = ctx.getBean("multipleof3Channel", DirectChannel.class); - multipleof3Channel.subscribe(x -> System.out.println("multipleof3Channel: " + x)); - DirectChannel remainderIs1Channel = ctx.getBean("remainderIs1Channel", DirectChannel.class); - remainderIs1Channel.subscribe(x -> System.out.println("remainderIs1Channel: " + x)); - DirectChannel remainderIs2Channel = ctx.getBean("remainderIs2Channel", DirectChannel.class); - remainderIs2Channel.subscribe(x -> System.out.println("remainderIs2Channel: " + x)); - ctx.getBean(NumbersClassifier.class) - .flow(Arrays.asList(1, 2, 3, 4, 5, 6)); - ctx.close(); - } -} \ No newline at end of file diff --git a/spring-integration/src/main/java/com/baeldung/subflows/subflowmapping/RouterExample.java b/spring-integration/src/main/java/com/baeldung/subflows/subflowmapping/RouterExample.java index de1f11cf70..c0e902e739 100644 --- a/spring-integration/src/main/java/com/baeldung/subflows/subflowmapping/RouterExample.java +++ b/spring-integration/src/main/java/com/baeldung/subflows/subflowmapping/RouterExample.java @@ -1,15 +1,11 @@ package com.baeldung.subflows.subflowmapping; -import java.util.Arrays; import java.util.Collection; - -import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.integration.annotation.Gateway; import org.springframework.integration.annotation.IntegrationComponentScan; import org.springframework.integration.annotation.MessagingGateway; -import org.springframework.integration.channel.DirectChannel; +import org.springframework.integration.channel.QueueChannel; import org.springframework.integration.config.EnableIntegration; import org.springframework.integration.dsl.IntegrationFlow; @@ -18,44 +14,49 @@ import org.springframework.integration.dsl.IntegrationFlow; public class RouterExample { @MessagingGateway public interface NumbersClassifier { - @Gateway(requestChannel = "flow.input") - void flow(Collection numbers); + @Gateway(requestChannel = "classify.input") + void classify(Collection numbers); } @Bean - DirectChannel multipleof3Channel() { - return new DirectChannel(); + QueueChannel multipleofThreeChannel() { + return new QueueChannel(); } @Bean - DirectChannel remainderIs1Channel() { - return new DirectChannel(); + QueueChannel remainderIsOneChannel() { + return new QueueChannel(); } @Bean - DirectChannel remainderIs2Channel() { - return new DirectChannel(); + QueueChannel remainderIsTwoChannel() { + return new QueueChannel(); + } + + boolean isMultipleOfThree(Integer number) { + return number % 3 == 0; + } + + boolean isRemainderOne(Integer number) { + return number % 3 == 1; + } + + boolean isRemainderTwo(Integer number) { + return number % 3 == 2; } @Bean - public IntegrationFlow flow() { - return f -> f.split() - . route(p -> p % 3, m -> m.channelMapping(0, "multipleof3Channel") - .subFlowMapping(1, sf -> sf.channel("remainderIs1Channel")) - .subFlowMapping(2, sf -> sf. handle((p, h) -> p))) - .channel("remainderIs2Channel"); + public IntegrationFlow classify() { + return flow -> flow.split() + . route(number -> number % 3, + mapping -> mapping + .channelMapping(0, "multipleofThreeChannel") + .subFlowMapping(1, subflow -> subflow.channel("remainderIsOneChannel")) + .subFlowMapping(2, subflow -> subflow + . handle((payload, headers) -> { + // do extra work on the payload + return payload; + }))).channel("remainderIsTwoChannel"); } - public static void main(String[] args) { - final ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(RouterExample.class); - DirectChannel multipleof3Channel = ctx.getBean("multipleof3Channel", DirectChannel.class); - multipleof3Channel.subscribe(x -> System.out.println("multipleof3Channel: " + x)); - DirectChannel remainderIs1Channel = ctx.getBean("remainderIs1Channel", DirectChannel.class); - remainderIs1Channel.subscribe(x -> System.out.println("remainderIs1Channel: " + x)); - DirectChannel remainderIs2Channel = ctx.getBean("remainderIs2Channel", DirectChannel.class); - remainderIs2Channel.subscribe(x -> System.out.println("remainderIs2Channel: " + x)); - ctx.getBean(NumbersClassifier.class) - .flow(Arrays.asList(1, 2, 3, 4, 5, 6)); - ctx.close(); - } } \ No newline at end of file diff --git a/spring-integration/src/test/java/com/baeldung/subflows/discardflow/FilterUnitTest.java b/spring-integration/src/test/java/com/baeldung/subflows/discardflow/FilterUnitTest.java new file mode 100644 index 0000000000..3b3106212b --- /dev/null +++ b/spring-integration/src/test/java/com/baeldung/subflows/discardflow/FilterUnitTest.java @@ -0,0 +1,62 @@ +package com.baeldung.subflows.discardflow; + +import static org.junit.Assert.assertEquals; + +import java.util.Arrays; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.integration.channel.QueueChannel; +import org.springframework.messaging.Message; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +import com.baeldung.subflows.discardflow.FilterExample.NumbersClassifier; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(classes = { FilterExample.class }) +public class FilterUnitTest { + @Autowired + private QueueChannel multipleofThreeChannel; + + @Autowired + private QueueChannel remainderIsOneChannel; + + @Autowired + private QueueChannel remainderIsTwoChannel; + + @Autowired + private NumbersClassifier numbersClassifier; + + @Test + public void whenSendMessagesToFlow_thenNumbersAreClassified() { + + numbersClassifier.classify(Arrays.asList(1, 2, 3, 4, 5, 6)); + + Message outMessage = multipleofThreeChannel.receive(0); + + assertEquals(outMessage.getPayload(), 3); + + outMessage = multipleofThreeChannel.receive(0); + + assertEquals(outMessage.getPayload(), 6); + + outMessage = remainderIsOneChannel.receive(0); + + assertEquals(outMessage.getPayload(), 1); + outMessage = remainderIsOneChannel.receive(0); + + assertEquals(outMessage.getPayload(), 4); + + outMessage = remainderIsTwoChannel.receive(0); + + assertEquals(outMessage.getPayload(), 2); + + outMessage = remainderIsTwoChannel.receive(0); + + assertEquals(outMessage.getPayload(), 5); + + } + +} diff --git a/spring-integration/src/test/java/com/baeldung/subflows/publishsubscribechannel/PublishSubscribeChannelUnitTest.java b/spring-integration/src/test/java/com/baeldung/subflows/publishsubscribechannel/PublishSubscribeChannelUnitTest.java new file mode 100644 index 0000000000..91bf38c626 --- /dev/null +++ b/spring-integration/src/test/java/com/baeldung/subflows/publishsubscribechannel/PublishSubscribeChannelUnitTest.java @@ -0,0 +1,62 @@ +package com.baeldung.subflows.publishsubscribechannel; + +import static org.junit.Assert.assertEquals; + +import java.util.Arrays; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.integration.channel.QueueChannel; +import org.springframework.messaging.Message; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +import com.baeldung.subflows.publishsubscribechannel.PublishSubscibeChannelExample.NumbersClassifier; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(classes = { PublishSubscibeChannelExample.class }) +public class PublishSubscribeChannelUnitTest { + @Autowired + private QueueChannel multipleofThreeChannel; + + @Autowired + private QueueChannel remainderIsOneChannel; + + @Autowired + private QueueChannel remainderIsTwoChannel; + + @Autowired + private NumbersClassifier numbersClassifier; + + @Test + public void whenSendMessagesToFlow_thenNumbersAreClassified() { + + numbersClassifier.classify(Arrays.asList(1, 2, 3, 4, 5, 6)); + + Message outMessage = multipleofThreeChannel.receive(0); + + assertEquals(outMessage.getPayload(), 3); + + outMessage = multipleofThreeChannel.receive(0); + + assertEquals(outMessage.getPayload(), 6); + + outMessage = remainderIsOneChannel.receive(0); + + assertEquals(outMessage.getPayload(), 1); + outMessage = remainderIsOneChannel.receive(0); + + assertEquals(outMessage.getPayload(), 4); + + outMessage = remainderIsTwoChannel.receive(0); + + assertEquals(outMessage.getPayload(), 2); + + outMessage = remainderIsTwoChannel.receive(0); + + assertEquals(outMessage.getPayload(), 5); + + } + +} diff --git a/spring-integration/src/test/java/com/baeldung/subflows/routetorecipients/RouteToRecipientsUnitTest.java b/spring-integration/src/test/java/com/baeldung/subflows/routetorecipients/RouteToRecipientsUnitTest.java new file mode 100644 index 0000000000..d7a768dcd9 --- /dev/null +++ b/spring-integration/src/test/java/com/baeldung/subflows/routetorecipients/RouteToRecipientsUnitTest.java @@ -0,0 +1,63 @@ +package com.baeldung.subflows.routetorecipients; + +import static org.junit.Assert.assertEquals; + +import java.util.Arrays; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.integration.channel.QueueChannel; +import org.springframework.messaging.Message; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +import com.baeldung.subflows.routetorecipients.RouteToRecipientsExample; +import com.baeldung.subflows.routetorecipients.RouteToRecipientsExample.NumbersClassifier; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(classes = { RouteToRecipientsExample.class }) +public class RouteToRecipientsUnitTest { + @Autowired + private QueueChannel multipleofThreeChannel; + + @Autowired + private QueueChannel remainderIsOneChannel; + + @Autowired + private QueueChannel remainderIsTwoChannel; + + @Autowired + private NumbersClassifier numbersClassifier; + + @Test + public void whenSendMessagesToFlow_thenNumbersAreClassified() { + + numbersClassifier.classify(Arrays.asList(1, 2, 3, 4, 5, 6)); + + Message outMessage = multipleofThreeChannel.receive(0); + + assertEquals(outMessage.getPayload(), 3); + + outMessage = multipleofThreeChannel.receive(0); + + assertEquals(outMessage.getPayload(), 6); + + outMessage = remainderIsOneChannel.receive(0); + + assertEquals(outMessage.getPayload(), 1); + outMessage = remainderIsOneChannel.receive(0); + + assertEquals(outMessage.getPayload(), 4); + + outMessage = remainderIsTwoChannel.receive(0); + + assertEquals(outMessage.getPayload(), 2); + + outMessage = remainderIsTwoChannel.receive(0); + + assertEquals(outMessage.getPayload(), 5); + + } + +} diff --git a/spring-integration/src/test/java/com/baeldung/subflows/separateflows/SeparateFlowsUnitTest.java b/spring-integration/src/test/java/com/baeldung/subflows/separateflows/SeparateFlowsUnitTest.java new file mode 100644 index 0000000000..c02badcb1a --- /dev/null +++ b/spring-integration/src/test/java/com/baeldung/subflows/separateflows/SeparateFlowsUnitTest.java @@ -0,0 +1,75 @@ +package com.baeldung.subflows.separateflows; + +import java.util.Arrays; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.integration.channel.QueueChannel; +import org.springframework.messaging.Message; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import com.baeldung.subflows.separateflows.SeparateFlowsExample.NumbersClassifier; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(classes = { SeparateFlowsExample.class }) +public class SeparateFlowsUnitTest { + @Autowired + private QueueChannel multipleOfThreeChannel; + @Autowired + private QueueChannel remainderIsOneChannel; + @Autowired + private QueueChannel remainderIsTwoChannel; + + @Autowired + private NumbersClassifier numbersClassifier; + + @Test + public void whenSendMessagesToMultipleOf3Flow_thenOutputMultiplesOf3() { + + numbersClassifier.multipleofThree(Arrays.asList(1, 2, 3, 4, 5, 6)); + + Message outMessage = multipleOfThreeChannel.receive(0); + + assertEquals(outMessage.getPayload(), 3); + + outMessage = multipleOfThreeChannel.receive(0); + + assertEquals(outMessage.getPayload(), 6); + outMessage = multipleOfThreeChannel.receive(0); + assertNull(outMessage); + } + + @Test + public void whenSendMessagesToRemainderIs1Flow_thenOutputRemainderIs1() { + + numbersClassifier.remainderIsOne(Arrays.asList(1, 2, 3, 4, 5, 6)); + + Message outMessage = remainderIsOneChannel.receive(0); + + assertEquals(outMessage.getPayload(), 1); + + outMessage = remainderIsOneChannel.receive(0); + + assertEquals(outMessage.getPayload(), 4); + + } + + @Test + public void whenSendMessagesToRemainderIs2Flow_thenOutputRemainderIs2() { + + numbersClassifier.remainderIsTwo(Arrays.asList(1, 2, 3, 4, 5, 6)); + + Message outMessage = remainderIsTwoChannel.receive(0); + + assertEquals(outMessage.getPayload(), 2); + + outMessage = remainderIsTwoChannel.receive(0); + + assertEquals(outMessage.getPayload(), 5); + + } + +} diff --git a/spring-integration/src/test/java/com/baeldung/subflows/subflowmapping/RouterUnitTest.java b/spring-integration/src/test/java/com/baeldung/subflows/subflowmapping/RouterUnitTest.java new file mode 100644 index 0000000000..9ecbb22a9b --- /dev/null +++ b/spring-integration/src/test/java/com/baeldung/subflows/subflowmapping/RouterUnitTest.java @@ -0,0 +1,62 @@ +package com.baeldung.subflows.subflowmapping; + +import static org.junit.Assert.assertEquals; + +import java.util.Arrays; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.integration.channel.QueueChannel; +import org.springframework.messaging.Message; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +import com.baeldung.subflows.subflowmapping.RouterExample.NumbersClassifier; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(classes = { RouterExample.class }) +public class RouterUnitTest { + @Autowired + private QueueChannel multipleofThreeChannel; + + @Autowired + private QueueChannel remainderIsOneChannel; + + @Autowired + private QueueChannel remainderIsTwoChannel; + + @Autowired + private NumbersClassifier numbersClassifier; + + @Test + public void whenSendMessagesToFlow_thenNumbersAreClassified() { + + numbersClassifier.classify(Arrays.asList(1, 2, 3, 4, 5, 6)); + + Message outMessage = multipleofThreeChannel.receive(0); + + assertEquals(outMessage.getPayload(), 3); + + outMessage = multipleofThreeChannel.receive(0); + + assertEquals(outMessage.getPayload(), 6); + + outMessage = remainderIsOneChannel.receive(0); + + assertEquals(outMessage.getPayload(), 1); + outMessage = remainderIsOneChannel.receive(0); + + assertEquals(outMessage.getPayload(), 4); + + outMessage = remainderIsTwoChannel.receive(0); + + assertEquals(outMessage.getPayload(), 2); + + outMessage = remainderIsTwoChannel.receive(0); + + assertEquals(outMessage.getPayload(), 5); + + } + +} From 456f4b0f5a5a6a6ab0f6685c7cb84107728f320b Mon Sep 17 00:00:00 2001 From: cror Date: Mon, 19 Nov 2018 16:41:11 +0100 Subject: [PATCH 029/146] BAEL-2388: examples for equals and hashCode --- java-collections-maps/pom.xml | 6 +++ .../java/com/baeldung/map/hashCode/Money.java | 32 +++++++++++++ .../java/com/baeldung/map/hashCode/Team.java | 39 ++++++++++++++++ .../com/baeldung/map/hashCode/Voucher.java | 31 +++++++++++++ .../com/baeldung/map/hashCode/WrongTeam.java | 24 ++++++++++ .../baeldung/map/hashCode/WrongVoucher.java | 33 +++++++++++++ .../map/hashCode/equalsverifier_notes.txt | 1 + .../baeldung/map/hashCode/MoneyUnitTest.java | 27 +++++++++++ .../baeldung/map/hashCode/TeamUnitTest.java | 46 +++++++++++++++++++ 9 files changed, 239 insertions(+) create mode 100644 java-collections-maps/src/main/java/com/baeldung/map/hashCode/Money.java create mode 100644 java-collections-maps/src/main/java/com/baeldung/map/hashCode/Team.java create mode 100644 java-collections-maps/src/main/java/com/baeldung/map/hashCode/Voucher.java create mode 100644 java-collections-maps/src/main/java/com/baeldung/map/hashCode/WrongTeam.java create mode 100644 java-collections-maps/src/main/java/com/baeldung/map/hashCode/WrongVoucher.java create mode 100644 java-collections-maps/src/main/java/com/baeldung/map/hashCode/equalsverifier_notes.txt create mode 100644 java-collections-maps/src/test/java/com/baeldung/map/hashCode/MoneyUnitTest.java create mode 100644 java-collections-maps/src/test/java/com/baeldung/map/hashCode/TeamUnitTest.java diff --git a/java-collections-maps/pom.xml b/java-collections-maps/pom.xml index 0803866c51..6af8f7a5c6 100644 --- a/java-collections-maps/pom.xml +++ b/java-collections-maps/pom.xml @@ -41,6 +41,12 @@ streamex 0.6.5 + + nl.jqno.equalsverifier + equalsverifier + 3.0.3 + test + diff --git a/java-collections-maps/src/main/java/com/baeldung/map/hashCode/Money.java b/java-collections-maps/src/main/java/com/baeldung/map/hashCode/Money.java new file mode 100644 index 0000000000..0ba494d944 --- /dev/null +++ b/java-collections-maps/src/main/java/com/baeldung/map/hashCode/Money.java @@ -0,0 +1,32 @@ +package com.baeldung.map.hashcode; + +class Money { + + int amount; + String currencyCode; + + Money(int amount, String currencyCode) { + this.amount = amount; + this.currencyCode = currencyCode; + } + + @Override + public boolean equals(Object o) { + if (o == this) + return true; + if (!(o instanceof Money)) + return false; + Money other = (Money)o; + return this.amount == other.amount + && this.currencyCode == other.currencyCode; + } + + @Override + public int hashCode() { + int result = 17; + result = 31 * result + amount; + result = 31 * result + currencyCode.hashCode(); + return result; + } + +} diff --git a/java-collections-maps/src/main/java/com/baeldung/map/hashCode/Team.java b/java-collections-maps/src/main/java/com/baeldung/map/hashCode/Team.java new file mode 100644 index 0000000000..6c1473b8e9 --- /dev/null +++ b/java-collections-maps/src/main/java/com/baeldung/map/hashCode/Team.java @@ -0,0 +1,39 @@ +package com.baeldung.map.hashcode; + +class Team { + + final String city; + final String department; + + Team(String city, String department) { + this.city = city; + this.department = department; + } + + @Override + public final boolean equals(Object o) { + if (o == this) + return true; + if (!(o instanceof Team)) + return false; + Team otherTeam = (Team)o; + boolean cityEquals = (this.city == null && otherTeam.city == null) + || this.city != null && this.city.equals(otherTeam.city); + boolean departmentEquals = (this.department == null && otherTeam.department == null) + || this.department != null && this.department.equals(otherTeam.department); + return cityEquals && departmentEquals; + } + + @Override + public final int hashCode() { + int result = 17; + if (city != null) { + result = 31 * result + city.hashCode(); + } + if (department != null) { + result = 31 * result + department.hashCode(); + } + return result; + } + +} diff --git a/java-collections-maps/src/main/java/com/baeldung/map/hashCode/Voucher.java b/java-collections-maps/src/main/java/com/baeldung/map/hashCode/Voucher.java new file mode 100644 index 0000000000..b4536b38ea --- /dev/null +++ b/java-collections-maps/src/main/java/com/baeldung/map/hashCode/Voucher.java @@ -0,0 +1,31 @@ +package com.baeldung.map.hashcode; + +class Voucher { + + private Money value; + private String store; + + Voucher(int amount, String currencyCode, String store) { + this.value = new Money(amount, currencyCode); + this.store = store; + } + + @Override + public boolean equals(Object o) { + if (o == this) + return true; + if (!(o instanceof Voucher)) + return false; + Voucher other = (Voucher)o; + return this.value == other.value + && this.store == other.store; + } + + @Override + public int hashCode() { + int result = 17; + result = 31 * result + value.hashCode(); + result = 31 * result + store.hashCode(); + return result; + } +} \ No newline at end of file diff --git a/java-collections-maps/src/main/java/com/baeldung/map/hashCode/WrongTeam.java b/java-collections-maps/src/main/java/com/baeldung/map/hashCode/WrongTeam.java new file mode 100644 index 0000000000..57fb218ce0 --- /dev/null +++ b/java-collections-maps/src/main/java/com/baeldung/map/hashCode/WrongTeam.java @@ -0,0 +1,24 @@ +package com.baeldung.map.hashcode; + +class WrongTeam { + + String city; + String department; + + WrongTeam(String city, String department) { + this.city = city; + this.department = department; + } + + @Override + public boolean equals(Object o) { + if (o == this) + return true; + if (!(o instanceof WrongTeam)) + return false; + WrongTeam otherTeam = (WrongTeam)o; + return this.city == otherTeam.city + && this.department == otherTeam.department; + } + +} diff --git a/java-collections-maps/src/main/java/com/baeldung/map/hashCode/WrongVoucher.java b/java-collections-maps/src/main/java/com/baeldung/map/hashCode/WrongVoucher.java new file mode 100644 index 0000000000..03122c7cc8 --- /dev/null +++ b/java-collections-maps/src/main/java/com/baeldung/map/hashCode/WrongVoucher.java @@ -0,0 +1,33 @@ +package com.baeldung.map.hashcode; + +class WrongVoucher extends Money { + + private String store; + + WrongVoucher(int amount, String currencyCode, String store) { + super(amount, currencyCode); + + this.store = store; + } + + @Override + public boolean equals(Object o) { + if (o == this) + return true; + if (!(o instanceof WrongVoucher)) + return false; + WrongVoucher other = (WrongVoucher)o; + return this.amount == other.amount + && this.currencyCode == other.currencyCode + && this.store == other.store; + } + + @Override + public int hashCode() { + int result = 17; + result = 31 * result + amount; + result = 31 * result + currencyCode.hashCode(); + result = 31 * result + store.hashCode(); + return result; + } +} \ No newline at end of file diff --git a/java-collections-maps/src/main/java/com/baeldung/map/hashCode/equalsverifier_notes.txt b/java-collections-maps/src/main/java/com/baeldung/map/hashCode/equalsverifier_notes.txt new file mode 100644 index 0000000000..adc14f393a --- /dev/null +++ b/java-collections-maps/src/main/java/com/baeldung/map/hashCode/equalsverifier_notes.txt @@ -0,0 +1 @@ + Non-nullity: hashCode throws NullPointerException on field city. diff --git a/java-collections-maps/src/test/java/com/baeldung/map/hashCode/MoneyUnitTest.java b/java-collections-maps/src/test/java/com/baeldung/map/hashCode/MoneyUnitTest.java new file mode 100644 index 0000000000..f4cba4d114 --- /dev/null +++ b/java-collections-maps/src/test/java/com/baeldung/map/hashCode/MoneyUnitTest.java @@ -0,0 +1,27 @@ +package com.baeldung.map.hashcode; + +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertFalse; + +import org.junit.Test; + +public class MoneyUnitTest { + + @Test + public void givenMoneyInstancesWithSameAmountAndCurrency_whenEquals_thenReturnsTrue() { + Money income = new Money(55, "USD"); + Money expenses = new Money(55, "USD"); + + assertTrue(income.equals(expenses)); + } + + @Test + public void givenMoneyAndVoucherInstances_whenEquals_thenReturnValuesArentSymmetric() { + Money cash = new Money(42, "USD"); + WrongVoucher voucher = new WrongVoucher(42, "USD", "Amazon"); + + assertFalse(voucher.equals(cash)); + assertTrue(cash.equals(voucher)); + } + +} diff --git a/java-collections-maps/src/test/java/com/baeldung/map/hashCode/TeamUnitTest.java b/java-collections-maps/src/test/java/com/baeldung/map/hashCode/TeamUnitTest.java new file mode 100644 index 0000000000..89a7462438 --- /dev/null +++ b/java-collections-maps/src/test/java/com/baeldung/map/hashCode/TeamUnitTest.java @@ -0,0 +1,46 @@ +package com.baeldung.map.hashcode; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; + +import java.util.HashMap; +import java.util.Map; + +import org.junit.Test; + +import nl.jqno.equalsverifier.EqualsVerifier; + +public class TeamUnitTest { + + @Test + public void givenMapKeyWithHashCode_whenSearched_thenReturnsCorrectValue() { + Map leaders = new HashMap<>(); + leaders.put(new Team("New York", "development"), "Anne"); + leaders.put(new Team("Boston", "development"), "Brian"); + leaders.put(new Team("Boston", "marketing"), "Charlie"); + + Team myTeam = new Team("New York", "development"); + String myTeamleader = leaders.get(myTeam); + + assertEquals("Anne", myTeamleader); + } + + @Test + public void givenMapKeyWithoutHashCode_whenSearched_thenReturnsWrongValue() { + Map leaders = new HashMap<>(); + leaders.put(new WrongTeam("New York", "development"), "Anne"); + leaders.put(new WrongTeam("Boston", "development"), "Brian"); + leaders.put(new WrongTeam("Boston", "marketing"), "Charlie"); + + WrongTeam myTeam = new WrongTeam("New York", "development"); + String myTeamleader = leaders.get(myTeam); + + assertFalse("Anne".equals(myTeamleader)); + } + + @Test + public void equalsContract() { + EqualsVerifier.forClass(Team.class).verify(); + } + +} From cd8a9fd89a059beb8d709e5eebb04479ccb0d897 Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Mon, 19 Nov 2018 22:57:27 +0200 Subject: [PATCH 030/146] Update spring.factories --- .../src/main/resources/META-INF/spring.factories | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/spring-boot-autoconfiguration/src/main/resources/META-INF/spring.factories b/spring-boot-autoconfiguration/src/main/resources/META-INF/spring.factories index 5f55544eff..11c775fc6c 100644 --- a/spring-boot-autoconfiguration/src/main/resources/META-INF/spring.factories +++ b/spring-boot-autoconfiguration/src/main/resources/META-INF/spring.factories @@ -1,3 +1 @@ -org.springframework.boot.diagnostics.FailureAnalyzer=com.baeldung.failureanalyzer.MyBeanNotOfRequiredTypeFailureAnalyzer - -org.springframework.boot.autoconfigure.EnableAutoConfiguration=com.baeldung.autoconfiguration.MySQLAutoconfiguration \ No newline at end of file +org.springframework.boot.autoconfigure.EnableAutoConfiguration=com.baeldung.autoconfiguration.MySQLAutoconfiguration From 4d30ff3b438cd19d240a6b38225c74727c5a964a Mon Sep 17 00:00:00 2001 From: getwordsdone <44430887+getwordsdone@users.noreply.github.com> Date: Tue, 20 Nov 2018 10:31:31 +0530 Subject: [PATCH 031/146] A Guide to Constructors Issue: BAEL-2345 --- .../baeldung/constructors/BankAccount.java | 56 +++++++++++++++++++ .../baeldung/constructors/Transaction.java | 25 +++++++++ .../constructors/ConstructorUnitTest.java | 53 ++++++++++++++++++ 3 files changed, 134 insertions(+) create mode 100644 core-java/src/main/java/com/baeldung/constructors/BankAccount.java create mode 100644 core-java/src/main/java/com/baeldung/constructors/Transaction.java create mode 100644 core-java/src/test/java/com/baeldung/constructors/ConstructorUnitTest.java diff --git a/core-java/src/main/java/com/baeldung/constructors/BankAccount.java b/core-java/src/main/java/com/baeldung/constructors/BankAccount.java new file mode 100644 index 0000000000..3d50e85245 --- /dev/null +++ b/core-java/src/main/java/com/baeldung/constructors/BankAccount.java @@ -0,0 +1,56 @@ +package com.baeldung.constructors; + +import java.time.LocalDateTime; + +class BankAccount { + String name; + LocalDateTime opened; + double balance; + + @Override + public String toString() { + return String.format("%s, %s, %f", this.name, this.opened.toString(), this.balance); + } + + public String getName() { + return name; + } + + public LocalDateTime getOpened() { + return opened; + } + + public double getBalance() { + return this.balance; + } +} + +class BankAccountEmptyConstructor extends BankAccount { + public BankAccountEmptyConstructor() { + this.name = ""; + this.opened = LocalDateTime.now(); + this.balance = 0.0d; + } +} + +class BankAccountParameterizedConstructor extends BankAccount { + public BankAccountParameterizedConstructor(String name, LocalDateTime opened, double balance) { + this.name = name; + this.opened = opened; + this.balance = balance; + } +} + +class BankAccountCopyConstructor extends BankAccount { + public BankAccountCopyConstructor(String name, LocalDateTime opened, double balance) { + this.name = name; + this.opened = opened; + this.balance = balance; + } + + public BankAccountCopyConstructor(BankAccount other) { + this.name = other.name; + this.opened = LocalDateTime.now(); + this.balance = 0.0f; + } +} diff --git a/core-java/src/main/java/com/baeldung/constructors/Transaction.java b/core-java/src/main/java/com/baeldung/constructors/Transaction.java new file mode 100644 index 0000000000..14704f507a --- /dev/null +++ b/core-java/src/main/java/com/baeldung/constructors/Transaction.java @@ -0,0 +1,25 @@ +package com.baeldung.constructors; + +import java.time.LocalDateTime; + +class Transaction { + final BankAccountEmptyConstructor bankAccount; + final LocalDateTime date; + final double amount; + + public Transaction(BankAccountEmptyConstructor account, LocalDateTime date, double amount) { + this.bankAccount = account; + this.date = date; + this.amount = amount; + } + + /* + * Compilation Error :'(, all final variables must be explicitly initialised. + * public Transaction() { + * } + */ + + public void invalidMethod() { + // this.amount = 102.03; // Results in a compiler error. You cannot change the value of a final variable. + } +} diff --git a/core-java/src/test/java/com/baeldung/constructors/ConstructorUnitTest.java b/core-java/src/test/java/com/baeldung/constructors/ConstructorUnitTest.java new file mode 100644 index 0000000000..2cd8832fbf --- /dev/null +++ b/core-java/src/test/java/com/baeldung/constructors/ConstructorUnitTest.java @@ -0,0 +1,53 @@ +package com.baeldung.constructors; + +import com.baeldung.constructors.*; + +import java.util.logging.Logger; +import java.time.LocalDateTime; +import java.time.Month; + +import org.junit.Test; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatCode; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +public class ConstructorUnitTest { + final static Logger LOGGER = Logger.getLogger(ConstructorUnitTest.class.getName()); + + @Test + public void givenNoExplicitContructor_whenUsed_thenFails() { + BankAccount account = new BankAccount(); + assertThatThrownBy(() -> { account.toString(); }).isInstanceOf(Exception.class); + } + + @Test + public void givenNoArgumentConstructor_whenUsed_thenSucceeds() { + BankAccountEmptyConstructor account = new BankAccountEmptyConstructor(); + assertThatCode(() -> { + account.toString(); + }).doesNotThrowAnyException(); + } + + @Test + public void givenParameterisedConstructor_whenUsed_thenSucceeds() { + LocalDateTime opened = LocalDateTime.of(2018, Month.JUNE, 29, 06, 30, 00); + BankAccountParameterizedConstructor account = + new BankAccountParameterizedConstructor("Tom", opened, 1000.0f); + + assertThatCode(() -> { + account.toString(); + }).doesNotThrowAnyException(); + } + + @Test + public void givenCopyContructor_whenUser_thenMaintainsLogic() { + LocalDateTime opened = LocalDateTime.of(2018, Month.JUNE, 29, 06, 30, 00); + BankAccountCopyConstructor account = new BankAccountCopyConstructor("Tim", opened, 1000.0f); + BankAccountCopyConstructor newAccount = new BankAccountCopyConstructor(account); + + assertThat(account.getName()).isEqualTo(newAccount.getName()); + assertThat(account.getOpened()).isNotEqualTo(newAccount.getOpened()); + + assertThat(newAccount.getBalance()).isEqualTo(0.0f); + } +} From a67c10eec7ff0d733c1ed86f6f590147c4bb7140 Mon Sep 17 00:00:00 2001 From: cror Date: Tue, 20 Nov 2018 13:01:06 +0100 Subject: [PATCH 032/146] BAEL-2388: moved examples java-collections-maps -> core-java-long. Fixing String comparisons --- core-java-lang/pom.xml | 7 +++ .../com/baeldung/equalshashcode}/Money.java | 10 ++-- .../com/baeldung/equalshashcode}/Team.java | 2 +- .../com/baeldung/equalshashcode/Voucher.java | 38 +++++++++++++++ .../baeldung/equalshashcode}/WrongTeam.java | 8 +++- .../baeldung/equalshashcode/WrongVoucher.java | 47 +++++++++++++++++++ .../equalshashcode}/MoneyUnitTest.java | 2 +- .../equalshashcode}/TeamUnitTest.java | 2 +- java-collections-maps/pom.xml | 6 --- .../com/baeldung/map/hashCode/Voucher.java | 31 ------------ .../baeldung/map/hashCode/WrongVoucher.java | 33 ------------- .../map/hashCode/equalsverifier_notes.txt | 1 - 12 files changed, 109 insertions(+), 78 deletions(-) rename {java-collections-maps/src/main/java/com/baeldung/map/hashCode => core-java-lang/src/main/java/com/baeldung/equalshashcode}/Money.java (60%) rename {java-collections-maps/src/main/java/com/baeldung/map/hashCode => core-java-lang/src/main/java/com/baeldung/equalshashcode}/Team.java (96%) create mode 100644 core-java-lang/src/main/java/com/baeldung/equalshashcode/Voucher.java rename {java-collections-maps/src/main/java/com/baeldung/map/hashCode => core-java-lang/src/main/java/com/baeldung/equalshashcode}/WrongTeam.java (67%) create mode 100644 core-java-lang/src/main/java/com/baeldung/equalshashcode/WrongVoucher.java rename {java-collections-maps/src/test/java/com/baeldung/map/hashCode => core-java-lang/src/test/java/com/baeldung/equalshashcode}/MoneyUnitTest.java (94%) rename {java-collections-maps/src/test/java/com/baeldung/map/hashCode => core-java-lang/src/test/java/com/baeldung/equalshashcode}/TeamUnitTest.java (97%) delete mode 100644 java-collections-maps/src/main/java/com/baeldung/map/hashCode/Voucher.java delete mode 100644 java-collections-maps/src/main/java/com/baeldung/map/hashCode/WrongVoucher.java delete mode 100644 java-collections-maps/src/main/java/com/baeldung/map/hashCode/equalsverifier_notes.txt diff --git a/core-java-lang/pom.xml b/core-java-lang/pom.xml index ace39de274..2f307859f1 100644 --- a/core-java-lang/pom.xml +++ b/core-java-lang/pom.xml @@ -66,6 +66,12 @@ mail ${javax.mail.version} + + nl.jqno.equalsverifier + equalsverifier + ${equalsverifier.version} + test + @@ -424,6 +430,7 @@ 3.1.1 2.0.3.RELEASE 1.6.0 + 3.0.3 diff --git a/java-collections-maps/src/main/java/com/baeldung/map/hashCode/Money.java b/core-java-lang/src/main/java/com/baeldung/equalshashcode/Money.java similarity index 60% rename from java-collections-maps/src/main/java/com/baeldung/map/hashCode/Money.java rename to core-java-lang/src/main/java/com/baeldung/equalshashcode/Money.java index 0ba494d944..60c043545d 100644 --- a/java-collections-maps/src/main/java/com/baeldung/map/hashCode/Money.java +++ b/core-java-lang/src/main/java/com/baeldung/equalshashcode/Money.java @@ -1,4 +1,4 @@ -package com.baeldung.map.hashcode; +package com.baeldung.equalshashcode; class Money { @@ -17,15 +17,19 @@ class Money { if (!(o instanceof Money)) return false; Money other = (Money)o; + boolean currencyCodeEquals = (this.currencyCode == null && other.currencyCode == null) + || (this.currencyCode != null && this.currencyCode.equals(other.currencyCode)); return this.amount == other.amount - && this.currencyCode == other.currencyCode; + && currencyCodeEquals; } @Override public int hashCode() { int result = 17; result = 31 * result + amount; - result = 31 * result + currencyCode.hashCode(); + if (currencyCode != null) { + result = 31 * result + currencyCode.hashCode(); + } return result; } diff --git a/java-collections-maps/src/main/java/com/baeldung/map/hashCode/Team.java b/core-java-lang/src/main/java/com/baeldung/equalshashcode/Team.java similarity index 96% rename from java-collections-maps/src/main/java/com/baeldung/map/hashCode/Team.java rename to core-java-lang/src/main/java/com/baeldung/equalshashcode/Team.java index 6c1473b8e9..c2dee1de6b 100644 --- a/java-collections-maps/src/main/java/com/baeldung/map/hashCode/Team.java +++ b/core-java-lang/src/main/java/com/baeldung/equalshashcode/Team.java @@ -1,4 +1,4 @@ -package com.baeldung.map.hashcode; +package com.baeldung.equalshashcode; class Team { diff --git a/core-java-lang/src/main/java/com/baeldung/equalshashcode/Voucher.java b/core-java-lang/src/main/java/com/baeldung/equalshashcode/Voucher.java new file mode 100644 index 0000000000..19f46e0358 --- /dev/null +++ b/core-java-lang/src/main/java/com/baeldung/equalshashcode/Voucher.java @@ -0,0 +1,38 @@ +package com.baeldung.equalshashcode; + +class Voucher { + + private Money value; + private String store; + + Voucher(int amount, String currencyCode, String store) { + this.value = new Money(amount, currencyCode); + this.store = store; + } + + @Override + public boolean equals(Object o) { + if (o == this) + return true; + if (!(o instanceof Voucher)) + return false; + Voucher other = (Voucher)o; + boolean valueEquals = (this.value == null && other.value == null) + || (this.value != null && this.value.equals(other.value)); + boolean storeEquals = (this.store == null && other.store == null) + || (this.store != null && this.store.equals(other.store)); + return valueEquals && storeEquals; + } + + @Override + public int hashCode() { + int result = 17; + if (this.value != null) { + result = 31 * result + value.hashCode(); + } + if (this.store != null) { + result = 31 * result + store.hashCode(); + } + return result; + } +} \ No newline at end of file diff --git a/java-collections-maps/src/main/java/com/baeldung/map/hashCode/WrongTeam.java b/core-java-lang/src/main/java/com/baeldung/equalshashcode/WrongTeam.java similarity index 67% rename from java-collections-maps/src/main/java/com/baeldung/map/hashCode/WrongTeam.java rename to core-java-lang/src/main/java/com/baeldung/equalshashcode/WrongTeam.java index 57fb218ce0..c4477aa790 100644 --- a/java-collections-maps/src/main/java/com/baeldung/map/hashCode/WrongTeam.java +++ b/core-java-lang/src/main/java/com/baeldung/equalshashcode/WrongTeam.java @@ -1,5 +1,11 @@ -package com.baeldung.map.hashcode; +package com.baeldung.equalshashcode; +/* (non-Javadoc) +* This class overrides equals, but it doesn't override hashCode. +* +* To see which problems this leads to: +* TeamUnitTest.givenMapKeyWithoutHashCode_whenSearched_thenReturnsWrongValue +*/ class WrongTeam { String city; diff --git a/core-java-lang/src/main/java/com/baeldung/equalshashcode/WrongVoucher.java b/core-java-lang/src/main/java/com/baeldung/equalshashcode/WrongVoucher.java new file mode 100644 index 0000000000..97935bf8de --- /dev/null +++ b/core-java-lang/src/main/java/com/baeldung/equalshashcode/WrongVoucher.java @@ -0,0 +1,47 @@ +package com.baeldung.equalshashcode; + +/* (non-Javadoc) +* This class extends the Money class that has overridden the equals method and once again overrides the equals method. +* +* To see which problems this leads to: +* MoneyUnitTest.givenMoneyAndVoucherInstances_whenEquals_thenReturnValuesArentSymmetric +*/ +class WrongVoucher extends Money { + + private String store; + + WrongVoucher(int amount, String currencyCode, String store) { + super(amount, currencyCode); + + this.store = store; + } + + @Override + public boolean equals(Object o) { + if (o == this) + return true; + if (!(o instanceof WrongVoucher)) + return false; + WrongVoucher other = (WrongVoucher)o; + boolean currencyCodeEquals = (this.currencyCode == null && other.currencyCode == null) + || (this.currencyCode != null && this.currencyCode.equals(other.currencyCode)); + boolean storeEquals = (this.store == null && other.store == null) + || (this.store != null && this.store.equals(other.store)); + return this.amount == other.amount + && currencyCodeEquals + && storeEquals; + } + + @Override + public int hashCode() { + int result = 17; + result = 31 * result + amount; + if (this.currencyCode != null) { + result = 31 * result + currencyCode.hashCode(); + } + if (this.store != null) { + result = 31 * result + store.hashCode(); + } + return result; + } +} \ No newline at end of file diff --git a/java-collections-maps/src/test/java/com/baeldung/map/hashCode/MoneyUnitTest.java b/core-java-lang/src/test/java/com/baeldung/equalshashcode/MoneyUnitTest.java similarity index 94% rename from java-collections-maps/src/test/java/com/baeldung/map/hashCode/MoneyUnitTest.java rename to core-java-lang/src/test/java/com/baeldung/equalshashcode/MoneyUnitTest.java index f4cba4d114..60584fdb53 100644 --- a/java-collections-maps/src/test/java/com/baeldung/map/hashCode/MoneyUnitTest.java +++ b/core-java-lang/src/test/java/com/baeldung/equalshashcode/MoneyUnitTest.java @@ -1,4 +1,4 @@ -package com.baeldung.map.hashcode; +package com.baeldung.equalshashcode; import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertFalse; diff --git a/java-collections-maps/src/test/java/com/baeldung/map/hashCode/TeamUnitTest.java b/core-java-lang/src/test/java/com/baeldung/equalshashcode/TeamUnitTest.java similarity index 97% rename from java-collections-maps/src/test/java/com/baeldung/map/hashCode/TeamUnitTest.java rename to core-java-lang/src/test/java/com/baeldung/equalshashcode/TeamUnitTest.java index 89a7462438..a2de408796 100644 --- a/java-collections-maps/src/test/java/com/baeldung/map/hashCode/TeamUnitTest.java +++ b/core-java-lang/src/test/java/com/baeldung/equalshashcode/TeamUnitTest.java @@ -1,4 +1,4 @@ -package com.baeldung.map.hashcode; +package com.baeldung.equalshashcode; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; diff --git a/java-collections-maps/pom.xml b/java-collections-maps/pom.xml index 6af8f7a5c6..0803866c51 100644 --- a/java-collections-maps/pom.xml +++ b/java-collections-maps/pom.xml @@ -41,12 +41,6 @@ streamex 0.6.5 - - nl.jqno.equalsverifier - equalsverifier - 3.0.3 - test - diff --git a/java-collections-maps/src/main/java/com/baeldung/map/hashCode/Voucher.java b/java-collections-maps/src/main/java/com/baeldung/map/hashCode/Voucher.java deleted file mode 100644 index b4536b38ea..0000000000 --- a/java-collections-maps/src/main/java/com/baeldung/map/hashCode/Voucher.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.baeldung.map.hashcode; - -class Voucher { - - private Money value; - private String store; - - Voucher(int amount, String currencyCode, String store) { - this.value = new Money(amount, currencyCode); - this.store = store; - } - - @Override - public boolean equals(Object o) { - if (o == this) - return true; - if (!(o instanceof Voucher)) - return false; - Voucher other = (Voucher)o; - return this.value == other.value - && this.store == other.store; - } - - @Override - public int hashCode() { - int result = 17; - result = 31 * result + value.hashCode(); - result = 31 * result + store.hashCode(); - return result; - } -} \ No newline at end of file diff --git a/java-collections-maps/src/main/java/com/baeldung/map/hashCode/WrongVoucher.java b/java-collections-maps/src/main/java/com/baeldung/map/hashCode/WrongVoucher.java deleted file mode 100644 index 03122c7cc8..0000000000 --- a/java-collections-maps/src/main/java/com/baeldung/map/hashCode/WrongVoucher.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.baeldung.map.hashcode; - -class WrongVoucher extends Money { - - private String store; - - WrongVoucher(int amount, String currencyCode, String store) { - super(amount, currencyCode); - - this.store = store; - } - - @Override - public boolean equals(Object o) { - if (o == this) - return true; - if (!(o instanceof WrongVoucher)) - return false; - WrongVoucher other = (WrongVoucher)o; - return this.amount == other.amount - && this.currencyCode == other.currencyCode - && this.store == other.store; - } - - @Override - public int hashCode() { - int result = 17; - result = 31 * result + amount; - result = 31 * result + currencyCode.hashCode(); - result = 31 * result + store.hashCode(); - return result; - } -} \ No newline at end of file diff --git a/java-collections-maps/src/main/java/com/baeldung/map/hashCode/equalsverifier_notes.txt b/java-collections-maps/src/main/java/com/baeldung/map/hashCode/equalsverifier_notes.txt deleted file mode 100644 index adc14f393a..0000000000 --- a/java-collections-maps/src/main/java/com/baeldung/map/hashCode/equalsverifier_notes.txt +++ /dev/null @@ -1 +0,0 @@ - Non-nullity: hashCode throws NullPointerException on field city. From 6045b4291a618d4b00046aa9ae495f1ff325996b Mon Sep 17 00:00:00 2001 From: Jan Hauer Date: Thu, 8 Nov 2018 10:43:42 +0100 Subject: [PATCH 033/146] BAEL-2305 Adds array intersection operations --- .../array/operations/ArrayOperations.java | 14 ++++ .../operations/IntersectionUnitTest.java | 66 +++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 core-java-arrays/src/test/java/com/baeldung/array/operations/IntersectionUnitTest.java diff --git a/core-java-arrays/src/main/java/com/baeldung/array/operations/ArrayOperations.java b/core-java-arrays/src/main/java/com/baeldung/array/operations/ArrayOperations.java index 98155ed952..d8cc0afd61 100644 --- a/core-java-arrays/src/main/java/com/baeldung/array/operations/ArrayOperations.java +++ b/core-java-arrays/src/main/java/com/baeldung/array/operations/ArrayOperations.java @@ -4,11 +4,13 @@ import java.lang.reflect.Array; import java.util.Arrays; import java.util.HashSet; import java.util.LinkedHashSet; +import java.util.LinkedList; import java.util.Random; import java.util.Set; import java.util.function.Function; import java.util.function.IntPredicate; import java.util.function.Predicate; +import java.util.stream.Stream; import org.apache.commons.lang3.ArrayUtils; @@ -194,4 +196,16 @@ public class ArrayOperations { public static T getRandomFromObjectArray(T[] array) { return array[new Random().nextInt(array.length)]; } + + public static Integer[] intersectionSimple(final Integer[] a, final Integer[] b){ + return Stream.of(a).filter(Arrays.asList(b)::contains).toArray(Integer[]::new); + } + + public static Integer[] intersectionSet(final Integer[] a, final Integer[] b){ + return Stream.of(a).filter(Arrays.asList(b)::contains).distinct().toArray(Integer[]::new); + } + + public static Integer[] intersectionMultiSet(final Integer[] a, final Integer[] b){ + return Stream.of(a).filter(new LinkedList<>(Arrays.asList(b))::remove).toArray(Integer[]::new); + } } diff --git a/core-java-arrays/src/test/java/com/baeldung/array/operations/IntersectionUnitTest.java b/core-java-arrays/src/test/java/com/baeldung/array/operations/IntersectionUnitTest.java new file mode 100644 index 0000000000..3c61060ea8 --- /dev/null +++ b/core-java-arrays/src/test/java/com/baeldung/array/operations/IntersectionUnitTest.java @@ -0,0 +1,66 @@ +package com.baeldung.array.operations; + +import org.junit.jupiter.api.Test; + +import static com.baeldung.array.operations.ArrayOperations.intersectionMultiSet; +import static com.baeldung.array.operations.ArrayOperations.intersectionSet; +import static com.baeldung.array.operations.ArrayOperations.intersectionSimple; +import static org.assertj.core.api.Assertions.assertThat; + +class IntersectionUnitTest { + private static final Integer[] a = { 1, 3, 2 }; + private static final Integer[] b = { 4, 3, 2, 4, 2, 3, 4, 4, 3 }; + private static final Integer[] c = { 1, 3, 2, 3, 3, 2 }; + + @Test + void whenIntersectionSimpleIsUsed_thenCommonEntriesAreInTheResult() { + assertThat(intersectionSimple(a, b)).isEqualTo(new Integer[] { 3, 2 }); + assertThat(intersectionSimple(b, a)).isEqualTo(new Integer[] { 3, 2, 2, 3, 3 }); + } + + @Test + void whenIntersectionSimpleIsUsedWithAnArrayAndItself_thenTheResultIsTheIdentity() { + assertThat(intersectionSimple(b, b)).isEqualTo(b); + assertThat(intersectionSimple(a, a)).isEqualTo(a); + } + + @Test + void whenIntersectionSetIsUsed_thenCommonEntriesAreInTheResult() { + assertThat(intersectionSet(b, a)).isEqualTo(new Integer[] { 3, 2 }); + } + + @Test + void whenIntersectionSetIsUsed_thenTheNumberOfEntriesDoesNotChangeWithTheParameterOrder() { + assertThat(intersectionSet(a, b)).isEqualTo(new Integer[] { 3, 2 }); + assertThat(intersectionSet(b, a)).isEqualTo(new Integer[] { 3, 2 }); + } + + @Test + void whenIntersectionSetIsUsedWithAnArrayAndWithItself_andTheInputHasNoDuplicateEntries_ThenTheResultIsTheIdentity() { + assertThat(intersectionSet(a, a)).isEqualTo(a); + } + + @Test + void whenIntersectionSetIsUsedWithAnArrayAndWithItself_andTheInputHasDuplicateEntries_ThenTheResultIsNotTheIdentity() { + assertThat(intersectionSet(b, b)).isNotEqualTo(b); + } + + @Test + void whenMultiSetIsUsed_thenCommonEntriesAreInTheResult() { + assertThat(intersectionMultiSet(b, a)).isEqualTo(new Integer[] { 3, 2 }); + } + + @Test + void whenIntersectionMultiSetIsUsed_thenTheNumberOfEntriesDoesNotChangeWithTheParameterOrder() { + assertThat(intersectionMultiSet(a, b)).isEqualTo(new Integer[] { 3, 2 }); + assertThat(intersectionMultiSet(b, a)).isEqualTo(new Integer[] { 3, 2 }); + assertThat(intersectionMultiSet(b, c)).isEqualTo(new Integer[] { 3, 2, 2, 3, 3 }); + assertThat(intersectionMultiSet(c, b)).isEqualTo(new Integer[] { 3, 2, 3, 3, 2 }); + } + + @Test + void whenIntersectionMultiSetIsUsedWithAnArrayAndWithItself_ThenTheResultIsTheIdentity() { + assertThat(intersectionMultiSet(b, b)).isEqualTo(b); + assertThat(intersectionMultiSet(a, a)).isEqualTo(a); + } +} \ No newline at end of file From 2c4cefe51693fb961d15b4ea5942868909603c9a Mon Sep 17 00:00:00 2001 From: Vizsoro Date: Tue, 20 Nov 2018 19:33:54 +0100 Subject: [PATCH 034/146] Arrow in Kotlin Issue: BAEL-1495 --- kotlin-libraries/pom.xml | 7 + .../FunctionalErrorHandlingWithEither.kt | 54 +++++++ .../FunctionalErrorHandlingWithOption.kt | 46 ++++++ .../kotlin/arrow/FunctionalDataTypes.kt | 143 ++++++++++++++++++ .../FunctionalErrorHandlingWithEitherTest.kt | 68 +++++++++ .../FunctionalErrorHandlingWithOptionTest.kt | 34 +++++ 6 files changed, 352 insertions(+) create mode 100644 kotlin-libraries/src/main/kotlin/com/baeldung/kotlin/arrow/FunctionalErrorHandlingWithEither.kt create mode 100644 kotlin-libraries/src/main/kotlin/com/baeldung/kotlin/arrow/FunctionalErrorHandlingWithOption.kt create mode 100644 kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/arrow/FunctionalDataTypes.kt create mode 100644 kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/arrow/FunctionalErrorHandlingWithEitherTest.kt create mode 100644 kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/arrow/FunctionalErrorHandlingWithOptionTest.kt diff --git a/kotlin-libraries/pom.xml b/kotlin-libraries/pom.xml index c5b7fed951..92a643e458 100644 --- a/kotlin-libraries/pom.xml +++ b/kotlin-libraries/pom.xml @@ -87,6 +87,13 @@ h2 ${h2database.version} + + + io.arrow-kt + arrow-core + 0.7.3 + + diff --git a/kotlin-libraries/src/main/kotlin/com/baeldung/kotlin/arrow/FunctionalErrorHandlingWithEither.kt b/kotlin-libraries/src/main/kotlin/com/baeldung/kotlin/arrow/FunctionalErrorHandlingWithEither.kt new file mode 100644 index 0000000000..75dfb9a2a4 --- /dev/null +++ b/kotlin-libraries/src/main/kotlin/com/baeldung/kotlin/arrow/FunctionalErrorHandlingWithEither.kt @@ -0,0 +1,54 @@ +package com.baeldung.kotlin.arrow + +import arrow.core.Either +import arrow.core.filterOrElse +import kotlin.math.sqrt + +class FunctionalErrorHandlingWithEither { + + sealed class ComputeProblem { + object OddNumber : ComputeProblem() + object NotANumber : ComputeProblem() + } + + fun parseInput(s : String) : Either = Either.cond(s.toIntOrNull() != null, {-> s.toInt()}, {->ComputeProblem.NotANumber} ) + + fun isEven(x : Int) : Boolean = x % 2 == 0 + + fun biggestDivisor(x: Int) : Int = biggestDivisor(x, 2) + + fun biggestDivisor(x : Int, y : Int) : Int { + if(x == y){ + return 1; + } + if(x % y == 0){ + return x / y; + } + return biggestDivisor(x, y+1) + } + + fun isSquareNumber(x : Int) : Boolean { + val sqrt: Double = sqrt(x.toDouble()) + return sqrt % 1.0 == 0.0 + } + + fun computeWithEither(input : String) : Either { + return parseInput(input) + .filterOrElse(::isEven) {->ComputeProblem.OddNumber} + .map (::biggestDivisor) + .map (::isSquareNumber) + } + + fun computeWithEitherClient(input : String) { + val computeWithEither = computeWithEither(input) + + when(computeWithEither){ + is Either.Right -> "The greatest divisor is square number: ${computeWithEither.b}" + is Either.Left -> when(computeWithEither.a){ + is ComputeProblem.NotANumber -> "Wrong input! Not a number!" + is ComputeProblem.OddNumber -> "It is an odd number!" + } + } + } + +} \ No newline at end of file diff --git a/kotlin-libraries/src/main/kotlin/com/baeldung/kotlin/arrow/FunctionalErrorHandlingWithOption.kt b/kotlin-libraries/src/main/kotlin/com/baeldung/kotlin/arrow/FunctionalErrorHandlingWithOption.kt new file mode 100644 index 0000000000..5fddd1d88e --- /dev/null +++ b/kotlin-libraries/src/main/kotlin/com/baeldung/kotlin/arrow/FunctionalErrorHandlingWithOption.kt @@ -0,0 +1,46 @@ +package com.baeldung.kotlin.arrow + +import arrow.core.None +import arrow.core.Option +import arrow.core.Some +import kotlin.math.sqrt + +class FunctionalErrorHandlingWithOption { + + fun parseInput(s : String) : Option = Option.fromNullable(s.toIntOrNull()) + + fun isEven(x : Int) : Boolean = x % 2 == 0 + + fun biggestDivisor(x: Int) : Int = biggestDivisor(x, 2) + + fun biggestDivisor(x : Int, y : Int) : Int { + if(x == y){ + return 1; + } + if(x % y == 0){ + return x / y; + } + return biggestDivisor(x, y+1) + } + + fun isSquareNumber(x : Int) : Boolean { + val sqrt: Double = sqrt(x.toDouble()) + return sqrt % 1.0 == 0.0 + } + + fun computeWithOption(input : String) : Option { + return parseInput(input) + .filter(::isEven) + .map(::biggestDivisor) + .map(::isSquareNumber) + } + + fun computeWithOptionClient(input : String) : String{ + val computeOption = computeWithOption(input) + + return when(computeOption){ + is None -> "Not an even number!" + is Some -> "The greatest divisor is square number: ${computeOption.t}" + } + } +} \ No newline at end of file diff --git a/kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/arrow/FunctionalDataTypes.kt b/kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/arrow/FunctionalDataTypes.kt new file mode 100644 index 0000000000..692425ee07 --- /dev/null +++ b/kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/arrow/FunctionalDataTypes.kt @@ -0,0 +1,143 @@ +package com.baeldung.kotlin.arrow + +import arrow.core.* +import org.junit.Assert +import org.junit.Test + +class FunctionalDataTypes { + + @Test + fun whenIdCreated_thanValueIsPresent(){ + val id = Id("foo") + val justId = Id.just("foo"); + + Assert.assertEquals("foo", id.extract()) + Assert.assertEquals(justId, id) + } + + fun length(s : String) : Int = s.length + + fun isBigEnough(i : Int) : Boolean = i > 10 + + @Test + fun whenIdCreated_thanMapIsAssociative(){ + val foo = Id("foo") + + val map1 = foo.map(::length) + .map(::isBigEnough) + val map2 = foo.map { s -> isBigEnough(length(s)) } + + Assert.assertEquals(map1, map2) + } + + fun lengthId(s : String) : Id = Id.just(length(s)) + + fun isBigEnoughId(i : Int) : Id = Id.just(isBigEnough(i)) + + @Test + fun whenIdCreated_thanFlatMapIsAssociative(){ + val bar = Id("bar") + + val flatMap = bar.flatMap(::lengthId) + .flatMap(::isBigEnoughId) + val flatMap1 = bar.flatMap { s -> lengthId(s).flatMap(::isBigEnoughId) } + + Assert.assertEquals(flatMap, flatMap1) + } + + @Test + fun whenOptionCreated_thanValueIsPresent(){ + val factory = Option.just(42) + val constructor = Option(42) + val emptyOptional = Option.empty() + val fromNullable = Option.fromNullable(null) + + Assert.assertEquals(42, factory.getOrElse { -1 }) + Assert.assertEquals(factory, constructor) + Assert.assertEquals(emptyOptional, fromNullable) + } + + @Test + fun whenOptionCreated_thanConstructorDifferFromFactory(){ + val constructor : Option = Option(null) + val fromNullable : Option = Option.fromNullable(null) + + try{ + constructor.map { s -> s!!.length } + Assert.fail() + } catch (e : KotlinNullPointerException){ + fromNullable.map { s->s!!.length } + } + Assert.assertNotEquals(constructor, fromNullable) + } + + fun wrapper(x : Integer?) : Option = if (x == null) Option.just(-1) else Option.just(x.toInt()) + + @Test + fun whenOptionFromNullableCreated_thanItBreaksLeftIdentity(){ + val optionFromNull = Option.fromNullable(null) + + Assert.assertNotEquals(optionFromNull.flatMap(::wrapper), wrapper(null)) + } + + @Test + fun whenEitherCreated_thanOneValueIsPresent(){ + val rightOnly : Either = Either.right(42) + val leftOnly : Either = Either.left("foo") + + Assert.assertTrue(rightOnly.isRight()) + Assert.assertTrue(leftOnly.isLeft()) + Assert.assertEquals(42, rightOnly.getOrElse { -1 }) + Assert.assertEquals(-1, leftOnly.getOrElse { -1 }) + + Assert.assertEquals(0, rightOnly.map { it % 2 }.getOrElse { -1 }) + Assert.assertEquals(-1, leftOnly.map { it % 2 }.getOrElse { -1 }) + Assert.assertTrue(rightOnly.flatMap { Either.Right(it % 2) }.isRight()) + Assert.assertTrue(leftOnly.flatMap { Either.Right(it % 2) }.isLeft()) + } + + @Test + fun whenEvalNowUsed_thenMapEvaluatedLazily(){ + val now = Eval.now(1) + Assert.assertEquals(1, now.value()) + + var counter : Int = 0 + val map = now.map { x -> counter++; x+1 } + Assert.assertEquals(0, counter) + + val value = map.value() + Assert.assertEquals(2, value) + Assert.assertEquals(1, counter) + } + + @Test + fun whenEvalLaterUsed_theResultIsMemoized(){ + var counter : Int = 0 + val later = Eval.later { counter++; counter } + Assert.assertEquals(0, counter) + + val firstValue = later.value() + Assert.assertEquals(1, firstValue) + Assert.assertEquals(1, counter) + + val secondValue = later.value() + Assert.assertEquals(1, secondValue) + Assert.assertEquals(1, counter) + } + + @Test + fun whenEvalAlwaysUsed_theResultIsNotMemoized(){ + var counter : Int = 0 + val later = Eval.always { counter++; counter } + Assert.assertEquals(0, counter) + + val firstValue = later.value() + Assert.assertEquals(1, firstValue) + Assert.assertEquals(1, counter) + + val secondValue = later.value() + Assert.assertEquals(2, secondValue) + Assert.assertEquals(2, counter) + } + +} \ No newline at end of file diff --git a/kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/arrow/FunctionalErrorHandlingWithEitherTest.kt b/kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/arrow/FunctionalErrorHandlingWithEitherTest.kt new file mode 100644 index 0000000000..47fbf825a0 --- /dev/null +++ b/kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/arrow/FunctionalErrorHandlingWithEitherTest.kt @@ -0,0 +1,68 @@ +package com.baeldung.kotlin.arrow + +import arrow.core.Either +import com.baeldung.kotlin.arrow.FunctionalErrorHandlingWithEither.ComputeProblem.NotANumber +import com.baeldung.kotlin.arrow.FunctionalErrorHandlingWithEither.ComputeProblem.OddNumber +import org.junit.Assert +import org.junit.Test + +class FunctionalErrorHandlingWithEitherTest { + + val operator = FunctionalErrorHandlingWithEither() + + @Test + fun givenInvalidInput_whenComputeInvoked_NotANumberIsPresent(){ + val computeWithEither = operator.computeWithEither("bar") + + Assert.assertTrue(computeWithEither.isLeft()) + when(computeWithEither){ + is Either.Left -> when(computeWithEither.a){ + NotANumber -> "Ok." + else -> Assert.fail() + } + else -> Assert.fail() + } + } + + @Test + fun givenOddNumberInput_whenComputeInvoked_OddNumberIsPresent(){ + val computeWithEither = operator.computeWithEither("121") + + Assert.assertTrue(computeWithEither.isLeft()) + when(computeWithEither){ + is Either.Left -> when(computeWithEither.a){ + OddNumber -> "Ok." + else -> Assert.fail() + } + else -> Assert.fail() + } + } + + @Test + fun givenEvenNumberWithoutSquare_whenComputeInvoked_OddNumberIsPresent(){ + val computeWithEither = operator.computeWithEither("100") + + Assert.assertTrue(computeWithEither.isRight()) + when(computeWithEither){ + is Either.Right -> when(computeWithEither.b){ + false -> "Ok." + else -> Assert.fail() + } + else -> Assert.fail() + } + } + + @Test + fun givenEvenNumberWithSquare_whenComputeInvoked_OddNumberIsPresent(){ + val computeWithEither = operator.computeWithEither("98") + + Assert.assertTrue(computeWithEither.isRight()) + when(computeWithEither){ + is Either.Right -> when(computeWithEither.b){ + true -> "Ok." + else -> Assert.fail() + } + else -> Assert.fail() + } + } +} \ No newline at end of file diff --git a/kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/arrow/FunctionalErrorHandlingWithOptionTest.kt b/kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/arrow/FunctionalErrorHandlingWithOptionTest.kt new file mode 100644 index 0000000000..3ca4cd033f --- /dev/null +++ b/kotlin-libraries/src/test/kotlin/com/baeldung/kotlin/arrow/FunctionalErrorHandlingWithOptionTest.kt @@ -0,0 +1,34 @@ +package com.baeldung.kotlin.arrow + +import org.junit.Assert +import org.junit.Test + +class FunctionalErrorHandlingWithOptionTest { + + val operator = FunctionalErrorHandlingWithOption() + + @Test + fun givenInvalidInput_thenErrorMessageIsPresent(){ + val useComputeOption = operator.computeWithOptionClient("foo") + Assert.assertEquals("Not an even number!", useComputeOption) + } + + @Test + fun givenOddNumberInput_thenErrorMessageIsPresent(){ + val useComputeOption = operator.computeWithOptionClient("539") + Assert.assertEquals("Not an even number!",useComputeOption) + } + + @Test + fun givenEvenNumberInputWithNonSquareNum_thenFalseMessageIsPresent(){ + val useComputeOption = operator.computeWithOptionClient("100") + Assert.assertEquals("The greatest divisor is square number: false",useComputeOption) + } + + @Test + fun givenEvenNumberInputWithSquareNum_thenTrueMessageIsPresent(){ + val useComputeOption = operator.computeWithOptionClient("242") + Assert.assertEquals("The greatest divisor is square number: true",useComputeOption) + } + +} \ No newline at end of file From b0ea0e56483771e87333c6ddaec6ab7b48997bb6 Mon Sep 17 00:00:00 2001 From: Kevin Gilmore Date: Tue, 20 Nov 2018 21:28:01 -0600 Subject: [PATCH 035/146] BAEL-2312: add link back to article --- core-java/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java/README.md b/core-java/README.md index 11d9fd2ee0..7617897e95 100644 --- a/core-java/README.md +++ b/core-java/README.md @@ -85,3 +85,4 @@ - [A Guide to SimpleDateFormat](https://www.baeldung.com/java-simple-date-format) - [SSL Handshake Failures](https://www.baeldung.com/java-ssl-handshake-failures) - [Implementing a Binary Tree in Java](https://www.baeldung.com/java-binary-tree) +- [Abstract Classes in Java](https://www.baeldung.com/java-abstract-class) From 7e9f96117e5cc9becca1660adc855e07744f3b36 Mon Sep 17 00:00:00 2001 From: KevinGilmore Date: Tue, 20 Nov 2018 21:33:41 -0600 Subject: [PATCH 036/146] BAEL-2312 update README (#5744) * BAEL-2015: add link back to article * BAEL-2166 BAEL-2302 add links back to articles * BAEL-2312: add link back to article --- core-java/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java/README.md b/core-java/README.md index 11d9fd2ee0..7617897e95 100644 --- a/core-java/README.md +++ b/core-java/README.md @@ -85,3 +85,4 @@ - [A Guide to SimpleDateFormat](https://www.baeldung.com/java-simple-date-format) - [SSL Handshake Failures](https://www.baeldung.com/java-ssl-handshake-failures) - [Implementing a Binary Tree in Java](https://www.baeldung.com/java-binary-tree) +- [Abstract Classes in Java](https://www.baeldung.com/java-abstract-class) From cf602faff9a5d2971f28c853374cb90066108831 Mon Sep 17 00:00:00 2001 From: Loredana Date: Thu, 22 Nov 2018 00:37:23 +0200 Subject: [PATCH 037/146] revert boot 2.1 upgrade --- parent-boot-2/pom.xml | 5 +++-- .../security/SpringSecurity5Application.java | 11 ++++++----- .../Spring5ReactiveServerClientIntegrationTest.java | 13 +++++++------ spring-5-security/pom.xml | 4 ++-- spring-data-rest/pom.xml | 4 ++++ spring-security-mvc-boot/pom.xml | 2 +- spring-security-sso/pom.xml | 4 +++- .../spring-security-sso-auth-server/pom.xml | 8 ++++---- .../spring-security-sso-ui-2/pom.xml | 4 ++-- spring-security-sso/spring-security-sso-ui/pom.xml | 4 ++-- spring-security-thymeleaf/pom.xml | 2 +- 11 files changed, 35 insertions(+), 26 deletions(-) diff --git a/parent-boot-2/pom.xml b/parent-boot-2/pom.xml index bb89cb2729..67837e1a4e 100644 --- a/parent-boot-2/pom.xml +++ b/parent-boot-2/pom.xml @@ -77,7 +77,8 @@ 3.1.0 1.0.11.RELEASE - 2.1.0.RELEASE - 2.1.0.RELEASE + 2.0.5.RELEASE + + diff --git a/spring-5-reactive-security/src/main/java/com/baeldung/reactive/security/SpringSecurity5Application.java b/spring-5-reactive-security/src/main/java/com/baeldung/reactive/security/SpringSecurity5Application.java index ba913bc2d7..f2963c4fa5 100644 --- a/spring-5-reactive-security/src/main/java/com/baeldung/reactive/security/SpringSecurity5Application.java +++ b/spring-5-reactive-security/src/main/java/com/baeldung/reactive/security/SpringSecurity5Application.java @@ -8,8 +8,8 @@ import org.springframework.http.server.reactive.HttpHandler; import org.springframework.http.server.reactive.ReactorHttpHandlerAdapter; import org.springframework.web.reactive.config.EnableWebFlux; import org.springframework.web.server.adapter.WebHttpHandlerBuilder; -import reactor.netty.DisposableServer; -import reactor.netty.http.server.HttpServer; +import reactor.ipc.netty.NettyContext; +import reactor.ipc.netty.http.server.HttpServer; @ComponentScan(basePackages = {"com.baeldung.reactive.security"}) @EnableWebFlux @@ -18,16 +18,17 @@ public class SpringSecurity5Application { public static void main(String[] args) { try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(SpringSecurity5Application.class)) { - context.getBean(DisposableServer.class).onDispose().block(); + context.getBean(NettyContext.class).onClose().block(); } } @Bean - public DisposableServer nettyContext(ApplicationContext context) { + public NettyContext nettyContext(ApplicationContext context) { HttpHandler handler = WebHttpHandlerBuilder.applicationContext(context) .build(); ReactorHttpHandlerAdapter adapter = new ReactorHttpHandlerAdapter(handler); - return HttpServer.create().host("localhost").port(8080).handle(adapter).bind().block(); + HttpServer httpServer = HttpServer.create("localhost", 8080); + return httpServer.newHandler(adapter).block(); } } diff --git a/spring-5-reactive/src/test/java/com/baeldung/reactive/Spring5ReactiveServerClientIntegrationTest.java b/spring-5-reactive/src/test/java/com/baeldung/reactive/Spring5ReactiveServerClientIntegrationTest.java index 384600994e..5ebfa39358 100644 --- a/spring-5-reactive/src/test/java/com/baeldung/reactive/Spring5ReactiveServerClientIntegrationTest.java +++ b/spring-5-reactive/src/test/java/com/baeldung/reactive/Spring5ReactiveServerClientIntegrationTest.java @@ -10,8 +10,8 @@ import org.springframework.web.reactive.function.server.RouterFunctions; import org.springframework.web.reactive.function.server.ServerResponse; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; -import reactor.netty.DisposableServer; -import reactor.netty.http.server.HttpServer; +import reactor.ipc.netty.NettyContext; +import reactor.ipc.netty.http.server.HttpServer; import java.time.Duration; @@ -19,11 +19,11 @@ import static org.springframework.web.reactive.function.server.RequestPredicates import static org.springframework.web.reactive.function.server.RequestPredicates.POST; public class Spring5ReactiveServerClientIntegrationTest { - private static DisposableServer nettyServer; + private static NettyContext nettyContext; @BeforeAll public static void setUp() throws Exception { - HttpServer server = HttpServer.create().host("localhost").port(8080); + HttpServer server = HttpServer.create("localhost", 8080); RouterFunction route = RouterFunctions.route(POST("/task/process"), request -> ServerResponse.ok() .body(request.bodyToFlux(Task.class) .map(ll -> new Task("TaskName", 1)), Task.class)) @@ -31,12 +31,13 @@ public class Spring5ReactiveServerClientIntegrationTest { .body(Mono.just("server is alive"), String.class))); HttpHandler httpHandler = RouterFunctions.toHttpHandler(route); ReactorHttpHandlerAdapter adapter = new ReactorHttpHandlerAdapter(httpHandler); - nettyServer = server.handle(adapter).bind().block(); + nettyContext = server.newHandler(adapter) + .block(); } @AfterAll public static void shutDown() { - nettyServer.dispose(); + nettyContext.dispose(); } // @Test diff --git a/spring-5-security/pom.xml b/spring-5-security/pom.xml index da62f39fa9..f5fb359896 100644 --- a/spring-5-security/pom.xml +++ b/spring-5-security/pom.xml @@ -31,14 +31,14 @@ org.thymeleaf.extras - thymeleaf-extras-springsecurity5 + thymeleaf-extras-springsecurity4 org.springframework.security.oauth.boot spring-security-oauth2-autoconfigure - ${oauth-auto.version} + 2.0.1.RELEASE org.springframework.security diff --git a/spring-data-rest/pom.xml b/spring-data-rest/pom.xml index a756ef0497..a6f12e1904 100644 --- a/spring-data-rest/pom.xml +++ b/spring-data-rest/pom.xml @@ -42,4 +42,8 @@ ${project.artifactId} + + 2.1.0.RELEASE + + diff --git a/spring-security-mvc-boot/pom.xml b/spring-security-mvc-boot/pom.xml index 0a40b0b324..2427d0de1a 100644 --- a/spring-security-mvc-boot/pom.xml +++ b/spring-security-mvc-boot/pom.xml @@ -36,7 +36,7 @@ org.thymeleaf.extras - thymeleaf-extras-springsecurity5 + thymeleaf-extras-springsecurity4 org.springframework.boot diff --git a/spring-security-sso/pom.xml b/spring-security-sso/pom.xml index 7761919ca7..6e61da1519 100644 --- a/spring-security-sso/pom.xml +++ b/spring-security-sso/pom.xml @@ -23,6 +23,8 @@ 3.1.0 + 2.3.3.RELEASE + 2.0.1.RELEASE - \ No newline at end of file + diff --git a/spring-security-sso/spring-security-sso-auth-server/pom.xml b/spring-security-sso/spring-security-sso-auth-server/pom.xml index c0ad6dee2e..ff76f377c6 100644 --- a/spring-security-sso/spring-security-sso-auth-server/pom.xml +++ b/spring-security-sso/spring-security-sso-auth-server/pom.xml @@ -20,10 +20,10 @@ - org.springframework.security.oauth.boot - spring-security-oauth2-autoconfigure - ${oauth-auto.version} + org.springframework.security.oauth + spring-security-oauth2 + ${oauth.version} - \ No newline at end of file + diff --git a/spring-security-sso/spring-security-sso-ui-2/pom.xml b/spring-security-sso/spring-security-sso-ui-2/pom.xml index 5881409c3a..1f9a5754ae 100644 --- a/spring-security-sso/spring-security-sso-ui-2/pom.xml +++ b/spring-security-sso/spring-security-sso-ui-2/pom.xml @@ -37,9 +37,9 @@ org.thymeleaf.extras - thymeleaf-extras-springsecurity5 + thymeleaf-extras-springsecurity4 - \ No newline at end of file + diff --git a/spring-security-sso/spring-security-sso-ui/pom.xml b/spring-security-sso/spring-security-sso-ui/pom.xml index 3e85eb4737..56131749ba 100644 --- a/spring-security-sso/spring-security-sso-ui/pom.xml +++ b/spring-security-sso/spring-security-sso-ui/pom.xml @@ -38,9 +38,9 @@ org.thymeleaf.extras - thymeleaf-extras-springsecurity5 + thymeleaf-extras-springsecurity4 - \ No newline at end of file + diff --git a/spring-security-thymeleaf/pom.xml b/spring-security-thymeleaf/pom.xml index d8b476683a..5b7715bdeb 100644 --- a/spring-security-thymeleaf/pom.xml +++ b/spring-security-thymeleaf/pom.xml @@ -43,7 +43,7 @@ org.thymeleaf.extras - thymeleaf-extras-springsecurity5 + thymeleaf-extras-springsecurity4 From 9726c99c31a163f0d34f88c409d621286e57ae64 Mon Sep 17 00:00:00 2001 From: Kuba Date: Thu, 22 Nov 2018 03:28:17 +0100 Subject: [PATCH 038/146] BAEL-2279 - Logging reactive sequence (#5667) * BAEL-2279 - Logging reactive sequence * BAEL-2279 - Logging reactive sequence * Format fix. * Add all examples. Fix formatting. * BAEL 2279 - rename file, formatting fixes, update deps. --- logging-modules/log4j/pom.xml | 10 ++++++++- .../webFluxLogging/WebFluxLoggingExample.java | 21 +++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 logging-modules/log4j/src/main/java/com/baeldung/webFluxLogging/WebFluxLoggingExample.java diff --git a/logging-modules/log4j/pom.xml b/logging-modules/log4j/pom.xml index 432295fc62..1b27e03445 100644 --- a/logging-modules/log4j/pom.xml +++ b/logging-modules/log4j/pom.xml @@ -1,5 +1,6 @@ - 4.0.0 com.baeldung @@ -43,6 +44,12 @@ disruptor ${disruptor.version} + + + org.springframework.boot + spring-boot-starter-webflux + ${spring-boot.version} + @@ -50,6 +57,7 @@ 2.7 2.7 3.3.6 + 2.1.0.RELEASE \ No newline at end of file diff --git a/logging-modules/log4j/src/main/java/com/baeldung/webFluxLogging/WebFluxLoggingExample.java b/logging-modules/log4j/src/main/java/com/baeldung/webFluxLogging/WebFluxLoggingExample.java new file mode 100644 index 0000000000..f429fd57f3 --- /dev/null +++ b/logging-modules/log4j/src/main/java/com/baeldung/webFluxLogging/WebFluxLoggingExample.java @@ -0,0 +1,21 @@ +package com.baeldung.webFluxLogging; + +import reactor.core.publisher.Flux; + +public class WebFluxLoggingExample { + + public static void main(String[] args) { + Flux reactiveStream = Flux.range(1, 5).log(); + + reactiveStream.subscribe(); + + reactiveStream = Flux.range(1, 5).log().take(3); + + reactiveStream.subscribe(); + + reactiveStream = Flux.range(1, 5).take(3).log(); + + reactiveStream.subscribe(); + } + +} From 31858afca7598cf4c5b8e305f7fa4cb113d340d5 Mon Sep 17 00:00:00 2001 From: charlesgonzales <39999268+charlesgonzales@users.noreply.github.com> Date: Thu, 22 Nov 2018 12:49:54 +0800 Subject: [PATCH 039/146] Bi-monthly test failure - fix (BAEL-10330) (#5736) * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.md * Update README.MD * Update README.md * Create README.md * Update README.md * Update README.md * Update README.md * Update README.md --- algorithms-miscellaneous-2/README.md | 1 + core-java-10/README.md | 1 + core-java-8/README.md | 1 + core-java-collections/README.md | 1 + core-java-io/README.md | 1 + core-java/README.md | 2 ++ java-dates/README.md | 1 + persistence-modules/spring-boot-persistence/README.MD | 1 + persistence-modules/spring-data-jpa/README.md | 1 + persistence-modules/spring-data-mongodb/README.md | 1 + spring-5-reactive-oauth/README.md | 3 +++ spring-all/README.md | 1 + spring-cloud/README.md | 1 + spring-rest-template/README.md | 1 + spring-rest/README.md | 1 + 15 files changed, 18 insertions(+) create mode 100644 spring-5-reactive-oauth/README.md diff --git a/algorithms-miscellaneous-2/README.md b/algorithms-miscellaneous-2/README.md index 6772a94a8d..d693a44f66 100644 --- a/algorithms-miscellaneous-2/README.md +++ b/algorithms-miscellaneous-2/README.md @@ -17,3 +17,4 @@ - [Round Up to the Nearest Hundred](https://www.baeldung.com/java-round-up-nearest-hundred) - [Calculate Percentage in Java](https://www.baeldung.com/java-calculate-percentage) - [Converting Between Byte Arrays and Hexadecimal Strings in Java](https://www.baeldung.com/java-byte-arrays-hex-strings) +- [Convert Latitude and Longitude to a 2D Point in Java](https://www.baeldung.com/java-convert-latitude-longitude) diff --git a/core-java-10/README.md b/core-java-10/README.md index 84fa381a26..f0a25712a7 100644 --- a/core-java-10/README.md +++ b/core-java-10/README.md @@ -4,3 +4,4 @@ - [Java 10 LocalVariable Type-Inference](http://www.baeldung.com/java-10-local-variable-type-inference) - [Guide to Java 10](http://www.baeldung.com/java-10-overview) - [Copy a List to Another List in Java](http://www.baeldung.com/java-copy-list-to-another) +- [Deep Dive Into the New Java JIT Compiler – Graal](https://www.baeldung.com/graal-java-jit-compiler) diff --git a/core-java-8/README.md b/core-java-8/README.md index ffd629a170..6786b29120 100644 --- a/core-java-8/README.md +++ b/core-java-8/README.md @@ -33,3 +33,4 @@ - [An Overview of Regular Expressions Performance in Java](https://www.baeldung.com/java-regex-performance) - [Java Primitives versus Objects](https://www.baeldung.com/java-primitives-vs-objects) - [How to Use if/else Logic in Java 8 Streams](https://www.baeldung.com/java-8-streams-if-else-logic) +- [How to Replace Many if Statements in Java](https://www.baeldung.com/java-replace-if-statements) diff --git a/core-java-collections/README.md b/core-java-collections/README.md index 0fcf7367c7..858dbef0b3 100644 --- a/core-java-collections/README.md +++ b/core-java-collections/README.md @@ -50,3 +50,4 @@ - [Check If Two Lists are Equal in Java](http://www.baeldung.com/java-test-a-list-for-ordinality-and-equality) - [Java List Initialization in One Line](https://www.baeldung.com/java-init-list-one-line) - [ClassCastException: Arrays$ArrayList cannot be cast to ArrayList](https://www.baeldung.com/java-classcastexception-arrays-arraylist) +- [A Guide to EnumMap](https://www.baeldung.com/java-enum-map) diff --git a/core-java-io/README.md b/core-java-io/README.md index c81e466b57..3d028783ed 100644 --- a/core-java-io/README.md +++ b/core-java-io/README.md @@ -34,3 +34,4 @@ - [Read a File into an ArrayList](https://www.baeldung.com/java-file-to-arraylist) - [Guide to Java OutputStream](https://www.baeldung.com/java-outputstream) - [Reading a CSV File into an Array](https://www.baeldung.com/java-csv-file-array) +- [Guide to BufferedReader](https://www.baeldung.com/java-buffered-reader) diff --git a/core-java/README.md b/core-java/README.md index 7617897e95..e8923e9a2f 100644 --- a/core-java/README.md +++ b/core-java/README.md @@ -85,4 +85,6 @@ - [A Guide to SimpleDateFormat](https://www.baeldung.com/java-simple-date-format) - [SSL Handshake Failures](https://www.baeldung.com/java-ssl-handshake-failures) - [Implementing a Binary Tree in Java](https://www.baeldung.com/java-binary-tree) +- [Changing the Order in a Sum Operation Can Produce Different Results?](https://www.baeldung.com/java-floating-point-sum-order) +- [Java – Try with Resources](https://www.baeldung.com/java-try-with-resources) - [Abstract Classes in Java](https://www.baeldung.com/java-abstract-class) diff --git a/java-dates/README.md b/java-dates/README.md index 66046b16a6..3f6d7998b8 100644 --- a/java-dates/README.md +++ b/java-dates/README.md @@ -24,3 +24,4 @@ - [Add Hours To a Date In Java](http://www.baeldung.com/java-add-hours-date) - [Guide to DateTimeFormatter](https://www.baeldung.com/java-datetimeformatter) - [Format ZonedDateTime to String](https://www.baeldung.com/java-format-zoned-datetime-string) +- [Convert Between java.time.Instant and java.sql.Timestamp](Convert Between java.time.Instant and java.sql.Timestamp) diff --git a/persistence-modules/spring-boot-persistence/README.MD b/persistence-modules/spring-boot-persistence/README.MD index 6cf172426a..8988fb4ebd 100644 --- a/persistence-modules/spring-boot-persistence/README.MD +++ b/persistence-modules/spring-boot-persistence/README.MD @@ -4,3 +4,4 @@ - [Configuring Separate Spring DataSource for Tests](http://www.baeldung.com/spring-testing-separate-data-source) - [Quick Guide on data.sql and schema.sql Files in Spring Boot](http://www.baeldung.com/spring-boot-data-sql-and-schema-sql) - [Configuring a Tomcat Connection Pool in Spring Boot](https://www.baeldung.com/spring-boot-tomcat-connection-pool) +- [Hibernate Field Naming with Spring Boot](https://www.baeldung.com/hibernate-field-naming-spring-boot) diff --git a/persistence-modules/spring-data-jpa/README.md b/persistence-modules/spring-data-jpa/README.md index 44ce240da3..a65b744944 100644 --- a/persistence-modules/spring-data-jpa/README.md +++ b/persistence-modules/spring-data-jpa/README.md @@ -15,6 +15,7 @@ - [Query Entities by Dates and Times with Spring Data JPA](https://www.baeldung.com/spring-data-jpa-query-by-date) - [DDD Aggregates and @DomainEvents](https://www.baeldung.com/spring-data-ddd) - [Spring Data – CrudRepository save() Method](https://www.baeldung.com/spring-data-crud-repository-save) +- [Limiting Query Results with JPA and Spring Data JPA](https://www.baeldung.com/jpa-limit-query-results) ### Eclipse Config After importing the project into Eclipse, you may see the following error: diff --git a/persistence-modules/spring-data-mongodb/README.md b/persistence-modules/spring-data-mongodb/README.md index c7bc7584be..c4f21dffc0 100644 --- a/persistence-modules/spring-data-mongodb/README.md +++ b/persistence-modules/spring-data-mongodb/README.md @@ -12,3 +12,4 @@ - [Spring Data MongoDB: Projections and Aggregations](http://www.baeldung.com/spring-data-mongodb-projections-aggregations) - [Spring Data Annotations](http://www.baeldung.com/spring-data-annotations) - [Spring Data MongoDB Transactions](https://www.baeldung.com/spring-data-mongodb-transactions ) +- [ZonedDateTime with Spring Data MongoDB](https://www.baeldung.com/spring-data-mongodb-zoneddatetime) diff --git a/spring-5-reactive-oauth/README.md b/spring-5-reactive-oauth/README.md new file mode 100644 index 0000000000..0f27cf5d20 --- /dev/null +++ b/spring-5-reactive-oauth/README.md @@ -0,0 +1,3 @@ +### Relevant Articles: + +- [Spring Security OAuth Login with WebFlux](https://www.baeldung.com/spring-oauth-login-webflux) diff --git a/spring-all/README.md b/spring-all/README.md index 34e5c3435e..0d78efdcf2 100644 --- a/spring-all/README.md +++ b/spring-all/README.md @@ -33,3 +33,4 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [Spring Cache – Creating a Custom KeyGenerator](http://www.baeldung.com/spring-cache-custom-keygenerator) - [Spring @Primary Annotation](http://www.baeldung.com/spring-primary) - [Spring Events](https://www.baeldung.com/spring-events) +- [Spring Null-Safety Annotations](https://www.baeldung.com/spring-null-safety-annotations) diff --git a/spring-cloud/README.md b/spring-cloud/README.md index 16bc2d110a..dc43bd1a66 100644 --- a/spring-cloud/README.md +++ b/spring-cloud/README.md @@ -30,3 +30,4 @@ - [Introduction to Netflix Archaius with Spring Cloud](https://www.baeldung.com/netflix-archaius-spring-cloud-integration) - [An Intro to Spring Cloud Vault](https://www.baeldung.com/spring-cloud-vault) - [Netflix Archaius with Various Database Configurations](https://www.baeldung.com/netflix-archaius-database-configurations) +- [Rate Limiting in Spring Cloud Netflix Zuul](https://www.baeldung.com/spring-cloud-zuul-rate-limit) diff --git a/spring-rest-template/README.md b/spring-rest-template/README.md index d69d5c01c7..2c31796080 100644 --- a/spring-rest-template/README.md +++ b/spring-rest-template/README.md @@ -5,3 +5,4 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring ### Relevant Articles: - [Uploading MultipartFile with Spring RestTemplate](http://www.baeldung.com/spring-rest-template-multipart-upload) +- [Mocking a RestTemplate in Spring](https://www.baeldung.com/spring-mock-rest-template) diff --git a/spring-rest/README.md b/spring-rest/README.md index d449a4d92a..5b8a35a4a5 100644 --- a/spring-rest/README.md +++ b/spring-rest/README.md @@ -23,3 +23,4 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [Using the Spring RestTemplate Interceptor](http://www.baeldung.com/spring-rest-template-interceptor) - [Get and Post Lists of Objects with RestTemplate](http://www.baeldung.com/spring-rest-template-list) - [How to Set a Header on a Response with Spring 5](http://www.baeldung.com/spring-response-header) +- [Spring’s RequestBody and ResponseBody Annotations](https://www.baeldung.com/spring-request-response-body) From 4d3b4ca3f0f11cd6cfb06c57abe4f006c7db6ba4 Mon Sep 17 00:00:00 2001 From: Seun Matt Date: Thu, 22 Nov 2018 08:02:44 +0100 Subject: [PATCH 040/146] Moved example code for BAEL-2366 (#5752) * added example code for BAEL-2366 * moved example code for BAEL-2366 --- .../StringReplaceAndRemoveUnitTest.java | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 java-strings/src/test/java/com/baeldung/string/StringReplaceAndRemoveUnitTest.java diff --git a/java-strings/src/test/java/com/baeldung/string/StringReplaceAndRemoveUnitTest.java b/java-strings/src/test/java/com/baeldung/string/StringReplaceAndRemoveUnitTest.java new file mode 100644 index 0000000000..d952d2383b --- /dev/null +++ b/java-strings/src/test/java/com/baeldung/string/StringReplaceAndRemoveUnitTest.java @@ -0,0 +1,83 @@ +package com.baeldung.string; + + +import org.apache.commons.lang3.StringUtils; +import org.junit.Test; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +public class StringReplaceAndRemoveUnitTest { + + + @Test + public void givenTestStrings_whenReplace_thenProcessedString() { + + String master = "Hello World Baeldung!"; + String target = "Baeldung"; + String replacement = "Java"; + String processed = master.replace(target, replacement); + assertTrue(processed.contains(replacement)); + assertFalse(processed.contains(target)); + + } + + @Test + public void givenTestStrings_whenReplaceAll_thenProcessedString() { + + String master2 = "Welcome to Baeldung, Hello World Baeldung"; + String regexTarget= "(Baeldung)$"; + String replacement = "Java"; + String processed2 = master2.replaceAll(regexTarget, replacement); + assertTrue(processed2.endsWith("Java")); + + } + + @Test + public void givenTestStrings_whenStringBuilderMethods_thenProcessedString() { + + String master = "Hello World Baeldung!"; + String target = "Baeldung"; + String replacement = "Java"; + + int startIndex = master.indexOf(target); + int stopIndex = startIndex + target.length(); + + StringBuilder builder = new StringBuilder(master); + + + builder.delete(startIndex, stopIndex); + assertFalse(builder.toString().contains(target)); + + + builder.replace(startIndex, stopIndex, replacement); + assertTrue(builder.toString().contains(replacement)); + + + } + + + @Test + public void givenTestStrings_whenStringUtilsMethods_thenProcessedStrings() { + + String master = "Hello World Baeldung!"; + String target = "Baeldung"; + String replacement = "Java"; + + String processed = StringUtils.replace(master, target, replacement); + assertTrue(processed.contains(replacement)); + + String master2 = "Hello World Baeldung!"; + String target2 = "baeldung"; + String processed2 = StringUtils.replaceIgnoreCase(master2, target2, replacement); + assertFalse(processed2.contains(target)); + + } + + + + + + + +} From 56ab8e2049028b784ac2a769a86171cd5a59a852 Mon Sep 17 00:00:00 2001 From: Kumar Chandrakant Date: Thu, 22 Nov 2018 15:29:58 +0530 Subject: [PATCH 041/146] BAEL-2334: Adding file for the tutorial on Graph in Java --- .../main/java/com/baeldung/graph/Graph.java | 112 ++++++++++++++++++ .../com/baeldung/graph/GraphTraversal.java | 44 +++++++ .../graph/GraphTraversalUnitTest.java | 36 ++++++ 3 files changed, 192 insertions(+) create mode 100644 core-java/src/main/java/com/baeldung/graph/Graph.java create mode 100644 core-java/src/main/java/com/baeldung/graph/GraphTraversal.java create mode 100644 core-java/src/test/java/com/baeldung/graph/GraphTraversalUnitTest.java diff --git a/core-java/src/main/java/com/baeldung/graph/Graph.java b/core-java/src/main/java/com/baeldung/graph/Graph.java new file mode 100644 index 0000000000..7095f64709 --- /dev/null +++ b/core-java/src/main/java/com/baeldung/graph/Graph.java @@ -0,0 +1,112 @@ +package com.baeldung.graph; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; + +public class Graph { + private Set vertices; + private Set edges; + private Map> adjVertices; + + Graph() { + this.vertices = new HashSet(); + this.edges = new HashSet(); + this.adjVertices = new HashMap>(); + } + + boolean addVertex(String label) { + return vertices.add(new Vertex(label)); + } + + boolean removeVertex(String label) { + return vertices.remove(new Vertex(label)); + } + + boolean addEdge(String label1, String label2) { + Vertex v1 = new Vertex(label1); + Vertex v2 = new Vertex(label2); + Edge e = new Edge(v1, v2); + if (this.edges.add(e)) { + adjVertices.putIfAbsent(v1, new HashSet<>()); + adjVertices.putIfAbsent(v2, new HashSet<>()); + adjVertices.get(v1) + .add(e); + adjVertices.get(v2) + .add(e); + } + return true; + } + + boolean removeEdge(String label1, String label2) { + Vertex v1 = new Vertex(label1); + Vertex v2 = new Vertex(label2); + Edge e = new Edge(v1, v2); + if (this.edges.remove(e)) { + Set eV1 = adjVertices.get(v1); + Set eV2 = adjVertices.get(v2); + + if (eV1 != null) + eV1.remove(e); + if (eV2 != null) + eV2.remove(e); + } + return true; + } + + Set getAdjVertices(String label) { + Vertex v = new Vertex(label); + return adjVertices.get(v) + .stream() + .map(e -> e.v1.equals(v) ? e.v2 : e.v1) + .collect(Collectors.toSet()); + } + + class Vertex { + String label; + Vertex(String label) { + this.label = label; + } + @Override + public boolean equals(Object obj) { + Vertex vertex = (Vertex) obj; + return vertex.label == label; + } + @Override + public int hashCode() { + return label.hashCode(); + } + @Override + public String toString() { + return label; + } + } + + class Edge { + Vertex v1; + Vertex v2; + Edge(String label1, String label2) { + this.v1 = new Vertex(label1); + this.v2 = new Vertex(label2); + } + Edge(Vertex vertex1, Vertex vertex2) { + this.v1 = vertex1; + this.v2 = vertex2; + } + @Override + public boolean equals(Object obj) { + Edge edge = (Edge) obj; + return edge.v1.equals(v1) && edge.v2.equals(v2); + } + @Override + public int hashCode() { + return v1.hashCode() + v2.hashCode(); + } + @Override + public String toString() { + return v1.label + "-" + v2.label; + } + } +} \ No newline at end of file diff --git a/core-java/src/main/java/com/baeldung/graph/GraphTraversal.java b/core-java/src/main/java/com/baeldung/graph/GraphTraversal.java new file mode 100644 index 0000000000..479e653a5c --- /dev/null +++ b/core-java/src/main/java/com/baeldung/graph/GraphTraversal.java @@ -0,0 +1,44 @@ +package com.baeldung.graph; + +import java.util.LinkedHashSet; +import java.util.LinkedList; +import java.util.Queue; +import java.util.Set; +import java.util.Stack; + +import com.baeldung.graph.Graph.Vertex; + +public class GraphTraversal { + static Set depthFirstTraversal(Graph graph, String root) { + Set visited = new LinkedHashSet(); + Stack stack = new Stack(); + stack.push(root); + while (!stack.isEmpty()) { + String vertex = stack.pop(); + if (!visited.contains(vertex)) { + visited.add(vertex); + for (Vertex v : graph.getAdjVertices(vertex)) { + stack.push(v.label); + } + } + } + return visited; + } + + static Set breadthFirstTraversal(Graph graph, String root) { + Set visited = new LinkedHashSet(); + Queue queue = new LinkedList(); + queue.add(root); + visited.add(root); + while (!queue.isEmpty()) { + String vertex = queue.poll(); + for (Vertex v : graph.getAdjVertices(vertex)) { + if (!visited.contains(v.label)) { + visited.add(v.label); + queue.add(v.label); + } + } + } + return visited; + } +} \ No newline at end of file diff --git a/core-java/src/test/java/com/baeldung/graph/GraphTraversalUnitTest.java b/core-java/src/test/java/com/baeldung/graph/GraphTraversalUnitTest.java new file mode 100644 index 0000000000..84611a580a --- /dev/null +++ b/core-java/src/test/java/com/baeldung/graph/GraphTraversalUnitTest.java @@ -0,0 +1,36 @@ +package com.baeldung.graph; + +import org.junit.Assert; +import org.junit.Test; + +public class GraphTraversalUnitTest { + @Test + public void givenAGraph_whenTraversingDepthFirst_thenExpectedResult() { + Graph graph = createGraph(); + Assert.assertEquals("[A, D, E, B, C]", + GraphTraversal.depthFirstTraversal(graph, "A").toString()); + } + + @Test + public void givenAGraph_whenTraversingBreadthFirst_thenExpectedResult() { + Graph graph = createGraph(); + Assert.assertEquals("[A, B, D, C, E]", + GraphTraversal.breadthFirstTraversal(graph, "A").toString()); + } + + Graph createGraph() { + Graph graph = new Graph(); + graph.addVertex("A"); + graph.addVertex("B"); + graph.addVertex("C"); + graph.addVertex("D"); + graph.addVertex("E"); + graph.addEdge("A", "B"); + graph.addEdge("A", "D"); + graph.addEdge("B", "C"); + graph.addEdge("D", "C"); + graph.addEdge("B", "E"); + graph.addEdge("D", "E"); + return graph; + } +} \ No newline at end of file From 3928c8955934209ae00de8656c6065de1f5a565c Mon Sep 17 00:00:00 2001 From: Eugen Paraschiv Date: Thu, 22 Nov 2018 16:19:26 +0200 Subject: [PATCH 042/146] the third profile --- pom.xml | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/pom.xml b/pom.xml index 5ebf7ba4f3..2fed100fc6 100644 --- a/pom.xml +++ b/pom.xml @@ -738,6 +738,46 @@ helidon + + + + default-third + + + + + org.apache.maven.plugins + maven-surefire-plugin + ${maven-surefire-plugin.version} + + 3 + true + + **/*IntegrationTest.java + **/*IntTest.java + **/*LongRunningUnitTest.java + **/*ManualTest.java + **/*JdbcTest.java + **/*LiveTest.java + + + + + + + + + parent-boot-1 + parent-boot-2 + parent-spring-4 + parent-spring-5 + parent-java + parent-kotlin + + testing-modules/gatling + geotools + + From af3e0e9b063b71b6109be70b2b5c8b1a1e3db728 Mon Sep 17 00:00:00 2001 From: Eugen Paraschiv Date: Thu, 22 Nov 2018 17:38:17 +0200 Subject: [PATCH 043/146] splitting the integration-lite profile --- pom.xml | 72 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/pom.xml b/pom.xml index 2fed100fc6..d72fcc9f26 100644 --- a/pom.xml +++ b/pom.xml @@ -1238,43 +1238,8 @@ - - integration-lite-test - - - - - org.apache.maven.plugins - maven-surefire-plugin - - - **/*ManualTest.java - **/*LiveTest.java - - - **/*IntegrationTest.java - **/*IntTest.java - - - - - - - - parent-boot-1 - parent-boot-2 - parent-spring-4 - parent-spring-5 - parent-java - parent-kotlin - - spring-4 - - - - - integration-lite + integration-lite-first @@ -1302,6 +1267,7 @@ parent-spring-5 parent-java parent-kotlin + asm atomix persistence-modules/apache-cayenne @@ -1449,7 +1415,41 @@ spring-cucumber spring-ejb spring-aop + + + + + + integration-lite-second + + + + + org.apache.maven.plugins + maven-surefire-plugin + + + **/*ManualTest.java + **/*LiveTest.java + + + **/*IntegrationTest.java + **/*IntTest.java + + + + + + + + parent-boot-1 + parent-boot-2 + parent-spring-4 + parent-spring-5 + parent-java + parent-kotlin + persistence-modules/spring-data-dynamodb persistence-modules/spring-data-keyvalue persistence-modules/spring-data-mongodb From 608fe77823aa77578393678afed1f7709c67562a Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Thu, 22 Nov 2018 17:53:33 +0200 Subject: [PATCH 044/146] disable gib default (#5726) * disable gib default * Update .travis.yml --- .travis.yml | 2 +- pom.xml | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 683422dc97..5e86714a89 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,7 @@ before_install: - echo "MAVEN_OPTS='-Xmx2048M -Xss128M -XX:+CMSClassUnloadingEnabled -XX:+UseG1GC -XX:-UseGCOverheadLimit'" > ~/.mavenrc install: skip -script: travis_wait 60 mvn -q install -Pdefault-first,default-second +script: travis_wait 60 mvn -q install -Pdefault-first,default-second -Dgib.enabled=true sudo: required diff --git a/pom.xml b/pom.xml index d72fcc9f26..00d5af8214 100644 --- a/pom.xml +++ b/pom.xml @@ -1575,7 +1575,6 @@ + false 4.12 1.3 From 076de3f006be1687b600bbb9ca86a9e1ebebdd36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Dupire?= Date: Thu, 22 Nov 2018 17:22:47 +0100 Subject: [PATCH 045/146] BAEL-2309 Retrieving a Class Name in Java (#5716) * [BAEL-2309] SomeClass and its test * [BAEL-2309] Fixing test naming * [BAEL-2309] Changed name for RetrievingClassName * [BAEL-2309] Updating package name * [BAEL-2309] Fix comment mistake * [BAEL-2309] Fixing test class name --- .../className/RetrievingClassName.java | 9 + .../RetrievingClassNameUnitTest.java | 156 ++++++++++++++++++ 2 files changed, 165 insertions(+) create mode 100644 core-java/src/main/java/com/baeldung/className/RetrievingClassName.java create mode 100644 core-java/src/test/java/com/baeldung/className/RetrievingClassNameUnitTest.java diff --git a/core-java/src/main/java/com/baeldung/className/RetrievingClassName.java b/core-java/src/main/java/com/baeldung/className/RetrievingClassName.java new file mode 100644 index 0000000000..ab6c8a51ff --- /dev/null +++ b/core-java/src/main/java/com/baeldung/className/RetrievingClassName.java @@ -0,0 +1,9 @@ +package com.baeldung.className; + +public class RetrievingClassName { + + public class InnerClass { + + } + +} diff --git a/core-java/src/test/java/com/baeldung/className/RetrievingClassNameUnitTest.java b/core-java/src/test/java/com/baeldung/className/RetrievingClassNameUnitTest.java new file mode 100644 index 0000000000..f9dbf91d2c --- /dev/null +++ b/core-java/src/test/java/com/baeldung/className/RetrievingClassNameUnitTest.java @@ -0,0 +1,156 @@ +package com.baeldung.className; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +public class RetrievingClassNameUnitTest { + + // Retrieving Simple Name + @Test + public void givenRetrievingClassName_whenGetSimpleName_thenRetrievingClassName() { + assertEquals("RetrievingClassName", RetrievingClassName.class.getSimpleName()); + } + + @Test + public void givenPrimitiveInt_whenGetSimpleName_thenInt() { + assertEquals("int", int.class.getSimpleName()); + } + + @Test + public void givenRetrievingClassNameArray_whenGetSimpleName_thenRetrievingClassNameWithBrackets() { + assertEquals("RetrievingClassName[]", RetrievingClassName[].class.getSimpleName()); + assertEquals("RetrievingClassName[][]", RetrievingClassName[][].class.getSimpleName()); + } + + @Test + public void givenAnonymousClass_whenGetSimpleName_thenEmptyString() { + assertEquals("", new RetrievingClassName() {}.getClass().getSimpleName()); + } + + // Retrieving Other Names + // - Primitive Types + @Test + public void givenPrimitiveInt_whenGetName_thenInt() { + assertEquals("int", int.class.getName()); + } + + @Test + public void givenPrimitiveInt_whenGetTypeName_thenInt() { + assertEquals("int", int.class.getTypeName()); + } + + @Test + public void givenPrimitiveInt_whenGetCanonicalName_thenInt() { + assertEquals("int", int.class.getCanonicalName()); + } + + // - Object Types + @Test + public void givenRetrievingClassName_whenGetName_thenCanonicalName() { + assertEquals("com.baeldung.className.RetrievingClassName", RetrievingClassName.class.getName()); + } + + @Test + public void givenRetrievingClassName_whenGetTypeName_thenCanonicalName() { + assertEquals("com.baeldung.className.RetrievingClassName", RetrievingClassName.class.getTypeName()); + } + + @Test + public void givenRetrievingClassName_whenGetCanonicalName_thenCanonicalName() { + assertEquals("com.baeldung.className.RetrievingClassName", RetrievingClassName.class.getCanonicalName()); + } + + // - Inner Classes + @Test + public void givenRetrievingClassNameInnerClass_whenGetName_thenCanonicalNameWithDollarSeparator() { + assertEquals("com.baeldung.className.RetrievingClassName$InnerClass", RetrievingClassName.InnerClass.class.getName()); + } + + @Test + public void givenRetrievingClassNameInnerClass_whenGetTypeName_thenCanonicalNameWithDollarSeparator() { + assertEquals("com.baeldung.className.RetrievingClassName$InnerClass", RetrievingClassName.InnerClass.class.getTypeName()); + } + + @Test + public void givenRetrievingClassNameInnerClass_whenGetCanonicalName_thenCanonicalName() { + assertEquals("com.baeldung.className.RetrievingClassName.InnerClass", RetrievingClassName.InnerClass.class.getCanonicalName()); + } + + // - Anonymous Classes + @Test + public void givenAnonymousClass_whenGetName_thenCallingClassCanonicalNameWithDollarSeparatorAndCountNumber() { + // These are the second and third appearences of an anonymous class in RetrievingClassNameUnitTest, hence $2 and $3 expectations + assertEquals("com.baeldung.className.RetrievingClassNameUnitTest$2", new RetrievingClassName() {}.getClass().getName()); + assertEquals("com.baeldung.className.RetrievingClassNameUnitTest$3", new RetrievingClassName() {}.getClass().getName()); + } + + @Test + public void givenAnonymousClass_whenGetTypeName_thenCallingClassCanonicalNameWithDollarSeparatorAndCountNumber() { + // These are the fourth and fifth appearences of an anonymous class in RetrievingClassNameUnitTest, hence $4 and $5 expectations + assertEquals("com.baeldung.className.RetrievingClassNameUnitTest$4", new RetrievingClassName() {}.getClass().getTypeName()); + assertEquals("com.baeldung.className.RetrievingClassNameUnitTest$5", new RetrievingClassName() {}.getClass().getTypeName()); + } + + @Test + public void givenAnonymousClass_whenGetCanonicalName_thenNull() { + assertNull(new RetrievingClassName() {}.getClass().getCanonicalName()); + } + + // - Arrays + @Test + public void givenPrimitiveIntArray_whenGetName_thenOpeningBracketsAndPrimitiveIntLetter() { + assertEquals("[I", int[].class.getName()); + assertEquals("[[I", int[][].class.getName()); + } + + @Test + public void givenRetrievingClassNameArray_whenGetName_thenOpeningBracketsLetterLAndRetrievingClassNameGetName() { + assertEquals("[Lcom.baeldung.className.RetrievingClassName;", RetrievingClassName[].class.getName()); + assertEquals("[[Lcom.baeldung.className.RetrievingClassName;", RetrievingClassName[][].class.getName()); + } + + @Test + public void givenRetrievingClassNameInnerClassArray_whenGetName_thenOpeningBracketsLetterLAndRetrievingClassNameInnerClassGetName() { + assertEquals("[Lcom.baeldung.className.RetrievingClassName$InnerClass;", RetrievingClassName.InnerClass[].class.getName()); + assertEquals("[[Lcom.baeldung.className.RetrievingClassName$InnerClass;", RetrievingClassName.InnerClass[][].class.getName()); + } + + @Test + public void givenPrimitiveIntArray_whenGetTypeName_thenPrimitiveIntGetTypeNameWithBrackets() { + assertEquals("int[]", int[].class.getTypeName()); + assertEquals("int[][]", int[][].class.getTypeName()); + } + + @Test + public void givenRetrievingClassNameArray_whenGetTypeName_thenRetrievingClassNameGetTypeNameWithBrackets() { + assertEquals("com.baeldung.className.RetrievingClassName[]", RetrievingClassName[].class.getTypeName()); + assertEquals("com.baeldung.className.RetrievingClassName[][]", RetrievingClassName[][].class.getTypeName()); + } + + @Test + public void givenRetrievingClassNameInnerClassArray_whenGetTypeName_thenRetrievingClassNameInnerClassGetTypeNameWithBrackets() { + assertEquals("com.baeldung.className.RetrievingClassName$InnerClass[]", RetrievingClassName.InnerClass[].class.getTypeName()); + assertEquals("com.baeldung.className.RetrievingClassName$InnerClass[][]", RetrievingClassName.InnerClass[][].class.getTypeName()); + } + + @Test + public void givenPrimitiveIntArray_whenGetCanonicalName_thenPrimitiveIntGetCanonicalNameWithBrackets() { + assertEquals("int[]", int[].class.getCanonicalName()); + assertEquals("int[][]", int[][].class.getCanonicalName()); + } + + @Test + public void givenRetrievingClassNameArray_whenGetCanonicalName_thenRetrievingClassNameGetCanonicalNameWithBrackets() { + assertEquals("com.baeldung.className.RetrievingClassName[]", RetrievingClassName[].class.getCanonicalName()); + assertEquals("com.baeldung.className.RetrievingClassName[][]", RetrievingClassName[][].class.getCanonicalName()); + } + + @Test + public void givenRetrievingClassNameInnerClassArray_whenGetCanonicalName_thenRetrievingClassNameInnerClassGetCanonicalNameWithBrackets() { + assertEquals("com.baeldung.className.RetrievingClassName.InnerClass[]", RetrievingClassName.InnerClass[].class.getCanonicalName()); + assertEquals("com.baeldung.className.RetrievingClassName.InnerClass[][]", RetrievingClassName.InnerClass[][].class.getCanonicalName()); + } + +} \ No newline at end of file From e24d89199b668199a35b445fd4fc417ac9a1dc4e Mon Sep 17 00:00:00 2001 From: Eugen Paraschiv Date: Thu, 22 Nov 2018 19:52:02 +0200 Subject: [PATCH 046/146] profile work --- pom.xml | 96 ++++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 65 insertions(+), 31 deletions(-) diff --git a/pom.xml b/pom.xml index 00d5af8214..f94574a801 100644 --- a/pom.xml +++ b/pom.xml @@ -1384,37 +1384,6 @@ testing-modules/selenium-junit-testng persistence-modules/solr spark-java - spring-4 - spring-5-data-reactive - spring-5-reactive - spring-5-reactive-security - spring-5-reactive-client - spring-5-mvc - spring-5-security - spring-activiti - spring-akka - spring-amqp - spring-all - spring-amqp-simple - spring-apache-camel - spring-batch - spring-bom - spring-boot-keycloak - spring-boot-bootstrap - spring-boot-admin - spring-boot-camel - persistence-modules/spring-boot-persistence - spring-boot-security - spring-boot-mvc - spring-boot-logging-log4j2 - spring-boot-disable-console-logging - spring-cloud-data-flow - spring-cloud - spring-cloud-bus - spring-core - spring-cucumber - spring-ejb - spring-aop @@ -1450,6 +1419,38 @@ parent-java parent-kotlin + spring-4 + spring-5-data-reactive + spring-5-reactive + spring-5-reactive-security + spring-5-reactive-client + spring-5-mvc + spring-5-security + spring-activiti + spring-akka + spring-amqp + spring-all + spring-amqp-simple + spring-apache-camel + spring-batch + spring-bom + spring-boot-keycloak + spring-boot-bootstrap + spring-boot-admin + spring-boot-camel + persistence-modules/spring-boot-persistence + spring-boot-security + spring-boot-mvc + spring-boot-logging-log4j2 + spring-boot-disable-console-logging + spring-cloud-data-flow + spring-cloud + spring-cloud-bus + spring-core + spring-cucumber + spring-ejb + spring-aop + persistence-modules/spring-data-dynamodb persistence-modules/spring-data-keyvalue persistence-modules/spring-data-mongodb @@ -1531,6 +1532,39 @@ testing-modules/testing testing-modules/testng video-tutorials + + + + + + integration-lite-third + + + + + org.apache.maven.plugins + maven-surefire-plugin + + + **/*ManualTest.java + **/*LiveTest.java + + + **/*IntegrationTest.java + **/*IntTest.java + + + + + + + + parent-boot-1 + parent-boot-2 + parent-spring-4 + parent-spring-5 + parent-java + parent-kotlin xmlunit-2 struts-2 From 5ad9f285e14451760cb24c189276ad76cce5fcc7 Mon Sep 17 00:00:00 2001 From: Eugen Paraschiv Date: Thu, 22 Nov 2018 20:37:50 +0200 Subject: [PATCH 047/146] profile work --- pom.xml | 783 +++++++++++++++++++++++++++++--------------------------- 1 file changed, 400 insertions(+), 383 deletions(-) diff --git a/pom.xml b/pom.xml index f94574a801..e36a972611 100644 --- a/pom.xml +++ b/pom.xml @@ -934,310 +934,6 @@ - - integration - - - - - org.apache.maven.plugins - maven-surefire-plugin - - - **/*ManualTest.java - **/*LiveTest.java - - - **/*IntegrationTest.java - **/*IntTest.java - - - - - - - - - parent-boot-1 - parent-boot-2 - parent-spring-4 - parent-spring-5 - parent-java - parent-kotlin - - - - - - - - - - testing-modules/mockito - testing-modules/mockito-2 - testing-modules/mocks - mustache - mvn-wrapper - noexception - persistence-modules/orientdb - osgi - orika - patterns - pdf - protobuffer - persistence-modules/querydsl - reactor-core - persistence-modules/redis - testing-modules/rest-assured - testing-modules/rest-testing - resteasy - rxjava - rxjava-2 - spring-swagger-codegen - testing-modules/selenium-junit-testng - persistence-modules/solr - spark-java - spring-4 - spring-5 - spring-5-data-reactive - spring-5-reactive - spring-5-reactive-security - spring-5-reactive-client - spring-5-mvc - spring-5-security - spring-activiti - spring-akka - spring-amqp - spring-all - spring-amqp-simple - spring-apache-camel - spring-batch - jmh - - - - - - spring-bom - spring-boot - spring-boot-client - spring-boot-keycloak - spring-boot-bootstrap - spring-boot-admin - spring-boot-camel - spring-boot-ops - persistence-modules/spring-boot-persistence - spring-boot-security - spring-boot-mvc - spring-boot-logging-log4j2 - spring-boot-disable-console-logging - spring-cloud-data-flow - spring-cloud - spring-cloud-bus - spring-core - spring-cucumber - spring-ejb - spring-aop - persistence-modules/spring-data-cassandra - persistence-modules/spring-data-couchbase-2 - persistence-modules/spring-data-dynamodb - persistence-modules/spring-data-elasticsearch - persistence-modules/spring-data-keyvalue - persistence-modules/spring-data-mongodb - persistence-modules/spring-data-jpa - persistence-modules/spring-data-neo4j - persistence-modules/spring-data-redis - spring-data-rest - - - - - - - persistence-modules/spring-data-solr - spring-dispatcher-servlet - spring-exceptions - spring-freemarker - persistence-modules/spring-hibernate-3 - persistence-modules/spring-hibernate4 - persistence-modules/spring-hibernate-5 - persistence-modules/spring-data-eclipselink - spring-integration - spring-jenkins-pipeline - spring-jersey - spring-jms - spring-jooq - persistence-modules/spring-jpa - spring-kafka - spring-katharsis - spring-ldap - spring-mockito - spring-mvc-forms-jsp - spring-mvc-forms-thymeleaf - spring-mvc-java - spring-mvc-velocity - spring-mvc-webflow - spring-mvc-xml - spring-mvc-kotlin - spring-protobuf - spring-quartz - spring-rest-angular - spring-rest-full - spring-rest-query-language - spring-rest - spring-resttemplate - spring-rest-simple - spring-reactive-kotlin - - - - - - - - - - - - - - - - java-websocket - persistence-modules/activejdbc - animal-sniffer-mvn-plugin - apache-avro - apache-bval - apache-shiro - apache-spark - asciidoctor - checker-plugin - - - core-java-sun - custom-pmd - dagger - data-structures - dubbo - persistence-modules/flyway - - - jni - jooby - - - - ratpack - rest-with-spark-java - spring-boot-autoconfiguration - spring-boot-custom-starter - spring-boot-jasypt - spring-data-rest-querydsl - spring-groovy - spring-mobile - spring-mustache - spring-mvc-simple - spring-mybatis - spring-rest-hal-browser - spring-rest-shell - spring-rest-template - spring-roo - spring-security-stormpath - sse-jaxrs - static-analysis - stripe - - - wicket - xstream - cas/cas-secured-app - - - - - - - - - - - - - - jenkins/hello-world - - - - spring-boot-custom-starter/greeter - persistence-modules/spring-boot-h2/spring-boot-h2-database - - - - - - - - integration-lite-first @@ -1270,7 +966,6 @@ asm atomix - persistence-modules/apache-cayenne aws aws-lambda akka-streams @@ -1290,25 +985,30 @@ autovalue axon azure + apache-velocity + apache-solrj + apache-meecrowave + antlr + bootique + cdi - java-strings - core-java-collections - java-collections-conversions - java-collections-maps core-java-io core-java-8 - java-streams core-groovy - couchbase - persistence-modules/deltaspike + dozer + disruptor + drools + deeplearning4j + ethereum + feign flips - testing-modules/groovy-spock + google-cloud gson guava @@ -1317,17 +1017,20 @@ guava-modules/guava-19 guava-modules/guava-21 guice - disruptor - spring-static-resources + hazelcast - persistence-modules/hbase - hystrix + httpclient + image-processing immutables - persistence-modules/influxdb + jackson - vavr + java-strings + + java-collections-conversions + java-collections-maps + java-streams java-lite java-numbers java-rmi @@ -1345,45 +1048,68 @@ json jsoup jta - testing-modules/junit-5 - testing-modules/junit5-migration jws + jersey + java-spi + java-ee-8-security-api + libraries-data linkrest logging-modules/log-mdc logging-modules/log4j - logging-modules/logback lombok + lucene + mapstruct - maven mesos-marathon msf4j - testing-modules/mockito - testing-modules/mockito-2 - testing-modules/mocks mustache mvn-wrapper + mybatis + metrics + maven-archetype + noexception - persistence-modules/orientdb + osgi orika + patterns pdf protobuffer - persistence-modules/querydsl - reactor-core + performance-tests + + persistence-modules/java-jdbi persistence-modules/redis - testing-modules/rest-assured - testing-modules/rest-testing + persistence-modules/orientdb + persistence-modules/querydsl + persistence-modules/apache-cayenne + persistence-modules/solr + persistence-modules/spring-data-dynamodb + persistence-modules/spring-data-keyvalue + persistence-modules/spring-data-mongodb + persistence-modules/spring-data-neo4j + persistence-modules/spring-data-solr + persistence-modules/spring-hibernate-5 + persistence-modules/spring-data-eclipselink + persistence-modules/spring-jpa + persistence-modules/spring-hibernate-3 + persistence-modules/spring-data-gemfire + persistence-modules/spring-boot-persistence + persistence-modules/liquibase + persistence-modules/java-cockroachdb + persistence-modules/deltaspike + persistence-modules/hbase + persistence-modules/influxdb + persistence-modules/spring-hibernate4 + + reactor-core resteasy rxjava rxjava-2 - spring-swagger-codegen - testing-modules/selenium-junit-testng - persistence-modules/solr - spark-java + rabbitmq @@ -1434,15 +1160,16 @@ spring-apache-camel spring-batch spring-bom + spring-boot-keycloak spring-boot-bootstrap spring-boot-admin spring-boot-camel - persistence-modules/spring-boot-persistence spring-boot-security spring-boot-mvc spring-boot-logging-log4j2 spring-boot-disable-console-logging + spring-cloud-data-flow spring-cloud spring-cloud-bus @@ -1451,27 +1178,17 @@ spring-ejb spring-aop - persistence-modules/spring-data-dynamodb - persistence-modules/spring-data-keyvalue - persistence-modules/spring-data-mongodb - persistence-modules/spring-data-neo4j - spring-data-rest - persistence-modules/spring-data-solr spring-dispatcher-servlet spring-exceptions spring-freemarker - persistence-modules/spring-hibernate-3 - persistence-modules/spring-hibernate-5 - persistence-modules/spring-data-eclipselink spring-integration spring-jenkins-pipeline spring-jersey spring-jms spring-jooq - persistence-modules/spring-jpa spring-kafka spring-katharsis spring-ldap @@ -1529,9 +1246,15 @@ spring-vault spring-jinq spring-rest-embedded-tomcat - testing-modules/testing - testing-modules/testng - video-tutorials + + spring-static-resources + spring-swagger-codegen + spring-drools + spring-boot-property-exp + spring-security-thymeleaf + spring-boot-ctx-fluent + spring-webflux-amqp + @@ -1565,48 +1288,38 @@ parent-spring-5 parent-java parent-kotlin - - xmlunit-2 + + spark-java + saas struts-2 - apache-velocity - apache-solrj - rabbitmq - - persistence-modules/spring-data-gemfire - mybatis - spring-drools - drools - persistence-modules/liquibase - spring-boot-property-exp + + testing-modules/selenium-junit-testng + testing-modules/groovy-spock + testing-modules/mockito + testing-modules/mockito-2 + testing-modules/mocks + testing-modules/rest-assured + testing-modules/rest-testing + testing-modules/junit-5 + testing-modules/junit5-migration + testing-modules/testing + testing-modules/testng testing-modules/mockserver testing-modules/test-containers + twilio + undertow + + video-tutorials vaadin vertx-and-rxjava - saas - deeplearning4j - lucene vraptor - persistence-modules/java-cockroachdb - spring-security-thymeleaf - persistence-modules/java-jdbi - jersey - java-spi - performance-tests - twilio - spring-boot-ctx-fluent - java-ee-8-security-api - spring-webflux-amqp - antlr - maven-archetype - apache-meecrowave - - persistence-modules/spring-hibernate4 - xml vertx - metrics - httpclient - + vavr + + xmlunit-2 + xml + + + + + + + + + + testing-modules/mockito + testing-modules/mockito-2 + testing-modules/mocks + mustache + mvn-wrapper + noexception + persistence-modules/orientdb + osgi + orika + patterns + pdf + protobuffer + persistence-modules/querydsl + reactor-core + persistence-modules/redis + testing-modules/rest-assured + testing-modules/rest-testing + resteasy + rxjava + rxjava-2 + spring-swagger-codegen + testing-modules/selenium-junit-testng + persistence-modules/solr + spark-java + spring-4 + spring-5 + spring-5-data-reactive + spring-5-reactive + spring-5-reactive-security + spring-5-reactive-client + spring-5-mvc + spring-5-security + spring-activiti + spring-akka + spring-amqp + spring-all + spring-amqp-simple + spring-apache-camel + spring-batch + jmh + + + + + + spring-bom + spring-boot + spring-boot-client + spring-boot-keycloak + spring-boot-bootstrap + spring-boot-admin + spring-boot-camel + spring-boot-ops + persistence-modules/spring-boot-persistence + spring-boot-security + spring-boot-mvc + spring-boot-logging-log4j2 + spring-boot-disable-console-logging + spring-cloud-data-flow + spring-cloud + spring-cloud-bus + spring-core + spring-cucumber + spring-ejb + spring-aop + persistence-modules/spring-data-cassandra + persistence-modules/spring-data-couchbase-2 + persistence-modules/spring-data-dynamodb + persistence-modules/spring-data-elasticsearch + persistence-modules/spring-data-keyvalue + persistence-modules/spring-data-mongodb + persistence-modules/spring-data-jpa + persistence-modules/spring-data-neo4j + persistence-modules/spring-data-redis + spring-data-rest + + + + + + + persistence-modules/spring-data-solr + spring-dispatcher-servlet + spring-exceptions + spring-freemarker + persistence-modules/spring-hibernate-3 + persistence-modules/spring-hibernate4 + persistence-modules/spring-hibernate-5 + persistence-modules/spring-data-eclipselink + spring-integration + spring-jenkins-pipeline + spring-jersey + spring-jms + spring-jooq + persistence-modules/spring-jpa + spring-kafka + spring-katharsis + spring-ldap + spring-mockito + spring-mvc-forms-jsp + spring-mvc-forms-thymeleaf + spring-mvc-java + spring-mvc-velocity + spring-mvc-webflow + spring-mvc-xml + spring-mvc-kotlin + spring-protobuf + spring-quartz + spring-rest-angular + spring-rest-full + spring-rest-query-language + spring-rest + spring-resttemplate + spring-rest-simple + spring-reactive-kotlin + + + + + + + + + + + + + + + + java-websocket + persistence-modules/activejdbc + animal-sniffer-mvn-plugin + apache-avro + apache-bval + apache-shiro + apache-spark + asciidoctor + checker-plugin + + + core-java-sun + custom-pmd + dagger + data-structures + dubbo + persistence-modules/flyway + + + jni + jooby + + + + ratpack + rest-with-spark-java + spring-boot-autoconfiguration + spring-boot-custom-starter + spring-boot-jasypt + spring-data-rest-querydsl + spring-groovy + spring-mobile + spring-mustache + spring-mvc-simple + spring-mybatis + spring-rest-hal-browser + spring-rest-shell + spring-rest-template + spring-roo + spring-security-stormpath + sse-jaxrs + static-analysis + stripe + + + wicket + xstream + cas/cas-secured-app + + + + + + + + + + + + + + jenkins/hello-world + + + + spring-boot-custom-starter/greeter + persistence-modules/spring-boot-h2/spring-boot-h2-database + + + + + + + + integration-heavy From bb00c371513bb44812bda03d120ee9a389a0f74d Mon Sep 17 00:00:00 2001 From: smokeyrobot Date: Thu, 22 Nov 2018 15:13:14 -0500 Subject: [PATCH 048/146] Gatling vs JMeter vs The Grinder Issue: BAEL-46 --- .../load-testing-comparison/pom.xml | 148 +++++++++ .../com/baeldung/loadtesting/Application.java | 12 + .../loadtesting/RewardsController.java | 51 +++ .../loadtesting/TransactionController.java | 26 ++ .../model/CustomerRewardsAccount.java | 22 ++ .../loadtesting/model/Transaction.java | 30 ++ .../repository/CustomerRewardsRepository.java | 11 + .../repository/TransactionRepository.java | 11 + .../scripts/Gatling/GatlingScenario.scala | 52 ++++ .../resources/scripts/JMeter/Test Plan.jmx | 293 ++++++++++++++++++ .../scripts/The Grinder/grinder.properties | 5 + .../resources/scripts/The Grinder/grinder.py | 40 +++ 12 files changed, 701 insertions(+) create mode 100644 testing-modules/load-testing-comparison/pom.xml create mode 100644 testing-modules/load-testing-comparison/src/main/java/com/baeldung/loadtesting/Application.java create mode 100644 testing-modules/load-testing-comparison/src/main/java/com/baeldung/loadtesting/RewardsController.java create mode 100644 testing-modules/load-testing-comparison/src/main/java/com/baeldung/loadtesting/TransactionController.java create mode 100644 testing-modules/load-testing-comparison/src/main/java/com/baeldung/loadtesting/model/CustomerRewardsAccount.java create mode 100644 testing-modules/load-testing-comparison/src/main/java/com/baeldung/loadtesting/model/Transaction.java create mode 100644 testing-modules/load-testing-comparison/src/main/java/com/baeldung/loadtesting/repository/CustomerRewardsRepository.java create mode 100644 testing-modules/load-testing-comparison/src/main/java/com/baeldung/loadtesting/repository/TransactionRepository.java create mode 100644 testing-modules/load-testing-comparison/src/main/resources/scripts/Gatling/GatlingScenario.scala create mode 100644 testing-modules/load-testing-comparison/src/main/resources/scripts/JMeter/Test Plan.jmx create mode 100644 testing-modules/load-testing-comparison/src/main/resources/scripts/The Grinder/grinder.properties create mode 100644 testing-modules/load-testing-comparison/src/main/resources/scripts/The Grinder/grinder.py diff --git a/testing-modules/load-testing-comparison/pom.xml b/testing-modules/load-testing-comparison/pom.xml new file mode 100644 index 0000000000..869eda1bb5 --- /dev/null +++ b/testing-modules/load-testing-comparison/pom.xml @@ -0,0 +1,148 @@ + + + + parent-modules + com.baeldung + 1.0.0-SNAPSHOT + ../../pom.xml + + 4.0.0 + + load-testing-bakeoff + + + 1.8 + 1.8 + UTF-8 + 2.11.12 + 2.2.5 + 3.2.2 + 2.2.1 + 5.0 + 3.11 + 2.0.5.RELEASE + + + + + io.gatling + gatling-app + ${gatling.version} + + + io.gatling + gatling-recorder + ${gatling.version} + + + io.gatling.highcharts + gatling-charts-highcharts + ${gatling.version} + + + org.scala-lang + scala-library + ${scala.version} + + + + + + + + com.fasterxml.jackson.core + jackson-databind + 2.9.4 + + + org.springframework.boot + spring-boot-starter + ${spring.boot.version} + + + org.springframework.boot + spring-boot-starter-web + ${spring.boot.version} + + + org.springframework.boot + spring-boot-starter-data-jpa + ${spring.boot.version} + + + org.springframework.boot + spring-boot-starter-test + ${spring.boot.version} + test + + + com.h2database + h2 + 1.4.197 + + + org.projectlombok + lombok + 1.18.2 + compile + + + + + + + + + + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + 2.0.5.RELEASE + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/testing-modules/load-testing-comparison/src/main/java/com/baeldung/loadtesting/Application.java b/testing-modules/load-testing-comparison/src/main/java/com/baeldung/loadtesting/Application.java new file mode 100644 index 0000000000..6647bcb640 --- /dev/null +++ b/testing-modules/load-testing-comparison/src/main/java/com/baeldung/loadtesting/Application.java @@ -0,0 +1,12 @@ +package com.baeldung.loadtesting; + +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/testing-modules/load-testing-comparison/src/main/java/com/baeldung/loadtesting/RewardsController.java b/testing-modules/load-testing-comparison/src/main/java/com/baeldung/loadtesting/RewardsController.java new file mode 100644 index 0000000000..50cc6fb7ab --- /dev/null +++ b/testing-modules/load-testing-comparison/src/main/java/com/baeldung/loadtesting/RewardsController.java @@ -0,0 +1,51 @@ +package com.baeldung.loadtesting; + +import com.baeldung.loadtesting.model.CustomerRewardsAccount; +import com.baeldung.loadtesting.model.Transaction; +import com.baeldung.loadtesting.repository.CustomerRewardsRepository; +import com.baeldung.loadtesting.repository.TransactionRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.util.Calendar; +import java.util.List; +import java.util.Optional; + +@RestController +public class RewardsController { + + @Autowired + private CustomerRewardsRepository customerRewardsRepository; + + @Autowired + private TransactionRepository transactionRepository; + + @PostMapping(path="/transactions/add") + public @ResponseBody Transaction saveTransactions(@RequestBody Transaction trnsctn){ + trnsctn.setTransactionDate(Calendar.getInstance().getTime()); + Transaction result = transactionRepository.save(trnsctn); + return result; + } + + @GetMapping(path="/transactions/findAll/{rewardId}") + public @ResponseBody Iterable getTransactions(@PathVariable Integer rewardId){ + return transactionRepository.findByCustomerRewardsId(rewardId); + } + + @PostMapping(path="/rewards/add") + public @ResponseBody CustomerRewardsAccount addRewardsAcount(@RequestBody CustomerRewardsAccount body) { + Optional acct = customerRewardsRepository.findByCustomerId(body.getCustomerId()); + return !acct.isPresent() ? customerRewardsRepository.save(body) : acct.get(); + } + + @GetMapping(path="/rewards/find/{customerId}") + public @ResponseBody + Optional find(@PathVariable Integer customerId) { + return customerRewardsRepository.findByCustomerId(customerId); + } + + @GetMapping(path="/rewards/all") + public @ResponseBody List findAll() { + return customerRewardsRepository.findAll(); + } +} diff --git a/testing-modules/load-testing-comparison/src/main/java/com/baeldung/loadtesting/TransactionController.java b/testing-modules/load-testing-comparison/src/main/java/com/baeldung/loadtesting/TransactionController.java new file mode 100644 index 0000000000..2ea2c06a41 --- /dev/null +++ b/testing-modules/load-testing-comparison/src/main/java/com/baeldung/loadtesting/TransactionController.java @@ -0,0 +1,26 @@ +package com.baeldung.loadtesting; + +import com.baeldung.loadtesting.model.Transaction; +import com.baeldung.loadtesting.repository.TransactionRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +@RestController +@Deprecated +public class TransactionController { + + @Autowired + private TransactionRepository transactionRepository; + + @PostMapping(path="/addTransaction") + public @ResponseBody + String saveTransactions(@RequestBody Transaction trnsctn){ + transactionRepository.save(trnsctn); + return "Saved Transaction."; + } + + @GetMapping(path="/findAll/{rewardId}") + public @ResponseBody Iterable getTransactions(@RequestParam Integer id){ + return transactionRepository.findByCustomerRewardsId(id); + } +} diff --git a/testing-modules/load-testing-comparison/src/main/java/com/baeldung/loadtesting/model/CustomerRewardsAccount.java b/testing-modules/load-testing-comparison/src/main/java/com/baeldung/loadtesting/model/CustomerRewardsAccount.java new file mode 100644 index 0000000000..2c6742fbaf --- /dev/null +++ b/testing-modules/load-testing-comparison/src/main/java/com/baeldung/loadtesting/model/CustomerRewardsAccount.java @@ -0,0 +1,22 @@ +package com.baeldung.loadtesting.model; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; + +import lombok.Data; + +@Entity +@Data +public class CustomerRewardsAccount { + + @Id + @GeneratedValue(strategy= GenerationType.AUTO) + private Integer id; + private Integer customerId; + + public Integer getCustomerId(){ + return this.customerId; + } +} diff --git a/testing-modules/load-testing-comparison/src/main/java/com/baeldung/loadtesting/model/Transaction.java b/testing-modules/load-testing-comparison/src/main/java/com/baeldung/loadtesting/model/Transaction.java new file mode 100644 index 0000000000..312f52f4ab --- /dev/null +++ b/testing-modules/load-testing-comparison/src/main/java/com/baeldung/loadtesting/model/Transaction.java @@ -0,0 +1,30 @@ +package com.baeldung.loadtesting.model; + +import lombok.Data; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import java.util.Date; +import java.util.Calendar; + +@Entity +@Data +public class Transaction { + + @Id + @GeneratedValue(strategy= GenerationType.AUTO) + private Integer id; + private Integer customerRewardsId; + private Integer customerId; + private Date transactionDate; + + public Transaction(){ + transactionDate = Calendar.getInstance().getTime(); + } + + public void setTransactionDate(Date transactionDate){ + this.transactionDate = transactionDate; + } +} diff --git a/testing-modules/load-testing-comparison/src/main/java/com/baeldung/loadtesting/repository/CustomerRewardsRepository.java b/testing-modules/load-testing-comparison/src/main/java/com/baeldung/loadtesting/repository/CustomerRewardsRepository.java new file mode 100644 index 0000000000..f945359eb8 --- /dev/null +++ b/testing-modules/load-testing-comparison/src/main/java/com/baeldung/loadtesting/repository/CustomerRewardsRepository.java @@ -0,0 +1,11 @@ +package com.baeldung.loadtesting.repository; + +import com.baeldung.loadtesting.model.CustomerRewardsAccount; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.Optional; + +public interface CustomerRewardsRepository extends JpaRepository { + + Optional findByCustomerId(Integer customerId); +} diff --git a/testing-modules/load-testing-comparison/src/main/java/com/baeldung/loadtesting/repository/TransactionRepository.java b/testing-modules/load-testing-comparison/src/main/java/com/baeldung/loadtesting/repository/TransactionRepository.java new file mode 100644 index 0000000000..af0b343c10 --- /dev/null +++ b/testing-modules/load-testing-comparison/src/main/java/com/baeldung/loadtesting/repository/TransactionRepository.java @@ -0,0 +1,11 @@ +package com.baeldung.loadtesting.repository; + +import com.baeldung.loadtesting.model.Transaction; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.List; + +public interface TransactionRepository extends JpaRepository { + + List findByCustomerRewardsId(Integer rewardsId); +} diff --git a/testing-modules/load-testing-comparison/src/main/resources/scripts/Gatling/GatlingScenario.scala b/testing-modules/load-testing-comparison/src/main/resources/scripts/Gatling/GatlingScenario.scala new file mode 100644 index 0000000000..f9b3837759 --- /dev/null +++ b/testing-modules/load-testing-comparison/src/main/resources/scripts/Gatling/GatlingScenario.scala @@ -0,0 +1,52 @@ +package com.baeldung + +import scala.util._ +import io.gatling.core.Predef._ +import io.gatling.http.Predef._ +import scala.concurrent.duration._ + +class RewardsScenario extends Simulation { + + def randCustId() = Random.nextInt(99) + + val httpProtocol = http.baseUrl("http://localhost:8080") + .acceptHeader("text/html,application/json;q=0.9,*/*;q=0.8") + .doNotTrackHeader("1") + .acceptLanguageHeader("en-US,en;q=0.5") + .acceptEncodingHeader("gzip, deflate") + .userAgentHeader("Mozilla/5.0 (Windows NT 5.1; rv:31.0) Gecko/20100101 Firefox/31.0") + + val scn = scenario("RewardsScenario") + .repeat(10){ + exec(http("transactions_add") + .post("/transactions/add/") + .body(StringBody("""{ "customerRewardsId":null,"customerId":""""+ randCustId() + """","transactionDate":null }""")).asJson + .check(jsonPath("$.id").saveAs("txnId")) + .check(jsonPath("$.transactionDate").saveAs("txtDate")) + .check(jsonPath("$.customerId").saveAs("custId"))) + .pause(1) + + .exec(http("get_reward") + .get("/rewards/find/${custId}") + .check(jsonPath("$.id").saveAs("rwdId"))) + .pause(1) + + .doIf("${rwdId.isUndefined()}"){ + exec(http("rewards_add") + .post("/rewards/add") + .body(StringBody("""{ "customerId": "${custId}" }""")).asJson + .check(jsonPath("$.id").saveAs("rwdId"))) + } + + .exec(http("transactions_add") + .post("/transactions/add/") + .body(StringBody("""{ "customerRewardsId":"${rwdId}","customerId":"${custId}","transactionDate":"${txtDate}" }""")).asJson) + .pause(1) + + .exec(http("get_reward") + .get("/transactions/findAll/${rwdId}")) + } + setUp( + scn.inject(atOnceUsers(100)) + ).protocols(httpProtocol) +} \ No newline at end of file diff --git a/testing-modules/load-testing-comparison/src/main/resources/scripts/JMeter/Test Plan.jmx b/testing-modules/load-testing-comparison/src/main/resources/scripts/JMeter/Test Plan.jmx new file mode 100644 index 0000000000..da32a13a22 --- /dev/null +++ b/testing-modules/load-testing-comparison/src/main/resources/scripts/JMeter/Test Plan.jmx @@ -0,0 +1,293 @@ + + + + + + false + true + false + + + + + + + + continue + + false + 10 + + 100 + 0 + false + + + + + + true + 1 + + + + + + Content-Type + application/json + + + + + + true + + + + false + {"customerRewardsId":null,"customerId":${random},"transactionDate":null} + = + + + + localhost + 8080 + http + + /transactions/add + POST + true + false + true + false + + + + + + + txnId + $.id + 1 + all + foo + + + + txnDate + $.transactionDate + 1 + Never + + + + custId + $.customerId + 1 + all + bob + + + + + + + + localhost + 8080 + + + /rewards/find/${custId} + GET + true + false + true + false + + + + + + + rwdId + $.id + 1 + 0 + all + + + + + ${rwdId} == 0 + true + + + + true + + + + false + {"customerId":${custId}} + = + + + + localhost + 8080 + + + /rewards/add + POST + true + false + true + false + + + + + + + rwdId + $.id + 1 + bar + all + + + + + + true + + + + false + {"id":${txnId},"customerRewardsId":${rwdId},"customerId":${custId},"transactionDate":"${txnDate}"} + = + + + + localhost + 8080 + + + /transactions/add + POST + true + false + true + false + + + + + + + + + + localhost + 8080 + + + /transactions/findAll/${rwdId} + GET + true + false + true + false + + + + + + + + 10000 + 1 + + false + 67 + random + + + + false + + saveConfig + + + true + true + true + + true + true + true + true + false + true + true + false + false + false + true + false + false + false + true + 0 + true + true + true + true + true + true + + + + + + + false + + saveConfig + + + true + true + true + + true + true + true + true + false + true + true + false + false + false + true + false + false + false + true + 0 + true + true + true + true + true + true + + + + + + + + + diff --git a/testing-modules/load-testing-comparison/src/main/resources/scripts/The Grinder/grinder.properties b/testing-modules/load-testing-comparison/src/main/resources/scripts/The Grinder/grinder.properties new file mode 100644 index 0000000000..68adf90856 --- /dev/null +++ b/testing-modules/load-testing-comparison/src/main/resources/scripts/The Grinder/grinder.properties @@ -0,0 +1,5 @@ +grinder.script = grinder.py +grinder.threads = 100 +grinder.processes = 1 +grinder.runs = 10 +grinder.logDirectory = /logs diff --git a/testing-modules/load-testing-comparison/src/main/resources/scripts/The Grinder/grinder.py b/testing-modules/load-testing-comparison/src/main/resources/scripts/The Grinder/grinder.py new file mode 100644 index 0000000000..025f90d38b --- /dev/null +++ b/testing-modules/load-testing-comparison/src/main/resources/scripts/The Grinder/grinder.py @@ -0,0 +1,40 @@ +import java.util.Random +from net.grinder.script import Test +from net.grinder.script.Grinder import grinder +from net.grinder.plugin.http import HTTPRequest, HTTPPluginControl, HTTPUtilities +from HTTPClient import NVPair + +def parseJsonString(json, element): + for x in json.split(","): + pc = x.replace('"','').split(":") + if pc[0].replace("{","") == element: + ele = pc[1].replace("}","") + return ele + else: + return "" + +test1 = Test(1, "Request resource") +request1 = HTTPRequest() +headers = \ +( NVPair('Content-Type', 'application/json'), ) +request1.setHeaders(headers) +utilities = HTTPPluginControl.getHTTPUtilities() +test1.record(request1) +random=java.util.Random() + +class TestRunner: + def __call__(self): + customerId = str(random.nextInt()); + + result = request1.POST("http://localhost:8080/transactions/add", "{"'"customerRewardsId"'":null,"'"customerId"'":"+ customerId + ","'"transactionDate"'":null}") + txnId = parseJsonString(result.getText(), "id") + + result = request1.GET("http://localhost:8080/rewards/find/"+ customerId) + rwdId = parseJsonString(result.getText(), "id") + + if rwdId == "": + result = request1.POST("http://localhost:8080/rewards/add", "{"'"customerId"'":"+ customerId + "}") + rwdId = parseJsonString(result.getText(), "id") + + result = request1.POST("http://localhost:8080/transactions/add", "{"'"id"'":" + txnId + ","'"customerRewardsId"'":" + rwdId + ","'"customerId"'":"+ customerId + ","'"transactionDate"'":null}") + result = request1.GET("http://localhost:8080/transactions/findAll/" + rwdId) \ No newline at end of file From 668aa4a583105f6598bb861a63cd5ade1a72f854 Mon Sep 17 00:00:00 2001 From: Eugen Paraschiv Date: Thu, 22 Nov 2018 22:42:18 +0200 Subject: [PATCH 049/146] profiles work --- pom.xml | 14 +++++++++++--- spring-amqp-simple/pom.xml | 1 - 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index e36a972611..bc0c63213f 100644 --- a/pom.xml +++ b/pom.xml @@ -1089,7 +1089,6 @@ persistence-modules/solr persistence-modules/spring-data-dynamodb persistence-modules/spring-data-keyvalue - persistence-modules/spring-data-mongodb persistence-modules/spring-data-neo4j persistence-modules/spring-data-solr persistence-modules/spring-hibernate-5 @@ -1111,6 +1110,11 @@ rxjava-2 rabbitmq + + + @@ -1146,7 +1150,6 @@ parent-kotlin spring-4 - spring-5-data-reactive spring-5-reactive spring-5-reactive-security spring-5-reactive-client @@ -1156,7 +1159,6 @@ spring-akka spring-amqp spring-all - spring-amqp-simple spring-apache-camel spring-batch spring-bom @@ -1255,6 +1257,12 @@ spring-boot-ctx-fluent spring-webflux-amqp + + + diff --git a/spring-amqp-simple/pom.xml b/spring-amqp-simple/pom.xml index 3d9ea55cfa..ea9c227d8c 100644 --- a/spring-amqp-simple/pom.xml +++ b/spring-amqp-simple/pom.xml @@ -5,7 +5,6 @@ com.baeldung spring-amqp-simple 1.0.0-SNAPSHOT - Spring AMQP Simple App parent-boot-1 From 4c1f773d07d65bf3716e0d4089aebfbaf39bb04a Mon Sep 17 00:00:00 2001 From: Loredana Date: Thu, 22 Nov 2018 22:59:37 +0200 Subject: [PATCH 050/146] move constructors to java lang module --- core-java-lang/README.md | 1 + .../src/main/java/com/baeldung/constructors/BankAccount.java | 0 .../src/main/java/com/baeldung/constructors/Transaction.java | 0 .../test/java/com/baeldung/constructors/ConstructorUnitTest.java | 0 4 files changed, 1 insertion(+) rename {core-java => core-java-lang}/src/main/java/com/baeldung/constructors/BankAccount.java (100%) rename {core-java => core-java-lang}/src/main/java/com/baeldung/constructors/Transaction.java (100%) rename {core-java => core-java-lang}/src/test/java/com/baeldung/constructors/ConstructorUnitTest.java (100%) diff --git a/core-java-lang/README.md b/core-java-lang/README.md index 85312cba68..62af72818f 100644 --- a/core-java-lang/README.md +++ b/core-java-lang/README.md @@ -56,4 +56,5 @@ - [How to Separate Double into Integer and Decimal Parts](https://www.baeldung.com/java-separate-double-into-integer-decimal-parts) - [“Sneaky Throws” in Java](http://www.baeldung.com/java-sneaky-throws) - [Inheritance and Composition (Is-a vs Has-a relationship) in Java](http://www.baeldung.com/java-inheritance-composition) +- [A Guide to Constructors in Java](https://www.baeldung.com/java-constructors) diff --git a/core-java/src/main/java/com/baeldung/constructors/BankAccount.java b/core-java-lang/src/main/java/com/baeldung/constructors/BankAccount.java similarity index 100% rename from core-java/src/main/java/com/baeldung/constructors/BankAccount.java rename to core-java-lang/src/main/java/com/baeldung/constructors/BankAccount.java diff --git a/core-java/src/main/java/com/baeldung/constructors/Transaction.java b/core-java-lang/src/main/java/com/baeldung/constructors/Transaction.java similarity index 100% rename from core-java/src/main/java/com/baeldung/constructors/Transaction.java rename to core-java-lang/src/main/java/com/baeldung/constructors/Transaction.java diff --git a/core-java/src/test/java/com/baeldung/constructors/ConstructorUnitTest.java b/core-java-lang/src/test/java/com/baeldung/constructors/ConstructorUnitTest.java similarity index 100% rename from core-java/src/test/java/com/baeldung/constructors/ConstructorUnitTest.java rename to core-java-lang/src/test/java/com/baeldung/constructors/ConstructorUnitTest.java From bf184639e7f96754af246b9b78eef4a54b85b573 Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Thu, 22 Nov 2018 23:36:10 +0200 Subject: [PATCH 051/146] Update README.md --- patterns/design-patterns/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/patterns/design-patterns/README.md b/patterns/design-patterns/README.md index 75f7cec73a..ae372bd460 100644 --- a/patterns/design-patterns/README.md +++ b/patterns/design-patterns/README.md @@ -12,3 +12,4 @@ - [The DAO Pattern in Java](http://www.baeldung.com/java-dao-pattern) - [Interpreter Design Pattern in Java](http://www.baeldung.com/java-interpreter-pattern) - [State Design Pattern in Java](https://www.baeldung.com/java-state-design-pattern) +- [The Decorator Pattern in Java](https://www.baeldung.com/java-decorator-pattern) From d988b1280a2c7d2d31029f3f4f1734dbd78ff511 Mon Sep 17 00:00:00 2001 From: Loredana Date: Thu, 22 Nov 2018 23:59:22 +0200 Subject: [PATCH 052/146] fix test --- .../org/baeldung/client/TestRestTemplateBasicLiveTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spring-resttemplate/src/test/java/org/baeldung/client/TestRestTemplateBasicLiveTest.java b/spring-resttemplate/src/test/java/org/baeldung/client/TestRestTemplateBasicLiveTest.java index 03a76aca74..e303c75a28 100644 --- a/spring-resttemplate/src/test/java/org/baeldung/client/TestRestTemplateBasicLiveTest.java +++ b/spring-resttemplate/src/test/java/org/baeldung/client/TestRestTemplateBasicLiveTest.java @@ -58,9 +58,9 @@ public class TestRestTemplateBasicLiveTest { @Test public void givenRestTemplateWrapperWithCredentials_whenSendGetForEntity_thenStatusOk() { - RestTemplateBuilder restTemplateBuilder = new RestTemplateBuilder().basicAuthentication("user", "passwd"); + RestTemplateBuilder restTemplateBuilder = new RestTemplateBuilder(); restTemplateBuilder.configure(restTemplate); - TestRestTemplate testRestTemplate = new TestRestTemplate(restTemplateBuilder); + TestRestTemplate testRestTemplate = new TestRestTemplate(restTemplateBuilder, "user", "passwd"); ResponseEntity response = testRestTemplate.getForEntity(URL_SECURED_BY_AUTHENTICATION, String.class); assertThat(response.getStatusCode(), equalTo(HttpStatus.OK)); From 58a536c3953e8a3e71dd256d11a67d8bdf49b7c9 Mon Sep 17 00:00:00 2001 From: kyleandari <44148335+kyleandari@users.noreply.github.com> Date: Fri, 23 Nov 2018 10:46:20 -0500 Subject: [PATCH 053/146] BAEL 2330 * Implementing Hexagonal Architecture in java * Removing duplicates from a string * Fix for the code review feedback - removing the hexagonal architecture code - removing the methods removeDuplicatesUsingCharArray - adding some meaningful sentences to test * Fix for the code review feedback - fix for removeDuplicatesUsingCharArray - adding unit testing - adding brackets around for loops * Fix for the code review feedback * Adding remove duplicates using java 8 distinct adding assets to the unittests to test for empty strings * Checking for empty strings in unit tests Adding an if statement to check whether an empty string is passed to removeDuplicatesUsingSorting method --- .../RemoveDuplicateFromString.java | 25 ++++++++++++------- .../RemoveDuplicateFromStringUnitTest.java | 24 ++++++++++++++++++ 2 files changed, 40 insertions(+), 9 deletions(-) diff --git a/java-strings/src/main/java/com/baeldung/stringduplicates/RemoveDuplicateFromString.java b/java-strings/src/main/java/com/baeldung/stringduplicates/RemoveDuplicateFromString.java index eeba81f334..d8fd9c4b14 100644 --- a/java-strings/src/main/java/com/baeldung/stringduplicates/RemoveDuplicateFromString.java +++ b/java-strings/src/main/java/com/baeldung/stringduplicates/RemoveDuplicateFromString.java @@ -44,16 +44,16 @@ public class RemoveDuplicateFromString { } String removeDuplicatesUsingSorting(String str) { - - char[] chars = str.toCharArray(); - - Arrays.sort(chars); - StringBuilder sb = new StringBuilder(); - sb.append(chars[0]); - for (int i = 1; i < chars.length; i++) { - if (chars[i] != chars[i - 1]) { - sb.append(chars[i]); + if(!str.isEmpty()) { + char[] chars = str.toCharArray(); + Arrays.sort(chars); + + sb.append(chars[0]); + for (int i = 1; i < chars.length; i++) { + if (chars[i] != chars[i - 1]) { + sb.append(chars[i]); + } } } @@ -90,6 +90,13 @@ public class RemoveDuplicateFromString { return sb.toString(); } + + String removeDuplicatesUsingDistinct(String str) { + StringBuilder sb = new StringBuilder(); + str.chars().distinct().forEach(c -> sb.append((char) c)); + return sb.toString(); + } + } diff --git a/java-strings/src/test/java/com/baeldung/stringduplicates/RemoveDuplicateFromStringUnitTest.java b/java-strings/src/test/java/com/baeldung/stringduplicates/RemoveDuplicateFromStringUnitTest.java index cf7819ced3..895ecc4a3b 100644 --- a/java-strings/src/test/java/com/baeldung/stringduplicates/RemoveDuplicateFromStringUnitTest.java +++ b/java-strings/src/test/java/com/baeldung/stringduplicates/RemoveDuplicateFromStringUnitTest.java @@ -8,6 +8,8 @@ public class RemoveDuplicateFromStringUnitTest { private final static String STR1 = "racecar"; private final static String STR2 = "J2ee programming"; + private final static String STR_EMPTY = ""; + private RemoveDuplicateFromString removeDuplicateFromString; @Before @@ -20,6 +22,8 @@ public class RemoveDuplicateFromStringUnitTest { public void whenUsingCharArray_DuplicatesShouldBeRemovedWithoutKeepingStringOrder() { String str1 = removeDuplicateFromString.removeDuplicatesUsingCharArray(STR1); String str2 = removeDuplicateFromString.removeDuplicatesUsingCharArray(STR2); + String strEmpty = removeDuplicateFromString.removeDuplicatesUsingCharArray(STR_EMPTY); + Assert.assertEquals("", strEmpty); Assert.assertEquals("ecar", str1); Assert.assertEquals("J2e poraming", str2); } @@ -28,6 +32,9 @@ public class RemoveDuplicateFromStringUnitTest { public void whenUsingLinkedHashSet_DuplicatesShouldBeRemovedAndItKeepStringOrder() { String str1 = removeDuplicateFromString.removeDuplicatesUsinglinkedHashSet(STR1); String str2 = removeDuplicateFromString.removeDuplicatesUsinglinkedHashSet(STR2); + + String strEmpty = removeDuplicateFromString.removeDuplicatesUsinglinkedHashSet(STR_EMPTY); + Assert.assertEquals("", strEmpty); Assert.assertEquals("race", str1); Assert.assertEquals("J2e progamin", str2); } @@ -36,6 +43,9 @@ public class RemoveDuplicateFromStringUnitTest { public void whenUsingSorting_DuplicatesShouldBeRemovedWithoutKeepingStringOrder() { String str1 = removeDuplicateFromString.removeDuplicatesUsingSorting(STR1); String str2 = removeDuplicateFromString.removeDuplicatesUsingSorting(STR2); + + String strEmpty = removeDuplicateFromString.removeDuplicatesUsingSorting(STR_EMPTY); + Assert.assertEquals("", strEmpty); Assert.assertEquals("acer", str1); Assert.assertEquals(" 2Jaegimnopr", str2); } @@ -44,6 +54,8 @@ public class RemoveDuplicateFromStringUnitTest { public void whenUsingHashSet_DuplicatesShouldBeRemovedWithoutKeepingStringOrder() { String str1 = removeDuplicateFromString.removeDuplicatesUsingHashSet(STR1); String str2 = removeDuplicateFromString.removeDuplicatesUsingHashSet(STR2); + String strEmpty = removeDuplicateFromString.removeDuplicatesUsingHashSet(STR_EMPTY); + Assert.assertEquals("", strEmpty); Assert.assertEquals("arce", str1); Assert.assertEquals(" pa2regiJmno", str2); } @@ -52,7 +64,19 @@ public class RemoveDuplicateFromStringUnitTest { public void whenUsingIndexOf_DuplicatesShouldBeRemovedWithoutKeepingStringOrder() { String str1 = removeDuplicateFromString.removeDuplicatesUsingIndexOf(STR1); String str2 = removeDuplicateFromString.removeDuplicatesUsingIndexOf(STR2); + String strEmpty = removeDuplicateFromString.removeDuplicatesUsingIndexOf(STR_EMPTY); + Assert.assertEquals("", strEmpty); Assert.assertEquals("ecar", str1); Assert.assertEquals("J2e poraming", str2); } + + @Test + public void whenUsingJava8_DuplicatesShouldBeRemovedAndItKeepStringOrder() { + String str1 = removeDuplicateFromString.removeDuplicatesUsingDistinct(STR1); + String str2 = removeDuplicateFromString.removeDuplicatesUsingDistinct(STR2); + String strEmpty = removeDuplicateFromString.removeDuplicatesUsingDistinct(STR_EMPTY); + Assert.assertEquals("", strEmpty); + Assert.assertEquals("race", str1); + Assert.assertEquals("J2e progamin", str2); + } } From cfd9a97bd48769f4bbf937e0b71be49177ad1e02 Mon Sep 17 00:00:00 2001 From: Eugen Date: Fri, 23 Nov 2018 17:57:50 +0200 Subject: [PATCH 054/146] Delete README.md --- parent-boot-1/README.md | 1 - 1 file changed, 1 deletion(-) delete mode 100644 parent-boot-1/README.md diff --git a/parent-boot-1/README.md b/parent-boot-1/README.md deleted file mode 100644 index ff12555376..0000000000 --- a/parent-boot-1/README.md +++ /dev/null @@ -1 +0,0 @@ -## Relevant articles: From 64bc8a412d2a40d82fde575c6b542c5e18106f34 Mon Sep 17 00:00:00 2001 From: eelhazati Date: Fri, 23 Nov 2018 17:00:08 +0100 Subject: [PATCH 055/146] JPA Entity Graph. --- .../com/baeldung/jpa/entitygraph/MainApp.java | 26 ++++++ .../jpa/entitygraph/model/Comment.java | 63 +++++++++++++ .../baeldung/jpa/entitygraph/model/Post.java | 86 +++++++++++++++++ .../baeldung/jpa/entitygraph/model/User.java | 48 ++++++++++ .../jpa/entitygraph/repo/PostRepository.java | 93 +++++++++++++++++++ .../main/resources/META-INF/persistence.xml | 55 +++++++---- .../java-jpa/src/main/resources/data-init.sql | 8 ++ .../entitygraph/repo/PostRepositoryTest.java | 68 ++++++++++++++ 8 files changed, 428 insertions(+), 19 deletions(-) create mode 100644 persistence-modules/java-jpa/src/main/java/com/baeldung/jpa/entitygraph/MainApp.java create mode 100644 persistence-modules/java-jpa/src/main/java/com/baeldung/jpa/entitygraph/model/Comment.java create mode 100644 persistence-modules/java-jpa/src/main/java/com/baeldung/jpa/entitygraph/model/Post.java create mode 100644 persistence-modules/java-jpa/src/main/java/com/baeldung/jpa/entitygraph/model/User.java create mode 100644 persistence-modules/java-jpa/src/main/java/com/baeldung/jpa/entitygraph/repo/PostRepository.java create mode 100644 persistence-modules/java-jpa/src/main/resources/data-init.sql create mode 100644 persistence-modules/java-jpa/src/test/java/com/baeldung/jpa/entitygraph/repo/PostRepositoryTest.java diff --git a/persistence-modules/java-jpa/src/main/java/com/baeldung/jpa/entitygraph/MainApp.java b/persistence-modules/java-jpa/src/main/java/com/baeldung/jpa/entitygraph/MainApp.java new file mode 100644 index 0000000000..88aa4389e9 --- /dev/null +++ b/persistence-modules/java-jpa/src/main/java/com/baeldung/jpa/entitygraph/MainApp.java @@ -0,0 +1,26 @@ +package com.baeldung.jpa.entitygraph; + +import com.baeldung.jpa.entitygraph.model.Post; +import com.baeldung.jpa.entitygraph.repo.PostRepository; + +public class MainApp { + + public static void main(String... args) { + Long postId = 1L; + Post post = null; + PostRepository postRepository = new PostRepository(); + + //Using EntityManager.find(). + post = postRepository.find(postId); + post = postRepository.findWithEntityGraph(postId); + post = postRepository.findWithEntityGraph2(postId); + + //Using JPQL: Query and TypedQuery + post = postRepository.findUsingJpql(postId); + + //Using Criteria API + post = postRepository.findUsingCriteria(postId); + + postRepository.clean(); + } +} \ No newline at end of file diff --git a/persistence-modules/java-jpa/src/main/java/com/baeldung/jpa/entitygraph/model/Comment.java b/persistence-modules/java-jpa/src/main/java/com/baeldung/jpa/entitygraph/model/Comment.java new file mode 100644 index 0000000000..40ecd3262b --- /dev/null +++ b/persistence-modules/java-jpa/src/main/java/com/baeldung/jpa/entitygraph/model/Comment.java @@ -0,0 +1,63 @@ +package com.baeldung.jpa.entitygraph.model; + +import javax.persistence.*; + +@Entity +public class Comment { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + private String reply; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn + private Post post; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn + private User user; + //... + + public Comment() { + } + + public Comment(String reply, Post post, User user) { + this.reply = reply; + this.post = post; + this.user = user; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getReply() { + return reply; + } + + public void setReply(String reply) { + this.reply = reply; + } + + public Post getPost() { + return post; + } + + public void setPost(Post post) { + this.post = post; + } + + public User getUser() { + return user; + } + + public void setUser(User user) { + this.user = user; + } +} \ No newline at end of file diff --git a/persistence-modules/java-jpa/src/main/java/com/baeldung/jpa/entitygraph/model/Post.java b/persistence-modules/java-jpa/src/main/java/com/baeldung/jpa/entitygraph/model/Post.java new file mode 100644 index 0000000000..59f17ae0c5 --- /dev/null +++ b/persistence-modules/java-jpa/src/main/java/com/baeldung/jpa/entitygraph/model/Post.java @@ -0,0 +1,86 @@ +package com.baeldung.jpa.entitygraph.model; + +import javax.persistence.*; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +@NamedEntityGraph( + name = "post-entity-graph", + attributeNodes = { + @NamedAttributeNode("subject"), + @NamedAttributeNode("user"), + @NamedAttributeNode("comments"), + } +) +@NamedEntityGraph( + name = "post-entity-graph-with-comment-users", + attributeNodes = { + @NamedAttributeNode("subject"), + @NamedAttributeNode("user"), + @NamedAttributeNode(value = "comments", subgraph = "comments-subgraph"), + }, + subgraphs = { + @NamedSubgraph( + name = "comments-subgraph", + attributeNodes = { + @NamedAttributeNode("user") + } + ) + } +) +@Entity +public class Post { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + private String subject; + @OneToMany(mappedBy = "post") + private List comments = new ArrayList<>(); + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn + private User user; + //... + + public Post() { + } + + public Post(String subject, User user) { + this.subject = subject; + this.user = user; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getSubject() { + return subject; + } + + public void setSubject(String subject) { + this.subject = subject; + } + + public List getComments() { + return comments; + } + + public void setComments(List comments) { + this.comments = comments; + } + + public User getUser() { + return user; + } + + public void setUser(User user) { + this.user = user; + } +} diff --git a/persistence-modules/java-jpa/src/main/java/com/baeldung/jpa/entitygraph/model/User.java b/persistence-modules/java-jpa/src/main/java/com/baeldung/jpa/entitygraph/model/User.java new file mode 100644 index 0000000000..b712100d4e --- /dev/null +++ b/persistence-modules/java-jpa/src/main/java/com/baeldung/jpa/entitygraph/model/User.java @@ -0,0 +1,48 @@ +package com.baeldung.jpa.entitygraph.model; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; + +@Entity +public class User { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + private String name; + private String email; + + //... + + public User() { + } + + public User(String email) { + this.email = email; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } +} diff --git a/persistence-modules/java-jpa/src/main/java/com/baeldung/jpa/entitygraph/repo/PostRepository.java b/persistence-modules/java-jpa/src/main/java/com/baeldung/jpa/entitygraph/repo/PostRepository.java new file mode 100644 index 0000000000..28f1e1b93c --- /dev/null +++ b/persistence-modules/java-jpa/src/main/java/com/baeldung/jpa/entitygraph/repo/PostRepository.java @@ -0,0 +1,93 @@ +package com.baeldung.jpa.entitygraph.repo; + +import com.baeldung.jpa.entitygraph.model.Post; + +import javax.persistence.*; +import javax.persistence.criteria.CriteriaBuilder; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Root; +import java.util.HashMap; +import java.util.Map; + +public class PostRepository { + private EntityManagerFactory emf = null; + + + public PostRepository() { + Map properties = new HashMap(); + properties.put("hibernate.show_sql", "true"); + properties.put("hibernate.format_sql", "true"); + emf = Persistence.createEntityManagerFactory("entity-graph-pu", properties); + } + + public Post find(Long id) { + EntityManager entityManager = emf.createEntityManager(); + + Post post = entityManager.find(Post.class, id); + + entityManager.close(); + return post; + } + + public Post findWithEntityGraph(Long id) { + EntityManager entityManager = emf.createEntityManager(); + + EntityGraph entityGraph = entityManager.getEntityGraph("post-entity-graph"); + Map properties = new HashMap<>(); + properties.put("javax.persistence.fetchgraph", entityGraph); + Post post = entityManager.find(Post.class, id, properties); + + entityManager.close(); + return post; + } + + public Post findWithEntityGraph2(Long id) { + EntityManager entityManager = emf.createEntityManager(); + + EntityGraph entityGraph = entityManager.createEntityGraph(Post.class); + entityGraph.addAttributeNodes("subject"); + entityGraph.addAttributeNodes("user"); + entityGraph.addSubgraph("comments") + .addAttributeNodes("user"); + + Map properties = new HashMap<>(); + properties.put("javax.persistence.fetchgraph", entityGraph); + Post post = entityManager.find(Post.class, id, properties); + + entityManager.close(); + return post; + } + + public Post findUsingJpql(Long id) { + EntityManager entityManager = emf.createEntityManager(); + + EntityGraph entityGraph = entityManager.getEntityGraph("post-entity-graph-with-comment-users"); + Post post = entityManager.createQuery("Select p from Post p where p.id=:id", Post.class) + .setParameter("id", id) + .setHint("javax.persistence.fetchgraph", entityGraph) + .getSingleResult(); + + entityManager.close(); + return post; + } + + public Post findUsingCriteria(Long id) { + EntityManager entityManager = emf.createEntityManager(); + + EntityGraph entityGraph = entityManager.getEntityGraph("post-entity-graph-with-comment-users"); + CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder(); + CriteriaQuery criteriaQuery = criteriaBuilder.createQuery(Post.class); + Root root = criteriaQuery.from(Post.class); + criteriaQuery.where(criteriaBuilder.equal(root.get("id"), id)); + TypedQuery typedQuery = entityManager.createQuery(criteriaQuery); + typedQuery.setHint("javax.persistence.loadgraph", entityGraph); + Post post = typedQuery.getSingleResult(); + + entityManager.close(); + return post; + } + + public void clean() { + emf.close(); + } +} diff --git a/persistence-modules/java-jpa/src/main/resources/META-INF/persistence.xml b/persistence-modules/java-jpa/src/main/resources/META-INF/persistence.xml index 3fdc8ce27c..433d456cc9 100644 --- a/persistence-modules/java-jpa/src/main/resources/META-INF/persistence.xml +++ b/persistence-modules/java-jpa/src/main/resources/META-INF/persistence.xml @@ -9,12 +9,12 @@ org.hibernate.jpa.HibernatePersistenceProvider com.baeldung.sqlresultsetmapping.ScheduledDay - + - - - + value="jdbc:h2:mem:test;INIT=RUNSCRIPT FROM 'classpath:database.sql'"/> + + + @@ -25,28 +25,45 @@ org.hibernate.jpa.HibernatePersistenceProvider com.baeldung.jpa.stringcast.Message - - - - - - + + + + + + - + org.hibernate.jpa.HibernatePersistenceProvider com.baeldung.jpa.model.Car - - - - - - + + + + + + - + + + com.baeldung.jpa.entitygraph.model.Post + com.baeldung.jpa.entitygraph.model.User + com.baeldung.jpa.entitygraph.model.Comment + true + + + + + + + + + + + \ No newline at end of file diff --git a/persistence-modules/java-jpa/src/main/resources/data-init.sql b/persistence-modules/java-jpa/src/main/resources/data-init.sql new file mode 100644 index 0000000000..86c3f2a651 --- /dev/null +++ b/persistence-modules/java-jpa/src/main/resources/data-init.sql @@ -0,0 +1,8 @@ +INSERT INTO `USER` (`ID`,`NAME`,`EMAIL`) VALUES (1,'user1','user1@test.com'); +INSERT INTO `USER` (`ID`,`NAME`,`EMAIL`) VALUES (2,'user2','user2@test.com'); +INSERT INTO `USER` (`ID`,`NAME`,`EMAIL`) VALUES (3,'user3','user3@test.com'); + +INSERT INTO `POST` (`ID`,`SUBJECT`,`USER_ID`) VALUES (1,'JPA Entity Graph In Action',1); + +INSERT INTO `COMMENT` (`ID`,`REPLY`,`POST_ID`,`USER_ID`) VALUES (1,'Nice !!',1,2); +INSERT INTO `COMMENT` (`ID`,`REPLY`,`POST_ID`,`USER_ID`) VALUES (2,'Cool !!',1,3); diff --git a/persistence-modules/java-jpa/src/test/java/com/baeldung/jpa/entitygraph/repo/PostRepositoryTest.java b/persistence-modules/java-jpa/src/test/java/com/baeldung/jpa/entitygraph/repo/PostRepositoryTest.java new file mode 100644 index 0000000000..382742f223 --- /dev/null +++ b/persistence-modules/java-jpa/src/test/java/com/baeldung/jpa/entitygraph/repo/PostRepositoryTest.java @@ -0,0 +1,68 @@ +package com.baeldung.jpa.entitygraph.repo; + +import com.baeldung.jpa.entitygraph.model.Comment; +import com.baeldung.jpa.entitygraph.model.Post; +import com.baeldung.jpa.entitygraph.model.User; +import org.hibernate.LazyInitializationException; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +import static org.junit.Assert.*; + +public class PostRepositoryTest { + + private static PostRepository postRepository = null; + + @BeforeClass + public static void once() { + postRepository = new PostRepository(); + } + + @Test(expected = LazyInitializationException.class) + public void find() { + Post post = postRepository.find(1L); + assertNotNull(post.getUser()); + String email = post.getUser().getEmail(); + assertNull(email); + } + + @Test + public void findWithEntityGraph() { + Post post = postRepository.findWithEntityGraph(1L); + assertNotNull(post.getUser()); + String email = post.getUser().getEmail(); + assertNotNull(email); + } + + @Test(expected = LazyInitializationException.class) + public void findWithEntityGraph_Comment_Without_User() { + Post post = postRepository.findWithEntityGraph(1L); + assertNotNull(post.getUser()); + String email = post.getUser().getEmail(); + assertNotNull(email); + assertNotNull(post.getComments()); + assertEquals(post.getComments().size(), 2); + Comment comment = post.getComments().get(0); + assertNotNull(comment); + User user = comment.getUser(); + user.getEmail(); + } + + @Test + public void findWithEntityGraph2_Comment_With_User() { + Post post = postRepository.findWithEntityGraph2(1L); + assertNotNull(post.getComments()); + assertEquals(post.getComments().size(), 2); + Comment comment = post.getComments().get(0); + assertNotNull(comment); + User user = comment.getUser(); + assertNotNull(user); + assertEquals(user.getEmail(), "user2@test.com"); + } + + @AfterClass + public static void destroy() { + postRepository.clean(); + } +} \ No newline at end of file From 3d945c079a8b4daabc3a1cd0c15155f7aec2579f Mon Sep 17 00:00:00 2001 From: eric-martin Date: Fri, 23 Nov 2018 23:41:00 -0600 Subject: [PATCH 056/146] Added @DirtiesContext to SpringContextIntegrationTest --- .../test/java/org/baeldung/SpringContextIntegrationTest.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spring-jenkins-pipeline/src/test/java/org/baeldung/SpringContextIntegrationTest.java b/spring-jenkins-pipeline/src/test/java/org/baeldung/SpringContextIntegrationTest.java index 8eb1589de7..0354f7211c 100644 --- a/spring-jenkins-pipeline/src/test/java/org/baeldung/SpringContextIntegrationTest.java +++ b/spring-jenkins-pipeline/src/test/java/org/baeldung/SpringContextIntegrationTest.java @@ -3,12 +3,14 @@ package org.baeldung; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringRunner; import com.baeldung.SpringJenkinsPipelineApplication; @RunWith(SpringRunner.class) @SpringBootTest(classes = SpringJenkinsPipelineApplication.class) +@DirtiesContext public class SpringContextIntegrationTest { @Test From 6e3245a0f142d7dc2c836c1f6d67e013a27424a9 Mon Sep 17 00:00:00 2001 From: Eugen Paraschiv Date: Sat, 24 Nov 2018 12:17:39 +0200 Subject: [PATCH 057/146] profile work --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index bc0c63213f..ae5897b6f3 100644 --- a/pom.xml +++ b/pom.xml @@ -775,7 +775,7 @@ parent-kotlin testing-modules/gatling - geotools + From 0d6007309574c5e29c255fc910aedf9dfc8934a4 Mon Sep 17 00:00:00 2001 From: DOHA Date: Sat, 24 Nov 2018 13:36:14 +0200 Subject: [PATCH 058/146] customise oauth2 requests --- .../CustomAuthorizationRequestResolver.java | 50 ++++++++++++++ .../oauth2/CustomRequestEntityConverter.java | 26 +++++++ .../oauth2/CustomTokenResponseConverter.java | 67 +++++++++++++++++++ .../com/baeldung/oauth2/SecurityConfig.java | 18 ++++- 4 files changed, 159 insertions(+), 2 deletions(-) create mode 100644 spring-5-security/src/main/java/com/baeldung/oauth2/CustomAuthorizationRequestResolver.java create mode 100644 spring-5-security/src/main/java/com/baeldung/oauth2/CustomRequestEntityConverter.java create mode 100644 spring-5-security/src/main/java/com/baeldung/oauth2/CustomTokenResponseConverter.java diff --git a/spring-5-security/src/main/java/com/baeldung/oauth2/CustomAuthorizationRequestResolver.java b/spring-5-security/src/main/java/com/baeldung/oauth2/CustomAuthorizationRequestResolver.java new file mode 100644 index 0000000000..025064423d --- /dev/null +++ b/spring-5-security/src/main/java/com/baeldung/oauth2/CustomAuthorizationRequestResolver.java @@ -0,0 +1,50 @@ +package com.baeldung.oauth2; + +import java.util.HashMap; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; + +import org.springframework.security.oauth2.client.registration.ClientRegistrationRepository; +import org.springframework.security.oauth2.client.web.DefaultOAuth2AuthorizationRequestResolver; +import org.springframework.security.oauth2.client.web.OAuth2AuthorizationRequestResolver; +import org.springframework.security.oauth2.core.endpoint.OAuth2AuthorizationRequest; + +public class CustomAuthorizationRequestResolver implements OAuth2AuthorizationRequestResolver { + + private OAuth2AuthorizationRequestResolver defaultResolver; + + public CustomAuthorizationRequestResolver(ClientRegistrationRepository repo, String authorizationRequestBaseUri){ + defaultResolver = new DefaultOAuth2AuthorizationRequestResolver(repo, authorizationRequestBaseUri); + } + + @Override + public OAuth2AuthorizationRequest resolve(HttpServletRequest request) { + OAuth2AuthorizationRequest req = defaultResolver.resolve(request); + if(req != null){ + req = customizeAuthorizationRequest(req); + } + return req; + } + + @Override + public OAuth2AuthorizationRequest resolve(HttpServletRequest request, String clientRegistrationId) { + OAuth2AuthorizationRequest req = defaultResolver.resolve(request, clientRegistrationId); + if(req != null){ + req = customizeAuthorizationRequest(req); + } + return req; + } + + private OAuth2AuthorizationRequest customizeAuthorizationRequest(OAuth2AuthorizationRequest req) { + Map extraParams = new HashMap(); + extraParams.putAll(req.getAdditionalParameters()); //VIP note + extraParams.put("test", "extra"); + System.out.println("here ====================="); + return OAuth2AuthorizationRequest.from(req).additionalParameters(extraParams).build(); + } + + private OAuth2AuthorizationRequest customizeAuthorizationRequest1(OAuth2AuthorizationRequest req) { + return OAuth2AuthorizationRequest.from(req).state("xyz").build(); + } +} diff --git a/spring-5-security/src/main/java/com/baeldung/oauth2/CustomRequestEntityConverter.java b/spring-5-security/src/main/java/com/baeldung/oauth2/CustomRequestEntityConverter.java new file mode 100644 index 0000000000..8884065769 --- /dev/null +++ b/spring-5-security/src/main/java/com/baeldung/oauth2/CustomRequestEntityConverter.java @@ -0,0 +1,26 @@ +package com.baeldung.oauth2; + +import org.springframework.core.convert.converter.Converter; +import org.springframework.http.RequestEntity; +import org.springframework.security.oauth2.client.endpoint.OAuth2AuthorizationCodeGrantRequest; +import org.springframework.security.oauth2.client.endpoint.OAuth2AuthorizationCodeGrantRequestEntityConverter; +import org.springframework.util.MultiValueMap; + +public class CustomRequestEntityConverter implements Converter> { + + private OAuth2AuthorizationCodeGrantRequestEntityConverter defaultConverter; + + public CustomRequestEntityConverter() { + defaultConverter = new OAuth2AuthorizationCodeGrantRequestEntityConverter(); + } + + @Override + public RequestEntity convert(OAuth2AuthorizationCodeGrantRequest req) { + RequestEntity entity = defaultConverter.convert(req); + MultiValueMap params = (MultiValueMap) entity.getBody(); + params.add("test2", "extra2"); + System.out.println(params.entrySet()); + return new RequestEntity<>(params, entity.getHeaders(), entity.getMethod(), entity.getUrl()); + } + +} diff --git a/spring-5-security/src/main/java/com/baeldung/oauth2/CustomTokenResponseConverter.java b/spring-5-security/src/main/java/com/baeldung/oauth2/CustomTokenResponseConverter.java new file mode 100644 index 0000000000..741f44871a --- /dev/null +++ b/spring-5-security/src/main/java/com/baeldung/oauth2/CustomTokenResponseConverter.java @@ -0,0 +1,67 @@ +package com.baeldung.oauth2; + +import java.util.Arrays; +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import org.springframework.core.convert.converter.Converter; +import org.springframework.security.oauth2.core.OAuth2AccessToken; +import org.springframework.security.oauth2.core.endpoint.OAuth2AccessTokenResponse; +import org.springframework.security.oauth2.core.endpoint.OAuth2ParameterNames; +import org.springframework.util.StringUtils; + +public class CustomTokenResponseConverter implements Converter, OAuth2AccessTokenResponse> { + private static final Set TOKEN_RESPONSE_PARAMETER_NAMES = Stream.of( + OAuth2ParameterNames.ACCESS_TOKEN, + OAuth2ParameterNames.TOKEN_TYPE, + OAuth2ParameterNames.EXPIRES_IN, + OAuth2ParameterNames.REFRESH_TOKEN, + OAuth2ParameterNames.SCOPE) .collect(Collectors.toSet()); + + @Override + public OAuth2AccessTokenResponse convert(Map tokenResponseParameters) { + String accessToken = tokenResponseParameters.get(OAuth2ParameterNames.ACCESS_TOKEN); + + OAuth2AccessToken.TokenType accessTokenType = null; + if (OAuth2AccessToken.TokenType.BEARER.getValue() + .equalsIgnoreCase(tokenResponseParameters.get(OAuth2ParameterNames.TOKEN_TYPE))) { + accessTokenType = OAuth2AccessToken.TokenType.BEARER; + } + + long expiresIn = 0; + if (tokenResponseParameters.containsKey(OAuth2ParameterNames.EXPIRES_IN)) { + try { + expiresIn = Long.valueOf(tokenResponseParameters.get(OAuth2ParameterNames.EXPIRES_IN)); + } catch (NumberFormatException ex) { + } + } + + Set scopes = Collections.emptySet(); + if (tokenResponseParameters.containsKey(OAuth2ParameterNames.SCOPE)) { + String scope = tokenResponseParameters.get(OAuth2ParameterNames.SCOPE); + scopes = Arrays.stream(StringUtils.delimitedListToStringArray(scope, " ")) + .collect(Collectors.toSet()); + } + + String refreshToken = tokenResponseParameters.get(OAuth2ParameterNames.REFRESH_TOKEN); + + Map additionalParameters = new LinkedHashMap<>(); + tokenResponseParameters.entrySet() + .stream() + .filter(e -> !TOKEN_RESPONSE_PARAMETER_NAMES.contains(e.getKey())) + .forEach(e -> additionalParameters.put(e.getKey(), e.getValue())); + + return OAuth2AccessTokenResponse.withToken(accessToken) + .tokenType(accessTokenType) + .expiresIn(expiresIn) + .scopes(scopes) + .refreshToken(refreshToken) + .additionalParameters(additionalParameters) + .build(); + } + +} diff --git a/spring-5-security/src/main/java/com/baeldung/oauth2/SecurityConfig.java b/spring-5-security/src/main/java/com/baeldung/oauth2/SecurityConfig.java index b45f325767..cf27b01a75 100644 --- a/spring-5-security/src/main/java/com/baeldung/oauth2/SecurityConfig.java +++ b/spring-5-security/src/main/java/com/baeldung/oauth2/SecurityConfig.java @@ -9,18 +9,22 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.PropertySource; import org.springframework.core.env.Environment; +import org.springframework.http.converter.FormHttpMessageConverter; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; import org.springframework.security.config.oauth2.client.CommonOAuth2Provider; -import org.springframework.security.oauth2.client.endpoint.NimbusAuthorizationCodeTokenResponseClient; +import org.springframework.security.oauth2.client.endpoint.DefaultAuthorizationCodeTokenResponseClient; import org.springframework.security.oauth2.client.endpoint.OAuth2AccessTokenResponseClient; import org.springframework.security.oauth2.client.endpoint.OAuth2AuthorizationCodeGrantRequest; +import org.springframework.security.oauth2.client.http.OAuth2ErrorResponseErrorHandler; import org.springframework.security.oauth2.client.registration.ClientRegistration; import org.springframework.security.oauth2.client.registration.ClientRegistrationRepository; import org.springframework.security.oauth2.client.registration.InMemoryClientRegistrationRepository; import org.springframework.security.oauth2.client.web.AuthorizationRequestRepository; import org.springframework.security.oauth2.client.web.HttpSessionOAuth2AuthorizationRequestRepository; import org.springframework.security.oauth2.core.endpoint.OAuth2AuthorizationRequest; +import org.springframework.security.oauth2.core.http.converter.OAuth2AccessTokenResponseHttpMessageConverter; +import org.springframework.web.client.RestTemplate; @Configuration @PropertySource("application-oauth2.properties") @@ -37,6 +41,8 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter { .oauth2Login() .loginPage("/oauth_login") .authorizationEndpoint() + .authorizationRequestResolver( new CustomAuthorizationRequestResolver(clientRegistrationRepository(),"/oauth2/authorize-client")) + .baseUri("/oauth2/authorize-client") .authorizationRequestRepository(authorizationRequestRepository()) .and() @@ -54,7 +60,15 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter { @Bean public OAuth2AccessTokenResponseClient accessTokenResponseClient() { - return new NimbusAuthorizationCodeTokenResponseClient(); + DefaultAuthorizationCodeTokenResponseClient accessTokenResponseClient = new DefaultAuthorizationCodeTokenResponseClient(); + accessTokenResponseClient.setRequestEntityConverter(new CustomRequestEntityConverter()); + + OAuth2AccessTokenResponseHttpMessageConverter tokenResponseHttpMessageConverter = new OAuth2AccessTokenResponseHttpMessageConverter(); + tokenResponseHttpMessageConverter.setTokenResponseConverter(new CustomTokenResponseConverter()); + RestTemplate restTemplate = new RestTemplate(Arrays.asList(new FormHttpMessageConverter(), tokenResponseHttpMessageConverter)); + restTemplate.setErrorHandler(new OAuth2ErrorResponseErrorHandler()); + accessTokenResponseClient.setRestOperations(restTemplate); + return accessTokenResponseClient; } From a6c9c5840f9942c89a7318c6ea7cced0de058345 Mon Sep 17 00:00:00 2001 From: Eugen Paraschiv Date: Sat, 24 Nov 2018 13:36:27 +0200 Subject: [PATCH 059/146] disabling unnecessary repo --- libraries/pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/pom.xml b/libraries/pom.xml index 8ffd33272d..936e86873d 100644 --- a/libraries/pom.xml +++ b/libraries/pom.xml @@ -720,11 +720,11 @@ - + false From 991436fa16b659cbe79a053f8ed4781f0662d284 Mon Sep 17 00:00:00 2001 From: saikat Date: Sat, 24 Nov 2018 18:58:48 +0530 Subject: [PATCH 060/146] Rename project module --- pom.xml | 2 +- {restx-demo => restx}/data/credentials.json | 0 {restx-demo => restx}/data/users.json | 0 {restx-demo => restx}/md.restx.json | 0 {restx-demo => restx}/pom.xml | 3 +-- {restx-demo => restx}/src/main/java/restx/demo/AppModule.java | 0 {restx-demo => restx}/src/main/java/restx/demo/AppServer.java | 0 {restx-demo => restx}/src/main/java/restx/demo/Roles.java | 0 .../src/main/java/restx/demo/domain/Message.java | 0 .../src/main/java/restx/demo/rest/HelloResource.java | 0 {restx-demo => restx}/src/main/resources/logback.xml | 0 .../src/main/resources/restx/demo/settings.properties | 0 {restx-demo => restx}/src/main/webapp/WEB-INF/web.xml | 0 .../test/java/restx/demo/rest/HelloResourceSpecUnitTest.java | 0 .../resources/specs/hello/should_admin_say_hello.spec.yaml | 0 .../resources/specs/hello/should_anyone_say_hello.spec.yaml | 0 .../should_missing_value_triggers_validation_error.spec.yaml | 0 .../resources/specs/hello/should_user1_say_hello.spec.yaml | 0 .../resources/specs/hello/should_user2_not_say_hello.spec.yaml | 0 19 files changed, 2 insertions(+), 3 deletions(-) rename {restx-demo => restx}/data/credentials.json (100%) rename {restx-demo => restx}/data/users.json (100%) rename {restx-demo => restx}/md.restx.json (100%) rename {restx-demo => restx}/pom.xml (98%) rename {restx-demo => restx}/src/main/java/restx/demo/AppModule.java (100%) rename {restx-demo => restx}/src/main/java/restx/demo/AppServer.java (100%) rename {restx-demo => restx}/src/main/java/restx/demo/Roles.java (100%) rename {restx-demo => restx}/src/main/java/restx/demo/domain/Message.java (100%) rename {restx-demo => restx}/src/main/java/restx/demo/rest/HelloResource.java (100%) rename {restx-demo => restx}/src/main/resources/logback.xml (100%) rename {restx-demo => restx}/src/main/resources/restx/demo/settings.properties (100%) rename {restx-demo => restx}/src/main/webapp/WEB-INF/web.xml (100%) rename restx-demo/src/test/java/restx/demo/rest/HelloResourceSpecTest.java => restx/src/test/java/restx/demo/rest/HelloResourceSpecUnitTest.java (100%) rename {restx-demo => restx}/src/test/resources/specs/hello/should_admin_say_hello.spec.yaml (100%) rename {restx-demo => restx}/src/test/resources/specs/hello/should_anyone_say_hello.spec.yaml (100%) rename {restx-demo => restx}/src/test/resources/specs/hello/should_missing_value_triggers_validation_error.spec.yaml (100%) rename {restx-demo => restx}/src/test/resources/specs/hello/should_user1_say_hello.spec.yaml (100%) rename {restx-demo => restx}/src/test/resources/specs/hello/should_user2_not_say_hello.spec.yaml (100%) diff --git a/pom.xml b/pom.xml index 10e23da0ad..77c666b3ab 100644 --- a/pom.xml +++ b/pom.xml @@ -1608,7 +1608,7 @@ persistence-modules/spring-data-elasticsearch core-java-concurrency core-java-concurrency-collections - restx-demo + restx diff --git a/restx-demo/data/credentials.json b/restx/data/credentials.json similarity index 100% rename from restx-demo/data/credentials.json rename to restx/data/credentials.json diff --git a/restx-demo/data/users.json b/restx/data/users.json similarity index 100% rename from restx-demo/data/users.json rename to restx/data/users.json diff --git a/restx-demo/md.restx.json b/restx/md.restx.json similarity index 100% rename from restx-demo/md.restx.json rename to restx/md.restx.json diff --git a/restx-demo/pom.xml b/restx/pom.xml similarity index 98% rename from restx-demo/pom.xml rename to restx/pom.xml index da106b8191..c6233b968c 100644 --- a/restx-demo/pom.xml +++ b/restx/pom.xml @@ -4,8 +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 - restx-demo - restx-demo + restx 0.1-SNAPSHOT war restx-demo diff --git a/restx-demo/src/main/java/restx/demo/AppModule.java b/restx/src/main/java/restx/demo/AppModule.java similarity index 100% rename from restx-demo/src/main/java/restx/demo/AppModule.java rename to restx/src/main/java/restx/demo/AppModule.java diff --git a/restx-demo/src/main/java/restx/demo/AppServer.java b/restx/src/main/java/restx/demo/AppServer.java similarity index 100% rename from restx-demo/src/main/java/restx/demo/AppServer.java rename to restx/src/main/java/restx/demo/AppServer.java diff --git a/restx-demo/src/main/java/restx/demo/Roles.java b/restx/src/main/java/restx/demo/Roles.java similarity index 100% rename from restx-demo/src/main/java/restx/demo/Roles.java rename to restx/src/main/java/restx/demo/Roles.java diff --git a/restx-demo/src/main/java/restx/demo/domain/Message.java b/restx/src/main/java/restx/demo/domain/Message.java similarity index 100% rename from restx-demo/src/main/java/restx/demo/domain/Message.java rename to restx/src/main/java/restx/demo/domain/Message.java diff --git a/restx-demo/src/main/java/restx/demo/rest/HelloResource.java b/restx/src/main/java/restx/demo/rest/HelloResource.java similarity index 100% rename from restx-demo/src/main/java/restx/demo/rest/HelloResource.java rename to restx/src/main/java/restx/demo/rest/HelloResource.java diff --git a/restx-demo/src/main/resources/logback.xml b/restx/src/main/resources/logback.xml similarity index 100% rename from restx-demo/src/main/resources/logback.xml rename to restx/src/main/resources/logback.xml diff --git a/restx-demo/src/main/resources/restx/demo/settings.properties b/restx/src/main/resources/restx/demo/settings.properties similarity index 100% rename from restx-demo/src/main/resources/restx/demo/settings.properties rename to restx/src/main/resources/restx/demo/settings.properties diff --git a/restx-demo/src/main/webapp/WEB-INF/web.xml b/restx/src/main/webapp/WEB-INF/web.xml similarity index 100% rename from restx-demo/src/main/webapp/WEB-INF/web.xml rename to restx/src/main/webapp/WEB-INF/web.xml diff --git a/restx-demo/src/test/java/restx/demo/rest/HelloResourceSpecTest.java b/restx/src/test/java/restx/demo/rest/HelloResourceSpecUnitTest.java similarity index 100% rename from restx-demo/src/test/java/restx/demo/rest/HelloResourceSpecTest.java rename to restx/src/test/java/restx/demo/rest/HelloResourceSpecUnitTest.java diff --git a/restx-demo/src/test/resources/specs/hello/should_admin_say_hello.spec.yaml b/restx/src/test/resources/specs/hello/should_admin_say_hello.spec.yaml similarity index 100% rename from restx-demo/src/test/resources/specs/hello/should_admin_say_hello.spec.yaml rename to restx/src/test/resources/specs/hello/should_admin_say_hello.spec.yaml diff --git a/restx-demo/src/test/resources/specs/hello/should_anyone_say_hello.spec.yaml b/restx/src/test/resources/specs/hello/should_anyone_say_hello.spec.yaml similarity index 100% rename from restx-demo/src/test/resources/specs/hello/should_anyone_say_hello.spec.yaml rename to restx/src/test/resources/specs/hello/should_anyone_say_hello.spec.yaml diff --git a/restx-demo/src/test/resources/specs/hello/should_missing_value_triggers_validation_error.spec.yaml b/restx/src/test/resources/specs/hello/should_missing_value_triggers_validation_error.spec.yaml similarity index 100% rename from restx-demo/src/test/resources/specs/hello/should_missing_value_triggers_validation_error.spec.yaml rename to restx/src/test/resources/specs/hello/should_missing_value_triggers_validation_error.spec.yaml diff --git a/restx-demo/src/test/resources/specs/hello/should_user1_say_hello.spec.yaml b/restx/src/test/resources/specs/hello/should_user1_say_hello.spec.yaml similarity index 100% rename from restx-demo/src/test/resources/specs/hello/should_user1_say_hello.spec.yaml rename to restx/src/test/resources/specs/hello/should_user1_say_hello.spec.yaml diff --git a/restx-demo/src/test/resources/specs/hello/should_user2_not_say_hello.spec.yaml b/restx/src/test/resources/specs/hello/should_user2_not_say_hello.spec.yaml similarity index 100% rename from restx-demo/src/test/resources/specs/hello/should_user2_not_say_hello.spec.yaml rename to restx/src/test/resources/specs/hello/should_user2_not_say_hello.spec.yaml From 9ba79376452c320ebb8b9b6cca7a61920a0f9767 Mon Sep 17 00:00:00 2001 From: saikat Date: Sat, 24 Nov 2018 19:00:09 +0530 Subject: [PATCH 061/146] Rename unit test to fix PMD failure --- .../java/restx/demo/rest/HelloResourceSpecUnitTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/restx/src/test/java/restx/demo/rest/HelloResourceSpecUnitTest.java b/restx/src/test/java/restx/demo/rest/HelloResourceSpecUnitTest.java index 138a22d074..f67e4565b3 100644 --- a/restx/src/test/java/restx/demo/rest/HelloResourceSpecUnitTest.java +++ b/restx/src/test/java/restx/demo/rest/HelloResourceSpecUnitTest.java @@ -1,13 +1,13 @@ package restx.demo.rest; -import restx.demo.AppServer; import org.junit.runner.RunWith; -import restx.tests.RestxSpecTestsRunner; + import restx.tests.FindSpecsIn; +import restx.tests.RestxSpecTestsRunner; @RunWith(RestxSpecTestsRunner.class) @FindSpecsIn("specs/hello") -public class HelloResourceSpecTest { +public class HelloResourceSpecUnitTest { /** * Useless, thanks to both @RunWith(RestxSpecTestsRunner.class) & @FindSpecsIn() From 8d393165c4ce7a372b0ff5a595d9351b8a4afa48 Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Sat, 24 Nov 2018 18:35:05 +0200 Subject: [PATCH 062/146] Update and rename PostRepositoryTest.java to PostRepositoryIntegrationTest.java --- ...RepositoryTest.java => PostRepositoryIntegrationTest.java} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename persistence-modules/java-jpa/src/test/java/com/baeldung/jpa/entitygraph/repo/{PostRepositoryTest.java => PostRepositoryIntegrationTest.java} (94%) diff --git a/persistence-modules/java-jpa/src/test/java/com/baeldung/jpa/entitygraph/repo/PostRepositoryTest.java b/persistence-modules/java-jpa/src/test/java/com/baeldung/jpa/entitygraph/repo/PostRepositoryIntegrationTest.java similarity index 94% rename from persistence-modules/java-jpa/src/test/java/com/baeldung/jpa/entitygraph/repo/PostRepositoryTest.java rename to persistence-modules/java-jpa/src/test/java/com/baeldung/jpa/entitygraph/repo/PostRepositoryIntegrationTest.java index 382742f223..4724bb41ad 100644 --- a/persistence-modules/java-jpa/src/test/java/com/baeldung/jpa/entitygraph/repo/PostRepositoryTest.java +++ b/persistence-modules/java-jpa/src/test/java/com/baeldung/jpa/entitygraph/repo/PostRepositoryIntegrationTest.java @@ -10,7 +10,7 @@ import org.junit.Test; import static org.junit.Assert.*; -public class PostRepositoryTest { +public class PostRepositoryIntegrationTest { private static PostRepository postRepository = null; @@ -65,4 +65,4 @@ public class PostRepositoryTest { public static void destroy() { postRepository.clean(); } -} \ No newline at end of file +} From 27ec13ea96cf876ba159babd9ec4e4a67c0877ca Mon Sep 17 00:00:00 2001 From: amit2103 Date: Sun, 25 Nov 2018 00:23:51 +0530 Subject: [PATCH 063/146] [BAEL-9712] - Modifed oauth version --- spring-5-security-oauth/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-5-security-oauth/pom.xml b/spring-5-security-oauth/pom.xml index 13359ae84a..33a0677724 100644 --- a/spring-5-security-oauth/pom.xml +++ b/spring-5-security-oauth/pom.xml @@ -66,7 +66,7 @@ - 2.0.5.RELEASE + 2.0.1.RELEASE From 4e4da4eb7739315bd797491938998723f850174e Mon Sep 17 00:00:00 2001 From: Loredana Date: Sat, 24 Nov 2018 21:50:20 +0200 Subject: [PATCH 064/146] fix start, edit readme --- spring-5-security-oauth/README.md | 3 ++- spring-5-security-oauth/pom.xml | 1 + spring-5-security/README.md | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/spring-5-security-oauth/README.md b/spring-5-security-oauth/README.md index 81d95c07d7..f13925992b 100644 --- a/spring-5-security-oauth/README.md +++ b/spring-5-security-oauth/README.md @@ -1,3 +1,4 @@ ## Relevant articles: -- [Spring Security 5 -OAuth2 Login](http://www.baeldung.com/spring-security-5-oauth2-login) \ No newline at end of file +- [Spring Security 5 -OAuth2 Login](http://www.baeldung.com/spring-security-5-oauth2-login) +- [Extracting Principal and Authorities using Spring Security OAuth](https://www.baeldung.com/spring-security-oauth-principal-authorities-extractor) diff --git a/spring-5-security-oauth/pom.xml b/spring-5-security-oauth/pom.xml index 33a0677724..f200052adf 100644 --- a/spring-5-security-oauth/pom.xml +++ b/spring-5-security-oauth/pom.xml @@ -67,6 +67,7 @@ 2.0.1.RELEASE + com.baeldung.oauth2.SpringOAuthApplication diff --git a/spring-5-security/README.md b/spring-5-security/README.md index 6e094e928f..37dc8b0f28 100644 --- a/spring-5-security/README.md +++ b/spring-5-security/README.md @@ -4,4 +4,4 @@ - [A Custom Spring SecurityConfigurer](http://www.baeldung.com/spring-security-custom-configurer) - [New Password Storage In Spring Security 5](http://www.baeldung.com/spring-security-5-password-storage) - [Default Password Encoder in Spring Security 5](https://www.baeldung.com/spring-security-5-default-password-encoder) -- [Extracting Principal and Authorities using Spring Security OAuth](https://www.baeldung.com/spring-security-oauth-principal-authorities-extractor) + From bff2c6f5b06ded73a09fce5ef6bc78cfc5645621 Mon Sep 17 00:00:00 2001 From: amit2103 Date: Sun, 25 Nov 2018 01:25:41 +0530 Subject: [PATCH 065/146] [BAEL-10780] - Added code for the checking string input article --- .../string/checkinputs/CheckIntegerInput.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 java-strings/src/main/java/com/baeldung/string/checkinputs/CheckIntegerInput.java diff --git a/java-strings/src/main/java/com/baeldung/string/checkinputs/CheckIntegerInput.java b/java-strings/src/main/java/com/baeldung/string/checkinputs/CheckIntegerInput.java new file mode 100644 index 0000000000..9462244bbb --- /dev/null +++ b/java-strings/src/main/java/com/baeldung/string/checkinputs/CheckIntegerInput.java @@ -0,0 +1,19 @@ +package com.baeldung.string.checkinputs; + +import java.util.Scanner; + +public class CheckIntegerInput { + + public static void main(String[] args) { + + try (Scanner scanner = new Scanner(System.in)) { + System.out.println("Enter an integer : "); + + if (scanner.hasNextInt()) { + System.out.println("You entered : " + scanner.nextInt()); + } else { + System.out.println("The input is not an integer"); + } + } + } +} \ No newline at end of file From 3c3d484eeb6a5676e3055cfa2d4b43c369b8a30b Mon Sep 17 00:00:00 2001 From: Alejandro Gervasio Date: Sat, 24 Nov 2018 18:02:25 -0300 Subject: [PATCH 066/146] BAEL-2354 - An Introduction to the Event Notification Model in CDI 2.0 (#5685) * Initial Commit * Update pom.xml * Update pom.xml * Update LowercaseTextServiceUnitTest.java * Update UppercaseTextServiceUnitTest.java * Delete TextApplication.java * Update source files * Update BootstrappingApplication.java * Add AnotherSimpleEventObserver class * Rename event classes * Update ExampleEventSource.java * Update UppercaseTextService.java * Delete TextService.java * Delete LowercaseTextService.java * Delete LowercaseTextServiceUnitTest.java * Delete UppercaseTextServiceUnitTest.java * Fixed text service unit test * Update TextService.java --- cdi/pom.xml | 25 +++++++++++-------- .../application/BootstrappingApplication.java | 15 +++++++++++ .../cdi2observers/events/ExampleEvent.java | 14 +++++++++++ .../events/ExampleEventSource.java | 14 +++++++++++ .../AnotherExampleEventObserver.java | 12 +++++++++ .../observers/ExampleEventObserver.java | 13 ++++++++++ .../cdi2observers/services/TextService.java | 8 ++++++ .../tests/TextServiceUnitTest.java | 14 +++++++++++ 8 files changed, 105 insertions(+), 10 deletions(-) create mode 100644 cdi/src/main/java/com/baeldung/cdi2observers/application/BootstrappingApplication.java create mode 100644 cdi/src/main/java/com/baeldung/cdi2observers/events/ExampleEvent.java create mode 100644 cdi/src/main/java/com/baeldung/cdi2observers/events/ExampleEventSource.java create mode 100644 cdi/src/main/java/com/baeldung/cdi2observers/observers/AnotherExampleEventObserver.java create mode 100644 cdi/src/main/java/com/baeldung/cdi2observers/observers/ExampleEventObserver.java create mode 100644 cdi/src/main/java/com/baeldung/cdi2observers/services/TextService.java create mode 100644 cdi/src/test/java/com/baeldung/test/cdi2observers/tests/TextServiceUnitTest.java diff --git a/cdi/pom.xml b/cdi/pom.xml index 2c719c1d7f..0b735e0ca5 100644 --- a/cdi/pom.xml +++ b/cdi/pom.xml @@ -5,7 +5,7 @@ com.baeldung cdi 1.0-SNAPSHOT - + com.baeldung parent-spring-4 @@ -14,6 +14,16 @@ + + javax.enterprise + cdi-api + ${cdi-api.version} + + + org.jboss.weld.se + weld-se-core + ${weld-se-core.version} + org.hamcrest hamcrest-core @@ -42,11 +52,6 @@ aspectjweaver ${aspectjweaver.version} - - org.jboss.weld.se - weld-se-core - ${weld-se-core.version} - org.springframework spring-test @@ -54,13 +59,13 @@ test - - 1.8.9 - 2.4.1.Final + 2.0.SP1 + 3.0.5.Final + 1.9.2 1.3 3.10.0 4.12 + 5.1.2.RELEASE - diff --git a/cdi/src/main/java/com/baeldung/cdi2observers/application/BootstrappingApplication.java b/cdi/src/main/java/com/baeldung/cdi2observers/application/BootstrappingApplication.java new file mode 100644 index 0000000000..4896408502 --- /dev/null +++ b/cdi/src/main/java/com/baeldung/cdi2observers/application/BootstrappingApplication.java @@ -0,0 +1,15 @@ +package com.baeldung.cdi.cdi2observers.application; + +import com.baeldung.cdi.cdi2observers.events.ExampleEvent; +import javax.enterprise.inject.se.SeContainer; +import javax.enterprise.inject.se.SeContainerInitializer; + +public class BootstrappingApplication { + + public static void main(String... args) { + SeContainerInitializer containerInitializer = SeContainerInitializer.newInstance(); + try (SeContainer container = containerInitializer.initialize()) { + container.getBeanManager().fireEvent(new ExampleEvent("Welcome to Baeldung!")); + } + } +} diff --git a/cdi/src/main/java/com/baeldung/cdi2observers/events/ExampleEvent.java b/cdi/src/main/java/com/baeldung/cdi2observers/events/ExampleEvent.java new file mode 100644 index 0000000000..a2329d2ef1 --- /dev/null +++ b/cdi/src/main/java/com/baeldung/cdi2observers/events/ExampleEvent.java @@ -0,0 +1,14 @@ +package com.baeldung.cdi.cdi2observers.events; + +public class ExampleEvent { + + private final String eventMessage; + + public ExampleEvent(String eventMessage) { + this.eventMessage = eventMessage; + } + + public String getEventMessage() { + return eventMessage; + } +} diff --git a/cdi/src/main/java/com/baeldung/cdi2observers/events/ExampleEventSource.java b/cdi/src/main/java/com/baeldung/cdi2observers/events/ExampleEventSource.java new file mode 100644 index 0000000000..f37030778a --- /dev/null +++ b/cdi/src/main/java/com/baeldung/cdi2observers/events/ExampleEventSource.java @@ -0,0 +1,14 @@ +package com.baeldung.cdi.cdi2observers.events; + +import javax.enterprise.event.Event; +import javax.inject.Inject; + +public class ExampleEventSource { + + @Inject + Event exampleEvent; + + public void fireEvent() { + exampleEvent.fireAsync(new ExampleEvent("Welcome to Baeldung!")); + } +} diff --git a/cdi/src/main/java/com/baeldung/cdi2observers/observers/AnotherExampleEventObserver.java b/cdi/src/main/java/com/baeldung/cdi2observers/observers/AnotherExampleEventObserver.java new file mode 100644 index 0000000000..34520c2b3d --- /dev/null +++ b/cdi/src/main/java/com/baeldung/cdi2observers/observers/AnotherExampleEventObserver.java @@ -0,0 +1,12 @@ +package com.baeldung.cdi.cdi2observers.observers; + +import com.baeldung.cdi.cdi2observers.events.ExampleEvent; +import javax.annotation.Priority; +import javax.enterprise.event.Observes; + +public class AnotherExampleEventObserver { + + public String onEvent(@Observes @Priority(2) ExampleEvent event) { + return event.getEventMessage(); + } +} diff --git a/cdi/src/main/java/com/baeldung/cdi2observers/observers/ExampleEventObserver.java b/cdi/src/main/java/com/baeldung/cdi2observers/observers/ExampleEventObserver.java new file mode 100644 index 0000000000..b3522b2ad0 --- /dev/null +++ b/cdi/src/main/java/com/baeldung/cdi2observers/observers/ExampleEventObserver.java @@ -0,0 +1,13 @@ +package com.baeldung.cdi.cdi2observers.observers; + +import com.baeldung.cdi.cdi2observers.events.ExampleEvent; +import com.baeldung.cdi.cdi2observers.services.TextService; +import javax.annotation.Priority; +import javax.enterprise.event.Observes; + +public class ExampleEventObserver { + + public String onEvent(@Observes @Priority(1) ExampleEvent event, TextService textService) { + return textService.parseText(event.getEventMessage()); + } +} diff --git a/cdi/src/main/java/com/baeldung/cdi2observers/services/TextService.java b/cdi/src/main/java/com/baeldung/cdi2observers/services/TextService.java new file mode 100644 index 0000000000..47788a0657 --- /dev/null +++ b/cdi/src/main/java/com/baeldung/cdi2observers/services/TextService.java @@ -0,0 +1,8 @@ +package com.baeldung.cdi.cdi2observers.services; + +public class TextService { + + public String parseText(String text) { + return text.toUpperCase(); + } +} diff --git a/cdi/src/test/java/com/baeldung/test/cdi2observers/tests/TextServiceUnitTest.java b/cdi/src/test/java/com/baeldung/test/cdi2observers/tests/TextServiceUnitTest.java new file mode 100644 index 0000000000..deecf13f9a --- /dev/null +++ b/cdi/src/test/java/com/baeldung/test/cdi2observers/tests/TextServiceUnitTest.java @@ -0,0 +1,14 @@ +package com.baeldung.cdi.cdi2observers.tests; + +import com.baeldung.cdi.cdi2observers.services.TextService; +import static org.assertj.core.api.Assertions.assertThat; +import org.junit.Test; + +public class TextServiceUnitTest { + + @Test + public void givenTextServiceInstance_whenCalledparseText_thenCorrect() { + TextService textService = new TextService(); + assertThat(textService.parseText("Baeldung")).isEqualTo("BAELDUNG"); + } +} From f784c3bb793b6de50323700e771a5e001f3e4850 Mon Sep 17 00:00:00 2001 From: Amitabh Mandal Date: Sun, 25 Nov 2018 15:31:22 +0530 Subject: [PATCH 067/146] BAEL-2168 Java EE 7 Batch Processing (#5645) * jberet batch * Batch Understanding * partition * exception * some more changes --- jee-7/pom.xml | 935 ++++++++++-------- .../ChunkExceptionSkipReadListener.java | 11 + .../batch/understanding/CustomCheckPoint.java | 12 + .../understanding/DeciderJobSequence.java | 14 + .../understanding/InjectSimpleBatchLet.java | 20 + .../batch/understanding/SimpleBatchLet.java | 13 + .../SimpleChunkItemProcessor.java | 12 + .../understanding/SimpleChunkItemReader.java | 27 + .../SimpleChunkItemReaderError.java | 31 + .../understanding/SimpleChunkWriter.java | 13 + .../exception/MyInputRecord.java | 41 + .../exception/MyItemProcessor.java | 15 + .../understanding/exception/MyItemReader.java | 42 + .../understanding/exception/MyItemWriter.java | 19 + .../exception/MyOutputRecord.java | 39 + .../exception/MyRetryProcessorListener.java | 11 + .../exception/MyRetryReadListener.java | 11 + .../exception/MyRetryWriteListener.java | 12 + .../exception/MySkipProcessorListener.java | 11 + .../exception/MySkipReadListener.java | 11 + .../exception/MySkipWriteListener.java | 13 + .../META-INF/batch-jobs/customCheckPoint.xml | 12 + .../META-INF/batch-jobs/decideJobSequence.xml | 18 + .../META-INF/batch-jobs/flowJobSequence.xml | 21 + .../batch-jobs/injectionSimpleBatchLet.xml | 13 + .../batch-jobs/partitionSimpleBatchLet.xml | 24 + .../META-INF/batch-jobs/simpleBatchLet.xml | 9 + .../META-INF/batch-jobs/simpleChunk.xml | 11 + .../META-INF/batch-jobs/simpleErrorChunk.xml | 24 + .../batch-jobs/simpleErrorSkipChunk.xml | 26 + .../META-INF/batch-jobs/simpleJobSequence.xml | 17 + .../META-INF/batch-jobs/splitJobSequence.xml | 22 + jee-7/src/main/resources/META-INF/beans.xml | 8 + .../batch/understanding/BatchTestHelper.java | 79 ++ .../CustomCheckPointUnitTest.java | 33 + .../understanding/JobSequenceUnitTest.java | 74 ++ .../understanding/SimpleBatchLetUnitTest.java | 68 ++ .../understanding/SimpleChunkUnitTest.java | 67 ++ .../SimpleErrorChunkUnitTest.java | 48 + 39 files changed, 1473 insertions(+), 414 deletions(-) create mode 100644 jee-7/src/main/java/com/baeldung/batch/understanding/ChunkExceptionSkipReadListener.java create mode 100644 jee-7/src/main/java/com/baeldung/batch/understanding/CustomCheckPoint.java create mode 100644 jee-7/src/main/java/com/baeldung/batch/understanding/DeciderJobSequence.java create mode 100644 jee-7/src/main/java/com/baeldung/batch/understanding/InjectSimpleBatchLet.java create mode 100644 jee-7/src/main/java/com/baeldung/batch/understanding/SimpleBatchLet.java create mode 100644 jee-7/src/main/java/com/baeldung/batch/understanding/SimpleChunkItemProcessor.java create mode 100644 jee-7/src/main/java/com/baeldung/batch/understanding/SimpleChunkItemReader.java create mode 100644 jee-7/src/main/java/com/baeldung/batch/understanding/SimpleChunkItemReaderError.java create mode 100644 jee-7/src/main/java/com/baeldung/batch/understanding/SimpleChunkWriter.java create mode 100644 jee-7/src/main/java/com/baeldung/batch/understanding/exception/MyInputRecord.java create mode 100644 jee-7/src/main/java/com/baeldung/batch/understanding/exception/MyItemProcessor.java create mode 100644 jee-7/src/main/java/com/baeldung/batch/understanding/exception/MyItemReader.java create mode 100644 jee-7/src/main/java/com/baeldung/batch/understanding/exception/MyItemWriter.java create mode 100644 jee-7/src/main/java/com/baeldung/batch/understanding/exception/MyOutputRecord.java create mode 100644 jee-7/src/main/java/com/baeldung/batch/understanding/exception/MyRetryProcessorListener.java create mode 100644 jee-7/src/main/java/com/baeldung/batch/understanding/exception/MyRetryReadListener.java create mode 100644 jee-7/src/main/java/com/baeldung/batch/understanding/exception/MyRetryWriteListener.java create mode 100644 jee-7/src/main/java/com/baeldung/batch/understanding/exception/MySkipProcessorListener.java create mode 100644 jee-7/src/main/java/com/baeldung/batch/understanding/exception/MySkipReadListener.java create mode 100644 jee-7/src/main/java/com/baeldung/batch/understanding/exception/MySkipWriteListener.java create mode 100644 jee-7/src/main/resources/META-INF/batch-jobs/customCheckPoint.xml create mode 100644 jee-7/src/main/resources/META-INF/batch-jobs/decideJobSequence.xml create mode 100644 jee-7/src/main/resources/META-INF/batch-jobs/flowJobSequence.xml create mode 100644 jee-7/src/main/resources/META-INF/batch-jobs/injectionSimpleBatchLet.xml create mode 100644 jee-7/src/main/resources/META-INF/batch-jobs/partitionSimpleBatchLet.xml create mode 100644 jee-7/src/main/resources/META-INF/batch-jobs/simpleBatchLet.xml create mode 100644 jee-7/src/main/resources/META-INF/batch-jobs/simpleChunk.xml create mode 100644 jee-7/src/main/resources/META-INF/batch-jobs/simpleErrorChunk.xml create mode 100644 jee-7/src/main/resources/META-INF/batch-jobs/simpleErrorSkipChunk.xml create mode 100644 jee-7/src/main/resources/META-INF/batch-jobs/simpleJobSequence.xml create mode 100644 jee-7/src/main/resources/META-INF/batch-jobs/splitJobSequence.xml create mode 100644 jee-7/src/main/resources/META-INF/beans.xml create mode 100644 jee-7/src/test/java/com/baeldung/batch/understanding/BatchTestHelper.java create mode 100644 jee-7/src/test/java/com/baeldung/batch/understanding/CustomCheckPointUnitTest.java create mode 100644 jee-7/src/test/java/com/baeldung/batch/understanding/JobSequenceUnitTest.java create mode 100644 jee-7/src/test/java/com/baeldung/batch/understanding/SimpleBatchLetUnitTest.java create mode 100644 jee-7/src/test/java/com/baeldung/batch/understanding/SimpleChunkUnitTest.java create mode 100644 jee-7/src/test/java/com/baeldung/batch/understanding/SimpleErrorChunkUnitTest.java diff --git a/jee-7/pom.xml b/jee-7/pom.xml index 4f6e6a20fb..9011648d17 100644 --- a/jee-7/pom.xml +++ b/jee-7/pom.xml @@ -1,430 +1,537 @@ - - 4.0.0 - jee-7 - 1.0-SNAPSHOT - war - JavaEE 7 Arquillian Archetype Sample + + 4.0.0 + jee-7 + 1.0-SNAPSHOT + war + JavaEE 7 Arquillian Archetype Sample - - com.baeldung - parent-modules - 1.0.0-SNAPSHOT - + + com.baeldung + parent-modules + 1.0.0-SNAPSHOT + - - - javax - javaee-api - ${javaee_api.version} - provided - + + + javax + javaee-api + ${javaee_api.version} + provided + - - org.jboss.arquillian.junit - arquillian-junit-container - test - - - org.jboss.arquillian.graphene - graphene-webdriver - ${graphene-webdriver.version} - pom - test - - - com.jayway.awaitility - awaitility - ${awaitility.version} - test - + + org.jboss.arquillian.junit + arquillian-junit-container + test + + + org.jboss.arquillian.graphene + graphene-webdriver + ${graphene-webdriver.version} + pom + test + + + com.jayway.awaitility + awaitility + ${awaitility.version} + test + - - org.jboss.shrinkwrap.resolver - shrinkwrap-resolver-impl-maven - test - jar - + + org.jboss.shrinkwrap.resolver + shrinkwrap-resolver-impl-maven + test + jar + - - org.jboss.shrinkwrap.resolver - shrinkwrap-resolver-impl-maven-archive - test - - - org.apache.httpcomponents - httpclient - ${httpclient.version} - - - commons-io - commons-io - ${commons-io.version} - - - com.sun.faces - jsf-api - ${com.sun.faces.jsf.version} - - - com.sun.faces - jsf-impl - ${com.sun.faces.jsf.version} - - - javax.servlet - jstl - ${jstl.version} - - - javax.servlet - javax.servlet-api - ${javax.servlet-api.version} - - - javax.servlet.jsp - jsp-api - ${jsp-api.version} - provided - - - taglibs - standard - ${taglibs.standard.version} - + + org.jboss.shrinkwrap.resolver + shrinkwrap-resolver-impl-maven-archive + test + + + org.apache.httpcomponents + httpclient + ${httpclient.version} + + + commons-io + commons-io + ${commons-io.version} + + + com.sun.faces + jsf-api + ${com.sun.faces.jsf.version} + + + com.sun.faces + jsf-impl + ${com.sun.faces.jsf.version} + + + javax.servlet + jstl + ${jstl.version} + + + javax.servlet + javax.servlet-api + ${javax.servlet-api.version} + + + javax.servlet.jsp + jsp-api + ${jsp-api.version} + provided + + + taglibs + standard + ${taglibs.standard.version} + - - javax.mvc - javax.mvc-api - 20160715 - - - org.glassfish.ozark - ozark - ${ozark.version} - + + javax.mvc + javax.mvc-api + 20160715 + + + org.glassfish.ozark + ozark + ${ozark.version} + - - org.springframework.security - spring-security-web - ${org.springframework.security.version} - + + org.springframework.security + spring-security-web + ${org.springframework.security.version} + - - org.springframework.security - spring-security-config - ${org.springframework.security.version} - - - org.springframework.security - spring-security-taglibs - ${org.springframework.security.version} - - + + org.springframework.security + spring-security-config + ${org.springframework.security.version} + + + org.springframework.security + spring-security-taglibs + ${org.springframework.security.version} + + - - - - org.apache.maven.plugins - maven-war-plugin - ${maven-war-plugin.version} - - src/main/webapp - false - - - - + + org.jboss.spec.javax.batch + jboss-batch-api_1.0_spec + 1.0.0.Final + + + org.jberet + jberet-core + 1.0.2.Final + + + org.jberet + jberet-support + 1.0.2.Final + + + org.jboss.spec.javax.transaction + jboss-transaction-api_1.2_spec + 1.0.0.Final + + + org.jboss.marshalling + jboss-marshalling + 1.4.2.Final + + + org.jboss.weld + weld-core + 2.1.1.Final + + + org.jboss.weld.se + weld-se + 2.1.1.Final + + + org.jberet + jberet-se + 1.0.2.Final + + + com.h2database + h2 + 1.4.178 + + + org.glassfish.jersey.containers + jersey-container-jetty-servlet + 2.22.1 + + - - - - org.jboss.arquillian - arquillian-bom - ${arquillian_core.version} - import - pom - - - org.jboss.arquillian.extension - arquillian-drone-bom - ${arquillian-drone-bom.version} - pom - import - - - + + + + org.apache.maven.plugins + maven-war-plugin + ${maven-war-plugin.version} + + src/main/webapp + false + + + + + + + + org.eclipse.m2e + lifecycle-mapping + 1.0.0 + + + + + + + org.apache.maven.plugins + + + maven-pmd-plugin + + + [3.8,) + + + check + + + + + + + + + + + + + - - - wildfly-managed-arquillian - - true - - - standalone-full.xml - ${project.build.directory}/wildfly-${version.wildfly} - - - - io.undertow - undertow-websockets-jsr - ${undertow-websockets-jsr.version} - test - - - org.jboss.resteasy - resteasy-client - ${resteasy.version} - test - - - org.jboss.resteasy - resteasy-jaxb-provider - ${resteasy.version} - test - - - org.jboss.resteasy - resteasy-json-p-provider - ${resteasy.version} - test - - - org.wildfly - wildfly-arquillian-container-managed - ${wildfly.version} - test - - + + + + org.jboss.arquillian + arquillian-bom + ${arquillian_core.version} + import + pom + + + org.jboss.arquillian.extension + arquillian-drone-bom + ${arquillian-drone-bom.version} + pom + import + + + - - - - - maven-dependency-plugin - ${maven-dependency-plugin.version} - - ${maven.test.skip} - - - - unpack - process-test-classes - - unpack - - - - - org.wildfly - wildfly-dist - ${wildfly.version} - zip - false - ${project.build.directory} - - - - - - - - maven-surefire-plugin - ${maven-surefire-plugin.version} - - - ${project.build.directory}/wildfly-${wildfly.version} - - - - - - - - - wildfly-remote-arquillian - - - io.undertow - undertow-websockets-jsr - ${undertow-websockets-jsr.version} - test - - - org.jboss.resteasy - resteasy-client - ${resteasy.version} - test - - - org.jboss.resteasy - resteasy-jaxb-provider - ${resteasy.version} - test - - - org.jboss.resteasy - resteasy-json-p-provider - ${resteasy.version} - test - - - org.wildfly - wildfly-arquillian-container-remote - ${wildfly.version} - test - - - - - glassfish-embedded-arquillian - - - org.glassfish.main.extras - glassfish-embedded-all - ${glassfish-embedded-all.version} - test - - - org.glassfish - javax.json - ${javax.json.version} - test - - - org.glassfish.tyrus - tyrus-client - ${tyrus.version} - test - - - org.glassfish.tyrus - tyrus-container-grizzly-client - ${tyrus.version} - test - - - org.glassfish.jersey.core - jersey-client - ${jersey.version} - test - - - org.jboss.arquillian.container - arquillian-glassfish-embedded-3.1 - ${arquillian-glassfish.version} - test - - - - - glassfish-remote-arquillian - - - org.glassfish - javax.json - ${javax.json.version} - test - - - org.glassfish.tyrus - tyrus-client - ${tyrus.version} - test - - - org.glassfish.tyrus - tyrus-container-grizzly-client - ${tyrus.version} - test - - - org.glassfish.jersey.core - jersey-client - ${jersey.version} - test - - - org.glassfish.jersey.media - jersey-media-json-jackson - ${jersey.version} - test - - - org.glassfish.jersey.media - jersey-media-json-processing - ${jersey.version} - test - - - org.jboss.arquillian.container - arquillian-glassfish-remote-3.1 - ${arquillian-glassfish.version} - test - - - - - webdriver-chrome - - true - - - chrome - - - - webdriver-firefox - - firefox - - - + + + wildfly-managed-arquillian + + true + + + standalone-full.xml + ${project.build.directory}/wildfly-${version.wildfly} + + + + io.undertow + undertow-websockets-jsr + ${undertow-websockets-jsr.version} + test + + + org.jboss.resteasy + resteasy-client + ${resteasy.version} + test + + + org.jboss.resteasy + resteasy-jaxb-provider + ${resteasy.version} + test + + + org.jboss.resteasy + resteasy-json-p-provider + ${resteasy.version} + test + + + org.wildfly + wildfly-arquillian-container-managed + ${wildfly.version} + test + + + sun.jdk + jconsole + + + + - - - bintray-mvc-spec-maven - bintray - http://dl.bintray.com/mvc-spec/maven - - true - - - false - - - + + + + + maven-dependency-plugin + ${maven-dependency-plugin.version} + + ${maven.test.skip} + + + + unpack + process-test-classes + + unpack + + + + + org.wildfly + wildfly-dist + ${wildfly.version} + zip + false + ${project.build.directory} + + + sun.jdk + jconsole + + + + + + + + + + maven-surefire-plugin + ${maven-surefire-plugin.version} + + + ${project.build.directory}/wildfly-${wildfly.version} + + + + + + + + + wildfly-remote-arquillian + + + io.undertow + undertow-websockets-jsr + ${undertow-websockets-jsr.version} + test + + + org.jboss.resteasy + resteasy-client + ${resteasy.version} + test + + + org.jboss.resteasy + resteasy-jaxb-provider + ${resteasy.version} + test + + + org.jboss.resteasy + resteasy-json-p-provider + ${resteasy.version} + test + + + org.wildfly + wildfly-arquillian-container-remote + ${wildfly.version} + test + + + sun.jdk + jconsole + + + + + + + glassfish-embedded-arquillian + + + org.glassfish.main.extras + glassfish-embedded-all + ${glassfish-embedded-all.version} + test + + + org.glassfish + javax.json + ${javax.json.version} + test + + + org.glassfish.tyrus + tyrus-client + ${tyrus.version} + test + + + org.glassfish.tyrus + tyrus-container-grizzly-client + ${tyrus.version} + test + + + org.glassfish.jersey.core + jersey-client + ${jersey.version} + test + + + org.jboss.arquillian.container + arquillian-glassfish-embedded-3.1 + ${arquillian-glassfish.version} + test + + + + + glassfish-remote-arquillian + + + org.glassfish + javax.json + ${javax.json.version} + test + + + org.glassfish.tyrus + tyrus-client + ${tyrus.version} + test + + + org.glassfish.tyrus + tyrus-container-grizzly-client + ${tyrus.version} + test + + + org.glassfish.jersey.core + jersey-client + ${jersey.version} + test + + + org.glassfish.jersey.media + jersey-media-json-jackson + ${jersey.version} + test + + + org.glassfish.jersey.media + jersey-media-json-processing + ${jersey.version} + test + + + org.jboss.arquillian.container + arquillian-glassfish-remote-3.1 + ${arquillian-glassfish.version} + test + + + + + webdriver-chrome + + true + + + chrome + + + + webdriver-firefox + + firefox + + + - - 1.8 - 3.0.0 - 7.0 - 1.1.11.Final - 8.2.1.Final - 1.7.0 - 1.4.6.Final - 3.0.19.Final - 4.1.1 - 1.0.4 - 1.13 - 2.25 - 1.0.0.Final - 2.6 - 4.2.3.RELEASE - 2.21.0 - 1.1.2 - 2.4 - 2.2.14 - 4.5 - 2.0.1.Final - 3.1.0 - 2.1.0.Final - 2.8 - 1.2 - 2.2 - 20160715 - + + + bintray-mvc-spec-maven + bintray + http://dl.bintray.com/mvc-spec/maven + + true + + + false + + + - + + 1.8 + 3.0.0 + 7.0 + 1.1.11.Final + 8.2.1.Final + 1.7.0 + 1.4.6.Final + 3.0.19.Final + 4.1.1 + 1.0.4 + 1.13 + 2.25 + 1.0.0.Final + 2.6 + 4.2.3.RELEASE + 2.21.0 + 1.1.2 + 2.4 + 2.2.14 + 4.5 + 2.0.1.Final + 3.1.0 + 2.1.0.Final + 2.8 + 1.2 + 2.2 + 20160715 + + + \ No newline at end of file diff --git a/jee-7/src/main/java/com/baeldung/batch/understanding/ChunkExceptionSkipReadListener.java b/jee-7/src/main/java/com/baeldung/batch/understanding/ChunkExceptionSkipReadListener.java new file mode 100644 index 0000000000..ce47de66af --- /dev/null +++ b/jee-7/src/main/java/com/baeldung/batch/understanding/ChunkExceptionSkipReadListener.java @@ -0,0 +1,11 @@ +package com.baeldung.batch.understanding; + +import javax.batch.api.chunk.listener.SkipReadListener; +import javax.inject.Named; + +@Named +public class ChunkExceptionSkipReadListener implements SkipReadListener { + @Override + public void onSkipReadItem(Exception e) throws Exception { + } +} \ No newline at end of file diff --git a/jee-7/src/main/java/com/baeldung/batch/understanding/CustomCheckPoint.java b/jee-7/src/main/java/com/baeldung/batch/understanding/CustomCheckPoint.java new file mode 100644 index 0000000000..fe6759b365 --- /dev/null +++ b/jee-7/src/main/java/com/baeldung/batch/understanding/CustomCheckPoint.java @@ -0,0 +1,12 @@ +package com.baeldung.batch.understanding; + +import javax.batch.api.chunk.AbstractCheckpointAlgorithm; +import javax.inject.Named; + +@Named +public class CustomCheckPoint extends AbstractCheckpointAlgorithm { + @Override + public boolean isReadyToCheckpoint() throws Exception { + return SimpleChunkItemReader.COUNT % 5 == 0; + } +} diff --git a/jee-7/src/main/java/com/baeldung/batch/understanding/DeciderJobSequence.java b/jee-7/src/main/java/com/baeldung/batch/understanding/DeciderJobSequence.java new file mode 100644 index 0000000000..6cc2012f23 --- /dev/null +++ b/jee-7/src/main/java/com/baeldung/batch/understanding/DeciderJobSequence.java @@ -0,0 +1,14 @@ +package com.baeldung.batch.understanding; + +import javax.batch.api.Decider; +import javax.batch.runtime.StepExecution; +import javax.inject.Named; + +@Named +public class DeciderJobSequence implements Decider { + @Override + public String decide(StepExecution[] ses) throws Exception { + return "nothing"; + } + +} \ No newline at end of file diff --git a/jee-7/src/main/java/com/baeldung/batch/understanding/InjectSimpleBatchLet.java b/jee-7/src/main/java/com/baeldung/batch/understanding/InjectSimpleBatchLet.java new file mode 100644 index 0000000000..93eb20708d --- /dev/null +++ b/jee-7/src/main/java/com/baeldung/batch/understanding/InjectSimpleBatchLet.java @@ -0,0 +1,20 @@ +package com.baeldung.batch.understanding; + +import javax.batch.api.AbstractBatchlet; +import javax.batch.api.BatchProperty; +import javax.batch.runtime.BatchStatus; +import javax.inject.Inject; +import javax.inject.Named; + +@Named +public class InjectSimpleBatchLet extends AbstractBatchlet { + @Inject + @BatchProperty(name = "name") + private String nameString; + + @Override + public String process() throws Exception { + System.out.println("Value passed in = " + nameString); + return BatchStatus.COMPLETED.toString(); + } +} diff --git a/jee-7/src/main/java/com/baeldung/batch/understanding/SimpleBatchLet.java b/jee-7/src/main/java/com/baeldung/batch/understanding/SimpleBatchLet.java new file mode 100644 index 0000000000..6a367b064b --- /dev/null +++ b/jee-7/src/main/java/com/baeldung/batch/understanding/SimpleBatchLet.java @@ -0,0 +1,13 @@ +package com.baeldung.batch.understanding; + +import javax.batch.api.AbstractBatchlet; +import javax.batch.runtime.BatchStatus; +import javax.inject.Named; + +@Named +public class SimpleBatchLet extends AbstractBatchlet { + @Override + public String process() throws Exception { + return BatchStatus.FAILED.toString(); + } +} diff --git a/jee-7/src/main/java/com/baeldung/batch/understanding/SimpleChunkItemProcessor.java b/jee-7/src/main/java/com/baeldung/batch/understanding/SimpleChunkItemProcessor.java new file mode 100644 index 0000000000..3f8166b6d8 --- /dev/null +++ b/jee-7/src/main/java/com/baeldung/batch/understanding/SimpleChunkItemProcessor.java @@ -0,0 +1,12 @@ +package com.baeldung.batch.understanding; + +import javax.batch.api.chunk.ItemProcessor; +import javax.inject.Named; + +@Named +public class SimpleChunkItemProcessor implements ItemProcessor { + @Override + public Integer processItem(Object t) { + return ((Integer) t).intValue() % 2 == 0 ? null : ((Integer) t).intValue(); + } +} diff --git a/jee-7/src/main/java/com/baeldung/batch/understanding/SimpleChunkItemReader.java b/jee-7/src/main/java/com/baeldung/batch/understanding/SimpleChunkItemReader.java new file mode 100644 index 0000000000..10f81d95d0 --- /dev/null +++ b/jee-7/src/main/java/com/baeldung/batch/understanding/SimpleChunkItemReader.java @@ -0,0 +1,27 @@ +package com.baeldung.batch.understanding; + +import java.io.Serializable; +import java.util.StringTokenizer; +import javax.batch.api.chunk.AbstractItemReader; +import javax.inject.Named; + +@Named +public class SimpleChunkItemReader extends AbstractItemReader { + private StringTokenizer tokens; + public static int COUNT = 0; + + @Override + public Integer readItem() throws Exception { + if (tokens.hasMoreTokens()) { + COUNT++; + String tempTokenize = tokens.nextToken(); + return Integer.valueOf(tempTokenize); + } + return null; + } + + @Override + public void open(Serializable checkpoint) throws Exception { + tokens = new StringTokenizer("1,2,3,4,5,6,7,8,9,10", ","); + } +} diff --git a/jee-7/src/main/java/com/baeldung/batch/understanding/SimpleChunkItemReaderError.java b/jee-7/src/main/java/com/baeldung/batch/understanding/SimpleChunkItemReaderError.java new file mode 100644 index 0000000000..92096d0571 --- /dev/null +++ b/jee-7/src/main/java/com/baeldung/batch/understanding/SimpleChunkItemReaderError.java @@ -0,0 +1,31 @@ +package com.baeldung.batch.understanding; + +import java.io.Serializable; +import java.util.StringTokenizer; + +import javax.batch.api.chunk.AbstractItemReader; +import javax.inject.Named; + +@Named +public class SimpleChunkItemReaderError extends AbstractItemReader { + private StringTokenizer tokens; + public static int COUNT = 0; + + @Override + public Integer readItem() throws Exception { + if (tokens.hasMoreTokens()) { + COUNT++; + int token = Integer.valueOf(tokens.nextToken()); + if (token == 3) { + throw new RuntimeException("Something happened"); + } + return Integer.valueOf(token); + } + return null; + } + + @Override + public void open(Serializable checkpoint) throws Exception { + tokens = new StringTokenizer("1,2,3,4,5,6,7,8,9,10", ","); + } +} \ No newline at end of file diff --git a/jee-7/src/main/java/com/baeldung/batch/understanding/SimpleChunkWriter.java b/jee-7/src/main/java/com/baeldung/batch/understanding/SimpleChunkWriter.java new file mode 100644 index 0000000000..909596766d --- /dev/null +++ b/jee-7/src/main/java/com/baeldung/batch/understanding/SimpleChunkWriter.java @@ -0,0 +1,13 @@ +package com.baeldung.batch.understanding; + +import java.util.List; + +import javax.batch.api.chunk.AbstractItemWriter; +import javax.inject.Named; + +@Named +public class SimpleChunkWriter extends AbstractItemWriter { + @Override + public void writeItems(List items) throws Exception { + } +} diff --git a/jee-7/src/main/java/com/baeldung/batch/understanding/exception/MyInputRecord.java b/jee-7/src/main/java/com/baeldung/batch/understanding/exception/MyInputRecord.java new file mode 100644 index 0000000000..e813a699c2 --- /dev/null +++ b/jee-7/src/main/java/com/baeldung/batch/understanding/exception/MyInputRecord.java @@ -0,0 +1,41 @@ +package com.baeldung.batch.understanding.exception; + +import java.io.Serializable; + +public class MyInputRecord implements Serializable { + private int id; + + public MyInputRecord(int id) { + this.id = id; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + + MyInputRecord that = (MyInputRecord) o; + + return id == that.id; + } + + @Override + public int hashCode() { + return id; + } + + @Override + public String toString() { + return "MyInputRecord: " + id; + } +} diff --git a/jee-7/src/main/java/com/baeldung/batch/understanding/exception/MyItemProcessor.java b/jee-7/src/main/java/com/baeldung/batch/understanding/exception/MyItemProcessor.java new file mode 100644 index 0000000000..4427a1f548 --- /dev/null +++ b/jee-7/src/main/java/com/baeldung/batch/understanding/exception/MyItemProcessor.java @@ -0,0 +1,15 @@ +package com.baeldung.batch.understanding.exception; + +import javax.batch.api.chunk.ItemProcessor; +import javax.inject.Named; + +@Named +public class MyItemProcessor implements ItemProcessor { + @Override + public Object processItem(Object t) { + if (((MyInputRecord) t).getId() == 6) { + throw new NullPointerException(); + } + return new MyOutputRecord(((MyInputRecord) t).getId()); + } +} diff --git a/jee-7/src/main/java/com/baeldung/batch/understanding/exception/MyItemReader.java b/jee-7/src/main/java/com/baeldung/batch/understanding/exception/MyItemReader.java new file mode 100644 index 0000000000..dd1876ab7d --- /dev/null +++ b/jee-7/src/main/java/com/baeldung/batch/understanding/exception/MyItemReader.java @@ -0,0 +1,42 @@ +package com.baeldung.batch.understanding.exception; + +import javax.batch.api.chunk.AbstractItemReader; +import javax.inject.Named; +import java.io.Serializable; +import java.util.StringTokenizer; + +@Named +public class MyItemReader extends AbstractItemReader { + private StringTokenizer tokens; + private MyInputRecord lastElement; + private boolean alreadyFailed; + + @Override + public void open(Serializable checkpoint) { + tokens = new StringTokenizer("1,2,3,4,5,6,7,8,9,10", ","); + if (checkpoint != null) { + while (!Integer.valueOf(tokens.nextToken()) + .equals(((MyInputRecord) checkpoint).getId())) { + } + } + } + + @Override + public Object readItem() { + if (tokens.hasMoreTokens()) { + int token = Integer.valueOf(tokens.nextToken()); + if (token == 5 && !alreadyFailed) { + alreadyFailed = true; + throw new IllegalArgumentException("Could not read record"); + } + lastElement = new MyInputRecord(token); + return lastElement; + } + return null; + } + + @Override + public Serializable checkpointInfo() throws Exception { + return lastElement; + } +} diff --git a/jee-7/src/main/java/com/baeldung/batch/understanding/exception/MyItemWriter.java b/jee-7/src/main/java/com/baeldung/batch/understanding/exception/MyItemWriter.java new file mode 100644 index 0000000000..4e80d86d44 --- /dev/null +++ b/jee-7/src/main/java/com/baeldung/batch/understanding/exception/MyItemWriter.java @@ -0,0 +1,19 @@ + +package com.baeldung.batch.understanding.exception; + +import javax.batch.api.chunk.AbstractItemWriter; +import javax.inject.Named; +import java.util.List; + +@Named +public class MyItemWriter extends AbstractItemWriter { + private static int retries = 0; + + @Override + public void writeItems(List list) { + if (retries <= 3 && list.contains(new MyOutputRecord(8))) { + retries++; + throw new UnsupportedOperationException(); + } + } +} diff --git a/jee-7/src/main/java/com/baeldung/batch/understanding/exception/MyOutputRecord.java b/jee-7/src/main/java/com/baeldung/batch/understanding/exception/MyOutputRecord.java new file mode 100644 index 0000000000..8f18fca7ba --- /dev/null +++ b/jee-7/src/main/java/com/baeldung/batch/understanding/exception/MyOutputRecord.java @@ -0,0 +1,39 @@ +package com.baeldung.batch.understanding.exception; + +import java.io.Serializable; + +public class MyOutputRecord implements Serializable { + private int id; + + public MyOutputRecord(int id) { + this.id = id; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + MyOutputRecord that = (MyOutputRecord) o; + + return id == that.id; + } + + @Override + public int hashCode() { + return id; + } + + @Override + public String toString() { + return "MyOutputRecord: " + id; + } +} diff --git a/jee-7/src/main/java/com/baeldung/batch/understanding/exception/MyRetryProcessorListener.java b/jee-7/src/main/java/com/baeldung/batch/understanding/exception/MyRetryProcessorListener.java new file mode 100644 index 0000000000..3bd35820c3 --- /dev/null +++ b/jee-7/src/main/java/com/baeldung/batch/understanding/exception/MyRetryProcessorListener.java @@ -0,0 +1,11 @@ +package com.baeldung.batch.understanding.exception; + +import javax.batch.api.chunk.listener.RetryProcessListener; +import javax.inject.Named; + +@Named +public class MyRetryProcessorListener implements RetryProcessListener { + @Override + public void onRetryProcessException(Object item, Exception ex) throws Exception { + } +} diff --git a/jee-7/src/main/java/com/baeldung/batch/understanding/exception/MyRetryReadListener.java b/jee-7/src/main/java/com/baeldung/batch/understanding/exception/MyRetryReadListener.java new file mode 100644 index 0000000000..5c4f56b75d --- /dev/null +++ b/jee-7/src/main/java/com/baeldung/batch/understanding/exception/MyRetryReadListener.java @@ -0,0 +1,11 @@ +package com.baeldung.batch.understanding.exception; + +import javax.batch.api.chunk.listener.RetryReadListener; +import javax.inject.Named; + +@Named +public class MyRetryReadListener implements RetryReadListener { + @Override + public void onRetryReadException(Exception ex) throws Exception { + } +} diff --git a/jee-7/src/main/java/com/baeldung/batch/understanding/exception/MyRetryWriteListener.java b/jee-7/src/main/java/com/baeldung/batch/understanding/exception/MyRetryWriteListener.java new file mode 100644 index 0000000000..a8683d86a9 --- /dev/null +++ b/jee-7/src/main/java/com/baeldung/batch/understanding/exception/MyRetryWriteListener.java @@ -0,0 +1,12 @@ +package com.baeldung.batch.understanding.exception; + +import javax.batch.api.chunk.listener.RetryWriteListener; +import javax.inject.Named; +import java.util.List; + +@Named +public class MyRetryWriteListener implements RetryWriteListener { + @Override + public void onRetryWriteException(List items, Exception ex) throws Exception { + } +} diff --git a/jee-7/src/main/java/com/baeldung/batch/understanding/exception/MySkipProcessorListener.java b/jee-7/src/main/java/com/baeldung/batch/understanding/exception/MySkipProcessorListener.java new file mode 100644 index 0000000000..74f7565cf7 --- /dev/null +++ b/jee-7/src/main/java/com/baeldung/batch/understanding/exception/MySkipProcessorListener.java @@ -0,0 +1,11 @@ +package com.baeldung.batch.understanding.exception; + +import javax.batch.api.chunk.listener.SkipProcessListener; +import javax.inject.Named; + +@Named +public class MySkipProcessorListener implements SkipProcessListener { + @Override + public void onSkipProcessItem(Object t, Exception e) throws Exception { + } +} diff --git a/jee-7/src/main/java/com/baeldung/batch/understanding/exception/MySkipReadListener.java b/jee-7/src/main/java/com/baeldung/batch/understanding/exception/MySkipReadListener.java new file mode 100644 index 0000000000..aecaf93e75 --- /dev/null +++ b/jee-7/src/main/java/com/baeldung/batch/understanding/exception/MySkipReadListener.java @@ -0,0 +1,11 @@ +package com.baeldung.batch.understanding.exception; + +import javax.batch.api.chunk.listener.SkipReadListener; +import javax.inject.Named; + +@Named +public class MySkipReadListener implements SkipReadListener { + @Override + public void onSkipReadItem(Exception e) throws Exception { + } +} diff --git a/jee-7/src/main/java/com/baeldung/batch/understanding/exception/MySkipWriteListener.java b/jee-7/src/main/java/com/baeldung/batch/understanding/exception/MySkipWriteListener.java new file mode 100644 index 0000000000..928773b61d --- /dev/null +++ b/jee-7/src/main/java/com/baeldung/batch/understanding/exception/MySkipWriteListener.java @@ -0,0 +1,13 @@ +package com.baeldung.batch.understanding.exception; + +import javax.batch.api.chunk.listener.SkipWriteListener; +import javax.inject.Named; +import java.util.List; + +@Named +public class MySkipWriteListener implements SkipWriteListener { + @Override + public void onSkipWriteItem(List list, Exception e) throws Exception { + list.remove(new MyOutputRecord(2)); + } +} diff --git a/jee-7/src/main/resources/META-INF/batch-jobs/customCheckPoint.xml b/jee-7/src/main/resources/META-INF/batch-jobs/customCheckPoint.xml new file mode 100644 index 0000000000..b0f327dd39 --- /dev/null +++ b/jee-7/src/main/resources/META-INF/batch-jobs/customCheckPoint.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/jee-7/src/main/resources/META-INF/batch-jobs/decideJobSequence.xml b/jee-7/src/main/resources/META-INF/batch-jobs/decideJobSequence.xml new file mode 100644 index 0000000000..4905586fb9 --- /dev/null +++ b/jee-7/src/main/resources/META-INF/batch-jobs/decideJobSequence.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/jee-7/src/main/resources/META-INF/batch-jobs/flowJobSequence.xml b/jee-7/src/main/resources/META-INF/batch-jobs/flowJobSequence.xml new file mode 100644 index 0000000000..207a9242b1 --- /dev/null +++ b/jee-7/src/main/resources/META-INF/batch-jobs/flowJobSequence.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/jee-7/src/main/resources/META-INF/batch-jobs/injectionSimpleBatchLet.xml b/jee-7/src/main/resources/META-INF/batch-jobs/injectionSimpleBatchLet.xml new file mode 100644 index 0000000000..d152f063f6 --- /dev/null +++ b/jee-7/src/main/resources/META-INF/batch-jobs/injectionSimpleBatchLet.xml @@ -0,0 +1,13 @@ + + + + + + + + + + \ No newline at end of file diff --git a/jee-7/src/main/resources/META-INF/batch-jobs/partitionSimpleBatchLet.xml b/jee-7/src/main/resources/META-INF/batch-jobs/partitionSimpleBatchLet.xml new file mode 100644 index 0000000000..76c64ee899 --- /dev/null +++ b/jee-7/src/main/resources/META-INF/batch-jobs/partitionSimpleBatchLet.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/jee-7/src/main/resources/META-INF/batch-jobs/simpleBatchLet.xml b/jee-7/src/main/resources/META-INF/batch-jobs/simpleBatchLet.xml new file mode 100644 index 0000000000..9c707de8a4 --- /dev/null +++ b/jee-7/src/main/resources/META-INF/batch-jobs/simpleBatchLet.xml @@ -0,0 +1,9 @@ + + + + + + \ No newline at end of file diff --git a/jee-7/src/main/resources/META-INF/batch-jobs/simpleChunk.xml b/jee-7/src/main/resources/META-INF/batch-jobs/simpleChunk.xml new file mode 100644 index 0000000000..b2b15b7bd9 --- /dev/null +++ b/jee-7/src/main/resources/META-INF/batch-jobs/simpleChunk.xml @@ -0,0 +1,11 @@ + + + + + + + + + + \ No newline at end of file diff --git a/jee-7/src/main/resources/META-INF/batch-jobs/simpleErrorChunk.xml b/jee-7/src/main/resources/META-INF/batch-jobs/simpleErrorChunk.xml new file mode 100644 index 0000000000..743fcafd65 --- /dev/null +++ b/jee-7/src/main/resources/META-INF/batch-jobs/simpleErrorChunk.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/jee-7/src/main/resources/META-INF/batch-jobs/simpleErrorSkipChunk.xml b/jee-7/src/main/resources/META-INF/batch-jobs/simpleErrorSkipChunk.xml new file mode 100644 index 0000000000..2fafb83cc7 --- /dev/null +++ b/jee-7/src/main/resources/META-INF/batch-jobs/simpleErrorSkipChunk.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/jee-7/src/main/resources/META-INF/batch-jobs/simpleJobSequence.xml b/jee-7/src/main/resources/META-INF/batch-jobs/simpleJobSequence.xml new file mode 100644 index 0000000000..7110db7f23 --- /dev/null +++ b/jee-7/src/main/resources/META-INF/batch-jobs/simpleJobSequence.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/jee-7/src/main/resources/META-INF/batch-jobs/splitJobSequence.xml b/jee-7/src/main/resources/META-INF/batch-jobs/splitJobSequence.xml new file mode 100644 index 0000000000..0a9ea97dc7 --- /dev/null +++ b/jee-7/src/main/resources/META-INF/batch-jobs/splitJobSequence.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/jee-7/src/main/resources/META-INF/beans.xml b/jee-7/src/main/resources/META-INF/beans.xml new file mode 100644 index 0000000000..ae0f4bf2ee --- /dev/null +++ b/jee-7/src/main/resources/META-INF/beans.xml @@ -0,0 +1,8 @@ + + + \ No newline at end of file diff --git a/jee-7/src/test/java/com/baeldung/batch/understanding/BatchTestHelper.java b/jee-7/src/test/java/com/baeldung/batch/understanding/BatchTestHelper.java new file mode 100644 index 0000000000..5060bd9b91 --- /dev/null +++ b/jee-7/src/test/java/com/baeldung/batch/understanding/BatchTestHelper.java @@ -0,0 +1,79 @@ +package com.baeldung.batch.understanding; + +import java.util.HashMap; +import java.util.Map; + +import javax.batch.runtime.BatchRuntime; +import javax.batch.runtime.BatchStatus; +import javax.batch.runtime.JobExecution; +import javax.batch.runtime.Metric; + +public class BatchTestHelper { + private static final int MAX_TRIES = 40; + private static final int THREAD_SLEEP = 1000; + + private BatchTestHelper() { + throw new UnsupportedOperationException(); + } + + public static JobExecution keepTestAlive(JobExecution jobExecution) throws InterruptedException { + int maxTries = 0; + while (!jobExecution.getBatchStatus() + .equals(BatchStatus.COMPLETED)) { + if (maxTries < MAX_TRIES) { + maxTries++; + Thread.sleep(THREAD_SLEEP); + jobExecution = BatchRuntime.getJobOperator() + .getJobExecution(jobExecution.getExecutionId()); + } else { + break; + } + } + Thread.sleep(THREAD_SLEEP); + return jobExecution; + } + + public static JobExecution keepTestFailed(JobExecution jobExecution) throws InterruptedException { + int maxTries = 0; + while (!jobExecution.getBatchStatus() + .equals(BatchStatus.FAILED)) { + if (maxTries < MAX_TRIES) { + maxTries++; + Thread.sleep(THREAD_SLEEP); + jobExecution = BatchRuntime.getJobOperator() + .getJobExecution(jobExecution.getExecutionId()); + } else { + break; + } + } + Thread.sleep(THREAD_SLEEP); + + return jobExecution; + } + + public static JobExecution keepTestStopped(JobExecution jobExecution) throws InterruptedException { + int maxTries = 0; + while (!jobExecution.getBatchStatus() + .equals(BatchStatus.STOPPED)) { + if (maxTries < MAX_TRIES) { + maxTries++; + Thread.sleep(THREAD_SLEEP); + jobExecution = BatchRuntime.getJobOperator() + .getJobExecution(jobExecution.getExecutionId()); + } else { + break; + } + } + Thread.sleep(THREAD_SLEEP); + return jobExecution; + } + + public static Map getMetricsMap(Metric[] metrics) { + Map metricsMap = new HashMap<>(); + for (Metric metric : metrics) { + metricsMap.put(metric.getType(), metric.getValue()); + } + return metricsMap; + } + +} diff --git a/jee-7/src/test/java/com/baeldung/batch/understanding/CustomCheckPointUnitTest.java b/jee-7/src/test/java/com/baeldung/batch/understanding/CustomCheckPointUnitTest.java new file mode 100644 index 0000000000..a9488c5c03 --- /dev/null +++ b/jee-7/src/test/java/com/baeldung/batch/understanding/CustomCheckPointUnitTest.java @@ -0,0 +1,33 @@ +package com.baeldung.batch.understanding; + +import static org.junit.jupiter.api.Assertions.*; +import java.util.Map; +import java.util.Properties; +import javax.batch.operations.JobOperator; +import javax.batch.runtime.BatchRuntime; +import javax.batch.runtime.BatchStatus; +import javax.batch.runtime.JobExecution; +import javax.batch.runtime.Metric; +import javax.batch.runtime.StepExecution; +import com.baeldung.batch.understanding.BatchTestHelper; + +import org.junit.jupiter.api.Test; + +class CustomCheckPointUnitTest { + @Test + public void givenChunk_whenCustomCheckPoint_thenCommitCount_3() throws Exception { + JobOperator jobOperator = BatchRuntime.getJobOperator(); + Long executionId = jobOperator.start("customCheckPoint", new Properties()); + JobExecution jobExecution = jobOperator.getJobExecution(executionId); + jobExecution = BatchTestHelper.keepTestAlive(jobExecution); + for (StepExecution stepExecution : jobOperator.getStepExecutions(executionId)) { + if (stepExecution.getStepName() + .equals("firstChunkStep")) { + Map metricsMap = BatchTestHelper.getMetricsMap(stepExecution.getMetrics()); + assertEquals(3L, metricsMap.get(Metric.MetricType.COMMIT_COUNT) + .longValue()); + } + } + assertEquals(jobExecution.getBatchStatus(), BatchStatus.COMPLETED); + } +} diff --git a/jee-7/src/test/java/com/baeldung/batch/understanding/JobSequenceUnitTest.java b/jee-7/src/test/java/com/baeldung/batch/understanding/JobSequenceUnitTest.java new file mode 100644 index 0000000000..7c5e8d0b78 --- /dev/null +++ b/jee-7/src/test/java/com/baeldung/batch/understanding/JobSequenceUnitTest.java @@ -0,0 +1,74 @@ +package com.baeldung.batch.understanding; + +import static org.junit.jupiter.api.Assertions.*; + +import java.util.ArrayList; +import java.util.List; +import java.util.Properties; + +import javax.batch.operations.JobOperator; +import javax.batch.runtime.BatchRuntime; +import javax.batch.runtime.BatchStatus; +import javax.batch.runtime.JobExecution; +import javax.batch.runtime.StepExecution; + +import org.junit.jupiter.api.Test; + +class JobSequenceUnitTest { + @Test + public void givenTwoSteps_thenBatch_CompleteWithSuccess() throws Exception { + JobOperator jobOperator = BatchRuntime.getJobOperator(); + Long executionId = jobOperator.start("simpleJobSequence", new Properties()); + JobExecution jobExecution = jobOperator.getJobExecution(executionId); + jobExecution = BatchTestHelper.keepTestAlive(jobExecution); + assertEquals(2 , jobOperator.getStepExecutions(executionId).size()); + assertEquals(jobExecution.getBatchStatus(), BatchStatus.COMPLETED); + } + + @Test + public void givenFlow_thenBatch_CompleteWithSuccess() throws Exception { + JobOperator jobOperator = BatchRuntime.getJobOperator(); + Long executionId = jobOperator.start("flowJobSequence", new Properties()); + JobExecution jobExecution = jobOperator.getJobExecution(executionId); + jobExecution = BatchTestHelper.keepTestAlive(jobExecution); + assertEquals(3 , jobOperator.getStepExecutions(executionId).size()); + assertEquals(jobExecution.getBatchStatus(), BatchStatus.COMPLETED); + } + + @Test + public void givenDecider_thenBatch_CompleteWithSuccess() throws Exception { + JobOperator jobOperator = BatchRuntime.getJobOperator(); + Long executionId = jobOperator.start("decideJobSequence", new Properties()); + JobExecution jobExecution = jobOperator.getJobExecution(executionId); + jobExecution = BatchTestHelper.keepTestAlive(jobExecution); + List stepExecutions = jobOperator.getStepExecutions(executionId); + List executedSteps = new ArrayList<>(); + for (StepExecution stepExecution : stepExecutions) { + executedSteps.add(stepExecution.getStepName()); + } + assertEquals(2, jobOperator.getStepExecutions(executionId).size()); + assertArrayEquals(new String[] { "firstBatchStepStep1", "firstBatchStepStep3" }, executedSteps.toArray()); + assertEquals(jobExecution.getBatchStatus(), BatchStatus.COMPLETED); + } + + @Test + public void givenSplit_thenBatch_CompletesWithSuccess() throws Exception { + JobOperator jobOperator = BatchRuntime.getJobOperator(); + Long executionId = jobOperator.start("splitJobSequence", new Properties()); + JobExecution jobExecution = jobOperator.getJobExecution(executionId); + jobExecution = BatchTestHelper.keepTestAlive(jobExecution); + List stepExecutions = jobOperator.getStepExecutions(executionId); + List executedSteps = new ArrayList<>(); + for (StepExecution stepExecution : stepExecutions) { + executedSteps.add(stepExecution.getStepName()); + } + assertEquals(3, stepExecutions.size()); + assertTrue(executedSteps.contains("splitJobSequenceStep1")); + assertTrue(executedSteps.contains("splitJobSequenceStep2")); + assertTrue(executedSteps.contains("splitJobSequenceStep3")); + assertTrue(executedSteps.get(0).equals("splitJobSequenceStep1") || executedSteps.get(0).equals("splitJobSequenceStep2")); + assertTrue(executedSteps.get(1).equals("splitJobSequenceStep1") || executedSteps.get(1).equals("splitJobSequenceStep2")); + assertTrue(executedSteps.get(2).equals("splitJobSequenceStep3")); + assertEquals(jobExecution.getBatchStatus(), BatchStatus.COMPLETED); + } +} diff --git a/jee-7/src/test/java/com/baeldung/batch/understanding/SimpleBatchLetUnitTest.java b/jee-7/src/test/java/com/baeldung/batch/understanding/SimpleBatchLetUnitTest.java new file mode 100644 index 0000000000..485c997cc6 --- /dev/null +++ b/jee-7/src/test/java/com/baeldung/batch/understanding/SimpleBatchLetUnitTest.java @@ -0,0 +1,68 @@ +package com.baeldung.batch.understanding; + +import static org.junit.jupiter.api.Assertions.*; + +import java.util.List; +import java.util.Map; +import java.util.Properties; + +import javax.batch.operations.JobOperator; +import javax.batch.runtime.BatchRuntime; +import javax.batch.runtime.BatchStatus; +import javax.batch.runtime.JobExecution; +import javax.batch.runtime.Metric; +import javax.batch.runtime.StepExecution; + +import org.junit.jupiter.api.Test; + +class SimpleBatchLetUnitTest { + @Test + public void givenBatchLet_thenBatch_CompleteWithSuccess() throws Exception { + JobOperator jobOperator = BatchRuntime.getJobOperator(); + Long executionId = jobOperator.start("simpleBatchLet", new Properties()); + JobExecution jobExecution = jobOperator.getJobExecution(executionId); + jobExecution = BatchTestHelper.keepTestAlive(jobExecution); + assertEquals(jobExecution.getBatchStatus(), BatchStatus.COMPLETED); + } + + @Test + public void givenBatchLetProperty_thenBatch_CompleteWithSuccess() throws Exception { + JobOperator jobOperator = BatchRuntime.getJobOperator(); + Long executionId = jobOperator.start("injectionSimpleBatchLet", new Properties()); + JobExecution jobExecution = jobOperator.getJobExecution(executionId); + jobExecution = BatchTestHelper.keepTestAlive(jobExecution); + assertEquals(jobExecution.getBatchStatus(), BatchStatus.COMPLETED); + } + + @Test + public void givenBatchLetPartition_thenBatch_CompleteWithSuccess() throws Exception { + JobOperator jobOperator = BatchRuntime.getJobOperator(); + Long executionId = jobOperator.start("partitionSimpleBatchLet", new Properties()); + JobExecution jobExecution = jobOperator.getJobExecution(executionId); + jobExecution = BatchTestHelper.keepTestAlive(jobExecution); + assertEquals(jobExecution.getBatchStatus(), BatchStatus.COMPLETED); + } + + @Test + public void givenBatchLetStarted_whenStopped_thenBatchStopped() throws Exception { + JobOperator jobOperator = BatchRuntime.getJobOperator(); + Long executionId = jobOperator.start("simpleBatchLet", new Properties()); + JobExecution jobExecution = jobOperator.getJobExecution(executionId); + jobOperator.stop(executionId); + jobExecution = BatchTestHelper.keepTestStopped(jobExecution); + assertEquals(jobExecution.getBatchStatus(), BatchStatus.STOPPED); + } + + @Test + public void givenBatchLetStopped_whenRestarted_thenBatchCompletesSuccess() throws Exception { + JobOperator jobOperator = BatchRuntime.getJobOperator(); + Long executionId = jobOperator.start("simpleBatchLet", new Properties()); + JobExecution jobExecution = jobOperator.getJobExecution(executionId); + jobOperator.stop(executionId); + jobExecution = BatchTestHelper.keepTestStopped(jobExecution); + assertEquals(jobExecution.getBatchStatus(), BatchStatus.STOPPED); + executionId = jobOperator.restart(jobExecution.getExecutionId(), new Properties()); + jobExecution = BatchTestHelper.keepTestAlive(jobOperator.getJobExecution(executionId)); + assertEquals(jobExecution.getBatchStatus(), BatchStatus.COMPLETED); + } +} diff --git a/jee-7/src/test/java/com/baeldung/batch/understanding/SimpleChunkUnitTest.java b/jee-7/src/test/java/com/baeldung/batch/understanding/SimpleChunkUnitTest.java new file mode 100644 index 0000000000..57c794ba00 --- /dev/null +++ b/jee-7/src/test/java/com/baeldung/batch/understanding/SimpleChunkUnitTest.java @@ -0,0 +1,67 @@ +package com.baeldung.batch.understanding; + +import static org.junit.jupiter.api.Assertions.*; + +import java.util.List; +import java.util.Map; +import java.util.Properties; + +import javax.batch.operations.JobOperator; +import javax.batch.runtime.BatchRuntime; +import javax.batch.runtime.BatchStatus; +import javax.batch.runtime.JobExecution; +import javax.batch.runtime.Metric; +import javax.batch.runtime.StepExecution; + +import org.junit.jupiter.api.Test; + +class SimpleChunkUnitTest { + @Test + public void givenChunk_thenBatch_CompletesWithSucess() throws Exception { + JobOperator jobOperator = BatchRuntime.getJobOperator(); + Long executionId = jobOperator.start("simpleChunk", new Properties()); + JobExecution jobExecution = jobOperator.getJobExecution(executionId); + jobExecution = BatchTestHelper.keepTestAlive(jobExecution); + List stepExecutions = jobOperator.getStepExecutions(executionId); + for (StepExecution stepExecution : stepExecutions) { + if (stepExecution.getStepName() + .equals("firstChunkStep")) { + Map metricsMap = BatchTestHelper.getMetricsMap(stepExecution.getMetrics()); + assertEquals(10L, metricsMap.get(Metric.MetricType.READ_COUNT) + .longValue()); + assertEquals(10L / 2L, metricsMap.get(Metric.MetricType.WRITE_COUNT) + .longValue()); + assertEquals(10L / 3 + (10L % 3 > 0 ? 1 : 0), metricsMap.get(Metric.MetricType.COMMIT_COUNT) + .longValue()); + } + } + assertEquals(jobExecution.getBatchStatus(), BatchStatus.COMPLETED); + } + + @Test + public void givenChunk__thenBatch_fetchInformation() throws Exception { + JobOperator jobOperator = BatchRuntime.getJobOperator(); + Long executionId = jobOperator.start("simpleChunk", new Properties()); + JobExecution jobExecution = jobOperator.getJobExecution(executionId); + jobExecution = BatchTestHelper.keepTestAlive(jobExecution); + // job name contains simpleBatchLet which is the name of the file + assertTrue(jobOperator.getJobNames().contains("simpleChunk")); + // job parameters are empty + assertTrue(jobOperator.getParameters(executionId).isEmpty()); + // step execution information + List stepExecutions = jobOperator.getStepExecutions(executionId); + assertEquals("firstChunkStep", stepExecutions.get(0).getStepName()); + // finding out batch status + assertEquals(BatchStatus.COMPLETED, stepExecutions.get(0).getBatchStatus()); + Map metricTest = BatchTestHelper.getMetricsMap(stepExecutions.get(0).getMetrics()); + assertEquals(10L, metricTest.get(Metric.MetricType.READ_COUNT).longValue()); + assertEquals(5L, metricTest.get(Metric.MetricType.FILTER_COUNT).longValue()); + assertEquals(4L, metricTest.get(Metric.MetricType.COMMIT_COUNT).longValue()); + assertEquals(5L, metricTest.get(Metric.MetricType.WRITE_COUNT).longValue()); + assertEquals(0L, metricTest.get(Metric.MetricType.READ_SKIP_COUNT).longValue()); + assertEquals(0L, metricTest.get(Metric.MetricType.WRITE_SKIP_COUNT).longValue()); + assertEquals(0L, metricTest.get(Metric.MetricType.PROCESS_SKIP_COUNT).longValue()); + assertEquals(0L, metricTest.get(Metric.MetricType.ROLLBACK_COUNT).longValue()); + assertEquals(jobExecution.getBatchStatus(), BatchStatus.COMPLETED); + } +} diff --git a/jee-7/src/test/java/com/baeldung/batch/understanding/SimpleErrorChunkUnitTest.java b/jee-7/src/test/java/com/baeldung/batch/understanding/SimpleErrorChunkUnitTest.java new file mode 100644 index 0000000000..0f6d068888 --- /dev/null +++ b/jee-7/src/test/java/com/baeldung/batch/understanding/SimpleErrorChunkUnitTest.java @@ -0,0 +1,48 @@ +package com.baeldung.batch.understanding; + +import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.*; + +import java.util.List; +import java.util.Map; +import java.util.Properties; +import javax.batch.operations.JobOperator; +import javax.batch.runtime.BatchRuntime; +import javax.batch.runtime.BatchStatus; +import javax.batch.runtime.JobExecution; +import javax.batch.runtime.Metric.MetricType; +import javax.batch.runtime.StepExecution; + +import org.junit.jupiter.api.Test; + +class SimpleErrorChunkUnitTest { + + @Test + public void givenChunkError_thenBatch_CompletesWithFailed() throws Exception { + JobOperator jobOperator = BatchRuntime.getJobOperator(); + Long executionId = jobOperator.start("simpleErrorChunk", new Properties()); + JobExecution jobExecution = jobOperator.getJobExecution(executionId); + jobExecution = BatchTestHelper.keepTestFailed(jobExecution); + System.out.println(jobExecution.getBatchStatus()); + assertEquals(jobExecution.getBatchStatus(), BatchStatus.FAILED); + } + + @Test + public void givenChunkError_thenErrorSkipped_CompletesWithSuccess() throws Exception { + JobOperator jobOperator = BatchRuntime.getJobOperator(); + Long executionId = jobOperator.start("simpleErrorSkipChunk", new Properties()); + JobExecution jobExecution = jobOperator.getJobExecution(executionId); + jobExecution = BatchTestHelper.keepTestAlive(jobExecution); + List stepExecutions = jobOperator.getStepExecutions(executionId); + for (StepExecution stepExecution : stepExecutions) { + if (stepExecution.getStepName() + .equals("errorStep")) { + Map metricsMap = BatchTestHelper.getMetricsMap(stepExecution.getMetrics()); + long skipCount = metricsMap.get(MetricType.PROCESS_SKIP_COUNT) + .longValue(); + assertTrue("Skip count=" + skipCount, skipCount == 1l || skipCount == 2l); + } + } + assertEquals(jobExecution.getBatchStatus(), BatchStatus.COMPLETED); + } +} From cb840c6224ddc74280447e1e55213ca0e07186e9 Mon Sep 17 00:00:00 2001 From: DOHA Date: Sun, 25 Nov 2018 14:55:27 +0200 Subject: [PATCH 068/146] move customise oauth2 requests --- spring-5-security-oauth/pom.xml | 3 ++- .../baeldung/oauth2/CustomAuthorizationRequestResolver.java | 0 .../java/com/baeldung/oauth2/CustomRequestEntityConverter.java | 0 .../java/com/baeldung/oauth2/CustomTokenResponseConverter.java | 0 4 files changed, 2 insertions(+), 1 deletion(-) rename {spring-5-security => spring-5-security-oauth}/src/main/java/com/baeldung/oauth2/CustomAuthorizationRequestResolver.java (100%) rename {spring-5-security => spring-5-security-oauth}/src/main/java/com/baeldung/oauth2/CustomRequestEntityConverter.java (100%) rename {spring-5-security => spring-5-security-oauth}/src/main/java/com/baeldung/oauth2/CustomTokenResponseConverter.java (100%) diff --git a/spring-5-security-oauth/pom.xml b/spring-5-security-oauth/pom.xml index f200052adf..5814f1dd43 100644 --- a/spring-5-security-oauth/pom.xml +++ b/spring-5-security-oauth/pom.xml @@ -31,7 +31,7 @@ org.thymeleaf.extras - thymeleaf-extras-springsecurity4 + thymeleaf-extras-springsecurity5 @@ -66,6 +66,7 @@ + 2.1.0.RELEASE 2.0.1.RELEASE com.baeldung.oauth2.SpringOAuthApplication diff --git a/spring-5-security/src/main/java/com/baeldung/oauth2/CustomAuthorizationRequestResolver.java b/spring-5-security-oauth/src/main/java/com/baeldung/oauth2/CustomAuthorizationRequestResolver.java similarity index 100% rename from spring-5-security/src/main/java/com/baeldung/oauth2/CustomAuthorizationRequestResolver.java rename to spring-5-security-oauth/src/main/java/com/baeldung/oauth2/CustomAuthorizationRequestResolver.java diff --git a/spring-5-security/src/main/java/com/baeldung/oauth2/CustomRequestEntityConverter.java b/spring-5-security-oauth/src/main/java/com/baeldung/oauth2/CustomRequestEntityConverter.java similarity index 100% rename from spring-5-security/src/main/java/com/baeldung/oauth2/CustomRequestEntityConverter.java rename to spring-5-security-oauth/src/main/java/com/baeldung/oauth2/CustomRequestEntityConverter.java diff --git a/spring-5-security/src/main/java/com/baeldung/oauth2/CustomTokenResponseConverter.java b/spring-5-security-oauth/src/main/java/com/baeldung/oauth2/CustomTokenResponseConverter.java similarity index 100% rename from spring-5-security/src/main/java/com/baeldung/oauth2/CustomTokenResponseConverter.java rename to spring-5-security-oauth/src/main/java/com/baeldung/oauth2/CustomTokenResponseConverter.java From 0b7f01463c2ce5cadee5fb43f3625f78876a0ca5 Mon Sep 17 00:00:00 2001 From: Trevor Gowing Date: Sun, 25 Nov 2018 17:09:32 +0200 Subject: [PATCH 069/146] Fix typo Passenger#fistName BAEL-2208 --- .../main/java/com/baeldung/limit/Passenger.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/limit/Passenger.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/limit/Passenger.java index e7eb3af10b..fb5c35de91 100644 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/limit/Passenger.java +++ b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/limit/Passenger.java @@ -17,7 +17,7 @@ class Passenger { @Basic(optional = false) @Column(nullable = false) - private String fistName; + private String firstName; @Basic(optional = false) @Column(nullable = false) @@ -27,8 +27,8 @@ class Passenger { @Column(nullable = false) private int seatNumber; - private Passenger(String fistName, String lastName, int seatNumber) { - this.fistName = fistName; + private Passenger(String firstName, String lastName, int seatNumber) { + this.firstName = firstName; this.lastName = lastName; this.seatNumber = seatNumber; } @@ -44,20 +44,20 @@ class Passenger { if (object == null || getClass() != object.getClass()) return false; Passenger passenger = (Passenger) object; - return getSeatNumber() == passenger.getSeatNumber() && Objects.equals(getFistName(), passenger.getFistName()) + return getSeatNumber() == passenger.getSeatNumber() && Objects.equals(getFirstName(), passenger.getFirstName()) && Objects.equals(getLastName(), passenger.getLastName()); } @Override public int hashCode() { - return Objects.hash(getFistName(), getLastName(), getSeatNumber()); + return Objects.hash(getFirstName(), getLastName(), getSeatNumber()); } @Override public String toString() { final StringBuilder toStringBuilder = new StringBuilder(getClass().getSimpleName()); toStringBuilder.append("{ id=").append(id); - toStringBuilder.append(", fistName='").append(fistName).append('\''); + toStringBuilder.append(", firstName='").append(firstName).append('\''); toStringBuilder.append(", lastName='").append(lastName).append('\''); toStringBuilder.append(", seatNumber=").append(seatNumber); toStringBuilder.append('}'); @@ -68,8 +68,8 @@ class Passenger { return id; } - String getFistName() { - return fistName; + String getFirstName() { + return firstName; } String getLastName() { From 0c384f13b07351b745ae15b08aeb93ea999ee55b Mon Sep 17 00:00:00 2001 From: Trevor Gowing Date: Sun, 25 Nov 2018 16:13:57 +0200 Subject: [PATCH 070/146] Rename limit package to passenger Rename LimitIntegrationTest to PassengerRepositoryIntegrationTest Going to include code on sorting so it will no longer be limit specific. BAEL-2331 --- .../{limit => passenger}/CustomPassengerRepository.java | 2 +- .../java/com/baeldung/{limit => passenger}/Passenger.java | 2 +- .../baeldung/{limit => passenger}/PassengerRepository.java | 2 +- .../{limit => passenger}/PassengerRepositoryImpl.java | 2 +- .../PassengerRepositoryIntegrationTest.java} | 4 ++-- 5 files changed, 6 insertions(+), 6 deletions(-) rename persistence-modules/spring-data-jpa/src/main/java/com/baeldung/{limit => passenger}/CustomPassengerRepository.java (80%) rename persistence-modules/spring-data-jpa/src/main/java/com/baeldung/{limit => passenger}/Passenger.java (98%) rename persistence-modules/spring-data-jpa/src/main/java/com/baeldung/{limit => passenger}/PassengerRepository.java (86%) rename persistence-modules/spring-data-jpa/src/main/java/com/baeldung/{limit => passenger}/PassengerRepositoryImpl.java (94%) rename persistence-modules/spring-data-jpa/src/test/java/com/baeldung/{limit/LimitIntegrationTest.java => passenger/PassengerRepositoryIntegrationTest.java} (96%) diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/limit/CustomPassengerRepository.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/passenger/CustomPassengerRepository.java similarity index 80% rename from persistence-modules/spring-data-jpa/src/main/java/com/baeldung/limit/CustomPassengerRepository.java rename to persistence-modules/spring-data-jpa/src/main/java/com/baeldung/passenger/CustomPassengerRepository.java index e9b5ba272f..7ae44bfbda 100644 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/limit/CustomPassengerRepository.java +++ b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/passenger/CustomPassengerRepository.java @@ -1,4 +1,4 @@ -package com.baeldung.limit; +package com.baeldung.passenger; import java.util.List; diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/limit/Passenger.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/passenger/Passenger.java similarity index 98% rename from persistence-modules/spring-data-jpa/src/main/java/com/baeldung/limit/Passenger.java rename to persistence-modules/spring-data-jpa/src/main/java/com/baeldung/passenger/Passenger.java index fb5c35de91..24ae47e597 100644 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/limit/Passenger.java +++ b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/passenger/Passenger.java @@ -1,4 +1,4 @@ -package com.baeldung.limit; +package com.baeldung.passenger; import javax.persistence.Basic; import javax.persistence.Column; diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/limit/PassengerRepository.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/passenger/PassengerRepository.java similarity index 86% rename from persistence-modules/spring-data-jpa/src/main/java/com/baeldung/limit/PassengerRepository.java rename to persistence-modules/spring-data-jpa/src/main/java/com/baeldung/passenger/PassengerRepository.java index 6301f6e307..58c782f27a 100644 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/limit/PassengerRepository.java +++ b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/passenger/PassengerRepository.java @@ -1,4 +1,4 @@ -package com.baeldung.limit; +package com.baeldung.passenger; import org.springframework.data.jpa.repository.JpaRepository; diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/limit/PassengerRepositoryImpl.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/passenger/PassengerRepositoryImpl.java similarity index 94% rename from persistence-modules/spring-data-jpa/src/main/java/com/baeldung/limit/PassengerRepositoryImpl.java rename to persistence-modules/spring-data-jpa/src/main/java/com/baeldung/passenger/PassengerRepositoryImpl.java index 2d13eb7cad..bd6e535e3e 100644 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/limit/PassengerRepositoryImpl.java +++ b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/passenger/PassengerRepositoryImpl.java @@ -1,4 +1,4 @@ -package com.baeldung.limit; +package com.baeldung.passenger; import org.springframework.stereotype.Repository; diff --git a/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/limit/LimitIntegrationTest.java b/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/passenger/PassengerRepositoryIntegrationTest.java similarity index 96% rename from persistence-modules/spring-data-jpa/src/test/java/com/baeldung/limit/LimitIntegrationTest.java rename to persistence-modules/spring-data-jpa/src/test/java/com/baeldung/passenger/PassengerRepositoryIntegrationTest.java index 27e0ebdd9f..19366730c5 100644 --- a/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/limit/LimitIntegrationTest.java +++ b/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/passenger/PassengerRepositoryIntegrationTest.java @@ -1,4 +1,4 @@ -package com.baeldung.limit; +package com.baeldung.passenger; import org.junit.Before; import org.junit.Test; @@ -18,7 +18,7 @@ import static org.junit.Assert.assertEquals; @DataJpaTest @RunWith(SpringRunner.class) -public class LimitIntegrationTest { +public class PassengerRepositoryIntegrationTest { @PersistenceContext private EntityManager entityManager; From 322af68ae2093966427c4265440f8994d2416a6d Mon Sep 17 00:00:00 2001 From: Trevor Gowing Date: Sun, 25 Nov 2018 17:11:31 +0200 Subject: [PATCH 071/146] How to sort query results with Spring Data BAEL-2331 --- .../passenger/PassengerRepository.java | 4 +++ .../PassengerRepositoryIntegrationTest.java | 28 +++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/passenger/PassengerRepository.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/passenger/PassengerRepository.java index 58c782f27a..2e4561d91b 100644 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/passenger/PassengerRepository.java +++ b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/passenger/PassengerRepository.java @@ -2,7 +2,11 @@ package com.baeldung.passenger; import org.springframework.data.jpa.repository.JpaRepository; +import java.util.List; + interface PassengerRepository extends JpaRepository, CustomPassengerRepository { Passenger findFirstByOrderBySeatNumberAsc(); + + List findByOrderBySeatNumberAsc(); } diff --git a/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/passenger/PassengerRepositoryIntegrationTest.java b/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/passenger/PassengerRepositoryIntegrationTest.java index 19366730c5..5ca2d21421 100644 --- a/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/passenger/PassengerRepositoryIntegrationTest.java +++ b/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/passenger/PassengerRepositoryIntegrationTest.java @@ -14,6 +14,8 @@ import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; import java.util.List; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.contains; import static org.junit.Assert.assertEquals; @DataJpaTest @@ -66,4 +68,30 @@ public class PassengerRepositoryIntegrationTest { Passenger actual = page.getContent().get(0); assertEquals(expected, actual); } + + @Test + public void givenSeveralPassengersWhenOrderedBySeatNumberAscThenThePassengersReturnedInCorrectOrder() { + Passenger fred = Passenger.from("Fred", "Bloggs", 22); + Passenger ricki = Passenger.from("Ricki", "Bobbie", 36); + Passenger jill = Passenger.from("Jill", "Smith", 50); + Passenger siya = Passenger.from("Siya", "Kolisi", 85); + Passenger eve = Passenger.from("Eve", "Jackson", 95); + + List passengers = repository.findByOrderBySeatNumberAsc(); + + assertThat(passengers, contains(fred, ricki, jill, siya, eve)); + } + + @Test + public void givenSeveralPassengersWhenFindAllWithSortBySeatNumberAscThenReturnPassengersInCorrectOrder() { + Passenger fred = Passenger.from("Fred", "Bloggs", 22); + Passenger ricki = Passenger.from("Ricki", "Bobbie", 36); + Passenger jill = Passenger.from("Jill", "Smith", 50); + Passenger siya = Passenger.from("Siya", "Kolisi", 85); + Passenger eve = Passenger.from("Eve", "Jackson", 95); + + List passengers = repository.findAll(Sort.by(Sort.Direction.ASC, "seatNumber")); + + assertThat(passengers, contains(fred, ricki, jill, siya, eve)); + } } From a2722368af3aaec55d19b603e3d75b52639fb9fd Mon Sep 17 00:00:00 2001 From: Loredana Date: Sun, 25 Nov 2018 20:10:37 +0200 Subject: [PATCH 072/146] add data order methods --- .../java/com/baeldung/passenger/PassengerRepository.java | 5 +++++ .../passenger/PassengerRepositoryIntegrationTest.java | 5 +++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/passenger/PassengerRepository.java b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/passenger/PassengerRepository.java index 2e4561d91b..6ae6afb403 100644 --- a/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/passenger/PassengerRepository.java +++ b/persistence-modules/spring-data-jpa/src/main/java/com/baeldung/passenger/PassengerRepository.java @@ -1,5 +1,6 @@ package com.baeldung.passenger; +import org.springframework.data.domain.Sort; import org.springframework.data.jpa.repository.JpaRepository; import java.util.List; @@ -9,4 +10,8 @@ interface PassengerRepository extends JpaRepository, CustomPass Passenger findFirstByOrderBySeatNumberAsc(); List findByOrderBySeatNumberAsc(); + + List findByLastNameOrderBySeatNumberAsc(String lastName); + + List findByLastName(String lastName, Sort sort); } diff --git a/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/passenger/PassengerRepositoryIntegrationTest.java b/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/passenger/PassengerRepositoryIntegrationTest.java index 5ca2d21421..c57e771345 100644 --- a/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/passenger/PassengerRepositoryIntegrationTest.java +++ b/persistence-modules/spring-data-jpa/src/test/java/com/baeldung/passenger/PassengerRepositoryIntegrationTest.java @@ -70,7 +70,7 @@ public class PassengerRepositoryIntegrationTest { } @Test - public void givenSeveralPassengersWhenOrderedBySeatNumberAscThenThePassengersReturnedInCorrectOrder() { + public void givenPassengers_whenOrderedBySeatNumberAsc_thenCorrectOrder() { Passenger fred = Passenger.from("Fred", "Bloggs", 22); Passenger ricki = Passenger.from("Ricki", "Bobbie", 36); Passenger jill = Passenger.from("Jill", "Smith", 50); @@ -83,7 +83,7 @@ public class PassengerRepositoryIntegrationTest { } @Test - public void givenSeveralPassengersWhenFindAllWithSortBySeatNumberAscThenReturnPassengersInCorrectOrder() { + public void givenPassengers_whenFindAllWithSortBySeatNumberAsc_thenCorrectOrder() { Passenger fred = Passenger.from("Fred", "Bloggs", 22); Passenger ricki = Passenger.from("Ricki", "Bobbie", 36); Passenger jill = Passenger.from("Jill", "Smith", 50); @@ -94,4 +94,5 @@ public class PassengerRepositoryIntegrationTest { assertThat(passengers, contains(fred, ricki, jill, siya, eve)); } + } From 777b9ecc9bbefaf9c8d3bbcbeef50a1a0e6bfbf2 Mon Sep 17 00:00:00 2001 From: DOHA Date: Sun, 25 Nov 2018 22:04:02 +0200 Subject: [PATCH 073/146] minor fix --- spring-5-security-oauth/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-5-security-oauth/pom.xml b/spring-5-security-oauth/pom.xml index 5814f1dd43..59150a153f 100644 --- a/spring-5-security-oauth/pom.xml +++ b/spring-5-security-oauth/pom.xml @@ -67,7 +67,7 @@ 2.1.0.RELEASE - 2.0.1.RELEASE + 2.1.0.RELEASE com.baeldung.oauth2.SpringOAuthApplication From 29c9eb444567c40ed0dd20d1661753dfd258fbd7 Mon Sep 17 00:00:00 2001 From: Emily Cheyne Date: Sun, 25 Nov 2018 16:05:39 -0800 Subject: [PATCH 074/146] BAEL-2330 (#5776) update readme --- java-strings/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/java-strings/README.md b/java-strings/README.md index 2847a0d0a8..222b28e8ad 100644 --- a/java-strings/README.md +++ b/java-strings/README.md @@ -37,3 +37,4 @@ - [Using indexOf to Find All Occurrences of a Word in a String](https://www.baeldung.com/java-indexOf-find-string-occurrences) - [Java Base64 Encoding and Decoding](https://www.baeldung.com/java-base64-encode-and-decode) - [Generate a Secure Random Password in Java](https://www.baeldung.com/java-generate-secure-password) +- [Removing Repeated Characters from a String](https://www.baeldung.com/java-remove-repeated-char) From a1de031c67871e55b54cfbbdb3988a5732709816 Mon Sep 17 00:00:00 2001 From: FrancoCorleone Date: Mon, 26 Nov 2018 04:14:20 +0100 Subject: [PATCH 075/146] Add joining primitives tests (#5740) * Add joining primitives tests * Small refactor * Fix naming for PMD * Add char examples to testing cases * Fix literal separator * CR changes --- .../StringFromPrimitiveArrayUnitTest.java | 129 ++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 java-strings/src/test/java/com/baeldung/string/StringFromPrimitiveArrayUnitTest.java diff --git a/java-strings/src/test/java/com/baeldung/string/StringFromPrimitiveArrayUnitTest.java b/java-strings/src/test/java/com/baeldung/string/StringFromPrimitiveArrayUnitTest.java new file mode 100644 index 0000000000..c93089e543 --- /dev/null +++ b/java-strings/src/test/java/com/baeldung/string/StringFromPrimitiveArrayUnitTest.java @@ -0,0 +1,129 @@ +package com.baeldung.string; + +import com.google.common.base.Joiner; +import com.google.common.primitives.Chars; +import com.google.common.primitives.Ints; +import org.apache.commons.lang3.ArrayUtils; +import org.apache.commons.lang3.StringUtils; +import org.junit.Test; + +import java.nio.CharBuffer; +import java.util.Arrays; +import java.util.StringJoiner; +import java.util.stream.Collectors; + +import static org.assertj.core.api.Assertions.assertThat; + + +public class StringFromPrimitiveArrayUnitTest { + + private int[] intArray = {1, 2, 3, 4, 5, 6, 7, 8, 9}; + + private char[] charArray = {'a', 'b', 'c', 'd', 'e', 'f'}; + + private char separatorChar = '-'; + + private String separator = String.valueOf(separatorChar); + + private String expectedIntString = "1-2-3-4-5-6-7-8-9"; + + private String expectedCharString = "a-b-c-d-e-f"; + + @Test + public void givenIntArray_whenJoinBySeparator_thenReturnsString_through_Java8CollectorsJoining() { + assertThat(Arrays.stream(intArray) + .mapToObj(String::valueOf) + .collect(Collectors.joining(separator))) + .isEqualTo(expectedIntString); + } + + @Test + public void givenCharArray_whenJoinBySeparator_thenReturnsString_through_Java8CollectorsJoining() { + assertThat(CharBuffer.wrap(charArray).chars() + .mapToObj(intChar -> String.valueOf((char) intChar)) + .collect(Collectors.joining(separator))) + .isEqualTo(expectedCharString); + } + + + @Test + public void giveIntArray_whenJoinBySeparator_thenReturnsString_through_Java8StringJoiner() { + StringJoiner intStringJoiner = new StringJoiner(separator); + + Arrays.stream(intArray) + .mapToObj(String::valueOf) + .forEach(intStringJoiner::add); + + assertThat(intStringJoiner.toString()).isEqualTo(expectedIntString); + } + + @Test + public void givenCharArray_whenJoinBySeparator_thenReturnsString_through_Java8StringJoiner() { + StringJoiner charStringJoiner = new StringJoiner(separator); + + CharBuffer.wrap(charArray).chars() + .mapToObj(intChar -> String.valueOf((char) intChar)) + .forEach(charStringJoiner::add); + + assertThat(charStringJoiner.toString()).isEqualTo(expectedCharString); + } + + @Test + public void givenIntArray_whenJoinBySeparator_thenReturnsString_through_CommonsLang() { + assertThat(StringUtils.join(intArray, separatorChar)).isEqualTo(expectedIntString); + assertThat(StringUtils.join(ArrayUtils.toObject(intArray), separator)).isEqualTo(expectedIntString); + } + + @Test + public void givenCharArray_whenJoinBySeparator_thenReturnsString_through_CommonsLang() { + assertThat(StringUtils.join(charArray, separatorChar)).isEqualTo(expectedCharString); + assertThat(StringUtils.join(ArrayUtils.toObject(charArray), separator)).isEqualTo(expectedCharString); + } + + @Test + public void givenIntArray_whenJoinBySeparator_thenReturnsString_through_GuavaJoiner() { + assertThat(Joiner.on(separator).join(Ints.asList(intArray))).isEqualTo(expectedIntString); + } + + @Test + public void givenCharArray_whenJoinBySeparator_thenReturnsString_through_GuavaJoiner() { + assertThat(Joiner.on(separator).join(Chars.asList(charArray))).isEqualTo(expectedCharString); + } + + @Test + public void givenIntArray_whenJoinBySeparator_thenReturnsString_through_Java7StringBuilder() { + assertThat(joinIntArrayWithStringBuilder(intArray, separator)).isEqualTo(expectedIntString); + } + + @Test + public void givenCharArray_whenJoinBySeparator_thenReturnsString_through_Java7StringBuilder() { + assertThat(joinCharArrayWithStringBuilder(charArray, separator)).isEqualTo(expectedCharString); + } + + private String joinIntArrayWithStringBuilder(int[] array, String separator) { + if (array.length == 0) { + return ""; + } + StringBuilder stringBuilder = new StringBuilder(); + for (int i = 0; i < array.length - 1; i++) { + stringBuilder.append(array[i]); + stringBuilder.append(separator); + } + stringBuilder.append(array[array.length - 1]); + return stringBuilder.toString(); + } + + private String joinCharArrayWithStringBuilder(char[] array, String separator) { + if (array.length == 0) { + return ""; + } + StringBuilder stringBuilder = new StringBuilder(); + for (int i = 0; i < array.length - 1; i++) { + stringBuilder.append(array[i]); + stringBuilder.append(separator); + } + stringBuilder.append(array[array.length - 1]); + return stringBuilder.toString(); + } + +} From 7719b2e30a1ed724dc291919fda7dc48b3b53c08 Mon Sep 17 00:00:00 2001 From: Seun Matt Date: Mon, 26 Nov 2018 17:20:11 +0100 Subject: [PATCH 076/146] example code for BAEL-1961 (#5781) * added example code for BAEL-2366 * moved example code for BAEL-2366 * example code for BAEL-1961 * moved example code into integration test * updated the test assertions --- .../com/baeldung/mongodb/Application.java | 8 ++ .../baeldung/mongodb/daos/UserRepository.java | 10 +++ .../mongodb/events/UserModelListener.java | 28 +++++++ .../mongodb/models/DatabaseSequence.java | 32 ++++++++ .../com/baeldung/mongodb/models/User.java | 73 +++++++++++++++++++ .../services/SequenceGeneratorService.java | 35 +++++++++ ...goDbAutoGeneratedFieldIntegrationTest.java | 36 +++++++++ 7 files changed, 222 insertions(+) create mode 100755 spring-boot/src/main/java/com/baeldung/mongodb/daos/UserRepository.java create mode 100644 spring-boot/src/main/java/com/baeldung/mongodb/events/UserModelListener.java create mode 100755 spring-boot/src/main/java/com/baeldung/mongodb/models/DatabaseSequence.java create mode 100755 spring-boot/src/main/java/com/baeldung/mongodb/models/User.java create mode 100755 spring-boot/src/main/java/com/baeldung/mongodb/services/SequenceGeneratorService.java create mode 100644 spring-boot/src/test/java/com/baeldung/mongodb/MongoDbAutoGeneratedFieldIntegrationTest.java diff --git a/spring-boot/src/main/java/com/baeldung/mongodb/Application.java b/spring-boot/src/main/java/com/baeldung/mongodb/Application.java index 092ce3352b..c0a9ad59a7 100644 --- a/spring-boot/src/main/java/com/baeldung/mongodb/Application.java +++ b/spring-boot/src/main/java/com/baeldung/mongodb/Application.java @@ -1,11 +1,19 @@ package com.baeldung.mongodb; +import com.baeldung.mongodb.daos.UserRepository; +import com.baeldung.mongodb.models.User; +import org.springframework.boot.CommandLineRunner; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.Bean; + +import java.util.List; @SpringBootApplication public class Application { + public static void main(String[] args) { SpringApplication.run(Application.class, args); } + } diff --git a/spring-boot/src/main/java/com/baeldung/mongodb/daos/UserRepository.java b/spring-boot/src/main/java/com/baeldung/mongodb/daos/UserRepository.java new file mode 100755 index 0000000000..7f58fdd1c8 --- /dev/null +++ b/spring-boot/src/main/java/com/baeldung/mongodb/daos/UserRepository.java @@ -0,0 +1,10 @@ +package com.baeldung.mongodb.daos; + + +import com.baeldung.mongodb.models.User; +import org.springframework.data.mongodb.repository.MongoRepository; + + +public interface UserRepository extends MongoRepository { + +} diff --git a/spring-boot/src/main/java/com/baeldung/mongodb/events/UserModelListener.java b/spring-boot/src/main/java/com/baeldung/mongodb/events/UserModelListener.java new file mode 100644 index 0000000000..24b53f3d2d --- /dev/null +++ b/spring-boot/src/main/java/com/baeldung/mongodb/events/UserModelListener.java @@ -0,0 +1,28 @@ +package com.baeldung.mongodb.events; + + +import com.baeldung.mongodb.models.User; +import com.baeldung.mongodb.services.SequenceGeneratorService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.mongodb.core.mapping.event.AbstractMongoEventListener; +import org.springframework.data.mongodb.core.mapping.event.BeforeConvertEvent; +import org.springframework.stereotype.Component; + + +@Component +public class UserModelListener extends AbstractMongoEventListener { + + private SequenceGeneratorService sequenceGenerator; + + @Autowired + public UserModelListener(SequenceGeneratorService sequenceGenerator) { + this.sequenceGenerator = sequenceGenerator; + } + + @Override + public void onBeforeConvert(BeforeConvertEvent event) { + event.getSource().setId(sequenceGenerator.generateSequence(User.SEQUENCE_NAME)); + } + + +} diff --git a/spring-boot/src/main/java/com/baeldung/mongodb/models/DatabaseSequence.java b/spring-boot/src/main/java/com/baeldung/mongodb/models/DatabaseSequence.java new file mode 100755 index 0000000000..c2c04f7ee6 --- /dev/null +++ b/spring-boot/src/main/java/com/baeldung/mongodb/models/DatabaseSequence.java @@ -0,0 +1,32 @@ +package com.baeldung.mongodb.models; + +import org.springframework.data.annotation.Id; +import org.springframework.data.mongodb.core.mapping.Document; + + +@Document(collection = "database_sequences") +public class DatabaseSequence { + + @Id + private String id; + + private long seq; + + public DatabaseSequence() {} + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public long getSeq() { + return seq; + } + + public void setSeq(long seq) { + this.seq = seq; + } +} diff --git a/spring-boot/src/main/java/com/baeldung/mongodb/models/User.java b/spring-boot/src/main/java/com/baeldung/mongodb/models/User.java new file mode 100755 index 0000000000..1f08074313 --- /dev/null +++ b/spring-boot/src/main/java/com/baeldung/mongodb/models/User.java @@ -0,0 +1,73 @@ +package com.baeldung.mongodb.models; + +import org.springframework.data.annotation.Id; +import org.springframework.data.annotation.Transient; +import org.springframework.data.mongodb.core.mapping.Document; + + +@Document(collection = "users") +public class User { + + @Transient + public static final String SEQUENCE_NAME = "users_sequence"; + + @Id + private long id; + + private String firstName; + + private String lastName; + + private String email; + + public User() { } + + public User(String firstName, String lastName, String email) { + this.firstName = firstName; + this.lastName = lastName; + this.email = email; + } + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + + @Override + public String toString() { + return "User{" + + "id=" + id + + ", firstName='" + firstName + '\'' + + ", lastName='" + lastName + '\'' + + ", email='" + email + '\'' + + '}'; + } +} diff --git a/spring-boot/src/main/java/com/baeldung/mongodb/services/SequenceGeneratorService.java b/spring-boot/src/main/java/com/baeldung/mongodb/services/SequenceGeneratorService.java new file mode 100755 index 0000000000..52ece27d63 --- /dev/null +++ b/spring-boot/src/main/java/com/baeldung/mongodb/services/SequenceGeneratorService.java @@ -0,0 +1,35 @@ +package com.baeldung.mongodb.services; + +import com.baeldung.mongodb.models.DatabaseSequence; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.mongodb.core.MongoOperations; +import org.springframework.data.mongodb.core.query.Update; +import org.springframework.stereotype.Service; + +import java.util.Objects; + +import static org.springframework.data.mongodb.core.FindAndModifyOptions.options; +import static org.springframework.data.mongodb.core.query.Criteria.where; +import static org.springframework.data.mongodb.core.query.Query.query; + + +@Service +public class SequenceGeneratorService { + + + private MongoOperations mongoOperations; + + @Autowired + public SequenceGeneratorService(MongoOperations mongoOperations) { + this.mongoOperations = mongoOperations; + } + + public long generateSequence(String seqName) { + + DatabaseSequence counter = mongoOperations.findAndModify(query(where("_id").is(seqName)), + new Update().inc("seq",1), options().returnNew(true).upsert(true), + DatabaseSequence.class); + return !Objects.isNull(counter) ? counter.getSeq() : 1; + + } +} diff --git a/spring-boot/src/test/java/com/baeldung/mongodb/MongoDbAutoGeneratedFieldIntegrationTest.java b/spring-boot/src/test/java/com/baeldung/mongodb/MongoDbAutoGeneratedFieldIntegrationTest.java new file mode 100644 index 0000000000..3430bca69a --- /dev/null +++ b/spring-boot/src/test/java/com/baeldung/mongodb/MongoDbAutoGeneratedFieldIntegrationTest.java @@ -0,0 +1,36 @@ +package com.baeldung.mongodb; + +import com.baeldung.mongodb.daos.UserRepository; +import com.baeldung.mongodb.models.User; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.junit4.SpringRunner; +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.List; + + +@RunWith(SpringRunner.class) +public class MongoDbAutoGeneratedFieldIntegrationTest { + + @Autowired + private UserRepository userRepository; + + @Test + public void contextLoads() {} + + @Test + public void givenUserObject_whenSave_thenCreateNewUser() { + + User user = new User(); + user.setFirstName("John"); + user.setLastName("Doe"); + user.setEmail("john.doe@example.com"); + userRepository.save(user); + + assertThat(userRepository.findAll().size()).isGreaterThan(0); + } + + +} From 5ba5b605360e1de095fe29d3bd3b7f32fd382761 Mon Sep 17 00:00:00 2001 From: greg Date: Tue, 27 Nov 2018 02:08:42 +0100 Subject: [PATCH 077/146] BAEL-2368 convert array to string and back (#5689) * BAEL-2368 convert string array to string * BAEL-2368 Convert array to string code * BAEL-2368 Change package * Fix for test --- .../ArrayToStringUnitTest.java | 136 ++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100644 java-collections-conversions/src/test/java/org/baeldung/convertarraytostring/ArrayToStringUnitTest.java diff --git a/java-collections-conversions/src/test/java/org/baeldung/convertarraytostring/ArrayToStringUnitTest.java b/java-collections-conversions/src/test/java/org/baeldung/convertarraytostring/ArrayToStringUnitTest.java new file mode 100644 index 0000000000..b563475997 --- /dev/null +++ b/java-collections-conversions/src/test/java/org/baeldung/convertarraytostring/ArrayToStringUnitTest.java @@ -0,0 +1,136 @@ +package org.baeldung.convertarraytostring; + +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +import org.apache.commons.lang3.StringUtils; +import org.junit.Test; + +import com.google.common.base.Joiner; +import com.google.common.base.Splitter; + +import static org.hamcrest.CoreMatchers.instanceOf; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.Assert.assertEquals; + +public class ArrayToStringUnitTest { + + // convert with Java + + @Test + public void givenAStringArray_whenConvertBeforeJava8_thenReturnString() { + + String[] strArray = { "Convert", "Array", "With", "Java" }; + StringBuilder stringBuilder = new StringBuilder(); + + for (int i = 0; i < strArray.length; i++) { + stringBuilder.append(strArray[i]); + } + String joinedString = stringBuilder.toString(); + + assertThat(joinedString, instanceOf(String.class)); + assertEquals("ConvertArrayWithJava", joinedString); + } + + @Test + public void givenAString_whenConvertBeforeJava8_thenReturnStringArray() { + + String input = "lorem ipsum dolor sit amet"; + String[] strArray = input.split(" "); + + assertThat(strArray, instanceOf(String[].class)); + assertEquals(5, strArray.length); + + input = "loremipsum"; + strArray = input.split(""); + assertThat(strArray, instanceOf(String[].class)); + assertEquals(10, strArray.length); + } + + @Test + public void givenAnIntArray_whenConvertBeforeJava8_thenReturnString() { + + int[] strArray = { 1, 2, 3, 4, 5 }; + StringBuilder stringBuilder = new StringBuilder(); + + for (int i = 0; i < strArray.length; i++) { + stringBuilder.append(Integer.valueOf(strArray[i])); + } + String joinedString = stringBuilder.toString(); + + assertThat(joinedString, instanceOf(String.class)); + assertEquals("12345", joinedString); + } + + // convert with Java Stream API + + @Test + public void givenAStringArray_whenConvertWithJavaStream_thenReturnString() { + + String[] strArray = { "Convert", "With", "Java", "Streams" }; + String joinedString = Arrays.stream(strArray) + .collect(Collectors.joining()); + assertThat(joinedString, instanceOf(String.class)); + assertEquals("ConvertWithJavaStreams", joinedString); + + joinedString = Arrays.stream(strArray) + .collect(Collectors.joining(",")); + assertThat(joinedString, instanceOf(String.class)); + assertEquals("Convert,With,Java,Streams", joinedString); + } + + + // convert with Apache Commons + + @Test + public void givenAStringArray_whenConvertWithApacheCommons_thenReturnString() { + + String[] strArray = { "Convert", "With", "Apache", "Commons" }; + String joinedString = StringUtils.join(strArray); + + assertThat(joinedString, instanceOf(String.class)); + assertEquals("ConvertWithApacheCommons", joinedString); + } + + @Test + public void givenAString_whenConvertWithApacheCommons_thenReturnStringArray() { + + String input = "lorem ipsum dolor sit amet"; + String[] strArray = StringUtils.split(input, " "); + + assertThat(strArray, instanceOf(String[].class)); + assertEquals(5, strArray.length); + } + + + // convert with Guava + + @Test + public void givenAStringArray_whenConvertWithGuava_thenReturnString() { + + String[] strArray = { "Convert", "With", "Guava", null }; + String joinedString = Joiner.on("") + .skipNulls() + .join(strArray); + + assertThat(joinedString, instanceOf(String.class)); + assertEquals("ConvertWithGuava", joinedString); + } + + + @Test + public void givenAString_whenConvertWithGuava_thenReturnStringArray() { + + String input = "lorem ipsum dolor sit amet"; + + List resultList = Splitter.on(' ') + .trimResults() + .omitEmptyStrings() + .splitToList(input); + String[] strArray = resultList.toArray(new String[0]); + + assertThat(strArray, instanceOf(String[].class)); + assertEquals(5, strArray.length); + } +} From 71bca76bf827294905ea98cb6dab1bde1abc029a Mon Sep 17 00:00:00 2001 From: enpy Date: Tue, 27 Nov 2018 16:21:45 +0100 Subject: [PATCH 078/146] BAEL-2809 Get all Data in a table with Hibernate (#5670) * BAEL-2809 Get all Data in a table with Hibernate * Delete transaction.log * Update FindAll.java * Update FindAllTest.java * Update FindAll.java * Update FindAllTest.java * Rename FindAllTest.java to FindAllUnitTest.java --- .../baeldung/hibernate/findall/FindAll.java | 35 +++++++++++ .../hibernate/findall/FindAllUnitTest.java | 63 +++++++++++++++++++ 2 files changed, 98 insertions(+) create mode 100644 persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/findall/FindAll.java create mode 100644 persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/findall/FindAllUnitTest.java diff --git a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/findall/FindAll.java b/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/findall/FindAll.java new file mode 100644 index 0000000000..cc0c234df0 --- /dev/null +++ b/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/findall/FindAll.java @@ -0,0 +1,35 @@ +package com.baeldung.hibernate.findall; + +import java.util.List; + +import javax.persistence.TypedQuery; +import javax.persistence.criteria.CriteriaBuilder; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Root; + +import org.hibernate.Session; + +import com.baeldung.hibernate.pojo.Student; + +public class FindAll { + + private Session session; + + public FindAll(Session session) { + super(); + this.session = session; + } + + public List findAllWithJpql() { + return session.createQuery("SELECT a FROM Student a", Student.class).getResultList(); + } + + public List findAllWithCriteriaQuery() { + CriteriaBuilder cb = session.getCriteriaBuilder(); + CriteriaQuery cq = cb.createQuery(Student.class); + Root rootEntry = cq.from(Student.class); + CriteriaQuery all = cq.select(rootEntry); + TypedQuery allQuery = session.createQuery(all); + return allQuery.getResultList(); + } +} diff --git a/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/findall/FindAllUnitTest.java b/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/findall/FindAllUnitTest.java new file mode 100644 index 0000000000..8a1b9e9791 --- /dev/null +++ b/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/findall/FindAllUnitTest.java @@ -0,0 +1,63 @@ +package com.baeldung.hibernate.findall; + +import static org.junit.Assert.assertEquals; + +import java.io.IOException; +import java.util.List; + +import org.hibernate.Session; +import org.hibernate.Transaction; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.baeldung.hibernate.HibernateUtil; +import com.baeldung.hibernate.pojo.Student; + +public class FindAllUnitTest { + + private Session session; + private Transaction transaction; + + private FindAll findAll; + + @Before + public void setUp() throws IOException { + + session = HibernateUtil.getSessionFactory().openSession(); + transaction = session.beginTransaction(); + findAll = new FindAll(session); + + session.createNativeQuery("delete from Student").executeUpdate(); + + Student student1 = new Student(); + session.persist(student1); + + Student student2 = new Student(); + session.persist(student2); + + Student student3 = new Student(); + session.persist(student3); + + transaction.commit(); + transaction = session.beginTransaction(); + } + + @After + public void tearDown() { + transaction.rollback(); + session.close(); + } + + @Test + public void givenCriteriaQuery_WhenFindAll_ThenGetAllPersons() { + List list = findAll.findAllWithCriteriaQuery(); + assertEquals(3, list.size()); + } + + @Test + public void givenJpql_WhenFindAll_ThenGetAllPersons() { + List list = findAll.findAllWithJpql(); + assertEquals(3, list.size()); + } +} From 7410f52561a0949751cc27e60a5902fc8d0f65d5 Mon Sep 17 00:00:00 2001 From: Kumar Chandrakant Date: Wed, 28 Nov 2018 01:00:16 +0530 Subject: [PATCH 079/146] Changed the source files for incorporating review comments on the tutorial. --- .../main/java/com/baeldung/graph/Graph.java | 116 ++++++------------ .../graph/GraphTraversalUnitTest.java | 30 ++--- 2 files changed, 55 insertions(+), 91 deletions(-) diff --git a/core-java/src/main/java/com/baeldung/graph/Graph.java b/core-java/src/main/java/com/baeldung/graph/Graph.java index 7095f64709..43b5c0aa08 100644 --- a/core-java/src/main/java/com/baeldung/graph/Graph.java +++ b/core-java/src/main/java/com/baeldung/graph/Graph.java @@ -1,67 +1,57 @@ package com.baeldung.graph; +import java.util.ArrayList; import java.util.HashMap; -import java.util.HashSet; +import java.util.List; import java.util.Map; -import java.util.Set; import java.util.stream.Collectors; public class Graph { - private Set vertices; - private Set edges; - private Map> adjVertices; + private Map> adjVertices; Graph() { - this.vertices = new HashSet(); - this.edges = new HashSet(); - this.adjVertices = new HashMap>(); + this.adjVertices = new HashMap>(); } - boolean addVertex(String label) { - return vertices.add(new Vertex(label)); + void addVertex(String label) { + adjVertices.putIfAbsent(new Vertex(label), new ArrayList<>()); } - boolean removeVertex(String label) { - return vertices.remove(new Vertex(label)); - } - - boolean addEdge(String label1, String label2) { - Vertex v1 = new Vertex(label1); - Vertex v2 = new Vertex(label2); - Edge e = new Edge(v1, v2); - if (this.edges.add(e)) { - adjVertices.putIfAbsent(v1, new HashSet<>()); - adjVertices.putIfAbsent(v2, new HashSet<>()); - adjVertices.get(v1) - .add(e); - adjVertices.get(v2) - .add(e); - } - return true; - } - - boolean removeEdge(String label1, String label2) { - Vertex v1 = new Vertex(label1); - Vertex v2 = new Vertex(label2); - Edge e = new Edge(v1, v2); - if (this.edges.remove(e)) { - Set eV1 = adjVertices.get(v1); - Set eV2 = adjVertices.get(v2); - - if (eV1 != null) - eV1.remove(e); - if (eV2 != null) - eV2.remove(e); - } - return true; - } - - Set getAdjVertices(String label) { + void removeVertex(String label) { Vertex v = new Vertex(label); - return adjVertices.get(v) - .stream() - .map(e -> e.v1.equals(v) ? e.v2 : e.v1) - .collect(Collectors.toSet()); + adjVertices.values().stream().map(e -> e.remove(v)).collect(Collectors.toList()); + adjVertices.remove(new Vertex(label)); + } + + void addEdge(String label1, String label2) { + Vertex v1 = new Vertex(label1); + Vertex v2 = new Vertex(label2); + adjVertices.get(v1).add(v2); + adjVertices.get(v2).add(v1); + } + + void removeEdge(String label1, String label2) { + Vertex v1 = new Vertex(label1); + Vertex v2 = new Vertex(label2); + List eV1 = adjVertices.get(v1); + List eV2 = adjVertices.get(v2); + if (eV1 != null) + eV1.remove(v2); + if (eV2 != null) + eV2.remove(v1); + } + + List getAdjVertices(String label) { + return adjVertices.get(new Vertex(label)); + } + + String printGraph() { + StringBuffer sb = new StringBuffer(); + for(Vertex v : adjVertices.keySet()) { + sb.append(v); + sb.append(adjVertices.get(v)); + } + return sb.toString(); } class Vertex { @@ -83,30 +73,4 @@ public class Graph { return label; } } - - class Edge { - Vertex v1; - Vertex v2; - Edge(String label1, String label2) { - this.v1 = new Vertex(label1); - this.v2 = new Vertex(label2); - } - Edge(Vertex vertex1, Vertex vertex2) { - this.v1 = vertex1; - this.v2 = vertex2; - } - @Override - public boolean equals(Object obj) { - Edge edge = (Edge) obj; - return edge.v1.equals(v1) && edge.v2.equals(v2); - } - @Override - public int hashCode() { - return v1.hashCode() + v2.hashCode(); - } - @Override - public String toString() { - return v1.label + "-" + v2.label; - } - } } \ No newline at end of file diff --git a/core-java/src/test/java/com/baeldung/graph/GraphTraversalUnitTest.java b/core-java/src/test/java/com/baeldung/graph/GraphTraversalUnitTest.java index 84611a580a..d955d56d95 100644 --- a/core-java/src/test/java/com/baeldung/graph/GraphTraversalUnitTest.java +++ b/core-java/src/test/java/com/baeldung/graph/GraphTraversalUnitTest.java @@ -7,30 +7,30 @@ public class GraphTraversalUnitTest { @Test public void givenAGraph_whenTraversingDepthFirst_thenExpectedResult() { Graph graph = createGraph(); - Assert.assertEquals("[A, D, E, B, C]", - GraphTraversal.depthFirstTraversal(graph, "A").toString()); + Assert.assertEquals("[Bob, Rob, Maria, Alice, Mark]", + GraphTraversal.depthFirstTraversal(graph, "Bob").toString()); } @Test public void givenAGraph_whenTraversingBreadthFirst_thenExpectedResult() { Graph graph = createGraph(); - Assert.assertEquals("[A, B, D, C, E]", - GraphTraversal.breadthFirstTraversal(graph, "A").toString()); + Assert.assertEquals("[Bob, Alice, Rob, Mark, Maria]", + GraphTraversal.breadthFirstTraversal(graph, "Bob").toString()); } Graph createGraph() { Graph graph = new Graph(); - graph.addVertex("A"); - graph.addVertex("B"); - graph.addVertex("C"); - graph.addVertex("D"); - graph.addVertex("E"); - graph.addEdge("A", "B"); - graph.addEdge("A", "D"); - graph.addEdge("B", "C"); - graph.addEdge("D", "C"); - graph.addEdge("B", "E"); - graph.addEdge("D", "E"); + graph.addVertex("Bob"); + graph.addVertex("Alice"); + graph.addVertex("Mark"); + graph.addVertex("Rob"); + graph.addVertex("Maria"); + graph.addEdge("Bob", "Alice"); + graph.addEdge("Bob", "Rob"); + graph.addEdge("Alice", "Mark"); + graph.addEdge("Rob", "Mark"); + graph.addEdge("Alice", "Maria"); + graph.addEdge("Rob", "Maria"); return graph; } } \ No newline at end of file From 3d2f6eff678ba244de9a9b1150e7c82307614fa4 Mon Sep 17 00:00:00 2001 From: Ger Roza Date: Tue, 27 Nov 2018 17:32:34 -0200 Subject: [PATCH 080/146] [BAEL-2278] spring-5-reactive | debugging reactive streams (#5789) * First approach for the scenario, not stable yet. * Added 2 services for teh article Consumer is the main example project, with all the debugging functionality * * cleaned unused spring-5-data functionality * cleaning unused spring-5-data pom * *fixed indentation error * addressed Jira comments: * Created live test, and renamed unit test as integrtion test * Tried to fix issue in CI, couldnt reproduce locally --- .../consumer/ConsumerSSEApplication.java | 33 +++++ .../consumer/chronjobs/ChronJobs.java | 122 ++++++++++++++++++ .../ReactiveConfigsToggleRestController.java | 23 ++++ .../debugging/consumer/model/Foo.java | 26 ++++ .../debugging/consumer/model/FooDto.java | 12 ++ .../consumer/service/FooNameHelper.java | 45 +++++++ .../consumer/service/FooQuantityHelper.java | 31 +++++ .../consumer/service/FooReporter.java | 26 ++++ .../consumer/service/FooService.java | 91 +++++++++++++ .../server/ServerSSEApplication.java | 29 +++++ .../server/handlers/ServerHandler.java | 47 +++++++ .../baeldung/debugging/server/model/Foo.java | 16 +++ .../server/routers/ServerRouter.java | 22 ++++ .../src/main/resources/application.properties | 3 +- .../ConsumerFooServiceIntegrationTest.java | 65 ++++++++++ .../consumer/ConsumerFooServiceLiveTest.java | 49 +++++++ .../consumer/utils/ListAppender.java | 25 ++++ .../src/test/resources/logback-test.xml | 16 +++ 18 files changed, 679 insertions(+), 2 deletions(-) create mode 100644 spring-5-reactive/src/main/java/com/baeldung/debugging/consumer/ConsumerSSEApplication.java create mode 100644 spring-5-reactive/src/main/java/com/baeldung/debugging/consumer/chronjobs/ChronJobs.java create mode 100644 spring-5-reactive/src/main/java/com/baeldung/debugging/consumer/controllers/ReactiveConfigsToggleRestController.java create mode 100644 spring-5-reactive/src/main/java/com/baeldung/debugging/consumer/model/Foo.java create mode 100644 spring-5-reactive/src/main/java/com/baeldung/debugging/consumer/model/FooDto.java create mode 100644 spring-5-reactive/src/main/java/com/baeldung/debugging/consumer/service/FooNameHelper.java create mode 100644 spring-5-reactive/src/main/java/com/baeldung/debugging/consumer/service/FooQuantityHelper.java create mode 100644 spring-5-reactive/src/main/java/com/baeldung/debugging/consumer/service/FooReporter.java create mode 100644 spring-5-reactive/src/main/java/com/baeldung/debugging/consumer/service/FooService.java create mode 100644 spring-5-reactive/src/main/java/com/baeldung/debugging/server/ServerSSEApplication.java create mode 100644 spring-5-reactive/src/main/java/com/baeldung/debugging/server/handlers/ServerHandler.java create mode 100644 spring-5-reactive/src/main/java/com/baeldung/debugging/server/model/Foo.java create mode 100644 spring-5-reactive/src/main/java/com/baeldung/debugging/server/routers/ServerRouter.java create mode 100644 spring-5-reactive/src/test/java/com/baeldung/debugging/consumer/ConsumerFooServiceIntegrationTest.java create mode 100644 spring-5-reactive/src/test/java/com/baeldung/debugging/consumer/ConsumerFooServiceLiveTest.java create mode 100644 spring-5-reactive/src/test/java/com/baeldung/debugging/consumer/utils/ListAppender.java create mode 100644 spring-5-reactive/src/test/resources/logback-test.xml diff --git a/spring-5-reactive/src/main/java/com/baeldung/debugging/consumer/ConsumerSSEApplication.java b/spring-5-reactive/src/main/java/com/baeldung/debugging/consumer/ConsumerSSEApplication.java new file mode 100644 index 0000000000..55db3d7392 --- /dev/null +++ b/spring-5-reactive/src/main/java/com/baeldung/debugging/consumer/ConsumerSSEApplication.java @@ -0,0 +1,33 @@ +package com.baeldung.debugging.consumer; + +import java.util.Collections; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.mongo.MongoReactiveAutoConfiguration; +import org.springframework.context.annotation.Bean; +import org.springframework.scheduling.annotation.EnableScheduling; +import org.springframework.security.config.web.server.ServerHttpSecurity; +import org.springframework.security.web.server.SecurityWebFilterChain; + +import reactor.core.publisher.Hooks; + +@SpringBootApplication(exclude = MongoReactiveAutoConfiguration.class) +@EnableScheduling +public class ConsumerSSEApplication { + + public static void main(String[] args) { + Hooks.onOperatorDebug(); + SpringApplication app = new SpringApplication(ConsumerSSEApplication.class); + app.setDefaultProperties(Collections.singletonMap("server.port", "8082")); + app.run(args); + } + + @Bean + public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) { + http.authorizeExchange() + .anyExchange() + .permitAll(); + return http.build(); + } +} diff --git a/spring-5-reactive/src/main/java/com/baeldung/debugging/consumer/chronjobs/ChronJobs.java b/spring-5-reactive/src/main/java/com/baeldung/debugging/consumer/chronjobs/ChronJobs.java new file mode 100644 index 0000000000..09cbc34a6f --- /dev/null +++ b/spring-5-reactive/src/main/java/com/baeldung/debugging/consumer/chronjobs/ChronJobs.java @@ -0,0 +1,122 @@ +package com.baeldung.debugging.consumer.chronjobs; + +import java.time.Duration; +import java.util.concurrent.ThreadLocalRandom; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.MediaType; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; +import org.springframework.web.reactive.function.client.WebClient; + +import com.baeldung.debugging.consumer.model.Foo; +import com.baeldung.debugging.consumer.model.FooDto; +import com.baeldung.debugging.consumer.service.FooService; + +import reactor.core.publisher.Flux; + +@Component +public class ChronJobs { + + private static Logger logger = LoggerFactory.getLogger(ChronJobs.class); + private WebClient client = WebClient.create("http://localhost:8081"); + + @Autowired + private FooService service; + + @Scheduled(fixedRate = 10000) + public void consumeInfiniteFlux() { + Flux fluxFoo = client.get() + .uri("/functional-reactive/periodic-foo") + .accept(MediaType.TEXT_EVENT_STREAM) + .retrieve() + .bodyToFlux(FooDto.class) + .delayElements(Duration.ofMillis(100)) + .map(dto -> { + logger.debug("process 1 with dto id {} name{}", dto.getId(), dto.getName()); + return new Foo(dto); + }); + Integer random = ThreadLocalRandom.current() + .nextInt(0, 3); + switch (random) { + case 0: + logger.info("process 1 with approach 1"); + service.processFoo(fluxFoo); + break; + case 1: + logger.info("process 1 with approach 1 EH"); + service.processUsingApproachOneWithErrorHandling(fluxFoo); + break; + default: + logger.info("process 1 with approach 2"); + service.processFooInAnotherScenario(fluxFoo); + break; + + } + } + + @Scheduled(fixedRate = 20000) + public void consumeFiniteFlux2() { + Flux fluxFoo = client.get() + .uri("/functional-reactive/periodic-foo-2") + .accept(MediaType.TEXT_EVENT_STREAM) + .retrieve() + .bodyToFlux(FooDto.class) + .delayElements(Duration.ofMillis(100)) + .map(dto -> { + logger.debug("process 2 with dto id {} name{}", dto.getId(), dto.getName()); + return new Foo(dto); + }); + Integer random = ThreadLocalRandom.current() + .nextInt(0, 3); + switch (random) { + case 0: + logger.info("process 2 with approach 1"); + service.processFoo(fluxFoo); + break; + case 1: + logger.info("process 2 with approach 1 EH"); + service.processUsingApproachOneWithErrorHandling(fluxFoo); + break; + default: + logger.info("process 2 with approach 2"); + service.processFooInAnotherScenario(fluxFoo); + break; + + } + } + + @Scheduled(fixedRate = 20000) + public void consumeFiniteFlux3() { + Flux fluxFoo = client.get() + .uri("/functional-reactive/periodic-foo-2") + .accept(MediaType.TEXT_EVENT_STREAM) + .retrieve() + .bodyToFlux(FooDto.class) + .delayElements(Duration.ofMillis(100)) + .map(dto -> { + logger.debug("process 3 with dto id {} name{}", dto.getId(), dto.getName()); + return new Foo(dto); + }); + logger.info("process 3 with approach 3"); + service.processUsingApproachThree(fluxFoo); + } + + @Scheduled(fixedRate = 20000) + public void consumeFiniteFluxWithCheckpoint4() { + Flux fluxFoo = client.get() + .uri("/functional-reactive/periodic-foo-2") + .accept(MediaType.TEXT_EVENT_STREAM) + .retrieve() + .bodyToFlux(FooDto.class) + .delayElements(Duration.ofMillis(100)) + .map(dto -> { + logger.debug("process 4 with dto id {} name{}", dto.getId(), dto.getName()); + return new Foo(dto); + }); + logger.info("process 4 with approach 4"); + service.processUsingApproachFourWithCheckpoint(fluxFoo); + } +} diff --git a/spring-5-reactive/src/main/java/com/baeldung/debugging/consumer/controllers/ReactiveConfigsToggleRestController.java b/spring-5-reactive/src/main/java/com/baeldung/debugging/consumer/controllers/ReactiveConfigsToggleRestController.java new file mode 100644 index 0000000000..3dcdc6c7c0 --- /dev/null +++ b/spring-5-reactive/src/main/java/com/baeldung/debugging/consumer/controllers/ReactiveConfigsToggleRestController.java @@ -0,0 +1,23 @@ +package com.baeldung.debugging.consumer.controllers; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +import reactor.core.publisher.Hooks; + +@RestController +public class ReactiveConfigsToggleRestController { + + @GetMapping("/debug-hook-on") + public String setReactiveDebugOn() { + Hooks.onOperatorDebug(); + return "DEBUG HOOK ON"; + } + + @GetMapping("/debug-hook-off") + public String setReactiveDebugOff() { + Hooks.resetOnOperatorDebug(); + return "DEBUG HOOK OFF"; + } + +} diff --git a/spring-5-reactive/src/main/java/com/baeldung/debugging/consumer/model/Foo.java b/spring-5-reactive/src/main/java/com/baeldung/debugging/consumer/model/Foo.java new file mode 100644 index 0000000000..e101457b84 --- /dev/null +++ b/spring-5-reactive/src/main/java/com/baeldung/debugging/consumer/model/Foo.java @@ -0,0 +1,26 @@ +package com.baeldung.debugging.consumer.model; + +import java.util.concurrent.ThreadLocalRandom; + +import org.springframework.data.annotation.Id; + +import lombok.AllArgsConstructor; +import lombok.Data; + +@Data +@AllArgsConstructor +public class Foo { + + @Id + private Integer id; + private String formattedName; + private Integer quantity; + + public Foo(FooDto dto) { + this.id = (ThreadLocalRandom.current() + .nextInt(0, 100) == 0) ? null : dto.getId(); + this.formattedName = dto.getName(); + this.quantity = ThreadLocalRandom.current() + .nextInt(0, 10); + } +} diff --git a/spring-5-reactive/src/main/java/com/baeldung/debugging/consumer/model/FooDto.java b/spring-5-reactive/src/main/java/com/baeldung/debugging/consumer/model/FooDto.java new file mode 100644 index 0000000000..50508fd216 --- /dev/null +++ b/spring-5-reactive/src/main/java/com/baeldung/debugging/consumer/model/FooDto.java @@ -0,0 +1,12 @@ +package com.baeldung.debugging.consumer.model; + +import lombok.AllArgsConstructor; +import lombok.Data; + +@Data +@AllArgsConstructor +public class FooDto { + + private Integer id; + private String name; +} diff --git a/spring-5-reactive/src/main/java/com/baeldung/debugging/consumer/service/FooNameHelper.java b/spring-5-reactive/src/main/java/com/baeldung/debugging/consumer/service/FooNameHelper.java new file mode 100644 index 0000000000..772b360437 --- /dev/null +++ b/spring-5-reactive/src/main/java/com/baeldung/debugging/consumer/service/FooNameHelper.java @@ -0,0 +1,45 @@ +package com.baeldung.debugging.consumer.service; + +import java.util.concurrent.ThreadLocalRandom; + +import com.baeldung.debugging.consumer.model.Foo; + +import reactor.core.publisher.Flux; + +public class FooNameHelper { + + public static Flux concatAndSubstringFooName(Flux flux) { + flux = concatFooName(flux); + flux = substringFooName(flux); + return flux; + } + + public static Flux concatFooName(Flux flux) { + flux = flux.map(foo -> { + String processedName = null; + Integer random = ThreadLocalRandom.current() + .nextInt(0, 80); + processedName = (random != 0) ? foo.getFormattedName() : foo.getFormattedName() + "-bael"; + foo.setFormattedName(processedName); + return foo; + }); + return flux; + } + + public static Flux substringFooName(Flux flux) { + return flux.map(foo -> { + String processedName; + Integer random = ThreadLocalRandom.current() + .nextInt(0, 100); + + processedName = (random == 0) ? foo.getFormattedName() + .substring(10, 15) + : foo.getFormattedName() + .substring(0, 5); + + foo.setFormattedName(processedName); + return foo; + }); + } + +} diff --git a/spring-5-reactive/src/main/java/com/baeldung/debugging/consumer/service/FooQuantityHelper.java b/spring-5-reactive/src/main/java/com/baeldung/debugging/consumer/service/FooQuantityHelper.java new file mode 100644 index 0000000000..615239313d --- /dev/null +++ b/spring-5-reactive/src/main/java/com/baeldung/debugging/consumer/service/FooQuantityHelper.java @@ -0,0 +1,31 @@ +package com.baeldung.debugging.consumer.service; + +import java.util.concurrent.ThreadLocalRandom; + +import com.baeldung.debugging.consumer.model.Foo; + +import reactor.core.publisher.Flux; + +public class FooQuantityHelper { + + public static Flux processFooReducingQuantity(Flux flux) { + flux = flux.map(foo -> { + Integer result; + Integer random = ThreadLocalRandom.current() + .nextInt(0, 90); + result = (random == 0) ? result = 0 : foo.getQuantity() + 2; + foo.setQuantity(result); + return foo; + }); + return divideFooQuantity(flux); + } + + public static Flux divideFooQuantity(Flux flux) { + return flux.map(foo -> { + Integer result = Math.round(5 / foo.getQuantity()); + foo.setQuantity(result); + return foo; + }); + } + +} diff --git a/spring-5-reactive/src/main/java/com/baeldung/debugging/consumer/service/FooReporter.java b/spring-5-reactive/src/main/java/com/baeldung/debugging/consumer/service/FooReporter.java new file mode 100644 index 0000000000..f53cd238e0 --- /dev/null +++ b/spring-5-reactive/src/main/java/com/baeldung/debugging/consumer/service/FooReporter.java @@ -0,0 +1,26 @@ +package com.baeldung.debugging.consumer.service; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.baeldung.debugging.consumer.model.Foo; + +import reactor.core.publisher.Flux; + +public class FooReporter { + + private static Logger logger = LoggerFactory.getLogger(FooReporter.class); + + public static Flux reportResult(Flux input, String approach) { + return input.map(foo -> { + if (foo.getId() == null) + throw new IllegalArgumentException("Null id is not valid!"); + logger.info("Reporting for approach {}: Foo with id '{}' name '{}' and quantity '{}'", approach, foo.getId(), foo.getFormattedName(), foo.getQuantity()); + return foo; + }); + } + + public static Flux reportResult(Flux input) { + return reportResult(input, "default"); + } +} diff --git a/spring-5-reactive/src/main/java/com/baeldung/debugging/consumer/service/FooService.java b/spring-5-reactive/src/main/java/com/baeldung/debugging/consumer/service/FooService.java new file mode 100644 index 0000000000..937e445ef5 --- /dev/null +++ b/spring-5-reactive/src/main/java/com/baeldung/debugging/consumer/service/FooService.java @@ -0,0 +1,91 @@ +package com.baeldung.debugging.consumer.service; + +import static com.baeldung.debugging.consumer.service.FooNameHelper.concatAndSubstringFooName; +import static com.baeldung.debugging.consumer.service.FooNameHelper.substringFooName; +import static com.baeldung.debugging.consumer.service.FooQuantityHelper.divideFooQuantity; +import static com.baeldung.debugging.consumer.service.FooQuantityHelper.processFooReducingQuantity; +import static com.baeldung.debugging.consumer.service.FooReporter.reportResult; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; + +import com.baeldung.debugging.consumer.model.Foo; + +import reactor.core.publisher.Flux; + +@Component +public class FooService { + + private static Logger logger = LoggerFactory.getLogger(FooService.class); + + public void processFoo(Flux flux) { + flux = FooNameHelper.concatFooName(flux); + flux = FooNameHelper.substringFooName(flux); + flux = flux.log(); + flux = FooReporter.reportResult(flux); + flux = flux.doOnError(error -> { + logger.error("The following error happened on processFoo method!", error); + }); + flux.subscribe(); + } + + public void processFooInAnotherScenario(Flux flux) { + flux = FooNameHelper.substringFooName(flux); + flux = FooQuantityHelper.divideFooQuantity(flux); + flux.subscribe(); + } + + public void processUsingApproachOneWithErrorHandling(Flux flux) { + logger.info("starting approach one w error handling!"); + flux = concatAndSubstringFooName(flux); + flux = concatAndSubstringFooName(flux); + flux = substringFooName(flux); + flux = processFooReducingQuantity(flux); + flux = processFooReducingQuantity(flux); + flux = processFooReducingQuantity(flux); + flux = reportResult(flux, "ONE w/ EH"); + flux = flux.doOnError(error -> { + logger.error("Approach 1 with Error Handling failed!", error); + }); + flux.subscribe(); + } + + public void processUsingApproachThree(Flux flux) { + logger.info("starting approach three!"); + flux = concatAndSubstringFooName(flux); + flux = reportResult(flux, "THREE"); + flux = flux.doOnError(error -> { + logger.error("Approach 3 failed!", error); + }); + flux.subscribe(); + } + + public void processUsingApproachFourWithCheckpoint(Flux flux) { + logger.info("starting approach four!"); + flux = concatAndSubstringFooName(flux); + flux = flux.checkpoint("CHECKPOINT 1"); + flux = concatAndSubstringFooName(flux); + flux = divideFooQuantity(flux); + flux = flux.checkpoint("CHECKPOINT 2", true); + flux = reportResult(flux, "FOUR"); + flux = concatAndSubstringFooName(flux).doOnError(error -> { + logger.error("Approach 4 failed!", error); + }); + flux.subscribe(); + } + + public void processUsingApproachFourWithInitialCheckpoint(Flux flux) { + logger.info("starting approach four!"); + flux = concatAndSubstringFooName(flux); + flux = flux.checkpoint("CHECKPOINT 1", true); + flux = concatAndSubstringFooName(flux); + flux = divideFooQuantity(flux); + flux = reportResult(flux, "FOUR"); + flux = flux.doOnError(error -> { + logger.error("Approach 4-2 failed!", error); + }); + flux.subscribe(); + } + +} diff --git a/spring-5-reactive/src/main/java/com/baeldung/debugging/server/ServerSSEApplication.java b/spring-5-reactive/src/main/java/com/baeldung/debugging/server/ServerSSEApplication.java new file mode 100644 index 0000000000..6b24ee39f0 --- /dev/null +++ b/spring-5-reactive/src/main/java/com/baeldung/debugging/server/ServerSSEApplication.java @@ -0,0 +1,29 @@ +package com.baeldung.debugging.server; + +import java.util.Collections; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.Bean; +import org.springframework.security.config.web.server.ServerHttpSecurity; +import org.springframework.security.web.server.SecurityWebFilterChain; +import org.springframework.web.reactive.config.EnableWebFlux; + +@EnableWebFlux +@SpringBootApplication +public class ServerSSEApplication { + + public static void main(String[] args) { + SpringApplication app = new SpringApplication(ServerSSEApplication.class); + app.setDefaultProperties(Collections.singletonMap("server.port", "8081")); + app.run(args); + } + + @Bean + public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) { + http.authorizeExchange() + .anyExchange() + .permitAll(); + return http.build(); + } +} diff --git a/spring-5-reactive/src/main/java/com/baeldung/debugging/server/handlers/ServerHandler.java b/spring-5-reactive/src/main/java/com/baeldung/debugging/server/handlers/ServerHandler.java new file mode 100644 index 0000000000..759cd9b01d --- /dev/null +++ b/spring-5-reactive/src/main/java/com/baeldung/debugging/server/handlers/ServerHandler.java @@ -0,0 +1,47 @@ +package com.baeldung.debugging.server.handlers; + +import java.time.Duration; +import java.util.concurrent.ThreadLocalRandom; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.http.MediaType; +import org.springframework.stereotype.Component; +import org.springframework.web.reactive.function.server.ServerRequest; +import org.springframework.web.reactive.function.server.ServerResponse; + +import com.baeldung.debugging.server.model.Foo; + +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; + +@Component +public class ServerHandler { + + private static Logger logger = LoggerFactory.getLogger(ServerHandler.class); + + public Mono useHandler(final ServerRequest request) { + // there are chances that something goes wrong here... + return ServerResponse.ok() + .contentType(MediaType.TEXT_EVENT_STREAM) + .body(Flux.interval(Duration.ofSeconds(1)) + .map(sequence -> { + logger.info("retrieving Foo. Sequence: {}", sequence); + if (ThreadLocalRandom.current() + .nextInt(0, 50) == 1) { + throw new RuntimeException("There was an error retrieving the Foo!"); + } + return new Foo(sequence, "name" + sequence); + + }), Foo.class); + } + + public Mono useHandlerFinite(final ServerRequest request) { + return ServerResponse.ok() + .contentType(MediaType.TEXT_EVENT_STREAM) + .body(Flux.range(0, 50) + .map(sequence -> { + return new Foo(new Long(sequence), "theFooNameNumber" + sequence); + }), Foo.class); + } +} diff --git a/spring-5-reactive/src/main/java/com/baeldung/debugging/server/model/Foo.java b/spring-5-reactive/src/main/java/com/baeldung/debugging/server/model/Foo.java new file mode 100644 index 0000000000..a60e468e7f --- /dev/null +++ b/spring-5-reactive/src/main/java/com/baeldung/debugging/server/model/Foo.java @@ -0,0 +1,16 @@ +package com.baeldung.debugging.server.model; + +import org.springframework.data.annotation.Id; + +import lombok.AllArgsConstructor; +import lombok.Data; + +@Data +@AllArgsConstructor +public class Foo { + + @Id + private Long id; + private String name; + +} diff --git a/spring-5-reactive/src/main/java/com/baeldung/debugging/server/routers/ServerRouter.java b/spring-5-reactive/src/main/java/com/baeldung/debugging/server/routers/ServerRouter.java new file mode 100644 index 0000000000..6378b2213d --- /dev/null +++ b/spring-5-reactive/src/main/java/com/baeldung/debugging/server/routers/ServerRouter.java @@ -0,0 +1,22 @@ +package com.baeldung.debugging.server.routers; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.reactive.function.server.RequestPredicates; +import org.springframework.web.reactive.function.server.RouterFunction; +import org.springframework.web.reactive.function.server.RouterFunctions; +import org.springframework.web.reactive.function.server.ServerResponse; + +import com.baeldung.debugging.server.handlers.ServerHandler; + +@Configuration +public class ServerRouter { + + @Bean + public RouterFunction responseRoute(@Autowired ServerHandler handler) { + return RouterFunctions.route(RequestPredicates.GET("/functional-reactive/periodic-foo"), handler::useHandler) + .andRoute(RequestPredicates.GET("/functional-reactive/periodic-foo-2"), handler::useHandlerFinite); + } + +} diff --git a/spring-5-reactive/src/main/resources/application.properties b/spring-5-reactive/src/main/resources/application.properties index 92f3116f84..4b49e8e8a2 100644 --- a/spring-5-reactive/src/main/resources/application.properties +++ b/spring-5-reactive/src/main/resources/application.properties @@ -1,2 +1 @@ -logging.level.root=INFO - +logging.level.root=INFO \ No newline at end of file diff --git a/spring-5-reactive/src/test/java/com/baeldung/debugging/consumer/ConsumerFooServiceIntegrationTest.java b/spring-5-reactive/src/test/java/com/baeldung/debugging/consumer/ConsumerFooServiceIntegrationTest.java new file mode 100644 index 0000000000..b7ed031ec7 --- /dev/null +++ b/spring-5-reactive/src/test/java/com/baeldung/debugging/consumer/ConsumerFooServiceIntegrationTest.java @@ -0,0 +1,65 @@ +package com.baeldung.debugging.consumer; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.Arrays; +import java.util.Collection; +import java.util.Optional; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import com.baeldung.debugging.consumer.model.Foo; +import com.baeldung.debugging.consumer.service.FooService; +import com.baeldung.debugging.consumer.utils.ListAppender; + +import ch.qos.logback.classic.spi.ILoggingEvent; +import ch.qos.logback.classic.spi.IThrowableProxy; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Hooks; + +public class ConsumerFooServiceIntegrationTest { + + FooService service = new FooService(); + + @BeforeEach + public void clearLogList() { + Hooks.onOperatorDebug(); + ListAppender.clearEventList(); + } + + @Test + public void givenFooWithNullId_whenProcessFoo_thenLogsWithDebugTrace() { + Foo one = new Foo(1, "nameverylong", 8); + Foo two = new Foo(null, "nameverylong", 4); + Flux flux = Flux.just(one, two); + + service.processFoo(flux); + + Collection allLoggedEntries = ListAppender.getEvents() + .stream() + .map(ILoggingEvent::getFormattedMessage) + .collect(Collectors.toList()); + + Collection allSuppressedEntries = ListAppender.getEvents() + .stream() + .map(ILoggingEvent::getThrowableProxy) + .flatMap(t -> { + return Optional.ofNullable(t) + .map(IThrowableProxy::getSuppressed) + .map(Arrays::stream) + .orElse(Stream.empty()); + }) + .map(IThrowableProxy::getMessage) + .collect(Collectors.toList()); + assertThat(allLoggedEntries).anyMatch(entry -> entry.contains("The following error happened on processFoo method!")) + .anyMatch(entry -> entry.contains("| onSubscribe")) + .anyMatch(entry -> entry.contains("| cancel()")); + + assertThat(allSuppressedEntries).anyMatch(entry -> entry.contains("Assembly trace from producer")) + .anyMatch(entry -> entry.contains("Error has been observed by the following operator(s)")); + } + +} diff --git a/spring-5-reactive/src/test/java/com/baeldung/debugging/consumer/ConsumerFooServiceLiveTest.java b/spring-5-reactive/src/test/java/com/baeldung/debugging/consumer/ConsumerFooServiceLiveTest.java new file mode 100644 index 0000000000..af9bdfbc9b --- /dev/null +++ b/spring-5-reactive/src/test/java/com/baeldung/debugging/consumer/ConsumerFooServiceLiveTest.java @@ -0,0 +1,49 @@ +package com.baeldung.debugging.consumer; + +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.springframework.test.web.reactive.server.WebTestClient; +import org.springframework.test.web.reactive.server.WebTestClient.ResponseSpec; + +import com.baeldung.debugging.consumer.service.FooService; + +public class ConsumerFooServiceLiveTest { + + FooService service = new FooService(); + + private static final String BASE_URL = "http://localhost:8082"; + private static final String DEBUG_HOOK_ON = BASE_URL + "/debug-hook-on"; + private static final String DEBUG_HOOK_OFF = BASE_URL + "/debug-hook-off"; + + private static WebTestClient client; + + @BeforeAll + public static void setup() { + client = WebTestClient.bindToServer() + .baseUrl(BASE_URL) + .build(); + } + + @Test + public void whenRequestingDebugHookOn_thenObtainExpectedMessage() { + ResponseSpec response = client.get() + .uri(DEBUG_HOOK_ON) + .exchange(); + response.expectStatus() + .isOk() + .expectBody(String.class) + .isEqualTo("DEBUG HOOK ON"); + } + + @Test + public void whenRequestingDebugHookOff_thenObtainExpectedMessage() { + ResponseSpec response = client.get() + .uri(DEBUG_HOOK_OFF) + .exchange(); + response.expectStatus() + .isOk() + .expectBody(String.class) + .isEqualTo("DEBUG HOOK OFF"); + } + +} diff --git a/spring-5-reactive/src/test/java/com/baeldung/debugging/consumer/utils/ListAppender.java b/spring-5-reactive/src/test/java/com/baeldung/debugging/consumer/utils/ListAppender.java new file mode 100644 index 0000000000..c8c1c110bb --- /dev/null +++ b/spring-5-reactive/src/test/java/com/baeldung/debugging/consumer/utils/ListAppender.java @@ -0,0 +1,25 @@ +package com.baeldung.debugging.consumer.utils; + +import java.util.ArrayList; +import java.util.List; + +import ch.qos.logback.classic.spi.ILoggingEvent; +import ch.qos.logback.core.AppenderBase; + +public class ListAppender extends AppenderBase { + + static private List events = new ArrayList<>(); + + @Override + protected void append(ILoggingEvent eventObject) { + events.add(eventObject); + } + + public static List getEvents() { + return events; + } + + public static void clearEventList() { + events.clear(); + } +} diff --git a/spring-5-reactive/src/test/resources/logback-test.xml b/spring-5-reactive/src/test/resources/logback-test.xml new file mode 100644 index 0000000000..514029e402 --- /dev/null +++ b/spring-5-reactive/src/test/resources/logback-test.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + \ No newline at end of file From 0f2fea091b053a30c418532439c98ee13794767a Mon Sep 17 00:00:00 2001 From: DOHA Date: Wed, 28 Nov 2018 13:59:16 +0200 Subject: [PATCH 081/146] add more custom oauth examples --- .../CustomAuthorizationRequestResolver.java | 7 ++++++ .../LinkedinTokenResponseConverter.java | 24 +++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 spring-5-security-oauth/src/main/java/com/baeldung/oauth2/LinkedinTokenResponseConverter.java diff --git a/spring-5-security-oauth/src/main/java/com/baeldung/oauth2/CustomAuthorizationRequestResolver.java b/spring-5-security-oauth/src/main/java/com/baeldung/oauth2/CustomAuthorizationRequestResolver.java index 025064423d..b3fcd15a9a 100644 --- a/spring-5-security-oauth/src/main/java/com/baeldung/oauth2/CustomAuthorizationRequestResolver.java +++ b/spring-5-security-oauth/src/main/java/com/baeldung/oauth2/CustomAuthorizationRequestResolver.java @@ -47,4 +47,11 @@ public class CustomAuthorizationRequestResolver implements OAuth2AuthorizationRe private OAuth2AuthorizationRequest customizeAuthorizationRequest1(OAuth2AuthorizationRequest req) { return OAuth2AuthorizationRequest.from(req).state("xyz").build(); } + + private OAuth2AuthorizationRequest customizeOktaReq(OAuth2AuthorizationRequest req) { + Map extraParams = new HashMap(); + extraParams.putAll(req.getAdditionalParameters()); + extraParams.put("idp", "https://idprovider.com"); + return OAuth2AuthorizationRequest.from(req).additionalParameters(extraParams).build(); + } } diff --git a/spring-5-security-oauth/src/main/java/com/baeldung/oauth2/LinkedinTokenResponseConverter.java b/spring-5-security-oauth/src/main/java/com/baeldung/oauth2/LinkedinTokenResponseConverter.java new file mode 100644 index 0000000000..f638b6101a --- /dev/null +++ b/spring-5-security-oauth/src/main/java/com/baeldung/oauth2/LinkedinTokenResponseConverter.java @@ -0,0 +1,24 @@ +package com.baeldung.oauth2; + +import java.util.Map; + +import org.springframework.core.convert.converter.Converter; +import org.springframework.security.oauth2.core.OAuth2AccessToken; +import org.springframework.security.oauth2.core.endpoint.OAuth2AccessTokenResponse; +import org.springframework.security.oauth2.core.endpoint.OAuth2ParameterNames; + +public class LinkedinTokenResponseConverter implements Converter, OAuth2AccessTokenResponse> { + + @Override + public OAuth2AccessTokenResponse convert(Map tokenResponseParameters) { + String accessToken = tokenResponseParameters.get(OAuth2ParameterNames.ACCESS_TOKEN); + long expiresIn = Long.valueOf(tokenResponseParameters.get(OAuth2ParameterNames.EXPIRES_IN)); + + OAuth2AccessToken.TokenType accessTokenType = OAuth2AccessToken.TokenType.BEARER; + + return OAuth2AccessTokenResponse.withToken(accessToken) + .tokenType(accessTokenType) + .expiresIn(expiresIn) + .build(); + } +} From ac37b4fb65bcceb3f977a208508f894f0e66fb3e Mon Sep 17 00:00:00 2001 From: Kuba Date: Wed, 28 Nov 2018 15:42:07 +0100 Subject: [PATCH 082/146] BAEL-2279 - Logging reactive sequence * BAEL-2279 - Logging reactive sequence * BAEL-2279 - Logging reactive sequence * Format fix. * Add all examples. Fix formatting. * BAEL 2279 - rename file, formatting fixes, update deps. * BAEL-2279 - Move code to reactive module. * BAEL 2279 - Remove old code. --- logging-modules/log4j/pom.xml | 7 ------- .../baeldung/webflux/logging}/WebFluxLoggingExample.java | 2 +- 2 files changed, 1 insertion(+), 8 deletions(-) rename {logging-modules/log4j/src/main/java/com/baeldung/webFluxLogging => spring-5-reactive/src/main/java/com/baeldung/webflux/logging}/WebFluxLoggingExample.java (91%) diff --git a/logging-modules/log4j/pom.xml b/logging-modules/log4j/pom.xml index 1b27e03445..c5ce1d06ad 100644 --- a/logging-modules/log4j/pom.xml +++ b/logging-modules/log4j/pom.xml @@ -44,12 +44,6 @@ disruptor ${disruptor.version} - - - org.springframework.boot - spring-boot-starter-webflux - ${spring-boot.version} - @@ -57,7 +51,6 @@ 2.7 2.7 3.3.6 - 2.1.0.RELEASE \ No newline at end of file diff --git a/logging-modules/log4j/src/main/java/com/baeldung/webFluxLogging/WebFluxLoggingExample.java b/spring-5-reactive/src/main/java/com/baeldung/webflux/logging/WebFluxLoggingExample.java similarity index 91% rename from logging-modules/log4j/src/main/java/com/baeldung/webFluxLogging/WebFluxLoggingExample.java rename to spring-5-reactive/src/main/java/com/baeldung/webflux/logging/WebFluxLoggingExample.java index f429fd57f3..c4881b2296 100644 --- a/logging-modules/log4j/src/main/java/com/baeldung/webFluxLogging/WebFluxLoggingExample.java +++ b/spring-5-reactive/src/main/java/com/baeldung/webflux/logging/WebFluxLoggingExample.java @@ -1,4 +1,4 @@ -package com.baeldung.webFluxLogging; +package com.baeldung.webflux.logging; import reactor.core.publisher.Flux; From b6431622ed022ca029a725a902bb0458ccbd5720 Mon Sep 17 00:00:00 2001 From: Aravind Ranganathan Date: Wed, 28 Nov 2018 12:01:32 -0500 Subject: [PATCH 083/146] Spring Data Cassandra Reactive Issue: BAEL-1870 --- .../spring-data-cassandra-reactive/pom.xml | 70 +++++++++++++++++++ ...pringDataCassandraReactiveApplication.java | 12 ++++ .../controller/EmployeeController.java | 49 +++++++++++++ .../cassandra/reactive/model/Employee.java | 20 ++++++ .../repository/EmployeeRepository.java | 11 +++ .../reactive/service/EmployeeService.java | 35 ++++++++++ .../src/main/resources/application.properties | 2 + ...tiveEmployeeRepositoryIntegrationTest.java | 55 +++++++++++++++ 8 files changed, 254 insertions(+) create mode 100644 persistence-modules/spring-data-cassandra-reactive/pom.xml create mode 100644 persistence-modules/spring-data-cassandra-reactive/src/main/java/com/baeldung/cassandra/reactive/SpringDataCassandraReactiveApplication.java create mode 100644 persistence-modules/spring-data-cassandra-reactive/src/main/java/com/baeldung/cassandra/reactive/controller/EmployeeController.java create mode 100644 persistence-modules/spring-data-cassandra-reactive/src/main/java/com/baeldung/cassandra/reactive/model/Employee.java create mode 100644 persistence-modules/spring-data-cassandra-reactive/src/main/java/com/baeldung/cassandra/reactive/repository/EmployeeRepository.java create mode 100644 persistence-modules/spring-data-cassandra-reactive/src/main/java/com/baeldung/cassandra/reactive/service/EmployeeService.java create mode 100644 persistence-modules/spring-data-cassandra-reactive/src/main/resources/application.properties create mode 100644 persistence-modules/spring-data-cassandra-reactive/src/test/java/com/baeldung/cassandra/reactive/ReactiveEmployeeRepositoryIntegrationTest.java diff --git a/persistence-modules/spring-data-cassandra-reactive/pom.xml b/persistence-modules/spring-data-cassandra-reactive/pom.xml new file mode 100644 index 0000000000..037b1fd3c1 --- /dev/null +++ b/persistence-modules/spring-data-cassandra-reactive/pom.xml @@ -0,0 +1,70 @@ + + + 4.0.0 + + com.baeldung + spring-data-cassandra-reactive + 0.0.1-SNAPSHOT + jar + + spring-data-cassandra-reactive + Spring Data Cassandra reactive + + + org.springframework.boot + spring-boot-starter-parent + 2.1.0.RELEASE + + + + + UTF-8 + UTF-8 + + 1.8 + + + + + org.springframework.data + spring-data-cassandra + 2.1.2.RELEASE + + + io.projectreactor + reactor-core + + + org.springframework.boot + spring-boot-starter-web + + + org.projectlombok + lombok + true + + + org.springframework.boot + spring-boot-starter-test + test + + + io.projectreactor + reactor-test + test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + + diff --git a/persistence-modules/spring-data-cassandra-reactive/src/main/java/com/baeldung/cassandra/reactive/SpringDataCassandraReactiveApplication.java b/persistence-modules/spring-data-cassandra-reactive/src/main/java/com/baeldung/cassandra/reactive/SpringDataCassandraReactiveApplication.java new file mode 100644 index 0000000000..5f467042a3 --- /dev/null +++ b/persistence-modules/spring-data-cassandra-reactive/src/main/java/com/baeldung/cassandra/reactive/SpringDataCassandraReactiveApplication.java @@ -0,0 +1,12 @@ +package com.baeldung.cassandra.reactive; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SpringDataCassandraReactiveApplication { + + public static void main(String[] args) { + SpringApplication.run(SpringDataCassandraReactiveApplication.class, args); + } +} diff --git a/persistence-modules/spring-data-cassandra-reactive/src/main/java/com/baeldung/cassandra/reactive/controller/EmployeeController.java b/persistence-modules/spring-data-cassandra-reactive/src/main/java/com/baeldung/cassandra/reactive/controller/EmployeeController.java new file mode 100644 index 0000000000..e9de213e61 --- /dev/null +++ b/persistence-modules/spring-data-cassandra-reactive/src/main/java/com/baeldung/cassandra/reactive/controller/EmployeeController.java @@ -0,0 +1,49 @@ +package com.baeldung.cassandra.reactive.controller; + +import com.baeldung.cassandra.reactive.model.Employee; +import com.baeldung.cassandra.reactive.service.EmployeeService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; + +import javax.annotation.PostConstruct; +import java.util.ArrayList; +import java.util.List; + +@RestController +@RequestMapping("employee") +public class EmployeeController { + + @Autowired + EmployeeService employeeService; + + @PostConstruct + public void saveEmployees() { + List employees = new ArrayList<>(); + employees.add(new Employee(123, "John Doe", "Delaware", "jdoe@xyz.com", 31)); + employees.add(new Employee(324, "Adam Smith", "North Carolina", "asmith@xyz.com", 43)); + employees.add(new Employee(355, "Kevin Dunner", "Virginia", "kdunner@xyz.com", 24)); + employees.add(new Employee(643, "Mike Lauren", "New York", "mlauren@xyz.com", 41)); + employeeService.initializeEmployees(employees); + } + + @GetMapping("/list") + public Flux getAllEmployees() { + Flux employees = employeeService.getAllEmployees(); + return employees; + } + + @GetMapping("/{id}") + public Mono getEmployeeById(@PathVariable int id) { + return employeeService.getEmployeeById(id); + } + + @GetMapping("/filterByAge/{age}") + public Flux getEmployeesFilterByAge(@PathVariable int age) { + return employeeService.getEmployeesFilterByAge(age); + } +} diff --git a/persistence-modules/spring-data-cassandra-reactive/src/main/java/com/baeldung/cassandra/reactive/model/Employee.java b/persistence-modules/spring-data-cassandra-reactive/src/main/java/com/baeldung/cassandra/reactive/model/Employee.java new file mode 100644 index 0000000000..a78f884778 --- /dev/null +++ b/persistence-modules/spring-data-cassandra-reactive/src/main/java/com/baeldung/cassandra/reactive/model/Employee.java @@ -0,0 +1,20 @@ +package com.baeldung.cassandra.reactive.model; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.springframework.data.cassandra.core.mapping.PrimaryKey; +import org.springframework.data.cassandra.core.mapping.Table; + +@Table +@Data +@AllArgsConstructor +@NoArgsConstructor +public class Employee { + @PrimaryKey + private int id; + private String name; + private String address; + private String email; + private int age; +} diff --git a/persistence-modules/spring-data-cassandra-reactive/src/main/java/com/baeldung/cassandra/reactive/repository/EmployeeRepository.java b/persistence-modules/spring-data-cassandra-reactive/src/main/java/com/baeldung/cassandra/reactive/repository/EmployeeRepository.java new file mode 100644 index 0000000000..22dc2b4565 --- /dev/null +++ b/persistence-modules/spring-data-cassandra-reactive/src/main/java/com/baeldung/cassandra/reactive/repository/EmployeeRepository.java @@ -0,0 +1,11 @@ +package com.baeldung.cassandra.reactive.repository; + +import com.baeldung.cassandra.reactive.model.Employee; +import org.springframework.data.cassandra.repository.AllowFiltering; +import org.springframework.data.cassandra.repository.ReactiveCassandraRepository; +import reactor.core.publisher.Flux; + +public interface EmployeeRepository extends ReactiveCassandraRepository { + @AllowFiltering + Flux findByAgeGreaterThan(int age); +} diff --git a/persistence-modules/spring-data-cassandra-reactive/src/main/java/com/baeldung/cassandra/reactive/service/EmployeeService.java b/persistence-modules/spring-data-cassandra-reactive/src/main/java/com/baeldung/cassandra/reactive/service/EmployeeService.java new file mode 100644 index 0000000000..40c330937a --- /dev/null +++ b/persistence-modules/spring-data-cassandra-reactive/src/main/java/com/baeldung/cassandra/reactive/service/EmployeeService.java @@ -0,0 +1,35 @@ +package com.baeldung.cassandra.reactive.service; + +import com.baeldung.cassandra.reactive.model.Employee; +import com.baeldung.cassandra.reactive.repository.EmployeeRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; + +import java.util.List; + +@Service +public class EmployeeService { + + @Autowired + EmployeeRepository employeeRepository; + + public void initializeEmployees(List employees) { + Flux savedEmployees = employeeRepository.saveAll(employees); + savedEmployees.subscribe(); + } + + public Flux getAllEmployees() { + Flux employees = employeeRepository.findAll(); + return employees; + } + + public Flux getEmployeesFilterByAge(int age) { + return employeeRepository.findByAgeGreaterThan(age); + } + + public Mono getEmployeeById(int id) { + return employeeRepository.findById(id); + } +} diff --git a/persistence-modules/spring-data-cassandra-reactive/src/main/resources/application.properties b/persistence-modules/spring-data-cassandra-reactive/src/main/resources/application.properties new file mode 100644 index 0000000000..7ed2f10131 --- /dev/null +++ b/persistence-modules/spring-data-cassandra-reactive/src/main/resources/application.properties @@ -0,0 +1,2 @@ +spring.data.cassandra.keyspace-name=practice +spring.data.cassandra.port=9042 \ No newline at end of file diff --git a/persistence-modules/spring-data-cassandra-reactive/src/test/java/com/baeldung/cassandra/reactive/ReactiveEmployeeRepositoryIntegrationTest.java b/persistence-modules/spring-data-cassandra-reactive/src/test/java/com/baeldung/cassandra/reactive/ReactiveEmployeeRepositoryIntegrationTest.java new file mode 100644 index 0000000000..ad726fe969 --- /dev/null +++ b/persistence-modules/spring-data-cassandra-reactive/src/test/java/com/baeldung/cassandra/reactive/ReactiveEmployeeRepositoryIntegrationTest.java @@ -0,0 +1,55 @@ +package com.baeldung.cassandra.reactive; + +import com.baeldung.cassandra.reactive.model.Employee; +import com.baeldung.cassandra.reactive.repository.EmployeeRepository; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; +import reactor.test.StepVerifier; + + +@RunWith(SpringRunner.class) +@SpringBootTest +public class ReactiveEmployeeRepositoryIntegrationTest { + + @Autowired + EmployeeRepository repository; + + @Before + public void setUp() { + + Flux deleteAndInsert = repository.deleteAll() // + .thenMany(repository.saveAll(Flux.just( + new Employee(111, "John Doe", "Delaware", "jdoe@xyz.com", 31), + new Employee(222, "Adam Smith", "North Carolina", "asmith@xyz.com", 43), + new Employee(333, "Kevin Dunner", "Virginia", "kdunner@xyz.com", 24), + new Employee(444, "Mike Lauren", "New York", "mlauren@xyz.com", 41)))); + + StepVerifier.create(deleteAndInsert).expectNextCount(4).verifyComplete(); + } + + @Test + public void givenRecordsAreInserted_whenDbIsQueried_thenShouldIncludeNewRecords() { + + Mono saveAndCount = repository.count() + .doOnNext(System.out::println) + .thenMany(repository.saveAll(Flux.just(new Employee(325, "Kim Jones", "Florida", "kjones@xyz.com", 42), + new Employee(654, "Tom Moody", "New Hampshire", "tmoody@xyz.com", 44)))) + .last() + .flatMap(v -> repository.count()) + .doOnNext(System.out::println); + + StepVerifier.create(saveAndCount).expectNext(6L).verifyComplete(); + } + + @Test + public void givenAgeForFilter_whenDbIsQueried_thenShouldReturnFilteredRecords() { + StepVerifier.create(repository.findByAgeGreaterThan(35)).expectNextCount(2).verifyComplete(); + } + +} From c81567741e2072face906788d33f366056c95fea Mon Sep 17 00:00:00 2001 From: Josh Cummings Date: Wed, 28 Nov 2018 10:02:09 -0700 Subject: [PATCH 084/146] Move ClassName to core-java-lang (#5796) Issue: BAEL-2309 --- .../src/main/java/com/baeldung/className/RetrievingClassName.java | 0 .../java/com/baeldung/className/RetrievingClassNameUnitTest.java | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename {core-java => core-java-lang}/src/main/java/com/baeldung/className/RetrievingClassName.java (100%) rename {core-java => core-java-lang}/src/test/java/com/baeldung/className/RetrievingClassNameUnitTest.java (100%) diff --git a/core-java/src/main/java/com/baeldung/className/RetrievingClassName.java b/core-java-lang/src/main/java/com/baeldung/className/RetrievingClassName.java similarity index 100% rename from core-java/src/main/java/com/baeldung/className/RetrievingClassName.java rename to core-java-lang/src/main/java/com/baeldung/className/RetrievingClassName.java diff --git a/core-java/src/test/java/com/baeldung/className/RetrievingClassNameUnitTest.java b/core-java-lang/src/test/java/com/baeldung/className/RetrievingClassNameUnitTest.java similarity index 100% rename from core-java/src/test/java/com/baeldung/className/RetrievingClassNameUnitTest.java rename to core-java-lang/src/test/java/com/baeldung/className/RetrievingClassNameUnitTest.java From 866666f3db77a8d72a58a4f269561537d9389533 Mon Sep 17 00:00:00 2001 From: Josh Cummings Date: Wed, 28 Nov 2018 10:02:35 -0700 Subject: [PATCH 085/146] Add load-testing-comparison to Build (#5757) Issue: bael-46 --- pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pom.xml b/pom.xml index 70248b9993..b998967bbf 100644 --- a/pom.xml +++ b/pom.xml @@ -377,6 +377,7 @@ feign flips testing-modules/groovy-spock + testing-modules/load-testing-comparison google-cloud google-web-toolkit gson From 4b6515d8a379b5bfc0aaae572a21ecb7581cb21f Mon Sep 17 00:00:00 2001 From: Tom Hombergs Date: Wed, 28 Nov 2018 20:46:43 +0100 Subject: [PATCH 086/146] added readme --- restx/README.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 restx/README.md diff --git a/restx/README.md b/restx/README.md new file mode 100644 index 0000000000..f586f08a21 --- /dev/null +++ b/restx/README.md @@ -0,0 +1,3 @@ +# Relevant Articles + +* [Introduction to RESTX](https://www.baeldung.com/java-restx) From 5871653e65d41da0191afe56ed2b1ce2cac92338 Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Wed, 28 Nov 2018 23:42:40 +0200 Subject: [PATCH 087/146] Update and rename OptimizedMatcherUnitTest.java to OptimizedMatcherManualTest.java --- ...izedMatcherUnitTest.java => OptimizedMatcherManualTest.java} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename core-java/src/test/java/com/baeldung/regexp/optmization/{OptimizedMatcherUnitTest.java => OptimizedMatcherManualTest.java} (98%) diff --git a/core-java/src/test/java/com/baeldung/regexp/optmization/OptimizedMatcherUnitTest.java b/core-java/src/test/java/com/baeldung/regexp/optmization/OptimizedMatcherManualTest.java similarity index 98% rename from core-java/src/test/java/com/baeldung/regexp/optmization/OptimizedMatcherUnitTest.java rename to core-java/src/test/java/com/baeldung/regexp/optmization/OptimizedMatcherManualTest.java index 2be6b6ad4b..f44968a5a7 100644 --- a/core-java/src/test/java/com/baeldung/regexp/optmization/OptimizedMatcherUnitTest.java +++ b/core-java/src/test/java/com/baeldung/regexp/optmization/OptimizedMatcherManualTest.java @@ -11,7 +11,7 @@ import java.util.regex.Pattern; import static org.junit.Assert.assertTrue; -public class OptimizedMatcherUnitTest { +public class OptimizedMatcherManualTest { private String action; From 186c2994a745dccf09a543bd578655556e2ff7c9 Mon Sep 17 00:00:00 2001 From: DOHA Date: Thu, 29 Nov 2018 01:51:07 +0200 Subject: [PATCH 088/146] organise oauth2 request code --- .../oauth2/CustomRequestSecurityConfig.java | 119 ++++++++++++++++++ .../com/baeldung/oauth2/SecurityConfig.java | 13 -- .../CustomAuthorizationRequestResolver.java | 2 +- .../CustomRequestEntityConverter.java | 2 +- .../CustomTokenResponseConverter.java | 2 +- .../LinkedinTokenResponseConverter.java | 2 +- 6 files changed, 123 insertions(+), 17 deletions(-) create mode 100644 spring-5-security-oauth/src/main/java/com/baeldung/oauth2/CustomRequestSecurityConfig.java rename spring-5-security-oauth/src/main/java/com/baeldung/{oauth2 => oauth2request}/CustomAuthorizationRequestResolver.java (98%) rename spring-5-security-oauth/src/main/java/com/baeldung/{oauth2 => oauth2request}/CustomRequestEntityConverter.java (96%) rename spring-5-security-oauth/src/main/java/com/baeldung/{oauth2 => oauth2request}/CustomTokenResponseConverter.java (98%) rename spring-5-security-oauth/src/main/java/com/baeldung/{oauth2 => oauth2request}/LinkedinTokenResponseConverter.java (96%) diff --git a/spring-5-security-oauth/src/main/java/com/baeldung/oauth2/CustomRequestSecurityConfig.java b/spring-5-security-oauth/src/main/java/com/baeldung/oauth2/CustomRequestSecurityConfig.java new file mode 100644 index 0000000000..51caee8178 --- /dev/null +++ b/spring-5-security-oauth/src/main/java/com/baeldung/oauth2/CustomRequestSecurityConfig.java @@ -0,0 +1,119 @@ +package com.baeldung.oauth2; + +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.PropertySource; +import org.springframework.core.env.Environment; +import org.springframework.http.converter.FormHttpMessageConverter; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; +import org.springframework.security.config.oauth2.client.CommonOAuth2Provider; +import org.springframework.security.oauth2.client.endpoint.DefaultAuthorizationCodeTokenResponseClient; +import org.springframework.security.oauth2.client.endpoint.OAuth2AccessTokenResponseClient; +import org.springframework.security.oauth2.client.endpoint.OAuth2AuthorizationCodeGrantRequest; +import org.springframework.security.oauth2.client.http.OAuth2ErrorResponseErrorHandler; +import org.springframework.security.oauth2.client.registration.ClientRegistration; +import org.springframework.security.oauth2.client.registration.ClientRegistrationRepository; +import org.springframework.security.oauth2.client.registration.InMemoryClientRegistrationRepository; +import org.springframework.security.oauth2.client.web.AuthorizationRequestRepository; +import org.springframework.security.oauth2.client.web.HttpSessionOAuth2AuthorizationRequestRepository; +import org.springframework.security.oauth2.core.endpoint.OAuth2AuthorizationRequest; +import org.springframework.security.oauth2.core.http.converter.OAuth2AccessTokenResponseHttpMessageConverter; +import org.springframework.web.client.RestTemplate; + +import com.baeldung.oauth2request.CustomAuthorizationRequestResolver; +import com.baeldung.oauth2request.CustomRequestEntityConverter; +import com.baeldung.oauth2request.CustomTokenResponseConverter; + +//@Configuration +@PropertySource("application-oauth2.properties") +public class CustomRequestSecurityConfig extends WebSecurityConfigurerAdapter { + + @Override + protected void configure(HttpSecurity http) throws Exception { + http.authorizeRequests() + .antMatchers("/oauth_login", "/loginFailure", "/") + .permitAll() + .anyRequest() + .authenticated() + .and() + .oauth2Login() + .loginPage("/oauth_login") + .authorizationEndpoint() + .authorizationRequestResolver( new CustomAuthorizationRequestResolver(clientRegistrationRepository(),"/oauth2/authorize-client")) + + .baseUri("/oauth2/authorize-client") + .authorizationRequestRepository(authorizationRequestRepository()) + .and() + .tokenEndpoint() + .accessTokenResponseClient(accessTokenResponseClient()) + .and() + .defaultSuccessUrl("/loginSuccess") + .failureUrl("/loginFailure"); + } + + @Bean + public AuthorizationRequestRepository authorizationRequestRepository() { + return new HttpSessionOAuth2AuthorizationRequestRepository(); + } + + @Bean + public OAuth2AccessTokenResponseClient accessTokenResponseClient() { + DefaultAuthorizationCodeTokenResponseClient accessTokenResponseClient = new DefaultAuthorizationCodeTokenResponseClient(); + accessTokenResponseClient.setRequestEntityConverter(new CustomRequestEntityConverter()); + + OAuth2AccessTokenResponseHttpMessageConverter tokenResponseHttpMessageConverter = new OAuth2AccessTokenResponseHttpMessageConverter(); + tokenResponseHttpMessageConverter.setTokenResponseConverter(new CustomTokenResponseConverter()); + RestTemplate restTemplate = new RestTemplate(Arrays.asList(new FormHttpMessageConverter(), tokenResponseHttpMessageConverter)); + restTemplate.setErrorHandler(new OAuth2ErrorResponseErrorHandler()); + accessTokenResponseClient.setRestOperations(restTemplate); + return accessTokenResponseClient; + } + + + // additional configuration for non-Spring Boot projects + private static List clients = Arrays.asList("google", "facebook"); + + //@Bean + public ClientRegistrationRepository clientRegistrationRepository() { + List registrations = clients.stream() + .map(c -> getRegistration(c)) + .filter(registration -> registration != null) + .collect(Collectors.toList()); + + return new InMemoryClientRegistrationRepository(registrations); + } + + private static String CLIENT_PROPERTY_KEY = "spring.security.oauth2.client.registration."; + + @Autowired + private Environment env; + + private ClientRegistration getRegistration(String client) { + String clientId = env.getProperty(CLIENT_PROPERTY_KEY + client + ".client-id"); + + if (clientId == null) { + return null; + } + + String clientSecret = env.getProperty(CLIENT_PROPERTY_KEY + client + ".client-secret"); + if (client.equals("google")) { + return CommonOAuth2Provider.GOOGLE.getBuilder(client) + .clientId(clientId) + .clientSecret(clientSecret) + .build(); + } + if (client.equals("facebook")) { + return CommonOAuth2Provider.FACEBOOK.getBuilder(client) + .clientId(clientId) + .clientSecret(clientSecret) + .build(); + } + return null; + } + +} diff --git a/spring-5-security-oauth/src/main/java/com/baeldung/oauth2/SecurityConfig.java b/spring-5-security-oauth/src/main/java/com/baeldung/oauth2/SecurityConfig.java index cf27b01a75..e17e339142 100644 --- a/spring-5-security-oauth/src/main/java/com/baeldung/oauth2/SecurityConfig.java +++ b/spring-5-security-oauth/src/main/java/com/baeldung/oauth2/SecurityConfig.java @@ -9,22 +9,18 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.PropertySource; import org.springframework.core.env.Environment; -import org.springframework.http.converter.FormHttpMessageConverter; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; import org.springframework.security.config.oauth2.client.CommonOAuth2Provider; import org.springframework.security.oauth2.client.endpoint.DefaultAuthorizationCodeTokenResponseClient; import org.springframework.security.oauth2.client.endpoint.OAuth2AccessTokenResponseClient; import org.springframework.security.oauth2.client.endpoint.OAuth2AuthorizationCodeGrantRequest; -import org.springframework.security.oauth2.client.http.OAuth2ErrorResponseErrorHandler; import org.springframework.security.oauth2.client.registration.ClientRegistration; import org.springframework.security.oauth2.client.registration.ClientRegistrationRepository; import org.springframework.security.oauth2.client.registration.InMemoryClientRegistrationRepository; import org.springframework.security.oauth2.client.web.AuthorizationRequestRepository; import org.springframework.security.oauth2.client.web.HttpSessionOAuth2AuthorizationRequestRepository; import org.springframework.security.oauth2.core.endpoint.OAuth2AuthorizationRequest; -import org.springframework.security.oauth2.core.http.converter.OAuth2AccessTokenResponseHttpMessageConverter; -import org.springframework.web.client.RestTemplate; @Configuration @PropertySource("application-oauth2.properties") @@ -41,8 +37,6 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter { .oauth2Login() .loginPage("/oauth_login") .authorizationEndpoint() - .authorizationRequestResolver( new CustomAuthorizationRequestResolver(clientRegistrationRepository(),"/oauth2/authorize-client")) - .baseUri("/oauth2/authorize-client") .authorizationRequestRepository(authorizationRequestRepository()) .and() @@ -61,13 +55,6 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter { @Bean public OAuth2AccessTokenResponseClient accessTokenResponseClient() { DefaultAuthorizationCodeTokenResponseClient accessTokenResponseClient = new DefaultAuthorizationCodeTokenResponseClient(); - accessTokenResponseClient.setRequestEntityConverter(new CustomRequestEntityConverter()); - - OAuth2AccessTokenResponseHttpMessageConverter tokenResponseHttpMessageConverter = new OAuth2AccessTokenResponseHttpMessageConverter(); - tokenResponseHttpMessageConverter.setTokenResponseConverter(new CustomTokenResponseConverter()); - RestTemplate restTemplate = new RestTemplate(Arrays.asList(new FormHttpMessageConverter(), tokenResponseHttpMessageConverter)); - restTemplate.setErrorHandler(new OAuth2ErrorResponseErrorHandler()); - accessTokenResponseClient.setRestOperations(restTemplate); return accessTokenResponseClient; } diff --git a/spring-5-security-oauth/src/main/java/com/baeldung/oauth2/CustomAuthorizationRequestResolver.java b/spring-5-security-oauth/src/main/java/com/baeldung/oauth2request/CustomAuthorizationRequestResolver.java similarity index 98% rename from spring-5-security-oauth/src/main/java/com/baeldung/oauth2/CustomAuthorizationRequestResolver.java rename to spring-5-security-oauth/src/main/java/com/baeldung/oauth2request/CustomAuthorizationRequestResolver.java index b3fcd15a9a..47aacf9c06 100644 --- a/spring-5-security-oauth/src/main/java/com/baeldung/oauth2/CustomAuthorizationRequestResolver.java +++ b/spring-5-security-oauth/src/main/java/com/baeldung/oauth2request/CustomAuthorizationRequestResolver.java @@ -1,4 +1,4 @@ -package com.baeldung.oauth2; +package com.baeldung.oauth2request; import java.util.HashMap; import java.util.Map; diff --git a/spring-5-security-oauth/src/main/java/com/baeldung/oauth2/CustomRequestEntityConverter.java b/spring-5-security-oauth/src/main/java/com/baeldung/oauth2request/CustomRequestEntityConverter.java similarity index 96% rename from spring-5-security-oauth/src/main/java/com/baeldung/oauth2/CustomRequestEntityConverter.java rename to spring-5-security-oauth/src/main/java/com/baeldung/oauth2request/CustomRequestEntityConverter.java index 8884065769..5486105c34 100644 --- a/spring-5-security-oauth/src/main/java/com/baeldung/oauth2/CustomRequestEntityConverter.java +++ b/spring-5-security-oauth/src/main/java/com/baeldung/oauth2request/CustomRequestEntityConverter.java @@ -1,4 +1,4 @@ -package com.baeldung.oauth2; +package com.baeldung.oauth2request; import org.springframework.core.convert.converter.Converter; import org.springframework.http.RequestEntity; diff --git a/spring-5-security-oauth/src/main/java/com/baeldung/oauth2/CustomTokenResponseConverter.java b/spring-5-security-oauth/src/main/java/com/baeldung/oauth2request/CustomTokenResponseConverter.java similarity index 98% rename from spring-5-security-oauth/src/main/java/com/baeldung/oauth2/CustomTokenResponseConverter.java rename to spring-5-security-oauth/src/main/java/com/baeldung/oauth2request/CustomTokenResponseConverter.java index 741f44871a..b9775d674a 100644 --- a/spring-5-security-oauth/src/main/java/com/baeldung/oauth2/CustomTokenResponseConverter.java +++ b/spring-5-security-oauth/src/main/java/com/baeldung/oauth2request/CustomTokenResponseConverter.java @@ -1,4 +1,4 @@ -package com.baeldung.oauth2; +package com.baeldung.oauth2request; import java.util.Arrays; import java.util.Collections; diff --git a/spring-5-security-oauth/src/main/java/com/baeldung/oauth2/LinkedinTokenResponseConverter.java b/spring-5-security-oauth/src/main/java/com/baeldung/oauth2request/LinkedinTokenResponseConverter.java similarity index 96% rename from spring-5-security-oauth/src/main/java/com/baeldung/oauth2/LinkedinTokenResponseConverter.java rename to spring-5-security-oauth/src/main/java/com/baeldung/oauth2request/LinkedinTokenResponseConverter.java index f638b6101a..89b3d32de5 100644 --- a/spring-5-security-oauth/src/main/java/com/baeldung/oauth2/LinkedinTokenResponseConverter.java +++ b/spring-5-security-oauth/src/main/java/com/baeldung/oauth2request/LinkedinTokenResponseConverter.java @@ -1,4 +1,4 @@ -package com.baeldung.oauth2; +package com.baeldung.oauth2request; import java.util.Map; From 2ee5e03b887585e5a4f1b4657b5d47583f2984fb Mon Sep 17 00:00:00 2001 From: Ali Dehghani Date: Thu, 22 Nov 2018 23:07:29 +0330 Subject: [PATCH 089/146] Added the codes used for operator overloading article --- .../kotlin/com/baeldung/operators/Money.kt | 27 +++++++++++++++++ .../kotlin/com/baeldung/operators/Page.kt | 14 +++++++++ .../kotlin/com/baeldung/operators/Point.kt | 14 +++++++++ .../main/kotlin/com/baeldung/operators/UI.kt | 30 +++++++++++++++++++ .../kotlin/com/baeldung/operators/Utils.kt | 4 +++ 5 files changed, 89 insertions(+) create mode 100644 core-kotlin/src/main/kotlin/com/baeldung/operators/Money.kt create mode 100644 core-kotlin/src/main/kotlin/com/baeldung/operators/Page.kt create mode 100644 core-kotlin/src/main/kotlin/com/baeldung/operators/Point.kt create mode 100644 core-kotlin/src/main/kotlin/com/baeldung/operators/UI.kt create mode 100644 core-kotlin/src/main/kotlin/com/baeldung/operators/Utils.kt diff --git a/core-kotlin/src/main/kotlin/com/baeldung/operators/Money.kt b/core-kotlin/src/main/kotlin/com/baeldung/operators/Money.kt new file mode 100644 index 0000000000..ffaea71e1e --- /dev/null +++ b/core-kotlin/src/main/kotlin/com/baeldung/operators/Money.kt @@ -0,0 +1,27 @@ +enum class Currency { + DOLLARS, EURO +} + +class Money(val amount: BigDecimal, val currency: Currency) : Comparable { + + override fun compareTo(other: Money): Int = + convert(Currency.DOLLARS).compareTo(other.convert(Currency.DOLLARS)) + + fun convert(currency: Currency): BigDecimal = TODO() + + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (other !is Money) return false + + if (amount != other.amount) return false + if (currency != other.currency) return false + + return true + } + + override fun hashCode(): Int { + var result = amount.hashCode() + result = 31 * result + currency.hashCode() + return result + } +} \ No newline at end of file diff --git a/core-kotlin/src/main/kotlin/com/baeldung/operators/Page.kt b/core-kotlin/src/main/kotlin/com/baeldung/operators/Page.kt new file mode 100644 index 0000000000..db03779b35 --- /dev/null +++ b/core-kotlin/src/main/kotlin/com/baeldung/operators/Page.kt @@ -0,0 +1,14 @@ +interface Page { + fun pageNumber(): Int + fun pageSize(): Int + fun elements(): MutableList +} + +operator fun Page.get(index: Int): T = elements()[index] +operator fun Page.get(start: Int, endExclusive: Int): List = elements().subList(start, endExclusive) +operator fun Page.set(index: Int, value: T) { + elements()[index] = value +} + +operator fun Page.contains(element: T): Boolean = element in elements() +operator fun Page.iterator() = elements().iterator() \ No newline at end of file diff --git a/core-kotlin/src/main/kotlin/com/baeldung/operators/Point.kt b/core-kotlin/src/main/kotlin/com/baeldung/operators/Point.kt new file mode 100644 index 0000000000..7af2fc1cad --- /dev/null +++ b/core-kotlin/src/main/kotlin/com/baeldung/operators/Point.kt @@ -0,0 +1,14 @@ +data class Point(val x: Int, val y: Int) + +operator fun Point.unaryMinus() = Point(-x, -y) +operator fun Point.not() = Point(y, x) +operator fun Point.inc() = Point(x + 1, y + 1) +operator fun Point.dec() = Point(x - 1, y - 1) + +operator fun Point.plus(other: Point): Point = Point(x + other.x, y + other.y) +operator fun Point.minus(other: Point): Point = Point(x - other.x, y - other.y) +operator fun Point.times(other: Point): Point = Point(x * other.x, y * other.y) +operator fun Point.div(other: Point): Point = Point(x / other.x, y / other.y) +operator fun Point.rem(other: Point): Point = Point(x % other.x, y % other.y) +operator fun Point.times(factor: Int): Point = Point(x * factor, y * factor) +operator fun Int.times(point: Point): Point = Point(point.x * this, point.y * this) \ No newline at end of file diff --git a/core-kotlin/src/main/kotlin/com/baeldung/operators/UI.kt b/core-kotlin/src/main/kotlin/com/baeldung/operators/UI.kt new file mode 100644 index 0000000000..abb4a4a00c --- /dev/null +++ b/core-kotlin/src/main/kotlin/com/baeldung/operators/UI.kt @@ -0,0 +1,30 @@ +interface View +class TextView(val value: String) : View +class ImageView(val url: String) : View + +class UI { + private val views = mutableListOf() + + operator fun String.unaryPlus() { + views.add(TextView(this)) + } + + operator fun View.unaryPlus() { + views.add(this) + } +} + +fun ui(init: UI.() -> Unit): UI { + val ui = UI() + ui.init() + + return ui +} + +fun main(args: Array) { + val header = ui { + +ImageView("http://logo.com") + +"Brand name" + +"Brand description" + } +} \ No newline at end of file diff --git a/core-kotlin/src/main/kotlin/com/baeldung/operators/Utils.kt b/core-kotlin/src/main/kotlin/com/baeldung/operators/Utils.kt new file mode 100644 index 0000000000..a3c671369c --- /dev/null +++ b/core-kotlin/src/main/kotlin/com/baeldung/operators/Utils.kt @@ -0,0 +1,4 @@ +operator fun MutableCollection.plusAssign(element: T) { + add(element) +} +operator fun BigInteger.plus(other: Int): BigInteger = add(BigInteger("$other")) \ No newline at end of file From a8d9eb084a9f48d14dd9af46e2f870b12df74c33 Mon Sep 17 00:00:00 2001 From: Ali Dehghani Date: Thu, 22 Nov 2018 23:47:49 +0330 Subject: [PATCH 090/146] Added two missing import statements --- core-kotlin/src/main/kotlin/com/baeldung/operators/Money.kt | 2 ++ core-kotlin/src/main/kotlin/com/baeldung/operators/Utils.kt | 2 ++ 2 files changed, 4 insertions(+) diff --git a/core-kotlin/src/main/kotlin/com/baeldung/operators/Money.kt b/core-kotlin/src/main/kotlin/com/baeldung/operators/Money.kt index ffaea71e1e..1bb015ac27 100644 --- a/core-kotlin/src/main/kotlin/com/baeldung/operators/Money.kt +++ b/core-kotlin/src/main/kotlin/com/baeldung/operators/Money.kt @@ -1,3 +1,5 @@ +import java.math.BigDecimal + enum class Currency { DOLLARS, EURO } diff --git a/core-kotlin/src/main/kotlin/com/baeldung/operators/Utils.kt b/core-kotlin/src/main/kotlin/com/baeldung/operators/Utils.kt index a3c671369c..ba33d3e7a2 100644 --- a/core-kotlin/src/main/kotlin/com/baeldung/operators/Utils.kt +++ b/core-kotlin/src/main/kotlin/com/baeldung/operators/Utils.kt @@ -1,3 +1,5 @@ +import java.math.BigInteger + operator fun MutableCollection.plusAssign(element: T) { add(element) } From 1250605e19850ea102e4275fcc8a882220c82d97 Mon Sep 17 00:00:00 2001 From: Ali Dehghani Date: Sun, 25 Nov 2018 00:51:27 +0330 Subject: [PATCH 091/146] Added a new shape class instead of UI. --- .../kotlin/com/baeldung/operators/Point.kt | 17 ++++++++++- .../main/kotlin/com/baeldung/operators/UI.kt | 30 ------------------- 2 files changed, 16 insertions(+), 31 deletions(-) delete mode 100644 core-kotlin/src/main/kotlin/com/baeldung/operators/UI.kt diff --git a/core-kotlin/src/main/kotlin/com/baeldung/operators/Point.kt b/core-kotlin/src/main/kotlin/com/baeldung/operators/Point.kt index 7af2fc1cad..22617a4ee6 100644 --- a/core-kotlin/src/main/kotlin/com/baeldung/operators/Point.kt +++ b/core-kotlin/src/main/kotlin/com/baeldung/operators/Point.kt @@ -11,4 +11,19 @@ operator fun Point.times(other: Point): Point = Point(x * other.x, y * other.y) operator fun Point.div(other: Point): Point = Point(x / other.x, y / other.y) operator fun Point.rem(other: Point): Point = Point(x % other.x, y % other.y) operator fun Point.times(factor: Int): Point = Point(x * factor, y * factor) -operator fun Int.times(point: Point): Point = Point(point.x * this, point.y * this) \ No newline at end of file +operator fun Int.times(point: Point): Point = Point(point.x * this, point.y * this) + +class Shape { + private val points = mutableListOf() + + operator fun Point.unaryPlus() { + points.add(this) + } +} + +fun shape(init: Shape.() -> Unit): Shape { + val shape = Shape() + shape.init() + + return shape +} \ No newline at end of file diff --git a/core-kotlin/src/main/kotlin/com/baeldung/operators/UI.kt b/core-kotlin/src/main/kotlin/com/baeldung/operators/UI.kt deleted file mode 100644 index abb4a4a00c..0000000000 --- a/core-kotlin/src/main/kotlin/com/baeldung/operators/UI.kt +++ /dev/null @@ -1,30 +0,0 @@ -interface View -class TextView(val value: String) : View -class ImageView(val url: String) : View - -class UI { - private val views = mutableListOf() - - operator fun String.unaryPlus() { - views.add(TextView(this)) - } - - operator fun View.unaryPlus() { - views.add(this) - } -} - -fun ui(init: UI.() -> Unit): UI { - val ui = UI() - ui.init() - - return ui -} - -fun main(args: Array) { - val header = ui { - +ImageView("http://logo.com") - +"Brand name" - +"Brand description" - } -} \ No newline at end of file From ad8ae556a8a8e0673d8810490447366e5a544584 Mon Sep 17 00:00:00 2001 From: Ali Dehghani Date: Thu, 29 Nov 2018 13:30:52 +0330 Subject: [PATCH 092/146] Added a few unit tests for kotlin operator examples. --- .../kotlin/com/baeldung/operators/Money.kt | 2 + .../kotlin/com/baeldung/operators/Page.kt | 2 + .../kotlin/com/baeldung/operators/Point.kt | 4 +- .../kotlin/com/baeldung/operators/Utils.kt | 2 + .../kotlin/com/baeldung/operators/PageTest.kt | 28 +++++++++++ .../com/baeldung/operators/PointTest.kt | 48 +++++++++++++++++++ 6 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 core-kotlin/src/test/kotlin/com/baeldung/operators/PageTest.kt create mode 100644 core-kotlin/src/test/kotlin/com/baeldung/operators/PointTest.kt diff --git a/core-kotlin/src/main/kotlin/com/baeldung/operators/Money.kt b/core-kotlin/src/main/kotlin/com/baeldung/operators/Money.kt index 1bb015ac27..93eb78c5b6 100644 --- a/core-kotlin/src/main/kotlin/com/baeldung/operators/Money.kt +++ b/core-kotlin/src/main/kotlin/com/baeldung/operators/Money.kt @@ -1,3 +1,5 @@ +package com.baeldung.operators + import java.math.BigDecimal enum class Currency { diff --git a/core-kotlin/src/main/kotlin/com/baeldung/operators/Page.kt b/core-kotlin/src/main/kotlin/com/baeldung/operators/Page.kt index db03779b35..1077eb94f9 100644 --- a/core-kotlin/src/main/kotlin/com/baeldung/operators/Page.kt +++ b/core-kotlin/src/main/kotlin/com/baeldung/operators/Page.kt @@ -1,3 +1,5 @@ +package com.baeldung.operators + interface Page { fun pageNumber(): Int fun pageSize(): Int diff --git a/core-kotlin/src/main/kotlin/com/baeldung/operators/Point.kt b/core-kotlin/src/main/kotlin/com/baeldung/operators/Point.kt index 22617a4ee6..e3282e64cc 100644 --- a/core-kotlin/src/main/kotlin/com/baeldung/operators/Point.kt +++ b/core-kotlin/src/main/kotlin/com/baeldung/operators/Point.kt @@ -1,3 +1,5 @@ +package com.baeldung.operators + data class Point(val x: Int, val y: Int) operator fun Point.unaryMinus() = Point(-x, -y) @@ -14,7 +16,7 @@ operator fun Point.times(factor: Int): Point = Point(x * factor, y * factor) operator fun Int.times(point: Point): Point = Point(point.x * this, point.y * this) class Shape { - private val points = mutableListOf() + val points = mutableListOf() operator fun Point.unaryPlus() { points.add(this) diff --git a/core-kotlin/src/main/kotlin/com/baeldung/operators/Utils.kt b/core-kotlin/src/main/kotlin/com/baeldung/operators/Utils.kt index ba33d3e7a2..0f16544f38 100644 --- a/core-kotlin/src/main/kotlin/com/baeldung/operators/Utils.kt +++ b/core-kotlin/src/main/kotlin/com/baeldung/operators/Utils.kt @@ -1,3 +1,5 @@ +package com.baeldung.operators + import java.math.BigInteger operator fun MutableCollection.plusAssign(element: T) { diff --git a/core-kotlin/src/test/kotlin/com/baeldung/operators/PageTest.kt b/core-kotlin/src/test/kotlin/com/baeldung/operators/PageTest.kt new file mode 100644 index 0000000000..4217fc0c08 --- /dev/null +++ b/core-kotlin/src/test/kotlin/com/baeldung/operators/PageTest.kt @@ -0,0 +1,28 @@ +package com.baeldung.operators + +import org.junit.Test +import kotlin.test.assertEquals +import kotlin.test.assertTrue + +class PageTest { + + private val page = PageImpl(1, 10, "Java", "Kotlin", "Scala") + + @Test + fun `Get convention should work as expected`() { + assertEquals(page[1], "Kotlin") + assertEquals(page[1, 3], listOf("Kotlin", "Scala")) + } + + @Test + fun `In convention should work on a page as expected`() { + assertTrue("Kotlin" in page) + } + +} + +private class PageImpl(val page: Int, val size: Int, vararg val elements: T) : Page { + override fun pageNumber(): Int = page + override fun pageSize(): Int = size + override fun elements(): MutableList = mutableListOf(*elements) +} \ No newline at end of file diff --git a/core-kotlin/src/test/kotlin/com/baeldung/operators/PointTest.kt b/core-kotlin/src/test/kotlin/com/baeldung/operators/PointTest.kt new file mode 100644 index 0000000000..168ab6431d --- /dev/null +++ b/core-kotlin/src/test/kotlin/com/baeldung/operators/PointTest.kt @@ -0,0 +1,48 @@ +package com.baeldung.operators + +import org.junit.Test +import kotlin.test.assertEquals +import kotlin.test.assertTrue + +class PointTest { + + private val p1 = Point(1, 2) + private val p2 = Point(2, 3) + + @Test + fun `We should be able to add two points together using +`() { + assertEquals(p1 + p2, Point(3, 5)) + } + + @Test + fun `We shoud be able to subtract one point from another using -`() { + assertEquals(p1 - p2, Point(-1, -1)) + } + + @Test + fun `We should be able to multiply two points together with *`() { + assertEquals(p1 * p2, Point(2, 6)) + } + + @Test + fun `We should be able to divide one point by another`() { + assertEquals(p1 / p2, Point(0, 0)) + } + + @Test + fun `We should be able to scale a point by an integral factor`() { + assertEquals(p1 * 2, Point(2, 4)) + assertEquals(2 * p1, Point(2, 4)) + } + + @Test + fun `We should be able to add points to an empty shape`() { + val line = shape { + +Point(0, 0) + +Point(1, 3) + } + + assertTrue(Point(0, 0) in line.points) + assertTrue(Point(1, 3) in line.points) + } +} \ No newline at end of file From ef74a2538e126eec8bec6e5b81d6ecd570454c12 Mon Sep 17 00:00:00 2001 From: Ali Dehghani Date: Thu, 29 Nov 2018 15:57:06 +0330 Subject: [PATCH 093/146] Added a few unit tests for kotlin operator examples. --- .../test/kotlin/com/baeldung/operators/UtilsTest.kt | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 core-kotlin/src/test/kotlin/com/baeldung/operators/UtilsTest.kt diff --git a/core-kotlin/src/test/kotlin/com/baeldung/operators/UtilsTest.kt b/core-kotlin/src/test/kotlin/com/baeldung/operators/UtilsTest.kt new file mode 100644 index 0000000000..4abe962cb5 --- /dev/null +++ b/core-kotlin/src/test/kotlin/com/baeldung/operators/UtilsTest.kt @@ -0,0 +1,13 @@ +package com.baeldung.operators + +import java.math.BigInteger +import org.junit.Test +import kotlin.test.assertEquals + +class UtilsTest { + + @Test + fun `We should be able to add an int value to an existing BigInteger using +`() { + assertEquals(BigInteger.ZERO + 1, BigInteger.ONE) + } +} \ No newline at end of file From f5b4a5e7023881474110c19e192246694b1bc99d Mon Sep 17 00:00:00 2001 From: Dionis Prifti Date: Thu, 29 Nov 2018 15:46:33 +0100 Subject: [PATCH 094/146] BAEL-2347: Added test examples for Coupound Assignment Operators. --- .../CompoundOperatorsTest.java | 111 ++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 core-java-lang/src/test/java/com/baeldung/compoundoperators/CompoundOperatorsTest.java diff --git a/core-java-lang/src/test/java/com/baeldung/compoundoperators/CompoundOperatorsTest.java b/core-java-lang/src/test/java/com/baeldung/compoundoperators/CompoundOperatorsTest.java new file mode 100644 index 0000000000..4a7833af95 --- /dev/null +++ b/core-java-lang/src/test/java/com/baeldung/compoundoperators/CompoundOperatorsTest.java @@ -0,0 +1,111 @@ +package com.baeldung.compoundoperators; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class CompoundOperatorsTest { + + @Test + public void whenAssignmentOperatorIsUsed_thenValueIsAssigned() { + int x = 5; + + assertEquals(5, x); + } + + @Test + public void whenCompoundAssignmentUsed_thenSameAsSimpleAssignment() { + int a = 3, b = 3, c = -2; + a = a * c; // Simple assignment operator + b *= c; // Compound assignment operator + + assertEquals(a, b); + } + + @Test + public void whenAssignmentOperatorIsUsed_thenValueIsReturned() { + long x = 5; + long y = (x=3); + + assertEquals(3, y); + assertEquals(y, x); + } + + @Test + public void whenCompoundOperatorsAreUsed_thenOperationsArePerformedAndAssigned() { + //Simple assignment + int x = 5; //x is 5 + + //Incrementation + x += 5; //x is 10 + assertEquals(10, x); + + //Decrementation + x -= 2; //x is 8 + assertEquals(8, x); + + //Multiplication + x *= 2; //x is 16 + assertEquals(16, x); + + //Division + x /= 4; //x is 4 + assertEquals(4, x); + + //Modulus + x %= 3; //x is 1 + assertEquals(1, x); + + + //Binary AND + x &= 4; //x is 0 + assertEquals(0, x); + + //Binary exclusive OR + x ^= 4; //x is 4 + assertEquals(4, x); + + //Binary inclusive OR + x |= 8; //x is 12 + assertEquals(12, x); + + + //Binary Left Shift + x <<= 2; //x is 48 + assertEquals(48, x); + + //Binary Right Shift + x >>= 2; //x is 12 + assertEquals(12, x); + + //Shift right zero fill + x >>>= 1; //x is 6 + assertEquals(6, x); + } + + @Test(expected = NullPointerException.class) + public void whenArrayIsNull_thenThrowNullException() { + int[] numbers = null; + + //Trying Incrementation + numbers[2] += 5; + } + + @Test(expected = ArrayIndexOutOfBoundsException.class) + public void whenArrayIndexNotCorrect_thenThrowArrayIndexException() { + int[] numbers = {0, 1}; + + //Trying Incrementation + numbers[2] += 5; + } + + @Test + public void whenArrayIndexIsCorrect_thenPerformOperation() { + int[] numbers = {0, 1}; + + //Incrementation + numbers[1] += 5; + assertEquals(6, numbers[1]); + } + +} From 7b3e306d2288022591f0f63ac89fbaad606253be Mon Sep 17 00:00:00 2001 From: Emily Cheyne Date: Thu, 29 Nov 2018 08:06:18 -0800 Subject: [PATCH 095/146] BAEL-2309 update readme --- core-java-lang/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-lang/README.md b/core-java-lang/README.md index 62af72818f..79d2375c24 100644 --- a/core-java-lang/README.md +++ b/core-java-lang/README.md @@ -57,4 +57,5 @@ - [“Sneaky Throws” in Java](http://www.baeldung.com/java-sneaky-throws) - [Inheritance and Composition (Is-a vs Has-a relationship) in Java](http://www.baeldung.com/java-inheritance-composition) - [A Guide to Constructors in Java](https://www.baeldung.com/java-constructors) +- [Retrieving a Class Name in Java](https://www.baeldung.com/java-class-name) From 5812866573fbd12890b909f88331b238974b509f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dar=C3=ADo=20Carrasquel?= Date: Thu, 29 Nov 2018 11:58:12 -0500 Subject: [PATCH 096/146] Ways to iterate over a list Issue: BAEL-2311 --- .../com/baeldung/java/list/WaysToIterate.java | 67 +++++++++++++++++ .../java/list/WaysToIterateUnitTest.java | 71 +++++++++++++++++++ 2 files changed, 138 insertions(+) create mode 100644 core-java-collections/src/main/java/com/baeldung/java/list/WaysToIterate.java create mode 100644 core-java-collections/src/test/java/com/baeldung/java/list/WaysToIterateUnitTest.java diff --git a/core-java-collections/src/main/java/com/baeldung/java/list/WaysToIterate.java b/core-java-collections/src/main/java/com/baeldung/java/list/WaysToIterate.java new file mode 100644 index 0000000000..3cce08eabb --- /dev/null +++ b/core-java-collections/src/main/java/com/baeldung/java/list/WaysToIterate.java @@ -0,0 +1,67 @@ +package com.baeldung.java.list; + +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; +import java.util.ListIterator; + +/** + * Demonstrates the different ways to loop over + * the elements of a list. + */ +public class WaysToIterate { + + List countries = Arrays.asList("Germany", "Panama", "Australia"); + + /** + * Iterate over a list using a basic for loop + */ + public void iterateWithForLoop() { + for (int i = 0; i < countries.size(); i++) { + System.out.println(countries.get(i)); + } + } + + /** + * Iterate over a list using the enhanced for loop + */ + public void iterateWithEnhancedForLoop() { + for (String country : countries) { + System.out.println(country); + } + } + + /** + * Iterate over a list using an Iterator + */ + public void iterateWithIterator() { + Iterator countriesIterator = countries.iterator(); + while(countriesIterator.hasNext()) { + System.out.println(countriesIterator.next()); + } + } + + /** + * Iterate over a list using a ListIterator + */ + public void iterateWithListIterator() { + ListIterator listIterator = countries.listIterator(); + while(listIterator.hasNext()) { + System.out.println(listIterator.next()); + } + } + + /** + * Iterate over a list using the Iterable.forEach() method + */ + public void iterateWithForEach() { + countries.forEach(System.out::println); + } + + /** + * Iterate over a list using the Stream.forEach() method + */ + public void iterateWithStreamForEach() { + countries.stream().forEach((c) -> System.out.println(c)); + } +} \ No newline at end of file diff --git a/core-java-collections/src/test/java/com/baeldung/java/list/WaysToIterateUnitTest.java b/core-java-collections/src/test/java/com/baeldung/java/list/WaysToIterateUnitTest.java new file mode 100644 index 0000000000..973c60b233 --- /dev/null +++ b/core-java-collections/src/test/java/com/baeldung/java/list/WaysToIterateUnitTest.java @@ -0,0 +1,71 @@ +package com.baeldung.java.list; + +import static org.junit.Assert.assertEquals; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; +import java.util.ListIterator; + +import org.junit.Test; + +public class WaysToIterateUnitTest { + + List globalCountries = new ArrayList(); + List europeanCountries = Arrays.asList("Germany", "Panama", "Australia"); + + @Test + public void whenIteratingUsingForLoop_thenReturnThreeAsSizeOfList() { + for (int i = 0; i < europeanCountries.size(); i++) { + globalCountries.add(europeanCountries.get(i)); + } + assertEquals(globalCountries.size(), 3); + globalCountries.clear(); + } + + @Test + public void whenIteratingUsingEnhancedForLoop_thenReturnThreeAsSizeOfList() { + for (String country : europeanCountries) { + globalCountries.add(country); + } + assertEquals(globalCountries.size(), 3); + globalCountries.clear(); + } + + @Test + public void whenIteratingUsingIterator_thenReturnThreeAsSizeOfList() { + Iterator countriesIterator = europeanCountries.iterator(); + while (countriesIterator.hasNext()) { + globalCountries.add(countriesIterator.next()); + } + + assertEquals(globalCountries.size(), 3); + globalCountries.clear(); + } + + @Test + public void whenIteratingUsingListIterator_thenReturnThreeAsSizeOfList() { + ListIterator countriesIterator = europeanCountries.listIterator(); + while (countriesIterator.hasNext()) { + globalCountries.add(countriesIterator.next()); + } + + assertEquals(globalCountries.size(), 3); + globalCountries.clear(); + } + + @Test + public void whenIteratingUsingForEach_thenReturnThreeAsSizeOfList() { + europeanCountries.forEach(country -> globalCountries.add(country)); + assertEquals(globalCountries.size(), 3); + globalCountries.clear(); + } + + @Test + public void whenIteratingUsingStreamForEach_thenReturnThreeAsSizeOfList() { + europeanCountries.stream().forEach((country) -> globalCountries.add(country)); + assertEquals(globalCountries.size(), 3); + globalCountries.clear(); + } +} \ No newline at end of file From 3b42c4882005976595e55d9eb2239133859e4a34 Mon Sep 17 00:00:00 2001 From: Dionis Prifti Date: Thu, 29 Nov 2018 21:05:59 +0100 Subject: [PATCH 097/146] BAEL-2347: Fixed test about return value of assignment operator. --- .../com/baeldung/compoundoperators/CompoundOperatorsTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core-java-lang/src/test/java/com/baeldung/compoundoperators/CompoundOperatorsTest.java b/core-java-lang/src/test/java/com/baeldung/compoundoperators/CompoundOperatorsTest.java index 4a7833af95..3b3478b38e 100644 --- a/core-java-lang/src/test/java/com/baeldung/compoundoperators/CompoundOperatorsTest.java +++ b/core-java-lang/src/test/java/com/baeldung/compoundoperators/CompoundOperatorsTest.java @@ -24,8 +24,8 @@ public class CompoundOperatorsTest { @Test public void whenAssignmentOperatorIsUsed_thenValueIsReturned() { - long x = 5; - long y = (x=3); + long x = 1; + long y = (x+=2); assertEquals(3, y); assertEquals(y, x); From 97fe04aace59891d3746cf60d46929608053d12d Mon Sep 17 00:00:00 2001 From: Eugen Paraschiv Date: Thu, 29 Nov 2018 23:30:46 +0200 Subject: [PATCH 098/146] reenabling some modules --- pom.xml | 33 ++++++++++----------------------- 1 file changed, 10 insertions(+), 23 deletions(-) diff --git a/pom.xml b/pom.xml index 35a2de9a45..8fa93373fc 100644 --- a/pom.xml +++ b/pom.xml @@ -637,7 +637,7 @@ dubbo persistence-modules/flyway - + JGit jni jooby @@ -662,24 +662,13 @@ sse-jaxrs static-analysis stripe - + structurizr Twitter4J wicket xstream cas/cas-secured-app cas/cas-server - - - - - - - - - - - - + graphql/graphql-java @@ -687,9 +676,6 @@ spring-boot-custom-starter/greeter persistence-modules/spring-boot-h2/spring-boot-h2-database - - - flyway-cdi-extension spring-security-acl @@ -711,7 +697,7 @@ spring-security-mvc-session spring-security-mvc-socket spring-security-openid - + spring-security-react spring-security-rest-basic-auth spring-security-rest-custom spring-security-rest @@ -734,8 +720,8 @@ spring-rest-angular spring-rest-full spring-rest-query-language - - + spring-rest + spring-rest-simple spring-resttemplate helidon @@ -1030,7 +1016,7 @@ jackson java-strings - + java-collections-conversions java-collections-maps java-streams @@ -1114,9 +1100,10 @@ rabbitmq - persistence-modules/spring-data-mongodb - --> From 71f76d28ccddb5780254968c81a2810818f8e9ae Mon Sep 17 00:00:00 2001 From: Emily Cheyne Date: Thu, 29 Nov 2018 16:15:20 -0800 Subject: [PATCH 099/146] BAEL-2279 update readme --- spring-5-reactive/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-5-reactive/README.md b/spring-5-reactive/README.md index 267925b798..4fab0c12ad 100644 --- a/spring-5-reactive/README.md +++ b/spring-5-reactive/README.md @@ -16,3 +16,4 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [Server-Sent Events in Spring](https://www.baeldung.com/spring-server-sent-events) - [A Guide to Spring Session Reactive Support: WebSession](https://www.baeldung.com/spring-session-reactive) - [Validation for Functional Endpoints in Spring 5](https://www.baeldung.com/spring-functional-endpoints-validation) +- [Logging a Reactive Sequence](https://www.baeldung.com/spring-reactive-sequence-logging) From 02fc56c41bd5004bef4d2d4c091eccde2a341285 Mon Sep 17 00:00:00 2001 From: Kevin Gilmore Date: Thu, 29 Nov 2018 20:54:00 -0600 Subject: [PATCH 100/146] BAEL-2354: add link back to article --- cdi/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/cdi/README.md b/cdi/README.md index 0477ce85bd..1523aacf6b 100644 --- a/cdi/README.md +++ b/cdi/README.md @@ -1,3 +1,4 @@ ### Relevant Articles: - [CDI Interceptor vs Spring AspectJ](http://www.baeldung.com/cdi-interceptor-vs-spring-aspectj) - [An Introduction to CDI (Contexts and Dependency Injection) in Java](http://www.baeldung.com/java-ee-cdi) +- [Introduction to the Event Notification Model in CDI 2.0](https://www.baeldung.com/cdi-event-notification) From f4c5f8b8ae250190defaabe7df9c832a3a80659a Mon Sep 17 00:00:00 2001 From: raghav-jha Date: Fri, 30 Nov 2018 11:40:11 +0530 Subject: [PATCH 101/146] JPA One-To-One Association Tutorial Issue: BAEL-2394 --- .../hibernate/onetoone/HibernateUtil.java | 38 +++++++++ .../baeldung/hibernate/onetoone/Strategy.java | 25 ++++++ .../onetoone/foreignkeybased/Address.java | 60 ++++++++++++++ .../onetoone/foreignkeybased/User.java | 51 ++++++++++++ .../onetoone/jointablebased/Employee.java | 53 ++++++++++++ .../onetoone/jointablebased/WorkStation.java | 61 ++++++++++++++ .../onetoone/sharedkeybased/Address.java | 60 ++++++++++++++ .../onetoone/sharedkeybased/User.java | 50 ++++++++++++ .../src/main/resources/one-to-one.cfg.xml | 16 ++++ ...ToOneAnnotationFKBasedIntegrationTest.java | 80 +++++++++++++++++++ ...ToOneAnnotationJTBasedIntegrationTest.java | 80 +++++++++++++++++++ ...oOneAnnotationSPKBasedIntegrationTest.java | 79 ++++++++++++++++++ .../src/test/resources/one-to-one.cfg.xml | 16 ++++ 13 files changed, 669 insertions(+) create mode 100644 persistence-modules/spring-hibernate-5/src/main/java/com/baeldung/hibernate/onetoone/HibernateUtil.java create mode 100644 persistence-modules/spring-hibernate-5/src/main/java/com/baeldung/hibernate/onetoone/Strategy.java create mode 100644 persistence-modules/spring-hibernate-5/src/main/java/com/baeldung/hibernate/onetoone/foreignkeybased/Address.java create mode 100644 persistence-modules/spring-hibernate-5/src/main/java/com/baeldung/hibernate/onetoone/foreignkeybased/User.java create mode 100644 persistence-modules/spring-hibernate-5/src/main/java/com/baeldung/hibernate/onetoone/jointablebased/Employee.java create mode 100644 persistence-modules/spring-hibernate-5/src/main/java/com/baeldung/hibernate/onetoone/jointablebased/WorkStation.java create mode 100644 persistence-modules/spring-hibernate-5/src/main/java/com/baeldung/hibernate/onetoone/sharedkeybased/Address.java create mode 100644 persistence-modules/spring-hibernate-5/src/main/java/com/baeldung/hibernate/onetoone/sharedkeybased/User.java create mode 100644 persistence-modules/spring-hibernate-5/src/main/resources/one-to-one.cfg.xml create mode 100644 persistence-modules/spring-hibernate-5/src/test/java/com/baeldung/hibernate/onetoone/HibernateOneToOneAnnotationFKBasedIntegrationTest.java create mode 100644 persistence-modules/spring-hibernate-5/src/test/java/com/baeldung/hibernate/onetoone/HibernateOneToOneAnnotationJTBasedIntegrationTest.java create mode 100644 persistence-modules/spring-hibernate-5/src/test/java/com/baeldung/hibernate/onetoone/HibernateOneToOneAnnotationSPKBasedIntegrationTest.java create mode 100644 persistence-modules/spring-hibernate-5/src/test/resources/one-to-one.cfg.xml diff --git a/persistence-modules/spring-hibernate-5/src/main/java/com/baeldung/hibernate/onetoone/HibernateUtil.java b/persistence-modules/spring-hibernate-5/src/main/java/com/baeldung/hibernate/onetoone/HibernateUtil.java new file mode 100644 index 0000000000..899fcde947 --- /dev/null +++ b/persistence-modules/spring-hibernate-5/src/main/java/com/baeldung/hibernate/onetoone/HibernateUtil.java @@ -0,0 +1,38 @@ +package com.baeldung.hibernate.onetoone; + +import org.hibernate.SessionFactory; +import org.hibernate.boot.registry.StandardServiceRegistryBuilder; +import org.hibernate.cfg.Configuration; +import org.hibernate.service.ServiceRegistry; + +public class HibernateUtil { + private static SessionFactory sessionFactory; + + private static SessionFactory buildSessionFactory(Strategy strategy) { + try { + // Create the SessionFactory from hibernate-annotation.cfg.xml + Configuration configuration = new Configuration(); + + for (Class entityClass : strategy.getEntityClasses()) { + configuration.addAnnotatedClass(entityClass); + } + configuration.configure("one-to-one.cfg.xml"); + + ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()) + .build(); + + SessionFactory sessionFactory = configuration.buildSessionFactory(serviceRegistry); + + return sessionFactory; + } catch (Throwable ex) { + ex.printStackTrace(); + throw new ExceptionInInitializerError(ex); + } + } + + public static SessionFactory getSessionFactory(Strategy strategy) { + if (sessionFactory == null) + sessionFactory = buildSessionFactory(strategy); + return sessionFactory; + } +} diff --git a/persistence-modules/spring-hibernate-5/src/main/java/com/baeldung/hibernate/onetoone/Strategy.java b/persistence-modules/spring-hibernate-5/src/main/java/com/baeldung/hibernate/onetoone/Strategy.java new file mode 100644 index 0000000000..3180566ca5 --- /dev/null +++ b/persistence-modules/spring-hibernate-5/src/main/java/com/baeldung/hibernate/onetoone/Strategy.java @@ -0,0 +1,25 @@ +package com.baeldung.hibernate.onetoone; + + +import java.util.Arrays; +import java.util.List; + +public enum Strategy { + //See that the classes belongs to different packages + FOREIGN_KEY(Arrays.asList(com.baeldung.hibernate.onetoone.foreignkeybased.User.class, + com.baeldung.hibernate.onetoone.foreignkeybased.Address.class)), + SHARED_PRIMARY_KEY(Arrays.asList(com.baeldung.hibernate.onetoone.sharedkeybased.User.class, + com.baeldung.hibernate.onetoone.sharedkeybased.Address.class)), + JOIN_TABLE_BASED(Arrays.asList(com.baeldung.hibernate.onetoone.jointablebased.Employee.class, + com.baeldung.hibernate.onetoone.jointablebased.WorkStation.class)); + + private List> entityClasses; + + Strategy(List> entityClasses) { + this.entityClasses = entityClasses; + } + + public List> getEntityClasses() { + return entityClasses; + } +} diff --git a/persistence-modules/spring-hibernate-5/src/main/java/com/baeldung/hibernate/onetoone/foreignkeybased/Address.java b/persistence-modules/spring-hibernate-5/src/main/java/com/baeldung/hibernate/onetoone/foreignkeybased/Address.java new file mode 100644 index 0000000000..e05eb46030 --- /dev/null +++ b/persistence-modules/spring-hibernate-5/src/main/java/com/baeldung/hibernate/onetoone/foreignkeybased/Address.java @@ -0,0 +1,60 @@ +package com.baeldung.hibernate.onetoone.foreignkeybased; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.OneToOne; +import javax.persistence.Table; + +@Entity +@Table(name = "address") +public class Address { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name = "id") + private Long id; + + @Column(name = "street") + private String street; + + @Column(name = "city") + private String city; + + @OneToOne(mappedBy = "address") + private User user; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getStreet() { + return street; + } + + public void setStreet(String street) { + this.street = street; + } + + public String getCity() { + return city; + } + + public void setCity(String city) { + this.city = city; + } + + public User getUser() { + return user; + } + + public void setUser(User user) { + this.user = user; + } +} diff --git a/persistence-modules/spring-hibernate-5/src/main/java/com/baeldung/hibernate/onetoone/foreignkeybased/User.java b/persistence-modules/spring-hibernate-5/src/main/java/com/baeldung/hibernate/onetoone/foreignkeybased/User.java new file mode 100644 index 0000000000..56b108d0d1 --- /dev/null +++ b/persistence-modules/spring-hibernate-5/src/main/java/com/baeldung/hibernate/onetoone/foreignkeybased/User.java @@ -0,0 +1,51 @@ +package com.baeldung.hibernate.onetoone.foreignkeybased; + +import javax.persistence.CascadeType; +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.OneToOne; +import javax.persistence.Table; + +@Entity +@Table(name = "users") +public class User { + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name = "id") + private Long id; + + @Column(name = "username") + private String userName; + + @OneToOne(cascade = CascadeType.ALL) + @JoinColumn(name = "address_id", referencedColumnName = "id") + private Address address; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getUserName() { + return userName; + } + + public void setUserName(String userName) { + this.userName = userName; + } + + public Address getAddress() { + return address; + } + + public void setAddress(Address address) { + this.address = address; + } +} diff --git a/persistence-modules/spring-hibernate-5/src/main/java/com/baeldung/hibernate/onetoone/jointablebased/Employee.java b/persistence-modules/spring-hibernate-5/src/main/java/com/baeldung/hibernate/onetoone/jointablebased/Employee.java new file mode 100644 index 0000000000..a0bc101b9f --- /dev/null +++ b/persistence-modules/spring-hibernate-5/src/main/java/com/baeldung/hibernate/onetoone/jointablebased/Employee.java @@ -0,0 +1,53 @@ +package com.baeldung.hibernate.onetoone.jointablebased; + +import javax.persistence.CascadeType; +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.JoinTable; +import javax.persistence.OneToOne; +import javax.persistence.Table; + +@Entity +@Table(name = "employee") +public class Employee { + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name = "id") + private Long id; + + @Column(name = "ename") + private String name; + + @OneToOne(cascade = CascadeType.ALL) + @JoinTable(name = "emp_workstation", joinColumns = {@JoinColumn(name = "employee_id", referencedColumnName = "id")}, + inverseJoinColumns = {@JoinColumn(name = "workstation_id", referencedColumnName = "id")}) + private WorkStation workStation; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public WorkStation getWorkStation() { + return workStation; + } + + public void setWorkStation(WorkStation workStation) { + this.workStation = workStation; + } +} diff --git a/persistence-modules/spring-hibernate-5/src/main/java/com/baeldung/hibernate/onetoone/jointablebased/WorkStation.java b/persistence-modules/spring-hibernate-5/src/main/java/com/baeldung/hibernate/onetoone/jointablebased/WorkStation.java new file mode 100644 index 0000000000..f530611f6e --- /dev/null +++ b/persistence-modules/spring-hibernate-5/src/main/java/com/baeldung/hibernate/onetoone/jointablebased/WorkStation.java @@ -0,0 +1,61 @@ +package com.baeldung.hibernate.onetoone.jointablebased; + + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.OneToOne; +import javax.persistence.Table; + +@Entity +@Table(name = "workstation") +public class WorkStation { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name = "id") + private Long id; + + @Column(name = "workstation_number") + private Integer workstationNumber; + + @Column(name = "floor") + private String floor; + + @OneToOne(mappedBy = "workStation") + private Employee employee; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Integer getWorkstationNumber() { + return workstationNumber; + } + + public void setWorkstationNumber(Integer workstationNumber) { + this.workstationNumber = workstationNumber; + } + + public String getFloor() { + return floor; + } + + public void setFloor(String floor) { + this.floor = floor; + } + + public Employee getEmployee() { + return employee; + } + + public void setEmployee(Employee employee) { + this.employee = employee; + } +} \ No newline at end of file diff --git a/persistence-modules/spring-hibernate-5/src/main/java/com/baeldung/hibernate/onetoone/sharedkeybased/Address.java b/persistence-modules/spring-hibernate-5/src/main/java/com/baeldung/hibernate/onetoone/sharedkeybased/Address.java new file mode 100644 index 0000000000..927516f6bb --- /dev/null +++ b/persistence-modules/spring-hibernate-5/src/main/java/com/baeldung/hibernate/onetoone/sharedkeybased/Address.java @@ -0,0 +1,60 @@ +package com.baeldung.hibernate.onetoone.sharedkeybased; + + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.MapsId; +import javax.persistence.OneToOne; +import javax.persistence.Table; + +@Entity +@Table(name = "address") +public class Address { + + @Id + @Column(name = "id") + private Long id; + + @Column(name = "street") + private String street; + + @Column(name = "city") + private String city; + + @OneToOne + @MapsId + private User user; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getStreet() { + return street; + } + + public void setStreet(String street) { + this.street = street; + } + + public String getCity() { + return city; + } + + public void setCity(String city) { + this.city = city; + } + + public User getUser() { + return user; + } + + public void setUser(User user) { + this.user = user; + } +} diff --git a/persistence-modules/spring-hibernate-5/src/main/java/com/baeldung/hibernate/onetoone/sharedkeybased/User.java b/persistence-modules/spring-hibernate-5/src/main/java/com/baeldung/hibernate/onetoone/sharedkeybased/User.java new file mode 100644 index 0000000000..fa00db1271 --- /dev/null +++ b/persistence-modules/spring-hibernate-5/src/main/java/com/baeldung/hibernate/onetoone/sharedkeybased/User.java @@ -0,0 +1,50 @@ +package com.baeldung.hibernate.onetoone.sharedkeybased; + + +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.OneToOne; +import javax.persistence.Table; + +@Entity +@Table(name = "users") +public class User { + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name = "id") + private Long id; + + @Column(name = "username") + private String userName; + + @OneToOne(mappedBy = "user", cascade = CascadeType.ALL) + private Address address; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getUserName() { + return userName; + } + + public void setUserName(String userName) { + this.userName = userName; + } + + public Address getAddress() { + return address; + } + + public void setAddress(Address address) { + this.address = address; + } +} diff --git a/persistence-modules/spring-hibernate-5/src/main/resources/one-to-one.cfg.xml b/persistence-modules/spring-hibernate-5/src/main/resources/one-to-one.cfg.xml new file mode 100644 index 0000000000..7522036acb --- /dev/null +++ b/persistence-modules/spring-hibernate-5/src/main/resources/one-to-one.cfg.xml @@ -0,0 +1,16 @@ + + + + + org.h2.Driver + + jdbc:h2:mem:spring_hibernate_one_to_one + sa + org.hibernate.dialect.H2Dialect + thread + true + create-drop + + \ No newline at end of file diff --git a/persistence-modules/spring-hibernate-5/src/test/java/com/baeldung/hibernate/onetoone/HibernateOneToOneAnnotationFKBasedIntegrationTest.java b/persistence-modules/spring-hibernate-5/src/test/java/com/baeldung/hibernate/onetoone/HibernateOneToOneAnnotationFKBasedIntegrationTest.java new file mode 100644 index 0000000000..475c93f6ff --- /dev/null +++ b/persistence-modules/spring-hibernate-5/src/test/java/com/baeldung/hibernate/onetoone/HibernateOneToOneAnnotationFKBasedIntegrationTest.java @@ -0,0 +1,80 @@ +package com.baeldung.hibernate.onetoone; + +import com.baeldung.hibernate.onetoone.foreignkeybased.Address; +import com.baeldung.hibernate.onetoone.foreignkeybased.User; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +public class HibernateOneToOneAnnotationFKBasedIntegrationTest { + + private static SessionFactory sessionFactory; + + private Session session; + + @BeforeClass + public static void beforeTests() { + sessionFactory = HibernateUtil.getSessionFactory(Strategy.FOREIGN_KEY); + } + + @Before + public void setUp() { + session = sessionFactory.openSession(); + session.beginTransaction(); + } + + @Test + public void givenData_whenInsert_thenCreates1to1relationship() { + User user = new User(); + user.setUserName("alice@baeldung.com"); + + Address address = new Address(); + address.setStreet("FK Street"); + address.setCity("FK City"); + + address.setUser(user); + user.setAddress(address); + + //Address entry will automatically be created by hibernate, since cascade type is specified as ALL + session.persist(user); + session.getTransaction().commit(); + + assert1to1InsertedData(); + } + + private void assert1to1InsertedData() { + @SuppressWarnings("unchecked") + List userList = session.createQuery("FROM User").list(); + + assertNotNull(userList); + assertEquals(1, userList.size()); + + User user = userList.get(0); + assertEquals("alice@baeldung.com", user.getUserName()); + + Address address = user.getAddress(); + assertNotNull(address); + assertEquals("FK Street", address.getStreet()); + assertEquals("FK City", address.getCity()); + + } + + @After + public void tearDown() { + session.close(); + } + + @AfterClass + public static void afterTests() { + sessionFactory.close(); + } +} diff --git a/persistence-modules/spring-hibernate-5/src/test/java/com/baeldung/hibernate/onetoone/HibernateOneToOneAnnotationJTBasedIntegrationTest.java b/persistence-modules/spring-hibernate-5/src/test/java/com/baeldung/hibernate/onetoone/HibernateOneToOneAnnotationJTBasedIntegrationTest.java new file mode 100644 index 0000000000..df4cd4d137 --- /dev/null +++ b/persistence-modules/spring-hibernate-5/src/test/java/com/baeldung/hibernate/onetoone/HibernateOneToOneAnnotationJTBasedIntegrationTest.java @@ -0,0 +1,80 @@ +package com.baeldung.hibernate.onetoone; + +import com.baeldung.hibernate.onetoone.jointablebased.Employee; +import com.baeldung.hibernate.onetoone.jointablebased.WorkStation; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +public class HibernateOneToOneAnnotationJTBasedIntegrationTest { + + private static SessionFactory sessionFactory; + + private Session session; + + @BeforeClass + public static void beforeTests() { + sessionFactory = HibernateUtil.getSessionFactory(Strategy.JOIN_TABLE_BASED); + } + + @Before + public void setUp() { + session = sessionFactory.openSession(); + session.beginTransaction(); + } + + @Test + public void givenData_whenInsert_thenCreates1to1relationship() { + Employee employee = new Employee(); + employee.setName("bob@baeldung.com"); + + WorkStation workStation = new WorkStation(); + workStation.setWorkstationNumber(626); + workStation.setFloor("Sixth Floor"); + + + employee.setWorkStation(workStation); + workStation.setEmployee(employee); + + session.persist(employee); + session.getTransaction().commit(); + + assert1to1InsertedData(); + } + + private void assert1to1InsertedData() { + @SuppressWarnings("unchecked") + List employeeList = session.createQuery("FROM Employee").list(); + assertNotNull(employeeList); + assertEquals(1, employeeList.size()); + + Employee employee = employeeList.get(0); + assertEquals("bob@baeldung.com", employee.getName()); + + WorkStation workStation = employee.getWorkStation(); + + assertNotNull(workStation); + assertEquals((long) 626, (long) workStation.getWorkstationNumber()); + assertEquals("Sixth Floor", workStation.getFloor()); + + } + + @After + public void tearDown() { + session.close(); + } + + @AfterClass + public static void afterTests() { + sessionFactory.close(); + } +} diff --git a/persistence-modules/spring-hibernate-5/src/test/java/com/baeldung/hibernate/onetoone/HibernateOneToOneAnnotationSPKBasedIntegrationTest.java b/persistence-modules/spring-hibernate-5/src/test/java/com/baeldung/hibernate/onetoone/HibernateOneToOneAnnotationSPKBasedIntegrationTest.java new file mode 100644 index 0000000000..7931a8e3fe --- /dev/null +++ b/persistence-modules/spring-hibernate-5/src/test/java/com/baeldung/hibernate/onetoone/HibernateOneToOneAnnotationSPKBasedIntegrationTest.java @@ -0,0 +1,79 @@ +package com.baeldung.hibernate.onetoone; + +import com.baeldung.hibernate.onetoone.sharedkeybased.Address; +import com.baeldung.hibernate.onetoone.sharedkeybased.User; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +public class HibernateOneToOneAnnotationSPKBasedIntegrationTest { + + private static SessionFactory sessionFactory; + + private Session session; + + @BeforeClass + public static void beforeTests() { + sessionFactory = HibernateUtil.getSessionFactory(Strategy.SHARED_PRIMARY_KEY); + } + + @Before + public void setUp() { + session = sessionFactory.openSession(); + session.beginTransaction(); + } + + @Test + public void givenData_whenInsert_thenCreates1to1relationship() { + User user = new User(); + user.setUserName("alice@baeldung.com"); + + Address address = new Address(); + address.setStreet("SPK Street"); + address.setCity("SPK City"); + + address.setUser(user); + user.setAddress(address); + + //Address entry will automatically be created by hibernate, since cascade type is specified as ALL + session.persist(user); + session.getTransaction().commit(); + + assert1to1InsertedData(); + } + + + private void assert1to1InsertedData() { + @SuppressWarnings("unchecked") + List userList = session.createQuery("FROM User").list(); + assertNotNull(userList); + assertEquals(1, userList.size()); + + User user = userList.get(0); + assertEquals("alice@baeldung.com", user.getUserName()); + + Address address = user.getAddress(); + assertNotNull(address); + assertEquals("SPK Street", address.getStreet()); + assertEquals("SPK City", address.getCity()); + } + + @After + public void tearDown() { + session.close(); + } + + @AfterClass + public static void afterTests() { + sessionFactory.close(); + } +} diff --git a/persistence-modules/spring-hibernate-5/src/test/resources/one-to-one.cfg.xml b/persistence-modules/spring-hibernate-5/src/test/resources/one-to-one.cfg.xml new file mode 100644 index 0000000000..60417e312d --- /dev/null +++ b/persistence-modules/spring-hibernate-5/src/test/resources/one-to-one.cfg.xml @@ -0,0 +1,16 @@ + + + + + org.h2.Driver + + jdbc:h2:mem:spring_hibernate_one_to_one + sa + org.hibernate.dialect.H2Dialect + thread + true + create-drop + + From ee6162e04b5394ce234c3e8c0cdd283bf26fa989 Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Fri, 30 Nov 2018 09:05:42 +0200 Subject: [PATCH 102/146] Update README.md (#5794) --- patterns/design-patterns/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/patterns/design-patterns/README.md b/patterns/design-patterns/README.md index ae372bd460..e56872b3fd 100644 --- a/patterns/design-patterns/README.md +++ b/patterns/design-patterns/README.md @@ -13,3 +13,4 @@ - [Interpreter Design Pattern in Java](http://www.baeldung.com/java-interpreter-pattern) - [State Design Pattern in Java](https://www.baeldung.com/java-state-design-pattern) - [The Decorator Pattern in Java](https://www.baeldung.com/java-decorator-pattern) +- [Abstract Factory Pattern in Java](https://www.baeldung.com/java-abstract-factory-pattern) From e98f2f4f605f8fb805609bbe6ecb664c699e3b57 Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Fri, 30 Nov 2018 10:27:43 +0200 Subject: [PATCH 103/146] Update README.md --- core-java-lang/README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/core-java-lang/README.md b/core-java-lang/README.md index 79d2375c24..607abbcdc5 100644 --- a/core-java-lang/README.md +++ b/core-java-lang/README.md @@ -58,4 +58,3 @@ - [Inheritance and Composition (Is-a vs Has-a relationship) in Java](http://www.baeldung.com/java-inheritance-composition) - [A Guide to Constructors in Java](https://www.baeldung.com/java-constructors) - [Retrieving a Class Name in Java](https://www.baeldung.com/java-class-name) - From 30bbc946d203b16c81b21c7bdbf4d12714a87830 Mon Sep 17 00:00:00 2001 From: Eugen Paraschiv Date: Fri, 30 Nov 2018 12:06:24 +0200 Subject: [PATCH 104/146] pom cleanup --- pom.xml | 1043 +++++++++++++++++-------------------------------------- 1 file changed, 316 insertions(+), 727 deletions(-) diff --git a/pom.xml b/pom.xml index 8fa93373fc..d149e07f57 100644 --- a/pom.xml +++ b/pom.xml @@ -323,207 +323,164 @@ parent-boot-1 - parent-boot-2 - parent-spring-4 - parent-spring-5 - parent-java - parent-kotlin - asm - atomix - persistence-modules/apache-cayenne - aws - aws-lambda - akka-streams - algorithms-genetic - algorithms-miscellaneous-1 - algorithms-miscellaneous-2 - algorithms-sorting - annotations - apache-cxf - apache-fop - apache-geode - apache-poi - apache-tika - apache-thrift - apache-curator - apache-zookeeper - apache-opennlp - autovalue - axon - azure - bootique - cdi - java-strings - - core-java - core-java-lang - core-java-arrays - core-java-collections - java-collections-conversions - java-collections-maps - core-java-io - core-java-8 - java-streams - persistence-modules/core-java-persistence - core-kotlin - kotlin-libraries - core-groovy - core-java-concurrency - core-java-concurrency-collections - couchbase - persistence-modules/deltaspike - dozer - ethereum - feign - flips - testing-modules/groovy-spock - testing-modules/load-testing-comparison - google-cloud - google-web-toolkit - gson - guava - guava-collections - guava-modules/guava-18 - guava-modules/guava-19 - guava-modules/guava-21 - guice - disruptor - core-scala - spring-static-resources - hazelcast - persistence-modules/hbase - persistence-modules/hibernate5 - httpclient - hystrix - image-processing - immutables - persistence-modules/influxdb - jackson - persistence-modules/java-cassandra - vavr - java-lite - java-numbers - java-rmi - java-vavr-stream - javax-servlets - javaxval - jaxb - javafx - jgroups - jee-7 - jee-7-security - jhipster - jjwt - jsf - json-path - json - jsoup - testing-modules/junit-5 - - libraries - libraries-data - libraries-security - libraries-server - linkrest - logging-modules/log-mdc - logging-modules/log4j - logging-modules/log4j2 - logging-modules/logback - lombok - mapstruct - metrics - maven - mesos-marathon - msf4j - testing-modules/mockito - testing-modules/mockito-2 - testing-modules/mocks - mustache - mvn-wrapper - noexception - persistence-modules/orientdb - osgi - orika - patterns - pdf - protobuffer - persistence-modules/querydsl - reactor-core - persistence-modules/redis - testing-modules/rest-assured - testing-modules/rest-testing - resteasy - rxjava - rxjava-2 - spring-swagger-codegen - testing-modules/selenium-junit-testng - persistence-modules/solr - spark-java - spring-4 - spring-5 - spring-5-data-reactive - spring-5-reactive - spring-5-reactive-security - spring-5-reactive-client - spring-5-mvc - spring-5-security - spring-5-security-oauth - spring-5-reactive-oauth - spring-activiti - spring-akka - spring-amqp - spring-all - spring-amqp-simple - spring-apache-camel - spring-batch - spring-bom - spring-boot - spring-boot-client - spring-boot-keycloak - spring-boot-bootstrap - spring-boot-admin - spring-boot-camel - spring-boot-ops - persistence-modules/spring-boot-persistence - spring-boot-security - spring-boot-mvc - spring-boot-vue - spring-boot-logging-log4j2 - spring-boot-disable-console-logging - spring-cloud-data-flow - spring-cloud - spring-cloud-bus - spring-core - spring-cucumber - spring-ejb - spring-aop - persistence-modules/spring-data-cassandra - persistence-modules/spring-data-couchbase-2 - persistence-modules/spring-data-dynamodb - persistence-modules/spring-data-elasticsearch - persistence-modules/spring-data-jpa - persistence-modules/spring-data-keyvalue - persistence-modules/spring-data-mongodb - persistence-modules/spring-data-neo4j - persistence-modules/spring-data-redis - spring-data-rest - persistence-modules/spring-data-solr - spring-dispatcher-servlet - spring-exceptions - spring-freemarker - persistence-modules/spring-hibernate-3 - persistence-modules/spring-hibernate4 - persistence-modules/spring-hibernate-5 - persistence-modules/spring-data-eclipselink - spring-integration - spring-jenkins-pipeline - spring-jersey - jmeter - spring-jms - spring-jooq - persistence-modules/spring-jpa - ddd - + parent-boot-2 + parent-spring-4 + parent-spring-5 + parent-java + parent-kotlin + + asm + atomix + aws + aws-lambda + akka-streams + algorithms-genetic + algorithms-miscellaneous-1 + algorithms-miscellaneous-2 + algorithms-sorting + annotations + apache-cxf + apache-fop + apache-poi + apache-tika + apache-thrift + apache-curator + apache-zookeeper + apache-opennlp + autovalue + axon + azure + apache-velocity + apache-solrj + apache-meecrowave + antlr + + bootique + + cdi + core-java-collections + core-java-io + core-java-8 + core-groovy + couchbase + + dozer + disruptor + drools + deeplearning4j + + ethereum + + feign + flips + + google-cloud + gson + guava + guava-collections + guava-modules/guava-18 + guava-modules/guava-19 + guava-modules/guava-21 + guice + + hazelcast + hystrix + httpclient + + image-processing + immutables + + jackson + java-strings + + java-collections-conversions + java-collections-maps + java-streams + java-lite + java-numbers + java-rmi + java-vavr-stream + javax-servlets + javaxval + jaxb + javafx + jgroups + jee-7 + jee-7-security + jjwt + jsf + json-path + json + jsoup + jta + jws + jersey + java-spi + java-ee-8-security-api + + libraries-data + linkrest + logging-modules/log-mdc + logging-modules/log4j + logging-modules/logback + lombok + lucene + + mapstruct + maven + mesos-marathon + msf4j + mustache + mvn-wrapper + mybatis + metrics + maven-archetype + + noexception + + osgi + orika + + patterns + pdf + protobuffer + performance-tests + + persistence-modules/java-jdbi + persistence-modules/redis + persistence-modules/orientdb + persistence-modules/querydsl + persistence-modules/apache-cayenne + persistence-modules/solr + persistence-modules/spring-data-dynamodb + persistence-modules/spring-data-keyvalue + persistence-modules/spring-data-neo4j + persistence-modules/spring-data-solr + persistence-modules/spring-hibernate-5 + persistence-modules/spring-data-eclipselink + persistence-modules/spring-jpa + persistence-modules/spring-hibernate-3 + persistence-modules/spring-data-gemfire + persistence-modules/spring-boot-persistence + persistence-modules/liquibase + persistence-modules/java-cockroachdb + persistence-modules/deltaspike + persistence-modules/hbase + persistence-modules/influxdb + persistence-modules/spring-hibernate4 + + reactor-core + resteasy + rxjava + rxjava-2 + rabbitmq + + + + persistence-modules/spring-data-mongodb + @@ -562,148 +519,50 @@ parent-java parent-kotlin - spring-session - spring-sleuth - spring-social-login - spring-spel - spring-state-machine - spring-thymeleaf - spring-userservice - spring-zuul - spring-remoting - spring-reactor - spring-vertx - spring-jinq - spring-rest-embedded-tomcat - testing-modules/testing - testing-modules/testng - video-tutorials - xml - xmlunit-2 - struts-2 - apache-velocity - apache-solrj - rabbitmq - vertx - persistence-modules/spring-data-gemfire - mybatis - spring-drools - drools - persistence-modules/liquibase - spring-boot-property-exp - testing-modules/mockserver - testing-modules/test-containers - undertow - vaadin - vertx-and-rxjava - saas - deeplearning4j - lucene - vraptor - persistence-modules/java-cockroachdb - spring-security-thymeleaf - persistence-modules/java-jdbi - jersey - java-spi - performance-tests - twilio - spring-boot-ctx-fluent - java-ee-8-security-api - spring-webflux-amqp - antlr - maven-archetype - optaplanner - apache-meecrowave - spring-reactive-kotlin - persistence-modules/jnosql - spring-boot-angular-ecommerce - jta - - java-websocket - persistence-modules/activejdbc - animal-sniffer-mvn-plugin - apache-avro - apache-bval - apache-shiro - apache-spark - asciidoctor - checker-plugin - - - core-java-sun - custom-pmd - dagger - data-structures - dubbo - persistence-modules/flyway - - JGit - jni - jooby - - - - ratpack - rest-with-spark-java - spring-boot-autoconfiguration - spring-boot-custom-starter - spring-boot-jasypt - spring-data-rest-querydsl - spring-groovy - spring-mobile - spring-mustache - spring-mvc-simple - spring-mybatis - spring-rest-hal-browser - spring-rest-shell - spring-rest-template - spring-roo - spring-security-stormpath - sse-jaxrs - static-analysis - stripe - structurizr - Twitter4J - wicket - xstream - cas/cas-secured-app - cas/cas-server - graphql/graphql-java - - - - - spring-boot-custom-starter/greeter - persistence-modules/spring-boot-h2/spring-boot-h2-database - - flyway-cdi-extension + spring-4 + spring-5 + spring-5-reactive + spring-5-reactive-security + spring-5-reactive-client + spring-5-mvc + spring-5-security + spring-5-security-oauth + spring-activiti + spring-akka + spring-amqp + spring-all + spring-apache-camel + spring-batch + spring-bom - spring-security-acl - spring-security-cache-control - spring-security-client/spring-security-jsp-authentication - spring-security-client/spring-security-jsp-authorize - spring-security-client/spring-security-jsp-config - spring-security-client/spring-security-mvc - spring-security-client/spring-security-thymeleaf-authentication - spring-security-client/spring-security-thymeleaf-authorize - spring-security-client/spring-security-thymeleaf-config - spring-security-core - spring-security-mvc-boot - spring-security-mvc-custom - spring-security-mvc-digest-auth - spring-security-mvc-ldap - spring-security-mvc-login - spring-security-mvc-persisted-remember-me - spring-security-mvc-session - spring-security-mvc-socket - spring-security-openid - spring-security-react - spring-security-rest-basic-auth - spring-security-rest-custom - spring-security-rest - spring-security-sso - spring-security-x509 + spring-boot-keycloak + spring-boot-bootstrap + spring-boot-admin + spring-boot-camel + spring-boot-security + spring-boot-mvc + spring-boot-logging-log4j2 + spring-boot-disable-console-logging + spring-cloud-data-flow + spring-cloud + spring-cloud-bus + spring-core + spring-cucumber + spring-ejb + spring-aop + + spring-data-rest + spring-dispatcher-servlet + spring-exceptions + spring-freemarker + + spring-integration + spring-jenkins-pipeline + spring-jersey + + spring-jms + spring-jooq spring-kafka spring-katharsis spring-ldap @@ -721,49 +580,118 @@ spring-rest-full spring-rest-query-language spring-rest - spring-rest-simple spring-resttemplate - helidon - - - - - - default-third - - - - - org.apache.maven.plugins - maven-surefire-plugin - ${maven-surefire-plugin.version} - - 3 - true - - **/*IntegrationTest.java - **/*IntTest.java - **/*LongRunningUnitTest.java - **/*ManualTest.java - **/*JdbcTest.java - **/*LiveTest.java - - - - - - - - - parent-boot-1 - parent-boot-2 - parent-spring-4 - parent-spring-5 - parent-java - parent-kotlin + spring-rest-simple + spring-security-acl + spring-security-cache-control + spring-security-client/spring-security-jsp-authentication + spring-security-client/spring-security-jsp-authorize + spring-security-client/spring-security-jsp-config + spring-security-client/spring-security-mvc + spring-security-client/spring-security-thymeleaf-authentication + spring-security-client/spring-security-thymeleaf-authorize + spring-security-client/spring-security-thymeleaf-config + spring-security-core + spring-security-mvc-boot + spring-security-mvc-digest-auth + spring-security-mvc-ldap + spring-security-mvc-login + spring-security-mvc-persisted-remember-me + spring-security-mvc-session + spring-security-mvc-socket + spring-security-openid + + spring-security-rest-basic-auth + spring-security-rest-custom + spring-security-rest + spring-security-sso + spring-security-x509 + spring-session + spring-sleuth + spring-social-login + spring-spel + spring-state-machine + spring-thymeleaf + spring-userservice + spring-zuul + spring-remoting + spring-reactor + spring-vertx + spring-vault + spring-jinq + spring-rest-embedded-tomcat + spring-static-resources + spring-swagger-codegen + spring-drools + spring-boot-property-exp + spring-security-thymeleaf + spring-boot-ctx-fluent + spring-webflux-amqp + + spark-java + saas + struts-2 + + testing-modules/selenium-junit-testng + testing-modules/groovy-spock + testing-modules/mockito + testing-modules/mockito-2 + testing-modules/mocks + testing-modules/rest-assured + testing-modules/rest-testing + testing-modules/junit-5 + testing-modules/junit5-migration + testing-modules/testing + testing-modules/testng + testing-modules/mockserver + testing-modules/test-containers + twilio + + undertow + + video-tutorials + vaadin + vertx-and-rxjava + vraptor + vertx + vavr + + xmlunit-2 + xml + + + + + + + spring-boot + spring-boot-ops + core-kotlin + core-java + google-web-toolkit + spring-security-mvc-custom + core-java-concurrency + --> + + + + @@ -1140,6 +1068,7 @@ parent-kotlin spring-4 + spring-5 spring-5-reactive spring-5-reactive-security spring-5-reactive-client @@ -1248,45 +1177,6 @@ spring-boot-ctx-fluent spring-webflux-amqp - - - - - - - - - integration-lite-third - - - - - org.apache.maven.plugins - maven-surefire-plugin - - - **/*ManualTest.java - **/*LiveTest.java - - - **/*IntegrationTest.java - **/*IntTest.java - - - - - - - - parent-boot-1 - parent-boot-2 - parent-spring-4 - parent-spring-5 - parent-java - parent-kotlin spark-java saas @@ -1338,320 +1228,19 @@ testing-modules/gatling spring-boot spring-boot-ops - spring-5 core-kotlin core-java google-web-toolkit spring-security-mvc-custom core-java-concurrency --> - - - - - - - - integration - - - - - org.apache.maven.plugins - maven-surefire-plugin - - - **/*ManualTest.java - **/*LiveTest.java - - - **/*IntegrationTest.java - **/*IntTest.java - - - - - - - - - parent-boot-1 - parent-boot-2 - parent-spring-4 - parent-spring-5 - parent-java - parent-kotlin - - - - - - - - - - testing-modules/mockito - testing-modules/mockito-2 - testing-modules/mocks - mustache - mvn-wrapper - noexception - persistence-modules/orientdb - osgi - orika - patterns - pdf - protobuffer - persistence-modules/querydsl - reactor-core - persistence-modules/redis - testing-modules/rest-assured - testing-modules/rest-testing - resteasy - rxjava - rxjava-2 - spring-swagger-codegen - testing-modules/selenium-junit-testng - persistence-modules/solr - spark-java - spring-4 - spring-5 - spring-5-data-reactive - spring-5-reactive - spring-5-reactive-security - spring-5-reactive-client - spring-5-mvc - spring-5-security - spring-5-security-oauth - spring-activiti - spring-akka - spring-amqp - spring-all + + + - - - - spring-bom - spring-boot - spring-boot-client - spring-boot-keycloak - spring-boot-bootstrap - spring-boot-admin - spring-boot-camel - spring-boot-ops - persistence-modules/spring-boot-persistence - spring-boot-security - spring-boot-mvc - spring-boot-logging-log4j2 - spring-boot-disable-console-logging - spring-cloud-data-flow - spring-cloud - spring-cloud-bus - spring-core - spring-cucumber - spring-ejb - spring-aop - persistence-modules/spring-data-cassandra - persistence-modules/spring-data-couchbase-2 - persistence-modules/spring-data-dynamodb - persistence-modules/spring-data-elasticsearch - persistence-modules/spring-data-keyvalue - persistence-modules/spring-data-mongodb - persistence-modules/spring-data-jpa - persistence-modules/spring-data-neo4j - persistence-modules/spring-data-redis - spring-data-rest - - - - - - - persistence-modules/spring-data-solr - spring-dispatcher-servlet - spring-exceptions - spring-freemarker - persistence-modules/spring-hibernate-3 - persistence-modules/spring-hibernate4 - persistence-modules/spring-hibernate-5 - persistence-modules/spring-data-eclipselink - spring-integration - spring-jenkins-pipeline - spring-jersey - spring-jms - spring-jooq - persistence-modules/spring-jpa - spring-kafka - spring-katharsis - spring-ldap - spring-mockito - spring-mvc-forms-jsp - spring-mvc-forms-thymeleaf - spring-mvc-java - spring-mvc-velocity - spring-mvc-webflow - spring-mvc-xml - spring-mvc-kotlin - spring-protobuf - spring-quartz - spring-rest-angular - spring-rest-full - spring-rest-query-language - spring-rest - spring-resttemplate - spring-rest-simple - spring-reactive-kotlin - - - - - - - - - - - - - - - - java-websocket - persistence-modules/activejdbc - animal-sniffer-mvn-plugin - apache-avro - apache-bval - apache-shiro - apache-spark - asciidoctor - checker-plugin - - - core-java-sun - custom-pmd - dagger - data-structures - dubbo - persistence-modules/flyway - - - jni - jooby - - - - ratpack - rest-with-spark-java - spring-boot-autoconfiguration - spring-boot-custom-starter - spring-boot-jasypt - spring-data-rest-querydsl - spring-groovy - spring-mobile - spring-mustache - spring-mvc-simple - spring-mybatis - spring-rest-hal-browser - spring-rest-shell - spring-rest-template - spring-roo - spring-security-stormpath - sse-jaxrs - static-analysis - stripe - - - wicket - xstream - cas/cas-secured-app - - - - - - - - - - - - - - jenkins/hello-world - - - - spring-boot-custom-starter/greeter - persistence-modules/spring-boot-h2/spring-boot-h2-database - - - - + spring-5-data-reactive + --> + From 7be6c2f8de71a4e60f6177b2dd33d2d0c9c9098a Mon Sep 17 00:00:00 2001 From: Eugen Paraschiv Date: Fri, 30 Nov 2018 13:10:10 +0200 Subject: [PATCH 105/146] minor pom cleanup --- pom.xml | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/pom.xml b/pom.xml index d149e07f57..ef7a7f6b1d 100644 --- a/pom.xml +++ b/pom.xml @@ -468,6 +468,11 @@ persistence-modules/hbase persistence-modules/influxdb persistence-modules/spring-hibernate4 + persistence-modules/spring-data-mongodb + persistence-modules/java-cassandra + persistence-modules/spring-data-cassandra + persistence-modules/spring-data-couchbase-2 + persistence-modules/spring-data-redis reactor-core resteasy @@ -475,12 +480,6 @@ rxjava-2 rabbitmq - - - persistence-modules/spring-data-mongodb - @@ -600,7 +599,7 @@ spring-security-mvc-session spring-security-mvc-socket spring-security-openid - + spring-security-react spring-security-rest-basic-auth spring-security-rest-custom spring-security-rest @@ -628,7 +627,7 @@ spring-security-thymeleaf spring-boot-ctx-fluent spring-webflux-amqp - + spark-java saas struts-2 @@ -662,12 +661,7 @@ @@ -1020,6 +1014,11 @@ persistence-modules/hbase persistence-modules/influxdb persistence-modules/spring-hibernate4 + persistence-modules/spring-data-mongodb + persistence-modules/java-cassandra + persistence-modules/spring-data-cassandra + persistence-modules/spring-data-couchbase-2 + persistence-modules/spring-data-redis reactor-core resteasy @@ -1027,12 +1026,6 @@ rxjava-2 rabbitmq - - - persistence-modules/spring-data-mongodb - @@ -1148,7 +1141,7 @@ spring-security-mvc-session spring-security-mvc-socket spring-security-openid - + spring-security-react spring-security-rest-basic-auth spring-security-rest-custom spring-security-rest From 55aff7f5f21fefbf89f8854b38f99813d1e5fd4e Mon Sep 17 00:00:00 2001 From: FrancoCorleone Date: Fri, 30 Nov 2018 13:35:27 +0100 Subject: [PATCH 106/146] Upgrading commons lang3 and guava dependencies (#5790) * Upgrading Guava package * Upgrading commons lang3 package --- java-strings/pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/java-strings/pom.xml b/java-strings/pom.xml index ab94c28d4d..f4fb1c0865 100755 --- a/java-strings/pom.xml +++ b/java-strings/pom.xml @@ -122,13 +122,13 @@ - 3.5 + 3.8.1 1.10 3.6.1 1.19 61.1 - 26.0-jre + 27.0.1-jre From a797be29bd1a75868e9714d3a84c0f86260a79cc Mon Sep 17 00:00:00 2001 From: Eugen Paraschiv Date: Fri, 30 Nov 2018 18:43:11 +0200 Subject: [PATCH 107/146] temporarily disabling the module --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index ef7a7f6b1d..da17fc2931 100644 --- a/pom.xml +++ b/pom.xml @@ -599,7 +599,7 @@ spring-security-mvc-session spring-security-mvc-socket spring-security-openid - spring-security-react + spring-security-rest-basic-auth spring-security-rest-custom spring-security-rest @@ -1141,7 +1141,7 @@ spring-security-mvc-session spring-security-mvc-socket spring-security-openid - spring-security-react + spring-security-rest-basic-auth spring-security-rest-custom spring-security-rest From 4058bfc60114b9a32e69474bfb6e4b148ff06331 Mon Sep 17 00:00:00 2001 From: Dhawal Kapil Date: Fri, 30 Nov 2018 22:16:08 +0530 Subject: [PATCH 108/146] BAEL-9567 Align module names, folder names and artifact id - Added "name" in pom.xml whereever it was missing and aligned the present ones with the artifactid and foldername --- algorithms-genetic/pom.xml | 4 +-- algorithms-miscellaneous-1/pom.xml | 4 +-- algorithms-miscellaneous-2/pom.xml | 2 +- algorithms-sorting/pom.xml | 2 +- annotations/annotation-processing/pom.xml | 3 +- annotations/annotation-user/pom.xml | 1 + annotations/pom.xml | 3 +- apache-avro/pom.xml | 3 +- apache-bval/pom.xml | 3 +- apache-curator/pom.xml | 1 + apache-cxf/cxf-aegis/pom.xml | 3 +- apache-cxf/cxf-introduction/pom.xml | 3 +- apache-cxf/cxf-jaxrs-implementation/pom.xml | 3 +- apache-cxf/cxf-spring/pom.xml | 1 + apache-cxf/pom.xml | 2 +- apache-cxf/sse-jaxrs/pom.xml | 2 +- apache-cxf/sse-jaxrs/sse-jaxrs-client/pom.xml | 7 ++-- apache-cxf/sse-jaxrs/sse-jaxrs-server/pom.xml | 8 ++--- apache-geode/pom.xml | 5 ++- apache-opennlp/pom.xml | 1 + apache-poi/pom.xml | 2 +- apache-pulsar/pom.xml | 33 ++++++++++--------- apache-shiro/pom.xml | 3 +- apache-thrift/pom.xml | 2 +- apache-tika/pom.xml | 4 +-- apache-zookeeper/pom.xml | 2 +- asm/pom.xml | 1 + atomix/pom.xml | 3 +- axon/pom.xml | 3 +- cas/cas-server/pom.xml | 3 +- cdi/pom.xml | 2 +- core-groovy/pom.xml | 1 + core-java-9/pom.xml | 1 - core-java/pom.xml | 2 +- core-kotlin/pom.xml | 1 + core-scala/pom.xml | 1 + data-structures/pom.xml | 2 +- drools/pom.xml | 3 +- dubbo/pom.xml | 1 + flyway-cdi-extension/pom.xml | 2 +- guava-modules/guava-18/pom.xml | 4 +-- guava-modules/guava-19/pom.xml | 4 +-- guava-modules/guava-21/pom.xml | 3 +- guest/core-java-9/pom.xml | 3 +- guest/core-java/pom.xml | 1 + guest/core-kotlin/pom.xml | 3 +- guest/deep-jsf/pom.xml | 1 + guest/junit5-example/pom.xml | 3 +- guest/log4j2-example/pom.xml | 3 +- guest/logback-example/pom.xml | 1 + guest/memory-leaks/pom.xml | 4 +-- guest/remote-debugging/pom.xml | 2 +- guest/slf4j/guide/pom.xml | 3 +- guest/slf4j/guide/slf4j-log4j/pom.xml | 2 +- guest/slf4j/guide/slf4j-log4j2/pom.xml | 2 +- guest/slf4j/guide/slf4j-logback/pom.xml | 2 +- guest/spring-boot-app/pom.xml | 1 + guest/spring-mvc/pom.xml | 2 +- guest/thread-pools/pom.xml | 3 +- guest/tomcat-app/pom.xml | 1 + guest/webservices/rest-client/pom.xml | 1 + guest/webservices/rest-server/pom.xml | 1 + guest/webservices/spring-rest-service/pom.xml | 1 + helidon/helidon-mp/pom.xml | 4 +-- helidon/helidon-se/pom.xml | 4 +-- helidon/pom.xml | 3 +- image-processing/pom.xml | 4 +-- immutables/pom.xml | 4 +-- .../app-auth-basic-store-db/pom.xml | 2 +- .../app-auth-custom-form-store-custom/pom.xml | 2 +- .../app-auth-custom-no-store/pom.xml | 2 +- .../app-auth-form-store-ldap/pom.xml | 2 +- java-ee-8-security-api/pom.xml | 1 + java-lite/pom.xml | 1 + java-rmi/pom.xml | 1 + java-spi/exchange-rate-api/pom.xml | 1 + java-spi/exchange-rate-app/pom.xml | 1 + java-spi/exchange-rate-impl/pom.xml | 1 + java-spi/pom.xml | 1 + java-vavr-stream/pom.xml | 1 + java-websocket/pom.xml | 4 +-- javafx/pom.xml | 3 +- javax-servlets/pom.xml | 1 + javaxval/pom.xml | 4 +-- jee-7/pom.xml | 1 + jenkins/hello-world/pom.xml | 4 +-- jersey/pom.xml | 2 +- jhipster/jhipster-microservice/pom.xml | 4 +-- jhipster/jhipster-monolithic/pom.xml | 1 + jni/pom.xml | 3 +- jsf/pom.xml | 1 + json/pom.xml | 3 +- jsoup/pom.xml | 1 + jta/pom.xml | 3 +- jws/pom.xml | 4 +-- kotlin-libraries/pom.xml | 1 + libraries-server/pom.xml | 3 +- linkrest/pom.xml | 2 +- logging-modules/log4j/pom.xml | 1 + logging-modules/log4j2/pom.xml | 3 +- maven-archetype/pom.xml | 3 +- .../maven-polyglot-json-extension/pom.xml | 4 +-- maven/pom.xml | 1 + maven/versions-maven-plugin/pom.xml | 5 +-- mesos-marathon/pom.xml | 3 +- metrics/pom.xml | 3 +- microprofile/pom.xml | 1 + msf4j/pom.xml | 1 + muleesb/pom.xml | 6 ++-- mybatis/pom.xml | 3 +- optaplanner/pom.xml | 7 ++-- parent-boot-1/pom.xml | 1 + parent-boot-2/pom.xml | 1 + patterns/design-patterns/pom.xml | 4 ++- patterns/front-controller/pom.xml | 1 + patterns/intercepting-filter/pom.xml | 2 +- patterns/pom.xml | 1 + performance-tests/pom.xml | 3 +- persistence-modules/hbase/pom.xml | 1 + persistence-modules/hibernate5/pom.xml | 1 + persistence-modules/java-cassandra/pom.xml | 1 + persistence-modules/java-cockroachdb/pom.xml | 1 + persistence-modules/java-jdbi/pom.xml | 1 + persistence-modules/java-jpa/pom.xml | 7 ++-- persistence-modules/java-mongodb/pom.xml | 1 + .../jnosql/jnosql-artemis/pom.xml | 6 ++-- .../jnosql/jnosql-diana/pom.xml | 6 ++-- persistence-modules/jnosql/pom.xml | 2 +- persistence-modules/liquibase/pom.xml | 1 + persistence-modules/orientdb/pom.xml | 2 +- .../spring-boot-h2-database/pom.xml | 2 +- .../spring-boot-persistence/pom.xml | 4 +-- .../spring-data-gemfire/pom.xml | 1 + persistence-modules/spring-data-jpa/pom.xml | 1 + .../spring-data-keyvalue/pom.xml | 1 + persistence-modules/spring-data-neo4j/pom.xml | 3 +- persistence-modules/spring-data-redis/pom.xml | 1 + protobuffer/pom.xml | 3 +- reactor-core/pom.xml | 4 +-- rxjava-2/pom.xml | 4 +-- rxjava/pom.xml | 4 +-- spring-5-data-reactive/pom.xml | 1 + spring-amqp-simple/pom.xml | 1 + spring-boot-admin/pom.xml | 1 + spring-boot-autoconfiguration/pom.xml | 2 +- spring-boot-camel/pom.xml | 3 +- spring-boot-crud/pom.xml | 2 +- spring-boot-ctx-fluent/pom.xml | 2 +- .../greeter-library/pom.xml | 3 +- .../greeter-spring-boot-autoconfigure/pom.xml | 2 +- .../greeter-spring-boot-sample-app/pom.xml | 2 +- .../greeter-spring-boot-starter/pom.xml | 2 +- spring-boot-custom-starter/greeter/pom.xml | 3 +- spring-boot-custom-starter/pom.xml | 1 + .../disabling-console-jul/pom.xml | 2 +- .../disabling-console-log4j2/pom.xml | 2 +- .../disabling-console-logback/pom.xml | 4 ++- spring-boot-disable-console-logging/pom.xml | 1 + spring-boot-logging-log4j2/pom.xml | 2 +- .../property-exp-custom-config/pom.xml | 3 +- .../property-exp-default-config/pom.xml | 3 +- spring-cloud-bus/pom.xml | 1 + spring-cloud-data-flow/etl/pom.xml | 3 +- spring-cloud-data-flow/pom.xml | 3 +- .../dynamodb-config/pom.xml | 1 + .../spring-cloud-archaius/jdbc-config/pom.xml | 1 + .../zookeeper-config/pom.xml | 1 + spring-cloud/spring-cloud-aws/pom.xml | 2 +- .../spring-cloud-bootstrap/config/pom.xml | 1 + .../spring-cloud-bootstrap/discovery/pom.xml | 2 +- .../spring-cloud-bootstrap/gateway/pom.xml | 1 + spring-cloud/spring-cloud-bootstrap/pom.xml | 1 + .../spring-cloud-bootstrap/svc-book/pom.xml | 2 +- .../spring-cloud-bootstrap/svc-rating/pom.xml | 2 +- .../spring-cloud-bootstrap/zipkin/pom.xml | 1 + .../spring-cloud-config/client/pom.xml | 5 +-- spring-cloud/spring-cloud-config/pom.xml | 1 + .../spring-cloud-config/server/pom.xml | 5 +-- .../spring-cloud-connectors-heroku/pom.xml | 1 + spring-cloud/spring-cloud-contract/pom.xml | 1 + spring-cloud/spring-cloud-eureka/pom.xml | 2 +- .../spring-cloud-eureka-client/pom.xml | 4 +-- .../spring-cloud-eureka-feign-client/pom.xml | 2 +- .../spring-cloud-eureka-server/pom.xml | 2 +- spring-cloud/spring-cloud-functions/pom.xml | 6 ++-- spring-cloud/spring-cloud-gateway/pom.xml | 2 +- .../demo-backend/pom.xml | 3 +- .../demo-frontend/pom.xml | 3 +- spring-cloud/spring-cloud-kubernetes/pom.xml | 2 +- .../spring-cloud-security/auth-server/pom.xml | 1 + spring-cloud/spring-cloud-task/pom.xml | 1 + spring-cloud/spring-cloud-zookeeper/pom.xml | 3 +- .../eureka-client/pom.xml | 2 +- .../eureka-server/pom.xml | 2 +- .../pom.xml | 2 +- .../zuul-server/pom.xml | 1 + spring-drools/pom.xml | 3 +- spring-ejb/spring-ejb-remote/pom.xml | 3 +- spring-ejb/wildfly/pom.xml | 4 +-- spring-ejb/wildfly/widlfly-web/pom.xml | 3 +- spring-ejb/wildfly/wildfly-ear/pom.xml | 3 +- .../wildfly/wildfly-ejb-interfaces/pom.xml | 3 +- spring-ejb/wildfly/wildfly-ejb/pom.xml | 3 +- spring-ejb/wildfly/wildfly-jpa/pom.xml | 3 +- spring-freemarker/pom.xml | 2 +- spring-jersey/pom.xml | 3 +- spring-jooq/pom.xml | 3 +- spring-katharsis/pom.xml | 3 +- spring-ldap/pom.xml | 1 + spring-mvc-simple/pom.xml | 3 +- spring-mybatis/pom.xml | 3 +- spring-reactive-kotlin/pom.xml | 2 +- .../remoting-hessian-burlap/pom.xml | 1 + .../remoting-hessian-burlap-client/pom.xml | 11 ++++--- .../remoting-hessian-burlap-server/pom.xml | 7 ++-- spring-remoting/remoting-http/pom.xml | 4 ++- .../remoting-http-client/pom.xml | 1 + .../remoting-http-server/pom.xml | 1 + spring-remoting/remoting-jms/pom.xml | 10 +++--- .../remoting-jms/remoting-jms-client/pom.xml | 7 ++-- .../remoting-jms/remoting-jms-server/pom.xml | 7 ++-- spring-remoting/remoting-rmi/pom.xml | 3 +- .../remoting-rmi/remoting-rmi-client/pom.xml | 9 ++--- .../remoting-rmi/remoting-rmi-server/pom.xml | 7 ++-- spring-rest-hal-browser/pom.xml | 3 +- spring-roo/pom.xml | 2 +- spring-security-angular/server/pom.xml | 4 +-- spring-security-cache-control/pom.xml | 2 +- .../pom.xml | 2 +- spring-security-x509/pom.xml | 3 +- .../spring-security-x509-basic-auth/pom.xml | 3 +- .../spring-security-x509-client-auth/pom.xml | 3 +- spring-session/spring-session-redis/pom.xml | 1 + spring-sleuth/pom.xml | 3 +- spring-spel/pom.xml | 2 +- spring-state-machine/pom.xml | 3 +- spring-swagger-codegen/pom.xml | 1 + .../spring-swagger-codegen-app/pom.xml | 3 +- spring-thymeleaf/pom.xml | 1 + spring-userservice/pom.xml | 4 +-- spring-vertx/pom.xml | 3 +- sse-jaxrs/pom.xml | 2 +- sse-jaxrs/sse-jaxrs-client/pom.xml | 4 +-- sse-jaxrs/sse-jaxrs-server/pom.xml | 8 ++--- static-analysis/pom.xml | 2 +- structurizr/pom.xml | 2 +- struts-2/pom.xml | 2 +- testing-modules/gatling/pom.xml | 3 +- testing-modules/groovy-spock/pom.xml | 1 + .../load-testing-comparison/pom.xml | 7 ++-- testing-modules/mockito-2/pom.xml | 2 +- testing-modules/mockserver/pom.xml | 3 +- testing-modules/parallel-tests-junit/pom.xml | 2 ++ testing-modules/selenium-junit-testng/pom.xml | 3 +- twilio/pom.xml | 3 +- vertx-and-rxjava/pom.xml | 3 +- video-tutorials/jackson-annotations/pom.xml | 3 +- vraptor/pom.xml | 2 +- xmlunit-2/pom.xml | 1 + 259 files changed, 421 insertions(+), 279 deletions(-) diff --git a/algorithms-genetic/pom.xml b/algorithms-genetic/pom.xml index 2a10a81980..662e0c5913 100644 --- a/algorithms-genetic/pom.xml +++ b/algorithms-genetic/pom.xml @@ -1,10 +1,10 @@ 4.0.0 - com.baeldung algorithms-genetic 0.0.1-SNAPSHOT - + algorithms-genetic + com.baeldung parent-modules diff --git a/algorithms-miscellaneous-1/pom.xml b/algorithms-miscellaneous-1/pom.xml index 16749d452e..75b031282b 100644 --- a/algorithms-miscellaneous-1/pom.xml +++ b/algorithms-miscellaneous-1/pom.xml @@ -1,10 +1,10 @@ 4.0.0 - com.baeldung algorithms-miscellaneous-1 0.0.1-SNAPSHOT - + algorithms-miscellaneous-1 + com.baeldung parent-modules diff --git a/algorithms-miscellaneous-2/pom.xml b/algorithms-miscellaneous-2/pom.xml index eeae544612..25472d4888 100644 --- a/algorithms-miscellaneous-2/pom.xml +++ b/algorithms-miscellaneous-2/pom.xml @@ -1,9 +1,9 @@ 4.0.0 - com.baeldung algorithms-miscellaneous-2 0.0.1-SNAPSHOT + algorithms-miscellaneous-2 com.baeldung diff --git a/algorithms-sorting/pom.xml b/algorithms-sorting/pom.xml index 60ae37f2a4..2aee6e9199 100644 --- a/algorithms-sorting/pom.xml +++ b/algorithms-sorting/pom.xml @@ -1,9 +1,9 @@ 4.0.0 - com.baeldung algorithms-sorting 0.0.1-SNAPSHOT + algorithms-sorting com.baeldung diff --git a/annotations/annotation-processing/pom.xml b/annotations/annotation-processing/pom.xml index 8e53334521..d9aca6040d 100644 --- a/annotations/annotation-processing/pom.xml +++ b/annotations/annotation-processing/pom.xml @@ -3,7 +3,8 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 annotation-processing - + annotation-processing + com.baeldung 1.0.0-SNAPSHOT diff --git a/annotations/annotation-user/pom.xml b/annotations/annotation-user/pom.xml index 07ea9a5b5a..422cc7f119 100644 --- a/annotations/annotation-user/pom.xml +++ b/annotations/annotation-user/pom.xml @@ -3,6 +3,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 annotation-user + annotation-user annotations diff --git a/annotations/pom.xml b/annotations/pom.xml index 2c73d3d91b..6d83f5b057 100644 --- a/annotations/pom.xml +++ b/annotations/pom.xml @@ -4,7 +4,8 @@ 4.0.0 annotations pom - + annotations + parent-modules com.baeldung diff --git a/apache-avro/pom.xml b/apache-avro/pom.xml index ddf5844271..18f9c34d64 100644 --- a/apache-avro/pom.xml +++ b/apache-avro/pom.xml @@ -3,10 +3,9 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - com.baeldung apache-avro 0.0.1-SNAPSHOT - Apache Avro + apache-avro UTF-8 diff --git a/apache-bval/pom.xml b/apache-bval/pom.xml index 5ddb1ecb59..786f587fb1 100644 --- a/apache-bval/pom.xml +++ b/apache-bval/pom.xml @@ -4,7 +4,8 @@ apache-bval apache-bval 0.0.1-SNAPSHOT - + apache-bval + com.baeldung parent-modules diff --git a/apache-curator/pom.xml b/apache-curator/pom.xml index ac10811e7a..bcca38b199 100644 --- a/apache-curator/pom.xml +++ b/apache-curator/pom.xml @@ -4,6 +4,7 @@ apache-curator 0.0.1-SNAPSHOT jar + apache-curator com.baeldung diff --git a/apache-cxf/cxf-aegis/pom.xml b/apache-cxf/cxf-aegis/pom.xml index b7e9e426a2..1d36178b82 100644 --- a/apache-cxf/cxf-aegis/pom.xml +++ b/apache-cxf/cxf-aegis/pom.xml @@ -2,7 +2,8 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 4.0.0 cxf-aegis - + cxf-aegis + com.baeldung apache-cxf diff --git a/apache-cxf/cxf-introduction/pom.xml b/apache-cxf/cxf-introduction/pom.xml index a9e82c16b3..17f03afd25 100644 --- a/apache-cxf/cxf-introduction/pom.xml +++ b/apache-cxf/cxf-introduction/pom.xml @@ -4,7 +4,8 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 4.0.0 cxf-introduction - + cxf-introduction + com.baeldung apache-cxf diff --git a/apache-cxf/cxf-jaxrs-implementation/pom.xml b/apache-cxf/cxf-jaxrs-implementation/pom.xml index 89acbdf1bd..03d0f67c90 100644 --- a/apache-cxf/cxf-jaxrs-implementation/pom.xml +++ b/apache-cxf/cxf-jaxrs-implementation/pom.xml @@ -4,7 +4,8 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 4.0.0 cxf-jaxrs-implementation - + cxf-jaxrs-implementation + com.baeldung apache-cxf diff --git a/apache-cxf/cxf-spring/pom.xml b/apache-cxf/cxf-spring/pom.xml index 31e75e7cdd..97715af54c 100644 --- a/apache-cxf/cxf-spring/pom.xml +++ b/apache-cxf/cxf-spring/pom.xml @@ -3,6 +3,7 @@ 4.0.0 cxf-spring war + cxf-spring com.baeldung diff --git a/apache-cxf/pom.xml b/apache-cxf/pom.xml index 8918fd4450..0016f33d70 100644 --- a/apache-cxf/pom.xml +++ b/apache-cxf/pom.xml @@ -1,9 +1,9 @@ 4.0.0 - com.baeldung apache-cxf 0.0.1-SNAPSHOT + apache-cxf pom diff --git a/apache-cxf/sse-jaxrs/pom.xml b/apache-cxf/sse-jaxrs/pom.xml index d4b6c19d03..cb5c96660a 100644 --- a/apache-cxf/sse-jaxrs/pom.xml +++ b/apache-cxf/sse-jaxrs/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 - sse-jaxrs + sse-jaxrs pom diff --git a/apache-cxf/sse-jaxrs/sse-jaxrs-client/pom.xml b/apache-cxf/sse-jaxrs/sse-jaxrs-client/pom.xml index 0f5406fbc7..c7acf22c32 100644 --- a/apache-cxf/sse-jaxrs/sse-jaxrs-client/pom.xml +++ b/apache-cxf/sse-jaxrs/sse-jaxrs-client/pom.xml @@ -3,15 +3,15 @@ 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 - + sse-jaxrs-client + sse-jaxrs-client + com.baeldung sse-jaxrs 0.0.1-SNAPSHOT - sse-jaxrs-client - 3.2.0 @@ -21,7 +21,6 @@ org.codehaus.mojo exec-maven-plugin - 1.6.0 singleEvent diff --git a/apache-cxf/sse-jaxrs/sse-jaxrs-server/pom.xml b/apache-cxf/sse-jaxrs/sse-jaxrs-server/pom.xml index 2e82dc3829..eeb5726ee1 100644 --- a/apache-cxf/sse-jaxrs/sse-jaxrs-server/pom.xml +++ b/apache-cxf/sse-jaxrs/sse-jaxrs-server/pom.xml @@ -3,16 +3,16 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - + sse-jaxrs-server + sse-jaxrs-server + war + com.baeldung sse-jaxrs 0.0.1-SNAPSHOT - sse-jaxrs-server - war - 2.4.2 false diff --git a/apache-geode/pom.xml b/apache-geode/pom.xml index a3f6604ac4..738accdcb8 100644 --- a/apache-geode/pom.xml +++ b/apache-geode/pom.xml @@ -3,11 +3,10 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - - com.baeldung apache-geode 1.0-SNAPSHOT - + apache-geode + com.baeldung parent-modules diff --git a/apache-opennlp/pom.xml b/apache-opennlp/pom.xml index 985c9a2df2..6b2e6a9729 100644 --- a/apache-opennlp/pom.xml +++ b/apache-opennlp/pom.xml @@ -4,6 +4,7 @@ 4.0.0 apache-opennlp 1.0-SNAPSHOT + apache-opennlp jar diff --git a/apache-poi/pom.xml b/apache-poi/pom.xml index a1ec626d43..54c3e8e928 100644 --- a/apache-poi/pom.xml +++ b/apache-poi/pom.xml @@ -1,9 +1,9 @@ 4.0.0 - com.baeldung apache-poi 0.0.1-SNAPSHOT + apache-poi com.baeldung diff --git a/apache-pulsar/pom.xml b/apache-pulsar/pom.xml index da004a7638..a4c09586eb 100644 --- a/apache-pulsar/pom.xml +++ b/apache-pulsar/pom.xml @@ -1,21 +1,22 @@ - 4.0.0 - com.baeldung.pulsar - pulsar-java - 0.0.1 + 4.0.0 + com.baeldung.pulsar + apache-pulsar + 0.0.1 + apache-pulsar - - - org.apache.pulsar - pulsar-client - 2.1.1-incubating - compile - - - - 1.8 - 1.8 - + + + org.apache.pulsar + pulsar-client + 2.1.1-incubating + compile + + + + 1.8 + 1.8 + diff --git a/apache-shiro/pom.xml b/apache-shiro/pom.xml index 98d9563284..644d70b30a 100644 --- a/apache-shiro/pom.xml +++ b/apache-shiro/pom.xml @@ -5,7 +5,8 @@ 4.0.0 apache-shiro 1.0-SNAPSHOT - + apache-shiro + parent-boot-1 com.baeldung diff --git a/apache-thrift/pom.xml b/apache-thrift/pom.xml index b22364cb19..ab54fc2cef 100644 --- a/apache-thrift/pom.xml +++ b/apache-thrift/pom.xml @@ -1,9 +1,9 @@ 4.0.0 - com.baeldung apache-thrift 0.0.1-SNAPSHOT + apache-thrift pom diff --git a/apache-tika/pom.xml b/apache-tika/pom.xml index 5a76fdeeda..0399914a5f 100644 --- a/apache-tika/pom.xml +++ b/apache-tika/pom.xml @@ -1,10 +1,10 @@ 4.0.0 - com.baeldung apache-tika 0.0.1-SNAPSHOT - + apache-tika + com.baeldung parent-modules diff --git a/apache-zookeeper/pom.xml b/apache-zookeeper/pom.xml index 0b29186ccc..53e4217358 100644 --- a/apache-zookeeper/pom.xml +++ b/apache-zookeeper/pom.xml @@ -1,9 +1,9 @@ 4.0.0 - com.baeldung apache-zookeeper 0.0.1-SNAPSHOT + apache-zookeeper jar diff --git a/asm/pom.xml b/asm/pom.xml index 5aad2a0e37..e56438c808 100644 --- a/asm/pom.xml +++ b/asm/pom.xml @@ -5,6 +5,7 @@ com.baeldung.examples asm 1.0 + asm jar diff --git a/atomix/pom.xml b/atomix/pom.xml index f85d2d7484..e50c1d867f 100644 --- a/atomix/pom.xml +++ b/atomix/pom.xml @@ -4,7 +4,8 @@ com.atomix.io atomix 0.0.1-SNAPSHOT - + atomix + com.baeldung parent-modules diff --git a/axon/pom.xml b/axon/pom.xml index 915a04feb5..c643ea9e57 100644 --- a/axon/pom.xml +++ b/axon/pom.xml @@ -3,7 +3,8 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 axon - + axon + parent-modules com.baeldung diff --git a/cas/cas-server/pom.xml b/cas/cas-server/pom.xml index 9b61aaec3d..98f5f10493 100644 --- a/cas/cas-server/pom.xml +++ b/cas/cas-server/pom.xml @@ -3,8 +3,9 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd "> 4.0.0 cas-server - war 1.0 + cas-server + war parent-boot-1 diff --git a/cdi/pom.xml b/cdi/pom.xml index 0b735e0ca5..0cf5062ccc 100644 --- a/cdi/pom.xml +++ b/cdi/pom.xml @@ -2,9 +2,9 @@ 4.0.0 - com.baeldung cdi 1.0-SNAPSHOT + cdi com.baeldung diff --git a/core-groovy/pom.xml b/core-groovy/pom.xml index 909250710e..e54c766280 100644 --- a/core-groovy/pom.xml +++ b/core-groovy/pom.xml @@ -4,6 +4,7 @@ 4.0.0 core-groovy 1.0-SNAPSHOT + core-groovy jar diff --git a/core-java-9/pom.xml b/core-java-9/pom.xml index f22d0a3ed9..cd1fa74dbb 100644 --- a/core-java-9/pom.xml +++ b/core-java-9/pom.xml @@ -1,7 +1,6 @@ 4.0.0 - com.baeldung core-java-9 0.2-SNAPSHOT core-java-9 diff --git a/core-java/pom.xml b/core-java/pom.xml index 9fbc8f6810..64345ab14c 100644 --- a/core-java/pom.xml +++ b/core-java/pom.xml @@ -3,8 +3,8 @@ 4.0.0 core-java 0.1.0-SNAPSHOT - jar core-java + jar com.baeldung diff --git a/core-kotlin/pom.xml b/core-kotlin/pom.xml index 2b559b19e0..ed79ebc01b 100644 --- a/core-kotlin/pom.xml +++ b/core-kotlin/pom.xml @@ -3,6 +3,7 @@ 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 + core-kotlin jar diff --git a/core-scala/pom.xml b/core-scala/pom.xml index eb7c1c3330..343f21484a 100644 --- a/core-scala/pom.xml +++ b/core-scala/pom.xml @@ -4,6 +4,7 @@ 4.0.0 core-scala 1.0-SNAPSHOT + core-scala jar diff --git a/data-structures/pom.xml b/data-structures/pom.xml index c1a1f1d371..4958598234 100644 --- a/data-structures/pom.xml +++ b/data-structures/pom.xml @@ -1,9 +1,9 @@ 4.0.0 - com.baeldung data-structures 0.0.1-SNAPSHOT + data-structures com.baeldung diff --git a/drools/pom.xml b/drools/pom.xml index 009ac8acec..b5cfc7d6dc 100644 --- a/drools/pom.xml +++ b/drools/pom.xml @@ -3,7 +3,8 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 drools - + drools + com.baeldung parent-spring-4 diff --git a/dubbo/pom.xml b/dubbo/pom.xml index 6f81ec5cff..9fe228bf89 100644 --- a/dubbo/pom.xml +++ b/dubbo/pom.xml @@ -2,6 +2,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 dubbo + dubbo parent-modules diff --git a/flyway-cdi-extension/pom.xml b/flyway-cdi-extension/pom.xml index c6ee26f783..dbb32f1e5a 100644 --- a/flyway-cdi-extension/pom.xml +++ b/flyway-cdi-extension/pom.xml @@ -3,10 +3,10 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - com.baeldung flyway-cdi-extension 1.0-SNAPSHOT + flyway-cdi-extension 1.8 diff --git a/guava-modules/guava-18/pom.xml b/guava-modules/guava-18/pom.xml index ce9395fbf4..d55aa9ce82 100644 --- a/guava-modules/guava-18/pom.xml +++ b/guava-modules/guava-18/pom.xml @@ -2,10 +2,10 @@ 4.0.0 - com.baeldung guava-18 0.1.0-SNAPSHOT - + guava-18 + com.baeldung parent-java diff --git a/guava-modules/guava-19/pom.xml b/guava-modules/guava-19/pom.xml index 5dfb4d2cec..0548bb0c1f 100644 --- a/guava-modules/guava-19/pom.xml +++ b/guava-modules/guava-19/pom.xml @@ -2,10 +2,10 @@ 4.0.0 - com.baeldung guava-19 0.1.0-SNAPSHOT - + guava-19 + com.baeldung parent-java diff --git a/guava-modules/guava-21/pom.xml b/guava-modules/guava-21/pom.xml index 945b7c27c1..bdb1058a48 100644 --- a/guava-modules/guava-21/pom.xml +++ b/guava-modules/guava-21/pom.xml @@ -4,7 +4,8 @@ 4.0.0 guava-21 1.0-SNAPSHOT - + guava-21 + com.baeldung parent-java diff --git a/guest/core-java-9/pom.xml b/guest/core-java-9/pom.xml index e9271b42ff..3847c19d16 100644 --- a/guest/core-java-9/pom.xml +++ b/guest/core-java-9/pom.xml @@ -4,7 +4,8 @@ com.stackify core-java-9 0.0.1-SNAPSHOT - + core-java-9 + com.baeldung parent-modules diff --git a/guest/core-java/pom.xml b/guest/core-java/pom.xml index 787dd764a1..5057f7eaed 100644 --- a/guest/core-java/pom.xml +++ b/guest/core-java/pom.xml @@ -4,6 +4,7 @@ com.stackify core-java 0.0.1-SNAPSHOT + core-java com.baeldung diff --git a/guest/core-kotlin/pom.xml b/guest/core-kotlin/pom.xml index 6b189143a4..a57dd28ffd 100644 --- a/guest/core-kotlin/pom.xml +++ b/guest/core-kotlin/pom.xml @@ -6,7 +6,8 @@ 1.0-SNAPSHOT com.stackify jar - + core-kotlin + jcenter diff --git a/guest/deep-jsf/pom.xml b/guest/deep-jsf/pom.xml index e09b5e0606..12426a8833 100644 --- a/guest/deep-jsf/pom.xml +++ b/guest/deep-jsf/pom.xml @@ -4,6 +4,7 @@ com.stackify deep-jsf 0.0.1-SNAPSHOT + deep-jsf war diff --git a/guest/junit5-example/pom.xml b/guest/junit5-example/pom.xml index 457fb1fcaa..7c0cc3e776 100644 --- a/guest/junit5-example/pom.xml +++ b/guest/junit5-example/pom.xml @@ -4,7 +4,8 @@ junit5-example junit5-example 0.0.1-SNAPSHOT - + junit5-example + com.baeldung parent-modules diff --git a/guest/log4j2-example/pom.xml b/guest/log4j2-example/pom.xml index f64869879f..ab55e0b60e 100644 --- a/guest/log4j2-example/pom.xml +++ b/guest/log4j2-example/pom.xml @@ -4,7 +4,8 @@ log4j2-example log4j2-example 0.0.1-SNAPSHOT - + log4j2-example + com.baeldung parent-modules diff --git a/guest/logback-example/pom.xml b/guest/logback-example/pom.xml index 04de6a00a2..6e9fe0ddea 100644 --- a/guest/logback-example/pom.xml +++ b/guest/logback-example/pom.xml @@ -4,6 +4,7 @@ com.stackify logback-example 0.0.1-SNAPSHOT + logback-example com.baeldung diff --git a/guest/memory-leaks/pom.xml b/guest/memory-leaks/pom.xml index 956ae9c408..f1d411acbc 100644 --- a/guest/memory-leaks/pom.xml +++ b/guest/memory-leaks/pom.xml @@ -1,10 +1,10 @@ 4.0.0 - com.baeldung memory-leaks 0.0.1-SNAPSHOT - + memory-leaks + com.baeldung parent-modules diff --git a/guest/remote-debugging/pom.xml b/guest/remote-debugging/pom.xml index 974421de97..07b9cc49d8 100644 --- a/guest/remote-debugging/pom.xml +++ b/guest/remote-debugging/pom.xml @@ -5,8 +5,8 @@ com.stackify remote-debugging 0.0.1-SNAPSHOT + remote-debugging war - remote-debugging org.springframework.boot diff --git a/guest/slf4j/guide/pom.xml b/guest/slf4j/guide/pom.xml index 0db9b46247..657ede73b6 100644 --- a/guest/slf4j/guide/pom.xml +++ b/guest/slf4j/guide/pom.xml @@ -2,13 +2,12 @@ 4.0.0 - com.stackify.slf4j.guide slf4j-parent-module 1.0.0-SNAPSHOT + slf4j-parent-module pom - org.springframework.boot spring-boot-starter-parent diff --git a/guest/slf4j/guide/slf4j-log4j/pom.xml b/guest/slf4j/guide/slf4j-log4j/pom.xml index 0d08fa6191..bca5392f4d 100644 --- a/guest/slf4j/guide/slf4j-log4j/pom.xml +++ b/guest/slf4j/guide/slf4j-log4j/pom.xml @@ -2,9 +2,9 @@ 4.0.0 - slf4j-log4j 0.0.1-SNAPSHOT + slf4j-log4j jar diff --git a/guest/slf4j/guide/slf4j-log4j2/pom.xml b/guest/slf4j/guide/slf4j-log4j2/pom.xml index 643649335f..9473362cb8 100644 --- a/guest/slf4j/guide/slf4j-log4j2/pom.xml +++ b/guest/slf4j/guide/slf4j-log4j2/pom.xml @@ -2,9 +2,9 @@ 4.0.0 - slf4j-log4j2 0.0.1-SNAPSHOT + slf4j-log4j2 jar diff --git a/guest/slf4j/guide/slf4j-logback/pom.xml b/guest/slf4j/guide/slf4j-logback/pom.xml index e8aebf0ef6..0327e79732 100644 --- a/guest/slf4j/guide/slf4j-logback/pom.xml +++ b/guest/slf4j/guide/slf4j-logback/pom.xml @@ -2,9 +2,9 @@ 4.0.0 - slf4j-logback 0.0.1-SNAPSHOT + slf4j-logback jar diff --git a/guest/spring-boot-app/pom.xml b/guest/spring-boot-app/pom.xml index 7daa8f668e..423dadbb99 100644 --- a/guest/spring-boot-app/pom.xml +++ b/guest/spring-boot-app/pom.xml @@ -4,6 +4,7 @@ spring-boot-app spring-boot-app 0.0.1-SNAPSHOT + spring-boot-app war diff --git a/guest/spring-mvc/pom.xml b/guest/spring-mvc/pom.xml index c0ef451605..3bffb1530d 100644 --- a/guest/spring-mvc/pom.xml +++ b/guest/spring-mvc/pom.xml @@ -5,8 +5,8 @@ com.stackify.guest spring-mvc 0.0.1-SNAPSHOT - jar spring-mvc + jar Spring MVC sample project diff --git a/guest/thread-pools/pom.xml b/guest/thread-pools/pom.xml index db9a5ac89f..2591cb2746 100644 --- a/guest/thread-pools/pom.xml +++ b/guest/thread-pools/pom.xml @@ -4,7 +4,8 @@ com.stackify thread-pools 0.0.1-SNAPSHOT - + thread-pools + com.baeldung parent-modules diff --git a/guest/tomcat-app/pom.xml b/guest/tomcat-app/pom.xml index 7fd27e869b..9ce77c758a 100644 --- a/guest/tomcat-app/pom.xml +++ b/guest/tomcat-app/pom.xml @@ -4,6 +4,7 @@ com.stackify tomcat-app 0.0.1-SNAPSHOT + tomcat-app war diff --git a/guest/webservices/rest-client/pom.xml b/guest/webservices/rest-client/pom.xml index 5e52b7161c..8508186e86 100644 --- a/guest/webservices/rest-client/pom.xml +++ b/guest/webservices/rest-client/pom.xml @@ -3,6 +3,7 @@ com.stackify rest-client 0.0.1-SNAPSHOT + rest-client war diff --git a/guest/webservices/rest-server/pom.xml b/guest/webservices/rest-server/pom.xml index 4b3d241293..c576924215 100644 --- a/guest/webservices/rest-server/pom.xml +++ b/guest/webservices/rest-server/pom.xml @@ -4,6 +4,7 @@ com.stackify rest-server 0.0.1-SNAPSHOT + rest-server war diff --git a/guest/webservices/spring-rest-service/pom.xml b/guest/webservices/spring-rest-service/pom.xml index 49d35766e8..fcec8a3e12 100644 --- a/guest/webservices/spring-rest-service/pom.xml +++ b/guest/webservices/spring-rest-service/pom.xml @@ -4,6 +4,7 @@ com.stackify spring-rest-service 0.0.1-SNAPSHOT + spring-rest-service war diff --git a/helidon/helidon-mp/pom.xml b/helidon/helidon-mp/pom.xml index 1ec1131a67..1f39431886 100644 --- a/helidon/helidon-mp/pom.xml +++ b/helidon/helidon-mp/pom.xml @@ -2,9 +2,9 @@ 4.0.0 - helidon-mp - + helidon-mp + com.baeldung.helidon helidon diff --git a/helidon/helidon-se/pom.xml b/helidon/helidon-se/pom.xml index 5e14ecb81c..8982bf048e 100644 --- a/helidon/helidon-se/pom.xml +++ b/helidon/helidon-se/pom.xml @@ -3,9 +3,9 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - helidon-se - + helidon-se + com.baeldung.helidon helidon diff --git a/helidon/pom.xml b/helidon/pom.xml index ea8cc52ee0..85bab4db42 100644 --- a/helidon/pom.xml +++ b/helidon/pom.xml @@ -2,10 +2,9 @@ 4.0.0 - com.baeldung.helidon helidon - 1.0.0-SNAPSHOT + helidon pom diff --git a/image-processing/pom.xml b/image-processing/pom.xml index fe8001ae3a..ce75145dc7 100644 --- a/image-processing/pom.xml +++ b/image-processing/pom.xml @@ -2,10 +2,10 @@ 4.0.0 - com.baeldung image-processing 1.0-SNAPSHOT - + image-processing + com.baeldung parent-modules diff --git a/immutables/pom.xml b/immutables/pom.xml index 17510690b0..efb21e584a 100644 --- a/immutables/pom.xml +++ b/immutables/pom.xml @@ -3,8 +3,8 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 immutables - 1.0.0-SNAPSHOT - + immutables + com.baeldung parent-modules diff --git a/java-ee-8-security-api/app-auth-basic-store-db/pom.xml b/java-ee-8-security-api/app-auth-basic-store-db/pom.xml index 6ecc9f7e80..cf92fe2ecd 100644 --- a/java-ee-8-security-api/app-auth-basic-store-db/pom.xml +++ b/java-ee-8-security-api/app-auth-basic-store-db/pom.xml @@ -2,8 +2,8 @@ 4.0.0 - app-auth-basic-store-db + app-auth-basic-store-db war diff --git a/java-ee-8-security-api/app-auth-custom-form-store-custom/pom.xml b/java-ee-8-security-api/app-auth-custom-form-store-custom/pom.xml index bf5315e993..43809f1cd5 100644 --- a/java-ee-8-security-api/app-auth-custom-form-store-custom/pom.xml +++ b/java-ee-8-security-api/app-auth-custom-form-store-custom/pom.xml @@ -2,8 +2,8 @@ 4.0.0 - app-auth-custom-form-store-custom + app-auth-custom-form-store-custom war diff --git a/java-ee-8-security-api/app-auth-custom-no-store/pom.xml b/java-ee-8-security-api/app-auth-custom-no-store/pom.xml index c05c0f19be..f9d63f8623 100644 --- a/java-ee-8-security-api/app-auth-custom-no-store/pom.xml +++ b/java-ee-8-security-api/app-auth-custom-no-store/pom.xml @@ -2,8 +2,8 @@ 4.0.0 - app-auth-custom-no-store + app-auth-custom-no-store war diff --git a/java-ee-8-security-api/app-auth-form-store-ldap/pom.xml b/java-ee-8-security-api/app-auth-form-store-ldap/pom.xml index 570b36add5..6a7b97b2d7 100644 --- a/java-ee-8-security-api/app-auth-form-store-ldap/pom.xml +++ b/java-ee-8-security-api/app-auth-form-store-ldap/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 - app-auth-form-store-ldap + app-auth-form-store-ldap war diff --git a/java-ee-8-security-api/pom.xml b/java-ee-8-security-api/pom.xml index 7546839492..ad33c74ad3 100644 --- a/java-ee-8-security-api/pom.xml +++ b/java-ee-8-security-api/pom.xml @@ -5,6 +5,7 @@ 4.0.0 java-ee-8-security-api 1.0-SNAPSHOT + java-ee-8-security-api pom diff --git a/java-lite/pom.xml b/java-lite/pom.xml index 5111cd2e7f..03f4e29f4e 100644 --- a/java-lite/pom.xml +++ b/java-lite/pom.xml @@ -5,6 +5,7 @@ org.baeldung java-lite 1.0-SNAPSHOT + java-lite war diff --git a/java-rmi/pom.xml b/java-rmi/pom.xml index 33931baedf..ad413b66ab 100644 --- a/java-rmi/pom.xml +++ b/java-rmi/pom.xml @@ -4,6 +4,7 @@ com.baeldung.rmi java-rmi 1.0-SNAPSHOT + java-rmi jar diff --git a/java-spi/exchange-rate-api/pom.xml b/java-spi/exchange-rate-api/pom.xml index b626916b56..fd3a7ae0a7 100644 --- a/java-spi/exchange-rate-api/pom.xml +++ b/java-spi/exchange-rate-api/pom.xml @@ -2,6 +2,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 exchange-rate-api + exchange-rate-api jar diff --git a/java-spi/exchange-rate-app/pom.xml b/java-spi/exchange-rate-app/pom.xml index a42a30ceda..7a076d560c 100644 --- a/java-spi/exchange-rate-app/pom.xml +++ b/java-spi/exchange-rate-app/pom.xml @@ -2,6 +2,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 exchange-rate-app + exchange-rate-app jar diff --git a/java-spi/exchange-rate-impl/pom.xml b/java-spi/exchange-rate-impl/pom.xml index 41c874c659..8a77b51793 100644 --- a/java-spi/exchange-rate-impl/pom.xml +++ b/java-spi/exchange-rate-impl/pom.xml @@ -2,6 +2,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 exchange-rate-impl + exchange-rate-impl jar diff --git a/java-spi/pom.xml b/java-spi/pom.xml index 9ac87bf960..97a22024bd 100644 --- a/java-spi/pom.xml +++ b/java-spi/pom.xml @@ -2,6 +2,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 java-spi + java-spi pom diff --git a/java-vavr-stream/pom.xml b/java-vavr-stream/pom.xml index 395d2c81ba..c92f3c8742 100644 --- a/java-vavr-stream/pom.xml +++ b/java-vavr-stream/pom.xml @@ -5,6 +5,7 @@ com.baeldung.samples java-vavr-stream 1.0 + java-vavr-stream jar diff --git a/java-websocket/pom.xml b/java-websocket/pom.xml index e8ff8dfc36..7ba3ca61d0 100644 --- a/java-websocket/pom.xml +++ b/java-websocket/pom.xml @@ -1,10 +1,10 @@ 4.0.0 - com.baeldung java-websocket - war 0.0.1-SNAPSHOT + java-websocket + war com.baeldung diff --git a/javafx/pom.xml b/javafx/pom.xml index c9c5bc294e..44e6f7e8da 100644 --- a/javafx/pom.xml +++ b/javafx/pom.xml @@ -3,7 +3,8 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 javafx - + javafx + parent-modules com.baeldung diff --git a/javax-servlets/pom.xml b/javax-servlets/pom.xml index 7b4eecd880..f00dd0ebe8 100644 --- a/javax-servlets/pom.xml +++ b/javax-servlets/pom.xml @@ -5,6 +5,7 @@ com.baeldung.javax-servlets javax-servlets 1.0-SNAPSHOT + javax-servlets war diff --git a/javaxval/pom.xml b/javaxval/pom.xml index 22f1827213..5f2690b5b4 100644 --- a/javaxval/pom.xml +++ b/javaxval/pom.xml @@ -1,10 +1,10 @@ 4.0.0 - com.baeldung javaxval 0.1-SNAPSHOT - + javaxval + com.baeldung parent-modules diff --git a/jee-7/pom.xml b/jee-7/pom.xml index 9011648d17..97ed2cc51d 100644 --- a/jee-7/pom.xml +++ b/jee-7/pom.xml @@ -5,6 +5,7 @@ 4.0.0 jee-7 1.0-SNAPSHOT + jee-7 war JavaEE 7 Arquillian Archetype Sample diff --git a/jenkins/hello-world/pom.xml b/jenkins/hello-world/pom.xml index fb2154c7ad..f00a551173 100644 --- a/jenkins/hello-world/pom.xml +++ b/jenkins/hello-world/pom.xml @@ -2,10 +2,10 @@ 4.0.0 - jenkins-hello-world + hello-world 1.0-SNAPSHOT + hello-world hpi - Hello World Plugin A sample Jenkins Hello World plugin diff --git a/jersey/pom.xml b/jersey/pom.xml index b55bdc5330..a3adb4cf5a 100644 --- a/jersey/pom.xml +++ b/jersey/pom.xml @@ -2,9 +2,9 @@ 4.0.0 - com.baeldung jersey 0.0.1-SNAPSHOT + jersey war diff --git a/jhipster/jhipster-microservice/pom.xml b/jhipster/jhipster-microservice/pom.xml index 4a60e47f87..051d5f70b7 100644 --- a/jhipster/jhipster-microservice/pom.xml +++ b/jhipster/jhipster-microservice/pom.xml @@ -3,9 +3,9 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 jhipster-microservice + jhipster-microservice pom - JHipster Microservice - + jhipster com.baeldung.jhipster diff --git a/jhipster/jhipster-monolithic/pom.xml b/jhipster/jhipster-monolithic/pom.xml index e242668759..12dead99df 100644 --- a/jhipster/jhipster-monolithic/pom.xml +++ b/jhipster/jhipster-monolithic/pom.xml @@ -3,6 +3,7 @@ 4.0.0 jhipster-monolithic war + jhipster-monolithic JHipster Monolithic Application diff --git a/jni/pom.xml b/jni/pom.xml index d4cc409d33..4850e07ed7 100644 --- a/jni/pom.xml +++ b/jni/pom.xml @@ -2,7 +2,8 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 jni - + jni + com.baeldung parent-modules diff --git a/jsf/pom.xml b/jsf/pom.xml index 2ac8a9f7c2..fc6d4a0ee2 100644 --- a/jsf/pom.xml +++ b/jsf/pom.xml @@ -4,6 +4,7 @@ 4.0.0 jsf 0.1-SNAPSHOT + jsf war diff --git a/json/pom.xml b/json/pom.xml index b688baec06..db98ec437e 100644 --- a/json/pom.xml +++ b/json/pom.xml @@ -4,7 +4,8 @@ org.baeldung json 0.0.1-SNAPSHOT - + json + com.baeldung parent-modules diff --git a/jsoup/pom.xml b/jsoup/pom.xml index 2704d7bc00..f6e25e7a23 100644 --- a/jsoup/pom.xml +++ b/jsoup/pom.xml @@ -3,6 +3,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 jsoup + jsoup jar diff --git a/jta/pom.xml b/jta/pom.xml index 89bdccf25e..4754c1872b 100644 --- a/jta/pom.xml +++ b/jta/pom.xml @@ -3,8 +3,9 @@ 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 - jta-demo + jta 1.0-SNAPSHOT + jta jar JEE JTA demo diff --git a/jws/pom.xml b/jws/pom.xml index 1970ab9921..2c89b687f8 100644 --- a/jws/pom.xml +++ b/jws/pom.xml @@ -3,9 +3,9 @@ 4.0.0 com.example jws - war 0.0.1-SNAPSHOT - jws-example + jws + war com.baeldung diff --git a/kotlin-libraries/pom.xml b/kotlin-libraries/pom.xml index 92a643e458..ae77a9aa2d 100644 --- a/kotlin-libraries/pom.xml +++ b/kotlin-libraries/pom.xml @@ -3,6 +3,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 kotlin-libraries + kotlin-libraries jar diff --git a/libraries-server/pom.xml b/libraries-server/pom.xml index 6fca09faf4..661f5f01d5 100644 --- a/libraries-server/pom.xml +++ b/libraries-server/pom.xml @@ -1,9 +1,10 @@ 4.0.0 - com.baeldung libraries-server 0.0.1-SNAPSHOT + libraries-server + com.baeldung parent-modules diff --git a/linkrest/pom.xml b/linkrest/pom.xml index a27caea1ff..073a173aff 100644 --- a/linkrest/pom.xml +++ b/linkrest/pom.xml @@ -1,9 +1,9 @@ 4.0.0 - com.baeldung linkrest 0.0.1-SNAPSHOT + linkrest war diff --git a/logging-modules/log4j/pom.xml b/logging-modules/log4j/pom.xml index 1b27e03445..40db69fb94 100644 --- a/logging-modules/log4j/pom.xml +++ b/logging-modules/log4j/pom.xml @@ -6,6 +6,7 @@ com.baeldung log4j 1.0-SNAPSHOT + log4j com.baeldung diff --git a/logging-modules/log4j2/pom.xml b/logging-modules/log4j2/pom.xml index 65da318636..d46f92dcd6 100644 --- a/logging-modules/log4j2/pom.xml +++ b/logging-modules/log4j2/pom.xml @@ -3,7 +3,8 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 log4j2 - + log4j2 + com.baeldung parent-modules diff --git a/maven-archetype/pom.xml b/maven-archetype/pom.xml index f7871c81ea..73ddc78fc7 100644 --- a/maven-archetype/pom.xml +++ b/maven-archetype/pom.xml @@ -5,9 +5,10 @@ com.baeldung.archetypes maven-archetype 1.0-SNAPSHOT + maven-archetype maven-archetype Archetype used to generate rest application based on jaxrs 2.1 - + diff --git a/maven-polyglot/maven-polyglot-json-extension/pom.xml b/maven-polyglot/maven-polyglot-json-extension/pom.xml index d5c5b7ab55..fe1e025d1f 100644 --- a/maven-polyglot/maven-polyglot-json-extension/pom.xml +++ b/maven-polyglot/maven-polyglot-json-extension/pom.xml @@ -3,11 +3,11 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - com.baeldung.maven.polyglot maven-polyglot-json-extension 1.0-SNAPSHOT - + maven-polyglot-json-extension + 1.8 1.8 diff --git a/maven/pom.xml b/maven/pom.xml index 4bec533226..01fd28db74 100644 --- a/maven/pom.xml +++ b/maven/pom.xml @@ -4,6 +4,7 @@ com.baeldung maven 0.0.1-SNAPSHOT + maven war diff --git a/maven/versions-maven-plugin/pom.xml b/maven/versions-maven-plugin/pom.xml index 295c77b860..dc0cba75f9 100644 --- a/maven/versions-maven-plugin/pom.xml +++ b/maven/versions-maven-plugin/pom.xml @@ -3,9 +3,10 @@ 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 + versions-maven-plugin 0.0.1-SNAPSHOT - + versions-maven-plugin + 1.15 diff --git a/mesos-marathon/pom.xml b/mesos-marathon/pom.xml index f92c00892b..dee8eca10d 100644 --- a/mesos-marathon/pom.xml +++ b/mesos-marathon/pom.xml @@ -5,7 +5,8 @@ com.baeldung mesos-marathon 0.0.1-SNAPSHOT - + mesos-marathon + parent-boot-1 com.baeldung diff --git a/metrics/pom.xml b/metrics/pom.xml index 9cf1ec588f..79d340aa49 100644 --- a/metrics/pom.xml +++ b/metrics/pom.xml @@ -3,7 +3,8 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 metrics - + metrics + parent-modules com.baeldung diff --git a/microprofile/pom.xml b/microprofile/pom.xml index d75b6443ed..52df348ace 100644 --- a/microprofile/pom.xml +++ b/microprofile/pom.xml @@ -5,6 +5,7 @@ com.baeldung microprofile 1.0-SNAPSHOT + microprofile war diff --git a/msf4j/pom.xml b/msf4j/pom.xml index 9a6483772b..4a6f63159d 100644 --- a/msf4j/pom.xml +++ b/msf4j/pom.xml @@ -5,6 +5,7 @@ com.baeldung.msf4j msf4j 0.0.1-SNAPSHOT + msf4j parent-modules diff --git a/muleesb/pom.xml b/muleesb/pom.xml index b34123567a..4b74b6d4f4 100644 --- a/muleesb/pom.xml +++ b/muleesb/pom.xml @@ -6,9 +6,9 @@ com.mycompany muleesb 1.0.0-SNAPSHOT - mule - Mule muleesb Application - + muleesb + mule + com.baeldung parent-modules diff --git a/mybatis/pom.xml b/mybatis/pom.xml index aa9ff9e288..4e63d14ded 100644 --- a/mybatis/pom.xml +++ b/mybatis/pom.xml @@ -5,7 +5,8 @@ com.baeldung mybatis 1.0.0-SNAPSHOT - + mybatis + com.baeldung parent-modules diff --git a/optaplanner/pom.xml b/optaplanner/pom.xml index 22abbedc8c..fbce0ea072 100644 --- a/optaplanner/pom.xml +++ b/optaplanner/pom.xml @@ -2,14 +2,15 @@ + 4.0.0 + optaplanner + optaplanner + parent-modules com.baeldung 1.0.0-SNAPSHOT - 4.0.0 - - optaplanner diff --git a/parent-boot-1/pom.xml b/parent-boot-1/pom.xml index 171806390d..53f91f975d 100644 --- a/parent-boot-1/pom.xml +++ b/parent-boot-1/pom.xml @@ -3,6 +3,7 @@ 4.0.0 parent-boot-1 0.0.1-SNAPSHOT + parent-boot-1 pom Parent for all Spring Boot 1.x modules diff --git a/parent-boot-2/pom.xml b/parent-boot-2/pom.xml index 67837e1a4e..89afd79bf4 100644 --- a/parent-boot-2/pom.xml +++ b/parent-boot-2/pom.xml @@ -3,6 +3,7 @@ 4.0.0 parent-boot-2 0.0.1-SNAPSHOT + parent-boot-2 pom Parent for all Spring Boot 2 modules diff --git a/patterns/design-patterns/pom.xml b/patterns/design-patterns/pom.xml index dc2631b36e..ac201ad653 100644 --- a/patterns/design-patterns/pom.xml +++ b/patterns/design-patterns/pom.xml @@ -4,7 +4,9 @@ 4.0.0 design-patterns 1.0 - jar + design-patterns + jar + com.baeldung patterns diff --git a/patterns/front-controller/pom.xml b/patterns/front-controller/pom.xml index 435b0dd9cd..bb003dd00a 100644 --- a/patterns/front-controller/pom.xml +++ b/patterns/front-controller/pom.xml @@ -3,6 +3,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 front-controller + front-controller war diff --git a/patterns/intercepting-filter/pom.xml b/patterns/intercepting-filter/pom.xml index fa94d5d1fd..33589dc242 100644 --- a/patterns/intercepting-filter/pom.xml +++ b/patterns/intercepting-filter/pom.xml @@ -2,8 +2,8 @@ 4.0.0 - intercepting-filter + intercepting-filter war diff --git a/patterns/pom.xml b/patterns/pom.xml index df09f1836a..bc1f5173e2 100644 --- a/patterns/pom.xml +++ b/patterns/pom.xml @@ -4,6 +4,7 @@ 4.0.0 patterns pom + patterns com.baeldung diff --git a/performance-tests/pom.xml b/performance-tests/pom.xml index 8c9d027724..7d77c2a0e3 100644 --- a/performance-tests/pom.xml +++ b/performance-tests/pom.xml @@ -4,7 +4,8 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 performance-tests - + performance-tests + parent-modules com.baeldung diff --git a/persistence-modules/hbase/pom.xml b/persistence-modules/hbase/pom.xml index ffd1464482..daf0db5291 100644 --- a/persistence-modules/hbase/pom.xml +++ b/persistence-modules/hbase/pom.xml @@ -3,6 +3,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 hbase + hbase parent-modules diff --git a/persistence-modules/hibernate5/pom.xml b/persistence-modules/hibernate5/pom.xml index 24f4055a82..363e2153b6 100644 --- a/persistence-modules/hibernate5/pom.xml +++ b/persistence-modules/hibernate5/pom.xml @@ -5,6 +5,7 @@ com.baeldung hibernate5 0.0.1-SNAPSHOT + hibernate5 com.baeldung diff --git a/persistence-modules/java-cassandra/pom.xml b/persistence-modules/java-cassandra/pom.xml index 36ec6b5ac8..aac5d49547 100644 --- a/persistence-modules/java-cassandra/pom.xml +++ b/persistence-modules/java-cassandra/pom.xml @@ -4,6 +4,7 @@ com.baeldung java-cassandra 1.0.0-SNAPSHOT + java-cassandra com.baeldung diff --git a/persistence-modules/java-cockroachdb/pom.xml b/persistence-modules/java-cockroachdb/pom.xml index 870707c750..2a92934a6e 100644 --- a/persistence-modules/java-cockroachdb/pom.xml +++ b/persistence-modules/java-cockroachdb/pom.xml @@ -5,6 +5,7 @@ com.baeldung java-cockroachdb 1.0-SNAPSHOT + java-cockroachdb parent-modules diff --git a/persistence-modules/java-jdbi/pom.xml b/persistence-modules/java-jdbi/pom.xml index 885906fcd0..9281f4fd9d 100644 --- a/persistence-modules/java-jdbi/pom.xml +++ b/persistence-modules/java-jdbi/pom.xml @@ -4,6 +4,7 @@ 4.0.0 java-jdbi 1.0-SNAPSHOT + java-jdbi parent-modules diff --git a/persistence-modules/java-jpa/pom.xml b/persistence-modules/java-jpa/pom.xml index 78764f7148..ddab51a2e2 100644 --- a/persistence-modules/java-jpa/pom.xml +++ b/persistence-modules/java-jpa/pom.xml @@ -2,15 +2,16 @@ + 4.0.0 + java-jpa + java-jpa + parent-modules com.baeldung 1.0.0-SNAPSHOT ../../pom.xml - 4.0.0 - - java-jpa diff --git a/persistence-modules/java-mongodb/pom.xml b/persistence-modules/java-mongodb/pom.xml index bbc48f54c2..9658ef567f 100644 --- a/persistence-modules/java-mongodb/pom.xml +++ b/persistence-modules/java-mongodb/pom.xml @@ -5,6 +5,7 @@ com.baeldung java-mongodb 1.0-SNAPSHOT + java-mongodb com.baeldung diff --git a/persistence-modules/jnosql/jnosql-artemis/pom.xml b/persistence-modules/jnosql/jnosql-artemis/pom.xml index 9c2bfd1ba0..8a978fb179 100644 --- a/persistence-modules/jnosql/jnosql-artemis/pom.xml +++ b/persistence-modules/jnosql/jnosql-artemis/pom.xml @@ -3,6 +3,9 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 + jnosql-artemis + jnosql-artemis + war com.baeldung.jnosql @@ -10,9 +13,6 @@ 1.0-SNAPSHOT - jnosql-artemis - war - 2.4.2 false diff --git a/persistence-modules/jnosql/jnosql-diana/pom.xml b/persistence-modules/jnosql/jnosql-diana/pom.xml index 767defb2a8..126f0314d9 100644 --- a/persistence-modules/jnosql/jnosql-diana/pom.xml +++ b/persistence-modules/jnosql/jnosql-diana/pom.xml @@ -3,15 +3,15 @@ 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 - + jnosql-diana + jnosql-diana + com.baeldung.jnosql jnosql 1.0-SNAPSHOT - jnosql-diana - diff --git a/persistence-modules/jnosql/pom.xml b/persistence-modules/jnosql/pom.xml index c87ad3cf4b..5fb29a3b9c 100644 --- a/persistence-modules/jnosql/pom.xml +++ b/persistence-modules/jnosql/pom.xml @@ -3,10 +3,10 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - com.baeldung.jnosql jnosql 1.0-SNAPSHOT + jnosql pom diff --git a/persistence-modules/liquibase/pom.xml b/persistence-modules/liquibase/pom.xml index cb2bee8d48..b06d38e6a0 100644 --- a/persistence-modules/liquibase/pom.xml +++ b/persistence-modules/liquibase/pom.xml @@ -3,6 +3,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 liquibase + liquibase parent-modules diff --git a/persistence-modules/orientdb/pom.xml b/persistence-modules/orientdb/pom.xml index e4bc9a0585..a8ac3fb789 100644 --- a/persistence-modules/orientdb/pom.xml +++ b/persistence-modules/orientdb/pom.xml @@ -4,8 +4,8 @@ 4.0.0 orientdb 0.0.1-SNAPSHOT + orientdb jar - intro-orientdb introduction to the OrientDB Java APIs diff --git a/persistence-modules/spring-boot-h2/spring-boot-h2-database/pom.xml b/persistence-modules/spring-boot-h2/spring-boot-h2-database/pom.xml index 4d677ab0d4..6ebc75de8d 100644 --- a/persistence-modules/spring-boot-h2/spring-boot-h2-database/pom.xml +++ b/persistence-modules/spring-boot-h2/spring-boot-h2-database/pom.xml @@ -3,10 +3,10 @@ xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - com.baeldung.h2db spring-boot-h2-database 0.0.1-SNAPSHOT + spring-boot-h2-database jar Demo Spring Boot applications that starts H2 in memory database diff --git a/persistence-modules/spring-boot-persistence/pom.xml b/persistence-modules/spring-boot-persistence/pom.xml index 80472fdd57..0ea42b1cb7 100644 --- a/persistence-modules/spring-boot-persistence/pom.xml +++ b/persistence-modules/spring-boot-persistence/pom.xml @@ -2,11 +2,11 @@ - 4.0.0 - + 4.0.0 com.baeldung spring-boot-persistence 0.1.0 + spring-boot-persistence parent-boot-2 diff --git a/persistence-modules/spring-data-gemfire/pom.xml b/persistence-modules/spring-data-gemfire/pom.xml index 34346c502f..292b7387ac 100644 --- a/persistence-modules/spring-data-gemfire/pom.xml +++ b/persistence-modules/spring-data-gemfire/pom.xml @@ -5,6 +5,7 @@ com.baeldung spring-data-gemfire 1.0.0-SNAPSHOT + spring-data-gemfire jar diff --git a/persistence-modules/spring-data-jpa/pom.xml b/persistence-modules/spring-data-jpa/pom.xml index 643210ab89..786e587734 100644 --- a/persistence-modules/spring-data-jpa/pom.xml +++ b/persistence-modules/spring-data-jpa/pom.xml @@ -5,6 +5,7 @@ 4.0.0 com.baeldung spring-data-jpa + spring-data-jpa parent-boot-2 diff --git a/persistence-modules/spring-data-keyvalue/pom.xml b/persistence-modules/spring-data-keyvalue/pom.xml index 6675595f2b..1fee0a88d4 100644 --- a/persistence-modules/spring-data-keyvalue/pom.xml +++ b/persistence-modules/spring-data-keyvalue/pom.xml @@ -2,6 +2,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 spring-data-keyvalue + spring-data-keyvalue parent-boot-2 diff --git a/persistence-modules/spring-data-neo4j/pom.xml b/persistence-modules/spring-data-neo4j/pom.xml index 2be4df71be..1e5d51ddf2 100644 --- a/persistence-modules/spring-data-neo4j/pom.xml +++ b/persistence-modules/spring-data-neo4j/pom.xml @@ -3,7 +3,8 @@ 4.0.0 spring-data-neo4j 1.0 - + spring-data-neo4j + com.baeldung parent-modules diff --git a/persistence-modules/spring-data-redis/pom.xml b/persistence-modules/spring-data-redis/pom.xml index bee3d683b8..683f874b6c 100644 --- a/persistence-modules/spring-data-redis/pom.xml +++ b/persistence-modules/spring-data-redis/pom.xml @@ -4,6 +4,7 @@ com.baeldung spring-data-redis 1.0 + spring-data-redis jar diff --git a/protobuffer/pom.xml b/protobuffer/pom.xml index ff443a1615..d9e6cb26e4 100644 --- a/protobuffer/pom.xml +++ b/protobuffer/pom.xml @@ -3,7 +3,8 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 protobuffer - + protobuffer + parent-modules com.baeldung diff --git a/reactor-core/pom.xml b/reactor-core/pom.xml index cf720ad6ea..db9550df7b 100644 --- a/reactor-core/pom.xml +++ b/reactor-core/pom.xml @@ -1,11 +1,11 @@ 4.0.0 - org.baeldung reactor-core 0.0.1-SNAPSHOT - + reactor-core + com.baeldung parent-modules diff --git a/rxjava-2/pom.xml b/rxjava-2/pom.xml index a18b096b6d..3b4c167f3a 100644 --- a/rxjava-2/pom.xml +++ b/rxjava-2/pom.xml @@ -2,10 +2,10 @@ 4.0.0 - rxjava-2 1.0-SNAPSHOT - + rxjava-2 + com.baeldung parent-java diff --git a/rxjava/pom.xml b/rxjava/pom.xml index b316001d87..596a5196da 100644 --- a/rxjava/pom.xml +++ b/rxjava/pom.xml @@ -2,10 +2,10 @@ 4.0.0 - rxjava 1.0-SNAPSHOT - + rxjava + com.baeldung parent-java diff --git a/spring-5-data-reactive/pom.xml b/spring-5-data-reactive/pom.xml index 5c723c6e29..aa73cf11ae 100644 --- a/spring-5-data-reactive/pom.xml +++ b/spring-5-data-reactive/pom.xml @@ -3,6 +3,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 spring-5-data-reactive + spring-5-data-reactive jar diff --git a/spring-amqp-simple/pom.xml b/spring-amqp-simple/pom.xml index ea9c227d8c..57d84acee6 100644 --- a/spring-amqp-simple/pom.xml +++ b/spring-amqp-simple/pom.xml @@ -5,6 +5,7 @@ com.baeldung spring-amqp-simple 1.0.0-SNAPSHOT + spring-amqp-simple parent-boot-1 diff --git a/spring-boot-admin/pom.xml b/spring-boot-admin/pom.xml index 58cea728cc..23852dee57 100644 --- a/spring-boot-admin/pom.xml +++ b/spring-boot-admin/pom.xml @@ -3,6 +3,7 @@ 4.0.0 spring-boot-admin 0.0.1-SNAPSHOT + spring-boot-admin pom diff --git a/spring-boot-autoconfiguration/pom.xml b/spring-boot-autoconfiguration/pom.xml index b88587f731..1c3d8796ed 100644 --- a/spring-boot-autoconfiguration/pom.xml +++ b/spring-boot-autoconfiguration/pom.xml @@ -5,7 +5,7 @@ spring-boot-autoconfiguration 0.0.1-SNAPSHOT war - spring-boot-auto-configuration + spring-boot-autoconfiguration This is simple boot application demonstrating a custom auto-configuration diff --git a/spring-boot-camel/pom.xml b/spring-boot-camel/pom.xml index 19a0bec809..8bab0ed5c8 100644 --- a/spring-boot-camel/pom.xml +++ b/spring-boot-camel/pom.xml @@ -5,7 +5,8 @@ com.example spring-boot-camel 0.0.1-SNAPSHOT - + spring-boot-camel + com.baeldung parent-modules diff --git a/spring-boot-crud/pom.xml b/spring-boot-crud/pom.xml index f803a7e70b..749bf9cb5a 100644 --- a/spring-boot-crud/pom.xml +++ b/spring-boot-crud/pom.xml @@ -3,10 +3,10 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 4.0.0 - com.baeldung.spring-boot-crud spring-boot-crud 0.1.0 + spring-boot-crud org.springframework.boot diff --git a/spring-boot-ctx-fluent/pom.xml b/spring-boot-ctx-fluent/pom.xml index f9b691aea7..b238374612 100644 --- a/spring-boot-ctx-fluent/pom.xml +++ b/spring-boot-ctx-fluent/pom.xml @@ -1,10 +1,10 @@ 4.0.0 - com.baeldung spring-boot-ctx-fluent 0.0.1-SNAPSHOT + spring-boot-ctx-fluent jar diff --git a/spring-boot-custom-starter/greeter-library/pom.xml b/spring-boot-custom-starter/greeter-library/pom.xml index 3717ba005c..7e0c5c4d22 100644 --- a/spring-boot-custom-starter/greeter-library/pom.xml +++ b/spring-boot-custom-starter/greeter-library/pom.xml @@ -1,10 +1,11 @@ 4.0.0 - com.baeldung greeter-library 0.0.1-SNAPSHOT + greeter-library + spring-boot-custom-starter com.baeldung diff --git a/spring-boot-custom-starter/greeter-spring-boot-autoconfigure/pom.xml b/spring-boot-custom-starter/greeter-spring-boot-autoconfigure/pom.xml index 5862bdd6c8..1e4ee698c6 100644 --- a/spring-boot-custom-starter/greeter-spring-boot-autoconfigure/pom.xml +++ b/spring-boot-custom-starter/greeter-spring-boot-autoconfigure/pom.xml @@ -1,10 +1,10 @@ 4.0.0 - com.baeldung greeter-spring-boot-autoconfigure 0.0.1-SNAPSHOT + greeter-spring-boot-autoconfigure spring-boot-custom-starter diff --git a/spring-boot-custom-starter/greeter-spring-boot-sample-app/pom.xml b/spring-boot-custom-starter/greeter-spring-boot-sample-app/pom.xml index 88c5d1caf5..91cc41d669 100644 --- a/spring-boot-custom-starter/greeter-spring-boot-sample-app/pom.xml +++ b/spring-boot-custom-starter/greeter-spring-boot-sample-app/pom.xml @@ -1,10 +1,10 @@ 4.0.0 - com.baeldung greeter-spring-boot-sample-app 0.0.1-SNAPSHOT + greeter-spring-boot-sample-app spring-boot-custom-starter diff --git a/spring-boot-custom-starter/greeter-spring-boot-starter/pom.xml b/spring-boot-custom-starter/greeter-spring-boot-starter/pom.xml index e71882db29..560d6fa79b 100644 --- a/spring-boot-custom-starter/greeter-spring-boot-starter/pom.xml +++ b/spring-boot-custom-starter/greeter-spring-boot-starter/pom.xml @@ -1,10 +1,10 @@ 4.0.0 - com.baeldung greeter-spring-boot-starter 0.0.1-SNAPSHOT + greeter-spring-boot-starter spring-boot-custom-starter diff --git a/spring-boot-custom-starter/greeter/pom.xml b/spring-boot-custom-starter/greeter/pom.xml index 3cfd6da09e..95fcaa66c8 100644 --- a/spring-boot-custom-starter/greeter/pom.xml +++ b/spring-boot-custom-starter/greeter/pom.xml @@ -1,10 +1,11 @@ 4.0.0 - com.baeldung greeter 0.0.1-SNAPSHOT + greeter + parent-boot-1 com.baeldung diff --git a/spring-boot-custom-starter/pom.xml b/spring-boot-custom-starter/pom.xml index 97b33ce2b8..9c03cfdd0e 100644 --- a/spring-boot-custom-starter/pom.xml +++ b/spring-boot-custom-starter/pom.xml @@ -4,6 +4,7 @@ com.baeldung spring-boot-custom-starter 0.0.1-SNAPSHOT + spring-boot-custom-starter pom diff --git a/spring-boot-disable-console-logging/disabling-console-jul/pom.xml b/spring-boot-disable-console-logging/disabling-console-jul/pom.xml index ceac0616e9..fbcd0768f9 100644 --- a/spring-boot-disable-console-logging/disabling-console-jul/pom.xml +++ b/spring-boot-disable-console-logging/disabling-console-jul/pom.xml @@ -2,7 +2,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 disabling-console-jul - + disabling-console-jul diff --git a/spring-boot-disable-console-logging/disabling-console-log4j2/pom.xml b/spring-boot-disable-console-logging/disabling-console-log4j2/pom.xml index d6e9a8b5e5..6f3f01669e 100644 --- a/spring-boot-disable-console-logging/disabling-console-log4j2/pom.xml +++ b/spring-boot-disable-console-logging/disabling-console-log4j2/pom.xml @@ -2,7 +2,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 disabling-console-log4j2 - + disabling-console-log4j2 diff --git a/spring-boot-disable-console-logging/disabling-console-logback/pom.xml b/spring-boot-disable-console-logging/disabling-console-logback/pom.xml index f18066ea03..fef0a1f4c6 100644 --- a/spring-boot-disable-console-logging/disabling-console-logback/pom.xml +++ b/spring-boot-disable-console-logging/disabling-console-logback/pom.xml @@ -1,11 +1,13 @@ 4.0.0 + disabling-console-logback + disabling-console-logback + com.baeldung spring-boot-disable-console-logging 0.0.1-SNAPSHOT - disabling-console-logback diff --git a/spring-boot-disable-console-logging/pom.xml b/spring-boot-disable-console-logging/pom.xml index ec84372f99..63ed129347 100644 --- a/spring-boot-disable-console-logging/pom.xml +++ b/spring-boot-disable-console-logging/pom.xml @@ -2,6 +2,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 spring-boot-disable-console-logging + spring-boot-disable-console-logging pom Projects for Disabling Spring Boot Console Logging tutorials diff --git a/spring-boot-logging-log4j2/pom.xml b/spring-boot-logging-log4j2/pom.xml index 38dc5fb341..ad678a14cf 100644 --- a/spring-boot-logging-log4j2/pom.xml +++ b/spring-boot-logging-log4j2/pom.xml @@ -2,9 +2,9 @@ 4.0.0 - spring-boot-logging-log4j2 jar + spring-boot-logging-log4j2 Demo project for Spring Boot Logging with Log4J2 diff --git a/spring-boot-property-exp/property-exp-custom-config/pom.xml b/spring-boot-property-exp/property-exp-custom-config/pom.xml index ab22c5ad30..9988924408 100644 --- a/spring-boot-property-exp/property-exp-custom-config/pom.xml +++ b/spring-boot-property-exp/property-exp-custom-config/pom.xml @@ -1,11 +1,10 @@ 4.0.0 - property-exp-custom - com.baeldung property-exp-custom-config 0.0.1-SNAPSHOT + property-exp-custom-config jar diff --git a/spring-boot-property-exp/property-exp-default-config/pom.xml b/spring-boot-property-exp/property-exp-default-config/pom.xml index 4ede36e61a..7892288f45 100644 --- a/spring-boot-property-exp/property-exp-default-config/pom.xml +++ b/spring-boot-property-exp/property-exp-default-config/pom.xml @@ -1,11 +1,10 @@ 4.0.0 - property-exp-default - com.baeldung property-exp-default-config 0.0.1-SNAPSHOT + property-exp-default-config jar diff --git a/spring-cloud-bus/pom.xml b/spring-cloud-bus/pom.xml index d493c4e984..784e4cbae6 100644 --- a/spring-cloud-bus/pom.xml +++ b/spring-cloud-bus/pom.xml @@ -7,6 +7,7 @@ spring-cloud-bus 1.0.0-SNAPSHOT pom + spring-cloud-bus parent-boot-1 diff --git a/spring-cloud-data-flow/etl/pom.xml b/spring-cloud-data-flow/etl/pom.xml index 2b904f6e0d..e203999ee9 100644 --- a/spring-cloud-data-flow/etl/pom.xml +++ b/spring-cloud-data-flow/etl/pom.xml @@ -5,7 +5,8 @@ etl-spring-cloud-data-flow 0.0.1-SNAPSHOT pom - + etl-spring-cloud-data-flow + org.baeldung.spring.cloud spring-cloud-data-flow diff --git a/spring-cloud-data-flow/pom.xml b/spring-cloud-data-flow/pom.xml index 5a007f3c7d..dd1ceed71a 100644 --- a/spring-cloud-data-flow/pom.xml +++ b/spring-cloud-data-flow/pom.xml @@ -5,7 +5,8 @@ spring-cloud-data-flow 0.0.1-SNAPSHOT pom - + spring-cloud-data-flow + com.baeldung parent-modules diff --git a/spring-cloud/spring-cloud-archaius/dynamodb-config/pom.xml b/spring-cloud/spring-cloud-archaius/dynamodb-config/pom.xml index 3ffbf8f619..96f6c8711e 100644 --- a/spring-cloud/spring-cloud-archaius/dynamodb-config/pom.xml +++ b/spring-cloud/spring-cloud-archaius/dynamodb-config/pom.xml @@ -3,6 +3,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 dynamodb-config + dynamodb-config jar diff --git a/spring-cloud/spring-cloud-archaius/jdbc-config/pom.xml b/spring-cloud/spring-cloud-archaius/jdbc-config/pom.xml index bb283576d8..59dea4890e 100644 --- a/spring-cloud/spring-cloud-archaius/jdbc-config/pom.xml +++ b/spring-cloud/spring-cloud-archaius/jdbc-config/pom.xml @@ -3,6 +3,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 jdbc-config + jdbc-config jar diff --git a/spring-cloud/spring-cloud-archaius/zookeeper-config/pom.xml b/spring-cloud/spring-cloud-archaius/zookeeper-config/pom.xml index 8f8ec99ad8..51010eefb2 100644 --- a/spring-cloud/spring-cloud-archaius/zookeeper-config/pom.xml +++ b/spring-cloud/spring-cloud-archaius/zookeeper-config/pom.xml @@ -3,6 +3,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 zookeeper-config + zookeeper-config jar diff --git a/spring-cloud/spring-cloud-aws/pom.xml b/spring-cloud/spring-cloud-aws/pom.xml index 09518483a4..7edabd03f5 100644 --- a/spring-cloud/spring-cloud-aws/pom.xml +++ b/spring-cloud/spring-cloud-aws/pom.xml @@ -5,7 +5,7 @@ com.baeldung.spring.cloud spring-cloud-aws jar - Spring Cloud AWS + spring-cloud-aws Spring Cloud AWS Examples diff --git a/spring-cloud/spring-cloud-bootstrap/config/pom.xml b/spring-cloud/spring-cloud-bootstrap/config/pom.xml index 14a926fc2c..1379af0b05 100644 --- a/spring-cloud/spring-cloud-bootstrap/config/pom.xml +++ b/spring-cloud/spring-cloud-bootstrap/config/pom.xml @@ -4,6 +4,7 @@ 4.0.0 config 1.0.0-SNAPSHOT + config parent-boot-1 diff --git a/spring-cloud/spring-cloud-bootstrap/discovery/pom.xml b/spring-cloud/spring-cloud-bootstrap/discovery/pom.xml index f94d8829f6..735d3745d7 100644 --- a/spring-cloud/spring-cloud-bootstrap/discovery/pom.xml +++ b/spring-cloud/spring-cloud-bootstrap/discovery/pom.xml @@ -2,9 +2,9 @@ 4.0.0 - discovery 1.0.0-SNAPSHOT + discovery parent-boot-1 diff --git a/spring-cloud/spring-cloud-bootstrap/gateway/pom.xml b/spring-cloud/spring-cloud-bootstrap/gateway/pom.xml index fc69c16738..2efa926e3a 100644 --- a/spring-cloud/spring-cloud-bootstrap/gateway/pom.xml +++ b/spring-cloud/spring-cloud-bootstrap/gateway/pom.xml @@ -4,6 +4,7 @@ 4.0.0 gateway 1.0.0-SNAPSHOT + gateway parent-boot-1 diff --git a/spring-cloud/spring-cloud-bootstrap/pom.xml b/spring-cloud/spring-cloud-bootstrap/pom.xml index 74801159eb..46460c0d74 100644 --- a/spring-cloud/spring-cloud-bootstrap/pom.xml +++ b/spring-cloud/spring-cloud-bootstrap/pom.xml @@ -4,6 +4,7 @@ 4.0.0 spring-cloud-bootstrap 1.0.0-SNAPSHOT + spring-cloud-bootstrap pom diff --git a/spring-cloud/spring-cloud-bootstrap/svc-book/pom.xml b/spring-cloud/spring-cloud-bootstrap/svc-book/pom.xml index c0d920d373..eb855a91e3 100644 --- a/spring-cloud/spring-cloud-bootstrap/svc-book/pom.xml +++ b/spring-cloud/spring-cloud-bootstrap/svc-book/pom.xml @@ -2,10 +2,10 @@ 4.0.0 - com.baeldung.spring.cloud svc-book 1.0.0-SNAPSHOT + svc-book parent-boot-1 diff --git a/spring-cloud/spring-cloud-bootstrap/svc-rating/pom.xml b/spring-cloud/spring-cloud-bootstrap/svc-rating/pom.xml index 3aa2db8f65..7c1e93bad1 100644 --- a/spring-cloud/spring-cloud-bootstrap/svc-rating/pom.xml +++ b/spring-cloud/spring-cloud-bootstrap/svc-rating/pom.xml @@ -2,10 +2,10 @@ 4.0.0 - com.baeldung.spring.cloud svc-rating 1.0.0-SNAPSHOT + svc-rating parent-boot-1 diff --git a/spring-cloud/spring-cloud-bootstrap/zipkin/pom.xml b/spring-cloud/spring-cloud-bootstrap/zipkin/pom.xml index 8735e24d48..1bf9ecb9e7 100644 --- a/spring-cloud/spring-cloud-bootstrap/zipkin/pom.xml +++ b/spring-cloud/spring-cloud-bootstrap/zipkin/pom.xml @@ -4,6 +4,7 @@ 4.0.0 zipkin 1.0.0-SNAPSHOT + zipkin parent-boot-1 diff --git a/spring-cloud/spring-cloud-config/client/pom.xml b/spring-cloud/spring-cloud-config/client/pom.xml index 800a496a82..c55f9bc471 100644 --- a/spring-cloud/spring-cloud-config/client/pom.xml +++ b/spring-cloud/spring-cloud-config/client/pom.xml @@ -3,13 +3,14 @@ xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - + client + client + com.baeldung.spring.cloud spring-cloud-config 1.0-SNAPSHOT - client diff --git a/spring-cloud/spring-cloud-config/pom.xml b/spring-cloud/spring-cloud-config/pom.xml index b28828bf37..1a4efc7a60 100644 --- a/spring-cloud/spring-cloud-config/pom.xml +++ b/spring-cloud/spring-cloud-config/pom.xml @@ -5,6 +5,7 @@ com.baeldung.spring.cloud spring-cloud-config 1.0-SNAPSHOT + spring-cloud-config pom diff --git a/spring-cloud/spring-cloud-config/server/pom.xml b/spring-cloud/spring-cloud-config/server/pom.xml index 7bbb903cf9..b4be7663e2 100644 --- a/spring-cloud/spring-cloud-config/server/pom.xml +++ b/spring-cloud/spring-cloud-config/server/pom.xml @@ -3,13 +3,14 @@ xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - + server + server + com.baeldung.spring.cloud spring-cloud-config 1.0-SNAPSHOT - server diff --git a/spring-cloud/spring-cloud-connectors-heroku/pom.xml b/spring-cloud/spring-cloud-connectors-heroku/pom.xml index f00c9eb1fc..d2e9292511 100644 --- a/spring-cloud/spring-cloud-connectors-heroku/pom.xml +++ b/spring-cloud/spring-cloud-connectors-heroku/pom.xml @@ -5,6 +5,7 @@ com.baeldung.spring.cloud spring-cloud-connectors-heroku 1.0.0-SNAPSHOT + spring-cloud-connectors-heroku parent-boot-1 diff --git a/spring-cloud/spring-cloud-contract/pom.xml b/spring-cloud/spring-cloud-contract/pom.xml index 5dde6a7a99..3563d0ee58 100644 --- a/spring-cloud/spring-cloud-contract/pom.xml +++ b/spring-cloud/spring-cloud-contract/pom.xml @@ -6,6 +6,7 @@ com.baeldung.spring.cloud spring-cloud-contract 1.0.0-SNAPSHOT + spring-cloud-contract com.baeldung.spring.cloud diff --git a/spring-cloud/spring-cloud-eureka/pom.xml b/spring-cloud/spring-cloud-eureka/pom.xml index 7f7e2650d5..99d8c0ed40 100644 --- a/spring-cloud/spring-cloud-eureka/pom.xml +++ b/spring-cloud/spring-cloud-eureka/pom.xml @@ -6,7 +6,7 @@ spring-cloud-eureka 1.0.0-SNAPSHOT pom - Spring Cloud Eureka + spring-cloud-eureka Spring Cloud Eureka Server and Sample Clients diff --git a/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-client/pom.xml b/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-client/pom.xml index 0bf9547aff..5378095af0 100644 --- a/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-client/pom.xml +++ b/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-client/pom.xml @@ -2,12 +2,10 @@ 4.0.0 - spring-cloud-eureka-client 1.0.0-SNAPSHOT jar - - Spring Cloud Eureka Client + spring-cloud-eureka-client Spring Cloud Eureka Sample Client diff --git a/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client/pom.xml b/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client/pom.xml index d572b10d40..f2057c8a76 100644 --- a/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client/pom.xml +++ b/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-feign-client/pom.xml @@ -5,7 +5,7 @@ spring-cloud-eureka-feign-client 1.0.0-SNAPSHOT jar - Spring Cloud Eureka Feign Client + spring-cloud-eureka-feign-client Spring Cloud Eureka - Sample Feign Client diff --git a/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-server/pom.xml b/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-server/pom.xml index da2c50d3c7..587aed6c49 100644 --- a/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-server/pom.xml +++ b/spring-cloud/spring-cloud-eureka/spring-cloud-eureka-server/pom.xml @@ -5,7 +5,7 @@ spring-cloud-eureka-server 1.0.0-SNAPSHOT jar - Spring Cloud Eureka Server + spring-cloud-eureka-server Spring Cloud Eureka Server Demo diff --git a/spring-cloud/spring-cloud-functions/pom.xml b/spring-cloud/spring-cloud-functions/pom.xml index 8b2b0ad385..5686fc8c64 100644 --- a/spring-cloud/spring-cloud-functions/pom.xml +++ b/spring-cloud/spring-cloud-functions/pom.xml @@ -3,13 +3,11 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - com.baeldung.spring - cloudfunction-aws + spring-cloud-functions 0.0.1-SNAPSHOT jar - - cloudfunction-aws + spring-cloud-functions Demo project for Spring Cloud Function diff --git a/spring-cloud/spring-cloud-gateway/pom.xml b/spring-cloud/spring-cloud-gateway/pom.xml index 4d8b57d4cf..c297d90896 100644 --- a/spring-cloud/spring-cloud-gateway/pom.xml +++ b/spring-cloud/spring-cloud-gateway/pom.xml @@ -4,7 +4,7 @@ 4.0.0 spring-cloud-gateway jar - Spring Cloud Gateway + spring-cloud-gateway com.baeldung.spring.cloud diff --git a/spring-cloud/spring-cloud-kubernetes/demo-backend/pom.xml b/spring-cloud/spring-cloud-kubernetes/demo-backend/pom.xml index 308a81fd74..f7b04baec3 100644 --- a/spring-cloud/spring-cloud-kubernetes/demo-backend/pom.xml +++ b/spring-cloud/spring-cloud-kubernetes/demo-backend/pom.xml @@ -3,7 +3,8 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 demo-backend - + demo-backend + com.baeldung.spring.cloud spring-cloud-kubernetes diff --git a/spring-cloud/spring-cloud-kubernetes/demo-frontend/pom.xml b/spring-cloud/spring-cloud-kubernetes/demo-frontend/pom.xml index 968529c648..da55ca5034 100644 --- a/spring-cloud/spring-cloud-kubernetes/demo-frontend/pom.xml +++ b/spring-cloud/spring-cloud-kubernetes/demo-frontend/pom.xml @@ -3,7 +3,8 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 demo-frontend - + demo-frontend + com.baeldung.spring.cloud spring-cloud-kubernetes diff --git a/spring-cloud/spring-cloud-kubernetes/pom.xml b/spring-cloud/spring-cloud-kubernetes/pom.xml index fd9f7b5876..984b3811dd 100644 --- a/spring-cloud/spring-cloud-kubernetes/pom.xml +++ b/spring-cloud/spring-cloud-kubernetes/pom.xml @@ -2,11 +2,11 @@ 4.0.0 - com.baeldung.spring.cloud spring-cloud-kubernetes 1.0-SNAPSHOT pom + spring-cloud-kubernetes demo-frontend diff --git a/spring-cloud/spring-cloud-security/auth-server/pom.xml b/spring-cloud/spring-cloud-security/auth-server/pom.xml index 92f92808f6..4b3f94b825 100644 --- a/spring-cloud/spring-cloud-security/auth-server/pom.xml +++ b/spring-cloud/spring-cloud-security/auth-server/pom.xml @@ -3,6 +3,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 auth-server + auth-server Spring Cloud Security APP Server Module diff --git a/spring-cloud/spring-cloud-task/pom.xml b/spring-cloud/spring-cloud-task/pom.xml index ef76d464bc..748cc378f1 100644 --- a/spring-cloud/spring-cloud-task/pom.xml +++ b/spring-cloud/spring-cloud-task/pom.xml @@ -6,6 +6,7 @@ spring-cloud-task 1.0.0-SNAPSHOT pom + spring-cloud-task parent-boot-1 diff --git a/spring-cloud/spring-cloud-zookeeper/pom.xml b/spring-cloud/spring-cloud-zookeeper/pom.xml index 4535c2072d..9661f2b71a 100644 --- a/spring-cloud/spring-cloud-zookeeper/pom.xml +++ b/spring-cloud/spring-cloud-zookeeper/pom.xml @@ -4,7 +4,8 @@ 4.0.0 spring-cloud-zookeeper pom - + spring-cloud-zookeeper + com.baeldung.spring.cloud spring-cloud diff --git a/spring-cloud/spring-cloud-zuul-eureka-integration/eureka-client/pom.xml b/spring-cloud/spring-cloud-zuul-eureka-integration/eureka-client/pom.xml index 6a5b7ddb55..c4f7ae704a 100644 --- a/spring-cloud/spring-cloud-zuul-eureka-integration/eureka-client/pom.xml +++ b/spring-cloud/spring-cloud-zuul-eureka-integration/eureka-client/pom.xml @@ -5,7 +5,7 @@ eureka-client 1.0.0-SNAPSHOT jar - Spring Cloud Eureka Client + eureka-client Spring Cloud Eureka Sample Client diff --git a/spring-cloud/spring-cloud-zuul-eureka-integration/eureka-server/pom.xml b/spring-cloud/spring-cloud-zuul-eureka-integration/eureka-server/pom.xml index e3c5109a26..0256ee7000 100644 --- a/spring-cloud/spring-cloud-zuul-eureka-integration/eureka-server/pom.xml +++ b/spring-cloud/spring-cloud-zuul-eureka-integration/eureka-server/pom.xml @@ -5,7 +5,7 @@ eureka-server 1.0.0-SNAPSHOT jar - Spring Cloud Eureka Server + eureka-server Spring Cloud Eureka Server Demo diff --git a/spring-cloud/spring-cloud-zuul-eureka-integration/pom.xml b/spring-cloud/spring-cloud-zuul-eureka-integration/pom.xml index 4d3687134f..edd7b9d99e 100644 --- a/spring-cloud/spring-cloud-zuul-eureka-integration/pom.xml +++ b/spring-cloud/spring-cloud-zuul-eureka-integration/pom.xml @@ -7,7 +7,7 @@ spring-cloud-zuul-eureka-integration 1.0.0-SNAPSHOT pom - Spring Cloud Zuul and Eureka Integration + spring-cloud-zuul-eureka-integration Spring Cloud Zuul and Eureka Integration diff --git a/spring-cloud/spring-cloud-zuul-eureka-integration/zuul-server/pom.xml b/spring-cloud/spring-cloud-zuul-eureka-integration/zuul-server/pom.xml index e64ceb501e..39f94efdf0 100644 --- a/spring-cloud/spring-cloud-zuul-eureka-integration/zuul-server/pom.xml +++ b/spring-cloud/spring-cloud-zuul-eureka-integration/zuul-server/pom.xml @@ -2,6 +2,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 zuul-server + zuul-server com.baeldung.spring.cloud diff --git a/spring-drools/pom.xml b/spring-drools/pom.xml index 8c65d5e34e..5bb2d6a8e9 100644 --- a/spring-drools/pom.xml +++ b/spring-drools/pom.xml @@ -5,7 +5,8 @@ com.baeldung spring-drools 1.0.0-SNAPSHOT - + spring-drools + com.baeldung parent-modules diff --git a/spring-ejb/spring-ejb-remote/pom.xml b/spring-ejb/spring-ejb-remote/pom.xml index 4756846cc8..797cc3ac68 100644 --- a/spring-ejb/spring-ejb-remote/pom.xml +++ b/spring-ejb/spring-ejb-remote/pom.xml @@ -4,7 +4,8 @@ 4.0.0 spring-ejb-remote ejb - + spring-ejb-remote + com.baeldung.spring.ejb spring-ejb diff --git a/spring-ejb/wildfly/pom.xml b/spring-ejb/wildfly/pom.xml index 8f7d4c287a..f50dad82f1 100644 --- a/spring-ejb/wildfly/pom.xml +++ b/spring-ejb/wildfly/pom.xml @@ -2,10 +2,10 @@ 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.wildfly - wildfly-example + wildfly 0.0.1-SNAPSHOT pom - wildfly-example + wildfly com.baeldung.spring.ejb diff --git a/spring-ejb/wildfly/widlfly-web/pom.xml b/spring-ejb/wildfly/widlfly-web/pom.xml index 559c5f1755..1dcb18a230 100644 --- a/spring-ejb/wildfly/widlfly-web/pom.xml +++ b/spring-ejb/wildfly/widlfly-web/pom.xml @@ -3,7 +3,8 @@ 4.0.0 widlfly-web war - + widlfly-web + com.baeldung.wildfly wildfly-example diff --git a/spring-ejb/wildfly/wildfly-ear/pom.xml b/spring-ejb/wildfly/wildfly-ear/pom.xml index d1e47ecd0f..dc9059370f 100644 --- a/spring-ejb/wildfly/wildfly-ear/pom.xml +++ b/spring-ejb/wildfly/wildfly-ear/pom.xml @@ -3,7 +3,8 @@ 4.0.0 wildfly-ear ear - + wildfly-ear + com.baeldung.wildfly wildfly-example diff --git a/spring-ejb/wildfly/wildfly-ejb-interfaces/pom.xml b/spring-ejb/wildfly/wildfly-ejb-interfaces/pom.xml index ec502f2ab3..0324aa8e47 100644 --- a/spring-ejb/wildfly/wildfly-ejb-interfaces/pom.xml +++ b/spring-ejb/wildfly/wildfly-ejb-interfaces/pom.xml @@ -2,7 +2,8 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 wildfly-ejb-interfaces - + wildfly-ejb-interfaces + com.baeldung.wildfly wildfly-example diff --git a/spring-ejb/wildfly/wildfly-ejb/pom.xml b/spring-ejb/wildfly/wildfly-ejb/pom.xml index 2c87ec8449..22bceef044 100644 --- a/spring-ejb/wildfly/wildfly-ejb/pom.xml +++ b/spring-ejb/wildfly/wildfly-ejb/pom.xml @@ -3,7 +3,8 @@ 4.0.0 wildfly-ejb ejb - + wildfly-ejb + com.baeldung.wildfly wildfly-example diff --git a/spring-ejb/wildfly/wildfly-jpa/pom.xml b/spring-ejb/wildfly/wildfly-jpa/pom.xml index 12cf2c81e4..6a0352c102 100644 --- a/spring-ejb/wildfly/wildfly-jpa/pom.xml +++ b/spring-ejb/wildfly/wildfly-jpa/pom.xml @@ -2,7 +2,8 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 wildfly-jpa - + wildfly-jpa + com.baeldung.wildfly wildfly-example diff --git a/spring-freemarker/pom.xml b/spring-freemarker/pom.xml index 4ff57e27f0..02f2a3fd06 100644 --- a/spring-freemarker/pom.xml +++ b/spring-freemarker/pom.xml @@ -5,7 +5,7 @@ spring-freemarker war 1.0-SNAPSHOT - Spring Freemarker Example + spring-freemarker com.baeldung diff --git a/spring-jersey/pom.xml b/spring-jersey/pom.xml index 872835177d..5e7b50d291 100644 --- a/spring-jersey/pom.xml +++ b/spring-jersey/pom.xml @@ -6,7 +6,8 @@ spring-jersey 0.1-SNAPSHOT war - + spring-jersey + com.baeldung parent-modules diff --git a/spring-jooq/pom.xml b/spring-jooq/pom.xml index 744ae34cc8..bbd6025418 100644 --- a/spring-jooq/pom.xml +++ b/spring-jooq/pom.xml @@ -2,7 +2,8 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 spring-jooq - + spring-jooq + parent-boot-1 com.baeldung diff --git a/spring-katharsis/pom.xml b/spring-katharsis/pom.xml index 39648a982c..756aae93d3 100644 --- a/spring-katharsis/pom.xml +++ b/spring-katharsis/pom.xml @@ -5,7 +5,8 @@ spring-katharsis 0.0.1-SNAPSHOT war - + spring-katharsis + parent-boot-1 com.baeldung diff --git a/spring-ldap/pom.xml b/spring-ldap/pom.xml index 3b2525d899..7399a84c2b 100644 --- a/spring-ldap/pom.xml +++ b/spring-ldap/pom.xml @@ -5,6 +5,7 @@ spring-ldap 0.1-SNAPSHOT jar + spring-ldap com.baeldung diff --git a/spring-mvc-simple/pom.xml b/spring-mvc-simple/pom.xml index e4e30183eb..8d7ad0fa7f 100644 --- a/spring-mvc-simple/pom.xml +++ b/spring-mvc-simple/pom.xml @@ -4,8 +4,7 @@ spring-mvc-simple war 0.0.1-SNAPSHOT - Spring MVC simple Maven Webapp - http://maven.apache.org + spring-mvc-simple com.baeldung diff --git a/spring-mybatis/pom.xml b/spring-mybatis/pom.xml index 7b8b66fef1..af70cb6377 100644 --- a/spring-mybatis/pom.xml +++ b/spring-mybatis/pom.xml @@ -5,8 +5,7 @@ spring-mybatis jar 0.0.1-SNAPSHOT - spring-mybatis Maven Webapp - http://maven.apache.org + spring-mybatis com.baeldung diff --git a/spring-reactive-kotlin/pom.xml b/spring-reactive-kotlin/pom.xml index bff39984e0..7bd31396f7 100644 --- a/spring-reactive-kotlin/pom.xml +++ b/spring-reactive-kotlin/pom.xml @@ -4,7 +4,7 @@ 4.0.0 spring-reactive-kotlin jar - Spring Reactive Kotlin + spring-reactive-kotlin Demo project for Spring Boot diff --git a/spring-remoting/remoting-hessian-burlap/pom.xml b/spring-remoting/remoting-hessian-burlap/pom.xml index 6cb5a51812..e63d0ee22e 100644 --- a/spring-remoting/remoting-hessian-burlap/pom.xml +++ b/spring-remoting/remoting-hessian-burlap/pom.xml @@ -5,6 +5,7 @@ 4.0.0 remoting-hessian-burlap pom + remoting-hessian-burlap spring-remoting diff --git a/spring-remoting/remoting-hessian-burlap/remoting-hessian-burlap-client/pom.xml b/spring-remoting/remoting-hessian-burlap/remoting-hessian-burlap-client/pom.xml index f337d5e51f..104712c3d7 100644 --- a/spring-remoting/remoting-hessian-burlap/remoting-hessian-burlap-client/pom.xml +++ b/spring-remoting/remoting-hessian-burlap/remoting-hessian-burlap-client/pom.xml @@ -2,15 +2,16 @@ - + 4.0.0 + spring-remoting-hessian-burlap-client + spring-remoting-hessian-burlap-client + + remoting-hessian-burlap com.baeldung 1.0-SNAPSHOT - 4.0.0 - - spring-remoting-hessian-burlap-client - + org.springframework.boot diff --git a/spring-remoting/remoting-hessian-burlap/remoting-hessian-burlap-server/pom.xml b/spring-remoting/remoting-hessian-burlap/remoting-hessian-burlap-server/pom.xml index 5b6e03348f..33b824442f 100644 --- a/spring-remoting/remoting-hessian-burlap/remoting-hessian-burlap-server/pom.xml +++ b/spring-remoting/remoting-hessian-burlap/remoting-hessian-burlap-server/pom.xml @@ -2,14 +2,15 @@ + 4.0.0 + remoting-hessian-burlap-server + remoting-hessian-burlap-server + remoting-hessian-burlap com.baeldung 1.0-SNAPSHOT - 4.0.0 - - remoting-hessian-burlap-server diff --git a/spring-remoting/remoting-http/pom.xml b/spring-remoting/remoting-http/pom.xml index 3262736ec8..886a28b886 100644 --- a/spring-remoting/remoting-http/pom.xml +++ b/spring-remoting/remoting-http/pom.xml @@ -4,8 +4,10 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 remoting-http - Parent for all modules related to HTTP Spring Remoting. pom + + remoting-http + Parent for all modules related to HTTP Spring Remoting. com.baeldung diff --git a/spring-remoting/remoting-http/remoting-http-client/pom.xml b/spring-remoting/remoting-http/remoting-http-client/pom.xml index 9a6e98ffdd..56412d3cdf 100644 --- a/spring-remoting/remoting-http/remoting-http-client/pom.xml +++ b/spring-remoting/remoting-http/remoting-http-client/pom.xml @@ -4,6 +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 remoting-http-client + remoting-http-client Shows how to invoke a remote service using Spring Remoting HTTP. diff --git a/spring-remoting/remoting-http/remoting-http-server/pom.xml b/spring-remoting/remoting-http/remoting-http-server/pom.xml index 53d27a5efa..c3f87e776e 100644 --- a/spring-remoting/remoting-http/remoting-http-server/pom.xml +++ b/spring-remoting/remoting-http/remoting-http-server/pom.xml @@ -4,6 +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 remoting-http-server + remoting-http-server Shows how to expose a service using Spring Remoting HTTP. diff --git a/spring-remoting/remoting-jms/pom.xml b/spring-remoting/remoting-jms/pom.xml index fe36431423..e24b5b7929 100644 --- a/spring-remoting/remoting-jms/pom.xml +++ b/spring-remoting/remoting-jms/pom.xml @@ -2,18 +2,20 @@ + 4.0.0 + remoting-jms + remoting-jms + pom + spring-remoting com.baeldung 1.0-SNAPSHOT - 4.0.0 - pom + remoting-jms-client remoting-jms-server - remoting-jms - \ No newline at end of file diff --git a/spring-remoting/remoting-jms/remoting-jms-client/pom.xml b/spring-remoting/remoting-jms/remoting-jms-client/pom.xml index ed27282a38..b7b1af5a1a 100644 --- a/spring-remoting/remoting-jms/remoting-jms-client/pom.xml +++ b/spring-remoting/remoting-jms/remoting-jms-client/pom.xml @@ -2,14 +2,15 @@ + 4.0.0 + remoting-jms-client + remoting-jms-client + remoting-jms com.baeldung 1.0-SNAPSHOT - 4.0.0 - - remoting-jms-client UTF-8 diff --git a/spring-remoting/remoting-jms/remoting-jms-server/pom.xml b/spring-remoting/remoting-jms/remoting-jms-server/pom.xml index 7657267f1d..8a17cdb0a9 100644 --- a/spring-remoting/remoting-jms/remoting-jms-server/pom.xml +++ b/spring-remoting/remoting-jms/remoting-jms-server/pom.xml @@ -2,14 +2,15 @@ + 4.0.0 + remoting-jms-server + remoting-jms-server + remoting-jms com.baeldung 1.0-SNAPSHOT - 4.0.0 - - remoting-jms-server UTF-8 diff --git a/spring-remoting/remoting-rmi/pom.xml b/spring-remoting/remoting-rmi/pom.xml index cd15a6ec60..b3b84786b8 100644 --- a/spring-remoting/remoting-rmi/pom.xml +++ b/spring-remoting/remoting-rmi/pom.xml @@ -3,8 +3,9 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - pom remoting-rmi + pom + remoting-rmi spring-remoting diff --git a/spring-remoting/remoting-rmi/remoting-rmi-client/pom.xml b/spring-remoting/remoting-rmi/remoting-rmi-client/pom.xml index 1e3cd4b977..4ac0283e94 100644 --- a/spring-remoting/remoting-rmi/remoting-rmi-client/pom.xml +++ b/spring-remoting/remoting-rmi/remoting-rmi-client/pom.xml @@ -2,15 +2,16 @@ + 4.0.0 + remoting-rmi-client + remoting-rmi-client + remoting-rmi com.baeldung 1.0-SNAPSHOT - 4.0.0 - - remoting-rmi-client - + org.springframework.boot diff --git a/spring-remoting/remoting-rmi/remoting-rmi-server/pom.xml b/spring-remoting/remoting-rmi/remoting-rmi-server/pom.xml index 68b01829e1..7fb4d2c1bc 100644 --- a/spring-remoting/remoting-rmi/remoting-rmi-server/pom.xml +++ b/spring-remoting/remoting-rmi/remoting-rmi-server/pom.xml @@ -2,14 +2,15 @@ + 4.0.0 + remoting-rmi-server + remoting-rmi-server + remoting-rmi com.baeldung 1.0-SNAPSHOT - 4.0.0 - - remoting-rmi-server UTF-8 diff --git a/spring-rest-hal-browser/pom.xml b/spring-rest-hal-browser/pom.xml index 6c56faf0b2..ee0a2c043d 100644 --- a/spring-rest-hal-browser/pom.xml +++ b/spring-rest-hal-browser/pom.xml @@ -3,10 +3,11 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - com.baeldung spring-rest-hal-browser 1.0-SNAPSHOT + spring-rest-hal-browser + diff --git a/spring-roo/pom.xml b/spring-roo/pom.xml index c205c98dc0..baa0e7f5e6 100644 --- a/spring-roo/pom.xml +++ b/spring-roo/pom.xml @@ -6,7 +6,7 @@ com.baeldung spring-roo 1.0.0.BUILD-SNAPSHOT - Spring Roo + spring-roo jar diff --git a/spring-security-angular/server/pom.xml b/spring-security-angular/server/pom.xml index c1faecca55..55269bb35f 100644 --- a/spring-security-angular/server/pom.xml +++ b/spring-security-angular/server/pom.xml @@ -3,10 +3,10 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 com.baeldung - spring-security-angular + server 0.0.1-SNAPSHOT jar - spring-security-angular + server Spring Security Angular diff --git a/spring-security-cache-control/pom.xml b/spring-security-cache-control/pom.xml index b7dfc9db3a..c630774849 100644 --- a/spring-security-cache-control/pom.xml +++ b/spring-security-cache-control/pom.xml @@ -2,10 +2,10 @@ 4.0.0 - com.baeldung spring-security-cache-control 1.0-SNAPSHOT + spring-security-cache-control parent-boot-1 diff --git a/spring-security-client/spring-security-jsp-authentication/pom.xml b/spring-security-client/spring-security-jsp-authentication/pom.xml index 0e564b47b8..9bb58863d9 100644 --- a/spring-security-client/spring-security-jsp-authentication/pom.xml +++ b/spring-security-client/spring-security-jsp-authentication/pom.xml @@ -6,7 +6,7 @@ spring-security-jsp-authentication 0.0.1-SNAPSHOT war - spring-security-jsp-authenticate + spring-security-jsp-authentication Spring Security JSP Authentication tag sample diff --git a/spring-security-x509/pom.xml b/spring-security-x509/pom.xml index 0cee3b3129..658840e866 100644 --- a/spring-security-x509/pom.xml +++ b/spring-security-x509/pom.xml @@ -6,7 +6,8 @@ spring-security-x509 0.0.1-SNAPSHOT pom - + spring-security-x509 + parent-boot-1 com.baeldung diff --git a/spring-security-x509/spring-security-x509-basic-auth/pom.xml b/spring-security-x509/spring-security-x509-basic-auth/pom.xml index 67f2b4fbcd..5b68a8e63b 100644 --- a/spring-security-x509/spring-security-x509-basic-auth/pom.xml +++ b/spring-security-x509/spring-security-x509-basic-auth/pom.xml @@ -2,11 +2,10 @@ 4.0.0 - spring-security-x509-basic-auth 0.0.1-SNAPSHOT jar - Spring Security x.509 Basic Authentication + spring-security-x509-basic-auth Spring x.509 Authentication Demo diff --git a/spring-security-x509/spring-security-x509-client-auth/pom.xml b/spring-security-x509/spring-security-x509-client-auth/pom.xml index 5cb4001a94..47ec7f971d 100644 --- a/spring-security-x509/spring-security-x509-client-auth/pom.xml +++ b/spring-security-x509/spring-security-x509-client-auth/pom.xml @@ -2,11 +2,10 @@ 4.0.0 - spring-security-x509-client-auth 0.0.1-SNAPSHOT jar - Spring Security x.509 Client Authentication + spring-security-x509-client-auth Spring x.509 Client Authentication Demo diff --git a/spring-session/spring-session-redis/pom.xml b/spring-session/spring-session-redis/pom.xml index 00da656226..96d90b2776 100644 --- a/spring-session/spring-session-redis/pom.xml +++ b/spring-session/spring-session-redis/pom.xml @@ -5,6 +5,7 @@ spring-session-redis 1.0.0-SNAPSHOT jar + spring-session-redis parent-boot-1 diff --git a/spring-sleuth/pom.xml b/spring-sleuth/pom.xml index a9a8d3e96e..5ce9e07858 100644 --- a/spring-sleuth/pom.xml +++ b/spring-sleuth/pom.xml @@ -6,7 +6,8 @@ spring-sleuth 1.0.0-SNAPSHOT jar - + spring-sleuth + parent-boot-1 com.baeldung diff --git a/spring-spel/pom.xml b/spring-spel/pom.xml index 4af318fde2..aa6eb45158 100644 --- a/spring-spel/pom.xml +++ b/spring-spel/pom.xml @@ -5,7 +5,7 @@ com.baeldung spring-spel 1.0-SNAPSHOT - Spring SpEL + spring-spel com.baeldung diff --git a/spring-state-machine/pom.xml b/spring-state-machine/pom.xml index 5d15e4dfad..b911b5b5ee 100644 --- a/spring-state-machine/pom.xml +++ b/spring-state-machine/pom.xml @@ -3,7 +3,8 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 spring-state-machine - + spring-state-machine + parent-modules com.baeldung diff --git a/spring-swagger-codegen/pom.xml b/spring-swagger-codegen/pom.xml index 8e551d850f..e1bb98360e 100644 --- a/spring-swagger-codegen/pom.xml +++ b/spring-swagger-codegen/pom.xml @@ -4,6 +4,7 @@ spring-swagger-codegen 0.0.1-SNAPSHOT pom + spring-swagger-codegen com.baeldung diff --git a/spring-swagger-codegen/spring-swagger-codegen-app/pom.xml b/spring-swagger-codegen/spring-swagger-codegen-app/pom.xml index 4aff696828..f9410b6865 100644 --- a/spring-swagger-codegen/spring-swagger-codegen-app/pom.xml +++ b/spring-swagger-codegen/spring-swagger-codegen-app/pom.xml @@ -2,7 +2,8 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 spring-swagger-codegen-app - + spring-swagger-codegen-app + com.baeldung spring-swagger-codegen diff --git a/spring-thymeleaf/pom.xml b/spring-thymeleaf/pom.xml index 0926728aba..78f95fe1df 100644 --- a/spring-thymeleaf/pom.xml +++ b/spring-thymeleaf/pom.xml @@ -5,6 +5,7 @@ spring-thymeleaf 0.1-SNAPSHOT war + spring-thymeleaf com.baeldung diff --git a/spring-userservice/pom.xml b/spring-userservice/pom.xml index 7144a57ca6..e562171103 100644 --- a/spring-userservice/pom.xml +++ b/spring-userservice/pom.xml @@ -1,12 +1,12 @@ 4.0.0 - spring-userservice spring-userservice 0.0.1-SNAPSHOT war - + spring-userservice + com.baeldung parent-spring-4 diff --git a/spring-vertx/pom.xml b/spring-vertx/pom.xml index 790eeff128..14ed77d359 100644 --- a/spring-vertx/pom.xml +++ b/spring-vertx/pom.xml @@ -2,10 +2,9 @@ 4.0.0 - spring-vertx jar - Spring Vertx + spring-vertx A demo project with vertx spring integration diff --git a/sse-jaxrs/pom.xml b/sse-jaxrs/pom.xml index ac9bff937f..68d1b1bc2b 100644 --- a/sse-jaxrs/pom.xml +++ b/sse-jaxrs/pom.xml @@ -3,10 +3,10 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - com.baeldung.sse sse-jaxrs 1.0-SNAPSHOT + sse-jaxrs pom diff --git a/sse-jaxrs/sse-jaxrs-client/pom.xml b/sse-jaxrs/sse-jaxrs-client/pom.xml index a9068e133f..15a991bfc0 100644 --- a/sse-jaxrs/sse-jaxrs-client/pom.xml +++ b/sse-jaxrs/sse-jaxrs-client/pom.xml @@ -3,6 +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 + sse-jaxrs-client + sse-jaxrs-client com.baeldung.sse @@ -10,8 +12,6 @@ 1.0-SNAPSHOT - sse-jaxrs-client - 3.2.0 diff --git a/sse-jaxrs/sse-jaxrs-server/pom.xml b/sse-jaxrs/sse-jaxrs-server/pom.xml index 1e89c70e13..825dcddbdf 100644 --- a/sse-jaxrs/sse-jaxrs-server/pom.xml +++ b/sse-jaxrs/sse-jaxrs-server/pom.xml @@ -3,16 +3,16 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - + sse-jaxrs-server + war + sse-jaxrs-server + com.baeldung.sse sse-jaxrs 1.0-SNAPSHOT - sse-jaxrs-server - war - 2.4.2 false diff --git a/static-analysis/pom.xml b/static-analysis/pom.xml index 14853d81f7..94d68f895b 100644 --- a/static-analysis/pom.xml +++ b/static-analysis/pom.xml @@ -2,10 +2,10 @@ 4.0.0 - com.baeldung static-analysis 1.0-SNAPSHOT + static-analysis com.baeldung diff --git a/structurizr/pom.xml b/structurizr/pom.xml index cbbbf8d68c..76b1e355f1 100644 --- a/structurizr/pom.xml +++ b/structurizr/pom.xml @@ -2,9 +2,9 @@ 4.0.0 - com.baeldung structurizr + structurizr com.baeldung diff --git a/struts-2/pom.xml b/struts-2/pom.xml index fee68c8303..ac8579d9e0 100644 --- a/struts-2/pom.xml +++ b/struts-2/pom.xml @@ -5,7 +5,7 @@ struts-2 0.0.1-SNAPSHOT pom - Struts 2 + struts-2 com.baeldung diff --git a/testing-modules/gatling/pom.xml b/testing-modules/gatling/pom.xml index 8d4c89ec62..158da176c6 100644 --- a/testing-modules/gatling/pom.xml +++ b/testing-modules/gatling/pom.xml @@ -6,7 +6,8 @@ org.baeldung gatling 1.0-SNAPSHOT - + gatling + com.baeldung parent-modules diff --git a/testing-modules/groovy-spock/pom.xml b/testing-modules/groovy-spock/pom.xml index e0da345eb4..3dd01c29ab 100644 --- a/testing-modules/groovy-spock/pom.xml +++ b/testing-modules/groovy-spock/pom.xml @@ -6,6 +6,7 @@ groovy-spock 1.0-SNAPSHOT jar + groovy-spock com.baeldung diff --git a/testing-modules/load-testing-comparison/pom.xml b/testing-modules/load-testing-comparison/pom.xml index 869eda1bb5..42614d310b 100644 --- a/testing-modules/load-testing-comparison/pom.xml +++ b/testing-modules/load-testing-comparison/pom.xml @@ -2,15 +2,16 @@ + 4.0.0 + load-testing-comparison + load-testing-comparison + parent-modules com.baeldung 1.0.0-SNAPSHOT ../../pom.xml - 4.0.0 - - load-testing-bakeoff 1.8 diff --git a/testing-modules/mockito-2/pom.xml b/testing-modules/mockito-2/pom.xml index cab4d7977b..5f60566566 100644 --- a/testing-modules/mockito-2/pom.xml +++ b/testing-modules/mockito-2/pom.xml @@ -5,7 +5,7 @@ mockito-2 0.0.1-SNAPSHOT jar - mockito-2-with-java8 + mockito-2 com.baeldung diff --git a/testing-modules/mockserver/pom.xml b/testing-modules/mockserver/pom.xml index c2fa2870e2..1db409bd7c 100644 --- a/testing-modules/mockserver/pom.xml +++ b/testing-modules/mockserver/pom.xml @@ -5,7 +5,8 @@ com.baeldung mockserver 1.0.0-SNAPSHOT - + mockserver + com.baeldung parent-modules diff --git a/testing-modules/parallel-tests-junit/pom.xml b/testing-modules/parallel-tests-junit/pom.xml index 3fd4e695e5..ecca8b3930 100644 --- a/testing-modules/parallel-tests-junit/pom.xml +++ b/testing-modules/parallel-tests-junit/pom.xml @@ -5,6 +5,8 @@ parallel-tests-junit 0.0.1-SNAPSHOT pom + parallel-tests-junit + math-test-functions string-test-functions diff --git a/testing-modules/selenium-junit-testng/pom.xml b/testing-modules/selenium-junit-testng/pom.xml index e22f7421cf..ae15fc97c0 100644 --- a/testing-modules/selenium-junit-testng/pom.xml +++ b/testing-modules/selenium-junit-testng/pom.xml @@ -4,7 +4,8 @@ com.baeldung selenium-junit-testng 0.0.1-SNAPSHOT - + selenium-junit-testng + com.baeldung parent-modules diff --git a/twilio/pom.xml b/twilio/pom.xml index 610cc04b60..81fbf8ab20 100644 --- a/twilio/pom.xml +++ b/twilio/pom.xml @@ -4,7 +4,8 @@ 4.0.0 twilio 1.0-SNAPSHOT - + twilio + parent-modules com.baeldung diff --git a/vertx-and-rxjava/pom.xml b/vertx-and-rxjava/pom.xml index cbc94dd8f1..389eaf687b 100644 --- a/vertx-and-rxjava/pom.xml +++ b/vertx-and-rxjava/pom.xml @@ -3,7 +3,8 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 vertx-and-rxjava - + vertx-and-rxjava + com.baeldung parent-modules diff --git a/video-tutorials/jackson-annotations/pom.xml b/video-tutorials/jackson-annotations/pom.xml index 748721b83c..121609ad4d 100644 --- a/video-tutorials/jackson-annotations/pom.xml +++ b/video-tutorials/jackson-annotations/pom.xml @@ -1,11 +1,10 @@ 4.0.0 - com.baeldung jackson-annotations 1.0.0-SNAPSHOT - jacksonannotation + jackson-annotations com.baeldung diff --git a/vraptor/pom.xml b/vraptor/pom.xml index ae43d8e083..97005bd158 100644 --- a/vraptor/pom.xml +++ b/vraptor/pom.xml @@ -1,11 +1,11 @@ 4.0.0 - com.baeldung vraptor 1.0.0 war + vraptor A demo project to start using VRaptor 4 diff --git a/xmlunit-2/pom.xml b/xmlunit-2/pom.xml index 806ebb6c0e..faefeca7a1 100644 --- a/xmlunit-2/pom.xml +++ b/xmlunit-2/pom.xml @@ -4,6 +4,7 @@ com.baeldung xmlunit-2 1.0 + xmlunit-2 com.baeldung From 30864ad7bf208a24a6e7d445828a2dea1d22d4bb Mon Sep 17 00:00:00 2001 From: Dhawal Kapil Date: Fri, 30 Nov 2018 22:28:32 +0530 Subject: [PATCH 109/146] BAEL-9567 Align module names, folder names and artifact id - Fixed parent pom id --- spring-ejb/wildfly/widlfly-web/pom.xml | 4 ++-- spring-ejb/wildfly/wildfly-ear/pom.xml | 2 +- spring-ejb/wildfly/wildfly-ejb-interfaces/pom.xml | 2 +- spring-ejb/wildfly/wildfly-ejb/pom.xml | 2 +- spring-ejb/wildfly/wildfly-jpa/pom.xml | 2 +- spring-ejb/wildfly/wildfly-mdb/pom.xml | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/spring-ejb/wildfly/widlfly-web/pom.xml b/spring-ejb/wildfly/widlfly-web/pom.xml index 1dcb18a230..f0baac10dd 100644 --- a/spring-ejb/wildfly/widlfly-web/pom.xml +++ b/spring-ejb/wildfly/widlfly-web/pom.xml @@ -4,10 +4,10 @@ widlfly-web war widlfly-web - + com.baeldung.wildfly - wildfly-example + wildfly 0.0.1-SNAPSHOT diff --git a/spring-ejb/wildfly/wildfly-ear/pom.xml b/spring-ejb/wildfly/wildfly-ear/pom.xml index dc9059370f..93d6df96e5 100644 --- a/spring-ejb/wildfly/wildfly-ear/pom.xml +++ b/spring-ejb/wildfly/wildfly-ear/pom.xml @@ -7,7 +7,7 @@ com.baeldung.wildfly - wildfly-example + wildfly 0.0.1-SNAPSHOT diff --git a/spring-ejb/wildfly/wildfly-ejb-interfaces/pom.xml b/spring-ejb/wildfly/wildfly-ejb-interfaces/pom.xml index 0324aa8e47..41c7012ea9 100644 --- a/spring-ejb/wildfly/wildfly-ejb-interfaces/pom.xml +++ b/spring-ejb/wildfly/wildfly-ejb-interfaces/pom.xml @@ -6,7 +6,7 @@ com.baeldung.wildfly - wildfly-example + wildfly 0.0.1-SNAPSHOT diff --git a/spring-ejb/wildfly/wildfly-ejb/pom.xml b/spring-ejb/wildfly/wildfly-ejb/pom.xml index 22bceef044..12bfc9c1bf 100644 --- a/spring-ejb/wildfly/wildfly-ejb/pom.xml +++ b/spring-ejb/wildfly/wildfly-ejb/pom.xml @@ -7,7 +7,7 @@ com.baeldung.wildfly - wildfly-example + wildfly 0.0.1-SNAPSHOT diff --git a/spring-ejb/wildfly/wildfly-jpa/pom.xml b/spring-ejb/wildfly/wildfly-jpa/pom.xml index 6a0352c102..3005ab714c 100644 --- a/spring-ejb/wildfly/wildfly-jpa/pom.xml +++ b/spring-ejb/wildfly/wildfly-jpa/pom.xml @@ -6,7 +6,7 @@ com.baeldung.wildfly - wildfly-example + wildfly 0.0.1-SNAPSHOT diff --git a/spring-ejb/wildfly/wildfly-mdb/pom.xml b/spring-ejb/wildfly/wildfly-mdb/pom.xml index 186ddc50c0..a2ffca2fc5 100644 --- a/spring-ejb/wildfly/wildfly-mdb/pom.xml +++ b/spring-ejb/wildfly/wildfly-mdb/pom.xml @@ -6,7 +6,7 @@ com.baeldung.wildfly - wildfly-example + wildfly 0.0.1-SNAPSHOT From b02321519f0193b25a193cdbf5a7a7ce0313f5b1 Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Fri, 30 Nov 2018 19:28:39 +0200 Subject: [PATCH 110/146] Update CustomRequestSecurityConfig.java --- .../java/com/baeldung/oauth2/CustomRequestSecurityConfig.java | 1 - 1 file changed, 1 deletion(-) diff --git a/spring-5-security-oauth/src/main/java/com/baeldung/oauth2/CustomRequestSecurityConfig.java b/spring-5-security-oauth/src/main/java/com/baeldung/oauth2/CustomRequestSecurityConfig.java index 51caee8178..2aba5a82ac 100644 --- a/spring-5-security-oauth/src/main/java/com/baeldung/oauth2/CustomRequestSecurityConfig.java +++ b/spring-5-security-oauth/src/main/java/com/baeldung/oauth2/CustomRequestSecurityConfig.java @@ -115,5 +115,4 @@ public class CustomRequestSecurityConfig extends WebSecurityConfigurerAdapter { } return null; } - } From dfa76b232f6a5d0299acf763bfb19a190c7a6621 Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Fri, 30 Nov 2018 19:41:31 +0200 Subject: [PATCH 111/146] Update README.md --- spring-5-reactive/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-5-reactive/README.md b/spring-5-reactive/README.md index 4fab0c12ad..fc898a56dc 100644 --- a/spring-5-reactive/README.md +++ b/spring-5-reactive/README.md @@ -17,3 +17,4 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [A Guide to Spring Session Reactive Support: WebSession](https://www.baeldung.com/spring-session-reactive) - [Validation for Functional Endpoints in Spring 5](https://www.baeldung.com/spring-functional-endpoints-validation) - [Logging a Reactive Sequence](https://www.baeldung.com/spring-reactive-sequence-logging) + From 2c44ec056e1056ece63ebdc722a700cfbe7321c5 Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Fri, 30 Nov 2018 19:56:53 +0200 Subject: [PATCH 112/146] Update README.md --- cdi/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/cdi/README.md b/cdi/README.md index 1523aacf6b..bfb635be9e 100644 --- a/cdi/README.md +++ b/cdi/README.md @@ -2,3 +2,4 @@ - [CDI Interceptor vs Spring AspectJ](http://www.baeldung.com/cdi-interceptor-vs-spring-aspectj) - [An Introduction to CDI (Contexts and Dependency Injection) in Java](http://www.baeldung.com/java-ee-cdi) - [Introduction to the Event Notification Model in CDI 2.0](https://www.baeldung.com/cdi-event-notification) + From 6f717e04d5f119f39fd1753f6f3a234217b7a5bf Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Fri, 30 Nov 2018 20:26:30 +0200 Subject: [PATCH 113/146] Update and rename CompoundOperatorsTest.java to CompoundOperatorsUnitTest.java --- ...ompoundOperatorsTest.java => CompoundOperatorsUnitTest.java} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename core-java-lang/src/test/java/com/baeldung/compoundoperators/{CompoundOperatorsTest.java => CompoundOperatorsUnitTest.java} (98%) diff --git a/core-java-lang/src/test/java/com/baeldung/compoundoperators/CompoundOperatorsTest.java b/core-java-lang/src/test/java/com/baeldung/compoundoperators/CompoundOperatorsUnitTest.java similarity index 98% rename from core-java-lang/src/test/java/com/baeldung/compoundoperators/CompoundOperatorsTest.java rename to core-java-lang/src/test/java/com/baeldung/compoundoperators/CompoundOperatorsUnitTest.java index 3b3478b38e..532776edd4 100644 --- a/core-java-lang/src/test/java/com/baeldung/compoundoperators/CompoundOperatorsTest.java +++ b/core-java-lang/src/test/java/com/baeldung/compoundoperators/CompoundOperatorsUnitTest.java @@ -4,7 +4,7 @@ import org.junit.Test; import static org.junit.Assert.assertEquals; -public class CompoundOperatorsTest { +public class CompoundOperatorsUnitTest { @Test public void whenAssignmentOperatorIsUsed_thenValueIsAssigned() { From a2982271e3362b467d57dd36b3557c8eb0dbc094 Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Fri, 30 Nov 2018 21:16:33 +0200 Subject: [PATCH 114/146] Update README.md --- core-java-lang/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-lang/README.md b/core-java-lang/README.md index 607abbcdc5..79d2375c24 100644 --- a/core-java-lang/README.md +++ b/core-java-lang/README.md @@ -58,3 +58,4 @@ - [Inheritance and Composition (Is-a vs Has-a relationship) in Java](http://www.baeldung.com/java-inheritance-composition) - [A Guide to Constructors in Java](https://www.baeldung.com/java-constructors) - [Retrieving a Class Name in Java](https://www.baeldung.com/java-class-name) + From b740a59e2baa23032febb4abb5892c7072f95f37 Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Fri, 30 Nov 2018 21:17:29 +0200 Subject: [PATCH 115/146] Update README.md --- restx/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/restx/README.md b/restx/README.md index f586f08a21..665f7ea82d 100644 --- a/restx/README.md +++ b/restx/README.md @@ -1,3 +1,4 @@ # Relevant Articles * [Introduction to RESTX](https://www.baeldung.com/java-restx) + From 95dc6fd367ab733887dd7f7a314965d98ee43764 Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Fri, 30 Nov 2018 21:17:59 +0200 Subject: [PATCH 116/146] Update pom.xml --- algorithms-genetic/pom.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/algorithms-genetic/pom.xml b/algorithms-genetic/pom.xml index 662e0c5913..fc6d36dac1 100644 --- a/algorithms-genetic/pom.xml +++ b/algorithms-genetic/pom.xml @@ -61,4 +61,5 @@ 1.11 - \ No newline at end of file + + From 6e478c5fed04af8807be8afce9d5266cf59b68d3 Mon Sep 17 00:00:00 2001 From: Muhammad Asif Anwar Date: Sat, 1 Dec 2018 00:57:07 +0400 Subject: [PATCH 117/146] for BAEL 10834 (#5816) * Update pom.xml * enabling spring-security-react module --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index da17fc2931..ef7a7f6b1d 100644 --- a/pom.xml +++ b/pom.xml @@ -599,7 +599,7 @@ spring-security-mvc-session spring-security-mvc-socket spring-security-openid - + spring-security-react spring-security-rest-basic-auth spring-security-rest-custom spring-security-rest @@ -1141,7 +1141,7 @@ spring-security-mvc-session spring-security-mvc-socket spring-security-openid - + spring-security-react spring-security-rest-basic-auth spring-security-rest-custom spring-security-rest From eeb02d95ae78750ea0254be3338c007a20df5f3e Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Fri, 30 Nov 2018 23:20:02 +0200 Subject: [PATCH 118/146] Update pom.xml --- pom.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index ef7a7f6b1d..7b295abc24 100644 --- a/pom.xml +++ b/pom.xml @@ -405,7 +405,8 @@ jaxb javafx jgroups - jee-7 + jee-7-security jjwt jsf From b0039348cfa292774718babb813e4dde15955e77 Mon Sep 17 00:00:00 2001 From: Loredana Date: Fri, 30 Nov 2018 23:50:52 +0200 Subject: [PATCH 119/146] fix module names --- spring-cloud-data-flow/etl/customer-mongodb-sink/pom.xml | 1 - spring-cloud-data-flow/etl/customer-transform/pom.xml | 1 - spring-cloud-data-flow/etl/pom.xml | 5 ++--- spring-cloud-data-flow/pom.xml | 3 +-- 4 files changed, 3 insertions(+), 7 deletions(-) diff --git a/spring-cloud-data-flow/etl/customer-mongodb-sink/pom.xml b/spring-cloud-data-flow/etl/customer-mongodb-sink/pom.xml index 468d8e17d0..779a4a803a 100644 --- a/spring-cloud-data-flow/etl/customer-mongodb-sink/pom.xml +++ b/spring-cloud-data-flow/etl/customer-mongodb-sink/pom.xml @@ -4,7 +4,6 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - com.customer customer-mongodb-sink jar diff --git a/spring-cloud-data-flow/etl/customer-transform/pom.xml b/spring-cloud-data-flow/etl/customer-transform/pom.xml index bc4b648907..c344b0fc57 100644 --- a/spring-cloud-data-flow/etl/customer-transform/pom.xml +++ b/spring-cloud-data-flow/etl/customer-transform/pom.xml @@ -4,7 +4,6 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - com.customer customer-transform 0.0.1-SNAPSHOT jar diff --git a/spring-cloud-data-flow/etl/pom.xml b/spring-cloud-data-flow/etl/pom.xml index e203999ee9..1f35d2072b 100644 --- a/spring-cloud-data-flow/etl/pom.xml +++ b/spring-cloud-data-flow/etl/pom.xml @@ -1,11 +1,10 @@ 4.0.0 - org.baeldung.spring.cloud - etl-spring-cloud-data-flow + etl + etl 0.0.1-SNAPSHOT pom - etl-spring-cloud-data-flow org.baeldung.spring.cloud diff --git a/spring-cloud-data-flow/pom.xml b/spring-cloud-data-flow/pom.xml index dd1ceed71a..b5ef5d2c2a 100644 --- a/spring-cloud-data-flow/pom.xml +++ b/spring-cloud-data-flow/pom.xml @@ -1,11 +1,10 @@ 4.0.0 - org.baeldung.spring.cloud spring-cloud-data-flow 0.0.1-SNAPSHOT pom - spring-cloud-data-flow + spring-cloud-data-flow com.baeldung From eb1a92698b544a30e9ec5ad2f99711ca9a8f1309 Mon Sep 17 00:00:00 2001 From: Emily Cheyne Date: Fri, 30 Nov 2018 15:26:54 -0800 Subject: [PATCH 120/146] BAEL-2368 update readme --- java-collections-conversions/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/java-collections-conversions/README.md b/java-collections-conversions/README.md index 761a78d7b0..0f89e07d63 100644 --- a/java-collections-conversions/README.md +++ b/java-collections-conversions/README.md @@ -8,4 +8,5 @@ - [Converting between a List and a Set in Java](http://www.baeldung.com/convert-list-to-set-and-set-to-list) - [Convert a Map to an Array, List or Set in Java](http://www.baeldung.com/convert-map-values-to-array-list-set) - [Converting a List to String in Java](http://www.baeldung.com/java-list-to-string) -- [How to Convert List to Map in Java](http://www.baeldung.com/java-list-to-map) \ No newline at end of file +- [How to Convert List to Map in Java](http://www.baeldung.com/java-list-to-map) +- [Array to String Conversions](https://www.baeldung.com/java-array-to-string) From b81bcc75f68ab9db34e1e761c6aedc78c2dcdda0 Mon Sep 17 00:00:00 2001 From: Emily Cheyne Date: Fri, 30 Nov 2018 15:27:12 -0800 Subject: [PATCH 121/146] Update README.md --- core-java-lang/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-lang/README.md b/core-java-lang/README.md index 79d2375c24..0f75e9474b 100644 --- a/core-java-lang/README.md +++ b/core-java-lang/README.md @@ -59,3 +59,4 @@ - [A Guide to Constructors in Java](https://www.baeldung.com/java-constructors) - [Retrieving a Class Name in Java](https://www.baeldung.com/java-class-name) + From e884dc106340904c5af72dd54932c1bf8d3e6d94 Mon Sep 17 00:00:00 2001 From: eric-martin Date: Fri, 30 Nov 2018 22:39:06 -0600 Subject: [PATCH 122/146] Fixed compiler errors in spring-boot-crud --- .../src/main/java/com/baeldung/crud/Application.java | 2 -- .../baeldung/crud/controllers/UserController.java | 6 ++++-- .../com/baeldung/crud/UserControllerUnitTest.java | 12 +++++++----- .../test/java/com/baeldung/crud/UserUnitTest.java | 4 +++- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/spring-boot-crud/src/main/java/com/baeldung/crud/Application.java b/spring-boot-crud/src/main/java/com/baeldung/crud/Application.java index 436cccb964..d9f594fb75 100644 --- a/spring-boot-crud/src/main/java/com/baeldung/crud/Application.java +++ b/spring-boot-crud/src/main/java/com/baeldung/crud/Application.java @@ -14,8 +14,6 @@ import org.springframework.transaction.annotation.EnableTransactionManagement; @EnableJpaRepositories(basePackages="com.baeldung.crud.repositories") @EnableTransactionManagement @EntityScan(basePackages="com.baeldung.crud.entities") - -@SpringBootApplication public class Application { public static void main(String[] args) { diff --git a/spring-boot-crud/src/main/java/com/baeldung/crud/controllers/UserController.java b/spring-boot-crud/src/main/java/com/baeldung/crud/controllers/UserController.java index 1b7185c2fd..9a6cb477aa 100644 --- a/spring-boot-crud/src/main/java/com/baeldung/crud/controllers/UserController.java +++ b/spring-boot-crud/src/main/java/com/baeldung/crud/controllers/UserController.java @@ -1,8 +1,7 @@ package com.baeldung.crud.controllers; -import com.baeldung.crud.UserRepository; -import com.baeldung.crud.entities.User; import javax.validation.Valid; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; @@ -11,6 +10,9 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; +import com.baeldung.crud.entities.User; +import com.baeldung.crud.repositories.UserRepository; + @Controller public class UserController { diff --git a/spring-boot-crud/src/test/java/com/baeldung/crud/UserControllerUnitTest.java b/spring-boot-crud/src/test/java/com/baeldung/crud/UserControllerUnitTest.java index 7773a962fb..2de0828ae5 100644 --- a/spring-boot-crud/src/test/java/com/baeldung/crud/UserControllerUnitTest.java +++ b/spring-boot-crud/src/test/java/com/baeldung/crud/UserControllerUnitTest.java @@ -1,16 +1,18 @@ package com.baeldung.crud; -import com.baeldung.crud.UserController; -import com.baeldung.crud.entities.User; -import com.baeldung.crud.UserRepository; import static org.assertj.core.api.Assertions.assertThat; -import org.junit.BeforeClass; -import org.junit.Test; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; + +import org.junit.BeforeClass; +import org.junit.Test; import org.springframework.ui.Model; import org.springframework.validation.BindingResult; +import com.baeldung.crud.controllers.UserController; +import com.baeldung.crud.entities.User; +import com.baeldung.crud.repositories.UserRepository; + public class UserControllerUnitTest { private static UserController userController; diff --git a/spring-boot-crud/src/test/java/com/baeldung/crud/UserUnitTest.java b/spring-boot-crud/src/test/java/com/baeldung/crud/UserUnitTest.java index a3c6a922d8..565f6727c3 100644 --- a/spring-boot-crud/src/test/java/com/baeldung/crud/UserUnitTest.java +++ b/spring-boot-crud/src/test/java/com/baeldung/crud/UserUnitTest.java @@ -1,9 +1,11 @@ package com.baeldung.crud; -import com.baeldung.crud.User; import static org.assertj.core.api.Assertions.assertThat; + import org.junit.Test; +import com.baeldung.crud.entities.User; + public class UserUnitTest { @Test From a303df4442c3d7c038f50f412c6248e913290dba Mon Sep 17 00:00:00 2001 From: Loredana Date: Sat, 1 Dec 2018 08:51:37 +0200 Subject: [PATCH 123/146] fix module names --- spring-cloud-data-flow/data-flow-server/pom.xml | 1 - spring-cloud-data-flow/data-flow-shell/pom.xml | 1 - spring-cloud-data-flow/etl/pom.xml | 2 +- spring-cloud-data-flow/log-sink/pom.xml | 1 - spring-cloud-data-flow/time-processor/pom.xml | 1 - spring-cloud-data-flow/time-source/pom.xml | 1 - 6 files changed, 1 insertion(+), 6 deletions(-) diff --git a/spring-cloud-data-flow/data-flow-server/pom.xml b/spring-cloud-data-flow/data-flow-server/pom.xml index 0133d65978..a02d2984c1 100644 --- a/spring-cloud-data-flow/data-flow-server/pom.xml +++ b/spring-cloud-data-flow/data-flow-server/pom.xml @@ -3,7 +3,6 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - org.baeldung.spring.cloud data-flow-server 0.0.1-SNAPSHOT jar diff --git a/spring-cloud-data-flow/data-flow-shell/pom.xml b/spring-cloud-data-flow/data-flow-shell/pom.xml index e4ec145277..3b155736c3 100644 --- a/spring-cloud-data-flow/data-flow-shell/pom.xml +++ b/spring-cloud-data-flow/data-flow-shell/pom.xml @@ -3,7 +3,6 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - org.baeldung.spring.cloud data-flow-shell 0.0.1-SNAPSHOT jar diff --git a/spring-cloud-data-flow/etl/pom.xml b/spring-cloud-data-flow/etl/pom.xml index 1f35d2072b..7d5040e8ad 100644 --- a/spring-cloud-data-flow/etl/pom.xml +++ b/spring-cloud-data-flow/etl/pom.xml @@ -7,7 +7,7 @@ pom - org.baeldung.spring.cloud + com.baeldung spring-cloud-data-flow 0.0.1-SNAPSHOT diff --git a/spring-cloud-data-flow/log-sink/pom.xml b/spring-cloud-data-flow/log-sink/pom.xml index 33a0a4df45..69de679c2a 100644 --- a/spring-cloud-data-flow/log-sink/pom.xml +++ b/spring-cloud-data-flow/log-sink/pom.xml @@ -3,7 +3,6 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - org.baeldung.spring.cloud log-sink 0.0.1-SNAPSHOT jar diff --git a/spring-cloud-data-flow/time-processor/pom.xml b/spring-cloud-data-flow/time-processor/pom.xml index 4f31e55b96..e630df1865 100644 --- a/spring-cloud-data-flow/time-processor/pom.xml +++ b/spring-cloud-data-flow/time-processor/pom.xml @@ -3,7 +3,6 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - org.baeldung.spring.cloud time-processor 0.0.1-SNAPSHOT jar diff --git a/spring-cloud-data-flow/time-source/pom.xml b/spring-cloud-data-flow/time-source/pom.xml index dc593fdb14..649af32cf0 100644 --- a/spring-cloud-data-flow/time-source/pom.xml +++ b/spring-cloud-data-flow/time-source/pom.xml @@ -3,7 +3,6 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - org.baeldung.spring.cloud time-source 0.0.1-SNAPSHOT jar From 8a48239decdea2f491d6d3845f2cfbefbaec66d5 Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Sat, 1 Dec 2018 08:53:41 +0200 Subject: [PATCH 124/146] Update pom.xml --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 7b295abc24..3c5c171c96 100644 --- a/pom.xml +++ b/pom.xml @@ -600,7 +600,7 @@ spring-security-mvc-session spring-security-mvc-socket spring-security-openid - spring-security-react + spring-security-rest-basic-auth spring-security-rest-custom spring-security-rest From 51352c470f98c417bb4ecb9b3150eb9f167bc361 Mon Sep 17 00:00:00 2001 From: Josh Cummings Date: Sat, 1 Dec 2018 00:40:53 -0700 Subject: [PATCH 125/146] SQLite with Spring Boot Added custom dialect for SQLite database. Simplify spring-data-rest Configuration Now uses profiles so that learners don't need to uncomment code in order for demonstrations to work. Issue: BAEL-2213 --- spring-data-rest/pom.xml | 11 +++ .../java/com/baeldung/config/DbConfig.java | 26 ++++++- .../com/baeldung/dialect/SQLiteDialect.java | 78 +++++++++++++++++++ .../dialect/SQLiteIdentityColumnSupport.java | 22 ++++++ .../src/main/resources/application.properties | 1 + .../resources/persistence-sqlite.properties | 7 +- 6 files changed, 142 insertions(+), 3 deletions(-) create mode 100644 spring-data-rest/src/main/java/com/baeldung/dialect/SQLiteDialect.java create mode 100644 spring-data-rest/src/main/java/com/baeldung/dialect/SQLiteIdentityColumnSupport.java diff --git a/spring-data-rest/pom.xml b/spring-data-rest/pom.xml index a6f12e1904..2fe4715bac 100644 --- a/spring-data-rest/pom.xml +++ b/spring-data-rest/pom.xml @@ -33,6 +33,15 @@ com.h2database h2 + + org.springframework.boot + spring-boot-autoconfigure + + + org.xerial + sqlite-jdbc + ${sqlite.version} + @@ -43,6 +52,8 @@ + com.baeldung.SpringDataRestApplication + 3.25.2 2.1.0.RELEASE diff --git a/spring-data-rest/src/main/java/com/baeldung/config/DbConfig.java b/spring-data-rest/src/main/java/com/baeldung/config/DbConfig.java index 8d1f9de497..26d882d6a0 100644 --- a/spring-data-rest/src/main/java/com/baeldung/config/DbConfig.java +++ b/spring-data-rest/src/main/java/com/baeldung/config/DbConfig.java @@ -7,6 +7,7 @@ import javax.sql.DataSource; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Profile; import org.springframework.context.annotation.PropertySource; import org.springframework.core.env.Environment; import org.springframework.data.jpa.repository.config.EnableJpaRepositories; @@ -14,11 +15,12 @@ import org.springframework.jdbc.datasource.DriverManagerDataSource; import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter; -//@Configuration +@Configuration @EnableJpaRepositories(basePackages = "com.baeldung.repositories") // @PropertySource("persistence-h2.properties") // @PropertySource("persistence-hsqldb.properties") // @PropertySource("persistence-derby.properties") +//@PropertySource("persistence-sqlite.properties") public class DbConfig { @Autowired @@ -59,3 +61,25 @@ public class DbConfig { } } + +@Configuration +@Profile("h2") +@PropertySource("persistence-h2.properties") +class H2Config {} + +@Configuration +@Profile("hsqldb") +@PropertySource("persistence-hsqldb.properties") +class HsqldbConfig {} + + +@Configuration +@Profile("derby") +@PropertySource("persistence-derby.properties") +class DerbyConfig {} + + +@Configuration +@Profile("sqlite") +@PropertySource("persistence-sqlite.properties") +class SqliteConfig {} diff --git a/spring-data-rest/src/main/java/com/baeldung/dialect/SQLiteDialect.java b/spring-data-rest/src/main/java/com/baeldung/dialect/SQLiteDialect.java new file mode 100644 index 0000000000..4512f7d34d --- /dev/null +++ b/spring-data-rest/src/main/java/com/baeldung/dialect/SQLiteDialect.java @@ -0,0 +1,78 @@ +package com.baeldung.dialect; + +import org.hibernate.dialect.Dialect; +import org.hibernate.dialect.identity.IdentityColumnSupport; + +import java.sql.Types; + +public class SQLiteDialect extends Dialect { + + public SQLiteDialect() { + registerColumnType(Types.BIT, "integer"); + registerColumnType(Types.TINYINT, "tinyint"); + registerColumnType(Types.SMALLINT, "smallint"); + registerColumnType(Types.INTEGER, "integer"); + registerColumnType(Types.BIGINT, "bigint"); + registerColumnType(Types.FLOAT, "float"); + registerColumnType(Types.REAL, "real"); + registerColumnType(Types.DOUBLE, "double"); + registerColumnType(Types.NUMERIC, "numeric"); + registerColumnType(Types.DECIMAL, "decimal"); + registerColumnType(Types.CHAR, "char"); + registerColumnType(Types.VARCHAR, "varchar"); + registerColumnType(Types.LONGVARCHAR, "longvarchar"); + registerColumnType(Types.DATE, "date"); + registerColumnType(Types.TIME, "time"); + registerColumnType(Types.TIMESTAMP, "timestamp"); + registerColumnType(Types.BINARY, "blob"); + registerColumnType(Types.VARBINARY, "blob"); + registerColumnType(Types.LONGVARBINARY, "blob"); + registerColumnType(Types.BLOB, "blob"); + registerColumnType(Types.CLOB, "clob"); + registerColumnType(Types.BOOLEAN, "integer"); + } + + public IdentityColumnSupport getIdentityColumnSupport() { + return new SQLiteIdentityColumnSupport(); + } + + public boolean hasAlterTable() { + return false; + } + + public boolean dropConstraints() { + return false; + } + + public String getDropForeignKeyString() { + return ""; + } + + public String getAddForeignKeyConstraintString(String constraintName, String[] foreignKey, String referencedTable, String[] primaryKey, boolean referencesPrimaryKey) { + return ""; + } + + public String getAddPrimaryKeyConstraintString(String constraintName) { + return ""; + } + + public String getForUpdateString() { + return ""; + } + + public String getAddColumnString() { + return "add column"; + } + + public boolean supportsOuterJoinForUpdate() { + return false; + } + + public boolean supportsIfExistsBeforeTableName() { + return true; + } + + public boolean supportsCascadeDelete() { + return false; + } +} diff --git a/spring-data-rest/src/main/java/com/baeldung/dialect/SQLiteIdentityColumnSupport.java b/spring-data-rest/src/main/java/com/baeldung/dialect/SQLiteIdentityColumnSupport.java new file mode 100644 index 0000000000..cf6e3a9a97 --- /dev/null +++ b/spring-data-rest/src/main/java/com/baeldung/dialect/SQLiteIdentityColumnSupport.java @@ -0,0 +1,22 @@ +package com.baeldung.dialect; + +import org.hibernate.MappingException; +import org.hibernate.dialect.identity.IdentityColumnSupportImpl; + +public class SQLiteIdentityColumnSupport extends IdentityColumnSupportImpl { + + @Override + public boolean supportsIdentityColumns() { + return true; + } + + @Override + public String getIdentitySelectString(String table, String column, int type) throws MappingException { + return "select last_insert_rowid()"; + } + + @Override + public String getIdentityColumnString(int type) throws MappingException { + return "integer"; + } +} diff --git a/spring-data-rest/src/main/resources/application.properties b/spring-data-rest/src/main/resources/application.properties index e69de29bb2..06cb22a4fe 100644 --- a/spring-data-rest/src/main/resources/application.properties +++ b/spring-data-rest/src/main/resources/application.properties @@ -0,0 +1 @@ +spring.profiles.default=h2 \ No newline at end of file diff --git a/spring-data-rest/src/main/resources/persistence-sqlite.properties b/spring-data-rest/src/main/resources/persistence-sqlite.properties index 018c2cbaca..b6b5f4e4d6 100644 --- a/spring-data-rest/src/main/resources/persistence-sqlite.properties +++ b/spring-data-rest/src/main/resources/persistence-sqlite.properties @@ -1,4 +1,7 @@ driverClassName=org.sqlite.JDBC -url=jdbc:sqlite:memory:myDb +url=jdbc:sqlite:memory:myDb?cache=shared username=sa -password=sa \ No newline at end of file +password=sa +hibernate.dialect=com.baeldung.dialect.SQLiteDialect +hibernate.hbm2ddl.auto=create-drop +hibernate.show_sql=true From d2f148c90fee69b4e60b288e9defe1c476c056fa Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Sat, 1 Dec 2018 09:53:13 +0200 Subject: [PATCH 126/146] Update Application.java --- .../src/main/java/com/baeldung/crud/Application.java | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-boot-crud/src/main/java/com/baeldung/crud/Application.java b/spring-boot-crud/src/main/java/com/baeldung/crud/Application.java index d9f594fb75..0b686e90e9 100644 --- a/spring-boot-crud/src/main/java/com/baeldung/crud/Application.java +++ b/spring-boot-crud/src/main/java/com/baeldung/crud/Application.java @@ -19,4 +19,5 @@ public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } + } From 0bdc4f6602b530d4f009a8582edb7a3a2a93650c Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Sat, 1 Dec 2018 09:53:40 +0200 Subject: [PATCH 127/146] Update README.md --- core-java-lang/README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/core-java-lang/README.md b/core-java-lang/README.md index 0f75e9474b..79d2375c24 100644 --- a/core-java-lang/README.md +++ b/core-java-lang/README.md @@ -59,4 +59,3 @@ - [A Guide to Constructors in Java](https://www.baeldung.com/java-constructors) - [Retrieving a Class Name in Java](https://www.baeldung.com/java-class-name) - From 7cbd26433d079de819e1c564941fac67ca2d59e5 Mon Sep 17 00:00:00 2001 From: Eugen Paraschiv Date: Sat, 1 Dec 2018 11:22:23 +0200 Subject: [PATCH 128/146] pom cleanup work --- pom.xml | 186 +++++++++++++++++++++++++++----------------------------- 1 file changed, 88 insertions(+), 98 deletions(-) diff --git a/pom.xml b/pom.xml index 3c5c171c96..86ed229bce 100644 --- a/pom.xml +++ b/pom.xml @@ -363,6 +363,9 @@ core-java-8 core-groovy couchbase + core-java-concurrency + core-kotlin + core-java dozer disruptor @@ -419,6 +422,7 @@ java-spi java-ee-8-security-api + libraries libraries-data linkrest logging-modules/log-mdc @@ -469,7 +473,7 @@ persistence-modules/hbase persistence-modules/influxdb persistence-modules/spring-hibernate4 - persistence-modules/spring-data-mongodb + persistence-modules/spring-data-mongodb persistence-modules/java-cassandra persistence-modules/spring-data-cassandra persistence-modules/spring-data-couchbase-2 @@ -527,6 +531,8 @@ spring-5-mvc spring-5-security spring-5-security-oauth + + spring-aop spring-activiti spring-akka spring-amqp @@ -534,7 +540,6 @@ spring-apache-camel spring-batch spring-bom - spring-boot-keycloak spring-boot-bootstrap spring-boot-admin @@ -543,29 +548,34 @@ spring-boot-mvc spring-boot-logging-log4j2 spring-boot-disable-console-logging + spring-boot-property-exp + spring-boot-ctx-fluent + spring-boot + spring-boot-ops spring-cloud-data-flow spring-cloud spring-cloud-bus spring-core spring-cucumber - spring-ejb - spring-aop - spring-data-rest + spring-drools spring-dispatcher-servlet + spring-ejb spring-exceptions + spring-freemarker - spring-integration + + spring-jinq spring-jenkins-pipeline spring-jersey - spring-jms spring-jooq spring-kafka spring-katharsis spring-ldap + spring-mockito spring-mvc-forms-jsp spring-mvc-forms-thymeleaf @@ -574,6 +584,7 @@ spring-mvc-webflow spring-mvc-xml spring-mvc-kotlin + spring-protobuf spring-quartz spring-rest-angular @@ -582,6 +593,26 @@ spring-rest spring-resttemplate spring-rest-simple + spring-remoting + + spring-session + spring-sleuth + spring-social-login + spring-spel + spring-state-machine + spring-thymeleaf + spring-userservice + + spring-zuul + spring-reactor + spring-vertx + spring-vault + spring-rest-embedded-tomcat + spring-swagger-codegen + spring-webflux-amqp + + spring-static-resources + spring-security-thymeleaf spring-security-acl spring-security-cache-control spring-security-client/spring-security-jsp-authentication @@ -600,34 +631,13 @@ spring-security-mvc-session spring-security-mvc-socket spring-security-openid - + spring-security-rest-basic-auth spring-security-rest-custom spring-security-rest spring-security-sso spring-security-x509 - spring-session - spring-sleuth - spring-social-login - spring-spel - spring-state-machine - spring-thymeleaf - spring-userservice - spring-zuul - spring-remoting - spring-reactor - spring-vertx - spring-vault - spring-jinq - spring-rest-embedded-tomcat - - spring-static-resources - spring-swagger-codegen - spring-drools - spring-boot-property-exp - spring-security-thymeleaf - spring-boot-ctx-fluent - spring-webflux-amqp + spring-security-mvc-custom spark-java saas @@ -668,17 +678,12 @@ @@ -910,6 +915,9 @@ core-java-8 core-groovy couchbase + core-java-concurrency + core-kotlin + core-java dozer disruptor @@ -952,7 +960,8 @@ jaxb javafx jgroups - jee-7 + jee-7-security jjwt jsf @@ -965,6 +974,7 @@ java-spi java-ee-8-security-api + libraries libraries-data linkrest logging-modules/log-mdc @@ -1015,7 +1025,7 @@ persistence-modules/hbase persistence-modules/influxdb persistence-modules/spring-hibernate4 - persistence-modules/spring-data-mongodb + persistence-modules/spring-data-mongodb persistence-modules/java-cassandra persistence-modules/spring-data-cassandra persistence-modules/spring-data-couchbase-2 @@ -1069,6 +1079,8 @@ spring-5-mvc spring-5-security spring-5-security-oauth + + spring-aop spring-activiti spring-akka spring-amqp @@ -1076,7 +1088,6 @@ spring-apache-camel spring-batch spring-bom - spring-boot-keycloak spring-boot-bootstrap spring-boot-admin @@ -1085,29 +1096,34 @@ spring-boot-mvc spring-boot-logging-log4j2 spring-boot-disable-console-logging + spring-boot-property-exp + spring-boot-ctx-fluent + spring-boot + spring-boot-ops spring-cloud-data-flow spring-cloud spring-cloud-bus spring-core spring-cucumber - spring-ejb - spring-aop - spring-data-rest + spring-drools spring-dispatcher-servlet + spring-ejb spring-exceptions + spring-freemarker - spring-integration + + spring-jinq spring-jenkins-pipeline spring-jersey - spring-jms spring-jooq spring-kafka spring-katharsis spring-ldap + spring-mockito spring-mvc-forms-jsp spring-mvc-forms-thymeleaf @@ -1116,6 +1132,7 @@ spring-mvc-webflow spring-mvc-xml spring-mvc-kotlin + spring-protobuf spring-quartz spring-rest-angular @@ -1124,6 +1141,26 @@ spring-rest spring-resttemplate spring-rest-simple + spring-remoting + + spring-session + spring-sleuth + spring-social-login + spring-spel + spring-state-machine + spring-thymeleaf + spring-userservice + + spring-zuul + spring-reactor + spring-vertx + spring-vault + spring-rest-embedded-tomcat + spring-swagger-codegen + spring-webflux-amqp + + spring-static-resources + spring-security-thymeleaf spring-security-acl spring-security-cache-control spring-security-client/spring-security-jsp-authentication @@ -1142,35 +1179,13 @@ spring-security-mvc-session spring-security-mvc-socket spring-security-openid - spring-security-react + spring-security-rest-basic-auth spring-security-rest-custom spring-security-rest spring-security-sso spring-security-x509 - spring-session - spring-sleuth - spring-social-login - spring-spel - spring-state-machine - spring-thymeleaf - spring-userservice - spring-zuul - spring-remoting - spring-reactor - spring-vertx - spring-vault - spring-jinq - spring-rest-embedded-tomcat - - spring-static-resources - spring-swagger-codegen - spring-drools - spring-boot-property-exp - spring-security-thymeleaf - spring-boot-ctx-fluent - spring-webflux-amqp - + spring-security-mvc-custom spark-java saas @@ -1205,28 +1220,18 @@ @@ -1268,23 +1273,8 @@ parent-spring-5 parent-java parent-kotlin - libraries - geotools - jhipster - testing-modules/gatling - spring-boot - spring-boot-ops - spring-5 - core-kotlin - kotlin-libraries - core-java - google-web-toolkit - spring-security-mvc-custom - persistence-modules/hibernate5 - persistence-modules/spring-data-elasticsearch - core-java-concurrency - core-java-concurrency-collections - restx + + From 5d512da017bcdf653fb6d96c4fb2d4ee6951f193 Mon Sep 17 00:00:00 2001 From: Eugen Paraschiv Date: Sat, 1 Dec 2018 11:23:47 +0200 Subject: [PATCH 129/146] adding the jira --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 86ed229bce..cd128aa4c5 100644 --- a/pom.xml +++ b/pom.xml @@ -631,7 +631,7 @@ spring-security-mvc-session spring-security-mvc-socket spring-security-openid - + spring-security-rest-basic-auth spring-security-rest-custom spring-security-rest @@ -1179,7 +1179,7 @@ spring-security-mvc-session spring-security-mvc-socket spring-security-openid - + spring-security-rest-basic-auth spring-security-rest-custom spring-security-rest From a2b79472d9cbd74f076f32f792a1c31d138762c4 Mon Sep 17 00:00:00 2001 From: KevinGilmore Date: Sat, 1 Dec 2018 07:10:46 -0600 Subject: [PATCH 130/146] BAEL-2246: add link back to article (#5824) --- java-strings/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/java-strings/README.md b/java-strings/README.md index 222b28e8ad..11893e68a2 100644 --- a/java-strings/README.md +++ b/java-strings/README.md @@ -38,3 +38,4 @@ - [Java Base64 Encoding and Decoding](https://www.baeldung.com/java-base64-encode-and-decode) - [Generate a Secure Random Password in Java](https://www.baeldung.com/java-generate-secure-password) - [Removing Repeated Characters from a String](https://www.baeldung.com/java-remove-repeated-char) +- [Join Array of Primitives with Separator in Java](https://www.baeldung.com/java-join-primitive-array) From 2fa22543451c87fd28f98280e4abd19997f6af53 Mon Sep 17 00:00:00 2001 From: Eugen Paraschiv Date: Sat, 1 Dec 2018 18:49:06 +0200 Subject: [PATCH 131/146] ignoring module --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index cd128aa4c5..4b64a1a27e 100644 --- a/pom.xml +++ b/pom.xml @@ -364,7 +364,7 @@ core-groovy couchbase core-java-concurrency - core-kotlin + core-java dozer @@ -916,7 +916,7 @@ core-groovy couchbase core-java-concurrency - core-kotlin + core-java dozer From 90ca342016f2495acb1d551d17143be3043650e5 Mon Sep 17 00:00:00 2001 From: Eugen Paraschiv Date: Sat, 1 Dec 2018 19:39:47 +0200 Subject: [PATCH 132/146] disabling very long running module --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 4b64a1a27e..f9eee3b5e6 100644 --- a/pom.xml +++ b/pom.xml @@ -363,7 +363,7 @@ core-java-8 core-groovy couchbase - core-java-concurrency + core-java From 56400babbf49417074097d0b10c4747610a4cdfa Mon Sep 17 00:00:00 2001 From: Eugen Paraschiv Date: Sat, 1 Dec 2018 19:40:23 +0200 Subject: [PATCH 133/146] disabling very long running module --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index f9eee3b5e6..2bed3c4960 100644 --- a/pom.xml +++ b/pom.xml @@ -915,7 +915,7 @@ core-java-8 core-groovy couchbase - core-java-concurrency + core-java From fe7e4f87f2ad412e60ac50405870ad89baf49b29 Mon Sep 17 00:00:00 2001 From: Eugen Paraschiv Date: Sat, 1 Dec 2018 20:45:56 +0200 Subject: [PATCH 134/146] ignoring long running module --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 2bed3c4960..6480193201 100644 --- a/pom.xml +++ b/pom.xml @@ -422,7 +422,7 @@ java-spi java-ee-8-security-api - libraries + libraries-data linkrest logging-modules/log-mdc @@ -974,7 +974,7 @@ java-spi java-ee-8-security-api - libraries + libraries-data linkrest logging-modules/log-mdc From dcb2dd46027ea9ed32e579a025b3f96496c506b5 Mon Sep 17 00:00:00 2001 From: Emily Cheyne Date: Sun, 2 Dec 2018 07:41:24 -0800 Subject: [PATCH 135/146] BAEL-2300 update readme --- core-java/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java/README.md b/core-java/README.md index e8923e9a2f..b8ad28cc0c 100644 --- a/core-java/README.md +++ b/core-java/README.md @@ -88,3 +88,4 @@ - [Changing the Order in a Sum Operation Can Produce Different Results?](https://www.baeldung.com/java-floating-point-sum-order) - [Java – Try with Resources](https://www.baeldung.com/java-try-with-resources) - [Abstract Classes in Java](https://www.baeldung.com/java-abstract-class) +- [Guide to Character Encoding](https://www.baeldung.com/java-char-encoding) From 0a87548bf80fdb8cfbd15edab2621df836ba1bda Mon Sep 17 00:00:00 2001 From: Emily Cheyne Date: Sun, 2 Dec 2018 08:11:11 -0800 Subject: [PATCH 136/146] BAEL-2089 update readme --- persistence-modules/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/persistence-modules/README.md b/persistence-modules/README.md index f12163bd6a..75ccc749e5 100644 --- a/persistence-modules/README.md +++ b/persistence-modules/README.md @@ -9,3 +9,4 @@ - [Introduction to Lettuce – the Java Redis Client](http://www.baeldung.com/java-redis-lettuce) - [A Guide to Jdbi](http://www.baeldung.com/jdbi) - [Pessimistic Locking in JPA](http://www.baeldung.com/jpa-pessimistic-locking) +- [Get All Data from a Table with Hibernate](https://www.baeldung.com/hibernate-select-all) From 857192358caf26bba0fec77f6991aed290fa91ab Mon Sep 17 00:00:00 2001 From: fanatixan Date: Sun, 2 Dec 2018 19:36:38 +0100 Subject: [PATCH 137/146] bael-2361 (#5804) * bael-2361 * Update RemoveLeadingAndTrailingZeroes.java * moving examples to java-string project --- .../RemoveLeadingAndTrailingZeroes.java | 103 +++++++++++++ ...emoveLeadingAndTrailingZeroesUnitTest.java | 143 ++++++++++++++++++ 2 files changed, 246 insertions(+) create mode 100644 java-strings/src/main/java/com/baeldung/string/removeleadingtrailingchar/RemoveLeadingAndTrailingZeroes.java create mode 100644 java-strings/src/test/java/com/baeldung/string/removeleadingtrailingchar/RemoveLeadingAndTrailingZeroesUnitTest.java diff --git a/java-strings/src/main/java/com/baeldung/string/removeleadingtrailingchar/RemoveLeadingAndTrailingZeroes.java b/java-strings/src/main/java/com/baeldung/string/removeleadingtrailingchar/RemoveLeadingAndTrailingZeroes.java new file mode 100644 index 0000000000..c9d748e897 --- /dev/null +++ b/java-strings/src/main/java/com/baeldung/string/removeleadingtrailingchar/RemoveLeadingAndTrailingZeroes.java @@ -0,0 +1,103 @@ +package com.baeldung.string.removeleadingtrailingchar; + + +import org.apache.commons.lang3.StringUtils; + +import com.google.common.base.CharMatcher; + +public class RemoveLeadingAndTrailingZeroes { + + public static String removeLeadingZeroesWithStringBuilder(String s) { + StringBuilder sb = new StringBuilder(s); + + while (sb.length() > 1 && sb.charAt(0) == '0') { + sb.deleteCharAt(0); + } + + return sb.toString(); + } + + public static String removeTrailingZeroesWithStringBuilder(String s) { + StringBuilder sb = new StringBuilder(s); + + while (sb.length() > 1 && sb.charAt(sb.length() - 1) == '0') { + sb.setLength(sb.length() - 1); + } + + return sb.toString(); + } + + public static String removeLeadingZeroesWithSubstring(String s) { + int index = 0; + + for (; index < s.length() - 1; index++) { + if (s.charAt(index) != '0') { + break; + } + } + + return s.substring(index); + } + + public static String removeTrailingZeroesWithSubstring(String s) { + int index = s.length() - 1; + + for (; index > 0; index--) { + if (s.charAt(index) != '0') { + break; + } + } + + return s.substring(0, index + 1); + } + + public static String removeLeadingZeroesWithApacheCommonsStripStart(String s) { + String stripped = StringUtils.stripStart(s, "0"); + + if (stripped.isEmpty() && !s.isEmpty()) { + return "0"; + } + + return stripped; + } + + public static String removeTrailingZeroesWithApacheCommonsStripEnd(String s) { + String stripped = StringUtils.stripEnd(s, "0"); + + if (stripped.isEmpty() && !s.isEmpty()) { + return "0"; + } + + return stripped; + } + + public static String removeLeadingZeroesWithGuavaTrimLeadingFrom(String s) { + String stripped = CharMatcher.is('0') + .trimLeadingFrom(s); + + if (stripped.isEmpty() && !s.isEmpty()) { + return "0"; + } + + return stripped; + } + + public static String removeTrailingZeroesWithGuavaTrimTrailingFrom(String s) { + String stripped = CharMatcher.is('0') + .trimTrailingFrom(s); + + if (stripped.isEmpty() && !s.isEmpty()) { + return "0"; + } + + return stripped; + } + + public static String removeLeadingZeroesWithRegex(String s) { + return s.replaceAll("^0+(?!$)", ""); + } + + public static String removeTrailingZeroesWithRegex(String s) { + return s.replaceAll("(?!^)0+$", ""); + } +} diff --git a/java-strings/src/test/java/com/baeldung/string/removeleadingtrailingchar/RemoveLeadingAndTrailingZeroesUnitTest.java b/java-strings/src/test/java/com/baeldung/string/removeleadingtrailingchar/RemoveLeadingAndTrailingZeroesUnitTest.java new file mode 100644 index 0000000000..55f932fea1 --- /dev/null +++ b/java-strings/src/test/java/com/baeldung/string/removeleadingtrailingchar/RemoveLeadingAndTrailingZeroesUnitTest.java @@ -0,0 +1,143 @@ +package com.baeldung.string.removeleadingtrailingchar; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.stream.Stream; + +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +public class RemoveLeadingAndTrailingZeroesUnitTest { + + public static Stream leadingZeroTestProvider() { + return Stream.of(Arguments.of("", ""), Arguments.of("abc", "abc"), Arguments.of("123", "123"), Arguments.of("0abc", "abc"), Arguments.of("0123", "123"), Arguments.of("0000123", "123"), Arguments.of("1230", "1230"), Arguments.of("01230", "1230"), Arguments.of("01", "1"), + Arguments.of("0001", "1"), Arguments.of("0", "0"), Arguments.of("00", "0"), Arguments.of("0000", "0"), Arguments.of("12034", "12034"), Arguments.of("1200034", "1200034"), Arguments.of("0012034", "12034"), Arguments.of("1203400", "1203400")); + } + + public static Stream trailingZeroTestProvider() { + return Stream.of(Arguments.of("", ""), Arguments.of("abc", "abc"), Arguments.of("123", "123"), Arguments.of("abc0", "abc"), Arguments.of("1230", "123"), Arguments.of("1230000", "123"), Arguments.of("0123", "0123"), Arguments.of("01230", "0123"), Arguments.of("10", "1"), + Arguments.of("1000", "1"), Arguments.of("0", "0"), Arguments.of("00", "0"), Arguments.of("0000", "0"), Arguments.of("12034", "12034"), Arguments.of("1200034", "1200034"), Arguments.of("0012034", "0012034"), Arguments.of("1203400", "12034")); + } + + @ParameterizedTest + @MethodSource("leadingZeroTestProvider") + public void givenTestStrings_whenRemoveLeadingZeroesWithStringBuilder_thenReturnWithoutLeadingZeroes(String input, String expected) { + // given + + // when + String result = RemoveLeadingAndTrailingZeroes.removeLeadingZeroesWithStringBuilder(input); + + // then + assertThat(result).isEqualTo(expected); + } + + @ParameterizedTest + @MethodSource("trailingZeroTestProvider") + public void givenTestStrings_whenRemoveTrailingZeroesWithStringBuilder_thenReturnWithoutTrailingZeroes(String input, String expected) { + // given + + // when + String result = RemoveLeadingAndTrailingZeroes.removeTrailingZeroesWithStringBuilder(input); + + // then + assertThat(result).isEqualTo(expected); + } + + @ParameterizedTest + @MethodSource("leadingZeroTestProvider") + public void givenTestStrings_whenRemoveLeadingZeroesWithSubstring_thenReturnWithoutLeadingZeroes(String input, String expected) { + // given + + // when + String result = RemoveLeadingAndTrailingZeroes.removeLeadingZeroesWithSubstring(input); + + // then + assertThat(result).isEqualTo(expected); + } + + @ParameterizedTest + @MethodSource("trailingZeroTestProvider") + public void givenTestStrings_whenRemoveTrailingZeroesWithSubstring_thenReturnWithoutTrailingZeroes(String input, String expected) { + // given + + // when + String result = RemoveLeadingAndTrailingZeroes.removeTrailingZeroesWithSubstring(input); + + // then + assertThat(result).isEqualTo(expected); + } + + @ParameterizedTest + @MethodSource("leadingZeroTestProvider") + public void givenTestStrings_whenRemoveLeadingZeroesWithApacheCommonsStripStart_thenReturnWithoutLeadingZeroes(String input, String expected) { + // given + + // when + String result = RemoveLeadingAndTrailingZeroes.removeLeadingZeroesWithApacheCommonsStripStart(input); + + // then + assertThat(result).isEqualTo(expected); + } + + @ParameterizedTest + @MethodSource("trailingZeroTestProvider") + public void givenTestStrings_whenRemoveTrailingZeroesWithApacheCommonsStripEnd_thenReturnWithoutTrailingZeroes(String input, String expected) { + // given + + // when + String result = RemoveLeadingAndTrailingZeroes.removeTrailingZeroesWithApacheCommonsStripEnd(input); + + // then + assertThat(result).isEqualTo(expected); + } + + @ParameterizedTest + @MethodSource("leadingZeroTestProvider") + public void givenTestStrings_whenRemoveLeadingZeroesWithGuavaTrimLeadingFrom_thenReturnWithoutLeadingZeroes(String input, String expected) { + // given + + // when + String result = RemoveLeadingAndTrailingZeroes.removeLeadingZeroesWithGuavaTrimLeadingFrom(input); + + // then + assertThat(result).isEqualTo(expected); + } + + @ParameterizedTest + @MethodSource("trailingZeroTestProvider") + public void givenTestStrings_whenRemoveTrailingZeroesWithGuavaTrimTrailingFrom_thenReturnWithoutTrailingZeroes(String input, String expected) { + // given + + // when + String result = RemoveLeadingAndTrailingZeroes.removeTrailingZeroesWithGuavaTrimTrailingFrom(input); + + // then + assertThat(result).isEqualTo(expected); + } + + @ParameterizedTest + @MethodSource("leadingZeroTestProvider") + public void givenTestStrings_whenRemoveLeadingZeroesWithRegex_thenReturnWithoutLeadingZeroes(String input, String expected) { + // given + + // when + String result = RemoveLeadingAndTrailingZeroes.removeLeadingZeroesWithRegex(input); + + // then + assertThat(result).isEqualTo(expected); + } + + @ParameterizedTest + @MethodSource("trailingZeroTestProvider") + public void givenTestStrings_whenRemoveTrailingZeroesWithRegex_thenReturnWithoutTrailingZeroes(String input, String expected) { + // given + + // when + String result = RemoveLeadingAndTrailingZeroes.removeTrailingZeroesWithRegex(input); + + // then + assertThat(result).isEqualTo(expected); + } + +} From 6b29e94a406d81e23f6d7534c3692b7c855da12a Mon Sep 17 00:00:00 2001 From: chrisoberle Date: Sun, 2 Dec 2018 21:23:39 -0500 Subject: [PATCH 138/146] BAEL-2174 How to use proxies in core java (#5805) * move samples from core-java to new core-java-net module * remove erroneous commit of .vscode dir --- core-java-net/.gitignore | 25 +++++++++++++++++++ core-java-net/README.md | 3 +++ core-java-net/pom.xml | 19 ++++++++++++++ .../proxies/CommandLineProxyDemo.java | 0 .../networking/proxies/DirectProxyDemo.java | 0 .../networking/proxies/SocksProxyDemo.java | 0 .../proxies/SystemPropertyProxyDemo.java | 0 .../proxies/UrlConnectionUtils.java | 0 .../networking/proxies/WebProxyDemo.java | 0 core-java-net/src/test/resources/.gitignore | 13 ++++++++++ pom.xml | 4 ++- 11 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 core-java-net/.gitignore create mode 100644 core-java-net/README.md create mode 100644 core-java-net/pom.xml rename {core-java => core-java-net}/src/main/java/com/baeldung/networking/proxies/CommandLineProxyDemo.java (100%) rename {core-java => core-java-net}/src/main/java/com/baeldung/networking/proxies/DirectProxyDemo.java (100%) rename {core-java => core-java-net}/src/main/java/com/baeldung/networking/proxies/SocksProxyDemo.java (100%) rename {core-java => core-java-net}/src/main/java/com/baeldung/networking/proxies/SystemPropertyProxyDemo.java (100%) rename {core-java => core-java-net}/src/main/java/com/baeldung/networking/proxies/UrlConnectionUtils.java (100%) rename {core-java => core-java-net}/src/main/java/com/baeldung/networking/proxies/WebProxyDemo.java (100%) create mode 100644 core-java-net/src/test/resources/.gitignore diff --git a/core-java-net/.gitignore b/core-java-net/.gitignore new file mode 100644 index 0000000000..374c8bf907 --- /dev/null +++ b/core-java-net/.gitignore @@ -0,0 +1,25 @@ +*.class + +0.* + +#folders# +/target +/neoDb* +/data +/src/main/webapp/WEB-INF/classes +*/META-INF/* +.resourceCache + +# Packaged files # +*.jar +*.war +*.ear + +# Files generated by integration tests +backup-pom.xml +/bin/ +/temp + +#IntelliJ specific +.idea/ +*.iml \ No newline at end of file diff --git a/core-java-net/README.md b/core-java-net/README.md new file mode 100644 index 0000000000..b7a142ea27 --- /dev/null +++ b/core-java-net/README.md @@ -0,0 +1,3 @@ +========= + +## Core Java Net diff --git a/core-java-net/pom.xml b/core-java-net/pom.xml new file mode 100644 index 0000000000..28d5766a9a --- /dev/null +++ b/core-java-net/pom.xml @@ -0,0 +1,19 @@ + + 4.0.0 + core-java-net + 0.1.0-SNAPSHOT + jar + core-java-net + + + com.baeldung + parent-java + 0.0.1-SNAPSHOT + ../parent-java + + + + core-java-net + + diff --git a/core-java/src/main/java/com/baeldung/networking/proxies/CommandLineProxyDemo.java b/core-java-net/src/main/java/com/baeldung/networking/proxies/CommandLineProxyDemo.java similarity index 100% rename from core-java/src/main/java/com/baeldung/networking/proxies/CommandLineProxyDemo.java rename to core-java-net/src/main/java/com/baeldung/networking/proxies/CommandLineProxyDemo.java diff --git a/core-java/src/main/java/com/baeldung/networking/proxies/DirectProxyDemo.java b/core-java-net/src/main/java/com/baeldung/networking/proxies/DirectProxyDemo.java similarity index 100% rename from core-java/src/main/java/com/baeldung/networking/proxies/DirectProxyDemo.java rename to core-java-net/src/main/java/com/baeldung/networking/proxies/DirectProxyDemo.java diff --git a/core-java/src/main/java/com/baeldung/networking/proxies/SocksProxyDemo.java b/core-java-net/src/main/java/com/baeldung/networking/proxies/SocksProxyDemo.java similarity index 100% rename from core-java/src/main/java/com/baeldung/networking/proxies/SocksProxyDemo.java rename to core-java-net/src/main/java/com/baeldung/networking/proxies/SocksProxyDemo.java diff --git a/core-java/src/main/java/com/baeldung/networking/proxies/SystemPropertyProxyDemo.java b/core-java-net/src/main/java/com/baeldung/networking/proxies/SystemPropertyProxyDemo.java similarity index 100% rename from core-java/src/main/java/com/baeldung/networking/proxies/SystemPropertyProxyDemo.java rename to core-java-net/src/main/java/com/baeldung/networking/proxies/SystemPropertyProxyDemo.java diff --git a/core-java/src/main/java/com/baeldung/networking/proxies/UrlConnectionUtils.java b/core-java-net/src/main/java/com/baeldung/networking/proxies/UrlConnectionUtils.java similarity index 100% rename from core-java/src/main/java/com/baeldung/networking/proxies/UrlConnectionUtils.java rename to core-java-net/src/main/java/com/baeldung/networking/proxies/UrlConnectionUtils.java diff --git a/core-java/src/main/java/com/baeldung/networking/proxies/WebProxyDemo.java b/core-java-net/src/main/java/com/baeldung/networking/proxies/WebProxyDemo.java similarity index 100% rename from core-java/src/main/java/com/baeldung/networking/proxies/WebProxyDemo.java rename to core-java-net/src/main/java/com/baeldung/networking/proxies/WebProxyDemo.java diff --git a/core-java-net/src/test/resources/.gitignore b/core-java-net/src/test/resources/.gitignore new file mode 100644 index 0000000000..83c05e60c8 --- /dev/null +++ b/core-java-net/src/test/resources/.gitignore @@ -0,0 +1,13 @@ +*.class + +#folders# +/target +/neoDb* +/data +/src/main/webapp/WEB-INF/classes +*/META-INF/* + +# Packaged files # +*.jar +*.war +*.ear \ No newline at end of file diff --git a/pom.xml b/pom.xml index 6480193201..b5c61dff9d 100644 --- a/pom.xml +++ b/pom.xml @@ -366,7 +366,8 @@ core-java - + core-java-net + dozer disruptor drools @@ -918,6 +919,7 @@ core-java + core-java-net dozer disruptor From dcf28dd16638a27ea620d5d47b904ebe1195afc5 Mon Sep 17 00:00:00 2001 From: Seun Matt Date: Mon, 3 Dec 2018 17:03:41 +0100 Subject: [PATCH 139/146] refactor the spring boot persistence mongodb module (#5829) * added example code for BAEL-2366 * moved example code for BAEL-2366 * example code for BAEL-1961 * moved example code into integration test * updated the test assertions * refactor the spring boot persistence mongodb module * remove redundant example code * declared the spring boot persistence module in the root pom * fixed issue with non-imported file --- .../.gitignore | 4 + .../spring-boot-persistence-mongodb/pom.xml | 106 ++++++++++++++++++ .../SpringBootPersistenceApplication.java | 13 +++ .../baeldung/mongodb/daos/UserRepository.java | 0 .../mongodb/events/UserModelListener.java | 0 .../mongodb/models/DatabaseSequence.java | 0 .../com/baeldung/mongodb/models/User.java | 0 .../services/SequenceGeneratorService.java | 0 .../src/main/resources/application.properties | 8 ++ ...goDbAutoGeneratedFieldIntegrationTest.java | 7 +- pom.xml | 1 + .../com/baeldung/mongodb/Application.java | 19 ---- .../mongodb/MongoDbSpringIntegrationTest.java | 1 + 13 files changed, 137 insertions(+), 22 deletions(-) create mode 100644 persistence-modules/spring-boot-persistence-mongodb/.gitignore create mode 100644 persistence-modules/spring-boot-persistence-mongodb/pom.xml create mode 100644 persistence-modules/spring-boot-persistence-mongodb/src/main/java/com/baeldung/SpringBootPersistenceApplication.java rename {spring-boot => persistence-modules/spring-boot-persistence-mongodb}/src/main/java/com/baeldung/mongodb/daos/UserRepository.java (100%) rename {spring-boot => persistence-modules/spring-boot-persistence-mongodb}/src/main/java/com/baeldung/mongodb/events/UserModelListener.java (100%) rename {spring-boot => persistence-modules/spring-boot-persistence-mongodb}/src/main/java/com/baeldung/mongodb/models/DatabaseSequence.java (100%) rename {spring-boot => persistence-modules/spring-boot-persistence-mongodb}/src/main/java/com/baeldung/mongodb/models/User.java (100%) rename {spring-boot => persistence-modules/spring-boot-persistence-mongodb}/src/main/java/com/baeldung/mongodb/services/SequenceGeneratorService.java (100%) create mode 100644 persistence-modules/spring-boot-persistence-mongodb/src/main/resources/application.properties rename {spring-boot => persistence-modules/spring-boot-persistence-mongodb}/src/test/java/com/baeldung/mongodb/MongoDbAutoGeneratedFieldIntegrationTest.java (88%) delete mode 100644 spring-boot/src/main/java/com/baeldung/mongodb/Application.java diff --git a/persistence-modules/spring-boot-persistence-mongodb/.gitignore b/persistence-modules/spring-boot-persistence-mongodb/.gitignore new file mode 100644 index 0000000000..f96dae6a60 --- /dev/null +++ b/persistence-modules/spring-boot-persistence-mongodb/.gitignore @@ -0,0 +1,4 @@ + +/.idea/ +/target/ +/spring-boot-persistence.iml diff --git a/persistence-modules/spring-boot-persistence-mongodb/pom.xml b/persistence-modules/spring-boot-persistence-mongodb/pom.xml new file mode 100644 index 0000000000..fc267eedf6 --- /dev/null +++ b/persistence-modules/spring-boot-persistence-mongodb/pom.xml @@ -0,0 +1,106 @@ + + + 4.0.0 + + + parent-boot-2 + com.baeldung + 0.0.1-SNAPSHOT + ../../parent-boot-2 + + + spring-boot-persistence-mongodb + war + spring-boot-persistence-mongodb + This is simple boot application for Spring boot persistence mongodb test + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-data-mongodb + + + + 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.springframework.boot + spring-boot-starter-test + test + + + + + spring-boot-persistence + + + src/main/resources + true + + + + + org.apache.maven.plugins + maven-war-plugin + + + + + + + autoconfiguration + + + + org.apache.maven.plugins + maven-surefire-plugin + + + integration-test + + test + + + + **/*LiveTest.java + **/*IntegrationTest.java + **/*IntTest.java + + + + + + + json + + + + + + + + + + \ No newline at end of file diff --git a/persistence-modules/spring-boot-persistence-mongodb/src/main/java/com/baeldung/SpringBootPersistenceApplication.java b/persistence-modules/spring-boot-persistence-mongodb/src/main/java/com/baeldung/SpringBootPersistenceApplication.java new file mode 100644 index 0000000000..2dff3f37df --- /dev/null +++ b/persistence-modules/spring-boot-persistence-mongodb/src/main/java/com/baeldung/SpringBootPersistenceApplication.java @@ -0,0 +1,13 @@ +package com.baeldung; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SpringBootPersistenceApplication { + + public static void main(String ... args) { + SpringApplication.run(SpringBootPersistenceApplication.class, args); + } + +} diff --git a/spring-boot/src/main/java/com/baeldung/mongodb/daos/UserRepository.java b/persistence-modules/spring-boot-persistence-mongodb/src/main/java/com/baeldung/mongodb/daos/UserRepository.java similarity index 100% rename from spring-boot/src/main/java/com/baeldung/mongodb/daos/UserRepository.java rename to persistence-modules/spring-boot-persistence-mongodb/src/main/java/com/baeldung/mongodb/daos/UserRepository.java diff --git a/spring-boot/src/main/java/com/baeldung/mongodb/events/UserModelListener.java b/persistence-modules/spring-boot-persistence-mongodb/src/main/java/com/baeldung/mongodb/events/UserModelListener.java similarity index 100% rename from spring-boot/src/main/java/com/baeldung/mongodb/events/UserModelListener.java rename to persistence-modules/spring-boot-persistence-mongodb/src/main/java/com/baeldung/mongodb/events/UserModelListener.java diff --git a/spring-boot/src/main/java/com/baeldung/mongodb/models/DatabaseSequence.java b/persistence-modules/spring-boot-persistence-mongodb/src/main/java/com/baeldung/mongodb/models/DatabaseSequence.java similarity index 100% rename from spring-boot/src/main/java/com/baeldung/mongodb/models/DatabaseSequence.java rename to persistence-modules/spring-boot-persistence-mongodb/src/main/java/com/baeldung/mongodb/models/DatabaseSequence.java diff --git a/spring-boot/src/main/java/com/baeldung/mongodb/models/User.java b/persistence-modules/spring-boot-persistence-mongodb/src/main/java/com/baeldung/mongodb/models/User.java similarity index 100% rename from spring-boot/src/main/java/com/baeldung/mongodb/models/User.java rename to persistence-modules/spring-boot-persistence-mongodb/src/main/java/com/baeldung/mongodb/models/User.java diff --git a/spring-boot/src/main/java/com/baeldung/mongodb/services/SequenceGeneratorService.java b/persistence-modules/spring-boot-persistence-mongodb/src/main/java/com/baeldung/mongodb/services/SequenceGeneratorService.java similarity index 100% rename from spring-boot/src/main/java/com/baeldung/mongodb/services/SequenceGeneratorService.java rename to persistence-modules/spring-boot-persistence-mongodb/src/main/java/com/baeldung/mongodb/services/SequenceGeneratorService.java diff --git a/persistence-modules/spring-boot-persistence-mongodb/src/main/resources/application.properties b/persistence-modules/spring-boot-persistence-mongodb/src/main/resources/application.properties new file mode 100644 index 0000000000..5b1b8000d0 --- /dev/null +++ b/persistence-modules/spring-boot-persistence-mongodb/src/main/resources/application.properties @@ -0,0 +1,8 @@ +spring.application.name=spring-boot-persistence +server.port=${PORT:0} + +#spring boot mongodb +spring.data.mongodb.host=localhost +spring.data.mongodb.port=27017 +spring.data.mongodb.database=springboot-mongo + diff --git a/spring-boot/src/test/java/com/baeldung/mongodb/MongoDbAutoGeneratedFieldIntegrationTest.java b/persistence-modules/spring-boot-persistence-mongodb/src/test/java/com/baeldung/mongodb/MongoDbAutoGeneratedFieldIntegrationTest.java similarity index 88% rename from spring-boot/src/test/java/com/baeldung/mongodb/MongoDbAutoGeneratedFieldIntegrationTest.java rename to persistence-modules/spring-boot-persistence-mongodb/src/test/java/com/baeldung/mongodb/MongoDbAutoGeneratedFieldIntegrationTest.java index 3430bca69a..cec1ad5fea 100644 --- a/spring-boot/src/test/java/com/baeldung/mongodb/MongoDbAutoGeneratedFieldIntegrationTest.java +++ b/persistence-modules/spring-boot-persistence-mongodb/src/test/java/com/baeldung/mongodb/MongoDbAutoGeneratedFieldIntegrationTest.java @@ -5,17 +5,18 @@ import com.baeldung.mongodb.models.User; 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 static org.assertj.core.api.Assertions.assertThat; -import java.util.List; +import static org.assertj.core.api.Assertions.assertThat; @RunWith(SpringRunner.class) +@SpringBootTest public class MongoDbAutoGeneratedFieldIntegrationTest { @Autowired - private UserRepository userRepository; + UserRepository userRepository; @Test public void contextLoads() {} diff --git a/pom.xml b/pom.xml index b5c61dff9d..dabb4a9628 100644 --- a/pom.xml +++ b/pom.xml @@ -479,6 +479,7 @@ persistence-modules/spring-data-cassandra persistence-modules/spring-data-couchbase-2 persistence-modules/spring-data-redis + persistence-modules/spring-boot-persistence-mongodb reactor-core resteasy diff --git a/spring-boot/src/main/java/com/baeldung/mongodb/Application.java b/spring-boot/src/main/java/com/baeldung/mongodb/Application.java deleted file mode 100644 index c0a9ad59a7..0000000000 --- a/spring-boot/src/main/java/com/baeldung/mongodb/Application.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.baeldung.mongodb; - -import com.baeldung.mongodb.daos.UserRepository; -import com.baeldung.mongodb.models.User; -import org.springframework.boot.CommandLineRunner; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.context.annotation.Bean; - -import java.util.List; - -@SpringBootApplication -public class Application { - - public static void main(String[] args) { - SpringApplication.run(Application.class, args); - } - -} diff --git a/spring-boot/src/test/java/com/baeldung/mongodb/MongoDbSpringIntegrationTest.java b/spring-boot/src/test/java/com/baeldung/mongodb/MongoDbSpringIntegrationTest.java index 5431217c3e..39127f62e9 100644 --- a/spring-boot/src/test/java/com/baeldung/mongodb/MongoDbSpringIntegrationTest.java +++ b/spring-boot/src/test/java/com/baeldung/mongodb/MongoDbSpringIntegrationTest.java @@ -2,6 +2,7 @@ package com.baeldung.mongodb; import static org.assertj.core.api.Assertions.assertThat; +import org.baeldung.boot.Application; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; From d25f0f1bb3e4dae3618ccfdcc09e2bf61212c978 Mon Sep 17 00:00:00 2001 From: yatendragoel Date: Mon, 3 Dec 2018 23:02:16 +0530 Subject: [PATCH 140/146] BAEL-2403: Immutable Map implementations in Java (#5828) * BAEL-2203 - Convert java.time.Instant to java.sql.Timestamp and vice-versa * BAEL-2203: Review edits * Removed ZoneId code * Converted class to JUnit Test * Update and rename ConvertInstantToTimestampTest.java to ConvertInstantToTimestampUnitTest.java * BAEL-2403: Immutable Map implementations in Java * BAEL-2403: Immutable Map implementations in Java - Changed file name --- .../java/map/ImmutableMapUnitTest.java | 87 +++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 java-collections-maps/src/test/java/com/baeldung/java/map/ImmutableMapUnitTest.java diff --git a/java-collections-maps/src/test/java/com/baeldung/java/map/ImmutableMapUnitTest.java b/java-collections-maps/src/test/java/com/baeldung/java/map/ImmutableMapUnitTest.java new file mode 100644 index 0000000000..b239ae07d8 --- /dev/null +++ b/java-collections-maps/src/test/java/com/baeldung/java/map/ImmutableMapUnitTest.java @@ -0,0 +1,87 @@ +package com.baeldung.java.map; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +import org.junit.jupiter.api.Test; + +import com.google.common.collect.ImmutableMap; + + +public class ImmutableMapUnitTest { + + @Test + public void whenCollectionsUnModifiableMapMethod_thenOriginalCollectionChangesReflectInUnmodifiableMap() { + + Map mutableMap = new HashMap<>(); + mutableMap.put("USA", "North America"); + + Map unmodifiableMap = Collections.unmodifiableMap(mutableMap); + assertThrows(UnsupportedOperationException.class, () -> unmodifiableMap.put("Canada", "North America")); + + mutableMap.remove("USA"); + assertFalse(unmodifiableMap.containsKey("USA")); + + mutableMap.put("Mexico", "North America"); + assertTrue(unmodifiableMap.containsKey("Mexico")); + } + + @Test + @SuppressWarnings("deprecation") + public void whenGuavaImmutableMapFromCopyOfMethod_thenOriginalCollectionChangesDoNotReflectInImmutableMap() { + + Map mutableMap = new HashMap<>(); + mutableMap.put("USA", "North America"); + + ImmutableMap immutableMap = ImmutableMap.copyOf(mutableMap); + assertTrue(immutableMap.containsKey("USA")); + + assertThrows(UnsupportedOperationException.class, () -> immutableMap.put("Canada", "North America")); + + mutableMap.remove("USA"); + assertTrue(immutableMap.containsKey("USA")); + + mutableMap.put("Mexico", "North America"); + assertFalse(immutableMap.containsKey("Mexico")); + } + + @Test + @SuppressWarnings("deprecation") + public void whenGuavaImmutableMapFromBuilderMethod_thenOriginalCollectionChangesDoNotReflectInImmutableMap() { + + Map mutableMap = new HashMap<>(); + mutableMap.put("USA", "North America"); + + ImmutableMap immutableMap = ImmutableMap.builder() + .putAll(mutableMap) + .put("Costa Rica", "North America") + .build(); + assertTrue(immutableMap.containsKey("USA")); + assertTrue(immutableMap.containsKey("Costa Rica")); + + assertThrows(UnsupportedOperationException.class, () -> immutableMap.put("Canada", "North America")); + + mutableMap.remove("USA"); + assertTrue(immutableMap.containsKey("USA")); + + mutableMap.put("Mexico", "North America"); + assertFalse(immutableMap.containsKey("Mexico")); + } + + @Test + @SuppressWarnings("deprecation") + public void whenGuavaImmutableMapFromOfMethod_thenOriginalCollectionChangesDoNotReflectInImmutableMap() { + + ImmutableMap immutableMap = ImmutableMap.of("USA", "North America", "Costa Rica", "North America"); + assertTrue(immutableMap.containsKey("USA")); + assertTrue(immutableMap.containsKey("Costa Rica")); + + assertThrows(UnsupportedOperationException.class, () -> immutableMap.put("Canada", "North America")); + } + +} From 3addff050fd2d2c67408f6151f3a96f42752e832 Mon Sep 17 00:00:00 2001 From: Mher Baghinyan Date: Tue, 4 Dec 2018 09:17:57 +0400 Subject: [PATCH 141/146] printf examples Issue: BAEL-2228 --- .../com/baeldung/printf/PrintfExamples.java | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 core-java/src/main/java/com/baeldung/printf/PrintfExamples.java diff --git a/core-java/src/main/java/com/baeldung/printf/PrintfExamples.java b/core-java/src/main/java/com/baeldung/printf/PrintfExamples.java new file mode 100644 index 0000000000..3d451f6f50 --- /dev/null +++ b/core-java/src/main/java/com/baeldung/printf/PrintfExamples.java @@ -0,0 +1,61 @@ +package com.baeldung.printf; + +import java.util.Date; +import java.util.Locale; + +public class PrintfExamples { + + public static void main(String[] args) { + + printfNewLine(); + printfChar(); + printfString(); + printfNumber(); + printfDateTime(); + printfBoolean(); + } + + private static void printfNewLine() { + System.out.printf("baeldung%nline%nterminator"); + } + + private static void printfString() { + System.out.printf("'%s' %n", "baeldung"); + System.out.printf("'%S' %n", "baeldung"); + System.out.printf("'%15s' %n", "baeldung"); + System.out.printf("'%-10s' %n", "baeldung"); + } + + private static void printfChar() { + System.out.printf("%c%n", 's'); + System.out.printf("%C%n", 's'); + } + + private static void printfNumber() { + System.out.printf("simple integer: %d%n", 10000L); + + System.out.printf(Locale.US, "%,d %n", 10000); + System.out.printf(Locale.ITALY, "%,d %n", 10000); + + System.out.printf("%f%n", 5.1473); + System.out.printf("'%5.2f'%n", 5.1473); + System.out.printf("'%5.2e'%n", 5.1473); + } + + private static void printfBoolean() { + System.out.printf("%b%n", null); + System.out.printf("%B%n", false); + System.out.printf("%B%n", 5.3); + System.out.printf("%b%n", "random text"); + } + + private static void printfDateTime() { + Date date = new Date(); + System.out.printf("%tT%n", date); + System.out.printf("hours %tH: minutes %tM: seconds %tS%n", date, date, date); + System.out.printf("%1$tH:%1$tM:%1$tS %1$tp %1$tL %1$tN %1$tz %n", date); + + System.out.printf("%1$tA %1$tB %1$tY %n", date); + System.out.printf("%1$td.%1$tm.%1$ty %n", date); + } +} From 57d6c392b2cdabc158274ee5c3d87447f107795b Mon Sep 17 00:00:00 2001 From: Eugen Date: Tue, 4 Dec 2018 17:00:27 +0200 Subject: [PATCH 142/146] Update README.md --- spring-rest-full/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-rest-full/README.md b/spring-rest-full/README.md index b8fef9cb82..a5d72372f7 100644 --- a/spring-rest-full/README.md +++ b/spring-rest-full/README.md @@ -17,7 +17,7 @@ The "Learn Spring Security" Classes: http://github.learnspringsecurity.com - [Project Configuration with Spring](http://www.baeldung.com/project-configuration-with-spring) - [Metrics for your Spring REST API](http://www.baeldung.com/spring-rest-api-metrics) - [Bootstrap a Web Application with Spring 4](http://www.baeldung.com/bootstraping-a-web-application-with-spring-and-java-based-configuration) -- [Build a REST API with Spring 4 and Java Config](http://www.baeldung.com/building-a-restful-web-service-with-spring-and-java-based-configuration) +- [Build a REST API with Spring and Java Config](http://www.baeldung.com/building-a-restful-web-service-with-spring-and-java-based-configuration) - [Error Handling for REST with Spring](http://www.baeldung.com/exception-handling-for-rest-with-spring) From a370f6e78170adbede74bb3d6a749ea9c8685850 Mon Sep 17 00:00:00 2001 From: Dhananjay Singh Date: Wed, 5 Dec 2018 07:23:51 +0530 Subject: [PATCH 143/146] Calculate Factorial in Java (#5748) * Factorials * Refactored factorials * Change input to int * Small fixes * Renamed tests --- algorithms-miscellaneous-1/pom.xml | 6 ++ .../algorithms/factorial/Factorial.java | 63 ++++++++++++++++ .../factorial/FactorialUnitTest.java | 72 +++++++++++++++++++ 3 files changed, 141 insertions(+) create mode 100644 algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/factorial/Factorial.java create mode 100644 algorithms-miscellaneous-1/src/test/java/com/baeldung/algorithms/factorial/FactorialUnitTest.java diff --git a/algorithms-miscellaneous-1/pom.xml b/algorithms-miscellaneous-1/pom.xml index 75b031282b..5006670dd9 100644 --- a/algorithms-miscellaneous-1/pom.xml +++ b/algorithms-miscellaneous-1/pom.xml @@ -17,6 +17,11 @@ commons-math3 ${commons-math3.version} + + com.google.guava + guava + ${guava.version} + commons-codec commons-codec @@ -73,6 +78,7 @@ 3.6.1 3.9.0 1.11 + 25.1-jre \ No newline at end of file diff --git a/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/factorial/Factorial.java b/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/factorial/Factorial.java new file mode 100644 index 0000000000..43d2221773 --- /dev/null +++ b/algorithms-miscellaneous-1/src/main/java/com/baeldung/algorithms/factorial/Factorial.java @@ -0,0 +1,63 @@ +package com.baeldung.algorithms.factorial; + +import java.math.BigInteger; +import java.util.stream.LongStream; + +import org.apache.commons.math3.util.CombinatoricsUtils; + +import com.google.common.math.BigIntegerMath; + +public class Factorial { + + public long factorialUsingForLoop(int n) { + long fact = 1; + for (int i = 2; i <= n; i++) { + fact = fact * i; + } + return fact; + } + + public long factorialUsingStreams(int n) { + return LongStream.rangeClosed(1, n) + .reduce(1, (long x, long y) -> x * y); + } + + public long factorialUsingRecursion(int n) { + if (n <= 2) { + return n; + } + return n * factorialUsingRecursion(n - 1); + } + + private Long[] factorials = new Long[20]; + + public long factorialUsingMemoize(int n) { + + if (factorials[n] != null) { + return factorials[n]; + } + + if (n <= 2) { + return n; + } + long nthValue = n * factorialUsingMemoize(n - 1); + factorials[n] = nthValue; + return nthValue; + } + + public BigInteger factorialHavingLargeResult(int n) { + BigInteger result = BigInteger.ONE; + for (int i = 2; i <= n; i++) + result = result.multiply(BigInteger.valueOf(i)); + return result; + } + + public long factorialUsingApacheCommons(int n) { + return CombinatoricsUtils.factorial(n); + } + + public BigInteger factorialUsingGuava(int n) { + return BigIntegerMath.factorial(n); + } + +} diff --git a/algorithms-miscellaneous-1/src/test/java/com/baeldung/algorithms/factorial/FactorialUnitTest.java b/algorithms-miscellaneous-1/src/test/java/com/baeldung/algorithms/factorial/FactorialUnitTest.java new file mode 100644 index 0000000000..c185dba62b --- /dev/null +++ b/algorithms-miscellaneous-1/src/test/java/com/baeldung/algorithms/factorial/FactorialUnitTest.java @@ -0,0 +1,72 @@ +package com.baeldung.algorithms.factorial; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.math.BigInteger; + +import org.junit.Before; +import org.junit.Test; + +public class FactorialUnitTest { + + Factorial factorial; + + @Before + public void setup() { + factorial = new Factorial(); + } + + @Test + public void whenCalculatingFactorialUsingForLoop_thenCorrect() { + int n = 5; + + assertThat(factorial.factorialUsingForLoop(n)).isEqualTo(120); + } + + @Test + public void whenCalculatingFactorialUsingStreams_thenCorrect() { + int n = 5; + + assertThat(factorial.factorialUsingStreams(n)).isEqualTo(120); + } + + @Test + public void whenCalculatingFactorialUsingRecursion_thenCorrect() { + int n = 5; + + assertThat(factorial.factorialUsingRecursion(n)).isEqualTo(120); + } + + @Test + public void whenCalculatingFactorialUsingMemoize_thenCorrect() { + int n = 5; + + assertThat(factorial.factorialUsingMemoize(n)).isEqualTo(120); + + n = 6; + + assertThat(factorial.factorialUsingMemoize(n)).isEqualTo(720); + } + + @Test + public void whenCalculatingFactorialHavingLargeResult_thenCorrect() { + int n = 22; + + assertThat(factorial.factorialHavingLargeResult(n)).isEqualTo(new BigInteger("1124000727777607680000")); + } + + @Test + public void whenCalculatingFactorialUsingApacheCommons_thenCorrect() { + int n = 5; + + assertThat(factorial.factorialUsingApacheCommons(n)).isEqualTo(120); + } + + @Test + public void whenCalculatingFactorialUsingGuava_thenCorrect() { + int n = 22; + + assertThat(factorial.factorialUsingGuava(n)).isEqualTo(new BigInteger("1124000727777607680000")); + } + +} From c4d92d17b5d77d9e675d25a4e0620af4cb8f130f Mon Sep 17 00:00:00 2001 From: gmconte <3528114+gmconte@users.noreply.github.com> Date: Wed, 5 Dec 2018 03:09:47 +0000 Subject: [PATCH 144/146] BAEL-2346: modifying concurrency code to add more examples (#5843) --- .../ScheduledExecutorServiceDemo.java | 58 ++++++++++++------- .../daemon/MultipleThreadsExample.java | 12 ++++ .../baeldung/concurrent/daemon/NewThread.java | 10 +++- .../daemon/SingleThreadExample.java | 8 +++ 4 files changed, 65 insertions(+), 23 deletions(-) create mode 100644 core-java-concurrency/src/main/java/com/baeldung/concurrent/daemon/MultipleThreadsExample.java create mode 100644 core-java-concurrency/src/main/java/com/baeldung/concurrent/daemon/SingleThreadExample.java diff --git a/core-java-concurrency/src/main/java/com/baeldung/concurrent/Scheduledexecutorservice/ScheduledExecutorServiceDemo.java b/core-java-concurrency/src/main/java/com/baeldung/concurrent/Scheduledexecutorservice/ScheduledExecutorServiceDemo.java index b77019eea5..0989195ba7 100644 --- a/core-java-concurrency/src/main/java/com/baeldung/concurrent/Scheduledexecutorservice/ScheduledExecutorServiceDemo.java +++ b/core-java-concurrency/src/main/java/com/baeldung/concurrent/Scheduledexecutorservice/ScheduledExecutorServiceDemo.java @@ -1,34 +1,52 @@ package com.baeldung.concurrent.Scheduledexecutorservice; import java.util.concurrent.Executors; -import java.util.concurrent.Future; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; +import java.util.function.Function; public class ScheduledExecutorServiceDemo { - public void execute() { + private void execute() { ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor(); - - ScheduledFuture scheduledFuture = executorService.schedule(() -> { - // Task - }, 1, TimeUnit.SECONDS); - - executorService.scheduleAtFixedRate(() -> { - // Task - }, 1, 10, TimeUnit.SECONDS); - - executorService.scheduleWithFixedDelay(() -> { - // Task - }, 1, 10, TimeUnit.SECONDS); - - Future future = executorService.schedule(() -> { - // Task - return "Hellow world"; - }, 1, TimeUnit.SECONDS); - + getTasksToRun().apply(executorService); executorService.shutdown(); } + private void executeWithMultiThread() { + ScheduledExecutorService executorService = Executors.newScheduledThreadPool(2); + getTasksToRun().apply(executorService); + executorService.shutdown(); + } + + private Function getTasksToRun() { + return (executorService -> { + ScheduledFuture scheduledFuture1 = executorService.schedule(() -> { + // Task + }, 1, TimeUnit.SECONDS); + + ScheduledFuture scheduledFuture2 = executorService.scheduleAtFixedRate(() -> { + // Task + }, 1, 10, TimeUnit.SECONDS); + + ScheduledFuture scheduledFuture3 = executorService.scheduleWithFixedDelay(() -> { + // Task + }, 1, 10, TimeUnit.SECONDS); + + ScheduledFuture scheduledFuture4 = executorService.schedule(() -> { + // Task + return "Hellow world"; + }, 1, TimeUnit.SECONDS); + return null; + }); + } + + public static void main(String... args) { + ScheduledExecutorServiceDemo demo = new ScheduledExecutorServiceDemo(); + demo.execute(); + demo.executeWithMultiThread(); + } + + } diff --git a/core-java-concurrency/src/main/java/com/baeldung/concurrent/daemon/MultipleThreadsExample.java b/core-java-concurrency/src/main/java/com/baeldung/concurrent/daemon/MultipleThreadsExample.java new file mode 100644 index 0000000000..492466e0c3 --- /dev/null +++ b/core-java-concurrency/src/main/java/com/baeldung/concurrent/daemon/MultipleThreadsExample.java @@ -0,0 +1,12 @@ +package com.baeldung.concurrent.daemon; + +public class MultipleThreadsExample { + public static void main(String[] args) { + NewThread t1 = new NewThread(); + t1.setName("MyThread-1"); + NewThread t2 = new NewThread(); + t2.setName("MyThread-2"); + t1.start(); + t2.start(); + } +} diff --git a/core-java-concurrency/src/main/java/com/baeldung/concurrent/daemon/NewThread.java b/core-java-concurrency/src/main/java/com/baeldung/concurrent/daemon/NewThread.java index 4d87978070..370ce99c09 100644 --- a/core-java-concurrency/src/main/java/com/baeldung/concurrent/daemon/NewThread.java +++ b/core-java-concurrency/src/main/java/com/baeldung/concurrent/daemon/NewThread.java @@ -1,14 +1,18 @@ package com.baeldung.concurrent.daemon; public class NewThread extends Thread { - public void run() { long startTime = System.currentTimeMillis(); while (true) { for (int i = 0; i < 10; i++) { - System.out.println("New Thread is running..." + i); + System.out.println(this.getName() + ": New Thread is running..." + i); + try { + //Wait for one sec so it doesn't print too fast + Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } } - // prevent the Thread to run forever. It will finish it's execution after 2 seconds if (System.currentTimeMillis() - startTime > 2000) { Thread.currentThread().interrupt(); diff --git a/core-java-concurrency/src/main/java/com/baeldung/concurrent/daemon/SingleThreadExample.java b/core-java-concurrency/src/main/java/com/baeldung/concurrent/daemon/SingleThreadExample.java new file mode 100644 index 0000000000..16d8b2be1e --- /dev/null +++ b/core-java-concurrency/src/main/java/com/baeldung/concurrent/daemon/SingleThreadExample.java @@ -0,0 +1,8 @@ +package com.baeldung.concurrent.daemon; + +public class SingleThreadExample { + public static void main(String[] args) { + NewThread t = new NewThread(); + t.start(); + } +} From a21f82001cee47d1d69fecc069b8da631a3d6533 Mon Sep 17 00:00:00 2001 From: Ger Roza Date: Wed, 5 Dec 2018 01:14:12 -0200 Subject: [PATCH 145/146] Added cases using subscribeOn and publishOn when debuggin reactive streams, for analysis (#5841) --- .../consumer/chronjobs/ChronJobs.java | 32 +++++++++++++++++++ .../debugging/consumer/model/Foo.java | 7 +++- .../debugging/consumer/model/FooDto.java | 8 +++-- .../consumer/service/FooService.java | 29 +++++++++++++++++ 4 files changed, 73 insertions(+), 3 deletions(-) diff --git a/spring-5-reactive/src/main/java/com/baeldung/debugging/consumer/chronjobs/ChronJobs.java b/spring-5-reactive/src/main/java/com/baeldung/debugging/consumer/chronjobs/ChronJobs.java index 09cbc34a6f..bf96ab56d6 100644 --- a/spring-5-reactive/src/main/java/com/baeldung/debugging/consumer/chronjobs/ChronJobs.java +++ b/spring-5-reactive/src/main/java/com/baeldung/debugging/consumer/chronjobs/ChronJobs.java @@ -119,4 +119,36 @@ public class ChronJobs { logger.info("process 4 with approach 4"); service.processUsingApproachFourWithCheckpoint(fluxFoo); } + + @Scheduled(fixedRate = 20000) + public void consumeFiniteFluxWitParallelScheduler() { + Flux fluxFoo = client.get() + .uri("/functional-reactive/periodic-foo-2") + .accept(MediaType.TEXT_EVENT_STREAM) + .retrieve() + .bodyToFlux(FooDto.class) + .delayElements(Duration.ofMillis(100)) + .map(dto -> { + logger.debug("process 5-parallel with dto id {} name{}", dto.getId(), dto.getName()); + return new Foo(dto); + }); + logger.info("process 5-parallel with approach 5-parallel"); + service.processUsingApproachFivePublishingToDifferentParallelThreads(fluxFoo); + } + + @Scheduled(fixedRate = 20000) + public void consumeFiniteFluxWithSingleSchedulers() { + Flux fluxFoo = client.get() + .uri("/functional-reactive/periodic-foo-2") + .accept(MediaType.TEXT_EVENT_STREAM) + .retrieve() + .bodyToFlux(FooDto.class) + .delayElements(Duration.ofMillis(100)) + .map(dto -> { + logger.debug("process 5-single with dto id {} name{}", dto.getId(), dto.getName()); + return new Foo(dto); + }); + logger.info("process 5-single with approach 5-single"); + service.processUsingApproachFivePublishingToDifferentSingleThreads(fluxFoo); + } } diff --git a/spring-5-reactive/src/main/java/com/baeldung/debugging/consumer/model/Foo.java b/spring-5-reactive/src/main/java/com/baeldung/debugging/consumer/model/Foo.java index e101457b84..ac5093c261 100644 --- a/spring-5-reactive/src/main/java/com/baeldung/debugging/consumer/model/Foo.java +++ b/spring-5-reactive/src/main/java/com/baeldung/debugging/consumer/model/Foo.java @@ -6,8 +6,13 @@ import org.springframework.data.annotation.Id; import lombok.AllArgsConstructor; import lombok.Data; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; -@Data +@Getter +@Setter +@NoArgsConstructor @AllArgsConstructor public class Foo { diff --git a/spring-5-reactive/src/main/java/com/baeldung/debugging/consumer/model/FooDto.java b/spring-5-reactive/src/main/java/com/baeldung/debugging/consumer/model/FooDto.java index 50508fd216..33f19c4e60 100644 --- a/spring-5-reactive/src/main/java/com/baeldung/debugging/consumer/model/FooDto.java +++ b/spring-5-reactive/src/main/java/com/baeldung/debugging/consumer/model/FooDto.java @@ -1,9 +1,13 @@ package com.baeldung.debugging.consumer.model; import lombok.AllArgsConstructor; -import lombok.Data; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; -@Data +@Getter +@Setter +@NoArgsConstructor @AllArgsConstructor public class FooDto { diff --git a/spring-5-reactive/src/main/java/com/baeldung/debugging/consumer/service/FooService.java b/spring-5-reactive/src/main/java/com/baeldung/debugging/consumer/service/FooService.java index 937e445ef5..438f6d473c 100644 --- a/spring-5-reactive/src/main/java/com/baeldung/debugging/consumer/service/FooService.java +++ b/spring-5-reactive/src/main/java/com/baeldung/debugging/consumer/service/FooService.java @@ -13,6 +13,7 @@ import org.springframework.stereotype.Component; import com.baeldung.debugging.consumer.model.Foo; import reactor.core.publisher.Flux; +import reactor.core.scheduler.Schedulers; @Component public class FooService { @@ -88,4 +89,32 @@ public class FooService { flux.subscribe(); } + public void processUsingApproachFivePublishingToDifferentParallelThreads(Flux flux) { + logger.info("starting approach five-parallel!"); + flux = concatAndSubstringFooName(flux).publishOn(Schedulers.newParallel("five-parallel-foo")) + .log(); + flux = concatAndSubstringFooName(flux); + flux = divideFooQuantity(flux); + flux = reportResult(flux, "FIVE-PARALLEL").publishOn(Schedulers.newSingle("five-parallel-bar")); + flux = concatAndSubstringFooName(flux).doOnError(error -> { + logger.error("Approach 5-parallel failed!", error); + }); + flux.subscribeOn(Schedulers.newParallel("five-parallel-starter")) + .subscribe(); + } + + public void processUsingApproachFivePublishingToDifferentSingleThreads(Flux flux) { + logger.info("starting approach five-single!"); + flux = flux.log() + .subscribeOn(Schedulers.newSingle("five-single-starter")); + flux = concatAndSubstringFooName(flux).publishOn(Schedulers.newSingle("five-single-foo")); + flux = concatAndSubstringFooName(flux); + flux = divideFooQuantity(flux); + flux = reportResult(flux, "FIVE-SINGLE").publishOn(Schedulers.newSingle("five-single-bar")); + flux = concatAndSubstringFooName(flux).doOnError(error -> { + logger.error("Approach 5-single failed!", error); + }); + flux.subscribe(); + } + } From cac62f06ae95ca2c97d1707a24973a48c778d246 Mon Sep 17 00:00:00 2001 From: Priyesh Mashelkar Date: Wed, 5 Dec 2018 18:30:14 +0000 Subject: [PATCH 146/146] BAEL-2344 Hibernate Named Query (#5835) * Added writer * Added implementation and test class * Added more details * Updated tests * Updated code as per review comments * Added test class and one named query * Updated test class * Added update HQL * Added new initialisation script and new queries * Corrected queries * Removed commented code * printf examples Issue: BAEL-2228 * Update README.md * Added implementation and test class * Added more details * Updated tests * Updated code as per review comments * Added test class and one named query * Updated test class * Added update HQL * Added new initialisation script and new queries * Corrected queries * Removed commented code --- .../hibernate/entities/DeptEmployee.java | 75 +++++++++++++ .../src/main/resources/init_database.sql | 10 ++ .../hibernate/NamedQueryIntegrationTest.java | 103 ++++++++++++++++++ .../resources/hibernate-namedquery.properties | 9 ++ .../hibernate/entities/DeptEmployee.java | 14 ++- 5 files changed, 209 insertions(+), 2 deletions(-) create mode 100644 hibernate5/src/main/java/com/baeldung/hibernate/entities/DeptEmployee.java create mode 100644 hibernate5/src/main/resources/init_database.sql create mode 100644 hibernate5/src/test/java/com/baeldung/hibernate/NamedQueryIntegrationTest.java create mode 100644 hibernate5/src/test/resources/hibernate-namedquery.properties diff --git a/hibernate5/src/main/java/com/baeldung/hibernate/entities/DeptEmployee.java b/hibernate5/src/main/java/com/baeldung/hibernate/entities/DeptEmployee.java new file mode 100644 index 0000000000..7813e89a48 --- /dev/null +++ b/hibernate5/src/main/java/com/baeldung/hibernate/entities/DeptEmployee.java @@ -0,0 +1,75 @@ +package com.baeldung.hibernate.entities; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.ManyToOne; + +@org.hibernate.annotations.NamedQueries({ @org.hibernate.annotations.NamedQuery(name = "DeptEmployee_FindByEmployeeNumber", query = "from DeptEmployee where employeeNumber = :employeeNo"), + @org.hibernate.annotations.NamedQuery(name = "DeptEmployee_FindAllByDesgination", query = "from DeptEmployee where designation = :designation"), + @org.hibernate.annotations.NamedQuery(name = "DeptEmployee_UpdateEmployeeDepartment", query = "Update DeptEmployee set department = :newDepartment where employeeNumber = :employeeNo"), + @org.hibernate.annotations.NamedQuery(name = "DeptEmployee_FindAllByDepartment", query = "from DeptEmployee where department = :department", timeout = 1, fetchSize = 10) }) +@org.hibernate.annotations.NamedNativeQueries({ @org.hibernate.annotations.NamedNativeQuery(name = "DeptEmployee_FindByEmployeeName", query = "select * from deptemployee emp where name=:name", resultClass = DeptEmployee.class), + @org.hibernate.annotations.NamedNativeQuery(name = "DeptEmployee_UpdateEmployeeDesignation", query = "call UPDATE_EMPLOYEE_DESIGNATION(:employeeNumber, :newDesignation)", resultClass = DeptEmployee.class) }) +@Entity +public class DeptEmployee { + @Id + @GeneratedValue(strategy = GenerationType.SEQUENCE) + private long id; + + private String employeeNumber; + + private String designation; + + private String name; + + @ManyToOne + private Department department; + + public DeptEmployee(String name, String employeeNumber, Department department) { + this.name = name; + this.employeeNumber = employeeNumber; + this.department = department; + } + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public String getEmployeeNumber() { + return employeeNumber; + } + + public void setEmployeeNumber(String employeeNumber) { + this.employeeNumber = employeeNumber; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Department getDepartment() { + return department; + } + + public void setDepartment(Department department) { + this.department = department; + } + + public String getDesignation() { + return designation; + } + + public void setDesignation(String designation) { + this.designation = designation; + } +} diff --git a/hibernate5/src/main/resources/init_database.sql b/hibernate5/src/main/resources/init_database.sql new file mode 100644 index 0000000000..154a5a0bc0 --- /dev/null +++ b/hibernate5/src/main/resources/init_database.sql @@ -0,0 +1,10 @@ +CREATE ALIAS UPDATE_EMPLOYEE_DESIGNATION AS $$ +import java.sql.CallableStatement; +import java.sql.Connection; +import java.sql.SQLException; +@CODE +void updateEmployeeDesignation(final Connection conn, final String employeeNumber, final String designation) throws SQLException { + CallableStatement updateStatement = conn.prepareCall("update deptemployee set designation = '" + designation + "' where employeeNumber = '" + employeeNumber + "'"); + updateStatement.execute(); +} +$$; \ No newline at end of file diff --git a/hibernate5/src/test/java/com/baeldung/hibernate/NamedQueryIntegrationTest.java b/hibernate5/src/test/java/com/baeldung/hibernate/NamedQueryIntegrationTest.java new file mode 100644 index 0000000000..ef6ec89bc4 --- /dev/null +++ b/hibernate5/src/test/java/com/baeldung/hibernate/NamedQueryIntegrationTest.java @@ -0,0 +1,103 @@ +package com.baeldung.hibernate; + +import java.io.IOException; + +import org.hibernate.Session; +import org.hibernate.Transaction; +import org.hibernate.query.NativeQuery; +import org.hibernate.query.Query; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +import com.baeldung.hibernate.entities.Department; +import com.baeldung.hibernate.entities.DeptEmployee; + +public class NamedQueryIntegrationTest { + private static Session session; + + private Transaction transaction; + + private Long purchaseDeptId; + + @BeforeClass + public static void setUpClass() throws IOException { + session = HibernateUtil.getSessionFactory("hibernate-namedquery.properties").openSession(); + } + + @Before + public void setUp() throws IOException { + transaction = session.beginTransaction(); + session.createNativeQuery("delete from deptemployee").executeUpdate(); + session.createNativeQuery("delete from department").executeUpdate(); + Department salesDepartment = new Department("Sales"); + Department purchaseDepartment = new Department("Purchase"); + DeptEmployee employee1 = new DeptEmployee("John Wayne", "001", salesDepartment); + DeptEmployee employee2 = new DeptEmployee("Sarah Vinton", "002", salesDepartment); + DeptEmployee employee3 = new DeptEmployee("Lisa Carter", "003", salesDepartment); + session.persist(salesDepartment); + session.persist(purchaseDepartment); + purchaseDeptId = purchaseDepartment.getId(); + session.persist(employee1); + session.persist(employee2); + session.persist(employee3); + transaction.commit(); + transaction = session.beginTransaction(); + } + + @After + public void tearDown() { + if(transaction.isActive()) { + transaction.rollback(); + } + } + + @Test + public void whenNamedQueryIsCalledUsingCreateNamedQuery_ThenOk() { + Query query = session.createNamedQuery("DeptEmployee_FindByEmployeeNumber", DeptEmployee.class); + query.setParameter("employeeNo", "001"); + DeptEmployee result = query.getSingleResult(); + Assert.assertNotNull(result); + Assert.assertEquals("John Wayne", result.getName()); + } + + @Test + public void whenNamedNativeQueryIsCalledUsingCreateNamedQuery_ThenOk() { + Query query = session.createNamedQuery("DeptEmployee_FindByEmployeeName", DeptEmployee.class); + query.setParameter("name", "John Wayne"); + DeptEmployee result = query.getSingleResult(); + Assert.assertNotNull(result); + Assert.assertEquals("001", result.getEmployeeNumber()); + } + + @Test + public void whenNamedNativeQueryIsCalledUsingGetNamedNativeQuery_ThenOk() { + @SuppressWarnings("rawtypes") + NativeQuery query = session.getNamedNativeQuery("DeptEmployee_FindByEmployeeName"); + query.setParameter("name", "John Wayne"); + DeptEmployee result = (DeptEmployee) query.getSingleResult(); + Assert.assertNotNull(result); + Assert.assertEquals("001", result.getEmployeeNumber()); + } + + @Test + public void whenUpdateQueryIsCalledWithCreateNamedQuery_ThenOk() { + Query spQuery = session.createNamedQuery("DeptEmployee_UpdateEmployeeDepartment"); + spQuery.setParameter("employeeNo", "001"); + Department newDepartment = session.find(Department.class, purchaseDeptId); + spQuery.setParameter("newDepartment", newDepartment); + spQuery.executeUpdate(); + transaction.commit(); + } + + @Test + public void whenNamedStoredProcedureIsCalledWithCreateNamedQuery_ThenOk() { + Query spQuery = session.createNamedQuery("DeptEmployee_UpdateEmployeeDesignation"); + spQuery.setParameter("employeeNumber", "002"); + spQuery.setParameter("newDesignation", "Supervisor"); + spQuery.executeUpdate(); + transaction.commit(); + } +} diff --git a/hibernate5/src/test/resources/hibernate-namedquery.properties b/hibernate5/src/test/resources/hibernate-namedquery.properties new file mode 100644 index 0000000000..457f965347 --- /dev/null +++ b/hibernate5/src/test/resources/hibernate-namedquery.properties @@ -0,0 +1,9 @@ +hibernate.connection.driver_class=org.h2.Driver +hibernate.connection.url=jdbc:h2:mem:mydb1;DB_CLOSE_DELAY=-1;INIT=RUNSCRIPT FROM 'src/main/resources/init_database.sql' +hibernate.connection.username=sa +hibernate.connection.autocommit=true +jdbc.password= + +hibernate.dialect=org.hibernate.dialect.H2Dialect +hibernate.show_sql=true +hibernate.hbm2ddl.auto=create-drop \ No newline at end of file diff --git a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/entities/DeptEmployee.java b/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/entities/DeptEmployee.java index 8b5d9c41f3..6510e70650 100644 --- a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/entities/DeptEmployee.java +++ b/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/entities/DeptEmployee.java @@ -1,7 +1,17 @@ package com.baeldung.hibernate.entities; -import javax.persistence.*; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.ManyToOne; +@org.hibernate.annotations.NamedQueries({ @org.hibernate.annotations.NamedQuery(name = "DeptEmployee_FindByEmployeeNumber", query = "from DeptEmployee where employeeNumber = :employeeNo"), + @org.hibernate.annotations.NamedQuery(name = "DeptEmployee_FindAllByDesgination", query = "from DeptEmployee where designation = :designation"), + @org.hibernate.annotations.NamedQuery(name = "DeptEmployee_UpdateEmployeeDepartment", query = "Update DeptEmployee set department = :newDepartment where employeeNumber = :employeeNo"), + @org.hibernate.annotations.NamedQuery(name = "DeptEmployee_FindAllByDepartment", query = "from DeptEmployee where department = :department", timeout = 1, fetchSize = 10) }) +@org.hibernate.annotations.NamedNativeQueries({ @org.hibernate.annotations.NamedNativeQuery(name = "DeptEmployee_FindByEmployeeName", query = "select * from deptemployee emp where name=:name", resultClass = DeptEmployee.class), + @org.hibernate.annotations.NamedNativeQuery(name = "DeptEmployee_UpdateEmployeeDesignation", query = "call UPDATE_EMPLOYEE_DESIGNATION(:employeeNumber, :newDesignation)", resultClass = DeptEmployee.class) }) @Entity public class DeptEmployee { @Id @@ -16,7 +26,7 @@ public class DeptEmployee { @ManyToOne private Department department; - + public DeptEmployee(String name, String employeeNumber, Department department) { this.name = name; this.employeeNumber = employeeNumber;