Search in sources :

Example 41 with MvcResult

use of org.springframework.test.web.servlet.MvcResult in project uhgroupings by uhawaii-system-its-ti-iam.

the class TestGroupingsRestController method mapGroupingAssignment.

private GroupingAssignment mapGroupingAssignment() throws Exception {
    ObjectMapper objectMapper = new ObjectMapper();
    MvcResult result = mockMvc.perform(get("/api/groupings/groupingAssignment").with(csrf())).andExpect(status().isOk()).andReturn();
    return objectMapper.readValue(result.getResponse().getContentAsByteArray(), GroupingAssignment.class);
}
Also used : MvcResult(org.springframework.test.web.servlet.MvcResult) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 42 with MvcResult

use of org.springframework.test.web.servlet.MvcResult in project open-kilda by telstra.

the class FlowControllerTest method pathFlow.

@Test
@WithMockUser(username = USERNAME, password = PASSWORD, roles = ROLE)
public void pathFlow() throws Exception {
    MvcResult result = mockMvc.perform(get("/flows/path/{flow-id}", TestMessageMock.FLOW_ID).header(CORRELATION_ID, testCorrelationId()).contentType(APPLICATION_JSON_VALUE)).andExpect(status().isOk()).andExpect(content().contentType(APPLICATION_JSON_UTF8_VALUE)).andReturn();
    FlowPathPayload response = MAPPER.readValue(result.getResponse().getContentAsString(), FlowPathPayload.class);
    assertEquals(TestMessageMock.flowPath, response);
}
Also used : FlowPathPayload(org.openkilda.messaging.payload.flow.FlowPathPayload) MvcResult(org.springframework.test.web.servlet.MvcResult) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test)

Example 43 with MvcResult

use of org.springframework.test.web.servlet.MvcResult in project open-kilda by telstra.

the class FlowControllerTest method deleteFlows.

@Test
@WithMockUser(username = USERNAME, password = PASSWORD, roles = ROLE)
public void deleteFlows() throws Exception {
    MvcResult result = mockMvc.perform(delete("/flows").header(CORRELATION_ID, testCorrelationId()).header(EXTRA_AUTH, System.currentTimeMillis() - TimeUnit.SECONDS.toMillis(119)).contentType(APPLICATION_JSON_VALUE)).andExpect(status().isOk()).andExpect(content().contentType(APPLICATION_JSON_UTF8_VALUE)).andReturn();
    FlowPayload[] response = MAPPER.readValue(result.getResponse().getContentAsString(), FlowPayload[].class);
    assertEquals(TestMessageMock.flow, response[0]);
}
Also used : FlowPayload(org.openkilda.messaging.payload.flow.FlowPayload) MvcResult(org.springframework.test.web.servlet.MvcResult) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test)

Example 44 with MvcResult

use of org.springframework.test.web.servlet.MvcResult in project open-kilda by telstra.

the class FlowControllerTest method statusFlow.

@Test
@WithMockUser(username = USERNAME, password = PASSWORD, roles = ROLE)
public void statusFlow() throws Exception {
    MvcResult result = mockMvc.perform(get("/flows/status/{flow-id}", TestMessageMock.FLOW_ID).header(CORRELATION_ID, testCorrelationId()).contentType(APPLICATION_JSON_VALUE)).andExpect(status().isOk()).andExpect(content().contentType(APPLICATION_JSON_UTF8_VALUE)).andReturn();
    FlowIdStatusPayload response = MAPPER.readValue(result.getResponse().getContentAsString(), FlowIdStatusPayload.class);
    assertEquals(TestMessageMock.flowStatus, response);
}
Also used : FlowIdStatusPayload(org.openkilda.messaging.payload.flow.FlowIdStatusPayload) MvcResult(org.springframework.test.web.servlet.MvcResult) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test)

Example 45 with MvcResult

use of org.springframework.test.web.servlet.MvcResult in project open-kilda by telstra.

the class FlowControllerTest method getFlow.

@Test
@WithMockUser(username = USERNAME, password = PASSWORD, roles = ROLE)
public void getFlow() throws Exception {
    MvcResult result = mockMvc.perform(get("/flows/{flow-id}", TestMessageMock.FLOW_ID).header(CORRELATION_ID, testCorrelationId()).contentType(APPLICATION_JSON_VALUE)).andExpect(status().isOk()).andExpect(content().contentType(APPLICATION_JSON_UTF8_VALUE)).andReturn();
    FlowPayload response = MAPPER.readValue(result.getResponse().getContentAsString(), FlowPayload.class);
    assertEquals(TestMessageMock.flow, response);
}
Also used : FlowPayload(org.openkilda.messaging.payload.flow.FlowPayload) MvcResult(org.springframework.test.web.servlet.MvcResult) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test)

Aggregations

MvcResult (org.springframework.test.web.servlet.MvcResult)628 Test (org.junit.Test)365 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)178 Test (org.junit.jupiter.api.Test)163 ResultMatcher (org.springframework.test.web.servlet.ResultMatcher)69 MockHttpServletRequestBuilder (org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder)39 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)38 WebMvcTest (org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest)36 MockHttpSession (org.springframework.mock.web.MockHttpSession)35 ResultActions (org.springframework.test.web.servlet.ResultActions)27 DatabaseSetup (com.github.springtestdbunit.annotation.DatabaseSetup)26 ExpectedDatabase (com.github.springtestdbunit.annotation.ExpectedDatabase)26 Map (java.util.Map)24 RequestBuilder (org.springframework.test.web.servlet.RequestBuilder)24 WithMockUser (org.springframework.security.test.context.support.WithMockUser)23 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)22 AbstractSaturnConsoleTest (com.vip.saturn.job.console.AbstractSaturnConsoleTest)20 Cookie (javax.servlet.http.Cookie)18 MockMvc (org.springframework.test.web.servlet.MockMvc)17 HttpSession (jakarta.servlet.http.HttpSession)16