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

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

Introduction

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

Prototype

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

Source Link

Document

Add an array of values for the specified HTTP parameter.

Usage

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

@Test
public void shouldRetireAConcept() throws Exception {
    String uuid = "0a9afe04-088b-44ca-9291-0a8c3b5c96fa";
    Concept concept = service.getConceptByUuid(uuid);
    Assert.assertFalse(concept.isRetired());

    MockHttpServletRequest req = request(RequestMethod.DELETE, getURI() + "/" + uuid);
    req.addParameter("!purge", "");
    req.addParameter("reason", "really ridiculous random reason");
    handle(req);/*from   w  w w .  j  a va  2 s. c om*/

    concept = service.getConceptByUuid(uuid);
    Assert.assertTrue(concept.isRetired());
    Assert.assertEquals("really ridiculous random reason", concept.getRetireReason());
}

From source file:nl.surfnet.coin.teams.control.DetailTeamControllerTest.java

@Test
public void testAddRoleHappyFlow() throws Exception {
    MockHttpServletRequest request = getRequest();
    String token = TokenUtil.generateSessionToken();
    request.addParameter("teamId", "team-1");
    request.addParameter("memberId", "member-1");
    request.addParameter("roleId", Role.Manager.toString());
    request.addParameter("doAction", "add");

    GrouperTeamService grouperTeamService = mock(GrouperTeamService.class);
    Member member = getMember();/*w w  w  .  j  a v  a  2 s .c  o  m*/
    when(grouperTeamService.findMember("team-1", "member-1")).thenReturn(member);
    when(grouperTeamService.addMemberRole("team-1", "member-1", Role.Manager, "member-1")).thenReturn(true);
    autoWireMock(detailTeamController, new Returns(true), ControllerUtil.class);
    autoWireMock(detailTeamController, grouperTeamService, GrouperTeamService.class);
    autoWireRemainingResources(detailTeamController);

    RedirectView view = detailTeamController.addOrRemoveRole(getModelMap(), request, token, token,
            new SimpleSessionStatus());
    assertEquals("detailteam.shtml?team=team-1&view=app&mes=role.added&offset=0", view.getUrl());
}

From source file:org.hdiv.filter.ValidatorHelperTest.java

/**
 * Validation test for an init action./*from  w  w w .  j  a v  a 2s . co  m*/
 */
public void testValidateHashActionIsStartPage() {

    MockHttpServletRequest request = (MockHttpServletRequest) HDIVUtil.getHttpServletRequest();

    this.dataComposer.beginRequest(this.targetName);
    request.setRequestURI("/testing.do");

    String pageState = this.dataComposer.endRequest();
    this.dataComposer.endPage();

    request.addParameter(hdivParameter, pageState);

    RequestWrapper requestWrapper = new RequestWrapper(request);
    assertTrue(helper.validate(requestWrapper).isValid());
}

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

@Test
public void shouldReturnTheAuditInfoForTheFullRepresentation() throws Exception {
    MockHttpServletRequest req = request(RequestMethod.GET, getURI() + "/0dde1358-7fcf-4341-a330-f119241a46e8");
    req.addParameter(RestConstants.REQUEST_PROPERTY_FOR_REPRESENTATION, RestConstants.REPRESENTATION_FULL);
    SimpleObject result = deserialize(handle(req));
    Assert.assertNotNull(result);//  ww w.  j a  v a  2  s  .  c  o  m
    Assert.assertNotNull(PropertyUtils.getProperty(result, "auditInfo"));
}

From source file:org.hdiv.filter.ValidatorHelperTest.java

/**
 * Validation test with a wrong page identifier. It should not pass validation as there isn't any state in memory
 * which matches this identifier.// w  ww.  j  a  v a 2s  . c  o m
 */
public void testValidateHashMemoryWrongStateIndetifier() {

    MockHttpServletRequest request = (MockHttpServletRequest) HDIVUtil.getHttpServletRequest();

    this.dataComposer.beginRequest(this.targetName);
    this.dataComposer.compose("param1", "value1", false);

    // page identifier is incorrect
    String pageState = "1-1";

    request.addParameter(hdivParameter, pageState);

    String value = (this.confidentiality) ? "0" : "value1";
    request.addParameter("param1", value);

    this.dataComposer.endPage();

    boolean result = true;
    try {
        RequestWrapper requestWrapper = new RequestWrapper(request);
        result = helper.validate(requestWrapper).isValid();
        assertFalse(result);
    } catch (Exception e) {
        assertTrue(true);
    }
}

From source file:nl.surfnet.coin.teams.control.DetailTeamControllerTest.java

