Fixed spring-data-rest integration tests
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");
