diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000000..5403384d97c --- /dev/null +++ b/.travis.yml @@ -0,0 +1,20 @@ +# Use docker-based build environment (instead of openvz) +sudo: false + +language: java +jdk: + - oraclejdk7 +env: + global: + - MAVEN_OPTS="-XX:MaxPermSize=512m -Xmx4g" + +cache: + directories: + - '$HOME/.m2/repository' + +install: /bin/true +script: + - mvn -B clean install && cd hapi-fhir-cobertura && mvn -B -DTRAVIS_JOB_ID=$TRAVIS_JOB_ID -P COBERTURA clean cobertura:cobertura coveralls:report +# - mvn -B clean install -Dcobertura.skip=true && mvn -B -DTRAVIS_JOB_ID=$TRAVIS_JOB_ID -P COBERTURA clean cobertura:cobertura coveralls:report + + diff --git a/README.md b/README.md index f191355e48f..722eed8ca3c 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,10 @@ hapi-fhir HAPI FHIR - Java API for HL7 FHIR Clients and Servers +[![Build Status](https://travis-ci.org/jamesagnew/hapi-fhir.svg?branch=master)](https://travis-ci.org/jamesagnew/hapi-fhir) +[![Coverage Status](https://coveralls.io/repos/jamesagnew/hapi-fhir/badge.svg?branch=master)](https://coveralls.io/r/jamesagnew/hapi-fhir?branch=master) +[![Maven Central](https://maven-badges.herokuapp.com/maven-central/ca.uhn.hapi.fhir/hapi-fhir-base/badge.svg)](http://search.maven.org/#search|ga|1|ca.uhn.hapi.fhir) + Complete project documentation is available here: http://jamesagnew.github.io/hapi-fhir/ diff --git a/examples/pom.xml b/examples/pom.xml index 4316da83aab..1a58bcc20d8 100644 --- a/examples/pom.xml +++ b/examples/pom.xml @@ -1,4 +1,5 @@ - + 4.0.0 @@ -42,6 +43,19 @@ + + + + org.apache.maven.plugins + maven-project-info-reports-plugin + ${maven_project_info_plugin_version} + + true + + + + + 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-deployable-pom/pom.xml b/hapi-deployable-pom/pom.xml index 15f21b5f436..0af7779d6c5 100644 --- a/hapi-deployable-pom/pom.xml +++ b/hapi-deployable-pom/pom.xml @@ -18,14 +18,10 @@ org.apache.maven.plugins maven-project-info-reports-plugin - 2.7 - - - - scm - - - + ${maven_project_info_plugin_version} + + true + org.apache.maven.plugins diff --git a/hapi-fhir-base/pom.xml b/hapi-fhir-base/pom.xml index e521a9c49bd..9fcea136f95 100644 --- a/hapi-fhir-base/pom.xml +++ b/hapi-fhir-base/pom.xml @@ -160,7 +160,7 @@ ${junit_version} test - + @@ -180,7 +180,7 @@ SITE - + +--> + org.apache.maven.plugins maven-jxr-plugin @@ -213,20 +212,11 @@ jxr - + + + ch.qos.logback + logback-classic + ${logback_version} + + + + 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.codehaus.mojo + cobertura-maven-plugin + ${maven_cobertura_plugin_version} + + false + + html + xml + + 256m + + + ca.uhn.fhir.model.dstu.valueset.* + + + **/valueset/*.class + **/exceptions/*.class + + + + + + + verify + + check + + + + + + + + + org.eluder.coveralls + coveralls-maven-plugin + 3.1.0 + + + + ${basedir}/target/coverage.xml + + + UTF-8 + travis-ci + ${env.TRAVIS_JOB_ID} + + ../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 + ../hapi-fhir-base/src/main/java + ../hapi-fhir-jpaserver-base/src/main/java + + + + + 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 + false + -Xms512m -Xmx1024m + + + + 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} + + + + + verify + + 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 + + + + + + org.apache.maven.plugins + maven-project-info-reports-plugin + ${maven_project_info_plugin_version} + + true + + + + org.apache.maven.plugins + maven-checkstyle-plugin + + + + checkstyle + + + + + false + + + + + diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseFhirResourceDao.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseFhirResourceDao.java index 680b31e8893..dd465e8d56e 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseFhirResourceDao.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseFhirResourceDao.java @@ -1002,7 +1002,7 @@ public abstract class BaseFhirResourceDao extends BaseFhirD return singleCode; } - private void createSort(CriteriaBuilder theBuilder, Root theFrom, SortSpec theSort, List theOrders, List thePredicates) { + private void createSort(CriteriaBuilder theBuilder, Root theFrom, SortSpec theSort, List theOrders) { if (theSort == null || isBlank(theSort.getParamName())) { return; } @@ -1017,7 +1017,7 @@ public abstract class BaseFhirResourceDao extends BaseFhirD theOrders.add(theBuilder.desc(theFrom.get("myId"))); } - createSort(theBuilder, theFrom, theSort.getChain(), theOrders, null); + createSort(theBuilder, theFrom, theSort.getChain(), theOrders); return; } @@ -1039,6 +1039,10 @@ public abstract class BaseFhirResourceDao extends BaseFhirD joinAttrName = "myParamsDate"; sortAttrName = "myValueLow"; break; + case REFERENCE: + joinAttrName = "myResourceLinks"; + sortAttrName = "myTargetResourcePid"; + break; default: throw new NotImplementedException("This server does not support _sort specifications of type " + param.getParamType() + " - Can't serve _sort=" + theSort.getParamName()); } @@ -1054,7 +1058,7 @@ public abstract class BaseFhirResourceDao extends BaseFhirD theOrders.add(theBuilder.desc(stringJoin.get(sortAttrName))); } - createSort(theBuilder, theFrom, theSort.getChain(), theOrders, null); + createSort(theBuilder, theFrom, theSort.getChain(), theOrders); } @Override @@ -1142,6 +1146,10 @@ public abstract class BaseFhirResourceDao extends BaseFhirD return outcome; } + /** + * May + * @param theResource The resource that is about to be stored + */ protected void preProcessResourceForStorage(T theResource) { // nothing by default } @@ -1655,7 +1663,7 @@ public abstract class BaseFhirResourceDao extends BaseFhirD CriteriaQuery cq = builder.createTupleQuery(); Root from = cq.from(ResourceTable.class); predicates.add(from.get("myId").in(loadPids)); - createSort(builder, from, theParams.getSort(), orders, predicates); + createSort(builder, from, theParams.getSort(), orders); if (orders.size() > 0) { Set originalPids = loadPids; loadPids = new LinkedHashSet(); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/BaseFhirDaoTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/BaseFhirDaoTest.java index 82ef8eac653..ff538892abd 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/BaseFhirDaoTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/BaseFhirDaoTest.java @@ -7,7 +7,7 @@ import org.junit.Test; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.dstu2.resource.Condition; -public class BaseFhirDaoTest { +public class BaseFhirDaoTest extends BaseJpaTest { private static FhirContext ourCtx = FhirContext.forDstu2(); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/BaseJpaTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/BaseJpaTest.java new file mode 100644 index 00000000000..73131570890 --- /dev/null +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/BaseJpaTest.java @@ -0,0 +1,20 @@ +package ca.uhn.fhir.jpa.dao; + +import java.sql.DriverManager; +import java.sql.SQLException; +import java.sql.SQLNonTransientConnectionException; + +import org.junit.AfterClass; + +public class BaseJpaTest { + + @AfterClass + public static void afterClassShutdownDerby() throws SQLException { +// try { +// DriverManager.getConnection("jdbc:derby:memory:myUnitTestDB;drop=true"); +// } catch (SQLNonTransientConnectionException e) { +// // expected.. for some reason.... +// } + } + +} diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoDstu1Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoDstu1Test.java index 82963836453..bb6571cecd4 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoDstu1Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoDstu1Test.java @@ -25,7 +25,7 @@ import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException; import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; -public class FhirResourceDaoDstu1Test { +public class FhirResourceDaoDstu1Test extends BaseJpaTest { private static ClassPathXmlApplicationContext ourCtx; private static IFhirResourceDao ourDeviceDao; diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoDstu2Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoDstu2Test.java index 1749b67e9da..d01b8c89f4e 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoDstu2Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/FhirResourceDaoDstu2Test.java @@ -93,7 +93,7 @@ import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException; import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; @SuppressWarnings("unchecked") -public class FhirResourceDaoDstu2Test { +public class FhirResourceDaoDstu2Test extends BaseJpaTest { private static ClassPathXmlApplicationContext ourCtx; private static IFhirResourceDao ourDeviceDao; @@ -2210,6 +2210,67 @@ public class FhirResourceDaoDstu2Test { assertThat(actual, contains(id3, id2, id1, id4)); } + @Test + public void testSortByReference() { + String methodName = "testSortByReference"; + + Organization o1 = new Organization(); + IdDt oid1 = ourOrganizationDao.create(o1).getId().toUnqualifiedVersionless(); + + Organization o2 = new Organization(); + IdDt oid2 = ourOrganizationDao.create(o2).getId().toUnqualifiedVersionless(); + + Patient p = new Patient(); + p.addIdentifier().setSystem("urn:system").setValue(methodName); + p.addName().addFamily("testSortF1").addGiven("testSortG1"); + p.getManagingOrganization().setReference(oid1); + IdDt id1 = ourPatientDao.create(p).getId().toUnqualifiedVersionless(); + + p = new Patient(); + p.addIdentifier().setSystem("urn:system").setValue(methodName); + p.addName().addFamily("testSortF2").addGiven("testSortG2"); + p.getManagingOrganization().setReference(oid2); + IdDt id2 = ourPatientDao.create(p).getId().toUnqualifiedVersionless(); + + p = new Patient(); + p.addIdentifier().setSystem("urn:system").setValue(methodName); + p.addName().addFamily("testSortF3").addGiven("testSortG3"); + p.getManagingOrganization().setReference(oid1); + IdDt id3 = ourPatientDao.create(p).getId().toUnqualifiedVersionless(); + + p = new Patient(); + p.addIdentifier().setSystem("urn:system").setValue(methodName); + p.getManagingOrganization().setReference(oid2); + IdDt id4 = ourPatientDao.create(p).getId().toUnqualifiedVersionless(); + + SearchParameterMap pm; + List actual; + + pm = new SearchParameterMap(); + pm.add(Patient.SP_IDENTIFIER, new TokenParam("urn:system", methodName)); + pm.setSort(new SortSpec(Patient.SP_ORGANIZATION)); + actual = toUnqualifiedVersionlessIds(ourPatientDao.search(pm)); + assertEquals(4, actual.size()); + assertThat(actual.subList(0, 2), containsInAnyOrder(id1, id3)); + assertThat(actual.subList(2, 4), containsInAnyOrder(id2, id4)); + + pm = new SearchParameterMap(); + pm.add(Patient.SP_IDENTIFIER, new TokenParam("urn:system", methodName)); + pm.setSort(new SortSpec(Patient.SP_ORGANIZATION).setOrder(SortOrderEnum.ASC)); + actual = toUnqualifiedVersionlessIds(ourPatientDao.search(pm)); + assertEquals(4, actual.size()); + assertThat(actual.subList(0, 2), containsInAnyOrder(id1, id3)); + assertThat(actual.subList(2, 4), containsInAnyOrder(id2, id4)); + + pm = new SearchParameterMap(); + pm.add(Patient.SP_IDENTIFIER, new TokenParam("urn:system", methodName)); + pm.setSort(new SortSpec(Patient.SP_ORGANIZATION).setOrder(SortOrderEnum.DESC)); + actual = toUnqualifiedVersionlessIds(ourPatientDao.search(pm)); + assertEquals(4, actual.size()); + assertThat(actual.subList(0, 2), containsInAnyOrder(id2, id4)); + assertThat(actual.subList(2, 4), containsInAnyOrder(id1, id3)); + } + @Test public void testStoreUnversionedResources() { Organization o1 = new Organization(); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/FhirSystemDaoDstu1Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/FhirSystemDaoDstu1Test.java index cf4971e8a3d..37cfda114ef 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/FhirSystemDaoDstu1Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/FhirSystemDaoDstu1Test.java @@ -45,7 +45,7 @@ import ca.uhn.fhir.rest.param.TokenParam; import ca.uhn.fhir.rest.server.IBundleProvider; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; -public class FhirSystemDaoDstu1Test { +public class FhirSystemDaoDstu1Test extends BaseJpaTest { private static ClassPathXmlApplicationContext ourCtx; private static FhirContext ourFhirContext; diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/FhirSystemDaoDstu2Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/FhirSystemDaoDstu2Test.java index 6afacf45aa1..517992b5afc 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/FhirSystemDaoDstu2Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/FhirSystemDaoDstu2Test.java @@ -8,6 +8,8 @@ import static org.hamcrest.Matchers.startsWith; import static org.junit.Assert.*; import java.io.InputStream; +import java.sql.DriverManager; +import java.sql.SQLException; import java.util.ArrayList; import java.util.List; @@ -45,7 +47,7 @@ import ca.uhn.fhir.rest.server.exceptions.PreconditionFailedException; import ca.uhn.fhir.rest.server.exceptions.ResourceGoneException; import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException; -public class FhirSystemDaoDstu2Test { +public class FhirSystemDaoDstu2Test extends BaseJpaTest { private static ClassPathXmlApplicationContext ourCtx; private static FhirContext ourFhirContext; @@ -953,7 +955,7 @@ public class FhirSystemDaoDstu2Test { } @AfterClass - public static void afterClass() { + public static void afterClass() throws SQLException { ourCtx.close(); } 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..05546effce1 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 @@ -17,6 +17,7 @@ import org.junit.Test; import org.springframework.context.support.ClassPathXmlApplicationContext; import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.jpa.dao.BaseJpaTest; import ca.uhn.fhir.jpa.dao.DaoConfig; import ca.uhn.fhir.jpa.dao.IFhirResourceDao; import ca.uhn.fhir.jpa.testutil.RandomServerPortProvider; @@ -49,12 +50,12 @@ import ca.uhn.fhir.rest.server.RestfulServer; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; -public class ResourceProviderDstu1Test { +public class ResourceProviderDstu1Test extends BaseJpaTest { 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 +406,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 +493,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 +525,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 0786d4d5f9f..d3739fb7aa0 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 @@ -44,6 +44,7 @@ import org.junit.Test; import org.springframework.context.support.ClassPathXmlApplicationContext; import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.jpa.dao.BaseJpaTest; import ca.uhn.fhir.jpa.dao.DaoConfig; import ca.uhn.fhir.jpa.dao.IFhirResourceDao; import ca.uhn.fhir.jpa.testutil.RandomServerPortProvider; @@ -93,12 +94,12 @@ import ca.uhn.fhir.rest.server.RestfulServer; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; -public class ResourceProviderDstu2Test { +public class ResourceProviderDstu2Test extends BaseJpaTest { 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; @@ -145,7 +146,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 @@ -191,7 +192,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); @@ -281,7 +282,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"))); @@ -325,7 +326,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"))); @@ -406,8 +407,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; @@ -446,7 +447,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(); @@ -515,7 +516,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()); @@ -896,14 +897,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("")); } @@ -960,7 +961,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"))); @@ -1018,7 +1019,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"); @@ -1046,7 +1047,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"); @@ -1083,9 +1084,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"; @@ -1117,9 +1117,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..7a5673a01cd 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 @@ -13,6 +13,7 @@ import org.junit.Test; import org.springframework.context.support.ClassPathXmlApplicationContext; import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.jpa.dao.BaseJpaTest; import ca.uhn.fhir.jpa.testutil.RandomServerPortProvider; import ca.uhn.fhir.model.api.Bundle; import ca.uhn.fhir.model.dstu.resource.Patient; @@ -26,7 +27,7 @@ import ca.uhn.fhir.rest.client.interceptor.LoggingInterceptor; import ca.uhn.fhir.rest.server.IResourceProvider; import ca.uhn.fhir.rest.server.RestfulServer; -public class ResourceProviderMultiVersionTest { +public class ResourceProviderMultiVersionTest extends BaseJpaTest { private static ClassPathXmlApplicationContext ourAppCtx; private static IGenericClient ourClientDstu2; @@ -139,8 +140,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 +155,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..380079407bd 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 @@ -19,6 +19,7 @@ import org.junit.Test; import org.springframework.context.support.ClassPathXmlApplicationContext; import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.jpa.dao.BaseJpaTest; import ca.uhn.fhir.jpa.dao.IFhirResourceDao; import ca.uhn.fhir.jpa.rp.dstu.ObservationResourceProvider; import ca.uhn.fhir.jpa.rp.dstu.OrganizationResourceProvider; @@ -34,7 +35,7 @@ import ca.uhn.fhir.model.primitive.IdDt; import ca.uhn.fhir.rest.client.IGenericClient; import ca.uhn.fhir.rest.server.RestfulServer; -public class SystemProviderDstu1Test { +public class SystemProviderDstu1Test extends BaseJpaTest { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(SystemProviderDstu1Test.class); private static Server ourServer; @@ -89,7 +90,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..8c68a7e3ade 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 @@ -15,6 +15,7 @@ import org.junit.Test; import org.springframework.context.support.ClassPathXmlApplicationContext; import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.jpa.dao.BaseJpaTest; import ca.uhn.fhir.jpa.dao.IFhirResourceDao; import ca.uhn.fhir.jpa.rp.dstu.ObservationResourceProvider; import ca.uhn.fhir.jpa.rp.dstu.OrganizationResourceProvider; @@ -29,7 +30,7 @@ import ca.uhn.fhir.model.primitive.IdDt; import ca.uhn.fhir.rest.client.IGenericClient; import ca.uhn.fhir.rest.server.RestfulServer; -public class SystemProviderDstu2Test { +public class SystemProviderDstu2Test extends BaseJpaTest { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(SystemProviderDstu2Test.class); private static Server ourServer; @@ -122,7 +123,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/CustomThymeleafNarrativeGeneratorTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/narrative/CustomThymeleafNarrativeGeneratorTest.java index f7868e25add..c5377ed371d 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/narrative/CustomThymeleafNarrativeGeneratorTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/narrative/CustomThymeleafNarrativeGeneratorTest.java @@ -18,7 +18,7 @@ public class CustomThymeleafNarrativeGeneratorTest { @Test public void testGenerator() { - CustomThymeleafNarrativeGenerator gen = new CustomThymeleafNarrativeGenerator("file:src/test/resources/narrative/customnarrative.properties"); + CustomThymeleafNarrativeGenerator gen = new CustomThymeleafNarrativeGenerator("classpath:narrative/customnarrative.properties"); gen.setFhirContext(ourCtx); Practitioner p = new Practitioner(); 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..0bdb34a48c6 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 @@ -2,9 +2,7 @@ package ca.uhn.fhir.rest.client; import static org.junit.Assert.assertFalse; import static org.mockito.Matchers.argThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; +import static org.mockito.Mockito.*; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.servlet.ServletHandler; @@ -39,8 +37,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; @@ -63,15 +60,18 @@ public class LoggingInterceptorTest { @Test public void testLogger() throws Exception { + System.out.println("Starting testLogger"); IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort); client.registerInterceptor(new LoggingInterceptor(true)); Patient patient = client.read(Patient.class, "1"); assertFalse(patient.getIdentifierFirstRep().isEmpty()); - verify(myMockAppender).doAppend(argThat(new ArgumentMatcher() { + verify(myMockAppender, atLeastOnce()).doAppend(argThat(new ArgumentMatcher() { @Override public boolean matches(final Object argument) { - return ((LoggingEvent) argument).getFormattedMessage().contains("Content-Type: application/xml+fhir; charset=UTF-8"); + String formattedMessage = ((LoggingEvent) argument).getFormattedMessage(); + System.out.println("Verifying: " + formattedMessage); + return formattedMessage.contains("Content-Type: application/xml+fhir; charset=UTF-8"); } })); } @@ -89,15 +89,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..9cee97ecc49 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 @@ -58,6 +58,7 @@ import org.hl7.fhir.instance.model.annotations.ResourceDef; import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IPrimitiveType; import org.hl7.fhir.utilities.xhtml.XhtmlNode; +import org.junit.After; import org.junit.BeforeClass; import org.junit.Test; import org.xml.sax.SAXException; @@ -68,9 +69,13 @@ import ca.uhn.fhir.model.base.composite.BaseNarrativeDt; import ca.uhn.fhir.narrative.INarrativeGenerator; public class JsonParserHl7OrgTest { - private static FhirContext ourCtx; + private static final FhirContext ourCtx = FhirContext.forDstu2Hl7Org(); private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(JsonParserHl7OrgTest.class); + @After + public void after() { + ourCtx.setNarrativeGenerator(null); + } @Test @@ -410,7 +415,7 @@ public class JsonParserHl7OrgTest { rpt.getText().setDivAsString("AAA"); rpt.addSpecimen().setResource(spm); - IParser p = new FhirContext(DiagnosticReport.class).newJsonParser().setPrettyPrint(true); + IParser p = ourCtx.newJsonParser().setPrettyPrint(true); String str = p.encodeResourceToString(rpt); ourLog.info(str); @@ -451,7 +456,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 +475,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 +591,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); @@ -632,7 +637,7 @@ public class JsonParserHl7OrgTest { Observation obs = new Observation(); obs.setValue(new DecimalType(112.22)); - IParser p = new FhirContext(Observation.class).newJsonParser(); + IParser p = ourCtx.newJsonParser(); try { p.encodeResourceToString(obs); @@ -698,7 +703,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 +721,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 +769,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 +795,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 +820,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 +967,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)); @@ -1073,7 +1078,7 @@ public class JsonParserHl7OrgTest { */ @Test public void testParseWithIncorrectReference() throws IOException { - String jsonString = IOUtils.toString(JsonParser.class.getResourceAsStream("/example-patient-general.json")); + String jsonString = IOUtils.toString(JsonParser.class.getResourceAsStream("/example-patient-general-hl7orgdstu2.json")); jsonString = jsonString.replace("\"reference\"", "\"resource\""); Patient parsed = ourCtx.newJsonParser().parseResource(Patient.class, jsonString); assertEquals("Organization/1", parsed.getManagingOrganization().getReference()); @@ -1082,7 +1087,7 @@ public class JsonParserHl7OrgTest { @Test public void testSimpleParse() throws DataFormatException, IOException { - String msg = IOUtils.toString(XmlParser.class.getResourceAsStream("/example-patient-general.json")); + String msg = IOUtils.toString(XmlParser.class.getResourceAsStream("/example-patient-general-hl7orgdstu2.json")); IParser p = ourCtx.newJsonParser(); // ourLog.info("Reading in message: {}", msg); Patient res = p.parseResource(Patient.class, msg); @@ -1099,7 +1104,7 @@ public class JsonParserHl7OrgTest { @Test public void testSimpleResourceEncode() throws IOException { - String xmlString = IOUtils.toString(JsonParser.class.getResourceAsStream("/example-patient-general.xml"), Charset.forName("UTF-8")); + String xmlString = IOUtils.toString(JsonParser.class.getResourceAsStream("/example-patient-general-hl7orgdstu2.xml"), Charset.forName("UTF-8")); Patient obs = ourCtx.newXmlParser().parseResource(Patient.class, xmlString); List undeclaredExtensions = obs.getContact().get(0).getName().getFamily().get(0).getExtension(); @@ -1112,7 +1117,7 @@ public class JsonParserHl7OrgTest { String encoded = jsonParser.encodeResourceToString(obs); ourLog.info(encoded); - String jsonString = IOUtils.toString(JsonParser.class.getResourceAsStream("/example-patient-general.json"), Charset.forName("UTF-8")); + String jsonString = IOUtils.toString(JsonParser.class.getResourceAsStream("/example-patient-general-hl7orgdstu2.json"), Charset.forName("UTF-8")); JSON expected = JSONSerializer.toJSON(jsonString); JSON actual = JSONSerializer.toJSON(encoded.trim()); @@ -1133,9 +1138,8 @@ public class JsonParserHl7OrgTest { @Test public void testSimpleResourceEncodeWithCustomType() throws IOException, SAXException { - FhirContext fhirCtx = new FhirContext(MyObservationWithExtensions.class); - String jsonString = IOUtils.toString(JsonParser.class.getResourceAsStream("/example-patient-general.json"), Charset.forName("UTF-8")); - MyObservationWithExtensions obs = fhirCtx.newJsonParser().parseResource(MyObservationWithExtensions.class, jsonString); + String jsonString = IOUtils.toString(JsonParser.class.getResourceAsStream("/example-patient-general-hl7orgdstu2.json"), Charset.forName("UTF-8")); + MyObservationWithExtensions obs = ourCtx.newJsonParser().parseResource(MyObservationWithExtensions.class, jsonString); assertEquals(0, obs.getExtension().size()); assertEquals("aaaa", obs.getExtAtt().getContentType()); @@ -1146,11 +1150,11 @@ public class JsonParserHl7OrgTest { org.hl7.fhir.instance.model.Extension undeclaredExtension = undeclaredExtensions.get(0); assertEquals("http://hl7.org/fhir/Profile/iso-21090#qualifier", undeclaredExtension.getUrl()); - IParser xmlParser = fhirCtx.newXmlParser(); + IParser xmlParser = ourCtx.newXmlParser(); String encoded = xmlParser.encodeResourceToString(obs); encoded = encoded.replaceAll("", "").replace("\n", "").replace("\r", "").replaceAll(">\\s+<", "><"); - String xmlString = IOUtils.toString(JsonParser.class.getResourceAsStream("/example-patient-general.xml"), Charset.forName("UTF-8")); + String xmlString = IOUtils.toString(JsonParser.class.getResourceAsStream("/example-patient-general-hl7orgdstu2.xml"), Charset.forName("UTF-8")); xmlString = xmlString.replaceAll("", "").replace("\n", "").replace("\r", "").replaceAll(">\\s+<", "><"); ourLog.info("Expected: " + xmlString); @@ -1189,7 +1193,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,16 +1230,11 @@ public class JsonParserHl7OrgTest { "}"; //@formatter:on - String encoded = new FhirContext().newJsonParser().encodeTagListToString(tagList); + String encoded = ourCtx.newJsonParser().encodeTagListToString(tagList); assertEquals(expected, encoded); } - @BeforeClass - public static void beforeClass() { - ourCtx = FhirContext.forDstu2Hl7Org(); - } - @ResourceDef(name = "Patient") public static class MyPatientWithOneDeclaredAddressExtension extends Patient { 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..8e94cfa56bc 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")); @@ -1107,7 +1107,7 @@ public class XmlParserHl7OrgDstu2Test { @Test public void testLoadAndEncodeDeclaredExtensions() throws ConfigurationException, DataFormatException, SAXException, IOException { - IParser p = new FhirContext(ResourceWithExtensionsA.class).newXmlParser(); + IParser p = ourCtx.newXmlParser(); //@formatter:off String msg = "\n" + @@ -1142,7 +1142,7 @@ public class XmlParserHl7OrgDstu2Test { ""; //@formatter:on - ResourceWithExtensionsA resource = (ResourceWithExtensionsA) p.parseResource(msg); + ResourceWithExtensionsA resource = (ResourceWithExtensionsA) p.parseResource(ResourceWithExtensionsA.class, msg); assertEquals("IdentifierLabel", resource.getIdentifier().get(0).getValue()); assertEquals("Foo1Value", resource.getFoo1().get(0).getValue()); assertEquals("Foo1Value2", resource.getFoo1().get(1).getValue()); @@ -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); @@ -1477,7 +1477,7 @@ public class XmlParserHl7OrgDstu2Test { @Test public void testSimpleResourceEncode() throws IOException, SAXException { - String xmlString = IOUtils.toString(XmlParserHl7OrgDstu2Test.class.getResourceAsStream("/example-patient-general.json"), Charset.forName("UTF-8")); + String xmlString = IOUtils.toString(XmlParserHl7OrgDstu2Test.class.getResourceAsStream("/example-patient-general-hl7orgdstu2.json"), Charset.forName("UTF-8")); Patient obs = ourCtx.newJsonParser().parseResource(Patient.class, xmlString); List undeclaredExtensions = obs.getContact().get(0).getName().getFamily().get(0).getExtension(); @@ -1490,7 +1490,7 @@ public class XmlParserHl7OrgDstu2Test { String encoded = jsonParser.encodeResourceToString(obs); ourLog.info(encoded); - String jsonString = IOUtils.toString(XmlParserHl7OrgDstu2Test.class.getResourceAsStream("/example-patient-general.xml"), Charset.forName("UTF-8")); + String jsonString = IOUtils.toString(XmlParserHl7OrgDstu2Test.class.getResourceAsStream("/example-patient-general-hl7orgdstu2.xml"), Charset.forName("UTF-8")); String expected = (jsonString); String actual = (encoded.trim()); @@ -1503,9 +1503,8 @@ public class XmlParserHl7OrgDstu2Test { @Test public void testSimpleResourceEncodeWithCustomType() throws IOException { - FhirContext fhirCtx = new FhirContext(MyObservationWithExtensions.class); - String xmlString = IOUtils.toString(XmlParserHl7OrgDstu2Test.class.getResourceAsStream("/example-patient-general.xml"), Charset.forName("UTF-8")); - MyObservationWithExtensions obs = fhirCtx.newXmlParser().parseResource(MyObservationWithExtensions.class, xmlString); + String xmlString = IOUtils.toString(XmlParserHl7OrgDstu2Test.class.getResourceAsStream("/example-patient-general-hl7orgdstu2.xml"), Charset.forName("UTF-8")); + MyObservationWithExtensions obs = ourCtx.newXmlParser().parseResource(MyObservationWithExtensions.class, xmlString); assertEquals(0, obs.getExtension().size()); assertEquals("aaaa", obs.getExtAtt().getContentType()); @@ -1516,11 +1515,11 @@ public class XmlParserHl7OrgDstu2Test { Extension undeclaredExtension = undeclaredExtensions.get(0); assertEquals("http://hl7.org/fhir/Profile/iso-21090#qualifier", undeclaredExtension.getUrl()); - IParser jsonParser = fhirCtx.newJsonParser().setPrettyPrint(true); + IParser jsonParser = ourCtx.newJsonParser().setPrettyPrint(true); String encoded = jsonParser.encodeResourceToString(obs); ourLog.info(encoded); - String jsonString = IOUtils.toString(XmlParserHl7OrgDstu2Test.class.getResourceAsStream("/example-patient-general.json"), Charset.forName("UTF-8")); + String jsonString = IOUtils.toString(XmlParserHl7OrgDstu2Test.class.getResourceAsStream("/example-patient-general-hl7orgdstu2.json"), Charset.forName("UTF-8")); JSON expected = JSONSerializer.toJSON(jsonString); JSON actual = JSONSerializer.toJSON(encoded.trim()); @@ -1540,7 +1539,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-structures-hl7org-dstu2/src/test/resources/example-patient-general.json b/hapi-fhir-structures-hl7org-dstu2/src/test/resources/example-patient-general-hl7orgdstu2.json similarity index 100% rename from hapi-fhir-structures-hl7org-dstu2/src/test/resources/example-patient-general.json rename to hapi-fhir-structures-hl7org-dstu2/src/test/resources/example-patient-general-hl7orgdstu2.json diff --git a/hapi-fhir-structures-hl7org-dstu2/src/test/resources/example-patient-general.xml b/hapi-fhir-structures-hl7org-dstu2/src/test/resources/example-patient-general-hl7orgdstu2.xml similarity index 100% rename from hapi-fhir-structures-hl7org-dstu2/src/test/resources/example-patient-general.xml rename to hapi-fhir-structures-hl7org-dstu2/src/test/resources/example-patient-general-hl7orgdstu2.xml diff --git a/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/tinder/TinderClientMojo.java b/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/tinder/TinderClientMojo.java index ba6e1815570..b5cde76bd0c 100644 --- a/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/tinder/TinderClientMojo.java +++ b/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/tinder/TinderClientMojo.java @@ -156,7 +156,7 @@ public class TinderClientMojo extends AbstractMojo { File file = new File(myDirectoryBase, myClientClassSimpleName + ".java"); FileWriter w = new FileWriter(file, false); - ourLog.info("Writing file: {}", file.getAbsolutePath()); + ourLog.debug("Writing file: {}", file.getAbsolutePath()); VelocityContext ctx = new VelocityContext(); ctx.put("packageBase", myPackageBase); diff --git a/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/tinder/TinderStructuresMojo.java b/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/tinder/TinderStructuresMojo.java index ae64c8ee9c3..ea250a10797 100644 --- a/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/tinder/TinderStructuresMojo.java +++ b/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/tinder/TinderStructuresMojo.java @@ -121,8 +121,9 @@ public class TinderStructuresMojo extends AbstractMojo { rp.getLocalImports().putAll(datatypeLocalImports); datatypeLocalImports.putAll(rp.getLocalImports()); - ourLog.info("Writing Resources..."); File resSubDirectoryBase = new File(directoryBase, "resource"); + ourLog.info("Writing Resources to directory: {}", resSubDirectoryBase.getAbsolutePath()); + rp.combineContentMaps(dtp); rp.writeAll(resSubDirectoryBase, resDirectoryBase, packageName); } diff --git a/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/tinder/ValueSetGenerator.java b/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/tinder/ValueSetGenerator.java index b99e01fc6c9..836f94e76f0 100644 --- a/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/tinder/ValueSetGenerator.java +++ b/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/tinder/ValueSetGenerator.java @@ -274,7 +274,7 @@ public class ValueSetGenerator { File f = new File(theOutputDirectory, theValueSetTm.getClassName() + ".java"); FileWriter w = new FileWriter(f, false); - ourLog.info("Writing file: {}", f.getAbsolutePath()); + ourLog.debug("Writing file: {}", f.getAbsolutePath()); VelocityContext ctx = new VelocityContext(); ctx.put("valueSet", theValueSetTm); diff --git a/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/tinder/parser/BaseStructureParser.java b/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/tinder/parser/BaseStructureParser.java index 501e10f3db1..1b4913398d3 100644 --- a/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/tinder/parser/BaseStructureParser.java +++ b/hapi-tinder-plugin/src/main/java/ca/uhn/fhir/tinder/parser/BaseStructureParser.java @@ -83,13 +83,13 @@ public abstract class BaseStructureParser { if (isNotBlank(theResource.getBinding())) { String bindingClass = theVsp.getClassForValueSetIdAndMarkAsNeeded(theResource.getBinding()); if (bindingClass != null) { - ourLog.info("Adding binding ValueSet class: {}", bindingClass); + ourLog.debug("Adding binding ValueSet class: {}", bindingClass); theResource.setBindingClass(bindingClass); addImport(bindingClass); myLocallyDefinedClassNames.put(bindingClass, "valueset"); } else { - ourLog.info("No binding found for: {}", theResource.getBinding()); - ourLog.info(" * Valid: {}", new TreeSet(theVsp.getValueSets().keySet())); + ourLog.debug("No binding found for: {}", theResource.getBinding()); + ourLog.debug(" * Valid: {}", new TreeSet(theVsp.getValueSets().keySet())); } } for (BaseElement next : theResource.getChildren()) { @@ -396,7 +396,7 @@ public abstract class BaseStructureParser { private void write(BaseRootType theResource, File theFile, String thePackageBase) throws IOException, MojoFailureException { FileWriter w = new FileWriter(theFile, false); - ourLog.info("Writing file: {}", theFile.getAbsolutePath()); + ourLog.debug("Writing file: {}", theFile.getAbsolutePath()); ArrayList imports = new ArrayList(); for (String next : myImports) { @@ -486,7 +486,7 @@ public abstract class BaseStructureParser { } for (BaseRootType next : myResources) { - ourLog.info("Writing Resource {}", next.getName()); + ourLog.debug("Writing Resource {}", next.getName()); scanForCorrections(next); scanForTypeNameConflicts(next); @@ -520,7 +520,7 @@ public abstract class BaseStructureParser { File versionFile = new File(theResourceOutputDirectory, "fhirversion.properties"); FileWriter w = new FileWriter(versionFile, false); - ourLog.info("Writing file: {}", versionFile.getAbsolutePath()); + ourLog.debug("Writing file: {}", versionFile.getAbsolutePath()); VelocityContext ctx = new VelocityContext(); ctx.put("nameToResourceClass", myNameToResourceClass); diff --git a/pom.xml b/pom.xml index 00b5f160f5c..7a02b0dbfe3 100644 --- a/pom.xml +++ b/pom.xml @@ -45,13 +45,17 @@ + + net.sourceforge.cobertura + cobertura + 2.1.1 + provided + - + 3.0.1 @@ -156,15 +160,13 @@ - + 1.0 UTF-8 - + ${user.home}/sites/hapi-fhir ${user.home}/sites/scm/hapi-fhir @@ -178,14 +180,11 @@ 10.11.1.1 18.0 2.0.0.0 - + 4.2.17.Final 5.1.0.Final 9.2.6.v20141205 @@ -195,6 +194,7 @@ 1.8 1.9.1 2.5.3 + 2.7 2.18.1 1.6 2.10.1 @@ -216,13 +216,30 @@ 2.1.4.RELEASE 1.0.1 4.4.1 - + 1.6 UTF-8 + + org.codehaus.mojo + cobertura-maven-plugin + ${maven_cobertura_plugin_version} + + true + + + + org.eluder.coveralls + coveralls-maven-plugin + 3.1.0 + + + + + org.apache.maven.plugins maven-compiler-plugin @@ -320,12 +337,11 @@ doxia-module-markdown 1.6
- + lt.velykis.maven.skins reflow-velocity-tools - 1.1.1 + 1.1.1 org.apache.velocity @@ -334,7 +350,8 @@ - + org.eclipse.m2e lifecycle-mapping @@ -425,21 +442,21 @@ - - org.apache.maven.plugins - maven-checkstyle-plugin - 2.15 - - - com.puppycrawl.tools - checkstyle - 6.7 - - - - src/checkstyle/checkstyle.xml - - + + org.apache.maven.plugins + maven-checkstyle-plugin + 2.15 + + + com.puppycrawl.tools + checkstyle + 6.7 + + + + src/checkstyle/checkstyle.xml + + @@ -474,26 +491,61 @@ - + - + - + - + - + - + - + + + + + + + + Fixing Checkstyle Report + + + "../../ + "./ + + + + http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap-responsive.min.css + ./css/bootstrap-responsive.min.css + + + + Welcome]]> + + + ]]> + + @@ -533,7 +585,7 @@ Changing Breadcrumbs - + /]]> /
  • Documentation
  • @@ -623,46 +675,6 @@ ]]>
    - Adding social plugins for HAPI - - - - - - - - - - - - - -
    -
    - - -

    - - -

    - - ]]>
    -
    - - @@ -727,23 +739,11 @@ - + org.apache.maven.plugins maven-changes-plugin @@ -776,12 +776,12 @@ - - ${project.basedir}/hapi-fhir-base/target/surefire-reports/ - ${project.basedir}/hapi-fhir-structures-dstu/target/surefire-reports/ - ${project.basedir}/hapi-fhir-structures-dstu2/target/surefire-reports/ - ${project.basedir}/hapi-fhir-jpaserver-base/target/surefire-reports/ - + + ${project.basedir}/hapi-fhir-base/target/surefire-reports/ + ${project.basedir}/hapi-fhir-structures-dstu/target/surefire-reports/ + ${project.basedir}/hapi-fhir-structures-dstu2/target/surefire-reports/ + ${project.basedir}/hapi-fhir-jpaserver-base/target/surefire-reports/ + @@ -808,32 +808,21 @@ ROOT + + + + - + + SIGN_ARTIFACTS @@ -869,6 +858,7 @@ hapi-fhir-structures-dstu2 hapi-fhir-structures-hl7org-dstu2 hapi-fhir-jpaserver-base + hapi-fhir-cobertura examples @@ -899,7 +889,7 @@ hapi-deployable-pom hapi-fhir-base - + hapi-fhir-base-test-mindeps-client hapi-fhir-base-test-mindeps-server hapi-tinder-plugin @@ -917,6 +907,12 @@ hapi-fhir-dist + + COBERTURA + + hapi-fhir-cobertura + +
    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. diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 3e61605f653..5f7758ee2e6 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -119,6 +119,10 @@ Generic/fluent client and JPA server now both support _lastUpdated search parameter which was added in DSTU2 + + JPA server now supports sorting on reference parameters. Thanks to + Vishal Kachroo for reporting that this wasn't working! + @@ -495,8 +499,8 @@ API CHANGE:]]> The "FHIR structures" for DSTU1 (the classes which model the resources and composite datatypes) have been moved out of the core JAR into their own JAR, in order to allow support for DEV resources, and DSTU2 resources when thast - version is finalized. See - upgrading]]> + version is finalized. See the + DSTU2 page]]> for more information. diff --git a/src/checkstyle/checkstyle.xml b/src/checkstyle/checkstyle.xml index 4deedf36ebc..06f1a53ef8b 100644 --- a/src/checkstyle/checkstyle.xml +++ b/src/checkstyle/checkstyle.xml @@ -42,10 +42,10 @@ - + - + @@ -54,13 +54,14 @@ - + + @@ -110,8 +112,7 @@ - - + @@ -175,12 +176,13 @@ - - + li{float:none;margin-left:0;} [class*="span"],.uneditable-input[class*="span"],.row-fluid [class*="span"]{float:none;display:block;width:100%;margin-left:0;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;} .span12,.row-fluid .span12{width:100%;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;} .row-fluid [class*="offset"]:first-child{margin-left:0;} .input-large,.input-xlarge,.input-xxlarge,input[class*="span"],select[class*="span"],textarea[class*="span"],.uneditable-input{display:block;width:100%;min-height:30px;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;} .input-prepend input,.input-append input,.input-prepend input[class*="span"],.input-append input[class*="span"]{display:inline-block;width:auto;} .controls-row [class*="span"]+[class*="span"]{margin-left:0;} .modal{position:fixed;top:20px;left:20px;right:20px;width:auto;margin:0;}.modal.fade{top:-100px;} .modal.fade.in{top:20px;}}@media (max-width:480px){.nav-collapse{-webkit-transform:translate3d(0, 0, 0);} .page-header h1 small{display:block;line-height:20px;} input[type="checkbox"],input[type="radio"]{border:1px solid #ccc;} .form-horizontal .control-label{float:none;width:auto;padding-top:0;text-align:left;} .form-horizontal .controls{margin-left:0;} .form-horizontal .control-list{padding-top:0;} .form-horizontal .form-actions{padding-left:10px;padding-right:10px;} .media .pull-left,.media .pull-right{float:none;display:block;margin-bottom:10px;} .media-object{margin-right:0;margin-left:0;} .modal{top:10px;left:10px;right:10px;} .modal-header .close{padding:10px;margin:-10px;} .carousel-caption{position:static;}}@media (min-width:768px) and (max-width:979px){.row{margin-left:-20px;*zoom:1;}.row:before,.row:after{display:table;content:"";line-height:0;} .row:after{clear:both;} [class*="span"]{float:left;min-height:1px;margin-left:20px;} .container,.navbar-static-top .container,.navbar-fixed-top .container,.navbar-fixed-bottom .container{width:724px;} .span12{width:724px;} .span11{width:662px;} .span10{width:600px;} .span9{width:538px;} .span8{width:476px;} .span7{width:414px;} .span6{width:352px;} .span5{width:290px;} .span4{width:228px;} .span3{width:166px;} .span2{width:104px;} .span1{width:42px;} .offset12{margin-left:764px;} .offset11{margin-left:702px;} .offset10{margin-left:640px;} .offset9{margin-left:578px;} .offset8{margin-left:516px;} .offset7{margin-left:454px;} .offset6{margin-left:392px;} .offset5{margin-left:330px;} .offset4{margin-left:268px;} .offset3{margin-left:206px;} .offset2{margin-left:144px;} .offset1{margin-left:82px;} .row-fluid{width:100%;*zoom:1;}.row-fluid:before,.row-fluid:after{display:table;content:"";line-height:0;} .row-fluid:after{clear:both;} .row-fluid [class*="span"]{display:block;width:100%;min-height:30px;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;float:left;margin-left:2.7624309392265194%;*margin-left:2.709239449864817%;} .row-fluid [class*="span"]:first-child{margin-left:0;} .row-fluid .controls-row [class*="span"]+[class*="span"]{margin-left:2.7624309392265194%;} .row-fluid .span12{width:100%;*width:99.94680851063829%;} .row-fluid .span11{width:91.43646408839778%;*width:91.38327259903608%;} .row-fluid .span10{width:82.87292817679558%;*width:82.81973668743387%;} .row-fluid .span9{width:74.30939226519337%;*width:74.25620077583166%;} .row-fluid .span8{width:65.74585635359117%;*width:65.69266486422946%;} .row-fluid .span7{width:57.18232044198895%;*width:57.12912895262725%;} .row-fluid .span6{width:48.61878453038674%;*width:48.56559304102504%;} .row-fluid .span5{width:40.05524861878453%;*width:40.00205712942283%;} .row-fluid .span4{width:31.491712707182323%;*width:31.43852121782062%;} .row-fluid .span3{width:22.92817679558011%;*width:22.87498530621841%;} .row-fluid .span2{width:14.3646408839779%;*width:14.311449394616199%;} .row-fluid .span1{width:5.801104972375691%;*width:5.747913483013988%;} .row-fluid .offset12{margin-left:105.52486187845304%;*margin-left:105.41847889972962%;} .row-fluid .offset12:first-child{margin-left:102.76243093922652%;*margin-left:102.6560479605031%;} .row-fluid .offset11{margin-left:96.96132596685082%;*margin-left:96.8549429881274%;} .row-fluid .offset11:first-child{margin-left:94.1988950276243%;*margin-left:94.09251204890089%;} .row-fluid .offset10{margin-left:88.39779005524862%;*margin-left:88.2914070765252%;} .row-fluid .offset10:first-child{margin-left:85.6353591160221%;*margin-left:85.52897613729868%;} .row-fluid .offset9{margin-left:79.8342541436464%;*margin-left:79.72787116492299%;} .row-fluid .offset9:first-child{margin-left:77.07182320441989%;*margin-left:76.96544022569647%;} .row-fluid .offset8{margin-left:71.2707182320442%;*margin-left:71.16433525332079%;} .row-fluid .offset8:first-child{margin-left:68.50828729281768%;*margin-left:68.40190431409427%;} .row-fluid .offset7{margin-left:62.70718232044199%;*margin-left:62.600799341718584%;} .row-fluid .offset7:first-child{margin-left:59.94475138121547%;*margin-left:59.838368402492065%;} .row-fluid .offset6{margin-left:54.14364640883978%;*margin-left:54.037263430116376%;} .row-fluid .offset6:first-child{margin-left:51.38121546961326%;*margin-left:51.27483249088986%;} .row-fluid .offset5{margin-left:45.58011049723757%;*margin-left:45.47372751851417%;} .row-fluid .offset5:first-child{margin-left:42.81767955801105%;*margin-left:42.71129657928765%;} .row-fluid .offset4{margin-left:37.01657458563536%;*margin-left:36.91019160691196%;} .row-fluid .offset4:first-child{margin-left:34.25414364640884%;*margin-left:34.14776066768544%;} .row-fluid .offset3{margin-left:28.45303867403315%;*margin-left:28.346655695309746%;} .row-fluid .offset3:first-child{margin-left:25.69060773480663%;*margin-left:25.584224756083227%;} .row-fluid .offset2{margin-left:19.88950276243094%;*margin-left:19.783119783707537%;} .row-fluid .offset2:first-child{margin-left:17.12707182320442%;*margin-left:17.02068884448102%;} .row-fluid .offset1{margin-left:11.32596685082873%;*margin-left:11.219583872105325%;} .row-fluid .offset1:first-child{margin-left:8.56353591160221%;*margin-left:8.457152932878806%;} input,textarea,.uneditable-input{margin-left:0;} .controls-row [class*="span"]+[class*="span"]{margin-left:20px;} input.span12,textarea.span12,.uneditable-input.span12{width:710px;} input.span11,textarea.span11,.uneditable-input.span11{width:648px;} input.span10,textarea.span10,.uneditable-input.span10{width:586px;} input.span9,textarea.span9,.uneditable-input.span9{width:524px;} input.span8,textarea.span8,.uneditable-input.span8{width:462px;} input.span7,textarea.span7,.uneditable-input.span7{width:400px;} input.span6,textarea.span6,.uneditable-input.span6{width:338px;} input.span5,textarea.span5,.uneditable-input.span5{width:276px;} input.span4,textarea.span4,.uneditable-input.span4{width:214px;} input.span3,textarea.span3,.uneditable-input.span3{width:152px;} input.span2,textarea.span2,.uneditable-input.span2{width:90px;} input.span1,textarea.span1,.uneditable-input.span1{width:28px;}}@media (min-width:1200px){.row{margin-left:-30px;*zoom:1;}.row:before,.row:after{display:table;content:"";line-height:0;} .row:after{clear:both;} [class*="span"]{float:left;min-height:1px;margin-left:30px;} .container,.navbar-static-top .container,.navbar-fixed-top .container,.navbar-fixed-bottom .container{width:1170px;} .span12{width:1170px;} .span11{width:1070px;} .span10{width:970px;} .span9{width:870px;} .span8{width:770px;} .span7{width:670px;} .span6{width:570px;} .span5{width:470px;} .span4{width:370px;} .span3{width:270px;} .span2{width:170px;} .span1{width:70px;} .offset12{margin-left:1230px;} .offset11{margin-left:1130px;} .offset10{margin-left:1030px;} .offset9{margin-left:930px;} .offset8{margin-left:830px;} .offset7{margin-left:730px;} .offset6{margin-left:630px;} .offset5{margin-left:530px;} .offset4{margin-left:430px;} .offset3{margin-left:330px;} .offset2{margin-left:230px;} .offset1{margin-left:130px;} .row-fluid{width:100%;*zoom:1;}.row-fluid:before,.row-fluid:after{display:table;content:"";line-height:0;} .row-fluid:after{clear:both;} .row-fluid [class*="span"]{display:block;width:100%;min-height:30px;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;float:left;margin-left:2.564102564102564%;*margin-left:2.5109110747408616%;} .row-fluid [class*="span"]:first-child{margin-left:0;} .row-fluid .controls-row [class*="span"]+[class*="span"]{margin-left:2.564102564102564%;} .row-fluid .span12{width:100%;*width:99.94680851063829%;} .row-fluid .span11{width:91.45299145299145%;*width:91.39979996362975%;} .row-fluid .span10{width:82.90598290598291%;*width:82.8527914166212%;} .row-fluid .span9{width:74.35897435897436%;*width:74.30578286961266%;} .row-fluid .span8{width:65.81196581196582%;*width:65.75877432260411%;} .row-fluid .span7{width:57.26495726495726%;*width:57.21176577559556%;} .row-fluid .span6{width:48.717948717948715%;*width:48.664757228587014%;} .row-fluid .span5{width:40.17094017094017%;*width:40.11774868157847%;} .row-fluid .span4{width:31.623931623931625%;*width:31.570740134569924%;} .row-fluid .span3{width:23.076923076923077%;*width:23.023731587561375%;} .row-fluid .span2{width:14.52991452991453%;*width:14.476723040552828%;} .row-fluid .span1{width:5.982905982905983%;*width:5.929714493544281%;} .row-fluid .offset12{margin-left:105.12820512820512%;*margin-left:105.02182214948171%;} .row-fluid .offset12:first-child{margin-left:102.56410256410257%;*margin-left:102.45771958537915%;} .row-fluid .offset11{margin-left:96.58119658119658%;*margin-left:96.47481360247316%;} .row-fluid .offset11:first-child{margin-left:94.01709401709402%;*margin-left:93.91071103837061%;} .row-fluid .offset10{margin-left:88.03418803418803%;*margin-left:87.92780505546462%;} .row-fluid .offset10:first-child{margin-left:85.47008547008548%;*margin-left:85.36370249136206%;} .row-fluid .offset9{margin-left:79.48717948717949%;*margin-left:79.38079650845607%;} .row-fluid .offset9:first-child{margin-left:76.92307692307693%;*margin-left:76.81669394435352%;} .row-fluid .offset8{margin-left:70.94017094017094%;*margin-left:70.83378796144753%;} .row-fluid .offset8:first-child{margin-left:68.37606837606839%;*margin-left:68.26968539734497%;} .row-fluid .offset7{margin-left:62.393162393162385%;*margin-left:62.28677941443899%;} .row-fluid .offset7:first-child{margin-left:59.82905982905982%;*margin-left:59.72267685033642%;} .row-fluid .offset6{margin-left:53.84615384615384%;*margin-left:53.739770867430444%;} .row-fluid .offset6:first-child{margin-left:51.28205128205128%;*margin-left:51.175668303327875%;} .row-fluid .offset5{margin-left:45.299145299145295%;*margin-left:45.1927623204219%;} .row-fluid .offset5:first-child{margin-left:42.73504273504273%;*margin-left:42.62865975631933%;} .row-fluid .offset4{margin-left:36.75213675213675%;*margin-left:36.645753773413354%;} .row-fluid .offset4:first-child{margin-left:34.18803418803419%;*margin-left:34.081651209310785%;} .row-fluid .offset3{margin-left:28.205128205128204%;*margin-left:28.0987452264048%;} .row-fluid .offset3:first-child{margin-left:25.641025641025642%;*margin-left:25.53464266230224%;} .row-fluid .offset2{margin-left:19.65811965811966%;*margin-left:19.551736679396257%;} .row-fluid .offset2:first-child{margin-left:17.094017094017094%;*margin-left:16.98763411529369%;} .row-fluid .offset1{margin-left:11.11111111111111%;*margin-left:11.004728132387708%;} .row-fluid .offset1:first-child{margin-left:8.547008547008547%;*margin-left:8.440625568285142%;} input,textarea,.uneditable-input{margin-left:0;} .controls-row [class*="span"]+[class*="span"]{margin-left:30px;} input.span12,textarea.span12,.uneditable-input.span12{width:1156px;} input.span11,textarea.span11,.uneditable-input.span11{width:1056px;} input.span10,textarea.span10,.uneditable-input.span10{width:956px;} input.span9,textarea.span9,.uneditable-input.span9{width:856px;} input.span8,textarea.span8,.uneditable-input.span8{width:756px;} input.span7,textarea.span7,.uneditable-input.span7{width:656px;} input.span6,textarea.span6,.uneditable-input.span6{width:556px;} input.span5,textarea.span5,.uneditable-input.span5{width:456px;} input.span4,textarea.span4,.uneditable-input.span4{width:356px;} input.span3,textarea.span3,.uneditable-input.span3{width:256px;} input.span2,textarea.span2,.uneditable-input.span2{width:156px;} input.span1,textarea.span1,.uneditable-input.span1{width:56px;} .thumbnails{margin-left:-30px;} .thumbnails>li{margin-left:30px;} .row-fluid .thumbnails{margin-left:0;}}@media (max-width:979px){body{padding-top:0;} .navbar-fixed-top,.navbar-fixed-bottom{position:static;} .navbar-fixed-top{margin-bottom:20px;} .navbar-fixed-bottom{margin-top:20px;} .navbar-fixed-top .navbar-inner,.navbar-fixed-bottom .navbar-inner{padding:5px;} .navbar .container{width:auto;padding:0;} .navbar .brand{padding-left:10px;padding-right:10px;margin:0 0 0 -5px;} .nav-collapse{clear:both;} .nav-collapse .nav{float:none;margin:0 0 10px;} .nav-collapse .nav>li{float:none;} .nav-collapse .nav>li>a{margin-bottom:2px;} .nav-collapse .nav>.divider-vertical{display:none;} .nav-collapse .nav .nav-header{color:#777777;text-shadow:none;} .nav-collapse .nav>li>a,.nav-collapse .dropdown-menu a{padding:9px 15px;font-weight:bold;color:#777777;-webkit-border-radius:3px;-moz-border-radius:3px;border-radius:3px;} .nav-collapse .btn{padding:4px 10px 4px;font-weight:normal;-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px;} .nav-collapse .dropdown-menu li+li a{margin-bottom:2px;} .nav-collapse .nav>li>a:hover,.nav-collapse .nav>li>a:focus,.nav-collapse .dropdown-menu a:hover,.nav-collapse .dropdown-menu a:focus{background-color:#f2f2f2;} .navbar-inverse .nav-collapse .nav>li>a,.navbar-inverse .nav-collapse .dropdown-menu a{color:#999999;} .navbar-inverse .nav-collapse .nav>li>a:hover,.navbar-inverse .nav-collapse .nav>li>a:focus,.navbar-inverse .nav-collapse .dropdown-menu a:hover,.navbar-inverse .nav-collapse .dropdown-menu a:focus{background-color:#111111;} .nav-collapse.in .btn-group{margin-top:5px;padding:0;} .nav-collapse .dropdown-menu{position:static;top:auto;left:auto;float:none;display:none;max-width:none;margin:0 15px;padding:0;background-color:transparent;border:none;-webkit-border-radius:0;-moz-border-radius:0;border-radius:0;-webkit-box-shadow:none;-moz-box-shadow:none;box-shadow:none;} .nav-collapse .open>.dropdown-menu{display:block;} .nav-collapse .dropdown-menu:before,.nav-collapse .dropdown-menu:after{display:none;} .nav-collapse .dropdown-menu .divider{display:none;} .nav-collapse .nav>li>.dropdown-menu:before,.nav-collapse .nav>li>.dropdown-menu:after{display:none;} .nav-collapse .navbar-form,.nav-collapse .navbar-search{float:none;padding:10px 15px;margin:10px 0;border-top:1px solid #f2f2f2;border-bottom:1px solid #f2f2f2;-webkit-box-shadow:inset 0 1px 0 rgba(255,255,255,.1), 0 1px 0 rgba(255,255,255,.1);-moz-box-shadow:inset 0 1px 0 rgba(255,255,255,.1), 0 1px 0 rgba(255,255,255,.1);box-shadow:inset 0 1px 0 rgba(255,255,255,.1), 0 1px 0 rgba(255,255,255,.1);} .navbar-inverse .nav-collapse .navbar-form,.navbar-inverse .nav-collapse .navbar-search{border-top-color:#111111;border-bottom-color:#111111;} .navbar .nav-collapse .nav.pull-right{float:none;margin-left:0;} .nav-collapse,.nav-collapse.collapse{overflow:hidden;height:0;} .navbar .btn-navbar{display:block;} .navbar-static .navbar-inner{padding-left:10px;padding-right:10px;}}@media (min-width:980px){.nav-collapse.collapse{height:auto !important;overflow:visible !important;}} diff --git a/src/site/resources/hapi.css b/src/site/resources/hapi.css index bba7409daff..25fce5416ce 100644 --- a/src/site/resources/hapi.css +++ b/src/site/resources/hapi.css @@ -86,8 +86,13 @@ A.pagenavlinks { } */ -body { +@media (min-width: 980px) { /* 768 980 */ + body { padding-top: 40px; + } +} + +body { padding-bottom: 10px; } @@ -101,6 +106,7 @@ pre { .page-header { padding-bottom: 2px; margin: 0px 0 0px; + border-bottom: none; } h1[id]:before, h2[id]:before, diff --git a/src/site/site.xml b/src/site/site.xml index 9f443d3091c..1a00b94344a 100644 --- a/src/site/site.xml +++ b/src/site/site.xml @@ -5,6 +5,7 @@ xsi:schemaLocation="http://maven.apache.org/DECORATION/1.3.0 http://maven.apache.org/xsd/decoration-1.3.0.xsd" name="HAPI"> + @@ -77,7 +79,7 @@ - + @@ -137,8 +139,10 @@ - + + + diff --git a/src/site/xdoc/doc_dstu2.xml b/src/site/xdoc/doc_dstu2.xml index d7703b2bfa4..4611985e5c2 100644 --- a/src/site/xdoc/doc_dstu2.xml +++ b/src/site/xdoc/doc_dstu2.xml @@ -17,12 +17,21 @@ Continuous Integration Builds of the FHIR specification itself and many (if not most) of these changes will end up in the final DSTU2 specification which is expected to be released - in mid-2015. + in mid-to-late-2015.

    - The most interesting changes to DSTU2 include: + DSTU2 is a significant upgrade to FHIR. While many things are unchanged, + lots of things have changed. Some of the the more interesting differences include:

      +
    • + A new + Bundle + format which is no longer based on Atom. The new format does resemble the + Atom format so it will not be unfamiliar to anyone who is used to DSTU1 bundles + but it has a few differences. On a conceptual level FHIR now defines a Bundle as + just another type of resource. +
    • New "id" and "meta" @@ -32,27 +41,9 @@ in URLs and HTTP headers outside of the payload)
    • - A new - Bundle - format which is no longer based on Atom. The new format does resemble the - Atom format so it will not be unfamiliar to anyone who is used to DSTU1 bundles - but it has a few differences. On a conceptual level FHIR now thinks of Bundles as - resources themselves, so the new bundle also gains the meta element described above. -
    • -
    • - In JSON encoding, the - encoding of extensions has changed a bit, so that extensions on non-primitive - elements now appear with the extension URL as the JSON key, instead of being - a value in an object called "extension". See the JSON documentation to see how - this new style looks. This change was reverted by HL7. -
    • -
    • - A number of new resources have been added, and some existing resources have changed. - One particularly visible (and non-backwards-compatible) change is that - Patient.gender has changed from a CodeableConcept to a Code. While this new type - is much more intuitive (having multiple codings attached to a single gender field is - confusing) it does mean that existing DSTU1 Patient resources will not parse correctly - as DSTU2 resources if they include a gender. + Numerous changes to the model, including attribute changes to existing resources, + the addition of a number of new resources, and the removal of a few redundant ones + as well.
    @@ -135,6 +126,105 @@ +
    + +

    + Since the early days of FHIR, HL7.org has provided an + open source "Java Reference Implementation", which is an implementation + of a FHIR data model, parser, and client in Java. +

    +

    + HAPI was originally started as a separate Java implementation of FHIR, + with a fairly different focus: implementing servers with an easily + extendible data model. Over time though, the two Java implementations have + shown a fair bit of overlap, so at the 2014 + DevDays we decided + to try and harmonize the two libraries. +

    +

    + HAPI FHIR 1.1 begins the availability of a harmonized library. Note that + this version has not yet been formally released, but is currently available in + "snapshot" development builds. +

    +

    + For HAPI FHIR users: This integration will bring the ability to use powerful features + from the RI in your applications, such as the resource validator and the narrative + generator. +

    +

    + For RI users: This integration will bring the ability to use HAPI's client + and server frameworks in your application, as well as the ability to take advantage + of HAPI's code-first statically bound extension mechanism. +

    + + +

    + At this point, the RI integration consists of a new parallel set of + classes representing the FHIR data model. For example, in addition to the + Patient classes representing HAPI's DSTU1 and DSTU2 models there is now + a new Patient class representing the RI structure (which is also a DSTU2 + structure). +

    +

    + The reference implementation (RI) structures have been added as a new + maven dependency library called hapi-fhir-structures-hl7org-dstu2. See + the download page for information on the Maven + dependencies for this version of the structures. +

    +

    + A new interface has been added which serves as a master interface + for all resource classes: org.hl7.fhir.instance.model.api.IBaseResource. + All RI resource classes will be in the package org.hl7.fhir.instance.model, + as shown below. +

    + Structures + +

    + Datatypes will also be found inthe same package. Unlike HAPI datatype structures, + which all end with "Dt", the RI primitive structure names end with "Type" and the + RI composite structures have no suffix, as shown below. +

    + Structures + +
    + + + +

    + If you want to use the RI structures in your application, + you will need to use the "hapi-fhir-structures-hl7org-dstu2-[version].jar" + library. +

    + +

    + Using these structures is then similar to using other structures. +

    + + + + + + +
    + +
    + +
    + +

    + If you have an existing application built using a version of previous + version of HAPI FHIR, there is one change that may affect you. As shown above, + a new interface called IBaseResource has been introduced, and the + IResource interface extends from it. Many methods in the API which + previously returned IResource now return IBaseResource. +

    +

    + For these methods, you may cast the IBaseResource to + IResource. +

    + +
    + diff --git a/src/site/xdoc/download.xml.vm b/src/site/xdoc/download.xml.vm index 22d41944815..319cdf0dc36 100644 --- a/src/site/xdoc/download.xml.vm +++ b/src/site/xdoc/download.xml.vm @@ -21,6 +21,21 @@ GitHub Release Section.

    + +

    + FHIR is a fast moving specification, and there is a lot of ongoing work + in HAPI as well. While we regularly put out new releases, there may be + times when you want to try out the latest unreleased version. You can ususally + look at the source of the + changes report + to get a sense of what has changed in the next unreleased version. +

    +

    + See using snapshot builds below to find out + how to get these builds.S +

    +
    +
    @@ -30,18 +45,20 @@ The structures JAR contains classes with the resource and datatype definitions for a given version of FHIR.

    -

    - At this time, the only official release of FHIR is the "DSTU1" release, - which is available by including the hapi-fhir-structures-dstu-[version].jar. - Note that the ballot process for the next release (DSTU2) has not yet been - completed, but many users are already targeting it for new development as it - is likely to be approved without significant changes. -

    -

    - If you use Maven, you can include these JARs with the following dependency tags - to enable DSTU1 support: -

    - + + +

    + At this time, the only official release of FHIR is the "DSTU1" release, + which is available by including the hapi-fhir-structures-dstu-[version].jar. + Note that the ballot process for the next release (DSTU2) has not yet been + completed, but many users are already targeting it for new development as it + is likely to be approved without significant changes. +

    +

    + If you use Maven, you can include these JARs with the following dependency tags + to enable DSTU1 support: +

    + ca.uhn.hapi.fhir hapi-fhir-base ${hapi_stable_version} @@ -51,8 +68,9 @@ hapi-fhir-structures-dstu ${hapi_stable_version} ]]> - - + + +

    HAPI also has a hapi-fhir-structures-dstu2-[version].jar, which @@ -76,11 +94,11 @@ - +

    To use the HL7.org reference implementation structures - (see the upgrading page for more information), + (see the DSTU2 page for more information), use the following dependency.

    @@ -143,12 +161,6 @@ compile 'ca.uhn.hapi.fhir:hapi-fhir-structures-dstu2:${hapi_stable_version}']]>< } }]]> -

    - Non Maven users can often also find snapshot builds in the Maven repository - manually by searching - here. -

    -
    diff --git a/src/site/xdoc/index.xml b/src/site/xdoc/index.xml index 9661bece336..27e9fad200e 100644 --- a/src/site/xdoc/index.xml +++ b/src/site/xdoc/index.xml @@ -10,9 +10,20 @@
    -

    - SOCIALPLUGINSHEREFHIR +

    + +
    + +
    + +
    + Build Status +
    + Coverage Status +
    + Maven Central

    +

    This is the homepage for the HAPI-FHIR library. We are developing an open-source implementation of the FHIR specification in Java.