org.springframework
@@ -162,18 +162,16 @@
1.8
1.8
- 3.2.0
2.21.0
2.3.2-b02
4.0.0
6.0.10.Final
enter-location-of-server
- 1.3.2
+ 1.3.2
3.0.7.RELEASE
2.4.12
2.3.27-incubating
1.2.5
- 1.0.2
1.9.0
1.4.9
5.1.0
diff --git a/spring-mvc-velocity/pom.xml b/spring-mvc-velocity/pom.xml
index df19b67e8e..5954e48e8f 100644
--- a/spring-mvc-velocity/pom.xml
+++ b/spring-mvc-velocity/pom.xml
@@ -115,7 +115,6 @@
2.9.0
- 2.6
2.7
1.6.1
diff --git a/spring-mvc-webflow/pom.xml b/spring-mvc-webflow/pom.xml
index c8de990da0..219a2be689 100644
--- a/spring-mvc-webflow/pom.xml
+++ b/spring-mvc-webflow/pom.xml
@@ -94,7 +94,6 @@
4.5.2
- 2.6
2.7
1.6.1
diff --git a/spring-mvc-xml/pom.xml b/spring-mvc-xml/pom.xml
index c978bdd983..9f7a24b358 100644
--- a/spring-mvc-xml/pom.xml
+++ b/spring-mvc-xml/pom.xml
@@ -33,7 +33,7 @@
javax.servlet
javax.servlet-api
- ${javax.servlet.version}
+ ${javax.servlet-api.version}
provided
@@ -129,17 +129,13 @@
6.0.10.Final
- 1.2
- 3.1.0
3.0.1-b08
19.0
- 3.5
2.8.0
- 2.6
1.6.1
diff --git a/spring-rest-angular/pom.xml b/spring-rest-angular/pom.xml
index 5240ae24e7..69becfb4ae 100644
--- a/spring-rest-angular/pom.xml
+++ b/spring-rest-angular/pom.xml
@@ -74,7 +74,6 @@
19.0
- 3.5
org.baeldung.web.main.Application
diff --git a/spring-rest-full/pom.xml b/spring-rest-full/pom.xml
index a85393b7a8..5bc3a70ed5 100644
--- a/spring-rest-full/pom.xml
+++ b/spring-rest-full/pom.xml
@@ -287,7 +287,6 @@
19.0
- 3.5
3.25.0-GA
diff --git a/spring-rest-query-language/pom.xml b/spring-rest-query-language/pom.xml
index 70fea91f31..7ee658d8ba 100644
--- a/spring-rest-query-language/pom.xml
+++ b/spring-rest-query-language/pom.xml
@@ -353,7 +353,6 @@
19.0
- 3.5
1.7.0
diff --git a/spring-rest-simple/README.md b/spring-rest-simple/README.md
index 882d0ac301..c01f27bd98 100644
--- a/spring-rest-simple/README.md
+++ b/spring-rest-simple/README.md
@@ -5,3 +5,4 @@
- [Spring RequestMapping](http://www.baeldung.com/spring-requestmapping)
- [Spring and Apache FileUpload](http://www.baeldung.com/spring-apache-file-upload)
- [Test a REST API with curl](http://www.baeldung.com/curl-rest)
+- [CORS with Spring](https://www.baeldung.com/spring-cors)
diff --git a/spring-rest-simple/pom.xml b/spring-rest-simple/pom.xml
index d301957eb9..263e451c62 100644
--- a/spring-rest-simple/pom.xml
+++ b/spring-rest-simple/pom.xml
@@ -323,7 +323,6 @@
4.0.0
1.4
3.1.0
- 3.5
1.4.9
diff --git a/spring-rest-simple/src/main/java/com/baeldung/cors/Account.java b/spring-rest-simple/src/main/java/com/baeldung/cors/Account.java
new file mode 100644
index 0000000000..dc6a541a46
--- /dev/null
+++ b/spring-rest-simple/src/main/java/com/baeldung/cors/Account.java
@@ -0,0 +1,9 @@
+package com.baeldung.cors;
+
+public class Account {
+ private Long id;
+
+ public Account(Long id) {
+ this.id = id;
+ }
+}
diff --git a/spring-rest-simple/src/main/java/com/baeldung/cors/AccountController.java b/spring-rest-simple/src/main/java/com/baeldung/cors/AccountController.java
new file mode 100644
index 0000000000..c387eb2121
--- /dev/null
+++ b/spring-rest-simple/src/main/java/com/baeldung/cors/AccountController.java
@@ -0,0 +1,24 @@
+package com.baeldung.cors;
+
+import org.springframework.web.bind.annotation.CrossOrigin;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RestController;
+
+@CrossOrigin(maxAge = 3600)
+@RestController
+@RequestMapping("/account")
+public class AccountController {
+
+ @CrossOrigin("http://example.com")
+ @RequestMapping("/{id}")
+ public Account retrieve(@PathVariable Long id) {
+ return new Account(id);
+ }
+
+ @RequestMapping(method = RequestMethod.DELETE, path = "/{id}")
+ public void remove(@PathVariable Long id) {
+ // ...
+ }
+}
\ No newline at end of file
diff --git a/spring-rest-simple/src/main/java/com/baeldung/cors/WebConfig.java b/spring-rest-simple/src/main/java/com/baeldung/cors/WebConfig.java
new file mode 100644
index 0000000000..dc579ce4ba
--- /dev/null
+++ b/spring-rest-simple/src/main/java/com/baeldung/cors/WebConfig.java
@@ -0,0 +1,16 @@
+package com.baeldung.cors;
+
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.servlet.config.annotation.CorsRegistry;
+import org.springframework.web.servlet.config.annotation.EnableWebMvc;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
+
+@Configuration
+@EnableWebMvc
+public class WebConfig implements WebMvcConfigurer {
+
+ @Override
+ public void addCorsMappings(CorsRegistry registry) {
+ registry.addMapping("/**");
+ }
+}
\ No newline at end of file
diff --git a/spring-rest-simple/src/main/webapp/WEB-INF/spring-web-config.xml b/spring-rest-simple/src/main/webapp/WEB-INF/spring-web-config.xml
new file mode 100644
index 0000000000..07d50ae1d6
--- /dev/null
+++ b/spring-rest-simple/src/main/webapp/WEB-INF/spring-web-config.xml
@@ -0,0 +1,25 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/spring-rest/pom.xml b/spring-rest/pom.xml
index 99bdd7646d..670bac9805 100644
--- a/spring-rest/pom.xml
+++ b/spring-rest/pom.xml
@@ -263,7 +263,6 @@
4.0.0
1.4
3.1.0
- 3.5
20.0
diff --git a/spring-resttemplate/pom.xml b/spring-resttemplate/pom.xml
index 06d4eed9fc..ae5cfed4c9 100644
--- a/spring-resttemplate/pom.xml
+++ b/spring-resttemplate/pom.xml
@@ -284,7 +284,6 @@
- 3.5
1.4.9
diff --git a/spring-security-mvc-custom/pom.xml b/spring-security-mvc-custom/pom.xml
index 4e932f3245..3bae514bc1 100644
--- a/spring-security-mvc-custom/pom.xml
+++ b/spring-security-mvc-custom/pom.xml
@@ -194,10 +194,8 @@
19.0
- 3.5
- 2.6
1.6.1
diff --git a/spring-security-mvc-digest-auth/pom.xml b/spring-security-mvc-digest-auth/pom.xml
index cf1de1730d..0baaea15ef 100644
--- a/spring-security-mvc-digest-auth/pom.xml
+++ b/spring-security-mvc-digest-auth/pom.xml
@@ -196,13 +196,11 @@
19.0
- 3.5
4.4.5
4.5.2
- 2.6
1.6.1
diff --git a/spring-security-mvc-jsonview/pom.xml b/spring-security-mvc-jsonview/pom.xml
index 8fa7b4ffb5..a7f668ae8b 100644
--- a/spring-security-mvc-jsonview/pom.xml
+++ b/spring-security-mvc-jsonview/pom.xml
@@ -111,7 +111,7 @@
javax.servlet
javax.servlet-api
- ${javax.servlet.version}
+ ${javax.servlet-api.version}
provided
@@ -206,12 +206,6 @@
-
- 3.1.0
- 1.2
-
-
- 2.6
1.6.1
2.4.0
diff --git a/spring-security-mvc-login/pom.xml b/spring-security-mvc-login/pom.xml
index 02ed0e36f2..1ca11bc1ab 100644
--- a/spring-security-mvc-login/pom.xml
+++ b/spring-security-mvc-login/pom.xml
@@ -175,7 +175,6 @@
- 2.6
1.6.1
diff --git a/spring-security-mvc-persisted-remember-me/pom.xml b/spring-security-mvc-persisted-remember-me/pom.xml
index 5e987dcb77..2f7989d573 100644
--- a/spring-security-mvc-persisted-remember-me/pom.xml
+++ b/spring-security-mvc-persisted-remember-me/pom.xml
@@ -99,7 +99,7 @@
javax.servlet
javax.servlet-api
- ${javax.servlet.version}
+ ${javax.servlet-api.version}
provided
@@ -200,15 +200,10 @@
9.4.1212
-
- 3.1.0
- 1.2
-
19.0
- 2.6
1.6.1
1.5.10.RELEASE
diff --git a/spring-security-mvc-session/pom.xml b/spring-security-mvc-session/pom.xml
index 276f651436..b55ce70517 100644
--- a/spring-security-mvc-session/pom.xml
+++ b/spring-security-mvc-session/pom.xml
@@ -119,7 +119,6 @@
3.0.2
- 2.6
1.6.1
diff --git a/spring-security-mvc-socket/pom.xml b/spring-security-mvc-socket/pom.xml
index f1d28355fd..f799a7fa9f 100644
--- a/spring-security-mvc-socket/pom.xml
+++ b/spring-security-mvc-socket/pom.xml
@@ -78,7 +78,7 @@
com.h2database
h2
- ${h2database.version}
+ ${h2.version}
@@ -186,7 +186,6 @@
5.2.10.Final
4.2.3.RELEASE
1.11.3.RELEASE
- 1.4.196
1.2.3
diff --git a/spring-security-react/pom.xml b/spring-security-react/pom.xml
index c7b7c85be8..40c284af7f 100644
--- a/spring-security-react/pom.xml
+++ b/spring-security-react/pom.xml
@@ -169,10 +169,8 @@
19.0
- 3.5
- 2.6
2.7
1.6
9.4.11.v20180605
diff --git a/spring-security-rest-basic-auth/pom.xml b/spring-security-rest-basic-auth/pom.xml
index 8a90247386..78bab83db5 100644
--- a/spring-security-rest-basic-auth/pom.xml
+++ b/spring-security-rest-basic-auth/pom.xml
@@ -279,7 +279,6 @@
19.0
- 2.6
1.6.1
diff --git a/spring-security-rest-custom/pom.xml b/spring-security-rest-custom/pom.xml
index 2180b917e5..4bab9b9d95 100644
--- a/spring-security-rest-custom/pom.xml
+++ b/spring-security-rest-custom/pom.xml
@@ -206,7 +206,6 @@
19.0
- 3.5
1.2
diff --git a/spring-security-rest/pom.xml b/spring-security-rest/pom.xml
index af38c1ffef..a66909a68e 100644
--- a/spring-security-rest/pom.xml
+++ b/spring-security-rest/pom.xml
@@ -271,7 +271,6 @@
26.0-jre
- 3.5
1.3.2
diff --git a/spring-soap/pom.xml b/spring-soap/pom.xml
index 16f19b681f..e155a0f6b2 100644
--- a/spring-soap/pom.xml
+++ b/spring-soap/pom.xml
@@ -62,7 +62,6 @@
- 1.8
2.1.2.RELEASE
diff --git a/spring-social-login/pom.xml b/spring-social-login/pom.xml
index e948c908d4..655e885568 100644
--- a/spring-social-login/pom.xml
+++ b/spring-social-login/pom.xml
@@ -94,8 +94,4 @@
-
- 3.3.2
-
-
\ No newline at end of file
diff --git a/spring-static-resources/pom.xml b/spring-static-resources/pom.xml
index 84519a37c1..b8068814ba 100644
--- a/spring-static-resources/pom.xml
+++ b/spring-static-resources/pom.xml
@@ -145,7 +145,7 @@
commons-io
commons-io
- ${commons.io.version}
+ ${commons-io.version}
@@ -215,9 +215,6 @@
1.5.1
-
-
- 2.5
\ No newline at end of file
diff --git a/spring-userservice/pom.xml b/spring-userservice/pom.xml
index e6e8553c80..cd61dfbf27 100644
--- a/spring-userservice/pom.xml
+++ b/spring-userservice/pom.xml
@@ -234,11 +234,7 @@
19.0
- 3.5
1.4.01
-
-
- 2.6
\ No newline at end of file
diff --git a/spring-zuul/pom.xml b/spring-zuul/pom.xml
index fbbbdddbf7..a613f51c3f 100644
--- a/spring-zuul/pom.xml
+++ b/spring-zuul/pom.xml
@@ -39,10 +39,6 @@
2.1.0.RELEASE
-
- 3.5
-
- 2.6
\ No newline at end of file
diff --git a/struts-2/pom.xml b/struts-2/pom.xml
index 7de688ff2c..1f7d6876d5 100644
--- a/struts-2/pom.xml
+++ b/struts-2/pom.xml
@@ -70,7 +70,6 @@
2.5.5
2.5.8
4.3.6.RELEASE
- 3.0.0
\ No newline at end of file
diff --git a/tensorflow-java/pom.xml b/tensorflow-java/pom.xml
index f9abde737c..84d2f6cf21 100644
--- a/tensorflow-java/pom.xml
+++ b/tensorflow-java/pom.xml
@@ -24,13 +24,13 @@
org.junit.jupiter
junit-jupiter-api
- ${junit.jupiter.version}
+ ${junit-jupiter.version}
test
org.junit.jupiter
junit-jupiter-engine
- ${junit.jupiter.version}
+ ${junit-jupiter.version}
test
@@ -46,6 +46,5 @@
1.12.0
- 5.4.0
\ No newline at end of file
diff --git a/easy-random/pom.xml b/testing-modules/easy-random/pom.xml
similarity index 93%
rename from easy-random/pom.xml
rename to testing-modules/easy-random/pom.xml
index 61f0ed2cd4..93c0027f8f 100644
--- a/easy-random/pom.xml
+++ b/testing-modules/easy-random/pom.xml
@@ -10,6 +10,7 @@
parent-modules
com.baeldung
1.0.0-SNAPSHOT
+ ../../
diff --git a/easy-random/src/main/java/org/baeldung/easy/random/model/Department.java b/testing-modules/easy-random/src/main/java/org/baeldung/easy/random/model/Department.java
similarity index 100%
rename from easy-random/src/main/java/org/baeldung/easy/random/model/Department.java
rename to testing-modules/easy-random/src/main/java/org/baeldung/easy/random/model/Department.java
diff --git a/easy-random/src/main/java/org/baeldung/easy/random/model/Employee.java b/testing-modules/easy-random/src/main/java/org/baeldung/easy/random/model/Employee.java
similarity index 100%
rename from easy-random/src/main/java/org/baeldung/easy/random/model/Employee.java
rename to testing-modules/easy-random/src/main/java/org/baeldung/easy/random/model/Employee.java
diff --git a/easy-random/src/main/java/org/baeldung/easy/random/model/Grade.java b/testing-modules/easy-random/src/main/java/org/baeldung/easy/random/model/Grade.java
similarity index 100%
rename from easy-random/src/main/java/org/baeldung/easy/random/model/Grade.java
rename to testing-modules/easy-random/src/main/java/org/baeldung/easy/random/model/Grade.java
diff --git a/easy-random/src/main/java/org/baeldung/easy/random/model/Person.java b/testing-modules/easy-random/src/main/java/org/baeldung/easy/random/model/Person.java
similarity index 100%
rename from easy-random/src/main/java/org/baeldung/easy/random/model/Person.java
rename to testing-modules/easy-random/src/main/java/org/baeldung/easy/random/model/Person.java
diff --git a/easy-random/src/main/java/org/baeldung/easy/random/model/YearQuarter.java b/testing-modules/easy-random/src/main/java/org/baeldung/easy/random/model/YearQuarter.java
similarity index 100%
rename from easy-random/src/main/java/org/baeldung/easy/random/model/YearQuarter.java
rename to testing-modules/easy-random/src/main/java/org/baeldung/easy/random/model/YearQuarter.java
diff --git a/easy-random/src/main/java/org/baeldung/easy/random/randomizer/YearQuarterRandomizer.java b/testing-modules/easy-random/src/main/java/org/baeldung/easy/random/randomizer/YearQuarterRandomizer.java
similarity index 100%
rename from easy-random/src/main/java/org/baeldung/easy/random/randomizer/YearQuarterRandomizer.java
rename to testing-modules/easy-random/src/main/java/org/baeldung/easy/random/randomizer/YearQuarterRandomizer.java
diff --git a/easy-random/src/test/java/org/baeldung/easy/random/EasyRandomUnitTest.java b/testing-modules/easy-random/src/test/java/org/baeldung/easy/random/EasyRandomUnitTest.java
similarity index 100%
rename from easy-random/src/test/java/org/baeldung/easy/random/EasyRandomUnitTest.java
rename to testing-modules/easy-random/src/test/java/org/baeldung/easy/random/EasyRandomUnitTest.java
diff --git a/testing-modules/easymock/pom.xml b/testing-modules/easymock/pom.xml
new file mode 100644
index 0000000000..ed9a077f67
--- /dev/null
+++ b/testing-modules/easymock/pom.xml
@@ -0,0 +1,30 @@
+
+
+ 4.0.0
+ easymock
+ easymock
+ http://maven.apache.org
+
+
+ com.baeldung
+ testing-modules
+ 1.0.0-SNAPSHOT
+
+
+
+
+ org.easymock
+ easymock
+ ${easymock.version}
+ test
+
+
+
+
+ UTF-8
+ 4.0.2
+
+
diff --git a/testing-modules/easymock/src/main/java/com/baeldung/testing/easymock/ForecastProcessor.java b/testing-modules/easymock/src/main/java/com/baeldung/testing/easymock/ForecastProcessor.java
new file mode 100644
index 0000000000..482e985e5b
--- /dev/null
+++ b/testing-modules/easymock/src/main/java/com/baeldung/testing/easymock/ForecastProcessor.java
@@ -0,0 +1,28 @@
+package com.baeldung.testing.easymock;
+
+import java.math.BigDecimal;
+
+public class ForecastProcessor {
+ private WeatherService weatherService;
+
+ public BigDecimal getMaximumTemperature(String locationName) {
+
+ Location location = new Location(locationName);
+
+ try {
+ weatherService.populateTemperature(location);
+ } catch (ServiceUnavailableException e) {
+ return null;
+ }
+
+ return location.getMaximumTemparature();
+ }
+
+ public WeatherService getWeatherService() {
+ return weatherService;
+ }
+
+ public void setWeatherService(WeatherService weatherService) {
+ this.weatherService = weatherService;
+ }
+}
diff --git a/testing-modules/easymock/src/main/java/com/baeldung/testing/easymock/Location.java b/testing-modules/easymock/src/main/java/com/baeldung/testing/easymock/Location.java
new file mode 100644
index 0000000000..5f318acd5c
--- /dev/null
+++ b/testing-modules/easymock/src/main/java/com/baeldung/testing/easymock/Location.java
@@ -0,0 +1,33 @@
+package com.baeldung.testing.easymock;
+
+import java.math.BigDecimal;
+
+public class Location {
+ private String name;
+ private BigDecimal minimumTemperature;
+ private BigDecimal maximumTemparature;
+
+ public Location(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public BigDecimal getMinimumTemperature() {
+ return minimumTemperature;
+ }
+
+ public void setMinimumTemperature(BigDecimal minimumTemperature) {
+ this.minimumTemperature = minimumTemperature;
+ }
+
+ public BigDecimal getMaximumTemparature() {
+ return maximumTemparature;
+ }
+
+ public void setMaximumTemparature(BigDecimal maximumTemparature) {
+ this.maximumTemparature = maximumTemparature;
+ }
+}
diff --git a/testing-modules/easymock/src/main/java/com/baeldung/testing/easymock/ServiceUnavailableException.java b/testing-modules/easymock/src/main/java/com/baeldung/testing/easymock/ServiceUnavailableException.java
new file mode 100644
index 0000000000..abab4bdee8
--- /dev/null
+++ b/testing-modules/easymock/src/main/java/com/baeldung/testing/easymock/ServiceUnavailableException.java
@@ -0,0 +1,7 @@
+package com.baeldung.testing.easymock;
+
+public class ServiceUnavailableException extends Exception {
+
+ private static final long serialVersionUID = 6961151537340723535L;
+
+}
diff --git a/testing-modules/easymock/src/main/java/com/baeldung/testing/easymock/WeatherService.java b/testing-modules/easymock/src/main/java/com/baeldung/testing/easymock/WeatherService.java
new file mode 100644
index 0000000000..1c6b11b17b
--- /dev/null
+++ b/testing-modules/easymock/src/main/java/com/baeldung/testing/easymock/WeatherService.java
@@ -0,0 +1,5 @@
+package com.baeldung.testing.easymock;
+
+public interface WeatherService {
+ void populateTemperature(Location location) throws ServiceUnavailableException;
+}
diff --git a/testing-modules/easymock/src/test/java/com/baeldung/testing/easymock/ForecastProcessorUnitTest.java b/testing-modules/easymock/src/test/java/com/baeldung/testing/easymock/ForecastProcessorUnitTest.java
new file mode 100644
index 0000000000..fa8fa847ae
--- /dev/null
+++ b/testing-modules/easymock/src/test/java/com/baeldung/testing/easymock/ForecastProcessorUnitTest.java
@@ -0,0 +1,49 @@
+package com.baeldung.testing.easymock;
+
+import static org.hamcrest.Matchers.equalTo;
+import static org.junit.Assert.assertThat;
+
+import java.math.BigDecimal;
+
+import org.easymock.EasyMock;
+import org.easymock.EasyMockRule;
+import org.easymock.Mock;
+import org.easymock.TestSubject;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+public class ForecastProcessorUnitTest {
+ private static int MAX_TEMP = 90;
+
+ @Rule
+ public EasyMockRule rule = new EasyMockRule(this);
+
+ @TestSubject
+ private ForecastProcessor forecastProcessor = new ForecastProcessor();
+
+ @Mock
+ private WeatherService mockWeatherService;
+
+ @Before
+ public void setUp() {
+ forecastProcessor.setWeatherService(mockWeatherService);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void givenLocationName_whenWeatherServicePopulatesTemperatures_thenMaxTempReturned() throws ServiceUnavailableException {
+ mockWeatherService.populateTemperature(EasyMock.anyObject(Location.class));
+ EasyMock.expectLastCall()
+ .andAnswer(() -> {
+ Location passedLocation = (Location) EasyMock.getCurrentArguments()[0];
+ passedLocation.setMaximumTemparature(new BigDecimal(MAX_TEMP));
+ passedLocation.setMinimumTemperature(new BigDecimal(MAX_TEMP - 10));
+ return null;
+ });
+ EasyMock.replay(mockWeatherService);
+ BigDecimal maxTemperature = forecastProcessor.getMaximumTemperature("New York");
+ EasyMock.verify(mockWeatherService);
+ assertThat(maxTemperature, equalTo(new BigDecimal(MAX_TEMP)));
+ }
+}
diff --git a/testing-modules/junit-5-advanced/src/main/resources/logback.xml b/testing-modules/junit-5-advanced/src/main/resources/logback.xml
new file mode 100644
index 0000000000..7d900d8ea8
--- /dev/null
+++ b/testing-modules/junit-5-advanced/src/main/resources/logback.xml
@@ -0,0 +1,13 @@
+
+
+
+
+ %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/testing-modules/junit-5-advanced/src/test/java/com/baeldung/extensions/testwatcher/TestResultLoggerExtension.java b/testing-modules/junit-5-advanced/src/test/java/com/baeldung/extensions/testwatcher/TestResultLoggerExtension.java
new file mode 100644
index 0000000000..a92c44a85b
--- /dev/null
+++ b/testing-modules/junit-5-advanced/src/test/java/com/baeldung/extensions/testwatcher/TestResultLoggerExtension.java
@@ -0,0 +1,62 @@
+package com.baeldung.extensions.testwatcher;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+
+import org.junit.jupiter.api.extension.AfterAllCallback;
+import org.junit.jupiter.api.extension.ExtensionContext;
+import org.junit.jupiter.api.extension.TestWatcher;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class TestResultLoggerExtension implements TestWatcher, AfterAllCallback {
+
+ private static final Logger LOG = LoggerFactory.getLogger(TestResultLoggerExtension.class);
+
+ private List testResultsStatus = new ArrayList<>();
+
+ private enum TestResultStatus {
+ SUCCESSFUL, ABORTED, FAILED, DISABLED;
+ }
+
+ @Override
+ public void testDisabled(ExtensionContext context, Optional reason) {
+ LOG.info("Test Disabled for test {}: with reason :- {}", context.getDisplayName(), reason.orElse("No reason"));
+
+ testResultsStatus.add(TestResultStatus.DISABLED);
+ }
+
+ @Override
+ public void testSuccessful(ExtensionContext context) {
+ LOG.info("Test Successful for test {}: ", context.getDisplayName());
+
+ testResultsStatus.add(TestResultStatus.SUCCESSFUL);
+ }
+
+ @Override
+ public void testAborted(ExtensionContext context, Throwable cause) {
+ LOG.info("Test Aborted for test {}: ", context.getDisplayName());
+
+ testResultsStatus.add(TestResultStatus.ABORTED);
+ }
+
+ @Override
+ public void testFailed(ExtensionContext context, Throwable cause) {
+ LOG.info("Test Aborted for test {}: ", context.getDisplayName());
+
+ testResultsStatus.add(TestResultStatus.FAILED);
+ }
+
+ @Override
+ public void afterAll(ExtensionContext context) throws Exception {
+ Map summary = testResultsStatus.stream()
+ .collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
+
+ LOG.info("Test result summary for {} {}", context.getDisplayName(), summary.toString());
+ }
+
+}
diff --git a/testing-modules/junit-5-advanced/src/test/java/com/baeldung/extensions/testwatcher/TestWatcherAPIUnitTest.java b/testing-modules/junit-5-advanced/src/test/java/com/baeldung/extensions/testwatcher/TestWatcherAPIUnitTest.java
new file mode 100644
index 0000000000..89666cf9b8
--- /dev/null
+++ b/testing-modules/junit-5-advanced/src/test/java/com/baeldung/extensions/testwatcher/TestWatcherAPIUnitTest.java
@@ -0,0 +1,36 @@
+package com.baeldung.extensions.testwatcher;
+
+import static org.junit.jupiter.api.Assertions.fail;
+
+import org.junit.Assert;
+import org.junit.jupiter.api.Assumptions;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+@ExtendWith(TestResultLoggerExtension.class)
+class TestWatcherAPIUnitTest {
+
+ @Test
+ void givenFalseIsTrue_whenTestAbortedThenCaptureResult() {
+ Assumptions.assumeTrue(false);
+ }
+
+ @Disabled
+ @Test
+ void givenTrueIsTrue_whenTestDisabledThenCaptureResult() {
+ Assert.assertTrue(true);
+ }
+
+ @Test
+ void givenTrueIsTrue_whenTestAbortedThenCaptureResult() {
+ Assumptions.assumeTrue(true);
+ }
+
+ @Disabled("This test is disabled")
+ @Test
+ void givenFailure_whenTestDisabledWithReason_ThenCaptureResult() {
+ fail("Not yet implemented");
+ }
+
+}
diff --git a/testing-modules/junit-5-basics/README.md b/testing-modules/junit-5-basics/README.md
index c09c030780..2c924a15a7 100644
--- a/testing-modules/junit-5-basics/README.md
+++ b/testing-modules/junit-5-basics/README.md
@@ -1,5 +1,11 @@
### Relevant Articles:
-
+- [The Basics of JUnit 5 – A Preview](http://www.baeldung.com/junit-5-preview)
+- [A Guide to JUnit 5](http://www.baeldung.com/junit-5)
+- [JUnit5 @RunWith](http://www.baeldung.com/junit-5-runwith)
- [Get the Path of the /src/test/resources Directory in JUnit](https://www.baeldung.com/junit-src-test-resources-directory-path)
- [Tagging and Filtering JUnit Tests](https://www.baeldung.com/junit-filtering-tests)
- [JUnit 5 Temporary Directory Support](https://www.baeldung.com/junit-5-temporary-directory)
+- [@Before vs @BeforeClass vs @BeforeEach vs @BeforeAll](http://www.baeldung.com/junit-before-beforeclass-beforeeach-beforeall)
+- [JUnit 5 @Test Annotation](http://www.baeldung.com/junit-5-test-annotation)
+- [Migrating from JUnit 4 to JUnit 5](http://www.baeldung.com/junit-5-migration)
+- [Assert an Exception is Thrown in JUnit 4 and 5](http://www.baeldung.com/junit-assert-exception)
\ No newline at end of file
diff --git a/testing-modules/junit-5-basics/pom.xml b/testing-modules/junit-5-basics/pom.xml
index f72c14ee65..68a0ceeee7 100644
--- a/testing-modules/junit-5-basics/pom.xml
+++ b/testing-modules/junit-5-basics/pom.xml
@@ -153,7 +153,6 @@
5.4.2
1.2.0
5.4.2
- 1.4.196
5.0.6.RELEASE
2.21.0
diff --git a/testing-modules/junit-5/src/main/java/com/baeldung/junit5/Greetings.java b/testing-modules/junit-5-basics/src/main/java/com/baeldung/junit5/Greetings.java
similarity index 100%
rename from testing-modules/junit-5/src/main/java/com/baeldung/junit5/Greetings.java
rename to testing-modules/junit-5-basics/src/main/java/com/baeldung/junit5/Greetings.java
diff --git a/testing-modules/junit-5/src/main/java/com/baeldung/junit5/bean/NumbersBean.java b/testing-modules/junit-5-basics/src/main/java/com/baeldung/junit5/bean/NumbersBean.java
similarity index 100%
rename from testing-modules/junit-5/src/main/java/com/baeldung/junit5/bean/NumbersBean.java
rename to testing-modules/junit-5-basics/src/main/java/com/baeldung/junit5/bean/NumbersBean.java
diff --git a/testing-modules/junit-5/src/test/java/com/baeldung/ExceptionUnitTest.java b/testing-modules/junit-5-basics/src/test/java/com/baeldung/ExceptionUnitTest.java
similarity index 100%
rename from testing-modules/junit-5/src/test/java/com/baeldung/ExceptionUnitTest.java
rename to testing-modules/junit-5-basics/src/test/java/com/baeldung/ExceptionUnitTest.java
diff --git a/testing-modules/junit-5/src/test/java/com/baeldung/FirstUnitTest.java b/testing-modules/junit-5-basics/src/test/java/com/baeldung/FirstUnitTest.java
similarity index 100%
rename from testing-modules/junit-5/src/test/java/com/baeldung/FirstUnitTest.java
rename to testing-modules/junit-5-basics/src/test/java/com/baeldung/FirstUnitTest.java
diff --git a/testing-modules/junit-5/src/test/java/com/baeldung/GreetingsUnitTest.java b/testing-modules/junit-5-basics/src/test/java/com/baeldung/GreetingsUnitTest.java
similarity index 100%
rename from testing-modules/junit-5/src/test/java/com/baeldung/GreetingsUnitTest.java
rename to testing-modules/junit-5-basics/src/test/java/com/baeldung/GreetingsUnitTest.java
diff --git a/testing-modules/junit-5/src/test/java/com/baeldung/JUnit5NewFeaturesUnitTest.java b/testing-modules/junit-5-basics/src/test/java/com/baeldung/JUnit5NewFeaturesUnitTest.java
similarity index 100%
rename from testing-modules/junit-5/src/test/java/com/baeldung/JUnit5NewFeaturesUnitTest.java
rename to testing-modules/junit-5-basics/src/test/java/com/baeldung/JUnit5NewFeaturesUnitTest.java
diff --git a/testing-modules/junit-5/src/test/java/com/baeldung/LiveTest.java b/testing-modules/junit-5-basics/src/test/java/com/baeldung/LiveTest.java
similarity index 100%
rename from testing-modules/junit-5/src/test/java/com/baeldung/LiveTest.java
rename to testing-modules/junit-5-basics/src/test/java/com/baeldung/LiveTest.java
diff --git a/testing-modules/junit-5/src/test/java/com/baeldung/exception/ExceptionAssertionUnitTest.java b/testing-modules/junit-5-basics/src/test/java/com/baeldung/exception/ExceptionAssertionUnitTest.java
similarity index 100%
rename from testing-modules/junit-5/src/test/java/com/baeldung/exception/ExceptionAssertionUnitTest.java
rename to testing-modules/junit-5-basics/src/test/java/com/baeldung/exception/ExceptionAssertionUnitTest.java
diff --git a/testing-modules/junit-5/src/test/java/com/baeldung/junit5/bean/test/NumbersBeanUnitTest.java b/testing-modules/junit-5-basics/src/test/java/com/baeldung/junit5/bean/test/NumbersBeanUnitTest.java
similarity index 100%
rename from testing-modules/junit-5/src/test/java/com/baeldung/junit5/bean/test/NumbersBeanUnitTest.java
rename to testing-modules/junit-5-basics/src/test/java/com/baeldung/junit5/bean/test/NumbersBeanUnitTest.java
diff --git a/testing-modules/junit-5/src/test/java/com/baeldung/junit5/spring/GreetingsSpringUnitTest.java b/testing-modules/junit-5-basics/src/test/java/com/baeldung/junit5/spring/GreetingsSpringUnitTest.java
similarity index 100%
rename from testing-modules/junit-5/src/test/java/com/baeldung/junit5/spring/GreetingsSpringUnitTest.java
rename to testing-modules/junit-5-basics/src/test/java/com/baeldung/junit5/spring/GreetingsSpringUnitTest.java
diff --git a/testing-modules/junit-5/src/test/java/com/baeldung/junit5/spring/SpringTestConfiguration.java b/testing-modules/junit-5-basics/src/test/java/com/baeldung/junit5/spring/SpringTestConfiguration.java
similarity index 100%
rename from testing-modules/junit-5/src/test/java/com/baeldung/junit5/spring/SpringTestConfiguration.java
rename to testing-modules/junit-5-basics/src/test/java/com/baeldung/junit5/spring/SpringTestConfiguration.java
diff --git a/testing-modules/junit-5/src/test/java/com/baeldung/migration/junit4/AnnotationTestExampleUnitTest.java b/testing-modules/junit-5-basics/src/test/java/com/baeldung/migration/junit4/AnnotationTestExampleUnitTest.java
similarity index 100%
rename from testing-modules/junit-5/src/test/java/com/baeldung/migration/junit4/AnnotationTestExampleUnitTest.java
rename to testing-modules/junit-5-basics/src/test/java/com/baeldung/migration/junit4/AnnotationTestExampleUnitTest.java
diff --git a/testing-modules/junit-5/src/test/java/com/baeldung/migration/junit4/AssertionsExampleUnitTest.java b/testing-modules/junit-5-basics/src/test/java/com/baeldung/migration/junit4/AssertionsExampleUnitTest.java
similarity index 100%
rename from testing-modules/junit-5/src/test/java/com/baeldung/migration/junit4/AssertionsExampleUnitTest.java
rename to testing-modules/junit-5-basics/src/test/java/com/baeldung/migration/junit4/AssertionsExampleUnitTest.java
diff --git a/testing-modules/junit-5/src/test/java/com/baeldung/migration/junit4/BeforeAndAfterAnnotationsUnitTest.java b/testing-modules/junit-5-basics/src/test/java/com/baeldung/migration/junit4/BeforeAndAfterAnnotationsUnitTest.java
similarity index 100%
rename from testing-modules/junit-5/src/test/java/com/baeldung/migration/junit4/BeforeAndAfterAnnotationsUnitTest.java
rename to testing-modules/junit-5-basics/src/test/java/com/baeldung/migration/junit4/BeforeAndAfterAnnotationsUnitTest.java
diff --git a/testing-modules/junit-5/src/test/java/com/baeldung/migration/junit4/BeforeClassAndAfterClassAnnotationsUnitTest.java b/testing-modules/junit-5-basics/src/test/java/com/baeldung/migration/junit4/BeforeClassAndAfterClassAnnotationsUnitTest.java
similarity index 100%
rename from testing-modules/junit-5/src/test/java/com/baeldung/migration/junit4/BeforeClassAndAfterClassAnnotationsUnitTest.java
rename to testing-modules/junit-5-basics/src/test/java/com/baeldung/migration/junit4/BeforeClassAndAfterClassAnnotationsUnitTest.java
diff --git a/testing-modules/junit-5/src/test/java/com/baeldung/migration/junit4/ExceptionAssertionUnitTest.java b/testing-modules/junit-5-basics/src/test/java/com/baeldung/migration/junit4/ExceptionAssertionUnitTest.java
similarity index 100%
rename from testing-modules/junit-5/src/test/java/com/baeldung/migration/junit4/ExceptionAssertionUnitTest.java
rename to testing-modules/junit-5-basics/src/test/java/com/baeldung/migration/junit4/ExceptionAssertionUnitTest.java
diff --git a/testing-modules/junit-5/src/test/java/com/baeldung/migration/junit4/RuleExampleUnitTest.java b/testing-modules/junit-5-basics/src/test/java/com/baeldung/migration/junit4/RuleExampleUnitTest.java
similarity index 100%
rename from testing-modules/junit-5/src/test/java/com/baeldung/migration/junit4/RuleExampleUnitTest.java
rename to testing-modules/junit-5-basics/src/test/java/com/baeldung/migration/junit4/RuleExampleUnitTest.java
diff --git a/testing-modules/junit-5/src/test/java/com/baeldung/migration/junit4/categories/Annotations.java b/testing-modules/junit-5-basics/src/test/java/com/baeldung/migration/junit4/categories/Annotations.java
similarity index 100%
rename from testing-modules/junit-5/src/test/java/com/baeldung/migration/junit4/categories/Annotations.java
rename to testing-modules/junit-5-basics/src/test/java/com/baeldung/migration/junit4/categories/Annotations.java
diff --git a/testing-modules/junit-5/src/test/java/com/baeldung/migration/junit4/categories/JUnit4UnitTest.java b/testing-modules/junit-5-basics/src/test/java/com/baeldung/migration/junit4/categories/JUnit4UnitTest.java
similarity index 100%
rename from testing-modules/junit-5/src/test/java/com/baeldung/migration/junit4/categories/JUnit4UnitTest.java
rename to testing-modules/junit-5-basics/src/test/java/com/baeldung/migration/junit4/categories/JUnit4UnitTest.java
diff --git a/testing-modules/junit-5/src/test/java/com/baeldung/migration/junit4/rules/TraceUnitTestRule.java b/testing-modules/junit-5-basics/src/test/java/com/baeldung/migration/junit4/rules/TraceUnitTestRule.java
similarity index 100%
rename from testing-modules/junit-5/src/test/java/com/baeldung/migration/junit4/rules/TraceUnitTestRule.java
rename to testing-modules/junit-5-basics/src/test/java/com/baeldung/migration/junit4/rules/TraceUnitTestRule.java
diff --git a/testing-modules/junit-5/src/test/java/com/baeldung/migration/junit5/AnnotationTestExampleUnitTest.java b/testing-modules/junit-5-basics/src/test/java/com/baeldung/migration/junit5/AnnotationTestExampleUnitTest.java
similarity index 100%
rename from testing-modules/junit-5/src/test/java/com/baeldung/migration/junit5/AnnotationTestExampleUnitTest.java
rename to testing-modules/junit-5-basics/src/test/java/com/baeldung/migration/junit5/AnnotationTestExampleUnitTest.java
diff --git a/testing-modules/junit-5/src/test/java/com/baeldung/migration/junit5/AssertionsExampleUnitTest.java b/testing-modules/junit-5-basics/src/test/java/com/baeldung/migration/junit5/AssertionsExampleUnitTest.java
similarity index 100%
rename from testing-modules/junit-5/src/test/java/com/baeldung/migration/junit5/AssertionsExampleUnitTest.java
rename to testing-modules/junit-5-basics/src/test/java/com/baeldung/migration/junit5/AssertionsExampleUnitTest.java
diff --git a/testing-modules/junit-5/src/test/java/com/baeldung/migration/junit5/AssumptionUnitTest.java b/testing-modules/junit-5-basics/src/test/java/com/baeldung/migration/junit5/AssumptionUnitTest.java
similarity index 100%
rename from testing-modules/junit-5/src/test/java/com/baeldung/migration/junit5/AssumptionUnitTest.java
rename to testing-modules/junit-5-basics/src/test/java/com/baeldung/migration/junit5/AssumptionUnitTest.java
diff --git a/testing-modules/junit-5/src/test/java/com/baeldung/migration/junit5/BeforeAllAndAfterAllAnnotationsUnitTest.java b/testing-modules/junit-5-basics/src/test/java/com/baeldung/migration/junit5/BeforeAllAndAfterAllAnnotationsUnitTest.java
similarity index 100%
rename from testing-modules/junit-5/src/test/java/com/baeldung/migration/junit5/BeforeAllAndAfterAllAnnotationsUnitTest.java
rename to testing-modules/junit-5-basics/src/test/java/com/baeldung/migration/junit5/BeforeAllAndAfterAllAnnotationsUnitTest.java
diff --git a/testing-modules/junit-5/src/test/java/com/baeldung/migration/junit5/BeforeEachAndAfterEachAnnotationsUnitTest.java b/testing-modules/junit-5-basics/src/test/java/com/baeldung/migration/junit5/BeforeEachAndAfterEachAnnotationsUnitTest.java
similarity index 100%
rename from testing-modules/junit-5/src/test/java/com/baeldung/migration/junit5/BeforeEachAndAfterEachAnnotationsUnitTest.java
rename to testing-modules/junit-5-basics/src/test/java/com/baeldung/migration/junit5/BeforeEachAndAfterEachAnnotationsUnitTest.java
diff --git a/testing-modules/junit-5/src/test/java/com/baeldung/migration/junit5/RuleExampleUnitTest.java b/testing-modules/junit-5-basics/src/test/java/com/baeldung/migration/junit5/RuleExampleUnitTest.java
similarity index 100%
rename from testing-modules/junit-5/src/test/java/com/baeldung/migration/junit5/RuleExampleUnitTest.java
rename to testing-modules/junit-5-basics/src/test/java/com/baeldung/migration/junit5/RuleExampleUnitTest.java
diff --git a/testing-modules/junit-5/src/test/java/com/baeldung/migration/junit5/extensions/TraceUnitExtension.java b/testing-modules/junit-5-basics/src/test/java/com/baeldung/migration/junit5/extensions/TraceUnitExtension.java
similarity index 100%
rename from testing-modules/junit-5/src/test/java/com/baeldung/migration/junit5/extensions/TraceUnitExtension.java
rename to testing-modules/junit-5-basics/src/test/java/com/baeldung/migration/junit5/extensions/TraceUnitExtension.java
diff --git a/testing-modules/junit-5-basics/src/test/java/com/baeldung/resourcedirectory/ReadResourceDirectoryUnitTest.java b/testing-modules/junit-5-basics/src/test/java/com/baeldung/resourcedirectory/ReadResourceDirectoryUnitTest.java
index 20fa372abd..eb8cab2462 100644
--- a/testing-modules/junit-5-basics/src/test/java/com/baeldung/resourcedirectory/ReadResourceDirectoryUnitTest.java
+++ b/testing-modules/junit-5-basics/src/test/java/com/baeldung/resourcedirectory/ReadResourceDirectoryUnitTest.java
@@ -17,7 +17,7 @@ public class ReadResourceDirectoryUnitTest {
String absolutePath = file.getAbsolutePath();
System.out.println(absolutePath);
- Assert.assertTrue(absolutePath.endsWith("src/test/resources"));
+ Assert.assertTrue(absolutePath.endsWith("src" + File.separator + "test" + File.separator + "resources"));
}
@Test
@@ -27,7 +27,7 @@ public class ReadResourceDirectoryUnitTest {
String absolutePath = resourceDirectory.toFile().getAbsolutePath();
System.out.println(absolutePath);
- Assert.assertTrue(absolutePath.endsWith("src/test/resources"));
+ Assert.assertTrue(absolutePath.endsWith("src" + File.separator + "test" + File.separator + "resources"));
}
@Test
@@ -39,7 +39,7 @@ public class ReadResourceDirectoryUnitTest {
String absolutePath = file.getAbsolutePath();
System.out.println(absolutePath);
- Assert.assertTrue(absolutePath.endsWith("/example_resource.txt"));
+ Assert.assertTrue(absolutePath.endsWith(File.separator + "example_resource.txt"));
}
}
diff --git a/testing-modules/junit-5/src/test/java/com/baeldung/suites/AllUnitTest.java b/testing-modules/junit-5-basics/src/test/java/com/baeldung/suites/AllUnitTest.java
similarity index 100%
rename from testing-modules/junit-5/src/test/java/com/baeldung/suites/AllUnitTest.java
rename to testing-modules/junit-5-basics/src/test/java/com/baeldung/suites/AllUnitTest.java
diff --git a/testing-modules/junit-5/README.md b/testing-modules/junit-5/README.md
index 47db6587b4..d543b9b09b 100644
--- a/testing-modules/junit-5/README.md
+++ b/testing-modules/junit-5/README.md
@@ -1,16 +1,9 @@
### Relevant Articles:
-- [The Basics of JUnit 5 – A Preview](http://www.baeldung.com/junit-5-preview)
-- [A Guide to JUnit 5](http://www.baeldung.com/junit-5)
- [A Guide to @RepeatedTest in Junit 5](http://www.baeldung.com/junit-5-repeated-test)
- [Guide to Dynamic Tests in Junit 5](http://www.baeldung.com/junit5-dynamic-tests)
- [A Guide to JUnit 5 Extensions](http://www.baeldung.com/junit-5-extensions)
- [Inject Parameters into JUnit Jupiter Unit Tests](http://www.baeldung.com/junit-5-parameters)
- [Mockito and JUnit 5 – Using ExtendWith](http://www.baeldung.com/mockito-junit-5-extension)
-- [JUnit5 @RunWith](http://www.baeldung.com/junit-5-runwith)
-- [JUnit 5 @Test Annotation](http://www.baeldung.com/junit-5-test-annotation)
-- [Assert an Exception is Thrown in JUnit 4 and 5](http://www.baeldung.com/junit-assert-exception)
-- [@Before vs @BeforeClass vs @BeforeEach vs @BeforeAll](http://www.baeldung.com/junit-before-beforeclass-beforeeach-beforeall)
-- [Migrating from JUnit 4 to JUnit 5](http://www.baeldung.com/junit-5-migration)
- [JUnit5 Programmatic Extension Registration with @RegisterExtension](http://www.baeldung.com/junit-5-registerextension-annotation)
- [The Order of Tests in JUnit](http://www.baeldung.com/junit-5-test-order)
- [Running JUnit Tests Programmatically, from a Java Application](https://www.baeldung.com/junit-tests-run-programmatically-from-java)
diff --git a/testing-modules/load-testing-comparison/pom.xml b/testing-modules/load-testing-comparison/pom.xml
index 44014e96ab..2c53657481 100644
--- a/testing-modules/load-testing-comparison/pom.xml
+++ b/testing-modules/load-testing-comparison/pom.xml
@@ -145,7 +145,6 @@
5.0
3.11
2.0.5.RELEASE
- 1.4.197
\ No newline at end of file
diff --git a/testing-modules/mockito/pom.xml b/testing-modules/mockito/pom.xml
index 19dbaa0dc1..7b6d6e7735 100644
--- a/testing-modules/mockito/pom.xml
+++ b/testing-modules/mockito/pom.xml
@@ -94,7 +94,6 @@
2.0.9.RELEASE
19.0
- 3.5
1.7.0
diff --git a/testing-modules/pom.xml b/testing-modules/pom.xml
index 95a19c2557..3a1c3f3bf4 100644
--- a/testing-modules/pom.xml
+++ b/testing-modules/pom.xml
@@ -14,6 +14,7 @@
+ easy-random
gatling
groovy-spock
junit-5
@@ -33,6 +34,7 @@
testing
testng
junit-5-basics
+ easymock
junit-5-advanced
diff --git a/testing-modules/rest-assured/pom.xml b/testing-modules/rest-assured/pom.xml
index 4ed10f0641..eb85c6c8be 100644
--- a/testing-modules/rest-assured/pom.xml
+++ b/testing-modules/rest-assured/pom.xml
@@ -194,14 +194,12 @@
18.0
- 2.9.7
1.8
19.0
2.5
1.4.7
9.4.0.v20161208
- 3.5
3.2.2
4.4.5
diff --git a/testing-modules/rest-testing/pom.xml b/testing-modules/rest-testing/pom.xml
index 6dad3be117..a1995ce9ff 100644
--- a/testing-modules/rest-testing/pom.xml
+++ b/testing-modules/rest-testing/pom.xml
@@ -151,7 +151,6 @@
19.0
- 3.5
2.9.0
@@ -163,9 +162,6 @@
4.5.2
4.1
-
-
- 2.6
\ No newline at end of file
diff --git a/testing-modules/spring-testing/pom.xml b/testing-modules/spring-testing/pom.xml
index f4d7b5dc66..6f2700e2df 100644
--- a/testing-modules/spring-testing/pom.xml
+++ b/testing-modules/spring-testing/pom.xml
@@ -73,7 +73,7 @@
javax.servlet
javax.servlet-api
- ${servlet.api.version}
+ ${javax.servlet-api.version}
@@ -94,7 +94,7 @@
3.1.6
5.4.0
5.1.4.RELEASE
- 4.0.1
+ 4.0.1
2.1.1
diff --git a/testing-modules/test-containers/pom.xml b/testing-modules/test-containers/pom.xml
index 7ee002ea8b..292af2051a 100644
--- a/testing-modules/test-containers/pom.xml
+++ b/testing-modules/test-containers/pom.xml
@@ -99,7 +99,6 @@
- 5.1.0
1.0.1
4.12.1
2.8.2
diff --git a/vaadin/pom.xml b/vaadin/pom.xml
index 089ebe67c1..e3d882bbda 100644
--- a/vaadin/pom.xml
+++ b/vaadin/pom.xml
@@ -187,7 +187,6 @@
1.8
local
mytheme
- 3.0.0
3.0.0
diff --git a/video-tutorials/jackson-annotations/pom.xml b/video-tutorials/jackson-annotations/pom.xml
index 2492951d1a..200ca7577f 100644
--- a/video-tutorials/jackson-annotations/pom.xml
+++ b/video-tutorials/jackson-annotations/pom.xml
@@ -141,10 +141,6 @@
2.8.0
4.1
-
- 3.5
- 2.5
-
3.0.1
3.0.0
diff --git a/xml/pom.xml b/xml/pom.xml
index e9b89c71fc..123875b1d9 100644
--- a/xml/pom.xml
+++ b/xml/pom.xml
@@ -249,18 +249,12 @@
1.6.1
1.1.6
2.0.6
- 2.5
4.1
1.2.4.5
2.1
1.4.2
1.0-2
-
- 3.5
- 2.4
- 1.8
-
1.3.1
diff --git a/xstream/pom.xml b/xstream/pom.xml
index f75e10fc7d..b98e258599 100644
--- a/xstream/pom.xml
+++ b/xstream/pom.xml
@@ -11,6 +11,7 @@
com.baeldung
parent-modules
1.0.0-SNAPSHOT
+ ../pom.xml
@@ -28,8 +29,8 @@
- 1.4.9
+ 1.4.10
1.3.8
-
\ No newline at end of file
+
diff --git a/xstream/src/main/java/com/baeldung/rce/App.java b/xstream/src/main/java/com/baeldung/rce/App.java
new file mode 100644
index 0000000000..3720c7fa93
--- /dev/null
+++ b/xstream/src/main/java/com/baeldung/rce/App.java
@@ -0,0 +1,92 @@
+package com.baeldung.rce;
+
+import com.sun.net.httpserver.HttpServer;
+import com.thoughtworks.xstream.XStream;
+import com.thoughtworks.xstream.security.NoTypePermission;
+import com.thoughtworks.xstream.security.NullPermission;
+import com.thoughtworks.xstream.security.PrimitiveTypePermission;
+
+import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * Web application which is intentionally vulnerable to an XStream remote code
+ * exploitation (RCE).
+ *
+ *
+ * This test application is meant to maintain a set of {@link Person} models. It
+ * exposes a "/persons" endpoint which supports the following operations:
+ *
+ *
+ * - {@code POST} XML for adding a new {@link Person} to the set
+ *
- {@code GET} for retrieving the set of {@link Person} models as XML
+ *
+ *
+ * The {@code POST} handler is vulnerable to an RCE exploit.
+ */
+public final class App {
+
+ public static App createHardened(int port) {
+ final XStream xstream = new XStream();
+ xstream.addPermission(NoTypePermission.NONE);
+ xstream.addPermission(NullPermission.NULL);
+ xstream.addPermission(PrimitiveTypePermission.PRIMITIVES);
+ xstream.allowTypes(new Class>[] { Person.class });
+ return new App(port, xstream);
+ }
+
+ public static App createVulnerable(int port) {
+ return new App(port, new XStream());
+ }
+
+ private final int port;
+ private final Set persons;
+ private final XStream xstream;
+ private HttpServer server;
+
+ private App(int port, XStream xstream) {
+ this.port = port;
+ persons = new HashSet<>();
+ // this app is vulnerable because XStream security is not configured
+ this.xstream = xstream;
+ this.xstream.alias("person", Person.class);
+ }
+
+ void start() throws IOException {
+ server = HttpServer.create(new InetSocketAddress("localhost", port), 0);
+ server.createContext("/persons", exchange -> {
+ switch (exchange.getRequestMethod()) {
+ case "POST":
+ final Person person = (Person) xstream.fromXML(exchange.getRequestBody());
+ persons.add(person);
+ exchange.sendResponseHeaders(201, 0);
+ exchange.close();
+ break;
+ case "GET":
+ exchange.sendResponseHeaders(200, 0);
+ xstream.toXML(persons, exchange.getResponseBody());
+ exchange.close();
+ break;
+ default:
+ exchange.sendResponseHeaders(405, 0);
+ exchange.close();
+ }
+ });
+ server.start();
+ }
+
+ void stop() {
+ if (server != null) {
+ server.stop(0);
+ }
+ }
+
+ int port() {
+ if (server == null)
+ throw new IllegalStateException("Server not started");
+ return server.getAddress()
+ .getPort();
+ }
+}
diff --git a/xstream/src/main/java/com/baeldung/rce/Person.java b/xstream/src/main/java/com/baeldung/rce/Person.java
new file mode 100644
index 0000000000..336c47798b
--- /dev/null
+++ b/xstream/src/main/java/com/baeldung/rce/Person.java
@@ -0,0 +1,43 @@
+package com.baeldung.rce;
+
+import java.util.Objects;
+
+/** Person model */
+public final class Person {
+
+ private String first;
+ private String last;
+
+ public String getFirst() {
+ return first;
+ }
+
+ public void setFirst(String first) {
+ this.first = first;
+ }
+
+ public String getLast() {
+ return last;
+ }
+
+ public void setLast(String last) {
+ this.last = last;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (!(o instanceof Person)) {
+ return false;
+ }
+ Person person = (Person) o;
+ return Objects.equals(first, person.first) && Objects.equals(last, person.last);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(first, last);
+ }
+}
diff --git a/xstream/src/test/java/com/baeldung/rce/AppUnitTest.java b/xstream/src/test/java/com/baeldung/rce/AppUnitTest.java
new file mode 100644
index 0000000000..3b541ae099
--- /dev/null
+++ b/xstream/src/test/java/com/baeldung/rce/AppUnitTest.java
@@ -0,0 +1,65 @@
+package com.baeldung.rce;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.HttpURLConnection;
+import java.net.SocketException;
+import java.net.URL;
+
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Unit test which demonstrates a remote code exploit against the {@link App}
+ * server. Sends an XML request containing an attack payload to the {@code POST}
+ * endpoint.
+ */
+public final class AppUnitTest {
+
+ private App app;
+
+ /** start a new web server */
+ @Before
+ public void before() throws IOException {
+ app = App.createVulnerable(0);
+ app.start();
+ }
+
+ /** stop the web server */
+ @After
+ public void after() {
+ if (app != null)
+ app.stop();
+ }
+
+ /**
+ * Test passes when an {@link IOException} is thrown because this indicates that
+ * the attacker caused the application to fail in some way. This does not
+ * actually confirm that the exploit took place, because the RCE is a
+ * side-effect that is difficult to observe.
+ */
+ @Test(expected = SocketException.class)
+ public void givenAppIsVulneable_whenExecuteRemoteCodeWhichThrowsException_thenThrowsException() throws IOException {
+ // POST the attack.xml to the application's /persons endpoint
+ final URL url = new URL("http://localhost:" + app.port() + "/persons");
+ final HttpURLConnection connection = (HttpURLConnection) url.openConnection();
+ connection.setRequestMethod("POST");
+ connection.setDoOutput(true);
+ connection.setUseCaches(false);
+ connection.setRequestProperty("Content-Type", "application/xml");
+ connection.connect();
+ try (OutputStream os = connection.getOutputStream(); InputStream is = AppUnitTest.class.getResourceAsStream("/attack.xml")) {
+ byte[] buffer = new byte[1024];
+ while (is.read(buffer) > 0) {
+ os.write(buffer);
+ }
+ }
+ final int rc = connection.getResponseCode();
+ connection.disconnect();
+ assertTrue(rc >= 400);
+ }
+}
diff --git a/xstream/src/test/java/com/baeldung/rce/AttackExploitedException.java b/xstream/src/test/java/com/baeldung/rce/AttackExploitedException.java
new file mode 100644
index 0000000000..16c906abfc
--- /dev/null
+++ b/xstream/src/test/java/com/baeldung/rce/AttackExploitedException.java
@@ -0,0 +1,7 @@
+package com.baeldung.rce;
+
+/**
+ * Indicates a successful remote code execution attack has taken place.
+ */
+final class AttackExploitedException extends RuntimeException {
+}
diff --git a/xstream/src/test/java/com/baeldung/rce/AttackExploitedExceptionThrower.java b/xstream/src/test/java/com/baeldung/rce/AttackExploitedExceptionThrower.java
new file mode 100644
index 0000000000..16ed143f7a
--- /dev/null
+++ b/xstream/src/test/java/com/baeldung/rce/AttackExploitedExceptionThrower.java
@@ -0,0 +1,13 @@
+package com.baeldung.rce;
+
+/**
+ * Class which contains an action to throw {@link AttackExploitedException}.
+ * This helper is used by {@link AppTest} to determine when the remote code
+ * exploit has taken place.
+ */
+final class AttackExploitedExceptionThrower {
+
+ public void throwAttackExploitedException() {
+ throw new AttackExploitedException();
+ }
+}
diff --git a/xstream/src/test/java/com/baeldung/rce/XStreamBasicsUnitTest.java b/xstream/src/test/java/com/baeldung/rce/XStreamBasicsUnitTest.java
new file mode 100644
index 0000000000..d762813b22
--- /dev/null
+++ b/xstream/src/test/java/com/baeldung/rce/XStreamBasicsUnitTest.java
@@ -0,0 +1,82 @@
+package com.baeldung.rce;
+
+import com.thoughtworks.xstream.XStream;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.Collections;
+import java.util.Map;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Demonstrates XStream basics
+ */
+public final class XStreamBasicsUnitTest {
+
+ private XStream xstream;
+
+ @Before
+ public void before() {
+ xstream = new XStream();
+ xstream.alias("person", Person.class);
+ }
+
+ @Test
+ public void whenWritePerson_thenWritesExpectedXml() {
+ Person person = new Person();
+ person.setFirst("John");
+ person.setLast("Smith");
+
+ String xml = xstream.toXML(person);
+
+ // @formatter:off
+ String expected = ""
+ + "\n"
+ + " John\n"
+ + " Smith\n"
+ + "";
+ // @formatter:on
+ assertEquals(expected, xml);
+
+ }
+
+ @Test
+ public void whenReadXmlAsPerson_thenReturnsNewPerson() {
+ // @formatter:off
+ String xml = ""
+ + ""
+ + " John"
+ + " Smith"
+ + "";
+ // @formatter:on
+
+ Person person = (Person) xstream.fromXML(xml);
+
+ Person expected = new Person();
+ expected.setFirst("John");
+ expected.setLast("Smith");
+ assertEquals(person, expected);
+ }
+
+ @Test
+ public void givenXmlRepresentationOfMap_whenDeserialize_thenBuildsMap() {
+ // @formatter:off
+ String xml = ""
+ + "";
+ // @formatter:on
+ @SuppressWarnings("unchecked")
+ Map actual = (Map) xstream.fromXML(xml);
+
+ final Map expected = Collections.singletonMap("foo", 10);
+
+ assertEquals(expected, actual);
+ }
+
+}
diff --git a/xstream/src/test/resources/attack.xml b/xstream/src/test/resources/attack.xml
new file mode 100644
index 0000000000..8a5713648c
--- /dev/null
+++ b/xstream/src/test/resources/attack.xml
@@ -0,0 +1,12 @@
+
+ foo
+
+ java.lang.Comparable
+
+
+
+ throwAttackExploitedException
+
+
+
diff --git a/xstream/src/test/resources/calculator-attack.xml b/xstream/src/test/resources/calculator-attack.xml
new file mode 100644
index 0000000000..ae24843dc6
--- /dev/null
+++ b/xstream/src/test/resources/calculator-attack.xml
@@ -0,0 +1,16 @@
+
+ foo
+
+ java.lang.Comparable
+
+
+
+ open
+ /Applications/Calculator.app
+
+
+ start
+
+
+