From 22379add8edf84b76bf4e584d2c91005f6b372ef Mon Sep 17 00:00:00 2001 From: amit2103 Date: Sun, 3 Feb 2019 15:03:02 +0530 Subject: [PATCH] [BAEL-10924] - Fixed spring-data-rest integration tests --- ...pringDataRestValidatorIntegrationTest.java | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/spring-data-rest/src/test/java/com/baeldung/validator/SpringDataRestValidatorIntegrationTest.java b/spring-data-rest/src/test/java/com/baeldung/validator/SpringDataRestValidatorIntegrationTest.java index d41736e434..6da76d6a33 100644 --- a/spring-data-rest/src/test/java/com/baeldung/validator/SpringDataRestValidatorIntegrationTest.java +++ b/spring-data-rest/src/test/java/com/baeldung/validator/SpringDataRestValidatorIntegrationTest.java @@ -1,8 +1,12 @@ package com.baeldung.validator; -import com.baeldung.SpringDataRestApplication; -import com.baeldung.models.WebsiteUser; -import com.fasterxml.jackson.databind.ObjectMapper; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.redirectedUrl; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import static org.springframework.test.web.servlet.setup.MockMvcBuilders.webAppContextSetup; + import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -10,14 +14,14 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.http.MediaType; +import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.web.servlet.MockMvc; import org.springframework.web.context.WebApplicationContext; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.redirectedUrl; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -import static org.springframework.test.web.servlet.setup.MockMvcBuilders.webAppContextSetup; +import com.baeldung.SpringDataRestApplication; +import com.baeldung.models.WebsiteUser; +import com.fasterxml.jackson.databind.ObjectMapper; @RunWith(SpringJUnit4ClassRunner.class) @SpringBootTest(classes = SpringDataRestApplication.class, webEnvironment = SpringBootTest.WebEnvironment.MOCK) @@ -42,6 +46,7 @@ public class SpringDataRestValidatorIntegrationTest { }; @Test + @DirtiesContext(methodMode = DirtiesContext.MethodMode.BEFORE_METHOD) public void whenAddingNewCorrectUser_thenCorrectStatusCodeAndResponse() throws Exception { WebsiteUser user = new WebsiteUser(); user.setEmail("john.doe@john.com"); @@ -83,6 +88,7 @@ public class SpringDataRestValidatorIntegrationTest { } @Test + @DirtiesContext(methodMode = DirtiesContext.MethodMode.BEFORE_METHOD) public void whenDeletingCorrectUser_thenCorrectStatusCodeAndResponse() throws Exception { WebsiteUser user = new WebsiteUser(); user.setEmail("john.doe@john.com"); @@ -92,6 +98,7 @@ public class SpringDataRestValidatorIntegrationTest { } @Test + @DirtiesContext(methodMode = DirtiesContext.MethodMode.BEFORE_METHOD) public void whenSearchingByEmail_thenCorrectStatusCodeAndResponse() throws Exception { WebsiteUser user = new WebsiteUser(); user.setEmail("john.doe@john.com");