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.zilverline.web.TestZilverController.java

public void testFlushCacheHandler() {
    try {//w  w w  .  ja  v  a2  s  .  c  o  m
        ZilverController zilverC = (ZilverController) applicationContext.getBean("zilverController");
        assertNotNull(zilverC);
        CollectionManager colMan = (CollectionManager) applicationContext.getBean("collectionMan");
        // get testdate collection
        DocumentCollection testdata = colMan.getCollectionByName("testdata");
        assertNotNull(testdata);
        MockHttpServletRequest request = new MockHttpServletRequest();
        request.addParameter("collection", "testdata");
        HttpServletResponse response = new MockHttpServletResponse();
        ModelAndView mv = zilverC.flushCacheHandler(request, response);
        assertNotNull(mv);
    } catch (BeansException e) {
        fail(e.getMessage());
    } catch (ServletException e) {
        fail(e.getMessage());
    }
}

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

@Test
public void testRedirectToSavedRequest() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest();
    MockHttpServletResponse response = new MockHttpServletResponse();
    RequestContext context = new RequestContext(request, response);
    SavedRequest savedRequest = mock(SavedRequest.class);

    when(savedRequest.getRedirectUrl()).thenReturn(SAVED_REQUEST_URL);
    when(requestCache.getRequest(request, response)).thenReturn(savedRequest);

    handler.handle(context, mock(Authentication.class));

    assertEquals(SAVED_REQUEST_URL, response.getRedirectedUrl());
    assertEquals(HttpServletResponse.SC_MOVED_TEMPORARILY, response.getStatus());
    assertTrue(response.isCommitted());/*from  www. j  a  v  a  2s  .  c o m*/
}

From source file:ar.com.zauber.commons.web.proxy.impl.ValidateURLRequestMapperTest.java

/** @throws Exception on error */
public final void testNullReturn() throws Exception {
    final URLRequestMapper v = new ValidateURLRequestMapper(new URLRequestMapper() {
        public URLResult getProxiedURLFromRequest(final HttpServletRequest request) {
            return null;
        }/*ww w . j av a2 s . co m*/
    });
    try {
        v.getProxiedURLFromRequest(new MockHttpServletRequest());
        fail();
    } catch (final IllegalArgumentException e) {
        assertEquals("a retured URL from URLRequestMapper can't be null", e.getMessage());
    }
}

From source file:org.parancoe.web.test.ControllerTest.java

/**
 * Reset the request and the response, maintaining the same session.
 * Useful, for example, to call a post after calling the get of the form.
 *//*from ww  w  .  ja  v  a2s  .  co m*/
protected void resetRequestAndResponse() {
    HttpSession httpSession = null;
    // preparing the multipart request
    if (mpReq != null) {
        httpSession = mpReq.getSession();
    }
    mpReq = new MockMultipartHttpServletRequest();
    mpReq.setSession(httpSession);
    mpReq.setMethod("GET");
    // preparing the normal request
    if (req != null) {
        httpSession = req.getSession();
    }
    req = new MockHttpServletRequest();
    req.setSession(httpSession);
    req.setMethod("GET");
    res = new MockHttpServletResponse();
}

From source file:org.jasig.cas.client.session.SingleSignOutFilterTests.java

@Before
public void setUp() throws Exception {
    filter = new SingleSignOutFilter();
    filter.setCasServerUrlPrefix(CAS_SERVER_URL_PREFIX);
    filter.setIgnoreInitConfiguration(true);
    filter.init(new MockFilterConfig());
    request = new MockHttpServletRequest();
    response = new MockHttpServletResponse();
    filterChain = new MockFilterChain();
}

From source file:org.openmrs.module.webservices.rest.web.v1_0.controller.OrderControllerTest.java

@Before
public void before() throws Exception {
    executeDataSet("customTestDataset.xml");
    this.service = Context.getOrderService();
    this.controller = new OrderController();
    this.request = new MockHttpServletRequest();
    this.response = new MockHttpServletResponse();
}

From source file:org.openmrs.web.controller.provider.ProviderFormControllerTest.java

/**
 * @verifies not void or change attributeList if the attribute values are same
 * @see org.openmrs.web.controller.provider.ProviderFormController#onSubmit(javax.servlet.http.HttpServletRequest,
 *      String, String, String, String, org.openmrs.Provider,
 *      org.springframework.validation.BindingResult, org.springframework.ui.ModelMap)
 *//*  w  w  w  .j  av a  2s .  c o  m*/
@Test
public void onSubmit_shouldNotVoidOrChangeAttributeListIfTheAttributeValuesAreSame() throws Exception {
    executeDataSet(PROVIDERS_ATTRIBUTES_XML);
    Provider provider = Context.getProviderService().getProvider(1);
    ProviderAttributeType providerAttributeType = Context.getProviderService().getProviderAttributeType(1);
    providerAttributeType.setName("provider joined date");
    MockHttpServletRequest mockHttpServletRequest = new MockHttpServletRequest();
    mockHttpServletRequest.setParameter("attribute." + providerAttributeType.getId(), "2011-04-25");
    BindException errors = new BindException(provider, "provider");
    ProviderFormController providerFormController = (ProviderFormController) applicationContext
            .getBean("providerFormController");
    providerFormController.onSubmit(mockHttpServletRequest, "save", null, null, null, provider, errors,
            createModelMap(providerAttributeType));
    Assert.assertFalse(((ProviderAttribute) (provider.getAttributes().toArray()[0])).getVoided());
    Assert.assertEquals(1, provider.getAttributes().size());

}

From source file:org.openmrs.module.feedback.web.FeedbackFormControllerTest.java

@Before
public void setUp() throws Exception {

    this.service = Context.getService(FeedbackService.class);
    this.controller = new FeedbackAdminListController();
    this.request = new MockHttpServletRequest();
    this.response = new MockHttpServletResponse();

    initializeInMemoryDatabase();/* w ww.jav  a  2  s  . co  m*/
    executeDataSet("initialInMemoryTestDataSet.xml");
    executeDataSet("FeedbackDataset.xml");
    executeDataSet("FeedbackAccessDataset.xml");
    authenticate();
}

From source file:org.araneaframework.tests.framework.filter.StandardSerializingAuditFilterServiceTests.java

public void setUp() throws Exception {
    service = new StandardSerializingAuditFilterService();
    child = new MockEventfulBaseService();
    service.setChildService(child);//from   www. jav a 2s  .  co  m

    httpSession = new MockHttpSession();

    Map map = new HashMap();
    map.put(HttpSession.class, httpSession);

    MockLifeCycle.begin(service, new StandardEnvironment(null, map));

    req = new MockHttpServletRequest();
    res = new MockHttpServletResponse();

    input = new StandardServletInputData(req);
    output = new StandardServletOutputData(req, res);
}

From source file:org.openmrs.module.webservices.rest.web.v1_0.controller.CohortControllerTest.java

@Before
public void before() throws Exception {
    this.service = Context.getCohortService();
    this.controller = new CohortController();
    this.request = new MockHttpServletRequest();
    this.response = new MockHttpServletResponse();
    executeDataSet(datasetFilename);/*from w w w .  j  a v a2s  . c  o  m*/
}