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/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/SpringContextTest.java
similarity index 92%
rename from spring-userservice/src/test/java/org/baeldung/SpringContextIntegrationTest.java
rename to spring-userservice/src/test/java/org/baeldung/SpringContextTest.java
index 825b89eb10..2853a955fa 100644
--- a/spring-userservice/src/test/java/org/baeldung/SpringContextIntegrationTest.java
+++ b/spring-userservice/src/test/java/org/baeldung/SpringContextTest.java
@@ -10,7 +10,7 @@ import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = { MvcConfig.class, PersistenceDerbyJPAConfig.class, SecSecurityConfig.class })
-public class SpringContextIntegrationTest {
+public class SpringContextTest {
@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-vault/src/test/java/org/baeldung/SpringContextTest.java b/spring-vault/src/test/java/org/baeldung/SpringContextTest.java
new file mode 100644
index 0000000000..95abe622fa
--- /dev/null
+++ b/spring-vault/src/test/java/org/baeldung/SpringContextTest.java
@@ -0,0 +1,16 @@
+package org.baeldung;
+
+import org.baeldung.springvault.SpringVaultApplication;
+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 = SpringVaultApplication.class)
+public class SpringContextTest {
+
+ @Test
+ public void whenSpringContextIsBootstrapped_thenNoExceptions() {
+ }
+}
diff --git a/spring-vertx/src/test/java/org/baeldung/SpringContextTest.java b/spring-vertx/src/test/java/org/baeldung/SpringContextTest.java
new file mode 100644
index 0000000000..4ce94ec16a
--- /dev/null
+++ b/spring-vertx/src/test/java/org/baeldung/SpringContextTest.java
@@ -0,0 +1,17 @@
+package org.baeldung;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+
+import com.baeldung.vertxspring.VertxSpringApplication;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest(classes = VertxSpringApplication.class)
+public class SpringContextTest {
+
+ @Test
+ public void whenSpringContextIsBootstrapped_thenNoExceptions() {
+ }
+}
diff --git a/spring-webflux-amqp/src/test/java/org/baeldung/SpringContextTest.java b/spring-webflux-amqp/src/test/java/org/baeldung/SpringContextTest.java
new file mode 100644
index 0000000000..88d29d5ac0
--- /dev/null
+++ b/spring-webflux-amqp/src/test/java/org/baeldung/SpringContextTest.java
@@ -0,0 +1,16 @@
+package org.baeldung;
+
+import org.baeldung.spring.amqp.SpringWebfluxAmqpApplication;
+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 = SpringWebfluxAmqpApplication.class)
+public class SpringContextTest {
+
+ @Test
+ public void whenSpringContextIsBootstrapped_thenNoExceptions() {
+ }
+}
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/spring-zuul/spring-zuul-foos-resource/src/test/java/org/baeldung/SpringContextTest.java b/spring-zuul/spring-zuul-foos-resource/src/test/java/org/baeldung/SpringContextTest.java
new file mode 100644
index 0000000000..2a57d7aa07
--- /dev/null
+++ b/spring-zuul/spring-zuul-foos-resource/src/test/java/org/baeldung/SpringContextTest.java
@@ -0,0 +1,16 @@
+package org.baeldung;
+
+import org.baeldung.config.ResourceServerApplication;
+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 = ResourceServerApplication.class)
+public class SpringContextTest {
+
+ @Test
+ public void whenSpringContextIsBootstrapped_thenNoExceptions() {
+ }
+}
diff --git a/spring-zuul/spring-zuul-ui/src/test/java/org/baeldung/SpringContextTest.java b/spring-zuul/spring-zuul-ui/src/test/java/org/baeldung/SpringContextTest.java
new file mode 100644
index 0000000000..fd35ec0841
--- /dev/null
+++ b/spring-zuul/spring-zuul-ui/src/test/java/org/baeldung/SpringContextTest.java
@@ -0,0 +1,16 @@
+package org.baeldung;
+
+import org.baeldung.config.UiApplication;
+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 = UiApplication.class)
+public class SpringContextTest {
+
+ @Test
+ public void whenSpringContextIsBootstrapped_thenNoExceptions() {
+ }
+}
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 94%
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/gatling/pom.xml b/testing-modules/gatling/pom.xml
index 158da176c6..e708d939e4 100644
--- a/testing-modules/gatling/pom.xml
+++ b/testing-modules/gatling/pom.xml
@@ -14,6 +14,31 @@
1.0.0-SNAPSHOT
../../
+
+
+
+
+ io.gatling
+ gatling-app
+ ${gatling.version}
+
+
+ io.gatling
+ gatling-recorder
+ ${gatling.version}
+
+
+ io.gatling.highcharts
+ gatling-charts-highcharts
+ ${gatling.version}
+
+
+ org.scala-lang
+ scala-library
+ ${scala.version}
+
+
+
@@ -77,52 +102,27 @@
simulation
-
- io.gatling
- gatling-maven-plugin
- ${gatling-maven-plugin.version}
-
-
- test
-
- execute
-
-
- true
-
-
-
-
-
-
+
+ io.gatling
+ gatling-maven-plugin
+ ${gatling-maven-plugin.version}
+
+
+ test
+
+ execute
+
+
+ true
+
+
+
+
+
+
-
-
-
- io.gatling
- gatling-app
- ${gatling.version}
-
-
- io.gatling
- gatling-recorder
- ${gatling.version}
-
-
- io.gatling.highcharts
- gatling-charts-highcharts
- ${gatling.version}
-
-
- org.scala-lang
- scala-library
- ${scala.version}
-
-
-
-
1.8
1.8
diff --git a/testing-modules/junit-5-advanced/README.md b/testing-modules/junit-5-advanced/README.md
new file mode 100644
index 0000000000..7282a4efad
--- /dev/null
+++ b/testing-modules/junit-5-advanced/README.md
@@ -0,0 +1,3 @@
+### Relevant Articles
+
+- [JUnit 5 TestWatcher API](https://www.baeldung.com/junit-testwatcher)
diff --git a/testing-modules/junit-5-advanced/src/main/java/com/baeldung/failure_vs_error/SimpleCalculator.java b/testing-modules/junit-5-advanced/src/main/java/com/baeldung/failure_vs_error/SimpleCalculator.java
new file mode 100644
index 0000000000..d018aa939f
--- /dev/null
+++ b/testing-modules/junit-5-advanced/src/main/java/com/baeldung/failure_vs_error/SimpleCalculator.java
@@ -0,0 +1,15 @@
+package com.baeldung.failure_vs_error;
+
+/**
+ * @author paullatzelsperger
+ * @since 2019-07-17
+ */
+public class SimpleCalculator {
+
+ public static double divideNumbers(double dividend, double divisor) {
+ if (divisor == 0) {
+ throw new ArithmeticException("Division by zero!");
+ }
+ return dividend / divisor;
+ }
+}
diff --git a/xmlunit-2/src/main/resources/logback.xml b/testing-modules/junit-5-advanced/src/main/resources/logback.xml
similarity index 100%
rename from xmlunit-2/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/displayname/ReplaceUnderscoresGeneratorUnitTest.java b/testing-modules/junit-5-advanced/src/test/java/com/baeldung/displayname/ReplaceUnderscoresGeneratorUnitTest.java
index d6e023cfe8..429d6bac2a 100644
--- a/testing-modules/junit-5-advanced/src/test/java/com/baeldung/displayname/ReplaceUnderscoresGeneratorUnitTest.java
+++ b/testing-modules/junit-5-advanced/src/test/java/com/baeldung/displayname/ReplaceUnderscoresGeneratorUnitTest.java
@@ -9,7 +9,7 @@ class ReplaceUnderscoresGeneratorUnitTest {
class when_doing_something {
@Test
- void then_should_happen_something() {
+ void then_something_should_happen() {
}
@Test
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-advanced/src/test/java/com/baeldung/failure_vs_error/SimpleCalculatorUnitTest.java b/testing-modules/junit-5-advanced/src/test/java/com/baeldung/failure_vs_error/SimpleCalculatorUnitTest.java
new file mode 100644
index 0000000000..9b1777258c
--- /dev/null
+++ b/testing-modules/junit-5-advanced/src/test/java/com/baeldung/failure_vs_error/SimpleCalculatorUnitTest.java
@@ -0,0 +1,32 @@
+package com.baeldung.failure_vs_error;
+
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+/**
+ * @author paullatzelsperger
+ * @since 2019-07-17
+ */
+class SimpleCalculatorUnitTest {
+
+ @Test
+ void divideNumbers() {
+ double result = SimpleCalculator.divideNumbers(6, 3);
+ assertEquals(2, result);
+ }
+
+ @Test
+ @Disabled("test is expected to fail, disabled so that CI build still goes through")
+ void divideNumbers_failure() {
+ double result = SimpleCalculator.divideNumbers(6, 3);
+ assertEquals(15, result);
+ }
+
+ @Test
+ @Disabled("test is expected to raise an error, disabled so that CI build still goes through")
+ void divideNumbers_error() {
+ SimpleCalculator.divideNumbers(10, 0);
+ }
+}
diff --git a/testing-modules/junit-5-basics/README.md b/testing-modules/junit-5-basics/README.md
index 6e44a9c071..dbe6803401 100644
--- a/testing-modules/junit-5-basics/README.md
+++ b/testing-modules/junit-5-basics/README.md
@@ -1,4 +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 acdd7eb2ac..7b6d6e7735 100644
--- a/testing-modules/mockito/pom.xml
+++ b/testing-modules/mockito/pom.xml
@@ -33,7 +33,7 @@
org.eclipse.persistence
javax.persistence
- 2.1.1
+ ${javax.persistence.version}
@@ -94,11 +94,11 @@
2.0.9.RELEASE
19.0
- 3.5
1.7.0
2.0.0.0
+ 2.1.1
\ No newline at end of file
diff --git a/testing-modules/mockito/src/test/java/org/baeldung/mockito/MockitoInjectIntoSpyUnitTest.java b/testing-modules/mockito/src/test/java/org/baeldung/mockito/MockitoInjectIntoSpyUnitTest.java
index 4f5ceb04e7..568492ca10 100644
--- a/testing-modules/mockito/src/test/java/org/baeldung/mockito/MockitoInjectIntoSpyUnitTest.java
+++ b/testing-modules/mockito/src/test/java/org/baeldung/mockito/MockitoInjectIntoSpyUnitTest.java
@@ -30,7 +30,7 @@ public class MockitoInjectIntoSpyUnitTest {
private MyDictionary spyDic;
@Test
- public void whenUseInjectMocksAnnotation_thenCorrect2() {
+ public void whenUseInjectMocksAnnotation_thenCorrect() {
Mockito.when(wordMap.get("aWord")).thenReturn("aMeaning");
assertEquals("aMeaning", spyDic.getMeaning("aWord"));
diff --git a/testing-modules/mocks/mock-comparisons/pom.xml b/testing-modules/mocks/mock-comparisons/pom.xml
index ae36280300..e454f124ce 100644
--- a/testing-modules/mocks/mock-comparisons/pom.xml
+++ b/testing-modules/mocks/mock-comparisons/pom.xml
@@ -49,7 +49,6 @@
2.21.0
3.5.1
1.41
-
diff --git a/testing-modules/pom.xml b/testing-modules/pom.xml
index 95a19c2557..8d40c668c0 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,8 @@
testing
testng
junit-5-basics
+ easymock
junit-5-advanced
+ xmlunit-2
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/README.md b/testing-modules/spring-testing/README.md
index 07888d7cdf..0970eabeff 100644
--- a/testing-modules/spring-testing/README.md
+++ b/testing-modules/spring-testing/README.md
@@ -4,4 +4,5 @@
- [A Quick Guide to @TestPropertySource](https://www.baeldung.com/spring-test-property-source)
- [Guide to ReflectionTestUtils for Unit Testing](https://www.baeldung.com/spring-reflection-test-utils)
- [How to Test the @Scheduled Annotation](https://www.baeldung.com/spring-testing-scheduled-annotation)
-- [Override properties in Spring]()
\ No newline at end of file
+- [Using SpringJUnit4ClassRunner with Parameterized](https://www.baeldung.com/springjunit4classrunner-parameterized)
+- [Override properties in Spring]()
diff --git a/testing-modules/spring-testing/pom.xml b/testing-modules/spring-testing/pom.xml
index 0eca9b6a7e..6f2700e2df 100644
--- a/testing-modules/spring-testing/pom.xml
+++ b/testing-modules/spring-testing/pom.xml
@@ -51,7 +51,7 @@
org.eclipse.persistence
javax.persistence
- 2.1.1
+ ${javax.persistence.version}
org.springframework.data
@@ -73,7 +73,7 @@
javax.servlet
javax.servlet-api
- ${servlet.api.version}
+ ${javax.servlet-api.version}
@@ -94,7 +94,8 @@
3.1.6
5.4.0
5.1.4.RELEASE
- 4.0.1
+ 4.0.1
+ 2.1.1
\ No newline at end of file
diff --git a/testing-modules/test-containers/pom.xml b/testing-modules/test-containers/pom.xml
index 7ee002ea8b..bd87cb5b22 100644
--- a/testing-modules/test-containers/pom.xml
+++ b/testing-modules/test-containers/pom.xml
@@ -23,6 +23,12 @@
${junit.platform.version}
test
+
+ org.junit.platform
+ junit-platform-commons
+ ${junit.platform.version}
+ test
+
org.junit.vintage
junit-vintage-engine
@@ -59,6 +65,11 @@
selenium-remote-driver
${selenium-remote-driver.version}
+
+ org.seleniumhq.selenium
+ selenium-chrome-driver
+ ${selenium-remote-driver.version}
+
@@ -76,7 +87,7 @@
org.junit.platform
junit-platform-surefire-provider
- ${junit.platform.version}
+ ${junit-platform-surefire-provider.version}
@@ -99,16 +110,14 @@
- 5.1.0
- 1.0.1
- 4.12.1
- 2.8.2
- 2.21.0
- 5.0.1.RELEASE
- 1.7.2
- 42.2.2
- 3.12.0
- 2.21.0
+ 1.5.0
+ 5.5.0
+ 2.12.0
+ 1.11.4
+ 42.2.6
+ 3.141.59
+ 2.22.2
+ 1.3.2
diff --git a/testing-modules/test-containers/src/test/java/com/baeldung/testconainers/WebDriverContainerLiveTest.java b/testing-modules/test-containers/src/test/java/com/baeldung/testconainers/WebDriverContainerLiveTest.java
index 0e52c4e9f7..0fdf0ede79 100644
--- a/testing-modules/test-containers/src/test/java/com/baeldung/testconainers/WebDriverContainerLiveTest.java
+++ b/testing-modules/test-containers/src/test/java/com/baeldung/testconainers/WebDriverContainerLiveTest.java
@@ -2,29 +2,26 @@ package com.baeldung.testconainers;
import static org.junit.Assert.assertEquals;
-import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.openqa.selenium.By;
-import org.openqa.selenium.remote.DesiredCapabilities;
+import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.RemoteWebDriver;
-import org.testcontainers.DockerClientFactory;
import org.testcontainers.containers.BrowserWebDriverContainer;
-import org.testcontainers.containers.GenericContainer;
public class WebDriverContainerLiveTest {
@Rule
public BrowserWebDriverContainer chrome
= new BrowserWebDriverContainer()
- .withDesiredCapabilities(DesiredCapabilities.chrome());
+ .withCapabilities(new ChromeOptions());
@Test
public void whenNavigatedToPage_thenHeadingIsInThePage() {
RemoteWebDriver driver = chrome.getWebDriver();
- driver.get("https://saucelabs.com/test/guinea-pig");
- String heading = driver.findElement(By.xpath("/html/body/h1"))
+ driver.get("http://example.com");
+ String heading = driver.findElement(By.xpath("/html/body/div/h1"))
.getText();
- assertEquals("This page is a Selenium sandbox", heading);
+ assertEquals("Example Domain", heading);
}
}
diff --git a/xmlunit-2/README.md b/testing-modules/xmlunit-2/README.md
similarity index 100%
rename from xmlunit-2/README.md
rename to testing-modules/xmlunit-2/README.md
diff --git a/xmlunit-2/pom.xml b/testing-modules/xmlunit-2/pom.xml
similarity index 94%
rename from xmlunit-2/pom.xml
rename to testing-modules/xmlunit-2/pom.xml
index faefeca7a1..aa516bfcc5 100644
--- a/xmlunit-2/pom.xml
+++ b/testing-modules/xmlunit-2/pom.xml
@@ -1,15 +1,14 @@
4.0.0
- com.baeldung
xmlunit-2
- 1.0
xmlunit-2
com.baeldung
parent-modules
1.0.0-SNAPSHOT
+ ../../
@@ -23,7 +22,6 @@
xmlunit-core
${xmlunit.version}
-
diff --git a/xmlunit-2/src/main/java/com/baeldung/xmlunit/IgnoreAttributeDifferenceEvaluator.java b/testing-modules/xmlunit-2/src/main/java/com/baeldung/xmlunit/IgnoreAttributeDifferenceEvaluator.java
similarity index 100%
rename from xmlunit-2/src/main/java/com/baeldung/xmlunit/IgnoreAttributeDifferenceEvaluator.java
rename to testing-modules/xmlunit-2/src/main/java/com/baeldung/xmlunit/IgnoreAttributeDifferenceEvaluator.java
diff --git a/testing-modules/xmlunit-2/src/main/resources/logback.xml b/testing-modules/xmlunit-2/src/main/resources/logback.xml
new file mode 100644
index 0000000000..7d900d8ea8
--- /dev/null
+++ b/testing-modules/xmlunit-2/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/xmlunit-2/src/test/java/com/baeldung/xmlunit/XMLUnitTest.java b/testing-modules/xmlunit-2/src/test/java/com/baeldung/xmlunit/XMLUnitTest.java
similarity index 100%
rename from xmlunit-2/src/test/java/com/baeldung/xmlunit/XMLUnitTest.java
rename to testing-modules/xmlunit-2/src/test/java/com/baeldung/xmlunit/XMLUnitTest.java
diff --git a/xmlunit-2/src/test/resources/control.xml b/testing-modules/xmlunit-2/src/test/resources/control.xml
similarity index 100%
rename from xmlunit-2/src/test/resources/control.xml
rename to testing-modules/xmlunit-2/src/test/resources/control.xml
diff --git a/xmlunit-2/src/test/resources/students.xml b/testing-modules/xmlunit-2/src/test/resources/students.xml
similarity index 100%
rename from xmlunit-2/src/test/resources/students.xml
rename to testing-modules/xmlunit-2/src/test/resources/students.xml
diff --git a/xmlunit-2/src/test/resources/students.xsd b/testing-modules/xmlunit-2/src/test/resources/students.xsd
similarity index 100%
rename from xmlunit-2/src/test/resources/students.xsd
rename to testing-modules/xmlunit-2/src/test/resources/students.xsd
diff --git a/xmlunit-2/src/test/resources/students_with_error.xml b/testing-modules/xmlunit-2/src/test/resources/students_with_error.xml
similarity index 100%
rename from xmlunit-2/src/test/resources/students_with_error.xml
rename to testing-modules/xmlunit-2/src/test/resources/students_with_error.xml
diff --git a/xmlunit-2/src/test/resources/teachers.xml b/testing-modules/xmlunit-2/src/test/resources/teachers.xml
similarity index 100%
rename from xmlunit-2/src/test/resources/teachers.xml
rename to testing-modules/xmlunit-2/src/test/resources/teachers.xml
diff --git a/xmlunit-2/src/test/resources/test.xml b/testing-modules/xmlunit-2/src/test/resources/test.xml
similarity index 100%
rename from xmlunit-2/src/test/resources/test.xml
rename to testing-modules/xmlunit-2/src/test/resources/test.xml
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/vertx-and-rxjava/.gitignore b/vertx-and-rxjava/.gitignore
new file mode 100644
index 0000000000..3aba11e2fd
--- /dev/null
+++ b/vertx-and-rxjava/.gitignore
@@ -0,0 +1 @@
+/.vertx
\ No newline at end of file
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 ba6a734dc9..540b1fc03b 100644
--- a/xml/pom.xml
+++ b/xml/pom.xml
@@ -1,4 +1,5 @@
-
4.0.0
xml
@@ -14,7 +15,7 @@
- dom4j
+ org.dom4j
dom4j
${dom4j.version}
@@ -23,29 +24,52 @@
jaxen
${jaxen.version}
-
+
+ org.jooq
+ joox-java-6
+ ${joox.version}
+
org.jdom
jdom2
${jdom2.version}
-
- javax.xml
+ javax.xml.bind
jaxb-api
- 2.1
+ ${jaxb-api.version}
+
+
+ com.sun.xml.bind
+ jaxb-impl
+ ${jaxb-impl.version}
+
+
+ com.sun.xml.bind
+ jaxb-core
+ ${jaxb-core.version}
javax.xml
jaxp-api
- 1.4.2
+ ${jaxp-api.version}
javax.xml.stream
stax-api
- 1.0-2
+ ${stax-api.version}
+
+
+
+ org.openjdk.jmh
+ jmh-core
+ ${jmh.version}
+
+
+ org.openjdk.jmh
+ jmh-generator-annprocess
+ ${jmh.version}
-
commons-io
@@ -76,6 +100,31 @@
commons-lang
${commons-lang.version}
+
+
+ org.junit.jupiter
+ junit-jupiter
+ ${junit-jupiter.version}
+ test
+
+
+ org.junit.vintage
+ junit-vintage-engine
+ ${junit-jupiter.version}
+ test
+
+
+ org.assertj
+ assertj-core
+ ${assertj-core.version}
+ test
+
+
+ org.xmlunit
+ xmlunit-assertj
+ ${xmlunit-assertj.version}
+ test
+
@@ -86,6 +135,16 @@
true
+
+
+ maven-compiler-plugin
+ ${maven-compiler-plugin.version}
+
+
+ maven-surefire-plugin
+ ${maven-surefire-plugin.version}
+
+
@@ -213,7 +272,8 @@
-
+
maven-assembly-plugin
${project.basedir}
@@ -232,8 +292,10 @@
- make-assembly
- package
+ make-assembly
+ package
attached
@@ -246,13 +308,22 @@
- 1.6.1
- 1.1.6
+ 2.1.1
+ 1.2.0
2.0.6
+ 1.6.2
2.5
4.1
1.2.4.5
-
+ 2.3.1
+ 1.4.2
+ 2.3.0.1
+ 2.3.2
+ 1.0-2
+ 3.12.2
+ 2.6.3
+ 5.5.0
+ 1.21
3.5
2.4
@@ -260,6 +331,8 @@
1.3.1
+ 3.8.0
+ 2.22.2
diff --git a/xml/src/main/java/com/baeldung/xml/attribute/Dom4jTransformer.java b/xml/src/main/java/com/baeldung/xml/attribute/Dom4jTransformer.java
new file mode 100644
index 0000000000..a1922ad224
--- /dev/null
+++ b/xml/src/main/java/com/baeldung/xml/attribute/Dom4jTransformer.java
@@ -0,0 +1,45 @@
+package com.baeldung.xml.attribute;
+
+import org.dom4j.*;
+import org.dom4j.io.DocumentSource;
+import org.dom4j.io.SAXReader;
+
+import javax.xml.XMLConstants;
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.stream.StreamResult;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.util.List;
+
+public class Dom4jTransformer {
+ private final Document input;
+
+ public Dom4jTransformer(String resourcePath) throws DocumentException {
+ // 1- Build the doc from the XML file
+ SAXReader xmlReader = new SAXReader();
+ this.input = xmlReader.read(resourcePath);
+ }
+
+ public String modifyAttribute(String attribute, String oldValue, String newValue) throws TransformerException {
+ // 2- Locate the node(s) with xpath, we can use index and iterator too.
+ String expr = String.format("//*[contains(@%s, '%s')]", attribute, oldValue);
+ XPath xpath = DocumentHelper.createXPath(expr);
+ List nodes = xpath.selectNodes(input);
+ // 3- Make the change on the selected nodes
+ for (int i = 0; i < nodes.size(); i++) {
+ Element element = (Element) nodes.get(i);
+ element.addAttribute(attribute, newValue);
+ }
+ // 4- Save the result to a new XML doc
+ TransformerFactory factory = TransformerFactory.newInstance();
+ factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
+ Transformer xformer = factory.newTransformer();
+ xformer.setOutputProperty(OutputKeys.INDENT, "yes");
+ Writer output = new StringWriter();
+ xformer.transform(new DocumentSource(input), new StreamResult(output));
+ return output.toString();
+ }
+}
diff --git a/xml/src/main/java/com/baeldung/xml/attribute/JaxpTransformer.java b/xml/src/main/java/com/baeldung/xml/attribute/JaxpTransformer.java
new file mode 100644
index 0000000000..a2266a2b44
--- /dev/null
+++ b/xml/src/main/java/com/baeldung/xml/attribute/JaxpTransformer.java
@@ -0,0 +1,63 @@
+package com.baeldung.xml.attribute;
+
+import java.io.IOException;
+import java.io.StringWriter;
+import java.io.Writer;
+
+import javax.xml.XMLConstants;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.TransformerFactoryConfigurationError;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.xpath.XPath;
+import javax.xml.xpath.XPathConstants;
+import javax.xml.xpath.XPathExpressionException;
+import javax.xml.xpath.XPathFactory;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
+
+public class JaxpTransformer {
+
+ private Document input;
+
+ public JaxpTransformer(String resourcePath) throws SAXException, IOException, ParserConfigurationException {
+ // 1- Build the doc from the XML file
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
+ input = factory.newDocumentBuilder()
+ .parse(resourcePath);
+ }
+
+ public String modifyAttribute(String attribute, String oldValue, String newValue) throws XPathExpressionException, TransformerFactoryConfigurationError, TransformerException {
+ // 2- Locate the node(s) with xpath
+ XPath xpath = XPathFactory.newInstance()
+ .newXPath();
+ NodeList nodes = (NodeList) xpath.evaluate(String.format("//*[contains(@%s, '%s')]", attribute, oldValue), input, XPathConstants.NODESET);
+ // 3- Make the change on the selected nodes
+ for (int i = 0; i < nodes.getLength(); i++) {
+ Element value = (Element) nodes.item(i);
+ value.setAttribute(attribute, newValue);
+ }
+ //Stream api syntax
+ // IntStream
+ // .range(0, nodes.getLength())
+ // .mapToObj(i -> (Element) nodes.item(i))
+ // .forEach(value -> value.setAttribute(attribute, newValue));
+ // 4- Save the result to a new XML doc
+ TransformerFactory factory = TransformerFactory.newInstance();
+ factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
+ Transformer xformer = factory.newTransformer();
+ xformer.setOutputProperty(OutputKeys.INDENT, "yes");
+ Writer output = new StringWriter();
+ xformer.transform(new DOMSource(input), new StreamResult(output));
+ return output.toString();
+ }
+}
diff --git a/xml/src/main/java/com/baeldung/xml/attribute/JooxTransformer.java b/xml/src/main/java/com/baeldung/xml/attribute/JooxTransformer.java
new file mode 100644
index 0000000000..d36d60ec59
--- /dev/null
+++ b/xml/src/main/java/com/baeldung/xml/attribute/JooxTransformer.java
@@ -0,0 +1,38 @@
+package com.baeldung.xml.attribute;
+
+import org.joox.JOOX;
+import org.joox.Match;
+import org.w3c.dom.Document;
+import org.xml.sax.SAXException;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.transform.TransformerFactoryConfigurationError;
+import java.io.IOException;
+
+import static org.joox.JOOX.$;
+
+public class JooxTransformer {
+
+ private final Document input;
+
+ public JooxTransformer(String resourcePath) throws SAXException, IOException {
+ // 1- Build the doc from the XML file
+ DocumentBuilder builder = JOOX.builder();
+ input = builder.parse(resourcePath);
+ }
+
+ public String modifyAttribute(String attribute, String oldValue, String newValue) throws TransformerFactoryConfigurationError {
+ // 2- Select the document
+ Match $ = $(input);
+ // 3 - Find node to modify
+ String expr = String.format("//*[contains(@%s, '%s')]", attribute, oldValue);
+ $
+ // .find("to") or with xpath
+ .xpath(expr)
+ .get()
+ .stream()
+ .forEach(e -> e.setAttribute(attribute, newValue));
+ // 4- Return result as String
+ return $.toString();
+ }
+}
diff --git a/xml/src/main/java/com/baeldung/xml/attribute/jmh/AttributeBenchMark.java b/xml/src/main/java/com/baeldung/xml/attribute/jmh/AttributeBenchMark.java
new file mode 100644
index 0000000000..064e181713
--- /dev/null
+++ b/xml/src/main/java/com/baeldung/xml/attribute/jmh/AttributeBenchMark.java
@@ -0,0 +1,72 @@
+package com.baeldung.xml.attribute.jmh;
+
+import org.dom4j.DocumentException;
+import org.openjdk.jmh.annotations.*;
+import org.openjdk.jmh.runner.Runner;
+import org.openjdk.jmh.runner.RunnerException;
+import org.openjdk.jmh.runner.options.Options;
+import org.openjdk.jmh.runner.options.OptionsBuilder;
+import org.xml.sax.SAXException;
+
+import com.baeldung.xml.attribute.Dom4jTransformer;
+import com.baeldung.xml.attribute.JaxpTransformer;
+import com.baeldung.xml.attribute.JooxTransformer;
+
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.TransformerException;
+import javax.xml.xpath.XPathExpressionException;
+import java.io.IOException;
+import java.util.concurrent.TimeUnit;
+
+@BenchmarkMode(Mode.AverageTime)
+@OutputTimeUnit(TimeUnit.MILLISECONDS)
+@State(Scope.Benchmark)
+public class AttributeBenchMark {
+
+ public static void main(String[] args) throws RunnerException {
+ Options opt = new OptionsBuilder()
+ .include(AttributeBenchMark.class.getSimpleName())
+ .forks(1)
+ .build();
+ new Runner(opt).run();
+ }
+
+ @Benchmark
+ public String dom4jBenchmark() throws DocumentException, TransformerException {
+ String path = getClass()
+ .getResource("/xml/attribute.xml")
+ .toString();
+ Dom4jTransformer transformer = new Dom4jTransformer(path);
+ String attribute = "customer";
+ String oldValue = "true";
+ String newValue = "false";
+
+ return transformer.modifyAttribute(attribute, oldValue, newValue);
+ }
+
+ @Benchmark
+ public String jooxBenchmark() throws IOException, SAXException {
+ String path = getClass()
+ .getResource("/xml/attribute.xml")
+ .toString();
+ JooxTransformer transformer = new JooxTransformer(path);
+ String attribute = "customer";
+ String oldValue = "true";
+ String newValue = "false";
+
+ return transformer.modifyAttribute(attribute, oldValue, newValue);
+ }
+
+ @Benchmark
+ public String jaxpBenchmark() throws TransformerException, ParserConfigurationException, SAXException, IOException, XPathExpressionException {
+ String path = getClass()
+ .getResource("/xml/attribute.xml")
+ .toString();
+ JaxpTransformer transformer = new JaxpTransformer(path);
+ String attribute = "customer";
+ String oldValue = "true";
+ String newValue = "false";
+
+ return transformer.modifyAttribute(attribute, oldValue, newValue);
+ }
+}
diff --git a/xml/src/main/resources/xml/attribute.xml b/xml/src/main/resources/xml/attribute.xml
new file mode 100644
index 0000000000..c8fa3f1071
--- /dev/null
+++ b/xml/src/main/resources/xml/attribute.xml
@@ -0,0 +1,5 @@
+
+
+ john@email.com
+ mary@email.com
+
\ No newline at end of file
diff --git a/xml/src/main/resources/xml/attribute_expected.xml b/xml/src/main/resources/xml/attribute_expected.xml
new file mode 100644
index 0000000000..1d5d7b0cea
--- /dev/null
+++ b/xml/src/main/resources/xml/attribute_expected.xml
@@ -0,0 +1,5 @@
+
+
+ john@email.com
+ mary@email.com
+
\ No newline at end of file
diff --git a/xml/src/test/java/com/baeldung/xml/attribute/Dom4jProcessorUnitTest.java b/xml/src/test/java/com/baeldung/xml/attribute/Dom4jProcessorUnitTest.java
new file mode 100644
index 0000000000..485744f9a5
--- /dev/null
+++ b/xml/src/test/java/com/baeldung/xml/attribute/Dom4jProcessorUnitTest.java
@@ -0,0 +1,55 @@
+package com.baeldung.xml.attribute;
+
+import org.dom4j.DocumentException;
+import org.junit.jupiter.api.Test;
+
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactoryConfigurationError;
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+
+import static org.xmlunit.assertj.XmlAssert.assertThat;
+
+/**
+ * Unit test for {@link Dom4jTransformer}.
+ */
+public class Dom4jProcessorUnitTest {
+
+ @Test
+ public void givenXmlWithAttributes_whenModifyAttribute_thenGetXmlUpdated() throws TransformerFactoryConfigurationError, TransformerException, DocumentException {
+ String path = getClass()
+ .getResource("/xml/attribute.xml")
+ .toString();
+ Dom4jTransformer transformer = new Dom4jTransformer(path);
+ String attribute = "customer";
+ String oldValue = "true";
+ String newValue = "false";
+
+ String result = transformer.modifyAttribute(attribute, oldValue, newValue);
+
+ assertThat(result).hasXPath("//*[contains(@customer, 'false')]");
+ }
+
+ @Test
+ public void givenTwoXml_whenModifyAttribute_thenGetSimilarXml() throws IOException, TransformerFactoryConfigurationError, TransformerException, URISyntaxException, DocumentException {
+ String path = getClass()
+ .getResource("/xml/attribute.xml")
+ .toString();
+ Dom4jTransformer transformer = new Dom4jTransformer(path);
+ String attribute = "customer";
+ String oldValue = "true";
+ String newValue = "false";
+ String expectedXml = new String(Files.readAllBytes((Paths.get(getClass()
+ .getResource("/xml/attribute_expected.xml")
+ .toURI()))));
+
+ String result = transformer.modifyAttribute(attribute, oldValue, newValue);
+
+ assertThat(result)
+ .and(expectedXml)
+ .areSimilar();
+ }
+
+}
diff --git a/xml/src/test/java/com/baeldung/xml/attribute/JaxpProcessorUnitTest.java b/xml/src/test/java/com/baeldung/xml/attribute/JaxpProcessorUnitTest.java
new file mode 100644
index 0000000000..8394016dbd
--- /dev/null
+++ b/xml/src/test/java/com/baeldung/xml/attribute/JaxpProcessorUnitTest.java
@@ -0,0 +1,34 @@
+package com.baeldung.xml.attribute;
+
+import static org.xmlunit.assertj.XmlAssert.assertThat;
+
+import java.io.IOException;
+
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactoryConfigurationError;
+import javax.xml.xpath.XPathExpressionException;
+
+import org.junit.jupiter.api.Test;
+import org.xml.sax.SAXException;
+
+/**
+ * Unit test for {@link JaxpTransformer}.
+ */
+public class JaxpProcessorUnitTest {
+
+ @Test
+ public void givenXmlWithAttributes_whenModifyAttribute_thenGetXmlUpdated() throws IOException, SAXException, ParserConfigurationException, XPathExpressionException, TransformerFactoryConfigurationError, TransformerException {
+ String path = getClass().getResource("/xml/attribute.xml")
+ .toString();
+ JaxpTransformer transformer = new JaxpTransformer(path);
+ String attribute = "customer";
+ String oldValue = "true";
+ String newValue = "false";
+
+ String result = transformer.modifyAttribute(attribute, oldValue, newValue);
+
+ assertThat(result).hasXPath("//*[contains(@customer, 'false')]");
+ }
+
+}
diff --git a/xml/src/test/java/com/baeldung/xml/attribute/JooxProcessorUnitTest.java b/xml/src/test/java/com/baeldung/xml/attribute/JooxProcessorUnitTest.java
new file mode 100644
index 0000000000..38c7c59789
--- /dev/null
+++ b/xml/src/test/java/com/baeldung/xml/attribute/JooxProcessorUnitTest.java
@@ -0,0 +1,54 @@
+package com.baeldung.xml.attribute;
+
+import org.junit.jupiter.api.Test;
+import org.xml.sax.SAXException;
+
+import javax.xml.transform.TransformerFactoryConfigurationError;
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+
+import static org.xmlunit.assertj.XmlAssert.assertThat;
+
+/**
+ * Unit test for {@link JooxTransformer}.
+ */
+public class JooxProcessorUnitTest {
+
+ @Test
+ public void givenXmlWithAttributes_whenModifyAttribute_thenGetXmlUpdated() throws IOException, SAXException, TransformerFactoryConfigurationError {
+ String path = getClass()
+ .getResource("/xml/attribute.xml")
+ .toString();
+ JooxTransformer transformer = new JooxTransformer(path);
+ String attribute = "customer";
+ String oldValue = "true";
+ String newValue = "false";
+
+ String result = transformer.modifyAttribute(attribute, oldValue, newValue);
+
+ assertThat(result).hasXPath("//*[contains(@customer, 'false')]");
+ }
+
+ @Test
+ public void givenTwoXml_whenModifyAttribute_thenGetSimilarXml() throws IOException, TransformerFactoryConfigurationError, URISyntaxException, SAXException {
+ String path = getClass()
+ .getResource("/xml/attribute.xml")
+ .toString();
+ JooxTransformer transformer = new JooxTransformer(path);
+ String attribute = "customer";
+ String oldValue = "true";
+ String newValue = "false";
+ String expectedXml = new String(Files.readAllBytes((Paths.get(getClass()
+ .getResource("/xml/attribute_expected.xml")
+ .toURI()))));
+
+ String result = transformer.modifyAttribute(attribute, oldValue, newValue);
+
+ assertThat(result)
+ .and(expectedXml)
+ .areSimilar();
+ }
+
+}
diff --git a/xml/src/test/resources/xml/attribute.xml b/xml/src/test/resources/xml/attribute.xml
new file mode 100644
index 0000000000..c8fa3f1071
--- /dev/null
+++ b/xml/src/test/resources/xml/attribute.xml
@@ -0,0 +1,5 @@
+
+
+ john@email.com
+ mary@email.com
+
\ No newline at end of file
diff --git a/xml/src/test/resources/xml/attribute_expected.xml b/xml/src/test/resources/xml/attribute_expected.xml
new file mode 100644
index 0000000000..1d5d7b0cea
--- /dev/null
+++ b/xml/src/test/resources/xml/attribute_expected.xml
@@ -0,0 +1,5 @@
+
+
+ john@email.com
+ mary@email.com
+
\ No newline at end of file
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
+
+
+