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.jasig.cas.authentication.principal.SimpleWebApplicationServiceImplTests.java

public void testResponseWithNoTicket() {
    final MockHttpServletRequest request = new MockHttpServletRequest();
    request.setParameter("service", "service");
    final WebApplicationService impl = SimpleWebApplicationServiceImpl.createServiceFrom(request);

    final Response response = impl.getResponse(null);
    assertNotNull(response);/*from  w  w w. j  ava2s .  c  om*/
    assertEquals(ResponseType.REDIRECT, response.getResponseType());
    assertFalse(response.getUrl().contains("ticket="));
}

From source file:org.jasig.cas.authentication.principal.SimpleWebApplicationServiceImplTests.java

public void testResponseWithNoTicketAndOneParameterInServiceURL() {
    final MockHttpServletRequest request = new MockHttpServletRequest();
    request.setParameter("service", "http://foo.com/?param=test");
    final WebApplicationService impl = SimpleWebApplicationServiceImpl.createServiceFrom(request);

    final Response response = impl.getResponse(null);
    assertNotNull(response);//  w  w w .j  ava  2s.c o m
    assertEquals(ResponseType.REDIRECT, response.getResponseType());
    assertEquals("http://foo.com/?param=test", response.getUrl());
}

From source file:org.jasig.cas.services.web.ServiceThemeResolverTests.java

public void testGetDefaultService() {
    final MockHttpServletRequest request = new MockHttpServletRequest();
    request.setParameter("service", "myServiceId");
    request.addHeader("User-Agent", "Mozilla");
    assertEquals("test", this.serviceThemeResolver.resolveThemeName(request));
}

From source file:org.jasig.cas.authentication.principal.SimpleWebApplicationServiceImplTests.java

public void testResponseWithNoTicketAndNoParameterInServiceURL() {
    final MockHttpServletRequest request = new MockHttpServletRequest();
    request.setParameter("service", "http://foo.com/");
    final WebApplicationService impl = SimpleWebApplicationServiceImpl.createServiceFrom(request);

    final Response response = impl.getResponse(null);
    assertNotNull(response);/*from   w  w w.jav a  2  s. c  om*/
    assertEquals(ResponseType.REDIRECT, response.getResponseType());
    assertFalse(response.getUrl().contains("ticket="));
    assertEquals("http://foo.com/", response.getUrl());
}

From source file:org.jasig.cas.services.web.ServiceThemeResolverTests.java

public void testGetDefaultServiceWithNoServicesManager() {
    this.serviceThemeResolver.setServicesManager(null);
    final MockHttpServletRequest request = new MockHttpServletRequest();
    request.setParameter("service", "myServiceId");
    request.addHeader("User-Agent", "Mozilla");
    assertEquals("test", this.serviceThemeResolver.resolveThemeName(request));
}

From source file:org.openmrs.web.controller.program.ProgramFormControllerTest.java

/**
 * @see ProgramFormController#onSubmit(HttpServletRequest,HttpServletResponse,Object,BindException)
 *///from ww w .  ja va  2  s  . c  o  m
@Test
@Transactional(readOnly = true)
@Verifies(value = "should save workflows with program", method = "onSubmit(HttpServletRequest,HttpServletResponse,Object,BindException)")
public void onSubmit_shouldSaveWorkflowsWithProgram() throws Exception {

    // sanity check to make sure that program #3 doesn't have any workflows already:
    Assert.assertEquals(0, Context.getProgramWorkflowService().getProgram(3).getAllWorkflows().size());

    MockHttpServletRequest request = new MockHttpServletRequest("POST", "");
    request.setParameter("programId", "3");
    request.setParameter("allWorkflows", ":3"); // set one workflow on this program

    ProgramFormController controller = (ProgramFormController) applicationContext.getBean("programForm");
    controller.handleRequest(request, new MockHttpServletResponse());

    Assert.assertNotSame(0, Context.getProgramWorkflowService().getProgram(3).getAllWorkflows().size());
    Assert.assertEquals(1, Context.getProgramWorkflowService().getProgram(3).getAllWorkflows().size());
}

From source file:org.jasig.cas.services.web.ServiceThemeResolverTests.java

