From 7eb86d3eaa0c1d2fbba565b3786180dc43aeb974 Mon Sep 17 00:00:00 2001 From: James Agnew Date: Tue, 5 Sep 2017 19:00:42 -0700 Subject: [PATCH] Work on tests --- ...quireManualActivationInterceptorDstu2.java | 81 +++++++++---------- ...quireManualActivationInterceptorDstu3.java | 76 +++++++++-------- ...sRequireManualActivationInterceptorR4.java | 78 +++++++++--------- .../fhir/jpa/dao/dstu3/BaseJpaDstu3Test.java | 3 +- .../jpa/provider/SubscriptionsDstu2Test.java | 13 +-- .../dstu3/BaseResourceProviderDstu3Test.java | 1 - ...rceProviderCustomSearchParamDstu3Test.java | 2 +- .../dstu3/SubscriptionsDstu3Test.java | 11 ++- ...sourceProviderCustomSearchParamR4Test.java | 2 +- .../jpa/provider/r4/SubscriptionsR4Test.java | 11 ++- 10 files changed, 142 insertions(+), 136 deletions(-) diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/util/SubscriptionsRequireManualActivationInterceptorDstu2.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/util/SubscriptionsRequireManualActivationInterceptorDstu2.java index 0fd3d560a78..b19b1d2fcae 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/util/SubscriptionsRequireManualActivationInterceptorDstu2.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/util/SubscriptionsRequireManualActivationInterceptorDstu2.java @@ -1,5 +1,18 @@ package ca.uhn.fhir.jpa.util; +import ca.uhn.fhir.jpa.dao.IFhirResourceDao; +import ca.uhn.fhir.model.dstu2.resource.Subscription; +import ca.uhn.fhir.model.dstu2.valueset.SubscriptionChannelTypeEnum; +import ca.uhn.fhir.model.dstu2.valueset.SubscriptionStatusEnum; +import ca.uhn.fhir.rest.api.RestOperationTypeEnum; +import ca.uhn.fhir.rest.api.server.RequestDetails; +import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException; +import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; +import ca.uhn.fhir.rest.server.interceptor.ServerOperationInterceptorAdapter; +import org.hl7.fhir.instance.model.api.IBaseResource; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; + import static org.apache.commons.lang3.StringUtils.isNotBlank; /* @@ -11,9 +24,9 @@ import static org.apache.commons.lang3.StringUtils.isNotBlank; * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -22,53 +35,37 @@ import static org.apache.commons.lang3.StringUtils.isNotBlank; * #L% */ -import org.hl7.fhir.instance.model.api.IIdType; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; - -import ca.uhn.fhir.jpa.dao.FhirResourceDaoSubscriptionDstu2; -import ca.uhn.fhir.jpa.dao.IFhirResourceDao; -import ca.uhn.fhir.model.api.ResourceMetadataKeyEnum; -import ca.uhn.fhir.model.dstu2.resource.Subscription; -import ca.uhn.fhir.model.dstu2.valueset.SubscriptionChannelTypeEnum; -import ca.uhn.fhir.model.dstu2.valueset.SubscriptionStatusEnum; -import ca.uhn.fhir.rest.api.RestOperationTypeEnum; -import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException; -import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; -import ca.uhn.fhir.rest.server.interceptor.InterceptorAdapter; - /** * Interceptor which requires newly created {@link Subscription subscriptions} to be in * {@link SubscriptionStatusEnum#REQUESTED} state and prevents clients from changing the status. */ -public class SubscriptionsRequireManualActivationInterceptorDstu2 extends InterceptorAdapter { - - public static final ResourceMetadataKeyEnum ALLOW_STATUS_CHANGE = new AllowStatusChangeMetadata(FhirResourceDaoSubscriptionDstu2.class.getName() + "_ALLOW_STATUS_CHANGE"); +public class SubscriptionsRequireManualActivationInterceptorDstu2 extends ServerOperationInterceptorAdapter { @Autowired - @Qualifier("mySubscriptionDaoDstu2") + @Qualifier("mySubscriptionDaoR4") private IFhirResourceDao myDao; @Override - public void incomingRequestPreHandled(RestOperationTypeEnum theOperation, ActionRequestDetails theProcessedRequest) { - switch (theOperation) { - case CREATE: - case UPDATE: - if (theProcessedRequest.getResourceType().equals("Subscription")) { - verifyStatusOk(theOperation, theProcessedRequest); - } - break; - default: - break; + public void resourceCreated(RequestDetails theRequest, IBaseResource theResource) { + if (myDao.getContext().getResourceDefinition(theResource).getName().equals("Subscription")) { + verifyStatusOk(RestOperationTypeEnum.CREATE, null, theResource); } } + @Override + public void resourceUpdated(RequestDetails theRequest, IBaseResource theOldResource, IBaseResource theNewResource) { + if (myDao.getContext().getResourceDefinition(theNewResource).getName().equals("Subscription")) { + verifyStatusOk(RestOperationTypeEnum.UPDATE, theOldResource, theNewResource); + } + } + + public void setDao(IFhirResourceDao theDao) { myDao = theDao; } - private void verifyStatusOk(RestOperationTypeEnum theOperation, ActionRequestDetails theRequestDetails) { - Subscription subscription = (Subscription) theRequestDetails.getResource(); + private void verifyStatusOk(RestOperationTypeEnum theOperation, IBaseResource theOldResourceOrNull, IBaseResource theResource) { + Subscription subscription = (Subscription) theResource; SubscriptionStatusEnum newStatus = subscription.getStatusElement().getValueAsEnum(); if (newStatus == SubscriptionStatusEnum.REQUESTED || newStatus == SubscriptionStatusEnum.OFF) { @@ -80,24 +77,22 @@ public class SubscriptionsRequireManualActivationInterceptorDstu2 extends Interc throw new UnprocessableEntityException("Can not " + theOperation.getCode() + " resource: Subscription.status must be populated" + ((isNotBlank(actualCode)) ? " (invalid value " + actualCode + ")" : "")); } - IIdType requestId = theRequestDetails.getId(); - if (requestId != null && requestId.hasIdPart()) { - Subscription existing; + if (theOldResourceOrNull != null) { try { - existing = myDao.read(requestId, null); + Subscription existing = (Subscription) theOldResourceOrNull; SubscriptionStatusEnum existingStatus = existing.getStatusElement().getValueAsEnum(); if (existingStatus != newStatus) { - verifyActiveStatus(subscription, newStatus, existingStatus); + verifyActiveStatus(theOperation, subscription, newStatus, existingStatus); } } catch (ResourceNotFoundException e) { - verifyActiveStatus(subscription, newStatus, null); + verifyActiveStatus(theOperation, subscription, newStatus, null); } } else { - verifyActiveStatus(subscription, newStatus, null); + verifyActiveStatus(theOperation, subscription, newStatus, null); } } - private void verifyActiveStatus(Subscription theSubscription, SubscriptionStatusEnum newStatus, SubscriptionStatusEnum theExistingStatus) { + private void verifyActiveStatus(RestOperationTypeEnum theOperation, Subscription theSubscription, SubscriptionStatusEnum newStatus, SubscriptionStatusEnum theExistingStatus) { SubscriptionChannelTypeEnum channelType = theSubscription.getChannel().getTypeElement().getValueAsEnum(); if (channelType == null) { @@ -112,6 +107,10 @@ public class SubscriptionsRequireManualActivationInterceptorDstu2 extends Interc throw new UnprocessableEntityException("Subscription.status can not be changed from " + describeStatus(theExistingStatus) + " to " + describeStatus(newStatus)); } + if (theSubscription.getStatus() == null) { + throw new UnprocessableEntityException("Can not " + theOperation.getCode().toLowerCase() + " resource: Subscription.status must be populated"); + } + throw new UnprocessableEntityException("Subscription.status must be '" + SubscriptionStatusEnum.OFF.getCode() + "' or '" + SubscriptionStatusEnum.REQUESTED.getCode() + "' on a newly created subscription"); } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/util/SubscriptionsRequireManualActivationInterceptorDstu3.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/util/SubscriptionsRequireManualActivationInterceptorDstu3.java index 1e656432a4d..73d96f46525 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/util/SubscriptionsRequireManualActivationInterceptorDstu3.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/util/SubscriptionsRequireManualActivationInterceptorDstu3.java @@ -1,10 +1,19 @@ package ca.uhn.fhir.jpa.util; -import static org.apache.commons.lang3.StringUtils.isNotBlank; - +import ca.uhn.fhir.jpa.dao.IFhirResourceDao; +import ca.uhn.fhir.rest.api.RestOperationTypeEnum; +import ca.uhn.fhir.rest.api.server.RequestDetails; +import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException; +import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; +import ca.uhn.fhir.rest.server.interceptor.ServerOperationInterceptorAdapter; import org.hl7.fhir.dstu3.model.Subscription; import org.hl7.fhir.dstu3.model.Subscription.SubscriptionChannelType; import org.hl7.fhir.dstu3.model.Subscription.SubscriptionStatus; +import org.hl7.fhir.instance.model.api.IBaseResource; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; + +import static org.apache.commons.lang3.StringUtils.isNotBlank; /* * #%L @@ -15,9 +24,9 @@ import org.hl7.fhir.dstu3.model.Subscription.SubscriptionStatus; * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -26,50 +35,37 @@ import org.hl7.fhir.dstu3.model.Subscription.SubscriptionStatus; * #L% */ -import org.hl7.fhir.instance.model.api.IIdType; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; - -import ca.uhn.fhir.jpa.dao.IFhirResourceDao; -import ca.uhn.fhir.jpa.dao.dstu3.FhirResourceDaoSubscriptionDstu3; -import ca.uhn.fhir.model.api.ResourceMetadataKeyEnum; -import ca.uhn.fhir.rest.api.RestOperationTypeEnum; -import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException; -import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; -import ca.uhn.fhir.rest.server.interceptor.InterceptorAdapter; - /** * Interceptor which requires newly created {@link Subscription subscriptions} to be in * {@link SubscriptionStatus#REQUESTED} state and prevents clients from changing the status. */ -public class SubscriptionsRequireManualActivationInterceptorDstu3 extends InterceptorAdapter { +public class SubscriptionsRequireManualActivationInterceptorDstu3 extends ServerOperationInterceptorAdapter { - public static final ResourceMetadataKeyEnum ALLOW_STATUS_CHANGE = new AllowStatusChangeMetadata(FhirResourceDaoSubscriptionDstu3.class.getName() + "_ALLOW_STATUS_CHANGE"); - @Autowired @Qualifier("mySubscriptionDaoDstu3") private IFhirResourceDao myDao; @Override - public void incomingRequestPreHandled(RestOperationTypeEnum theOperation, ActionRequestDetails theProcessedRequest) { - switch (theOperation) { - case CREATE: - case UPDATE: - if (theProcessedRequest.getResourceType().equals("Subscription")) { - verifyStatusOk(theOperation, theProcessedRequest); - } - break; - default: - break; + public void resourceCreated(RequestDetails theRequest, IBaseResource theResource) { + if (myDao.getContext().getResourceDefinition(theResource).getName().equals("Subscription")) { + verifyStatusOk(RestOperationTypeEnum.CREATE, null, theResource); } } + @Override + public void resourceUpdated(RequestDetails theRequest, IBaseResource theOldResource, IBaseResource theNewResource) { + if (myDao.getContext().getResourceDefinition(theNewResource).getName().equals("Subscription")) { + verifyStatusOk(RestOperationTypeEnum.UPDATE, theOldResource, theNewResource); + } + } + + public void setDao(IFhirResourceDao theDao) { myDao = theDao; } - private void verifyStatusOk(RestOperationTypeEnum theOperation, ActionRequestDetails theRequestDetails) { - Subscription subscription = (Subscription) theRequestDetails.getResource(); + private void verifyStatusOk(RestOperationTypeEnum theOperation, IBaseResource theOldResourceOrNull, IBaseResource theResource) { + Subscription subscription = (Subscription) theResource; SubscriptionStatus newStatus = subscription.getStatusElement().getValue(); if (newStatus == SubscriptionStatus.REQUESTED || newStatus == SubscriptionStatus.OFF) { @@ -81,24 +77,22 @@ public class SubscriptionsRequireManualActivationInterceptorDstu3 extends Interc throw new UnprocessableEntityException("Can not " + theOperation.getCode() + " resource: Subscription.status must be populated" + ((isNotBlank(actualCode)) ? " (invalid value " + actualCode + ")" : "")); } - IIdType requestId = theRequestDetails.getId(); - if (requestId != null && requestId.hasIdPart()) { - Subscription existing; + if (theOldResourceOrNull != null) { try { - existing = myDao.read(requestId, null); + Subscription existing = (Subscription) theOldResourceOrNull; SubscriptionStatus existingStatus = existing.getStatusElement().getValue(); if (existingStatus != newStatus) { - verifyActiveStatus(subscription, newStatus, existingStatus); + verifyActiveStatus(theOperation, subscription, newStatus, existingStatus); } } catch (ResourceNotFoundException e) { - verifyActiveStatus(subscription, newStatus, null); + verifyActiveStatus(theOperation, subscription, newStatus, null); } } else { - verifyActiveStatus(subscription, newStatus, null); + verifyActiveStatus(theOperation, subscription, newStatus, null); } } - private void verifyActiveStatus(Subscription theSubscription, SubscriptionStatus newStatus, SubscriptionStatus theExistingStatus) { + private void verifyActiveStatus(RestOperationTypeEnum theOperation, Subscription theSubscription, SubscriptionStatus newStatus, SubscriptionStatus theExistingStatus) { SubscriptionChannelType channelType = theSubscription.getChannel().getTypeElement().getValue(); if (channelType == null) { @@ -113,6 +107,10 @@ public class SubscriptionsRequireManualActivationInterceptorDstu3 extends Interc throw new UnprocessableEntityException("Subscription.status can not be changed from " + describeStatus(theExistingStatus) + " to " + describeStatus(newStatus)); } + if (theSubscription.getStatus() == null) { + throw new UnprocessableEntityException("Can not " + theOperation.getCode().toLowerCase() + " resource: Subscription.status must be populated"); + } + throw new UnprocessableEntityException("Subscription.status must be '" + SubscriptionStatus.OFF.toCode() + "' or '" + SubscriptionStatus.REQUESTED.toCode() + "' on a newly created subscription"); } diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/util/SubscriptionsRequireManualActivationInterceptorR4.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/util/SubscriptionsRequireManualActivationInterceptorR4.java index 2d59775e2b6..1b96227c70a 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/util/SubscriptionsRequireManualActivationInterceptorR4.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/util/SubscriptionsRequireManualActivationInterceptorR4.java @@ -1,5 +1,18 @@ package ca.uhn.fhir.jpa.util; +import ca.uhn.fhir.jpa.dao.IFhirResourceDao; +import ca.uhn.fhir.rest.api.RestOperationTypeEnum; +import ca.uhn.fhir.rest.api.server.RequestDetails; +import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException; +import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; +import ca.uhn.fhir.rest.server.interceptor.ServerOperationInterceptorAdapter; +import org.hl7.fhir.instance.model.api.IBaseResource; +import org.hl7.fhir.r4.model.Subscription; +import org.hl7.fhir.r4.model.Subscription.SubscriptionChannelType; +import org.hl7.fhir.r4.model.Subscription.SubscriptionStatus; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; + import static org.apache.commons.lang3.StringUtils.isNotBlank; /* @@ -11,9 +24,9 @@ import static org.apache.commons.lang3.StringUtils.isNotBlank; * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -22,52 +35,37 @@ import static org.apache.commons.lang3.StringUtils.isNotBlank; * #L% */ -import org.hl7.fhir.instance.model.api.IIdType; -import org.hl7.fhir.r4.model.Subscription; -import org.hl7.fhir.r4.model.Subscription.SubscriptionChannelType; -import org.hl7.fhir.r4.model.Subscription.SubscriptionStatus; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; - -import ca.uhn.fhir.jpa.dao.IFhirResourceDao; -import ca.uhn.fhir.jpa.dao.r4.FhirResourceDaoSubscriptionR4; -import ca.uhn.fhir.model.api.ResourceMetadataKeyEnum; -import ca.uhn.fhir.rest.api.RestOperationTypeEnum; -import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException; -import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; -import ca.uhn.fhir.rest.server.interceptor.InterceptorAdapter; - /** * Interceptor which requires newly created {@link Subscription subscriptions} to be in * {@link SubscriptionStatus#REQUESTED} state and prevents clients from changing the status. */ -public class SubscriptionsRequireManualActivationInterceptorR4 extends InterceptorAdapter { +public class SubscriptionsRequireManualActivationInterceptorR4 extends ServerOperationInterceptorAdapter { - public static final ResourceMetadataKeyEnum ALLOW_STATUS_CHANGE = new AllowStatusChangeMetadata(FhirResourceDaoSubscriptionR4.class.getName() + "_ALLOW_STATUS_CHANGE"); @Autowired @Qualifier("mySubscriptionDaoR4") private IFhirResourceDao myDao; @Override - public void incomingRequestPreHandled(RestOperationTypeEnum theOperation, ActionRequestDetails theProcessedRequest) { - switch (theOperation) { - case CREATE: - case UPDATE: - if (theProcessedRequest.getResourceType().equals("Subscription")) { - verifyStatusOk(theOperation, theProcessedRequest); - } - break; - default: - break; + public void resourceCreated(RequestDetails theRequest, IBaseResource theResource) { + if (myDao.getContext().getResourceDefinition(theResource).getName().equals("Subscription")) { + verifyStatusOk(RestOperationTypeEnum.CREATE, null, theResource); } } + @Override + public void resourceUpdated(RequestDetails theRequest, IBaseResource theOldResource, IBaseResource theNewResource) { + if (myDao.getContext().getResourceDefinition(theNewResource).getName().equals("Subscription")) { + verifyStatusOk(RestOperationTypeEnum.UPDATE, theOldResource, theNewResource); + } + } + + public void setDao(IFhirResourceDao theDao) { myDao = theDao; } - private void verifyStatusOk(RestOperationTypeEnum theOperation, ActionRequestDetails theRequestDetails) { - Subscription subscription = (Subscription) theRequestDetails.getResource(); + private void verifyStatusOk(RestOperationTypeEnum theOperation, IBaseResource theOldResourceOrNull, IBaseResource theResource) { + Subscription subscription = (Subscription) theResource; SubscriptionStatus newStatus = subscription.getStatusElement().getValue(); if (newStatus == SubscriptionStatus.REQUESTED || newStatus == SubscriptionStatus.OFF) { @@ -79,24 +77,22 @@ public class SubscriptionsRequireManualActivationInterceptorR4 extends Intercept throw new UnprocessableEntityException("Can not " + theOperation.getCode() + " resource: Subscription.status must be populated" + ((isNotBlank(actualCode)) ? " (invalid value " + actualCode + ")" : "")); } - IIdType requestId = theRequestDetails.getId(); - if (requestId != null && requestId.hasIdPart()) { - Subscription existing; + if (theOldResourceOrNull != null) { try { - existing = myDao.read(requestId, null); + Subscription existing = (Subscription) theOldResourceOrNull; SubscriptionStatus existingStatus = existing.getStatusElement().getValue(); if (existingStatus != newStatus) { - verifyActiveStatus(subscription, newStatus, existingStatus); + verifyActiveStatus(theOperation, subscription, newStatus, existingStatus); } } catch (ResourceNotFoundException e) { - verifyActiveStatus(subscription, newStatus, null); + verifyActiveStatus(theOperation, subscription, newStatus, null); } } else { - verifyActiveStatus(subscription, newStatus, null); + verifyActiveStatus(theOperation, subscription, newStatus, null); } } - private void verifyActiveStatus(Subscription theSubscription, SubscriptionStatus newStatus, SubscriptionStatus theExistingStatus) { + private void verifyActiveStatus(RestOperationTypeEnum theOperation, Subscription theSubscription, SubscriptionStatus newStatus, SubscriptionStatus theExistingStatus) { SubscriptionChannelType channelType = theSubscription.getChannel().getTypeElement().getValue(); if (channelType == null) { @@ -111,6 +107,10 @@ public class SubscriptionsRequireManualActivationInterceptorR4 extends Intercept throw new UnprocessableEntityException("Subscription.status can not be changed from " + describeStatus(theExistingStatus) + " to " + describeStatus(newStatus)); } + if (theSubscription.getStatus() == null) { + throw new UnprocessableEntityException("Can not " + theOperation.getCode().toLowerCase() + " resource: Subscription.status must be populated"); + } + throw new UnprocessableEntityException("Subscription.status must be '" + SubscriptionStatus.OFF.toCode() + "' or '" + SubscriptionStatus.REQUESTED.toCode() + "' on a newly created subscription"); } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/BaseJpaDstu3Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/BaseJpaDstu3Test.java index 6e21d4d9094..ec4388df2a2 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/BaseJpaDstu3Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/BaseJpaDstu3Test.java @@ -221,6 +221,7 @@ public abstract class BaseJpaDstu3Test extends BaseJpaTest { myDaoConfig.setExpireSearchResultsAfterMillis(new DaoConfig().getExpireSearchResultsAfterMillis()); myDaoConfig.setReuseCachedSearchResultsForMillis(new DaoConfig().getReuseCachedSearchResultsForMillis()); myDaoConfig.setSuppressUpdatesWithNoChange(new DaoConfig().isSuppressUpdatesWithNoChange()); + myDaoConfig.getInterceptors().clear(); } @After() @@ -232,7 +233,7 @@ public abstract class BaseJpaDstu3Test extends BaseJpaTest { @Before public void beforeCreateInterceptor() { myInterceptor = mock(IServerInterceptor.class); - myDaoConfig.setInterceptors(myInterceptor); + myDaoConfig.getInterceptors().add(myInterceptor); } @Before diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/SubscriptionsDstu2Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/SubscriptionsDstu2Test.java index 11911f6f051..31171aa8dcb 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/SubscriptionsDstu2Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/SubscriptionsDstu2Test.java @@ -1,5 +1,6 @@ package ca.uhn.fhir.jpa.provider; +import static org.hamcrest.Matchers.containsString; import static org.junit.Assert.*; import java.net.URI; @@ -131,7 +132,7 @@ public class SubscriptionsDstu2Test extends BaseResourceProviderDstu2Test { ourClient.create().resource(subs).execute(); fail(); } catch (UnprocessableEntityException e) { - assertEquals("HTTP 422 Unprocessable Entity: Can not create resource: Subscription.status must be populated", e.getMessage()); + assertThat(e.getMessage(), containsString("Subscription.status must be populated on this server")); } subs.setId("ABC"); @@ -139,7 +140,7 @@ public class SubscriptionsDstu2Test extends BaseResourceProviderDstu2Test { ourClient.update().resource(subs).execute(); fail(); } catch (UnprocessableEntityException e) { - assertEquals("HTTP 422 Unprocessable Entity: Can not create resource: Subscription.status must be populated", e.getMessage()); + assertThat(e.getMessage(), containsString("Subscription.status must be populated on this server")); } subs.setStatus(SubscriptionStatusEnum.REQUESTED); @@ -168,7 +169,7 @@ public class SubscriptionsDstu2Test extends BaseResourceProviderDstu2Test { ourClient.update().resource(subs).execute(); fail(); } catch (UnprocessableEntityException e) { - assertEquals("HTTP 422 Unprocessable Entity: Can not update resource: Subscription.status must be populated", e.getMessage()); + assertThat(e.getMessage(), containsString("Subscription.status must be populated on this server")); } subs.setStatus(SubscriptionStatusEnum.OFF); @@ -186,7 +187,7 @@ public class SubscriptionsDstu2Test extends BaseResourceProviderDstu2Test { ourClient.create().resource(subs).execute(); fail(); } catch (UnprocessableEntityException e) { - assertEquals("HTTP 422 Unprocessable Entity: Can not create resource: Subscription.status must be populated (invalid value aaaaa)", e.getMessage()); + assertThat(e.getMessage(), containsString("Subscription.status must be populated on this server")); } } @@ -194,6 +195,8 @@ public class SubscriptionsDstu2Test extends BaseResourceProviderDstu2Test { public void testCreateInvalidWrongStatus() { Subscription subs = new Subscription(); subs.getChannel().setType(SubscriptionChannelTypeEnum.REST_HOOK); + subs.getChannel().setPayload("application/fhir+json"); + subs.getChannel().setEndpoint("http://foo"); subs.setStatus(SubscriptionStatusEnum.ACTIVE); subs.setCriteria("Observation?identifier=123"); try { @@ -425,7 +428,7 @@ public class SubscriptionsDstu2Test extends BaseResourceProviderDstu2Test { ourClient.update().resource(subs).execute(); fail(); } catch (UnprocessableEntityException e) { - assertEquals("HTTP 422 Unprocessable Entity: Can not update resource: Subscription.status must be populated", e.getMessage()); + assertThat(e.getMessage(), containsString("Subscription.status must be populated on this server")); } subs.setStatus(SubscriptionStatusEnum.OFF); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/BaseResourceProviderDstu3Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/BaseResourceProviderDstu3Test.java index e19e5bd0c17..1301edb3930 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/BaseResourceProviderDstu3Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/BaseResourceProviderDstu3Test.java @@ -73,7 +73,6 @@ public abstract class BaseResourceProviderDstu3Test extends BaseJpaDstu3Test { myFhirCtx.getRestfulClientFactory().setServerValidationMode(ServerValidationModeEnum.NEVER); myFhirCtx.getRestfulClientFactory().setSocketTimeout(1200 * 1000); myFhirCtx.setParserErrorHandler(new StrictErrorHandler()); - myDaoConfig.getInterceptors().clear(); if (ourServer == null) { ourPort = PortUtil.findFreePort(); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderCustomSearchParamDstu3Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderCustomSearchParamDstu3Test.java index 6886524df4e..7b59d34ca37 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderCustomSearchParamDstu3Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderCustomSearchParamDstu3Test.java @@ -381,7 +381,7 @@ public class ResourceProviderCustomSearchParamDstu3Test extends BaseResourceProv public void testSearchQualifiedWithCustomReferenceParam() { SearchParameter fooSp = new SearchParameter(); - fooSp.addBase("Patient"); + fooSp.addBase("Observation"); fooSp.setCode("foo"); fooSp.setType(org.hl7.fhir.dstu3.model.Enumerations.SearchParamType.REFERENCE); fooSp.setTitle("FOO SP"); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/SubscriptionsDstu3Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/SubscriptionsDstu3Test.java index 971cb72ba44..1c5761741ed 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/SubscriptionsDstu3Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/SubscriptionsDstu3Test.java @@ -1,5 +1,6 @@ package ca.uhn.fhir.jpa.provider.dstu3; +import static org.hamcrest.Matchers.containsString; import static org.junit.Assert.*; import java.net.URI; @@ -122,7 +123,7 @@ public class SubscriptionsDstu3Test extends BaseResourceProviderDstu3Test { ourClient.create().resource(subs).execute(); fail(); } catch (UnprocessableEntityException e) { - assertEquals("HTTP 422 Unprocessable Entity: Can not create resource: Subscription.status must be populated", e.getMessage()); + assertThat(e.getMessage(), containsString("Subscription.status must be populated on this server")); } subs.setId("ABC"); @@ -130,7 +131,7 @@ public class SubscriptionsDstu3Test extends BaseResourceProviderDstu3Test { ourClient.update().resource(subs).execute(); fail(); } catch (UnprocessableEntityException e) { - assertEquals("HTTP 422 Unprocessable Entity: Can not create resource: Subscription.status must be populated", e.getMessage()); + assertThat(e.getMessage(), containsString("Subscription.status must be populated on this server")); } subs.setStatus(SubscriptionStatus.REQUESTED); @@ -141,6 +142,8 @@ public class SubscriptionsDstu3Test extends BaseResourceProviderDstu3Test { public void testCreateInvalidWrongStatus() { Subscription subs = new Subscription(); subs.getChannel().setType(SubscriptionChannelType.RESTHOOK); + subs.getChannel().setPayload("application/fhir+json"); + subs.getChannel().setEndpoint("http://foo"); subs.setStatus(SubscriptionStatus.ACTIVE); subs.setCriteria("Observation?identifier=123"); try { @@ -375,7 +378,7 @@ public class SubscriptionsDstu3Test extends BaseResourceProviderDstu3Test { ourClient.update().resource(subs).execute(); fail(); } catch (UnprocessableEntityException e) { - assertEquals("HTTP 422 Unprocessable Entity: Can not update resource: Subscription.status must be populated", e.getMessage()); + assertThat(e.getMessage(), containsString("Subscription.status must be populated on this server")); } subs.setStatus(SubscriptionStatus.OFF); @@ -406,7 +409,7 @@ public class SubscriptionsDstu3Test extends BaseResourceProviderDstu3Test { ourClient.update().resource(subs).execute(); fail(); } catch (UnprocessableEntityException e) { - assertEquals("HTTP 422 Unprocessable Entity: Can not update resource: Subscription.status must be populated", e.getMessage()); + assertThat(e.getMessage(), containsString("Subscription.status must be populated on this server")); } subs.setStatus(SubscriptionStatus.OFF); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderCustomSearchParamR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderCustomSearchParamR4Test.java index c1484e1e0d8..c0bfdc29769 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderCustomSearchParamR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderCustomSearchParamR4Test.java @@ -381,7 +381,7 @@ public class ResourceProviderCustomSearchParamR4Test extends BaseResourceProvide public void testSearchQualifiedWithCustomReferenceParam() { SearchParameter fooSp = new SearchParameter(); - fooSp.addBase("Patient"); + fooSp.addBase("Observation"); fooSp.setCode("foo"); fooSp.setType(org.hl7.fhir.r4.model.Enumerations.SearchParamType.REFERENCE); fooSp.setTitle("FOO SP"); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/SubscriptionsR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/SubscriptionsR4Test.java index df5cdcafbac..5b15640708c 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/SubscriptionsR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/SubscriptionsR4Test.java @@ -1,5 +1,6 @@ package ca.uhn.fhir.jpa.provider.r4; +import static org.hamcrest.Matchers.containsString; import static org.junit.Assert.*; import java.net.URI; @@ -122,7 +123,7 @@ public class SubscriptionsR4Test extends BaseResourceProviderR4Test { ourClient.create().resource(subs).execute(); fail(); } catch (UnprocessableEntityException e) { - assertEquals("HTTP 422 Unprocessable Entity: Can not create resource: Subscription.status must be populated", e.getMessage()); + assertThat(e.getMessage(), containsString("Subscription.status must be populated on this server")); } subs.setId("ABC"); @@ -130,7 +131,7 @@ public class SubscriptionsR4Test extends BaseResourceProviderR4Test { ourClient.update().resource(subs).execute(); fail(); } catch (UnprocessableEntityException e) { - assertEquals("HTTP 422 Unprocessable Entity: Can not create resource: Subscription.status must be populated", e.getMessage()); + assertThat(e.getMessage(), containsString("Subscription.status must be populated on this server")); } subs.setStatus(SubscriptionStatus.REQUESTED); @@ -141,6 +142,8 @@ public class SubscriptionsR4Test extends BaseResourceProviderR4Test { public void testCreateInvalidWrongStatus() { Subscription subs = new Subscription(); subs.getChannel().setType(SubscriptionChannelType.RESTHOOK); + subs.getChannel().setPayload("application/fhir+json"); + subs.getChannel().setEndpoint("http://foo"); subs.setStatus(SubscriptionStatus.ACTIVE); subs.setCriteria("Observation?identifier=123"); try { @@ -375,7 +378,7 @@ public class SubscriptionsR4Test extends BaseResourceProviderR4Test { ourClient.update().resource(subs).execute(); fail(); } catch (UnprocessableEntityException e) { - assertEquals("HTTP 422 Unprocessable Entity: Can not update resource: Subscription.status must be populated", e.getMessage()); + assertThat(e.getMessage(), containsString("Subscription.status must be populated on this server")); } subs.setStatus(SubscriptionStatus.OFF); @@ -406,7 +409,7 @@ public class SubscriptionsR4Test extends BaseResourceProviderR4Test { ourClient.update().resource(subs).execute(); fail(); } catch (UnprocessableEntityException e) { - assertEquals("HTTP 422 Unprocessable Entity: Can not update resource: Subscription.status must be populated", e.getMessage()); + assertThat(e.getMessage(), containsString("Subscription.status must be populated on this server")); } subs.setStatus(SubscriptionStatus.OFF);