Search in sources :

Example 86 with MvcResult

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

the class ProfessionalTypeControllerTests method testGetProfessionalType.

@Test
@DatabaseSetup("/data/professionaltype/professional-type-after-updating.xml")
@ExpectedDatabase(table = "professional_types", value = "/data/professionaltype/professional-type-after-updating.xml", assertionMode = NON_STRICT)
public void testGetProfessionalType() throws Exception {
    MvcResult mvcResult = mvc.perform(get("/api/v1/user-management/professional-types/" + PROFESSIONAL_TYPE_ID)).andExpect(OK_STATUS).andExpect(NO_ERROR_CODE).andReturn();
    JSONAssert.assertEquals(UPDATED_PROFESSIONAL_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 87 with MvcResult

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

the class ProfessionalTypeControllerTests method testCreateProfessionalType.

@Test
@DatabaseSetup(value = "/data/professionaltype/empty-professional-type.xml")
@ExpectedDatabase(table = "users_data", value = "/data/users-without-external-dependency.xml", assertionMode = NON_STRICT)
public void testCreateProfessionalType() throws Exception {
    CommonProfessionalTypeDTO professionalTypeDTO = new CommonProfessionalTypeDTO();
    professionalTypeDTO.setName(PROFESSIONAL_TYPE_NAME);
    MvcResult mvcResult = mvc.perform(post("/api/v1/admin/professional-types/").contentType(APPLICATION_JSON).content(objectMapper.writeValueAsBytes(professionalTypeDTO))).andExpect(jsonPath("$.result.id").isNotEmpty()).andExpect(OK_STATUS).andExpect(NO_ERROR_CODE).andReturn();
    JSONAssert.assertEquals(PROFESSIONAL_TYPE_JSON_OBJECT, getResultJSONObject(mvcResult), false);
}
Also used : CommonProfessionalTypeDTO(com.odysseusinc.arachne.commons.api.v1.dto.CommonProfessionalTypeDTO) MvcResult(org.springframework.test.web.servlet.MvcResult) ExpectedDatabase(com.github.springtestdbunit.annotation.ExpectedDatabase) Test(org.junit.Test) DatabaseSetup(com.github.springtestdbunit.annotation.DatabaseSetup)

Example 88 with MvcResult

use of org.springframework.test.web.servlet.MvcResult in project nixmash-blog by mintster.

the class GlobalControllerTests method googleAnalyticsAnonymousUserTest.

@Test
@WithAnonymousUser
public void googleAnalyticsAnonymousUserTest() throws Exception {
    RequestBuilder request = get("/").with(csrf());
    MvcResult result = mockMvc.perform(request).andReturn();
    assertTrue(result.getResponse().getContentAsString().contains(TRACKING_ID));
}
Also used : RequestBuilder(org.springframework.test.web.servlet.RequestBuilder) MvcResult(org.springframework.test.web.servlet.MvcResult) WithAnonymousUser(org.springframework.security.test.context.support.WithAnonymousUser) Test(org.junit.Test)

Example 89 with MvcResult

use of org.springframework.test.web.servlet.MvcResult in project nixmash-blog by mintster.

the class PermaPostsControllerTests method summaryTwitterCardMetaDataExists.

@Test
public void summaryTwitterCardMetaDataExists() throws Exception {
    // H2 PostId 1L has SUMMARY as TwitterCardType
    MvcResult mvcResult = this.mockMvc.perform(get("/post/javascript-bootstrap")).andExpect(status().isOk()).andReturn();
    assertThat(mvcResult.getResponse().getContentAsString(), containsString("<meta name=\"twitter:card\" content=\"summary\" />"));
}
Also used : MvcResult(org.springframework.test.web.servlet.MvcResult) Test(org.junit.Test)

Example 90 with MvcResult

use of org.springframework.test.web.servlet.MvcResult in project nixmash-blog by mintster.

the class PostsRestControllerTests method moreLikeThis_PostDocNumLessThanAppSetting.

@Test
public void moreLikeThis_PostDocNumLessThanAppSetting() throws Exception {
    // MoreLikeThis PopulatePostStream() throws IndexOutOfBoundsException
    // Returns No MoreLikeThis Posts message containing "nomlt-message" classname
    applicationSettings.setMoreLikeThisNum(1000);
    mockMvc.perform(get("/post/" + MLT_POSTNAME)).andExpect(model().attributeExists(MORELIKETHIS_ATTRIBUTE));
    MvcResult mvcResult = mockMvc.perform(get("/json/posts/post/mlt/" + MLT_POSTID)).andExpect(status().isOk()).andExpect(content().contentTypeCompatibleWith(MediaType.TEXT_HTML)).andReturn();
    assertThat(mvcResult.getResponse().getContentAsString(), containsString("<div class=\"nomlt-message\">"));
}
Also used : MvcResult(org.springframework.test.web.servlet.MvcResult) Test(org.junit.Test)

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