Merge pull request #6269 from amit2103/BAEL-10924

[BAEL-10924] - Fixed spring-data-rest integration tests
This commit is contained in:
Loredana Crusoveanu 2019-02-03 16:13:54 +02:00 committed by GitHub
commit 438846642e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 7 deletions

View File

@ -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");