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.soybeanMilk.test.unit.web.TestAbstractTargetHandler.java

private WebObjectSource createWebObjectSource() {
    MockHttpServletRequest request = new MockHttpServletRequest();
    MockHttpServletResponse response = new MockHttpServletResponse();
    MockServletContext application = new MockServletContext();

    WebObjectSource os = new DefaultWebObjectSource(request, response, application, new WebGenericConverter());

    return os;// w  w w .  j a  v a 2 s  . c o m
}

From source file:org.jasig.cas.web.flow.SendTicketGrantingTicketActionTests.java

@Test
public void testTgtToSetRemovingOldTgt() throws Exception {
    final MockHttpServletResponse response = new MockHttpServletResponse();
    final MockHttpServletRequest request = new MockHttpServletRequest();
    final String TICKET_VALUE = "test";
    request.setCookies(new Cookie[] { new Cookie("TGT", "test5") });
    WebUtils.putTicketGrantingTicketInRequestScope(this.context, TICKET_VALUE);
    this.context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));

    assertEquals("success", this.action.execute(this.context).getId());
    assertEquals(TICKET_VALUE, response.getCookies()[0].getValue());
}

From source file:com.cognitivabrasil.repositorio.web.FileControllerIT.java

@Test
public void testGetFile() throws IOException {
    createFile();/*from  www  .jav a  2 s  . c  o m*/
    MockHttpServletResponse response = new MockHttpServletResponse();
    Files f = fService.get(1);
    f.setLocation(FILETEST);
    fController.getFile(1, response);
    assertThat(response.getStatus(), equalTo(200));
    assertThat(response.getHeader("Content-Disposition"), equalTo("attachment; filename=" + f.getName()));

    FileUtils.forceDelete(new java.io.File(FILETEST));

}

From source file:org.jasig.cas.web.flow.GenerateServiceTicketActionTests.java

@Test
public void testTicketGrantingTicketFromRequest() throws Exception {
    MockRequestContext context = new MockRequestContext();
    context.getFlowScope().put("service", TestUtils.getService());
    MockHttpServletRequest request = new MockHttpServletRequest();
    context.setExternalContext(//from  w  ww.  ja  va2  s. c om
            new ServletExternalContext(new MockServletContext(), request, new MockHttpServletResponse()));
    request.addParameter("service", "service");
    WebUtils.putTicketGrantingTicketInRequestScope(context, this.ticketGrantingTicket);

    this.action.execute(context);

    assertNotNull(WebUtils.getServiceTicketFromRequestScope(context));
}

From source file:org.jasig.cas.web.view.Saml10SuccessResponseViewTests.java

public void testResponse() throws Exception {
    final Map<String, Object> model = new HashMap<String, Object>();

    final Map<String, Object> attributes = new HashMap<String, Object>();
    attributes.put("testAttribute", "testValue");
    attributes.put("testEmptyCollection", Collections.emptyList());
    attributes.put("testAttributeCollection", Arrays.asList(new String[] { "tac1", "tac2" }));
    final SimplePrincipal principal = new SimplePrincipal("testPrincipal", attributes);

    final MutableAuthentication authentication = new MutableAuthentication(principal);
    authentication.getAttributes().put(SamlAuthenticationMetaDataPopulator.ATTRIBUTE_AUTHENTICATION_METHOD,
            SamlAuthenticationMetaDataPopulator.AUTHN_METHOD_SSL_TLS_CLIENT);
    authentication.getAttributes().put("testSamlAttribute", "value");

    final List<Authentication> authentications = new ArrayList<Authentication>();
    authentications.add(authentication);

    final Assertion assertion = new ImmutableAssertionImpl(authentications, TestUtils.getService(), true);

    model.put("assertion", assertion);

    final MockHttpServletResponse servletResponse = new MockHttpServletResponse();

    this.response.renderMergedOutputModel(model, new MockHttpServletRequest(), servletResponse);
    final String written = servletResponse.getContentAsString();

    assertTrue(written.contains("testPrincipal"));
    assertTrue(written.contains("testAttribute"));
    assertTrue(written.contains("testValue"));
    assertFalse(written.contains("testEmptyCollection"));
    assertTrue(written.contains("testAttributeCollection"));
    assertTrue(written.contains("tac1"));
    assertTrue(written.contains("tac2"));
    assertTrue(written.contains(SamlAuthenticationMetaDataPopulator.AUTHN_METHOD_SSL_TLS_CLIENT));
    assertTrue(written.contains("AuthenticationMethod"));
    assertTrue(written.contains("AssertionID"));
}

From source file:org.zilverline.web.TestZilverController.java

public void testFailFlushCacheHandler() {
    try {/*from  w  ww  .ja  v a 2  s.  co m*/
        ZilverController zilverC = (ZilverController) applicationContext.getBean("zilverController");
        assertNotNull(zilverC);
        CollectionManager colMan = (CollectionManager) applicationContext.getBean("collectionMan");
        // get testdate collection
        DocumentCollection testdata = colMan.getCollectionByName("testdata3");
        assertNull(testdata);
        MockHttpServletRequest request = new MockHttpServletRequest();
        request.addParameter("collection", "testdata3");
        HttpServletResponse response = new MockHttpServletResponse();
        ModelAndView mv = zilverC.flushCacheHandler(request, response);
        assertNotNull(mv);
        fail("Should throw ServletException");
    } catch (BeansException e) {
        fail(e.getMessage());
    } catch (ServletException e) {
        assertNotNull(e.getMessage());
    }
}

From source file:org.terasoluna.gfw.web.message.MessagesPanelTagTest.java

/**
 * create mock PageContext.//w ww  .  ja v  a 2s.  c o  m
 */
protected MockPageContext createPageContext() {
    MockServletContext sc = new MockServletContext();
    wac = mock(WebApplicationContext.class);
    when(wac.getMessage(eq("hello.world"), eq(new Object[] {}), (Locale) anyObject()))
            .thenReturn("hello world!");
    when(wac.getMessage(eq("foo.bar"), eq(new Object[] { 1, 2 }), (Locale) anyObject()))
            .thenReturn("foo1 and bar2");

    when(wac.getServletContext()).thenReturn(sc);
    request = new MockHttpServletRequest(sc);
    MockHttpServletResponse response = new MockHttpServletResponse();
    sc.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
    return new MockPageContext(sc, request, response);
}