Search in sources :

Example 76 with MvcResult

use of org.springframework.test.web.servlet.MvcResult in project ArachneCentralAPI by OHDSI.

the class UserControllerTests method testGetProfile.

@Test
@WithUserDetails(value = ADMIN_EMAIL)
@DatabaseSetup("/data/user/enabled-user.xml")
@ExpectedDatabase(value = "/data/user/enabled-user.xml", assertionMode = NON_STRICT)
public void testGetProfile() throws Exception {
    MvcResult mvcResult = mvc.perform(get("/api/v1/user-management/users/" + USER_2_UUID + "/profile")).andExpect(NO_ERROR_CODE).andExpect(OK_STATUS).andReturn();
    JSONAssert.assertEquals(USER_JSON_OBJECT, getGeneral(mvcResult), false);
}
Also used : MvcResult(org.springframework.test.web.servlet.MvcResult) ExpectedDatabase(com.github.springtestdbunit.annotation.ExpectedDatabase) Test(org.junit.Test) WithUserDetails(org.springframework.security.test.context.support.WithUserDetails) DatabaseSetup(com.github.springtestdbunit.annotation.DatabaseSetup)

Example 77 with MvcResult

use of org.springframework.test.web.servlet.MvcResult in project ArachneCentralAPI by OHDSI.

the class UserControllerTests method testRemoveLinkFromUser.

@Test
@WithUserDetails(value = ADMIN_EMAIL)
@DatabaseSetup("/data/user/admin-user-with-link-for-deleting.xml")
@ExpectedDatabase(value = "/data/user/admin-user.xml", assertionMode = NON_STRICT)
public void testRemoveLinkFromUser() throws Exception {
    final Integer linkId = 1;
    MvcResult mvcResult = mvc.perform(delete("/api/v1/user-management/users/links/" + linkId)).andExpect(NO_ERROR_CODE).andExpect(OK_STATUS).andExpect(jsonPath("$.result.skills").isEmpty()).andReturn();
    JSONAssert.assertEquals(ADMIN_JSON_OBJECT, getGeneral(mvcResult), FALSE);
}
Also used : MvcResult(org.springframework.test.web.servlet.MvcResult) ExpectedDatabase(com.github.springtestdbunit.annotation.ExpectedDatabase) Test(org.junit.Test) WithUserDetails(org.springframework.security.test.context.support.WithUserDetails) DatabaseSetup(com.github.springtestdbunit.annotation.DatabaseSetup)

Example 78 with MvcResult

use of org.springframework.test.web.servlet.MvcResult in project ArachneCentralAPI by OHDSI.

the class UserControllerTests method testAddPublicationToUser.

@Test
@WithUserDetails(value = ADMIN_EMAIL)
@DatabaseSetup("/data/user/admin-user.xml")
@ExpectedDatabase(value = "/data/user/admin-user-with-publication.xml", assertionMode = NON_STRICT)
public void testAddPublicationToUser() throws Exception {
    UserPublicationDTO inputDTO = new UserPublicationDTO();
    inputDTO.setDescription(USER_LINK_DESCRIPTION);
    inputDTO.setTitle(USER_LINK_TITLE);
    inputDTO.setUrl(USER_LINK_URL);
    inputDTO.setDate(DATE);
    inputDTO.setPublisher(PUBLISHER);
    MvcResult mvcResult = mvc.perform(post("/api/v1/user-management/users/publications").contentType(APPLICATION_JSON).content(objectMapper.writeValueAsString(inputDTO))).andExpect(NO_ERROR_CODE).andExpect(OK_STATUS).andExpect(jsonPath("$.result.publications").isNotEmpty()).andExpect(jsonPath("$.result.publications", hasSize(1))).andReturn();
    JSONAssert.assertEquals(ADMIN_JSON_OBJECT, getGeneral(mvcResult), FALSE);
    JSONArray publications = (JSONArray) getResultJSONObject(mvcResult).get("publications");
    JSONAssert.assertEquals(PUBLICATION, (JSONObject) publications.get(0), FALSE);
}
Also used : JSONArray(org.json.JSONArray) UserPublicationDTO(com.odysseusinc.arachne.portal.api.v1.dto.UserPublicationDTO) MvcResult(org.springframework.test.web.servlet.MvcResult) ExpectedDatabase(com.github.springtestdbunit.annotation.ExpectedDatabase) Test(org.junit.Test) WithUserDetails(org.springframework.security.test.context.support.WithUserDetails) DatabaseSetup(com.github.springtestdbunit.annotation.DatabaseSetup)