public void testGetServiceTheme() {
    final RegisteredServiceImpl r = new RegisteredServiceImpl();
    r.setTheme("myTheme");
    r.setId(1000);//from w  w w.jav  a 2 s.  c o  m
    r.setServiceId("myServiceId");

    this.servicesManager.save(r);

    final MockHttpServletRequest request = new MockHttpServletRequest();
    request.setParameter("service", "myServiceId");
    request.addHeader("User-Agent", "Mozilla");
    System.out.println("1");
    assertEquals("myTheme", this.serviceThemeResolver.resolveThemeName(request));
}

From source file:org.openmrs.web.controller.patient.PatientFormControllerTest.java

/**
 * @see PatientFormController#onSubmit(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, Object, org.springframework.validation.BindException)
 *///from  w  w w . jav a 2 s.co  m
@Test
@Verifies(value = "void patient when void reason is not empty", method = "onSubmit(HttpServletRequest, HttpServletResponse, Object, BindException)")
public void onSubmit_shouldVoidPatientWhenVoidReasonIsNotEmpty() throws Exception {

    Patient p = Context.getPatientService().getPatient(2);

    HttpServletResponse response = new MockHttpServletResponse();

    PatientFormController controller = (PatientFormController) applicationContext.getBean("patientForm");
    controller.setApplicationContext(applicationContext);

    MockHttpServletRequest request = new MockHttpServletRequest("POST", "");
    request.setParameter("action", "Patient.void");
    request.setParameter("voidReason", "some reason");
    BindException errors = new BindException(p, "patient");
    ModelAndView modelAndview = controller.onSubmit(request, response, p, errors);

    Assert.assertTrue(p.isVoided());
}

From source file:org.openmrs.web.controller.program.ProgramFormControllerTest.java

/**
 * @see ProgramFormController#onSubmit(HttpServletRequest,HttpServletResponse,Object,BindException)
 * @verifies edit existing workflows within programs
 */// www.j  a  va2 s .  c om
@Test
@Transactional(readOnly = true)
public void onSubmit_shouldEditExistingWorkflowsWithinPrograms() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest("POST", "");
    request.setParameter("programId", "3");
    request.setParameter("allWorkflows", ":3 4"); // set two workflows on this program

    ProgramFormController controller = (ProgramFormController) applicationContext.getBean("programForm");
    controller.handleRequest(request, new MockHttpServletResponse());

    Assert.assertEquals(2, Context.getProgramWorkflowService().getProgram(3).getWorkflows().size());

    request = new MockHttpServletRequest("POST", "");
    request.setParameter("programId", "3");
    request.setParameter("allWorkflows", ":5"); // set one workflow on this program

    controller.handleRequest(request, new MockHttpServletResponse());

    Assert.assertEquals(1, Context.getProgramWorkflowService().getProgram(3).getWorkflows().size());
    Assert.assertEquals(5, Context.getProgramWorkflowService().getProgram(3).getWorkflows().iterator().next()
            .getConcept().getConceptId().intValue());
}

From source file:org.openmrs.web.controller.patient.PatientFormControllerTest.java

/**
 * @see PatientFormController#onSubmit(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, Object, org.springframework.validation.BindException)
 *//*from www  .  j av  a2  s  . co  m*/
@Test
@Verifies(value = "not void patient when void reason is empty", method = "onSubmit(HttpServletRequest, HttpServletResponse, Object, BindException)")
public void onSubmit_shouldNotVoidPatientWhenVoidReasonIsEmpty() throws Exception {
    Patient p = Context.getPatientService().getPatient(2);

    HttpServletResponse response = new MockHttpServletResponse();

    PatientFormController controller = (PatientFormController) applicationContext.getBean("patientForm");
    controller.setApplicationContext(applicationContext);

    MockHttpServletRequest request = new MockHttpServletRequest("POST", "");
    request.setParameter("action", "Patient.void");
    request.setParameter("voidReason", "");
    BindException errors = new BindException(p, "patient");
    ModelAndView modelAndview = controller.onSubmit(request, response, p, errors);

    Assert.assertTrue(!p.isVoided());
    String tmp = request.getSession().getAttribute(WebConstants.OPENMRS_ERROR_ATTR).toString();
    Assert.assertEquals(tmp, "Patient.error.void.reasonEmpty");
}