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

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

Introduction

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

Prototype

public MockHttpServletRequest() 

Source Link

Document

Create a new MockHttpServletRequest with a default MockServletContext .

Usage

From source file:com.nerderg.ajaxanywhere.tests.unit.TestAAUtils.java

@Before
public void setup() {
    mockHttpServletRequest = new MockHttpServletRequest();
}

From source file:mjg.HelloServletJavaTest.java

@Test
public void testDoGet() {
    HelloServlet servlet = new HelloServlet();
    MockHttpServletRequest req = new MockHttpServletRequest();
    MockHttpServletResponse resp = new MockHttpServletResponse();
    try {/* w  ww . j  ava  2  s .  c  o  m*/
        servlet.doGet(req, resp);
        assertEquals("Hello, Servlet!", resp.getContentAsString().trim());
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (ServletException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:org.energyos.espi.datacustodian.web.filter.CORSFilterTests.java

@Test
public void testDoFilterInternal() throws Exception {
    CORSFilter corsFilter = new CORSFilter();
    FilterChain filterChain = mock(FilterChain.class);
    MockHttpServletRequest request = new MockHttpServletRequest();
    MockHttpServletResponse response = new MockHttpServletResponse();

    corsFilter.doFilter(request, response, filterChain);

    verify(filterChain).doFilter(request, response);
}

From source file:org.jmesa.limit.state.SessionStateTest.java

@Test
public void retrieveLimitFromParameter() {

    MockHttpServletRequest request = new MockHttpServletRequest();
    WebContext webContext = new HttpServletRequestWebContext(request);

    webContext.setSessionAttribute(ID + "_LIMIT", new Limit(ID));

    SessionState state = new SessionState();
    state.setId(ID);/*w  w w. j  a v a 2  s  .c om*/
    state.setStateAttr("restore");
    state.setWebContext(webContext);

    Limit limit = state.retrieveLimit();

    assertNull("The limit is not null.", limit); // should be null until pass parameter

    request.addParameter("restore", "true");

    limit = state.retrieveLimit();

    assertNotNull("The limit is null.", limit); // should now not be null
}

From source file:org.jmesa.worksheet.state.WorksheetStateTest.java

@Test
public void retrieveWorksheet() {

    MockHttpServletRequest request = new MockHttpServletRequest();
    WebContext webContext = new HttpServletRequestWebContext(request);

    webContext.setSessionAttribute(ID, new Limit(ID));

    WorksheetState state = new SessionWorksheetState(ID, webContext);

    Worksheet worksheet = new Worksheet(ID);
    worksheet.setWebContext(webContext);

    assertNull("The worksheet is not null.", state.retrieveWorksheet());

    state.persistWorksheet(worksheet);//w w  w  .j a v  a2 s  .co m

    assertNotNull("The worksheet is null.", state.retrieveWorksheet());
}

From source file:com.nebhale.cyclinglibrary.web.json.LinkTest.java

@Before
public void setRequestContext() {
    RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(new MockHttpServletRequest()));
}

From source file:org.jasig.cas.event.advice.PageRequestHandlerInterceptorAdapterTests.java

public void testPublishEvent() throws Exception {
    this.adapter.afterCompletion(new MockHttpServletRequest(), new MockHttpServletResponse(), null, null);
    assertNotNull(this.event);
}

From source file:org.sventon.web.HttpBasicAuthenticationHandlerTest.java

@Test
public void testParseCredentials() throws Exception {
    final MockHttpServletRequest request = new MockHttpServletRequest();
    final HttpBasicAuthenticationHandler handler = new HttpBasicAuthenticationHandler();

    Credentials credentials;//from w  w w . j  a v  a  2 s . c om

    try {
        handler.parseCredentials(request);
        fail("Should cause IllegalArgumentException");
    } catch (IllegalArgumentException iae) {
        // Expected
    }

    final String credentialString = "uid:pwd";

    request.addHeader(AbstractHttpAuthenticationHandler.AUTHORIZATION_HEADER,
            "Basic " + new String(Base64.encodeBase64(credentialString.getBytes())));
    credentials = handler.parseCredentials(request);
    assertFalse(credentials.isEmpty());
    assertEquals("uid", credentials.getUserName());
    assertEquals("pwd", credentials.getPassword());
}

From source file:net.lshift.diffa.adapter.scanning.AggregationBuilderTest.java

@Test
public void shouldNotAddDateAggregationForEmptyRequest() {
    MockHttpServletRequest req = new MockHttpServletRequest();
    AggregationBuilder builder = new AggregationBuilder(req);

    builder.maybeAddDateAggregation("test");
    assertEquals(0, builder.toList().size());
}

From source file:org.araneaframework.tests.StandardServletOutputDataTests.java

public void setUp() {
    req = new MockHttpServletRequest();
    resp = new MockHttpServletResponse();

    out = new StandardServletOutputData(req, resp);
}