use of ca.uhn.hl7v2.model.Group in project openmrs-module-fhir2 by openmrs.
the class GroupFhirResourceProviderIntegrationTest method shouldReturnBadRequestWhenDocumentIdDoesNotMatchGroupIdAsJSON.
@Test
public void shouldReturnBadRequestWhenDocumentIdDoesNotMatchGroupIdAsJSON() throws Exception {
// get the existing record
MockHttpServletResponse response = get("/Group/" + COHORT_UUID).accept(FhirMediaTypes.JSON).go();
Group group = readResponse(response);
// update the existing record
group.setId(BAD_COHORT_UUID);
// send the update to the server
response = put("/Group/" + COHORT_UUID).jsonContent(toJson(group)).accept(FhirMediaTypes.JSON).go();
assertThat(response, isBadRequest());
assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString()));
assertThat(response.getContentAsString(), notNullValue());
OperationOutcome operationOutcome = readOperationOutcome(response);
assertThat(operationOutcome, notNullValue());
assertThat(operationOutcome.hasIssue(), is(true));
}
use of ca.uhn.hl7v2.model.Group in project openmrs-module-fhir2 by openmrs.
the class GroupFhirResourceProviderIntegrationTest method shouldCreateNewGroupAsXML.
@Test
public void shouldCreateNewGroupAsXML() throws Exception {
// read JSON record
String xmlGroup;
try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(XML_CREATE_GROUP_DOCUMENT)) {
Objects.requireNonNull(is);
xmlGroup = IOUtils.toString(is, StandardCharsets.UTF_8);
}
// create group
MockHttpServletResponse response = post("/Group").accept(FhirMediaTypes.XML).xmlContent(xmlGroup).go();
// verify created correctly
assertThat(response, isCreated());
assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString()));
assertThat(response.getContentAsString(), notNullValue());
Group group = readResponse(response);
assertThat(group, notNullValue());
assertThat(group.getActive(), is(true));
assertThat(group.hasMember(), is(true));
// try to get new group
response = get(group.getId()).accept(FhirMediaTypes.XML).go();
assertThat(response, isOk());
Group newGroup = readResponse(response);
assertThat(newGroup.getId(), equalTo(group.getId()));
assertThat(newGroup.getActive(), equalTo(true));
}
use of ca.uhn.hl7v2.model.Group in project openmrs-module-fhir2 by openmrs.
the class GroupFhirResourceProviderIntegrationTest method shouldUpdateExistingGroupAsXML.
@Test
public void shouldUpdateExistingGroupAsXML() throws Exception {
// Before update
MockHttpServletResponse response = get("/Group/" + COHORT_UUID).accept(FhirMediaTypes.XML).go();
assertThat(response, isOk());
assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString()));
assertThat(response.getContentAsString(), notNullValue());
Group group = readResponse(response);
assertThat(group, notNullValue());
assertThat(group, validResource());
assertThat(group.getIdElement().getIdPart(), equalTo(COHORT_UUID));
// Get existing group with updated name
String xmlGroup;
try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(XML_UPDATE_GROUP_DOCUMENT)) {
Objects.requireNonNull(is);
xmlGroup = IOUtils.toString(is, StandardCharsets.UTF_8);
}
// Update
response = put("/Group/" + COHORT_UUID).xmlContent(xmlGroup).accept(FhirMediaTypes.XML).go();
assertThat(response, isOk());
assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString()));
assertThat(response.getContentAsString(), notNullValue());
// read updated record
group = readResponse(response);
assertThat(group, notNullValue());
assertThat(group.getIdElement().getIdPart(), equalTo(COHORT_UUID));
assertThat(group.getActive(), is(true));
assertThat(group, validResource());
// Double-check via get
response = get("/Group/" + COHORT_UUID).accept(FhirMediaTypes.XML).go();
Group updatedGroup = readResponse(response);
assertThat(updatedGroup, validResource());
assertThat(updatedGroup, notNullValue());
assertThat(updatedGroup.getActive(), is(true));
}
use of ca.uhn.hl7v2.model.Group in project openmrs-module-fhir2 by openmrs.
the class GroupFhirResourceProviderIntegrationTest method shouldReturnNotFoundWhenUpdatingNonExistentGroupAsXML.
@Test
public void shouldReturnNotFoundWhenUpdatingNonExistentGroupAsXML() throws Exception {
// get the existing record
MockHttpServletResponse response = get("/Group/" + COHORT_UUID).accept(FhirMediaTypes.XML).go();
Group group = readResponse(response);
// update the existing record
group.setId(BAD_COHORT_UUID);
// send the update to the server
response = put("/Group/" + BAD_COHORT_UUID).xmlContent(toXML(group)).accept(FhirMediaTypes.XML).go();
assertThat(response, isNotFound());
assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString()));
assertThat(response.getContentAsString(), notNullValue());
OperationOutcome operationOutcome = readOperationOutcome(response);
assertThat(operationOutcome, notNullValue());
assertThat(operationOutcome.hasIssue(), is(true));
}
use of ca.uhn.hl7v2.model.Group in project openmrs-module-fhir2 by openmrs.
the class GroupFhirResourceProviderIntegrationTest method shouldReturnBadRequestWhenDocumentIdDoesNotMatchGroupIdAsXML.
@Test
public void shouldReturnBadRequestWhenDocumentIdDoesNotMatchGroupIdAsXML() throws Exception {
// get the existing record
MockHttpServletResponse response = get("/Group/" + COHORT_UUID).accept(FhirMediaTypes.XML).go();
Group group = readResponse(response);
// update the existing record
group.setId(BAD_COHORT_UUID);
// send the update to the server
response = put("/Group/" + COHORT_UUID).xmlContent(toXML(group)).accept(FhirMediaTypes.XML).go();
assertThat(response, isBadRequest());
assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString()));
assertThat(response.getContentAsString(), notNullValue());
OperationOutcome operationOutcome = readOperationOutcome(response);
assertThat(operationOutcome, notNullValue());
assertThat(operationOutcome.hasIssue(), is(true));
}
Aggregations