From 48a70669c5a0fcb0cf3e4523be78b4e6435ae564 Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Fri, 6 Apr 2018 11:03:47 +0300 Subject: [PATCH 01/36] style pages --- .../controllers/MyErrorController.java | 22 ++++++++++--------- .../main/resources/templates/error-404.html | 13 ++++++++--- .../main/resources/templates/error-500.html | 15 ++++++++++--- .../src/main/resources/templates/error.html | 13 +++++++++-- .../src/main/resources/templates/index.ftl | 6 ----- 5 files changed, 45 insertions(+), 24 deletions(-) delete mode 100644 spring-boot/src/main/resources/templates/index.ftl diff --git a/spring-boot/src/main/java/com/baeldung/errorhandling/controllers/MyErrorController.java b/spring-boot/src/main/java/com/baeldung/errorhandling/controllers/MyErrorController.java index d0c548e7bb..caa335ed23 100644 --- a/spring-boot/src/main/java/com/baeldung/errorhandling/controllers/MyErrorController.java +++ b/spring-boot/src/main/java/com/baeldung/errorhandling/controllers/MyErrorController.java @@ -15,19 +15,21 @@ public class MyErrorController implements ErrorController { @RequestMapping(value = "/error") public String handleError(HttpServletRequest request) { + + Object status = request.getAttribute(RequestDispatcher.ERROR_STATUS_CODE); - Integer statusCode = - Integer.valueOf(request.getAttribute(RequestDispatcher.ERROR_STATUS_CODE).toString()); + if (status != null) { + + Integer statusCode = Integer.valueOf(status.toString()); - if(statusCode == HttpStatus.NOT_FOUND.value()) { - return "error-404"; - } - else if(statusCode == HttpStatus.INTERNAL_SERVER_ERROR.value()) { - return "error-500"; - } - else { - return "error"; + if(statusCode == HttpStatus.NOT_FOUND.value()) { + return "error-404"; + } + else if(statusCode == HttpStatus.INTERNAL_SERVER_ERROR.value()) { + return "error-500"; + } } + return "error"; } @Override diff --git a/spring-boot/src/main/resources/templates/error-404.html b/spring-boot/src/main/resources/templates/error-404.html index 3d3adaefa6..cf68032596 100644 --- a/spring-boot/src/main/resources/templates/error-404.html +++ b/spring-boot/src/main/resources/templates/error-404.html @@ -1,7 +1,14 @@ + + + + -

Sorry we couldn't find the resource you are looking for

-Go Home +
+
+

Sorry, we couldn't find the page you were looking for.

+

Go Home

+
- + \ No newline at end of file diff --git a/spring-boot/src/main/resources/templates/error-500.html b/spring-boot/src/main/resources/templates/error-500.html index 979dd76764..5ddf458229 100644 --- a/spring-boot/src/main/resources/templates/error-500.html +++ b/spring-boot/src/main/resources/templates/error-500.html @@ -1,7 +1,16 @@ + + + + -

Oops! We spilled something but we're fixing it

-Go Home +
+
+

Sorry, something went wrong!

+ +

We're fixing it.

+

Go Home

+
- + \ No newline at end of file diff --git a/spring-boot/src/main/resources/templates/error.html b/spring-boot/src/main/resources/templates/error.html index 26d1a22b6c..bc517913b2 100644 --- a/spring-boot/src/main/resources/templates/error.html +++ b/spring-boot/src/main/resources/templates/error.html @@ -1,7 +1,16 @@ + + + + -

Something went wrong! Our Engineers are on it temp

-Go Home +
+
+

Something went wrong!

+ +

Our Engineers are on it.

+

Go Home

+
diff --git a/spring-boot/src/main/resources/templates/index.ftl b/spring-boot/src/main/resources/templates/index.ftl deleted file mode 100644 index ce0505006e..0000000000 --- a/spring-boot/src/main/resources/templates/index.ftl +++ /dev/null @@ -1,6 +0,0 @@ - - - -

Welcome Home

- - From b1e230de41f1abb7bd963c5ed9815257c4e3c91b Mon Sep 17 00:00:00 2001 From: Marcos Lopez Gonzalez Date: Tue, 10 Apr 2018 22:16:50 +0200 Subject: [PATCH 02/36] arrayList * shorter tests names --- .../junit4/BeforeAndAfterAnnotationsTest.java | 11 ++++------- .../junit5/BeforeEachAndAfterEachAnnotationsTest.java | 11 ++++------- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/testing-modules/junit-5/src/test/java/com/baeldung/migration/junit4/BeforeAndAfterAnnotationsTest.java b/testing-modules/junit-5/src/test/java/com/baeldung/migration/junit4/BeforeAndAfterAnnotationsTest.java index 305c7a8442..e26b10e7e5 100644 --- a/testing-modules/junit-5/src/test/java/com/baeldung/migration/junit4/BeforeAndAfterAnnotationsTest.java +++ b/testing-modules/junit-5/src/test/java/com/baeldung/migration/junit4/BeforeAndAfterAnnotationsTest.java @@ -3,6 +3,7 @@ package com.baeldung.migration.junit4; import static org.junit.Assert.assertEquals; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import org.junit.After; @@ -23,21 +24,17 @@ public class BeforeAndAfterAnnotationsTest { @Before public void init() { LOG.info("startup"); - - list = new ArrayList<>(); - list.add("test1"); - list.add("test2"); + list = new ArrayList<>(Arrays.asList("test1", "test2")); } @After public void finalize() { LOG.info("finalize"); - list.clear(); } @Test - public void whenCheckingListSizeAtBeginning_ThenSizeEqualsToStartupSize() { + public void whenCheckingListSize_ThenSizeEqualsToInit() { LOG.info("executing test"); assertEquals(2, list.size()); @@ -45,7 +42,7 @@ public class BeforeAndAfterAnnotationsTest { } @Test - public void whenCheckingListSizeAtBeginningAgain_ThenSizeEqualsToStartupSize() { + public void whenCheckingListSizeAgain_ThenSizeEqualsToInit() { LOG.info("executing another test"); assertEquals(2, list.size()); diff --git a/testing-modules/junit-5/src/test/java/com/baeldung/migration/junit5/BeforeEachAndAfterEachAnnotationsTest.java b/testing-modules/junit-5/src/test/java/com/baeldung/migration/junit5/BeforeEachAndAfterEachAnnotationsTest.java index 9785303b48..6302992a5b 100644 --- a/testing-modules/junit-5/src/test/java/com/baeldung/migration/junit5/BeforeEachAndAfterEachAnnotationsTest.java +++ b/testing-modules/junit-5/src/test/java/com/baeldung/migration/junit5/BeforeEachAndAfterEachAnnotationsTest.java @@ -3,6 +3,7 @@ package com.baeldung.migration.junit5; import static org.junit.Assert.assertEquals; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import org.junit.jupiter.api.AfterEach; @@ -23,21 +24,17 @@ public class BeforeEachAndAfterEachAnnotationsTest { @BeforeEach public void init() { LOG.info("startup"); - - list = new ArrayList<>(); - list.add("test1"); - list.add("test2"); + list = new ArrayList<>(Arrays.asList("test1", "test2")); } @AfterEach public void finalize() { LOG.info("finalize"); - list.clear(); } @Test - public void whenCheckingListSizeAtBeginning_ThenSizeEqualsToStartupSize() { + public void whenCheckingListSize_ThenSizeEqualsToInit() { LOG.info("executing test"); assertEquals(2, list.size()); @@ -45,7 +42,7 @@ public class BeforeEachAndAfterEachAnnotationsTest { } @Test - public void whenCheckingListSizeAtBeginningAgain_ThenSizeEqualsToStartupSize() { + public void whenCheckingListSizeAgain_ThenSizeEqualsToInit() { LOG.info("executing another test"); assertEquals(2, list.size()); From 5829bb58f0299cd52870fce9aef19cfe3304870f Mon Sep 17 00:00:00 2001 From: mansi2392 Date: Wed, 11 Apr 2018 20:44:32 +0530 Subject: [PATCH 03/36] BAEL-1557 Refactor --- .../opennlp/LanguageDetectorAndTrainingDataTest.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/apache-opennlp/src/test/java/com/baeldung/apache/opennlp/LanguageDetectorAndTrainingDataTest.java b/apache-opennlp/src/test/java/com/baeldung/apache/opennlp/LanguageDetectorAndTrainingDataTest.java index d9c18862e8..5eb649dae1 100644 --- a/apache-opennlp/src/test/java/com/baeldung/apache/opennlp/LanguageDetectorAndTrainingDataTest.java +++ b/apache-opennlp/src/test/java/com/baeldung/apache/opennlp/LanguageDetectorAndTrainingDataTest.java @@ -16,6 +16,7 @@ import opennlp.tools.util.ObjectStream; import opennlp.tools.util.PlainTextByLineStream; import opennlp.tools.util.TrainingParameters; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.tuple; import org.junit.Test; public class LanguageDetectorAndTrainingDataTest { @@ -35,7 +36,9 @@ public class LanguageDetectorAndTrainingDataTest { LanguageDetector ld = new LanguageDetectorME(model); Language[] languages = ld.predictLanguages("estava em uma marcenaria na Rua Bruno"); - assertThat(Arrays.asList(languages).toString()).contains("pob (0.9999999950605625)", "ita (4.939427661577956E-9)", "spa (9.665954064665144E-15)", - "fra (8.250349924885834E-25)"); + + assertThat(Arrays.asList(languages)).extracting("lang", "confidence").contains(tuple("pob", 0.9999999950605625), + tuple("ita", 4.939427661577956E-9), tuple("spa", 9.665954064665144E-15), + tuple("fra", 8.250349924885834E-25)); } } From f79236b43303170a100d82340adb50cffceda1a3 Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Sat, 14 Apr 2018 18:16:08 +0300 Subject: [PATCH 04/36] fix volatile test --- .../SharedObjectManualTest.java | 51 +++++++------------ 1 file changed, 18 insertions(+), 33 deletions(-) diff --git a/core-java-concurrency/src/test/java/com/baeldung/concurrent/volatilekeyword/SharedObjectManualTest.java b/core-java-concurrency/src/test/java/com/baeldung/concurrent/volatilekeyword/SharedObjectManualTest.java index 8770cb4e90..90615f23b8 100644 --- a/core-java-concurrency/src/test/java/com/baeldung/concurrent/volatilekeyword/SharedObjectManualTest.java +++ b/core-java-concurrency/src/test/java/com/baeldung/concurrent/volatilekeyword/SharedObjectManualTest.java @@ -1,55 +1,37 @@ package com.baeldung.concurrent.volatilekeyword; -import org.junit.After; -import org.junit.Before; import org.junit.Test; -import static junit.framework.Assert.assertEquals; +import static org.junit.Assert.*; public class SharedObjectManualTest { - private SharedObject sharedObject; - private int valueReadByThread2; - private int valueReadByThread3; - - @Before - public void setUp() { - sharedObject = new SharedObject(); - } - @Test public void whenOneThreadWrites_thenVolatileReadsFromMainMemory() throws InterruptedException { + SharedObject sharedObject = new SharedObject(); + Thread writer = new Thread(() -> sharedObject.increamentCount()); writer.start(); - + Thread.sleep(100); + System.out.println(sharedObject.getCount()); Thread readerOne = new Thread(() -> { - try { - Thread.sleep(1000); - } catch (InterruptedException e) { - e.printStackTrace(); - } - valueReadByThread2 = sharedObject.getCount(); + int valueReadByThread2 = sharedObject.getCount(); + assertEquals(1, valueReadByThread2); }); readerOne.start(); Thread readerTwo = new Thread(() -> { - try { - Thread.sleep(1000); - } catch (InterruptedException e) { - e.printStackTrace(); - } - valueReadByThread3 = sharedObject.getCount(); + int valueReadByThread3 = sharedObject.getCount(); + assertEquals(1, valueReadByThread3); }); readerTwo.start(); - assertEquals(1, valueReadByThread2); - assertEquals(1, valueReadByThread3); - } @Test public void whenTwoThreadWrites_thenVolatileReadsFromMainMemory() throws InterruptedException { + SharedObject sharedObject = new SharedObject(); Thread writerOne = new Thread(() -> sharedObject.increamentCount()); writerOne.start(); Thread.sleep(100); @@ -58,14 +40,17 @@ public class SharedObjectManualTest { writerTwo.start(); Thread.sleep(100); - Thread readerOne = new Thread(() -> valueReadByThread2 = sharedObject.getCount()); + Thread readerOne = new Thread(() -> { + int valueReadByThread2 = sharedObject.getCount(); + assertEquals(2, valueReadByThread2); + }); readerOne.start(); - Thread readerTwo = new Thread(() -> valueReadByThread3 = sharedObject.getCount()); + Thread readerTwo = new Thread(() -> { + int valueReadByThread3 = sharedObject.getCount(); + assertEquals(2, valueReadByThread3); + }); readerTwo.start(); - assertEquals(2, valueReadByThread2); - assertEquals(2, valueReadByThread3); - } } From a60f86ddeeeefcd4cf311cfcce8c64f8b028fa31 Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Sat, 14 Apr 2018 18:17:25 +0300 Subject: [PATCH 05/36] remove sysout --- .../concurrent/volatilekeyword/SharedObjectManualTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/core-java-concurrency/src/test/java/com/baeldung/concurrent/volatilekeyword/SharedObjectManualTest.java b/core-java-concurrency/src/test/java/com/baeldung/concurrent/volatilekeyword/SharedObjectManualTest.java index 90615f23b8..731ae887e1 100644 --- a/core-java-concurrency/src/test/java/com/baeldung/concurrent/volatilekeyword/SharedObjectManualTest.java +++ b/core-java-concurrency/src/test/java/com/baeldung/concurrent/volatilekeyword/SharedObjectManualTest.java @@ -13,7 +13,6 @@ public class SharedObjectManualTest { Thread writer = new Thread(() -> sharedObject.increamentCount()); writer.start(); Thread.sleep(100); - System.out.println(sharedObject.getCount()); Thread readerOne = new Thread(() -> { int valueReadByThread2 = sharedObject.getCount(); From a41399d8a1aec1a7475764ee6314b62c936cc74d Mon Sep 17 00:00:00 2001 From: Eric Goebelbecker Date: Sat, 14 Apr 2018 11:50:07 -0400 Subject: [PATCH 06/36] BAEL-1595 - JetS3t (#3994) * BAEL-1595 - JetS3t for S3 storage. * BAEL-1595 - use ArrayList for streams * BAEL-1595 - use ArrayList for streams --- .../com/baeldung/jets3t/JetS3tLiveTest.java | 33 ++++++++++++++----- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/libraries/src/test/java/com/baeldung/jets3t/JetS3tLiveTest.java b/libraries/src/test/java/com/baeldung/jets3t/JetS3tLiveTest.java index 3b0cc9b4c1..cf0b203e10 100644 --- a/libraries/src/test/java/com/baeldung/jets3t/JetS3tLiveTest.java +++ b/libraries/src/test/java/com/baeldung/jets3t/JetS3tLiveTest.java @@ -15,6 +15,7 @@ import org.junit.Test; import java.io.*; import java.nio.file.Files; +import java.util.ArrayList; import java.util.Arrays; import java.util.stream.Collectors; @@ -191,14 +192,25 @@ public class JetS3tLiveTest { S3Bucket bucket = createBucket(); assertNotNull(bucket); - // Create a stream - ByteArrayInputStream testStream = new ByteArrayInputStream("test stream".getBytes()); + ArrayList numbers = new ArrayList<>(); + numbers.add(2); + numbers.add(3); + numbers.add(5); + numbers.add(7); + + // Serialize ArrayList + ByteArrayOutputStream bytes = new ByteArrayOutputStream(); + ObjectOutputStream objectOutputStream = new ObjectOutputStream(bytes); + objectOutputStream.writeObject(numbers); + + // Wrap bytes + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes.toByteArray()); // Create and populate object S3Object streamObject = new S3Object("stream"); - streamObject.setDataInputStream(testStream); - streamObject.setContentLength(testStream.available()); - streamObject.setContentType("text/plain"); + streamObject.setDataInputStream(byteArrayInputStream); + streamObject.setContentLength(byteArrayInputStream.available()); + streamObject.setContentType("binary/octet-stream"); // Put it s3Service.putObject(BucketName, streamObject); @@ -206,11 +218,14 @@ public class JetS3tLiveTest { // Get it S3Object newStreamObject = s3Service.getObject(BucketName, "stream"); - // Convert back to string - String testString = new BufferedReader(new InputStreamReader(newStreamObject.getDataInputStream())) - .lines().collect(Collectors.joining("\n")); + // Convert back to ArrayList + ObjectInputStream objectInputStream = new ObjectInputStream(newStreamObject.getDataInputStream()); + ArrayList newNumbers = (ArrayList)objectInputStream.readObject(); - assertTrue("test stream".equals(testString)); + assertEquals(2, (int)newNumbers.get(0)); + assertEquals(3, (int)newNumbers.get(1)); + assertEquals(5, (int)newNumbers.get(2)); + assertEquals(7, (int)newNumbers.get(3)); // Clean up deleteObject("stream"); From d6d44c7cb93eb1dd0e5034d3a20c41980d24c500 Mon Sep 17 00:00:00 2001 From: Mher Baghinyan Date: Sat, 14 Apr 2018 22:33:34 +0400 Subject: [PATCH 07/36] Bael 1603 (#3984) * apache ignite module added * Ignite more extended * apache ignite full code * employee json * apache ignite * reformatting the loop * move apache ignite code snippets into libraries-data --- libraries-data/pom.xml | 22 +++++++ .../ignite/cache/CustomLifecycleBean.java | 14 +++++ .../ignite/cache/IgniteCacheExample.java | 58 +++++++++++++++++++ .../com/baeldung/ignite/jdbc/IgniteJDBC.java | 58 +++++++++++++++++++ .../com/baeldung/ignite/model/Employee.java | 48 +++++++++++++++ .../baeldung/ignite/stream/CacheConfig.java | 24 ++++++++ .../baeldung/ignite/stream/IgniteStream.java | 44 ++++++++++++++ .../src/main/resources/employee.txt | 3 + 8 files changed, 271 insertions(+) create mode 100644 libraries-data/src/main/java/com/baeldung/ignite/cache/CustomLifecycleBean.java create mode 100644 libraries-data/src/main/java/com/baeldung/ignite/cache/IgniteCacheExample.java create mode 100644 libraries-data/src/main/java/com/baeldung/ignite/jdbc/IgniteJDBC.java create mode 100644 libraries-data/src/main/java/com/baeldung/ignite/model/Employee.java create mode 100644 libraries-data/src/main/java/com/baeldung/ignite/stream/CacheConfig.java create mode 100644 libraries-data/src/main/java/com/baeldung/ignite/stream/IgniteStream.java create mode 100644 libraries-data/src/main/resources/employee.txt diff --git a/libraries-data/pom.xml b/libraries-data/pom.xml index 4727ca2222..55bf02ae16 100644 --- a/libraries-data/pom.xml +++ b/libraries-data/pom.xml @@ -65,6 +65,26 @@ test test + + org.apache.ignite + ignite-core + ${ignite.version} + + + org.apache.ignite + ignite-spring + ${ignite.version} + + + org.apache.ignite + ignite-indexing + ${ignite.version} + + + com.google.code.gson + gson + ${gson.version} + @@ -181,5 +201,7 @@ 3.7.0 5.0 1.0.0 + 2.3.0 + 2.8.2 \ No newline at end of file diff --git a/libraries-data/src/main/java/com/baeldung/ignite/cache/CustomLifecycleBean.java b/libraries-data/src/main/java/com/baeldung/ignite/cache/CustomLifecycleBean.java new file mode 100644 index 0000000000..0b603dcee0 --- /dev/null +++ b/libraries-data/src/main/java/com/baeldung/ignite/cache/CustomLifecycleBean.java @@ -0,0 +1,14 @@ +package com.baeldung.ignite.cache; + +import org.apache.ignite.IgniteException; +import org.apache.ignite.lifecycle.LifecycleBean; +import org.apache.ignite.lifecycle.LifecycleEventType; + +public class CustomLifecycleBean implements LifecycleBean { + @Override + public void onLifecycleEvent(LifecycleEventType lifecycleEventType) throws IgniteException { + if (lifecycleEventType == LifecycleEventType.AFTER_NODE_START) { + //do something right after the Ignite node starts + } + } +} diff --git a/libraries-data/src/main/java/com/baeldung/ignite/cache/IgniteCacheExample.java b/libraries-data/src/main/java/com/baeldung/ignite/cache/IgniteCacheExample.java new file mode 100644 index 0000000000..8c40b8f312 --- /dev/null +++ b/libraries-data/src/main/java/com/baeldung/ignite/cache/IgniteCacheExample.java @@ -0,0 +1,58 @@ +package com.baeldung.ignite.cache; + +import com.baeldung.ignite.model.Employee; +import org.apache.ignite.Ignite; +import org.apache.ignite.IgniteCache; +import org.apache.ignite.Ignition; +import org.apache.ignite.cache.query.QueryCursor; +import org.apache.ignite.cache.query.SqlFieldsQuery; +import org.apache.ignite.configuration.IgniteConfiguration; + +import java.util.List; + +public class IgniteCacheExample { + + public static void main(String[] args) { + + Ignite ignite = Ignition.ignite(); + + IgniteCache cache = ignite.cache("baeldungCache"); + + cache.put(1, "baeldung cache value"); + + String message = cache.get(1); + } + + private static void getObjectFromCache(Ignite ignite) { + + IgniteCache cache = ignite.getOrCreateCache("baeldungCache"); + + cache.put(1, new Employee(1, "John", true)); + cache.put(2, new Employee(2, "Anna", false)); + cache.put(3, new Employee(3, "George", true)); + + Employee employee = cache.get(1); + } + + private static void getFromCacheWithSQl(Ignite ignite) { + + IgniteCache cache = ignite.cache("baeldungCache"); + + SqlFieldsQuery sql = new SqlFieldsQuery( + "select name from Employee where isEmployed = 'true'"); + + QueryCursor> cursor = cache.query(sql); + + for (List row : cursor) { + System.out.println(row.get(0)); + } + } + + private static void customInitialization() { + + IgniteConfiguration configuration = new IgniteConfiguration(); + configuration.setLifecycleBeans(new CustomLifecycleBean()); + Ignite ignite = Ignition.start(configuration); + } + +} diff --git a/libraries-data/src/main/java/com/baeldung/ignite/jdbc/IgniteJDBC.java b/libraries-data/src/main/java/com/baeldung/ignite/jdbc/IgniteJDBC.java new file mode 100644 index 0000000000..de144711b3 --- /dev/null +++ b/libraries-data/src/main/java/com/baeldung/ignite/jdbc/IgniteJDBC.java @@ -0,0 +1,58 @@ +package com.baeldung.ignite.jdbc; + +import java.sql.*; + +/** + * Created by Gebruiker on 3/14/2018. + */ +public class IgniteJDBC { + + public static void main(String[] args) throws ClassNotFoundException, SQLException { + + Class.forName("org.apache.ignite.IgniteJdbcThinDriver"); + + Connection conn = DriverManager.getConnection("jdbc:ignite:thin://127.0.0.1/"); + + createDatabaseTables(conn); + + insertData(conn); + + getData(conn); + } + + private static void createDatabaseTables(Connection conn) throws SQLException { + + Statement sql = conn.createStatement(); + sql.executeUpdate("CREATE TABLE Employee (" + + " id INTEGER PRIMARY KEY, name VARCHAR, isEmployed timyint(1)) " + + " WITH \"template=replicated\""); + + sql.executeUpdate("CREATE INDEX idx_employee_name ON Employee (name)"); + } + + private static void insertData(Connection conn) throws SQLException { + + PreparedStatement sql = + conn.prepareStatement("INSERT INTO Employee (id, name, isEmployed) VALUES (?, ?, ?)"); + sql.setLong(1, 1); + sql.setString(2, "James"); + sql.setBoolean(3, true); + sql.executeUpdate(); + + sql.setLong(1, 2); + sql.setString(2, "Monica"); + sql.setBoolean(3, false); + sql.executeUpdate(); + } + + private static void getData(Connection conn) throws SQLException { + + Statement sql = conn.createStatement(); + ResultSet rs = sql.executeQuery("SELECT e.name, e.isEmployed " + + " FROM Employee e " + + " WHERE e.isEmployed = TRUE "); + + while (rs.next()) + System.out.println(rs.getString(1) + ", " + rs.getString(2)); + } +} diff --git a/libraries-data/src/main/java/com/baeldung/ignite/model/Employee.java b/libraries-data/src/main/java/com/baeldung/ignite/model/Employee.java new file mode 100644 index 0000000000..21f5ef89d0 --- /dev/null +++ b/libraries-data/src/main/java/com/baeldung/ignite/model/Employee.java @@ -0,0 +1,48 @@ +package com.baeldung.ignite.model; + + +public class Employee { + + private Integer id; + private String name; + private boolean isEmployed; + + public Employee(Integer id, String name, boolean isEmployed) { + this.id = id; + this.name = name; + this.isEmployed = isEmployed; + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public boolean isEmployed() { + return isEmployed; + } + + public void setEmployed(boolean employed) { + isEmployed = employed; + } + + @Override + public String toString() { + return "Employee{" + + "id=" + id + + ", name='" + name + '\'' + + ", isEmployed=" + isEmployed + + '}'; + } +} diff --git a/libraries-data/src/main/java/com/baeldung/ignite/stream/CacheConfig.java b/libraries-data/src/main/java/com/baeldung/ignite/stream/CacheConfig.java new file mode 100644 index 0000000000..2b0f71e0b9 --- /dev/null +++ b/libraries-data/src/main/java/com/baeldung/ignite/stream/CacheConfig.java @@ -0,0 +1,24 @@ +package com.baeldung.ignite.stream; + +import com.baeldung.ignite.model.Employee; +import org.apache.ignite.configuration.CacheConfiguration; + +import javax.cache.configuration.FactoryBuilder; +import javax.cache.expiry.CreatedExpiryPolicy; +import javax.cache.expiry.Duration; +import java.util.concurrent.TimeUnit; + + +public class CacheConfig { + + public static CacheConfiguration employeeCache() { + + CacheConfiguration config = new CacheConfiguration<>("baeldungEmployees"); + + config.setIndexedTypes(Integer.class, Employee.class); + config.setExpiryPolicyFactory(FactoryBuilder.factoryOf( + new CreatedExpiryPolicy(new Duration(TimeUnit.SECONDS, 5)))); + + return config; + } +} \ No newline at end of file diff --git a/libraries-data/src/main/java/com/baeldung/ignite/stream/IgniteStream.java b/libraries-data/src/main/java/com/baeldung/ignite/stream/IgniteStream.java new file mode 100644 index 0000000000..839da36c22 --- /dev/null +++ b/libraries-data/src/main/java/com/baeldung/ignite/stream/IgniteStream.java @@ -0,0 +1,44 @@ +package com.baeldung.ignite.stream; + +import com.baeldung.ignite.model.Employee; +import com.google.gson.Gson; +import org.apache.ignite.Ignite; +import org.apache.ignite.IgniteCache; +import org.apache.ignite.IgniteDataStreamer; +import org.apache.ignite.Ignition; +import org.apache.ignite.stream.StreamTransformer; + +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; + +public class IgniteStream { + + public static void main(String[] args) throws Exception { + + Ignition.setClientMode(true); + Ignite ignite = Ignition.start(); + + IgniteCache cache = ignite.getOrCreateCache(CacheConfig.employeeCache()); + IgniteDataStreamer streamer = ignite.dataStreamer(cache.getName()); + streamer.allowOverwrite(true); + + streamer.receiver(StreamTransformer.from((e, arg) -> { + + Employee employee = e.getValue(); + employee.setEmployed(true); + e.setValue(employee); + + return null; + })); + + Path path = Paths.get(IgniteStream.class.getResource("employees.txt").toURI()); + + Files.lines(path) + .forEach(line -> { + Employee employee = new Gson().fromJson(line, Employee.class); + streamer.addData(employee.getId(), employee); + }); + + } +} diff --git a/libraries-data/src/main/resources/employee.txt b/libraries-data/src/main/resources/employee.txt new file mode 100644 index 0000000000..6c476f39fa --- /dev/null +++ b/libraries-data/src/main/resources/employee.txt @@ -0,0 +1,3 @@ +{id:"1", name="John", isEmployed: "true"} +{id:"1", name="Anna", isEmployed: "false"} +{id:"1", name="George", isEmployed: "true"} \ No newline at end of file From 43d51a406b48ee44e78eba5d745e159294b76df0 Mon Sep 17 00:00:00 2001 From: Krzysiek Przygudzki Date: Sat, 14 Apr 2018 21:40:06 +0200 Subject: [PATCH 08/36] [BAEL-4453] Upgrade Katharsis to 3.0.2 and fix imports (#3910) --- spring-katharsis/pom.xml | 22 +++++++++++++------ .../main/java/org/baeldung/Application.java | 3 +-- .../persistence/katharsis/JsonApiFilter.java | 6 ++--- .../katharsis/RoleResourceRepository.java | 7 +++--- .../katharsis/UserResourceRepository.java | 4 ++-- .../UserToRoleRelationshipRepository.java | 4 ++-- 6 files changed, 26 insertions(+), 20 deletions(-) diff --git a/spring-katharsis/pom.xml b/spring-katharsis/pom.xml index 49c0a5acf9..00552c6d5b 100644 --- a/spring-katharsis/pom.xml +++ b/spring-katharsis/pom.xml @@ -35,21 +35,25 @@ io.katharsis katharsis-servlet ${katharsis.version} + + + org.apache.commons + commons-lang3 + + org.reflections reflections 0.9.10 + + org.apache.commons + commons-lang3 + 3.7 + - - - 2.1.3 - 1.6.1 - - - @@ -128,5 +132,9 @@ + + 3.0.2 + 1.6.1 + diff --git a/spring-katharsis/src/main/java/org/baeldung/Application.java b/spring-katharsis/src/main/java/org/baeldung/Application.java index b61151d87f..ee072305d8 100644 --- a/spring-katharsis/src/main/java/org/baeldung/Application.java +++ b/spring-katharsis/src/main/java/org/baeldung/Application.java @@ -9,7 +9,6 @@ public class Application extends SpringBootServletInitializer { public static void main(String[] args) { SpringApplication.run(Application.class, args); - } -} \ No newline at end of file +} diff --git a/spring-katharsis/src/main/java/org/baeldung/persistence/katharsis/JsonApiFilter.java b/spring-katharsis/src/main/java/org/baeldung/persistence/katharsis/JsonApiFilter.java index dc07841fe6..3d0d441357 100644 --- a/spring-katharsis/src/main/java/org/baeldung/persistence/katharsis/JsonApiFilter.java +++ b/spring-katharsis/src/main/java/org/baeldung/persistence/katharsis/JsonApiFilter.java @@ -1,8 +1,8 @@ package org.baeldung.persistence.katharsis; -import io.katharsis.invoker.KatharsisInvokerBuilder; -import io.katharsis.locator.JsonServiceLocator; -import io.katharsis.servlet.AbstractKatharsisFilter; +import io.katharsis.invoker.internal.legacy.KatharsisInvokerBuilder; +import io.katharsis.legacy.locator.JsonServiceLocator; +import io.katharsis.servlet.legacy.AbstractKatharsisFilter; import org.springframework.beans.BeansException; import org.springframework.beans.factory.BeanFactory; diff --git a/spring-katharsis/src/main/java/org/baeldung/persistence/katharsis/RoleResourceRepository.java b/spring-katharsis/src/main/java/org/baeldung/persistence/katharsis/RoleResourceRepository.java index 101e4c2b7e..52ca40e26e 100644 --- a/spring-katharsis/src/main/java/org/baeldung/persistence/katharsis/RoleResourceRepository.java +++ b/spring-katharsis/src/main/java/org/baeldung/persistence/katharsis/RoleResourceRepository.java @@ -1,7 +1,7 @@ package org.baeldung.persistence.katharsis; -import io.katharsis.queryParams.QueryParams; -import io.katharsis.repository.ResourceRepository; +import io.katharsis.legacy.queryParams.QueryParams; +import io.katharsis.legacy.repository.ResourceRepository; import org.baeldung.persistence.dao.RoleRepository; import org.baeldung.persistence.model.Role; @@ -11,8 +11,7 @@ import org.springframework.stereotype.Component; @Component public class RoleResourceRepository implements ResourceRepository { - @Autowired - private RoleRepository roleRepository; + @Autowired private RoleRepository roleRepository; @Override public Role findOne(Long id, QueryParams params) { diff --git a/spring-katharsis/src/main/java/org/baeldung/persistence/katharsis/UserResourceRepository.java b/spring-katharsis/src/main/java/org/baeldung/persistence/katharsis/UserResourceRepository.java index b6d519ab80..a36c3c3c0a 100644 --- a/spring-katharsis/src/main/java/org/baeldung/persistence/katharsis/UserResourceRepository.java +++ b/spring-katharsis/src/main/java/org/baeldung/persistence/katharsis/UserResourceRepository.java @@ -1,7 +1,7 @@ package org.baeldung.persistence.katharsis; -import io.katharsis.queryParams.QueryParams; -import io.katharsis.repository.ResourceRepository; +import io.katharsis.legacy.queryParams.QueryParams; +import io.katharsis.legacy.repository.ResourceRepository; import org.baeldung.persistence.dao.UserRepository; import org.baeldung.persistence.model.User; diff --git a/spring-katharsis/src/main/java/org/baeldung/persistence/katharsis/UserToRoleRelationshipRepository.java b/spring-katharsis/src/main/java/org/baeldung/persistence/katharsis/UserToRoleRelationshipRepository.java index 168cd1c866..19007a285f 100644 --- a/spring-katharsis/src/main/java/org/baeldung/persistence/katharsis/UserToRoleRelationshipRepository.java +++ b/spring-katharsis/src/main/java/org/baeldung/persistence/katharsis/UserToRoleRelationshipRepository.java @@ -1,7 +1,7 @@ package org.baeldung.persistence.katharsis; -import io.katharsis.queryParams.QueryParams; -import io.katharsis.repository.RelationshipRepository; +import io.katharsis.legacy.queryParams.QueryParams; +import io.katharsis.legacy.repository.RelationshipRepository; import java.util.HashSet; import java.util.Set; From cb723bbfaf6dd8e73df85466090c69a899ffa9a2 Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Sat, 14 Apr 2018 23:22:11 +0300 Subject: [PATCH 09/36] Update README.md --- javafx/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/javafx/README.md b/javafx/README.md index 483c556ca7..5ec5c77f2f 100644 --- a/javafx/README.md +++ b/javafx/README.md @@ -1,3 +1,3 @@ ### Relevant Articles: -- +-Introduction to JavaFX [http://www.baeldung.com/javafx] From 03d58c3848a6c0db165273e43a3e6a1873b4ea72 Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Sat, 14 Apr 2018 23:23:10 +0300 Subject: [PATCH 10/36] Update README.md --- javafx/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/javafx/README.md b/javafx/README.md index 5ec5c77f2f..66c81f17ad 100644 --- a/javafx/README.md +++ b/javafx/README.md @@ -1,3 +1,3 @@ ### Relevant Articles: --Introduction to JavaFX [http://www.baeldung.com/javafx] +-[Introduction to JavaFX](http://www.baeldung.com/javafx) From f243517852ce478107fc75df75476e2afc22dc44 Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Sat, 14 Apr 2018 23:24:42 +0300 Subject: [PATCH 11/36] Update README.md --- testing-modules/junit-5/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/testing-modules/junit-5/README.md b/testing-modules/junit-5/README.md index ed429de489..03c55b461d 100644 --- a/testing-modules/junit-5/README.md +++ b/testing-modules/junit-5/README.md @@ -9,3 +9,4 @@ - [Mockito and JUnit 5 – Using ExtendWith](http://www.baeldung.com/mockito-junit-5-extension) - [JUnit 5 – @RunWith](http://www.baeldung.com/junit-5-runwith) - [JUnit 5 @Test Annotation](http://www.baeldung.com/junit-5-test-annotation) +- [JUnit Assert an Exception is Thrown](http://www.baeldung.com/junit-assert-exception) From 84c857d114be9870e8d268398c911cd0922ce284 Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Sat, 14 Apr 2018 23:26:36 +0300 Subject: [PATCH 12/36] Update README.MD --- spring-boot/README.MD | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-boot/README.MD b/spring-boot/README.MD index e78756cf08..c663274c9f 100644 --- a/spring-boot/README.MD +++ b/spring-boot/README.MD @@ -32,3 +32,4 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [Spring Data Java 8 Support](http://www.baeldung.com/spring-data-java-8) - [A Quick Guide to Maven Wrapper](http://www.baeldung.com/maven-wrapper) - [An Introduction to Kong](http://www.baeldung.com/kong) +- [Spring Boot Customize Whitelabel Error Page](http://www.baeldung.com/spring-boot-custom-error-page) From 78912c3d3b676fa842e7ef5ff833ceb57e6ef65d Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Sun, 15 Apr 2018 09:21:07 +0300 Subject: [PATCH 13/36] replace hsql with h2 --- core-java/pom.xml | 7 +++---- .../src/main/java/com/baeldung/jdbc/BatchProcessing.java | 4 ++-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/core-java/pom.xml b/core-java/pom.xml index 11458f4f60..b7760dc250 100644 --- a/core-java/pom.xml +++ b/core-java/pom.xml @@ -231,10 +231,9 @@ 1.5.8.RELEASE - org.hsqldb - hsqldb - 2.4.0 - runtime + com.h2database + h2 + 1.4.197 diff --git a/core-java/src/main/java/com/baeldung/jdbc/BatchProcessing.java b/core-java/src/main/java/com/baeldung/jdbc/BatchProcessing.java index d5c53c3ffc..1242eb3628 100644 --- a/core-java/src/main/java/com/baeldung/jdbc/BatchProcessing.java +++ b/core-java/src/main/java/com/baeldung/jdbc/BatchProcessing.java @@ -13,8 +13,8 @@ public class BatchProcessing { public void getConnection(){ try { - Class.forName("org.hsqldb.jdbcDriver"); - connection = DriverManager.getConnection("jdbc:hsqldb:file:C:\\EMPLOYEEDB", "SA", ""); + Class.forName("org.h2.Driver"); + connection = DriverManager.getConnection("jdbc:h2:file:C:\\EMPLOYEEDB", "SA", ""); connection.setAutoCommit(false); } catch (Exception e) { e.printStackTrace(System.out); From f8e6940155bda9afc866f18ce8366625f3253fc5 Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Sun, 15 Apr 2018 09:35:00 +0300 Subject: [PATCH 14/36] add in mem db --- core-java/src/main/java/com/baeldung/jdbc/BatchProcessing.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-java/src/main/java/com/baeldung/jdbc/BatchProcessing.java b/core-java/src/main/java/com/baeldung/jdbc/BatchProcessing.java index 1242eb3628..ad6a064c98 100644 --- a/core-java/src/main/java/com/baeldung/jdbc/BatchProcessing.java +++ b/core-java/src/main/java/com/baeldung/jdbc/BatchProcessing.java @@ -14,7 +14,7 @@ public class BatchProcessing { public void getConnection(){ try { Class.forName("org.h2.Driver"); - connection = DriverManager.getConnection("jdbc:h2:file:C:\\EMPLOYEEDB", "SA", ""); + connection = DriverManager.getConnection("jdbc:h2:mem:db", "SA", ""); connection.setAutoCommit(false); } catch (Exception e) { e.printStackTrace(System.out); From 90e6ec20e78b2067fd78a7f80d5a1fa5d3d2b9df Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Sun, 15 Apr 2018 10:11:45 +0300 Subject: [PATCH 15/36] add txt files --- core-java/.gitignore | 1 - core-java/src/main/resources/file.txt | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 core-java/src/main/resources/file.txt diff --git a/core-java/.gitignore b/core-java/.gitignore index 3de4cc647e..374c8bf907 100644 --- a/core-java/.gitignore +++ b/core-java/.gitignore @@ -16,7 +16,6 @@ *.ear # Files generated by integration tests -*.txt backup-pom.xml /bin/ /temp diff --git a/core-java/src/main/resources/file.txt b/core-java/src/main/resources/file.txt new file mode 100644 index 0000000000..558d8bbf35 --- /dev/null +++ b/core-java/src/main/resources/file.txt @@ -0,0 +1 @@ +baeldung.com \ No newline at end of file From cd5c1cd642995a14a4661fd1b041b1c22dc314de Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Sun, 15 Apr 2018 10:35:50 +0300 Subject: [PATCH 16/36] Update README.MD --- spring-boot/README.MD | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-boot/README.MD b/spring-boot/README.MD index c663274c9f..028fde5056 100644 --- a/spring-boot/README.MD +++ b/spring-boot/README.MD @@ -33,3 +33,4 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [A Quick Guide to Maven Wrapper](http://www.baeldung.com/maven-wrapper) - [An Introduction to Kong](http://www.baeldung.com/kong) - [Spring Boot Customize Whitelabel Error Page](http://www.baeldung.com/spring-boot-custom-error-page) + From 69886ac326d9e4a7e6a080cd7e22b17e670b03ae Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Sun, 15 Apr 2018 10:36:06 +0300 Subject: [PATCH 17/36] Update README.md --- testing-modules/junit-5/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/testing-modules/junit-5/README.md b/testing-modules/junit-5/README.md index 03c55b461d..441faf2766 100644 --- a/testing-modules/junit-5/README.md +++ b/testing-modules/junit-5/README.md @@ -10,3 +10,4 @@ - [JUnit 5 – @RunWith](http://www.baeldung.com/junit-5-runwith) - [JUnit 5 @Test Annotation](http://www.baeldung.com/junit-5-test-annotation) - [JUnit Assert an Exception is Thrown](http://www.baeldung.com/junit-assert-exception) + From d10437c7aba5ec8f0512cee89799520222f57fea Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Sun, 15 Apr 2018 14:19:50 +0300 Subject: [PATCH 18/36] ignore clear properties test --- .../src/test/java/com/baeldung/system/SystemPropertiesTest.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core-java/src/test/java/com/baeldung/system/SystemPropertiesTest.java b/core-java/src/test/java/com/baeldung/system/SystemPropertiesTest.java index bbae75091a..4fca27f96c 100644 --- a/core-java/src/test/java/com/baeldung/system/SystemPropertiesTest.java +++ b/core-java/src/test/java/com/baeldung/system/SystemPropertiesTest.java @@ -1,6 +1,7 @@ package com.baeldung.system; import org.junit.Assert; +import org.junit.Ignore; import org.junit.Test; import java.util.Properties; @@ -44,6 +45,7 @@ public class SystemPropertiesTest { } @Test + @Ignore public void givenSystem_whenCalledClearProperties_thenDeleteAllPropertiesasResult() { // Clears all system properties. Use with care! From fb4c450a2f35899e3112c16b5f3eac017f396d08 Mon Sep 17 00:00:00 2001 From: pauljervis Date: Sun, 15 Apr 2018 18:22:42 +0100 Subject: [PATCH 19/36] Bael 1601 redirects (#4006) * tidy pom move classes to javax-servlets * move into spring-mvc-simple * updated POM to handle no default tests in module --- javax-servlets/pom.xml | 9 ++++--- spring-boot-bootstrap/pom.xml | 1 - spring-mvc-simple/pom.xml | 24 ++++++++++++------- .../spring/servlets}/ForwardedServlet.java | 2 +- .../spring/servlets}/HelloServlet.java | 2 +- .../spring/servlets}/RedirectedServlet.java | 2 +- .../spring/servlets}/WelcomeServlet.java | 3 +-- .../spring/servlets}/HelloServletTest.java | 11 ++++----- .../spring/servlets}/WelcomeServletTest.java | 7 +++--- 9 files changed, 34 insertions(+), 27 deletions(-) rename {spring-boot-bootstrap/src/main/java/org/baeldung => spring-mvc-simple/src/main/java/com/baeldung/spring/servlets}/ForwardedServlet.java (94%) rename {spring-boot-bootstrap/src/main/java/org/baeldung => spring-mvc-simple/src/main/java/com/baeldung/spring/servlets}/HelloServlet.java (94%) rename {spring-boot-bootstrap/src/main/java/org/baeldung => spring-mvc-simple/src/main/java/com/baeldung/spring/servlets}/RedirectedServlet.java (94%) rename {spring-boot-bootstrap/src/main/java/org/baeldung => spring-mvc-simple/src/main/java/com/baeldung/spring/servlets}/WelcomeServlet.java (93%) rename {spring-boot-bootstrap/src/test/java/org/baeldung => spring-mvc-simple/src/test/java/com/baeldung/spring/servlets}/HelloServletTest.java (84%) rename {spring-boot-bootstrap/src/test/java/org/baeldung => spring-mvc-simple/src/test/java/com/baeldung/spring/servlets}/WelcomeServletTest.java (85%) diff --git a/javax-servlets/pom.xml b/javax-servlets/pom.xml index 7407666309..a75af414cd 100644 --- a/javax-servlets/pom.xml +++ b/javax-servlets/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 - com.baeldung javax-servlets 1.0-SNAPSHOT @@ -13,8 +12,6 @@ 1.0.0-SNAPSHOT - - @@ -35,6 +32,12 @@ + + org.springframework + spring-test + 5.0.5.RELEASE + test + diff --git a/spring-boot-bootstrap/pom.xml b/spring-boot-bootstrap/pom.xml index eb97d6d426..ad2512846b 100644 --- a/spring-boot-bootstrap/pom.xml +++ b/spring-boot-bootstrap/pom.xml @@ -5,7 +5,6 @@ org.baeldung spring-boot-bootstrap - 0.0.1-SNAPSHOT jar spring-boot-bootstrap diff --git a/spring-mvc-simple/pom.xml b/spring-mvc-simple/pom.xml index 10d267aeb5..4e7f39bad3 100644 --- a/spring-mvc-simple/pom.xml +++ b/spring-mvc-simple/pom.xml @@ -1,17 +1,17 @@ - 4.0.0 - com.baeldung spring-mvc-simple war 0.0.1-SNAPSHOT Spring MVC simple Maven Webapp http://maven.apache.org - - com.baeldung - parent-modules - 1.0.0-SNAPSHOT - + + com.baeldung + parent-modules + 1.0.0-SNAPSHOT + 1.8 1.8 @@ -19,7 +19,7 @@ 5.0.2.RELEASE 3.2.0 3.7.0 - 2.20 + 2.21.0 1.2 2.3.2-b02 4.0.0 @@ -172,6 +172,14 @@ maven-surefire-plugin ${maven-surefire-plugin.version} + + + default-test + + true + + + org.junit.platform diff --git a/spring-boot-bootstrap/src/main/java/org/baeldung/ForwardedServlet.java b/spring-mvc-simple/src/main/java/com/baeldung/spring/servlets/ForwardedServlet.java similarity index 94% rename from spring-boot-bootstrap/src/main/java/org/baeldung/ForwardedServlet.java rename to spring-mvc-simple/src/main/java/com/baeldung/spring/servlets/ForwardedServlet.java index e42da22852..222ed16c17 100644 --- a/spring-boot-bootstrap/src/main/java/org/baeldung/ForwardedServlet.java +++ b/spring-mvc-simple/src/main/java/com/baeldung/spring/servlets/ForwardedServlet.java @@ -1,4 +1,4 @@ -package org.baeldung; +package com.baeldung.spring.servlets; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; diff --git a/spring-boot-bootstrap/src/main/java/org/baeldung/HelloServlet.java b/spring-mvc-simple/src/main/java/com/baeldung/spring/servlets/HelloServlet.java similarity index 94% rename from spring-boot-bootstrap/src/main/java/org/baeldung/HelloServlet.java rename to spring-mvc-simple/src/main/java/com/baeldung/spring/servlets/HelloServlet.java index 63673143d6..89bfca795f 100644 --- a/spring-boot-bootstrap/src/main/java/org/baeldung/HelloServlet.java +++ b/spring-mvc-simple/src/main/java/com/baeldung/spring/servlets/HelloServlet.java @@ -1,4 +1,4 @@ -package org.baeldung; +package com.baeldung.spring.servlets; import javax.servlet.RequestDispatcher; import javax.servlet.ServletException; diff --git a/spring-boot-bootstrap/src/main/java/org/baeldung/RedirectedServlet.java b/spring-mvc-simple/src/main/java/com/baeldung/spring/servlets/RedirectedServlet.java similarity index 94% rename from spring-boot-bootstrap/src/main/java/org/baeldung/RedirectedServlet.java rename to spring-mvc-simple/src/main/java/com/baeldung/spring/servlets/RedirectedServlet.java index 6d4b1ebce9..3074eec018 100644 --- a/spring-boot-bootstrap/src/main/java/org/baeldung/RedirectedServlet.java +++ b/spring-mvc-simple/src/main/java/com/baeldung/spring/servlets/RedirectedServlet.java @@ -1,4 +1,4 @@ -package org.baeldung; +package com.baeldung.spring.servlets; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; diff --git a/spring-boot-bootstrap/src/main/java/org/baeldung/WelcomeServlet.java b/spring-mvc-simple/src/main/java/com/baeldung/spring/servlets/WelcomeServlet.java similarity index 93% rename from spring-boot-bootstrap/src/main/java/org/baeldung/WelcomeServlet.java rename to spring-mvc-simple/src/main/java/com/baeldung/spring/servlets/WelcomeServlet.java index b4a51fc4dc..6f9ee8e7c4 100644 --- a/spring-boot-bootstrap/src/main/java/org/baeldung/WelcomeServlet.java +++ b/spring-mvc-simple/src/main/java/com/baeldung/spring/servlets/WelcomeServlet.java @@ -1,5 +1,4 @@ -package org.baeldung; - +package com.baeldung.spring.servlets; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; diff --git a/spring-boot-bootstrap/src/test/java/org/baeldung/HelloServletTest.java b/spring-mvc-simple/src/test/java/com/baeldung/spring/servlets/HelloServletTest.java similarity index 84% rename from spring-boot-bootstrap/src/test/java/org/baeldung/HelloServletTest.java rename to spring-mvc-simple/src/test/java/com/baeldung/spring/servlets/HelloServletTest.java index 93e52cf0be..e8dd8f1b73 100644 --- a/spring-boot-bootstrap/src/test/java/org/baeldung/HelloServletTest.java +++ b/spring-mvc-simple/src/test/java/com/baeldung/spring/servlets/HelloServletTest.java @@ -1,13 +1,12 @@ -package org.baeldung; +package com.baeldung.spring.servlets; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.mock.web.MockHttpServletResponse; - import javax.servlet.ServletException; import java.io.IOException; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public class HelloServletTest { @Test @@ -16,9 +15,9 @@ public class HelloServletTest { request.addParameter("name", "Dennis"); MockHttpServletResponse response = new MockHttpServletResponse(); HelloServlet servlet = new HelloServlet(); - + servlet.doGet(request, response); - + assertEquals("/forwarded", response.getForwardedUrl()); assertEquals(200, response.getStatus()); } diff --git a/spring-boot-bootstrap/src/test/java/org/baeldung/WelcomeServletTest.java b/spring-mvc-simple/src/test/java/com/baeldung/spring/servlets/WelcomeServletTest.java similarity index 85% rename from spring-boot-bootstrap/src/test/java/org/baeldung/WelcomeServletTest.java rename to spring-mvc-simple/src/test/java/com/baeldung/spring/servlets/WelcomeServletTest.java index a52b2a5c01..9ec177a452 100644 --- a/spring-boot-bootstrap/src/test/java/org/baeldung/WelcomeServletTest.java +++ b/spring-mvc-simple/src/test/java/com/baeldung/spring/servlets/WelcomeServletTest.java @@ -1,13 +1,12 @@ -package org.baeldung; +package com.baeldung.spring.servlets; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.mock.web.MockHttpServletResponse; - import javax.servlet.ServletException; import java.io.IOException; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public class WelcomeServletTest { @Test From 9adb3e359be0d329adb0a2802a9a891c00eb8f94 Mon Sep 17 00:00:00 2001 From: Eric Goebelbecker Date: Sun, 15 Apr 2018 14:19:35 -0400 Subject: [PATCH 20/36] BAEL-1595 - Using jets3t as a client for Amazon S3 (#4018) * BAEL-1595 - Using jets3t as a client for Amazon S3 * BAEL-1595 - Using jets3t as a client for Amazon S3. Missed jar versions. --- aws/pom.xml | 15 + .../com/baeldung/jets3t/JetS3tLiveTest.java | 351 ++++++++++++++++++ 2 files changed, 366 insertions(+) create mode 100644 aws/src/test/java/com/baeldung/jets3t/JetS3tLiveTest.java diff --git a/aws/pom.xml b/aws/pom.xml index c62b1b9913..34870bb736 100644 --- a/aws/pom.xml +++ b/aws/pom.xml @@ -24,6 +24,8 @@ 3.8.0 1.11.86 https://s3-us-west-2.amazonaws.com/dynamodb-local/release + 1.10.L001 + 0.9.4.0006L @@ -97,6 +99,19 @@ ${dynamodblocal.version} test + + + + org.lucee + jets3t + ${jets3t-version} + + + org.lucee + commons-codec + ${commons-codec-version} + + diff --git a/aws/src/test/java/com/baeldung/jets3t/JetS3tLiveTest.java b/aws/src/test/java/com/baeldung/jets3t/JetS3tLiveTest.java new file mode 100644 index 0000000000..cf0b203e10 --- /dev/null +++ b/aws/src/test/java/com/baeldung/jets3t/JetS3tLiveTest.java @@ -0,0 +1,351 @@ +package com.baeldung.jets3t; + +import org.apache.commons.codec.digest.DigestUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.jets3t.service.S3Service; +import org.jets3t.service.ServiceException; +import org.jets3t.service.impl.rest.httpclient.RestS3Service; +import org.jets3t.service.model.S3Bucket; +import org.jets3t.service.model.S3Object; +import org.jets3t.service.model.StorageObject; +import org.jets3t.service.security.AWSCredentials; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.io.*; +import java.nio.file.Files; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.stream.Collectors; + +import static java.nio.file.StandardCopyOption.REPLACE_EXISTING; +import static junit.framework.TestCase.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +public class JetS3tLiveTest { + + private Log log = LogFactory.getLog(JetS3tLiveTest.class); + + private static final String BucketName = "baeldung-barfoo"; + private static final String TestString = "test string"; + private static final String TestStringName = "string object"; + private static final String TgtBucket = "baeldung-tgtbucket"; + + private static S3Service s3Service; + + @BeforeClass + public static void connectS3() throws Exception { + + // Replace with your keys + String awsAccessKey = "your access key"; + String awsSecretKey = "your secret key"; + + // Create credentials + AWSCredentials awsCredentials = new AWSCredentials(awsAccessKey, awsSecretKey); + + // Create service + s3Service = new RestS3Service(awsCredentials); + } + + @Test + public void givenCreate_AndDeleteBucket_CountGoesUpThenDown() throws Exception { + + // List buckets, get a count + S3Bucket[] myBuckets = s3Service.listAllBuckets(); + int count = Arrays.stream(myBuckets).map(S3Bucket::getName).collect(Collectors.toList()).size(); + + // Create a bucket + S3Bucket bucket = createBucket(); + assertNotNull(bucket); + + // List again + myBuckets = s3Service.listAllBuckets(); + int newCount = Arrays.stream(myBuckets).map(S3Bucket::getName).collect(Collectors.toList()).size(); + + // We should have one more + assertEquals((count + 1), newCount); + + // Delete so next test doesn't fail + deleteBucket(); + + // Check the count again, just for laughs + myBuckets = s3Service.listAllBuckets(); + newCount = Arrays.stream(myBuckets).map(S3Bucket::getName).collect(Collectors.toList()).size(); + assertEquals(count, newCount); + + } + + private S3Bucket createBucket() throws Exception { + S3Bucket bucket = s3Service.createBucket(BucketName); + log.info(bucket); + return bucket; + } + + + private void deleteBucket() throws ServiceException { + s3Service.deleteBucket(BucketName); + } + + @Test + public void givenString_Uploaded_StringInfoIsAvailable() throws Exception { + + // Create a bucket + S3Bucket bucket = createBucket(); + assertNotNull(bucket); + + // Upload a string + uploadStringData(); + + // Get the details + StorageObject objectDetailsOnly = s3Service.getObjectDetails(BucketName, TestStringName); + log.info("Content type: " + objectDetailsOnly.getContentType() + " length: " + objectDetailsOnly.getContentLength()); + + // Delete it + deleteObject(TestStringName); + + // For next test + deleteBucket(); + } + + private void uploadStringData() throws Exception { + S3Object stringObject = new S3Object(TestStringName, TestString); + s3Service.putObject(BucketName, stringObject); + log.info("Content type:" + stringObject.getContentType()); + } + + private void deleteObject(String objectName) throws ServiceException { + s3Service.deleteObject(BucketName, objectName); + } + + @Test + public void givenStringUploaded_StringIsDownloaded() throws Exception { + + // Get a bucket + S3Bucket bucket = createBucket(); + assertNotNull(bucket); + + uploadStringData(); + + // Download + S3Object stringObject = s3Service.getObject(BucketName, TestStringName); + + // Process stream into a string + String downloadedString = new BufferedReader(new InputStreamReader(stringObject.getDataInputStream())).lines().collect(Collectors.joining("\n")); + + // Verify + assertTrue(TestString.equals(downloadedString)); + + + // Clean up for next test + deleteObject(TestStringName); + deleteBucket(); + } + + @Test + public void givenBinaryFileUploaded_FileIsDownloaded() throws Exception { + + // get a bucket + S3Bucket bucket = createBucket(); + assertNotNull(bucket); + + // Put a binary file + S3Object fileObject = new S3Object(new File("src/test/resources/test.jpg")); + s3Service.putObject(BucketName, fileObject); + + // Print info about type and name + log.info("Content type:" + fileObject.getContentType()); + log.info("File object name is " + fileObject.getName()); + + // Download + S3Object newFileObject = s3Service.getObject(BucketName, "test.jpg"); + + // Save to a different name + File newFile = new File("src/test/resources/newtest.jpg"); + Files.copy(newFileObject.getDataInputStream(), newFile.toPath(), REPLACE_EXISTING); + + + // Get hashes and compare + String origMD5 = getFileMD5("src/test/resources/test.jpg"); + String newMD5 = getFileMD5("src/test/resources/newtest.jpg"); + assertTrue(origMD5.equals(newMD5)); + + // Clean up + deleteObject("test.jpg"); + deleteBucket(); + } + + // Get MD5 hash for a file + private String getFileMD5(String filename) throws IOException { + try (FileInputStream fis = new FileInputStream(new File(filename))) { + return DigestUtils.md5Hex(fis); + } + } + + + + @Test + public void givenStreamDataUploaded_StreamDataIsDownloaded() throws Exception { + + // get a bucket + S3Bucket bucket = createBucket(); + assertNotNull(bucket); + + ArrayList numbers = new ArrayList<>(); + numbers.add(2); + numbers.add(3); + numbers.add(5); + numbers.add(7); + + // Serialize ArrayList + ByteArrayOutputStream bytes = new ByteArrayOutputStream(); + ObjectOutputStream objectOutputStream = new ObjectOutputStream(bytes); + objectOutputStream.writeObject(numbers); + + // Wrap bytes + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes.toByteArray()); + + // Create and populate object + S3Object streamObject = new S3Object("stream"); + streamObject.setDataInputStream(byteArrayInputStream); + streamObject.setContentLength(byteArrayInputStream.available()); + streamObject.setContentType("binary/octet-stream"); + + // Put it + s3Service.putObject(BucketName, streamObject); + + // Get it + S3Object newStreamObject = s3Service.getObject(BucketName, "stream"); + + // Convert back to ArrayList + ObjectInputStream objectInputStream = new ObjectInputStream(newStreamObject.getDataInputStream()); + ArrayList newNumbers = (ArrayList)objectInputStream.readObject(); + + assertEquals(2, (int)newNumbers.get(0)); + assertEquals(3, (int)newNumbers.get(1)); + assertEquals(5, (int)newNumbers.get(2)); + assertEquals(7, (int)newNumbers.get(3)); + + // Clean up + deleteObject("stream"); + deleteBucket(); + } + + @Test + public void whenFileCopied_CopyIsSame() throws Exception { + + // get a bucket + S3Bucket bucket = createBucket(); + assertNotNull(bucket); + + // Put a binary file + S3Object fileObject = new S3Object(new File("src/test/resources/test.jpg")); + s3Service.putObject(BucketName, fileObject); + + + // Copy it + S3Object targetObject = new S3Object("testcopy.jpg"); + s3Service.copyObject(BucketName, "test.jpg", BucketName, targetObject, false); + + + // Download + S3Object newFileObject = s3Service.getObject(BucketName, "testcopy.jpg"); + + // Save to a different name + File newFile = new File("src/test/resources/testcopy.jpg"); + Files.copy(newFileObject.getDataInputStream(), newFile.toPath(), REPLACE_EXISTING); + + + // Get hashes and compare + String origMD5 = getFileMD5("src/test/resources/test.jpg"); + String newMD5 = getFileMD5("src/test/resources/testcopy.jpg"); + assertTrue(origMD5.equals(newMD5)); + + // Clean up + deleteObject("test.jpg"); + deleteObject("testcopy.jpg"); + deleteBucket(); + + } + + + @Test + public void whenFileRenamed_NewNameIsSame() throws Exception { + + // get a bucket + S3Bucket bucket = createBucket(); + assertNotNull(bucket); + + // Put a binary file + S3Object fileObject = new S3Object(new File("src/test/resources/test.jpg")); + s3Service.putObject(BucketName, fileObject); + + + // Copy it + s3Service.renameObject(BucketName, "test.jpg", new S3Object("spidey.jpg")); + + + // Download + S3Object newFileObject = s3Service.getObject(BucketName, "spidey.jpg"); + + // Save to a different name + File newFile = new File("src/test/resources/spidey.jpg"); + Files.copy(newFileObject.getDataInputStream(), newFile.toPath(), REPLACE_EXISTING); + + + // Get hashes and compare + String origMD5 = getFileMD5("src/test/resources/test.jpg"); + String newMD5 = getFileMD5("src/test/resources/spidey.jpg"); + assertTrue(origMD5.equals(newMD5)); + + // Clean up + deleteObject("test.jpg"); + deleteObject("spidey.jpg"); + deleteBucket(); + + } + + @Test + public void whenFileMoved_NewInstanceIsSame() throws Exception { + + // get a bucket + S3Bucket bucket = createBucket(); + assertNotNull(bucket); + + // create another bucket + S3Bucket tgtBucket = s3Service.createBucket(TgtBucket); + + + // Put a binary file + S3Object fileObject = new S3Object(new File("src/test/resources/test.jpg")); + s3Service.putObject(BucketName, fileObject); + + + // Copy it + s3Service.moveObject(BucketName, "test.jpg", TgtBucket, + new S3Object("spidey.jpg"), false); + + + // Download + S3Object newFileObject = s3Service.getObject(TgtBucket, "spidey.jpg"); + + // Save to a different name + File newFile = new File("src/test/resources/spidey.jpg"); + Files.copy(newFileObject.getDataInputStream(), newFile.toPath(), REPLACE_EXISTING); + + + // Get hashes and compare + String origMD5 = getFileMD5("src/test/resources/test.jpg"); + String newMD5 = getFileMD5("src/test/resources/spidey.jpg"); + assertTrue(origMD5.equals(newMD5)); + + // Clean up + deleteBucket(); + + s3Service.deleteObject(TgtBucket, "spidey.jpg"); + s3Service.deleteBucket(TgtBucket); + } + + +} From c6b0bb04d17ec693fc7db10d5a93ba1b53b30396 Mon Sep 17 00:00:00 2001 From: Tom Hombergs Date: Sun, 15 Apr 2018 20:48:51 +0200 Subject: [PATCH 21/36] added article link --- core-kotlin/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-kotlin/README.md b/core-kotlin/README.md index 54528a076b..d6bd41a111 100644 --- a/core-kotlin/README.md +++ b/core-kotlin/README.md @@ -23,3 +23,4 @@ - [Kotlin Dependency Injection with Kodein](http://www.baeldung.com/kotlin-kodein-dependency-injection) - [Regular Expressions in Kotlin](http://www.baeldung.com/kotlin-regular-expressions) - [Objects in Kotlin](http://www.baeldung.com/kotlin-objects) +- [Reading from a File in Kotlin](http://www.baeldung.com/kotlin-read-file) From 87e4c25f453c0b0cf554e0fb4d0f41d0555b70ee Mon Sep 17 00:00:00 2001 From: gautamshetty Date: Sun, 15 Apr 2018 14:26:30 -0500 Subject: [PATCH 22/36] [BAEL 717]-Singleton Session Bean. (#4001) * BAEL-717: Singleton EJB Bean Files for BAEL-717:Singleton EJB Bean. * BAEL-717: Singleton EJB Bean Corrected Indentation. * BAEL-717: Singleton EJB Bean Corrected Indentation. * BAEL-717: Singleton EJB Bean Corrected Indentation. * BAEL-717: Singleton EJB Bean Corrected Indentation. * BAEL-717: Singleton EJB Bean Changed artifactId value. * BAEL-717: Singleton EJB Bean. Added module for Singleton EJB Bean. * BAEL-717: Singleton EJB Bean. Removed Singleton EJB Bean Module. * BAEL-717: Singleton EJB Bean Changed the JNDI Lookup name. * BAEL-717: Singleton EJB Bean. Added the "singleton-ejb-bean" module. * BAEL-717: Singleton EJB Bean. Corrected Indentation. * BAEL-717: Singleton EJB Bean Corrected Indentation. * BAEL-717: Singleton EJB Bean. Corrected Indentation. * BAEL-717: Singleton EJB Bean. Corrected Indentation. * BAEL-717:Singleton EJB Bean. Corrected Indentation. * BAEL-717:Singleton EJB Bean. Corrected Indentation. * BAEL-717: Singleton Session Bean. Added class for Bean-Managed concurrrency. Changed class name from CountryStateCacheBean to CountryStateContainerManagedBean. * BAEL-717: Singleton Session Bean. Changing the name of the class to CountryStateContainerManagedBean. * BAEL-717: Singleton Session Bean. Added method to test Bean-Managed concurrency. * Get Latest. * deleting CountryStateBeanManagedBean for new file. * deleting CountryStateCacheBean for new file. * deleting CountryStateContainerManagedBean for new file. * BAEL-717: Singleton Session Bean. Adding file for Bean with Bean-Managed concurrency. Changing file name for original file to CountryStateContainerManagedBean with Container-Managed concurrency. * Deleting file for new checkin. * BAEL-717: Singleton Session Bean. Added test case for Bean-Manged concurrency. Change in JNDI names. * BAEL-717: Singleton Session Bean. Changed the assert method parameter order and null check in test cases. --- .../CountryStateBeanManagedBean.java | 39 +++++++++++++++++++ ... => CountryStateContainerManagedBean.java} | 2 +- .../CountryStateCacheBeanTest.java | 27 ++++++++----- 3 files changed, 58 insertions(+), 10 deletions(-) create mode 100644 spring-ejb/singleton-ejb-bean/src/main/java/com/baeldung/singletonbean/CountryStateBeanManagedBean.java rename spring-ejb/singleton-ejb-bean/src/main/java/com/baeldung/singletonbean/{CountryStateCacheBean.java => CountryStateContainerManagedBean.java} (93%) diff --git a/spring-ejb/singleton-ejb-bean/src/main/java/com/baeldung/singletonbean/CountryStateBeanManagedBean.java b/spring-ejb/singleton-ejb-bean/src/main/java/com/baeldung/singletonbean/CountryStateBeanManagedBean.java new file mode 100644 index 0000000000..b437dc4d7f --- /dev/null +++ b/spring-ejb/singleton-ejb-bean/src/main/java/com/baeldung/singletonbean/CountryStateBeanManagedBean.java @@ -0,0 +1,39 @@ +package com.baeldung.singletonbean; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.annotation.PostConstruct; +import javax.ejb.ConcurrencyManagement; +import javax.ejb.ConcurrencyManagementType; +import javax.ejb.Lock; +import javax.ejb.LockType; +import javax.ejb.Singleton; +import javax.ejb.Startup; + +@Singleton +@Startup +@ConcurrencyManagement(ConcurrencyManagementType.BEAN) +public class CountryStateBeanManagedBean implements CountryState { + + private volatile Map> countryStatesMap = new HashMap>(); + + @PostConstruct + public synchronized void initialize() { + + List states = new ArrayList(); + states.add("Texas"); + states.add("Alabama"); + states.add("Alaska"); + states.add("Arizona"); + states.add("Arkansas"); + + countryStatesMap.put("UnitedStates", states); + } + + public List getStates(String country) { + return countryStatesMap.get(country); + } +} diff --git a/spring-ejb/singleton-ejb-bean/src/main/java/com/baeldung/singletonbean/CountryStateCacheBean.java b/spring-ejb/singleton-ejb-bean/src/main/java/com/baeldung/singletonbean/CountryStateContainerManagedBean.java similarity index 93% rename from spring-ejb/singleton-ejb-bean/src/main/java/com/baeldung/singletonbean/CountryStateCacheBean.java rename to spring-ejb/singleton-ejb-bean/src/main/java/com/baeldung/singletonbean/CountryStateContainerManagedBean.java index 3b4d80c88c..ee16285824 100644 --- a/spring-ejb/singleton-ejb-bean/src/main/java/com/baeldung/singletonbean/CountryStateCacheBean.java +++ b/spring-ejb/singleton-ejb-bean/src/main/java/com/baeldung/singletonbean/CountryStateContainerManagedBean.java @@ -16,7 +16,7 @@ import javax.ejb.Startup; @Singleton @Startup @ConcurrencyManagement(ConcurrencyManagementType.CONTAINER) -public class CountryStateCacheBean implements CountryState { +public class CountryStateContainerManagedBean implements CountryState { private Map> countryStatesMap = new HashMap>(); diff --git a/spring-ejb/singleton-ejb-bean/src/test/java/com/baeldung/singletonbean/CountryStateCacheBeanTest.java b/spring-ejb/singleton-ejb-bean/src/test/java/com/baeldung/singletonbean/CountryStateCacheBeanTest.java index 988a4eeb6d..62412084bd 100644 --- a/spring-ejb/singleton-ejb-bean/src/test/java/com/baeldung/singletonbean/CountryStateCacheBeanTest.java +++ b/spring-ejb/singleton-ejb-bean/src/test/java/com/baeldung/singletonbean/CountryStateCacheBeanTest.java @@ -1,6 +1,7 @@ package com.baeldung.singletonbean; import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertNotNull; import java.util.List; @@ -11,8 +12,6 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; -import com.baeldung.singletonbean.CountryState; - public class CountryStateCacheBeanTest { private EJBContainer ejbContainer = null; @@ -27,15 +26,25 @@ public class CountryStateCacheBeanTest { } @Test - public void whenCallGetStates_ReturnsStatesForCountry() throws Exception { + public void whenCallGetStatesFromContainerManagedBean_ReturnsStatesForCountry() throws Exception { - String[] actualStates = { "Texas", "Alabama", "Alaska", "Arizona", "Arkansas" }; + String[] expectedStates = { "Texas", "Alabama", "Alaska", "Arizona", "Arkansas" }; - CountryState countryStateBean = (CountryState) context.lookup("java:global/singleton-ejb-bean/CountryStateCacheBean"); - List states = countryStateBean.getStates("UnitedStates"); - if (states != null) { - assertArrayEquals(states.toArray(), actualStates); - } + CountryState countryStateBean = (CountryState) context.lookup("java:global/singleton-ejb-bean/CountryStateContainerManagedBean"); + List actualStates = countryStateBean.getStates("UnitedStates"); + assertNotNull(actualStates); + assertArrayEquals(expectedStates, actualStates.toArray()); + } + + @Test + public void whenCallGetStatesFromBeanManagedBean_ReturnsStatesForCountry() throws Exception { + + String[] expectedStates = { "Texas", "Alabama", "Alaska", "Arizona", "Arkansas" }; + + CountryState countryStateBean = (CountryState) context.lookup("java:global/singleton-ejb-bean/CountryStateBeanManagedBean"); + List actualStates = countryStateBean.getStates("UnitedStates"); + assertNotNull(actualStates); + assertArrayEquals(expectedStates, actualStates.toArray()); } @After From 63a220d39a2a245fa07b3e57b33144839fff955a Mon Sep 17 00:00:00 2001 From: hemantvsn Date: Mon, 16 Apr 2018 01:12:23 +0530 Subject: [PATCH 23/36] Added boot app, filters, controller and model (#3848) --- .../SpringBootFiltersApplication.java | 17 +++++++ .../controller/UserController.java | 34 +++++++++++++ .../filters/RequestResponseLoggingFilter.java | 50 +++++++++++++++++++ .../filters/TransactionFilter.java | 47 +++++++++++++++++ .../bootcustomfilters/model/User.java | 45 +++++++++++++++++ 5 files changed, 193 insertions(+) create mode 100644 spring-boot/src/main/java/com/baeldung/bootcustomfilters/SpringBootFiltersApplication.java create mode 100644 spring-boot/src/main/java/com/baeldung/bootcustomfilters/controller/UserController.java create mode 100644 spring-boot/src/main/java/com/baeldung/bootcustomfilters/filters/RequestResponseLoggingFilter.java create mode 100644 spring-boot/src/main/java/com/baeldung/bootcustomfilters/filters/TransactionFilter.java create mode 100644 spring-boot/src/main/java/com/baeldung/bootcustomfilters/model/User.java diff --git a/spring-boot/src/main/java/com/baeldung/bootcustomfilters/SpringBootFiltersApplication.java b/spring-boot/src/main/java/com/baeldung/bootcustomfilters/SpringBootFiltersApplication.java new file mode 100644 index 0000000000..c4653932c0 --- /dev/null +++ b/spring-boot/src/main/java/com/baeldung/bootcustomfilters/SpringBootFiltersApplication.java @@ -0,0 +1,17 @@ +package com.baeldung.bootcustomfilters; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +/** + * Boot application + * @author hemant + * + */ +@SpringBootApplication +public class SpringBootFiltersApplication { + + public static void main(String[] args) { + SpringApplication.run(SpringBootFiltersApplication.class, args); + } +} diff --git a/spring-boot/src/main/java/com/baeldung/bootcustomfilters/controller/UserController.java b/spring-boot/src/main/java/com/baeldung/bootcustomfilters/controller/UserController.java new file mode 100644 index 0000000000..9dfab1192d --- /dev/null +++ b/spring-boot/src/main/java/com/baeldung/bootcustomfilters/controller/UserController.java @@ -0,0 +1,34 @@ +package com.baeldung.bootcustomfilters.controller; + +import java.util.Arrays; +import java.util.List; +import java.util.UUID; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import com.baeldung.bootcustomfilters.model.User; + +/** + * Rest controller for User + * @author hemant + * + */ +@RestController +@RequestMapping("/users") +public class UserController { + + private static final Logger LOG = LoggerFactory.getLogger(UserController.class); + + @RequestMapping("") + public List getAllUsers() { + LOG.info("Fetching all the users"); + return Arrays.asList( + new User(UUID.randomUUID().toString(), "User1", "user1@test.com"), + new User(UUID.randomUUID().toString(), "User1", "user1@test.com"), + new User(UUID.randomUUID().toString(), "User1", "user1@test.com")); + } + +} diff --git a/spring-boot/src/main/java/com/baeldung/bootcustomfilters/filters/RequestResponseLoggingFilter.java b/spring-boot/src/main/java/com/baeldung/bootcustomfilters/filters/RequestResponseLoggingFilter.java new file mode 100644 index 0000000000..e42ea7d2dd --- /dev/null +++ b/spring-boot/src/main/java/com/baeldung/bootcustomfilters/filters/RequestResponseLoggingFilter.java @@ -0,0 +1,50 @@ +package com.baeldung.bootcustomfilters.filters; + +import java.io.IOException; + +import javax.servlet.Filter; +import javax.servlet.FilterChain; +import javax.servlet.FilterConfig; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.core.annotation.Order; +import org.springframework.stereotype.Component; + +/** + * A servlet filter to log request and response + * The logging implementation is pretty native and for demonstration only + * @author hemant + * + */ +@Component +@Order(2) +public class RequestResponseLoggingFilter implements Filter { + + private final static Logger LOG = LoggerFactory.getLogger(RequestResponseLoggingFilter.class); + + @Override + public void init(final FilterConfig filterConfig) throws ServletException { + LOG.info("Initializing filter :{}", this); + } + + @Override + public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) + throws IOException, ServletException { + HttpServletRequest req = (HttpServletRequest) request; + HttpServletResponse res = (HttpServletResponse) response; + LOG.info("Logging Request {} : {}", req.getMethod(), req.getRequestURI()); + chain.doFilter(request, response); + LOG.info("Logging Response :{}", res.getContentType()); + } + + @Override + public void destroy() { + LOG.warn("Destructing filter :{}", this); + } +} diff --git a/spring-boot/src/main/java/com/baeldung/bootcustomfilters/filters/TransactionFilter.java b/spring-boot/src/main/java/com/baeldung/bootcustomfilters/filters/TransactionFilter.java new file mode 100644 index 0000000000..d92b723e73 --- /dev/null +++ b/spring-boot/src/main/java/com/baeldung/bootcustomfilters/filters/TransactionFilter.java @@ -0,0 +1,47 @@ +package com.baeldung.bootcustomfilters.filters; + +import java.io.IOException; + +import javax.servlet.Filter; +import javax.servlet.FilterChain; +import javax.servlet.FilterConfig; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; +import javax.servlet.http.HttpServletRequest; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.core.annotation.Order; +import org.springframework.stereotype.Component; + +/** + * A filter to create transaction before and commit it once request completes + * The current implemenatation is just for demo + * @author hemant + * + */ +@Component +@Order(1) +public class TransactionFilter implements Filter { + + private final static Logger LOG = LoggerFactory.getLogger(TransactionFilter.class); + + @Override + public void init(final FilterConfig filterConfig) throws ServletException { + LOG.info("Initializing filter :{}", this); + } + + @Override + public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException { + HttpServletRequest req = (HttpServletRequest) request; + LOG.info("Starting Transaction for req :{}", req.getRequestURI()); + chain.doFilter(request, response); + LOG.info("Committing Transaction for req :{}", req.getRequestURI()); + } + + @Override + public void destroy() { + LOG.warn("Destructing filter :{}", this); + } +} diff --git a/spring-boot/src/main/java/com/baeldung/bootcustomfilters/model/User.java b/spring-boot/src/main/java/com/baeldung/bootcustomfilters/model/User.java new file mode 100644 index 0000000000..ab8e6c8206 --- /dev/null +++ b/spring-boot/src/main/java/com/baeldung/bootcustomfilters/model/User.java @@ -0,0 +1,45 @@ +package com.baeldung.bootcustomfilters.model; + +/** + * User model + * @author hemant + * + */ +public class User { + + private String id; + private String name; + private String email; + + public User(String id, String name, String email) { + super(); + this.id = id; + this.name = name; + this.email = email; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + +} From 6561af5cd2c138d96a013dee999a1ff7a6126e8c Mon Sep 17 00:00:00 2001 From: linhvovn Date: Mon, 16 Apr 2018 03:49:12 +0800 Subject: [PATCH 24/36] Bael 1684 - Move to spring-jpa (#4015) * [tlinh2110] BAEL 1684 Init * [BAEL1684-tlinh2110] Move to spring-jpa * [BAEL-1684 tlinh2110] Remove unused file --- .../autogenkey/config/PersistenceConfig.java | 28 +++++++++++ .../MessageRepositoryJDBCTemplate.java | 38 ++++++++++++++ .../MessageRepositorySimpleJDBCInsert.java | 29 +++++++++++ .../src/main/resources/autogenkey-schema.sql | 5 ++ .../jdbc/autogenkey/GetAutoGenKeyByJDBC.java | 49 +++++++++++++++++++ 5 files changed, 149 insertions(+) create mode 100644 persistence-modules/spring-jpa/src/main/java/com/baeldung/jdbc/autogenkey/config/PersistenceConfig.java create mode 100644 persistence-modules/spring-jpa/src/main/java/com/baeldung/jdbc/autogenkey/repository/MessageRepositoryJDBCTemplate.java create mode 100644 persistence-modules/spring-jpa/src/main/java/com/baeldung/jdbc/autogenkey/repository/MessageRepositorySimpleJDBCInsert.java create mode 100644 persistence-modules/spring-jpa/src/main/resources/autogenkey-schema.sql create mode 100644 persistence-modules/spring-jpa/src/test/java/com/baeldung/jdbc/autogenkey/GetAutoGenKeyByJDBC.java diff --git a/persistence-modules/spring-jpa/src/main/java/com/baeldung/jdbc/autogenkey/config/PersistenceConfig.java b/persistence-modules/spring-jpa/src/main/java/com/baeldung/jdbc/autogenkey/config/PersistenceConfig.java new file mode 100644 index 0000000000..99f50abf4c --- /dev/null +++ b/persistence-modules/spring-jpa/src/main/java/com/baeldung/jdbc/autogenkey/config/PersistenceConfig.java @@ -0,0 +1,28 @@ +package com.baeldung.jdbc.autogenkey.config; + +import javax.sql.DataSource; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.env.Environment; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; +import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType; + +@Configuration +public class PersistenceConfig { + + @Bean + public DataSource dataSource(Environment env) { + return new EmbeddedDatabaseBuilder() + .setType(EmbeddedDatabaseType.H2) + .addScript("autogenkey-schema.sql") + .build(); + } + + @Bean + public JdbcTemplate jdbcTemplate(DataSource dataSource) { + return new JdbcTemplate(dataSource); + } + +} diff --git a/persistence-modules/spring-jpa/src/main/java/com/baeldung/jdbc/autogenkey/repository/MessageRepositoryJDBCTemplate.java b/persistence-modules/spring-jpa/src/main/java/com/baeldung/jdbc/autogenkey/repository/MessageRepositoryJDBCTemplate.java new file mode 100644 index 0000000000..cf0dbe4681 --- /dev/null +++ b/persistence-modules/spring-jpa/src/main/java/com/baeldung/jdbc/autogenkey/repository/MessageRepositoryJDBCTemplate.java @@ -0,0 +1,38 @@ +package com.baeldung.jdbc.autogenkey.repository; + +import java.sql.PreparedStatement; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.support.GeneratedKeyHolder; +import org.springframework.jdbc.support.KeyHolder; +import org.springframework.stereotype.Repository; + +@Repository +public class MessageRepositoryJDBCTemplate { + + @Autowired + JdbcTemplate jdbcTemplate; + + final String INSERT_MESSAGE_SQL = "insert into sys_message (message) values(?) "; + + public long insert(final String message) { + + KeyHolder keyHolder = new GeneratedKeyHolder(); + + jdbcTemplate.update(connection -> { + PreparedStatement ps = connection.prepareStatement(INSERT_MESSAGE_SQL); + ps.setString(1, message); + return ps; + }, keyHolder); + + return (long) keyHolder.getKey(); + } + + final String SELECT_BY_ID = "select message from sys_message where id = ?"; + + public String getMessageById(long id) { + return this.jdbcTemplate.queryForObject(SELECT_BY_ID, String.class, new Object[] { id }); + } + +} diff --git a/persistence-modules/spring-jpa/src/main/java/com/baeldung/jdbc/autogenkey/repository/MessageRepositorySimpleJDBCInsert.java b/persistence-modules/spring-jpa/src/main/java/com/baeldung/jdbc/autogenkey/repository/MessageRepositorySimpleJDBCInsert.java new file mode 100644 index 0000000000..022ea29ed6 --- /dev/null +++ b/persistence-modules/spring-jpa/src/main/java/com/baeldung/jdbc/autogenkey/repository/MessageRepositorySimpleJDBCInsert.java @@ -0,0 +1,29 @@ +package com.baeldung.jdbc.autogenkey.repository; + +import java.util.HashMap; +import java.util.Map; + +import javax.sql.DataSource; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.jdbc.core.simple.SimpleJdbcInsert; +import org.springframework.stereotype.Repository; + +@Repository +public class MessageRepositorySimpleJDBCInsert { + + SimpleJdbcInsert messageInsert; + + @Autowired + public MessageRepositorySimpleJDBCInsert(DataSource dataSource) { + messageInsert = new SimpleJdbcInsert(dataSource).withTableName("sys_message").usingGeneratedKeyColumns("id"); + } + + public long insert(String message) { + Map parameters = new HashMap(1); + parameters.put("message", message); + Number newId = messageInsert.executeAndReturnKey(parameters); + return (long) newId; + } + +} diff --git a/persistence-modules/spring-jpa/src/main/resources/autogenkey-schema.sql b/persistence-modules/spring-jpa/src/main/resources/autogenkey-schema.sql new file mode 100644 index 0000000000..925b27143c --- /dev/null +++ b/persistence-modules/spring-jpa/src/main/resources/autogenkey-schema.sql @@ -0,0 +1,5 @@ +CREATE TABLE IF NOT EXISTS sys_message ( + id bigint(20) NOT NULL AUTO_INCREMENT, + message varchar(100) NOT NULL, + PRIMARY KEY (id) +); \ No newline at end of file diff --git a/persistence-modules/spring-jpa/src/test/java/com/baeldung/jdbc/autogenkey/GetAutoGenKeyByJDBC.java b/persistence-modules/spring-jpa/src/test/java/com/baeldung/jdbc/autogenkey/GetAutoGenKeyByJDBC.java new file mode 100644 index 0000000000..aa4d061997 --- /dev/null +++ b/persistence-modules/spring-jpa/src/test/java/com/baeldung/jdbc/autogenkey/GetAutoGenKeyByJDBC.java @@ -0,0 +1,49 @@ +package com.baeldung.jdbc.autogenkey; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.test.context.junit4.SpringRunner; + +import com.baeldung.jdbc.autogenkey.repository.MessageRepositoryJDBCTemplate; +import com.baeldung.jdbc.autogenkey.repository.MessageRepositorySimpleJDBCInsert; + +@RunWith(SpringRunner.class) +public class GetAutoGenKeyByJDBC { + + @Configuration + @ComponentScan(basePackages = { "com.baeldung.jdbc.autogenkey" }) + public static class SpringConfig { + + } + + @Autowired + MessageRepositorySimpleJDBCInsert messageRepositorySimpleJDBCInsert; + + @Autowired + MessageRepositoryJDBCTemplate messageRepositoryJDBCTemplate; + + final String MESSAGE_CONTENT = "Test"; + + @Test + public void insertJDBC_whenLoadMessageByKey_thenGetTheSameMessage() { + long key = messageRepositoryJDBCTemplate.insert(MESSAGE_CONTENT); + String loadedMessage = messageRepositoryJDBCTemplate.getMessageById(key); + + assertEquals(MESSAGE_CONTENT, loadedMessage); + + } + + @Test + public void insertSimpleInsert_whenLoadMessageKey_thenGetTheSameMessage() { + long key = messageRepositorySimpleJDBCInsert.insert(MESSAGE_CONTENT); + String loadedMessage = messageRepositoryJDBCTemplate.getMessageById(key); + + assertEquals(MESSAGE_CONTENT, loadedMessage); + } + +} From 9b982ec865e922dc2d28c3d8219b2bf17025e0b6 Mon Sep 17 00:00:00 2001 From: Tom Hombergs Date: Mon, 16 Apr 2018 00:11:38 +0200 Subject: [PATCH 25/36] added link to article --- patterns/facade/README.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 patterns/facade/README.md diff --git a/patterns/facade/README.md b/patterns/facade/README.md new file mode 100644 index 0000000000..cb44bf4bc4 --- /dev/null +++ b/patterns/facade/README.md @@ -0,0 +1,2 @@ +### Relevant Articles: +- [Facade Design Pattern in Java](http://www.baeldung.com/java-facade-pattern) From c1a6b5b553b93004d085cfa8a411abebc6d104db Mon Sep 17 00:00:00 2001 From: Tom Hombergs Date: Mon, 16 Apr 2018 08:24:00 +0200 Subject: [PATCH 26/36] added article link (#4021) --- testing-modules/junit-5/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/testing-modules/junit-5/README.md b/testing-modules/junit-5/README.md index 441faf2766..85e628668a 100644 --- a/testing-modules/junit-5/README.md +++ b/testing-modules/junit-5/README.md @@ -10,4 +10,5 @@ - [JUnit 5 – @RunWith](http://www.baeldung.com/junit-5-runwith) - [JUnit 5 @Test Annotation](http://www.baeldung.com/junit-5-test-annotation) - [JUnit Assert an Exception is Thrown](http://www.baeldung.com/junit-assert-exception) +- [@Before vs @BeforeClass vs @BeforeEach vs @BeforeAll](http://www.baeldung.com/junit-before-beforeclass-beforeeach-beforeall) From 5d5b44c0a96c47a240c8801f789cce1f30cc63c1 Mon Sep 17 00:00:00 2001 From: Ekaterina Galkina Date: Mon, 16 Apr 2018 12:36:19 +0500 Subject: [PATCH 27/36] BAEL-1645 fix --- .../src/main/java/com/baeldung/assertions/Car.java | 5 +++++ .../java/com/baeldung/assertions/CarBattery.java | 13 +++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 spring-5/src/main/java/com/baeldung/assertions/CarBattery.java diff --git a/spring-5/src/main/java/com/baeldung/assertions/Car.java b/spring-5/src/main/java/com/baeldung/assertions/Car.java index 4e210dfaab..599246c752 100644 --- a/spring-5/src/main/java/com/baeldung/assertions/Car.java +++ b/spring-5/src/main/java/com/baeldung/assertions/Car.java @@ -43,6 +43,11 @@ public class Car { Assert.isNull(oil, "oil must be null"); // ... } + + public void replaceBattery(CarBattery carBattery){ + Assert.isNull(carBattery.getCharge(), "to replace battery the charge must be null"); + // ... + } public void сhangeEngine(Engine engine) { Assert.isInstanceOf(ToyotaEngine.class, engine); diff --git a/spring-5/src/main/java/com/baeldung/assertions/CarBattery.java b/spring-5/src/main/java/com/baeldung/assertions/CarBattery.java new file mode 100644 index 0000000000..a75457a7ec --- /dev/null +++ b/spring-5/src/main/java/com/baeldung/assertions/CarBattery.java @@ -0,0 +1,13 @@ +package com.baeldung.assertions; + +public class CarBattery { + private String charge; + + public String getCharge() { + return charge; + } + + public void setCharge(String charge) { + this.charge = charge; + } +} From 56b2899171491ee28536d93820cb9731f55aaef0 Mon Sep 17 00:00:00 2001 From: Ekaterina Galkina Date: Mon, 16 Apr 2018 12:49:41 +0500 Subject: [PATCH 28/36] BAEL-1645 fix 2 --- spring-5/src/main/java/com/baeldung/assertions/Car.java | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/spring-5/src/main/java/com/baeldung/assertions/Car.java b/spring-5/src/main/java/com/baeldung/assertions/Car.java index 599246c752..210fca5cf3 100644 --- a/spring-5/src/main/java/com/baeldung/assertions/Car.java +++ b/spring-5/src/main/java/com/baeldung/assertions/Car.java @@ -39,12 +39,7 @@ public class Car { // ... } - public void сhangeOilWithIsNull(String oil) { - Assert.isNull(oil, "oil must be null"); - // ... - } - - public void replaceBattery(CarBattery carBattery){ + public void replaceBattery(CarBattery carBattery) { Assert.isNull(carBattery.getCharge(), "to replace battery the charge must be null"); // ... } From 59e46080d8681c8f4a854cb383d4148b3d49208b Mon Sep 17 00:00:00 2001 From: Ekaterina Galkina Date: Mon, 16 Apr 2018 12:57:51 +0500 Subject: [PATCH 29/36] BAEL-1645 fix 3 --- spring-5/src/main/java/com/baeldung/assertions/Car.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/spring-5/src/main/java/com/baeldung/assertions/Car.java b/spring-5/src/main/java/com/baeldung/assertions/Car.java index 210fca5cf3..abff27f0b0 100644 --- a/spring-5/src/main/java/com/baeldung/assertions/Car.java +++ b/spring-5/src/main/java/com/baeldung/assertions/Car.java @@ -99,7 +99,9 @@ public class Car { car.fuel(); car.сhangeOil("oil"); - car.сhangeOilWithIsNull(null); + + CarBattery carBattery = new CarBattery(); + car.replaceBattery(carBattery); car.сhangeEngine(new ToyotaEngine()); From 6f887d29c657cb6c89051e4104b72eea56ba44ae Mon Sep 17 00:00:00 2001 From: Gangadharan Khoteeswarun Date: Mon, 16 Apr 2018 22:17:39 +0800 Subject: [PATCH 30/36] @Lookup annotation Code (#3900) * Updated * Changed Test Names * Updated code for method injection section 3.2 * Added Grader bean and changes for it --- .../baeldung/methodinjections/AppConfig.java | 10 +++++ .../com/baeldung/methodinjections/Grader.java | 19 ++++++++ .../methodinjections/SchoolNotification.java | 45 +++++++++++++++++++ .../baeldung/methodinjections/Student.java | 27 +++++++++++ .../methodinjections/StudentServices.java | 21 +++++++++ spring-core/src/main/resources/beans.xml | 15 +++++++ .../methodinjections/StudentTest.java | 31 +++++++++++++ 7 files changed, 168 insertions(+) create mode 100644 spring-core/src/main/java/com/baeldung/methodinjections/AppConfig.java create mode 100644 spring-core/src/main/java/com/baeldung/methodinjections/Grader.java create mode 100644 spring-core/src/main/java/com/baeldung/methodinjections/SchoolNotification.java create mode 100644 spring-core/src/main/java/com/baeldung/methodinjections/Student.java create mode 100644 spring-core/src/main/java/com/baeldung/methodinjections/StudentServices.java create mode 100644 spring-core/src/main/resources/beans.xml create mode 100644 spring-core/src/test/java/com/baeldung/methodinjections/StudentTest.java diff --git a/spring-core/src/main/java/com/baeldung/methodinjections/AppConfig.java b/spring-core/src/main/java/com/baeldung/methodinjections/AppConfig.java new file mode 100644 index 0000000000..7c1e209383 --- /dev/null +++ b/spring-core/src/main/java/com/baeldung/methodinjections/AppConfig.java @@ -0,0 +1,10 @@ +package com.baeldung.methodinjections; + +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; + +@Configuration +@ComponentScan(basePackages = "com.baeldung.methodinjections") + +public class AppConfig { +} diff --git a/spring-core/src/main/java/com/baeldung/methodinjections/Grader.java b/spring-core/src/main/java/com/baeldung/methodinjections/Grader.java new file mode 100644 index 0000000000..10dc77484c --- /dev/null +++ b/spring-core/src/main/java/com/baeldung/methodinjections/Grader.java @@ -0,0 +1,19 @@ +package com.baeldung.methodinjections; + +import java.util.Collection; + +import org.springframework.stereotype.Component; + +@Component +public class Grader { + + public String grade(Collection marks) { + + boolean result = marks.stream() + .anyMatch(mark -> mark < 45); + if (result) { + return "FAIL"; + } + return "PASS"; + } +} diff --git a/spring-core/src/main/java/com/baeldung/methodinjections/SchoolNotification.java b/spring-core/src/main/java/com/baeldung/methodinjections/SchoolNotification.java new file mode 100644 index 0000000000..752eb8893f --- /dev/null +++ b/spring-core/src/main/java/com/baeldung/methodinjections/SchoolNotification.java @@ -0,0 +1,45 @@ +package com.baeldung.methodinjections; + +import java.util.ArrayList; +import java.util.Collection; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.config.ConfigurableBeanFactory; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; + +@Component("schoolNotification") +@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) +public class SchoolNotification { + @Autowired + Grader grader; + + private String name; + private Collection marks; + + public SchoolNotification(String name) { + this.name = name; + this.marks = new ArrayList(); + } + + public String addMark(Integer mark) { + this.marks.add(mark); + return this.grader.grade(this.marks); + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Collection getMarks() { + return marks; + } + + public void setMarks(Collection marks) { + this.marks = marks; + } +} diff --git a/spring-core/src/main/java/com/baeldung/methodinjections/Student.java b/spring-core/src/main/java/com/baeldung/methodinjections/Student.java new file mode 100644 index 0000000000..ceeebc3d0d --- /dev/null +++ b/spring-core/src/main/java/com/baeldung/methodinjections/Student.java @@ -0,0 +1,27 @@ +package com.baeldung.methodinjections; + +import org.springframework.beans.factory.annotation.Lookup; +import org.springframework.stereotype.Component; + +@Component("studentBean") +public class Student { + + private String id; + + /** + * Injects a prototype bean SchoolNotification into Singleton student + */ + @Lookup + public SchoolNotification getNotification(String name) { + // spring overrides and returns a SchoolNotification instance + return null; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } +} diff --git a/spring-core/src/main/java/com/baeldung/methodinjections/StudentServices.java b/spring-core/src/main/java/com/baeldung/methodinjections/StudentServices.java new file mode 100644 index 0000000000..20d631b120 --- /dev/null +++ b/spring-core/src/main/java/com/baeldung/methodinjections/StudentServices.java @@ -0,0 +1,21 @@ +package com.baeldung.methodinjections; + +import java.util.HashMap; +import java.util.Map; + +import org.springframework.beans.factory.annotation.Lookup; +import org.springframework.stereotype.Component; + +@Component("studentService") +public abstract class StudentServices { + + private Map notes = new HashMap<>(); + + @Lookup + protected abstract SchoolNotification getNotification(String name); + + public String appendMark(String name, Integer mark) { + SchoolNotification notification = notes.computeIfAbsent(name, exists -> getNotification(name)); + return notification.addMark(mark); + } +} diff --git a/spring-core/src/main/resources/beans.xml b/spring-core/src/main/resources/beans.xml new file mode 100644 index 0000000000..4002fa63bd --- /dev/null +++ b/spring-core/src/main/resources/beans.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/spring-core/src/test/java/com/baeldung/methodinjections/StudentTest.java b/spring-core/src/test/java/com/baeldung/methodinjections/StudentTest.java new file mode 100644 index 0000000000..8c04ef472e --- /dev/null +++ b/spring-core/src/test/java/com/baeldung/methodinjections/StudentTest.java @@ -0,0 +1,31 @@ +package com.baeldung.methodinjections; + +import org.junit.Assert; +import org.junit.Test; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +public class StudentTest { + + @Test + public void whenLookupMethodCalled_thenNewInstanceReturned() { + AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class); + Student student1 = context.getBean("studentBean", Student.class); + Student student2 = context.getBean("studentBean", Student.class); + + Assert.assertEquals(student1, student2); + Assert.assertNotEquals(student1.getNotification("Alex"), student2.getNotification("Bethany")); + context.close(); + } + + @Test + public void whenAbstractGetterMethodInjects_thenNewInstanceReturned() { + ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("beans.xml"); + StudentServices services = context.getBean("studentServices", StudentServices.class); + + Assert.assertEquals("PASS", services.appendMark("Alex", 76)); + Assert.assertEquals("FAIL", services.appendMark("Bethany", 44)); + Assert.assertEquals("PASS", services.appendMark("Claire", 96)); + context.close(); + } +} From 72b5ac265cc32929de64971cd6c5d3a03f36684c Mon Sep 17 00:00:00 2001 From: tamasradu Date: Mon, 16 Apr 2018 17:38:24 +0300 Subject: [PATCH 31/36] Updated unit test to use assertj (#4025) --- .../netty/EmbeddedChannelUnitTest.java | 122 ++++++++---------- 1 file changed, 56 insertions(+), 66 deletions(-) diff --git a/libraries/src/test/java/com/baeldung/netty/EmbeddedChannelUnitTest.java b/libraries/src/test/java/com/baeldung/netty/EmbeddedChannelUnitTest.java index 8a324ebc72..ca723a7b7f 100644 --- a/libraries/src/test/java/com/baeldung/netty/EmbeddedChannelUnitTest.java +++ b/libraries/src/test/java/com/baeldung/netty/EmbeddedChannelUnitTest.java @@ -1,11 +1,10 @@ package com.baeldung.netty; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - import java.nio.charset.Charset; -import org.junit.Assert; +import static org.assertj.core.api.Assertions.*; + +import org.assertj.core.api.Assertions; import org.junit.Test; import io.netty.channel.embedded.EmbeddedChannel; @@ -17,91 +16,82 @@ import io.netty.handler.codec.http.HttpResponseStatus; import io.netty.handler.codec.http.HttpVersion; public class EmbeddedChannelUnitTest { - + @Test public void givenTwoChannelHandlers_testPipeline() { - - final FullHttpRequest httpRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/calculate?a=10&b=5"); - httpRequest.headers().add("Operator", "Add"); - EmbeddedChannel channel = new EmbeddedChannel( - new HttpMessageHandler(), new CalculatorOperationHandler()); - - channel.pipeline() - .addFirst(new HttpMessageHandler()) - .addLast(new CalculatorOperationHandler()); + final FullHttpRequest httpRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, + "/calculate?a=10&b=5"); + httpRequest.headers().add("Operator", "Add"); + EmbeddedChannel channel = new EmbeddedChannel(new HttpMessageHandler(), new CalculatorOperationHandler()); - // send HTTP request to server and check that the message is on the inbound pipeline - assertTrue(channel.writeInbound(httpRequest)); + channel.pipeline().addFirst(new HttpMessageHandler()).addLast(new CalculatorOperationHandler()); - long inboundChannelResponse = channel.readInbound(); - assertEquals(15, inboundChannelResponse); + // send HTTP request to server and check that the message is on the inbound pipeline + assertThat(channel.writeInbound(httpRequest)).isTrue(); - // we should have an outbound message in the form of a HTTP response - assertEquals(1, channel.outboundMessages().size()); - // Object response = channel.readOutbound(); + long inboundChannelResponse = channel.readInbound(); + assertThat(inboundChannelResponse).isEqualTo(15); - FullHttpResponse httpResponse = channel.readOutbound(); - String httpResponseContent = httpResponse.content().toString(Charset.defaultCharset()); - assertTrue("15".equalsIgnoreCase(httpResponseContent)); + // we should have an outbound message in the form of a HTTP response + assertThat(channel.outboundMessages().size()).isEqualTo(1); + // Object response = channel.readOutbound(); + + FullHttpResponse httpResponse = channel.readOutbound(); + String httpResponseContent = httpResponse.content().toString(Charset.defaultCharset()); + assertThat(httpResponseContent).isEqualTo("15"); } - + @Test public void givenTwoChannelHandlers_testExceptionHandlingInHttpMessageHandler() { - - EmbeddedChannel channel = new EmbeddedChannel( - new HttpMessageHandler(), new CalculatorOperationHandler()); - final FullHttpRequest wrongHttpRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/calculate?a=10&b=5"); - wrongHttpRequest.headers().add("Operator", "Add"); + EmbeddedChannel channel = new EmbeddedChannel(new HttpMessageHandler(), new CalculatorOperationHandler()); - try { - // send invalid HTTP request to server and expect and error - channel.pipeline().fireChannelRead(wrongHttpRequest); - channel.checkException(); - // channel.writeInbound(wrongHttpRequest); - Assert.fail(); + final FullHttpRequest wrongHttpRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, + "/calculate?a=10&b=5"); + wrongHttpRequest.headers().add("Operator", "Add"); - } catch (Exception ex) { + Throwable thrownException = catchThrowable(() -> { + // send invalid HTTP request to server and expect and error + channel.pipeline().fireChannelRead(wrongHttpRequest); + channel.checkException(); + Assertions.failBecauseExceptionWasNotThrown(UnsupportedOperationException.class); + }); - // the HttpMessageHandler does not handle the exception and throws it down the pipeline - assertTrue(ex instanceof UnsupportedOperationException); - assertTrue(ex.getMessage().equalsIgnoreCase("HTTP method not supported")); + assertThat(thrownException) + .isInstanceOf(UnsupportedOperationException.class) + .hasMessage("HTTP method not supported"); - FullHttpResponse errorHttpResponse = channel.readOutbound(); - String errorHttpResponseContent = errorHttpResponse.content().toString(Charset.defaultCharset()); - assertTrue("Operation not defined".equalsIgnoreCase(errorHttpResponseContent)); - assertEquals(HttpResponseStatus.INTERNAL_SERVER_ERROR, errorHttpResponse.status()); - } + FullHttpResponse errorHttpResponse = channel.readOutbound(); + String errorHttpResponseContent = errorHttpResponse.content().toString(Charset.defaultCharset()); + assertThat(errorHttpResponseContent).isEqualToIgnoringCase("Operation not defined"); + assertThat(errorHttpResponse.status()).isEqualTo(HttpResponseStatus.INTERNAL_SERVER_ERROR); } - - + @Test public void givenTwoChannelHandlers_testExceptionHandlingInCalculatorOperationHandler() { - EmbeddedChannel channel = new EmbeddedChannel( - new HttpMessageHandler(), new CalculatorOperationHandler()); + EmbeddedChannel channel = new EmbeddedChannel(new HttpMessageHandler(), new CalculatorOperationHandler()); - final FullHttpRequest wrongHttpRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/calculate?a=10&b=5"); - wrongHttpRequest.headers().add("Operator", "Invalid_operation"); + final FullHttpRequest wrongHttpRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, + "/calculate?a=10&b=5"); + wrongHttpRequest.headers().add("Operator", "Invalid_operation"); - try { - // send invalid HTTP request to server and expect and error - channel.writeInbound(wrongHttpRequest); - Assert.fail(); + Throwable thrownException = catchThrowable(() -> { + // send invalid HTTP request to server and expect and error + channel.writeInbound(wrongHttpRequest); + Assertions.failBecauseExceptionWasNotThrown(IllegalArgumentException.class); + }); - } catch (Exception ex) { + // the HttpMessageHandler does not handle the exception and throws it down the + // pipeline + assertThat(thrownException).isInstanceOf(IllegalArgumentException.class).hasMessage("Operation not defined"); - // the HttpMessageHandler does not handle the exception and throws it down the pipeline - assertTrue(ex instanceof IllegalArgumentException); - assertTrue(ex.getMessage().equalsIgnoreCase("Operation not defined")); - - // the outbound message is a HTTP response with the status code 500 - FullHttpResponse errorHttpResponse = channel.readOutbound(); - String errorHttpResponseContent = errorHttpResponse.content().toString(Charset.defaultCharset()); - assertTrue("Operation not defined".equalsIgnoreCase(errorHttpResponseContent)); - assertEquals(HttpResponseStatus.INTERNAL_SERVER_ERROR, errorHttpResponse.status()); - } + // the outbound message is a HTTP response with the status code 500 + FullHttpResponse errorHttpResponse = channel.readOutbound(); + String errorHttpResponseContent = errorHttpResponse.content().toString(Charset.defaultCharset()); + assertThat(errorHttpResponseContent).isEqualToIgnoringCase("Operation not defined"); + assertThat(errorHttpResponse.status()).isEqualTo(HttpResponseStatus.INTERNAL_SERVER_ERROR); } } From c32bbe3be776add922ef0ec5c4e27ceaf1d5e2d6 Mon Sep 17 00:00:00 2001 From: Jorge Date: Mon, 16 Apr 2018 21:09:15 +0200 Subject: [PATCH 32/36] [Bael 1687] - Spring Data Reactive Mongo DB microservice in Kotlin (#3993) * [BAEL-1641] Find all pairs of numbers in an array that add up to a given sum * Commiting editor's suggested changes * Commiting article Spring Data Reactive Mongo DB microservice in Kotlin * Revert commit for BAEL 1687 - Moving those files to a new branch * [BAEL-1687] - Real-time data streaming using Reactive MongoDB and Kotlin * Reverting changes [BAEL-1641] - Not from this branch * [BAEL-1687] - Code Peer Review - Added suggested changes --- spring-data-5-reactive/pom.xml | 124 ++++++++++++++++++ .../main/kotlin/com/baeldung/Application.kt | 12 ++ .../src/main/kotlin/com/baeldung/Event.kt | 6 + .../kotlin/com/baeldung/EventRepository.kt | 5 + .../main/kotlin/com/baeldung/MongoConfig.kt | 33 +++++ .../main/kotlin/com/baeldung/SendEmitter.kt | 43 ++++++ .../src/main/resources/static/index.html | 33 +++++ 7 files changed, 256 insertions(+) create mode 100644 spring-data-5-reactive/pom.xml create mode 100644 spring-data-5-reactive/src/main/kotlin/com/baeldung/Application.kt create mode 100644 spring-data-5-reactive/src/main/kotlin/com/baeldung/Event.kt create mode 100644 spring-data-5-reactive/src/main/kotlin/com/baeldung/EventRepository.kt create mode 100644 spring-data-5-reactive/src/main/kotlin/com/baeldung/MongoConfig.kt create mode 100644 spring-data-5-reactive/src/main/kotlin/com/baeldung/SendEmitter.kt create mode 100644 spring-data-5-reactive/src/main/resources/static/index.html diff --git a/spring-data-5-reactive/pom.xml b/spring-data-5-reactive/pom.xml new file mode 100644 index 0000000000..85d025bd9c --- /dev/null +++ b/spring-data-5-reactive/pom.xml @@ -0,0 +1,124 @@ + + + 4.0.0 + + com.baeldung + spring-5-data-reactive + 0.0.1-SNAPSHOT + jar + + Spring-5-data-reactive + Spring-5-data-reactive with Springboot 2.0.1 + + + org.springframework.boot + spring-boot-starter-parent + 2.0.1.RELEASE + + + + + UTF-8 + UTF-8 + 1.8 + 1.2.20 + + + + + org.springframework.boot + spring-boot-starter-data-mongodb-reactive + + + org.springframework.boot + spring-boot-starter-web + + + javax.ws.rs + javax.ws.rs-api + 2.1 + + + com.fasterxml.jackson.module + jackson-module-kotlin + + + org.jetbrains.kotlin + kotlin-stdlib-jdk8 + + + org.jetbrains.kotlin + kotlin-reflect + + + org.projectlombok + lombok + + + io.projectreactor + reactor-test + test + + + org.jetbrains.kotlin + kotlin-stdlib-jdk8 + ${kotlin.version} + + + + + + spring-libs-snapshot + Spring Snapshot Repository + http://repo.spring.io/libs-snapshot + + + + + src/main/kotlin + + + org.springframework.boot + spring-boot-maven-plugin + + + kotlin-maven-plugin + ${kotlin.version} + + + compile + compile + + compile + + + + test-compile + test-compile + + test-compile + + + + org.jetbrains.kotlin + + + -Xjsr305=strict + + + spring + + 1.8 + + + + org.jetbrains.kotlin + kotlin-maven-allopen + ${kotlin.version} + + + + + + diff --git a/spring-data-5-reactive/src/main/kotlin/com/baeldung/Application.kt b/spring-data-5-reactive/src/main/kotlin/com/baeldung/Application.kt new file mode 100644 index 0000000000..b21dd6bfb5 --- /dev/null +++ b/spring-data-5-reactive/src/main/kotlin/com/baeldung/Application.kt @@ -0,0 +1,12 @@ +package org.jetbrains.kotlin.demo + +import org.springframework.boot.SpringApplication +import org.springframework.boot.autoconfigure.SpringBootApplication + +@SpringBootApplication +class Application + +fun main(args: Array) { + SpringApplication.run(Application::class.java, *args) +} + diff --git a/spring-data-5-reactive/src/main/kotlin/com/baeldung/Event.kt b/spring-data-5-reactive/src/main/kotlin/com/baeldung/Event.kt new file mode 100644 index 0000000000..17fa9699a8 --- /dev/null +++ b/spring-data-5-reactive/src/main/kotlin/com/baeldung/Event.kt @@ -0,0 +1,6 @@ +package com.baeldung + +import org.springframework.data.mongodb.core.mapping.Document + +@Document +data class Event(val id: String, val name: String) diff --git a/spring-data-5-reactive/src/main/kotlin/com/baeldung/EventRepository.kt b/spring-data-5-reactive/src/main/kotlin/com/baeldung/EventRepository.kt new file mode 100644 index 0000000000..33d4b85a93 --- /dev/null +++ b/spring-data-5-reactive/src/main/kotlin/com/baeldung/EventRepository.kt @@ -0,0 +1,5 @@ +package com.baeldung + +import org.springframework.data.mongodb.repository.ReactiveMongoRepository + +interface EventRepository : ReactiveMongoRepository diff --git a/spring-data-5-reactive/src/main/kotlin/com/baeldung/MongoConfig.kt b/spring-data-5-reactive/src/main/kotlin/com/baeldung/MongoConfig.kt new file mode 100644 index 0000000000..a45a630f38 --- /dev/null +++ b/spring-data-5-reactive/src/main/kotlin/com/baeldung/MongoConfig.kt @@ -0,0 +1,33 @@ +package com.baeldung + +import com.mongodb.reactivestreams.client.MongoClient +import com.mongodb.reactivestreams.client.MongoClients +import org.springframework.context.annotation.Bean +import org.springframework.context.annotation.Configuration +import org.springframework.data.mongodb.config.AbstractReactiveMongoConfiguration +import org.springframework.data.mongodb.core.ReactiveMongoTemplate +import org.springframework.data.mongodb.repository.config.EnableReactiveMongoRepositories + + +@Configuration +@EnableReactiveMongoRepositories(basePackageClasses = arrayOf(EventRepository::class)) +class MongoConfig : AbstractReactiveMongoConfiguration() { + + override fun reactiveMongoClient(): com.mongodb.reactivestreams.client.MongoClient { + return mongoClient() + } + + @Bean + fun mongoClient(): MongoClient { + return MongoClients.create() + } + + override fun getDatabaseName(): String { + return "mongoDatabase" + } + + @Bean + override fun reactiveMongoTemplate(): ReactiveMongoTemplate { + return ReactiveMongoTemplate(mongoClient(), databaseName) + } +} diff --git a/spring-data-5-reactive/src/main/kotlin/com/baeldung/SendEmitter.kt b/spring-data-5-reactive/src/main/kotlin/com/baeldung/SendEmitter.kt new file mode 100644 index 0000000000..bc879e10df --- /dev/null +++ b/spring-data-5-reactive/src/main/kotlin/com/baeldung/SendEmitter.kt @@ -0,0 +1,43 @@ +package com.baeldung + +import org.springframework.web.bind.annotation.GetMapping +import org.springframework.web.bind.annotation.RequestParam +import org.springframework.web.bind.annotation.RestController +import org.springframework.web.servlet.mvc.method.annotation.SseEmitter +import reactor.core.publisher.Flux +import reactor.core.publisher.Mono +import java.util.* +import javax.ws.rs.core.MediaType + + +@RestController +class SendEmitter(val eventRepository: EventRepository) { + + private var emitter = SseEmitter() + + /** + * Save and send an SSE to all subscribed clients + */ + @GetMapping("/saveEvent") + fun executeExample(@RequestParam("eventName") eventName: String): Flux { + // Create new event + var event = Event(UUID.randomUUID().toString(), eventName) + // Save event + var stream = eventRepository.saveAll(Mono.just(event)) + // Send event + emitter.send(SseEmitter.event().data(event)) + // Return SSE + return stream + } + + /** + * Receive SSEs + */ + @GetMapping(value = "/receiveChanges") + fun handle(): SseEmitter { + // Create new emitter + this.emitter = SseEmitter() + // Return SSE + return emitter + } +} diff --git a/spring-data-5-reactive/src/main/resources/static/index.html b/spring-data-5-reactive/src/main/resources/static/index.html new file mode 100644 index 0000000000..8fbb3b6b05 --- /dev/null +++ b/spring-data-5-reactive/src/main/resources/static/index.html @@ -0,0 +1,33 @@ + + + +
+ + +
+ + + +
+ + + + From d7eaa0080402a23d625867a92a010b454895bea2 Mon Sep 17 00:00:00 2001 From: pauljervis Date: Tue, 17 Apr 2018 13:09:34 +0100 Subject: [PATCH 33/36] Bael 1601 kotlin (#4016) * add article files * update kotlin version in pom * IntelliJ added binary folder to all the .gitignores * IntelliJ added binary folder to all the .gitignores * update test function names * Expand tests and add more code for more meaningful content within the article. Remove core-kotlin from parent pom again for eclipse to work. * adjust for issues with custom-pmd * rename test * Revert "IntelliJ added binary folder to all the .gitignores" This reverts commit 0850a2acd5162499540231146c795cfda9ffcfc5. * Revert "IntelliJ added binary folder to all the .gitignores" This reverts commit 2b17cf2ff3624ecbe37f07bb9985ecfd3a977e01. --- core-kotlin/.gitignore | 1 + core-kotlin/pom.xml | 23 +++--- .../kotlin/com/baeldung/filter/ChunkedTest.kt | 39 ++++++++++ .../com/baeldung/filter/DistinctTest.kt | 71 +++++++++++++++++++ .../kotlin/com/baeldung/filter/DropTest.kt | 53 ++++++++++++++ .../kotlin/com/baeldung/filter/FilterTest.kt | 39 ++++++++++ .../kotlin/com/baeldung/filter/SliceTest.kt | 44 ++++++++++++ .../kotlin/com/baeldung/filter/TakeTest.kt | 38 ++++++++++ pom.xml | 1 + 9 files changed, 298 insertions(+), 11 deletions(-) create mode 100644 core-kotlin/.gitignore create mode 100644 core-kotlin/src/test/kotlin/com/baeldung/filter/ChunkedTest.kt create mode 100644 core-kotlin/src/test/kotlin/com/baeldung/filter/DistinctTest.kt create mode 100644 core-kotlin/src/test/kotlin/com/baeldung/filter/DropTest.kt create mode 100644 core-kotlin/src/test/kotlin/com/baeldung/filter/FilterTest.kt create mode 100644 core-kotlin/src/test/kotlin/com/baeldung/filter/SliceTest.kt create mode 100644 core-kotlin/src/test/kotlin/com/baeldung/filter/TakeTest.kt diff --git a/core-kotlin/.gitignore b/core-kotlin/.gitignore new file mode 100644 index 0000000000..ae3c172604 --- /dev/null +++ b/core-kotlin/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/core-kotlin/pom.xml b/core-kotlin/pom.xml index 36298ca084..6c729d5688 100644 --- a/core-kotlin/pom.xml +++ b/core-kotlin/pom.xml @@ -21,6 +21,11 @@ + + org.apache.commons + commons-math3 + ${commons-math3.version} + org.junit.jupiter junit-jupiter-engine @@ -33,12 +38,6 @@ ${junit.platform.version} test - - junit - junit - ${junit4.version} - test - org.jetbrains.kotlin kotlin-stdlib @@ -46,7 +45,7 @@ org.jetbrains.kotlin - kotlin-stdlib-jre8 + kotlin-stdlib-jdk8 ${kotlin-stdlib.version} @@ -194,14 +193,16 @@ UTF-8 - 1.1.2 - 1.1.2 - 1.1.2 - 1.1.2 + 1.2.31 + 1.2.31 + 1.2.31 + 1.2.31 0.15 1.5.0 4.1.0 + 3.6.1 + 5.0.0 1.0.0 4.12.0 diff --git a/core-kotlin/src/test/kotlin/com/baeldung/filter/ChunkedTest.kt b/core-kotlin/src/test/kotlin/com/baeldung/filter/ChunkedTest.kt new file mode 100644 index 0000000000..20797cc633 --- /dev/null +++ b/core-kotlin/src/test/kotlin/com/baeldung/filter/ChunkedTest.kt @@ -0,0 +1,39 @@ +package com.baeldung.filter + +import org.junit.jupiter.api.Assertions.assertIterableEquals +import org.junit.jupiter.api.Test + +internal class ChunkedTest { + + @Test + fun givenDNAFragmentString_whenChunking_thenProduceListOfChunks() { + val dnaFragment = "ATTCGCGGCCGCCAA" + + val fragments = dnaFragment.chunked(3) + + assertIterableEquals(listOf("ATT", "CGC", "GGC", "CGC", "CAA"), fragments) + } + + @Test + fun givenDNAString_whenChunkingWithTransformer_thenProduceTransformedList() { + val codonTable = mapOf("ATT" to "Isoleucine", "CAA" to "Glutamine", "CGC" to "Arginine", "GGC" to "Glycine") + val dnaFragment = "ATTCGCGGCCGCCAA" + + val proteins = dnaFragment.chunked(3) { codon -> + codonTable[codon.toString()] ?: error("Unknown codon") + } + + assertIterableEquals(listOf("Isoleucine", "Arginine", "Glycine", "Arginine", "Glutamine"), proteins) + } + + @Test + fun givenListOfValues_whenChunking_thenProduceListOfArrays() { + val whole = listOf(1, 4, 7, 4753, 2, 34, 62, 76, 5868, 0) + val chunks = whole.chunked(6) + + val expected = listOf(listOf(1, 4, 7, 4753, 2, 34), listOf(62, 76, 5868, 0)) + + assertIterableEquals(expected, chunks) + } + +} \ No newline at end of file diff --git a/core-kotlin/src/test/kotlin/com/baeldung/filter/DistinctTest.kt b/core-kotlin/src/test/kotlin/com/baeldung/filter/DistinctTest.kt new file mode 100644 index 0000000000..4e445af536 --- /dev/null +++ b/core-kotlin/src/test/kotlin/com/baeldung/filter/DistinctTest.kt @@ -0,0 +1,71 @@ +package com.baeldung.filter + +import org.junit.jupiter.api.Assertions.assertIterableEquals +import org.junit.jupiter.api.Test + +internal class DistinctTest { + data class SmallClass(val key: String, val num: Int) + + @Test + fun givenArrayOfSomeDuplicateValues_whenApplyingDistinct_thenReturnListOfNoDuplicateValues() { + val array = arrayOf(1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 5, 6, 7, 8, 9) + val result = array.distinct() + val expected = listOf(1, 2, 3, 4, 5, 6, 7, 8, 9) + + assertIterableEquals(expected, result) + } + + @Test + fun givenArrayOfClassObjects_whenApplyingDistinctOnClassProperty_thenReturnListDistinctOnThatValue() { + + val original = arrayOf( + SmallClass("key1", 1), + SmallClass("key2", 2), + SmallClass("key3", 3), + SmallClass("key4", 3), + SmallClass("er", 9), + SmallClass("er", 10), + SmallClass("er", 11)) + + val actual = original.distinctBy { it.key } + + val expected = listOf( + SmallClass("key1", 1), + SmallClass("key2", 2), + SmallClass("key3", 3), + SmallClass("key4", 3), + SmallClass("er", 9)) + + + assertIterableEquals(expected, actual) + } + + @Test + fun givenArrayOfClassObjects_whenApplyingComplicatedSelector_thenReturnFirstElementToMatchEachSelectorValue() { + val array = arrayOf( + SmallClass("key1", 1), + SmallClass("key2", 2), + SmallClass("key3", 3), + SmallClass("key4", 3), + SmallClass("er", 9), + SmallClass("er", 10), + SmallClass("er", 11), + SmallClass("er", 11), + SmallClass("er", 91), + SmallClass("blob", 22), + SmallClass("dob", 27), + SmallClass("high", 201_434_314)) + + val actual = array.distinctBy { Math.floor(it.num / 10.0) } + + val expected = listOf( + SmallClass("key1", 1), + SmallClass("er", 10), + SmallClass("er", 91), + SmallClass("blob", 22), + SmallClass("high", 201_434_314)) + + assertIterableEquals(expected, actual) + } + +} \ No newline at end of file diff --git a/core-kotlin/src/test/kotlin/com/baeldung/filter/DropTest.kt b/core-kotlin/src/test/kotlin/com/baeldung/filter/DropTest.kt new file mode 100644 index 0000000000..7c2685f39b --- /dev/null +++ b/core-kotlin/src/test/kotlin/com/baeldung/filter/DropTest.kt @@ -0,0 +1,53 @@ +package com.baeldung.filter + +import org.junit.jupiter.api.Assertions.assertIterableEquals +import org.junit.jupiter.api.Test + +internal class DropTest { + + @Test + fun whenDroppingFirstTwoItemsOfArray_thenTwoLess() { + val array = arrayOf(1, 2, 3, 4) + val result = array.drop(2) + val expected = listOf(3, 4) + + assertIterableEquals(expected, result) + } + + @Test + fun whenDroppingMoreItemsOfArray_thenEmptyList() { + val array = arrayOf(1, 2, 3, 4) + val result = array.drop(5) + val expected = listOf() + + assertIterableEquals(expected, result) + } + + @Test + fun givenArray_whenDroppingLastElement_thenReturnListWithoutLastElement() { + val array = arrayOf("1", "2", "3", "4") + val result = array.dropLast(1) + val expected = listOf("1", "2", "3") + + assertIterableEquals(expected, result) + } + + @Test + fun givenArrayOfFloats_whenDroppingLastUntilPredicateIsFalse_thenReturnSubsetListOfFloats() { + val array = arrayOf(1f, 1f, 1f, 1f, 1f, 2f, 1f, 1f, 1f) + val result = array.dropLastWhile { it == 1f } + val expected = listOf(1f, 1f, 1f, 1f, 1f, 2f) + + assertIterableEquals(expected, result) + } + + @Test + fun givenList_whenDroppingMoreThanAvailable_thenThrowException() { + val list = listOf('a', 'e', 'i', 'o', 'u') + val result = list.drop(6) + val expected: List = listOf() + + assertIterableEquals(expected, result) + } + +} \ No newline at end of file diff --git a/core-kotlin/src/test/kotlin/com/baeldung/filter/FilterTest.kt b/core-kotlin/src/test/kotlin/com/baeldung/filter/FilterTest.kt new file mode 100644 index 0000000000..efe6354f25 --- /dev/null +++ b/core-kotlin/src/test/kotlin/com/baeldung/filter/FilterTest.kt @@ -0,0 +1,39 @@ +package com.baeldung.filter + +import org.apache.commons.math3.primes.Primes +import org.junit.jupiter.api.Assertions.assertIterableEquals +import org.junit.jupiter.api.Test +import kotlin.test.assertTrue + +internal class FilterTest { + + @Test + fun givenAscendingValueMap_whenFilteringOnValue_ThenReturnSubsetOfMap() { + val originalMap = mapOf("key1" to 1, "key2" to 2, "key3" to 3) + val filteredMap = originalMap.filter { it.value < 2 } + val expectedMap = mapOf("key1" to 1) + + assertTrue { expectedMap == filteredMap } + } + + @Test + fun givenSeveralCollections_whenFilteringToAccumulativeList_thenListContainsAllContents() { + val array1 = arrayOf(90, 92, 93, 94, 92, 95, 93) + val array2 = sequenceOf(51, 31, 83, 674_506_111, 256_203_161, 15_485_863) + val list1 = listOf(0, 1, 2, 3, 4, 5, 6, 7, 8, 9) + val primes = mutableListOf() + + val expected = listOf(2, 3, 5, 7, 31, 83, 15_485_863, 256_203_161, 674_506_111) + + val primeCheck = { num: Int -> Primes.isPrime(num) } + + array1.filterTo(primes, primeCheck) + list1.filterTo(primes, primeCheck) + array2.filterTo(primes, primeCheck) + + primes.sort() + + assertIterableEquals(expected, primes) + } + +} \ No newline at end of file diff --git a/core-kotlin/src/test/kotlin/com/baeldung/filter/SliceTest.kt b/core-kotlin/src/test/kotlin/com/baeldung/filter/SliceTest.kt new file mode 100644 index 0000000000..dca167928d --- /dev/null +++ b/core-kotlin/src/test/kotlin/com/baeldung/filter/SliceTest.kt @@ -0,0 +1,44 @@ +package com.baeldung.filter + +import org.junit.jupiter.api.Assertions.assertIterableEquals +import org.junit.jupiter.api.Assertions.assertThrows +import org.junit.jupiter.api.Test + +internal class SliceTest { + + @Test + fun whenSlicingAnArrayWithDotRange_ThenListEqualsTheSlice() { + val original = arrayOf(1, 2, 3, 2, 1) + val actual = original.slice(1..3) + val expected = listOf(2, 3, 2) + + assertIterableEquals(expected, actual) + } + + @Test + fun whenSlicingAnArrayWithDownToRange_thenListMadeUpOfReverseSlice() { + val original = arrayOf(1, 2, 3, 2, 1) + val actual = original.slice(3 downTo 0) + val expected = listOf(2, 3, 2, 1) + + assertIterableEquals(expected, actual) + } + + @Test + fun whenSlicingBeyondTheRangeOfTheArray_thenContainManyNulls() { + val original = arrayOf(12, 3, 34, 4) + val actual = original.slice(3..8) + val expected = listOf(4, null, null, null, null, null) + + assertIterableEquals(expected, actual) + } + + @Test + fun whenSlicingBeyondRangeOfArrayWithStep_thenOutOfBoundsException() { + assertThrows(ArrayIndexOutOfBoundsException::class.java) { + val original = arrayOf(12, 3, 34, 4) + original.slice(3..8 step 2) + } + } + +} \ No newline at end of file diff --git a/core-kotlin/src/test/kotlin/com/baeldung/filter/TakeTest.kt b/core-kotlin/src/test/kotlin/com/baeldung/filter/TakeTest.kt new file mode 100644 index 0000000000..d021177de8 --- /dev/null +++ b/core-kotlin/src/test/kotlin/com/baeldung/filter/TakeTest.kt @@ -0,0 +1,38 @@ +package com.baeldung.filter + +import org.junit.jupiter.api.Assertions.assertIterableEquals +import org.junit.jupiter.api.Test + +internal class TakeTest { + + @Test + fun `given array of alternating types, when predicating on 'is String', then produce list of array up until predicate is false`() { + val originalArray = arrayOf("val1", 2, "val3", 4, "val5", 6) + val actualList = originalArray.takeWhile { it is String } + val expectedList = listOf("val1") + + assertIterableEquals(expectedList, actualList) + } + + @Test + fun `given array of alternating types, when taking 4 items, then produce list of first 4 items`() { + val originalArray = arrayOf("val1", 2, "val3", 4, "val5", 6) + val actualList = originalArray.take(4) + val expectedList = listOf("val1", 2, "val3", 4) + + println(originalArray.drop(4)) + println(actualList) + + assertIterableEquals(expectedList, actualList) + } + + @Test + fun `when taking more items than available, then return all elements`() { + val originalArray = arrayOf(1, 2) + val actual = originalArray.take(10) + val expected = listOf(1, 2) + + assertIterableEquals(expected, actual) + } + +} \ No newline at end of file diff --git a/pom.xml b/pom.xml index 64744eb2da..f0cb72e4d0 100644 --- a/pom.xml +++ b/pom.xml @@ -64,6 +64,7 @@ core-java core-java-io core-java-8 + core-groovy core-java-concurrency From ce5113c48c75fec6a372381293b70feb3e63b24d Mon Sep 17 00:00:00 2001 From: pauljervis Date: Tue, 17 Apr 2018 16:37:14 +0100 Subject: [PATCH 34/36] Bael 1404 kotlin (#4033) * add article files * update kotlin version in pom * IntelliJ added binary folder to all the .gitignores * IntelliJ added binary folder to all the .gitignores * update test function names * Expand tests and add more code for more meaningful content within the article. Remove core-kotlin from parent pom again for eclipse to work. * adjust for issues with custom-pmd * rename test * Revert "IntelliJ added binary folder to all the .gitignores" This reverts commit 0850a2acd5162499540231146c795cfda9ffcfc5. * Revert "IntelliJ added binary folder to all the .gitignores" This reverts commit 2b17cf2ff3624ecbe37f07bb9985ecfd3a977e01. * renamed test to match article --- core-kotlin/src/test/kotlin/com/baeldung/filter/DistinctTest.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-kotlin/src/test/kotlin/com/baeldung/filter/DistinctTest.kt b/core-kotlin/src/test/kotlin/com/baeldung/filter/DistinctTest.kt index 4e445af536..4cc6f647e1 100644 --- a/core-kotlin/src/test/kotlin/com/baeldung/filter/DistinctTest.kt +++ b/core-kotlin/src/test/kotlin/com/baeldung/filter/DistinctTest.kt @@ -7,7 +7,7 @@ internal class DistinctTest { data class SmallClass(val key: String, val num: Int) @Test - fun givenArrayOfSomeDuplicateValues_whenApplyingDistinct_thenReturnListOfNoDuplicateValues() { + fun whenApplyingDistinct_thenReturnListOfNoDuplicateValues() { val array = arrayOf(1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 5, 6, 7, 8, 9) val result = array.distinct() val expected = listOf(1, 2, 3, 4, 5, 6, 7, 8, 9) From 86cebe51d726969e47502056ea4f0bee67cfd40f Mon Sep 17 00:00:00 2001 From: amit2103 Date: Wed, 18 Apr 2018 11:34:50 +0530 Subject: [PATCH 35/36] Bael 5926 (#4023) * Added parent module on poms that have no parent defined * Removed dependency reduced pom from undertow module * Aligned and Defined the common plugins in the parents * Removed dependency-reduced-pom.xml from undertow module * Reverting test fail modules with surefire testFailureIgnore ture * Reverted wrong push with org.hsqldb --- animal-sniffer-mvn-plugin/pom.xml | 8 --- annotations/annotation-processing/pom.xml | 21 ------ apache-cxf/cxf-introduction/pom.xml | 9 --- apache-cxf/cxf-jaxrs-implementation/pom.xml | 9 --- apache-cxf/cxf-spring/pom.xml | 27 ------- apache-spark/pom.xml | 13 ---- atomix/pom.xml | 14 ---- bootique/dependency-reduced-pom.xml | 56 --------------- camel-api/pom.xml | 9 --- cas/cas-secured-app/pom.xml | 18 ----- core-groovy/pom.xml | 4 -- core-java-9/pom.xml | 7 -- core-java-io/pom.xml | 14 +--- core-java-sun/pom.xml | 25 ------- core-java/externalizable.txt | Bin 0 -> 106 bytes core-java/pom.xml | 11 --- core-java/yofile.txt | Bin 0 -> 98 bytes core-java/yofile2.txt | Bin 0 -> 275 bytes core-kotlin/pom.xml | 4 -- drools/pom.xml | 23 ------ dubbo/pom.xml | 23 ------ ejb/ejb-session-beans/pom.xml | 12 ---- geotools/pom.xml | 14 ---- guest/core-java/pom.xml | 13 ---- guest/deep-jsf/pom.xml | 11 --- guest/junit5-example/pom.xml | 8 --- guest/log4j2-example/pom.xml | 10 --- guest/logback-example/pom.xml | 14 ---- guest/memory-leaks/pom.xml | 10 --- guest/thread-pools/pom.xml | 13 ---- guest/tomcat-app/pom.xml | 8 --- guest/webservices/rest-client/pom.xml | 8 --- guest/webservices/rest-server/pom.xml | 8 --- hibernate5/pom.xml | 28 -------- java-difference-date/pom.xml | 15 ---- .../JavaEEAnnotationsSample/pom.xml | 15 ++-- jpa-storedprocedure/pom.xml | 1 - jsonb/pom.xml | 1 - libraries-data/pom.xml | 9 --- libraries/pom.xml | 10 --- linkrest/pom.xml | 8 --- mustache/pom.xml | 17 ----- .../JavaEEAnnotationsSample/pom.xml | 9 --- patterns/behavioral-patterns/pom.xml | 9 --- patterns/facade/pom.xml | 9 --- patterns/front-controller/pom.xml | 9 --- persistence-modules/liquibase/pom.xml | 10 --- .../spring-hibernate-5/pom.xml | 26 ------- resteasy/bin/pom.xml | 67 ++---------------- spring-boot-bootstrap/pom.xml | 9 --- spring-cloud/spring-cloud-aws/pom.xml | 7 +- .../spring-cloud-bootstrap/gateway/pom.xml | 18 ----- .../spring-cloud-connectors-heroku/pom.xml | 15 ---- spring-cloud/spring-cloud-consul/pom.xml | 21 ------ .../spring-cloud-contract-consumer/pom.xml | 11 --- spring-cloud/spring-cloud-eureka/pom.xml | 21 ------ .../spring-cloud-eureka-client/pom.xml | 18 ----- .../spring-cloud-eureka-feign-client/pom.xml | 18 ----- .../spring-cloud-eureka-server/pom.xml | 20 +----- spring-cloud/spring-cloud-gateway/pom.xml | 21 ------ .../feign-rest-consumer/pom.xml | 20 +----- spring-cloud/spring-cloud-hystrix/pom.xml | 21 ------ .../rest-consumer/pom.xml | 20 +----- .../rest-producer/pom.xml | 20 +----- spring-cloud/spring-cloud-stream/pom.xml | 21 ------ .../bin/eureka-client/pom.xml | 18 ----- .../bin/eureka-server/pom.xml | 19 ----- .../bin/pom.xml | 20 ------ .../bin/zuul-server/pom.xml | 17 ----- .../eureka-client/pom.xml | 18 ----- .../eureka-server/pom.xml | 18 ----- .../pom.xml | 20 ------ .../zuul-server/pom.xml | 17 ----- spring-mvc-simple/pom.xml | 7 +- spring-security-mvc-socket/pom.xml | 8 --- .../spring-swagger-codegen-api-client/pom.xml | 9 --- testing-modules/junit-5/pom.xml | 8 --- testing-modules/mockserver/pom.xml | 21 ++---- vavr/pom.xml | 23 +----- vraptor/pom.xml | 9 --- xml/pom.xml | 10 --- 81 files changed, 26 insertions(+), 1164 deletions(-) delete mode 100644 bootique/dependency-reduced-pom.xml create mode 100644 core-java/externalizable.txt create mode 100644 core-java/yofile.txt create mode 100644 core-java/yofile2.txt diff --git a/animal-sniffer-mvn-plugin/pom.xml b/animal-sniffer-mvn-plugin/pom.xml index 0fec5d0175..c2ed19b401 100644 --- a/animal-sniffer-mvn-plugin/pom.xml +++ b/animal-sniffer-mvn-plugin/pom.xml @@ -26,14 +26,6 @@ - - maven-compiler-plugin - 3.7.0 - - 1.8 - 1.8 - - org.codehaus.mojo animal-sniffer-maven-plugin diff --git a/annotations/annotation-processing/pom.xml b/annotations/annotation-processing/pom.xml index b5219d57ba..7dabe7a9a7 100644 --- a/annotations/annotation-processing/pom.xml +++ b/annotations/annotation-processing/pom.xml @@ -19,32 +19,11 @@
- com.google.auto.service auto-service ${auto-service.version} provided - - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - ${maven-compiler-plugin.version} - - 1.8 - 1.8 - - - - - - - \ No newline at end of file diff --git a/apache-cxf/cxf-introduction/pom.xml b/apache-cxf/cxf-introduction/pom.xml index 1b9ba22230..c584fcfe5b 100644 --- a/apache-cxf/cxf-introduction/pom.xml +++ b/apache-cxf/cxf-introduction/pom.xml @@ -25,15 +25,6 @@ com.baeldung.cxf.introduction.Server
- - maven-surefire-plugin - ${surefire.version} - - - **/*LiveTest.java - - -
diff --git a/apache-cxf/cxf-jaxrs-implementation/pom.xml b/apache-cxf/cxf-jaxrs-implementation/pom.xml index 981e0ef7aa..32b93c9e78 100644 --- a/apache-cxf/cxf-jaxrs-implementation/pom.xml +++ b/apache-cxf/cxf-jaxrs-implementation/pom.xml @@ -27,15 +27,6 @@ com.baeldung.cxf.jaxrs.implementation.RestfulServer - - maven-surefire-plugin - ${surefire.version} - - - **/*LiveTest.java - - -
diff --git a/apache-cxf/cxf-spring/pom.xml b/apache-cxf/cxf-spring/pom.xml index 2cd700680b..9bfc2dd889 100644 --- a/apache-cxf/cxf-spring/pom.xml +++ b/apache-cxf/cxf-spring/pom.xml @@ -52,15 +52,6 @@ false - - maven-surefire-plugin - ${surefire.version} - - - **/*LiveTest.java - - - @@ -102,24 +93,6 @@ - - - maven-surefire-plugin - ${surefire.version} - - - integration-test - - test - - - - none - - - - - diff --git a/apache-spark/pom.xml b/apache-spark/pom.xml index 2f94987b11..e53e115ddd 100644 --- a/apache-spark/pom.xml +++ b/apache-spark/pom.xml @@ -32,17 +32,4 @@ test - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.7.0 - - 1.8 - 1.8 - - - - diff --git a/atomix/pom.xml b/atomix/pom.xml index 80c573dd86..0ecdf8987d 100644 --- a/atomix/pom.xml +++ b/atomix/pom.xml @@ -29,18 +29,4 @@ 1.2.17 - - - - maven-compiler-plugin - 3.7.0 - - 1.8 - 1.8 - - - - - - diff --git a/bootique/dependency-reduced-pom.xml b/bootique/dependency-reduced-pom.xml deleted file mode 100644 index ab09cfb7b1..0000000000 --- a/bootique/dependency-reduced-pom.xml +++ /dev/null @@ -1,56 +0,0 @@ - - - - bootique-parent - io.bootique.parent - 0.12 - - 4.0.0 - com.baeldung.bootique - bootique - bootique - 1.0-SNAPSHOT - http://maven.apache.org - - - - maven-shade-plugin - - - - - - io.bootique - bootique-test - 0.23 - test - - - junit - junit - 4.12 - test - - - hamcrest-core - org.hamcrest - - - - - - - - io.bootique.bom - bootique-bom - 0.23 - pom - import - - - - - com.baeldung.bootique.App - - - diff --git a/camel-api/pom.xml b/camel-api/pom.xml index 3f96e2209c..a1cdb1064e 100644 --- a/camel-api/pom.xml +++ b/camel-api/pom.xml @@ -45,14 +45,6 @@ spring-boot:run - - maven-compiler-plugin - ${maven-compiler-plugin.version} - - 1.8 - 1.8 - - org.springframework.boot spring-boot-maven-plugin @@ -71,7 +63,6 @@ UTF-8 3.7.0 - 2.19.1 2.19.1 1.5.4.RELEASE diff --git a/cas/cas-secured-app/pom.xml b/cas/cas-secured-app/pom.xml index d52597412e..947aa2f351 100644 --- a/cas/cas-secured-app/pom.xml +++ b/cas/cas-secured-app/pom.xml @@ -65,24 +65,6 @@ org.springframework.boot spring-boot-maven-plugin - - org.apache.maven.plugins - maven-surefire-plugin - ${maven-surefire-plugin.version} - - 3 - true - - **/*IntegrationTest.java - **/*LongRunningUnitTest.java - **/*ManualTest.java - **/JdbcTest.java - **/*LiveTest.java - - - - - diff --git a/core-groovy/pom.xml b/core-groovy/pom.xml index 91cbe66e35..e645e95a88 100644 --- a/core-groovy/pom.xml +++ b/core-groovy/pom.xml @@ -78,10 +78,6 @@ - - maven-surefire-plugin - ${maven-surefire-plugin.version} - maven-failsafe-plugin 2.19.1 diff --git a/core-java-9/pom.xml b/core-java-9/pom.xml index 40e29af35f..5f07a62e13 100644 --- a/core-java-9/pom.xml +++ b/core-java-9/pom.xml @@ -75,13 +75,6 @@ 1.9 - - - org.apache.maven.plugins - maven-surefire-plugin - ${maven-surefire-plugin.version} - - diff --git a/core-java-io/pom.xml b/core-java-io/pom.xml index 1c2a9b1249..03fd5799c9 100644 --- a/core-java-io/pom.xml +++ b/core-java-io/pom.xml @@ -232,18 +232,7 @@ - - - org.apache.maven.plugins - maven-compiler-plugin - ${maven-compiler-plugin.version} - - 1.8 - 1.8 - - - - + org.apache.maven.plugins maven-surefire-plugin @@ -256,7 +245,6 @@ true - org.springframework.boot spring-boot-maven-plugin diff --git a/core-java-sun/pom.xml b/core-java-sun/pom.xml index 2b654fa3a5..04c2454872 100644 --- a/core-java-sun/pom.xml +++ b/core-java-sun/pom.xml @@ -238,31 +238,6 @@ - - - org.apache.maven.plugins - maven-compiler-plugin - ${maven-compiler-plugin.version} - - 1.8 - 1.8 - - - - - org.apache.maven.plugins - maven-surefire-plugin - - - **/*LiveTest.java - **/*IntegrationTest.java - **/*LongRunningUnitTest.java - **/*ManualTest.java - - - - - org.apache.maven.plugins maven-dependency-plugin diff --git a/core-java/externalizable.txt b/core-java/externalizable.txt new file mode 100644 index 0000000000000000000000000000000000000000..ddd3e143a8fdbd74d97d1d5fcbe6ef58ea78e1a4 GIT binary patch literal 106 zcmZ4UmVvcgm4V%{C^t1PGm(KkGPNkREHRIPfw7E%*EcmKvm~{sC^0WJF|W9YK{Yu) zS1&0sH7BJsFI_LS0w|Z4n3GwRn3R*M=bWFLTbh?yQYpAq{rFxjKM5uVMo$K&%#?}( I1_lOJ09uA3U;qFB literal 0 HcmV?d00001 diff --git a/core-java/pom.xml b/core-java/pom.xml index b7760dc250..f7bf9ed12a 100644 --- a/core-java/pom.xml +++ b/core-java/pom.xml @@ -247,17 +247,6 @@ - - - org.apache.maven.plugins - maven-compiler-plugin - ${maven-compiler-plugin.version} - - 1.8 - 1.8 - - - org.apache.maven.plugins maven-surefire-plugin diff --git a/core-java/yofile.txt b/core-java/yofile.txt new file mode 100644 index 0000000000000000000000000000000000000000..ad56bf35f7a64171f415909f14caae6c5e679593 GIT binary patch literal 98 zcmZ4UmVvdnh(R$qKUXg)F*PTpG%sDRIJGD2*LSS*OuAojaeVm4G7k@y84zFaETyXJb8vRN3c>;|JBC3dsbAtDy< z{JhU|zCk%N(3$FlO_1a)SAu0^VwCX;ZLAgRC#lp+B6!aWz>A=glF78P(23lYf3E!J z%11A#SEMe{{*!ofpMVd32muO;prkM%3yo-w3*-`&;A3lIC7jdYO$)(5le5>K0DA%~ rRF(vp#`So*ueV(vyb#I@lsOd!YF}=cClfN8^PyGUUv@sgOX(F4<$G8t literal 0 HcmV?d00001 diff --git a/core-kotlin/pom.xml b/core-kotlin/pom.xml index 6c729d5688..b5aeb264e1 100644 --- a/core-kotlin/pom.xml +++ b/core-kotlin/pom.xml @@ -159,10 +159,6 @@ - - maven-surefire-plugin - ${maven-surefire-plugin.version} - maven-failsafe-plugin 2.19.1 diff --git a/drools/pom.xml b/drools/pom.xml index 5f228802fa..35f3f7331c 100644 --- a/drools/pom.xml +++ b/drools/pom.xml @@ -60,28 +60,5 @@ spring-core 4.3.6.RELEASE - - - - - - org.apache.maven.plugins - maven-surefire-plugin - ${maven-surefire-plugin.version} - - 3 - true - - **/*IntegrationTest.java - **/*LongRunningUnitTest.java - **/*ManualTest.java - **/JdbcTest.java - **/*LiveTest.java - - - - - - diff --git a/dubbo/pom.xml b/dubbo/pom.xml index af242e5905..866d1c49c9 100644 --- a/dubbo/pom.xml +++ b/dubbo/pom.xml @@ -47,27 +47,4 @@ - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.7.0 - - 1.8 - 1.8 - - - - maven-surefire-plugin - ${surefire.version} - - - **/*LiveTest.java - - - - - - diff --git a/ejb/ejb-session-beans/pom.xml b/ejb/ejb-session-beans/pom.xml index b89ff6ed15..8d05389a95 100644 --- a/ejb/ejb-session-beans/pom.xml +++ b/ejb/ejb-session-beans/pom.xml @@ -80,14 +80,6 @@ - - maven-compiler-plugin - 3.7.0 - - 1.8 - 1.8 - - maven-war-plugin 2.4 @@ -95,10 +87,6 @@ false - - maven-surefire-plugin - 2.17 - diff --git a/geotools/pom.xml b/geotools/pom.xml index 01bd6448bb..edd3c4bf3a 100644 --- a/geotools/pom.xml +++ b/geotools/pom.xml @@ -57,20 +57,6 @@ http://repo.opengeo.org - - - - true - org.apache.maven.plugins - maven-compiler-plugin - 3.7.0 - - 1.8 - 1.8 - - - - 15.2 15.2 diff --git a/guest/core-java/pom.xml b/guest/core-java/pom.xml index 35756f784b..ccad9b87cf 100644 --- a/guest/core-java/pom.xml +++ b/guest/core-java/pom.xml @@ -40,19 +40,6 @@ test - - - - - maven-compiler-plugin - 3.7.0 - - 1.8 - 1.8 - - - - 2.8.2 1.3 diff --git a/guest/deep-jsf/pom.xml b/guest/deep-jsf/pom.xml index 4697bbf588..bbb544443f 100644 --- a/guest/deep-jsf/pom.xml +++ b/guest/deep-jsf/pom.xml @@ -29,17 +29,6 @@ deep-jsf - - - org.apache.maven.plugins - maven-compiler-plugin - 3.7.0 - - 1.8 - 1.8 - - - \ No newline at end of file diff --git a/guest/junit5-example/pom.xml b/guest/junit5-example/pom.xml index 0e92060a71..c9ea232715 100644 --- a/guest/junit5-example/pom.xml +++ b/guest/junit5-example/pom.xml @@ -44,14 +44,6 @@ - - maven-compiler-plugin - 3.7.0 - - 1.8 - 1.8 - - maven-surefire-plugin 2.19.1 diff --git a/guest/log4j2-example/pom.xml b/guest/log4j2-example/pom.xml index 594b759538..26e026448f 100644 --- a/guest/log4j2-example/pom.xml +++ b/guest/log4j2-example/pom.xml @@ -41,16 +41,6 @@ - - - maven-compiler-plugin - 3.7.0 - - 1.8 - 1.8 - - - diff --git a/guest/logback-example/pom.xml b/guest/logback-example/pom.xml index 1f277787d3..8240e45b6a 100644 --- a/guest/logback-example/pom.xml +++ b/guest/logback-example/pom.xml @@ -28,19 +28,5 @@ janino 3.0.7 - - - - - - maven-compiler-plugin - 3.7.0 - - 1.8 - 1.8 - - - - \ No newline at end of file diff --git a/guest/memory-leaks/pom.xml b/guest/memory-leaks/pom.xml index e0f256b2d5..63d5af9474 100644 --- a/guest/memory-leaks/pom.xml +++ b/guest/memory-leaks/pom.xml @@ -30,15 +30,5 @@ src/test/resources/ - - - maven-compiler-plugin - 3.7.0 - - 1.8 - 1.8 - - - \ No newline at end of file diff --git a/guest/thread-pools/pom.xml b/guest/thread-pools/pom.xml index 32ae6384e2..42770edb2a 100644 --- a/guest/thread-pools/pom.xml +++ b/guest/thread-pools/pom.xml @@ -17,17 +17,4 @@ 1.2.3 - - - - - maven-compiler-plugin - 3.7.0 - - 1.8 - 1.8 - - - - \ No newline at end of file diff --git a/guest/tomcat-app/pom.xml b/guest/tomcat-app/pom.xml index 02f3abcc32..2ea5190248 100644 --- a/guest/tomcat-app/pom.xml +++ b/guest/tomcat-app/pom.xml @@ -55,14 +55,6 @@ - - maven-compiler-plugin - 3.7.0 - - 1.8 - 1.8 - - maven-war-plugin 3.0.0 diff --git a/guest/webservices/rest-client/pom.xml b/guest/webservices/rest-client/pom.xml index d74d713a29..b124e632a3 100644 --- a/guest/webservices/rest-client/pom.xml +++ b/guest/webservices/rest-client/pom.xml @@ -12,14 +12,6 @@ - - maven-compiler-plugin - 3.7.0 - - 1.8 - 1.8 - - maven-war-plugin 2.6 diff --git a/guest/webservices/rest-server/pom.xml b/guest/webservices/rest-server/pom.xml index be43a85166..a183d4110c 100644 --- a/guest/webservices/rest-server/pom.xml +++ b/guest/webservices/rest-server/pom.xml @@ -36,14 +36,6 @@ - - maven-compiler-plugin - 3.7.0 - - 1.8 - 1.8 - - maven-war-plugin 3.0.0 diff --git a/hibernate5/pom.xml b/hibernate5/pom.xml index 31fe10ee97..a9dcf56c1c 100644 --- a/hibernate5/pom.xml +++ b/hibernate5/pom.xml @@ -67,33 +67,5 @@ true - - - - org.apache.maven.plugins - maven-compiler-plugin - ${maven-compiler-plugin.version} - - 1.8 - 1.8 - - - - - org.apache.maven.plugins - maven-surefire-plugin - - 3 - true - - **/*IntegrationTest.java - **/*LiveTest.java - - - - - - - diff --git a/java-difference-date/pom.xml b/java-difference-date/pom.xml index ac3f0fa3b5..7a1ee5f1eb 100644 --- a/java-difference-date/pom.xml +++ b/java-difference-date/pom.xml @@ -36,22 +36,7 @@ - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.7.0 - - 1.8 - 1.8 - - - - - - 1.8 4.12 2.9.9 1.5.1 diff --git a/jee-7/src/main/java/com/baeldung/javaeeannotations/JavaEEAnnotationsSample/pom.xml b/jee-7/src/main/java/com/baeldung/javaeeannotations/JavaEEAnnotationsSample/pom.xml index de69efa43a..3c9dbcc5a5 100644 --- a/jee-7/src/main/java/com/baeldung/javaeeannotations/JavaEEAnnotationsSample/pom.xml +++ b/jee-7/src/main/java/com/baeldung/javaeeannotations/JavaEEAnnotationsSample/pom.xml @@ -6,7 +6,11 @@ war JavaEEAnnotationsSample JavaEEAnnotationsSample - + + com.baeldung + parent-modules + 1.0.0-SNAPSHOT + @@ -31,15 +35,6 @@ - - org.apache.maven.plugins - maven-compiler-plugin - 3.7.0 - - 1.8 - 1.8 - - org.apache.maven.plugins maven-war-plugin diff --git a/jpa-storedprocedure/pom.xml b/jpa-storedprocedure/pom.xml index cbda37a7b3..a054994fcb 100644 --- a/jpa-storedprocedure/pom.xml +++ b/jpa-storedprocedure/pom.xml @@ -19,7 +19,6 @@ 5.2.5.Final 6.0.5 2.5 - 2.19.1 diff --git a/jsonb/pom.xml b/jsonb/pom.xml index 03f4f227b1..63dc331f7a 100644 --- a/jsonb/pom.xml +++ b/jsonb/pom.xml @@ -99,7 +99,6 @@ 1.8 1.0.0 5.0.0 - 2.20 1.0 1.1.3 1.0 diff --git a/libraries-data/pom.xml b/libraries-data/pom.xml index 55bf02ae16..d19d03b3ff 100644 --- a/libraries-data/pom.xml +++ b/libraries-data/pom.xml @@ -89,15 +89,6 @@ - - org.apache.maven.plugins - maven-compiler-plugin - ${maven-compiler-plugin.version} - - 1.8 - 1.8 - - diff --git a/libraries/pom.xml b/libraries/pom.xml index be2876ec3b..43c8239e96 100644 --- a/libraries/pom.xml +++ b/libraries/pom.xml @@ -785,16 +785,6 @@ - - - - maven-compiler-plugin - 3.7.0 - - 1.8 - 1.8 - - diff --git a/linkrest/pom.xml b/linkrest/pom.xml index 819436236f..1dac87c4e9 100644 --- a/linkrest/pom.xml +++ b/linkrest/pom.xml @@ -35,14 +35,6 @@ - - maven-compiler-plugin - 3.7.0 - - 1.8 - 1.8 - - maven-war-plugin 2.6 diff --git a/mustache/pom.xml b/mustache/pom.xml index 1c64dbdb0b..5e40402cbc 100644 --- a/mustache/pom.xml +++ b/mustache/pom.xml @@ -71,24 +71,7 @@ org.springframework.boot spring-boot-maven-plugin - - org.apache.maven.plugins - maven-surefire-plugin - ${maven-surefire-plugin.version} - - 3 - true - - **/*IntegrationTest.java - **/*LongRunningUnitTest.java - **/*ManualTest.java - **/JdbcTest.java - **/*LiveTest.java - - - - diff --git a/out/production/main180/com/baeldung/javaeeannotations/JavaEEAnnotationsSample/pom.xml b/out/production/main180/com/baeldung/javaeeannotations/JavaEEAnnotationsSample/pom.xml index de69efa43a..89ea844fc8 100644 --- a/out/production/main180/com/baeldung/javaeeannotations/JavaEEAnnotationsSample/pom.xml +++ b/out/production/main180/com/baeldung/javaeeannotations/JavaEEAnnotationsSample/pom.xml @@ -31,15 +31,6 @@ - - org.apache.maven.plugins - maven-compiler-plugin - 3.7.0 - - 1.8 - 1.8 - - org.apache.maven.plugins maven-war-plugin diff --git a/patterns/behavioral-patterns/pom.xml b/patterns/behavioral-patterns/pom.xml index 3c40520ce1..11170b70bc 100644 --- a/patterns/behavioral-patterns/pom.xml +++ b/patterns/behavioral-patterns/pom.xml @@ -20,15 +20,6 @@ test - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.7.0 - - - UTF-8 1.8 diff --git a/patterns/facade/pom.xml b/patterns/facade/pom.xml index ee46a2a80d..6b9bc739db 100644 --- a/patterns/facade/pom.xml +++ b/patterns/facade/pom.xml @@ -20,15 +20,6 @@ test - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.7.0 - - - UTF-8 1.8 diff --git a/patterns/front-controller/pom.xml b/patterns/front-controller/pom.xml index b746d5dc6c..c41e2f5e09 100644 --- a/patterns/front-controller/pom.xml +++ b/patterns/front-controller/pom.xml @@ -22,15 +22,6 @@ - - org.apache.maven.plugins - maven-compiler-plugin - 3.7.0 - - 1.8 - 1.8 - - org.apache.maven.plugins maven-war-plugin diff --git a/persistence-modules/liquibase/pom.xml b/persistence-modules/liquibase/pom.xml index a70483437f..bb5a3700b1 100644 --- a/persistence-modules/liquibase/pom.xml +++ b/persistence-modules/liquibase/pom.xml @@ -23,16 +23,6 @@ baeldung-liquibase-demo - - org.apache.maven.plugins - maven-compiler-plugin - 3.7.0 - - 1.8 - 1.8 - - - org.liquibase liquibase-maven-plugin diff --git a/persistence-modules/spring-hibernate-5/pom.xml b/persistence-modules/spring-hibernate-5/pom.xml index 86e952c0e4..5b244dfd63 100644 --- a/persistence-modules/spring-hibernate-5/pom.xml +++ b/persistence-modules/spring-hibernate-5/pom.xml @@ -149,32 +149,6 @@ true - - - - - org.apache.maven.plugins - maven-compiler-plugin - ${maven-compiler-plugin.version} - - 1.8 - 1.8 - - - - - org.apache.maven.plugins - maven-surefire-plugin - ${maven-surefire-plugin.version} - - - **/*IntegrationTest.java - - - - - - diff --git a/resteasy/bin/pom.xml b/resteasy/bin/pom.xml index 2e1f839a55..f275bc814f 100644 --- a/resteasy/bin/pom.xml +++ b/resteasy/bin/pom.xml @@ -13,6 +13,12 @@ 2.5 1.6.1 + + + com.baeldung + resteasy-tutorial + 1.0 + RestEasyTutorial @@ -73,66 +79,5 @@ commons-io ${commons-io.version} - - - - - live - - - - org.apache.maven.plugins - maven-surefire-plugin - - - integration-test - - test - - - - **/*IntegrationTest.java - - - **/*LiveTest.java - - - - - - - json - - - - - org.codehaus.cargo - cargo-maven2-plugin - ${cargo-maven2-plugin.version} - - false - - - - start-server - pre-integration-test - - start - - - - stop-server - post-integration-test - - stop - - - - - - - - - \ No newline at end of file diff --git a/spring-boot-bootstrap/pom.xml b/spring-boot-bootstrap/pom.xml index ad2512846b..07466c76f2 100644 --- a/spring-boot-bootstrap/pom.xml +++ b/spring-boot-bootstrap/pom.xml @@ -86,15 +86,6 @@ - - - - org.springframework.boot - spring-boot-maven-plugin - - - - integration diff --git a/spring-cloud/spring-cloud-aws/pom.xml b/spring-cloud/spring-cloud-aws/pom.xml index b27b6c0d18..28f04cd435 100644 --- a/spring-cloud/spring-cloud-aws/pom.xml +++ b/spring-cloud/spring-cloud-aws/pom.xml @@ -70,12 +70,7 @@ - - - org.springframework.boot - spring-boot-maven-plugin - - + maven-surefire-plugin diff --git a/spring-cloud/spring-cloud-bootstrap/gateway/pom.xml b/spring-cloud/spring-cloud-bootstrap/gateway/pom.xml index f32de88076..566fbb2a42 100644 --- a/spring-cloud/spring-cloud-bootstrap/gateway/pom.xml +++ b/spring-cloud/spring-cloud-bootstrap/gateway/pom.xml @@ -69,24 +69,6 @@ org.springframework.boot spring-boot-maven-plugin - - org.apache.maven.plugins - maven-compiler-plugin - ${maven-compiler-plugin.version} - - 1.8 - 1.8 - - - - org.apache.maven.plugins - maven-surefire-plugin - - - **/*LiveTest.java - - - maven-antrun-plugin diff --git a/spring-cloud/spring-cloud-connectors-heroku/pom.xml b/spring-cloud/spring-cloud-connectors-heroku/pom.xml index 83e8e360c8..f0154d5b36 100644 --- a/spring-cloud/spring-cloud-connectors-heroku/pom.xml +++ b/spring-cloud/spring-cloud-connectors-heroku/pom.xml @@ -61,13 +61,8 @@ Brixton.SR7 - - - org.springframework.boot - spring-boot-maven-plugin - org.apache.maven.plugins maven-surefire-plugin @@ -85,16 +80,6 @@ true - - org.apache.maven.plugins - maven-compiler-plugin - 3.7.0 - - 1.8 - 1.8 - - - \ No newline at end of file diff --git a/spring-cloud/spring-cloud-consul/pom.xml b/spring-cloud/spring-cloud-consul/pom.xml index 7ce570d50d..fe791071c0 100644 --- a/spring-cloud/spring-cloud-consul/pom.xml +++ b/spring-cloud/spring-cloud-consul/pom.xml @@ -34,25 +34,4 @@ 1.3.0.RELEASE - - - - - - org.apache.maven.plugins - maven-compiler-plugin - ${maven-compiler-plugin.version} - - 1.8 - 1.8 - - - - org.springframework.boot - spring-boot-maven-plugin - ${spring-boot-maven-plugin.version} - - - - diff --git a/spring-cloud/spring-cloud-contract/spring-cloud-contract-consumer/pom.xml b/spring-cloud/spring-cloud-contract/spring-cloud-contract-consumer/pom.xml index 67fea178eb..b80f453106 100644 --- a/spring-cloud/spring-cloud-contract/spring-cloud-contract-consumer/pom.xml +++ b/spring-cloud/spring-cloud-contract/spring-cloud-contract-consumer/pom.xml @@ -54,15 +54,4 @@ test - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - - diff --git a/spring-cloud/spring-cloud-eureka/pom.xml b/spring-cloud/spring-cloud-eureka/pom.xml index e90609c48d..01b1f45e1e 100644 --- a/spring-cloud/spring-cloud-eureka/pom.xml +++ b/spring-cloud/spring-cloud-eureka/pom.xml @@ -29,25 +29,4 @@ 3.7.0 1.4.2.RELEASE - - - - - - org.apache.maven.plugins - maven-compiler-plugin - ${maven-compiler-plugin.version} - - 1.8 - 1.8 - - - - org.springframework.boot - spring-boot-maven-plugin - ${spring-boot-maven-plugin.version} - - - - 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 cd363ffef1..bf0167fd00 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 @@ -43,24 +43,6 @@ - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.7.0 - - 1.8 - 1.8 - - - - org.springframework.boot - spring-boot-maven-plugin - - - - Brixton.SR7 1.2.3.RELEASE 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 038a0ab81d..54e1beb349 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 @@ -53,24 +53,6 @@ - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.7.0 - - 1.8 - 1.8 - - - - org.springframework.boot - spring-boot-maven-plugin - - - - Brixton.SR7 1.2.3.RELEASE 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 e4bae32011..ecd6a79e7e 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 @@ -37,25 +37,7 @@ - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.7.0 - - 1.8 - 1.8 - - - - org.springframework.boot - spring-boot-maven-plugin - - - - + Brixton.SR7 1.2.3.RELEASE diff --git a/spring-cloud/spring-cloud-gateway/pom.xml b/spring-cloud/spring-cloud-gateway/pom.xml index 90737f369d..0592af8b03 100644 --- a/spring-cloud/spring-cloud-gateway/pom.xml +++ b/spring-cloud/spring-cloud-gateway/pom.xml @@ -75,25 +75,4 @@ - - - - - - org.apache.maven.plugins - maven-compiler-plugin - ${maven-compiler-plugin.version} - - 1.8 - 1.8 - - - - org.springframework.boot - spring-boot-maven-plugin - ${spring-boot-maven-plugin.version} - - - - diff --git a/spring-cloud/spring-cloud-hystrix/feign-rest-consumer/pom.xml b/spring-cloud/spring-cloud-hystrix/feign-rest-consumer/pom.xml index 5913b60a01..ce6e743f5c 100644 --- a/spring-cloud/spring-cloud-hystrix/feign-rest-consumer/pom.xml +++ b/spring-cloud/spring-cloud-hystrix/feign-rest-consumer/pom.xml @@ -66,25 +66,7 @@ - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.7.0 - - 1.8 - 1.8 - - - - org.springframework.boot - spring-boot-maven-plugin - - - - + 1.2.3.RELEASE 1.2.3.RELEASE diff --git a/spring-cloud/spring-cloud-hystrix/pom.xml b/spring-cloud/spring-cloud-hystrix/pom.xml index 9a6af9a790..5bfbba5a14 100644 --- a/spring-cloud/spring-cloud-hystrix/pom.xml +++ b/spring-cloud/spring-cloud-hystrix/pom.xml @@ -28,25 +28,4 @@ 3.7.0 1.4.2.RELEASE - - - - - - org.apache.maven.plugins - maven-compiler-plugin - ${maven-compiler-plugin.version} - - 1.8 - 1.8 - - - - org.springframework.boot - spring-boot-maven-plugin - ${spring-boot-maven-plugin.version} - - - - diff --git a/spring-cloud/spring-cloud-hystrix/rest-consumer/pom.xml b/spring-cloud/spring-cloud-hystrix/rest-consumer/pom.xml index 46e408d339..d2e1bc5b08 100644 --- a/spring-cloud/spring-cloud-hystrix/rest-consumer/pom.xml +++ b/spring-cloud/spring-cloud-hystrix/rest-consumer/pom.xml @@ -56,25 +56,7 @@ - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.7.0 - - 1.8 - 1.8 - - - - org.springframework.boot - spring-boot-maven-plugin - - - - + Brixton.SR7 1.2.3.RELEASE diff --git a/spring-cloud/spring-cloud-hystrix/rest-producer/pom.xml b/spring-cloud/spring-cloud-hystrix/rest-producer/pom.xml index 804ef2eb29..f491175982 100644 --- a/spring-cloud/spring-cloud-hystrix/rest-producer/pom.xml +++ b/spring-cloud/spring-cloud-hystrix/rest-producer/pom.xml @@ -24,25 +24,7 @@ ${spring-boot-starter-web.version} - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.7.0 - - 1.8 - 1.8 - - - - org.springframework.boot - spring-boot-maven-plugin - - - - + Brixton.SR7 diff --git a/spring-cloud/spring-cloud-stream/pom.xml b/spring-cloud/spring-cloud-stream/pom.xml index 65a327e664..65b343d46f 100644 --- a/spring-cloud/spring-cloud-stream/pom.xml +++ b/spring-cloud/spring-cloud-stream/pom.xml @@ -47,25 +47,4 @@ - - - - - - org.apache.maven.plugins - maven-compiler-plugin - ${maven-compiler-plugin.version} - - 1.8 - 1.8 - - - - org.springframework.boot - spring-boot-maven-plugin - ${spring-boot-maven-plugin.version} - - - - diff --git a/spring-cloud/spring-cloud-zuul-eureka-integration/bin/eureka-client/pom.xml b/spring-cloud/spring-cloud-zuul-eureka-integration/bin/eureka-client/pom.xml index a3185a44d4..978a804819 100644 --- a/spring-cloud/spring-cloud-zuul-eureka-integration/bin/eureka-client/pom.xml +++ b/spring-cloud/spring-cloud-zuul-eureka-integration/bin/eureka-client/pom.xml @@ -42,24 +42,6 @@ - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.7.0 - - 1.8 - 1.8 - - - - org.springframework.boot - spring-boot-maven-plugin - - - - Brixton.SR7 1.2.3.RELEASE diff --git a/spring-cloud/spring-cloud-zuul-eureka-integration/bin/eureka-server/pom.xml b/spring-cloud/spring-cloud-zuul-eureka-integration/bin/eureka-server/pom.xml index d86cfa8589..8204b1f42a 100644 --- a/spring-cloud/spring-cloud-zuul-eureka-integration/bin/eureka-server/pom.xml +++ b/spring-cloud/spring-cloud-zuul-eureka-integration/bin/eureka-server/pom.xml @@ -42,25 +42,6 @@ - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.7.0 - - 1.8 - 1.8 - - - - org.springframework.boot - spring-boot-maven-plugin - - - - Brixton.SR7 1.2.3.RELEASE diff --git a/spring-cloud/spring-cloud-zuul-eureka-integration/bin/pom.xml b/spring-cloud/spring-cloud-zuul-eureka-integration/bin/pom.xml index fabad77a77..f9def34004 100644 --- a/spring-cloud/spring-cloud-zuul-eureka-integration/bin/pom.xml +++ b/spring-cloud/spring-cloud-zuul-eureka-integration/bin/pom.xml @@ -27,26 +27,6 @@ 1.10 - - - - - org.apache.maven.plugins - maven-compiler-plugin - ${maven-compiler-plugin.version} - - 1.8 - 1.8 - - - - org.springframework.boot - spring-boot-maven-plugin - ${spring-boot-maven-plugin.version} - - - - zuul-server eureka-server diff --git a/spring-cloud/spring-cloud-zuul-eureka-integration/bin/zuul-server/pom.xml b/spring-cloud/spring-cloud-zuul-eureka-integration/bin/zuul-server/pom.xml index 2622a3e36b..d423ed8fe2 100644 --- a/spring-cloud/spring-cloud-zuul-eureka-integration/bin/zuul-server/pom.xml +++ b/spring-cloud/spring-cloud-zuul-eureka-integration/bin/zuul-server/pom.xml @@ -41,21 +41,4 @@ - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.7.0 - - 1.8 - 1.8 - - - - org.springframework.boot - spring-boot-maven-plugin - - - \ No newline at end of file diff --git a/spring-cloud/spring-cloud-zuul-eureka-integration/eureka-client/pom.xml b/spring-cloud/spring-cloud-zuul-eureka-integration/eureka-client/pom.xml index a3185a44d4..978a804819 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 @@ -42,24 +42,6 @@ - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.7.0 - - 1.8 - 1.8 - - - - org.springframework.boot - spring-boot-maven-plugin - - - - Brixton.SR7 1.2.3.RELEASE 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 d86cfa8589..8005db761b 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 @@ -43,24 +43,6 @@ - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.7.0 - - 1.8 - 1.8 - - - - org.springframework.boot - spring-boot-maven-plugin - - - - Brixton.SR7 1.2.3.RELEASE diff --git a/spring-cloud/spring-cloud-zuul-eureka-integration/pom.xml b/spring-cloud/spring-cloud-zuul-eureka-integration/pom.xml index b4c7188abe..773d9af758 100644 --- a/spring-cloud/spring-cloud-zuul-eureka-integration/pom.xml +++ b/spring-cloud/spring-cloud-zuul-eureka-integration/pom.xml @@ -28,26 +28,6 @@ 1.2.10 - - - - - org.apache.maven.plugins - maven-compiler-plugin - ${maven-compiler-plugin.version} - - 1.8 - 1.8 - - - - org.springframework.boot - spring-boot-maven-plugin - ${spring-boot-maven-plugin.version} - - - - zuul-server eureka-server 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 b68fd63155..1600681239 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 @@ -46,21 +46,4 @@ - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.7.0 - - 1.8 - 1.8 - - - - org.springframework.boot - spring-boot-maven-plugin - - - \ No newline at end of file diff --git a/spring-mvc-simple/pom.xml b/spring-mvc-simple/pom.xml index 4e7f39bad3..31b57c496f 100644 --- a/spring-mvc-simple/pom.xml +++ b/spring-mvc-simple/pom.xml @@ -7,11 +7,13 @@ 0.0.1-SNAPSHOT Spring MVC simple Maven Webapp http://maven.apache.org + com.baeldung parent-modules 1.0.0-SNAPSHOT + 1.8 1.8 @@ -164,11 +166,6 @@ ${deploy-path} - - org.apache.maven.plugins - maven-compiler-plugin - ${maven.compiler.version} - maven-surefire-plugin ${maven-surefire-plugin.version} diff --git a/spring-security-mvc-socket/pom.xml b/spring-security-mvc-socket/pom.xml index 1bc295a778..382f141483 100644 --- a/spring-security-mvc-socket/pom.xml +++ b/spring-security-mvc-socket/pom.xml @@ -154,14 +154,6 @@ - - maven-compiler-plugin - 3.7.0 - - 1.8 - 1.8 - - org.apache.tomcat.maven tomcat7-maven-plugin diff --git a/spring-swagger-codegen/spring-swagger-codegen-api-client/pom.xml b/spring-swagger-codegen/spring-swagger-codegen-api-client/pom.xml index 61df37ad57..265ca1ec26 100644 --- a/spring-swagger-codegen/spring-swagger-codegen-api-client/pom.xml +++ b/spring-swagger-codegen/spring-swagger-codegen-api-client/pom.xml @@ -120,15 +120,6 @@ - - org.apache.maven.plugins - maven-compiler-plugin - 3.7.0 - - 1.8 - 1.8 - - org.apache.maven.plugins maven-javadoc-plugin diff --git a/testing-modules/junit-5/pom.xml b/testing-modules/junit-5/pom.xml index 28a29d8545..87e424e0da 100644 --- a/testing-modules/junit-5/pom.xml +++ b/testing-modules/junit-5/pom.xml @@ -41,14 +41,6 @@ - - maven-compiler-plugin - ${maven-compiler-plugin.version} - - ${java.version} - ${java.version} - - maven-surefire-plugin ${maven-surefire-plugin.version} diff --git a/testing-modules/mockserver/pom.xml b/testing-modules/mockserver/pom.xml index 8d3e97f129..7f2d85e4c0 100644 --- a/testing-modules/mockserver/pom.xml +++ b/testing-modules/mockserver/pom.xml @@ -7,6 +7,12 @@ com.baeldung mockserver 1.0.0-SNAPSHOT + + com.baeldung + parent-modules + 1.0.0-SNAPSHOT + ../../ + 3.10.8 4.4.1 @@ -35,20 +41,5 @@ httpcore ${apche-http-version} - - - - - maven-surefire-plugin - 2.20 - - - **/**LiveTest.java - - - - - - \ No newline at end of file diff --git a/vavr/pom.xml b/vavr/pom.xml index 28747af3ee..f6733d229c 100644 --- a/vavr/pom.xml +++ b/vavr/pom.xml @@ -65,28 +65,7 @@ http://repo.spring.io/snapshot - - - - - org.apache.maven.plugins - maven-surefire-plugin - ${maven-surefire-plugin.version} - - 3 - true - - **/*IntegrationTest.java - **/*LongRunningUnitTest.java - **/*ManualTest.java - **/JdbcTest.java - **/*LiveTest.java - - - - - - + 1.8 0.9.1 diff --git a/vraptor/pom.xml b/vraptor/pom.xml index e90f286630..59e5eb645c 100644 --- a/vraptor/pom.xml +++ b/vraptor/pom.xml @@ -116,15 +116,6 @@ vraptor src/main/webapp/WEB-INF/classes - - org.apache.maven.plugins - maven-compiler-plugin - 3.7.0 - - 1.8 - 1.8 - - org.apache.tomcat.maven tomcat7-maven-plugin diff --git a/xml/pom.xml b/xml/pom.xml index 66c17a4f33..c001c264d2 100644 --- a/xml/pom.xml +++ b/xml/pom.xml @@ -156,16 +156,6 @@ - - org.apache.maven.plugins - maven-compiler-plugin - 3.7.0 - - ${java-version} - ${java-version} - - - org.apache.maven.plugins maven-surefire-plugin From 263009fb32f89d0e53401ec729820e16041a6bbe Mon Sep 17 00:00:00 2001 From: Adrian Precub Date: Wed, 18 Apr 2018 14:21:51 +0300 Subject: [PATCH 36/36] BAEL-1202: java keystore (#4011) --- .../com/baeldung/keystore/JavaKeyStore.java | 92 ++++++++ .../baeldung/keystore/JavaKeyStoreTest.java | 205 ++++++++++++++++++ 2 files changed, 297 insertions(+) create mode 100644 core-java/src/main/java/com/baeldung/keystore/JavaKeyStore.java create mode 100644 core-java/src/test/java/com/baeldung/keystore/JavaKeyStoreTest.java diff --git a/core-java/src/main/java/com/baeldung/keystore/JavaKeyStore.java b/core-java/src/main/java/com/baeldung/keystore/JavaKeyStore.java new file mode 100644 index 0000000000..29cba37d43 --- /dev/null +++ b/core-java/src/main/java/com/baeldung/keystore/JavaKeyStore.java @@ -0,0 +1,92 @@ +package com.baeldung.keystore; + +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.security.KeyStore; +import java.security.KeyStoreException; +import java.security.NoSuchAlgorithmException; +import java.security.PrivateKey; +import java.security.UnrecoverableEntryException; +import java.security.cert.Certificate; +import java.security.cert.CertificateException; +import java.util.Enumeration; + +/** + * Created by adi on 3/7/18. + */ +public class JavaKeyStore { + + private KeyStore keyStore; + + private String keyStoreName; + private String keyStoreType; + private String keyStorePassword; + + JavaKeyStore(String keyStoreType, String keyStorePassword, String keyStoreName) throws CertificateException, NoSuchAlgorithmException, KeyStoreException, IOException { + this.keyStoreName = keyStoreName; + this.keyStoreType = keyStoreType; + this.keyStorePassword = keyStorePassword; + } + + void createEmptyKeyStore() throws KeyStoreException, CertificateException, NoSuchAlgorithmException, IOException { + if(keyStoreType ==null || keyStoreType.isEmpty()){ + keyStoreType = KeyStore.getDefaultType(); + } + keyStore = KeyStore.getInstance(keyStoreType); + //load + char[] pwdArray = keyStorePassword.toCharArray(); + keyStore.load(null, pwdArray); + + // Save the keyStore + FileOutputStream fos = new FileOutputStream(keyStoreName); + keyStore.store(fos, pwdArray); + fos.close(); + } + + void loadKeyStore() throws IOException, KeyStoreException, CertificateException, NoSuchAlgorithmException { + char[] pwdArray = keyStorePassword.toCharArray(); + keyStore.load(new FileInputStream(keyStoreName), pwdArray); + } + + void setEntry(String alias, KeyStore.SecretKeyEntry secretKeyEntry, KeyStore.ProtectionParameter protectionParameter) throws KeyStoreException { + keyStore.setEntry(alias, secretKeyEntry, protectionParameter); + } + + KeyStore.Entry getEntry(String alias) throws UnrecoverableEntryException, NoSuchAlgorithmException, KeyStoreException { + KeyStore.ProtectionParameter protParam = new KeyStore.PasswordProtection(keyStorePassword.toCharArray()); + return keyStore.getEntry(alias, protParam); + } + + void setKeyEntry(String alias, PrivateKey privateKey, String keyPassword, Certificate[] certificateChain) throws KeyStoreException { + keyStore.setKeyEntry(alias, privateKey, keyPassword.toCharArray(), certificateChain); + } + + void setCertificateEntry(String alias, Certificate certificate) throws KeyStoreException { + keyStore.setCertificateEntry(alias, certificate); + } + + Certificate getCertificate(String alias) throws KeyStoreException { + return keyStore.getCertificate(alias); + } + + void deleteEntry(String alias) throws KeyStoreException { + keyStore.deleteEntry(alias); + } + + void deleteKeyStore() throws KeyStoreException, IOException { + Enumeration aliases = keyStore.aliases(); + while (aliases.hasMoreElements()) { + String alias = aliases.nextElement(); + keyStore.deleteEntry(alias); + } + keyStore = null; + Files.delete(Paths.get(keyStoreName)); + } + + KeyStore getKeyStore() { + return this.keyStore; + } +} diff --git a/core-java/src/test/java/com/baeldung/keystore/JavaKeyStoreTest.java b/core-java/src/test/java/com/baeldung/keystore/JavaKeyStoreTest.java new file mode 100644 index 0000000000..ff1d337597 --- /dev/null +++ b/core-java/src/test/java/com/baeldung/keystore/JavaKeyStoreTest.java @@ -0,0 +1,205 @@ +package com.baeldung.keystore; + +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import sun.security.x509.AlgorithmId; +import sun.security.x509.CertificateAlgorithmId; +import sun.security.x509.CertificateSerialNumber; +import sun.security.x509.CertificateValidity; +import sun.security.x509.CertificateVersion; +import sun.security.x509.CertificateX509Key; +import sun.security.x509.X500Name; +import sun.security.x509.X509CertImpl; +import sun.security.x509.X509CertInfo; + +import javax.crypto.KeyGenerator; +import javax.crypto.SecretKey; +import java.io.IOException; +import java.math.BigInteger; +import java.security.InvalidKeyException; +import java.security.KeyPair; +import java.security.KeyPairGenerator; +import java.security.KeyStore; +import java.security.NoSuchAlgorithmException; +import java.security.NoSuchProviderException; +import java.security.SecureRandom; +import java.security.SignatureException; +import java.security.cert.CertificateException; +import java.security.cert.X509Certificate; +import java.util.Date; + +/** + * Created by adi on 4/14/18. + */ +public class JavaKeyStoreTest { + + private JavaKeyStore keyStore; + + private static final String KEYSTORE_PWD = "abc123"; + private static final String KEYSTORE_NAME = "myKeyStore"; + private static final String KEY_STORE_TYPE = "JCEKS"; + + private static final String MY_SECRET_ENTRY = "mySecretEntry"; + private static final String DN_NAME = "CN=test, OU=test, O=test, L=test, ST=test, C=CY"; + private static final String SHA1WITHRSA = "SHA1withRSA"; + private static final String MY_PRIVATE_KEY = "myPrivateKey"; + private static final String MY_CERTIFICATE = "myCertificate"; + + @Before + public void setUp() throws Exception { + //using java cryptography extension keyStore instead of Keystore.getDefaultType + keyStore = new JavaKeyStore(KEY_STORE_TYPE, KEYSTORE_PWD, KEYSTORE_NAME); + } + + @After + public void tearDown() throws Exception { + if (keyStore.getKeyStore() != null) { + keyStore.deleteKeyStore(); + } + } + + @Test + public void givenNoKeyStore_whenCreateEmptyKeyStore_thenGetKeyStoreNotNull() throws Exception { + keyStore.createEmptyKeyStore(); + KeyStore result = keyStore.getKeyStore(); + Assert.assertNotNull(result); + } + + @Test + public void givenEmptyKeystore_whenLoadKeyStore_thenKeyStoreLoadedAndSizeZero() throws Exception { + keyStore.createEmptyKeyStore(); + keyStore.loadKeyStore(); + KeyStore result = keyStore.getKeyStore(); + Assert.assertNotNull(result); + Assert.assertTrue(result.size() == 0); + } + + @Test + public void givenLoadedKeyStore_whenSetEntry_thenSizeIsOneAndGetKeyNotNull() throws Exception { + keyStore.createEmptyKeyStore(); + keyStore.loadKeyStore(); + + KeyGenerator keygen = KeyGenerator.getInstance("HmacSHA256"); + SecretKey secretKey = keygen.generateKey(); + //ideally, password should be different for every key + KeyStore.ProtectionParameter protParam = new KeyStore.PasswordProtection(KEYSTORE_PWD.toCharArray()); + KeyStore.SecretKeyEntry secretKeyEntry = new KeyStore.SecretKeyEntry(secretKey); + keyStore.setEntry(MY_SECRET_ENTRY, secretKeyEntry, protParam); + + KeyStore result = keyStore.getKeyStore(); + Assert.assertTrue(result.size() == 1); + KeyStore.Entry entry = keyStore.getEntry(MY_SECRET_ENTRY); + Assert.assertTrue(entry != null); + } + + @Test + public void givenLoadedKeyStore_whenSetKeyEntry_thenSizeIsOneAndGetEntryNotNull() throws Exception { + keyStore.createEmptyKeyStore(); + keyStore.loadKeyStore(); + + // Generate the key pair + KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA"); + keyPairGenerator.initialize(1024); + KeyPair keyPair = keyPairGenerator.generateKeyPair(); + + // Generate a self signed certificate + X509Certificate certificate = generateSelfSignedCertificate(keyPair); + + X509Certificate[] certificateChain = new X509Certificate[1]; + certificateChain[0] = certificate; + keyStore.setKeyEntry(MY_PRIVATE_KEY, keyPair.getPrivate(), KEYSTORE_PWD, certificateChain); + + KeyStore result = keyStore.getKeyStore(); + Assert.assertTrue(result.size() == 1); + KeyStore.Entry entry = keyStore.getEntry(MY_PRIVATE_KEY); + Assert.assertTrue(entry != null); + } + + @Test + public void givenLoadedKeyStore_whenSetCertificateEntry_thenSizeIsOneAndGetCertificateEntryNotNull() throws Exception { + keyStore.createEmptyKeyStore(); + keyStore.loadKeyStore(); + + // Generate the key pair + KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA"); + keyPairGenerator.initialize(1024); + KeyPair keyPair = keyPairGenerator.generateKeyPair(); + + // Generate a self signed certificate + X509Certificate certificate = generateSelfSignedCertificate(keyPair); + + keyStore.setCertificateEntry(MY_CERTIFICATE, certificate); + + KeyStore result = this.keyStore.getKeyStore(); + Assert.assertTrue(result.size() == 1); + java.security.cert.Certificate resultCertificate = keyStore.getCertificate(MY_CERTIFICATE); + Assert.assertNotNull(resultCertificate); + } + + @Test + public void givenLoadedKeyStoreWithOneEntry_whenDeleteEntry_thenKeyStoreSizeIsZero() throws Exception { + keyStore.createEmptyKeyStore(); + keyStore.loadKeyStore(); + + KeyGenerator keygen = KeyGenerator.getInstance("HmacSHA256"); + SecretKey secretKey = keygen.generateKey(); + //ideally, password should be different for every key + KeyStore.ProtectionParameter protParam = new KeyStore.PasswordProtection(KEYSTORE_PWD.toCharArray()); + KeyStore.SecretKeyEntry secretKeyEntry = new KeyStore.SecretKeyEntry(secretKey); + keyStore.setEntry(MY_SECRET_ENTRY, secretKeyEntry, protParam); + + keyStore.deleteEntry(MY_SECRET_ENTRY); + + KeyStore result = this.keyStore.getKeyStore(); + Assert.assertTrue(result.size() == 0); + } + + @Test + public void givenLoadedKeystore_whenDeleteKeyStore_thenKeyStoreIsNull() throws Exception { + keyStore.createEmptyKeyStore(); + keyStore.loadKeyStore(); + + keyStore.deleteKeyStore(); + + KeyStore result = this.keyStore.getKeyStore(); + Assert.assertTrue(result == null); + } + + private X509Certificate generateSelfSignedCertificate(KeyPair keyPair) throws CertificateException, IOException, NoSuchProviderException, NoSuchAlgorithmException, InvalidKeyException, SignatureException { + X509CertInfo certInfo = new X509CertInfo(); + // Serial number and version + certInfo.set(X509CertInfo.SERIAL_NUMBER, new CertificateSerialNumber(new BigInteger(64, new SecureRandom()))); + certInfo.set(X509CertInfo.VERSION, new CertificateVersion(CertificateVersion.V3)); + + // Subject & Issuer + X500Name owner = new X500Name(DN_NAME); + certInfo.set(X509CertInfo.SUBJECT, owner); + certInfo.set(X509CertInfo.ISSUER, owner); + + // Key and algorithm + certInfo.set(X509CertInfo.KEY, new CertificateX509Key(keyPair.getPublic())); + AlgorithmId algorithm = new AlgorithmId(AlgorithmId.sha1WithRSAEncryption_oid); + certInfo.set(X509CertInfo.ALGORITHM_ID, new CertificateAlgorithmId(algorithm)); + + // Validity + Date validFrom = new Date(); + Date validTo = new Date(validFrom.getTime() + 50L * 365L * 24L * 60L * 60L * 1000L); //50 years + CertificateValidity validity = new CertificateValidity(validFrom, validTo); + certInfo.set(X509CertInfo.VALIDITY, validity); + + // Create certificate and sign it + X509CertImpl cert = new X509CertImpl(certInfo); + cert.sign(keyPair.getPrivate(), SHA1WITHRSA); + + // Since the SHA1withRSA provider may have a different algorithm ID to what we think it should be, + // we need to reset the algorithm ID, and resign the certificate + AlgorithmId actualAlgorithm = (AlgorithmId) cert.get(X509CertImpl.SIG_ALG); + certInfo.set(CertificateAlgorithmId.NAME + "." + CertificateAlgorithmId.ALGORITHM, actualAlgorithm); + X509CertImpl newCert = new X509CertImpl(certInfo); + newCert.sign(keyPair.getPrivate(), SHA1WITHRSA); + + return newCert; + } +} \ No newline at end of file