use of com.ibm.watson.compare_comply.v1.model.Location in project openmrs-module-fhir2 by openmrs.
the class LocationFhirResourceProviderIntegrationTest method shouldCreateNewLocationAsJson.
@Test
public void shouldCreateNewLocationAsJson() throws Exception {
// read JSON record
String jsonLocation;
try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(JSON_CREATE_LOCATION_DOCUMENT)) {
Objects.requireNonNull(is);
jsonLocation = IOUtils.toString(is, StandardCharsets.UTF_8);
}
// create location
MockHttpServletResponse response = post("/Location").accept(FhirMediaTypes.JSON).jsonContent(jsonLocation).go();
// verify created correctly
assertThat(response, isCreated());
assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString()));
assertThat(response.getContentAsString(), notNullValue());
Location location = readResponse(response);
assertThat(location, notNullValue());
assertThat(location.getName(), equalTo("Test location"));
assertThat(location.getAddress().getCity(), equalTo("kampala"));
assertThat(location.getAddress().getCountry(), equalTo("uganda"));
assertThat(location.getAddress().getState(), equalTo("MI"));
assertThat(location.getAddress().getPostalCode(), equalTo("9105 PZ"));
assertThat(location.getMeta().getTagFirstRep().getCode(), equalTo("mCSD_Location"));
assertThat(location.getMeta().getTagFirstRep().getDisplay(), equalTo("mCSD_Location"));
assertThat(location, validResource());
// try to get new location
response = get("/Location/" + location.getIdElement().getIdPart()).accept(FhirMediaTypes.JSON).go();
assertThat(response, isOk());
Location newLocation = readResponse(response);
assertThat(newLocation.getId(), equalTo(location.getId()));
}
use of com.ibm.watson.compare_comply.v1.model.Location in project openmrs-module-fhir2 by openmrs.
the class LocationFhirResourceProviderIntegrationTest method shouldUpdateExistingLocationAsJson.
@Test
public void shouldUpdateExistingLocationAsJson() throws Exception {
// get the existing record
MockHttpServletResponse response = get("/Location/" + LOCATION_UUID).accept(FhirMediaTypes.JSON).go();
Location location = readResponse(response);
// update the existing record
location.getAddress().setCountry("France");
// send the update to the server
response = put("/Location/" + LOCATION_UUID).jsonContent(toJson(location)).accept(FhirMediaTypes.JSON).go();
assertThat(response, isOk());
assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString()));
assertThat(response.getContentAsString(), notNullValue());
// read the updated record
Location updatedLocation = readResponse(response);
assertThat(updatedLocation, notNullValue());
assertThat(updatedLocation.getIdElement().getIdPart(), equalTo(LOCATION_UUID));
assertThat(updatedLocation.getAddress().getCountry(), equalTo("France"));
assertThat(updatedLocation, validResource());
// double-check the record returned via get
response = get("/Location/" + LOCATION_UUID).accept(FhirMediaTypes.JSON).go();
Location reReadLocation = readResponse(response);
assertThat(reReadLocation.getAddress().getCountry(), equalTo("France"));
}
use of com.ibm.watson.compare_comply.v1.model.Location in project openmrs-module-fhir2 by openmrs.
the class LocationFhirResourceProviderIntegrationTest method shouldCreateNewLocationAsXML.
@Test
public void shouldCreateNewLocationAsXML() throws Exception {
// read XML record
String xmlLocation;
try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(XML_CREATE_LOCATION_DOCUMENT)) {
Objects.requireNonNull(is);
xmlLocation = IOUtils.toString(is, StandardCharsets.UTF_8);
}
// create location
MockHttpServletResponse response = post("/Location").accept(FhirMediaTypes.XML).xmlContent(xmlLocation).go();
// verify created correctly
assertThat(response, isCreated());
assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString()));
assertThat(response.getContentAsString(), notNullValue());
Location location = readResponse(response);
assertThat(location, notNullValue());
assertThat(location.getName(), equalTo("Test location"));
assertThat(location.getAddress().getCity(), equalTo("kampala"));
assertThat(location.getAddress().getCountry(), equalTo("uganda"));
assertThat(location.getAddress().getState(), equalTo("MI"));
assertThat(location.getAddress().getPostalCode(), equalTo("9105 PZ"));
assertThat(location, validResource());
// try to get new location
response = get("/Location/" + location.getIdElement().getIdPart()).accept(FhirMediaTypes.XML).go();
assertThat(response, isOk());
Location newLocation = readResponse(response);
assertThat(newLocation.getId(), equalTo(location.getId()));
}
use of com.ibm.watson.compare_comply.v1.model.Location in project openmrs-module-fhir2 by openmrs.
the class LocationFhirResourceProviderIntegrationTest method shouldCreateNewLocationWithExistingTagAsJson.
@Test
public void shouldCreateNewLocationWithExistingTagAsJson() throws Exception {
// Create Location Tag Before Posting LOcation
LocationTag tag = new LocationTag("mCSD_Location", "mCSD_Location");
locationService.saveLocationTag(tag);
// read JSON record
String jsonLocation;
try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(JSON_CREATE_LOCATION_DOCUMENT)) {
Objects.requireNonNull(is);
jsonLocation = IOUtils.toString(is, StandardCharsets.UTF_8);
}
// create location
MockHttpServletResponse response = post("/Location").accept(FhirMediaTypes.JSON).jsonContent(jsonLocation).go();
// verify created correctly
assertThat(response, isCreated());
assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString()));
assertThat(response.getContentAsString(), notNullValue());
Location location = readResponse(response);
assertThat(location, notNullValue());
assertThat(location.getName(), equalTo("Test location"));
assertThat(location.getAddress().getCity(), equalTo("kampala"));
assertThat(location.getAddress().getCountry(), equalTo("uganda"));
assertThat(location.getAddress().getState(), equalTo("MI"));
assertThat(location.getAddress().getPostalCode(), equalTo("9105 PZ"));
assertThat(location.getMeta().getTagFirstRep().getCode(), equalTo("mCSD_Location"));
assertThat(location.getMeta().getTagFirstRep().getDisplay(), equalTo("mCSD_Location"));
assertThat(location, validResource());
// try to get new location
response = get("/Location/" + location.getIdElement().getIdPart()).accept(FhirMediaTypes.JSON).go();
assertThat(response, isOk());
Location newLocation = readResponse(response);
assertThat(newLocation.getId(), equalTo(location.getId()));
}
use of com.ibm.watson.compare_comply.v1.model.Location in project openmrs-module-fhir2 by openmrs.
the class LocationFhirResourceProviderIntegrationTest method shouldReturnBadRequestWhenDocumentIdDoesNotMatchLocationIdAsJson.
@Test
public void shouldReturnBadRequestWhenDocumentIdDoesNotMatchLocationIdAsJson() throws Exception {
// get the existing record
MockHttpServletResponse response = get("/Location/" + LOCATION_UUID).accept(FhirMediaTypes.JSON).go();
Location location = readResponse(response);
// update the existing record
location.setId(UNKNOWN_LOCATION_UUID);
// send the update to the server
response = put("/Location/" + LOCATION_UUID).jsonContent(toJson(location)).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));
}
Aggregations