diff --git a/.travis.yml b/.travis.yml index a98b7603500..fbd6c31bf41 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,2 +1,7 @@ language: java +jdk: + - oraclejdk6 + +install: mvn clean install -Dcobertura.skip=true +script: mvn -P COBERTURA clean cobertura:cobertura diff --git a/examples/src/main/java/example/ClientExamples.java b/examples/src/main/java/example/ClientExamples.java index 7631f07c514..5725e8b161c 100644 --- a/examples/src/main/java/example/ClientExamples.java +++ b/examples/src/main/java/example/ClientExamples.java @@ -19,7 +19,7 @@ public class ClientExamples { @SuppressWarnings("unused") public void createProxy() { // START SNIPPET: proxy - FhirContext ctx = new FhirContext(); + FhirContext ctx = FhirContext.forDstu2(); // Set connections to access the network via the HTTP proxy at // example.com : 8888 @@ -36,7 +36,7 @@ public class ClientExamples { @SuppressWarnings("unused") public void createTimeouts() { // START SNIPPET: timeouts - FhirContext ctx = new FhirContext(); + FhirContext ctx = FhirContext.forDstu2(); // Set how long to try and establish the initial TCP connection (in ms) ctx.getRestfulClientFactory().setConnectTimeout(20 * 1000); @@ -53,7 +53,7 @@ public class ClientExamples { public void createSecurity() { // START SNIPPET: security // Create a context and get the client factory so it can be configured - FhirContext ctx = new FhirContext(); + FhirContext ctx = FhirContext.forDstu2(); IRestfulClientFactory clientFactory = ctx.getRestfulClientFactory(); // Create an HTTP basic auth interceptor @@ -74,7 +74,7 @@ public class ClientExamples { public void createCookie() { // START SNIPPET: cookie // Create a context and get the client factory so it can be configured - FhirContext ctx = new FhirContext(); + FhirContext ctx = FhirContext.forDstu2(); IRestfulClientFactory clientFactory = ctx.getRestfulClientFactory(); // Create a cookie interceptor. This cookie will have the name "mycookie" and @@ -95,7 +95,7 @@ public class ClientExamples { public void createSecurityBearer() { // START SNIPPET: securityBearer // Create a context and get the client factory so it can be configured - FhirContext ctx = new FhirContext(); + FhirContext ctx = FhirContext.forDstu2(); IRestfulClientFactory clientFactory = ctx.getRestfulClientFactory(); // In reality the token would have come from an authorization server @@ -117,7 +117,7 @@ public class ClientExamples { { // START SNIPPET: logging // Create a context and get the client factory so it can be configured - FhirContext ctx = new FhirContext(); + FhirContext ctx = FhirContext.forDstu2(); IRestfulClientFactory clientFactory = ctx.getRestfulClientFactory(); // Create a logging interceptor @@ -141,7 +141,7 @@ public class ClientExamples { { // START SNIPPET: clientConfig // Create a client - FhirContext ctx = new FhirContext(); + FhirContext ctx = FhirContext.forDstu2(); IPatientClient client = ctx.newRestfulClient(IPatientClient.class, "http://localhost:9999/"); // Request JSON encoding from the server (_format=json) diff --git a/examples/src/main/java/example/CompleteExampleClient.java b/examples/src/main/java/example/CompleteExampleClient.java index 9ac8526c13b..b58a0b47351 100644 --- a/examples/src/main/java/example/CompleteExampleClient.java +++ b/examples/src/main/java/example/CompleteExampleClient.java @@ -37,7 +37,7 @@ public class CompleteExampleClient { public static void main(String[] args) throws IOException { // Create a client factory - FhirContext ctx = new FhirContext(); + FhirContext ctx = FhirContext.forDstu2(); // Create the client String serverBase = "http://fhir.healthintersections.com.au/open"; diff --git a/examples/src/main/java/example/ExampleRestfulClient.java b/examples/src/main/java/example/ExampleRestfulClient.java index 3995b0e1082..16e05c2304e 100644 --- a/examples/src/main/java/example/ExampleRestfulClient.java +++ b/examples/src/main/java/example/ExampleRestfulClient.java @@ -11,7 +11,7 @@ public class ExampleRestfulClient { //START SNIPPET: client public static void main(String[] args) { - FhirContext ctx = new FhirContext(); + FhirContext ctx = FhirContext.forDstu2(); String serverBase = "http://foo.com/fhirServerBase"; // Create the client diff --git a/examples/src/main/java/example/Extensions.java b/examples/src/main/java/example/Extensions.java index ea7fdde2d1c..3506f2af5a5 100644 --- a/examples/src/main/java/example/Extensions.java +++ b/examples/src/main/java/example/Extensions.java @@ -49,7 +49,8 @@ ExtensionDt givenExt = new ExtensionDt(false, "http://examples.com#moreext", new given.addUndeclaredExtension(givenExt); //END SNIPPET: resourceStringExtension -String output = new FhirContext().newXmlParser().setPrettyPrint(true).encodeResourceToString(patient); +FhirContext ctx = FhirContext.forDstu2(); +String output = ctx.newXmlParser().setPrettyPrint(true).encodeResourceToString(patient); System.out.println(output); diff --git a/examples/src/main/java/example/HttpProxy.java b/examples/src/main/java/example/HttpProxy.java index 73348773488..866d0a6f882 100644 --- a/examples/src/main/java/example/HttpProxy.java +++ b/examples/src/main/java/example/HttpProxy.java @@ -39,7 +39,7 @@ public class HttpProxy { .disableCookieManagement(); CloseableHttpClient httpClient = clientBuilder.build(); - FhirContext ctx = new FhirContext(); + FhirContext ctx = FhirContext.forDstu2(); String serverBase = "http://spark.furore.com/fhir/"; ctx.getRestfulClientFactory().setHttpClient(httpClient); IGenericClient client = ctx.newRestfulGenericClient(serverBase); diff --git a/examples/src/main/java/example/MyPatientUse.java b/examples/src/main/java/example/MyPatientUse.java index 3e973a3707e..548555eb4f5 100644 --- a/examples/src/main/java/example/MyPatientUse.java +++ b/examples/src/main/java/example/MyPatientUse.java @@ -65,19 +65,19 @@ patient.getImportantDates().add(new DateTimeDt("2014-01-26T11:11:11")); patient.addName().addFamily("Smith").addGiven("John").addGiven("Quincy").addSuffix("Jr"); -IParser p = new FhirContext().newXmlParser().setPrettyPrint(true); +IParser p = FhirContext.forDstu2().newXmlParser().setPrettyPrint(true); String messageString = p.encodeResourceToString(patient); System.out.println(messageString); //END SNIPPET: patientUse //START SNIPPET: patientParse -IParser parser = new FhirContext().newXmlParser(); +IParser parser = FhirContext.forDstu2().newXmlParser(); MyPatient newPatient = parser.parseResource(MyPatient.class, messageString); //END SNIPPET: patientParse { - FhirContext ctx2 = new FhirContext(); + FhirContext ctx2 = FhirContext.forDstu2(); RuntimeResourceDefinition def = ctx2.getResourceDefinition(patient); System.out.println(ctx2.newXmlParser().setPrettyPrint(true).encodeResourceToString(def.toProfile())); } diff --git a/examples/src/main/java/example/Narrative.java b/examples/src/main/java/example/Narrative.java index 1acd6b3b06a..d43ad1c976c 100644 --- a/examples/src/main/java/example/Narrative.java +++ b/examples/src/main/java/example/Narrative.java @@ -18,7 +18,7 @@ patient.addIdentifier().setSystem("urn:foo").setValue("7000135"); patient.addName().addFamily("Smith").addGiven("John").addGiven("Edward"); patient.addAddress().addLine("742 Evergreen Terrace").setCity("Springfield").setState("ZZ"); -FhirContext ctx = new FhirContext(); +FhirContext ctx = FhirContext.forDstu2(); // Use the narrative generator ctx.setNarrativeGenerator(new DefaultThymeleafNarrativeGenerator()); diff --git a/examples/src/main/java/example/NarrativeGenerator.java b/examples/src/main/java/example/NarrativeGenerator.java index 997a26b8b57..e4bbd00e4f5 100644 --- a/examples/src/main/java/example/NarrativeGenerator.java +++ b/examples/src/main/java/example/NarrativeGenerator.java @@ -16,7 +16,7 @@ public class NarrativeGenerator { String propFile = "classpath:/com/foo/customnarrative.properties"; CustomThymeleafNarrativeGenerator gen = new CustomThymeleafNarrativeGenerator(propFile); -FhirContext ctx = new FhirContext(); +FhirContext ctx = FhirContext.forDstu2(); ctx.setNarrativeGenerator(gen); //END SNIPPET: gen diff --git a/examples/src/main/java/example/QuickUsage.java b/examples/src/main/java/example/QuickUsage.java index 06b39a00ed6..fffa88ed80f 100644 --- a/examples/src/main/java/example/QuickUsage.java +++ b/examples/src/main/java/example/QuickUsage.java @@ -30,7 +30,7 @@ patient.addName().addFamily("Smith").addGiven("John").addGiven("Q").addSuffix("J patient.setGender(AdministrativeGenderEnum.MALE); -FhirContext ctx = new FhirContext(); +FhirContext ctx = FhirContext.forDstu2(); String xmlEncoded = ctx.newXmlParser().encodeResourceToString(patient); String jsonEncoded = ctx.newJsonParser().encodeResourceToString(patient); diff --git a/examples/src/main/java/example/ResourceRefs.java b/examples/src/main/java/example/ResourceRefs.java index 102db3a5392..b5d81d41595 100644 --- a/examples/src/main/java/example/ResourceRefs.java +++ b/examples/src/main/java/example/ResourceRefs.java @@ -6,7 +6,7 @@ import ca.uhn.fhir.model.dstu2.resource.Patient; public class ResourceRefs { - private static FhirContext ourCtx = new FhirContext(); + private static FhirContext ourCtx = FhirContext.forDstu2(); public static void main(String[] args) { manualContained(); diff --git a/examples/src/main/java/example/RestfulPatientResourceProviderMore.java b/examples/src/main/java/example/RestfulPatientResourceProviderMore.java index 662ca2691d6..fceb09d8f97 100644 --- a/examples/src/main/java/example/RestfulPatientResourceProviderMore.java +++ b/examples/src/main/java/example/RestfulPatientResourceProviderMore.java @@ -933,7 +933,7 @@ public interface HistoryClient extends IBasicClient { public void bbbbb() throws DataFormatException, IOException { //START SNIPPET: metadataClientUsage -FhirContext ctx = new FhirContext(); +FhirContext ctx = FhirContext.forDstu2(); MetadataClient client = ctx.newRestfulClient(MetadataClient.class, "http://spark.furore.com/fhir"); Conformance metadata = client.getServerMetadata(); System.out.println(ctx.newXmlParser().encodeResourceToString(metadata)); @@ -973,7 +973,7 @@ private interface IPatientClient extends IBasicClient public void clientRead() { //START SNIPPET: clientReadTags -IPatientClient client = new FhirContext().newRestfulClient(IPatientClient.class, "http://foo/fhir"); +IPatientClient client = FhirContext.forDstu2().newRestfulClient(IPatientClient.class, "http://foo/fhir"); Patient patient = client.readPatient(new IdDt("1234")); // Access the tag list diff --git a/examples/src/main/java/example/ServerInterceptors.java b/examples/src/main/java/example/ServerInterceptors.java index 9f72c18dab6..fdfc5311ba4 100644 --- a/examples/src/main/java/example/ServerInterceptors.java +++ b/examples/src/main/java/example/ServerInterceptors.java @@ -43,7 +43,7 @@ ExtensionDt ext2 = new ExtensionDt(false, "http://examples.com#moreext", new Str given.addUndeclaredExtension(ext2); //END SNIPPET: resourceStringExtension -String output = new FhirContext().newXmlParser().setPrettyPrint(true).encodeResourceToString(patient); +String output = FhirContext.forDstu2().newXmlParser().setPrettyPrint(true).encodeResourceToString(patient); System.out.println(output); diff --git a/examples/src/main/java/example/TagsExamples.java b/examples/src/main/java/example/TagsExamples.java index 57bbdce0c74..5619c9422f8 100644 --- a/examples/src/main/java/example/TagsExamples.java +++ b/examples/src/main/java/example/TagsExamples.java @@ -20,7 +20,7 @@ public class TagsExamples { @SuppressWarnings("unused") public void getResourceTags() { // START SNIPPET: getResourceTags - IGenericClient client = new FhirContext().newRestfulGenericClient("http://fhir.healthintersections.com.au/open"); + IGenericClient client = FhirContext.forDstu2().newRestfulGenericClient("http://fhir.healthintersections.com.au/open"); Patient p = client.read(Patient.class, "1"); // Retrieve the list of tags from the resource metadata diff --git a/examples/src/main/java/example/ValidatorExamples.java b/examples/src/main/java/example/ValidatorExamples.java index 1a901ccd553..e4ff8725c6e 100644 --- a/examples/src/main/java/example/ValidatorExamples.java +++ b/examples/src/main/java/example/ValidatorExamples.java @@ -37,7 +37,7 @@ public class ValidatorExamples { public void validateResource() { // START SNIPPET: basicValidation // As always, you need a context - FhirContext ctx = new FhirContext(); + FhirContext ctx = FhirContext.forDstu2(); // Create and populate a new patient object Patient p = new Patient(); @@ -73,7 +73,7 @@ public class ValidatorExamples { private static void validateFiles() throws Exception { // START SNIPPET: validateFiles - FhirContext ctx = new FhirContext(); + FhirContext ctx = FhirContext.forDstu2(); // Create a validator and configure it FhirValidator validator = ctx.newValidator(); diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/narrative/BaseThymeleafNarrativeGenerator.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/narrative/BaseThymeleafNarrativeGenerator.java index c6d0dd879a5..43c84b6990e 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/narrative/BaseThymeleafNarrativeGenerator.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/narrative/BaseThymeleafNarrativeGenerator.java @@ -292,6 +292,7 @@ public abstract class BaseThymeleafNarrativeGenerator implements INarrativeGener loadProperties(next); } } catch (IOException e) { + ourLog.info("Failed to load property file " + propFileName, e); throw new ConfigurationException("Can not load property file " + propFileName, e); } diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/RestfulServer.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/RestfulServer.java index 702c257b55e..660406cd236 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/RestfulServer.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/RestfulServer.java @@ -103,12 +103,18 @@ public class RestfulServer extends HttpServlet { private boolean myUseBrowserFriendlyContentTypes; /** - * Constructor + * Constructor. Note that if no {@link FhirContext} is passed in to the server (either through the constructor, or + * through {@link #setFhirContext(FhirContext)}) the server will determine which version of FHIR to support + * through classpath scanning. This is brittle, and it is highly recommended to explicitly specify + * a FHIR version. */ public RestfulServer() { - this(new FhirContext()); + this(null); } + /** + * Constructor + */ public RestfulServer(FhirContext theCtx) { myFhirContext = theCtx; } @@ -200,7 +206,7 @@ public class RestfulServer extends HttpServlet { int count = 0; for (Method m : ReflectionUtil.getDeclaredMethods(clazz)) { - BaseMethodBinding foundMethodBinding = BaseMethodBinding.bindMethod(m, myFhirContext, theProvider); + BaseMethodBinding foundMethodBinding = BaseMethodBinding.bindMethod(m, getFhirContext(), theProvider); if (foundMethodBinding == null) { continue; } @@ -220,7 +226,7 @@ public class RestfulServer extends HttpServlet { if (resourceName == null) { resourceBinding = myServerBinding; } else { - RuntimeResourceDefinition definition = myFhirContext.getResourceDefinition(resourceName); + RuntimeResourceDefinition definition = getFhirContext().getResourceDefinition(resourceName); if (myResourceNameToProvider.containsKey(definition.getName())) { resourceBinding = myResourceNameToProvider.get(definition.getName()); } else { @@ -270,7 +276,7 @@ public class RestfulServer extends HttpServlet { if (Modifier.isPublic(m.getModifiers())) { ourLog.debug("Scanning public method: {}#{}", theSystemProvider.getClass(), m.getName()); - BaseMethodBinding foundMethodBinding = BaseMethodBinding.bindMethod(m, myFhirContext, theSystemProvider); + BaseMethodBinding foundMethodBinding = BaseMethodBinding.bindMethod(m, getFhirContext(), theSystemProvider); if (foundMethodBinding != null) { if (foundMethodBinding instanceof ConformanceMethodBinding) { myServerConformanceMethod = foundMethodBinding; @@ -318,6 +324,9 @@ public class RestfulServer extends HttpServlet { * creating their own. */ public FhirContext getFhirContext() { + if (myFhirContext == null) { + myFhirContext = new FhirContext(); + } return myFhirContext; } @@ -419,7 +428,7 @@ public class RestfulServer extends HttpServlet { } public IResourceProvider getServerProfilesProvider() { - return myFhirContext.getVersion().createServerProfilesProvider(this); + return getFhirContext().getVersion().createServerProfilesProvider(this); } /** @@ -462,7 +471,7 @@ public class RestfulServer extends HttpServlet { NarrativeModeEnum narrativeMode = RestfulServerUtils.determineNarrativeMode(theRequest); boolean respondGzip = theRequest.isRespondGzip(); - IVersionSpecificBundleFactory bundleFactory = myFhirContext.newBundleFactory(); + IVersionSpecificBundleFactory bundleFactory = getFhirContext().newBundleFactory(); Set includes = new HashSet(); String[] reqIncludes = theRequest.getServletRequest().getParameterValues(Constants.PARAM_INCLUDE); @@ -765,7 +774,7 @@ public class RestfulServer extends HttpServlet { throw new NullPointerException("getResourceType() on class '" + nextProvider.getClass().getCanonicalName() + "' returned null"); } - String resourceName = myFhirContext.getResourceDefinition(resourceType).getName(); + String resourceName = getFhirContext().getResourceDefinition(resourceType).getName(); if (typeToProvider.containsKey(resourceName)) { throw new ServletException("Multiple resource providers return resource type[" + resourceName + "]: First[" + typeToProvider.get(resourceName).getClass().getCanonicalName() + "] and Second[" + nextProvider.getClass().getCanonicalName() + "]"); @@ -792,7 +801,7 @@ public class RestfulServer extends HttpServlet { Object confProvider = getServerConformanceProvider(); if (confProvider == null) { - confProvider = myFhirContext.getVersion().createServerConformanceProvider(this); + confProvider = getFhirContext().getVersion().createServerConformanceProvider(this); } findSystemMethods(confProvider); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/ResourceProviderDstu1Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/ResourceProviderDstu1Test.java index 7fbccf64244..d705d64e0ba 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/ResourceProviderDstu1Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/ResourceProviderDstu1Test.java @@ -54,7 +54,7 @@ public class ResourceProviderDstu1Test { private static ClassPathXmlApplicationContext ourAppCtx; private static IGenericClient ourClient; private static DaoConfig ourDaoConfig; - private static FhirContext ourFhirCtx; + private static FhirContext ourCtx = FhirContext.forDstu1(); private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ResourceProviderDstu1Test.class); private static IFhirResourceDao ourOrganizationDao; // private static IFhirResourceDao ourObservationDao; @@ -405,14 +405,14 @@ public class ResourceProviderDstu1Test { // Read back directly from the DAO { Organization returned = ourOrganizationDao.read(orgId); - String val = ourFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(returned); + String val = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(returned); ourLog.info(val); assertThat(val, containsString("")); } // Read back through the HTTP API { Organization returned = ourClient.read(Organization.class, orgId); - String val = ourFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(returned); + String val = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(returned); ourLog.info(val); assertThat(val, containsString("")); } @@ -492,9 +492,7 @@ public class ResourceProviderDstu1Test { public static void beforeClass() throws Exception { int port = RandomServerPortProvider.findFreePort(); - RestfulServer restServer = new RestfulServer(); - ourFhirCtx = FhirContext.forDstu1(); - restServer.setFhirContext(ourFhirCtx); + RestfulServer restServer = new RestfulServer(ourCtx); String serverBase = "http://localhost:" + port + "/fhir/context"; @@ -526,7 +524,7 @@ public class ResourceProviderDstu1Test { ourServer.setHandler(proxyHandler); ourServer.start(); - ourClient = ourFhirCtx.newRestfulGenericClient(serverBase); + ourClient = ourCtx.newRestfulGenericClient(serverBase); ourClient.registerInterceptor(new LoggingInterceptor(true)); } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/ResourceProviderDstu2Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/ResourceProviderDstu2Test.java index 364bd91e5f4..dc66f2dafae 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/ResourceProviderDstu2Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/ResourceProviderDstu2Test.java @@ -101,7 +101,7 @@ public class ResourceProviderDstu2Test { private static ClassPathXmlApplicationContext ourAppCtx; private static IGenericClient ourClient; private static DaoConfig ourDaoConfig; - private static FhirContext ourFhirCtx; + private static FhirContext ourCtx = FhirContext.forDstu2(); private static CloseableHttpClient ourHttpClient; private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ResourceProviderDstu2Test.class); private static IFhirResourceDao ourOrganizationDao; @@ -148,7 +148,7 @@ public class ResourceProviderDstu2Test { ca.uhn.fhir.model.dstu2.resource.Bundle bundle = client.read().resource(ca.uhn.fhir.model.dstu2.resource.Bundle.class).withId(id).execute(); - ourLog.info(ourFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(bundle)); + ourLog.info(ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(bundle)); } @Test @@ -194,7 +194,7 @@ public class ResourceProviderDstu2Test { Patient pt = new Patient(); pt.addName().addFamily(methodName); - String resource = ourFhirCtx.newXmlParser().encodeResourceToString(pt); + String resource = ourCtx.newXmlParser().encodeResourceToString(pt); HttpPost post = new HttpPost(ourServerBase + "/Patient"); post.addHeader(Constants.HEADER_IF_NONE_EXIST, "Patient?name=" + methodName); @@ -284,7 +284,7 @@ public class ResourceProviderDstu2Test { Patient pt = new Patient(); pt.addName().addFamily(methodName); - String resource = ourFhirCtx.newXmlParser().encodeResourceToString(pt); + String resource = ourCtx.newXmlParser().encodeResourceToString(pt); HttpPost post = new HttpPost(ourServerBase + "/Patient"); post.setEntity(new StringEntity(resource, ContentType.create(Constants.CT_FHIR_XML, "UTF-8"))); @@ -328,7 +328,7 @@ public class ResourceProviderDstu2Test { Patient pt = new Patient(); pt.addName().addFamily(methodName); pt.addIdentifier().setSystem("http://ghh.org/patient").setValue(methodName); - String resource = ourFhirCtx.newXmlParser().encodeResourceToString(pt); + String resource = ourCtx.newXmlParser().encodeResourceToString(pt); HttpPost post = new HttpPost(ourServerBase + "/Patient"); post.setEntity(new StringEntity(resource, ContentType.create(Constants.CT_FHIR_XML, "UTF-8"))); @@ -409,8 +409,8 @@ public class ResourceProviderDstu2Test { */ @Test public void testDocumentManifestResources() throws Exception { - ourFhirCtx.getResourceDefinition(Practitioner.class); - ourFhirCtx.getResourceDefinition(ca.uhn.fhir.model.dstu.resource.DocumentManifest.class); + ourCtx.getResourceDefinition(Practitioner.class); + ourCtx.getResourceDefinition(ca.uhn.fhir.model.dstu.resource.DocumentManifest.class); IGenericClient client = ourClient; @@ -449,7 +449,7 @@ public class ResourceProviderDstu2Test { @Test public void testEverythingDoesntRepeatPatient() throws Exception { ca.uhn.fhir.model.dstu2.resource.Bundle b; - b = ourFhirCtx.newJsonParser().parseResource(ca.uhn.fhir.model.dstu2.resource.Bundle.class, new InputStreamReader(ResourceProviderDstu2Test.class.getResourceAsStream("/bug147-bundle.json"))); + b = ourCtx.newJsonParser().parseResource(ca.uhn.fhir.model.dstu2.resource.Bundle.class, new InputStreamReader(ResourceProviderDstu2Test.class.getResourceAsStream("/bug147-bundle.json"))); ca.uhn.fhir.model.dstu2.resource.Bundle resp = ourClient.transaction().withBundle(b).execute(); List ids = new ArrayList(); @@ -518,7 +518,7 @@ public class ResourceProviderDstu2Test { ca.uhn.fhir.model.dstu2.resource.Bundle resp = ourClient.transaction().withBundle(b).execute(); - ourLog.info(ourFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(resp)); + ourLog.info(ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(resp)); IdDt patientId = new IdDt(resp.getEntry().get(1).getTransactionResponse().getLocation()); assertEquals("Patient", patientId.getResourceType()); @@ -874,14 +874,14 @@ public class ResourceProviderDstu2Test { // Read back directly from the DAO { Organization returned = ourOrganizationDao.read(orgId); - String val = ourFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(returned); + String val = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(returned); ourLog.info(val); assertThat(val, containsString("")); } // Read back through the HTTP API { Organization returned = ourClient.read(Organization.class, orgId); - String val = ourFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(returned); + String val = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(returned); ourLog.info(val); assertThat(val, containsString("")); } @@ -938,7 +938,7 @@ public class ResourceProviderDstu2Test { Patient pt = new Patient(); pt.addName().addFamily(methodName); - String resource = ourFhirCtx.newXmlParser().encodeResourceToString(pt); + String resource = ourCtx.newXmlParser().encodeResourceToString(pt); HttpPost post = new HttpPost(ourServerBase + "/Patient?name=" + methodName); post.setEntity(new StringEntity(resource, ContentType.create(Constants.CT_FHIR_XML, "UTF-8"))); @@ -996,7 +996,7 @@ public class ResourceProviderDstu2Test { Parameters input = new Parameters(); input.addParameter().setName("resource").setResource(patient); - String inputStr = ourFhirCtx.newXmlParser().encodeResourceToString(input); + String inputStr = ourCtx.newXmlParser().encodeResourceToString(input); ourLog.info(inputStr); HttpPost post = new HttpPost(ourServerBase + "/Patient/$validate"); @@ -1024,7 +1024,7 @@ public class ResourceProviderDstu2Test { Parameters input = new Parameters(); input.addParameter().setName("resource").setResource(patient); - String inputStr = ourFhirCtx.newXmlParser().encodeResourceToString(input); + String inputStr = ourCtx.newXmlParser().encodeResourceToString(input); ourLog.info(inputStr); HttpPost post = new HttpPost(ourServerBase + "/Patient/$validate"); @@ -1061,9 +1061,8 @@ public class ResourceProviderDstu2Test { public static void beforeClass() throws Exception { ourPort = RandomServerPortProvider.findFreePort(); - RestfulServer restServer = new RestfulServer(); - ourFhirCtx = FhirContext.forDstu2(); - restServer.setFhirContext(ourFhirCtx); + RestfulServer restServer = new RestfulServer(ourCtx); + restServer.setFhirContext(ourCtx); ourServerBase = "http://localhost:" + ourPort + "/fhir/context"; @@ -1095,9 +1094,9 @@ public class ResourceProviderDstu2Test { ourServer.setHandler(proxyHandler); ourServer.start(); - ourFhirCtx.getRestfulClientFactory().setServerValidationMode(ServerValidationModeEnum.NEVER); - ourFhirCtx.getRestfulClientFactory().setSocketTimeout(1200 * 1000); - ourClient = ourFhirCtx.newRestfulGenericClient(ourServerBase); + ourCtx.getRestfulClientFactory().setServerValidationMode(ServerValidationModeEnum.NEVER); + ourCtx.getRestfulClientFactory().setSocketTimeout(1200 * 1000); + ourClient = ourCtx.newRestfulGenericClient(ourServerBase); // ourClient.registerInterceptor(new LoggingInterceptor(true)); PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(5000, TimeUnit.MILLISECONDS); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/ResourceProviderMultiVersionTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/ResourceProviderMultiVersionTest.java index 3c8144fcd03..b5bfd1dcbc1 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/ResourceProviderMultiVersionTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/ResourceProviderMultiVersionTest.java @@ -139,8 +139,7 @@ public class ResourceProviderMultiVersionTest { * DEV resources */ - RestfulServer restServerDstu2 = new RestfulServer(); - restServerDstu2.setFhirContext(ourAppCtx.getBean("myFhirContextDstu2", FhirContext.class)); + RestfulServer restServerDstu2 = new RestfulServer(ourAppCtx.getBean("myFhirContextDstu2", FhirContext.class)); List rpsDstu2 = (List) ourAppCtx.getBean("myResourceProvidersDstu2", List.class); restServerDstu2.setResourceProviders(rpsDstu2); @@ -155,8 +154,7 @@ public class ResourceProviderMultiVersionTest { * DSTU resources */ - RestfulServer restServerDstu1 = new RestfulServer(); - restServerDstu1.setFhirContext(ourAppCtx.getBean("myFhirContextDstu1", FhirContext.class)); + RestfulServer restServerDstu1 = new RestfulServer(ourAppCtx.getBean("myFhirContextDstu1", FhirContext.class)); List rpsDstu1 = (List) ourAppCtx.getBean("myResourceProvidersDstu1", List.class); restServerDstu1.setResourceProviders(rpsDstu1); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/SystemProviderDstu1Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/SystemProviderDstu1Test.java index 1e72a5df471..58b03c85ad0 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/SystemProviderDstu1Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/SystemProviderDstu1Test.java @@ -89,7 +89,7 @@ public class SystemProviderDstu1Test { OrganizationResourceProvider organizationRp = new OrganizationResourceProvider(); organizationRp.setDao(organizationDao); - RestfulServer restServer = new RestfulServer(); + RestfulServer restServer = new RestfulServer(ourCtx); restServer.setResourceProviders(patientRp, questionnaireRp, observationRp, organizationRp); JpaSystemProviderDstu1 systemProv = ourAppCtx.getBean(JpaSystemProviderDstu1.class, "mySystemProviderDstu1"); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/SystemProviderDstu2Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/SystemProviderDstu2Test.java index 0c8cecc473c..1a6ba0c4fdf 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/SystemProviderDstu2Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/SystemProviderDstu2Test.java @@ -122,7 +122,7 @@ public class SystemProviderDstu2Test { OrganizationResourceProvider organizationRp = new OrganizationResourceProvider(); organizationRp.setDao(organizationDao); - RestfulServer restServer = new RestfulServer(); + RestfulServer restServer = new RestfulServer(ourCtx); restServer.setResourceProviders(patientRp, questionnaireRp, observationRp, organizationRp); JpaSystemProviderDstu2 systemProv = ourAppCtx.getBean(JpaSystemProviderDstu2.class, "mySystemProviderDstu2"); diff --git a/hapi-fhir-jpaserver-base/src/test/resources/bundle.json b/hapi-fhir-jpaserver-base/src/test/resources/bundle-dstu2.json similarity index 100% rename from hapi-fhir-jpaserver-base/src/test/resources/bundle.json rename to hapi-fhir-jpaserver-base/src/test/resources/bundle-dstu2.json diff --git a/hapi-fhir-jpaserver-base/src/test/resources/logback-test.xml b/hapi-fhir-jpaserver-base/src/test/resources/logback-test.xml index 929b7f34772..658cd6bad1c 100644 --- a/hapi-fhir-jpaserver-base/src/test/resources/logback-test.xml +++ b/hapi-fhir-jpaserver-base/src/test/resources/logback-test.xml @@ -14,7 +14,7 @@ - + @@ -26,4 +26,4 @@ - \ No newline at end of file + diff --git a/hapi-fhir-jpaserver-uhnfhirtest/src/main/java/ca/uhn/fhirtest/FhirContextFactory.java b/hapi-fhir-jpaserver-uhnfhirtest/src/main/java/ca/uhn/fhirtest/FhirContextFactory.java index 760059631e1..b4a7da3d8e3 100644 --- a/hapi-fhir-jpaserver-uhnfhirtest/src/main/java/ca/uhn/fhirtest/FhirContextFactory.java +++ b/hapi-fhir-jpaserver-uhnfhirtest/src/main/java/ca/uhn/fhirtest/FhirContextFactory.java @@ -7,9 +7,10 @@ import ca.uhn.fhir.context.FhirContext; public class FhirContextFactory implements FactoryBean, InitializingBean { - private int myConnectionRequestTimeout = 5000; - private int mySocketTimeout = 10000; + private int myConnectionRequestTimeout = 5000; + private int mySocketTimeout = 10000; private int myConnectTimeout = 4000; + public int getConnectionRequestTimeout() { return myConnectionRequestTimeout; } @@ -36,9 +37,9 @@ public class FhirContextFactory implements FactoryBean, Initializin private FhirContext myCtx; - public FhirContextFactory() { + public FhirContextFactory() { } - + @Override public FhirContext getObject() throws Exception { return myCtx; @@ -56,7 +57,7 @@ public class FhirContextFactory implements FactoryBean, Initializin @Override public void afterPropertiesSet() throws Exception { - myCtx=new FhirContext(); + myCtx = new FhirContext(); myCtx.getRestfulClientFactory().setConnectTimeout(myConnectTimeout); myCtx.getRestfulClientFactory().setSocketTimeout(mySocketTimeout); myCtx.getRestfulClientFactory().setConnectionRequestTimeout(myConnectionRequestTimeout); diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/Dstu1EnvTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/Dstu1EnvTest.java deleted file mode 100644 index 594c887c060..00000000000 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/Dstu1EnvTest.java +++ /dev/null @@ -1,17 +0,0 @@ -package ca.uhn.fhir; - -import static org.junit.Assert.*; - -import org.junit.Test; - -import ca.uhn.fhir.context.FhirContext; -import ca.uhn.fhir.context.FhirVersionEnum; - -public class Dstu1EnvTest { - - @Test - public void testCorrectDefault() { - FhirContext ctx = new FhirContext(); - assertEquals("new FhirContext() is creating a context with the wrong FHIR versions. Something is probably wrong with the classpath.", FhirVersionEnum.DSTU1, ctx.getVersion().getVersion()); - } -} diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/DuplicateExtensionTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/DuplicateExtensionTest.java index 6cc134e97df..8faee32d8c6 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/DuplicateExtensionTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/DuplicateExtensionTest.java @@ -23,7 +23,7 @@ public class DuplicateExtensionTest extends TestCase { @Test public void testScannerShouldAddProvidedResources() { - FhirContext ctx = new FhirContext(); + FhirContext ctx = FhirContext.forDstu1(); RuntimeResourceDefinition patientDef = ctx.getResourceDefinition(CustomPatient.class); Profile profile = (Profile) patientDef.toProfile("http://foo.org/fhir"); diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/ExtensionTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/ExtensionTest.java index 706c2331bc7..94c0f601ce7 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/ExtensionTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/ExtensionTest.java @@ -16,7 +16,7 @@ import ca.uhn.fhir.parser.MyPatient; public class ExtensionTest { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ExtensionTest.class); - private static FhirContext ourCtx = new FhirContext(); + private static FhirContext ourCtx = FhirContext.forDstu1(); @Test public void testExtensionType() { @@ -66,19 +66,19 @@ public class ExtensionTest { patient.addName().addFamily("Smith").addGiven("John").addGiven("Quincy").addSuffix("Jr"); - IParser p = new FhirContext().newXmlParser().setPrettyPrint(true); + IParser p = FhirContext.forDstu1().newXmlParser().setPrettyPrint(true); String messageString = p.encodeResourceToString(patient); System.out.println(messageString); // END SNIPPET: patientUse // START SNIPPET: patientParse - IParser parser = new FhirContext().newXmlParser(); + IParser parser = FhirContext.forDstu1().newXmlParser(); MyPatient newPatient = parser.parseResource(MyPatient.class, messageString); // END SNIPPET: patientParse { - FhirContext ctx2 = new FhirContext(); + FhirContext ctx2 = FhirContext.forDstu1(); RuntimeResourceDefinition def = ctx2.getResourceDefinition(patient); System.out.println(ctx2.newXmlParser().setPrettyPrint(true).encodeResourceToString(def.toProfile("http://foo.org/fhir"))); } diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/FhirContextTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/FhirContextDstu1Test.java similarity index 81% rename from hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/FhirContextTest.java rename to hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/FhirContextDstu1Test.java index 458e901c468..129be44e0be 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/FhirContextTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/FhirContextDstu1Test.java @@ -9,11 +9,11 @@ import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.model.dstu.resource.Patient; import ca.uhn.fhir.model.dstu.resource.ValueSet; -public class FhirContextTest { +public class FhirContextDstu1Test { @Test public void testIncrementalScan() { - FhirContext ctx = new FhirContext(); + FhirContext ctx = FhirContext.forDstu1(); RuntimeResourceDefinition vsDef = ctx.getResourceDefinition(ValueSet.class); RuntimeResourceDefinition ptDef = ctx.getResourceDefinition(Patient.class); assertNotNull(ptDef); @@ -24,13 +24,13 @@ public class FhirContextTest { @Test public void testFindBinary() { - RuntimeResourceDefinition def = new FhirContext().getResourceDefinition("Binary"); + RuntimeResourceDefinition def = FhirContext.forDstu1().getResourceDefinition("Binary"); assertEquals("Binary", def.getName()); } @Test(expected = IllegalArgumentException.class) public void testGetResourceDefinitionFails() { - new FhirContext().getResourceDefinition(IResource.class); + FhirContext.forDstu1().getResourceDefinition(IResource.class); } @Test diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/InvalidResourceTypeTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/InvalidResourceTypeTest.java index 8a941debd4e..ed7a1710031 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/InvalidResourceTypeTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/InvalidResourceTypeTest.java @@ -10,7 +10,7 @@ import ca.uhn.fhir.model.dstu.resource.Patient; public class InvalidResourceTypeTest { - private static FhirContext ourCtx = new FhirContext(); + private static FhirContext ourCtx = FhirContext.forDstu1(); @Test public void testNonInstantiableType() { diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/ModelExtensionTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/ModelExtensionTest.java index c45d3f1d51a..fc3a444e58a 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/ModelExtensionTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/ModelExtensionTest.java @@ -11,7 +11,7 @@ import ca.uhn.fhir.parser.MyPatient; public class ModelExtensionTest { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ModelExtensionTest.class); - private FhirContext ourCtx = new FhirContext(); + private FhirContext ourCtx = FhirContext.forDstu1(); @Test public void testModelExtension() throws DataFormatException { diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/ModelScannerTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/ModelScannerTest.java index a4b05e77941..ad5d7d8e14c 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/ModelScannerTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/ModelScannerTest.java @@ -19,7 +19,7 @@ public class ModelScannerTest { @Test public void testExtendedClass() { - FhirContext ctx = new FhirContext(); + FhirContext ctx = FhirContext.forDstu1(); ctx.getResourceDefinition(MyPatient.class); RuntimeResourceDefinition patient = ctx.getResourceDefinition("Patient"); diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/NameChanges.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/NameChanges.java index 809a83ce99b..bc02a244b0d 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/NameChanges.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/NameChanges.java @@ -19,7 +19,7 @@ public class NameChanges { @SuppressWarnings("unchecked") @Test public void testNameChanges() throws IOException, ClassNotFoundException { - FhirContext ctx = new FhirContext(); + FhirContext ctx = FhirContext.forDstu1(); ImmutableSet names = ClassPath.from(getClass().getClassLoader()).getTopLevelClasses(Patient.class.getPackage().getName()); List changes = new ArrayList(); diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/ProvidedResourceScannerTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/ProvidedResourceScannerTest.java index 36624a98e7a..be4b6320591 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/ProvidedResourceScannerTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/ProvidedResourceScannerTest.java @@ -12,7 +12,7 @@ import static org.junit.Assert.assertNull; public class ProvidedResourceScannerTest extends TestCase { @Test public void testScannerShouldAddProvidedResources() { - FhirContext ctx = new FhirContext(); + FhirContext ctx = FhirContext.forDstu1(); assertEquals(CustomPatient.class, ctx.getElementDefinition(CustomPatient.class).getImplementingClass()); assertEquals(Patient.class, ctx.getResourceDefinition("Patient").getImplementingClass()); diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/model/api/TagListTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/model/api/TagListTest.java index bcce42d2a6e..ffc6ae60b70 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/model/api/TagListTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/model/api/TagListTest.java @@ -13,7 +13,7 @@ import ca.uhn.fhir.model.dstu.resource.Patient; public class TagListTest { - private FhirContext myCtx = new FhirContext(); + private FhirContext myCtx = FhirContext.forDstu1(); @Test public void testEquals() { diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/model/primitive/BaseDateTimeDtTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/model/primitive/BaseDateTimeDtTest.java index b4b8811002f..462f59b8b40 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/model/primitive/BaseDateTimeDtTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/model/primitive/BaseDateTimeDtTest.java @@ -27,7 +27,7 @@ public class BaseDateTimeDtTest { private FastDateFormat myDateInstantZoneParser; private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(BaseDateTimeDtTest.class); - private static FhirContext ourCtx = new FhirContext(); + private static FhirContext ourCtx = FhirContext.forDstu1(); @Before public void before() { diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/model/primitive/IdDtTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/model/primitive/IdDtTest.java index 13578cf1cf3..46b982203ec 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/model/primitive/IdDtTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/model/primitive/IdDtTest.java @@ -206,7 +206,7 @@ public class IdDtTest { @BeforeClass public static void beforeClass() { - ourCtx = new FhirContext(); + ourCtx = FhirContext.forDstu1(); } } diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/model/view/ViewGeneratorTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/model/view/ViewGeneratorTest.java index 3ac118379fc..7ed6cf75178 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/model/view/ViewGeneratorTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/model/view/ViewGeneratorTest.java @@ -14,7 +14,7 @@ import ca.uhn.fhir.parser.IParser; public class ViewGeneratorTest { - private static FhirContext ourCtx = new FhirContext(); + private static FhirContext ourCtx = FhirContext.forDstu1(); @Test public void testView() { diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/narrative/DefaultThymeleafNarrativeGeneratorTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/narrative/DefaultThymeleafNarrativeGeneratorTest.java index 0e2c2c41a74..942202d052d 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/narrative/DefaultThymeleafNarrativeGeneratorTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/narrative/DefaultThymeleafNarrativeGeneratorTest.java @@ -46,7 +46,7 @@ public class DefaultThymeleafNarrativeGeneratorTest { gen.setIgnoreFailures(false); gen.setIgnoreMissingTemplates(false); - myCtx = new FhirContext(); + myCtx = FhirContext.forDstu1(); myCtx.setNarrativeGenerator(gen); } diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/parser/BaseParserTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/parser/BaseParserTest.java index 8682c7e40f3..f848f9fed03 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/parser/BaseParserTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/parser/BaseParserTest.java @@ -13,7 +13,7 @@ import ca.uhn.fhir.model.dstu.resource.Composition; public class BaseParserTest { - private static final FhirContext ourCtx = new FhirContext(); + private static final FhirContext ourCtx = FhirContext.forDstu1(); private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(BaseParserTest.class); diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/parser/ContainedResourceEncodingTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/parser/ContainedResourceEncodingTest.java index 254975fc04c..c9a525c2f76 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/parser/ContainedResourceEncodingTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/parser/ContainedResourceEncodingTest.java @@ -58,7 +58,7 @@ public class ContainedResourceEncodingTest { initPatient(); initAuthor(); initComposition(); - this.ctx = new FhirContext(); + this.ctx = FhirContext.forDstu1(); } diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/parser/JsonParserTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/parser/JsonParserTest.java index a67059ccc58..314d2bd0323 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/parser/JsonParserTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/parser/JsonParserTest.java @@ -28,6 +28,7 @@ import org.hamcrest.core.IsNot; import org.hamcrest.core.StringContains; import org.hamcrest.text.StringContainsInOrder; import org.hl7.fhir.instance.model.api.IBaseResource; +import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; @@ -294,13 +295,13 @@ public class JsonParserTest { e.setResource(new Patient()); b.addCategory("scheme", "term", "label"); - String val = new FhirContext().newJsonParser().setPrettyPrint(false).encodeBundleToString(b); + String val = ourCtx.newJsonParser().setPrettyPrint(false).encodeBundleToString(b); ourLog.info(val); assertThat(val, StringContains.containsString("\"category\":[{\"term\":\"term\",\"label\":\"label\",\"scheme\":\"scheme\"}]")); assertThat(val, not(containsString("text"))); - b = new FhirContext().newJsonParser().parseBundle(val); + b = ourCtx.newJsonParser().parseBundle(val); assertEquals(1, b.getEntries().size()); assertEquals(1, b.getCategories().size()); assertEquals("term", b.getCategories().get(0).getTerm()); @@ -489,7 +490,7 @@ public class JsonParserTest { @Test public void testEncodeDeclaredExtensionWithAddressContent() { - IParser parser = new FhirContext().newJsonParser(); + IParser parser = ourCtx.newJsonParser(); MyPatientWithOneDeclaredAddressExtension patient = new MyPatientWithOneDeclaredAddressExtension(); patient.addAddress().setUse(AddressUseEnum.HOME); @@ -508,7 +509,7 @@ public class JsonParserTest { @Test public void testEncodeDeclaredExtensionWithResourceContent() { - IParser parser = new FhirContext().newJsonParser(); + IParser parser = ourCtx.newJsonParser(); MyPatientWithOneDeclaredExtension patient = new MyPatientWithOneDeclaredExtension(); patient.addAddress().setUse(AddressUseEnum.HOME); @@ -620,7 +621,7 @@ public class JsonParserTest { @Test public void testEncodeExtensionWithResourceContent() { - IParser parser = new FhirContext().newJsonParser(); + IParser parser = ourCtx.newJsonParser(); Patient patient = new Patient(); patient.addAddress().setUse(AddressUseEnum.HOME); @@ -751,7 +752,7 @@ public class JsonParserTest { ExtensionDt parameter = q.addParameter(); parameter.setUrl("http://hl7.org/fhir/query#_query").setValue(new StringDt("example")); - String val = new FhirContext().newJsonParser().encodeResourceToString(q); + String val = ourCtx.newJsonParser().encodeResourceToString(q); ourLog.info(val); //@formatter:off @@ -779,7 +780,7 @@ public class JsonParserTest { Patient patient = new Patient(); patient.setManagingOrganization(new ResourceReferenceDt()); - IParser p = new FhirContext().newJsonParser(); + IParser p = ourCtx.newJsonParser(); String str = p.encodeResourceToString(patient); assertThat(str, IsNot.not(StringContains.containsString("managingOrganization"))); @@ -797,7 +798,7 @@ public class JsonParserTest { @Test public void testEncodeUndeclaredExtensionWithAddressContent() { - IParser parser = new FhirContext().newJsonParser(); + IParser parser = ourCtx.newJsonParser(); Patient patient = new Patient(); patient.addAddress().setUse(AddressUseEnum.HOME); @@ -845,15 +846,15 @@ public class JsonParserTest { HumanNameDt given = name.addGiven("Joe"); ExtensionDt ext2 = new ExtensionDt(false, "http://examples.com#givenext", new StringDt("Hello")); given.addUndeclaredExtension(ext2); - String enc = new FhirContext().newJsonParser().encodeResourceToString(patient); + String enc = ourCtx.newJsonParser().encodeResourceToString(patient); ourLog.info(enc); assertEquals("{\"resourceType\":\"Patient\",\"name\":[{\"extension\":[{\"url\":\"http://examples.com#givenext\",\"valueString\":\"Hello\"}],\"family\":[\"Shmoe\"],\"given\":[\"Joe\"]}]}", enc); - IParser newJsonParser = new FhirContext().newJsonParser(); + IParser newJsonParser = ourCtx.newJsonParser(); StringReader reader = new StringReader(enc); Patient parsed = newJsonParser.parseResource(Patient.class, reader); - ourLog.info(new FhirContext().newXmlParser().setPrettyPrint(true).encodeResourceToString(parsed)); + ourLog.info(ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(parsed)); assertEquals(1, parsed.getNameFirstRep().getUndeclaredExtensionsByUrl("http://examples.com#givenext").size()); ExtensionDt ext = parsed.getNameFirstRep().getUndeclaredExtensionsByUrl("http://examples.com#givenext").get(0); @@ -872,7 +873,7 @@ public class JsonParserTest { ExtensionDt ext2 = new ExtensionDt(false, "http://examples.com#givenext", new StringDt("Hello")); family.addUndeclaredExtension(ext2); - String enc = new FhirContext().newJsonParser().encodeResourceToString(patient); + String enc = ourCtx.newJsonParser().encodeResourceToString(patient); ourLog.info(enc); //@formatter:off assertThat(enc, containsString(("{\n" + @@ -897,7 +898,7 @@ public class JsonParserTest { "}").replace("\n", "").replaceAll(" +", ""))); //@formatter:on - Patient parsed = new FhirContext().newJsonParser().parseResource(Patient.class, new StringReader(enc)); + Patient parsed = ourCtx.newJsonParser().parseResource(Patient.class, new StringReader(enc)); assertEquals(1, parsed.getNameFirstRep().getFamilyFirstRep().getUndeclaredExtensionsByUrl("http://examples.com#givenext").size()); ExtensionDt ext = parsed.getNameFirstRep().getFamilyFirstRep().getUndeclaredExtensionsByUrl("http://examples.com#givenext").get(0); assertEquals("Hello", ext.getValueAsPrimitive().getValue()); @@ -956,7 +957,7 @@ public class JsonParserTest { // nothing }}; - FhirContext context = new FhirContext(); + FhirContext context = ourCtx; context.setNarrativeGenerator(gen); IParser p = context.newJsonParser(); p.encodeResourceToWriter(patient, new OutputStreamWriter(System.out)); @@ -967,6 +968,11 @@ public class JsonParserTest { assertThat(str, StringContains.containsString(",\"text\":{\"status\":\"generated\",\"div\":\"
help
\"},")); } + @Before + public void before() { + ourCtx.setNarrativeGenerator(null); + } + @Test public void testNestedContainedResources() { @@ -1330,7 +1336,7 @@ public class JsonParserTest { "}"; //@formatter:on - TagList tagList = new FhirContext().newJsonParser().parseTagList(tagListStr); + TagList tagList = ourCtx.newJsonParser().parseTagList(tagListStr); assertEquals(3, tagList.size()); assertEquals("term0", tagList.get(0).getTerm()); assertEquals("label0", tagList.get(0).getLabel()); @@ -1367,14 +1373,14 @@ public class JsonParserTest { "}"; //@formatter:on - String encoded = new FhirContext().newJsonParser().encodeTagListToString(tagList); + String encoded = ourCtx.newJsonParser().encodeTagListToString(tagList); assertEquals(expected, encoded); } @BeforeClass public static void beforeClass() { - ourCtx = new FhirContext(); + ourCtx = FhirContext.forDstu1(); } @ResourceDef(name = "Patient") diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/parser/XmlParserTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/parser/XmlParserTest.java index 738facb25c4..a43221fe551 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/parser/XmlParserTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/parser/XmlParserTest.java @@ -1700,8 +1700,7 @@ public class XmlParserTest { @Test public void testParseFeedWithListResource() throws ConfigurationException, DataFormatException, IOException { - // Use new context here to ensure List isn't already loaded - IParser p = new FhirContext().newXmlParser(); + IParser p = FhirContext.forDstu1().newXmlParser(); // Use new context here String string = IOUtils.toString(XmlParserTest.class.getResourceAsStream("/feed-with-list.xml"), Charset.forName("UTF-8")); Bundle bundle = p.parseBundle(string); @@ -1920,7 +1919,7 @@ public class XmlParserTest { XMLUnit.setIgnoreAttributeOrder(true); XMLUnit.setIgnoreComments(true); XMLUnit.setIgnoreWhitespace(true); - ourCtx = new FhirContext(); + ourCtx = FhirContext.forDstu1(); } @BeforeClass diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/client/BasicAuthInterceptorTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/client/BasicAuthInterceptorTest.java index ac3e054fd22..48171a3f3a2 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/client/BasicAuthInterceptorTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/client/BasicAuthInterceptorTest.java @@ -97,7 +97,7 @@ public class BasicAuthInterceptorTest { @BeforeClass public static void beforeClass() { - ourCtx = new FhirContext(); + ourCtx = FhirContext.forDstu1(); } } diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/client/BearerTokenAuthInterceptorTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/client/BearerTokenAuthInterceptorTest.java index aded3d69089..b1e99b1e208 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/client/BearerTokenAuthInterceptorTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/client/BearerTokenAuthInterceptorTest.java @@ -82,7 +82,7 @@ public class BearerTokenAuthInterceptorTest { @BeforeClass public static void beforeClass() { - ourCtx = new FhirContext(); + ourCtx = FhirContext.forDstu1(); } } diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/client/ClientTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/client/ClientDstu1Test.java similarity index 94% rename from hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/client/ClientTest.java rename to hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/client/ClientDstu1Test.java index 7376a97b5b7..12ae8aae412 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/client/ClientTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/client/ClientDstu1Test.java @@ -1,12 +1,8 @@ package ca.uhn.fhir.rest.client; -import static org.hamcrest.Matchers.containsString; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; +import static org.hamcrest.Matchers.*; +import static org.junit.Assert.*; +import static org.mockito.Mockito.*; import java.io.InputStream; import java.io.StringReader; @@ -47,7 +43,6 @@ import ca.uhn.fhir.model.api.TagList; import ca.uhn.fhir.model.api.annotation.ResourceDef; import ca.uhn.fhir.model.base.resource.BaseConformance; import ca.uhn.fhir.model.dstu.composite.CodingDt; -import ca.uhn.fhir.model.dstu.resource.Conformance; import ca.uhn.fhir.model.dstu.resource.Observation; import ca.uhn.fhir.model.dstu.resource.OperationOutcome; import ca.uhn.fhir.model.dstu.resource.Patient; @@ -77,19 +72,19 @@ import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException; import ca.uhn.fhir.rest.server.exceptions.ResourceVersionConflictException; -public class ClientTest { +public class ClientDstu1Test { - private FhirContext ctx; + private FhirContext ourCtx; private HttpClient httpClient; private HttpResponse httpResponse; @Before public void before() { - ctx = new FhirContext(Patient.class, Conformance.class); + ourCtx = FhirContext.forDstu1(); httpClient = mock(HttpClient.class, new ReturnsDeepStubs()); - ctx.getRestfulClientFactory().setHttpClient(httpClient); - ctx.getRestfulClientFactory().setServerValidationModeEnum(ServerValidationModeEnum.NEVER); + ourCtx.getRestfulClientFactory().setHttpClient(httpClient); + ourCtx.getRestfulClientFactory().setServerValidationMode(ServerValidationModeEnum.NEVER); httpResponse = mock(HttpResponse.class, new ReturnsDeepStubs()); } @@ -136,7 +131,7 @@ public class ClientTest { when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(""), Charset.forName("UTF-8"))); when(httpResponse.getAllHeaders()).thenReturn(toHeaderArray("Location", "http://example.com/fhir/Patient/100/_history/200")); - ITestClient client = ctx.newRestfulClient(ITestClient.class, "http://foo"); + ITestClient client = ourCtx.newRestfulClient(ITestClient.class, "http://foo"); CapturingInterceptor interceptor = new CapturingInterceptor(); client.registerInterceptor(interceptor); @@ -165,7 +160,7 @@ public class ClientTest { when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader("foobar"), Charset.forName("UTF-8"))); try { - ctx.newRestfulClient(ITestClient.class, "http://foo").createPatient(patient); + ourCtx.newRestfulClient(ITestClient.class, "http://foo").createPatient(patient); fail(); } catch (InvalidRequestException e) { assertThat(e.getMessage(), StringContains.containsString("foobar")); @@ -185,10 +180,10 @@ public class ClientTest { when(httpClient.execute(capt.capture())).thenReturn(httpResponse); when(httpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 201, "OK")); when(httpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8")); - when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(ctx.newXmlParser().encodeResourceToString(patient)), Charset.forName("UTF-8"))); + when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(ourCtx.newXmlParser().encodeResourceToString(patient)), Charset.forName("UTF-8"))); when(httpResponse.getAllHeaders()).thenReturn(toHeaderArray("Location", "http://example.com/fhir/Patient/100/_history/200")); - ITestClient client = ctx.newRestfulClient(ITestClient.class, "http://foo"); + ITestClient client = ourCtx.newRestfulClient(ITestClient.class, "http://foo"); MethodOutcome response = client.createPatient(patient); assertEquals(HttpPost.class, capt.getValue().getClass()); @@ -211,7 +206,7 @@ public class ClientTest { when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(""), Charset.forName("UTF-8"))); when(httpResponse.getAllHeaders()).thenReturn(toHeaderArray("Location", "http://example.com/fhir/Patient/100/_history/200")); - ITestClient client = ctx.newRestfulClient(ITestClient.class, "http://foo"); + ITestClient client = ourCtx.newRestfulClient(ITestClient.class, "http://foo"); TagList tagList = new TagList(); tagList.add(new Tag((String) null, "Dog", "DogLabel")); tagList.add(new Tag("http://cats", "Cat", "CatLabel")); @@ -237,7 +232,7 @@ public class ClientTest { OperationOutcome oo = new OperationOutcome(); oo.addIssue().setDetails("Hello"); - String resp = new FhirContext().newXmlParser().encodeResourceToString(oo); + String resp = ourCtx.newXmlParser().encodeResourceToString(oo); ArgumentCaptor capt = ArgumentCaptor.forClass(HttpUriRequest.class); when(httpClient.execute(capt.capture())).thenReturn(httpResponse); @@ -245,7 +240,7 @@ public class ClientTest { when(httpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8")); when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(resp), Charset.forName("UTF-8"))); - ITestClient client = ctx.newRestfulClient(ITestClient.class, "http://foo"); + ITestClient client = ourCtx.newRestfulClient(ITestClient.class, "http://foo"); MethodOutcome response = client.deletePatient(new IdDt("1234")); assertEquals(HttpDelete.class, capt.getValue().getClass()); @@ -262,7 +257,7 @@ public class ClientTest { when(httpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_TEXT + "; charset=UTF-8")); when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(""), Charset.forName("UTF-8"))); - ITestClient client = ctx.newRestfulClient(ITestClient.class, "http://foo"); + ITestClient client = ourCtx.newRestfulClient(ITestClient.class, "http://foo"); client.deleteDiagnosticReport(new IdDt("1234")); assertEquals(HttpDelete.class, capt.getValue().getClass()); @@ -272,7 +267,7 @@ public class ClientTest { @Test public void testGetConformance() throws Exception { - String msg = IOUtils.toString(ClientTest.class.getResourceAsStream("/example-metadata.xml")); + String msg = IOUtils.toString(ClientDstu1Test.class.getResourceAsStream("/example-metadata.xml")); ArgumentCaptor capt = ArgumentCaptor.forClass(HttpUriRequest.class); when(httpClient.execute(capt.capture())).thenReturn(httpResponse); @@ -280,7 +275,7 @@ public class ClientTest { when(httpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8")); when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8"))); - ITestClient client = ctx.newRestfulClient(ITestClient.class, "http://foo"); + ITestClient client = ourCtx.newRestfulClient(ITestClient.class, "http://foo"); BaseConformance response = client.getServerConformanceStatement(); assertEquals("http://foo/metadata", capt.getValue().getURI().toString()); @@ -319,7 +314,7 @@ public class ClientTest { when(httpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_ATOM_XML + "; charset=UTF-8")); when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8"))); - ITestClient client = ctx.newRestfulClient(ITestClient.class, "http://foo"); + ITestClient client = ourCtx.newRestfulClient(ITestClient.class, "http://foo"); Bundle response = client.getHistoryPatientInstance(new IdDt("111")); assertEquals("http://foo/Patient/111/_history", capt.getValue().getURI().toString()); @@ -391,7 +386,7 @@ public class ClientTest { when(httpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_ATOM_XML + "; charset=UTF-8")); when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8"))); - ITestClient client = ctx.newRestfulClient(ITestClient.class, "http://foo"); + ITestClient client = ourCtx.newRestfulClient(ITestClient.class, "http://foo"); Bundle response = client.getHistoryPatientType(); assertEquals("http://foo/Patient/_history", capt.getValue().getURI().toString()); @@ -462,7 +457,7 @@ public class ClientTest { when(httpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_ATOM_XML + "; charset=UTF-8")); when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8"))); - ITestClient client = ctx.newRestfulClient(ITestClient.class, "http://foo"); + ITestClient client = ourCtx.newRestfulClient(ITestClient.class, "http://foo"); Bundle response = client.getHistoryServer(); assertEquals("http://foo/_history", capt.getValue().getURI().toString()); @@ -521,7 +516,7 @@ public class ClientTest { } }); - ITestClient client = ctx.newRestfulClient(ITestClient.class, "http://foo"); + ITestClient client = ourCtx.newRestfulClient(ITestClient.class, "http://foo"); // ensures the local timezone String expectedDateString = new InstantDt(new InstantDt("2012-01-02T12:01:02").getValue()).getValueAsString(); @@ -556,7 +551,7 @@ public class ClientTest { // TODO: remove the read annotation and make sure we get a sensible // error message to tell the user why the method isn't working - FhirContext ctx = new FhirContext(); + FhirContext ctx = ourCtx; ctx.getRestfulClientFactory().setServerValidationModeEnum(ServerValidationModeEnum.NEVER); ClientWithoutAnnotation client = ctx.newRestfulClient(ClientWithoutAnnotation.class, "http://wildfhir.aegis.net/fhir"); @@ -596,7 +591,7 @@ public class ClientTest { when(httpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8")); when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8"))); - ITestClient client = ctx.newRestfulClient(ITestClient.class, "http://foo"); + ITestClient client = ourCtx.newRestfulClient(ITestClient.class, "http://foo"); // Patient response = client.findPatientByMrn(new // IdentifierDt("urn:foo", "123")); Patient response = client.getPatientById(new IdDt("111")); @@ -640,7 +635,7 @@ public class ClientTest { when(httpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", "application/fhir+xml; charset=UTF-8")); when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8"))); - ITestClient client = ctx.newRestfulClient(ITestClient.class, "http://foo"); + ITestClient client = ourCtx.newRestfulClient(ITestClient.class, "http://foo"); // Patient response = client.findPatientByMrn(new // IdentifierDt("urn:foo", "123")); Patient response = client.getPatientById(new IdDt("111")); @@ -662,7 +657,7 @@ public class ClientTest { when(httpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_TEXT)); when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader("Internal Failure"), Charset.forName("UTF-8"))); - ITestClient client = ctx.newRestfulClient(ITestClient.class, "http://foo"); + ITestClient client = ourCtx.newRestfulClient(ITestClient.class, "http://foo"); try { client.getPatientById(new IdDt("111")); fail(); @@ -689,7 +684,7 @@ public class ClientTest { when(httpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML)); when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8"))); - ITestClient client = ctx.newRestfulClient(ITestClient.class, "http://foo"); + ITestClient client = ourCtx.newRestfulClient(ITestClient.class, "http://foo"); try { client.getPatientById(new IdDt("111")); fail(); @@ -723,7 +718,7 @@ public class ClientTest { when(httpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML)); when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8"))); - ITestClient client = ctx.newRestfulClient(ITestClient.class, "http://foo"); + ITestClient client = ourCtx.newRestfulClient(ITestClient.class, "http://foo"); // Patient response = client.findPatientByMrn(new // IdentifierDt("urn:foo", "123")); Patient response = client.getPatientById(new IdDt("111")); @@ -748,7 +743,7 @@ public class ClientTest { when(httpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8")); when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8"))); - ITestClient client = ctx.newRestfulClient(ITestClient.class, "http://foo"); + ITestClient client = ourCtx.newRestfulClient(ITestClient.class, "http://foo"); DateRangeParam param = new DateRangeParam(); param.setLowerBound(new DateParam(QuantityCompararatorEnum.GREATERTHAN_OR_EQUALS, "2011-01-01")); param.setUpperBound(new DateParam(QuantityCompararatorEnum.LESSTHAN_OR_EQUALS, "2021-01-01")); @@ -772,7 +767,7 @@ public class ClientTest { // httpResponse = new BasicHttpResponse(statusline, catalog, locale) when(httpClient.execute(capt.capture())).thenReturn(httpResponse); - ITestClient client = ctx.newRestfulClient(ITestClient.class, "http://foo"); + ITestClient client = ourCtx.newRestfulClient(ITestClient.class, "http://foo"); List response = client.getPatientByDob(new DateParam(QuantityCompararatorEnum.GREATERTHAN_OR_EQUALS, "2011-01-02")); assertEquals("http://foo/Patient?birthdate=%3E%3D2011-01-02", capt.getValue().getURI().toString()); @@ -793,7 +788,7 @@ public class ClientTest { when(httpClient.execute(capt.capture())).thenReturn(httpResponse); - ITestClient client = ctx.newRestfulClient(ITestClient.class, "http://foo"); + ITestClient client = ourCtx.newRestfulClient(ITestClient.class, "http://foo"); List response = client.getPatientByCompartmentAndDob(new IdDt("123"), new DateParam(QuantityCompararatorEnum.GREATERTHAN_OR_EQUALS, "2011-01-02")); assertEquals("http://foo/Patient/123/compartmentName?birthdate=%3E%3D2011-01-02", capt.getValue().getURI().toString()); @@ -819,7 +814,7 @@ public class ClientTest { when(httpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8")); when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8"))); - ITestClient client = ctx.newRestfulClient(ITestClient.class, "http://foo"); + ITestClient client = ourCtx.newRestfulClient(ITestClient.class, "http://foo"); Patient response = client.findPatientQuantity(new QuantityParam(QuantityCompararatorEnum.GREATERTHAN, 123L, "foo", "bar")); assertEquals("http://foo/Patient?quantityParam=%3E123%7Cfoo%7Cbar", capt.getValue().getURI().toString()); @@ -838,7 +833,7 @@ public class ClientTest { when(httpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8")); when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8"))); - ITestClient client = ctx.newRestfulClient(ITestClient.class, "http://foo"); + ITestClient client = ourCtx.newRestfulClient(ITestClient.class, "http://foo"); Patient response = client.findPatientByMrn(new TokenParam("urn:foo", "123")); assertEquals("http://foo/Patient?identifier=urn%3Afoo%7C123", capt.getValue().getURI().toString()); @@ -857,7 +852,7 @@ public class ClientTest { when(httpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8")); when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8"))); - ITestClient client = ctx.newRestfulClient(ITestClient.class, "http://foo"); + ITestClient client = ourCtx.newRestfulClient(ITestClient.class, "http://foo"); TokenOrListParam identifiers = new TokenOrListParam(); identifiers.add(new CodingDt("foo", "bar")); identifiers.add(new CodingDt("baz", "boz")); @@ -878,7 +873,7 @@ public class ClientTest { when(httpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8")); when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8"))); - ITestClient client = ctx.newRestfulClient(ITestClient.class, "http://foo"); + ITestClient client = ourCtx.newRestfulClient(ITestClient.class, "http://foo"); client.getPatientNoParams(); assertEquals("http://foo/Patient?_query=someQueryNoParams", capt.getValue().getURI().toString()); @@ -896,7 +891,7 @@ public class ClientTest { when(httpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8")); when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8"))); - ITestClient client = ctx.newRestfulClient(ITestClient.class, "http://foo"); + ITestClient client = ourCtx.newRestfulClient(ITestClient.class, "http://foo"); client.getPatientOneParam(new StringParam("BB")); assertEquals("http://foo/Patient?_query=someQueryOneParam¶m1=BB", capt.getValue().getURI().toString()); @@ -914,7 +909,7 @@ public class ClientTest { when(httpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8")); when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8"))); - ITestClientWithCustomType client = ctx.newRestfulClient(ITestClientWithCustomType.class, "http://foo"); + ITestClientWithCustomType client = ourCtx.newRestfulClient(ITestClientWithCustomType.class, "http://foo"); CustomPatient response = client.getPatientByDob(new DateParam(QuantityCompararatorEnum.GREATERTHAN_OR_EQUALS, "2011-01-02")); assertEquals("http://foo/Patient?birthdate=%3E%3D2011-01-02", capt.getValue().getURI().toString()); @@ -933,7 +928,7 @@ public class ClientTest { when(httpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8")); when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8"))); - ITestClientWithCustomTypeList client = ctx.newRestfulClient(ITestClientWithCustomTypeList.class, "http://foo"); + ITestClientWithCustomTypeList client = ourCtx.newRestfulClient(ITestClientWithCustomTypeList.class, "http://foo"); List response = client.getPatientByDob(new DateParam(QuantityCompararatorEnum.GREATERTHAN_OR_EQUALS, "2011-01-02")); assertEquals("http://foo/Patient?birthdate=%3E%3D2011-01-02", capt.getValue().getURI().toString()); @@ -954,7 +949,7 @@ public class ClientTest { // TODO: document this - ITestClient client = ctx.newRestfulClient(ITestClient.class, "http://foo"); + ITestClient client = ourCtx.newRestfulClient(ITestClient.class, "http://foo"); client.getPatientByDob(new DateParam(QuantityCompararatorEnum.GREATERTHAN_OR_EQUALS, "2011-01-02")); assertEquals("http://foo/Patient?birthdate=%3E%3D2011-01-02", capt.getAllValues().get(0).getURI().toString()); @@ -982,7 +977,7 @@ public class ClientTest { when(httpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8")); when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8"))); - ITestClient client = ctx.newRestfulClient(ITestClient.class, "http://foo"); + ITestClient client = ourCtx.newRestfulClient(ITestClient.class, "http://foo"); client.getPatientWithIncludes(new StringParam("aaa"), Arrays.asList(new Include[] { new Include("inc1"), new Include("inc2") })); assertEquals("http://foo/Patient?withIncludes=aaa&_include=inc1&_include=inc2", capt.getValue().getURI().toString()); @@ -1000,7 +995,7 @@ public class ClientTest { when(httpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8")); when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8"))); - ITestClient client = ctx.newRestfulClient(ITestClient.class, "http://foo"); + ITestClient client = ourCtx.newRestfulClient(ITestClient.class, "http://foo"); Bundle response = client.findPatientByName(new StringParam("AAA"), null); assertEquals("http://foo/Patient?family=AAA", capt.getValue().getURI().toString()); @@ -1012,7 +1007,7 @@ public class ClientTest { */ when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8"))); - client = ctx.newRestfulClient(ITestClient.class, "http://foo"); + client = ourCtx.newRestfulClient(ITestClient.class, "http://foo"); response = client.findPatientByName(new StringParam("AAA"), new StringParam("BBB")); assertEquals("http://foo/Patient?family=AAA&given=BBB", capt.getValue().getURI().toString()); @@ -1032,7 +1027,7 @@ public class ClientTest { when(httpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8")); when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8"))); - ITestClient client = ctx.newRestfulClient(ITestClient.class, "http://foo"); + ITestClient client = ourCtx.newRestfulClient(ITestClient.class, "http://foo"); StringParam str = new StringParam("FOO$BAR"); DateParam date = new DateParam("2001-01-01"); client.getObservationByNameValueDate(new CompositeParam(str, date)); @@ -1052,7 +1047,7 @@ public class ClientTest { when(httpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8")); when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8"))); - ITestClientWithStringIncludes client = ctx.newRestfulClient(ITestClientWithStringIncludes.class, "http://foo"); + ITestClientWithStringIncludes client = ourCtx.newRestfulClient(ITestClientWithStringIncludes.class, "http://foo"); client.getPatientWithIncludes(new StringParam("aaa"), "inc1"); assertEquals("http://foo/Patient?withIncludes=aaa&_include=inc1", capt.getValue().getURI().toString()); @@ -1072,7 +1067,7 @@ public class ClientTest { when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(""), Charset.forName("UTF-8"))); when(httpResponse.getAllHeaders()).thenReturn(toHeaderArray("Location", "http://example.com/fhir/Patient/100/_history/200")); - ITestClient client = ctx.newRestfulClient(ITestClient.class, "http://foo"); + ITestClient client = ourCtx.newRestfulClient(ITestClient.class, "http://foo"); MethodOutcome response = client.updatePatient(new IdDt("100"), patient); assertEquals(HttpPut.class, capt.getValue().getClass()); @@ -1100,7 +1095,7 @@ public class ClientTest { when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(""), Charset.forName("UTF-8"))); when(httpResponse.getAllHeaders()).thenReturn(toHeaderArray("Content-Location", "http://example.com/fhir/Patient/100/_history/200")); - ITestClient client = ctx.newRestfulClient(ITestClient.class, "http://foo"); + ITestClient client = ourCtx.newRestfulClient(ITestClient.class, "http://foo"); client.updatePatient(new IdDt("Patient/100/_history/200"), patient); assertEquals(HttpPut.class, capt.getValue().getClass()); @@ -1124,7 +1119,7 @@ public class ClientTest { when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(""), Charset.forName("UTF-8"))); when(httpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), Constants.STATUS_HTTP_409_CONFLICT, "Conflict")); - ITestClient client = ctx.newRestfulClient(ITestClient.class, "http://foo"); + ITestClient client = ourCtx.newRestfulClient(ITestClient.class, "http://foo"); client.updatePatient(new IdDt("Patient/100/_history/200"), patient); } @@ -1141,7 +1136,7 @@ public class ClientTest { when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(""), Charset.forName("UTF-8"))); when(httpResponse.getAllHeaders()).thenReturn(toHeaderArray("Location", "http://example.com/fhir/Patient/100/_history/200")); - ITestClient client = ctx.newRestfulClient(ITestClient.class, "http://foo"); + ITestClient client = ourCtx.newRestfulClient(ITestClient.class, "http://foo"); MethodOutcome response = client.updatePatient(new IdDt("Patient/100/_history/200"), patient); assertEquals(HttpPut.class, capt.getValue().getClass()); @@ -1166,7 +1161,7 @@ public class ClientTest { when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(""), Charset.forName("UTF-8"))); when(httpResponse.getAllHeaders()).thenReturn(toHeaderArray("Location", "http://example.com/fhir/Patient/100/_history/200")); - ITestClient client = ctx.newRestfulClient(ITestClient.class, "http://foo"); + ITestClient client = ourCtx.newRestfulClient(ITestClient.class, "http://foo"); MethodOutcome response = client.validatePatient(patient); assertEquals(HttpPost.class, capt.getValue().getClass()); @@ -1199,7 +1194,7 @@ public class ClientTest { when(httpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8")); when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8"))); - ITestClient client = ctx.newRestfulClient(ITestClient.class, "http://foo"); + ITestClient client = ourCtx.newRestfulClient(ITestClient.class, "http://foo"); // Patient response = client.findPatientByMrn(new // IdentifierDt("urn:foo", "123")); Patient response = client.getPatientById(new IdDt("Patient/111/_history/999")); @@ -1224,7 +1219,7 @@ public class ClientTest { } }); - ITestClientWithNarrativeParam client = ctx.newRestfulClient(ITestClientWithNarrativeParam.class, "http://foo"); + ITestClientWithNarrativeParam client = ourCtx.newRestfulClient(ITestClientWithNarrativeParam.class, "http://foo"); int idx = 0; diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/client/ClientIntegrationTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/client/ClientIntegrationTest.java index a76dca1d0e2..8c920c55ac7 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/client/ClientIntegrationTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/client/ClientIntegrationTest.java @@ -34,6 +34,7 @@ public class ClientIntegrationTest { private int myPort; private Server myServer; private MyPatientResourceProvider myPatientProvider; + private static FhirContext ourCtx = FhirContext.forDstu1(); @Before public void before() { @@ -43,7 +44,7 @@ public class ClientIntegrationTest { myPatientProvider = new MyPatientResourceProvider(); ServletHandler proxyHandler = new ServletHandler(); - RestfulServer servlet = new RestfulServer(); + RestfulServer servlet = new RestfulServer(ourCtx); servlet.setResourceProviders(myPatientProvider); ServletHolder servletHolder = new ServletHolder(servlet); proxyHandler.addServletWithMapping(servletHolder, "/*"); @@ -57,7 +58,7 @@ public class ClientIntegrationTest { myServer.start(); - FhirContext ctx = new FhirContext(); + FhirContext ctx = FhirContext.forDstu1(); HttpClientBuilder builder = HttpClientBuilder.create(); // PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(5000, TimeUnit.MILLISECONDS); diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/client/ExceptionHandlingTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/client/ExceptionHandlingTest.java index d6041b69ba6..25ae3205225 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/client/ExceptionHandlingTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/client/ExceptionHandlingTest.java @@ -38,7 +38,7 @@ public class ExceptionHandlingTest { @BeforeClass public static void beforeClass() { - ourCtx = new FhirContext(); + ourCtx = FhirContext.forDstu1(); } @Before diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/client/GenericClientTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/client/GenericClientTest.java index c2db362aa9b..3a88b106426 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/client/GenericClientTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/client/GenericClientTest.java @@ -778,7 +778,7 @@ public class GenericClientTest { @Test public void testSearchByNumberExact() throws Exception { - String msg = new FhirContext().newXmlParser().encodeBundleToString(new Bundle()); + String msg = ourCtx.newXmlParser().encodeBundleToString(new Bundle()); ArgumentCaptor capt = ArgumentCaptor.forClass(HttpUriRequest.class); when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse); @@ -1360,7 +1360,7 @@ public class GenericClientTest { @BeforeClass public static void beforeClass() { - ourCtx = new FhirContext(); + ourCtx = FhirContext.forDstu1(); } } diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/client/HttpProxyTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/client/HttpProxyTest.java index 5e1a900387f..cfc5ac27922 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/client/HttpProxyTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/client/HttpProxyTest.java @@ -49,7 +49,7 @@ public class HttpProxyTest { myFirstRequest = true; myAuthHeader = null; - RestfulServer restServer = new RestfulServer() { + RestfulServer restServer = new RestfulServer(ourCtx) { @Override protected void doGet(HttpServletRequest theRequest, HttpServletResponse theResponse) throws ServletException, IOException { @@ -69,7 +69,6 @@ public class HttpProxyTest { } }; - restServer.setFhirContext(ourCtx); restServer.setResourceProviders(new PatientResourceProvider()); // ServletHandler proxyHandler = new ServletHandler(); @@ -123,7 +122,7 @@ public class HttpProxyTest { @BeforeClass public static void beforeClass() throws Exception { - ourCtx = new FhirContext(); + ourCtx = FhirContext.forDstu1(); } public static class PatientResourceProvider implements IResourceProvider { diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/client/LoggingInterceptorTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/client/LoggingInterceptorTest.java index 877c871d7b0..7bb7c73a611 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/client/LoggingInterceptorTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/client/LoggingInterceptorTest.java @@ -39,8 +39,7 @@ public class LoggingInterceptorTest { private static int ourPort; private static Server ourServer; - private static FhirContext ourCtx; - + private static final FhirContext ourCtx = FhirContext.forDstu1(); private Appender myMockAppender; private Logger myLoggerRoot; @@ -89,15 +88,14 @@ public class LoggingInterceptorTest { DummyProvider patientProvider = new DummyProvider(); ServletHandler proxyHandler = new ServletHandler(); - RestfulServer servlet = new RestfulServer(); - ourCtx = servlet.getFhirContext(); + RestfulServer servlet = new RestfulServer(ourCtx); servlet.setResourceProviders(patientProvider); ServletHolder servletHolder = new ServletHolder(servlet); proxyHandler.addServletWithMapping(servletHolder, "/*"); ourServer.setHandler(proxyHandler); ourServer.start(); - ourCtx.getRestfulClientFactory().setServerValidationModeEnum(ServerValidationModeEnum.NEVER); + ourCtx.getRestfulClientFactory().setServerValidationMode(ServerValidationModeEnum.NEVER); } /** diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/client/SearchTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/client/SearchClientDstu1Test.java similarity index 99% rename from hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/client/SearchTest.java rename to hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/client/SearchClientDstu1Test.java index eb8ff4c7704..aa6e3475852 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/client/SearchTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/client/SearchClientDstu1Test.java @@ -42,9 +42,9 @@ import ca.uhn.fhir.rest.param.TokenParam; import ca.uhn.fhir.rest.server.Constants; import ca.uhn.fhir.rest.server.exceptions.BaseServerResponseException; -public class SearchTest { +public class SearchClientDstu1Test { - private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(SearchTest.class); + private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(SearchClientDstu1Test.class); private FhirContext ourCtx; private HttpClient ourHttpClient; diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/method/BaseOutcomeReturningMethodBindingTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/method/BaseOutcomeReturningMethodBindingTest.java index 025886ab5c3..8a5e29e749d 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/method/BaseOutcomeReturningMethodBindingTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/method/BaseOutcomeReturningMethodBindingTest.java @@ -184,7 +184,7 @@ public class BaseOutcomeReturningMethodBindingTest { "}"; //@formatter:on - TagList parsedFromResource = new FhirContext().newJsonParser().parseTagList(resourceString); + TagList parsedFromResource = FhirContext.forDstu1().newJsonParser().parseTagList(resourceString); assertEquals(parsedFromHeader.size(), parsedFromResource.size()); diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/AcceptHeaderTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/AcceptHeaderTest.java index c6882fd4d26..6c5fce7b54e 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/AcceptHeaderTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/AcceptHeaderTest.java @@ -38,6 +38,7 @@ public class AcceptHeaderTest { private static CloseableHttpClient ourClient; private static int ourPort; private static Server ourServer; + private static FhirContext ourCtx = FhirContext.forDstu1(); @Test public void testReadNoHeader() throws Exception { @@ -97,7 +98,7 @@ public class AcceptHeaderTest { ourServer = new Server(ourPort); ServletHandler proxyHandler = new ServletHandler(); - RestfulServer servlet = new RestfulServer(); + RestfulServer servlet = new RestfulServer(ourCtx); servlet.setResourceProviders(new PatientProvider()); servlet.setDefaultResponseEncoding(EncodingEnum.XML); ServletHolder servletHolder = new ServletHolder(servlet); diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/BinaryTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/BinaryTest.java index b10a1ac6d69..05967398334 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/BinaryTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/BinaryTest.java @@ -44,7 +44,7 @@ import ca.uhn.fhir.util.PortUtil; public class BinaryTest { private static CloseableHttpClient ourClient; - private static FhirContext ourCtx = new FhirContext(); + private static FhirContext ourCtx = FhirContext.forDstu1(); private static Binary ourLast; private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(BinaryTest.class); @@ -166,7 +166,7 @@ public class BinaryTest { ResourceProvider patientProvider = new ResourceProvider(); ServletHandler proxyHandler = new ServletHandler(); - RestfulServer servlet = new RestfulServer(); + RestfulServer servlet = new RestfulServer(ourCtx); servlet.setResourceProviders(patientProvider); ServletHolder servletHolder = new ServletHolder(servlet); proxyHandler.addServletWithMapping(servletHolder, "/*"); diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/CompositeParameterTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/CompositeParameterTest.java index 151f9135600..a50ad187951 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/CompositeParameterTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/CompositeParameterTest.java @@ -40,7 +40,7 @@ import ca.uhn.fhir.util.PortUtil; public class CompositeParameterTest { private static CloseableHttpClient ourClient; - private static FhirContext ourCtx; + private static final FhirContext ourCtx = FhirContext.forDstu1(); private static int ourPort; private static Server ourServer; @@ -106,8 +106,7 @@ public class CompositeParameterTest { DummyObservationResourceProvider patientProvider = new DummyObservationResourceProvider(); ServletHandler proxyHandler = new ServletHandler(); - RestfulServer servlet = new RestfulServer(); - ourCtx = servlet.getFhirContext(); + RestfulServer servlet = new RestfulServer(ourCtx); servlet.setResourceProviders(patientProvider); ServletHolder servletHolder = new ServletHolder(servlet); proxyHandler.addServletWithMapping(servletHolder, "/*"); @@ -118,8 +117,6 @@ public class CompositeParameterTest { HttpClientBuilder builder = HttpClientBuilder.create(); builder.setConnectionManager(connectionManager); ourClient = builder.build(); - - ourCtx = servlet.getFhirContext(); } /** diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/CompressionTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/CompressionTest.java index c90f86cc7bd..82ccae7ceab 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/CompressionTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/CompressionTest.java @@ -41,7 +41,7 @@ public class CompressionTest { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(CompressionTest.class); private static int ourPort; private static Server ourServer; - private static FhirContext ourCtx; + private static final FhirContext ourCtx = FhirContext.forDstu1(); public static String decompress(byte[] theResource) { GZIPInputStream is; @@ -107,8 +107,7 @@ public class CompressionTest { DummyProvider patientProvider = new DummyProvider(); ServletHandler proxyHandler = new ServletHandler(); - RestfulServer servlet = new RestfulServer(); - ourCtx = servlet.getFhirContext(); + RestfulServer servlet = new RestfulServer(ourCtx); servlet.setResourceProviders(patientProvider); ServletHolder servletHolder = new ServletHolder(servlet); proxyHandler.addServletWithMapping(servletHolder, "/*"); diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/CorsTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/CorsTest.java index 37c5ac7e847..9a16f2c42ac 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/CorsTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/CorsTest.java @@ -37,7 +37,7 @@ import ca.uhn.fhir.util.PortUtil; */ public class CorsTest { private static CloseableHttpClient ourClient; - private static FhirContext ourCtx; + private static final FhirContext ourCtx = FhirContext.forDstu1(); private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(CorsTest.class); @Test @@ -45,8 +45,7 @@ public class CorsTest { int port = PortUtil.findFreePort(); Server server = new Server(port); - RestfulServer restServer = new RestfulServer(); - restServer.setFhirContext(ourCtx); + RestfulServer restServer = new RestfulServer(ourCtx); restServer.setResourceProviders(new DummyPatientResourceProvider()); // ServletHandler proxyHandler = new ServletHandler(); @@ -125,8 +124,6 @@ public class CorsTest { @BeforeClass public static void beforeClass() throws Exception { - ourCtx = new FhirContext(); - PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(5000, TimeUnit.MILLISECONDS); HttpClientBuilder builder = HttpClientBuilder.create(); builder.setConnectionManager(connectionManager); diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/CreateTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/CreateTest.java index f8b9afdcc4a..22483bd2be4 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/CreateTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/CreateTest.java @@ -51,11 +51,11 @@ import ca.uhn.fhir.util.PortUtil; */ public class CreateTest { private static CloseableHttpClient ourClient; + private static final FhirContext ourCtx = FhirContext.forDstu1(); private static EncodingEnum ourLastEncoding; private static String ourLastResourceBody; private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(CreateTest.class); private static int ourPort; - private static DiagnosticReportProvider ourReportProvider; private static Server ourServer; @@ -65,7 +65,7 @@ public class CreateTest { ourLastResourceBody=null; ourLastEncoding=null; } - + @Test public void testCreate() throws Exception { @@ -74,7 +74,7 @@ public class CreateTest { patient.addIdentifier().setValue("002"); HttpPost httpPost = new HttpPost("http://localhost:" + ourPort + "/Patient"); - httpPost.setEntity(new StringEntity(new FhirContext().newXmlParser().encodeResourceToString(patient), ContentType.create(Constants.CT_FHIR_XML, "UTF-8"))); + httpPost.setEntity(new StringEntity(ourCtx.newXmlParser().encodeResourceToString(patient), ContentType.create(Constants.CT_FHIR_XML, "UTF-8"))); HttpResponse status = ourClient.execute(httpPost); @@ -91,31 +91,6 @@ public class CreateTest { } - @Test - public void testCreateWithNoParsed() throws Exception { - - Organization org = new Organization(); - org.addIdentifier().setValue("001"); - org.addIdentifier().setValue("002"); - - HttpPost httpPost = new HttpPost("http://localhost:" + ourPort + "/Organization"); - httpPost.setEntity(new StringEntity(new FhirContext().newJsonParser().encodeResourceToString(org), ContentType.create(Constants.CT_FHIR_JSON, "UTF-8"))); - - HttpResponse status = ourClient.execute(httpPost); - - String responseContent = IOUtils.toString(status.getEntity().getContent()); - IOUtils.closeQuietly(status.getEntity().getContent()); - ourLog.info("Response was:\n{}", responseContent); - - assertEquals(201, status.getStatusLine().getStatusCode()); - assertEquals("http://localhost:" + ourPort + "/Organization/001", status.getFirstHeader("location").getValue()); - assertThat(status.getFirstHeader(Constants.HEADER_CONTENT_TYPE).getValue(), StringContains.containsString("UTF-8")); - - assertThat(ourLastResourceBody, stringContainsInOrder("\"resourceType\":\"Organization\"", "\"identifier\"","\"value\":\"001")); - assertEquals(EncodingEnum.JSON, ourLastEncoding); - - } - @Test public void testCreateById() throws Exception { @@ -124,7 +99,7 @@ public class CreateTest { patient.addIdentifier().setValue("002"); HttpPost httpPost = new HttpPost("http://localhost:" + ourPort + "/Patient/1234"); - httpPost.setEntity(new StringEntity(new FhirContext().newXmlParser().encodeResourceToString(patient), ContentType.create(Constants.CT_FHIR_XML, "UTF-8"))); + httpPost.setEntity(new StringEntity(ourCtx.newXmlParser().encodeResourceToString(patient), ContentType.create(Constants.CT_FHIR_XML, "UTF-8"))); HttpResponse status = ourClient.execute(httpPost); @@ -144,7 +119,7 @@ public class CreateTest { obs.getIdentifier().setValue("001"); HttpPost httpPost = new HttpPost("http://localhost:" + ourPort + "/Observation"); - httpPost.setEntity(new StringEntity(new FhirContext().newJsonParser().encodeResourceToString(obs), ContentType.create(Constants.CT_FHIR_JSON, "UTF-8"))); + httpPost.setEntity(new StringEntity(ourCtx.newJsonParser().encodeResourceToString(obs), ContentType.create(Constants.CT_FHIR_JSON, "UTF-8"))); HttpResponse status = ourClient.execute(httpPost); @@ -166,7 +141,7 @@ public class CreateTest { patient.addIdentifier().setValue("002"); HttpPost httpPost = new HttpPost("http://localhost:" + ourPort + "/Patient"); - httpPost.setEntity(new StringEntity(new FhirContext().newJsonParser().encodeResourceToString(patient), ContentType.create(Constants.CT_FHIR_JSON, "UTF-8"))); + httpPost.setEntity(new StringEntity(ourCtx.newJsonParser().encodeResourceToString(patient), ContentType.create(Constants.CT_FHIR_JSON, "UTF-8"))); HttpResponse status = ourClient.execute(httpPost); @@ -180,6 +155,31 @@ public class CreateTest { } + @Test + public void testCreateWithNoParsed() throws Exception { + + Organization org = new Organization(); + org.addIdentifier().setValue("001"); + org.addIdentifier().setValue("002"); + + HttpPost httpPost = new HttpPost("http://localhost:" + ourPort + "/Organization"); + httpPost.setEntity(new StringEntity(ourCtx.newJsonParser().encodeResourceToString(org), ContentType.create(Constants.CT_FHIR_JSON, "UTF-8"))); + + HttpResponse status = ourClient.execute(httpPost); + + String responseContent = IOUtils.toString(status.getEntity().getContent()); + IOUtils.closeQuietly(status.getEntity().getContent()); + ourLog.info("Response was:\n{}", responseContent); + + assertEquals(201, status.getStatusLine().getStatusCode()); + assertEquals("http://localhost:" + ourPort + "/Organization/001", status.getFirstHeader("location").getValue()); + assertThat(status.getFirstHeader(Constants.HEADER_CONTENT_TYPE).getValue(), StringContains.containsString("UTF-8")); + + assertThat(ourLastResourceBody, stringContainsInOrder("\"resourceType\":\"Organization\"", "\"identifier\"","\"value\":\"001")); + assertEquals(EncodingEnum.JSON, ourLastEncoding); + + } + @Test public void testCreateWithUnprocessableEntity() throws Exception { @@ -187,7 +187,7 @@ public class CreateTest { report.getIdentifier().setValue("001"); HttpPost httpPost = new HttpPost("http://localhost:" + ourPort + "/DiagnosticReport"); - httpPost.setEntity(new StringEntity(new FhirContext().newXmlParser().encodeResourceToString(report), ContentType.create(Constants.CT_FHIR_XML, "UTF-8"))); + httpPost.setEntity(new StringEntity(ourCtx.newXmlParser().encodeResourceToString(report), ContentType.create(Constants.CT_FHIR_XML, "UTF-8"))); HttpResponse status = ourClient.execute(httpPost); @@ -198,7 +198,7 @@ public class CreateTest { assertEquals(422, status.getStatusLine().getStatusCode()); - OperationOutcome outcome = new FhirContext().newXmlParser().parseResource(OperationOutcome.class, new StringReader(responseContent)); + OperationOutcome outcome = ourCtx.newXmlParser().parseResource(OperationOutcome.class, new StringReader(responseContent)); assertEquals("FOOBAR", outcome.getIssueFirstRep().getDetails().getValue()); } @@ -218,7 +218,7 @@ public class CreateTest { ourReportProvider = new DiagnosticReportProvider(); ServletHandler proxyHandler = new ServletHandler(); - RestfulServer servlet = new RestfulServer(); + RestfulServer servlet = new RestfulServer(ourCtx); servlet.setResourceProviders( patientProvider, ourReportProvider, new DummyAdverseReactionResourceProvider(), new CustomObservationProvider(), new OrganizationProvider()); @@ -329,6 +329,23 @@ public class CreateTest { } + public static class OrganizationProvider implements IResourceProvider { + + @Create() + public MethodOutcome create(@ResourceParam String theResourceBody, @ResourceParam EncodingEnum theEncoding) { + ourLastResourceBody=theResourceBody; + ourLastEncoding=theEncoding; + + return new MethodOutcome(new IdDt("001")); + } + + @Override + public Class getResourceType() { + return Organization.class; + } + + } + public static class PatientProvider implements IResourceProvider { @Create() @@ -351,21 +368,4 @@ public class CreateTest { } - public static class OrganizationProvider implements IResourceProvider { - - @Create() - public MethodOutcome create(@ResourceParam String theResourceBody, @ResourceParam EncodingEnum theEncoding) { - ourLastResourceBody=theResourceBody; - ourLastEncoding=theEncoding; - - return new MethodOutcome(new IdDt("001")); - } - - @Override - public Class getResourceType() { - return Organization.class; - } - - } - } diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/CustomTypeTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/CustomTypeTest.java index 9e7e92f4147..2b1007f994d 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/CustomTypeTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/CustomTypeTest.java @@ -165,7 +165,7 @@ public class CustomTypeTest { DummyPatientResourceProvider patientProvider = new DummyPatientResourceProvider(); ServletHandler proxyHandler = new ServletHandler(); - ourServlet = new RestfulServer(); + ourServlet = new RestfulServer(ourCtx); ourServlet.getFhirContext().setNarrativeGenerator(new DefaultThymeleafNarrativeGenerator()); ourServlet.setResourceProviders(patientProvider); diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/DateRangeParamSearchTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/DateRangeParamSearchTest.java index a7fa5aa0a40..f2a642aa532 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/DateRangeParamSearchTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/DateRangeParamSearchTest.java @@ -20,6 +20,7 @@ import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; +import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.model.dstu.resource.Patient; import ca.uhn.fhir.narrative.DefaultThymeleafNarrativeGenerator; @@ -37,7 +38,8 @@ public class DateRangeParamSearchTest { private static CloseableHttpClient ourClient; private static int ourPort; private static Server ourServer; - + private static final FhirContext ourCtx = FhirContext.forDstu1(); + @Test public void testSearchForOneUnqualifiedDate() throws Exception { String baseUrl = "http://localhost:" + ourPort + "/Patient?" + Patient.SP_BIRTHDATE + "="; @@ -85,7 +87,7 @@ public class DateRangeParamSearchTest { DummyPatientResourceProvider patientProvider = new DummyPatientResourceProvider(); ServletHandler proxyHandler = new ServletHandler(); - RestfulServer servlet = new RestfulServer(); + RestfulServer servlet = new RestfulServer(ourCtx); servlet.getFhirContext().setNarrativeGenerator(new DefaultThymeleafNarrativeGenerator()); servlet.setResourceProviders(patientProvider); diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/DefaultEncodingTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/DefaultEncodingTest.java index 02050b47933..c1fcb31038e 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/DefaultEncodingTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/DefaultEncodingTest.java @@ -44,9 +44,8 @@ public class DefaultEncodingTest { private static CloseableHttpClient ourClient; private static int ourPort; private static Server ourServer; - private static FhirContext ourCtx; + private static final FhirContext ourCtx = FhirContext.forDstu1(); private static RestfulServer ourRestfulServer; - private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(DefaultEncodingTest.class); @Test public void testReadWithDefaultJsonPretty() throws Exception { @@ -135,8 +134,7 @@ public class DefaultEncodingTest { ourServer = new Server(ourPort); ServletHandler proxyHandler = new ServletHandler(); - ourRestfulServer = new RestfulServer(); - ourCtx = ourRestfulServer.getFhirContext(); + ourRestfulServer = new RestfulServer(ourCtx); ourRestfulServer.setResourceProviders(new PatientProvider()); ServletHolder servletHolder = new ServletHolder(ourRestfulServer); proxyHandler.addServletWithMapping(servletHolder, "/*"); diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/DestroyTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/DestroyTest.java index a41085cb5d3..c3816b6f4a6 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/DestroyTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/DestroyTest.java @@ -1,23 +1,22 @@ package ca.uhn.fhir.rest.server; +import static org.mockito.Mockito.*; + +import java.util.Arrays; + +import javax.servlet.ServletException; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.runners.MockitoJUnitRunner; + +import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.model.dstu.resource.DiagnosticReport; import ca.uhn.fhir.rest.annotation.Create; import ca.uhn.fhir.rest.annotation.Destroy; import ca.uhn.fhir.rest.annotation.ResourceParam; import ca.uhn.fhir.rest.api.MethodOutcome; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; - -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; - -import java.util.Arrays; - -import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.verify; /** * Created by Bill de Beaubien on 11/10/2014. @@ -26,70 +25,72 @@ import static org.mockito.Mockito.verify; @RunWith(MockitoJUnitRunner.class) public class DestroyTest { - @Test - public void testDestroyCallsAnnotatedMethodsOnProviders() throws ServletException { - RestfulServer servlet = new RestfulServer(); - DiagnosticReportProvider provider = spy(new DiagnosticReportProvider()); - servlet.setResourceProviders(Arrays.asList((IResourceProvider) provider)); - servlet.init(); - servlet.destroy(); - verify(provider).destroy(); - } + private static final FhirContext ourCtx = FhirContext.forDstu1(); - @Test - public void testChainsUpThroughSuperclasses() throws ServletException { - RestfulServer servlet = new RestfulServer(); - DerivedDiagnosticReportProvider provider = spy(new DerivedDiagnosticReportProvider()); - servlet.setResourceProviders(Arrays.asList((IResourceProvider) provider)); - servlet.init(); - servlet.destroy(); - verify(provider).destroy(); - } + @Test + public void testDestroyCallsAnnotatedMethodsOnProviders() throws ServletException { + RestfulServer servlet = new RestfulServer(ourCtx); + DiagnosticReportProvider provider = spy(new DiagnosticReportProvider()); + servlet.setResourceProviders(Arrays.asList((IResourceProvider) provider)); + servlet.init(); + servlet.destroy(); + verify(provider).destroy(); + } - @Test - public void testNoDestroyDoesNotCauseInfiniteRecursion() throws ServletException { - RestfulServer servlet = new RestfulServer(); - DiagnosticReportProviderSansDestroy provider = new DiagnosticReportProviderSansDestroy(); - servlet.setResourceProviders(Arrays.asList((IResourceProvider) provider)); - servlet.init(); - servlet.destroy(); - // nothing to verify other than the test didn't hang forever - } + @Test + public void testChainsUpThroughSuperclasses() throws ServletException { + RestfulServer servlet = new RestfulServer(ourCtx); + DerivedDiagnosticReportProvider provider = spy(new DerivedDiagnosticReportProvider()); + servlet.setResourceProviders(Arrays.asList((IResourceProvider) provider)); + servlet.init(); + servlet.destroy(); + verify(provider).destroy(); + } - public class DiagnosticReportProvider implements IResourceProvider { + @Test + public void testNoDestroyDoesNotCauseInfiniteRecursion() throws ServletException { + RestfulServer servlet = new RestfulServer(ourCtx); + DiagnosticReportProviderSansDestroy provider = new DiagnosticReportProviderSansDestroy(); + servlet.setResourceProviders(Arrays.asList((IResourceProvider) provider)); + servlet.init(); + servlet.destroy(); + // nothing to verify other than the test didn't hang forever + } - @Override - public Class getResourceType() { - return DiagnosticReport.class; - } + public class DiagnosticReportProvider implements IResourceProvider { - @Create - public MethodOutcome createResource(@ResourceParam DiagnosticReport theDiagnosticReport) { - // do nothing - return new MethodOutcome(); - } + @Override + public Class getResourceType() { + return DiagnosticReport.class; + } - @Destroy - public void destroy() { - // do nothing - } - } + @Create + public MethodOutcome createResource(@ResourceParam DiagnosticReport theDiagnosticReport) { + // do nothing + return new MethodOutcome(); + } - public class DerivedDiagnosticReportProvider extends DiagnosticReportProvider { - // move along, nothing to see here - } + @Destroy + public void destroy() { + // do nothing + } + } - public class DiagnosticReportProviderSansDestroy implements IResourceProvider { + public class DerivedDiagnosticReportProvider extends DiagnosticReportProvider { + // move along, nothing to see here + } - @Override - public Class getResourceType() { - return DiagnosticReport.class; - } + public class DiagnosticReportProviderSansDestroy implements IResourceProvider { - @Create - public MethodOutcome createResource(@ResourceParam DiagnosticReport theDiagnosticReport) { - // do nothing - return new MethodOutcome(); - } - } + @Override + public Class getResourceType() { + return DiagnosticReport.class; + } + + @Create + public MethodOutcome createResource(@ResourceParam DiagnosticReport theDiagnosticReport) { + // do nothing + return new MethodOutcome(); + } + } } diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/DynamicSearchTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/DynamicSearchTest.java index 278bdbb4855..63d06a264b1 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/DynamicSearchTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/DynamicSearchTest.java @@ -40,7 +40,7 @@ import ca.uhn.fhir.util.PortUtil; public class DynamicSearchTest { private static CloseableHttpClient ourClient; - private static FhirContext ourCtx = new FhirContext(); + private static FhirContext ourCtx = FhirContext.forDstu1(); private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(DynamicSearchTest.class); private static int ourPort; @@ -144,7 +144,7 @@ public class DynamicSearchTest { DummyPatientResourceProvider patientProvider = new DummyPatientResourceProvider(); ServletHandler proxyHandler = new ServletHandler(); - RestfulServer servlet = new RestfulServer(); + RestfulServer servlet = new RestfulServer(ourCtx); servlet.getFhirContext().setNarrativeGenerator(new DefaultThymeleafNarrativeGenerator()); servlet.setResourceProviders(patientProvider); diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ExceptionTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ExceptionTest.java index 7256483d443..3e9497daaa4 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ExceptionTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ExceptionTest.java @@ -23,6 +23,7 @@ import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; +import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.model.dstu.resource.OperationOutcome; import ca.uhn.fhir.model.dstu.resource.Patient; @@ -52,6 +53,7 @@ public class ExceptionTest { private static int ourPort; private static Server ourServer; private static RestfulServer servlet; + private static final FhirContext ourCtx = FhirContext.forDstu1(); @Before public void before() { @@ -189,7 +191,7 @@ public class ExceptionTest { DummyPatientResourceProvider patientProvider = new DummyPatientResourceProvider(); ServletHandler proxyHandler = new ServletHandler(); - servlet = new RestfulServer(); + servlet = new RestfulServer(ourCtx); servlet.setResourceProviders(patientProvider); ServletHolder servletHolder = new ServletHolder(servlet); proxyHandler.addServletWithMapping(servletHolder, "/*"); diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/HistoryTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/HistoryTest.java index 4f847eeb106..f26bec3c3c8 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/HistoryTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/HistoryTest.java @@ -37,9 +37,65 @@ import ca.uhn.fhir.util.PortUtil; public class HistoryTest { private static CloseableHttpClient ourClient; + private static FhirContext ourCtx= FhirContext.forDstu1(); private static int ourPort; + private static Server ourServer; + @Test + public void testInstanceHistory() throws Exception { + { + HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/123/_history"); + HttpResponse status = ourClient.execute(httpGet); + String responseContent = IOUtils.toString(status.getEntity().getContent()); + IOUtils.closeQuietly(status.getEntity().getContent()); + + assertEquals(200, status.getStatusLine().getStatusCode()); + + Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent); + assertEquals(2, bundle.getEntries().size()); + assertEquals("http://localhost:" + ourPort +"/Patient/ih1/_history/1", bundle.getEntries().get(0).getLinkSelf().getValue()); + assertEquals("http://localhost:" + ourPort +"/Patient/ih1/_history/2", bundle.getEntries().get(1).getLinkSelf().getValue()); + + } + } + + @Test + public void testServerHistory() throws Exception { + { + HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/_history"); + HttpResponse status = ourClient.execute(httpGet); + String responseContent = IOUtils.toString(status.getEntity().getContent()); + IOUtils.closeQuietly(status.getEntity().getContent()); + + assertEquals(200, status.getStatusLine().getStatusCode()); + + Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent); + assertEquals(2, bundle.getEntries().size()); + assertEquals("http://localhost:" + ourPort +"/Patient/h1/_history/1", bundle.getEntries().get(0).getLinkSelf().getValue()); + assertEquals("http://localhost:" + ourPort +"/Patient/h1/_history/2", bundle.getEntries().get(1).getLinkSelf().getValue()); + + } + } + + @Test + public void testTypeHistory() throws Exception { + { + HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/_history"); + HttpResponse status = ourClient.execute(httpGet); + String responseContent = IOUtils.toString(status.getEntity().getContent()); + IOUtils.closeQuietly(status.getEntity().getContent()); + + assertEquals(200, status.getStatusLine().getStatusCode()); + + Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent); + assertEquals(2, bundle.getEntries().size()); + assertEquals("http://localhost:" + ourPort +"/Patient/th1/_history/1", bundle.getEntries().get(0).getLinkSelf().getValue()); + assertEquals("http://localhost:" + ourPort +"/Patient/th1/_history/2", bundle.getEntries().get(1).getLinkSelf().getValue()); + + } + } + /** * We test this here because of bug 3- At one point VRead would "steal" instance history calls and handle them */ @@ -53,65 +109,11 @@ public class HistoryTest { assertEquals(200, status.getStatusLine().getStatusCode()); - Patient bundle = new FhirContext().newXmlParser().parseResource(Patient.class, responseContent); + Patient bundle = ourCtx.newXmlParser().parseResource(Patient.class, responseContent); assertEquals("vread", bundle.getNameFirstRep().getFamilyFirstRep().getValue()); } } - @Test - public void testServerHistory() throws Exception { - { - HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/_history"); - HttpResponse status = ourClient.execute(httpGet); - String responseContent = IOUtils.toString(status.getEntity().getContent()); - IOUtils.closeQuietly(status.getEntity().getContent()); - - assertEquals(200, status.getStatusLine().getStatusCode()); - - Bundle bundle = new FhirContext().newXmlParser().parseBundle(responseContent); - assertEquals(2, bundle.getEntries().size()); - assertEquals("http://localhost:" + ourPort +"/Patient/h1/_history/1", bundle.getEntries().get(0).getLinkSelf().getValue()); - assertEquals("http://localhost:" + ourPort +"/Patient/h1/_history/2", bundle.getEntries().get(1).getLinkSelf().getValue()); - - } - } - - @Test - public void testInstanceHistory() throws Exception { - { - HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/123/_history"); - HttpResponse status = ourClient.execute(httpGet); - String responseContent = IOUtils.toString(status.getEntity().getContent()); - IOUtils.closeQuietly(status.getEntity().getContent()); - - assertEquals(200, status.getStatusLine().getStatusCode()); - - Bundle bundle = new FhirContext().newXmlParser().parseBundle(responseContent); - assertEquals(2, bundle.getEntries().size()); - assertEquals("http://localhost:" + ourPort +"/Patient/ih1/_history/1", bundle.getEntries().get(0).getLinkSelf().getValue()); - assertEquals("http://localhost:" + ourPort +"/Patient/ih1/_history/2", bundle.getEntries().get(1).getLinkSelf().getValue()); - - } - } - - @Test - public void testTypeHistory() throws Exception { - { - HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/_history"); - HttpResponse status = ourClient.execute(httpGet); - String responseContent = IOUtils.toString(status.getEntity().getContent()); - IOUtils.closeQuietly(status.getEntity().getContent()); - - assertEquals(200, status.getStatusLine().getStatusCode()); - - Bundle bundle = new FhirContext().newXmlParser().parseBundle(responseContent); - assertEquals(2, bundle.getEntries().size()); - assertEquals("http://localhost:" + ourPort +"/Patient/th1/_history/1", bundle.getEntries().get(0).getLinkSelf().getValue()); - assertEquals("http://localhost:" + ourPort +"/Patient/th1/_history/2", bundle.getEntries().get(1).getLinkSelf().getValue()); - - } - } - @AfterClass public static void afterClass() throws Exception { ourServer.stop(); @@ -126,7 +128,7 @@ public class HistoryTest { DummyResourceProvider patientProvider = new DummyResourceProvider(); ServletHandler proxyHandler = new ServletHandler(); - RestfulServer servlet = new RestfulServer(); + RestfulServer servlet = new RestfulServer(ourCtx); servlet.setPlainProviders(plainProvider); servlet.setResourceProviders(patientProvider); ServletHolder servletHolder = new ServletHolder(servlet); @@ -141,59 +143,6 @@ public class HistoryTest { } - public static class DummyResourceProvider implements IResourceProvider { - - @Override - public Class getResourceType() { - return Patient.class; - } - - @Read(version=true) - public Patient vread(@IdParam IdDt theId) { - Patient retVal = new Patient(); - retVal.addName().addFamily("vread"); - retVal.setId(theId); - return retVal; - } - - @History - public List instanceHistory(@IdParam IdDt theId) { - ArrayList retVal = new ArrayList(); - - Patient patient = new Patient(); - patient.setId("Patient/ih1/_history/1"); - patient.addName().addFamily("history"); - retVal.add(patient); - - Patient patient2 = new Patient(); - patient2.setId("Patient/ih1/_history/2"); - patient2.addName().addFamily("history"); - retVal.add(patient2); - - return retVal; - } - - @History - public List typeHistory() { - ArrayList retVal = new ArrayList(); - - Patient patient = new Patient(); - patient.setId("Patient/th1/_history/1"); - patient.addName().addFamily("history"); - retVal.add(patient); - - Patient patient2 = new Patient(); - patient2.setId("Patient/th1/_history/2"); - patient2.addName().addFamily("history"); - retVal.add(patient2); - - return retVal; - } - - - } - - /** * Created by dsotnikov on 2/25/2014. */ @@ -219,6 +168,59 @@ public class HistoryTest { + } + + + public static class DummyResourceProvider implements IResourceProvider { + + @Override + public Class getResourceType() { + return Patient.class; + } + + @History + public List instanceHistory(@IdParam IdDt theId) { + ArrayList retVal = new ArrayList(); + + Patient patient = new Patient(); + patient.setId("Patient/ih1/_history/1"); + patient.addName().addFamily("history"); + retVal.add(patient); + + Patient patient2 = new Patient(); + patient2.setId("Patient/ih1/_history/2"); + patient2.addName().addFamily("history"); + retVal.add(patient2); + + return retVal; + } + + @History + public List typeHistory() { + ArrayList retVal = new ArrayList(); + + Patient patient = new Patient(); + patient.setId("Patient/th1/_history/1"); + patient.addName().addFamily("history"); + retVal.add(patient); + + Patient patient2 = new Patient(); + patient2.setId("Patient/th1/_history/2"); + patient2.addName().addFamily("history"); + retVal.add(patient2); + + return retVal; + } + + @Read(version=true) + public Patient vread(@IdParam IdDt theId) { + Patient retVal = new Patient(); + retVal.addName().addFamily("vread"); + retVal.setId(theId); + return retVal; + } + + } } diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/IncludeTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/IncludeTest.java index 8b05981ce1e..a05fa753f46 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/IncludeTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/IncludeTest.java @@ -88,9 +88,8 @@ public class IncludeTest { assertEquals("Hello", p.getId().getIdPart()); assertEquals("foo", p.getName().get(0).getFamilyFirstRep().getValue()); } - - -// @Test + + // @Test public void testMixedContainedAndNonContained() throws Exception { HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/DiagnosticReport?_query=stitchedInclude&_pretty=true"); HttpResponse status = ourClient.execute(httpGet); @@ -98,12 +97,11 @@ public class IncludeTest { IOUtils.closeQuietly(status.getEntity().getContent()); ourLog.info(responseContent); - + assertEquals(200, status.getStatusLine().getStatusCode()); Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent); assertEquals(4, bundle.size()); } - @Test public void testIIncludedResourcesNonContained() throws Exception { @@ -114,23 +112,22 @@ public class IncludeTest { assertEquals(200, status.getStatusLine().getStatusCode()); Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent); - + ourLog.info(responseContent); - + assertEquals(3, bundle.size()); assertEquals(new IdDt("Patient/p1"), bundle.toListOfResources().get(0).getId().toUnqualifiedVersionless()); assertEquals(new IdDt("Patient/p2"), bundle.toListOfResources().get(1).getId().toUnqualifiedVersionless()); assertEquals(new IdDt("Organization/o1"), bundle.toListOfResources().get(2).getId().toUnqualifiedVersionless()); - - Patient p1 = (Patient) bundle.toListOfResources().get(0); - assertEquals(0,p1.getContained().getContainedResources().size()); - - Patient p2 = (Patient) bundle.toListOfResources().get(1); - assertEquals(0,p2.getContained().getContainedResources().size()); - + Patient p1 = (Patient) bundle.toListOfResources().get(0); + assertEquals(0, p1.getContained().getContainedResources().size()); + + Patient p2 = (Patient) bundle.toListOfResources().get(1); + assertEquals(0, p2.getContained().getContainedResources().size()); + } - + @Test public void testIIncludedResourcesNonContainedInExtension() throws Exception { HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?_query=extInclude&_pretty=true"); @@ -140,24 +137,22 @@ public class IncludeTest { assertEquals(200, status.getStatusLine().getStatusCode()); Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent); - + ourLog.info(responseContent); - + assertEquals(3, bundle.size()); assertEquals(new IdDt("Patient/p1"), bundle.toListOfResources().get(0).getId().toUnqualifiedVersionless()); assertEquals(new IdDt("Patient/p2"), bundle.toListOfResources().get(1).getId().toUnqualifiedVersionless()); assertEquals(new IdDt("Organization/o1"), bundle.toListOfResources().get(2).getId().toUnqualifiedVersionless()); - - Patient p1 = (Patient) bundle.toListOfResources().get(0); - assertEquals(0,p1.getContained().getContainedResources().size()); - - Patient p2 = (Patient) bundle.toListOfResources().get(1); - assertEquals(0,p2.getContained().getContainedResources().size()); - + Patient p1 = (Patient) bundle.toListOfResources().get(0); + assertEquals(0, p1.getContained().getContainedResources().size()); + + Patient p2 = (Patient) bundle.toListOfResources().get(1); + assertEquals(0, p2.getContained().getContainedResources().size()); + } - - + @Test public void testIIncludedResourcesNonContainedInExtensionJson() throws Exception { HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?_query=extInclude&_pretty=true&_format=json"); @@ -167,21 +162,20 @@ public class IncludeTest { assertEquals(200, status.getStatusLine().getStatusCode()); Bundle bundle = ourCtx.newJsonParser().parseBundle(responseContent); - + ourLog.info(responseContent); - + assertEquals(3, bundle.size()); assertEquals(new IdDt("Patient/p1"), bundle.toListOfResources().get(0).getId().toUnqualifiedVersionless()); assertEquals(new IdDt("Patient/p2"), bundle.toListOfResources().get(1).getId().toUnqualifiedVersionless()); assertEquals(new IdDt("Organization/o1"), bundle.toListOfResources().get(2).getId().toUnqualifiedVersionless()); - - Patient p1 = (Patient) bundle.toListOfResources().get(0); - assertEquals(0,p1.getContained().getContainedResources().size()); - - Patient p2 = (Patient) bundle.toListOfResources().get(1); - assertEquals(0,p2.getContained().getContainedResources().size()); - + Patient p1 = (Patient) bundle.toListOfResources().get(0); + assertEquals(0, p1.getContained().getContainedResources().size()); + + Patient p2 = (Patient) bundle.toListOfResources().get(1); + assertEquals(0, p2.getContained().getContainedResources().size()); + } @Test @@ -193,26 +187,23 @@ public class IncludeTest { assertEquals(200, status.getStatusLine().getStatusCode()); Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent); - + ourLog.info(responseContent); - + assertEquals(4, bundle.size()); assertEquals(new IdDt("Patient/p1"), bundle.toListOfResources().get(0).getId().toUnqualifiedVersionless()); assertEquals(new IdDt("Patient/p2"), bundle.toListOfResources().get(1).getId().toUnqualifiedVersionless()); assertEquals(new IdDt("Organization/o1"), bundle.toListOfResources().get(2).getId().toUnqualifiedVersionless()); assertEquals(new IdDt("Organization/o2"), bundle.toListOfResources().get(3).getId().toUnqualifiedVersionless()); - + Patient p1 = (Patient) bundle.toListOfResources().get(0); - assertEquals(0,p1.getContained().getContainedResources().size()); - + assertEquals(0, p1.getContained().getContainedResources().size()); + Patient p2 = (Patient) bundle.toListOfResources().get(1); - assertEquals(0,p2.getContained().getContainedResources().size()); + assertEquals(0, p2.getContained().getContainedResources().size()); - } - - @Test public void testTwoInclude() throws Exception { HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?name=Hello&_include=foo&_include=bar"); @@ -229,10 +220,10 @@ public class IncludeTest { assertEquals("Hello", p.getId().getIdPart()); Set values = new HashSet(); - values.add( p.getName().get(0).getFamilyFirstRep().getValue()); - values.add( p.getName().get(1).getFamilyFirstRep().getValue()); + values.add(p.getName().get(0).getFamilyFirstRep().getValue()); + values.add(p.getName().get(1).getFamilyFirstRep().getValue()); assertThat(values, containsInAnyOrder("foo", "bar")); - + } @Test @@ -242,9 +233,9 @@ public class IncludeTest { assertEquals(400, status.getStatusLine().getStatusCode()); String responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent()); - + ourLog.info(responseContent); - assertThat(responseContent,containsString("Invalid _include parameter value")); + assertThat(responseContent, containsString("Invalid _include parameter value")); } @AfterClass @@ -254,17 +245,16 @@ public class IncludeTest { @BeforeClass public static void beforeClass() throws Exception { - - ourCtx = new FhirContext(); + + ourCtx = FhirContext.forDstu1(); ourPort = PortUtil.findFreePort(); ourServer = new Server(ourPort); DummyPatientResourceProvider patientProvider = new DummyPatientResourceProvider(); ServletHandler proxyHandler = new ServletHandler(); - RestfulServer servlet = new RestfulServer(); - servlet.setFhirContext(ourCtx); - servlet.setBundleInclusionRule(BundleInclusionRule.BASED_ON_RESOURCE_PRESENCE); + RestfulServer servlet = new RestfulServer(ourCtx); + servlet.setBundleInclusionRule(BundleInclusionRule.BASED_ON_RESOURCE_PRESENCE); servlet.setResourceProviders(patientProvider, new DummyDiagnosticReportResourceProvider()); ServletHolder servletHolder = new ServletHolder(servlet); proxyHandler.addServletWithMapping(servletHolder, "/*"); @@ -278,11 +268,10 @@ public class IncludeTest { } - @ResourceDef(name="Patient") - public static class ExtPatient extends Patient - { - @Child(name="secondOrg") - @Extension(url="http://foo#secondOrg", definedLocally = false, isModifier = false) + @ResourceDef(name = "Patient") + public static class ExtPatient extends Patient { + @Child(name = "secondOrg") + @Extension(url = "http://foo#secondOrg", definedLocally = false, isModifier = false) private ResourceReferenceDt mySecondOrg; @Override @@ -291,8 +280,8 @@ public class IncludeTest { } public ResourceReferenceDt getSecondOrg() { - if (mySecondOrg==null) { - mySecondOrg= new ResourceReferenceDt(); + if (mySecondOrg == null) { + mySecondOrg = new ResourceReferenceDt(); } return mySecondOrg; } @@ -300,9 +289,9 @@ public class IncludeTest { public void setSecondOrg(ResourceReferenceDt theSecondOrg) { mySecondOrg = theSecondOrg; } - + } - + /** * Created by dsotnikov on 2/25/2014. */ @@ -312,7 +301,7 @@ public class IncludeTest { public Class getResourceType() { return DiagnosticReport.class; } - + @Search(queryName = "stitchedInclude") public List stitchedInclude() { Practitioner pr1 = new Practitioner(); @@ -330,11 +319,11 @@ public class IncludeTest { Observation o1 = new Observation(); o1.getName().setText("Obs1"); o1.addPerformer().setResource(pr1); - + Observation o2 = new Observation(); o2.getName().setText("Obs2"); o2.addPerformer().setResource(pr2); - + Observation o3 = new Observation(); o3.getName().setText("Obs3"); o3.addPerformer().setResource(pr3); @@ -345,15 +334,12 @@ public class IncludeTest { rep.addResult().setResource(o1); rep.addResult().setResource(o2); rep.addResult().setResource(o3); - + return Collections.singletonList(rep); } - - - + } - - + /** * Created by dsotnikov on 2/25/2014. */ @@ -377,8 +363,7 @@ public class IncludeTest { return Arrays.asList(p1, p2); } - - + @Search(queryName = "extInclude") public List extInclude() { Organization o1 = new Organization(); @@ -408,7 +393,7 @@ public class IncludeTest { o2.getName().setValue("o2"); o2.setId("o2"); o1.getPartOf().setResource(o2); - + ExtPatient p1 = new ExtPatient(); p1.setId("p1"); p1.addIdentifier().setLabel("p1"); @@ -422,7 +407,6 @@ public class IncludeTest { return Arrays.asList(p1, p2); } - @Search(queryName = "containedInclude") public List containedInclude() { Organization o1 = new Organization(); @@ -440,11 +424,9 @@ public class IncludeTest { return Arrays.asList(p1, p2); } - + @Search - public List findPatientWithSimpleNames( - @RequiredParam(name = Patient.SP_NAME) StringDt theName, - @IncludeParam(allow = { "foo", "bar" }) Set theIncludes) { + public List findPatientWithSimpleNames(@RequiredParam(name = Patient.SP_NAME) StringDt theName, @IncludeParam(allow = { "foo", "bar" }) Set theIncludes) { ArrayList retVal = new ArrayList(); Patient p = new Patient(); @@ -469,23 +451,21 @@ public class IncludeTest { } - public static void main(String[] args) { - + Organization org = new Organization(); org.setId("Organization/65546"); org.getName().setValue("Contained Test Organization"); - + Patient patient = new Patient(); patient.setId("Patient/1333"); patient.addIdentifier("urn:mrns", "253345"); patient.getManagingOrganization().setResource(patient); - - - System.out.println(new FhirContext().newXmlParser().setPrettyPrint(true).encodeResourceToString(patient)); - + + System.out.println(FhirContext.forDstu1().newXmlParser().setPrettyPrint(true).encodeResourceToString(patient)); + patient.getManagingOrganization().getReference(); - + } - + } diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/InterceptorTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/InterceptorTest.java index 98fd750b3c4..4450d67024c 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/InterceptorTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/InterceptorTest.java @@ -27,6 +27,7 @@ import org.junit.BeforeClass; import org.junit.Test; import org.mockito.InOrder; +import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.model.dstu.composite.HumanNameDt; import ca.uhn.fhir.model.dstu.composite.IdentifierDt; @@ -53,6 +54,7 @@ public class InterceptorTest { private static RestfulServer servlet; private IServerInterceptor myInterceptor1; private IServerInterceptor myInterceptor2; + private static final FhirContext ourCtx = FhirContext.forDstu1(); @Test public void testInterceptorFires() throws Exception { @@ -101,7 +103,7 @@ public class InterceptorTest { DummyPatientResourceProvider patientProvider = new DummyPatientResourceProvider(); ServletHandler proxyHandler = new ServletHandler(); - servlet = new RestfulServer(); + servlet = new RestfulServer(ourCtx); servlet.setResourceProviders(patientProvider); ServletHolder servletHolder = new ServletHolder(servlet); proxyHandler.addServletWithMapping(servletHolder, "/*"); diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/MethodPriorityTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/MethodPriorityTest.java index 92b5b180f51..a2ef5162b9a 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/MethodPriorityTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/MethodPriorityTest.java @@ -36,7 +36,7 @@ import ca.uhn.fhir.util.PortUtil; public class MethodPriorityTest { private static CloseableHttpClient ourClient; - private static FhirContext ourCtx = new FhirContext(); + private static FhirContext ourCtx = FhirContext.forDstu1(); private static int ourPort; private static Server ourServer; private static RestfulServer ourServlet; @@ -72,8 +72,7 @@ public class MethodPriorityTest { ourServer = new Server(ourPort); ServletHandler proxyHandler = new ServletHandler(); - ourServlet = new RestfulServer(); - ourServlet.setFhirContext(ourCtx); + ourServlet = new RestfulServer(ourCtx); ourServlet.getFhirContext().setNarrativeGenerator(new DefaultThymeleafNarrativeGenerator()); ServletHolder servletHolder = new ServletHolder(ourServlet); diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/PagingTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/PagingTest.java index 77feec9e662..5ed0f3391a1 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/PagingTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/PagingTest.java @@ -46,6 +46,7 @@ public class PagingTest { private static CloseableHttpClient ourClient; private static int ourPort; + private static final FhirContext ourCtx = FhirContext.forDstu1(); private static Server ourServer; private static FhirContext ourContext; private static RestfulServer myRestfulServer; @@ -270,7 +271,7 @@ public class PagingTest { @BeforeClass public static void beforeClass() throws Exception { - ourContext = new FhirContext(); + ourContext = FhirContext.forDstu1(); ourPort = PortUtil.findFreePort(); ourServer = new Server(ourPort); @@ -278,7 +279,7 @@ public class PagingTest { DummyPatientResourceProvider patientProvider = new DummyPatientResourceProvider(); ServletHandler proxyHandler = new ServletHandler(); - myRestfulServer = new RestfulServer(); + myRestfulServer = new RestfulServer(ourCtx); myRestfulServer.setResourceProviders(patientProvider); ServletHolder servletHolder = new ServletHolder(myRestfulServer); proxyHandler.addServletWithMapping(servletHolder, "/*"); diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/PlainProviderTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/PlainProviderTest.java index 325ee42d0c4..2d2c59cadd4 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/PlainProviderTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/PlainProviderTest.java @@ -51,18 +51,17 @@ public class PlainProviderTest { private int myPort; private Server myServer; private CloseableHttpClient myClient; - private FhirContext myCtx; + private static final FhirContext ourCtx = FhirContext.forDstu1(); private RestfulServer myRestfulServer; @Before public void before() throws Exception { myPort = PortUtil.findFreePort(); myServer = new Server(myPort); - myCtx = new FhirContext(Patient.class); ServletHandler proxyHandler = new ServletHandler(); ServletHolder servletHolder = new ServletHolder(); - myRestfulServer = new RestfulServer(); + myRestfulServer = new RestfulServer(ourCtx); servletHolder.setServlet(myRestfulServer); proxyHandler.addServletWithMapping(servletHolder, "/fhir/context/*"); myServer.setHandler(proxyHandler); @@ -95,7 +94,7 @@ public class PlainProviderTest { ourLog.info("Response was:\n{}", responseContent); assertEquals(200, status.getStatusLine().getStatusCode()); - Bundle bundle = myCtx.newXmlParser().parseBundle(responseContent); + Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent); assertEquals(1, bundle.getEntries().size()); @@ -121,7 +120,7 @@ public class PlainProviderTest { IOUtils.closeQuietly(status.getEntity().getContent()); ourLog.info("Response was:\n{}", responseContent); assertEquals(200, status.getStatusLine().getStatusCode()); - Bundle bundle = myCtx.newXmlParser().parseBundle(responseContent); + Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent); assertEquals(3, bundle.getEntries().size()); assertThat(provider.myLastSince.getValueAsString(), StringStartsWith.startsWith("2012-01-02T00:01:02")); @@ -131,7 +130,7 @@ public class PlainProviderTest { responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent()); assertEquals(200, status.getStatusLine().getStatusCode()); - bundle = myCtx.newXmlParser().parseBundle(responseContent); + bundle = ourCtx.newXmlParser().parseBundle(responseContent); assertEquals(3, bundle.getEntries().size()); assertNull(provider.myLastSince.getValueAsString()); assertThat(provider.myLastCount.getValueAsString(), IsEqual.equalTo("12")); @@ -140,7 +139,7 @@ public class PlainProviderTest { responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent()); assertEquals(200, status.getStatusLine().getStatusCode()); - bundle = myCtx.newXmlParser().parseBundle(responseContent); + bundle = ourCtx.newXmlParser().parseBundle(responseContent); assertEquals(3, bundle.getEntries().size()); assertThat(provider.myLastSince.getValueAsString(), StringStartsWith.startsWith("2012-01-02T00:01:02")); assertNull(provider.myLastCount.getValueAsString()); @@ -149,7 +148,7 @@ public class PlainProviderTest { responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent()); assertEquals(200, status.getStatusLine().getStatusCode()); - bundle = myCtx.newXmlParser().parseBundle(responseContent); + bundle = ourCtx.newXmlParser().parseBundle(responseContent); assertEquals(3, bundle.getEntries().size()); assertNull(provider.myLastSince.getValueAsString()); assertNull(provider.myLastCount.getValueAsString()); diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ReadTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ReadDstu1Test.java similarity index 96% rename from hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ReadTest.java rename to hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ReadDstu1Test.java index 70b63010e84..6392fb9265a 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ReadTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ReadDstu1Test.java @@ -1,10 +1,8 @@ package ca.uhn.fhir.rest.server; -import static org.hamcrest.Matchers.not; -import static org.hamcrest.Matchers.stringContainsInOrder; +import static org.hamcrest.Matchers.*; import static org.junit.Assert.*; -import java.io.IOException; import java.net.URLEncoder; import java.util.concurrent.TimeUnit; @@ -22,8 +20,6 @@ import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; -import com.google.common.net.UrlEscapers; - import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.model.dstu.composite.IdentifierDt; @@ -39,13 +35,13 @@ import ca.uhn.fhir.util.PortUtil; /** * Created by dsotnikov on 2/25/2014. */ -public class ReadTest { +public class ReadDstu1Test { private static CloseableHttpClient ourClient; private static int ourPort; private static Server ourServer; - private static FhirContext ourCtx; - private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ReadTest.class); + private static final FhirContext ourCtx = FhirContext.forDstu1(); + private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ReadDstu1Test.class); @Test public void testReadXml() throws Exception { @@ -68,7 +64,7 @@ public class ReadTest { assertThat(responseContent, stringContainsInOrder("1", "\"")); assertThat(responseContent, not(stringContainsInOrder("1", "\"", "1"))); } - + @Test public void testEncodeConvertsReferencesToRelative() throws Exception { HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/1?_format=xml"); @@ -205,8 +201,8 @@ public class ReadTest { PatientProvider patientProvider = new PatientProvider(); ServletHandler proxyHandler = new ServletHandler(); - RestfulServer servlet = new RestfulServer(); - ourCtx = servlet.getFhirContext(); + RestfulServer servlet = new RestfulServer(ourCtx); + servlet.setResourceProviders(patientProvider, new BinaryProvider(), new OrganizationProviderWithAbstractReturnType()); ServletHolder servletHolder = new ServletHolder(servlet); proxyHandler.addServletWithMapping(servletHolder, "/*"); diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ReferenceParameterTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ReferenceParameterTest.java index 020b33dd062..3c793c04fb9 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ReferenceParameterTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ReferenceParameterTest.java @@ -53,7 +53,7 @@ import ca.uhn.fhir.util.PortUtil; public class ReferenceParameterTest { private static CloseableHttpClient ourClient; - private static FhirContext ourCtx; + private static final FhirContext ourCtx = FhirContext.forDstu1(); private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ReferenceParameterTest.class); private static int ourPort; private static Server ourServer; @@ -298,9 +298,8 @@ public class ReferenceParameterTest { DummyPatientResourceProvider patientProvider = new DummyPatientResourceProvider(); ServletHandler proxyHandler = new ServletHandler(); - RestfulServer servlet = new RestfulServer(); + RestfulServer servlet = new RestfulServer(ourCtx); servlet.setBundleInclusionRule(BundleInclusionRule.BASED_ON_RESOURCE_PRESENCE); - ourCtx = servlet.getFhirContext(); servlet.setResourceProviders(patientProvider, new DummyOrganizationResourceProvider(), new DummyLocationResourceProvider()); ServletHolder servletHolder = new ServletHolder(servlet); proxyHandler.addServletWithMapping(servletHolder, "/*"); @@ -311,8 +310,6 @@ public class ReferenceParameterTest { HttpClientBuilder builder = HttpClientBuilder.create(); builder.setConnectionManager(connectionManager); ourClient = builder.build(); - - ourCtx = servlet.getFhirContext(); } public static class DummyLocationResourceProvider implements IResourceProvider { diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ResourceMethodTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ResourceMethodTest.java index 9376769a601..22deabb3c20 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ResourceMethodTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ResourceMethodTest.java @@ -32,7 +32,7 @@ public class ResourceMethodTest { @Before public void before() throws NoSuchMethodException, SecurityException { - rm = new SearchMethodBinding(Patient.class, ResourceMethodTest.class.getMethod("foo"), new FhirContext(), null); + rm = new SearchMethodBinding(Patient.class, ResourceMethodTest.class.getMethod("foo"), FhirContext.forDstu1(), null); } @Test diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ResourceProviderWithNoMethodsTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ResourceProviderWithNoMethodsTest.java index 18a0b82d6bf..4d6bf68c48b 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ResourceProviderWithNoMethodsTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ResourceProviderWithNoMethodsTest.java @@ -10,6 +10,7 @@ import org.eclipse.jetty.servlet.ServletHolder; import org.junit.After; import org.junit.Test; +import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.model.dstu.resource.Binary; import ca.uhn.fhir.model.primitive.IdDt; @@ -20,7 +21,8 @@ import ca.uhn.fhir.util.PortUtil; public class ResourceProviderWithNoMethodsTest { private Server ourServer; - + private static final FhirContext ourCtx = FhirContext.forDstu1(); + @After public void after() throws Exception { ourServer.stop(); @@ -34,7 +36,7 @@ public class ResourceProviderWithNoMethodsTest { ResourceProvider patientProvider = new ResourceProvider(); ServletHandler proxyHandler = new ServletHandler(); - RestfulServer servlet = new RestfulServer(); + RestfulServer servlet = new RestfulServer(ourCtx); servlet.setResourceProviders(patientProvider); ServletHolder servletHolder = new ServletHolder(servlet); proxyHandler.addServletWithMapping(servletHolder, "/*"); @@ -56,7 +58,7 @@ public class ResourceProviderWithNoMethodsTest { NonPublicMethodProvider patientProvider = new NonPublicMethodProvider(); ServletHandler proxyHandler = new ServletHandler(); - RestfulServer servlet = new RestfulServer(); + RestfulServer servlet = new RestfulServer(ourCtx); servlet.setResourceProviders(patientProvider); ServletHolder servletHolder = new ServletHolder(servlet); proxyHandler.addServletWithMapping(servletHolder, "/*"); diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/RestfulServerMethodTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/RestfulServerMethodTest.java index 6dbd4368eea..852e897b4ed 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/RestfulServerMethodTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/RestfulServerMethodTest.java @@ -91,7 +91,7 @@ import ca.uhn.fhir.util.PortUtil; public class RestfulServerMethodTest { private static CloseableHttpClient ourClient; - private static FhirContext ourCtx; + private static final FhirContext ourCtx = FhirContext.forDstu1(); private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(RestfulServerMethodTest.class); private static int ourPort; private static DummyDiagnosticReportResourceProvider ourReportProvider; @@ -943,7 +943,7 @@ public class RestfulServerMethodTest { assertEquals("BBB", patient.getName().get(0).getGiven().get(0).getValue()); } - + @Test public void testValidate() throws Exception { @@ -951,7 +951,7 @@ public class RestfulServerMethodTest { patient.addName().addFamily("FOO"); HttpPost httpPost = new HttpPost("http://localhost:" + ourPort + "/Patient/_validate"); - httpPost.setEntity(new StringEntity(new FhirContext().newXmlParser().encodeResourceToString(patient), ContentType.create(Constants.CT_FHIR_XML, "UTF-8"))); + httpPost.setEntity(new StringEntity(ourCtx.newXmlParser().encodeResourceToString(patient), ContentType.create(Constants.CT_FHIR_XML, "UTF-8"))); HttpResponse status = ourClient.execute(httpPost); @@ -962,7 +962,7 @@ public class RestfulServerMethodTest { assertThat(responseContent, not(containsString("\n "))); assertEquals(200, status.getStatusLine().getStatusCode()); - OperationOutcome oo = new FhirContext().newXmlParser().parseResource(OperationOutcome.class, responseContent); + OperationOutcome oo = ourCtx.newXmlParser().parseResource(OperationOutcome.class, responseContent); assertEquals("it passed", oo.getIssueFirstRep().getDetails().getValue()); // Now should fail @@ -971,7 +971,7 @@ public class RestfulServerMethodTest { patient.addName().addFamily("BAR"); httpPost = new HttpPost("http://localhost:" + ourPort + "/Patient/_validate"); - httpPost.setEntity(new StringEntity(new FhirContext().newXmlParser().encodeResourceToString(patient), ContentType.create(Constants.CT_FHIR_XML, "UTF-8"))); + httpPost.setEntity(new StringEntity(ourCtx.newXmlParser().encodeResourceToString(patient), ContentType.create(Constants.CT_FHIR_XML, "UTF-8"))); status = ourClient.execute(httpPost); @@ -981,7 +981,7 @@ public class RestfulServerMethodTest { ourLog.info("Response was:\n{}", responseContent); assertEquals(422, status.getStatusLine().getStatusCode()); - oo = new FhirContext().newXmlParser().parseResource(OperationOutcome.class, responseContent); + oo = ourCtx.newXmlParser().parseResource(OperationOutcome.class, responseContent); assertEquals("it failed", oo.getIssueFirstRep().getDetails().getValue()); // Should fail with outcome @@ -990,7 +990,7 @@ public class RestfulServerMethodTest { patient.addName().addFamily("BAZ"); httpPost = new HttpPost("http://localhost:" + ourPort + "/Patient/_validate"); - httpPost.setEntity(new StringEntity(new FhirContext().newXmlParser().encodeResourceToString(patient), ContentType.create(Constants.CT_FHIR_XML, "UTF-8"))); + httpPost.setEntity(new StringEntity(ourCtx.newXmlParser().encodeResourceToString(patient), ContentType.create(Constants.CT_FHIR_XML, "UTF-8"))); status = ourClient.execute(httpPost); @@ -1010,7 +1010,7 @@ public class RestfulServerMethodTest { patient.addName().addFamily("FOO"); HttpPost httpPost = new HttpPost("http://localhost:" + ourPort + "/Patient/_validate?_pretty=true"); - httpPost.setEntity(new StringEntity(new FhirContext().newXmlParser().encodeResourceToString(patient), ContentType.create(Constants.CT_FHIR_XML, "UTF-8"))); + httpPost.setEntity(new StringEntity(ourCtx.newXmlParser().encodeResourceToString(patient), ContentType.create(Constants.CT_FHIR_XML, "UTF-8"))); HttpResponse status = ourClient.execute(httpPost); @@ -1065,7 +1065,6 @@ public class RestfulServerMethodTest { public static void beforeClass() throws Exception { ourPort = PortUtil.findFreePort(); ourServer = new Server(ourPort); - ourCtx = new FhirContext(Patient.class); DummyPatientResourceProvider patientProvider = new DummyPatientResourceProvider(); ourReportProvider = new DummyDiagnosticReportResourceProvider(); @@ -1429,6 +1428,7 @@ public class RestfulServerMethodTest { private Collection myResourceProviders; public DummyRestfulServer(IResourceProvider... theResourceProviders) { + super(ourCtx); myResourceProviders = new ArrayList(Arrays.asList(theResourceProviders)); } diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/RestfulServerSelfReferenceTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/RestfulServerSelfReferenceTest.java index 2ec76f3ba3d..797a894b9e4 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/RestfulServerSelfReferenceTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/RestfulServerSelfReferenceTest.java @@ -62,7 +62,7 @@ public class RestfulServerSelfReferenceTest { int port = PortUtil.findFreePort(); Server server = new Server(port); - RestfulServer restServer = new RestfulServer(); + RestfulServer restServer = new RestfulServer(ourCtx); restServer.setFhirContext(ourCtx); restServer.setResourceProviders(new DummyPatientResourceProvider()); @@ -108,7 +108,7 @@ public class RestfulServerSelfReferenceTest { DummyPatientResourceProvider patientProvider = new DummyPatientResourceProvider(); ServletHandler proxyHandler = new ServletHandler(); - RestfulServer server = new RestfulServer(); + RestfulServer server = new RestfulServer(ourCtx); ServerProfileProvider profProvider = new ServerProfileProvider(server); server.setFhirContext(ourCtx); server.setResourceProviders(patientProvider, profProvider); diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/SearchTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/SearchSearchServerDstu1Test.java similarity index 99% rename from hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/SearchTest.java rename to hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/SearchSearchServerDstu1Test.java index 270678b11b9..be6e5c69b4f 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/SearchTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/SearchSearchServerDstu1Test.java @@ -66,11 +66,11 @@ import com.google.common.net.UrlEscapers; /** * Created by dsotnikov on 2/25/2014. */ -public class SearchTest { +public class SearchSearchServerDstu1Test { private static CloseableHttpClient ourClient; - private static FhirContext ourCtx = new FhirContext(); - private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(SearchTest.class); + private static FhirContext ourCtx = FhirContext.forDstu1(); + private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(SearchSearchServerDstu1Test.class); private static int ourPort; private static Server ourServer; diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ServerBaseTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ServerBaseTest.java index 1e98cb7b04a..cd21f730349 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ServerBaseTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ServerBaseTest.java @@ -35,7 +35,7 @@ public class ServerBaseTest { private static CloseableHttpClient ourClient; private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ServerBaseTest.class); private Server myServer; - private static FhirContext ourCtx = new FhirContext(); + private static FhirContext ourCtx = FhirContext.forDstu1(); @Test public void testTransaction() throws Exception { diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ServerConformanceProviderTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ServerConformanceProviderTest.java index 09eeaa570c9..78b46fbcd4a 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ServerConformanceProviderTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ServerConformanceProviderTest.java @@ -41,12 +41,12 @@ import javax.servlet.http.HttpServletRequest; public class ServerConformanceProviderTest { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ServerConformanceProviderTest.class); - private FhirContext myCtx = new FhirContext(); + private static FhirContext ourCtx = FhirContext.forDstu1(); @Test public void testSearchParameterDocumentation() throws Exception { - RestfulServer rs = new RestfulServer(); + RestfulServer rs = new RestfulServer(ourCtx); rs.setProviders(new SearchProvider()); ServerConformanceProvider sc = new ServerConformanceProvider(rs); @@ -68,7 +68,7 @@ public class ServerConformanceProviderTest { assertTrue(found); Conformance conformance = sc.getServerConformance(createHttpServletRequest()); - String conf = myCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(conformance); + String conf = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(conformance); ourLog.info(conf); assertThat(conf, containsString("")); @@ -80,7 +80,7 @@ public class ServerConformanceProviderTest { @Test public void testValidateGeneratedStatement() throws Exception { - RestfulServer rs = new RestfulServer(); + RestfulServer rs = new RestfulServer(ourCtx); rs.setProviders(new MultiOptionalProvider()); ServerConformanceProvider sc = new ServerConformanceProvider(rs); @@ -90,7 +90,7 @@ public class ServerConformanceProviderTest { Conformance conformance = sc.getServerConformance(createHttpServletRequest()); - myCtx.newValidator().validate(conformance); + ourCtx.newValidator().validate(conformance); } @@ -98,7 +98,7 @@ public class ServerConformanceProviderTest { @Test public void testMultiOptionalDocumentation() throws Exception { - RestfulServer rs = new RestfulServer(); + RestfulServer rs = new RestfulServer(ourCtx); rs.setProviders(new MultiOptionalProvider()); ServerConformanceProvider sc = new ServerConformanceProvider(rs); @@ -119,7 +119,7 @@ public class ServerConformanceProviderTest { } assertTrue(found); Conformance conformance = sc.getServerConformance(createHttpServletRequest()); - String conf = new FhirContext().newXmlParser().setPrettyPrint(true).encodeResourceToString(conformance); + String conf = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(conformance); ourLog.info(conf); assertThat(conf, containsString("")); @@ -130,7 +130,7 @@ public class ServerConformanceProviderTest { @Test public void testProviderWithRequiredAndOptional() throws Exception { - RestfulServer rs = new RestfulServer(); + RestfulServer rs = new RestfulServer(ourCtx); rs.setProviders(new ProviderWithRequiredAndOptional()); ServerConformanceProvider sc = new ServerConformanceProvider(rs); @@ -139,7 +139,7 @@ public class ServerConformanceProviderTest { rs.init(createServletConfig()); Conformance conformance = sc.getServerConformance(createHttpServletRequest()); - String conf = new FhirContext().newXmlParser().setPrettyPrint(true).encodeResourceToString(conformance); + String conf = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(conformance); ourLog.info(conf); Rest rest = conformance.getRestFirstRep(); diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ServerExtraParametersTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ServerExtraParametersTest.java index ae0d9f27a97..8eba44b4a0d 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ServerExtraParametersTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ServerExtraParametersTest.java @@ -34,14 +34,17 @@ public class ServerExtraParametersTest { private int myPort; private Server myServer; private RestfulServer myServlet; - + private static FhirContext ourCtx = FhirContext.forDstu1(); + @Before public void before() { myPort = PortUtil.findFreePort(); myServer = new Server(myPort); ServletHandler proxyHandler = new ServletHandler(); - myServlet = new RestfulServer(); + myServlet = new RestfulServer(ourCtx); + myServlet.setFhirContext(ourCtx); + ServletHolder servletHolder = new ServletHolder(myServlet); proxyHandler.addServletWithMapping(servletHolder, "/*"); myServer.setHandler(proxyHandler); @@ -55,7 +58,7 @@ public class ServerExtraParametersTest { myServer.start(); - FhirContext ctx = new FhirContext(); + FhirContext ctx = ourCtx; PatientClient client = ctx.newRestfulClient(PatientClient.class, "http://localhost:" + myPort + "/"); List actualPatients = client.searchForPatients(new StringDt("AAAABBBB")); @@ -72,7 +75,7 @@ public class ServerExtraParametersTest { myServer.start(); - FhirContext ctx = new FhirContext(); + FhirContext ctx = ourCtx; IGenericClient client = ctx.newRestfulGenericClient("http://localhost:" + myPort + "/"); client.registerInterceptor(new LoggingInterceptor(true)); diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ServerFeaturesTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ServerFeaturesTest.java index 042b4e2f08c..b3c7bba2236 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ServerFeaturesTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ServerFeaturesTest.java @@ -27,6 +27,7 @@ import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; +import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.api.Bundle; import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.model.dstu.composite.HumanNameDt; @@ -51,7 +52,8 @@ public class ServerFeaturesTest { private static int ourPort; private static Server ourServer; private static RestfulServer servlet; - + private static final FhirContext ourCtx = FhirContext.forDstu1(); + @Test public void testPrettyPrint() throws Exception { /* @@ -295,7 +297,7 @@ public class ServerFeaturesTest { DummyPatientResourceProvider patientProvider = new DummyPatientResourceProvider(); ServletHandler proxyHandler = new ServletHandler(); - servlet = new RestfulServer(); + servlet = new RestfulServer(ourCtx); servlet.setResourceProviders(patientProvider); servlet.setBundleInclusionRule(BundleInclusionRule.BASED_ON_RESOURCE_PRESENCE); ServletHolder servletHolder = new ServletHolder(servlet); diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ServerInvalidDefinitionTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ServerInvalidDefinitionTest.java index 934eaad4f0c..23338deccb7 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ServerInvalidDefinitionTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ServerInvalidDefinitionTest.java @@ -11,6 +11,7 @@ import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IIdType; import org.junit.Test; +import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.FhirVersionEnum; import ca.uhn.fhir.model.api.IElement; import ca.uhn.fhir.model.api.IResource; @@ -27,20 +28,21 @@ import ca.uhn.fhir.rest.annotation.Search; import ca.uhn.fhir.rest.param.StringParam; public class ServerInvalidDefinitionTest { - + private static final FhirContext ourCtx = FhirContext.forDstu1(); + /** * Normal, should initialize properly */ @Test() public void testBaseline() throws ServletException { - RestfulServer srv = new RestfulServer(); + RestfulServer srv = new RestfulServer(ourCtx); srv.setResourceProviders(new InstantiableTypeForResourceProvider()); srv.init(); } @Test public void testInvalidSpecialNameResourceProvider() { - RestfulServer srv = new RestfulServer(); + RestfulServer srv = new RestfulServer(ourCtx); srv.setResourceProviders(new InvalidSpecialParameterNameResourceProvider()); try { @@ -54,7 +56,7 @@ public class ServerInvalidDefinitionTest { @Test public void testMultipleResourceProviderForSameType() { - RestfulServer srv = new RestfulServer(); + RestfulServer srv = new RestfulServer(ourCtx); srv.setResourceProviders(new PatientResourceProvider1(), new PatientResourceProvider2()); try { @@ -69,7 +71,7 @@ public class ServerInvalidDefinitionTest { @Test public void testPrivateResourceProvider() { - RestfulServer srv = new RestfulServer(); + RestfulServer srv = new RestfulServer(ourCtx); srv.setResourceProviders(new PrivateResourceProvider()); try { @@ -83,7 +85,7 @@ public class ServerInvalidDefinitionTest { @Test public void testProviderWithNonResourceType() { - RestfulServer srv = new RestfulServer(); + RestfulServer srv = new RestfulServer(ourCtx); srv.setResourceProviders(new ProviderWithNonResourceType()); try { @@ -97,7 +99,7 @@ public class ServerInvalidDefinitionTest { @Test public void testReadMethodWithoutIdParamProvider() { - RestfulServer srv = new RestfulServer(); + RestfulServer srv = new RestfulServer(ourCtx); srv.setResourceProviders(new ReadMethodWithoutIdParamProvider()); try { @@ -110,7 +112,7 @@ public class ServerInvalidDefinitionTest { @Test public void testReadMethodWithSearchParameters() { - RestfulServer srv = new RestfulServer(); + RestfulServer srv = new RestfulServer(ourCtx); srv.setResourceProviders(new ReadMethodWithSearchParamProvider()); try { @@ -123,7 +125,7 @@ public class ServerInvalidDefinitionTest { @Test public void testSearchWithId() { - RestfulServer srv = new RestfulServer(); + RestfulServer srv = new RestfulServer(ourCtx); srv.setResourceProviders(new SearchWithIdParamProvider()); try { diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ServerProvidedResourceScannerTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ServerProvidedResourceScannerTest.java index 53ccb30a8bc..a7911a9a2f6 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ServerProvidedResourceScannerTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ServerProvidedResourceScannerTest.java @@ -1,5 +1,6 @@ package ca.uhn.fhir.rest.server; +import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.model.api.annotation.ProvidesResources; import ca.uhn.fhir.model.api.annotation.ResourceDef; @@ -9,9 +10,11 @@ import ca.uhn.fhir.model.primitive.IdDt; import ca.uhn.fhir.rest.annotation.IdParam; import ca.uhn.fhir.rest.annotation.Read; import junit.framework.TestCase; + import org.junit.Test; import javax.servlet.ServletException; + import java.util.ArrayList; import java.util.List; @@ -19,7 +22,9 @@ import java.util.List; * Created by Bill de Beaubien on 11/1/2014. */ public class ServerProvidedResourceScannerTest extends TestCase { - @Test + private static final FhirContext ourCtx = FhirContext.forDstu1(); + + @Test public void testWhenRestfulServerInitialized_annotatedResources_shouldBeAddedToContext() throws ServletException { // Given MyServer server = new MyServer(); @@ -35,7 +40,7 @@ public class ServerProvidedResourceScannerTest extends TestCase { @Test public void testWhenUnannotatedServerInitialized_annotatedResources_shouldNotBeAddedToContext() throws ServletException { // Given - RestfulServer server = new RestfulServer(); + RestfulServer server = new RestfulServer(ourCtx); // When server.init(); @@ -67,10 +72,23 @@ public class ServerProvidedResourceScannerTest extends TestCase { @ProvidesResources(resources={CustomPatient.class,CustomObservation.class}) class MyServer extends RestfulServer { + + private static final long serialVersionUID = 1L; + + public MyServer() { + super(ourCtx); + } + } class MyServerWithProvider extends RestfulServer { - @Override + private static final long serialVersionUID = 1L; + + public MyServerWithProvider() { + super(ourCtx); + } + + @Override protected void initialize() throws ServletException { List providers = new ArrayList(); providers.add(new MyObservationProvider()); diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/SortTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/SortTest.java index fe49b53e367..e58f01353bf 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/SortTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/SortTest.java @@ -36,10 +36,10 @@ import ca.uhn.fhir.util.PortUtil; public class SortTest { private static CloseableHttpClient ourClient; - private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(SortTest.class); private static int ourPort; private static Server ourServer; - + private static FhirContext ourCtx = FhirContext.forDstu1(); + @Test public void testNoSort() throws Exception { HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?name=Hello"); @@ -47,7 +47,7 @@ public class SortTest { String responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent()); assertEquals(200, status.getStatusLine().getStatusCode()); - Bundle bundle = new FhirContext().newXmlParser().parseBundle(responseContent); + Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent); assertEquals(1, bundle.size()); Patient p = bundle.getResources(Patient.class).get(0); @@ -63,7 +63,7 @@ public class SortTest { String responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent()); assertEquals(200, status.getStatusLine().getStatusCode()); - Bundle bundle = new FhirContext().newXmlParser().parseBundle(responseContent); + Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent); assertEquals(1, bundle.size()); Patient p = bundle.getResources(Patient.class).get(0); @@ -77,7 +77,7 @@ public class SortTest { String responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent()); assertEquals(200, status.getStatusLine().getStatusCode()); - Bundle bundle = new FhirContext().newXmlParser().parseBundle(responseContent); + Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent); assertEquals(1, bundle.size()); Patient p = bundle.getResources(Patient.class).get(0); @@ -91,7 +91,7 @@ public class SortTest { String responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent()); assertEquals(200, status.getStatusLine().getStatusCode()); - Bundle bundle = new FhirContext().newXmlParser().parseBundle(responseContent); + Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent); assertEquals(1, bundle.size()); Patient p = bundle.getResources(Patient.class).get(0); @@ -110,7 +110,7 @@ public class SortTest { String responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent()); assertEquals(200, status.getStatusLine().getStatusCode()); - Bundle bundle = new FhirContext().newXmlParser().parseBundle(responseContent); + Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent); assertEquals(1, bundle.size()); Patient p = bundle.getResources(Patient.class).get(0); @@ -136,7 +136,7 @@ public class SortTest { DummyPatientResourceProvider patientProvider = new DummyPatientResourceProvider(); ServletHandler proxyHandler = new ServletHandler(); - RestfulServer servlet = new RestfulServer(); + RestfulServer servlet = new RestfulServer(ourCtx); servlet.setResourceProviders(patientProvider); ServletHolder servletHolder = new ServletHolder(servlet); proxyHandler.addServletWithMapping(servletHolder, "/*"); diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/StringParameterTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/StringParameterTest.java index eeeb582c0c1..03ecdc211f6 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/StringParameterTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/StringParameterTest.java @@ -34,69 +34,30 @@ import ca.uhn.fhir.util.PortUtil; public class StringParameterTest { private static CloseableHttpClient ourClient; - private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(StringParameterTest.class); + private static FhirContext ourCtx = FhirContext.forDstu1(); private static int ourPort; + private static Server ourServer; - @Test - public void testSearchWithFormatAndPretty() throws Exception { - { - HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?str=aaa&_format=xml&_pretty=true"); - HttpResponse status = ourClient.execute(httpGet); - String responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent()); - - assertEquals(200, status.getStatusLine().getStatusCode()); - assertEquals(1, new FhirContext().newXmlParser().parseBundle(responseContent).getEntries().size()); - } - } - - @Test - public void testSearchNormalMatch() throws Exception { - { - HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?str=aaa"); - HttpResponse status = ourClient.execute(httpGet); - String responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent()); - IOUtils.closeQuietly(status.getEntity().getContent()); - - assertEquals(200, status.getStatusLine().getStatusCode()); - assertEquals(1, new FhirContext().newXmlParser().parseBundle(responseContent).getEntries().size()); - } - { - HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?str=AAA"); - HttpResponse status = ourClient.execute(httpGet); - String responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent()); - IOUtils.closeQuietly(status.getEntity().getContent()); - - assertEquals(200, status.getStatusLine().getStatusCode()); - assertEquals(1, new FhirContext().newXmlParser().parseBundle(responseContent).getEntries().size()); - } - { - HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?str=BBB"); - HttpResponse status = ourClient.execute(httpGet); - String responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent()); - - assertEquals(200, status.getStatusLine().getStatusCode()); - assertEquals(0, new FhirContext().newXmlParser().parseBundle(responseContent).getEntries().size()); - } - } - @Test public void testRawString() throws Exception { { HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?plain=aaa"); HttpResponse status = ourClient.execute(httpGet); - String responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent()); + String responseContent = IOUtils.toString(status.getEntity().getContent()); + IOUtils.closeQuietly(status.getEntity().getContent()); assertEquals(200, status.getStatusLine().getStatusCode()); - assertEquals(1, new FhirContext().newXmlParser().parseBundle(responseContent).getEntries().size()); + assertEquals(1, ourCtx.newXmlParser().parseBundle(responseContent).getEntries().size()); } { HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?plain=BBB"); HttpResponse status = ourClient.execute(httpGet); - String responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent()); + String responseContent = IOUtils.toString(status.getEntity().getContent()); + IOUtils.closeQuietly(status.getEntity().getContent()); assertEquals(200, status.getStatusLine().getStatusCode()); - assertEquals(0, new FhirContext().newXmlParser().parseBundle(responseContent).getEntries().size()); + assertEquals(0, ourCtx.newXmlParser().parseBundle(responseContent).getEntries().size()); } } @@ -105,26 +66,29 @@ public class StringParameterTest { { HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?str:exact=aaa"); HttpResponse status = ourClient.execute(httpGet); - String responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent()); + String responseContent = IOUtils.toString(status.getEntity().getContent()); + IOUtils.closeQuietly(status.getEntity().getContent()); assertEquals(200, status.getStatusLine().getStatusCode()); - assertEquals(1, new FhirContext().newXmlParser().parseBundle(responseContent).getEntries().size()); + assertEquals(1, ourCtx.newXmlParser().parseBundle(responseContent).getEntries().size()); } { HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?str:exact=AAA"); HttpResponse status = ourClient.execute(httpGet); - String responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent()); + String responseContent = IOUtils.toString(status.getEntity().getContent()); + IOUtils.closeQuietly(status.getEntity().getContent()); assertEquals(200, status.getStatusLine().getStatusCode()); - assertEquals(0, new FhirContext().newXmlParser().parseBundle(responseContent).getEntries().size()); + assertEquals(0, ourCtx.newXmlParser().parseBundle(responseContent).getEntries().size()); } { HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?str:exact=BBB"); HttpResponse status = ourClient.execute(httpGet); - String responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent()); + String responseContent = IOUtils.toString(status.getEntity().getContent()); + IOUtils.closeQuietly(status.getEntity().getContent()); assertEquals(200, status.getStatusLine().getStatusCode()); - assertEquals(0, new FhirContext().newXmlParser().parseBundle(responseContent).getEntries().size()); + assertEquals(0, ourCtx.newXmlParser().parseBundle(responseContent).getEntries().size()); } } @@ -133,14 +97,60 @@ public class StringParameterTest { { HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?ccc:exact=aaa"); HttpResponse status = ourClient.execute(httpGet); - String responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent()); + String responseContent = IOUtils.toString(status.getEntity().getContent()); + IOUtils.closeQuietly(status.getEntity().getContent()); assertEquals(200, status.getStatusLine().getStatusCode()); - assertEquals(1, new FhirContext().newXmlParser().parseBundle(responseContent).getEntries().size()); + assertEquals(1, ourCtx.newXmlParser().parseBundle(responseContent).getEntries().size()); + } + } + + @Test + public void testSearchNormalMatch() throws Exception { + { + HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?str=aaa"); + HttpResponse status = ourClient.execute(httpGet); + String responseContent = IOUtils.toString(status.getEntity().getContent()); + IOUtils.closeQuietly(status.getEntity().getContent()); + IOUtils.closeQuietly(status.getEntity().getContent()); + + assertEquals(200, status.getStatusLine().getStatusCode()); + assertEquals(1, ourCtx.newXmlParser().parseBundle(responseContent).getEntries().size()); + } + { + HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?str=AAA"); + HttpResponse status = ourClient.execute(httpGet); + String responseContent = IOUtils.toString(status.getEntity().getContent()); + IOUtils.closeQuietly(status.getEntity().getContent()); + IOUtils.closeQuietly(status.getEntity().getContent()); + + assertEquals(200, status.getStatusLine().getStatusCode()); + assertEquals(1, ourCtx.newXmlParser().parseBundle(responseContent).getEntries().size()); + } + { + HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?str=BBB"); + HttpResponse status = ourClient.execute(httpGet); + String responseContent = IOUtils.toString(status.getEntity().getContent()); + IOUtils.closeQuietly(status.getEntity().getContent()); + + assertEquals(200, status.getStatusLine().getStatusCode()); + assertEquals(0, ourCtx.newXmlParser().parseBundle(responseContent).getEntries().size()); + } + } + + @Test + public void testSearchWithFormatAndPretty() throws Exception { + { + HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?str=aaa&_format=xml&_pretty=true"); + HttpResponse status = ourClient.execute(httpGet); + String responseContent = IOUtils.toString(status.getEntity().getContent()); + IOUtils.closeQuietly(status.getEntity().getContent()); + + assertEquals(200, status.getStatusLine().getStatusCode()); + assertEquals(1, ourCtx.newXmlParser().parseBundle(responseContent).getEntries().size()); } } - @AfterClass public static void afterClass() throws Exception { ourServer.stop(); @@ -154,7 +164,8 @@ public class StringParameterTest { DummyPatientResourceProvider patientProvider = new DummyPatientResourceProvider(); ServletHandler proxyHandler = new ServletHandler(); - RestfulServer servlet = new RestfulServer(); + RestfulServer servlet = new RestfulServer(ourCtx); + servlet.setFhirContext(ourCtx); servlet.setResourceProviders(patientProvider); ServletHolder servletHolder = new ServletHolder(servlet); proxyHandler.addServletWithMapping(servletHolder, "/*"); @@ -173,6 +184,19 @@ public class StringParameterTest { */ public static class DummyPatientResourceProvider implements IResourceProvider { + @Search + public List findPatientByString(@RequiredParam(name = "plain") String theParam) { + ArrayList retVal = new ArrayList(); + + if (theParam.toLowerCase().equals("aaa")) { + Patient patient = new Patient(); + patient.setId("1"); + retVal.add(patient); + } + + return retVal; + } + @Search public List findPatientByStringParam(@RequiredParam(name = "str") StringParam theParam) { ArrayList retVal = new ArrayList(); @@ -191,19 +215,6 @@ public class StringParameterTest { return retVal; } - @Search - public List findPatientByString(@RequiredParam(name = "plain") String theParam) { - ArrayList retVal = new ArrayList(); - - if (theParam.toLowerCase().equals("aaa")) { - Patient patient = new Patient(); - patient.setId("1"); - retVal.add(patient); - } - - return retVal; - } - @Search public List findPatientWithOptional(@OptionalParam(name = "ccc") StringParam theParam) { ArrayList retVal = new ArrayList(); @@ -222,7 +233,6 @@ public class StringParameterTest { return retVal; } - @Override public Class getResourceType() { return Patient.class; diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/TagsServerTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/TagsServerTest.java index 1fa5a8f7739..5a88a4795cf 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/TagsServerTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/TagsServerTest.java @@ -240,7 +240,7 @@ public class TagsServerTest { ourProvider = new DummyProvider(); ServletHandler proxyHandler = new ServletHandler(); - RestfulServer servlet = new RestfulServer(); + RestfulServer servlet = new RestfulServer(ourCtx); servlet.setPlainProviders(ourProvider); ServletHolder servletHolder = new ServletHolder(servlet); proxyHandler.addServletWithMapping(servletHolder, "/*"); diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/TransactionTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/TransactionTest.java index 67e82345bdf..fe3a66721cd 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/TransactionTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/TransactionTest.java @@ -40,7 +40,7 @@ import ca.uhn.fhir.util.PortUtil; public class TransactionTest { private static CloseableHttpClient ourClient; - private static FhirContext ourCtx = new FhirContext(); + private static FhirContext ourCtx = FhirContext.forDstu1(); private static boolean ourDropFirstResource; private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(TransactionTest.class); private static int ourPort; @@ -88,7 +88,7 @@ public class TransactionTest { ourLog.info(responseContent); - Bundle bundle = new FhirContext().newXmlParser().parseBundle(responseContent); + Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent); assertEquals(3, bundle.size()); BundleEntry entry0 = bundle.getEntries().get(0); @@ -144,7 +144,7 @@ public class TransactionTest { ourLog.info(responseContent); - Bundle bundle = new FhirContext().newXmlParser().parseBundle(responseContent); + Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent); assertEquals(2, bundle.size()); BundleEntry entry1 = bundle.getEntries().get(0); @@ -195,7 +195,7 @@ public class TransactionTest { ourLog.info(responseContent); - Bundle bundle = new FhirContext().newXmlParser().parseBundle(responseContent); + Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent); assertEquals(4, bundle.size()); assertEquals(OperationOutcome.class, bundle.getEntries().get(0).getResource().getClass()); @@ -228,7 +228,7 @@ public class TransactionTest { ourServer = new Server(ourPort); DummyProvider patientProvider = new DummyProvider(); - RestfulServer server = new RestfulServer(); + RestfulServer server = new RestfulServer(ourCtx); server.setProviders(patientProvider); org.eclipse.jetty.servlet.ServletContextHandler proxyHandler = new org.eclipse.jetty.servlet.ServletContextHandler(); diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/TransactionWithBundleParamTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/TransactionWithBundleParamTest.java index 0d4ec224d6a..d0153e77326 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/TransactionWithBundleParamTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/TransactionWithBundleParamTest.java @@ -40,7 +40,7 @@ import ca.uhn.fhir.util.PortUtil; public class TransactionWithBundleParamTest { private static CloseableHttpClient ourClient; - private static FhirContext ourCtx = new FhirContext(); + private static FhirContext ourCtx = FhirContext.forDstu1(); private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(TransactionWithBundleParamTest.class); private static int ourPort; private static boolean ourReturnOperationOutcome; @@ -144,7 +144,7 @@ public class TransactionWithBundleParamTest { ourLog.info(responseContent); - Bundle bundle = new FhirContext().newXmlParser().parseBundle(responseContent); + Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent); assertEquals(4, bundle.size()); assertEquals(OperationOutcome.class, bundle.getEntries().get(0).getResource().getClass()); @@ -177,7 +177,7 @@ public class TransactionWithBundleParamTest { ourServer = new Server(ourPort); DummyProvider patientProvider = new DummyProvider(); - RestfulServer server = new RestfulServer(); + RestfulServer server = new RestfulServer(ourCtx); server.setProviders(patientProvider); org.eclipse.jetty.servlet.ServletContextHandler proxyHandler = new org.eclipse.jetty.servlet.ServletContextHandler(); diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/UpdateTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/UpdateTest.java index b4ac663f43a..4a19c53f994 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/UpdateTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/UpdateTest.java @@ -47,6 +47,7 @@ public class UpdateTest { private static int ourPort; private static DiagnosticReportProvider ourReportProvider; private static Server ourServer; + private static FhirContext ourCtx = FhirContext.forDstu1(); @Test public void testUpdate() throws Exception { @@ -55,7 +56,7 @@ public class UpdateTest { patient.addIdentifier().setValue("002"); HttpPut httpPost = new HttpPut("http://localhost:" + ourPort + "/Patient/001"); - httpPost.setEntity(new StringEntity(new FhirContext().newXmlParser().encodeResourceToString(patient), ContentType.create(Constants.CT_FHIR_XML, "UTF-8"))); + httpPost.setEntity(new StringEntity(ourCtx.newXmlParser().encodeResourceToString(patient), ContentType.create(Constants.CT_FHIR_XML, "UTF-8"))); HttpResponse status = ourClient.execute(httpPost); @@ -64,7 +65,7 @@ public class UpdateTest { ourLog.info("Response was:\n{}", responseContent); - OperationOutcome oo = new FhirContext().newXmlParser().parseResource(OperationOutcome.class, responseContent); + OperationOutcome oo = ourCtx.newXmlParser().parseResource(OperationOutcome.class, responseContent); assertEquals("OODETAILS", oo.getIssueFirstRep().getDetails().getValue()); assertEquals(200, status.getStatusLine().getStatusCode()); @@ -81,7 +82,7 @@ public class UpdateTest { patient.addIdentifier().setValue("002"); HttpPut httpPost = new HttpPut("http://localhost:" + ourPort + "/Patient/001CREATE"); - httpPost.setEntity(new StringEntity(new FhirContext().newXmlParser().encodeResourceToString(patient), ContentType.create(Constants.CT_FHIR_XML, "UTF-8"))); + httpPost.setEntity(new StringEntity(ourCtx.newXmlParser().encodeResourceToString(patient), ContentType.create(Constants.CT_FHIR_XML, "UTF-8"))); HttpResponse status = ourClient.execute(httpPost); @@ -90,7 +91,7 @@ public class UpdateTest { ourLog.info("Response was:\n{}", responseContent); - OperationOutcome oo = new FhirContext().newXmlParser().parseResource(OperationOutcome.class, responseContent); + OperationOutcome oo = ourCtx.newXmlParser().parseResource(OperationOutcome.class, responseContent); assertEquals("OODETAILS", oo.getIssueFirstRep().getDetails().getValue()); assertEquals(201, status.getStatusLine().getStatusCode()); @@ -105,7 +106,7 @@ public class UpdateTest { patient.addIdentifier().setValue("002"); HttpPut httpPost = new HttpPut("http://localhost:" + ourPort + "/DiagnosticReport/AAAAAA"); - httpPost.setEntity(new StringEntity(new FhirContext().newXmlParser().encodeResourceToString(patient), ContentType.create(Constants.CT_FHIR_XML, "UTF-8"))); + httpPost.setEntity(new StringEntity(ourCtx.newXmlParser().encodeResourceToString(patient), ContentType.create(Constants.CT_FHIR_XML, "UTF-8"))); HttpResponse status = ourClient.execute(httpPost); @@ -125,7 +126,7 @@ public class UpdateTest { dr.addCodedDiagnosis().addCoding().setCode("AAA"); HttpPut httpPost = new HttpPut("http://localhost:" + ourPort + "/DiagnosticReport/001"); - httpPost.setEntity(new StringEntity(new FhirContext().newXmlParser().encodeResourceToString(dr), ContentType.create(Constants.CT_FHIR_XML, "UTF-8"))); + httpPost.setEntity(new StringEntity(ourCtx.newXmlParser().encodeResourceToString(dr), ContentType.create(Constants.CT_FHIR_XML, "UTF-8"))); HttpResponse status = ourClient.execute(httpPost); @@ -143,7 +144,7 @@ public class UpdateTest { HttpPut httpPost = new HttpPut("http://localhost:" + ourPort + "/DiagnosticReport/001"); httpPost.addHeader("Category", "Dog; scheme=\"urn:animals\", Cat; scheme=\"urn:animals\""); - httpPost.setEntity(new StringEntity(new FhirContext().newXmlParser().encodeResourceToString(dr), ContentType.create(Constants.CT_FHIR_XML, "UTF-8"))); + httpPost.setEntity(new StringEntity(ourCtx.newXmlParser().encodeResourceToString(dr), ContentType.create(Constants.CT_FHIR_XML, "UTF-8"))); CloseableHttpResponse status = ourClient.execute(httpPost); IOUtils.closeQuietly(status.getEntity().getContent()); @@ -153,7 +154,7 @@ public class UpdateTest { httpPost = new HttpPut("http://localhost:" + ourPort + "/DiagnosticReport/001"); httpPost.addHeader("Category", "Dog; label=\"aa\"; scheme=\"urn:animals\", Cat; label=\"bb\"; scheme=\"urn:animals\""); - httpPost.setEntity(new StringEntity(new FhirContext().newXmlParser().encodeResourceToString(dr), ContentType.create(Constants.CT_FHIR_XML, "UTF-8"))); + httpPost.setEntity(new StringEntity(ourCtx.newXmlParser().encodeResourceToString(dr), ContentType.create(Constants.CT_FHIR_XML, "UTF-8"))); status = ourClient.execute(httpPost); IOUtils.closeQuietly(status.getEntity().getContent()); @@ -171,7 +172,7 @@ public class UpdateTest { HttpPut httpPost = new HttpPut("http://localhost:" + ourPort + "/DiagnosticReport/001"); httpPost.addHeader("Category", "Dog; scheme=\"animals\""); - httpPost.setEntity(new StringEntity(new FhirContext().newXmlParser().encodeResourceToString(dr), ContentType.create(Constants.CT_FHIR_XML, "UTF-8"))); + httpPost.setEntity(new StringEntity(ourCtx.newXmlParser().encodeResourceToString(dr), ContentType.create(Constants.CT_FHIR_XML, "UTF-8"))); CloseableHttpResponse status = ourClient.execute(httpPost); IOUtils.closeQuietly(status.getEntity().getContent()); @@ -188,7 +189,7 @@ public class UpdateTest { HttpPut httpPost = new HttpPut("http://localhost:" + ourPort + "/DiagnosticReport/001"); httpPost.addHeader("Category", "Dog; scheme=\"http://foo\""); - httpPost.setEntity(new StringEntity(new FhirContext().newXmlParser().encodeResourceToString(dr), ContentType.create(Constants.CT_FHIR_XML, "UTF-8"))); + httpPost.setEntity(new StringEntity(ourCtx.newXmlParser().encodeResourceToString(dr), ContentType.create(Constants.CT_FHIR_XML, "UTF-8"))); CloseableHttpResponse status = ourClient.execute(httpPost); IOUtils.closeQuietly(status.getEntity().getContent()); @@ -197,7 +198,7 @@ public class UpdateTest { httpPost = new HttpPut("http://localhost:" + ourPort + "/DiagnosticReport/001"); httpPost.addHeader("Category", "Dog; scheme=\"http://foo\";"); - httpPost.setEntity(new StringEntity(new FhirContext().newXmlParser().encodeResourceToString(dr), ContentType.create(Constants.CT_FHIR_XML, "UTF-8"))); + httpPost.setEntity(new StringEntity(ourCtx.newXmlParser().encodeResourceToString(dr), ContentType.create(Constants.CT_FHIR_XML, "UTF-8"))); ourClient.execute(httpPost); IOUtils.closeQuietly(status.getEntity().getContent()); @@ -214,7 +215,7 @@ public class UpdateTest { HttpPut httpPost = new HttpPut("http://localhost:" + ourPort + "/DiagnosticReport/001"); httpPost.addHeader("Category", "Dog; scheme=\"http://foo\"; label=\"aaaa\""); - httpPost.setEntity(new StringEntity(new FhirContext().newXmlParser().encodeResourceToString(dr), ContentType.create(Constants.CT_FHIR_XML, "UTF-8"))); + httpPost.setEntity(new StringEntity(ourCtx.newXmlParser().encodeResourceToString(dr), ContentType.create(Constants.CT_FHIR_XML, "UTF-8"))); CloseableHttpResponse status = ourClient.execute(httpPost); assertEquals(1, ourReportProvider.getLastTags().size()); assertEquals(new Tag("http://foo", "Dog", "aaaa"), ourReportProvider.getLastTags().get(0)); @@ -222,7 +223,7 @@ public class UpdateTest { httpPost = new HttpPut("http://localhost:" + ourPort + "/DiagnosticReport/001"); httpPost.addHeader("Category", "Dog; scheme=\"http://foo\"; label=\"aaaa\"; "); - httpPost.setEntity(new StringEntity(new FhirContext().newXmlParser().encodeResourceToString(dr), ContentType.create(Constants.CT_FHIR_XML, "UTF-8"))); + httpPost.setEntity(new StringEntity(ourCtx.newXmlParser().encodeResourceToString(dr), ContentType.create(Constants.CT_FHIR_XML, "UTF-8"))); status=ourClient.execute(httpPost); IOUtils.closeQuietly(status.getEntity().getContent()); @@ -239,7 +240,7 @@ public class UpdateTest { HttpPut httpPut = new HttpPut("http://localhost:" + ourPort + "/DiagnosticReport/001"); httpPut.addHeader("Content-Location", "/DiagnosticReport/001/_history/004"); - httpPut.setEntity(new StringEntity(new FhirContext().newXmlParser().encodeResourceToString(patient), ContentType.create(Constants.CT_FHIR_XML, "UTF-8"))); + httpPut.setEntity(new StringEntity(ourCtx.newXmlParser().encodeResourceToString(patient), ContentType.create(Constants.CT_FHIR_XML, "UTF-8"))); HttpResponse status = ourClient.execute(httpPut); IOUtils.closeQuietly(status.getEntity().getContent()); @@ -261,7 +262,7 @@ public class UpdateTest { HttpPut httpPut = new HttpPut("http://localhost:" + ourPort + "/DiagnosticReport/001"); httpPut.addHeader("Content-Location", "/Patient/001/_history/002"); - httpPut.setEntity(new StringEntity(new FhirContext().newXmlParser().encodeResourceToString(patient), ContentType.create(Constants.CT_FHIR_XML, "UTF-8"))); + httpPut.setEntity(new StringEntity(ourCtx.newXmlParser().encodeResourceToString(patient), ContentType.create(Constants.CT_FHIR_XML, "UTF-8"))); CloseableHttpResponse status = ourClient.execute(httpPut); String responseContent = IOUtils.toString(status.getEntity().getContent()); @@ -282,7 +283,7 @@ public class UpdateTest { patient.addIdentifier().setValue("002"); HttpPut httpPost = new HttpPut("http://localhost:" + ourPort + "/DiagnosticReport/001"); - httpPost.setEntity(new StringEntity(new FhirContext().newXmlParser().encodeResourceToString(patient), ContentType.create(Constants.CT_FHIR_XML, "UTF-8"))); + httpPost.setEntity(new StringEntity(ourCtx.newXmlParser().encodeResourceToString(patient), ContentType.create(Constants.CT_FHIR_XML, "UTF-8"))); ourClient.execute(httpPost); fail(); @@ -295,7 +296,7 @@ public class UpdateTest { patient.addIdentifier().setValue("002"); HttpPut httpPost = new HttpPut("http://localhost:" + ourPort + "/Organization/001"); - httpPost.setEntity(new StringEntity(new FhirContext().newXmlParser().encodeResourceToString(patient), ContentType.create(Constants.CT_FHIR_XML, "UTF-8"))); + httpPost.setEntity(new StringEntity(ourCtx.newXmlParser().encodeResourceToString(patient), ContentType.create(Constants.CT_FHIR_XML, "UTF-8"))); CloseableHttpResponse status = ourClient.execute(httpPost); IOUtils.closeQuietly(status.getEntity().getContent()); @@ -320,7 +321,7 @@ public class UpdateTest { ourReportProvider = new DiagnosticReportProvider(); ServletHandler proxyHandler = new ServletHandler(); - RestfulServer servlet = new RestfulServer(); + RestfulServer servlet = new RestfulServer(ourCtx); servlet.setResourceProviders(patientProvider, ourReportProvider, new ObservationProvider(), new OrganizationResourceProvider()); ServletHolder servletHolder = new ServletHolder(servlet); proxyHandler.addServletWithMapping(servletHolder, "/*"); @@ -386,7 +387,6 @@ public class UpdateTest { return Observation.class; } - @SuppressWarnings("unused") @Update() public MethodOutcome updateDiagnosticReportWithVersion(@IdParam IdDt theId, @ResourceParam DiagnosticOrder thePatient) { /* diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ValidateDstu1Test.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ValidateDstu1Test.java index b9a2c531362..aeed91e6264 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ValidateDstu1Test.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ValidateDstu1Test.java @@ -39,8 +39,8 @@ public class ValidateDstu1Test { private static CloseableHttpClient ourClient; private static EncodingEnum ourLastEncoding; private static String ourLastResourceBody; - private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ValidateDstu1Test.class); private static int ourPort; + private static FhirContext ourCtx = FhirContext.forDstu1(); private static Server ourServer; @Before() @@ -57,7 +57,7 @@ public class ValidateDstu1Test { patient.addIdentifier().setValue("002"); HttpPost httpPost = new HttpPost("http://localhost:" + ourPort + "/Patient/_validate"); - httpPost.setEntity(new StringEntity(new FhirContext().newXmlParser().encodeResourceToString(patient), ContentType.create(Constants.CT_FHIR_XML, "UTF-8"))); + httpPost.setEntity(new StringEntity(ourCtx.newXmlParser().encodeResourceToString(patient), ContentType.create(Constants.CT_FHIR_XML, "UTF-8"))); HttpResponse status = ourClient.execute(httpPost); @@ -76,7 +76,7 @@ public class ValidateDstu1Test { org.addIdentifier().setValue("002"); HttpPost httpPost = new HttpPost("http://localhost:" + ourPort + "/Organization/_validate"); - httpPost.setEntity(new StringEntity(new FhirContext().newJsonParser().encodeResourceToString(org), ContentType.create(Constants.CT_FHIR_JSON, "UTF-8"))); + httpPost.setEntity(new StringEntity(ourCtx.newJsonParser().encodeResourceToString(org), ContentType.create(Constants.CT_FHIR_JSON, "UTF-8"))); HttpResponse status = ourClient.execute(httpPost); assertEquals(204, status.getStatusLine().getStatusCode()); @@ -99,7 +99,7 @@ public class ValidateDstu1Test { PatientProvider patientProvider = new PatientProvider(); ServletHandler proxyHandler = new ServletHandler(); - RestfulServer servlet = new RestfulServer(); + RestfulServer servlet = new RestfulServer(ourCtx); servlet.setResourceProviders(patientProvider, new OrganizationProvider()); ServletHolder servletHolder = new ServletHolder(servlet); proxyHandler.addServletWithMapping(servletHolder, "/*"); diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/interceptor/AuditingInterceptorTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/interceptor/AuditingInterceptorTest.java index 16b08c60e4f..67dbb70f208 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/interceptor/AuditingInterceptorTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/interceptor/AuditingInterceptorTest.java @@ -29,6 +29,7 @@ import org.junit.BeforeClass; import org.junit.Test; import org.mockito.ArgumentCaptor; +import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.model.base.composite.BaseCodingDt; import ca.uhn.fhir.model.base.resource.BaseSecurityEvent; @@ -64,6 +65,7 @@ public class AuditingInterceptorTest { private static Server ourServer; private static RestfulServer servlet; private IServerInterceptor myInterceptor; + private static final FhirContext ourCtx = FhirContext.forDstu1(); private class MockDataStore implements IAuditDataStore { @@ -190,7 +192,7 @@ public class AuditingInterceptorTest { DummyPatientResourceProvider patientProvider = new DummyPatientResourceProvider(); ServletHandler proxyHandler = new ServletHandler(); - servlet = new RestfulServer(); + servlet = new RestfulServer(ourCtx); servlet.setResourceProviders(patientProvider); ServletHolder servletHolder = new ServletHolder(servlet); proxyHandler.addServletWithMapping(servletHolder, "/*"); diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/interceptor/ExceptionHandlingInterceptorTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/interceptor/ExceptionHandlingInterceptorTest.java index 1725596a958..a5fe6d0c4a0 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/interceptor/ExceptionHandlingInterceptorTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/interceptor/ExceptionHandlingInterceptorTest.java @@ -24,6 +24,7 @@ import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; +import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.model.dstu.resource.OperationOutcome; import ca.uhn.fhir.model.dstu.resource.Patient; @@ -52,6 +53,7 @@ public class ExceptionHandlingInterceptorTest { private static Server ourServer; private static RestfulServer servlet; private static ExceptionHandlingInterceptor myInterceptor; + private static final FhirContext ourCtx = FhirContext.forDstu1(); @Before public void before() { @@ -109,7 +111,7 @@ public class ExceptionHandlingInterceptorTest { DummyPatientResourceProvider patientProvider = new DummyPatientResourceProvider(); ServletHandler proxyHandler = new ServletHandler(); - servlet = new RestfulServer(); + servlet = new RestfulServer(ourCtx); servlet.setResourceProviders(patientProvider); ServletHolder servletHolder = new ServletHolder(servlet); proxyHandler.addServletWithMapping(servletHolder, "/*"); diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/interceptor/ExceptionInterceptorMethodTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/interceptor/ExceptionInterceptorMethodTest.java index a03fce86c87..e403771ff93 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/interceptor/ExceptionInterceptorMethodTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/interceptor/ExceptionInterceptorMethodTest.java @@ -27,6 +27,7 @@ import org.mockito.ArgumentCaptor; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; +import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.dstu.resource.Patient; import ca.uhn.fhir.rest.annotation.Search; import ca.uhn.fhir.rest.method.RequestDetails; @@ -43,7 +44,8 @@ public class ExceptionInterceptorMethodTest { private static RestfulServer servlet; private IServerInterceptor myInterceptor; private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ExceptionInterceptorMethodTest.class); - + private static final FhirContext ourCtx = FhirContext.forDstu1(); + @Test public void testThrowUnprocessableEntityException() throws Exception { @@ -112,7 +114,7 @@ public class ExceptionInterceptorMethodTest { DummyPatientResourceProvider patientProvider = new DummyPatientResourceProvider(); ServletHandler proxyHandler = new ServletHandler(); - servlet = new RestfulServer(); + servlet = new RestfulServer(ourCtx); servlet.setResourceProviders(patientProvider); ServletHolder servletHolder = new ServletHolder(servlet); proxyHandler.addServletWithMapping(servletHolder, "/*"); diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/util/FhirTerserTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/util/FhirTerserTest.java index 0ab2f4ca0c8..cc15830b3ad 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/util/FhirTerserTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/util/FhirTerserTest.java @@ -17,7 +17,7 @@ import ca.uhn.fhir.model.primitive.StringDt; public class FhirTerserTest { - private static FhirContext ourCtx = new FhirContext(); + private static FhirContext ourCtx = FhirContext.forDstu1(); @Test public void testGetAllPopulatedChildElementsOfType() { @@ -29,7 +29,7 @@ public class FhirTerserTest { p.addAddress().addLine("Line2"); p.addName().addFamily("Line3"); - FhirTerser t = new FhirContext().newTerser(); + FhirTerser t = ourCtx.newTerser(); List strings = t.getAllPopulatedChildElementsOfType(p, StringDt.class); assertEquals(3, strings.size()); @@ -43,7 +43,7 @@ public class FhirTerserTest { Observation obs = new Observation(); obs.setValue(new QuantityDt(123L)); - FhirTerser t = new FhirContext().newTerser(); + FhirTerser t = ourCtx.newTerser(); // As string { diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/validation/ResourceValidatorTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/validation/ResourceValidatorTest.java index 456b00d214f..e098b2e6d96 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/validation/ResourceValidatorTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/validation/ResourceValidatorTest.java @@ -26,7 +26,7 @@ import static org.junit.Assert.fail; public class ResourceValidatorTest { - private static FhirContext ourCtx = new FhirContext(); + private static FhirContext ourCtx = FhirContext.forDstu1(); private static Locale ourDefaultLocale; private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ResourceValidatorTest.class); diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/validation/ValidationResultTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/validation/ValidationResultDstu1Test.java similarity index 98% rename from hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/validation/ValidationResultTest.java rename to hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/validation/ValidationResultDstu1Test.java index 051bbde3e32..d5ee0386698 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/validation/ValidationResultTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/validation/ValidationResultDstu1Test.java @@ -13,7 +13,7 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; -public class ValidationResultTest { +public class ValidationResultDstu1Test { @Test public void isSuccessful_IsTrueForNullOperationOutcome() { diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/validation/ValidatorInstantiatorTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/validation/ValidatorInstantiatorTest.java index f73ae04ed7c..87a40cb679a 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/validation/ValidatorInstantiatorTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/validation/ValidatorInstantiatorTest.java @@ -8,12 +8,12 @@ import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.validation.FhirValidator; public class ValidatorInstantiatorTest { + private static FhirContext ourCtx = FhirContext.forDstu1(); @Test public void testValidator() { - FhirContext ctx = new FhirContext(); - FhirValidator val = ctx.newValidator(); + FhirValidator val = ourCtx.newValidator(); // We have a full classpath, so take advantage assertTrue(val.isValidateAgainstStandardSchema()); diff --git a/hapi-fhir-structures-dstu/src/test/resources/logback-test.xml b/hapi-fhir-structures-dstu/src/test/resources/logback-test.xml index 996190aeccf..e5cbbb9c22e 100644 --- a/hapi-fhir-structures-dstu/src/test/resources/logback-test.xml +++ b/hapi-fhir-structures-dstu/src/test/resources/logback-test.xml @@ -23,8 +23,8 @@
--> - + - \ No newline at end of file + diff --git a/hapi-fhir-structures-dstu/src/test/resources/narrative/customnarrative.properties b/hapi-fhir-structures-dstu/src/test/resources/narrative/customnarrative.properties index 4f4404c5495..ff22e4e5016 100644 --- a/hapi-fhir-structures-dstu/src/test/resources/narrative/customnarrative.properties +++ b/hapi-fhir-structures-dstu/src/test/resources/narrative/customnarrative.properties @@ -9,7 +9,7 @@ # Format is file:/path/foo.html or classpath:/com/classpath/foo.html # practitioner.class=ca.uhn.fhir.model.dstu.resource.Practitioner -practitioner.narrative=file:src/test/resources/narrative/Practitioner.html +practitioner.narrative=classpath:narrative/Practitioner.html # You may also override/define behaviour for datatypes humanname.class=ca.uhn.fhir.model.dstu.composite.HumanNameDt diff --git a/hapi-fhir-structures-dstu2/.gitignore b/hapi-fhir-structures-dstu2/.gitignore index be015a3d566..30eac0753b3 100644 --- a/hapi-fhir-structures-dstu2/.gitignore +++ b/hapi-fhir-structures-dstu2/.gitignore @@ -142,3 +142,6 @@ local.properties /target/ /target/ /target/ +/target/ +/target/ +/target/ diff --git a/hapi-fhir-structures-dstu2/pom.xml b/hapi-fhir-structures-dstu2/pom.xml index 6c2cc96eddc..789bbe6c060 100644 --- a/hapi-fhir-structures-dstu2/pom.xml +++ b/hapi-fhir-structures-dstu2/pom.xml @@ -40,7 +40,7 @@ xmlunit xmlunit - 1.6 + ${xmlunit_version} test diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/Dstu2EnvTest.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/Dstu2EnvTest.java deleted file mode 100644 index 77eb1431887..00000000000 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/Dstu2EnvTest.java +++ /dev/null @@ -1,17 +0,0 @@ -package ca.uhn.fhir; - -import static org.junit.Assert.*; - -import org.junit.Test; - -import ca.uhn.fhir.context.FhirContext; -import ca.uhn.fhir.context.FhirVersionEnum; - -public class Dstu2EnvTest { - - @Test - public void testCorrectDefault() { - FhirContext ctx = new FhirContext(); - assertEquals("new FhirContext() is creating a context with the wrong FHIR versions. Something is probably wrong with the classpath.", FhirVersionEnum.DSTU2, ctx.getVersion().getVersion()); - } -} diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/model/primitive/BaseDateTimeDtTest.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/model/primitive/BaseDateTimeDtDstu2Test.java similarity index 96% rename from hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/model/primitive/BaseDateTimeDtTest.java rename to hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/model/primitive/BaseDateTimeDtDstu2Test.java index 100fc199630..8cad29650a8 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/model/primitive/BaseDateTimeDtTest.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/model/primitive/BaseDateTimeDtDstu2Test.java @@ -15,9 +15,9 @@ import org.junit.Test; import ca.uhn.fhir.model.api.TemporalPrecisionEnum; -public class BaseDateTimeDtTest { +public class BaseDateTimeDtDstu2Test { private static Locale ourDefaultLocale; - private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(BaseDateTimeDtTest.class); + private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(BaseDateTimeDtDstu2Test.class); private SimpleDateFormat myDateInstantParser; @Before diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/narrative/BaseThymeleafNarrativeGeneratorTest.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/narrative/BaseThymeleafNarrativeGeneratorDstu2Test.java similarity index 93% rename from hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/narrative/BaseThymeleafNarrativeGeneratorTest.java rename to hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/narrative/BaseThymeleafNarrativeGeneratorDstu2Test.java index 8151d7ac233..aff14d39eb0 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/narrative/BaseThymeleafNarrativeGeneratorTest.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/narrative/BaseThymeleafNarrativeGeneratorDstu2Test.java @@ -4,8 +4,8 @@ import static org.junit.Assert.assertEquals; import org.junit.Test; -public class BaseThymeleafNarrativeGeneratorTest { - private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(BaseThymeleafNarrativeGeneratorTest.class); +public class BaseThymeleafNarrativeGeneratorDstu2Test { + private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(BaseThymeleafNarrativeGeneratorDstu2Test.class); @Test public void testTrimWhitespace() { diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/narrative/CustomThymeleafNarrativeGeneratorTest.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/narrative/CustomThymeleafNarrativeGeneratorDstu2Test.java similarity index 77% rename from hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/narrative/CustomThymeleafNarrativeGeneratorTest.java rename to hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/narrative/CustomThymeleafNarrativeGeneratorDstu2Test.java index c6b8063e6e4..fe40d0e96c3 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/narrative/CustomThymeleafNarrativeGeneratorTest.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/narrative/CustomThymeleafNarrativeGeneratorDstu2Test.java @@ -9,16 +9,17 @@ import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.dstu2.composite.NarrativeDt; import ca.uhn.fhir.model.dstu2.resource.Practitioner; -public class CustomThymeleafNarrativeGeneratorTest { +public class CustomThymeleafNarrativeGeneratorDstu2Test { - private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(CustomThymeleafNarrativeGeneratorTest.class); + private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(CustomThymeleafNarrativeGeneratorDstu2Test.class); private static FhirContext ourCtx = FhirContext.forDstu2(); @Test public void testGenerator() { - CustomThymeleafNarrativeGenerator gen = new CustomThymeleafNarrativeGenerator("file:src/test/resources/narrative/customnarrative.properties"); +// CustomThymeleafNarrativeGenerator gen = new CustomThymeleafNarrativeGenerator("file:src/test/resources/narrative/customnarrative.properties"); + CustomThymeleafNarrativeGenerator gen = new CustomThymeleafNarrativeGenerator("classpath:narrative/customnarrative_dstu2.properties"); ourCtx.setNarrativeGenerator(gen); Practitioner p = new Practitioner(); diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/narrative/DefaultThymeleafNarrativeGeneratorTestDstu2.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/narrative/DefaultThymeleafNarrativeGeneratorTestDstu2.java index c85b2ef5c2e..3ac210921b1 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/narrative/DefaultThymeleafNarrativeGeneratorTestDstu2.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/narrative/DefaultThymeleafNarrativeGeneratorTestDstu2.java @@ -33,7 +33,7 @@ import ca.uhn.fhir.model.primitive.StringDt; import ca.uhn.fhir.parser.DataFormatException; public class DefaultThymeleafNarrativeGeneratorTestDstu2 { - private FhirContext myCtx; + private static FhirContext ourCtx = FhirContext.forDstu2(); private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(DefaultThymeleafNarrativeGeneratorTestDstu2.class); private DefaultThymeleafNarrativeGenerator myGen; @@ -44,8 +44,7 @@ public class DefaultThymeleafNarrativeGeneratorTestDstu2 { myGen.setIgnoreFailures(false); myGen.setIgnoreMissingTemplates(false); - myCtx = new FhirContext(); - myCtx.setNarrativeGenerator(myGen); + ourCtx.setNarrativeGenerator(myGen); } @Test @@ -125,7 +124,7 @@ public class DefaultThymeleafNarrativeGeneratorTestDstu2 { ""; //@formatter:on - OperationOutcome oo = myCtx.newXmlParser().parseResource(OperationOutcome.class, parse); + OperationOutcome oo = ourCtx.newXmlParser().parseResource(OperationOutcome.class, parse); // String output = gen.generateTitle(oo); // ourLog.info(output); @@ -188,7 +187,7 @@ public class DefaultThymeleafNarrativeGeneratorTestDstu2 { // Now try it with the parser - output = myCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(value); + output = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(value); ourLog.info(output); assertThat(output, StringContains.containsString("
Some & Diagnostic Report
")); diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/parser/JsonParserDstu2Test.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/parser/JsonParserDstu2Test.java index b591f0c7b09..5b3c0218af8 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/parser/JsonParserDstu2Test.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/parser/JsonParserDstu2Test.java @@ -232,7 +232,7 @@ public class JsonParserDstu2Test { report.getContained().getContainedResources().add(obsv); report.addResult().setResource(obsv); - IParser parser = new FhirContext().newXmlParser().setPrettyPrint(true); + IParser parser = ourCtx.newXmlParser().setPrettyPrint(true); String message = parser.encodeResourceToString(report); ourLog.info(message); Assert.assertThat(message, containsString("contained")); @@ -247,12 +247,12 @@ public class JsonParserDstu2Test { e.setResource(new Patient()); b.addCategory("scheme", "term", "label"); - String val = new FhirContext().newJsonParser().setPrettyPrint(false).encodeBundleToString(b); + String val = ourCtx.newJsonParser().setPrettyPrint(false).encodeBundleToString(b); ourLog.info(val); assertThat(val, not(containsString("text"))); - b = new FhirContext().newJsonParser().parseBundle(val); + b = ourCtx.newJsonParser().parseBundle(val); assertEquals(1, b.getEntries().size()); } @@ -268,11 +268,11 @@ public class JsonParserDstu2Test { Entry e = b.addEntry(); e.setResource(new Patient()); - String val = new FhirContext().newJsonParser().setPrettyPrint(false).encodeResourceToString(b); + String val = ourCtx.newJsonParser().setPrettyPrint(false).encodeResourceToString(b); ourLog.info(val); assertThat(val, not(containsString("text"))); - val = new FhirContext().newXmlParser().setPrettyPrint(false).encodeResourceToString(b); + val = ourCtx.newXmlParser().setPrettyPrint(false).encodeResourceToString(b); ourLog.info(val); assertThat(val, not(containsString("text"))); @@ -297,7 +297,7 @@ public class JsonParserDstu2Test { obsv.setId("#123"); report.addResult().setReference("#123"); - IParser parser = new FhirContext().newXmlParser().setPrettyPrint(true); + IParser parser = ourCtx.newXmlParser().setPrettyPrint(true); String message = parser.encodeResourceToString(report); ourLog.info(message); Assert.assertThat(message, containsString("contained")); diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/client/BundleTypeTest.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/client/BundleTypeDstu2Test.java similarity index 88% rename from hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/client/BundleTypeTest.java rename to hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/client/BundleTypeDstu2Test.java index 6a5923189a8..e42757332d1 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/client/BundleTypeTest.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/client/BundleTypeDstu2Test.java @@ -1,9 +1,7 @@ package ca.uhn.fhir.rest.client; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; +import static org.junit.Assert.*; +import static org.mockito.Mockito.*; import java.io.StringReader; import java.nio.charset.Charset; @@ -27,14 +25,13 @@ import org.mockito.internal.stubbing.defaultanswers.ReturnsDeepStubs; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.api.Bundle; -import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.model.dstu2.resource.Patient; import ca.uhn.fhir.model.valueset.BundleTypeEnum; import ca.uhn.fhir.rest.server.Constants; -public class BundleTypeTest { +public class BundleTypeDstu2Test { - private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(BundleTypeTest.class); + private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(BundleTypeDstu2Test.class); private FhirContext ourCtx; private HttpClient ourHttpClient; @@ -46,7 +43,7 @@ public class BundleTypeTest { ourHttpClient = mock(HttpClient.class, new ReturnsDeepStubs()); ourCtx.getRestfulClientFactory().setHttpClient(ourHttpClient); - ourCtx.getRestfulClientFactory().setServerValidationModeEnum(ServerValidationModeEnum.NEVER); + ourCtx.getRestfulClientFactory().setServerValidationMode(ServerValidationModeEnum.NEVER); ourHttpResponse = mock(HttpResponse.class, new ReturnsDeepStubs()); } diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/client/ETagClientTest.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/client/ETagClientDstu2Test.java similarity index 99% rename from hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/client/ETagClientTest.java rename to hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/client/ETagClientDstu2Test.java index cbb8b3bbd5e..74b3e2e614d 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/client/ETagClientTest.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/client/ETagClientDstu2Test.java @@ -39,7 +39,7 @@ import ca.uhn.fhir.rest.server.exceptions.PreconditionFailedException; /** * Created by dsotnikov on 2/25/2014. */ -public class ETagClientTest { +public class ETagClientDstu2Test { private static FhirContext ourCtx; private HttpClient myHttpClient; @@ -283,7 +283,7 @@ public class ETagClientTest { @BeforeClass public static void beforeClass() { - ourCtx = new FhirContext(); + ourCtx = FhirContext.forDstu2(); } } diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/client/OperationClientTest.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/client/OperationClientDstu2Test.java similarity index 99% rename from hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/client/OperationClientTest.java rename to hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/client/OperationClientDstu2Test.java index a8997359971..ca9eb53ed4b 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/client/OperationClientTest.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/client/OperationClientDstu2Test.java @@ -38,9 +38,9 @@ import ca.uhn.fhir.rest.annotation.OperationParam; import ca.uhn.fhir.rest.client.api.IBasicClient; import ca.uhn.fhir.rest.server.Constants; -public class OperationClientTest { +public class OperationClientDstu2Test { - private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(OperationClientTest.class); + private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(OperationClientDstu2Test.class); private FhirContext ourCtx; private HttpClient ourHttpClient; diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/BinaryTestDstu2.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/BinaryTestDstu2.java index def08cc63f7..08ebbc7aa49 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/BinaryTestDstu2.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/BinaryTestDstu2.java @@ -46,7 +46,7 @@ import ca.uhn.fhir.util.PortUtil; public class BinaryTestDstu2 { private static CloseableHttpClient ourClient; - private static FhirContext ourCtx = new FhirContext(); + private static FhirContext ourCtx = FhirContext.forDstu2(); private static Binary ourLast; private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(BinaryTestDstu2.class); @@ -186,7 +186,7 @@ public class BinaryTestDstu2 { ResourceProvider patientProvider = new ResourceProvider(); ServletHandler proxyHandler = new ServletHandler(); - RestfulServer servlet = new RestfulServer(); + RestfulServer servlet = new RestfulServer(ourCtx); servlet.setResourceProviders(patientProvider); ServletHolder servletHolder = new ServletHolder(servlet); proxyHandler.addServletWithMapping(servletHolder, "/*"); diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/BundleTypeInResponseTest.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/BundleTypeInResponseTest.java index 67ccabc5262..67e76ee64a3 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/BundleTypeInResponseTest.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/BundleTypeInResponseTest.java @@ -34,7 +34,7 @@ import ca.uhn.fhir.util.PortUtil; public class BundleTypeInResponseTest { private static CloseableHttpClient ourClient; - private static FhirContext ourCtx = new FhirContext(); + private static FhirContext ourCtx = FhirContext.forDstu2(); private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(BundleTypeInResponseTest.class); private static int ourPort; @@ -69,7 +69,7 @@ public class BundleTypeInResponseTest { DummyPatientResourceProvider patientProvider = new DummyPatientResourceProvider(); ServletHandler proxyHandler = new ServletHandler(); - RestfulServer servlet = new RestfulServer(); + RestfulServer servlet = new RestfulServer(ourCtx); servlet.getFhirContext().setNarrativeGenerator(new DefaultThymeleafNarrativeGenerator()); servlet.setResourceProviders(patientProvider); diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/CreateConditionalTest.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/CreateConditionalTest.java index 6ad36c6d173..446b33ee590 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/CreateConditionalTest.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/CreateConditionalTest.java @@ -52,6 +52,7 @@ public class CreateConditionalTest { private static IdDt ourLastId; private static IdDt ourLastIdParam; private static boolean ourLastRequestWasSearch; + private static FhirContext ourCtx = FhirContext.forDstu2(); @@ -71,7 +72,7 @@ public class CreateConditionalTest { HttpPost httpPost = new HttpPost("http://localhost:" + ourPort + "/Patient"); httpPost.addHeader(Constants.HEADER_IF_NONE_EXIST, "Patient?identifier=system%7C001"); - httpPost.setEntity(new StringEntity(new FhirContext().newXmlParser().encodeResourceToString(patient), ContentType.create(Constants.CT_FHIR_XML, "UTF-8"))); + httpPost.setEntity(new StringEntity(ourCtx.newXmlParser().encodeResourceToString(patient), ContentType.create(Constants.CT_FHIR_XML, "UTF-8"))); HttpResponse status = ourClient.execute(httpPost); @@ -97,7 +98,7 @@ public class CreateConditionalTest { patient.addIdentifier().setValue("002"); HttpPost httpPost = new HttpPost("http://localhost:" + ourPort + "/Patient/2?_format=true&_pretty=true"); - httpPost.setEntity(new StringEntity(new FhirContext().newXmlParser().encodeResourceToString(patient), ContentType.create(Constants.CT_FHIR_XML, "UTF-8"))); + httpPost.setEntity(new StringEntity(ourCtx.newXmlParser().encodeResourceToString(patient), ContentType.create(Constants.CT_FHIR_XML, "UTF-8"))); HttpResponse status = ourClient.execute(httpPost); @@ -153,7 +154,7 @@ public class CreateConditionalTest { PatientProvider patientProvider = new PatientProvider(); ServletHandler proxyHandler = new ServletHandler(); - RestfulServer servlet = new RestfulServer(); + RestfulServer servlet = new RestfulServer(ourCtx); servlet.setResourceProviders(patientProvider); ServletHolder servletHolder = new ServletHolder(servlet); proxyHandler.addServletWithMapping(servletHolder, "/*"); diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/DeleteConditionalTest.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/DeleteConditionalTest.java index 280d8b3effe..6b193300dec 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/DeleteConditionalTest.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/DeleteConditionalTest.java @@ -18,6 +18,7 @@ import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; +import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.model.dstu2.resource.Patient; import ca.uhn.fhir.model.primitive.IdDt; @@ -34,7 +35,7 @@ public class DeleteConditionalTest { private static CloseableHttpClient ourClient; private static String ourLastConditionalUrl; private static int ourPort; - + private static final FhirContext ourCtx = FhirContext.forDstu2(); private static Server ourServer; private static IdDt ourLastIdParam; @@ -91,7 +92,7 @@ public class DeleteConditionalTest { PatientProvider patientProvider = new PatientProvider(); ServletHandler proxyHandler = new ServletHandler(); - RestfulServer servlet = new RestfulServer(); + RestfulServer servlet = new RestfulServer(ourCtx); servlet.setResourceProviders(patientProvider); ServletHolder servletHolder = new ServletHolder(servlet); proxyHandler.addServletWithMapping(servletHolder, "/*"); diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/ETagServerTest.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/ETagServerTest.java index b7f194cddb3..1318a12cfa9 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/ETagServerTest.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/ETagServerTest.java @@ -171,7 +171,7 @@ public class ETagServerTest { PatientProvider patientProvider = new PatientProvider(); ServletHandler proxyHandler = new ServletHandler(); - RestfulServer servlet = new RestfulServer(); + RestfulServer servlet = new RestfulServer(ourCtx); ourCtx = servlet.getFhirContext(); servlet.setResourceProviders(patientProvider); ServletHolder servletHolder = new ServletHolder(servlet); diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/IncludeAndRevincludeParameterTest.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/IncludeAndRevincludeParameterTest.java index 4c9f88016af..98af0b55a13 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/IncludeAndRevincludeParameterTest.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/IncludeAndRevincludeParameterTest.java @@ -85,13 +85,12 @@ public class IncludeAndRevincludeParameterTest { @BeforeClass public static void beforeClass() throws Exception { - ourCtx = new FhirContext(); + ourCtx = FhirContext.forDstu2(); ourPort = PortUtil.findFreePort(); ourServer = new Server(ourPort); ServletHandler proxyHandler = new ServletHandler(); - RestfulServer servlet = new RestfulServer(); - servlet.setFhirContext(ourCtx); + RestfulServer servlet = new RestfulServer(ourCtx); servlet.setResourceProviders(new DummyPatientResourceProvider()); servlet.setBundleInclusionRule(BundleInclusionRule.BASED_ON_RESOURCE_PRESENCE); ServletHolder servletHolder = new ServletHolder(servlet); diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/IncludeDstu2Test.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/IncludeDstu2Test.java index f0d8eab9ad6..7fd65eb5238 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/IncludeDstu2Test.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/IncludeDstu2Test.java @@ -270,15 +270,14 @@ public class IncludeDstu2Test { @BeforeClass public static void beforeClass() throws Exception { - ourCtx = new FhirContext(); + ourCtx = FhirContext.forDstu2(); ourPort = PortUtil.findFreePort(); ourServer = new Server(ourPort); DummyPatientResourceProvider patientProvider = new DummyPatientResourceProvider(); ServletHandler proxyHandler = new ServletHandler(); - RestfulServer servlet = new RestfulServer(); - servlet.setFhirContext(ourCtx); + RestfulServer servlet = new RestfulServer(ourCtx); servlet.setResourceProviders(patientProvider, new DummyDiagnosticReportResourceProvider()); servlet.setBundleInclusionRule(BundleInclusionRule.BASED_ON_RESOURCE_PRESENCE); ServletHolder servletHolder = new ServletHolder(servlet); diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/OperationServerTest.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/OperationServerTest.java index 74b063b7c69..48249943126 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/OperationServerTest.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/OperationServerTest.java @@ -334,7 +334,7 @@ public class OperationServerTest { ourServer = new Server(ourPort); ServletHandler proxyHandler = new ServletHandler(); - RestfulServer servlet = new RestfulServer(); + RestfulServer servlet = new RestfulServer(ourCtx); servlet.setPagingProvider(new FifoMemoryPagingProvider(10).setDefaultPageSize(2)); diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/PreferTest.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/PreferTest.java index 9915ce84b78..6daf96cba5b 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/PreferTest.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/PreferTest.java @@ -39,7 +39,7 @@ public class PreferTest { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(PreferTest.class); private static int ourPort; private static Server ourServer; - + private static FhirContext ourCtx = FhirContext.forDstu2(); @Test @@ -49,7 +49,7 @@ public class PreferTest { patient.addIdentifier().setValue("002"); HttpPost httpPost = new HttpPost("http://localhost:" + ourPort + "/Patient"); - httpPost.setEntity(new StringEntity(new FhirContext().newXmlParser().encodeResourceToString(patient), ContentType.create(Constants.CT_FHIR_XML, "UTF-8"))); + httpPost.setEntity(new StringEntity(ourCtx.newXmlParser().encodeResourceToString(patient), ContentType.create(Constants.CT_FHIR_XML, "UTF-8"))); HttpResponse status = ourClient.execute(httpPost); @@ -81,7 +81,7 @@ public class PreferTest { PatientProvider patientProvider = new PatientProvider(); ServletHandler proxyHandler = new ServletHandler(); - RestfulServer servlet = new RestfulServer(); + RestfulServer servlet = new RestfulServer(ourCtx); servlet.setResourceProviders(patientProvider); ServletHolder servletHolder = new ServletHolder(servlet); proxyHandler.addServletWithMapping(servletHolder, "/*"); diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/ReadTest.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/ReadDstu2Test.java similarity index 96% rename from hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/ReadTest.java rename to hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/ReadDstu2Test.java index a0f41c08def..159416ebb3f 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/ReadTest.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/ReadDstu2Test.java @@ -30,13 +30,13 @@ import ca.uhn.fhir.util.PortUtil; /** * Created by dsotnikov on 2/25/2014. */ -public class ReadTest { +public class ReadDstu2Test { private static CloseableHttpClient ourClient; private static int ourPort; private static Server ourServer; - private static FhirContext ourCtx; - + private static FhirContext ourCtx = FhirContext.forDstu2(); + /** * In DSTU2+ the resource ID appears in the resource body */ @@ -75,14 +75,13 @@ public class ReadTest { @BeforeClass public static void beforeClass() throws Exception { - ourCtx = new FhirContext(); ourPort = PortUtil.findFreePort(); ourServer = new Server(ourPort); DummyPatientResourceProvider patientProvider = new DummyPatientResourceProvider(); ServletHandler proxyHandler = new ServletHandler(); - RestfulServer servlet = new RestfulServer(); + RestfulServer servlet = new RestfulServer(ourCtx); servlet.setFhirContext(ourCtx); servlet.setResourceProviders(patientProvider); ServletHolder servletHolder = new ServletHolder(servlet); diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/SearchDstu2Test.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/SearchDstu2Test.java index cf689c9ac88..830e7cd04dc 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/SearchDstu2Test.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/SearchDstu2Test.java @@ -35,7 +35,7 @@ import ca.uhn.fhir.util.PortUtil; public class SearchDstu2Test { private static CloseableHttpClient ourClient; - private static FhirContext ourCtx = new FhirContext(); + private static FhirContext ourCtx = FhirContext.forDstu2(); private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(SearchDstu2Test.class); private static int ourPort; @@ -100,7 +100,7 @@ public class SearchDstu2Test { DummyPatientResourceProvider patientProvider = new DummyPatientResourceProvider(); ServletHandler proxyHandler = new ServletHandler(); - RestfulServer servlet = new RestfulServer(); + RestfulServer servlet = new RestfulServer(ourCtx); servlet.setResourceProviders(patientProvider); ServletHolder servletHolder = new ServletHolder(servlet); diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/SearchWithDstu2BundleTest.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/SearchWithDstu2BundleTest.java index b9b963414e4..bdb22d397b7 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/SearchWithDstu2BundleTest.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/SearchWithDstu2BundleTest.java @@ -30,7 +30,7 @@ public class SearchWithDstu2BundleTest { private static CloseableHttpClient ourClient; private static int ourPort; private static Server ourServer; - private static FhirContext ourCtx; + private static FhirContext ourCtx = FhirContext.forDstu2(); private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(SearchWithDstu2BundleTest.class); @Test @@ -69,14 +69,13 @@ public class SearchWithDstu2BundleTest { @BeforeClass public static void beforeClass() throws Exception { - ourCtx = new FhirContext(); ourPort = PortUtil.findFreePort(); ourServer = new Server(ourPort); DummyPatientResourceProvider patientProvider = new DummyPatientResourceProvider(); ServletHandler proxyHandler = new ServletHandler(); - RestfulServer servlet = new RestfulServer(); + RestfulServer servlet = new RestfulServer(ourCtx); servlet.setFhirContext(ourCtx); servlet.setResourceProviders(patientProvider); ServletHolder servletHolder = new ServletHolder(servlet); diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/ServerConformanceProviderDstu2Test.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/ServerConformanceProviderDstu2Test.java index a4e23c221fd..e22dcbe6f8c 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/ServerConformanceProviderDstu2Test.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/ServerConformanceProviderDstu2Test.java @@ -46,12 +46,12 @@ import ca.uhn.fhir.rest.server.provider.dstu2.ServerConformanceProvider; public class ServerConformanceProviderDstu2Test { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ServerConformanceProviderDstu2Test.class); - private FhirContext myCtx = new FhirContext(); + private static FhirContext ourCtx = FhirContext.forDstu2(); @Test public void testSearchParameterDocumentation() throws Exception { - RestfulServer rs = new RestfulServer(); + RestfulServer rs = new RestfulServer(ourCtx); rs.setProviders(new SearchProvider()); ServerConformanceProvider sc = new ServerConformanceProvider(rs); @@ -73,7 +73,7 @@ public class ServerConformanceProviderDstu2Test { assertTrue(found); Conformance conformance = sc.getServerConformance(createHttpServletRequest()); - String conf = myCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(conformance); + String conf = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(conformance); ourLog.info(conf); assertThat(conf, containsString("")); @@ -84,7 +84,7 @@ public class ServerConformanceProviderDstu2Test { @Test public void testOperationDocumentation() throws Exception { - RestfulServer rs = new RestfulServer(); + RestfulServer rs = new RestfulServer(ourCtx); rs.setProviders(new SearchProvider()); ServerConformanceProvider sc = new ServerConformanceProvider(rs); @@ -106,7 +106,7 @@ public class ServerConformanceProviderDstu2Test { assertTrue(found); Conformance conformance = sc.getServerConformance(createHttpServletRequest()); - String conf = myCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(conformance); + String conf = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(conformance); ourLog.info(conf); assertThat(conf, containsString("")); @@ -117,7 +117,7 @@ public class ServerConformanceProviderDstu2Test { @Test public void testExtendedOperationReturningBundle() throws Exception { - RestfulServer rs = new RestfulServer(); + RestfulServer rs = new RestfulServer(ourCtx); rs.setProviders(new ProviderWithExtendedOperationReturningBundle()); ServerConformanceProvider sc = new ServerConformanceProvider(rs); @@ -127,7 +127,7 @@ public class ServerConformanceProviderDstu2Test { Conformance conformance = sc.getServerConformance(createHttpServletRequest()); - String conf = myCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(conformance); + String conf = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(conformance); ourLog.info(conf); } @@ -135,7 +135,7 @@ public class ServerConformanceProviderDstu2Test { @Test public void testValidateGeneratedStatement() throws Exception { - RestfulServer rs = new RestfulServer(); + RestfulServer rs = new RestfulServer(ourCtx); rs.setProviders(new MultiOptionalProvider()); ServerConformanceProvider sc = new ServerConformanceProvider(rs); @@ -145,7 +145,7 @@ public class ServerConformanceProviderDstu2Test { Conformance conformance = sc.getServerConformance(createHttpServletRequest()); - assertTrue(myCtx.newValidator().validateWithResult(conformance).isSuccessful()); + assertTrue(ourCtx.newValidator().validateWithResult(conformance).isSuccessful()); } @@ -153,7 +153,7 @@ public class ServerConformanceProviderDstu2Test { @Test public void testMultiOptionalDocumentation() throws Exception { - RestfulServer rs = new RestfulServer(); + RestfulServer rs = new RestfulServer(ourCtx); rs.setProviders(new MultiOptionalProvider()); ServerConformanceProvider sc = new ServerConformanceProvider(rs); @@ -175,7 +175,7 @@ public class ServerConformanceProviderDstu2Test { assertTrue(found); Conformance conformance = sc.getServerConformance(createHttpServletRequest()); - String conf = new FhirContext().newXmlParser().setPrettyPrint(true).encodeResourceToString(conformance); + String conf = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(conformance); ourLog.info(conf); assertThat(conf, containsString("")); @@ -186,7 +186,7 @@ public class ServerConformanceProviderDstu2Test { @Test public void testProviderWithRequiredAndOptional() throws Exception { - RestfulServer rs = new RestfulServer(); + RestfulServer rs = new RestfulServer(ourCtx); rs.setProviders(new ProviderWithRequiredAndOptional()); ServerConformanceProvider sc = new ServerConformanceProvider(rs); @@ -195,7 +195,7 @@ public class ServerConformanceProviderDstu2Test { rs.init(createServletConfig()); Conformance conformance = sc.getServerConformance(createHttpServletRequest()); - String conf = new FhirContext().newXmlParser().setPrettyPrint(true).encodeResourceToString(conformance); + String conf = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(conformance); ourLog.info(conf); Rest rest = conformance.getRestFirstRep(); diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/ServerInvalidDefinitionDstu2Test.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/ServerInvalidDefinitionDstu2Test.java index bfdecac3e10..04eec27dd26 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/ServerInvalidDefinitionDstu2Test.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/ServerInvalidDefinitionDstu2Test.java @@ -20,7 +20,7 @@ public class ServerInvalidDefinitionDstu2Test { @Test public void testOperationReturningOldBundleProvider() { - RestfulServer srv = new RestfulServer(); + RestfulServer srv = new RestfulServer(ourCtx); srv.setFhirContext(ourCtx); srv.setResourceProviders(new OperationReturningOldBundleProvider()); diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/TransactionWithBundleResourceParamTest.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/TransactionWithBundleResourceParamTest.java index b8deec6db73..130bbbe46ee 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/TransactionWithBundleResourceParamTest.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/TransactionWithBundleResourceParamTest.java @@ -48,7 +48,7 @@ public class TransactionWithBundleResourceParamTest { } private static CloseableHttpClient ourClient; - private static FhirContext ourCtx = new FhirContext(); + private static FhirContext ourCtx = FhirContext.forDstu2(); private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(TransactionWithBundleResourceParamTest.class); private static int ourPort; private static boolean ourReturnOperationOutcome; @@ -208,7 +208,7 @@ public class TransactionWithBundleResourceParamTest { ourLog.info(responseContent); - Bundle bundle = new FhirContext().newXmlParser().parseResource(Bundle.class, responseContent); + Bundle bundle = ourCtx.newXmlParser().parseResource(Bundle.class, responseContent); assertEquals(4, bundle.getEntry().size()); assertEquals(OperationOutcome.class, bundle.getEntry().get(0).getResource().getClass()); @@ -234,7 +234,7 @@ public class TransactionWithBundleResourceParamTest { ourServer = new Server(ourPort); DummyProvider patientProvider = new DummyProvider(); - RestfulServer server = new RestfulServer(); + RestfulServer server = new RestfulServer(ourCtx); server.setProviders(patientProvider); org.eclipse.jetty.servlet.ServletContextHandler proxyHandler = new org.eclipse.jetty.servlet.ServletContextHandler(); diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/UpdateConditionalTest.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/UpdateConditionalTest.java index 31692213e12..00276a123c9 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/UpdateConditionalTest.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/UpdateConditionalTest.java @@ -52,7 +52,7 @@ public class UpdateConditionalTest { private static String ourLastConditionalUrl; private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(UpdateConditionalTest.class); private static int ourPort; - + private static FhirContext ourCtx = FhirContext.forDstu2(); private static Server ourServer; private static IdDt ourLastId; private static IdDt ourLastIdParam; @@ -75,7 +75,7 @@ public class UpdateConditionalTest { patient.addIdentifier().setValue("002"); HttpPut httpPost = new HttpPut("http://localhost:" + ourPort + "/Patient?identifier=system%7C001"); - httpPost.setEntity(new StringEntity(new FhirContext().newXmlParser().encodeResourceToString(patient), ContentType.create(Constants.CT_FHIR_XML, "UTF-8"))); + httpPost.setEntity(new StringEntity(ourCtx.newXmlParser().encodeResourceToString(patient), ContentType.create(Constants.CT_FHIR_XML, "UTF-8"))); HttpResponse status = ourClient.execute(httpPost); @@ -101,7 +101,7 @@ public class UpdateConditionalTest { patient.addIdentifier().setValue("002"); HttpPut httpPost = new HttpPut("http://localhost:" + ourPort + "/Patient/2"); - httpPost.setEntity(new StringEntity(new FhirContext().newXmlParser().encodeResourceToString(patient), ContentType.create(Constants.CT_FHIR_XML, "UTF-8"))); + httpPost.setEntity(new StringEntity(ourCtx.newXmlParser().encodeResourceToString(patient), ContentType.create(Constants.CT_FHIR_XML, "UTF-8"))); HttpResponse status = ourClient.execute(httpPost); @@ -157,7 +157,7 @@ public class UpdateConditionalTest { PatientProvider patientProvider = new PatientProvider(); ServletHandler proxyHandler = new ServletHandler(); - RestfulServer servlet = new RestfulServer(); + RestfulServer servlet = new RestfulServer(ourCtx); servlet.setResourceProviders(patientProvider); ServletHolder servletHolder = new ServletHolder(servlet); proxyHandler.addServletWithMapping(servletHolder, "/*"); diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/ValidateDstu2Test.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/ValidateDstu2Test.java index 1b2fc6e53ae..a0e3e621e3a 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/ValidateDstu2Test.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/ValidateDstu2Test.java @@ -44,13 +44,13 @@ public class ValidateDstu2Test { private static CloseableHttpClient ourClient; private static EncodingEnum ourLastEncoding; private static String ourLastResourceBody; - private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ValidateDstu2Test.class); private static int ourPort; private static Server ourServer; private static BaseOperationOutcome ourOutcomeToReturn; private static ValidationModeEnum ourLastMode; private static String ourLastProfile; - + private static FhirContext ourCtx = FhirContext.forDstu2(); + @Before() public void before() { ourLastResourceBody = null; @@ -73,7 +73,7 @@ public class ValidateDstu2Test { params.addParameter().setName("mode").setValue(new StringDt(ValidationModeEnum.CREATE.name())); HttpPost httpPost = new HttpPost("http://localhost:" + ourPort + "/Patient/$validate"); - httpPost.setEntity(new StringEntity(new FhirContext().newXmlParser().encodeResourceToString(params), ContentType.create(Constants.CT_FHIR_XML, "UTF-8"))); + httpPost.setEntity(new StringEntity(ourCtx.newXmlParser().encodeResourceToString(params), ContentType.create(Constants.CT_FHIR_XML, "UTF-8"))); HttpResponse status = ourClient.execute(httpPost); String resp = IOUtils.toString(status.getEntity().getContent()); @@ -97,7 +97,7 @@ public class ValidateDstu2Test { params.addParameter().setName("resource").setResource(patient); HttpPost httpPost = new HttpPost("http://localhost:" + ourPort + "/Patient/$validate"); - httpPost.setEntity(new StringEntity(new FhirContext().newXmlParser().encodeResourceToString(params), ContentType.create(Constants.CT_FHIR_XML, "UTF-8"))); + httpPost.setEntity(new StringEntity(ourCtx.newXmlParser().encodeResourceToString(params), ContentType.create(Constants.CT_FHIR_XML, "UTF-8"))); HttpResponse status = ourClient.execute(httpPost); String resp = IOUtils.toString(status.getEntity().getContent()); @@ -122,7 +122,7 @@ public class ValidateDstu2Test { params.addParameter().setName("resource").setResource(patient); HttpPost httpPost = new HttpPost("http://localhost:" + ourPort + "/Patient/$validate"); - httpPost.setEntity(new StringEntity(new FhirContext().newXmlParser().encodeResourceToString(params), ContentType.create(Constants.CT_FHIR_XML, "UTF-8"))); + httpPost.setEntity(new StringEntity(ourCtx.newXmlParser().encodeResourceToString(params), ContentType.create(Constants.CT_FHIR_XML, "UTF-8"))); HttpResponse status = ourClient.execute(httpPost); String resp = IOUtils.toString(status.getEntity().getContent()); @@ -144,7 +144,7 @@ public class ValidateDstu2Test { params.addParameter().setName("resource").setResource(org); HttpPost httpPost = new HttpPost("http://localhost:" + ourPort + "/Organization/$validate"); - httpPost.setEntity(new StringEntity(new FhirContext().newJsonParser().encodeResourceToString(params), ContentType.create(Constants.CT_FHIR_JSON, "UTF-8"))); + httpPost.setEntity(new StringEntity(ourCtx.newJsonParser().encodeResourceToString(params), ContentType.create(Constants.CT_FHIR_JSON, "UTF-8"))); HttpResponse status = ourClient.execute(httpPost); assertEquals(200, status.getStatusLine().getStatusCode()); @@ -167,7 +167,7 @@ public class ValidateDstu2Test { PatientProvider patientProvider = new PatientProvider(); ServletHandler proxyHandler = new ServletHandler(); - RestfulServer servlet = new RestfulServer(); + RestfulServer servlet = new RestfulServer(ourCtx); servlet.setResourceProviders(patientProvider, new OrganizationProvider()); ServletHolder servletHolder = new ServletHolder(servlet); proxyHandler.addServletWithMapping(servletHolder, "/*"); diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/interceptor/LoggingInterceptorTest.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/interceptor/LoggingInterceptorDstu2Test.java similarity index 98% rename from hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/interceptor/LoggingInterceptorTest.java rename to hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/interceptor/LoggingInterceptorDstu2Test.java index 3407a78a722..033987cdf77 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/interceptor/LoggingInterceptorTest.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/interceptor/LoggingInterceptorDstu2Test.java @@ -28,6 +28,7 @@ import org.junit.Test; import org.mockito.ArgumentCaptor; import org.slf4j.Logger; +import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.dstu2.composite.HumanNameDt; import ca.uhn.fhir.model.dstu2.composite.IdentifierDt; import ca.uhn.fhir.model.dstu2.resource.Bundle; @@ -50,14 +51,15 @@ import ca.uhn.fhir.util.PortUtil; /** * Created by dsotnikov on 2/25/2014. */ -public class LoggingInterceptorTest { +public class LoggingInterceptorDstu2Test { private static CloseableHttpClient ourClient; private static int ourPort; private static Server ourServer; private static RestfulServer servlet; private IServerInterceptor myInterceptor; - + private static final FhirContext ourCtx = FhirContext.forDstu2(); + @Test public void testRead() throws Exception { @@ -187,7 +189,7 @@ public class LoggingInterceptorTest { ourServer = new Server(ourPort); ServletHandler proxyHandler = new ServletHandler(); - servlet = new RestfulServer(); + servlet = new RestfulServer(ourCtx); servlet.setResourceProviders(new DummyPatientResourceProvider()); servlet.setPlainProviders(new PlainProvider()); diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/provider/dstu2/Dstu2BundleFactoryTest.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/provider/dstu2/Dstu2BundleFactoryTest.java index 7c8974c711f..22e8a6b3737 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/provider/dstu2/Dstu2BundleFactoryTest.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/provider/dstu2/Dstu2BundleFactoryTest.java @@ -32,7 +32,7 @@ public class Dstu2BundleFactoryTest { @BeforeClass public static void beforeClass() throws Exception { - ourCtx = new FhirContext(Patient.class); + ourCtx = FhirContext.forDstu2(); } @Before @@ -159,7 +159,8 @@ public class Dstu2BundleFactoryTest { return count; } - private List getResourcesOfType(Bundle theBundle, Class theResourceClass) { + @SuppressWarnings("unchecked") + private List getResourcesOfType(Bundle theBundle, Class theResourceClass) { List resources = new ArrayList(); for (Bundle.Entry entry : theBundle.getEntry()) { if (theResourceClass.isAssignableFrom(entry.getResource().getClass())) { diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/util/FhirTerserDstu2Test.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/util/FhirTerserDstu2Test.java index f8f900a97fa..74d36ddef51 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/util/FhirTerserDstu2Test.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/util/FhirTerserDstu2Test.java @@ -24,7 +24,7 @@ import ca.uhn.fhir.model.primitive.StringDt; public class FhirTerserDstu2Test { - private static FhirContext ourCtx = new FhirContext(); + private static FhirContext ourCtx = FhirContext.forDstu2(); @Test public void testGetAllPopulatedChildElementsOfTypeDoesntDescendIntoEmbedded() { diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/validation/ValidationResultTest.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/validation/ValidationResultDstu2Test.java similarity index 98% rename from hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/validation/ValidationResultTest.java rename to hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/validation/ValidationResultDstu2Test.java index d3acf3b2128..5ce8e1f737f 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/validation/ValidationResultTest.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/validation/ValidationResultDstu2Test.java @@ -14,7 +14,7 @@ import org.junit.Test; import ca.uhn.fhir.model.base.resource.BaseOperationOutcome.BaseIssue; import ca.uhn.fhir.model.dstu2.resource.OperationOutcome; -public class ValidationResultTest { +public class ValidationResultDstu2Test { @Test public void isSuccessful_IsTrueForNullOperationOutcome() { diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/validation/ValidatorInstantiatorTest.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/validation/ValidatorInstantiatorDstu2Test.java similarity index 71% rename from hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/validation/ValidatorInstantiatorTest.java rename to hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/validation/ValidatorInstantiatorDstu2Test.java index 27fc3a42ea2..08e1b7329da 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/validation/ValidatorInstantiatorTest.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/validation/ValidatorInstantiatorDstu2Test.java @@ -6,13 +6,13 @@ import org.junit.Test; import ca.uhn.fhir.context.FhirContext; -public class ValidatorInstantiatorTest { +public class ValidatorInstantiatorDstu2Test { + private static FhirContext ourCtx = FhirContext.forDstu2(); @Test public void testValidator() { - FhirContext ctx = new FhirContext(); - FhirValidator val = ctx.newValidator(); + FhirValidator val = ourCtx.newValidator(); // We have a full classpath, so take advantage assertTrue(val.isValidateAgainstStandardSchema()); diff --git a/hapi-fhir-structures-dstu2/src/test/resources/logback-test.xml b/hapi-fhir-structures-dstu2/src/test/resources/logback-test.xml index 996190aeccf..e5cbbb9c22e 100644 --- a/hapi-fhir-structures-dstu2/src/test/resources/logback-test.xml +++ b/hapi-fhir-structures-dstu2/src/test/resources/logback-test.xml @@ -23,8 +23,8 @@ --> - + - \ No newline at end of file + diff --git a/hapi-fhir-structures-dstu2/src/test/resources/narrative/Practitioner.html b/hapi-fhir-structures-dstu2/src/test/resources/narrative/PractitionerDstu2.html similarity index 100% rename from hapi-fhir-structures-dstu2/src/test/resources/narrative/Practitioner.html rename to hapi-fhir-structures-dstu2/src/test/resources/narrative/PractitionerDstu2.html diff --git a/hapi-fhir-structures-dstu2/src/test/resources/narrative/customnarrative.properties b/hapi-fhir-structures-dstu2/src/test/resources/narrative/customnarrative_dstu2.properties similarity index 78% rename from hapi-fhir-structures-dstu2/src/test/resources/narrative/customnarrative.properties rename to hapi-fhir-structures-dstu2/src/test/resources/narrative/customnarrative_dstu2.properties index 628b77ea47b..7edb1758dda 100644 --- a/hapi-fhir-structures-dstu2/src/test/resources/narrative/customnarrative.properties +++ b/hapi-fhir-structures-dstu2/src/test/resources/narrative/customnarrative_dstu2.properties @@ -8,8 +8,8 @@ # template file. # Format is file:/path/foo.html or classpath:/com/classpath/foo.html # -practitioner.class=ca.uhn.fhir.model.dev.resource.Practitioner -practitioner.narrative=file:src/test/resources/narrative/Practitioner.html +practitioner.class=ca.uhn.fhir.model.dstu2.resource.Practitioner +practitioner.narrative=classpath:narrative/PractitionerDstu2.html # You may also override/define behaviour for datatypes humanname.class=ca.uhn.fhir.model.dev.composite.HumanNameDt diff --git a/hapi-fhir-structures-hl7org-dstu2/.gitignore b/hapi-fhir-structures-hl7org-dstu2/.gitignore index 88dc6eaba34..d9b8e6daf6e 100644 --- a/hapi-fhir-structures-hl7org-dstu2/.gitignore +++ b/hapi-fhir-structures-hl7org-dstu2/.gitignore @@ -126,3 +126,4 @@ local.properties # TeXlipse plugin .texlipse +/target/ diff --git a/hapi-fhir-structures-hl7org-dstu2/src/test/java/ca/uhn/fhir/model/IdTypeTest.java b/hapi-fhir-structures-hl7org-dstu2/src/test/java/ca/uhn/fhir/model/IdTypeTest.java index 7312c7bef1f..17a20de2ca8 100644 --- a/hapi-fhir-structures-hl7org-dstu2/src/test/java/ca/uhn/fhir/model/IdTypeTest.java +++ b/hapi-fhir-structures-hl7org-dstu2/src/test/java/ca/uhn/fhir/model/IdTypeTest.java @@ -220,7 +220,7 @@ public class IdTypeTest { @BeforeClass public static void beforeClass() { - ourCtx = new FhirContext(); + ourCtx = FhirContext.forDstu2Hl7Org(); } } diff --git a/hapi-fhir-structures-hl7org-dstu2/src/test/java/ca/uhn/fhir/parser/JsonParserHl7OrgTest.java b/hapi-fhir-structures-hl7org-dstu2/src/test/java/ca/uhn/fhir/parser/JsonParserHl7OrgTest.java index 597cb0c8b1b..a27e5b611e2 100644 --- a/hapi-fhir-structures-hl7org-dstu2/src/test/java/ca/uhn/fhir/parser/JsonParserHl7OrgTest.java +++ b/hapi-fhir-structures-hl7org-dstu2/src/test/java/ca/uhn/fhir/parser/JsonParserHl7OrgTest.java @@ -451,7 +451,7 @@ public class JsonParserHl7OrgTest { @Test public void testEncodeDeclaredExtensionWithAddressContent() { - IParser parser = new FhirContext().newJsonParser(); + IParser parser = ourCtx.newJsonParser(); MyPatientWithOneDeclaredAddressExtension patient = new MyPatientWithOneDeclaredAddressExtension(); patient.addAddress().setUse(AddressUse.HOME); @@ -470,7 +470,7 @@ public class JsonParserHl7OrgTest { @Test public void testEncodeDeclaredExtensionWithResourceContent() { - IParser parser = new FhirContext().newJsonParser(); + IParser parser = ourCtx.newJsonParser(); MyPatientWithOneDeclaredExtension patient = new MyPatientWithOneDeclaredExtension(); patient.addAddress().setUse(AddressUse.HOME); @@ -586,7 +586,7 @@ public class JsonParserHl7OrgTest { @Test public void testEncodeExtensionWithResourceContent() { - IParser parser = new FhirContext().newJsonParser(); + IParser parser = ourCtx.newJsonParser(); Patient patient = new Patient(); patient.addAddress().setUse(AddressUse.HOME); @@ -698,7 +698,7 @@ public class JsonParserHl7OrgTest { Patient patient = new Patient(); patient.setManagingOrganization(new Reference()); - IParser p = new FhirContext().newJsonParser(); + IParser p = ourCtx.newJsonParser(); String str = p.encodeResourceToString(patient); assertThat(str, IsNot.not(StringContains.containsString("managingOrganization"))); @@ -716,7 +716,7 @@ public class JsonParserHl7OrgTest { @Test public void testEncodeUndeclaredExtensionWithAddressContent() { - IParser parser = new FhirContext().newJsonParser(); + IParser parser = ourCtx.newJsonParser(); Patient patient = new Patient(); patient.addAddress().setUse(AddressUse.HOME); @@ -764,15 +764,15 @@ public class JsonParserHl7OrgTest { HumanName given = name.addGiven("Joe"); Extension ext2 = new Extension().setUrl("http://examples.com#givenext").setValue( new StringType("Hello")); given.getExtension().add(ext2); - String enc = new FhirContext().newJsonParser().encodeResourceToString(patient); + String enc = ourCtx.newJsonParser().encodeResourceToString(patient); ourLog.info(enc); assertEquals("{\"resourceType\":\"Patient\",\"name\":[{\"extension\":[{\"url\":\"http://examples.com#givenext\",\"valueString\":\"Hello\"}],\"family\":[\"Shmoe\"],\"given\":[\"Joe\"]}]}", enc); - IParser newJsonParser = new FhirContext().newJsonParser(); + IParser newJsonParser = ourCtx.newJsonParser(); StringReader reader = new StringReader(enc); Patient parsed = newJsonParser.parseResource(Patient.class, reader); - ourLog.info(new FhirContext().newXmlParser().setPrettyPrint(true).encodeResourceToString(parsed)); + ourLog.info(ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(parsed)); assertEquals(1, parsed.getName().get(0).getExtension().size()); Extension ext = parsed.getName().get(0).getExtension().get(0); @@ -790,7 +790,7 @@ public class JsonParserHl7OrgTest { family.setValue("Shmoe"); family.addExtension().setUrl("http://examples.com#givenext").setValue( new StringType("Hello")); - String enc = new FhirContext().newJsonParser().encodeResourceToString(patient); + String enc = ourCtx.newJsonParser().encodeResourceToString(patient); ourLog.info(enc); //@formatter:off assertThat(enc, containsString(("{\n" + @@ -815,7 +815,7 @@ public class JsonParserHl7OrgTest { "}").replace("\n", "").replaceAll(" +", ""))); //@formatter:on - Patient parsed = new FhirContext().newJsonParser().parseResource(Patient.class, new StringReader(enc)); + Patient parsed = ourCtx.newJsonParser().parseResource(Patient.class, new StringReader(enc)); assertEquals(1, parsed.getName().get(0).getFamily().get(0).getExtension().size()); Extension ext = parsed.getName().get(0).getFamily().get(0).getExtension().get(0); assertEquals("Hello", ((IPrimitiveType)ext.getValue()).getValue()); @@ -962,7 +962,7 @@ public class JsonParserHl7OrgTest { // nothing }}; - FhirContext context = new FhirContext(); + FhirContext context = ourCtx; context.setNarrativeGenerator(gen); IParser p = context.newJsonParser(); p.encodeResourceToWriter(patient, new OutputStreamWriter(System.out)); @@ -1189,7 +1189,7 @@ public class JsonParserHl7OrgTest { "}"; //@formatter:on - TagList tagList = new FhirContext().newJsonParser().parseTagList(tagListStr); + TagList tagList = ourCtx.newJsonParser().parseTagList(tagListStr); assertEquals(3, tagList.size()); assertEquals("term0", tagList.get(0).getTerm()); assertEquals("label0", tagList.get(0).getLabel()); @@ -1226,7 +1226,7 @@ public class JsonParserHl7OrgTest { "}"; //@formatter:on - String encoded = new FhirContext().newJsonParser().encodeTagListToString(tagList); + String encoded = ourCtx.newJsonParser().encodeTagListToString(tagList); assertEquals(expected, encoded); } diff --git a/hapi-fhir-structures-hl7org-dstu2/src/test/java/ca/uhn/fhir/parser/MyOrganization.java b/hapi-fhir-structures-hl7org-dstu2/src/test/java/ca/uhn/fhir/parser/MyOrganizationDstu2.java similarity index 78% rename from hapi-fhir-structures-hl7org-dstu2/src/test/java/ca/uhn/fhir/parser/MyOrganization.java rename to hapi-fhir-structures-hl7org-dstu2/src/test/java/ca/uhn/fhir/parser/MyOrganizationDstu2.java index 32944fab387..29bfafe1349 100644 --- a/hapi-fhir-structures-hl7org-dstu2/src/test/java/ca/uhn/fhir/parser/MyOrganization.java +++ b/hapi-fhir-structures-hl7org-dstu2/src/test/java/ca/uhn/fhir/parser/MyOrganizationDstu2.java @@ -4,7 +4,7 @@ import org.hl7.fhir.instance.model.Organization; import org.hl7.fhir.instance.model.annotations.ResourceDef; @ResourceDef() -public class MyOrganization extends Organization { +public class MyOrganizationDstu2 extends Organization { private static final long serialVersionUID = 1L; diff --git a/hapi-fhir-structures-hl7org-dstu2/src/test/java/ca/uhn/fhir/parser/MyPatient.java b/hapi-fhir-structures-hl7org-dstu2/src/test/java/ca/uhn/fhir/parser/MyPatientHl7Org.java similarity index 96% rename from hapi-fhir-structures-hl7org-dstu2/src/test/java/ca/uhn/fhir/parser/MyPatient.java rename to hapi-fhir-structures-hl7org-dstu2/src/test/java/ca/uhn/fhir/parser/MyPatientHl7Org.java index 7a96d2cb3ca..4e5aa27dc5d 100644 --- a/hapi-fhir-structures-hl7org-dstu2/src/test/java/ca/uhn/fhir/parser/MyPatient.java +++ b/hapi-fhir-structures-hl7org-dstu2/src/test/java/ca/uhn/fhir/parser/MyPatientHl7Org.java @@ -14,7 +14,7 @@ import org.hl7.fhir.instance.model.annotations.ResourceDef; @ResourceDef() -public class MyPatient extends Patient { +public class MyPatientHl7Org extends Patient { private static final long serialVersionUID = 1L; @@ -29,7 +29,7 @@ public class MyPatient extends Patient { private List myImportantDates; @Child(name="managingOrganization", order=Child.REPLACE_PARENT, min=0, max=1, type={ - MyOrganization.class }) + MyOrganizationDstu2.class }) @Description( shortDefinition="Organization that is the custodian of the patient record", formalDefinition="Organization that is the custodian of the patient record" diff --git a/hapi-fhir-structures-hl7org-dstu2/src/test/java/ca/uhn/fhir/parser/XmlParserHl7OrgDstu2Test.java b/hapi-fhir-structures-hl7org-dstu2/src/test/java/ca/uhn/fhir/parser/XmlParserHl7OrgDstu2Test.java index 7e76d5cd4d7..209bf39e1e6 100644 --- a/hapi-fhir-structures-hl7org-dstu2/src/test/java/ca/uhn/fhir/parser/XmlParserHl7OrgDstu2Test.java +++ b/hapi-fhir-structures-hl7org-dstu2/src/test/java/ca/uhn/fhir/parser/XmlParserHl7OrgDstu2Test.java @@ -1051,7 +1051,7 @@ public class XmlParserHl7OrgDstu2Test { @Test public void testExtensions() throws DataFormatException { - MyPatient patient = new MyPatient(); + MyPatientHl7Org patient = new MyPatientHl7Org(); patient.setPetName(new StringType("Fido")); patient.getImportantDates().add(new DateTimeType("2010-01-02")); patient.getImportantDates().add(new DateTimeType("2014-01-26T11:11:11")); @@ -1358,7 +1358,7 @@ public class XmlParserHl7OrgDstu2Test { } }; - FhirContext context = new FhirContext(); + FhirContext context = ourCtx; context.setNarrativeGenerator(gen); IParser p = context.newXmlParser(); String str = p.encodeResourceToString(patient); @@ -1540,7 +1540,7 @@ public class XmlParserHl7OrgDstu2Test { XMLUnit.setIgnoreAttributeOrder(true); XMLUnit.setIgnoreComments(true); XMLUnit.setIgnoreWhitespace(true); - ourCtx = new FhirContext(); + ourCtx = FhirContext.forDstu2Hl7Org(); } } diff --git a/hapi-fhir-structures-hl7org-dstu2/src/test/java/ca/uhn/fhir/rest/client/ClientServerValidationTestDstu2.java b/hapi-fhir-structures-hl7org-dstu2/src/test/java/ca/uhn/fhir/rest/client/ClientServerValidationTestHl7OrgDstu2.java similarity index 98% rename from hapi-fhir-structures-hl7org-dstu2/src/test/java/ca/uhn/fhir/rest/client/ClientServerValidationTestDstu2.java rename to hapi-fhir-structures-hl7org-dstu2/src/test/java/ca/uhn/fhir/rest/client/ClientServerValidationTestHl7OrgDstu2.java index ae2f82f522f..7887570cf8e 100644 --- a/hapi-fhir-structures-hl7org-dstu2/src/test/java/ca/uhn/fhir/rest/client/ClientServerValidationTestDstu2.java +++ b/hapi-fhir-structures-hl7org-dstu2/src/test/java/ca/uhn/fhir/rest/client/ClientServerValidationTestHl7OrgDstu2.java @@ -37,9 +37,9 @@ import ca.uhn.fhir.rest.client.exceptions.FhirClientConnectionException; import ca.uhn.fhir.rest.client.exceptions.FhirClientInappropriateForServerException; import ca.uhn.fhir.rest.server.Constants; -public class ClientServerValidationTestDstu2 { +public class ClientServerValidationTestHl7OrgDstu2 { - private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ClientServerValidationTestDstu2.class); + private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ClientServerValidationTestHl7OrgDstu2.class); private FhirContext myCtx; private HttpClient myHttpClient; private HttpResponse myHttpResponse; diff --git a/hapi-fhir-structures-hl7org-dstu2/src/test/java/ca/uhn/fhir/rest/client/ETagClientTest.java b/hapi-fhir-structures-hl7org-dstu2/src/test/java/ca/uhn/fhir/rest/client/ETagClientTest.java index b4c38053f56..8e7a82b4ef8 100644 --- a/hapi-fhir-structures-hl7org-dstu2/src/test/java/ca/uhn/fhir/rest/client/ETagClientTest.java +++ b/hapi-fhir-structures-hl7org-dstu2/src/test/java/ca/uhn/fhir/rest/client/ETagClientTest.java @@ -274,7 +274,7 @@ public class ETagClientTest { @BeforeClass public static void beforeClass() { - ourCtx = new FhirContext(); + ourCtx = FhirContext.forDstu2Hl7Org(); } } diff --git a/hapi-fhir-testconsolidated/pom.xml b/hapi-fhir-testconsolidated/pom.xml new file mode 100644 index 00000000000..c10a73d1310 --- /dev/null +++ b/hapi-fhir-testconsolidated/pom.xml @@ -0,0 +1,366 @@ + + 4.0.0 + + + ca.uhn.hapi.fhir + hapi-fhir + 1.1-SNAPSHOT + ../pom.xml + + + hapi-fhir-testconsolidated + jar + + HAPI FHIR - Consolidated Test Project + + + + ca.uhn.hapi.fhir + hapi-fhir-base + 1.1-SNAPSHOT + + + ca.uhn.hapi.fhir + hapi-fhir-structures-dstu + 1.1-SNAPSHOT + + + ca.uhn.hapi.fhir + hapi-fhir-structures-dstu2 + 1.1-SNAPSHOT + + + ca.uhn.hapi.fhir + hapi-fhir-structures-hl7org-dstu2 + 1.1-SNAPSHOT + + + ca.uhn.hapi.fhir + hapi-fhir-jpaserver-base + 1.1-SNAPSHOT + + + + com.phloc + phloc-schematron + ${phloc_schematron_version} + + + com.phloc + phloc-commons + ${phloc_commons_version} + + + org.thymeleaf + thymeleaf + ${thymeleaf-version} + + + + org.slf4j + jcl-over-slf4j + ${slf4j_version} + + + + ch.qos.logback + logback-classic + ${logback_version} + test + + + org.hamcrest + java-hamcrest + ${hamcrest_version} + test + + + + + junit + junit + ${junit_version} + test + + + org.apache.derby + derby + ${derby_version} + test + + + commons-dbcp + commons-dbcp + 1.4 + test + + + + javax.servlet + javax.servlet-api + 3.1.0 + provided + + + + org.eclipse.jetty + jetty-servlets + ${jetty_version} + test + + + org.eclipse.jetty + jetty-servlet + ${jetty_version} + test + + + org.eclipse.jetty + jetty-server + ${jetty_version} + test + + + org.eclipse.jetty + jetty-servlet + ${jetty_version} + test + + + org.eclipse.jetty + jetty-util + ${jetty_version} + test + + + org.mockito + mockito-all + 1.9.5 + test + + + net.sf.json-lib + json-lib + 2.4 + jdk15 + test + + + commons-logging + commons-logging + + + + + net.sf.json-lib + json-lib + 2.4 + jdk15-sources + test + + + directory-naming + naming-java + 0.8 + test + + + commons-logging + commons-logging + + + + + org.hamcrest + java-hamcrest + ${hamcrest_version} + test + + + com.google.guava + guava + ${guava_version} + + + org.ebaysf.web + cors-filter + ${ebay_cors_filter_version} + test + + + xmlunit + xmlunit + ${xmlunit_version} + test + + + + + + + + + + + + org.apache.maven.plugins + maven-site-plugin + + true + + + + + + + org.eluder.coveralls + coveralls-maven-plugin + 3.1.0 + + + + + org.codehaus.mojo + build-helper-maven-plugin + ${maven_build_helper_plugin_version} + + + add-source + generate-sources + + add-source + + + + ../hapi-fhir-base/src/main/java + ../hapi-fhir-jpaserver-base/src/main/java + + + + + add-test-source + generate-test-sources + + add-test-source + + + + ../hapi-fhir-structures-dstu/src/test/java + ../hapi-fhir-structures-dstu2/src/test/java + ../hapi-fhir-structures-hl7org-dstu2/src/test/java + ../hapi-fhir-jpaserver-base/src/test/java + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + alphabetical + + + + org.apache.maven.plugins + maven-install-plugin + + true + + + + org.apache.maven.plugins + maven-deploy-plugin + + true + + + + + org.codehaus.mojo + cobertura-maven-plugin + ${maven_cobertura_plugin_version} + + false + + + ca.uhn.fhir.model.dstu.valueset.* + ca.uhn.fhir.model.valueset.* + ca.uhn.fhir.rest.client.exceptions.* + ca.uhn.fhir.rest.server.exceptions.* + + + ca/uhn/fhir/model/dstu/valueset/*.class + ca/uhn/fhir/model/valueset/*.class + ca/uhn/fhir/rest/client.exceptions/*.class + ca/uhn/fhir/rest/server.exceptions/*.class + + + + + + verify + + check + + + + + + org.codehaus.mojo + cobertura-maven-plugin + ${maven_cobertura_plugin_version} + + + + + + + + + clean + check + + + + + + + + + + ../hapi-fhir-jpaserver-base/src/test/resources + + + ../hapi-fhir-structures-dstu/src/test/resources + + + ../hapi-fhir-structures-dstu2/src/test/resources + + + ../hapi-fhir-structures-hl7org-dstu2/src/test/resources + + + + + + + org.codehaus.mojo + cobertura-maven-plugin + ${maven_cobertura_plugin_version} + + + + cobertura + + + + + + + diff --git a/pom.xml b/pom.xml index 00b5f160f5c..d1b57c14654 100644 --- a/pom.xml +++ b/pom.xml @@ -195,6 +195,7 @@ 1.8 1.9.1 2.5.3 + 2.7 2.18.1 1.6 2.10.1 @@ -216,13 +217,21 @@ 2.1.4.RELEASE 1.0.1 4.4.1 - + 1.6 UTF-8 + + org.codehaus.mojo + cobertura-maven-plugin + ${maven_cobertura_plugin_version} + + + + org.apache.maven.plugins maven-compiler-plugin @@ -917,6 +926,15 @@ hapi-fhir-dist + + COBERTURA + + true + + + hapi-fhir-testconsolidated + + diff --git a/restful-server-example-test/src/test/java/ca/uhn/example/ExampleTest.java b/restful-server-example-test/src/test/java/ca/uhn/example/ExampleTest.java index 98be299b205..86d2e7200f2 100644 --- a/restful-server-example-test/src/test/java/ca/uhn/example/ExampleTest.java +++ b/restful-server-example-test/src/test/java/ca/uhn/example/ExampleTest.java @@ -88,7 +88,7 @@ public class ExampleTest { ourServer.start(); - ourCtx = new FhirContext(); + ourCtx = FhirContext.forDstu2(); ourClient = ourCtx.newRestfulGenericClient(base); } diff --git a/restful-server-example/src/main/java/ca/uhn/example/servlet/ExampleRestfulServlet.java b/restful-server-example/src/main/java/ca/uhn/example/servlet/ExampleRestfulServlet.java index 245e70df665..02a5ff533d0 100644 --- a/restful-server-example/src/main/java/ca/uhn/example/servlet/ExampleRestfulServlet.java +++ b/restful-server-example/src/main/java/ca/uhn/example/servlet/ExampleRestfulServlet.java @@ -18,14 +18,19 @@ public class ExampleRestfulServlet extends RestfulServer { private static final long serialVersionUID = 1L; + /** + * Constructor + */ + public ExampleRestfulServlet() { + super(FhirContext.forDstu2()); // Support DSTU2 + } + /** * This method is called automatically when the * servlet is initializing. */ @Override public void initialize() { - setFhirContext(FhirContext.forDstu2());// Support DSTU2 - /* * Two resource providers are defined. Each one handles a specific * type of resource.