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:org.eclipse.virgo.snaps.core.internal.SnapUtilsTests.java

@Test
public void determineSnapContextPathFromDeepPathInfo() {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setServletPath("/hotels/booking/index");
    String contextPath = SnapUtils.determineSnapContextPath(request);
    assertEquals("/hotels", contextPath);
}

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

/**
 * Tests that {@link TextControl} return <code>null</code> on empty request.
 * @throws Exception/*  ww w  . j a v a  2  s.c o m*/
 */
public void testDataCycling() throws Exception {
    MockHttpServletRequest emptyRequest = new MockHttpServletRequest();
    emptyRequest.addParameter("myTextBox", "");

    FormElement sfe = new FormElement();

    sfe._getComponent().init(new MockEnviroment());

    TextControl tb = new TextControl();
    tb.setMandatory(true);

    sfe.setControl(tb);
    sfe.setData(new LongData());
    sfe.setConverter(new StringToLongConverter());

    sfe._getWidget().update(new StandardServletInputData(emptyRequest));
    sfe.convertAndValidate();

    sfe.getData().setValue(new Long(110));

    sfe._getWidget().process();

    assertEquals("The textbox must have the data item value!",
            ((StringArrayRequestControl.ViewModel) sfe.getControl()._getViewable().getViewModel())
                    .getSimpleValue(),
            "110");

    sfe._getComponent().destroy();
}

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

@Test
public void shouldAddDateAggregationWhenParameterIsAvailable() {
    MockHttpServletRequest req = new MockHttpServletRequest();
    req.addParameter("bizDate-granularity", "monthly");
    AggregationBuilder builder = new AggregationBuilder(req);

    builder.maybeAddDateAggregation("bizDate");
    assertEquals(1, builder.toList().size());
    assertThat(builder.toList().get(0), is(instanceOf(DateAggregation.class)));
}

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

protected MockHttpServletResponse loginUnsuccessfully(final String username, final String fromAddress)
        throws Exception {
    final MockHttpServletRequest request = new MockHttpServletRequest();
    final MockHttpServletResponse response = new MockHttpServletResponse();
    request.setMethod("POST");
    request.setParameter("username", username);
    request.setRemoteAddr(fromAddress);/*  ww w .  j  a  v  a 2  s . co m*/
    MockRequestContext context = new MockRequestContext();
    context.setCurrentEvent(new Event("", "error"));
    request.setAttribute("flowRequestContext", context);
    getThrottle().preHandle(request, response, null);
    getThrottle().postHandle(request, response, null, null);
    return response;
}

From source file:com.carlos.projects.billing.ui.controllers.ShowComponentsControllerTest.java

@Test
public void shouldForwardToNewDocumentPage() throws Exception {
    //given//ww w  . j  av  a2s  .c o m
    ShowComponentsController controller = new ShowComponentsController();
    controller.setViewName("showComponents");
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setMethod("GET");
    MockHttpServletResponse response = new MockHttpServletResponse();

    //when
    ModelAndView modelAndView = controller.handleRequest(request, response);

    //then
    assertThat(modelAndView.getViewName(), is("showComponents"));
}

From source file:org.jrecruiter.web.actions.BaseActionTest.java

@Override
protected void setUp() throws Exception {
    ActionContext ac = new ActionContext(new HashMap<String, Object>());
    ActionContext.setContext(ac);//from  w w w  .ja  va 2s.co  m
    ActionContext.getContext().setSession(new HashMap<String, Object>());

    // populate the request so getRequest().getSession() doesn't fail in BaseAction.java
    ServletActionContext.setRequest(new MockHttpServletRequest());

    super.setUp();
}

From source file:org.jmesa.limit.LimitFactoryTest.java

@Test
public void createLimitAndRowSelect() {

    MockHttpServletRequest request = new MockHttpServletRequest();
    WebContext webContext = new HttpServletRequestWebContext(request);
    webContext.setParameterMap(getParameters());
    LimitFactory limitFactory = new LimitFactory(ID, webContext);
    checkAssertions(limitFactory);/*from  ww  w.  ja  v a2 s . c  om*/
}

From source file:com.gu.management.logging.Log4JManagerServletTest.java

@Before
public void setUp() throws Exception {
    initMocks(this);

    request = new MockHttpServletRequest();
    response = new MockHttpServletResponse();

    servlet = new Log4JManagerServlet();
}

From source file:org.n52.iceland.request.RequestContextTest.java

@Test
public void ip4CompactIpv6Address() {
    MockHttpServletRequest mockRequest = new MockHttpServletRequest();
    mockRequest.setRemoteAddr("::101.45.75.219");
    RequestContext fromRequest = RequestContext.fromRequest(mockRequest);
    Assert.assertEquals("101.45.75.219", fromRequest.getIPAddress().get().toString());

    mockRequest.setRemoteAddr("0:0:0:0:0:0:101.45.75.219");
    fromRequest = RequestContext.fromRequest(mockRequest);

    Assert.assertEquals("101.45.75.219", fromRequest.getIPAddress().get().toString());
}

From source file:com.carlos.projects.billing.ui.controllers.NewDocumentControllerTest.java

@Test
public void shouldForwardToNewDocumentPage() throws Exception {
    //given/*w ww.j a  v a2  s  .  c  om*/
    NewDocumentController controller = new NewDocumentController();
    controller.setViewName("newDocument");
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setMethod("GET");
    MockHttpServletResponse response = new MockHttpServletResponse();

    //when
    ModelAndView modelAndView = controller.handleRequest(request, response);

    //then
    assertThat(modelAndView.getViewName(), is("newDocument"));
}