use of org.springframework.mock.web.MockHttpServletResponse in project cas by apereo.
the class SendTicketGrantingTicketActionTests method verifyTgtToSet.
@Test
public void verifyTgtToSet() throws Exception {
final MockHttpServletRequest request = new MockHttpServletRequest();
request.setRemoteAddr(LOCALHOST_IP);
request.setLocalAddr(LOCALHOST_IP);
ClientInfoHolder.setClientInfo(new ClientInfo(request));
final MockHttpServletResponse response = new MockHttpServletResponse();
request.addHeader("User-Agent", "Test");
final TicketGrantingTicket tgt = mock(TicketGrantingTicket.class);
when(tgt.getId()).thenReturn(TEST_STRING);
WebUtils.putTicketGrantingTicketInScopes(this.context, tgt);
this.context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
assertEquals(SUCCESS, this.action.execute(this.context).getId());
request.setCookies(response.getCookies());
assertEquals(tgt.getId(), this.ticketGrantingTicketCookieGenerator.retrieveCookieValue(request));
}
use of org.springframework.mock.web.MockHttpServletResponse in project cas by apereo.
the class SendTicketGrantingTicketActionTests method verifySsoSessionCookieOnServiceSsoDisallowed.
@Test
public void verifySsoSessionCookieOnServiceSsoDisallowed() throws Exception {
final MockHttpServletResponse response = new MockHttpServletResponse();
final MockHttpServletRequest request = new MockHttpServletRequest();
final WebApplicationService svc = mock(WebApplicationService.class);
when(svc.getId()).thenReturn("TestSsoFalse");
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));
this.context.getFlowScope().put("service", svc);
final SendTicketGrantingTicketAction action = new SendTicketGrantingTicketAction(centralAuthenticationService, servicesManager, ticketGrantingTicketCookieGenerator, false);
assertEquals(SUCCESS, action.execute(this.context).getId());
assertEquals(0, response.getCookies().length);
}
use of org.springframework.mock.web.MockHttpServletResponse in project head by mifos.
the class RedirectionControllerTest method testHandleRequest.
@Test
public void testHandleRequest() throws ServletException, IOException {
String expectedPageToRedirectTo = "foopage";
RedirectionController controller = new RedirectionController();
controller.setViewToRedirectTo(expectedPageToRedirectTo);
MockHttpServletRequest mockRequest = new MockHttpServletRequest();
MockHttpServletResponse mockResponse = new MockHttpServletResponse();
ModelAndView modelAndView = controller.handleRequest(mockRequest, mockResponse);
Assert.assertEquals(expectedPageToRedirectTo, modelAndView.getViewName());
Assert.assertNotNull(modelAndView.getModel());
Map<String, Object> modelMap = (Map<String, Object>) modelAndView.getModel().get("model");
Object response = modelMap.get("response");
Assert.assertNotNull(response);
Assert.assertEquals(MockHttpServletResponse.class, response.getClass());
}
use of org.springframework.mock.web.MockHttpServletResponse in project pinpoint by naver.
the class SpringWebMvcIT method testRequest.
@Test
public void testRequest() throws Exception {
MockServletConfig config = new MockServletConfig();
MockHttpServletRequest req = new MockHttpServletRequest();
MockHttpServletResponse res = new MockHttpServletResponse();
config.addInitParameter("contextConfigLocation", "classpath:spring-web-test.xml");
req.setMethod("GET");
req.setRequestURI("/");
req.setRemoteAddr("1.2.3.4");
DispatcherServlet servlet = new DispatcherServlet();
servlet.init(config);
servlet.service(req, res);
Method method = FrameworkServlet.class.getDeclaredMethod("doGet", HttpServletRequest.class, HttpServletResponse.class);
PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance();
verifier.printCache();
verifier.verifyTrace(Expectations.event(SPRING_MVC, method));
verifier.verifyTraceCount(0);
}
use of org.springframework.mock.web.MockHttpServletResponse in project opennms by OpenNMS.
the class RequisitionRestServiceIT method testDuplicateNodes.
@Test
public void testDuplicateNodes() throws Exception {
MockLogAppender.setupLogging(true, "DEBUG");
String req = "<model-import xmlns=\"http://xmlns.opennms.org/xsd/config/model-import\" date-stamp=\"2006-03-09T00:03:09\" foreign-source=\"test\">" + "<node node-label=\"a\" foreign-id=\"a\" />" + "<node node-label=\"b\" foreign-id=\"c\" />" + "<node node-label=\"c\" foreign-id=\"c\" />" + "</model-import>";
final MockHttpServletResponse response = sendPost("/requisitions", req, 400, null);
assertTrue("response should say 'c' has duplicates", response.getContentAsString().contains("Duplicate nodes found on foreign source test: c (2 found)"));
}
Aggregations