Example usage for org.springframework.mock.web MockHttpServletResponse MockHttpServletResponse

List of usage examples for org.springframework.mock.web MockHttpServletResponse MockHttpServletResponse

Introduction

In this page you can find the example usage for org.springframework.mock.web MockHttpServletResponse MockHttpServletResponse.

Prototype

MockHttpServletResponse

Source Link

Usage

From source file:org.jasig.cas.web.support.CookieRetrievingCookieGeneratorTests.java

public void testCookieAddWithoutRememberMe() {
    final MockHttpServletRequest request = new MockHttpServletRequest();
    final MockHttpServletResponse response = new MockHttpServletResponse();

    this.g.addCookie(request, response, "test");

    final Cookie c = response.getCookie("test");
    assertEquals(5, c.getMaxAge());//  w w w . ja v  a2s.c  o  m
    assertEquals("test", c.getValue());
}

From source file:org.jasig.cas.support.oauth.web.OAuth20CallbackAuthorizeControllerTests.java

@Test
public void testOK() throws Exception {
    final MockHttpServletRequest mockRequest = new MockHttpServletRequest("GET",
            CONTEXT + OAuthConstants.CALLBACK_AUTHORIZE_URL);
    mockRequest.addParameter(OAuthConstants.TICKET, SERVICE_TICKET);
    final MockHttpSession mockSession = new MockHttpSession();
    mockSession.putValue(OAuthConstants.OAUTH20_CALLBACKURL, REDIRECT_URI);
    mockSession.putValue(OAuthConstants.OAUTH20_SERVICE_NAME, SERVICE_NAME);
    mockRequest.setSession(mockSession);
    final MockHttpServletResponse mockResponse = new MockHttpServletResponse();
    final OAuth20WrapperController oauth20WrapperController = new OAuth20WrapperController();
    oauth20WrapperController.afterPropertiesSet();
    final ModelAndView modelAndView = oauth20WrapperController.handleRequest(mockRequest, mockResponse);
    assertEquals(OAuthConstants.CONFIRM_VIEW, modelAndView.getViewName());
    final Map<String, Object> map = modelAndView.getModel();
    assertEquals(SERVICE_NAME, map.get("serviceName"));
    assertEquals(REDIRECT_URI + "?" + OAuthConstants.CODE + "=" + SERVICE_TICKET, map.get("callbackUrl"));
}

From source file:com.surevine.alfresco.audit.integration.RevertWikiPageTest.java

/**
 * Test sunny day scenario.  In fact, this is the only scenario as everything else is a CREATE
 *//*from   ww  w .  java 2s.  co m*/
@Test
public void testSuccessfulReversion() {

    try {

        JSONObject json = new JSONObject();

        json.put(AlfrescoJSONKeys.PAGE, "wiki-page");
        json.put(AlfrescoJSONKeys.WIKI_PAGE_CONTENT, "<p>in europa league action.</p>");
        eslFixture.addToJSON(json);

        mockRequest.setRequestURI("/alfresco/s/slingshot/wiki/page/mytestsite/" + TEST_WIKIPAGE_NAME);
        mockRequest.setContent(json.toString().getBytes());
        mockResponse = new MockHttpServletResponse();
        mockChain = new MockFilterChain();

        springAuditFilterBean.doFilter(mockRequest, mockResponse, mockChain);

        Auditable audited = getSingleAuditedEvent();

        verifyGenericAuditMetadata(audited);
        assertEquals(audited.getAction(), "WIKI_PAGE_REVERTED");
        assertEquals(eslFixture.toString(), audited.getSecLabel());

    } catch (Exception e) {
        e.printStackTrace();
        fail();
    }
}

From source file:org.jasig.cas.client.session.SingleSignOutFilterTests.java

@Before
public void setUp() throws Exception {
    filter = new SingleSignOutFilter();
    filter.setCasServerUrlPrefix(CAS_SERVER_URL_PREFIX);
    filter.setIgnoreInitConfiguration(true);
    filter.init(new MockFilterConfig());
    request = new MockHttpServletRequest();
    response = new MockHttpServletResponse();
    filterChain = new MockFilterChain();
}

From source file:org.araneaframework.tests.framework.filter.StandardSerializingAuditFilterServiceTests.java

public void setUp() throws Exception {
    service = new StandardSerializingAuditFilterService();
    child = new MockEventfulBaseService();
    service.setChildService(child);/*from  w ww .ja  va  2 s  . co  m*/

    httpSession = new MockHttpSession();

    Map map = new HashMap();
    map.put(HttpSession.class, httpSession);

    MockLifeCycle.begin(service, new StandardEnvironment(null, map));

    req = new MockHttpServletRequest();
    res = new MockHttpServletResponse();

    input = new StandardServletInputData(req);
    output = new StandardServletOutputData(req, res);
}

From source file:org.openmrs.module.webservices.rest.web.v1_0.controller.OrderControllerTest.java

@Before
public void before() throws Exception {
    executeDataSet("customTestDataset.xml");
    this.service = Context.getOrderService();
    this.controller = new OrderController();
    this.request = new MockHttpServletRequest();
    this.response = new MockHttpServletResponse();
}

From source file:org.craftercms.security.authentication.impl.LoginSuccessHandleImplTest.java

@Test
public void testRedirectToSavedRequest() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest();
    MockHttpServletResponse response = new MockHttpServletResponse();
    RequestContext context = new RequestContext(request, response);
    SavedRequest savedRequest = mock(SavedRequest.class);

    when(savedRequest.getRedirectUrl()).thenReturn(SAVED_REQUEST_URL);
    when(requestCache.getRequest(request, response)).thenReturn(savedRequest);

    handler.handle(context, mock(Authentication.class));

    assertEquals(SAVED_REQUEST_URL, response.getRedirectedUrl());
    assertEquals(HttpServletResponse.SC_MOVED_TEMPORARILY, response.getStatus());
    assertTrue(response.isCommitted());/*www .  j a  v a 2s.c  o  m*/
}

From source file:org.openmrs.module.feedback.web.FeedbackFormControllerTest.java

@Before
public void setUp() throws Exception {

    this.service = Context.getService(FeedbackService.class);
    this.controller = new FeedbackAdminListController();
    this.request = new MockHttpServletRequest();
    this.response = new MockHttpServletResponse();

    initializeInMemoryDatabase();/*from  w w  w .j  a v a 2  s  . c  o  m*/
    executeDataSet("initialInMemoryTestDataSet.xml");
    executeDataSet("FeedbackDataset.xml");
    executeDataSet("FeedbackAccessDataset.xml");
    authenticate();
}

From source file:org.openmrs.ui.framework.IntegrationTest.java

@Test
public void integrationTest() throws Exception {
    MockHttpSession httpSession = new MockHttpSession();
    Session session = sessionFactory.getSession(httpSession);
    MockHttpServletResponse response = new MockHttpServletResponse();
    PageRequest req = new PageRequest("uiframework", "home", new MockHttpServletRequest(), response, session);

    String html = pageFactory.handle(req);
    System.out.println("Result = " + html);

    // should not be cached
    assertThat((String) response.getHeader("Cache-Control"), is("no-cache,no-store,must-revalidate"));
}

From source file:org.openmrs.module.webservices.rest.web.v1_0.controller.CohortControllerTest.java

@Before
public void before() throws Exception {
    this.service = Context.getCohortService();
    this.controller = new CohortController();
    this.request = new MockHttpServletRequest();
    this.response = new MockHttpServletResponse();
    executeDataSet(datasetFilename);/*ww  w.  j a  v a  2 s .c o m*/
}