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);
}
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);
}
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));
}
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));
}
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);
}
Aggregations