From 5a7e1de367e094c5220566b44230e3941e523a38 Mon Sep 17 00:00:00 2001 From: Tadgh Date: Tue, 7 Jul 2020 10:15:38 -0700 Subject: [PATCH] Flesh out tests --- .../provider/EmpiProviderClearLinkR4Test.java | 33 +++++++++++++++---- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/provider/EmpiProviderClearLinkR4Test.java b/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/provider/EmpiProviderClearLinkR4Test.java index ee3e8cf7e7a..85297ff9ece 100644 --- a/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/provider/EmpiProviderClearLinkR4Test.java +++ b/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/provider/EmpiProviderClearLinkR4Test.java @@ -2,6 +2,8 @@ package ca.uhn.fhir.jpa.empi.provider; import ca.uhn.fhir.jpa.entity.EmpiLink; import ca.uhn.fhir.model.primitive.IdDt; +import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; +import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException; import org.hl7.fhir.r4.model.Person; import org.hl7.fhir.r4.model.Practitioner; import org.hl7.fhir.r4.model.StringType; @@ -15,19 +17,24 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.nullValue; +import static org.hamcrest.Matchers.notNullValue; +import static org.junit.jupiter.api.Assertions.fail; public class EmpiProviderClearLinkR4Test extends BaseLinkR4Test { protected Practitioner myPractitioner; protected StringType myPractitionerId; + protected Person myPractitionerPerson; + protected StringType myPractitionerPersonId; @BeforeEach public void before() { super.before(); myPractitioner = createPractitionerAndUpdateLinks(new Practitioner()); myPractitionerId = new StringType(myPractitioner.getIdElement().getValue()); + myPractitionerPerson = getPersonFromTarget(myPractitioner); + myPractitionerPersonId = new StringType(myPractitionerPerson.getIdElement().getValue()); } @Test @@ -54,24 +61,36 @@ public class EmpiProviderClearLinkR4Test extends BaseLinkR4Test { public void testClearPatientLinks() { assertLinkCount(2); + Person read = myPersonDao.read(new IdDt(myPersonId.getValueAsString()).toVersionless()); + assertThat(read, is(notNullValue())); myEmpiProviderR4.clearEmpiLinks(new StringType("patient")); assertNoPatientLinksExist(); - Person read = myPersonDao.read(new IdDt(myPersonId.getValueAsString()).toVersionless()); - assertThat(read, is(equalTo(nullValue()))); + try { + myPersonDao.read(new IdDt(myPersonId.getValueAsString()).toVersionless()); + fail(); + } catch (ResourceNotFoundException e) {} + } @Test public void testClearPractitionerLinks() { assertLinkCount(2); - myEmpiProviderR4.clearEmpiLinks(new StringType("patient")); + myEmpiProviderR4.clearEmpiLinks(new StringType("practitioner")); assertNoPractitionerLinksExist(); + try { + myPersonDao.read(new IdDt(myPractitionerPersonId.getValueAsString()).toVersionless()); + fail(); + } catch (ResourceNotFoundException e) {} } @Test public void testClearInvalidTargetType() { - myEmpiProviderR4.updateLink(myPersonId, myPatientId, MATCH_RESULT, myRequestDetails); - Person person = myEmpiProviderR4.updateLink(myVersionlessPersonId, myPatientId, NO_MATCH_RESULT, myRequestDetails); - assertThat(person.getLink(), hasSize(0)); + try { + myEmpiProviderR4.clearEmpiLinks(new StringType("observation")); + fail(); + } catch (InvalidRequestException e) { + assertThat(e.getMessage(), is(equalTo("$empi-clear does not support resource type: observation"))); + } }