Search in sources :

Example 81 with MvcResult

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

the class AnalysisControllerTests method testGetAnalysis.

@Test
@WithUserDetails(value = ADMIN_EMAIL)
@DatabaseSetups({ @DatabaseSetup("/data/study-with-contributor.xml"), @DatabaseSetup("/data/analysis/analysis-after-title-updating.xml") })
@ExpectedDatabases({ @ExpectedDatabase(value = "/data/study-with-contributor.xml", assertionMode = NON_STRICT), @ExpectedDatabase(value = "/data/analysis/analysis-after-title-updating.xml", assertionMode = NON_STRICT) })
public void testGetAnalysis() throws Exception {
    MvcResult mvcResult = mvc.perform(get("/api/v1/analysis-management/analyses/" + ANALYSIS_ID)).andExpect(OK_STATUS).andExpect(NO_ERROR_CODE).andReturn();
    JSONAssert.assertEquals(UPDATED_ANALYSIS_JSON_OBJECT, getResultJSONObject(mvcResult), false);
}
Also used : MvcResult(org.springframework.test.web.servlet.MvcResult) DatabaseSetups(com.github.springtestdbunit.annotation.DatabaseSetups) Test(org.junit.Test) WithUserDetails(org.springframework.security.test.context.support.WithUserDetails) ExpectedDatabases(com.github.springtestdbunit.annotation.ExpectedDatabases)

Example 82 with MvcResult

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

the class AnalysisControllerTests method testUpdate.

private void testUpdate(AnalysisUpdateDTO analysisDTO, JSONObject expected, String newValue) throws Exception {
    MvcResult mvcResult = mvc.perform(put("/api/v1/analysis-management/analyses/" + ANALYSIS_ID).contentType(APPLICATION_JSON).content(objectMapper.writeValueAsBytes(analysisDTO))).andExpect(OK_STATUS).andExpect(NO_ERROR_CODE).andReturn();
    JSONObject result = getResultJSONObject(mvcResult);
    JSONAssert.assertEquals(expected, result, false);
}
Also used : JSONObject(org.json.JSONObject) MvcResult(org.springframework.test.web.servlet.MvcResult)

Example 83 with MvcResult

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

the class AnalysisSubmissionControllerTests method createSubmission.

private void createSubmission(Long studyId, Long analysisId, Long dataSourceId) throws Exception {
    final MvcResult mvcResult = sendRequest(studyId, analysisId, dataSourceId).andExpect(NO_ERROR_CODE).andExpect(jsonPath("$.result").isArray()).andExpect(jsonPath("$.result", hasSize(1))).andReturn();
    JSONObject expectedJsonObject = new JSONObject().put("dataSource", new JSONObject().put("id", dataSourceId));
    JSONAssert.assertEquals(expectedJsonObject, getResultJSONArray(mvcResult).getJSONObject(0), false);
}
Also used : JSONObject(org.json.JSONObject) MvcResult(org.springframework.test.web.servlet.MvcResult)

Example 84 with MvcResult

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

the class AuthControllerTests method testRefreshToken.

@Test
public void testRefreshToken() throws Exception {
    String authToken = login();
    MvcResult mvcResult = mvc.perform(post("/api/v1/auth/refresh").header(tokenHeader, authToken).contentType(APPLICATION_JSON)).andExpect(NO_ERROR_CODE).andReturn();
    authToken = getResponse(mvcResult).getString("result");
    mvc.perform(get("/api/v1/test").header(tokenHeader, authToken).contentType(APPLICATION_JSON)).andExpect(status().isNotFound());
}
Also used : MvcResult(org.springframework.test.web.servlet.MvcResult) Test(org.junit.Test)

Example 85 with MvcResult

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

the class RoleControllerTests method testUpdateRole.

@Test
@DatabaseSetup(value = "/data/role/role-before-updating.xml")
@ExpectedDatabase(table = "roles", value = "/data/role/roles.xml", assertionMode = NON_STRICT_UNORDERED)
public void testUpdateRole() throws Exception {
    RoleDTO roleDTO = new RoleDTO();
    roleDTO.setId(ROLE_ID);
    roleDTO.setName(UPDATED_ROLE_NAME);
    roleDTO.setDescription(ROLE_DESCRIPTION);
    MvcResult mvcResult = mvc.perform(put("/api/v1/admin/roles/" + ROLE_ID).contentType(APPLICATION_JSON).content(objectMapper.writeValueAsBytes(roleDTO))).andExpect(jsonPath("$.result.id").isNotEmpty()).andExpect(OK_STATUS).andExpect(NO_ERROR_CODE).andReturn();
    JSONAssert.assertEquals(UPDATED_ROLE_JSON_OBJECT, getResultJSONObject(mvcResult), false);
}
Also used : RoleDTO(com.odysseusinc.arachne.portal.api.v1.dto.dictionary.RoleDTO) 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