Search in sources :

Example 26 with Server

use of org.hl7.gravity.refimpl.sdohexchange.model.Server in project openmrs-module-fhir2 by openmrs.

the class PersonFhirResourceProviderIntegrationTest method shouldReturnBadRequestWhenDocumentIdDoesNotMatchPersonIdAsJson.

@Test
public void shouldReturnBadRequestWhenDocumentIdDoesNotMatchPersonIdAsJson() throws Exception {
    // get the existing record
    MockHttpServletResponse response = get("/Person/" + PERSON_UUID).accept(FhirMediaTypes.JSON).go();
    Person person = readResponse(response);
    // update the existing record
    person.setId(WRONG_PERSON_UUID);
    // send the update to the server
    response = put("/Person/" + PERSON_UUID).jsonContent(toJson(person)).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) Person(org.hl7.fhir.dstu3.model.Person) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 27 with Server

use of org.hl7.gravity.refimpl.sdohexchange.model.Server in project openmrs-module-fhir2 by openmrs.

the class PersonFhirResourceProviderIntegrationTest method shouldUpdateExistingPersonAsXML.

@Test
public void shouldUpdateExistingPersonAsXML() throws Exception {
    // get the existing record
    MockHttpServletResponse response = get("/Person/" + PERSON_UUID).accept(FhirMediaTypes.XML).go();
    Person person = readResponse(response);
    // update the existing record
    Date birthDate = DateUtils.truncate(new Date(), Calendar.DATE);
    person.setBirthDate(birthDate);
    // send the update to the server
    response = put("/Person/" + PERSON_UUID).xmlContent(toXML(person)).accept(FhirMediaTypes.XML).go();
    assertThat(response, isOk());
    assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString()));
    assertThat(response.getContentAsString(), notNullValue());
    // read the updated record
    Person updatedPerson = readResponse(response);
    assertThat(updatedPerson, notNullValue());
    assertThat(updatedPerson.getIdElement().getIdPart(), equalTo(PERSON_UUID));
    assertThat(updatedPerson.getBirthDate(), equalTo(birthDate));
    assertThat(person, validResource());
    // double-check the record returned via get
    response = get("/Person/" + PERSON_UUID).accept(FhirMediaTypes.XML).go();
    Person reReadPerson = readResponse(response);
    assertThat(reReadPerson.getBirthDate(), equalTo(birthDate));
}
Also used : Person(org.hl7.fhir.dstu3.model.Person) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Date(java.util.Date) LocalDate(java.time.LocalDate) Test(org.junit.Test)

Example 28 with Server

use of org.hl7.gravity.refimpl.sdohexchange.model.Server in project openmrs-module-fhir2 by openmrs.

the class PractitionerFhirResourceProviderIntegrationTest method shouldUpdateExistingPractitionerAsXML.

@Test
public void shouldUpdateExistingPractitionerAsXML() throws Exception {
    // get the existing record
    MockHttpServletResponse response = get("/Practitioner/" + PRACTITIONER_UUID).accept(FhirMediaTypes.XML).go();
    Practitioner practitioner = readResponse(response);
    // update the existing record
    Date birthDate = DateUtils.truncate(new Date(), Calendar.DATE);
    practitioner.setBirthDate(birthDate);
    // send the update to the server
    response = put("/Practitioner/" + PRACTITIONER_UUID).xmlContent(toXML(practitioner)).accept(FhirMediaTypes.XML).go();
    assertThat(response, isOk());
    assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString()));
    assertThat(response.getContentAsString(), notNullValue());
    // read the updated record
    Practitioner updatedPractitioner = readResponse(response);
    assertThat(updatedPractitioner, notNullValue());
    assertThat(updatedPractitioner.getIdElement().getIdPart(), equalTo(PRACTITIONER_UUID));
    assertThat(updatedPractitioner.getBirthDate(), equalTo(birthDate));
    assertThat(practitioner, validResource());
    // double-check the record returned via get
    response = get("/Practitioner/" + PRACTITIONER_UUID).accept(FhirMediaTypes.XML).go();
    Practitioner reReadPractitioner = readResponse(response);
    assertThat(reReadPractitioner.getBirthDate(), equalTo(birthDate));
}
Also used : Practitioner(org.hl7.fhir.dstu3.model.Practitioner) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Date(java.util.Date) LocalDate(java.time.LocalDate) Test(org.junit.Test)

Example 29 with Server

use of org.hl7.gravity.refimpl.sdohexchange.model.Server in project openmrs-module-fhir2 by openmrs.

the class PractitionerFhirResourceProviderIntegrationTest method shouldReturnNotFoundWhenUpdatingNonExistentPractitionerAsJson.

@Test
public void shouldReturnNotFoundWhenUpdatingNonExistentPractitionerAsJson() throws Exception {
    // get the existing record
    MockHttpServletResponse response = get("/Practitioner/" + PRACTITIONER_UUID).accept(FhirMediaTypes.JSON).go();
    Practitioner practitioner = readResponse(response);
    // update the existing record
    practitioner.setId(WRONG_PRACTITIONER_UUID);
    // send the update to the server
    response = put("/Practitioner/" + WRONG_PRACTITIONER_UUID).jsonContent(toJson(practitioner)).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 : Practitioner(org.hl7.fhir.dstu3.model.Practitioner) OperationOutcome(org.hl7.fhir.dstu3.model.OperationOutcome) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 30 with Server

use of org.hl7.gravity.refimpl.sdohexchange.model.Server in project openmrs-module-fhir2 by openmrs.

the class PractitionerFhirResourceProviderIntegrationTest method shouldReturnNotFoundWhenUpdatingNonExistentPractitionerAsXML.

@Test
public void shouldReturnNotFoundWhenUpdatingNonExistentPractitionerAsXML() throws Exception {
    // get the existing record
    MockHttpServletResponse response = get("/Practitioner/" + PRACTITIONER_UUID).accept(FhirMediaTypes.XML).go();
    Practitioner practitioner = readResponse(response);
    // update the existing record
    practitioner.setId(WRONG_PRACTITIONER_UUID);
    // send the update to the server
    response = put("/Practitioner/" + WRONG_PRACTITIONER_UUID).xmlContent(toXML(practitioner)).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));
}
Also used : Practitioner(org.hl7.fhir.dstu3.model.Practitioner) OperationOutcome(org.hl7.fhir.dstu3.model.OperationOutcome) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)107 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)100 IOException (java.io.IOException)47 OperationOutcome (org.hl7.fhir.r4.model.OperationOutcome)42 FHIRException (org.hl7.fhir.exceptions.FHIRException)39 OperationOutcome (org.hl7.fhir.dstu3.model.OperationOutcome)38 ArrayList (java.util.ArrayList)25 BaseFhirIntegrationTest (org.openmrs.module.fhir2.BaseFhirIntegrationTest)24 FileNotFoundException (java.io.FileNotFoundException)21 TerminologyServiceException (org.hl7.fhir.exceptions.TerminologyServiceException)19 Date (java.util.Date)18 Bundle (org.hl7.fhir.r4.model.Bundle)17 URISyntaxException (java.net.URISyntaxException)16 HashMap (java.util.HashMap)16 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)16 FhirContext (ca.uhn.fhir.context.FhirContext)14 LocalDate (java.time.LocalDate)14 NoTerminologyServiceException (org.hl7.fhir.exceptions.NoTerminologyServiceException)13 File (java.io.File)12 Header (org.apache.http.Header)11