From 10f7eb31eba4dc0bb6fa5e5905cb1563b50b63f3 Mon Sep 17 00:00:00 2001 From: Ken Stevens Date: Mon, 29 Apr 2019 10:20:45 -0400 Subject: [PATCH] fixed delete reference error message --- .../ca/uhn/fhir/jpa/dao/BaseHapiFhirDao.java | 2 +- .../jpa/dao/r4/FhirResourceDaoR4Test.java | 22 +++++++++---------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirDao.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirDao.java index 5b88743948e..df3ecce6b0e 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirDao.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirDao.java @@ -1294,7 +1294,7 @@ public abstract class BaseHapiFhirDao implements IDao, b.append("Unable to delete "); b.append(next.getTargetId().toUnqualifiedVersionless().getValue()); b.append(" because at least one resource has a reference to this resource. First reference found was resource "); - b.append(next.getTargetId().toUnqualifiedVersionless().getValue()); + b.append(next.getSourceId().toUnqualifiedVersionless().getValue()); b.append(" in path "); b.append(next.getSourcePath()); String msg = b.toString(); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4Test.java index 2e26893205e..d0291116fa9 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4Test.java @@ -5,8 +5,8 @@ import ca.uhn.fhir.jpa.dao.BaseHapiFhirResourceDao; import ca.uhn.fhir.jpa.dao.DaoConfig; import ca.uhn.fhir.jpa.dao.IFhirResourceDao; import ca.uhn.fhir.jpa.entity.Search; -import ca.uhn.fhir.jpa.model.search.SearchStatusEnum; import ca.uhn.fhir.jpa.model.entity.*; +import ca.uhn.fhir.jpa.model.search.SearchStatusEnum; import ca.uhn.fhir.jpa.search.SearchCoordinatorSvcImpl; import ca.uhn.fhir.jpa.searchparam.SearchParamConstants; import ca.uhn.fhir.jpa.searchparam.SearchParameterMap; @@ -16,11 +16,12 @@ import ca.uhn.fhir.model.api.ResourceMetadataKeyEnum; import ca.uhn.fhir.model.valueset.BundleEntrySearchModeEnum; import ca.uhn.fhir.model.valueset.BundleEntryTransactionMethodEnum; import ca.uhn.fhir.rest.api.Constants; -import ca.uhn.fhir.rest.api.*; +import ca.uhn.fhir.rest.api.MethodOutcome; +import ca.uhn.fhir.rest.api.SortOrderEnum; +import ca.uhn.fhir.rest.api.SortSpec; import ca.uhn.fhir.rest.api.server.IBundleProvider; import ca.uhn.fhir.rest.param.*; import ca.uhn.fhir.rest.server.exceptions.*; -import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor.ActionRequestDetails; import com.google.common.base.Charsets; import com.google.common.collect.Lists; import org.apache.commons.io.IOUtils; @@ -43,7 +44,6 @@ import org.hl7.fhir.r4.model.OperationOutcome.IssueSeverity; import org.hl7.fhir.r4.model.OperationOutcome.IssueType; import org.hl7.fhir.r4.model.Quantity.QuantityComparator; import org.junit.*; -import org.mockito.ArgumentCaptor; import org.springframework.transaction.TransactionDefinition; import org.springframework.transaction.TransactionStatus; import org.springframework.transaction.support.TransactionCallbackWithoutResult; @@ -57,11 +57,9 @@ import java.util.concurrent.Executors; import java.util.concurrent.Future; import static org.apache.commons.lang3.StringUtils.defaultString; -import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.*; import static org.junit.Assert.*; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.reset; @SuppressWarnings({"unchecked", "deprecation", "Duplicates"}) public class FhirResourceDaoR4Test extends BaseJpaR4Test { @@ -1196,7 +1194,8 @@ public class FhirResourceDaoR4Test extends BaseJpaR4Test { myOrganizationDao.delete(orgId, mySrd); fail(); } catch (ResourceVersionConflictException e) { - assertConflictException(e); + assertConflictException("Patient", e); + ourLog.info("Expected exception thrown: " + e.getMessage()); } myPatientDao.delete(patId, mySrd); @@ -1402,7 +1401,7 @@ public class FhirResourceDaoR4Test extends BaseJpaR4Test { myObservationDao.deleteByUrl("Observation?_has:DiagnosticReport:result:identifier=foo|IDENTIFIER", mySrd); fail(); } catch (ResourceVersionConflictException e) { - assertConflictException(e); + assertConflictException("DiagnosticReport", e); } myObservationDao.read(obs1id); @@ -3874,9 +3873,10 @@ public class FhirResourceDaoR4Test extends BaseJpaR4Test { TestUtil.clearAllStaticFieldsForUnitTest(); } - public static void assertConflictException(ResourceVersionConflictException e) { + public static void assertConflictException(String theResourceType, ResourceVersionConflictException e) { assertThat(e.getMessage(), matchesPattern( - "Unable to delete [a-zA-Z]+/[0-9]+ because at least one resource has a reference to this resource. First reference found was resource [a-zA-Z]+/[0-9]+ in path [a-zA-Z]+.[a-zA-Z]+")); + "Unable to delete [a-zA-Z]+/[0-9]+ because at least one resource has a reference to this resource. First reference found was resource " + theResourceType + "/[0-9]+ in path [a-zA-Z]+.[a-zA-Z]+")); + } private static List toStringList(List theUriType) {