Search in sources :

Example 76 with OperationOutcome

use of org.hl7.fhir.r5.model.OperationOutcome in project openmrs-module-fhir2 by openmrs.

the class MedicationFhirResourceProviderIntegrationTest method shouldReturnBadRequestWhenDocumentIdDoesNotMatchMedicationIdAsJson.

@Test
public void shouldReturnBadRequestWhenDocumentIdDoesNotMatchMedicationIdAsJson() throws Exception {
    // get the existing record
    MockHttpServletResponse response = get("/Medication/" + MEDICATION_UUID).accept(FhirMediaTypes.JSON).go();
    Medication medication = readResponse(response);
    // update the existing record
    medication.setId(WRONG_MEDICATION_UUID);
    // send the update to the server
    response = put("/Medication/" + MEDICATION_UUID).jsonContent(toJson(medication)).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));
}
Also used : OperationOutcome(org.hl7.fhir.dstu3.model.OperationOutcome) Medication(org.hl7.fhir.dstu3.model.Medication) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test) BaseFhirIntegrationTest(org.openmrs.module.fhir2.BaseFhirIntegrationTest)

Example 77 with OperationOutcome

use of org.hl7.fhir.r5.model.OperationOutcome in project openmrs-module-fhir2 by openmrs.

the class MedicationFhirResourceProviderIntegrationTest method shouldReturnNotFoundWhenDeletingNonExistentMedication.

@Test
public void shouldReturnNotFoundWhenDeletingNonExistentMedication() throws Exception {
    MockHttpServletResponse response = delete("/Medication/" + WRONG_MEDICATION_UUID).accept(FhirMediaTypes.JSON).go();
    assertThat(response, isNotFound());
    assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString()));
    assertThat(response.getContentAsString(), notNullValue());
    OperationOutcome operationOutcome = readOperationOutcome(response);
    assertThat(operationOutcome, notNullValue());
    assertThat(operationOutcome.hasIssue(), is(true));
}
Also used : OperationOutcome(org.hl7.fhir.dstu3.model.OperationOutcome) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test) BaseFhirIntegrationTest(org.openmrs.module.fhir2.BaseFhirIntegrationTest)

Example 78 with OperationOutcome

use of org.hl7.fhir.r5.model.OperationOutcome in project openmrs-module-fhir2 by openmrs.

the class TaskFhirResourceIntegrationTest method shouldReturnBadRequestWhenDocumentIdDoesNotMatchTaskIdAsJson.

@Test
public void shouldReturnBadRequestWhenDocumentIdDoesNotMatchTaskIdAsJson() throws Exception {
    MockHttpServletResponse response = get("/Task/" + TASK_UUID).accept(FhirMediaTypes.JSON).go();
    assertThat(response, isOk());
    Task task = readResponse(response);
    task.setId(WRONG_TASK_UUID);
    response = put("/Task/" + TASK_UUID).jsonContent(toJson(task)).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));
}
Also used : Task(org.hl7.fhir.dstu3.model.Task) OperationOutcome(org.hl7.fhir.dstu3.model.OperationOutcome) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 79 with OperationOutcome

use of org.hl7.fhir.r5.model.OperationOutcome in project openmrs-module-fhir2 by openmrs.

the class TaskFhirResourceIntegrationTest method shouldReturnNotFoundWhenUpdatingNonExistentTaskAsJson.

@Test
public void shouldReturnNotFoundWhenUpdatingNonExistentTaskAsJson() throws Exception {
    MockHttpServletResponse response = get("/Task/" + TASK_UUID).accept(FhirMediaTypes.JSON).go();
    assertThat(response, isOk());
    Task patient = readResponse(response);
    patient.setId(WRONG_TASK_UUID);
    response = put("/Task/" + WRONG_TASK_UUID).jsonContent(toJson(patient)).accept(FhirMediaTypes.JSON).go();
    assertThat(response, isNotFound());
    assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString()));
    assertThat(response.getContentAsString(), notNullValue());
    OperationOutcome operationOutcome = readOperationOutcome(response);
    assertThat(operationOutcome, notNullValue());
    assertThat(operationOutcome.hasIssue(), is(true));
}
Also used : Task(org.hl7.fhir.dstu3.model.Task) OperationOutcome(org.hl7.fhir.dstu3.model.OperationOutcome) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 80 with OperationOutcome

use of org.hl7.fhir.r5.model.OperationOutcome in project openmrs-module-fhir2 by openmrs.

the class TaskFhirResourceIntegrationTest method shouldReturnNotFoundWhenDeletingNonExistentTask.

@Test
public void shouldReturnNotFoundWhenDeletingNonExistentTask() throws Exception {
    MockHttpServletResponse response = delete("/Patient/" + WRONG_TASK_UUID).accept(FhirMediaTypes.JSON).go();
    assertThat(response, isNotFound());
    assertThat(response.getContentType(), is(FhirMediaTypes.JSON.toString()));
    assertThat(response.getContentAsString(), notNullValue());
    OperationOutcome operationOutcome = readOperationOutcome(response);
    assertThat(operationOutcome, notNullValue());
    assertThat(operationOutcome.hasIssue(), is(true));
}
Also used : OperationOutcome(org.hl7.fhir.dstu3.model.OperationOutcome) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)214 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)181 OperationOutcome (org.hl7.fhir.r4.model.OperationOutcome)161 OperationOutcome (org.hl7.fhir.dstu3.model.OperationOutcome)144 Test (org.junit.jupiter.api.Test)42 BaseFhirIntegrationTest (org.openmrs.module.fhir2.BaseFhirIntegrationTest)31 IOException (java.io.IOException)26 IBaseOperationOutcome (org.hl7.fhir.instance.model.api.IBaseOperationOutcome)24 OperationOutcomeIssueComponent (org.hl7.fhir.r4.model.OperationOutcome.OperationOutcomeIssueComponent)23 MethodOutcome (ca.uhn.fhir.rest.api.MethodOutcome)22 OperationOutcome (org.hl7.fhir.r5.model.OperationOutcome)20 IdType (org.hl7.fhir.dstu3.model.IdType)17 IdType (org.hl7.fhir.r4.model.IdType)17 CodeableConcept (org.hl7.fhir.dstu3.model.CodeableConcept)15 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)15 URISyntaxException (java.net.URISyntaxException)13 GET (javax.ws.rs.GET)12 Path (javax.ws.rs.Path)12 Produces (javax.ws.rs.Produces)12 Header (org.apache.http.Header)11