Search in sources :

Example 71 with Group

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

the class GroupResourceProviderIntegrationTest method shouldReturnNotFoundWhenDeletingNonExistentGroup.

@Test
public void shouldReturnNotFoundWhenDeletingNonExistentGroup() throws Exception {
    MockHttpServletResponse response = delete("/Group/" + BAD_COHORT_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 72 with Group

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

the class GroupResourceProviderIntegrationTest method shouldCreateNewGroupAsXML.

@Test
public void shouldCreateNewGroupAsXML() throws Exception {
    // read JSON record
    String xmlGroup;
    try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(XML_CREATE_GROUP_DOCUMENT)) {
        Objects.requireNonNull(is);
        xmlGroup = IOUtils.toString(is, StandardCharsets.UTF_8);
    }
    // create group
    MockHttpServletResponse response = post("/Group").accept(FhirMediaTypes.XML).xmlContent(xmlGroup).go();
    // verify created correctly
    assertThat(response, isCreated());
    assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString()));
    assertThat(response.getContentAsString(), notNullValue());
    Group group = readResponse(response);
    assertThat(group, notNullValue());
    assertThat(group.getActive(), is(true));
    assertThat(group.hasMember(), is(true));
    assertThat(group.getMember(), notNullValue());
    assertThat(group.getQuantity(), equalTo(1));
    // try to get new group
    response = get(group.getId()).accept(FhirMediaTypes.XML).go();
    assertThat(response, isOk());
    Group newGroup = readResponse(response);
    assertThat(newGroup.getId(), equalTo(group.getId()));
    assertThat(newGroup.getActive(), equalTo(true));
}
Also used : Group(org.hl7.fhir.dstu3.model.Group) InputStream(java.io.InputStream) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test) BaseFhirIntegrationTest(org.openmrs.module.fhir2.BaseFhirIntegrationTest)

Example 73 with Group

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

the class GroupResourceProviderIntegrationTest method shouldReturnNotFoundWhenUpdatingNonExistentGroupAsXML.

@Test
public void shouldReturnNotFoundWhenUpdatingNonExistentGroupAsXML() throws Exception {
    // get the existing record
    MockHttpServletResponse response = get("/Group/" + COHORT_UUID).accept(FhirMediaTypes.XML).go();
    Group group = readResponse(response);
    // update the existing record
    group.setId(BAD_COHORT_UUID);
    // send the update to the server
    response = put("/Group/" + BAD_COHORT_UUID).xmlContent(toXML(group)).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 : Group(org.hl7.fhir.dstu3.model.Group) OperationOutcome(org.hl7.fhir.dstu3.model.OperationOutcome) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test) BaseFhirIntegrationTest(org.openmrs.module.fhir2.BaseFhirIntegrationTest)

Example 74 with Group

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

the class GroupFhirResourceProviderIntegrationTest method shouldReturnBadRequestWhenDocumentIdDoesNotMatchGroupIdAsJSON.

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

Example 75 with Group

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

the class GroupFhirResourceProviderIntegrationTest method shouldCreateNewGroupAsXML.

@Test
public void shouldCreateNewGroupAsXML() throws Exception {
    // read JSON record
    String xmlGroup;
    try (InputStream is = this.getClass().getClassLoader().getResourceAsStream(XML_CREATE_GROUP_DOCUMENT)) {
        Objects.requireNonNull(is);
        xmlGroup = IOUtils.toString(is, StandardCharsets.UTF_8);
    }
    // create group
    MockHttpServletResponse response = post("/Group").accept(FhirMediaTypes.XML).xmlContent(xmlGroup).go();
    // verify created correctly
    assertThat(response, isCreated());
    assertThat(response.getContentType(), is(FhirMediaTypes.XML.toString()));
    assertThat(response.getContentAsString(), notNullValue());
    Group group = readResponse(response);
    assertThat(group, notNullValue());
    assertThat(group.getActive(), is(true));
    assertThat(group.hasMember(), is(true));
    // try to get new group
    response = get(group.getId()).accept(FhirMediaTypes.XML).go();
    assertThat(response, isOk());
    Group newGroup = readResponse(response);
    assertThat(newGroup.getId(), equalTo(group.getId()));
    assertThat(newGroup.getActive(), equalTo(true));
}
Also used : Group(org.hl7.fhir.dstu3.model.Group) InputStream(java.io.InputStream) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test) BaseFhirIntegrationTest(org.openmrs.module.fhir2.BaseFhirIntegrationTest)

Aggregations

Test (org.junit.Test)106 Group (org.hl7.fhir.r4.model.Group)74 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)59 ArrayList (java.util.ArrayList)57 BaseFhirIntegrationTest (org.openmrs.module.fhir2.BaseFhirIntegrationTest)50 Group (org.hl7.fhir.dstu3.model.Group)44 FHIRException (org.hl7.fhir.exceptions.FHIRException)37 Cohort (org.openmrs.Cohort)32 Test (org.junit.jupiter.api.Test)29 InputStream (java.io.InputStream)21 Reference (org.hl7.fhir.r4.model.Reference)21 List (java.util.List)16 Complex (org.hl7.fhir.dstu2016may.formats.RdfGenerator.Complex)16 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)16 Coding (org.hl7.fhir.r4.model.Coding)16 Diagnosis (gov.cms.bfd.server.war.commons.Diagnosis)15 IOException (java.io.IOException)13 IdType (org.hl7.fhir.dstu3.model.IdType)13 OperationOutcome (org.hl7.fhir.r4.model.OperationOutcome)13 Complex (org.hl7.fhir.r4.utils.formats.Turtle.Complex)13