@Test
public void testRemoveRoleHappyFlow() throws Exception {
    MockHttpServletRequest request = getRequest();
    String token = TokenUtil.generateSessionToken();
    request.addParameter("teamId", "team-1");
    request.addParameter("memberId", "member-1");
    request.addParameter("roleId", "1");
    request.addParameter("doAction", "remove");

    HashSet<Role> roles = new HashSet<Role>();
    roles.add(Role.Member);
    roles.add(Role.Manager);/* ww  w .ja v a2 s  .  co m*/
    roles.add(Role.Admin);

    HashSet<Member> admins = new HashSet<Member>();
    admins.add(new Member(new HashSet<Role>(), "Jane Doe", "member-2", "jane@doe.com"));

    List<Member> members = new ArrayList<Member>();
    members.add(new Member(roles, "Jane Doe", "member-2", "jane@doe.com"));

    Team mockTeam = new Team("team-1", "Team 1", "team description", members);

    GrouperTeamService grouperTeamService = mock(GrouperTeamService.class);
    when(grouperTeamService.findTeamById("team-1")).thenReturn(mockTeam);
    when(grouperTeamService.findAdmins(mockTeam)).thenReturn(admins);
    when(grouperTeamService.removeMemberRole("team-1", "member-1", Role.Manager, "member-1")).thenReturn(true);

    autoWireMock(detailTeamController, new Returns(true), ControllerUtil.class);
    autoWireMock(detailTeamController, grouperTeamService, GrouperTeamService.class);
    autoWireRemainingResources(detailTeamController);

    RedirectView view = detailTeamController.addOrRemoveRole(getModelMap(), request, token, token,
            new SimpleSessionStatus());

    assertEquals("detailteam.shtml?team=team-1&view=app&mes=role.removed&offset=0", view.getUrl());
}

From source file:nl.surfnet.coin.teams.control.DetailTeamControllerTest.java

@Test
public void testDeleteMember() throws Exception {
    MockHttpServletRequest request = getRequest();
    String token = TokenUtil.generateSessionToken();
    // add the member
    request.addParameter("member", "member-1");

    Member member = getMember();//from   www  . jav  a  2s  .c  om

    autoWireMock(detailTeamController, new Returns(member), GrouperTeamService.class);
    autoWireRemainingResources(detailTeamController);

    RedirectView result = detailTeamController.deleteMember(getModelMap(), request, token, token, "team-1",
            new SimpleSessionStatus());

    assertEquals("detailteam.shtml?team=team-1&mes=error.NotAuthorizedToDeleteMember&view=app",
            result.getUrl());
}

From source file:org.hdiv.filter.ValidatorHelperTest.java

/**
 * Validation test for a non-editable parameter with a correct value.
 *///from w w w .  jav a  2  s.c  o  m
public void testValidateHashOneNotEditableOneParameter() {

    MockHttpServletRequest request = (MockHttpServletRequest) HDIVUtil.getHttpServletRequest();

    this.dataComposer.beginRequest(this.targetName);
    this.dataComposer.compose("param1", "value1", false);

    String pageState = this.dataComposer.endRequest();
    this.dataComposer.endPage();

    request.addParameter(hdivParameter, pageState);

    String value = (this.confidentiality) ? "0" : "value1";
    request.addParameter("param1", value);

    RequestWrapper requestWrapper = new RequestWrapper(request);
    assertTrue(helper.validate(requestWrapper).isValid());
}

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

@Test
public void shouldReturnCustomRepresentation() throws Exception {
    String conceptUuid = "95312123-e0c2-466d-b6b1-cb6e990d0d65";

    MockHttpServletRequest request = request(RequestMethod.GET, getURI() + "/" + conceptUuid);
    request.addParameter("v", "custom:(uuid,datatype:(uuid,name),conceptClass,names:ref)");
    MockHttpServletResponse response = handle(request);
    SimpleObject object = deserialize(response);

    Assert.assertEquals("95312123-e0c2-466d-b6b1-cb6e990d0d65", object.get("uuid"));
    Assert.assertEquals(4, object.size());

    @SuppressWarnings("unchecked")
    Map<Object, Object> datatype = (Map<Object, Object>) object.get("datatype");
    Assert.assertEquals(2, datatype.size());
    Assert.assertEquals("8d4a48b6-c2cc-11de-8d13-0010c6dffd0f", datatype.get("uuid"));
    Assert.assertEquals("Coded", datatype.get("name"));

    @SuppressWarnings("unchecked")
    Map<Object, Object> conceptClass = (Map<Object, Object>) object.get("conceptClass");
    Assert.assertEquals(7, conceptClass.size());
    Assert.assertEquals("a82ef63c-e4e4-48d6-988a-fdd74d7541a7", conceptClass.get("uuid"));
    Assert.assertEquals("Question", conceptClass.get("display"));
    Assert.assertEquals("Question", conceptClass.get("name"));
    Assert.assertEquals("Question (eg, patient history, SF36 items)", conceptClass.get("description"));
    Assert.assertEquals(false, conceptClass.get("retired"));
    Assert.assertNotNull(conceptClass.get("links"));
    Assert.assertNotNull(conceptClass.get("resourceVersion"));

    @SuppressWarnings("unchecked")
    List<Object> names = (List<Object>) object.get("names");
    Assert.assertEquals(1, names.size());

    @SuppressWarnings("unchecked")
    Map<Object, Object> name = (Map<Object, Object>) names.get(0);
    Assert.assertEquals(3, name.size());
    Assert.assertEquals("325391a8-db12-4e24-863f-5d66f7a4d713", name.get("uuid"));
    Assert.assertEquals("FOOD ASSISTANCE FOR ENTIRE FAMILY", name.get("display"));
    Assert.assertNotNull(name.get("links"));

}