From 07d86c50d69e4cef5d6f765fe2d40c77a43e2336 Mon Sep 17 00:00:00 2001 From: James Agnew Date: Wed, 13 Apr 2016 08:09:51 -0400 Subject: [PATCH 1/2] Work on cobertura --- README.md | 2 +- hapi-fhir-cobertura/.classpath | 10 +++++++ hapi-fhir-cobertura/.project | 29 +++++++++++++++++++ .../org.eclipse.core.resources.prefs | 2 ++ .../.settings/org.eclipse.jdt.core.prefs | 7 +++++ .../.settings/org.eclipse.m2e.core.prefs | 4 +++ ....eclipse.wst.common.project.facet.core.xml | 4 +++ hapi-fhir-cobertura/pom.xml | 2 +- pom.xml | 15 ++++++++++ src/site/site.xml | 2 +- src/site/xdoc/download.xml.vm | 14 +++++---- src/site/xdoc/index.xml | 8 ++--- 12 files changed, 87 insertions(+), 12 deletions(-) create mode 100644 hapi-fhir-cobertura/.classpath create mode 100644 hapi-fhir-cobertura/.project create mode 100644 hapi-fhir-cobertura/.settings/org.eclipse.core.resources.prefs create mode 100644 hapi-fhir-cobertura/.settings/org.eclipse.jdt.core.prefs create mode 100644 hapi-fhir-cobertura/.settings/org.eclipse.m2e.core.prefs create mode 100644 hapi-fhir-cobertura/.settings/org.eclipse.wst.common.project.facet.core.xml diff --git a/README.md b/README.md index 8dbce63a151..183bb3e76a3 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ HAPI FHIR - Java API for HL7 FHIR Clients and Servers [![Coverage Status](https://coveralls.io/repos/jamesagnew/hapi-fhir/badge.svg?branch=master&service=github)](https://coveralls.io/github/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) [![Dependency Status](https://www.versioneye.com/user/projects/55e1d0d9c6d8f2001c00043e/badge.svg?style=flat)](https://www.versioneye.com/user/projects/55e1d0d9c6d8f2001c00043e) -[![License](https://img.shields.io/badge/license-apache%202.0-ff69b4.svg)](http://jamesagnew.github.io/hapi-fhir/license.html) +[![License](https://img.shields.io/badge/license-apache%202.0-60C060.svg)](http://jamesagnew.github.io/hapi-fhir/license.html) Complete project documentation is available here: http://jamesagnew.github.io/hapi-fhir/ diff --git a/hapi-fhir-cobertura/.classpath b/hapi-fhir-cobertura/.classpath new file mode 100644 index 00000000000..534617148b0 --- /dev/null +++ b/hapi-fhir-cobertura/.classpath @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/hapi-fhir-cobertura/.project b/hapi-fhir-cobertura/.project new file mode 100644 index 00000000000..f339ae91d38 --- /dev/null +++ b/hapi-fhir-cobertura/.project @@ -0,0 +1,29 @@ + + + hapi-fhir-cobertura + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.wst.common.project.facet.core.builder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.wst.common.project.facet.core.nature + org.eclipse.jdt.core.javanature + + diff --git a/hapi-fhir-cobertura/.settings/org.eclipse.core.resources.prefs b/hapi-fhir-cobertura/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 00000000000..99f26c0203a --- /dev/null +++ b/hapi-fhir-cobertura/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/hapi-fhir-cobertura/.settings/org.eclipse.jdt.core.prefs b/hapi-fhir-cobertura/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 00000000000..f42de363afa --- /dev/null +++ b/hapi-fhir-cobertura/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,7 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 +org.eclipse.jdt.core.compiler.compliance=1.7 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.7 diff --git a/hapi-fhir-cobertura/.settings/org.eclipse.m2e.core.prefs b/hapi-fhir-cobertura/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 00000000000..f897a7f1cb2 --- /dev/null +++ b/hapi-fhir-cobertura/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/hapi-fhir-cobertura/.settings/org.eclipse.wst.common.project.facet.core.xml b/hapi-fhir-cobertura/.settings/org.eclipse.wst.common.project.facet.core.xml new file mode 100644 index 00000000000..bc0009a4558 --- /dev/null +++ b/hapi-fhir-cobertura/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -0,0 +1,4 @@ + + + + diff --git a/hapi-fhir-cobertura/pom.xml b/hapi-fhir-cobertura/pom.xml index 40d4fc936bd..6819840adfc 100644 --- a/hapi-fhir-cobertura/pom.xml +++ b/hapi-fhir-cobertura/pom.xml @@ -300,7 +300,7 @@ true - false + diff --git a/pom.xml b/pom.xml index 4d250931fde..2b5a6061ebd 100644 --- a/pom.xml +++ b/pom.xml @@ -1074,6 +1074,21 @@ http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap-responsive.min.css ./css/bootstrap-responsive.min.css + + + http://netdna.bootstrapcd + https://netdna.bootstrapcd + + + + http://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css + https://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css + + + + http://ajax.googleapis + https://ajax.googleapis + Welcome]]> diff --git a/src/site/site.xml b/src/site/site.xml index 9e0933173b0..1cecd14f04c 100644 --- a/src/site/site.xml +++ b/src/site/site.xml @@ -210,7 +210,7 @@ Hosted on GitHub
Star us and we will love you!
- + ]]> hapi-fhir-structures-dstu - 1.1 - 1.4 + 1.1 - 1.5 DSTU1 0.0.82 @@ -33,7 +33,7 @@ DSTU2 1.0.0 - 1.3, 1.4 + 1.3 - 1.5 DSTU2 1.0.2 @@ -46,13 +46,17 @@ DSTU2 1.0.0 - 1.3, 1.4 + 1.3 - 1.5 DSTU2 1.0.2 - hapi-fhir-structures-dstu3 + hapi-fhir-structures-dstu3 1.4 - DSTU2 1.3.0 Snapshot (SVN 7602) + DSTU3 1.3.0 Snapshot (SVN 7602) + + + 1.5 + DSTU3 1.4.0 Snapshot (SVN 8138) diff --git a/src/site/xdoc/index.xml b/src/site/xdoc/index.xml index 123763c0471..b173cbf4c50 100644 --- a/src/site/xdoc/index.xml +++ b/src/site/xdoc/index.xml @@ -11,11 +11,11 @@

- +
- +
- +
Build Status
@@ -25,7 +25,7 @@
VersionEye
- Apache 2.0 Licensed + Apache 2.0 Licensed

