result = query.getResultList();
- if (result != null && result.size() > 0) {
- return result.get(0);
- } else
- return null;
- }
-
- public MyUser save(final MyUser user) {
- entityManager.persist(user);
- return user;
- }
-
- public void removeUserByUsername(String username) {
- final Query query = entityManager.createQuery("delete from MyUser where username=:username");
- query.setParameter("username", username);
- query.executeUpdate();
- }
-
- public EntityManager getEntityManager() {
- return entityManager;
- }
-
- public void setEntityManager(final EntityManager entityManager) {
- this.entityManager = entityManager;
- }
-}
diff --git a/spring-userservice/src/main/java/org/baeldung/user/service/MyUserService.java b/spring-userservice/src/main/java/org/baeldung/user/service/MyUserService.java
deleted file mode 100644
index 2ab44752c0..0000000000
--- a/spring-userservice/src/main/java/org/baeldung/user/service/MyUserService.java
+++ /dev/null
@@ -1,49 +0,0 @@
-package org.baeldung.user.service;
-
-import org.baeldung.persistence.model.MyUser;
-import org.baeldung.user.dao.MyUserDAO;
-import org.baeldung.web.MyUserDto;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.security.crypto.password.PasswordEncoder;
-import org.springframework.stereotype.Service;
-import org.springframework.transaction.annotation.Transactional;
-
-@Service
-@Transactional
-public class MyUserService {
-
- @Autowired
- private PasswordEncoder passwordEncoder;
-
- @Autowired
- MyUserDAO myUserDAO;
-
- public MyUser registerNewUserAccount(final MyUserDto accountDto) throws Exception {
- if (usernameExists(accountDto.getUsername())) {
- throw new Exception("There is an account with that username: " + accountDto.getUsername());
- }
- final MyUser user = new MyUser();
-
- user.setUsername(accountDto.getUsername());
- user.setPassword(passwordEncoder.encode(accountDto.getPassword()));
- return myUserDAO.save(user);
- }
-
- public MyUser getUserByUsername(final String username) {
- final MyUser user = myUserDAO.findByUsername(username);
- return user;
- }
-
- public void removeUserByUsername(String username) {
- myUserDAO.removeUserByUsername(username);
- }
-
- private boolean usernameExists(final String username) {
- final MyUser user = myUserDAO.findByUsername(username);
- if (user != null) {
- return true;
- }
- return false;
- }
-
-}
diff --git a/spring-userservice/src/main/java/org/baeldung/web/MyUserDto.java b/spring-userservice/src/main/java/org/baeldung/web/MyUserDto.java
deleted file mode 100644
index 60a6848ea4..0000000000
--- a/spring-userservice/src/main/java/org/baeldung/web/MyUserDto.java
+++ /dev/null
@@ -1,29 +0,0 @@
-package org.baeldung.web;
-
-import javax.validation.constraints.NotNull;
-import javax.validation.constraints.Size;
-
-public class MyUserDto {
- @NotNull
- @Size(min = 1)
- private String username;
-
- private String password;
-
- public String getUsername() {
- return username;
- }
-
- public void setUsername(final String username) {
- this.username = username;
- }
-
- public String getPassword() {
- return password;
- }
-
- public void setPassword(final String password) {
- this.password = password;
- }
-
-}
diff --git a/spring-userservice/src/main/resources/logback.xml b/spring-userservice/src/main/resources/logback.xml
deleted file mode 100644
index 7d900d8ea8..0000000000
--- a/spring-userservice/src/main/resources/logback.xml
+++ /dev/null
@@ -1,13 +0,0 @@
-
-
-
-
- %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/spring-userservice/src/main/resources/persistence-derby.properties b/spring-userservice/src/main/resources/persistence-derby.properties
deleted file mode 100644
index b76c5de12f..0000000000
--- a/spring-userservice/src/main/resources/persistence-derby.properties
+++ /dev/null
@@ -1,12 +0,0 @@
-# jdbc.X
-jdbc.driverClassName=org.apache.derby.jdbc.EmbeddedDriver
-jdbc.url=jdbc:derby:memory:spring_custom_user_service;create=true
-jdbc.user=tutorialuser
-jdbc.pass=tutorialpass
-
-# hibernate.X
-hibernate.dialect=org.hibernate.dialect.DerbyDialect
-hibernate.show_sql=false
-hibernate.hbm2ddl.auto=update
-hibernate.cache.use_second_level_cache=false
-hibernate.cache.use_query_cache=false
\ No newline at end of file
diff --git a/spring-userservice/src/main/webapp/META-INF/MANIFEST.MF b/spring-userservice/src/main/webapp/META-INF/MANIFEST.MF
deleted file mode 100644
index 254272e1c0..0000000000
--- a/spring-userservice/src/main/webapp/META-INF/MANIFEST.MF
+++ /dev/null
@@ -1,3 +0,0 @@
-Manifest-Version: 1.0
-Class-Path:
-
diff --git a/spring-userservice/src/main/webapp/WEB-INF/mvc-dispatcher-servlet.xml b/spring-userservice/src/main/webapp/WEB-INF/mvc-dispatcher-servlet.xml
deleted file mode 100644
index 48ef8a8c43..0000000000
--- a/spring-userservice/src/main/webapp/WEB-INF/mvc-dispatcher-servlet.xml
+++ /dev/null
@@ -1,88 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- /WEB-INF/views/
-
-
- .jsp
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- ${hibernate.hbm2ddl.auto}
- ${hibernate.dialect}
- ${hibernate.cache.use_second_level_cache}
- ${hibernate.cache.use_query_cache}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/spring-userservice/src/main/webapp/WEB-INF/views/index.jsp b/spring-userservice/src/main/webapp/WEB-INF/views/index.jsp
deleted file mode 100644
index 0c89257cd2..0000000000
--- a/spring-userservice/src/main/webapp/WEB-INF/views/index.jsp
+++ /dev/null
@@ -1,35 +0,0 @@
-<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
- pageEncoding="ISO-8859-1"%>
-<%@ taglib prefix="c"
- uri="http://java.sun.com/jsp/jstl/core" %>
-<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
-
-
-
-
-
-Welcome!
-
-
-
-
-
-
-
-Register
-
-
-Login
-
-
-${message }
-
-
-Hello, ${name }!
-
-
-Logout
-
-
-
-
\ No newline at end of file
diff --git a/spring-userservice/src/main/webapp/WEB-INF/views/login.jsp b/spring-userservice/src/main/webapp/WEB-INF/views/login.jsp
deleted file mode 100644
index 29431f426d..0000000000
--- a/spring-userservice/src/main/webapp/WEB-INF/views/login.jsp
+++ /dev/null
@@ -1,29 +0,0 @@
-<%@ taglib prefix="c"
- uri="http://java.sun.com/jsp/jstl/core" %>
-
-
-
-
-
- Login
-
-
- Username or password invalid!
-
-
\ No newline at end of file
diff --git a/spring-userservice/src/main/webapp/WEB-INF/views/register.jsp b/spring-userservice/src/main/webapp/WEB-INF/views/register.jsp
deleted file mode 100644
index e6e9d373a0..0000000000
--- a/spring-userservice/src/main/webapp/WEB-INF/views/register.jsp
+++ /dev/null
@@ -1,23 +0,0 @@
-<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
- pageEncoding="ISO-8859-1"%>
-<%@ taglib prefix="c"
- uri="http://java.sun.com/jsp/jstl/core" %>
-
-
-
-
-Welcome!
-
-
-
-
-
-Register here:
-
-
-
-
\ No newline at end of file
diff --git a/spring-userservice/src/main/webapp/WEB-INF/web.xml b/spring-userservice/src/main/webapp/WEB-INF/web.xml
deleted file mode 100644
index b526774179..0000000000
--- a/spring-userservice/src/main/webapp/WEB-INF/web.xml
+++ /dev/null
@@ -1,51 +0,0 @@
-
-
-
- Spring MVC Application
-
-
-
-
-
- mvc-dispatcher
- org.springframework.web.servlet.DispatcherServlet
- 1
-
-
- mvc-dispatcher
- /
-
-
-
-
- springSecurityFilterChain
- org.springframework.web.filter.DelegatingFilterProxy
-
-
- springSecurityFilterChain
- /*
-
-
-
- index.jsp
-
-
-
\ No newline at end of file
diff --git a/spring-userservice/src/test/java/org/baeldung/SpringContextIntegrationTest.java b/spring-userservice/src/test/java/org/baeldung/SpringContextIntegrationTest.java
deleted file mode 100644
index 825b89eb10..0000000000
--- a/spring-userservice/src/test/java/org/baeldung/SpringContextIntegrationTest.java
+++ /dev/null
@@ -1,18 +0,0 @@
-package org.baeldung;
-
-import org.baeldung.custom.config.MvcConfig;
-import org.baeldung.custom.config.PersistenceDerbyJPAConfig;
-import org.baeldung.custom.config.SecSecurityConfig;
-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(classes = { MvcConfig.class, PersistenceDerbyJPAConfig.class, SecSecurityConfig.class })
-public class SpringContextIntegrationTest {
-
- @Test
- public void whenSpringContextIsBootstrapped_thenNoExceptions() {
- }
-}
diff --git a/spring-userservice/src/test/java/org/baeldung/userservice/CustomUserDetailsServiceIntegrationTest.java b/spring-userservice/src/test/java/org/baeldung/userservice/CustomUserDetailsServiceIntegrationTest.java
deleted file mode 100644
index 1cd38228b8..0000000000
--- a/spring-userservice/src/test/java/org/baeldung/userservice/CustomUserDetailsServiceIntegrationTest.java
+++ /dev/null
@@ -1,82 +0,0 @@
-package org.baeldung.userservice;
-
-import static org.junit.Assert.assertEquals;
-
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import org.baeldung.custom.config.MvcConfig;
-import org.baeldung.custom.config.PersistenceDerbyJPAConfig;
-import org.baeldung.custom.config.SecSecurityConfig;
-import org.baeldung.user.service.MyUserService;
-import org.baeldung.web.MyUserDto;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.test.context.SpringBootTest;
-import org.springframework.security.authentication.AuthenticationProvider;
-import org.springframework.security.authentication.BadCredentialsException;
-import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
-import org.springframework.security.core.Authentication;
-import org.springframework.test.context.junit4.SpringRunner;
-import org.springframework.test.context.web.WebAppConfiguration;
-
-@RunWith(SpringRunner.class)
-@SpringBootTest(classes = { MvcConfig.class, PersistenceDerbyJPAConfig.class, SecSecurityConfig.class })
-@WebAppConfiguration
-public class CustomUserDetailsServiceIntegrationTest {
-
- private static final Logger LOG = Logger.getLogger("CustomUserDetailsServiceTest");
-
- public static final String USERNAME = "user";
- public static final String PASSWORD = "pass";
- public static final String USERNAME2 = "user2";
-
- @Autowired
- MyUserService myUserService;
-
- @Autowired
- AuthenticationProvider authenticationProvider;
-
- @Test
- public void givenExistingUser_whenAuthenticate_thenRetrieveFromDb() {
- try {
- MyUserDto userDTO = new MyUserDto();
- userDTO.setUsername(USERNAME);
- userDTO.setPassword(PASSWORD);
-
- myUserService.registerNewUserAccount(userDTO);
-
- UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken(USERNAME, PASSWORD);
- Authentication authentication = authenticationProvider.authenticate(auth);
-
- assertEquals(authentication.getName(), USERNAME);
-
- } catch (Exception exc) {
- LOG.log(Level.SEVERE, "Error creating account");
- } finally {
- myUserService.removeUserByUsername(USERNAME);
- }
- }
-
- @Test(expected = BadCredentialsException.class)
- public void givenIncorrectUser_whenAuthenticate_thenBadCredentialsException() {
- try {
- MyUserDto userDTO = new MyUserDto();
- userDTO.setUsername(USERNAME);
- userDTO.setPassword(PASSWORD);
-
- try {
- myUserService.registerNewUserAccount(userDTO);
- } catch (Exception exc) {
- LOG.log(Level.SEVERE, "Error creating account");
- }
-
- UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken(USERNAME2, PASSWORD);
- Authentication authentication = authenticationProvider.authenticate(auth);
- } finally {
- myUserService.removeUserByUsername(USERNAME);
- }
- }
-
-}
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/testing-modules/README.md b/testing-modules/README.md
index d69f07215e..b269f547ec 100644
--- a/testing-modules/README.md
+++ b/testing-modules/README.md
@@ -13,5 +13,3 @@
- [Headers, Cookies and Parameters with REST-assured](http://www.baeldung.com/rest-assured-header-cookie-parameter)
- [JSON Schema Validation with REST-assured](http://www.baeldung.com/rest-assured-json-schema)
- [Testing Callbacks with Mockito](http://www.baeldung.com/mockito-callbacks)
-- [Running JUnit Tests in Parallel with Maven](https://www.baeldung.com/maven-junit-parallel-tests)
-- [Gatling vs JMeter vs The Grinder: Comparing Load Test Tools](https://www.baeldung.com/gatling-jmeter-grinder-comparison)
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
index 2b16dd3a1f..ed9a077f67 100644
--- a/testing-modules/easymock/pom.xml
+++ b/testing-modules/easymock/pom.xml
@@ -4,23 +4,27 @@
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
4.0.0
+ easymock
+ easymock
+ http://maven.apache.org
+
com.baeldung
testing-modules
1.0.0-SNAPSHOT
- easymock
- easymock
- http://maven.apache.org
-
- UTF-8
-
+
org.easymock
easymock
- 4.0.2
+ ${easymock.version}
test
+
+
+ UTF-8
+ 4.0.2
+
diff --git a/rest-with-spark-java/src/main/resources/logback.xml b/testing-modules/junit-5-advanced/src/main/resources/logback.xml
similarity index 100%
rename from rest-with-spark-java/src/main/resources/logback.xml
rename to testing-modules/junit-5-advanced/src/main/resources/logback.xml
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..dbe6803401 100644
--- a/testing-modules/junit-5-basics/README.md
+++ b/testing-modules/junit-5-basics/README.md
@@ -1,5 +1,10 @@
### Relevant Articles:
-
+- [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)
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/junit5-migration/README.md b/testing-modules/junit5-migration/README.md
new file mode 100644
index 0000000000..b97ff8255c
--- /dev/null
+++ b/testing-modules/junit5-migration/README.md
@@ -0,0 +1,2 @@
+
+This is the code for the Junit 4 - Junit 5 Migration E-book.
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 bc6e23a6b7..3a1c3f3bf4 100644
--- a/testing-modules/pom.xml
+++ b/testing-modules/pom.xml
@@ -14,6 +14,7 @@
+ easy-random
gatling
groovy-spock
junit-5
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
+
+
+