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:ejportal.webapp.filter.StaticFilterTest.java

/**
 * Test filter forwards when path doesnt match.
 * //  w w  w .ja v a  2  s  .c  o m
 * @throws Exception
 *             the exception
 */
public void testFilterForwardsWhenPathDoesntMatch() throws Exception {
    final MockHttpServletRequest request = new MockHttpServletRequest("GET", "/editProfile.html");
    final MockHttpServletResponse response = new MockHttpServletResponse();
    final MockFilterChain chain = new MockFilterChain();

    this.filter.doFilter(request, response, chain);

    Assert.assertNotNull(chain.getForwardURL());
}

From source file:test.com.tsc9526.monalisa.service.actions.AbstractActionTest.java

protected Response getRespone(MockHttpServletRequest req) throws Exception {
    MockHttpServletResponse resp = new MockHttpServletResponse();
    req.addHeader("DEV_TEST", "true");

    DbQueryHttpServlet ms = new DbQueryHttpServlet();
    ms.service(req, resp);/*from   ww w . j  a  v a 2s . co  m*/

    String type = resp.getContentType();
    Assert.assertTrue(type.indexOf("json") > 0 && type.indexOf("utf-8") > 0);

    String body = resp.getContentAsString();

    Response r = Response.fromJson(body);

    if (req.getParameter("page") != null && r.getStatus() == 200) {
        int total = Integer.parseInt(resp.getHeader("X-Total-Page"));
        Assert.assertTrue(total >= 0);
    }

    return r;
}

From source file:edu.internet2.middleware.shibboleth.idp.system.conf1.ShibbolethSSOTestCase.java

/** Tests initial leg of the SSO request where request is decoded and sent to the authentication engine. */
public void testFirstAuthenticationLeg() throws Exception {
    MockServletContext servletContext = new MockServletContext();

    MockHttpServletRequest servletRequest = buildServletRequest();
    MockHttpServletResponse servletResponse = new MockHttpServletResponse();

    ProfileHandlerManager handlerManager = (ProfileHandlerManager) getApplicationContext()
            .getBean("shibboleth.HandlerManager");
    AbstractShibbolethProfileHandler handler = (AbstractShibbolethProfileHandler) handlerManager
            .getProfileHandler(servletRequest);
    assertNotNull(handler);//w  w w .  ja v a  2  s  .  c  o  m

    // Process request
    HTTPInTransport profileRequest = new HttpServletRequestAdapter(servletRequest);
    HTTPOutTransport profileResponse = new HttpServletResponseAdapter(servletResponse, false);
    handler.processRequest(profileRequest, profileResponse);

    servletRequest.setCookies(servletResponse.getCookies());
    ShibbolethSSOLoginContext loginContext = (ShibbolethSSOLoginContext) HttpServletHelper
            .getLoginContext(handler.getStorageService(), servletContext, servletRequest);

    assertNotNull(loginContext);
    assertEquals(false, loginContext.getAuthenticationAttempted());
    assertEquals(false, loginContext.isForceAuthRequired());
    assertEquals(false, loginContext.isPassiveAuthRequired());
    assertEquals("/AuthnEngine", loginContext.getAuthenticationEngineURL());
    assertEquals("/shibboleth/SSO", loginContext.getProfileHandlerURL());
    assertEquals("urn:example.org:sp1", loginContext.getRelyingPartyId());
    assertEquals(0, loginContext.getRequestedAuthenticationMethods().size());
    assertEquals("https://example.org/mySP", loginContext.getSpAssertionConsumerService());
    assertEquals("https://example.org/mySP", loginContext.getSpAssertionConsumerService());

    assertTrue(servletResponse.getRedirectedUrl().endsWith("/AuthnEngine"));
}

From source file:org.terasoluna.gfw.web.token.transaction.TransactionTokenInterceptorTest.java

@Before
public void setUp() throws Exception {

    // prepare request object
    request = new MockHttpServletRequest();
    request.setRequestURI("/token/first");
    request.setMethod("GET");

    // prepare response object
    response = new MockHttpServletResponse();

    // set ServletRequestAttributes to RequestContextHolder
    ServletRequestAttributes attributes = new ServletRequestAttributes(request);
    RequestContextHolder.setRequestAttributes(attributes);

    // prepare intercepter instance
    interceptor = new TransactionTokenInterceptor();
}

From source file:alpha.portal.webapp.controller.UserFormControllerTest.java

/**
 * Test add.//from   www . j av a 2 s  .  co m
 * 
 * @throws Exception
 *             the exception
 */
@Test
public void testAdd() throws Exception {
    this.log.debug("testing add new user...");
    this.request = this.newGet("/userform.html");
    this.request.addParameter("method", "Add");
    this.request.addUserRole(Constants.ADMIN_ROLE);

    final Map<String, Object> model = this.c.showForm(this.request, new MockHttpServletResponse()).getModel();
    final Object object = model.get("user");
    Assert.assertTrue(object instanceof User);
    this.user = (User) object;
    Assert.assertNull(this.user.getUsername());
}

From source file:org.ngrinder.script.controller.SvnDavControllerTest.java

@Test
public void testHandleError() throws IOException {
    DAVException davE = new DAVException("Test Error", 404, 0);
    HttpServletResponse resp = new MockHttpServletResponse();
    SvnDavController.handleError(davE, resp);
}

From source file:org.araneaframework.tests.integration.SmokeTests.java

public void setUp() throws Exception {
    servlet = new MockServlet();

    req = new MockHttpServletRequest();
    resp = new MockHttpServletResponse();
}

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

@Test
public void testSendError() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest();
    MockHttpServletResponse response = new MockHttpServletResponse();
    RequestContext context = new RequestContext(request, response);

    handler.handle(context, new AuthenticationRequiredException(""));

    verify(requestCache).saveRequest(request, response);

    assertEquals(HttpServletResponse.SC_UNAUTHORIZED, response.getStatus());
    assertTrue(response.isCommitted());//  w w w.  jav  a 2  s.  com
}

From source file:com.goSmarter.activiti.loanrequest.web.LoanRequestControllerTest.java

@Before
public void setUp() {
    requestMock = new MockHttpServletRequest();
    requestMock.setContentType(MediaType.APPLICATION_JSON_VALUE);
    requestMock.setAttribute(HandlerMapping.INTROSPECT_TYPE_LEVEL_MAPPING, Boolean.FALSE);

    responseMock = new MockHttpServletResponse();

    handlerAdapter = new AnnotationMethodHandlerAdapter();
    HttpMessageConverter[] messageConverters = { new MappingJacksonHttpMessageConverter() };
    handlerAdapter.setMessageConverters(messageConverters);

    mapper = new ObjectMapper();
    loanRequest = new LoanRequest();
}

From source file:com.google.api.server.spi.handlers.EndpointsMethodHandlerTest.java

@Before
public void setUp() throws Exception {
    classLoader = EndpointsMethodHandlerTest.class.getClassLoader();
    request = new MockHttpServletRequest();
    response = new MockHttpServletResponse();
    context = new EndpointsContext("", "", request, response);
    systemService = SystemService.builder().withDefaults(classLoader)
            .addService(TestEndpoint.class, new TestEndpoint()).build();
    typeLoader = new TypeLoader(classLoader);
    apiConfig = new ApiConfig.Factory().create(ServiceContext.create(), typeLoader, TestEndpoint.class);
}