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

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

Introduction

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

Prototype

public void setParameter(String name, String... values) 

Source Link

Document

Set an array of values for the specified HTTP parameter.

Usage

From source file:org.openmrs.web.controller.form.FieldFormControllerTest.java

/**
 * @see FieldFormController#formBackingObject(HttpServletRequest)
 *///from   www. j  a v  a2  s  .  c  o  m
// @Transactional annotation needed because the parent class is @Transactional and so screws propagates to this readOnly test
@Transactional(readOnly = true)
@Test
@Verifies(value = "should get field", method = "formBackingObject(HttpServletRequest)")
public void formBackingObject_shouldGetField() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest("GET", "");
    request.setParameter("fieldId", "1");

    HttpServletResponse response = new MockHttpServletResponse();

    FieldFormController controller = (FieldFormController) applicationContext.getBean("fieldForm");

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

    // make sure there is a "userId" filled in on the concept
    Field command = (Field) modelAndView.getModel().get("field");
    Assert.assertNotNull(command.getFieldId());
}

From source file:org.craftercms.profile.interceptors.AccessTokenCheckingInterceptorTest.java

@Test(expected = ExpiredAccessTokenException.class)
public void testPreHandleExpiredAccessToken() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setParameter(ProfileConstants.PARAM_ACCESS_TOKEN_ID, EXPIRED_TOKEN_ID.toString());

    interceptor.preHandle(request, null, null);
}

From source file:org.jasig.cas.web.flow.InitialFlowSetupActionTests.java

public void testServiceFound() throws Exception {
    final MockRequestContext context = new MockRequestContext();
    final MockHttpServletRequest request = new MockHttpServletRequest();
    request.setParameter("service", "test");
    context.setExternalContext(//w  w w.ja v  a 2  s  .co m
            new ServletExternalContext(new MockServletContext(), request, new MockHttpServletResponse()));

    final Event event = this.action.execute(context);

    assertEquals("test", WebUtils.getService(context).getId());
    assertEquals("success", event.getId());
}

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

/**
 * @see ShowGraphServlet#getChart(HttpServletRequest)
 *///from  w ww.  j a va2s.  c  o  m
@Test
@Verifies(value = "should set value axis label to concept numeric units if given units is null", method = "getChart(HttpServletRequest)")
public void getChart_shouldSetValueAxisLabelToConceptNumericUnitsIfGivenUnitsIsNull() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setParameter("patientId", "7");
    request.setParameter("conceptId", "5497"); // cd4

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

    Assert.assertEquals("cells/mmL", chart.getXYPlot().getRangeAxis().getLabel());
}

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

/**
 * @see ShowGraphServlet#getChart(HttpServletRequest)
 *///from   w w w .j  a  va 2  s . c  om
@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.openmrs.web.controller.form.FieldFormControllerTest.java

/**
 * @see FieldFormController#onSubmit(HttpServletRequest,HttpServletResponse,Object,BindException)
 *//* w w  w  . j a va2 s .c o  m*/
@Test
@Verifies(value = "should not fail on field answers", method = "onSubmit(HttpServletRequest,HttpServletResponse,Object,BindException)")
public void onSubmit_shouldNotFailOnFieldAnswers() throws Exception {
    final String FIELD_ID = "1";

    MockHttpServletRequest request = new MockHttpServletRequest("GET", "");
    request.setParameter("fieldId", FIELD_ID);

    HttpServletResponse response = new MockHttpServletResponse();
    FieldFormController controller = (FieldFormController) applicationContext.getBean("fieldForm");
    controller.handleRequest(request, response);

    Context.closeSession();
    Context.openSession();
    authenticate();

    request = new MockHttpServletRequest("POST", "");
    response = new MockHttpServletResponse();
    request.setParameter("fieldId", FIELD_ID);
    request.setParameter("name", "Some concept");
    request.setParameter("description", "This is a test field");
    request.setParameter("fieldTypeId", "1");
    request.setParameter("name", "Some concept");
    request.setParameter("conceptId", "3");
    request.setParameter("action", "save");

    controller.handleRequest(request, response);
}

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)
 *//*from w ww. j  a  v a2s  .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.craftercms.profile.interceptors.AccessTokenCheckingInterceptorTest.java

@Test
public void testPreHandle() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setParameter(ProfileConstants.PARAM_ACCESS_TOKEN_ID, NORMAL_TOKEN_ID.toString());

    interceptor.preHandle(request, null, null);

    Application app = Application.getCurrent();

    TenantPermission permission = new TenantPermission();
    permission.allow("*");

    assertNotNull(app);//  w w  w . ja  v  a  2  s .c o m
    assertEquals(APPLICATION, app.getName());
    assertEquals(Arrays.asList(permission), app.getTenantPermissions());

    verify(tokenRepository).findById(NORMAL_TOKEN_ID.toString());

    Application.clear();
}

From source file:org.jasig.cas.client.authentication.FacesCompatibleAuthenticationRedirectStrategyTests.java

@Test
public void facesPartialResponse() throws Exception {
    final String redirectUrl = "http://www.jasig.org";
    final MockHttpServletRequest request = new MockHttpServletRequest();
    final MockHttpServletResponse response = new MockHttpServletResponse();
    request.setParameter("javax.faces.partial.ajax", "true");
    this.strategy.redirect(request, response, redirectUrl);
    assertNull(response.getRedirectedUrl());
    assertTrue(response.getContentAsString().contains(redirectUrl));
}

From source file:com.geodan.ngr.serviceintegration.TestCSWTransformer.java

private void test() {
    try {//from w ww .  j ava 2  s  . c o m
        MockHttpServletRequest request = new MockHttpServletRequest();
        MockHttpServletResponse response = new MockHttpServletResponse();
        request.setParameter("startPosition", "1");
        request.setParameter("maxRecords", "3");
        //request.setParameter("ElementSetName", "full");
        //request.setParameter("ElementSetName", "minimal");
        //request.setParameter("searchterms-1", "niEuWe");
        //request.setParameter("field-1", "AnyText");
        //request.setParameter("searchterms-2", "heeeeee");
        //request.setParameter("field-2", "title");
        //request.setParameter("searchterms-3", "OGC:WMS");
        //request.setParameter("searchterms-3", "OGC:WMS-1.1.1-http-get-capabilities");
        //request.setParameter("searchterms-3", "OGC:WMS-1.1.1-http-get-capabilities");
        //request.setParameter("field-3", "OnlineResourceType");
        //request.setParameter("url","http://nationaalgeoregister.nl:80/geonetwork/srv/en/csw");
        request.setParameter("url", "http://nationaalgeoregister.nl/geonetwork/srv/en/csw");
        //request.setParameter("callback", "callbackfunction");

        go(request, response);
    } catch (Throwable x) {
        System.out.println(x.getMessage());
        x.printStackTrace();
    }
}