From d0c619a0ad084433514d9b36ddf679b55db91c9b Mon Sep 17 00:00:00 2001 From: shreyashthakare Date: Tue, 17 Jul 2018 00:32:13 +0530 Subject: [PATCH 01/13] BAEL-1960: Custom appender for log4j --- logging-modules/log4j2/pom.xml | 219 +++++++++--------- .../logging/log4j2/appender/MapAppender.java | 58 +++++ .../appender/MapAppenderIntegrationTest.java | 35 +++ .../log4j2/src/test/resources/log4j2.xml | 174 +++++++------- 4 files changed, 297 insertions(+), 189 deletions(-) create mode 100644 logging-modules/log4j2/src/main/java/com/baeldung/logging/log4j2/appender/MapAppender.java create mode 100644 logging-modules/log4j2/src/test/java/com/baeldung/logging/log4j2/appender/MapAppenderIntegrationTest.java diff --git a/logging-modules/log4j2/pom.xml b/logging-modules/log4j2/pom.xml index 89d37e789c..b577931f0f 100644 --- a/logging-modules/log4j2/pom.xml +++ b/logging-modules/log4j2/pom.xml @@ -1,117 +1,126 @@ - - 4.0.0 - log4j2 + + 4.0.0 + log4j2 - - com.baeldung - parent-modules - 1.0.0-SNAPSHOT - ../../ - + + com.baeldung + parent-modules + 1.0.0-SNAPSHOT + ../../ + - - - - org.apache.logging.log4j - log4j-core - ${log4j-core.version} - + + + + org.apache.logging.log4j + log4j-core + ${log4j-core.version} + - - - com.fasterxml.jackson.core - jackson-databind - ${jackson.version} - + + + org.apache.logging.log4j + log4j-api + ${log4j-core.version} + - - - com.fasterxml.jackson.dataformat - jackson-dataformat-xml - ${jackson.version} - - - - com.h2database - h2 - ${h2.version} - - - org.apache.commons - commons-dbcp2 - ${commons-dbcp2.version} - + + + com.fasterxml.jackson.core + jackson-databind + ${jackson.version} + - - - org.apache.logging.log4j - log4j-core - ${log4j-core.version} - test-jar - test - - + + + com.fasterxml.jackson.dataformat + jackson-dataformat-xml + ${jackson.version} + - - - - org.apache.maven.plugins - maven-compiler-plugin - ${maven-compiler-plugin.version} - - none - - - - + + + com.h2database + h2 + ${h2.version} + + + org.apache.commons + commons-dbcp2 + ${commons-dbcp2.version} + - - - integration - - - - org.apache.maven.plugins - maven-surefire-plugin - - - integration-test - - test - - - - **/*ManualTest.java - **/*LiveTest.java - - - **/*IntegrationTest.java - **/*IntTest.java - - - - - - - json - ${java.io.tmpdir}/${maven.build.timestamp}/logfile.json - - - - - - - + + + org.apache.logging.log4j + log4j-core + ${log4j-core.version} + test-jar + test + + - - 2.9.5 - 1.4.193 - 2.1.1 - 2.11.0 - yyyyMMddHHmmss - + + + + org.apache.maven.plugins + maven-compiler-plugin + ${maven-compiler-plugin.version} + + none + + + + + + + + integration + + + + org.apache.maven.plugins + maven-surefire-plugin + + + integration-test + + test + + + + **/*ManualTest.java + **/*LiveTest.java + + + **/*IntegrationTest.java + **/*IntTest.java + + + + + + + json + ${java.io.tmpdir}/${maven.build.timestamp}/logfile.json + + + + + + + + + + 2.9.5 + 1.4.193 + 2.1.1 + 2.11.0 + yyyyMMddHHmmss + diff --git a/logging-modules/log4j2/src/main/java/com/baeldung/logging/log4j2/appender/MapAppender.java b/logging-modules/log4j2/src/main/java/com/baeldung/logging/log4j2/appender/MapAppender.java new file mode 100644 index 0000000000..160ba58395 --- /dev/null +++ b/logging-modules/log4j2/src/main/java/com/baeldung/logging/log4j2/appender/MapAppender.java @@ -0,0 +1,58 @@ +/** + * + */ +package com.baeldung.logging.log4j2.appender; + +import java.io.Serializable; +import java.time.Instant; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; + +import org.apache.logging.log4j.core.Appender; +import org.apache.logging.log4j.core.Core; +import org.apache.logging.log4j.core.Filter; +import org.apache.logging.log4j.core.Layout; +import org.apache.logging.log4j.core.LogEvent; +import org.apache.logging.log4j.core.appender.AbstractAppender; +import org.apache.logging.log4j.core.config.plugins.Plugin; +import org.apache.logging.log4j.core.config.plugins.PluginAttribute; +import org.apache.logging.log4j.core.config.plugins.PluginElement; +import org.apache.logging.log4j.core.config.plugins.PluginFactory; +import org.apache.logging.log4j.core.layout.PatternLayout; + +@Plugin(name = "MapAppender", category = Core.CATEGORY_NAME, elementType = Appender.ELEMENT_TYPE, printObject = true) +public class MapAppender extends AbstractAppender { + + private ConcurrentMap eventMap = new ConcurrentHashMap<>(); + + protected MapAppender(String name, Filter filter, Layout layout) { + super(name, filter, layout); + } + + @PluginFactory + public static MapAppender createAppender(@PluginAttribute("name") String name, @PluginElement("Layout") Layout layout, @PluginElement("Filter") final Filter filter) { + if (name == null) { + LOGGER.error("No name provided for MapAppender"); + return null; + } + if (layout == null) { + layout = PatternLayout.createDefaultLayout(); + } + return new MapAppender(name, filter, layout); + } + + @Override + public void append(LogEvent event) { + eventMap.put(Instant.now() + .toString(), event); + } + + public ConcurrentMap getEventMap() { + return eventMap; + } + + public void setEventMap(ConcurrentMap eventMap) { + this.eventMap = eventMap; + } + +} diff --git a/logging-modules/log4j2/src/test/java/com/baeldung/logging/log4j2/appender/MapAppenderIntegrationTest.java b/logging-modules/log4j2/src/test/java/com/baeldung/logging/log4j2/appender/MapAppenderIntegrationTest.java new file mode 100644 index 0000000000..020aaafc74 --- /dev/null +++ b/logging-modules/log4j2/src/test/java/com/baeldung/logging/log4j2/appender/MapAppenderIntegrationTest.java @@ -0,0 +1,35 @@ +package com.baeldung.logging.log4j2.appender; + +import static org.junit.Assert.assertEquals; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.core.LoggerContext; +import org.apache.logging.log4j.core.config.Configuration; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +@RunWith(JUnit4.class) +public class MapAppenderIntegrationTest { + + private Logger logger; + + @Before + public void setup() { + logger = LogManager.getLogger(MapAppenderIntegrationTest.class); + } + + @Test + public void whenLoggerEmitsLoggingEvent_thenAppenderReceivesEvent() throws Exception { + logger.info("Test from {}", this.getClass() + .getSimpleName()); + LoggerContext context = LoggerContext.getContext(false); + Configuration config = context.getConfiguration(); + MapAppender appender = config.getAppender("MapAppender"); + assertEquals(appender.getEventMap() + .size(), 1); + } + +} diff --git a/logging-modules/log4j2/src/test/resources/log4j2.xml b/logging-modules/log4j2/src/test/resources/log4j2.xml index 83b664a507..d0fd0d088f 100644 --- a/logging-modules/log4j2/src/test/resources/log4j2.xml +++ b/logging-modules/log4j2/src/test/resources/log4j2.xml @@ -1,87 +1,93 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + packages="com.baeldung" status="WARN"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From 380dce8e6e629c7546222cd07ede44099c58608e Mon Sep 17 00:00:00 2001 From: root Date: Wed, 25 Jul 2018 00:21:47 +0530 Subject: [PATCH 02/13] Changes as per suggestion to BAEL-1960 --- .../logging/log4j2/appender/MapAppender.java | 26 ++++++++----------- .../log4j2/src/test/resources/log4j2.xml | 5 +--- 2 files changed, 12 insertions(+), 19 deletions(-) diff --git a/logging-modules/log4j2/src/main/java/com/baeldung/logging/log4j2/appender/MapAppender.java b/logging-modules/log4j2/src/main/java/com/baeldung/logging/log4j2/appender/MapAppender.java index 160ba58395..e9c025f480 100644 --- a/logging-modules/log4j2/src/main/java/com/baeldung/logging/log4j2/appender/MapAppender.java +++ b/logging-modules/log4j2/src/main/java/com/baeldung/logging/log4j2/appender/MapAppender.java @@ -3,46 +3,42 @@ */ package com.baeldung.logging.log4j2.appender; -import java.io.Serializable; import java.time.Instant; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; +import org.apache.logging.log4j.Level; import org.apache.logging.log4j.core.Appender; import org.apache.logging.log4j.core.Core; import org.apache.logging.log4j.core.Filter; -import org.apache.logging.log4j.core.Layout; import org.apache.logging.log4j.core.LogEvent; import org.apache.logging.log4j.core.appender.AbstractAppender; import org.apache.logging.log4j.core.config.plugins.Plugin; import org.apache.logging.log4j.core.config.plugins.PluginAttribute; import org.apache.logging.log4j.core.config.plugins.PluginElement; import org.apache.logging.log4j.core.config.plugins.PluginFactory; -import org.apache.logging.log4j.core.layout.PatternLayout; -@Plugin(name = "MapAppender", category = Core.CATEGORY_NAME, elementType = Appender.ELEMENT_TYPE, printObject = true) +@Plugin(name = "MapAppender", category = Core.CATEGORY_NAME, elementType = Appender.ELEMENT_TYPE, printObject = false) public class MapAppender extends AbstractAppender { private ConcurrentMap eventMap = new ConcurrentHashMap<>(); - protected MapAppender(String name, Filter filter, Layout layout) { - super(name, filter, layout); + protected MapAppender(String name, Filter filter) { + super(name, filter, null); } @PluginFactory - public static MapAppender createAppender(@PluginAttribute("name") String name, @PluginElement("Layout") Layout layout, @PluginElement("Filter") final Filter filter) { - if (name == null) { - LOGGER.error("No name provided for MapAppender"); - return null; - } - if (layout == null) { - layout = PatternLayout.createDefaultLayout(); - } - return new MapAppender(name, filter, layout); + public static MapAppender createAppender(@PluginAttribute("name") String name, @PluginElement("Filter") final Filter filter) { + return new MapAppender(name, filter); } @Override public void append(LogEvent event) { + if (event.getLevel() + .isLessSpecificThan(Level.WARN)) { + error("Unable to log less than WARN level."); + return; + } eventMap.put(Instant.now() .toString(), event); } diff --git a/logging-modules/log4j2/src/test/resources/log4j2.xml b/logging-modules/log4j2/src/test/resources/log4j2.xml index d0fd0d088f..eefa00e1ba 100644 --- a/logging-modules/log4j2/src/test/resources/log4j2.xml +++ b/logging-modules/log4j2/src/test/resources/log4j2.xml @@ -51,10 +51,7 @@ - - - + Date: Wed, 25 Jul 2018 23:24:03 +0530 Subject: [PATCH 03/13] Changes as [er review for BAEL-1960 --- logging-modules/log4j2/pom.xml | 216 +++++++++--------- .../logging/log4j2/appender/MapAppender.java | 2 +- 2 files changed, 108 insertions(+), 110 deletions(-) diff --git a/logging-modules/log4j2/pom.xml b/logging-modules/log4j2/pom.xml index b577931f0f..9d8a523462 100644 --- a/logging-modules/log4j2/pom.xml +++ b/logging-modules/log4j2/pom.xml @@ -1,25 +1,24 @@ - - 4.0.0 - log4j2 + + 4.0.0 + log4j2 - - com.baeldung - parent-modules - 1.0.0-SNAPSHOT - ../../ - - - - - - org.apache.logging.log4j - log4j-core - ${log4j-core.version} - + + com.baeldung + parent-modules + 1.0.0-SNAPSHOT + ../../ + + + + + org.apache.logging.log4j + log4j-core + ${log4j-core.version} + + org.apache.logging.log4j @@ -27,100 +26,99 @@ ${log4j-core.version} + + + com.fasterxml.jackson.core + jackson-databind + ${jackson.version} + - - - com.fasterxml.jackson.core - jackson-databind - ${jackson.version} - + + + com.fasterxml.jackson.dataformat + jackson-dataformat-xml + ${jackson.version} + - - - com.fasterxml.jackson.dataformat - jackson-dataformat-xml - ${jackson.version} - + + + com.h2database + h2 + ${h2.version} + + + org.apache.commons + commons-dbcp2 + ${commons-dbcp2.version} + - - - com.h2database - h2 - ${h2.version} - - - org.apache.commons - commons-dbcp2 - ${commons-dbcp2.version} - + + + org.apache.logging.log4j + log4j-core + ${log4j-core.version} + test-jar + test + + - - - org.apache.logging.log4j - log4j-core - ${log4j-core.version} - test-jar - test - - + + + + org.apache.maven.plugins + maven-compiler-plugin + ${maven-compiler-plugin.version} + + none + + + + - - - - org.apache.maven.plugins - maven-compiler-plugin - ${maven-compiler-plugin.version} - - none - - - - + + + integration + + + + org.apache.maven.plugins + maven-surefire-plugin + + + integration-test + + test + + + + **/*ManualTest.java + **/*LiveTest.java + + + **/*IntegrationTest.java + **/*IntTest.java + + + + + + + json + ${java.io.tmpdir}/${maven.build.timestamp}/logfile.json + + + + + + + - - - integration - - - - org.apache.maven.plugins - maven-surefire-plugin - - - integration-test - - test - - - - **/*ManualTest.java - **/*LiveTest.java - - - **/*IntegrationTest.java - **/*IntTest.java - - - - - - - json - ${java.io.tmpdir}/${maven.build.timestamp}/logfile.json - - - - - - - + + 2.9.5 + 1.4.193 + 2.1.1 + 2.11.0 + yyyyMMddHHmmss + - - 2.9.5 - 1.4.193 - 2.1.1 - 2.11.0 - yyyyMMddHHmmss - - - + \ No newline at end of file diff --git a/logging-modules/log4j2/src/main/java/com/baeldung/logging/log4j2/appender/MapAppender.java b/logging-modules/log4j2/src/main/java/com/baeldung/logging/log4j2/appender/MapAppender.java index e9c025f480..2015b6d573 100644 --- a/logging-modules/log4j2/src/main/java/com/baeldung/logging/log4j2/appender/MapAppender.java +++ b/logging-modules/log4j2/src/main/java/com/baeldung/logging/log4j2/appender/MapAppender.java @@ -18,7 +18,7 @@ import org.apache.logging.log4j.core.config.plugins.PluginAttribute; import org.apache.logging.log4j.core.config.plugins.PluginElement; import org.apache.logging.log4j.core.config.plugins.PluginFactory; -@Plugin(name = "MapAppender", category = Core.CATEGORY_NAME, elementType = Appender.ELEMENT_TYPE, printObject = false) +@Plugin(name = "MapAppender", category = Core.CATEGORY_NAME, elementType = Appender.ELEMENT_TYPE) public class MapAppender extends AbstractAppender { private ConcurrentMap eventMap = new ConcurrentHashMap<>(); From 73bd03a331ac2e6f2e6b1e7e9263fe81b275ca6a Mon Sep 17 00:00:00 2001 From: root Date: Wed, 25 Jul 2018 23:27:14 +0530 Subject: [PATCH 04/13] Changes for formatting as per suggestion. --- logging-modules/log4j2/pom.xml | 213 +++++++++++++++++---------------- 1 file changed, 107 insertions(+), 106 deletions(-) diff --git a/logging-modules/log4j2/pom.xml b/logging-modules/log4j2/pom.xml index 9d8a523462..f6b3fea227 100644 --- a/logging-modules/log4j2/pom.xml +++ b/logging-modules/log4j2/pom.xml @@ -1,24 +1,25 @@ - - 4.0.0 - log4j2 + + 4.0.0 + log4j2 - - com.baeldung - parent-modules - 1.0.0-SNAPSHOT - ../../ - + + com.baeldung + parent-modules + 1.0.0-SNAPSHOT + ../../ + + + + + + org.apache.logging.log4j + log4j-core + ${log4j-core.version} + - - - - org.apache.logging.log4j - log4j-core - ${log4j-core.version} - - org.apache.logging.log4j @@ -26,99 +27,99 @@ ${log4j-core.version} - - - com.fasterxml.jackson.core - jackson-databind - ${jackson.version} - + + + com.fasterxml.jackson.core + jackson-databind + ${jackson.version} + - - - com.fasterxml.jackson.dataformat - jackson-dataformat-xml - ${jackson.version} - + + + com.fasterxml.jackson.dataformat + jackson-dataformat-xml + ${jackson.version} + - - - com.h2database - h2 - ${h2.version} - - - org.apache.commons - commons-dbcp2 - ${commons-dbcp2.version} - + + + com.h2database + h2 + ${h2.version} + + + org.apache.commons + commons-dbcp2 + ${commons-dbcp2.version} + - - - org.apache.logging.log4j - log4j-core - ${log4j-core.version} - test-jar - test - - + + + org.apache.logging.log4j + log4j-core + ${log4j-core.version} + test-jar + test + + - - - - org.apache.maven.plugins - maven-compiler-plugin - ${maven-compiler-plugin.version} - - none - - - - + + + + org.apache.maven.plugins + maven-compiler-plugin + ${maven-compiler-plugin.version} + + none + + + + - - - integration - - - - org.apache.maven.plugins - maven-surefire-plugin - - - integration-test - - test - - - - **/*ManualTest.java - **/*LiveTest.java - - - **/*IntegrationTest.java - **/*IntTest.java - - - - - - - json - ${java.io.tmpdir}/${maven.build.timestamp}/logfile.json - - - - - - - + + + integration + + + + org.apache.maven.plugins + maven-surefire-plugin + + + integration-test + + test + + + + **/*ManualTest.java + **/*LiveTest.java + + + **/*IntegrationTest.java + **/*IntTest.java + + + + + + + json + ${java.io.tmpdir}/${maven.build.timestamp}/logfile.json + + + + + + + - - 2.9.5 - 1.4.193 - 2.1.1 - 2.11.0 - yyyyMMddHHmmss - + + 2.9.5 + 1.4.193 + 2.1.1 + 2.11.0 + yyyyMMddHHmmss + \ No newline at end of file From 74787e9026ef52645fcc3178869624b91bfee6c6 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 25 Jul 2018 23:30:08 +0530 Subject: [PATCH 05/13] BAEL-1960. Copied pom.xml from master and pasted my changes against it. --- logging-modules/log4j2/pom.xml | 213 ++++++++++++++++----------------- 1 file changed, 106 insertions(+), 107 deletions(-) diff --git a/logging-modules/log4j2/pom.xml b/logging-modules/log4j2/pom.xml index f6b3fea227..9d8a523462 100644 --- a/logging-modules/log4j2/pom.xml +++ b/logging-modules/log4j2/pom.xml @@ -1,25 +1,24 @@ - - 4.0.0 - log4j2 + + 4.0.0 + log4j2 - - com.baeldung - parent-modules - 1.0.0-SNAPSHOT - ../../ - - - - - - org.apache.logging.log4j - log4j-core - ${log4j-core.version} - + + com.baeldung + parent-modules + 1.0.0-SNAPSHOT + ../../ + + + + + org.apache.logging.log4j + log4j-core + ${log4j-core.version} + + org.apache.logging.log4j @@ -27,99 +26,99 @@ ${log4j-core.version} - - - com.fasterxml.jackson.core - jackson-databind - ${jackson.version} - + + + com.fasterxml.jackson.core + jackson-databind + ${jackson.version} + - - - com.fasterxml.jackson.dataformat - jackson-dataformat-xml - ${jackson.version} - + + + com.fasterxml.jackson.dataformat + jackson-dataformat-xml + ${jackson.version} + - - - com.h2database - h2 - ${h2.version} - - - org.apache.commons - commons-dbcp2 - ${commons-dbcp2.version} - + + + com.h2database + h2 + ${h2.version} + + + org.apache.commons + commons-dbcp2 + ${commons-dbcp2.version} + - - - org.apache.logging.log4j - log4j-core - ${log4j-core.version} - test-jar - test - - + + + org.apache.logging.log4j + log4j-core + ${log4j-core.version} + test-jar + test + + - - - - org.apache.maven.plugins - maven-compiler-plugin - ${maven-compiler-plugin.version} - - none - - - - + + + + org.apache.maven.plugins + maven-compiler-plugin + ${maven-compiler-plugin.version} + + none + + + + - - - integration - - - - org.apache.maven.plugins - maven-surefire-plugin - - - integration-test - - test - - - - **/*ManualTest.java - **/*LiveTest.java - - - **/*IntegrationTest.java - **/*IntTest.java - - - - - - - json - ${java.io.tmpdir}/${maven.build.timestamp}/logfile.json - - - - - - - + + + integration + + + + org.apache.maven.plugins + maven-surefire-plugin + + + integration-test + + test + + + + **/*ManualTest.java + **/*LiveTest.java + + + **/*IntegrationTest.java + **/*IntTest.java + + + + + + + json + ${java.io.tmpdir}/${maven.build.timestamp}/logfile.json + + + + + + + - - 2.9.5 - 1.4.193 - 2.1.1 - 2.11.0 - yyyyMMddHHmmss - + + 2.9.5 + 1.4.193 + 2.1.1 + 2.11.0 + yyyyMMddHHmmss + \ No newline at end of file From cd4dbef187d546940ed816c685d84d54b18f6ccf Mon Sep 17 00:00:00 2001 From: root Date: Thu, 26 Jul 2018 12:49:30 +0530 Subject: [PATCH 06/13] Chnages for spaces instead of tabs. --- logging-modules/log4j2/pom.xml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/logging-modules/log4j2/pom.xml b/logging-modules/log4j2/pom.xml index 9d8a523462..65da318636 100644 --- a/logging-modules/log4j2/pom.xml +++ b/logging-modules/log4j2/pom.xml @@ -19,12 +19,12 @@ ${log4j-core.version} - - - org.apache.logging.log4j - log4j-api - ${log4j-core.version} - + + + org.apache.logging.log4j + log4j-api + ${log4j-core.version} + From 2f0b1b46c9feb66ecc7ec622f03626bf824352a3 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 26 Jul 2018 12:54:28 +0530 Subject: [PATCH 07/13] Changes for spaces instead of tabs. --- .../log4j2/src/test/resources/log4j2.xml | 175 +++++++++--------- 1 file changed, 87 insertions(+), 88 deletions(-) diff --git a/logging-modules/log4j2/src/test/resources/log4j2.xml b/logging-modules/log4j2/src/test/resources/log4j2.xml index eefa00e1ba..246ffb0707 100644 --- a/logging-modules/log4j2/src/test/resources/log4j2.xml +++ b/logging-modules/log4j2/src/test/resources/log4j2.xml @@ -1,90 +1,89 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From 0be91964dfda73817a65d747e1d885cc838d4be1 Mon Sep 17 00:00:00 2001 From: Shreyash Date: Tue, 7 Aug 2018 13:14:21 +0530 Subject: [PATCH 08/13] BAEL-1164 hzaelcast Jet. --- hazelcast/pom.xml | 20 +++----- .../baeldung/hazelcast/jet/WordCounter.java | 51 +++++++++++++++++++ .../hazelcast/jet/WordCounterUnitTest.java | 21 ++++++++ 3 files changed, 80 insertions(+), 12 deletions(-) create mode 100644 hazelcast/src/main/java/com/baeldung/hazelcast/jet/WordCounter.java create mode 100644 hazelcast/src/test/java/com/baeldung/hazelcast/jet/WordCounterUnitTest.java diff --git a/hazelcast/pom.xml b/hazelcast/pom.xml index cc366cd0a6..705792ad05 100644 --- a/hazelcast/pom.xml +++ b/hazelcast/pom.xml @@ -13,16 +13,12 @@ - - com.hazelcast - hazelcast - ${hazelcast.version} - - - com.hazelcast - hazelcast-client - ${hazelcast.version} - + + + com.hazelcast.jet + hazelcast-jet + ${hazelcast.jet.version} + @@ -36,8 +32,8 @@ - - 3.8.4 + + 0.6 \ No newline at end of file diff --git a/hazelcast/src/main/java/com/baeldung/hazelcast/jet/WordCounter.java b/hazelcast/src/main/java/com/baeldung/hazelcast/jet/WordCounter.java new file mode 100644 index 0000000000..971986bcae --- /dev/null +++ b/hazelcast/src/main/java/com/baeldung/hazelcast/jet/WordCounter.java @@ -0,0 +1,51 @@ +package com.baeldung.hazelcast.jet; + +import java.util.List; +import java.util.Map; + +import static com.hazelcast.jet.Traversers.traverseArray; +import static com.hazelcast.jet.aggregate.AggregateOperations.counting; +import static com.hazelcast.jet.function.DistributedFunctions.wholeItem; + +import com.hazelcast.jet.Jet; +import com.hazelcast.jet.JetInstance; +import com.hazelcast.jet.pipeline.Pipeline; +import com.hazelcast.jet.pipeline.Sinks; +import com.hazelcast.jet.pipeline.Sources; + +public class WordCounter { + + private static final String LIST_NAME = "textList"; + + private static final String MAP_NAME = "countMap"; + + private Pipeline createPipeLine() { + Pipeline p = Pipeline.create(); + p.drawFrom(Sources. list(LIST_NAME)) + .flatMap(word -> traverseArray(word.toLowerCase() + .split("\\W+"))) + .filter(word -> !word.isEmpty()) + .groupingKey(wholeItem()) + .aggregate(counting()) + .drainTo(Sinks.map(MAP_NAME)); + return p; + } + + public Long countWord(List sentences, String word) { + long count = 0; + JetInstance jet = Jet.newJetInstance(); + try { + List textList = jet.getList(LIST_NAME); + textList.addAll(sentences); + Pipeline p = createPipeLine(); + jet.newJob(p) + .join(); + Map counts = jet.getMap(MAP_NAME); + count = counts.get(word); + } finally { + Jet.shutdownAll(); + } + return count; + } + +} diff --git a/hazelcast/src/test/java/com/baeldung/hazelcast/jet/WordCounterUnitTest.java b/hazelcast/src/test/java/com/baeldung/hazelcast/jet/WordCounterUnitTest.java new file mode 100644 index 0000000000..95596b3860 --- /dev/null +++ b/hazelcast/src/test/java/com/baeldung/hazelcast/jet/WordCounterUnitTest.java @@ -0,0 +1,21 @@ +package com.baeldung.hazelcast.jet; + +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; + +public class WordCounterUnitTest { + + @Test + public void whenGivenSentencesAndWord_ThenReturnCountOfWord() { + List sentences = new ArrayList<>(); + sentences.add("The first second was alright, but the second second was tough."); + WordCounter wordCounter = new WordCounter(); + long countSecond = wordCounter.countWord(sentences, "second"); + assertTrue(countSecond == 3); + } + +} From fb0a6ab53977d540297bbe2cde1c2dbcb72e725f Mon Sep 17 00:00:00 2001 From: DOHA Date: Thu, 9 Aug 2018 15:37:13 +0300 Subject: [PATCH 09/13] upgrade and cleanup spring-thymeleaf --- spring-thymeleaf/pom.xml | 100 +++++++----------- .../thymeleaf/config/WebMVCConfig.java | 21 ++-- .../thymeleaf/config/WebMVCSecurity.java | 2 +- .../controller/FragmentsIntegrationTest.java | 27 +++-- 4 files changed, 64 insertions(+), 86 deletions(-) diff --git a/spring-thymeleaf/pom.xml b/spring-thymeleaf/pom.xml index c023dcdb5f..0926728aba 100644 --- a/spring-thymeleaf/pom.xml +++ b/spring-thymeleaf/pom.xml @@ -1,5 +1,5 @@ + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 com.baeldung spring-thymeleaf @@ -8,8 +8,9 @@ com.baeldung - parent-modules - 1.0.0-SNAPSHOT + parent-spring-5 + 0.0.1-SNAPSHOT + ../parent-spring-5 @@ -17,7 +18,7 @@ org.springframework spring-context - ${org.springframework-version} + ${spring.version} @@ -29,19 +30,38 @@ org.springframework spring-webmvc - ${org.springframework-version} + ${spring.version} + + + org.springframework.data + spring-data-commons + ${spring-data.version} + + + + javax.validation + validation-api + ${javax.validation-version} + + + org.hibernate.validator + hibernate-validator + ${hibernate-validator.version} + + org.springframework.security spring-security-web - ${springframework-security.version} + ${spring-security.version} org.springframework.security spring-security-config - ${springframework-security.version} + ${spring-security.version} + org.thymeleaf @@ -50,10 +70,9 @@ org.thymeleaf - thymeleaf-spring4 + thymeleaf-spring5 ${org.thymeleaf-version} - nz.net.ultraq.thymeleaf thymeleaf-layout-dialect @@ -64,60 +83,29 @@ thymeleaf-extras-java8time ${org.thymeleaf.extras-version} + javax.servlet javax.servlet-api - ${javax.servlet-version} + ${javax.servlet-api.version} provided - - - javax.validation - validation-api - ${javax.validation-version} - - - org.hibernate - hibernate-validator - ${hibernate-validator.version} - - + org.springframework spring-test - ${org.springframework-version} + ${spring.version} test - org.springframework.security spring-security-test - ${springframework-security.version} + ${spring-security.version} test - - - - - - org.springframework.data - spring-data-commons - ${springFramework-data.version} - @@ -131,7 +119,7 @@ false - + org.codehaus.cargo cargo-maven2-plugin @@ -151,7 +139,7 @@ - + org.apache.tomcat.maven tomcat7-maven-plugin @@ -176,22 +164,14 @@ - - 4.3.4.RELEASE - 4.2.0.RELEASE - 2.0.7.RELEASE - 3.1.0 - + 2.0.9.RELEASE 3.0.9.RELEASE - 3.0.0.RELEASE - 2.1.2 - - 1.1.0.Final - 5.3.3.Final - 5.2.5.Final + 3.0.1.RELEASE + 2.3.0 + 2.0.1.Final + 6.0.11.Final - 2.6 1.6.1 2.2 diff --git a/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/config/WebMVCConfig.java b/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/config/WebMVCConfig.java index 2e76877199..34a59ea391 100644 --- a/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/config/WebMVCConfig.java +++ b/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/config/WebMVCConfig.java @@ -2,6 +2,9 @@ package com.baeldung.thymeleaf.config; import java.util.Locale; +import nz.net.ultraq.thymeleaf.LayoutDialect; +import nz.net.ultraq.thymeleaf.decorators.strategies.GroupingStrategy; + import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; import org.springframework.context.annotation.Bean; @@ -15,23 +18,20 @@ import org.springframework.web.servlet.ViewResolver; import org.springframework.web.servlet.config.annotation.EnableWebMvc; import org.springframework.web.servlet.config.annotation.InterceptorRegistry; import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; -import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; import org.springframework.web.servlet.i18n.LocaleChangeInterceptor; import org.springframework.web.servlet.i18n.SessionLocaleResolver; -import org.thymeleaf.TemplateEngine; import org.thymeleaf.extras.java8time.dialect.Java8TimeDialect; -import org.thymeleaf.spring4.SpringTemplateEngine; -import org.thymeleaf.spring4.templateresolver.SpringResourceTemplateResolver; -import org.thymeleaf.spring4.view.ThymeleafViewResolver; +import org.thymeleaf.spring5.ISpringTemplateEngine; +import org.thymeleaf.spring5.SpringTemplateEngine; +import org.thymeleaf.spring5.templateresolver.SpringResourceTemplateResolver; +import org.thymeleaf.spring5.view.ThymeleafViewResolver; import org.thymeleaf.templatemode.TemplateMode; import org.thymeleaf.templateresolver.ITemplateResolver; import com.baeldung.thymeleaf.formatter.NameFormatter; import com.baeldung.thymeleaf.utils.ArrayUtil; -import nz.net.ultraq.thymeleaf.LayoutDialect; -import nz.net.ultraq.thymeleaf.decorators.strategies.GroupingStrategy; - @Configuration @EnableWebMvc @ComponentScan({ "com.baeldung.thymeleaf" }) @@ -39,10 +39,11 @@ import nz.net.ultraq.thymeleaf.decorators.strategies.GroupingStrategy; * Java configuration file that is used for Spring MVC and Thymeleaf * configurations */ -public class WebMVCConfig extends WebMvcConfigurerAdapter implements ApplicationContextAware { +public class WebMVCConfig implements WebMvcConfigurer, ApplicationContextAware { private ApplicationContext applicationContext; + @Override public void setApplicationContext(ApplicationContext applicationContext) { this.applicationContext = applicationContext; } @@ -77,7 +78,7 @@ public class WebMVCConfig extends WebMvcConfigurerAdapter implements Application return resolver; } - private TemplateEngine templateEngine(ITemplateResolver templateResolver) { + private ISpringTemplateEngine templateEngine(ITemplateResolver templateResolver) { SpringTemplateEngine engine = new SpringTemplateEngine(); engine.addDialect(new LayoutDialect(new GroupingStrategy())); engine.addDialect(new Java8TimeDialect()); diff --git a/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/config/WebMVCSecurity.java b/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/config/WebMVCSecurity.java index 46bff38a3f..ea51ca3cd9 100644 --- a/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/config/WebMVCSecurity.java +++ b/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/config/WebMVCSecurity.java @@ -27,7 +27,7 @@ public class WebMVCSecurity extends WebSecurityConfigurerAdapter { @Override protected void configure(final AuthenticationManagerBuilder auth) throws Exception { - auth.inMemoryAuthentication().withUser("user1").password("user1Pass").authorities("ROLE_USER"); + auth.inMemoryAuthentication().withUser("user1").password("{noop}user1Pass").authorities("ROLE_USER"); } @Override diff --git a/spring-thymeleaf/src/test/java/com/baeldung/thymeleaf/controller/FragmentsIntegrationTest.java b/spring-thymeleaf/src/test/java/com/baeldung/thymeleaf/controller/FragmentsIntegrationTest.java index 5bc45d0004..c6158b76b1 100644 --- a/spring-thymeleaf/src/test/java/com/baeldung/thymeleaf/controller/FragmentsIntegrationTest.java +++ b/spring-thymeleaf/src/test/java/com/baeldung/thymeleaf/controller/FragmentsIntegrationTest.java @@ -1,10 +1,22 @@ package com.baeldung.thymeleaf.controller; +import static org.hamcrest.Matchers.containsString; +import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.user; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import javax.servlet.Filter; + import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.mock.web.MockHttpSession; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.request.RequestPostProcessor; import org.springframework.test.web.servlet.setup.MockMvcBuilders; @@ -15,21 +27,6 @@ import com.baeldung.thymeleaf.config.WebApp; import com.baeldung.thymeleaf.config.WebMVCConfig; import com.baeldung.thymeleaf.config.WebMVCSecurity; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.test.context.web.WebAppConfiguration; - -import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.user; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - -import javax.servlet.Filter; - -import static org.hamcrest.Matchers.containsString; - @RunWith(SpringJUnit4ClassRunner.class) @WebAppConfiguration @ContextConfiguration(classes = { WebApp.class, WebMVCConfig.class, WebMVCSecurity.class, InitSecurity.class }) From e7485a181318f1cc0f2a54bdb4fe0d437594207f Mon Sep 17 00:00:00 2001 From: Dhawal Kapil Date: Thu, 9 Aug 2018 21:43:44 +0530 Subject: [PATCH 10/13] Task/bael 8020 (#4919) * BAEL-8020 Fix surefire configs of spring-5 projects -Removed surefire configurations from spring-5 projects * BAEL-8020 Fix surefire configs of spring-5 projects -Fixed surefire and junit configuration of spring-5-** projects -Fixed mavensurefire plugin to execute JUnit5 tests BAEL-8125 * BAEL-8020 Fix sure fire configs in spring5 project -Fixed dependency for junit-5 * BAEL-8020 Fix sure fire configs in spring5 project -Fixed dependency for junit5-migration * BAEL-8020 Fix surefire configs -Updated maven war plugin to 3.0.0 * BAEL-8020 Fix surefire configs -Upgraded surefire custom logger api version to 2.21.0 for all child projects * BAEL-8020 -Deleted empty test SpringBootMvcApplicationTests.java in spring-boot-mvc. -Renamed SpringBootMvcApplicationTests.java correct in spring-boot-vue * BAEL-8020 Fix surfire configs -Added junit vintage dependency to run junit4 tests --- core-java-sun/pom.xml | 2 +- core-java/pom.xml | 2 +- java-numbers/pom.xml | 2 +- jee-7/pom.xml | 2 +- mustache/pom.xml | 2 +- parent-boot-2/pom.xml | 107 ++++-------------- pom.xml | 45 +++++++- spring-5-mvc/pom.xml | 18 --- spring-5-reactive-client/pom.xml | 61 +--------- spring-5-reactive/pom.xml | 55 --------- spring-5-security/pom.xml | 16 --- ...nMemoryAuthControllerIntegrationTest.java} | 2 +- spring-5/pom.xml | 55 --------- .../SpringBootMvcApplicationTests.java | 16 --- ... => SpringBootMvcApplicationUnitTest.java} | 2 +- spring-boot/pom.xml | 1 + .../spring-cloud-connectors-heroku/pom.xml | 2 +- spring-reactive-kotlin/pom.xml | 3 - spring-rest-embedded-tomcat/pom.xml | 1 - testing-modules/junit-5/pom.xml | 6 +- testing-modules/junit5-migration/pom.xml | 6 +- testing-modules/test-containers/pom.xml | 2 +- 22 files changed, 83 insertions(+), 325 deletions(-) rename spring-5-security/src/test/java/com/baeldung/inmemory/{InMemoryAuthControllerTest.java => InMemoryAuthControllerIntegrationTest.java} (97%) delete mode 100644 spring-boot-mvc/src/test/java/com/baeldung/springbootmvc/SpringBootMvcApplicationTests.java rename spring-boot-vue/src/test/java/com/baeldung/springbootmvc/{SpringBootMvcApplicationTests.java => SpringBootMvcApplicationUnitTest.java} (96%) diff --git a/core-java-sun/pom.xml b/core-java-sun/pom.xml index f489f3b030..7292335232 100644 --- a/core-java-sun/pom.xml +++ b/core-java-sun/pom.xml @@ -303,7 +303,7 @@ 1.7.0 - 2.19.1 + 2.21.0 1.8.0 3.0.2 diff --git a/core-java/pom.xml b/core-java/pom.xml index b83cb478d4..3f44851f97 100644 --- a/core-java/pom.xml +++ b/core-java/pom.xml @@ -530,7 +530,7 @@ 3.10.0 - 2.19.1 + 2.21.0 4.3.4.RELEASE 1.5.8.RELEASE diff --git a/java-numbers/pom.xml b/java-numbers/pom.xml index a9fb556517..bf4d3e8792 100644 --- a/java-numbers/pom.xml +++ b/java-numbers/pom.xml @@ -156,7 +156,7 @@ 1.19 1.19 - 2.19.1 + 2.21.0 3.0.0-M1 3.0.2 diff --git a/jee-7/pom.xml b/jee-7/pom.xml index d0246f650a..fbf102185d 100644 --- a/jee-7/pom.xml +++ b/jee-7/pom.xml @@ -418,7 +418,7 @@ 1.0.0.Final 2.6 4.2.3.RELEASE - 2.17 + 2.21.0 1.1.2 2.4 2.2.14 diff --git a/mustache/pom.xml b/mustache/pom.xml index 6012c9a15a..d385246182 100644 --- a/mustache/pom.xml +++ b/mustache/pom.xml @@ -153,7 +153,7 @@ 3.7.0 - 2.19.1 + 2.21.0 0.8 3.3.7 1.8 diff --git a/parent-boot-2/pom.xml b/parent-boot-2/pom.xml index ab6162a5a5..2fc46e4c28 100644 --- a/parent-boot-2/pom.xml +++ b/parent-boot-2/pom.xml @@ -8,18 +8,27 @@ Parent for all Spring Boot 2 modules - org.springframework.boot - spring-boot-starter-parent - 2.0.1.RELEASE - + com.baeldung + parent-modules + 1.0.0-SNAPSHOT + + + + org.springframework.boot + spring-boot-dependencies + 2.0.1.RELEASE + pom + import + + + io.rest-assured rest-assured - ${rest-assured.version} - + org.springframework.boot spring-boot-starter-test @@ -27,79 +36,16 @@ - - - - org.springframework.boot - spring-boot-maven-plugin - - - org.apache.maven.plugins - maven-surefire-plugin - ${maven-surefire-plugin.version} - - 3 - true - - **/*IntegrationTest.java - **/*IntTest.java - **/*LongRunningUnitTest.java - **/*ManualTest.java - **/*LiveTest.java - - - - - org.apache.maven.plugins - maven-compiler-plugin - ${maven-compiler-plugin.version} - - ${maven.compiler.source} - ${maven.compiler.target} - - - - - + + + + org.springframework.boot + spring-boot-maven-plugin + 2.0.1.RELEASE + + + - - integration - - - - org.apache.maven.plugins - maven-surefire-plugin - - - integration-test - - test - - - - **/*ManualTest.java - **/*LiveTest.java - **/AutoconfigurationTest.java - **/*UnitTest.java - - - **/*IntegrationTest.java - **/*IntTest.java - */EthControllerTestOne.java - **/*EntryPointsTest.java - - - - - - - json - - - - - - thin-jar @@ -122,13 +68,8 @@ - UTF-8 - UTF-8 - 1.8 3.1.0 - 1.8 - 1.8 1.0.11.RELEASE diff --git a/pom.xml b/pom.xml index a9aaff3e22..978e27f055 100644 --- a/pom.xml +++ b/pom.xml @@ -43,9 +43,15 @@ org.junit.jupiter junit-jupiter-engine - ${junit.jupiter.version} + ${junit-jupiter.version} test + + org.junit.jupiter + junit-jupiter-api + ${junit-jupiter.version} + test + org.hamcrest hamcrest-core @@ -70,6 +76,14 @@ ${mockito.version} test + + org.apache.maven.surefire + surefire-logger-api + ${maven-surefire-plugin.version} + + test + true + @@ -98,6 +112,23 @@ **/*LiveTest.java + + + org.junit.platform + junit-platform-surefire-provider + ${junit-platform.version} + + + org.junit.jupiter + junit-jupiter-engine + ${junit-jupiter.version} + + + org.junit.vintage + junit-vintage-engine + ${junit-jupiter.version} + + org.apache.maven.plugins @@ -187,6 +218,10 @@ + + maven-war-plugin + ${maven-war-plugin.version} + @@ -406,6 +441,7 @@ spring-4 spring-5 spring-5-reactive + spring-5-reactive-client spring-5-mvc spring-5-security spring-activiti @@ -663,6 +699,7 @@ spring-4 spring-5 spring-5-reactive + spring-5-reactive-client spring-5-mvc spring-5-security spring-activiti @@ -942,6 +979,7 @@ spark-java spring-4 spring-5-reactive + spring-5-reactive-client spring-5-mvc spring-5-security spring-activiti @@ -1220,7 +1258,7 @@ 2.19.1 2.5 1.4 - 2.6 + 3.0.0 3.1.0 1.2 2.3.1 @@ -1228,7 +1266,8 @@ 1.2 2.5.0 1.3 - 5.0.2 + 1.2.0 + 5.2.0 0.3.1 2.5.1 0.0.1 diff --git a/spring-5-mvc/pom.xml b/spring-5-mvc/pom.xml index 0408550c79..2d28eb741e 100644 --- a/spring-5-mvc/pom.xml +++ b/spring-5-mvc/pom.xml @@ -82,11 +82,6 @@ spring-boot-starter-test test - - junit - junit - test - com.jayway.restassured rest-assured @@ -137,19 +132,6 @@ - - org.apache.maven.plugins - maven-surefire-plugin - - - false - - **/*IntegrationTest.java - **/*IntTest.java - **/*LiveTest.java - - - diff --git a/spring-5-reactive-client/pom.xml b/spring-5-reactive-client/pom.xml index 9388ee83c1..f60832d545 100644 --- a/spring-5-reactive-client/pom.xml +++ b/spring-5-reactive-client/pom.xml @@ -11,8 +11,8 @@ spring 5 sample project about new features - parent-boot-2 com.baeldung + parent-boot-2 0.0.1-SNAPSHOT ../parent-boot-2 @@ -43,20 +43,6 @@ javax.json.bind javax.json.bind-api - - - - - - - - - - - - - - org.apache.geronimo.specs geronimo-json_1.1_spec @@ -102,28 +88,6 @@ test - - org.junit.jupiter - junit-jupiter-api - - - org.junit.jupiter - junit-jupiter-engine - test - - - org.junit.platform - junit-platform-surefire-provider - ${junit.platform.version} - test - - - org.junit.platform - junit-platform-runner - ${junit.platform.version} - test - - org.projectlombok lombok @@ -145,22 +109,6 @@ JAR - - - org.apache.maven.plugins - maven-surefire-plugin - - 3 - true - methods - true - - **/*IntegrationTest.java - **/*IntTest.java - **/*LiveTest.java - - - @@ -186,13 +134,6 @@ - UTF-8 - UTF-8 - 1.8 - 1.0.0 - 5.0.0 - 2.20 - 5.0.2.RELEASE 1.0.1.RELEASE 1.1.3 1.0 diff --git a/spring-5-reactive/pom.xml b/spring-5-reactive/pom.xml index acc82be0d1..f89fd45581 100644 --- a/spring-5-reactive/pom.xml +++ b/spring-5-reactive/pom.xml @@ -43,20 +43,6 @@ org.springframework.boot spring-boot-starter-actuator - - - - - - - - - - - - - - org.projectlombok lombok @@ -100,28 +86,6 @@ ${commons-collections4.version} test - - - org.junit.jupiter - junit-jupiter-api - - - org.junit.jupiter - junit-jupiter-engine - test - - - org.junit.platform - junit-platform-surefire-provider - ${junit.platform.version} - test - - - org.junit.platform - junit-platform-runner - ${junit.platform.version} - test - org.apache.commons commons-lang3 @@ -159,29 +123,10 @@ JAR - - - org.apache.maven.plugins - maven-surefire-plugin - - 3 - true - methods - true - - **/*IntegrationTest.java - **/*IntTest.java - **/*LiveTest.java - - - - 1.0.0 - 5.0.2 - 2.20 1.0.1.RELEASE 2.1.12 1.1.3 diff --git a/spring-5-security/pom.xml b/spring-5-security/pom.xml index 7024e6f873..ebcd6556a4 100644 --- a/spring-5-security/pom.xml +++ b/spring-5-security/pom.xml @@ -76,22 +76,6 @@ JAR - - - org.apache.maven.plugins - maven-surefire-plugin - - 3 - true - methods - true - - **/*IntegrationTest.java - **/*IntTest.java - **/*LiveTest.java - - - diff --git a/spring-5-security/src/test/java/com/baeldung/inmemory/InMemoryAuthControllerTest.java b/spring-5-security/src/test/java/com/baeldung/inmemory/InMemoryAuthControllerIntegrationTest.java similarity index 97% rename from spring-5-security/src/test/java/com/baeldung/inmemory/InMemoryAuthControllerTest.java rename to spring-5-security/src/test/java/com/baeldung/inmemory/InMemoryAuthControllerIntegrationTest.java index 7a8ea7b248..9d08cb7cfa 100644 --- a/spring-5-security/src/test/java/com/baeldung/inmemory/InMemoryAuthControllerTest.java +++ b/spring-5-security/src/test/java/com/baeldung/inmemory/InMemoryAuthControllerIntegrationTest.java @@ -14,7 +14,7 @@ import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) @SpringBootTest(classes = InMemoryAuthApplication.class, webEnvironment = WebEnvironment.RANDOM_PORT) -public class InMemoryAuthControllerTest { +public class InMemoryAuthControllerIntegrationTest { @Autowired private TestRestTemplate template; diff --git a/spring-5/pom.xml b/spring-5/pom.xml index e37833ff94..9f60b8a364 100644 --- a/spring-5/pom.xml +++ b/spring-5/pom.xml @@ -41,18 +41,6 @@ javax.json.bind javax.json.bind-api - - - - - - - - - - - - org.apache.geronimo.specs geronimo-json_1.1_spec @@ -85,45 +73,21 @@ org.springframework spring-test - - org.springframework.boot - spring-boot-starter-test - test - org.springframework.security spring-security-test test - org.apache.commons commons-collections4 ${commons-collections4.version} test - org.junit.jupiter junit-jupiter-api - - org.junit.jupiter - junit-jupiter-engine - test - - - org.junit.platform - junit-platform-surefire-provider - ${junit.platform.version} - test - - - org.junit.platform - junit-platform-runner - ${junit.platform.version} - test - org.springframework.restdocs @@ -147,22 +111,6 @@ JAR - - - org.apache.maven.plugins - maven-surefire-plugin - - 3 - true - methods - true - - **/*IntegrationTest.java - **/*IntTest.java - **/*LiveTest.java - - - org.asciidoctor asciidoctor-maven-plugin @@ -190,9 +138,6 @@ - 1.0.0 - 5.0.2.RELEASE - 1.0.1.RELEASE 1.0 1.5.6 4.1 diff --git a/spring-boot-mvc/src/test/java/com/baeldung/springbootmvc/SpringBootMvcApplicationTests.java b/spring-boot-mvc/src/test/java/com/baeldung/springbootmvc/SpringBootMvcApplicationTests.java deleted file mode 100644 index 1add635ed8..0000000000 --- a/spring-boot-mvc/src/test/java/com/baeldung/springbootmvc/SpringBootMvcApplicationTests.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.baeldung.springbootmvc; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -@RunWith(SpringRunner.class) -@SpringBootTest -public class SpringBootMvcApplicationTests { - - @Test - public void contextLoads() { - } - -} diff --git a/spring-boot-vue/src/test/java/com/baeldung/springbootmvc/SpringBootMvcApplicationTests.java b/spring-boot-vue/src/test/java/com/baeldung/springbootmvc/SpringBootMvcApplicationUnitTest.java similarity index 96% rename from spring-boot-vue/src/test/java/com/baeldung/springbootmvc/SpringBootMvcApplicationTests.java rename to spring-boot-vue/src/test/java/com/baeldung/springbootmvc/SpringBootMvcApplicationUnitTest.java index 6364351eb3..567b239ed2 100644 --- a/spring-boot-vue/src/test/java/com/baeldung/springbootmvc/SpringBootMvcApplicationTests.java +++ b/spring-boot-vue/src/test/java/com/baeldung/springbootmvc/SpringBootMvcApplicationUnitTest.java @@ -16,7 +16,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. @RunWith(SpringRunner.class) @SpringBootTest @AutoConfigureMockMvc -public class SpringBootMvcApplicationTests { +public class SpringBootMvcApplicationUnitTest { @Autowired private MockMvc mockMvc; diff --git a/spring-boot/pom.xml b/spring-boot/pom.xml index ef30600d45..c0e386a679 100644 --- a/spring-boot/pom.xml +++ b/spring-boot/pom.xml @@ -222,6 +222,7 @@ 3.6.0 3.2.0 18.0 + 1.2.0 \ No newline at end of file diff --git a/spring-cloud/spring-cloud-connectors-heroku/pom.xml b/spring-cloud/spring-cloud-connectors-heroku/pom.xml index 875aa5ceaa..f25c190d56 100644 --- a/spring-cloud/spring-cloud-connectors-heroku/pom.xml +++ b/spring-cloud/spring-cloud-connectors-heroku/pom.xml @@ -79,7 +79,7 @@ Brixton.SR7 - 2.19.1 + 2.21.0 9.4-1201-jdbc4 diff --git a/spring-reactive-kotlin/pom.xml b/spring-reactive-kotlin/pom.xml index 8eafe9f217..f2f0dc58ec 100644 --- a/spring-reactive-kotlin/pom.xml +++ b/spring-reactive-kotlin/pom.xml @@ -19,9 +19,6 @@ - UTF-8 - UTF-8 - 1.8 1.2.41 diff --git a/spring-rest-embedded-tomcat/pom.xml b/spring-rest-embedded-tomcat/pom.xml index edccbb17d5..1a1adce6db 100644 --- a/spring-rest-embedded-tomcat/pom.xml +++ b/spring-rest-embedded-tomcat/pom.xml @@ -85,7 +85,6 @@ - 2.19.1 2.9.2 1.8 1.8 diff --git a/testing-modules/junit-5/pom.xml b/testing-modules/junit-5/pom.xml index c60cc00c2c..93365264ac 100644 --- a/testing-modules/junit-5/pom.xml +++ b/testing-modules/junit-5/pom.xml @@ -118,14 +118,14 @@ - 5.1.0 - 1.1.0 + 5.2.0 + 1.2.0 5.2.0 2.8.2 1.4.196 2.8.9 1.7.4 - 2.19.1 + 2.21.0 1.6.0 5.0.1.RELEASE diff --git a/testing-modules/junit5-migration/pom.xml b/testing-modules/junit5-migration/pom.xml index ae46b479bb..9d9d418774 100644 --- a/testing-modules/junit5-migration/pom.xml +++ b/testing-modules/junit5-migration/pom.xml @@ -80,10 +80,10 @@ - 5.1.0 - 1.1.0 + 5.2.0 + 1.2.0 5.2.0 - 2.19.1 + 2.21.0 1.6.0 diff --git a/testing-modules/test-containers/pom.xml b/testing-modules/test-containers/pom.xml index 2a8f434040..0ace187555 100644 --- a/testing-modules/test-containers/pom.xml +++ b/testing-modules/test-containers/pom.xml @@ -109,7 +109,7 @@ 1.7.2 42.2.2 3.12.0 - 2.19.1 + 2.21.0 From e80c93b72badd46e9f1ce8870d494ca7eb1beba1 Mon Sep 17 00:00:00 2001 From: Adrian Precub Date: Fri, 10 Aug 2018 07:40:47 +0300 Subject: [PATCH 11/13] BAEL-2039: chaos monkey for spring boot (#4889) --- spring-boot/pom.xml | 7 +++++ .../chaosmonkey/SpringBootChaosMonkeyApp.java | 15 +++++++++ .../controller/PermissionsController.java | 25 +++++++++++++++ .../service/PermissionsService.java | 17 ++++++++++ .../src/main/resources/application.properties | 31 +++++++++++++++++++ 5 files changed, 95 insertions(+) create mode 100644 spring-boot/src/main/java/com/baeldung/chaosmonkey/SpringBootChaosMonkeyApp.java create mode 100644 spring-boot/src/main/java/com/baeldung/chaosmonkey/controller/PermissionsController.java create mode 100644 spring-boot/src/main/java/com/baeldung/chaosmonkey/service/PermissionsService.java diff --git a/spring-boot/pom.xml b/spring-boot/pom.xml index c0e386a679..3a43dbd828 100644 --- a/spring-boot/pom.xml +++ b/spring-boot/pom.xml @@ -149,6 +149,12 @@ rome ${rome.version} + + + de.codecentric + chaos-monkey-spring-boot + ${chaos.monkey.version} + @@ -219,6 +225,7 @@ 8.5.11 2.4.1.Final 1.9.0 + 2.0.0 3.6.0 3.2.0 18.0 diff --git a/spring-boot/src/main/java/com/baeldung/chaosmonkey/SpringBootChaosMonkeyApp.java b/spring-boot/src/main/java/com/baeldung/chaosmonkey/SpringBootChaosMonkeyApp.java new file mode 100644 index 0000000000..16a0aea13b --- /dev/null +++ b/spring-boot/src/main/java/com/baeldung/chaosmonkey/SpringBootChaosMonkeyApp.java @@ -0,0 +1,15 @@ +package com.baeldung.chaosmonkey; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +/** + * Created by adi on 8/2/18. + */ +@SpringBootApplication(scanBasePackages = { "com.baeldung.chaosmonkey" }) +public class SpringBootChaosMonkeyApp { + + public static void main(String[] args) { + SpringApplication.run(SpringBootChaosMonkeyApp.class, args); + } +} diff --git a/spring-boot/src/main/java/com/baeldung/chaosmonkey/controller/PermissionsController.java b/spring-boot/src/main/java/com/baeldung/chaosmonkey/controller/PermissionsController.java new file mode 100644 index 0000000000..6ceb117f4e --- /dev/null +++ b/spring-boot/src/main/java/com/baeldung/chaosmonkey/controller/PermissionsController.java @@ -0,0 +1,25 @@ +package com.baeldung.chaosmonkey.controller; + +import com.baeldung.chaosmonkey.service.PermissionsService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +/** + * Created by adi on 8/2/18. + */ +@RestController +@RequestMapping("/permissions") +public class PermissionsController { + + @Autowired private PermissionsService permissionsService; + + @GetMapping + public List getAllPermissions() { + return permissionsService.getAllPermissions(); + } + +} diff --git a/spring-boot/src/main/java/com/baeldung/chaosmonkey/service/PermissionsService.java b/spring-boot/src/main/java/com/baeldung/chaosmonkey/service/PermissionsService.java new file mode 100644 index 0000000000..435e262901 --- /dev/null +++ b/spring-boot/src/main/java/com/baeldung/chaosmonkey/service/PermissionsService.java @@ -0,0 +1,17 @@ +package com.baeldung.chaosmonkey.service; + +import org.springframework.stereotype.Service; + +import java.util.Arrays; +import java.util.List; + +/** + * Created by adi on 8/2/18. + */ +@Service +public class PermissionsService { + + public List getAllPermissions() { + return Arrays.asList("CREATE", "READ", "UPDATE", "DELETE"); + } +} diff --git a/spring-boot/src/main/resources/application.properties b/spring-boot/src/main/resources/application.properties index 8c02e528ab..629e880940 100644 --- a/spring-boot/src/main/resources/application.properties +++ b/spring-boot/src/main/resources/application.properties @@ -43,3 +43,34 @@ servlet.mapping=/dispatcherExampleURL #spring.banner.image.invert= //TODO contactInfoType=email + +#chaos monkey for spring boot props +management.endpoint.chaosmonkey.enabled=true +management.endpoint.chaosmonkeyjmx.enabled=true + +spring.profiles.active=chaos-monkey +#Determine whether should execute or not +chaos.monkey.enabled=true +#How many requests are to be attacked. 1: attack each request; 5: each 5th request is attacked +chaos.monkey.assaults.level=1 +#Minimum latency in ms added to the request +chaos.monkey.assaults.latencyRangeStart=3000 +#Maximum latency in ms added to the request +chaos.monkey.assaults.latencyRangeEnd=15000 +#Latency assault active +chaos.monkey.assaults.latencyActive=true +#Exception assault active +chaos.monkey.assaults.exceptionsActive=false +#AppKiller assault active +chaos.monkey.assaults.killApplicationActive=false +#Controller watcher active +chaos.monkey.watcher.controller=false +#RestController watcher active +chaos.monkey.watcher.restController=false +#Service watcher active +chaos.monkey.watcher.service=true +#Repository watcher active +chaos.monkey.watcher.repository=false +#Component watcher active +chaos.monkey.watcher.component=false + From 52e055e770341f98e62563fc84311b2660cfaa37 Mon Sep 17 00:00:00 2001 From: Dhawal Kapil Date: Fri, 10 Aug 2018 10:16:38 +0530 Subject: [PATCH 12/13] BAEL-8141 Can we remove some of the Spring milestone/snapshot repos from modules? (#4941) BAEL-8141 --- .../spring-data-dynamodb/pom.xml | 34 ------------------- spring-5-mvc/pom.xml | 24 +------------ spring-5-reactive-client/pom.xml | 21 ------------ spring-5-security/pom.xml | 21 ------------ spring-cloud/spring-cloud-gateway/pom.xml | 23 ++----------- .../spring-cloud-ribbon-client/pom.xml | 19 ----------- spring-security-openid/pom.xml | 21 ------------ 7 files changed, 3 insertions(+), 160 deletions(-) diff --git a/persistence-modules/spring-data-dynamodb/pom.xml b/persistence-modules/spring-data-dynamodb/pom.xml index 9f2b63c17c..e5bd78d208 100644 --- a/persistence-modules/spring-data-dynamodb/pom.xml +++ b/persistence-modules/spring-data-dynamodb/pom.xml @@ -177,46 +177,12 @@ - - spring-snapshots - Spring Snapshots - https://repo.spring.io/snapshot - - true - - - - spring-milestones - Spring Milestones - https://repo.spring.io/milestone - - false - - dynamodb-local DynamoDB Local Release Repository ${dynamodblocal.repository.url} - - - spring-snapshots - Spring Snapshots - https://repo.spring.io/snapshot - - true - - - - spring-milestones - Spring Milestones - https://repo.spring.io/milestone - - false - - - diff --git a/spring-5-mvc/pom.xml b/spring-5-mvc/pom.xml index 2d28eb741e..f5346a0fa0 100644 --- a/spring-5-mvc/pom.xml +++ b/spring-5-mvc/pom.xml @@ -134,31 +134,9 @@ - - - - spring-milestones - Spring Milestones - https://repo.spring.io/milestone - - false - - - - - - spring-milestones - Spring Milestones - https://repo.spring.io/milestone - - false - - - - + 2.9.0 1.1.2 - diff --git a/spring-5-reactive-client/pom.xml b/spring-5-reactive-client/pom.xml index f60832d545..f2f7dd1729 100644 --- a/spring-5-reactive-client/pom.xml +++ b/spring-5-reactive-client/pom.xml @@ -112,27 +112,6 @@ - - - spring-milestones - Spring Milestones - https://repo.spring.io/milestone - - false - - - - - - spring-milestones - Spring Milestones - https://repo.spring.io/milestone - - false - - - - 1.0.1.RELEASE 1.1.3 diff --git a/spring-5-security/pom.xml b/spring-5-security/pom.xml index ebcd6556a4..1435019c24 100644 --- a/spring-5-security/pom.xml +++ b/spring-5-security/pom.xml @@ -79,25 +79,4 @@ - - - spring-milestones - Spring Milestones - https://repo.spring.io/milestone - - false - - - - - - spring-milestones - Spring Milestones - https://repo.spring.io/milestone - - false - - - - \ No newline at end of file diff --git a/spring-cloud/spring-cloud-gateway/pom.xml b/spring-cloud/spring-cloud-gateway/pom.xml index db57373b6f..8babbff274 100644 --- a/spring-cloud/spring-cloud-gateway/pom.xml +++ b/spring-cloud/spring-cloud-gateway/pom.xml @@ -28,7 +28,7 @@ org.springframework.cloud - spring-cloud-starter-gateway + spring-cloud-starter org.springframework.boot @@ -54,27 +54,8 @@ - - - spring-snapshots - Spring Snapshots - https://repo.spring.io/snapshot - - true - - - - spring-milestones - Spring Milestones - https://repo.spring.io/milestone - - false - - - - - 2.0.0.RC2 + 2.0.1.RELEASE 6.0.2.Final diff --git a/spring-cloud/spring-cloud-ribbon-client/pom.xml b/spring-cloud/spring-cloud-ribbon-client/pom.xml index eb8398848c..fd69dbe043 100644 --- a/spring-cloud/spring-cloud-ribbon-client/pom.xml +++ b/spring-cloud/spring-cloud-ribbon-client/pom.xml @@ -38,25 +38,6 @@ - - - spring-snapshots - Spring Snapshots - https://repo.spring.io/snapshot - - true - - - - spring-milestones - Spring Milestones - https://repo.spring.io/milestone - - false - - - - Brixton.SR7 diff --git a/spring-security-openid/pom.xml b/spring-security-openid/pom.xml index 9c498f3700..a2c0b6b119 100644 --- a/spring-security-openid/pom.xml +++ b/spring-security-openid/pom.xml @@ -51,27 +51,6 @@ - - - spring-milestones - Spring Milestones - https://repo.spring.io/milestone - - false - - - - - - spring-milestones - Spring Milestones - https://repo.spring.io/milestone - - false - - - - 2.2.1.RELEASE 1.0.9.RELEASE From 2a3c5b8eac0337782fcf7636fe6167cffd58605e Mon Sep 17 00:00:00 2001 From: Krzysztof Majewski Date: Fri, 10 Aug 2018 13:55:58 +0200 Subject: [PATCH 13/13] BAEL-2056 (#4945) --- .../baeldung/collection/CollectionsEmpty.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 core-java-collections/src/test/java/com/baeldung/collection/CollectionsEmpty.java diff --git a/core-java-collections/src/test/java/com/baeldung/collection/CollectionsEmpty.java b/core-java-collections/src/test/java/com/baeldung/collection/CollectionsEmpty.java new file mode 100644 index 0000000000..86a262107d --- /dev/null +++ b/core-java-collections/src/test/java/com/baeldung/collection/CollectionsEmpty.java @@ -0,0 +1,26 @@ +package com.baeldung.collection; + +import java.util.List; +import java.util.ArrayList; +import java.util.Collections; +import org.junit.Assert; +import org.junit.Test; + +public class CollectionsEmpty { + + @Test + public void givenArrayList_whenAddingElement_addsNewElement() { + ArrayList mutableList = new ArrayList<>(); + mutableList.add("test"); + + Assert.assertEquals(mutableList.size(), 1); + Assert.assertEquals(mutableList.get(0), "test"); + } + + @Test(expected = UnsupportedOperationException.class) + public void givenCollectionsEmptyList_whenAddingElement_throwsUnsupportedOperationException() { + List immutableList = Collections.emptyList(); + immutableList.add("test"); + } + +} \ No newline at end of file