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:net.eusashead.hateoas.conditional.interceptor.RequestBuilder.java

public RequestBuilder(String path, String query, String verb) {

    // Create the request
    this.request = new MockHttpServletRequest();

    // Set verb, path and query
    request.setRequestURI(path);//from  w w w. j  a va 2  s  . c  o m
    request.setQueryString(query);
    request.setMethod(verb);

}

From source file:org.openmrs.web.servlet.ShowGraphServletTest.java

/**
 * @see ShowGraphServlet#getChart(HttpServletRequest)
 *///from  ww  w .ja v a 2  s.c  o  m
@Test
@Verifies(value = "should set value axis label to given units", method = "getChart(HttpServletRequest)")
public void getChart_shouldSetValueAxisLabelToGivenUnits() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setParameter("patientId", "7");
    request.setParameter("conceptId", "5497"); // cd4
    request.setParameter("units", "CUSTOM UNITS");

    JFreeChart chart = new ShowGraphServlet().getChart(request);

    Assert.assertEquals("CUSTOM UNITS", chart.getXYPlot().getRangeAxis().getLabel());
}

From source file:org.fishwife.jrugged.spring.TestStatusController.java

@Before
public void setUp() {
    monitoredService = new MonitoredServiceStub();
    impl = new StatusController(monitoredService);
    req = new MockHttpServletRequest();
    resp = new MockHttpServletResponse();
}

From source file:com.amashchenko.struts2.pdfstream.PdfStreamResultTest.java

@Test
public void testFindBaseUrl() throws Exception {
    Assert.assertNotNull(pdfStreamResult);

    MockHttpServletRequest request = new MockHttpServletRequest();

    request.setLocalName("localhost");
    request.setRequestURI("/contextPath/requestURI");
    request.setQueryString("queryString");
    request.setContextPath("/contextPath");

    final String baseUrl = pdfStreamResult.findBaseUrl(request);

    Assert.assertEquals("http://localhost/contextPath/", baseUrl);
}

From source file:net.handle.servlet.RequestAdapterTest.java

@Before
public void setup() throws Exception {
    settings = new Settings(new XMLConfiguration(RequestAdapterTest.class.getResource("/OpenHandleTest.xml")));
    handle = "10101/nature";
    request = new MockHttpServletRequest();
}

From source file:org.sventon.web.ctrl.template.ListFilesControllerTest.java

@Test
public void testSvnHandle() throws Exception {
    final RepositoryService mockService = EasyMock.createMock(RepositoryService.class);
    final MockHttpServletRequest request = new MockHttpServletRequest();
    request.setParameter("rowNumber", "12");

    final List<DirEntry> entries = TestUtils.getFileEntriesDirectoryList();

    final BaseCommand command = new BaseCommand();
    command.setName(new RepositoryName("test"));
    command.setRevision(Revision.create(12));

    final ListFilesController ctrl = new ListFilesController();
    ctrl.setRepositoryService(mockService);

    expect(mockService.list(null, command.getPath(), command.getRevisionNumber()))
            .andStubReturn(new DirList(entries, new Properties()));
    replay(mockService);/*from  w  w w .j  a  v  a2  s.c  o m*/

    final ModelAndView modelAndView = ctrl.svnHandle(null, command, 100, null, request, null, null);
    final Map model = modelAndView.getModel();
    verify(mockService);

    assertEquals(3, model.size());
    assertEquals(12, model.get("rowNumber"));
    assertEquals(entries.get(0), ((List<DirEntry>) model.get("dirEntries")).get(0));
}

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

public void testResponse() throws Exception {
    final MockHttpServletRequest request = new MockHttpServletRequest();
    final MockHttpServletResponse response = new MockHttpServletResponse();
    request.addParameter("TARGET", "service");

    final String description = "Validation failed";
    this.view.renderMergedOutputModel(Collections.<String, Object>singletonMap("description", description),
            request, response);/*from w  w w. java 2  s.  c  om*/

    final String responseText = response.getContentAsString();
    assertTrue(responseText.contains("Status"));
    assertTrue(responseText.contains(description));
}

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

@Test
public void testIsLoginAttempt() throws Exception {
    final MockHttpServletRequest request = new MockHttpServletRequest();
    assertFalse(handler.isLoginAttempt(request));

    request.addHeader(AbstractHttpAuthenticationHandler.AUTHORIZATION_HEADER, "Basic xyz:abc");
    assertTrue(handler.isLoginAttempt(request));
}

From source file:com.github.jrialland.ajpclient.servlet.TestWrongHost.java

/**
 * tries to make a request to an unknown host, verifies that the request
 * fails (the library does not hangs) and that we have a 502 error
 * /*  w  ww.j  av a  2  s .  c  o m*/
 * @throws Exception
 */
@Test
public void testWrongTargetHost() throws Exception {
    final MockHttpServletRequest request = new MockHttpServletRequest();
    request.setMethod("GET");
    request.setRequestURI("/dizzy.mp4");
    final MockHttpServletResponse response = new MockHttpServletResponse();

    final Future<Integer> statusFuture = Executors.newSingleThreadExecutor().submit(new Callable<Integer>() {
        @Override
        public Integer call() throws Exception {
            AjpServletProxy.forHost("unknownhost.inexistentdomain.com", 8415).forward(request, response);
            return response.getStatus();
        }
    });

    final long start = System.currentTimeMillis();

    // should finish in less that seconds
    final int status = statusFuture.get(10, TimeUnit.SECONDS);

    Assert.assertTrue(System.currentTimeMillis() - start < 8000);

    Assert.assertEquals(HttpServletResponse.SC_BAD_GATEWAY, status);
}

From source file:ar.com.zauber.commons.web.proxy.impl.dao.behaviour.impl.InmutableURLRequestMapperAssertionTest.java

/** test */
public final void testAssertion() {
    new InmutableURLRequestMapperAssertion(0L, new InmutableURLResult(), new MockHttpServletRequest())
            .assertRequest(new InmutableURLRequestMapper(new InmutableURLResult()));

}