Search in sources :

Example 76 with Location

use of org.hl7.fhir.r4.model.Location in project openmrs-module-fhir2 by openmrs.

the class LocationFhirResourceProviderWebTest method deleteLocation_shouldDeleteLocation.

@Test
public void deleteLocation_shouldDeleteLocation() throws Exception {
    org.hl7.fhir.r4.model.Location location = new org.hl7.fhir.r4.model.Location();
    location.setId(LOCATION_UUID);
    when(locationService.delete(LOCATION_UUID)).thenReturn(location);
    MockHttpServletResponse response = delete("/Location/" + LOCATION_UUID).accept(FhirMediaTypes.JSON).go();
    assertThat(response, isOk());
    assertThat(response.getContentType(), equalTo(FhirMediaTypes.JSON.toString()));
}
Also used : MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Location(org.hl7.fhir.dstu3.model.Location) Test(org.junit.Test)

Example 77 with Location

use of org.hl7.fhir.r4.model.Location in project openmrs-module-fhir2 by openmrs.

the class LocationFhirResourceProviderWebTest method verifyURI.

private void verifyURI(String uri) throws Exception {
    Location location = new Location();
    location.setId(LOCATION_UUID);
    when(locationService.searchForLocations(any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any())).thenReturn(new MockIBundleProvider<>(Collections.singletonList(location), 10, 1));
    MockHttpServletResponse response = get(uri).accept(FhirMediaTypes.JSON).go();
    assertThat(response, isOk());
    assertThat(response.getContentType(), equalTo(FhirMediaTypes.JSON.toString()));
    assertThat(readBundleResponse(response).getEntry().size(), greaterThanOrEqualTo(1));
}
Also used : MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Location(org.hl7.fhir.dstu3.model.Location)

Example 78 with Location

use of org.hl7.fhir.r4.model.Location in project openmrs-module-fhir2 by openmrs.

the class LocationFhirResourceProviderWebTest method getLocationById_shouldReturnLocationWithMatchingUuid.

@Test
public void getLocationById_shouldReturnLocationWithMatchingUuid() throws Exception {
    Location location = new Location();
    location.setId(LOCATION_UUID);
    when(locationService.get(LOCATION_UUID)).thenReturn(location);
    MockHttpServletResponse response = get("/Location/" + LOCATION_UUID).accept(FhirMediaTypes.JSON).go();
    assertThat(response, isOk());
    assertThat(response.getContentType(), equalTo(FhirMediaTypes.JSON.toString()));
    Location resource = readResponse(response);
    assertThat(resource.getIdElement().getIdPart(), equalTo(LOCATION_UUID));
}
Also used : MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Location(org.hl7.fhir.r4.model.Location) Test(org.junit.Test)

Example 79 with Location

use of org.hl7.fhir.r4.model.Location in project openmrs-module-fhir2 by openmrs.

the class LocationFhirResourceProviderWebTest method createLocation_shouldCreateLocation.

@Test
public void createLocation_shouldCreateLocation() throws Exception {
    String jsonLocation;
    try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(JSON_CREATE_LOCATION_PATH)) {
        Objects.requireNonNull(is);
        jsonLocation = IOUtils.toString(is, StandardCharsets.UTF_8);
    }
    Location location = new Location();
    location.setId(LOCATION_UUID);
    when(locationService.create(any(Location.class))).thenReturn(location);
    MockHttpServletResponse response = post("/Location").jsonContent(jsonLocation).accept(FhirMediaTypes.JSON).go();
    assertThat(response, isCreated());
}
Also used : InputStream(java.io.InputStream) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Location(org.hl7.fhir.r4.model.Location) Test(org.junit.Test)

Example 80 with Location

use of org.hl7.fhir.r4.model.Location in project openmrs-module-fhir2 by openmrs.

the class LocationFhirResourceProviderWebTest method shouldGetLocationHistoryById.

@Test
public void shouldGetLocationHistoryById() throws IOException, ServletException {
    Provenance provenance = new Provenance();
    provenance.setId(new IdType(FhirUtils.newUuid()));
    provenance.setRecorded(new Date());
    provenance.setActivity(new CodeableConcept().addCoding(new Coding().setCode("CREATE").setSystem(FhirConstants.FHIR_TERMINOLOGY_DATA_OPERATION).setDisplay("create")));
    provenance.addAgent(new Provenance.ProvenanceAgentComponent().setType(new CodeableConcept().addCoding(new Coding().setCode(FhirConstants.AUT).setDisplay(FhirConstants.AUTHOR).setSystem(FhirConstants.FHIR_TERMINOLOGY_PROVENANCE_PARTICIPANT_TYPE))).addRole(new CodeableConcept().addCoding(new Coding().setCode("").setDisplay("").setSystem(FhirConstants.FHIR_TERMINOLOGY_PARTICIPATION_TYPE))));
    Location location = new Location();
    location.setId(LOCATION_UUID);
    location.addContained(provenance);
    when(locationService.get(LOCATION_UUID)).thenReturn(location);
    MockHttpServletResponse response = getLocationHistoryByIdRequest();
    Bundle results = readBundleResponse(response);
    assertThat(results, Matchers.notNullValue());
    assertThat(results.hasEntry(), is(true));
    assertThat(results.getEntry().get(0).getResource(), Matchers.notNullValue());
    assertThat(results.getEntry().get(0).getResource().getResourceType().name(), equalTo(Provenance.class.getSimpleName()));
}
Also used : Provenance(org.hl7.fhir.r4.model.Provenance) Coding(org.hl7.fhir.r4.model.Coding) Bundle(org.hl7.fhir.r4.model.Bundle) Date(java.util.Date) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) IdType(org.hl7.fhir.r4.model.IdType) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) Location(org.hl7.fhir.r4.model.Location) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)215 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)94 Location (org.hl7.fhir.r4.model.Location)93 IBundleProvider (ca.uhn.fhir.rest.api.server.IBundleProvider)71 Location (org.hl7.fhir.dstu3.model.Location)66 InputStream (java.io.InputStream)46 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)39 Matchers.containsString (org.hamcrest.Matchers.containsString)38 Test (org.junit.jupiter.api.Test)38 BaseModuleContextSensitiveTest (org.openmrs.test.BaseModuleContextSensitiveTest)37 SearchParameterMap (org.openmrs.module.fhir2.api.search.param.SearchParameterMap)35 ArrayList (java.util.ArrayList)29 Complex (org.hl7.fhir.r4.utils.formats.Turtle.Complex)29 BaseFhirProvenanceResourceTest (org.openmrs.module.fhir2.providers.BaseFhirProvenanceResourceTest)26 Reference (org.hl7.fhir.r4.model.Reference)25 Date (java.util.Date)24 Bundle (org.hl7.fhir.r4.model.Bundle)24 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)24 ReferenceAndListParam (ca.uhn.fhir.rest.param.ReferenceAndListParam)23 ReferenceOrListParam (ca.uhn.fhir.rest.param.ReferenceOrListParam)23