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.web.support.WebUtilTests.java

public void testFindService() {
    final SamlArgumentExtractor openIdArgumentExtractor = new SamlArgumentExtractor();
    final CasArgumentExtractor casArgumentExtractor = new CasArgumentExtractor();
    final ArgumentExtractor[] argumentExtractors = new ArgumentExtractor[] { openIdArgumentExtractor,
            casArgumentExtractor };/*from   w  w w. j a  v  a  2s.  c om*/
    final MockHttpServletRequest request = new MockHttpServletRequest();
    request.setParameter("service", "test");

    final Service service = WebUtils.getService(Arrays.asList(argumentExtractors), request);

    assertEquals("test", service.getId());
}

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);//  ww w .  j  a  v a 2s  .  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.sventon.web.ctrl.template.ListDirectoryContentsControllerTest.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 ListDirectoryContentsController ctrl = new ListDirectoryContentsController();
    ctrl.setRepositoryService(mockService);

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

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

    assertEquals(2, model.size());
    assertEquals(entries.get(0), ((List<DirEntry>) model.get("dirEntries")).get(0));
    assertNull(modelAndView.getViewName());
}

From source file:cherry.foundation.onetimetoken.OneTimeTokenValidatorImplTest.java

@Test
public void testIsValid_NoSession() {
    String tokenValue = UUID.randomUUID().toString();
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setParameter("__OneTimeToken__", tokenValue);
    assertFalse(oneTimeTokenValidator.isValid(request));
}

From source file:cherry.foundation.onetimetoken.OneTimeTokenValidatorImplTest.java

@Test
public void testIsValid_NoSessionAttr() {
    String tokenValue = UUID.randomUUID().toString();
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setParameter("__OneTimeToken__", tokenValue);
    request.getSession();//w w  w. j  a  v a2 s .co m
    assertFalse(oneTimeTokenValidator.isValid(request));
}

From source file:cherry.foundation.onetimetoken.OneTimeTokenValidatorImplTest.java

@Test
public void testIsValid_TokenValueUnmatch() {
    String tokenValue = UUID.randomUUID().toString();
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setParameter("__OneTimeToken__", tokenValue);
    request.getSession().setAttribute("__OneTimeToken__", UUID.randomUUID().toString());
    assertFalse(oneTimeTokenValidator.isValid(request));
}

From source file:cherry.foundation.onetimetoken.OneTimeTokenValidatorImplTest.java

@Test
public void testIsValid_TokenValueMatch() {
    String tokenValue = UUID.randomUUID().toString();
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setParameter("__OneTimeToken__", tokenValue);
    request.getSession().setAttribute("__OneTimeToken__", tokenValue);
    assertTrue(oneTimeTokenValidator.isValid(request));
}

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

public void testResponseForJsession() {
    final MockHttpServletRequest request = new MockHttpServletRequest();
    request.setParameter("service", "http://www.cnn.com/;jsession=test");
    final WebApplicationService impl = SimpleWebApplicationServiceImpl.createServiceFrom(request);

    assertEquals("http://www.cnn.com/", impl.getId());
}

From source file:org.openmrs.web.controller.encounter.EncounterFormControllerTest.java

/**
 * @see EncounterFormController#onSubmit(javax.servlet.http.HttpServletRequest,
 *      javax.servlet.http.HttpServletResponse, java.lang.Object,
 *      org.springframework.validation.BindException)
 *//* w w  w  . j a v a 2 s .c o  m*/
@Test
@Verifies(value = "transfer encounter to another patient when encounter patient was changed", method = "onSubmit(HttpServletRequest, HttpServletResponse, Object, BindException)")
public void onSubmit_shouldSaveANewEncounterRoleObject() throws Exception {
    executeDataSet(ENC_INITIAL_DATA_XML);
    executeDataSet(TRANSFER_ENC_DATA_XML);

    EncounterFormController controller = new EncounterFormController();

    MockHttpServletResponse response = new MockHttpServletResponse();
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setParameter("patientId", "201");

    Encounter encounter = Context.getEncounterService().getEncounter(200);

    Patient oldPatient = encounter.getPatient();
    Patient newPatient = Context.getPatientService().getPatient(201);
    Assert.assertNotEquals(oldPatient, newPatient);

    List<Encounter> newEncounter = Context.getEncounterService()
            .getEncountersByPatientId(newPatient.getPatientId());
    Assert.assertEquals(0, newEncounter.size());

    BindException errors = new BindException(encounter, "encounterRole");

    controller.onSubmit(request, response, encounter, errors);

    Assert.assertEquals(true, encounter.isVoided());
    newEncounter = Context.getEncounterService().getEncountersByPatientId(newPatient.getPatientId());
    Assert.assertEquals(1, newEncounter.size());
    Assert.assertEquals(false, newEncounter.get(0).isVoided());
}

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

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

    final Response response = impl.getResponse("ticketId");
    assertNotNull(response);//from  w  w  w . ja  v a2 s .com
    assertEquals(ResponseType.REDIRECT, response.getResponseType());
}