Work on tests

This commit is contained in:
James Agnew 2017-09-05 19:00:42 -07:00
parent c32e8d42b3
commit 7eb86d3eaa
10 changed files with 142 additions and 136 deletions

View File

@ -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<Object> ALLOW_STATUS_CHANGE = new AllowStatusChangeMetadata(FhirResourceDaoSubscriptionDstu2.class.getName() + "_ALLOW_STATUS_CHANGE");
public class SubscriptionsRequireManualActivationInterceptorDstu2 extends ServerOperationInterceptorAdapter {
@Autowired
@Qualifier("mySubscriptionDaoDstu2")
@Qualifier("mySubscriptionDaoR4")
private IFhirResourceDao<Subscription> 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<Subscription> 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");
}

View File

@ -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<Object> ALLOW_STATUS_CHANGE = new AllowStatusChangeMetadata(FhirResourceDaoSubscriptionDstu3.class.getName() + "_ALLOW_STATUS_CHANGE");
@Autowired
@Qualifier("mySubscriptionDaoDstu3")
private IFhirResourceDao<Subscription> 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<Subscription> 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");
}

View File

@ -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<Object> ALLOW_STATUS_CHANGE = new AllowStatusChangeMetadata(FhirResourceDaoSubscriptionR4.class.getName() + "_ALLOW_STATUS_CHANGE");
@Autowired
@Qualifier("mySubscriptionDaoR4")
private IFhirResourceDao<Subscription> 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<Subscription> 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");
}

View File

@ -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

View File

@ -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);

View File

@ -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();

View File

@ -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");

View File

@ -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);

View File

@ -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");

View File

@ -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);