diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/BaseOutcomeReturningMethodBindingWithResourceParam.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/BaseOutcomeReturningMethodBindingWithResourceParam.java index 8fb5596995b..5b2fdcf569c 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/BaseOutcomeReturningMethodBindingWithResourceParam.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/BaseOutcomeReturningMethodBindingWithResourceParam.java @@ -1,7 +1,6 @@ package ca.uhn.fhir.rest.method; import static org.apache.commons.lang3.StringUtils.defaultIfBlank; -import static org.apache.commons.lang3.StringUtils.isBlank; /* * #%L @@ -38,7 +37,6 @@ import ca.uhn.fhir.rest.client.BaseHttpClientInvocation; import ca.uhn.fhir.rest.param.ResourceParameter; import ca.uhn.fhir.rest.server.IResourceProvider; import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; -import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor.ActionRequestDetails; abstract class BaseOutcomeReturningMethodBindingWithResourceParam extends BaseOutcomeReturningMethodBinding { @@ -111,7 +109,7 @@ abstract class BaseOutcomeReturningMethodBindingWithResourceParam extends BaseOu matchUrl = (String) theParams[myConditionalUrlIndex]; matchUrl = defaultIfBlank(matchUrl, null); } - validateResourceIdAndUrlIdForNonConditionalOperation(resourceId, urlId, matchUrl); + validateResourceIdAndUrlIdForNonConditionalOperation(resource, resourceId, urlId, matchUrl); } } } @@ -151,7 +149,7 @@ abstract class BaseOutcomeReturningMethodBindingWithResourceParam extends BaseOu * Subclasses may override */ @SuppressWarnings("unused") - protected void validateResourceIdAndUrlIdForNonConditionalOperation(String theResourceId, String theUrlId, String theMatchUrl) { + protected void validateResourceIdAndUrlIdForNonConditionalOperation(IBaseResource theResource, String theResourceId, String theUrlId, String theMatchUrl) { // nothing by default } diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/BaseResourceReturningMethodBinding.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/BaseResourceReturningMethodBinding.java index cec3bcc5d98..1bce71df52a 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/BaseResourceReturningMethodBinding.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/BaseResourceReturningMethodBinding.java @@ -32,8 +32,8 @@ import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; -import java.util.Map.Entry; import java.util.Set; +import java.util.TreeSet; import org.hl7.fhir.instance.model.api.IBaseBundle; import org.hl7.fhir.instance.model.api.IBaseResource; @@ -318,15 +318,15 @@ public abstract class BaseResourceReturningMethodBinding extends BaseMethodBindi if (theRequest.getRequestType() == RequestTypeEnum.GET) { boolean first = true; Map parameters = theRequest.getParameters(); - for (Entry nextParams : parameters.entrySet()) { - for (String nextParamValue : nextParams.getValue()) { + for (String nextParamName : new TreeSet(parameters.keySet())) { + for (String nextParamValue : parameters.get(nextParamName)) { if (first) { b.append('?'); first = false; } else { b.append('&'); } - b.append(UrlUtil.escape(nextParams.getKey())); + b.append(UrlUtil.escape(nextParamName)); b.append('='); b.append(UrlUtil.escape(nextParamValue)); } diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/CreateMethodBinding.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/CreateMethodBinding.java index 9849b6b9389..de189c87b08 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/CreateMethodBinding.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/CreateMethodBinding.java @@ -26,6 +26,8 @@ import java.lang.reflect.Method; import java.util.Collections; import java.util.Set; +import org.hl7.fhir.instance.model.api.IBaseResource; + import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.rest.annotation.Create; @@ -72,7 +74,7 @@ public class CreateMethodBinding extends BaseOutcomeReturningMethodBindingWithRe } @Override - protected void validateResourceIdAndUrlIdForNonConditionalOperation(String theResourceId, String theUrlId, String theMatchUrl) { + protected void validateResourceIdAndUrlIdForNonConditionalOperation(IBaseResource theResource, String theResourceId, String theUrlId, String theMatchUrl) { if (isNotBlank(theUrlId)) { String msg = getContext().getLocalizer().getMessage(BaseOutcomeReturningMethodBindingWithResourceParam.class, "idInUrlForCreate", theUrlId); throw new InvalidRequestException(msg); diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/UpdateMethodBinding.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/UpdateMethodBinding.java index 2908fe986c4..77bca6ce840 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/UpdateMethodBinding.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/UpdateMethodBinding.java @@ -26,6 +26,7 @@ import java.lang.reflect.Method; import java.util.Collections; import java.util.Set; +import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IIdType; import ca.uhn.fhir.context.FhirContext; @@ -133,21 +134,22 @@ public class UpdateMethodBinding extends BaseOutcomeReturningMethodBindingWithRe } @Override - protected void validateResourceIdAndUrlIdForNonConditionalOperation(String theResourceId, String theUrlId, String theMatchUrl) { + protected void validateResourceIdAndUrlIdForNonConditionalOperation(IBaseResource theResource, String theResourceId, String theUrlId, String theMatchUrl) { if (isBlank(theMatchUrl)) { + if (isBlank(theUrlId)) { + String msg = getContext().getLocalizer().getMessage(BaseOutcomeReturningMethodBindingWithResourceParam.class, "noIdInUrlForUpdate"); + throw new InvalidRequestException(msg); + } if (isBlank(theResourceId)) { // String msg = getContext().getLocalizer().getMessage(BaseOutcomeReturningMethodBindingWithResourceParam.class, "noIdInBodyForUpdate"); ourLog.warn("No resource ID found in resource body for update"); + theResource.setId(theUrlId); } else { if (!theResourceId.equals(theUrlId)) { String msg = getContext().getLocalizer().getMessage(BaseOutcomeReturningMethodBindingWithResourceParam.class, "incorrectIdForUpdate", theResourceId, theUrlId); throw new InvalidRequestException(msg); } } - if (isBlank(theUrlId)) { - String msg = getContext().getLocalizer().getMessage(BaseOutcomeReturningMethodBindingWithResourceParam.class, "noIdInUrlForUpdate"); - throw new InvalidRequestException(msg); - } } } diff --git a/hapi-fhir-base/src/main/resources/ca/uhn/fhir/i18n/hapi-messages.properties b/hapi-fhir-base/src/main/resources/ca/uhn/fhir/i18n/hapi-messages.properties index 832b8bd0a4c..4de5b4b5e50 100644 --- a/hapi-fhir-base/src/main/resources/ca/uhn/fhir/i18n/hapi-messages.properties +++ b/hapi-fhir-base/src/main/resources/ca/uhn/fhir/i18n/hapi-messages.properties @@ -76,4 +76,4 @@ ca.uhn.fhir.jpa.dao.BaseHapiFhirResourceDao.successfulUpdate=Successfully update ca.uhn.fhir.jpa.dao.SearchBuilder.invalidQuantityPrefix=Unable to handle quantity prefix "{0}" for value: {1} ca.uhn.fhir.jpa.dao.SearchBuilder.invalidNumberPrefix=Unable to handle number prefix "{0}" for value: {1} -ca.uhn.fhir.jpa.term.TerminologySvcImpl.cannotCreateDuplicateCodeSystemUri=Can not create multiple code systems with URI "{0}", already have one with resource ID: {1} \ No newline at end of file +ca.uhn.fhir.jpa.term.HapiTerminologySvcImpl.cannotCreateDuplicateCodeSystemUri=Can not create multiple code systems with URI "{0}", already have one with resource ID: {1} \ No newline at end of file diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/config/BaseConfig.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/config/BaseConfig.java index 94755cc43b7..8880b6d5169 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/config/BaseConfig.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/config/BaseConfig.java @@ -1,9 +1,5 @@ package ca.uhn.fhir.jpa.config; -import java.util.concurrent.RejectedExecutionHandler; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.ThreadFactory; - /* * #%L * HAPI FHIR JPA Server @@ -40,14 +36,13 @@ import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.SchedulingConfigurer; import org.springframework.scheduling.concurrent.ConcurrentTaskScheduler; import org.springframework.scheduling.concurrent.ScheduledExecutorFactoryBean; -import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; import org.springframework.scheduling.config.ScheduledTaskRegistrar; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.jpa.search.DatabaseBackedPagingProvider; import ca.uhn.fhir.jpa.search.StaleSearchDeletingSvc; -import ca.uhn.fhir.jpa.term.ITerminologySvc; -import ca.uhn.fhir.jpa.term.TerminologySvcImpl; +import ca.uhn.fhir.jpa.term.HapiTerminologySvcImpl; +import ca.uhn.fhir.jpa.term.IHapiTerminologySvc; @Configuration @EnableScheduling @@ -135,8 +130,8 @@ public class BaseConfig implements SchedulingConfigurer { } @Bean(autowire = Autowire.BY_TYPE) - public ITerminologySvc terminologyService() { - return new TerminologySvcImpl(); + public IHapiTerminologySvc terminologyService() { + return new HapiTerminologySvcImpl(); } // @PostConstruct diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirResourceDao.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirResourceDao.java index 44fbc90a0fe..43a5c563e1d 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirResourceDao.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirResourceDao.java @@ -65,7 +65,7 @@ import ca.uhn.fhir.jpa.entity.ResourceTable; import ca.uhn.fhir.jpa.entity.TagDefinition; import ca.uhn.fhir.jpa.entity.TagTypeEnum; import ca.uhn.fhir.jpa.interceptor.IJpaServerInterceptor; -import ca.uhn.fhir.jpa.term.ITerminologySvc; +import ca.uhn.fhir.jpa.term.IHapiTerminologySvc; import ca.uhn.fhir.jpa.util.DeleteConflict; import ca.uhn.fhir.jpa.util.StopWatch; import ca.uhn.fhir.model.api.IQueryParameterType; @@ -77,7 +77,6 @@ import ca.uhn.fhir.model.primitive.IdDt; import ca.uhn.fhir.rest.api.RestOperationTypeEnum; import ca.uhn.fhir.rest.method.RequestDetails; import ca.uhn.fhir.rest.method.RestSearchParameterTypeEnum; -import ca.uhn.fhir.rest.param.DateRangeParam; import ca.uhn.fhir.rest.server.IBundleProvider; import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; @@ -111,7 +110,7 @@ public abstract class BaseHapiFhirResourceDao extends B @Autowired() protected IResourceIndexedSearchParamUriDao myResourceIndexedSearchParamUriDao; @Autowired() - protected ITerminologySvc myTerminologySvc; + protected IHapiTerminologySvc myTerminologySvc; private String mySecondaryPrimaryKeyParamName; @@ -986,7 +985,6 @@ public abstract class BaseHapiFhirResourceDao extends B /* Note: resourcdeId will not be null or empty here, because * we check it and reject requests in BaseOutcomeReturningMethodBindingWithResourceParam */ - // resourceId = theResource.getIdElement(); try { diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/SearchBuilder.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/SearchBuilder.java index b85ecbeebcd..d1dc23fb2a2 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/SearchBuilder.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/SearchBuilder.java @@ -28,7 +28,6 @@ import static org.apache.commons.lang3.StringUtils.isNotBlank; import java.math.BigDecimal; import java.math.MathContext; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Date; @@ -63,7 +62,6 @@ import org.apache.commons.lang3.tuple.Pair; import org.hl7.fhir.instance.model.api.IAnyResource; import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IIdType; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.TransactionStatus; import org.springframework.transaction.support.TransactionCallback; @@ -101,7 +99,7 @@ import ca.uhn.fhir.jpa.entity.TagDefinition; import ca.uhn.fhir.jpa.entity.TagTypeEnum; import ca.uhn.fhir.jpa.entity.TermConcept; import ca.uhn.fhir.jpa.search.PersistedJpaBundleProvider; -import ca.uhn.fhir.jpa.term.ITerminologySvc; +import ca.uhn.fhir.jpa.term.IHapiTerminologySvc; import ca.uhn.fhir.jpa.util.StopWatch; import ca.uhn.fhir.model.api.IPrimitiveDatatype; import ca.uhn.fhir.model.api.IQueryParameterType; @@ -122,8 +120,6 @@ import ca.uhn.fhir.rest.method.RestSearchParameterTypeEnum; import ca.uhn.fhir.rest.param.CompositeParam; import ca.uhn.fhir.rest.param.DateParam; import ca.uhn.fhir.rest.param.DateRangeParam; -import ca.uhn.fhir.rest.param.HasAndListParam; -import ca.uhn.fhir.rest.param.HasOrListParam; import ca.uhn.fhir.rest.param.HasParam; import ca.uhn.fhir.rest.param.NumberParam; import ca.uhn.fhir.rest.param.ParamPrefixEnum; @@ -158,10 +154,10 @@ public class SearchBuilder { private IFulltextSearchSvc mySearchDao; private Search mySearchEntity; private ISearchResultDao mySearchResultDao; - private ITerminologySvc myTerminologySvc; + private IHapiTerminologySvc myTerminologySvc; public SearchBuilder(FhirContext theFhirContext, EntityManager theEntityManager, PlatformTransactionManager thePlatformTransactionManager, IFulltextSearchSvc theSearchDao, - ISearchResultDao theSearchResultDao, BaseHapiFhirDao theDao, IResourceIndexedSearchParamUriDao theResourceIndexedSearchParamUriDao, IForcedIdDao theForcedIdDao, ITerminologySvc theTerminologySvc) { + ISearchResultDao theSearchResultDao, BaseHapiFhirDao theDao, IResourceIndexedSearchParamUriDao theResourceIndexedSearchParamUriDao, IForcedIdDao theForcedIdDao, IHapiTerminologySvc theTerminologySvc) { myContext = theFhirContext; myEntityManager = theEntityManager; myPlatformTransactionManager = thePlatformTransactionManager; diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoCodeSystemDstu3.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoCodeSystemDstu3.java index c59bb35da45..5b58e02609f 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoCodeSystemDstu3.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoCodeSystemDstu3.java @@ -48,7 +48,7 @@ import ca.uhn.fhir.jpa.dao.IFhirResourceDaoCodeSystem; import ca.uhn.fhir.jpa.entity.ResourceTable; import ca.uhn.fhir.jpa.entity.TermCodeSystemVersion; import ca.uhn.fhir.jpa.entity.TermConcept; -import ca.uhn.fhir.jpa.term.ITerminologySvc; +import ca.uhn.fhir.jpa.term.IHapiTerminologySvc; import ca.uhn.fhir.jpa.util.LogicUtil; import ca.uhn.fhir.rest.method.RequestDetails; import ca.uhn.fhir.rest.param.TokenParam; @@ -60,7 +60,7 @@ public class FhirResourceDaoCodeSystemDstu3 extends FhirResourceDaoDstu3 findCodesAbove(Long theCodeSystemResourcePid, Long theCodeSystemResourceVersionPid, String theCode); 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 34634cc7ced..e19a217cf39 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 @@ -73,7 +73,7 @@ import ca.uhn.fhir.jpa.entity.ResourceIndexedSearchParamString; import ca.uhn.fhir.jpa.entity.ResourceTable; import ca.uhn.fhir.jpa.provider.dstu3.JpaSystemProviderDstu3; import ca.uhn.fhir.jpa.search.StaleSearchDeletingSvc; -import ca.uhn.fhir.jpa.term.ITerminologySvc; +import ca.uhn.fhir.jpa.term.IHapiTerminologySvc; import ca.uhn.fhir.jpa.validation.JpaValidationSupportChainDstu3; import ca.uhn.fhir.parser.IParser; import ca.uhn.fhir.rest.method.MethodUtil; @@ -198,7 +198,7 @@ public abstract class BaseJpaDstu3Test extends BaseJpaTest { @Qualifier("mySystemProviderDstu3") protected JpaSystemProviderDstu3 mySystemProvider; @Autowired - protected ITerminologySvc myTermSvc; + protected IHapiTerminologySvc myTermSvc; @Autowired protected PlatformTransactionManager myTxManager; @Autowired diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3SearchNoFtTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3SearchNoFtTest.java index fd9e3b0aa45..8cff2ac6c67 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3SearchNoFtTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3SearchNoFtTest.java @@ -617,7 +617,7 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { Observation o2 = new Observation(); o2.getCode().addCoding().setSystem("foo").setCode("testSearchCompositeParamDateN01"); - o1.setValue(new Period().setStartElement(new DateTimeType("2001-01-02T11:11:11")).setEndElement(new DateTimeType("2001-01-02T12:11:11"))); + o2.setValue(new Period().setStartElement(new DateTimeType("2001-01-02T11:11:11")).setEndElement(new DateTimeType("2001-01-02T12:11:11"))); IIdType id2 = myObservationDao.create(o2, mySrd).getId().toUnqualifiedVersionless(); { @@ -625,18 +625,29 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { DateParam v1 = new DateParam("2001-01-01"); CompositeParam val = new CompositeParam(v0, v1); IBundleProvider result = myObservationDao.search(Observation.SP_CODE_VALUE_DATE, val); - assertEquals(1, result.size()); - assertEquals(id1.toUnqualifiedVersionless(), result.getResources(0, 1).get(0).getIdElement().toUnqualifiedVersionless()); + assertThat(toUnqualifiedVersionlessIds(result), containsInAnyOrder(id1)); } { TokenParam v0 = new TokenParam("foo", "testSearchCompositeParamDateN01"); - // TODO: this should also work with ">2001-01-01T15:12:12" since the two times only have a lower bound DateParam v1 = new DateParam(">2001-01-01T10:12:12"); CompositeParam val = new CompositeParam(v0, v1); IBundleProvider result = myObservationDao.search(Observation.SP_CODE_VALUE_DATE, val); - assertEquals(2, result.size()); assertThat(toUnqualifiedVersionlessIds(result), containsInAnyOrder(id1, id2)); } + { + TokenParam v0 = new TokenParam("foo", "testSearchCompositeParamDateN01"); + DateParam v1 = new DateParam("gt2001-01-01T11:12:12"); + CompositeParam val = new CompositeParam(v0, v1); + IBundleProvider result = myObservationDao.search(Observation.SP_CODE_VALUE_DATE, val); + assertThat(toUnqualifiedVersionlessIds(result), containsInAnyOrder(id1, id2)); + } + { + TokenParam v0 = new TokenParam("foo", "testSearchCompositeParamDateN01"); + DateParam v1 = new DateParam("gt2001-01-01T15:12:12"); + CompositeParam val = new CompositeParam(v0, v1); + IBundleProvider result = myObservationDao.search(Observation.SP_CODE_VALUE_DATE, val); + assertThat(toUnqualifiedVersionlessIds(result), containsInAnyOrder(id2)); + } } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirSystemDaoDstu3Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirSystemDaoDstu3Test.java index d0639250319..e2c328e761d 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirSystemDaoDstu3Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirSystemDaoDstu3Test.java @@ -4,6 +4,7 @@ import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.emptyString; import static org.hamcrest.Matchers.endsWith; import static org.hamcrest.Matchers.greaterThan; +import static org.hamcrest.Matchers.matchesPattern; import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.startsWith; import static org.junit.Assert.assertEquals; @@ -17,7 +18,6 @@ import static org.mockito.Matchers.eq; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; -import java.io.IOException; import java.io.InputStream; import java.io.UnsupportedEncodingException; import java.util.List; @@ -88,7 +88,7 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest { ourLog.info(myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(response)); assertEquals("201 Created", response.getEntryFirstRep().getResponse().getStatus()); - assertEquals("Practitioner/1/_history/1", response.getEntryFirstRep().getResponse().getLocation()); + assertThat(response.getEntryFirstRep().getResponse().getLocation(), matchesPattern("Practitioner/[0-9]+/_history/1")); /* * Now a second time @@ -99,7 +99,7 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest { ourLog.info(myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(response)); assertEquals("200 OK", response.getEntryFirstRep().getResponse().getStatus()); - assertEquals("Practitioner/1/_history/1", response.getEntryFirstRep().getResponse().getLocation()); + assertThat(response.getEntryFirstRep().getResponse().getLocation(), matchesPattern("Practitioner/[0-9]+/_history/1")); } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderDstu3Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderDstu3Test.java index 882ee32e55a..ee7c7ba5ed7 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderDstu3Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderDstu3Test.java @@ -241,8 +241,13 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test { String output = IOUtils.toString(resp.getEntity().getContent()); ourLog.info(output); - assertThat(output, containsString("")); - assertThat(output, containsString("")); + Bundle b = myFhirCtx.newXmlParser().parseResource(Bundle.class, output); + + assertEquals("http://localhost:" + ourPort + "/fhir/context/Patient?_count=5&_pretty=true&name=Jernel%C3%B6v", b.getLink("self").getUrl()); + + Patient p = (Patient) b.getEntryFirstRep().getResource(); + assertEquals("Jernelöv", p.getNameFirstRep().getFamilyFirstRep().getValue()); + } finally { IOUtils.closeQuietly(resp.getEntity().getContent()); } @@ -2316,7 +2321,7 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test { ourLog.info(responseString); assertEquals(400, response.getStatusLine().getStatusCode()); OperationOutcome oo = myFhirCtx.newXmlParser().parseResource(OperationOutcome.class, responseString); - assertThat(oo.getIssue().get(0).getDiagnostics(), containsString("Can not update resource, resource body must contain an ID element for update (PUT) operation")); + assertThat(oo.getIssue().get(0).getDiagnostics(), containsString("Can not update resource, request URL must contain an ID element for update (PUT) operation (it must be of the form [base]/[resource type]/[id])")); } finally { response.close(); } @@ -2345,7 +2350,11 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test { } } + /** + * This does not currently cause an error, so this test is disabled + */ @Test + @Ignore public void testUpdateNoIdInBody() throws IOException, Exception { String methodName = "testUpdateNoIdInBody"; @@ -2353,13 +2362,13 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test { pt.addName().addFamily(methodName); String resource = myFhirCtx.newXmlParser().encodeResourceToString(pt); - HttpPut post = new HttpPut(ourServerBase + "/Patient/2"); + HttpPut post = new HttpPut(ourServerBase + "/Patient/FOO"); post.setEntity(new StringEntity(resource, ContentType.create(Constants.CT_FHIR_XML, "UTF-8"))); CloseableHttpResponse response = ourHttpClient.execute(post); try { String responseString = IOUtils.toString(response.getEntity().getContent()); ourLog.info(responseString); - assertThat(responseString, containsString("Can not update resource, resource body must contain an ID element for update (PUT) operation")); + assertThat(responseString, containsString("Can not update resource, request URL must contain an ID element for update (PUT) operation (it must be of the form [base]/[resource type]/[id])")); assertThat(responseString, containsString("