From 9cf64f78d023e3e9643cd801492e4857e856af19 Mon Sep 17 00:00:00 2001 From: James Agnew Date: Mon, 21 Jan 2019 14:46:17 -0500 Subject: [PATCH] Deprecate a bad setter on RetfulServer, fix a paging issue, and add a disabled unit test to the subscription matcher --- .../provider/r4/ResourceProviderR4Test.java | 28 +++++++++++++++++++ .../InMemorySubscriptionMatcherTestR3.java | 20 +++++++++++++ .../uhn/fhir/rest/server/RestfulServer.java | 14 ++++++++++ .../rest/server/method/PageMethodBinding.java | 2 +- .../fhir/rest/server/GraphQLR4RawTest.java | 3 +- .../uhn/fhir/rest/server/HistoryR4Test.java | 3 +- src/changes/changes.xml | 7 +++++ 7 files changed, 73 insertions(+), 4 deletions(-) diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4Test.java index 72f422b8a8b..4a4cddfa7e7 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4Test.java @@ -198,6 +198,34 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { } + @Test + public void testSearchFetchPageBeyondEnd() { + for (int i = 0; i < 10; i++) { + Organization o = new Organization(); + o.setId("O" + i); + o.setName("O" + i); + IIdType oid = ourClient.update().resource(o).execute().getId().toUnqualifiedVersionless(); + } + + Bundle output = ourClient + .search() + .forResource("Organization") + .count(3) + .returnBundle(Bundle.class) + .execute(); + + String nextPageUrl = output.getLink("next").getUrl(); + String url = nextPageUrl.replace("_getpagesoffset=3", "_getpagesoffset=999"); + ourLog.info("Going to request URL: {}", url); + + output = ourClient + .loadPage() + .byUrl(url) + .andReturnBundle(Bundle.class) + .execute(); + assertEquals(0, output.getEntry().size()); + + } @Test public void testDeleteConditional() { diff --git a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/matcher/InMemorySubscriptionMatcherTestR3.java b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/matcher/InMemorySubscriptionMatcherTestR3.java index 0e004ee603e..eb0706b2001 100644 --- a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/matcher/InMemorySubscriptionMatcherTestR3.java +++ b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/matcher/InMemorySubscriptionMatcherTestR3.java @@ -7,6 +7,7 @@ import org.hl7.fhir.dstu3.model.*; import org.hl7.fhir.dstu3.model.codesystems.MedicationRequestCategory; import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IIdType; +import org.junit.Ignore; import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -37,6 +38,25 @@ public class InMemorySubscriptionMatcherTestR3 extends BaseSubscriptionDstu3Test assertFalse(result.matched()); } + @Test + @Ignore + public void testResourceById() { + + ProcedureRequest pr = new ProcedureRequest(); + pr.setId("ProcedureRequest/123"); + pr.setIntent(ProcedureRequest.ProcedureRequestIntent.ORIGINALORDER); + + assertMatched(pr, "ProcedureRequest?_id=123"); + assertMatched(pr, "ProcedureRequest?_id=Patient/123"); + assertMatched(pr, "ProcedureRequest?_id=Patient/123,Patient/999"); + assertMatched(pr, "ProcedureRequest?_id=Patient/123&_id=Patient/123"); + assertNotMatched(pr, "ProcedureRequest?_id=Patient/888"); + assertNotMatched(pr, "ProcedureRequest?_id=Patient/888,Patient/999"); + assertNotMatched(pr, "ProcedureRequest?_id=Patient/123&_id=Patient/888"); + + } + + /* The following tests are copied from an e-mail from a site using HAPI FHIR */ diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/RestfulServer.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/RestfulServer.java index b825207ad85..99f5d50544b 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/RestfulServer.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/RestfulServer.java @@ -599,7 +599,9 @@ public class RestfulServer extends HttpServlet implements IRestfulServer theProviders) { Validate.noNullElements(theProviders, "theProviders must not contain any null elements"); @@ -1359,6 +1363,16 @@ public class RestfulServer extends HttpServlet implements IRestfulServer + + When fetching a page of search results, if a page offset beyond the total number + of available result was requested, a single result was still returned (e.g. + requesting a page beginning at index 1000 when there are only 10 results would + result in the 10th result being returned). This will now result in an empty + response Bundle as would be expected. +