From f91977cbace935df95d43eb9b0fded260f213e98 Mon Sep 17 00:00:00 2001 From: James Agnew Date: Wed, 8 Nov 2017 16:53:39 -0500 Subject: [PATCH] Beef up logging in tests --- .../dao/dstu2/FhirResourceDaoDstu2Test.java | 24 +++++++++++++++++++ .../ResourceProviderInterceptorDstu3Test.java | 16 +++++++++---- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoDstu2Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoDstu2Test.java index c03923110a2..1c3a5d470fc 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoDstu2Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoDstu2Test.java @@ -56,6 +56,30 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { myDaoConfig.setTreatReferencesAsLogical(new DaoConfig().getTreatReferencesAsLogical()); } + /** + * See #773 + */ + @Test + public void testDeleteResourceWithOutboundDeletedResources() { + myDaoConfig.setEnforceReferentialIntegrityOnDelete(false); + + Organization org = new Organization(); + org.setId("ORG"); + org.setName("ORG"); + myOrganizationDao.update(org); + + Patient pat = new Patient(); + pat.setId("PAT"); + pat.setActive(true); + pat.setManagingOrganization(new ResourceReferenceDt("Organization/ORG")); + myPatientDao.update(pat); + + myOrganizationDao.delete(new IdDt("Organization/ORG")); + + myPatientDao.delete(new IdDt("Patient/PAT")); + } + + private void assertGone(IIdType theId) { try { assertNotGone(theId); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderInterceptorDstu3Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderInterceptorDstu3Test.java index 29798cf84bf..2a4e87c050d 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderInterceptorDstu3Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderInterceptorDstu3Test.java @@ -1,7 +1,6 @@ package ca.uhn.fhir.jpa.provider.dstu3; import ca.uhn.fhir.jpa.provider.r4.ResourceProviderInterceptorR4Test; -import ca.uhn.fhir.model.dstu2.resource.Conformance; import ca.uhn.fhir.parser.IParser; import ca.uhn.fhir.rest.api.Constants; import ca.uhn.fhir.rest.api.RestOperationTypeEnum; @@ -61,8 +60,8 @@ public class ResourceProviderInterceptorDstu3Test extends BaseResourceProviderDs public void before() throws Exception { super.before(); - myServerInterceptor = mock(IServerInterceptor.class); - myDaoInterceptor = mock(IServerInterceptor.class); + myServerInterceptor = mock(IServerInterceptor.class, withSettings().verboseLogging()); + myDaoInterceptor = mock(IServerInterceptor.class, withSettings().verboseLogging()); resetServerInterceptor(); @@ -125,6 +124,8 @@ public class ResourceProviderInterceptorDstu3Test extends BaseResourceProviderDs public void testCreateResourceInTransaction() throws IOException, ServletException { String methodName = "testCreateResourceInTransaction"; + ourLog.info("** Starting {}", methodName); + Patient pt = new Patient(); pt.addName().setFamily(methodName); @@ -140,6 +141,11 @@ public class ResourceProviderInterceptorDstu3Test extends BaseResourceProviderDs resetServerInterceptor(); + ArgumentCaptor ardCaptor = ArgumentCaptor.forClass(ActionRequestDetails.class); + ArgumentCaptor opTypeCaptor = ArgumentCaptor.forClass(RestOperationTypeEnum.class); + verify(myDaoInterceptor, times(0)).incomingRequestPreHandled(opTypeCaptor.capture(), ardCaptor.capture()); + verify(myServerInterceptor, times(0)).incomingRequestPreHandled(opTypeCaptor.capture(), ardCaptor.capture()); + HttpPost post = new HttpPost(ourServerBase + "/"); post.setEntity(new StringEntity(resource, ContentType.create(Constants.CT_FHIR_XML, "UTF-8"))); CloseableHttpResponse response = ourHttpClient.execute(post); @@ -153,8 +159,8 @@ public class ResourceProviderInterceptorDstu3Test extends BaseResourceProviderDs * Server Interceptor */ - ArgumentCaptor ardCaptor = ArgumentCaptor.forClass(ActionRequestDetails.class); - ArgumentCaptor opTypeCaptor = ArgumentCaptor.forClass(RestOperationTypeEnum.class); + ardCaptor = ArgumentCaptor.forClass(ActionRequestDetails.class); + opTypeCaptor = ArgumentCaptor.forClass(RestOperationTypeEnum.class); verify(myServerInterceptor, times(2)).incomingRequestPreHandled(opTypeCaptor.capture(), ardCaptor.capture()); assertEquals(RestOperationTypeEnum.TRANSACTION, opTypeCaptor.getAllValues().get(0)); assertEquals(null, ardCaptor.getAllValues().get(0).getResourceType());