Search in sources :

Example 36 with Location

use of com.google.api.services.actions_fulfillment.v2.model.Location in project openmrs-module-fhir2 by openmrs.

the class LocationFhirResourceProviderWebTest method getLocationById_shouldReturnLocationWithMatchingUuid.

@Test
public void getLocationById_shouldReturnLocationWithMatchingUuid() throws Exception {
    org.hl7.fhir.r4.model.Location location = new org.hl7.fhir.r4.model.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.dstu3.model.Location) Test(org.junit.Test)

Example 37 with Location

use of com.google.api.services.actions_fulfillment.v2.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 38 with Location

use of com.google.api.services.actions_fulfillment.v2.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 39 with Location

use of com.google.api.services.actions_fulfillment.v2.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 40 with Location

use of com.google.api.services.actions_fulfillment.v2.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)

Aggregations

Test (org.junit.Test)120 Location (org.hl7.fhir.r4.model.Location)93 Location (org.hl7.fhir.dstu3.model.Location)66 IBundleProvider (ca.uhn.fhir.rest.api.server.IBundleProvider)59 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)42 BaseModuleContextSensitiveTest (org.openmrs.test.BaseModuleContextSensitiveTest)30 SearchParameterMap (org.openmrs.module.fhir2.api.search.param.SearchParameterMap)27 BaseFhirProvenanceResourceTest (org.openmrs.module.fhir2.providers.BaseFhirProvenanceResourceTest)21 StringAndListParam (ca.uhn.fhir.rest.param.StringAndListParam)20 StringOrListParam (ca.uhn.fhir.rest.param.StringOrListParam)20 StringParam (ca.uhn.fhir.rest.param.StringParam)20 ReferenceAndListParam (ca.uhn.fhir.rest.param.ReferenceAndListParam)16 ReferenceOrListParam (ca.uhn.fhir.rest.param.ReferenceOrListParam)16 ReferenceParam (ca.uhn.fhir.rest.param.ReferenceParam)16 MockIBundleProvider (org.openmrs.module.fhir2.providers.r4.MockIBundleProvider)16 TokenAndListParam (ca.uhn.fhir.rest.param.TokenAndListParam)13 Test (org.junit.jupiter.api.Test)13 ArrayList (java.util.ArrayList)11 HashSet (java.util.HashSet)11 TokenParam (ca.uhn.fhir.rest.param.TokenParam)10