Search in sources :

Example 71 with MvcResult

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

the class StudyTypeControllerTests method testGetStudyType.

@Test
@DatabaseSetup("/data/study/type/study-type-after-updating.xml")
@ExpectedDatabase(value = "/data/study/type/study-type-after-updating.xml", assertionMode = NON_STRICT)
public void testGetStudyType() throws Exception {
    MvcResult mvcResult = mvc.perform(get("/api/v1/study-management/study-types/" + ID)).andExpect(OK_STATUS).andReturn();
    JSONAssert.assertEquals(UPDATED_STUDY_TYPE_JSON_OBJECT, getResultJSONObject(mvcResult), false);
}
Also used : MvcResult(org.springframework.test.web.servlet.MvcResult) ExpectedDatabase(com.github.springtestdbunit.annotation.ExpectedDatabase) Test(org.junit.Test) DatabaseSetup(com.github.springtestdbunit.annotation.DatabaseSetup)

Example 72 with MvcResult

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

the class StudyTypeControllerTests method testCreateStudyType.

@Test
@DatabaseSetup("/data/study/type/empty-study-type.xml")
@ExpectedDatabase(value = "/data/study/type/added-study-type.xml", assertionMode = NON_STRICT)
public void testCreateStudyType() throws Exception {
    CreateStudyTypeDTO dto = new CreateStudyTypeDTO();
    dto.setName(NAME);
    MvcResult mvcResult = mvc.perform(post("/api/v1/admin/study-types").contentType(APPLICATION_JSON).content(objectMapper.writeValueAsBytes(dto))).andExpect(jsonPath("$.result.id").isNotEmpty()).andExpect(OK_STATUS).andReturn();
    JSONAssert.assertEquals(STUDY_TYPE_JSON_OBJECT, getResultJSONObject(mvcResult), false);
}
Also used : MvcResult(org.springframework.test.web.servlet.MvcResult) CreateStudyTypeDTO(com.odysseusinc.arachne.portal.api.v1.dto.dictionary.CreateStudyTypeDTO) ExpectedDatabase(com.github.springtestdbunit.annotation.ExpectedDatabase) Test(org.junit.Test) DatabaseSetup(com.github.springtestdbunit.annotation.DatabaseSetup)

Example 73 with MvcResult

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

the class UserControllerTests method testSuggest.

@Test
@WithUserDetails(value = ADMIN_EMAIL)
@DatabaseSetup(value = "/data/user/users-for-suggestion.xml")
@ExpectedDatabase(value = "/data/user/users-for-suggestion.xml", assertionMode = NON_STRICT)
public void testSuggest() throws Exception {
    final String query = "fir";
    final Long studyId = 1L;
    MvcResult mvcResult = mvc.perform(get("/api/v1/user-management/users/suggest?target=STUDY&query=" + query + "&id=" + studyId)).andExpect(OK_STATUS).andExpect(jsonPath("$").isArray()).andExpect(jsonPath("$", hasSize(3))).andReturn();
    JSONArray suggested = new JSONArray(mvcResult.getResponse().getContentAsString());
    List<Object> list = new ArrayList<>();
    for (int i = 0; i < suggested.length(); i++) {
        list.add(suggested.getJSONObject(i).get("id"));
    }
    // suggested user ids
    Assert.assertTrue(list.contains(UserIdUtils.idToUuid(3L)));
    Assert.assertTrue(list.contains(UserIdUtils.idToUuid(6L)));
    Assert.assertTrue(list.contains(UserIdUtils.idToUuid(7L)));
}
Also used : JSONArray(org.json.JSONArray) ArrayList(java.util.ArrayList) JSONObject(org.json.JSONObject) 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 74 with MvcResult

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

the class UserControllerTests method testDeletePublicationFromUser.

@Test
@WithUserDetails(value = ADMIN_EMAIL)
@DatabaseSetup("/data/user/admin-user-with-publication-for-deleting.xml")
@ExpectedDatabase(value = "/data/user/admin-user.xml", assertionMode = NON_STRICT)
public void testDeletePublicationFromUser() throws Exception {
    Integer publicationId = 1;
    MvcResult mvcResult = mvc.perform(delete("/api/v1/user-management/users/publications/" + publicationId)).andExpect(jsonPath("$.result.publications").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 75 with MvcResult

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

the class UserControllerTests method testLinkToUser.

@Test
@WithUserDetails(value = ADMIN_EMAIL)
@DatabaseSetup("/data/user/admin-user.xml")
@ExpectedDatabase(value = "/data/user/admin-user-with-link.xml", assertionMode = NON_STRICT)
public void testLinkToUser() throws Exception {
    UserLinkDTO link = getUserLinkDTO();
    MvcResult mvcResult = mvc.perform(post("/api/v1/user-management/users/links").contentType(APPLICATION_JSON).content(objectMapper.writeValueAsString(link))).andExpect(NO_ERROR_CODE).andExpect(OK_STATUS).andExpect(jsonPath("$.result.links").isNotEmpty()).andExpect(jsonPath("$.result.links").isArray()).andExpect(jsonPath("$.result.links", hasSize(1))).andReturn();
    JSONAssert.assertEquals(ADMIN_JSON_OBJECT, getGeneral(mvcResult), FALSE);
    JSONArray links = (JSONArray) getResultJSONObject(mvcResult).get("links");
    JSONAssert.assertEquals(USER_LINK, (JSONObject) links.get(0), FALSE);
}
Also used : UserLinkDTO(com.odysseusinc.arachne.portal.api.v1.dto.UserLinkDTO) JSONArray(org.json.JSONArray) 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)

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