From a090f5481f8e5009d23fa4c809ce7422f111be0d Mon Sep 17 00:00:00 2001 From: James Agnew Date: Wed, 13 Apr 2016 10:33:58 -0400 Subject: [PATCH 2/2] Try to get cobertura working --- .travis.yml | 5 +- .../main/java/ca/uhn/fhir/util/TestUtil.java | 45 + hapi-fhir-cobertura/pom.xml | 19 +- .../ca/uhn/fhir/jpa/dao/BaseFhirDaoTest.java | 10 +- .../java/ca/uhn/fhir/jpa/dao/BaseJpaTest.java | 7 + .../jpa/dao/FhirResourceDaoDstu1Test.java | 12 +- .../fhir/jpa/dao/FhirSystemDaoDstu1Test.java | 13 +- .../uhn/fhir/jpa/dao/SearchBuilderTest.java | 10 +- .../jpa/dao/dstu2/BaseJpaDstu2SystemTest.java | 8 + .../fhir/jpa/dao/dstu2/BaseJpaDstu2Test.java | 8 + .../FhirResourceDaoDstu2InterceptorTest.java | 8 + .../FhirResourceDaoDstu2SearchFtTest.java | 8 + .../FhirResourceDaoDstu2SearchNoFtTest.java | 8 + .../FhirResourceDaoDstu2SubscriptionTest.java | 8 + .../dao/dstu2/FhirResourceDaoDstu2Test.java | 8 + .../dstu2/FhirResourceDaoDstu2UpdateTest.java | 8 + .../FhirResourceDaoDstu2ValidateTest.java | 8 + .../FhirResourceDaoValueSetDstu2Test.java | 8 + .../jpa/dao/dstu2/FhirSearchDaoDstu2Test.java | 10 +- .../dstu2/FhirSystemDaoDstu2SearchTest.java | 9 + .../jpa/dao/dstu2/FhirSystemDaoDstu2Test.java | 8 + .../jpa/dao/dstu3/BaseJpaDstu3SystemTest.java | 8 + .../fhir/jpa/dao/dstu3/BaseJpaDstu3Test.java | 7 + .../FhirResourceDaoDstu3ContainedTest.java | 10 +- .../FhirResourceDaoDstu3InterceptorTest.java | 9 + .../FhirResourceDaoDstu3SearchFtTest.java | 8 + .../FhirResourceDaoDstu3SearchNoFtTest.java | 10 +- .../FhirResourceDaoDstu3SubscriptionTest.java | 8 + .../dao/dstu3/FhirResourceDaoDstu3Test.java | 8 + .../dstu3/FhirResourceDaoDstu3UpdateTest.java | 8 + .../FhirResourceDaoDstu3ValidateTest.java | 8 + .../FhirResourceDaoValueSetDstu3Test.java | 8 + .../jpa/dao/dstu3/FhirSearchDaoDstu3Test.java | 10 +- .../dstu3/FhirSystemDaoDstu3SearchTest.java | 9 + .../jpa/dao/dstu3/FhirSystemDaoDstu3Test.java | 8 + .../dstu3/SearchParamExtractorDstu3Test.java | 10 +- .../uhn/fhir/jpa/entity/TagTypeEnumTest.java | 9 + .../BaseResourceProviderDstu2Test.java | 7 + .../provider/ResourceProviderDstu1Test.java | 14 +- .../provider/ResourceProviderDstu2Test.java | 8 + .../ResourceProviderDstu2ValueSetTest.java | 10 +- .../jpa/provider/SearchParameterMapTest.java | 8 + .../jpa/provider/SubscriptionsDstu2Test.java | 8 + .../jpa/provider/SystemProviderDstu1Test.java | 16 +- .../jpa/provider/SystemProviderDstu2Test.java | 12 +- .../dstu3/BaseResourceProviderDstu3Test.java | 7 + .../ResourceProviderDstu3CodeSystemTest.java | 10 +- .../dstu3/ResourceProviderDstu3Test.java | 8 + .../ResourceProviderDstu3ValueSetTest.java | 10 +- ...roviderQuestionnaireResponseDstu3Test.java | 14 +- .../StaleSearchDeletingSvcDstu3Test.java | 9 + .../dstu3/SubscriptionsDstu3Test.java | 8 + .../dstu3/SystemProviderDstu3Test.java | 5 +- .../fhir/jpa/term/TerminologySvcImplTest.java | 8 + .../uhn/fhir/jpa/testutil/SpringFileTest.java | 9 + .../ValidatorAcrossVersionsTest.java | 8 + .../ca/uhn/fhir/ctx/FhirContextDstu2Test.java | 12 +- .../ca/uhn/fhir/model/dstu2/BundleTest.java | 8 + .../model/dstu2/CompartmentDstu2Test.java | 10 +- .../uhn/fhir/model/dstu2/ModelDstu2Test.java | 10 +- .../model/dstu2/ModelInstantiationTest.java | 10 +- .../dstu2/ModelSerializationDstu2Test.java | 8 + .../primitive/BaseDateTimeDtDstu2Test.java | 8 + .../BaseResourceReferenceDtTest.java | 8 + .../uhn/fhir/model/primitive/DateDtTest.java | 9 + ...eThymeleafNarrativeGeneratorDstu2Test.java | 9 + ...mThymeleafNarrativeGeneratorDstu2Test.java | 10 +- ...tThymeleafNarrativeGeneratorTestDstu2.java | 8 + .../uhn/fhir/parser/CustomTypeDstu2Test.java | 8 + .../EmptyElementWithExtensionDstu2Test.java | 8 + .../uhn/fhir/parser/ExtensionsDstu2Test.java | 10 +- .../uhn/fhir/parser/JsonParserDstu2Test.java | 8 + .../uhn/fhir/parser/RoundTripDstu2Test.java | 8 + .../uhn/fhir/parser/XmlParserDstu2Test.java | 8 + .../fhir/rest/client/BundleTypeDstu2Test.java | 8 + .../fhir/rest/client/ClientMockingTest.java | 8 + .../ClientServerValidationTestDstu2.java | 8 + .../client/ClientWithProfileDstu2Test.java | 8 + .../fhir/rest/client/ETagClientDstu2Test.java | 8 + .../rest/client/GenericClientDstu2Test.java | 8 + .../rest/client/OperationClientDstu2Test.java | 8 + ...ompressOutgoingContentInterceptorTest.java | 6 +- .../uhn/fhir/rest/server/BinaryDstu2Test.java | 13 +- .../rest/server/BundleTypeInResponseTest.java | 5 +- .../rest/server/CompartmentDstu2Test.java | 7 + .../rest/server/CreateConditionalTest.java | 39 +- .../uhn/fhir/rest/server/DeleteDstu2Test.java | 30 +- .../uhn/fhir/rest/server/ETagServerTest.java | 107 +-- .../fhir/rest/server/ElementsParamTest.java | 7 +- .../IncludeAndRevincludeParameterTest.java | 26 +- .../fhir/rest/server/IncludeDstu2Test.java | 276 +++--- .../OperationDuplicateServerDstu2Test.java | 6 +- .../rest/server/OperationServerDstu2Test.java | 784 +++++++++--------- ...onServerWithSearchParamTypesDstu2Test.java | 5 +- .../ca/uhn/fhir/rest/server/PreferTest.java | 63 +- .../uhn/fhir/rest/server/ReadDstu2Test.java | 53 +- .../uhn/fhir/rest/server/SearchDstu2Test.java | 446 +++++----- .../server/SearchWithDstu2BundleTest.java | 19 +- .../SearchWithGenericListDstu2Test.java | 7 +- .../ServerConformanceProviderDstu2Test.java | 9 + .../rest/server/ServerFeaturesDstu2Test.java | 34 +- .../ServerInvalidDefinitionDstu2Test.java | 10 +- .../rest/server/ServerSearchDstu2Test.java | 10 +- ...eHighlightingInterceptorExceptionTest.java | 22 +- .../fhir/rest/server/SummaryParamTest.java | 7 +- ...ransactionWithBundleResourceParamTest.java | 110 +-- .../rest/server/UpdateConditionalTest.java | 61 +- .../fhir/rest/server/ValidateDstu2Test.java | 147 ++-- .../InterceptorUserDataMapDstu2Test.java | 9 +- .../LoggingInterceptorDstu2Test.java | 130 +-- .../ResponseHighlightingInterceptorTest.java | 8 + .../ServerActionInterceptorTest.java | 8 + .../AuthorizationInterceptorDstu2Test.java | 248 +++--- .../dstu2/Dstu2BundleFactoryTest.java | 8 + .../ca/uhn/fhir/util/FhirTerserDstu2Test.java | 9 +- .../fhir/validation/BundleValidationTest.java | 10 + .../ResourceValidatorDstu2Test.java | 8 + .../ValidatorInstantiatorDstu2Test.java | 9 + .../fhir/context/FhirContextDstu3Test.java | 9 +- .../fhir/context/ModelScannerDstu3Test.java | 8 + .../RuntimeResourceDefinitionDstu3Test.java | 9 + .../fhir/model/BaseDateTimeTypeDstu3Test.java | 11 + .../java/ca/uhn/fhir/model/DateTypeTest.java | 10 + .../ca/uhn/fhir/model/IdTypeDstu3Test.java | 8 + .../ca/uhn/fhir/model/ModelDstu3Test.java | 8 + .../model/ModelSerializationDstu3Test.java | 8 + ...tThymeleafNarrativeGeneratorDstu3Test.java | 9 + .../uhn/fhir/parser/CustomTypeDstu3Test.java | 10 +- .../EmptyElementWithExtensionDstu3Test.java | 9 + .../uhn/fhir/parser/JsonParserDstu3Test.java | 10 +- .../uhn/fhir/parser/RoundTripDstu3Test.java | 10 +- .../uhn/fhir/parser/XmlParserDstu3Test.java | 8 + .../client/ClientWithCustomTypeDstu3Test.java | 8 + .../rest/client/GenericClientDstu3Test.java | 8 + .../rest/client/OperationClientDstu3Test.java | 9 + .../rest/client/SearchClientDstu3Test.java | 8 + .../rest/server/CreateBinaryDstu3Test.java | 47 +- .../uhn/fhir/rest/server/CreateDstu3Test.java | 5 +- .../rest/server/CustomTypeServerDstu3.java | 30 +- .../server/DeleteConditionalDstu3Test.java | 29 +- .../rest/server/InterceptorDstu3Test.java | 31 +- .../fhir/rest/server/MetadataDstu3Test2.java | 16 +- ...onServerWithSearchParamTypesDstu3Test.java | 11 +- ...RequestValidatingInterceptorDstu3Test.java | 193 ++--- ...esponseValidatingInterceptorDstu3Test.java | 204 ++--- .../server/ServerUsingOldTypesDstu3Test.java | 6 + .../FhirInstanceValidatorDstu3Test.java | 266 +++--- ...estionnaireResponseValidatorDstu3Test.java | 167 ++-- .../ServerConformanceProviderDstu3Test.java | 6 + .../ResourceValidatorDstu3Test.java | 6 + .../src/test/java/z/TestTest.java | 11 + 151 files changed, 2853 insertions(+), 1852 deletions(-) create mode 100644 hapi-fhir-base/src/main/java/ca/uhn/fhir/util/TestUtil.java diff --git a/.travis.yml b/.travis.yml index 5c493e6538c..ff46f83cfb0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,8 +19,7 @@ before_script: - export MAVEN_SKIP_RC=true script: - - mvn -e -B clean install && cd hapi-fhir-cobertura && mvn -e -B -DTRAVIS_JOB_ID=$TRAVIS_JOB_ID clean test jacoco:report coveralls:report - -# - mvn -e -B clean install && cd hapi-fhir-cobertura && mvn -e -B -DTRAVIS_JOB_ID=$TRAVIS_JOB_ID -P COBERTURA clean cobertura:cobertura coveralls:report +# - mvn -e -B clean install && cd hapi-fhir-cobertura && mvn -e -B -DTRAVIS_JOB_ID=$TRAVIS_JOB_ID clean test jacoco:report coveralls:report + - mvn -e -B clean install && cd hapi-fhir-cobertura && mvn -e -B -DTRAVIS_JOB_ID=$TRAVIS_JOB_ID -P COBERTURA clean cobertura:cobertura coveralls:report diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/TestUtil.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/TestUtil.java new file mode 100644 index 00000000000..e5c5f39e7dd --- /dev/null +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/TestUtil.java @@ -0,0 +1,45 @@ +package ca.uhn.fhir.util; + +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; +import java.util.Arrays; + +public class TestUtil { + private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(TestUtil.class); + + /** + * THIS IS FOR UNIT TESTS ONLY + */ + @CoverageIgnore + public static void clearAllStaticFieldsForUnitTest() { + + Class theType; + try { + throw new Exception(); + } catch (Exception e) { + StackTraceElement[] st = e.getStackTrace(); + StackTraceElement elem = st[1]; + String clazzName = elem.getClassName(); + try { + theType = Class.forName(clazzName); + } catch (ClassNotFoundException e1) { + throw new Error(e); + } + } + + for (Field next : Arrays.asList(theType.getDeclaredFields())) { + if (Modifier.isStatic(next.getModifiers())) { + if (!Modifier.isFinal(next.getModifiers()) && !next.getType().isPrimitive()) { + ourLog.info("Clearing value of field: {}", next.toString()); + try { + next.setAccessible(true); + next.set(theType, null); + } catch (Exception e) { + throw new Error(e); + } + } + } + } + } + +} diff --git a/hapi-fhir-cobertura/pom.xml b/hapi-fhir-cobertura/pom.xml index 5a010c35873..e52acf0fb63 100644 --- a/hapi-fhir-cobertura/pom.xml +++ b/hapi-fhir-cobertura/pom.xml @@ -296,7 +296,7 @@ maven-surefire-plugin alphabetical - -Xmx1024m + -Xmx1624m true @@ -400,21 +400,4 @@ - - - TRAVIS - - - - org.apache.maven.plugins - maven-surefire-plugin - - - false - - - - - - 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 8ba5f065cf9..9d585f5179f 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 @@ -2,6 +2,7 @@ package ca.uhn.fhir.jpa.dao; import static org.junit.Assert.assertEquals; +import org.junit.AfterClass; import org.junit.Test; import ca.uhn.fhir.context.FhirContext; @@ -12,11 +13,18 @@ import ca.uhn.fhir.model.primitive.DateTimeDt; import ca.uhn.fhir.rest.annotation.ResourceParam; import ca.uhn.fhir.rest.param.ReferenceParam; import ca.uhn.fhir.rest.param.ResourceParameter; +import ca.uhn.fhir.util.TestUtil; public class BaseFhirDaoTest extends BaseJpaTest { private static FhirContext ourCtx = FhirContext.forDstu2(); - + + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + @Test public void testTranslateMatchUrl() { SearchParameterMap match = BaseHapiFhirDao.translateMatchUrl("Condition?patient=304&_lastUpdated=>2011-01-01T11:12:21.0000Z", ourCtx.getResourceDefinition(Condition.class)); 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 index e657ccbff04..92dad994d6d 100644 --- 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 @@ -51,12 +51,19 @@ import ca.uhn.fhir.model.dstu2.resource.Bundle.Entry; import ca.uhn.fhir.rest.method.IRequestOperationCallback; import ca.uhn.fhir.rest.server.IBundleProvider; import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; +import ca.uhn.fhir.util.TestUtil; public class BaseJpaTest { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(BaseJpaTest.class); protected ServletRequestDetails mySrd; + @AfterClass + public static void afterClassClearContext() throws Exception { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + @SuppressWarnings({ "rawtypes" }) protected List toList(IBundleProvider theSearch) { return theSearch.getResources(0, theSearch.size()); 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 f5b99c75d3d..d28b5407d5b 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 @@ -27,6 +27,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; import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; +import ca.uhn.fhir.util.TestUtil; @SuppressWarnings("unused") public class FhirResourceDaoDstu1Test extends BaseJpaTest { @@ -124,11 +125,6 @@ public class FhirResourceDaoDstu1Test extends BaseJpaTest { } - @AfterClass - public static void afterClass() { - ourCtx.close(); - } - @SuppressWarnings("unchecked") @BeforeClass public static void beforeClass() { @@ -143,4 +139,10 @@ public class FhirResourceDaoDstu1Test extends BaseJpaTest { ourFhirCtx = ourCtx.getBean(FhirContext.class); } + @AfterClass + public static void afterClassClearContext() { + ourCtx.close(); + TestUtil.clearAllStaticFieldsForUnitTest(); + } + } 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 9df5b6577b4..334d65ba2f9 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 @@ -50,7 +50,7 @@ import ca.uhn.fhir.rest.method.RequestDetails; import ca.uhn.fhir.rest.param.TokenParam; import ca.uhn.fhir.rest.server.IBundleProvider; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; -import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; +import ca.uhn.fhir.util.TestUtil; public class FhirSystemDaoDstu1Test extends BaseJpaTest { @@ -65,6 +65,13 @@ public class FhirSystemDaoDstu1Test extends BaseJpaTest { private static EntityManager ourEntityManager; private static PlatformTransactionManager ourTxManager; + @AfterClass + public static void afterClassClearContext() { + ourCtx.close(); + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + @Before public void before() { myRequestDetails = mock(RequestDetails.class); @@ -476,10 +483,6 @@ public class FhirSystemDaoDstu1Test extends BaseJpaTest { } - @AfterClass - public static void afterClass() { - ourCtx.close(); - } @SuppressWarnings("unchecked") @BeforeClass diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/SearchBuilderTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/SearchBuilderTest.java index c987682cc82..a1856c78aaf 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/SearchBuilderTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/SearchBuilderTest.java @@ -6,13 +6,21 @@ import static org.junit.Assert.*; import java.math.BigDecimal; import java.math.MathContext; +import org.junit.AfterClass; import org.junit.Test; import ca.uhn.fhir.rest.param.ParamPrefixEnum; +import ca.uhn.fhir.util.TestUtil; public class SearchBuilderTest { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(SearchBuilderTest.class); - + + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + @Test public void testAA() { assertTrue(123.00004f <= 123.0001f); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/BaseJpaDstu2SystemTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/BaseJpaDstu2SystemTest.java index 7c3681da7a9..8e0ecfae1c6 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/BaseJpaDstu2SystemTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/BaseJpaDstu2SystemTest.java @@ -9,16 +9,24 @@ import javax.servlet.ServletConfig; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; +import org.junit.AfterClass; import org.junit.Before; import ca.uhn.fhir.jpa.rp.dstu2.PatientResourceProvider; import ca.uhn.fhir.rest.method.IRequestOperationCallback; import ca.uhn.fhir.rest.server.RestfulServer; import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; +import ca.uhn.fhir.util.TestUtil; public abstract class BaseJpaDstu2SystemTest extends BaseJpaDstu2Test { private RestfulServer myServer; + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + @SuppressWarnings("unchecked") @Before public void before() throws ServletException { diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/BaseJpaDstu2Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/BaseJpaDstu2Test.java index 343e37b7625..629ea6fbbc5 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/BaseJpaDstu2Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/BaseJpaDstu2Test.java @@ -12,6 +12,7 @@ import org.apache.commons.io.IOUtils; import org.hibernate.search.jpa.FullTextEntityManager; import org.hibernate.search.jpa.Search; import org.hl7.fhir.instance.model.api.IBaseResource; +import org.junit.AfterClass; import org.junit.Before; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -63,6 +64,7 @@ import ca.uhn.fhir.model.dstu2.resource.ValueSet; import ca.uhn.fhir.parser.IParser; import ca.uhn.fhir.rest.method.MethodUtil; import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor; +import ca.uhn.fhir.util.TestUtil; //@formatter:off @RunWith(SpringJUnit4ClassRunner.class) @@ -70,6 +72,12 @@ import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor; //@formatter:on public abstract class BaseJpaDstu2Test extends BaseJpaTest { + @AfterClass + public static void afterClassClearContext() throws Exception { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + @Autowired protected ApplicationContext myAppCtx; @Autowired diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoDstu2InterceptorTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoDstu2InterceptorTest.java index c8fe2c52f7a..7b95b83db4b 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoDstu2InterceptorTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoDstu2InterceptorTest.java @@ -8,6 +8,7 @@ import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import org.junit.After; +import org.junit.AfterClass; import org.junit.Before; import org.junit.Test; import org.mockito.ArgumentCaptor; @@ -19,12 +20,19 @@ import ca.uhn.fhir.model.dstu2.resource.Patient; import ca.uhn.fhir.model.primitive.IdDt; import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor.ActionRequestDetails; import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; +import ca.uhn.fhir.util.TestUtil; public class FhirResourceDaoDstu2InterceptorTest extends BaseJpaDstu2Test { private IJpaServerInterceptor myJpaInterceptor; private JpaServerInterceptorAdapter myJpaInterceptorAdapter = new JpaServerInterceptorAdapter(); + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + @After public void after() { myDaoConfig.getInterceptors().remove(myJpaInterceptor); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoDstu2SearchFtTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoDstu2SearchFtTest.java index 3fb87cf4148..8b5922804a4 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoDstu2SearchFtTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoDstu2SearchFtTest.java @@ -14,6 +14,7 @@ import java.util.List; import javax.servlet.http.HttpServletRequest; import org.hl7.fhir.instance.model.api.IIdType; +import org.junit.AfterClass; import org.junit.Test; import ca.uhn.fhir.jpa.dao.FulltextSearchSvcImpl.Suggestion; @@ -29,11 +30,18 @@ import ca.uhn.fhir.rest.param.StringOrListParam; import ca.uhn.fhir.rest.param.StringParam; import ca.uhn.fhir.rest.server.Constants; import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; +import ca.uhn.fhir.util.TestUtil; public class FhirResourceDaoDstu2SearchFtTest extends BaseJpaDstu2Test { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirResourceDaoDstu2SearchFtTest.class); + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + @Test public void testSuggestIgnoresBase64Content() { Patient patient = new Patient(); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoDstu2SearchNoFtTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoDstu2SearchNoFtTest.java index 7892c53c2e6..9ea8c6be3d2 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoDstu2SearchNoFtTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoDstu2SearchNoFtTest.java @@ -26,6 +26,7 @@ import javax.servlet.http.HttpServletRequest; import org.apache.commons.lang3.StringUtils; import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IIdType; +import org.junit.AfterClass; import org.junit.Ignore; import org.junit.Test; @@ -97,11 +98,18 @@ import ca.uhn.fhir.rest.server.IBundleProvider; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException; import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; +import ca.uhn.fhir.util.TestUtil; @SuppressWarnings("unchecked") public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirResourceDaoDstu2SearchNoFtTest.class); + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + @Test public void testCodeSearch() { Subscription subs = new Subscription(); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoDstu2SubscriptionTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoDstu2SubscriptionTest.java index 09ca3e643c6..c1a9ca5128c 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoDstu2SubscriptionTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoDstu2SubscriptionTest.java @@ -21,6 +21,7 @@ import javax.persistence.TypedQuery; import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IIdType; +import org.junit.AfterClass; import org.junit.Before; import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -39,11 +40,18 @@ import ca.uhn.fhir.rest.server.IBundleProvider; import ca.uhn.fhir.rest.server.exceptions.ResourceGoneException; import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; +import ca.uhn.fhir.util.TestUtil; public class FhirResourceDaoDstu2SubscriptionTest extends BaseJpaDstu2Test { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirResourceDaoDstu2SubscriptionTest.class); + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + @Autowired private ISubscriptionFlaggedResourceDataDao mySubscriptionFlaggedResourceDataDao; diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoDstu2Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoDstu2Test.java index 53aa27f0eb7..fc0e60aa7c1 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoDstu2Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoDstu2Test.java @@ -36,6 +36,7 @@ import org.hamcrest.Matchers; import org.hamcrest.core.StringContains; import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IIdType; +import org.junit.AfterClass; import org.junit.Test; import org.mockito.ArgumentCaptor; @@ -106,12 +107,19 @@ import ca.uhn.fhir.rest.server.exceptions.ResourceVersionConflictException; import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor.ActionRequestDetails; import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; +import ca.uhn.fhir.util.TestUtil; @SuppressWarnings("unchecked") public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirResourceDaoDstu2Test.class); + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + private void assertGone(IIdType theId) { try { assertNotGone(theId); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoDstu2UpdateTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoDstu2UpdateTest.java index 8e6ae5954c2..3426322cbad 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoDstu2UpdateTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoDstu2UpdateTest.java @@ -24,6 +24,7 @@ import java.util.Set; import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IIdType; +import org.junit.AfterClass; import org.junit.Test; import org.mockito.ArgumentCaptor; @@ -45,10 +46,17 @@ import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor.ActionRequestDetails; import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; +import ca.uhn.fhir.util.TestUtil; public class FhirResourceDaoDstu2UpdateTest extends BaseJpaDstu2Test { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirResourceDaoDstu2UpdateTest.class); + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + @Test public void testUpdateAndGetHistoryResource() throws InterruptedException { Patient patient = new Patient(); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoDstu2ValidateTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoDstu2ValidateTest.java index 9f96f842e43..45357bff1b5 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoDstu2ValidateTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoDstu2ValidateTest.java @@ -8,6 +8,7 @@ import java.io.IOException; import java.util.Arrays; import org.hl7.fhir.instance.model.api.IIdType; +import org.junit.AfterClass; import org.junit.Test; import ca.uhn.fhir.model.api.IResource; @@ -29,10 +30,17 @@ import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import ca.uhn.fhir.rest.server.exceptions.PreconditionFailedException; import ca.uhn.fhir.rest.server.exceptions.ResourceVersionConflictException; import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; +import ca.uhn.fhir.util.TestUtil; public class FhirResourceDaoDstu2ValidateTest extends BaseJpaDstu2Test { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirResourceDaoDstu2ValidateTest.class); + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + @Test public void testValidateResourceContainingProfileDeclarationJson() throws Exception { String methodName = "testValidateResourceContainingProfileDeclarationJson"; diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoValueSetDstu2Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoValueSetDstu2Test.java index d989d41ae93..f61d58f1d43 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoValueSetDstu2Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoValueSetDstu2Test.java @@ -11,6 +11,7 @@ import static org.junit.Assert.assertTrue; import java.io.IOException; import org.hl7.fhir.instance.model.api.IIdType; +import org.junit.AfterClass; import org.junit.Before; import org.junit.Test; import org.springframework.transaction.annotation.Transactional; @@ -25,6 +26,7 @@ import ca.uhn.fhir.model.primitive.IdDt; import ca.uhn.fhir.model.primitive.StringDt; import ca.uhn.fhir.model.primitive.UriDt; import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; +import ca.uhn.fhir.util.TestUtil; public class FhirResourceDaoValueSetDstu2Test extends BaseJpaDstu2Test { @@ -32,6 +34,12 @@ public class FhirResourceDaoValueSetDstu2Test extends BaseJpaDstu2Test { private IIdType myExtensionalVsId; + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + @Before @Transactional diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirSearchDaoDstu2Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirSearchDaoDstu2Test.java index ddfbfe78984..28559084bc2 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirSearchDaoDstu2Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirSearchDaoDstu2Test.java @@ -6,6 +6,7 @@ import static org.junit.Assert.assertThat; import java.util.List; +import org.junit.AfterClass; import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -18,9 +19,16 @@ import ca.uhn.fhir.rest.param.StringOrListParam; import ca.uhn.fhir.rest.param.StringParam; import ca.uhn.fhir.rest.server.Constants; import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; +import ca.uhn.fhir.util.TestUtil; public class FhirSearchDaoDstu2Test extends BaseJpaDstu2Test { - + + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + @Autowired private IFulltextSearchSvc mySearchDao; diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirSystemDaoDstu2SearchTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirSystemDaoDstu2SearchTest.java index c0cf1401c5e..68969357d16 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirSystemDaoDstu2SearchTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirSystemDaoDstu2SearchTest.java @@ -1,9 +1,18 @@ package ca.uhn.fhir.jpa.dao.dstu2; +import org.junit.AfterClass; import org.junit.Test; +import ca.uhn.fhir.util.TestUtil; + public class FhirSystemDaoDstu2SearchTest extends BaseJpaDstu2SystemTest { + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + @Test public void testSearchByParans() { // code to come.. just here to prevent a failure diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirSystemDaoDstu2Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirSystemDaoDstu2Test.java index e2ac13188a2..aec72821899 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirSystemDaoDstu2Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirSystemDaoDstu2Test.java @@ -24,6 +24,7 @@ import java.util.List; import org.apache.commons.io.IOUtils; import org.hl7.fhir.instance.model.api.IIdType; +import org.junit.AfterClass; import org.junit.Test; import org.mockito.ArgumentCaptor; import org.springframework.transaction.TransactionStatus; @@ -66,11 +67,18 @@ import ca.uhn.fhir.rest.server.exceptions.ResourceGoneException; import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException; import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor.ActionRequestDetails; import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; +import ca.uhn.fhir.util.TestUtil; public class FhirSystemDaoDstu2Test extends BaseJpaDstu2SystemTest { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirSystemDaoDstu2Test.class); + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + @Test public void testReindexing() { Patient p = new Patient(); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/BaseJpaDstu3SystemTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/BaseJpaDstu3SystemTest.java index c49f135d990..19c1b47f110 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/BaseJpaDstu3SystemTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/BaseJpaDstu3SystemTest.java @@ -9,17 +9,25 @@ import javax.servlet.ServletConfig; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; +import org.junit.AfterClass; import org.junit.Before; import ca.uhn.fhir.jpa.rp.dstu3.PatientResourceProvider; import ca.uhn.fhir.rest.method.IRequestOperationCallback; import ca.uhn.fhir.rest.server.RestfulServer; import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; +import ca.uhn.fhir.util.TestUtil; public abstract class BaseJpaDstu3SystemTest extends BaseJpaDstu3Test { protected ServletRequestDetails mySrd; private RestfulServer myServer; + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + @SuppressWarnings("unchecked") @Before public void before() throws ServletException { diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/BaseJpaDstu3Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/BaseJpaDstu3Test.java index 90bf3926d65..82551349485 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/BaseJpaDstu3Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/BaseJpaDstu3Test.java @@ -74,6 +74,7 @@ import ca.uhn.fhir.jpa.validation.JpaValidationSupportChainDstu3; import ca.uhn.fhir.parser.IParser; import ca.uhn.fhir.rest.method.MethodUtil; import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor; +import ca.uhn.fhir.util.TestUtil; //@formatter:off @RunWith(SpringJUnit4ClassRunner.class) @@ -84,6 +85,12 @@ public abstract class BaseJpaDstu3Test extends BaseJpaTest { private static IFhirResourceDaoValueSet ourValueSetDao; private static JpaValidationSupportChainDstu3 ourJpaValidationSupportChainDstu3; + @AfterClass + public static void afterClassClearContext() throws Exception { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + @Autowired private JpaValidationSupportChainDstu3 myJpaValidationSupportChainDstu3; @Autowired diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3ContainedTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3ContainedTest.java index 97b0584f710..f20f8934b16 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3ContainedTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3ContainedTest.java @@ -7,16 +7,24 @@ import org.hl7.fhir.dstu3.model.Observation; import org.hl7.fhir.dstu3.model.Patient; import org.hl7.fhir.dstu3.model.Reference; import org.hl7.fhir.instance.model.api.IIdType; +import org.junit.AfterClass; import org.junit.Test; import ca.uhn.fhir.jpa.dao.SearchParameterMap; import ca.uhn.fhir.rest.param.TokenParam; import ca.uhn.fhir.rest.param.TokenParamModifier; import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; +import ca.uhn.fhir.util.TestUtil; public class FhirResourceDaoDstu3ContainedTest extends BaseJpaDstu3Test { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirResourceDaoDstu3ContainedTest.class); - + + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + @Test public void before() { myDaoConfig.setIndexContainedResources(true); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3InterceptorTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3InterceptorTest.java index ea3a297ebf5..ba3ff65bc39 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3InterceptorTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3InterceptorTest.java @@ -10,6 +10,7 @@ import static org.mockito.Mockito.verify; import org.hl7.fhir.dstu3.model.IdType; import org.hl7.fhir.dstu3.model.Patient; import org.junit.After; +import org.junit.AfterClass; import org.junit.Before; import org.junit.Test; import org.mockito.ArgumentCaptor; @@ -19,12 +20,20 @@ import ca.uhn.fhir.jpa.interceptor.IJpaServerInterceptor; import ca.uhn.fhir.jpa.interceptor.JpaServerInterceptorAdapter; import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor.ActionRequestDetails; import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; +import ca.uhn.fhir.util.TestUtil; public class FhirResourceDaoDstu3InterceptorTest extends BaseJpaDstu3Test { private IJpaServerInterceptor myJpaInterceptor; private JpaServerInterceptorAdapter myJpaInterceptorAdapter = new JpaServerInterceptorAdapter(); + + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + @After public void after() { myDaoConfig.getInterceptors().remove(myJpaInterceptor); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3SearchFtTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3SearchFtTest.java index 93284f260f2..3da1eaefb26 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3SearchFtTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3SearchFtTest.java @@ -22,6 +22,7 @@ import org.hl7.fhir.dstu3.model.Patient; import org.hl7.fhir.dstu3.model.Quantity; import org.hl7.fhir.dstu3.model.StringType; import org.hl7.fhir.instance.model.api.IIdType; +import org.junit.AfterClass; import org.junit.Ignore; import org.junit.Test; @@ -34,11 +35,18 @@ import ca.uhn.fhir.rest.param.TokenParam; import ca.uhn.fhir.rest.param.TokenParamModifier; import ca.uhn.fhir.rest.server.Constants; import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; +import ca.uhn.fhir.util.TestUtil; public class FhirResourceDaoDstu3SearchFtTest extends BaseJpaDstu3Test { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirResourceDaoDstu3SearchFtTest.class); + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + @Test @Ignore public void testCodeTextSearch() { diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3SearchNoFtTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3SearchNoFtTest.java index 8cc1ae6c481..47f2be9f926 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3SearchNoFtTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3SearchNoFtTest.java @@ -54,6 +54,7 @@ import org.hl7.fhir.dstu3.model.ValueSet; import org.hl7.fhir.instance.model.api.IAnyResource; import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IIdType; +import org.junit.AfterClass; import org.junit.Ignore; import org.junit.Test; @@ -92,11 +93,18 @@ import ca.uhn.fhir.rest.server.IBundleProvider; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException; import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; +import ca.uhn.fhir.util.TestUtil; @SuppressWarnings("unchecked") public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirResourceDaoDstu3SearchNoFtTest.class); - + + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + @Test public void testCodeSearch() { Subscription subs = new Subscription(); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3SubscriptionTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3SubscriptionTest.java index ec65d004cd7..820a0b52d1e 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3SubscriptionTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3SubscriptionTest.java @@ -27,6 +27,7 @@ import org.hl7.fhir.dstu3.model.Subscription.SubscriptionChannelType; import org.hl7.fhir.dstu3.model.Subscription.SubscriptionStatus; import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IIdType; +import org.junit.AfterClass; import org.junit.Before; import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -39,11 +40,18 @@ import ca.uhn.fhir.rest.server.IBundleProvider; import ca.uhn.fhir.rest.server.exceptions.ResourceGoneException; import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; +import ca.uhn.fhir.util.TestUtil; public class FhirResourceDaoDstu3SubscriptionTest extends BaseJpaDstu3Test { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirResourceDaoDstu3SubscriptionTest.class); + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + @Autowired private ISubscriptionFlaggedResourceDataDao mySubscriptionFlaggedResourceDataDao; diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3Test.java index 585437a3713..a2ec5de06fd 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3Test.java @@ -66,6 +66,7 @@ import org.hl7.fhir.dstu3.model.UriType; import org.hl7.fhir.instance.model.api.IAnyResource; import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IIdType; +import org.junit.AfterClass; import org.junit.Test; import org.mockito.ArgumentCaptor; @@ -104,12 +105,19 @@ import ca.uhn.fhir.rest.server.exceptions.ResourceVersionConflictException; import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor.ActionRequestDetails; import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; +import ca.uhn.fhir.util.TestUtil; @SuppressWarnings("unchecked") public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirResourceDaoDstu3Test.class); + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + private void assertGone(IIdType theId) { try { assertNotGone(theId); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3UpdateTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3UpdateTest.java index 4d49504a902..fa9b5aa2905 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3UpdateTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3UpdateTest.java @@ -31,6 +31,7 @@ import org.hl7.fhir.dstu3.model.Resource; import org.hl7.fhir.dstu3.model.UriType; import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IIdType; +import org.junit.AfterClass; import org.junit.Ignore; import org.junit.Test; import org.mockito.ArgumentCaptor; @@ -43,10 +44,17 @@ import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor.ActionRequestDetails; import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; +import ca.uhn.fhir.util.TestUtil; public class FhirResourceDaoDstu3UpdateTest extends BaseJpaDstu3Test { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirResourceDaoDstu3UpdateTest.class); + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + @Test public void testUpdateAndGetHistoryResource() throws InterruptedException { Patient patient = new Patient(); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3ValidateTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3ValidateTest.java index ec19059186f..7fc7d152bd3 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3ValidateTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3ValidateTest.java @@ -19,6 +19,7 @@ import org.hl7.fhir.dstu3.model.StructureDefinition; import org.hl7.fhir.dstu3.model.ValueSet; import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IIdType; +import org.junit.AfterClass; import org.junit.Ignore; import org.junit.Test; @@ -29,10 +30,17 @@ import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import ca.uhn.fhir.rest.server.exceptions.PreconditionFailedException; import ca.uhn.fhir.rest.server.exceptions.ResourceVersionConflictException; import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; +import ca.uhn.fhir.util.TestUtil; public class FhirResourceDaoDstu3ValidateTest extends BaseJpaDstu3Test { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirResourceDaoDstu3ValidateTest.class); + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + @Test @Ignore public void testValidateResourceContainingProfileDeclarationJson() throws Exception { diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoValueSetDstu3Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoValueSetDstu3Test.java index 25c1bce651f..30f190aab7a 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoValueSetDstu3Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoValueSetDstu3Test.java @@ -19,6 +19,7 @@ import org.hl7.fhir.dstu3.model.StringType; import org.hl7.fhir.dstu3.model.UriType; import org.hl7.fhir.dstu3.model.ValueSet; import org.hl7.fhir.instance.model.api.IIdType; +import org.junit.AfterClass; import org.junit.Before; import org.junit.Ignore; import org.junit.Test; @@ -26,6 +27,7 @@ import org.springframework.transaction.annotation.Transactional; import ca.uhn.fhir.jpa.dao.IFhirResourceDaoValueSet.ValidateCodeResult; import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; +import ca.uhn.fhir.util.TestUtil; public class FhirResourceDaoValueSetDstu3Test extends BaseJpaDstu3Test { @@ -34,6 +36,12 @@ public class FhirResourceDaoValueSetDstu3Test extends BaseJpaDstu3Test { private IIdType myExtensionalVsId; + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + @Before @Transactional public void before02() throws IOException { diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirSearchDaoDstu3Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirSearchDaoDstu3Test.java index 9739a780d2f..2104356919c 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirSearchDaoDstu3Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirSearchDaoDstu3Test.java @@ -8,6 +8,7 @@ import java.util.List; import org.hl7.fhir.dstu3.model.Organization; import org.hl7.fhir.dstu3.model.Patient; +import org.junit.AfterClass; import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -18,9 +19,16 @@ import ca.uhn.fhir.rest.param.StringOrListParam; import ca.uhn.fhir.rest.param.StringParam; import ca.uhn.fhir.rest.server.Constants; import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; +import ca.uhn.fhir.util.TestUtil; public class FhirSearchDaoDstu3Test extends BaseJpaDstu3Test { - + + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + @Autowired private IFulltextSearchSvc mySearchDao; diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirSystemDaoDstu3SearchTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirSystemDaoDstu3SearchTest.java index 0a1b5bfc920..db08ee1499e 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirSystemDaoDstu3SearchTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirSystemDaoDstu3SearchTest.java @@ -1,9 +1,18 @@ package ca.uhn.fhir.jpa.dao.dstu3; +import org.junit.AfterClass; import org.junit.Test; +import ca.uhn.fhir.util.TestUtil; + public class FhirSystemDaoDstu3SearchTest extends BaseJpaDstu3SystemTest { + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + @Test public void testSearchByParans() { // code to come.. just here to prevent a failure diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirSystemDaoDstu3Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirSystemDaoDstu3Test.java index e5cae9f9a3d..8c910b9e48b 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirSystemDaoDstu3Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirSystemDaoDstu3Test.java @@ -43,6 +43,7 @@ import org.hl7.fhir.dstu3.model.ValueSet; import org.hl7.fhir.instance.model.api.IAnyResource; import org.hl7.fhir.instance.model.api.IIdType; import org.junit.After; +import org.junit.AfterClass; import org.junit.Ignore; import org.junit.Test; import org.mockito.ArgumentCaptor; @@ -65,11 +66,18 @@ import ca.uhn.fhir.rest.server.exceptions.PreconditionFailedException; import ca.uhn.fhir.rest.server.exceptions.ResourceGoneException; import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException; import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor.ActionRequestDetails; +import ca.uhn.fhir.util.TestUtil; public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirSystemDaoDstu3Test.class); + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + @Test public void testReindexing() { Patient p = new Patient(); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/SearchParamExtractorDstu3Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/SearchParamExtractorDstu3Test.java index 278740af9ab..22c67b19ea6 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/SearchParamExtractorDstu3Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/SearchParamExtractorDstu3Test.java @@ -5,17 +5,25 @@ import static org.junit.Assert.*; import java.util.Set; import org.hl7.fhir.dstu3.model.Observation; +import org.junit.AfterClass; import org.junit.Test; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.jpa.entity.BaseResourceIndexedSearchParam; import ca.uhn.fhir.jpa.entity.ResourceIndexedSearchParamToken; import ca.uhn.fhir.jpa.entity.ResourceTable; +import ca.uhn.fhir.util.TestUtil; public class SearchParamExtractorDstu3Test { private static final FhirContext ourCtx = FhirContext.forDstu3(); - + + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + @Test public void testParamWithOrInPath() { Observation obs = new Observation(); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/entity/TagTypeEnumTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/entity/TagTypeEnumTest.java index 6e953586ff3..75cf5f987fa 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/entity/TagTypeEnumTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/entity/TagTypeEnumTest.java @@ -2,10 +2,19 @@ package ca.uhn.fhir.jpa.entity; import static org.junit.Assert.*; +import org.junit.AfterClass; import org.junit.Test; +import ca.uhn.fhir.util.TestUtil; + public class TagTypeEnumTest { + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + @Test public void testOrder() { // Ordinals are used in DB columns so the order diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/BaseResourceProviderDstu2Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/BaseResourceProviderDstu2Test.java index ca818416e8c..840288d64da 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/BaseResourceProviderDstu2Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/BaseResourceProviderDstu2Test.java @@ -34,6 +34,7 @@ import ca.uhn.fhir.rest.client.ServerValidationModeEnum; import ca.uhn.fhir.rest.client.interceptor.LoggingInterceptor; import ca.uhn.fhir.rest.server.FifoMemoryPagingProvider; import ca.uhn.fhir.rest.server.RestfulServer; +import ca.uhn.fhir.util.TestUtil; public abstract class BaseResourceProviderDstu2Test extends BaseJpaDstu2Test { @@ -44,6 +45,12 @@ public abstract class BaseResourceProviderDstu2Test extends BaseJpaDstu2Test { protected static String ourServerBase; private static GenericWebApplicationContext ourWebApplicationContext; + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + public BaseResourceProviderDstu2Test() { super(); } 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 fa900ae9efc..0d472b4d487 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 @@ -64,6 +64,7 @@ import ca.uhn.fhir.rest.server.RestfulServer; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; +import ca.uhn.fhir.util.TestUtil; public class ResourceProviderDstu1Test extends BaseJpaTest { @@ -80,6 +81,14 @@ public class ResourceProviderDstu1Test extends BaseJpaTest { private static String ourServerBase; private static CloseableHttpClient ourHttpClient; + @AfterClass + public static void afterClassClearContext() throws Exception { + ourServer.stop(); + ourAppCtx.stop(); + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + // private static JpaConformanceProvider ourConfProvider; private void delete(String theResourceType, String theParamName, String theParamValue) { @@ -515,11 +524,6 @@ public class ResourceProviderDstu1Test extends BaseJpaTest { } - @AfterClass - public static void afterClass() throws Exception { - ourServer.stop(); - ourAppCtx.stop(); - } @SuppressWarnings("unchecked") @BeforeClass 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 fd3f322091d..9598183580e 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 @@ -40,6 +40,7 @@ import org.apache.http.entity.ContentType; import org.apache.http.entity.StringEntity; import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IIdType; +import org.junit.AfterClass; import org.junit.Test; import ca.uhn.fhir.model.api.Bundle; @@ -100,12 +101,19 @@ import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import ca.uhn.fhir.rest.server.exceptions.PreconditionFailedException; import ca.uhn.fhir.rest.server.exceptions.ResourceGoneException; import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; +import ca.uhn.fhir.util.TestUtil; import ca.uhn.fhir.util.UrlUtil; public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ResourceProviderDstu2Test.class); + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + @Override public void before() throws Exception { super.before(); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/ResourceProviderDstu2ValueSetTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/ResourceProviderDstu2ValueSetTest.java index 22837b58262..36a2a3c7616 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/ResourceProviderDstu2ValueSetTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/ResourceProviderDstu2ValueSetTest.java @@ -10,6 +10,7 @@ import static org.junit.Assert.fail; import java.io.IOException; import org.hl7.fhir.instance.model.api.IIdType; +import org.junit.AfterClass; import org.junit.Before; import org.junit.Ignore; import org.junit.Test; @@ -24,12 +25,19 @@ import ca.uhn.fhir.model.primitive.StringDt; import ca.uhn.fhir.model.primitive.UriDt; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; +import ca.uhn.fhir.util.TestUtil; public class ResourceProviderDstu2ValueSetTest extends BaseResourceProviderDstu2Test { private IIdType myExtensionalVsId; private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ResourceProviderDstu2ValueSetTest.class); - + + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + @Before @Transactional public void before02() throws IOException { diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/SearchParameterMapTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/SearchParameterMapTest.java index cb3bb8e1937..f79bed8fc0f 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/SearchParameterMapTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/SearchParameterMapTest.java @@ -2,12 +2,20 @@ package ca.uhn.fhir.jpa.provider; import static org.junit.Assert.assertEquals; +import org.junit.AfterClass; import org.junit.Test; import ca.uhn.fhir.jpa.dao.SearchParameterMap.EverythingModeEnum; +import ca.uhn.fhir.util.TestUtil; public class SearchParameterMapTest { + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + /** * {@link Search} uses these ordinals so they shouldn't get out of order */ diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/SubscriptionsDstu2Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/SubscriptionsDstu2Test.java index 5f933cab4d2..8581ae9f1c0 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/SubscriptionsDstu2Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/SubscriptionsDstu2Test.java @@ -17,6 +17,7 @@ import org.eclipse.jetty.websocket.client.ClientUpgradeRequest; import org.eclipse.jetty.websocket.client.WebSocketClient; import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IIdType; +import org.junit.AfterClass; import org.junit.Before; import org.junit.Test; @@ -32,6 +33,7 @@ import ca.uhn.fhir.model.primitive.IdDt; import ca.uhn.fhir.rest.server.EncodingEnum; import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; +import ca.uhn.fhir.util.TestUtil; public class SubscriptionsDstu2Test extends BaseResourceProviderDstu2Test { @@ -45,6 +47,12 @@ public class SubscriptionsDstu2Test extends BaseResourceProviderDstu2Test { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(SubscriptionsDstu2Test.class); + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + @Before public void beforeEnableScheduling() { myDaoConfig.setSchedulingDisabled(false); 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 08ed63475f8..93a76fc81f0 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 @@ -36,6 +36,7 @@ import ca.uhn.fhir.model.dstu2.resource.Bundle; import ca.uhn.fhir.model.primitive.IdDt; import ca.uhn.fhir.rest.client.IGenericClient; import ca.uhn.fhir.rest.server.RestfulServer; +import ca.uhn.fhir.util.TestUtil; public class SystemProviderDstu1Test extends BaseJpaTest { @@ -65,11 +66,6 @@ public class SystemProviderDstu1Test extends BaseJpaTest { } - @AfterClass - public static void afterClass() throws Exception { - ourServer.stop(); - ourAppCtx.stop(); - } @SuppressWarnings("unchecked") @BeforeClass @@ -121,5 +117,13 @@ public class SystemProviderDstu1Test extends BaseJpaTest { ourClient = ourCtx.newRestfulGenericClient(serverBase); ourClient.setLogRequestAndResponse(true); } - + + @AfterClass + public static void afterClassClearContext() throws Exception { + ourServer.stop(); + ourAppCtx.stop(); + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + } 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 fb00dda4b80..0e75e422997 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 @@ -52,6 +52,7 @@ import ca.uhn.fhir.rest.server.RestfulServer; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import ca.uhn.fhir.rest.server.interceptor.ResponseHighlighterInterceptor; import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; +import ca.uhn.fhir.util.TestUtil; public class SystemProviderDstu2Test extends BaseJpaDstu2Test { @@ -63,6 +64,13 @@ public class SystemProviderDstu2Test extends BaseJpaDstu2Test { private static Server ourServer; private static String ourServerBase; + @AfterClass + public static void afterClassClearContext() throws Exception { + ourServer.stop(); + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + @Before public void beforeStartServer() throws Exception { if (myRestServer == null) { @@ -419,9 +427,5 @@ public class SystemProviderDstu2Test extends BaseJpaDstu2Test { assertEquals(0, respSub.getEntry().size()); } - @AfterClass - public static void afterClass() throws Exception { - ourServer.stop(); - } } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/BaseResourceProviderDstu3Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/BaseResourceProviderDstu3Test.java index 6fde2431f16..b58bf14c581 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/BaseResourceProviderDstu3Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/BaseResourceProviderDstu3Test.java @@ -38,6 +38,7 @@ import ca.uhn.fhir.rest.client.ServerValidationModeEnum; import ca.uhn.fhir.rest.client.interceptor.LoggingInterceptor; import ca.uhn.fhir.rest.server.FifoMemoryPagingProvider; import ca.uhn.fhir.rest.server.RestfulServer; +import ca.uhn.fhir.util.TestUtil; public abstract class BaseResourceProviderDstu3Test extends BaseJpaDstu3Test { @@ -50,6 +51,12 @@ public abstract class BaseResourceProviderDstu3Test extends BaseJpaDstu3Test { private static JpaValidationSupportChainDstu3 myValidationSupport; private static GenericWebApplicationContext ourWebApplicationContext; + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + public BaseResourceProviderDstu3Test() { super(); } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderDstu3CodeSystemTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderDstu3CodeSystemTest.java index 94c35820980..41d592aeae3 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderDstu3CodeSystemTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderDstu3CodeSystemTest.java @@ -18,18 +18,26 @@ import org.hl7.fhir.dstu3.model.StringType; import org.hl7.fhir.dstu3.model.UriType; import org.hl7.fhir.dstu3.model.ValueSet; import org.hl7.fhir.instance.model.api.IIdType; +import org.junit.AfterClass; import org.junit.Before; import org.junit.Test; import org.springframework.transaction.annotation.Transactional; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException; +import ca.uhn.fhir.util.TestUtil; public class ResourceProviderDstu3CodeSystemTest extends BaseResourceProviderDstu3Test { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ResourceProviderDstu3CodeSystemTest.class); private IIdType myExtensionalVsId; - + + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + @Before @Transactional public void before02() throws IOException { diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderDstu3Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderDstu3Test.java index ea6595e1fa2..e5f103671d5 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderDstu3Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderDstu3Test.java @@ -86,6 +86,7 @@ import org.hl7.fhir.dstu3.model.UnsignedIntType; import org.hl7.fhir.dstu3.model.ValueSet; import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IIdType; +import org.junit.AfterClass; import org.junit.Ignore; import org.junit.Test; @@ -107,12 +108,19 @@ import ca.uhn.fhir.rest.server.exceptions.PreconditionFailedException; import ca.uhn.fhir.rest.server.exceptions.ResourceGoneException; import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; +import ca.uhn.fhir.util.TestUtil; import ca.uhn.fhir.util.UrlUtil; public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ResourceProviderDstu3Test.class); + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + @Override public void before() throws Exception { super.before(); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderDstu3ValueSetTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderDstu3ValueSetTest.java index 464f0ec388d..b7132a2dd80 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderDstu3ValueSetTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderDstu3ValueSetTest.java @@ -18,18 +18,26 @@ import org.hl7.fhir.dstu3.model.StringType; import org.hl7.fhir.dstu3.model.UriType; import org.hl7.fhir.dstu3.model.ValueSet; import org.hl7.fhir.instance.model.api.IIdType; +import org.junit.AfterClass; import org.junit.Before; import org.junit.Test; import org.springframework.transaction.annotation.Transactional; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException; +import ca.uhn.fhir.util.TestUtil; public class ResourceProviderDstu3ValueSetTest extends BaseResourceProviderDstu3Test { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ResourceProviderDstu3ValueSetTest.class); private IIdType myExtensionalVsId; - + + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + @Before @Transactional public void before02() throws IOException { diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderQuestionnaireResponseDstu3Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderQuestionnaireResponseDstu3Test.java index bf0c1d1ae87..18e1f858a28 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderQuestionnaireResponseDstu3Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderQuestionnaireResponseDstu3Test.java @@ -20,6 +20,7 @@ import org.junit.Test; import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; import ca.uhn.fhir.rest.server.interceptor.RequestValidatingInterceptor; import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; +import ca.uhn.fhir.util.TestUtil; import ca.uhn.fhir.validation.IValidatorModule; import ca.uhn.fhir.validation.ResultSeverityEnum; @@ -28,6 +29,14 @@ public class ResourceProviderQuestionnaireResponseDstu3Test extends BaseResource private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ResourceProviderQuestionnaireResponseDstu3Test.class); private static RequestValidatingInterceptor ourValidatingInterceptor; + @AfterClass + public static void afterClassClearContext() { + ourRestServer.unregisterInterceptor(ourValidatingInterceptor); + ourValidatingInterceptor = null; + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + @Override @Before public void before() throws Exception { @@ -45,11 +54,6 @@ public class ResourceProviderQuestionnaireResponseDstu3Test extends BaseResource } } - @AfterClass - public static void afterClass() { - ourRestServer.unregisterInterceptor(ourValidatingInterceptor); - ourValidatingInterceptor = null; - } @Test diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/StaleSearchDeletingSvcDstu3Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/StaleSearchDeletingSvcDstu3Test.java index 8f4219a00a7..921b6b9d473 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/StaleSearchDeletingSvcDstu3Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/StaleSearchDeletingSvcDstu3Test.java @@ -11,11 +11,13 @@ import org.apache.commons.lang3.time.DateUtils; import org.hl7.fhir.dstu3.model.Bundle; import org.hl7.fhir.dstu3.model.Bundle.BundleLinkComponent; import org.hl7.fhir.dstu3.model.Patient; +import org.junit.AfterClass; import org.junit.Test; import ca.uhn.fhir.rest.gclient.IQuery; import ca.uhn.fhir.rest.server.exceptions.ResourceGoneException; import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; +import ca.uhn.fhir.util.TestUtil; public class StaleSearchDeletingSvcDstu3Test extends BaseResourceProviderDstu3Test { @@ -28,6 +30,13 @@ public class StaleSearchDeletingSvcDstu3Test extends BaseResourceProviderDstu3Te myDaoConfig.setExpireSearchResultsAfterMillis(DateUtils.MILLIS_PER_HOUR); } + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + + @Test public void testEverythingInstanceWithContentFilter() throws Exception { diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/SubscriptionsDstu3Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/SubscriptionsDstu3Test.java index ab6f1bb6143..060b8c8a884 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/SubscriptionsDstu3Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/SubscriptionsDstu3Test.java @@ -22,6 +22,7 @@ import org.hl7.fhir.dstu3.model.Subscription.SubscriptionChannelType; import org.hl7.fhir.dstu3.model.Subscription.SubscriptionStatus; import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IIdType; +import org.junit.AfterClass; import org.junit.Before; import org.junit.Test; @@ -30,6 +31,7 @@ import ca.uhn.fhir.model.primitive.IdDt; import ca.uhn.fhir.rest.server.EncodingEnum; import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; +import ca.uhn.fhir.util.TestUtil; public class SubscriptionsDstu3Test extends BaseResourceProviderDstu3Test { @@ -45,6 +47,12 @@ public class SubscriptionsDstu3Test extends BaseResourceProviderDstu3Test { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(SubscriptionsDstu3Test.class); + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + @Before public void beforeEnableScheduling() { myDaoConfig.setSchedulingDisabled(false); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/SystemProviderDstu3Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/SystemProviderDstu3Test.java index 17933f84aa2..77ff3e151b0 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/SystemProviderDstu3Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/SystemProviderDstu3Test.java @@ -62,6 +62,7 @@ import ca.uhn.fhir.rest.server.RestfulServer; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import ca.uhn.fhir.rest.server.interceptor.RequestValidatingInterceptor; import ca.uhn.fhir.rest.server.interceptor.ResponseHighlighterInterceptor; +import ca.uhn.fhir.util.TestUtil; import ca.uhn.fhir.validation.ResultSeverityEnum; public class SystemProviderDstu3Test extends BaseJpaDstu3Test { @@ -74,6 +75,7 @@ public class SystemProviderDstu3Test extends BaseJpaDstu3Test { private static Server ourServer; private static String ourServerBase; + @Before public void beforeStartServer() throws Exception { if (myRestServer == null) { @@ -508,8 +510,9 @@ public class SystemProviderDstu3Test extends BaseJpaDstu3Test { } @AfterClass - public static void afterClass() throws Exception { + public static void afterClassClearContext() throws Exception { ourServer.stop(); + TestUtil.clearAllStaticFieldsForUnitTest(); } } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TerminologySvcImplTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TerminologySvcImplTest.java index 971d52d084e..e0877063065 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TerminologySvcImplTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TerminologySvcImplTest.java @@ -13,6 +13,7 @@ import java.util.Set; import org.hl7.fhir.dstu3.model.CodeSystem; import org.hl7.fhir.dstu3.model.CodeSystem.CodeSystemContentMode; import org.hl7.fhir.instance.model.api.IIdType; +import org.junit.AfterClass; import org.junit.Ignore; import org.junit.Test; @@ -22,9 +23,16 @@ import ca.uhn.fhir.jpa.entity.TermCodeSystemVersion; import ca.uhn.fhir.jpa.entity.TermConcept; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; +import ca.uhn.fhir.util.TestUtil; public class TerminologySvcImplTest extends BaseJpaDstu3Test { + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + @Test public void testStoreCodeSystemInvalidCyclicLoop() { CodeSystem codeSystem = new CodeSystem(); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/testutil/SpringFileTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/testutil/SpringFileTest.java index 11984332998..11a6ac336aa 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/testutil/SpringFileTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/testutil/SpringFileTest.java @@ -4,10 +4,19 @@ import static org.hamcrest.Matchers.*; import static org.junit.Assert.*; import org.apache.commons.io.IOUtils; +import org.junit.AfterClass; import org.junit.Test; +import ca.uhn.fhir.util.TestUtil; + public class SpringFileTest { + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + @Test public void testNoBadResources() throws Exception { String text = IOUtils.toString(SpringFileTest.class.getResourceAsStream("/hapi-fhir-server-resourceproviders-dstu2.xml")); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/validator/ValidatorAcrossVersionsTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/validator/ValidatorAcrossVersionsTest.java index 9d98f34e1f6..52c924a6a72 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/validator/ValidatorAcrossVersionsTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/validator/ValidatorAcrossVersionsTest.java @@ -3,11 +3,13 @@ package ca.uhn.fhir.validator; import static org.junit.Assert.assertEquals; import org.hl7.fhir.instance.hapi.validation.FhirInstanceValidator; +import org.junit.AfterClass; import org.junit.Test; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.dstu2.resource.QuestionnaireResponse; import ca.uhn.fhir.model.primitive.DateTimeDt; +import ca.uhn.fhir.util.TestUtil; import ca.uhn.fhir.validation.FhirValidator; import ca.uhn.fhir.validation.ValidationResult; @@ -17,6 +19,12 @@ import ca.uhn.fhir.validation.ValidationResult; public class ValidatorAcrossVersionsTest { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ValidatorAcrossVersionsTest.class); + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + @Test public void testValidateProfileOnDstu2Resource() { diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/ctx/FhirContextDstu2Test.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/ctx/FhirContextDstu2Test.java index 4013913883e..41a2ce65721 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/ctx/FhirContextDstu2Test.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/ctx/FhirContextDstu2Test.java @@ -2,6 +2,7 @@ package ca.uhn.fhir.ctx; import static org.junit.Assert.assertEquals; +import org.junit.AfterClass; import org.junit.Test; import ca.uhn.fhir.context.BaseRuntimeChildDatatypeDefinition; @@ -10,12 +11,19 @@ import ca.uhn.fhir.context.RuntimeResourceDefinition; import ca.uhn.fhir.model.dstu2.resource.Patient; import ca.uhn.fhir.model.dstu2.valueset.AdministrativeGenderEnum; import ca.uhn.fhir.model.dstu2.valueset.MaritalStatusCodesEnum; +import ca.uhn.fhir.util.TestUtil; public class FhirContextDstu2Test { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirContextDstu2Test.class); - private FhirContext ourCtx = FhirContext.forDstu2(); - + private static FhirContext ourCtx = FhirContext.forDstu2(); + + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + @Test public void testQueryBoundCode() { RuntimeResourceDefinition patientType = ourCtx.getResourceDefinition(Patient.class); diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/model/dstu2/BundleTest.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/model/dstu2/BundleTest.java index b0e1fe1e3fe..32d392377c0 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/model/dstu2/BundleTest.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/model/dstu2/BundleTest.java @@ -2,13 +2,21 @@ package ca.uhn.fhir.model.dstu2; import static org.junit.Assert.*; +import org.junit.AfterClass; import org.junit.Test; import ca.uhn.fhir.model.dstu2.resource.Bundle; import ca.uhn.fhir.model.dstu2.resource.Bundle.Link; +import ca.uhn.fhir.util.TestUtil; public class BundleTest { + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + @Test public void testGetLink() { Bundle b = new Bundle(); diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/model/dstu2/CompartmentDstu2Test.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/model/dstu2/CompartmentDstu2Test.java index c358515cb3a..9fd5e6098a4 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/model/dstu2/CompartmentDstu2Test.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/model/dstu2/CompartmentDstu2Test.java @@ -2,17 +2,25 @@ package ca.uhn.fhir.model.dstu2; import static org.junit.Assert.*; +import org.junit.AfterClass; import org.junit.Test; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.dstu2.resource.Observation; import ca.uhn.fhir.model.dstu2.resource.Patient; import ca.uhn.fhir.model.primitive.IdDt; +import ca.uhn.fhir.util.TestUtil; public class CompartmentDstu2Test { private static FhirContext ourCtx = FhirContext.forDstu2(); - + + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + @Test public void testMembership() { diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/model/dstu2/ModelDstu2Test.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/model/dstu2/ModelDstu2Test.java index 792e8a0c978..3242c1cb4b6 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/model/dstu2/ModelDstu2Test.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/model/dstu2/ModelDstu2Test.java @@ -5,6 +5,7 @@ import static org.junit.Assert.assertEquals; import java.util.Arrays; import java.util.List; +import org.junit.AfterClass; import org.junit.Test; import ca.uhn.fhir.context.FhirContext; @@ -12,11 +13,18 @@ import ca.uhn.fhir.model.dstu2.composite.CodeableConceptDt; import ca.uhn.fhir.model.dstu2.resource.Patient; import ca.uhn.fhir.model.dstu2.resource.Practitioner; import ca.uhn.fhir.model.dstu2.resource.Practitioner.PractitionerRole; +import ca.uhn.fhir.util.TestUtil; public class ModelDstu2Test { private static FhirContext ourCtx = FhirContext.forDstu2(); - + + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + /** * See #320 */ diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/model/dstu2/ModelInstantiationTest.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/model/dstu2/ModelInstantiationTest.java index f68d1776deb..77848388bfa 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/model/dstu2/ModelInstantiationTest.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/model/dstu2/ModelInstantiationTest.java @@ -5,17 +5,25 @@ import static org.junit.Assert.*; import java.util.Properties; import org.hl7.fhir.instance.model.api.IBaseBinary; +import org.junit.AfterClass; import org.junit.Test; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.RuntimeResourceDefinition; import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.model.dstu2.resource.Binary; +import ca.uhn.fhir.util.TestUtil; public class ModelInstantiationTest { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ModelInstantiationTest.class); - + + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + @Test public void testBinaryIsBaseBinary() { assertTrue(IBaseBinary.class.isAssignableFrom(Binary.class)); diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/model/dstu2/ModelSerializationDstu2Test.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/model/dstu2/ModelSerializationDstu2Test.java index 944d638053f..558d594e8f3 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/model/dstu2/ModelSerializationDstu2Test.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/model/dstu2/ModelSerializationDstu2Test.java @@ -8,6 +8,7 @@ import java.util.Date; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.SerializationUtils; import org.hl7.fhir.instance.model.api.IBaseResource; +import org.junit.AfterClass; import org.junit.Test; import ca.uhn.fhir.context.FhirContext; @@ -21,11 +22,18 @@ import ca.uhn.fhir.model.dstu2.valueset.AdministrativeGenderEnum; import ca.uhn.fhir.model.dstu2.valueset.IdentifierTypeCodesEnum; import ca.uhn.fhir.model.dstu2.valueset.MaritalStatusCodesEnum; import ca.uhn.fhir.parser.IParser; +import ca.uhn.fhir.util.TestUtil; public class ModelSerializationDstu2Test { private static final FhirContext ourCtx = FhirContext.forDstu2(); + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + /** * Verify that MaritalStatusCodeEnum (and, by extension, BoundCodeableConcepts in general) are serializable. Author: Nick Peterson (nrpeterson@gmail.com) */ diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/model/primitive/BaseDateTimeDtDstu2Test.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/model/primitive/BaseDateTimeDtDstu2Test.java index 5ab4160ecae..372725b9953 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/model/primitive/BaseDateTimeDtDstu2Test.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/model/primitive/BaseDateTimeDtDstu2Test.java @@ -11,17 +11,25 @@ import java.util.Date; import java.util.Locale; import java.util.TimeZone; +import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import ca.uhn.fhir.model.api.TemporalPrecisionEnum; +import ca.uhn.fhir.util.TestUtil; public class BaseDateTimeDtDstu2Test { private static Locale ourDefaultLocale; private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(BaseDateTimeDtDstu2Test.class); private SimpleDateFormat myDateInstantParser; + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + @Before public void before() { myDateInstantParser = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/model/primitive/BaseResourceReferenceDtTest.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/model/primitive/BaseResourceReferenceDtTest.java index 3744409aa99..c70937b9b0a 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/model/primitive/BaseResourceReferenceDtTest.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/model/primitive/BaseResourceReferenceDtTest.java @@ -20,6 +20,7 @@ import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpUriRequest; import org.apache.http.message.BasicHeader; import org.apache.http.message.BasicStatusLine; +import org.junit.AfterClass; import org.junit.Before; import org.junit.Test; import org.mockito.ArgumentCaptor; @@ -35,6 +36,7 @@ import ca.uhn.fhir.rest.client.IGenericClient; import ca.uhn.fhir.rest.client.ServerValidationModeEnum; import ca.uhn.fhir.rest.client.api.IRestfulClient; import ca.uhn.fhir.rest.server.Constants; +import ca.uhn.fhir.util.TestUtil; public class BaseResourceReferenceDtTest { @@ -43,6 +45,12 @@ public class BaseResourceReferenceDtTest { private HttpClient myHttpClient; private HttpResponse myHttpResponse; + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + @Before public void before() { ourCtx = FhirContext.forDstu2(); diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/model/primitive/DateDtTest.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/model/primitive/DateDtTest.java index f2b8be5fce0..90cc8e19ae7 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/model/primitive/DateDtTest.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/model/primitive/DateDtTest.java @@ -7,11 +7,20 @@ import java.util.Calendar; import java.util.TimeZone; import java.util.TreeSet; +import org.junit.AfterClass; import org.junit.Test; +import ca.uhn.fhir.util.TestUtil; + public class DateDtTest { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(DateDtTest.class); + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + @Test public void testPrecision() { diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/narrative/BaseThymeleafNarrativeGeneratorDstu2Test.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/narrative/BaseThymeleafNarrativeGeneratorDstu2Test.java index aff14d39eb0..bc0b80a796d 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/narrative/BaseThymeleafNarrativeGeneratorDstu2Test.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/narrative/BaseThymeleafNarrativeGeneratorDstu2Test.java @@ -2,11 +2,20 @@ package ca.uhn.fhir.narrative; import static org.junit.Assert.assertEquals; +import org.junit.AfterClass; import org.junit.Test; +import ca.uhn.fhir.util.TestUtil; + public class BaseThymeleafNarrativeGeneratorDstu2Test { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(BaseThymeleafNarrativeGeneratorDstu2Test.class); + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + @Test public void testTrimWhitespace() { diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/narrative/CustomThymeleafNarrativeGeneratorDstu2Test.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/narrative/CustomThymeleafNarrativeGeneratorDstu2Test.java index a30f8453da7..cd1ef67d13a 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/narrative/CustomThymeleafNarrativeGeneratorDstu2Test.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/narrative/CustomThymeleafNarrativeGeneratorDstu2Test.java @@ -3,18 +3,26 @@ package ca.uhn.fhir.narrative; import static org.hamcrest.Matchers.containsString; import static org.junit.Assert.assertThat; +import org.junit.AfterClass; import org.junit.Test; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.dstu2.composite.NarrativeDt; import ca.uhn.fhir.model.dstu2.resource.Practitioner; +import ca.uhn.fhir.util.TestUtil; public class CustomThymeleafNarrativeGeneratorDstu2Test { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(CustomThymeleafNarrativeGeneratorDstu2Test.class); private static FhirContext ourCtx = FhirContext.forDstu2(); - + + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + @Test public void testGenerator() { 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 654c2a41890..efc92ec448e 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 @@ -8,6 +8,7 @@ import static org.junit.Assert.assertTrue; import java.util.Date; import org.hamcrest.core.StringContains; +import org.junit.AfterClass; import org.junit.Before; import org.junit.Ignore; import org.junit.Test; @@ -34,12 +35,19 @@ import ca.uhn.fhir.model.dstu2.valueset.ObservationStatusEnum; import ca.uhn.fhir.model.primitive.DateTimeDt; import ca.uhn.fhir.model.primitive.StringDt; import ca.uhn.fhir.parser.DataFormatException; +import ca.uhn.fhir.util.TestUtil; public class DefaultThymeleafNarrativeGeneratorTestDstu2 { private static FhirContext ourCtx = FhirContext.forDstu2(); private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(DefaultThymeleafNarrativeGeneratorTestDstu2.class); private DefaultThymeleafNarrativeGenerator myGen; + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + @Before public void before() { myGen = new DefaultThymeleafNarrativeGenerator(); diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/parser/CustomTypeDstu2Test.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/parser/CustomTypeDstu2Test.java index 841e7be33be..12f77a00bf0 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/parser/CustomTypeDstu2Test.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/parser/CustomTypeDstu2Test.java @@ -11,6 +11,7 @@ import static org.junit.Assert.assertThat; import java.util.ArrayList; import java.util.List; +import org.junit.AfterClass; import org.junit.Before; import org.junit.Test; @@ -29,12 +30,19 @@ import ca.uhn.fhir.model.primitive.DateTimeDt; import ca.uhn.fhir.model.primitive.StringDt; import ca.uhn.fhir.rest.server.AddProfileTagEnum; import ca.uhn.fhir.util.ElementUtil; +import ca.uhn.fhir.util.TestUtil; public class CustomTypeDstu2Test { private static final FhirContext ourCtx = FhirContext.forDstu2(); private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(CustomTypeDstu2Test.class); + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + @Before public void before() { ourCtx.setAddProfileTagWhenEncoding(AddProfileTagEnum.ONLY_FOR_CUSTOM); diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/parser/EmptyElementWithExtensionDstu2Test.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/parser/EmptyElementWithExtensionDstu2Test.java index cfd226283dc..beb6fa3cc4d 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/parser/EmptyElementWithExtensionDstu2Test.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/parser/EmptyElementWithExtensionDstu2Test.java @@ -2,12 +2,14 @@ package ca.uhn.fhir.parser; import static org.junit.Assert.assertEquals; +import org.junit.AfterClass; import org.junit.Test; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.dstu2.composite.CodingDt; import ca.uhn.fhir.model.dstu2.resource.Observation; import ca.uhn.fhir.model.primitive.StringDt; +import ca.uhn.fhir.util.TestUtil; /** * Created by Bill de Beaubien on 12/20/2015. @@ -17,6 +19,12 @@ public class EmptyElementWithExtensionDstu2Test { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(EmptyElementWithExtensionDstu2Test.class); private static FhirContext ctx = FhirContext.forDstu2(); + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + @Test public void testNullFlavorCompositeJson() throws Exception { Observation observation = new Observation(); diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/parser/ExtensionsDstu2Test.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/parser/ExtensionsDstu2Test.java index 25c36875351..d40ad370382 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/parser/ExtensionsDstu2Test.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/parser/ExtensionsDstu2Test.java @@ -5,17 +5,25 @@ import static org.junit.Assert.assertEquals; import java.util.List; import org.apache.commons.io.IOUtils; +import org.junit.AfterClass; import org.junit.Test; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.api.ExtensionDt; import ca.uhn.fhir.model.dstu2.resource.Conformance; import ca.uhn.fhir.model.dstu2.resource.Conformance.RestSecurity; +import ca.uhn.fhir.util.TestUtil; public class ExtensionsDstu2Test { private static final FhirContext ourCtx = FhirContext.forDstu2(); - + + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + @Test public void testParseExtensions() throws Exception { String input = IOUtils.toString(getClass().getResourceAsStream("/smart-conf.xml")); 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 5bea761317c..977de2bf2c5 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 @@ -23,6 +23,7 @@ import java.util.UUID; import org.apache.commons.io.IOUtils; import org.hamcrest.Matchers; +import org.junit.AfterClass; import org.junit.Assert; import org.junit.Test; import org.mockito.ArgumentCaptor; @@ -68,6 +69,7 @@ import ca.uhn.fhir.model.primitive.InstantDt; import ca.uhn.fhir.model.primitive.StringDt; import ca.uhn.fhir.parser.IParserErrorHandler.IParseLocation; import ca.uhn.fhir.rest.server.Constants; +import ca.uhn.fhir.util.TestUtil; import net.sf.json.JSON; import net.sf.json.JSONSerializer; import net.sf.json.JsonConfig; @@ -76,6 +78,12 @@ public class JsonParserDstu2Test { private static final FhirContext ourCtx = FhirContext.forDstu2(); private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(JsonParserDstu2Test.class); + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + @Test public void testContainedResourceInExtensionUndeclared() { Patient p = new Patient(); diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/parser/RoundTripDstu2Test.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/parser/RoundTripDstu2Test.java index c61943629e9..7502afd0c9e 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/parser/RoundTripDstu2Test.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/parser/RoundTripDstu2Test.java @@ -17,15 +17,23 @@ import javax.xml.stream.events.XMLEvent; import org.custommonkey.xmlunit.DetailedDiff; import org.custommonkey.xmlunit.Diff; import org.hl7.fhir.instance.model.api.IBaseResource; +import org.junit.AfterClass; import org.junit.Test; import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.util.TestUtil; import ca.uhn.fhir.util.XmlUtil; public class RoundTripDstu2Test { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(RoundTripDstu2Test.class); private static FhirContext ourCtx = FhirContext.forDstu2(); + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + @Test public void testIt() { // Just so this doesn't complain until we enable roundtrip test diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/parser/XmlParserDstu2Test.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/parser/XmlParserDstu2Test.java index 1ef1552cae1..c2fcefe782a 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/parser/XmlParserDstu2Test.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/parser/XmlParserDstu2Test.java @@ -33,6 +33,7 @@ import org.hamcrest.collection.IsEmptyCollection; import org.hamcrest.core.StringContains; import org.hamcrest.text.StringContainsInOrder; import org.hl7.fhir.instance.model.api.IBaseResource; +import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import org.mockito.ArgumentCaptor; @@ -95,11 +96,18 @@ import ca.uhn.fhir.model.primitive.StringDt; import ca.uhn.fhir.parser.IParserErrorHandler.IParseLocation; import ca.uhn.fhir.rest.client.IGenericClient; import ca.uhn.fhir.rest.server.Constants; +import ca.uhn.fhir.util.TestUtil; public class XmlParserDstu2Test { private static final FhirContext ourCtx = FhirContext.forDstu2(); private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(XmlParserDstu2Test.class); + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + @Test public void testBundleWithBinary() { //@formatter:off diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/client/BundleTypeDstu2Test.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/client/BundleTypeDstu2Test.java index 9db25b3ce2a..ee21733e653 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/client/BundleTypeDstu2Test.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/client/BundleTypeDstu2Test.java @@ -18,6 +18,7 @@ import org.apache.http.message.BasicHeader; import org.apache.http.message.BasicStatusLine; import org.hamcrest.Matchers; import org.hl7.fhir.instance.model.api.IBaseResource; +import org.junit.AfterClass; import org.junit.Before; import org.junit.Test; import org.mockito.ArgumentCaptor; @@ -30,6 +31,7 @@ import ca.uhn.fhir.model.valueset.BundleTypeEnum; import ca.uhn.fhir.rest.client.interceptor.BearerTokenAuthInterceptor; import ca.uhn.fhir.rest.client.interceptor.LoggingInterceptor; import ca.uhn.fhir.rest.server.Constants; +import ca.uhn.fhir.util.TestUtil; public class BundleTypeDstu2Test { @@ -39,6 +41,12 @@ public class BundleTypeDstu2Test { private HttpResponse ourHttpResponse; + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + @Before public void before() { ourCtx = FhirContext.forDstu2(); diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/client/ClientMockingTest.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/client/ClientMockingTest.java index 28cdd123eb0..30c52c5c0c0 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/client/ClientMockingTest.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/client/ClientMockingTest.java @@ -4,6 +4,7 @@ import static org.junit.Assert.*; import static org.mockito.Mockito.*; import org.hl7.fhir.instance.model.api.IBaseBundle; +import org.junit.AfterClass; import org.junit.Test; import org.mockito.internal.stubbing.defaultanswers.ReturnsDeepStubs; import org.mockito.internal.stubbing.defaultanswers.ReturnsSmartNulls; @@ -12,9 +13,16 @@ import ca.uhn.fhir.model.dstu2.resource.Bundle; import ca.uhn.fhir.model.dstu2.resource.Condition; import ca.uhn.fhir.rest.gclient.ICriterion; import ca.uhn.fhir.rest.gclient.IQuery; +import ca.uhn.fhir.util.TestUtil; public class ClientMockingTest { + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + @SuppressWarnings("unchecked") @Test public void testMockingDeepStubs() { diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/client/ClientServerValidationTestDstu2.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/client/ClientServerValidationTestDstu2.java index 59abd7f9f6f..15dd008f31d 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/client/ClientServerValidationTestDstu2.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/client/ClientServerValidationTestDstu2.java @@ -19,6 +19,7 @@ import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpUriRequest; import org.apache.http.message.BasicHeader; import org.apache.http.message.BasicStatusLine; +import org.junit.AfterClass; import org.junit.Before; import org.junit.Test; import org.mockito.ArgumentCaptor; @@ -36,6 +37,7 @@ import ca.uhn.fhir.rest.client.exceptions.FhirClientInappropriateForServerExcept import ca.uhn.fhir.rest.client.interceptor.BasicAuthInterceptor; import ca.uhn.fhir.rest.server.Constants; import ca.uhn.fhir.rest.server.exceptions.AuthenticationException; +import ca.uhn.fhir.util.TestUtil; public class ClientServerValidationTestDstu2 { @@ -45,6 +47,12 @@ public class ClientServerValidationTestDstu2 { private HttpClient myHttpClient; private HttpResponse myHttpResponse; + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + @Before public void before() { myHttpClient = mock(HttpClient.class, new ReturnsDeepStubs()); diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/client/ClientWithProfileDstu2Test.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/client/ClientWithProfileDstu2Test.java index c6a01d966d3..8e353f811ed 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/client/ClientWithProfileDstu2Test.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/client/ClientWithProfileDstu2Test.java @@ -18,6 +18,7 @@ import org.apache.http.client.methods.HttpPost; import org.apache.http.client.methods.HttpUriRequest; import org.apache.http.message.BasicHeader; import org.apache.http.message.BasicStatusLine; +import org.junit.AfterClass; import org.junit.Before; import org.junit.Test; import org.mockito.ArgumentCaptor; @@ -31,6 +32,7 @@ import ca.uhn.fhir.model.dstu2.resource.OperationOutcome; import ca.uhn.fhir.model.dstu2.resource.Patient; import ca.uhn.fhir.model.dstu2.valueset.IssueTypeEnum; import ca.uhn.fhir.rest.server.Constants; +import ca.uhn.fhir.util.TestUtil; public class ClientWithProfileDstu2Test { @@ -39,6 +41,12 @@ public class ClientWithProfileDstu2Test { private HttpClient ourHttpClient; private HttpResponse ourHttpResponse; + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + @Before public void before() { ourCtx = FhirContext.forDstu2(); diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/client/ETagClientDstu2Test.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/client/ETagClientDstu2Test.java index 74b3e2e614d..64aa2110b74 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/client/ETagClientDstu2Test.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/client/ETagClientDstu2Test.java @@ -20,6 +20,7 @@ import org.apache.http.client.methods.HttpUriRequest; import org.apache.http.message.BasicHeader; import org.apache.http.message.BasicStatusLine; import org.hamcrest.core.StringContains; +import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; @@ -35,6 +36,7 @@ import ca.uhn.fhir.model.primitive.InstantDt; import ca.uhn.fhir.rest.server.Constants; import ca.uhn.fhir.rest.server.exceptions.NotModifiedException; import ca.uhn.fhir.rest.server.exceptions.PreconditionFailedException; +import ca.uhn.fhir.util.TestUtil; /** * Created by dsotnikov on 2/25/2014. @@ -46,6 +48,12 @@ public class ETagClientDstu2Test { private HttpResponse myHttpResponse; + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + @Before public void before() { diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/client/GenericClientDstu2Test.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/client/GenericClientDstu2Test.java index 81a0e895371..64328fcba07 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/client/GenericClientDstu2Test.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/client/GenericClientDstu2Test.java @@ -36,6 +36,7 @@ import org.hl7.fhir.instance.model.api.IBase; import org.hl7.fhir.instance.model.api.IBaseBundle; import org.hl7.fhir.instance.model.api.IBaseOperationOutcome; import org.hl7.fhir.instance.model.api.IBaseResource; +import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; @@ -78,6 +79,7 @@ import ca.uhn.fhir.rest.method.SearchStyleEnum; import ca.uhn.fhir.rest.param.DateRangeParam; import ca.uhn.fhir.rest.server.Constants; import ca.uhn.fhir.rest.server.EncodingEnum; +import ca.uhn.fhir.util.TestUtil; public class GenericClientDstu2Test { private static FhirContext ourCtx; @@ -89,6 +91,12 @@ public class GenericClientDstu2Test { private int myResponseCount = 0; + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + @Before public void before() { myHttpClient = mock(HttpClient.class, new ReturnsDeepStubs()); diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/client/OperationClientDstu2Test.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/client/OperationClientDstu2Test.java index 2a0227c4753..d4ca90a6bdd 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/client/OperationClientDstu2Test.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/client/OperationClientDstu2Test.java @@ -20,6 +20,7 @@ import org.apache.http.client.methods.HttpPost; import org.apache.http.client.methods.HttpUriRequest; import org.apache.http.message.BasicHeader; import org.apache.http.message.BasicStatusLine; +import org.junit.AfterClass; import org.junit.Before; import org.junit.Test; import org.mockito.ArgumentCaptor; @@ -38,6 +39,7 @@ import ca.uhn.fhir.rest.annotation.Operation; import ca.uhn.fhir.rest.annotation.OperationParam; import ca.uhn.fhir.rest.client.api.IBasicClient; import ca.uhn.fhir.rest.server.Constants; +import ca.uhn.fhir.util.TestUtil; public class OperationClientDstu2Test { @@ -47,6 +49,12 @@ public class OperationClientDstu2Test { private HttpResponse ourHttpResponse; + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + @Before public void before() { ourCtx = FhirContext.forDstu2(); diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/client/interceptor/CompressOutgoingContentInterceptorTest.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/client/interceptor/CompressOutgoingContentInterceptorTest.java index 39af449b633..ca8b6f0a86f 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/client/interceptor/CompressOutgoingContentInterceptorTest.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/client/interceptor/CompressOutgoingContentInterceptorTest.java @@ -26,6 +26,7 @@ import ca.uhn.fhir.rest.server.FifoMemoryPagingProvider; import ca.uhn.fhir.rest.server.IResourceProvider; import ca.uhn.fhir.rest.server.RestfulServer; import ca.uhn.fhir.util.PortUtil; +import ca.uhn.fhir.util.TestUtil; public class CompressOutgoingContentInterceptorTest { @@ -42,6 +43,7 @@ public class CompressOutgoingContentInterceptorTest { ourClient = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort); } + @Test public void testCreate() throws Exception { ourClient.registerInterceptor(new GZipContentInterceptor()); @@ -56,9 +58,11 @@ public class CompressOutgoingContentInterceptorTest { assertEquals("gzip", ourLastResponseEncoding); } + @AfterClass - public static void afterClass() throws Exception { + public static void afterClassClearContext() throws Exception { ourServer.stop(); + TestUtil.clearAllStaticFieldsForUnitTest(); } @BeforeClass diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/BinaryDstu2Test.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/BinaryDstu2Test.java index 78f99325ea2..4f838e076f1 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/BinaryDstu2Test.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/BinaryDstu2Test.java @@ -40,6 +40,7 @@ import ca.uhn.fhir.rest.annotation.ResourceParam; import ca.uhn.fhir.rest.annotation.Search; import ca.uhn.fhir.rest.api.MethodOutcome; import ca.uhn.fhir.util.PortUtil; +import ca.uhn.fhir.util.TestUtil; /** * Created by dsotnikov on 2/25/2014. @@ -56,6 +57,13 @@ public class BinaryDstu2Test { private static Server ourServer; + @AfterClass + public static void afterClassClearContext() throws Exception { + ourServer.stop(); + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + @Before public void before() { ourLast = null; @@ -207,11 +215,6 @@ public class BinaryDstu2Test { assertArrayEquals(new byte[] { 1, 2, 3, 4 }, bin.getContent()); } - @AfterClass - public static void afterClass() throws Exception { - ourServer.stop(); - } - @BeforeClass public static void beforeClass() throws Exception { ourPort = PortUtil.findFreePort(); 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 67e76ee64a3..62554ceac57 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 @@ -27,6 +27,7 @@ import ca.uhn.fhir.model.valueset.BundleTypeEnum; import ca.uhn.fhir.narrative.DefaultThymeleafNarrativeGenerator; import ca.uhn.fhir.rest.annotation.Search; import ca.uhn.fhir.util.PortUtil; +import ca.uhn.fhir.util.TestUtil; /** * Created by dsotnikov on 2/25/2014. @@ -56,9 +57,11 @@ public class BundleTypeInResponseTest { } + @AfterClass - public static void afterClass() throws Exception { + public static void afterClassClearContext() throws Exception { ourServer.stop(); + TestUtil.clearAllStaticFieldsForUnitTest(); } @BeforeClass diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/CompartmentDstu2Test.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/CompartmentDstu2Test.java index bcd1312565d..fb85ef1e736 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/CompartmentDstu2Test.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/CompartmentDstu2Test.java @@ -48,6 +48,7 @@ import ca.uhn.fhir.rest.annotation.ResourceParam; import ca.uhn.fhir.rest.annotation.Search; import ca.uhn.fhir.rest.api.MethodOutcome; import ca.uhn.fhir.util.PortUtil; +import ca.uhn.fhir.util.TestUtil; /** * Created by dsotnikov on 2/25/2014. @@ -62,6 +63,12 @@ public class CompartmentDstu2Test { private static FhirContext ourCtx = FhirContext.forDstu2(); private static IdDt ourLastId; + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + @Before public void before() { ourLastMethod = null; 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 1c717a77c73..d282eccaf86 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 @@ -38,6 +38,7 @@ import ca.uhn.fhir.rest.annotation.ResourceParam; import ca.uhn.fhir.rest.annotation.Search; import ca.uhn.fhir.rest.api.MethodOutcome; import ca.uhn.fhir.util.PortUtil; +import ca.uhn.fhir.util.TestUtil; /** * Created by dsotnikov on 2/25/2014. @@ -45,17 +46,16 @@ import ca.uhn.fhir.util.PortUtil; public class CreateConditionalTest { private static CloseableHttpClient ourClient; + private static FhirContext ourCtx = FhirContext.forDstu2(); private static String ourLastConditionalUrl; - private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(CreateConditionalTest.class); - private static int ourPort; - private static Server ourServer; private static IdDt ourLastId; private static IdDt ourLastIdParam; private static boolean ourLastRequestWasSearch; - private static FhirContext ourCtx = FhirContext.forDstu2(); - - + private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(CreateConditionalTest.class); + private static int ourPort; + private static Server ourServer; + @Before public void before() { ourLastId = null; @@ -64,6 +64,8 @@ public class CreateConditionalTest { ourLastRequestWasSearch = false; } + + @Test public void testCreateWithConditionalUrl() throws Exception { @@ -141,8 +143,9 @@ public class CreateConditionalTest { @AfterClass - public static void afterClass() throws Exception { + public static void afterClassClearContext() throws Exception { ourServer.stop(); + TestUtil.clearAllStaticFieldsForUnitTest(); } @@ -170,17 +173,6 @@ public class CreateConditionalTest { public static class PatientProvider implements IResourceProvider { - @Override - public Class getResourceType() { - return Patient.class; - } - - @Search - public List search(@OptionalParam(name="foo") StringDt theString) { - ourLastRequestWasSearch = true; - return new ArrayList(); - } - @Create() public MethodOutcome createPatient(@ResourceParam Patient thePatient, @ConditionalUrlParam String theConditional, @IdParam IdDt theIdParam) { ourLastConditionalUrl = theConditional; @@ -189,6 +181,17 @@ public class CreateConditionalTest { return new MethodOutcome(new IdDt("Patient/001/_history/002")); } + @Override + public Class getResourceType() { + return Patient.class; + } + + @Search + public List search(@OptionalParam(name="foo") StringDt theString) { + ourLastRequestWasSearch = true; + return new ArrayList(); + } + } } diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/DeleteDstu2Test.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/DeleteDstu2Test.java index a6281882368..306a1c786c8 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/DeleteDstu2Test.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/DeleteDstu2Test.java @@ -27,18 +27,18 @@ import ca.uhn.fhir.rest.annotation.Delete; import ca.uhn.fhir.rest.annotation.IdParam; import ca.uhn.fhir.rest.api.MethodOutcome; import ca.uhn.fhir.util.PortUtil; +import ca.uhn.fhir.util.TestUtil; public class DeleteDstu2Test { 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; private static boolean ourInvoked; + private static String ourLastConditionalUrl; + private static IdDt ourLastIdParam; + private static int ourPort; + private static Server ourServer; - - + @Before public void before() { ourLastConditionalUrl = null; @@ -46,6 +46,8 @@ public class DeleteDstu2Test { ourInvoked = false; } + + @Test public void testUpdateWithConditionalUrl() throws Exception { Patient patient = new Patient(); @@ -76,9 +78,11 @@ public class DeleteDstu2Test { assertNull(ourLastConditionalUrl); } + @AfterClass - public static void afterClass() throws Exception { + public static void afterClassClearContext() throws Exception { ourServer.stop(); + TestUtil.clearAllStaticFieldsForUnitTest(); } @@ -106,12 +110,6 @@ public class DeleteDstu2Test { public static class PatientProvider implements IResourceProvider { - @Override - public Class getResourceType() { - return Patient.class; - } - - @Delete() public MethodOutcome delete(@ConditionalUrlParam String theConditional, @IdParam IdDt theIdParam) { ourLastConditionalUrl = theConditional; @@ -120,6 +118,12 @@ public class DeleteDstu2Test { return new MethodOutcome(new IdDt("Patient/001/_history/002")); } + + @Override + public Class getResourceType() { + return Patient.class; + } + } } 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 39ef3855b42..df061e18d91 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 @@ -40,6 +40,7 @@ import ca.uhn.fhir.rest.annotation.Update; import ca.uhn.fhir.rest.api.MethodOutcome; import ca.uhn.fhir.rest.server.exceptions.PreconditionFailedException; import ca.uhn.fhir.util.PortUtil; +import ca.uhn.fhir.util.TestUtil; /** * Created by dsotnikov on 2/25/2014. @@ -47,12 +48,37 @@ import ca.uhn.fhir.util.PortUtil; public class ETagServerTest { private static CloseableHttpClient ourClient; + private static PoolingHttpClientConnectionManager ourConnectionManager; private static FhirContext ourCtx; + private static IdDt ourLastId; + private static Date ourLastModifiedDate; private static int ourPort; private static Server ourServer; - private static PoolingHttpClientConnectionManager ourConnectionManager; + + + @Before + public void before() throws IOException { + ourLastId = null; + } + + @Test + public void testAutomaticNotModified() throws Exception { + ourLastModifiedDate = new InstantDt("2012-11-25T02:34:45.2222Z").getValue(); + + HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/2"); + httpGet.addHeader(Constants.HEADER_IF_NONE_MATCH, "\"222\""); + HttpResponse status = ourClient.execute(httpGet); + try { + assertEquals(Constants.STATUS_HTTP_304_NOT_MODIFIED, status.getStatusLine().getStatusCode()); + } finally { + if (status.getEntity() != null) { + IOUtils.closeQuietly(status.getEntity().getContent()); + } + } + + } @Test public void testETagHeader() throws Exception { @@ -76,23 +102,6 @@ public class ETagServerTest { } } - @Test - public void testAutomaticNotModified() throws Exception { - ourLastModifiedDate = new InstantDt("2012-11-25T02:34:45.2222Z").getValue(); - - HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/2"); - httpGet.addHeader(Constants.HEADER_IF_NONE_MATCH, "\"222\""); - HttpResponse status = ourClient.execute(httpGet); - try { - assertEquals(Constants.STATUS_HTTP_304_NOT_MODIFIED, status.getStatusLine().getStatusCode()); - } finally { - if (status.getEntity() != null) { - IOUtils.closeQuietly(status.getEntity().getContent()); - } - } - - } - @Test public void testLastModifiedHeader() throws Exception { ourLastModifiedDate = new InstantDt("2012-11-25T02:34:45.2222Z").getValue(); @@ -117,32 +126,6 @@ public class ETagServerTest { } } - @Before - public void before() throws IOException { - ourLastId = null; - } - - @Test - public void testUpdateWithNoVersion() throws Exception { - Patient p = new Patient(); - p.setId("2"); - p.addIdentifier().setSystem("urn:system").setValue("001"); - String resBody = ourCtx.newXmlParser().encodeResourceToString(p); - - HttpPut http; - http = new HttpPut("http://localhost:" + ourPort + "/Patient/2"); - http.setEntity(new StringEntity(resBody, ContentType.create(Constants.CT_FHIR_XML, "UTF-8"))); - HttpResponse status = ourClient.execute(http); - try { - assertEquals(200, status.getStatusLine().getStatusCode()); - } finally { - if (status.getEntity() != null) { - IOUtils.closeQuietly(status.getEntity().getContent()); - } - } - - } - @Test public void testUpdateWithIfMatch() throws Exception { Patient p = new Patient(); @@ -187,9 +170,31 @@ public class ETagServerTest { } } + @Test + public void testUpdateWithNoVersion() throws Exception { + Patient p = new Patient(); + p.setId("2"); + p.addIdentifier().setSystem("urn:system").setValue("001"); + String resBody = ourCtx.newXmlParser().encodeResourceToString(p); + + HttpPut http; + http = new HttpPut("http://localhost:" + ourPort + "/Patient/2"); + http.setEntity(new StringEntity(resBody, ContentType.create(Constants.CT_FHIR_XML, "UTF-8"))); + HttpResponse status = ourClient.execute(http); + try { + assertEquals(200, status.getStatusLine().getStatusCode()); + } finally { + if (status.getEntity() != null) { + IOUtils.closeQuietly(status.getEntity().getContent()); + } + } + + } + @AfterClass - public static void afterClass() throws Exception { + public static void afterClassClearContext() throws Exception { ourServer.stop(); + TestUtil.clearAllStaticFieldsForUnitTest(); } @BeforeClass @@ -215,8 +220,6 @@ public class ETagServerTest { } - private static IdDt ourLastId; - public static class PatientProvider implements IResourceProvider { @Read(version = true) @@ -228,6 +231,11 @@ public class ETagServerTest { return patient; } + @Override + public Class getResourceType() { + return Patient.class; + } + @Update public MethodOutcome updatePatient(@IdParam IdDt theId, @ResourceParam Patient theResource) { ourLastId = theId; @@ -239,11 +247,6 @@ public class ETagServerTest { return new MethodOutcome(theId.withVersion(theId.getVersionIdPart() + "0")); } - @Override - public Class getResourceType() { - return Patient.class; - } - } } diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/ElementsParamTest.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/ElementsParamTest.java index b8c638baf64..29e385b89dd 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/ElementsParamTest.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/ElementsParamTest.java @@ -32,6 +32,7 @@ import ca.uhn.fhir.rest.annotation.Read; import ca.uhn.fhir.rest.annotation.Search; import ca.uhn.fhir.rest.api.SummaryEnum; import ca.uhn.fhir.util.PortUtil; +import ca.uhn.fhir.util.TestUtil; public class ElementsParamTest { @@ -47,6 +48,7 @@ public class ElementsParamTest { ourLastElements = null; } + @Test public void testReadSummaryData() throws Exception { HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/1?_elements=name,maritalStatus"); @@ -99,7 +101,6 @@ public class ElementsParamTest { assertThat(ourLastElements, containsInAnyOrder("name", "maritalStatus")); } - @Test public void testSearchSummaryText() throws Exception { HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?_elements=text"); @@ -117,9 +118,11 @@ public class ElementsParamTest { assertThat(ourLastElements, containsInAnyOrder("text")); } + @AfterClass - public static void afterClass() throws Exception { + public static void afterClassClearContext() throws Exception { ourServer.stop(); + TestUtil.clearAllStaticFieldsForUnitTest(); } @BeforeClass 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 98af0b55a13..741b4cf6ac0 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 @@ -31,6 +31,7 @@ import ca.uhn.fhir.model.dstu2.resource.Patient; import ca.uhn.fhir.rest.annotation.IncludeParam; import ca.uhn.fhir.rest.annotation.Search; import ca.uhn.fhir.util.PortUtil; +import ca.uhn.fhir.util.TestUtil; /** * Created by dsotnikov on 2/25/2014. @@ -38,19 +39,20 @@ import ca.uhn.fhir.util.PortUtil; public class IncludeAndRevincludeParameterTest { private static CloseableHttpClient ourClient; - private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(IncludeAndRevincludeParameterTest.class); - private static int ourPort; - private static Server ourServer; private static FhirContext ourCtx; private static Set ourIncludes; + private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(IncludeAndRevincludeParameterTest.class); + private static int ourPort; private static Set ourReverseIncludes; + private static Server ourServer; @Before public void before() { ourIncludes = null; ourReverseIncludes = null; } - + + @Test public void testNoIncludes() throws Exception { HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?_query=normalInclude"); @@ -62,7 +64,7 @@ public class IncludeAndRevincludeParameterTest { assertThat(ourIncludes, hasSize(0)); assertThat(ourReverseIncludes, hasSize(0)); } - + @Test public void testWithBoth() throws Exception { HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?_query=normalInclude&_include=A.a&_include=B.b&_revinclude=C.c&_revinclude=D.d"); @@ -77,9 +79,11 @@ public class IncludeAndRevincludeParameterTest { assertThat(ourReverseIncludes, containsInAnyOrder(new Include("C.c"), new Include("D.d"))); } + @AfterClass - public static void afterClass() throws Exception { + public static void afterClassClearContext() throws Exception { ourServer.stop(); + TestUtil.clearAllStaticFieldsForUnitTest(); } @BeforeClass @@ -107,6 +111,11 @@ public class IncludeAndRevincludeParameterTest { public static class DummyPatientResourceProvider implements IResourceProvider { + @Override + public Class getResourceType() { + return Patient.class; + } + @Search(queryName = "normalInclude") public List normalInclude( @IncludeParam() Set theIncludes, @@ -117,11 +126,6 @@ public class IncludeAndRevincludeParameterTest { return new ArrayList(); } - @Override - public Class getResourceType() { - return Patient.class; - } - } } 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 2fda41bde60..be93926db82 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 @@ -45,6 +45,7 @@ import ca.uhn.fhir.rest.annotation.RequiredParam; import ca.uhn.fhir.rest.annotation.Search; import ca.uhn.fhir.util.ElementUtil; import ca.uhn.fhir.util.PortUtil; +import ca.uhn.fhir.util.TestUtil; /** * Created by dsotnikov on 2/25/2014. @@ -52,80 +53,18 @@ import ca.uhn.fhir.util.PortUtil; public class IncludeDstu2Test { private static CloseableHttpClient ourClient; + private static FhirContext ourCtx; private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(IncludeDstu2Test.class); private static int ourPort; private static Server ourServer; - private static FhirContext ourCtx; @Test - public void testNoIncludes() throws Exception { - HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?name=Hello"); + public void testBadInclude() throws Exception { + HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?name=Hello&_include=foo&_include=baz"); 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(1, bundle.size()); - - Patient p = bundle.getResources(Patient.class).get(0); - assertEquals(0, p.getName().size()); - assertEquals("Hello", p.getId().getIdPart()); + assertEquals(400, status.getStatusLine().getStatusCode()); } - @Test - public void testOneIncludeXml() throws Exception { - HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?name=Hello&_include=foo"); - HttpResponse status = ourClient.execute(httpGet); - String responseContent = IOUtils.toString(status.getEntity().getContent()); - IOUtils.closeQuietly(status.getEntity().getContent()); - - assertEquals(200, status.getStatusLine().getStatusCode()); - - ourLog.info(responseContent); - - Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent); - assertEquals(1, bundle.size()); - - Patient p = bundle.getResources(Patient.class).get(0); - assertEquals(1, p.getName().size()); - assertEquals("Hello", p.getId().getIdPart()); - assertEquals("foo", p.getName().get(0).getFamilyFirstRep().getValue()); - } - - @Test - public void testOneIncludeJson() throws Exception { - HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?name=Hello&_include=foo&_format=json"); - HttpResponse status = ourClient.execute(httpGet); - String responseContent = IOUtils.toString(status.getEntity().getContent()); - IOUtils.closeQuietly(status.getEntity().getContent()); - - assertEquals(200, status.getStatusLine().getStatusCode()); - - ourLog.info(responseContent); - - Bundle bundle = ourCtx.newJsonParser().parseBundle(responseContent); - assertEquals(1, bundle.size()); - - Patient p = bundle.getResources(Patient.class).get(0); - assertEquals(1, p.getName().size()); - assertEquals("Hello", p.getId().getIdPart()); - assertEquals("foo", p.getName().get(0).getFamilyFirstRep().getValue()); - } - - // @Test - public void testMixedContainedAndNonContained() throws Exception { - HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/DiagnosticReport?_query=stitchedInclude&_pretty=true"); - HttpResponse status = ourClient.execute(httpGet); - String responseContent = IOUtils.toString(status.getEntity().getContent()); - 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 { @@ -153,6 +92,34 @@ public class IncludeDstu2Test { } + @Test + public void testIIncludedResourcesNonContainedInDeclaredExtension() throws Exception { + HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?_query=declaredExtInclude&_pretty=true"); + 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); + + 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()); + assertEquals(BundleEntrySearchModeEnum.INCLUDE, bundle.getEntries().get(2).getSearchMode().getValueAsEnum()); + assertEquals(BundleEntrySearchModeEnum.INCLUDE, bundle.getEntries().get(3).getSearchMode().getValueAsEnum()); + + 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"); @@ -205,32 +172,74 @@ public class IncludeDstu2Test { } + // @Test + public void testMixedContainedAndNonContained() throws Exception { + HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/DiagnosticReport?_query=stitchedInclude&_pretty=true"); + HttpResponse status = ourClient.execute(httpGet); + String responseContent = IOUtils.toString(status.getEntity().getContent()); + 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 testIIncludedResourcesNonContainedInDeclaredExtension() throws Exception { - HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?_query=declaredExtInclude&_pretty=true"); + public void testNoIncludes() throws Exception { + HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?name=Hello"); 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(1, bundle.size()); + + Patient p = bundle.getResources(Patient.class).get(0); + assertEquals(0, p.getName().size()); + assertEquals("Hello", p.getId().getIdPart()); + } + + @Test + public void testOneIncludeJson() throws Exception { + HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?name=Hello&_include=foo&_format=json"); + HttpResponse status = ourClient.execute(httpGet); + String responseContent = IOUtils.toString(status.getEntity().getContent()); + IOUtils.closeQuietly(status.getEntity().getContent()); + + assertEquals(200, status.getStatusLine().getStatusCode()); 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()); - assertEquals(BundleEntrySearchModeEnum.INCLUDE, bundle.getEntries().get(2).getSearchMode().getValueAsEnum()); - assertEquals(BundleEntrySearchModeEnum.INCLUDE, bundle.getEntries().get(3).getSearchMode().getValueAsEnum()); + Bundle bundle = ourCtx.newJsonParser().parseBundle(responseContent); + assertEquals(1, bundle.size()); - Patient p1 = (Patient) bundle.toListOfResources().get(0); - assertEquals(0, p1.getContained().getContainedResources().size()); + Patient p = bundle.getResources(Patient.class).get(0); + assertEquals(1, p.getName().size()); + assertEquals("Hello", p.getId().getIdPart()); + assertEquals("foo", p.getName().get(0).getFamilyFirstRep().getValue()); + } - Patient p2 = (Patient) bundle.toListOfResources().get(1); - assertEquals(0, p2.getContained().getContainedResources().size()); + @Test + public void testOneIncludeXml() throws Exception { + HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?name=Hello&_include=foo"); + HttpResponse status = ourClient.execute(httpGet); + String responseContent = IOUtils.toString(status.getEntity().getContent()); + IOUtils.closeQuietly(status.getEntity().getContent()); + assertEquals(200, status.getStatusLine().getStatusCode()); + + ourLog.info(responseContent); + + Bundle bundle = ourCtx.newXmlParser().parseBundle(responseContent); + assertEquals(1, bundle.size()); + + Patient p = bundle.getResources(Patient.class).get(0); + assertEquals(1, p.getName().size()); + assertEquals("Hello", p.getId().getIdPart()); + assertEquals("foo", p.getName().get(0).getFamilyFirstRep().getValue()); } @Test @@ -257,16 +266,11 @@ public class IncludeDstu2Test { } - @Test - public void testBadInclude() throws Exception { - HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?name=Hello&_include=foo&_include=baz"); - HttpResponse status = ourClient.execute(httpGet); - assertEquals(400, status.getStatusLine().getStatusCode()); - } @AfterClass - public static void afterClass() throws Exception { + public static void afterClassClearContext() throws Exception { ourServer.stop(); + TestUtil.clearAllStaticFieldsForUnitTest(); } @BeforeClass @@ -294,30 +298,6 @@ public class IncludeDstu2Test { } - @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 - public boolean isEmpty() { - return super.isEmpty() && ElementUtil.isEmpty(mySecondOrg); - } - - public ResourceReferenceDt getSecondOrg() { - if (mySecondOrg == null) { - mySecondOrg = new ResourceReferenceDt(); - } - return mySecondOrg; - } - - public void setSecondOrg(ResourceReferenceDt theSecondOrg) { - mySecondOrg = theSecondOrg; - } - - } - /** * Created by dsotnikov on 2/25/2014. */ @@ -371,11 +351,10 @@ public class IncludeDstu2Test { */ public static class DummyPatientResourceProvider implements IResourceProvider { - @Search(queryName = "normalInclude") - public List normalInclude() { + @Search(queryName = "containedInclude") + public List containedInclude() { Organization o1 = new Organization(); o1.getNameElement().setValue("o1"); - o1.setId("o1"); Patient p1 = new Patient(); p1.setId("p1"); @@ -390,25 +369,6 @@ public class IncludeDstu2Test { return Arrays.asList(p1, p2); } - @Search(queryName = "extInclude") - public List extInclude() { - Organization o1 = new Organization(); - o1.getNameElement().setValue("o1"); - o1.setId("o1"); - - Patient p1 = new Patient(); - p1.setId("p1"); - p1.addIdentifier().setValue("p1"); - p1.addUndeclaredExtension(false, "http://foo", new ResourceReferenceDt(o1)); - - Patient p2 = new Patient(); - p2.setId("p2"); - p2.addIdentifier().setValue("p2"); - p2.addUndeclaredExtension(false, "http://foo", new ResourceReferenceDt(o1)); - - return Arrays.asList(p1, p2); - } - @Search(queryName = "declaredExtInclude") public List declaredExtInclude() { Organization o1 = new Organization(); @@ -433,20 +393,21 @@ public class IncludeDstu2Test { return Arrays.asList(p1, p2); } - @Search(queryName = "containedInclude") - public List containedInclude() { + @Search(queryName = "extInclude") + public List extInclude() { Organization o1 = new Organization(); o1.getNameElement().setValue("o1"); + o1.setId("o1"); Patient p1 = new Patient(); p1.setId("p1"); p1.addIdentifier().setValue("p1"); - p1.getManagingOrganization().setResource(o1); + p1.addUndeclaredExtension(false, "http://foo", new ResourceReferenceDt(o1)); Patient p2 = new Patient(); p2.setId("p2"); p2.addIdentifier().setValue("p2"); - p2.getManagingOrganization().setResource(o1); + p2.addUndeclaredExtension(false, "http://foo", new ResourceReferenceDt(o1)); return Arrays.asList(p1, p2); } @@ -475,6 +436,49 @@ public class IncludeDstu2Test { return Patient.class; } + @Search(queryName = "normalInclude") + public List normalInclude() { + Organization o1 = new Organization(); + o1.getNameElement().setValue("o1"); + o1.setId("o1"); + + Patient p1 = new Patient(); + p1.setId("p1"); + p1.addIdentifier().setValue("p1"); + p1.getManagingOrganization().setResource(o1); + + Patient p2 = new Patient(); + p2.setId("p2"); + p2.addIdentifier().setValue("p2"); + p2.getManagingOrganization().setResource(o1); + + return Arrays.asList(p1, p2); + } + + } + + @ResourceDef(name = "Patient") + public static class ExtPatient extends Patient { + @Child(name = "secondOrg") + @Extension(url = "http://foo#secondOrg", definedLocally = false, isModifier = false) + private ResourceReferenceDt mySecondOrg; + + public ResourceReferenceDt getSecondOrg() { + if (mySecondOrg == null) { + mySecondOrg = new ResourceReferenceDt(); + } + return mySecondOrg; + } + + @Override + public boolean isEmpty() { + return super.isEmpty() && ElementUtil.isEmpty(mySecondOrg); + } + + public void setSecondOrg(ResourceReferenceDt theSecondOrg) { + mySecondOrg = theSecondOrg; + } + } } diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/OperationDuplicateServerDstu2Test.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/OperationDuplicateServerDstu2Test.java index 95dd2d80ae9..f8709196ad3 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/OperationDuplicateServerDstu2Test.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/OperationDuplicateServerDstu2Test.java @@ -30,6 +30,7 @@ import ca.uhn.fhir.model.primitive.StringDt; import ca.uhn.fhir.rest.annotation.Operation; import ca.uhn.fhir.rest.annotation.OperationParam; import ca.uhn.fhir.util.PortUtil; +import ca.uhn.fhir.util.TestUtil; public class OperationDuplicateServerDstu2Test { private static CloseableHttpClient ourClient; @@ -76,9 +77,12 @@ public class OperationDuplicateServerDstu2Test { } } + + @AfterClass - public static void afterClass() throws Exception { + public static void afterClassClearContext() throws Exception { ourServer.stop(); + TestUtil.clearAllStaticFieldsForUnitTest(); } @BeforeClass diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/OperationServerDstu2Test.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/OperationServerDstu2Test.java index a66ec0469f3..cc261a1af02 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/OperationServerDstu2Test.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/OperationServerDstu2Test.java @@ -48,21 +48,22 @@ import ca.uhn.fhir.rest.annotation.OperationParam; import ca.uhn.fhir.rest.annotation.Read; import ca.uhn.fhir.rest.client.IGenericClient; import ca.uhn.fhir.util.PortUtil; +import ca.uhn.fhir.util.TestUtil; public class OperationServerDstu2Test { private static CloseableHttpClient ourClient; private static FhirContext ourCtx; + private static IdDt ourLastId; + private static String ourLastMethod; private static StringDt ourLastParam1; private static Patient ourLastParam2; + private static List ourLastParam3; + private static MoneyDt ourLastParamMoney1; + private static UnsignedIntDt ourLastParamUnsignedInt1; private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(OperationServerDstu2Test.class); private static int ourPort; - private static IdDt ourLastId; private static Server ourServer; - private static String ourLastMethod; - private static List ourLastParam3; - private static UnsignedIntDt ourLastParamUnsignedInt1; - private static MoneyDt ourLastParamMoney1; @Before public void before() { @@ -75,22 +76,54 @@ public class OperationServerDstu2Test { ourLastMethod = ""; } - public static void main(String[] theValue) { - Parameters p = new Parameters(); - p.addParameter().setName("start").setValue(new DateTimeDt("2001-01-02")); - p.addParameter().setName("end").setValue(new DateTimeDt("2015-07-10")); - String inParamsStr = FhirContext.forDstu2().newXmlParser().encodeResourceToString(p); - ourLog.info(inParamsStr.replace("\"", "\\\"")); + + @Test + public void testConformance() throws Exception { + IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort); + Conformance p = client.fetchConformance().ofType(Conformance.class).execute(); + List ops = p.getRest().get(0).getOperation(); + assertThat(ops.size(), greaterThan(1)); + assertNull(ops.get(0).getDefinition().getReference().getBaseUrl()); + assertThat(ops.get(0).getDefinition().getReference().getValue(), startsWith("OperationDefinition/")); + + OperationDefinition def = client.read().resource(OperationDefinition.class).withId(ops.get(0).getDefinition().getReference()).execute(); + assertThat(def.getCode(), not(blankOrNullString())); + } + + @Test + public void testInstanceEverythingGet() throws Exception { + + // Try with a GET + HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/123/$everything"); + CloseableHttpResponse status = ourClient.execute(httpGet); + + assertEquals(200, status.getStatusLine().getStatusCode()); + String response = IOUtils.toString(status.getEntity().getContent()); + IOUtils.closeQuietly(status.getEntity().getContent()); + + assertEquals("instance $everything", ourLastMethod); + assertThat(response, startsWith(" ops = p.getRest().get(0).getOperation(); - assertThat(ops.size(), greaterThan(1)); - assertNull(ops.get(0).getDefinition().getReference().getBaseUrl()); - assertThat(ops.get(0).getDefinition().getReference().getValue(), startsWith("OperationDefinition/")); - - OperationDefinition def = client.read().resource(OperationDefinition.class).withId(ops.get(0).getDefinition().getReference()).execute(); - assertThat(def.getCode(), not(blankOrNullString())); - } - - @Test - public void testInstanceEverythingGet() throws Exception { - - // Try with a GET - HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/123/$everything"); - CloseableHttpResponse status = ourClient.execute(httpGet); - - assertEquals(200, status.getStatusLine().getStatusCode()); - String response = IOUtils.toString(status.getEntity().getContent()); - IOUtils.closeQuietly(status.getEntity().getContent()); - - assertEquals("instance $everything", ourLastMethod); - assertThat(response, startsWith(" getResourceType() { + return Patient.class; + } + + //@formatter:off + @Operation(name="$OP_INSTANCE") + public Parameters opInstance( + @IdParam IdDt theId, + @OperationParam(name="PARAM1") StringDt theParam1, + @OperationParam(name="PARAM2") Patient theParam2 + ) { + //@formatter:on + + ourLastMethod = "$OP_INSTANCE"; + ourLastId = theId; + ourLastParam1 = theParam1; + ourLastParam2 = theParam2; + + Parameters retVal = new Parameters(); + retVal.addParameter().setName("RET1").setValue(new StringDt("RETVAL1")); + return retVal; + } + + //@formatter:off + @Operation(name="$OP_INSTANCE_OR_TYPE") + public Parameters opInstanceOrType( + @IdParam(optional=true) IdDt theId, + @OperationParam(name="PARAM1") StringDt theParam1, + @OperationParam(name="PARAM2") Patient theParam2 + ) { + //@formatter:on + + ourLastMethod = "$OP_INSTANCE_OR_TYPE"; + ourLastId = theId; + ourLastParam1 = theParam1; + ourLastParam2 = theParam2; + + Parameters retVal = new Parameters(); + retVal.addParameter().setName("RET1").setValue(new StringDt("RETVAL1")); + return retVal; + } + + //@formatter:off + @Operation(name="$OP_PROFILE_DT2", idempotent=true) + public Bundle opProfileDt( + @OperationParam(name="PARAM1") MoneyDt theParam1 + ) { + //@formatter:on + + ourLastMethod = "$OP_PROFILE_DT2"; + ourLastParamMoney1 = theParam1; + + Bundle retVal = new Bundle(); + retVal.addEntry().getResponse().setStatus("100"); + return retVal; + } + + //@formatter:off + @Operation(name="$OP_PROFILE_DT", idempotent=true) + public Bundle opProfileDt( + @OperationParam(name="PARAM1") UnsignedIntDt theParam1 + ) { + //@formatter:on + + ourLastMethod = "$OP_PROFILE_DT"; + ourLastParamUnsignedInt1 = theParam1; + + Bundle retVal = new Bundle(); + retVal.addEntry().getResponse().setStatus("100"); + return retVal; + } + + //@formatter:off + @Operation(name="$OP_TYPE", idempotent=true) + public Parameters opType( + @OperationParam(name="PARAM1") StringDt theParam1, + @OperationParam(name="PARAM2") Patient theParam2 + ) { + //@formatter:on + + ourLastMethod = "$OP_TYPE"; + ourLastParam1 = theParam1; + ourLastParam2 = theParam2; + + Parameters retVal = new Parameters(); + retVal.addParameter().setName("RET1").setValue(new StringDt("RETVAL1")); + return retVal; + } + + //@formatter:off + @Operation(name="$OP_TYPE_ONLY_STRING", idempotent=true) + public Parameters opTypeOnlyString( + @OperationParam(name="PARAM1") StringDt theParam1 + ) { + //@formatter:on + + ourLastMethod = "$OP_TYPE"; + ourLastParam1 = theParam1; + + Parameters retVal = new Parameters(); + retVal.addParameter().setName("RET1").setValue(new StringDt("RETVAL1")); + return retVal; + } + + //@formatter:off + @Operation(name="$OP_TYPE_RET_BUNDLE") + public Bundle opTypeRetBundle( + @OperationParam(name="PARAM1") StringDt theParam1, + @OperationParam(name="PARAM2") Patient theParam2 + ) { + //@formatter:on + + ourLastMethod = "$OP_TYPE_RET_BUNDLE"; + ourLastParam1 = theParam1; + ourLastParam2 = theParam2; + + Bundle retVal = new Bundle(); + retVal.addEntry().getResponse().setStatus("100"); + return retVal; + } + + @Operation(name = "$everything", idempotent=true) + public Bundle patientEverything(@IdParam IdDt thePatientId) { + ourLastMethod = "instance $everything"; + ourLastId = thePatientId; + return new Bundle(); + } + + /** + * Just to make sure this method doesn't "steal" calls + */ + @Read + public Patient read(@IdParam IdDt theId) { + ourLastMethod = "read"; + Patient retVal = new Patient(); + retVal.setId(theId); + return retVal; + } + + } + public static class PlainProvider { //@formatter:off @@ -552,148 +700,4 @@ public class OperationServerDstu2Test { } - public static class PatientProvider implements IResourceProvider { - - @Override - public Class getResourceType() { - return Patient.class; - } - - /** - * Just to make sure this method doesn't "steal" calls - */ - @Read - public Patient read(@IdParam IdDt theId) { - ourLastMethod = "read"; - Patient retVal = new Patient(); - retVal.setId(theId); - return retVal; - } - - @Operation(name = "$everything", idempotent=true) - public Bundle patientEverything(@IdParam IdDt thePatientId) { - ourLastMethod = "instance $everything"; - ourLastId = thePatientId; - return new Bundle(); - } - - //@formatter:off - @Operation(name="$OP_TYPE", idempotent=true) - public Parameters opType( - @OperationParam(name="PARAM1") StringDt theParam1, - @OperationParam(name="PARAM2") Patient theParam2 - ) { - //@formatter:on - - ourLastMethod = "$OP_TYPE"; - ourLastParam1 = theParam1; - ourLastParam2 = theParam2; - - Parameters retVal = new Parameters(); - retVal.addParameter().setName("RET1").setValue(new StringDt("RETVAL1")); - return retVal; - } - - //@formatter:off - @Operation(name="$OP_TYPE_ONLY_STRING", idempotent=true) - public Parameters opTypeOnlyString( - @OperationParam(name="PARAM1") StringDt theParam1 - ) { - //@formatter:on - - ourLastMethod = "$OP_TYPE"; - ourLastParam1 = theParam1; - - Parameters retVal = new Parameters(); - retVal.addParameter().setName("RET1").setValue(new StringDt("RETVAL1")); - return retVal; - } - - //@formatter:off - @Operation(name="$OP_TYPE_RET_BUNDLE") - public Bundle opTypeRetBundle( - @OperationParam(name="PARAM1") StringDt theParam1, - @OperationParam(name="PARAM2") Patient theParam2 - ) { - //@formatter:on - - ourLastMethod = "$OP_TYPE_RET_BUNDLE"; - ourLastParam1 = theParam1; - ourLastParam2 = theParam2; - - Bundle retVal = new Bundle(); - retVal.addEntry().getResponse().setStatus("100"); - return retVal; - } - - //@formatter:off - @Operation(name="$OP_PROFILE_DT", idempotent=true) - public Bundle opProfileDt( - @OperationParam(name="PARAM1") UnsignedIntDt theParam1 - ) { - //@formatter:on - - ourLastMethod = "$OP_PROFILE_DT"; - ourLastParamUnsignedInt1 = theParam1; - - Bundle retVal = new Bundle(); - retVal.addEntry().getResponse().setStatus("100"); - return retVal; - } - - //@formatter:off - @Operation(name="$OP_PROFILE_DT2", idempotent=true) - public Bundle opProfileDt( - @OperationParam(name="PARAM1") MoneyDt theParam1 - ) { - //@formatter:on - - ourLastMethod = "$OP_PROFILE_DT2"; - ourLastParamMoney1 = theParam1; - - Bundle retVal = new Bundle(); - retVal.addEntry().getResponse().setStatus("100"); - return retVal; - } - - //@formatter:off - @Operation(name="$OP_INSTANCE") - public Parameters opInstance( - @IdParam IdDt theId, - @OperationParam(name="PARAM1") StringDt theParam1, - @OperationParam(name="PARAM2") Patient theParam2 - ) { - //@formatter:on - - ourLastMethod = "$OP_INSTANCE"; - ourLastId = theId; - ourLastParam1 = theParam1; - ourLastParam2 = theParam2; - - Parameters retVal = new Parameters(); - retVal.addParameter().setName("RET1").setValue(new StringDt("RETVAL1")); - return retVal; - } - - //@formatter:off - @Operation(name="$OP_INSTANCE_OR_TYPE") - public Parameters opInstanceOrType( - @IdParam(optional=true) IdDt theId, - @OperationParam(name="PARAM1") StringDt theParam1, - @OperationParam(name="PARAM2") Patient theParam2 - ) { - //@formatter:on - - ourLastMethod = "$OP_INSTANCE_OR_TYPE"; - ourLastId = theId; - ourLastParam1 = theParam1; - ourLastParam2 = theParam2; - - Parameters retVal = new Parameters(); - retVal.addParameter().setName("RET1").setValue(new StringDt("RETVAL1")); - return retVal; - } - - } - } diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/OperationServerWithSearchParamTypesDstu2Test.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/OperationServerWithSearchParamTypesDstu2Test.java index 6b9250d5762..fd6cb681cd0 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/OperationServerWithSearchParamTypesDstu2Test.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/OperationServerWithSearchParamTypesDstu2Test.java @@ -50,6 +50,7 @@ import ca.uhn.fhir.rest.param.TokenParam; import ca.uhn.fhir.rest.param.TokenParamModifier; import ca.uhn.fhir.rest.server.provider.dstu2.ServerConformanceProvider; import ca.uhn.fhir.util.PortUtil; +import ca.uhn.fhir.util.TestUtil; import ca.uhn.fhir.util.UrlUtil; public class OperationServerWithSearchParamTypesDstu2Test { @@ -70,6 +71,7 @@ public class OperationServerWithSearchParamTypesDstu2Test { ourLastParamValTok = null; } + private HttpServletRequest createHttpServletRequest() { HttpServletRequest req = mock(HttpServletRequest.class); when(req.getRequestURI()).thenReturn("/FhirStorm/fhir/Patient/_search"); @@ -324,8 +326,9 @@ public class OperationServerWithSearchParamTypesDstu2Test { } @AfterClass - public static void afterClass() throws Exception { + public static void afterClassClearContext() throws Exception { ourServer.stop(); + TestUtil.clearAllStaticFieldsForUnitTest(); } @BeforeClass 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 c99bf5eb648..c6bb81d9fb4 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 @@ -35,39 +35,17 @@ import ca.uhn.fhir.rest.annotation.ResourceParam; import ca.uhn.fhir.rest.annotation.Update; import ca.uhn.fhir.rest.api.MethodOutcome; import ca.uhn.fhir.util.PortUtil; +import ca.uhn.fhir.util.TestUtil; public class PreferTest { private static CloseableHttpClient ourClient; + private static FhirContext ourCtx = FhirContext.forDstu2(); 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 - public void testCreateWithNoPrefer() throws Exception { - Patient patient = new Patient(); - patient.addIdentifier().setValue("002"); - - HttpPost httpPost = new HttpPost("http://localhost:" + ourPort + "/Patient"); - httpPost.setEntity(new StringEntity(ourCtx.newXmlParser().encodeResourceToString(patient), ContentType.create(Constants.CT_FHIR_XML, "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 + "/Patient/001/_history/002", status.getFirstHeader("location").getValue()); - assertEquals("http://localhost:" + ourPort + "/Patient/001/_history/002", status.getFirstHeader("content-location").getValue()); - - } - - @Test public void testCreatePreferMinimal() throws Exception { @@ -93,6 +71,7 @@ public class PreferTest { } + @Test public void testCreatePreferRepresentation() throws Exception { @@ -119,9 +98,33 @@ public class PreferTest { } + @Test + public void testCreateWithNoPrefer() throws Exception { + + Patient patient = new Patient(); + patient.addIdentifier().setValue("002"); + + HttpPost httpPost = new HttpPost("http://localhost:" + ourPort + "/Patient"); + httpPost.setEntity(new StringEntity(ourCtx.newXmlParser().encodeResourceToString(patient), ContentType.create(Constants.CT_FHIR_XML, "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 + "/Patient/001/_history/002", status.getFirstHeader("location").getValue()); + assertEquals("http://localhost:" + ourPort + "/Patient/001/_history/002", status.getFirstHeader("content-location").getValue()); + + } + + @AfterClass - public static void afterClass() throws Exception { + public static void afterClassClearContext() throws Exception { ourServer.stop(); + TestUtil.clearAllStaticFieldsForUnitTest(); } @@ -149,11 +152,6 @@ public class PreferTest { public static class PatientProvider implements IResourceProvider { - @Override - public Class getResourceType() { - return Patient.class; - } - @Create() public MethodOutcome createPatient(@ResourceParam Patient thePatient) { IdDt id = new IdDt("Patient/001/_history/002"); @@ -166,6 +164,11 @@ public class PreferTest { return retVal; } + @Override + public Class getResourceType() { + return Patient.class; + } + @Update() public MethodOutcome updatePatient(@ResourceParam Patient thePatient, @IdParam IdDt theIdParam) { IdDt id = new IdDt("Patient/001/_history/002"); diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/ReadDstu2Test.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/ReadDstu2Test.java index 4dd09c4081e..28b92861998 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/ReadDstu2Test.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/ReadDstu2Test.java @@ -34,17 +34,18 @@ import ca.uhn.fhir.rest.server.AddProfileTagEnum; import ca.uhn.fhir.rest.server.IResourceProvider; import ca.uhn.fhir.rest.server.RestfulServer; import ca.uhn.fhir.util.PortUtil; +import ca.uhn.fhir.util.TestUtil; public class ReadDstu2Test { private static CloseableHttpClient ourClient; private static FhirContext ourCtx = FhirContext.forDstu2(); private static boolean ourInitializeProfileList; + private static IdDt ourLastId; private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ReadDstu2Test.class); private static int ourPort; private static Server ourServer; private static RestfulServer ourServlet; - private static IdDt ourLastId; @Before public void before() { @@ -53,6 +54,7 @@ public class ReadDstu2Test { ourLastId = null; } + /** * See #302 */ @@ -75,27 +77,6 @@ public class ReadDstu2Test { assertEquals("Patient/123", ourLastId.getValue()); } - @Test - public void testVread() throws Exception { - ourCtx.setAddProfileTagWhenEncoding(AddProfileTagEnum.ONLY_FOR_CUSTOM); - - HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/123/_history/1"); - HttpResponse status = ourClient.execute(httpGet); - String responseContent = IOUtils.toString(status.getEntity().getContent()); - IOUtils.closeQuietly(status.getEntity().getContent()); - - assertEquals(200, status.getStatusLine().getStatusCode()); - assertThat(responseContent, containsString("p1ReadValue")); - assertThat(responseContent, containsString("p1ReadId")); - assertEquals("", responseContent); - - ourLog.info(responseContent); - - assertEquals("Patient/123/_history/1", ourLastId.getValue()); - assertEquals("123", ourLastId.getIdPart()); - assertEquals("1", ourLastId.getVersionIdPart()); - } - /** * See #302 and #268 */ @@ -116,7 +97,7 @@ public class ReadDstu2Test { assertThat(responseContent, containsString("p1ReadId")); assertEquals("", responseContent); } - + /** * In DSTU2+ the resource ID appears in the resource body */ @@ -135,7 +116,7 @@ public class ReadDstu2Test { assertThat(responseContent, containsString("p1ReadId")); assertThat(responseContent, containsString("\"meta\":{\"profile\":[\"http://foo_profile\"]}")); } - + /** * In DSTU2+ the resource ID appears in the resource body */ @@ -152,10 +133,32 @@ public class ReadDstu2Test { ourLog.info(responseContent); } + + @Test + public void testVread() throws Exception { + ourCtx.setAddProfileTagWhenEncoding(AddProfileTagEnum.ONLY_FOR_CUSTOM); + + HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/123/_history/1"); + HttpResponse status = ourClient.execute(httpGet); + String responseContent = IOUtils.toString(status.getEntity().getContent()); + IOUtils.closeQuietly(status.getEntity().getContent()); + + assertEquals(200, status.getStatusLine().getStatusCode()); + assertThat(responseContent, containsString("p1ReadValue")); + assertThat(responseContent, containsString("p1ReadId")); + assertEquals("", responseContent); + + ourLog.info(responseContent); + + assertEquals("Patient/123/_history/1", ourLastId.getValue()); + assertEquals("123", ourLastId.getIdPart()); + assertEquals("1", ourLastId.getVersionIdPart()); + } @AfterClass - public static void afterClass() throws Exception { + public static void afterClassClearContext() throws Exception { ourServer.stop(); + TestUtil.clearAllStaticFieldsForUnitTest(); } @BeforeClass 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 f44aaf71fc9..e5fcf976d29 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 @@ -49,19 +49,20 @@ import ca.uhn.fhir.rest.param.ReferenceParam; import ca.uhn.fhir.rest.param.StringParam; import ca.uhn.fhir.util.PatternMatcher; import ca.uhn.fhir.util.PortUtil; +import ca.uhn.fhir.util.TestUtil; public class SearchDstu2Test { private static CloseableHttpClient ourClient; private static FhirContext ourCtx = FhirContext.forDstu2(); + private static DateAndListParam ourLastDateAndList; + private static String ourLastMethod; + private static QuantityParam ourLastQuantity; + private static ReferenceParam ourLastRef; private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(SearchDstu2Test.class); private static int ourPort; private static InstantDt ourReturnPublished; private static Server ourServer; - private static String ourLastMethod; - private static DateAndListParam ourLastDateAndList; - private static ReferenceParam ourLastRef; - private static QuantityParam ourLastQuantity; @Before public void before() { @@ -71,9 +72,69 @@ public class SearchDstu2Test { ourLastQuantity = null; } + @Test - public void testSearchWhitelist01Failing() throws Exception { - HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?_query=searchWhitelist01&ref=value"); + public void testEncodeConvertsReferencesToRelative() throws Exception { + HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?_query=searchWithRef"); + HttpResponse status = ourClient.execute(httpGet); + String responseContent = IOUtils.toString(status.getEntity().getContent()); + IOUtils.closeQuietly(status.getEntity().getContent()); + ourLog.info(responseContent); + + assertThat(responseContent, not(containsString("text"))); + + assertEquals(200, status.getStatusLine().getStatusCode()); + Patient patient = (Patient) ourCtx.newXmlParser().parseResource(Bundle.class, responseContent).getEntry().get(0).getResource(); + String ref = patient.getManagingOrganization().getReference().getValue(); + assertEquals("Organization/555", ref); + assertNull(status.getFirstHeader(Constants.HEADER_CONTENT_LOCATION)); + } + + @Test + public void testEncodeConvertsReferencesToRelativeJson() throws Exception { + HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?_query=searchWithRef&_format=json"); + HttpResponse status = ourClient.execute(httpGet); + String responseContent = IOUtils.toString(status.getEntity().getContent()); + IOUtils.closeQuietly(status.getEntity().getContent()); + ourLog.info(responseContent); + + assertThat(responseContent, not(containsString("text"))); + + assertEquals(200, status.getStatusLine().getStatusCode()); + Patient patient = (Patient) ourCtx.newJsonParser().parseResource(Bundle.class, responseContent).getEntry().get(0).getResource(); + String ref = patient.getManagingOrganization().getReference().getValue(); + assertEquals("Organization/555", ref); + assertNull(status.getFirstHeader(Constants.HEADER_CONTENT_LOCATION)); + } + + @Test + public void testResultBundleHasUpdateTime() throws Exception { + ourReturnPublished = new InstantDt("2011-02-03T11:22:33Z"); + + HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?_query=searchWithBundleProvider&_pretty=true"); + HttpResponse status = ourClient.execute(httpGet); + String responseContent = IOUtils.toString(status.getEntity().getContent()); + IOUtils.closeQuietly(status.getEntity().getContent()); + ourLog.info(responseContent); + + assertThat(responseContent, stringContainsInOrder("")); + } + + @Test + public void testResultBundleHasUuid() throws Exception { + HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?_query=searchWithRef"); + HttpResponse status = ourClient.execute(httpGet); + String responseContent = IOUtils.toString(status.getEntity().getContent()); + IOUtils.closeQuietly(status.getEntity().getContent()); + ourLog.info(responseContent); + + assertEquals(200, status.getStatusLine().getStatusCode()); + assertThat(responseContent, PatternMatcher.pattern("id value..[0-9a-f-]+\\\"")); + } + + @Test + public void testSearchBlacklist01Failing() throws Exception { + HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?_query=searchBlacklist01&ref.black1=value"); HttpResponse status = ourClient.execute(httpGet); String responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent()); @@ -81,6 +142,132 @@ public class SearchDstu2Test { assertEquals(400, status.getStatusLine().getStatusCode()); } + @Test + public void testSearchBlacklist01Passing() throws Exception { + HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?_query=searchBlacklist01&ref.white1=value"); + HttpResponse status = ourClient.execute(httpGet); + String responseContent = IOUtils.toString(status.getEntity().getContent()); + IOUtils.closeQuietly(status.getEntity().getContent()); + ourLog.info(responseContent); + assertEquals(200, status.getStatusLine().getStatusCode()); + assertEquals("searchBlacklist01", ourLastMethod); + } + + @Test + public void testSearchByPost() throws Exception { + HttpPost httpGet = new HttpPost("http://localhost:" + ourPort + "/Patient/_search"); + StringEntity entity = new StringEntity("searchDateAndList=2001,2002&searchDateAndList=2003,2004", ContentType.APPLICATION_FORM_URLENCODED); + httpGet.setEntity(entity); + + HttpResponse status = ourClient.execute(httpGet); + String responseContent = IOUtils.toString(status.getEntity().getContent()); + IOUtils.closeQuietly(status.getEntity().getContent()); + ourLog.info(responseContent); + assertEquals("searchDateAndList", ourLastMethod); + assertEquals(2, ourLastDateAndList.getValuesAsQueryTokens().size()); + assertEquals(2, ourLastDateAndList.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().size()); + assertEquals(2, ourLastDateAndList.getValuesAsQueryTokens().get(1).getValuesAsQueryTokens().size()); + assertEquals("2001", ourLastDateAndList.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getValueAsString()); + assertEquals("2002", ourLastDateAndList.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(1).getValueAsString()); + assertThat(responseContent, containsString("SYSTEM")); + } + + @Test + public void testSearchByPostWithBodyAndUrlParams() throws Exception { + + HttpPost httpGet = new HttpPost("http://localhost:" + ourPort + "/Patient/_search?_format=json"); + StringEntity entity = new StringEntity("searchDateAndList=2001,2002&searchDateAndList=2003,2004", ContentType.APPLICATION_FORM_URLENCODED); + httpGet.setEntity(entity); + + CloseableHttpResponse status = ourClient.execute(httpGet); + String responseContent = IOUtils.toString(status.getEntity().getContent()); + IOUtils.closeQuietly(status.getEntity().getContent()); + ourLog.info(responseContent); + assertEquals("searchDateAndList", ourLastMethod); + assertEquals(2, ourLastDateAndList.getValuesAsQueryTokens().size()); + assertEquals(2, ourLastDateAndList.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().size()); + assertEquals(2, ourLastDateAndList.getValuesAsQueryTokens().get(1).getValuesAsQueryTokens().size()); + assertEquals("2001", ourLastDateAndList.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getValueAsString()); + assertEquals("2002", ourLastDateAndList.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(1).getValueAsString()); + assertThat(responseContent, containsString(":\"SYSTEM\"")); + + } + + @Test + public void testSearchByPut() throws Exception { + HttpPut httpGet = new HttpPut("http://localhost:" + ourPort + "/Patient/_search"); + StringEntity entity = new StringEntity("searchDateAndList=2001,2002&searchDateAndList=2003,2004", ContentType.APPLICATION_FORM_URLENCODED); + httpGet.setEntity(entity); + + HttpResponse status = ourClient.execute(httpGet); + String responseContent = IOUtils.toString(status.getEntity().getContent()); + IOUtils.closeQuietly(status.getEntity().getContent()); + ourLog.info(responseContent); + assertEquals(400, status.getStatusLine().getStatusCode()); + } + + @Test + public void testSearchDateAndList() throws Exception { + HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?searchDateAndList=2001,2002&searchDateAndList=2003,2004"); + HttpResponse status = ourClient.execute(httpGet); + String responseContent = IOUtils.toString(status.getEntity().getContent()); + IOUtils.closeQuietly(status.getEntity().getContent()); + ourLog.info(responseContent); + assertEquals("searchDateAndList", ourLastMethod); + assertEquals(2, ourLastDateAndList.getValuesAsQueryTokens().size()); + assertEquals(2, ourLastDateAndList.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().size()); + assertEquals(2, ourLastDateAndList.getValuesAsQueryTokens().get(1).getValuesAsQueryTokens().size()); + assertEquals("2001", ourLastDateAndList.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getValueAsString()); + assertEquals("2002", ourLastDateAndList.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(1).getValueAsString()); + } + + /** + * See #247 + */ + @Test + public void testSearchPagesAllHaveCorrectBundleType() throws Exception { + Bundle resp; + { + HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?searchHugeResults=yes&_count=10&_pretty=true"); + HttpResponse status = ourClient.execute(httpGet); + String responseContent = IOUtils.toString(status.getEntity().getContent()); + IOUtils.closeQuietly(status.getEntity().getContent()); + ourLog.info(responseContent); + resp = ourCtx.newXmlParser().parseResource(Bundle.class, responseContent); + assertEquals("searchset", resp.getType()); + assertEquals(100, resp.getTotal().intValue()); + } + Link nextLink = resp.getLink("next"); + assertThat(nextLink.getUrl(), startsWith("http://")); + + // Now try the next page + { + HttpGet httpGet = new HttpGet(nextLink.getUrl()); + HttpResponse status = ourClient.execute(httpGet); + String responseContent = IOUtils.toString(status.getEntity().getContent()); + IOUtils.closeQuietly(status.getEntity().getContent()); + ourLog.info(responseContent); + resp = ourCtx.newXmlParser().parseResource(Bundle.class, responseContent); + assertEquals("searchset", resp.getType()); + assertEquals(100, resp.getTotal().intValue()); + } + + nextLink = resp.getLink("next"); + assertThat(nextLink.getUrl(), startsWith("http://")); + + // Now try a third page + { + HttpGet httpGet = new HttpGet(nextLink.getUrl()); + HttpResponse status = ourClient.execute(httpGet); + String responseContent = IOUtils.toString(status.getEntity().getContent()); + IOUtils.closeQuietly(status.getEntity().getContent()); + ourLog.info(responseContent); + resp = ourCtx.newXmlParser().parseResource(Bundle.class, responseContent); + assertEquals("searchset", resp.getType()); + assertEquals(100, resp.getTotal().intValue()); + } + } + /** * See #296 */ @@ -164,92 +351,8 @@ public class SearchDstu2Test { } @Test - public void testSearchDateAndList() throws Exception { - HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?searchDateAndList=2001,2002&searchDateAndList=2003,2004"); - HttpResponse status = ourClient.execute(httpGet); - String responseContent = IOUtils.toString(status.getEntity().getContent()); - IOUtils.closeQuietly(status.getEntity().getContent()); - ourLog.info(responseContent); - assertEquals("searchDateAndList", ourLastMethod); - assertEquals(2, ourLastDateAndList.getValuesAsQueryTokens().size()); - assertEquals(2, ourLastDateAndList.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().size()); - assertEquals(2, ourLastDateAndList.getValuesAsQueryTokens().get(1).getValuesAsQueryTokens().size()); - assertEquals("2001", ourLastDateAndList.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getValueAsString()); - assertEquals("2002", ourLastDateAndList.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(1).getValueAsString()); - } - - /** - * See #247 - */ - @Test - public void testSearchPagesAllHaveCorrectBundleType() throws Exception { - Bundle resp; - { - HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?searchHugeResults=yes&_count=10&_pretty=true"); - HttpResponse status = ourClient.execute(httpGet); - String responseContent = IOUtils.toString(status.getEntity().getContent()); - IOUtils.closeQuietly(status.getEntity().getContent()); - ourLog.info(responseContent); - resp = ourCtx.newXmlParser().parseResource(Bundle.class, responseContent); - assertEquals("searchset", resp.getType()); - assertEquals(100, resp.getTotal().intValue()); - } - Link nextLink = resp.getLink("next"); - assertThat(nextLink.getUrl(), startsWith("http://")); - - // Now try the next page - { - HttpGet httpGet = new HttpGet(nextLink.getUrl()); - HttpResponse status = ourClient.execute(httpGet); - String responseContent = IOUtils.toString(status.getEntity().getContent()); - IOUtils.closeQuietly(status.getEntity().getContent()); - ourLog.info(responseContent); - resp = ourCtx.newXmlParser().parseResource(Bundle.class, responseContent); - assertEquals("searchset", resp.getType()); - assertEquals(100, resp.getTotal().intValue()); - } - - nextLink = resp.getLink("next"); - assertThat(nextLink.getUrl(), startsWith("http://")); - - // Now try a third page - { - HttpGet httpGet = new HttpGet(nextLink.getUrl()); - HttpResponse status = ourClient.execute(httpGet); - String responseContent = IOUtils.toString(status.getEntity().getContent()); - IOUtils.closeQuietly(status.getEntity().getContent()); - ourLog.info(responseContent); - resp = ourCtx.newXmlParser().parseResource(Bundle.class, responseContent); - assertEquals("searchset", resp.getType()); - assertEquals(100, resp.getTotal().intValue()); - } - } - - @Test - public void testSearchByPost() throws Exception { - HttpPost httpGet = new HttpPost("http://localhost:" + ourPort + "/Patient/_search"); - StringEntity entity = new StringEntity("searchDateAndList=2001,2002&searchDateAndList=2003,2004", ContentType.APPLICATION_FORM_URLENCODED); - httpGet.setEntity(entity); - - HttpResponse status = ourClient.execute(httpGet); - String responseContent = IOUtils.toString(status.getEntity().getContent()); - IOUtils.closeQuietly(status.getEntity().getContent()); - ourLog.info(responseContent); - assertEquals("searchDateAndList", ourLastMethod); - assertEquals(2, ourLastDateAndList.getValuesAsQueryTokens().size()); - assertEquals(2, ourLastDateAndList.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().size()); - assertEquals(2, ourLastDateAndList.getValuesAsQueryTokens().get(1).getValuesAsQueryTokens().size()); - assertEquals("2001", ourLastDateAndList.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getValueAsString()); - assertEquals("2002", ourLastDateAndList.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(1).getValueAsString()); - assertThat(responseContent, containsString("SYSTEM")); - } - - @Test - public void testSearchByPut() throws Exception { - HttpPut httpGet = new HttpPut("http://localhost:" + ourPort + "/Patient/_search"); - StringEntity entity = new StringEntity("searchDateAndList=2001,2002&searchDateAndList=2003,2004", ContentType.APPLICATION_FORM_URLENCODED); - httpGet.setEntity(entity); - + public void testSearchWhitelist01Failing() throws Exception { + HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?_query=searchWhitelist01&ref=value"); HttpResponse status = ourClient.execute(httpGet); String responseContent = IOUtils.toString(status.getEntity().getContent()); IOUtils.closeQuietly(status.getEntity().getContent()); @@ -257,48 +360,6 @@ public class SearchDstu2Test { assertEquals(400, status.getStatusLine().getStatusCode()); } - @Test - public void testSearchByPostWithBodyAndUrlParams() throws Exception { - - HttpPost httpGet = new HttpPost("http://localhost:" + ourPort + "/Patient/_search?_format=json"); - StringEntity entity = new StringEntity("searchDateAndList=2001,2002&searchDateAndList=2003,2004", ContentType.APPLICATION_FORM_URLENCODED); - httpGet.setEntity(entity); - - CloseableHttpResponse status = ourClient.execute(httpGet); - String responseContent = IOUtils.toString(status.getEntity().getContent()); - IOUtils.closeQuietly(status.getEntity().getContent()); - ourLog.info(responseContent); - assertEquals("searchDateAndList", ourLastMethod); - assertEquals(2, ourLastDateAndList.getValuesAsQueryTokens().size()); - assertEquals(2, ourLastDateAndList.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().size()); - assertEquals(2, ourLastDateAndList.getValuesAsQueryTokens().get(1).getValuesAsQueryTokens().size()); - assertEquals("2001", ourLastDateAndList.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(0).getValueAsString()); - assertEquals("2002", ourLastDateAndList.getValuesAsQueryTokens().get(0).getValuesAsQueryTokens().get(1).getValueAsString()); - assertThat(responseContent, containsString(":\"SYSTEM\"")); - - } - - @Test - public void testSearchBlacklist01Failing() throws Exception { - HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?_query=searchBlacklist01&ref.black1=value"); - HttpResponse status = ourClient.execute(httpGet); - String responseContent = IOUtils.toString(status.getEntity().getContent()); - IOUtils.closeQuietly(status.getEntity().getContent()); - ourLog.info(responseContent); - assertEquals(400, status.getStatusLine().getStatusCode()); - } - - @Test - public void testSearchBlacklist01Passing() throws Exception { - HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?_query=searchBlacklist01&ref.white1=value"); - HttpResponse status = ourClient.execute(httpGet); - String responseContent = IOUtils.toString(status.getEntity().getContent()); - IOUtils.closeQuietly(status.getEntity().getContent()); - ourLog.info(responseContent); - assertEquals(200, status.getStatusLine().getStatusCode()); - assertEquals("searchBlacklist01", ourLastMethod); - } - @Test public void testSearchWhitelist01Passing() throws Exception { HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?_query=searchWhitelist01&ref.white1=value"); @@ -310,68 +371,11 @@ public class SearchDstu2Test { assertEquals("searchWhitelist01", ourLastMethod); } - @Test - public void testEncodeConvertsReferencesToRelative() throws Exception { - HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?_query=searchWithRef"); - HttpResponse status = ourClient.execute(httpGet); - String responseContent = IOUtils.toString(status.getEntity().getContent()); - IOUtils.closeQuietly(status.getEntity().getContent()); - ourLog.info(responseContent); - - assertThat(responseContent, not(containsString("text"))); - - assertEquals(200, status.getStatusLine().getStatusCode()); - Patient patient = (Patient) ourCtx.newXmlParser().parseResource(Bundle.class, responseContent).getEntry().get(0).getResource(); - String ref = patient.getManagingOrganization().getReference().getValue(); - assertEquals("Organization/555", ref); - assertNull(status.getFirstHeader(Constants.HEADER_CONTENT_LOCATION)); - } - - @Test - public void testEncodeConvertsReferencesToRelativeJson() throws Exception { - HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?_query=searchWithRef&_format=json"); - HttpResponse status = ourClient.execute(httpGet); - String responseContent = IOUtils.toString(status.getEntity().getContent()); - IOUtils.closeQuietly(status.getEntity().getContent()); - ourLog.info(responseContent); - - assertThat(responseContent, not(containsString("text"))); - - assertEquals(200, status.getStatusLine().getStatusCode()); - Patient patient = (Patient) ourCtx.newJsonParser().parseResource(Bundle.class, responseContent).getEntry().get(0).getResource(); - String ref = patient.getManagingOrganization().getReference().getValue(); - assertEquals("Organization/555", ref); - assertNull(status.getFirstHeader(Constants.HEADER_CONTENT_LOCATION)); - } - - @Test - public void testResultBundleHasUuid() throws Exception { - HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?_query=searchWithRef"); - HttpResponse status = ourClient.execute(httpGet); - String responseContent = IOUtils.toString(status.getEntity().getContent()); - IOUtils.closeQuietly(status.getEntity().getContent()); - ourLog.info(responseContent); - - assertEquals(200, status.getStatusLine().getStatusCode()); - assertThat(responseContent, PatternMatcher.pattern("id value..[0-9a-f-]+\\\"")); - } - - @Test - public void testResultBundleHasUpdateTime() throws Exception { - ourReturnPublished = new InstantDt("2011-02-03T11:22:33Z"); - - HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?_query=searchWithBundleProvider&_pretty=true"); - HttpResponse status = ourClient.execute(httpGet); - String responseContent = IOUtils.toString(status.getEntity().getContent()); - IOUtils.closeQuietly(status.getEntity().getContent()); - ourLog.info(responseContent); - - assertThat(responseContent, stringContainsInOrder("")); - } @AfterClass - public static void afterClass() throws Exception { + public static void afterClassClearContext() throws Exception { ourServer.stop(); + TestUtil.clearAllStaticFieldsForUnitTest(); } @BeforeClass @@ -409,30 +413,10 @@ public class SearchDstu2Test { } //@formatter:off - @Search(queryName="searchWhitelist01") - public List searchWhitelist01( - @RequiredParam(chainWhitelist="white1", name = "ref") ReferenceParam theParam) { - ourLastMethod = "searchWhitelist01"; - return Collections.emptyList(); - } - //@formatter:on - - //@formatter:off - @Search() - public List searchQuantity( - @RequiredParam(name="quantity") QuantityParam theParam) { - ourLastMethod = "searchQuantity"; - ourLastQuantity = theParam; - return Collections.emptyList(); - } - //@formatter:on - - //@formatter:off - @Search(queryName="searchNoList") - public List searchNoList( - @RequiredParam(name = "ref") ReferenceParam theParam) { - ourLastMethod = "searchNoList"; - ourLastRef = theParam; + @Search(queryName="searchBlacklist01") + public List searchBlacklist01( + @RequiredParam(chainBlacklist="black1", name = "ref") ReferenceParam theParam) { + ourLastMethod = "searchBlacklist01"; return Collections.emptyList(); } //@formatter:on @@ -467,10 +451,30 @@ public class SearchDstu2Test { //@formatter:on //@formatter:off - @Search(queryName="searchBlacklist01") - public List searchBlacklist01( - @RequiredParam(chainBlacklist="black1", name = "ref") ReferenceParam theParam) { - ourLastMethod = "searchBlacklist01"; + @Search(queryName="searchNoList") + public List searchNoList( + @RequiredParam(name = "ref") ReferenceParam theParam) { + ourLastMethod = "searchNoList"; + ourLastRef = theParam; + return Collections.emptyList(); + } + //@formatter:on + + //@formatter:off + @Search() + public List searchQuantity( + @RequiredParam(name="quantity") QuantityParam theParam) { + ourLastMethod = "searchQuantity"; + ourLastQuantity = theParam; + return Collections.emptyList(); + } + //@formatter:on + + //@formatter:off + @Search(queryName="searchWhitelist01") + public List searchWhitelist01( + @RequiredParam(chainWhitelist="white1", name = "ref") ReferenceParam theParam) { + ourLastMethod = "searchWhitelist01"; return Collections.emptyList(); } //@formatter:on 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 9188fa13014..868c81df705 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 @@ -24,14 +24,15 @@ import ca.uhn.fhir.model.dstu2.resource.Bundle; import ca.uhn.fhir.model.dstu2.resource.Patient; import ca.uhn.fhir.rest.annotation.Search; import ca.uhn.fhir.util.PortUtil; +import ca.uhn.fhir.util.TestUtil; public class SearchWithDstu2BundleTest { private static CloseableHttpClient ourClient; - private static int ourPort; - private static Server ourServer; private static FhirContext ourCtx = FhirContext.forDstu2(); private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(SearchWithDstu2BundleTest.class); + private static int ourPort; + private static Server ourServer; @Test public void testSearch() throws Exception { @@ -61,9 +62,11 @@ public class SearchWithDstu2BundleTest { } + @AfterClass - public static void afterClass() throws Exception { + public static void afterClassClearContext() throws Exception { ourServer.stop(); + TestUtil.clearAllStaticFieldsForUnitTest(); } @BeforeClass @@ -95,6 +98,11 @@ public class SearchWithDstu2BundleTest { */ public static class DummyPatientResourceProvider implements IResourceProvider { + @Override + public Class getResourceType() { + return Patient.class; + } + @Search public Bundle search() { Bundle retVal = new Bundle(); @@ -108,11 +116,6 @@ public class SearchWithDstu2BundleTest { return retVal; } - @Override - public Class getResourceType() { - return Patient.class; - } - } } diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/SearchWithGenericListDstu2Test.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/SearchWithGenericListDstu2Test.java index 0301effd313..09a27bc2459 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/SearchWithGenericListDstu2Test.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/SearchWithGenericListDstu2Test.java @@ -37,15 +37,16 @@ import ca.uhn.fhir.rest.param.ReferenceParam; import ca.uhn.fhir.rest.param.StringParam; import ca.uhn.fhir.rest.param.TokenParam; import ca.uhn.fhir.util.PortUtil; +import ca.uhn.fhir.util.TestUtil; public class SearchWithGenericListDstu2Test { private static CloseableHttpClient ourClient; private static FhirContext ourCtx = FhirContext.forDstu2(); + private static String ourLastMethod; private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(SearchWithGenericListDstu2Test.class); private static int ourPort; private static Server ourServer; - private static String ourLastMethod; @Before public void before() { @@ -68,9 +69,11 @@ public class SearchWithGenericListDstu2Test { } + @AfterClass - public static void afterClass() throws Exception { + public static void afterClassClearContext() throws Exception { ourServer.stop(); + TestUtil.clearAllStaticFieldsForUnitTest(); } @BeforeClass 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 7b2e39e4191..b90e169237f 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 @@ -18,6 +18,7 @@ import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import org.hl7.fhir.instance.model.api.IBaseResource; +import org.junit.AfterClass; import org.junit.Test; import ca.uhn.fhir.context.FhirContext; @@ -65,6 +66,7 @@ import ca.uhn.fhir.rest.param.DateRangeParam; import ca.uhn.fhir.rest.param.ReferenceAndListParam; import ca.uhn.fhir.rest.param.TokenOrListParam; import ca.uhn.fhir.rest.server.provider.dstu2.ServerConformanceProvider; +import ca.uhn.fhir.util.TestUtil; import ca.uhn.fhir.validation.ValidationResult; public class ServerConformanceProviderDstu2Test { @@ -72,6 +74,13 @@ public class ServerConformanceProviderDstu2Test { private static FhirContext ourCtx = FhirContext.forDstu2(); private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ServerConformanceProviderDstu2Test.class); + + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + private HttpServletRequest createHttpServletRequest() { HttpServletRequest req = mock(HttpServletRequest.class); when(req.getRequestURI()).thenReturn("/FhirStorm/fhir/Patient/_search"); diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/ServerFeaturesDstu2Test.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/ServerFeaturesDstu2Test.java index 04a96018586..7bdd7151eca 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/ServerFeaturesDstu2Test.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/ServerFeaturesDstu2Test.java @@ -29,6 +29,7 @@ import ca.uhn.fhir.model.primitive.IdDt; import ca.uhn.fhir.rest.annotation.IdParam; import ca.uhn.fhir.rest.annotation.Read; import ca.uhn.fhir.util.PortUtil; +import ca.uhn.fhir.util.TestUtil; /** * Created by dsotnikov on 2/25/2014. @@ -67,6 +68,7 @@ public class ServerFeaturesDstu2Test { } + /** * See #313 */ @@ -81,6 +83,20 @@ public class ServerFeaturesDstu2Test { assertEquals(400, status.getStatusLine().getStatusCode()); } + /** + * See #313 + */ + @Test + public void testOptionsForNonBasePath2() throws Exception { + HttpOptions httpGet = new HttpOptions("http://localhost:" + ourPort + "/Patient/1"); + HttpResponse status = ourClient.execute(httpGet); + String responseContent = IOUtils.toString(status.getEntity().getContent()); + IOUtils.closeQuietly(status.getEntity().getContent()); + + ourLog.info(responseContent); + assertEquals(400, status.getStatusLine().getStatusCode()); + } + /** * See #313 */ @@ -95,20 +111,6 @@ public class ServerFeaturesDstu2Test { assertEquals(405, status.getStatusLine().getStatusCode()); } - /** - * See #313 - */ - @Test - public void testOptionsForNonBasePath2() throws Exception { - HttpOptions httpGet = new HttpOptions("http://localhost:" + ourPort + "/Patient/1"); - HttpResponse status = ourClient.execute(httpGet); - String responseContent = IOUtils.toString(status.getEntity().getContent()); - IOUtils.closeQuietly(status.getEntity().getContent()); - - ourLog.info(responseContent); - assertEquals(400, status.getStatusLine().getStatusCode()); - } - @Test public void testOptionsJson() throws Exception { HttpOptions httpGet = new HttpOptions("http://localhost:" + ourPort + "?_format=json"); @@ -145,9 +147,11 @@ public class ServerFeaturesDstu2Test { } + @AfterClass - public static void afterClass() throws Exception { + public static void afterClassClearContext() throws Exception { ourServer.stop(); + TestUtil.clearAllStaticFieldsForUnitTest(); } @BeforeClass 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 76159b8f661..a479669e19d 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 @@ -7,6 +7,7 @@ import javax.servlet.ServletException; import org.hamcrest.core.StringContains; import org.hl7.fhir.instance.model.api.IBaseResource; +import org.junit.AfterClass; import org.junit.Test; import ca.uhn.fhir.context.FhirContext; @@ -19,11 +20,18 @@ import ca.uhn.fhir.rest.annotation.ResourceParam; import ca.uhn.fhir.rest.annotation.Update; import ca.uhn.fhir.rest.api.MethodOutcome; import ca.uhn.fhir.rest.param.TokenParam; +import ca.uhn.fhir.util.TestUtil; public class ServerInvalidDefinitionDstu2Test { private static FhirContext ourCtx = FhirContext.forDstu2(); - + + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + @Test public void testOperationReturningOldBundleProvider() { RestfulServer srv = new RestfulServer(ourCtx); diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/ServerSearchDstu2Test.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/ServerSearchDstu2Test.java index 4ea9c7f71c6..fd420833fb6 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/ServerSearchDstu2Test.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/ServerSearchDstu2Test.java @@ -27,6 +27,7 @@ import ca.uhn.fhir.rest.annotation.RequiredParam; import ca.uhn.fhir.rest.annotation.Search; import ca.uhn.fhir.rest.param.StringParam; import ca.uhn.fhir.util.PortUtil; +import ca.uhn.fhir.util.TestUtil; public class ServerSearchDstu2Test { @@ -43,7 +44,8 @@ public class ServerSearchDstu2Test { ourLastMethod = null; ourLastRef = null; } - + + @Test public void testSearchParam1() throws Exception { HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/?param1=param1value"); @@ -54,7 +56,7 @@ public class ServerSearchDstu2Test { assertEquals("searchParam1", ourLastMethod); assertEquals("param1value", ourLastRef.getValue()); } - + @Test public void testSearchParam2() throws Exception { HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/?param2=param2value&foo=bar"); @@ -76,9 +78,11 @@ public class ServerSearchDstu2Test { assertEquals(null, ourLastMethod); } + @AfterClass - public static void afterClass() throws Exception { + public static void afterClassClearContext() throws Exception { ourServer.stop(); + TestUtil.clearAllStaticFieldsForUnitTest(); } @BeforeClass diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/ServerWithResponseHighlightingInterceptorExceptionTest.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/ServerWithResponseHighlightingInterceptorExceptionTest.java index 80bad680dea..5843ae42ff9 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/ServerWithResponseHighlightingInterceptorExceptionTest.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/ServerWithResponseHighlightingInterceptorExceptionTest.java @@ -31,14 +31,15 @@ import ca.uhn.fhir.rest.param.TokenParam; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import ca.uhn.fhir.rest.server.interceptor.ResponseHighlighterInterceptor; import ca.uhn.fhir.util.PortUtil; +import ca.uhn.fhir.util.TestUtil; public class ServerWithResponseHighlightingInterceptorExceptionTest { - private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ServerWithResponseHighlightingInterceptorExceptionTest.class); - private static CloseableHttpClient ourClient; + + private static FhirContext ourCtx = FhirContext.forDstu2(); + private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ServerWithResponseHighlightingInterceptorExceptionTest.class); private static int ourPort; private static Server ourServer; - private static FhirContext ourCtx = FhirContext.forDstu2(); private static RestfulServer ourServlet; @Test @@ -53,6 +54,7 @@ public class ServerWithResponseHighlightingInterceptorExceptionTest { assertThat(responseContent, containsString("")); } + @Test public void testUnexpectedException() throws Exception { HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?identifier=123"); @@ -65,9 +67,11 @@ public class ServerWithResponseHighlightingInterceptorExceptionTest { assertThat(responseContent, containsString("")); } + @AfterClass - public static void afterClass() throws Exception { + public static void afterClassClearContext() throws Exception { ourServer.stop(); + TestUtil.clearAllStaticFieldsForUnitTest(); } @BeforeClass @@ -97,6 +101,11 @@ public class ServerWithResponseHighlightingInterceptorExceptionTest { public static class DummyPatientResourceProvider implements IResourceProvider { + @Override + public Class getResourceType() { + return Patient.class; + } + @Read public Patient read(@IdParam IdDt theId) { throw new InvalidRequestException("AAABBB"); @@ -107,11 +116,6 @@ public class ServerWithResponseHighlightingInterceptorExceptionTest { throw new Error("AAABBB"); } - @Override - public Class getResourceType() { - return Patient.class; - } - } } diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/SummaryParamTest.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/SummaryParamTest.java index a8f90bd5195..e0c75eb35be 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/SummaryParamTest.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/SummaryParamTest.java @@ -30,6 +30,7 @@ import ca.uhn.fhir.rest.annotation.Read; import ca.uhn.fhir.rest.annotation.Search; import ca.uhn.fhir.rest.api.SummaryEnum; import ca.uhn.fhir.util.PortUtil; +import ca.uhn.fhir.util.TestUtil; public class SummaryParamTest { @@ -47,7 +48,6 @@ public class SummaryParamTest { ourLastSummary = null; ourLastSummaryList = null; } - @Test public void testReadSummaryData() throws Exception { HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/1?_summary=" + SummaryEnum.DATA.getCode()); @@ -66,6 +66,8 @@ public class SummaryParamTest { assertEquals(SummaryEnum.DATA, ourLastSummary); } + + @Test public void testReadSummaryText() throws Exception { HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/1?_summary=" + SummaryEnum.TEXT.getCode()); @@ -214,8 +216,9 @@ public class SummaryParamTest { } @AfterClass - public static void afterClass() throws Exception { + public static void afterClassClearContext() throws Exception { ourServer.stop(); + TestUtil.clearAllStaticFieldsForUnitTest(); } @BeforeClass 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 ae1e2474732..da90f8fb92a 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 @@ -36,23 +36,21 @@ import ca.uhn.fhir.rest.annotation.TransactionParam; import ca.uhn.fhir.rest.client.IGenericClient; import ca.uhn.fhir.rest.client.api.IRestfulClient; import ca.uhn.fhir.util.PortUtil; +import ca.uhn.fhir.util.TestUtil; /** * Created by dsotnikov on 2/25/2014. */ public class TransactionWithBundleResourceParamTest { - @Test - public void testIt() { - - } - + private static CloseableHttpClient ourClient; + + 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; - private static Server ourServer; @Before @@ -74,53 +72,6 @@ public class TransactionWithBundleResourceParamTest { assertTrue(supportsTransaction); } - - @Test - public void testTransactionWithXmlRequest() throws Exception { - Bundle b = new Bundle(); - InstantDt nowInstant = InstantDt.withCurrentTime(); - - Patient p1 = new Patient(); - p1.addName().addFamily("Family1"); - Entry entry = b.addEntry(); - p1.getId().setValue("1"); - entry.setResource(p1); - - Patient p2 = new Patient(); - p2.addName().addFamily("Family2"); - entry = b.addEntry(); - p2.getId().setValue("2"); - entry.setResource(p2); - - Entry deletedEntry = b.addEntry(); - deletedEntry.getRequest().setMethod(HTTPVerbEnum.DELETE); - deletedEntry.getRequest().setUrl("http://base.com/Patient/123"); - - String bundleString = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(b); - ourLog.info(bundleString); - - HttpPost httpPost = new HttpPost("http://localhost:" + ourPort + "/"); - httpPost.setEntity(new StringEntity(bundleString, ContentType.create(Constants.CT_FHIR_XML, "UTF-8"))); - HttpResponse status = ourClient.execute(httpPost); - String responseContent = IOUtils.toString(status.getEntity().getContent()); - IOUtils.closeQuietly(status.getEntity().getContent()); - - assertEquals(200, status.getStatusLine().getStatusCode()); - - ourLog.info(responseContent); - - Bundle bundle = ourCtx.newXmlParser().parseResource(Bundle.class, responseContent); - assertEquals(3, bundle.getEntry().size()); - - Entry entry0 = bundle.getEntry().get(0); - assertEquals("Patient/81/_history/91", entry0.getResponse().getLocation()); - - Entry entry1 = bundle.getEntry().get(1); - assertEquals( "Patient/82/_history/92", entry1.getResponse().getLocation()); - - Entry entry2 = bundle.getEntry().get(2); - assertEquals("Patient/123/_history/93", entry2.getResponse().getLocation()); - } @Test public void testTransactionWithJsonRequest() throws Exception { @@ -169,7 +120,7 @@ public class TransactionWithBundleResourceParamTest { Entry entry2 = bundle.getEntry().get(2); assertEquals("Patient/123/_history/93", entry2.getResponse().getLocation()); } - + @Test public void testTransactionWithOperationOutcome() throws Exception { ourReturnOperationOutcome = true; @@ -223,9 +174,58 @@ public class TransactionWithBundleResourceParamTest { assertEquals( "Patient/3/_history/93", entry2.getResponse().getLocation()); } + @Test + public void testTransactionWithXmlRequest() throws Exception { + Bundle b = new Bundle(); + InstantDt nowInstant = InstantDt.withCurrentTime(); + + Patient p1 = new Patient(); + p1.addName().addFamily("Family1"); + Entry entry = b.addEntry(); + p1.getId().setValue("1"); + entry.setResource(p1); + + Patient p2 = new Patient(); + p2.addName().addFamily("Family2"); + entry = b.addEntry(); + p2.getId().setValue("2"); + entry.setResource(p2); + + Entry deletedEntry = b.addEntry(); + deletedEntry.getRequest().setMethod(HTTPVerbEnum.DELETE); + deletedEntry.getRequest().setUrl("http://base.com/Patient/123"); + + String bundleString = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(b); + ourLog.info(bundleString); + + HttpPost httpPost = new HttpPost("http://localhost:" + ourPort + "/"); + httpPost.setEntity(new StringEntity(bundleString, ContentType.create(Constants.CT_FHIR_XML, "UTF-8"))); + HttpResponse status = ourClient.execute(httpPost); + String responseContent = IOUtils.toString(status.getEntity().getContent()); + IOUtils.closeQuietly(status.getEntity().getContent()); + + assertEquals(200, status.getStatusLine().getStatusCode()); + + ourLog.info(responseContent); + + Bundle bundle = ourCtx.newXmlParser().parseResource(Bundle.class, responseContent); + assertEquals(3, bundle.getEntry().size()); + + Entry entry0 = bundle.getEntry().get(0); + assertEquals("Patient/81/_history/91", entry0.getResponse().getLocation()); + + Entry entry1 = bundle.getEntry().get(1); + assertEquals( "Patient/82/_history/92", entry1.getResponse().getLocation()); + + Entry entry2 = bundle.getEntry().get(2); + assertEquals("Patient/123/_history/93", entry2.getResponse().getLocation()); + } + + @AfterClass - public static void afterClass() throws Exception { + public static void afterClassClearContext() throws Exception { ourServer.stop(); + TestUtil.clearAllStaticFieldsForUnitTest(); } @BeforeClass 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 080de66505d..6c4860eae9d 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 @@ -38,23 +38,23 @@ import ca.uhn.fhir.rest.annotation.Search; import ca.uhn.fhir.rest.annotation.Update; import ca.uhn.fhir.rest.api.MethodOutcome; import ca.uhn.fhir.util.PortUtil; +import ca.uhn.fhir.util.TestUtil; /** * Created by dsotnikov on 2/25/2014. */ public class UpdateConditionalTest { private static CloseableHttpClient ourClient; - 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 String ourLastConditionalUrl; private static IdDt ourLastId; private static IdDt ourLastIdParam; private static boolean ourLastRequestWasSearch; + private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(UpdateConditionalTest.class); + private static int ourPort; + private static Server ourServer; - - + @Before public void before() { ourLastId = null; @@ -63,6 +63,30 @@ public class UpdateConditionalTest { ourLastRequestWasSearch = false; } + + + @Test + public void testSearchStillWorks() throws Exception { + + Patient patient = new Patient(); + patient.addIdentifier().setValue("002"); + + HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?_pretty=true"); + + HttpResponse status = ourClient.execute(httpGet); + + String responseContent = IOUtils.toString(status.getEntity().getContent()); + IOUtils.closeQuietly(status.getEntity().getContent()); + + ourLog.info("Response was:\n{}", responseContent); + + assertTrue(ourLastRequestWasSearch); + assertNull(ourLastId); + assertNull(ourLastIdParam); + assertNull(ourLastConditionalUrl); + + } + @Test public void testUpdateWithConditionalUrl() throws Exception { @@ -116,32 +140,11 @@ public class UpdateConditionalTest { } - @Test - public void testSearchStillWorks() throws Exception { - - Patient patient = new Patient(); - patient.addIdentifier().setValue("002"); - - HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?_pretty=true"); - - HttpResponse status = ourClient.execute(httpGet); - - String responseContent = IOUtils.toString(status.getEntity().getContent()); - IOUtils.closeQuietly(status.getEntity().getContent()); - - ourLog.info("Response was:\n{}", responseContent); - - assertTrue(ourLastRequestWasSearch); - assertNull(ourLastId); - assertNull(ourLastIdParam); - assertNull(ourLastConditionalUrl); - - } - @AfterClass - public static void afterClass() throws Exception { + public static void afterClassClearContext() throws Exception { ourServer.stop(); + TestUtil.clearAllStaticFieldsForUnitTest(); } 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 d4fdceeb294..7e221b9feb1 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 @@ -36,18 +36,19 @@ import ca.uhn.fhir.rest.annotation.Validate; import ca.uhn.fhir.rest.api.MethodOutcome; import ca.uhn.fhir.rest.api.ValidationModeEnum; import ca.uhn.fhir.util.PortUtil; +import ca.uhn.fhir.util.TestUtil; public class ValidateDstu2Test { private static CloseableHttpClient ourClient; + private static FhirContext ourCtx = FhirContext.forDstu2(); private static EncodingEnum ourLastEncoding; - private static String ourLastResourceBody; - 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(); - + private static String ourLastResourceBody; + private static BaseOperationOutcome ourOutcomeToReturn; + private static int ourPort; + private static Server ourServer; + @Before() public void before() { ourLastResourceBody = null; @@ -57,6 +58,50 @@ public class ValidateDstu2Test { ourLastProfile = null; } + + @Test + public void testValidate() throws Exception { + + Patient patient = new Patient(); + patient.addIdentifier().setValue("001"); + patient.addIdentifier().setValue("002"); + + Parameters params = new Parameters(); + params.addParameter().setName("resource").setResource(patient); + + HttpPost httpPost = new HttpPost("http://localhost:" + ourPort + "/Patient/$validate"); + 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()); + IOUtils.closeQuietly(status.getEntity().getContent()); + + assertEquals(200, status.getStatusLine().getStatusCode()); + + assertThat(resp, stringContainsInOrder(" getResourceType() { + return Organization.class; + } + + @Validate() + public MethodOutcome validate(@ResourceParam String theResourceBody, @ResourceParam EncodingEnum theEncoding) { + ourLastResourceBody = theResourceBody; + ourLastEncoding = theEncoding; + + return new MethodOutcome(new IdDt("001")); + } + + } + public static class PatientProvider implements IResourceProvider { + @Override + public Class getResourceType() { + return Patient.class; + } + @Validate() public MethodOutcome validatePatient(@ResourceParam Patient thePatient, @Validate.Mode ValidationModeEnum theMode, @Validate.Profile String theProfile) { IdDt id = new IdDt(thePatient.getIdentifier().get(0).getValue()); @@ -195,28 +220,6 @@ public class ValidateDstu2Test { return outcome; } - @Override - public Class getResourceType() { - return Patient.class; - } - - } - - public static class OrganizationProvider implements IResourceProvider { - - @Validate() - public MethodOutcome validate(@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-dstu2/src/test/java/ca/uhn/fhir/rest/server/interceptor/InterceptorUserDataMapDstu2Test.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/interceptor/InterceptorUserDataMapDstu2Test.java index a571f78fc93..0f9d32a408c 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/interceptor/InterceptorUserDataMapDstu2Test.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/interceptor/InterceptorUserDataMapDstu2Test.java @@ -54,6 +54,7 @@ import ca.uhn.fhir.rest.server.RestfulServer; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor.ActionRequestDetails; import ca.uhn.fhir.util.PortUtil; +import ca.uhn.fhir.util.TestUtil; public class InterceptorUserDataMapDstu2Test { @@ -68,20 +69,21 @@ public class InterceptorUserDataMapDstu2Test { private Map myMap; private Set myMapCheckMethods; private final Object myValue = "VALUE"; - + @Before public void before() { myInterceptor = mock(IServerInterceptor.class); servlet.setInterceptors(Collections.singletonList(myInterceptor)); } - + @Before public void beforePurgeMap() { myMap = null; myMapCheckMethods= new HashSet(); } + @Test public void testException() throws Exception { @@ -125,8 +127,9 @@ public class InterceptorUserDataMapDstu2Test { } @AfterClass - public static void afterClass() throws Exception { + public static void afterClassClearContext() throws Exception { ourServer.stop(); + TestUtil.clearAllStaticFieldsForUnitTest(); } @BeforeClass diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/interceptor/LoggingInterceptorDstu2Test.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/interceptor/LoggingInterceptorDstu2Test.java index 0b6b51fcb55..4e8e1604d08 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/interceptor/LoggingInterceptorDstu2Test.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/interceptor/LoggingInterceptorDstu2Test.java @@ -48,6 +48,7 @@ import ca.uhn.fhir.rest.server.IResourceProvider; import ca.uhn.fhir.rest.server.RestfulServer; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import ca.uhn.fhir.util.PortUtil; +import ca.uhn.fhir.util.TestUtil; /** * Created by dsotnikov on 2/25/2014. @@ -55,30 +56,19 @@ import ca.uhn.fhir.util.PortUtil; public class LoggingInterceptorDstu2Test { private static CloseableHttpClient ourClient; + private static final FhirContext ourCtx = FhirContext.forDstu2(); 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 { - LoggingInterceptor interceptor = new LoggingInterceptor(); - servlet.setInterceptors(Collections.singletonList((IServerInterceptor) interceptor)); - - Logger logger = mock(Logger.class); - interceptor.setLogger(logger); - - HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/1"); - HttpResponse status = ourClient.execute(httpGet); - IOUtils.closeQuietly(status.getEntity().getContent()); - - ArgumentCaptor captor = ArgumentCaptor.forClass(String.class); - verify(logger, times(1)).info(captor.capture()); - assertThat(captor.getValue(), StringContains.containsString("read - Patient/1")); + @Before + public void before() { + myInterceptor = mock(IServerInterceptor.class); + servlet.setInterceptors(Collections.singletonList(myInterceptor)); } + @Test public void testException() throws Exception { @@ -103,25 +93,6 @@ public class LoggingInterceptorDstu2Test { assertThat(captor.getAllValues().get(1), StringContains.containsString("ERROR - GET http://localhost:"+ourPort+"/Patient/EX")); } - @Test - public void testSearch() throws Exception { - - LoggingInterceptor interceptor = new LoggingInterceptor(); - interceptor.setMessageFormat("${operationType} - ${idOrResourceName} - ${requestParameters}"); - servlet.setInterceptors(Collections.singletonList((IServerInterceptor) interceptor)); - - Logger logger = mock(Logger.class); - interceptor.setLogger(logger); - - HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?_id=1"); - HttpResponse status = ourClient.execute(httpGet); - IOUtils.closeQuietly(status.getEntity().getContent()); - - ArgumentCaptor captor = ArgumentCaptor.forClass(String.class); - verify(logger, times(1)).info(captor.capture()); - assertThat(captor.getValue(), StringContains.containsString("search-type - Patient - ?_id=1")); - } - @Test public void testMetadata() throws Exception { @@ -197,15 +168,48 @@ public class LoggingInterceptorDstu2Test { assertEquals("extended-operation-type - $everything - Patient", captor.getValue()); } - @AfterClass - public static void afterClass() throws Exception { - ourServer.stop(); + @Test + public void testRead() throws Exception { + + LoggingInterceptor interceptor = new LoggingInterceptor(); + servlet.setInterceptors(Collections.singletonList((IServerInterceptor) interceptor)); + + Logger logger = mock(Logger.class); + interceptor.setLogger(logger); + + HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/1"); + HttpResponse status = ourClient.execute(httpGet); + IOUtils.closeQuietly(status.getEntity().getContent()); + + ArgumentCaptor captor = ArgumentCaptor.forClass(String.class); + verify(logger, times(1)).info(captor.capture()); + assertThat(captor.getValue(), StringContains.containsString("read - Patient/1")); } - @Before - public void before() { - myInterceptor = mock(IServerInterceptor.class); - servlet.setInterceptors(Collections.singletonList(myInterceptor)); + @Test + public void testSearch() throws Exception { + + LoggingInterceptor interceptor = new LoggingInterceptor(); + interceptor.setMessageFormat("${operationType} - ${idOrResourceName} - ${requestParameters}"); + servlet.setInterceptors(Collections.singletonList((IServerInterceptor) interceptor)); + + Logger logger = mock(Logger.class); + interceptor.setLogger(logger); + + HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient?_id=1"); + HttpResponse status = ourClient.execute(httpGet); + IOUtils.closeQuietly(status.getEntity().getContent()); + + ArgumentCaptor captor = ArgumentCaptor.forClass(String.class); + verify(logger, times(1)).info(captor.capture()); + assertThat(captor.getValue(), StringContains.containsString("search-type - Patient - ?_id=1")); + } + + + @AfterClass + public static void afterClassClearContext() throws Exception { + ourServer.stop(); + TestUtil.clearAllStaticFieldsForUnitTest(); } @BeforeClass @@ -236,6 +240,20 @@ public class LoggingInterceptorDstu2Test { */ public static class DummyPatientResourceProvider implements IResourceProvider { + private Patient createPatient1() { + Patient patient = new Patient(); + patient.addIdentifier(); + patient.getIdentifier().get(0).setUse(IdentifierUseEnum.OFFICIAL); + patient.getIdentifier().get(0).setSystem(new UriDt("urn:hapitest:mrns")); + patient.getIdentifier().get(0).setValue("00001"); + patient.addName(); + patient.getName().get(0).addFamily("Test"); + patient.getName().get(0).addGiven("PatientOne"); + patient.setGender(AdministrativeGenderEnum.MALE); + patient.getId().setValue("1"); + return patient; + } + public Map getIdToPatient() { Map idToPatient = new HashMap(); { @@ -297,14 +315,6 @@ public class LoggingInterceptorDstu2Test { return Patient.class; } - @Operation(name = "$everything", idempotent = true) - public Bundle patientTypeOperation(@IdParam IdDt theId, @OperationParam(name = "start") DateDt theStart, @OperationParam(name = "end") DateDt theEnd) { - - Bundle retVal = new Bundle(); - // Populate bundle with matching resources - return retVal; - } - @Operation(name = "$everything", idempotent = true) public Bundle patientTypeOperation(@OperationParam(name = "start") DateDt theStart, @OperationParam(name = "end") DateDt theEnd) { @@ -313,18 +323,12 @@ public class LoggingInterceptorDstu2Test { return retVal; } - private Patient createPatient1() { - Patient patient = new Patient(); - patient.addIdentifier(); - patient.getIdentifier().get(0).setUse(IdentifierUseEnum.OFFICIAL); - patient.getIdentifier().get(0).setSystem(new UriDt("urn:hapitest:mrns")); - patient.getIdentifier().get(0).setValue("00001"); - patient.addName(); - patient.getName().get(0).addFamily("Test"); - patient.getName().get(0).addGiven("PatientOne"); - patient.setGender(AdministrativeGenderEnum.MALE); - patient.getId().setValue("1"); - return patient; + @Operation(name = "$everything", idempotent = true) + public Bundle patientTypeOperation(@IdParam IdDt theId, @OperationParam(name = "start") DateDt theStart, @OperationParam(name = "end") DateDt theEnd) { + + Bundle retVal = new Bundle(); + // Populate bundle with matching resources + return retVal; } } diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/interceptor/ResponseHighlightingInterceptorTest.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/interceptor/ResponseHighlightingInterceptorTest.java index 538a3e458c6..73e72f3f6ab 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/interceptor/ResponseHighlightingInterceptorTest.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/interceptor/ResponseHighlightingInterceptorTest.java @@ -34,6 +34,7 @@ import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.servlet.ServletHandler; import org.eclipse.jetty.servlet.ServletHolder; +import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import org.mockito.invocation.InvocationOnMock; @@ -66,6 +67,7 @@ import ca.uhn.fhir.rest.server.RestfulServer; import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException; import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; import ca.uhn.fhir.util.PortUtil; +import ca.uhn.fhir.util.TestUtil; public class ResponseHighlightingInterceptorTest { @@ -77,6 +79,12 @@ public class ResponseHighlightingInterceptorTest { private static Server ourServer; private static RestfulServer ourServlet; + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + @Test public void testGetInvalidResource() throws Exception { HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Foobar/123"); diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/interceptor/ServerActionInterceptorTest.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/interceptor/ServerActionInterceptorTest.java index a39e1ef7ae5..f549ba7d168 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/interceptor/ServerActionInterceptorTest.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/interceptor/ServerActionInterceptorTest.java @@ -25,6 +25,7 @@ import org.eclipse.jetty.server.Server; import org.eclipse.jetty.servlet.ServletHandler; import org.eclipse.jetty.servlet.ServletHolder; import org.hl7.fhir.instance.model.api.IBaseResource; +import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; @@ -50,6 +51,7 @@ import ca.uhn.fhir.rest.server.IResourceProvider; import ca.uhn.fhir.rest.server.RestfulServer; import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor.ActionRequestDetails; import ca.uhn.fhir.util.PortUtil; +import ca.uhn.fhir.util.TestUtil; public class ServerActionInterceptorTest { @@ -60,6 +62,12 @@ public class ServerActionInterceptorTest { private static IServerInterceptor ourInterceptor; private static IGenericClient ourFhirClient; + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + @Test public void testRead() throws Exception { HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/123"); diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/interceptor/auth/AuthorizationInterceptorDstu2Test.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/interceptor/auth/AuthorizationInterceptorDstu2Test.java index a4b6160810a..8b5880981ff 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/interceptor/auth/AuthorizationInterceptorDstu2Test.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/interceptor/auth/AuthorizationInterceptorDstu2Test.java @@ -60,6 +60,7 @@ import ca.uhn.fhir.rest.server.IResourceProvider; import ca.uhn.fhir.rest.server.RestfulServer; import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor; import ca.uhn.fhir.util.PortUtil; +import ca.uhn.fhir.util.TestUtil; public class AuthorizationInterceptorDstu2Test { @@ -82,6 +83,7 @@ public class AuthorizationInterceptorDstu2Test { ourHitMethod = false; } + private HttpEntity createFhirResourceEntity(IBaseResource theResource) { String out = ourCtx.newJsonParser().encodeResourceToString(theResource); return new StringEntity(out, ContentType.create(Constants.CT_FHIR_JSON, "UTF-8")); @@ -116,6 +118,80 @@ public class AuthorizationInterceptorDstu2Test { return responseContent; } + @Test + public void testAllowAll() throws Exception { + ourServlet.registerInterceptor(new AuthorizationInterceptor(PolicyEnum.DENY) { + @Override + public List buildRuleList(RequestDetails theRequestDetails) { + //@formatter:off + return new RuleBuilder() + .deny("Rule 1").read().resourcesOfType(Patient.class).withAnyId().andThen() + .allowAll("Default Rule") + .build(); + //@formatter:on + } + }); + + HttpGet httpGet; + HttpResponse status; + String response; + + ourHitMethod = false; + ourReturn = Arrays.asList(createObservation(10, "Patient/2")); + httpGet = new HttpGet("http://localhost:" + ourPort + "/Observation/10"); + status = ourClient.execute(httpGet); + extractResponseAndClose(status); + assertEquals(200, status.getStatusLine().getStatusCode()); + assertTrue(ourHitMethod); + + ourHitMethod = false; + ourReturn = Arrays.asList(createPatient(2)); + httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/1"); + status = ourClient.execute(httpGet); + response = extractResponseAndClose(status); + ourLog.info(response); + assertThat(response, containsString("Access denied by rule: Rule 1")); + assertEquals(401, status.getStatusLine().getStatusCode()); + assertTrue(ourHitMethod); + } + + @Test + public void testDenyAll() throws Exception { + ourServlet.registerInterceptor(new AuthorizationInterceptor(PolicyEnum.DENY) { + @Override + public List buildRuleList(RequestDetails theRequestDetails) { + //@formatter:off + return new RuleBuilder() + .allow().read().resourcesOfType(Patient.class).withAnyId().andThen() + .denyAll("Default Rule") + .build(); + //@formatter:on + } + }); + + HttpGet httpGet; + HttpResponse status; + String response; + + ourHitMethod = false; + ourReturn = Arrays.asList(createPatient(2)); + httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/1"); + status = ourClient.execute(httpGet); + extractResponseAndClose(status); + assertEquals(200, status.getStatusLine().getStatusCode()); + assertTrue(ourHitMethod); + + ourHitMethod = false; + ourReturn = Arrays.asList(createObservation(10, "Patient/2")); + httpGet = new HttpGet("http://localhost:" + ourPort + "/Observation/10"); + status = ourClient.execute(httpGet); + response = extractResponseAndClose(status); + ourLog.info(response); + assertThat(response, containsString("Access denied by rule: Default Rule")); + assertEquals(401, status.getStatusLine().getStatusCode()); + assertTrue(ourHitMethod); + } + @Test public void testMetadataAllow() throws Exception { ourServlet.registerInterceptor(new AuthorizationInterceptor(PolicyEnum.DENY) { @@ -140,42 +216,6 @@ public class AuthorizationInterceptorDstu2Test { extractResponseAndClose(status); assertEquals(200, status.getStatusLine().getStatusCode()); } - - @Test - public void testTransactionWriteGood() throws Exception { - ourServlet.registerInterceptor(new AuthorizationInterceptor(PolicyEnum.DENY) { - @Override - public List buildRuleList(RequestDetails theRequestDetails) { - //@formatter:off - return new RuleBuilder() - .allow("Rule 1").transaction().withAnyOperation().andApplyNormalRules().andThen() - .allow("Rule 2").write().allResources().inCompartment("Patient", new IdDt("Patient/1")).andThen() - .allow("Rule 2").read().allResources().inCompartment("Patient", new IdDt("Patient/1")).andThen() - .build(); - //@formatter:on - } - }); - - Bundle input = new Bundle(); - input.setType(BundleTypeEnum.TRANSACTION); - input.addEntry().setResource(createPatient(1)).getRequest().setUrl("/Patient"); - - Bundle output = new Bundle(); - output.setType(BundleTypeEnum.TRANSACTION_RESPONSE); - output.addEntry().getResponse().setLocation("/Patient/1"); - - HttpPost httpPost; - HttpResponse status; - String response; - - ourReturn = Arrays.asList((IResource)output); - ourHitMethod = false; - httpPost = new HttpPost("http://localhost:" + ourPort + "/"); - httpPost.setEntity(createFhirResourceEntity(input)); - status = ourClient.execute(httpPost); - extractResponseAndClose(status); - assertEquals(200, status.getStatusLine().getStatusCode()); - } @Test public void testMetadataDeny() throws Exception { @@ -259,81 +299,6 @@ public class AuthorizationInterceptorDstu2Test { } - @Test - public void testAllowAll() throws Exception { - ourServlet.registerInterceptor(new AuthorizationInterceptor(PolicyEnum.DENY) { - @Override - public List buildRuleList(RequestDetails theRequestDetails) { - //@formatter:off - return new RuleBuilder() - .deny("Rule 1").read().resourcesOfType(Patient.class).withAnyId().andThen() - .allowAll("Default Rule") - .build(); - //@formatter:on - } - }); - - HttpGet httpGet; - HttpResponse status; - String response; - - ourHitMethod = false; - ourReturn = Arrays.asList(createObservation(10, "Patient/2")); - httpGet = new HttpGet("http://localhost:" + ourPort + "/Observation/10"); - status = ourClient.execute(httpGet); - extractResponseAndClose(status); - assertEquals(200, status.getStatusLine().getStatusCode()); - assertTrue(ourHitMethod); - - ourHitMethod = false; - ourReturn = Arrays.asList(createPatient(2)); - httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/1"); - status = ourClient.execute(httpGet); - response = extractResponseAndClose(status); - ourLog.info(response); - assertThat(response, containsString("Access denied by rule: Rule 1")); - assertEquals(401, status.getStatusLine().getStatusCode()); - assertTrue(ourHitMethod); - } - - @Test - public void testDenyAll() throws Exception { - ourServlet.registerInterceptor(new AuthorizationInterceptor(PolicyEnum.DENY) { - @Override - public List buildRuleList(RequestDetails theRequestDetails) { - //@formatter:off - return new RuleBuilder() - .allow().read().resourcesOfType(Patient.class).withAnyId().andThen() - .denyAll("Default Rule") - .build(); - //@formatter:on - } - }); - - HttpGet httpGet; - HttpResponse status; - String response; - - ourHitMethod = false; - ourReturn = Arrays.asList(createPatient(2)); - httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/1"); - status = ourClient.execute(httpGet); - extractResponseAndClose(status); - assertEquals(200, status.getStatusLine().getStatusCode()); - assertTrue(ourHitMethod); - - ourHitMethod = false; - ourReturn = Arrays.asList(createObservation(10, "Patient/2")); - httpGet = new HttpGet("http://localhost:" + ourPort + "/Observation/10"); - status = ourClient.execute(httpGet); - response = extractResponseAndClose(status); - ourLog.info(response); - assertThat(response, containsString("Access denied by rule: Default Rule")); - assertEquals(401, status.getStatusLine().getStatusCode()); - assertTrue(ourHitMethod); - } - - @Test public void testReadByCompartmentRight() throws Exception { ourServlet.registerInterceptor(new AuthorizationInterceptor(PolicyEnum.DENY) { @@ -437,6 +402,43 @@ public class AuthorizationInterceptorDstu2Test { } + + @Test + public void testTransactionWriteGood() throws Exception { + ourServlet.registerInterceptor(new AuthorizationInterceptor(PolicyEnum.DENY) { + @Override + public List buildRuleList(RequestDetails theRequestDetails) { + //@formatter:off + return new RuleBuilder() + .allow("Rule 1").transaction().withAnyOperation().andApplyNormalRules().andThen() + .allow("Rule 2").write().allResources().inCompartment("Patient", new IdDt("Patient/1")).andThen() + .allow("Rule 2").read().allResources().inCompartment("Patient", new IdDt("Patient/1")).andThen() + .build(); + //@formatter:on + } + }); + + Bundle input = new Bundle(); + input.setType(BundleTypeEnum.TRANSACTION); + input.addEntry().setResource(createPatient(1)).getRequest().setUrl("/Patient"); + + Bundle output = new Bundle(); + output.setType(BundleTypeEnum.TRANSACTION_RESPONSE); + output.addEntry().getResponse().setLocation("/Patient/1"); + + HttpPost httpPost; + HttpResponse status; + String response; + + ourReturn = Arrays.asList((IResource)output); + ourHitMethod = false; + httpPost = new HttpPost("http://localhost:" + ourPort + "/"); + httpPost.setEntity(createFhirResourceEntity(input)); + status = ourClient.execute(httpPost); + extractResponseAndClose(status); + assertEquals(200, status.getStatusLine().getStatusCode()); + } + @Test public void testWriteByCompartmentCreate() throws Exception { ourServlet.registerInterceptor(new AuthorizationInterceptor(PolicyEnum.DENY) { @@ -567,9 +569,11 @@ public class AuthorizationInterceptorDstu2Test { assertFalse(ourHitMethod); } + @AfterClass - public static void afterClass() throws Exception { + public static void afterClassClearContext() throws Exception { ourServer.stop(); + TestUtil.clearAllStaticFieldsForUnitTest(); } @BeforeClass @@ -647,16 +651,6 @@ public class AuthorizationInterceptorDstu2Test { } - public static class PlainProvider - { - @Transaction() - public Bundle search(@TransactionParam Bundle theInput) { - ourHitMethod = true; - return (Bundle) ourReturn.get(0); - } - - } - public static class DummyPatientResourceProvider implements IResourceProvider { @Create() @@ -707,5 +701,15 @@ public class AuthorizationInterceptorDstu2Test { } } + + public static class PlainProvider + { + @Transaction() + public Bundle search(@TransactionParam Bundle theInput) { + ourHitMethod = true; + return (Bundle) ourReturn.get(0); + } + + } } 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 22e8a6b3737..4d3983127c6 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 @@ -9,6 +9,7 @@ import java.util.List; import java.util.Set; import org.hl7.fhir.instance.model.api.IBaseResource; +import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; @@ -24,6 +25,7 @@ import ca.uhn.fhir.model.dstu2.resource.Patient; import ca.uhn.fhir.model.dstu2.resource.Practitioner; import ca.uhn.fhir.model.dstu2.resource.Specimen; import ca.uhn.fhir.rest.server.BundleInclusionRule; +import ca.uhn.fhir.util.TestUtil; public class Dstu2BundleFactoryTest { private static FhirContext ourCtx; @@ -35,6 +37,12 @@ public class Dstu2BundleFactoryTest { ourCtx = FhirContext.forDstu2(); } + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + @Before public void setUp() throws Exception { // DiagnosticReport 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 f93cbc2943d..724a65e0e5f 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 @@ -15,6 +15,7 @@ import java.util.List; import org.hl7.fhir.instance.model.api.IBase; import org.hl7.fhir.instance.model.api.IBaseReference; +import org.junit.AfterClass; import org.junit.Test; import org.mockito.ArgumentCaptor; @@ -53,7 +54,13 @@ public class FhirTerserDstu2Test { assertSame(ref, refs.get(0)); } - + + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + @Test public void testGetAllPopulatedChildElementsOfTypeDoesntDescendIntoEmbedded() { Patient p = new Patient(); diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/validation/BundleValidationTest.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/validation/BundleValidationTest.java index a49dbf14ec8..e1fc74c458d 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/validation/BundleValidationTest.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/validation/BundleValidationTest.java @@ -8,12 +8,16 @@ import ca.uhn.fhir.model.dstu2.valueset.AppointmentStatusEnum; import ca.uhn.fhir.model.dstu2.valueset.BundleTypeEnum; import ca.uhn.fhir.model.dstu2.valueset.ParticipantTypeEnum; import ca.uhn.fhir.model.dstu2.valueset.ParticipationStatusEnum; +import ca.uhn.fhir.util.TestUtil; + import org.junit.Ignore; import org.junit.Test; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import org.junit.AfterClass; + /** * @author Bill de Beaubien on 11/30/2015. */ @@ -36,6 +40,12 @@ public class BundleValidationTest { } } + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + @Ignore @Test diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/validation/ResourceValidatorDstu2Test.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/validation/ResourceValidatorDstu2Test.java index d317fba0e96..c8f7c4b77d7 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/validation/ResourceValidatorDstu2Test.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/validation/ResourceValidatorDstu2Test.java @@ -15,6 +15,7 @@ import java.text.SimpleDateFormat; import org.apache.commons.io.IOUtils; import org.hamcrest.core.StringContains; +import org.junit.AfterClass; import org.junit.Test; import ca.uhn.fhir.context.FhirContext; @@ -32,6 +33,7 @@ import ca.uhn.fhir.model.dstu2.valueset.UnitsOfTimeEnum; import ca.uhn.fhir.model.primitive.DateDt; import ca.uhn.fhir.model.primitive.StringDt; import ca.uhn.fhir.parser.IParser; +import ca.uhn.fhir.util.TestUtil; import ca.uhn.fhir.validation.schematron.SchematronBaseValidator; public class ResourceValidatorDstu2Test { @@ -50,6 +52,12 @@ public class ResourceValidatorDstu2Test { return val; } + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + /** * See * https://groups.google.com/d/msgid/hapi-fhir/a266083f-6454-4cf0-a431-c6500f052bea%40googlegroups.com?utm_medium= diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/validation/ValidatorInstantiatorDstu2Test.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/validation/ValidatorInstantiatorDstu2Test.java index b70967139c4..87eb42fca87 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/validation/ValidatorInstantiatorDstu2Test.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/validation/ValidatorInstantiatorDstu2Test.java @@ -2,13 +2,22 @@ package ca.uhn.fhir.validation; import static org.junit.Assert.assertTrue; +import org.junit.AfterClass; import org.junit.Test; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.dstu2.resource.Patient; +import ca.uhn.fhir.util.TestUtil; public class ValidatorInstantiatorDstu2Test { + + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + private static FhirContext ourCtx = FhirContext.forDstu2(); @Test public void testValidator() { diff --git a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/context/FhirContextDstu3Test.java b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/context/FhirContextDstu3Test.java index 46441b01e3c..1f19c8623da 100644 --- a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/context/FhirContextDstu3Test.java +++ b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/context/FhirContextDstu3Test.java @@ -4,17 +4,24 @@ import static org.junit.Assert.assertEquals; import org.hl7.fhir.dstu3.model.Enumerations.AdministrativeGender; import org.hl7.fhir.dstu3.model.Patient; +import org.junit.AfterClass; import org.junit.Test; import ca.uhn.fhir.context.BaseRuntimeChildDatatypeDefinition; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.RuntimeResourceDefinition; import ca.uhn.fhir.rest.client.MyPatientWithExtensions; +import ca.uhn.fhir.util.TestUtil; public class FhirContextDstu3Test { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirContextDstu3Test.class); - private FhirContext ourCtx = FhirContext.forDstu3(); + private static FhirContext ourCtx = FhirContext.forDstu3(); + + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } @Test public void testCustomTypeDoesntBecomeDefault() { diff --git a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/context/ModelScannerDstu3Test.java b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/context/ModelScannerDstu3Test.java index 9d56667eece..881e88cd52d 100644 --- a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/context/ModelScannerDstu3Test.java +++ b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/context/ModelScannerDstu3Test.java @@ -15,6 +15,7 @@ import org.hl7.fhir.instance.model.api.IAnyResource; import org.hl7.fhir.instance.model.api.IBaseMetaType; import org.hl7.fhir.instance.model.api.IIdType; import org.hl7.fhir.instance.model.api.IPrimitiveType; +import org.junit.AfterClass; import org.junit.Ignore; import org.junit.Test; @@ -22,9 +23,16 @@ import ca.uhn.fhir.model.api.annotation.Compartment; import ca.uhn.fhir.model.api.annotation.ResourceDef; import ca.uhn.fhir.model.api.annotation.SearchParamDefinition; import ca.uhn.fhir.parser.DataFormatException; +import ca.uhn.fhir.util.TestUtil; public class ModelScannerDstu3Test { + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + @Test public void testBundleMustImplementIBaseBundle() throws DataFormatException { FhirContext ctx = FhirContext.forDstu3(); diff --git a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/context/RuntimeResourceDefinitionDstu3Test.java b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/context/RuntimeResourceDefinitionDstu3Test.java index 75940b35a56..091ddd508c4 100644 --- a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/context/RuntimeResourceDefinitionDstu3Test.java +++ b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/context/RuntimeResourceDefinitionDstu3Test.java @@ -4,8 +4,11 @@ import static org.junit.Assert.*; import org.hl7.fhir.dstu3.model.Bundle; import org.hl7.fhir.dstu3.model.Patient; +import org.junit.AfterClass; import org.junit.Test; +import ca.uhn.fhir.util.TestUtil; + public class RuntimeResourceDefinitionDstu3Test { private FhirContext ourCtx = FhirContext.forDstu3(); @@ -20,4 +23,10 @@ public class RuntimeResourceDefinitionDstu3Test { ourCtx.getResourceDefinition("Bundle").getImplementingClass(Patient.class); } + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + } diff --git a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/model/BaseDateTimeTypeDstu3Test.java b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/model/BaseDateTimeTypeDstu3Test.java index 40bd631d7d0..7e27026a52f 100644 --- a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/model/BaseDateTimeTypeDstu3Test.java +++ b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/model/BaseDateTimeTypeDstu3Test.java @@ -14,10 +14,13 @@ import java.util.TimeZone; import org.hl7.fhir.dstu3.model.DateTimeType; import org.hl7.fhir.dstu3.model.DateType; import org.hl7.fhir.dstu3.model.TemporalPrecisionEnum; +import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; +import ca.uhn.fhir.util.TestUtil; + public class BaseDateTimeTypeDstu3Test { private static Locale ourDefaultLocale; private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(BaseDateTimeTypeDstu3Test.class); @@ -27,6 +30,14 @@ public class BaseDateTimeTypeDstu3Test { public void before() { myDateInstantParser = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); } + + + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + @Test public void testMinutePrecisionEncode() throws Exception { diff --git a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/model/DateTypeTest.java b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/model/DateTypeTest.java index c38568d004a..808571a64e7 100644 --- a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/model/DateTypeTest.java +++ b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/model/DateTypeTest.java @@ -6,11 +6,21 @@ import java.util.Calendar; import java.util.TimeZone; import org.hl7.fhir.dstu3.model.DateType; +import org.junit.AfterClass; import org.junit.Test; +import ca.uhn.fhir.util.TestUtil; + public class DateTypeTest { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(DateTypeTest.class); + + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + @Test public void testPrecision() { diff --git a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/model/IdTypeDstu3Test.java b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/model/IdTypeDstu3Test.java index eb2e2c18e52..37162e19ad9 100644 --- a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/model/IdTypeDstu3Test.java +++ b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/model/IdTypeDstu3Test.java @@ -10,10 +10,12 @@ import java.math.BigDecimal; import org.hl7.fhir.dstu3.model.IdType; import org.hl7.fhir.dstu3.model.Patient; import org.hl7.fhir.dstu3.model.Reference; +import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.util.TestUtil; public class IdTypeDstu3Test { @@ -21,6 +23,12 @@ public class IdTypeDstu3Test { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(IdTypeDstu3Test.class); + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + @Test public void testDetectLocal() { IdType id; diff --git a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/model/ModelDstu3Test.java b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/model/ModelDstu3Test.java index 6ad5dcd8fac..4c6033e5e2d 100644 --- a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/model/ModelDstu3Test.java +++ b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/model/ModelDstu3Test.java @@ -14,9 +14,11 @@ import org.hl7.fhir.dstu3.model.HumanName; import org.hl7.fhir.dstu3.model.Patient; import org.hl7.fhir.dstu3.model.Practitioner; import org.hl7.fhir.dstu3.model.Practitioner.PractitionerPractitionerRoleComponent; +import org.junit.AfterClass; import org.junit.Test; import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.util.TestUtil; public class ModelDstu3Test { @@ -33,6 +35,12 @@ public class ModelDstu3Test { assertEquals(CodeableConcept.class, roleField.getClass()); } + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + /** * See #304 */ diff --git a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/model/ModelSerializationDstu3Test.java b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/model/ModelSerializationDstu3Test.java index ad3468f419d..50904bd40f9 100644 --- a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/model/ModelSerializationDstu3Test.java +++ b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/model/ModelSerializationDstu3Test.java @@ -11,11 +11,13 @@ import org.hl7.fhir.dstu3.model.Enumerations.AdministrativeGender; import org.hl7.fhir.dstu3.model.HumanName; import org.hl7.fhir.dstu3.model.Patient; import org.hl7.fhir.instance.model.api.IBaseResource; +import org.junit.AfterClass; import org.junit.Test; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.api.TemporalPrecisionEnum; import ca.uhn.fhir.parser.IParser; +import ca.uhn.fhir.util.TestUtil; public class ModelSerializationDstu3Test { @@ -34,6 +36,12 @@ public class ModelSerializationDstu3Test { assertEquals(AdministrativeGender.MALE, deserialized); } + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + @Test public void testBoundCodeSerialization() { Patient p = new Patient(); diff --git a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/narrative/DefaultThymeleafNarrativeGeneratorDstu3Test.java b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/narrative/DefaultThymeleafNarrativeGeneratorDstu3Test.java index ca8f548cb1e..c61acf22e2f 100644 --- a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/narrative/DefaultThymeleafNarrativeGeneratorDstu3Test.java +++ b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/narrative/DefaultThymeleafNarrativeGeneratorDstu3Test.java @@ -28,12 +28,14 @@ import org.hl7.fhir.dstu3.model.DiagnosticReport.DiagnosticReportStatus; import org.hl7.fhir.dstu3.model.Encounter.EncounterClass; import org.hl7.fhir.dstu3.model.MedicationOrder.MedicationOrderStatus; import org.hl7.fhir.dstu3.model.Observation.ObservationStatus; +import org.junit.AfterClass; import org.junit.Before; import org.junit.Ignore; import org.junit.Test; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.parser.DataFormatException; +import ca.uhn.fhir.util.TestUtil; public class DefaultThymeleafNarrativeGeneratorDstu3Test { private static FhirContext ourCtx = FhirContext.forDstu3(); @@ -50,6 +52,13 @@ public class DefaultThymeleafNarrativeGeneratorDstu3Test { ourCtx.setNarrativeGenerator(myGen); } + + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + @Test public void testGeneratePatient() throws DataFormatException { Patient value = new Patient(); diff --git a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/parser/CustomTypeDstu3Test.java b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/parser/CustomTypeDstu3Test.java index d2492a5fa90..1d481d79dd4 100644 --- a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/parser/CustomTypeDstu3Test.java +++ b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/parser/CustomTypeDstu3Test.java @@ -16,6 +16,7 @@ import org.hl7.fhir.dstu3.model.MedicationOrder; import org.hl7.fhir.dstu3.model.Patient; import org.hl7.fhir.dstu3.model.Quantity; import org.hl7.fhir.dstu3.model.StringType; +import org.junit.AfterClass; import org.junit.Before; import org.junit.Test; @@ -28,6 +29,7 @@ import ca.uhn.fhir.model.primitive.DateTimeDt; import ca.uhn.fhir.model.primitive.StringDt; import ca.uhn.fhir.rest.server.AddProfileTagEnum; import ca.uhn.fhir.util.ElementUtil; +import ca.uhn.fhir.util.TestUtil; public class CustomTypeDstu3Test { @@ -38,7 +40,13 @@ public class CustomTypeDstu3Test { public void before() { ourCtx.setAddProfileTagWhenEncoding(AddProfileTagEnum.ONLY_FOR_CUSTOM); } - + + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + @Test public void parseBundleWithResourceDirective() { diff --git a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/parser/EmptyElementWithExtensionDstu3Test.java b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/parser/EmptyElementWithExtensionDstu3Test.java index cecf7b801f5..9edf653c141 100644 --- a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/parser/EmptyElementWithExtensionDstu3Test.java +++ b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/parser/EmptyElementWithExtensionDstu3Test.java @@ -6,9 +6,11 @@ import org.hl7.fhir.dstu3.model.Coding; import org.hl7.fhir.dstu3.model.Extension; import org.hl7.fhir.dstu3.model.Observation; import org.hl7.fhir.dstu3.model.StringType; +import org.junit.AfterClass; import org.junit.Test; import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.util.TestUtil; /** * Created by Bill de Beaubien on 12/20/2015. @@ -18,6 +20,13 @@ public class EmptyElementWithExtensionDstu3Test { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(EmptyElementWithExtensionDstu3Test.class); private static FhirContext ctx = FhirContext.forDstu3(); + + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + @Test public void testNullFlavorCompositeJson() throws Exception { Observation observation = new Observation(); diff --git a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/parser/JsonParserDstu3Test.java b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/parser/JsonParserDstu3Test.java index 13b37c11b88..3bdfb9860ec 100644 --- a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/parser/JsonParserDstu3Test.java +++ b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/parser/JsonParserDstu3Test.java @@ -58,6 +58,7 @@ import org.hl7.fhir.dstu3.model.StringType; import org.hl7.fhir.dstu3.model.UriType; import org.hl7.fhir.utilities.xhtml.XhtmlNode; import org.junit.After; +import org.junit.AfterClass; import org.junit.Assert; import org.junit.Ignore; import org.junit.Test; @@ -67,6 +68,7 @@ import com.google.common.collect.Sets; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.narrative.DefaultThymeleafNarrativeGenerator; import ca.uhn.fhir.rest.server.Constants; +import ca.uhn.fhir.util.TestUtil; import net.sf.json.JSON; import net.sf.json.JSONSerializer; import net.sf.json.JsonConfig; @@ -80,7 +82,13 @@ public class JsonParserDstu3Test { ourCtx.setNarrativeGenerator(null); } - + + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + @Test public void testEncodeAndParseExtensions() throws Exception { diff --git a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/parser/RoundTripDstu3Test.java b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/parser/RoundTripDstu3Test.java index 9fd8d52fa1e..2619d9bbd92 100644 --- a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/parser/RoundTripDstu3Test.java +++ b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/parser/RoundTripDstu3Test.java @@ -17,9 +17,11 @@ import javax.xml.stream.events.XMLEvent; import org.custommonkey.xmlunit.DetailedDiff; import org.custommonkey.xmlunit.Diff; import org.hl7.fhir.instance.model.api.IBaseResource; +import org.junit.AfterClass; import org.junit.Test; import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.util.TestUtil; import ca.uhn.fhir.util.XmlUtil; public class RoundTripDstu3Test { @@ -30,7 +32,13 @@ public class RoundTripDstu3Test { public void testIt() { // Just so this doesn't complain until we enable roundtrip test } - + + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + // @Test public void testRoundTrip() throws Exception { ZipInputStream is = new ZipInputStream(new FileInputStream("src/test/resources/examples.zip")); diff --git a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/parser/XmlParserDstu3Test.java b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/parser/XmlParserDstu3Test.java index 44139ebd952..266c8d228e3 100644 --- a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/parser/XmlParserDstu3Test.java +++ b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/parser/XmlParserDstu3Test.java @@ -85,6 +85,7 @@ import org.hl7.fhir.dstu3.model.UriType; import org.hl7.fhir.dstu3.model.ValueSet; import org.hl7.fhir.instance.model.api.IBaseResource; import org.junit.After; +import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Ignore; import org.junit.Test; @@ -97,6 +98,7 @@ import ca.uhn.fhir.narrative.DefaultThymeleafNarrativeGenerator; import ca.uhn.fhir.parser.IParserErrorHandler.IParseLocation; import ca.uhn.fhir.rest.client.IGenericClient; import ca.uhn.fhir.rest.server.Constants; +import ca.uhn.fhir.util.TestUtil; public class XmlParserDstu3Test { private static final FhirContext ourCtx = FhirContext.forDstu3(); @@ -107,6 +109,12 @@ public class XmlParserDstu3Test { ourCtx.setNarrativeGenerator(null); } + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + @Test public void testBundleWithBinary() { //@formatter:off diff --git a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/client/ClientWithCustomTypeDstu3Test.java b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/client/ClientWithCustomTypeDstu3Test.java index ff0a2c29a63..78d298c5a1d 100644 --- a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/client/ClientWithCustomTypeDstu3Test.java +++ b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/client/ClientWithCustomTypeDstu3Test.java @@ -25,6 +25,7 @@ import org.hl7.fhir.dstu3.model.Binary; import org.hl7.fhir.dstu3.model.Conformance; import org.hl7.fhir.dstu3.model.OperationOutcome; import org.hl7.fhir.dstu3.model.Patient; +import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; @@ -36,6 +37,7 @@ import org.mockito.stubbing.Answer; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.parser.IParser; import ca.uhn.fhir.rest.server.Constants; +import ca.uhn.fhir.util.TestUtil; import ca.uhn.fhir.util.VersionUtil; public class ClientWithCustomTypeDstu3Test { @@ -44,6 +46,12 @@ public class ClientWithCustomTypeDstu3Test { private HttpClient myHttpClient; private HttpResponse myHttpResponse; + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + @Before public void before() { myHttpClient = mock(HttpClient.class, new ReturnsDeepStubs()); diff --git a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/client/GenericClientDstu3Test.java b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/client/GenericClientDstu3Test.java index 45233cbf4ab..69c38f4bea5 100644 --- a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/client/GenericClientDstu3Test.java +++ b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/client/GenericClientDstu3Test.java @@ -30,6 +30,7 @@ import org.hl7.fhir.dstu3.model.OperationOutcome; import org.hl7.fhir.dstu3.model.Parameters; import org.hl7.fhir.dstu3.model.Patient; import org.hl7.fhir.instance.model.api.IBaseResource; +import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; @@ -43,6 +44,7 @@ import ca.uhn.fhir.parser.CustomTypeDstu3Test; import ca.uhn.fhir.parser.CustomTypeDstu3Test.MyCustomPatient; import ca.uhn.fhir.parser.IParser; import ca.uhn.fhir.rest.server.Constants; +import ca.uhn.fhir.util.TestUtil; import ca.uhn.fhir.util.VersionUtil; public class GenericClientDstu3Test { @@ -51,6 +53,12 @@ public class GenericClientDstu3Test { private HttpClient myHttpClient; private HttpResponse myHttpResponse; + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + @Before public void before() { myHttpClient = mock(HttpClient.class, new ReturnsDeepStubs()); diff --git a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/client/OperationClientDstu3Test.java b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/client/OperationClientDstu3Test.java index 24199e58379..9e98f06af14 100644 --- a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/client/OperationClientDstu3Test.java +++ b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/client/OperationClientDstu3Test.java @@ -21,6 +21,7 @@ import org.apache.http.message.BasicHeader; import org.apache.http.message.BasicStatusLine; import org.hl7.fhir.dstu3.model.Parameters; import org.hl7.fhir.dstu3.model.StringType; +import org.junit.AfterClass; import org.junit.Before; import org.junit.Test; import org.mockito.ArgumentCaptor; @@ -39,6 +40,7 @@ import ca.uhn.fhir.rest.param.TokenAndListParam; import ca.uhn.fhir.rest.param.TokenOrListParam; import ca.uhn.fhir.rest.param.TokenParam; import ca.uhn.fhir.rest.server.Constants; +import ca.uhn.fhir.util.TestUtil; public class OperationClientDstu3Test { @@ -51,6 +53,13 @@ public class OperationClientDstu3Test { private ArgumentCaptor capt; private IGenericClient ourGenClient; + + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + @Before public void before() throws Exception { ourCtx = FhirContext.forDstu3(); diff --git a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/client/SearchClientDstu3Test.java b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/client/SearchClientDstu3Test.java index a62275a9d2b..1d2fbb6bd0a 100644 --- a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/client/SearchClientDstu3Test.java +++ b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/client/SearchClientDstu3Test.java @@ -21,6 +21,7 @@ import org.hl7.fhir.dstu3.model.Bundle; import org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent; import org.hl7.fhir.dstu3.model.Extension; import org.hl7.fhir.dstu3.model.Location; +import org.junit.AfterClass; import org.junit.Before; import org.junit.Test; import org.mockito.ArgumentCaptor; @@ -35,6 +36,7 @@ import ca.uhn.fhir.rest.annotation.Search; import ca.uhn.fhir.rest.client.api.IRestfulClient; import ca.uhn.fhir.rest.param.StringParam; import ca.uhn.fhir.rest.server.Constants; +import ca.uhn.fhir.util.TestUtil; public class SearchClientDstu3Test { @@ -44,6 +46,12 @@ public class SearchClientDstu3Test { private HttpClient ourHttpClient; private HttpResponse ourHttpResponse; + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + @Before public void before() { ourCtx = FhirContext.forDstu3(); diff --git a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/server/CreateBinaryDstu3Test.java b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/server/CreateBinaryDstu3Test.java index 88a39f956a7..236f65eb4a5 100644 --- a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/server/CreateBinaryDstu3Test.java +++ b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/server/CreateBinaryDstu3Test.java @@ -29,18 +29,18 @@ import ca.uhn.fhir.rest.annotation.Create; import ca.uhn.fhir.rest.annotation.ResourceParam; import ca.uhn.fhir.rest.api.MethodOutcome; import ca.uhn.fhir.util.PortUtil; +import ca.uhn.fhir.util.TestUtil; public class CreateBinaryDstu3Test { private static CloseableHttpClient ourClient; - private static int ourPort; private static FhirContext ourCtx = FhirContext.forDstu3(); - private static Server ourServer; private static Binary ourLastBinary; - private static String ourLastBinaryString; private static byte[] ourLastBinaryBytes; + private static String ourLastBinaryString; + private static int ourPort; + private static Server ourServer; - - + @Before public void before() { ourLastBinary = null; @@ -49,16 +49,7 @@ public class CreateBinaryDstu3Test { } - @Test - public void testRawBytesNoContentType() throws Exception { - HttpPost post = new HttpPost("http://localhost:" + ourPort + "/Binary"); - post.setEntity(new ByteArrayEntity(new byte[] {0,1,2,3,4})); - ourClient.execute(post); - - assertNull(ourLastBinary.getContentType()); - assertArrayEquals(new byte[] {0,1,2,3,4}, ourLastBinary.getContent()); - } - + @Test public void testRawBytesBinaryContentType() throws Exception { HttpPost post = new HttpPost("http://localhost:" + ourPort + "/Binary"); @@ -70,7 +61,8 @@ public class CreateBinaryDstu3Test { assertArrayEquals(new byte[] {0,1,2,3,4}, ourLastBinary.getContent()); assertArrayEquals(new byte[] {0,1,2,3,4}, ourLastBinaryBytes); } - + + /** * Technically the client shouldn't be doing it this way, * but we'll be accepting @@ -113,10 +105,21 @@ public class CreateBinaryDstu3Test { assertEquals(encoded, ourLastBinaryString); assertArrayEquals(encoded.getBytes("UTF-8"), ourLastBinaryBytes); } + + @Test + public void testRawBytesNoContentType() throws Exception { + HttpPost post = new HttpPost("http://localhost:" + ourPort + "/Binary"); + post.setEntity(new ByteArrayEntity(new byte[] {0,1,2,3,4})); + ourClient.execute(post); + + assertNull(ourLastBinary.getContentType()); + assertArrayEquals(new byte[] {0,1,2,3,4}, ourLastBinary.getContent()); + } @AfterClass - public static void afterClass() throws Exception { + public static void afterClassClearContext() throws Exception { ourServer.stop(); + TestUtil.clearAllStaticFieldsForUnitTest(); } @@ -143,11 +146,6 @@ public class CreateBinaryDstu3Test { public static class BinaryProvider implements IResourceProvider { - @Override - public Class getResourceType() { - return Binary.class; - } - @Create() public MethodOutcome createBinary(@ResourceParam Binary theBinary, @ResourceParam String theBinaryString, @ResourceParam byte[] theBinaryBytes) { ourLastBinary = theBinary; @@ -155,6 +153,11 @@ public class CreateBinaryDstu3Test { ourLastBinaryBytes = theBinaryBytes; return new MethodOutcome(new IdType("Binary/001/_history/002")); } + + @Override + public Class getResourceType() { + return Binary.class; + } } diff --git a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/server/CreateDstu3Test.java b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/server/CreateDstu3Test.java index 3aad140a989..1229f9ba27f 100644 --- a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/server/CreateDstu3Test.java +++ b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/server/CreateDstu3Test.java @@ -33,6 +33,7 @@ import ca.uhn.fhir.rest.annotation.Read; import ca.uhn.fhir.rest.annotation.Search; import ca.uhn.fhir.rest.client.MyPatientWithExtensions; import ca.uhn.fhir.util.PortUtil; +import ca.uhn.fhir.util.TestUtil; public class CreateDstu3Test { private static CloseableHttpClient ourClient; @@ -69,6 +70,7 @@ public class CreateDstu3Test { //@formatter:on } + @Test public void testSearch() throws Exception { @@ -99,8 +101,9 @@ public class CreateDstu3Test { } @AfterClass - public static void afterClass() throws Exception { + public static void afterClassClearContext() throws Exception { ourServer.stop(); + TestUtil.clearAllStaticFieldsForUnitTest(); } @BeforeClass diff --git a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/server/CustomTypeServerDstu3.java b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/server/CustomTypeServerDstu3.java index 3bb93458051..cc33de4633f 100644 --- a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/server/CustomTypeServerDstu3.java +++ b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/server/CustomTypeServerDstu3.java @@ -38,18 +38,19 @@ import ca.uhn.fhir.rest.annotation.ResourceParam; import ca.uhn.fhir.rest.annotation.Search; import ca.uhn.fhir.rest.api.MethodOutcome; import ca.uhn.fhir.util.PortUtil; +import ca.uhn.fhir.util.TestUtil; public class CustomTypeServerDstu3 { private static CloseableHttpClient ourClient; + private static FhirContext ourCtx = FhirContext.forDstu3(); private static String ourLastConditionalUrl; - private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(CustomTypeServerDstu3.class); - private static int ourPort; - private static Server ourServer; private static IdType ourLastId; private static IdType ourLastIdParam; private static boolean ourLastRequestWasSearch; - private static FhirContext ourCtx = FhirContext.forDstu3(); + private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(CustomTypeServerDstu3.class); + private static int ourPort; + private static Server ourServer; @Before public void before() { @@ -59,6 +60,7 @@ public class CustomTypeServerDstu3 { ourLastRequestWasSearch = false; } + @Test public void testCreateWithIdInBody() throws Exception { @@ -126,9 +128,11 @@ public class CustomTypeServerDstu3 { assertEquals("Can not create resource with ID \"2\", ID must not be supplied on a create (POST) operation (use an HTTP PUT / update operation if you wish to supply an ID)", oo.getIssue().get(0).getDiagnostics()); } + @AfterClass - public static void afterClass() throws Exception { + public static void afterClassClearContext() throws Exception { ourServer.stop(); + TestUtil.clearAllStaticFieldsForUnitTest(); } @BeforeClass @@ -155,6 +159,14 @@ public class CustomTypeServerDstu3 { public static class PatientProvider implements IResourceProvider { + @Create() + public MethodOutcome createPatient(@ResourceParam Patient thePatient, @ConditionalUrlParam String theConditional, @IdParam IdType theIdParam) { + ourLastConditionalUrl = theConditional; + ourLastId = thePatient.getIdElement(); + ourLastIdParam = theIdParam; + return new MethodOutcome(new IdType("Patient/001/_history/002")); + } + @Override public Class getResourceType() { return Patient.class; @@ -166,14 +178,6 @@ public class CustomTypeServerDstu3 { return new ArrayList(); } - @Create() - public MethodOutcome createPatient(@ResourceParam Patient thePatient, @ConditionalUrlParam String theConditional, @IdParam IdType theIdParam) { - ourLastConditionalUrl = theConditional; - ourLastId = thePatient.getIdElement(); - ourLastIdParam = theIdParam; - return new MethodOutcome(new IdType("Patient/001/_history/002")); - } - } } diff --git a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/server/DeleteConditionalDstu3Test.java b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/server/DeleteConditionalDstu3Test.java index bad1a18c6dc..4a2405e2262 100644 --- a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/server/DeleteConditionalDstu3Test.java +++ b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/server/DeleteConditionalDstu3Test.java @@ -43,20 +43,20 @@ import ca.uhn.fhir.rest.api.MethodOutcome; import ca.uhn.fhir.rest.client.IGenericClient; import ca.uhn.fhir.rest.client.interceptor.LoggingInterceptor; import ca.uhn.fhir.util.PortUtil; +import ca.uhn.fhir.util.TestUtil; public class DeleteConditionalDstu3Test { private static CloseableHttpClient ourClient; - private static String ourLastConditionalUrl; - private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(DeleteConditionalDstu3Test.class); - private static int ourPort; private static FhirContext ourCtx = FhirContext.forDstu3(); - private static Server ourServer; + private static IGenericClient ourHapiClient; + private static String ourLastConditionalUrl; private static IdType ourLastIdParam; private static boolean ourLastRequestWasDelete; - private static IGenericClient ourHapiClient; - - + private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(DeleteConditionalDstu3Test.class); + private static int ourPort; + private static Server ourServer; + @Before public void before() { ourLastConditionalUrl = null; @@ -65,6 +65,7 @@ public class DeleteConditionalDstu3Test { } + @Test public void testSearchStillWorks() throws Exception { @@ -94,10 +95,12 @@ public class DeleteConditionalDstu3Test { } + @AfterClass - public static void afterClass() throws Exception { + public static void afterClassClearContext() throws Exception { ourServer.stop(); + TestUtil.clearAllStaticFieldsForUnitTest(); } @@ -128,11 +131,6 @@ public class DeleteConditionalDstu3Test { public static class PatientProvider implements IResourceProvider { - @Override - public Class getResourceType() { - return Patient.class; - } - @Delete() public MethodOutcome deletePatient(@IdParam IdType theIdParam, @ConditionalUrlParam String theConditional) { ourLastRequestWasDelete = true; @@ -140,6 +138,11 @@ public class DeleteConditionalDstu3Test { ourLastIdParam = theIdParam; return new MethodOutcome(new IdType("Patient/001/_history/002")); } + + @Override + public Class getResourceType() { + return Patient.class; + } } diff --git a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/server/InterceptorDstu3Test.java b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/server/InterceptorDstu3Test.java index 37eed11edba..857ecf5ee8b 100644 --- a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/server/InterceptorDstu3Test.java +++ b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/server/InterceptorDstu3Test.java @@ -42,16 +42,25 @@ import ca.uhn.fhir.rest.method.RequestDetails; import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor; import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor.ActionRequestDetails; import ca.uhn.fhir.util.PortUtil; +import ca.uhn.fhir.util.TestUtil; public class InterceptorDstu3Test { private static CloseableHttpClient ourClient; + private static final FhirContext ourCtx = FhirContext.forDstu3(); private static int ourPort; private static Server ourServer; private static RestfulServer servlet; private IServerInterceptor myInterceptor1; private IServerInterceptor myInterceptor2; - private static final FhirContext ourCtx = FhirContext.forDstu3(); + + @Before + public void before() { + myInterceptor1 = mock(IServerInterceptor.class); + myInterceptor2 = mock(IServerInterceptor.class); + servlet.setInterceptors(myInterceptor1, myInterceptor2); + } + @Test public void testValidate() throws Exception { @@ -108,15 +117,9 @@ public class InterceptorDstu3Test { } @AfterClass - public static void afterClass() throws Exception { + public static void afterClassClearContext() throws Exception { ourServer.stop(); - } - - @Before - public void before() { - myInterceptor1 = mock(IServerInterceptor.class); - myInterceptor2 = mock(IServerInterceptor.class); - servlet.setInterceptors(myInterceptor1, myInterceptor2); + TestUtil.clearAllStaticFieldsForUnitTest(); } @BeforeClass @@ -143,15 +146,15 @@ public class InterceptorDstu3Test { public static class DummyPatientResourceProvider implements IResourceProvider { - @Validate() - public MethodOutcome validate(@ResourceParam Patient theResource) { - return new MethodOutcome(); - } - @Override public Class getResourceType() { return Patient.class; } + + @Validate() + public MethodOutcome validate(@ResourceParam Patient theResource) { + return new MethodOutcome(); + } } } diff --git a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/server/MetadataDstu3Test2.java b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/server/MetadataDstu3Test2.java index 8af0b4c4b9d..414277de037 100644 --- a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/server/MetadataDstu3Test2.java +++ b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/server/MetadataDstu3Test2.java @@ -27,14 +27,15 @@ import ca.uhn.fhir.rest.annotation.ResourceParam; import ca.uhn.fhir.rest.annotation.Validate; import ca.uhn.fhir.rest.api.MethodOutcome; import ca.uhn.fhir.util.PortUtil; +import ca.uhn.fhir.util.TestUtil; public class MetadataDstu3Test2 { private static CloseableHttpClient ourClient; + private static final FhirContext ourCtx = FhirContext.forDstu3(); private static int ourPort; private static Server ourServer; private static RestfulServer servlet; - private static final FhirContext ourCtx = FhirContext.forDstu3(); @Test public void testHttpMethods() throws Exception { @@ -66,8 +67,9 @@ public class MetadataDstu3Test2 { } @AfterClass - public static void afterClass() throws Exception { + public static void afterClassClearContext() throws Exception { ourServer.stop(); + TestUtil.clearAllStaticFieldsForUnitTest(); } @BeforeClass @@ -94,15 +96,15 @@ public class MetadataDstu3Test2 { public static class DummyPatientResourceProvider implements IResourceProvider { - @Validate() - public MethodOutcome validate(@ResourceParam Patient theResource) { - return new MethodOutcome(); - } - @Override public Class getResourceType() { return Patient.class; } + + @Validate() + public MethodOutcome validate(@ResourceParam Patient theResource) { + return new MethodOutcome(); + } } } diff --git a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/server/OperationServerWithSearchParamTypesDstu3Test.java b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/server/OperationServerWithSearchParamTypesDstu3Test.java index e06620b11e5..1f2c56c0ee9 100644 --- a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/server/OperationServerWithSearchParamTypesDstu3Test.java +++ b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/server/OperationServerWithSearchParamTypesDstu3Test.java @@ -50,6 +50,7 @@ import ca.uhn.fhir.rest.param.TokenOrListParam; import ca.uhn.fhir.rest.param.TokenParam; import ca.uhn.fhir.rest.param.TokenParamModifier; import ca.uhn.fhir.util.PortUtil; +import ca.uhn.fhir.util.TestUtil; import ca.uhn.fhir.util.UrlUtil; public class OperationServerWithSearchParamTypesDstu3Test { @@ -62,7 +63,6 @@ public class OperationServerWithSearchParamTypesDstu3Test { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(OperationServerWithSearchParamTypesDstu3Test.class); private static int ourPort; private static Server ourServer; - @Before public void before() { ourLastMethod = ""; @@ -244,6 +244,7 @@ public class OperationServerWithSearchParamTypesDstu3Test { //@formatter:on } + @Test public void testNonRepeatingWithParams() throws Exception { Parameters p = new Parameters(); @@ -269,7 +270,6 @@ public class OperationServerWithSearchParamTypesDstu3Test { assertEquals("VALTOKB", ourLastParamValTok.get(0).getValuesAsQueryTokens().get(0).getValue()); assertEquals("type $nonrepeating", ourLastMethod); } - @Test public void testNonRepeatingWithUrl() throws Exception { HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/$nonrepeating?valstr=VALSTR&valtok=" + UrlUtil.escape("VALTOKA|VALTOKB")); @@ -289,7 +289,7 @@ public class OperationServerWithSearchParamTypesDstu3Test { assertEquals("VALTOKB", ourLastParamValTok.get(0).getValuesAsQueryTokens().get(0).getValue()); assertEquals("type $nonrepeating", ourLastMethod); } - + @Test public void testNonRepeatingWithUrlQualified() throws Exception { HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/$nonrepeating?valstr:exact=VALSTR&valtok:not=" + UrlUtil.escape("VALTOKA|VALTOKB")); @@ -311,7 +311,7 @@ public class OperationServerWithSearchParamTypesDstu3Test { assertEquals(TokenParamModifier.NOT, ourLastParamValTok.get(0).getValuesAsQueryTokens().get(0).getModifier()); assertEquals("type $nonrepeating", ourLastMethod); } - + @Test public void testOrListWithParameters() throws Exception { Parameters p = new Parameters(); @@ -371,8 +371,9 @@ public class OperationServerWithSearchParamTypesDstu3Test { } @AfterClass - public static void afterClass() throws Exception { + public static void afterClassClearContext() throws Exception { ourServer.stop(); + TestUtil.clearAllStaticFieldsForUnitTest(); } @BeforeClass public static void beforeClass() throws Exception { diff --git a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/server/RequestValidatingInterceptorDstu3Test.java b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/server/RequestValidatingInterceptorDstu3Test.java index 99f0f7d8dc9..9b389631cff 100644 --- a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/server/RequestValidatingInterceptorDstu3Test.java +++ b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/server/RequestValidatingInterceptorDstu3Test.java @@ -43,6 +43,7 @@ import ca.uhn.fhir.rest.api.MethodOutcome; import ca.uhn.fhir.rest.param.StringParam; import ca.uhn.fhir.rest.server.interceptor.RequestValidatingInterceptor; import ca.uhn.fhir.util.PortUtil; +import ca.uhn.fhir.util.TestUtil; import ca.uhn.fhir.validation.IValidatorModule; import ca.uhn.fhir.validation.ResultSeverityEnum; @@ -58,10 +59,9 @@ public class RequestValidatingInterceptorDstu3Test { private static RestfulServer ourServlet; - - private RequestValidatingInterceptor myInterceptor; + @Before public void before() { ourLastRequestWasSearch = false; @@ -78,53 +78,6 @@ public class RequestValidatingInterceptorDstu3Test { ourServlet.registerInterceptor(myInterceptor); } - @Test - public void testCreateJsonInvalidNoValidatorsSpecified() throws Exception { - myInterceptor.setAddResponseHeaderOnSeverity(ResultSeverityEnum.INFORMATION); - - Patient patient = new Patient(); - patient.addIdentifier().setValue("002"); - patient.setGender(AdministrativeGender.MALE); - patient.addContact().addRelationship().setText("FOO"); - String encoded = ourCtx.newJsonParser().encodeResourceToString(patient); - - HttpPost httpPost = new HttpPost("http://localhost:" + ourPort + "/Patient"); - httpPost.setEntity(new StringEntity(encoded, 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{}", status); - ourLog.info("Response was:\n{}", responseContent); - - assertEquals(422, status.getStatusLine().getStatusCode()); - assertThat(status.toString(), containsString("X-FHIR-Request-Validation")); - assertThat(responseContent, containsString("")); - } - - @Test - public void testFetchMetadata() throws Exception { - myInterceptor.setAddResponseHeaderOnSeverity(ResultSeverityEnum.INFORMATION); - - HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/metadata"); - - // This header caused a crash - httpGet.addHeader("Content-Type", "application/xml+fhir"); - - HttpResponse status = ourClient.execute(httpGet); - - String responseContent = IOUtils.toString(status.getEntity().getContent()); - IOUtils.closeQuietly(status.getEntity().getContent()); - - ourLog.info("Response was:\n{}", status); - ourLog.info("Response was:\n{}", responseContent); - - assertEquals(200, status.getStatusLine().getStatusCode()); - assertThat(responseContent, containsString("Conformance")); - } - @Test public void testCreateJsonInvalidNoFailure() throws Exception { myInterceptor.setFailOnSeverity(null); @@ -151,7 +104,33 @@ public class RequestValidatingInterceptorDstu3Test { assertThat(status.toString(), containsString("X-FHIR-Request-Validation")); assertThat(responseContent, not(containsString(""))); } - + + @Test + public void testCreateJsonInvalidNoValidatorsSpecified() throws Exception { + myInterceptor.setAddResponseHeaderOnSeverity(ResultSeverityEnum.INFORMATION); + + Patient patient = new Patient(); + patient.addIdentifier().setValue("002"); + patient.setGender(AdministrativeGender.MALE); + patient.addContact().addRelationship().setText("FOO"); + String encoded = ourCtx.newJsonParser().encodeResourceToString(patient); + + HttpPost httpPost = new HttpPost("http://localhost:" + ourPort + "/Patient"); + httpPost.setEntity(new StringEntity(encoded, 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{}", status); + ourLog.info("Response was:\n{}", responseContent); + + assertEquals(422, status.getStatusLine().getStatusCode()); + assertThat(status.toString(), containsString("X-FHIR-Request-Validation")); + assertThat(responseContent, containsString("")); + } + @Test public void testCreateJsonValidNoValidatorsSpecified() throws Exception { Patient patient = new Patient(); @@ -200,7 +179,10 @@ public class RequestValidatingInterceptorDstu3Test { } @Test - public void testCreateXmlInvalidNoValidatorsSpecified() throws Exception { + public void testCreateXmlInvalidInstanceValidator() throws Exception { + IValidatorModule module = new FhirInstanceValidator(); + myInterceptor.addValidatorModule(module); + myInterceptor.setAddResponseHeaderOnSeverity(ResultSeverityEnum.INFORMATION); myInterceptor.setAddResponseHeaderOnSeverity(ResultSeverityEnum.INFORMATION); Patient patient = new Patient(); @@ -224,7 +206,31 @@ public class RequestValidatingInterceptorDstu3Test { assertThat(status.toString(), containsString("X-FHIR-Request-Validation")); } + @Test + public void testCreateXmlInvalidNoValidatorsSpecified() throws Exception { + myInterceptor.setAddResponseHeaderOnSeverity(ResultSeverityEnum.INFORMATION); + Patient patient = new Patient(); + patient.addIdentifier().setValue("002"); + patient.setGender(AdministrativeGender.MALE); + patient.addContact().addRelationship().setText("FOO"); + String encoded = ourCtx.newXmlParser().encodeResourceToString(patient); + + HttpPost httpPost = new HttpPost("http://localhost:" + ourPort + "/Patient"); + httpPost.setEntity(new StringEntity(encoded, ContentType.create(Constants.CT_FHIR_XML, "UTF-8"))); + + HttpResponse status = ourClient.execute(httpPost); + + String responseContent = IOUtils.toString(status.getEntity().getContent()); + IOUtils.closeQuietly(status.getEntity().getContent()); + + ourLog.info("Response was:\n{}", status); + ourLog.info("Response was:\n{}", responseContent); + + assertEquals(422, status.getStatusLine().getStatusCode()); + assertThat(status.toString(), containsString("X-FHIR-Request-Validation")); + } + @Test public void testCreateXmlInvalidNoValidatorsSpecifiedOutcomeHeader() throws Exception { myInterceptor.setAddResponseHeaderOnSeverity(null); @@ -252,50 +258,6 @@ public class RequestValidatingInterceptorDstu3Test { assertThat(status.toString(), containsString("X-FHIR-Request-Validation: {\"resourceType\":\"OperationOutcome")); } - @Test - public void testCreateXmlInvalidInstanceValidator() throws Exception { - IValidatorModule module = new FhirInstanceValidator(); - myInterceptor.addValidatorModule(module); - myInterceptor.setAddResponseHeaderOnSeverity(ResultSeverityEnum.INFORMATION); - myInterceptor.setAddResponseHeaderOnSeverity(ResultSeverityEnum.INFORMATION); - - Patient patient = new Patient(); - patient.addIdentifier().setValue("002"); - patient.setGender(AdministrativeGender.MALE); - patient.addContact().addRelationship().setText("FOO"); - String encoded = ourCtx.newXmlParser().encodeResourceToString(patient); - - HttpPost httpPost = new HttpPost("http://localhost:" + ourPort + "/Patient"); - httpPost.setEntity(new StringEntity(encoded, ContentType.create(Constants.CT_FHIR_XML, "UTF-8"))); - - HttpResponse status = ourClient.execute(httpPost); - - String responseContent = IOUtils.toString(status.getEntity().getContent()); - IOUtils.closeQuietly(status.getEntity().getContent()); - - ourLog.info("Response was:\n{}", status); - ourLog.info("Response was:\n{}", responseContent); - - assertEquals(422, status.getStatusLine().getStatusCode()); - assertThat(status.toString(), containsString("X-FHIR-Request-Validation")); - } - - @Test - public void testSearch() throws Exception { - HttpGet httpPost = new HttpGet("http://localhost:" + ourPort + "/Patient?foo=bar"); - - HttpResponse status = ourClient.execute(httpPost); - - String responseContent = IOUtils.toString(status.getEntity().getContent()); - IOUtils.closeQuietly(status.getEntity().getContent()); - - ourLog.info("Response was:\n{}", status); - ourLog.info("Response was:\n{}", responseContent); - - assertEquals(200, status.getStatusLine().getStatusCode()); - assertThat(status.toString(), not(containsString("X-FHIR-Request-Validation"))); - assertEquals(true, ourLastRequestWasSearch); - } @Test public void testCreateXmlValidNoValidatorsSpecified() throws Exception { @@ -318,10 +280,49 @@ public class RequestValidatingInterceptorDstu3Test { assertEquals(201, status.getStatusLine().getStatusCode()); assertThat(status.toString(), not(containsString("X-FHIR-Request-Validation"))); } + + @Test + public void testFetchMetadata() throws Exception { + myInterceptor.setAddResponseHeaderOnSeverity(ResultSeverityEnum.INFORMATION); + + HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/metadata"); + + // This header caused a crash + httpGet.addHeader("Content-Type", "application/xml+fhir"); + + HttpResponse status = ourClient.execute(httpGet); + + String responseContent = IOUtils.toString(status.getEntity().getContent()); + IOUtils.closeQuietly(status.getEntity().getContent()); + + ourLog.info("Response was:\n{}", status); + ourLog.info("Response was:\n{}", responseContent); + + assertEquals(200, status.getStatusLine().getStatusCode()); + assertThat(responseContent, containsString("Conformance")); + } + + @Test + public void testSearch() throws Exception { + HttpGet httpPost = new HttpGet("http://localhost:" + ourPort + "/Patient?foo=bar"); + + HttpResponse status = ourClient.execute(httpPost); + + String responseContent = IOUtils.toString(status.getEntity().getContent()); + IOUtils.closeQuietly(status.getEntity().getContent()); + + ourLog.info("Response was:\n{}", status); + ourLog.info("Response was:\n{}", responseContent); + + assertEquals(200, status.getStatusLine().getStatusCode()); + assertThat(status.toString(), not(containsString("X-FHIR-Request-Validation"))); + assertEquals(true, ourLastRequestWasSearch); + } @AfterClass - public static void afterClass() throws Exception { + public static void afterClassClearContext() throws Exception { ourServer.stop(); + TestUtil.clearAllStaticFieldsForUnitTest(); } @BeforeClass diff --git a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/server/ResponseValidatingInterceptorDstu3Test.java b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/server/ResponseValidatingInterceptorDstu3Test.java index 3052b8dad3d..c8379530005 100644 --- a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/server/ResponseValidatingInterceptorDstu3Test.java +++ b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/server/ResponseValidatingInterceptorDstu3Test.java @@ -37,19 +37,20 @@ import ca.uhn.fhir.rest.api.RestOperationTypeEnum; import ca.uhn.fhir.rest.param.StringParam; import ca.uhn.fhir.rest.server.interceptor.ResponseValidatingInterceptor; import ca.uhn.fhir.util.PortUtil; +import ca.uhn.fhir.util.TestUtil; import ca.uhn.fhir.validation.IValidatorModule; import ca.uhn.fhir.validation.ResultSeverityEnum; public class ResponseValidatingInterceptorDstu3Test { - private static CloseableHttpClient ourClient; + public static IBaseResource myReturnResource; + private static CloseableHttpClient ourClient; private static FhirContext ourCtx = FhirContext.forDstu3(); private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ResponseValidatingInterceptorDstu3Test.class); private static int ourPort; private static Server ourServer; private static RestfulServer ourServlet; private ResponseValidatingInterceptor myInterceptor; - public static IBaseResource myReturnResource; @Before public void before() { @@ -67,6 +68,74 @@ public class ResponseValidatingInterceptorDstu3Test { ourServlet.registerInterceptor(myInterceptor); } + @Test + public void testLongHeaderTruncated() throws Exception { + IValidatorModule module = new FhirInstanceValidator(); + myInterceptor.addValidatorModule(module); + myInterceptor.setAddResponseOutcomeHeaderOnSeverity(ResultSeverityEnum.INFORMATION); + myInterceptor.setFailOnSeverity(null); + + Patient patient = new Patient(); + for (int i = 0; i < 1000; i++) { + patient.addContact().setGender(AdministrativeGender.MALE); + } + patient.setGender(AdministrativeGender.MALE); + myReturnResource = patient; + + HttpGet httpPost = new HttpGet("http://localhost:" + ourPort + "/Patient?foo=bar"); + + { + HttpResponse status = ourClient.execute(httpPost); + + String responseContent = IOUtils.toString(status.getEntity().getContent()); + IOUtils.closeQuietly(status.getEntity().getContent()); + + ourLog.info("Response was:\n{}", status); + ourLog.trace("Response was:\n{}", responseContent); + + assertEquals(200, status.getStatusLine().getStatusCode()); + assertThat(status.getFirstHeader("X-FHIR-Response-Validation").getValue(), endsWith("...")); + assertThat(status.getFirstHeader("X-FHIR-Response-Validation").getValue(), startsWith("{\"resourceType\":\"OperationOutcome\"")); + } + { + myInterceptor.setMaximumHeaderLength(100); + HttpResponse status = ourClient.execute(httpPost); + + String responseContent = IOUtils.toString(status.getEntity().getContent()); + IOUtils.closeQuietly(status.getEntity().getContent()); + + ourLog.info("Response was:\n{}", status); + ourLog.trace("Response was:\n{}", responseContent); + + assertEquals(200, status.getStatusLine().getStatusCode()); + assertThat(status.getFirstHeader("X-FHIR-Response-Validation").getValue(), endsWith("...")); + assertThat(status.getFirstHeader("X-FHIR-Response-Validation").getValue(), startsWith("{\"resourceType\":\"OperationOutcome\"")); + } + } + + @Test + public void testOperationOutcome() throws Exception { + myInterceptor.setAddResponseOutcomeHeaderOnSeverity(ResultSeverityEnum.INFORMATION); + Patient patient = new Patient(); + patient.addIdentifier().setValue("002"); + patient.setGender(AdministrativeGender.MALE); + myReturnResource = patient; + + HttpGet httpPost = new HttpGet("http://localhost:" + ourPort + "/Patient?foo=bar"); + + HttpResponse status = ourClient.execute(httpPost); + + String responseContent = IOUtils.toString(status.getEntity().getContent()); + IOUtils.closeQuietly(status.getEntity().getContent()); + + ourLog.info("Response was:\n{}", status); + ourLog.trace("Response was:\n{}", responseContent); + + assertEquals(200, status.getStatusLine().getStatusCode()); + assertThat(status.toString(), (containsString( + "X-FHIR-Response-Validation: {\"resourceType\":\"OperationOutcome\",\"issue\":[{\"severity\":\"information\",\"code\":\"informational\",\"diagnostics\":\"No issues detected\"}]}"))); + } + /** * Ignored until #264 is fixed */ @@ -139,6 +208,32 @@ public class ResponseValidatingInterceptorDstu3Test { assertThat(status.toString(), (containsString("X-FHIR-Response-Validation: NO ISSUES"))); } + @Test + public void testSearchXmlInvalidInstanceValidator() throws Exception { + IValidatorModule module = new FhirInstanceValidator(); + myInterceptor.addValidatorModule(module); + myInterceptor.setAddResponseHeaderOnSeverity(ResultSeverityEnum.INFORMATION); + + Patient patient = new Patient(); + patient.addIdentifier().setValue("002"); + patient.setGender(AdministrativeGender.MALE); + patient.addContact().addRelationship().setText("FOO"); + myReturnResource = patient; + + HttpGet httpPost = new HttpGet("http://localhost:" + ourPort + "/Patient?foo=bar"); + + HttpResponse status = ourClient.execute(httpPost); + + String responseContent = IOUtils.toString(status.getEntity().getContent()); + IOUtils.closeQuietly(status.getEntity().getContent()); + + ourLog.info("Response was:\n{}", status); + ourLog.info("Response was:\n{}", responseContent); + + assertEquals(422, status.getStatusLine().getStatusCode()); + assertThat(status.toString(), containsString("X-FHIR-Response-Validation")); + } + /** * Ignored until #264 is fixed */ @@ -166,15 +261,10 @@ public class ResponseValidatingInterceptorDstu3Test { } @Test - public void testSearchXmlInvalidInstanceValidator() throws Exception { - IValidatorModule module = new FhirInstanceValidator(); - myInterceptor.addValidatorModule(module); - myInterceptor.setAddResponseHeaderOnSeverity(ResultSeverityEnum.INFORMATION); - + public void testSearchXmlValidNoValidatorsSpecified() throws Exception { Patient patient = new Patient(); patient.addIdentifier().setValue("002"); patient.setGender(AdministrativeGender.MALE); - patient.addContact().addRelationship().setText("FOO"); myReturnResource = patient; HttpGet httpPost = new HttpGet("http://localhost:" + ourPort + "/Patient?foo=bar"); @@ -185,10 +275,10 @@ public class ResponseValidatingInterceptorDstu3Test { IOUtils.closeQuietly(status.getEntity().getContent()); ourLog.info("Response was:\n{}", status); - ourLog.info("Response was:\n{}", responseContent); + ourLog.trace("Response was:\n{}", responseContent); - assertEquals(422, status.getStatusLine().getStatusCode()); - assertThat(status.toString(), containsString("X-FHIR-Response-Validation")); + assertEquals(200, status.getStatusLine().getStatusCode()); + assertThat(status.toString(), not(containsString("X-FHIR-Response-Validation"))); } @Test @@ -231,98 +321,10 @@ public class ResponseValidatingInterceptorDstu3Test { assertThat(status.toString(), (containsString("X-FHIR-Response-Validation"))); } - @Test - public void testSearchXmlValidNoValidatorsSpecified() throws Exception { - Patient patient = new Patient(); - patient.addIdentifier().setValue("002"); - patient.setGender(AdministrativeGender.MALE); - myReturnResource = patient; - - HttpGet httpPost = new HttpGet("http://localhost:" + ourPort + "/Patient?foo=bar"); - - HttpResponse status = ourClient.execute(httpPost); - - String responseContent = IOUtils.toString(status.getEntity().getContent()); - IOUtils.closeQuietly(status.getEntity().getContent()); - - ourLog.info("Response was:\n{}", status); - ourLog.trace("Response was:\n{}", responseContent); - - assertEquals(200, status.getStatusLine().getStatusCode()); - assertThat(status.toString(), not(containsString("X-FHIR-Response-Validation"))); - } - - @Test - public void testOperationOutcome() throws Exception { - myInterceptor.setAddResponseOutcomeHeaderOnSeverity(ResultSeverityEnum.INFORMATION); - Patient patient = new Patient(); - patient.addIdentifier().setValue("002"); - patient.setGender(AdministrativeGender.MALE); - myReturnResource = patient; - - HttpGet httpPost = new HttpGet("http://localhost:" + ourPort + "/Patient?foo=bar"); - - HttpResponse status = ourClient.execute(httpPost); - - String responseContent = IOUtils.toString(status.getEntity().getContent()); - IOUtils.closeQuietly(status.getEntity().getContent()); - - ourLog.info("Response was:\n{}", status); - ourLog.trace("Response was:\n{}", responseContent); - - assertEquals(200, status.getStatusLine().getStatusCode()); - assertThat(status.toString(), (containsString( - "X-FHIR-Response-Validation: {\"resourceType\":\"OperationOutcome\",\"issue\":[{\"severity\":\"information\",\"code\":\"informational\",\"diagnostics\":\"No issues detected\"}]}"))); - } - - @Test - public void testLongHeaderTruncated() throws Exception { - IValidatorModule module = new FhirInstanceValidator(); - myInterceptor.addValidatorModule(module); - myInterceptor.setAddResponseOutcomeHeaderOnSeverity(ResultSeverityEnum.INFORMATION); - myInterceptor.setFailOnSeverity(null); - - Patient patient = new Patient(); - for (int i = 0; i < 1000; i++) { - patient.addContact().setGender(AdministrativeGender.MALE); - } - patient.setGender(AdministrativeGender.MALE); - myReturnResource = patient; - - HttpGet httpPost = new HttpGet("http://localhost:" + ourPort + "/Patient?foo=bar"); - - { - HttpResponse status = ourClient.execute(httpPost); - - String responseContent = IOUtils.toString(status.getEntity().getContent()); - IOUtils.closeQuietly(status.getEntity().getContent()); - - ourLog.info("Response was:\n{}", status); - ourLog.trace("Response was:\n{}", responseContent); - - assertEquals(200, status.getStatusLine().getStatusCode()); - assertThat(status.getFirstHeader("X-FHIR-Response-Validation").getValue(), endsWith("...")); - assertThat(status.getFirstHeader("X-FHIR-Response-Validation").getValue(), startsWith("{\"resourceType\":\"OperationOutcome\"")); - } - { - myInterceptor.setMaximumHeaderLength(100); - HttpResponse status = ourClient.execute(httpPost); - - String responseContent = IOUtils.toString(status.getEntity().getContent()); - IOUtils.closeQuietly(status.getEntity().getContent()); - - ourLog.info("Response was:\n{}", status); - ourLog.trace("Response was:\n{}", responseContent); - - assertEquals(200, status.getStatusLine().getStatusCode()); - assertThat(status.getFirstHeader("X-FHIR-Response-Validation").getValue(), endsWith("...")); - assertThat(status.getFirstHeader("X-FHIR-Response-Validation").getValue(), startsWith("{\"resourceType\":\"OperationOutcome\"")); - } - } - @AfterClass - public static void afterClass() throws Exception { + public static void afterClassClearContext() throws Exception { ourServer.stop(); + TestUtil.clearAllStaticFieldsForUnitTest(); } @BeforeClass diff --git a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/server/ServerUsingOldTypesDstu3Test.java b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/server/ServerUsingOldTypesDstu3Test.java index ef8330bd780..f55b461e50f 100644 --- a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/server/ServerUsingOldTypesDstu3Test.java +++ b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/rest/server/ServerUsingOldTypesDstu3Test.java @@ -8,6 +8,7 @@ import javax.servlet.ServletException; import org.hamcrest.core.StringContains; import org.hl7.fhir.dstu3.model.Patient; import org.hl7.fhir.instance.model.api.IBaseResource; +import org.junit.AfterClass; import org.junit.Test; import ca.uhn.fhir.context.FhirContext; @@ -17,10 +18,15 @@ import ca.uhn.fhir.rest.annotation.IdParam; import ca.uhn.fhir.rest.annotation.Operation; import ca.uhn.fhir.rest.annotation.OperationParam; import ca.uhn.fhir.rest.annotation.Read; +import ca.uhn.fhir.util.TestUtil; public class ServerUsingOldTypesDstu3Test { private static FhirContext ourCtx = FhirContext.forDstu3(); + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } @Test public void testReadProviderString() { diff --git a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/validation/FhirInstanceValidatorDstu3Test.java b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/validation/FhirInstanceValidatorDstu3Test.java index 9b40178e0c8..06c06bb4b2a 100644 --- a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/validation/FhirInstanceValidatorDstu3Test.java +++ b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/validation/FhirInstanceValidatorDstu3Test.java @@ -48,31 +48,32 @@ import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.util.TestUtil; public class FhirInstanceValidatorDstu3Test { + private static DefaultProfileValidationSupport myDefaultValidationSupport = new DefaultProfileValidationSupport(); private static FhirContext ourCtx = FhirContext.forDstu3(); private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirInstanceValidatorDstu3Test.class); - private static DefaultProfileValidationSupport myDefaultValidationSupport = new DefaultProfileValidationSupport(); private FhirInstanceValidator myInstanceVal; private IValidationSupport myMockSupport; + private Map mySupportedCodeSystemsForExpansion; private FhirValidator myVal; private ArrayList myValidConcepts; private Set myValidSystems = new HashSet(); - private Map mySupportedCodeSystemsForExpansion; + @Rule + public TestRule watcher = new TestWatcher() { + protected void starting(Description description) { + ourLog.info("Starting test: " + description.getMethodName()); + } + }; private void addValidConcept(String theSystem, String theCode) { myValidSystems.add(theSystem); myValidConcepts.add(theSystem + "___" + theCode); } - @AfterClass - public static void afterClass() { - myDefaultValidationSupport.flush(); - myDefaultValidationSupport = null; - } - @SuppressWarnings("unchecked") @Before public void before() { @@ -159,6 +160,24 @@ public class FhirInstanceValidatorDstu3Test { }); } + + private Object defaultString(Integer theLocationLine) { + return theLocationLine != null ? theLocationLine.toString() : ""; + } + + private List logResultsAndReturnAll(ValidationResult theOutput) { + List retVal = new ArrayList(); + + int index = 0; + for (SingleValidationMessage next : theOutput.getMessages()) { + ourLog.info("Result {}: {} - {}:{} {} - {}", new Object[] { index, next.getSeverity(), defaultString(next.getLocationLine()), defaultString(next.getLocationCol()), next.getLocationString(), next.getMessage() }); + index++; + + retVal.add(next); + } + + return retVal; + } private List logResultsAndReturnNonInformationalOnes(ValidationResult theOutput) { List retVal = new ArrayList(); @@ -176,30 +195,37 @@ public class FhirInstanceValidatorDstu3Test { return retVal; } - private List logResultsAndReturnAll(ValidationResult theOutput) { - List retVal = new ArrayList(); + @Test + public void testValidateBigRawJsonResource() throws Exception { + InputStream stream = FhirInstanceValidatorDstu3Test.class.getResourceAsStream("/conformance.json.gz"); + stream = new GZIPInputStream(stream); + String input = IOUtils.toString(stream); - int index = 0; - for (SingleValidationMessage next : theOutput.getMessages()) { - ourLog.info("Result {}: {} - {}:{} {} - {}", new Object[] { index, next.getSeverity(), defaultString(next.getLocationLine()), defaultString(next.getLocationCol()), next.getLocationString(), next.getMessage() }); - index++; - - retVal.add(next); + long start = System.currentTimeMillis(); + ValidationResult output = null; + int passes = 1; + for (int i = 0; i < passes; i++) { + ourLog.info("Pass {}", i + 1); + output = myVal.validateWithResult(input); } - return retVal; + long delay = System.currentTimeMillis() - start; + long per = delay / passes; + + logResultsAndReturnAll(output); + + ourLog.info("Took {} ms -- {}ms / pass", delay, per); } - private Object defaultString(Integer theLocationLine) { - return theLocationLine != null ? theLocationLine.toString() : ""; - } + @Test + public void testValidateQuestionnaireResponse() throws IOException { + String input = IOUtils.toString(FhirInstanceValidatorDstu3Test.class.getResourceAsStream("/qr_jon.xml")); - @Rule - public TestRule watcher = new TestWatcher() { - protected void starting(Description description) { - ourLog.info("Starting test: " + description.getMethodName()); - } - }; + ValidationResult output = myVal.validateWithResult(input); + logResultsAndReturnAll(output); + + assertThat(output.getMessages().toString(), containsString("Items not of type group should not have items - Item with linkId 5.1 of type BOOLEAN has 1 item(s)")); + } @Test public void testValidateRawJsonResource() { @@ -251,28 +277,6 @@ public class FhirInstanceValidatorDstu3Test { assertEquals(output.toString(), 0, output.getMessages().size()); } - @Test - public void testValidateBigRawJsonResource() throws Exception { - InputStream stream = FhirInstanceValidatorDstu3Test.class.getResourceAsStream("/conformance.json.gz"); - stream = new GZIPInputStream(stream); - String input = IOUtils.toString(stream); - - long start = System.currentTimeMillis(); - ValidationResult output = null; - int passes = 1; - for (int i = 0; i < passes; i++) { - ourLog.info("Pass {}", i + 1); - output = myVal.validateWithResult(input); - } - - long delay = System.currentTimeMillis() - start; - long per = delay / passes; - - logResultsAndReturnAll(output); - - ourLog.info("Took {} ms -- {}ms / pass", delay, per); - } - @Test public void testValidateRawXmlResourceBadAttributes() { // @formatter:off @@ -289,59 +293,24 @@ public class FhirInstanceValidatorDstu3Test { } @Test - public void testValidateQuestionnaireResponse() throws IOException { - String input = IOUtils.toString(FhirInstanceValidatorDstu3Test.class.getResourceAsStream("/qr_jon.xml")); - - ValidationResult output = myVal.validateWithResult(input); - logResultsAndReturnAll(output); - - assertThat(output.getMessages().toString(), containsString("Items not of type group should not have items - Item with linkId 5.1 of type BOOLEAN has 1 item(s)")); - } - - @Test - @Ignore - public void testValidateStructureDefinition() throws IOException { - String input = IOUtils.toString(FhirInstanceValidatorDstu3Test.class.getResourceAsStream("/sdc-questionnaire.profile.xml")); - - ValidationResult output = myVal.validateWithResult(input); - logResultsAndReturnAll(output); - - assertEquals(output.toString(), 3, output.getMessages().size()); - ourLog.info(output.getMessages().get(0).getLocationString()); - ourLog.info(output.getMessages().get(0).getMessage()); - } - - @Test - public void testValidateResourceFailingInvariant() { - Observation input = new Observation(); - - // Has a value, but not a status (which is required) - input.getCode().addCoding().setSystem("http://loinc.org").setCode("12345"); - input.setValue(new StringType("AAA")); - - ValidationResult output = myVal.validateWithResult(input); - assertThat(output.getMessages().size(), greaterThan(0)); - assertEquals("Element '/f:Observation.status': minimum required = 1, but only found 0", output.getMessages().get(0).getMessage()); - - } - - - - @Test - public void testValidateResourceContainingProfileDeclarationDoesntResolve() { - addValidConcept("http://loinc.org", "12345"); + public void testValidateResourceContainingLoincCode() { + addValidConcept("http://loinc.org", "1234567"); Observation input = new Observation(); - input.getMeta().addProfile("http://foo/myprofile"); + // input.getMeta().addProfile("http://hl7.org/fhir/StructureDefinition/devicemetricobservation"); - input.getCode().addCoding().setSystem("http://loinc.org").setCode("12345"); + input.addIdentifier().setSystem("http://acme").setValue("12345"); + input.getEncounter().setReference("http://foo.com/Encounter/9"); input.setStatus(ObservationStatus.FINAL); + input.getCode().addCoding().setSystem("http://loinc.org").setCode("12345"); myInstanceVal.setValidationSupport(myMockSupport); ValidationResult output = myVal.validateWithResult(input); - List errors = logResultsAndReturnNonInformationalOnes(output); - assertEquals(errors.toString(), 1, errors.size()); - assertEquals("StructureDefinition reference \"http://foo/myprofile\" could not be resolved", errors.get(0).getMessage()); + List errors = logResultsAndReturnAll(output); + + assertThat(errors.toString(), containsString("information")); + assertThat(errors.toString(), containsString("Unknown code: http://loinc.org / 12345")); + assertEquals(1, errors.size()); } @Test @@ -367,26 +336,38 @@ public class FhirInstanceValidatorDstu3Test { } @Test - public void testValidateResourceContainingLoincCode() { - addValidConcept("http://loinc.org", "1234567"); + public void testValidateResourceContainingProfileDeclarationDoesntResolve() { + addValidConcept("http://loinc.org", "12345"); Observation input = new Observation(); - // input.getMeta().addProfile("http://hl7.org/fhir/StructureDefinition/devicemetricobservation"); + input.getMeta().addProfile("http://foo/myprofile"); - input.addIdentifier().setSystem("http://acme").setValue("12345"); - input.getEncounter().setReference("http://foo.com/Encounter/9"); - input.setStatus(ObservationStatus.FINAL); input.getCode().addCoding().setSystem("http://loinc.org").setCode("12345"); + input.setStatus(ObservationStatus.FINAL); myInstanceVal.setValidationSupport(myMockSupport); ValidationResult output = myVal.validateWithResult(input); - List errors = logResultsAndReturnAll(output); - - assertThat(errors.toString(), containsString("information")); - assertThat(errors.toString(), containsString("Unknown code: http://loinc.org / 12345")); - assertEquals(1, errors.size()); + List errors = logResultsAndReturnNonInformationalOnes(output); + assertEquals(errors.toString(), 1, errors.size()); + assertEquals("StructureDefinition reference \"http://foo/myprofile\" could not be resolved", errors.get(0).getMessage()); } + @Test + public void testValidateResourceFailingInvariant() { + Observation input = new Observation(); + + // Has a value, but not a status (which is required) + input.getCode().addCoding().setSystem("http://loinc.org").setCode("12345"); + input.setValue(new StringType("AAA")); + + ValidationResult output = myVal.validateWithResult(input); + assertThat(output.getMessages().size(), greaterThan(0)); + assertEquals("Element '/f:Observation.status': minimum required = 1, but only found 0", output.getMessages().get(0).getMessage()); + + } + + + @Test public void testValidateResourceWithDefaultValueset() { Observation input = new Observation(); @@ -410,33 +391,6 @@ public class FhirInstanceValidatorDstu3Test { output.getMessages().get(0).getMessage()); } - @Test - public void testValidateResourceWithValuesetExpansionBad() { - - Patient patient = new Patient(); - patient.addIdentifier().setSystem("http://example.com/").setValue("12345").getType().addCoding().setSystem("http://example.com/foo/bar").setCode("bar"); - - ValidationResult output = myVal.validateWithResult(patient); - List all = logResultsAndReturnAll(output); - assertEquals(1, all.size()); - assertEquals("/f:Patient/f:identifier/f:type", all.get(0).getLocationString()); - assertEquals( - "None of the codes provided are in the value set http://hl7.org/fhir/ValueSet/identifier-type (http://hl7.org/fhir/ValueSet/identifier-type, and a code should come from this value set unless it has no suitable code", - all.get(0).getMessage()); - assertEquals(ResultSeverityEnum.WARNING, all.get(0).getSeverity()); - - } - - @Test - public void testValidateResourceWithValuesetExpansionGood() { - Patient patient = new Patient(); - patient.addIdentifier().setSystem("http://system").setValue("12345").getType().addCoding().setSystem("http://hl7.org/fhir/v2/0203").setCode("MR"); - - ValidationResult output = myVal.validateWithResult(patient); - List all = logResultsAndReturnAll(output); - assertEquals(0, all.size()); - } - @Test public void testValidateResourceWithExampleBindingCodeValidationFailing() { Observation input = new Observation(); @@ -502,4 +456,52 @@ public class FhirInstanceValidatorDstu3Test { assertEquals(errors.toString(), 0, errors.size()); } + @Test + public void testValidateResourceWithValuesetExpansionBad() { + + Patient patient = new Patient(); + patient.addIdentifier().setSystem("http://example.com/").setValue("12345").getType().addCoding().setSystem("http://example.com/foo/bar").setCode("bar"); + + ValidationResult output = myVal.validateWithResult(patient); + List all = logResultsAndReturnAll(output); + assertEquals(1, all.size()); + assertEquals("/f:Patient/f:identifier/f:type", all.get(0).getLocationString()); + assertEquals( + "None of the codes provided are in the value set http://hl7.org/fhir/ValueSet/identifier-type (http://hl7.org/fhir/ValueSet/identifier-type, and a code should come from this value set unless it has no suitable code", + all.get(0).getMessage()); + assertEquals(ResultSeverityEnum.WARNING, all.get(0).getSeverity()); + + } + + @Test + public void testValidateResourceWithValuesetExpansionGood() { + Patient patient = new Patient(); + patient.addIdentifier().setSystem("http://system").setValue("12345").getType().addCoding().setSystem("http://hl7.org/fhir/v2/0203").setCode("MR"); + + ValidationResult output = myVal.validateWithResult(patient); + List all = logResultsAndReturnAll(output); + assertEquals(0, all.size()); + } + + @Test + @Ignore + public void testValidateStructureDefinition() throws IOException { + String input = IOUtils.toString(FhirInstanceValidatorDstu3Test.class.getResourceAsStream("/sdc-questionnaire.profile.xml")); + + ValidationResult output = myVal.validateWithResult(input); + logResultsAndReturnAll(output); + + assertEquals(output.toString(), 3, output.getMessages().size()); + ourLog.info(output.getMessages().get(0).getLocationString()); + ourLog.info(output.getMessages().get(0).getMessage()); + } + + + @AfterClass + public static void afterClassClearContext() { + myDefaultValidationSupport.flush(); + myDefaultValidationSupport = null; + TestUtil.clearAllStaticFieldsForUnitTest(); + } + } diff --git a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/validation/QuestionnaireResponseValidatorDstu3Test.java b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/validation/QuestionnaireResponseValidatorDstu3Test.java index 8f2b01aee16..b751e26846b 100644 --- a/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/validation/QuestionnaireResponseValidatorDstu3Test.java +++ b/hapi-fhir-structures-dstu3/src/test/java/ca/uhn/fhir/validation/QuestionnaireResponseValidatorDstu3Test.java @@ -37,17 +37,19 @@ import org.junit.Before; import org.junit.Test; import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.util.TestUtil; public class QuestionnaireResponseValidatorDstu3Test { - private static final FhirContext ourCtx = FhirContext.forDstu3(); + private static DefaultProfileValidationSupport myDefaultValidationSupport = new DefaultProfileValidationSupport(); + private static final FhirContext ourCtx = FhirContext.forDstu3(); private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(QuestionnaireResponseValidatorDstu3Test.class); - private IWorkerContext myWorkerCtx; - private IValidationSupport myValSupport; - private FhirValidator myVal; - private FhirInstanceValidator myInstanceVal; + private FhirValidator myVal; + private IValidationSupport myValSupport; + + private IWorkerContext myWorkerCtx; @Before public void before() { @@ -65,13 +67,17 @@ public class QuestionnaireResponseValidatorDstu3Test { myVal.registerValidatorModule(myInstanceVal); } - private static DefaultProfileValidationSupport myDefaultValidationSupport = new DefaultProfileValidationSupport(); - @AfterClass - public static void afterClass() { - myDefaultValidationSupport.flush(); - myDefaultValidationSupport = null; + private ValidationResult stripBindingHasNoSourceMessage(ValidationResult theErrors) { + List messages = new ArrayList(theErrors.getMessages()); + for (int i = 0; i < messages.size(); i++) { + if (messages.get(i).getMessage().contains("has no source, so can't")) { + messages.remove(i); + i--; + } + } + + return new ValidationResult(ourCtx, messages); } - @Test public void testAnswerWithWrongType() { Questionnaire q = new Questionnaire(); @@ -150,6 +156,66 @@ public class QuestionnaireResponseValidatorDstu3Test { } + @Test + public void testGroupWithNoLinkIdInQuestionnaireResponse() { + Questionnaire q = new Questionnaire(); + QuestionnaireItemComponent qGroup = q.addItem().setType(QuestionnaireItemType.GROUP); + qGroup.addItem().setLinkId("link0").setRequired(true).setType(QuestionnaireItemType.BOOLEAN); + + QuestionnaireResponse qa = new QuestionnaireResponse(); + qa.setStatus(QuestionnaireResponseStatus.COMPLETED); + qa.getQuestionnaire().setReference("http://example.com/Questionnaire/q1"); + QuestionnaireResponseItemComponent qaGroup = qa.addItem(); + qaGroup.addItem().setLinkId("link0").addAnswer().setValue(new StringType("FOO")); + + when(myValSupport.fetchResource(any(FhirContext.class), eq(Questionnaire.class), eq(qa.getQuestionnaire().getReference()))).thenReturn(q); + ValidationResult errors = myVal.validateWithResult(qa); + + ourLog.info(errors.toString()); + assertThat(errors.toString(), containsString("No LinkId, so can't be validated")); + } + + @Test + public void testItemWithNoType() { + Questionnaire q = new Questionnaire(); + QuestionnaireItemComponent qGroup = q.addItem(); + qGroup.setLinkId("link0"); + qGroup.addItem().setLinkId("link1").setType(QuestionnaireItemType.STRING); + + QuestionnaireResponse qa = new QuestionnaireResponse(); + qa.setStatus(QuestionnaireResponseStatus.COMPLETED); + qa.getQuestionnaire().setReference("http://example.com/Questionnaire/q1"); + QuestionnaireResponseItemComponent qaGroup = qa.addItem().setLinkId("link0"); + qaGroup.addItem().setLinkId("link1").addAnswer().setValue(new StringType("FOO")); + + when(myValSupport.fetchResource(any(FhirContext.class), eq(Questionnaire.class), eq(qa.getQuestionnaire().getReference()))).thenReturn(q); + ValidationResult errors = myVal.validateWithResult(qa); + + ourLog.info(errors.toString()); + assertThat(errors.toString(), containsString("Definition for item link0 does not contain a type")); + assertEquals(1, errors.getMessages().size()); + } + + @Test + public void testMissingRequiredQuestion() { + + Questionnaire q = new Questionnaire(); + q.addItem().setLinkId("link0").setRequired(true).setType(QuestionnaireItemType.STRING); + q.addItem().setLinkId("link1").setRequired(true).setType(QuestionnaireItemType.STRING); + + QuestionnaireResponse qa = new QuestionnaireResponse(); + qa.setStatus(QuestionnaireResponseStatus.COMPLETED); + qa.getQuestionnaire().setReference("http://example.com/Questionnaire/q1"); + qa.addItem().setLinkId("link1").addAnswer().setValue(new StringType("FOO")); + + String reference = qa.getQuestionnaire().getReference(); + when(myValSupport.fetchResource(any(FhirContext.class), eq(Questionnaire.class), eq(reference))).thenReturn(q); + ValidationResult errors = myVal.validateWithResult(qa); + + ourLog.info(errors.toString()); + assertThat(errors.toString(), containsString("No response found for required item link0")); + } + @Test public void testOpenchoiceAnswer() { String questionnaireRef = "http://example.com/Questionnaire/q1"; @@ -264,78 +330,6 @@ public class QuestionnaireResponseValidatorDstu3Test { } - private ValidationResult stripBindingHasNoSourceMessage(ValidationResult theErrors) { - List messages = new ArrayList(theErrors.getMessages()); - for (int i = 0; i < messages.size(); i++) { - if (messages.get(i).getMessage().contains("has no source, so can't")) { - messages.remove(i); - i--; - } - } - - return new ValidationResult(ourCtx, messages); - } - - @Test - public void testGroupWithNoLinkIdInQuestionnaireResponse() { - Questionnaire q = new Questionnaire(); - QuestionnaireItemComponent qGroup = q.addItem().setType(QuestionnaireItemType.GROUP); - qGroup.addItem().setLinkId("link0").setRequired(true).setType(QuestionnaireItemType.BOOLEAN); - - QuestionnaireResponse qa = new QuestionnaireResponse(); - qa.setStatus(QuestionnaireResponseStatus.COMPLETED); - qa.getQuestionnaire().setReference("http://example.com/Questionnaire/q1"); - QuestionnaireResponseItemComponent qaGroup = qa.addItem(); - qaGroup.addItem().setLinkId("link0").addAnswer().setValue(new StringType("FOO")); - - when(myValSupport.fetchResource(any(FhirContext.class), eq(Questionnaire.class), eq(qa.getQuestionnaire().getReference()))).thenReturn(q); - ValidationResult errors = myVal.validateWithResult(qa); - - ourLog.info(errors.toString()); - assertThat(errors.toString(), containsString("No LinkId, so can't be validated")); - } - - @Test - public void testMissingRequiredQuestion() { - - Questionnaire q = new Questionnaire(); - q.addItem().setLinkId("link0").setRequired(true).setType(QuestionnaireItemType.STRING); - q.addItem().setLinkId("link1").setRequired(true).setType(QuestionnaireItemType.STRING); - - QuestionnaireResponse qa = new QuestionnaireResponse(); - qa.setStatus(QuestionnaireResponseStatus.COMPLETED); - qa.getQuestionnaire().setReference("http://example.com/Questionnaire/q1"); - qa.addItem().setLinkId("link1").addAnswer().setValue(new StringType("FOO")); - - String reference = qa.getQuestionnaire().getReference(); - when(myValSupport.fetchResource(any(FhirContext.class), eq(Questionnaire.class), eq(reference))).thenReturn(q); - ValidationResult errors = myVal.validateWithResult(qa); - - ourLog.info(errors.toString()); - assertThat(errors.toString(), containsString("No response found for required item link0")); - } - - @Test - public void testItemWithNoType() { - Questionnaire q = new Questionnaire(); - QuestionnaireItemComponent qGroup = q.addItem(); - qGroup.setLinkId("link0"); - qGroup.addItem().setLinkId("link1").setType(QuestionnaireItemType.STRING); - - QuestionnaireResponse qa = new QuestionnaireResponse(); - qa.setStatus(QuestionnaireResponseStatus.COMPLETED); - qa.getQuestionnaire().setReference("http://example.com/Questionnaire/q1"); - QuestionnaireResponseItemComponent qaGroup = qa.addItem().setLinkId("link0"); - qaGroup.addItem().setLinkId("link1").addAnswer().setValue(new StringType("FOO")); - - when(myValSupport.fetchResource(any(FhirContext.class), eq(Questionnaire.class), eq(qa.getQuestionnaire().getReference()))).thenReturn(q); - ValidationResult errors = myVal.validateWithResult(qa); - - ourLog.info(errors.toString()); - assertThat(errors.toString(), containsString("Definition for item link0 does not contain a type")); - assertEquals(1, errors.getMessages().size()); - } - @Test public void testUnexpectedAnswer() { Questionnaire q = new Questionnaire(); @@ -407,4 +401,11 @@ public class QuestionnaireResponseValidatorDstu3Test { assertEquals(errors.toString(), 10, errors.getMessages().size()); } + @AfterClass + public static void afterClassClearContext() { + myDefaultValidationSupport.flush(); + myDefaultValidationSupport = null; + TestUtil.clearAllStaticFieldsForUnitTest(); + } + } diff --git a/hapi-fhir-structures-dstu3/src/test/java/org/hl7/fhir/dstu3/hapi/rest/server/ServerConformanceProviderDstu3Test.java b/hapi-fhir-structures-dstu3/src/test/java/org/hl7/fhir/dstu3/hapi/rest/server/ServerConformanceProviderDstu3Test.java index d7957a98c38..7b4469b187b 100644 --- a/hapi-fhir-structures-dstu3/src/test/java/org/hl7/fhir/dstu3/hapi/rest/server/ServerConformanceProviderDstu3Test.java +++ b/hapi-fhir-structures-dstu3/src/test/java/org/hl7/fhir/dstu3/hapi/rest/server/ServerConformanceProviderDstu3Test.java @@ -31,6 +31,7 @@ import org.hl7.fhir.dstu3.model.Conformance.ConformanceRestResourceSearchParamCo import org.hl7.fhir.dstu3.model.Conformance.SystemRestfulInteraction; import org.hl7.fhir.dstu3.model.Conformance.TypeRestfulInteraction; import org.hl7.fhir.instance.model.api.IBaseResource; +import org.junit.AfterClass; import org.junit.Test; import ca.uhn.fhir.context.FhirContext; @@ -63,12 +64,17 @@ import ca.uhn.fhir.rest.param.TokenParam; import ca.uhn.fhir.rest.server.IResourceProvider; import ca.uhn.fhir.rest.server.ResourceBinding; import ca.uhn.fhir.rest.server.RestfulServer; +import ca.uhn.fhir.util.TestUtil; import ca.uhn.fhir.validation.ValidationResult; public class ServerConformanceProviderDstu3Test { private static FhirContext ourCtx = FhirContext.forDstu3(); private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ServerConformanceProviderDstu3Test.class); + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } private HttpServletRequest createHttpServletRequest() { HttpServletRequest req = mock(HttpServletRequest.class); diff --git a/hapi-fhir-structures-dstu3/src/test/java/org/hl7/fhir/dstu3/hapi/validation/ResourceValidatorDstu3Test.java b/hapi-fhir-structures-dstu3/src/test/java/org/hl7/fhir/dstu3/hapi/validation/ResourceValidatorDstu3Test.java index 8e4a19d8e12..db7fa3a7b62 100644 --- a/hapi-fhir-structures-dstu3/src/test/java/org/hl7/fhir/dstu3/hapi/validation/ResourceValidatorDstu3Test.java +++ b/hapi-fhir-structures-dstu3/src/test/java/org/hl7/fhir/dstu3/hapi/validation/ResourceValidatorDstu3Test.java @@ -12,10 +12,12 @@ import org.hl7.fhir.dstu3.model.Coding; import org.hl7.fhir.dstu3.model.OperationOutcome; import org.hl7.fhir.dstu3.model.Reference; import org.hl7.fhir.dstu3.model.StringType; +import org.junit.AfterClass; import org.junit.Test; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.parser.IParser; +import ca.uhn.fhir.util.TestUtil; import ca.uhn.fhir.validation.FhirValidator; import ca.uhn.fhir.validation.SchemaBaseValidator; import ca.uhn.fhir.validation.ValidationResult; @@ -25,6 +27,10 @@ public class ResourceValidatorDstu3Test { private static FhirContext ourCtx = FhirContext.forDstu3(); private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ResourceValidatorDstu3Test.class); + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } /** * See diff --git a/hapi-fhir-structures-dstu3/src/test/java/z/TestTest.java b/hapi-fhir-structures-dstu3/src/test/java/z/TestTest.java index b83c380435b..82132d8609a 100644 --- a/hapi-fhir-structures-dstu3/src/test/java/z/TestTest.java +++ b/hapi-fhir-structures-dstu3/src/test/java/z/TestTest.java @@ -1,8 +1,11 @@ package z; +import org.junit.AfterClass; import org.junit.Ignore; import org.junit.Test; +import ca.uhn.fhir.util.TestUtil; + public class TestTest { @Test @@ -11,4 +14,12 @@ public class TestTest { Thread.sleep(1000000); } + + @AfterClass + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + + }