Search in sources :

Example 91 with MockHttpServletResponse

use of org.springframework.mock.web.MockHttpServletResponse in project cas by apereo.

the class InitialFlowSetupActionSsoTests method disableFlowIfNoService.

@Test
public void disableFlowIfNoService() throws Exception {
    final MockRequestContext context = new MockRequestContext();
    final MockHttpServletRequest request = new MockHttpServletRequest();
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, new MockHttpServletResponse()));
    this.thrown.expect(NoSuchFlowExecutionException.class);
    this.action.execute(context);
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) MockRequestContext(org.springframework.webflow.test.MockRequestContext) MockServletContext(org.springframework.mock.web.MockServletContext) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 92 with MockHttpServletResponse

use of org.springframework.mock.web.MockHttpServletResponse in project cas by apereo.

the class SendTicketGrantingTicketActionSsoTests method verifySsoSessionCookieOnRenewAsParameter.

@Test
public void verifySsoSessionCookieOnRenewAsParameter() throws Exception {
    final MockHttpServletResponse response = new MockHttpServletResponse();
    final MockHttpServletRequest request = new MockHttpServletRequest();
    request.addParameter(CasProtocolConstants.PARAMETER_RENEW, "true");
    request.setRemoteAddr(LOCALHOST_IP);
    request.setLocalAddr(LOCALHOST_IP);
    request.addHeader(HttpRequestUtils.USER_AGENT_HEADER, "test");
    ClientInfoHolder.setClientInfo(new ClientInfo(request));
    final TicketGrantingTicket tgt = mock(TicketGrantingTicket.class);
    when(tgt.getId()).thenReturn(TEST_STRING);
    request.setCookies(new Cookie("TGT", "test5"));
    WebUtils.putTicketGrantingTicketInScopes(this.context, tgt);
    this.context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
    assertEquals(SUCCESS, action.execute(this.context).getId());
    assertEquals(0, response.getCookies().length);
}
Also used : Cookie(javax.servlet.http.Cookie) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) ServletExternalContext(org.springframework.webflow.context.servlet.ServletExternalContext) ClientInfo(org.apereo.inspektr.common.web.ClientInfo) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) MockServletContext(org.springframework.mock.web.MockServletContext) Test(org.junit.Test)

Example 93 with MockHttpServletResponse

use of org.springframework.mock.web.MockHttpServletResponse in project leopard by tanhaichao.

the class OnlyJsonViewTest method getBody.

@Test
public void getBody() {
    HttpServletRequest request = new MockHttpServletRequest();
    HttpServletResponse response = new MockHttpServletResponse();
    OnlyJsonView onlyJsonView = new OnlyJsonView("message");
    Assert.assertEquals("\"message\"", onlyJsonView.getBody(request, response));
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) OnlyJsonView(io.leopard.web.view.OnlyJsonView) HttpServletResponse(javax.servlet.http.HttpServletResponse) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 94 with MockHttpServletResponse

use of org.springframework.mock.web.MockHttpServletResponse in project leopard by tanhaichao.

the class TextViewTest method getBody.

@Test
public void getBody() {
    HttpServletRequest request = new MockHttpServletRequest();
    HttpServletResponse response = new MockHttpServletResponse();
    TextView textView = new TextView("message");
    Assert.assertEquals("message", textView.getBody(request, response));
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) TextView(io.leopard.web.view.TextView) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 95 with MockHttpServletResponse

use of org.springframework.mock.web.MockHttpServletResponse in project TOSCAna by StuPro-TOSCAna.

the class TransformationControllerTest method getInputsTest.

@Test
public void getInputsTest() throws Exception {
    preInitNonCreationTests();
    MvcResult result = mvc.perform(get(INPUTS_VALID_URL)).andDo(print()).andExpect(status().is(200)).andExpect(content().contentType(DEFAULT_CHARSET_HAL_JSON)).andExpect(jsonPath("$.inputs").isArray()).andExpect(jsonPath("$.inputs").isNotEmpty()).andExpect(jsonPath("$.inputs[0].key").isString()).andExpect(jsonPath("$.inputs[0].type").isString()).andExpect(jsonPath("$.inputs[0].description").isString()).andExpect(jsonPath("$.inputs[0].required").isBoolean()).andExpect(jsonPath("$.links[0].rel").value("self")).andExpect(jsonPath("$.links[0].href").value("http://localhost/api/csars/kubernetes-cluster/transformations/p-a/inputs")).andReturn();
    MockHttpServletResponse response = result.getResponse();
    String responseJson = new String(response.getContentAsByteArray());
    String[] values = JsonPath.parse(responseJson).read("$.inputs[*].value", String[].class);
    long nullCount = Arrays.asList(values).stream().filter(Objects::isNull).count();
    long testCount = Arrays.asList(values).stream().filter(e -> e != null && e.equals(INPUT_TEST_DEFAULT_VALUE)).count();
    assertEquals(8, nullCount);
    assertEquals(1, testCount);
}
Also used : TargetArtifact(org.opentosca.toscana.core.transformation.artifacts.TargetArtifact) Arrays(java.util.Arrays) MockMvcResultMatchers.jsonPath(org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath) Random(java.util.Random) TransformationService(org.opentosca.toscana.core.transformation.TransformationService) JSONObject(org.json.JSONObject) PlatformNotFoundException(org.opentosca.toscana.api.exceptions.PlatformNotFoundException) Map(java.util.Map) OutputProperty(org.opentosca.toscana.core.transformation.properties.OutputProperty) MockMvcRequestBuilders.put(org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put) MockMvcResultHandlers.print(org.springframework.test.web.servlet.result.MockMvcResultHandlers.print) PropertyType(org.opentosca.toscana.core.transformation.properties.PropertyType) MediaType(org.springframework.http.MediaType) PlatformInput(org.opentosca.toscana.core.transformation.properties.PlatformInput) Set(java.util.Set) Csar(org.opentosca.toscana.core.csar.Csar) Objects(java.util.Objects) List(java.util.List) Log(org.opentosca.toscana.core.transformation.logging.Log) LogEntry(org.opentosca.toscana.core.transformation.logging.LogEntry) PlatformService(org.opentosca.toscana.core.transformation.platform.PlatformService) Optional(java.util.Optional) TransformationState(org.opentosca.toscana.core.transformation.TransformationState) TestCsars(org.opentosca.toscana.core.testdata.TestCsars) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Transformation(org.opentosca.toscana.core.transformation.Transformation) HashMap(java.util.HashMap) Mockito.spy(org.mockito.Mockito.spy) MockMvcResultMatchers.content(org.springframework.test.web.servlet.result.MockMvcResultMatchers.content) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) ArrayList(java.util.ArrayList) TransformationImpl(org.opentosca.toscana.core.transformation.TransformationImpl) HashSet(java.util.HashSet) MockMvc(org.springframework.test.web.servlet.MockMvc) MockMvcRequestBuilders.delete(org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete) Lists(com.google.common.collect.Lists) MockMvcResultMatchers.status(org.springframework.test.web.servlet.result.MockMvcResultMatchers.status) MockMvcRequestBuilders.post(org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post) Platform(org.opentosca.toscana.core.transformation.platform.Platform) MvcResult(org.springframework.test.web.servlet.MvcResult) MockMvcBuilders(org.springframework.test.web.servlet.setup.MockMvcBuilders) CsarImpl(org.opentosca.toscana.core.csar.CsarImpl) Before(org.junit.Before) ByteArrayUtils(org.opentosca.toscana.core.testdata.ByteArrayUtils) Assert.assertTrue(org.junit.Assert.assertTrue) FileUtils(org.apache.commons.io.FileUtils) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) JsonPath(com.jayway.jsonpath.JsonPath) File(java.io.File) CsarService(org.opentosca.toscana.core.csar.CsarService) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) BaseSpringTest(org.opentosca.toscana.core.BaseSpringTest) Level(ch.qos.logback.classic.Level) HALRelationUtils(org.opentosca.toscana.api.utils.HALRelationUtils) MockMvcRequestBuilders.get(org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get) Collections(java.util.Collections) JSONArray(org.json.JSONArray) Assert.assertEquals(org.junit.Assert.assertEquals) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) MvcResult(org.springframework.test.web.servlet.MvcResult) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test) BaseSpringTest(org.opentosca.toscana.core.BaseSpringTest)

Aggregations

MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)2338 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)1986 Test (org.junit.jupiter.api.Test)1412 lombok.val (lombok.val)946 Test (org.junit.Test)558 ServletExternalContext (org.springframework.webflow.context.servlet.ServletExternalContext)484 MockServletContext (org.springframework.mock.web.MockServletContext)462 MockRequestContext (org.springframework.webflow.test.MockRequestContext)460 MockFilterChain (org.springframework.mock.web.MockFilterChain)239 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)184 JEEContext (org.pac4j.core.context.JEEContext)159 FilterChain (jakarta.servlet.FilterChain)117 Authentication (org.springframework.security.core.Authentication)116 BeforeEach (org.junit.jupiter.api.BeforeEach)106 MockTicketGrantingTicket (org.apereo.cas.mock.MockTicketGrantingTicket)97 HashMap (java.util.HashMap)84 HttpServletRequest (jakarta.servlet.http.HttpServletRequest)83 HttpServletResponse (jakarta.servlet.http.HttpServletResponse)67 MockHttpSession (org.springframework.mock.web.MockHttpSession)65 TestingAuthenticationToken (org.springframework.security.authentication.TestingAuthenticationToken)64