Search in sources :

Example 66 with MvcResult

use of org.springframework.test.web.servlet.MvcResult in project Saturn by vipshop.

the class JobOperationRestApiControllerTest method testCreateFailAsInvalidJobType.

@Test
public void testCreateFailAsInvalidJobType() throws Exception {
    JobEntity jobEntity = constructJobEntity("job1");
    // jobType should be mandatory
    jobEntity.setConfig("jobType", "abc");
    MvcResult result = mvc.perform(post("/rest/v1/domain/jobs").contentType(MediaType.APPLICATION_JSON).content(jobEntity.toJSON())).andExpect(status().isBadRequest()).andReturn();
    String message = fetchErrorMessage(result);
    assertEquals("error message not equal", "Invalid request. Parameter: {jobType} is malformed", message);
}
Also used : MvcResult(org.springframework.test.web.servlet.MvcResult) Test(org.junit.Test) WebMvcTest(org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest) AbstractSaturnConsoleTest(com.vip.saturn.job.console.AbstractSaturnConsoleTest)

Example 67 with MvcResult

use of org.springframework.test.web.servlet.MvcResult in project Saturn by vipshop.

the class JobOperationRestApiControllerTest method testCreateFailAsUnExpectedExceptionThrows.

@Test
public void testCreateFailAsUnExpectedExceptionThrows() throws Exception {
    String customErrMsg = "unexpected exception";
    willThrow(new RuntimeException(customErrMsg)).given(restApiService).createJob(any(String.class), any(JobConfig.class));
    JobEntity jobEntity = constructJobEntity("job1");
    MvcResult result = mvc.perform(post("/rest/v1/domain/jobs").contentType(MediaType.APPLICATION_JSON).content(jobEntity.toJSON())).andExpect(status().isInternalServerError()).andReturn();
    String message = fetchErrorMessage(result);
    assertEquals("error message not equal", customErrMsg, message);
}
Also used : MvcResult(org.springframework.test.web.servlet.MvcResult) RestApiJobConfig(com.vip.saturn.job.console.domain.RestApiJobConfig) JobConfig(com.vip.saturn.job.console.domain.JobConfig) Test(org.junit.Test) WebMvcTest(org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest) AbstractSaturnConsoleTest(com.vip.saturn.job.console.AbstractSaturnConsoleTest)

Example 68 with MvcResult

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

the class StudyControllerTests method testGetStudy.

@Test
@WithUserDetails(value = ADMIN_EMAIL)
@DatabaseSetup("/data/study/study-after-updating-description.xml")
@ExpectedDatabase(value = "/data/study/study-after-updating-description.xml", assertionMode = NON_STRICT)
public void testGetStudy() throws Exception {
    MvcResult mvcResult = mvc.perform(get("/api/v1/study-management/studies/" + STUDY_ID)).andExpect(NO_ERROR_CODE).andExpect(jsonPath("$.result.id").isNotEmpty()).andReturn();
    JSONAssert.assertEquals(UPDATED_STUDY_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 69 with MvcResult

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

the class SkillControllerTests method testGetSkill.

@Test
@DatabaseSetup("/data/skill/skill-after-updating.xml")
@ExpectedDatabase(value = "/data/skill/skill-after-updating.xml", assertionMode = NON_STRICT)
public void testGetSkill() throws Exception {
    MvcResult mvcResult = mvc.perform(get("/api/v1/user-management/skills/" + SKILL_ID)).andExpect(OK_STATUS).andExpect(NO_ERROR_CODE).andReturn();
    JSONAssert.assertEquals(UPDATED_SKILL_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 70 with MvcResult

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

the class SkillControllerTests method testCreateSkill.

@Test
@DatabaseSetup("/data/skill/empty-skill.xml")
@ExpectedDatabase(value = "/data/skill/added-skill.xml", assertionMode = NON_STRICT)
public void testCreateSkill() throws Exception {
    SkillDTO skillDTO = new SkillDTO();
    skillDTO.setName(SKILL_NAME);
    MvcResult mvcResult = mvc.perform(post("/api/v1/user-management/skills/").contentType(APPLICATION_JSON).content(objectMapper.writeValueAsBytes(skillDTO))).andExpect(jsonPath("$.result.id").isNotEmpty()).andExpect(OK_STATUS).andExpect(NO_ERROR_CODE).andReturn();
    JSONAssert.assertEquals(SKILL_JSON_OBJECT, getResultJSONObject(mvcResult), false);
}
Also used : SkillDTO(com.odysseusinc.arachne.portal.api.v1.dto.dictionary.SkillDTO) 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