Example 79 with MvcResult

use of org.springframework.test.web.servlet.MvcResult in project ArachneCentralAPI by OHDSI.

the class UserControllerTests method testGetUserInfo.

@Test
@WithUserDetails(value = ADMIN_EMAIL)
@DatabaseSetup("/data/user/admin-user.xml")
@ExpectedDatabase(value = "/data/user/admin-user.xml", assertionMode = NON_STRICT)
public void testGetUserInfo() throws Exception {
    MvcResult mvcResult = mvc.perform(get("/api/v1/auth/me")).andExpect(NO_ERROR_CODE).andExpect(OK_STATUS).andReturn();
    JSONAssert.assertEquals(ADMIN_JSON_OBJECT, getResultJSONObject(mvcResult), false);
}
Also used : MvcResult(org.springframework.test.web.servlet.MvcResult) ExpectedDatabase(com.github.springtestdbunit.annotation.ExpectedDatabase) Test(org.junit.Test) WithUserDetails(org.springframework.security.test.context.support.WithUserDetails) DatabaseSetup(com.github.springtestdbunit.annotation.DatabaseSetup)

Example 80 with MvcResult

use of org.springframework.test.web.servlet.MvcResult in project ArachneCentralAPI by OHDSI.

the class UserControllerTests method testCreateUser.

@Test
@DatabaseSetup("/data/user/admin-user.xml")
@ExpectedDatabase(value = "/data/user/registered-user-and-admin.xml", assertionMode = DatabaseAssertionMode.NON_STRICT)
public void testCreateUser() throws Exception {
    CommonUserRegistrationDTO inputDTO = getCommonUserRegistrationDTO(PASSWORD);
    MvcResult mvcResult = mvc.perform(post("/api/v1/auth/registration").contentType(APPLICATION_JSON).content(objectMapper.writeValueAsBytes(inputDTO)).with(anonymous())).andExpect(OK_STATUS).andReturn();
}
Also used : CommonUserRegistrationDTO(com.odysseusinc.arachne.commons.api.v1.dto.CommonUserRegistrationDTO) MvcResult(org.springframework.test.web.servlet.MvcResult) ExpectedDatabase(com.github.springtestdbunit.annotation.ExpectedDatabase) Test(org.junit.Test) DatabaseSetup(com.github.springtestdbunit.annotation.DatabaseSetup)

Aggregations

MvcResult (org.springframework.test.web.servlet.MvcResult)536 Test (org.junit.Test)300 Test (org.junit.jupiter.api.Test)143 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)132 ResultMatcher (org.springframework.test.web.servlet.ResultMatcher)69 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)38 MockHttpSession (org.springframework.mock.web.MockHttpSession)35 MockHttpServletRequestBuilder (org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder)34 WebMvcTest (org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest)31 DatabaseSetup (com.github.springtestdbunit.annotation.DatabaseSetup)26 ExpectedDatabase (com.github.springtestdbunit.annotation.ExpectedDatabase)26 RequestBuilder (org.springframework.test.web.servlet.RequestBuilder)24 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)22 Map (java.util.Map)22 ResultActions (org.springframework.test.web.servlet.ResultActions)19 Cookie (javax.servlet.http.Cookie)18 MockMvc (org.springframework.test.web.servlet.MockMvc)17 HttpSession (jakarta.servlet.http.HttpSession)16 JsonNode (com.fasterxml.jackson.databind.JsonNode)15 AbstractSaturnConsoleTest (com.vip.saturn.job.console.AbstractSaturnConsoleTest)15