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

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

Introduction

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

Prototype

public void setContent(@Nullable byte[] content) 

Source Link

Document

Set the content of the request body as a byte array.

Usage

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

@Test
public void shouldCreateAEncounterRole() throws Exception {
    long originalCount = getAllCount();

    SimpleObject encounterRole = new SimpleObject();
    encounterRole.add("name", "test name");
    encounterRole.add("description", "test description");

    String json = new ObjectMapper().writeValueAsString(encounterRole);

    MockHttpServletRequest req = request(RequestMethod.POST, getURI());
    req.setContent(json.getBytes());

    SimpleObject newEncounterRole = deserialize(handle(req));

    assertNotNull(PropertyUtils.getProperty(newEncounterRole, "uuid"));
    assertEquals(originalCount + 1, getAllCount());
}

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

@Test(expected = ResourceDoesNotSupportOperationException.class)
public void shouldCreateAConceptDatatype() throws Exception {
    SimpleObject conceptDataType = new SimpleObject();
    conceptDataType.add("name", "test name");
    conceptDataType.add("description", "test description");

    String json = new ObjectMapper().writeValueAsString(conceptDataType);

    MockHttpServletRequest req = request(RequestMethod.POST, getURI());
    req.setContent(json.getBytes());

    handle(req);//w ww. j a  v  a2 s.com
}

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

@Test(expected = ResourceDoesNotSupportOperationException.class)
public void shouldNotSupportCreatingAConceptDatatype() throws Exception {
    SimpleObject conceptDataType = new SimpleObject();
    conceptDataType.add("name", "test name");
    conceptDataType.add("description", "test description");

    String json = new ObjectMapper().writeValueAsString(conceptDataType);

    MockHttpServletRequest req = request(RequestMethod.POST, getURI());
    req.setContent(json.getBytes());

    handle(req);//from  ww w . j  a  v  a 2s . c o m
}

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

@Test
public void shouldEditingAnEncounterRole() throws Exception {
    final String newName = "updated name";
    SimpleObject encounterRole = new SimpleObject();
    encounterRole.add("name", newName);

    String json = new ObjectMapper().writeValueAsString(encounterRole);

    MockHttpServletRequest req = request(RequestMethod.POST, getURI() + "/" + getUuid());
    req.setContent(json.getBytes());
    handle(req);// w  ww .ja  va  2s .  c  om
    assertEquals(newName, service.getEncounterRoleByUuid(getUuid()).getName());
}

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

@Test
public void shouldCreateAPrivilege() throws Exception {
    long originalCount = getAllCount();

    SimpleObject privilege = new SimpleObject();
    privilege.add("name", "test name");
    privilege.add("description", "test description");

    String json = new ObjectMapper().writeValueAsString(privilege);

    MockHttpServletRequest req = request(RequestMethod.POST, getURI());
    req.setContent(json.getBytes());

    SimpleObject newPrivilege = deserialize(handle(req));

    assertNotNull(PropertyUtils.getProperty(newPrivilege, "uuid"));
    assertEquals(originalCount + 1, getAllCount());
}

From source file:net.jadler.stubbing.server.jetty.RequestUtilsTest.java

@Test
public void parameters() throws IOException {
    final MockHttpServletRequest httpRequest = prepareEmptyRequest();
    httpRequest.setQueryString("a=1&b=3");
    httpRequest.setContent("a=2".getBytes());
    httpRequest.addHeader("content-type", "application/x-www-form-urlencoded");

    final Request req = RequestUtils.convert(httpRequest);
    assertThat(req.getParameters().getKeys(), containsInAnyOrder("a", "b"));
    assertThat(req.getParameters().getValues("a"), contains("1", "2"));
    assertThat(req.getParameters().getValues("b"), contains("3"));
}

From source file:org.apache.amber.oauth2.ext.dynamicreg.server.request.OAuthServerRegistrationRequestTest.java

@Test(expected = OAuthProblemException.class)
public void testInvalidBodyPushRequest() throws Exception {
    final String inValidJson = FileUtils.readTextFileAsString("json/push_invalid.json");
    MockHttpServletRequest request = new MockHttpServletRequest("POST", "/oauth/register");
    request.setContentType(OAuth.ContentType.JSON);
    request.setContent(inValidJson.getBytes("UTF-8"));

    final JSONHttpServletRequestWrapper jsonWrapper = new JSONHttpServletRequestWrapper(request);
    OAuthServerRegistrationRequest registrationRequest = new OAuthServerRegistrationRequest(jsonWrapper);
}

From source file:com.surevine.alfresco.audit.MultiReadHttpServletRequestTest.java

MultiReadHttpServletRequest testRequestWithSize(int size) throws Exception {
    MockHttpServletRequest mockRequest = new MockHttpServletRequest();

    byte[] testData = getTestData(size);

    mockRequest.setContent(testData); // A request

    MultiReadHttpServletRequest request = new MultiReadHttpServletRequest(mockRequest);

    byte[] result1 = IOUtils.toByteArray(request.getInputStream());
    assertTrue("result1 should equal the input array. [" + testData.length + ", " + result1.length + "]",
            Arrays.equals(testData, result1));

    result1 = null;/* ww  w.j  a  v  a 2 s.  c o m*/
    System.gc();

    byte[] result2 = IOUtils.toByteArray(request.getInputStream());
    assertTrue("result2 should equal the output array [" + testData.length + ", " + result2.length + "]",
            Arrays.equals(testData, result2));

    testData = null;
    result2 = null;
    System.gc();

    return request;
}

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

@Test
public void shouldCreateAPatientIdentifierType() throws Exception {
    long originalCount = getAllCount();

    SimpleObject patientIdentifierType = new SimpleObject();
    patientIdentifierType.add("name", "test name");
    patientIdentifierType.add("description", "test description");

    String json = new ObjectMapper().writeValueAsString(patientIdentifierType);

    MockHttpServletRequest req = request(RequestMethod.POST, getURI());
    req.setContent(json.getBytes());

    SimpleObject newPatientIdentifierType = deserialize(handle(req));

    assertNotNull(PropertyUtils.getProperty(newPatientIdentifierType, "uuid"));
    assertEquals(originalCount + 1, getAllCount());
}

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

@Test
public void shouldCreateAConceptDatatype() throws Exception {
    long originalCount = getAllCount();

    SimpleObject conceptDataType = new SimpleObject();
    conceptDataType.add("name", "test name");
    conceptDataType.add("description", "test description");

    String json = new ObjectMapper().writeValueAsString(conceptDataType);

    MockHttpServletRequest req = request(RequestMethod.POST, getURI());
    req.setContent(json.getBytes());

    SimpleObject newConceptDatatype = deserialize(handle(req));

    Assert.assertNotNull(PropertyUtils.getProperty(newConceptDatatype, "uuid"));
    Assert.assertEquals(originalCount + 1, getAllCount());
}