From f356c7c385ed170311c378851a29dbe085e99931 Mon Sep 17 00:00:00 2001 From: James Agnew Date: Sat, 4 Jul 2020 18:28:16 -0400 Subject: [PATCH] Migrate to JUnit5 (#1952) * Work on junit * Work on junit 5 * Work on junit 5 * Bump errorprone vcersion * Work on tests * Junit 5 tweaks * Fixes * Work on tests * Work on junit5 * Work on tests * Test fixes * Work on junit5 * Test work * Get junit5 working * Test fix * Work on tests * WOrk on tests * Work on tests * fixes * Compile fix * One more tweak * Compile fix * Add changelog * Fix compile error * Compile fix --- example-projects/README.md | 2 +- .../fhir/jpa/cds/example/CdsExampleTests.java | 10 +- .../ca/uhn/fhir/jpa/demo/ExampleServerIT.java | 16 +- .../ca/uhn/fhir/android/BuiltJarDstu2IT.java | 11 +- .../fhir/android/BuiltJarDstu2ShadeIT.java | 8 +- .../android/client/GenericClientDstu3IT.java | 18 +- .../java/ca/uhn/fhir/context/FhirContext.java | 14 + .../uhn/fhir/context/FhirVersionEnumTest.java | 4 +- .../ca/uhn/fhir/i18n/HapiLocalizerTest.java | 6 +- .../executor/InterceptorServiceTest.java | 35 +- .../model/RequestPartitionIdTest.java | 6 +- .../api/ResourceMetadataKeyEnumTest.java | 4 +- .../java/ca/uhn/fhir/model/api/TagTest.java | 4 +- .../parser/json/JsonLikeStructureTest.java | 8 +- .../rest/api/CacheControlDirectiveTest.java | 4 +- .../ca/uhn/fhir/rest/api/ConstantsTest.java | 2 +- .../uhn/fhir/rest/api/EncodingEnumTest.java | 4 +- .../fhir/rest/api/QualifiedParamListTest.java | 12 +- .../fhir/rest/param/DateRangeParamTest.java | 11 +- .../fhir/rest/param/QualifierDetailsTest.java | 4 +- .../uhn/fhir/rest/param/StringParamTest.java | 4 +- .../uhn/fhir/rest/param/TokenParamTest.java | 4 +- .../BaseServerResponseExceptionTest.java | 4 +- .../java/ca/uhn/fhir/util/AsyncUtilTest.java | 2 +- .../ca/uhn/fhir/util/ClasspathUtilTest.java | 4 +- .../uhn/fhir/util/DependencyLogUtilTest.java | 7 +- .../java/ca/uhn/fhir/util/FileUtilTest.java | 4 +- .../java/ca/uhn/fhir/util/LogUtilTest.java | 2 +- .../java/ca/uhn/fhir/util/ObjectUtilTest.java | 4 +- .../ca/uhn/fhir/util/ReflectionUtilTest.java | 4 +- .../java/ca/uhn/fhir/util/StopWatchTest.java | 10 +- .../java/ca/uhn/fhir/util/UrlUtilTest.java | 4 +- .../ca/uhn/fhir/util/ValidateUtilTest.java | 6 +- .../ca/uhn/fhir/util/VersionEnumTest.java | 4 +- .../ca/uhn/fhir/util/VersionUtilTest.java | 4 +- .../uhn/fhir/validation/PlaceholderTest.java | 2 +- .../validation/ResultSeverityEnumTest.java | 4 +- .../java/ca/uhn/fhir/cli/BaseCommandTest.java | 4 +- .../fhir/cli/CreatePackageCommandTest.java | 12 +- ...ExportConceptMapToCsvCommandDstu3Test.java | 20 +- .../ExportConceptMapToCsvCommandR4Test.java | 12 +- .../HapiFlywayMigrateDatabaseCommandTest.java | 6 +- ...ImportCsvToConceptMapCommandDstu3Test.java | 78 +- .../ImportCsvToConceptMapCommandR4Test.java | 83 +- .../ca/uhn/fhir/cli/InstallIgPackTest.java | 2 +- .../java/ca/uhn/fhir/cli/OptionsTest.java | 2 +- .../cli/UploadTerminologyCommandTest.java | 19 +- .../ca/uhn/fhir/cli/ValidateCommandTest.java | 12 +- .../okhttp/GenericOkHttpClientDstu2Test.java | 824 +++++------ .../OkHttpRestfulClientFactoryTest.java | 8 +- .../client/OkHttpRestfulClientTest.java | 6 +- .../client/apache/ApacheHttpRequestTest.java | 4 +- .../SimpleRequestHeaderInterceptorTest.java | 4 +- ...ersionedApiConverterInterceptorR4Test.java | 13 +- .../converter/VersionConvertor_10_30Test.java | 4 +- .../converter/VersionConvertor_14_30Test.java | 4 +- .../5_1_0/1952-migrate-to-junit5.yaml | 5 + .../igpack/parser/IgPackParserDstu3Test.java | 6 +- hapi-fhir-jaxrsserver-base/pom.xml | 2 +- .../client/GenericJaxRsClientDstu2Test.java | 1213 ++++++++--------- .../client/GenericJaxRsClientDstu3Test.java | 1087 +++++++-------- .../client/JaxRsRestfulClientFactoryTest.java | 9 +- ...xRsConformanceProviderDstu2Hl7OrgTest.java | 8 +- ...ctJaxRsConformanceProviderDstu2_1Test.java | 8 +- ...ractJaxRsConformanceProviderDstu3Test.java | 214 +-- ...bstractJaxRsConformanceProviderR4Test.java | 8 +- .../AbstractJaxRsConformanceProviderTest.java | 8 +- .../server/AbstractJaxRsProviderTest.java | 130 +- ...bstractJaxRsResourceProviderDstu3Test.java | 41 +- .../AbstractJaxRsResourceProviderTest.java | 45 +- .../JaxRsExceptionInterceptorTest.java | 8 +- .../JaxRsResponseExceptionTest.java | 6 +- .../util/JaxRsMethodBindingsDstu3Test.java | 83 +- .../util/JaxRsMethodBindingsMimeTypeTest.java | 23 +- .../server/util/JaxRsMethodBindingsTest.java | 74 +- .../server/util/JaxRsRequestDstu3Test.java | 23 +- .../jaxrs/server/util/JaxRsRequestTest.java | 21 +- .../server/util/JaxRsResponseDstu3Test.java | 10 +- .../jaxrs/server/util/JaxRsResponseTest.java | 12 +- .../JaxRsPatientProviderDstu3Test.java | 16 +- .../example/JaxRsPatientProviderR4Test.java | 24 +- .../example/JaxRsPatientProviderTest.java | 20 +- hapi-fhir-jpaserver-base/pom.xml | 38 +- .../java/ca/uhn/fhir/jpa/util/TestUtil.java | 5 - .../BaseBinaryStorageSvcImplTest.java | 4 +- .../DatabaseBlobBinaryStorageSvcImplTest.java | 26 +- .../FilesystemBinaryStorageSvcImplTest.java | 12 +- .../NullBinaryStorageSvcImplTest.java | 41 +- .../jpa/bulk/BulkDataExportProviderTest.java | 25 +- .../jpa/bulk/BulkDataExportSvcImplR4Test.java | 20 +- .../HapiFhirHibernateJpaDialectTest.java | 9 +- .../ca/uhn/fhir/jpa/config/JpaEntityTest.java | 2 +- .../uhn/fhir/jpa/config/TestDstu2Config.java | 2 +- .../uhn/fhir/jpa/config/TestDstu3Config.java | 2 +- .../ca/uhn/fhir/jpa/config/TestR4Config.java | 3 +- .../ca/uhn/fhir/jpa/config/TestR5Config.java | 2 +- .../uhn/fhir/jpa/dao/BaseHapiFhirDaoTest.java | 4 +- .../java/ca/uhn/fhir/jpa/dao/BaseJpaTest.java | 38 +- .../ca/uhn/fhir/jpa/dao/DaoConfigTest.java | 6 +- .../uhn/fhir/jpa/dao/SearchBuilderTest.java | 10 +- .../fhir/jpa/dao/SearchFilterSyntaxTest.java | 22 +- .../jpa/dao/TolerantJsonParserR4Test.java | 9 +- .../jpa/dao/dstu2/BaseJpaDstu2SystemTest.java | 12 +- .../fhir/jpa/dao/dstu2/BaseJpaDstu2Test.java | 27 +- ...ceDaoDstu2SearchCustomSearchParamTest.java | 53 +- .../FhirResourceDaoDstu2SearchFtTest.java | 20 +- .../FhirResourceDaoDstu2SearchNoFtTest.java | 53 +- .../dao/dstu2/FhirResourceDaoDstu2Test.java | 74 +- .../dstu2/FhirResourceDaoDstu2UpdateTest.java | 19 +- .../FhirResourceDaoDstu2ValidateTest.java | 21 +- .../FhirResourceDaoValueSetDstu2Test.java | 70 +- .../jpa/dao/dstu2/FhirSearchDaoDstu2Test.java | 59 +- .../dstu2/FhirSystemDaoDstu2SearchTest.java | 9 +- .../jpa/dao/dstu2/FhirSystemDaoDstu2Test.java | 62 +- .../jpa/dao/dstu3/BaseJpaDstu3SystemTest.java | 12 +- .../fhir/jpa/dao/dstu3/BaseJpaDstu3Test.java | 35 +- .../dstu3/FhirDaoConcurrencyDstu3Test.java | 22 +- .../FhirResourceDaoCustomTypeDstu3Test.java | 17 +- .../FhirResourceDaoDocumentDstu3Test.java | 10 +- .../FhirResourceDaoDstu3CodeSystemTest.java | 11 +- .../FhirResourceDaoDstu3ConceptMapTest.java | 14 +- .../FhirResourceDaoDstu3ContainedTest.java | 8 +- ...ResourceDaoDstu3ExternalReferenceTest.java | 51 +- ...esourceDaoDstu3PhoneticSearchNoFtTest.java | 17 +- ...ourceDaoDstu3ReferentialIntegrityTest.java | 17 +- ...ceDaoDstu3SearchCustomSearchParamTest.java | 34 +- ...hirResourceDaoDstu3SearchDistanceTest.java | 10 +- .../FhirResourceDaoDstu3SearchFtTest.java | 58 +- .../FhirResourceDaoDstu3SearchNoFtTest.java | 59 +- .../dstu3/FhirResourceDaoDstu3SourceTest.java | 21 +- ...sourceDaoDstu3StructureDefinitionTest.java | 16 +- .../FhirResourceDaoDstu3TerminologyTest.java | 30 +- .../dao/dstu3/FhirResourceDaoDstu3Test.java | 58 +- .../dstu3/FhirResourceDaoDstu3UpdateTest.java | 42 +- .../FhirResourceDaoDstu3ValidateTest.java | 24 +- .../FhirResourceDaoDstu3ValueSetTest.java | 34 +- .../jpa/dao/dstu3/FhirSearchDaoDstu3Test.java | 12 +- .../dstu3/FhirSystemDaoDstu3SearchTest.java | 10 +- .../jpa/dao/dstu3/FhirSystemDaoDstu3Test.java | 83 +- .../fhir/jpa/dao/expunge/ExpungeHookTest.java | 21 +- .../jpa/dao/expunge/PartitionRunnerTest.java | 16 +- .../predicate/PredicateBuilderCoordsTest.java | 21 +- .../jpa/dao/predicate/SearchFuzzUtilTest.java | 6 +- .../fhir/jpa/dao/r4/BaseJpaR4SystemTest.java | 12 +- .../ca/uhn/fhir/jpa/dao/r4/BaseJpaR4Test.java | 43 +- .../fhir/jpa/dao/r4/BaseR4SearchLastN.java | 145 +- .../jpa/dao/r4/ConsentEventsDaoR4Test.java | 32 +- ...irResourceDaoCreatePlaceholdersR4Test.java | 20 +- .../r4/FhirResourceDaoCustomTypeR4Test.java | 17 +- .../dao/r4/FhirResourceDaoDocumentR4Test.java | 10 +- .../r4/FhirResourceDaoR4CacheWarmingTest.java | 20 +- .../r4/FhirResourceDaoR4CodeSystemTest.java | 16 +- .../r4/FhirResourceDaoR4ConceptMapTest.java | 18 +- .../r4/FhirResourceDaoR4ContainedTest.java | 8 +- .../dao/r4/FhirResourceDaoR4CreateTest.java | 20 +- .../dao/r4/FhirResourceDaoR4DeleteTest.java | 22 +- ...hirResourceDaoR4ExternalReferenceTest.java | 42 +- .../dao/r4/FhirResourceDaoR4FilterTest.java | 61 +- .../r4/FhirResourceDaoR4InterceptorTest.java | 24 +- ...rResourceDaoR4InvalidSubscriptionTest.java | 23 +- .../r4/FhirResourceDaoR4QueryCountTest.java | 37 +- ...ResourceDaoR4ReferentialIntegrityTest.java | 17 +- ...ourceDaoR4SearchCustomSearchParamTest.java | 28 +- .../FhirResourceDaoR4SearchDistanceTest.java | 8 +- .../dao/r4/FhirResourceDaoR4SearchFtTest.java | 23 +- .../FhirResourceDaoR4SearchLastNAsyncIT.java | 46 +- .../r4/FhirResourceDaoR4SearchLastNIT.java | 39 +- .../FhirResourceDaoR4SearchMissingTest.java | 25 +- .../r4/FhirResourceDaoR4SearchNoFtTest.java | 100 +- .../FhirResourceDaoR4SearchNoHashesTest.java | 66 +- .../FhirResourceDaoR4SearchOptimizedTest.java | 44 +- ...FhirResourceDaoR4SearchPageExpiryTest.java | 50 +- ...esourceDaoR4SearchWithElasticSearchIT.java | 24 +- ...urceDaoR4SearchWithLuceneDisabledTest.java | 28 +- .../FhirResourceDaoR4SelectiveUpdateTest.java | 11 +- .../jpa/dao/r4/FhirResourceDaoR4SortTest.java | 20 +- .../dao/r4/FhirResourceDaoR4SourceTest.java | 21 +- ...rResourceDaoR4StructureDefinitionTest.java | 14 +- ...sourceDaoR4TerminologyElasticsearchIT.java | 26 +- .../r4/FhirResourceDaoR4TerminologyTest.java | 36 +- .../jpa/dao/r4/FhirResourceDaoR4Test.java | 67 +- ...hirResourceDaoR4UniqueSearchParamTest.java | 57 +- ...hirResourceDaoR4UpdateTagSnapshotTest.java | 11 +- .../dao/r4/FhirResourceDaoR4UpdateTest.java | 34 +- .../dao/r4/FhirResourceDaoR4ValidateTest.java | 79 +- .../dao/r4/FhirResourceDaoR4ValueSetTest.java | 29 +- .../FhirResourceDaoSearchParameterR4Test.java | 19 +- .../fhir/jpa/dao/r4/FhirSearchDaoR4Test.java | 12 +- .../jpa/dao/r4/FhirSystemDaoR4SearchTest.java | 9 +- .../fhir/jpa/dao/r4/FhirSystemDaoR4Test.java | 58 +- .../fhir/jpa/dao/r4/PartitioningR4Test.java | 36 +- ...bservationIndexedSearchParamLastNR4IT.java | 43 +- .../dao/r4/SearchCoordinatorSvcImplTest.java | 17 +- .../dao/r4/SearchParamExtractorR4Test.java | 24 +- .../jpa/dao/r4/SearchParameterMapTest.java | 7 +- .../dao/r4/SearchWithInterceptorR4Test.java | 14 +- .../jpa/dao/r4/TransactionDeleteR4Test.java | 10 +- .../ca/uhn/fhir/jpa/dao/r5/BaseJpaR5Test.java | 37 +- .../r5/FhirResourceDaoR5SearchNoFtTest.java | 12 +- .../r5/StorageInterceptorEventsR5Test.java | 23 +- .../delete/DeleteConflictServiceR4Test.java | 14 +- .../jpa/delete/DeleteConflictServiceTest.java | 36 +- .../fhir/jpa/entity/TermCodeSystemTest.java | 6 +- .../jpa/entity/TermCodeSystemVersionTest.java | 4 +- .../jpa/graphql/JpaStorageServicesTest.java | 46 +- .../jpa/packages/IgInstallerDstu3Test.java | 26 +- .../jpa/packages/JpaPackageCacheTest.java | 5 +- .../fhir/jpa/packages/NpmSearchTestR4.java | 14 +- .../uhn/fhir/jpa/packages/NpmTestDstu3.java | 14 +- .../ca/uhn/fhir/jpa/packages/NpmTestR4.java | 20 +- .../packages/PackageInstallationSpecTest.java | 4 +- .../PackageVersionComparatorTest.java | 8 +- .../PartitionManagementProviderTest.java | 31 +- .../PartitionSettingsSvcImplTest.java | 6 +- .../fhir/jpa/patch/FhirPatchApplyR4Test.java | 7 +- ...chCoreTest.java => FhirPatchCoreTest.java} | 56 +- .../fhir/jpa/patch/FhirPatchDiffR4Test.java | 7 +- .../fhir/jpa/patch/FhirPatchR4CoreTest.java | 33 - .../fhir/jpa/patch/FhirPatchR5CoreTest.java | 33 - .../BaseResourceProviderDstu2Test.java | 13 +- .../provider/JpaGraphQLR4ProviderTest.java | 22 +- .../provider/ResourceProviderDstu2Test.java | 148 +- .../ResourceProviderDstu2ValueSetTest.java | 24 +- .../ResourceProviderExpungeDstu2Test.java | 22 +- .../jpa/provider/SearchParameterMapTest.java | 15 +- .../jpa/provider/SubscriptionsDstu2Test.java | 24 +- .../jpa/provider/SystemProviderDstu2Test.java | 23 +- ...temProviderTransactionSearchDstu2Test.java | 62 +- .../TerminologyUploaderProviderTest.java | 13 +- .../dstu3/BaseResourceProviderDstu3Test.java | 13 +- .../dstu3/CompositionDocumentDstu3Test.java | 21 +- .../jpa/provider/dstu3/CorsDstu3Test.java | 12 +- .../dstu3/GraphQLProviderDstu3Test.java | 4 +- .../dstu3/PatientEverythingDstu3Test.java | 36 +- ...rceProviderCustomSearchParamDstu3Test.java | 37 +- .../ResourceProviderDeleteSqlDstu3Test.java | 4 +- .../ResourceProviderDstu3BundleTest.java | 15 +- .../ResourceProviderDstu3CodeSystemTest.java | 19 +- .../ResourceProviderDstu3ConceptMapTest.java | 14 +- .../ResourceProviderDstu3DistanceTest.java | 6 +- ...eProviderDstu3StructureDefinitionTest.java | 10 +- .../dstu3/ResourceProviderDstu3Test.java | 72 +- .../ResourceProviderDstu3ValueSetTest.java | 19 +- .../ResourceProviderExpungeDstu3Test.java | 22 +- ...roviderQuestionnaireResponseDstu3Test.java | 48 +- .../jpa/provider/dstu3/ServerDstu3Test.java | 10 +- .../dstu3/SubscriptionsDstu3Test.java | 28 +- ...temProviderTransactionSearchDstu3Test.java | 31 +- .../r4/AuthorizationInterceptorJpaR4Test.java | 172 ++- ...zationInterceptorMultitenantJpaR4Test.java | 36 +- ...BaseMultitenantResourceProviderR4Test.java | 24 +- .../r4/BaseResourceProviderR4Test.java | 20 +- .../r4/BinaryAccessProviderR4Test.java | 47 +- .../r4/BinaryStorageInterceptorR4Test.java | 21 +- .../r4/CascadingDeleteInterceptorR4Test.java | 55 +- .../r4/CompositionDocumentR4Test.java | 33 +- ...sentInterceptorResourceProviderR4Test.java | 60 +- .../uhn/fhir/jpa/provider/r4/CorsR4Test.java | 10 +- .../jpa/provider/r4/DiffProviderR4Test.java | 29 +- .../jpa/provider/r4/EmptyIndexesR4Test.java | 31 +- .../fhir/jpa/provider/r4/ExpungeR4Test.java | 21 +- .../provider/r4/GraphQLProviderR4Test.java | 8 +- .../provider/r4/HookInterceptorR4Test.java | 47 +- .../provider/r4/MultitenantServerR4Test.java | 28 +- .../jpa/provider/r4/PatchProviderR4Test.java | 39 +- .../provider/r4/PatientEverythingR4Test.java | 53 +- ...sourceProviderCustomSearchParamR4Test.java | 63 +- .../r4/ResourceProviderExpungeR4Test.java | 32 +- .../r4/ResourceProviderInterceptorR4Test.java | 41 +- ...oviderOnlySomeResourcesProvidedR4Test.java | 15 +- ...ceProviderQuestionnaireResponseR4Test.java | 12 +- .../r4/ResourceProviderR4BundleTest.java | 19 +- .../r4/ResourceProviderR4CacheTest.java | 59 +- .../r4/ResourceProviderR4CodeSystemTest.java | 58 +- .../r4/ResourceProviderR4ConceptMapTest.java | 72 +- .../r4/ResourceProviderR4DistanceTest.java | 23 +- ...urceProviderR4StructureDefinitionTest.java | 26 +- .../provider/r4/ResourceProviderR4Test.java | 788 +++++------ .../r4/ResourceProviderR4ValueSetTest.java | 91 +- .../r4/ResourceProviderSummaryModeR4Test.java | 26 +- .../fhir/jpa/provider/r4/ServerR4Test.java | 22 +- .../r4/StaleSearchDeletingSvcR4Test.java | 34 +- .../jpa/provider/r4/SubscriptionsR4Test.java | 46 +- .../jpa/provider/r4/SystemProviderR4Test.java | 128 +- ...SystemProviderTransactionSearchR4Test.java | 37 +- .../r4/TerminologyUploaderProviderR4Test.java | 133 +- .../r5/BaseResourceProviderR5Test.java | 25 +- .../provider/r5/ResourceProviderR5Test.java | 42 +- .../r5/ResourceProviderR5ValueSetTest.java | 110 +- .../fhir/jpa/provider/r5/ServerR5Test.java | 24 +- .../jpa/sched/SchedulerServiceImplTest.java | 20 +- .../PagingMultinodeProviderDstu3Test.java | 50 +- .../PersistedJpaBundleProviderTest.java | 12 +- .../search/SearchCoordinatorSvcImplTest.java | 89 +- .../cache/DatabaseSearchCacheSvcImplTest.java | 21 +- ...lasticsearchSvcMultipleObservationsIT.java | 67 +- ...tNElasticsearchSvcSingleObservationIT.java | 47 +- .../r4/PagingMultinodeProviderR4Test.java | 35 +- .../ResourceReindexingSvcImplTest.java | 11 +- .../jpa/searchparam/MatchUrlServiceTest.java | 23 +- .../jpa/stresstest/StressTestParserTest.java | 9 +- .../fhir/jpa/stresstest/StressTestR4Test.java | 49 +- .../subscription/BaseSubscriptionsR4Test.java | 38 +- .../subscription/BaseSubscriptionsR5Test.java | 68 +- .../jpa/subscription/FhirServiceUtil.java | 5 +- ...SubscriptionValidatingInterceptorTest.java | 21 +- .../email/EmailSubscriptionDstu2Test.java | 12 +- .../email/EmailSubscriptionDstu3Test.java | 34 +- .../email/JavaMailEmailSenderTest.java | 12 +- .../InMemorySubscriptionMatcherR4Test.java | 22 +- ...tivatesPreExistingSubscriptionsR4Test.java | 19 +- .../resthook/RestHookTestDstu2Test.java | 33 +- .../resthook/RestHookTestDstu3Test.java | 55 +- .../resthook/RestHookTestR4Test.java | 157 ++- .../resthook/RestHookTestR5Test.java | 127 +- ...rceptorRegisteredToDaoConfigDstu2Test.java | 44 +- ...rceptorRegisteredToDaoConfigDstu3Test.java | 43 +- ...nterceptorRegisteredToDaoConfigR4Test.java | 68 +- .../RestHookWithEventDefinitionR4Test.java | 36 +- .../RestHookWithInterceptorR4Test.java | 47 +- .../SubscriptionTriggeringDstu3Test.java | 31 +- .../WebsocketWithCriteriaDstu2Test.java | 18 +- .../WebsocketWithCriteriaDstu3Test.java | 18 +- .../WebsocketWithCriteriaR4Test.java | 26 +- .../WebsocketWithSubscriptionIdDstu2Test.java | 14 +- .../WebsocketWithSubscriptionIdDstu3Test.java | 14 +- .../WebsocketWithSubscriptionIdR4Test.java | 22 +- .../ca/uhn/fhir/jpa/term/BaseLoaderTest.java | 8 +- .../ca/uhn/fhir/jpa/term/BaseTermR4Test.java | 8 +- .../term/TermCodeSystemStorageSvcTest.java | 6 +- .../term/TermDeferredStorageSvcImplTest.java | 14 +- .../term/TerminologyLoaderSvcCustomTest.java | 22 +- .../term/TerminologyLoaderSvcImgthlaTest.java | 21 +- ...minologyLoaderSvcIntegrationDstu3Test.java | 24 +- .../term/TerminologyLoaderSvcLoincTest.java | 41 +- .../TerminologyLoaderSvcSnomedCtTest.java | 20 +- .../jpa/term/TerminologySvcDeltaR4Test.java | 24 +- .../jpa/term/TerminologySvcImplDstu3Test.java | 141 +- .../jpa/term/TerminologySvcImplR4Test.java | 63 +- .../term/ValueSetConceptAccumulatorTest.java | 20 +- .../ValueSetExpansionR4ElasticsearchIT.java | 29 +- .../jpa/term/ValueSetExpansionR4Test.java | 30 +- .../uhn/fhir/jpa/testutil/SpringFileTest.java | 15 +- .../fhir/jpa/util/CoordCalculatorTest.java | 4 +- .../uhn/fhir/jpa/util/HashFunctionTester.java | 2 +- .../uhn/fhir/jpa/util/JpaClasspathTest.java | 6 +- .../fhir/jpa/util/ResourceCountCacheTest.java | 23 +- .../util/jsonpatch/JsonPatchUtilsTest.java | 9 +- .../fhir/jpa/z/ZContextCloserDstu2Test.java | 2 +- .../fhir/validator/AttachmentUtilTest.java | 11 +- .../ValidatorAcrossVersionsTest.java | 16 +- hapi-fhir-jpaserver-empi/pom.xml | 26 +- .../ca/uhn/fhir/jpa/empi/BaseEmpiR4Test.java | 21 +- .../fhir/jpa/empi/dao/EmpiLinkDaoSvcTest.java | 7 +- .../fhir/jpa/empi/entity/EmpiEnumTest.java | 4 +- .../fhir/jpa/empi/helper/BaseEmpiHelper.java | 36 +- .../jpa/empi/interceptor/EmpiExpungeTest.java | 14 +- .../interceptor/EmpiStorageInterceptorIT.java | 31 +- .../jpa/empi/provider/BaseLinkR4Test.java | 7 +- .../jpa/empi/provider/BaseProviderR4Test.java | 7 +- .../EmpiProviderMergePersonsR4Test.java | 13 +- .../provider/EmpiProviderQueryLinkR4Test.java | 13 +- .../EmpiProviderUpdateLinkR4Test.java | 8 +- .../empi/searchparam/SearchParameterTest.java | 14 +- ...CandidateSearchCriteriaBuilderSvcTest.java | 8 +- .../empi/svc/EmpiCandidateSearchSvcTest.java | 4 +- .../fhir/jpa/empi/svc/EmpiLinkSvcTest.java | 16 +- .../EmpiMatchLinkSvcMultipleEidModeTest.java | 12 +- .../jpa/empi/svc/EmpiMatchLinkSvcTest.java | 41 +- .../jpa/empi/svc/EmpiPersonMergerSvcTest.java | 16 +- .../jpa/empi/svc/EmpiResourceDaoSvcTest.java | 10 +- hapi-fhir-jpaserver-migrate/pom.xml | 5 - .../jpa/migrate/MigrationTaskSkipperTest.java | 8 +- .../fhir/jpa/migrate/SchemaMigratorTest.java | 49 +- .../jpa/migrate/taskdef/AddColumnTest.java | 46 +- .../taskdef/AddForeignKeyTaskTest.java | 16 +- .../taskdef/AddIdGeneratorTaskTest.java | 14 +- .../jpa/migrate/taskdef/AddIndexTest.java | 37 +- .../taskdef/AddTableByColumnTaskTest.java | 15 +- .../jpa/migrate/taskdef/AddTableTest.java | 22 +- .../migrate/taskdef/ArbitrarySqlTaskTest.java | 40 +- .../jpa/migrate/taskdef/BaseTaskTest.java | 6 +- .../fhir/jpa/migrate/taskdef/BaseTest.java | 28 +- .../migrate/taskdef/CalculateHashesTest.java | 21 +- .../jpa/migrate/taskdef/DropColumnTest.java | 26 +- .../taskdef/DropForeignKeyTaskTest.java | 15 +- .../taskdef/DropIdGeneratorTaskTest.java | 14 +- .../jpa/migrate/taskdef/DropIndexTest.java | 45 +- .../jpa/migrate/taskdef/DropTableTest.java | 48 +- .../taskdef/ExecuteRawSqlTaskTest.java | 23 +- .../fhir/jpa/migrate/taskdef/HashTest.java | 10 +- .../taskdef/InitializeSchemaTaskTest.java | 15 +- .../jpa/migrate/taskdef/ModifyColumnTest.java | 90 +- .../RenameColumnTaskDbSpecificTest.java | 5 +- .../migrate/taskdef/RenameColumnTaskTest.java | 106 +- .../tasks/HapiFhirJpaMigrationTasksTest.java | 2 +- .../tasks/api/BaseMigrationTasksTest.java | 6 +- .../ResourceIndexedSearchParamCoordsTest.java | 6 +- .../ResourceIndexedSearchParamDateTest.java | 44 +- ...esourceIndexedSearchParamQuantityTest.java | 6 +- .../ResourceIndexedSearchParamStringTest.java | 6 +- .../ResourceIndexedSearchParamTokenTest.java | 6 +- .../ResourceIndexedSearchParamUriTest.java | 6 +- .../jpa/model/entity/ResourceTableTest.java | 4 +- .../jpa/model/entity/TagDefinitionTest.java | 6 +- .../jpa/model/entity/TagTypeEnumTest.java | 8 +- .../fhir/jpa/model/util/StringUtilTest.java | 4 +- .../fhir/jpa/searchparam/IndexStressTest.java | 4 +- .../ResourceIndexedSearchParamsTest.java | 12 +- .../SearchParamExtractorDstu3Test.java | 14 +- .../SearchParamExtractorMegaTest.java | 6 +- .../SearchParamExtractorServiceTest.java | 18 +- .../InMemoryResourceMatcherR5Test.java | 96 +- .../registry/SearchParamRegistryImplTest.java | 24 +- .../jpa/searchparam/retry/RetrierTest.java | 42 +- .../SubscriptionChannelFactoryTest.java | 16 +- ...aseSubscriptionDeliverySubscriberTest.java | 16 +- .../matching/DaoSubscriptionMatcherTest.java | 10 +- .../registry/ActiveSubscriptionCacheTest.java | 12 +- .../module/BaseSubscriptionDstu3Test.java | 4 +- .../module/BaseSubscriptionTest.java | 10 +- .../module/CanonicalSubscriptionTest.java | 6 +- .../module/ResourceModifiedTest.java | 6 +- .../cache/BaseSubscriptionRegistryTest.java | 4 +- .../module/cache/SubscriptionLoaderTest.java | 9 +- .../cache/SubscriptionRegistrySharedTest.java | 2 +- .../cache/SubscriptionRegistryTest.java | 4 +- .../SubscriptionChannelRegistryTest.java | 29 +- .../InMemorySubscriptionMatcherR3Test.java | 12 +- .../SubscriptionStrategyEvaluatorTest.java | 20 +- ...kingQueueSubscribableChannelDstu3Test.java | 16 +- .../ResourceDeliveryMessageTest.java | 4 +- .../SubscriptionCheckingSubscriberTest.java | 4 +- .../SubscriptionMatchingSubscriberTest.java | 4 +- .../WebsocketConnectionValidatorTest.java | 26 +- ...bscriptionSubmitInterceptorLoaderTest.java | 8 +- ...SubscriptionValidatingInterceptorTest.java | 49 +- hapi-fhir-jpaserver-test-utilities/pom.xml | 15 +- .../ca/uhn/fhir/jpa/test/BaseJpaTest.java | 10 +- .../TemplateNarrativeGeneratorTest.java | 2 +- ...TokenServerInterceptorIntegrationTest.java | 16 +- ...nnectBearerTokenServerInterceptorTest.java | 6 +- hapi-fhir-server-empi/pom.xml | 11 + .../java/ca/uhn/fhir/empi/BaseR4Test.java | 5 +- .../rules/config/EmpiRuleValidatorTest.java | 8 +- .../empi/rules/json/EmpiRulesJsonR4Test.java | 14 +- .../rules/json/VectorMatchResultMapTest.java | 4 +- .../metric/matcher/DateMatcherR4Test.java | 20 +- .../metric/matcher/StringMatcherR4Test.java | 6 +- .../empi/rules/svc/BaseEmpiRulesR4Test.java | 4 +- .../svc/CustomResourceMatcherR4Test.java | 53 +- .../svc/EmpiResourceFieldMatcherR4Test.java | 15 +- .../svc/EmpiResourceMatcherSvcR4Test.java | 12 +- .../ca/uhn/fhir/empi/svc/EIDHelperR4Test.java | 8 +- .../uhn/fhir/empi/svc/NameUtilTestDSTU3.java | 4 +- .../ca/uhn/fhir/empi/svc/NameUtilTestR4.java | 2 +- .../fhir/empi/svc/PersonHelperDSTU3Test.java | 8 +- .../uhn/fhir/empi/svc/PersonHelperR4Test.java | 8 +- .../empi/util/AssuranceLevelUtilTest.java | 9 +- hapi-fhir-server/pom.xml | 2 +- .../rest/api/server/IBundleProviderTest.java | 6 +- .../SimplePreResourceShowDetailsTest.java | 34 +- .../ApacheProxyAddressStrategyTest.java | 8 +- .../CommonResourceSupertypeScannerTest.java | 4 +- .../IncomingRequestAddressStrategyTest.java | 4 +- .../fhir/rest/server/RestfulResponseTest.java | 9 +- .../fhir/rest/server/RestfulServerTest.java | 26 +- .../rest/server/RestfulServerUtilsTest.java | 4 +- .../rest/server/SimpleBundleProviderTest.java | 4 +- .../ca/uhn/fhir/rest/server/VerdictTest.java | 2 +- .../interceptor/auth/RuleBuilderTest.java | 6 +- .../interceptor/auth/RuleImplOpTest.java | 2 +- .../server/interceptor/auth/VerdictTest.java | 2 +- .../method/ConformanceMethodBindingTest.java | 6 +- .../server/method/MethodMatchEnumTest.java | 4 +- .../server/method/ReadMethodBindingTest.java | 14 +- .../method/SearchMethodBindingTest.java | 30 +- .../servlet/ServletRestfulResponseTest.java | 27 +- .../FhirAutoConfigurationTest.java | 30 +- ...pleJerseyRestfulServerApplicationTest.java | 45 +- ...SampleJpaRestfulServerApplicationTest.java | 36 +- .../fhir/context/DuplicateExtensionTest.java | 6 +- .../ca/uhn/fhir/context/ExtensionTest.java | 8 +- .../fhir/context/FhirContextDstu1Test.java | 8 +- .../uhn/fhir/context/FhirVersionEnumTest.java | 8 +- .../fhir/context/InvalidResourceTypeTest.java | 8 +- .../uhn/fhir/context/ModelExtensionTest.java | 8 +- .../fhir/context/ModelScannerDstu1Test.java | 16 +- .../java/ca/uhn/fhir/context/NameChanges.java | 8 +- .../context/ProvidedResourceScannerTest.java | 12 +- .../fhir/context/ResourceWithExtensionsA.java | 6 +- .../RuntimeResourceDefinitionTest.java | 14 +- .../context/copy/DuplicateExtensionTest.java | 6 +- .../uhn/fhir/context/copy/ExtensionTest.java | 8 +- .../context/copy/FhirContextDstu1Test.java | 8 +- .../context/copy/FhirVersionEnumTest.java | 8 +- .../context/copy/InvalidResourceTypeTest.java | 8 +- .../fhir/context/copy/ModelExtensionTest.java | 8 +- .../context/copy/ModelScannerDstu1Test.java | 16 +- .../ca/uhn/fhir/context/copy/NameChanges.java | 8 +- .../copy/ProvidedResourceScannerTest.java | 12 +- .../context/copy/ResourceWithExtensionsA.java | 6 +- .../copy/RuntimeResourceDefinitionTest.java | 14 +- .../ca/uhn/fhir/model/api/TagListTest.java | 8 +- .../base/composite/BaseCodingDtTest.java | 8 +- .../model/primitive/Base64BinaryDtTest.java | 6 +- .../fhir/model/primitive/CodingDtTest.java | 8 +- .../fhir/model/primitive/DecimalDtTest.java | 8 +- .../ca/uhn/fhir/model/primitive/IdDtTest.java | 12 +- .../model/primitive/IdentifierDtTest.java | 8 +- .../fhir/model/primitive/StringDtTest.java | 8 +- .../uhn/fhir/model/primitive/UriDtTest.java | 8 +- .../uhn/fhir/model/primitive/XhtmlDtTest.java | 8 +- .../fhir/model/view/ViewGeneratorTest.java | 8 +- .../BaseThymeleafNarrativeGeneratorTest.java | 8 +- ...CustomThymeleafNarrativeGeneratorTest.java | 8 +- ...efaultThymeleafNarrativeGeneratorTest.java | 12 +- .../ca/uhn/fhir/parser/BaseParserTest.java | 8 +- .../parser/ContainedResourceEncodingTest.java | 520 +++---- .../ca/uhn/fhir/parser/JsonParserTest.java | 32 +- .../ca/uhn/fhir/parser/XmlParserTest.java | 28 +- .../parser/jsonlike/JsonLikeParserTest.java | 14 +- .../fhir/rest/server/AcceptHeaderTest.java | 12 +- .../ca/uhn/fhir/rest/server/BinaryTest.java | 16 +- .../rest/server/CompositeParameterTest.java | 12 +- .../uhn/fhir/rest/server/CompressionTest.java | 12 +- .../ca/uhn/fhir/rest/server/CreateTest.java | 16 +- .../uhn/fhir/rest/server/CustomTypeTest.java | 8 +- .../fhir/rest/server/DefaultEncodingTest.java | 12 +- .../ca/uhn/fhir/rest/server/DestroyTest.java | 10 +- .../rest/server/Dstu1BundleFactoryTest.java | 16 +- .../uhn/fhir/rest/server/ExceptionTest.java | 18 +- .../IncomingRequestAddressStrategyTest.java | 16 +- .../uhn/fhir/rest/server/InterceptorTest.java | 8 +- .../fhir/rest/server/MethodPriorityTest.java | 16 +- .../ca/uhn/fhir/rest/server/PagingTest.java | 20 +- .../fhir/rest/server/PlainProviderTest.java | 16 +- .../uhn/fhir/rest/server/ReadDstu1Test.java | 12 +- .../rest/server/ReferenceParameterTest.java | 16 +- .../fhir/rest/server/ResourceMethodTest.java | 14 +- .../ResourceProviderWithNoMethodsTest.java | 12 +- .../rest/server/RestfulServerMethodTest.java | 18 +- .../RestfulServerSelfReferenceTest.java | 12 +- .../rest/server/RestfulServerUtilsTest.java | 8 +- ...archBundleProviderWithNoSizeDstu1Test.java | 16 +- .../uhn/fhir/rest/server/ServerBaseTest.java | 16 +- .../server/ServerConformanceProviderTest.java | 12 +- .../server/ServerExtraParametersTest.java | 16 +- .../fhir/rest/server/ServerFeaturesTest.java | 18 +- .../server/ServerInvalidDefinitionTest.java | 8 +- .../ServerProvidedResourceScannerTest.java | 6 +- .../server/ServletContextParsingTest.java | 16 +- .../ca/uhn/fhir/rest/server/SortTest.java | 12 +- .../fhir/rest/server/StringParameterTest.java | 12 +- .../uhn/fhir/rest/server/TagsServerTest.java | 16 +- .../uhn/fhir/rest/server/TokenParamTest.java | 16 +- .../uhn/fhir/rest/server/TransactionTest.java | 16 +- .../TransactionWithBundleParamTest.java | 16 +- .../uhn/fhir/rest/server/UpdateDstu1Test.java | 12 +- .../fhir/rest/server/ValidateDstu1Test.java | 16 +- .../validation/ResourceValidatorTest.java | 12 +- .../validation/ValidatorInstantiatorTest.java | 8 +- hapi-fhir-structures-dstu2.1/pom.xml | 6 + .../model/BackboneElementDstu2_1Test.java | 52 +- .../fhir/model/DomainResourceDstu2_1Test.java | 60 +- .../ca/uhn/fhir/model/IdTypeDstu2_1Test.java | 31 +- .../ca/uhn/fhir/model/ModelDstu2_1Test.java | 35 +- .../model/ModelSerializationDstu2_1Test.java | 21 +- .../fhir/parser/CustomTypeDstu2_1Test.java | 47 +- .../EmptyElementWithExtensionDstu3Test.java | 21 +- .../ca/uhn/fhir/parser/ErrorHandlerTest.java | 87 +- .../fhir/parser/JsonParserDstu2_1Test.java | 664 ++++----- .../uhn/fhir/parser/XmlParserDstu2_1Test.java | 67 +- .../ClientServerValidationDstu2_1Test.java | 47 +- .../ClientWithCustomTypeDstu2_1Test.java | 38 +- .../rest/client/GenericClientDstu2_1Test.java | 182 +-- .../client/NonGenericClientDstu2_1Test.java | 57 +- .../client/OperationClientDstu2_1Test.java | 66 +- .../rest/client/PatchClientDstu2_1Test.java | 53 +- .../rest/client/SearchClientDstu2_1Test.java | 67 +- .../rest/server/CreateBinaryDstu2_1Test.java | 40 +- .../fhir/rest/server/CreateDstu2_1Test.java | 57 +- .../rest/server/CustomTypeServerDstu2_1.java | 51 +- .../server/DeleteConditionalDstu2_1Test.java | 36 +- .../server/FormatParameterDstu2_1Test.java | 29 +- .../MetadataConformanceDstu2_1Test.java | 51 +- .../server/OperationServerDstu2_1Test.java | 21 +- ...ServerWithSearchParamTypesDstu2_1Test.java | 63 +- .../fhir/rest/server/PatchDstu2_1Test.java | 16 +- .../uhn/fhir/rest/server/ReadDstu2_1Test.java | 39 +- .../server/SearchCountParamDstu2_1Test.java | 43 +- .../fhir/rest/server/SearchDstu2_1Test.java | 39 +- .../server/SearchHasParamDstu2_1Test.java | 41 +- .../rest/server/SearchPostDstu2_1Test.java | 50 +- .../rest/server/SearchSortDstu2_1Test.java | 39 +- .../SearchWithGenericListDstu2_1Test.java | 41 +- .../server/SearchWithIncludesDstu2_1Test.java | 41 +- ...hWithServerAddressStrategyDstu2_1Test.java | 33 +- .../server/ServerExceptionDstu2_1Test.java | 39 +- .../server/ServerMimetypeDstu2_1Test.java | 59 +- .../ServerUsingOldTypesDstu2_1Test.java | 23 +- ...nclassifiedServerExceptionDstu2_1Test.java | 35 +- .../fhir/rest/server/UpdateDstu2_1Test.java | 45 +- .../fhir/rest/server/ValidateDstu2_1Test.java | 26 +- hapi-fhir-structures-dstu2/pom.xml | 5 - .../ca/uhn/fhir/ctx/FhirContextDstu2Test.java | 56 +- .../ca/uhn/fhir/model/dstu2/BundleTest.java | 20 +- .../model/dstu2/CompartmentDstu2Test.java | 28 +- .../uhn/fhir/model/dstu2/ModelDstu2Test.java | 25 +- .../model/dstu2/ModelInstantiationTest.java | 17 +- .../dstu2/ModelSerializationDstu2Test.java | 23 +- .../primitive/BaseDateTimeDtDstu2Test.java | 106 +- .../BaseResourceReferenceDtTest.java | 68 +- .../uhn/fhir/model/primitive/DateDtTest.java | 13 +- .../fhir/model/primitive/DecimalDtTest.java | 4 +- .../uhn/fhir/model/primitive/TimeDtTest.java | 4 +- .../uhn/fhir/model/primitive/UriDtTest.java | 4 +- ...eThymeleafNarrativeGeneratorDstu2Test.java | 11 +- ...mThymeleafNarrativeGeneratorDstu2Test.java | 13 +- ...tThymeleafNarrativeGeneratorDstu2Test.java | 59 +- .../fhir/parser/CustomResource364Dstu2.java | 4 +- .../uhn/fhir/parser/CustomTypeDstu2Test.java | 47 +- .../parser/ElementWithExtensionDstu2Test.java | 28 +- .../EmptyElementWithExtensionDstu2Test.java | 11 +- .../uhn/fhir/parser/ExtensionsDstu2Test.java | 17 +- .../uhn/fhir/parser/JsonParserDstu2Test.java | 73 +- .../uhn/fhir/parser/XmlParserDstu2Test.java | 1163 ++++++++-------- .../uhn/fhir/parser/i391/TestOutcomeTest.java | 15 +- .../i423/CustomProcedureRequestTest.java | 4 +- .../jsonlike/JsonLikeParserDstu2Test.java | 6 +- .../fhir/rest/client/BundleTypeDstu2Test.java | 55 +- .../fhir/rest/client/ClientMockingTest.java | 23 +- .../ClientServerValidationDstu2Test.java | 69 +- .../client/ClientWithProfileDstu2Test.java | 53 +- .../fhir/rest/client/ETagClientDstu2Test.java | 54 +- .../rest/client/GenericClientDstu2Test.java | 82 +- .../rest/client/MessageClientDstu2Test.java | 57 +- .../rest/client/OperationClientDstu2Test.java | 51 +- .../client/RestfulClientFactoryDstu2Test.java | 33 +- .../apache/ApacheClientIntegrationTest.java | 30 +- .../ApacheRestfulClientFactoryTest.java | 6 +- .../ca/uhn/fhir/rest/param/DateParamTest.java | 25 +- .../rest/param/TokenOrListParamDstu2Test.java | 15 +- .../uhn/fhir/rest/server/BinaryDstu2Test.java | 25 +- .../rest/server/BundleTypeInResponseTest.java | 39 +- .../rest/server/CompartmentDstu2Test.java | 56 +- .../rest/server/CreateConditionalTest.java | 53 +- .../uhn/fhir/rest/server/DeleteDstu2Test.java | 40 +- .../uhn/fhir/rest/server/ETagServerTest.java | 59 +- .../IncludeAndRevincludeParameterTest.java | 48 +- .../fhir/rest/server/IncludeDstu2Test.java | 32 +- .../OperationDuplicateServerDstu2Test.java | 41 +- .../rest/server/OperationServerDstu2Test.java | 83 +- ...onServerWithSearchParamTypesDstu2Test.java | 68 +- .../uhn/fhir/rest/server/ReadDstu2Test.java | 18 +- ...archBundleProviderWithNoSizeDstu2Test.java | 63 +- .../server/SearchCountParamDstu2Test.java | 47 +- .../uhn/fhir/rest/server/SearchDstu2Test.java | 42 +- ...rchReturningProfiledResourceDstu2Test.java | 12 +- .../server/SearchWithDstu2BundleTest.java | 34 +- .../SearchWithGenericListDstu2Test.java | 47 +- .../ServerConformanceProviderDstu2Test.java | 87 +- .../rest/server/ServerFeaturesDstu2Test.java | 43 +- .../rest/server/ServerSearchDstu2Test.java | 19 +- .../rest/server/SummaryParamDstu2Test.java | 23 +- ...ransactionWithBundleResourceParamTest.java | 48 +- ...ithVersionlessBundleResourceParamTest.java | 16 +- .../uhn/fhir/rest/server/UpdateDstu2Test.java | 59 +- .../fhir/rest/server/ValidateDstu2Test.java | 51 +- .../InterceptorUserDataMapDstu2Test.java | 33 +- .../LoggingInterceptorDstu2Test.java | 34 +- .../ServerActionInterceptorTest.java | 31 +- .../dstu2/Dstu2BundleFactoryTest.java | 36 +- .../ca/uhn/fhir/util/FhirTerserDstu2Test.java | 14 +- .../fhir/validation/BundleValidationTest.java | 29 +- .../ResourceValidatorDstu2Test.java | 25 +- .../ValidatorInstantiatorDstu2Test.java | 11 +- hapi-fhir-structures-dstu3/pom.xml | 11 +- .../context/ContextScanningDstu3Test.java | 14 +- .../fhir/context/FhirContextDstu3Test.java | 25 +- .../fhir/context/ModelScannerDstu3Test.java | 38 +- .../RuntimeResourceDefinitionDstu3Test.java | 21 +- .../ca/uhn/fhir/context/VersionDstu3Test.java | 4 +- .../java/ca/uhn/fhir/model/DateTypeTest.java | 17 +- .../ca/uhn/fhir/model/DecimalTypeTest.java | 4 +- .../ca/uhn/fhir/model/IdTypeDstu3Test.java | 15 +- .../ca/uhn/fhir/model/ModelDstu3Test.java | 41 +- .../model/ModelSerializationDstu3Test.java | 22 +- .../java/ca/uhn/fhir/model/XhtmlNodeTest.java | 15 +- ...tThymeleafNarrativeGeneratorDstu3Test.java | 100 +- .../ThymeleafNarrativeGeneratorTest.java | 6 +- .../uhn/fhir/parser/CustomTypeDstu3Test.java | 54 +- .../parser/ElementWithExtensionDstu3Test.java | 16 +- .../EmptyElementWithExtensionDstu3Test.java | 15 +- .../ca/uhn/fhir/parser/ErrorHandlerTest.java | 75 +- .../uhn/fhir/parser/JsonParserDstu3Test.java | 74 +- .../uhn/fhir/parser/XmlParserDstu3Test.java | 105 +- .../jsonlike/JsonLikeParserDstu3Test.java | 31 +- .../rest/client/ClientMimetypeDstu3Test.java | 13 +- .../ClientServerValidationDstu3Test.java | 47 +- .../client/ClientWithCustomTypeDstu3Test.java | 42 +- .../rest/client/GenericClientDstu3Test.java | 187 +-- .../client/NonGenericClientDstu3Test.java | 57 +- .../rest/client/OperationClientDstu3Test.java | 130 +- .../rest/client/PatchClientDstu3Test.java | 53 +- .../rest/client/SearchClientDstu3Test.java | 38 +- .../fhir/rest/method/ParameterUtilTest.java | 4 +- .../uhn/fhir/rest/param/NumberParamTest.java | 15 +- .../fhir/rest/param/QuantityParamTest.java | 15 +- .../fhir/rest/param/ReferenceParamTest.java | 14 +- .../rest/param/TokenOrListParamDstu3Test.java | 11 +- .../rest/server/CreateBinaryDstu3Test.java | 17 +- .../uhn/fhir/rest/server/CreateDstu3Test.java | 55 +- .../rest/server/CustomTypeServerDstu3.java | 51 +- .../server/DeleteConditionalDstu3Test.java | 36 +- .../rest/server/FormatParameterDstu3Test.java | 10 +- .../rest/server/InterceptorDstu3Test.java | 45 +- .../MetadataCapabilityStatementDstu3Test.java | 24 +- .../server/MetadataConformanceDstu3Test.java | 24 +- .../rest/server/OperationServerDstu3Test.java | 59 +- ...onServerWithSearchParamTypesDstu3Test.java | 63 +- .../rest/server/PatchServerDstu3Test.java | 16 +- .../uhn/fhir/rest/server/ReadDstu3Test.java | 42 +- ...archBundleProviderWithNoSizeDstu3Test.java | 47 +- .../server/SearchCountParamDstu3Test.java | 18 +- .../server/SearchDefaultMethodDstu3Test.java | 49 +- .../uhn/fhir/rest/server/SearchDstu3Test.java | 63 +- .../rest/server/SearchHasParamDstu3Test.java | 42 +- .../fhir/rest/server/SearchPostDstu3Test.java | 48 +- .../fhir/rest/server/SearchSortDstu3Test.java | 39 +- .../SearchWithGenericListDstu3Test.java | 41 +- .../server/SearchWithIncludesDstu3Test.java | 41 +- ...rchWithServerAddressStrategyDstu3Test.java | 33 +- .../rest/server/ServerExceptionDstu3Test.java | 17 +- .../rest/server/ServerMimetypeDstu3Test.java | 55 +- .../server/ServerUsingOldTypesDstu3Test.java | 23 +- .../UnclassifiedServerExceptionDstu3Test.java | 35 +- .../uhn/fhir/rest/server/UpdateDstu3Test.java | 53 +- .../fhir/rest/server/ValidateDstu3Test.java | 46 +- ...pprtedHttpMethodsInterceptorDstu3Test.java | 55 +- .../interceptor/CorsInterceptorDstu3Test.java | 64 +- .../AuthorizationInterceptorDstu3Test.java | 42 +- .../java/ca/uhn/fhir/util/MetaUtilTest.java | 4 +- .../fhir/util/ParametersUtilDstu3Test.java | 2 +- .../ca/uhn/fhir/util/XmlUtilDstu3Test.java | 28 +- ...rCapabilityStatementProviderDstu3Test.java | 47 +- .../dstu3/model/BackboneElementDstu3Test.java | 50 +- .../model/BaseDateTimeTypeDstu3Test.java | 71 +- .../dstu3/model/CodesystemsDstu3Test.java | 16 +- .../dstu3/model/DomainResourceDstu3Test.java | 54 +- .../fhir/dstu3/model/HumanNameDstu3Test.java | 4 +- .../model/MetadataResourceDstu3Test.java | 58 +- .../fhir/utilities/xhtml/XhtmlNodeTest.java | 4 +- hapi-fhir-structures-hl7org-dstu2/pom.xml | 6 + .../dstu2hl7org/Dstu2Hl7OrgBundleFactory.java | 18 +- .../fhir/dstu2/hapi/ctx/FhirDstu2Hl7Org.java | 25 +- .../server/ServerConformanceProvider.java | 43 +- .../context/FhirContextDstu2Hl7OrgTest.java | 4 +- .../model/BackboneElementHL7_Dstu2Test.java | 8 +- .../model/DomainResourceHL7_Dstu2Test.java | 8 +- .../java/ca/uhn/fhir/model/IdTypeTest.java | 21 +- .../ca/uhn/fhir/model/InstantiationTest.java | 21 +- .../uhn/fhir/model/ModelInheritanceTest.java | 10 +- .../java/ca/uhn/fhir/model/PrimititeTest.java | 8 +- .../java/ca/uhn/fhir/model/XhtmlNodeTest.java | 10 +- .../parser/JsonParserHl7OrgDstu2Test.java | 33 +- .../parser/MyObservationWithExtensions.java | 13 +- .../uhn/fhir/parser/MyOrganizationDstu2.java | 3 +- .../ca/uhn/fhir/parser/MyPatientHl7Org.java | 15 +- ...ntWithOneDeclaredEnumerationExtension.java | 7 +- .../fhir/parser/ResourceWithExtensionsA.java | 20 +- .../fhir/parser/XmlParserHl7OrgDstu2Test.java | 104 +- ...ClientServerValidationTestHl7OrgDstu2.java | 51 +- .../uhn/fhir/rest/client/ETagClientTest.java | 217 ++- .../client/GenericClientDstu2Hl7OrgTest.java | 68 +- .../fhir/rest/client/OperationClientTest.java | 42 +- .../rest/server/BinaryHl7OrgDstu2Test.java | 24 +- .../BundleTypeInResponseHl7OrgTest.java | 12 +- .../server/CreateConditionalHl7OrgTest.java | 47 +- .../server/DeleteConditionalHl7OrgTest.java | 35 +- ...cludeAndRevincludeParameterHl7OrgTest.java | 40 +- .../rest/server/IncludeHl7OrgDstu2Test.java | 28 +- ...erationDuplicateServerHl7OrgDstu2Test.java | 19 +- .../server/OperationServerHl7OrgTest.java | 26 +- .../rest/server/PreferHl7OrgDstu2Test.java | 28 +- .../fhir/rest/server/ReadHl7OrgDstu2Test.java | 28 +- .../rest/server/SearchHl7OrgDstu2Test.java | 19 +- .../SearchWithGenericListHl7OrgDstu2Test.java | 18 +- .../SearchWithHl7OrgDstu2BundleTest.java | 26 +- ...verConformanceProviderHl7OrgDstu2Test.java | 59 +- ...ithBundleResourceParamHl7OrgDstu2Test.java | 40 +- .../UpdateConditionalHl7OrgDstu2Test.java | 47 +- .../rest/server/ValidateHl7OrgDstu2Test.java | 45 +- hapi-fhir-structures-r4/pom.xml | 12 +- .../BaseRuntimeElementDefinitionTest.java | 4 +- ...aultThymeleafNarrativeGeneratorR4Test.java | 63 +- .../ca/uhn/fhir/parser/CustomTypeR4Test.java | 57 +- .../parser/ElementWithExtensionR4Test.java | 15 +- .../ca/uhn/fhir/parser/JsonParserR4Test.java | 26 +- .../ca/uhn/fhir/parser/RDFParserR4Test.java | 24 +- .../ca/uhn/fhir/parser/RDFParserTest.java | 10 +- .../ca/uhn/fhir/parser/XmlParserR4Test.java | 8 +- .../parser/jsonlike/JsonLikeParserTest.java | 85 +- .../fhir/parser/view/ViewGeneratorTest.java | 8 +- .../rest/client/BaseGenericClientR4Test.java | 15 +- .../rest/client/BasicAuthInterceptorTest.java | 46 +- .../BearerTokenAuthInterceptorTest.java | 13 +- .../fhir/rest/client/BinaryClientTest.java | 11 +- .../rest/client/CapturingInterceptorTest.java | 32 +- .../fhir/rest/client/ClientHeadersR4Test.java | 23 +- .../rest/client/ClientIntegrationTest.java | 41 +- .../rest/client/ClientMimetypeR4Test.java | 58 +- .../ca/uhn/fhir/rest/client/ClientR4Test.java | 63 +- .../client/ClientWithCustomTypeR4Test.java | 42 +- ...ompressOutgoingContentInterceptorTest.java | 18 +- .../rest/client/ExceptionHandlingTest.java | 47 +- .../fhir/rest/client/GenericClientR4Test.java | 16 +- .../uhn/fhir/rest/client/HttpProxyTest.java | 38 +- .../IncludedResourceStitchingClientTest.java | 60 +- .../rest/client/LoggingInterceptorTest.java | 25 +- .../rest/client/NonGenericClientR4Test.java | 57 +- .../rest/client/OperationClientR4Test.java | 21 +- .../fhir/rest/client/PatchClientR4Test.java | 53 +- .../fhir/rest/client/ReferenceClientTest.java | 49 +- .../fhir/rest/client/SearchClientR4Test.java | 55 +- .../fhir/rest/client/SearchClientTest.java | 19 +- .../uhn/fhir/rest/client/SortClientTest.java | 47 +- .../fhir/rest/client/StringClientTest.java | 21 +- ...ThreadLocalCapturingInterceptorR4Test.java | 22 +- .../rest/client/TransactionClientTest.java | 60 +- .../AdditionalHeadersInterceptorTest.java | 14 +- .../UrlTenantSelectionInterceptorTest.java | 4 +- .../fhir/rest/param/DateRangeParamR4Test.java | 48 +- .../fhir/rest/server/BaseR4ServerTest.java | 4 +- .../fhir/rest/server/BinaryServerR4Test.java | 27 +- .../rest/server/BlockingContentR4Test.java | 17 +- .../ca/uhn/fhir/rest/server/CreateR4Test.java | 32 +- .../fhir/rest/server/CustomTypeServerR4.java | 51 +- .../rest/server/DeleteConditionalR4Test.java | 22 +- .../fhir/rest/server/ETagServerR4Test.java | 27 +- .../fhir/rest/server/ElementsParamR4Test.java | 18 +- .../fhir/rest/server/GraphQLR4RawTest.java | 27 +- .../uhn/fhir/rest/server/HistoryR4Test.java | 34 +- .../ca/uhn/fhir/rest/server/IncludeTest.java | 29 +- .../fhir/rest/server/LastNProviderTest.java | 4 +- .../fhir/rest/server/MultitenancyR4Test.java | 20 +- .../server/OperationGenericServer2R4Test.java | 26 +- .../server/OperationGenericServerR4Test.java | 27 +- .../rest/server/OperationServerR4Test.java | 26 +- .../server/PagingUsingNamedPagesR4Test.java | 22 +- .../fhir/rest/server/PlainProviderR4Test.java | 38 +- .../ca/uhn/fhir/rest/server/PreferTest.java | 18 +- .../SearchBundleProviderWithNoSizeR4Test.java | 47 +- .../rest/server/SearchHasParamR4Test.java | 39 +- .../rest/server/SearchMethodPriorityTest.java | 20 +- .../ca/uhn/fhir/rest/server/SearchR4Test.java | 34 +- .../rest/server/SearchSearchServerR4Test.java | 82 +- .../fhir/rest/server/SearchSortR4Test.java | 36 +- ...rverCapabilityStatementProviderR4Test.java | 46 +- .../server/ServerInvalidDefinitionR4Test.java | 10 +- .../server/ServerMethodSelectionR4Test.java | 5 +- .../rest/server/ServerMimetypeR4Test.java | 18 +- .../fhir/rest/server/SummaryParamR4Test.java | 18 +- .../exceptions/ExceptionPropertiesTest.java | 61 +- ...sourceSourceFromHeaderInterceptorTest.java | 26 +- .../interceptor/ConsentInterceptorTest.java | 30 +- .../ExceptionHandlingInterceptorTest.java | 50 +- .../ExceptionInterceptorMethodTest.java | 24 +- .../FhirPathFilterInterceptorTest.java | 46 +- .../interceptor/InjectionAttackTest.java | 16 +- .../InterceptorThrowingExceptionR4Test.java | 24 +- .../ResponseHighlightingInterceptorTest.java | 49 +- .../ResponseSizeCapturingInterceptorTest.java | 36 +- .../ServeMediaResourceRawInterceptorTest.java | 21 +- ...eHighlightingInterceptorExceptionTest.java | 16 +- .../auth/AuthorizationInterceptorR4Test.java | 79 +- .../auth/SearchNarrowingInterceptorTest.java | 30 +- .../method/CreateMethodBindingTest.java | 11 +- .../provider/HashMapResourceProviderTest.java | 26 +- .../ca/uhn/fhir/util/FhirTerserR4Test.java | 239 ++-- .../ca/uhn/fhir/util/GraphQLEngineTest.java | 8 +- .../fhir/util/OperationOutcomeUtilTest.java | 4 +- .../uhn/fhir/util/ParametersUtilR4Test.java | 12 +- .../ca/uhn/fhir/util/ResourceUtilTest.java | 6 +- .../uhn/fhir/util/TransactionBuilderTest.java | 8 +- .../java/ca/uhn/fhir/util/XmlUtilTest.java | 15 +- .../uhn/fhir/util/bundle/BundleUtilTest.java | 10 +- .../fhir/r4/elementmodel/PropertyTest.java | 22 +- .../fhir/r4/model/BackboneElementR4Test.java | 50 +- .../hl7/fhir/r4/model/CodesystemsR4Test.java | 16 +- .../fhir/r4/model/DomainResourceR4Test.java | 52 +- .../hl7/fhir/r4/model/HumanNameR4Test.java | 4 +- .../org/hl7/fhir/r4/model/IdTypeR4Test.java | 15 +- .../fhir/r4/model/MetadataResourceR4Test.java | 58 +- .../org/hl7/fhir/r4/model/ModelR4Test.java | 6 +- hapi-fhir-structures-r5/pom.xml | 12 +- .../fhir/rest/client/GenericClientTest.java | 52 +- .../ca/uhn/fhir/rest/server/SearchR5Test.java | 18 +- ...rverCapabilityStatementProviderR5Test.java | 20 +- .../org/hl7/fhir/r5/model/ModelR5Test.java | 6 +- hapi-fhir-test-utilities/pom.xml | 38 +- ...ientRule.java => HttpClientExtension.java} | 43 +- .../fhir/test/utilities/ITestDataBuilder.java | 8 +- ...LoggingRule.java => LoggingExtension.java} | 46 +- .../HashMapResourceProviderExtension.java | 54 + .../server/HashMapResourceProviderRule.java | 60 - ...le.java => ResourceProviderExtension.java} | 32 +- ...rRule.java => RestfulServerExtension.java} | 40 +- hapi-fhir-validation/pom.xml | 4 + .../ca/uhn/fhir/fhirpath/FluentPathTest.java | 9 +- ...RequestValidatingInterceptorDstu3Test.java | 28 +- .../RequestValidatingInterceptorR4Test.java | 20 +- ...esponseValidatingInterceptorDstu3Test.java | 162 +-- .../ResponseValidatingInterceptorR4Test.java | 90 +- .../ParserWithValidationDstu3Test.java | 35 +- .../validation/SchemaBaseValidatorTest.java | 8 +- .../ValidationSupportChainTest.java | 4 +- ...mmonCodeSystemsTerminologyServiceTest.java | 10 +- ...rminologyServiceValidationSupportTest.java | 33 +- .../FhirInstanceValidatorDstu2Test.java | 24 +- .../ResourceValidatorDstu2_1Test.java | 20 +- .../dstu3/elementmodel/PropertyDstu3Test.java | 26 +- .../DefaultProfileValidationSupportTest.java | 12 +- .../FhirInstanceValidatorDstu3Test.java | 99 +- ...estionnaireResponseValidatorDstu3Test.java | 30 +- .../QuestionnaireValidatorDstu3Test.java | 14 +- .../ResourceValidatorDstu3Test.java | 26 +- .../validation/SchemaValidationDstu3Test.java | 19 +- ...atronValidationDstu3QuestionnaireTest.java | 19 +- .../hapi/validation/StructureMapTest.java | 8 +- .../fhir/dstu3/utils/FhirPathEngineTest.java | 18 +- .../fhir/r4/utils/FhirPathEngineR4Test.java | 16 +- .../CustomResourceGenerationTest.java | 4 +- .../FhirInstanceValidatorR4Test.java | 90 +- .../r4/validation/HapiWorkerContextTest.java | 12 +- .../QuestionnaireResponseValidatorR4Test.java | 16 +- .../QuestionnaireValidatorR4Test.java | 14 +- .../r4/validation/SchemaValidationR4Test.java | 19 +- ...hematronValidationR4QuestionnaireTest.java | 24 +- .../validation/SnapshotGeneratorR4Test.java | 6 +- .../FhirInstanceValidatorR5Test.java | 68 +- .../QuestionnaireResponseValidatorR5Test.java | 16 +- hapi-tinder-test/pom.xml | 5 - .../src/test/java/test/TestAntTask.java | 2 +- .../src/test/java/test/TestParticulars.java | 2 +- .../karaf/client/FhirClientTest.java | 8 +- .../Dstu2ResourceValidatorDstu2Test.java | 14 +- .../karaf/dstu21/JsonParserDstu2_1Test.java | 20 +- .../karaf/dstu21/XmlParserDstu2_1Test.java | 26 +- .../FhirInstanceValidatorTest.java | 8 +- .../JsonParserHl7OrgDstu2Test.java | 24 +- .../dstu2hl7org/XmlParserHl7OrgDstu2Test.java | 22 +- .../karaf/dstu3/Dstu3JsonParserTest.java | 22 +- .../karaf/dstu3/Dstu3XmlParserTest.java | 26 +- .../ResourceValidatorDstu3FeatureTest.java | 6 +- .../karaf/r4/FhirInstanceValidatorR4Test.java | 10 +- .../karaf/r4/R4JsonParserTest.java | 10 +- .../integration/karaf/r4/R4XmlParserTest.java | 10 +- pom.xml | 83 +- .../ExtendedOrganizationResourceTest.kt | 12 +- .../ca/uhn/fhir/rest/client/ClientTest.java | 4 +- .../parser/MultiVersionJsonParserTest.java | 6 +- .../parser/MultiVersionXmlParserTest.java | 40 +- .../uhn/fhir/testmindeps/FhirContextTest.java | 4 +- .../ca/uhn/fhir/testmindeps/ReadTest.java | 10 +- .../ca/uhn/fhir/testmindeps/SetupTest.java | 2 +- .../uhn/fhir/testmindeps/ValidatorTest.java | 10 +- 967 files changed, 16872 insertions(+), 15895 deletions(-) create mode 100644 hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/5_1_0/1952-migrate-to-junit5.yaml rename hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/patch/{BaseFhirPatchCoreTest.java => FhirPatchCoreTest.java} (64%) delete mode 100644 hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/patch/FhirPatchR4CoreTest.java delete mode 100644 hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/patch/FhirPatchR5CoreTest.java rename hapi-fhir-test-utilities/src/main/java/ca/uhn/fhir/test/utilities/{HttpClientRule.java => HttpClientExtension.java} (68%) rename hapi-fhir-test-utilities/src/main/java/ca/uhn/fhir/test/utilities/{LoggingRule.java => LoggingExtension.java} (52%) create mode 100644 hapi-fhir-test-utilities/src/main/java/ca/uhn/fhir/test/utilities/server/HashMapResourceProviderExtension.java delete mode 100644 hapi-fhir-test-utilities/src/main/java/ca/uhn/fhir/test/utilities/server/HashMapResourceProviderRule.java rename hapi-fhir-test-utilities/src/main/java/ca/uhn/fhir/test/utilities/server/{ResourceProviderRule.java => ResourceProviderExtension.java} (52%) rename hapi-fhir-test-utilities/src/main/java/ca/uhn/fhir/test/utilities/server/{RestfulServerRule.java => RestfulServerExtension.java} (85%) diff --git a/example-projects/README.md b/example-projects/README.md index 5ef27babc43..200f41802db 100644 --- a/example-projects/README.md +++ b/example-projects/README.md @@ -2,7 +2,7 @@ Most of the projects in this module are no longer supported. -The test in hapi-fhir-jpaserver-cds-example is @Ignored until Chris Schuler is able to make a change to the pom +The test in hapi-fhir-jpaserver-cds-example is @Disabledd until Chris Schuler is able to make a change to the pom this module depends on. ## Supported JPA Example: diff --git a/example-projects/hapi-fhir-jpaserver-cds-example/src/test/java/ca/uhn/fhir/jpa/cds/example/CdsExampleTests.java b/example-projects/hapi-fhir-jpaserver-cds-example/src/test/java/ca/uhn/fhir/jpa/cds/example/CdsExampleTests.java index 6ff16f29bad..a1076c6d815 100644 --- a/example-projects/hapi-fhir-jpaserver-cds-example/src/test/java/ca/uhn/fhir/jpa/cds/example/CdsExampleTests.java +++ b/example-projects/hapi-fhir-jpaserver-cds-example/src/test/java/ca/uhn/fhir/jpa/cds/example/CdsExampleTests.java @@ -11,7 +11,7 @@ import org.eclipse.jetty.server.Server; import org.eclipse.jetty.webapp.WebAppContext; import org.hl7.fhir.dstu3.model.*; import org.hl7.fhir.instance.model.api.IBaseResource; -import org.junit.*; +import org.junit.jupiter.api.*; import static org.hamcrest.MatcherAssert.assertThat; import java.io.*; import java.net.HttpURLConnection; @@ -21,8 +21,8 @@ import java.util.Collection; import java.util.List; import java.util.Scanner; -// TODO Remove @Ignore once Chris Schuler has fixed the external jar this project depends on -@Ignore +// TODO Remove @Disabled once Chris Schuler has fixed the external jar this project depends on +@Disabled public class CdsExampleTests { private static IGenericClient ourClient; private static FhirContext ourCtx = FhirContext.forDstu3(); @@ -34,7 +34,7 @@ public class CdsExampleTests { private static Collection providers; - @BeforeClass + @BeforeAll public static void beforeClass() throws Exception { // Configure and spin up server @@ -67,7 +67,7 @@ public class CdsExampleTests { putResource("general-fhirhelpers-3.json", "FHIRHelpers"); } - @AfterClass + @AfterAll public static void afterClass() throws Exception { JettyUtil.closeServer(ourServer); } diff --git a/example-projects/hapi-fhir-jpaserver-dynamic/src/test/java/ca/uhn/fhir/jpa/demo/ExampleServerIT.java b/example-projects/hapi-fhir-jpaserver-dynamic/src/test/java/ca/uhn/fhir/jpa/demo/ExampleServerIT.java index b5efb4e4875..99e4e00589d 100644 --- a/example-projects/hapi-fhir-jpaserver-dynamic/src/test/java/ca/uhn/fhir/jpa/demo/ExampleServerIT.java +++ b/example-projects/hapi-fhir-jpaserver-dynamic/src/test/java/ca/uhn/fhir/jpa/demo/ExampleServerIT.java @@ -1,6 +1,6 @@ package ca.uhn.fhir.jpa.demo; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.io.File; import java.io.IOException; @@ -10,10 +10,10 @@ import java.util.List; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.webapp.WebAppContext; import org.hl7.fhir.instance.model.api.IIdType; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEachClass; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.dstu2.resource.Patient; @@ -35,7 +35,7 @@ public class ExampleServerIT { private static String ourServerBase; @Test - @Ignore + @Disabled public void testCreateAndRead() throws IOException { ourLog.info("Base URL is: http://localhost:" + ourPort + "/baseDstu2"); String methodName = "testCreateResourceConditional"; @@ -50,12 +50,12 @@ public class ExampleServerIT { assertEquals(famNames, pt2.getName().get(0).getFamily()); } - @AfterClass + @AfterAll public static void afterClass() throws Exception { JettyUtil.closeServer(ourServer); } - @BeforeClass + @BeforeAll public static void beforeClass() throws Exception { /* * This runs under maven, and I'm not sure how else to figure out the target directory from code.. diff --git a/hapi-fhir-android/src/test/java/ca/uhn/fhir/android/BuiltJarDstu2IT.java b/hapi-fhir-android/src/test/java/ca/uhn/fhir/android/BuiltJarDstu2IT.java index a038a2d56de..626b1066a55 100644 --- a/hapi-fhir-android/src/test/java/ca/uhn/fhir/android/BuiltJarDstu2IT.java +++ b/hapi-fhir-android/src/test/java/ca/uhn/fhir/android/BuiltJarDstu2IT.java @@ -1,7 +1,7 @@ package ca.uhn.fhir.android; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; import java.io.File; import java.util.*; @@ -10,8 +10,9 @@ import java.util.zip.ZipFile; import org.apache.commons.io.FileUtils; import org.apache.commons.io.filefilter.WildcardFileFilter; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.dstu2.composite.QuantityDt; @@ -22,7 +23,7 @@ import ca.uhn.fhir.rest.client.exceptions.FhirClientConnectionException; public class BuiltJarDstu2IT { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(BuiltJarDstu2IT.class); - @BeforeClass + @BeforeAll public static void beforeClass() { System.setProperty("javax.xml.stream.XMLInputFactory", "FOO"); System.setProperty("javax.xml.stream.XMLOutputFactory", "FOO"); diff --git a/hapi-fhir-android/src/test/java/ca/uhn/fhir/android/BuiltJarDstu2ShadeIT.java b/hapi-fhir-android/src/test/java/ca/uhn/fhir/android/BuiltJarDstu2ShadeIT.java index cd10815159a..d36d8d78e9e 100644 --- a/hapi-fhir-android/src/test/java/ca/uhn/fhir/android/BuiltJarDstu2ShadeIT.java +++ b/hapi-fhir-android/src/test/java/ca/uhn/fhir/android/BuiltJarDstu2ShadeIT.java @@ -1,6 +1,6 @@ package ca.uhn.fhir.android; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.io.File; import java.util.*; @@ -9,8 +9,8 @@ import java.util.zip.ZipFile; import org.apache.commons.io.FileUtils; import org.apache.commons.io.filefilter.WildcardFileFilter; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.dstu2.composite.QuantityDt; @@ -22,7 +22,7 @@ public class BuiltJarDstu2ShadeIT { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(BuiltJarDstu2ShadeIT.class); @Test - @Ignore + @Disabled public void testParserXml() throws Exception { FhirContext ctx = FhirContext.forDstu2(); diff --git a/hapi-fhir-android/src/test/java/ca/uhn/fhir/android/client/GenericClientDstu3IT.java b/hapi-fhir-android/src/test/java/ca/uhn/fhir/android/client/GenericClientDstu3IT.java index b61df6acb0a..1c5cb01529f 100644 --- a/hapi-fhir-android/src/test/java/ca/uhn/fhir/android/client/GenericClientDstu3IT.java +++ b/hapi-fhir-android/src/test/java/ca/uhn/fhir/android/client/GenericClientDstu3IT.java @@ -1,6 +1,6 @@ package ca.uhn.fhir.android.client; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -10,7 +10,7 @@ import java.util.Date; import ca.uhn.fhir.rest.api.PreferReturnEnum; import org.hl7.fhir.dstu3.model.*; -import org.junit.*; +import org.junit.jupiter.api.*; import static org.hamcrest.MatcherAssert.assertThat; import org.mockito.ArgumentCaptor; import org.mockito.Mockito; import org.mockito.invocation.InvocationOnMock; @@ -41,7 +41,7 @@ public class GenericClientDstu3IT { private Request myRequest; private Protocol myProtocol; - @Before + @BeforeEach public void before() throws IOException { myHttpClient = mock(Call.Factory.class, Mockito.RETURNS_DEEP_STUBS); ourCtx.getRestfulClientFactory().setHttpClient(myHttpClient); @@ -82,7 +82,7 @@ public class GenericClientDstu3IT { * TODO: narratives don't work without stax */ @Test - @Ignore + @Disabled public void testBinaryCreateWithFhirContentType() throws Exception { IParser p = ourCtx.newXmlParser(); @@ -733,7 +733,7 @@ public class GenericClientDstu3IT { //TODO: narratives don't work without stax @Test - @Ignore + @Disabled public void testUpdateById() throws Exception { IParser p = ourCtx.newJsonParser(); @@ -773,7 +773,7 @@ public class GenericClientDstu3IT { // TODO: narratives don't work without stax @Test - @Ignore + @Disabled public void testUpdateWithPreferRepresentationServerReturnsOO() throws Exception { final IParser p = ourCtx.newJsonParser(); @@ -897,7 +897,7 @@ public class GenericClientDstu3IT { // TODO: narratives don't work without stax @Test - @Ignore + @Disabled public void testValidate() throws Exception { final IParser p = ourCtx.newXmlParser(); @@ -938,12 +938,12 @@ public class GenericClientDstu3IT { */ - @AfterClass + @AfterAll public static void afterClassClearContext() { TestUtil.clearAllStaticFieldsForUnitTest(); } - @BeforeClass + @BeforeAll public static void beforeClass() { // // Force StAX to fail like it will on android diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/FhirContext.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/FhirContext.java index a0523e8fec5..ba9d2d1d41c 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/FhirContext.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/context/FhirContext.java @@ -41,6 +41,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; +import java.util.EnumMap; import java.util.Enumeration; import java.util.HashMap; import java.util.HashSet; @@ -94,6 +95,7 @@ import java.util.Set; public class FhirContext { private static final List> EMPTY_LIST = Collections.emptyList(); + private static final Map ourStaticContexts = Collections.synchronizedMap(new EnumMap<>(FhirVersionEnum.class)); private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirContext.class); private final IFhirVersion myVersion; private AddProfileTagEnum myAddProfileTagWhenEncoding = AddProfileTagEnum.ONLY_FOR_CUSTOM; @@ -465,6 +467,7 @@ public class FhirContext { /** * Returns the name of a given resource class. + * * @param theResourceType * @return */ @@ -1034,6 +1037,17 @@ public class FhirContext { return new FhirContext(FhirVersionEnum.R5); } + /** + * Returns a statically cached {@literal FhirContext} instance for the given version, creating one if none exists in the + * cache. One FhirContext will be kept in the cache for each FHIR version that is requested (by calling + * this method for that version), and the cache will never be expired. + * + * @since 5.1.0 + */ + public static FhirContext forCached(FhirVersionEnum theFhirVersionEnum) { + return ourStaticContexts.computeIfAbsent(theFhirVersionEnum, v -> new FhirContext(v)); + } + private static Collection> toCollection(Class theResourceType) { ArrayList> retVal = new ArrayList<>(1); retVal.add(theResourceType); diff --git a/hapi-fhir-base/src/test/java/ca/uhn/fhir/context/FhirVersionEnumTest.java b/hapi-fhir-base/src/test/java/ca/uhn/fhir/context/FhirVersionEnumTest.java index 63051dfc65f..8b3926f9f44 100644 --- a/hapi-fhir-base/src/test/java/ca/uhn/fhir/context/FhirVersionEnumTest.java +++ b/hapi-fhir-base/src/test/java/ca/uhn/fhir/context/FhirVersionEnumTest.java @@ -1,8 +1,8 @@ package ca.uhn.fhir.context; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertEquals; public class FhirVersionEnumTest { diff --git a/hapi-fhir-base/src/test/java/ca/uhn/fhir/i18n/HapiLocalizerTest.java b/hapi-fhir-base/src/test/java/ca/uhn/fhir/i18n/HapiLocalizerTest.java index 3105b50c46f..29857f00522 100644 --- a/hapi-fhir-base/src/test/java/ca/uhn/fhir/i18n/HapiLocalizerTest.java +++ b/hapi-fhir-base/src/test/java/ca/uhn/fhir/i18n/HapiLocalizerTest.java @@ -1,12 +1,12 @@ package ca.uhn.fhir.i18n; import static org.hamcrest.Matchers.*; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.hamcrest.MatcherAssert.assertThat; import java.util.Set; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class HapiLocalizerTest { diff --git a/hapi-fhir-base/src/test/java/ca/uhn/fhir/interceptor/executor/InterceptorServiceTest.java b/hapi-fhir-base/src/test/java/ca/uhn/fhir/interceptor/executor/InterceptorServiceTest.java index 8ce9fc6b901..86725be977f 100644 --- a/hapi-fhir-base/src/test/java/ca/uhn/fhir/interceptor/executor/InterceptorServiceTest.java +++ b/hapi-fhir-base/src/test/java/ca/uhn/fhir/interceptor/executor/InterceptorServiceTest.java @@ -9,9 +9,9 @@ import ca.uhn.fhir.rest.server.exceptions.BaseServerResponseException; import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import ca.uhn.fhir.util.StopWatch; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -19,8 +19,15 @@ import java.util.ArrayList; import java.util.List; import static org.hamcrest.CoreMatchers.containsString; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.contains; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; + +//import org.junit.jupiter.api.Disabled; public class InterceptorServiceTest { @@ -121,17 +128,17 @@ public class InterceptorServiceTest { svc.registerInterceptor(myInterceptorManual); List globalInterceptors = svc.getGlobalInterceptorsForUnitTest(); assertEquals(3, globalInterceptors.size()); - assertTrue(globalInterceptors.get(0).getClass().toString(), globalInterceptors.get(0) instanceof MyTestInterceptorOne); - assertTrue(globalInterceptors.get(1).getClass().toString(), globalInterceptors.get(1) instanceof MyTestInterceptorManual); - assertTrue(globalInterceptors.get(2).getClass().toString(), globalInterceptors.get(2) instanceof MyTestInterceptorTwo); + assertTrue(globalInterceptors.get(0) instanceof MyTestInterceptorOne, globalInterceptors.get(0).getClass().toString()); + assertTrue(globalInterceptors.get(1) instanceof MyTestInterceptorManual, globalInterceptors.get(1).getClass().toString()); + assertTrue(globalInterceptors.get(2) instanceof MyTestInterceptorTwo, globalInterceptors.get(2).getClass().toString()); // Try to register again (should have no effect svc.registerInterceptor(myInterceptorManual); globalInterceptors = svc.getGlobalInterceptorsForUnitTest(); assertEquals(3, globalInterceptors.size()); - assertTrue(globalInterceptors.get(0).getClass().toString(), globalInterceptors.get(0) instanceof MyTestInterceptorOne); - assertTrue(globalInterceptors.get(1).getClass().toString(), globalInterceptors.get(1) instanceof MyTestInterceptorManual); - assertTrue(globalInterceptors.get(2).getClass().toString(), globalInterceptors.get(2) instanceof MyTestInterceptorTwo); + assertTrue(globalInterceptors.get(0) instanceof MyTestInterceptorOne, globalInterceptors.get(0).getClass().toString()); + assertTrue(globalInterceptors.get(1) instanceof MyTestInterceptorManual, globalInterceptors.get(1).getClass().toString()); + assertTrue(globalInterceptors.get(2) instanceof MyTestInterceptorTwo, globalInterceptors.get(2).getClass().toString()); // Make sure we have the right invokers in the right order List invokers = svc.getInterceptorsWithInvokersForPointcut(Pointcut.TEST_RB); @@ -143,8 +150,8 @@ public class InterceptorServiceTest { svc.unregisterInterceptor(myInterceptorManual); globalInterceptors = svc.getGlobalInterceptorsForUnitTest(); assertEquals(2, globalInterceptors.size()); - assertTrue(globalInterceptors.get(0).getClass().toString(), globalInterceptors.get(0) instanceof MyTestInterceptorOne); - assertTrue(globalInterceptors.get(1).getClass().toString(), globalInterceptors.get(1) instanceof MyTestInterceptorTwo); + assertTrue(globalInterceptors.get(0) instanceof MyTestInterceptorOne, globalInterceptors.get(0).getClass().toString()); + assertTrue(globalInterceptors.get(1) instanceof MyTestInterceptorTwo, globalInterceptors.get(1).getClass().toString()); } @@ -449,7 +456,7 @@ public class InterceptorServiceTest { * */ @Test - @Ignore("Performance test - Not needed normally") + @Disabled("Performance test - Not needed normally") public void testThreadLocalHookInterceptorMicroBenchmark() { threadLocalMicroBenchmark(true, 500000); threadLocalMicroBenchmark(false, 500000); @@ -497,7 +504,7 @@ public class InterceptorServiceTest { ourLog.info("ThreadLocalEnabled={} - Performed {} loops in {} - {} / loop - Outcomne: {}", theThreadlocalInvokersEnabled, theCount, sw.toString(), sw.formatMillisPerOperation(theCount), interceptor.myCount); } - @Before + @BeforeEach public void before() { myInvocations.clear(); } diff --git a/hapi-fhir-base/src/test/java/ca/uhn/fhir/interceptor/model/RequestPartitionIdTest.java b/hapi-fhir-base/src/test/java/ca/uhn/fhir/interceptor/model/RequestPartitionIdTest.java index 6045284ffe1..28de3972f80 100644 --- a/hapi-fhir-base/src/test/java/ca/uhn/fhir/interceptor/model/RequestPartitionIdTest.java +++ b/hapi-fhir-base/src/test/java/ca/uhn/fhir/interceptor/model/RequestPartitionIdTest.java @@ -1,11 +1,11 @@ package ca.uhn.fhir.interceptor.model; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.time.LocalDate; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; public class RequestPartitionIdTest { diff --git a/hapi-fhir-base/src/test/java/ca/uhn/fhir/model/api/ResourceMetadataKeyEnumTest.java b/hapi-fhir-base/src/test/java/ca/uhn/fhir/model/api/ResourceMetadataKeyEnumTest.java index c491081ffc0..b0ec6d38352 100644 --- a/hapi-fhir-base/src/test/java/ca/uhn/fhir/model/api/ResourceMetadataKeyEnumTest.java +++ b/hapi-fhir-base/src/test/java/ca/uhn/fhir/model/api/ResourceMetadataKeyEnumTest.java @@ -1,8 +1,8 @@ package ca.uhn.fhir.model.api; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; public class ResourceMetadataKeyEnumTest { diff --git a/hapi-fhir-base/src/test/java/ca/uhn/fhir/model/api/TagTest.java b/hapi-fhir-base/src/test/java/ca/uhn/fhir/model/api/TagTest.java index 403c96dfe74..ee4dd75e307 100644 --- a/hapi-fhir-base/src/test/java/ca/uhn/fhir/model/api/TagTest.java +++ b/hapi-fhir-base/src/test/java/ca/uhn/fhir/model/api/TagTest.java @@ -1,11 +1,11 @@ package ca.uhn.fhir.model.api; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.net.URI; import java.net.URISyntaxException; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; public class TagTest { diff --git a/hapi-fhir-base/src/test/java/ca/uhn/fhir/parser/json/JsonLikeStructureTest.java b/hapi-fhir-base/src/test/java/ca/uhn/fhir/parser/json/JsonLikeStructureTest.java index 3b71f8a8840..ce9a9f8cd36 100644 --- a/hapi-fhir-base/src/test/java/ca/uhn/fhir/parser/json/JsonLikeStructureTest.java +++ b/hapi-fhir-base/src/test/java/ca/uhn/fhir/parser/json/JsonLikeStructureTest.java @@ -1,12 +1,12 @@ package ca.uhn.fhir.parser.json; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; import java.io.StringReader; import ca.uhn.fhir.parser.json.jackson.JacksonStructure; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class JsonLikeStructureTest { // private static FhirContext ourCtx; @@ -141,4 +141,4 @@ public class JsonLikeStructureTest { assertEquals(value.getAsString(), "true"); } -} \ No newline at end of file +} diff --git a/hapi-fhir-base/src/test/java/ca/uhn/fhir/rest/api/CacheControlDirectiveTest.java b/hapi-fhir-base/src/test/java/ca/uhn/fhir/rest/api/CacheControlDirectiveTest.java index 4591b4bc1f1..744e03b17bd 100644 --- a/hapi-fhir-base/src/test/java/ca/uhn/fhir/rest/api/CacheControlDirectiveTest.java +++ b/hapi-fhir-base/src/test/java/ca/uhn/fhir/rest/api/CacheControlDirectiveTest.java @@ -1,11 +1,11 @@ package ca.uhn.fhir.rest.api; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.Arrays; import java.util.List; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; public class CacheControlDirectiveTest { diff --git a/hapi-fhir-base/src/test/java/ca/uhn/fhir/rest/api/ConstantsTest.java b/hapi-fhir-base/src/test/java/ca/uhn/fhir/rest/api/ConstantsTest.java index be1bcef1e68..8fb91f21dc9 100644 --- a/hapi-fhir-base/src/test/java/ca/uhn/fhir/rest/api/ConstantsTest.java +++ b/hapi-fhir-base/src/test/java/ca/uhn/fhir/rest/api/ConstantsTest.java @@ -1,6 +1,6 @@ package ca.uhn.fhir.rest.api; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class ConstantsTest { diff --git a/hapi-fhir-base/src/test/java/ca/uhn/fhir/rest/api/EncodingEnumTest.java b/hapi-fhir-base/src/test/java/ca/uhn/fhir/rest/api/EncodingEnumTest.java index 69b2e46164a..b510b658f69 100644 --- a/hapi-fhir-base/src/test/java/ca/uhn/fhir/rest/api/EncodingEnumTest.java +++ b/hapi-fhir-base/src/test/java/ca/uhn/fhir/rest/api/EncodingEnumTest.java @@ -1,8 +1,8 @@ package ca.uhn.fhir.rest.api; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; public class EncodingEnumTest { diff --git a/hapi-fhir-base/src/test/java/ca/uhn/fhir/rest/api/QualifiedParamListTest.java b/hapi-fhir-base/src/test/java/ca/uhn/fhir/rest/api/QualifiedParamListTest.java index ebb972c6290..a0018aead2d 100644 --- a/hapi-fhir-base/src/test/java/ca/uhn/fhir/rest/api/QualifiedParamListTest.java +++ b/hapi-fhir-base/src/test/java/ca/uhn/fhir/rest/api/QualifiedParamListTest.java @@ -1,14 +1,12 @@ package ca.uhn.fhir.rest.api; -import static org.junit.Assert.assertEquals; +import ca.uhn.fhir.util.TestUtil; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; import java.util.List; -import org.junit.AfterClass; -import org.junit.Test; - -import ca.uhn.fhir.rest.api.QualifiedParamList; -import ca.uhn.fhir.util.TestUtil; +import static org.junit.jupiter.api.Assertions.assertEquals; public class QualifiedParamListTest { @@ -37,7 +35,7 @@ public class QualifiedParamListTest { } - @AfterClass + @AfterAll public static void afterClassClearContext() { TestUtil.clearAllStaticFieldsForUnitTest(); } diff --git a/hapi-fhir-base/src/test/java/ca/uhn/fhir/rest/param/DateRangeParamTest.java b/hapi-fhir-base/src/test/java/ca/uhn/fhir/rest/param/DateRangeParamTest.java index eb79adb23bf..2c590d415db 100644 --- a/hapi-fhir-base/src/test/java/ca/uhn/fhir/rest/param/DateRangeParamTest.java +++ b/hapi-fhir-base/src/test/java/ca/uhn/fhir/rest/param/DateRangeParamTest.java @@ -2,22 +2,19 @@ package ca.uhn.fhir.rest.param; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.rest.api.QualifiedParamList; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import java.util.ArrayList; import java.util.List; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; -@RunWith(JUnit4.class) public class DateRangeParamTest { private FhirContext fhirContext; - @Before + @BeforeEach public void initMockContext() { fhirContext = Mockito.mock(FhirContext.class); } diff --git a/hapi-fhir-base/src/test/java/ca/uhn/fhir/rest/param/QualifierDetailsTest.java b/hapi-fhir-base/src/test/java/ca/uhn/fhir/rest/param/QualifierDetailsTest.java index d63b545b74e..33eb930e129 100644 --- a/hapi-fhir-base/src/test/java/ca/uhn/fhir/rest/param/QualifierDetailsTest.java +++ b/hapi-fhir-base/src/test/java/ca/uhn/fhir/rest/param/QualifierDetailsTest.java @@ -1,9 +1,9 @@ package ca.uhn.fhir.rest.param; import com.google.common.collect.Sets; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; public class QualifierDetailsTest { diff --git a/hapi-fhir-base/src/test/java/ca/uhn/fhir/rest/param/StringParamTest.java b/hapi-fhir-base/src/test/java/ca/uhn/fhir/rest/param/StringParamTest.java index f19fa54bf58..4bbce1afa1f 100644 --- a/hapi-fhir-base/src/test/java/ca/uhn/fhir/rest/param/StringParamTest.java +++ b/hapi-fhir-base/src/test/java/ca/uhn/fhir/rest/param/StringParamTest.java @@ -1,8 +1,8 @@ package ca.uhn.fhir.rest.param; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class StringParamTest { diff --git a/hapi-fhir-base/src/test/java/ca/uhn/fhir/rest/param/TokenParamTest.java b/hapi-fhir-base/src/test/java/ca/uhn/fhir/rest/param/TokenParamTest.java index db934b0d89c..f0781b316b5 100644 --- a/hapi-fhir-base/src/test/java/ca/uhn/fhir/rest/param/TokenParamTest.java +++ b/hapi-fhir-base/src/test/java/ca/uhn/fhir/rest/param/TokenParamTest.java @@ -1,8 +1,8 @@ package ca.uhn.fhir.rest.param; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; public class TokenParamTest { @Test diff --git a/hapi-fhir-base/src/test/java/ca/uhn/fhir/rest/server/exceptions/BaseServerResponseExceptionTest.java b/hapi-fhir-base/src/test/java/ca/uhn/fhir/rest/server/exceptions/BaseServerResponseExceptionTest.java index 4894cd77383..78d38818858 100644 --- a/hapi-fhir-base/src/test/java/ca/uhn/fhir/rest/server/exceptions/BaseServerResponseExceptionTest.java +++ b/hapi-fhir-base/src/test/java/ca/uhn/fhir/rest/server/exceptions/BaseServerResponseExceptionTest.java @@ -1,8 +1,8 @@ package ca.uhn.fhir.rest.server.exceptions; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; public class BaseServerResponseExceptionTest { diff --git a/hapi-fhir-base/src/test/java/ca/uhn/fhir/util/AsyncUtilTest.java b/hapi-fhir-base/src/test/java/ca/uhn/fhir/util/AsyncUtilTest.java index 7cbb8022c25..21341963775 100644 --- a/hapi-fhir-base/src/test/java/ca/uhn/fhir/util/AsyncUtilTest.java +++ b/hapi-fhir-base/src/test/java/ca/uhn/fhir/util/AsyncUtilTest.java @@ -1,7 +1,7 @@ package ca.uhn.fhir.util; import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; diff --git a/hapi-fhir-base/src/test/java/ca/uhn/fhir/util/ClasspathUtilTest.java b/hapi-fhir-base/src/test/java/ca/uhn/fhir/util/ClasspathUtilTest.java index c70687c910d..8c63dffdbf5 100644 --- a/hapi-fhir-base/src/test/java/ca/uhn/fhir/util/ClasspathUtilTest.java +++ b/hapi-fhir-base/src/test/java/ca/uhn/fhir/util/ClasspathUtilTest.java @@ -1,13 +1,13 @@ package ca.uhn.fhir.util; import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; diff --git a/hapi-fhir-base/src/test/java/ca/uhn/fhir/util/DependencyLogUtilTest.java b/hapi-fhir-base/src/test/java/ca/uhn/fhir/util/DependencyLogUtilTest.java index 36bf76d64ca..970acc0f54d 100644 --- a/hapi-fhir-base/src/test/java/ca/uhn/fhir/util/DependencyLogUtilTest.java +++ b/hapi-fhir-base/src/test/java/ca/uhn/fhir/util/DependencyLogUtilTest.java @@ -1,11 +1,10 @@ package ca.uhn.fhir.util; -import static org.junit.Assert.*; - -import org.junit.Test; - import ca.uhn.fhir.util.jar.DependencyLogFactory; import ca.uhn.fhir.util.jar.IDependencyLog; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertNotNull; public class DependencyLogUtilTest { diff --git a/hapi-fhir-base/src/test/java/ca/uhn/fhir/util/FileUtilTest.java b/hapi-fhir-base/src/test/java/ca/uhn/fhir/util/FileUtilTest.java index 6bd3d4b2ccc..24c4c0ece80 100644 --- a/hapi-fhir-base/src/test/java/ca/uhn/fhir/util/FileUtilTest.java +++ b/hapi-fhir-base/src/test/java/ca/uhn/fhir/util/FileUtilTest.java @@ -1,8 +1,8 @@ package ca.uhn.fhir.util; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertEquals; public class FileUtilTest { diff --git a/hapi-fhir-base/src/test/java/ca/uhn/fhir/util/LogUtilTest.java b/hapi-fhir-base/src/test/java/ca/uhn/fhir/util/LogUtilTest.java index 755d09d9010..1f8fa0c6578 100644 --- a/hapi-fhir-base/src/test/java/ca/uhn/fhir/util/LogUtilTest.java +++ b/hapi-fhir-base/src/test/java/ca/uhn/fhir/util/LogUtilTest.java @@ -1,6 +1,6 @@ package ca.uhn.fhir.util; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.event.Level; diff --git a/hapi-fhir-base/src/test/java/ca/uhn/fhir/util/ObjectUtilTest.java b/hapi-fhir-base/src/test/java/ca/uhn/fhir/util/ObjectUtilTest.java index 80a8d43db49..b6b9ff4c056 100644 --- a/hapi-fhir-base/src/test/java/ca/uhn/fhir/util/ObjectUtilTest.java +++ b/hapi-fhir-base/src/test/java/ca/uhn/fhir/util/ObjectUtilTest.java @@ -1,8 +1,8 @@ package ca.uhn.fhir.util; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class ObjectUtilTest { diff --git a/hapi-fhir-base/src/test/java/ca/uhn/fhir/util/ReflectionUtilTest.java b/hapi-fhir-base/src/test/java/ca/uhn/fhir/util/ReflectionUtilTest.java index 3239dcc9420..0b3060b950e 100644 --- a/hapi-fhir-base/src/test/java/ca/uhn/fhir/util/ReflectionUtilTest.java +++ b/hapi-fhir-base/src/test/java/ca/uhn/fhir/util/ReflectionUtilTest.java @@ -1,12 +1,12 @@ package ca.uhn.fhir.util; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.List; -import org.junit.Test; +import org.junit.jupiter.api.Test; import ca.uhn.fhir.context.ConfigurationException; diff --git a/hapi-fhir-base/src/test/java/ca/uhn/fhir/util/StopWatchTest.java b/hapi-fhir-base/src/test/java/ca/uhn/fhir/util/StopWatchTest.java index dc79e0cdb66..00face3e48b 100644 --- a/hapi-fhir-base/src/test/java/ca/uhn/fhir/util/StopWatchTest.java +++ b/hapi-fhir-base/src/test/java/ca/uhn/fhir/util/StopWatchTest.java @@ -2,21 +2,21 @@ package ca.uhn.fhir.util; import org.apache.commons.lang3.time.DateUtils; import org.hamcrest.Matchers; -import org.junit.After; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; import java.util.Date; import java.util.concurrent.TimeUnit; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.*; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; public class StopWatchTest { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(StopWatchTest.class); - @After + @AfterEach public void after() { StopWatch.setNowForUnitTestForUnitTest(null); } diff --git a/hapi-fhir-base/src/test/java/ca/uhn/fhir/util/UrlUtilTest.java b/hapi-fhir-base/src/test/java/ca/uhn/fhir/util/UrlUtilTest.java index 89757352175..3601f6bc40c 100644 --- a/hapi-fhir-base/src/test/java/ca/uhn/fhir/util/UrlUtilTest.java +++ b/hapi-fhir-base/src/test/java/ca/uhn/fhir/util/UrlUtilTest.java @@ -1,8 +1,8 @@ package ca.uhn.fhir.util; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; public class UrlUtilTest { diff --git a/hapi-fhir-base/src/test/java/ca/uhn/fhir/util/ValidateUtilTest.java b/hapi-fhir-base/src/test/java/ca/uhn/fhir/util/ValidateUtilTest.java index 1997de20000..f42c889adea 100644 --- a/hapi-fhir-base/src/test/java/ca/uhn/fhir/util/ValidateUtilTest.java +++ b/hapi-fhir-base/src/test/java/ca/uhn/fhir/util/ValidateUtilTest.java @@ -1,10 +1,10 @@ package ca.uhn.fhir.util; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; -import org.junit.Test; +import org.junit.jupiter.api.Test; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; diff --git a/hapi-fhir-base/src/test/java/ca/uhn/fhir/util/VersionEnumTest.java b/hapi-fhir-base/src/test/java/ca/uhn/fhir/util/VersionEnumTest.java index e7be7d7be79..a67def4473b 100644 --- a/hapi-fhir-base/src/test/java/ca/uhn/fhir/util/VersionEnumTest.java +++ b/hapi-fhir-base/src/test/java/ca/uhn/fhir/util/VersionEnumTest.java @@ -1,13 +1,13 @@ package ca.uhn.fhir.util; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; import static org.hamcrest.CoreMatchers.hasItem; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; public class VersionEnumTest { diff --git a/hapi-fhir-base/src/test/java/ca/uhn/fhir/util/VersionUtilTest.java b/hapi-fhir-base/src/test/java/ca/uhn/fhir/util/VersionUtilTest.java index c66151b6d3e..a40eca8fd87 100644 --- a/hapi-fhir-base/src/test/java/ca/uhn/fhir/util/VersionUtilTest.java +++ b/hapi-fhir-base/src/test/java/ca/uhn/fhir/util/VersionUtilTest.java @@ -1,10 +1,10 @@ package ca.uhn.fhir.util; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.hamcrest.CoreMatchers.not; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.blankOrNullString; -import static org.junit.Assert.*; public class VersionUtilTest { diff --git a/hapi-fhir-base/src/test/java/ca/uhn/fhir/validation/PlaceholderTest.java b/hapi-fhir-base/src/test/java/ca/uhn/fhir/validation/PlaceholderTest.java index 4a84e1c55d4..f757cc2b801 100644 --- a/hapi-fhir-base/src/test/java/ca/uhn/fhir/validation/PlaceholderTest.java +++ b/hapi-fhir-base/src/test/java/ca/uhn/fhir/validation/PlaceholderTest.java @@ -1,6 +1,6 @@ package ca.uhn.fhir.validation; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class PlaceholderTest { diff --git a/hapi-fhir-base/src/test/java/ca/uhn/fhir/validation/ResultSeverityEnumTest.java b/hapi-fhir-base/src/test/java/ca/uhn/fhir/validation/ResultSeverityEnumTest.java index 9ad7f47df3d..860c6367a6a 100644 --- a/hapi-fhir-base/src/test/java/ca/uhn/fhir/validation/ResultSeverityEnumTest.java +++ b/hapi-fhir-base/src/test/java/ca/uhn/fhir/validation/ResultSeverityEnumTest.java @@ -1,8 +1,8 @@ package ca.uhn.fhir.validation; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class ResultSeverityEnumTest { diff --git a/hapi-fhir-cli/hapi-fhir-cli-api/src/test/java/ca/uhn/fhir/cli/BaseCommandTest.java b/hapi-fhir-cli/hapi-fhir-cli-api/src/test/java/ca/uhn/fhir/cli/BaseCommandTest.java index 8a1b992a8d9..ec979542ac7 100644 --- a/hapi-fhir-cli/hapi-fhir-cli-api/src/test/java/ca/uhn/fhir/cli/BaseCommandTest.java +++ b/hapi-fhir-cli/hapi-fhir-cli-api/src/test/java/ca/uhn/fhir/cli/BaseCommandTest.java @@ -3,12 +3,12 @@ package ca.uhn.fhir.cli; import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.Options; import org.apache.commons.cli.ParseException; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.ByteArrayInputStream; import java.io.InputStream; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public class BaseCommandTest { diff --git a/hapi-fhir-cli/hapi-fhir-cli-api/src/test/java/ca/uhn/fhir/cli/CreatePackageCommandTest.java b/hapi-fhir-cli/hapi-fhir-cli-api/src/test/java/ca/uhn/fhir/cli/CreatePackageCommandTest.java index d0ccd11974e..fe00f139118 100644 --- a/hapi-fhir-cli/hapi-fhir-cli-api/src/test/java/ca/uhn/fhir/cli/CreatePackageCommandTest.java +++ b/hapi-fhir-cli/hapi-fhir-cli-api/src/test/java/ca/uhn/fhir/cli/CreatePackageCommandTest.java @@ -12,9 +12,9 @@ import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.r4.model.StructureDefinition; import org.hl7.fhir.r4.model.ValueSet; import org.hl7.fhir.utilities.cache.NpmPackage; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.rauschig.jarchivelib.Archiver; import org.rauschig.jarchivelib.ArchiverFactory; import org.slf4j.Logger; @@ -27,7 +27,7 @@ import java.io.IOException; import java.util.List; import java.util.stream.Collectors; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public class CreatePackageCommandTest extends BaseTest { @@ -41,14 +41,14 @@ public class CreatePackageCommandTest extends BaseTest { System.setProperty("test", "true"); } - @Before + @BeforeEach public void start() { myWorkDirectory = Files.createTempDir(); myTargetDirectory = Files.createTempDir(); myExtractDirectory = Files.createTempDir(); } - @After + @AfterEach public void stop() { try { FileUtils.deleteDirectory(myWorkDirectory); diff --git a/hapi-fhir-cli/hapi-fhir-cli-api/src/test/java/ca/uhn/fhir/cli/ExportConceptMapToCsvCommandDstu3Test.java b/hapi-fhir-cli/hapi-fhir-cli-api/src/test/java/ca/uhn/fhir/cli/ExportConceptMapToCsvCommandDstu3Test.java index f77837f3775..80e89fa2257 100644 --- a/hapi-fhir-cli/hapi-fhir-cli-api/src/test/java/ca/uhn/fhir/cli/ExportConceptMapToCsvCommandDstu3Test.java +++ b/hapi-fhir-cli/hapi-fhir-cli-api/src/test/java/ca/uhn/fhir/cli/ExportConceptMapToCsvCommandDstu3Test.java @@ -5,7 +5,7 @@ import ca.uhn.fhir.rest.client.api.IGenericClient; import ca.uhn.fhir.rest.server.RestfulServer; import ca.uhn.fhir.rest.server.interceptor.VerboseLoggingInterceptor; import ca.uhn.fhir.test.utilities.JettyUtil; -import ca.uhn.fhir.test.utilities.LoggingRule; +import ca.uhn.fhir.test.utilities.LoggingExtension; import ca.uhn.fhir.util.TestUtil; import com.google.common.base.Charsets; import org.apache.commons.io.FileUtils; @@ -16,17 +16,17 @@ import org.eclipse.jetty.servlet.ServletHolder; import org.hl7.fhir.dstu3.model.ConceptMap; import org.hl7.fhir.dstu3.model.Enumerations.ConceptMapEquivalence; import org.hl7.fhir.dstu3.model.UriType; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import static org.awaitility.Awaitility.await; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public class ExportConceptMapToCsvCommandDstu3Test { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ExportConceptMapToCsvCommandDstu3Test.class); @@ -49,8 +49,8 @@ public class ExportConceptMapToCsvCommandDstu3Test { System.setProperty("test", "true"); } - @Rule - public LoggingRule myLoggingRule = new LoggingRule(); + @RegisterExtension + public LoggingExtension myLoggingExtension = new LoggingExtension(); @Test public void testExportConceptMapToCsvCommand() throws IOException { @@ -85,13 +85,13 @@ public class ExportConceptMapToCsvCommandDstu3Test { FileUtils.deleteQuietly(new File(FILE)); } - @AfterClass + @AfterAll public static void afterClassClearContext() throws Exception { JettyUtil.closeServer(ourServer); TestUtil.clearAllStaticFieldsForUnitTest(); } - @BeforeClass + @BeforeAll public static void beforeClass() throws Exception { ourServer = new Server(0); diff --git a/hapi-fhir-cli/hapi-fhir-cli-api/src/test/java/ca/uhn/fhir/cli/ExportConceptMapToCsvCommandR4Test.java b/hapi-fhir-cli/hapi-fhir-cli-api/src/test/java/ca/uhn/fhir/cli/ExportConceptMapToCsvCommandR4Test.java index 269d1334c11..9ff9b85a5d7 100644 --- a/hapi-fhir-cli/hapi-fhir-cli-api/src/test/java/ca/uhn/fhir/cli/ExportConceptMapToCsvCommandR4Test.java +++ b/hapi-fhir-cli/hapi-fhir-cli-api/src/test/java/ca/uhn/fhir/cli/ExportConceptMapToCsvCommandR4Test.java @@ -15,16 +15,16 @@ import org.eclipse.jetty.servlet.ServletHolder; import org.hl7.fhir.r4.model.ConceptMap; import org.hl7.fhir.r4.model.Enumerations.ConceptMapEquivalence; import org.hl7.fhir.r4.model.UriType; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import static org.awaitility.Awaitility.await; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public class ExportConceptMapToCsvCommandR4Test { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ExportConceptMapToCsvCommandR4Test.class); @@ -78,13 +78,13 @@ public class ExportConceptMapToCsvCommandR4Test { FileUtils.deleteQuietly(new File(FILE)); } - @AfterClass + @AfterAll public static void afterClassClearContext() throws Exception { JettyUtil.closeServer(ourServer); TestUtil.clearAllStaticFieldsForUnitTest(); } - @BeforeClass + @BeforeAll public static void beforeClass() throws Exception { ourServer = new Server(0); diff --git a/hapi-fhir-cli/hapi-fhir-cli-api/src/test/java/ca/uhn/fhir/cli/HapiFlywayMigrateDatabaseCommandTest.java b/hapi-fhir-cli/hapi-fhir-cli-api/src/test/java/ca/uhn/fhir/cli/HapiFlywayMigrateDatabaseCommandTest.java index 6a1c15fcab5..d968a11503b 100644 --- a/hapi-fhir-cli/hapi-fhir-cli-api/src/test/java/ca/uhn/fhir/cli/HapiFlywayMigrateDatabaseCommandTest.java +++ b/hapi-fhir-cli/hapi-fhir-cli-api/src/test/java/ca/uhn/fhir/cli/HapiFlywayMigrateDatabaseCommandTest.java @@ -5,7 +5,7 @@ import ca.uhn.fhir.jpa.migrate.JdbcUtils; import com.google.common.base.Charsets; import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.jdbc.core.JdbcTemplate; @@ -26,9 +26,7 @@ import java.util.List; import java.util.Map; import static org.apache.commons.lang3.StringUtils.isBlank; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.*; public class HapiFlywayMigrateDatabaseCommandTest { diff --git a/hapi-fhir-cli/hapi-fhir-cli-api/src/test/java/ca/uhn/fhir/cli/ImportCsvToConceptMapCommandDstu3Test.java b/hapi-fhir-cli/hapi-fhir-cli-api/src/test/java/ca/uhn/fhir/cli/ImportCsvToConceptMapCommandDstu3Test.java index b1e78c2194f..dcf23514bb8 100644 --- a/hapi-fhir-cli/hapi-fhir-cli-api/src/test/java/ca/uhn/fhir/cli/ImportCsvToConceptMapCommandDstu3Test.java +++ b/hapi-fhir-cli/hapi-fhir-cli-api/src/test/java/ca/uhn/fhir/cli/ImportCsvToConceptMapCommandDstu3Test.java @@ -5,27 +5,27 @@ import ca.uhn.fhir.rest.api.MethodOutcome; import ca.uhn.fhir.rest.client.api.IGenericClient; import ca.uhn.fhir.rest.server.RestfulServer; import ca.uhn.fhir.rest.server.interceptor.VerboseLoggingInterceptor; +import ca.uhn.fhir.test.utilities.JettyUtil; import ca.uhn.fhir.util.TestUtil; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.servlet.ServletHandler; import org.eclipse.jetty.servlet.ServletHolder; -import org.hl7.fhir.exceptions.FHIRException; import org.hl7.fhir.dstu3.model.Bundle; import org.hl7.fhir.dstu3.model.ConceptMap; import org.hl7.fhir.dstu3.model.ConceptMap.ConceptMapGroupComponent; import org.hl7.fhir.dstu3.model.ConceptMap.SourceElementComponent; import org.hl7.fhir.dstu3.model.ConceptMap.TargetElementComponent; import org.hl7.fhir.dstu3.model.Enumerations.ConceptMapEquivalence; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; +import org.hl7.fhir.exceptions.FHIRException; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import java.io.File; -import static org.junit.Assert.*; - -import ca.uhn.fhir.test.utilities.JettyUtil; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; public class ImportCsvToConceptMapCommandDstu3Test { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ImportCsvToConceptMapCommandDstu3Test.class); @@ -53,40 +53,12 @@ public class ImportCsvToConceptMapCommandDstu3Test { System.setProperty("test", "true"); } - @After + @AfterEach public void afterClearResourceProvider() { HashMapResourceProviderConceptMapDstu3 resourceProvider = (HashMapResourceProviderConceptMapDstu3) restfulServer.getResourceProviders().iterator().next(); resourceProvider.clear(); } - @AfterClass - public static void afterClassClearContext() throws Exception { - JettyUtil.closeServer(ourServer); - TestUtil.clearAllStaticFieldsForUnitTest(); - } - - @BeforeClass - public static void beforeClass() throws Exception { - ourServer = new Server(0); - - ServletHandler servletHandler = new ServletHandler(); - - restfulServer = new RestfulServer(ourCtx); - restfulServer.registerInterceptor(new VerboseLoggingInterceptor()); - restfulServer.setResourceProviders(new HashMapResourceProviderConceptMapDstu3(ourCtx)); - - ServletHolder servletHolder = new ServletHolder(restfulServer); - servletHandler.addServletWithMapping(servletHolder, "/*"); - ourServer.setHandler(servletHandler); - - JettyUtil.startServer(ourServer); - ourPort = JettyUtil.getPortForStartedServer(ourServer); - - ourBase = "http://localhost:" + ourPort; - - ourClient = ourCtx.newRestfulGenericClient(ourBase); - } - @Test public void testConditionalUpdateResultsInCreate() { ConceptMap conceptMap = ExportConceptMapToCsvCommandDstu3Test.createConceptMap(); @@ -149,7 +121,7 @@ public class ImportCsvToConceptMapCommandDstu3Test { File fileToImport = new File(classLoader.getResource(FILENAME).getFile()); ImportCsvToConceptMapCommandDstu3Test.file = fileToImport.getAbsolutePath(); - App.main(new String[] {"import-csv-to-conceptmap", + App.main(new String[]{"import-csv-to-conceptmap", "-v", ourVersion, "-t", ourBase, "-u", CM_URL, @@ -345,7 +317,7 @@ public class ImportCsvToConceptMapCommandDstu3Test { assertEquals(ConceptMapEquivalence.EQUAL, target.getEquivalence()); assertEquals("3d This is a comment.", target.getComment()); - App.main(new String[] {"import-csv-to-conceptmap", + App.main(new String[]{"import-csv-to-conceptmap", "-v", ourVersion, "-t", ourBase, "-u", CM_URL, @@ -365,4 +337,32 @@ public class ImportCsvToConceptMapCommandDstu3Test { assertEquals("http://localhost:" + ourPort + "/ConceptMap/1/_history/2", conceptMap.getId()); } + + @AfterAll + public static void afterClassClearContext() throws Exception { + JettyUtil.closeServer(ourServer); + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + @BeforeAll + public static void beforeClass() throws Exception { + ourServer = new Server(0); + + ServletHandler servletHandler = new ServletHandler(); + + restfulServer = new RestfulServer(ourCtx); + restfulServer.registerInterceptor(new VerboseLoggingInterceptor()); + restfulServer.setResourceProviders(new HashMapResourceProviderConceptMapDstu3(ourCtx)); + + ServletHolder servletHolder = new ServletHolder(restfulServer); + servletHandler.addServletWithMapping(servletHolder, "/*"); + ourServer.setHandler(servletHandler); + + JettyUtil.startServer(ourServer); + ourPort = JettyUtil.getPortForStartedServer(ourServer); + + ourBase = "http://localhost:" + ourPort; + + ourClient = ourCtx.newRestfulGenericClient(ourBase); + } } diff --git a/hapi-fhir-cli/hapi-fhir-cli-api/src/test/java/ca/uhn/fhir/cli/ImportCsvToConceptMapCommandR4Test.java b/hapi-fhir-cli/hapi-fhir-cli-api/src/test/java/ca/uhn/fhir/cli/ImportCsvToConceptMapCommandR4Test.java index 4d8aaceb8e8..f59028a98f7 100644 --- a/hapi-fhir-cli/hapi-fhir-cli-api/src/test/java/ca/uhn/fhir/cli/ImportCsvToConceptMapCommandR4Test.java +++ b/hapi-fhir-cli/hapi-fhir-cli-api/src/test/java/ca/uhn/fhir/cli/ImportCsvToConceptMapCommandR4Test.java @@ -5,27 +5,28 @@ import ca.uhn.fhir.rest.api.MethodOutcome; import ca.uhn.fhir.rest.client.api.IGenericClient; import ca.uhn.fhir.rest.server.RestfulServer; import ca.uhn.fhir.rest.server.interceptor.VerboseLoggingInterceptor; +import ca.uhn.fhir.test.utilities.JettyUtil; import ca.uhn.fhir.util.TestUtil; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.servlet.ServletHandler; import org.eclipse.jetty.servlet.ServletHolder; +import org.hl7.fhir.exceptions.FHIRException; import org.hl7.fhir.r4.model.Bundle; import org.hl7.fhir.r4.model.ConceptMap; import org.hl7.fhir.r4.model.ConceptMap.ConceptMapGroupComponent; import org.hl7.fhir.r4.model.ConceptMap.SourceElementComponent; import org.hl7.fhir.r4.model.ConceptMap.TargetElementComponent; import org.hl7.fhir.r4.model.Enumerations.ConceptMapEquivalence; -import org.hl7.fhir.exceptions.FHIRException; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import java.io.File; -import static org.junit.Assert.*; - -import ca.uhn.fhir.test.utilities.JettyUtil; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; public class ImportCsvToConceptMapCommandR4Test { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ImportCsvToConceptMapCommandR4Test.class); @@ -53,40 +54,12 @@ public class ImportCsvToConceptMapCommandR4Test { System.setProperty("test", "true"); } - @After + @AfterEach public void afterClearResourceProvider() { HashMapResourceProviderConceptMapR4 resourceProvider = (HashMapResourceProviderConceptMapR4) restfulServer.getResourceProviders().iterator().next(); resourceProvider.clear(); } - @AfterClass - public static void afterClassClearContext() throws Exception { - JettyUtil.closeServer(ourServer); - TestUtil.clearAllStaticFieldsForUnitTest(); - } - - @BeforeClass - public static void beforeClass() throws Exception { - ourServer = new Server(0); - - ServletHandler servletHandler = new ServletHandler(); - - restfulServer = new RestfulServer(ourCtx); - restfulServer.registerInterceptor(new VerboseLoggingInterceptor()); - restfulServer.setResourceProviders(new HashMapResourceProviderConceptMapR4(ourCtx)); - - ServletHolder servletHolder = new ServletHolder(restfulServer); - servletHandler.addServletWithMapping(servletHolder, "/*"); - ourServer.setHandler(servletHandler); - - JettyUtil.startServer(ourServer); - ourPort = JettyUtil.getPortForStartedServer(ourServer); - - ourBase = "http://localhost:" + ourPort; - - ourClient = ourCtx.newRestfulGenericClient(ourBase); - } - @Test public void testConditionalUpdateResultsInCreate() { ConceptMap conceptMap = ExportConceptMapToCsvCommandR4Test.createConceptMap(); @@ -154,7 +127,7 @@ public class ImportCsvToConceptMapCommandR4Test { File fileToImport = new File(classLoader.getResource(FILENAME).getFile()); ImportCsvToConceptMapCommandR4Test.file = fileToImport.getAbsolutePath(); - App.main(new String[] {"import-csv-to-conceptmap", + App.main(new String[]{"import-csv-to-conceptmap", "-v", ourVersion, "-t", ourBase, "-u", CM_URL, @@ -350,7 +323,7 @@ public class ImportCsvToConceptMapCommandR4Test { assertEquals(ConceptMapEquivalence.EQUAL, target.getEquivalence()); assertEquals("3d This is a comment.", target.getComment()); - App.main(new String[] {"import-csv-to-conceptmap", + App.main(new String[]{"import-csv-to-conceptmap", "-v", ourVersion, "-t", ourBase, "-u", CM_URL, @@ -377,7 +350,7 @@ public class ImportCsvToConceptMapCommandR4Test { File fileToImport = new File(classLoader.getResource("loinc-to-phenx.csv").getFile()); ImportCsvToConceptMapCommandR4Test.file = fileToImport.getAbsolutePath(); - App.main(new String[] {"import-csv-to-conceptmap", + App.main(new String[]{"import-csv-to-conceptmap", "-v", ourVersion, "-t", ourBase, "-u", "http://loinc.org/cm/loinc-to-phenx", @@ -425,7 +398,7 @@ public class ImportCsvToConceptMapCommandR4Test { assertEquals(ConceptMapEquivalence.EQUIVALENT, target.getEquivalence()); assertNull(target.getComment()); - App.main(new String[] {"import-csv-to-conceptmap", + App.main(new String[]{"import-csv-to-conceptmap", "-v", ourVersion, "-t", ourBase, "-u", "http://loinc.org/cm/loinc-to-phenx", @@ -445,4 +418,32 @@ public class ImportCsvToConceptMapCommandR4Test { assertEquals("http://localhost:" + ourPort + "/ConceptMap/1/_history/2", conceptMap.getId()); } + + @AfterAll + public static void afterClassClearContext() throws Exception { + JettyUtil.closeServer(ourServer); + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + @BeforeAll + public static void beforeClass() throws Exception { + ourServer = new Server(0); + + ServletHandler servletHandler = new ServletHandler(); + + restfulServer = new RestfulServer(ourCtx); + restfulServer.registerInterceptor(new VerboseLoggingInterceptor()); + restfulServer.setResourceProviders(new HashMapResourceProviderConceptMapR4(ourCtx)); + + ServletHolder servletHolder = new ServletHolder(restfulServer); + servletHandler.addServletWithMapping(servletHolder, "/*"); + ourServer.setHandler(servletHandler); + + JettyUtil.startServer(ourServer); + ourPort = JettyUtil.getPortForStartedServer(ourServer); + + ourBase = "http://localhost:" + ourPort; + + ourClient = ourCtx.newRestfulGenericClient(ourBase); + } } diff --git a/hapi-fhir-cli/hapi-fhir-cli-api/src/test/java/ca/uhn/fhir/cli/InstallIgPackTest.java b/hapi-fhir-cli/hapi-fhir-cli-api/src/test/java/ca/uhn/fhir/cli/InstallIgPackTest.java index 567d2d2a64a..3bb24dcd1c1 100644 --- a/hapi-fhir-cli/hapi-fhir-cli-api/src/test/java/ca/uhn/fhir/cli/InstallIgPackTest.java +++ b/hapi-fhir-cli/hapi-fhir-cli-api/src/test/java/ca/uhn/fhir/cli/InstallIgPackTest.java @@ -1,6 +1,6 @@ package ca.uhn.fhir.cli; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class InstallIgPackTest { diff --git a/hapi-fhir-cli/hapi-fhir-cli-api/src/test/java/ca/uhn/fhir/cli/OptionsTest.java b/hapi-fhir-cli/hapi-fhir-cli-api/src/test/java/ca/uhn/fhir/cli/OptionsTest.java index c705a38fd3f..9ef8910b19b 100644 --- a/hapi-fhir-cli/hapi-fhir-cli-api/src/test/java/ca/uhn/fhir/cli/OptionsTest.java +++ b/hapi-fhir-cli/hapi-fhir-cli-api/src/test/java/ca/uhn/fhir/cli/OptionsTest.java @@ -1,6 +1,6 @@ package ca.uhn.fhir.cli; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class OptionsTest { diff --git a/hapi-fhir-cli/hapi-fhir-cli-api/src/test/java/ca/uhn/fhir/cli/UploadTerminologyCommandTest.java b/hapi-fhir-cli/hapi-fhir-cli-api/src/test/java/ca/uhn/fhir/cli/UploadTerminologyCommandTest.java index 2ed94ab0b9b..8b1eccd4d5a 100644 --- a/hapi-fhir-cli/hapi-fhir-cli-api/src/test/java/ca/uhn/fhir/cli/UploadTerminologyCommandTest.java +++ b/hapi-fhir-cli/hapi-fhir-cli-api/src/test/java/ca/uhn/fhir/cli/UploadTerminologyCommandTest.java @@ -17,14 +17,14 @@ import org.hamcrest.Matchers; import org.hl7.fhir.r4.model.CodeSystem; import org.hl7.fhir.r4.model.IdType; import org.hl7.fhir.r4.model.Patient; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import java.io.*; import java.util.List; @@ -32,14 +32,15 @@ import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; import static org.hamcrest.CoreMatchers.containsString; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.greaterThan; import static org.hamcrest.Matchers.matchesPattern; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.*; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class UploadTerminologyCommandTest extends BaseTest { static { @@ -364,7 +365,7 @@ public class UploadTerminologyCommandTest extends BaseTest { } - @After + @AfterEach public void after() throws Exception { JettyUtil.closeServer(myServer); @@ -378,7 +379,7 @@ public class UploadTerminologyCommandTest extends BaseTest { UploadTerminologyCommand.setTransferSizeLimitForUnitTest(-1); } - @Before + @BeforeEach public void before() throws Exception { myServer = new Server(0); diff --git a/hapi-fhir-cli/hapi-fhir-cli-api/src/test/java/ca/uhn/fhir/cli/ValidateCommandTest.java b/hapi-fhir-cli/hapi-fhir-cli-api/src/test/java/ca/uhn/fhir/cli/ValidateCommandTest.java index 1e6bbd71baa..92729e49db3 100644 --- a/hapi-fhir-cli/hapi-fhir-cli-api/src/test/java/ca/uhn/fhir/cli/ValidateCommandTest.java +++ b/hapi-fhir-cli/hapi-fhir-cli-api/src/test/java/ca/uhn/fhir/cli/ValidateCommandTest.java @@ -1,15 +1,15 @@ package ca.uhn.fhir.cli; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.fail; public class ValidateCommandTest { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ValidateCommandTest.class); - @Before + @BeforeEach public void before() { System.setProperty("test", "true"); } @@ -27,7 +27,7 @@ public class ValidateCommandTest { } @Test - @Ignore + @Disabled public void testValidateUsingIgPackSucceedingDstu2() { String resourcePath = ValidateCommandTest.class.getResource("/argo-dstu2-observation-good.json").getFile(); ourLog.info(resourcePath); diff --git a/hapi-fhir-client-okhttp/src/test/java/ca/uhn/fhir/okhttp/GenericOkHttpClientDstu2Test.java b/hapi-fhir-client-okhttp/src/test/java/ca/uhn/fhir/okhttp/GenericOkHttpClientDstu2Test.java index 34a549c8226..5295c15285b 100644 --- a/hapi-fhir-client-okhttp/src/test/java/ca/uhn/fhir/okhttp/GenericOkHttpClientDstu2Test.java +++ b/hapi-fhir-client-okhttp/src/test/java/ca/uhn/fhir/okhttp/GenericOkHttpClientDstu2Test.java @@ -1,44 +1,77 @@ package ca.uhn.fhir.okhttp; -import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; - -import java.io.IOException; -import java.util.*; - -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.apache.commons.io.Charsets; -import org.apache.commons.io.IOUtils; -import org.eclipse.jetty.server.Request; -import org.eclipse.jetty.server.Server; -import org.eclipse.jetty.server.handler.AbstractHandler; -import org.hl7.fhir.instance.model.api.*; -import org.junit.*; -import org.junit.Test; - -import com.google.common.collect.*; - import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.api.Include; import ca.uhn.fhir.model.api.ResourceMetadataKeyEnum; import ca.uhn.fhir.model.dstu2.composite.IdentifierDt; import ca.uhn.fhir.model.dstu2.composite.MetaDt; -import ca.uhn.fhir.model.dstu2.resource.*; +import ca.uhn.fhir.model.dstu2.resource.Bundle; import ca.uhn.fhir.model.dstu2.resource.Bundle.Entry; import ca.uhn.fhir.model.dstu2.resource.Bundle.Link; -import ca.uhn.fhir.model.primitive.*; +import ca.uhn.fhir.model.dstu2.resource.Conformance; +import ca.uhn.fhir.model.dstu2.resource.Observation; +import ca.uhn.fhir.model.dstu2.resource.OperationOutcome; +import ca.uhn.fhir.model.dstu2.resource.Parameters; +import ca.uhn.fhir.model.dstu2.resource.Patient; +import ca.uhn.fhir.model.primitive.CodeDt; +import ca.uhn.fhir.model.primitive.DateDt; +import ca.uhn.fhir.model.primitive.IdDt; +import ca.uhn.fhir.model.primitive.InstantDt; +import ca.uhn.fhir.model.primitive.StringDt; +import ca.uhn.fhir.model.primitive.UriDt; import ca.uhn.fhir.okhttp.client.OkHttpRestfulClientFactory; import ca.uhn.fhir.parser.IParser; -import ca.uhn.fhir.rest.api.*; -import ca.uhn.fhir.rest.client.api.*; +import ca.uhn.fhir.rest.api.Constants; +import ca.uhn.fhir.rest.api.EncodingEnum; +import ca.uhn.fhir.rest.api.MethodOutcome; +import ca.uhn.fhir.rest.api.PreferReturnEnum; +import ca.uhn.fhir.rest.api.SearchStyleEnum; +import ca.uhn.fhir.rest.api.SummaryEnum; +import ca.uhn.fhir.rest.client.api.Header; +import ca.uhn.fhir.rest.client.api.IGenericClient; +import ca.uhn.fhir.rest.client.api.ServerValidationModeEnum; import ca.uhn.fhir.rest.client.exceptions.InvalidResponseException; import ca.uhn.fhir.rest.client.impl.RestfulClientFactory; import ca.uhn.fhir.rest.client.interceptor.LoggingInterceptor; import ca.uhn.fhir.rest.param.DateRangeParam; import ca.uhn.fhir.test.utilities.JettyUtil; +import com.google.common.collect.ArrayListMultimap; +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; +import org.apache.commons.io.Charsets; +import org.apache.commons.io.IOUtils; +import org.eclipse.jetty.server.Request; +import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.server.handler.AbstractHandler; +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.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.util.Date; +import java.util.Enumeration; +import java.util.List; +import java.util.Map; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.either; +import static org.hamcrest.Matchers.emptyString; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.equalToIgnoringCase; +import static org.hamcrest.Matchers.not; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.fail; public class GenericOkHttpClientDstu2Test { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(GenericOkHttpClientDstu2Test.class); @@ -60,67 +93,11 @@ public class GenericOkHttpClientDstu2Test { private static List> ourRequestHeadersAll; private static Map ourRequestFirstHeaders; - @BeforeClass - public static void beforeClass() throws Exception { - ourCtx = FhirContext.forDstu2(); - - ourServer = new Server(0); - ourServer.setHandler(new AbstractHandler() { - - @Override - public void handle(String theArg0, Request theRequest, HttpServletRequest theServletRequest, HttpServletResponse theResp) throws IOException, ServletException { - theRequest.setHandled(true); - ourRequestUri = "http:" + theRequest.getHttpURI().toString(); - ourRequestUriAll.add(ourRequestUri); - ourRequestMethod = theRequest.getMethod(); - ourRequestContentType = theServletRequest.getContentType(); - ourRequestBodyBytes = IOUtils.toByteArray(theServletRequest.getInputStream()); - ourRequestBodyString = new String(ourRequestBodyBytes, Charsets.UTF_8); - - ourRequestHeaders = ArrayListMultimap.create(); - ourRequestHeadersAll.add(ourRequestHeaders); - ourRequestFirstHeaders = Maps.newHashMap(); - - for (Enumeration headerNameEnum = theRequest.getHeaderNames(); headerNameEnum.hasMoreElements();) { - String nextName = headerNameEnum.nextElement(); - for (Enumeration headerValueEnum = theRequest.getHeaders(nextName); headerValueEnum.hasMoreElements();) { - String nextValue = headerValueEnum.nextElement(); - if (ourRequestFirstHeaders.containsKey(nextName) == false) { - ourRequestFirstHeaders.put(nextName, new Header(nextName, nextValue)); - } - ourRequestHeaders.put(nextName, new Header(nextName, nextValue)); - } - } - - theResp.setStatus(ourResponseStatus); - - if (ourResponseBody != null) { - theResp.setContentType(ourResponseContentType); - theResp.getWriter().write(ourResponseBody); - } else if (ourResponseBodies != null) { - theResp.setContentType(ourResponseContentType); - theResp.getWriter().write(ourResponseBodies[ourResponseCount]); - } - - ourResponseCount++; - } - }); - - JettyUtil.startServer(ourServer); - ourPort = JettyUtil.getPortForStartedServer(ourServer); - } - - @AfterClass - public static void afterClass() throws Exception { - JettyUtil.closeServer(ourServer); - } - /** * This suite of tests can be reconfigured to test a different RestfulClientFactory implementation by * changing the instance returned here. * - * @param context - * FhirContext or null + * @param context FhirContext or null * @return RestfulClientFactory implementation to run tests against */ private RestfulClientFactory createNewClientFactoryForTesting(FhirContext context) { @@ -131,7 +108,7 @@ public class GenericOkHttpClientDstu2Test { } } - @Before + @BeforeEach public void before() { RestfulClientFactory clientFactory = createNewClientFactoryForTesting(ourCtx); clientFactory.setServerValidationMode(ServerValidationModeEnum.NEVER); @@ -159,20 +136,20 @@ public class GenericOkHttpClientDstu2Test { private String getPatientFeedWithOneResult() { String msg = "\n" + - "d039f91a-cc3c-4013-988e-af4d8d0614bd\n" + - "\n" + - "" - + "" - + "
John Cardinal: 444333333
" - + "" - + "" - + "" - + "" - + "
" - + "
" - + "
\n" - + "
\n" - + "
"; + "d039f91a-cc3c-4013-988e-af4d8d0614bd\n" + + "\n" + + "" + + "" + + "
John Cardinal: 444333333
" + + "" + + "" + + "" + + "" + + "
" + + "
" + + "
\n" + + "
\n" + + ""; return msg; } @@ -217,7 +194,7 @@ public class GenericOkHttpClientDstu2Test { patient.addName().addFamily("FAMILY"); ourResponseContentType = Constants.CT_FHIR_XML + "; charset=UTF-8"; - ourResponseBodies = new String[] { p.encodeResourceToString(conf), p.encodeResourceToString(patient) }; + ourResponseBodies = new String[]{p.encodeResourceToString(conf), p.encodeResourceToString(patient)}; ourCtx.getRestfulClientFactory().setServerValidationMode(ServerValidationModeEnum.ONCE); IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort + "/fhir"); @@ -247,7 +224,7 @@ public class GenericOkHttpClientDstu2Test { patient.addName().addFamily("FAMILY"); ourResponseContentType = Constants.CT_FHIR_XML + "; charset=UTF-8"; - ourResponseBodies = new String[] { p.encodeResourceToString(conf), p.encodeResourceToString(patient) }; + ourResponseBodies = new String[]{p.encodeResourceToString(conf), p.encodeResourceToString(patient)}; ourCtx.getRestfulClientFactory().setServerValidationMode(ServerValidationModeEnum.ONCE); IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort + "/fhir"); @@ -438,71 +415,71 @@ public class GenericOkHttpClientDstu2Test { ca.uhn.fhir.model.dstu2.resource.Bundle response; response = client - .history() - .onServer() - .andReturnBundle(ca.uhn.fhir.model.dstu2.resource.Bundle.class) - .execute(); + .history() + .onServer() + .andReturnBundle(ca.uhn.fhir.model.dstu2.resource.Bundle.class) + .execute(); assertEquals("http://localhost:" + ourPort + "/fhir/_history", ourRequestUri); assertEquals(1, response.getEntry().size()); response = client - .history() - .onServer() - .andReturnBundle(ca.uhn.fhir.model.dstu2.resource.Bundle.class) - .since((Date) null) - .count(null) - .execute(); + .history() + .onServer() + .andReturnBundle(ca.uhn.fhir.model.dstu2.resource.Bundle.class) + .since((Date) null) + .count(null) + .execute(); assertEquals("http://localhost:" + ourPort + "/fhir/_history", ourRequestUri); assertEquals(1, response.getEntry().size()); response = client - .history() - .onServer() - .andReturnBundle(ca.uhn.fhir.model.dstu2.resource.Bundle.class) - .since(new InstantDt()) - .execute(); + .history() + .onServer() + .andReturnBundle(ca.uhn.fhir.model.dstu2.resource.Bundle.class) + .since(new InstantDt()) + .execute(); assertEquals("http://localhost:" + ourPort + "/fhir/_history", ourRequestUri); assertEquals(1, response.getEntry().size()); response = client - .history() - .onType(Patient.class) - .andReturnBundle(ca.uhn.fhir.model.dstu2.resource.Bundle.class) - .execute(); + .history() + .onType(Patient.class) + .andReturnBundle(ca.uhn.fhir.model.dstu2.resource.Bundle.class) + .execute(); assertEquals("http://localhost:" + ourPort + "/fhir/Patient/_history", ourRequestUri); assertEquals(1, response.getEntry().size()); response = client - .history() - .onInstance(new IdDt("Patient", "123")) - .andReturnBundle(ca.uhn.fhir.model.dstu2.resource.Bundle.class) - .execute(); + .history() + .onInstance(new IdDt("Patient", "123")) + .andReturnBundle(ca.uhn.fhir.model.dstu2.resource.Bundle.class) + .execute(); assertEquals("http://localhost:" + ourPort + "/fhir/Patient/123/_history", ourRequestUri); assertEquals(1, response.getEntry().size()); response = client - .history() - .onInstance(new IdDt("Patient", "123")) - .andReturnBundle(ca.uhn.fhir.model.dstu2.resource.Bundle.class) - .count(123) - .since(new InstantDt("2001-01-02T11:22:33Z")) - .execute(); + .history() + .onInstance(new IdDt("Patient", "123")) + .andReturnBundle(ca.uhn.fhir.model.dstu2.resource.Bundle.class) + .count(123) + .since(new InstantDt("2001-01-02T11:22:33Z")) + .execute(); assertThat(ourRequestUri, either(equalTo("http://localhost:" + ourPort + "/fhir/Patient/123/_history?_since=2001-01-02T11:22:33Z&_count=123")) - .or(equalTo("http://localhost:" + ourPort + "/fhir/Patient/123/_history?_count=123&_since=2001-01-02T11:22:33Z"))); + .or(equalTo("http://localhost:" + ourPort + "/fhir/Patient/123/_history?_count=123&_since=2001-01-02T11:22:33Z"))); assertEquals(1, response.getEntry().size()); response = client - .history() - .onInstance(new IdDt("Patient", "123")) - .andReturnBundle(ca.uhn.fhir.model.dstu2.resource.Bundle.class) - .since(new InstantDt("2001-01-02T11:22:33Z").getValue()) - .execute(); + .history() + .onInstance(new IdDt("Patient", "123")) + .andReturnBundle(ca.uhn.fhir.model.dstu2.resource.Bundle.class) + .since(new InstantDt("2001-01-02T11:22:33Z").getValue()) + .execute(); assertThat(ourRequestUri, containsString("_since=2001-01")); assertEquals(1, response.getEntry().size()); @@ -524,18 +501,18 @@ public class GenericOkHttpClientDstu2Test { IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort + "/fhir"); MetaDt resp = client - .meta() - .add() - .onResource(new IdDt("Patient/123")) - .meta(inMeta) + .meta() + .add() + .onResource(new IdDt("Patient/123")) + .meta(inMeta) .encodedXml() - .execute(); + .execute(); assertEquals("http://localhost:" + ourPort + "/fhir/Patient/123/$meta-add", ourRequestUri); assertEquals("urn:profile:out", resp.getProfile().get(0).getValue()); assertEquals("POST", ourRequestMethod); assertEquals("", - ourRequestBodyString); + ourRequestBodyString); } @Test @@ -555,30 +532,30 @@ public class GenericOkHttpClientDstu2Test { IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort + "/fhir"); MetaDt resp = client - .meta() - .get(MetaDt.class) - .fromServer() - .execute(); + .meta() + .get(MetaDt.class) + .fromServer() + .execute(); assertEquals("http://localhost:" + ourPort + "/fhir/$meta", ourRequestUri); assertEquals("urn:profile:out", resp.getProfile().get(0).getValue()); assertEquals("GET", ourRequestMethod); resp = client - .meta() - .get(MetaDt.class) - .fromType("Patient") - .execute(); + .meta() + .get(MetaDt.class) + .fromType("Patient") + .execute(); assertEquals("http://localhost:" + ourPort + "/fhir/Patient/$meta", ourRequestUri); assertEquals("urn:profile:out", resp.getProfile().get(0).getValue()); assertEquals("GET", ourRequestMethod); resp = client - .meta() - .get(MetaDt.class) - .fromResource(new IdDt("Patient/123")) - .execute(); + .meta() + .get(MetaDt.class) + .fromResource(new IdDt("Patient/123")) + .execute(); assertEquals("http://localhost:" + ourPort + "/fhir/Patient/123/$meta", ourRequestUri); assertEquals("urn:profile:out", resp.getProfile().get(0).getValue()); @@ -605,48 +582,48 @@ public class GenericOkHttpClientDstu2Test { IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort + "/fhir"); Parameters resp = client - .operation() - .onServer() - .named("$SOMEOPERATION") - .withParameters(inParams) - .useHttpGet() - .execute(); + .operation() + .onServer() + .named("$SOMEOPERATION") + .withParameters(inParams) + .useHttpGet() + .execute(); assertEquals("http://localhost:" + ourPort + "/fhir/$SOMEOPERATION?param1=STRINGVALIN1¶m1=STRINGVALIN1b¶m2=STRINGVALIN2", ourRequestUri); assertEquals(respString, p.encodeResourceToString(resp)); assertEquals("GET", ourRequestMethod); resp = client - .operation() - .onType(Patient.class) - .named("$SOMEOPERATION") - .withParameters(inParams) - .useHttpGet() - .execute(); + .operation() + .onType(Patient.class) + .named("$SOMEOPERATION") + .withParameters(inParams) + .useHttpGet() + .execute(); assertEquals("http://localhost:" + ourPort + "/fhir/Patient/$SOMEOPERATION?param1=STRINGVALIN1¶m1=STRINGVALIN1b¶m2=STRINGVALIN2", ourRequestUri); assertEquals(respString, p.encodeResourceToString(resp)); assertEquals("GET", ourRequestMethod); resp = client - .operation() - .onInstance(new IdDt("Patient", "123")) - .named("$SOMEOPERATION") - .withParameters(inParams) - .useHttpGet() - .execute(); + .operation() + .onInstance(new IdDt("Patient", "123")) + .named("$SOMEOPERATION") + .withParameters(inParams) + .useHttpGet() + .execute(); assertEquals("http://localhost:" + ourPort + "/fhir/Patient/123/$SOMEOPERATION?param1=STRINGVALIN1¶m1=STRINGVALIN1b¶m2=STRINGVALIN2", ourRequestUri); assertEquals(respString, p.encodeResourceToString(resp)); assertEquals("GET", ourRequestMethod); resp = client - .operation() - .onInstance(new IdDt("http://foo.com/bar/baz/Patient/123/_history/22")) - .named("$SOMEOPERATION") - .withParameters(inParams) - .useHttpGet() - .execute(); + .operation() + .onInstance(new IdDt("http://foo.com/bar/baz/Patient/123/_history/22")) + .named("$SOMEOPERATION") + .withParameters(inParams) + .useHttpGet() + .execute(); assertEquals("http://localhost:" + ourPort + "/fhir/Patient/123/$SOMEOPERATION?param1=STRINGVALIN1¶m1=STRINGVALIN1b¶m2=STRINGVALIN2", ourRequestUri); } @@ -665,48 +642,48 @@ public class GenericOkHttpClientDstu2Test { IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort + "/fhir"); Parameters resp = client - .operation() - .onServer() - .named("$SOMEOPERATION") - .withNoParameters(Parameters.class) - .useHttpGet() - .execute(); + .operation() + .onServer() + .named("$SOMEOPERATION") + .withNoParameters(Parameters.class) + .useHttpGet() + .execute(); assertEquals("http://localhost:" + ourPort + "/fhir/$SOMEOPERATION", ourRequestUri); assertEquals(respString, p.encodeResourceToString(resp)); assertEquals("GET", ourRequestMethod); resp = client - .operation() - .onType(Patient.class) - .named("$SOMEOPERATION") - .withNoParameters(Parameters.class) - .useHttpGet() - .execute(); + .operation() + .onType(Patient.class) + .named("$SOMEOPERATION") + .withNoParameters(Parameters.class) + .useHttpGet() + .execute(); assertEquals("http://localhost:" + ourPort + "/fhir/Patient/$SOMEOPERATION", ourRequestUri); assertEquals(respString, p.encodeResourceToString(resp)); assertEquals("GET", ourRequestMethod); resp = client - .operation() - .onInstance(new IdDt("Patient", "123")) - .named("$SOMEOPERATION") - .withNoParameters(Parameters.class) - .useHttpGet() - .execute(); + .operation() + .onInstance(new IdDt("Patient", "123")) + .named("$SOMEOPERATION") + .withNoParameters(Parameters.class) + .useHttpGet() + .execute(); assertEquals("http://localhost:" + ourPort + "/fhir/Patient/123/$SOMEOPERATION", ourRequestUri); assertEquals(respString, p.encodeResourceToString(resp)); assertEquals("GET", ourRequestMethod); resp = client - .operation() - .onInstance(new IdDt("http://foo.com/bar/baz/Patient/123/_history/22")) - .named("$SOMEOPERATION") - .withNoParameters(Parameters.class) - .useHttpGet() - .execute(); + .operation() + .onInstance(new IdDt("http://foo.com/bar/baz/Patient/123/_history/22")) + .named("$SOMEOPERATION") + .withNoParameters(Parameters.class) + .useHttpGet() + .execute(); assertEquals("http://localhost:" + ourPort + "/fhir/Patient/123/$SOMEOPERATION", ourRequestUri); } @@ -714,7 +691,7 @@ public class GenericOkHttpClientDstu2Test { public void testOperationWithBundleResponseJson() throws Exception { ourResponseContentType = Constants.CT_FHIR_JSON; final String respString = "{\n" + " \"resourceType\":\"Bundle\",\n" + " \"id\":\"8cef5f2a-0ba9-43a5-be26-c8dde9ff0e19\",\n" + " \"base\":\"http://localhost:" + ourPort + "/fhir\"\n" - + "}"; + + "}"; ourResponseBody = respString; IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort + "/fhir"); @@ -759,10 +736,10 @@ public class GenericOkHttpClientDstu2Test { IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort + "/fhir"); Parameters resp = client - .operation() - .onServer() - .named("$SOMEOPERATION") - .withParameters(inParams).encodedXml().execute(); + .operation() + .onServer() + .named("$SOMEOPERATION") + .withParameters(inParams).encodedXml().execute(); assertEquals("http://localhost:" + ourPort + "/fhir/$SOMEOPERATION", ourRequestUri); assertEquals(1, ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE).size()); @@ -788,13 +765,13 @@ public class GenericOkHttpClientDstu2Test { IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort + "/fhir"); Parameters resp = client - .operation() - .onServer() - .named("$SOMEOPERATION") - .withParameter(Parameters.class, "name1", new StringDt("value1")) - .andParameter("name2", new StringDt("value1")) + .operation() + .onServer() + .named("$SOMEOPERATION") + .withParameter(Parameters.class, "name1", new StringDt("value1")) + .andParameter("name2", new StringDt("value1")) .encodedXml() - .execute(); + .execute(); assertEquals("http://localhost:" + ourPort + "/fhir/$SOMEOPERATION", ourRequestUri); assertEquals(respString, p.encodeResourceToString(resp)); @@ -802,21 +779,21 @@ public class GenericOkHttpClientDstu2Test { assertContentTypeEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8); assertEquals("POST", ourRequestMethod); assertEquals( - "", - (ourRequestBodyString)); + "", + (ourRequestBodyString)); /* * Composite type */ resp = client - .operation() - .onServer() - .named("$SOMEOPERATION") - .withParameter(Parameters.class, "name1", new IdentifierDt("system1", "value1")) - .andParameter("name2", new StringDt("value1")) + .operation() + .onServer() + .named("$SOMEOPERATION") + .withParameter(Parameters.class, "name1", new IdentifierDt("system1", "value1")) + .andParameter("name2", new StringDt("value1")) .encodedXml() - .execute(); + .execute(); assertEquals("http://localhost:" + ourPort + "/fhir/$SOMEOPERATION", ourRequestUri); assertEquals(respString, p.encodeResourceToString(resp)); @@ -824,21 +801,21 @@ public class GenericOkHttpClientDstu2Test { assertContentTypeEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8); assertEquals("POST", ourRequestMethod); assertEquals( - "", - (ourRequestBodyString)); + "", + (ourRequestBodyString)); /* * Resource */ resp = client - .operation() - .onServer() - .named("$SOMEOPERATION") - .withParameter(Parameters.class, "name1", new IdentifierDt("system1", "value1")) - .andParameter("name2", new Patient().setActive(true)) + .operation() + .onServer() + .named("$SOMEOPERATION") + .withParameter(Parameters.class, "name1", new IdentifierDt("system1", "value1")) + .andParameter("name2", new Patient().setActive(true)) .encodedXml() - .execute(); + .execute(); assertEquals("http://localhost:" + ourPort + "/fhir/$SOMEOPERATION", ourRequestUri); assertEquals(respString, p.encodeResourceToString(resp)); @@ -846,11 +823,11 @@ public class GenericOkHttpClientDstu2Test { assertContentTypeEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8); assertEquals("POST", ourRequestMethod); assertEquals( - "", - (ourRequestBodyString)); + "", + (ourRequestBodyString)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testOperationWithInvalidParam() { IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort + "/fhir"); @@ -889,12 +866,14 @@ public class GenericOkHttpClientDstu2Test { } }; - client + assertThrows(IllegalArgumentException.class, () -> { + client .operation() .onServer() .named("$SOMEOPERATION") .withParameter(Parameters.class, "name1", weirdBase) .execute(); + }); } @@ -913,30 +892,30 @@ public class GenericOkHttpClientDstu2Test { IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort + "/fhir"); client - .operation() - .onInstance(new IdDt("http://foo/Patient/1")) - .named("validate-code") - .withParameter(Parameters.class, "code", new CodeDt("8495-4")) - .andParameter("system", new UriDt("http://loinc.org")) - .useHttpGet() - .execute(); + .operation() + .onInstance(new IdDt("http://foo/Patient/1")) + .named("validate-code") + .withParameter(Parameters.class, "code", new CodeDt("8495-4")) + .andParameter("system", new UriDt("http://loinc.org")) + .useHttpGet() + .execute(); assertEquals("http://localhost:" + ourPort + "/fhir/Patient/1/$validate-code?code=8495-4&system=http%3A%2F%2Floinc.org", ourRequestUri); client - .operation() - .onInstance(new IdDt("http://foo/Patient/1")) - .named("validate-code") - .withParameter(Parameters.class, "code", new CodeDt("8495-4")) - .andParameter("system", new UriDt("http://loinc.org")) + .operation() + .onInstance(new IdDt("http://foo/Patient/1")) + .named("validate-code") + .withParameter(Parameters.class, "code", new CodeDt("8495-4")) + .andParameter("system", new UriDt("http://loinc.org")) .encodedXml() - .execute(); + .execute(); assertEquals("http://localhost:" + ourPort + "/fhir/Patient/1/$validate-code", ourRequestUri); ourLog.info(ourRequestBodyString); assertEquals( - "", - ourRequestBodyString); + "", + ourRequestBodyString); } @Test @@ -959,10 +938,10 @@ public class GenericOkHttpClientDstu2Test { IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort + "/fhir"); Parameters resp = client - .operation() - .onServer() - .named("$SOMEOPERATION") - .withParameters(inParams).encodedXml().execute(); + .operation() + .onServer() + .named("$SOMEOPERATION") + .withParameters(inParams).encodedXml().execute(); assertEquals("http://localhost:" + ourPort + "/fhir/$SOMEOPERATION", ourRequestUri); assertEquals(respString, p.encodeResourceToString(resp)); @@ -972,10 +951,10 @@ public class GenericOkHttpClientDstu2Test { assertEquals("POST", ourRequestMethod); resp = client - .operation() - .onType(Patient.class) - .named("$SOMEOPERATION") - .withParameters(inParams).encodedXml().execute(); + .operation() + .onType(Patient.class) + .named("$SOMEOPERATION") + .withParameters(inParams).encodedXml().execute(); assertEquals("http://localhost:" + ourPort + "/fhir/Patient/$SOMEOPERATION", ourRequestUri); assertEquals(respString, p.encodeResourceToString(resp)); @@ -985,10 +964,10 @@ public class GenericOkHttpClientDstu2Test { assertEquals("POST", ourRequestMethod); resp = client - .operation() - .onInstance(new IdDt("Patient", "123")) - .named("$SOMEOPERATION") - .withParameters(inParams).encodedXml().execute(); + .operation() + .onInstance(new IdDt("Patient", "123")) + .named("$SOMEOPERATION") + .withParameters(inParams).encodedXml().execute(); assertEquals("http://localhost:" + ourPort + "/fhir/Patient/123/$SOMEOPERATION", ourRequestUri); assertEquals(respString, p.encodeResourceToString(resp)); @@ -1020,10 +999,10 @@ public class GenericOkHttpClientDstu2Test { IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort + "/fhir"); Parameters resp = client - .operation() - .onServer() - .named("$SOMEOPERATION") - .withNoParameters(Parameters.class).encodedXml().execute(); + .operation() + .onServer() + .named("$SOMEOPERATION") + .withNoParameters(Parameters.class).encodedXml().execute(); assertEquals("http://localhost:" + ourPort + "/fhir/$SOMEOPERATION", ourRequestUri); assertEquals(respString, p.encodeResourceToString(resp)); @@ -1033,10 +1012,10 @@ public class GenericOkHttpClientDstu2Test { assertEquals("POST", ourRequestMethod); resp = client - .operation() - .onType(Patient.class) - .named("$SOMEOPERATION") - .withNoParameters(Parameters.class).encodedXml().execute(); + .operation() + .onType(Patient.class) + .named("$SOMEOPERATION") + .withNoParameters(Parameters.class).encodedXml().execute(); assertEquals("http://localhost:" + ourPort + "/fhir/Patient/$SOMEOPERATION", ourRequestUri); assertEquals(respString, p.encodeResourceToString(resp)); @@ -1046,10 +1025,10 @@ public class GenericOkHttpClientDstu2Test { assertEquals("POST", ourRequestMethod); resp = client - .operation() - .onInstance(new IdDt("Patient", "123")) - .named("$SOMEOPERATION") - .withNoParameters(Parameters.class).encodedXml().execute(); + .operation() + .onInstance(new IdDt("Patient", "123")) + .named("$SOMEOPERATION") + .withNoParameters(Parameters.class).encodedXml().execute(); assertEquals("http://localhost:" + ourPort + "/fhir/Patient/123/$SOMEOPERATION", ourRequestUri); assertEquals(respString, p.encodeResourceToString(resp)); @@ -1059,11 +1038,11 @@ public class GenericOkHttpClientDstu2Test { assertEquals("POST", ourRequestMethod); resp = client - .operation() - .onInstance(new IdDt("http://foo.com/bar/baz/Patient/123/_history/22")) - .named("$SOMEOPERATION") - .withNoParameters(Parameters.class) - .execute(); + .operation() + .onInstance(new IdDt("http://foo.com/bar/baz/Patient/123/_history/22")) + .named("$SOMEOPERATION") + .withNoParameters(Parameters.class) + .execute(); assertEquals("http://localhost:" + ourPort + "/fhir/Patient/123/$SOMEOPERATION", ourRequestUri); } @@ -1080,9 +1059,9 @@ public class GenericOkHttpClientDstu2Test { sourceBundle.getLinkOrCreate(IBaseBundle.LINK_NEXT).setUrl("http://localhost:" + ourPort + "/fhir/next"); ca.uhn.fhir.model.dstu2.resource.Bundle resp = client - .loadPage() - .next(sourceBundle) - .execute(); + .loadPage() + .next(sourceBundle) + .execute(); assertEquals(1, resp.getEntry().size()); assertEquals("http://localhost:" + ourPort + "/fhir/next", ourRequestUri); @@ -1111,9 +1090,9 @@ public class GenericOkHttpClientDstu2Test { sourceBundle.getLinkOrCreate("previous").setUrl("http://localhost:" + ourPort + "/fhir/prev"); ca.uhn.fhir.model.dstu2.resource.Bundle resp = client - .loadPage() - .previous(sourceBundle) - .execute(); + .loadPage() + .previous(sourceBundle) + .execute(); assertEquals(1, resp.getEntry().size()); assertEquals("http://localhost:" + ourPort + "/fhir/prev", ourRequestUri); @@ -1126,9 +1105,9 @@ public class GenericOkHttpClientDstu2Test { sourceBundle.getLinkOrCreate("prev").setUrl("http://localhost:" + ourPort + "/fhir/prev"); resp = client - .loadPage() - .previous(sourceBundle) - .execute(); + .loadPage() + .previous(sourceBundle) + .execute(); assertEquals(1, resp.getEntry().size()); assertEquals("http://localhost:" + ourPort + "/fhir/prev", ourRequestUri); @@ -1174,18 +1153,18 @@ public class GenericOkHttpClientDstu2Test { public void testReadUpdatedHeaderDoesntOverwriteResourceValue() throws Exception { final String input = "\n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - ""; + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + ""; ourResponseContentType = Constants.CT_FHIR_XML + "; charset=UTF-8"; ourResponseBody = input; @@ -1195,10 +1174,10 @@ public class GenericOkHttpClientDstu2Test { ca.uhn.fhir.model.dstu2.resource.Bundle response; response = client - .search() - .forResource(Patient.class) - .returnBundle(ca.uhn.fhir.model.dstu2.resource.Bundle.class) - .execute(); + .search() + .forResource(Patient.class) + .returnBundle(ca.uhn.fhir.model.dstu2.resource.Bundle.class) + .execute(); assertEquals("2015-06-22T15:48:57.554-04:00", ResourceMetadataKeyEnum.UPDATED.get(response).getValueAsString()); } @@ -1213,13 +1192,13 @@ public class GenericOkHttpClientDstu2Test { IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort + "/fhir"); IBaseResource response = client.read() - .resource("Patient") - .withId("123") - .elementsSubset("name", "identifier") - .execute(); + .resource("Patient") + .withId("123") + .elementsSubset("name", "identifier") + .execute(); assertThat(ourRequestUri, either(equalTo("http://localhost:" + ourPort + "/fhir/Patient/123?_elements=name%2Cidentifier")) - .or(equalTo("http://localhost:" + ourPort + "/fhir/Patient/123?_elements=identifier%2Cname"))); + .or(equalTo("http://localhost:" + ourPort + "/fhir/Patient/123?_elements=identifier%2Cname"))); assertEquals(Patient.class, response.getClass()); } @@ -1234,10 +1213,10 @@ public class GenericOkHttpClientDstu2Test { try { client.read() - .resource(Patient.class) - .withId("123") - .summaryMode(SummaryEnum.TEXT) - .execute(); + .resource(Patient.class) + .withId("123") + .summaryMode(SummaryEnum.TEXT) + .execute(); fail(); } catch (InvalidResponseException e) { assertThat(e.getMessage(), containsString("String does not appear to be valid")); @@ -1255,10 +1234,10 @@ public class GenericOkHttpClientDstu2Test { IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort + "/fhir"); Patient response = client.read() - .resource(Patient.class) - .withId("123") - .summaryMode(SummaryEnum.TEXT) - .execute(); + .resource(Patient.class) + .withId("123") + .summaryMode(SummaryEnum.TEXT) + .execute(); assertEquals("http://localhost:" + ourPort + "/fhir/Patient/123?_summary=text", ourRequestUri); assertEquals(Patient.class, response.getClass()); @@ -1275,10 +1254,10 @@ public class GenericOkHttpClientDstu2Test { IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort + "/fhir"); Bundle response = client.search() - .forResource("Patient") - .where(Patient.NAME.matches().value("james")) - .returnBundle(Bundle.class) - .execute(); + .forResource("Patient") + .where(Patient.NAME.matches().value("james")) + .returnBundle(Bundle.class) + .execute(); assertEquals("http://localhost:" + ourPort + "/fhir/Patient?name=james", ourRequestUri); assertEquals(Patient.class, response.getEntry().get(0).getResource().getClass()); @@ -1294,44 +1273,44 @@ public class GenericOkHttpClientDstu2Test { IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort + "/fhir"); ca.uhn.fhir.model.dstu2.resource.Bundle response = client.search() - .byUrl("http://localhost:" + ourPort + "/AAA?name=http://foo|bar") - .encodedJson() - .returnBundle(ca.uhn.fhir.model.dstu2.resource.Bundle.class) - .execute(); + .byUrl("http://localhost:" + ourPort + "/AAA?name=http://foo|bar") + .encodedJson() + .returnBundle(ca.uhn.fhir.model.dstu2.resource.Bundle.class) + .execute(); assertEquals("http://localhost:" + ourPort + "/AAA?name=http%3A//foo%7Cbar&_format=json", ourRequestUri); assertNotNull(response); response = client.search() - .byUrl("Patient?name=http://foo|bar") - .encodedJson() - .returnBundle(ca.uhn.fhir.model.dstu2.resource.Bundle.class) - .execute(); + .byUrl("Patient?name=http://foo|bar") + .encodedJson() + .returnBundle(ca.uhn.fhir.model.dstu2.resource.Bundle.class) + .execute(); assertEquals("http://localhost:" + ourPort + "/fhir/Patient?name=http%3A//foo%7Cbar&_format=json", ourRequestUri); assertNotNull(response); response = client.search() - .byUrl("/Patient?name=http://foo|bar") - .encodedJson() - .returnBundle(ca.uhn.fhir.model.dstu2.resource.Bundle.class) - .execute(); + .byUrl("/Patient?name=http://foo|bar") + .encodedJson() + .returnBundle(ca.uhn.fhir.model.dstu2.resource.Bundle.class) + .execute(); assertEquals("http://localhost:" + ourPort + "/fhir/Patient?name=http%3A//foo%7Cbar&_format=json", ourRequestUri); assertNotNull(response); response = client.search() - .byUrl("Patient") - .returnBundle(ca.uhn.fhir.model.dstu2.resource.Bundle.class) - .execute(); + .byUrl("Patient") + .returnBundle(ca.uhn.fhir.model.dstu2.resource.Bundle.class) + .execute(); assertEquals("http://localhost:" + ourPort + "/fhir/Patient", ourRequestUri); assertNotNull(response); response = client.search() - .byUrl("Patient?") - .returnBundle(ca.uhn.fhir.model.dstu2.resource.Bundle.class) - .execute(); + .byUrl("Patient?") + .returnBundle(ca.uhn.fhir.model.dstu2.resource.Bundle.class) + .execute(); assertEquals("http://localhost:" + ourPort + "/fhir/Patient", ourRequestUri); assertNotNull(response); @@ -1356,10 +1335,10 @@ public class GenericOkHttpClientDstu2Test { IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort + "/fhir"); ca.uhn.fhir.model.dstu2.resource.Bundle response = client.search() - .forResource("Observation") - .where(Patient.NAME.matches().value("FOO")) - .returnBundle(ca.uhn.fhir.model.dstu2.resource.Bundle.class) - .execute(); + .forResource("Observation") + .where(Patient.NAME.matches().value("FOO")) + .returnBundle(ca.uhn.fhir.model.dstu2.resource.Bundle.class) + .execute(); Link link = response.getLink().get(0); assertEquals("just trying add link", link.getRelation()); @@ -1381,14 +1360,14 @@ public class GenericOkHttpClientDstu2Test { IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort + "/fhir"); Bundle response = client.search() - .forResource("Patient") - .where(Patient.NAME.matches().value("james")) - .elementsSubset("name", "identifier") - .returnBundle(Bundle.class) - .execute(); + .forResource("Patient") + .where(Patient.NAME.matches().value("james")) + .elementsSubset("name", "identifier") + .returnBundle(Bundle.class) + .execute(); assertThat(ourRequestUri, either(equalTo("http://localhost:" + ourPort + "/fhir/Patient?name=james&_elements=name%2Cidentifier")) - .or(equalTo("http://localhost:" + ourPort + "/fhir/Patient?name=james&_elements=identifier%2Cname"))); + .or(equalTo("http://localhost:" + ourPort + "/fhir/Patient?name=james&_elements=identifier%2Cname"))); assertEquals(Patient.class, response.getEntry().get(0).getResource().getClass()); } @@ -1402,12 +1381,12 @@ public class GenericOkHttpClientDstu2Test { IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort + "/fhir"); Bundle response = client.search() - .forResource("Patient") - .where(Patient.NAME.matches().value("james")) - .elementsSubset("name", "identifier") - .usingStyle(SearchStyleEnum.POST) - .returnBundle(Bundle.class) - .execute(); + .forResource("Patient") + .where(Patient.NAME.matches().value("james")) + .elementsSubset("name", "identifier") + .usingStyle(SearchStyleEnum.POST) + .returnBundle(Bundle.class) + .execute(); assertEquals("http://localhost:" + ourPort + "/fhir/Patient/_search?_elements=identifier%2Cname", ourRequestUri); @@ -1434,13 +1413,13 @@ public class GenericOkHttpClientDstu2Test { IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort + "/fhir"); Bundle response = client.search() - .forResource("Patient") - .where(Patient.NAME.matches().value("james")) - .elementsSubset("name", "identifier") - .usingStyle(SearchStyleEnum.POST) - .encodedJson() - .returnBundle(Bundle.class) - .execute(); + .forResource("Patient") + .where(Patient.NAME.matches().value("james")) + .elementsSubset("name", "identifier") + .usingStyle(SearchStyleEnum.POST) + .encodedJson() + .returnBundle(Bundle.class) + .execute(); assertThat(ourRequestUri, containsString("http://localhost:" + ourPort + "/fhir/Patient/_search?")); assertThat(ourRequestUri, containsString("_elements=identifier%2Cname")); @@ -1468,11 +1447,11 @@ public class GenericOkHttpClientDstu2Test { IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort + "/fhir"); Bundle response = client.search() - .forResource("Patient") - .where(Patient.NAME.matches().value("james")) - .lastUpdated(new DateRangeParam("2011-01-01", "2012-01-01")) - .returnBundle(Bundle.class) - .execute(); + .forResource("Patient") + .where(Patient.NAME.matches().value("james")) + .lastUpdated(new DateRangeParam("2011-01-01", "2012-01-01")) + .returnBundle(Bundle.class) + .execute(); assertEquals("http://localhost:" + ourPort + "/fhir/Patient?name=james&_lastUpdated=ge2011-01-01&_lastUpdated=le2012-01-01", ourRequestUri); assertEquals(Patient.class, response.getEntry().get(0).getResource().getClass()); @@ -1488,13 +1467,13 @@ public class GenericOkHttpClientDstu2Test { IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort + "/fhir"); Bundle response = client.search() - .forResource("Patient") - .withProfile("http://foo1") - .withProfile("http://foo2") - .withSecurity("system1", "code1") - .withSecurity("system2", "code2") - .returnBundle(Bundle.class) - .execute(); + .forResource("Patient") + .withProfile("http://foo1") + .withProfile("http://foo2") + .withSecurity("system1", "code1") + .withSecurity("system2", "code2") + .returnBundle(Bundle.class) + .execute(); assertEquals("http://localhost:" + ourPort + "/fhir/Patient?_security=system1%7Ccode1&_security=system2%7Ccode2&_profile=http%3A%2F%2Ffoo1&_profile=http%3A%2F%2Ffoo2", ourRequestUri); assertEquals(Patient.class, response.getEntry().get(0).getResource().getClass()); @@ -1511,11 +1490,11 @@ public class GenericOkHttpClientDstu2Test { IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort + "/fhir"); Bundle response = client.search() - .forResource(Patient.class) - .encodedJson() - .revInclude(new Include("Provenance:target")) - .returnBundle(Bundle.class) - .execute(); + .forResource(Patient.class) + .encodedJson() + .revInclude(new Include("Provenance:target")) + .returnBundle(Bundle.class) + .execute(); assertEquals("http://localhost:" + ourPort + "/fhir/Patient?_revinclude=Provenance%3Atarget&_format=json", ourRequestUri); } @@ -1530,11 +1509,11 @@ public class GenericOkHttpClientDstu2Test { IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort + "/fhir"); Bundle response = client.search() - .forResource("Patient") - .where(Patient.NAME.matches().value("james")) - .summaryMode(SummaryEnum.FALSE) - .returnBundle(Bundle.class) - .execute(); + .forResource("Patient") + .where(Patient.NAME.matches().value("james")) + .summaryMode(SummaryEnum.FALSE) + .returnBundle(Bundle.class) + .execute(); assertEquals("http://localhost:" + ourPort + "/fhir/Patient?name=james&_summary=false", ourRequestUri); assertEquals(Patient.class, response.getEntry().get(0).getResource().getClass()); @@ -1561,17 +1540,17 @@ public class GenericOkHttpClientDstu2Test { IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort + "/fhir"); String response = client.transaction() - .withBundle(reqString) - .execute(); + .withBundle(reqString) + .execute(); assertEquals("http://localhost:" + ourPort + "/fhir/", ourRequestUri); assertThat(response, containsString("\"Bundle\"")); assertContentTypeEquals("application/json+fhir; charset=UTF-8"); response = client.transaction() - .withBundle(reqString) - .encodedXml() - .execute(); + .withBundle(reqString) + .encodedXml() + .execute(); assertEquals("http://localhost:" + ourPort + "/fhir/", ourRequestUri); assertContentTypeEquals("application/xml+fhir; charset=UTF-8"); @@ -1601,9 +1580,9 @@ public class GenericOkHttpClientDstu2Test { input.addEntry().setResource(p2); ca.uhn.fhir.model.dstu2.resource.Bundle response = client.transaction() - .withBundle(input) - .encodedJson() - .execute(); + .withBundle(input) + .encodedJson() + .execute(); assertEquals("http://localhost:" + ourPort + "/fhir", ourRequestUri); assertEquals(2, response.getEntry().size()); @@ -1748,8 +1727,8 @@ public class GenericOkHttpClientDstu2Test { assertEquals("http://localhost:" + ourPort + "/fhir/Patient/$validate", ourRequestUri); assertEquals("POST", ourRequestMethod); assertEquals( - "", - ourRequestBodyString); + "", + ourRequestBodyString); assertNotNull(response.getOperationOutcome()); assertEquals("FOOBAR", toOo(response.getOperationOutcome()).getIssueFirstRep().getDiagnosticsElement().getValue()); @@ -1757,8 +1736,8 @@ public class GenericOkHttpClientDstu2Test { assertEquals("http://localhost:" + ourPort + "/fhir/Patient/$validate", ourRequestUri); assertEquals("POST", ourRequestMethod); assertEquals( - "", - ourRequestBodyString); + "", + ourRequestBodyString); assertNotNull(response.getOperationOutcome()); assertEquals("FOOBAR", toOo(response.getOperationOutcome()).getIssueFirstRep().getDiagnosticsElement().getValue()); @@ -1799,8 +1778,8 @@ public class GenericOkHttpClientDstu2Test { assertEquals("http://localhost:" + ourPort + "/fhir/Patient/$validate?_format=xml", ourRequestUri); assertEquals("POST", ourRequestMethod); assertEquals( - "", - ourRequestBodyString); + "", + ourRequestBodyString); assertNotNull(response.getOperationOutcome()); assertEquals("FOOBAR", toOo(response.getOperationOutcome()).getIssueFirstRep().getDiagnosticsElement().getValue()); } @@ -1809,7 +1788,7 @@ public class GenericOkHttpClientDstu2Test { return (OperationOutcome) theOperationOutcome; } - @Before + @BeforeEach public void beforeReset() { ourRequestUri = null; ourRequestUriAll = Lists.newArrayList(); @@ -1827,4 +1806,59 @@ public class GenericOkHttpClientDstu2Test { ourRequestMethod = null; ourRequestHeadersAll = Lists.newArrayList(); } + + @BeforeAll + public static void beforeClass() throws Exception { + ourCtx = FhirContext.forDstu2(); + + ourServer = new Server(0); + ourServer.setHandler(new AbstractHandler() { + + @Override + public void handle(String theArg0, Request theRequest, HttpServletRequest theServletRequest, HttpServletResponse theResp) throws IOException, ServletException { + theRequest.setHandled(true); + ourRequestUri = "http:" + theRequest.getHttpURI().toString(); + ourRequestUriAll.add(ourRequestUri); + ourRequestMethod = theRequest.getMethod(); + ourRequestContentType = theServletRequest.getContentType(); + ourRequestBodyBytes = IOUtils.toByteArray(theServletRequest.getInputStream()); + ourRequestBodyString = new String(ourRequestBodyBytes, Charsets.UTF_8); + + ourRequestHeaders = ArrayListMultimap.create(); + ourRequestHeadersAll.add(ourRequestHeaders); + ourRequestFirstHeaders = Maps.newHashMap(); + + for (Enumeration headerNameEnum = theRequest.getHeaderNames(); headerNameEnum.hasMoreElements(); ) { + String nextName = headerNameEnum.nextElement(); + for (Enumeration headerValueEnum = theRequest.getHeaders(nextName); headerValueEnum.hasMoreElements(); ) { + String nextValue = headerValueEnum.nextElement(); + if (ourRequestFirstHeaders.containsKey(nextName) == false) { + ourRequestFirstHeaders.put(nextName, new Header(nextName, nextValue)); + } + ourRequestHeaders.put(nextName, new Header(nextName, nextValue)); + } + } + + theResp.setStatus(ourResponseStatus); + + if (ourResponseBody != null) { + theResp.setContentType(ourResponseContentType); + theResp.getWriter().write(ourResponseBody); + } else if (ourResponseBodies != null) { + theResp.setContentType(ourResponseContentType); + theResp.getWriter().write(ourResponseBodies[ourResponseCount]); + } + + ourResponseCount++; + } + }); + + JettyUtil.startServer(ourServer); + ourPort = JettyUtil.getPortForStartedServer(ourServer); + } + + @AfterAll + public static void afterClass() throws Exception { + JettyUtil.closeServer(ourServer); + } } diff --git a/hapi-fhir-client-okhttp/src/test/java/ca/uhn/fhir/okhttp/OkHttpRestfulClientFactoryTest.java b/hapi-fhir-client-okhttp/src/test/java/ca/uhn/fhir/okhttp/OkHttpRestfulClientFactoryTest.java index cb9cd08c15d..88368bad910 100644 --- a/hapi-fhir-client-okhttp/src/test/java/ca/uhn/fhir/okhttp/OkHttpRestfulClientFactoryTest.java +++ b/hapi-fhir-client-okhttp/src/test/java/ca/uhn/fhir/okhttp/OkHttpRestfulClientFactoryTest.java @@ -3,18 +3,18 @@ package ca.uhn.fhir.okhttp; import ca.uhn.fhir.okhttp.client.OkHttpRestfulClientFactory; import okhttp3.Call; import okhttp3.OkHttpClient; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.util.concurrent.TimeUnit; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; public class OkHttpRestfulClientFactoryTest { private OkHttpRestfulClientFactory clientFactory; - @Before + @BeforeEach public void setUp() { clientFactory = new OkHttpRestfulClientFactory(); } diff --git a/hapi-fhir-client-okhttp/src/test/java/ca/uhn/fhir/okhttp/client/OkHttpRestfulClientTest.java b/hapi-fhir-client-okhttp/src/test/java/ca/uhn/fhir/okhttp/client/OkHttpRestfulClientTest.java index ff147f57e3b..c2ad3d4a979 100644 --- a/hapi-fhir-client-okhttp/src/test/java/ca/uhn/fhir/okhttp/client/OkHttpRestfulClientTest.java +++ b/hapi-fhir-client-okhttp/src/test/java/ca/uhn/fhir/okhttp/client/OkHttpRestfulClientTest.java @@ -1,9 +1,9 @@ package ca.uhn.fhir.okhttp.client; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.hamcrest.Matchers.equalTo; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; public class OkHttpRestfulClientTest { @@ -21,4 +21,4 @@ public class OkHttpRestfulClientTest { assertThat(headerBuilder.toString(), equalTo("http://example.com")); } -} \ No newline at end of file +} diff --git a/hapi-fhir-client/src/test/java/ca/uhn/fhir/rest/client/apache/ApacheHttpRequestTest.java b/hapi-fhir-client/src/test/java/ca/uhn/fhir/rest/client/apache/ApacheHttpRequestTest.java index 960d76daba8..285a6d621f3 100644 --- a/hapi-fhir-client/src/test/java/ca/uhn/fhir/rest/client/apache/ApacheHttpRequestTest.java +++ b/hapi-fhir-client/src/test/java/ca/uhn/fhir/rest/client/apache/ApacheHttpRequestTest.java @@ -1,10 +1,10 @@ package ca.uhn.fhir.rest.client.apache; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import org.apache.http.client.methods.HttpPost; import org.apache.http.entity.StringEntity; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.IOException; import java.nio.charset.Charset; diff --git a/hapi-fhir-client/src/test/java/ca/uhn/fhir/rest/client/interceptor/SimpleRequestHeaderInterceptorTest.java b/hapi-fhir-client/src/test/java/ca/uhn/fhir/rest/client/interceptor/SimpleRequestHeaderInterceptorTest.java index a4fe8bb27c7..44eb8949514 100644 --- a/hapi-fhir-client/src/test/java/ca/uhn/fhir/rest/client/interceptor/SimpleRequestHeaderInterceptorTest.java +++ b/hapi-fhir-client/src/test/java/ca/uhn/fhir/rest/client/interceptor/SimpleRequestHeaderInterceptorTest.java @@ -1,8 +1,8 @@ package ca.uhn.fhir.rest.client.interceptor; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public class SimpleRequestHeaderInterceptorTest { @Test diff --git a/hapi-fhir-converter/src/test/java/ca/uhn/hapi/converters/server/VersionedApiConverterInterceptorR4Test.java b/hapi-fhir-converter/src/test/java/ca/uhn/hapi/converters/server/VersionedApiConverterInterceptorR4Test.java index 800bf3eb9b8..02e68aeafa1 100644 --- a/hapi-fhir-converter/src/test/java/ca/uhn/hapi/converters/server/VersionedApiConverterInterceptorR4Test.java +++ b/hapi-fhir-converter/src/test/java/ca/uhn/hapi/converters/server/VersionedApiConverterInterceptorR4Test.java @@ -5,6 +5,7 @@ import ca.uhn.fhir.rest.annotation.Search; import ca.uhn.fhir.rest.api.EncodingEnum; import ca.uhn.fhir.rest.server.IResourceProvider; import ca.uhn.fhir.rest.server.RestfulServer; +import ca.uhn.fhir.test.utilities.JettyUtil; import ca.uhn.fhir.util.TestUtil; import ca.uhn.fhir.util.UrlUtil; import org.apache.commons.io.IOUtils; @@ -19,9 +20,9 @@ import org.eclipse.jetty.servlet.ServletHolder; 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.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import java.nio.charset.StandardCharsets; import java.util.ArrayList; @@ -31,8 +32,6 @@ import java.util.concurrent.TimeUnit; import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.MatcherAssert.assertThat; -import ca.uhn.fhir.test.utilities.JettyUtil; - public class VersionedApiConverterInterceptorR4Test { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(VersionedApiConverterInterceptorR4Test.class); @@ -74,13 +73,13 @@ public class VersionedApiConverterInterceptorR4Test { } } - @AfterClass + @AfterAll public static void afterClassClearContext() throws Exception { JettyUtil.closeServer(ourServer); TestUtil.clearAllStaticFieldsForUnitTest(); } - @BeforeClass + @BeforeAll public static void beforeClass() throws Exception { ourServer = new Server(0); diff --git a/hapi-fhir-converter/src/test/java/org/hl7/fhir/converter/VersionConvertor_10_30Test.java b/hapi-fhir-converter/src/test/java/org/hl7/fhir/converter/VersionConvertor_10_30Test.java index a63a0d86344..d03a6f73173 100644 --- a/hapi-fhir-converter/src/test/java/org/hl7/fhir/converter/VersionConvertor_10_30Test.java +++ b/hapi-fhir-converter/src/test/java/org/hl7/fhir/converter/VersionConvertor_10_30Test.java @@ -1,12 +1,12 @@ package org.hl7.fhir.converter; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import org.hl7.fhir.convertors.VersionConvertor_10_30; import org.hl7.fhir.dstu3.model.*; import org.hl7.fhir.exceptions.FHIRException; import org.hl7.fhir.dstu2.model.Resource; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.Collections; import java.util.Date; diff --git a/hapi-fhir-converter/src/test/java/org/hl7/fhir/converter/VersionConvertor_14_30Test.java b/hapi-fhir-converter/src/test/java/org/hl7/fhir/converter/VersionConvertor_14_30Test.java index 8914d474e01..f896e422830 100644 --- a/hapi-fhir-converter/src/test/java/org/hl7/fhir/converter/VersionConvertor_14_30Test.java +++ b/hapi-fhir-converter/src/test/java/org/hl7/fhir/converter/VersionConvertor_14_30Test.java @@ -1,11 +1,11 @@ package org.hl7.fhir.converter; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import org.hl7.fhir.convertors.VersionConvertor_14_30; import org.hl7.fhir.dstu3.model.Questionnaire; import org.hl7.fhir.exceptions.FHIRException; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class VersionConvertor_14_30Test { diff --git a/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/5_1_0/1952-migrate-to-junit5.yaml b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/5_1_0/1952-migrate-to-junit5.yaml new file mode 100644 index 00000000000..07bd87ff9fa --- /dev/null +++ b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/5_1_0/1952-migrate-to-junit5.yaml @@ -0,0 +1,5 @@ +--- +type: change +issue: 1952 +title: HAPI FHIR has been migrated to use JUnit 5 (from JUnit 4) for unit testing. This change does not affect users of the + library, but helps to make tests more maintainable. diff --git a/hapi-fhir-igpacks/src/test/java/ca/uhn/fhir/igpack/parser/IgPackParserDstu3Test.java b/hapi-fhir-igpacks/src/test/java/ca/uhn/fhir/igpack/parser/IgPackParserDstu3Test.java index 1f6588d5c29..84b263dafe3 100644 --- a/hapi-fhir-igpacks/src/test/java/ca/uhn/fhir/igpack/parser/IgPackParserDstu3Test.java +++ b/hapi-fhir-igpacks/src/test/java/ca/uhn/fhir/igpack/parser/IgPackParserDstu3Test.java @@ -5,12 +5,12 @@ import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.support.IValidationSupport; import ca.uhn.fhir.igpacks.parser.IgPackParserDstu3; import org.hl7.fhir.dstu3.model.ValueSet; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; public class IgPackParserDstu3Test { private static final Logger ourLog = LoggerFactory.getLogger(IgPackParserDstu3Test.class); diff --git a/hapi-fhir-jaxrsserver-base/pom.xml b/hapi-fhir-jaxrsserver-base/pom.xml index dcb55ac919b..ade618da234 100644 --- a/hapi-fhir-jaxrsserver-base/pom.xml +++ b/hapi-fhir-jaxrsserver-base/pom.xml @@ -162,7 +162,7 @@ test - + diff --git a/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/client/GenericJaxRsClientDstu2Test.java b/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/client/GenericJaxRsClientDstu2Test.java index 62d057015b6..d4275bd66f4 100644 --- a/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/client/GenericJaxRsClientDstu2Test.java +++ b/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/client/GenericJaxRsClientDstu2Test.java @@ -1,81 +1,122 @@ package ca.uhn.fhir.jaxrs.client; -import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; - -import java.io.IOException; -import java.util.*; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.apache.commons.io.Charsets; -import org.apache.commons.io.IOUtils; -import org.eclipse.jetty.server.Request; -import org.eclipse.jetty.server.Server; -import org.eclipse.jetty.server.handler.AbstractHandler; -import org.hl7.fhir.instance.model.api.*; -import org.junit.*; -import org.junit.Test; - -import com.google.common.collect.*; - import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.api.Include; import ca.uhn.fhir.model.api.ResourceMetadataKeyEnum; import ca.uhn.fhir.model.dstu2.composite.IdentifierDt; import ca.uhn.fhir.model.dstu2.composite.MetaDt; -import ca.uhn.fhir.model.dstu2.resource.*; +import ca.uhn.fhir.model.dstu2.resource.Bundle; import ca.uhn.fhir.model.dstu2.resource.Bundle.Entry; import ca.uhn.fhir.model.dstu2.resource.Bundle.Link; -import ca.uhn.fhir.model.primitive.*; +import ca.uhn.fhir.model.dstu2.resource.Conformance; +import ca.uhn.fhir.model.dstu2.resource.Observation; +import ca.uhn.fhir.model.dstu2.resource.OperationOutcome; +import ca.uhn.fhir.model.dstu2.resource.Parameters; +import ca.uhn.fhir.model.dstu2.resource.Patient; +import ca.uhn.fhir.model.primitive.CodeDt; +import ca.uhn.fhir.model.primitive.DateDt; +import ca.uhn.fhir.model.primitive.IdDt; +import ca.uhn.fhir.model.primitive.InstantDt; +import ca.uhn.fhir.model.primitive.StringDt; +import ca.uhn.fhir.model.primitive.UriDt; import ca.uhn.fhir.parser.IParser; -import ca.uhn.fhir.rest.api.*; -import ca.uhn.fhir.rest.client.api.*; +import ca.uhn.fhir.rest.api.Constants; +import ca.uhn.fhir.rest.api.EncodingEnum; +import ca.uhn.fhir.rest.api.MethodOutcome; +import ca.uhn.fhir.rest.api.PreferReturnEnum; +import ca.uhn.fhir.rest.api.SearchStyleEnum; +import ca.uhn.fhir.rest.api.SummaryEnum; +import ca.uhn.fhir.rest.client.api.Header; +import ca.uhn.fhir.rest.client.api.IGenericClient; +import ca.uhn.fhir.rest.client.api.ServerValidationModeEnum; import ca.uhn.fhir.rest.client.exceptions.InvalidResponseException; import ca.uhn.fhir.rest.client.interceptor.LoggingInterceptor; import ca.uhn.fhir.rest.param.DateRangeParam; import ca.uhn.fhir.test.utilities.JettyUtil; +import com.google.common.collect.ArrayListMultimap; +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; +import org.apache.commons.io.Charsets; +import org.apache.commons.io.IOUtils; +import org.eclipse.jetty.server.Request; +import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.server.handler.AbstractHandler; +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.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Date; +import java.util.Enumeration; +import java.util.List; +import java.util.Map; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.either; +import static org.hamcrest.Matchers.emptyString; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.not; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.fail; public class GenericJaxRsClientDstu2Test { + private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(GenericJaxRsClientDstu2Test.class); private static FhirContext ourCtx; private static int ourPort; private static Server ourServer; - private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(GenericJaxRsClientDstu2Test.class); private static int ourResponseCount = 0; private static String[] ourResponseBodies; private static String ourResponseBody; private static String ourResponseContentType; private static int ourResponseStatus; private static String ourRequestUri; - - @Before + private static List ourRequestUriAll; + private static String ourRequestMethod; + private static String ourRequestContentType; + private static byte[] ourRequestBodyBytes; + private static String ourRequestBodyString; + private static ArrayListMultimap ourRequestHeaders; + private static List> ourRequestHeadersAll; + private static Map ourRequestFirstHeaders; + + @BeforeEach public void before() { JaxRsRestfulClientFactory clientFactory = new JaxRsRestfulClientFactory(ourCtx); clientFactory.setServerValidationMode(ServerValidationModeEnum.NEVER); - + ourCtx.setRestfulClientFactory(clientFactory); ourResponseCount = 0; } private String getPatientFeedWithOneResult() { - - String msg = "\n" + - "d039f91a-cc3c-4013-988e-af4d8d0614bd\n" + - "\n" + - "" - + "" - + "
John Cardinal: 444333333
" - + "" - + "" - + "" - + "" - + "
" - + "
" - + "
\n" - + "
\n" - + "
"; - + + String msg = "\n" + + "d039f91a-cc3c-4013-988e-af4d8d0614bd\n" + + "\n" + + "" + + "" + + "
John Cardinal: 444333333
" + + "" + + "" + + "" + + "" + + "
" + + "
" + + "
\n" + + "
\n" + + "
"; + return msg; } @@ -89,28 +130,27 @@ public class GenericJaxRsClientDstu2Test { final String respString = p.encodeResourceToString(conf); ourResponseContentType = Constants.CT_FHIR_XML + "; charset=UTF-8"; ourResponseBody = respString; - + IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort + "/fhir"); - client.fetchConformance().ofType(Conformance.class).execute(); assertEquals("http://localhost:" + ourPort + "/fhir/metadata", ourRequestUri); assertEquals(1, ourRequestHeaders.get("Accept").size()); assertThat(ourRequestHeaders.get("Accept").get(0).getValue(), containsString(Constants.HEADER_ACCEPT_VALUE_XML_OR_JSON_LEGACY)); - + client.fetchConformance().ofType(Conformance.class).encodedJson().execute(); assertEquals("http://localhost:" + ourPort + "/fhir/metadata?_format=json", ourRequestUri); assertEquals(1, ourRequestHeaders.get("Accept").size()); assertThat(ourRequestHeaders.get("Accept").get(0).getValue(), containsString(Constants.CT_FHIR_JSON)); - + client.fetchConformance().ofType(Conformance.class).encodedXml().execute(); assertEquals("http://localhost:" + ourPort + "/fhir/metadata?_format=xml", ourRequestUri); assertEquals(1, ourRequestHeaders.get("Accept").size()); assertThat(ourRequestHeaders.get("Accept").get(0).getValue(), containsString(Constants.CT_FHIR_XML)); - + } @Test @@ -124,7 +164,7 @@ public class GenericJaxRsClientDstu2Test { patient.addName().addFamily("FAMILY"); ourResponseContentType = Constants.CT_FHIR_XML + "; charset=UTF-8"; - ourResponseBodies = new String[] { p.encodeResourceToString(conf), p.encodeResourceToString(patient) }; + ourResponseBodies = new String[]{p.encodeResourceToString(conf), p.encodeResourceToString(patient)}; ourCtx.getRestfulClientFactory().setServerValidationMode(ServerValidationModeEnum.ONCE); IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort + "/fhir"); @@ -154,7 +194,7 @@ public class GenericJaxRsClientDstu2Test { patient.addName().addFamily("FAMILY"); ourResponseContentType = Constants.CT_FHIR_XML + "; charset=UTF-8"; - ourResponseBodies = new String[] { p.encodeResourceToString(conf), p.encodeResourceToString(patient) }; + ourResponseBodies = new String[]{p.encodeResourceToString(conf), p.encodeResourceToString(patient)}; ourCtx.getRestfulClientFactory().setServerValidationMode(ServerValidationModeEnum.ONCE); IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort + "/fhir"); @@ -181,7 +221,7 @@ public class GenericJaxRsClientDstu2Test { conf.setCopyright("COPY"); final String respString = p.encodeResourceToString(conf); - + ourResponseContentType = Constants.CT_FHIR_XML + "; charset=UTF-8"; ourResponseBody = respString; @@ -192,7 +232,7 @@ public class GenericJaxRsClientDstu2Test { assertEquals("http://localhost:" + ourPort + "/fhir/metadata", ourRequestUri); assertEquals("COPY", resp.getCopyright()); assertEquals("GET", ourRequestMethod); - + } @@ -200,7 +240,7 @@ public class GenericJaxRsClientDstu2Test { public void testProviderWhereWeForgotToSetTheContext() { JaxRsRestfulClientFactory clientFactory = new JaxRsRestfulClientFactory(); // no ctx clientFactory.setServerValidationMode(ServerValidationModeEnum.NEVER); - + ourCtx.setRestfulClientFactory(clientFactory); try { @@ -210,13 +250,11 @@ public class GenericJaxRsClientDstu2Test { assertEquals("JaxRsRestfulClientFactory does not have FhirContext defined. This must be set via JaxRsRestfulClientFactory#setFhirContext(FhirContext)", e.getMessage()); } } - - + @Test public void testCreate() { IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort + "/fhir"); - Patient p = new Patient(); p.addName().addFamily("FOOFAMILY"); @@ -228,7 +266,7 @@ public class GenericJaxRsClientDstu2Test { assertThat(ourRequestBodyString, containsString("")); assertEquals("http://localhost:" + ourPort + "/fhir/Patient", ourRequestUri); assertEquals("POST", ourRequestMethod); - + p.setId("123"); @@ -240,19 +278,18 @@ public class GenericJaxRsClientDstu2Test { assertThat(body, not(containsString("123"))); assertEquals("http://localhost:" + ourPort + "/fhir/Patient", ourRequestUri); assertEquals("POST", ourRequestMethod); - + } @Test public void testCreateConditional() { - - + + ourResponseStatus = Constants.STATUS_HTTP_204_NO_CONTENT; IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort + "/fhir"); - Patient p = new Patient(); p.addName().addFamily("FOOFAMILY"); @@ -264,7 +301,7 @@ public class GenericJaxRsClientDstu2Test { assertEquals("http://localhost:" + ourPort + "/fhir/Patient", ourRequestUri); assertEquals("http://localhost:" + ourPort + "/fhir/Patient?name=foo", ourRequestFirstHeaders.get(Constants.HEADER_IF_NONE_EXIST).getValue()); assertEquals("POST", ourRequestMethod); - + client.create().resource(p).conditionalByUrl("Patient?name=http://foo|bar").encodedXml().execute(); assertEquals(1, ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE).size()); @@ -273,7 +310,7 @@ public class GenericJaxRsClientDstu2Test { assertEquals("http://localhost:" + ourPort + "/fhir/Patient", ourRequestUri); assertEquals("http://localhost:" + ourPort + "/fhir/Patient?name=http%3A//foo%7Cbar", ourRequestFirstHeaders.get(Constants.HEADER_IF_NONE_EXIST).getValue()); assertEquals("POST", ourRequestMethod); - + client.create().resource(p).conditional().where(Patient.NAME.matches().value("foo")).encodedXml().execute(); assertEquals(1, ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE).size()); @@ -282,21 +319,18 @@ public class GenericJaxRsClientDstu2Test { assertEquals("http://localhost:" + ourPort + "/fhir/Patient", ourRequestUri); assertEquals("http://localhost:" + ourPort + "/fhir/Patient?name=foo", ourRequestFirstHeaders.get(Constants.HEADER_IF_NONE_EXIST).getValue()); assertEquals("POST", ourRequestMethod); - + } - - @Test public void testCreatePrefer() { - - + + ourResponseStatus = Constants.STATUS_HTTP_204_NO_CONTENT; IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort + "/fhir"); - Patient p = new Patient(); p.addName().addFamily("FOOFAMILY"); @@ -304,12 +338,12 @@ public class GenericJaxRsClientDstu2Test { client.create().resource(p).prefer(PreferReturnEnum.MINIMAL).execute(); assertEquals(1, ourRequestHeaders.get(Constants.HEADER_PREFER).size()); assertEquals(Constants.HEADER_PREFER_RETURN + '=' + Constants.HEADER_PREFER_RETURN_MINIMAL, ourRequestHeaders.get(Constants.HEADER_PREFER).get(0).getValue()); - + client.create().resource(p).prefer(PreferReturnEnum.REPRESENTATION).execute(); assertEquals(1, ourRequestHeaders.get(Constants.HEADER_PREFER).size()); assertEquals(Constants.HEADER_PREFER_RETURN + '=' + Constants.HEADER_PREFER_RETURN_REPRESENTATION, ourRequestHeaders.get(Constants.HEADER_PREFER).get(0).getValue()); - + } @@ -319,8 +353,7 @@ public class GenericJaxRsClientDstu2Test { p.setId("123"); final String formatted = ourCtx.newXmlParser().encodeResourceToString(p); - - + ourResponseStatus = Constants.STATUS_HTTP_200_OK; ourResponseContentType = Constants.CT_FHIR_XML + "; charset=UTF-8"; ourResponseBody = formatted; @@ -342,134 +375,126 @@ public class GenericJaxRsClientDstu2Test { IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort + "/fhir"); - client.delete().resourceById(new IdDt("Patient/123")).execute(); assertEquals("DELETE", ourRequestMethod); assertEquals("http://localhost:" + ourPort + "/fhir/Patient/123", ourRequestUri); - + client.delete().resourceConditionalByUrl("Patient?name=foo").execute(); assertEquals("DELETE", ourRequestMethod); assertEquals("http://localhost:" + ourPort + "/fhir/Patient?name=foo", ourRequestUri); - + client.delete().resourceConditionalByType("Patient").where(Patient.NAME.matches().value("foo")).execute(); assertEquals("DELETE", ourRequestMethod); assertEquals("http://localhost:" + ourPort + "/fhir/Patient?name=foo", ourRequestUri); - + } @Test public void testDelete() { ourResponseStatus = Constants.STATUS_HTTP_204_NO_CONTENT; - + IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort + "/fhir"); - client.delete().resourceById(new IdDt("Patient/123")).execute(); assertEquals("DELETE", ourRequestMethod); assertEquals("http://localhost:" + ourPort + "/fhir/Patient/123", ourRequestUri); - + } @Test public void testHistory() { final String msg = getPatientFeedWithOneResult(); - + ourResponseContentType = Constants.CT_FHIR_XML + "; charset=UTF-8"; ourResponseBody = msg; IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort + "/fhir"); - + ca.uhn.fhir.model.dstu2.resource.Bundle response; - + response = client - .history() - .onServer() - .andReturnBundle(ca.uhn.fhir.model.dstu2.resource.Bundle.class) - .execute(); - + .history() + .onServer() + .andReturnBundle(ca.uhn.fhir.model.dstu2.resource.Bundle.class) + .execute(); + assertEquals("http://localhost:" + ourPort + "/fhir/_history", ourRequestUri); assertEquals(1, response.getEntry().size()); - - + response = client - .history() - .onServer() - .andReturnBundle(ca.uhn.fhir.model.dstu2.resource.Bundle.class) - .since((Date)null) - .count(null) - .execute(); - + .history() + .onServer() + .andReturnBundle(ca.uhn.fhir.model.dstu2.resource.Bundle.class) + .since((Date) null) + .count(null) + .execute(); + assertEquals("http://localhost:" + ourPort + "/fhir/_history", ourRequestUri); assertEquals(1, response.getEntry().size()); - - + response = client - .history() - .onServer() - .andReturnBundle(ca.uhn.fhir.model.dstu2.resource.Bundle.class) - .since(new InstantDt()) - .execute(); - + .history() + .onServer() + .andReturnBundle(ca.uhn.fhir.model.dstu2.resource.Bundle.class) + .since(new InstantDt()) + .execute(); + assertEquals("http://localhost:" + ourPort + "/fhir/_history", ourRequestUri); assertEquals(1, response.getEntry().size()); - - + response = client - .history() - .onType(Patient.class) - .andReturnBundle(ca.uhn.fhir.model.dstu2.resource.Bundle.class) - .execute(); - + .history() + .onType(Patient.class) + .andReturnBundle(ca.uhn.fhir.model.dstu2.resource.Bundle.class) + .execute(); + assertEquals("http://localhost:" + ourPort + "/fhir/Patient/_history", ourRequestUri); assertEquals(1, response.getEntry().size()); - - + response = client - .history() - .onInstance(new IdDt("Patient", "123")) - .andReturnBundle(ca.uhn.fhir.model.dstu2.resource.Bundle.class) - .execute(); - + .history() + .onInstance(new IdDt("Patient", "123")) + .andReturnBundle(ca.uhn.fhir.model.dstu2.resource.Bundle.class) + .execute(); + assertEquals("http://localhost:" + ourPort + "/fhir/Patient/123/_history", ourRequestUri); assertEquals(1, response.getEntry().size()); - - + response = client - .history() - .onInstance(new IdDt("Patient", "123")) - .andReturnBundle(ca.uhn.fhir.model.dstu2.resource.Bundle.class) - .count(123) - .since(new InstantDt("2001-01-02T11:22:33Z")) - .execute(); - + .history() + .onInstance(new IdDt("Patient", "123")) + .andReturnBundle(ca.uhn.fhir.model.dstu2.resource.Bundle.class) + .count(123) + .since(new InstantDt("2001-01-02T11:22:33Z")) + .execute(); + assertThat(ourRequestUri, either(equalTo("http://localhost:" + ourPort + "/fhir/Patient/123/_history?_since=2001-01-02T11:22:33Z&_count=123")).or(equalTo("http://localhost:" + ourPort + "/fhir/Patient/123/_history?_count=123&_since=2001-01-02T11:22:33Z"))); assertEquals(1, response.getEntry().size()); - - + response = client - .history() - .onInstance(new IdDt("Patient", "123")) - .andReturnBundle(ca.uhn.fhir.model.dstu2.resource.Bundle.class) - .since(new InstantDt("2001-01-02T11:22:33Z").getValue()) - .execute(); - + .history() + .onInstance(new IdDt("Patient", "123")) + .andReturnBundle(ca.uhn.fhir.model.dstu2.resource.Bundle.class) + .since(new InstantDt("2001-01-02T11:22:33Z").getValue()) + .execute(); + assertThat(ourRequestUri, containsString("_since=2001-01")); assertEquals(1, response.getEntry().size()); - + } @Test @@ -481,28 +506,26 @@ public class GenericJaxRsClientDstu2Test { Parameters outParams = new Parameters(); outParams.addParameter().setName("meta").setValue(new MetaDt().addProfile("urn:profile:out")); final String respString = p.encodeResourceToString(outParams); - + ourResponseContentType = Constants.CT_FHIR_XML + "; charset=UTF-8"; ourResponseBody = respString; IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort + "/fhir"); - - MetaDt resp = client - .meta() - .add() - .onResource(new IdDt("Patient/123")) - .meta(inMeta) - .encodedXml() - .execute(); - + .meta() + .add() + .onResource(new IdDt("Patient/123")) + .meta(inMeta) + .encodedXml() + .execute(); + assertEquals("http://localhost:" + ourPort + "/fhir/Patient/123/$meta-add", ourRequestUri); assertEquals("urn:profile:out", resp.getProfile().get(0).getValue()); assertEquals("POST", ourRequestMethod); assertEquals("", ourRequestBodyString); - + } @@ -522,43 +545,39 @@ public class GenericJaxRsClientDstu2Test { IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort + "/fhir"); - - MetaDt resp = client - .meta() - .get(MetaDt.class) - .fromServer() - .execute(); - + .meta() + .get(MetaDt.class) + .fromServer() + .execute(); + assertEquals("http://localhost:" + ourPort + "/fhir/$meta", ourRequestUri); assertEquals("urn:profile:out", resp.getProfile().get(0).getValue()); assertEquals("GET", ourRequestMethod); - - + resp = client - .meta() - .get(MetaDt.class) - .fromType("Patient") - .execute(); - + .meta() + .get(MetaDt.class) + .fromType("Patient") + .execute(); + assertEquals("http://localhost:" + ourPort + "/fhir/Patient/$meta", ourRequestUri); assertEquals("urn:profile:out", resp.getProfile().get(0).getValue()); assertEquals("GET", ourRequestMethod); - - + resp = client - .meta() - .get(MetaDt.class) - .fromResource(new IdDt("Patient/123")) - .execute(); - + .meta() + .get(MetaDt.class) + .fromResource(new IdDt("Patient/123")) + .execute(); + assertEquals("http://localhost:" + ourPort + "/fhir/Patient/123/$meta", ourRequestUri); assertEquals("urn:profile:out", resp.getProfile().get(0).getValue()); assertEquals("GET", ourRequestMethod); - + } @@ -576,69 +595,63 @@ public class GenericJaxRsClientDstu2Test { outParams.addParameter().setValue(new StringDt("STRINGVALOUT2")); final String respString = p.encodeResourceToString(outParams); - - - + ourResponseContentType = Constants.CT_FHIR_XML + "; charset=UTF-8"; ourResponseBody = respString; IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort + "/fhir"); - - Parameters resp = client - .operation() - .onServer() - .named("$SOMEOPERATION") - .withParameters(inParams) - .useHttpGet() - .execute(); - + .operation() + .onServer() + .named("$SOMEOPERATION") + .withParameters(inParams) + .useHttpGet() + .execute(); + assertEquals("http://localhost:" + ourPort + "/fhir/$SOMEOPERATION?param1=STRINGVALIN1¶m1=STRINGVALIN1b¶m2=STRINGVALIN2", ourRequestUri); assertEquals(respString, p.encodeResourceToString(resp)); assertEquals("GET", ourRequestMethod); - - + resp = client - .operation() - .onType(Patient.class) - .named("$SOMEOPERATION") - .withParameters(inParams) - .useHttpGet() - .execute(); - + .operation() + .onType(Patient.class) + .named("$SOMEOPERATION") + .withParameters(inParams) + .useHttpGet() + .execute(); + assertEquals("http://localhost:" + ourPort + "/fhir/Patient/$SOMEOPERATION?param1=STRINGVALIN1¶m1=STRINGVALIN1b¶m2=STRINGVALIN2", ourRequestUri); assertEquals(respString, p.encodeResourceToString(resp)); assertEquals("GET", ourRequestMethod); - - + resp = client - .operation() - .onInstance(new IdDt("Patient", "123")) - .named("$SOMEOPERATION") - .withParameters(inParams) - .useHttpGet() - .execute(); - + .operation() + .onInstance(new IdDt("Patient", "123")) + .named("$SOMEOPERATION") + .withParameters(inParams) + .useHttpGet() + .execute(); + assertEquals("http://localhost:" + ourPort + "/fhir/Patient/123/$SOMEOPERATION?param1=STRINGVALIN1¶m1=STRINGVALIN1b¶m2=STRINGVALIN2", ourRequestUri); assertEquals(respString, p.encodeResourceToString(resp)); assertEquals("GET", ourRequestMethod); - + // @formatter:off resp = client - .operation() - .onInstance(new IdDt("http://foo.com/bar/baz/Patient/123/_history/22")) - .named("$SOMEOPERATION") - .withParameters(inParams) - .useHttpGet() - .execute(); + .operation() + .onInstance(new IdDt("http://foo.com/bar/baz/Patient/123/_history/22")) + .named("$SOMEOPERATION") + .withParameters(inParams) + .useHttpGet() + .execute(); // @formatter:on assertEquals("http://localhost:" + ourPort + "/fhir/Patient/123/$SOMEOPERATION?param1=STRINGVALIN1¶m1=STRINGVALIN1b¶m2=STRINGVALIN2", ourRequestUri); - + } @Test @@ -649,67 +662,63 @@ public class GenericJaxRsClientDstu2Test { outParams.addParameter().setValue(new StringDt("STRINGVALOUT1")); outParams.addParameter().setValue(new StringDt("STRINGVALOUT2")); final String respString = p.encodeResourceToString(outParams); - + ourResponseContentType = Constants.CT_FHIR_XML + "; charset=UTF-8"; ourResponseBody = respString; IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort + "/fhir"); - - Parameters resp = client - .operation() - .onServer() - .named("$SOMEOPERATION") - .withNoParameters(Parameters.class) - .useHttpGet() - .execute(); - + .operation() + .onServer() + .named("$SOMEOPERATION") + .withNoParameters(Parameters.class) + .useHttpGet() + .execute(); + assertEquals("http://localhost:" + ourPort + "/fhir/$SOMEOPERATION", ourRequestUri); assertEquals(respString, p.encodeResourceToString(resp)); assertEquals("GET", ourRequestMethod); - - + resp = client - .operation() - .onType(Patient.class) - .named("$SOMEOPERATION") - .withNoParameters(Parameters.class) - .useHttpGet() - .execute(); - + .operation() + .onType(Patient.class) + .named("$SOMEOPERATION") + .withNoParameters(Parameters.class) + .useHttpGet() + .execute(); + assertEquals("http://localhost:" + ourPort + "/fhir/Patient/$SOMEOPERATION", ourRequestUri); assertEquals(respString, p.encodeResourceToString(resp)); assertEquals("GET", ourRequestMethod); - - + resp = client - .operation() - .onInstance(new IdDt("Patient", "123")) - .named("$SOMEOPERATION") - .withNoParameters(Parameters.class) - .useHttpGet() - .execute(); - + .operation() + .onInstance(new IdDt("Patient", "123")) + .named("$SOMEOPERATION") + .withNoParameters(Parameters.class) + .useHttpGet() + .execute(); + assertEquals("http://localhost:" + ourPort + "/fhir/Patient/123/$SOMEOPERATION", ourRequestUri); assertEquals(respString, p.encodeResourceToString(resp)); assertEquals("GET", ourRequestMethod); - + // @formatter:off resp = client - .operation() - .onInstance(new IdDt("http://foo.com/bar/baz/Patient/123/_history/22")) - .named("$SOMEOPERATION") - .withNoParameters(Parameters.class) - .useHttpGet() - .execute(); + .operation() + .onInstance(new IdDt("http://foo.com/bar/baz/Patient/123/_history/22")) + .named("$SOMEOPERATION") + .withNoParameters(Parameters.class) + .useHttpGet() + .execute(); // @formatter:on assertEquals("http://localhost:" + ourPort + "/fhir/Patient/123/$SOMEOPERATION", ourRequestUri); - + } @Test @@ -760,15 +769,13 @@ public class GenericJaxRsClientDstu2Test { IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort + "/fhir"); - - Parameters resp = client - .operation() - .onServer() - .named("$SOMEOPERATION") - .withParameters(inParams).encodedXml().execute(); - + .operation() + .onServer() + .named("$SOMEOPERATION") + .withParameters(inParams).encodedXml().execute(); + assertEquals("http://localhost:" + ourPort + "/fhir/$SOMEOPERATION", ourRequestUri); assertEquals(1, ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE).size()); assertEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8, ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char")); @@ -776,7 +783,7 @@ public class GenericJaxRsClientDstu2Test { assertEquals("POST", ourRequestMethod); assertEquals(1, resp.getParameter().size()); assertEquals(ca.uhn.fhir.model.dstu2.resource.Bundle.class, resp.getParameter().get(0).getResource().getClass()); - + } @Test @@ -787,82 +794,80 @@ public class GenericJaxRsClientDstu2Test { outParams.addParameter().setValue(new StringDt("STRINGVALOUT1")); outParams.addParameter().setValue(new StringDt("STRINGVALOUT2")); final String respString = p.encodeResourceToString(outParams); - + ourResponseContentType = Constants.CT_FHIR_XML + "; charset=UTF-8"; ourResponseBody = respString; IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort + "/fhir"); - - Parameters resp = client - .operation() - .onServer() - .named("$SOMEOPERATION") - .withParameter(Parameters.class, "name1", new StringDt("value1")) - .andParameter("name2", new StringDt("value1")) - .encodedXml() - .execute(); - + .operation() + .onServer() + .named("$SOMEOPERATION") + .withParameter(Parameters.class, "name1", new StringDt("value1")) + .andParameter("name2", new StringDt("value1")) + .encodedXml() + .execute(); + assertEquals("http://localhost:" + ourPort + "/fhir/$SOMEOPERATION", ourRequestUri); assertEquals(respString, p.encodeResourceToString(resp)); assertEquals(1, ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE).size()); assertEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8, ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char")); assertEquals("POST", ourRequestMethod); assertEquals("", (ourRequestBodyString)); - + /* * Composite type */ - + resp = client - .operation() - .onServer() - .named("$SOMEOPERATION") - .withParameter(Parameters.class, "name1", new IdentifierDt("system1", "value1")) - .andParameter("name2", new StringDt("value1")) - .encodedXml() - .execute(); - + .operation() + .onServer() + .named("$SOMEOPERATION") + .withParameter(Parameters.class, "name1", new IdentifierDt("system1", "value1")) + .andParameter("name2", new StringDt("value1")) + .encodedXml() + .execute(); + assertEquals("http://localhost:" + ourPort + "/fhir/$SOMEOPERATION", ourRequestUri); assertEquals(respString, p.encodeResourceToString(resp)); assertEquals(1, ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE).size()); assertEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8, ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char")); assertEquals("POST", ourRequestMethod); assertEquals("", - (ourRequestBodyString)); - + (ourRequestBodyString)); + /* * Resource */ - + resp = client - .operation() - .onServer() - .named("$SOMEOPERATION") - .withParameter(Parameters.class, "name1", new IdentifierDt("system1", "value1")) - .andParameter("name2", new Patient().setActive(true)) - .encodedXml() - .execute(); - + .operation() + .onServer() + .named("$SOMEOPERATION") + .withParameter(Parameters.class, "name1", new IdentifierDt("system1", "value1")) + .andParameter("name2", new Patient().setActive(true)) + .encodedXml() + .execute(); + assertEquals("http://localhost:" + ourPort + "/fhir/$SOMEOPERATION", ourRequestUri); assertEquals(respString, p.encodeResourceToString(resp)); assertEquals(1, ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE).size()); assertEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8, ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char")); assertEquals("POST", ourRequestMethod); assertEquals( - "", - (ourRequestBodyString)); - + "", + (ourRequestBodyString)); + } - @Test(expected = IllegalArgumentException.class) + @Test public void testOperationWithInvalidParam() { IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort + "/fhir"); @@ -901,14 +906,15 @@ public class GenericJaxRsClientDstu2Test { } }; - - client + assertThrows(IllegalArgumentException.class, () -> { + client .operation() .onServer() .named("$SOMEOPERATION") .withParameter(Parameters.class, "name1", weirdBase) .execute(); - + }); + } @Test @@ -920,45 +926,40 @@ public class GenericJaxRsClientDstu2Test { outParams.addParameter().setValue(new StringDt("STRINGVALOUT2")); final String respString = p.encodeResourceToString(outParams); - - - + ourResponseContentType = Constants.CT_FHIR_XML + "; charset=UTF-8"; ourResponseBody = respString; IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort + "/fhir"); - - client - .operation() - .onInstance(new IdDt("http://foo/Patient/1")) - .named("validate-code") - .withParameter(Parameters.class, "code", new CodeDt("8495-4")) - .andParameter("system", new UriDt("http://loinc.org")) - .useHttpGet() - .execute(); - - + .operation() + .onInstance(new IdDt("http://foo/Patient/1")) + .named("validate-code") + .withParameter(Parameters.class, "code", new CodeDt("8495-4")) + .andParameter("system", new UriDt("http://loinc.org")) + .useHttpGet() + .execute(); + + assertEquals("http://localhost:" + ourPort + "/fhir/Patient/1/$validate-code?code=8495-4&system=http%3A%2F%2Floinc.org", ourRequestUri); - - + client - .operation() - .onInstance(new IdDt("http://foo/Patient/1")) - .named("validate-code") - .withParameter(Parameters.class, "code", new CodeDt("8495-4")) - .andParameter("system", new UriDt("http://loinc.org")) - .encodedXml() - .encodedXml() - .execute(); - - + .operation() + .onInstance(new IdDt("http://foo/Patient/1")) + .named("validate-code") + .withParameter(Parameters.class, "code", new CodeDt("8495-4")) + .andParameter("system", new UriDt("http://loinc.org")) + .encodedXml() + .encodedXml() + .execute(); + + assertEquals("http://localhost:" + ourPort + "/fhir/Patient/1/$validate-code", ourRequestUri); ourLog.info(ourRequestBodyString); - assertEquals("",ourRequestBodyString); + assertEquals("", ourRequestBodyString); } @@ -976,67 +977,61 @@ public class GenericJaxRsClientDstu2Test { outParams.addParameter().setValue(new StringDt("STRINGVALOUT2")); final String respString = p.encodeResourceToString(outParams); - - - + ourResponseContentType = Constants.CT_FHIR_XML + "; charset=UTF-8"; ourResponseBody = respString; IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort + "/fhir"); - - Parameters resp = client - .operation() - .onServer() - .named("$SOMEOPERATION") - .withParameters(inParams).encodedXml().execute(); - + .operation() + .onServer() + .named("$SOMEOPERATION") + .withParameters(inParams).encodedXml().execute(); + assertEquals("http://localhost:" + ourPort + "/fhir/$SOMEOPERATION", ourRequestUri); assertEquals(respString, p.encodeResourceToString(resp)); assertEquals(1, ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE).size()); assertEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8, ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char")); assertEquals(ourRequestBodyString, reqString); assertEquals("POST", ourRequestMethod); - - + resp = client - .operation() - .onType(Patient.class) - .named("$SOMEOPERATION") - .withParameters(inParams).encodedXml().execute(); - + .operation() + .onType(Patient.class) + .named("$SOMEOPERATION") + .withParameters(inParams).encodedXml().execute(); + assertEquals("http://localhost:" + ourPort + "/fhir/Patient/$SOMEOPERATION", ourRequestUri); assertEquals(respString, p.encodeResourceToString(resp)); assertEquals(1, ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE).size()); assertEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8, ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char")); assertEquals(ourRequestBodyString, reqString); assertEquals("POST", ourRequestMethod); - - + resp = client - .operation() - .onInstance(new IdDt("Patient", "123")) - .named("$SOMEOPERATION") - .withParameters(inParams) - .encodedXml() - .execute(); - + .operation() + .onInstance(new IdDt("Patient", "123")) + .named("$SOMEOPERATION") + .withParameters(inParams) + .encodedXml() + .execute(); + assertEquals("http://localhost:" + ourPort + "/fhir/Patient/123/$SOMEOPERATION", ourRequestUri); assertEquals(respString, p.encodeResourceToString(resp)); assertEquals(1, ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE).size()); assertEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8, ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char")); assertEquals(ourRequestBodyString, reqString); assertEquals("POST", ourRequestMethod); - + resp = client.operation().onInstance(new IdDt("http://foo.com/bar/baz/Patient/123/_history/22")).named("$SOMEOPERATION").withParameters(inParams).execute(); // @formatter:on assertEquals("http://localhost:" + ourPort + "/fhir/Patient/123/$SOMEOPERATION", ourRequestUri); - + } @Test @@ -1051,97 +1046,90 @@ public class GenericJaxRsClientDstu2Test { outParams.addParameter().setValue(new StringDt("STRINGVALOUT2")); final String respString = p.encodeResourceToString(outParams); - - - + ourResponseContentType = Constants.CT_FHIR_XML + "; charset=UTF-8"; ourResponseBody = respString; IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort + "/fhir"); - - Parameters resp = client - .operation() - .onServer() - .named("$SOMEOPERATION") - .withNoParameters(Parameters.class).encodedXml().execute(); - + .operation() + .onServer() + .named("$SOMEOPERATION") + .withNoParameters(Parameters.class).encodedXml().execute(); + assertEquals("http://localhost:" + ourPort + "/fhir/$SOMEOPERATION", ourRequestUri); assertEquals(respString, p.encodeResourceToString(resp)); assertEquals(1, ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE).size()); assertEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8, ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char")); assertEquals(ourRequestBodyString, reqString); assertEquals("POST", ourRequestMethod); - - + resp = client - .operation() - .onType(Patient.class) - .named("$SOMEOPERATION") - .withNoParameters(Parameters.class).encodedXml().execute(); - + .operation() + .onType(Patient.class) + .named("$SOMEOPERATION") + .withNoParameters(Parameters.class).encodedXml().execute(); + assertEquals("http://localhost:" + ourPort + "/fhir/Patient/$SOMEOPERATION", ourRequestUri); assertEquals(respString, p.encodeResourceToString(resp)); assertEquals(1, ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE).size()); assertEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8, ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char")); assertEquals(ourRequestBodyString, reqString); assertEquals("POST", ourRequestMethod); - - + resp = client - .operation() - .onInstance(new IdDt("Patient", "123")) - .named("$SOMEOPERATION") - .withNoParameters(Parameters.class).encodedXml().execute(); - + .operation() + .onInstance(new IdDt("Patient", "123")) + .named("$SOMEOPERATION") + .withNoParameters(Parameters.class).encodedXml().execute(); + assertEquals("http://localhost:" + ourPort + "/fhir/Patient/123/$SOMEOPERATION", ourRequestUri); assertEquals(respString, p.encodeResourceToString(resp)); assertEquals(1, ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE).size()); assertEquals(EncodingEnum.XML.getResourceContentType() + Constants.HEADER_SUFFIX_CT_UTF_8, ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char")); assertEquals(ourRequestBodyString, reqString); assertEquals("POST", ourRequestMethod); - + // @formatter:off resp = client - .operation() - .onInstance(new IdDt("http://foo.com/bar/baz/Patient/123/_history/22")) - .named("$SOMEOPERATION") - .withNoParameters(Parameters.class) - .execute(); + .operation() + .onInstance(new IdDt("http://foo.com/bar/baz/Patient/123/_history/22")) + .named("$SOMEOPERATION") + .withNoParameters(Parameters.class) + .execute(); // @formatter:on assertEquals("http://localhost:" + ourPort + "/fhir/Patient/123/$SOMEOPERATION", ourRequestUri); - + } @Test public void testPageNext() { - + ourResponseContentType = Constants.CT_FHIR_XML + "; charset=UTF-8"; ourResponseBody = getPatientFeedWithOneResult(); IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort + "/fhir"); - ca.uhn.fhir.model.dstu2.resource.Bundle sourceBundle = new ca.uhn.fhir.model.dstu2.resource.Bundle(); sourceBundle.getLinkOrCreate(IBaseBundle.LINK_PREV).setUrl("http://localhost:" + ourPort + "/fhir/prev"); sourceBundle.getLinkOrCreate(IBaseBundle.LINK_NEXT).setUrl("http://localhost:" + ourPort + "/fhir/next"); - + ca.uhn.fhir.model.dstu2.resource.Bundle resp = client - .loadPage() - .next(sourceBundle) - .execute(); - + .loadPage() + .next(sourceBundle) + .execute(); + assertEquals(1, resp.getEntry().size()); assertEquals("http://localhost:" + ourPort + "/fhir/next", ourRequestUri); - + } @@ -1159,29 +1147,27 @@ public class GenericJaxRsClientDstu2Test { @Test public void testPagePrev() { - - - + + ourResponseContentType = Constants.CT_FHIR_XML + "; charset=UTF-8"; ourResponseBody = getPatientFeedWithOneResult(); IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort + "/fhir"); - ca.uhn.fhir.model.dstu2.resource.Bundle sourceBundle = new ca.uhn.fhir.model.dstu2.resource.Bundle(); sourceBundle.getLinkOrCreate("previous").setUrl("http://localhost:" + ourPort + "/fhir/prev"); - + ca.uhn.fhir.model.dstu2.resource.Bundle resp = client - .loadPage() - .previous(sourceBundle) - .execute(); - + .loadPage() + .previous(sourceBundle) + .execute(); + assertEquals(1, resp.getEntry().size()); assertEquals("http://localhost:" + ourPort + "/fhir/prev", ourRequestUri); - + /* * Try with "prev" instead of "previous" @@ -1190,16 +1176,16 @@ public class GenericJaxRsClientDstu2Test { sourceBundle = new ca.uhn.fhir.model.dstu2.resource.Bundle(); sourceBundle.getLinkOrCreate("prev").setUrl("http://localhost:" + ourPort + "/fhir/prev"); - + resp = client - .loadPage() - .previous(sourceBundle) - .execute(); - + .loadPage() + .previous(sourceBundle) + .execute(); + assertEquals(1, resp.getEntry().size()); assertEquals("http://localhost:" + ourPort + "/fhir/prev", ourRequestUri); - + } @@ -1217,7 +1203,7 @@ public class GenericJaxRsClientDstu2Test { Patient response; - + response = (Patient) client.read(new UriDt("http://localhost:" + ourPort + "/fhir/Patient/123")); assertEquals("http://localhost:" + ourPort + "/fhir/Patient/123", ourRequestUri); assertEquals("FAM", response.getName().get(0).getFamily().get(0).getValue()); @@ -1245,25 +1231,22 @@ public class GenericJaxRsClientDstu2Test { @Test public void testReadUpdatedHeaderDoesntOverwriteResourceValue() { - - final String input = "\n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - ""; - - - - + final String input = "\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + ""; + + ourResponseContentType = Constants.CT_FHIR_XML + "; charset=UTF-8"; ourResponseBody = input; @@ -1272,10 +1255,10 @@ public class GenericJaxRsClientDstu2Test { ca.uhn.fhir.model.dstu2.resource.Bundle response; response = client - .search() - .forResource(Patient.class) - .returnBundle(ca.uhn.fhir.model.dstu2.resource.Bundle.class) - .execute(); + .search() + .forResource(Patient.class) + .returnBundle(ca.uhn.fhir.model.dstu2.resource.Bundle.class) + .execute(); assertEquals("2015-06-22T15:48:57.554-04:00", ResourceMetadataKeyEnum.UPDATED.get(response).getValueAsString()); } @@ -1284,9 +1267,7 @@ public class GenericJaxRsClientDstu2Test { public void testReadWithElementsParam() { String msg = "{\"resourceType\":\"Patient\",\"id\":\"1\",\"meta\":{\"versionId\":\"1\",\"lastUpdated\":\"2014-12-20T18:41:29.706-05:00\"},\"identifier\":[{\"system\":\"urn:MultiFhirVersionTest\",\"value\":\"testSubmitPatient01\"}]}"; - - - + ourResponseContentType = Constants.CT_FHIR_JSON + "; charset=UTF-8"; ourResponseBody = msg; @@ -1307,16 +1288,14 @@ public class GenericJaxRsClientDstu2Test { public void testReadWithSummaryInvalid() { String msg = "<>>>><<<<>"; - - - + ourResponseContentType = Constants.CT_HTML + "; charset=UTF-8"; ourResponseBody = msg; IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort + "/fhir"); - + try { client.read() .resource(Patient.class) @@ -1333,9 +1312,7 @@ public class GenericJaxRsClientDstu2Test { public void testReadWithSummaryParamHtml() { String msg = "
HELP IM A DIV
"; - - - + ourResponseContentType = Constants.CT_HTML + "; charset=UTF-8"; ourResponseBody = msg; @@ -1358,20 +1335,18 @@ public class GenericJaxRsClientDstu2Test { public void testSearchByString() { String msg = "{\"resourceType\":\"Bundle\",\"id\":null,\"base\":\"http://localhost:57931/fhir/contextDev\",\"total\":1,\"link\":[{\"relation\":\"self\",\"url\":\"http://localhost:57931/fhir/contextDev/Patient?identifier=urn%3AMultiFhirVersionTest%7CtestSubmitPatient01&_format=json\"}],\"entry\":[{\"resource\":{\"resourceType\":\"Patient\",\"id\":\"1\",\"meta\":{\"versionId\":\"1\",\"lastUpdated\":\"2014-12-20T18:41:29.706-05:00\"},\"identifier\":[{\"system\":\"urn:MultiFhirVersionTest\",\"value\":\"testSubmitPatient01\"}]}}]}"; - - - + ourResponseContentType = Constants.CT_FHIR_JSON + "; charset=UTF-8"; ourResponseBody = msg; IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort + "/fhir"); - Bundle response = client.search() - .forResource("Patient") - .where(Patient.NAME.matches().value("james")) - .returnBundle(Bundle.class) - .execute(); + Bundle response = client.search() + .forResource("Patient") + .where(Patient.NAME.matches().value("james")) + .returnBundle(Bundle.class) + .execute(); assertEquals("http://localhost:" + ourPort + "/fhir/Patient?name=james", ourRequestUri); assertEquals(Patient.class, response.getEntry().get(0).getResource().getClass()); @@ -1383,67 +1358,60 @@ public class GenericJaxRsClientDstu2Test { final String msg = getPatientFeedWithOneResult(); - - - + ourResponseContentType = Constants.CT_FHIR_XML + "; charset=UTF-8"; ourResponseBody = msg; IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort + "/fhir"); - - + ca.uhn.fhir.model.dstu2.resource.Bundle response = client.search() - .byUrl("http://localhost:" + ourPort + "/AAA?name=http://foo|bar") - .encodedJson() - .returnBundle(ca.uhn.fhir.model.dstu2.resource.Bundle.class) - .execute(); - + .byUrl("http://localhost:" + ourPort + "/AAA?name=http://foo|bar") + .encodedJson() + .returnBundle(ca.uhn.fhir.model.dstu2.resource.Bundle.class) + .execute(); + assertEquals("http://localhost:" + ourPort + "/AAA?name=http%3A//foo%7Cbar&_format=json", ourRequestUri); assertNotNull(response); - - + response = client.search() - .byUrl("Patient?name=http://foo|bar") - .encodedJson() - .returnBundle(ca.uhn.fhir.model.dstu2.resource.Bundle.class) - .execute(); - + .byUrl("Patient?name=http://foo|bar") + .encodedJson() + .returnBundle(ca.uhn.fhir.model.dstu2.resource.Bundle.class) + .execute(); + assertEquals("http://localhost:" + ourPort + "/fhir/Patient?name=http%3A//foo%7Cbar&_format=json", ourRequestUri); assertNotNull(response); - - + response = client.search() - .byUrl("/Patient?name=http://foo|bar") - .encodedJson() - .returnBundle(ca.uhn.fhir.model.dstu2.resource.Bundle.class) - .execute(); - + .byUrl("/Patient?name=http://foo|bar") + .encodedJson() + .returnBundle(ca.uhn.fhir.model.dstu2.resource.Bundle.class) + .execute(); + assertEquals("http://localhost:" + ourPort + "/fhir/Patient?name=http%3A//foo%7Cbar&_format=json", ourRequestUri); assertNotNull(response); - - + response = client.search() - .byUrl("Patient") - .returnBundle(ca.uhn.fhir.model.dstu2.resource.Bundle.class) - .execute(); - + .byUrl("Patient") + .returnBundle(ca.uhn.fhir.model.dstu2.resource.Bundle.class) + .execute(); + assertEquals("http://localhost:" + ourPort + "/fhir/Patient", ourRequestUri); assertNotNull(response); - - + response = client.search() - .byUrl("Patient?") - .returnBundle(ca.uhn.fhir.model.dstu2.resource.Bundle.class) - .execute(); - + .byUrl("Patient?") + .returnBundle(ca.uhn.fhir.model.dstu2.resource.Bundle.class) + .execute(); + assertEquals("http://localhost:" + ourPort + "/fhir/Patient", ourRequestUri); assertNotNull(response); - + try { client.search().byUrl("foo/bar?test=1"); @@ -1458,22 +1426,21 @@ public class GenericJaxRsClientDstu2Test { @Test public void testSearchReturningDstu2Bundle() throws Exception { String msg = IOUtils.toString(GenericJaxRsClientDstu2Test.class.getResourceAsStream("/bundle_orion.xml")); - - - + + ourResponseContentType = Constants.CT_FHIR_XML + "; charset=UTF-8"; ourResponseBody = msg; IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort + "/fhir"); - + ca.uhn.fhir.model.dstu2.resource.Bundle response = client.search() .forResource("Observation") .where(Patient.NAME.matches().value("FOO")) .returnBundle(ca.uhn.fhir.model.dstu2.resource.Bundle.class) .execute(); - + Link link = response.getLink().get(0); assertEquals("just trying add link", link.getRelation()); @@ -1489,23 +1456,21 @@ public class GenericJaxRsClientDstu2Test { public void testSearchWithElementsParam() { String msg = "{\"resourceType\":\"Bundle\",\"id\":null,\"base\":\"http://localhost:57931/fhir/contextDev\",\"total\":1,\"link\":[{\"relation\":\"self\",\"url\":\"http://localhost:57931/fhir/contextDev/Patient?identifier=urn%3AMultiFhirVersionTest%7CtestSubmitPatient01&_format=json\"}],\"entry\":[{\"resource\":{\"resourceType\":\"Patient\",\"id\":\"1\",\"meta\":{\"versionId\":\"1\",\"lastUpdated\":\"2014-12-20T18:41:29.706-05:00\"},\"identifier\":[{\"system\":\"urn:MultiFhirVersionTest\",\"value\":\"testSubmitPatient01\"}]}}]}"; - - - + ourResponseContentType = Constants.CT_FHIR_JSON + "; charset=UTF-8"; ourResponseBody = msg; IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort + "/fhir"); - - Bundle response = client.search() - .forResource("Patient") - .where(Patient.NAME.matches().value("james")) - .elementsSubset("name", "identifier") - .returnBundle(Bundle.class) - .execute(); - + + Bundle response = client.search() + .forResource("Patient") + .where(Patient.NAME.matches().value("james")) + .elementsSubset("name", "identifier") + .returnBundle(Bundle.class) + .execute(); + assertThat(ourRequestUri, either(equalTo("http://localhost:" + ourPort + "/fhir/Patient?name=james&_elements=name%2Cidentifier")).or(equalTo("http://localhost:" + ourPort + "/fhir/Patient?name=james&_elements=identifier%2Cname"))); assertEquals(Patient.class, response.getEntry().get(0).getResource().getClass()); @@ -1516,24 +1481,22 @@ public class GenericJaxRsClientDstu2Test { public void testSearchByPost() { String msg = "{\"resourceType\":\"Bundle\",\"id\":null,\"base\":\"http://localhost:57931/fhir/contextDev\",\"total\":1,\"link\":[{\"relation\":\"self\",\"url\":\"http://localhost:57931/fhir/contextDev/Patient?identifier=urn%3AMultiFhirVersionTest%7CtestSubmitPatient01&_format=json\"}],\"entry\":[{\"resource\":{\"resourceType\":\"Patient\",\"id\":\"1\",\"meta\":{\"versionId\":\"1\",\"lastUpdated\":\"2014-12-20T18:41:29.706-05:00\"},\"identifier\":[{\"system\":\"urn:MultiFhirVersionTest\",\"value\":\"testSubmitPatient01\"}]}}]}"; - - - + ourResponseContentType = Constants.CT_FHIR_JSON + "; charset=UTF-8"; ourResponseBody = msg; IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort + "/fhir"); - + Bundle response = client.search() .forResource("Patient") .where(Patient.NAME.matches().value("james")) .elementsSubset("name", "identifier") .usingStyle(SearchStyleEnum.POST) - .returnBundle(Bundle.class) + .returnBundle(Bundle.class) .execute(); - + assertEquals("http://localhost:" + ourPort + "/fhir/Patient/_search?_elements=identifier%2Cname", ourRequestUri); @@ -1553,25 +1516,23 @@ public class GenericJaxRsClientDstu2Test { public void testSearchByPostUseJson() { String msg = "{\"resourceType\":\"Bundle\",\"id\":null,\"base\":\"http://localhost:57931/fhir/contextDev\",\"total\":1,\"link\":[{\"relation\":\"self\",\"url\":\"http://localhost:57931/fhir/contextDev/Patient?identifier=urn%3AMultiFhirVersionTest%7CtestSubmitPatient01&_format=json\"}],\"entry\":[{\"resource\":{\"resourceType\":\"Patient\",\"id\":\"1\",\"meta\":{\"versionId\":\"1\",\"lastUpdated\":\"2014-12-20T18:41:29.706-05:00\"},\"identifier\":[{\"system\":\"urn:MultiFhirVersionTest\",\"value\":\"testSubmitPatient01\"}]}}]}"; - - - + ourResponseContentType = Constants.CT_FHIR_JSON + "; charset=UTF-8"; ourResponseBody = msg; IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort + "/fhir"); - + Bundle response = client.search() .forResource("Patient") .where(Patient.NAME.matches().value("james")) .elementsSubset("name", "identifier") .usingStyle(SearchStyleEnum.POST) .encodedJson() - .returnBundle(Bundle.class) + .returnBundle(Bundle.class) .execute(); - + assertThat(ourRequestUri, containsString("http://localhost:" + ourPort + "/fhir/Patient/_search?")); assertThat(ourRequestUri, containsString("_elements=identifier%2Cname")); @@ -1591,23 +1552,21 @@ public class GenericJaxRsClientDstu2Test { public void testSearchWithLastUpdated() { String msg = "{\"resourceType\":\"Bundle\",\"id\":null,\"base\":\"http://localhost:57931/fhir/contextDev\",\"total\":1,\"link\":[{\"relation\":\"self\",\"url\":\"http://localhost:57931/fhir/contextDev/Patient?identifier=urn%3AMultiFhirVersionTest%7CtestSubmitPatient01&_format=json\"}],\"entry\":[{\"resource\":{\"resourceType\":\"Patient\",\"id\":\"1\",\"meta\":{\"versionId\":\"1\",\"lastUpdated\":\"2014-12-20T18:41:29.706-05:00\"},\"identifier\":[{\"system\":\"urn:MultiFhirVersionTest\",\"value\":\"testSubmitPatient01\"}]}}]}"; - - - + ourResponseContentType = Constants.CT_FHIR_JSON + "; charset=UTF-8"; ourResponseBody = msg; IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort + "/fhir"); - - Bundle response = client.search() - .forResource("Patient") - .where(Patient.NAME.matches().value("james")) - .returnBundle(Bundle.class) - .lastUpdated(new DateRangeParam("2011-01-01", "2012-01-01")) - .execute(); - + + Bundle response = client.search() + .forResource("Patient") + .where(Patient.NAME.matches().value("james")) + .returnBundle(Bundle.class) + .lastUpdated(new DateRangeParam("2011-01-01", "2012-01-01")) + .execute(); + assertEquals("http://localhost:" + ourPort + "/fhir/Patient?name=james&_lastUpdated=ge2011-01-01&_lastUpdated=le2012-01-01", ourRequestUri); assertEquals(Patient.class, response.getEntry().get(0).getResource().getClass()); @@ -1618,25 +1577,23 @@ public class GenericJaxRsClientDstu2Test { public void testSearchWithProfileAndSecurity() { String msg = "{\"resourceType\":\"Bundle\",\"id\":null,\"base\":\"http://localhost:57931/fhir/contextDev\",\"total\":1,\"link\":[{\"relation\":\"self\",\"url\":\"http://localhost:57931/fhir/contextDev/Patient?identifier=urn%3AMultiFhirVersionTest%7CtestSubmitPatient01&_format=json\"}],\"entry\":[{\"resource\":{\"resourceType\":\"Patient\",\"id\":\"1\",\"meta\":{\"versionId\":\"1\",\"lastUpdated\":\"2014-12-20T18:41:29.706-05:00\"},\"identifier\":[{\"system\":\"urn:MultiFhirVersionTest\",\"value\":\"testSubmitPatient01\"}]}}]}"; - - - + ourResponseContentType = Constants.CT_FHIR_JSON + "; charset=UTF-8"; ourResponseBody = msg; IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort + "/fhir"); - - Bundle response = client.search() - .forResource("Patient") - .withProfile("http://foo1") - .withProfile("http://foo2") - .withSecurity("system1", "code1") - .withSecurity("system2", "code2") - .returnBundle(Bundle.class) - .execute(); - + + Bundle response = client.search() + .forResource("Patient") + .withProfile("http://foo1") + .withProfile("http://foo2") + .withSecurity("system1", "code1") + .withSecurity("system2", "code2") + .returnBundle(Bundle.class) + .execute(); + assertEquals("http://localhost:" + ourPort + "/fhir/Patient?_security=system1%7Ccode1&_security=system2%7Ccode2&_profile=http%3A%2F%2Ffoo1&_profile=http%3A%2F%2Ffoo2", ourRequestUri); assertEquals(Patient.class, response.getEntry().get(0).getResource().getClass()); @@ -1649,23 +1606,21 @@ public class GenericJaxRsClientDstu2Test { String msg = getPatientFeedWithOneResult(); - - - + ourResponseContentType = Constants.CT_FHIR_XML + "; charset=UTF-8"; ourResponseBody = msg; IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort + "/fhir"); - + Bundle response = client.search() - .forResource(Patient.class) - .encodedJson() - .revInclude(new Include("Provenance:target")) - .returnBundle(Bundle.class) - .execute(); - + .forResource(Patient.class) + .encodedJson() + .revInclude(new Include("Provenance:target")) + .returnBundle(Bundle.class) + .execute(); + assertEquals("http://localhost:" + ourPort + "/fhir/Patient?_revinclude=Provenance%3Atarget&_format=json", ourRequestUri); @@ -1675,23 +1630,21 @@ public class GenericJaxRsClientDstu2Test { public void testSearchWithSummaryParam() { String msg = "{\"resourceType\":\"Bundle\",\"id\":null,\"base\":\"http://localhost:57931/fhir/contextDev\",\"total\":1,\"link\":[{\"relation\":\"self\",\"url\":\"http://localhost:57931/fhir/contextDev/Patient?identifier=urn%3AMultiFhirVersionTest%7CtestSubmitPatient01&_format=json\"}],\"entry\":[{\"resource\":{\"resourceType\":\"Patient\",\"id\":\"1\",\"meta\":{\"versionId\":\"1\",\"lastUpdated\":\"2014-12-20T18:41:29.706-05:00\"},\"identifier\":[{\"system\":\"urn:MultiFhirVersionTest\",\"value\":\"testSubmitPatient01\"}]}}]}"; - - - + ourResponseContentType = Constants.CT_FHIR_JSON + "; charset=UTF-8"; ourResponseBody = msg; IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort + "/fhir"); - - Bundle response = client.search() - .forResource("Patient") - .where(Patient.NAME.matches().value("james")) - .summaryMode(SummaryEnum.FALSE) - .returnBundle(Bundle.class) - .execute(); - + + Bundle response = client.search() + .forResource("Patient") + .where(Patient.NAME.matches().value("james")) + .summaryMode(SummaryEnum.FALSE) + .returnBundle(Bundle.class) + .execute(); + assertEquals("http://localhost:" + ourPort + "/fhir/Patient?name=james&_summary=false", ourRequestUri); assertEquals(Patient.class, response.getEntry().get(0).getResource().getClass()); @@ -1706,9 +1659,7 @@ public class GenericJaxRsClientDstu2Test { resp.addEntry().getResponse().setLocation("Patient/2/_history/2"); String respString = ourCtx.newJsonParser().encodeResourceToString(resp); - - - + ourResponseContentType = Constants.CT_FHIR_JSON + "; charset=UTF-8"; ourResponseBody = respString; @@ -1725,12 +1676,12 @@ public class GenericJaxRsClientDstu2Test { p2.setId("http://example.com/Patient/2"); input.add(p2); - - List response = client.transaction() - .withResources(input) - .encodedJson() - .execute(); - + + List response = client.transaction() + .withResources(input) + .encodedJson() + .execute(); + assertEquals("http://localhost:" + ourPort + "/fhir", ourRequestUri); assertEquals(2, response.size()); @@ -1767,30 +1718,28 @@ public class GenericJaxRsClientDstu2Test { resp.addEntry().getResponse().setLocation("Patient/1/_history/1"); resp.addEntry().getResponse().setLocation("Patient/2/_history/2"); - - - + ourResponseContentType = Constants.CT_FHIR_JSON + "; charset=UTF-8"; ourResponseBody = reqString; IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort + "/fhir"); - + String response = client.transaction() .withBundle(reqString) .execute(); - + assertEquals("http://localhost:" + ourPort + "/fhir/", ourRequestUri); assertThat(response, containsString("\"Bundle\"")); assertEquals("application/json+fhir;charset=UTF-8", ourRequestFirstHeaders.get("Content-Type").getValue()); - - response = client.transaction() - .withBundle(reqString) - .encodedXml() - .execute(); - + + response = client.transaction() + .withBundle(reqString) + .encodedXml() + .execute(); + assertEquals("http://localhost:" + ourPort + "/fhir/", ourRequestUri); assertEquals("application/xml+fhir;charset=UTF-8", ourRequestFirstHeaders.get("Content-Type").getValue()); @@ -1805,9 +1754,7 @@ public class GenericJaxRsClientDstu2Test { resp.addEntry().getResponse().setLocation("Patient/2/_history/2"); String respString = ourCtx.newJsonParser().encodeResourceToString(resp); - - - + ourResponseContentType = Constants.CT_FHIR_JSON + "; charset=UTF-8"; ourResponseBody = respString; @@ -1824,12 +1771,12 @@ public class GenericJaxRsClientDstu2Test { p2.setId("Patient/2"); input.addEntry().setResource(p2); - - ca.uhn.fhir.model.dstu2.resource.Bundle response = client.transaction() - .withBundle(input) - .encodedJson() - .execute(); - + + ca.uhn.fhir.model.dstu2.resource.Bundle response = client.transaction() + .withBundle(input) + .encodedJson() + .execute(); + assertEquals("http://localhost:" + ourPort + "/fhir", ourRequestUri); assertEquals(2, response.getEntry().size()); @@ -1840,13 +1787,12 @@ public class GenericJaxRsClientDstu2Test { @Test public void testUpdateConditional() { - - + + ourResponseStatus = Constants.STATUS_HTTP_204_NO_CONTENT; - + IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort + "/fhir"); - Patient p = new Patient(); p.addName().addFamily("FOOFAMILY"); @@ -1857,7 +1803,7 @@ public class GenericJaxRsClientDstu2Test { assertThat(ourRequestBodyString, containsString("")); assertEquals("PUT", ourRequestMethod); assertEquals("http://localhost:" + ourPort + "/fhir/Patient?name=foo", ourRequestUri); - + client.update().resource(p).conditionalByUrl("Patient?name=http://foo|bar").encodedXml().execute(); assertEquals(1, ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE).size()); @@ -1865,7 +1811,7 @@ public class GenericJaxRsClientDstu2Test { assertThat(ourRequestBodyString, containsString("")); assertEquals("PUT", ourRequestMethod); assertEquals("http://localhost:" + ourPort + "/fhir/Patient?name=http%3A//foo%7Cbar", ourRequestUri); - + client.update().resource(ourCtx.newXmlParser().encodeResourceToString(p)).conditionalByUrl("Patient?name=foo").encodedXml().execute(); assertEquals(1, ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE).size()); @@ -1873,7 +1819,7 @@ public class GenericJaxRsClientDstu2Test { assertThat(ourRequestBodyString, containsString("")); assertEquals("PUT", ourRequestMethod); assertEquals("http://localhost:" + ourPort + "/fhir/Patient?name=foo", ourRequestUri); - + client.update().resource(p).conditional().where(Patient.NAME.matches().value("foo")).and(Patient.ADDRESS.matches().value("AAA|BBB")).encodedXml().execute(); assertEquals(1, ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE).size()); @@ -1881,7 +1827,7 @@ public class GenericJaxRsClientDstu2Test { assertThat(ourRequestBodyString, containsString("")); assertEquals("PUT", ourRequestMethod); assertEquals("http://localhost:" + ourPort + "/fhir/Patient?name=foo&address=AAA%5C%7CBBB", ourRequestUri); - + client.update().resource(ourCtx.newXmlParser().encodeResourceToString(p)).conditional().where(Patient.NAME.matches().value("foo")).and(Patient.ADDRESS.matches().value("AAA|BBB")).encodedXml().execute(); assertEquals(1, ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE).size()); @@ -1889,19 +1835,19 @@ public class GenericJaxRsClientDstu2Test { assertThat(ourRequestBodyString, containsString("")); assertEquals("PUT", ourRequestMethod); assertEquals("http://localhost:" + ourPort + "/fhir/Patient?name=foo&address=AAA%5C%7CBBB", ourRequestUri); - + } @Test public void testUpdateNonFluent() { - - + + ourResponseStatus = Constants.STATUS_HTTP_204_NO_CONTENT; IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort + "/fhir"); client.setEncoding(EncodingEnum.XML); - + Patient p = new Patient(); p.addName().addFamily("FOOFAMILY"); @@ -1912,7 +1858,7 @@ public class GenericJaxRsClientDstu2Test { assertThat(ourRequestBodyString, containsString("")); assertEquals("http://localhost:" + ourPort + "/fhir/Patient/123?_format=xml", ourRequestUri); assertEquals("PUT", ourRequestMethod); - + client.update("123", p); assertEquals(1, ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE).size()); @@ -1920,18 +1866,17 @@ public class GenericJaxRsClientDstu2Test { assertThat(ourRequestBodyString, containsString("")); assertEquals("http://localhost:" + ourPort + "/fhir/Patient/123?_format=xml", ourRequestUri); assertEquals("PUT", ourRequestMethod); - + } @Test public void testUpdatePrefer() { - - + + ourResponseStatus = Constants.STATUS_HTTP_204_NO_CONTENT; IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort + "/fhir"); - Patient p = new Patient(); p.setId(new IdDt("1")); @@ -1940,12 +1885,12 @@ public class GenericJaxRsClientDstu2Test { client.update().resource(p).prefer(PreferReturnEnum.MINIMAL).execute(); assertEquals(1, ourRequestHeaders.get(Constants.HEADER_PREFER).size()); assertEquals(Constants.HEADER_PREFER_RETURN + '=' + Constants.HEADER_PREFER_RETURN_MINIMAL, ourRequestHeaders.get(Constants.HEADER_PREFER).get(0).getValue()); - + client.update().resource(p).prefer(PreferReturnEnum.REPRESENTATION).execute(); assertEquals(1, ourRequestHeaders.get(Constants.HEADER_PREFER).size()); assertEquals(Constants.HEADER_PREFER_RETURN + '=' + Constants.HEADER_PREFER_RETURN_REPRESENTATION, ourRequestHeaders.get(Constants.HEADER_PREFER).get(0).getValue()); - + } @@ -1955,8 +1900,7 @@ public class GenericJaxRsClientDstu2Test { p.setId("123"); final String formatted = ourCtx.newXmlParser().encodeResourceToString(p); - - + ourResponseStatus = Constants.STATUS_HTTP_200_OK; ourResponseContentType = Constants.CT_FHIR_XML + "; charset=UTF-8"; ourResponseBody = formatted; @@ -1979,9 +1923,7 @@ public class GenericJaxRsClientDstu2Test { oo.addIssue().setDiagnostics("FOOBAR"); final String msg = ourCtx.newXmlParser().encodeResourceToString(oo); - - - + ourResponseContentType = Constants.CT_FHIR_XML + "; charset=UTF-8"; ourResponseBody = msg; @@ -1990,7 +1932,7 @@ public class GenericJaxRsClientDstu2Test { Patient p = new Patient(); p.addName().addGiven("GIVEN"); - + MethodOutcome response; response = client.validate().resource(p).encodedXml().execute(); @@ -1999,7 +1941,7 @@ public class GenericJaxRsClientDstu2Test { assertEquals("", ourRequestBodyString); assertNotNull(response.getOperationOutcome()); assertEquals("FOOBAR", toOo(response.getOperationOutcome()).getIssueFirstRep().getDiagnosticsElement().getValue()); - + response = client.validate().resource(ourCtx.newXmlParser().encodeResourceToString(p)).encodedXml().execute(); assertEquals("http://localhost:" + ourPort + "/fhir/Patient/$validate", ourRequestUri); @@ -2007,7 +1949,7 @@ public class GenericJaxRsClientDstu2Test { assertEquals("", ourRequestBodyString); assertNotNull(response.getOperationOutcome()); assertEquals("FOOBAR", toOo(response.getOperationOutcome()).getIssueFirstRep().getDiagnosticsElement().getValue()); - + response = client.validate().resource(ourCtx.newJsonParser().encodeResourceToString(p)).execute(); assertEquals("http://localhost:" + ourPort + "/fhir/Patient/$validate", ourRequestUri); @@ -2015,7 +1957,7 @@ public class GenericJaxRsClientDstu2Test { assertEquals("{\"resourceType\":\"Parameters\",\"parameter\":[{\"name\":\"resource\",\"resource\":{\"resourceType\":\"Patient\",\"name\":[{\"given\":[\"GIVEN\"]}]}}]}", ourRequestBodyString); assertNotNull(response.getOperationOutcome()); assertEquals("FOOBAR", toOo(response.getOperationOutcome()).getIssueFirstRep().getDiagnosticsElement().getValue()); - + response = client.validate().resource(ourCtx.newJsonParser().encodeResourceToString(p)).prettyPrint().execute(); assertEquals("http://localhost:" + ourPort + "/fhir/Patient/$validate?_pretty=true", ourRequestUri); @@ -2023,7 +1965,7 @@ public class GenericJaxRsClientDstu2Test { assertThat(ourRequestBodyString, containsString("\"resourceType\": \"Parameters\",\n")); assertNotNull(response.getOperationOutcome()); assertEquals("FOOBAR", toOo(response.getOperationOutcome()).getIssueFirstRep().getDiagnosticsElement().getValue()); - + } @Test @@ -2031,7 +1973,7 @@ public class GenericJaxRsClientDstu2Test { OperationOutcome oo = new OperationOutcome(); oo.addIssue().setDiagnostics("FOOBAR"); final String msg = ourCtx.newXmlParser().encodeResourceToString(oo); - + ourResponseContentType = Constants.CT_FHIR_XML + "; charset=UTF-8"; ourResponseBody = msg; @@ -2041,26 +1983,26 @@ public class GenericJaxRsClientDstu2Test { Patient p = new Patient(); p.addName().addGiven("GIVEN"); - + MethodOutcome response; - + response = client.validate(p); - + assertEquals("http://localhost:" + ourPort + "/fhir/Patient/$validate?_format=xml", ourRequestUri); assertEquals("POST", ourRequestMethod); assertEquals("", ourRequestBodyString); assertNotNull(response.getOperationOutcome()); assertEquals("FOOBAR", toOo(response.getOperationOutcome()).getIssueFirstRep().getDiagnosticsElement().getValue()); - + } private OperationOutcome toOo(IBaseOperationOutcome theOperationOutcome) { return (OperationOutcome) theOperationOutcome; } - @Before + @BeforeEach public void beforeReset() { ourRequestUri = null; ourRequestUriAll = Lists.newArrayList(); @@ -2068,7 +2010,7 @@ public class GenericJaxRsClientDstu2Test { ourResponseBody = null; ourResponseBodies = null; ourResponseCount = 0; - + ourResponseContentType = null; ourRequestContentType = null; ourRequestBodyBytes = null; @@ -2078,20 +2020,11 @@ public class GenericJaxRsClientDstu2Test { ourRequestMethod = null; ourRequestHeadersAll = Lists.newArrayList(); } - - private static List ourRequestUriAll; - private static String ourRequestMethod; - private static String ourRequestContentType; - private static byte[] ourRequestBodyBytes; - private static String ourRequestBodyString; - private static ArrayListMultimap ourRequestHeaders; - private static List> ourRequestHeadersAll; - private static Map ourRequestFirstHeaders; - - @BeforeClass + + @BeforeAll public static void beforeClass() throws Exception { ourCtx = FhirContext.forDstu2(); - + ourServer = new Server(0); ourServer.setHandler(new AbstractHandler() { @@ -2104,24 +2037,24 @@ public class GenericJaxRsClientDstu2Test { ourRequestContentType = theServletRequest.getContentType(); ourRequestBodyBytes = IOUtils.toByteArray(theServletRequest.getInputStream()); ourRequestBodyString = new String(ourRequestBodyBytes, Charsets.UTF_8); - + ourRequestHeaders = ArrayListMultimap.create(); ourRequestHeadersAll.add(ourRequestHeaders); ourRequestFirstHeaders = Maps.newHashMap(); - + for (Enumeration headerNameEnum = theRequest.getHeaderNames(); headerNameEnum.hasMoreElements(); ) { String nextName = headerNameEnum.nextElement(); for (Enumeration headerValueEnum = theRequest.getHeaders(nextName); headerValueEnum.hasMoreElements(); ) { String nextValue = headerValueEnum.nextElement(); - if (ourRequestFirstHeaders.containsKey(nextName)==false) { + if (ourRequestFirstHeaders.containsKey(nextName) == false) { ourRequestFirstHeaders.put(nextName, new Header(nextName, nextValue)); } ourRequestHeaders.put(nextName, new Header(nextName, nextValue)); } } - + theResp.setStatus(ourResponseStatus); - + if (ourResponseBody != null) { theResp.setContentType(ourResponseContentType); theResp.getWriter().write(ourResponseBody); @@ -2129,16 +2062,16 @@ public class GenericJaxRsClientDstu2Test { theResp.setContentType(ourResponseContentType); theResp.getWriter().write(ourResponseBodies[ourResponseCount]); } - + ourResponseCount++; } }); - + JettyUtil.startServer(ourServer); - ourPort = JettyUtil.getPortForStartedServer(ourServer); + ourPort = JettyUtil.getPortForStartedServer(ourServer); } - @AfterClass + @AfterAll public static void afterClass() throws Exception { JettyUtil.closeServer(ourServer); } diff --git a/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/client/GenericJaxRsClientDstu3Test.java b/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/client/GenericJaxRsClientDstu3Test.java index ef0512ee1be..71624ea0654 100644 --- a/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/client/GenericJaxRsClientDstu3Test.java +++ b/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/client/GenericJaxRsClientDstu3Test.java @@ -1,56 +1,103 @@ package ca.uhn.fhir.jaxrs.client; -import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; - -import java.io.IOException; -import java.util.*; -import java.util.Enumeration; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.apache.commons.io.Charsets; -import org.apache.commons.io.IOUtils; -import org.eclipse.jetty.server.Request; -import org.eclipse.jetty.server.Server; -import org.eclipse.jetty.server.handler.AbstractHandler; -import org.hl7.fhir.dstu3.model.*; -import org.hl7.fhir.dstu3.model.Bundle.*; -import org.hl7.fhir.instance.model.api.*; -import org.junit.*; - -import com.google.common.collect.*; - import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.api.Include; import ca.uhn.fhir.model.primitive.UriDt; import ca.uhn.fhir.parser.IParser; -import ca.uhn.fhir.rest.api.*; import ca.uhn.fhir.rest.api.Constants; -import ca.uhn.fhir.rest.client.api.*; +import ca.uhn.fhir.rest.api.EncodingEnum; +import ca.uhn.fhir.rest.api.MethodOutcome; +import ca.uhn.fhir.rest.api.PreferReturnEnum; +import ca.uhn.fhir.rest.api.SearchStyleEnum; +import ca.uhn.fhir.rest.api.SummaryEnum; +import ca.uhn.fhir.rest.client.api.Header; +import ca.uhn.fhir.rest.client.api.IGenericClient; +import ca.uhn.fhir.rest.client.api.ServerValidationModeEnum; import ca.uhn.fhir.rest.client.exceptions.InvalidResponseException; import ca.uhn.fhir.rest.client.interceptor.LoggingInterceptor; import ca.uhn.fhir.rest.param.DateRangeParam; import ca.uhn.fhir.test.utilities.JettyUtil; +import com.google.common.collect.ArrayListMultimap; +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; +import org.apache.commons.io.Charsets; +import org.apache.commons.io.IOUtils; +import org.eclipse.jetty.server.Request; +import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.server.handler.AbstractHandler; +import org.hl7.fhir.dstu3.model.Bundle; +import org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent; +import org.hl7.fhir.dstu3.model.Bundle.BundleLinkComponent; +import org.hl7.fhir.dstu3.model.Bundle.BundleType; +import org.hl7.fhir.dstu3.model.Bundle.HTTPVerb; +import org.hl7.fhir.dstu3.model.CapabilityStatement; +import org.hl7.fhir.dstu3.model.CodeType; +import org.hl7.fhir.dstu3.model.DateTimeType; +import org.hl7.fhir.dstu3.model.DateType; +import org.hl7.fhir.dstu3.model.IdType; +import org.hl7.fhir.dstu3.model.Identifier; +import org.hl7.fhir.dstu3.model.InstantType; +import org.hl7.fhir.dstu3.model.Meta; +import org.hl7.fhir.dstu3.model.Observation; +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.dstu3.model.Quantity; +import org.hl7.fhir.dstu3.model.StringType; +import org.hl7.fhir.dstu3.model.UriType; +import org.hl7.fhir.instance.model.api.IBase; +import org.hl7.fhir.instance.model.api.IBaseBundle; +import org.hl7.fhir.instance.model.api.IBaseResource; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Date; +import java.util.Enumeration; +import java.util.List; +import java.util.Map; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.either; +import static org.hamcrest.Matchers.emptyString; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.not; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.fail; public class GenericJaxRsClientDstu3Test { + private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(GenericJaxRsClientDstu3Test.class); private static FhirContext ourCtx; private static int ourPort; private static Server ourServer; - private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(GenericJaxRsClientDstu3Test.class); private static int ourResponseCount = 0; private static String[] ourResponseBodies; private static String ourResponseBody; private static String ourResponseContentType; private static int ourResponseStatus; private static String ourRequestUri; - - @Before + private static List ourRequestUriAll; + private static String ourRequestMethod; + private static String ourRequestContentType; + private static byte[] ourRequestBodyBytes; + private static String ourRequestBodyString; + private static ArrayListMultimap ourRequestHeaders; + private static List> ourRequestHeadersAll; + private static Map ourRequestFirstHeaders; + + @BeforeEach public void before() { JaxRsRestfulClientFactory clientFactory = new JaxRsRestfulClientFactory(ourCtx); clientFactory.setServerValidationMode(ServerValidationModeEnum.NEVER); - + ourCtx.setRestfulClientFactory(clientFactory); ourResponseCount = 0; System.setProperty("hapi.client.keepresponses", "true"); @@ -58,21 +105,21 @@ public class GenericJaxRsClientDstu3Test { private String getPatientFeedWithOneResult() { //@formatter:off - String msg = "\n" + - "d039f91a-cc3c-4013-988e-af4d8d0614bd\n" + - "\n" + - "" - + "" - + "
John Cardinal: 444333333
" - + "" - + "" - + "" - + "" - + "
" - + "
" - + "
\n" - + "
\n" - + "
"; + String msg = "\n" + + "d039f91a-cc3c-4013-988e-af4d8d0614bd\n" + + "\n" + + "" + + "" + + "
John Cardinal: 444333333
" + + "" + + "" + + "" + + "" + + "
" + + "
" + + "
\n" + + "
\n" + + "
"; //@formatter:on return msg; } @@ -87,28 +134,27 @@ public class GenericJaxRsClientDstu3Test { final String respString = p.encodeResourceToString(conf); ourResponseContentType = Constants.CT_FHIR_XML + "; charset=UTF-8"; ourResponseBody = respString; - + IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort + "/fhir"); - client.fetchConformance().ofType(CapabilityStatement.class).execute(); assertEquals("http://localhost:" + ourPort + "/fhir/metadata", ourRequestUri); assertEquals(1, ourRequestHeaders.get("Accept").size()); assertThat(ourRequestHeaders.get("Accept").get(0).getValue(), containsString(Constants.HEADER_ACCEPT_VALUE_XML_OR_JSON_NON_LEGACY)); - + client.fetchConformance().ofType(CapabilityStatement.class).encodedJson().execute(); assertEquals("http://localhost:" + ourPort + "/fhir/metadata?_format=json", ourRequestUri); assertEquals(1, ourRequestHeaders.get("Accept").size()); assertThat(ourRequestHeaders.get("Accept").get(0).getValue(), containsString(Constants.CT_FHIR_JSON)); - + client.fetchConformance().ofType(CapabilityStatement.class).encodedXml().execute(); assertEquals("http://localhost:" + ourPort + "/fhir/metadata?_format=xml", ourRequestUri); assertEquals(1, ourRequestHeaders.get("Accept").size()); assertThat(ourRequestHeaders.get("Accept").get(0).getValue(), containsString(Constants.CT_FHIR_XML)); - + } @Test @@ -122,7 +168,7 @@ public class GenericJaxRsClientDstu3Test { patient.addName().setFamily("FAMILY"); ourResponseContentType = Constants.CT_FHIR_XML + "; charset=UTF-8"; - ourResponseBodies = new String[] { p.encodeResourceToString(conf), p.encodeResourceToString(patient) }; + ourResponseBodies = new String[]{p.encodeResourceToString(conf), p.encodeResourceToString(patient)}; ourCtx.getRestfulClientFactory().setServerValidationMode(ServerValidationModeEnum.ONCE); IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort + "/fhir"); @@ -152,7 +198,7 @@ public class GenericJaxRsClientDstu3Test { patient.addName().setFamily("FAMILY"); ourResponseContentType = Constants.CT_FHIR_XML + "; charset=UTF-8"; - ourResponseBodies = new String[] { p.encodeResourceToString(conf), p.encodeResourceToString(patient) }; + ourResponseBodies = new String[]{p.encodeResourceToString(conf), p.encodeResourceToString(patient)}; ourCtx.getRestfulClientFactory().setServerValidationMode(ServerValidationModeEnum.ONCE); IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort + "/fhir"); @@ -178,13 +224,12 @@ public class GenericJaxRsClientDstu3Test { conf.setCopyright("COPY"); final String respString = p.encodeResourceToString(conf); - + ourResponseContentType = Constants.CT_FHIR_XML + "; charset=UTF-8"; ourResponseBody = respString; IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort + "/fhir"); - //@formatter:off CapabilityStatement resp = client.fetchConformance().ofType(CapabilityStatement.class).execute(); @@ -193,7 +238,7 @@ public class GenericJaxRsClientDstu3Test { assertEquals("http://localhost:" + ourPort + "/fhir/metadata", ourRequestUri); assertEquals("COPY", resp.getCopyright()); assertEquals("GET", ourRequestMethod); - + } @@ -201,7 +246,7 @@ public class GenericJaxRsClientDstu3Test { public void testProviderWhereWeForgotToSetTheContext() { JaxRsRestfulClientFactory clientFactory = new JaxRsRestfulClientFactory(); // no ctx clientFactory.setServerValidationMode(ServerValidationModeEnum.NEVER); - + ourCtx.setRestfulClientFactory(clientFactory); try { @@ -211,13 +256,11 @@ public class GenericJaxRsClientDstu3Test { assertEquals("JaxRsRestfulClientFactory does not have FhirContext defined. This must be set via JaxRsRestfulClientFactory#setFhirContext(FhirContext)", e.getMessage()); } } - - + @Test public void testCreate() { IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort + "/fhir"); - Patient p = new Patient(); p.addName().setFamily("FOOFAMILY"); @@ -229,7 +272,7 @@ public class GenericJaxRsClientDstu3Test { assertThat(ourRequestBodyString, containsString("")); assertEquals("http://localhost:" + ourPort + "/fhir/Patient", ourRequestUri); assertEquals("POST", ourRequestMethod); - + p.setId("123"); @@ -241,19 +284,18 @@ public class GenericJaxRsClientDstu3Test { assertThat(body, not(containsString("123"))); assertEquals("http://localhost:" + ourPort + "/fhir/Patient", ourRequestUri); assertEquals("POST", ourRequestMethod); - + } @Test public void testCreateConditional() { - - + + ourResponseStatus = Constants.STATUS_HTTP_204_NO_CONTENT; IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort + "/fhir"); - Patient p = new Patient(); p.addName().setFamily("FOOFAMILY"); @@ -265,7 +307,7 @@ public class GenericJaxRsClientDstu3Test { assertEquals("http://localhost:" + ourPort + "/fhir/Patient", ourRequestUri); assertEquals("http://localhost:" + ourPort + "/fhir/Patient?name=foo", ourRequestFirstHeaders.get(Constants.HEADER_IF_NONE_EXIST).getValue()); assertEquals("POST", ourRequestMethod); - + client.create().resource(p).conditionalByUrl("Patient?name=http://foo|bar").encodedXml().execute(); assertEquals(1, ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE).size()); @@ -274,7 +316,7 @@ public class GenericJaxRsClientDstu3Test { assertEquals("http://localhost:" + ourPort + "/fhir/Patient", ourRequestUri); assertEquals("http://localhost:" + ourPort + "/fhir/Patient?name=http%3A//foo%7Cbar", ourRequestFirstHeaders.get(Constants.HEADER_IF_NONE_EXIST).getValue()); assertEquals("POST", ourRequestMethod); - + client.create().resource(p).conditional().where(Patient.NAME.matches().value("foo")).encodedXml().execute(); assertEquals(1, ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE).size()); @@ -283,7 +325,7 @@ public class GenericJaxRsClientDstu3Test { assertEquals("http://localhost:" + ourPort + "/fhir/Patient", ourRequestUri); assertEquals("http://localhost:" + ourPort + "/fhir/Patient?name=foo", ourRequestFirstHeaders.get(Constants.HEADER_IF_NONE_EXIST).getValue()); assertEquals("POST", ourRequestMethod); - + } @@ -293,7 +335,6 @@ public class GenericJaxRsClientDstu3Test { IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort + "/fhir"); - Patient p = new Patient(); p.addName().setFamily("FOOFAMILY"); @@ -305,18 +346,17 @@ public class GenericJaxRsClientDstu3Test { assertThat(ourRequestBodyString, containsString("")); assertEquals("http://localhost:" + ourPort + "/fhir/Patient", ourRequestUri); assertEquals("POST", ourRequestMethod); - + } @Test public void testCreatePrefer() { - - + + ourResponseStatus = Constants.STATUS_HTTP_204_NO_CONTENT; IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort + "/fhir"); - Patient p = new Patient(); p.addName().setFamily("FOOFAMILY"); @@ -324,12 +364,12 @@ public class GenericJaxRsClientDstu3Test { client.create().resource(p).prefer(PreferReturnEnum.MINIMAL).execute(); assertEquals(1, ourRequestHeaders.get(Constants.HEADER_PREFER).size()); assertEquals(Constants.HEADER_PREFER_RETURN + '=' + Constants.HEADER_PREFER_RETURN_MINIMAL, ourRequestHeaders.get(Constants.HEADER_PREFER).get(0).getValue()); - + client.create().resource(p).prefer(PreferReturnEnum.REPRESENTATION).execute(); assertEquals(1, ourRequestHeaders.get(Constants.HEADER_PREFER).size()); assertEquals(Constants.HEADER_PREFER_RETURN + '=' + Constants.HEADER_PREFER_RETURN_REPRESENTATION, ourRequestHeaders.get(Constants.HEADER_PREFER).get(0).getValue()); - + } @@ -339,8 +379,7 @@ public class GenericJaxRsClientDstu3Test { p.setId("123"); final String formatted = ourCtx.newXmlParser().encodeResourceToString(p); - - + ourResponseStatus = Constants.STATUS_HTTP_200_OK; ourResponseContentType = Constants.CT_FHIR_XML + "; charset=UTF-8"; ourResponseBody = formatted; @@ -362,22 +401,21 @@ public class GenericJaxRsClientDstu3Test { IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort + "/fhir"); - client.delete().resourceById(new IdType("Patient/123")).execute(); assertEquals("DELETE", ourRequestMethod); assertEquals("http://localhost:" + ourPort + "/fhir/Patient/123", ourRequestUri); - + client.delete().resourceConditionalByUrl("Patient?name=foo").execute(); assertEquals("DELETE", ourRequestMethod); assertEquals("http://localhost:" + ourPort + "/fhir/Patient?name=foo", ourRequestUri); - + client.delete().resourceConditionalByType("Patient").where(Patient.NAME.matches().value("foo")).execute(); assertEquals("DELETE", ourRequestMethod); assertEquals("http://localhost:" + ourPort + "/fhir/Patient?name=foo", ourRequestUri); - + } @@ -385,22 +423,21 @@ public class GenericJaxRsClientDstu3Test { @Test public void testDeleteNonFluent() { ourResponseStatus = Constants.STATUS_HTTP_204_NO_CONTENT; - + IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort + "/fhir"); - client.delete().resourceById(new IdType("Patient/123")).execute(); assertEquals("DELETE", ourRequestMethod); assertEquals("http://localhost:" + ourPort + "/fhir/Patient/123", ourRequestUri); - + } @Test public void testHistory() { final String msg = getPatientFeedWithOneResult(); - + ourResponseContentType = Constants.CT_FHIR_XML + "; charset=UTF-8"; ourResponseBody = msg; @@ -410,86 +447,86 @@ public class GenericJaxRsClientDstu3Test { //@formatter:off response = client - .history() - .onServer() - .andReturnBundle(org.hl7.fhir.dstu3.model.Bundle.class) - .execute(); + .history() + .onServer() + .andReturnBundle(org.hl7.fhir.dstu3.model.Bundle.class) + .execute(); //@formatter:on assertEquals("http://localhost:" + ourPort + "/fhir/_history", ourRequestUri); assertEquals(1, response.getEntry().size()); - + //@formatter:off response = client - .history() - .onServer() - .andReturnBundle(org.hl7.fhir.dstu3.model.Bundle.class) - .since((Date)null) - .count(null) - .execute(); + .history() + .onServer() + .andReturnBundle(org.hl7.fhir.dstu3.model.Bundle.class) + .since((Date) null) + .count(null) + .execute(); //@formatter:on assertEquals("http://localhost:" + ourPort + "/fhir/_history", ourRequestUri); assertEquals(1, response.getEntry().size()); - + //@formatter:off response = client - .history() - .onServer() - .andReturnBundle(org.hl7.fhir.dstu3.model.Bundle.class) - .since(new InstantType()) - .execute(); + .history() + .onServer() + .andReturnBundle(org.hl7.fhir.dstu3.model.Bundle.class) + .since(new InstantType()) + .execute(); //@formatter:on assertEquals("http://localhost:" + ourPort + "/fhir/_history", ourRequestUri); assertEquals(1, response.getEntry().size()); - + //@formatter:off response = client - .history() - .onType(Patient.class) - .andReturnBundle(org.hl7.fhir.dstu3.model.Bundle.class) - .execute(); + .history() + .onType(Patient.class) + .andReturnBundle(org.hl7.fhir.dstu3.model.Bundle.class) + .execute(); //@formatter:on assertEquals("http://localhost:" + ourPort + "/fhir/Patient/_history", ourRequestUri); assertEquals(1, response.getEntry().size()); - + //@formatter:off response = client - .history() - .onInstance(new IdType("Patient", "123")) - .andReturnBundle(org.hl7.fhir.dstu3.model.Bundle.class) - .execute(); + .history() + .onInstance(new IdType("Patient", "123")) + .andReturnBundle(org.hl7.fhir.dstu3.model.Bundle.class) + .execute(); //@formatter:on assertEquals("http://localhost:" + ourPort + "/fhir/Patient/123/_history", ourRequestUri); assertEquals(1, response.getEntry().size()); - + //@formatter:off response = client - .history() - .onInstance(new IdType("Patient", "123")) - .andReturnBundle(org.hl7.fhir.dstu3.model.Bundle.class) - .count(123) - .since(new InstantType("2001-01-02T11:22:33Z")) - .execute(); + .history() + .onInstance(new IdType("Patient", "123")) + .andReturnBundle(org.hl7.fhir.dstu3.model.Bundle.class) + .count(123) + .since(new InstantType("2001-01-02T11:22:33Z")) + .execute(); //@formatter:on assertThat(ourRequestUri, either(equalTo("http://localhost:" + ourPort + "/fhir/Patient/123/_history?_since=2001-01-02T11:22:33Z&_count=123")).or(equalTo("http://localhost:" + ourPort + "/fhir/Patient/123/_history?_count=123&_since=2001-01-02T11:22:33Z"))); assertEquals(1, response.getEntry().size()); - + //@formatter:off response = client - .history() - .onInstance(new IdType("Patient", "123")) - .andReturnBundle(org.hl7.fhir.dstu3.model.Bundle.class) - .since(new InstantType("2001-01-02T11:22:33Z").getValue()) - .execute(); + .history() + .onInstance(new IdType("Patient", "123")) + .andReturnBundle(org.hl7.fhir.dstu3.model.Bundle.class) + .since(new InstantType("2001-01-02T11:22:33Z").getValue()) + .execute(); //@formatter:on assertThat(ourRequestUri, containsString("_since=2001-01")); assertEquals(1, response.getEntry().size()); - + } @Test @@ -501,28 +538,27 @@ public class GenericJaxRsClientDstu3Test { Parameters outParams = new Parameters(); outParams.addParameter().setName("meta").setValue(new Meta().addProfile("urn:profile:out")); final String respString = p.encodeResourceToString(outParams); - + ourResponseContentType = Constants.CT_FHIR_XML + "; charset=UTF-8"; ourResponseBody = respString; IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort + "/fhir"); - //@formatter:off Meta resp = client - .meta() - .add() - .onResource(new IdType("Patient/123")) - .meta(inMeta) - .encodedXml() - .execute(); + .meta() + .add() + .onResource(new IdType("Patient/123")) + .meta(inMeta) + .encodedXml() + .execute(); //@formatter:on assertEquals("http://localhost:" + ourPort + "/fhir/Patient/123/$meta-add", ourRequestUri); assertEquals("urn:profile:out", resp.getProfile().get(0).getValue()); assertEquals("POST", ourRequestMethod); assertEquals("", ourRequestBodyString); - + } @@ -542,43 +578,42 @@ public class GenericJaxRsClientDstu3Test { IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort + "/fhir"); - //@formatter:off Meta resp = client - .meta() - .get(Meta.class) - .fromServer() - .execute(); + .meta() + .get(Meta.class) + .fromServer() + .execute(); //@formatter:on assertEquals("http://localhost:" + ourPort + "/fhir/$meta", ourRequestUri); assertEquals("urn:profile:out", resp.getProfile().get(0).getValue()); assertEquals("GET", ourRequestMethod); - + //@formatter:off resp = client - .meta() - .get(Meta.class) - .fromType("Patient") - .execute(); + .meta() + .get(Meta.class) + .fromType("Patient") + .execute(); //@formatter:on assertEquals("http://localhost:" + ourPort + "/fhir/Patient/$meta", ourRequestUri); assertEquals("urn:profile:out", resp.getProfile().get(0).getValue()); assertEquals("GET", ourRequestMethod); - + //@formatter:off resp = client - .meta() - .get(Meta.class) - .fromResource(new IdType("Patient/123")) - .execute(); + .meta() + .get(Meta.class) + .fromResource(new IdType("Patient/123")) + .execute(); //@formatter:on assertEquals("http://localhost:" + ourPort + "/fhir/Patient/123/$meta", ourRequestUri); assertEquals("urn:profile:out", resp.getProfile().get(0).getValue()); assertEquals("GET", ourRequestMethod); - + } @@ -596,69 +631,66 @@ public class GenericJaxRsClientDstu3Test { outParams.addParameter().setValue(new StringType("STRINGVALOUT2")); final String respString = p.encodeResourceToString(outParams); - - - + ourResponseContentType = Constants.CT_FHIR_XML + "; charset=UTF-8"; ourResponseBody = respString; IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort + "/fhir"); - //@formatter:off Parameters resp = client - .operation() - .onServer() - .named("$SOMEOPERATION") - .withParameters(inParams) - .useHttpGet() - .execute(); + .operation() + .onServer() + .named("$SOMEOPERATION") + .withParameters(inParams) + .useHttpGet() + .execute(); //@formatter:on assertEquals("http://localhost:" + ourPort + "/fhir/$SOMEOPERATION?param1=STRINGVALIN1¶m1=STRINGVALIN1b¶m2=STRINGVALIN2", ourRequestUri); assertEquals(respString, p.encodeResourceToString(resp)); assertEquals("GET", ourRequestMethod); - + //@formatter:off resp = client - .operation() - .onType(Patient.class) - .named("$SOMEOPERATION") - .withParameters(inParams) - .useHttpGet() - .execute(); - //@formatter:on + .operation() + .onType(Patient.class) + .named("$SOMEOPERATION") + .withParameters(inParams) + .useHttpGet() + .execute(); + //@formatter:on assertEquals("http://localhost:" + ourPort + "/fhir/Patient/$SOMEOPERATION?param1=STRINGVALIN1¶m1=STRINGVALIN1b¶m2=STRINGVALIN2", ourRequestUri); assertEquals(respString, p.encodeResourceToString(resp)); assertEquals("GET", ourRequestMethod); - + //@formatter:off resp = client - .operation() - .onInstance(new IdType("Patient", "123")) - .named("$SOMEOPERATION") - .withParameters(inParams) - .useHttpGet() - .execute(); - //@formatter:on + .operation() + .onInstance(new IdType("Patient", "123")) + .named("$SOMEOPERATION") + .withParameters(inParams) + .useHttpGet() + .execute(); + //@formatter:on assertEquals("http://localhost:" + ourPort + "/fhir/Patient/123/$SOMEOPERATION?param1=STRINGVALIN1¶m1=STRINGVALIN1b¶m2=STRINGVALIN2", ourRequestUri); assertEquals(respString, p.encodeResourceToString(resp)); assertEquals("GET", ourRequestMethod); - + // @formatter:off resp = client - .operation() - .onInstance(new IdType("http://foo.com/bar/baz/Patient/123/_history/22")) - .named("$SOMEOPERATION") - .withParameters(inParams) - .useHttpGet() - .execute(); + .operation() + .onInstance(new IdType("http://foo.com/bar/baz/Patient/123/_history/22")) + .named("$SOMEOPERATION") + .withParameters(inParams) + .useHttpGet() + .execute(); // @formatter:on assertEquals("http://localhost:" + ourPort + "/fhir/Patient/123/$SOMEOPERATION?param1=STRINGVALIN1¶m1=STRINGVALIN1b¶m2=STRINGVALIN2", ourRequestUri); - + } @Test @@ -669,67 +701,66 @@ public class GenericJaxRsClientDstu3Test { outParams.addParameter().setValue(new StringType("STRINGVALOUT1")); outParams.addParameter().setValue(new StringType("STRINGVALOUT2")); final String respString = p.encodeResourceToString(outParams); - + ourResponseContentType = Constants.CT_FHIR_XML + "; charset=UTF-8"; ourResponseBody = respString; IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort + "/fhir"); - //@formatter:off Parameters resp = client - .operation() - .onServer() - .named("$SOMEOPERATION") - .withNoParameters(Parameters.class) - .useHttpGet() - .execute(); + .operation() + .onServer() + .named("$SOMEOPERATION") + .withNoParameters(Parameters.class) + .useHttpGet() + .execute(); //@formatter:on assertEquals("http://localhost:" + ourPort + "/fhir/$SOMEOPERATION", ourRequestUri); assertEquals(respString, p.encodeResourceToString(resp)); assertEquals("GET", ourRequestMethod); - + //@formatter:off resp = client - .operation() - .onType(Patient.class) - .named("$SOMEOPERATION") - .withNoParameters(Parameters.class) - .useHttpGet() - .execute(); - //@formatter:on + .operation() + .onType(Patient.class) + .named("$SOMEOPERATION") + .withNoParameters(Parameters.class) + .useHttpGet() + .execute(); + //@formatter:on assertEquals("http://localhost:" + ourPort + "/fhir/Patient/$SOMEOPERATION", ourRequestUri); assertEquals(respString, p.encodeResourceToString(resp)); assertEquals("GET", ourRequestMethod); - + //@formatter:off resp = client - .operation() - .onInstance(new IdType("Patient", "123")) - .named("$SOMEOPERATION") - .withNoParameters(Parameters.class) - .useHttpGet() - .execute(); - //@formatter:on + .operation() + .onInstance(new IdType("Patient", "123")) + .named("$SOMEOPERATION") + .withNoParameters(Parameters.class) + .useHttpGet() + .execute(); + //@formatter:on assertEquals("http://localhost:" + ourPort + "/fhir/Patient/123/$SOMEOPERATION", ourRequestUri); assertEquals(respString, p.encodeResourceToString(resp)); assertEquals("GET", ourRequestMethod); - + // @formatter:off resp = client - .operation() - .onInstance(new IdType("http://foo.com/bar/baz/Patient/123/_history/22")) - .named("$SOMEOPERATION") - .withNoParameters(Parameters.class) - .useHttpGet() - .execute(); + .operation() + .onInstance(new IdType("http://foo.com/bar/baz/Patient/123/_history/22")) + .named("$SOMEOPERATION") + .withNoParameters(Parameters.class) + .useHttpGet() + .execute(); // @formatter:on assertEquals("http://localhost:" + ourPort + "/fhir/Patient/123/$SOMEOPERATION", ourRequestUri); - + } @Test @@ -780,16 +811,15 @@ public class GenericJaxRsClientDstu3Test { IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort + "/fhir"); - //@formatter:off Parameters resp = client - .operation() - .onServer() - .named("$SOMEOPERATION") - .withParameters(inParams) - .encodedXml() - .execute(); + .operation() + .onServer() + .named("$SOMEOPERATION") + .withParameters(inParams) + .encodedXml() + .execute(); //@formatter:on assertEquals("http://localhost:" + ourPort + "/fhir/$SOMEOPERATION", ourRequestUri); assertEquals(1, ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE).size()); @@ -798,7 +828,7 @@ public class GenericJaxRsClientDstu3Test { assertEquals("POST", ourRequestMethod); assertEquals(1, resp.getParameter().size()); assertEquals(org.hl7.fhir.dstu3.model.Bundle.class, resp.getParameter().get(0).getResource().getClass()); - + } @Test @@ -809,23 +839,22 @@ public class GenericJaxRsClientDstu3Test { outParams.addParameter().setValue(new StringType("STRINGVALOUT1")); outParams.addParameter().setValue(new StringType("STRINGVALOUT2")); final String respString = p.encodeResourceToString(outParams); - + ourResponseContentType = Constants.CT_FHIR_XML + "; charset=UTF-8"; ourResponseBody = respString; IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort + "/fhir"); - //@formatter:off Parameters resp = client - .operation() - .onServer() - .named("$SOMEOPERATION") - .withParameter(Parameters.class, "name1", new StringType("value1")) - .andParameter("name2", new StringType("value1")) - .encodedXml() - .execute(); + .operation() + .onServer() + .named("$SOMEOPERATION") + .withParameter(Parameters.class, "name1", new StringType("value1")) + .andParameter("name2", new StringType("value1")) + .encodedXml() + .execute(); //@formatter:on assertEquals("http://localhost:" + ourPort + "/fhir/$SOMEOPERATION", ourRequestUri); assertEquals(respString, p.encodeResourceToString(resp)); @@ -833,7 +862,7 @@ public class GenericJaxRsClientDstu3Test { assertEquals(EncodingEnum.XML.getResourceContentTypeNonLegacy() + Constants.HEADER_SUFFIX_CT_UTF_8, ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char")); assertEquals("POST", ourRequestMethod); assertEquals("", (ourRequestBodyString)); - + /* * Composite type @@ -841,13 +870,13 @@ public class GenericJaxRsClientDstu3Test { //@formatter:off resp = client - .operation() - .onServer() - .named("$SOMEOPERATION") - .withParameter(Parameters.class, "name1", new Identifier().setSystem("system1").setValue("value1")) - .andParameter("name2", new StringType("value1")) + .operation() + .onServer() + .named("$SOMEOPERATION") + .withParameter(Parameters.class, "name1", new Identifier().setSystem("system1").setValue("value1")) + .andParameter("name2", new StringType("value1")) .encodedXml() - .execute(); + .execute(); //@formatter:on assertEquals("http://localhost:" + ourPort + "/fhir/$SOMEOPERATION", ourRequestUri); assertEquals(respString, p.encodeResourceToString(resp)); @@ -855,8 +884,8 @@ public class GenericJaxRsClientDstu3Test { assertEquals(EncodingEnum.XML.getResourceContentTypeNonLegacy() + Constants.HEADER_SUFFIX_CT_UTF_8, ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char")); assertEquals("POST", ourRequestMethod); assertEquals("", - (ourRequestBodyString)); - + (ourRequestBodyString)); + /* * Resource @@ -864,13 +893,13 @@ public class GenericJaxRsClientDstu3Test { //@formatter:off resp = client - .operation() - .onServer() - .named("$SOMEOPERATION") - .withParameter(Parameters.class, "name1", new Identifier().setSystem("system1").setValue("value1")) - .andParameter("name2", new Patient().setActive(true)) - .encodedXml() - .execute(); + .operation() + .onServer() + .named("$SOMEOPERATION") + .withParameter(Parameters.class, "name1", new Identifier().setSystem("system1").setValue("value1")) + .andParameter("name2", new Patient().setActive(true)) + .encodedXml() + .execute(); //@formatter:on assertEquals("http://localhost:" + ourPort + "/fhir/$SOMEOPERATION", ourRequestUri); assertEquals(respString, p.encodeResourceToString(resp)); @@ -878,13 +907,13 @@ public class GenericJaxRsClientDstu3Test { assertEquals(EncodingEnum.XML.getResourceContentTypeNonLegacy() + Constants.HEADER_SUFFIX_CT_UTF_8, ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char")); assertEquals("POST", ourRequestMethod); assertEquals( - "", - (ourRequestBodyString)); - + "", + (ourRequestBodyString)); + } - @Test(expected = IllegalArgumentException.class) + @Test public void testOperationWithInvalidParam() { IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort + "/fhir"); @@ -923,14 +952,14 @@ public class GenericJaxRsClientDstu3Test { } }; - //@formatter:off - client + assertThrows(IllegalArgumentException.class, () -> { + client .operation() .onServer() .named("$SOMEOPERATION") .withParameter(Parameters.class, "name1", weirdBase) .execute(); - //@formatter:on + }); } @Test @@ -942,44 +971,41 @@ public class GenericJaxRsClientDstu3Test { outParams.addParameter().setValue(new StringType("STRINGVALOUT2")); final String respString = p.encodeResourceToString(outParams); - - - + ourResponseContentType = Constants.CT_FHIR_XML + "; charset=UTF-8"; ourResponseBody = respString; IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort + "/fhir"); - //@formatter:off client - .operation() - .onInstance(new IdType("http://foo/Patient/1")) - .named("validate-code") - .withParameter(Parameters.class, "code", new CodeType("8495-4")) - .andParameter("system", new UriType("http://loinc.org")) - .useHttpGet() - .execute(); + .operation() + .onInstance(new IdType("http://foo/Patient/1")) + .named("validate-code") + .withParameter(Parameters.class, "code", new CodeType("8495-4")) + .andParameter("system", new UriType("http://loinc.org")) + .useHttpGet() + .execute(); //@formatter:off - + assertEquals("http://localhost:" + ourPort + "/fhir/Patient/1/$validate-code?code=8495-4&system=http%3A%2F%2Floinc.org", ourRequestUri); //@formatter:off - + client - .operation() - .onInstance(new IdType("http://foo/Patient/1")) - .named("validate-code") - .withParameter(Parameters.class, "code", new CodeType("8495-4")) - .andParameter("system", new UriType("http://loinc.org")) - .encodedXml() - .execute(); + .operation() + .onInstance(new IdType("http://foo/Patient/1")) + .named("validate-code") + .withParameter(Parameters.class, "code", new CodeType("8495-4")) + .andParameter("system", new UriType("http://loinc.org")) + .encodedXml() + .execute(); //@formatter:off - + assertEquals("http://localhost:" + ourPort + "/fhir/Patient/1/$validate-code", ourRequestUri); ourLog.info(ourRequestBodyString); - assertEquals("",ourRequestBodyString); + assertEquals("", ourRequestBodyString); } @@ -997,24 +1023,21 @@ public class GenericJaxRsClientDstu3Test { outParams.addParameter().setValue(new StringType("STRINGVALOUT2")); final String respString = p.encodeResourceToString(outParams); - - - + ourResponseContentType = Constants.CT_FHIR_XML + "; charset=UTF-8"; ourResponseBody = respString; IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort + "/fhir"); - //@formatter:off Parameters resp = client - .operation() - .onServer() - .named("$SOMEOPERATION") - .withParameters(inParams) - .encodedXml() - .execute(); + .operation() + .onServer() + .named("$SOMEOPERATION") + .withParameters(inParams) + .encodedXml() + .execute(); //@formatter:on assertEquals("http://localhost:" + ourPort + "/fhir/$SOMEOPERATION", ourRequestUri); assertEquals(respString, p.encodeResourceToString(resp)); @@ -1022,46 +1045,46 @@ public class GenericJaxRsClientDstu3Test { assertEquals(EncodingEnum.XML.getResourceContentTypeNonLegacy() + Constants.HEADER_SUFFIX_CT_UTF_8, ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char")); assertEquals(ourRequestBodyString, reqString); assertEquals("POST", ourRequestMethod); - + //@formatter:off resp = client - .operation() - .onType(Patient.class) - .named("$SOMEOPERATION") - .withParameters(inParams) - .encodedXml() - .execute(); - //@formatter:on + .operation() + .onType(Patient.class) + .named("$SOMEOPERATION") + .withParameters(inParams) + .encodedXml() + .execute(); + //@formatter:on assertEquals("http://localhost:" + ourPort + "/fhir/Patient/$SOMEOPERATION", ourRequestUri); assertEquals(respString, p.encodeResourceToString(resp)); assertEquals(1, ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE).size()); assertEquals(EncodingEnum.XML.getResourceContentTypeNonLegacy() + Constants.HEADER_SUFFIX_CT_UTF_8, ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char")); assertEquals(ourRequestBodyString, reqString); assertEquals("POST", ourRequestMethod); - + //@formatter:off resp = client - .operation() - .onInstance(new IdType("Patient", "123")) - .named("$SOMEOPERATION") - .withParameters(inParams) - .encodedXml() - .execute(); - //@formatter:on + .operation() + .onInstance(new IdType("Patient", "123")) + .named("$SOMEOPERATION") + .withParameters(inParams) + .encodedXml() + .execute(); + //@formatter:on assertEquals("http://localhost:" + ourPort + "/fhir/Patient/123/$SOMEOPERATION", ourRequestUri); assertEquals(respString, p.encodeResourceToString(resp)); assertEquals(1, ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE).size()); assertEquals(EncodingEnum.XML.getResourceContentTypeNonLegacy() + Constants.HEADER_SUFFIX_CT_UTF_8, ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char")); assertEquals(ourRequestBodyString, reqString); assertEquals("POST", ourRequestMethod); - + resp = client.operation().onInstance(new IdType("http://foo.com/bar/baz/Patient/123/_history/22")).named("$SOMEOPERATION").withParameters(inParams).execute(); // @formatter:on assertEquals("http://localhost:" + ourPort + "/fhir/Patient/123/$SOMEOPERATION", ourRequestUri); - + } @Test @@ -1076,22 +1099,19 @@ public class GenericJaxRsClientDstu3Test { outParams.addParameter().setValue(new StringType("STRINGVALOUT2")); final String respString = p.encodeResourceToString(outParams); - - - + ourResponseContentType = Constants.CT_FHIR_XML + "; charset=UTF-8"; ourResponseBody = respString; IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort + "/fhir"); - //@formatter:off Parameters resp = client - .operation() - .onServer() - .named("$SOMEOPERATION") - .withNoParameters(Parameters.class).encodedXml().execute(); + .operation() + .onServer() + .named("$SOMEOPERATION") + .withNoParameters(Parameters.class).encodedXml().execute(); //@formatter:on assertEquals("http://localhost:" + ourPort + "/fhir/$SOMEOPERATION", ourRequestUri); assertEquals(respString, p.encodeResourceToString(resp)); @@ -1099,61 +1119,60 @@ public class GenericJaxRsClientDstu3Test { assertEquals(EncodingEnum.XML.getResourceContentTypeNonLegacy() + Constants.HEADER_SUFFIX_CT_UTF_8, ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char")); assertEquals(ourRequestBodyString, reqString); assertEquals("POST", ourRequestMethod); - + //@formatter:off resp = client - .operation() - .onType(Patient.class) - .named("$SOMEOPERATION") - .withNoParameters(Parameters.class).encodedXml().execute(); - //@formatter:on + .operation() + .onType(Patient.class) + .named("$SOMEOPERATION") + .withNoParameters(Parameters.class).encodedXml().execute(); + //@formatter:on assertEquals("http://localhost:" + ourPort + "/fhir/Patient/$SOMEOPERATION", ourRequestUri); assertEquals(respString, p.encodeResourceToString(resp)); assertEquals(1, ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE).size()); assertEquals(EncodingEnum.XML.getResourceContentTypeNonLegacy() + Constants.HEADER_SUFFIX_CT_UTF_8, ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char")); assertEquals(ourRequestBodyString, reqString); assertEquals("POST", ourRequestMethod); - + //@formatter:off resp = client - .operation() - .onInstance(new IdType("Patient", "123")) - .named("$SOMEOPERATION") - .withNoParameters(Parameters.class) - .encodedXml() - .execute(); - //@formatter:on + .operation() + .onInstance(new IdType("Patient", "123")) + .named("$SOMEOPERATION") + .withNoParameters(Parameters.class) + .encodedXml() + .execute(); + //@formatter:on assertEquals("http://localhost:" + ourPort + "/fhir/Patient/123/$SOMEOPERATION", ourRequestUri); assertEquals(respString, p.encodeResourceToString(resp)); assertEquals(1, ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE).size()); assertEquals(EncodingEnum.XML.getResourceContentTypeNonLegacy() + Constants.HEADER_SUFFIX_CT_UTF_8, ourRequestFirstHeaders.get(Constants.HEADER_CONTENT_TYPE).getValue().replace(";char", "; char")); assertEquals(ourRequestBodyString, reqString); assertEquals("POST", ourRequestMethod); - + // @formatter:off resp = client - .operation() - .onInstance(new IdType("http://foo.com/bar/baz/Patient/123/_history/22")) - .named("$SOMEOPERATION") - .withNoParameters(Parameters.class) - .execute(); + .operation() + .onInstance(new IdType("http://foo.com/bar/baz/Patient/123/_history/22")) + .named("$SOMEOPERATION") + .withNoParameters(Parameters.class) + .execute(); // @formatter:on assertEquals("http://localhost:" + ourPort + "/fhir/Patient/123/$SOMEOPERATION", ourRequestUri); - + } @Test public void testPageNext() { - + ourResponseContentType = Constants.CT_FHIR_XML + "; charset=UTF-8"; ourResponseBody = getPatientFeedWithOneResult(); IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort + "/fhir"); - org.hl7.fhir.dstu3.model.Bundle sourceBundle = new org.hl7.fhir.dstu3.model.Bundle(); sourceBundle.getLinkOrCreate(IBaseBundle.LINK_PREV).setUrl("http://localhost:" + ourPort + "/fhir/prev"); @@ -1161,14 +1180,14 @@ public class GenericJaxRsClientDstu3Test { //@formatter:off org.hl7.fhir.dstu3.model.Bundle resp = client - .loadPage() - .next(sourceBundle) - .execute(); + .loadPage() + .next(sourceBundle) + .execute(); //@formatter:on assertEquals(1, resp.getEntry().size()); assertEquals("http://localhost:" + ourPort + "/fhir/next", ourRequestUri); - + } @@ -1186,29 +1205,27 @@ public class GenericJaxRsClientDstu3Test { @Test public void testPagePrev() { - - - + + ourResponseContentType = Constants.CT_FHIR_XML + "; charset=UTF-8"; ourResponseBody = getPatientFeedWithOneResult(); IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort + "/fhir"); - org.hl7.fhir.dstu3.model.Bundle sourceBundle = new org.hl7.fhir.dstu3.model.Bundle(); sourceBundle.getLinkOrCreate("previous").setUrl("http://localhost:" + ourPort + "/fhir/prev"); //@formatter:off org.hl7.fhir.dstu3.model.Bundle resp = client - .loadPage() - .previous(sourceBundle) - .execute(); + .loadPage() + .previous(sourceBundle) + .execute(); //@formatter:on assertEquals(1, resp.getEntry().size()); assertEquals("http://localhost:" + ourPort + "/fhir/prev", ourRequestUri); - + /* * Try with "prev" instead of "previous" @@ -1219,14 +1236,14 @@ public class GenericJaxRsClientDstu3Test { //@formatter:off resp = client - .loadPage() - .previous(sourceBundle) - .execute(); + .loadPage() + .previous(sourceBundle) + .execute(); //@formatter:on assertEquals(1, resp.getEntry().size()); assertEquals("http://localhost:" + ourPort + "/fhir/prev", ourRequestUri); - + } @@ -1244,7 +1261,7 @@ public class GenericJaxRsClientDstu3Test { Patient response; - + response = (Patient) client.read(new UriDt("http://localhost:" + ourPort + "/fhir/Patient/123")); assertEquals("http://localhost:" + ourPort + "/fhir/Patient/123", ourRequestUri); assertEquals("FAM", response.getName().get(0).getFamily()); @@ -1273,24 +1290,22 @@ public class GenericJaxRsClientDstu3Test { public void testReadUpdatedHeaderDoesntOverwriteResourceValue() { //@formatter:off - final String input = "\n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - ""; + final String input = "\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + ""; //@formatter:on - - - + ourResponseContentType = Constants.CT_FHIR_XML + "; charset=UTF-8"; ourResponseBody = input; @@ -1300,12 +1315,12 @@ public class GenericJaxRsClientDstu3Test { //@formatter:off response = client - .search() - .forResource(Patient.class) - .returnBundle(org.hl7.fhir.dstu3.model.Bundle.class) - .execute(); + .search() + .forResource(Patient.class) + .returnBundle(org.hl7.fhir.dstu3.model.Bundle.class) + .execute(); //@formatter:on - + assertEquals("2015-06-22T15:48:57.554-04:00", response.getMeta().getLastUpdatedElement().getValueAsString()); } @@ -1313,9 +1328,7 @@ public class GenericJaxRsClientDstu3Test { public void testReadWithElementsParam() { String msg = "{\"resourceType\":\"Patient\",\"id\":\"1\",\"meta\":{\"versionId\":\"1\",\"lastUpdated\":\"2014-12-20T18:41:29.706-05:00\"},\"identifier\":[{\"system\":\"urn:MultiFhirVersionTest\",\"value\":\"testSubmitPatient01\"}]}"; - - - + ourResponseContentType = Constants.CT_FHIR_JSON + "; charset=UTF-8"; ourResponseBody = msg; @@ -1338,9 +1351,7 @@ public class GenericJaxRsClientDstu3Test { public void testReadWithSummaryInvalid() { String msg = "<>>>><<<<>"; - - - + ourResponseContentType = Constants.CT_HTML + "; charset=UTF-8"; ourResponseBody = msg; @@ -1365,9 +1376,7 @@ public class GenericJaxRsClientDstu3Test { public void testReadWithSummaryParamHtml() { String msg = "
HELP IM A DIV
"; - - - + ourResponseContentType = Constants.CT_HTML + "; charset=UTF-8"; ourResponseBody = msg; @@ -1392,9 +1401,7 @@ public class GenericJaxRsClientDstu3Test { public void testSearchByString() { String msg = "{\"resourceType\":\"Bundle\",\"id\":null,\"base\":\"http://localhost:57931/fhir/contextDev\",\"total\":1,\"link\":[{\"relation\":\"self\",\"url\":\"http://localhost:57931/fhir/contextDev/Patient?identifier=urn%3AMultiFhirVersionTest%7CtestSubmitPatient01&_format=json\"}],\"entry\":[{\"resource\":{\"resourceType\":\"Patient\",\"id\":\"1\",\"meta\":{\"versionId\":\"1\",\"lastUpdated\":\"2014-12-20T18:41:29.706-05:00\"},\"identifier\":[{\"system\":\"urn:MultiFhirVersionTest\",\"value\":\"testSubmitPatient01\"}]}}]}"; - - - + ourResponseContentType = Constants.CT_FHIR_JSON + "; charset=UTF-8"; ourResponseBody = msg; @@ -1402,12 +1409,12 @@ public class GenericJaxRsClientDstu3Test { IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort + "/fhir"); //@formatter:off - Bundle response = client.search() - .forResource("Patient") - .where(Patient.NAME.matches().value("james")) - .returnBundle(Bundle.class) - .execute(); - //@formatter:on + Bundle response = client.search() + .forResource("Patient") + .where(Patient.NAME.matches().value("james")) + .returnBundle(Bundle.class) + .execute(); + //@formatter:on assertEquals("http://localhost:" + ourPort + "/fhir/Patient?name=james", ourRequestUri); assertEquals(Patient.class, response.getEntry().get(0).getResource().getClass()); @@ -1419,67 +1426,65 @@ public class GenericJaxRsClientDstu3Test { final String msg = getPatientFeedWithOneResult(); - - - + ourResponseContentType = Constants.CT_FHIR_XML + "; charset=UTF-8"; ourResponseBody = msg; IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort + "/fhir"); - + //@formatter:off org.hl7.fhir.dstu3.model.Bundle response = client.search() - .byUrl("http://localhost:" + ourPort + "/AAA?name=http://foo|bar") - .encodedJson() - .returnBundle(org.hl7.fhir.dstu3.model.Bundle.class) - .execute(); + .byUrl("http://localhost:" + ourPort + "/AAA?name=http://foo|bar") + .encodedJson() + .returnBundle(org.hl7.fhir.dstu3.model.Bundle.class) + .execute(); //@formatter:on assertEquals("http://localhost:" + ourPort + "/AAA?name=http%3A//foo%7Cbar&_format=json", ourRequestUri); assertNotNull(response); - + //@formatter:off response = client.search() - .byUrl("Patient?name=http://foo|bar") - .encodedJson() - .returnBundle(org.hl7.fhir.dstu3.model.Bundle.class) - .execute(); + .byUrl("Patient?name=http://foo|bar") + .encodedJson() + .returnBundle(org.hl7.fhir.dstu3.model.Bundle.class) + .execute(); //@formatter:on assertEquals("http://localhost:" + ourPort + "/fhir/Patient?name=http%3A//foo%7Cbar&_format=json", ourRequestUri); assertNotNull(response); - + //@formatter:off response = client.search() - .byUrl("/Patient?name=http://foo|bar") - .encodedJson() - .returnBundle(org.hl7.fhir.dstu3.model.Bundle.class) - .execute(); + .byUrl("/Patient?name=http://foo|bar") + .encodedJson() + .returnBundle(org.hl7.fhir.dstu3.model.Bundle.class) + .execute(); //@formatter:on assertEquals("http://localhost:" + ourPort + "/fhir/Patient?name=http%3A//foo%7Cbar&_format=json", ourRequestUri); assertNotNull(response); - + //@formatter:off response = client.search() - .byUrl("Patient") - .returnBundle(org.hl7.fhir.dstu3.model.Bundle.class) - .execute(); + .byUrl("Patient") + .returnBundle(org.hl7.fhir.dstu3.model.Bundle.class) + .execute(); //@formatter:on assertEquals("http://localhost:" + ourPort + "/fhir/Patient", ourRequestUri); assertNotNull(response); - + //@formatter:off response = client.search() - .byUrl("Patient?") - .returnBundle(org.hl7.fhir.dstu3.model.Bundle.class) - .execute(); + .byUrl("Patient?") + .returnBundle(org.hl7.fhir.dstu3.model.Bundle.class) + .execute(); //@formatter:on assertEquals("http://localhost:" + ourPort + "/fhir/Patient", ourRequestUri); assertNotNull(response); - + try { client.search().byUrl("foo/bar?test=1"); @@ -1494,9 +1499,8 @@ public class GenericJaxRsClientDstu3Test { @Test public void testSearchReturningDstu2Bundle() throws Exception { String msg = IOUtils.toString(GenericJaxRsClientDstu3Test.class.getResourceAsStream("/bundle_orion.xml")); - - - + + ourResponseContentType = Constants.CT_FHIR_XML + "; charset=UTF-8"; ourResponseBody = msg; @@ -1525,9 +1529,7 @@ public class GenericJaxRsClientDstu3Test { public void testSearchWithElementsParam() { String msg = "{\"resourceType\":\"Bundle\",\"id\":null,\"base\":\"http://localhost:57931/fhir/contextDev\",\"total\":1,\"link\":[{\"relation\":\"self\",\"url\":\"http://localhost:57931/fhir/contextDev/Patient?identifier=urn%3AMultiFhirVersionTest%7CtestSubmitPatient01&_format=json\"}],\"entry\":[{\"resource\":{\"resourceType\":\"Patient\",\"id\":\"1\",\"meta\":{\"versionId\":\"1\",\"lastUpdated\":\"2014-12-20T18:41:29.706-05:00\"},\"identifier\":[{\"system\":\"urn:MultiFhirVersionTest\",\"value\":\"testSubmitPatient01\"}]}}]}"; - - - + ourResponseContentType = Constants.CT_FHIR_JSON + "; charset=UTF-8"; ourResponseBody = msg; @@ -1535,13 +1537,13 @@ public class GenericJaxRsClientDstu3Test { IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort + "/fhir"); //@formatter:off - Bundle response = client.search() - .forResource("Patient") - .where(Patient.NAME.matches().value("james")) - .elementsSubset("name", "identifier") - .returnBundle(Bundle.class) - .execute(); - //@formatter:on + Bundle response = client.search() + .forResource("Patient") + .where(Patient.NAME.matches().value("james")) + .elementsSubset("name", "identifier") + .returnBundle(Bundle.class) + .execute(); + //@formatter:on assertThat(ourRequestUri, either(equalTo("http://localhost:" + ourPort + "/fhir/Patient?name=james&_elements=name%2Cidentifier")).or(equalTo("http://localhost:" + ourPort + "/fhir/Patient?name=james&_elements=identifier%2Cname"))); assertEquals(Patient.class, response.getEntry().get(0).getResource().getClass()); @@ -1552,9 +1554,7 @@ public class GenericJaxRsClientDstu3Test { public void testSearchByPost() { String msg = "{\"resourceType\":\"Bundle\",\"id\":null,\"base\":\"http://localhost:57931/fhir/contextDev\",\"total\":1,\"link\":[{\"relation\":\"self\",\"url\":\"http://localhost:57931/fhir/contextDev/Patient?identifier=urn%3AMultiFhirVersionTest%7CtestSubmitPatient01&_format=json\"}],\"entry\":[{\"resource\":{\"resourceType\":\"Patient\",\"id\":\"1\",\"meta\":{\"versionId\":\"1\",\"lastUpdated\":\"2014-12-20T18:41:29.706-05:00\"},\"identifier\":[{\"system\":\"urn:MultiFhirVersionTest\",\"value\":\"testSubmitPatient01\"}]}}]}"; - - - + ourResponseContentType = Constants.CT_FHIR_JSON + "; charset=UTF-8"; ourResponseBody = msg; @@ -1567,7 +1567,7 @@ public class GenericJaxRsClientDstu3Test { .where(Patient.NAME.matches().value("james")) .elementsSubset("name", "identifier") .usingStyle(SearchStyleEnum.POST) - .returnBundle(Bundle.class) + .returnBundle(Bundle.class) .execute(); //@formatter:on @@ -1589,9 +1589,7 @@ public class GenericJaxRsClientDstu3Test { public void testSearchByPostUseJson() { String msg = "{\"resourceType\":\"Bundle\",\"id\":null,\"base\":\"http://localhost:57931/fhir/contextDev\",\"total\":1,\"link\":[{\"relation\":\"self\",\"url\":\"http://localhost:57931/fhir/contextDev/Patient?identifier=urn%3AMultiFhirVersionTest%7CtestSubmitPatient01&_format=json\"}],\"entry\":[{\"resource\":{\"resourceType\":\"Patient\",\"id\":\"1\",\"meta\":{\"versionId\":\"1\",\"lastUpdated\":\"2014-12-20T18:41:29.706-05:00\"},\"identifier\":[{\"system\":\"urn:MultiFhirVersionTest\",\"value\":\"testSubmitPatient01\"}]}}]}"; - - - + ourResponseContentType = Constants.CT_FHIR_JSON + "; charset=UTF-8"; ourResponseBody = msg; @@ -1605,7 +1603,7 @@ public class GenericJaxRsClientDstu3Test { .elementsSubset("name", "identifier") .usingStyle(SearchStyleEnum.POST) .encodedJson() - .returnBundle(Bundle.class) + .returnBundle(Bundle.class) .execute(); //@formatter:on @@ -1627,9 +1625,7 @@ public class GenericJaxRsClientDstu3Test { public void testSearchWithLastUpdated() { String msg = "{\"resourceType\":\"Bundle\",\"id\":null,\"base\":\"http://localhost:57931/fhir/contextDev\",\"total\":1,\"link\":[{\"relation\":\"self\",\"url\":\"http://localhost:57931/fhir/contextDev/Patient?identifier=urn%3AMultiFhirVersionTest%7CtestSubmitPatient01&_format=json\"}],\"entry\":[{\"resource\":{\"resourceType\":\"Patient\",\"id\":\"1\",\"meta\":{\"versionId\":\"1\",\"lastUpdated\":\"2014-12-20T18:41:29.706-05:00\"},\"identifier\":[{\"system\":\"urn:MultiFhirVersionTest\",\"value\":\"testSubmitPatient01\"}]}}]}"; - - - + ourResponseContentType = Constants.CT_FHIR_JSON + "; charset=UTF-8"; ourResponseBody = msg; @@ -1637,13 +1633,13 @@ public class GenericJaxRsClientDstu3Test { IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort + "/fhir"); //@formatter:off - Bundle response = client.search() - .forResource("Patient") - .where(Patient.NAME.matches().value("james")) - .lastUpdated(new DateRangeParam("2011-01-01", "2012-01-01")) - .returnBundle(Bundle.class) - .execute(); - //@formatter:on + Bundle response = client.search() + .forResource("Patient") + .where(Patient.NAME.matches().value("james")) + .lastUpdated(new DateRangeParam("2011-01-01", "2012-01-01")) + .returnBundle(Bundle.class) + .execute(); + //@formatter:on assertEquals("http://localhost:" + ourPort + "/fhir/Patient?name=james&_lastUpdated=ge2011-01-01&_lastUpdated=le2012-01-01", ourRequestUri); assertEquals(Patient.class, response.getEntry().get(0).getResource().getClass()); @@ -1654,9 +1650,7 @@ public class GenericJaxRsClientDstu3Test { public void testSearchWithProfileAndSecurity() { String msg = "{\"resourceType\":\"Bundle\",\"id\":null,\"base\":\"http://localhost:57931/fhir/contextDev\",\"total\":1,\"link\":[{\"relation\":\"self\",\"url\":\"http://localhost:57931/fhir/contextDev/Patient?identifier=urn%3AMultiFhirVersionTest%7CtestSubmitPatient01&_format=json\"}],\"entry\":[{\"resource\":{\"resourceType\":\"Patient\",\"id\":\"1\",\"meta\":{\"versionId\":\"1\",\"lastUpdated\":\"2014-12-20T18:41:29.706-05:00\"},\"identifier\":[{\"system\":\"urn:MultiFhirVersionTest\",\"value\":\"testSubmitPatient01\"}]}}]}"; - - - + ourResponseContentType = Constants.CT_FHIR_JSON + "; charset=UTF-8"; ourResponseBody = msg; @@ -1664,15 +1658,15 @@ public class GenericJaxRsClientDstu3Test { IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort + "/fhir"); //@formatter:off - Bundle response = client.search() - .forResource("Patient") - .withProfile("http://foo1") - .withProfile("http://foo2") - .withSecurity("system1", "code1") - .withSecurity("system2", "code2") - .returnBundle(Bundle.class) - .execute(); - //@formatter:on + Bundle response = client.search() + .forResource("Patient") + .withProfile("http://foo1") + .withProfile("http://foo2") + .withSecurity("system1", "code1") + .withSecurity("system2", "code2") + .returnBundle(Bundle.class) + .execute(); + //@formatter:on assertEquals("http://localhost:" + ourPort + "/fhir/Patient?_security=system1%7Ccode1&_security=system2%7Ccode2&_profile=http%3A%2F%2Ffoo1&_profile=http%3A%2F%2Ffoo2", ourRequestUri); assertEquals(Patient.class, response.getEntry().get(0).getResource().getClass()); @@ -1685,9 +1679,7 @@ public class GenericJaxRsClientDstu3Test { String msg = getPatientFeedWithOneResult(); - - - + ourResponseContentType = Constants.CT_FHIR_XML + "; charset=UTF-8"; ourResponseBody = msg; @@ -1696,11 +1688,11 @@ public class GenericJaxRsClientDstu3Test { //@formatter:off Bundle response = client.search() - .forResource(Patient.class) - .encodedJson() - .revInclude(new Include("Provenance:target")) - .returnBundle(Bundle.class) - .execute(); + .forResource(Patient.class) + .encodedJson() + .revInclude(new Include("Provenance:target")) + .returnBundle(Bundle.class) + .execute(); //@formatter:on assertEquals("http://localhost:" + ourPort + "/fhir/Patient?_revinclude=Provenance%3Atarget&_format=json", ourRequestUri); @@ -1711,9 +1703,7 @@ public class GenericJaxRsClientDstu3Test { public void testSearchWithSummaryParam() { String msg = "{\"resourceType\":\"Bundle\",\"id\":null,\"base\":\"http://localhost:57931/fhir/contextDev\",\"total\":1,\"link\":[{\"relation\":\"self\",\"url\":\"http://localhost:57931/fhir/contextDev/Patient?identifier=urn%3AMultiFhirVersionTest%7CtestSubmitPatient01&_format=json\"}],\"entry\":[{\"resource\":{\"resourceType\":\"Patient\",\"id\":\"1\",\"meta\":{\"versionId\":\"1\",\"lastUpdated\":\"2014-12-20T18:41:29.706-05:00\"},\"identifier\":[{\"system\":\"urn:MultiFhirVersionTest\",\"value\":\"testSubmitPatient01\"}]}}]}"; - - - + ourResponseContentType = Constants.CT_FHIR_JSON + "; charset=UTF-8"; ourResponseBody = msg; @@ -1721,13 +1711,13 @@ public class GenericJaxRsClientDstu3Test { IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort + "/fhir"); //@formatter:off - Bundle response = client.search() - .forResource("Patient") - .where(Patient.NAME.matches().value("james")) - .summaryMode(SummaryEnum.FALSE) - .returnBundle(Bundle.class) - .execute(); - //@formatter:on + Bundle response = client.search() + .forResource("Patient") + .where(Patient.NAME.matches().value("james")) + .summaryMode(SummaryEnum.FALSE) + .returnBundle(Bundle.class) + .execute(); + //@formatter:on assertEquals("http://localhost:" + ourPort + "/fhir/Patient?name=james&_summary=false", ourRequestUri); assertEquals(Patient.class, response.getEntry().get(0).getResource().getClass()); @@ -1742,9 +1732,7 @@ public class GenericJaxRsClientDstu3Test { resp.addEntry().getResponse().setLocation("Patient/2/_history/2"); String respString = ourCtx.newJsonParser().encodeResourceToString(resp); - - - + ourResponseContentType = Constants.CT_FHIR_JSON + "; charset=UTF-8"; ourResponseBody = respString; @@ -1762,11 +1750,11 @@ public class GenericJaxRsClientDstu3Test { input.add(p2); //@formatter:off - List response = client.transaction() - .withResources(input) - .encodedJson() - .execute(); - //@formatter:on + List response = client.transaction() + .withResources(input) + .encodedJson() + .execute(); + //@formatter:on assertEquals("http://localhost:" + ourPort + "/fhir", ourRequestUri); assertEquals(2, response.size()); @@ -1819,9 +1807,7 @@ public class GenericJaxRsClientDstu3Test { resp.addEntry().getResponse().setLocation("Patient/1/_history/1"); resp.addEntry().getResponse().setLocation("Patient/2/_history/2"); - - - + ourResponseContentType = Constants.CT_FHIR_JSON + "; charset=UTF-8"; ourResponseBody = reqString; @@ -1838,11 +1824,11 @@ public class GenericJaxRsClientDstu3Test { assertEquals("application/fhir+json;charset=UTF-8", ourRequestFirstHeaders.get("Content-Type").getValue()); //@formatter:off - response = client.transaction() - .withBundle(reqString) - .encodedXml() - .execute(); - //@formatter:on + response = client.transaction() + .withBundle(reqString) + .encodedXml() + .execute(); + //@formatter:on assertEquals("http://localhost:" + ourPort + "/fhir/", ourRequestUri); assertEquals("application/fhir+xml;charset=UTF-8", ourRequestFirstHeaders.get("Content-Type").getValue()); @@ -1857,9 +1843,7 @@ public class GenericJaxRsClientDstu3Test { resp.addEntry().getResponse().setLocation("Patient/2/_history/2"); String respString = ourCtx.newJsonParser().encodeResourceToString(resp); - - - + ourResponseContentType = Constants.CT_FHIR_JSON + "; charset=UTF-8"; ourResponseBody = respString; @@ -1877,11 +1861,11 @@ public class GenericJaxRsClientDstu3Test { input.addEntry().setResource(p2); //@formatter:off - org.hl7.fhir.dstu3.model.Bundle response = client.transaction() - .withBundle(input) - .encodedJson() - .execute(); - //@formatter:on + org.hl7.fhir.dstu3.model.Bundle response = client.transaction() + .withBundle(input) + .encodedJson() + .execute(); + //@formatter:on assertEquals("http://localhost:" + ourPort + "/fhir", ourRequestUri); assertEquals(2, response.getEntry().size()); @@ -1892,13 +1876,12 @@ public class GenericJaxRsClientDstu3Test { @Test public void testUpdateConditional() { - - + + ourResponseStatus = Constants.STATUS_HTTP_204_NO_CONTENT; - + IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort + "/fhir"); - Patient p = new Patient(); p.addName().setFamily("FOOFAMILY"); @@ -1909,7 +1892,7 @@ public class GenericJaxRsClientDstu3Test { assertThat(ourRequestBodyString, containsString("")); assertEquals("PUT", ourRequestMethod); assertEquals("http://localhost:" + ourPort + "/fhir/Patient?name=foo", ourRequestUri); - + client.update().resource(p).conditionalByUrl("Patient?name=http://foo|bar").encodedXml().execute(); assertEquals(1, ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE).size()); @@ -1917,7 +1900,7 @@ public class GenericJaxRsClientDstu3Test { assertThat(ourRequestBodyString, containsString("")); assertEquals("PUT", ourRequestMethod); assertEquals("http://localhost:" + ourPort + "/fhir/Patient?name=http%3A//foo%7Cbar", ourRequestUri); - + client.update().resource(ourCtx.newXmlParser().encodeResourceToString(p)).conditionalByUrl("Patient?name=foo").execute(); assertEquals(1, ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE).size()); @@ -1925,7 +1908,7 @@ public class GenericJaxRsClientDstu3Test { assertThat(ourRequestBodyString, containsString("")); assertEquals("PUT", ourRequestMethod); assertEquals("http://localhost:" + ourPort + "/fhir/Patient?name=foo", ourRequestUri); - + client.update().resource(p).conditional().where(Patient.NAME.matches().value("foo")).and(Patient.ADDRESS.matches().value("AAA|BBB")).encodedXml().execute(); assertEquals(1, ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE).size()); @@ -1933,7 +1916,7 @@ public class GenericJaxRsClientDstu3Test { assertThat(ourRequestBodyString, containsString("")); assertEquals("PUT", ourRequestMethod); assertEquals("http://localhost:" + ourPort + "/fhir/Patient?name=foo&address=AAA%5C%7CBBB", ourRequestUri); - + client.update().resource(ourCtx.newXmlParser().encodeResourceToString(p)).conditional().where(Patient.NAME.matches().value("foo")).and(Patient.ADDRESS.matches().value("AAA|BBB")).encodedXml().execute(); assertEquals(1, ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE).size()); @@ -1941,20 +1924,19 @@ public class GenericJaxRsClientDstu3Test { assertThat(ourRequestBodyString, containsString("")); assertEquals("PUT", ourRequestMethod); assertEquals("http://localhost:" + ourPort + "/fhir/Patient?name=foo&address=AAA%5C%7CBBB", ourRequestUri); - + } @Test public void testUpdateNonFluent() { - - + + ourResponseStatus = Constants.STATUS_HTTP_204_NO_CONTENT; IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort + "/fhir"); client.setEncoding(EncodingEnum.XML); - Patient p = new Patient(); p.addName().setFamily("FOOFAMILY"); @@ -1965,7 +1947,7 @@ public class GenericJaxRsClientDstu3Test { assertThat(ourRequestBodyString, containsString("")); assertEquals("http://localhost:" + ourPort + "/fhir/Patient/123?_format=xml", ourRequestUri); assertEquals("PUT", ourRequestMethod); - + client.update("123", p); assertEquals(1, ourRequestHeaders.get(Constants.HEADER_CONTENT_TYPE).size()); @@ -1973,18 +1955,17 @@ public class GenericJaxRsClientDstu3Test { assertThat(ourRequestBodyString, containsString("")); assertEquals("http://localhost:" + ourPort + "/fhir/Patient/123?_format=xml", ourRequestUri); assertEquals("PUT", ourRequestMethod); - + } @Test public void testUpdatePrefer() { - - + + ourResponseStatus = Constants.STATUS_HTTP_204_NO_CONTENT; IGenericClient client = ourCtx.newRestfulGenericClient("http://localhost:" + ourPort + "/fhir"); - Patient p = new Patient(); p.setId(new IdType("1")); @@ -1993,12 +1974,12 @@ public class GenericJaxRsClientDstu3Test { client.update().resource(p).prefer(PreferReturnEnum.MINIMAL).execute(); assertEquals(1, ourRequestHeaders.get(Constants.HEADER_PREFER).size()); assertEquals(Constants.HEADER_PREFER_RETURN + '=' + Constants.HEADER_PREFER_RETURN_MINIMAL, ourRequestHeaders.get(Constants.HEADER_PREFER).get(0).getValue()); - + client.update().resource(p).prefer(PreferReturnEnum.REPRESENTATION).execute(); assertEquals(1, ourRequestHeaders.get(Constants.HEADER_PREFER).size()); assertEquals(Constants.HEADER_PREFER_RETURN + '=' + Constants.HEADER_PREFER_RETURN_REPRESENTATION, ourRequestHeaders.get(Constants.HEADER_PREFER).get(0).getValue()); - + } @@ -2008,8 +1989,7 @@ public class GenericJaxRsClientDstu3Test { p.setId("123"); final String formatted = ourCtx.newXmlParser().encodeResourceToString(p); - - + ourResponseStatus = Constants.STATUS_HTTP_200_OK; ourResponseContentType = Constants.CT_FHIR_XML + "; charset=UTF-8"; ourResponseBody = formatted; @@ -2032,9 +2012,7 @@ public class GenericJaxRsClientDstu3Test { oo.addIssue().setDiagnostics("FOOBAR"); final String msg = ourCtx.newXmlParser().encodeResourceToString(oo); - - - + ourResponseContentType = Constants.CT_FHIR_XML + "; charset=UTF-8"; ourResponseBody = msg; @@ -2043,7 +2021,7 @@ public class GenericJaxRsClientDstu3Test { Patient p = new Patient(); p.addName().addGiven("GIVEN"); - + MethodOutcome response; response = client.validate().resource(p).encodedXml().execute(); @@ -2052,7 +2030,7 @@ public class GenericJaxRsClientDstu3Test { assertEquals("", ourRequestBodyString); assertNotNull(response.getOperationOutcome()); assertEquals("FOOBAR", toOo(response.getOperationOutcome()).getIssue().get(0).getDiagnosticsElement().getValue()); - + response = client.validate().resource(ourCtx.newXmlParser().encodeResourceToString(p)).execute(); assertEquals("http://localhost:" + ourPort + "/fhir/Patient/$validate", ourRequestUri); @@ -2060,7 +2038,7 @@ public class GenericJaxRsClientDstu3Test { assertEquals("", ourRequestBodyString); assertNotNull(response.getOperationOutcome()); assertEquals("FOOBAR", toOo(response.getOperationOutcome()).getIssue().get(0).getDiagnosticsElement().getValue()); - + response = client.validate().resource(ourCtx.newJsonParser().encodeResourceToString(p)).execute(); assertEquals("http://localhost:" + ourPort + "/fhir/Patient/$validate", ourRequestUri); @@ -2068,7 +2046,7 @@ public class GenericJaxRsClientDstu3Test { assertEquals("{\"resourceType\":\"Parameters\",\"parameter\":[{\"name\":\"resource\",\"resource\":{\"resourceType\":\"Patient\",\"name\":[{\"given\":[\"GIVEN\"]}]}}]}", ourRequestBodyString); assertNotNull(response.getOperationOutcome()); assertEquals("FOOBAR", toOo(response.getOperationOutcome()).getIssue().get(0).getDiagnosticsElement().getValue()); - + response = client.validate().resource(ourCtx.newJsonParser().encodeResourceToString(p)).prettyPrint().execute(); assertEquals("http://localhost:" + ourPort + "/fhir/Patient/$validate?_pretty=true", ourRequestUri); @@ -2076,7 +2054,7 @@ public class GenericJaxRsClientDstu3Test { assertThat(ourRequestBodyString, containsString("\"resourceType\": \"Parameters\",\n")); assertNotNull(response.getOperationOutcome()); assertEquals("FOOBAR", toOo(response.getOperationOutcome()).getIssue().get(0).getDiagnosticsElement().getValue()); - + } @Test @@ -2084,7 +2062,7 @@ public class GenericJaxRsClientDstu3Test { OperationOutcome oo = new OperationOutcome(); oo.addIssue().setDiagnostics("FOOBAR"); final String msg = ourCtx.newXmlParser().encodeResourceToString(oo); - + ourResponseContentType = Constants.CT_FHIR_XML + "; charset=UTF-8"; ourResponseBody = msg; @@ -2094,7 +2072,7 @@ public class GenericJaxRsClientDstu3Test { Patient p = new Patient(); p.addName().addGiven("GIVEN"); - + MethodOutcome response; //@formatter:off @@ -2105,15 +2083,15 @@ public class GenericJaxRsClientDstu3Test { assertEquals("POST", ourRequestMethod); assertEquals("", ourRequestBodyString); assertNotNull(response.getOperationOutcome()); - assertEquals("FOOBAR", ((OperationOutcome)response.getOperationOutcome()).getIssue().get(0).getDiagnosticsElement().getValue()); - + assertEquals("FOOBAR", ((OperationOutcome) response.getOperationOutcome()).getIssue().get(0).getDiagnosticsElement().getValue()); + } private OperationOutcome toOo(IBaseResource theOperationOutcome) { return (OperationOutcome) theOperationOutcome; } - @Before + @BeforeEach public void beforeReset() { ourRequestUri = null; ourRequestUriAll = Lists.newArrayList(); @@ -2121,7 +2099,7 @@ public class GenericJaxRsClientDstu3Test { ourResponseBody = null; ourResponseBodies = null; ourResponseCount = 0; - + ourResponseContentType = null; ourRequestContentType = null; ourRequestBodyBytes = null; @@ -2131,20 +2109,11 @@ public class GenericJaxRsClientDstu3Test { ourRequestMethod = null; ourRequestHeadersAll = Lists.newArrayList(); } - - private static List ourRequestUriAll; - private static String ourRequestMethod; - private static String ourRequestContentType; - private static byte[] ourRequestBodyBytes; - private static String ourRequestBodyString; - private static ArrayListMultimap ourRequestHeaders; - private static List> ourRequestHeadersAll; - private static Map ourRequestFirstHeaders; - - @BeforeClass + + @BeforeAll public static void beforeClass() throws Exception { ourCtx = FhirContext.forDstu3(); - + ourServer = new Server(0); ourServer.setHandler(new AbstractHandler() { @@ -2157,24 +2126,24 @@ public class GenericJaxRsClientDstu3Test { ourRequestContentType = theServletRequest.getContentType(); ourRequestBodyBytes = IOUtils.toByteArray(theServletRequest.getInputStream()); ourRequestBodyString = new String(ourRequestBodyBytes, Charsets.UTF_8); - + ourRequestHeaders = ArrayListMultimap.create(); ourRequestHeadersAll.add(ourRequestHeaders); ourRequestFirstHeaders = Maps.newHashMap(); - + for (Enumeration headerNameEnum = theRequest.getHeaderNames(); headerNameEnum.hasMoreElements(); ) { String nextName = headerNameEnum.nextElement(); for (Enumeration headerValueEnum = theRequest.getHeaders(nextName); headerValueEnum.hasMoreElements(); ) { String nextValue = headerValueEnum.nextElement(); - if (ourRequestFirstHeaders.containsKey(nextName)==false) { + if (ourRequestFirstHeaders.containsKey(nextName) == false) { ourRequestFirstHeaders.put(nextName, new Header(nextName, nextValue)); } ourRequestHeaders.put(nextName, new Header(nextName, nextValue)); } } - + theResp.setStatus(ourResponseStatus); - + if (ourResponseBody != null) { theResp.setContentType(ourResponseContentType); theResp.getWriter().write(ourResponseBody); @@ -2182,16 +2151,16 @@ public class GenericJaxRsClientDstu3Test { theResp.setContentType(ourResponseContentType); theResp.getWriter().write(ourResponseBodies[ourResponseCount]); } - + ourResponseCount++; } }); - + JettyUtil.startServer(ourServer); - ourPort = JettyUtil.getPortForStartedServer(ourServer); + ourPort = JettyUtil.getPortForStartedServer(ourServer); } - @AfterClass + @AfterAll public static void afterClass() throws Exception { JettyUtil.closeServer(ourServer); } diff --git a/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/client/JaxRsRestfulClientFactoryTest.java b/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/client/JaxRsRestfulClientFactoryTest.java index c90ef75f85d..bf478228113 100644 --- a/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/client/JaxRsRestfulClientFactoryTest.java +++ b/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/client/JaxRsRestfulClientFactoryTest.java @@ -1,8 +1,8 @@ package ca.uhn.fhir.jaxrs.client; import ca.uhn.fhir.context.FhirContext; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -11,8 +11,9 @@ import java.util.ArrayList; import java.util.Arrays; import static org.hamcrest.CoreMatchers.hasItem; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.IsNot.not; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; /** * Created by Sebastien Riviere on 31/07/2017. @@ -51,7 +52,7 @@ public class JaxRsRestfulClientFactoryTest { assertThat(result.getConfiguration().getClasses(), hasItem(ca.uhn.fhir.jaxrs.client.MyFilter.class)); } - @Before + @BeforeEach public void setUp() { factory = new JaxRsRestfulClientFactory(context); } diff --git a/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/server/AbstractJaxRsConformanceProviderDstu2Hl7OrgTest.java b/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/server/AbstractJaxRsConformanceProviderDstu2Hl7OrgTest.java index 3d616361585..6196e398758 100644 --- a/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/server/AbstractJaxRsConformanceProviderDstu2Hl7OrgTest.java +++ b/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/server/AbstractJaxRsConformanceProviderDstu2Hl7OrgTest.java @@ -6,8 +6,8 @@ import ca.uhn.fhir.jaxrs.server.test.TestJaxRsMockPatientRestProviderDstu2Hl7Org import ca.uhn.fhir.rest.api.Constants; import ca.uhn.fhir.rest.server.IResourceProvider; import org.jboss.resteasy.specimpl.ResteasyHttpHeaders; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import javax.ws.rs.core.MultivaluedHashMap; import javax.ws.rs.core.Response; @@ -16,7 +16,7 @@ import java.net.URI; import java.util.Arrays; import java.util.concurrent.ConcurrentHashMap; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -29,7 +29,7 @@ public class AbstractJaxRsConformanceProviderDstu2Hl7OrgTest { private ResteasyHttpHeaders headers; private MultivaluedHashMap queryParameters; - @Before + @BeforeEach public void setUp() throws Exception { // uri info queryParameters = new MultivaluedHashMap<>(); diff --git a/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/server/AbstractJaxRsConformanceProviderDstu2_1Test.java b/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/server/AbstractJaxRsConformanceProviderDstu2_1Test.java index 1f90215d370..da458ab8c2d 100644 --- a/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/server/AbstractJaxRsConformanceProviderDstu2_1Test.java +++ b/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/server/AbstractJaxRsConformanceProviderDstu2_1Test.java @@ -6,8 +6,8 @@ import ca.uhn.fhir.jaxrs.server.test.TestJaxRsMockPatientRestProviderDstu2_1; import ca.uhn.fhir.rest.api.Constants; import ca.uhn.fhir.rest.server.IResourceProvider; import org.jboss.resteasy.specimpl.ResteasyHttpHeaders; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import javax.ws.rs.core.MultivaluedHashMap; import javax.ws.rs.core.Response; @@ -16,7 +16,7 @@ import java.net.URI; import java.util.Arrays; import java.util.concurrent.ConcurrentHashMap; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -29,7 +29,7 @@ public class AbstractJaxRsConformanceProviderDstu2_1Test { private ResteasyHttpHeaders headers; private MultivaluedHashMap queryParameters; - @Before + @BeforeEach public void setUp() throws Exception { // uri info queryParameters = new MultivaluedHashMap<>(); diff --git a/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/server/AbstractJaxRsConformanceProviderDstu3Test.java b/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/server/AbstractJaxRsConformanceProviderDstu3Test.java index 553c196d8b0..b70b9c63d92 100644 --- a/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/server/AbstractJaxRsConformanceProviderDstu3Test.java +++ b/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/server/AbstractJaxRsConformanceProviderDstu3Test.java @@ -1,107 +1,107 @@ -package ca.uhn.fhir.jaxrs.server; - -import ca.uhn.fhir.context.FhirContext; -import ca.uhn.fhir.jaxrs.server.test.TestJaxRsMockPatientRestProviderDstu3; -import ca.uhn.fhir.rest.api.Constants; -import ca.uhn.fhir.rest.server.IResourceProvider; -import org.jboss.resteasy.specimpl.ResteasyHttpHeaders; -import org.junit.Before; -import org.junit.Test; - -import javax.ws.rs.core.MultivaluedHashMap; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.UriInfo; -import java.net.URI; -import java.util.Arrays; -import java.util.concurrent.ConcurrentHashMap; - -import static org.junit.Assert.*; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import ca.uhn.fhir.jaxrs.server.test.TestJaxRsDummyPatientProviderDstu3; - -public class AbstractJaxRsConformanceProviderDstu3Test { - - private static final String BASEURI = "http://basiuri"; - private static final String REQUESTURI = BASEURI + "/metadata"; - AbstractJaxRsConformanceProvider provider; - private ConcurrentHashMap, IResourceProvider> providers; - private ResteasyHttpHeaders headers; - private MultivaluedHashMap queryParameters; - - @Before - public void setUp() throws Exception { - // uri info - queryParameters = new MultivaluedHashMap<>(); - // headers -// headers = new ContainerRequest(new URI(BASEURI), new URI(REQUESTURI), HttpMethod.GET, null, -// new MapPropertiesDelegate()); - headers = new ResteasyHttpHeaders(queryParameters); - - - providers = new ConcurrentHashMap, IResourceProvider>(); - provider = createConformanceProvider(providers); - } - - @Test - public void testConformance() throws Exception { - providers.put(AbstractJaxRsConformanceProvider.class, provider); - providers.put(TestJaxRsDummyPatientProviderDstu3.class, new TestJaxRsDummyPatientProviderDstu3()); - Response response = createConformanceProvider(providers).conformance(); - System.out.println(response); - } - - @Test - public void testConformanceUsingOptions() throws Exception { - providers.put(AbstractJaxRsConformanceProvider.class, provider); - providers.put(TestJaxRsDummyPatientProviderDstu3.class, new TestJaxRsDummyPatientProviderDstu3()); - Response response = createConformanceProvider(providers).conformanceUsingOptions(); - System.out.println(response); - } - - @Test - public void testConformanceWithMethods() throws Exception { - providers.put(AbstractJaxRsConformanceProvider.class, provider); - providers.put(TestJaxRsMockPatientRestProviderDstu3.class, new TestJaxRsMockPatientRestProviderDstu3()); - Response response = createConformanceProvider(providers).conformance(); - assertEquals(Constants.STATUS_HTTP_200_OK, response.getStatus()); - assertTrue(response.getEntity().toString().contains("\"type\": \"Patient\"")); - assertTrue(response.getEntity().toString().contains("\"someCustomOperation")); - System.out.println(response); - System.out.println(response.getEntity()); - } - - @Test - public void testConformanceInXml() throws Exception { - queryParameters.put(Constants.PARAM_FORMAT, Arrays.asList(Constants.CT_XML)); - providers.put(AbstractJaxRsConformanceProvider.class, provider); - providers.put(TestJaxRsMockPatientRestProviderDstu3.class, new TestJaxRsMockPatientRestProviderDstu3()); - Response response = createConformanceProvider(providers).conformance(); - assertEquals(Constants.STATUS_HTTP_200_OK, response.getStatus()); - System.out.println(response.getEntity()); - assertTrue(response.getEntity().toString().contains(" ")); - assertTrue(response.getEntity().toString().contains("\"someCustomOperation")); - System.out.println(response.getEntity()); - } - - private AbstractJaxRsConformanceProvider createConformanceProvider(final ConcurrentHashMap, IResourceProvider> providers) - throws Exception { - AbstractJaxRsConformanceProvider result = new AbstractJaxRsConformanceProvider(FhirContext.forDstu3(), null, null, null) { - @Override - protected ConcurrentHashMap, IResourceProvider> getProviders() { - return providers; - } - }; - // mocks - UriInfo uriInfo = mock(UriInfo.class); - when(uriInfo.getQueryParameters()).thenReturn(queryParameters); - when(uriInfo.getBaseUri()).thenReturn(new URI(BASEURI)); - when(uriInfo.getRequestUri()).thenReturn(new URI(BASEURI + "/foo")); - result.setUriInfo(uriInfo); - result.setHeaders(headers); - result.setUpPostConstruct(); - return result; - } - -} +package ca.uhn.fhir.jaxrs.server; + +import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.jaxrs.server.test.TestJaxRsMockPatientRestProviderDstu3; +import ca.uhn.fhir.rest.api.Constants; +import ca.uhn.fhir.rest.server.IResourceProvider; +import org.jboss.resteasy.specimpl.ResteasyHttpHeaders; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import javax.ws.rs.core.MultivaluedHashMap; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.UriInfo; +import java.net.URI; +import java.util.Arrays; +import java.util.concurrent.ConcurrentHashMap; + +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import ca.uhn.fhir.jaxrs.server.test.TestJaxRsDummyPatientProviderDstu3; + +public class AbstractJaxRsConformanceProviderDstu3Test { + + private static final String BASEURI = "http://basiuri"; + private static final String REQUESTURI = BASEURI + "/metadata"; + AbstractJaxRsConformanceProvider provider; + private ConcurrentHashMap, IResourceProvider> providers; + private ResteasyHttpHeaders headers; + private MultivaluedHashMap queryParameters; + + @BeforeEach + public void setUp() throws Exception { + // uri info + queryParameters = new MultivaluedHashMap<>(); + // headers +// headers = new ContainerRequest(new URI(BASEURI), new URI(REQUESTURI), HttpMethod.GET, null, +// new MapPropertiesDelegate()); + headers = new ResteasyHttpHeaders(queryParameters); + + + providers = new ConcurrentHashMap, IResourceProvider>(); + provider = createConformanceProvider(providers); + } + + @Test + public void testConformance() throws Exception { + providers.put(AbstractJaxRsConformanceProvider.class, provider); + providers.put(TestJaxRsDummyPatientProviderDstu3.class, new TestJaxRsDummyPatientProviderDstu3()); + Response response = createConformanceProvider(providers).conformance(); + System.out.println(response); + } + + @Test + public void testConformanceUsingOptions() throws Exception { + providers.put(AbstractJaxRsConformanceProvider.class, provider); + providers.put(TestJaxRsDummyPatientProviderDstu3.class, new TestJaxRsDummyPatientProviderDstu3()); + Response response = createConformanceProvider(providers).conformanceUsingOptions(); + System.out.println(response); + } + + @Test + public void testConformanceWithMethods() throws Exception { + providers.put(AbstractJaxRsConformanceProvider.class, provider); + providers.put(TestJaxRsMockPatientRestProviderDstu3.class, new TestJaxRsMockPatientRestProviderDstu3()); + Response response = createConformanceProvider(providers).conformance(); + assertEquals(Constants.STATUS_HTTP_200_OK, response.getStatus()); + assertTrue(response.getEntity().toString().contains("\"type\": \"Patient\"")); + assertTrue(response.getEntity().toString().contains("\"someCustomOperation")); + System.out.println(response); + System.out.println(response.getEntity()); + } + + @Test + public void testConformanceInXml() throws Exception { + queryParameters.put(Constants.PARAM_FORMAT, Arrays.asList(Constants.CT_XML)); + providers.put(AbstractJaxRsConformanceProvider.class, provider); + providers.put(TestJaxRsMockPatientRestProviderDstu3.class, new TestJaxRsMockPatientRestProviderDstu3()); + Response response = createConformanceProvider(providers).conformance(); + assertEquals(Constants.STATUS_HTTP_200_OK, response.getStatus()); + System.out.println(response.getEntity()); + assertTrue(response.getEntity().toString().contains(" ")); + assertTrue(response.getEntity().toString().contains("\"someCustomOperation")); + System.out.println(response.getEntity()); + } + + private AbstractJaxRsConformanceProvider createConformanceProvider(final ConcurrentHashMap, IResourceProvider> providers) + throws Exception { + AbstractJaxRsConformanceProvider result = new AbstractJaxRsConformanceProvider(FhirContext.forDstu3(), null, null, null) { + @Override + protected ConcurrentHashMap, IResourceProvider> getProviders() { + return providers; + } + }; + // mocks + UriInfo uriInfo = mock(UriInfo.class); + when(uriInfo.getQueryParameters()).thenReturn(queryParameters); + when(uriInfo.getBaseUri()).thenReturn(new URI(BASEURI)); + when(uriInfo.getRequestUri()).thenReturn(new URI(BASEURI + "/foo")); + result.setUriInfo(uriInfo); + result.setHeaders(headers); + result.setUpPostConstruct(); + return result; + } + +} diff --git a/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/server/AbstractJaxRsConformanceProviderR4Test.java b/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/server/AbstractJaxRsConformanceProviderR4Test.java index f7acd0f6daa..b897154483c 100644 --- a/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/server/AbstractJaxRsConformanceProviderR4Test.java +++ b/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/server/AbstractJaxRsConformanceProviderR4Test.java @@ -6,8 +6,8 @@ import ca.uhn.fhir.jaxrs.server.test.TestJaxRsMockPatientRestProviderR4; import ca.uhn.fhir.rest.api.Constants; import ca.uhn.fhir.rest.server.IResourceProvider; import org.jboss.resteasy.specimpl.ResteasyHttpHeaders; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import javax.ws.rs.core.MultivaluedHashMap; import javax.ws.rs.core.Response; @@ -16,7 +16,7 @@ import java.net.URI; import java.util.Arrays; import java.util.concurrent.ConcurrentHashMap; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -29,7 +29,7 @@ public class AbstractJaxRsConformanceProviderR4Test { private ResteasyHttpHeaders headers; private MultivaluedHashMap queryParameters; - @Before + @BeforeEach public void setUp() throws Exception { // uri info queryParameters = new MultivaluedHashMap<>(); diff --git a/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/server/AbstractJaxRsConformanceProviderTest.java b/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/server/AbstractJaxRsConformanceProviderTest.java index 5176f04cb46..5d8ad75a028 100644 --- a/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/server/AbstractJaxRsConformanceProviderTest.java +++ b/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/server/AbstractJaxRsConformanceProviderTest.java @@ -5,8 +5,8 @@ import ca.uhn.fhir.jaxrs.server.test.TestJaxRsMockPatientRestProvider; import ca.uhn.fhir.rest.api.Constants; import ca.uhn.fhir.rest.server.IResourceProvider; import org.jboss.resteasy.specimpl.ResteasyHttpHeaders; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import javax.ws.rs.core.MultivaluedHashMap; import javax.ws.rs.core.Response; @@ -15,7 +15,7 @@ import java.net.URI; import java.util.Arrays; import java.util.concurrent.ConcurrentHashMap; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -28,7 +28,7 @@ public class AbstractJaxRsConformanceProviderTest { private ResteasyHttpHeaders headers; private MultivaluedHashMap queryParameters; - @Before + @BeforeEach public void setUp() throws Exception { // uri info queryParameters = new MultivaluedHashMap<>(); diff --git a/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/server/AbstractJaxRsProviderTest.java b/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/server/AbstractJaxRsProviderTest.java index 4ff13b44da0..6abf8f9b82d 100644 --- a/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/server/AbstractJaxRsProviderTest.java +++ b/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/server/AbstractJaxRsProviderTest.java @@ -1,21 +1,5 @@ package ca.uhn.fhir.jaxrs.server; -import static org.junit.Assert.*; -import static org.mockito.Mockito.*; - -import java.io.IOException; -import java.net.URI; -import java.net.URISyntaxException; -import java.util.HashMap; - -import javax.ws.rs.core.*; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; - import ca.uhn.fhir.jaxrs.server.interceptor.JaxRsResponseException; import ca.uhn.fhir.jaxrs.server.util.JaxRsRequest; import ca.uhn.fhir.jaxrs.server.util.JaxRsResponse; @@ -24,62 +8,80 @@ import ca.uhn.fhir.parser.DataFormatException; import ca.uhn.fhir.rest.api.Constants; import ca.uhn.fhir.rest.api.server.IRestfulResponse; import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +import javax.ws.rs.core.MultivaluedHashMap; +import javax.ws.rs.core.MultivaluedMap; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.UriInfo; +import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; @SuppressWarnings("javadoc") -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class AbstractJaxRsProviderTest { - private AbstractJaxRsProviderMock provider; - @Mock - private JaxRsRequest theRequest; + private AbstractJaxRsProviderMock provider; + @Mock + private JaxRsRequest theRequest; - @Before - public void setUp() { - provider = new AbstractJaxRsProviderMock(); - final IRestfulResponse response = new JaxRsResponse(theRequest); - doReturn(provider).when(theRequest).getServer(); - doReturn(response).when(theRequest).getResponse(); - } + @BeforeEach + public void setUp() { + provider = new AbstractJaxRsProviderMock(); + final IRestfulResponse response = new JaxRsResponse(theRequest); + doReturn(provider).when(theRequest).getServer(); + doReturn(response).when(theRequest).getResponse(); + } - @Test - public void testHandleExceptionDataFormatException() throws IOException, URISyntaxException { - final DataFormatException theException = new DataFormatException(); - UriInfo uriInfo = mock(UriInfo.class); - when(uriInfo.getRequestUri()).thenReturn(new URI("http://example.com")); - when(uriInfo.getBaseUri()).thenReturn(new URI("http://example.com")); - when(uriInfo.getQueryParameters()).thenReturn(new MultivaluedHashMap()); - provider.setUriInfo(uriInfo); - final Response result = provider.handleException(theRequest, theException); - assertNotNull(result); - assertEquals(Constants.STATUS_HTTP_400_BAD_REQUEST, result.getStatus()); - } + @Test + public void testHandleExceptionDataFormatException() throws IOException, URISyntaxException { + final DataFormatException theException = new DataFormatException(); + UriInfo uriInfo = mock(UriInfo.class); + when(uriInfo.getRequestUri()).thenReturn(new URI("http://example.com")); + when(uriInfo.getBaseUri()).thenReturn(new URI("http://example.com")); + when(uriInfo.getQueryParameters()).thenReturn(new MultivaluedHashMap()); + provider.setUriInfo(uriInfo); + final Response result = provider.handleException(theRequest, theException); + assertNotNull(result); + assertEquals(Constants.STATUS_HTTP_400_BAD_REQUEST, result.getStatus()); + } - @Test - public void testHandleExceptionJaxRsResponseException() throws IOException { - final ResourceNotFoundException base = new ResourceNotFoundException(new IdDt(1L)); - final JaxRsResponseException theException = new JaxRsResponseException(base); - final Response result = provider.handleException(theRequest, theException); - assertNotNull(result); - assertEquals(base.getStatusCode(), result.getStatus()); - } + @Test + public void testHandleExceptionJaxRsResponseException() throws IOException { + final ResourceNotFoundException base = new ResourceNotFoundException(new IdDt(1L)); + final JaxRsResponseException theException = new JaxRsResponseException(base); + final Response result = provider.handleException(theRequest, theException); + assertNotNull(result); + assertEquals(base.getStatusCode(), result.getStatus()); + } - @Test - public void testHandleExceptionRuntimeException() throws IOException, URISyntaxException { - final RuntimeException theException = new RuntimeException(); - final UriInfo mockUriInfo = mock(UriInfo.class); - final MultivaluedMap mockMap = mock(MultivaluedMap.class); - when(mockUriInfo.getBaseUri()).thenReturn(new URI("http://www.test.com")); - when(mockUriInfo.getRequestUri()).thenReturn(new URI("http://www.test.com/test")); - when(mockUriInfo.getQueryParameters()).thenReturn(mockMap); + @Test + public void testHandleExceptionRuntimeException() throws IOException, URISyntaxException { + assertFalse(provider.withStackTrace()); - provider.setUriInfo(mockUriInfo); - final Response result = provider.handleException(theRequest, theException); - assertNotNull(result); - assertEquals(Constants.STATUS_HTTP_500_INTERNAL_ERROR, result.getStatus()); - } + final RuntimeException theException = new RuntimeException(); + final UriInfo mockUriInfo = mock(UriInfo.class); + final MultivaluedMap mockMap = mock(MultivaluedMap.class); + when(mockUriInfo.getBaseUri()).thenReturn(new URI("http://www.test.com")); + when(mockUriInfo.getRequestUri()).thenReturn(new URI("http://www.test.com/test")); + when(mockUriInfo.getQueryParameters()).thenReturn(mockMap); + + provider.setUriInfo(mockUriInfo); + final Response result = provider.handleException(theRequest, theException); + assertNotNull(result); + assertEquals(Constants.STATUS_HTTP_500_INTERNAL_ERROR, result.getStatus()); + } - @Test - public void testWithStackTrace() { - assertFalse(provider.withStackTrace()); - } } diff --git a/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/server/AbstractJaxRsResourceProviderDstu3Test.java b/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/server/AbstractJaxRsResourceProviderDstu3Test.java index 4511a914840..d3c0497dc6f 100644 --- a/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/server/AbstractJaxRsResourceProviderDstu3Test.java +++ b/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/server/AbstractJaxRsResourceProviderDstu3Test.java @@ -7,13 +7,17 @@ import ca.uhn.fhir.jaxrs.server.test.TestJaxRsConformanceRestProviderDstu3; import ca.uhn.fhir.jaxrs.server.test.TestJaxRsMockPageProviderDstu3; import ca.uhn.fhir.jaxrs.server.test.TestJaxRsMockPatientRestProviderDstu3; import ca.uhn.fhir.model.primitive.UriDt; -import ca.uhn.fhir.rest.api.*; +import ca.uhn.fhir.rest.api.EncodingEnum; +import ca.uhn.fhir.rest.api.MethodOutcome; +import ca.uhn.fhir.rest.api.PreferReturnEnum; +import ca.uhn.fhir.rest.api.SearchStyleEnum; import ca.uhn.fhir.rest.client.api.IGenericClient; import ca.uhn.fhir.rest.client.api.ServerValidationModeEnum; import ca.uhn.fhir.rest.client.interceptor.LoggingInterceptor; import ca.uhn.fhir.rest.param.StringAndListParam; import ca.uhn.fhir.rest.param.StringParam; import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException; +import ca.uhn.fhir.test.utilities.JettyUtil; import ca.uhn.fhir.util.TestUtil; import org.apache.commons.lang3.StringUtils; import org.eclipse.jetty.server.Server; @@ -23,8 +27,13 @@ import org.hl7.fhir.dstu3.model.*; import org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent; import org.hl7.fhir.instance.model.api.IBaseOperationOutcome; import org.hl7.fhir.instance.model.api.IBaseResource; -import org.junit.*; -import org.junit.runners.MethodSorters; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.MethodOrderer; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestMethodOrder; import org.mockito.ArgumentCaptor; import org.mockito.ArgumentMatcher; import org.mockito.ArgumentMatchers; @@ -34,16 +43,20 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.argThat; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.isNull; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.reset; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; -import ca.uhn.fhir.test.utilities.JettyUtil; - -@FixMethodOrder(MethodSorters.NAME_ASCENDING) +@TestMethodOrder(MethodOrderer.Alphanumeric.class) public class AbstractJaxRsResourceProviderDstu3Test { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(AbstractJaxRsResourceProviderDstu3Test.class); @@ -65,7 +78,7 @@ public class AbstractJaxRsResourceProviderDstu3Test { assertEquals(id, Integer.parseInt(resource.getIdElement().getIdPart())); } - @AfterClass + @AfterAll public static void afterClassClearContext() throws Exception { JettyUtil.closeServer(jettyServer); TestUtil.clearAllStaticFieldsForUnitTest(); @@ -114,7 +127,7 @@ public class AbstractJaxRsResourceProviderDstu3Test { return result; } - @Before + @BeforeEach public void setUp() { this.mock = TestJaxRsMockPatientRestProviderDstu3.mock; idCaptor = ArgumentCaptor.forClass(IdType.class); @@ -329,14 +342,14 @@ public class AbstractJaxRsResourceProviderDstu3Test { /** Search - Subsetting (_summary and _elements) */ @Test - @Ignore + @Disabled public void testSummary() { Object response = client.search().forResource(Patient.class) .returnBundle(org.hl7.fhir.dstu3.model.Bundle.class).execute(); } /** Transaction - Server */ -// @Ignore +// @Disabled // @Test // public void testTransaction() { // ca.uhn.fhir.model.api.Bundle bundle = new ca.uhn.fhir.model.api.Bundle(); @@ -370,7 +383,7 @@ public class AbstractJaxRsResourceProviderDstu3Test { } @SuppressWarnings("unchecked") - @Ignore + @Disabled @Test public void testResourceNotFound() throws Exception { when(mock.update(idCaptor.capture(), patientCaptor.capture(), conditionalCaptor.capture())).thenThrow(ResourceNotFoundException.class); @@ -420,7 +433,7 @@ public class AbstractJaxRsResourceProviderDstu3Test { assertNotNull(mO.getOperationOutcome()); } - @BeforeClass + @BeforeAll public static void setUpClass() throws Exception { ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); context.setContextPath("/"); diff --git a/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/server/AbstractJaxRsResourceProviderTest.java b/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/server/AbstractJaxRsResourceProviderTest.java index c97eccbf8d2..954d3c2c650 100644 --- a/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/server/AbstractJaxRsResourceProviderTest.java +++ b/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/server/AbstractJaxRsResourceProviderTest.java @@ -8,12 +8,19 @@ import ca.uhn.fhir.jaxrs.server.test.TestJaxRsMockPageProvider; import ca.uhn.fhir.jaxrs.server.test.TestJaxRsMockPatientRestProvider; import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.model.dstu2.composite.IdentifierDt; -import ca.uhn.fhir.model.dstu2.resource.*; +import ca.uhn.fhir.model.dstu2.resource.Bundle; +import ca.uhn.fhir.model.dstu2.resource.Conformance; +import ca.uhn.fhir.model.dstu2.resource.OperationOutcome; +import ca.uhn.fhir.model.dstu2.resource.Parameters; +import ca.uhn.fhir.model.dstu2.resource.Patient; import ca.uhn.fhir.model.primitive.DateDt; 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.api.*; +import ca.uhn.fhir.rest.api.EncodingEnum; +import ca.uhn.fhir.rest.api.MethodOutcome; +import ca.uhn.fhir.rest.api.PreferReturnEnum; +import ca.uhn.fhir.rest.api.SearchStyleEnum; import ca.uhn.fhir.rest.client.api.IGenericClient; import ca.uhn.fhir.rest.client.api.ServerValidationModeEnum; import ca.uhn.fhir.rest.client.interceptor.LoggingInterceptor; @@ -21,14 +28,20 @@ import ca.uhn.fhir.rest.param.StringAndListParam; import ca.uhn.fhir.rest.param.StringParam; import ca.uhn.fhir.rest.server.SimpleBundleProvider; import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException; +import ca.uhn.fhir.test.utilities.JettyUtil; import ca.uhn.fhir.util.TestUtil; import org.apache.commons.lang3.StringUtils; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletHolder; import org.hl7.fhir.instance.model.api.IBaseOperationOutcome; -import org.junit.*; -import org.junit.runners.MethodSorters; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.MethodOrderer; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestMethodOrder; import org.mockito.ArgumentCaptor; import org.mockito.Matchers; @@ -37,16 +50,20 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.argThat; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.isNull; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.reset; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; -import ca.uhn.fhir.test.utilities.JettyUtil; - -@FixMethodOrder(MethodSorters.NAME_ASCENDING) +@TestMethodOrder(MethodOrderer.Alphanumeric.class) public class AbstractJaxRsResourceProviderTest { private static IGenericClient client; @@ -70,7 +87,7 @@ public class AbstractJaxRsResourceProviderTest { assertEquals(url, resource.getId().getValueAsString().substring(serverBase.length() - 1)); } - @AfterClass + @AfterAll public static void afterClassClearContext() throws Exception { JettyUtil.closeServer(jettyServer); TestUtil.clearAllStaticFieldsForUnitTest(); @@ -110,7 +127,7 @@ public class AbstractJaxRsResourceProviderTest { compareResultUrl("/Patient/1", result); } - @Before + @BeforeEach public void setUp() { this.mock = TestJaxRsMockPatientRestProvider.mock; idCaptor = ArgumentCaptor.forClass(IdDt.class); @@ -308,7 +325,7 @@ public class AbstractJaxRsResourceProviderTest { /** Search - Subsetting (_summary and _elements) */ @Test - @Ignore + @Disabled public void testSummary() { Object response = client.search().forResource(Patient.class) .returnBundle(ca.uhn.fhir.model.dstu2.resource.Bundle.class).execute(); @@ -332,7 +349,7 @@ public class AbstractJaxRsResourceProviderTest { } @SuppressWarnings("unchecked") - @Ignore + @Disabled @Test public void testResourceNotFound() throws Exception { when(mock.update(idCaptor.capture(), patientCaptor.capture(), conditionalCaptor.capture())).thenThrow(ResourceNotFoundException.class); @@ -417,7 +434,7 @@ public class AbstractJaxRsResourceProviderTest { }); } - @BeforeClass + @BeforeAll public static void setUpClass() throws Exception { ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); context.setContextPath("/"); diff --git a/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/server/interceptor/JaxRsExceptionInterceptorTest.java b/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/server/interceptor/JaxRsExceptionInterceptorTest.java index 8ca3d08cb8d..249fe726368 100644 --- a/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/server/interceptor/JaxRsExceptionInterceptorTest.java +++ b/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/server/interceptor/JaxRsExceptionInterceptorTest.java @@ -1,6 +1,6 @@ package ca.uhn.fhir.jaxrs.server.interceptor; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Matchers.any; import static org.mockito.Matchers.isNull; import static org.mockito.Mockito.*; @@ -13,8 +13,8 @@ import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.ws.rs.core.*; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import ca.uhn.fhir.jaxrs.server.AbstractJaxRsProvider; import ca.uhn.fhir.jaxrs.server.test.TestJaxRsDummyPatientProvider; @@ -28,7 +28,7 @@ public class JaxRsExceptionInterceptorTest { JaxRsExceptionInterceptor interceptor = new JaxRsExceptionInterceptor(); private InvocationContext context; - @Before + @BeforeEach public void setUp() throws Exception { interceptor = new JaxRsExceptionInterceptor(); context = mock(InvocationContext.class); diff --git a/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/server/interceptor/JaxRsResponseExceptionTest.java b/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/server/interceptor/JaxRsResponseExceptionTest.java index 52dacb73e74..bfa5d6b8b8f 100644 --- a/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/server/interceptor/JaxRsResponseExceptionTest.java +++ b/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/server/interceptor/JaxRsResponseExceptionTest.java @@ -1,11 +1,11 @@ package ca.uhn.fhir.jaxrs.server.interceptor; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; import javax.ejb.ApplicationException; -import org.junit.Test; +import org.junit.jupiter.api.Test; import ca.uhn.fhir.rest.server.exceptions.ForbiddenOperationException; diff --git a/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/server/util/JaxRsMethodBindingsDstu3Test.java b/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/server/util/JaxRsMethodBindingsDstu3Test.java index 744b1f32fb7..f8725b7ff3e 100644 --- a/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/server/util/JaxRsMethodBindingsDstu3Test.java +++ b/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/server/util/JaxRsMethodBindingsDstu3Test.java @@ -1,22 +1,6 @@ package ca.uhn.fhir.jaxrs.server.util; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import java.util.List; - -import org.hl7.fhir.dstu3.model.IdType; -import org.hl7.fhir.dstu3.model.Parameters; -import org.hl7.fhir.dstu3.model.Patient; -import org.hl7.fhir.dstu3.model.StringType; -import org.junit.Before; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.runners.MethodSorters; - import ca.uhn.fhir.jaxrs.server.test.TestJaxRsDummyPatientProviderDstu3; -import ca.uhn.fhir.jaxrs.server.util.JaxRsMethodBindings; import ca.uhn.fhir.rest.annotation.IdParam; import ca.uhn.fhir.rest.annotation.Operation; import ca.uhn.fhir.rest.annotation.OperationParam; @@ -28,32 +12,46 @@ import ca.uhn.fhir.rest.api.MethodOutcome; import ca.uhn.fhir.rest.api.RestOperationTypeEnum; import ca.uhn.fhir.rest.param.StringParam; import ca.uhn.fhir.rest.server.exceptions.NotImplementedOperationException; +import org.hl7.fhir.dstu3.model.IdType; +import org.hl7.fhir.dstu3.model.Parameters; +import org.hl7.fhir.dstu3.model.Patient; +import org.hl7.fhir.dstu3.model.StringType; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; -@FixMethodOrder(MethodSorters.DEFAULT) public class JaxRsMethodBindingsDstu3Test { - - @Before - public void setUp() { - JaxRsMethodBindings.getClassBindings().clear(); - } - @Test(expected = NotImplementedOperationException.class) - public void testFindMethodsForProviderNotDefinedMappingMethods() { - new TestJaxRsDummyPatientProviderDstu3().getBindings().getBinding(RestOperationTypeEnum.UPDATE, ""); + @BeforeEach + public void setUp() { + JaxRsMethodBindings.getClassBindings().clear(); } - + + @Test + public void testFindMethodsForProviderNotDefinedMappingMethods() { + assertThrows(NotImplementedOperationException.class, () -> { + new TestJaxRsDummyPatientProviderDstu3().getBindings().getBinding(RestOperationTypeEnum.UPDATE, ""); + }); + } + @Test public void testFindMethodsForProviderWithMethods() { class TestFindPatientProvider extends TestJaxRsDummyPatientProviderDstu3 { - @Search - public List search(@RequiredParam(name = Patient.SP_NAME) final StringParam name) { - return null; - } + @Search + public List search(@RequiredParam(name = Patient.SP_NAME) final StringParam name) { + return null; + } } new TestFindPatientProvider(); assertEquals(TestFindPatientProvider.class, new TestFindPatientProvider().getBindings().getBinding(RestOperationTypeEnum.SEARCH_TYPE, "").getMethod().getDeclaringClass()); } - + @Test public void testFindMethodsFor2ProvidersWithMethods() { class TestFindPatientProvider extends TestJaxRsDummyPatientProviderDstu3 { @@ -63,15 +61,15 @@ public class JaxRsMethodBindingsDstu3Test { } } class TestUpdatePatientProvider extends TestJaxRsDummyPatientProviderDstu3 { - @Update - public MethodOutcome update(@IdParam final IdType theId, @ResourceParam final Patient patient) { + @Update + public MethodOutcome update(@IdParam final IdType theId, @ResourceParam final Patient patient) { return null; } } assertEquals(TestFindPatientProvider.class, new TestFindPatientProvider().getBindings().getBinding(RestOperationTypeEnum.SEARCH_TYPE, "").getMethod().getDeclaringClass()); assertEquals(TestUpdatePatientProvider.class, new TestUpdatePatientProvider().getBindings().getBinding(RestOperationTypeEnum.UPDATE, "").getMethod().getDeclaringClass()); } - + @Test public void testFindMethodsWithDoubleMethodsDeclaration() { class TestDoubleSearchProvider extends TestJaxRsDummyPatientProviderDstu3 { @@ -79,7 +77,7 @@ public class JaxRsMethodBindingsDstu3Test { public List search1(@RequiredParam(name = Patient.SP_NAME) final StringParam name) { return null; } - + @Search public List search2(@RequiredParam(name = Patient.SP_NAME) final StringParam name) { return null; @@ -88,12 +86,12 @@ public class JaxRsMethodBindingsDstu3Test { try { new TestDoubleSearchProvider(); fail(); - } catch(IllegalArgumentException e) { + } catch (IllegalArgumentException e) { assertTrue(e.getMessage().contains("search1")); assertTrue(e.getMessage().contains("search2")); } } - + @Test public void testFindMethodsWithMultipleMethods() { class TestFindPatientProvider extends TestJaxRsDummyPatientProviderDstu3 { @@ -101,15 +99,18 @@ public class JaxRsMethodBindingsDstu3Test { public List search(@RequiredParam(name = Patient.SP_NAME) final StringParam name) { return null; } + @Update public MethodOutcome update(@IdParam final IdType theId, @ResourceParam final Patient patient) { return null; } - @Operation(name = "firstMethod", idempotent = true, returnParameters = { @OperationParam(name = "return", type = StringType.class) }) + + @Operation(name = "firstMethod", idempotent = true, returnParameters = {@OperationParam(name = "return", type = StringType.class)}) public Parameters firstMethod(@OperationParam(name = "dummy") StringType dummyInput) { return null; } - @Operation(name = "secondMethod", returnParameters = { @OperationParam(name = "return", type = StringType.class) }) + + @Operation(name = "secondMethod", returnParameters = {@OperationParam(name = "return", type = StringType.class)}) public Parameters secondMethod(@OperationParam(name = "dummy") StringType dummyInput) { return null; } @@ -122,8 +123,8 @@ public class JaxRsMethodBindingsDstu3Test { try { bindings.getBinding(RestOperationTypeEnum.EXTENDED_OPERATION_TYPE, "$thirdMethod"); fail(); - } catch(NotImplementedOperationException e){ + } catch (NotImplementedOperationException e) { } - } + } } diff --git a/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/server/util/JaxRsMethodBindingsMimeTypeTest.java b/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/server/util/JaxRsMethodBindingsMimeTypeTest.java index c4ea3fb3530..822b363bfb0 100644 --- a/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/server/util/JaxRsMethodBindingsMimeTypeTest.java +++ b/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/server/util/JaxRsMethodBindingsMimeTypeTest.java @@ -4,25 +4,22 @@ import ca.uhn.fhir.jaxrs.server.test.AbstractDummyPatientProvider; import ca.uhn.fhir.jaxrs.server.test.TestJaxRsDummyPatientProviderR4; import ca.uhn.fhir.jaxrs.server.test.TestJaxRsDummyPatientProviderR4MimeType; import ca.uhn.fhir.rest.api.RestOperationTypeEnum; -import org.junit.Before; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.runners.MethodSorters; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -@FixMethodOrder(MethodSorters.DEFAULT) public class JaxRsMethodBindingsMimeTypeTest { - - @Before - public void setUp() { - JaxRsMethodBindings.getClassBindings().clear(); - } + + @BeforeEach + public void setUp() { + JaxRsMethodBindings.getClassBindings().clear(); + } @Test public void testFindMethodsFor2ProvidersWithMethods() { assertEquals(AbstractDummyPatientProvider.class, new TestJaxRsDummyPatientProviderR4().getBindings().getBinding(RestOperationTypeEnum.SEARCH_TYPE, "").getMethod().getDeclaringClass()); assertEquals(AbstractDummyPatientProvider.class, new TestJaxRsDummyPatientProviderR4MimeType().getBindings().getBinding(RestOperationTypeEnum.SEARCH_TYPE, "").getMethod().getDeclaringClass()); } - - } + +} diff --git a/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/server/util/JaxRsMethodBindingsTest.java b/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/server/util/JaxRsMethodBindingsTest.java index e70c77f1df2..b3ea3678315 100644 --- a/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/server/util/JaxRsMethodBindingsTest.java +++ b/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/server/util/JaxRsMethodBindingsTest.java @@ -1,16 +1,5 @@ package ca.uhn.fhir.jaxrs.server.util; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import java.util.List; - -import org.junit.Before; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.runners.MethodSorters; - import ca.uhn.fhir.jaxrs.server.test.TestJaxRsDummyPatientProvider; import ca.uhn.fhir.model.dstu2.resource.Parameters; import ca.uhn.fhir.model.dstu2.resource.Patient; @@ -27,32 +16,42 @@ import ca.uhn.fhir.rest.api.MethodOutcome; import ca.uhn.fhir.rest.api.RestOperationTypeEnum; import ca.uhn.fhir.rest.param.StringParam; import ca.uhn.fhir.rest.server.exceptions.NotImplementedOperationException; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; -@FixMethodOrder(MethodSorters.DEFAULT) public class JaxRsMethodBindingsTest { - - @Before - public void setUp() { - JaxRsMethodBindings.getClassBindings().clear(); - } - @Test(expected = NotImplementedOperationException.class) - public void testFindMethodsForProviderNotDefinedMappingMethods() { - new TestJaxRsDummyPatientProvider().getBindings().getBinding(RestOperationTypeEnum.UPDATE, ""); + @BeforeEach + public void setUp() { + JaxRsMethodBindings.getClassBindings().clear(); } - + + @Test + public void testFindMethodsForProviderNotDefinedMappingMethods() { + assertThrows(NotImplementedOperationException.class, () -> { + new TestJaxRsDummyPatientProvider().getBindings().getBinding(RestOperationTypeEnum.UPDATE, ""); + }); + } + @Test public void testFindMethodsForProviderWithMethods() { class TestFindPatientProvider extends TestJaxRsDummyPatientProvider { - @Search - public List search(@RequiredParam(name = Patient.SP_NAME) final StringParam name) { - return null; - } + @Search + public List search(@RequiredParam(name = Patient.SP_NAME) final StringParam name) { + return null; + } } new TestFindPatientProvider(); assertEquals(TestFindPatientProvider.class, new TestFindPatientProvider().getBindings().getBinding(RestOperationTypeEnum.SEARCH_TYPE, "").getMethod().getDeclaringClass()); } - + @Test public void testFindMethodsFor2ProvidersWithMethods() { class TestFindPatientProvider extends TestJaxRsDummyPatientProvider { @@ -62,15 +61,15 @@ public class JaxRsMethodBindingsTest { } } class TestUpdatePatientProvider extends TestJaxRsDummyPatientProvider { - @Update - public MethodOutcome update(@IdParam final IdDt theId, @ResourceParam final Patient patient) { + @Update + public MethodOutcome update(@IdParam final IdDt theId, @ResourceParam final Patient patient) { return null; } } assertEquals(TestFindPatientProvider.class, new TestFindPatientProvider().getBindings().getBinding(RestOperationTypeEnum.SEARCH_TYPE, "").getMethod().getDeclaringClass()); assertEquals(TestUpdatePatientProvider.class, new TestUpdatePatientProvider().getBindings().getBinding(RestOperationTypeEnum.UPDATE, "").getMethod().getDeclaringClass()); } - + @Test public void testFindMethodsWithDoubleMethodsDeclaration() { class TestDoubleSearchProvider extends TestJaxRsDummyPatientProvider { @@ -78,7 +77,7 @@ public class JaxRsMethodBindingsTest { public List search1(@RequiredParam(name = Patient.SP_NAME) final StringParam name) { return null; } - + @Search public List search2(@RequiredParam(name = Patient.SP_NAME) final StringParam name) { return null; @@ -87,12 +86,12 @@ public class JaxRsMethodBindingsTest { try { new TestDoubleSearchProvider(); fail(); - } catch(IllegalArgumentException e) { + } catch (IllegalArgumentException e) { assertTrue(e.getMessage().contains("search1")); assertTrue(e.getMessage().contains("search2")); } } - + @Test public void testFindMethodsWithMultipleMethods() { class TestFindPatientProvider extends TestJaxRsDummyPatientProvider { @@ -100,15 +99,18 @@ public class JaxRsMethodBindingsTest { public List search(@RequiredParam(name = Patient.SP_NAME) final StringParam name) { return null; } + @Update public MethodOutcome update(@IdParam final IdDt theId, @ResourceParam final Patient patient) { return null; } - @Operation(name = "firstMethod", idempotent = true, returnParameters = { @OperationParam(name = "return", type = StringDt.class) }) + + @Operation(name = "firstMethod", idempotent = true, returnParameters = {@OperationParam(name = "return", type = StringDt.class)}) public Parameters firstMethod(@OperationParam(name = "dummy") StringDt dummyInput) { return null; } - @Operation(name = "secondMethod", returnParameters = { @OperationParam(name = "return", type = StringDt.class) }) + + @Operation(name = "secondMethod", returnParameters = {@OperationParam(name = "return", type = StringDt.class)}) public Parameters secondMethod(@OperationParam(name = "dummy") StringDt dummyInput) { return null; } @@ -121,8 +123,8 @@ public class JaxRsMethodBindingsTest { try { bindings.getBinding(RestOperationTypeEnum.EXTENDED_OPERATION_TYPE, "$thirdMethod"); fail(); - } catch(NotImplementedOperationException e){ + } catch (NotImplementedOperationException e) { } - } + } } diff --git a/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/server/util/JaxRsRequestDstu3Test.java b/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/server/util/JaxRsRequestDstu3Test.java index 4fde9eaba3b..a9d22cac006 100644 --- a/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/server/util/JaxRsRequestDstu3Test.java +++ b/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/server/util/JaxRsRequestDstu3Test.java @@ -3,10 +3,11 @@ package ca.uhn.fhir.jaxrs.server.util; import ca.uhn.fhir.jaxrs.server.test.TestJaxRsDummyPatientProviderDstu3; import ca.uhn.fhir.rest.api.RequestTypeEnum; import ca.uhn.fhir.rest.api.RestOperationTypeEnum; +import ca.uhn.fhir.rest.server.exceptions.NotImplementedOperationException; import org.apache.commons.lang3.StringUtils; import org.jboss.resteasy.specimpl.ResteasyHttpHeaders; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import javax.ws.rs.core.MultivaluedHashMap; import javax.ws.rs.core.MultivaluedMap; @@ -15,7 +16,7 @@ import java.io.IOException; import java.net.URISyntaxException; import java.util.Arrays; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.*; public class JaxRsRequestDstu3Test { @@ -29,7 +30,7 @@ public class JaxRsRequestDstu3Test { private ResteasyHttpHeaders headers; private TestJaxRsDummyPatientProviderDstu3 provider; - @Before + @BeforeEach public void setUp() throws URISyntaxException { details = createRequestDetails(); } @@ -66,14 +67,18 @@ public class JaxRsRequestDstu3Test { assertTrue(response == details.getResponse()); } - @Test(expected = UnsupportedOperationException.class) - public void testGetReader() throws IOException { - details.getReader(); + @Test + public void testGetReader() { + assertThrows(UnsupportedOperationException.class, ()->{ + details.getReader(); + }); } - @Test(expected = UnsupportedOperationException.class) + @Test public void testGetInputStream() { - details.getInputStream(); + assertThrows(UnsupportedOperationException.class, ()->{ + details.getInputStream(); + }); } @Test diff --git a/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/server/util/JaxRsRequestTest.java b/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/server/util/JaxRsRequestTest.java index 87c55cbcdd4..f4badf06e66 100644 --- a/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/server/util/JaxRsRequestTest.java +++ b/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/server/util/JaxRsRequestTest.java @@ -3,10 +3,11 @@ package ca.uhn.fhir.jaxrs.server.util; import ca.uhn.fhir.jaxrs.server.test.TestJaxRsDummyPatientProvider; import ca.uhn.fhir.rest.api.RequestTypeEnum; import ca.uhn.fhir.rest.api.RestOperationTypeEnum; +import ca.uhn.fhir.rest.server.exceptions.NotImplementedOperationException; import org.apache.commons.lang3.StringUtils; import org.jboss.resteasy.specimpl.ResteasyHttpHeaders; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import javax.ws.rs.core.MultivaluedHashMap; import javax.ws.rs.core.MultivaluedMap; @@ -15,7 +16,7 @@ import java.io.IOException; import java.net.URISyntaxException; import java.util.Arrays; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.*; public class JaxRsRequestTest { @@ -29,7 +30,7 @@ public class JaxRsRequestTest { private ResteasyHttpHeaders headers; private TestJaxRsDummyPatientProvider provider; - @Before + @BeforeEach public void setUp() throws URISyntaxException { details = createRequestDetails(); } @@ -66,14 +67,18 @@ public class JaxRsRequestTest { assertTrue(response == details.getResponse()); } - @Test(expected = UnsupportedOperationException.class) + @Test public void testGetReader() throws IOException { - details.getReader(); + assertThrows(UnsupportedOperationException.class,()->{ + details.getReader(); + }); } - @Test(expected = UnsupportedOperationException.class) + @Test public void testGetInputStream() { - details.getInputStream(); + assertThrows(UnsupportedOperationException.class, ()->{ + details.getInputStream(); + }); } @Test diff --git a/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/server/util/JaxRsResponseDstu3Test.java b/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/server/util/JaxRsResponseDstu3Test.java index 510d995e860..d08f334ca6d 100644 --- a/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/server/util/JaxRsResponseDstu3Test.java +++ b/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/server/util/JaxRsResponseDstu3Test.java @@ -1,7 +1,7 @@ package ca.uhn.fhir.jaxrs.server.util; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; import java.net.URISyntaxException; @@ -12,8 +12,8 @@ import javax.ws.rs.core.Response; import org.hl7.fhir.dstu3.model.*; import org.hl7.fhir.instance.model.api.IBaseBinary; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import ca.uhn.fhir.rest.api.Constants; import ca.uhn.fhir.rest.api.MethodOutcome; @@ -27,7 +27,7 @@ public class JaxRsResponseDstu3Test { private Bundle bundle; private Set theSummaryMode; - @Before + @BeforeEach public void setUp() throws URISyntaxException { request = new JaxRsRequestDstu3Test().createRequestDetails(); this.response = (JaxRsResponse) request.getResponse(); diff --git a/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/server/util/JaxRsResponseTest.java b/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/server/util/JaxRsResponseTest.java index c5b58275855..7aa1b36e5d6 100644 --- a/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/server/util/JaxRsResponseTest.java +++ b/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/server/util/JaxRsResponseTest.java @@ -1,8 +1,8 @@ package ca.uhn.fhir.jaxrs.server.util; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; import java.net.URISyntaxException; @@ -13,8 +13,8 @@ import javax.ws.rs.core.Response; import org.hamcrest.Matchers; import org.hl7.fhir.instance.model.api.IBaseBinary; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import ca.uhn.fhir.model.dstu2.resource.Binary; import ca.uhn.fhir.model.dstu2.resource.Patient; @@ -29,7 +29,7 @@ public class JaxRsResponseTest { private JaxRsRequest request; private Set theSummaryMode; - @Before + @BeforeEach public void setUp() throws URISyntaxException { request = new JaxRsRequestTest().createRequestDetails(); this.response = (JaxRsResponse) request.getResponse(); diff --git a/hapi-fhir-jaxrsserver-example/src/test/java/ca/uhn/fhir/jaxrs/server/example/JaxRsPatientProviderDstu3Test.java b/hapi-fhir-jaxrsserver-example/src/test/java/ca/uhn/fhir/jaxrs/server/example/JaxRsPatientProviderDstu3Test.java index 1dbf355bf6b..dc88d84bf47 100644 --- a/hapi-fhir-jaxrsserver-example/src/test/java/ca/uhn/fhir/jaxrs/server/example/JaxRsPatientProviderDstu3Test.java +++ b/hapi-fhir-jaxrsserver-example/src/test/java/ca/uhn/fhir/jaxrs/server/example/JaxRsPatientProviderDstu3Test.java @@ -1,6 +1,6 @@ package ca.uhn.fhir.jaxrs.server.example; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.util.Arrays; import java.util.List; @@ -12,7 +12,7 @@ import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletHolder; import org.hl7.fhir.dstu3.model.*; import org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent; -import org.junit.*; +import org.junit.jupiter.api.*; import static org.hamcrest.MatcherAssert.assertThat; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.jaxrs.client.JaxRsRestfulClientFactory; @@ -31,13 +31,13 @@ public class JaxRsPatientProviderDstu3Test { private static int ourPort; private static Server jettyServer; - @AfterClass + @AfterAll public static void afterClassClearContext() throws Exception { JettyUtil.closeServer(jettyServer); TestUtil.clearAllStaticFieldsForUnitTest(); } - @BeforeClass + @BeforeAll public static void setUpClass() throws Exception { ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); @@ -124,7 +124,7 @@ public class JaxRsPatientProviderDstu3Test { /** Search - Subsetting (_summary and _elements) */ @Test - @Ignore + @Disabled public void testSummary() { client.search() .forResource(Patient.class) @@ -202,7 +202,7 @@ public class JaxRsPatientProviderDstu3Test { /** Conformance - Server */ @Test - @Ignore + @Disabled public void testConformance() { final CapabilityStatement conf = client.fetchConformance().ofType(CapabilityStatement.class).execute(); System.out.println(conf.getRest().get(0).getResource().get(0).getType()); @@ -231,7 +231,7 @@ public class JaxRsPatientProviderDstu3Test { .execute(); String resultValue = outParams.getParameter().get(0).getValue().toString(); System.out.println(resultValue); - assertEquals("expected but found : "+ resultValue, resultValue.contains("myAwesomeDummyValue"), true); + assertEquals(resultValue.contains("myAwesomeDummyValue"), true, "expected but found : "+ resultValue); } @Test @@ -252,7 +252,7 @@ public class JaxRsPatientProviderDstu3Test { .execute(); String resultValue = outParams.getParameter().get(0).getValue().toString(); System.out.println(resultValue); - assertEquals("expected but found : "+ resultValue, resultValue.contains("myAwesomeDummyValue"), true); + assertEquals(resultValue.contains("myAwesomeDummyValue"), true, "expected but found : "+ resultValue); } @Test diff --git a/hapi-fhir-jaxrsserver-example/src/test/java/ca/uhn/fhir/jaxrs/server/example/JaxRsPatientProviderR4Test.java b/hapi-fhir-jaxrsserver-example/src/test/java/ca/uhn/fhir/jaxrs/server/example/JaxRsPatientProviderR4Test.java index 414d5167675..053d83b783b 100644 --- a/hapi-fhir-jaxrsserver-example/src/test/java/ca/uhn/fhir/jaxrs/server/example/JaxRsPatientProviderR4Test.java +++ b/hapi-fhir-jaxrsserver-example/src/test/java/ca/uhn/fhir/jaxrs/server/example/JaxRsPatientProviderR4Test.java @@ -16,15 +16,15 @@ import org.eclipse.jetty.server.Server; import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletHolder; import org.hl7.fhir.r4.model.*; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import java.util.Arrays; import java.util.List; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; public class JaxRsPatientProviderR4Test { @@ -34,13 +34,13 @@ public class JaxRsPatientProviderR4Test { private static int ourPort; private static Server jettyServer; - @AfterClass + @AfterAll public static void afterClassClearContext() throws Exception { JettyUtil.closeServer(jettyServer); TestUtil.clearAllStaticFieldsForUnitTest(); } - @BeforeClass + @BeforeAll public static void setUpClass() throws Exception { ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); @@ -135,7 +135,7 @@ public class JaxRsPatientProviderR4Test { /** Search - Subsetting (_summary and _elements) */ @Test - @Ignore + @Disabled public void testSummary() { client.search() .forResource(Patient.class) @@ -209,7 +209,7 @@ public class JaxRsPatientProviderR4Test { } /** Transaction - Server */ - @Ignore + @Disabled @Test public void testTransaction() { Bundle bundle = new Bundle(); @@ -226,7 +226,7 @@ public class JaxRsPatientProviderR4Test { /** Conformance - Server */ @Test - @Ignore + @Disabled public void testConformance() { final CapabilityStatement caps = client.capabilities().ofType(CapabilityStatement.class).execute(); System.out.println(caps.getRest().get(0).getResource().get(0).getType()); @@ -255,7 +255,7 @@ public class JaxRsPatientProviderR4Test { .execute(); String resultValue = outParams.getParameter().get(0).getValue().toString(); System.out.println(resultValue); - assertEquals("expected but found : " + resultValue, resultValue.contains("myAwesomeDummyValue"), true); + assertEquals(resultValue.contains("myAwesomeDummyValue"), true, "expected but found : " + resultValue); } @Test @@ -276,7 +276,7 @@ public class JaxRsPatientProviderR4Test { .execute(); String resultValue = outParams.getParameter().get(0).getValue().toString(); System.out.println(resultValue); - assertEquals("expected but found : " + resultValue, resultValue.contains("myAwesomeDummyValue"), true); + assertEquals(resultValue.contains("myAwesomeDummyValue"), true, "expected but found : " + resultValue); } @Test diff --git a/hapi-fhir-jaxrsserver-example/src/test/java/ca/uhn/fhir/jaxrs/server/example/JaxRsPatientProviderTest.java b/hapi-fhir-jaxrsserver-example/src/test/java/ca/uhn/fhir/jaxrs/server/example/JaxRsPatientProviderTest.java index 215ba2bf300..934673aa494 100644 --- a/hapi-fhir-jaxrsserver-example/src/test/java/ca/uhn/fhir/jaxrs/server/example/JaxRsPatientProviderTest.java +++ b/hapi-fhir-jaxrsserver-example/src/test/java/ca/uhn/fhir/jaxrs/server/example/JaxRsPatientProviderTest.java @@ -1,6 +1,6 @@ package ca.uhn.fhir.jaxrs.server.example; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.util.Arrays; import java.util.List; @@ -9,8 +9,8 @@ import org.apache.commons.lang3.StringUtils; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletHolder; -import org.junit.*; -import org.junit.Test; +import org.junit.jupiter.api.*; import static org.hamcrest.MatcherAssert.assertThat; +import org.junit.jupiter.api.Test; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.jaxrs.client.JaxRsRestfulClientFactory; @@ -34,13 +34,13 @@ public class JaxRsPatientProviderTest { private static int ourPort; private static Server jettyServer; - @AfterClass + @AfterAll public static void afterClassClearContext() throws Exception { JettyUtil.closeServer(jettyServer); TestUtil.clearAllStaticFieldsForUnitTest(); } - @BeforeClass + @BeforeAll public static void setUpClass() throws Exception { ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); @@ -135,7 +135,7 @@ public class JaxRsPatientProviderTest { /** Search - Subsetting (_summary and _elements) */ @Test - @Ignore + @Disabled public void testSummary() { client.search() .forResource(Patient.class) @@ -209,7 +209,7 @@ public class JaxRsPatientProviderTest { } /** Transaction - Server */ - @Ignore + @Disabled @Test public void testTransaction() { Bundle bundle = new Bundle(); @@ -226,7 +226,7 @@ public class JaxRsPatientProviderTest { /** Conformance - Server */ @Test - @Ignore + @Disabled public void testConformance() { final Conformance conf = client.fetchConformance().ofType(Conformance.class).execute(); System.out.println(conf.getRest().get(0).getResource().get(0).getType()); @@ -255,7 +255,7 @@ public class JaxRsPatientProviderTest { .execute(); String resultValue = outParams.getParameter().get(0).getValue().toString(); System.out.println(resultValue); - assertEquals("expected but found : " + resultValue, resultValue.contains("myAwesomeDummyValue"), true); + assertEquals(resultValue.contains("myAwesomeDummyValue"), true); } @Test @@ -276,7 +276,7 @@ public class JaxRsPatientProviderTest { .execute(); String resultValue = outParams.getParameter().get(0).getValue().toString(); System.out.println(resultValue); - assertEquals("expected but found : " + resultValue, resultValue.contains("myAwesomeDummyValue"), true); + assertEquals(resultValue.contains("myAwesomeDummyValue"), true, "expected but found : " + resultValue); } @Test diff --git a/hapi-fhir-jpaserver-base/pom.xml b/hapi-fhir-jpaserver-base/pom.xml index cf98a02b985..895d78ff727 100644 --- a/hapi-fhir-jpaserver-base/pom.xml +++ b/hapi-fhir-jpaserver-base/pom.xml @@ -248,11 +248,6 @@ - @@ -757,8 +750,7 @@ dstu3 ca.uhn.fhir.jpa.config ca.uhn.fhir.jpa.rp.dstu3 - hapi-fhir-server-resourceproviders-dstu3.xml - + hapi-fhir-server-resourceproviders-dstu3.xml @@ -773,8 +765,7 @@ r4 ca.uhn.fhir.jpa.config ca.uhn.fhir.jpa.rp.r4 - hapi-fhir-server-resourceproviders-r4.xml - + hapi-fhir-server-resourceproviders-r4.xml @@ -789,8 +780,7 @@ r5 ca.uhn.fhir.jpa.config ca.uhn.fhir.jpa.rp.r5 - hapi-fhir-server-resourceproviders-r5.xml - + hapi-fhir-server-resourceproviders-r5.xml diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/util/TestUtil.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/util/TestUtil.java index 1bea0ca4b24..3f5d8adf1ec 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/util/TestUtil.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/util/TestUtil.java @@ -285,11 +285,6 @@ public class TestUtil { } } - - public static void clearAllStaticFieldsForUnitTest() { - ca.uhn.fhir.util.TestUtil.clearAllStaticFieldsForUnitTest(); - } - public static InstantType getTimestamp(IBaseResource resource) { return new InstantType(new Date(resource.getMeta().getLastUpdated().getTime())); } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/binstore/BaseBinaryStorageSvcImplTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/binstore/BaseBinaryStorageSvcImplTest.java index 499d5a2a4f7..767f6990eaa 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/binstore/BaseBinaryStorageSvcImplTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/binstore/BaseBinaryStorageSvcImplTest.java @@ -1,11 +1,11 @@ package ca.uhn.fhir.jpa.binstore; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import static org.hamcrest.Matchers.matchesPattern; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; public class BaseBinaryStorageSvcImplTest { diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/binstore/DatabaseBlobBinaryStorageSvcImplTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/binstore/DatabaseBlobBinaryStorageSvcImplTest.java index e7b644bb2c9..c97eec91e5b 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/binstore/DatabaseBlobBinaryStorageSvcImplTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/binstore/DatabaseBlobBinaryStorageSvcImplTest.java @@ -5,9 +5,9 @@ import ca.uhn.fhir.jpa.dao.r4.BaseJpaR4Test; import ca.uhn.fhir.jpa.model.entity.BinaryStorageEntity; import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException; import org.hl7.fhir.r4.model.IdType; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.context.annotation.Bean; @@ -22,15 +22,15 @@ import java.sql.Blob; import java.sql.SQLException; import static org.hamcrest.CoreMatchers.containsString; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.matchesPattern; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -45,12 +45,12 @@ public class DatabaseBlobBinaryStorageSvcImplTest extends BaseJpaR4Test { @Autowired private DaoConfig myDaoConfig; - @Before + @BeforeEach public void backupDaoConfig() { defaultPreloadBlobFromInputStream = myDaoConfig.isPreloadBlobFromInputStream(); } - @After + @AfterEach public void restoreDaoConfig() { myDaoConfig.setPreloadBlobFromInputStream(defaultPreloadBlobFromInputStream); } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/binstore/FilesystemBinaryStorageSvcImplTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/binstore/FilesystemBinaryStorageSvcImplTest.java index 9326a58b87d..025007501b5 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/binstore/FilesystemBinaryStorageSvcImplTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/binstore/FilesystemBinaryStorageSvcImplTest.java @@ -5,9 +5,9 @@ import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException; import org.apache.commons.io.FileUtils; import org.hl7.fhir.instance.model.api.IIdType; import org.hl7.fhir.r4.model.IdType; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -16,7 +16,7 @@ import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; public class FilesystemBinaryStorageSvcImplTest { @@ -25,13 +25,13 @@ public class FilesystemBinaryStorageSvcImplTest { private File myPath; private FilesystemBinaryStorageSvcImpl mySvc; - @Before + @BeforeEach public void before() { myPath = new File("./target/fstmp"); mySvc = new FilesystemBinaryStorageSvcImpl(myPath.getAbsolutePath()); } - @After + @AfterEach public void after() throws IOException { FileUtils.deleteDirectory(myPath); } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/binstore/NullBinaryStorageSvcImplTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/binstore/NullBinaryStorageSvcImplTest.java index 856b4687979..45d0a91f2ac 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/binstore/NullBinaryStorageSvcImplTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/binstore/NullBinaryStorageSvcImplTest.java @@ -1,9 +1,10 @@ package ca.uhn.fhir.jpa.binstore; import org.hl7.fhir.r4.model.IdType; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertFalse; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; public class NullBinaryStorageSvcImplTest { @@ -14,33 +15,45 @@ public class NullBinaryStorageSvcImplTest { assertFalse(mySvc.shouldStoreBlob(1, new IdType("Patient/2"), "application/json")); } - @Test(expected = UnsupportedOperationException.class) + @Test public void storeBlob() { - mySvc.storeBlob(null, null, null, null); + assertThrows(UnsupportedOperationException.class, () -> { + mySvc.storeBlob(null, null, null, null); + }); } - @Test(expected = UnsupportedOperationException.class) + @Test public void fetchBlobDetails() { - mySvc.fetchBlobDetails(null, null); + assertThrows(UnsupportedOperationException.class, () -> { + mySvc.fetchBlobDetails(null, null); + }); } - @Test(expected = UnsupportedOperationException.class) + @Test public void writeBlob() { - mySvc.writeBlob(null, null, null); + assertThrows(UnsupportedOperationException.class, () -> { + mySvc.writeBlob(null, null, null); + }); } - @Test(expected = UnsupportedOperationException.class) + @Test public void expungeBlob() { - mySvc.expungeBlob(null, null); + assertThrows(UnsupportedOperationException.class, () -> { + mySvc.expungeBlob(null, null); + }); } - @Test(expected = UnsupportedOperationException.class) + @Test public void fetchBlob() { - mySvc.fetchBlob(null, null); + assertThrows(UnsupportedOperationException.class, () -> { + mySvc.fetchBlob(null, null); + }); } - @Test(expected = UnsupportedOperationException.class) + @Test public void newBlobId() { - mySvc.newBlobId(); + assertThrows(UnsupportedOperationException.class, () -> { + mySvc.newBlobId(); + }); } } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/bulk/BulkDataExportProviderTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/bulk/BulkDataExportProviderTest.java index 7e9c8100e0e..6ea7548091a 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/bulk/BulkDataExportProviderTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/bulk/BulkDataExportProviderTest.java @@ -1,6 +1,7 @@ package ca.uhn.fhir.jpa.bulk; import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.context.FhirVersionEnum; import ca.uhn.fhir.jpa.bulk.api.IBulkDataExportSvc; import ca.uhn.fhir.jpa.bulk.model.BulkExportResponseJson; import ca.uhn.fhir.jpa.bulk.model.BulkJobStatusEnum; @@ -28,14 +29,14 @@ import org.hl7.fhir.r4.model.IdType; import org.hl7.fhir.r4.model.InstantType; import org.hl7.fhir.r4.model.Parameters; import org.hl7.fhir.r4.model.StringType; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -44,24 +45,24 @@ import java.util.Date; import java.util.Set; import java.util.concurrent.TimeUnit; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.notNullValue; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.eq; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class BulkDataExportProviderTest { private static final String A_JOB_ID = "0000000-AAAAAA"; private static final Logger ourLog = LoggerFactory.getLogger(BulkDataExportProviderTest.class); private Server myServer; - private FhirContext myCtx = FhirContext.forR4(); + private FhirContext myCtx = FhirContext.forCached(FhirVersionEnum.R4); private int myPort; @Mock private IBulkDataExportSvc myBulkDataExportSvc; @@ -75,13 +76,13 @@ public class BulkDataExportProviderTest { @Captor private ArgumentCaptor> myFiltersCaptor; - @After + @AfterEach public void after() throws Exception { JettyUtil.closeServer(myServer); myClient.close(); } - @Before + @BeforeEach public void start() throws Exception { myServer = new Server(0); @@ -154,7 +155,7 @@ public class BulkDataExportProviderTest { String url = "http://localhost:" + myPort + "/" + JpaConstants.OPERATION_EXPORT + "?" + JpaConstants.PARAM_EXPORT_OUTPUT_FORMAT + "=" + UrlUtil.escapeUrlParam(Constants.CT_FHIR_NDJSON) + "&" + JpaConstants.PARAM_EXPORT_TYPE + "=" + UrlUtil.escapeUrlParam("Patient, Practitioner") - + "&" + JpaConstants.PARAM_EXPORT_SINCE+ "="+ UrlUtil.escapeUrlParam(now.getValueAsString()) + + "&" + JpaConstants.PARAM_EXPORT_SINCE + "=" + UrlUtil.escapeUrlParam(now.getValueAsString()) + "&" + JpaConstants.PARAM_EXPORT_TYPE_FILTER + "=" + UrlUtil.escapeUrlParam("Patient?identifier=foo"); HttpGet get = new HttpGet(url); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/bulk/BulkDataExportSvcImplR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/bulk/BulkDataExportSvcImplR4Test.java index da8686ef5df..8fa8c304e82 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/bulk/BulkDataExportSvcImplR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/bulk/BulkDataExportSvcImplR4Test.java @@ -22,7 +22,7 @@ import org.hl7.fhir.r4.model.Binary; import org.hl7.fhir.r4.model.InstantType; import org.hl7.fhir.r4.model.Observation; import org.hl7.fhir.r4.model.Patient; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.batch.core.BatchStatus; @@ -45,16 +45,16 @@ import java.util.stream.Collectors; import static org.awaitility.Awaitility.await; import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.equalTo; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.fail; public class BulkDataExportSvcImplR4Test extends BaseJpaR4Test { - private static final Logger ourLog = LoggerFactory.getLogger(BulkDataExportSvcImplR4Test.class); public static final String TEST_FILTER = "Patient?gender=female"; + private static final Logger ourLog = LoggerFactory.getLogger(BulkDataExportSvcImplR4Test.class); @Autowired private IBulkExportJobDao myBulkExportJobDao; @Autowired @@ -168,7 +168,7 @@ public class BulkDataExportSvcImplR4Test extends BaseJpaR4Test { // Check the status IBulkDataExportSvc.JobInfo status = myBulkDataExportSvc.getJobInfoOrThrowResourceNotFound(jobDetails.getJobId()); assertEquals(BulkJobStatusEnum.SUBMITTED, status.getStatus()); - assertEquals("/$export?_outputFormat=application%2Ffhir%2Bndjson&_type=Observation,Patient&_typeFilter="+TEST_FILTER, status.getRequest()); + assertEquals("/$export?_outputFormat=application%2Ffhir%2Bndjson&_type=Observation,Patient&_typeFilter=" + TEST_FILTER, status.getRequest()); // Run a scheduled pass to build the export myBulkDataExportSvc.buildExportFiles(); @@ -213,7 +213,7 @@ public class BulkDataExportSvcImplR4Test extends BaseJpaR4Test { JobExecution jobExecution = myBatchJobSubmitter.runJob(myBulkJob, paramBuilder.toJobParameters()); awaitJobCompletion(jobExecution); - String jobUUID = (String)jobExecution.getExecutionContext().get("jobUUID"); + String jobUUID = (String) jobExecution.getExecutionContext().get("jobUUID"); IBulkDataExportSvc.JobInfo jobInfo = myBulkDataExportSvc.getJobInfoOrThrowResourceNotFound(jobUUID); assertThat(jobInfo.getStatus(), equalTo(BulkJobStatusEnum.COMPLETE)); @@ -375,7 +375,7 @@ public class BulkDataExportSvcImplR4Test extends BaseJpaR4Test { // Run a scheduled pass to build the export myBulkDataExportSvc.buildExportFiles(); - + awaitAllBulkJobCompletions(); // Fetch the job again diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/config/HapiFhirHibernateJpaDialectTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/config/HapiFhirHibernateJpaDialectTest.java index deba96e2520..9adf8821b5b 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/config/HapiFhirHibernateJpaDialectTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/config/HapiFhirHibernateJpaDialectTest.java @@ -7,21 +7,22 @@ import org.hibernate.HibernateException; import org.hibernate.PersistentObjectException; import org.hibernate.StaleStateException; import org.hibernate.exception.ConstraintViolationException; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.dao.DataAccessException; import javax.persistence.PersistenceException; import java.sql.SQLException; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; public class HapiFhirHibernateJpaDialectTest { private HapiFhirHibernateJpaDialect mySvc; - @Before + @BeforeEach public void before() { mySvc = new HapiFhirHibernateJpaDialect(new HapiLocalizer()); } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/config/JpaEntityTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/config/JpaEntityTest.java index 00d668dd547..4b101987b53 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/config/JpaEntityTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/config/JpaEntityTest.java @@ -1,7 +1,7 @@ package ca.uhn.fhir.jpa.config; import ca.uhn.fhir.jpa.util.TestUtil; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class JpaEntityTest { diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/config/TestDstu2Config.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/config/TestDstu2Config.java index d73f87ef800..659d68dbb9c 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/config/TestDstu2Config.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/config/TestDstu2Config.java @@ -25,7 +25,7 @@ import java.sql.SQLException; import java.util.Properties; import java.util.concurrent.TimeUnit; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.fail; @Configuration @Import(TestJPAConfig.class) diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/config/TestDstu3Config.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/config/TestDstu3Config.java index c485e79325f..5c46caa0981 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/config/TestDstu3Config.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/config/TestDstu3Config.java @@ -24,7 +24,7 @@ import java.sql.Connection; import java.util.Properties; import java.util.concurrent.TimeUnit; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.fail; @Configuration @Import(TestJPAConfig.class) diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/config/TestR4Config.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/config/TestR4Config.java index 8dbe1d26e62..1dfb5d78f78 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/config/TestR4Config.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/config/TestR4Config.java @@ -27,7 +27,7 @@ import java.sql.Connection; import java.util.Properties; import java.util.concurrent.TimeUnit; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.fail; @Configuration @Import({TestJPAConfig.class, BatchJobsConfig.class}) @@ -162,6 +162,7 @@ public class TestR4Config extends BaseJavaConfigR4 { extraProperties.put("hibernate.search.default.directory_provider", "local-heap"); extraProperties.put("hibernate.search.lucene_version", "LUCENE_CURRENT"); extraProperties.put("hibernate.search.autoregister_listeners", "true"); + extraProperties.put("hibernate.temp.use_jdbc_metadata_defaults","false"); return extraProperties; } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/config/TestR5Config.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/config/TestR5Config.java index 41817800839..eed2b68e933 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/config/TestR5Config.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/config/TestR5Config.java @@ -23,7 +23,7 @@ import javax.sql.DataSource; import java.sql.Connection; import java.util.Properties; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.fail; @Configuration @Import(TestJPAConfig.class) diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirDaoTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirDaoTest.java index 787b3fa2ec8..30a96db0f2d 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirDaoTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirDaoTest.java @@ -1,8 +1,8 @@ package ca.uhn.fhir.jpa.dao; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public class BaseHapiFhirDaoTest { 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 6fb39294484..dae3bdc868c 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 @@ -31,7 +31,7 @@ import ca.uhn.fhir.rest.api.server.IBundleProvider; import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; import ca.uhn.fhir.test.BaseTest; -import ca.uhn.fhir.test.utilities.LoggingRule; +import ca.uhn.fhir.test.utilities.LoggingExtension; import ca.uhn.fhir.test.utilities.ProxyUtil; import ca.uhn.fhir.test.utilities.UnregisterScheduledProcessor; import ca.uhn.fhir.util.BundleUtil; @@ -49,11 +49,11 @@ import org.hl7.fhir.dstu3.model.Resource; import org.hl7.fhir.instance.model.api.IBaseBundle; import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IIdType; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Rule; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.extension.RegisterExtension; import org.mockito.Answers; import org.mockito.Mock; import org.mockito.MockitoAnnotations; @@ -83,8 +83,8 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.stream.Collectors; import static ca.uhn.fhir.util.TestUtil.randomizeLocale; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.when; @@ -110,8 +110,8 @@ public abstract class BaseJpaTest extends BaseTest { TestUtil.setShouldRandomizeTimezones(false); } - @Rule - public LoggingRule myLoggingRule = new LoggingRule(); + @RegisterExtension + public LoggingExtension myLoggingExtension = new LoggingExtension(); @Mock(answer = Answers.RETURNS_DEEP_STUBS) protected ServletRequestDetails mySrd; protected InterceptorService myRequestOperationCallback; @@ -137,7 +137,7 @@ public abstract class BaseJpaTest extends BaseTest { @Autowired private FhirInstanceValidator myFhirInstanceValidator; - @After + @AfterEach public void afterPerformCleanup() { BaseHapiFhirDao.setDisableIncrementOnUpdateForUnitTest(false); if (myCaptureQueriesListener != null) { @@ -158,7 +158,7 @@ public abstract class BaseJpaTest extends BaseTest { } - @After + @AfterEach public void afterValidateNoTransaction() { PlatformTransactionManager txManager = getTxManager(); if (txManager instanceof JpaTransactionManager) { @@ -185,14 +185,14 @@ public abstract class BaseJpaTest extends BaseTest { } } - @Before + @BeforeEach public void beforeInitPartitions() { if (myPartitionConfigSvc != null) { myPartitionConfigSvc.start(); } } - @Before + @BeforeEach public void beforeInitMocks() { myRequestOperationCallback = new InterceptorService(); @@ -419,18 +419,12 @@ public abstract class BaseJpaTest extends BaseTest { return retVal.toArray(new String[0]); } - @BeforeClass + @BeforeAll public static void beforeClassRandomizeLocale() { randomizeLocale(); } - @SuppressWarnings("RedundantThrows") - @AfterClass - public static void afterClassClearContext() throws Exception { - TestUtil.clearAllStaticFieldsForUnitTest(); - } - - @AfterClass + @AfterAll public static void afterClassShutdownDerby() { // DriverManager.getConnection("jdbc:derby:;shutdown=true"); // try { diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/DaoConfigTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/DaoConfigTest.java index e5f3819583b..bd9ea505dd2 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/DaoConfigTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/DaoConfigTest.java @@ -1,13 +1,13 @@ package ca.uhn.fhir.jpa.dao; import ca.uhn.fhir.jpa.api.config.DaoConfig; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.Arrays; import java.util.HashSet; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; public class DaoConfigTest { 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 748eccd11e9..721b08c55eb 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 @@ -4,9 +4,9 @@ import ca.uhn.fhir.jpa.api.config.DaoConfig; import ca.uhn.fhir.rest.api.server.storage.ResourcePersistentId; import ca.uhn.fhir.jpa.model.entity.ResourceTable; import ca.uhn.fhir.jpa.searchparam.SearchParameterMap; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.junit.MockitoJUnitRunner; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; import javax.persistence.EntityManager; import javax.persistence.TypedQuery; @@ -15,12 +15,12 @@ import java.util.HashSet; import java.util.List; import java.util.Set; -import static org.junit.Assert.assertFalse; +import static org.junit.jupiter.api.Assertions.assertFalse; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class SearchBuilderTest { diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/SearchFilterSyntaxTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/SearchFilterSyntaxTest.java index 7f3cbd027a5..2a2fac26443 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/SearchFilterSyntaxTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/SearchFilterSyntaxTest.java @@ -2,9 +2,11 @@ package ca.uhn.fhir.jpa.dao; import ca.uhn.fhir.jpa.dao.predicate.SearchFilterParser; import ca.uhn.fhir.util.TestUtil; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; public class SearchFilterSyntaxTest { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(SearchFilterSyntaxTest.class); @@ -13,13 +15,8 @@ public class SearchFilterSyntaxTest { SearchFilterParser.Filter filter = SearchFilterParser.parse(theExpression); ourLog.info("Source: {}", theExpression); ourLog.info("Parsed: {}", filter.toString()); - Assert.assertNotNull("Parsing failed - returned null", - filter); - Assert.assertEquals(String.format("Expression mismatch: found %s, expecting %s", - filter.toString(), - theExpression), - theExpression, - filter.toString()); + assertNotNull(filter, "Parsing failed - returned null"); + assertEquals(theExpression, filter.toString(), String.format("Expression mismatch: found %s, expecting %s", filter.toString(), theExpression)); } @Test @@ -72,9 +69,4 @@ public class SearchFilterSyntaxTest { testParse("this eq that and this1 eq that1"); } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } - } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/TolerantJsonParserR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/TolerantJsonParserR4Test.java index dea758dc150..2f7a172b55c 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/TolerantJsonParserR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/TolerantJsonParserR4Test.java @@ -1,18 +1,19 @@ package ca.uhn.fhir.jpa.dao; import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.context.FhirVersionEnum; import ca.uhn.fhir.parser.DataFormatException; import ca.uhn.fhir.parser.LenientErrorHandler; import org.hl7.fhir.r4.model.Observation; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.hamcrest.Matchers.containsString; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.hamcrest.MatcherAssert.assertThat; public class TolerantJsonParserR4Test { - private FhirContext myFhirContext = FhirContext.forR4(); + private FhirContext myFhirContext = FhirContext.forCached(FhirVersionEnum.R4); @Test public void testParseInvalidNumeric_LeadingDecimal() { 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 44aa4b904da..0f42439a65a 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 @@ -5,8 +5,8 @@ import ca.uhn.fhir.jpa.rp.dstu2.PatientResourceProvider; import ca.uhn.fhir.rest.server.RestfulServer; import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; import ca.uhn.fhir.util.TestUtil; -import org.junit.AfterClass; -import org.junit.Before; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; import javax.servlet.ServletConfig; import javax.servlet.ServletException; @@ -19,14 +19,8 @@ import static org.mockito.Mockito.when; public abstract class BaseJpaDstu2SystemTest extends BaseJpaDstu2Test { private RestfulServer myServer; - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } - - @SuppressWarnings("unchecked") - @Before + @BeforeEach public void before() throws ServletException { mySrd = mock(ServletRequestDetails.class); when(mySrd.getInterceptorBroadcaster()).thenReturn(mock(IInterceptorBroadcaster.class)); 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 d5912201826..a3804114065 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 @@ -65,15 +65,15 @@ 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.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.context.ApplicationContext; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.TransactionDefinition; import org.springframework.transaction.annotation.Transactional; @@ -83,9 +83,9 @@ import javax.persistence.EntityManager; import java.io.IOException; import java.io.InputStream; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.fail; -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = {TestDstu2Config.class}) public abstract class BaseJpaDstu2Test extends BaseJpaTest { @Autowired @@ -223,7 +223,7 @@ public abstract class BaseJpaDstu2Test extends BaseJpaTest { @Autowired private IBulkDataExportSvc myBulkDataExportSvc; - @Before + @BeforeEach public void beforeFlushFT() { runInTransaction(() -> { FullTextEntityManager ftem = Search.getFullTextEntityManager(myEntityManager); @@ -236,13 +236,13 @@ public abstract class BaseJpaDstu2Test extends BaseJpaTest { myDaoConfig.setIndexMissingFields(DaoConfig.IndexEnabledEnum.ENABLED); } - @Before + @BeforeEach @Transactional() public void beforePurgeDatabase() { purgeDatabase(myDaoConfig, mySystemDao, myResourceReindexingSvc, mySearchCoordinatorSvc, mySearchParamRegistry, myBulkDataExportSvc); } - @Before + @BeforeEach public void beforeResetConfig() { myDaoConfig.setHardSearchLimit(1000); myDaoConfig.setHardTagListLimit(1000); @@ -250,7 +250,7 @@ public abstract class BaseJpaDstu2Test extends BaseJpaTest { myDaoConfig.setAllowExternalReferences(new DaoConfig().isAllowExternalReferences()); } - @After + @AfterEach public void afterResetInterceptors() { myInterceptorRegistry.unregisterAllInterceptors(); } @@ -283,10 +283,5 @@ public abstract class BaseJpaDstu2Test extends BaseJpaTest { return retVal; } - @SuppressWarnings("RedundantThrows") - @AfterClass - public static void afterClassClearContext() throws Exception { - TestUtil.clearAllStaticFieldsForUnitTest(); - } } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoDstu2SearchCustomSearchParamTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoDstu2SearchCustomSearchParamTest.java index 5074dd27b49..bdeb2e803ca 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoDstu2SearchCustomSearchParamTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu2/FhirResourceDaoDstu2SearchCustomSearchParamTest.java @@ -9,34 +9,63 @@ import ca.uhn.fhir.model.api.Include; import ca.uhn.fhir.model.dstu2.composite.CodeableConceptDt; import ca.uhn.fhir.model.dstu2.composite.CodingDt; import ca.uhn.fhir.model.dstu2.composite.ResourceReferenceDt; -import ca.uhn.fhir.model.dstu2.resource.*; -import ca.uhn.fhir.model.dstu2.valueset.*; -import ca.uhn.fhir.model.primitive.*; +import ca.uhn.fhir.model.dstu2.resource.Appointment; +import ca.uhn.fhir.model.dstu2.resource.Communication; +import ca.uhn.fhir.model.dstu2.resource.Group; +import ca.uhn.fhir.model.dstu2.resource.Patient; +import ca.uhn.fhir.model.dstu2.resource.Practitioner; +import ca.uhn.fhir.model.dstu2.resource.SearchParameter; +import ca.uhn.fhir.model.dstu2.valueset.AdministrativeGenderEnum; +import ca.uhn.fhir.model.dstu2.valueset.AppointmentStatusEnum; +import ca.uhn.fhir.model.dstu2.valueset.CommunicationStatusEnum; +import ca.uhn.fhir.model.dstu2.valueset.ConformanceResourceStatusEnum; +import ca.uhn.fhir.model.dstu2.valueset.ResourceTypeEnum; +import ca.uhn.fhir.model.dstu2.valueset.SearchParamTypeEnum; +import ca.uhn.fhir.model.dstu2.valueset.XPathUsageTypeEnum; +import ca.uhn.fhir.model.primitive.CodeDt; +import ca.uhn.fhir.model.primitive.DateDt; +import ca.uhn.fhir.model.primitive.DecimalDt; +import ca.uhn.fhir.model.primitive.IntegerDt; +import ca.uhn.fhir.model.primitive.StringDt; import ca.uhn.fhir.rest.api.server.IBundleProvider; -import ca.uhn.fhir.rest.param.*; +import ca.uhn.fhir.rest.param.DateParam; +import ca.uhn.fhir.rest.param.NumberParam; +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.rest.server.exceptions.InternalErrorException; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; import ca.uhn.fhir.util.TestUtil; import org.hl7.fhir.instance.model.api.IIdType; -import org.junit.*; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; import org.mockito.internal.util.collections.ListUtil; import java.util.List; -import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.containsInAnyOrder; +import static org.hamcrest.Matchers.empty; +import static org.hamcrest.Matchers.not; +import static org.hamcrest.Matchers.startsWith; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; public class FhirResourceDaoDstu2SearchCustomSearchParamTest extends BaseJpaDstu2Test { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirResourceDaoDstu2SearchCustomSearchParamTest.class); - @Before + @BeforeEach public void beforeDisableResultReuse() { myDaoConfig.setReuseCachedSearchResultsForMillis(null); myDaoConfig.setDefaultSearchParamsCanBeOverridden(new ModelConfig().isDefaultSearchParamsCanBeOverridden()); } - @After + @AfterEach public void after() { myDaoConfig.setValidateSearchParameterExpressionsOnSave(new DaoConfig().isValidateSearchParameterExpressionsOnSave()); } @@ -857,7 +886,7 @@ public class FhirResourceDaoDstu2SearchCustomSearchParamTest extends BaseJpaDstu } @Test - @Ignore + @Disabled public void testSearchForStringOnIdentifierWithSpecificSystem() { SearchParameter fooSp = new SearchParameter(); @@ -1007,9 +1036,5 @@ public class FhirResourceDaoDstu2SearchCustomSearchParamTest extends BaseJpaDstu } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } } 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 46c0c28d0bd..5849c50da2c 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 @@ -1,7 +1,8 @@ package ca.uhn.fhir.jpa.dao.dstu2; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.mock; import java.util.List; @@ -10,9 +11,9 @@ import javax.servlet.http.HttpServletRequest; import ca.uhn.fhir.jpa.dao.BaseHapiFhirResourceDao; import org.hl7.fhir.instance.model.api.IIdType; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.transaction.TransactionStatus; import org.springframework.transaction.support.TransactionCallbackWithoutResult; @@ -29,16 +30,11 @@ public class FhirResourceDaoDstu2SearchFtTest extends BaseJpaDstu2Test { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirResourceDaoDstu2SearchFtTest.class); - @Before + @BeforeEach public void beforeDisableResultReuse() { myDaoConfig.setReuseCachedSearchResultsForMillis(null); } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } - @Test public void testSuggestIgnoresBase64Content() { Patient patient = new Patient(); @@ -272,7 +268,7 @@ public class FhirResourceDaoDstu2SearchFtTest extends BaseJpaDstu2Test { obs4.getCode().addCoding().setCode("CODE1"); obs4.setValue(new StringDt("obsvalue1")); IIdType obsId4 = myObservationDao.create(obs4, mySrd).getId().toUnqualifiedVersionless(); - assertNotEquals(obsId1.getIdPart(), obsId4.getIdPart(), devId1); + assertNotEquals(obsId4.getIdPart(), devId1, obsId1.getIdPart()); param = new StringAndListParam(); param.addAnd(new StringOrListParam().addOr(new StringParam("obsvalue1"))); @@ -359,7 +355,7 @@ public class FhirResourceDaoDstu2SearchFtTest extends BaseJpaDstu2Test { obs4.getCode().addCoding().setCode("CODE1"); obs4.setValue(new StringDt("obsvalue1")); IIdType obsId4 = myObservationDao.create(obs4, mySrd).getId().toUnqualifiedVersionless(); - assertNotEquals(obsId1.getIdPart(), obsId4.getIdPart(), devId1); + assertNotEquals(obsId4.getIdPart(), devId1, obsId1.getIdPart()); param = new StringAndListParam(); param.addAnd(new StringOrListParam().addOr(new StringParam("obsvalue1"))); 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 b23035d9650..3cb1c79718c 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 @@ -6,14 +6,28 @@ import ca.uhn.fhir.jpa.searchparam.SearchParameterMap; import ca.uhn.fhir.jpa.dao.data.ISearchParamPresentDao; import ca.uhn.fhir.jpa.model.entity.*; import ca.uhn.fhir.jpa.util.TestUtil; -import ca.uhn.fhir.model.api.*; +import ca.uhn.fhir.model.api.IResource; +import ca.uhn.fhir.model.api.Include; +import ca.uhn.fhir.model.api.ResourceMetadataKeyEnum; +import ca.uhn.fhir.model.api.TagList; +import ca.uhn.fhir.model.api.TemporalPrecisionEnum; import ca.uhn.fhir.model.base.composite.BaseCodingDt; -import ca.uhn.fhir.model.dstu2.composite.*; +import ca.uhn.fhir.model.dstu2.composite.CodeableConceptDt; +import ca.uhn.fhir.model.dstu2.composite.CodingDt; +import ca.uhn.fhir.model.dstu2.composite.IdentifierDt; +import ca.uhn.fhir.model.dstu2.composite.PeriodDt; +import ca.uhn.fhir.model.dstu2.composite.QuantityDt; +import ca.uhn.fhir.model.dstu2.composite.ResourceReferenceDt; import ca.uhn.fhir.model.dstu2.resource.*; import ca.uhn.fhir.model.dstu2.valueset.ContactPointSystemEnum; import ca.uhn.fhir.model.dstu2.valueset.SubscriptionChannelTypeEnum; import ca.uhn.fhir.model.dstu2.valueset.SubscriptionStatusEnum; -import ca.uhn.fhir.model.primitive.*; +import ca.uhn.fhir.model.primitive.CodeDt; +import ca.uhn.fhir.model.primitive.DateDt; +import ca.uhn.fhir.model.primitive.DateTimeDt; +import ca.uhn.fhir.model.primitive.IdDt; +import ca.uhn.fhir.model.primitive.InstantDt; +import ca.uhn.fhir.model.primitive.StringDt; import ca.uhn.fhir.rest.api.Constants; import ca.uhn.fhir.rest.api.SortOrderEnum; import ca.uhn.fhir.rest.api.SortSpec; @@ -23,10 +37,10 @@ import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; 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.Before; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import javax.servlet.http.HttpServletRequest; @@ -36,8 +50,17 @@ import java.util.Date; import java.util.List; import java.util.Set; -import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.containsInAnyOrder; +import static org.hamcrest.Matchers.containsInRelativeOrder; +import static org.hamcrest.Matchers.empty; +import static org.hamcrest.Matchers.endsWith; +import static org.hamcrest.Matchers.hasItems; +import static org.hamcrest.Matchers.not; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.Mockito.mock; @SuppressWarnings("unchecked") @@ -46,7 +69,7 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test { @Autowired private ISearchParamPresentDao mySearchParamPresentDao; - @Before + @BeforeEach public void beforeDisableResultReuse() { myDaoConfig.setReuseCachedSearchResultsForMillis(null); } @@ -1029,7 +1052,7 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test { * See #310 */ @Test - @Ignore + @Disabled public void testSearchMultiMatches() { for (int i = 0; i < 100; i++) { @@ -1647,7 +1670,7 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test { } @Test - @Ignore + @Disabled public void testSearchUnknownContentParam() { SearchParameterMap params = new SearchParameterMap(); params.add(Constants.PARAM_CONTENT, new StringDt("fulltext")); @@ -1660,7 +1683,7 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test { } @Test - @Ignore + @Disabled public void testSearchUnknownTextParam() { SearchParameterMap params = new SearchParameterMap(); params.add(Constants.PARAM_TEXT, new StringDt("fulltext")); @@ -2456,9 +2479,5 @@ public class FhirResourceDaoDstu2SearchNoFtTest extends BaseJpaDstu2Test { return b.toString(); } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } } 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 4daf828056a..a741732d435 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 @@ -76,11 +76,11 @@ 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.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import java.io.IOException; @@ -94,6 +94,7 @@ import java.util.Set; import java.util.stream.Collectors; import static org.apache.commons.lang3.StringUtils.defaultString; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.containsString; @@ -101,21 +102,22 @@ import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.greaterThan; import static org.hamcrest.Matchers.hasItem; import static org.hamcrest.Matchers.not; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; @SuppressWarnings("unchecked") public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirResourceDaoDstu2Test.class); + @Autowired + private IForcedIdDao myForcedIdDao; - @After + @AfterEach public final void after() { myDaoConfig.setAllowExternalReferences(new DaoConfig().isAllowExternalReferences()); myDaoConfig.setTreatReferencesAsLogical(new DaoConfig().getTreatReferencesAsLogical()); @@ -144,7 +146,7 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { } } - @Before + @BeforeEach public void beforeDisableResultReuse() { myDaoConfig.setReuseCachedSearchResultsForMillis(null); } @@ -986,9 +988,6 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { assertGone(org2Id); } - @Autowired - private IForcedIdDao myForcedIdDao; - @Test public void testHistoryByForcedId() { IIdType idv1; @@ -1005,8 +1004,8 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { idv2 = myPatientDao.update(patient, mySrd).getId(); } - runInTransaction(()->{ - ourLog.info("Forced IDs:\n{}", myForcedIdDao.findAll().stream().map(t->t.toString()).collect(Collectors.joining("\n"))); + runInTransaction(() -> { + ourLog.info("Forced IDs:\n{}", myForcedIdDao.findAll().stream().map(t -> t.toString()).collect(Collectors.joining("\n"))); }); List patients = toList(myPatientDao.history(idv1.toVersionless(), null, null, mySrd)); @@ -1053,7 +1052,7 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { for (int i = 0; i < fullSize; i++) { String expected = id.withVersion(Integer.toString(fullSize + 1 - i)).getValue(); String actual = history.getResources(i, i + 1).get(0).getIdElement().getValue(); - assertEquals("Failure at " + i, expected, actual); + assertEquals(expected, actual, "Failure at " + i); } // By type @@ -1121,7 +1120,7 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { String actual = history.getResources(i, i + 1).get(0).getIdElement().getValue(); assertEquals(expected, actual); } - assertEquals(log(history), fullSize + 1, history.size().intValue()); + assertEquals(fullSize + 1, history.size().intValue(), log(history)); // By type history = myPatientDao.history(null, null, mySrd); @@ -1132,7 +1131,7 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { } ourLog.info(log(history)); ourLog.info("Want {} but got {}", fullSize + 1, history.size().intValue()); - assertEquals(log(history), fullSize + 1, history.size().intValue()); // fails? + assertEquals(fullSize + 1, history.size().intValue(), log(history)); // fails? // By server history = mySystemDao.history(null, null, mySrd); @@ -1141,7 +1140,7 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { String actual = history.getResources(i, i + 1).get(0).getIdElement().getValue(); assertEquals(expected, actual); } - assertEquals(log(history), fullSize + 1, history.size().intValue()); + assertEquals(fullSize + 1, history.size().intValue(), log(history)); /* * With since date @@ -2253,7 +2252,7 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { } @Test - @Ignore + @Disabled public void testSortByQuantity() { Observation res; @@ -2518,7 +2517,7 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { } @Test - @Ignore + @Disabled public void testSortByUri() { ConceptMap res = new ConceptMap(); res.addElement().addTarget().addDependsOn().setElement("http://foo2"); @@ -2727,15 +2726,15 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { published = (TagList) retrieved.getResourceMetadata().get(ResourceMetadataKeyEnum.TAG_LIST); sort(published); assertEquals(3, published.size()); - assertEquals(published.toString(), "Dog", published.get(0).getTerm()); - assertEquals(published.toString(), "Puppies", published.get(0).getLabel()); - assertEquals(published.toString(), null, published.get(0).getScheme()); - assertEquals(published.toString(), "Cat", published.get(1).getTerm()); - assertEquals(published.toString(), "Kittens", published.get(1).getLabel()); - assertEquals(published.toString(), "http://foo", published.get(1).getScheme()); - assertEquals(published.toString(), "Cow", published.get(2).getTerm()); - assertEquals(published.toString(), "Calves", published.get(2).getLabel()); - assertEquals(published.toString(), "http://foo", published.get(2).getScheme()); + assertEquals( "Dog", published.get(0).getTerm()); + assertEquals( "Puppies", published.get(0).getLabel()); + assertEquals(null, published.get(0).getScheme()); + assertEquals( "Cat", published.get(1).getTerm()); + assertEquals( "Kittens", published.get(1).getLabel()); + assertEquals( "http://foo", published.get(1).getScheme()); + assertEquals( "Cow", published.get(2).getTerm()); + assertEquals( "Calves", published.get(2).getLabel()); + assertEquals( "http://foo", published.get(2).getScheme()); secLabels = ResourceMetadataKeyEnum.SECURITY_LABELS.get(retrieved); sortCodings(secLabels); @@ -2809,9 +2808,4 @@ public class FhirResourceDaoDstu2Test extends BaseJpaDstu2Test { } } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } - } 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 43d61f97462..2531f34768c 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 @@ -17,8 +17,8 @@ import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; import ca.uhn.fhir.util.TestUtil; import org.hl7.fhir.instance.model.api.IIdType; -import org.junit.AfterClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; import java.io.IOException; import java.util.ArrayList; @@ -26,16 +26,19 @@ import java.util.HashSet; import java.util.List; import java.util.Set; -import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.containsInAnyOrder; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.endsWith; +import static org.hamcrest.Matchers.not; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.fail; 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 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 5e638fa3189..620be635195 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 @@ -21,32 +21,27 @@ import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; import ca.uhn.fhir.util.TestUtil; import org.hl7.fhir.instance.model.api.IBaseOperationOutcome; import org.hl7.fhir.instance.model.api.IIdType; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.io.IOException; import java.util.Collections; import static org.hamcrest.Matchers.containsString; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.fail; 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(); - } - - @Before + @BeforeEach public void before() { myDaoConfig.setAllowExternalReferences(true); } - @After + @AfterEach public void after() { myDaoConfig.setAllowExternalReferences(new DaoConfig().isAllowExternalReferences()); } 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 d9e4878ed14..fd6f6be67e0 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 @@ -10,20 +10,20 @@ import ca.uhn.fhir.model.primitive.StringDt; import ca.uhn.fhir.model.primitive.UriDt; import ca.uhn.fhir.util.TestUtil; import org.hl7.fhir.instance.model.api.IIdType; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.transaction.annotation.Transactional; import java.io.IOException; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.stringContainsInOrder; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; public class FhirResourceDaoValueSetDstu2Test extends BaseJpaDstu2Test { @@ -31,14 +31,7 @@ public class FhirResourceDaoValueSetDstu2Test extends BaseJpaDstu2Test { private IIdType myExtensionalVsId; - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } - - - - @Before + @BeforeEach @Transactional public void before02() throws IOException { ValueSet upload = loadResourceFromClasspath(ValueSet.class, "/extensional-case-2.xml"); @@ -152,20 +145,20 @@ public class FhirResourceDaoValueSetDstu2Test extends BaseJpaDstu2Test { ourLog.info(resp); // @formatter:off assertThat(resp, - stringContainsInOrder("", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "" - )); + stringContainsInOrder("", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "" + )); //@formatter:on /* @@ -177,8 +170,8 @@ public class FhirResourceDaoValueSetDstu2Test extends BaseJpaDstu2Test { ourLog.info(resp); //@formatter:off assertThat(resp, stringContainsInOrder( - "", - "")); + "", + "")); //@formatter:on /* @@ -190,11 +183,11 @@ public class FhirResourceDaoValueSetDstu2Test extends BaseJpaDstu2Test { ourLog.info(resp); //@formatter:off assertThat(resp, stringContainsInOrder( - "", - "")); + "", + "")); //@formatter:on } - + @Test public void testExpandByIdentifier() { ValueSet expanded = myValueSetDao.expandByIdentifier("http://www.healthintersections.com.au/fhir/ValueSet/extensional-case-2", "11378"); @@ -202,8 +195,8 @@ public class FhirResourceDaoValueSetDstu2Test extends BaseJpaDstu2Test { ourLog.info(resp); //@formatter:off assertThat(resp, stringContainsInOrder( - "", - "")); + "", + "")); //@formatter:on assertThat(resp, not(containsString(""))); @@ -217,11 +210,12 @@ public class FhirResourceDaoValueSetDstu2Test extends BaseJpaDstu2Test { ourLog.info(resp); //@formatter:off assertThat(resp, stringContainsInOrder( - "", - "")); + "", + "")); //@formatter:on assertThat(resp, not(containsString(""))); } + } 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 6b183c97738..59052587adf 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 @@ -1,35 +1,30 @@ package ca.uhn.fhir.jpa.dao.dstu2; -import static org.hamcrest.Matchers.containsInAnyOrder; -import static org.hamcrest.Matchers.empty; -import static org.junit.Assert.assertThat; - -import java.util.List; - -import ca.uhn.fhir.rest.api.server.storage.ResourcePersistentId; -import org.junit.AfterClass; -import org.junit.Test; -import org.springframework.beans.factory.annotation.Autowired; - import ca.uhn.fhir.jpa.dao.IFulltextSearchSvc; import ca.uhn.fhir.jpa.searchparam.SearchParameterMap; import ca.uhn.fhir.model.dstu2.resource.Organization; import ca.uhn.fhir.model.dstu2.resource.Patient; import ca.uhn.fhir.rest.api.Constants; -import ca.uhn.fhir.rest.param.*; +import ca.uhn.fhir.rest.api.server.storage.ResourcePersistentId; +import ca.uhn.fhir.rest.param.StringAndListParam; +import ca.uhn.fhir.rest.param.StringOrListParam; +import ca.uhn.fhir.rest.param.StringParam; import ca.uhn.fhir.util.TestUtil; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.List; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsInAnyOrder; +import static org.hamcrest.Matchers.empty; public class FhirSearchDaoDstu2Test extends BaseJpaDstu2Test { - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } - - @Autowired private IFulltextSearchSvc mySearchDao; - + @Test public void testContentSearch() { Long id1; @@ -64,7 +59,7 @@ public class FhirSearchDaoDstu2Test extends BaseJpaDstu2Test { { StringAndListParam content = new StringAndListParam(); content.addAnd(new StringOrListParam().addOr(new StringParam("AAAS"))); - + map.add(Constants.PARAM_CONTENT, content); List found = mySearchDao.search(resourceName, map); assertThat(ResourcePersistentId.toLongList(found), containsInAnyOrder(id1)); @@ -73,17 +68,17 @@ public class FhirSearchDaoDstu2Test extends BaseJpaDstu2Test { { StringAndListParam content = new StringAndListParam(); content.addAnd(new StringOrListParam().addOr(new StringParam("AAAS")).addOr(new StringParam("AAAB"))); - + map.add(Constants.PARAM_CONTENT, content); List found = mySearchDao.search(resourceName, map); assertThat(ResourcePersistentId.toLongList(found), containsInAnyOrder(id1, id2)); - } + } // AND { StringAndListParam content = new StringAndListParam(); content.addAnd(new StringOrListParam().addOr(new StringParam("AAAS"))); content.addAnd(new StringOrListParam().addOr(new StringParam("CCC"))); - + map.add(Constants.PARAM_CONTENT, content); List found = mySearchDao.search(resourceName, map); assertThat(ResourcePersistentId.toLongList(found), containsInAnyOrder(id1)); @@ -93,7 +88,7 @@ public class FhirSearchDaoDstu2Test extends BaseJpaDstu2Test { StringAndListParam content = new StringAndListParam(); content.addAnd(new StringOrListParam().addOr(new StringParam("AAAB")).addOr(new StringParam("AAAS"))); content.addAnd(new StringOrListParam().addOr(new StringParam("CCC"))); - + map.add(Constants.PARAM_CONTENT, content); List found = mySearchDao.search(resourceName, map); assertThat(ResourcePersistentId.toLongList(found), containsInAnyOrder(id1, id2)); @@ -102,14 +97,14 @@ public class FhirSearchDaoDstu2Test extends BaseJpaDstu2Test { { StringAndListParam content = new StringAndListParam(); content.addAnd(new StringOrListParam().addOr(new StringParam("CCC")).addOr(new StringParam("DDD"))); - + map.add(Constants.PARAM_CONTENT, content); List found = mySearchDao.search(null, map); assertThat(ResourcePersistentId.toLongList(found), containsInAnyOrder(id1, id2, id3)); } } - + @Test public void testNarrativeSearch() { Long id1; @@ -132,7 +127,7 @@ public class FhirSearchDaoDstu2Test extends BaseJpaDstu2Test { { StringAndListParam content = new StringAndListParam(); content.addAnd(new StringOrListParam().addOr(new StringParam("AAAS"))); - + map.add(Constants.PARAM_TEXT, content); List found = mySearchDao.search(resourceName, map); assertThat(ResourcePersistentId.toLongList(found), containsInAnyOrder(id1)); @@ -141,17 +136,17 @@ public class FhirSearchDaoDstu2Test extends BaseJpaDstu2Test { { StringAndListParam content = new StringAndListParam(); content.addAnd(new StringOrListParam().addOr(new StringParam("AAAS")).addOr(new StringParam("AAAB"))); - + map.add(Constants.PARAM_TEXT, content); List found = mySearchDao.search(resourceName, map); assertThat(ResourcePersistentId.toLongList(found), containsInAnyOrder(id1, id2)); - } + } // AND { StringAndListParam content = new StringAndListParam(); content.addAnd(new StringOrListParam().addOr(new StringParam("AAAS"))); content.addAnd(new StringOrListParam().addOr(new StringParam("CCC"))); - + map.add(Constants.PARAM_TEXT, content); List found = mySearchDao.search(resourceName, map); assertThat(ResourcePersistentId.toLongList(found), containsInAnyOrder(id1)); @@ -161,7 +156,7 @@ public class FhirSearchDaoDstu2Test extends BaseJpaDstu2Test { StringAndListParam content = new StringAndListParam(); content.addAnd(new StringOrListParam().addOr(new StringParam("AAAB")).addOr(new StringParam("AAAS"))); content.addAnd(new StringOrListParam().addOr(new StringParam("CCC"))); - + map.add(Constants.PARAM_TEXT, content); List found = mySearchDao.search(resourceName, map); assertThat(ResourcePersistentId.toLongList(found), containsInAnyOrder(id1, id2)); @@ -170,7 +165,7 @@ public class FhirSearchDaoDstu2Test extends BaseJpaDstu2Test { { StringAndListParam content = new StringAndListParam(); content.addAnd(new StringOrListParam().addOr(new StringParam("div"))); - + map.add(Constants.PARAM_TEXT, content); List found = mySearchDao.search(resourceName, map); assertThat(ResourcePersistentId.toLongList(found), empty()); 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 68969357d16..1ef3d34a5ca 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,17 +1,12 @@ package ca.uhn.fhir.jpa.dao.dstu2; -import org.junit.AfterClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; import ca.uhn.fhir.util.TestUtil; public class FhirSystemDaoDstu2SearchTest extends BaseJpaDstu2SystemTest { - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } - @Test public void testSearchByParans() { 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 68b33beb560..9b50b569762 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 @@ -1,9 +1,9 @@ package ca.uhn.fhir.jpa.dao.dstu2; import ca.uhn.fhir.jpa.dao.BaseHapiFhirDao; -import ca.uhn.fhir.jpa.searchparam.SearchParameterMap; import ca.uhn.fhir.jpa.model.entity.TagTypeEnum; import ca.uhn.fhir.jpa.provider.SystemProviderDstu2Test; +import ca.uhn.fhir.jpa.searchparam.SearchParameterMap; import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.model.api.ResourceMetadataKeyEnum; import ca.uhn.fhir.model.api.TagList; @@ -12,10 +12,18 @@ import ca.uhn.fhir.model.dstu2.composite.AttachmentDt; import ca.uhn.fhir.model.dstu2.composite.CodingDt; import ca.uhn.fhir.model.dstu2.composite.MetaDt; import ca.uhn.fhir.model.dstu2.composite.ResourceReferenceDt; -import ca.uhn.fhir.model.dstu2.resource.*; +import ca.uhn.fhir.model.dstu2.resource.Appointment; +import ca.uhn.fhir.model.dstu2.resource.Binary; +import ca.uhn.fhir.model.dstu2.resource.Bundle; import ca.uhn.fhir.model.dstu2.resource.Bundle.Entry; import ca.uhn.fhir.model.dstu2.resource.Bundle.EntryRequest; import ca.uhn.fhir.model.dstu2.resource.Bundle.EntryResponse; +import ca.uhn.fhir.model.dstu2.resource.DiagnosticReport; +import ca.uhn.fhir.model.dstu2.resource.Medication; +import ca.uhn.fhir.model.dstu2.resource.MedicationOrder; +import ca.uhn.fhir.model.dstu2.resource.Observation; +import ca.uhn.fhir.model.dstu2.resource.OperationOutcome; +import ca.uhn.fhir.model.dstu2.resource.Patient; import ca.uhn.fhir.model.dstu2.valueset.BundleTypeEnum; import ca.uhn.fhir.model.dstu2.valueset.HTTPVerbEnum; import ca.uhn.fhir.model.dstu2.valueset.IssueSeverityEnum; @@ -23,29 +31,34 @@ import ca.uhn.fhir.model.dstu2.valueset.ObservationStatusEnum; import ca.uhn.fhir.model.primitive.IdDt; import ca.uhn.fhir.model.primitive.UriDt; import ca.uhn.fhir.rest.api.Constants; -import ca.uhn.fhir.rest.api.RestOperationTypeEnum; import ca.uhn.fhir.rest.api.server.IBundleProvider; import ca.uhn.fhir.rest.param.TokenParam; -import ca.uhn.fhir.rest.server.exceptions.*; -import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor.ActionRequestDetails; +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.ResourceNotFoundException; +import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; import ca.uhn.fhir.util.TestUtil; import org.apache.commons.io.IOUtils; import org.hl7.fhir.dstu3.model.IdType; import org.hl7.fhir.instance.model.api.IIdType; -import org.junit.AfterClass; -import org.junit.Test; -import org.mockito.ArgumentCaptor; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; import java.io.InputStream; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; public class FhirSystemDaoDstu2Test extends BaseJpaDstu2SystemTest { @@ -1005,7 +1018,7 @@ public class FhirSystemDaoDstu2Test extends BaseJpaDstu2SystemTest { } - @Test(expected = InvalidRequestException.class) + @Test public void testTransactionFailsWithDuplicateIds() { Bundle request = new Bundle(); @@ -1019,7 +1032,12 @@ public class FhirSystemDaoDstu2Test extends BaseJpaDstu2SystemTest { patient2.addIdentifier().setSystem("urn:system").setValue("testPersistWithSimpleLinkP02"); request.addEntry().setResource(patient2).getRequest().setMethod(HTTPVerbEnum.POST); - mySystemDao.transaction(mySrd, request); + try { + mySystemDao.transaction(mySrd, request); + fail(); + } catch (InvalidRequestException e) { + assertEquals("Transaction bundle contains multiple resources with ID: Patient/testTransactionFailsWithDusplicateIds", e.getMessage()); + } } @Test @@ -1774,9 +1792,9 @@ public class FhirSystemDaoDstu2Test extends BaseJpaDstu2SystemTest { assertEquals(BundleTypeEnum.TRANSACTION_RESPONSE, resp.getTypeElement().getValueAsEnum()); assertEquals(3, resp.getEntry().size()); - assertTrue(resp.getEntry().get(0).getResponse().getLocation(), new IdDt(resp.getEntry().get(0).getResponse().getLocation()).getIdPart().matches("^[0-9]+$")); - assertTrue(resp.getEntry().get(1).getResponse().getLocation(), new IdDt(resp.getEntry().get(1).getResponse().getLocation()).getIdPart().matches("^[0-9]+$")); - assertTrue(resp.getEntry().get(2).getResponse().getLocation(), new IdDt(resp.getEntry().get(2).getResponse().getLocation()).getIdPart().matches("^[0-9]+$")); + assertTrue(new IdDt(resp.getEntry().get(0).getResponse().getLocation()).getIdPart().matches("^[0-9]+$"), resp.getEntry().get(0).getResponse().getLocation()); + assertTrue(new IdDt(resp.getEntry().get(1).getResponse().getLocation()).getIdPart().matches("^[0-9]+$"), resp.getEntry().get(1).getResponse().getLocation()); + assertTrue(new IdDt(resp.getEntry().get(2).getResponse().getLocation()).getIdPart().matches("^[0-9]+$"), resp.getEntry().get(2).getResponse().getLocation()); o1 = myObservationDao.read(new IdDt(resp.getEntry().get(1).getResponse().getLocation()), mySrd); o2 = myObservationDao.read(new IdDt(resp.getEntry().get(2).getResponse().getLocation()), mySrd); @@ -1815,9 +1833,9 @@ public class FhirSystemDaoDstu2Test extends BaseJpaDstu2SystemTest { assertEquals(BundleTypeEnum.TRANSACTION_RESPONSE, resp.getTypeElement().getValueAsEnum()); assertEquals(3, resp.getEntry().size()); - assertTrue(resp.getEntry().get(0).getResponse().getLocation(), new IdDt(resp.getEntry().get(0).getResponse().getLocation()).getIdPart().matches("^[0-9]+$")); - assertTrue(resp.getEntry().get(1).getResponse().getLocation(), new IdDt(resp.getEntry().get(1).getResponse().getLocation()).getIdPart().matches("^[0-9]+$")); - assertTrue(resp.getEntry().get(2).getResponse().getLocation(), new IdDt(resp.getEntry().get(2).getResponse().getLocation()).getIdPart().matches("^[0-9]+$")); + assertTrue(new IdDt(resp.getEntry().get(0).getResponse().getLocation()).getIdPart().matches("^[0-9]+$"), resp.getEntry().get(0).getResponse().getLocation()); + assertTrue(new IdDt(resp.getEntry().get(1).getResponse().getLocation()).getIdPart().matches("^[0-9]+$"), resp.getEntry().get(1).getResponse().getLocation()); + assertTrue(new IdDt(resp.getEntry().get(2).getResponse().getLocation()).getIdPart().matches("^[0-9]+$"), resp.getEntry().get(2).getResponse().getLocation()); o1 = myObservationDao.read(new IdDt(resp.getEntry().get(1).getResponse().getLocation()), mySrd); o2 = myObservationDao.read(new IdDt(resp.getEntry().get(2).getResponse().getLocation()), mySrd); @@ -1976,9 +1994,5 @@ public class FhirSystemDaoDstu2Test extends BaseJpaDstu2SystemTest { assertEquals(attachment2.getUrl(), dr.getPresentedForm().get(1).getUrl()); } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } } 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 259a0e17006..33c3782f7f7 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 @@ -5,8 +5,8 @@ import ca.uhn.fhir.jpa.rp.dstu3.PatientResourceProvider; import ca.uhn.fhir.rest.server.RestfulServer; import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; import ca.uhn.fhir.util.TestUtil; -import org.junit.AfterClass; -import org.junit.Before; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; import javax.servlet.ServletConfig; import javax.servlet.ServletException; @@ -20,14 +20,8 @@ public abstract class BaseJpaDstu3SystemTest extends BaseJpaDstu3Test { protected ServletRequestDetails mySrd; private RestfulServer myServer; - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } - - @SuppressWarnings("unchecked") - @Before + @BeforeEach public void before() throws ServletException { mySrd = mock(ServletRequestDetails.class); when(mySrd.getInterceptorBroadcaster()).thenReturn(mock(IInterceptorBroadcaster.class)); 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 02b8b6b8dce..9a38ac1a693 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 @@ -103,15 +103,15 @@ import org.hl7.fhir.dstu3.model.Task; import org.hl7.fhir.dstu3.model.ValueSet; import org.hl7.fhir.exceptions.FHIRException; import org.hl7.fhir.instance.model.api.IBaseResource; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.context.ApplicationContext; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.util.AopTestUtils; import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.TransactionDefinition; @@ -125,9 +125,9 @@ import java.nio.charset.StandardCharsets; import java.util.Map; import static org.hl7.fhir.convertors.conv30_40.ConceptMap30_40.convertConceptMap; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.fail; -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = {TestDstu3Config.class}) public abstract class BaseJpaDstu3Test extends BaseJpaTest { @@ -335,13 +335,13 @@ public abstract class BaseJpaDstu3Test extends BaseJpaTest { @Autowired protected ITermConceptMapGroupElementTargetDao myTermConceptMapGroupElementTargetDao; @Autowired + protected ITermCodeSystemStorageSvc myTermCodeSystemStorageSvc; + @Autowired private IValidationSupport myJpaValidationSupportChainDstu3; @Autowired private IBulkDataExportSvc myBulkDataExportSvc; - @Autowired - protected ITermCodeSystemStorageSvc myTermCodeSystemStorageSvc; - @After() + @AfterEach() public void afterCleanupDao() { myDaoConfig.setExpireSearchResults(new DaoConfig().isExpireSearchResults()); myDaoConfig.setExpireSearchResultsAfterMillis(new DaoConfig().getExpireSearchResultsAfterMillis()); @@ -349,12 +349,12 @@ public abstract class BaseJpaDstu3Test extends BaseJpaTest { myDaoConfig.setSuppressUpdatesWithNoChange(new DaoConfig().isSuppressUpdatesWithNoChange()); } - @After + @AfterEach public void afterResetInterceptors() { myInterceptorRegistry.unregisterAllInterceptors(); } - @After + @AfterEach public void afterClearTerminologyCaches() { BaseTermReadSvcImpl baseHapiTerminologySvc = AopTestUtils.getTargetObject(myTermSvc); baseHapiTerminologySvc.clearCaches(); @@ -364,13 +364,13 @@ public abstract class BaseJpaDstu3Test extends BaseJpaTest { deferredSvc.clearDeferred(); } - @After() + @AfterEach() public void afterGrabCaches() { ourValueSetDao = myValueSetDao; ourJpaValidationSupportChainDstu3 = myJpaValidationSupportChainDstu3; } - @Before + @BeforeEach public void beforeFlushFT() { runInTransaction(() -> { FullTextEntityManager ftem = Search.getFullTextEntityManager(myEntityManager); @@ -383,13 +383,13 @@ public abstract class BaseJpaDstu3Test extends BaseJpaTest { myDaoConfig.setIndexMissingFields(DaoConfig.IndexEnabledEnum.ENABLED); } - @Before + @BeforeEach @Transactional() public void beforePurgeDatabase() { purgeDatabase(myDaoConfig, mySystemDao, myResourceReindexingSvc, mySearchCoordinatorSvc, mySearchParamRegistry, myBulkDataExportSvc); } - @Before + @BeforeEach public void beforeResetConfig() { myDaoConfig.setHardSearchLimit(1000); myDaoConfig.setHardTagListLimit(1000); @@ -425,7 +425,7 @@ public abstract class BaseJpaDstu3Test extends BaseJpaTest { return retVal; } - @AfterClass + @AfterAll public static void afterClassClearContextBaseJpaDstu3Test() { if (ourValueSetDao != null) { ourValueSetDao.purgeCaches(); @@ -433,7 +433,6 @@ public abstract class BaseJpaDstu3Test extends BaseJpaTest { if (ourJpaValidationSupportChainDstu3 != null) { ourJpaValidationSupportChainDstu3.invalidateCaches(); } - TestUtil.clearAllStaticFieldsForUnitTest(); } /** diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirDaoConcurrencyDstu3Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirDaoConcurrencyDstu3Test.java index 867ef18fa72..abc7e7162e9 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirDaoConcurrencyDstu3Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirDaoConcurrencyDstu3Test.java @@ -12,10 +12,10 @@ import org.hl7.fhir.dstu3.model.IdType; import org.hl7.fhir.dstu3.model.Organization; import org.hl7.fhir.dstu3.model.Patient; import org.hl7.fhir.instance.model.api.IBaseResource; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.util.comparator.ComparableComparator; @@ -29,7 +29,7 @@ import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertEquals; public class FhirDaoConcurrencyDstu3Test extends BaseJpaDstu3SystemTest { @@ -39,12 +39,12 @@ public class FhirDaoConcurrencyDstu3Test extends BaseJpaDstu3SystemTest { public BasicDataSource myBasicDataSource; private int myMaxTotal; - @After + @AfterEach public void afterResetConnectionPool() { myBasicDataSource.setMaxTotal(myMaxTotal); } - @Before + @BeforeEach public void beforeSetUpConnectionPool() { myMaxTotal = myBasicDataSource.getMaxTotal(); myBasicDataSource.setMaxTotal(5); @@ -55,7 +55,7 @@ public class FhirDaoConcurrencyDstu3Test extends BaseJpaDstu3SystemTest { ThreadPoolExecutor exec = new ThreadPoolExecutor(10, 10, 0L, TimeUnit.MILLISECONDS, - new LinkedBlockingQueue()); + new LinkedBlockingQueue<>()); final AtomicInteger errors = new AtomicInteger(); @@ -139,14 +139,10 @@ public class FhirDaoConcurrencyDstu3Test extends BaseJpaDstu3SystemTest { ourLog.info("Last version: {}", lastVersion); //assertEquals(message, currentVersion.intValue(), versions.size()); - assertEquals(message, currentVersion, lastVersion); + assertEquals(currentVersion, lastVersion, message); } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoCustomTypeDstu3Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoCustomTypeDstu3Test.java index 9362d9abdb0..183b4ecd13d 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoCustomTypeDstu3Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoCustomTypeDstu3Test.java @@ -1,20 +1,21 @@ package ca.uhn.fhir.jpa.dao.dstu3; -import static org.junit.Assert.assertEquals; - -import org.hl7.fhir.dstu3.model.StringType; -import org.hl7.fhir.instance.model.api.IIdType; -import org.junit.*; - import ca.uhn.fhir.jpa.searchparam.SearchParameterMap; import ca.uhn.fhir.rest.api.server.IBundleProvider; +import org.hl7.fhir.dstu3.model.StringType; +import org.hl7.fhir.instance.model.api.IIdType; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; + +import static org.junit.jupiter.api.Assertions.assertEquals; @SuppressWarnings({ }) public class FhirResourceDaoCustomTypeDstu3Test extends BaseJpaDstu3Test { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirResourceDaoCustomTypeDstu3Test.class); - @Before + @BeforeEach public void before() { myFhirCtx.setDefaultTypeForProfile(CustomObservationDstu3.PROFILE, CustomObservationDstu3.class); } @@ -36,7 +37,7 @@ public class FhirResourceDaoCustomTypeDstu3Test extends BaseJpaDstu3Test { } - @After + @AfterEach public void after() { myFhirCtx.setDefaultTypeForProfile(CustomObservationDstu3.PROFILE, null); } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDocumentDstu3Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDocumentDstu3Test.java index 8cdb6e995af..2cbb645c7cc 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDocumentDstu3Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDocumentDstu3Test.java @@ -4,8 +4,8 @@ import ca.uhn.fhir.jpa.api.model.DaoMethodOutcome; import ca.uhn.fhir.util.TestUtil; import org.apache.commons.io.IOUtils; import org.hl7.fhir.dstu3.model.Bundle; -import org.junit.AfterClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; import java.nio.charset.StandardCharsets; @@ -13,12 +13,6 @@ public class FhirResourceDaoDocumentDstu3Test extends BaseJpaDstu3Test { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirResourceDaoDocumentDstu3Test.class); - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } - - @Test public void testPostDocument() throws Exception { String input = IOUtils.toString(getClass().getResourceAsStream("/sample-document.xml"), StandardCharsets.UTF_8); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3CodeSystemTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3CodeSystemTest.java index c9784f48643..9be3a98c9cc 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3CodeSystemTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3CodeSystemTest.java @@ -6,18 +6,17 @@ import org.apache.commons.io.IOUtils; import org.hl7.fhir.dstu3.model.CodeSystem; import org.hl7.fhir.dstu3.model.Enumerations; import org.hl7.fhir.instance.model.api.IIdType; -import org.junit.AfterClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; import java.nio.charset.StandardCharsets; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; public class FhirResourceDaoDstu3CodeSystemTest extends BaseJpaDstu3Test { - @AfterClass + @AfterAll public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); TermReindexingSvcImpl.setForceSaveDeferredAlwaysForUnitTest(false); } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3ConceptMapTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3ConceptMapTest.java index 5ff7d8ed05a..4599cfd3c6a 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3ConceptMapTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3ConceptMapTest.java @@ -9,22 +9,22 @@ import org.hl7.fhir.instance.model.api.IIdType; import org.hl7.fhir.r4.model.Coding; import org.hl7.fhir.r4.model.Enumerations; import org.hl7.fhir.r4.model.UriType; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.transaction.TransactionStatus; import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.support.TransactionCallbackWithoutResult; import org.springframework.transaction.support.TransactionTemplate; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; public class FhirResourceDaoDstu3ConceptMapTest extends BaseJpaDstu3Test { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirResourceDaoDstu3ConceptMapTest.class); private IIdType myConceptMapId; - @Before + @BeforeEach @Transactional public void before02() { myConceptMapId = myConceptMapDao.create(createConceptMap(), mySrd).getId().toUnqualifiedVersionless(); @@ -98,8 +98,4 @@ public class FhirResourceDaoDstu3ConceptMapTest extends BaseJpaDstu3Test { }); } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } } 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 c24c0825d8a..c9a20d333fe 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 @@ -8,8 +8,8 @@ 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 org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder; @@ -17,10 +17,6 @@ import static org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInA 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 diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3ExternalReferenceTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3ExternalReferenceTest.java index 68d72f3e0d8..9a86deed1b5 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3ExternalReferenceTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3ExternalReferenceTest.java @@ -4,44 +4,37 @@ import ca.uhn.fhir.jpa.api.config.DaoConfig; import ca.uhn.fhir.jpa.searchparam.SearchParameterMap; import ca.uhn.fhir.rest.param.ReferenceParam; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; -import ca.uhn.fhir.util.TestUtil; import org.hl7.fhir.dstu3.model.Organization; import org.hl7.fhir.dstu3.model.Patient; import org.hl7.fhir.instance.model.api.IIdType; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.util.HashSet; import java.util.Set; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.empty; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; public class FhirResourceDaoDstu3ExternalReferenceTest extends BaseJpaDstu3Test { - @Before + @BeforeEach public void beforeDisableResultReuse() { myDaoConfig.setReuseCachedSearchResultsForMillis(null); } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } - - @Before - @After + @BeforeEach + @AfterEach public void resetDefaultBehaviour() { // Reset to default myDaoConfig.setAllowExternalReferences(new DaoConfig().isAllowExternalReferences()); myDaoConfig.setTreatBaseUrlsAsLocal(null); } - + @Test public void testInternalReferenceBlockedByDefault() { Patient p = new Patient(); @@ -60,7 +53,7 @@ public class FhirResourceDaoDstu3ExternalReferenceTest extends BaseJpaDstu3Test org.setId("FOO"); org.setName("Org Name"); myOrganizationDao.update(org, mySrd); - + Patient p = new Patient(); p.getManagingOrganization().setReference("http://example.com/base/Organization/FOO"); try { @@ -79,11 +72,11 @@ public class FhirResourceDaoDstu3ExternalReferenceTest extends BaseJpaDstu3Test myOrganizationDao.update(org, mySrd); myDaoConfig.setAllowExternalReferences(true); - + Patient p = new Patient(); p.getManagingOrganization().setReference("http://example.com/base/Organization/FOO"); IIdType pid = myPatientDao.create(p, mySrd).getId().toUnqualifiedVersionless(); - + SearchParameterMap map = new SearchParameterMap(); map.add(Patient.SP_ORGANIZATION, new ReferenceParam("http://example.com/base/Organization/FOO")); assertThat(toUnqualifiedVersionlessIdValues(myPatientDao.search(map)), contains(pid.getValue())); @@ -104,16 +97,16 @@ public class FhirResourceDaoDstu3ExternalReferenceTest extends BaseJpaDstu3Test Set urls = new HashSet(); urls.add("http://example.com/base/"); myDaoConfig.setTreatBaseUrlsAsLocal(urls); - + Patient p = new Patient(); p.getManagingOrganization().setReference("http://example.com/base/Organization/FOO"); IIdType pid = myPatientDao.create(p, mySrd).getId().toUnqualifiedVersionless(); - + p = myPatientDao.read(pid, mySrd); assertEquals("Organization/FOO", p.getManagingOrganization().getReference()); - + SearchParameterMap map; - + map = new SearchParameterMap(); map.add(Patient.SP_ORGANIZATION, new ReferenceParam("http://example.com/base/Organization/FOO")); assertThat(toUnqualifiedVersionlessIdValues(myPatientDao.search(map)), contains(pid.getValue())); @@ -122,11 +115,11 @@ public class FhirResourceDaoDstu3ExternalReferenceTest extends BaseJpaDstu3Test @Test public void testSearchForInvalidLocalReference() { SearchParameterMap map; - + map = new SearchParameterMap(); map.add(Patient.SP_ORGANIZATION, new ReferenceParam("Organization/FOO")); assertThat(toUnqualifiedVersionlessIdValues(myPatientDao.search(map)), empty()); - + map = new SearchParameterMap(); map.add(Patient.SP_ORGANIZATION, new ReferenceParam("Organization/9999999999")); assertThat(toUnqualifiedVersionlessIdValues(myPatientDao.search(map)), empty()); @@ -143,14 +136,14 @@ public class FhirResourceDaoDstu3ExternalReferenceTest extends BaseJpaDstu3Test Set urls = new HashSet(); urls.add("http://example.com/base/"); myDaoConfig.setTreatBaseUrlsAsLocal(urls); - + Patient p = new Patient(); p.getManagingOrganization().setReference("http://example.com/base/Organization/FOO"); IIdType pid = myPatientDao.create(p, mySrd).getId().toUnqualifiedVersionless(); - + p = myPatientDao.read(pid, mySrd); assertEquals("Organization/FOO", p.getManagingOrganization().getReference()); - + SearchParameterMap map; // Different base diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3PhoneticSearchNoFtTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3PhoneticSearchNoFtTest.java index 231a8ed3203..d90cdea8ff0 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3PhoneticSearchNoFtTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3PhoneticSearchNoFtTest.java @@ -9,25 +9,26 @@ import ca.uhn.fhir.jpa.searchparam.SearchParameterMap; import ca.uhn.fhir.jpa.searchparam.registry.ISearchParamRegistry; import ca.uhn.fhir.rest.param.StringParam; import org.apache.commons.codec.language.Soundex; +import org.aspectj.lang.annotation.Before; import org.hl7.fhir.dstu3.model.Enumerations; import org.hl7.fhir.dstu3.model.Patient; import org.hl7.fhir.dstu3.model.SearchParameter; import org.hl7.fhir.dstu3.model.StringType; import org.hl7.fhir.instance.model.api.IIdType; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import java.util.List; import java.util.stream.Collectors; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.hasSize; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; public class FhirResourceDaoDstu3PhoneticSearchNoFtTest extends BaseJpaDstu3Test { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirResourceDaoDstu3PhoneticSearchNoFtTest.class); @@ -43,7 +44,7 @@ public class FhirResourceDaoDstu3PhoneticSearchNoFtTest extends BaseJpaDstu3Test @Autowired ISearchParamRegistry mySearchParamRegistry; - @Before + @BeforeEach public void beforeDisableResultReuse() { myDaoConfig.setIndexMissingFields(DaoConfig.IndexEnabledEnum.DISABLED); myDaoConfig.setReuseCachedSearchResultsForMillis(null); @@ -55,7 +56,7 @@ public class FhirResourceDaoDstu3PhoneticSearchNoFtTest extends BaseJpaDstu3Test mySearchParamRegistry.setPhoneticEncoder(new ApacheEncoder(PhoneticEncoderEnum.SOUNDEX.name(), new Soundex())); } - @After + @AfterEach public void resetStringEncoder() { mySearchParamRegistry.setPhoneticEncoder(null); } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3ReferentialIntegrityTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3ReferentialIntegrityTest.java index 9fd50667c61..ee52083b94f 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3ReferentialIntegrityTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3ReferentialIntegrityTest.java @@ -8,16 +8,16 @@ import org.hl7.fhir.dstu3.model.Organization; 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.After; -import org.junit.AfterClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; public class FhirResourceDaoDstu3ReferentialIntegrityTest extends BaseJpaDstu3Test { - @After + @AfterEach public void afterResetConfig() { myDaoConfig.setEnforceReferentialIntegrityOnWrite(new DaoConfig().isEnforceReferentialIntegrityOnWrite()); myDaoConfig.setEnforceReferentialIntegrityOnDelete(new DaoConfig().isEnforceReferentialIntegrityOnDelete()); @@ -89,10 +89,5 @@ public class FhirResourceDaoDstu3ReferentialIntegrityTest extends BaseJpaDstu3Te } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } - } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3SearchCustomSearchParamTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3SearchCustomSearchParamTest.java index 6d2fdc8388a..8ea405c252e 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3SearchCustomSearchParamTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3SearchCustomSearchParamTest.java @@ -4,9 +4,12 @@ import ca.uhn.fhir.jpa.api.config.DaoConfig; import ca.uhn.fhir.jpa.model.entity.ResourceIndexedSearchParamToken; import ca.uhn.fhir.jpa.searchparam.SearchParameterMap; import ca.uhn.fhir.model.api.Include; -import ca.uhn.fhir.parser.IParser; import ca.uhn.fhir.rest.api.server.IBundleProvider; -import ca.uhn.fhir.rest.param.*; +import ca.uhn.fhir.rest.param.DateParam; +import ca.uhn.fhir.rest.param.NumberParam; +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.rest.server.exceptions.InternalErrorException; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; @@ -16,26 +19,31 @@ import org.hl7.fhir.dstu3.model.Appointment.AppointmentStatus; import org.hl7.fhir.dstu3.model.Enumerations.AdministrativeGender; import org.hl7.fhir.exceptions.FHIRException; import org.hl7.fhir.instance.model.api.IIdType; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.util.List; import java.util.stream.Collectors; -import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.containsInAnyOrder; +import static org.hamcrest.Matchers.empty; +import static org.hamcrest.Matchers.startsWith; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; public class FhirResourceDaoDstu3SearchCustomSearchParamTest extends BaseJpaDstu3Test { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirResourceDaoDstu3SearchCustomSearchParamTest.class); - @Before + @BeforeEach public void beforeDisableResultReuse() { myDaoConfig.setReuseCachedSearchResultsForMillis(null); } - @After + @AfterEach public void after() { myDaoConfig.setValidateSearchParameterExpressionsOnSave(new DaoConfig().isValidateSearchParameterExpressionsOnSave()); } @@ -1088,7 +1096,7 @@ public class FhirResourceDaoDstu3SearchCustomSearchParamTest extends BaseJpaDstu .filter(t -> t.getParamName().equals("medicationadministration-ingredient-medication")) .collect(Collectors.toList()); ourLog.info("Tokens: {}", tokens); - assertEquals(tokens.toString(), 1, tokens.size()); + assertEquals(1, tokens.size(), tokens.toString()); }); @@ -1099,9 +1107,5 @@ public class FhirResourceDaoDstu3SearchCustomSearchParamTest extends BaseJpaDstu } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3SearchDistanceTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3SearchDistanceTest.java index 5867db54e93..70a2f2df523 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3SearchDistanceTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3SearchDistanceTest.java @@ -5,22 +5,24 @@ import ca.uhn.fhir.jpa.searchparam.SearchParameterMap; import ca.uhn.fhir.jpa.util.CoordCalculatorTest; import ca.uhn.fhir.rest.param.TokenParam; import org.hl7.fhir.dstu3.model.Location; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.InvalidDataAccessApiUsageException; import java.util.List; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.is; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; public class FhirResourceDaoDstu3SearchDistanceTest extends BaseJpaDstu3Test { @Autowired MatchUrlService myMatchUrlService; - @Before + @BeforeEach public void beforeDisableResultReuse() { myDaoConfig.setReuseCachedSearchResultsForMillis(null); } 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 48a2c578794..36e0c16279f 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 @@ -1,41 +1,51 @@ package ca.uhn.fhir.jpa.dao.dstu3; -import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; -import static org.mockito.Mockito.mock; - -import java.util.List; - -import javax.servlet.http.HttpServletRequest; - import ca.uhn.fhir.jpa.dao.BaseHapiFhirResourceDao; -import org.hl7.fhir.dstu3.model.*; -import org.hl7.fhir.dstu3.model.Observation.ObservationStatus; -import org.hl7.fhir.instance.model.api.IIdType; -import org.junit.*; - import ca.uhn.fhir.jpa.dao.FulltextSearchSvcImpl.Suggestion; import ca.uhn.fhir.jpa.searchparam.SearchParameterMap; import ca.uhn.fhir.rest.api.Constants; -import ca.uhn.fhir.rest.param.*; +import ca.uhn.fhir.rest.param.StringAndListParam; +import ca.uhn.fhir.rest.param.StringOrListParam; +import ca.uhn.fhir.rest.param.StringParam; +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; +import org.hl7.fhir.dstu3.model.Base64BinaryType; +import org.hl7.fhir.dstu3.model.Device; +import org.hl7.fhir.dstu3.model.Media; +import org.hl7.fhir.dstu3.model.Observation; +import org.hl7.fhir.dstu3.model.Observation.ObservationStatus; +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.jupiter.api.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; + +import javax.servlet.http.HttpServletRequest; +import java.util.List; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.containsInAnyOrder; +import static org.hamcrest.Matchers.empty; +import static org.hamcrest.Matchers.not; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.mockito.Mockito.mock; public class FhirResourceDaoDstu3SearchFtTest extends BaseJpaDstu3Test { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirResourceDaoDstu3SearchFtTest.class); - @Before + @BeforeEach public void beforeDisableResultReuse() { myDaoConfig.setReuseCachedSearchResultsForMillis(null); } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } - - @Test public void testCodeTextSearch() { Observation obs1 = new Observation(); @@ -109,7 +119,7 @@ public class FhirResourceDaoDstu3SearchFtTest extends BaseJpaDstu3Test { } @Test - @Ignore + @Disabled public void testStringTextSearch() { Observation obs1 = new Observation(); obs1.getCode().setText("AAAAA"); @@ -355,7 +365,7 @@ public class FhirResourceDaoDstu3SearchFtTest extends BaseJpaDstu3Test { obs4.getCode().addCoding().setCode("CODE1"); obs4.setValue(new StringType("obsvalue1")); IIdType obsId4 = myObservationDao.create(obs4, mockSrd()).getId().toUnqualifiedVersionless(); - assertNotEquals(obsId1.getIdPart(), obsId4.getIdPart(), devId1); + assertNotEquals(obsId4.getIdPart(), devId1, obsId1.getIdPart()); param = new StringAndListParam(); param.addAnd(new StringOrListParam().addOr(new StringParam("obsvalue1"))); @@ -442,7 +452,7 @@ public class FhirResourceDaoDstu3SearchFtTest extends BaseJpaDstu3Test { obs4.getCode().addCoding().setCode("CODE1"); obs4.setValue(new StringType("obsvalue1")); IIdType obsId4 = myObservationDao.create(obs4, mockSrd()).getId().toUnqualifiedVersionless(); - assertNotEquals(obsId1.getIdPart(), obsId4.getIdPart(), devId1); + assertNotEquals(obsId4.getIdPart(), devId1, obsId1.getIdPart()); param = new StringAndListParam(); param.addAnd(new StringOrListParam().addOr(new StringParam("obsvalue1"))); 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 dcb2521d6e6..bf87c278902 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 @@ -1,7 +1,13 @@ package ca.uhn.fhir.jpa.dao.dstu3; import ca.uhn.fhir.jpa.api.config.DaoConfig; -import ca.uhn.fhir.jpa.model.entity.*; +import ca.uhn.fhir.jpa.model.entity.ResourceIndexedSearchParamDate; +import ca.uhn.fhir.jpa.model.entity.ResourceIndexedSearchParamNumber; +import ca.uhn.fhir.jpa.model.entity.ResourceIndexedSearchParamQuantity; +import ca.uhn.fhir.jpa.model.entity.ResourceIndexedSearchParamString; +import ca.uhn.fhir.jpa.model.entity.ResourceIndexedSearchParamToken; +import ca.uhn.fhir.jpa.model.entity.ResourceIndexedSearchParamUri; +import ca.uhn.fhir.jpa.model.entity.ResourceLink; import ca.uhn.fhir.jpa.searchparam.SearchParamConstants; import ca.uhn.fhir.jpa.searchparam.SearchParameterMap; import ca.uhn.fhir.jpa.searchparam.SearchParameterMap.EverythingModeEnum; @@ -30,10 +36,10 @@ 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.hl7.fhir.instance.model.api.IPrimitiveType; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.springframework.transaction.TransactionDefinition; import org.springframework.transaction.TransactionStatus; import org.springframework.transaction.support.TransactionCallback; @@ -48,15 +54,25 @@ import java.util.List; import java.util.Set; import java.util.TreeSet; -import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.containsInAnyOrder; +import static org.hamcrest.Matchers.containsInRelativeOrder; +import static org.hamcrest.Matchers.empty; +import static org.hamcrest.Matchers.endsWith; +import static org.hamcrest.Matchers.hasItem; +import static org.hamcrest.Matchers.hasItems; +import static org.hamcrest.Matchers.not; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.Mockito.mock; @SuppressWarnings("unchecked") public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirResourceDaoDstu3SearchNoFtTest.class); - @Before + @BeforeEach public void beforeDisableResultReuse() { myDaoConfig.setReuseCachedSearchResultsForMillis(null); myDaoConfig.setFetchSizeDefaultMaximum(new DaoConfig().getFetchSizeDefaultMaximum()); @@ -145,7 +161,7 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { } @Test - public void testEverythingTimings() throws Exception { + public void testEverythingTimings() { String methodName = "testEverythingTimings"; Organization org = new Organization(); @@ -803,7 +819,7 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { { TokenParam v0 = new TokenParam("foo", "testSearchCompositeParamN01"); StringParam v1 = new StringParam("testSearchCompositeParamS01"); - CompositeParam val = new CompositeParam(v0, v1); + CompositeParam val = new CompositeParam<>(v0, v1); IBundleProvider result = myObservationDao.search(new SearchParameterMap().setLoadSynchronous(true).add(Observation.SP_CODE_VALUE_STRING, val)); assertEquals(1, result.size().intValue()); assertEquals(id1.toUnqualifiedVersionless(), result.getResources(0, 1).get(0).getIdElement().toUnqualifiedVersionless()); @@ -854,7 +870,7 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { { TokenParam v0 = new TokenParam("foo", "testSearchCompositeParamDateN01"); DateParam v1 = new DateParam("gt2001-01-01T15:12:12Z"); - CompositeParam val = new CompositeParam(v0, v1); + CompositeParam val = new CompositeParam<>(v0, v1); IBundleProvider result = myObservationDao.search(new SearchParameterMap().setLoadSynchronous(true).add(Observation.SP_CODE_VALUE_DATE, val)); assertThat(toUnqualifiedVersionlessIds(result), containsInAnyOrder(id2)); } @@ -888,28 +904,28 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { { TokenParam v0 = new TokenParam("http://foo", "code1"); QuantityParam v1 = new QuantityParam(ParamPrefixEnum.GREATERTHAN_OR_EQUALS, 150, "http://bar", "code1"); - CompositeParam val = new CompositeParam(v0, v1); + CompositeParam val = new CompositeParam<>(v0, v1); IBundleProvider result = myObservationDao.search(new SearchParameterMap().setLoadSynchronous(true).add(param, val)); assertThat(toUnqualifiedVersionlessIdValues(result), containsInAnyOrder(id2.getValue())); } { TokenParam v0 = new TokenParam("http://foo", "code1"); QuantityParam v1 = new QuantityParam(ParamPrefixEnum.GREATERTHAN_OR_EQUALS, 50, "http://bar", "code1"); - CompositeParam val = new CompositeParam(v0, v1); + CompositeParam val = new CompositeParam<>(v0, v1); IBundleProvider result = myObservationDao.search(new SearchParameterMap().setLoadSynchronous(true).add(param, val)); assertThat(toUnqualifiedVersionlessIdValues(result), containsInAnyOrder(id1.getValue(), id2.getValue())); } { TokenParam v0 = new TokenParam("http://foo", "code4"); QuantityParam v1 = new QuantityParam(ParamPrefixEnum.GREATERTHAN_OR_EQUALS, 50, "http://bar", "code1"); - CompositeParam val = new CompositeParam(v0, v1); + CompositeParam val = new CompositeParam<>(v0, v1); IBundleProvider result = myObservationDao.search(new SearchParameterMap().setLoadSynchronous(true).add(param, val)); assertThat(toUnqualifiedVersionlessIdValues(result), empty()); } { TokenParam v0 = new TokenParam("http://foo", "code1"); QuantityParam v1 = new QuantityParam(ParamPrefixEnum.GREATERTHAN_OR_EQUALS, 50, "http://bar", "code4"); - CompositeParam val = new CompositeParam(v0, v1); + CompositeParam val = new CompositeParam<>(v0, v1); IBundleProvider result = myObservationDao.search(new SearchParameterMap().setLoadSynchronous(true).add(param, val)); assertThat(toUnqualifiedVersionlessIdValues(result), empty()); } @@ -1306,7 +1322,7 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { } @Test - public void testSearchLastUpdatedParam() throws InterruptedException { + public void testSearchLastUpdatedParam() { String methodName = "testSearchLastUpdatedParam"; DateTimeType beforeAny = new DateTimeType(new Date(), TemporalPrecisionEnum.MILLI); @@ -1676,7 +1692,7 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { } @Test - public void testSearchQuantityWrongParam() throws Exception { + public void testSearchQuantityWrongParam() { Condition c1 = new Condition(); c1.setAbatement(new Range().setLow((SimpleQuantity) new SimpleQuantity().setValue(1L)).setHigh((SimpleQuantity) new SimpleQuantity().setValue(1L))); String id1 = myConditionDao.create(c1).getId().toUnqualifiedVersionless().getValue(); @@ -2306,7 +2322,7 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { } @Test - @Ignore + @Disabled public void testSearchUnknownContentParam() { SearchParameterMap params = new SearchParameterMap(); params.add(Constants.PARAM_CONTENT, new StringParam("fulltext")); @@ -2319,7 +2335,7 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { } @Test - @Ignore + @Disabled public void testSearchUnknownTextParam() { SearchParameterMap params = new SearchParameterMap(); params.add(Constants.PARAM_TEXT, new StringParam("fulltext")); @@ -3615,9 +3631,4 @@ public class FhirResourceDaoDstu3SearchNoFtTest extends BaseJpaDstu3Test { return b.toString(); } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } - } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3SourceTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3SourceTest.java index 7971519bfa4..e706b810013 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3SourceTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3SourceTest.java @@ -15,27 +15,27 @@ import org.apache.commons.text.RandomStringGenerator; import org.hl7.fhir.dstu3.model.Patient; import org.hl7.fhir.dstu3.model.StringType; import org.hl7.fhir.instance.model.api.IIdType; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.matchesPattern; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Mockito.when; @SuppressWarnings({"Duplicates"}) public class FhirResourceDaoDstu3SourceTest extends BaseJpaDstu3Test { - @After + @AfterEach public final void after() { when(mySrd.getRequestId()).thenReturn(null); myDaoConfig.setStoreMetaSourceInformation(new DaoConfig().getStoreMetaSourceInformation()); } - @Before + @BeforeEach public void before() { myDaoConfig.setStoreMetaSourceInformation(DaoConfig.StoreMetaSourceInformationEnum.SOURCE_URI_AND_REQUEST_ID); } @@ -220,11 +220,6 @@ public class FhirResourceDaoDstu3SourceTest extends BaseJpaDstu3Test { } } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } - public static void assertConflictException(String theResourceType, ResourceVersionConflictException e) { assertThat(e.getMessage(), matchesPattern( "Unable to delete [a-zA-Z]+/[0-9]+ because at least one resource has a reference to this resource. First reference found was resource " + theResourceType + "/[0-9]+ in path [a-zA-Z]+.[a-zA-Z]+")); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3StructureDefinitionTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3StructureDefinitionTest.java index 49ca8f0f8c6..d852ff06d21 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3StructureDefinitionTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3StructureDefinitionTest.java @@ -2,20 +2,19 @@ package ca.uhn.fhir.jpa.dao.dstu3; import ca.uhn.fhir.util.TestUtil; import org.hl7.fhir.dstu3.model.StructureDefinition; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; import java.io.IOException; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -@SuppressWarnings({"unchecked", "deprecation"}) public class FhirResourceDaoDstu3StructureDefinitionTest extends BaseJpaDstu3Test { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirResourceDaoDstu3StructureDefinitionTest.class); - @After + @AfterEach public final void after() { } @@ -31,9 +30,4 @@ public class FhirResourceDaoDstu3StructureDefinitionTest extends BaseJpaDstu3Tes } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } - } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3TerminologyTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3TerminologyTest.java index 8544a07bc7f..f8e15870a2f 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3TerminologyTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3TerminologyTest.java @@ -37,11 +37,11 @@ import org.hl7.fhir.dstu3.model.ValueSet.ConceptSetComponent; import org.hl7.fhir.dstu3.model.ValueSet.FilterOperator; import org.hl7.fhir.dstu3.model.ValueSet.ValueSetExpansionContainsComponent; import org.hl7.fhir.instance.model.api.IIdType; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import java.util.ArrayList; @@ -51,9 +51,9 @@ import java.util.Set; import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.containsStringIgnoringCase; import static org.hamcrest.Matchers.empty; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.fail; public class FhirResourceDaoDstu3TerminologyTest extends BaseJpaDstu3Test { @@ -64,14 +64,14 @@ public class FhirResourceDaoDstu3TerminologyTest extends BaseJpaDstu3Test { @Autowired private CachingValidationSupport myCachingValidationSupport; - @After + @AfterEach public void after() { myDaoConfig.setDeferIndexingForCodesystemsOfSize(new DaoConfig().getDeferIndexingForCodesystemsOfSize()); TermReindexingSvcImpl.setForceSaveDeferredAlwaysForUnitTest(false); } - @Before + @BeforeEach public void before() { myDaoConfig.setMaximumExpansionSize(5000); myCachingValidationSupport.invalidateCaches(); @@ -326,7 +326,7 @@ public class FhirResourceDaoDstu3TerminologyTest extends BaseJpaDstu3Test { } // TODO: get this working - @Ignore + @Disabled @Test public void testExpandWithOpEquals() { @@ -719,7 +719,7 @@ public class FhirResourceDaoDstu3TerminologyTest extends BaseJpaDstu3Test { * Can't currently abort costly */ @Test - @Ignore + @Disabled public void testRefuseCostlyExpansionFhirCodesystem() { createLocalCsAndVs(); myDaoConfig.setMaximumExpansionSize(1); @@ -1152,7 +1152,7 @@ public class FhirResourceDaoDstu3TerminologyTest extends BaseJpaDstu3Test { * Todo: not yet implemented */ @Test - @Ignore + @Disabled public void testSearchCodeNotInBuiltInValueSet() { AllergyIntolerance ai1 = new AllergyIntolerance(); ai1.setClinicalStatus(AllergyIntoleranceClinicalStatus.ACTIVE); @@ -1195,9 +1195,5 @@ public class FhirResourceDaoDstu3TerminologyTest extends BaseJpaDstu3Test { return retVal; } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } } 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 af4fbc697c6..1898863dc37 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 @@ -80,11 +80,11 @@ 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.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.springframework.transaction.TransactionStatus; import org.springframework.transaction.support.TransactionCallbackWithoutResult; import org.springframework.transaction.support.TransactionTemplate; @@ -107,21 +107,21 @@ import static org.hamcrest.Matchers.hasItem; import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.matchesPattern; import static org.hamcrest.Matchers.not; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; @SuppressWarnings({"unchecked", "deprecation"}) public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirResourceDaoDstu3Test.class); - @After + @AfterEach public final void after() { myDaoConfig.setAllowExternalReferences(new DaoConfig().isAllowExternalReferences()); myDaoConfig.setTreatReferencesAsLogical(new DaoConfig().getTreatReferencesAsLogical()); @@ -153,7 +153,7 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { } - @Before + @BeforeEach public void beforeDisableResultReuse() { myDaoConfig.setReuseCachedSearchResultsForMillis(null); } @@ -483,7 +483,7 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { } @Test - @Ignore + @Disabled public void testCreateBuiltInProfiles() throws Exception { org.hl7.fhir.dstu3.model.Bundle bundle; String name = "profiles-resources"; @@ -2758,7 +2758,7 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { } @Test - @Ignore + @Disabled public void testSortByQuantity() { Observation res; @@ -3024,7 +3024,7 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { } @Test - @Ignore + @Disabled public void testSortByUri() { ConceptMap res = new ConceptMap(); res.addGroup().setSource("http://foo2"); @@ -3233,15 +3233,15 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { published = (ArrayList) retrieved.getMeta().getTag(); sort(published); assertEquals(3, published.size()); - assertEquals(published.toString(), "Dog", published.get(0).getCode()); - assertEquals(published.toString(), "Puppies", published.get(0).getDisplay()); - assertEquals(published.toString(), null, published.get(0).getSystem()); - assertEquals(published.toString(), "Cat", published.get(1).getCode()); - assertEquals(published.toString(), "Kittens", published.get(1).getDisplay()); - assertEquals(published.toString(), "http://foo", published.get(1).getSystem()); - assertEquals(published.toString(), "Cow", published.get(2).getCode()); - assertEquals(published.toString(), "Calves", published.get(2).getDisplay()); - assertEquals(published.toString(), "http://foo", published.get(2).getSystem()); + assertEquals("Dog", published.get(0).getCode()); + assertEquals("Puppies", published.get(0).getDisplay()); + assertEquals(null, published.get(0).getSystem()); + assertEquals("Cat", published.get(1).getCode()); + assertEquals("Kittens", published.get(1).getDisplay()); + assertEquals("http://foo", published.get(1).getSystem()); + assertEquals("Cow", published.get(2).getCode()); + assertEquals("Calves", published.get(2).getDisplay()); + assertEquals("http://foo", published.get(2).getSystem()); secLabels = retrieved.getMeta().getSecurity(); sortCodings(secLabels); @@ -3369,10 +3369,6 @@ public class FhirResourceDaoDstu3Test extends BaseJpaDstu3Test { myConsentDao.create(consent); } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } public static void assertConflictException(ResourceVersionConflictException e) { assertThat(e.getMessage(), matchesPattern( 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 659347babf5..7ba8b20822d 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 @@ -11,17 +11,34 @@ import ca.uhn.fhir.rest.server.exceptions.ResourceGoneException; import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException; import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; import ca.uhn.fhir.util.TestUtil; -import org.hl7.fhir.dstu3.model.*; +import org.hl7.fhir.dstu3.model.CodeSystem; +import org.hl7.fhir.dstu3.model.Coding; +import org.hl7.fhir.dstu3.model.IdType; +import org.hl7.fhir.dstu3.model.Meta; +import org.hl7.fhir.dstu3.model.Organization; +import org.hl7.fhir.dstu3.model.Patient; +import org.hl7.fhir.dstu3.model.UriType; 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.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; -import java.util.*; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.TimeZone; -import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.containsInAnyOrder; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.endsWith; +import static org.hamcrest.Matchers.not; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.fail; public class FhirResourceDaoDstu3UpdateTest extends BaseJpaDstu3Test { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirResourceDaoDstu3UpdateTest.class); @@ -110,7 +127,7 @@ public class FhirResourceDaoDstu3UpdateTest extends BaseJpaDstu3Test { } - @After + @AfterEach public void afterResetDao() { myDaoConfig.setResourceMetaCountHardLimit(new DaoConfig().getResourceMetaCountHardLimit()); } @@ -418,7 +435,7 @@ public class FhirResourceDaoDstu3UpdateTest extends BaseJpaDstu3Test { } @Test - @Ignore + @Disabled public void testUpdateIgnoresIdenticalVersions() { String methodName = "testUpdateIgnoresIdenticalVersions"; @@ -808,9 +825,4 @@ public class FhirResourceDaoDstu3UpdateTest extends BaseJpaDstu3Test { } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } - } 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 f94807291b3..3745e2f2b53 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 @@ -22,10 +22,10 @@ import org.hl7.fhir.dstu3.model.Observation.ObservationStatus; import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IIdType; import org.hl7.fhir.r5.utils.IResourceValidator; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.test.util.AopTestUtils; @@ -34,8 +34,8 @@ import java.io.IOException; import java.nio.charset.StandardCharsets; import static org.hamcrest.Matchers.containsString; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.fail; public class FhirResourceDaoDstu3ValidateTest extends BaseJpaDstu3Test { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirResourceDaoDstu3ValidateTest.class); @@ -125,7 +125,7 @@ public class FhirResourceDaoDstu3ValidateTest extends BaseJpaDstu3Test { } - @After + @AfterEach public void after() { FhirInstanceValidator val = AopTestUtils.getTargetObject(myValidatorModule); val.setBestPracticeWarningLevel(org.hl7.fhir.r5.utils.IResourceValidator.BestPracticeWarningLevel.Warning); @@ -239,7 +239,7 @@ public class FhirResourceDaoDstu3ValidateTest extends BaseJpaDstu3Test { } @Test - @Ignore + @Disabled public void testValidateResourceContainingProfileDeclarationJson() throws Exception { String methodName = "testValidateResourceContainingProfileDeclarationJson"; OperationOutcome outcome = doTestValidateResourceContainingProfileDeclaration(methodName, EncodingEnum.JSON); @@ -252,7 +252,7 @@ public class FhirResourceDaoDstu3ValidateTest extends BaseJpaDstu3Test { } @Test - @Ignore + @Disabled public void testValidateResourceContainingProfileDeclarationXml() throws Exception { String methodName = "testValidateResourceContainingProfileDeclarationXml"; OperationOutcome outcome = doTestValidateResourceContainingProfileDeclaration(methodName, EncodingEnum.XML); @@ -461,7 +461,7 @@ public class FhirResourceDaoDstu3ValidateTest extends BaseJpaDstu3Test { * Format has changed, this is out of date */ @Test - @Ignore + @Disabled public void testValidateNewQuestionnaireFormat() throws Exception { String input = IOUtils.toString(FhirResourceDaoDstu3ValidateTest.class.getResourceAsStream("/questionnaire_dstu3.xml")); try { @@ -498,9 +498,5 @@ public class FhirResourceDaoDstu3ValidateTest extends BaseJpaDstu3Test { } } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3ValueSetTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3ValueSetTest.java index 265e08e74d9..cf667709acb 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3ValueSetTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/dstu3/FhirResourceDaoDstu3ValueSetTest.java @@ -14,24 +14,24 @@ import org.hl7.fhir.dstu3.model.UriType; import org.hl7.fhir.dstu3.model.ValueSet; import org.hl7.fhir.instance.model.api.IIdType; import org.hl7.fhir.instance.model.api.IPrimitiveType; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.transaction.annotation.Transactional; import java.io.IOException; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.stringContainsInOrder; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; public class FhirResourceDaoDstu3ValueSetTest extends BaseJpaDstu3Test { @@ -41,7 +41,7 @@ public class FhirResourceDaoDstu3ValueSetTest extends BaseJpaDstu3Test { @Autowired private IValidationSupport myValidationSupport; - @Before + @BeforeEach @Transactional public void before02() throws IOException { ValueSet upload = loadResourceFromClasspath(ValueSet.class, "/extensional-case-3-vs.xml"); @@ -53,7 +53,7 @@ public class FhirResourceDaoDstu3ValueSetTest extends BaseJpaDstu3Test { } @Test - @Ignore + @Disabled public void testBuiltInValueSetFetchAndExpand() { try { @@ -111,7 +111,7 @@ public class FhirResourceDaoDstu3ValueSetTest extends BaseJpaDstu3Test { } @Test - @Ignore + @Disabled public void testExpandByIdentifier() { ValueSet expanded = myValueSetDao.expandByIdentifier("http://www.healthintersections.com.au/fhir/ValueSet/extensional-case-2", "11378"); String resp = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(expanded); @@ -129,7 +129,7 @@ public class FhirResourceDaoDstu3ValueSetTest extends BaseJpaDstu3Test { * This type of expansion doesn't really make sense.. */ @Test - @Ignore + @Disabled public void testExpandByValueSet() throws IOException { ValueSet toExpand = loadResourceFromClasspath(ValueSet.class, "/extensional-case-3-vs.xml"); ValueSet expanded = myValueSetDao.expand(toExpand, "11378"); @@ -253,13 +253,9 @@ public class FhirResourceDaoDstu3ValueSetTest extends BaseJpaDstu3Test { IFhirResourceDaoValueSet.ValidateCodeResult result = myValueSetDao.validateCode(vsIdentifier, null, code, system, display, coding, codeableConcept, mySrd); ourLog.info(result.getMessage()); - assertTrue(result.getMessage(), result.isResult()); + assertTrue(result.isResult(), result.getMessage()); } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } } 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 a0b301884cb..916d2841305 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 @@ -2,15 +2,15 @@ package ca.uhn.fhir.jpa.dao.dstu3; import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.empty; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import java.util.List; import ca.uhn.fhir.rest.api.server.storage.ResourcePersistentId; import org.hl7.fhir.dstu3.model.Organization; import org.hl7.fhir.dstu3.model.Patient; -import org.junit.AfterClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import ca.uhn.fhir.jpa.dao.IFulltextSearchSvc; @@ -21,12 +21,6 @@ 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 db08ee1499e..fd47d44bd85 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,18 +1,12 @@ package ca.uhn.fhir.jpa.dao.dstu3; -import org.junit.AfterClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.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 3116eb331d2..11fac06fce8 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 @@ -1,6 +1,5 @@ package ca.uhn.fhir.jpa.dao.dstu3; -import ca.uhn.fhir.interceptor.api.IInterceptorBroadcaster; import ca.uhn.fhir.interceptor.api.IInterceptorService; import ca.uhn.fhir.jpa.api.config.DaoConfig; import ca.uhn.fhir.jpa.api.dao.DaoRegistry; @@ -26,7 +25,6 @@ import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException; import ca.uhn.fhir.rest.server.exceptions.ResourceVersionConflictException; import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; import ca.uhn.fhir.util.StopWatch; -import ca.uhn.fhir.util.TestUtil; import com.google.common.base.Charsets; import com.google.common.collect.Maps; import org.apache.commons.io.IOUtils; @@ -61,22 +59,21 @@ import org.hl7.fhir.dstu3.model.Resource; import org.hl7.fhir.dstu3.model.UriType; 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.Before; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.mockito.internal.stubbing.answers.CallsRealMethods; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.transaction.TransactionStatus; import org.springframework.transaction.support.TransactionCallbackWithoutResult; import org.springframework.transaction.support.TransactionTemplate; +import javax.annotation.Nonnull; import java.io.IOException; import java.io.InputStream; import java.math.BigDecimal; import java.nio.charset.StandardCharsets; -import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -84,6 +81,7 @@ import java.util.Map; import java.util.Set; import java.util.stream.Collectors; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.empty; @@ -93,14 +91,13 @@ import static org.hamcrest.Matchers.greaterThan; import static org.hamcrest.Matchers.matchesPattern; import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.startsWith; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.when; @@ -113,7 +110,7 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest { @Autowired private IInterceptorService myInterceptorBroadcaster; - @After + @AfterEach public void after() { myDaoConfig.setAllowInlineMatchUrlReferences(false); myDaoConfig.setAllowMultipleDelete(new DaoConfig().isAllowMultipleDelete()); @@ -122,7 +119,7 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest { } - @Before + @BeforeEach public void beforeDisableResultReuse() { myDaoConfig.setReuseCachedSearchResultsForMillis(null); } @@ -408,7 +405,7 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest { @Test - @Ignore + @Disabled public void testProcessCollectionAsBatch() throws IOException { byte[] inputBytes = IOUtils.toByteArray(getClass().getResourceAsStream("/dstu3/Reilly_Libby_73.json.gz")); String input = GZipUtil.decompress(inputBytes); @@ -1131,7 +1128,7 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest { } @Test - public void testTransactionCreateWithLinks() throws IOException { + public void testTransactionCreateWithLinks() { Bundle request = new Bundle(); request.setType(BundleType.TRANSACTION); @@ -1473,7 +1470,7 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest { } @Test - public void testTransactionDoesNotLeavePlaceholderIds() throws Exception { + public void testTransactionDoesNotLeavePlaceholderIds() { String input; try { input = IOUtils.toString(getClass().getResourceAsStream("/cdr-bundle.json"), StandardCharsets.UTF_8); @@ -1765,7 +1762,7 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest { } - @Test(expected = InvalidRequestException.class) + @Test public void testTransactionFailsWithDuplicateIds() { Bundle request = new Bundle(); @@ -1778,8 +1775,12 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest { patient2.setId(new IdType("Patient/testTransactionFailsWithDusplicateIds")); patient2.addIdentifier().setSystem("urn:system").setValue("testPersistWithSimpleLinkP02"); request.addEntry().setResource(patient2).getRequest().setMethod(HTTPVerb.POST); - - mySystemDao.transaction(mySrd, request); + try { + mySystemDao.transaction(mySrd, request); + fail(); + } catch (InvalidRequestException e) { + assertEquals("Transaction bundle contains multiple resources with ID: Patient/testTransactionFailsWithDusplicateIds", e.getMessage()); + } } @Test @@ -1852,7 +1853,7 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest { * by a large cascading delete */ @Test - @Ignore + @Disabled public void testTransactionFromBundle_Slow() throws Exception { myDaoConfig.setIndexMissingFields(DaoConfig.IndexEnabledEnum.DISABLED); myDaoConfig.setMaximumDeleteConflictQueryCount(10000); @@ -1986,7 +1987,6 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest { } - @Test public void testTransactionReadWithIfNoneMatch() { String methodName = "testTransactionReadWithIfNoneMatch"; @@ -2124,7 +2124,7 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest { assertThat(nextEntry.getResponse().getLocation(), not(containsString("test"))); assertEquals(id.toVersionless(), p.getIdElement().toVersionless()); assertNotEquals(id, p.getId()); - assertThat(p.getId().toString(), endsWith("/_history/2")); + assertThat(p.getId(), endsWith("/_history/2")); nextEntry = resp.getEntry().get(0); assertEquals(Constants.STATUS_HTTP_200_OK + " OK", nextEntry.getResponse().getStatus()); @@ -2280,7 +2280,7 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest { } @Test - public void testTransactionWIthInvalidPlaceholder() throws Exception { + public void testTransactionWIthInvalidPlaceholder() { Bundle res = new Bundle(); res.setType(BundleType.TRANSACTION); @@ -2337,7 +2337,7 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest { * Format changed, source isn't valid */ @Test - @Ignore + @Disabled public void testTransactionWithBundledValidationSourceAndTarget() throws Exception { InputStream bundleRes = SystemProviderDstu2Test.class.getResourceAsStream("/questionnaire-sdc-profile-example-ussg-fht.xml"); @@ -2614,8 +2614,8 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest { new TransactionTemplate(myTxManager).execute(new TransactionCallbackWithoutResult() { @Override - protected void doInTransactionWithoutResult(TransactionStatus theStatus) { - Set values = new HashSet(); + protected void doInTransactionWithoutResult(@Nonnull TransactionStatus theStatus) { + Set values = new HashSet<>(); for (ResourceTag next : myResourceTagDao.findAll()) { if (!values.add(next.toString())) { ourLog.info("Found duplicate tag on resource of type {}", next.getResource().getResourceType()); @@ -2991,7 +2991,7 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest { // } @Test - public void testTransactionWithRelativeOidIds() throws Exception { + public void testTransactionWithRelativeOidIds() { Bundle res = new Bundle(); res.setType(BundleType.TRANSACTION); @@ -3017,9 +3017,9 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest { assertEquals(BundleType.TRANSACTIONRESPONSE, resp.getTypeElement().getValue()); assertEquals(3, resp.getEntry().size()); - assertTrue(resp.getEntry().get(0).getResponse().getLocation(), new IdType(resp.getEntry().get(0).getResponse().getLocation()).getIdPart().matches("^[0-9]+$")); - assertTrue(resp.getEntry().get(1).getResponse().getLocation(), new IdType(resp.getEntry().get(1).getResponse().getLocation()).getIdPart().matches("^[0-9]+$")); - assertTrue(resp.getEntry().get(2).getResponse().getLocation(), new IdType(resp.getEntry().get(2).getResponse().getLocation()).getIdPart().matches("^[0-9]+$")); + assertTrue(new IdType(resp.getEntry().get(0).getResponse().getLocation()).getIdPart().matches("^[0-9]+$"), resp.getEntry().get(0).getResponse().getLocation()); + assertTrue(new IdType(resp.getEntry().get(1).getResponse().getLocation()).getIdPart().matches("^[0-9]+$"), resp.getEntry().get(1).getResponse().getLocation()); + assertTrue(new IdType(resp.getEntry().get(2).getResponse().getLocation()).getIdPart().matches("^[0-9]+$"), resp.getEntry().get(2).getResponse().getLocation()); o1 = myObservationDao.read(new IdType(resp.getEntry().get(1).getResponse().getLocation()), mySrd); o2 = myObservationDao.read(new IdType(resp.getEntry().get(2).getResponse().getLocation()), mySrd); @@ -3032,7 +3032,7 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest { * This is not the correct way to do it, but we'll allow it to be lenient */ @Test - public void testTransactionWithRelativeOidIdsQualified() throws Exception { + public void testTransactionWithRelativeOidIdsQualified() { Bundle res = new Bundle(); res.setType(BundleType.TRANSACTION); @@ -3058,9 +3058,9 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest { assertEquals(BundleType.TRANSACTIONRESPONSE, resp.getTypeElement().getValue()); assertEquals(3, resp.getEntry().size()); - assertTrue(resp.getEntry().get(0).getResponse().getLocation(), new IdType(resp.getEntry().get(0).getResponse().getLocation()).getIdPart().matches("^[0-9]+$")); - assertTrue(resp.getEntry().get(1).getResponse().getLocation(), new IdType(resp.getEntry().get(1).getResponse().getLocation()).getIdPart().matches("^[0-9]+$")); - assertTrue(resp.getEntry().get(2).getResponse().getLocation(), new IdType(resp.getEntry().get(2).getResponse().getLocation()).getIdPart().matches("^[0-9]+$")); + assertTrue(new IdType(resp.getEntry().get(0).getResponse().getLocation()).getIdPart().matches("^[0-9]+$"), resp.getEntry().get(0).getResponse().getLocation()); + assertTrue(new IdType(resp.getEntry().get(1).getResponse().getLocation()).getIdPart().matches("^[0-9]+$"), resp.getEntry().get(1).getResponse().getLocation()); + assertTrue(new IdType(resp.getEntry().get(2).getResponse().getLocation()).getIdPart().matches("^[0-9]+$"), resp.getEntry().get(2).getResponse().getLocation()); o1 = myObservationDao.read(new IdType(resp.getEntry().get(1).getResponse().getLocation()), mySrd); o2 = myObservationDao.read(new IdType(resp.getEntry().get(2).getResponse().getLocation()), mySrd); @@ -3201,9 +3201,4 @@ public class FhirSystemDaoDstu3Test extends BaseJpaDstu3SystemTest { } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } - } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/expunge/ExpungeHookTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/expunge/ExpungeHookTest.java index cbfc1973245..a13947beb62 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/expunge/ExpungeHookTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/expunge/ExpungeHookTest.java @@ -11,17 +11,18 @@ import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException; import ca.uhn.test.concurrency.PointcutLatch; import org.hl7.fhir.dstu3.model.Patient; import org.hl7.fhir.instance.model.api.IIdType; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import static org.hamcrest.Matchers.containsString; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; public class ExpungeHookTest extends BaseJpaDstu3Test { @Autowired @@ -36,14 +37,14 @@ public class ExpungeHookTest extends BaseJpaDstu3Test { PointcutLatch myEverythingLatch = new PointcutLatch(Pointcut.STORAGE_PRESTORAGE_EXPUNGE_EVERYTHING); PointcutLatch myExpungeResourceLatch = new PointcutLatch(Pointcut.STORAGE_PRESTORAGE_EXPUNGE_RESOURCE); - @Before + @BeforeEach public void before() { myDaoConfig.setExpungeEnabled(true); myInterceptorService.registerAnonymousInterceptor(Pointcut.STORAGE_PRESTORAGE_EXPUNGE_EVERYTHING, myEverythingLatch); myInterceptorService.registerAnonymousInterceptor(Pointcut.STORAGE_PRESTORAGE_EXPUNGE_RESOURCE, myExpungeResourceLatch); } - @After + @AfterEach public void after() { assertTrue(myInterceptorService.unregisterInterceptor(myEverythingLatch)); assertTrue(myInterceptorService.unregisterInterceptor(myExpungeResourceLatch)); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/expunge/PartitionRunnerTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/expunge/PartitionRunnerTest.java index 4535383bd3a..9cd49c8544d 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/expunge/PartitionRunnerTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/expunge/PartitionRunnerTest.java @@ -6,16 +6,16 @@ import ca.uhn.fhir.jpa.config.TestDstu3Config; import ca.uhn.test.concurrency.PointcutLatch; import com.google.common.collect.Sets; import org.apache.commons.lang3.builder.ToStringBuilder; -import org.junit.After; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Slice; import org.springframework.data.domain.SliceImpl; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import java.util.ArrayList; import java.util.List; @@ -24,10 +24,10 @@ import java.util.function.Consumer; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.isOneOf; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; -@RunWith(SpringRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = {TestDstu3Config.class}) public class PartitionRunnerTest { private static final Logger ourLog = LoggerFactory.getLogger(PartitionRunnerTest.class); @@ -41,7 +41,7 @@ public class PartitionRunnerTest { private DaoConfig myDaoConfig; private PointcutLatch myLatch = new PointcutLatch("partition call"); - @After + @AfterEach public void before() { myDaoConfig.setExpungeThreadCount(new DaoConfig().getExpungeThreadCount()); myDaoConfig.setExpungeBatchSize(new DaoConfig().getExpungeBatchSize()); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/predicate/PredicateBuilderCoordsTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/predicate/PredicateBuilderCoordsTest.java index 2da1fb75d06..2567ed2ece3 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/predicate/PredicateBuilderCoordsTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/predicate/PredicateBuilderCoordsTest.java @@ -4,11 +4,11 @@ import ca.uhn.fhir.jpa.dao.SearchBuilder; import ca.uhn.fhir.jpa.util.CoordCalculator; import ca.uhn.fhir.jpa.util.CoordCalculatorTest; import ca.uhn.fhir.jpa.util.SearchBox; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.ArgumentCaptor; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.From; @@ -17,18 +17,21 @@ import javax.persistence.criteria.Predicate; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.greaterThan; import static org.hamcrest.Matchers.lessThan; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.Mockito.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class PredicateBuilderCoordsTest { PredicateBuilderCoords myPredicateBuilderCoords; private SearchBuilder mySearchBuilder; private CriteriaBuilder myBuilder; private From myFrom; - @Before + @BeforeEach public void before() { mySearchBuilder = mock(SearchBuilder.class); myBuilder = mock(CriteriaBuilder.class); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/predicate/SearchFuzzUtilTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/predicate/SearchFuzzUtilTest.java index 0ea02794e22..d864a0ea825 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/predicate/SearchFuzzUtilTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/predicate/SearchFuzzUtilTest.java @@ -2,7 +2,7 @@ package ca.uhn.fhir.jpa.dao.predicate; import ca.uhn.fhir.jpa.dao.SearchBuilderTest; import ca.uhn.fhir.rest.param.ParamPrefixEnum; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -10,8 +10,8 @@ import java.math.BigDecimal; import java.math.MathContext; import static org.hamcrest.Matchers.startsWith; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.hamcrest.MatcherAssert.assertThat; public class SearchFuzzUtilTest { private static final Logger ourLog = LoggerFactory.getLogger(SearchBuilderTest.class); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/BaseJpaR4SystemTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/BaseJpaR4SystemTest.java index a06e93756e7..4bb1c93d12e 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/BaseJpaR4SystemTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/BaseJpaR4SystemTest.java @@ -5,8 +5,8 @@ import ca.uhn.fhir.jpa.rp.r4.PatientResourceProvider; import ca.uhn.fhir.rest.server.RestfulServer; import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; import ca.uhn.fhir.util.TestUtil; -import org.junit.AfterClass; -import org.junit.Before; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; import javax.servlet.ServletConfig; import javax.servlet.ServletException; @@ -20,14 +20,8 @@ public abstract class BaseJpaR4SystemTest extends BaseJpaR4Test { protected ServletRequestDetails mySrd; private RestfulServer myServer; - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } - - @SuppressWarnings("unchecked") - @Before + @BeforeEach public void before() throws ServletException { mySrd = mock(ServletRequestDetails.class); when(mySrd.getInterceptorBroadcaster()).thenReturn(mock(IInterceptorBroadcaster.class)); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/BaseJpaR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/BaseJpaR4Test.java index b55634fc169..0630319a005 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/BaseJpaR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/BaseJpaR4Test.java @@ -150,15 +150,15 @@ import org.hl7.fhir.r4.model.Task; import org.hl7.fhir.r4.model.UriType; import org.hl7.fhir.r4.model.ValueSet; import org.hl7.fhir.r5.utils.IResourceValidator; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.context.ApplicationContext; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.util.AopTestUtils; import org.springframework.transaction.PlatformTransactionManager; @@ -170,15 +170,15 @@ import java.util.List; import java.util.Map; import java.util.stream.Collectors; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.empty; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.Mockito.mock; -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = {TestR4Config.class}) -public abstract class BaseJpaR4Test extends BaseJpaTest implements ITestDataBuilder { +public abstract class BaseJpaR4Test extends BaseJpaTest implements ITestDataBuilder { private static IValidationSupport ourJpaValidationSupportChainR4; private static IFhirResourceDaoValueSet ourValueSetDao; @@ -451,19 +451,19 @@ public abstract class BaseJpaR4Test extends BaseJpaTest implements ITestDataBui protected SubscriptionRegistry mySubscriptionRegistry; protected IServerInterceptor myInterceptor; @Autowired + protected DaoRegistry myDaoRegistry; + @Autowired private IValidationSupport myJpaValidationSupportChainR4; private PerformanceTracingLoggingInterceptor myPerformanceTracingLoggingInterceptor; private List mySystemInterceptors; @Autowired - protected DaoRegistry myDaoRegistry; - @Autowired private IBulkDataExportSvc myBulkDataExportSvc; @Autowired private IdHelperService myIdHelperService; @Autowired protected IBatchJobSubmitter myBatchJobSubmitter; - @After() + @AfterEach() public void afterCleanupDao() { myDaoConfig.setExpireSearchResults(new DaoConfig().isExpireSearchResults()); myDaoConfig.setEnforceReferentialIntegrityOnDelete(new DaoConfig().isEnforceReferentialIntegrityOnDelete()); @@ -476,12 +476,12 @@ public abstract class BaseJpaR4Test extends BaseJpaTest implements ITestDataBui myPagingProvider.setMaximumPageSize(BasePagingProvider.DEFAULT_MAX_PAGE_SIZE); } - @After + @AfterEach public void afterResetInterceptors() { myInterceptorRegistry.unregisterAllInterceptors(); } - @After + @AfterEach public void afterClearTerminologyCaches() { BaseTermReadSvcImpl baseHapiTerminologySvc = AopTestUtils.getTargetObject(myTermSvc); baseHapiTerminologySvc.clearCaches(); @@ -491,13 +491,13 @@ public abstract class BaseJpaR4Test extends BaseJpaTest implements ITestDataBui termDeferredStorageSvc.clearDeferred(); } - @After() + @AfterEach() public void afterGrabCaches() { ourValueSetDao = myValueSetDao; ourJpaValidationSupportChainR4 = myJpaValidationSupportChainR4; } - @Before + @BeforeEach public void beforeCreateInterceptor() { mySystemInterceptors = myInterceptorRegistry.getAllRegisteredInterceptors(); @@ -507,12 +507,12 @@ public abstract class BaseJpaR4Test extends BaseJpaTest implements ITestDataBui myInterceptorRegistry.registerInterceptor(myPerformanceTracingLoggingInterceptor); } - @Before + @BeforeEach public void beforeUnregisterAllSubscriptions() { mySubscriptionRegistry.unregisterAllSubscriptions(); } - @Before + @BeforeEach public void beforeFlushFT() { runInTransaction(() -> { FullTextEntityManager ftem = Search.getFullTextEntityManager(myEntityManager); @@ -525,12 +525,12 @@ public abstract class BaseJpaR4Test extends BaseJpaTest implements ITestDataBui myDaoConfig.setIndexMissingFields(new DaoConfig().getIndexMissingFields()); } - @After + @AfterEach public void afterPurgeDatabase() { purgeDatabase(myDaoConfig, mySystemDao, myResourceReindexingSvc, mySearchCoordinatorSvc, mySearchParamRegistry, myBulkDataExportSvc); } - @Before + @BeforeEach public void beforeResetConfig() { myDaoConfig.setHardSearchLimit(1000); myDaoConfig.setHardTagListLimit(1000); @@ -629,11 +629,10 @@ public abstract class BaseJpaR4Test extends BaseJpaTest implements ITestDataBui } } - @AfterClass + @AfterAll public static void afterClassClearContextBaseJpaR4Test() { ourValueSetDao.purgeCaches(); ourJpaValidationSupportChainR4.invalidateCaches(); - TestUtil.clearAllStaticFieldsForUnitTest(); } /** diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/BaseR4SearchLastN.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/BaseR4SearchLastN.java index 976882aaf06..972c3adc0f9 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/BaseR4SearchLastN.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/BaseR4SearchLastN.java @@ -25,15 +25,15 @@ import org.hl7.fhir.r4.model.DateTimeType; import org.hl7.fhir.r4.model.Observation; import org.hl7.fhir.r4.model.Patient; import org.hl7.fhir.r4.model.StringType; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.transaction.PlatformTransactionManager; import java.io.IOException; @@ -45,33 +45,49 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.when; -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = { TestR4ConfigWithElasticsearchClient.class }) +@ExtendWith(SpringExtension.class) +@ContextConfiguration(classes = {TestR4ConfigWithElasticsearchClient.class}) public class BaseR4SearchLastN extends BaseJpaTest { + private static final Map observationPatientMap = new HashMap<>(); + private static final Map observationCategoryMap = new HashMap<>(); + private static final Map observationCodeMap = new HashMap<>(); + private static final Map observationEffectiveMap = new HashMap<>(); + protected static IIdType patient0Id = null; + protected static IIdType patient1Id = null; + protected static IIdType patient2Id = null; + // Using static variables including the flag below so that we can initalize the database and indexes once + // (all of the tests only read from the DB and indexes and so no need to re-initialze them for each test). + private static boolean dataLoaded = false; + private static Calendar observationDate = new GregorianCalendar(); + protected final String observationCd0 = "code0"; + protected final String observationCd1 = "code1"; + protected final String observationCd2 = "code2"; + protected final String categoryCd0 = "category0"; + protected final String codeSystem = "http://mycode.com"; + private final String observationCd3 = "code3"; + private final String categoryCd1 = "category1"; + private final String categoryCd2 = "category2"; + private final String categoryCd3 = "category3"; + private final String categorySystem = "http://mycategory.com"; @Autowired @Qualifier("myPatientDaoR4") protected IFhirResourceDaoPatient myPatientDao; - @Autowired @Qualifier("myObservationDaoR4") protected IFhirResourceDaoObservation myObservationDao; - @Autowired protected DaoConfig myDaoConfig; - @Autowired protected FhirContext myFhirCtx; - - @Autowired - private ElasticsearchSvcImpl myElasticsearchSvc; - @Autowired protected PlatformTransactionManager myPlatformTransactionManager; + @Autowired + private ElasticsearchSvcImpl myElasticsearchSvc; @Override protected FhirContext getContext() { @@ -83,50 +99,19 @@ public class BaseR4SearchLastN extends BaseJpaTest { return myPlatformTransactionManager; } - @Before - public void beforeEnableLastN() { - myDaoConfig.setLastNEnabled(true); - } - - @After + @AfterEach public void afterDisableLastN() { myDaoConfig.setLastNEnabled(new DaoConfig().isLastNEnabled()); } - protected final String observationCd0 = "code0"; - protected final String observationCd1 = "code1"; - protected final String observationCd2 = "code2"; - private final String observationCd3 = "code3"; - - protected final String categoryCd0 = "category0"; - private final String categoryCd1 = "category1"; - private final String categoryCd2 = "category2"; - private final String categoryCd3 = "category3"; - - protected final String codeSystem = "http://mycode.com"; - private final String categorySystem = "http://mycategory.com"; - - // Using static variables including the flag below so that we can initalize the database and indexes once - // (all of the tests only read from the DB and indexes and so no need to re-initialze them for each test). - private static boolean dataLoaded = false; - - protected static IIdType patient0Id = null; - protected static IIdType patient1Id = null; - protected static IIdType patient2Id = null; - - private static final Map observationPatientMap = new HashMap<>(); - private static final Map observationCategoryMap = new HashMap<>(); - private static final Map observationCodeMap = new HashMap<>(); - private static final Map observationEffectiveMap = new HashMap<>(); - - private static Calendar observationDate = new GregorianCalendar(); - - @Before + @BeforeEach public void beforeCreateTestPatientsAndObservations() throws IOException { + myDaoConfig.setLastNEnabled(true); + // Using a static flag to ensure that test data and elasticsearch index is only created once. // Creating this data and the index is time consuming and as such want to avoid having to repeat for each test. // Normally would use a static @BeforeClass method for this purpose, but Autowired objects cannot be accessed in static methods. - if(!dataLoaded) { + if (!dataLoaded) { Patient pt = new Patient(); pt.addName().setFamily("Lastn").addGiven("Arthur"); patient0Id = myPatientDao.create(pt, mockSrd()).getId().toUnqualifiedVersionless(); @@ -149,19 +134,19 @@ public class BaseR4SearchLastN extends BaseJpaTest { } private void createObservationsForPatient(IIdType thePatientId) { - createFiveObservationsForPatientCodeCategory(thePatientId,observationCd0, categoryCd0, 15); - createFiveObservationsForPatientCodeCategory(thePatientId,observationCd0, categoryCd1, 10); - createFiveObservationsForPatientCodeCategory(thePatientId,observationCd0, categoryCd2, 5); - createFiveObservationsForPatientCodeCategory(thePatientId,observationCd1, categoryCd0, 10); - createFiveObservationsForPatientCodeCategory(thePatientId,observationCd1, categoryCd1, 5); - createFiveObservationsForPatientCodeCategory(thePatientId,observationCd2, categoryCd2, 5); - createFiveObservationsForPatientCodeCategory(thePatientId,observationCd3, categoryCd3, 5); + createFiveObservationsForPatientCodeCategory(thePatientId, observationCd0, categoryCd0, 15); + createFiveObservationsForPatientCodeCategory(thePatientId, observationCd0, categoryCd1, 10); + createFiveObservationsForPatientCodeCategory(thePatientId, observationCd0, categoryCd2, 5); + createFiveObservationsForPatientCodeCategory(thePatientId, observationCd1, categoryCd0, 10); + createFiveObservationsForPatientCodeCategory(thePatientId, observationCd1, categoryCd1, 5); + createFiveObservationsForPatientCodeCategory(thePatientId, observationCd2, categoryCd2, 5); + createFiveObservationsForPatientCodeCategory(thePatientId, observationCd3, categoryCd3, 5); } private void createFiveObservationsForPatientCodeCategory(IIdType thePatientId, String theObservationCode, String theCategoryCode, Integer theTimeOffset) { - for (int idx=0; idx<5; idx++ ) { + for (int idx = 0; idx < 5; idx++) { Observation obs = new Observation(); obs.getSubject().setReferenceElement(thePatientId); obs.getCode().addCoding().setCode(theObservationCode).setSystem(codeSystem); @@ -178,9 +163,9 @@ public class BaseR4SearchLastN extends BaseJpaTest { } private Date calculateObservationDateFromOffset(Integer theTimeOffset, Integer theObservationIndex) { - int milliSecondsPerHour = 3600*1000; + int milliSecondsPerHour = 3600 * 1000; // Generate a Date by subtracting a calculated number of hours from the static observationDate property. - return new Date(observationDate.getTimeInMillis() - (milliSecondsPerHour*(theTimeOffset+theObservationIndex))); + return new Date(observationDate.getTimeInMillis() - (milliSecondsPerHour * (theTimeOffset + theObservationIndex))); } protected ServletRequestDetails mockSrd() { @@ -207,7 +192,7 @@ public class BaseR4SearchLastN extends BaseJpaTest { sortedObservationCodes.add(observationCd2); sortedObservationCodes.add(observationCd3); - executeTestCase(params, sortedPatients, sortedObservationCodes, null,105); + executeTestCase(params, sortedPatients, sortedObservationCodes, null, 105); } @Test @@ -219,7 +204,7 @@ public class BaseR4SearchLastN extends BaseJpaTest { Map requestParameters = new HashMap<>(); when(mySrd.getParameters()).thenReturn(requestParameters); - List actual = toUnqualifiedVersionlessIdValues(myObservationDao.observationsLastN(params, mockSrd(),null)); + List actual = toUnqualifiedVersionlessIdValues(myObservationDao.observationsLastN(params, mockSrd(), null)); assertEquals(4, actual.size()); } @@ -233,7 +218,7 @@ public class BaseR4SearchLastN extends BaseJpaTest { when(mySrd.getParameters()).thenReturn(requestParameters); - actual = toUnqualifiedVersionlessIdValues(myObservationDao.observationsLastN(params, mockSrd(),null)); + actual = toUnqualifiedVersionlessIdValues(myObservationDao.observationsLastN(params, mockSrd(), null)); assertEquals(expectedObservationCount, actual.size()); @@ -245,7 +230,7 @@ public class BaseR4SearchLastN extends BaseJpaTest { // Validate patient grouping for (String patientId : thePatientIds) { assertEquals(patientId, observationPatientMap.get(theObservationIds.get(theNextObservationIdx))); - theNextObservationIdx = validateSortingWithinPatient(theObservationIds,theNextObservationIdx,theCodes, theCategores, patientId); + theNextObservationIdx = validateSortingWithinPatient(theObservationIds, theNextObservationIdx, theCodes, theCategores, patientId); } assertEquals(theObservationIds.size(), theNextObservationIdx); } @@ -256,7 +241,7 @@ public class BaseR4SearchLastN extends BaseJpaTest { for (String codeValue : theCodes) { assertEquals(codeValue, observationCodeMap.get(theObservationIds.get(theNextObservationIdx))); // Validate sorting within code group - theNextObservationIdx = validateSortingWithinCode(theObservationIds,theNextObservationIdx, + theNextObservationIdx = validateSortingWithinCode(theObservationIds, theNextObservationIdx, observationCodeMap.get(theObservationIds.get(theNextObservationIdx)), theCategories, thePatientId); } return theNextObservationIdx; @@ -267,8 +252,8 @@ public class BaseR4SearchLastN extends BaseJpaTest { int theNextObservationIdx = theFirstObservationIdxForPatientAndCode; Date lastEffectiveDt = observationEffectiveMap.get(theObservationIds.get(theNextObservationIdx)); theNextObservationIdx++; - while(theObservationCode.equals(observationCodeMap.get(theObservationIds.get(theNextObservationIdx))) - && thePatientId.equals(observationPatientMap.get(theObservationIds.get(theNextObservationIdx)))) { + while (theObservationCode.equals(observationCodeMap.get(theObservationIds.get(theNextObservationIdx))) + && thePatientId.equals(observationPatientMap.get(theObservationIds.get(theNextObservationIdx)))) { // Check that effective date is before that of the previous observation. assertTrue(lastEffectiveDt.compareTo(observationEffectiveMap.get(theObservationIds.get(theNextObservationIdx))) > 0); lastEffectiveDt = observationEffectiveMap.get(theObservationIds.get(theNextObservationIdx)); @@ -302,7 +287,7 @@ public class BaseR4SearchLastN extends BaseJpaTest { sortedObservationCodes.add(observationCd2); sortedObservationCodes.add(observationCd3); - executeTestCase(params, sortedPatients,sortedObservationCodes, null,35); + executeTestCase(params, sortedPatients, sortedObservationCodes, null, 35); params = new SearchParameterMap(); ReferenceParam patientParam = new ReferenceParam("Patient", "", patient0Id.getValue()); @@ -317,7 +302,7 @@ public class BaseR4SearchLastN extends BaseJpaTest { sortedObservationCodes.add(observationCd2); sortedObservationCodes.add(observationCd3); - executeTestCase(params, sortedPatients,sortedObservationCodes, null,35); + executeTestCase(params, sortedPatients, sortedObservationCodes, null, 35); } protected ReferenceAndListParam buildReferenceAndListParam(ReferenceParam... theReference) { @@ -347,7 +332,7 @@ public class BaseR4SearchLastN extends BaseJpaTest { sortedObservationCodes.add(observationCd2); sortedObservationCodes.add(observationCd3); - executeTestCase(params, sortedPatients, sortedObservationCodes, null,70); + executeTestCase(params, sortedPatients, sortedObservationCodes, null, 70); // Two Patient parameters params = new SearchParameterMap(); @@ -359,7 +344,7 @@ public class BaseR4SearchLastN extends BaseJpaTest { sortedPatients.add(patient0Id.getValue()); sortedPatients.add(patient2Id.getValue()); - executeTestCase(params,sortedPatients, sortedObservationCodes, null,70); + executeTestCase(params, sortedPatients, sortedObservationCodes, null, 70); } @@ -564,7 +549,7 @@ public class BaseR4SearchLastN extends BaseJpaTest { ReferenceParam subjectParam = new ReferenceParam("Patient", "", patient0Id.getValue()); params.add(Observation.SP_SUBJECT, buildReferenceAndListParam(subjectParam)); - DateParam myDateParam = new DateParam(ParamPrefixEnum.LESSTHAN, new Date(observationDate.getTimeInMillis() - (3600*1000*9))); + DateParam myDateParam = new DateParam(ParamPrefixEnum.LESSTHAN, new Date(observationDate.getTimeInMillis() - (3600 * 1000 * 9))); params.add(Observation.SP_DATE, myDateParam); List sortedPatients = new ArrayList<>(); @@ -574,7 +559,7 @@ public class BaseR4SearchLastN extends BaseJpaTest { sortedObservationCodes.add(observationCd0); sortedObservationCodes.add(observationCd1); - executeTestCase(params, sortedPatients,sortedObservationCodes, null,15); + executeTestCase(params, sortedPatients, sortedObservationCodes, null, 15); } @@ -585,8 +570,8 @@ public class BaseR4SearchLastN extends BaseJpaTest { ReferenceParam subjectParam = new ReferenceParam("Patient", "", patient0Id.getValue()); params.add(Observation.SP_SUBJECT, buildReferenceAndListParam(subjectParam)); - DateParam lowDateParam = new DateParam(ParamPrefixEnum.LESSTHAN, new Date(observationDate.getTimeInMillis() - (3600*1000*(9)))); - DateParam highDateParam = new DateParam(ParamPrefixEnum.GREATERTHAN, new Date(observationDate.getTimeInMillis() - (3600*1000*(15)))); + DateParam lowDateParam = new DateParam(ParamPrefixEnum.LESSTHAN, new Date(observationDate.getTimeInMillis() - (3600 * 1000 * (9)))); + DateParam highDateParam = new DateParam(ParamPrefixEnum.GREATERTHAN, new Date(observationDate.getTimeInMillis() - (3600 * 1000 * (15)))); DateAndListParam myDateAndListParam = new DateAndListParam(); myDateAndListParam.addAnd(new DateOrListParam().addOr(lowDateParam)); myDateAndListParam.addAnd(new DateOrListParam().addOr(highDateParam)); @@ -600,11 +585,11 @@ public class BaseR4SearchLastN extends BaseJpaTest { sortedObservationCodes.add(observationCd0); sortedObservationCodes.add(observationCd1); - executeTestCase(params, sortedPatients,sortedObservationCodes, null,10); + executeTestCase(params, sortedPatients, sortedObservationCodes, null, 10); } - @AfterClass + @AfterAll public static void afterClassClearContext() { TestUtil.clearAllStaticFieldsForUnitTest(); } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/ConsentEventsDaoR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/ConsentEventsDaoR4Test.java index d9fc6ddda69..360366ae17a 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/ConsentEventsDaoR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/ConsentEventsDaoR4Test.java @@ -20,14 +20,14 @@ import org.hl7.fhir.instance.model.api.IIdType; import org.hl7.fhir.r4.model.IdType; import org.hl7.fhir.r4.model.Observation; import org.hl7.fhir.r4.model.Patient; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import javax.servlet.ServletException; import java.util.ArrayList; @@ -36,16 +36,16 @@ import java.util.List; import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; -import static junit.framework.TestCase.assertTrue; import static org.apache.commons.lang3.StringUtils.leftPad; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.greaterThan; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.Mockito.when; @SuppressWarnings("unchecked") -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = {TestR4Config.class}) public class ConsentEventsDaoR4Test extends BaseJpaR4SystemTest { @@ -58,14 +58,14 @@ public class ConsentEventsDaoR4Test extends BaseJpaR4SystemTest { private List myObservationIdsWithVersions; private List myPatientIdsEvenOnly; - @After + @AfterEach public void after() { myDaoConfig.setSearchPreFetchThresholds(new DaoConfig().getSearchPreFetchThresholds()); myDaoConfig.setIndexMissingFields(new DaoConfig().getIndexMissingFields()); } @Override - @Before + @BeforeEach public void before() throws ServletException { super.before(); @@ -131,14 +131,14 @@ public class ConsentEventsDaoR4Test extends BaseJpaR4SystemTest { List returnedIdValues = toUnqualifiedVersionlessIdValues(resources); assertEquals(myObservationIdsEvenOnly.subList(0, 10), returnedIdValues); assertEquals(1, hitCount.get()); - assertEquals("Wrong response from " + outcome.getClass(), myObservationIds.subList(0, 20), interceptedResourceIds); + assertEquals(myObservationIds.subList(0, 20), interceptedResourceIds, "Wrong response from " + outcome.getClass()); // Fetch the next 30 (do cross a fetch boundary) String searchId = outcome.getUuid(); outcome = myPagingProvider.retrieveResultList(mySrd, searchId); resources = outcome.getResources(10, 40); returnedIdValues = toUnqualifiedVersionlessIdValues(resources); - if (!myObservationIdsEvenOnly.subList(10,25).equals(returnedIdValues)) { + if (!myObservationIdsEvenOnly.subList(10, 25).equals(returnedIdValues)) { if (resources.size() != 1) { runInTransaction(() -> { Search search = mySearchEntityDao.findByUuidAndFetchIncludes(searchId).get(); @@ -146,7 +146,7 @@ public class ConsentEventsDaoR4Test extends BaseJpaR4SystemTest { }); } } - assertEquals("Wrong response from " + outcome.getClass(), myObservationIdsEvenOnly.subList(10, 25), returnedIdValues); + assertEquals(myObservationIdsEvenOnly.subList(10, 25), returnedIdValues, "Wrong response from " + outcome.getClass()); assertEquals(2, hitCount.get()); } @@ -335,7 +335,7 @@ public class ConsentEventsDaoR4Test extends BaseJpaR4SystemTest { */ assertEquals(1, hitCount.get()); assertEquals(myObservationIdsWithVersions.subList(90, myObservationIdsWithVersions.size()), sort(interceptedResourceIds)); - returnedIdValues.forEach(t-> assertTrue(new IdType(t).getIdPartAsLong() % 2 == 0)); + returnedIdValues.forEach(t -> assertTrue(new IdType(t).getIdPartAsLong() % 2 == 0)); } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoCreatePlaceholdersR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoCreatePlaceholdersR4Test.java index 9eab9c91901..2278a76de7e 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoCreatePlaceholdersR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoCreatePlaceholdersR4Test.java @@ -17,25 +17,25 @@ import org.hl7.fhir.r4.model.Observation.ObservationStatus; import org.hl7.fhir.r4.model.Patient; import org.hl7.fhir.r4.model.Reference; import org.hl7.fhir.r4.model.Task; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; import java.util.List; import static org.hamcrest.CoreMatchers.startsWith; import static org.hamcrest.Matchers.contains; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.fail; @SuppressWarnings({"ConstantConditions"}) public class FhirResourceDaoCreatePlaceholdersR4Test extends BaseJpaR4Test { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirResourceDaoCreatePlaceholdersR4Test.class); - @After + @AfterEach public final void afterResetDao() { myDaoConfig.setAutoCreatePlaceholderReferenceTargets(new DaoConfig().isAutoCreatePlaceholderReferenceTargets()); myDaoConfig.setResourceClientIdStrategy(new DaoConfig().getResourceClientIdStrategy()); @@ -257,10 +257,6 @@ public class FhirResourceDaoCreatePlaceholdersR4Test extends BaseJpaR4Test { } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoCustomTypeR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoCustomTypeR4Test.java index b00b92de015..a25f1d01248 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoCustomTypeR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoCustomTypeR4Test.java @@ -1,20 +1,21 @@ package ca.uhn.fhir.jpa.dao.r4; -import static org.junit.Assert.assertEquals; - -import org.hl7.fhir.r4.model.StringType; -import org.hl7.fhir.instance.model.api.IIdType; -import org.junit.*; - import ca.uhn.fhir.jpa.searchparam.SearchParameterMap; import ca.uhn.fhir.rest.api.server.IBundleProvider; +import org.hl7.fhir.instance.model.api.IIdType; +import org.hl7.fhir.r4.model.StringType; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; + +import static org.junit.jupiter.api.Assertions.assertEquals; @SuppressWarnings({ }) public class FhirResourceDaoCustomTypeR4Test extends BaseJpaR4Test { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirResourceDaoCustomTypeR4Test.class); - @Before + @BeforeEach public void before() { myFhirCtx.setDefaultTypeForProfile(CustomObservationR4.PROFILE, CustomObservationR4.class); } @@ -36,7 +37,7 @@ public class FhirResourceDaoCustomTypeR4Test extends BaseJpaR4Test { } - @After + @AfterEach public void after() { myFhirCtx.setDefaultTypeForProfile(CustomObservationR4.PROFILE, null); } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoDocumentR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoDocumentR4Test.java index 5156e2824d9..f1d181032b9 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoDocumentR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoDocumentR4Test.java @@ -4,8 +4,8 @@ import ca.uhn.fhir.jpa.api.model.DaoMethodOutcome; import ca.uhn.fhir.util.TestUtil; import org.apache.commons.io.IOUtils; import org.hl7.fhir.r4.model.Bundle; -import org.junit.AfterClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; import java.nio.charset.StandardCharsets; @@ -13,12 +13,6 @@ public class FhirResourceDaoDocumentR4Test extends BaseJpaR4Test { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirResourceDaoDocumentR4Test.class); - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } - - @Test public void testPostDocument() throws Exception { String input = IOUtils.toString(getClass().getResourceAsStream("/sample-document.xml"), StandardCharsets.UTF_8); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4CacheWarmingTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4CacheWarmingTest.java index 4bdb76816bd..b24fc335fca 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4CacheWarmingTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4CacheWarmingTest.java @@ -11,22 +11,22 @@ import ca.uhn.fhir.rest.api.server.IBundleProvider; import ca.uhn.fhir.rest.param.StringParam; import ca.uhn.fhir.util.TestUtil; import org.hl7.fhir.r4.model.Patient; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.util.ArrayList; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; public class FhirResourceDaoR4CacheWarmingTest extends BaseJpaR4Test { private static final Logger ourLog = LoggerFactory.getLogger(FhirResourceDaoR4CacheWarmingTest.class); - @After + @AfterEach public void afterResetDao() { myDaoConfig.setResourceServerIdStrategy(new DaoConfig().getResourceServerIdStrategy()); @@ -105,10 +105,4 @@ public class FhirResourceDaoR4CacheWarmingTest extends BaseJpaR4Test { assertTrue(resultCasted.isCacheHit()); } - - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } - } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4CodeSystemTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4CodeSystemTest.java index eb72982441b..df2905456c4 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4CodeSystemTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4CodeSystemTest.java @@ -1,19 +1,18 @@ package ca.uhn.fhir.jpa.dao.r4; import ca.uhn.fhir.jpa.term.TermReindexingSvcImpl; -import ca.uhn.fhir.util.TestUtil; import org.apache.commons.io.IOUtils; import org.hl7.fhir.instance.model.api.IIdType; import org.hl7.fhir.r4.model.CodeSystem; -import org.junit.AfterClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; import java.nio.charset.StandardCharsets; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; public class FhirResourceDaoR4CodeSystemTest extends BaseJpaR4Test { @@ -73,9 +72,8 @@ public class FhirResourceDaoR4CodeSystemTest extends BaseJpaR4Test { } - @AfterClass + @AfterAll public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); TermReindexingSvcImpl.setForceSaveDeferredAlwaysForUnitTest(false); } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4ConceptMapTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4ConceptMapTest.java index 58b58024f42..23a59c9e29b 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4ConceptMapTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4ConceptMapTest.java @@ -10,9 +10,9 @@ import org.hl7.fhir.r4.model.Coding; import org.hl7.fhir.r4.model.ConceptMap; import org.hl7.fhir.r4.model.Enumerations.ConceptMapEquivalence; import org.hl7.fhir.r4.model.UriType; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.transaction.TransactionStatus; @@ -22,16 +22,16 @@ import org.springframework.transaction.support.TransactionTemplate; import java.io.IOException; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; public class FhirResourceDaoR4ConceptMapTest extends BaseJpaR4Test { private static final Logger ourLog = LoggerFactory.getLogger(FhirResourceDaoR4ConceptMapTest.class); private IIdType myConceptMapId; - @Before + @BeforeEach @Transactional public void before02() { myConceptMapId = myConceptMapDao.create(createConceptMap(), mySrd).getId().toUnqualifiedVersionless(); @@ -1060,8 +1060,4 @@ public class FhirResourceDaoR4ConceptMapTest extends BaseJpaR4Test { } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4ContainedTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4ContainedTest.java index 9bc8e9b4783..f425ae6ca7b 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4ContainedTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4ContainedTest.java @@ -4,8 +4,8 @@ import org.hl7.fhir.r4.model.Observation; import org.hl7.fhir.r4.model.Patient; import org.hl7.fhir.r4.model.Reference; import org.hl7.fhir.instance.model.api.IIdType; -import org.junit.AfterClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; import ca.uhn.fhir.jpa.searchparam.SearchParameterMap; import ca.uhn.fhir.util.TestUtil; @@ -13,10 +13,6 @@ import ca.uhn.fhir.util.TestUtil; public class FhirResourceDaoR4ContainedTest extends BaseJpaR4Test { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirResourceDaoR4ContainedTest.class); - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } @Test diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4CreateTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4CreateTest.java index 5403f473173..9860da500f3 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4CreateTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4CreateTest.java @@ -18,9 +18,9 @@ import org.hl7.fhir.r4.model.Organization; import org.hl7.fhir.r4.model.Patient; import org.hl7.fhir.r4.model.SampledData; import org.hl7.fhir.r4.model.SearchParameter; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.data.domain.PageRequest; @@ -28,18 +28,18 @@ import org.springframework.data.domain.PageRequest; import java.io.IOException; import java.util.Date; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.matchesPattern; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; public class FhirResourceDaoR4CreateTest extends BaseJpaR4Test { private static final Logger ourLog = LoggerFactory.getLogger(FhirResourceDaoR4CreateTest.class); - @After + @AfterEach public void afterResetDao() { myDaoConfig.setResourceServerIdStrategy(new DaoConfig().getResourceServerIdStrategy()); myDaoConfig.setResourceClientIdStrategy(new DaoConfig().getResourceClientIdStrategy()); @@ -330,9 +330,5 @@ public class FhirResourceDaoR4CreateTest extends BaseJpaR4Test { } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4DeleteTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4DeleteTest.java index 00c12994e66..97cc8d26b42 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4DeleteTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4DeleteTest.java @@ -12,24 +12,24 @@ import org.hl7.fhir.r4.model.Bundle; import org.hl7.fhir.r4.model.IdType; import org.hl7.fhir.r4.model.Organization; import org.hl7.fhir.r4.model.Patient; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.IOException; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; public class FhirResourceDaoR4DeleteTest extends BaseJpaR4Test { private static final Logger ourLog = LoggerFactory.getLogger(FhirResourceDaoR4DeleteTest.class); - @After + @AfterEach public void after() { myDaoConfig.setDeleteEnabled(new DaoConfig().isDeleteEnabled()); } @@ -220,9 +220,5 @@ public class FhirResourceDaoR4DeleteTest extends BaseJpaR4Test { } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4ExternalReferenceTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4ExternalReferenceTest.java index fa82ef36355..9985e433c4a 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4ExternalReferenceTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4ExternalReferenceTest.java @@ -1,5 +1,14 @@ package ca.uhn.fhir.jpa.dao.r4; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.empty; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.fail; + +import java.util.HashSet; +import java.util.Set; + import ca.uhn.fhir.jpa.api.config.DaoConfig; import ca.uhn.fhir.jpa.searchparam.SearchParameterMap; import ca.uhn.fhir.rest.param.ReferenceParam; @@ -8,34 +17,27 @@ import ca.uhn.fhir.util.TestUtil; import org.hl7.fhir.instance.model.api.IIdType; import org.hl7.fhir.r4.model.Organization; import org.hl7.fhir.r4.model.Patient; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Test; +import org.hl7.fhir.instance.model.api.IIdType; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -import java.util.HashSet; -import java.util.Set; - -import static org.hamcrest.Matchers.contains; -import static org.hamcrest.Matchers.empty; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; +import ca.uhn.fhir.jpa.api.config.DaoConfig; +import ca.uhn.fhir.jpa.searchparam.SearchParameterMap; +import ca.uhn.fhir.rest.param.ReferenceParam; +import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; +import ca.uhn.fhir.util.TestUtil; public class FhirResourceDaoR4ExternalReferenceTest extends BaseJpaR4Test { - @Before + @BeforeEach public void beforeDisableResultReuse() { myDaoConfig.setReuseCachedSearchResultsForMillis(null); } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } - - @Before - @After + @BeforeEach + @AfterEach public void resetDefaultBehaviour() { // Reset to default myDaoConfig.setAllowExternalReferences(new DaoConfig().isAllowExternalReferences()); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4FilterTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4FilterTest.java index ce144c0ab36..f2abd93904e 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4FilterTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4FilterTest.java @@ -15,27 +15,27 @@ import org.hl7.fhir.r4.model.DecimalType; import org.hl7.fhir.r4.model.Patient; import org.hl7.fhir.r4.model.RiskAssessment; import org.hl7.fhir.r4.model.ValueSet; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.util.List; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsInAnyOrder; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; @SuppressWarnings({"Duplicates"}) public class FhirResourceDaoR4FilterTest extends BaseJpaR4Test { - @After + @AfterEach public void after() { myDaoConfig.setFilterParameterEnabled(new DaoConfig().isFilterParameterEnabled()); } - @Before + @BeforeEach public void before() { myDaoConfig.setFilterParameterEnabled(true); } @@ -190,21 +190,22 @@ public class FhirResourceDaoR4FilterTest extends BaseJpaR4Test { map = new SearchParameterMap(); map.setLoadSynchronous(true); - map.add(Constants.PARAM_FILTER, new StringParam(String.format("status eq active or _id eq %s", idVal))); - myCaptureQueriesListener.clear(); - found = toUnqualifiedVersionlessIdValues(myEncounterDao.search(map)); - myCaptureQueriesListener.logSelectQueriesForCurrentThread(0); - assertThat(found, Matchers.empty()); - - map = new SearchParameterMap(); - map.setLoadSynchronous(true); - map.add(Constants.PARAM_FILTER, new StringParam(String.format("_id eq %s", idVal))); + map.add(Constants.PARAM_FILTER, new StringParam(String.format("status eq active or _id eq %s", + idVal))); found = toUnqualifiedVersionlessIdValues(myEncounterDao.search(map)); assertThat(found, Matchers.empty()); map = new SearchParameterMap(); map.setLoadSynchronous(true); - map.add(Constants.PARAM_FILTER, new StringParam(String.format("_id eq %s", idVal))); + map.add(Constants.PARAM_FILTER, new StringParam(String.format("_id eq %s", + idVal))); + found = toUnqualifiedVersionlessIdValues(myEncounterDao.search(map)); + assertThat(found, Matchers.empty()); + + map = new SearchParameterMap(); + map.setLoadSynchronous(true); + map.add(Constants.PARAM_FILTER, new StringParam(String.format("_id eq %s", + idVal))); found = toUnqualifiedVersionlessIdValues(myPatientDao.search(map)); assertThat(found, containsInAnyOrder(id1)); @@ -949,7 +950,7 @@ public class FhirResourceDaoR4FilterTest extends BaseJpaR4Test { } @Test - public void testSearchUriEq() throws Exception { + public void testSearchUriEq() { ValueSet vs1 = new ValueSet(); vs1.setUrl("http://hl7.org/foo/baz"); @@ -975,7 +976,7 @@ public class FhirResourceDaoR4FilterTest extends BaseJpaR4Test { } @Test - public void testSearchUriNe() throws Exception { + public void testSearchUriNe() { ValueSet vs1 = new ValueSet(); vs1.setUrl("http://hl7.org/foo/baz"); @@ -1001,7 +1002,7 @@ public class FhirResourceDaoR4FilterTest extends BaseJpaR4Test { } @Test - public void testSearchUriCo() throws Exception { + public void testSearchUriCo() { ValueSet vs1 = new ValueSet(); vs1.setUrl("http://hl7.org/foo/baz"); @@ -1027,7 +1028,7 @@ public class FhirResourceDaoR4FilterTest extends BaseJpaR4Test { } @Test - public void testSearchUriGt() throws Exception { + public void testSearchUriGt() { ValueSet vs1 = new ValueSet(); vs1.setUrl("http://hl7.org/foo/baz"); @@ -1053,7 +1054,7 @@ public class FhirResourceDaoR4FilterTest extends BaseJpaR4Test { } @Test - public void testSearchUriLt() throws Exception { + public void testSearchUriLt() { ValueSet vs1 = new ValueSet(); vs1.setUrl("http://hl7.org/foo/baz"); @@ -1079,7 +1080,7 @@ public class FhirResourceDaoR4FilterTest extends BaseJpaR4Test { } @Test - public void testSearchUriGe() throws Exception { + public void testSearchUriGe() { ValueSet vs1 = new ValueSet(); vs1.setUrl("http://hl7.org/foo/baz"); @@ -1101,7 +1102,7 @@ public class FhirResourceDaoR4FilterTest extends BaseJpaR4Test { } @Test - public void testSearchUriLe() throws Exception { + public void testSearchUriLe() { ValueSet vs1 = new ValueSet(); vs1.setUrl("http://hl7.org/foo/baz"); @@ -1127,7 +1128,7 @@ public class FhirResourceDaoR4FilterTest extends BaseJpaR4Test { } @Test - public void testSearchUriSw() throws Exception { + public void testSearchUriSw() { ValueSet vs1 = new ValueSet(); vs1.setUrl("http://hl7.org/foo/baz"); @@ -1149,7 +1150,7 @@ public class FhirResourceDaoR4FilterTest extends BaseJpaR4Test { } @Test - public void testSearchUriEw() throws Exception { + public void testSearchUriEw() { ValueSet vs1 = new ValueSet(); vs1.setUrl("http://hl7.org/foo/baz"); @@ -1170,9 +1171,5 @@ public class FhirResourceDaoR4FilterTest extends BaseJpaR4Test { } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4InterceptorTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4InterceptorTest.java index 54f08074aba..31f68443559 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4InterceptorTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4InterceptorTest.java @@ -15,10 +15,10 @@ import org.hl7.fhir.r4.model.Bundle.BundleType; import org.hl7.fhir.r4.model.Bundle.HTTPVerb; import org.hl7.fhir.r4.model.IdType; import org.hl7.fhir.r4.model.Patient; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; import org.mockito.InOrder; import org.mockito.Mockito; @@ -29,10 +29,10 @@ import java.util.ArrayList; import java.util.List; import static org.hamcrest.Matchers.containsString; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Matchers.any; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.inOrder; @@ -46,12 +46,12 @@ public class FhirResourceDaoR4InterceptorTest extends BaseJpaR4Test { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirResourceDaoR4InterceptorTest.class); private List myIds = new ArrayList<>(); - @After + @AfterEach public void after() { myDaoConfig.setAllowMultipleDelete(new DaoConfig().isAllowMultipleDelete()); } - @Before + @BeforeEach public void before() { } @@ -641,8 +641,4 @@ public class FhirResourceDaoR4InterceptorTest extends BaseJpaR4Test { } } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4InvalidSubscriptionTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4InvalidSubscriptionTest.java index 35c203ed6f4..dd8790ead1b 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4InvalidSubscriptionTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4InvalidSubscriptionTest.java @@ -7,32 +7,32 @@ import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; import ca.uhn.fhir.util.TestUtil; import org.hl7.fhir.instance.model.api.IIdType; import org.hl7.fhir.r4.model.Subscription; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; public class FhirResourceDaoR4InvalidSubscriptionTest extends BaseJpaR4Test { @Autowired private SubscriptionTestUtil mySubscriptionTestUtil; - @After + @AfterEach public void afterResetDao() { myDaoConfig.setResourceServerIdStrategy(new DaoConfig().getResourceServerIdStrategy()); BaseHapiFhirDao.setValidationDisabledForUnitTest(false); } - @After + @AfterEach public void afterUnregisterRestHookListener() { mySubscriptionTestUtil.unregisterSubscriptionInterceptor(); } - @Before + @BeforeEach public void beforeRegisterRestHookListener() { mySubscriptionTestUtil.registerRestHookInterceptor(); } @@ -57,9 +57,4 @@ public class FhirResourceDaoR4InvalidSubscriptionTest extends BaseJpaR4Test { } } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } - } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4QueryCountTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4QueryCountTest.java index e17b4d4fed4..b2193ff74da 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4QueryCountTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4QueryCountTest.java @@ -3,7 +3,6 @@ package ca.uhn.fhir.jpa.dao.r4; import ca.uhn.fhir.jpa.api.config.DaoConfig; import ca.uhn.fhir.jpa.searchparam.SearchParameterMap; import ca.uhn.fhir.jpa.util.SqlQuery; -import ca.uhn.fhir.jpa.util.TestUtil; import ca.uhn.fhir.rest.api.SortSpec; import ca.uhn.fhir.rest.api.server.IBundleProvider; import ca.uhn.fhir.rest.param.ReferenceParam; @@ -21,29 +20,28 @@ import org.hl7.fhir.r4.model.Practitioner; import org.hl7.fhir.r4.model.Reference; import org.hl7.fhir.r4.model.ServiceRequest; import org.hl7.fhir.r4.model.StringType; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.util.List; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.empty; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; public class FhirResourceDaoR4QueryCountTest extends BaseJpaR4Test { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirResourceDaoR4QueryCountTest.class); - @After + @AfterEach public void afterResetDao() { myDaoConfig.setResourceMetaCountHardLimit(new DaoConfig().getResourceMetaCountHardLimit()); myDaoConfig.setIndexMissingFields(new DaoConfig().getIndexMissingFields()); myDaoConfig.setDeleteEnabled(new DaoConfig().isDeleteEnabled()); } - @Before + @BeforeEach public void before() { myInterceptorRegistry.registerInterceptor(myInterceptor); } @@ -147,10 +145,10 @@ public class FhirResourceDaoR4QueryCountTest extends BaseJpaR4Test { // Validate once myCaptureQueriesListener.clear(); myObservationDao.validate(obs, null, null, null, null, null, null); - assertEquals(myCaptureQueriesListener.logSelectQueriesForCurrentThread(), 9, myCaptureQueriesListener.getSelectQueriesForCurrentThread().size()); - assertEquals(myCaptureQueriesListener.logUpdateQueriesForCurrentThread(), 0, myCaptureQueriesListener.getUpdateQueriesForCurrentThread().size()); - assertEquals(myCaptureQueriesListener.logInsertQueriesForCurrentThread(), 0, myCaptureQueriesListener.getInsertQueriesForCurrentThread().size()); - assertEquals(myCaptureQueriesListener.logDeleteQueriesForCurrentThread(), 0, myCaptureQueriesListener.getDeleteQueriesForCurrentThread().size()); + assertEquals(9, myCaptureQueriesListener.getSelectQueriesForCurrentThread().size()); + assertEquals(0, myCaptureQueriesListener.getUpdateQueriesForCurrentThread().size()); + assertEquals(0, myCaptureQueriesListener.getInsertQueriesForCurrentThread().size()); + assertEquals(0, myCaptureQueriesListener.getDeleteQueriesForCurrentThread().size()); // Validate again (should rely only on caches) myCaptureQueriesListener.clear(); @@ -576,8 +574,8 @@ public class FhirResourceDaoR4QueryCountTest extends BaseJpaR4Test { myCaptureQueriesListener.clear(); IBundleProvider outcome = myPatientDao.search(map); assertThat(toUnqualifiedVersionlessIdValues(outcome), containsInAnyOrder( - "Patient/P1", "CareTeam/CT1-0", "CareTeam/CT1-1","CareTeam/CT1-2", - "Patient/P2", "CareTeam/CT2-0", "CareTeam/CT2-1","CareTeam/CT2-2" + "Patient/P1", "CareTeam/CT1-0", "CareTeam/CT1-1", "CareTeam/CT1-2", + "Patient/P2", "CareTeam/CT2-0", "CareTeam/CT2-1", "CareTeam/CT2-2" )); myCaptureQueriesListener.logSelectQueriesForCurrentThread(); @@ -1176,8 +1174,8 @@ public class FhirResourceDaoR4QueryCountTest extends BaseJpaR4Test { myCaptureQueriesListener.clear(); mySystemDao.transaction(mySrd, input); myCaptureQueriesListener.logSelectQueriesForCurrentThread(); - assertEquals(myCaptureQueriesListener.logSelectQueriesForCurrentThread(), 3, myCaptureQueriesListener.countSelectQueriesForCurrentThread()); - assertEquals(myCaptureQueriesListener.logInsertQueriesForCurrentThread(), 8, myCaptureQueriesListener.countInsertQueriesForCurrentThread()); + assertEquals(3, myCaptureQueriesListener.countSelectQueriesForCurrentThread()); + assertEquals(8, myCaptureQueriesListener.countInsertQueriesForCurrentThread()); myCaptureQueriesListener.logUpdateQueriesForCurrentThread(); assertEquals(1, myCaptureQueriesListener.countUpdateQueriesForCurrentThread()); assertEquals(0, myCaptureQueriesListener.countDeleteQueriesForCurrentThread()); @@ -1195,9 +1193,4 @@ public class FhirResourceDaoR4QueryCountTest extends BaseJpaR4Test { } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } - } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4ReferentialIntegrityTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4ReferentialIntegrityTest.java index b6caa4e7a9f..3c3de290a30 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4ReferentialIntegrityTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4ReferentialIntegrityTest.java @@ -8,21 +8,16 @@ import org.hl7.fhir.instance.model.api.IIdType; import org.hl7.fhir.r4.model.Organization; import org.hl7.fhir.r4.model.Patient; import org.hl7.fhir.r4.model.Reference; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; public class FhirResourceDaoR4ReferentialIntegrityTest extends BaseJpaR4Test { - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } - - @After + @AfterEach public void afterResetConfig() { myDaoConfig.setEnforceReferentialIntegrityOnWrite(new DaoConfig().isEnforceReferentialIntegrityOnWrite()); myDaoConfig.setEnforceReferentialIntegrityOnDelete(new DaoConfig().isEnforceReferentialIntegrityOnDelete()); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchCustomSearchParamTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchCustomSearchParamTest.java index ddb982d5569..5b0b55b6b10 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchCustomSearchParamTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchCustomSearchParamTest.java @@ -50,11 +50,11 @@ import org.hl7.fhir.r4.model.SearchParameter; import org.hl7.fhir.r4.model.ServiceRequest; import org.hl7.fhir.r4.model.Specimen; import org.hl7.fhir.r4.model.StringType; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; import org.mockito.ArgumentCaptor; import org.mockito.internal.util.collections.ListUtil; import org.springframework.transaction.TransactionStatus; @@ -64,6 +64,7 @@ import org.springframework.transaction.support.TransactionTemplate; import java.util.List; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.containsString; @@ -71,9 +72,8 @@ import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.hasItems; import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.startsWith; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.Mockito.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; @@ -82,12 +82,12 @@ import static org.mockito.Mockito.verify; public class FhirResourceDaoR4SearchCustomSearchParamTest extends BaseJpaR4Test { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirResourceDaoR4SearchCustomSearchParamTest.class); - @After + @AfterEach public void after() { myDaoConfig.setValidateSearchParameterExpressionsOnSave(new DaoConfig().isValidateSearchParameterExpressionsOnSave()); } - @Before + @BeforeEach public void beforeDisableResultReuse() { myDaoConfig.setReuseCachedSearchResultsForMillis(null); myModelConfig.setDefaultSearchParamsCanBeOverridden(new ModelConfig().isDefaultSearchParamsCanBeOverridden()); @@ -153,7 +153,7 @@ public class FhirResourceDaoR4SearchCustomSearchParamTest extends BaseJpaR4Test } @Test - @Ignore + @Disabled public void testCreateInvalidParamInvalidResourceName() { SearchParameter fooSp = new SearchParameter(); fooSp.addBase("Patient"); @@ -189,7 +189,7 @@ public class FhirResourceDaoR4SearchCustomSearchParamTest extends BaseJpaR4Test } @Test - @Ignore + @Disabled public void testCreateInvalidParamNoResourceName() { SearchParameter fooSp = new SearchParameter(); fooSp.addBase("Patient"); @@ -1433,9 +1433,5 @@ public class FhirResourceDaoR4SearchCustomSearchParamTest extends BaseJpaR4Test - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchDistanceTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchDistanceTest.java index 3401fc3fbef..d4a4341dffb 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchDistanceTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchDistanceTest.java @@ -4,18 +4,18 @@ import ca.uhn.fhir.jpa.searchparam.MatchUrlService; import ca.uhn.fhir.jpa.searchparam.SearchParameterMap; import ca.uhn.fhir.jpa.util.CoordCalculatorTest; import org.hl7.fhir.r4.model.Location; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import java.util.List; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.Matchers.contains; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; public class FhirResourceDaoR4SearchDistanceTest extends BaseJpaR4Test { - @Before + @BeforeEach public void beforeDisableResultReuse() { myDaoConfig.setReuseCachedSearchResultsForMillis(null); } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchFtTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchFtTest.java index a95ee5c5ec8..853de6ee8a8 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchFtTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchFtTest.java @@ -10,23 +10,24 @@ import ca.uhn.fhir.util.TestUtil; import org.hl7.fhir.instance.model.api.IIdType; import org.hl7.fhir.r4.model.*; import org.hl7.fhir.r4.model.Observation.ObservationStatus; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import javax.servlet.http.HttpServletRequest; import java.util.List; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.mock; public class FhirResourceDaoR4SearchFtTest extends BaseJpaR4Test { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirResourceDaoR4SearchFtTest.class); - @Before + @BeforeEach public void beforeDisableResultReuse() { myDaoConfig.setReuseCachedSearchResultsForMillis(null); } @@ -99,7 +100,7 @@ public class FhirResourceDaoR4SearchFtTest extends BaseJpaR4Test { } @Test - @Ignore + @Disabled public void testStringTextSearch() { Observation obs1 = new Observation(); obs1.getCode().setText("AAAAA"); @@ -358,7 +359,7 @@ public class FhirResourceDaoR4SearchFtTest extends BaseJpaR4Test { obs4.getCode().addCoding().setCode("CODE1"); obs4.setValue(new StringType("obsvalue1")); IIdType obsId4 = myObservationDao.create(obs4, mockSrd()).getId().toUnqualifiedVersionless(); - assertNotEquals(obsId1.getIdPart(), obsId4.getIdPart(), devId1); + assertNotEquals(obsId4.getIdPart(), devId1, obsId1.getIdPart()); param = new StringAndListParam(); param.addAnd(new StringOrListParam().addOr(new StringParam("obsvalue1"))); @@ -445,7 +446,7 @@ public class FhirResourceDaoR4SearchFtTest extends BaseJpaR4Test { obs4.getCode().addCoding().setCode("CODE1"); obs4.setValue(new StringType("obsvalue1")); IIdType obsId4 = myObservationDao.create(obs4, mockSrd()).getId().toUnqualifiedVersionless(); - assertNotEquals(obsId1.getIdPart(), obsId4.getIdPart(), devId1); + assertNotEquals(obsId4.getIdPart(), devId1, obsId1.getIdPart()); param = new StringAndListParam(); param.addAnd(new StringOrListParam().addOr(new StringParam("obsvalue1"))); @@ -567,9 +568,5 @@ public class FhirResourceDaoR4SearchFtTest extends BaseJpaR4Test { } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchLastNAsyncIT.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchLastNAsyncIT.java index b7a28efb5fc..e06b690899f 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchLastNAsyncIT.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchLastNAsyncIT.java @@ -2,19 +2,19 @@ package ca.uhn.fhir.jpa.dao.r4; import ca.uhn.fhir.jpa.api.config.DaoConfig; import ca.uhn.fhir.jpa.dao.SearchBuilder; +import ca.uhn.fhir.jpa.dao.data.ISearchDao; +import ca.uhn.fhir.jpa.entity.Search; import ca.uhn.fhir.jpa.searchparam.SearchParameterMap; import ca.uhn.fhir.rest.param.ReferenceParam; import ca.uhn.fhir.rest.param.TokenParam; import ca.uhn.fhir.rest.server.RestfulServer; -import ca.uhn.fhir.util.TestUtil; import org.hl7.fhir.r4.model.Observation; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import java.util.ArrayList; import java.util.HashMap; @@ -22,20 +22,21 @@ import java.util.List; import java.util.Map; import java.util.stream.Collectors; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.matchesPattern; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.when; -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) public class FhirResourceDaoR4SearchLastNAsyncIT extends BaseR4SearchLastN { @Autowired protected DaoConfig myDaoConfig; - private List originalPreFetchThresholds; + @Autowired + private ISearchDao mySearchDao; - @Before + @BeforeEach public void before() { RestfulServer myServer = new RestfulServer(myFhirCtx); @@ -56,7 +57,7 @@ public class FhirResourceDaoR4SearchLastNAsyncIT extends BaseR4SearchLastN { } - @After + @AfterEach public void after() { myDaoConfig.setSearchPreFetchThresholds(originalPreFetchThresholds); SearchBuilder.setMaxPageSize50ForTest(false); @@ -65,6 +66,12 @@ public class FhirResourceDaoR4SearchLastNAsyncIT extends BaseR4SearchLastN { @Test public void testLastNChunking() { + runInTransaction(()->{ + for (Search search : mySearchDao.findAll()) { + mySearchDao.updateDeleted(search.getId(), true); + } + }); + // Set up search parameters that will return 75 Observations. SearchParameterMap params = new SearchParameterMap(); ReferenceParam subjectParam1 = new ReferenceParam("Patient", "", patient0Id.getValue()); @@ -92,7 +99,7 @@ public class FhirResourceDaoR4SearchLastNAsyncIT extends BaseR4SearchLastN { myDaoConfig.setSearchPreFetchThresholds(myBiggerPreFetchThresholds); myCaptureQueriesListener.clear(); - List results = toUnqualifiedVersionlessIdValues(myObservationDao.observationsLastN(params, mockSrd(),null)); + List results = toUnqualifiedVersionlessIdValues(myObservationDao.observationsLastN(params, mockSrd(), null)); assertEquals(75, results.size()); myCaptureQueriesListener.logSelectQueriesForCurrentThread(); List queries = myCaptureQueriesListener @@ -106,7 +113,7 @@ public class FhirResourceDaoR4SearchLastNAsyncIT extends BaseR4SearchLastN { // The first chunked query should have a full complement of PIDs StringBuilder firstQueryPattern = new StringBuilder(".*RES_ID in \\('[0-9]+'"); - for (int pidIndex = 1; pidIndex<50; pidIndex++) { + for (int pidIndex = 1; pidIndex < 50; pidIndex++) { firstQueryPattern.append(" , '[0-9]+'"); } firstQueryPattern.append("\\).*"); @@ -114,10 +121,10 @@ public class FhirResourceDaoR4SearchLastNAsyncIT extends BaseR4SearchLastN { // the second chunked query should be padded with "-1". StringBuilder secondQueryPattern = new StringBuilder(".*RES_ID in \\('[0-9]+'"); - for (int pidIndex = 1; pidIndex<25; pidIndex++) { + for (int pidIndex = 1; pidIndex < 25; pidIndex++) { secondQueryPattern.append(" , '[0-9]+'"); } - for (int pidIndex = 0; pidIndex<25; pidIndex++) { + for (int pidIndex = 0; pidIndex < 25; pidIndex++) { secondQueryPattern.append(" , '-1'"); } secondQueryPattern.append("\\).*"); @@ -125,9 +132,4 @@ public class FhirResourceDaoR4SearchLastNAsyncIT extends BaseR4SearchLastN { } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } - } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchLastNIT.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchLastNIT.java index d2314dc191e..2ac7e6f002e 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchLastNIT.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchLastNIT.java @@ -2,26 +2,28 @@ package ca.uhn.fhir.jpa.dao.r4; import ca.uhn.fhir.jpa.dao.SearchBuilder; import ca.uhn.fhir.jpa.searchparam.SearchParameterMap; -import ca.uhn.fhir.rest.param.*; -import ca.uhn.fhir.util.TestUtil; -import org.hl7.fhir.r4.model.*; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import ca.uhn.fhir.rest.param.ReferenceParam; +import ca.uhn.fhir.rest.param.TokenParam; +import org.hl7.fhir.r4.model.Observation; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.test.context.junit.jupiter.SpringExtension; -import java.util.*; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import java.util.stream.Collectors; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.matchesPattern; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.when; -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) public class FhirResourceDaoR4SearchLastNIT extends BaseR4SearchLastN { - @After + @AfterEach public void resetMaximumPageSize() { SearchBuilder.setMaxPageSize50ForTest(false); } @@ -49,7 +51,7 @@ public class FhirResourceDaoR4SearchLastNIT extends BaseR4SearchLastN { SearchBuilder.setMaxPageSize50ForTest(true); myCaptureQueriesListener.clear(); - List results = toUnqualifiedVersionlessIdValues(myObservationDao.observationsLastN(params, mockSrd(),null)); + List results = toUnqualifiedVersionlessIdValues(myObservationDao.observationsLastN(params, mockSrd(), null)); assertEquals(75, results.size()); myCaptureQueriesListener.logSelectQueriesForCurrentThread(); List queries = myCaptureQueriesListener @@ -63,7 +65,7 @@ public class FhirResourceDaoR4SearchLastNIT extends BaseR4SearchLastN { // The first and third chunked queries should have a full complement of PIDs StringBuilder firstQueryPattern = new StringBuilder(".*RES_ID in \\('[0-9]+'"); - for (int pidIndex = 1; pidIndex<50; pidIndex++) { + for (int pidIndex = 1; pidIndex < 50; pidIndex++) { firstQueryPattern.append(" , '[0-9]+'"); } firstQueryPattern.append("\\).*"); @@ -72,10 +74,10 @@ public class FhirResourceDaoR4SearchLastNIT extends BaseR4SearchLastN { // the second and fourth chunked queries should be padded with "-1". StringBuilder secondQueryPattern = new StringBuilder(".*RES_ID in \\('[0-9]+'"); - for (int pidIndex = 1; pidIndex<25; pidIndex++) { + for (int pidIndex = 1; pidIndex < 25; pidIndex++) { secondQueryPattern.append(" , '[0-9]+'"); } - for (int pidIndex = 0; pidIndex<25; pidIndex++) { + for (int pidIndex = 0; pidIndex < 25; pidIndex++) { secondQueryPattern.append(" , '-1'"); } secondQueryPattern.append("\\).*"); @@ -84,9 +86,4 @@ public class FhirResourceDaoR4SearchLastNIT extends BaseR4SearchLastN { } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } - } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchMissingTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchMissingTest.java index 50e13882a58..4973932609f 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchMissingTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchMissingTest.java @@ -10,33 +10,22 @@ import ca.uhn.fhir.rest.param.StringParam; import ca.uhn.fhir.rest.param.TokenParam; import ca.uhn.fhir.rest.server.exceptions.MethodNotAllowedException; import org.hl7.fhir.instance.model.api.IIdType; -import org.hl7.fhir.r4.model.DateType; -import org.hl7.fhir.r4.model.MedicationRequest; -import org.hl7.fhir.r4.model.Observation; -import org.hl7.fhir.r4.model.Organization; -import org.hl7.fhir.r4.model.Patient; -import org.hl7.fhir.r4.model.Quantity; -import org.hl7.fhir.r4.model.Reference; -import org.hl7.fhir.r4.model.Task; -import org.junit.Before; -import org.junit.Test; +import org.hl7.fhir.r4.model.*; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.util.List; -import static org.hamcrest.Matchers.contains; -import static org.hamcrest.Matchers.containsInRelativeOrder; -import static org.hamcrest.Matchers.empty; -import static org.hamcrest.Matchers.hasSize; -import static org.hamcrest.Matchers.not; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.*; +import static org.junit.jupiter.api.Assertions.*; public class FhirResourceDaoR4SearchMissingTest extends BaseJpaR4Test { private static final Logger ourLog = LoggerFactory.getLogger(FhirResourceDaoR4SearchMissingTest.class); - @Before + @BeforeEach public void beforeResetMissing() { myDaoConfig.setIndexMissingFields(DaoConfig.IndexEnabledEnum.ENABLED); } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchNoFtTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchNoFtTest.java index 42ce8e0a9a1..2fdec9a3241 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchNoFtTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchNoFtTest.java @@ -118,14 +118,15 @@ import org.hl7.fhir.r4.model.Substance; import org.hl7.fhir.r4.model.Task; import org.hl7.fhir.r4.model.Timing; import org.hl7.fhir.r4.model.ValueSet; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; import org.mockito.ArgumentMatchers; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.transaction.TransactionDefinition; import org.springframework.transaction.TransactionStatus; import org.springframework.transaction.support.TransactionCallback; import org.springframework.transaction.support.TransactionCallbackWithoutResult; @@ -144,6 +145,7 @@ import java.util.TreeSet; import java.util.stream.Collectors; import static ca.uhn.fhir.rest.api.Constants.PARAM_TYPE; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.containsString; @@ -153,12 +155,11 @@ import static org.hamcrest.Matchers.hasItem; import static org.hamcrest.Matchers.hasItems; import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.not; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -170,7 +171,7 @@ public class FhirResourceDaoR4SearchNoFtTest extends BaseJpaR4Test { @Autowired MatchUrlService myMatchUrlService; - @After + @AfterEach public void afterResetSearchSize() { myDaoConfig.setReuseCachedSearchResultsForMillis(new DaoConfig().getReuseCachedSearchResultsForMillis()); myDaoConfig.setFetchSizeDefaultMaximum(new DaoConfig().getFetchSizeDefaultMaximum()); @@ -179,7 +180,7 @@ public class FhirResourceDaoR4SearchNoFtTest extends BaseJpaR4Test { myDaoConfig.setIndexMissingFields(new DaoConfig().getIndexMissingFields()); } - @Before + @BeforeEach public void beforeDisableCacheReuse() { myModelConfig.setSuppressStringIndexingInTokens(new ModelConfig().isSuppressStringIndexingInTokens()); myDaoConfig.setReuseCachedSearchResultsForMillis(null); @@ -731,7 +732,7 @@ public class FhirResourceDaoR4SearchNoFtTest extends BaseJpaR4Test { * Per message from David Hay on Skype */ @Test - @Ignore + @Disabled public void testEverythingWithLargeSet() throws Exception { myFhirCtx.setParserErrorHandler(new StrictErrorHandler()); @@ -1179,7 +1180,7 @@ public class FhirResourceDaoR4SearchNoFtTest extends BaseJpaR4Test { final IIdType id = myServiceRequestDao.create(res, mySrd).getId().toUnqualifiedVersionless(); TransactionTemplate txTemplate = new TransactionTemplate(myTransactionMgr); - txTemplate.setPropagationBehavior(TransactionTemplate.PROPAGATION_REQUIRES_NEW); + txTemplate.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW); txTemplate.execute(new TransactionCallbackWithoutResult() { @Override protected void doInTransactionWithoutResult(TransactionStatus theArg0) { @@ -1575,7 +1576,7 @@ public class FhirResourceDaoR4SearchNoFtTest extends BaseJpaR4Test { { TokenParam v0 = new TokenParam("foo", "testSearchCompositeParamN01"); StringParam v1 = new StringParam("testSearchCompositeParamS02"); - CompositeParam val = new CompositeParam(v0, v1); + CompositeParam val = new CompositeParam<>(v0, v1); IBundleProvider result = myObservationDao.search(new SearchParameterMap().setLoadSynchronous(true).add(Observation.SP_CODE_VALUE_STRING, val)); assertEquals(1, result.size().intValue()); assertEquals(id2.toUnqualifiedVersionless(), result.getResources(0, 1).get(0).getIdElement().toUnqualifiedVersionless()); @@ -1597,28 +1598,28 @@ public class FhirResourceDaoR4SearchNoFtTest extends BaseJpaR4Test { { TokenParam v0 = new TokenParam("foo", "testSearchCompositeParamDateN01"); DateParam v1 = new DateParam("2001-01-01"); - CompositeParam val = new CompositeParam(v0, v1); + CompositeParam val = new CompositeParam<>(v0, v1); IBundleProvider result = myObservationDao.search(new SearchParameterMap().setLoadSynchronous(true).add(Observation.SP_CODE_VALUE_DATE, val)); assertThat(toUnqualifiedVersionlessIds(result), containsInAnyOrder(id1)); } { TokenParam v0 = new TokenParam("foo", "testSearchCompositeParamDateN01"); DateParam v1 = new DateParam(">2001-01-01T10:12:12Z"); - CompositeParam val = new CompositeParam(v0, v1); + CompositeParam val = new CompositeParam<>(v0, v1); IBundleProvider result = myObservationDao.search(new SearchParameterMap().setLoadSynchronous(true).add(Observation.SP_CODE_VALUE_DATE, val)); assertThat(toUnqualifiedVersionlessIds(result), containsInAnyOrder(id1, id2)); } { TokenParam v0 = new TokenParam("foo", "testSearchCompositeParamDateN01"); DateParam v1 = new DateParam("gt2001-01-01T11:12:12Z"); - CompositeParam val = new CompositeParam(v0, v1); + CompositeParam val = new CompositeParam<>(v0, v1); IBundleProvider result = myObservationDao.search(new SearchParameterMap().setLoadSynchronous(true).add(Observation.SP_CODE_VALUE_DATE, val)); assertThat(toUnqualifiedVersionlessIds(result), containsInAnyOrder(id1, id2)); } { TokenParam v0 = new TokenParam("foo", "testSearchCompositeParamDateN01"); DateParam v1 = new DateParam("gt2001-01-01T15:12:12Z"); - CompositeParam val = new CompositeParam(v0, v1); + CompositeParam val = new CompositeParam<>(v0, v1); IBundleProvider result = myObservationDao.search(new SearchParameterMap().setLoadSynchronous(true).add(Observation.SP_CODE_VALUE_DATE, val)); assertThat(toUnqualifiedVersionlessIds(result), containsInAnyOrder(id2)); } @@ -2334,7 +2335,7 @@ public class FhirResourceDaoR4SearchNoFtTest extends BaseJpaR4Test { } @Test - public void testSearchLastUpdatedParam() throws InterruptedException { + public void testSearchLastUpdatedParam() { String methodName = "testSearchLastUpdatedParam"; DateTimeType beforeAny = new DateTimeType(new Date(), TemporalPrecisionEnum.MILLI); @@ -2418,9 +2419,8 @@ public class FhirResourceDaoR4SearchNoFtTest extends BaseJpaR4Test { } - @SuppressWarnings("deprecation") @Test - public void testSearchLastUpdatedParamWithComparator() throws InterruptedException { + public void testSearchLastUpdatedParamWithComparator() { IIdType id0; { Patient patient = new Patient(); @@ -2829,11 +2829,11 @@ public class FhirResourceDaoR4SearchNoFtTest extends BaseJpaR4Test { @Test public void testSearchQuantityWrongParam() { Condition c1 = new Condition(); - c1.setAbatement(new Range().setLow((SimpleQuantity) new SimpleQuantity().setValue(1L)).setHigh((SimpleQuantity) new SimpleQuantity().setValue(1L))); + c1.setAbatement(new Range().setLow(new SimpleQuantity().setValue(1L)).setHigh(new SimpleQuantity().setValue(1L))); String id1 = myConditionDao.create(c1).getId().toUnqualifiedVersionless().getValue(); Condition c2 = new Condition(); - c2.setOnset(new Range().setLow((SimpleQuantity) new SimpleQuantity().setValue(1L)).setHigh((SimpleQuantity) new SimpleQuantity().setValue(1L))); + c2.setOnset(new Range().setLow(new SimpleQuantity().setValue(1L)).setHigh(new SimpleQuantity().setValue(1L))); String id2 = myConditionDao.create(c2).getId().toUnqualifiedVersionless().getValue(); { @@ -2974,7 +2974,7 @@ public class FhirResourceDaoR4SearchNoFtTest extends BaseJpaR4Test { } @Test - public void testSearchResourceLinkWithChainWithMultipleTypes() throws Exception { + public void testSearchResourceLinkWithChainWithMultipleTypes() { Patient patient = new Patient(); patient.addName().setFamily("testSearchResourceLinkWithChainWithMultipleTypes01"); patient.addName().setFamily("testSearchResourceLinkWithChainWithMultipleTypesXX"); @@ -3076,7 +3076,7 @@ public class FhirResourceDaoR4SearchNoFtTest extends BaseJpaR4Test { myCaptureQueriesListener.clear(); result = toList(myObservationDao.search(new SearchParameterMap().setLoadSynchronous(true).add(Observation.SP_SUBJECT, new ReferenceParam("testSearchResourceLinkWithTextLogicalId99")))); myCaptureQueriesListener.logSelectQueriesForCurrentThread(); - assertEquals(result.toString(), 0, result.size()); + assertEquals(0, result.size(), result.toString()); // And with a numeric ID that doesn't exist result = toList(myObservationDao.search(new SearchParameterMap().setLoadSynchronous(true).add(Observation.SP_SUBJECT, new ReferenceParam("999999999999999")))); @@ -3161,7 +3161,7 @@ public class FhirResourceDaoR4SearchNoFtTest extends BaseJpaR4Test { .collect(Collectors.toList()); String resultingQueryNotFormatted = queries.get(0); - assertEquals(resultingQueryNotFormatted, 1, StringUtils.countMatches(resultingQueryNotFormatted, "HASH_VALUE")); + assertEquals(1, StringUtils.countMatches(resultingQueryNotFormatted, "HASH_VALUE"), resultingQueryNotFormatted); assertThat(resultingQueryNotFormatted, containsString("HASH_VALUE in ('3140583648400062149' , '4929264259256651518')")); // Ensure that the search actually worked @@ -3197,7 +3197,7 @@ public class FhirResourceDaoR4SearchNoFtTest extends BaseJpaR4Test { .collect(Collectors.toList()); String resultingQueryNotFormatted = queries.get(0); - assertEquals(resultingQueryNotFormatted, 1, StringUtils.countMatches(resultingQueryNotFormatted, "HASH_VALUE")); + assertEquals(1, StringUtils.countMatches(resultingQueryNotFormatted, "HASH_VALUE"), resultingQueryNotFormatted); assertThat(resultingQueryNotFormatted, containsString("HASH_VALUE in ('3140583648400062149' , '4929264259256651518')")); // Ensure that the search actually worked @@ -3411,8 +3411,8 @@ public class FhirResourceDaoR4SearchNoFtTest extends BaseJpaR4Test { .collect(Collectors.toList()); String searchQuery = queries.get(0); - assertEquals(searchQuery, 3, StringUtils.countMatches(searchQuery.toUpperCase(), "HFJ_SPIDX_TOKEN")); - assertEquals(searchQuery, 4, StringUtils.countMatches(searchQuery.toUpperCase(), "LEFT OUTER JOIN")); + assertEquals(3, StringUtils.countMatches(searchQuery.toUpperCase(), "HFJ_SPIDX_TOKEN"), searchQuery); + assertEquals(4, StringUtils.countMatches(searchQuery.toUpperCase(), "LEFT OUTER JOIN"), searchQuery); } @@ -3436,12 +3436,12 @@ public class FhirResourceDaoR4SearchNoFtTest extends BaseJpaR4Test { .collect(Collectors.toList()); String searchQuery = queries.get(0); - assertEquals(searchQuery, 1, StringUtils.countMatches(searchQuery.toUpperCase(), "HFJ_SPIDX_TOKEN")); - assertEquals(searchQuery, 1, StringUtils.countMatches(searchQuery.toUpperCase(), "LEFT OUTER JOIN")); - assertEquals(searchQuery, 2, StringUtils.countMatches(searchQuery.toUpperCase(), "AND RESOURCETA0_.RES_UPDATED")); + assertEquals(1, StringUtils.countMatches(searchQuery.toUpperCase(), "HFJ_SPIDX_TOKEN"), searchQuery); + assertEquals(1, StringUtils.countMatches(searchQuery.toUpperCase(), "LEFT OUTER JOIN"), searchQuery); + assertEquals(2, StringUtils.countMatches(searchQuery.toUpperCase(), "AND RESOURCETA0_.RES_UPDATED"), searchQuery); } - @Ignore + @Disabled @Test public void testSearchWithContext() { @@ -3712,7 +3712,7 @@ public class FhirResourceDaoR4SearchNoFtTest extends BaseJpaR4Test { } @Test - @Ignore + @Disabled public void testSearchUnknownContentParam() { SearchParameterMap params = new SearchParameterMap(); params.add(Constants.PARAM_CONTENT, new StringParam("fulltext")); @@ -3725,7 +3725,7 @@ public class FhirResourceDaoR4SearchNoFtTest extends BaseJpaR4Test { } @Test - @Ignore + @Disabled public void testSearchUnknownTextParam() { SearchParameterMap params = new SearchParameterMap(); params.add(Constants.PARAM_TEXT, new StringParam("fulltext")); @@ -4075,9 +4075,9 @@ public class FhirResourceDaoR4SearchNoFtTest extends BaseJpaR4Test { assertThat(patients.toString(), patients, contains(obsId1)); String searchQuery = myCaptureQueriesListener.getSelectQueriesForCurrentThread().get(0).getSql(true, true); ourLog.info("Search query:\n{}", searchQuery); - assertEquals(searchQuery, 1, StringUtils.countMatches(searchQuery.toLowerCase(), "join")); - assertEquals(searchQuery, 1, StringUtils.countMatches(searchQuery.toLowerCase(), "hash_identity")); - assertEquals(searchQuery, 2, StringUtils.countMatches(searchQuery.toLowerCase(), "sp_value_low")); + assertEquals(1, StringUtils.countMatches(searchQuery.toLowerCase(), "join"), searchQuery); + assertEquals(1, StringUtils.countMatches(searchQuery.toLowerCase(), "hash_identity"), searchQuery); + assertEquals(2, StringUtils.countMatches(searchQuery.toLowerCase(), "sp_value_low"), searchQuery); } // Two AND instances of 1 SP and 1 instance of another @@ -4093,9 +4093,9 @@ public class FhirResourceDaoR4SearchNoFtTest extends BaseJpaR4Test { assertThat(patients.toString(), patients, contains(obsId1)); String searchQuery = myCaptureQueriesListener.getSelectQueriesForCurrentThread().get(0).getSql(true, true); ourLog.info("Search query:\n{}", searchQuery); - assertEquals(searchQuery, 2, StringUtils.countMatches(searchQuery.toLowerCase(), "join")); - assertEquals(searchQuery, 2, StringUtils.countMatches(searchQuery.toLowerCase(), "hash_identity")); - assertEquals(searchQuery, 4, StringUtils.countMatches(searchQuery.toLowerCase(), "sp_value_low")); + assertEquals(2, StringUtils.countMatches(searchQuery.toLowerCase(), "join"), searchQuery); + assertEquals(2, StringUtils.countMatches(searchQuery.toLowerCase(), "hash_identity"), searchQuery); + assertEquals(4, StringUtils.countMatches(searchQuery.toLowerCase(), "sp_value_low"), searchQuery); } // Period search @@ -4108,9 +4108,9 @@ public class FhirResourceDaoR4SearchNoFtTest extends BaseJpaR4Test { assertThat(patients.toString(), patients, containsInAnyOrder(obsId3, obsId4)); String searchQuery = myCaptureQueriesListener.getSelectQueriesForCurrentThread().get(0).getSql(true, true); ourLog.info("Search query:\n{}", searchQuery); - assertEquals(searchQuery, 1, StringUtils.countMatches(searchQuery.toLowerCase(), "join")); - assertEquals(searchQuery, 1, StringUtils.countMatches(searchQuery.toLowerCase(), "hash_identity")); - assertEquals(searchQuery, 1, StringUtils.countMatches(searchQuery.toLowerCase(), "sp_value_low")); + assertEquals(1, StringUtils.countMatches(searchQuery.toLowerCase(), "join"), searchQuery); + assertEquals(1, StringUtils.countMatches(searchQuery.toLowerCase(), "hash_identity"), searchQuery); + assertEquals(1, StringUtils.countMatches(searchQuery.toLowerCase(), "sp_value_low"), searchQuery); } } @@ -4476,7 +4476,7 @@ public class FhirResourceDaoR4SearchNoFtTest extends BaseJpaR4Test { public void testSearchWithRevIncludes() { final String methodName = "testSearchWithRevIncludes"; TransactionTemplate txTemplate = new TransactionTemplate(myTransactionMgr); - txTemplate.setPropagationBehavior(TransactionTemplate.PROPAGATION_REQUIRES_NEW); + txTemplate.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW); IIdType pid = txTemplate.execute(new TransactionCallback() { @Override @@ -4494,7 +4494,7 @@ public class FhirResourceDaoR4SearchNoFtTest extends BaseJpaR4Test { }); SearchParameterMap map = new SearchParameterMap(); - map.add(Patient.SP_RES_ID, new StringParam(pid.getIdPart())); + map.add(IAnyResource.SP_RES_ID, new StringParam(pid.getIdPart())); map.addRevInclude(Condition.INCLUDE_PATIENT); IBundleProvider results = myPatientDao.search(map); List foundResources = results.getResources(0, results.size()); @@ -5125,9 +5125,5 @@ public class FhirResourceDaoR4SearchNoFtTest extends BaseJpaR4Test { return b.toString(); } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchNoHashesTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchNoHashesTest.java index ccbb3e40a87..9c5648fb41e 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchNoHashesTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchNoHashesTest.java @@ -93,12 +93,13 @@ import org.hl7.fhir.r4.model.Subscription.SubscriptionStatus; import org.hl7.fhir.r4.model.Substance; import org.hl7.fhir.r4.model.Task; import org.hl7.fhir.r4.model.ValueSet; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.transaction.TransactionDefinition; import org.springframework.transaction.TransactionStatus; import org.springframework.transaction.support.TransactionCallback; import org.springframework.transaction.support.TransactionCallbackWithoutResult; @@ -115,6 +116,7 @@ import java.util.Set; import java.util.TreeSet; import java.util.stream.Collectors; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.containsString; @@ -123,10 +125,9 @@ import static org.hamcrest.Matchers.endsWith; import static org.hamcrest.Matchers.hasItem; import static org.hamcrest.Matchers.hasItems; import static org.hamcrest.Matchers.not; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.Mockito.mock; @SuppressWarnings({"unchecked", "Duplicates"}) @@ -135,7 +136,7 @@ public class FhirResourceDaoR4SearchNoHashesTest extends BaseJpaR4Test { @Autowired private ISearchDao mySearchEntityDao; - @After + @AfterEach public void afterResetSearchSize() { myDaoConfig.setReuseCachedSearchResultsForMillis(new DaoConfig().getReuseCachedSearchResultsForMillis()); myDaoConfig.setFetchSizeDefaultMaximum(new DaoConfig().getFetchSizeDefaultMaximum()); @@ -143,7 +144,7 @@ public class FhirResourceDaoR4SearchNoHashesTest extends BaseJpaR4Test { myDaoConfig.setDisableHashBasedSearches(false); } - @Before + @BeforeEach public void beforeInitialize() { myDaoConfig.setReuseCachedSearchResultsForMillis(null); myDaoConfig.setDisableHashBasedSearches(true); @@ -389,7 +390,7 @@ public class FhirResourceDaoR4SearchNoHashesTest extends BaseJpaR4Test { * Per message from David Hay on Skype */ @Test - @Ignore + @Disabled public void testEverythingWithLargeSet() throws Exception { myFhirCtx.setParserErrorHandler(new StrictErrorHandler()); @@ -397,7 +398,7 @@ public class FhirResourceDaoR4SearchNoHashesTest extends BaseJpaR4Test { Bundle inputBundle = myFhirCtx.newJsonParser().parseResource(Bundle.class, inputString); inputBundle.setType(BundleType.TRANSACTION); - Set allIds = new TreeSet(); + Set allIds = new TreeSet<>(); for (BundleEntryComponent nextEntry : inputBundle.getEntry()) { nextEntry.getRequest().setMethod(HTTPVerb.PUT); nextEntry.getRequest().setUrl(nextEntry.getResource().getId()); @@ -500,7 +501,7 @@ public class FhirResourceDaoR4SearchNoHashesTest extends BaseJpaR4Test { .collect(Collectors.toList()); String resultingQueryNotFormatted = queries.get(0); - assertEquals(resultingQueryNotFormatted, 1, StringUtils.countMatches(resultingQueryNotFormatted, "SP_VALUE")); + assertEquals(1, StringUtils.countMatches(resultingQueryNotFormatted, "SP_VALUE"), resultingQueryNotFormatted); assertThat(resultingQueryNotFormatted, containsString("SP_VALUE in ('BAR' , 'FOO')")); // Ensure that the search actually worked @@ -786,7 +787,7 @@ public class FhirResourceDaoR4SearchNoHashesTest extends BaseJpaR4Test { final IIdType id = myServiceRequestDao.create(res, mySrd).getId().toUnqualifiedVersionless(); TransactionTemplate txTemplate = new TransactionTemplate(myTransactionMgr); - txTemplate.setPropagationBehavior(TransactionTemplate.PROPAGATION_REQUIRES_NEW); + txTemplate.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW); txTemplate.execute(new TransactionCallbackWithoutResult() { @Override protected void doInTransactionWithoutResult(TransactionStatus theArg0) { @@ -1108,7 +1109,7 @@ public class FhirResourceDaoR4SearchNoHashesTest extends BaseJpaR4Test { { TokenParam v0 = new TokenParam("foo", "testSearchCompositeParamN01"); StringParam v1 = new StringParam("testSearchCompositeParamS01"); - CompositeParam val = new CompositeParam(v0, v1); + CompositeParam val = new CompositeParam<>(v0, v1); IBundleProvider result = myObservationDao.search(new SearchParameterMap().setLoadSynchronous(true).add(Observation.SP_CODE_VALUE_STRING, val)); assertEquals(1, result.size().intValue()); assertEquals(id1.toUnqualifiedVersionless(), result.getResources(0, 1).get(0).getIdElement().toUnqualifiedVersionless()); @@ -1116,7 +1117,7 @@ public class FhirResourceDaoR4SearchNoHashesTest extends BaseJpaR4Test { { TokenParam v0 = new TokenParam("foo", "testSearchCompositeParamN01"); StringParam v1 = new StringParam("testSearchCompositeParamS02"); - CompositeParam val = new CompositeParam(v0, v1); + CompositeParam val = new CompositeParam<>(v0, v1); IBundleProvider result = myObservationDao.search(new SearchParameterMap().setLoadSynchronous(true).add(Observation.SP_CODE_VALUE_STRING, val)); assertEquals(1, result.size().intValue()); assertEquals(id2.toUnqualifiedVersionless(), result.getResources(0, 1).get(0).getIdElement().toUnqualifiedVersionless()); @@ -1138,28 +1139,28 @@ public class FhirResourceDaoR4SearchNoHashesTest extends BaseJpaR4Test { { TokenParam v0 = new TokenParam("foo", "testSearchCompositeParamDateN01"); DateParam v1 = new DateParam("2001-01-01"); - CompositeParam val = new CompositeParam(v0, v1); + CompositeParam val = new CompositeParam<>(v0, v1); IBundleProvider result = myObservationDao.search(new SearchParameterMap().setLoadSynchronous(true).add(Observation.SP_CODE_VALUE_DATE, val)); assertThat(toUnqualifiedVersionlessIds(result), containsInAnyOrder(id1)); } { TokenParam v0 = new TokenParam("foo", "testSearchCompositeParamDateN01"); DateParam v1 = new DateParam(">2001-01-01T10:12:12Z"); - CompositeParam val = new CompositeParam(v0, v1); + CompositeParam val = new CompositeParam<>(v0, v1); IBundleProvider result = myObservationDao.search(new SearchParameterMap().setLoadSynchronous(true).add(Observation.SP_CODE_VALUE_DATE, val)); assertThat(toUnqualifiedVersionlessIds(result), containsInAnyOrder(id1, id2)); } { TokenParam v0 = new TokenParam("foo", "testSearchCompositeParamDateN01"); DateParam v1 = new DateParam("gt2001-01-01T11:12:12Z"); - CompositeParam val = new CompositeParam(v0, v1); + CompositeParam val = new CompositeParam<>(v0, v1); IBundleProvider result = myObservationDao.search(new SearchParameterMap().setLoadSynchronous(true).add(Observation.SP_CODE_VALUE_DATE, val)); assertThat(toUnqualifiedVersionlessIds(result), containsInAnyOrder(id1, id2)); } { TokenParam v0 = new TokenParam("foo", "testSearchCompositeParamDateN01"); DateParam v1 = new DateParam("gt2001-01-01T15:12:12Z"); - CompositeParam val = new CompositeParam(v0, v1); + CompositeParam val = new CompositeParam<>(v0, v1); IBundleProvider result = myObservationDao.search(new SearchParameterMap().setLoadSynchronous(true).add(Observation.SP_CODE_VALUE_DATE, val)); assertThat(toUnqualifiedVersionlessIds(result), containsInAnyOrder(id2)); } @@ -1473,7 +1474,7 @@ public class FhirResourceDaoR4SearchNoHashesTest extends BaseJpaR4Test { } @Test - public void testSearchLastUpdatedParam() throws InterruptedException { + public void testSearchLastUpdatedParam() { String methodName = "testSearchLastUpdatedParam"; TestUtil.sleepOneClick(); @@ -1557,9 +1558,8 @@ public class FhirResourceDaoR4SearchNoHashesTest extends BaseJpaR4Test { } - @SuppressWarnings("deprecation") @Test - public void testSearchLastUpdatedParamWithComparator() throws InterruptedException { + public void testSearchLastUpdatedParamWithComparator() { IIdType id0; { Patient patient = new Patient(); @@ -1852,11 +1852,11 @@ public class FhirResourceDaoR4SearchNoHashesTest extends BaseJpaR4Test { @Test public void testSearchQuantityWrongParam() { Condition c1 = new Condition(); - c1.setAbatement(new Range().setLow((SimpleQuantity) new SimpleQuantity().setValue(1L)).setHigh((SimpleQuantity) new SimpleQuantity().setValue(1L))); + c1.setAbatement(new Range().setLow(new SimpleQuantity().setValue(1L)).setHigh(new SimpleQuantity().setValue(1L))); String id1 = myConditionDao.create(c1).getId().toUnqualifiedVersionless().getValue(); Condition c2 = new Condition(); - c2.setOnset(new Range().setLow((SimpleQuantity) new SimpleQuantity().setValue(1L)).setHigh((SimpleQuantity) new SimpleQuantity().setValue(1L))); + c2.setOnset(new Range().setLow(new SimpleQuantity().setValue(1L)).setHigh(new SimpleQuantity().setValue(1L))); String id2 = myConditionDao.create(c2).getId().toUnqualifiedVersionless().getValue(); { @@ -2113,7 +2113,7 @@ public class FhirResourceDaoR4SearchNoHashesTest extends BaseJpaR4Test { } @Test - public void testSearchStringParam() throws Exception { + public void testSearchStringParam() { IIdType pid1; IIdType pid2; { @@ -2456,7 +2456,7 @@ public class FhirResourceDaoR4SearchNoHashesTest extends BaseJpaR4Test { } @Test - @Ignore + @Disabled public void testSearchUnknownContentParam() { SearchParameterMap params = new SearchParameterMap(); params.add(Constants.PARAM_CONTENT, new StringParam("fulltext")); @@ -2469,7 +2469,7 @@ public class FhirResourceDaoR4SearchNoHashesTest extends BaseJpaR4Test { } @Test - @Ignore + @Disabled public void testSearchUnknownTextParam() { SearchParameterMap params = new SearchParameterMap(); params.add(Constants.PARAM_TEXT, new StringParam("fulltext")); @@ -3014,7 +3014,7 @@ public class FhirResourceDaoR4SearchNoHashesTest extends BaseJpaR4Test { public void testSearchWithRevIncludes() { final String methodName = "testSearchWithRevIncludes"; TransactionTemplate txTemplate = new TransactionTemplate(myTransactionMgr); - txTemplate.setPropagationBehavior(TransactionTemplate.PROPAGATION_REQUIRES_NEW); + txTemplate.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW); IIdType pid = txTemplate.execute(new TransactionCallback() { @Override @@ -3032,7 +3032,7 @@ public class FhirResourceDaoR4SearchNoHashesTest extends BaseJpaR4Test { }); SearchParameterMap map = new SearchParameterMap(); - map.add(Patient.SP_RES_ID, new StringParam(pid.getIdPart())); + map.add(IAnyResource.SP_RES_ID, new StringParam(pid.getIdPart())); map.addRevInclude(Condition.INCLUDE_PATIENT); IBundleProvider results = myPatientDao.search(map); List foundResources = results.getResources(0, results.size()); @@ -3477,9 +3477,5 @@ public class FhirResourceDaoR4SearchNoHashesTest extends BaseJpaR4Test { return b.toString(); } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchOptimizedTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchOptimizedTest.java index e5822137b6b..aa839c5ebde 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchOptimizedTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchOptimizedTest.java @@ -22,15 +22,11 @@ import ca.uhn.fhir.util.TestUtil; import org.apache.commons.lang3.StringUtils; import org.hl7.fhir.instance.model.api.IAnyResource; import org.hl7.fhir.instance.model.api.IIdType; -import org.hl7.fhir.r4.model.DateTimeType; -import org.hl7.fhir.r4.model.Enumerations; -import org.hl7.fhir.r4.model.Organization; -import org.hl7.fhir.r4.model.Patient; -import org.hl7.fhir.r4.model.Reference; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Test; +import org.hl7.fhir.r4.model.*; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.aop.framework.AopProxyUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.concurrent.ThreadPoolExecutorFactoryBean; @@ -44,16 +40,9 @@ import java.util.stream.Collectors; import static org.apache.commons.lang3.StringUtils.leftPad; import static org.awaitility.Awaitility.await; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.empty; -import static org.hamcrest.Matchers.hasSize; -import static org.hamcrest.Matchers.matchesPattern; -import static org.hamcrest.Matchers.not; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.*; +import static org.junit.jupiter.api.Assertions.*; public class FhirResourceDaoR4SearchOptimizedTest extends BaseJpaR4Test { @@ -65,7 +54,7 @@ public class FhirResourceDaoR4SearchOptimizedTest extends BaseJpaR4Test { @Autowired private ISearchResultDao mySearchResultDao; - @Before + @BeforeEach public void before() { mySearchCoordinatorSvcImpl = (SearchCoordinatorSvcImpl) AopProxyUtils.getSingletonTarget(mySearchCoordinatorSvc); mySearchCoordinatorSvcImpl.setLoadingThrottleForUnitTests(null); @@ -73,7 +62,7 @@ public class FhirResourceDaoR4SearchOptimizedTest extends BaseJpaR4Test { myCaptureQueriesListener.setCaptureQueryStackTrace(true); } - @After + @AfterEach public final void after() { mySearchCoordinatorSvcImpl.setLoadingThrottleForUnitTests(null); mySearchCoordinatorSvcImpl.setSyncSizeForUnitTests(SearchCoordinatorSvcImpl.DEFAULT_SYNC_SIZE); @@ -158,7 +147,7 @@ public class FhirResourceDaoR4SearchOptimizedTest extends BaseJpaR4Test { assertThat(ids, hasSize(10)); PersistedJpaBundleProvider bundleProvider = (PersistedJpaBundleProvider) myDatabaseBackedPagingProvider.retrieveResultList(null, uuid); Integer bundleSize = bundleProvider.size(); - assertNotNull("Null size from provider of type " + bundleProvider.getClass() + " - Cache hit: " + bundleProvider.isCacheHit(), bundleSize); + assertNotNull(bundleSize, "Null size from provider of type " + bundleProvider.getClass() + " - Cache hit: " + bundleProvider.isCacheHit()); assertEquals(201, bundleSize.intValue()); // Search with count only @@ -754,7 +743,7 @@ public class FhirResourceDaoR4SearchOptimizedTest extends BaseJpaR4Test { .collect(Collectors.toList()); String resultingQueryNotFormatted = queries.get(0); - assertEquals(resultingQueryNotFormatted, 1, StringUtils.countMatches(resultingQueryNotFormatted, "Patient.managingOrganization")); + assertEquals(1, StringUtils.countMatches(resultingQueryNotFormatted, "Patient.managingOrganization"), resultingQueryNotFormatted); assertThat(resultingQueryNotFormatted, containsString("TARGET_RESOURCE_ID in ('" + ids.get(0) + "' , '" + ids.get(1) + "' , '" + ids.get(2) + "' , '" + ids.get(3) + "' , '" + ids.get(4) + "')")); // Ensure that the search actually worked @@ -763,7 +752,7 @@ public class FhirResourceDaoR4SearchOptimizedTest extends BaseJpaR4Test { } - @After + @AfterEach public void afterResetDao() { myDaoConfig.setResourceMetaCountHardLimit(new DaoConfig().getResourceMetaCountHardLimit()); myDaoConfig.setIndexMissingFields(new DaoConfig().getIndexMissingFields()); @@ -1138,7 +1127,7 @@ public class FhirResourceDaoR4SearchOptimizedTest extends BaseJpaR4Test { // The search itself resultingQueryNotFormatted = queries.get(1); - assertEquals(resultingQueryNotFormatted, 1, StringUtils.countMatches(resultingQueryNotFormatted, "Patient.managingOrganization")); + assertEquals(1, StringUtils.countMatches(resultingQueryNotFormatted, "Patient.managingOrganization"), resultingQueryNotFormatted); assertThat(resultingQueryNotFormatted, matchesPattern(".*TARGET_RESOURCE_ID in \\('[0-9]+' , '[0-9]+' , '[0-9]+' , '[0-9]+' , '[0-9]+'\\).*")); // Ensure that the search actually worked @@ -1146,9 +1135,4 @@ public class FhirResourceDaoR4SearchOptimizedTest extends BaseJpaR4Test { } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } - } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchPageExpiryTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchPageExpiryTest.java index 5a0b0dc5e40..2ea2fac62a0 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchPageExpiryTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchPageExpiryTest.java @@ -16,9 +16,9 @@ import org.apache.commons.lang3.time.DateUtils; import org.hl7.fhir.instance.model.api.IIdType; import org.hl7.fhir.r4.model.InstantType; import org.hl7.fhir.r4.model.Patient; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -34,8 +34,14 @@ import java.util.concurrent.atomic.AtomicLong; import static ca.uhn.fhir.jpa.search.cache.DatabaseSearchCacheSvcImpl.SEARCH_CLEANUP_JOB_INTERVAL_MILLIS; import static org.awaitility.Awaitility.await; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsInAnyOrder; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; @SuppressWarnings("Duplicates") public class FhirResourceDaoR4SearchPageExpiryTest extends BaseJpaR4Test { @@ -44,21 +50,21 @@ public class FhirResourceDaoR4SearchPageExpiryTest extends BaseJpaR4Test { @Autowired private ISearchDao mySearchEntityDao; - @After() + @AfterEach() public void after() { DatabaseSearchCacheSvcImpl staleSearchDeletingSvc = AopTestUtils.getTargetObject(mySearchCacheSvc); staleSearchDeletingSvc.setCutoffSlackForUnitTest(SEARCH_CLEANUP_JOB_INTERVAL_MILLIS); DatabaseSearchCacheSvcImpl.setNowForUnitTests(null); } - @Before + @BeforeEach public void before() { DatabaseSearchCacheSvcImpl staleSearchDeletingSvc = AopTestUtils.getTargetObject(mySearchCacheSvc); staleSearchDeletingSvc.setCutoffSlackForUnitTest(0); myDaoConfig.setCountSearchResultsUpTo(new DaoConfig().getCountSearchResultsUpTo()); } - @Before + @BeforeEach public void beforeDisableResultReuse() { myDaoConfig.setReuseCachedSearchResultsForMillis(null); myDaoConfig.setCountSearchResultsUpTo(10000); @@ -134,13 +140,13 @@ public class FhirResourceDaoR4SearchPageExpiryTest extends BaseJpaR4Test { newTxTemplate().execute(new TransactionCallbackWithoutResult() { @Override protected void doInTransactionWithoutResult(TransactionStatus theArg0) { - Search search1 = mySearchEntityDao.findByUuidAndFetchIncludes(searchUuid1).orElseThrow(()->new InternalErrorException("Search doesn't exist")); + Search search1 = mySearchEntityDao.findByUuidAndFetchIncludes(searchUuid1).orElseThrow(() -> new InternalErrorException("Search doesn't exist")); assertNotNull(search1); search1timestamp.set(search1.getCreated().getTime()); - Search search2 = mySearchEntityDao.findByUuidAndFetchIncludes(searchUuid2).orElseThrow(()->new InternalErrorException("Search doesn't exist")); + Search search2 = mySearchEntityDao.findByUuidAndFetchIncludes(searchUuid2).orElseThrow(() -> new InternalErrorException("Search doesn't exist")); assertNotNull(search2); search2timestamp.set(search2.getCreated().getTime()); - Search search3 = mySearchEntityDao.findByUuidAndFetchIncludes(searchUuid3).orElseThrow(()->new InternalErrorException("Search doesn't exist")); + Search search3 = mySearchEntityDao.findByUuidAndFetchIncludes(searchUuid3).orElseThrow(() -> new InternalErrorException("Search doesn't exist")); assertNotNull(search3); search3timestamp.set(search3.getCreated().getTime()); } @@ -162,8 +168,8 @@ public class FhirResourceDaoR4SearchPageExpiryTest extends BaseJpaR4Test { newTxTemplate().execute(new TransactionCallbackWithoutResult() { @Override protected void doInTransactionWithoutResult(TransactionStatus theArg0) { - assertFalse("Search 1 still exists", mySearchEntityDao.findByUuidAndFetchIncludes(searchUuid1).isPresent()); - assertTrue("Search 3 still exists", mySearchEntityDao.findByUuidAndFetchIncludes(searchUuid3).isPresent()); + assertFalse(mySearchEntityDao.findByUuidAndFetchIncludes(searchUuid1).isPresent(), "Search 1 still exists"); + assertTrue(mySearchEntityDao.findByUuidAndFetchIncludes(searchUuid3).isPresent(), "Search 3 still exists"); } }); @@ -171,8 +177,8 @@ public class FhirResourceDaoR4SearchPageExpiryTest extends BaseJpaR4Test { myStaleSearchDeletingSvc.pollForStaleSearchesAndDeleteThem(); - await().until(()-> newTxTemplate().execute(t -> !mySearchEntityDao.findByUuidAndFetchIncludes(searchUuid1).isPresent())); - await().until(()-> newTxTemplate().execute(t -> !mySearchEntityDao.findByUuidAndFetchIncludes(searchUuid3).isPresent())); + await().until(() -> newTxTemplate().execute(t -> !mySearchEntityDao.findByUuidAndFetchIncludes(searchUuid1).isPresent())); + await().until(() -> newTxTemplate().execute(t -> !mySearchEntityDao.findByUuidAndFetchIncludes(searchUuid3).isPresent())); } @Test @@ -207,8 +213,8 @@ public class FhirResourceDaoR4SearchPageExpiryTest extends BaseJpaR4Test { txTemplate.execute(new TransactionCallbackWithoutResult() { @Override protected void doInTransactionWithoutResult(TransactionStatus theArg0) { - Search search = mySearchEntityDao.findByUuidAndFetchIncludes(bundleProvider.getUuid()).orElseThrow(()->new InternalErrorException("Search doesn't exist")); - assertNotNull("Failed after " + sw.toString(), search); + Search search = mySearchEntityDao.findByUuidAndFetchIncludes(bundleProvider.getUuid()).orElseThrow(() -> new InternalErrorException("Search doesn't exist")); + assertNotNull(search, "Failed after " + sw.toString()); start.set(search.getCreated().getTime()); ourLog.info("Search was created: {}", new InstantType(new Date(start.get()))); } @@ -311,8 +317,8 @@ public class FhirResourceDaoR4SearchPageExpiryTest extends BaseJpaR4Test { newTxTemplate().execute(new TransactionCallbackWithoutResult() { @Override protected void doInTransactionWithoutResult(TransactionStatus theArg0) { - Search search1 = mySearchEntityDao.findByUuidAndFetchIncludes(searchUuid1).orElseThrow(()->new InternalErrorException("Search doesn't exist")); - Search search3 = mySearchEntityDao.findByUuidAndFetchIncludes(searchUuid3).orElseThrow(()->new InternalErrorException("Search doesn't exist")); + Search search1 = mySearchEntityDao.findByUuidAndFetchIncludes(searchUuid1).orElseThrow(() -> new InternalErrorException("Search doesn't exist")); + Search search3 = mySearchEntityDao.findByUuidAndFetchIncludes(searchUuid3).orElseThrow(() -> new InternalErrorException("Search doesn't exist")); assertNotNull(search3); search1timestamp.set(search1.getCreated().getTime()); search3timestamp.set(search3.getCreated().getTime()); @@ -334,8 +340,8 @@ public class FhirResourceDaoR4SearchPageExpiryTest extends BaseJpaR4Test { newTxTemplate().execute(new TransactionCallbackWithoutResult() { @Override protected void doInTransactionWithoutResult(TransactionStatus theArg0) { - assertFalse("Search 1 still exists", mySearchEntityDao.findByUuidAndFetchIncludes(searchUuid1).isPresent()); - assertFalse("Search 3 still exists", mySearchEntityDao.findByUuidAndFetchIncludes(searchUuid3).isPresent()); + assertFalse(mySearchEntityDao.findByUuidAndFetchIncludes(searchUuid1).isPresent(), "Search 1 still exists"); + assertFalse(mySearchEntityDao.findByUuidAndFetchIncludes(searchUuid3).isPresent(), "Search 3 still exists"); } }); @@ -373,7 +379,7 @@ public class FhirResourceDaoR4SearchPageExpiryTest extends BaseJpaR4Test { TestUtil.sleepAtLeast(100); } } - assertNotNull("Search " + bundleProvider.getUuid() + " not found on disk after 10 seconds", search); + assertNotNull(search, "Search " + bundleProvider.getUuid() + " not found on disk after 10 seconds"); myDaoConfig.setExpireSearchResults(false); @@ -383,7 +389,7 @@ public class FhirResourceDaoR4SearchPageExpiryTest extends BaseJpaR4Test { newTxTemplate().execute(new TransactionCallbackWithoutResult() { @Override protected void doInTransactionWithoutResult(TransactionStatus theArg0) { - Search search = mySearchEntityDao.findByUuidAndFetchIncludes(bundleProvider.getUuid()).orElseThrow(()->new InternalErrorException("Search doesn't exist")); + Search search = mySearchEntityDao.findByUuidAndFetchIncludes(bundleProvider.getUuid()).orElseThrow(() -> new InternalErrorException("Search doesn't exist")); assertNotNull(search); } }); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchWithElasticSearchIT.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchWithElasticSearchIT.java index fd245f74be3..2139b93b543 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchWithElasticSearchIT.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchWithElasticSearchIT.java @@ -37,15 +37,15 @@ import org.hl7.fhir.r4.model.Meta; import org.hl7.fhir.r4.model.Observation; import org.hl7.fhir.r4.model.Quantity; import org.hl7.fhir.r4.model.ValueSet; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.transaction.PlatformTransactionManager; import java.io.IOException; @@ -53,11 +53,11 @@ import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsInAnyOrder; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = {TestR4ConfigWithElasticSearch.class}) @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS) public class FhirResourceDaoR4SearchWithElasticSearchIT extends BaseJpaTest { @@ -99,7 +99,7 @@ public class FhirResourceDaoR4SearchWithElasticSearchIT extends BaseJpaTest { @Autowired private ITermCodeSystemStorageSvc myTermCodeSystemStorageSvc; - @Before + @BeforeEach public void beforePurgeDatabase() { purgeDatabase(myDaoConfig, mySystemDao, myResourceReindexingSvc, mySearchCoordinatorSvc, mySearchParamRegistry, myBulkDataExportSvc); } @@ -115,7 +115,7 @@ public class FhirResourceDaoR4SearchWithElasticSearchIT extends BaseJpaTest { } @Test - public void testResourceTextSearch() throws InterruptedException { + public void testResourceTextSearch() { Observation obs1 = new Observation(); obs1.getCode().setText("Systolic Blood Pressure"); obs1.setStatus(Observation.ObservationStatus.FINAL); @@ -286,9 +286,5 @@ public class FhirResourceDaoR4SearchWithElasticSearchIT extends BaseJpaTest { } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchWithLuceneDisabledTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchWithLuceneDisabledTest.java index 7e3d68545a2..f53f269a2d8 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchWithLuceneDisabledTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SearchWithLuceneDisabledTest.java @@ -43,16 +43,16 @@ import org.hl7.fhir.r4.model.Meta; import org.hl7.fhir.r4.model.Observation; import org.hl7.fhir.r4.model.Organization; import org.hl7.fhir.r4.model.ValueSet; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.annotation.Transactional; @@ -62,10 +62,10 @@ import java.io.InputStream; import java.nio.charset.StandardCharsets; import java.util.List; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = {TestR4WithLuceneDisabledConfig.class}) @DirtiesContext public class FhirResourceDaoR4SearchWithLuceneDisabledTest extends BaseJpaTest { @@ -142,13 +142,13 @@ public class FhirResourceDaoR4SearchWithLuceneDisabledTest extends BaseJpaTest { @Autowired private ITermReadSvc myTermSvc; - @Before + @BeforeEach @Transactional() public void beforePurgeDatabase() { purgeDatabase(myDaoConfig, mySystemDao, myResourceReindexingSvc, mySearchCoordinatorSvc, mySearchParamRegistry, myBulkDataExportSvc); } - @Before + @BeforeEach public void beforeResetConfig() { myDaoConfig.setHardSearchLimit(1000); myDaoConfig.setHardTagListLimit(1000); @@ -246,7 +246,7 @@ public class FhirResourceDaoR4SearchWithLuceneDisabledTest extends BaseJpaTest { @Test - @Ignore + @Disabled public void testExpandValueSetWithFilter() { CodeSystem cs = new CodeSystem(); cs.setUrl("http://fooCS"); @@ -338,9 +338,5 @@ public class FhirResourceDaoR4SearchWithLuceneDisabledTest extends BaseJpaTest { } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SelectiveUpdateTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SelectiveUpdateTest.java index daa418a4594..c91fe542436 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SelectiveUpdateTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SelectiveUpdateTest.java @@ -8,11 +8,11 @@ import org.hl7.fhir.instance.model.api.IIdType; import org.hl7.fhir.r4.model.Identifier; import org.hl7.fhir.r4.model.Patient; import org.hl7.fhir.r4.model.Resource; -import org.junit.AfterClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; import static org.apache.commons.lang3.StringUtils.isBlank; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public class FhirResourceDaoR4SelectiveUpdateTest extends BaseJpaR4Test { @@ -78,11 +78,6 @@ public class FhirResourceDaoR4SelectiveUpdateTest extends BaseJpaR4Test { } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } - public static Identifier getEuidIdentifier(Patient thePt, boolean theCreate) { return thePt .getIdentifier() diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SortTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SortTest.java index 751483876fa..994b0e7bb68 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SortTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SortTest.java @@ -17,23 +17,24 @@ import org.hl7.fhir.r4.model.DateTimeType; import org.hl7.fhir.r4.model.Enumerations.AdministrativeGender; import org.hl7.fhir.r4.model.Observation; import org.hl7.fhir.r4.model.Patient; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; import java.util.List; import java.util.stream.Collectors; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.containsInAnyOrder; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertEquals; @SuppressWarnings({"unchecked", "deprecation"}) public class FhirResourceDaoR4SortTest extends BaseJpaR4Test { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirResourceDaoR4SortTest.class); - @After + @AfterEach public final void after() { myDaoConfig.setIndexMissingFields(new DaoConfig().getIndexMissingFields()); } @@ -348,8 +349,8 @@ public class FhirResourceDaoR4SortTest extends BaseJpaR4Test { SearchParameterMap map; List ids; - runInTransaction(()->{ - ourLog.info("Dates:\n * {}", myResourceIndexedSearchParamDateDao.findAll().stream().map(t->t.toString()).collect(Collectors.joining("\n * "))); + runInTransaction(() -> { + ourLog.info("Dates:\n * {}", myResourceIndexedSearchParamDateDao.findAll().stream().map(t -> t.toString()).collect(Collectors.joining("\n * "))); }); map = new SearchParameterMap(); @@ -364,9 +365,4 @@ public class FhirResourceDaoR4SortTest extends BaseJpaR4Test { } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } - } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SourceTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SourceTest.java index 5904c00a8ed..206ff32b7fa 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SourceTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4SourceTest.java @@ -13,27 +13,27 @@ import ca.uhn.fhir.rest.server.exceptions.ResourceVersionConflictException; import org.apache.commons.text.RandomStringGenerator; import org.hl7.fhir.instance.model.api.IIdType; import org.hl7.fhir.r4.model.Patient; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.matchesPattern; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Mockito.when; @SuppressWarnings({"Duplicates"}) public class FhirResourceDaoR4SourceTest extends BaseJpaR4Test { - @After + @AfterEach public final void after() { when(mySrd.getRequestId()).thenReturn(null); myDaoConfig.setStoreMetaSourceInformation(new DaoConfig().getStoreMetaSourceInformation()); } - @Before + @BeforeEach public void before() { myDaoConfig.setStoreMetaSourceInformation(DaoConfig.StoreMetaSourceInformationEnum.SOURCE_URI_AND_REQUEST_ID); } @@ -218,11 +218,6 @@ public class FhirResourceDaoR4SourceTest extends BaseJpaR4Test { } } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } - public static void assertConflictException(String theResourceType, ResourceVersionConflictException e) { assertThat(e.getMessage(), matchesPattern( "Unable to delete [a-zA-Z]+/[0-9]+ because at least one resource has a reference to this resource. First reference found was resource " + theResourceType + "/[0-9]+ in path [a-zA-Z]+.[a-zA-Z]+")); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4StructureDefinitionTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4StructureDefinitionTest.java index 4636329ae4f..d2fb98206a0 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4StructureDefinitionTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4StructureDefinitionTest.java @@ -6,20 +6,20 @@ import ca.uhn.fhir.context.support.DefaultProfileValidationSupport; import org.hl7.fhir.common.hapi.validation.support.SnapshotGeneratingValidationSupport; import org.hl7.fhir.common.hapi.validation.support.ValidationSupportChain; import org.hl7.fhir.r4.model.StructureDefinition; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; import java.io.IOException; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; @SuppressWarnings({"unchecked", "deprecation"}) public class FhirResourceDaoR4StructureDefinitionTest extends BaseJpaR4Test { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirResourceDaoR4StructureDefinitionTest.class); - @After + @AfterEach public final void after() { } @@ -47,9 +47,5 @@ public class FhirResourceDaoR4StructureDefinitionTest extends BaseJpaR4Test { } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4TerminologyElasticsearchIT.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4TerminologyElasticsearchIT.java index 57fc6b37126..e5c298a8011 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4TerminologyElasticsearchIT.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4TerminologyElasticsearchIT.java @@ -26,25 +26,25 @@ import org.hl7.fhir.r4.model.CodeableConcept; import org.hl7.fhir.r4.model.Coding; import org.hl7.fhir.r4.model.ValueSet; import org.hl7.fhir.r4.model.ValueSet.ConceptReferenceComponent; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Answers; import org.mockito.Mock; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.transaction.PlatformTransactionManager; import java.util.Set; import java.util.stream.Collectors; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsInAnyOrder; -import static org.junit.Assert.assertThat; -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = {TestR4ConfigWithElasticSearch.class}) public class FhirResourceDaoR4TerminologyElasticsearchIT extends BaseJpaTest { @@ -64,11 +64,12 @@ public class FhirResourceDaoR4TerminologyElasticsearchIT extends BaseJpaTest { @Autowired @Qualifier("myValueSetDaoR4") protected IFhirResourceDaoValueSet myValueSetDao; + @Mock(answer = Answers.RETURNS_DEEP_STUBS) + protected ServletRequestDetails mySrd; @Autowired FhirContext myFhirContext; @Autowired PlatformTransactionManager myTxManager; - @Autowired private IFhirSystemDao mySystemDao; @Autowired @@ -80,9 +81,6 @@ public class FhirResourceDaoR4TerminologyElasticsearchIT extends BaseJpaTest { @Autowired private IBulkDataExportSvc myBulkDataExportSvc; - @Mock(answer = Answers.RETURNS_DEEP_STUBS) - protected ServletRequestDetails mySrd; - @Test public void testExpandWithIncludeContainingDashesInInclude() { CodeSystem codeSystem = new CodeSystem(); @@ -111,7 +109,7 @@ public class FhirResourceDaoR4TerminologyElasticsearchIT extends BaseJpaTest { concept = new TermConcept(cs, "LA9999-7"); cs.getConcepts().add(concept); - myTermCodeSystemStorageSvc.storeNewCodeSystemVersion(new ResourcePersistentId(table.getId()), URL_MY_CODE_SYSTEM, "SYSTEM NAME", "SYSTEM VERSION" , cs, table); + myTermCodeSystemStorageSvc.storeNewCodeSystemVersion(new ResourcePersistentId(table.getId()), URL_MY_CODE_SYSTEM, "SYSTEM NAME", "SYSTEM VERSION", cs, table); ValueSet valueSet = new ValueSet(); valueSet.setUrl(URL_MY_VALUE_SET); @@ -144,12 +142,12 @@ public class FhirResourceDaoR4TerminologyElasticsearchIT extends BaseJpaTest { return myTxManager; } - @After + @AfterEach public void afterPurgeDatabase() { purgeDatabase(myDaoConfig, mySystemDao, myResourceReindexingSvc, mySearchCoordinatorSvc, mySearchParamRegistry, myBulkDataExportSvc); } - @AfterClass + @AfterAll public static void afterClassClearContext() { TestUtil.clearAllStaticFieldsForUnitTest(); } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4TerminologyTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4TerminologyTest.java index 9756a8bc560..b73ced860d1 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4TerminologyTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4TerminologyTest.java @@ -36,11 +36,11 @@ import org.hl7.fhir.r4.model.ValueSet.ConceptSetComponent; import org.hl7.fhir.r4.model.ValueSet.FilterOperator; import org.hl7.fhir.r4.model.ValueSet.ValueSetComposeComponent; import org.hl7.fhir.r4.model.ValueSet.ValueSetExpansionContainsComponent; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; import java.util.ArrayList; import java.util.Date; @@ -48,13 +48,13 @@ import java.util.List; import java.util.Set; import java.util.stream.Collectors; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.containsStringIgnoringCase; import static org.hamcrest.Matchers.empty; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; @SuppressWarnings("Duplicates") public class FhirResourceDaoR4TerminologyTest extends BaseJpaR4Test { @@ -64,14 +64,14 @@ public class FhirResourceDaoR4TerminologyTest extends BaseJpaR4Test { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirResourceDaoR4TerminologyTest.class); - @After + @AfterEach public void after() { myDaoConfig.setDeferIndexingForCodesystemsOfSize(new DaoConfig().getDeferIndexingForCodesystemsOfSize()); TermReindexingSvcImpl.setForceSaveDeferredAlwaysForUnitTest(false); } - @Before + @BeforeEach public void before() { myDaoConfig.setMaximumExpansionSize(5000); myCachingValidationSupport.invalidateCaches(); @@ -285,7 +285,7 @@ public class FhirResourceDaoR4TerminologyTest extends BaseJpaR4Test { runInTransaction(() -> { List concepts = myTermConceptDao.findAll(); for (TermConcept next : concepts) { - assertTrue(new InstantType(new Date(next.getUpdated().getTime())) + " <= " + new InstantType(new Date(start)), next.getUpdated().getTime() > start); + assertTrue(next.getUpdated().getTime() > start, new InstantType(new Date(next.getUpdated().getTime())) + " <= " + new InstantType(new Date(start))); } }); } @@ -585,7 +585,7 @@ public class FhirResourceDaoR4TerminologyTest extends BaseJpaR4Test { } @Test - @Ignore + @Disabled public void testExpandWithNoResultsInLocalValueSet1() { createLocalCsAndVs(); @@ -621,7 +621,7 @@ public class FhirResourceDaoR4TerminologyTest extends BaseJpaR4Test { } // TODO: get this working - @Ignore + @Disabled @Test public void testExpandWithOpEquals() { @@ -836,7 +836,7 @@ public class FhirResourceDaoR4TerminologyTest extends BaseJpaR4Test { * Can't currently abort costly */ @Test - @Ignore + @Disabled public void testRefuseCostlyExpansionFhirCodesystem() { createLocalCsAndVs(); myDaoConfig.setMaximumExpansionSize(1); @@ -1271,7 +1271,7 @@ public class FhirResourceDaoR4TerminologyTest extends BaseJpaR4Test { * Todo: not yet implemented */ @Test - @Ignore + @Disabled public void testSearchCodeNotInBuiltInValueSet() { AllergyIntolerance ai1 = new AllergyIntolerance(); ai1.getClinicalStatus().addCoding().setSystem("http://terminology.hl7.org/CodeSystem/allergyintolerance-clinical").setCode("active"); @@ -1314,9 +1314,5 @@ public class FhirResourceDaoR4TerminologyTest extends BaseJpaR4Test { return retVal; } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4Test.java index 862ad30b4a5..4f156dcda3c 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4Test.java @@ -6,7 +6,6 @@ import ca.uhn.fhir.jpa.dao.BaseHapiFhirDao; import ca.uhn.fhir.jpa.dao.BaseHapiFhirResourceDao; import ca.uhn.fhir.jpa.dao.JpaResourceDao; import ca.uhn.fhir.jpa.entity.Search; -import ca.uhn.fhir.rest.api.server.storage.ResourcePersistentId; import ca.uhn.fhir.jpa.model.entity.ResourceEncodingEnum; import ca.uhn.fhir.jpa.model.entity.ResourceHistoryTable; import ca.uhn.fhir.jpa.model.entity.ResourceIndexedSearchParamString; @@ -26,6 +25,7 @@ import ca.uhn.fhir.rest.api.MethodOutcome; import ca.uhn.fhir.rest.api.SortOrderEnum; import ca.uhn.fhir.rest.api.SortSpec; import ca.uhn.fhir.rest.api.server.IBundleProvider; +import ca.uhn.fhir.rest.api.server.storage.ResourcePersistentId; import ca.uhn.fhir.rest.param.DateParam; import ca.uhn.fhir.rest.param.DateRangeParam; import ca.uhn.fhir.rest.param.ParamPrefixEnum; @@ -98,11 +98,11 @@ import org.hl7.fhir.r4.model.StringType; import org.hl7.fhir.r4.model.StructureDefinition; import org.hl7.fhir.r4.model.Timing; import org.hl7.fhir.r4.model.UriType; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.springframework.transaction.TransactionDefinition; import org.springframework.transaction.TransactionStatus; import org.springframework.transaction.support.TransactionCallbackWithoutResult; @@ -123,6 +123,7 @@ import java.util.concurrent.Executors; import java.util.concurrent.Future; import static org.apache.commons.lang3.StringUtils.defaultString; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.containsString; @@ -132,14 +133,13 @@ import static org.hamcrest.Matchers.hasItem; import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.matchesPattern; import static org.hamcrest.Matchers.not; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.Mockito.reset; @SuppressWarnings({"unchecked", "deprecation", "Duplicates"}) @@ -147,7 +147,7 @@ public class FhirResourceDaoR4Test extends BaseJpaR4Test { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirResourceDaoR4Test.class); - @After + @AfterEach public final void after() { myDaoConfig.setAllowExternalReferences(new DaoConfig().isAllowExternalReferences()); myDaoConfig.setTreatReferencesAsLogical(new DaoConfig().getTreatReferencesAsLogical()); @@ -156,7 +156,7 @@ public class FhirResourceDaoR4Test extends BaseJpaR4Test { myDaoConfig.setIndexMissingFields(new DaoConfig().getIndexMissingFields()); } - @Before + @BeforeEach public void before() { myInterceptorRegistry.registerInterceptor(myInterceptor); } @@ -186,13 +186,13 @@ public class FhirResourceDaoR4Test extends BaseJpaR4Test { } } - @Before + @BeforeEach public void beforeDisableResultReuse() { myDaoConfig.setReuseCachedSearchResultsForMillis(null); } private List extractNames(IBundleProvider theSearch) { - ArrayList retVal = new ArrayList(); + ArrayList retVal = new ArrayList<>(); for (IBaseResource next : theSearch.getResources(0, theSearch.size())) { Patient nextPt = (Patient) next; retVal.add(nextPt.getName().get(0).getNameAsSingleString()); @@ -651,7 +651,7 @@ public class FhirResourceDaoR4Test extends BaseJpaR4Test { } @Test - @Ignore + @Disabled public void testCreateBuiltInProfiles() throws Exception { org.hl7.fhir.r4.model.Bundle bundle; String name = "profiles-resources"; @@ -3027,7 +3027,7 @@ public class FhirResourceDaoR4Test extends BaseJpaR4Test { } @Test - @Ignore + @Disabled public void testSortByEncounterLength() { String methodName = "testSortByNumber"; @@ -3200,7 +3200,7 @@ public class FhirResourceDaoR4Test extends BaseJpaR4Test { } @Test - @Ignore + @Disabled public void testSortByQuantity() { Observation res; @@ -3468,7 +3468,7 @@ public class FhirResourceDaoR4Test extends BaseJpaR4Test { } @Test - @Ignore + @Disabled public void testSortByUri() { ConceptMap res = new ConceptMap(); res.addGroup().setSource("http://foo2"); @@ -3677,15 +3677,15 @@ public class FhirResourceDaoR4Test extends BaseJpaR4Test { published = (ArrayList) retrieved.getMeta().getTag(); sort(published); assertEquals(3, published.size()); - assertEquals(published.toString(), "Dog", published.get(0).getCode()); - assertEquals(published.toString(), "Puppies", published.get(0).getDisplay()); - assertEquals(published.toString(), null, published.get(0).getSystem()); - assertEquals(published.toString(), "Cat", published.get(1).getCode()); - assertEquals(published.toString(), "Kittens", published.get(1).getDisplay()); - assertEquals(published.toString(), "http://foo", published.get(1).getSystem()); - assertEquals(published.toString(), "Cow", published.get(2).getCode()); - assertEquals(published.toString(), "Calves", published.get(2).getDisplay()); - assertEquals(published.toString(), "http://foo", published.get(2).getSystem()); + assertEquals( "Dog", published.get(0).getCode()); + assertEquals( "Puppies", published.get(0).getDisplay()); + assertEquals( null, published.get(0).getSystem()); + assertEquals( "Cat", published.get(1).getCode()); + assertEquals( "Kittens", published.get(1).getDisplay()); + assertEquals( "http://foo", published.get(1).getSystem()); + assertEquals( "Cow", published.get(2).getCode()); + assertEquals( "Calves", published.get(2).getDisplay()); + assertEquals( "http://foo", published.get(2).getSystem()); secLabels = retrieved.getMeta().getSecurity(); sortCodings(secLabels); @@ -3844,11 +3844,6 @@ public class FhirResourceDaoR4Test extends BaseJpaR4Test { assertNotEquals(uuid, results.getUuid()); } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } - public static void assertConflictException(String theResourceType, ResourceVersionConflictException e) { assertThat(e.getMessage(), matchesPattern( "Unable to delete [a-zA-Z]+/[0-9]+ because at least one resource has a reference to this resource. First reference found was resource " + theResourceType + "/[0-9]+ in path [a-zA-Z]+.[a-zA-Z]+")); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4UniqueSearchParamTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4UniqueSearchParamTest.java index 8f0bf0bf99b..f44c2653b95 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4UniqueSearchParamTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4UniqueSearchParamTest.java @@ -26,10 +26,10 @@ import ca.uhn.fhir.util.TestUtil; import org.hl7.fhir.instance.model.api.IIdType; import org.hl7.fhir.r4.model.*; import org.hl7.fhir.r4.model.Enumerations.PublicationStatus; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentMatchers; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.transaction.TransactionStatus; @@ -44,6 +44,7 @@ import java.util.UUID; import java.util.stream.Collectors; import static ca.uhn.fhir.jpa.dao.BaseHapiFhirDao.INDEX_STATUS_INDEXED; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.either; @@ -51,10 +52,9 @@ import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.stringContainsInOrder; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -67,7 +67,7 @@ public class FhirResourceDaoR4UniqueSearchParamTest extends BaseJpaR4Test { private IInterceptorBroadcaster myInterceptorBroadcaster; private List myMessages = new ArrayList<>(); - @After + @AfterEach public void after() throws Exception { myModelConfig.setDefaultSearchParamsCanBeOverridden(new ModelConfig().isDefaultSearchParamsCanBeOverridden()); myDaoConfig.setUniqueIndexesCheckedBeforeSave(new DaoConfig().isUniqueIndexesCheckedBeforeSave()); @@ -79,7 +79,7 @@ public class FhirResourceDaoR4UniqueSearchParamTest extends BaseJpaR4Test { svc.initExecutor(); } - @Before + @BeforeEach public void before() { myModelConfig.setDefaultSearchParamsCanBeOverridden(true); myDaoConfig.setSchedulingDisabled(true); @@ -702,7 +702,7 @@ public class FhirResourceDaoR4UniqueSearchParamTest extends BaseJpaR4Test { runInTransaction(() -> { List uniques = myResourceIndexedCompositeStringUniqueDao.findAll(); - assertEquals(uniques.toString(), 1, uniques.size()); + assertEquals(1, uniques.size(), uniques.toString()); assertThat(uniques.get(0).getResource().getIdDt().toUnqualifiedVersionless().getValue(), either(equalTo("Observation/" + id2.getIdPart())).or(equalTo("Observation/" + id3.getIdPart()))); assertEquals("Observation?code=foo%7Cbar&date=2011-01-01&subject=Patient%2F" + id1.getIdPart(), uniques.get(0).getIndexString()); @@ -719,7 +719,7 @@ public class FhirResourceDaoR4UniqueSearchParamTest extends BaseJpaR4Test { runInTransaction(() -> { List uniques = myResourceIndexedCompositeStringUniqueDao.findAll(); - assertEquals(uniques.toString(), 1, uniques.size()); + assertEquals(1, uniques.size(), uniques.toString()); assertThat(uniques.get(0).getResource().getIdDt().toUnqualifiedVersionless().getValue(), either(equalTo("Observation/" + id2.getIdPart())).or(equalTo("Observation/" + id3.getIdPart()))); assertEquals("Observation?code=foo%7Cbar&date=2011-01-01&subject=Patient%2F" + id1.getIdPart(), uniques.get(0).getIndexString()); }); @@ -822,7 +822,7 @@ public class FhirResourceDaoR4UniqueSearchParamTest extends BaseJpaR4Test { List tables = myResourceTableDao.findAll(); String resourceIds = tables.stream().map(t -> t.getIdDt().getValue()).collect(Collectors.joining(", ")); // 1 patient, 1 coverage, 3 search parameters - assertEquals(resourceIds, 5, tables.size()); + assertEquals(5, tables.size(), resourceIds); for (int i = 0; i < tables.size(); i++) { assertEquals(INDEX_STATUS_INDEXED, tables.get(i).getIndexStatus().intValue()); } @@ -831,7 +831,7 @@ public class FhirResourceDaoR4UniqueSearchParamTest extends BaseJpaR4Test { runInTransaction(() -> { List uniques = myResourceIndexedCompositeStringUniqueDao.findAll(); ourLog.info("** Uniques: {}", uniques); - assertEquals(uniques.toString(), 1, uniques.size()); + assertEquals(1, uniques.size(), uniques.toString()); assertEquals("Coverage/" + id3.getIdPart(), uniques.get(0).getResource().getIdDt().toUnqualifiedVersionless().getValue()); assertEquals("Coverage?beneficiary=Patient%2F" + id2.getIdPart() + "&identifier=urn%3Afoo%3Abar%7C123", uniques.get(0).getIndexString()); }); @@ -999,7 +999,7 @@ public class FhirResourceDaoR4UniqueSearchParamTest extends BaseJpaR4Test { @Override protected void doInTransactionWithoutResult(@Nonnull TransactionStatus status) { List all = myResourceIndexedCompositeStringUniqueDao.findAll(); - assertEquals(all.toString(), 1, all.size()); + assertEquals(1, all.size(), all.toString()); } }); @@ -1108,7 +1108,7 @@ public class FhirResourceDaoR4UniqueSearchParamTest extends BaseJpaR4Test { IIdType id1 = myPatientDao.create(pt1).getId().toUnqualifiedVersionless(); List uniques = myResourceIndexedCompositeStringUniqueDao.findAll(); - assertEquals(uniques.toString(), 1, uniques.size()); + assertEquals(1, uniques.size(), uniques.toString()); assertEquals("Patient/" + id1.getIdPart(), uniques.get(0).getResource().getIdDt().toUnqualifiedVersionless().getValue()); assertEquals("Patient?birthdate=2011-01-01&gender=http%3A%2F%2Fhl7.org%2Ffhir%2Fadministrative-gender%7Cmale", uniques.get(0).getIndexString()); } @@ -1119,7 +1119,7 @@ public class FhirResourceDaoR4UniqueSearchParamTest extends BaseJpaR4Test { List uniques; uniques = myResourceIndexedCompositeStringUniqueDao.findAll(); - assertEquals(uniques.toString(), 0, uniques.size()); + assertEquals(0, uniques.size(), uniques.toString()); Patient pt1 = new Patient(); pt1.setActive(true); @@ -1138,7 +1138,7 @@ public class FhirResourceDaoR4UniqueSearchParamTest extends BaseJpaR4Test { ourLog.info("ID1: {} - ID2: {} - ID3: {}", id1, id2, id3); uniques = myResourceIndexedCompositeStringUniqueDao.findAll(); - assertEquals(uniques.toString(), 1, uniques.size()); + assertEquals(1, uniques.size(), uniques.toString()); assertEquals("Observation/" + id2.getIdPart(), uniques.get(0).getResource().getIdDt().toUnqualifiedVersionless().getValue()); assertEquals("Observation?code=foo%7Cbar&date=2011-01-01&subject=Patient%2F" + id1.getIdPart(), uniques.get(0).getIndexString()); } @@ -1347,19 +1347,19 @@ public class FhirResourceDaoR4UniqueSearchParamTest extends BaseJpaR4Test { pt.setGender(Enumerations.AdministrativeGender.MALE); myPatientDao.create(pt).getId().toUnqualifiedVersionless(); uniques = myResourceIndexedCompositeStringUniqueDao.findAll(); - assertEquals(uniques.toString(), 0, uniques.size()); + assertEquals(0, uniques.size(), uniques.toString()); pt = new Patient(); myPatientDao.create(pt).getId().toUnqualifiedVersionless(); uniques = myResourceIndexedCompositeStringUniqueDao.findAll(); - assertEquals(uniques.toString(), 0, uniques.size()); + assertEquals(0, uniques.size(), uniques.toString()); pt = new Patient(); pt.setBirthDateElement(new DateType()); pt.setGender(Enumerations.AdministrativeGender.MALE); myPatientDao.create(pt).getId().toUnqualifiedVersionless(); uniques = myResourceIndexedCompositeStringUniqueDao.findAll(); - assertEquals(uniques.toString(), 0, uniques.size()); + assertEquals(0, uniques.size(), uniques.toString()); } @@ -1379,7 +1379,7 @@ public class FhirResourceDaoR4UniqueSearchParamTest extends BaseJpaR4Test { pt.setManagingOrganization(new Reference("Organization/ORG")); myPatientDao.create(pt).getId().toUnqualifiedVersionless(); uniques = myResourceIndexedCompositeStringUniqueDao.findAll(); - assertEquals(uniques.toString(), 0, uniques.size()); + assertEquals(0, uniques.size(), uniques.toString()); pt = new Patient(); pt.addName() @@ -1389,13 +1389,13 @@ public class FhirResourceDaoR4UniqueSearchParamTest extends BaseJpaR4Test { .addGiven("GIVEN2"); // GIVEN2 happens twice myPatientDao.create(pt).getId().toUnqualifiedVersionless(); uniques = myResourceIndexedCompositeStringUniqueDao.findAll(); - assertEquals(uniques.toString(), 0, uniques.size()); + assertEquals(0, uniques.size(), uniques.toString()); pt = new Patient(); pt.setActive(true); myPatientDao.create(pt).getId().toUnqualifiedVersionless(); uniques = myResourceIndexedCompositeStringUniqueDao.findAll(); - assertEquals(uniques.toString(), 0, uniques.size()); + assertEquals(0, uniques.size(), uniques.toString()); } @Test @@ -1421,7 +1421,7 @@ public class FhirResourceDaoR4UniqueSearchParamTest extends BaseJpaR4Test { myResourceReindexingSvc.forceReindexingPass(); List uniques = myResourceIndexedCompositeStringUniqueDao.findAll(); - assertEquals(uniques.toString(), 1, uniques.size()); + assertEquals(1, uniques.size(), uniques.toString()); assertEquals("Observation/" + id2.getIdPart(), uniques.get(0).getResource().getIdDt().toUnqualifiedVersionless().getValue()); assertEquals("Observation?code=foo%7Cbar&date=2011-01-01&subject=Patient%2F" + id1.getIdPart(), uniques.get(0).getIndexString()); @@ -1432,7 +1432,7 @@ public class FhirResourceDaoR4UniqueSearchParamTest extends BaseJpaR4Test { myResourceReindexingSvc.forceReindexingPass(); uniques = myResourceIndexedCompositeStringUniqueDao.findAll(); - assertEquals(uniques.toString(), 1, uniques.size()); + assertEquals(1, uniques.size(), uniques.toString()); assertEquals("Observation/" + id2.getIdPart(), uniques.get(0).getResource().getIdDt().toUnqualifiedVersionless().getValue()); assertEquals("Observation?code=foo%7Cbar&date=2011-01-01&subject=Patient%2F" + id1.getIdPart(), uniques.get(0).getIndexString()); @@ -1525,10 +1525,5 @@ public class FhirResourceDaoR4UniqueSearchParamTest extends BaseJpaR4Test { } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } - } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4UpdateTagSnapshotTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4UpdateTagSnapshotTest.java index 78cc03b3e92..52fed86ab43 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4UpdateTagSnapshotTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4UpdateTagSnapshotTest.java @@ -6,10 +6,11 @@ import com.google.common.collect.Lists; import org.hamcrest.Matchers; import org.hl7.fhir.r4.model.IdType; import org.hl7.fhir.r4.model.Patient; -import org.junit.AfterClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.when; @@ -135,9 +136,5 @@ public class FhirResourceDaoR4UpdateTagSnapshotTest extends BaseJpaR4Test { assertEquals("1", p.getIdElement().getVersionIdPart()); } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4UpdateTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4UpdateTest.java index 26685134fe2..677cb72f763 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4UpdateTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4UpdateTest.java @@ -25,11 +25,11 @@ import org.hl7.fhir.r4.model.Meta; import org.hl7.fhir.r4.model.Organization; import org.hl7.fhir.r4.model.Patient; import org.hl7.fhir.r4.model.Resource; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; import java.util.ArrayList; import java.util.Date; @@ -39,25 +39,25 @@ import java.util.Set; import java.util.TimeZone; import java.util.UUID; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.endsWith; import static org.hamcrest.Matchers.matchesPattern; import static org.hamcrest.Matchers.not; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.Mockito.reset; public class FhirResourceDaoR4UpdateTest extends BaseJpaR4Test { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirResourceDaoR4UpdateTest.class); - @After + @AfterEach public void afterResetDao() { myDaoConfig.setResourceMetaCountHardLimit(new DaoConfig().getResourceMetaCountHardLimit()); myDaoConfig.setIndexMissingFields(new DaoConfig().getIndexMissingFields()); @@ -65,7 +65,7 @@ public class FhirResourceDaoR4UpdateTest extends BaseJpaR4Test { myDaoConfig.setResourceClientIdStrategy(new DaoConfig().getResourceClientIdStrategy()); } - @Before + @BeforeEach public void before() { myInterceptorRegistry.registerInterceptor(myInterceptor); } @@ -596,7 +596,7 @@ public class FhirResourceDaoR4UpdateTest extends BaseJpaR4Test { } @Test - @Ignore + @Disabled public void testUpdateIgnoresIdenticalVersions() { String methodName = "testUpdateIgnoresIdenticalVersions"; @@ -1004,9 +1004,5 @@ public class FhirResourceDaoR4UpdateTest extends BaseJpaR4Test { } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4ValidateTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4ValidateTest.java index 770d67049f2..d8de50da72a 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4ValidateTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4ValidateTest.java @@ -21,7 +21,6 @@ import ca.uhn.fhir.rest.server.exceptions.ResourceVersionConflictException; import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; import ca.uhn.fhir.util.OperationOutcomeUtil; import ca.uhn.fhir.util.StopWatch; -import ca.uhn.fhir.util.TestUtil; import ca.uhn.fhir.validation.IValidatorModule; import org.apache.commons.io.IOUtils; import org.hl7.fhir.common.hapi.validation.validator.FhirInstanceValidator; @@ -53,10 +52,9 @@ import org.hl7.fhir.r4.model.StringType; import org.hl7.fhir.r4.model.StructureDefinition; import org.hl7.fhir.r4.model.ValueSet; import org.hl7.fhir.r5.utils.IResourceValidator; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.util.AopTestUtils; import org.springframework.transaction.PlatformTransactionManager; @@ -66,12 +64,12 @@ import java.nio.charset.StandardCharsets; import java.util.Collections; import static org.awaitility.Awaitility.await; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.not; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -139,38 +137,38 @@ public class FhirResourceDaoR4ValidateTest extends BaseJpaR4Test { obs.getText().setStatus(Narrative.NarrativeStatus.GENERATED); obs.getCode().getCodingFirstRep().setSystem("http://loinc.org").setCode("CODE3").setDisplay("Display 3"); oo = validateAndReturnOutcome(obs); - assertEquals(encode(oo), "No issues detected during validation", oo.getIssueFirstRep().getDiagnostics()); + assertEquals("No issues detected during validation", oo.getIssueFirstRep().getDiagnostics(), encode(oo)); // Invalid code obs.getText().setStatus(Narrative.NarrativeStatus.GENERATED); obs.getCode().getCodingFirstRep().setSystem("http://loinc.org").setCode("non-existing-code").setDisplay("Display 3"); oo = validateAndReturnOutcome(obs); - assertEquals(encode(oo), "None of the codes provided are in the value set http://example.com/fhir/ValueSet/observation-vitalsignresult (http://example.com/fhir/ValueSet/observation-vitalsignresult), and a code from this value set is required) (codes = http://loinc.org#non-existing-code)", oo.getIssueFirstRep().getDiagnostics()); + assertEquals("None of the codes provided are in the value set http://example.com/fhir/ValueSet/observation-vitalsignresult (http://example.com/fhir/ValueSet/observation-vitalsignresult), and a code from this value set is required) (codes = http://loinc.org#non-existing-code)", oo.getIssueFirstRep().getDiagnostics(), encode(oo)); // Valid code with no system obs.getText().setStatus(Narrative.NarrativeStatus.GENERATED); obs.getCode().getCodingFirstRep().setSystem(null).setCode("CODE3").setDisplay("Display 3"); oo = validateAndReturnOutcome(obs); - assertEquals(encode(oo), "None of the codes provided are in the value set http://example.com/fhir/ValueSet/observation-vitalsignresult (http://example.com/fhir/ValueSet/observation-vitalsignresult), and a code from this value set is required) (codes = null#CODE3)", oo.getIssueFirstRep().getDiagnostics()); + assertEquals("None of the codes provided are in the value set http://example.com/fhir/ValueSet/observation-vitalsignresult (http://example.com/fhir/ValueSet/observation-vitalsignresult), and a code from this value set is required) (codes = null#CODE3)", oo.getIssueFirstRep().getDiagnostics(), encode(oo)); // Valid code with wrong system obs.getText().setStatus(Narrative.NarrativeStatus.GENERATED); obs.getCode().getCodingFirstRep().setSystem("http://foo").setCode("CODE3").setDisplay("Display 3"); oo = validateAndReturnOutcome(obs); - assertEquals(encode(oo), "None of the codes provided are in the value set http://example.com/fhir/ValueSet/observation-vitalsignresult (http://example.com/fhir/ValueSet/observation-vitalsignresult), and a code from this value set is required) (codes = http://foo#CODE3)", oo.getIssueFirstRep().getDiagnostics()); + assertEquals("None of the codes provided are in the value set http://example.com/fhir/ValueSet/observation-vitalsignresult (http://example.com/fhir/ValueSet/observation-vitalsignresult), and a code from this value set is required) (codes = http://foo#CODE3)", oo.getIssueFirstRep().getDiagnostics(), encode(oo)); // Code that exists but isn't in the valueset obs.getText().setStatus(Narrative.NarrativeStatus.GENERATED); obs.getCode().getCodingFirstRep().setSystem("http://terminology.hl7.org/CodeSystem/observation-category").setCode("vital-signs").setDisplay("Display 3"); oo = validateAndReturnOutcome(obs); - assertEquals(encode(oo), "None of the codes provided are in the value set http://example.com/fhir/ValueSet/observation-vitalsignresult (http://example.com/fhir/ValueSet/observation-vitalsignresult), and a code from this value set is required) (codes = http://terminology.hl7.org/CodeSystem/observation-category#vital-signs)", oo.getIssueFirstRep().getDiagnostics()); + assertEquals("None of the codes provided are in the value set http://example.com/fhir/ValueSet/observation-vitalsignresult (http://example.com/fhir/ValueSet/observation-vitalsignresult), and a code from this value set is required) (codes = http://terminology.hl7.org/CodeSystem/observation-category#vital-signs)", oo.getIssueFirstRep().getDiagnostics(), encode(oo)); // Invalid code in built-in VS/CS obs.getText().setStatus(Narrative.NarrativeStatus.GENERATED); obs.getCode().getCodingFirstRep().setSystem("http://loinc.org").setCode("CODE3").setDisplay("Display 3"); obs.getCategoryFirstRep().addCoding().setSystem("http://terminology.hl7.org/CodeSystem/observation-category").setCode("FOO"); oo = validateAndReturnOutcome(obs); - assertEquals(encode(oo), "Unknown code 'http://terminology.hl7.org/CodeSystem/observation-category#FOO'", oo.getIssueFirstRep().getDiagnostics()); + assertEquals("Unknown code 'http://terminology.hl7.org/CodeSystem/observation-category#FOO'", oo.getIssueFirstRep().getDiagnostics(), encode(oo)); // Make sure we're caching the validations as opposed to hitting the DB every time myCaptureQueriesListener.clear(); @@ -180,14 +178,14 @@ public class FhirResourceDaoR4ValidateTest extends BaseJpaR4Test { obs.getCategoryFirstRep().addCoding().setSystem("http://terminology.hl7.org/CodeSystem/observation-category").setCode("vital-signs"); obs.getCode().getCodingFirstRep().setSystem("http://loinc.org").setCode("CODE4").setDisplay("Display 3"); oo = validateAndReturnOutcome(obs); - assertEquals(encode(oo), "No issues detected during validation", oo.getIssueFirstRep().getDiagnostics()); + assertEquals("No issues detected during validation", oo.getIssueFirstRep().getDiagnostics(), encode(oo)); myCaptureQueriesListener.logSelectQueriesForCurrentThread(); myCaptureQueriesListener.clear(); obs.getText().setStatus(Narrative.NarrativeStatus.GENERATED); obs.getCode().getCodingFirstRep().setSystem("http://loinc.org").setCode("CODE4").setDisplay("Display 3"); oo = validateAndReturnOutcome(obs); - assertEquals(encode(oo), "No issues detected during validation", oo.getIssueFirstRep().getDiagnostics()); + assertEquals("No issues detected during validation", oo.getIssueFirstRep().getDiagnostics(), encode(oo)); myCaptureQueriesListener.logSelectQueriesForCurrentThread(); @@ -241,19 +239,19 @@ public class FhirResourceDaoR4ValidateTest extends BaseJpaR4Test { obs.setSubject(new Reference("Group/123")); OperationOutcome oo = validateAndReturnOutcome(obs); ourLog.info(myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(oo)); - assertEquals(encode(oo), "Unable to resolve resource \"Group/123\"", oo.getIssueFirstRep().getDiagnostics()); + assertEquals("Unable to resolve resource \"Group/123\"", oo.getIssueFirstRep().getDiagnostics(), encode(oo)); // Target of wrong type obs.setSubject(new Reference("Group/ABC")); oo = validateAndReturnOutcome(obs); ourLog.info(myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(oo)); - assertEquals(encode(oo), "Invalid Resource target type. Found Group, but expected one of ([Patient])", oo.getIssueFirstRep().getDiagnostics()); + assertEquals("Invalid Resource target type. Found Group, but expected one of ([Patient])", oo.getIssueFirstRep().getDiagnostics(), encode(oo)); // Target of right type obs.setSubject(new Reference("Patient/DEF")); oo = validateAndReturnOutcome(obs); ourLog.info(myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(oo)); - assertEquals(encode(oo), "No issues detected during validation", oo.getIssueFirstRep().getDiagnostics()); + assertEquals("No issues detected during validation", oo.getIssueFirstRep().getDiagnostics(), encode(oo)); } @@ -305,19 +303,19 @@ public class FhirResourceDaoR4ValidateTest extends BaseJpaR4Test { obs.setSubject(new Reference("Group/123")); OperationOutcome oo = validateAndReturnOutcome(obs); ourLog.info(myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(oo)); - assertEquals(encode(oo), "Unable to resolve resource \"Group/123\"", oo.getIssueFirstRep().getDiagnostics()); + assertEquals("Unable to resolve resource \"Group/123\"", oo.getIssueFirstRep().getDiagnostics(), encode(oo)); // Target of wrong type obs.setSubject(new Reference("Group/ABC")); oo = validateAndReturnOutcome(obs); ourLog.info(myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(oo)); - assertEquals(encode(oo), "Unable to find matching profile for Group/ABC (by type) among choices: ; [CanonicalType[http://hl7.org/fhir/StructureDefinition/Patient]]", oo.getIssueFirstRep().getDiagnostics()); + assertEquals("Unable to find matching profile for Group/ABC (by type) among choices: ; [CanonicalType[http://hl7.org/fhir/StructureDefinition/Patient]]", oo.getIssueFirstRep().getDiagnostics(), encode(oo)); // Target of right type obs.setSubject(new Reference("Patient/DEF")); oo = validateAndReturnOutcome(obs); ourLog.info(myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(oo)); - assertEquals(encode(oo), "No issues detected during validation", oo.getIssueFirstRep().getDiagnostics()); + assertEquals("No issues detected during validation", oo.getIssueFirstRep().getDiagnostics(), encode(oo)); } @@ -370,19 +368,19 @@ public class FhirResourceDaoR4ValidateTest extends BaseJpaR4Test { obs.setSubject(new Reference("Group/123")); OperationOutcome oo = validateAndReturnOutcome(obs); ourLog.info(myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(oo)); - assertEquals(encode(oo), "Unable to resolve resource \"Group/123\"", oo.getIssueFirstRep().getDiagnostics()); + assertEquals("Unable to resolve resource \"Group/123\"", oo.getIssueFirstRep().getDiagnostics(), encode(oo)); // Target of wrong type obs.setSubject(new Reference("Group/ABC")); oo = validateAndReturnOutcome(obs); ourLog.info(myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(oo)); - assertEquals(encode(oo), "No issues detected during validation", oo.getIssueFirstRep().getDiagnostics()); + assertEquals("No issues detected during validation", oo.getIssueFirstRep().getDiagnostics(), encode(oo)); // Target of right type obs.setSubject(new Reference("Patient/DEF")); oo = validateAndReturnOutcome(obs); ourLog.info(myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(oo)); - assertEquals(encode(oo), "No issues detected during validation", oo.getIssueFirstRep().getDiagnostics()); + assertEquals("No issues detected during validation", oo.getIssueFirstRep().getDiagnostics(), encode(oo)); } @@ -495,38 +493,38 @@ public class FhirResourceDaoR4ValidateTest extends BaseJpaR4Test { obs.getText().setStatus(Narrative.NarrativeStatus.GENERATED); obs.getCode().getCodingFirstRep().setSystem("http://loinc.org").setCode("CODE3").setDisplay("Display 3"); oo = validateAndReturnOutcome(obs); - assertEquals(encode(oo), "No issues detected during validation", oo.getIssueFirstRep().getDiagnostics()); + assertEquals("No issues detected during validation", oo.getIssueFirstRep().getDiagnostics(), encode(oo)); // Invalid code obs.getText().setStatus(Narrative.NarrativeStatus.GENERATED); obs.getCode().getCodingFirstRep().setSystem("http://loinc.org").setCode("non-existing-code").setDisplay("Display 3"); oo = validateAndReturnOutcome(obs); - assertEquals(encode(oo), "None of the codes provided are in the value set http://example.com/fhir/ValueSet/observation-vitalsignresult (http://example.com/fhir/ValueSet/observation-vitalsignresult), and a code from this value set is required) (codes = http://loinc.org#non-existing-code)", oo.getIssueFirstRep().getDiagnostics()); + assertEquals("None of the codes provided are in the value set http://example.com/fhir/ValueSet/observation-vitalsignresult (http://example.com/fhir/ValueSet/observation-vitalsignresult), and a code from this value set is required) (codes = http://loinc.org#non-existing-code)", oo.getIssueFirstRep().getDiagnostics(), encode(oo)); // Valid code with no system obs.getText().setStatus(Narrative.NarrativeStatus.GENERATED); obs.getCode().getCodingFirstRep().setSystem(null).setCode("CODE3").setDisplay("Display 3"); oo = validateAndReturnOutcome(obs); - assertEquals(encode(oo), "None of the codes provided are in the value set http://example.com/fhir/ValueSet/observation-vitalsignresult (http://example.com/fhir/ValueSet/observation-vitalsignresult), and a code from this value set is required) (codes = null#CODE3)", oo.getIssueFirstRep().getDiagnostics()); + assertEquals("None of the codes provided are in the value set http://example.com/fhir/ValueSet/observation-vitalsignresult (http://example.com/fhir/ValueSet/observation-vitalsignresult), and a code from this value set is required) (codes = null#CODE3)", oo.getIssueFirstRep().getDiagnostics(), encode(oo)); // Valid code with wrong system obs.getText().setStatus(Narrative.NarrativeStatus.GENERATED); obs.getCode().getCodingFirstRep().setSystem("http://foo").setCode("CODE3").setDisplay("Display 3"); oo = validateAndReturnOutcome(obs); - assertEquals(encode(oo), "None of the codes provided are in the value set http://example.com/fhir/ValueSet/observation-vitalsignresult (http://example.com/fhir/ValueSet/observation-vitalsignresult), and a code from this value set is required) (codes = http://foo#CODE3)", oo.getIssueFirstRep().getDiagnostics()); + assertEquals("None of the codes provided are in the value set http://example.com/fhir/ValueSet/observation-vitalsignresult (http://example.com/fhir/ValueSet/observation-vitalsignresult), and a code from this value set is required) (codes = http://foo#CODE3)", oo.getIssueFirstRep().getDiagnostics(), encode(oo)); // Code that exists but isn't in the valueset obs.getText().setStatus(Narrative.NarrativeStatus.GENERATED); obs.getCode().getCodingFirstRep().setSystem("http://terminology.hl7.org/CodeSystem/observation-category").setCode("vital-signs").setDisplay("Display 3"); oo = validateAndReturnOutcome(obs); - assertEquals(encode(oo), "None of the codes provided are in the value set http://example.com/fhir/ValueSet/observation-vitalsignresult (http://example.com/fhir/ValueSet/observation-vitalsignresult), and a code from this value set is required) (codes = http://terminology.hl7.org/CodeSystem/observation-category#vital-signs)", oo.getIssueFirstRep().getDiagnostics()); + assertEquals("None of the codes provided are in the value set http://example.com/fhir/ValueSet/observation-vitalsignresult (http://example.com/fhir/ValueSet/observation-vitalsignresult), and a code from this value set is required) (codes = http://terminology.hl7.org/CodeSystem/observation-category#vital-signs)", oo.getIssueFirstRep().getDiagnostics(), encode(oo)); // Invalid code in built-in VS/CS obs.getText().setStatus(Narrative.NarrativeStatus.GENERATED); obs.getCode().getCodingFirstRep().setSystem("http://loinc.org").setCode("CODE3").setDisplay("Display 3"); obs.getCategoryFirstRep().addCoding().setSystem("http://terminology.hl7.org/CodeSystem/observation-category").setCode("FOO"); oo = validateAndReturnOutcome(obs); - assertEquals(encode(oo), "Unknown code 'http://terminology.hl7.org/CodeSystem/observation-category#FOO'", oo.getIssueFirstRep().getDiagnostics()); + assertEquals("Unknown code 'http://terminology.hl7.org/CodeSystem/observation-category#FOO'", oo.getIssueFirstRep().getDiagnostics(), encode(oo)); } @@ -566,7 +564,7 @@ public class FhirResourceDaoR4ValidateTest extends BaseJpaR4Test { obs.getText().setStatus(Narrative.NarrativeStatus.GENERATED); obs.getCode().getCodingFirstRep().setSystem("http://loinc.org").setCode("CODE3").setDisplay("Display 3"); oo = validateAndReturnOutcome(obs); - assertEquals(encode(oo), "No issues detected during validation", oo.getIssueFirstRep().getDiagnostics()); + assertEquals("No issues detected during validation", oo.getIssueFirstRep().getDiagnostics(), encode(oo)); } finally { myJpaValidationSupportChain.removeValidationSupport(validationSupport); @@ -577,7 +575,7 @@ public class FhirResourceDaoR4ValidateTest extends BaseJpaR4Test { * Make sure that we do something sane when validating throws an unexpected exception */ @Test - @Ignore + @Disabled public void testValidate_TermSvcHasDatabaseRollback() { BaseTermReadSvcImpl.setInvokeOnNextCallForUnitTest(() -> { try { @@ -711,7 +709,7 @@ public class FhirResourceDaoR4ValidateTest extends BaseJpaR4Test { } @Test - @Ignore + @Disabled public void testValidateResourceContainingProfileDeclarationJson() throws Exception { String methodName = "testValidateResourceContainingProfileDeclarationJson"; OperationOutcome outcome = doTestValidateResourceContainingProfileDeclaration(methodName, EncodingEnum.JSON); @@ -724,7 +722,7 @@ public class FhirResourceDaoR4ValidateTest extends BaseJpaR4Test { } @Test - @Ignore + @Disabled public void testValidateResourceContainingProfileDeclarationXml() throws Exception { String methodName = "testValidateResourceContainingProfileDeclarationXml"; OperationOutcome outcome = doTestValidateResourceContainingProfileDeclaration(methodName, EncodingEnum.XML); @@ -933,7 +931,7 @@ public class FhirResourceDaoR4ValidateTest extends BaseJpaR4Test { } } - @After + @AfterEach public void after() { FhirInstanceValidator val = AopTestUtils.getTargetObject(myValidatorModule); val.setBestPracticeWarningLevel(IResourceValidator.BestPracticeWarningLevel.Warning); @@ -1259,7 +1257,7 @@ public class FhirResourceDaoR4ValidateTest extends BaseJpaR4Test { * Format has changed, this is out of date */ @Test - @Ignore + @Disabled public void testValidateNewQuestionnaireFormat() throws Exception { String input = IOUtils.toString(FhirResourceDaoR4ValidateTest.class.getResourceAsStream("/questionnaire_r4.xml")); try { @@ -1314,9 +1312,4 @@ public class FhirResourceDaoR4ValidateTest extends BaseJpaR4Test { } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } - } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4ValueSetTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4ValueSetTest.java index 5c0fd454a50..1d751cc4833 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4ValueSetTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4ValueSetTest.java @@ -15,21 +15,21 @@ import org.hl7.fhir.r4.model.IdType; import org.hl7.fhir.r4.model.StringType; import org.hl7.fhir.r4.model.UriType; import org.hl7.fhir.r4.model.ValueSet; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.transaction.annotation.Transactional; import java.io.IOException; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.stringContainsInOrder; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; public class FhirResourceDaoR4ValueSetTest extends BaseJpaR4Test { @@ -37,19 +37,14 @@ public class FhirResourceDaoR4ValueSetTest extends BaseJpaR4Test { private IIdType myExtensionalVsId; - @After + @AfterEach public void after() { myDaoConfig.setPreExpandValueSets(new DaoConfig().isPreExpandValueSets()); myDaoConfig.setMaximumExpansionSize(new DaoConfig().getMaximumExpansionSize()); } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } - - @Before + @BeforeEach @Transactional public void before02() throws IOException { ValueSet upload = loadResourceFromClasspath(ValueSet.class, "/extensional-case-3-vs.xml"); @@ -282,7 +277,7 @@ public class FhirResourceDaoR4ValueSetTest extends BaseJpaR4Test { IFhirResourceDaoValueSet.ValidateCodeResult result = myValueSetDao.validateCode(vsIdentifier, null, code, system, display, coding, codeableConcept, mySrd); ourLog.info(result.getMessage()); - assertTrue(result.getMessage(), result.isResult()); + assertTrue( result.isResult(), result.getMessage()); assertEquals("Male", result.getDisplay()); } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoSearchParameterR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoSearchParameterR4Test.java index d8927950832..dea3529cec2 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoSearchParameterR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoSearchParameterR4Test.java @@ -1,26 +1,27 @@ package ca.uhn.fhir.jpa.dao.r4; import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.context.FhirVersionEnum; import ca.uhn.fhir.context.RuntimeResourceDefinition; import ca.uhn.fhir.context.RuntimeSearchParam; import ca.uhn.fhir.jpa.api.config.DaoConfig; import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; import org.hl7.fhir.r4.model.Enumerations; import org.hl7.fhir.r4.model.SearchParameter; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.context.ApplicationContext; import static org.apache.commons.lang3.StringUtils.isBlank; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class FhirResourceDaoSearchParameterR4Test { private static final Logger ourLog = LoggerFactory.getLogger(FhirResourceDaoSearchParameterR4Test.class); @@ -29,9 +30,9 @@ public class FhirResourceDaoSearchParameterR4Test { @Mock private ApplicationContext myApplicationContext; - @Before + @BeforeEach public void before() { - myCtx = FhirContext.forR4(); + myCtx = FhirContext.forCached(FhirVersionEnum.R4); myDao = new FhirResourceDaoSearchParameterR4(); myDao.setContext(myCtx); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirSearchDaoR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirSearchDaoR4Test.java index 2a7c3c72470..ef906312341 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirSearchDaoR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirSearchDaoR4Test.java @@ -10,24 +10,18 @@ import ca.uhn.fhir.rest.param.StringParam; import ca.uhn.fhir.util.TestUtil; import org.hl7.fhir.r4.model.Organization; import org.hl7.fhir.r4.model.Patient; -import org.junit.AfterClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import java.util.List; import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.empty; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; public class FhirSearchDaoR4Test extends BaseJpaR4Test { - @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/r4/FhirSystemDaoR4SearchTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirSystemDaoR4SearchTest.java index b29fc6a09b8..65b19bb83fe 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirSystemDaoR4SearchTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirSystemDaoR4SearchTest.java @@ -1,17 +1,12 @@ package ca.uhn.fhir.jpa.dao.r4; -import org.junit.AfterClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; import ca.uhn.fhir.util.TestUtil; public class FhirSystemDaoR4SearchTest extends BaseJpaR4SystemTest { - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } - @Test public void testSearchByParans() { diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirSystemDaoR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirSystemDaoR4Test.java index 2c05b68138b..f7330219930 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirSystemDaoR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirSystemDaoR4Test.java @@ -60,11 +60,11 @@ import org.hl7.fhir.r4.model.Quantity; import org.hl7.fhir.r4.model.Reference; import org.hl7.fhir.r4.model.Resource; import org.hl7.fhir.r4.model.ValueSet; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; import org.springframework.transaction.TransactionDefinition; import org.springframework.transaction.TransactionStatus; import org.springframework.transaction.support.TransactionCallback; @@ -83,6 +83,7 @@ import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.empty; @@ -92,26 +93,26 @@ import static org.hamcrest.Matchers.greaterThan; import static org.hamcrest.Matchers.matchesPattern; import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.startsWith; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; public class FhirSystemDaoR4Test extends BaseJpaR4SystemTest { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirSystemDaoR4Test.class); - @After + @AfterEach public void after() { myDaoConfig.setAllowInlineMatchUrlReferences(false); myDaoConfig.setAllowMultipleDelete(new DaoConfig().isAllowMultipleDelete()); } - @Before + @BeforeEach public void beforeDisableResultReuse() { myInterceptorRegistry.registerInterceptor(myInterceptor); myDaoConfig.setReuseCachedSearchResultsForMillis(null); @@ -2257,7 +2258,7 @@ public class FhirSystemDaoR4Test extends BaseJpaR4SystemTest { } - @Test(expected = InvalidRequestException.class) + @Test public void testTransactionFailsWithDuplicateIds() { Bundle request = new Bundle(); @@ -2271,7 +2272,9 @@ public class FhirSystemDaoR4Test extends BaseJpaR4SystemTest { patient2.addIdentifier().setSystem("urn:system").setValue("testPersistWithSimpleLinkP02"); request.addEntry().setResource(patient2).getRequest().setMethod(HTTPVerb.POST); - mySystemDao.transaction(mySrd, request); + assertThrows(InvalidRequestException.class, ()->{ + mySystemDao.transaction(mySrd, request); + }); } @Test @@ -2943,7 +2946,7 @@ public class FhirSystemDaoR4Test extends BaseJpaR4SystemTest { * Format changed, source isn't valid */ @Test - @Ignore + @Disabled public void testTransactionWithBundledValidationSourceAndTarget() throws Exception { InputStream bundleRes = SystemProviderDstu2Test.class.getResourceAsStream("/questionnaire-sdc-profile-example-ussg-fht.xml"); @@ -3284,7 +3287,7 @@ public class FhirSystemDaoR4Test extends BaseJpaR4SystemTest { * See #801 */ @Test - @Ignore + @Disabled public void testTransactionWithMatchUrlToReferenceInSameBundle() throws IOException { String input = IOUtils.toString(getClass().getResourceAsStream("/r4/bug801.json"), StandardCharsets.UTF_8); Bundle bundle = myFhirCtx.newJsonParser().parseResource(Bundle.class, input); @@ -3610,9 +3613,9 @@ public class FhirSystemDaoR4Test extends BaseJpaR4SystemTest { assertEquals(BundleType.TRANSACTIONRESPONSE, resp.getTypeElement().getValue()); assertEquals(3, resp.getEntry().size()); - assertTrue(resp.getEntry().get(0).getResponse().getLocation(), new IdType(resp.getEntry().get(0).getResponse().getLocation()).getIdPart().matches("^[0-9]+$")); - assertTrue(resp.getEntry().get(1).getResponse().getLocation(), new IdType(resp.getEntry().get(1).getResponse().getLocation()).getIdPart().matches("^[0-9]+$")); - assertTrue(resp.getEntry().get(2).getResponse().getLocation(), new IdType(resp.getEntry().get(2).getResponse().getLocation()).getIdPart().matches("^[0-9]+$")); + assertTrue(new IdType(resp.getEntry().get(0).getResponse().getLocation()).getIdPart().matches("^[0-9]+$"), resp.getEntry().get(0).getResponse().getLocation()); + assertTrue(new IdType(resp.getEntry().get(1).getResponse().getLocation()).getIdPart().matches("^[0-9]+$"), resp.getEntry().get(1).getResponse().getLocation()); + assertTrue(new IdType(resp.getEntry().get(2).getResponse().getLocation()).getIdPart().matches("^[0-9]+$"), resp.getEntry().get(2).getResponse().getLocation()); o1 = myObservationDao.read(new IdType(resp.getEntry().get(1).getResponse().getLocation()), mySrd); o2 = myObservationDao.read(new IdType(resp.getEntry().get(2).getResponse().getLocation()), mySrd); @@ -3753,9 +3756,9 @@ public class FhirSystemDaoR4Test extends BaseJpaR4SystemTest { assertEquals(BundleType.TRANSACTIONRESPONSE, resp.getTypeElement().getValue()); assertEquals(3, resp.getEntry().size()); - assertTrue(resp.getEntry().get(0).getResponse().getLocation(), new IdType(resp.getEntry().get(0).getResponse().getLocation()).getIdPart().matches("^[0-9]+$")); - assertTrue(resp.getEntry().get(1).getResponse().getLocation(), new IdType(resp.getEntry().get(1).getResponse().getLocation()).getIdPart().matches("^[0-9]+$")); - assertTrue(resp.getEntry().get(2).getResponse().getLocation(), new IdType(resp.getEntry().get(2).getResponse().getLocation()).getIdPart().matches("^[0-9]+$")); + assertTrue(new IdType(resp.getEntry().get(0).getResponse().getLocation()).getIdPart().matches("^[0-9]+$"), resp.getEntry().get(0).getResponse().getLocation()); + assertTrue(new IdType(resp.getEntry().get(1).getResponse().getLocation()).getIdPart().matches("^[0-9]+$"), resp.getEntry().get(1).getResponse().getLocation()); + assertTrue(new IdType(resp.getEntry().get(2).getResponse().getLocation()).getIdPart().matches("^[0-9]+$"), resp.getEntry().get(2).getResponse().getLocation()); o1 = myObservationDao.read(new IdType(resp.getEntry().get(1).getResponse().getLocation()), mySrd); o2 = myObservationDao.read(new IdType(resp.getEntry().get(2).getResponse().getLocation()), mySrd); @@ -3935,9 +3938,4 @@ public class FhirSystemDaoR4Test extends BaseJpaR4SystemTest { } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } - } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/PartitioningR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/PartitioningR4Test.java index df772f09ce5..dce798cd173 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/PartitioningR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/PartitioningR4Test.java @@ -52,10 +52,9 @@ import org.hl7.fhir.r4.model.Observation; import org.hl7.fhir.r4.model.Organization; import org.hl7.fhir.r4.model.Patient; import org.hl7.fhir.r4.model.SearchParameter; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; import org.springframework.beans.factory.annotation.Autowired; @@ -70,14 +69,14 @@ import java.util.stream.Collectors; import static ca.uhn.fhir.jpa.util.TestUtil.sleepAtLeast; import static org.apache.commons.lang3.StringUtils.countMatches; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.matchesPattern; import static org.hamcrest.Matchers.startsWith; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; @@ -98,7 +97,7 @@ public class PartitioningR4Test extends BaseJpaR4SystemTest { @Autowired private IPartitionLookupSvc myPartitionConfigSvc; - @After + @AfterEach public void after() { myPartitionInterceptor.assertNoRemainingIds(); @@ -120,7 +119,7 @@ public class PartitioningR4Test extends BaseJpaR4SystemTest { } @Override - @Before + @BeforeEach public void before() throws ServletException { super.before(); @@ -185,10 +184,10 @@ public class PartitioningR4Test extends BaseJpaR4SystemTest { List selectQueries = myCaptureQueriesListener.getSelectQueriesForCurrentThread(); assertEquals(2, selectQueries.size()); // Look up the partition - assertThat(selectQueries.get(0).getSql(true,false).toLowerCase(), containsString(" from hfj_partition ")); + assertThat(selectQueries.get(0).getSql(true, false).toLowerCase(), containsString(" from hfj_partition ")); // Look up the referenced subject/patient - assertThat(selectQueries.get(1).getSql(true,false).toLowerCase(), containsString(" from hfj_resource ")); - assertEquals(0, StringUtils.countMatches(selectQueries.get(1).getSql(true,false).toLowerCase(), "partition")); + assertThat(selectQueries.get(1).getSql(true, false).toLowerCase(), containsString(" from hfj_resource ")); + assertEquals(0, StringUtils.countMatches(selectQueries.get(1).getSql(true, false).toLowerCase(), "partition")); runInTransaction(() -> { List resLinks = myResourceLinkDao.findAll(); @@ -2372,8 +2371,8 @@ public class PartitioningR4Test extends BaseJpaR4SystemTest { // Resolve forced IDs sql = myCaptureQueriesListener.getSelectQueriesForCurrentThread().get(2).getSql(true, true); - assertEquals(sql, 1, countMatches(sql, "forcedid0_.RESOURCE_PID in")); - assertEquals(sql, 0, countMatches(sql, "PARTITION_ID is null")); + assertEquals(1, countMatches(sql, "forcedid0_.RESOURCE_PID in"), sql); + assertEquals(0, countMatches(sql, "PARTITION_ID is null"), sql); } @Test @@ -2532,9 +2531,4 @@ public class PartitioningR4Test extends BaseJpaR4SystemTest { } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } - } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/PersistObservationIndexedSearchParamLastNR4IT.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/PersistObservationIndexedSearchParamLastNR4IT.java index 5b7c6606fd4..74a56313c45 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/PersistObservationIndexedSearchParamLastNR4IT.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/PersistObservationIndexedSearchParamLastNR4IT.java @@ -1,6 +1,7 @@ package ca.uhn.fhir.jpa.dao.r4; import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.context.FhirVersionEnum; import ca.uhn.fhir.jpa.api.config.DaoConfig; import ca.uhn.fhir.jpa.api.dao.IFhirSystemDao; import ca.uhn.fhir.jpa.config.TestR4ConfigWithElasticsearchClient; @@ -15,15 +16,20 @@ import ca.uhn.fhir.parser.IParser; import ca.uhn.fhir.rest.param.*; import com.google.common.base.Charsets; import org.apache.commons.io.IOUtils; +import org.aspectj.lang.annotation.Before; import org.hl7.fhir.r4.model.*; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.MethodOrderer; +import org.junit.jupiter.api.Order; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestMethodOrder; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.io.Resource; import org.springframework.core.io.support.PathMatchingResourcePatternResolver; import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import javax.persistence.EntityManager; @@ -34,13 +40,15 @@ import java.io.InputStream; import java.util.*; import java.util.concurrent.atomic.AtomicInteger; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; -@RunWith(SpringJUnit4ClassRunner.class) + +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = {TestR4ConfigWithElasticsearchClient.class}) +@TestMethodOrder(MethodOrderer.OrderAnnotation.class) public class PersistObservationIndexedSearchParamLastNR4IT { @Autowired @@ -61,8 +69,9 @@ public class PersistObservationIndexedSearchParamLastNR4IT { @Autowired private DaoConfig myDaoConfig; - @Before + @BeforeEach public void before() throws IOException { + myDaoConfig.setLastNEnabled(true); elasticsearchSvc.deleteAllDocumentsForTest(ElasticsearchSvcImpl.OBSERVATION_INDEX); elasticsearchSvc.deleteAllDocumentsForTest(ElasticsearchSvcImpl.OBSERVATION_CODE_INDEX); @@ -71,12 +80,7 @@ public class PersistObservationIndexedSearchParamLastNR4IT { } - @Before - public void beforeEnableLastN() { - myDaoConfig.setLastNEnabled(true); - } - - @After + @AfterEach public void afterDisableLastN() { myDaoConfig.setLastNEnabled(new DaoConfig().isLastNEnabled()); } @@ -95,6 +99,7 @@ public class PersistObservationIndexedSearchParamLastNR4IT { private ReferenceAndListParam multiSubjectParams = null; + @Order(3) @Test public void testIndexObservationSingle() throws IOException { indexSingleObservation(); @@ -195,6 +200,7 @@ public class PersistObservationIndexedSearchParamLastNR4IT { return codeableConceptField; } + @Order(2) @Test public void testIndexObservationMultiple() throws IOException { indexMultipleObservations(); @@ -297,6 +303,7 @@ public class PersistObservationIndexedSearchParamLastNR4IT { } + @Order(0) @Test public void testDeleteObservation() throws IOException { indexMultipleObservations(); @@ -338,6 +345,7 @@ public class PersistObservationIndexedSearchParamLastNR4IT { } + @Order(4) @Test public void testUpdateObservation() throws IOException { indexSingleObservation(); @@ -398,9 +406,10 @@ public class PersistObservationIndexedSearchParamLastNR4IT { } + @Order(1) @Test public void testSampleBundleInTransaction() throws IOException { - FhirContext myFhirCtx = FhirContext.forR4(); + FhirContext myFhirCtx = FhirContext.forCached(FhirVersionEnum.R4); PathMatchingResourcePatternResolver provider = new PathMatchingResourcePatternResolver(); final Resource[] bundleResources; diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/SearchCoordinatorSvcImplTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/SearchCoordinatorSvcImplTest.java index 4a1483a248b..4eb8f636121 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/SearchCoordinatorSvcImplTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/SearchCoordinatorSvcImplTest.java @@ -12,24 +12,21 @@ import ca.uhn.fhir.jpa.search.cache.DatabaseSearchCacheSvcImpl; import ca.uhn.fhir.jpa.search.cache.ISearchCacheSvc; import ca.uhn.fhir.util.TestUtil; import org.apache.commons.lang3.time.DateUtils; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import java.util.Date; import java.util.UUID; import static ca.uhn.fhir.jpa.search.cache.DatabaseSearchCacheSvcImpl.DEFAULT_MAX_DELETE_CANDIDATES_TO_FIND; -import static org.junit.Assert.assertEquals; +import static org.hamcrest.Matchers.containsInAnyOrder; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.hamcrest.MatcherAssert.assertThat; public class SearchCoordinatorSvcImplTest extends BaseJpaR4Test { - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } - @Autowired private ISearchDao mySearchDao; @@ -45,7 +42,7 @@ public class SearchCoordinatorSvcImplTest extends BaseJpaR4Test { @Autowired private ISearchCacheSvc myDataaseCacheSvc; - @After + @AfterEach public void after() { DatabaseSearchCacheSvcImpl.setMaximumResultsToDeleteInOnePassForUnitTest(DatabaseSearchCacheSvcImpl.DEFAULT_MAX_RESULTS_TO_DELETE_IN_ONE_PAS); DatabaseSearchCacheSvcImpl.setMaximumSearchesToCheckForDeletionCandidacyForUnitTest(DEFAULT_MAX_DELETE_CANDIDATES_TO_FIND); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/SearchParamExtractorR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/SearchParamExtractorR4Test.java index c38069fb90c..2bcc4763edd 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/SearchParamExtractorR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/SearchParamExtractorR4Test.java @@ -1,6 +1,7 @@ package ca.uhn.fhir.jpa.dao.r4; import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.context.FhirVersionEnum; import ca.uhn.fhir.context.RuntimeResourceDefinition; import ca.uhn.fhir.context.RuntimeSearchParam; import ca.uhn.fhir.context.phonetic.IPhoneticEncoder; @@ -32,10 +33,10 @@ import org.hl7.fhir.r4.model.Patient; import org.hl7.fhir.r4.model.Quantity; import org.hl7.fhir.r4.model.Reference; import org.hl7.fhir.r4.model.SearchParameter; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -49,18 +50,18 @@ import java.util.Set; import java.util.stream.Collectors; import static java.util.Comparator.comparing; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; public class SearchParamExtractorR4Test { private static final Logger ourLog = LoggerFactory.getLogger(SearchParamExtractorR4Test.class); - private static FhirContext ourCtx = FhirContext.forR4(); + private static FhirContext ourCtx = FhirContext.forCached(FhirVersionEnum.R4); private static IValidationSupport ourValidationSupport; private MySearchParamRegistry mySearchParamRegistry; private PartitionSettings myPartitionSettings; - @Before + @BeforeEach public void before() { mySearchParamRegistry = new MySearchParamRegistry(); @@ -409,12 +410,7 @@ public class SearchParamExtractorR4Test { } } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } - - @BeforeClass + @BeforeAll public static void beforeClass() { ourValidationSupport = new DefaultProfileValidationSupport(ourCtx); } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/SearchParameterMapTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/SearchParameterMapTest.java index e892b235149..2195260620a 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/SearchParameterMapTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/SearchParameterMapTest.java @@ -1,16 +1,17 @@ package ca.uhn.fhir.jpa.dao.r4; import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.context.FhirVersionEnum; import ca.uhn.fhir.jpa.searchparam.SearchParameterMap; import ca.uhn.fhir.rest.param.HasParam; import ca.uhn.fhir.test.BaseTest; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public class SearchParameterMapTest extends BaseTest { - private FhirContext myContext = FhirContext.forR4(); + private FhirContext myContext = FhirContext.forCached(FhirVersionEnum.R4); @Test public void toNormalizedQueryStringTest() { diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/SearchWithInterceptorR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/SearchWithInterceptorR4Test.java index 15911d306db..3d13c980128 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/SearchWithInterceptorR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/SearchWithInterceptorR4Test.java @@ -10,15 +10,17 @@ import ca.uhn.fhir.rest.api.server.RequestDetails; import ca.uhn.fhir.rest.param.TokenParam; import org.hl7.fhir.r4.model.Condition; import org.hl7.fhir.r4.model.Patient; -import org.junit.AfterClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; import java.util.List; import static org.hamcrest.CoreMatchers.containsString; -import static org.junit.Assert.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; -@SuppressWarnings({"unchecked", "Duplicates"}) +@SuppressWarnings({"Duplicates"}) public class SearchWithInterceptorR4Test extends BaseJpaR4Test { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(SearchWithInterceptorR4Test.class); @@ -74,9 +76,5 @@ public class SearchWithInterceptorR4Test extends BaseJpaR4Test { } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/TransactionDeleteR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/TransactionDeleteR4Test.java index ab241bfff75..894c1908e46 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/TransactionDeleteR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r4/TransactionDeleteR4Test.java @@ -7,17 +7,17 @@ import org.hl7.fhir.r4.model.Bundle; import org.hl7.fhir.r4.model.DiagnosticReport; import org.hl7.fhir.r4.model.Observation; import org.hl7.fhir.r4.model.Reference; -import org.junit.After; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.matchesPattern; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.fail; public class TransactionDeleteR4Test extends BaseJpaR4SystemTest { - @After + @AfterEach public void after() { myDaoConfig.setEnforceReferentialIntegrityOnDelete(true); } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r5/BaseJpaR5Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r5/BaseJpaR5Test.java index 4894a38c2cf..da959cba3c6 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r5/BaseJpaR5Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r5/BaseJpaR5Test.java @@ -131,15 +131,15 @@ import org.hl7.fhir.r5.model.Task; import org.hl7.fhir.r5.model.UriType; import org.hl7.fhir.r5.model.ValueSet; import org.hl7.fhir.r5.utils.IResourceValidator; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.context.ApplicationContext; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.util.AopTestUtils; import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.annotation.Transactional; @@ -151,10 +151,10 @@ import java.nio.charset.StandardCharsets; import java.util.List; import java.util.Map; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.Mockito.mock; -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = {TestR5Config.class}) public abstract class BaseJpaR5Test extends BaseJpaTest { private static IValidationSupport ourJpaValidationSupportChainR5; @@ -398,6 +398,8 @@ public abstract class BaseJpaR5Test extends BaseJpaTest { protected SubscriptionRegistry mySubscriptionRegistry; protected IServerInterceptor myInterceptor; @Autowired + protected ITermDeferredStorageSvc myTermDeferredStorageSvc; + @Autowired private IValidationSupport myJpaValidationSupportChain; private PerformanceTracingLoggingInterceptor myPerformanceTracingLoggingInterceptor; private List mySystemInterceptors; @@ -405,10 +407,8 @@ public abstract class BaseJpaR5Test extends BaseJpaTest { private DaoRegistry myDaoRegistry; @Autowired private IBulkDataExportSvc myBulkDataExportSvc; - @Autowired - protected ITermDeferredStorageSvc myTermDeferredStorageSvc; - @After() + @AfterEach() public void afterCleanupDao() { myDaoConfig.setExpireSearchResults(new DaoConfig().isExpireSearchResults()); myDaoConfig.setEnforceReferentialIntegrityOnDelete(new DaoConfig().isEnforceReferentialIntegrityOnDelete()); @@ -421,12 +421,12 @@ public abstract class BaseJpaR5Test extends BaseJpaTest { myPagingProvider.setMaximumPageSize(BasePagingProvider.DEFAULT_MAX_PAGE_SIZE); } - @After + @AfterEach public void afterResetInterceptors() { myInterceptorRegistry.unregisterAllInterceptors(); } - @After + @AfterEach public void afterClearTerminologyCaches() { BaseTermReadSvcImpl baseHapiTerminologySvc = AopTestUtils.getTargetObject(myTermSvc); baseHapiTerminologySvc.clearCaches(); @@ -436,13 +436,13 @@ public abstract class BaseJpaR5Test extends BaseJpaTest { deferredStorageSvc.clearDeferred(); } - @After() + @AfterEach() public void afterGrabCaches() { ourValueSetDao = myValueSetDao; ourJpaValidationSupportChainR5 = myJpaValidationSupportChain; } - @Before + @BeforeEach public void beforeCreateInterceptor() { mySystemInterceptors = myInterceptorRegistry.getAllRegisteredInterceptors(); @@ -452,7 +452,7 @@ public abstract class BaseJpaR5Test extends BaseJpaTest { myInterceptorRegistry.registerInterceptor(myPerformanceTracingLoggingInterceptor); } - @Before + @BeforeEach public void beforeFlushFT() { runInTransaction(() -> { FullTextEntityManager ftem = Search.getFullTextEntityManager(myEntityManager); @@ -465,13 +465,13 @@ public abstract class BaseJpaR5Test extends BaseJpaTest { myDaoConfig.setIndexMissingFields(DaoConfig.IndexEnabledEnum.ENABLED); } - @Before + @BeforeEach @Transactional() public void beforePurgeDatabase() { purgeDatabase(myDaoConfig, mySystemDao, myResourceReindexingSvc, mySearchCoordinatorSvc, mySearchParamRegistry, myBulkDataExportSvc); } - @Before + @BeforeEach public void beforeResetConfig() { myDaoConfig.setHardTagListLimit(1000); myFhirCtx.setParserErrorHandler(new StrictErrorHandler()); @@ -517,11 +517,10 @@ public abstract class BaseJpaR5Test extends BaseJpaTest { dao.update(resourceParsed); } - @AfterClass + @AfterAll public static void afterClassClearContextBaseJpaR5Test() { ourValueSetDao.purgeCaches(); ourJpaValidationSupportChainR5.invalidateCaches(); - TestUtil.clearAllStaticFieldsForUnitTest(); } /** diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r5/FhirResourceDaoR5SearchNoFtTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r5/FhirResourceDaoR5SearchNoFtTest.java index 362152f540f..bc5a6e28d1f 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r5/FhirResourceDaoR5SearchNoFtTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r5/FhirResourceDaoR5SearchNoFtTest.java @@ -14,12 +14,12 @@ import org.hl7.fhir.r5.model.Organization; import org.hl7.fhir.r5.model.Patient; import org.hl7.fhir.r5.model.Practitioner; import org.hl7.fhir.r5.model.PractitionerRole; -import org.junit.AfterClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; import java.util.Date; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; @SuppressWarnings({"unchecked", "Duplicates"}) public class FhirResourceDaoR5SearchNoFtTest extends BaseJpaR5Test { @@ -136,10 +136,4 @@ public class FhirResourceDaoR5SearchNoFtTest extends BaseJpaR5Test { assertEquals(0, outcome.getResources(0, 3).size()); } - - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } - } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r5/StorageInterceptorEventsR5Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r5/StorageInterceptorEventsR5Test.java index fbea0a3c77c..e80d6244fab 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r5/StorageInterceptorEventsR5Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/r5/StorageInterceptorEventsR5Test.java @@ -12,18 +12,18 @@ import ca.uhn.fhir.rest.server.SimpleBundleProvider; import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.r5.model.IdType; import org.hl7.fhir.r5.model.Patient; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; import java.util.List; import java.util.concurrent.atomic.AtomicInteger; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.when; -@SuppressWarnings({"unchecked", "Duplicates"}) +@SuppressWarnings({"Duplicates"}) public class StorageInterceptorEventsR5Test extends BaseJpaR5Test { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(StorageInterceptorEventsR5Test.class); @@ -59,7 +59,7 @@ public class StorageInterceptorEventsR5Test extends BaseJpaR5Test { // Initial search returns all SearchParameterMap params = new SearchParameterMap(); IBundleProvider search = myPatientDao.search(params, mySrd); - assertTrue(search.getClass().toString(), search instanceof PersistedJpaBundleProvider); + assertTrue(search instanceof PersistedJpaBundleProvider, search.getClass().toString()); List found = search.getResources(0, 100); assertEquals(3, found.size()); assertEquals(3, showedCounter.get()); @@ -103,7 +103,7 @@ public class StorageInterceptorEventsR5Test extends BaseJpaR5Test { SearchParameterMap params = new SearchParameterMap(); params.setLoadSynchronous(true); IBundleProvider search = myPatientDao.search(params, mySrd); - assertTrue(search.getClass().toString(), search instanceof SimpleBundleProvider); + assertTrue(search instanceof SimpleBundleProvider, search.getClass().toString()); List found = search.getResources(0, 100); assertEquals(3, found.size()); assertEquals(3, showedCounter.get()); @@ -120,15 +120,10 @@ public class StorageInterceptorEventsR5Test extends BaseJpaR5Test { assertEquals(2, showedCounter.get()); } - @After + @AfterEach public void after() { myInterceptorRegistry.unregisterAllInterceptors(); } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } - } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/delete/DeleteConflictServiceR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/delete/DeleteConflictServiceR4Test.java index 5726e7613a6..4f52219ae9f 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/delete/DeleteConflictServiceR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/delete/DeleteConflictServiceR4Test.java @@ -13,9 +13,9 @@ import org.hl7.fhir.r4.model.Condition; import org.hl7.fhir.r4.model.Organization; import org.hl7.fhir.r4.model.Patient; import org.hl7.fhir.r4.model.Reference; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -24,9 +24,7 @@ import java.util.ArrayList; import java.util.List; import java.util.function.Function; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.*; public class DeleteConflictServiceR4Test extends BaseJpaR4Test { private static final Logger ourLog = LoggerFactory.getLogger(DeleteConflictServiceR4Test.class); @@ -37,14 +35,14 @@ public class DeleteConflictServiceR4Test extends BaseJpaR4Test { private final DeleteConflictInterceptor myDeleteInterceptor = new DeleteConflictInterceptor(); private int myInterceptorDeleteCount; - @Before + @BeforeEach public void beforeRegisterInterceptor() { myInterceptorRegistry.registerInterceptor(myDeleteInterceptor); myInterceptorDeleteCount = 0; myDeleteInterceptor.clear(); } - @After + @AfterEach public void afterUnregisterInterceptor() { myInterceptorRegistry.unregisterAllInterceptors(); } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/delete/DeleteConflictServiceTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/delete/DeleteConflictServiceTest.java index ff1c2941d0b..688aec5ee6a 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/delete/DeleteConflictServiceTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/delete/DeleteConflictServiceTest.java @@ -9,23 +9,23 @@ import ca.uhn.fhir.jpa.model.config.PartitionSettings; import ca.uhn.fhir.jpa.model.entity.ResourceLink; import ca.uhn.fhir.jpa.model.entity.ResourceTable; import ca.uhn.fhir.rest.api.server.storage.TransactionDetails; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.context.annotation.Bean; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import java.util.ArrayList; import java.util.List; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.Mockito.when; -@RunWith(SpringRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = {DeleteConflictServiceTest.SpringConfig.class}) public class DeleteConflictServiceTest { @@ -47,15 +47,6 @@ public class DeleteConflictServiceTest { @Autowired private DeleteConflictService myDeleteConflictService; - static class SpringConfig { - @Bean - DeleteConflictService myDeleteConflictService() { return new DeleteConflictService(); } - @Bean - DaoConfig myDaoConfig() { return new DaoConfig(); } - @Bean - PartitionSettings partitionSettings() { return new PartitionSettings(); } - } - @Test public void noInterceptorTwoConflictsDoesntRetry() { ResourceTable entity = new ResourceTable(); @@ -69,4 +60,21 @@ public class DeleteConflictServiceTest { int retryCount = myDeleteConflictService.validateOkToDelete(deleteConflicts, entity, false, null, new TransactionDetails()); assertEquals(0, retryCount); } + + static class SpringConfig { + @Bean + DeleteConflictService myDeleteConflictService() { + return new DeleteConflictService(); + } + + @Bean + DaoConfig myDaoConfig() { + return new DaoConfig(); + } + + @Bean + PartitionSettings partitionSettings() { + return new PartitionSettings(); + } + } } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/entity/TermCodeSystemTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/entity/TermCodeSystemTest.java index 3558233dba6..02c4dbbba99 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/entity/TermCodeSystemTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/entity/TermCodeSystemTest.java @@ -1,9 +1,9 @@ package ca.uhn.fhir.jpa.entity; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; public class TermCodeSystemTest { diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/entity/TermCodeSystemVersionTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/entity/TermCodeSystemVersionTest.java index 2438bf38fa6..fa2e344cc19 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/entity/TermCodeSystemVersionTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/entity/TermCodeSystemVersionTest.java @@ -1,8 +1,8 @@ package ca.uhn.fhir.jpa.entity; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; public class TermCodeSystemVersionTest { diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/graphql/JpaStorageServicesTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/graphql/JpaStorageServicesTest.java index dc3a0cd2667..01bb7db42dd 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/graphql/JpaStorageServicesTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/graphql/JpaStorageServicesTest.java @@ -4,6 +4,7 @@ import ca.uhn.fhir.jpa.api.config.DaoConfig; import ca.uhn.fhir.jpa.config.TestR4Config; import ca.uhn.fhir.jpa.dao.r4.BaseJpaR4Test; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; +import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.r4.model.Appointment; import org.hl7.fhir.r4.model.CodeableConcept; @@ -11,39 +12,43 @@ import org.hl7.fhir.r4.model.Coding; import org.hl7.fhir.utilities.graphql.Argument; import org.hl7.fhir.utilities.graphql.IGraphQLStorageServices; import org.hl7.fhir.utilities.graphql.StringValue; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; + @ContextConfiguration(classes = {TestR4Config.class}) -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @DirtiesContext public class JpaStorageServicesTest extends BaseJpaR4Test { - @After + @Autowired + private IGraphQLStorageServices mySvc; + + @AfterEach public void after() { myDaoConfig.setFilterParameterEnabled(new DaoConfig().isFilterParameterEnabled()); } - @Before + @BeforeEach public void before() { myDaoConfig.setFilterParameterEnabled(true); } - @Autowired - private IGraphQLStorageServices mySvc; - private String createSomeAppointment() { CodeableConcept someCodeableConcept = new CodeableConcept(new Coding("TEST_SYSTEM", "TEST_CODE", "TEST_DISPLAY")); Appointment someAppointment = new Appointment(); @@ -60,8 +65,8 @@ public class JpaStorageServicesTest extends BaseJpaR4Test { List result = new ArrayList<>(); mySvc.listResources(mySrd, "Appointment", Collections.singletonList(argument), result); - Assert.assertFalse(result.isEmpty()); - Assert.assertTrue(result.stream().anyMatch((it) -> it.getIdElement().getIdPart().equals(appointmentId))); + assertFalse(result.isEmpty()); + assertTrue(result.stream().anyMatch((it) -> it.getIdElement().getIdPart().equals(appointmentId))); } @Test @@ -73,15 +78,20 @@ public class JpaStorageServicesTest extends BaseJpaR4Test { List result = new ArrayList<>(); mySvc.listResources(mySrd, "Appointment", Collections.singletonList(argument), result); - Assert.assertFalse(result.isEmpty()); - Assert.assertTrue(result.stream().anyMatch((it) -> it.getIdElement().getIdPart().equals(appointmentId))); + assertFalse(result.isEmpty()); + assertTrue(result.stream().anyMatch((it) -> it.getIdElement().getIdPart().equals(appointmentId))); } - @Test(expected = InvalidRequestException.class) + @Test public void testListResourceGraphqlInvalidException() { Argument argument = new Argument("test", new StringValue("some test value")); List result = new ArrayList<>(); - mySvc.listResources(mySrd, "Appointment", Collections.singletonList(argument), result); + try { + mySvc.listResources(mySrd, "Appointment", Collections.singletonList(argument), result); + fail(); + } catch (InvalidRequestException e) { + assertEquals("Unknown GraphQL argument \"test\". Value GraphQL argument for this type are: [_id, _language, actor, appointment_type, based_on, date, identifier, location, part_status, patient, practitioner, reason_code, reason_reference, service_category, service_type, slot, specialty, status, supporting_info]", e.getMessage()); + } } } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/packages/IgInstallerDstu3Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/packages/IgInstallerDstu3Test.java index 15d5605414b..cf57cdcbd95 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/packages/IgInstallerDstu3Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/packages/IgInstallerDstu3Test.java @@ -11,25 +11,23 @@ import org.eclipse.jetty.server.Server; import org.eclipse.jetty.servlet.ServletHandler; import org.eclipse.jetty.servlet.ServletHolder; import org.hl7.fhir.utilities.cache.IPackageCacheManager; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import java.io.InputStream; import java.util.stream.Collectors; import static ca.uhn.fhir.util.ClasspathUtil.loadResourceAsByteArray; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.hasItem; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; public class IgInstallerDstu3Test extends BaseJpaDstu3Test { @@ -46,7 +44,7 @@ public class IgInstallerDstu3Test extends BaseJpaDstu3Test { private INpmPackageVersionDao myPackageVersionDao; private int myPort; - @Before + @BeforeEach public void before() throws Exception { JpaPackageCache jpaPackageCache = ProxyUtil.getSingletonTarget(myPackageCacheManager, JpaPackageCache.class); @@ -63,11 +61,9 @@ public class IgInstallerDstu3Test extends BaseJpaDstu3Test { jpaPackageCache.addPackageServer("http://localhost:" + myPort); myFakeNpmServlet.getResponses().clear(); - - InputStream stream; } - @After + @AfterEach public void after() throws Exception { JettyUtil.closeServer(myServer); daoConfig.setAllowExternalReferences(new DaoConfig().isAllowExternalReferences()); @@ -84,7 +80,7 @@ public class IgInstallerDstu3Test extends BaseJpaDstu3Test { igInstaller.install(new PackageInstallationSpec().setName("erroneous-ig").setVersion("1.0.2").setInstallMode(PackageInstallationSpec.InstallModeEnum.STORE_AND_INSTALL).setPackageContents(bytes)); fail(); } catch (ImplementationGuideInstallationException e) { - Assert.assertThat(e.getMessage(), containsString("Failure when generating snapshot of StructureDefinition")); + assertThat(e.getMessage(), containsString("Failure when generating snapshot of StructureDefinition")); } } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/packages/JpaPackageCacheTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/packages/JpaPackageCacheTest.java index b3db84a4a68..a82b944a778 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/packages/JpaPackageCacheTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/packages/JpaPackageCacheTest.java @@ -4,13 +4,14 @@ import ca.uhn.fhir.jpa.dao.r4.BaseJpaR4Test; import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException; import org.hl7.fhir.utilities.cache.IPackageCacheManager; import org.hl7.fhir.utilities.cache.NpmPackage; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import java.io.IOException; import java.io.InputStream; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; public class JpaPackageCacheTest extends BaseJpaR4Test { diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/packages/NpmSearchTestR4.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/packages/NpmSearchTestR4.java index 86117d9c182..7027875787a 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/packages/NpmSearchTestR4.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/packages/NpmSearchTestR4.java @@ -7,8 +7,8 @@ import ca.uhn.fhir.jpa.dao.r4.BaseJpaR4Test; import ca.uhn.fhir.test.utilities.ProxyUtil; import ca.uhn.fhir.util.JsonUtil; import org.hamcrest.Matchers; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -16,8 +16,8 @@ import org.springframework.beans.factory.annotation.Autowired; import java.io.IOException; import java.util.stream.Collectors; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; public class NpmSearchTestR4 extends BaseJpaR4Test { @@ -35,7 +35,7 @@ public class NpmSearchTestR4 extends BaseJpaR4Test { @Autowired private INpmPackageVersionResourceDao myPackageVersionResourceDao; - @Before + @BeforeEach public void before() throws Exception { JpaPackageCache jpaPackageCache = ProxyUtil.getSingletonTarget(myPackageCacheManager, JpaPackageCache.class); jpaPackageCache.getPackageServers().clear(); @@ -201,8 +201,8 @@ public class NpmSearchTestR4 extends BaseJpaR4Test { myCaptureQueriesListener.logSelectQueriesForCurrentThread(); - runInTransaction(()->{ - ourLog.info("Versions:\n * {}", myPackageVersionDao.findAll().stream().map(t->t.toString()).collect(Collectors.joining("\n * "))); + runInTransaction(() -> { + ourLog.info("Versions:\n * {}", myPackageVersionDao.findAll().stream().map(t -> t.toString()).collect(Collectors.joining("\n * "))); }); ourLog.info("Search rersults:\r{}", JsonUtil.serialize(search)); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/packages/NpmTestDstu3.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/packages/NpmTestDstu3.java index 324353d854d..13c798a9a36 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/packages/NpmTestDstu3.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/packages/NpmTestDstu3.java @@ -14,9 +14,9 @@ import org.hl7.fhir.dstu3.model.Condition; import org.hl7.fhir.dstu3.model.OperationOutcome; import org.hl7.fhir.dstu3.model.StructureDefinition; import org.hl7.fhir.dstu3.model.ValueSet; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -28,8 +28,8 @@ import java.io.IOException; import java.util.HashMap; import java.util.Map; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; public class NpmTestDstu3 extends BaseJpaDstu3Test { @@ -44,7 +44,7 @@ public class NpmTestDstu3 extends BaseJpaDstu3Test { private Server myServer; private final Map myResponses = new HashMap<>(); - @Before + @BeforeEach public void before() throws Exception { JpaPackageCache jpaPackageCache = ProxyUtil.getSingletonTarget(myPackageCacheManager, JpaPackageCache.class); @@ -63,7 +63,7 @@ public class NpmTestDstu3 extends BaseJpaDstu3Test { myResponses.clear(); } - @After + @AfterEach public void after() throws Exception { JettyUtil.closeServer(myServer); } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/packages/NpmTestR4.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/packages/NpmTestR4.java index 46f2f4a70a4..4e1f1bba30c 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/packages/NpmTestR4.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/packages/NpmTestR4.java @@ -25,9 +25,9 @@ import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.r4.model.ImplementationGuide; import org.hl7.fhir.r4.model.StructureDefinition; import org.hl7.fhir.utilities.cache.NpmPackage; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -42,14 +42,14 @@ import java.util.HashMap; import java.util.Map; import java.util.stream.Collectors; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.hasItem; import static org.hamcrest.Matchers.not; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThat; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; public class NpmTestR4 extends BaseJpaR4Test { @@ -69,7 +69,7 @@ public class NpmTestR4 extends BaseJpaR4Test { private INpmPackageVersionResourceDao myPackageVersionResourceDao; private FakeNpmServlet myFakeNpmServlet; - @Before + @BeforeEach public void before() throws Exception { JpaPackageCache jpaPackageCache = ProxyUtil.getSingletonTarget(myPackageCacheManager, JpaPackageCache.class); @@ -88,7 +88,7 @@ public class NpmTestR4 extends BaseJpaR4Test { myFakeNpmServlet.myResponses.clear(); } - @After + @AfterEach public void after() throws Exception { JettyUtil.closeServer(myServer); myDaoConfig.setAllowExternalReferences(new DaoConfig().isAllowExternalReferences()); @@ -115,7 +115,7 @@ public class NpmTestR4 extends BaseJpaR4Test { assertEquals("Nictiz NL package of FHIR STU3 conformance resources for MedMij information standard Questionnaires. Includes dependency on Zib2017 and SDC.\\n\\nHCIMs: https://zibs.nl/wiki/HCIM_Release_2017(EN)", pkg.description()); // Fetch resource by URL - FhirContext fhirContext = FhirContext.forDstu3(); + FhirContext fhirContext = FhirContext.forCached(FhirVersionEnum.DSTU3); runInTransaction(() -> { IBaseResource asset = myPackageCacheManager.loadPackageAssetByUrl(FhirVersionEnum.DSTU3, "http://nictiz.nl/fhir/StructureDefinition/vl-QuestionnaireResponse"); assertThat(fhirContext.newJsonParser().encodeResourceToString(asset), containsString("\"url\":\"http://nictiz.nl/fhir/StructureDefinition/vl-QuestionnaireResponse\",\"version\":\"1.0.1\"")); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/packages/PackageInstallationSpecTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/packages/PackageInstallationSpecTest.java index 90fefccf0bc..8a353de71e2 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/packages/PackageInstallationSpecTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/packages/PackageInstallationSpecTest.java @@ -1,12 +1,12 @@ package ca.uhn.fhir.jpa.packages; import ca.uhn.fhir.util.JsonUtil; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.IOException; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; -import static org.junit.Assert.*; public class PackageInstallationSpecTest { diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/packages/PackageVersionComparatorTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/packages/PackageVersionComparatorTest.java index 60b7e926163..247a95cb86c 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/packages/PackageVersionComparatorTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/packages/PackageVersionComparatorTest.java @@ -1,12 +1,12 @@ package ca.uhn.fhir.jpa.packages; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static com.google.common.collect.Lists.newArrayList; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.contains; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.thymeleaf.util.ListUtils.sort; public class PackageVersionComparatorTest { diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/partition/PartitionManagementProviderTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/partition/PartitionManagementProviderTest.java index 0eb7df13e2b..ab609103900 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/partition/PartitionManagementProviderTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/partition/PartitionManagementProviderTest.java @@ -1,22 +1,23 @@ package ca.uhn.fhir.jpa.partition; import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.context.FhirVersionEnum; import ca.uhn.fhir.jpa.entity.PartitionEntity; import ca.uhn.fhir.rest.client.api.IGenericClient; import ca.uhn.fhir.rest.client.interceptor.LoggingInterceptor; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import ca.uhn.fhir.rest.server.provider.ProviderConstants; -import ca.uhn.fhir.test.utilities.server.RestfulServerRule; +import ca.uhn.fhir.test.utilities.server.RestfulServerExtension; import org.hl7.fhir.r4.model.CodeType; import org.hl7.fhir.r4.model.IntegerType; import org.hl7.fhir.r4.model.Parameters; import org.hl7.fhir.r4.model.StringType; import org.jetbrains.annotations.NotNull; -import org.junit.After; -import org.junit.Before; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.api.extension.RegisterExtension; import org.mockito.stubbing.Answer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -25,10 +26,10 @@ import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.times; @@ -36,28 +37,28 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.when; -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = PartitionManagementProviderTest.MyConfig.class) public class PartitionManagementProviderTest { private static final Logger ourLog = LoggerFactory.getLogger(PartitionManagementProviderTest.class); - private static FhirContext ourCtx = FhirContext.forR4(); - @ClassRule - public static RestfulServerRule ourServerRule = new RestfulServerRule(ourCtx); + private static FhirContext ourCtx = FhirContext.forCached(FhirVersionEnum.R4); + @RegisterExtension + public static RestfulServerExtension ourServerRule = new RestfulServerExtension(ourCtx); @MockBean private IPartitionLookupSvc myPartitionConfigSvc; @Autowired private PartitionManagementProvider myPartitionManagementProvider; private IGenericClient myClient; - @Before + @BeforeEach public void before() { ourServerRule.getRestfulServer().registerProvider(myPartitionManagementProvider); myClient = ourServerRule.getFhirClient(); myClient.registerInterceptor(new LoggingInterceptor(false)); } - @After + @AfterEach public void after() { ourServerRule.getRestfulServer().unregisterProvider(myPartitionManagementProvider); } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/partition/PartitionSettingsSvcImplTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/partition/PartitionSettingsSvcImplTest.java index b64a418d37e..6bf1c707163 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/partition/PartitionSettingsSvcImplTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/partition/PartitionSettingsSvcImplTest.java @@ -4,10 +4,10 @@ import ca.uhn.fhir.jpa.dao.r4.BaseJpaR4Test; import ca.uhn.fhir.jpa.entity.PartitionEntity; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; public class PartitionSettingsSvcImplTest extends BaseJpaR4Test { diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/patch/FhirPatchApplyR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/patch/FhirPatchApplyR4Test.java index d48e1ee9f84..1ffb33d5eb5 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/patch/FhirPatchApplyR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/patch/FhirPatchApplyR4Test.java @@ -1,6 +1,7 @@ package ca.uhn.fhir.jpa.patch; import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.context.FhirVersionEnum; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import org.hl7.fhir.instance.model.api.IBase; import org.hl7.fhir.instance.model.api.IBaseResource; @@ -10,16 +11,16 @@ import org.hl7.fhir.r4.model.IntegerType; import org.hl7.fhir.r4.model.Parameters; import org.hl7.fhir.r4.model.Patient; import org.hl7.fhir.r4.model.StringType; -import org.junit.Test; +import org.junit.jupiter.api.Test; import javax.annotation.Nullable; import java.util.stream.Collectors; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public class FhirPatchApplyR4Test { - private static final FhirContext ourCtx = FhirContext.forR4(); + private static final FhirContext ourCtx = FhirContext.forCached(FhirVersionEnum.R4); @Test public void testInvalidOperation() { diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/patch/BaseFhirPatchCoreTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/patch/FhirPatchCoreTest.java similarity index 64% rename from hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/patch/BaseFhirPatchCoreTest.java rename to hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/patch/FhirPatchCoreTest.java index e7ee5f14f27..b044d489485 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/patch/BaseFhirPatchCoreTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/patch/FhirPatchCoreTest.java @@ -1,14 +1,13 @@ package ca.uhn.fhir.jpa.patch; import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.context.FhirVersionEnum; import ca.uhn.fhir.test.BaseTest; import ca.uhn.fhir.util.ClasspathUtil; import ca.uhn.fhir.util.XmlUtil; import org.hl7.fhir.instance.model.api.IBaseResource; -import org.hl7.fhir.r4.model.Parameters; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.w3c.dom.Document; @@ -23,38 +22,25 @@ import java.util.ArrayList; import java.util.Collection; import java.util.List; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; -@RunWith(Parameterized.class) -public abstract class BaseFhirPatchCoreTest extends BaseTest { +public class FhirPatchCoreTest extends BaseTest { - private static final Logger ourLog = LoggerFactory.getLogger(BaseFhirPatchCoreTest.class); - private final String myName; - private final String myMode; - private final IBaseResource myInput; - private final IBaseResource myPatch; - private final IBaseResource myOutput; + private static final Logger ourLog = LoggerFactory.getLogger(FhirPatchCoreTest.class); - public BaseFhirPatchCoreTest(String theName, String theMode, IBaseResource theInput, IBaseResource thePatch, IBaseResource theOutput) { - myName = theName; - myMode = theMode; - myInput = theInput; - myPatch = thePatch; - myOutput = theOutput; - } - - @Test - public void testApply() { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("parameters") + public void testApply(String myName, String myMode, IBaseResource myInput, IBaseResource myPatch, IBaseResource myOutput, FhirContext theContext) { ourLog.info("Testing diff in {} mode: {}", myMode, myName); if (myMode.equals("both") || myMode.equals("forwards")) { - FhirPatch patch = new FhirPatch(getContext()); + FhirPatch patch = new FhirPatch(theContext); patch.apply(myInput, myPatch); - String expected = getContext().newJsonParser().setPrettyPrint(true).encodeResourceToString(myOutput); - String actual = getContext().newJsonParser().setPrettyPrint(true).encodeResourceToString(myInput); + String expected = theContext.newJsonParser().setPrettyPrint(true).encodeResourceToString(myOutput); + String actual = theContext.newJsonParser().setPrettyPrint(true).encodeResourceToString(myInput); assertEquals(expected, actual); } else { @@ -63,7 +49,19 @@ public abstract class BaseFhirPatchCoreTest extends BaseTest { } - protected abstract FhirContext getContext(); + public static List parameters() throws TransformerException, SAXException, IOException { + String testSpecR4 = "/org/hl7/fhir/testcases/r4/patch/fhir-path-tests.xml"; + Collection retValR4 = loadTestSpec(FhirContext.forCached(FhirVersionEnum.R4), testSpecR4); + + String testSpecR5 = "/org/hl7/fhir/testcases/r5/patch/fhir-path-tests.xml"; + Collection retValR5 = loadTestSpec(FhirContext.forCached(FhirVersionEnum.R5), testSpecR5); + + ArrayList retVal = new ArrayList<>(); + retVal.addAll(retValR4); + retVal.addAll(retValR5); + + return retVal; + } @Nonnull @@ -96,7 +94,7 @@ public abstract class BaseFhirPatchCoreTest extends BaseTest { String outputEncoded = XmlUtil.encodeDocument(outputResourceElement); IBaseResource output = theContext.newXmlParser().parseResource(outputEncoded); - retVal.add(new Object[]{name, mode, input, diff, output}); + retVal.add(new Object[]{name, mode, input, diff, output, theContext}); } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/patch/FhirPatchDiffR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/patch/FhirPatchDiffR4Test.java index 6d3f80de0d5..11e15dec383 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/patch/FhirPatchDiffR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/patch/FhirPatchDiffR4Test.java @@ -1,6 +1,7 @@ package ca.uhn.fhir.jpa.patch; import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.context.FhirVersionEnum; import org.hl7.fhir.instance.model.api.IBase; import org.hl7.fhir.r4.model.BooleanType; import org.hl7.fhir.r4.model.DateTimeType; @@ -10,18 +11,18 @@ import org.hl7.fhir.r4.model.Identifier; import org.hl7.fhir.r4.model.Parameters; import org.hl7.fhir.r4.model.Patient; import org.hl7.fhir.r4.model.StringType; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import static ca.uhn.fhir.jpa.patch.FhirPatchApplyR4Test.extractPartValue; import static ca.uhn.fhir.jpa.patch.FhirPatchApplyR4Test.extractPartValuePrimitive; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public class FhirPatchDiffR4Test { private static final Logger ourLog = LoggerFactory.getLogger(FhirPatchDiffR4Test.class); - private static final FhirContext ourCtx = FhirContext.forR4(); + private static final FhirContext ourCtx = FhirContext.forCached(FhirVersionEnum.R4); @Test public void testReplaceIdentifier() { diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/patch/FhirPatchR4CoreTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/patch/FhirPatchR4CoreTest.java deleted file mode 100644 index 419b263fce7..00000000000 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/patch/FhirPatchR4CoreTest.java +++ /dev/null @@ -1,33 +0,0 @@ -package ca.uhn.fhir.jpa.patch; - -import ca.uhn.fhir.context.FhirContext; -import org.hl7.fhir.instance.model.api.IBaseResource; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.xml.sax.SAXException; - -import javax.xml.transform.TransformerException; -import java.io.IOException; -import java.util.Collection; - -@RunWith(Parameterized.class) -public class FhirPatchR4CoreTest extends BaseFhirPatchCoreTest { - - private static final FhirContext ourCtx = FhirContext.forR4(); - - public FhirPatchR4CoreTest(String theName, String theMode, IBaseResource theInput, IBaseResource thePatch, IBaseResource theOutput) { - super(theName, theMode, theInput, thePatch, theOutput); - } - - @Override - protected FhirContext getContext() { - return ourCtx; - } - - @Parameterized.Parameters(name = "{0}") - public static Collection parameters() throws IOException, SAXException, TransformerException { - String testSpec = "/org/hl7/fhir/testcases/r4/patch/fhir-path-tests.xml"; - return loadTestSpec(ourCtx, testSpec); - } - -} diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/patch/FhirPatchR5CoreTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/patch/FhirPatchR5CoreTest.java deleted file mode 100644 index 67dfbdb643d..00000000000 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/patch/FhirPatchR5CoreTest.java +++ /dev/null @@ -1,33 +0,0 @@ -package ca.uhn.fhir.jpa.patch; - -import ca.uhn.fhir.context.FhirContext; -import org.hl7.fhir.instance.model.api.IBaseResource; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.xml.sax.SAXException; - -import javax.xml.transform.TransformerException; -import java.io.IOException; -import java.util.Collection; - -@RunWith(Parameterized.class) -public class FhirPatchR5CoreTest extends BaseFhirPatchCoreTest { - - private static final FhirContext ourCtx = FhirContext.forR5(); - - public FhirPatchR5CoreTest(String theName, String theMode, IBaseResource theInput, IBaseResource thePatch, IBaseResource theOutput) { - super(theName, theMode, theInput, thePatch, theOutput); - } - - @Override - protected FhirContext getContext() { - return ourCtx; - } - - @Parameterized.Parameters(name = "{0}") - public static Collection parameters() throws IOException, SAXException, TransformerException { - String testSpec = "/org/hl7/fhir/testcases/r5/patch/fhir-path-tests.xml"; - return loadTestSpec(ourCtx, testSpec); - } - -} 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 e877f13d1dc..910122b49a9 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 @@ -21,9 +21,9 @@ import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletHolder; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; import org.springframework.transaction.PlatformTransactionManager; import org.springframework.web.context.ContextLoader; import org.springframework.web.context.WebApplicationContext; @@ -55,13 +55,13 @@ public abstract class BaseResourceProviderDstu2Test extends BaseJpaDstu2Test { } - @After + @AfterEach public void after() throws Exception { myFhirCtx.getRestfulClientFactory().setServerValidationMode(ServerValidationModeEnum.ONCE); } @SuppressWarnings({"unchecked", "rawtypes"}) - @Before + @BeforeEach public void before() throws Exception { myFhirCtx.getRestfulClientFactory().setServerValidationMode(ServerValidationModeEnum.NEVER); myFhirCtx.getRestfulClientFactory().setSocketTimeout(1200 * 1000); @@ -145,7 +145,7 @@ public abstract class BaseResourceProviderDstu2Test extends BaseJpaDstu2Test { return names; } - @AfterClass + @AfterAll public static void afterClassClearContextBaseResourceProviderDstu3Test() throws Exception { JettyUtil.closeServer(ourServer); ourHttpClient.close(); @@ -153,7 +153,6 @@ public abstract class BaseResourceProviderDstu2Test extends BaseJpaDstu2Test { ourHttpClient = null; ourWebApplicationContext.close(); ourWebApplicationContext = null; - TestUtil.clearAllStaticFieldsForUnitTest(); } } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/JpaGraphQLR4ProviderTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/JpaGraphQLR4ProviderTest.java index 90b2b4cc184..fb8ac5800c5 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/JpaGraphQLR4ProviderTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/JpaGraphQLR4ProviderTest.java @@ -1,6 +1,7 @@ package ca.uhn.fhir.jpa.provider; import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.context.FhirVersionEnum; import ca.uhn.fhir.rest.annotation.OptionalParam; import ca.uhn.fhir.rest.annotation.Search; import ca.uhn.fhir.rest.api.Constants; @@ -30,19 +31,19 @@ import org.hl7.fhir.r4.model.Patient; import org.hl7.fhir.r4.model.Resource; import org.hl7.fhir.utilities.graphql.Argument; import org.hl7.fhir.utilities.graphql.IGraphQLStorageServices; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; import java.util.concurrent.TimeUnit; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.startsWith; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; public class JpaGraphQLR4ProviderTest { @@ -50,11 +51,11 @@ public class JpaGraphQLR4ProviderTest { public static final String DATA_PREFIX = "{\"data\": "; public static final String DATA_SUFFIX = "}"; private static CloseableHttpClient ourClient; - private static FhirContext ourCtx = FhirContext.forR4(); + private static FhirContext ourCtx = FhirContext.forCached(FhirVersionEnum.R4); private static int ourPort; private static Server ourServer; - @Before + @BeforeEach public void before() { //nothing } @@ -169,13 +170,12 @@ public class JpaGraphQLR4ProviderTest { } - @AfterClass + @AfterAll public static void afterClassClearContext() throws Exception { JettyUtil.closeServer(ourServer); - TestUtil.clearAllStaticFieldsForUnitTest(); } - @BeforeClass + @BeforeAll public static void beforeClass() throws Exception { ourServer = new Server(0); 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 0cd97fc7eeb..77c3c89e41d 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 @@ -1,5 +1,63 @@ package ca.uhn.fhir.jpa.provider; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.containsInAnyOrder; +import static org.hamcrest.Matchers.containsInRelativeOrder; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.empty; +import static org.hamcrest.Matchers.emptyString; +import static org.hamcrest.Matchers.endsWith; +import static org.hamcrest.Matchers.greaterThan; +import static org.hamcrest.Matchers.hasItems; +import static org.hamcrest.Matchers.not; +import static org.hamcrest.Matchers.startsWith; +import static org.hamcrest.Matchers.stringContainsInOrder; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.InetSocketAddress; +import java.net.Socket; +import java.net.SocketTimeoutException; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Date; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.apache.commons.io.IOUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpDelete; +import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.client.methods.HttpPut; +import org.apache.http.entity.ByteArrayEntity; +import org.apache.http.entity.ContentType; +import org.apache.http.entity.StringEntity; +import org.hl7.fhir.instance.model.api.IBaseBundle; +import org.hl7.fhir.instance.model.api.IBaseResource; +import org.hl7.fhir.instance.model.api.IIdType; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; +import org.springframework.test.util.AopTestUtils; + +import com.google.common.base.Charsets; + import ca.uhn.fhir.jpa.api.config.DaoConfig; import ca.uhn.fhir.jpa.model.util.JpaConstants; import ca.uhn.fhir.jpa.search.SearchCoordinatorSvcImpl; @@ -68,62 +126,6 @@ import ca.uhn.fhir.util.BundleUtil; import ca.uhn.fhir.util.StopWatch; import ca.uhn.fhir.util.TestUtil; import ca.uhn.fhir.util.UrlUtil; -import com.google.common.base.Charsets; -import org.apache.commons.io.IOUtils; -import org.apache.commons.lang3.StringUtils; -import org.apache.http.client.methods.CloseableHttpResponse; -import org.apache.http.client.methods.HttpDelete; -import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.client.methods.HttpPost; -import org.apache.http.client.methods.HttpPut; -import org.apache.http.entity.ByteArrayEntity; -import org.apache.http.entity.ContentType; -import org.apache.http.entity.StringEntity; -import org.hl7.fhir.instance.model.api.IBaseBundle; -import org.hl7.fhir.instance.model.api.IBaseResource; -import org.hl7.fhir.instance.model.api.IIdType; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; -import org.springframework.test.util.AopTestUtils; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.net.InetSocketAddress; -import java.net.Socket; -import java.net.SocketTimeoutException; -import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.Date; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import static org.hamcrest.Matchers.contains; -import static org.hamcrest.Matchers.containsInAnyOrder; -import static org.hamcrest.Matchers.containsInRelativeOrder; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.empty; -import static org.hamcrest.Matchers.emptyString; -import static org.hamcrest.Matchers.endsWith; -import static org.hamcrest.Matchers.greaterThan; -import static org.hamcrest.Matchers.hasItems; -import static org.hamcrest.Matchers.not; -import static org.hamcrest.Matchers.startsWith; -import static org.hamcrest.Matchers.stringContainsInOrder; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test { @@ -131,7 +133,7 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test { private SearchCoordinatorSvcImpl mySearchCoordinatorSvcRaw; @Override - @After + @AfterEach public void after() throws Exception { super.after(); @@ -145,6 +147,7 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test { } + @BeforeEach @Override public void before() throws Exception { super.before(); @@ -152,7 +155,7 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test { myDaoConfig.setAllowMultipleDelete(true); } - @Before + @BeforeEach public void beforeDisableResultReuse() { myDaoConfig.setReuseCachedSearchResultsForMillis(null); mySearchCoordinatorSvcRaw = AopTestUtils.getTargetObject(mySearchCoordinatorSvc); @@ -1065,7 +1068,7 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test { } ourLog.info("$everything: " + ids.toString()); - assertFalse(ids.toString(), dupes); + assertFalse(dupes, ids.toString()); } /* @@ -1086,7 +1089,7 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test { } ourLog.info("$everything: " + ids.toString()); - assertFalse(ids.toString(), dupes); + assertFalse(dupes, ids.toString()); assertThat(ids.toString(), containsString("Condition")); assertThat(ids.size(), greaterThan(10)); } @@ -1352,7 +1355,7 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test { .returnBundle(Bundle.class) .execute(); - assertEquals("nothing matches profile x", Collections.emptyList(), actual.getEntry()); + assertEquals(Collections.emptyList(), actual.getEntry(), "nothing matches profile x"); actual = ourClient.search() .forResource(Organization.class) @@ -1369,7 +1372,7 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test { for (Entry ele : actual.getEntry()) { actualIds.add(ele.getResource().getId().getIdPart()); } - assertEquals("Expects to retrieve the 1 orgination matching on Org1's profiles", expectedIds, actualIds); + assertEquals(expectedIds, actualIds, "Expects to retrieve the 1 orgination matching on Org1's profiles"); actual = ourClient.search() .forResource(Organization.class) @@ -1387,7 +1390,7 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test { for (Entry ele : actual.getEntry()) { actualIds.add(ele.getResource().getId().getIdPart()); } - assertEquals("Expects to retrieve the 2 orginations, since we match on (the common profile AND (Org1's second profile OR org2's second profile))", expectedIds, actualIds); + assertEquals(expectedIds, actualIds, "Expects to retrieve the 2 orginations, since we match on (the common profile AND (Org1's second profile OR org2's second profile))"); } @Test @@ -1580,7 +1583,7 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test { assertEquals(10, response.getEntry().size()); if (ourConnectionPoolSize > 1) { - assertEquals("Total should be null but was " + response.getTotalElement().getValueAsString() + " in " + sw.toString(), null, response.getTotalElement().getValueAsString()); + assertEquals(null, response.getTotalElement().getValueAsString(), "Total should be null but was " + response.getTotalElement().getValueAsString() + " in " + sw.toString()); } assertThat(response.getLink("next").getUrl(), not(emptyString())); @@ -1888,7 +1891,7 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test { for (Entry ele : actual.getEntry()) { actualIds.add(ele.getResource().getId().getIdPart()); } - assertEquals("Expects to retrieve the 2 patients which reference the two different organizations", expectedIds, actualIds); + assertEquals(expectedIds, actualIds, "Expects to retrieve the 2 patients which reference the two different organizations"); } @Test @@ -2116,8 +2119,9 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test { assertEquals(SearchEntryModeEnum.INCLUDE, found.getEntry().get(1).getSearch().getModeElement().getValueAsEnum()); } - @Test(expected = InvalidRequestException.class) + @Test public void testSearchWithInvalidSort() { + try { Observation o = new Observation(); o.getCode().setText("testSearchWithInvalidSort"); myObservationDao.create(o, mySrd); @@ -2127,6 +2131,10 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test { .sort().ascending(Observation.CODE_VALUE_QUANTITY) // composite sort not supported yet .prettyPrint() .execute(); + fail(); + } catch (InvalidRequestException e) { + assertEquals("HTTP 400 Bad Request: This server does not support _sort specifications of type COMPOSITE - Can't serve _sort=code-value-quantity", e.getMessage()); + } } @Test @@ -2144,7 +2152,7 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test { IdDt deletedIdMissingFalse = (IdDt) ourClient.create().resource(org).execute().getId().toUnqualifiedVersionless(); ourClient.delete().resourceById(deletedIdMissingFalse).execute(); - List resources = new ArrayList(); + List resources = new ArrayList<>(); for (int i = 0; i < 20; i++) { org = new Organization(); org.setName(methodName + "_0" + i); @@ -2631,7 +2639,7 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test { * From example from david hay - moved to the hl7org_dstu2 project */ @Test - @Ignore + @Disabled public void testValidateDavidsAllergyIntolerance() throws Exception { myDaoConfig.setAllowExternalReferences(true); @@ -2893,9 +2901,5 @@ public class ResourceProviderDstu2Test extends BaseResourceProviderDstu2Test { } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } } 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 c30e6fe7355..5d2a153e95a 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 @@ -3,17 +3,17 @@ package ca.uhn.fhir.jpa.provider; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.stringContainsInOrder; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.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; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.springframework.transaction.annotation.Transactional; import ca.uhn.fhir.model.dstu2.composite.CodingDt; @@ -31,13 +31,7 @@ public class ResourceProviderDstu2ValueSetTest extends BaseResourceProviderDstu2 private IIdType myExtensionalVsId; private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ResourceProviderDstu2ValueSetTest.class); - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } - - - @Before + @BeforeEach @Transactional public void before02() throws IOException { ValueSet upload = loadResourceFromClasspath(ValueSet.class, "/extensional-case-2.xml"); @@ -99,7 +93,7 @@ public class ResourceProviderDstu2ValueSetTest extends BaseResourceProviderDstu2 } @Test - @Ignore + @Disabled public void testLookupOperationForBuiltInCode() { Parameters respParam = ourClient .operation() diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/ResourceProviderExpungeDstu2Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/ResourceProviderExpungeDstu2Test.java index 9b8541c08ae..cb435e12288 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/ResourceProviderExpungeDstu2Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/ResourceProviderExpungeDstu2Test.java @@ -11,13 +11,13 @@ import ca.uhn.fhir.rest.server.exceptions.ResourceGoneException; import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException; import ca.uhn.fhir.util.TestUtil; import org.hl7.fhir.instance.model.api.IIdType; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; public class ResourceProviderExpungeDstu2Test extends BaseResourceProviderDstu2Test { private IIdType myOneVersionPatientId; @@ -27,7 +27,7 @@ public class ResourceProviderExpungeDstu2Test extends BaseResourceProviderDstu2T private IIdType myTwoVersionObservationId; private IIdType myDeletedObservationId; - @After + @AfterEach public void afterDisableExpunge() { myDaoConfig.setExpungeEnabled(new DaoConfig().isExpungeEnabled()); } @@ -55,7 +55,7 @@ public class ResourceProviderExpungeDstu2Test extends BaseResourceProviderDstu2T } @Override - @Before + @BeforeEach public void before() throws Exception { super.before(); @@ -104,7 +104,7 @@ public class ResourceProviderExpungeDstu2Test extends BaseResourceProviderDstu2T } - @Before + @BeforeEach public void beforeEnableExpunge() { myDaoConfig.setExpungeEnabled(true); } @@ -288,9 +288,5 @@ public class ResourceProviderExpungeDstu2Test extends BaseResourceProviderDstu2T assertGone(myDeletedObservationId); } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } } 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 ea440839852..d5210186f4e 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 @@ -1,9 +1,10 @@ package ca.uhn.fhir.jpa.provider; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -import org.junit.AfterClass; -import org.junit.Test; +import ca.uhn.fhir.context.FhirVersionEnum; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.jpa.searchparam.SearchParameterMap; @@ -16,13 +17,7 @@ import ca.uhn.fhir.util.TestUtil; import ca.uhn.fhir.util.UrlUtil; public class SearchParameterMapTest { - - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } - - private static FhirContext ourCtx = FhirContext.forDstu3(); + private static FhirContext ourCtx = FhirContext.forCached(FhirVersionEnum.DSTU3); @Test 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 12c650e1904..2641039df16 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 @@ -13,41 +13,42 @@ import org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage; import org.eclipse.jetty.websocket.api.annotations.WebSocket; import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IIdType; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.util.ArrayList; import java.util.List; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.in; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; public class SubscriptionsDstu2Test extends BaseResourceProviderDstu2Test { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(SubscriptionsDstu2Test.class); private SubscriptionsRequireManualActivationInterceptorDstu2 myInterceptor; - @Before + @BeforeEach public void beforeCreateInterceptor() { myInterceptor = new SubscriptionsRequireManualActivationInterceptorDstu2(); myInterceptor.setDao(mySubscriptionDao); myInterceptorRegistry.registerInterceptor(myInterceptor); } - @After + @AfterEach public void afterDestroyInterceptor() { myInterceptorRegistry.unregisterInterceptor(myInterceptor); } - @Before + @BeforeEach public void beforeDisableResultReuse() { myDaoConfig.setReuseCachedSearchResultsForMillis(null); } - @Before + @BeforeEach public void beforeEnableScheduling() { myDaoConfig.setSchedulingDisabled(false); } @@ -176,11 +177,6 @@ public class SubscriptionsDstu2Test extends BaseResourceProviderDstu2Test { ourClient.update().resource(subs).execute(); } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } - public class BaseSocket { protected String myError; protected boolean myGotBound; 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 f3f9f518d56..e38bcd3c903 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 @@ -1,6 +1,7 @@ package ca.uhn.fhir.jpa.provider; import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.context.FhirVersionEnum; import ca.uhn.fhir.jpa.dao.dstu2.BaseJpaDstu2Test; import ca.uhn.fhir.jpa.rp.dstu2.*; import ca.uhn.fhir.model.dstu2.resource.*; @@ -30,10 +31,10 @@ import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletHolder; import org.hl7.fhir.instance.model.api.IIdType; import org.hl7.fhir.r4.model.IdType; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; @@ -42,8 +43,9 @@ import java.io.InputStream; import java.nio.charset.StandardCharsets; import java.util.concurrent.TimeUnit; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import ca.uhn.fhir.test.utilities.JettyUtil; @@ -57,7 +59,7 @@ public class SystemProviderDstu2Test extends BaseJpaDstu2Test { private static Server ourServer; private static String ourServerBase; - @Before + @BeforeEach public void beforeStartServer() throws Exception { if (myRestServer == null) { PatientResourceProvider patientRp = new PatientResourceProvider(); @@ -101,7 +103,7 @@ public class SystemProviderDstu2Test extends BaseJpaDstu2Test { servletHolder.setServlet(restServer); proxyHandler.addServlet(servletHolder, "/fhir/context/*"); - ourCtx = FhirContext.forDstu2(); + ourCtx = FhirContext.forCached(FhirVersionEnum.DSTU2); restServer.setFhirContext(ourCtx); ourServer.setHandler(proxyHandler); @@ -293,7 +295,7 @@ public class SystemProviderDstu2Test extends BaseJpaDstu2Test { } @Test - @Ignore + @Disabled public void testTransactionReSavesPreviouslyDeletedResources() throws IOException { for (int i = 0; i < 10; i++) { @@ -380,7 +382,7 @@ public class SystemProviderDstu2Test extends BaseJpaDstu2Test { * This is Gramahe's test transaction - it requires some set up in order to work */ @Test - @Ignore + @Disabled public void testTransactionFromBundle3() throws Exception { InputStream bundleRes = SystemProviderDstu2Test.class.getResourceAsStream("/grahame-transaction.xml"); @@ -490,10 +492,9 @@ public class SystemProviderDstu2Test extends BaseJpaDstu2Test { } } - @AfterClass + @AfterAll public static void afterClassClearContext() throws Exception { JettyUtil.closeServer(ourServer); - TestUtil.clearAllStaticFieldsForUnitTest(); } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/SystemProviderTransactionSearchDstu2Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/SystemProviderTransactionSearchDstu2Test.java index c98215523b9..4291cc754c8 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/SystemProviderTransactionSearchDstu2Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/SystemProviderTransactionSearchDstu2Test.java @@ -1,6 +1,7 @@ package ca.uhn.fhir.jpa.provider; import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.context.FhirVersionEnum; import ca.uhn.fhir.jpa.api.config.DaoConfig; import ca.uhn.fhir.jpa.dao.dstu2.BaseJpaDstu2Test; import ca.uhn.fhir.jpa.rp.dstu2.ObservationResourceProvider; @@ -17,29 +18,28 @@ import ca.uhn.fhir.rest.client.api.IGenericClient; import ca.uhn.fhir.rest.client.interceptor.SimpleRequestHeaderInterceptor; import ca.uhn.fhir.rest.server.RestfulServer; import ca.uhn.fhir.test.utilities.JettyUtil; -import ca.uhn.fhir.util.TestUtil; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletHolder; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.util.ArrayList; import java.util.List; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.nullValue; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; public class SystemProviderTransactionSearchDstu2Test extends BaseJpaDstu2Test { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(SystemProviderTransactionSearchDstu2Test.class); private static RestfulServer myRestServer; - private static IGenericClient ourClient; + private IGenericClient myClient; private static FhirContext ourCtx; private static Server ourServer; private static String ourServerBase; @@ -47,19 +47,13 @@ public class SystemProviderTransactionSearchDstu2Test extends BaseJpaDstu2Test { @SuppressWarnings("deprecation") - @After + @AfterEach public void after() { - ourClient.unregisterInterceptor(mySimpleHeaderInterceptor); + myClient.unregisterInterceptor(mySimpleHeaderInterceptor); myDaoConfig.setMaximumSearchResultCountInTransaction(new DaoConfig().getMaximumSearchResultCountInTransaction()); } - @Before - public void before() { - mySimpleHeaderInterceptor = new SimpleRequestHeaderInterceptor(); - ourClient.registerInterceptor(mySimpleHeaderInterceptor); - } - - @Before + @BeforeEach public void beforeStartServer() throws Exception { if (myRestServer == null) { PatientResourceProvider patientRp = new PatientResourceProvider(); @@ -88,23 +82,26 @@ public class SystemProviderTransactionSearchDstu2Test extends BaseJpaDstu2Test { servletHolder.setServlet(restServer); proxyHandler.addServlet(servletHolder, "/fhir/context/*"); - ourCtx = FhirContext.forDstu2(); + ourCtx = FhirContext.forCached(FhirVersionEnum.DSTU2); restServer.setFhirContext(ourCtx); ourServer.setHandler(proxyHandler); JettyUtil.startServer(ourServer); - int myPort = JettyUtil.getPortForStartedServer(ourServer); + int myPort = JettyUtil.getPortForStartedServer(ourServer); ourServerBase = "http://localhost:" + myPort + "/fhir/context"; - ourCtx.getRestfulClientFactory().setSocketTimeout(600 * 1000); - ourClient = ourCtx.newRestfulGenericClient(ourServerBase); myRestServer = restServer; } myRestServer.setDefaultResponseEncoding(EncodingEnum.XML); myRestServer.setPagingProvider(myPagingProvider); - } + ourCtx.getRestfulClientFactory().setSocketTimeout(600 * 1000); + myClient = ourCtx.newRestfulGenericClient(ourServerBase); + + mySimpleHeaderInterceptor = new SimpleRequestHeaderInterceptor(); + myClient.registerInterceptor(mySimpleHeaderInterceptor); + } private List create20Patients() { List ids = new ArrayList(); @@ -133,7 +130,7 @@ public class SystemProviderTransactionSearchDstu2Test extends BaseJpaDstu2Test { myDaoConfig.setMaximumSearchResultCountInTransaction(100); - Bundle output = ourClient.transaction().withBundle(input).execute(); + Bundle output = myClient.transaction().withBundle(input).execute(); ourLog.info(myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(output)); assertEquals(1, output.getEntry().size()); @@ -156,7 +153,7 @@ public class SystemProviderTransactionSearchDstu2Test extends BaseJpaDstu2Test { .setMethod(HTTPVerbEnum.GET) .setUrl("Patient?_count=5&_sort=name"); - Bundle output = ourClient.transaction().withBundle(input).execute(); + Bundle output = myClient.transaction().withBundle(input).execute(); ourLog.info(myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(output)); assertEquals(1, output.getEntry().size()); @@ -166,7 +163,7 @@ public class SystemProviderTransactionSearchDstu2Test extends BaseJpaDstu2Test { assertThat(actualIds, contains(ids.subList(0, 5).toArray(new String[0]))); String nextPageLink = respBundle.getLink("next").getUrl(); - output = ourClient.loadPage().byUrl(nextPageLink).andReturnBundle(Bundle.class).execute(); + output = myClient.loadPage().byUrl(nextPageLink).andReturnBundle(Bundle.class).execute(); respBundle = output; assertEquals(5, respBundle.getEntry().size()); actualIds = toIds(respBundle); @@ -191,7 +188,7 @@ public class SystemProviderTransactionSearchDstu2Test extends BaseJpaDstu2Test { .setUrl("Patient?_count=5&identifier=urn:foo|A,AAAAA" + i); } - Bundle output = ourClient.transaction().withBundle(input).execute(); + Bundle output = myClient.transaction().withBundle(input).execute(); ourLog.info(myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(output)); assertEquals(30, output.getEntry().size()); @@ -218,7 +215,7 @@ public class SystemProviderTransactionSearchDstu2Test extends BaseJpaDstu2Test { myDaoConfig.setMaximumSearchResultCountInTransaction(100); - Bundle output = ourClient.transaction().withBundle(input).execute(); + Bundle output = myClient.transaction().withBundle(input).execute(); ourLog.info(myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(output)); assertEquals(1, output.getEntry().size()); @@ -241,7 +238,7 @@ public class SystemProviderTransactionSearchDstu2Test extends BaseJpaDstu2Test { .setMethod(HTTPVerbEnum.GET) .setUrl("Patient?_count=5&_sort=name"); - Bundle output = ourClient.transaction().withBundle(input).execute(); + Bundle output = myClient.transaction().withBundle(input).execute(); ourLog.info(myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(output)); assertEquals(1, output.getEntry().size()); @@ -251,7 +248,7 @@ public class SystemProviderTransactionSearchDstu2Test extends BaseJpaDstu2Test { assertThat(actualIds, contains(ids.subList(0, 5).toArray(new String[0]))); String nextPageLink = respBundle.getLink("next").getUrl(); - output = ourClient.loadPage().byUrl(nextPageLink).andReturnBundle(Bundle.class).execute(); + output = myClient.loadPage().byUrl(nextPageLink).andReturnBundle(Bundle.class).execute(); respBundle = output; assertEquals(5, respBundle.getEntry().size()); actualIds = toIds(respBundle); @@ -276,7 +273,7 @@ public class SystemProviderTransactionSearchDstu2Test extends BaseJpaDstu2Test { .setUrl("Patient?_count=5&identifier=urn:foo|A,AAAAA" + i); } - Bundle output = ourClient.transaction().withBundle(input).execute(); + Bundle output = myClient.transaction().withBundle(input).execute(); ourLog.info(myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(output)); assertEquals(30, output.getEntry().size()); @@ -290,17 +287,16 @@ public class SystemProviderTransactionSearchDstu2Test extends BaseJpaDstu2Test { } private List toIds(Bundle theRespBundle) { - ArrayList retVal = new ArrayList(); + ArrayList retVal = new ArrayList<>(); for (Entry next : theRespBundle.getEntry()) { retVal.add(next.getResource().getIdElement().toUnqualifiedVersionless().getValue()); } return retVal; } - @AfterClass + @AfterAll public static void afterClassClearContext() throws Exception { JettyUtil.closeServer(ourServer); - TestUtil.clearAllStaticFieldsForUnitTest(); } } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/TerminologyUploaderProviderTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/TerminologyUploaderProviderTest.java index 4e1376e16bc..e40c255f6c3 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/TerminologyUploaderProviderTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/TerminologyUploaderProviderTest.java @@ -1,18 +1,19 @@ package ca.uhn.fhir.jpa.provider; import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.context.FhirVersionEnum; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import ca.uhn.fhir.test.BaseTest; import org.hl7.fhir.r4.model.CodeSystem; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public class TerminologyUploaderProviderTest extends BaseTest { @Test public void testCanonicalizeR3() { TerminologyUploaderProvider provider = new TerminologyUploaderProvider(); - provider.setContext(FhirContext.forDstu3()); + provider.setContext(FhirContext.forCached(FhirVersionEnum.DSTU3)); org.hl7.fhir.dstu3.model.CodeSystem input = new org.hl7.fhir.dstu3.model.CodeSystem(); input.addConcept().setCode("FOO").setDisplay("Foo"); @@ -25,7 +26,7 @@ public class TerminologyUploaderProviderTest extends BaseTest { @Test public void testCanonicalizeR4() { TerminologyUploaderProvider provider = new TerminologyUploaderProvider(); - provider.setContext(FhirContext.forR4()); + provider.setContext(FhirContext.forCached(FhirVersionEnum.R4)); org.hl7.fhir.r4.model.CodeSystem input = new org.hl7.fhir.r4.model.CodeSystem(); input.addConcept().setCode("FOO").setDisplay("Foo"); @@ -38,7 +39,7 @@ public class TerminologyUploaderProviderTest extends BaseTest { @Test public void testCanonicalizeR5() { TerminologyUploaderProvider provider = new TerminologyUploaderProvider(); - provider.setContext(FhirContext.forR5()); + provider.setContext(FhirContext.forCached(FhirVersionEnum.R5)); org.hl7.fhir.r5.model.CodeSystem input = new org.hl7.fhir.r5.model.CodeSystem(); input.addConcept().setCode("FOO").setDisplay("Foo"); @@ -51,7 +52,7 @@ public class TerminologyUploaderProviderTest extends BaseTest { @Test public void testCanonicalizeR5_WrongType() { TerminologyUploaderProvider provider = new TerminologyUploaderProvider(); - provider.setContext(FhirContext.forR5()); + provider.setContext(FhirContext.forCached(FhirVersionEnum.R5)); org.hl7.fhir.r5.model.Patient input = new org.hl7.fhir.r5.model.Patient(); 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 1dc0356cc9f..b1a36411e3d 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 @@ -30,9 +30,9 @@ import org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent; import org.hl7.fhir.dstu3.model.Parameters; import org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent; import org.hl7.fhir.dstu3.model.Patient; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; import org.springframework.web.context.ContextLoader; import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; @@ -68,7 +68,7 @@ public abstract class BaseResourceProviderDstu3Test extends BaseJpaDstu3Test { super(); } - @After + @AfterEach public void after() throws Exception { myFhirCtx.getRestfulClientFactory().setServerValidationMode(ServerValidationModeEnum.ONCE); myResourceCountsCache.clear(); @@ -76,7 +76,7 @@ public abstract class BaseResourceProviderDstu3Test extends BaseJpaDstu3Test { } @SuppressWarnings({"unchecked", "rawtypes"}) - @Before + @BeforeEach public void before() throws Exception { myResourceCountsCache.clear(); myFhirCtx.getRestfulClientFactory().setServerValidationMode(ServerValidationModeEnum.NEVER); @@ -192,7 +192,7 @@ public abstract class BaseResourceProviderDstu3Test extends BaseJpaDstu3Test { return names; } - @AfterClass + @AfterAll public static void afterClassClearContextBaseResourceProviderDstu3Test() throws Exception { JettyUtil.closeServer(ourServer); ourHttpClient.close(); @@ -202,7 +202,6 @@ public abstract class BaseResourceProviderDstu3Test extends BaseJpaDstu3Test { myValidationSupport = null; ourWebApplicationContext.close(); ourWebApplicationContext = null; - TestUtil.clearAllStaticFieldsForUnitTest(); } public static int getNumberOfParametersByName(Parameters theParameters, String theName) { diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/CompositionDocumentDstu3Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/CompositionDocumentDstu3Test.java index d9d43ec1121..2268a0e231a 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/CompositionDocumentDstu3Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/CompositionDocumentDstu3Test.java @@ -20,10 +20,10 @@ import org.hl7.fhir.dstu3.model.Observation.ObservationStatus; import org.hl7.fhir.dstu3.model.Organization; import org.hl7.fhir.dstu3.model.Patient; import org.hl7.fhir.dstu3.model.Reference; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import java.io.IOException; import java.util.ArrayList; @@ -31,10 +31,10 @@ import java.util.HashSet; import java.util.List; import java.util.Set; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.hasItem; import static org.hamcrest.Matchers.hasItems; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThat; +import static org.junit.jupiter.api.Assertions.assertNull; public class CompositionDocumentDstu3Test extends BaseResourceProviderDstu3Test { @@ -46,13 +46,13 @@ public class CompositionDocumentDstu3Test extends BaseResourceProviderDstu3Test private String listId; private String compId; - @Before + @BeforeEach public void beforeDisableResultReuse() { myDaoConfig.setReuseCachedSearchResultsForMillis(null); } @Override - @After + @AfterEach public void after() throws Exception { super.after(); @@ -60,6 +60,7 @@ public class CompositionDocumentDstu3Test extends BaseResourceProviderDstu3Test } @Override + @BeforeEach public void before() throws Exception { super.before(); myFhirCtx.setParserErrorHandler(new StrictErrorHandler()); @@ -142,8 +143,4 @@ public class CompositionDocumentDstu3Test extends BaseResourceProviderDstu3Test return bundle; } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/CorsDstu3Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/CorsDstu3Test.java index 2047426b528..995456956cd 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/CorsDstu3Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/CorsDstu3Test.java @@ -1,14 +1,14 @@ package ca.uhn.fhir.jpa.provider.dstu3; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.io.IOException; import org.apache.commons.io.IOUtils; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; -import org.junit.AfterClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; import ca.uhn.fhir.util.TestUtil; @@ -28,10 +28,4 @@ public class CorsDstu3Test extends BaseResourceProviderDstu3Test { assertEquals(200, resp.getStatusLine().getStatusCode()); } - - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } - } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/GraphQLProviderDstu3Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/GraphQLProviderDstu3Test.java index 110b9a7a43b..bdacba5605a 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/GraphQLProviderDstu3Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/GraphQLProviderDstu3Test.java @@ -7,7 +7,7 @@ import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; import org.hl7.fhir.dstu3.model.Patient; import org.hl7.fhir.instance.model.api.IIdType; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -16,7 +16,7 @@ import java.nio.charset.StandardCharsets; import static ca.uhn.fhir.jpa.provider.JpaGraphQLR4ProviderTest.DATA_PREFIX; import static ca.uhn.fhir.jpa.provider.JpaGraphQLR4ProviderTest.DATA_SUFFIX; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public class GraphQLProviderDstu3Test extends BaseResourceProviderDstu3Test { private Logger ourLog = LoggerFactory.getLogger(GraphQLProviderDstu3Test.class); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/PatientEverythingDstu3Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/PatientEverythingDstu3Test.java index d9b9ac77957..3fe6ec041d1 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/PatientEverythingDstu3Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/PatientEverythingDstu3Test.java @@ -9,22 +9,33 @@ import org.apache.commons.io.IOUtils; import org.apache.http.client.ClientProtocolException; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; -import org.hl7.fhir.dstu3.model.*; +import org.hl7.fhir.dstu3.model.Bundle; import org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent; +import org.hl7.fhir.dstu3.model.Encounter; import org.hl7.fhir.dstu3.model.Encounter.EncounterStatus; +import org.hl7.fhir.dstu3.model.Observation; import org.hl7.fhir.dstu3.model.Observation.ObservationStatus; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Test; +import org.hl7.fhir.dstu3.model.Organization; +import org.hl7.fhir.dstu3.model.Patient; +import org.hl7.fhir.dstu3.model.Reference; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.io.IOException; import java.util.ArrayList; import java.util.Set; import java.util.TreeSet; -import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.hasItem; +import static org.hamcrest.Matchers.hasItems; +import static org.hamcrest.Matchers.not; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; public class PatientEverythingDstu3Test extends BaseResourceProviderDstu3Test { @@ -39,13 +50,13 @@ public class PatientEverythingDstu3Test extends BaseResourceProviderDstu3Test { private Organization myOrg; private Patient myPatient; - @Before + @BeforeEach public void beforeDisableResultReuse() { myDaoConfig.setReuseCachedSearchResultsForMillis(null); } @Override - @After + @AfterEach public void after() throws Exception { super.after(); @@ -53,6 +64,7 @@ public class PatientEverythingDstu3Test extends BaseResourceProviderDstu3Test { myDaoConfig.setEverythingIncludesFetchPageSize(new DaoConfig().getEverythingIncludesFetchPageSize()); } + @BeforeEach @Override public void before() throws Exception { super.before(); @@ -147,7 +159,7 @@ public class PatientEverythingDstu3Test extends BaseResourceProviderDstu3Test { assertNull(bundle.getLink("next")); - Set actual = new TreeSet(); + Set actual = new TreeSet<>(); for (BundleEntryComponent nextEntry : bundle.getEntry()) { actual.add(nextEntry.getResource().getIdElement().toUnqualifiedVersionless().getValue()); } @@ -243,9 +255,5 @@ public class PatientEverythingDstu3Test extends BaseResourceProviderDstu3Test { return bundle; } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderCustomSearchParamDstu3Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderCustomSearchParamDstu3Test.java index ca6c479698c..83870680c87 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderCustomSearchParamDstu3Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderCustomSearchParamDstu3Test.java @@ -14,18 +14,26 @@ import ca.uhn.fhir.util.TestUtil; import org.apache.commons.io.IOUtils; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; -import org.hl7.fhir.dstu3.model.*; +import org.hl7.fhir.dstu3.model.Appointment; +import org.hl7.fhir.dstu3.model.Bundle; +import org.hl7.fhir.dstu3.model.CapabilityStatement; import org.hl7.fhir.dstu3.model.CapabilityStatement.CapabilityStatementRestComponent; import org.hl7.fhir.dstu3.model.CapabilityStatement.CapabilityStatementRestResourceComponent; import org.hl7.fhir.dstu3.model.CapabilityStatement.CapabilityStatementRestResourceSearchParamComponent; +import org.hl7.fhir.dstu3.model.CodeType; import org.hl7.fhir.dstu3.model.Enumerations.AdministrativeGender; +import org.hl7.fhir.dstu3.model.Observation; import org.hl7.fhir.dstu3.model.Observation.ObservationStatus; +import org.hl7.fhir.dstu3.model.Patient; +import org.hl7.fhir.dstu3.model.Practitioner; +import org.hl7.fhir.dstu3.model.Reference; +import org.hl7.fhir.dstu3.model.SearchParameter; import org.hl7.fhir.dstu3.model.SearchParameter.XPathUsageType; import org.hl7.fhir.instance.model.api.IIdType; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.transaction.TransactionStatus; import org.springframework.transaction.support.TransactionCallbackWithoutResult; import org.springframework.transaction.support.TransactionTemplate; @@ -35,16 +43,20 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.containsString; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.fail; public class ResourceProviderCustomSearchParamDstu3Test extends BaseResourceProviderDstu3Test { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ResourceProviderCustomSearchParamDstu3Test.class); @Override - @After + @AfterEach public void after() throws Exception { super.after(); @@ -52,12 +64,7 @@ public class ResourceProviderCustomSearchParamDstu3Test extends BaseResourceProv } @Override - public void before() throws Exception { - super.before(); - } - - @Override - @Before + @BeforeEach public void beforeResetConfig() { super.beforeResetConfig(); @@ -376,9 +383,5 @@ public class ResourceProviderCustomSearchParamDstu3Test extends BaseResourceProv } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderDeleteSqlDstu3Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderDeleteSqlDstu3Test.java index 8fa2bd63c3d..aff375c7a0f 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderDeleteSqlDstu3Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderDeleteSqlDstu3Test.java @@ -5,14 +5,14 @@ import ca.uhn.fhir.jpa.util.SqlQuery; import org.hl7.fhir.dstu3.model.CodeableConcept; import org.hl7.fhir.dstu3.model.Observation; import org.hl7.fhir.instance.model.api.IIdType; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import java.util.stream.Collectors; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public class ResourceProviderDeleteSqlDstu3Test extends BaseResourceProviderDstu3Test { diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderDstu3BundleTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderDstu3BundleTest.java index d77bba5e503..b9dc4c6f396 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderDstu3BundleTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderDstu3BundleTest.java @@ -4,15 +4,13 @@ import ca.uhn.fhir.jpa.model.util.JpaConstants; import ca.uhn.fhir.rest.server.exceptions.NotImplementedOperationException; import ca.uhn.fhir.util.TestUtil; import org.hl7.fhir.dstu3.model.Bundle; -import org.hl7.fhir.dstu3.model.Bundle.BundleType; -import org.hl7.fhir.dstu3.model.Composition; import org.hl7.fhir.dstu3.model.Parameters; -import org.hl7.fhir.instance.model.api.IIdType; -import org.junit.AfterClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; import static org.hamcrest.CoreMatchers.containsString; -import static org.junit.Assert.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.fail; public class ResourceProviderDstu3BundleTest extends BaseResourceProviderDstu3Test { @@ -37,10 +35,5 @@ public class ResourceProviderDstu3BundleTest extends BaseResourceProviderDstu3Te } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } - } 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 b52a67c22db..132bdd8fe15 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 @@ -1,6 +1,7 @@ package ca.uhn.fhir.jpa.provider.dstu3; import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.context.FhirVersionEnum; import ca.uhn.fhir.jpa.dao.dstu3.FhirResourceDaoDstu3TerminologyTest; import ca.uhn.fhir.jpa.term.TermReindexingSvcImpl; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; @@ -9,22 +10,22 @@ import ca.uhn.fhir.util.TestUtil; import org.hl7.fhir.dstu3.model.*; 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.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.transaction.annotation.Transactional; import java.io.IOException; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; public class ResourceProviderDstu3CodeSystemTest extends BaseResourceProviderDstu3Test { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ResourceProviderDstu3CodeSystemTest.class); - public static FhirContext ourCtx = FhirContext.forDstu3(); + public static FhirContext ourCtx = FhirContext.forCached(FhirVersionEnum.DSTU3); - @Before + @BeforeEach @Transactional public void before02() throws IOException { CodeSystem cs = loadResourceFromClasspath(CodeSystem.class, "/extensional-case-3-cs.xml"); @@ -331,10 +332,6 @@ public class ResourceProviderDstu3CodeSystemTest extends BaseResourceProviderDst return ourCtx.newJsonParser().parseResource(theType, loadResource(theFilename)); } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderDstu3ConceptMapTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderDstu3ConceptMapTest.java index ee316210a3a..c64e531fdf4 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderDstu3ConceptMapTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderDstu3ConceptMapTest.java @@ -5,26 +5,22 @@ import ca.uhn.fhir.util.TestUtil; import org.hl7.fhir.dstu3.model.*; import org.hl7.fhir.dstu3.model.Parameters.ParametersParameterComponent; import org.hl7.fhir.instance.model.api.IIdType; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.transaction.annotation.Transactional; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; public class ResourceProviderDstu3ConceptMapTest extends BaseResourceProviderDstu3Test { private static final Logger ourLog = LoggerFactory.getLogger(ResourceProviderDstu3ConceptMapTest.class); private IIdType myConceptMapId; - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } - @Before + @BeforeEach @Transactional public void before02() { myConceptMapId = myConceptMapDao.create(createConceptMap(), mySrd).getId().toUnqualifiedVersionless(); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderDstu3DistanceTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderDstu3DistanceTest.java index 75f492e45da..bca55e8f918 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderDstu3DistanceTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderDstu3DistanceTest.java @@ -5,14 +5,16 @@ import org.hl7.fhir.dstu3.model.Bundle; import org.hl7.fhir.dstu3.model.Location; import org.hl7.fhir.dstu3.model.PractitionerRole; import org.hl7.fhir.instance.model.api.IIdType; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.net.URLEncoder; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public class ResourceProviderDstu3DistanceTest extends BaseResourceProviderDstu3Test { + @BeforeEach @Override public void before() throws Exception { super.before(); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderDstu3StructureDefinitionTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderDstu3StructureDefinitionTest.java index ff9e7ca5ddd..6a096df970f 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderDstu3StructureDefinitionTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderDstu3StructureDefinitionTest.java @@ -9,19 +9,15 @@ import org.hl7.fhir.dstu3.model.Parameters; import org.hl7.fhir.dstu3.model.StringType; import org.hl7.fhir.dstu3.model.StructureDefinition; import org.hl7.fhir.instance.model.api.IIdType; -import org.junit.AfterClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; import java.io.IOException; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public class ResourceProviderDstu3StructureDefinitionTest extends BaseResourceProviderDstu3Test { - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } @Test public void testSnapshotWithResourceParameter() 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 0aca3eb2369..3be5b845c50 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 @@ -112,10 +112,11 @@ 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.After; -import org.junit.AfterClass; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.util.AopTestUtils; import org.springframework.transaction.TransactionStatus; @@ -139,29 +140,14 @@ import java.util.Set; import java.util.TreeSet; import static org.apache.commons.lang3.StringUtils.isNotBlank; -import static org.hamcrest.Matchers.contains; -import static org.hamcrest.Matchers.containsInAnyOrder; -import static org.hamcrest.Matchers.containsInRelativeOrder; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.empty; -import static org.hamcrest.Matchers.emptyString; -import static org.hamcrest.Matchers.endsWith; -import static org.hamcrest.Matchers.greaterThan; -import static org.hamcrest.Matchers.hasItem; -import static org.hamcrest.Matchers.hasItems; -import static org.hamcrest.Matchers.hasSize; -import static org.hamcrest.Matchers.lessThanOrEqualTo; -import static org.hamcrest.Matchers.matchesPattern; -import static org.hamcrest.Matchers.not; -import static org.hamcrest.Matchers.startsWith; -import static org.hamcrest.Matchers.stringContainsInOrder; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test { @@ -171,7 +157,7 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test { private ISearchDao mySearchEntityDao; @Override - @After + @AfterEach public void after() throws Exception { super.after(); @@ -281,6 +267,7 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test { } } + @BeforeEach @Override public void before() throws Exception { super.before(); @@ -613,7 +600,7 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test { } @Override - public void interceptResponse(IHttpResponse theResponse) throws IOException { // TODO Auto-generated method stu + public void interceptResponse(IHttpResponse theResponse) { // TODO Auto-generated method stu } }); @@ -641,7 +628,7 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test { } @Test - @Ignore + @Disabled public void testCreateQuestionnaireResponseWithValidation() { CodeSystem cs = new CodeSystem(); cs.setUrl("http://urn/system"); @@ -1393,7 +1380,7 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test { } ourLog.info("$everything: " + ids.toString()); - assertFalse(ids.toString(), dupes); + assertFalse(dupes, ids.toString()); } /* @@ -1414,7 +1401,7 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test { } ourLog.info("$everything: " + ids.toString()); - assertFalse(ids.toString(), dupes); + assertFalse(dupes, ids.toString()); assertThat(ids.toString(), containsString("Condition")); assertThat(ids.size(), greaterThan(10)); } @@ -2745,7 +2732,7 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test { for (BundleEntryComponent ele : actual.getEntry()) { actualIds.add(ele.getResource().getIdElement().getIdPart()); } - assertEquals("Expects to retrieve the 2 patients which reference the two different organizations", expectedIds, actualIds); + assertEquals(expectedIds, actualIds, "Expects to retrieve the 2 patients which reference the two different organizations"); } @Test @@ -3000,7 +2987,7 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test { ourLog.info(value.getTime() + ""); ourLog.info(before.getTime() + ""); assertTrue(value.after(before)); - assertTrue(new InstantDt(value) + " should be before " + new InstantDt(after), value.before(after)); + assertTrue(value.before(after), new InstantDt(value) + " should be before " + new InstantDt(after)); } @Test @@ -3371,12 +3358,12 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test { } - @Test(expected = InvalidRequestException.class) + @Test public void testSearchWithInvalidSort() { + try { Observation o = new Observation(); o.getCode().setText("testSearchWithInvalidSort"); myObservationDao.create(o, mySrd); - //@formatter:off ourClient .search() .forResource(Observation.class) @@ -3384,7 +3371,10 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test { .prettyPrint() .returnBundle(Bundle.class) .execute(); - //@formatter:on + fail(); + } catch (InvalidRequestException e) { + assertEquals("HTTP 400 Bad Request: This server does not support _sort specifications of type COMPOSITE - Can't serve _sort=code-value-quantity", e.getMessage()); + } } @Test @@ -3402,7 +3392,7 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test { IIdType deletedIdMissingFalse = ourClient.create().resource(org).execute().getId().toUnqualifiedVersionless(); ourClient.delete().resourceById(deletedIdMissingFalse).execute(); - List resources = new ArrayList(); + List resources = new ArrayList<>(); for (int i = 0; i < 20; i++) { org = new Organization(); org.setName(methodName + "_0" + i); @@ -3770,7 +3760,7 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test { * This does not currently cause an error, so this test is disabled */ @Test - @Ignore + @Disabled public void testUpdateNoIdInBody() throws Exception { String methodName = "testUpdateNoIdInBody"; @@ -4378,9 +4368,5 @@ public class ResourceProviderDstu3Test extends BaseResourceProviderDstu3Test { return new InstantDt(theDate).getValueAsString(); } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } } 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 e260c82933e..882e7365637 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 @@ -36,9 +36,9 @@ import org.hl7.fhir.dstu3.model.ValueSet; import org.hl7.fhir.dstu3.model.ValueSet.ConceptSetComponent; import org.hl7.fhir.dstu3.model.ValueSet.FilterOperator; import org.hl7.fhir.instance.model.api.IIdType; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; import org.springframework.transaction.TransactionStatus; import org.springframework.transaction.support.TransactionCallbackWithoutResult; import org.springframework.transaction.support.TransactionTemplate; @@ -51,11 +51,8 @@ import java.util.List; import static ca.uhn.fhir.jpa.dao.dstu3.FhirResourceDaoDstu3TerminologyTest.URL_MY_CODE_SYSTEM; import static ca.uhn.fhir.jpa.dao.dstu3.FhirResourceDaoDstu3TerminologyTest.URL_MY_VALUE_SET; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.*; public class ResourceProviderDstu3ValueSetTest extends BaseResourceProviderDstu3Test { @@ -820,15 +817,11 @@ public class ResourceProviderDstu3ValueSetTest extends BaseResourceProviderDstu3 assertEquals("Male", ((StringType) respParam.getParameter().get(2).getValue()).getValue()); } - @After + @AfterEach public void afterResetPreExpansionDefault() { myDaoConfig.setPreExpandValueSets(new DaoConfig().isPreExpandValueSets()); } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } public static CodeSystem createExternalCs(IFhirResourceDao theCodeSystemDao, IResourceTableDao theResourceTableDao, ITermCodeSystemStorageSvc theTermCodeSystemStorageSvc, ServletRequestDetails theRequestDetails) { CodeSystem codeSystem = new CodeSystem(); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderExpungeDstu3Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderExpungeDstu3Test.java index 34c487da76f..ca4ee42a0e9 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderExpungeDstu3Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ResourceProviderExpungeDstu3Test.java @@ -15,15 +15,15 @@ import org.hl7.fhir.dstu3.model.Observation; import org.hl7.fhir.dstu3.model.Parameters; import org.hl7.fhir.dstu3.model.Patient; import org.hl7.fhir.instance.model.api.IIdType; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; public class ResourceProviderExpungeDstu3Test extends BaseResourceProviderDstu3Test { @@ -35,7 +35,7 @@ public class ResourceProviderExpungeDstu3Test extends BaseResourceProviderDstu3T private IIdType myTwoVersionObservationId; private IIdType myDeletedObservationId; - @After + @AfterEach public void afterDisableExpunge() { myDaoConfig.setExpungeEnabled(new DaoConfig().isExpungeEnabled()); } @@ -63,7 +63,7 @@ public class ResourceProviderExpungeDstu3Test extends BaseResourceProviderDstu3T } @Override - @Before + @BeforeEach public void before() throws Exception { super.before(); @@ -112,7 +112,7 @@ public class ResourceProviderExpungeDstu3Test extends BaseResourceProviderDstu3T } - @Before + @BeforeEach public void beforeEnableExpunge() { myDaoConfig.setExpungeEnabled(true); } @@ -366,9 +366,5 @@ public class ResourceProviderExpungeDstu3Test extends BaseResourceProviderDstu3T ourLog.info(myFhirCtx.newJsonParser().encodeResourceToString(p)); } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } } 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 91f2b46a5c1..bd6243a9da4 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 @@ -1,43 +1,51 @@ package ca.uhn.fhir.jpa.provider.dstu3; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.startsWith; -import static org.junit.Assert.*; - -import java.nio.charset.StandardCharsets; -import java.util.Collection; - -import org.apache.commons.io.IOUtils; -import org.apache.http.client.methods.*; -import org.apache.http.entity.ContentType; -import org.apache.http.entity.StringEntity; -import org.hl7.fhir.dstu3.model.*; -import org.hl7.fhir.dstu3.model.Questionnaire.QuestionnaireItemType; -import org.hl7.fhir.dstu3.model.QuestionnaireResponse.QuestionnaireResponseStatus; -import org.hl7.fhir.instance.model.api.IIdType; -import org.junit.*; - import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; import ca.uhn.fhir.rest.server.interceptor.RequestValidatingInterceptor; import ca.uhn.fhir.util.TestUtil; import ca.uhn.fhir.validation.IValidatorModule; import ca.uhn.fhir.validation.ResultSeverityEnum; +import org.apache.commons.io.IOUtils; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.entity.ContentType; +import org.apache.http.entity.StringEntity; +import org.hl7.fhir.dstu3.model.DecimalType; +import org.hl7.fhir.dstu3.model.IdType; +import org.hl7.fhir.dstu3.model.Patient; +import org.hl7.fhir.dstu3.model.Questionnaire; +import org.hl7.fhir.dstu3.model.Questionnaire.QuestionnaireItemType; +import org.hl7.fhir.dstu3.model.QuestionnaireResponse; +import org.hl7.fhir.dstu3.model.QuestionnaireResponse.QuestionnaireResponseStatus; +import org.hl7.fhir.instance.model.api.IIdType; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; + +import java.nio.charset.StandardCharsets; +import java.util.Collection; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.startsWith; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; public class ResourceProviderQuestionnaireResponseDstu3Test extends BaseResourceProviderDstu3Test { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ResourceProviderQuestionnaireResponseDstu3Test.class); private static RequestValidatingInterceptor ourValidatingInterceptor; - @AfterClass + @AfterAll public static void afterClassClearContext() { ourRestServer.unregisterInterceptor(ourValidatingInterceptor); ourValidatingInterceptor = null; - TestUtil.clearAllStaticFieldsForUnitTest(); } @Override - @Before + @BeforeEach public void before() throws Exception { super.before(); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ServerDstu3Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ServerDstu3Test.java index 92728e7358e..db6bde81d17 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ServerDstu3Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/ServerDstu3Test.java @@ -2,7 +2,7 @@ package ca.uhn.fhir.jpa.provider.dstu3; import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.stringContainsInOrder; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.io.IOException; import java.nio.charset.StandardCharsets; @@ -15,8 +15,8 @@ import org.apache.http.client.methods.HttpGet; import org.hl7.fhir.dstu3.model.CapabilityStatement; import org.hl7.fhir.dstu3.model.CapabilityStatement.CapabilityStatementRestResourceComponent; import org.hl7.fhir.dstu3.model.CapabilityStatement.CapabilityStatementRestResourceSearchParamComponent; -import org.junit.AfterClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; import ca.uhn.fhir.util.TestUtil; @@ -61,9 +61,5 @@ public class ServerDstu3Test extends BaseResourceProviderDstu3Test { } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } } 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 04b08891ff9..88c2003a702 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 @@ -13,40 +13,42 @@ 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.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.util.ArrayList; import java.util.List; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; public class SubscriptionsDstu3Test extends BaseResourceProviderDstu3Test { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(SubscriptionsDstu3Test.class); private SubscriptionsRequireManualActivationInterceptorDstu3 myInterceptor; - @Before + @BeforeEach public void beforeCreateInterceptor() { myInterceptor = new SubscriptionsRequireManualActivationInterceptorDstu3(); myInterceptor.setDao(mySubscriptionDao); myInterceptorRegistry.registerInterceptor(myInterceptor); } - @After + @AfterEach public void afterDestroyInterceptor() { myInterceptorRegistry.unregisterInterceptor(myInterceptor); } - @Before + @BeforeEach public void beforeDisableResultReuse() { myDaoConfig.setReuseCachedSearchResultsForMillis(null); } - @Before + @BeforeEach public void beforeEnableScheduling() { myDaoConfig.setSchedulingDisabled(false); } @@ -124,7 +126,7 @@ public class SubscriptionsDstu3Test extends BaseResourceProviderDstu3Test { } try { - subs.setStatus((SubscriptionStatus) null); + subs.setStatus(null); ourClient.update().resource(subs).execute(); fail(); } catch (UnprocessableEntityException e) { @@ -155,7 +157,7 @@ public class SubscriptionsDstu3Test extends BaseResourceProviderDstu3Test { } try { - subs.setStatus((SubscriptionStatus) null); + subs.setStatus(null); ourClient.update().resource(subs).execute(); fail(); } catch (UnprocessableEntityException e) { @@ -166,10 +168,6 @@ public class SubscriptionsDstu3Test extends BaseResourceProviderDstu3Test { ourClient.update().resource(subs).execute(); } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } public class BaseSocket { protected String myError; diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/SystemProviderTransactionSearchDstu3Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/SystemProviderTransactionSearchDstu3Test.java index 42c2621e9e5..902e792d724 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/SystemProviderTransactionSearchDstu3Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/dstu3/SystemProviderTransactionSearchDstu3Test.java @@ -1,6 +1,7 @@ package ca.uhn.fhir.jpa.provider.dstu3; import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.context.FhirVersionEnum; import ca.uhn.fhir.jpa.api.config.DaoConfig; import ca.uhn.fhir.jpa.dao.dstu3.BaseJpaDstu3Test; import ca.uhn.fhir.jpa.rp.dstu3.ObservationResourceProvider; @@ -33,24 +34,24 @@ import org.hl7.fhir.dstu3.model.Bundle.HTTPVerb; import org.hl7.fhir.dstu3.model.Enumerations.AdministrativeGender; import org.hl7.fhir.dstu3.model.Patient; import org.hl7.fhir.instance.model.api.IIdType; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; import java.util.concurrent.TimeUnit; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.nullValue; import static org.hamcrest.Matchers.startsWith; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; public class SystemProviderTransactionSearchDstu3Test extends BaseJpaDstu3Test { @@ -66,19 +67,13 @@ public class SystemProviderTransactionSearchDstu3Test extends BaseJpaDstu3Test { @SuppressWarnings("deprecation") - @After + @AfterEach public void after() { ourClient.unregisterInterceptor(mySimpleHeaderInterceptor); myDaoConfig.setMaximumSearchResultCountInTransaction(new DaoConfig().getMaximumSearchResultCountInTransaction()); } - @Before - public void before() { - mySimpleHeaderInterceptor = new SimpleRequestHeaderInterceptor(); - ourClient.registerInterceptor(mySimpleHeaderInterceptor); - } - - @Before + @BeforeEach public void beforeStartServer() throws Exception { if (myRestServer == null) { PatientResourceProvider patientRp = new PatientResourceProvider(); @@ -107,7 +102,7 @@ public class SystemProviderTransactionSearchDstu3Test extends BaseJpaDstu3Test { servletHolder.setServlet(restServer); proxyHandler.addServlet(servletHolder, "/fhir/context/*"); - ourCtx = FhirContext.forDstu3(); + ourCtx = FhirContext.forCached(FhirVersionEnum.DSTU3); restServer.setFhirContext(ourCtx); ourServer.setHandler(proxyHandler); @@ -128,6 +123,9 @@ public class SystemProviderTransactionSearchDstu3Test extends BaseJpaDstu3Test { myRestServer.setDefaultResponseEncoding(EncodingEnum.XML); myRestServer.setPagingProvider(myPagingProvider); + + mySimpleHeaderInterceptor = new SimpleRequestHeaderInterceptor(); + ourClient.registerInterceptor(mySimpleHeaderInterceptor); } @@ -353,10 +351,9 @@ public class SystemProviderTransactionSearchDstu3Test extends BaseJpaDstu3Test { return retVal; } - @AfterClass + @AfterAll public static void afterClassClearContext() throws Exception { JettyUtil.closeServer(ourServer); - TestUtil.clearAllStaticFieldsForUnitTest(); } } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/AuthorizationInterceptorJpaR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/AuthorizationInterceptorJpaR4Test.java index f572cfdf669..306aee27944 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/AuthorizationInterceptorJpaR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/AuthorizationInterceptorJpaR4Test.java @@ -16,7 +16,6 @@ import ca.uhn.fhir.rest.server.interceptor.auth.IAuthRuleTester; import ca.uhn.fhir.rest.server.interceptor.auth.PolicyEnum; import ca.uhn.fhir.rest.server.interceptor.auth.RuleBuilder; import ca.uhn.fhir.rest.server.provider.ProviderConstants; -import ca.uhn.fhir.util.TestUtil; import ca.uhn.fhir.util.UrlUtil; import org.apache.commons.io.IOUtils; import org.apache.http.client.methods.CloseableHttpResponse; @@ -42,8 +41,8 @@ import org.hl7.fhir.r4.model.Patient; import org.hl7.fhir.r4.model.Practitioner; import org.hl7.fhir.r4.model.Reference; import org.hl7.fhir.r4.model.StringType; -import org.junit.AfterClass; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -52,17 +51,18 @@ import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.List; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.startsWith; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.fail; public class AuthorizationInterceptorJpaR4Test extends BaseResourceProviderR4Test { private static final Logger ourLog = LoggerFactory.getLogger(AuthorizationInterceptorJpaR4Test.class); + @BeforeEach @Override public void before() throws Exception { super.before(); @@ -76,11 +76,11 @@ public class AuthorizationInterceptorJpaR4Test extends BaseResourceProviderR4Tes public void testBlockUpdatingPatientUserDoesnNotHaveAccessTo() { Patient pt1 = new Patient(); pt1.setActive(true); - final IIdType pid1 = ourClient.create().resource(pt1).execute().getId().toUnqualifiedVersionless(); + final IIdType pid1 = myClient.create().resource(pt1).execute().getId().toUnqualifiedVersionless(); Patient pt2 = new Patient(); pt2.setActive(false); - final IIdType pid2 = ourClient.create().resource(pt2).execute().getId().toUnqualifiedVersionless(); + final IIdType pid2 = myClient.create().resource(pt2).execute().getId().toUnqualifiedVersionless(); AuthorizationInterceptor authInterceptor = new AuthorizationInterceptor(PolicyEnum.DENY) { @Override @@ -95,7 +95,7 @@ public class AuthorizationInterceptorJpaR4Test extends BaseResourceProviderR4Tes Observation obs = new Observation(); obs.setStatus(ObservationStatus.FINAL); obs.setSubject(new Reference(pid1)); - IIdType oid = ourClient.create().resource(obs).execute().getId().toUnqualified(); + IIdType oid = myClient.create().resource(obs).execute().getId().toUnqualified(); ourRestServer.getInterceptorService().unregisterInterceptor(authInterceptor); ourRestServer.getInterceptorService().registerInterceptor(new AuthorizationInterceptor(PolicyEnum.DENY) { @@ -118,7 +118,7 @@ public class AuthorizationInterceptorJpaR4Test extends BaseResourceProviderR4Tes obs.setSubject(new Reference(pid2)); try { - ourClient.update().resource(obs).execute(); + myClient.update().resource(obs).execute(); fail(); } catch (ForbiddenOperationException e) { // good @@ -132,7 +132,7 @@ public class AuthorizationInterceptorJpaR4Test extends BaseResourceProviderR4Tes Patient patient = new Patient(); patient.addIdentifier().setSystem("http://uhn.ca/mrns").setValue("100"); patient.addName().setFamily("Tester").addGiven("Raghad"); - final MethodOutcome output1 = ourClient.update().resource(patient).conditionalByUrl("Patient?identifier=http://uhn.ca/mrns|100").execute(); + final MethodOutcome output1 = myClient.update().resource(patient).conditionalByUrl("Patient?identifier=http://uhn.ca/mrns|100").execute(); ourRestServer.getInterceptorService().registerInterceptor(new AuthorizationInterceptor(PolicyEnum.DENY) { @Override @@ -148,7 +148,7 @@ public class AuthorizationInterceptorJpaR4Test extends BaseResourceProviderR4Tes patient.setId(output1.getId().toUnqualifiedVersionless()); patient.addIdentifier().setSystem("http://uhn.ca/mrns").setValue("100"); patient.addName().setFamily("Tester").addGiven("Raghad"); - MethodOutcome output2 = ourClient.update().resource(patient).conditionalByUrl("Patient?identifier=http://uhn.ca/mrns|100").execute(); + MethodOutcome output2 = myClient.update().resource(patient).conditionalByUrl("Patient?identifier=http://uhn.ca/mrns|100").execute(); assertEquals(output1.getId().getIdPart(), output2.getId().getIdPart()); @@ -156,7 +156,7 @@ public class AuthorizationInterceptorJpaR4Test extends BaseResourceProviderR4Tes patient.addIdentifier().setSystem("http://uhn.ca/mrns").setValue("100"); patient.addName().setFamily("Tester").addGiven("Raghad"); try { - ourClient.update().resource(patient).conditionalByUrl("Patient?identifier=http://uhn.ca/mrns|101").execute(); + myClient.update().resource(patient).conditionalByUrl("Patient?identifier=http://uhn.ca/mrns|101").execute(); fail(); } catch (ForbiddenOperationException e) { assertEquals("HTTP 403 Forbidden: Access denied by default policy (no applicable rules)", e.getMessage()); @@ -167,7 +167,7 @@ public class AuthorizationInterceptorJpaR4Test extends BaseResourceProviderR4Tes patient.addIdentifier().setSystem("http://uhn.ca/mrns").setValue("100"); patient.addName().setFamily("Tester").addGiven("Raghad"); try { - ourClient.update().resource(patient).execute(); + myClient.update().resource(patient).execute(); fail(); } catch (ForbiddenOperationException e) { assertEquals("HTTP 403 Forbidden: Access denied by default policy (no applicable rules)", e.getMessage()); @@ -214,12 +214,12 @@ public class AuthorizationInterceptorJpaR4Test extends BaseResourceProviderR4Tes .getRequest() .setMethod(Bundle.HTTPVerb.POST) .setIfNoneExist("Patient?identifier=http://uhn.ca/mrns|100"); - Bundle response = ourClient.transaction().withBundle(request).execute(); + Bundle response = myClient.transaction().withBundle(request).execute(); ourLog.info(myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(response)); // Subsequent calls also shouldn't fail - ourClient.transaction().withBundle(request).execute(); - ourClient.transaction().withBundle(request).execute(); + myClient.transaction().withBundle(request).execute(); + myClient.transaction().withBundle(request).execute(); } // Create a patient with wrong identifier (blocked) @@ -237,7 +237,7 @@ public class AuthorizationInterceptorJpaR4Test extends BaseResourceProviderR4Tes .setIfNoneExist("Patient?identifier=http://uhn.ca/mrns|101"); try { - ourClient.transaction().withBundle(request).execute(); + myClient.transaction().withBundle(request).execute(); fail(); } catch (ForbiddenOperationException e) { assertEquals("HTTP 403 Forbidden: Access denied by default policy (no applicable rules)", e.getMessage()); @@ -258,7 +258,7 @@ public class AuthorizationInterceptorJpaR4Test extends BaseResourceProviderR4Tes .setIfNoneExist("Organization?name=FOO"); try { - ourClient.transaction().withBundle(request).execute(); + myClient.transaction().withBundle(request).execute(); fail(); } catch (ForbiddenOperationException e) { assertEquals("HTTP 403 Forbidden: Access denied by default policy (no applicable rules)", e.getMessage()); @@ -274,7 +274,7 @@ public class AuthorizationInterceptorJpaR4Test extends BaseResourceProviderR4Tes Patient patient = new Patient(); patient.addIdentifier().setSystem("http://uhn.ca/mrns").setValue("100"); patient.addName().setFamily("Tester").addGiven("Raghad"); - IIdType id = ourClient.update().resource(patient).conditionalByUrl("Patient?identifier=http://uhn.ca/mrns|100").execute().getId().toUnqualifiedVersionless(); + IIdType id = myClient.update().resource(patient).conditionalByUrl("Patient?identifier=http://uhn.ca/mrns|100").execute().getId().toUnqualifiedVersionless(); ourRestServer.registerInterceptor(new AuthorizationInterceptor(PolicyEnum.DENY) { @Override @@ -292,7 +292,7 @@ public class AuthorizationInterceptorJpaR4Test extends BaseResourceProviderR4Tes SimpleRequestHeaderInterceptor interceptor = new SimpleRequestHeaderInterceptor("Authorization", "Bearer AAA"); try { - ourClient.registerInterceptor(interceptor); + myClient.registerInterceptor(interceptor); Bundle bundle; Bundle responseBundle; @@ -301,7 +301,7 @@ public class AuthorizationInterceptorJpaR4Test extends BaseResourceProviderR4Tes bundle = new Bundle(); bundle.setType(Bundle.BundleType.TRANSACTION); bundle.addEntry().getRequest().setMethod(Bundle.HTTPVerb.GET).setUrl(id.getValue()); - responseBundle = ourClient.transaction().withBundle(bundle).execute(); + responseBundle = myClient.transaction().withBundle(bundle).execute(); patient = (Patient) responseBundle.getEntry().get(0).getResource(); assertEquals("Tester", patient.getNameFirstRep().getFamily()); @@ -309,13 +309,13 @@ public class AuthorizationInterceptorJpaR4Test extends BaseResourceProviderR4Tes bundle = new Bundle(); bundle.setType(Bundle.BundleType.TRANSACTION); bundle.addEntry().getRequest().setMethod(Bundle.HTTPVerb.GET).setUrl("Patient?"); - responseBundle = ourClient.transaction().withBundle(bundle).execute(); + responseBundle = myClient.transaction().withBundle(bundle).execute(); responseBundle = (Bundle) responseBundle.getEntry().get(0).getResource(); patient = (Patient) responseBundle.getEntry().get(0).getResource(); assertEquals("Tester", patient.getNameFirstRep().getFamily()); } finally { - ourClient.unregisterInterceptor(interceptor); + myClient.unregisterInterceptor(interceptor); } } @@ -326,16 +326,16 @@ public class AuthorizationInterceptorJpaR4Test extends BaseResourceProviderR4Tes Patient patient = new Patient(); patient.addIdentifier().setSystem("http://uhn.ca/mrns").setValue("100"); patient.addName().setFamily("Tester").addGiven("Raghad"); - IIdType patientId = ourClient.create().resource(patient).execute().getId().toUnqualifiedVersionless(); + IIdType patientId = myClient.create().resource(patient).execute().getId().toUnqualifiedVersionless(); Observation obs = new Observation(); obs.setStatus(ObservationStatus.FINAL); obs.setSubject(new Reference(patientId)); - IIdType observationId = ourClient.create().resource(obs).execute().getId().toUnqualifiedVersionless(); + IIdType observationId = myClient.create().resource(obs).execute().getId().toUnqualifiedVersionless(); Observation obs2 = new Observation(); obs2.setStatus(ObservationStatus.FINAL); - IIdType observationId2 = ourClient.create().resource(obs2).execute().getId().toUnqualifiedVersionless(); + IIdType observationId2 = myClient.create().resource(obs2).execute().getId().toUnqualifiedVersionless(); ourRestServer.registerInterceptor(new AuthorizationInterceptor(PolicyEnum.DENY) { @Override @@ -350,12 +350,12 @@ public class AuthorizationInterceptorJpaR4Test extends BaseResourceProviderR4Tes Observation response; // Read (no masking) - response = ourClient.read().resource(Observation.class).withId(observationId).execute(); + response = myClient.read().resource(Observation.class).withId(observationId).execute(); assertEquals(ObservationStatus.FINAL, response.getStatus()); assertEquals(patientId.getValue(), response.getSubject().getReference()); // Read (with _elements masking) - response = ourClient + response = myClient .read() .resource(Observation.class) .withId(observationId) @@ -366,7 +366,7 @@ public class AuthorizationInterceptorJpaR4Test extends BaseResourceProviderR4Tes // Read a non-allowed observation try { - ourClient.read().resource(Observation.class).withId(observationId2).execute(); + myClient.read().resource(Observation.class).withId(observationId2).execute(); fail(); } catch (ForbiddenOperationException e) { // good @@ -384,17 +384,17 @@ public class AuthorizationInterceptorJpaR4Test extends BaseResourceProviderR4Tes patient.setId("Patient/A"); patient.addIdentifier().setSystem("http://uhn.ca/mrns").setValue("100"); patient.addName().setFamily("Tester").addGiven("Raghad"); - IIdType id = ourClient.update().resource(patient).execute().getId(); + IIdType id = myClient.update().resource(patient).execute().getId(); Observation obs = new Observation(); obs.setId("Observation/B"); obs.getSubject().setReference("Patient/A"); - ourClient.update().resource(obs).execute(); + myClient.update().resource(obs).execute(); obs = new Observation(); obs.setId("Observation/C"); obs.setStatus(ObservationStatus.FINAL); - ourClient.update().resource(obs).execute(); + myClient.update().resource(obs).execute(); ourRestServer.registerInterceptor(new AuthorizationInterceptor(PolicyEnum.DENY) { @Override @@ -407,17 +407,17 @@ public class AuthorizationInterceptorJpaR4Test extends BaseResourceProviderR4Tes } }); - ourClient.delete().resourceById(new IdType("Observation/B")).execute(); + myClient.delete().resourceById(new IdType("Observation/B")).execute(); try { - ourClient.read().resource(Observation.class).withId("Observation/B").execute(); + myClient.read().resource(Observation.class).withId("Observation/B").execute(); fail(); } catch (ResourceGoneException e) { // good } try { - ourClient.delete().resourceById(new IdType("Observation/C")).execute(); + myClient.delete().resourceById(new IdType("Observation/C")).execute(); fail(); } catch (ForbiddenOperationException e) { // good @@ -433,16 +433,16 @@ public class AuthorizationInterceptorJpaR4Test extends BaseResourceProviderR4Tes Patient patient = new Patient(); patient.addIdentifier().setSystem("http://uhn.ca/mrns").setValue("100"); patient.addName().setFamily("Tester").addGiven("Raghad"); - final IIdType id = ourClient.create().resource(patient).execute().getId(); + final IIdType id = myClient.create().resource(patient).execute().getId(); Observation obsInCompartment = new Observation(); obsInCompartment.setStatus(ObservationStatus.FINAL); obsInCompartment.getSubject().setReferenceElement(id.toUnqualifiedVersionless()); - IIdType obsInCompartmentId = ourClient.create().resource(obsInCompartment).execute().getId().toUnqualifiedVersionless(); + IIdType obsInCompartmentId = myClient.create().resource(obsInCompartment).execute().getId().toUnqualifiedVersionless(); Observation obsNotInCompartment = new Observation(); obsNotInCompartment.setStatus(ObservationStatus.FINAL); - IIdType obsNotInCompartmentId = ourClient.create().resource(obsNotInCompartment).execute().getId().toUnqualifiedVersionless(); + IIdType obsNotInCompartmentId = myClient.create().resource(obsNotInCompartment).execute().getId().toUnqualifiedVersionless(); ourRestServer.registerInterceptor(new AuthorizationInterceptor(PolicyEnum.DENY) { @Override @@ -455,10 +455,10 @@ public class AuthorizationInterceptorJpaR4Test extends BaseResourceProviderR4Tes } }); - ourClient.delete().resourceById(obsInCompartmentId.toUnqualifiedVersionless()).execute(); + myClient.delete().resourceById(obsInCompartmentId.toUnqualifiedVersionless()).execute(); try { - ourClient.delete().resourceById(obsNotInCompartmentId.toUnqualifiedVersionless()).execute(); + myClient.delete().resourceById(obsNotInCompartmentId.toUnqualifiedVersionless()).execute(); fail(); } catch (ForbiddenOperationException e) { // good @@ -471,16 +471,16 @@ public class AuthorizationInterceptorJpaR4Test extends BaseResourceProviderR4Tes Patient patient = new Patient(); patient.addIdentifier().setSystem("http://uhn.ca/mrns").setValue("100"); patient.addName().setFamily("Tester").addGiven("Raghad"); - final IIdType id = ourClient.create().resource(patient).execute().getId(); + final IIdType id = myClient.create().resource(patient).execute().getId(); Observation obsInCompartment = new Observation(); obsInCompartment.setStatus(ObservationStatus.FINAL); obsInCompartment.getSubject().setReferenceElement(id.toUnqualifiedVersionless()); - IIdType obsInCompartmentId = ourClient.create().resource(obsInCompartment).execute().getId().toUnqualifiedVersionless(); + IIdType obsInCompartmentId = myClient.create().resource(obsInCompartment).execute().getId().toUnqualifiedVersionless(); Observation obsNotInCompartment = new Observation(); obsNotInCompartment.setStatus(ObservationStatus.FINAL); - IIdType obsNotInCompartmentId = ourClient.create().resource(obsNotInCompartment).execute().getId().toUnqualifiedVersionless(); + IIdType obsNotInCompartmentId = myClient.create().resource(obsNotInCompartment).execute().getId().toUnqualifiedVersionless(); ourRestServer.registerInterceptor(new AuthorizationInterceptor(PolicyEnum.DENY) { @Override @@ -498,13 +498,13 @@ public class AuthorizationInterceptorJpaR4Test extends BaseResourceProviderR4Tes bundle = new Bundle(); bundle.setType(Bundle.BundleType.TRANSACTION); bundle.addEntry().getRequest().setMethod(Bundle.HTTPVerb.DELETE).setUrl(obsInCompartmentId.toUnqualifiedVersionless().getValue()); - ourClient.transaction().withBundle(bundle).execute(); + myClient.transaction().withBundle(bundle).execute(); try { bundle = new Bundle(); bundle.setType(Bundle.BundleType.TRANSACTION); bundle.addEntry().getRequest().setMethod(Bundle.HTTPVerb.DELETE).setUrl(obsNotInCompartmentId.toUnqualifiedVersionless().getValue()); - ourClient.transaction().withBundle(bundle).execute(); + myClient.transaction().withBundle(bundle).execute(); fail(); } catch (ForbiddenOperationException e) { // good @@ -530,16 +530,16 @@ public class AuthorizationInterceptorJpaR4Test extends BaseResourceProviderR4Tes Patient patient = new Patient(); patient.addIdentifier().setSystem("http://uhn.ca/mrns").setValue("100"); patient.addName().setFamily("Tester").addGiven("Raghad"); - IIdType id = ourClient.create().resource(patient).execute().getId(); + IIdType id = myClient.create().resource(patient).execute().getId(); try { - ourClient.delete().resourceById(id.toUnqualifiedVersionless()).execute(); + myClient.delete().resourceById(id.toUnqualifiedVersionless()).execute(); fail(); } catch (ForbiddenOperationException e) { // good } - patient = ourClient.read().resource(Patient.class).withId(id.toUnqualifiedVersionless()).execute(); + patient = myClient.read().resource(Patient.class).withId(id.toUnqualifiedVersionless()).execute(); assertEquals(id.getValue(), patient.getId()); } @@ -553,12 +553,12 @@ public class AuthorizationInterceptorJpaR4Test extends BaseResourceProviderR4Tes Patient patient = new Patient(); patient.addIdentifier().setSystem("http://uhn.ca/mrns").setValue("100"); patient.addName().setFamily("Tester").addGiven("Raghad"); - final IIdType patientId = ourClient.create().resource(patient).execute().getId().toUnqualifiedVersionless(); + final IIdType patientId = myClient.create().resource(patient).execute().getId().toUnqualifiedVersionless(); Observation obs = new Observation(); obs.setStatus(ObservationStatus.FINAL); obs.getSubject().setReferenceElement(patientId); - ourClient.create().resource(obs).execute(); + myClient.create().resource(obs).execute(); // Allow any deletes, but don't allow cascade ourRestServer.registerInterceptor(new AuthorizationInterceptor(PolicyEnum.DENY) { @@ -571,7 +571,7 @@ public class AuthorizationInterceptorJpaR4Test extends BaseResourceProviderR4Tes }); try { - ourClient + myClient .delete() .resourceById(patientId) .withAdditionalHeader(Constants.HEADER_CASCADE, Constants.CASCADE_DELETE) @@ -597,12 +597,12 @@ public class AuthorizationInterceptorJpaR4Test extends BaseResourceProviderR4Tes Patient patient = new Patient(); patient.addIdentifier().setSystem("http://uhn.ca/mrns").setValue("100"); patient.addName().setFamily("Tester").addGiven("Raghad"); - final IIdType patientId = ourClient.create().resource(patient).execute().getId().toUnqualifiedVersionless(); + final IIdType patientId = myClient.create().resource(patient).execute().getId().toUnqualifiedVersionless(); Observation obs = new Observation(); obs.setStatus(ObservationStatus.FINAL); obs.getSubject().setReferenceElement(patientId); - ourClient.create().resource(obs).execute(); + myClient.create().resource(obs).execute(); // Allow any deletes, but don't allow cascade ourRestServer.registerInterceptor(new AuthorizationInterceptor(PolicyEnum.DENY) { @@ -615,7 +615,7 @@ public class AuthorizationInterceptorJpaR4Test extends BaseResourceProviderR4Tes } }); - ourClient + myClient .delete() .resourceById(patientId) .withAdditionalHeader(Constants.HEADER_CASCADE, Constants.CASCADE_DELETE) @@ -636,12 +636,12 @@ public class AuthorizationInterceptorJpaR4Test extends BaseResourceProviderR4Tes Patient patient = new Patient(); patient.addIdentifier().setSystem("http://uhn.ca/mrns").setValue("100"); patient.addName().setFamily("Tester").addGiven("Raghad"); - final IIdType patientId = ourClient.create().resource(patient).execute().getId().toUnqualifiedVersionless(); + final IIdType patientId = myClient.create().resource(patient).execute().getId().toUnqualifiedVersionless(); Observation obs = new Observation(); obs.setStatus(ObservationStatus.FINAL); obs.getSubject().setReferenceElement(patientId); - ourClient.create().resource(obs).execute(); + myClient.create().resource(obs).execute(); // Allow any deletes, but don't allow cascade ourRestServer.registerInterceptor(new AuthorizationInterceptor(PolicyEnum.DENY) { @@ -656,7 +656,7 @@ public class AuthorizationInterceptorJpaR4Test extends BaseResourceProviderR4Tes }); try { - ourClient + myClient .delete() .resourceById(patientId) .withAdditionalHeader(Constants.HEADER_CASCADE, Constants.CASCADE_DELETE) @@ -759,14 +759,14 @@ public class AuthorizationInterceptorJpaR4Test extends BaseResourceProviderR4Tes Parameters diff; - diff = ourClient.operation().onInstance("Patient/A").named(ProviderConstants.DIFF_OPERATION_NAME).withNoParameters(Parameters.class).execute(); + diff = myClient.operation().onInstance("Patient/A").named(ProviderConstants.DIFF_OPERATION_NAME).withNoParameters(Parameters.class).execute(); assertEquals(1, diff.getParameter().size()); - diff = ourClient.operation().onInstanceVersion(new IdType("Patient/A/_history/2")).named(ProviderConstants.DIFF_OPERATION_NAME).withNoParameters(Parameters.class).execute(); + diff = myClient.operation().onInstanceVersion(new IdType("Patient/A/_history/2")).named(ProviderConstants.DIFF_OPERATION_NAME).withNoParameters(Parameters.class).execute(); assertEquals(1, diff.getParameter().size()); try { - ourClient.operation().onInstance("Observation/B").named(ProviderConstants.DIFF_OPERATION_NAME).withNoParameters(Parameters.class).execute(); + myClient.operation().onInstance("Observation/B").named(ProviderConstants.DIFF_OPERATION_NAME).withNoParameters(Parameters.class).execute(); fail(); } catch (ForbiddenOperationException e) { // good @@ -795,7 +795,7 @@ public class AuthorizationInterceptorJpaR4Test extends BaseResourceProviderR4Tes Parameters diff; - diff = ourClient + diff = myClient .operation() .onServer() .named(ProviderConstants.DIFF_OPERATION_NAME) @@ -805,7 +805,7 @@ public class AuthorizationInterceptorJpaR4Test extends BaseResourceProviderR4Tes assertEquals(2, diff.getParameter().size()); try { - ourClient + myClient .operation() .onServer() .named(ProviderConstants.DIFF_OPERATION_NAME) @@ -888,7 +888,7 @@ public class AuthorizationInterceptorJpaR4Test extends BaseResourceProviderR4Tes o.getSubject().setResource(p); request.addEntry().setResource(o).getRequest().setMethod(Bundle.HTTPVerb.POST); - Bundle resp = ourClient.transaction().withBundle(request).execute(); + Bundle resp = myClient.transaction().withBundle(request).execute(); assertEquals(2, resp.getEntry().size()); @@ -925,7 +925,7 @@ public class AuthorizationInterceptorJpaR4Test extends BaseResourceProviderR4Tes .setMethod(Bundle.HTTPVerb.POST); // return=minimal - should succeed - Bundle resp = ourClient + Bundle resp = myClient .transaction() .withBundle(bundle) .withAdditionalHeader(Constants.HEADER_PREFER, "return=" + Constants.HEADER_PREFER_RETURN_MINIMAL) @@ -934,7 +934,7 @@ public class AuthorizationInterceptorJpaR4Test extends BaseResourceProviderR4Tes assertNull(resp.getEntry().get(0).getResource()); // return=OperationOutcome - should succeed - resp = ourClient + resp = myClient .transaction() .withBundle(bundle) .withAdditionalHeader(Constants.HEADER_PREFER, "return=" + Constants.HEADER_PREFER_RETURN_OPERATION_OUTCOME) @@ -944,7 +944,7 @@ public class AuthorizationInterceptorJpaR4Test extends BaseResourceProviderR4Tes // return=Representation - should fail try { - ourClient + myClient .transaction() .withBundle(bundle) .withAdditionalHeader(Constants.HEADER_PREFER, "return=" + Constants.HEADER_PREFER_RETURN_REPRESENTATION) @@ -1037,7 +1037,7 @@ public class AuthorizationInterceptorJpaR4Test extends BaseResourceProviderR4Tes .setMethod(Bundle.HTTPVerb.POST); - Bundle resp = ourClient + Bundle resp = myClient .transaction() .withBundle(bundle) .withAdditionalHeader(Constants.HEADER_PREFER, "return=" + Constants.HEADER_PREFER_RETURN_MINIMAL) @@ -1050,21 +1050,21 @@ public class AuthorizationInterceptorJpaR4Test extends BaseResourceProviderR4Tes public void testPatchWithinCompartment() { Patient pt1 = new Patient(); pt1.setActive(true); - final IIdType pid1 = ourClient.create().resource(pt1).execute().getId().toUnqualifiedVersionless(); + final IIdType pid1 = myClient.create().resource(pt1).execute().getId().toUnqualifiedVersionless(); Observation obs1 = new Observation(); obs1.setStatus(ObservationStatus.FINAL); obs1.setSubject(new Reference(pid1)); - IIdType oid1 = ourClient.create().resource(obs1).execute().getId().toUnqualified(); + IIdType oid1 = myClient.create().resource(obs1).execute().getId().toUnqualified(); Patient pt2 = new Patient(); pt2.setActive(false); - final IIdType pid2 = ourClient.create().resource(pt2).execute().getId().toUnqualifiedVersionless(); + final IIdType pid2 = myClient.create().resource(pt2).execute().getId().toUnqualifiedVersionless(); Observation obs2 = new Observation(); obs2.setStatus(ObservationStatus.FINAL); obs2.setSubject(new Reference(pid2)); - IIdType oid2 = ourClient.create().resource(obs2).execute().getId().toUnqualified(); + IIdType oid2 = myClient.create().resource(obs2).execute().getId().toUnqualified(); ourRestServer.registerInterceptor(new AuthorizationInterceptor(PolicyEnum.DENY) { @Override @@ -1082,18 +1082,18 @@ public class AuthorizationInterceptorJpaR4Test extends BaseResourceProviderR4Tes " ]"; // Allowed - ourClient.patch().withBody(patchBody).withId(oid1).execute(); - obs1 = ourClient.read().resource(Observation.class).withId(oid1.toUnqualifiedVersionless()).execute(); + myClient.patch().withBody(patchBody).withId(oid1).execute(); + obs1 = myClient.read().resource(Observation.class).withId(oid1.toUnqualifiedVersionless()).execute(); assertEquals(ObservationStatus.AMENDED, obs1.getStatus()); // Denied try { - ourClient.patch().withBody(patchBody).withId(oid2).execute(); + myClient.patch().withBody(patchBody).withId(oid2).execute(); fail(); } catch (ForbiddenOperationException e) { // good } - obs2 = ourClient.read().resource(Observation.class).withId(oid2.toUnqualifiedVersionless()).execute(); + obs2 = myClient.read().resource(Observation.class).withId(oid2.toUnqualifiedVersionless()).execute(); assertEquals(ObservationStatus.FINAL, obs2.getStatus()); } @@ -1103,14 +1103,14 @@ public class AuthorizationInterceptorJpaR4Test extends BaseResourceProviderR4Tes @Test public void testReadingObservationAccessRight() { Practitioner practitioner1 = new Practitioner(); - final IIdType practitionerId1 = ourClient.create().resource(practitioner1).execute().getId().toUnqualifiedVersionless(); + final IIdType practitionerId1 = myClient.create().resource(practitioner1).execute().getId().toUnqualifiedVersionless(); Practitioner practitioner2 = new Practitioner(); - final IIdType practitionerId2 = ourClient.create().resource(practitioner2).execute().getId().toUnqualifiedVersionless(); + final IIdType practitionerId2 = myClient.create().resource(practitioner2).execute().getId().toUnqualifiedVersionless(); Patient patient = new Patient(); patient.setActive(true); - final IIdType patientId = ourClient.create().resource(patient).execute().getId().toUnqualifiedVersionless(); + final IIdType patientId = myClient.create().resource(patient).execute().getId().toUnqualifiedVersionless(); ourRestServer.registerInterceptor(new AuthorizationInterceptor(PolicyEnum.DENY) { @Override @@ -1136,28 +1136,24 @@ public class AuthorizationInterceptorJpaR4Test extends BaseResourceProviderR4Tes obs1.setStatus(ObservationStatus.FINAL); obs1.setPerformer( Arrays.asList(new Reference(practitionerId1), new Reference(practitionerId2))); - IIdType oid1 = ourClient.create().resource(obs1).execute().getId().toUnqualified(); + IIdType oid1 = myClient.create().resource(obs1).execute().getId().toUnqualified(); // Observation with practitioner1 and practitioner1 as the Performer -> should have the read access - ourClient.read().resource(Observation.class).withId(oid1).execute(); + myClient.read().resource(Observation.class).withId(oid1).execute(); Observation obs2 = new Observation(); obs2.setStatus(ObservationStatus.FINAL); obs2.setSubject(new Reference(patientId)); - IIdType oid2 = ourClient.create().resource(obs2).execute().getId().toUnqualified(); + IIdType oid2 = myClient.create().resource(obs2).execute().getId().toUnqualified(); // Observation with patient as the subject -> read access should be blocked try { - ourClient.read().resource(Observation.class).withId(oid2).execute(); + myClient.read().resource(Observation.class).withId(oid2).execute(); fail(); } catch (ForbiddenOperationException e) { // good } } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/AuthorizationInterceptorMultitenantJpaR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/AuthorizationInterceptorMultitenantJpaR4Test.java index f639013be2a..d76e06eb332 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/AuthorizationInterceptorMultitenantJpaR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/AuthorizationInterceptorMultitenantJpaR4Test.java @@ -2,7 +2,6 @@ package ca.uhn.fhir.jpa.provider.r4; import ca.uhn.fhir.jpa.model.config.PartitionSettings; import ca.uhn.fhir.jpa.model.entity.ResourceTable; -import ca.uhn.fhir.jpa.util.TestUtil; import ca.uhn.fhir.rest.server.exceptions.ForbiddenOperationException; import ca.uhn.fhir.rest.server.interceptor.auth.RuleBuilder; import ca.uhn.fhir.test.utilities.ITestDataBuilder; @@ -12,19 +11,18 @@ import org.hl7.fhir.instance.model.api.IIdType; import org.hl7.fhir.r4.model.Bundle; import org.hl7.fhir.r4.model.Observation; import org.hl7.fhir.r4.model.Patient; -import org.junit.AfterClass; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.util.List; import java.util.Optional; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.contains; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; @SuppressWarnings("Duplicates") public class AuthorizationInterceptorMultitenantJpaR4Test extends BaseMultitenantResourceProviderR4Test implements ITestDataBuilder { @@ -56,7 +54,7 @@ public class AuthorizationInterceptorMultitenantJpaR4Test extends BaseMultitenan myTenantClientInterceptor.setTenantId(TENANT_B); try { - ourClient.read().resource(Patient.class).withId(idB).execute(); + myClient.read().resource(Patient.class).withId(idB).execute(); fail(); } catch (ForbiddenOperationException e) { // good @@ -73,7 +71,7 @@ public class AuthorizationInterceptorMultitenantJpaR4Test extends BaseMultitenan .build()); myTenantClientInterceptor.setTenantId(TENANT_A); - Patient p = ourClient.read().resource(Patient.class).withId(idA).execute(); + Patient p = myClient.read().resource(Patient.class).withId(idA).execute(); assertTrue(p.getActive()); } @@ -88,7 +86,7 @@ public class AuthorizationInterceptorMultitenantJpaR4Test extends BaseMultitenan myTenantClientInterceptor.setTenantId(TENANT_B); try { - ourClient.read().resource(Patient.class).withId(idB).execute(); + myClient.read().resource(Patient.class).withId(idB).execute(); fail(); } catch (ForbiddenOperationException e) { // good @@ -104,7 +102,7 @@ public class AuthorizationInterceptorMultitenantJpaR4Test extends BaseMultitenan .build()); myTenantClientInterceptor.setTenantId("DEFAULT"); - Patient p = ourClient.read().resource(Patient.class).withId(idA).execute(); + Patient p = myClient.read().resource(Patient.class).withId(idA).execute(); assertTrue(p.getActive()); } @@ -118,7 +116,7 @@ public class AuthorizationInterceptorMultitenantJpaR4Test extends BaseMultitenan myTenantClientInterceptor.setTenantId(TENANT_A); try { - ourClient.read().resource(Patient.class).withId(idA).execute(); + myClient.read().resource(Patient.class).withId(idA).execute(); fail(); } catch (ForbiddenOperationException e) { // good @@ -138,7 +136,7 @@ public class AuthorizationInterceptorMultitenantJpaR4Test extends BaseMultitenan myTenantClientInterceptor.setTenantId(TENANT_B); - Bundle output = ourClient + Bundle output = myClient .search() .forResource("Observation") .include(Observation.INCLUDE_ALL) @@ -161,7 +159,7 @@ public class AuthorizationInterceptorMultitenantJpaR4Test extends BaseMultitenan myTenantClientInterceptor.setTenantId(TENANT_B); try { - ourClient + myClient .search() .forResource("Observation") .include(Observation.INCLUDE_ALL) @@ -194,7 +192,7 @@ public class AuthorizationInterceptorMultitenantJpaR4Test extends BaseMultitenan myTenantClientInterceptor.setTenantId(TENANT_A); // Search and fetch the first 3 - Bundle bundle = ourClient + Bundle bundle = myClient .search() .forResource("Observation") .include(Observation.INCLUDE_ALL) @@ -206,7 +204,7 @@ public class AuthorizationInterceptorMultitenantJpaR4Test extends BaseMultitenan assertThat(toUnqualifiedVersionlessIds(bundle).toString(), toUnqualifiedVersionlessIds(bundle), contains(observationIds.get(0), observationIds.get(1), observationIds.get(2), patientIdA)); // Fetch the next 3 - bundle = ourClient + bundle = myClient .loadPage() .next(bundle) .execute(); @@ -215,7 +213,7 @@ public class AuthorizationInterceptorMultitenantJpaR4Test extends BaseMultitenan // Fetch the next 3 - This should fail as the last observation has a cross-partition reference try { - bundle = ourClient + bundle = myClient .loadPage() .next(bundle) .execute(); @@ -226,8 +224,4 @@ public class AuthorizationInterceptorMultitenantJpaR4Test extends BaseMultitenan } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/BaseMultitenantResourceProviderR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/BaseMultitenantResourceProviderR4Test.java index a7598137a0b..c85c4315dbd 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/BaseMultitenantResourceProviderR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/BaseMultitenantResourceProviderR4Test.java @@ -19,8 +19,8 @@ import org.hl7.fhir.instance.model.api.IIdType; import org.hl7.fhir.r4.model.CodeType; import org.hl7.fhir.r4.model.IntegerType; import org.hl7.fhir.r4.model.Parameters; -import org.junit.After; -import org.junit.Before; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.springframework.beans.factory.annotation.Autowired; import java.util.List; @@ -45,7 +45,7 @@ public abstract class BaseMultitenantResourceProviderR4Test extends BaseResource protected AuthorizationInterceptor myAuthorizationInterceptor; @Override - @Before + @BeforeEach public void before() throws Exception { super.before(); @@ -55,18 +55,18 @@ public abstract class BaseMultitenantResourceProviderR4Test extends BaseResource ourRestServer.setTenantIdentificationStrategy(new UrlBaseTenantIdentificationStrategy()); myCapturingInterceptor = new CapturingInterceptor(); - ourClient.getInterceptorService().registerInterceptor(myCapturingInterceptor); + myClient.getInterceptorService().registerInterceptor(myCapturingInterceptor); myTenantClientInterceptor = new UrlTenantSelectionInterceptor(); - ourClient.getInterceptorService().registerInterceptor(myTenantClientInterceptor); + myClient.getInterceptorService().registerInterceptor(myTenantClientInterceptor); - ourClient.getInterceptorService().registerInterceptor(new LoggingInterceptor()); + myClient.getInterceptorService().registerInterceptor(new LoggingInterceptor()); createTenants(); } @Override - @After + @AfterEach public void after() throws Exception { super.after(); @@ -78,7 +78,7 @@ public abstract class BaseMultitenantResourceProviderR4Test extends BaseResource ourRestServer.unregisterProvider(myPartitionManagementProvider); ourRestServer.setTenantIdentificationStrategy(null); - ourClient.getInterceptorService().unregisterAllInterceptors(); + myClient.getInterceptorService().unregisterAllInterceptors(); } @Override @@ -90,7 +90,7 @@ public abstract class BaseMultitenantResourceProviderR4Test extends BaseResource private void createTenants() { myTenantClientInterceptor.setTenantId(DEFAULT_PERSISTED_PARTITION_NAME); - ourClient + myClient .operation() .onServer() .named(ProviderConstants.PARTITION_MANAGEMENT_CREATE_PARTITION) @@ -98,7 +98,7 @@ public abstract class BaseMultitenantResourceProviderR4Test extends BaseResource .andParameter(ProviderConstants.PARTITION_MANAGEMENT_PARTITION_NAME, new CodeType(TENANT_A)) .execute(); - ourClient + myClient .operation() .onServer() .named(ProviderConstants.PARTITION_MANAGEMENT_CREATE_PARTITION) @@ -125,12 +125,12 @@ public abstract class BaseMultitenantResourceProviderR4Test extends BaseResource @Override public IIdType doCreateResource(IBaseResource theResource) { - return ourClient.create().resource(theResource).execute().getId(); + return myClient.create().resource(theResource).execute().getId(); } @Override public IIdType doUpdateResource(IBaseResource theResource) { - return ourClient.update().resource(theResource).execute().getId(); + return myClient.update().resource(theResource).execute().getId(); } @Override diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/BaseResourceProviderR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/BaseResourceProviderR4Test.java index e3acdc27278..d6393c27fe1 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/BaseResourceProviderR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/BaseResourceProviderR4Test.java @@ -34,9 +34,9 @@ import org.hl7.fhir.r4.model.Bundle.BundleEntryComponent; import org.hl7.fhir.r4.model.Parameters; import org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent; import org.hl7.fhir.r4.model.Patient; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.context.ContextLoader; import org.springframework.web.context.WebApplicationContext; @@ -66,7 +66,7 @@ public abstract class BaseResourceProviderR4Test extends BaseJpaR4Test { private static DatabaseBackedPagingProvider ourPagingProvider; private static GenericWebApplicationContext ourWebApplicationContext; private static SubscriptionMatcherInterceptor ourSubscriptionMatcherInterceptor; - protected IGenericClient ourClient; + protected IGenericClient myClient; @Autowired protected SubscriptionLoader mySubscriptionLoader; @Autowired @@ -79,14 +79,13 @@ public abstract class BaseResourceProviderR4Test extends BaseJpaR4Test { super(); } - @After + @AfterEach public void after() throws Exception { myFhirCtx.getRestfulClientFactory().setServerValidationMode(ServerValidationModeEnum.ONCE); ourRestServer.getInterceptorService().unregisterAllInterceptors(); } - @SuppressWarnings({"unchecked", "rawtypes"}) - @Before + @BeforeEach public void before() throws Exception { myFhirCtx.getRestfulClientFactory().setServerValidationMode(ServerValidationModeEnum.NEVER); myFhirCtx.getRestfulClientFactory().setSocketTimeout(1200 * 1000); @@ -181,9 +180,9 @@ public abstract class BaseResourceProviderR4Test extends BaseJpaR4Test { ourRestServer.setPagingProvider(ourPagingProvider); - ourClient = myFhirCtx.newRestfulGenericClient(ourServerBase); + myClient = myFhirCtx.newRestfulGenericClient(ourServerBase); if (shouldLogClient()) { - ourClient.registerInterceptor(new LoggingInterceptor()); + myClient.registerInterceptor(new LoggingInterceptor()); } } @@ -208,7 +207,7 @@ public abstract class BaseResourceProviderR4Test extends BaseJpaR4Test { Thread.sleep(500); } - @AfterClass + @AfterAll public static void afterClassClearContextBaseResourceProviderR4Test() throws Exception { JettyUtil.closeServer(ourServer); ourHttpClient.close(); @@ -218,7 +217,6 @@ public abstract class BaseResourceProviderR4Test extends BaseJpaR4Test { myValidationSupport = null; ourWebApplicationContext.close(); ourWebApplicationContext = null; - TestUtil.clearAllStaticFieldsForUnitTest(); } public static int getNumberOfParametersByName(Parameters theParameters, String theName) { diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/BinaryAccessProviderR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/BinaryAccessProviderR4Test.java index dc03b27fba1..1f914ed838c 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/BinaryAccessProviderR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/BinaryAccessProviderR4Test.java @@ -19,15 +19,10 @@ import org.apache.http.client.methods.HttpPost; import org.apache.http.entity.ByteArrayEntity; import org.apache.http.entity.ContentType; import org.hl7.fhir.instance.model.api.IIdType; -import org.hl7.fhir.r4.model.Attachment; -import org.hl7.fhir.r4.model.Binary; -import org.hl7.fhir.r4.model.BooleanType; -import org.hl7.fhir.r4.model.DocumentReference; -import org.hl7.fhir.r4.model.Parameters; -import org.hl7.fhir.r4.model.StringType; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.hl7.fhir.r4.model.*; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -35,21 +30,11 @@ import org.springframework.beans.factory.annotation.Autowired; import java.io.ByteArrayOutputStream; import java.io.IOException; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.matchesPattern; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; -import static org.mockito.Mockito.any; -import static org.mockito.Mockito.doAnswer; -import static org.mockito.Mockito.eq; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.timeout; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoMoreInteractions; +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.Mockito.*; public class BinaryAccessProviderR4Test extends BaseResourceProviderR4Test { @@ -63,7 +48,7 @@ public class BinaryAccessProviderR4Test extends BaseResourceProviderR4Test { private IBinaryStorageSvc myBinaryStorageSvc; @Override - @Before + @BeforeEach public void before() throws Exception { super.before(); myStorageSvc.setMinimumBinarySize(10); @@ -72,7 +57,7 @@ public class BinaryAccessProviderR4Test extends BaseResourceProviderR4Test { } @Override - @After + @AfterEach public void after() throws Exception { super.after(); myStorageSvc.setMinimumBinarySize(0); @@ -305,7 +290,7 @@ public class BinaryAccessProviderR4Test extends BaseResourceProviderR4Test { .addExtension(HapiExtensions.EXT_EXTERNALIZED_BINARY_ID, new StringType("0000-1111") ); try { - ourClient.create().resource(dr).execute(); + myClient.create().resource(dr).execute(); fail(); } catch (InvalidRequestException e) { assertThat(e.getMessage(), containsString("Can not find the requested binary content. It may have been deleted.")); @@ -369,7 +354,7 @@ public class BinaryAccessProviderR4Test extends BaseResourceProviderR4Test { ourLog.info(myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(binary)); - IIdType id = ourClient.create().resource(binary).execute().getId().toUnqualifiedVersionless(); + IIdType id = myClient.create().resource(binary).execute().getId().toUnqualifiedVersionless(); IAnonymousInterceptor interceptor = mock(IAnonymousInterceptor.class); myInterceptorRegistry.registerAnonymousInterceptor(Pointcut.STORAGE_PRESHOW_RESOURCES, interceptor); @@ -436,7 +421,7 @@ public class BinaryAccessProviderR4Test extends BaseResourceProviderR4Test { ourLog.info(myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(binary)); - IIdType id = ourClient.create().resource(binary).execute().getId().toUnqualifiedVersionless(); + IIdType id = myClient.create().resource(binary).execute().getId().toUnqualifiedVersionless(); // Write using the operation @@ -501,7 +486,7 @@ public class BinaryAccessProviderR4Test extends BaseResourceProviderR4Test { ourLog.info(myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(documentReference)); - return ourClient.create().resource(documentReference).execute().getId().toUnqualifiedVersionless(); + return myClient.create().resource(documentReference).execute().getId().toUnqualifiedVersionless(); } @@ -532,9 +517,9 @@ public class BinaryAccessProviderR4Test extends BaseResourceProviderR4Test { assertEquals(15, capture.size()); // Now delete (logical delete- should not expunge the binary) - ourClient.delete().resourceById(id).execute(); + myClient.delete().resourceById(id).execute(); try { - ourClient.read().resource("DocumentReference").withId(id).execute(); + myClient.read().resource("DocumentReference").withId(id).execute(); fail(); } catch (ResourceGoneException e) { // good @@ -547,7 +532,7 @@ public class BinaryAccessProviderR4Test extends BaseResourceProviderR4Test { // Now expunge Parameters parameters = new Parameters(); parameters.addParameter().setName(JpaConstants.OPERATION_EXPUNGE_PARAM_EXPUNGE_DELETED_RESOURCES).setValue(new BooleanType(true)); - ourClient + myClient .operation() .onInstance(id) .named(JpaConstants.OPERATION_EXPUNGE) diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/BinaryStorageInterceptorR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/BinaryStorageInterceptorR4Test.java index 30297631352..5084e9ec123 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/BinaryStorageInterceptorR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/BinaryStorageInterceptorR4Test.java @@ -12,21 +12,16 @@ import org.hl7.fhir.r4.model.Binary; import org.hl7.fhir.r4.model.DocumentReference; import org.hl7.fhir.r4.model.Enumerations; import org.hl7.fhir.r4.model.StringType; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import static org.hamcrest.Matchers.blankOrNullString; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.not; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.*; +import static org.junit.jupiter.api.Assertions.*; public class BinaryStorageInterceptorR4Test extends BaseResourceProviderR4Test { @@ -41,7 +36,7 @@ public class BinaryStorageInterceptorR4Test extends BaseResourceProviderR4Test { private IBinaryStorageSvc myBinaryStorageSvc; @Override - @Before + @BeforeEach public void before() throws Exception { super.before(); myStorageSvc.setMinimumBinarySize(10); @@ -50,7 +45,7 @@ public class BinaryStorageInterceptorR4Test extends BaseResourceProviderR4Test { } @Override - @After + @AfterEach public void after() throws Exception { super.after(); myStorageSvc.setMinimumBinarySize(0); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/CascadingDeleteInterceptorR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/CascadingDeleteInterceptorR4Test.java index 19ebdc194b4..231d1ebc2de 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/CascadingDeleteInterceptorR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/CascadingDeleteInterceptorR4Test.java @@ -6,23 +6,30 @@ import ca.uhn.fhir.jpa.interceptor.CascadingDeleteInterceptor; import ca.uhn.fhir.rest.api.Constants; import ca.uhn.fhir.rest.server.exceptions.ResourceGoneException; import ca.uhn.fhir.rest.server.exceptions.ResourceVersionConflictException; -import ca.uhn.fhir.util.TestUtil; import com.google.common.base.Charsets; import org.apache.commons.io.IOUtils; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpDelete; import org.hl7.fhir.instance.model.api.IIdType; -import org.hl7.fhir.r4.model.*; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Test; +import org.hl7.fhir.r4.model.CarePlan; +import org.hl7.fhir.r4.model.Condition; +import org.hl7.fhir.r4.model.DiagnosticReport; +import org.hl7.fhir.r4.model.Encounter; +import org.hl7.fhir.r4.model.Observation; +import org.hl7.fhir.r4.model.Organization; +import org.hl7.fhir.r4.model.Patient; +import org.hl7.fhir.r4.model.Reference; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import java.io.IOException; import static org.hamcrest.CoreMatchers.containsString; -import static org.junit.Assert.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; public class CascadingDeleteInterceptorR4Test extends BaseResourceProviderR4Test { @@ -41,7 +48,7 @@ public class CascadingDeleteInterceptorR4Test extends BaseResourceProviderR4Test private IIdType myEncounterId; @Override - @Before + @BeforeEach public void before() throws Exception { super.before(); @@ -49,7 +56,7 @@ public class CascadingDeleteInterceptorR4Test extends BaseResourceProviderR4Test } @Override - @After + @AfterEach public void after() throws Exception { super.after(); ourRestServer.getInterceptorService().unregisterInterceptor(myDeleteInterceptor); @@ -58,33 +65,33 @@ public class CascadingDeleteInterceptorR4Test extends BaseResourceProviderR4Test public void createResources() { Patient p = new Patient(); p.setActive(true); - myPatientId = ourClient.create().resource(p).execute().getId().toUnqualifiedVersionless(); + myPatientId = myClient.create().resource(p).execute().getId().toUnqualifiedVersionless(); Encounter e = new Encounter(); e.setSubject(new Reference(myPatientId)); - myEncounterId = ourClient.create().resource(e).execute().getId().toUnqualifiedVersionless(); + myEncounterId = myClient.create().resource(e).execute().getId().toUnqualifiedVersionless(); CarePlan cp = new CarePlan(); cp.setEncounter(new Reference(myEncounterId)); - ourClient.create().resource(cp).execute(); + myClient.create().resource(cp).execute(); Observation o = new Observation(); o.setStatus(Observation.ObservationStatus.FINAL); - o.setSubject( new Reference(myPatientId)); + o.setSubject(new Reference(myPatientId)); o.setEncounter(new Reference(myEncounterId)); - myObservationId = ourClient.create().resource(o).execute().getId().toUnqualifiedVersionless(); + myObservationId = myClient.create().resource(o).execute().getId().toUnqualifiedVersionless(); DiagnosticReport dr = new DiagnosticReport(); dr.setStatus(DiagnosticReport.DiagnosticReportStatus.FINAL); dr.addResult().setReference(myObservationId.getValue()); dr.setEncounter(new Reference(myEncounterId)); - myDiagnosticReportId = ourClient.create().resource(dr).execute().getId().toUnqualifiedVersionless(); + myDiagnosticReportId = myClient.create().resource(dr).execute().getId().toUnqualifiedVersionless(); Condition condition = new Condition(); condition.setSubject(new Reference(myPatientId)); condition.setAsserter(new Reference(myPatientId)); condition.setEncounter(new Reference(myEncounterId)); - myConditionId = ourClient.create().resource(condition).execute().getId().toUnqualifiedVersionless(); + myConditionId = myClient.create().resource(condition).execute().getId().toUnqualifiedVersionless(); } @Test @@ -92,7 +99,7 @@ public class CascadingDeleteInterceptorR4Test extends BaseResourceProviderR4Test createResources(); try { - ourClient.delete().resourceById(myPatientId).execute(); + myClient.delete().resourceById(myPatientId).execute(); fail(); } catch (ResourceVersionConflictException e) { // good @@ -121,7 +128,7 @@ public class CascadingDeleteInterceptorR4Test extends BaseResourceProviderR4Test ourRestServer.getInterceptorService().registerInterceptor(myDeleteInterceptor); try { - ourClient.delete().resourceById(myPatientId).execute(); + myClient.delete().resourceById(myPatientId).execute(); fail(); } catch (ResourceVersionConflictException e) { String output = myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(e.getOperationOutcome()); @@ -147,7 +154,7 @@ public class CascadingDeleteInterceptorR4Test extends BaseResourceProviderR4Test try { ourLog.info("Reading {}", myPatientId); - ourClient.read().resource(Patient.class).withId(myPatientId).execute(); + myClient.read().resource(Patient.class).withId(myPatientId).execute(); fail(); } catch (ResourceGoneException e) { // good @@ -182,14 +189,14 @@ public class CascadingDeleteInterceptorR4Test extends BaseResourceProviderR4Test try { ourLog.info("Reading {}", o0id); - ourClient.read().resource(Organization.class).withId(o0id).execute(); + myClient.read().resource(Organization.class).withId(o0id).execute(); fail(); } catch (ResourceGoneException e) { // good } try { ourLog.info("Reading {}", o1id); - ourClient.read().resource(Organization.class).withId(o1id).execute(); + myClient.read().resource(Organization.class).withId(o1id).execute(); fail(); } catch (ResourceGoneException e) { // good @@ -214,17 +221,13 @@ public class CascadingDeleteInterceptorR4Test extends BaseResourceProviderR4Test try { ourLog.info("Reading {}", myPatientId); - ourClient.read().resource(Patient.class).withId(myPatientId).execute(); + myClient.read().resource(Patient.class).withId(myPatientId).execute(); fail(); } catch (ResourceGoneException e) { // good } } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/CompositionDocumentR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/CompositionDocumentR4Test.java index 97463c51ce9..f62bb71cc23 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/CompositionDocumentR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/CompositionDocumentR4Test.java @@ -7,16 +7,14 @@ import ca.uhn.fhir.jpa.api.config.DaoConfig; import ca.uhn.fhir.parser.StrictErrorHandler; import ca.uhn.fhir.rest.api.EncodingEnum; import ca.uhn.fhir.rest.api.server.IPreResourceAccessDetails; -import ca.uhn.fhir.util.TestUtil; import com.google.common.base.Charsets; import org.apache.commons.io.IOUtils; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; import org.hl7.fhir.r4.model.*; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.Mockito; @@ -29,8 +27,8 @@ import java.util.Set; import static org.hamcrest.Matchers.hasItem; import static org.hamcrest.Matchers.hasItems; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThat; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.*; @@ -47,13 +45,13 @@ public class CompositionDocumentR4Test extends BaseResourceProviderR4Test { @Captor private ArgumentCaptor myHookParamsCaptor; - @Before + @BeforeEach public void beforeDisableResultReuse() { myDaoConfig.setReuseCachedSearchResultsForMillis(null); } @Override - @After + @AfterEach public void after() throws Exception { super.after(); @@ -61,6 +59,7 @@ public class CompositionDocumentR4Test extends BaseResourceProviderR4Test { } @Override + @BeforeEach public void before() throws Exception { super.before(); myFhirCtx.setParserErrorHandler(new StrictErrorHandler()); @@ -69,18 +68,18 @@ public class CompositionDocumentR4Test extends BaseResourceProviderR4Test { Organization org = new Organization(); org.setName("an org"); - orgId = ourClient.create().resource(org).execute().getId().toUnqualifiedVersionless().getValue(); + orgId = myClient.create().resource(org).execute().getId().toUnqualifiedVersionless().getValue(); ourLog.info("OrgId: {}", orgId); Patient patient = new Patient(); patient.getManagingOrganization().setReference(orgId); - patId = ourClient.create().resource(patient).execute().getId().toUnqualifiedVersionless().getValue(); + patId = myClient.create().resource(patient).execute().getId().toUnqualifiedVersionless().getValue(); Encounter enc = new Encounter(); enc.setStatus(Encounter.EncounterStatus.ARRIVED); enc.getSubject().setReference(patId); enc.getServiceProvider().setReference(orgId); - encId = ourClient.create().resource(enc).execute().getId().toUnqualifiedVersionless().getValue(); + encId = myClient.create().resource(enc).execute().getId().toUnqualifiedVersionless().getValue(); ListResource listResource = new ListResource(); @@ -90,13 +89,13 @@ public class CompositionDocumentR4Test extends BaseResourceProviderR4Test { Observation obs = new Observation(); obs.getSubject().setReference(patId); obs.setStatus(Observation.ObservationStatus.FINAL); - String obsId = ourClient.create().resource(obs).execute().getId().toUnqualifiedVersionless().getValue(); + String obsId = myClient.create().resource(obs).execute().getId().toUnqualifiedVersionless().getValue(); listResource.addEntry(new ListResource.ListEntryComponent().setItem(new Reference(obs))); myObs.add(obs); myObsIds.add(obsId); } - listId = ourClient.create().resource(listResource).execute().getId().toUnqualifiedVersionless().getValue(); + listId = myClient.create().resource(listResource).execute().getId().toUnqualifiedVersionless().getValue(); Composition composition = new Composition(); composition.setSubject(new Reference(patId)); @@ -108,7 +107,7 @@ public class CompositionDocumentR4Test extends BaseResourceProviderR4Test { for (String obsId : myObsIds) { composition.addSection().addEntry(new Reference(obsId)); } - compId = ourClient.create().resource(composition).execute().getId().toUnqualifiedVersionless().getValue(); + compId = myClient.create().resource(composition).execute().getId().toUnqualifiedVersionless().getValue(); } @Test @@ -184,8 +183,4 @@ public class CompositionDocumentR4Test extends BaseResourceProviderR4Test { return bundle; } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ConsentInterceptorResourceProviderR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ConsentInterceptorResourceProviderR4Test.java index fe89fad7457..4b8936d1200 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ConsentInterceptorResourceProviderR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ConsentInterceptorResourceProviderR4Test.java @@ -37,16 +37,16 @@ import org.hl7.fhir.r4.model.Observation; import org.hl7.fhir.r4.model.OperationOutcome; import org.hl7.fhir.r4.model.Organization; import org.hl7.fhir.r4.model.Patient; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import java.io.IOException; import java.util.ArrayList; @@ -57,18 +57,18 @@ import java.util.stream.Collectors; import static org.apache.commons.lang3.StringUtils.leftPad; import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.CoreMatchers.not; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.blankOrNullString; import static org.hamcrest.Matchers.matchesPattern; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = {TestR4Config.class}) public class ConsentInterceptorResourceProviderR4Test extends BaseResourceProviderR4Test { @@ -84,7 +84,7 @@ public class ConsentInterceptorResourceProviderR4Test extends BaseResourceProvid private Object myGraphQlProvider; @Override - @After + @AfterEach public void after() throws Exception { super.after(); Validate.notNull(myConsentInterceptor); @@ -94,7 +94,7 @@ public class ConsentInterceptorResourceProviderR4Test extends BaseResourceProvid } @Override - @Before + @BeforeEach public void before() throws Exception { super.before(); myDaoConfig.setSearchPreFetchThresholds(Arrays.asList(20, 50, 190)); @@ -110,7 +110,7 @@ public class ConsentInterceptorResourceProviderR4Test extends BaseResourceProvid ourRestServer.getInterceptorService().registerInterceptor(myConsentInterceptor); // Perform a search - Bundle result = ourClient + Bundle result = myClient .search() .forResource("Observation") .sort() @@ -123,7 +123,7 @@ public class ConsentInterceptorResourceProviderR4Test extends BaseResourceProvid assertEquals(myObservationIdsEvenOnly.subList(0, 15), returnedIdValues); // Fetch the next page - result = ourClient + result = myClient .loadPage() .next(result) .execute(); @@ -141,7 +141,7 @@ public class ConsentInterceptorResourceProviderR4Test extends BaseResourceProvid create50Observations(); CapturingInterceptor capture = new CapturingInterceptor(); - ourClient.registerInterceptor(capture); + myClient.registerInterceptor(capture); DelegatingConsentService consentService = new DelegatingConsentService(); myConsentInterceptor = new ConsentInterceptor(consentService, IConsentContextServices.NULL_IMPL); @@ -149,7 +149,7 @@ public class ConsentInterceptorResourceProviderR4Test extends BaseResourceProvid // Perform a search and only allow even consentService.setTarget(new ConsentSvcCantSeeOddNumbered()); - Bundle result = ourClient + Bundle result = myClient .search() .forResource("Observation") .sort() @@ -165,7 +165,7 @@ public class ConsentInterceptorResourceProviderR4Test extends BaseResourceProvid // Perform a search and only allow odd consentService.setTarget(new ConsentSvcCantSeeEvenNumbered()); - result = ourClient + result = myClient .search() .forResource("Observation") .sort() @@ -181,7 +181,7 @@ public class ConsentInterceptorResourceProviderR4Test extends BaseResourceProvid // Perform a search and allow all with a PROCEED consentService.setTarget(new ConsentSvcNop(ConsentOperationStatusEnum.PROCEED)); - result = ourClient + result = myClient .search() .forResource("Observation") .sort() @@ -197,7 +197,7 @@ public class ConsentInterceptorResourceProviderR4Test extends BaseResourceProvid // Perform a search and allow all with an AUTHORIZED (no further checking) consentService.setTarget(new ConsentSvcNop(ConsentOperationStatusEnum.AUTHORIZED)); - result = ourClient + result = myClient .search() .forResource("Observation") .sort() @@ -214,7 +214,7 @@ public class ConsentInterceptorResourceProviderR4Test extends BaseResourceProvid // Perform a second search and allow all with an AUTHORIZED (no further checking) // which means we should finally get one from the cache consentService.setTarget(new ConsentSvcNop(ConsentOperationStatusEnum.AUTHORIZED)); - result = ourClient + result = myClient .search() .forResource("Observation") .sort() @@ -228,7 +228,7 @@ public class ConsentInterceptorResourceProviderR4Test extends BaseResourceProvid cacheOutcome = capture.getLastResponse().getHeaders(Constants.HEADER_X_CACHE); assertThat(cacheOutcome.get(0), matchesPattern("^HIT from .*")); - ourClient.unregisterInterceptor(capture); + myClient.unregisterInterceptor(capture); } @Test @@ -240,7 +240,7 @@ public class ConsentInterceptorResourceProviderR4Test extends BaseResourceProvid ourRestServer.getInterceptorService().registerInterceptor(myConsentInterceptor); // Perform a search - Bundle result = ourClient + Bundle result = myClient .search() .forResource("Observation") .sort() @@ -256,7 +256,7 @@ public class ConsentInterceptorResourceProviderR4Test extends BaseResourceProvid }); // Fetch the next page - result = ourClient + result = myClient .loadPage() .next(result) .execute(); @@ -277,7 +277,7 @@ public class ConsentInterceptorResourceProviderR4Test extends BaseResourceProvid ourRestServer.getInterceptorService().registerInterceptor(myConsentInterceptor); // Perform a search - Bundle result = ourClient + Bundle result = myClient .history() .onServer() .returnBundle(Bundle.class) @@ -297,17 +297,17 @@ public class ConsentInterceptorResourceProviderR4Test extends BaseResourceProvid myConsentInterceptor = new ConsentInterceptor(consentService, IConsentContextServices.NULL_IMPL); ourRestServer.getInterceptorService().registerInterceptor(myConsentInterceptor); - ourClient.read().resource("Observation").withId(new IdType(myObservationIdsEvenOnly.get(0))).execute(); - ourClient.read().resource("Observation").withId(new IdType(myObservationIdsEvenOnly.get(1))).execute(); + myClient.read().resource("Observation").withId(new IdType(myObservationIdsEvenOnly.get(0))).execute(); + myClient.read().resource("Observation").withId(new IdType(myObservationIdsEvenOnly.get(1))).execute(); try { - ourClient.read().resource("Observation").withId(new IdType(myObservationIdsOddOnly.get(0))).execute(); + myClient.read().resource("Observation").withId(new IdType(myObservationIdsOddOnly.get(0))).execute(); fail(); } catch (ResourceNotFoundException e) { // good } try { - ourClient.read().resource("Observation").withId(new IdType(myObservationIdsOddOnly.get(1))).execute(); + myClient.read().resource("Observation").withId(new IdType(myObservationIdsOddOnly.get(1))).execute(); fail(); } catch (ResourceNotFoundException e) { // good @@ -363,7 +363,7 @@ public class ConsentInterceptorResourceProviderR4Test extends BaseResourceProvid Patient patient = new Patient(); patient.setActive(true); - IIdType id = ourClient.create().resource(patient).prefer(PreferReturnEnum.REPRESENTATION).execute().getId().toUnqualifiedVersionless(); + IIdType id = myClient.create().resource(patient).prefer(PreferReturnEnum.REPRESENTATION).execute().getId().toUnqualifiedVersionless(); DelegatingConsentService consentService = new DelegatingConsentService(); myConsentInterceptor = new ConsentInterceptor(consentService, IConsentContextServices.NULL_IMPL); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/CorsR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/CorsR4Test.java index 31571ce57c1..33a3fd4c5a0 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/CorsR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/CorsR4Test.java @@ -1,14 +1,14 @@ package ca.uhn.fhir.jpa.provider.r4; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.io.IOException; import org.apache.commons.io.IOUtils; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; -import org.junit.AfterClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; import ca.uhn.fhir.util.TestUtil; @@ -29,9 +29,5 @@ public class CorsR4Test extends BaseResourceProviderR4Test { } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/DiffProviderR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/DiffProviderR4Test.java index f793d39cd28..4bef2c7b8d0 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/DiffProviderR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/DiffProviderR4Test.java @@ -10,14 +10,14 @@ import org.hl7.fhir.r4.model.IdType; import org.hl7.fhir.r4.model.Parameters; import org.hl7.fhir.r4.model.Patient; import org.hl7.fhir.r4.model.StringType; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import static ca.uhn.fhir.jpa.patch.FhirPatchApplyR4Test.extractPartValue; import static ca.uhn.fhir.jpa.patch.FhirPatchApplyR4Test.extractPartValuePrimitive; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; public class DiffProviderR4Test extends BaseResourceProviderR4Test { @@ -31,7 +31,7 @@ public class DiffProviderR4Test extends BaseResourceProviderR4Test { createPatient(withId(id), withActiveTrue()); createPatient(withId(id), withActiveTrue(), withFamily("SMITH")); - Parameters diff = ourClient + Parameters diff = myClient .operation() .onInstance(id) .named(ProviderConstants.DIFF_OPERATION_NAME) @@ -54,7 +54,7 @@ public class DiffProviderR4Test extends BaseResourceProviderR4Test { assertEquals("SMITH", extractPartValue(diff, 1, "operation", "value", HumanName.class).getFamily()); } - + @Test public void testLatestVersion_2_to_3() { // Create and 2 updates @@ -62,7 +62,7 @@ public class DiffProviderR4Test extends BaseResourceProviderR4Test { createPatient(withId(id), withActiveTrue()); createPatient(withId(id), withActiveTrue(), withFamily("SMITH")); - Parameters diff = ourClient + Parameters diff = myClient .operation() .onInstance(id) .named(ProviderConstants.DIFF_OPERATION_NAME) @@ -81,7 +81,7 @@ public class DiffProviderR4Test extends BaseResourceProviderR4Test { assertEquals("replace", extractPartValuePrimitive(diff, 1, "operation", "type")); assertEquals("Patient.meta.lastUpdated", extractPartValuePrimitive(diff, 1, "operation", "path")); - + assertEquals("replace", extractPartValuePrimitive(diff, 2, "operation", "type")); assertEquals("Patient.text.div", extractPartValuePrimitive(diff, 2, "operation", "path")); assertEquals("
", extractPartValuePrimitive(diff, 2, "operation", "previousValue")); @@ -101,12 +101,12 @@ public class DiffProviderR4Test extends BaseResourceProviderR4Test { createPatient(withId(id), withActiveTrue()); createPatient(withId(id), withActiveTrue(), withFamily("SMITH")); - runInTransaction(()->{ + runInTransaction(() -> { ResourceHistoryTable version2 = myResourceHistoryTableDao.findForIdAndVersionAndFetchProvenance(id.getIdPartAsLong(), 2); myResourceHistoryTableDao.deleteByPid(version2.getId()); }); - Parameters diff = ourClient + Parameters diff = myClient .operation() .onInstance(id) .named(ProviderConstants.DIFF_OPERATION_NAME) @@ -130,7 +130,7 @@ public class DiffProviderR4Test extends BaseResourceProviderR4Test { // Create only IIdType id = createPatient(withActiveTrue()).toUnqualifiedVersionless(); - Parameters diff = ourClient + Parameters diff = myClient .operation() .onInstance(id) .named(ProviderConstants.DIFF_OPERATION_NAME) @@ -155,7 +155,7 @@ public class DiffProviderR4Test extends BaseResourceProviderR4Test { createPatient(withId(id), withActiveTrue()); createPatient(withId(id), withActiveTrue(), withFamily("SMITH")); - Parameters diff = ourClient + Parameters diff = myClient .operation() .onInstance(id) .named(ProviderConstants.DIFF_OPERATION_NAME) @@ -175,14 +175,13 @@ public class DiffProviderR4Test extends BaseResourceProviderR4Test { } - @Test public void testDifferentResources_Versionless() { // Create and 2 updates IIdType id1 = createPatient(withId("A"), withActiveFalse()).toUnqualifiedVersionless(); IIdType id2 = createPatient(withId("B"), withActiveTrue()).toUnqualifiedVersionless(); - Parameters diff = ourClient + Parameters diff = myClient .operation() .onServer() .named(ProviderConstants.DIFF_OPERATION_NAME) @@ -211,7 +210,7 @@ public class DiffProviderR4Test extends BaseResourceProviderR4Test { IIdType id2 = createPatient(withId("B"), withActiveFalse()).toUnqualifiedVersionless(); id2 = createPatient(withId(id2), withActiveTrue(), withFamily("JONES")).toUnqualified(); - Parameters diff = ourClient + Parameters diff = myClient .operation() .onServer() .named(ProviderConstants.DIFF_OPERATION_NAME) @@ -234,7 +233,7 @@ public class DiffProviderR4Test extends BaseResourceProviderR4Test { @Test public void testDifferentResources_DifferentTypes() { try { - ourClient + myClient .operation() .onServer() .named(ProviderConstants.DIFF_OPERATION_NAME) diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/EmptyIndexesR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/EmptyIndexesR4Test.java index 482c3fa6308..6b14da66fb2 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/EmptyIndexesR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/EmptyIndexesR4Test.java @@ -1,6 +1,7 @@ package ca.uhn.fhir.jpa.provider.r4; import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.context.FhirVersionEnum; import ca.uhn.fhir.jpa.api.config.DaoConfig; import ca.uhn.fhir.jpa.dao.r4.BaseJpaR4Test; import ca.uhn.fhir.jpa.rp.r4.ObservationResourceProvider; @@ -19,16 +20,16 @@ import org.eclipse.jetty.server.Server; import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletHolder; import org.hl7.fhir.r4.model.Observation; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import java.util.concurrent.TimeUnit; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.hasSize; -import static org.junit.Assert.assertThat; public class EmptyIndexesR4Test extends BaseJpaR4Test { private static RestfulServer myRestServer; @@ -40,20 +41,13 @@ public class EmptyIndexesR4Test extends BaseJpaR4Test { private SimpleRequestHeaderInterceptor mySimpleHeaderInterceptor; @SuppressWarnings("deprecation") - @After + @AfterEach public void after() { ourClient.unregisterInterceptor(mySimpleHeaderInterceptor); myDaoConfig.setIndexMissingFields(new DaoConfig().getIndexMissingFields()); } - @Before - public void before() { - mySimpleHeaderInterceptor = new SimpleRequestHeaderInterceptor(); - ourClient.registerInterceptor(mySimpleHeaderInterceptor); - myDaoConfig.setIndexMissingFields(DaoConfig.IndexEnabledEnum.DISABLED); - } - - @Before + @BeforeEach public void beforeStartServer() throws Exception { if (myRestServer == null) { PatientResourceProvider patientRp = new PatientResourceProvider(); @@ -82,7 +76,7 @@ public class EmptyIndexesR4Test extends BaseJpaR4Test { servletHolder.setServlet(restServer); proxyHandler.addServlet(servletHolder, "/fhir/context/*"); - ourCtx = FhirContext.forR4(); + ourCtx = FhirContext.forCached(FhirVersionEnum.R4); restServer.setFhirContext(ourCtx); ourServer.setHandler(proxyHandler); @@ -103,6 +97,10 @@ public class EmptyIndexesR4Test extends BaseJpaR4Test { myRestServer.setDefaultResponseEncoding(EncodingEnum.XML); myRestServer.setPagingProvider(myPagingProvider); + + mySimpleHeaderInterceptor = new SimpleRequestHeaderInterceptor(); + ourClient.registerInterceptor(mySimpleHeaderInterceptor); + myDaoConfig.setIndexMissingFields(DaoConfig.IndexEnabledEnum.DISABLED); } @@ -133,10 +131,9 @@ public class EmptyIndexesR4Test extends BaseJpaR4Test { } - @AfterClass + @AfterAll public static void afterClassClearContext() throws Exception { JettyUtil.closeServer(ourServer); - TestUtil.clearAllStaticFieldsForUnitTest(); } } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ExpungeR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ExpungeR4Test.java index 8b781bd5b01..ababc396273 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ExpungeR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ExpungeR4Test.java @@ -22,10 +22,10 @@ import org.hl7.fhir.r4.model.IdType; import org.hl7.fhir.r4.model.Observation; import org.hl7.fhir.r4.model.Patient; import org.hl7.fhir.r4.model.SearchParameter; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -33,11 +33,10 @@ import org.springframework.beans.factory.annotation.Autowired; import java.util.List; import static org.awaitility.Awaitility.await; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.not; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.*; public class ExpungeR4Test extends BaseResourceProviderR4Test { @@ -53,12 +52,12 @@ public class ExpungeR4Test extends BaseResourceProviderR4Test { @Autowired private ISearchResultDao mySearchResultDao; - @After + @AfterEach public void afterDisableExpunge() { myDaoConfig.setExpungeEnabled(new DaoConfig().isExpungeEnabled()); } - @Before + @BeforeEach public void beforeEnableExpunge() { myDaoConfig.setExpungeEnabled(true); } @@ -465,9 +464,5 @@ public class ExpungeR4Test extends BaseResourceProviderR4Test { } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/GraphQLProviderR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/GraphQLProviderR4Test.java index 879aa8da5e5..9b8bb600bdc 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/GraphQLProviderR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/GraphQLProviderR4Test.java @@ -7,7 +7,7 @@ import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; import org.hl7.fhir.instance.model.api.IIdType; import org.hl7.fhir.r4.model.Patient; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -16,7 +16,7 @@ import java.nio.charset.StandardCharsets; import static ca.uhn.fhir.jpa.provider.JpaGraphQLR4ProviderTest.DATA_PREFIX; import static ca.uhn.fhir.jpa.provider.JpaGraphQLR4ProviderTest.DATA_SUFFIX; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public class GraphQLProviderR4Test extends BaseResourceProviderR4Test { private Logger ourLog = LoggerFactory.getLogger(GraphQLProviderR4Test.class); @@ -80,13 +80,13 @@ public class GraphQLProviderR4Test extends BaseResourceProviderR4Test { p.addName() .addGiven("GivenOnly1") .addGiven("GivenOnly2"); - myPatientId0 = ourClient.create().resource(p).execute().getId().toUnqualifiedVersionless(); + myPatientId0 = myClient.create().resource(p).execute().getId().toUnqualifiedVersionless(); p = new Patient(); p.addName() .addGiven("GivenOnlyB1") .addGiven("GivenOnlyB2"); - ourClient.create().resource(p).execute(); + myClient.create().resource(p).execute(); } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/HookInterceptorR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/HookInterceptorR4Test.java index aa92a4d12de..040655c5158 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/HookInterceptorR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/HookInterceptorR4Test.java @@ -2,25 +2,24 @@ package ca.uhn.fhir.jpa.provider.r4; import ca.uhn.fhir.interceptor.api.Pointcut; import ca.uhn.fhir.rest.api.MethodOutcome; -import ca.uhn.fhir.util.TestUtil; 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.hl7.fhir.r4.model.Patient; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.concurrent.atomic.AtomicLong; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; public class HookInterceptorR4Test extends BaseResourceProviderR4Test { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(HookInterceptorR4Test.class); // @Override -// @After +// @AfterEach // public void after( ) throws Exception { // super.after(); // @@ -36,12 +35,12 @@ public class HookInterceptorR4Test extends BaseResourceProviderR4Test { Patient p = new Patient(); p.getNameFirstRep().setFamily("OLDFAMILY"); - MethodOutcome outcome = ourClient.create().resource(p).execute(); + MethodOutcome outcome = myClient.create().resource(p).execute(); // Response reflects change, stored resource also does Patient responsePatient = (Patient) outcome.getResource(); assertEquals("NEWFAMILY", responsePatient.getNameFirstRep().getFamily()); - responsePatient = ourClient.read().resource(Patient.class).withId(outcome.getId()).execute(); + responsePatient = myClient.read().resource(Patient.class).withId(outcome.getId()).execute(); assertEquals("NEWFAMILY", responsePatient.getNameFirstRep().getFamily()); } @@ -55,12 +54,12 @@ public class HookInterceptorR4Test extends BaseResourceProviderR4Test { Patient p = new Patient(); p.getNameFirstRep().setFamily("OLDFAMILY"); - MethodOutcome outcome = ourClient.create().resource(p).execute(); + MethodOutcome outcome = myClient.create().resource(p).execute(); // Response reflects change, stored resource does not Patient responsePatient = (Patient) outcome.getResource(); assertEquals("NEWFAMILY", responsePatient.getNameFirstRep().getFamily()); - responsePatient = ourClient.read().resource(Patient.class).withId(outcome.getId()).execute(); + responsePatient = myClient.read().resource(Patient.class).withId(outcome.getId()).execute(); assertEquals("OLDFAMILY", responsePatient.getNameFirstRep().getFamily()); } @@ -71,10 +70,10 @@ public class HookInterceptorR4Test extends BaseResourceProviderR4Test { myInterceptorRegistry.registerAnonymousInterceptor(Pointcut.STORAGE_PRECOMMIT_RESOURCE_CREATED, (thePointcut, t) -> { IAnyResource resource = (IAnyResource) t.get(IBaseResource.class, 0); Long resourcePid = (Long) resource.getUserData("RESOURCE_PID"); - assertNotNull("Expecting RESOURCE_PID to be set on resource user data.", resourcePid); + assertNotNull(resourcePid, "Expecting RESOURCE_PID to be set on resource user data."); pid.set(resourcePid); }); - ourClient.create().resource(new Patient()).execute(); + myClient.create().resource(new Patient()).execute(); assertTrue(pid.get() > 0); } @@ -86,19 +85,19 @@ public class HookInterceptorR4Test extends BaseResourceProviderR4Test { IAnyResource oldResource = (IAnyResource) t.get(IBaseResource.class, 0); Long oldResourcePid = (Long) oldResource.getUserData("RESOURCE_PID"); - assertNotNull("Expecting RESOURCE_PID to be set on resource user data.", oldResourcePid); + assertNotNull(oldResourcePid, "Expecting RESOURCE_PID to be set on resource user data."); oldPid.set(oldResourcePid); IAnyResource newResource = (IAnyResource) t.get(IBaseResource.class, 1); Long newResourcePid = (Long) newResource.getUserData("RESOURCE_PID"); - assertNotNull("Expecting RESOURCE_PID to be set on resource user data.", newResourcePid); + assertNotNull(newResourcePid, "Expecting RESOURCE_PID to be set on resource user data."); newPid.set(newResourcePid); }); Patient patient = new Patient(); - IIdType id = ourClient.create().resource(patient).execute().getId(); + IIdType id = myClient.create().resource(patient).execute().getId(); patient.setId(id); patient.getNameFirstRep().setFamily("SOMECHANGE"); - ourClient.update().resource(patient).execute(); + myClient.update().resource(patient).execute(); assertTrue(oldPid.get() > 0); assertTrue(newPid.get() > 0); } @@ -107,7 +106,7 @@ public class HookInterceptorR4Test extends BaseResourceProviderR4Test { public void testOP_PRESTORAGE_RESOURCE_UPDATED_ModifyResource() { Patient p = new Patient(); p.setActive(true); - IIdType id = ourClient.create().resource(p).execute().getId(); + IIdType id = myClient.create().resource(p).execute().getId(); myInterceptorRegistry.registerAnonymousInterceptor(Pointcut.STORAGE_PRESTORAGE_RESOURCE_UPDATED, (thePointcut, t) -> { Patient contents = (Patient) t.get(IBaseResource.class, 1); @@ -117,12 +116,12 @@ public class HookInterceptorR4Test extends BaseResourceProviderR4Test { p = new Patient(); p.setId(id); p.getNameFirstRep().setFamily("OLDFAMILY"); - MethodOutcome outcome = ourClient.update().resource(p).execute(); + MethodOutcome outcome = myClient.update().resource(p).execute(); // Response reflects change, stored resource also does Patient responsePatient = (Patient) outcome.getResource(); assertEquals("NEWFAMILY", responsePatient.getNameFirstRep().getFamily()); - responsePatient = ourClient.read().resource(Patient.class).withId(outcome.getId()).execute(); + responsePatient = myClient.read().resource(Patient.class).withId(outcome.getId()).execute(); assertEquals("NEWFAMILY", responsePatient.getNameFirstRep().getFamily()); } @@ -131,7 +130,7 @@ public class HookInterceptorR4Test extends BaseResourceProviderR4Test { public void testOP_PRECOMMIT_RESOURCE_UPDATED_ModifyResource() { Patient p = new Patient(); p.setActive(true); - IIdType id = ourClient.create().resource(p).execute().getId(); + IIdType id = myClient.create().resource(p).execute().getId(); myInterceptorRegistry.registerAnonymousInterceptor(Pointcut.STORAGE_PRECOMMIT_RESOURCE_UPDATED, (thePointcut, t) -> { Patient contents = (Patient) t.get(IBaseResource.class, 1); @@ -141,20 +140,16 @@ public class HookInterceptorR4Test extends BaseResourceProviderR4Test { p = new Patient(); p.setId(id); p.getNameFirstRep().setFamily("OLDFAMILY"); - MethodOutcome outcome = ourClient.update().resource(p).execute(); + MethodOutcome outcome = myClient.update().resource(p).execute(); // Response reflects change, stored resource does not Patient responsePatient = (Patient) outcome.getResource(); assertEquals("NEWFAMILY", responsePatient.getNameFirstRep().getFamily()); - responsePatient = ourClient.read().resource(Patient.class).withId(outcome.getId()).execute(); + responsePatient = myClient.read().resource(Patient.class).withId(outcome.getId()).execute(); assertEquals("OLDFAMILY", responsePatient.getNameFirstRep().getFamily()); } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/MultitenantServerR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/MultitenantServerR4Test.java index 95e16572998..21300f2adf2 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/MultitenantServerR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/MultitenantServerR4Test.java @@ -1,6 +1,5 @@ package ca.uhn.fhir.jpa.provider.r4; -import ca.uhn.fhir.jpa.util.TestUtil; import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException; import ca.uhn.fhir.test.utilities.ITestDataBuilder; import org.hl7.fhir.instance.model.api.IIdType; @@ -9,17 +8,15 @@ import org.hl7.fhir.r4.model.CapabilityStatement; import org.hl7.fhir.r4.model.IdType; import org.hl7.fhir.r4.model.Organization; import org.hl7.fhir.r4.model.Patient; -import org.junit.AfterClass; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.Date; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.in; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; @SuppressWarnings("Duplicates") public class MultitenantServerR4Test extends BaseMultitenantResourceProviderR4Test implements ITestDataBuilder { @@ -27,7 +24,7 @@ public class MultitenantServerR4Test extends BaseMultitenantResourceProviderR4Te @Test public void testFetchCapabilityStatement() { myTenantClientInterceptor.setTenantId(TENANT_A); - CapabilityStatement cs = ourClient.capabilities().ofType(CapabilityStatement.class).execute(); + CapabilityStatement cs = myClient.capabilities().ofType(CapabilityStatement.class).execute(); assertEquals("HAPI FHIR Server", cs.getSoftware().getName()); assertEquals(ourServerBase + "/TENANT-A/metadata", myCapturingInterceptor.getLastRequest().getUri()); @@ -44,12 +41,12 @@ public class MultitenantServerR4Test extends BaseMultitenantResourceProviderR4Te // Now read back myTenantClientInterceptor.setTenantId(TENANT_A); - Patient response = ourClient.read().resource(Patient.class).withId(idA).execute(); + Patient response = myClient.read().resource(Patient.class).withId(idA).execute(); assertTrue(response.getActive()); myTenantClientInterceptor.setTenantId(TENANT_B); try { - ourClient.read().resource(Patient.class).withId(idA).execute(); + myClient.read().resource(Patient.class).withId(idA).execute(); fail(); } catch (ResourceNotFoundException e) { // good @@ -63,7 +60,7 @@ public class MultitenantServerR4Test extends BaseMultitenantResourceProviderR4Te Patient patientA = new Patient(); patientA.setActive(true); try { - ourClient.create().resource(patientA).execute(); + myClient.create().resource(patientA).execute(); fail(); } catch (ResourceNotFoundException e) { assertThat(e.getMessage(), containsString("Partition name \"TENANT-ZZZ\" is not valid")); @@ -97,13 +94,8 @@ public class MultitenantServerR4Test extends BaseMultitenantResourceProviderR4Te .getRequest().setUrl("Patient").setMethod(Bundle.HTTPVerb.POST); myTenantClientInterceptor.setTenantId(TENANT_A); - Bundle response = ourClient.transaction().withBundle(input).execute(); + Bundle response = myClient.transaction().withBundle(input).execute(); } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } - } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/PatchProviderR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/PatchProviderR4Test.java index 43fca6b4a23..07edf0cbaa2 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/PatchProviderR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/PatchProviderR4Test.java @@ -9,10 +9,9 @@ import org.apache.http.client.methods.HttpPatch; import org.apache.http.client.methods.HttpPost; 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.hl7.fhir.r4.model.*; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -20,8 +19,8 @@ import java.io.IOException; import java.nio.charset.StandardCharsets; import static org.hamcrest.CoreMatchers.containsString; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.hamcrest.MatcherAssert.assertThat; public class PatchProviderR4Test extends BaseResourceProviderR4Test { @@ -34,7 +33,7 @@ public class PatchProviderR4Test extends BaseResourceProviderR4Test { patient.setActive(true); patient.addIdentifier().addExtension("http://foo", new StringType("abc")); patient.addIdentifier().setSystem("sys").setValue("val"); - IIdType id = ourClient.create().resource(patient).execute().getId().toUnqualifiedVersionless(); + IIdType id = myClient.create().resource(patient).execute().getId().toUnqualifiedVersionless(); Parameters patch = new Parameters(); Parameters.ParametersParameterComponent operation = patch.addParameter(); @@ -48,7 +47,7 @@ public class PatchProviderR4Test extends BaseResourceProviderR4Test { .setName("path") .setValue(new StringType("Patient.identifier[0]")); - MethodOutcome outcome = ourClient + MethodOutcome outcome = myClient .patch() .withFhirPatch(patch) .withId(id) @@ -57,7 +56,7 @@ public class PatchProviderR4Test extends BaseResourceProviderR4Test { Patient resultingResource = (Patient) outcome.getResource(); assertEquals(1, resultingResource.getIdentifier().size()); - resultingResource = ourClient.read().resource(Patient.class).withId(id).execute(); + resultingResource = myClient.read().resource(Patient.class).withId(id).execute(); assertEquals(1, resultingResource.getIdentifier().size()); } @@ -97,7 +96,7 @@ public class PatchProviderR4Test extends BaseResourceProviderR4Test { assertThat(responseString, containsString("\"resourceType\":\"Bundle\"")); } - Patient newPt = ourClient.read().resource(Patient.class).withId(pid1.getIdPart()).execute(); + Patient newPt = myClient.read().resource(Patient.class).withId(pid1.getIdPart()).execute(); assertEquals("2", newPt.getIdElement().getVersionIdPart()); assertEquals(false, newPt.getActive()); } @@ -165,7 +164,7 @@ public class PatchProviderR4Test extends BaseResourceProviderR4Test { assertThat(responseString, containsString("INFORMATION")); } - Patient newPt = ourClient.read().resource(Patient.class).withId(pid1.getIdPart()).execute(); + Patient newPt = myClient.read().resource(Patient.class).withId(pid1.getIdPart()).execute(); assertEquals("2", newPt.getIdElement().getVersionIdPart()); assertEquals(false, newPt.getActive()); } @@ -206,7 +205,7 @@ public class PatchProviderR4Test extends BaseResourceProviderR4Test { assertThat(responseString, containsString("\"resourceType\":\"Bundle\"")); } - Patient newPt = ourClient.read().resource(Patient.class).withId(pid1.getIdPart()).execute(); + Patient newPt = myClient.read().resource(Patient.class).withId(pid1.getIdPart()).execute(); assertEquals("2", newPt.getIdElement().getVersionIdPart()); assertEquals(false, newPt.getActive()); } @@ -235,7 +234,7 @@ public class PatchProviderR4Test extends BaseResourceProviderR4Test { assertThat(responseString, containsString("INFORMATION")); } - Patient newPt = ourClient.read().resource(Patient.class).withId(pid1.getIdPart()).execute(); + Patient newPt = myClient.read().resource(Patient.class).withId(pid1.getIdPart()).execute(); assertEquals("2", newPt.getIdElement().getVersionIdPart()); assertEquals(false, newPt.getActive()); } @@ -263,7 +262,7 @@ public class PatchProviderR4Test extends BaseResourceProviderR4Test { assertThat(responseString, containsString("Invalid match URL "Patient?_id=" + pid1.getIdPart() + "FOO" - No resources match this search")); } - Patient newPt = ourClient.read().resource(Patient.class).withId(pid1.getIdPart()).execute(); + Patient newPt = myClient.read().resource(Patient.class).withId(pid1.getIdPart()).execute(); assertEquals("1", newPt.getIdElement().getVersionIdPart()); } @@ -358,7 +357,7 @@ public class PatchProviderR4Test extends BaseResourceProviderR4Test { assertThat(responseString, containsString("")); } - Patient newPt = ourClient.read().resource(Patient.class).withId(pid1.getIdPart()).execute(); + Patient newPt = myClient.read().resource(Patient.class).withId(pid1.getIdPart()).execute(); assertEquals("1", newPt.getIdElement().getVersionIdPart()); assertEquals(true, newPt.getActive()); } @@ -387,7 +386,7 @@ public class PatchProviderR4Test extends BaseResourceProviderR4Test { assertThat(responseString, containsString("INFORMATION")); } - Patient newPt = ourClient.read().resource(Patient.class).withId(pid1.getIdPart()).execute(); + Patient newPt = myClient.read().resource(Patient.class).withId(pid1.getIdPart()).execute(); assertEquals("2", newPt.getIdElement().getVersionIdPart()); assertEquals(false, newPt.getActive()); } @@ -416,7 +415,7 @@ public class PatchProviderR4Test extends BaseResourceProviderR4Test { assertThat(responseString, containsString("INFORMATION")); } - Patient newPt = ourClient.read().resource(Patient.class).withId(pid1.getIdPart()).execute(); + Patient newPt = myClient.read().resource(Patient.class).withId(pid1.getIdPart()).execute(); assertEquals("2", newPt.getIdElement().getVersionIdPart()); assertEquals(false, newPt.getActive()); } @@ -458,7 +457,7 @@ public class PatchProviderR4Test extends BaseResourceProviderR4Test { assertThat(responseString, containsString("\"resourceType\":\"Bundle\"")); } - Patient newPt = ourClient.read().resource(Patient.class).withId(pid1.getIdPart()).execute(); + Patient newPt = myClient.read().resource(Patient.class).withId(pid1.getIdPart()).execute(); assertEquals("2", newPt.getIdElement().getVersionIdPart()); assertEquals(false, newPt.getActive()); } @@ -497,7 +496,7 @@ public class PatchProviderR4Test extends BaseResourceProviderR4Test { assertThat(responseString, containsString("Missing or invalid content type for PATCH operation")); } - Patient newPt = ourClient.read().resource(Patient.class).withId(pid1.getIdPart()).execute(); + Patient newPt = myClient.read().resource(Patient.class).withId(pid1.getIdPart()).execute(); assertEquals("1", newPt.getIdElement().getVersionIdPart()); assertEquals(true, newPt.getActive()); } @@ -535,7 +534,7 @@ public class PatchProviderR4Test extends BaseResourceProviderR4Test { assertThat(responseString, containsString("Unable to determine PATCH body from request")); } - Patient newPt = ourClient.read().resource(Patient.class).withId(pid1.getIdPart()).execute(); + Patient newPt = myClient.read().resource(Patient.class).withId(pid1.getIdPart()).execute(); assertEquals("1", newPt.getIdElement().getVersionIdPart()); assertEquals(true, newPt.getActive()); } @@ -574,7 +573,7 @@ public class PatchProviderR4Test extends BaseResourceProviderR4Test { assertThat(responseString, containsString("Invalid Content-Type for PATCH operation: application/octet-stream")); } - Patient newPt = ourClient.read().resource(Patient.class).withId(pid1.getIdPart()).execute(); + Patient newPt = myClient.read().resource(Patient.class).withId(pid1.getIdPart()).execute(); assertEquals("1", newPt.getIdElement().getVersionIdPart()); assertEquals(true, newPt.getActive()); } @@ -612,7 +611,7 @@ public class PatchProviderR4Test extends BaseResourceProviderR4Test { assertThat(responseString, containsString("Binary PATCH detected with FHIR content type. FHIR Patch should use Parameters resource.")); } - Patient newPt = ourClient.read().resource(Patient.class).withId(pid1.getIdPart()).execute(); + Patient newPt = myClient.read().resource(Patient.class).withId(pid1.getIdPart()).execute(); assertEquals("1", newPt.getIdElement().getVersionIdPart()); assertEquals(true, newPt.getActive()); } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/PatientEverythingR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/PatientEverythingR4Test.java index 0d8d9c6ac3b..66534174903 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/PatientEverythingR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/PatientEverythingR4Test.java @@ -1,9 +1,15 @@ package ca.uhn.fhir.jpa.provider.r4; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.*; +import static org.junit.jupiter.api.Assertions.*; + +import java.io.IOException; +import java.util.*; + import ca.uhn.fhir.jpa.api.config.DaoConfig; import ca.uhn.fhir.parser.StrictErrorHandler; import ca.uhn.fhir.rest.api.EncodingEnum; -import ca.uhn.fhir.util.TestUtil; import com.google.common.base.Charsets; import org.apache.commons.io.IOUtils; import org.apache.http.client.ClientProtocolException; @@ -17,24 +23,9 @@ import org.hl7.fhir.r4.model.Observation; import org.hl7.fhir.r4.model.Observation.ObservationStatus; import org.hl7.fhir.r4.model.Organization; import org.hl7.fhir.r4.model.Patient; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.*; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Set; -import java.util.TreeSet; - -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.hasItem; -import static org.hamcrest.Matchers.hasItems; -import static org.hamcrest.Matchers.not; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThat; +import org.junit.jupiter.api.BeforeEach; @SuppressWarnings("Duplicates") public class PatientEverythingR4Test extends BaseResourceProviderR4Test { @@ -48,13 +39,13 @@ public class PatientEverythingR4Test extends BaseResourceProviderR4Test { private String myWrongPatId; private String myWrongEnc1; - @Before + @BeforeEach public void beforeDisableResultReuse() { myDaoConfig.setReuseCachedSearchResultsForMillis(null); } @Override - @After + @AfterEach public void after() throws Exception { super.after(); @@ -64,6 +55,7 @@ public class PatientEverythingR4Test extends BaseResourceProviderR4Test { } @Override + @BeforeEach public void before() throws Exception { super.before(); myFhirCtx.setParserErrorHandler(new StrictErrorHandler()); @@ -72,41 +64,41 @@ public class PatientEverythingR4Test extends BaseResourceProviderR4Test { Organization org = new Organization(); org.setName("an org"); - orgId = ourClient.create().resource(org).execute().getId().toUnqualifiedVersionless().getValue(); + orgId = myClient.create().resource(org).execute().getId().toUnqualifiedVersionless().getValue(); ourLog.info("OrgId: {}", orgId); Patient patient = new Patient(); patient.getManagingOrganization().setReference(orgId); - patId = ourClient.create().resource(patient).execute().getId().toUnqualifiedVersionless().getValue(); + patId = myClient.create().resource(patient).execute().getId().toUnqualifiedVersionless().getValue(); Patient patient2 = new Patient(); patient2.getManagingOrganization().setReference(orgId); - myWrongPatId = ourClient.create().resource(patient2).execute().getId().toUnqualifiedVersionless().getValue(); + myWrongPatId = myClient.create().resource(patient2).execute().getId().toUnqualifiedVersionless().getValue(); Encounter enc1 = new Encounter(); enc1.setStatus(EncounterStatus.CANCELLED); enc1.getSubject().setReference(patId); enc1.getServiceProvider().setReference(orgId); - encId1 = ourClient.create().resource(enc1).execute().getId().toUnqualifiedVersionless().getValue(); + encId1 = myClient.create().resource(enc1).execute().getId().toUnqualifiedVersionless().getValue(); Encounter enc2 = new Encounter(); enc2.setStatus(EncounterStatus.ARRIVED); enc2.getSubject().setReference(patId); enc2.getServiceProvider().setReference(orgId); - encId2 = ourClient.create().resource(enc2).execute().getId().toUnqualifiedVersionless().getValue(); + encId2 = myClient.create().resource(enc2).execute().getId().toUnqualifiedVersionless().getValue(); Encounter wrongEnc1 = new Encounter(); wrongEnc1.setStatus(EncounterStatus.ARRIVED); wrongEnc1.getSubject().setReference(myWrongPatId); wrongEnc1.getServiceProvider().setReference(orgId); - myWrongEnc1 = ourClient.create().resource(wrongEnc1).execute().getId().toUnqualifiedVersionless().getValue(); + myWrongEnc1 = myClient.create().resource(wrongEnc1).execute().getId().toUnqualifiedVersionless().getValue(); - myObsIds = new ArrayList(); + myObsIds = new ArrayList<>(); for (int i = 0; i < 20; i++) { Observation obs = new Observation(); obs.getSubject().setReference(patId); obs.setStatus(ObservationStatus.FINAL); - String obsId = ourClient.create().resource(obs).execute().getId().toUnqualifiedVersionless().getValue(); + String obsId = myClient.create().resource(obs).execute().getId().toUnqualifiedVersionless().getValue(); myObsIds.add(obsId); } @@ -215,9 +207,4 @@ public class PatientEverythingR4Test extends BaseResourceProviderR4Test { return bundle; } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } - } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderCustomSearchParamR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderCustomSearchParamR4Test.java index 4d7b3b6514d..7f77dc3c151 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderCustomSearchParamR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderCustomSearchParamR4Test.java @@ -17,7 +17,6 @@ import ca.uhn.fhir.rest.gclient.ReferenceClientParam; import ca.uhn.fhir.rest.gclient.TokenClientParam; import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; import ca.uhn.fhir.util.BundleUtil; -import ca.uhn.fhir.util.TestUtil; import org.apache.commons.io.IOUtils; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; @@ -38,10 +37,9 @@ import org.hl7.fhir.r4.model.Practitioner; import org.hl7.fhir.r4.model.Reference; import org.hl7.fhir.r4.model.SearchParameter; import org.hl7.fhir.r4.model.SearchParameter.XPathUsageType; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.transaction.TransactionStatus; import org.springframework.transaction.support.TransactionCallbackWithoutResult; import org.springframework.transaction.support.TransactionTemplate; @@ -52,13 +50,13 @@ import java.util.List; import java.util.Map; import java.util.stream.Collectors; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.containsString; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.fail; public class ResourceProviderCustomSearchParamR4Test extends BaseResourceProviderR4Test { @@ -66,13 +64,14 @@ public class ResourceProviderCustomSearchParamR4Test extends BaseResourceProvide @Override - @After + @AfterEach public void after() throws Exception { super.after(); myModelConfig.setDefaultSearchParamsCanBeOverridden(new ModelConfig().isDefaultSearchParamsCanBeOverridden()); myDaoConfig.setAllowContainsSearches(new DaoConfig().isAllowContainsSearches()); } + @BeforeEach @Override public void before() throws Exception { super.before(); @@ -80,7 +79,7 @@ public class ResourceProviderCustomSearchParamR4Test extends BaseResourceProvide } @Override - @Before + @BeforeEach public void beforeResetConfig() { super.beforeResetConfig(); @@ -112,7 +111,7 @@ public class ResourceProviderCustomSearchParamR4Test extends BaseResourceProvide sp.setTitle("Foo Param"); try { - ourClient.create().resource(sp).execute(); + myClient.create().resource(sp).execute(); fail(); } catch (UnprocessableEntityException e) { assertEquals("HTTP 422 Unprocessable Entity: SearchParameter.status is missing or invalid", e.getMessage()); @@ -123,7 +122,7 @@ public class ResourceProviderCustomSearchParamR4Test extends BaseResourceProvide public void testConformanceOverrideAllowed() { myModelConfig.setDefaultSearchParamsCanBeOverridden(true); - CapabilityStatement conformance = ourClient + CapabilityStatement conformance = myClient .fetchConformance() .ofType(CapabilityStatement.class) .execute(); @@ -175,7 +174,7 @@ public class ResourceProviderCustomSearchParamR4Test extends BaseResourceProvide } }); - conformance = ourClient + conformance = myClient .fetchConformance() .ofType(CapabilityStatement.class) .execute(); @@ -281,7 +280,7 @@ public class ResourceProviderCustomSearchParamR4Test extends BaseResourceProvide ourLog.info(myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(eyeColourSp)); - ourClient + myClient .create() .resource(eyeColourSp) .execute(); @@ -300,7 +299,7 @@ public class ResourceProviderCustomSearchParamR4Test extends BaseResourceProvide p2.addExtension().setUrl("http://acme.org/eyecolour").setValue(new CodeType("green")); IIdType p2id = myPatientDao.create(p2).getId().toUnqualifiedVersionless(); - Bundle bundle = ourClient + Bundle bundle = myClient .search() .forResource(Patient.class) .where(new TokenClientParam("eyecolour").exactly().code("blue")) @@ -347,7 +346,7 @@ public class ResourceProviderCustomSearchParamR4Test extends BaseResourceProvide List foundResources; Bundle result; - result = ourClient + result = myClient .search() .forResource(Observation.class) .where(new ReferenceClientParam("foo").hasChainedProperty(Patient.GENDER.exactly().code("male"))) @@ -387,7 +386,7 @@ public class ResourceProviderCustomSearchParamR4Test extends BaseResourceProvide List foundResources; Bundle result; - result = ourClient + result = myClient .search() .forResource(Patient.class) .where(new TokenClientParam("foo").exactly().code("male")) @@ -443,13 +442,13 @@ public class ResourceProviderCustomSearchParamR4Test extends BaseResourceProvide do { if (bundle == null) { - bundle = ourClient + bundle = myClient .search() .byUrl(ourServerBase + "/Patient?identifier=FOO") .returnBundle(Bundle.class) .execute(); } else { - bundle = ourClient + bundle = myClient .loadPage() .next(bundle) .execute(); @@ -463,15 +462,15 @@ public class ResourceProviderCustomSearchParamR4Test extends BaseResourceProvide String queries = " * " + myCaptureQueriesListener .getSelectQueries() .stream() - .map(t->t.getSql(true, false)) + .map(t -> t.getSql(true, false)) .collect(Collectors.joining("\n * ")); ourLog.info("Found: {}", found); runInTransaction(() -> { - List currentResults = myEntityManager.createNativeQuery("select distinct resourceta0_.RES_ID as col_0_0_ from HFJ_RESOURCE resourceta0_ left outer join HFJ_SPIDX_STRING myparamsst1_ on resourceta0_.RES_ID=myparamsst1_.RES_ID where myparamsst1_.HASH_NORM_PREFIX='5901791607832193956' and (myparamsst1_.SP_VALUE_NORMALIZED like 'SECTION%') limit '500'") .getResultList(); - List currentResources = myEntityManager.createNativeQuery("select resourceta0_.RES_ID as col_0_0_ from HFJ_RESOURCE resourceta0_") .getResultList(); + List currentResults = myEntityManager.createNativeQuery("select distinct resourceta0_.RES_ID as col_0_0_ from HFJ_RESOURCE resourceta0_ left outer join HFJ_SPIDX_STRING myparamsst1_ on resourceta0_.RES_ID=myparamsst1_.RES_ID where myparamsst1_.HASH_NORM_PREFIX='5901791607832193956' and (myparamsst1_.SP_VALUE_NORMALIZED like 'SECTION%') limit '500'").getResultList(); + List currentResources = myEntityManager.createNativeQuery("select resourceta0_.RES_ID as col_0_0_ from HFJ_RESOURCE resourceta0_").getResultList(); List searches = mySearchEntityDao.findAll(); assertEquals(1, searches.size()); @@ -484,21 +483,21 @@ public class ResourceProviderCustomSearchParamR4Test extends BaseResourceProvide search.toString() + "\nQueries :\n" + queries; - for (Long next :ids) { + for (Long next : ids) { if (!actualIds.contains(next)) { List indexes = myResourceIndexedSearchParamStringDao .findAll() .stream() - .filter(t->t.getResourcePid().equals(next)) + .filter(t -> t.getResourcePid().equals(next)) .collect(Collectors.toList()); - message += "\n\nResource " + next + " has prefixes:\n * " + indexes.stream().map(t->t.toString()).collect(Collectors.joining("\n * ")); + message += "\n\nResource " + next + " has prefixes:\n * " + indexes.stream().map(t -> t.toString()).collect(Collectors.joining("\n * ")); break; } } - assertEquals(message, 200, search.getNumFound()); - assertEquals(message, 200, search.getTotalCount().intValue()); - assertEquals(message, SearchStatusEnum.FINISHED, search.getStatus()); + assertEquals(200, search.getNumFound(), message); + assertEquals(200, search.getTotalCount().intValue(), message); + assertEquals(SearchStatusEnum.FINISHED, search.getStatus(), message); }); assertEquals(200, foundCount); @@ -508,9 +507,5 @@ public class ResourceProviderCustomSearchParamR4Test extends BaseResourceProvide } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderExpungeR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderExpungeR4Test.java index a46005774b9..ab98df6b216 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderExpungeR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderExpungeR4Test.java @@ -6,20 +6,18 @@ import ca.uhn.fhir.jpa.model.util.JpaConstants; import ca.uhn.fhir.rest.server.exceptions.MethodNotAllowedException; import ca.uhn.fhir.rest.server.exceptions.ResourceGoneException; import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException; -import ca.uhn.fhir.util.TestUtil; import org.hl7.fhir.instance.model.api.IIdType; import org.hl7.fhir.r4.model.BooleanType; import org.hl7.fhir.r4.model.IntegerType; import org.hl7.fhir.r4.model.Observation; import org.hl7.fhir.r4.model.Parameters; import org.hl7.fhir.r4.model.Patient; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; public class ResourceProviderExpungeR4Test extends BaseResourceProviderR4Test { @@ -31,7 +29,7 @@ public class ResourceProviderExpungeR4Test extends BaseResourceProviderR4Test { private IIdType myTwoVersionObservationId; private IIdType myDeletedObservationId; - @After + @AfterEach public void afterDisableExpunge() { myDaoConfig.setExpungeEnabled(new DaoConfig().isExpungeEnabled()); } @@ -59,7 +57,7 @@ public class ResourceProviderExpungeR4Test extends BaseResourceProviderR4Test { } @Override - @Before + @BeforeEach public void before() throws Exception { super.before(); @@ -108,7 +106,7 @@ public class ResourceProviderExpungeR4Test extends BaseResourceProviderR4Test { } - @Before + @BeforeEach public void beforeEnableExpunge() { myDaoConfig.setExpungeEnabled(true); } @@ -144,7 +142,7 @@ public class ResourceProviderExpungeR4Test extends BaseResourceProviderR4Test { ourLog.info(myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(input)); - Parameters output = ourClient + Parameters output = myClient .operation() .onInstance(myTwoVersionPatientId) .named("expunge") @@ -184,7 +182,7 @@ public class ResourceProviderExpungeR4Test extends BaseResourceProviderR4Test { .setValue(new BooleanType(true)); try { - ourClient + myClient .operation() .onInstance(myTwoVersionPatientId) .named("expunge") @@ -217,7 +215,7 @@ public class ResourceProviderExpungeR4Test extends BaseResourceProviderR4Test { ourLog.info(myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(input)); - Parameters output = ourClient + Parameters output = myClient .operation() .onServer() .named("expunge") @@ -256,7 +254,7 @@ public class ResourceProviderExpungeR4Test extends BaseResourceProviderR4Test { ourLog.info(myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(input)); - Parameters output = ourClient + Parameters output = myClient .operation() .onType(Patient.class) .named("expunge") @@ -302,7 +300,7 @@ public class ResourceProviderExpungeR4Test extends BaseResourceProviderR4Test { ourLog.info(myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(input)); - Parameters output = ourClient + Parameters output = myClient .operation() .onInstanceVersion(myTwoVersionPatientId.withVersion("1")) .named("expunge") @@ -326,9 +324,5 @@ public class ResourceProviderExpungeR4Test extends BaseResourceProviderR4Test { } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderInterceptorR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderInterceptorR4Test.java index 38de65c7327..f67badfd4b2 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderInterceptorR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderInterceptorR4Test.java @@ -17,7 +17,6 @@ import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor; import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor.ActionRequestDetails; import ca.uhn.fhir.rest.server.interceptor.ServerOperationInterceptorAdapter; import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; -import ca.uhn.fhir.util.TestUtil; import com.google.common.collect.Lists; import org.apache.commons.io.IOUtils; import org.apache.http.client.methods.CloseableHttpResponse; @@ -34,9 +33,8 @@ import org.hl7.fhir.r4.model.Observation; import org.hl7.fhir.r4.model.Organization; import org.hl7.fhir.r4.model.Patient; import org.hl7.fhir.r4.model.Reference; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.Mock; @@ -44,24 +42,16 @@ import org.mockito.Mock; import javax.servlet.ServletException; import java.io.IOException; import java.nio.charset.StandardCharsets; -import java.time.Duration; import java.util.ArrayList; import java.util.List; import static org.apache.commons.lang3.time.DateUtils.MILLIS_PER_SECOND; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.startsWith; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThat; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.atLeast; -import static org.mockito.Mockito.eq; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.reset; -import static org.mockito.Mockito.timeout; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.*; public class ResourceProviderInterceptorR4Test extends BaseResourceProviderR4Test { @@ -73,7 +63,7 @@ public class ResourceProviderInterceptorR4Test extends BaseResourceProviderR4Tes private ArgumentCaptor myParamsCaptor; @Override - @After + @AfterEach public void after() throws Exception { super.after(); @@ -103,7 +93,7 @@ public class ResourceProviderInterceptorR4Test extends BaseResourceProviderR4Tes ourLog.info("About to perform search..."); - Bundle results = ourClient.search().forResource(Patient.class).returnBundle(Bundle.class).execute(); + Bundle results = myClient.search().forResource(Patient.class).returnBundle(Bundle.class).execute(); verify(interceptor, times(1)).invoke(eq(Pointcut.JPA_PERFTRACE_SEARCH_FIRST_RESULT_LOADED), myParamsCaptor.capture()); verify(interceptor, times(1)).invoke(eq(Pointcut.JPA_PERFTRACE_SEARCH_SELECT_COMPLETE), myParamsCaptor.capture()); @@ -116,7 +106,7 @@ public class ResourceProviderInterceptorR4Test extends BaseResourceProviderR4Tes // Load the next (and final) page reset(interceptor); - results = ourClient.loadPage().next(results).execute(); + results = myClient.loadPage().next(results).execute(); assertNotNull(results); verify(interceptor, times(1)).invoke(eq(Pointcut.JPA_PERFTRACE_SEARCH_FIRST_RESULT_LOADED), myParamsCaptor.capture()); verify(interceptor, times(1)).invoke(eq(Pointcut.JPA_PERFTRACE_SEARCH_SELECT_COMPLETE), myParamsCaptor.capture()); @@ -233,9 +223,9 @@ public class ResourceProviderInterceptorR4Test extends BaseResourceProviderR4Tes Patient p = new Patient(); p.setActive(true); - IIdType pid = ourClient.create().resource(p).execute().getId().toUnqualifiedVersionless(); + IIdType pid = myClient.create().resource(p).execute().getId().toUnqualifiedVersionless(); - Bundle observations = ourClient + Bundle observations = myClient .search() .forResource("Observation") .where(Observation.SUBJECT.hasId(pid)) @@ -256,7 +246,7 @@ public class ResourceProviderInterceptorR4Test extends BaseResourceProviderR4Tes Organization org = new Organization(); org.setName("orgName"); - IIdType orgId = ourClient.create().resource(org).execute().getId().toUnqualified(); + IIdType orgId = myClient.create().resource(org).execute().getId().toUnqualified(); assertNotNull(orgId.getVersionIdPartAsLong()); Patient pt = new Patient(); @@ -352,7 +342,7 @@ public class ResourceProviderInterceptorR4Test extends BaseResourceProviderR4Tes Observation observation = new Observation(); observation.setSubject(new Reference(createdPatient.getId())); - ourClient.create().resource(observation).execute(); + myClient.create().resource(observation).execute(); } } } @@ -415,7 +405,7 @@ public class ResourceProviderInterceptorR4Test extends BaseResourceProviderR4Tes try { ourRestServer.registerInterceptor(interceptor); - Bundle bundle = ourClient + Bundle bundle = myClient .search() .forResource(Observation.class) .where(Observation.SUBJECT.hasId("Patient/p1")) @@ -432,11 +422,6 @@ public class ResourceProviderInterceptorR4Test extends BaseResourceProviderR4Tes } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } - public static void verifyDaoInterceptor(IServerInterceptor theDaoInterceptor) { ArgumentCaptor ardCaptor; ArgumentCaptor opTypeCaptor; diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderOnlySomeResourcesProvidedR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderOnlySomeResourcesProvidedR4Test.java index ea4e4c52bea..1d2891dcb54 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderOnlySomeResourcesProvidedR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderOnlySomeResourcesProvidedR4Test.java @@ -1,12 +1,10 @@ package ca.uhn.fhir.jpa.provider.r4; import ca.uhn.fhir.jpa.api.dao.DaoRegistry; -import ca.uhn.fhir.jpa.util.TestUtil; import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException; import org.hl7.fhir.r4.model.Patient; import org.hl7.fhir.r4.model.Practitioner; -import org.junit.AfterClass; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.test.annotation.DirtiesContext; @@ -16,7 +14,7 @@ import javax.annotation.PostConstruct; import javax.annotation.PreDestroy; import static org.hamcrest.CoreMatchers.containsString; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; @SuppressWarnings("Duplicates") @ContextConfiguration(classes = {ResourceProviderOnlySomeResourcesProvidedR4Test.OnlySomeResourcesProvidedCtxConfig.class}) @@ -27,12 +25,12 @@ public class ResourceProviderOnlySomeResourcesProvidedR4Test extends BaseResourc public void testCreateUnsupportedType() { Patient pt1 = new Patient(); pt1.addName().setFamily("Elizabeth"); - ourClient.create().resource(pt1).execute(); + myClient.create().resource(pt1).execute(); Practitioner pract = new Practitioner(); pract.setActive(true); try { - ourClient.create().resource(pract).execute(); + myClient.create().resource(pract).execute(); } catch (ResourceNotFoundException e) { assertThat(e.getMessage(), containsString("Unknown resource type 'Practitioner' - Server knows how to handle:")); } @@ -72,9 +70,4 @@ public class ResourceProviderOnlySomeResourcesProvidedR4Test extends BaseResourc } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } - } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderQuestionnaireResponseR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderQuestionnaireResponseR4Test.java index c85b962680d..9641ca22752 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderQuestionnaireResponseR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderQuestionnaireResponseR4Test.java @@ -2,7 +2,7 @@ package ca.uhn.fhir.jpa.provider.r4; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.startsWith; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.nio.charset.StandardCharsets; import java.util.Collection; @@ -15,11 +15,10 @@ import org.hl7.fhir.r4.model.*; import org.hl7.fhir.r4.model.Questionnaire.QuestionnaireItemType; import org.hl7.fhir.r4.model.QuestionnaireResponse.QuestionnaireResponseStatus; import org.hl7.fhir.instance.model.api.IIdType; -import org.junit.*; +import org.junit.jupiter.api.*; import static org.hamcrest.MatcherAssert.assertThat; import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; import ca.uhn.fhir.rest.server.interceptor.RequestValidatingInterceptor; -import ca.uhn.fhir.util.TestUtil; import ca.uhn.fhir.validation.IValidatorModule; import ca.uhn.fhir.validation.ResultSeverityEnum; @@ -28,16 +27,15 @@ public class ResourceProviderQuestionnaireResponseR4Test extends BaseResourcePro private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ResourceProviderQuestionnaireResponseR4Test.class); private static RequestValidatingInterceptor ourValidatingInterceptor; - @AfterClass + @AfterAll public static void afterClassClearContext() { ourRestServer.unregisterInterceptor(ourValidatingInterceptor); ourValidatingInterceptor = null; - TestUtil.clearAllStaticFieldsForUnitTest(); } @Override - @Before + @BeforeEach public void before() throws Exception { super.before(); @@ -72,7 +70,7 @@ public class ResourceProviderQuestionnaireResponseR4Test extends BaseResourcePro qr1.setStatus(QuestionnaireResponseStatus.COMPLETED); qr1.addItem().setLinkId("link1").addAnswer().setValue(new DecimalType(123)); try { - ourClient.create().resource(qr1).execute(); + myClient.create().resource(qr1).execute(); fail(); } catch (UnprocessableEntityException e) { assertThat(myFhirCtx.newJsonParser().encodeResourceToString(e.getOperationOutcome()), containsString("Answer value must be of type string")); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4BundleTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4BundleTest.java index 2bbbba76c04..6c349b33e97 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4BundleTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4BundleTest.java @@ -2,18 +2,16 @@ package ca.uhn.fhir.jpa.provider.r4; import ca.uhn.fhir.jpa.model.util.JpaConstants; import ca.uhn.fhir.rest.server.exceptions.NotImplementedOperationException; -import ca.uhn.fhir.util.TestUtil; import org.hl7.fhir.instance.model.api.IIdType; import org.hl7.fhir.r4.model.Bundle; import org.hl7.fhir.r4.model.Bundle.BundleType; -import org.hl7.fhir.r4.model.Composition; import org.hl7.fhir.r4.model.Parameters; import org.hl7.fhir.r4.model.Patient; -import org.junit.AfterClass; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.hamcrest.CoreMatchers.containsString; -import static org.junit.Assert.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.*; public class ResourceProviderR4BundleTest extends BaseResourceProviderR4Test { @@ -32,9 +30,9 @@ public class ResourceProviderR4BundleTest extends BaseResourceProviderR4Test { composition.setActive(true); bundle.addEntry().setFullUrl("http://foo/").setResource(composition); - IIdType id = ourClient.create().resource(bundle).execute().getId(); + IIdType id = myClient.create().resource(bundle).execute().getId(); - Bundle retBundle = ourClient.read().resource(Bundle.class).withId(id).execute(); + Bundle retBundle = myClient.read().resource(Bundle.class).withId(id).execute(); ourLog.info(myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(retBundle)); @@ -52,7 +50,7 @@ public class ResourceProviderR4BundleTest extends BaseResourceProviderR4Test { .setName("content") .setResource(bundle); try { - ourClient.operation().onServer().named(JpaConstants.OPERATION_PROCESS_MESSAGE).withParameters(parameters).execute(); + myClient.operation().onServer().named(JpaConstants.OPERATION_PROCESS_MESSAGE).withParameters(parameters).execute(); fail(); } catch (NotImplementedOperationException e) { assertThat(e.getMessage(), containsString("This operation is not yet implemented on this server")); @@ -60,10 +58,5 @@ public class ResourceProviderR4BundleTest extends BaseResourceProviderR4Test { } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } - } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4CacheTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4CacheTest.java index 85cd89e30f7..834d93ba816 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4CacheTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4CacheTest.java @@ -11,9 +11,9 @@ import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import org.hl7.fhir.r4.model.Bundle; import org.hl7.fhir.r4.model.IdType; import org.hl7.fhir.r4.model.Patient; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -25,9 +25,9 @@ import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.greaterThan; import static org.hamcrest.Matchers.lessThan; import static org.hamcrest.core.IsNot.not; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.fail; public class ResourceProviderR4CacheTest extends BaseResourceProviderR4Test { @@ -37,22 +37,23 @@ public class ResourceProviderR4CacheTest extends BaseResourceProviderR4Test { private ISearchDao mySearchEntityDao; @Override - @After + @AfterEach public void after() throws Exception { super.after(); myDaoConfig.setReuseCachedSearchResultsForMillis(new DaoConfig().getReuseCachedSearchResultsForMillis()); myDaoConfig.setCacheControlNoStoreMaxResultsUpperLimit(new DaoConfig().getCacheControlNoStoreMaxResultsUpperLimit()); - ourClient.unregisterInterceptor(myCapturingInterceptor); + myClient.unregisterInterceptor(myCapturingInterceptor); } + @BeforeEach @Override public void before() throws Exception { super.before(); myFhirCtx.setParserErrorHandler(new StrictErrorHandler()); myCapturingInterceptor = new CapturingInterceptor(); - ourClient.registerInterceptor(myCapturingInterceptor); + myClient.registerInterceptor(myCapturingInterceptor); } @Test @@ -60,9 +61,9 @@ public class ResourceProviderR4CacheTest extends BaseResourceProviderR4Test { Patient pt1 = new Patient(); pt1.addName().setFamily("FAM"); - ourClient.create().resource(pt1).execute(); + myClient.create().resource(pt1).execute(); - Bundle results = ourClient + Bundle results = myClient .search() .forResource("Patient") .where(Patient.FAMILY.matches().value("FAM")) @@ -75,9 +76,9 @@ public class ResourceProviderR4CacheTest extends BaseResourceProviderR4Test { Patient pt2 = new Patient(); pt2.addName().setFamily("FAM"); - ourClient.create().resource(pt2).execute(); + myClient.create().resource(pt2).execute(); - results = ourClient + results = myClient .search() .forResource("Patient") .where(Patient.FAMILY.matches().value("FAM")) @@ -96,10 +97,10 @@ public class ResourceProviderR4CacheTest extends BaseResourceProviderR4Test { for (int i = 0; i < 10; i++) { Patient pt1 = new Patient(); pt1.addName().setFamily("FAM" + i); - ourClient.create().resource(pt1).execute(); + myClient.create().resource(pt1).execute(); } - Bundle results = ourClient + Bundle results = myClient .search() .forResource("Patient") .where(Patient.FAMILY.matches().value("FAM")) @@ -116,7 +117,7 @@ public class ResourceProviderR4CacheTest extends BaseResourceProviderR4Test { public void testCacheNoStoreMaxResultsWithIllegalValue() { myDaoConfig.setCacheControlNoStoreMaxResultsUpperLimit(123); try { - ourClient + myClient .search() .forResource("Patient") .where(Patient.FAMILY.matches().value("FAM")) @@ -134,18 +135,18 @@ public class ResourceProviderR4CacheTest extends BaseResourceProviderR4Test { Patient pt1 = new Patient(); pt1.addName().setFamily("FAM"); - ourClient.create().resource(pt1).execute(); + myClient.create().resource(pt1).execute(); - Bundle results = ourClient.search().forResource("Patient").where(Patient.FAMILY.matches().value("FAM")).returnBundle(Bundle.class).execute(); + Bundle results = myClient.search().forResource("Patient").where(Patient.FAMILY.matches().value("FAM")).returnBundle(Bundle.class).execute(); assertEquals(1, results.getEntry().size()); assertEquals(1, mySearchEntityDao.count()); assertThat(myCapturingInterceptor.getLastResponse().getHeaders(Constants.HEADER_X_CACHE), empty()); Patient pt2 = new Patient(); pt2.addName().setFamily("FAM"); - ourClient.create().resource(pt2).execute(); + myClient.create().resource(pt2).execute(); - results = ourClient + results = myClient .search() .forResource("Patient") .where(Patient.FAMILY.matches().value("FAM")) @@ -163,13 +164,13 @@ public class ResourceProviderR4CacheTest extends BaseResourceProviderR4Test { Patient pt1 = new Patient(); pt1.addName().setFamily("FAM"); - ourClient.create().resource(pt1).execute(); + myClient.create().resource(pt1).execute(); Date beforeFirst = new Date(); TestUtil.sleepOneClick(); - Bundle results1 = ourClient.search().forResource("Patient").where(Patient.FAMILY.matches().value("FAM")).returnBundle(Bundle.class).execute(); + Bundle results1 = myClient.search().forResource("Patient").where(Patient.FAMILY.matches().value("FAM")).returnBundle(Bundle.class).execute(); TestUtil.sleepOneClick(); @@ -183,9 +184,9 @@ public class ResourceProviderR4CacheTest extends BaseResourceProviderR4Test { Patient pt2 = new Patient(); pt2.addName().setFamily("FAM"); - ourClient.create().resource(pt2).execute(); + myClient.create().resource(pt2).execute(); - Bundle results2 = ourClient.search().forResource("Patient").where(Patient.FAMILY.matches().value("FAM")).returnBundle(Bundle.class).execute(); + Bundle results2 = myClient.search().forResource("Patient").where(Patient.FAMILY.matches().value("FAM")).returnBundle(Bundle.class).execute(); assertEquals(1, results2.getEntry().size()); assertEquals(1, mySearchEntityDao.count()); assertEquals("HIT from " + ourServerBase, myCapturingInterceptor.getLastResponse().getHeaders(Constants.HEADER_X_CACHE).get(0)); @@ -203,7 +204,7 @@ public class ResourceProviderR4CacheTest extends BaseResourceProviderR4Test { p.addName().setFamily("Foo"); String p2Id = myPatientDao.create(p).getId().toUnqualifiedVersionless().getValue(); - Bundle resp1 = ourClient + Bundle resp1 = myClient .search() .forResource("Patient") .where(Patient.NAME.matches().value("foo")) @@ -211,9 +212,9 @@ public class ResourceProviderR4CacheTest extends BaseResourceProviderR4Test { .execute(); assertEquals(2, resp1.getEntry().size()); - ourClient.delete().resourceById(new IdType(p1Id)).execute(); + myClient.delete().resourceById(new IdType(p1Id)).execute(); - Bundle resp2 = ourClient + Bundle resp2 = myClient .search() .forResource("Patient") .where(Patient.NAME.matches().value("foo")) @@ -226,9 +227,5 @@ public class ResourceProviderR4CacheTest extends BaseResourceProviderR4Test { assertEquals(1, resp2.getEntry().size()); } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4CodeSystemTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4CodeSystemTest.java index dd12eff75e4..8fc41cbb4ab 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4CodeSystemTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4CodeSystemTest.java @@ -2,29 +2,24 @@ package ca.uhn.fhir.jpa.provider.r4; import ca.uhn.fhir.jpa.dao.r4.FhirResourceDaoR4TerminologyTest; import ca.uhn.fhir.jpa.model.util.JpaConstants; -import ca.uhn.fhir.jpa.provider.TerminologyUploaderProvider; -import ca.uhn.fhir.rest.client.interceptor.LoggingInterceptor; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException; -import ca.uhn.fhir.util.TestUtil; import org.hl7.fhir.r4.model.*; import org.hl7.fhir.r4.model.codesystems.ConceptSubsumptionOutcome; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.transaction.annotation.Transactional; import java.io.IOException; -import static org.hamcrest.CoreMatchers.containsString; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; public class ResourceProviderR4CodeSystemTest extends BaseResourceProviderR4Test { private static final String SYSTEM_PARENTCHILD = "http://parentchild"; private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ResourceProviderR4CodeSystemTest.class); - @Before + @BeforeEach @Transactional public void before02() throws IOException { CodeSystem cs = loadResourceFromClasspath(CodeSystem.class, "/extensional-case-3-cs.xml"); @@ -51,7 +46,7 @@ public class ResourceProviderR4CodeSystemTest extends BaseResourceProviderR4Test public void testLookupOnExternalCode() { ResourceProviderR4ValueSetTest.createExternalCs(myCodeSystemDao, myResourceTableDao, myTermCodeSystemStorageSvc, mySrd); - Parameters respParam = ourClient + Parameters respParam = myClient .operation() .onType(CodeSystem.class) .named("lookup") @@ -72,7 +67,7 @@ public class ResourceProviderR4CodeSystemTest extends BaseResourceProviderR4Test assertEquals(false, ((BooleanType) respParam.getParameter().get(3).getValue()).getValue()); // With HTTP GET - respParam = ourClient + respParam = myClient .operation() .onType(CodeSystem.class) .named("lookup") @@ -97,7 +92,7 @@ public class ResourceProviderR4CodeSystemTest extends BaseResourceProviderR4Test @Test public void testLookupOperationByCodeAndSystemBuiltInCode() { - Parameters respParam = ourClient + Parameters respParam = myClient .operation() .onType(CodeSystem.class) .named("lookup") @@ -121,7 +116,7 @@ public class ResourceProviderR4CodeSystemTest extends BaseResourceProviderR4Test @Test public void testLookupOperationByCodeAndSystemBuiltInNonexistantCode() { try { - ourClient + myClient .operation() .onType(CodeSystem.class) .named("lookup") @@ -136,7 +131,7 @@ public class ResourceProviderR4CodeSystemTest extends BaseResourceProviderR4Test @Test public void testLookupOperationByCodeAndSystemUserDefinedCode() { - Parameters respParam = ourClient + Parameters respParam = myClient .operation() .onType(CodeSystem.class) .named("lookup") @@ -158,7 +153,7 @@ public class ResourceProviderR4CodeSystemTest extends BaseResourceProviderR4Test @Test public void testLookupOperationByCodeAndSystemUserDefinedNonExistantCode() { try { - ourClient + myClient .operation() .onType(CodeSystem.class) .named("lookup") @@ -173,7 +168,7 @@ public class ResourceProviderR4CodeSystemTest extends BaseResourceProviderR4Test @Test public void testLookupOperationByCoding() { - Parameters respParam = ourClient + Parameters respParam = myClient .operation() .onType(CodeSystem.class) .named("lookup") @@ -194,7 +189,7 @@ public class ResourceProviderR4CodeSystemTest extends BaseResourceProviderR4Test @Test public void testLookupOperationByInvalidCombination() { try { - ourClient + myClient .operation() .onType(CodeSystem.class) .named("lookup") @@ -211,7 +206,7 @@ public class ResourceProviderR4CodeSystemTest extends BaseResourceProviderR4Test @Test public void testLookupOperationByInvalidCombination2() { try { - ourClient + myClient .operation() .onType(CodeSystem.class) .named("lookup") @@ -227,7 +222,7 @@ public class ResourceProviderR4CodeSystemTest extends BaseResourceProviderR4Test @Test public void testLookupOperationByInvalidCombination3() { try { - ourClient + myClient .operation() .onType(CodeSystem.class) .named("lookup") @@ -241,7 +236,7 @@ public class ResourceProviderR4CodeSystemTest extends BaseResourceProviderR4Test @Test public void testLookupOperationForBuiltInCode() { - Parameters respParam = ourClient + Parameters respParam = myClient .operation() .onType(CodeSystem.class) .named("lookup") @@ -264,7 +259,7 @@ public class ResourceProviderR4CodeSystemTest extends BaseResourceProviderR4Test @Test public void testSubsumesOnCodes_Subsumes() { - Parameters respParam = ourClient + Parameters respParam = myClient .operation() .onType(CodeSystem.class) .named(JpaConstants.OPERATION_SUBSUMES) @@ -284,7 +279,7 @@ public class ResourceProviderR4CodeSystemTest extends BaseResourceProviderR4Test @Test public void testSubsumesOnCodes_Subsumedby() { - Parameters respParam = ourClient + Parameters respParam = myClient .operation() .onType(CodeSystem.class) .named(JpaConstants.OPERATION_SUBSUMES) @@ -303,7 +298,7 @@ public class ResourceProviderR4CodeSystemTest extends BaseResourceProviderR4Test @Test public void testSubsumesOnCodes_Disjoint() { - Parameters respParam = ourClient + Parameters respParam = myClient .operation() .onType(CodeSystem.class) .named(JpaConstants.OPERATION_SUBSUMES) @@ -323,7 +318,7 @@ public class ResourceProviderR4CodeSystemTest extends BaseResourceProviderR4Test @Test public void testSubsumesOnCodes_InvalidCodeLeft() { try { - ourClient + myClient .operation() .onType(CodeSystem.class) .named(JpaConstants.OPERATION_SUBSUMES) @@ -338,7 +333,7 @@ public class ResourceProviderR4CodeSystemTest extends BaseResourceProviderR4Test @Test public void testSubsumesOnCodes_InvalidCodeRight() { try { - ourClient + myClient .operation() .onType(CodeSystem.class) .named(JpaConstants.OPERATION_SUBSUMES) @@ -353,7 +348,7 @@ public class ResourceProviderR4CodeSystemTest extends BaseResourceProviderR4Test @Test public void testSubsumesOnCodings_MismatchedCs() { try { - ourClient + myClient .operation() .onType(CodeSystem.class) .named(JpaConstants.OPERATION_SUBSUMES) @@ -368,7 +363,7 @@ public class ResourceProviderR4CodeSystemTest extends BaseResourceProviderR4Test @Test public void testSubsumesOnCodings_Subsumes() { - Parameters respParam = ourClient + Parameters respParam = myClient .operation() .onType(CodeSystem.class) .named(JpaConstants.OPERATION_SUBSUMES) @@ -387,7 +382,7 @@ public class ResourceProviderR4CodeSystemTest extends BaseResourceProviderR4Test @Test public void testSubsumesOnCodings_Subsumedby() { - Parameters respParam = ourClient + Parameters respParam = myClient .operation() .onType(CodeSystem.class) .named(JpaConstants.OPERATION_SUBSUMES) @@ -405,7 +400,7 @@ public class ResourceProviderR4CodeSystemTest extends BaseResourceProviderR4Test @Test public void testSubsumesOnCodings_Disjoint() { - Parameters respParam = ourClient + Parameters respParam = myClient .operation() .onType(CodeSystem.class) .named(JpaConstants.OPERATION_SUBSUMES) @@ -422,9 +417,4 @@ public class ResourceProviderR4CodeSystemTest extends BaseResourceProviderR4Test } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } - } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4ConceptMapTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4ConceptMapTest.java index 4ee1149e756..14e2fe2b28f 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4ConceptMapTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4ConceptMapTest.java @@ -1,30 +1,22 @@ package ca.uhn.fhir.jpa.provider.r4; import ca.uhn.fhir.rest.api.MethodOutcome; -import ca.uhn.fhir.util.TestUtil; import org.hl7.fhir.instance.model.api.IIdType; import org.hl7.fhir.r4.model.*; import org.hl7.fhir.r4.model.Parameters.ParametersParameterComponent; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.transaction.annotation.Transactional; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; public class ResourceProviderR4ConceptMapTest extends BaseResourceProviderR4Test { private static final Logger ourLog = LoggerFactory.getLogger(ResourceProviderR4ConceptMapTest.class); private IIdType myConceptMapId; - - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } - - @Before + @BeforeEach @Transactional public void before02() { myConceptMapId = myConceptMapDao.create(createConceptMap(), mySrd).getId().toUnqualifiedVersionless(); @@ -34,7 +26,7 @@ public class ResourceProviderR4ConceptMapTest extends BaseResourceProviderR4Test public void testStoreExistingTermConceptMapAndChildren() { ConceptMap conceptMap = createConceptMap(); - MethodOutcome methodOutcome = ourClient + MethodOutcome methodOutcome = myClient .update() .resource(conceptMap) .conditional() @@ -50,7 +42,7 @@ public class ResourceProviderR4ConceptMapTest extends BaseResourceProviderR4Test ConceptMap conceptMap = createConceptMap(); conceptMap.getGroupFirstRep().getElementFirstRep().setCode("UPDATED_CODE"); - MethodOutcome methodOutcome = ourClient + MethodOutcome methodOutcome = myClient .update() .resource(conceptMap) .conditional() @@ -74,7 +66,7 @@ public class ResourceProviderR4ConceptMapTest extends BaseResourceProviderR4Test ourLog.info("Request Parameters:\n" + myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(inParams)); - Parameters respParams = ourClient + Parameters respParams = myClient .operation() .onType(ConceptMap.class) .named("translate") @@ -132,7 +124,7 @@ public class ResourceProviderR4ConceptMapTest extends BaseResourceProviderR4Test ourLog.info("Request Parameters:\n" + myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(inParams)); - Parameters respParams = ourClient + Parameters respParams = myClient .operation() .onType(ConceptMap.class) .named("translate") @@ -177,7 +169,7 @@ public class ResourceProviderR4ConceptMapTest extends BaseResourceProviderR4Test ourLog.info("Request Parameters:\n" + myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(inParams)); - Parameters respParams = ourClient + Parameters respParams = myClient .operation() .onType(ConceptMap.class) .named("translate") @@ -210,7 +202,7 @@ public class ResourceProviderR4ConceptMapTest extends BaseResourceProviderR4Test ourLog.info("Request Parameters:\n" + myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(inParams)); - Parameters respParams = ourClient + Parameters respParams = myClient .operation() .onType(ConceptMap.class) .named("translate") @@ -288,7 +280,7 @@ public class ResourceProviderR4ConceptMapTest extends BaseResourceProviderR4Test ourLog.info("Request Parameters:\n" + myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(inParams)); - Parameters respParams = ourClient + Parameters respParams = myClient .operation() .onType(ConceptMap.class) .named("translate") @@ -341,7 +333,7 @@ public class ResourceProviderR4ConceptMapTest extends BaseResourceProviderR4Test ourLog.info("Request Parameters:\n" + myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(inParams)); - Parameters respParams = ourClient + Parameters respParams = myClient .operation() .onType(ConceptMap.class) .named("translate") @@ -432,7 +424,7 @@ public class ResourceProviderR4ConceptMapTest extends BaseResourceProviderR4Test ourLog.info("Request Parameters:\n" + myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(inParams)); - Parameters respParams = ourClient + Parameters respParams = myClient .operation() .onType(ConceptMap.class) .named("translate") @@ -511,7 +503,7 @@ public class ResourceProviderR4ConceptMapTest extends BaseResourceProviderR4Test ourLog.info("Request Parameters:\n" + myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(inParams)); - Parameters respParams = ourClient + Parameters respParams = myClient .operation() .onType(ConceptMap.class) .named("translate") @@ -562,7 +554,7 @@ public class ResourceProviderR4ConceptMapTest extends BaseResourceProviderR4Test ourLog.info("Request Parameters:\n" + myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(inParams)); - Parameters respParams = ourClient + Parameters respParams = myClient .operation() .onType(ConceptMap.class) .named("translate") @@ -627,7 +619,7 @@ public class ResourceProviderR4ConceptMapTest extends BaseResourceProviderR4Test ourLog.info("Request Parameters:\n" + myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(inParams)); - Parameters respParams = ourClient + Parameters respParams = myClient .operation() .onType(ConceptMap.class) .named("translate") @@ -678,7 +670,7 @@ public class ResourceProviderR4ConceptMapTest extends BaseResourceProviderR4Test ourLog.info("Request Parameters:\n" + myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(inParams)); - Parameters respParams = ourClient + Parameters respParams = myClient .operation() .onType(ConceptMap.class) .named("translate") @@ -741,7 +733,7 @@ public class ResourceProviderR4ConceptMapTest extends BaseResourceProviderR4Test ourLog.info("Request Parameters:\n" + myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(inParams)); - Parameters respParams = ourClient + Parameters respParams = myClient .operation() .onType(ConceptMap.class) .named("translate") @@ -818,7 +810,7 @@ public class ResourceProviderR4ConceptMapTest extends BaseResourceProviderR4Test ourLog.info("Request Parameters:\n" + myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(inParams)); - Parameters respParams = ourClient + Parameters respParams = myClient .operation() .onType(ConceptMap.class) .named("translate") @@ -889,7 +881,7 @@ public class ResourceProviderR4ConceptMapTest extends BaseResourceProviderR4Test ourLog.info("Request Parameters:\n" + myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(inParams)); - Parameters respParams = ourClient + Parameters respParams = myClient .operation() .onInstance(myConceptMapId) .named("translate") @@ -970,7 +962,7 @@ public class ResourceProviderR4ConceptMapTest extends BaseResourceProviderR4Test ourLog.info("Request Parameters:\n" + myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(inParams)); - Parameters respParams = ourClient + Parameters respParams = myClient .operation() .onType(ConceptMap.class) .named("translate") @@ -1016,7 +1008,7 @@ public class ResourceProviderR4ConceptMapTest extends BaseResourceProviderR4Test ourLog.info("Request Parameters:\n" + myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(inParams)); - Parameters respParams = ourClient + Parameters respParams = myClient .operation() .onType(ConceptMap.class) .named("translate") @@ -1051,7 +1043,7 @@ public class ResourceProviderR4ConceptMapTest extends BaseResourceProviderR4Test ourLog.info("Request Parameters:\n" + myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(inParams)); - Parameters respParams = ourClient + Parameters respParams = myClient .operation() .onType(ConceptMap.class) .named("translate") @@ -1117,7 +1109,7 @@ public class ResourceProviderR4ConceptMapTest extends BaseResourceProviderR4Test ourLog.info("Request Parameters:\n" + myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(inParams)); - Parameters respParams = ourClient + Parameters respParams = myClient .operation() .onType(ConceptMap.class) .named("translate") @@ -1187,7 +1179,7 @@ public class ResourceProviderR4ConceptMapTest extends BaseResourceProviderR4Test ourLog.info("Request Parameters:\n" + myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(inParams)); - Parameters respParams = ourClient + Parameters respParams = myClient .operation() .onType(ConceptMap.class) .named("translate") @@ -1280,7 +1272,7 @@ public class ResourceProviderR4ConceptMapTest extends BaseResourceProviderR4Test ourLog.info("Request Parameters:\n" + myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(inParams)); - Parameters respParams = ourClient + Parameters respParams = myClient .operation() .onType(ConceptMap.class) .named("translate") @@ -1347,7 +1339,7 @@ public class ResourceProviderR4ConceptMapTest extends BaseResourceProviderR4Test ourLog.info("Request Parameters:\n" + myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(inParams)); - Parameters respParams = ourClient + Parameters respParams = myClient .operation() .onType(ConceptMap.class) .named("translate") @@ -1414,7 +1406,7 @@ public class ResourceProviderR4ConceptMapTest extends BaseResourceProviderR4Test ourLog.info("Request Parameters:\n" + myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(inParams)); - Parameters respParams = ourClient + Parameters respParams = myClient .operation() .onType(ConceptMap.class) .named("translate") @@ -1467,7 +1459,7 @@ public class ResourceProviderR4ConceptMapTest extends BaseResourceProviderR4Test ourLog.info("Request Parameters:\n" + myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(inParams)); - Parameters respParams = ourClient + Parameters respParams = myClient .operation() .onType(ConceptMap.class) .named("translate") @@ -1518,7 +1510,7 @@ public class ResourceProviderR4ConceptMapTest extends BaseResourceProviderR4Test ourLog.info("Request Parameters:\n" + myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(inParams)); - Parameters respParams = ourClient + Parameters respParams = myClient .operation() .onType(ConceptMap.class) .named("translate") @@ -1583,7 +1575,7 @@ public class ResourceProviderR4ConceptMapTest extends BaseResourceProviderR4Test ourLog.info("Request Parameters:\n" + myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(inParams)); - Parameters respParams = ourClient + Parameters respParams = myClient .operation() .onType(ConceptMap.class) .named("translate") @@ -1641,7 +1633,7 @@ public class ResourceProviderR4ConceptMapTest extends BaseResourceProviderR4Test ourLog.info("Request Parameters:\n" + myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(inParams)); - Parameters respParams = ourClient + Parameters respParams = myClient .operation() .onInstance(myConceptMapId) .named("translate") diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4DistanceTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4DistanceTest.java index 653f7b7a258..e9725f9b219 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4DistanceTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4DistanceTest.java @@ -5,11 +5,14 @@ import org.hl7.fhir.instance.model.api.IIdType; import org.hl7.fhir.r4.model.Bundle; import org.hl7.fhir.r4.model.Location; import org.hl7.fhir.r4.model.PractitionerRole; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public class ResourceProviderR4DistanceTest extends BaseResourceProviderR4Test { + + @BeforeEach @Override public void before() throws Exception { super.before(); @@ -23,7 +26,7 @@ public class ResourceProviderR4DistanceTest extends BaseResourceProviderR4Test { double longitude = CoordCalculatorTest.LONGITUDE_UHN; Location.LocationPositionComponent position = new Location.LocationPositionComponent().setLatitude(latitude).setLongitude(longitude); loc.setPosition(position); - IIdType locId = ourClient.create().resource(loc).execute().getId().toUnqualifiedVersionless(); + IIdType locId = myClient.create().resource(loc).execute().getId().toUnqualifiedVersionless(); { // In the box double bigEnoughDistance = CoordCalculatorTest.DISTANCE_KM_CHIN_TO_UHN * 2; @@ -31,7 +34,7 @@ public class ResourceProviderR4DistanceTest extends BaseResourceProviderR4Test { Location.SP_NEAR + "=" + CoordCalculatorTest.LATITUDE_CHIN + "|" + CoordCalculatorTest.LONGITUDE_CHIN + "|" + bigEnoughDistance; - Bundle actual = ourClient + Bundle actual = myClient .search() .byUrl(ourServerBase + "/" + url) .encodedJson() @@ -49,7 +52,7 @@ public class ResourceProviderR4DistanceTest extends BaseResourceProviderR4Test { "|" + tooSmallDistance; myCaptureQueriesListener.clear(); - Bundle actual = ourClient + Bundle actual = myClient .search() .byUrl(ourServerBase + "/" + url) .encodedJson() @@ -69,16 +72,16 @@ public class ResourceProviderR4DistanceTest extends BaseResourceProviderR4Test { double longitude = CoordCalculatorTest.LONGITUDE_CHIN; Location.LocationPositionComponent position = new Location.LocationPositionComponent().setLatitude(latitude).setLongitude(longitude); loc.setPosition(position); - IIdType locId = ourClient.create().resource(loc).execute().getId().toUnqualifiedVersionless(); + IIdType locId = myClient.create().resource(loc).execute().getId().toUnqualifiedVersionless(); PractitionerRole pr = new PractitionerRole(); pr.addLocation().setReference(locId.getValue()); - IIdType prId = ourClient.create().resource(pr).execute().getId().toUnqualifiedVersionless(); + IIdType prId = myClient.create().resource(pr).execute().getId().toUnqualifiedVersionless(); String url = "PractitionerRole?location." + Location.SP_NEAR + "=" + latitude + "|" + longitude; - Bundle actual = ourClient + Bundle actual = myClient .search() .byUrl(ourServerBase + "/" + url) .encodedJson() @@ -111,7 +114,7 @@ public class ResourceProviderR4DistanceTest extends BaseResourceProviderR4Test { "|" + bigEnoughDistance; myCaptureQueriesListener.clear(); - Bundle actual = ourClient + Bundle actual = myClient .search() .byUrl(ourServerBase + "/" + url) .encodedJson() @@ -131,7 +134,7 @@ public class ResourceProviderR4DistanceTest extends BaseResourceProviderR4Test { "|" + tooSmallDistance; myCaptureQueriesListener.clear(); - Bundle actual = ourClient + Bundle actual = myClient .search() .byUrl(ourServerBase + "/" + url) .encodedJson() diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4StructureDefinitionTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4StructureDefinitionTest.java index dcd6672d402..e0deed18200 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4StructureDefinitionTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4StructureDefinitionTest.java @@ -3,21 +3,19 @@ package ca.uhn.fhir.jpa.provider.r4; import ca.uhn.fhir.jpa.model.util.JpaConstants; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException; -import ca.uhn.fhir.util.TestUtil; import org.hl7.fhir.instance.model.api.IIdType; import org.hl7.fhir.r4.model.Bundle; import org.hl7.fhir.r4.model.IdType; import org.hl7.fhir.r4.model.Parameters; import org.hl7.fhir.r4.model.StringType; import org.hl7.fhir.r4.model.StructureDefinition; -import org.junit.AfterClass; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.IOException; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public class ResourceProviderR4StructureDefinitionTest extends BaseResourceProviderR4Test { @@ -28,7 +26,7 @@ public class ResourceProviderR4StructureDefinitionTest extends BaseResourceProvi StructureDefinition sd = loadResource(myFhirCtx, StructureDefinition.class, "/r4/sd-david-dhtest7.json"); myStructureDefinitionDao.update(sd); - Bundle response = ourClient + Bundle response = myClient .search() .forResource(StructureDefinition.class) .returnBundle(Bundle.class) @@ -43,7 +41,7 @@ public class ResourceProviderR4StructureDefinitionTest extends BaseResourceProvi public void testSnapshotWithResourceParameter() throws IOException { StructureDefinition sd = loadResourceFromClasspath(StructureDefinition.class, "/r4/profile-differential-patient-r4.json"); - StructureDefinition response = ourClient + StructureDefinition response = myClient .operation() .onType(StructureDefinition.class) .named(JpaConstants.OPERATION_SNAPSHOT) @@ -56,9 +54,9 @@ public class ResourceProviderR4StructureDefinitionTest extends BaseResourceProvi @Test public void testSnapshotWithId() throws IOException { StructureDefinition sd = loadResourceFromClasspath(StructureDefinition.class, "/r4/profile-differential-patient-r4.json"); - IIdType id = ourClient.create().resource(sd).execute().getId().toUnqualifiedVersionless(); + IIdType id = myClient.create().resource(sd).execute().getId().toUnqualifiedVersionless(); - StructureDefinition response = ourClient + StructureDefinition response = myClient .operation() .onInstance(id) .named(JpaConstants.OPERATION_SNAPSHOT) @@ -71,9 +69,9 @@ public class ResourceProviderR4StructureDefinitionTest extends BaseResourceProvi @Test public void testSnapshotWithUrl() throws IOException { StructureDefinition sd = loadResourceFromClasspath(StructureDefinition.class, "/r4/profile-differential-patient-r4.json"); - IIdType id = ourClient.create().resource(sd).execute().getId().toUnqualifiedVersionless(); + IIdType id = myClient.create().resource(sd).execute().getId().toUnqualifiedVersionless(); - StructureDefinition response = ourClient + StructureDefinition response = myClient .operation() .onType(StructureDefinition.class) .named(JpaConstants.OPERATION_SNAPSHOT) @@ -86,7 +84,7 @@ public class ResourceProviderR4StructureDefinitionTest extends BaseResourceProvi @Test public void testSnapshotWithUrlAndId() { try { - ourClient + myClient .operation() .onInstance(new IdType("StructureDefinition/123")) .named(JpaConstants.OPERATION_SNAPSHOT) @@ -101,7 +99,7 @@ public class ResourceProviderR4StructureDefinitionTest extends BaseResourceProvi @Test public void testSnapshotWithInvalidUrl() { try { - ourClient + myClient .operation() .onType(StructureDefinition.class) .named(JpaConstants.OPERATION_SNAPSHOT) @@ -113,8 +111,4 @@ public class ResourceProviderR4StructureDefinitionTest extends BaseResourceProvi } } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4Test.java index ec07c67be5a..5e9159f4c8f 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4Test.java @@ -7,7 +7,6 @@ import ca.uhn.fhir.jpa.entity.Search; import ca.uhn.fhir.jpa.model.entity.ResourceHistoryTable; import ca.uhn.fhir.jpa.model.util.JpaConstants; import ca.uhn.fhir.jpa.search.SearchCoordinatorSvcImpl; -import ca.uhn.fhir.jpa.util.TestUtil; import ca.uhn.fhir.model.api.TemporalPrecisionEnum; import ca.uhn.fhir.model.primitive.InstantDt; import ca.uhn.fhir.model.primitive.UriDt; @@ -128,11 +127,7 @@ import org.hl7.fhir.r4.model.Subscription.SubscriptionStatus; import org.hl7.fhir.r4.model.UnsignedIntType; import org.hl7.fhir.r4.model.ValueSet; import org.hl7.fhir.utilities.xhtml.XhtmlNode; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.*; import static org.hamcrest.MatcherAssert.assertThat; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.util.AopTestUtils; import org.springframework.transaction.TransactionStatus; @@ -160,31 +155,8 @@ import java.util.stream.Collectors; import static ca.uhn.fhir.jpa.util.TestUtil.sleepAtLeast; import static ca.uhn.fhir.jpa.util.TestUtil.sleepOneClick; import static org.apache.commons.lang3.StringUtils.isNotBlank; -import static org.hamcrest.Matchers.contains; -import static org.hamcrest.Matchers.containsInAnyOrder; -import static org.hamcrest.Matchers.containsInRelativeOrder; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.empty; -import static org.hamcrest.Matchers.emptyString; -import static org.hamcrest.Matchers.endsWith; -import static org.hamcrest.Matchers.greaterThan; -import static org.hamcrest.Matchers.hasItem; -import static org.hamcrest.Matchers.hasItems; -import static org.hamcrest.Matchers.hasSize; -import static org.hamcrest.Matchers.lessThan; -import static org.hamcrest.Matchers.lessThanOrEqualTo; -import static org.hamcrest.Matchers.matchesPattern; -import static org.hamcrest.Matchers.not; -import static org.hamcrest.Matchers.startsWith; -import static org.hamcrest.Matchers.stringContainsInOrder; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.hamcrest.Matchers.*; +import static org.junit.jupiter.api.Assertions.*; @SuppressWarnings("Duplicates") public class ResourceProviderR4Test extends BaseResourceProviderR4Test { @@ -197,7 +169,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { private ISearchDao mySearchEntityDao; @Override - @After + @AfterEach public void after() throws Exception { super.after(); @@ -214,16 +186,17 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { mySearchCoordinatorSvcRaw.setNeverUseLocalSearchForUnitTests(false); mySearchCoordinatorSvcRaw.cancelAllActiveSearches(); - ourClient.unregisterInterceptor(myCapturingInterceptor); + myClient.unregisterInterceptor(myCapturingInterceptor); } + @BeforeEach @Override public void before() throws Exception { super.before(); myFhirCtx.setParserErrorHandler(new StrictErrorHandler()); myDaoConfig.setAllowMultipleDelete(true); - ourClient.registerInterceptor(myCapturingInterceptor); + myClient.registerInterceptor(myCapturingInterceptor); myDaoConfig.setSearchPreFetchThresholds(new DaoConfig().getSearchPreFetchThresholds()); } @@ -236,7 +209,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { searchParameter.setExpression("Procedure.extension('Procedure#focalAccess')"); searchParameter.setXpathUsage(SearchParameter.XPathUsageType.NORMAL); searchParameter.setStatus(Enumerations.PublicationStatus.ACTIVE); - ourClient.create().resource(searchParameter).execute(); + myClient.create().resource(searchParameter).execute(); mySearchParamRegistry.forceRefresh(); @@ -258,7 +231,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { searchParameter.setExpression("Procedure.extension('Procedure#focalAccess')"); searchParameter.setXpathUsage(SearchParameter.XPathUsageType.NORMAL); searchParameter.setStatus(Enumerations.PublicationStatus.ACTIVE); - ourClient.create().resource(searchParameter).execute(); + myClient.create().resource(searchParameter).execute(); mySearchParamRegistry.forceRefresh(); @@ -275,7 +248,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { myCaptureQueriesListener.clear(); - ourClient + myClient .loadPage() .byUrl(ourServerBase + "/Practitioner?identifier=" + UrlUtil.escapeUrlParam("ABC|,DEF")) .andReturnBundle(Bundle.class) @@ -302,7 +275,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { myPatientDao.create(pt3).getId().toUnqualifiedVersionless().getValue(); - Bundle output = ourClient + Bundle output = myClient .search() .forResource("Patient") .where(Patient.NAME.contains().value("ZAB")) @@ -311,7 +284,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { List ids = output.getEntry().stream().map(t -> t.getResource().getIdElement().toUnqualifiedVersionless().getValue()).collect(Collectors.toList()); assertThat(ids, containsInAnyOrder(pt1id)); - output = ourClient + output = myClient .search() .forResource("Patient") .where(Patient.NAME.contains().value("zab")) @@ -328,22 +301,22 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { Procedure procedure = new Procedure(); procedure.setStatus(Procedure.ProcedureStatus.COMPLETED); - String procedureId = ourClient.create().resource(procedure).execute().getId().toUnqualifiedVersionless().getValue(); + String procedureId = myClient.create().resource(procedure).execute().getId().toUnqualifiedVersionless().getValue(); DocumentReference dr = new DocumentReference(); dr.addContent().getAttachment().setContentType("application/vnd.mfer"); - String drId = ourClient.create().resource(dr).execute().getId().toUnqualifiedVersionless().getValue(); + String drId = myClient.create().resource(dr).execute().getId().toUnqualifiedVersionless().getValue(); for (int i = 0; i < 60; i++) { Observation obs = new Observation(); obs.addPartOf().setReference(procedureId); obs.addDerivedFrom().setReference(drId); - ourClient.create().resource(obs).execute(); + myClient.create().resource(obs).execute(); } ourLog.info("Starting search"); - Bundle response = ourClient + Bundle response = myClient .search() .byUrl("Observation?part-of=" + procedureId + "&derived-from:DocumentReference.contenttype=application/vnd.mfer&_total=accurate&_count=2") .returnBundle(Bundle.class) @@ -355,7 +328,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { obsCount += response.getEntry().size(); pageCount++; if (response.getLink("next") != null) { - response = ourClient.loadPage().next(response).execute(); + response = myClient.loadPage().next(response).execute(); } else { response = null; } @@ -378,10 +351,10 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { Organization o = new Organization(); o.setId("O" + i); o.setName("O" + i); - ourClient.update().resource(o).execute().getId().toUnqualifiedVersionless(); + myClient.update().resource(o).execute().getId().toUnqualifiedVersionless(); } - Bundle output = ourClient + Bundle output = myClient .search() .forResource("Organization") .count(3) @@ -390,7 +363,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { assertNull(output.getTotalElement().getValue()); - output = ourClient + output = myClient .search() .forResource("Organization") .count(3) @@ -404,7 +377,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { linkNext = linkNext.replaceAll("_getpagesoffset=[0-9]+", "_getpagesoffset=3300"); assertThat(linkNext, containsString("_getpagesoffset=3300")); - Bundle nextPageBundle = ourClient.loadPage().byUrl(linkNext).andReturnBundle(Bundle.class).execute(); + Bundle nextPageBundle = myClient.loadPage().byUrl(linkNext).andReturnBundle(Bundle.class).execute(); ourLog.info(myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(nextPageBundle)); assertEquals(null, nextPageBundle.getLink("next")); } @@ -416,16 +389,16 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { Organization o = new Organization(); o.setId("O" + i); o.setName("O" + i); - IIdType oid = ourClient.update().resource(o).execute().getId().toUnqualifiedVersionless(); + IIdType oid = myClient.update().resource(o).execute().getId().toUnqualifiedVersionless(); Patient p = new Patient(); p.setId("P" + i); p.getManagingOrganization().setReference(oid.getValue()); - ourClient.update().resource(p).execute(); + myClient.update().resource(p).execute(); } - Bundle output = ourClient + Bundle output = myClient .search() .forResource("Patient") .include(IBaseResource.INCLUDE_ALL) @@ -439,7 +412,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { assertNotNull(output.getLink("next")); // Page 2 - output = ourClient + output = myClient .loadPage() .next(output) .execute(); @@ -461,7 +434,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { sp.setCode("extpatorg"); sp.setName("extpatorg"); sp.setExpression("Patient.extension('http://patext').value.as(Reference)"); - ourClient.create().resource(sp).execute(); + myClient.create().resource(sp).execute(); sp = new SearchParameter(); sp.addBase("Organization"); @@ -470,25 +443,25 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { sp.setCode("extorgorg"); sp.setName("extorgorg"); sp.setExpression("Organization.extension('http://orgext').value.as(Reference)"); - ourClient.create().resource(sp).execute(); + myClient.create().resource(sp).execute(); mySearchParamRegistry.forceRefresh(); Organization grandParent = new Organization(); grandParent.setName("GRANDPARENT"); - IIdType grandParentId = ourClient.create().resource(grandParent).execute().getId().toUnqualifiedVersionless(); + IIdType grandParentId = myClient.create().resource(grandParent).execute().getId().toUnqualifiedVersionless(); Organization parent = new Organization(); parent.setName("PARENT"); parent.getPartOf().setReference(grandParentId.getValue()); parent.addExtension("http://orgext", new Reference().setReference(grandParentId.getValue())); - IIdType parentId = ourClient.create().resource(parent).execute().getId().toUnqualifiedVersionless(); + IIdType parentId = myClient.create().resource(parent).execute().getId().toUnqualifiedVersionless(); Organization org = new Organization(); org.setName("ORGANIZATION"); org.getPartOf().setReference(parentId.getValue()); org.addExtension("http://orgext", new Reference().setReference(parentId.getValue())); - IIdType orgId = ourClient.create().resource(org).execute().getId().toUnqualifiedVersionless(); + IIdType orgId = myClient.create().resource(org).execute().getId().toUnqualifiedVersionless(); myCaptureQueriesListener.logSelectQueriesForCurrentThread(); myCaptureQueriesListener.clear(); @@ -496,7 +469,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { Patient p = new Patient(); p.getManagingOrganization().setReference(orgId.getValue()); p.addExtension("http://patext", new Reference().setReference(orgId.getValue())); - String pid = ourClient.create().resource(p).execute().getId().toUnqualified().getValue(); + String pid = myClient.create().resource(p).execute().getId().toUnqualified().getValue(); List idValues; @@ -536,10 +509,10 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { Organization o = new Organization(); o.setId("O" + i); o.setName("O" + i); - IIdType oid = ourClient.update().resource(o).execute().getId().toUnqualifiedVersionless(); + IIdType oid = myClient.update().resource(o).execute().getId().toUnqualifiedVersionless(); } - Bundle output = ourClient + Bundle output = myClient .search() .forResource("Organization") .count(3) @@ -550,7 +523,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { String url = nextPageUrl.replace("_getpagesoffset=3", "_getpagesoffset=999"); ourLog.info("Going to request URL: {}", url); - output = ourClient + output = myClient .loadPage() .byUrl(url) .andReturnBundle(Bundle.class) @@ -566,15 +539,15 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { p.addName().setFamily("FAM").addGiven("GIV"); IIdType id = myPatientDao.create(p).getId(); - ourClient.read().resource("Patient").withId(id.toUnqualifiedVersionless()).execute(); + myClient.read().resource("Patient").withId(id.toUnqualifiedVersionless()).execute(); - ourClient + myClient .delete() .resourceConditionalByUrl("Patient?family=FAM&given=giv") .execute(); try { - ourClient.read().resource("Patient").withId(id.toUnqualifiedVersionless()).execute(); + myClient.read().resource("Patient").withId(id.toUnqualifiedVersionless()).execute(); fail(); } catch (ResourceGoneException e) { // good @@ -589,16 +562,16 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { p.addName().setFamily("FAM").addGiven("GIV"); IIdType id = myPatientDao.create(p).getId().toUnqualifiedVersionless(); - ourClient + myClient .delete() .resourceById(id) .execute(); CapturingInterceptor captureInterceptor = new CapturingInterceptor(); - ourClient.registerInterceptor(captureInterceptor); + myClient.registerInterceptor(captureInterceptor); try { - ourClient.read().resource("Patient").withId(id.toUnqualifiedVersionless()).execute(); + myClient.read().resource("Patient").withId(id.toUnqualifiedVersionless()).execute(); fail(); } catch (ResourceGoneException e) { // good @@ -685,7 +658,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { } - @Before + @BeforeEach public void beforeDisableResultReuse() { myDaoConfig.setReuseCachedSearchResultsForMillis(null); mySearchCoordinatorSvcRaw = AopTestUtils.getTargetObject(mySearchCoordinatorSvc); @@ -718,12 +691,12 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { public void saveAndRetrieveBasicResource() throws IOException { String input = IOUtils.toString(getClass().getResourceAsStream("/basic-stu3.xml"), StandardCharsets.UTF_8); - String respString = ourClient.transaction().withBundle(input).prettyPrint().execute(); + String respString = myClient.transaction().withBundle(input).prettyPrint().execute(); ourLog.info(respString); Bundle bundle = myFhirCtx.newXmlParser().parseResource(Bundle.class, respString); IdType id = new IdType(bundle.getEntry().get(0).getResponse().getLocation()); - Basic basic = ourClient.read().resource(Basic.class).withId(id).execute(); + Basic basic = myClient.read().resource(Basic.class).withId(id).execute(); List exts = basic.getExtensionsByUrl("http://localhost:1080/hapi-fhir-jpaserver-example/baseDstu2/StructureDefinition/DateID"); assertEquals(1, exts.size()); } @@ -757,7 +730,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { } @Test - @Ignore + @Disabled public void test() throws IOException { HttpGet get = new HttpGet(ourServerBase + "/QuestionnaireResponse?_count=50&status=completed&questionnaire=ARIncenterAbsRecord&_lastUpdated=%3E" + UrlUtil.escapeUrlParam("=2018-01-01") + "&context.organization=O3435"); ourLog.info("*** MAKING QUERY"); @@ -767,7 +740,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { @Test public void testBundleCreate() throws Exception { - IGenericClient client = ourClient; + IGenericClient client = myClient; String resBody = IOUtils.toString(ResourceProviderR4Test.class.getResource("/r4/document-father.json"), StandardCharsets.UTF_8); IIdType id = client.create().resource(resBody).execute().getId(); @@ -781,7 +754,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { @Test public void testBundleCreateWithTypeTransaction() throws Exception { - IGenericClient client = ourClient; + IGenericClient client = myClient; String resBody = IOUtils.toString(ResourceProviderR4Test.class.getResource("/r4/document-father.json"), StandardCharsets.UTF_8); resBody = resBody.replace("\"type\": \"document\"", "\"type\": \"transaction\""); @@ -799,10 +772,10 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { subs.setStatus(SubscriptionStatus.ACTIVE); subs.getChannel().setType(SubscriptionChannelType.WEBSOCKET); subs.setCriteria("Observation?"); - IIdType id = ourClient.create().resource(subs).execute().getId().toUnqualifiedVersionless(); + IIdType id = myClient.create().resource(subs).execute().getId().toUnqualifiedVersionless(); //@formatter:off - Bundle resp = ourClient + Bundle resp = myClient .search() .forResource(Subscription.class) .where(Subscription.TYPE.exactly().code(SubscriptionChannelType.WEBSOCKET.toCode())) @@ -814,7 +787,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { assertThat(toUnqualifiedVersionlessIds(resp), contains(id)); //@formatter:off - resp = ourClient + resp = myClient .search() .forResource(Subscription.class) .where(Subscription.TYPE.exactly().systemAndCode(SubscriptionChannelType.WEBSOCKET.getSystem(), SubscriptionChannelType.WEBSOCKET.toCode())) @@ -826,7 +799,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { assertThat(toUnqualifiedVersionlessIds(resp), contains(id)); //@formatter:off - resp = ourClient + resp = myClient .search() .forResource(Subscription.class) .where(Subscription.TYPE.exactly().systemAndCode(SubscriptionChannelType.WEBSOCKET.getSystem(), SubscriptionChannelType.WEBSOCKET.toCode())) @@ -847,9 +820,9 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { org.setName("rpr4_testCountParam_01"); resources.add(org); } - ourClient.transaction().withResources(resources).prettyPrint().encodedXml().execute(); + myClient.transaction().withResources(resources).prettyPrint().encodedXml().execute(); - Bundle found = ourClient + Bundle found = myClient .search() .forResource(Organization.class) .where(Organization.NAME.matches().value("rpr4_testCountParam_01")) @@ -858,7 +831,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { .execute(); assertEquals(10, found.getEntry().size()); - found = ourClient.search().forResource(Organization.class).where(Organization.NAME.matches().value("rpr4_testCountParam_01")).count(999).returnBundle(Bundle.class).execute(); + found = myClient.search().forResource(Organization.class).where(Organization.NAME.matches().value("rpr4_testCountParam_01")).count(999).returnBundle(Bundle.class).execute(); assertEquals(50, found.getEntry().size()); } @@ -868,20 +841,20 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { Patient p = new Patient(); p.setActive(false); p.addIdentifier().setSystem("foo").setValue("bar"); - IIdType id = ourClient.create().resource(p).execute().getId(); + IIdType id = myClient.create().resource(p).execute().getId(); p = new Patient(); p.setId(id); p.setActive(true); p.addIdentifier().setSystem("foo").setValue("bar"); - ourClient.update().resource(p).execute().getId(); + myClient.update().resource(p).execute(); // Now conditional create p = new Patient(); p.setActive(true); p.setBirthDateElement(new DateType("2011-01-01")); p.addIdentifier().setSystem("foo").setValue("bar"); - MethodOutcome outcome = ourClient + MethodOutcome outcome = myClient .create() .resource(p) .conditionalByUrl("Patient?identifier=foo|bar") @@ -905,9 +878,9 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { binary.setContent(arr); binary.setContentType("dansk"); - IIdType resource = ourClient.create().resource(binary).execute().getId(); + IIdType resource = myClient.create().resource(binary).execute().getId(); - Binary fromDB = ourClient.read().resource(Binary.class).withId(resource.toVersionless()).execute(); + Binary fromDB = myClient.read().resource(Binary.class).withId(resource.toVersionless()).execute(); assertEquals("1", fromDB.getIdElement().getVersionIdPart()); arr[0] = 2; @@ -921,7 +894,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { resp.close(); } - fromDB = ourClient.read().resource(Binary.class).withId(resource.toVersionless()).execute(); + fromDB = myClient.read().resource(Binary.class).withId(resource.toVersionless()).execute(); assertEquals("2", fromDB.getIdElement().getVersionIdPart()); arr[0] = 3; @@ -937,7 +910,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { resp.close(); } - fromDB = ourClient.read().resource(Binary.class).withId(resource.toVersionless()).execute(); + fromDB = myClient.read().resource(Binary.class).withId(resource.toVersionless()).execute(); assertEquals("3", fromDB.getIdElement().getVersionIdPart()); // Now an update with the wrong ID in the body @@ -954,7 +927,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { resp.close(); } - fromDB = ourClient.read().resource(Binary.class).withId(resource.toVersionless()).execute(); + fromDB = myClient.read().resource(Binary.class).withId(resource.toVersionless()).execute(); assertEquals("3", fromDB.getIdElement().getVersionIdPart()); } @@ -966,7 +939,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { public void testCreateBundle() throws IOException { String input = IOUtils.toString(getClass().getResourceAsStream("/bryn-bundle.json"), StandardCharsets.UTF_8); Validate.notNull(input); - ourClient.create().resource(input).execute(); + myClient.create().resource(input).execute(); } @Test @@ -975,13 +948,13 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { patient.addIdentifier().setSystem("http://uhn.ca/mrns").setValue("100"); patient.addName().setFamily("Tester").addGiven("Raghad"); - MethodOutcome output1 = ourClient.update().resource(patient).conditionalByUrl("Patient?identifier=http://uhn.ca/mrns|100").execute(); + MethodOutcome output1 = myClient.update().resource(patient).conditionalByUrl("Patient?identifier=http://uhn.ca/mrns|100").execute(); patient = new Patient(); patient.addIdentifier().setSystem("http://uhn.ca/mrns").setValue("100"); patient.addName().setFamily("Tester").addGiven("Raghad"); - MethodOutcome output2 = ourClient.update().resource(patient).conditionalByUrl("Patient?identifier=http://uhn.ca/mrns|100").execute(); + MethodOutcome output2 = myClient.update().resource(patient).conditionalByUrl("Patient?identifier=http://uhn.ca/mrns|100").execute(); assertEquals(output1.getId().getIdPart(), output2.getId().getIdPart()); } @@ -993,7 +966,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { interceptor.setFailOnSeverity(null); ourRestServer.registerInterceptor(interceptor); - ourClient.registerInterceptor(new IClientInterceptor() { + myClient.registerInterceptor(new IClientInterceptor() { @Override public void interceptRequest(IHttpRequest theRequest) { theRequest.addHeader(Constants.HEADER_PREFER, Constants.HEADER_PREFER_RETURN + "=" + Constants.HEADER_PREFER_RETURN_OPERATION_OUTCOME); @@ -1008,7 +981,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { // Missing status, which is mandatory Observation obs = new Observation(); obs.addIdentifier().setSystem("urn:foo").setValue("bar"); - IBaseResource outcome = ourClient.create().resource(obs).execute().getOperationOutcome(); + IBaseResource outcome = myClient.create().resource(obs).execute().getOperationOutcome(); String encodedOo = myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(outcome); ourLog.info(encodedOo); @@ -1016,7 +989,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { assertThat(encodedOo, containsString("Successfully created resource \\\"Observation/")); interceptor.setAddValidationResultsToResponseOperationOutcome(false); - outcome = ourClient.create().resource(obs).execute().getOperationOutcome(); + outcome = myClient.create().resource(obs).execute().getOperationOutcome(); encodedOo = myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(outcome); ourLog.info(encodedOo); assertThat(encodedOo, not(containsString("cvc-complex-type.2.4.b"))); @@ -1028,20 +1001,20 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { } @Test - @Ignore + @Disabled public void testCreateQuestionnaireResponseWithValidation() { CodeSystem cs = new CodeSystem(); cs.setUrl("http://urn/system"); cs.addConcept().setCode("code0"); - ourClient.create().resource(cs).execute(); + myClient.create().resource(cs).execute(); ValueSet options = new ValueSet(); options.getCompose().addInclude().setSystem("http://urn/system"); - IIdType optId = ourClient.create().resource(options).execute().getId(); + IIdType optId = myClient.create().resource(options).execute().getId(); Questionnaire q = new Questionnaire(); q.addItem().setLinkId("link0").setRequired(false).setType(QuestionnaireItemType.CHOICE).setAnswerValueSet((optId.getValue())); - IIdType qId = ourClient.create().resource(q).execute().getId(); + IIdType qId = myClient.create().resource(q).execute().getId(); QuestionnaireResponse qa; @@ -1050,7 +1023,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { qa = new QuestionnaireResponse(); qa.setQuestionnaire(qId.toUnqualifiedVersionless().getValue()); qa.addItem().setLinkId("link0").addAnswer().setValue(new Coding().setSystem("urn:system").setCode("code0")); - ourClient.create().resource(qa).execute(); + myClient.create().resource(qa).execute(); // Bad code @@ -1058,7 +1031,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { qa.setQuestionnaire(qId.toUnqualifiedVersionless().getValue()); qa.addItem().setLinkId("link0").addAnswer().setValue(new Coding().setSystem("urn:system").setCode("code1")); try { - ourClient.create().resource(qa).execute(); + myClient.create().resource(qa).execute(); fail(); } catch (UnprocessableEntityException e) { assertThat(e.getMessage(), containsString("Question with linkId[link0]")); @@ -1071,7 +1044,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { Patient patient = new Patient(); patient.addName().setFamily("FooName"); - IIdType patientId = ourClient.create().resource(patient).execute().getId(); + IIdType patientId = myClient.create().resource(patient).execute().getId(); //Reference patientReference = new Reference("Patient/" + patientId.getIdPart()); <--- this works Reference patientReference = new Reference(patientId); // <--- this is seen as an external reference @@ -1081,10 +1054,10 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { attachment.setLanguage("ENG"); media.setContent(attachment); media.setSubject(patientReference); - IIdType mediaId = ourClient.create().resource(media).execute().getId(); + IIdType mediaId = myClient.create().resource(media).execute().getId(); // Search for wrong type - Bundle returnedBundle = ourClient.search() + Bundle returnedBundle = myClient.search() .forResource(Observation.class) .where(Observation.ENCOUNTER.hasId(patientReference.getReference())) .returnBundle(Bundle.class) @@ -1092,7 +1065,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { assertEquals(0, returnedBundle.getEntry().size()); // Search for right type - returnedBundle = ourClient.search() + returnedBundle = myClient.search() .forResource(Media.class) .where(Media.SUBJECT.hasId(patientReference.getReference())) .returnBundle(Bundle.class) @@ -1251,7 +1224,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { p.addName().setFamily(methodName); p.setId(methodName); - IIdType optId = ourClient.update().resource(p).execute().getId(); + IIdType optId = myClient.update().resource(p).execute().getId(); assertEquals(methodName, optId.getIdPart()); assertEquals("1", optId.getVersionIdPart()); } @@ -1260,12 +1233,12 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { public void testDeepChaining() { Location l1 = new Location(); l1.getNameElement().setValue("testDeepChainingL1"); - IIdType l1id = ourClient.create().resource(l1).execute().getId(); + IIdType l1id = myClient.create().resource(l1).execute().getId(); Location l2 = new Location(); l2.getNameElement().setValue("testDeepChainingL2"); l2.getPartOf().setReferenceElement(l1id.toVersionless().toUnqualified()); - IIdType l2id = ourClient.create().resource(l2).execute().getId(); + IIdType l2id = myClient.create().resource(l2).execute().getId(); Encounter e1 = new Encounter(); e1.addIdentifier().setSystem("urn:foo").setValue("testDeepChainingE1"); @@ -1273,9 +1246,9 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { EncounterLocationComponent location = e1.addLocation(); location.getLocation().setReferenceElement(l2id.toUnqualifiedVersionless()); location.setPeriod(new Period().setStart(new Date(), TemporalPrecisionEnum.SECOND).setEnd(new Date(), TemporalPrecisionEnum.SECOND)); - IIdType e1id = ourClient.create().resource(e1).execute().getId(); + IIdType e1id = myClient.create().resource(e1).execute().getId(); - Bundle res = ourClient.search() + Bundle res = myClient.search() .forResource(Encounter.class) .where(Encounter.IDENTIFIER.exactly().systemAndCode("urn:foo", "testDeepChainingE1")) .include(Encounter.INCLUDE_LOCATION.asRecursive()) @@ -1295,15 +1268,15 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { public void testReferenceOfWrongType() { Group l2 = new Group(); l2.setActive(true); - IIdType l2id = ourClient.create().resource(l2).execute().getId(); + IIdType l2id = myClient.create().resource(l2).execute().getId(); Encounter e1 = new Encounter(); e1.getStatusElement().setValue(EncounterStatus.INPROGRESS); e1.getSubject().setReference(l2id.toUnqualifiedVersionless().getValue()); - IIdType e1id = ourClient.create().resource(e1).execute().getId(); + IIdType e1id = myClient.create().resource(e1).execute().getId(); // Wrong type - Bundle res = ourClient.search() + Bundle res = myClient.search() .forResource(Encounter.class) .include(Encounter.INCLUDE_PATIENT.asRecursive()) .returnBundle(Bundle.class) @@ -1316,7 +1289,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { assertEquals(e1id.toUnqualifiedVersionless(), genResourcesOfType(res, Encounter.class).get(0).getIdElement().toUnqualifiedVersionless()); // Right type - res = ourClient.search() + res = myClient.search() .forResource(Encounter.class) .include(Encounter.INCLUDE_SUBJECT.asRecursive()) .returnBundle(Bundle.class) @@ -1348,7 +1321,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { try { //@formatter:off - ourClient + myClient .delete() .resourceConditionalByType(Patient.class) .where(Patient.IDENTIFIER.exactly().code(methodName)) @@ -1361,12 +1334,12 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { } // Not deleted yet.. - ourClient.read().resource("Patient").withId(id1).execute(); - ourClient.read().resource("Patient").withId(id2).execute(); + myClient.read().resource("Patient").withId(id1).execute(); + myClient.read().resource("Patient").withId(id2).execute(); myDaoConfig.setAllowMultipleDelete(true); - MethodOutcome response = ourClient + MethodOutcome response = myClient .delete() .resourceConditionalByType(Patient.class) .where(Patient.IDENTIFIER.exactly().code(methodName)) @@ -1377,13 +1350,13 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { assertThat(encoded, containsString( " ids = toUnqualifiedVersionlessIds(b); assertThat(ids, containsInAnyOrder(patientId, encId, orgId1, orgId2, orgId1parent, locPId, locCId, obsId, devId)); @@ -1731,52 +1704,52 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { Organization org1parent = new Organization(); org1parent.setId("org1parent"); org1parent.setName(methodName + "1parent"); - IIdType orgId1parent = ourClient.update().resource(org1parent).execute().getId().toUnqualifiedVersionless(); + IIdType orgId1parent = myClient.update().resource(org1parent).execute().getId().toUnqualifiedVersionless(); Organization org1 = new Organization(); org1.setName(methodName + "1"); org1.getPartOf().setReferenceElement(orgId1parent); - IIdType orgId1 = ourClient.create().resource(org1).execute().getId().toUnqualifiedVersionless(); + IIdType orgId1 = myClient.create().resource(org1).execute().getId().toUnqualifiedVersionless(); Patient p = new Patient(); p.addName().setFamily(methodName); p.getManagingOrganization().setReferenceElement(orgId1); - IIdType patientId = ourClient.create().resource(p).execute().getId().toUnqualifiedVersionless(); + IIdType patientId = myClient.create().resource(p).execute().getId().toUnqualifiedVersionless(); Organization org2 = new Organization(); org2.setName(methodName + "1"); - IIdType orgId2 = ourClient.create().resource(org2).execute().getId().toUnqualifiedVersionless(); + IIdType orgId2 = myClient.create().resource(org2).execute().getId().toUnqualifiedVersionless(); Device dev = new Device(); dev.setManufacturer(methodName); dev.getOwner().setReferenceElement(orgId2); - IIdType devId = ourClient.create().resource(dev).execute().getId().toUnqualifiedVersionless(); + IIdType devId = myClient.create().resource(dev).execute().getId().toUnqualifiedVersionless(); Location locParent = new Location(); locParent.setName(methodName + "Parent"); - IIdType locPId = ourClient.create().resource(locParent).execute().getId().toUnqualifiedVersionless(); + IIdType locPId = myClient.create().resource(locParent).execute().getId().toUnqualifiedVersionless(); Location locChild = new Location(); locChild.setName(methodName); locChild.getPartOf().setReferenceElement(locPId); - IIdType locCId = ourClient.create().resource(locChild).execute().getId().toUnqualifiedVersionless(); + IIdType locCId = myClient.create().resource(locChild).execute().getId().toUnqualifiedVersionless(); Encounter encU = new Encounter(); encU.addIdentifier().setValue(methodName); - IIdType encUId = ourClient.create().resource(encU).execute().getId().toUnqualifiedVersionless(); + IIdType encUId = myClient.create().resource(encU).execute().getId().toUnqualifiedVersionless(); Encounter enc = new Encounter(); enc.getSubject().setReferenceElement(patientId); enc.addLocation().getLocation().setReferenceElement(locCId); - IIdType encId = ourClient.create().resource(enc).execute().getId().toUnqualifiedVersionless(); + IIdType encId = myClient.create().resource(enc).execute().getId().toUnqualifiedVersionless(); Observation obs = new Observation(); obs.getSubject().setReferenceElement(patientId); obs.getDevice().setReferenceElement(devId); obs.getEncounter().setReferenceElement(encId); - IIdType obsId = ourClient.create().resource(obs).execute().getId().toUnqualifiedVersionless(); + IIdType obsId = myClient.create().resource(obs).execute().getId().toUnqualifiedVersionless(); - Parameters output = ourClient.operation().onType(Encounter.class).named("everything").withNoParameters(Parameters.class).execute(); + Parameters output = myClient.operation().onType(Encounter.class).named("everything").withNoParameters(Parameters.class).execute(); Bundle b = (Bundle) output.getParameter().get(0).getResource(); List ids = toUnqualifiedVersionlessIds(b); assertThat(ids, containsInAnyOrder(patientId, encUId, encId, orgId1, orgId2, orgId1parent, locPId, locCId, obsId, devId)); @@ -1831,7 +1804,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { param.addAnd(new StringOrListParam().addOr(new StringParam("obsvalue1"))); //@formatter:off - Parameters response = ourClient + Parameters response = myClient .operation() .onInstance(ptId1) .named("everything") @@ -1853,7 +1826,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { IParser parser = myFhirCtx.newJsonParser(); b = parser.parseResource(Bundle.class, new InputStreamReader(ResourceProviderR4Test.class.getResourceAsStream("/r4/bug147-bundle.json"))); - Bundle resp = ourClient.transaction().withBundle(b).execute(); + Bundle resp = myClient.transaction().withBundle(b).execute(); List ids = new ArrayList<>(); for (BundleEntryComponent next : resp.getEntry()) { IdType toAdd = new IdType(next.getResponse().getLocation()).toUnqualifiedVersionless(); @@ -1865,7 +1838,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { assertEquals("Patient", patientId.getResourceType()); { - Parameters output = ourClient.operation().onInstance(patientId).named("everything").withNoParameters(Parameters.class).execute(); + Parameters output = myClient.operation().onInstance(patientId).named("everything").withNoParameters(Parameters.class).execute(); b = (Bundle) output.getParameter().get(0).getResource(); ids = new ArrayList<>(); @@ -1877,7 +1850,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { } ourLog.info("$everything: " + ids.toString()); - assertFalse(ids.toString(), dupes); + assertFalse(dupes, ids.toString()); } /* @@ -1886,7 +1859,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { { Parameters input = new Parameters(); input.addParameter().setName(Constants.PARAM_COUNT).setValue(new UnsignedIntType(100)); - Parameters output = ourClient.operation().onInstance(patientId).named("everything").withParameters(input).execute(); + Parameters output = myClient.operation().onInstance(patientId).named("everything").withParameters(input).execute(); b = (Bundle) output.getParameter().get(0).getResource(); ids = new ArrayList<>(); @@ -1898,7 +1871,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { } ourLog.info("$everything: " + ids.toString()); - assertFalse(ids.toString(), dupes); + assertFalse(dupes, ids.toString()); assertThat(ids.toString(), containsString("Condition")); assertThat(ids.size(), greaterThan(10)); } @@ -1924,7 +1897,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { mo.setMedication(new Reference(medId)); IIdType moId = myMedicationRequestDao.create(mo, mySrd).getId().toUnqualifiedVersionless(); - Parameters output = ourClient.operation().onInstance(patId).named("everything").withNoParameters(Parameters.class).execute(); + Parameters output = myClient.operation().onInstance(patId).named("everything").withNoParameters(Parameters.class).execute(); Bundle b = (Bundle) output.getParameter().get(0).getResource(); List ids = toUnqualifiedVersionlessIds(b); ourLog.info(ids.toString()); @@ -1945,14 +1918,14 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { c.getSubject().setReference("Patient/1"); b.addEntry().setResource(c).getRequest().setMethod(HTTPVerb.POST); - Bundle resp = ourClient.transaction().withBundle(b).execute(); + Bundle resp = myClient.transaction().withBundle(b).execute(); ourLog.info(myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(resp)); IdType patientId = new IdType(resp.getEntry().get(0).getResponse().getLocation()); assertEquals("Patient", patientId.getResourceType()); - Parameters output = ourClient.operation().onInstance(patientId).named("everything").withNoParameters(Parameters.class).execute(); + Parameters output = myClient.operation().onInstance(patientId).named("everything").withNoParameters(Parameters.class).execute(); b = (Bundle) output.getParameter().get(0).getResource(); List ids = new ArrayList<>(); @@ -1973,37 +1946,37 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { Organization org1parent = new Organization(); org1parent.setId("org1parent"); org1parent.setName(methodName + "1parent"); - IIdType orgId1parent = ourClient.update().resource(org1parent).execute().getId().toUnqualifiedVersionless(); + IIdType orgId1parent = myClient.update().resource(org1parent).execute().getId().toUnqualifiedVersionless(); Organization org1 = new Organization(); org1.setName(methodName + "1"); org1.getPartOf().setReferenceElement(orgId1parent); - IIdType orgId1 = ourClient.create().resource(org1).execute().getId().toUnqualifiedVersionless(); + IIdType orgId1 = myClient.create().resource(org1).execute().getId().toUnqualifiedVersionless(); Patient p = new Patient(); p.addName().setFamily(methodName); p.getManagingOrganization().setReferenceElement(orgId1); - IIdType patientId = ourClient.create().resource(p).execute().getId().toUnqualifiedVersionless(); + IIdType patientId = myClient.create().resource(p).execute().getId().toUnqualifiedVersionless(); Organization org2 = new Organization(); org2.setName(methodName + "1"); - IIdType orgId2 = ourClient.create().resource(org2).execute().getId().toUnqualifiedVersionless(); + IIdType orgId2 = myClient.create().resource(org2).execute().getId().toUnqualifiedVersionless(); Device dev = new Device(); dev.setManufacturer(methodName); dev.getOwner().setReferenceElement(orgId2); - IIdType devId = ourClient.create().resource(dev).execute().getId().toUnqualifiedVersionless(); + IIdType devId = myClient.create().resource(dev).execute().getId().toUnqualifiedVersionless(); Observation obs = new Observation(); obs.getSubject().setReferenceElement(patientId); obs.getDevice().setReferenceElement(devId); - IIdType obsId = ourClient.create().resource(obs).execute().getId().toUnqualifiedVersionless(); + IIdType obsId = myClient.create().resource(obs).execute().getId().toUnqualifiedVersionless(); Encounter enc = new Encounter(); enc.getSubject().setReferenceElement(patientId); - IIdType encId = ourClient.create().resource(enc).execute().getId().toUnqualifiedVersionless(); + IIdType encId = myClient.create().resource(enc).execute().getId().toUnqualifiedVersionless(); - Parameters output = ourClient.operation().onInstance(patientId).named("everything").withNoParameters(Parameters.class).execute(); + Parameters output = myClient.operation().onInstance(patientId).named("everything").withNoParameters(Parameters.class).execute(); Bundle b = (Bundle) output.getParameter().get(0).getResource(); List ids = toUnqualifiedVersionlessIds(b); assertThat(ids, containsInAnyOrder(patientId, devId, obsId, encId, orgId1, orgId2, orgId1parent)); @@ -2017,32 +1990,32 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { Organization o1 = new Organization(); o1.setName(methodName + "1"); - IIdType o1Id = ourClient.create().resource(o1).execute().getId().toUnqualifiedVersionless(); + IIdType o1Id = myClient.create().resource(o1).execute().getId().toUnqualifiedVersionless(); Organization o2 = new Organization(); o2.setName(methodName + "2"); - IIdType o2Id = ourClient.create().resource(o2).execute().getId().toUnqualifiedVersionless(); + IIdType o2Id = myClient.create().resource(o2).execute().getId().toUnqualifiedVersionless(); Patient p1 = new Patient(); p1.addName().setFamily(methodName + "1"); p1.getManagingOrganization().setReferenceElement(o1Id); - IIdType p1Id = ourClient.create().resource(p1).execute().getId().toUnqualifiedVersionless(); + IIdType p1Id = myClient.create().resource(p1).execute().getId().toUnqualifiedVersionless(); Patient p2 = new Patient(); p2.addName().setFamily(methodName + "2"); p2.getManagingOrganization().setReferenceElement(o2Id); - IIdType p2Id = ourClient.create().resource(p2).execute().getId().toUnqualifiedVersionless(); + IIdType p2Id = myClient.create().resource(p2).execute().getId().toUnqualifiedVersionless(); Condition c1 = new Condition(); c1.getSubject().setReferenceElement(p1Id); - IIdType c1Id = ourClient.create().resource(c1).execute().getId().toUnqualifiedVersionless(); + IIdType c1Id = myClient.create().resource(c1).execute().getId().toUnqualifiedVersionless(); Condition c2 = new Condition(); c2.getSubject().setReferenceElement(p2Id); - IIdType c2Id = ourClient.create().resource(c2).execute().getId().toUnqualifiedVersionless(); + IIdType c2Id = myClient.create().resource(c2).execute().getId().toUnqualifiedVersionless(); Condition c3 = new Condition(); c3.addIdentifier().setValue(methodName + "3"); - IIdType c3Id = ourClient.create().resource(c3).execute().getId().toUnqualifiedVersionless(); + IIdType c3Id = myClient.create().resource(c3).execute().getId().toUnqualifiedVersionless(); - Parameters output = ourClient.operation().onType(Patient.class).named("everything").withNoParameters(Parameters.class).execute(); + Parameters output = myClient.operation().onType(Patient.class).named("everything").withNoParameters(Parameters.class).execute(); Bundle b = (Bundle) output.getParameter().get(0).getResource(); assertEquals(BundleType.SEARCHSET, b.getType()); @@ -2059,7 +2032,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { Organization org = new Organization(); org.setName(methodName); - IIdType oId = ourClient.create().resource(org).execute().getId().toUnqualifiedVersionless(); + IIdType oId = myClient.create().resource(org).execute().getId().toUnqualifiedVersionless(); long time1 = System.currentTimeMillis(); Thread.sleep(10); @@ -2067,7 +2040,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { Patient p = new Patient(); p.addName().setFamily(methodName); p.getManagingOrganization().setReferenceElement(oId); - IIdType pId = ourClient.create().resource(p).execute().getId().toUnqualifiedVersionless(); + IIdType pId = myClient.create().resource(p).execute().getId().toUnqualifiedVersionless(); long time2 = System.currentTimeMillis(); Thread.sleep(10); @@ -2075,7 +2048,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { Condition c = new Condition(); c.getCode().setText(methodName); c.getSubject().setReferenceElement(pId); - IIdType cId = ourClient.create().resource(c).execute().getId().toUnqualifiedVersionless(); + IIdType cId = myClient.create().resource(c).execute().getId().toUnqualifiedVersionless(); Thread.sleep(10); long time3 = System.currentTimeMillis(); @@ -2150,7 +2123,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { * Per message from David Hay on Skype */ @Test - @Ignore + @Disabled public void testEverythingWithLargeSet() throws Exception { String inputString = IOUtils.toString(getClass().getResourceAsStream("/david_big_bundle.json"), StandardCharsets.UTF_8); @@ -2170,7 +2143,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { mySystemDao.transaction(mySrd, inputBundle); - Bundle responseBundle = ourClient + Bundle responseBundle = myClient .operation() .onInstance(new IdType("Patient/A161443")) .named("everything") @@ -2198,7 +2171,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { } String nextUrl = responseBundle.getLink("next").getUrl(); - responseBundle = ourClient.fetchResourceFromUrl(Bundle.class, nextUrl); + responseBundle = myClient.fetchResourceFromUrl(Bundle.class, nextUrl); for (int i = 0; i < responseBundle.getEntry().size(); i++) { for (BundleEntryComponent nextEntry : responseBundle.getEntry()) { idsSet.add(nextEntry.getResource().getIdElement().toUnqualifiedVersionless().getValue()); @@ -2206,7 +2179,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { } nextUrl = responseBundle.getLink("next").getUrl(); - responseBundle = ourClient.fetchResourceFromUrl(Bundle.class, nextUrl); + responseBundle = myClient.fetchResourceFromUrl(Bundle.class, nextUrl); for (int i = 0; i < responseBundle.getEntry().size(); i++) { for (BundleEntryComponent nextEntry : responseBundle.getEntry()) { idsSet.add(nextEntry.getResource().getIdElement().toUnqualifiedVersionless().getValue()); @@ -2236,16 +2209,16 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { Patient p = new Patient(); p.setActive(true); - IIdType id = ourClient.create().resource(p).execute().getId().toUnqualifiedVersionless(); + IIdType id = myClient.create().resource(p).execute().getId().toUnqualifiedVersionless(); for (int i = 1; i < LARGE_NUMBER; i++) { Observation obs = new Observation(); obs.setId("A" + StringUtils.leftPad(Integer.toString(i), 2, '0')); obs.setSubject(new Reference(id)); - ourClient.update().resource(obs).execute(); + myClient.update().resource(obs).execute(); } - Bundle responseBundle = ourClient + Bundle responseBundle = myClient .operation() .onInstance(id) .named("everything") @@ -2265,7 +2238,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { while (nextLink != null) { String nextUrl = nextLink.getUrl(); - responseBundle = ourClient.fetchResourceFromUrl(Bundle.class, nextUrl); + responseBundle = myClient.fetchResourceFromUrl(Bundle.class, nextUrl); for (int i = 0; i < responseBundle.getEntry().size(); i++) { BundleEntryComponent nextEntry = responseBundle.getEntry().get(i); ids.add(nextEntry.getResource().getIdElement().getIdPart()); @@ -2288,11 +2261,11 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { public void testEverythingWithOnlyPatient() { Patient p = new Patient(); p.setActive(true); - IIdType id = ourClient.create().resource(p).execute().getId().toUnqualifiedVersionless(); + IIdType id = myClient.create().resource(p).execute().getId().toUnqualifiedVersionless(); myFhirCtx.getRestfulClientFactory().setSocketTimeout(300 * 1000); - Bundle response = ourClient + Bundle response = myClient .operation() .onInstance(id) .named("everything") @@ -2420,18 +2393,18 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { Patient p = new Patient(); p.setId("FOO"); p.addName().setFamily("FAMILY"); - ourClient.update().resource(p).execute(); + myClient.update().resource(p).execute(); p = new Patient(); p.setId("BAR"); p.addName().setFamily("HELLO"); - ourClient.update().resource(p).execute(); + myClient.update().resource(p).execute(); Observation o = new Observation(); o.setId("BAZ"); o.getSubject().setReference("Patient/FOO"); o.getCode().setText("GOODBYE"); - ourClient.update().resource(o).execute(); + myClient.update().resource(o).execute(); List ids = searchAndReturnUnqualifiedVersionlessIdValues(ourServerBase + "/Patient/FOO/$everything?_content=White"); assertThat(ids, contains("Patient/FOO")); @@ -2448,18 +2421,18 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { Patient p = new Patient(); p.setId("FOO"); p.addName().setFamily("FAMILY"); - ourClient.update().resource(p).execute(); + myClient.update().resource(p).execute(); p = new Patient(); p.setId("BAR"); p.addName().setFamily("HELLO"); - ourClient.update().resource(p).execute(); + myClient.update().resource(p).execute(); Observation o = new Observation(); o.setId("BAZ"); o.getSubject().setReference("Patient/FOO"); o.getCode().setText("GOODBYE"); - ourClient.update().resource(o).execute(); + myClient.update().resource(o).execute(); List ids = searchAndReturnUnqualifiedVersionlessIdValues(ourServerBase + "/Patient?_id=FOO&_content=family"); assertThat(ids, contains("Patient/FOO")); @@ -2474,7 +2447,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { Patient pt = new Patient(); pt.addName().setFamily(methodName); - ourClient.create().resource(pt).execute().getId().toUnqualifiedVersionless(); + myClient.create().resource(pt).execute().getId().toUnqualifiedVersionless(); myResourceCountsCache.clear(); myResourceCountsCache.update(); @@ -2588,14 +2561,14 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { Patient patient = new Patient(); patient.addName().setFamily(methodName); - IIdType id = ourClient.create().resource(patient).execute().getId().toVersionless(); - ourClient.delete().resourceById(id).execute(); + IIdType id = myClient.create().resource(patient).execute().getId().toVersionless(); + myClient.delete().resourceById(id).execute(); patient.setId(id); - ourClient.update().resource(patient).execute(); + myClient.update().resource(patient).execute(); ourLog.info("Res ID: {}", id); - Bundle history = ourClient.history().onInstance(id.getValue()).andReturnBundle(Bundle.class).prettyPrint().summaryMode(SummaryEnum.DATA).execute(); + Bundle history = myClient.history().onInstance(id.getValue()).andReturnBundle(Bundle.class).prettyPrint().summaryMode(SummaryEnum.DATA).execute(); assertEquals(3, history.getEntry().size()); assertEquals(id.withVersion("3").getValue(), history.getEntry().get(0).getResource().getId()); assertEquals(1, ((Patient) history.getEntry().get(0).getResource()).getName().size()); @@ -2736,7 +2709,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { */ @Test public void testImagingStudyResources() throws Exception { - IGenericClient client = ourClient; + IGenericClient client = myClient; int initialSize = client.search().forResource(ImagingStudy.class).returnBundle(Bundle.class).execute().getEntry().size(); @@ -2765,7 +2738,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { myPatientDao.create(pt); } - Bundle bundle = ourClient + Bundle bundle = myClient .search() .forResource(Patient.class) .include(Patient.INCLUDE_ORGANIZATION) @@ -2788,9 +2761,9 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { Patient p = new Patient(); p.getManagingOrganization().setReference("http://example.com/Organization/123"); - ourClient.create().resource(p).execute(); + myClient.create().resource(p).execute(); - Bundle b = ourClient.search().forResource("Patient").include(Patient.INCLUDE_ORGANIZATION).returnBundle(Bundle.class).execute(); + Bundle b = myClient.search().forResource("Patient").include(Patient.INCLUDE_ORGANIZATION).returnBundle(Bundle.class).execute(); assertEquals(1, b.getEntry().size()); } @@ -2798,7 +2771,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { public void testMetaOperationWithNoMetaParameter() throws Exception { Patient p = new Patient(); p.addName().setFamily("testMetaAddInvalid"); - IIdType id = ourClient.create().resource(p).execute().getId().toUnqualifiedVersionless(); + IIdType id = myClient.create().resource(p).execute().getId().toUnqualifiedVersionless(); //@formatter:off String input = "\n" + @@ -2844,19 +2817,19 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { Patient pt = new Patient(); pt.addName().setFamily(methodName); - IIdType id = ourClient.create().resource(pt).execute().getId().toUnqualifiedVersionless(); + IIdType id = myClient.create().resource(pt).execute().getId().toUnqualifiedVersionless(); - Meta meta = ourClient.meta().get(Meta.class).fromResource(id).execute(); + Meta meta = myClient.meta().get(Meta.class).fromResource(id).execute(); assertEquals(0, meta.getTag().size()); Meta inMeta = new Meta(); inMeta.addTag().setSystem("urn:system1").setCode("urn:code1"); - meta = ourClient.meta().add().onResource(id).meta(inMeta).execute(); + meta = myClient.meta().add().onResource(id).meta(inMeta).execute(); assertEquals(1, meta.getTag().size()); inMeta = new Meta(); inMeta.addTag().setSystem("urn:system1").setCode("urn:code1"); - meta = ourClient.meta().delete().onResource(id).meta(inMeta).execute(); + meta = myClient.meta().delete().onResource(id).meta(inMeta).execute(); assertEquals(0, meta.getTag().size()); } @@ -2878,9 +2851,9 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { StructureDefinition p = new StructureDefinition(); p.setAbstract(true); p.setUrl("http://example.com/foo"); - IIdType id = ourClient.create().resource(p).execute().getId().toUnqualifiedVersionless(); + IIdType id = myClient.create().resource(p).execute().getId().toUnqualifiedVersionless(); - Bundle resp = ourClient + Bundle resp = myClient .search() .forResource(StructureDefinition.class) .where(StructureDefinition.URL.matches().value("http://example.com/foo")) @@ -2907,7 +2880,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { mySearchCoordinatorSvcRaw.setSyncSizeForUnitTests(10); mySearchCoordinatorSvcRaw.setNeverUseLocalSearchForUnitTests(true); - Bundle response = ourClient + Bundle response = myClient .operation() .onInstance(new IdType(pid)) .named("everything") @@ -2925,7 +2898,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { // Load page 2 String nextUrl = response.getLink("next").getUrl(); - response = ourClient.fetchResourceFromUrl(Bundle.class, nextUrl); + response = myClient.fetchResourceFromUrl(Bundle.class, nextUrl); assertEquals(10, response.getEntry().size()); if (response.getTotalElement().getValueAsString() != null) { @@ -2937,7 +2910,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { Thread.sleep(2000); nextUrl = response.getLink("next").getUrl(); - response = ourClient.fetchResourceFromUrl(Bundle.class, nextUrl); + response = myClient.fetchResourceFromUrl(Bundle.class, nextUrl); assertEquals(1, response.getEntry().size()); assertEquals("21", response.getTotalElement().getValueAsString()); @@ -2964,7 +2937,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { mySearchCoordinatorSvcRaw.setSyncSizeForUnitTests(10); mySearchCoordinatorSvcRaw.setNeverUseLocalSearchForUnitTests(true); - Bundle response = ourClient + Bundle response = myClient .operation() .onInstance(new IdType(pid)) .named("everything") @@ -3050,7 +3023,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { assertThat(responseString, containsString("INFORMATION")); } - Patient newPt = ourClient.read().resource(Patient.class).withId(pid1.getIdPart()).execute(); + Patient newPt = myClient.read().resource(Patient.class).withId(pid1.getIdPart()).execute(); assertEquals("2", newPt.getIdElement().getVersionIdPart()); assertEquals(false, newPt.getActive()); } @@ -3078,7 +3051,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { assertThat(responseString, containsString("")); } - Patient newPt = ourClient.read().resource(Patient.class).withId(pid1.getIdPart()).execute(); + Patient newPt = myClient.read().resource(Patient.class).withId(pid1.getIdPart()).execute(); assertEquals("1", newPt.getIdElement().getVersionIdPart()); assertEquals(true, newPt.getActive()); } @@ -3107,7 +3080,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { assertThat(responseString, containsString("INFORMATION")); } - Patient newPt = ourClient.read().resource(Patient.class).withId(pid1.getIdPart()).execute(); + Patient newPt = myClient.read().resource(Patient.class).withId(pid1.getIdPart()).execute(); assertEquals("2", newPt.getIdElement().getVersionIdPart()); assertEquals(false, newPt.getActive()); } @@ -3136,7 +3109,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { assertThat(responseString, containsString("INFORMATION")); } - Patient newPt = ourClient.read().resource(Patient.class).withId(pid1.getIdPart()).execute(); + Patient newPt = myClient.read().resource(Patient.class).withId(pid1.getIdPart()).execute(); assertEquals("2", newPt.getIdElement().getVersionIdPart()); assertEquals(false, newPt.getActive()); } @@ -3145,25 +3118,25 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { public void testPreserveVersionsOnAuditEvent() { Organization org = new Organization(); org.setName("ORG"); - IIdType orgId = ourClient.create().resource(org).execute().getId(); + IIdType orgId = myClient.create().resource(org).execute().getId(); assertEquals("1", orgId.getVersionIdPart()); Patient patient = new Patient(); patient.addIdentifier().setSystem("http://uhn.ca/mrns").setValue("100"); patient.getManagingOrganization().setReference(orgId.toUnqualified().getValue()); - IIdType patientId = ourClient.create().resource(patient).execute().getId(); + IIdType patientId = myClient.create().resource(patient).execute().getId(); assertEquals("1", patientId.getVersionIdPart()); AuditEvent ae = new org.hl7.fhir.r4.model.AuditEvent(); ae.addEntity().getWhat().setReference(patientId.toUnqualified().getValue()); - IIdType aeId = ourClient.create().resource(ae).execute().getId(); + IIdType aeId = myClient.create().resource(ae).execute().getId(); assertEquals("1", aeId.getVersionIdPart()); - patient = ourClient.read().resource(Patient.class).withId(patientId).execute(); + patient = myClient.read().resource(Patient.class).withId(patientId).execute(); assertTrue(patient.getManagingOrganization().getReferenceElement().hasIdPart()); assertFalse(patient.getManagingOrganization().getReferenceElement().hasVersionIdPart()); - ae = ourClient.read().resource(AuditEvent.class).withId(aeId).execute(); + ae = myClient.read().resource(AuditEvent.class).withId(aeId).execute(); assertTrue(ae.getEntityFirstRep().getWhat().getReferenceElement().hasIdPart()); assertTrue(ae.getEntityFirstRep().getWhat().getReferenceElement().hasVersionIdPart()); @@ -3174,7 +3147,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { */ @Test public void testProcedureRequestResources() { - IGenericClient client = ourClient; + IGenericClient client = myClient; int initialSize = client.search().forResource(ServiceRequest.class).returnBundle(Bundle.class).execute().getEntry().size(); @@ -3198,19 +3171,19 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { pat = new Patient(); pat.addIdentifier().setSystem("urn:system").setValue("testReadAllInstancesOfType_01"); - ourClient.create().resource(pat).prettyPrint().encodedXml().execute(); + myClient.create().resource(pat).prettyPrint().encodedXml().execute(); pat = new Patient(); pat.addIdentifier().setSystem("urn:system").setValue("testReadAllInstancesOfType_02"); - ourClient.create().resource(pat).prettyPrint().encodedXml().execute(); + myClient.create().resource(pat).prettyPrint().encodedXml().execute(); { - Bundle returned = ourClient.search().forResource(Patient.class).encodedXml().returnBundle(Bundle.class).execute(); + Bundle returned = myClient.search().forResource(Patient.class).encodedXml().returnBundle(Bundle.class).execute(); assertThat(returned.getEntry().size(), greaterThan(1)); assertEquals(BundleType.SEARCHSET, returned.getType()); } { - Bundle returned = ourClient.search().forResource(Patient.class).encodedJson().returnBundle(Bundle.class).execute(); + Bundle returned = myClient.search().forResource(Patient.class).encodedJson().returnBundle(Bundle.class).execute(); assertThat(returned.getEntry().size(), greaterThan(1)); } } @@ -3219,11 +3192,11 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { public void testRetrieveMissingVersionsDoesntCrashHistory() { Patient p1 = new Patient(); p1.setActive(true); - final IIdType id1 = ourClient.create().resource(p1).execute().getId(); + final IIdType id1 = myClient.create().resource(p1).execute().getId(); Patient p2 = new Patient(); p2.setActive(false); - IIdType id2 = ourClient.create().resource(p2).execute().getId(); + IIdType id2 = myClient.create().resource(p2).execute().getId(); new TransactionTemplate(myTxManager).execute(new TransactionCallbackWithoutResult() { @Override @@ -3233,7 +3206,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { } }); - Bundle bundle = ourClient.history().onServer().andReturnBundle(Bundle.class).execute(); + Bundle bundle = myClient.history().onServer().andReturnBundle(Bundle.class).execute(); assertEquals(1, bundle.getTotal()); assertEquals(1, bundle.getEntry().size()); assertEquals(id2.getIdPart(), bundle.getEntry().get(0).getResource().getIdElement().getIdPart()); @@ -3243,11 +3216,11 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { public void testRetrieveMissingVersionsDoesntCrashSearch() { Patient p1 = new Patient(); p1.setActive(true); - final IIdType id1 = ourClient.create().resource(p1).execute().getId(); + final IIdType id1 = myClient.create().resource(p1).execute().getId(); Patient p2 = new Patient(); p2.setActive(false); - IIdType id2 = ourClient.create().resource(p2).execute().getId(); + IIdType id2 = myClient.create().resource(p2).execute().getId(); myCaptureQueriesListener.clear(); new TransactionTemplate(myTxManager).execute(new TransactionCallbackWithoutResult() { @@ -3259,7 +3232,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { }); myCaptureQueriesListener.logAllQueriesForCurrentThread(); - Bundle bundle = ourClient.search().forResource("Patient").returnBundle(Bundle.class).execute(); + Bundle bundle = myClient.search().forResource("Patient").returnBundle(Bundle.class).execute(); ourLog.info("Result: {}", myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(bundle)); assertEquals(2, bundle.getTotal()); assertEquals(1, bundle.getEntry().size()); @@ -3273,9 +3246,9 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { p1.getText().getDiv().setValueAsString("
HELLO WORLD
"); p1.addIdentifier().setSystem("urn:system").setValue("testSaveAndRetrieveExistingNarrative01"); - IIdType newId = ourClient.create().resource(p1).encodedJson().execute().getId(); + IIdType newId = myClient.create().resource(p1).encodedJson().execute().getId(); - Patient actual = ourClient.read().resource(Patient.class).withId(newId).encodedJson().execute(); + Patient actual = myClient.read().resource(Patient.class).withId(newId).encodedJson().execute(); assertEquals("
HELLO WORLD
", actual.getText().getDiv().getValueAsString()); } @@ -3286,9 +3259,9 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { p1.getText().getDiv().setValueAsString("
HELLO WORLD
"); p1.addIdentifier().setSystem("urn:system").setValue("testSaveAndRetrieveExistingNarrative01"); - IIdType newId = ourClient.create().resource(p1).encodedXml().execute().getId(); + IIdType newId = myClient.create().resource(p1).encodedXml().execute().getId(); - Patient actual = ourClient.read().resource(Patient.class).withId(newId).encodedXml().execute(); + Patient actual = myClient.read().resource(Patient.class).withId(newId).encodedXml().execute(); assertEquals("
HELLO WORLD
", actual.getText().getDiv().getValueAsString()); } @@ -3301,9 +3274,9 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { .setUrl("http://foo") .setValue(new Reference("Practitioner/A")); - ourClient.update().resource(nextPatient).execute(); + myClient.update().resource(nextPatient).execute(); - Patient p = ourClient.read().resource(Patient.class).withId("B").execute(); + Patient p = myClient.read().resource(Patient.class).withId("B").execute(); String encoded = myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(p); ourLog.info(encoded); @@ -3321,12 +3294,12 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { p1.getManagingOrganization().setResource(o1); - IIdType newId = ourClient.create().resource(p1).execute().getId(); + IIdType newId = myClient.create().resource(p1).execute().getId(); - Patient actual = ourClient.read(Patient.class, new UriDt(newId.getValue())); + Patient actual = myClient.read(Patient.class, new UriDt(newId.getValue())); assertEquals(1, actual.getContained().size()); - Bundle b = ourClient + Bundle b = myClient .search() .forResource("Patient") .where(Patient.IDENTIFIER.exactly().systemAndCode("urn:system:rpr4", "testSaveAndRetrieveWithContained01")) @@ -3343,9 +3316,9 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { p1.getText().setDivAsString("
IdentifiertestSearchByResourceChain01
"); p1.addIdentifier().setSystem("urn:system").setValue("testSearchByResourceChain01"); - IdType newId = (IdType) ourClient.create().resource(p1).execute().getId(); + IdType newId = (IdType) myClient.create().resource(p1).execute().getId(); - Patient actual = ourClient.read(Patient.class, newId.getIdPart()); + Patient actual = myClient.read(Patient.class, newId.getIdPart()); assertThat(actual.getText().getDiv().getValueAsString(), containsString("IdentifiertestSearchByResourceChain01")); } @@ -3363,7 +3336,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { .setCode("B"); b.addConcept().setCode("B1"); b.addConcept().setCode("B2"); - ourClient.create().resource(cs).execute(); + myClient.create().resource(cs).execute(); ValueSet vs = new ValueSet(); vs.setUrl("http://vs"); @@ -3374,7 +3347,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { .setProperty("concept") .setOp(ValueSet.FilterOperator.ISA) .setValue("A"); - IIdType vsid = ourClient.create().resource(vs).execute().getId().toUnqualifiedVersionless(); + IIdType vsid = myClient.create().resource(vs).execute().getId().toUnqualifiedVersionless(); HttpGet read = new HttpGet(ourServerBase + "/" + vsid.getValue() + "/$expand"); try (CloseableHttpResponse response = ourHttpClient.execute(read)) { @@ -3403,9 +3376,9 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { enc.addReasonCode() .addCoding().setSystem("http://myorg").setCode("hugs").setDisplay("Hugs for better wellness"); enc.getPeriod().setStartElement(new DateTimeType("2012")); - IIdType id = ourClient.create().resource(enc).execute().getId().toUnqualifiedVersionless(); + IIdType id = myClient.create().resource(enc).execute().getId().toUnqualifiedVersionless(); - enc = ourClient.read().resource(Encounter.class).withId(id).execute(); + enc = myClient.read().resource(Encounter.class).withId(id).execute(); assertEquals("hugs", enc.getReasonCodeFirstRep().getCodingFirstRep().getCode()); } @@ -3424,7 +3397,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { .setCode("B"); b.addConcept().setCode("B1"); b.addConcept().setCode("B2"); - ourClient.create().resource(cs).execute(); + myClient.create().resource(cs).execute(); ValueSet vs = new ValueSet(); vs.setUrl("http://vs"); @@ -3435,19 +3408,19 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { .setProperty("concept") .setOp(ValueSet.FilterOperator.ISA) .setValue("A"); - ourClient.create().resource(vs).execute().getId().toUnqualifiedVersionless(); + myClient.create().resource(vs).execute().getId().toUnqualifiedVersionless(); Observation obs = new Observation(); obs.getCode().addCoding().setSystem("http://cs").setCode("A1"); obs.setValue(new StringType("OBS1")); obs.setStatus(ObservationStatus.FINAL); - ourClient.create().resource(obs).execute(); + myClient.create().resource(obs).execute(); Observation obs2 = new Observation(); obs2.getCode().addCoding().setSystem("http://cs").setCode("B1"); obs2.setStatus(ObservationStatus.FINAL); obs2.setValue(new StringType("OBS2")); - ourClient.create().resource(obs2).execute(); + myClient.create().resource(obs2).execute(); HttpGet read = new HttpGet(ourServerBase + "/Observation?code:in=http://vs"); try (CloseableHttpResponse response = ourHttpClient.execute(read)) { @@ -3520,7 +3493,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { Bundle found; - found = ourClient + found = myClient .search() .forResource(Patient.class) .where(IAnyResource.RES_ID.exactly().systemAndValues(null, id1.getIdPart(), id2.getIdPart())) @@ -3529,7 +3502,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { assertThat(toUnqualifiedVersionlessIds(found), containsInAnyOrder(id1, id2)); - found = ourClient + found = myClient .search() .forResource(Patient.class) .where(IAnyResource.RES_ID.exactly().systemAndValues(null, Arrays.asList(id1.getIdPart(), id2.getIdPart(), "FOOOOO"))) @@ -3538,7 +3511,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { assertThat(toUnqualifiedVersionlessIds(found), containsInAnyOrder(id1, id2)); - found = ourClient + found = myClient .search() .forResource(Patient.class) .where(IAnyResource.RES_ID.exactly().systemAndCode(null, id1.getIdPart())) @@ -3547,7 +3520,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { assertThat(toUnqualifiedVersionlessIds(found), containsInAnyOrder(id1)); - found = ourClient + found = myClient .search() .forResource(Patient.class) .where(IAnyResource.RES_ID.exactly().codes(id1.getIdPart(), id2.getIdPart())) @@ -3557,7 +3530,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { assertThat(toUnqualifiedVersionlessIds(found), containsInAnyOrder(id1)); - found = ourClient + found = myClient .search() .forResource(Patient.class) .where(IAnyResource.RES_ID.exactly().codes(Arrays.asList(id1.getIdPart(), id2.getIdPart(), "FOOOOO"))) @@ -3567,7 +3540,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { assertThat(toUnqualifiedVersionlessIds(found), containsInAnyOrder(id1)); - found = ourClient + found = myClient .search() .forResource(Patient.class) .where(IAnyResource.RES_ID.exactly().codes(id1.getIdPart(), id2.getIdPart(), "FOOO")) @@ -3576,7 +3549,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { assertThat(toUnqualifiedVersionlessIds(found), containsInAnyOrder(id1, id2)); - found = ourClient + found = myClient .search() .forResource(Patient.class) .where(IAnyResource.RES_ID.exactly().codes("FOOO")) @@ -3592,15 +3565,15 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { Patient p1 = new Patient(); p1.addIdentifier().setSystem("urn:system").setValue("testSearchByIdentifier01"); p1.addName().setFamily("testSearchByIdentifierFamily01").addGiven("testSearchByIdentifierGiven01"); - IdType p1Id = (IdType) ourClient.create().resource(p1).execute().getId(); + IdType p1Id = (IdType) myClient.create().resource(p1).execute().getId(); Patient p2 = new Patient(); p2.addIdentifier().setSystem("urn:system").setValue("testSearchByIdentifier02"); p2.addName().setFamily("testSearchByIdentifierFamily01").addGiven("testSearchByIdentifierGiven02"); - ourClient.create().resource(p2).execute(); + myClient.create().resource(p2).execute(); //@formatter:off - Bundle actual = ourClient + Bundle actual = myClient .search() .forResource(Patient.class) .where(Patient.IDENTIFIER.exactly().systemAndCode("urn:system", "testSearchByIdentifier01")) @@ -3621,10 +3594,10 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { Patient p1 = new Patient(); p1.addIdentifier().setValue("testSearchByIdentifierWithoutSystem01"); - IdType p1Id = (IdType) ourClient.create().resource(p1).execute().getId(); + IdType p1Id = (IdType) myClient.create().resource(p1).execute().getId(); //@formatter:off - Bundle actual = ourClient + Bundle actual = myClient .search() .forResource(Patient.class) .where(Patient.IDENTIFIER.exactly().systemAndCode(null, "testSearchByIdentifierWithoutSystem01")) @@ -3644,7 +3617,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { Patient p = new Patient(); p.addName().setFamily(methodName + "1"); - IIdType pid1 = ourClient.create().resource(p).execute().getId().toUnqualifiedVersionless(); + IIdType pid1 = myClient.create().resource(p).execute().getId().toUnqualifiedVersionless(); Thread.sleep(10); long time1 = System.currentTimeMillis(); @@ -3652,7 +3625,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { Patient p2 = new Patient(); p2.addName().setFamily(methodName + "2"); - IIdType pid2 = ourClient.create().resource(p2).execute().getId().toUnqualifiedVersionless(); + IIdType pid2 = myClient.create().resource(p2).execute().getId().toUnqualifiedVersionless(); HttpGet get = new HttpGet(ourServerBase + "/Patient?_lastUpdated=lt" + new InstantType(new Date(time1)).getValueAsString()); CloseableHttpResponse response = ourHttpClient.execute(get); @@ -3692,12 +3665,12 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { Patient p2 = new Patient(); p2.setId("P2"); p2.addName().setFamily("P2"); - ourClient.update().resource(p2).execute().getId().toUnqualifiedVersionless(); + myClient.update().resource(p2).execute().getId().toUnqualifiedVersionless(); Practitioner pract = new Practitioner(); pract.setId("PRAC"); pract.addName().setFamily("PRACT"); - ourClient.update().resource(pract).execute().getId().toUnqualifiedVersionless(); + myClient.update().resource(pract).execute().getId().toUnqualifiedVersionless(); Encounter enc = new Encounter(); enc.setId("E2"); @@ -3705,7 +3678,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { enc.setPeriod(new Period().setStart(new Date()).setEnd(new Date())); enc.getSubject().setReference("Patient/P2"); enc.addParticipant().getIndividual().setReference("Practitioner/PRAC"); - ourClient.update().resource(enc).execute().getId().toUnqualifiedVersionless(); + myClient.update().resource(enc).execute().getId().toUnqualifiedVersionless(); HttpGet get = new HttpGet(ourServerBase + "/Encounter?patient=P2&date=ge2017-01-01&_include:recurse=Encounter:practitioner&_lastUpdated=ge2017-11-10"); CloseableHttpResponse response = ourHttpClient.execute(get); @@ -3741,25 +3714,25 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { public void testSearchByReferenceIds() { Organization o1 = new Organization(); o1.setName("testSearchByResourceChainName01"); - IIdType o1id = ourClient.create().resource(o1).execute().getId().toUnqualifiedVersionless(); + IIdType o1id = myClient.create().resource(o1).execute().getId().toUnqualifiedVersionless(); Organization o2 = new Organization(); o2.setName("testSearchByResourceChainName02"); - IIdType o2id = ourClient.create().resource(o2).execute().getId().toUnqualifiedVersionless(); + IIdType o2id = myClient.create().resource(o2).execute().getId().toUnqualifiedVersionless(); Patient p1 = new Patient(); p1.addIdentifier().setSystem("urn:system").setValue("testSearchByReferenceIds01"); p1.addName().setFamily("testSearchByReferenceIdsFamily01").addGiven("testSearchByReferenceIdsGiven01"); p1.setManagingOrganization(new Reference(o1id.toUnqualifiedVersionless())); - IIdType p1Id = ourClient.create().resource(p1).execute().getId(); + IIdType p1Id = myClient.create().resource(p1).execute().getId(); Patient p2 = new Patient(); p2.addIdentifier().setSystem("urn:system").setValue("testSearchByReferenceIds02"); p2.addName().setFamily("testSearchByReferenceIdsFamily02").addGiven("testSearchByReferenceIdsGiven02"); p2.setManagingOrganization(new Reference(o2id.toUnqualifiedVersionless())); - IIdType p2Id = ourClient.create().resource(p2).execute().getId(); + IIdType p2Id = myClient.create().resource(p2).execute().getId(); //@formatter:off - Bundle actual = ourClient.search() + Bundle actual = myClient.search() .forResource(Patient.class) .where(Patient.ORGANIZATION.hasAnyOfIds(Arrays.asList(o1id.getIdPart(), o2id.getIdPart()))) .encodedJson().prettyPrint().returnBundle(Bundle.class).execute(); @@ -3771,7 +3744,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { for (BundleEntryComponent ele : actual.getEntry()) { actualIds.add(ele.getResource().getIdElement().getIdPart()); } - assertEquals("Expects to retrieve the 2 patients which reference the two different organizations", expectedIds, actualIds); + assertEquals(expectedIds, actualIds, "Expects to retrieve the 2 patients which reference the two different organizations"); } @Test @@ -3779,16 +3752,16 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { Organization o1 = new Organization(); o1.setName("testSearchByResourceChainName01"); - IdType o1id = (IdType) ourClient.create().resource(o1).execute().getId().toUnqualifiedVersionless(); + IdType o1id = (IdType) myClient.create().resource(o1).execute().getId().toUnqualifiedVersionless(); Patient p1 = new Patient(); p1.addIdentifier().setSystem("urn:system").setValue("testSearchByResourceChain01"); p1.addName().setFamily("testSearchByResourceChainFamily01").addGiven("testSearchByResourceChainGiven01"); p1.setManagingOrganization(new Reference(o1id.toUnqualifiedVersionless())); - IdType p1Id = (IdType) ourClient.create().resource(p1).execute().getId(); + IdType p1Id = (IdType) myClient.create().resource(p1).execute().getId(); //@formatter:off - Bundle actual = ourClient.search() + Bundle actual = myClient.search() .forResource(Patient.class) .where(Patient.ORGANIZATION.hasId(o1id.getIdPart())) .encodedJson().prettyPrint().returnBundle(Bundle.class).execute(); @@ -3797,7 +3770,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { assertEquals(p1Id.getIdPart(), actual.getEntry().get(0).getResource().getIdElement().getIdPart()); //@formatter:off - actual = ourClient.search() + actual = myClient.search() .forResource(Patient.class) .where(Patient.ORGANIZATION.hasId(o1id.getValue())) .encodedJson().prettyPrint().returnBundle(Bundle.class).execute(); @@ -3842,14 +3815,14 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { Patient patient = new Patient(); patient.addIdentifier().setSystem("urn:system").setValue("001"); patient.addName().setFamily(methodName).addGiven("Joe"); - id1a = ourClient.create().resource(patient).execute().getId().toUnqualifiedVersionless(); + id1a = myClient.create().resource(patient).execute().getId().toUnqualifiedVersionless(); } IIdType id1b; { Patient patient = new Patient(); patient.addIdentifier().setSystem("urn:system").setValue("002"); patient.addName().setFamily(methodName + "XXXX").addGiven("Joe"); - id1b = ourClient.create().resource(patient).execute().getId().toUnqualifiedVersionless(); + id1b = myClient.create().resource(patient).execute().getId().toUnqualifiedVersionless(); } Thread.sleep(1100); @@ -3861,12 +3834,12 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { Patient patient = new Patient(); patient.addIdentifier().setSystem("urn:system").setValue("002"); patient.addName().setFamily(methodName).addGiven("John"); - id2 = ourClient.create().resource(patient).execute().getId().toUnqualifiedVersionless(); + id2 = myClient.create().resource(patient).execute().getId().toUnqualifiedVersionless(); } { //@formatter:off - Bundle found = ourClient.search() + Bundle found = myClient.search() .forResource(Patient.class) .where(Patient.NAME.matches().value("testSearchLastUpdatedParamRp")) .returnBundle(Bundle.class) @@ -3877,7 +3850,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { } { //@formatter:off - Bundle found = ourClient.search() + Bundle found = myClient.search() .forResource(Patient.class) .where(Patient.NAME.matches().value("testSearchLastUpdatedParamRp")) .lastUpdated(new DateRangeParam(beforeAny, null)) @@ -3889,7 +3862,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { } { //@formatter:off - Bundle found = ourClient.search() + Bundle found = myClient.search() .forResource(Patient.class) .where(Patient.NAME.matches().value("testSearchLastUpdatedParamRp")) .lastUpdated(new DateRangeParam(beforeR2, null)) @@ -3902,7 +3875,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { } { //@formatter:off - Bundle found = ourClient.search() + Bundle found = myClient.search() .forResource(Patient.class) .where(Patient.NAME.matches().value("testSearchLastUpdatedParamRp")) .lastUpdated(new DateRangeParam(beforeAny, beforeR2)) @@ -3915,7 +3888,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { } { //@formatter:off - Bundle found = ourClient.search() + Bundle found = myClient.search() .forResource(Patient.class) .where(Patient.NAME.matches().value("testSearchLastUpdatedParamRp")) .lastUpdated(new DateRangeParam(null, beforeR2)) @@ -3962,16 +3935,13 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { String oid2 = myObservationDao.create(o2, mySrd).getId().toUnqualifiedVersionless().getValue(); HttpGet get = new HttpGet(ourServerBase + "/Observation?value-quantity=gt-15"); - CloseableHttpResponse resp = ourHttpClient.execute(get); - try { + try (CloseableHttpResponse resp = ourHttpClient.execute(get)) { assertEquals(200, resp.getStatusLine().getStatusCode()); Bundle bundle = myFhirCtx.newXmlParser().parseResource(Bundle.class, IOUtils.toString(resp.getEntity().getContent(), Constants.CHARSET_UTF8)); List ids = toUnqualifiedVersionlessIdValues(bundle); assertThat(ids, contains(oid1)); assertThat(ids, not(contains(oid2))); - } finally { - resp.close(); } } @@ -3997,7 +3967,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { List linkNext = Lists.newArrayList(); for (int i = 0; i < 100; i++) { - Bundle bundle = ourClient.search().forResource(Patient.class).where(Patient.NAME.matches().value("testSearchPagingKeepsOldSearches")).count(5).returnBundle(Bundle.class).execute(); + Bundle bundle = myClient.search().forResource(Patient.class).where(Patient.NAME.matches().value("testSearchPagingKeepsOldSearches")).count(5).returnBundle(Bundle.class).execute(); assertTrue(isNotBlank(bundle.getLink("next").getUrl())); assertEquals(5, bundle.getEntry().size()); linkNext.add(bundle.getLink("next").getUrl()); @@ -4006,7 +3976,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { int index = 0; for (String nextLink : linkNext) { ourLog.info("Fetching index {}", index++); - Bundle b = ourClient.fetchResourceFromUrl(Bundle.class, nextLink); + Bundle b = myClient.fetchResourceFromUrl(Bundle.class, nextLink); assertEquals(5, b.getEntry().size()); } } @@ -4030,7 +4000,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { Thread.sleep(1); //@formatter:off - Bundle found = ourClient + Bundle found = myClient .search() .forResource(Patient.class) .prettyPrint() @@ -4048,7 +4018,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { ourLog.info(value.getTime() + ""); ourLog.info(before.getTime() + ""); assertTrue(value.after(before)); - assertTrue(new InstantDt(value) + " should be before " + new InstantDt(after), value.before(after)); + assertTrue(value.before(after), new InstantDt(value) + " should be before " + new InstantDt(after)); } @Test @@ -4059,11 +4029,11 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { org.setName("HELLO"); resources.add(org); } - ourClient.transaction().withResources(resources).prettyPrint().encodedXml().execute(); + myClient.transaction().withResources(resources).prettyPrint().encodedXml().execute(); myDaoConfig.setReuseCachedSearchResultsForMillis(1000L); - Bundle result1 = ourClient + Bundle result1 = myClient .search() .forResource("Organization") .returnBundle(Bundle.class) @@ -4071,7 +4041,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { final String uuid1 = toSearchUuidFromLinkNext(result1); - Bundle result2 = ourClient + Bundle result2 = myClient .search() .forResource("Organization") .returnBundle(Bundle.class) @@ -4084,25 +4054,25 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { @Test public void testSearchReusesBeforeExpiry() { - List resources = new ArrayList(); + List resources = new ArrayList<>(); for (int i = 0; i < 50; i++) { Organization org = new Organization(); org.setName("HELLO"); resources.add(org); } - ourClient.transaction().withResources(resources).prettyPrint().encodedXml().execute(); + myClient.transaction().withResources(resources).prettyPrint().encodedXml().execute(); { myDaoConfig.setReuseCachedSearchResultsForMillis(10L); - Bundle result1 = ourClient + Bundle result1 = myClient .search() .forResource("Organization") .returnBundle(Bundle.class) .execute(); final String uuid1 = toSearchUuidFromLinkNext(result1); sleepAtLeast(11L); - Bundle result2 = ourClient + Bundle result2 = myClient .search() .forResource("Organization") .returnBundle(Bundle.class) @@ -4113,7 +4083,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { { myDaoConfig.setReuseCachedSearchResultsForMillis(1000L); - Bundle result1 = ourClient + Bundle result1 = myClient .search() .forResource("Organization") .returnBundle(Bundle.class) @@ -4125,7 +4095,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { mySearchEntityDao.save(search); }); sleepOneClick(); - Bundle result2 = ourClient + Bundle result2 = myClient .search() .forResource("Organization") .returnBundle(Bundle.class) @@ -4146,11 +4116,11 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { org.setName("HELLO"); resources.add(org); } - ourClient.transaction().withResources(resources).prettyPrint().encodedXml().execute(); + myClient.transaction().withResources(resources).prettyPrint().encodedXml().execute(); myDaoConfig.setReuseCachedSearchResultsForMillis(null); - Bundle result1 = ourClient + Bundle result1 = myClient .search() .forResource("Organization") .where(Organization.NAME.matches().value("HELLO")) @@ -4160,7 +4130,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { final String uuid1 = toSearchUuidFromLinkNext(result1); - Bundle result2 = ourClient + Bundle result2 = myClient .search() .forResource("Organization") .where(Organization.NAME.matches().value("HELLO")) @@ -4170,7 +4140,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { final String uuid2 = toSearchUuidFromLinkNext(result2); - Bundle result3 = ourClient + Bundle result3 = myClient .search() .forResource("Organization") .where(Organization.NAME.matches().value("HELLO")) @@ -4192,11 +4162,11 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { org.setName("HELLO"); resources.add(org); } - ourClient.transaction().withResources(resources).prettyPrint().encodedXml().execute(); + myClient.transaction().withResources(resources).prettyPrint().encodedXml().execute(); myDaoConfig.setReuseCachedSearchResultsForMillis(1000L); - Bundle result1 = ourClient + Bundle result1 = myClient .search() .forResource("Organization") .where(Organization.NAME.matches().value("HELLO")) @@ -4208,7 +4178,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { Search search1 = newTxTemplate().execute(theStatus -> mySearchEntityDao.findByUuidAndFetchIncludes(uuid1).orElseThrow(() -> new InternalErrorException(""))); Date created1 = search1.getCreated(); - Bundle result2 = ourClient + Bundle result2 = myClient .search() .forResource("Organization") .where(Organization.NAME.matches().value("HELLO")) @@ -4224,7 +4194,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { Thread.sleep(1500); - Bundle result3 = ourClient + Bundle result3 = myClient .search() .forResource("Organization") .where(Organization.NAME.matches().value("HELLO")) @@ -4246,11 +4216,11 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { org.setName("HELLO"); resources.add(org); } - ourClient.transaction().withResources(resources).prettyPrint().encodedXml().execute(); + myClient.transaction().withResources(resources).prettyPrint().encodedXml().execute(); myDaoConfig.setReuseCachedSearchResultsForMillis(100000L); - Bundle result1 = ourClient + Bundle result1 = myClient .search() .forResource("Organization") .returnBundle(Bundle.class) @@ -4262,7 +4232,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { sleepOneClick(); - Bundle result2 = ourClient + Bundle result2 = myClient .search() .forResource("Organization") .returnBundle(Bundle.class) @@ -4285,9 +4255,9 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { Patient patient = new Patient(); patient.addIdentifier().setSystem("urn:system2").setValue("testSearchTokenParam002"); patient.addName().setFamily("Tester").addGiven("testSearchTokenParam2"); - ourClient.create().resource(patient).execute(); + myClient.create().resource(patient).execute(); - Bundle response = ourClient + Bundle response = myClient .search() .forResource(Patient.class) .returnBundle(Bundle.class) @@ -4295,14 +4265,14 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { patient = (Patient) response.getEntry().get(0).getResource(); - ourClient + myClient .meta() .add() .onResource(patient.getIdElement()) .meta(new Meta().addTag("http://system", "tag1", "display")) .execute(); - response = ourClient + response = myClient .search() .forResource(Patient.class) .returnBundle(Bundle.class) @@ -4331,7 +4301,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { patient.addName().setFamily("Tester").addGiven("testSearchTokenParam2"); myPatientDao.create(patient, mySrd); - Bundle response = ourClient + Bundle response = myClient .search() .forResource(Patient.class) .where(Patient.IDENTIFIER.hasSystemWithAnyCode("urn:system")) @@ -4349,14 +4319,14 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { for (int i = 0; i < 10; i++) { Patient pat = new Patient(); pat.addIdentifier().setSystem("urn:system:rpr4").setValue("test" + i); - ourClient.create().resource(pat).execute(); + myClient.create().resource(pat).execute(); } StopWatch sw = new StopWatch(); ourLog.info("** About to search with count of 1"); - Bundle found = ourClient + Bundle found = myClient .search() .forResource(Patient.class) .returnBundle(Bundle.class) @@ -4390,12 +4360,12 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { for (int i = 0; i < 10; i++) { Patient pat = new Patient(); pat.addIdentifier().setSystem("urn:system:rpr4").setValue("test" + i); - ourClient.create().resource(pat).execute(); + myClient.create().resource(pat).execute(); } StopWatch sw = new StopWatch(); - Bundle found = ourClient + Bundle found = myClient .search() .forResource(Patient.class) .returnBundle(Bundle.class) @@ -4418,12 +4388,12 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { for (int i = 0; i < 10; i++) { Patient pat = new Patient(); pat.addIdentifier().setSystem("urn:system:rpr4").setValue("test" + i); - ourClient.create().resource(pat).execute(); + myClient.create().resource(pat).execute(); } StopWatch sw = new StopWatch(); - Bundle found = ourClient + Bundle found = myClient .search() .forResource(Patient.class) .returnBundle(Bundle.class) @@ -4451,7 +4421,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { Observation obs = new Observation(); obs.setStatus(ObservationStatus.FINAL); obs.getCode().addCoding().setSystem("foo").setCode("bar"); - ourClient.create().resource(obs).execute(); + myClient.create().resource(obs).execute(); testSearchWithEmptyParameter("/Observation?value-quantity="); testSearchWithEmptyParameter("/Observation?code=bar&value-quantity="); @@ -4475,14 +4445,14 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { public void testSearchWithInclude() { Organization org = new Organization(); org.addIdentifier().setSystem("urn:system:rpr4").setValue("testSearchWithInclude01"); - IdType orgId = (IdType) ourClient.create().resource(org).prettyPrint().encodedXml().execute().getId(); + IdType orgId = (IdType) myClient.create().resource(org).prettyPrint().encodedXml().execute().getId(); Patient pat = new Patient(); pat.addIdentifier().setSystem("urn:system:rpr4").setValue("testSearchWithInclude02"); pat.getManagingOrganization().setReferenceElement(orgId.toUnqualifiedVersionless()); - ourClient.create().resource(pat).prettyPrint().encodedXml().execute(); + myClient.create().resource(pat).prettyPrint().encodedXml().execute(); - Bundle found = ourClient + Bundle found = myClient .search() .forResource(Patient.class) .where(Patient.IDENTIFIER.exactly().systemAndIdentifier("urn:system:rpr4", "testSearchWithInclude02")) @@ -4501,7 +4471,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { @Test() public void testSearchWithInvalidNumberPrefix() { try { - ourClient + myClient .search() .forResource(MolecularSequence.class) .where(MolecularSequence.VARIANT_END.withPrefix(ParamPrefixEnum.ENDS_BEFORE).number(100)) @@ -4521,7 +4491,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { myObservationDao.create(o, mySrd); try { //@formatter:off - ourClient + myClient .search() .forResource(Observation.class) .where(Observation.VALUE_QUANTITY.withPrefix(ParamPrefixEnum.ENDS_BEFORE).number(100).andNoUnits()) @@ -4535,20 +4505,23 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { } } - @Test(expected = InvalidRequestException.class) + @Test public void testSearchWithInvalidSort() { + try { Observation o = new Observation(); o.getCode().setText("testSearchWithInvalidSort"); myObservationDao.create(o, mySrd); - //@formatter:off - ourClient + myClient .search() .forResource(Observation.class) .sort().ascending(Observation.CODE_VALUE_QUANTITY) // composite sort not supported yet .prettyPrint() .returnBundle(Bundle.class) .execute(); - //@formatter:on + fail(); + } catch (InvalidRequestException e) { + assertEquals("HTTP 400 Bad Request: This server does not support _sort specifications of type COMPOSITE - Can't serve _sort=code-value-quantity", e.getMessage()); + } } @Test @@ -4559,13 +4532,13 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { String methodName = "testSearchWithMissing"; Organization org = new Organization(); - IIdType deletedIdMissingTrue = ourClient.create().resource(org).execute().getId().toUnqualifiedVersionless(); - ourClient.delete().resourceById(deletedIdMissingTrue).execute(); + IIdType deletedIdMissingTrue = myClient.create().resource(org).execute().getId().toUnqualifiedVersionless(); + myClient.delete().resourceById(deletedIdMissingTrue).execute(); org = new Organization(); org.setName("Help I'm a Bug"); - IIdType deletedIdMissingFalse = ourClient.create().resource(org).execute().getId().toUnqualifiedVersionless(); - ourClient.delete().resourceById(deletedIdMissingFalse).execute(); + IIdType deletedIdMissingFalse = myClient.create().resource(org).execute().getId().toUnqualifiedVersionless(); + myClient.delete().resourceById(deletedIdMissingFalse).execute(); List resources = new ArrayList<>(); for (int i = 0; i < 20; i++) { @@ -4573,20 +4546,20 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { org.setName(methodName + "_0" + i); resources.add(org); } - ourClient.transaction().withResources(resources).prettyPrint().encodedXml().execute(); + myClient.transaction().withResources(resources).prettyPrint().encodedXml().execute(); org = new Organization(); org.addIdentifier().setSystem("urn:system:rpr4").setValue(methodName + "01"); org.setName(methodName + "name"); - IIdType orgNotMissing = ourClient.create().resource(org).prettyPrint().encodedXml().execute().getId().toUnqualifiedVersionless(); + IIdType orgNotMissing = myClient.create().resource(org).prettyPrint().encodedXml().execute().getId().toUnqualifiedVersionless(); org = new Organization(); org.addIdentifier().setSystem("urn:system:rpr4").setValue(methodName + "01"); - IIdType orgMissing = ourClient.create().resource(org).prettyPrint().encodedXml().execute().getId().toUnqualifiedVersionless(); + IIdType orgMissing = myClient.create().resource(org).prettyPrint().encodedXml().execute().getId().toUnqualifiedVersionless(); { //@formatter:off - Bundle found = ourClient + Bundle found = myClient .search() .forResource(Organization.class) .where(Organization.NAME.isMissing(false)) @@ -4605,7 +4578,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { } //@formatter:off - Bundle found = ourClient + Bundle found = myClient .search() .forResource(Organization.class) .where(Organization.NAME.isMissing(true)) @@ -4646,16 +4619,13 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { IIdType id2 = myMedicationRequestDao.create(mr2).getId().toUnqualifiedVersionless(); HttpGet get = new HttpGet(ourServerBase + "/MedicationRequest?date:missing=false"); - CloseableHttpResponse resp = ourHttpClient.execute(get); - try { + try (CloseableHttpResponse resp = ourHttpClient.execute(get)) { assertEquals(200, resp.getStatusLine().getStatusCode()); Bundle bundle = myFhirCtx.newXmlParser().parseResource(Bundle.class, IOUtils.toString(resp.getEntity().getContent(), Constants.CHARSET_UTF8)); List ids = toUnqualifiedVersionlessIdValues(bundle); assertThat(ids, contains(id1.getValue())); assertThat(ids, not(contains(id2.getValue()))); - } finally { - resp.close(); } } @@ -4696,7 +4666,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { Observation obs = new Observation(); obs.getCode().setText("THIS_IS_THE_TEXT"); obs.getCode().addCoding().setSystem("SYSTEM").setCode("CODE").setDisplay("THIS_IS_THE_DISPLAY"); - ourClient.create().resource(obs).execute(); + myClient.create().resource(obs).execute(); testSearchReturnsResults("/Observation?code%3Atext=THIS_IS_THE_TEXT"); testSearchReturnsResults("/Observation?code%3Atext=THIS_IS_THE_"); @@ -4709,25 +4679,25 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { public void testSelfReferentialInclude() { Location loc1 = new Location(); loc1.setName("loc1"); - IIdType loc1id = ourClient.create().resource(loc1).execute().getId().toUnqualifiedVersionless(); + IIdType loc1id = myClient.create().resource(loc1).execute().getId().toUnqualifiedVersionless(); Location loc2 = new Location(); loc2.setName("loc2"); - IIdType loc2id = ourClient.create().resource(loc2).execute().getId().toUnqualifiedVersionless(); + IIdType loc2id = myClient.create().resource(loc2).execute().getId().toUnqualifiedVersionless(); loc1 = new Location(); loc1.setId(loc1id); loc1.setName("loc1"); loc1.getPartOf().setReference(loc2id.getValue()); - ourClient.update().resource(loc1).execute().getId().toUnqualifiedVersionless(); + myClient.update().resource(loc1).execute().getId().toUnqualifiedVersionless(); loc2 = new Location(); loc2.setId(loc2id); loc2.setName("loc2"); loc2.getPartOf().setReference(loc1id.getValue()); - ourClient.update().resource(loc2).execute().getId().toUnqualifiedVersionless(); + myClient.update().resource(loc2).execute().getId().toUnqualifiedVersionless(); - IBaseBundle result = ourClient + IBaseBundle result = myClient .search() .forResource(Location.class) .where(Location.NAME.matches().value("loc1")) @@ -4740,25 +4710,25 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { public void testSelfReferentialRevInclude() { Location loc1 = new Location(); loc1.setName("loc1"); - IIdType loc1id = ourClient.create().resource(loc1).execute().getId().toUnqualifiedVersionless(); + IIdType loc1id = myClient.create().resource(loc1).execute().getId().toUnqualifiedVersionless(); Location loc2 = new Location(); loc2.setName("loc2"); - IIdType loc2id = ourClient.create().resource(loc2).execute().getId().toUnqualifiedVersionless(); + IIdType loc2id = myClient.create().resource(loc2).execute().getId().toUnqualifiedVersionless(); loc1 = new Location(); loc1.setId(loc1id); loc1.setName("loc1"); loc1.getPartOf().setReference(loc2id.getValue()); - ourClient.update().resource(loc1).execute().getId().toUnqualifiedVersionless(); + myClient.update().resource(loc1).execute().getId().toUnqualifiedVersionless(); loc2 = new Location(); loc2.setId(loc2id); loc2.setName("loc2"); loc2.getPartOf().setReference(loc1id.getValue()); - ourClient.update().resource(loc2).execute().getId().toUnqualifiedVersionless(); + myClient.update().resource(loc2).execute().getId().toUnqualifiedVersionless(); - IBaseBundle result = ourClient + IBaseBundle result = myClient .search() .forResource(Location.class) .where(Location.NAME.matches().value("loc1")) @@ -4774,15 +4744,15 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { Patient p = new Patient(); p.setId("p"); p.setActive(true); - ourClient.update().resource(p).execute(); + myClient.update().resource(p).execute(); CarePlan cp = new CarePlan(); cp.setId("cp"); cp.getSubject().setResource(p); cp.addActivity().getDetail().getCode().addCoding().setSystem("FOO").setCode("BAR"); - ourClient.update().resource(cp).execute(); + myClient.update().resource(cp).execute(); - Bundle b = ourClient + Bundle b = myClient .search() .forResource(CarePlan.class) .where(CarePlan.ACTIVITY_CODE.exactly().systemAndCode("FOO", "BAR")) @@ -4805,89 +4775,89 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(methodName); - ourClient.create().resource(p).execute(); + myClient.create().resource(p).execute(); p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(methodName); p.addName().addGiven("Daniel").setFamily("Adams"); - ourClient.create().resource(p).execute(); + myClient.create().resource(p).execute(); p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(methodName); p.addName().addGiven("Aaron").setFamily("Alexis"); - ourClient.create().resource(p).execute(); + myClient.create().resource(p).execute(); p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(methodName); p.addName().addGiven("Carol").setFamily("Allen"); - ourClient.create().resource(p).execute(); + myClient.create().resource(p).execute(); p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(methodName); p.addName().addGiven("Ruth").setFamily("Black"); - ourClient.create().resource(p).execute(); + myClient.create().resource(p).execute(); p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(methodName); p.addName().addGiven("Brian").setFamily("Brooks"); - ourClient.create().resource(p).execute(); + myClient.create().resource(p).execute(); p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(methodName); p.addName().addGiven("Susan").setFamily("Clark"); - ourClient.create().resource(p).execute(); + myClient.create().resource(p).execute(); p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(methodName); p.addName().addGiven("Amy").setFamily("Clark"); - ourClient.create().resource(p).execute(); + myClient.create().resource(p).execute(); p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(methodName); p.addName().addGiven("Anthony").setFamily("Coleman"); - ourClient.create().resource(p).execute(); + myClient.create().resource(p).execute(); p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(methodName); p.addName().addGiven("Steven").setFamily("Coleman"); - ourClient.create().resource(p).execute(); + myClient.create().resource(p).execute(); p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(methodName); p.addName().addGiven("Lisa").setFamily("Coleman"); - ourClient.create().resource(p).execute(); + myClient.create().resource(p).execute(); p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(methodName); p.addName().addGiven("Ruth").setFamily("Cook"); - ourClient.create().resource(p).execute(); + myClient.create().resource(p).execute(); p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(methodName); p.addName().addGiven("Betty").setFamily("Davis"); - ourClient.create().resource(p).execute(); + myClient.create().resource(p).execute(); p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(methodName); p.addName().addGiven("Joshua").setFamily("Diaz"); - ourClient.create().resource(p).execute(); + myClient.create().resource(p).execute(); p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(methodName); p.addName().addGiven("Brian").setFamily("Gracia"); - ourClient.create().resource(p).execute(); + myClient.create().resource(p).execute(); p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(methodName); p.addName().addGiven("Stephan").setFamily("Graham"); - ourClient.create().resource(p).execute(); + myClient.create().resource(p).execute(); p = new Patient(); p.addIdentifier().setSystem("urn:system").setValue(methodName); p.addName().addGiven("Sarah").setFamily("Graham"); - ourClient.create().resource(p).execute(); + myClient.create().resource(p).execute(); - Bundle resp = ourClient + Bundle resp = myClient .search() .forResource(Patient.class) .where(Patient.IDENTIFIER.exactly().systemAndCode("urn:system", methodName)) @@ -4929,7 +4899,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { Organization org = new Organization(); org.setName("測試醫院"); org.addIdentifier().setSystem("urn:system").setValue("testStoreUtf8Characters_01"); - IdType orgId = (IdType) ourClient.create().resource(org).prettyPrint().encodedXml().execute().getId(); + IdType orgId = (IdType) myClient.create().resource(org).prettyPrint().encodedXml().execute().getId(); // Read back directly from the DAO { @@ -4940,7 +4910,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { } // Read back through the HTTP API { - Organization returned = ourClient.read(Organization.class, orgId.getIdPart()); + Organization returned = myClient.read(Organization.class, orgId.getIdPart()); String val = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(returned); ourLog.info(val); assertThat(val, containsString("")); @@ -4967,7 +4937,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { p1.setManagingOrganization(new Reference("Organization/99999999999")); try { - ourClient.create().resource(p1).execute(); + myClient.create().resource(p1).execute(); fail(); } catch (InvalidRequestException e) { assertThat(e.getMessage(), containsString("Organization/99999999999")); @@ -5019,7 +4989,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { * This does not currently cause an error, so this test is disabled */ @Test - @Ignore + @Disabled public void testUpdateNoIdInBody() throws Exception { String methodName = "testUpdateNoIdInBody"; @@ -5044,7 +5014,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { Patient p1 = new Patient(); p1.addIdentifier().setSystem("urn:system").setValue("testUpdateRejectsInvalidTypes"); p1.addName().setFamily("Tester").addGiven("testUpdateRejectsInvalidTypes"); - IdType p1id = (IdType) ourClient.create().resource(p1).execute().getId(); + IdType p1id = (IdType) myClient.create().resource(p1).execute().getId(); // Try to update with the wrong ID in the resource body p1.setId("FOO"); @@ -5105,20 +5075,20 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { Patient p1 = new Patient(); p1.addIdentifier().setSystem("urn:system").setValue("testUpdateRejectsInvalidTypes"); p1.addName().setFamily("Tester").addGiven("testUpdateRejectsInvalidTypes"); - IdType p1id = (IdType) ourClient.create().resource(p1).execute().getId(); + IdType p1id = (IdType) myClient.create().resource(p1).execute().getId(); Organization p2 = new Organization(); p2.setId(p1id.getIdPart()); p2.getNameElement().setValue("testUpdateRejectsInvalidTypes"); try { - ourClient.update().resource(p2).withId("Organization/" + p1id.getIdPart()).execute(); + myClient.update().resource(p2).withId("Organization/" + p1id.getIdPart()).execute(); fail(); } catch (UnprocessableEntityException e) { // good } try { - ourClient.update().resource(p2).withId("Patient/" + p1id.getIdPart()).execute(); + myClient.update().resource(p2).withId("Patient/" + p1id.getIdPart()).execute(); fail(); } catch (UnprocessableEntityException e) { // good @@ -5294,14 +5264,14 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { Patient p1 = new Patient(); p1.addIdentifier().setSystem("urn:system").setValue("testUpdateWithClientSuppliedIdWhichDoesntExistrpr4"); - MethodOutcome outcome = ourClient.update().resource(p1).withId("testUpdateWithClientSuppliedIdWhichDoesntExistrpr4").execute(); + MethodOutcome outcome = myClient.update().resource(p1).withId("testUpdateWithClientSuppliedIdWhichDoesntExistrpr4").execute(); assertEquals(true, outcome.getCreated().booleanValue()); IdType p1Id = (IdType) outcome.getId(); assertThat(p1Id.getValue(), containsString("Patient/testUpdateWithClientSuppliedIdWhichDoesntExistrpr4/_history")); //@formatter:off - Bundle actual = ourClient + Bundle actual = myClient .search() .forResource(Patient.class) .where(Patient.IDENTIFIER.exactly().systemAndCode("urn:system", "testUpdateWithClientSuppliedIdWhichDoesntExistrpr4")) @@ -5320,23 +5290,23 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { public void testUpdateWithSource() { Patient patient = new Patient(); patient.setActive(false); - IIdType patientid = ourClient.create().resource(patient).execute().getId().toUnqualifiedVersionless(); + IIdType patientid = myClient.create().resource(patient).execute().getId().toUnqualifiedVersionless(); { - Patient readPatient = (Patient) ourClient.read().resource("Patient").withId(patientid).execute(); + Patient readPatient = (Patient) myClient.read().resource("Patient").withId(patientid).execute(); assertThat(readPatient.getMeta().getSource(), matchesPattern("#[a-zA-Z0-9]+")); } patient.setId(patientid); patient.setActive(true); - ourClient.update().resource(patient).execute(); + myClient.update().resource(patient).execute(); { - Patient readPatient = (Patient) ourClient.read().resource("Patient").withId(patientid).execute(); + Patient readPatient = (Patient) myClient.read().resource("Patient").withId(patientid).execute(); assertThat(readPatient.getMeta().getSource(), matchesPattern("#[a-zA-Z0-9]+")); readPatient.addName().setFamily("testUpdateWithSource"); - ourClient.update().resource(readPatient).execute(); - readPatient = (Patient) ourClient.read().resource("Patient").withId(patientid).execute(); + myClient.update().resource(readPatient).execute(); + readPatient = (Patient) myClient.read().resource("Patient").withId(patientid).execute(); assertThat(readPatient.getMeta().getSource(), matchesPattern("#[a-zA-Z0-9]+")); } } @@ -5347,7 +5317,7 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { Patient pt = new Patient(); pt.addName().setFamily(methodName); - IIdType id = ourClient.create().resource(pt).execute().getId().toUnqualifiedVersionless(); + IIdType id = myClient.create().resource(pt).execute().getId().toUnqualifiedVersionless(); pt.addName().setFamily("FAM2"); pt.setId(id.toUnqualifiedVersionless()); @@ -5409,12 +5379,12 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { String input = IOUtils.toString(getClass().getResourceAsStream("/dstu3-person.json"), StandardCharsets.UTF_8); try { - ourClient.update().resource(input).withId("Patient/PERSON1").execute(); + myClient.update().resource(input).withId("Patient/PERSON1").execute(); } catch (InvalidRequestException e) { assertEquals("", e.getMessage()); } - MethodOutcome resp = ourClient.update().resource(input).withId("Person/PERSON1").execute(); + MethodOutcome resp = myClient.update().resource(input).withId("Person/PERSON1").execute(); assertEquals("Person/PERSON1/_history/1", resp.getId().toUnqualified().getValue()); } @@ -5639,10 +5609,10 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { @Test public void testValueSetExpandOperation() throws IOException { CodeSystem cs = myFhirCtx.newXmlParser().parseResource(CodeSystem.class, new InputStreamReader(ResourceProviderR4Test.class.getResourceAsStream("/extensional-case-3-cs.xml"))); - ourClient.create().resource(cs).execute(); + myClient.create().resource(cs).execute(); ValueSet upload = myFhirCtx.newXmlParser().parseResource(ValueSet.class, new InputStreamReader(ResourceProviderR4Test.class.getResourceAsStream("/extensional-case-3-vs.xml"))); - IIdType vsid = ourClient.create().resource(upload).execute().getId().toUnqualifiedVersionless(); + IIdType vsid = myClient.create().resource(upload).execute().getId().toUnqualifiedVersionless(); HttpGet get = new HttpGet(ourServerBase + "/ValueSet/" + vsid.getIdPart() + "/$expand"); CloseableHttpResponse response = ourHttpClient.execute(get); @@ -5695,9 +5665,5 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test { return new InstantDt(theDate).getValueAsString(); } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4ValueSetTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4ValueSetTest.java index fc09fbf80d1..69a3f9fc44f 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4ValueSetTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderR4ValueSetTest.java @@ -16,7 +16,6 @@ import ca.uhn.fhir.jpa.term.api.ITermCodeSystemStorageSvc; 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; import ca.uhn.fhir.util.UrlUtil; import com.google.common.base.Charsets; import org.apache.commons.io.IOUtils; @@ -42,9 +41,8 @@ import org.hl7.fhir.r4.model.ValueSet; import org.hl7.fhir.r4.model.ValueSet.ConceptSetComponent; import org.hl7.fhir.r4.model.ValueSet.FilterOperator; import org.hl7.fhir.r4.model.codesystems.HttpVerb; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; import org.springframework.transaction.TransactionStatus; import org.springframework.transaction.support.TransactionCallbackWithoutResult; import org.springframework.transaction.support.TransactionTemplate; @@ -60,12 +58,12 @@ import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.containsStringIgnoringCase; import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.stringContainsInOrder; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; public class ResourceProviderR4ValueSetTest extends BaseResourceProviderR4Test { @@ -215,7 +213,7 @@ public class ResourceProviderR4ValueSetTest extends BaseResourceProviderR4Test { public void testExpandById() throws Exception { loadAndPersistCodeSystemAndValueSet(); - Parameters respParam = ourClient + Parameters respParam = myClient .operation() .onInstance(myExtensionalVsId) .named("expand") @@ -248,7 +246,7 @@ public class ResourceProviderR4ValueSetTest extends BaseResourceProviderR4Test { loadAndPersistCodeSystemAndValueSet(); myTermSvc.preExpandDeferredValueSetsToTerminologyTables(); - Parameters respParam = ourClient + Parameters respParam = myClient .operation() .onInstance(myExtensionalVsId) .named("expand") @@ -278,7 +276,7 @@ public class ResourceProviderR4ValueSetTest extends BaseResourceProviderR4Test { public void testExpandByIdWithFilter() throws Exception { loadAndPersistCodeSystemAndValueSet(); - Parameters respParam = ourClient + Parameters respParam = myClient .operation() .onInstance(myExtensionalVsId) .named("expand") @@ -300,7 +298,7 @@ public class ResourceProviderR4ValueSetTest extends BaseResourceProviderR4Test { loadAndPersistCodeSystemAndValueSet(); myTermSvc.preExpandDeferredValueSetsToTerminologyTables(); - Parameters respParam = ourClient + Parameters respParam = myClient .operation() .onInstance(myExtensionalVsId) .named("expand") @@ -319,7 +317,7 @@ public class ResourceProviderR4ValueSetTest extends BaseResourceProviderR4Test { public void testExpandByUrl() throws Exception { loadAndPersistCodeSystemAndValueSet(); - Parameters respParam = ourClient + Parameters respParam = myClient .operation() .onType(ValueSet.class) .named("expand") @@ -340,7 +338,7 @@ public class ResourceProviderR4ValueSetTest extends BaseResourceProviderR4Test { loadAndPersistCodeSystemAndValueSet(); try { - ourClient + myClient .operation() .onType(ValueSet.class) .named("expand") @@ -359,7 +357,7 @@ public class ResourceProviderR4ValueSetTest extends BaseResourceProviderR4Test { loadAndPersistCodeSystemAndValueSet(); myTermSvc.preExpandDeferredValueSetsToTerminologyTables(); - Parameters respParam = ourClient + Parameters respParam = myClient .operation() .onType(ValueSet.class) .named("expand") @@ -383,7 +381,7 @@ public class ResourceProviderR4ValueSetTest extends BaseResourceProviderR4Test { myTermSvc.preExpandDeferredValueSetsToTerminologyTables(); try { - ourClient + myClient .operation() .onType(ValueSet.class) .named("expand") @@ -401,7 +399,7 @@ public class ResourceProviderR4ValueSetTest extends BaseResourceProviderR4Test { ValueSet toExpand = loadResourceFromClasspath(ValueSet.class, "/extensional-case-3-vs.xml"); - Parameters respParam = ourClient + Parameters respParam = myClient .operation() .onType(ValueSet.class) .named("expand") @@ -426,7 +424,7 @@ public class ResourceProviderR4ValueSetTest extends BaseResourceProviderR4Test { ValueSet toExpand = loadResourceFromClasspath(ValueSet.class, "/extensional-case-3-vs.xml"); - Parameters respParam = ourClient + Parameters respParam = myClient .operation() .onType(ValueSet.class) .named("expand") @@ -447,7 +445,7 @@ public class ResourceProviderR4ValueSetTest extends BaseResourceProviderR4Test { createLocalVsPointingAtBuiltInCodeSystem(); assertNotNull(myLocalValueSetId); - Parameters respParam = ourClient + Parameters respParam = myClient .operation() .onType(ValueSet.class) .named("expand") @@ -467,7 +465,7 @@ public class ResourceProviderR4ValueSetTest extends BaseResourceProviderR4Test { assertNotNull(myLocalVs); myLocalVs.setId(""); - Parameters respParam = ourClient + Parameters respParam = myClient .operation() .onType(ValueSet.class) .named("expand") @@ -489,7 +487,7 @@ public class ResourceProviderR4ValueSetTest extends BaseResourceProviderR4Test { loadAndPersistCodeSystemAndValueSet(); try { - ourClient + myClient .operation() .onType(ValueSet.class) .named("expand") @@ -502,7 +500,7 @@ public class ResourceProviderR4ValueSetTest extends BaseResourceProviderR4Test { try { ValueSet toExpand = loadResourceFromClasspath(ValueSet.class, "/r4/extensional-case-r4.xml"); - ourClient + myClient .operation() .onType(ValueSet.class) .named("expand") @@ -516,7 +514,7 @@ public class ResourceProviderR4ValueSetTest extends BaseResourceProviderR4Test { try { ValueSet toExpand = loadResourceFromClasspath(ValueSet.class, "/r4/extensional-case.xml"); - ourClient + myClient .operation() .onInstance(myExtensionalVsId) .named("expand") @@ -529,7 +527,7 @@ public class ResourceProviderR4ValueSetTest extends BaseResourceProviderR4Test { } try { - ourClient + myClient .operation() .onInstance(myExtensionalVsId) .named("expand") @@ -541,7 +539,7 @@ public class ResourceProviderR4ValueSetTest extends BaseResourceProviderR4Test { } try { - ourClient + myClient .operation() .onInstance(myExtensionalVsId) .named("expand") @@ -558,7 +556,7 @@ public class ResourceProviderR4ValueSetTest extends BaseResourceProviderR4Test { createLocalVsPointingAtBuiltInCodeSystem(); assertNotNull(myLocalValueSetId); - Parameters respParam = ourClient + Parameters respParam = myClient .operation() .onInstance(myLocalValueSetId) .named("expand") @@ -577,7 +575,7 @@ public class ResourceProviderR4ValueSetTest extends BaseResourceProviderR4Test { createExternalCsAndLocalVs(); assertNotNull(myLocalValueSetId); - Parameters respParam = ourClient + Parameters respParam = myClient .operation() .onInstance(myLocalValueSetId) .named("expand") @@ -597,7 +595,7 @@ public class ResourceProviderR4ValueSetTest extends BaseResourceProviderR4Test { @Test public void testExpandValueSetByBuiltInUrl() { - Parameters respParam = ourClient + Parameters respParam = myClient .operation() .onType(ValueSet.class) .named("expand") @@ -617,7 +615,7 @@ public class ResourceProviderR4ValueSetTest extends BaseResourceProviderR4Test { createExternalCsAndLocalVs(); assertNotNull(myLocalValueSetId); - Parameters respParam = ourClient + Parameters respParam = myClient .operation() .onType(ValueSet.class) .named("expand") @@ -640,7 +638,7 @@ public class ResourceProviderR4ValueSetTest extends BaseResourceProviderR4Test { assertNotNull(myLocalValueSetId); try { - ourClient + myClient .operation() .onInstance(myLocalValueSetId) .named("expand") @@ -659,15 +657,15 @@ public class ResourceProviderR4ValueSetTest extends BaseResourceProviderR4Test { cs.setContent(CodeSystemContentMode.COMPLETE); cs.setUrl("http://foo1"); cs.addConcept().setCode("foo1").setDisplay("foo1"); - ourClient.update().resource(cs).execute(); + myClient.update().resource(cs).execute(); ValueSet vs = new ValueSet(); vs.setId("ValueSet/VS179789"); vs.setUrl("http://bar"); vs.getCompose().addInclude().setSystem("http://foo1").addConcept().setCode("foo1"); - ourClient.update().resource(vs).execute(); + myClient.update().resource(vs).execute(); - ValueSet expanded = ourClient + ValueSet expanded = myClient .operation() .onInstance(new IdType("ValueSet/VS179789")) .named("$expand") @@ -683,15 +681,15 @@ public class ResourceProviderR4ValueSetTest extends BaseResourceProviderR4Test { cs.setContent(CodeSystemContentMode.COMPLETE); cs.setUrl("http://foo2"); cs.addConcept().setCode("foo2").setDisplay("foo2"); - ourClient.update().resource(cs).execute(); + myClient.update().resource(cs).execute(); vs = new ValueSet(); vs.setId("ValueSet/VS179789"); vs.setUrl("http://bar"); vs.getCompose().addInclude().setSystem("http://foo2").addConcept().setCode("foo2"); - ourClient.update().resource(vs).execute(); + myClient.update().resource(vs).execute(); - expanded = ourClient + expanded = myClient .operation() .onInstance(new IdType("ValueSet/VS179789")) .named("$expand") @@ -775,7 +773,7 @@ public class ResourceProviderR4ValueSetTest extends BaseResourceProviderR4Test { ValueSet updatedValueSet = valueSet; updatedValueSet.setName(valueSet.getName().concat(" - MODIFIED")); - String url = ourClient.getServerBase().concat("/").concat(myExtensionalVsId.getValueAsString()); + String url = myClient.getServerBase().concat("/").concat(myExtensionalVsId.getValueAsString()); Bundle bundle = new Bundle(); bundle.setType(Bundle.BundleType.TRANSACTION); bundle @@ -786,7 +784,7 @@ public class ResourceProviderR4ValueSetTest extends BaseResourceProviderR4Test { .setMethod(Bundle.HTTPVerb.PUT) .setUrl(url); ourLog.info("Transaction Bundle:\n" + myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(bundle)); - ourClient.transaction().withBundle(bundle).execute(); + myClient.transaction().withBundle(bundle).execute(); updatedValueSet = myValueSetDao.read(myExtensionalVsId); ourLog.info("Updated ValueSet:\n" + myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(updatedValueSet)); @@ -892,7 +890,7 @@ public class ResourceProviderR4ValueSetTest extends BaseResourceProviderR4Test { public void testValidateCodeOperationByCodeAndSystemInstance() throws Exception { loadAndPersistCodeSystemAndValueSet(); - Parameters respParam = ourClient + Parameters respParam = myClient .operation() .onInstance(myExtensionalVsId) .named("validate-code") @@ -953,7 +951,7 @@ public class ResourceProviderR4ValueSetTest extends BaseResourceProviderR4Test { public void testValidateCodeOperationByCodeAndSystemType() throws Exception { loadAndPersistCodeSystemAndValueSet(); - Parameters respParam = ourClient + Parameters respParam = myClient .operation() .onType(ValueSet.class) .named("validate-code") @@ -969,7 +967,7 @@ public class ResourceProviderR4ValueSetTest extends BaseResourceProviderR4Test { @Test public void testValidateCodeAgainstBuiltInSystem() { - Parameters respParam = ourClient + Parameters respParam = myClient .operation() .onType(ValueSet.class) .named("validate-code") @@ -1038,16 +1036,11 @@ public class ResourceProviderR4ValueSetTest extends BaseResourceProviderR4Test { } - @After + @AfterEach public void afterResetPreExpansionDefault() { myDaoConfig.setPreExpandValueSets(new DaoConfig().isPreExpandValueSets()); } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } - public static CodeSystem createExternalCs(IFhirResourceDao theCodeSystemDao, IResourceTableDao theResourceTableDao, ITermCodeSystemStorageSvc theTermCodeSystemStorageSvc, ServletRequestDetails theRequestDetails) { CodeSystem codeSystem = new CodeSystem(); codeSystem.setUrl(URL_MY_CODE_SYSTEM); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderSummaryModeR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderSummaryModeR4Test.java index ff4314f069f..09725f30a6f 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderSummaryModeR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ResourceProviderSummaryModeR4Test.java @@ -4,17 +4,16 @@ import ca.uhn.fhir.jpa.api.config.DaoConfig; import ca.uhn.fhir.jpa.search.SearchCoordinatorSvcImpl; import ca.uhn.fhir.rest.api.SearchTotalModeEnum; import ca.uhn.fhir.rest.api.SummaryEnum; -import ca.uhn.fhir.util.TestUtil; import com.google.common.collect.Lists; import org.hl7.fhir.r4.model.Bundle; import org.hl7.fhir.r4.model.Narrative; import org.hl7.fhir.r4.model.Patient; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.test.util.AopTestUtils; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; @SuppressWarnings("Duplicates") public class ResourceProviderSummaryModeR4Test extends BaseResourceProviderR4Test { @@ -23,7 +22,7 @@ public class ResourceProviderSummaryModeR4Test extends BaseResourceProviderR4Tes private SearchCoordinatorSvcImpl mySearchCoordinatorSvcRaw; @Override - @After + @AfterEach public void after() throws Exception { super.after(); myDaoConfig.setCountSearchResultsUpTo(null); @@ -33,6 +32,7 @@ public class ResourceProviderSummaryModeR4Test extends BaseResourceProviderR4Tes myDaoConfig.setDefaultTotalMode(null); } + @BeforeEach @Override public void before() throws Exception { super.before(); @@ -62,7 +62,7 @@ public class ResourceProviderSummaryModeR4Test extends BaseResourceProviderR4Tes */ @Test public void testSearchWithCount() { - Bundle outcome = ourClient + Bundle outcome = myClient .search() .forResource(Patient.class) .where(Patient.ACTIVE.exactly().code("true")) @@ -79,7 +79,7 @@ public class ResourceProviderSummaryModeR4Test extends BaseResourceProviderR4Tes */ @Test public void testSearchWithTotalAccurate() { - Bundle outcome = ourClient + Bundle outcome = myClient .search() .forResource(Patient.class) .where(Patient.ACTIVE.exactly().code("true")) @@ -98,7 +98,7 @@ public class ResourceProviderSummaryModeR4Test extends BaseResourceProviderR4Tes public void testSearchWithTotalAccurateSpecifiedAsDefault() { myDaoConfig.setDefaultTotalMode(SearchTotalModeEnum.ACCURATE); - Bundle outcome = ourClient + Bundle outcome = myClient .search() .forResource(Patient.class) .where(Patient.ACTIVE.exactly().code("true")) @@ -115,7 +115,7 @@ public class ResourceProviderSummaryModeR4Test extends BaseResourceProviderR4Tes */ @Test public void testSearchWithNoSummaryMode() { - Bundle outcome = ourClient + Bundle outcome = myClient .search() .forResource(Patient.class) .where(Patient.ACTIVE.exactly().code("true")) @@ -134,7 +134,7 @@ public class ResourceProviderSummaryModeR4Test extends BaseResourceProviderR4Tes public void testSearchTotalNoneOverridingDefault() { myDaoConfig.setDefaultTotalMode(SearchTotalModeEnum.ACCURATE); - Bundle outcome = ourClient + Bundle outcome = myClient .search() .forResource(Patient.class) .where(Patient.ACTIVE.exactly().code("true")) @@ -146,9 +146,5 @@ public class ResourceProviderSummaryModeR4Test extends BaseResourceProviderR4Tes assertEquals(10, outcome.getEntry().size()); } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ServerR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ServerR4Test.java index 4cd4ded20a5..7a6f1009202 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ServerR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/ServerR4Test.java @@ -5,7 +5,6 @@ import ca.uhn.fhir.rest.api.EncodingEnum; import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; import ca.uhn.fhir.rest.server.exceptions.PreconditionFailedException; import ca.uhn.fhir.util.ExtensionConstants; -import ca.uhn.fhir.util.TestUtil; import org.apache.commons.io.IOUtils; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; @@ -14,8 +13,7 @@ import org.hl7.fhir.r4.model.CapabilityStatement.CapabilityStatementRestResource import org.hl7.fhir.r4.model.CapabilityStatement.CapabilityStatementRestResourceSearchParamComponent; import org.hl7.fhir.r4.model.Extension; import org.hl7.fhir.r4.model.Patient; -import org.junit.AfterClass; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import java.io.IOException; @@ -23,9 +21,9 @@ import java.nio.charset.StandardCharsets; import java.util.HashSet; import java.util.Set; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.fail; public class ServerR4Test extends BaseResourceProviderR4Test { @@ -94,7 +92,7 @@ public class ServerR4Test extends BaseResourceProviderR4Test { public void testMetadataIncludesResourceCounts() { Patient p = new Patient(); p.setActive(true); - ourClient.create().resource(p).execute(); + myClient.create().resource(p).execute(); /* * Initial fetch after a clear should return @@ -102,7 +100,7 @@ public class ServerR4Test extends BaseResourceProviderR4Test { */ myResourceCountsCache.clear(); - CapabilityStatement capabilityStatement = ourClient + CapabilityStatement capabilityStatement = myClient .capabilities() .ofType(CapabilityStatement.class) .execute(); @@ -124,7 +122,7 @@ public class ServerR4Test extends BaseResourceProviderR4Test { */ myResourceCountsCache.update(); - capabilityStatement = ourClient + capabilityStatement = myClient .capabilities() .ofType(CapabilityStatement.class) .execute(); @@ -142,10 +140,4 @@ public class ServerR4Test extends BaseResourceProviderR4Test { } - - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } - } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/StaleSearchDeletingSvcR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/StaleSearchDeletingSvcR4Test.java index c66c824022c..56cabaf802b 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/StaleSearchDeletingSvcR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/StaleSearchDeletingSvcR4Test.java @@ -13,15 +13,13 @@ import ca.uhn.fhir.jpa.search.cache.DatabaseSearchCacheSvcImpl; import ca.uhn.fhir.rest.gclient.IClientExecutable; import ca.uhn.fhir.rest.gclient.IQuery; import ca.uhn.fhir.rest.server.exceptions.ResourceGoneException; -import ca.uhn.fhir.util.TestUtil; import org.apache.commons.lang3.time.DateUtils; import org.hl7.fhir.r4.model.Bundle; import org.hl7.fhir.r4.model.Bundle.BundleLinkComponent; import org.hl7.fhir.r4.model.Patient; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.util.AopTestUtils; @@ -29,8 +27,13 @@ import java.util.Date; import java.util.UUID; import static ca.uhn.fhir.jpa.util.TestUtil.sleepAtLeast; -import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.blankOrNullString; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.not; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.fail; public class StaleSearchDeletingSvcR4Test extends BaseResourceProviderR4Test { @@ -43,7 +46,7 @@ public class StaleSearchDeletingSvcR4Test extends BaseResourceProviderR4Test { private ISearchIncludeDao mySearchIncludeDao; @Override - @After() + @AfterEach() public void after() throws Exception { super.after(); DatabaseSearchCacheSvcImpl staleSearchDeletingSvc = AopTestUtils.getTargetObject(mySearchCacheSvc); @@ -53,7 +56,7 @@ public class StaleSearchDeletingSvcR4Test extends BaseResourceProviderR4Test { } @Override - @Before + @BeforeEach public void before() throws Exception { super.before(); DatabaseSearchCacheSvcImpl staleSearchDeletingSvc = AopTestUtils.getTargetObject(mySearchCacheSvc); @@ -69,7 +72,7 @@ public class StaleSearchDeletingSvcR4Test extends BaseResourceProviderR4Test { myPatientDao.create(pt1, mySrd).getId().toUnqualifiedVersionless(); } - IClientExecutable, Bundle> search = ourClient + IClientExecutable, Bundle> search = myClient .search() .forResource(Patient.class) .where(Patient.NAME.matches().value("Everything")) @@ -86,12 +89,12 @@ public class StaleSearchDeletingSvcR4Test extends BaseResourceProviderR4Test { String nextLinkUrl = nextLink.getUrl(); assertThat(nextLinkUrl, not(blankOrNullString())); - Bundle resp2 = ourClient.search().byUrl(nextLinkUrl).returnBundle(Bundle.class).execute(); + Bundle resp2 = myClient.search().byUrl(nextLinkUrl).returnBundle(Bundle.class).execute(); ourLog.info(myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(resp2)); myStaleSearchDeletingSvc.pollForStaleSearchesAndDeleteThem(); - ourClient.search().byUrl(nextLinkUrl).returnBundle(Bundle.class).execute(); + myClient.search().byUrl(nextLinkUrl).returnBundle(Bundle.class).execute(); Thread.sleep(20); myDaoConfig.setExpireSearchResultsAfterMillis(10); @@ -99,7 +102,7 @@ public class StaleSearchDeletingSvcR4Test extends BaseResourceProviderR4Test { myStaleSearchDeletingSvc.pollForStaleSearchesAndDeleteThem(); try { - ourClient.search().byUrl(nextLinkUrl).returnBundle(Bundle.class).execute(); + myClient.search().byUrl(nextLinkUrl).returnBundle(Bundle.class).execute(); fail(); } catch (ResourceGoneException e) { assertThat(e.getMessage(), containsString("does not exist and may have expired")); @@ -202,10 +205,5 @@ public class StaleSearchDeletingSvcR4Test extends BaseResourceProviderR4Test { } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } - } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/SubscriptionsR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/SubscriptionsR4Test.java index abddabd05fb..d914e804c39 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/SubscriptionsR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/SubscriptionsR4Test.java @@ -3,7 +3,6 @@ package ca.uhn.fhir.jpa.provider.r4; import ca.uhn.fhir.jpa.util.SubscriptionsRequireManualActivationInterceptorR4; import ca.uhn.fhir.rest.api.EncodingEnum; import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; -import ca.uhn.fhir.util.TestUtil; import org.eclipse.jetty.websocket.api.Session; import org.eclipse.jetty.websocket.api.annotations.OnWebSocketConnect; import org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage; @@ -13,21 +12,22 @@ import org.hl7.fhir.instance.model.api.IIdType; import org.hl7.fhir.r4.model.Subscription; import org.hl7.fhir.r4.model.Subscription.SubscriptionChannelType; import org.hl7.fhir.r4.model.Subscription.SubscriptionStatus; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.util.ArrayList; import java.util.List; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; public class SubscriptionsR4Test extends BaseResourceProviderR4Test { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(SubscriptionsR4Test.class); @Override + @BeforeEach public void beforeCreateInterceptor() { super.beforeCreateInterceptor(); @@ -36,12 +36,12 @@ public class SubscriptionsR4Test extends BaseResourceProviderR4Test { myInterceptorRegistry.registerInterceptor(interceptor); } - @Before + @BeforeEach public void beforeDisableResultReuse() { myDaoConfig.setReuseCachedSearchResultsForMillis(null); } - @Before + @BeforeEach public void beforeEnableScheduling() { myDaoConfig.setSchedulingDisabled(false); } @@ -55,7 +55,7 @@ public class SubscriptionsR4Test extends BaseResourceProviderR4Test { subs.getChannel().setEndpoint("http://localhost:8888"); subs.setCriteria("Observation?identifier=123"); try { - ourClient.create().resource(subs).execute(); + myClient.create().resource(subs).execute(); fail(); } catch (UnprocessableEntityException e) { assertThat(e.getMessage(), containsString("Subscription.status must be populated on this server")); @@ -63,14 +63,14 @@ public class SubscriptionsR4Test extends BaseResourceProviderR4Test { subs.setId("ABC"); try { - ourClient.update().resource(subs).execute(); + myClient.update().resource(subs).execute(); fail(); } catch (UnprocessableEntityException e) { assertThat(e.getMessage(), containsString("Subscription.status must be populated on this server")); } subs.setStatus(SubscriptionStatus.REQUESTED); - ourClient.update().resource(subs).execute(); + myClient.update().resource(subs).execute(); } @Test @@ -82,7 +82,7 @@ public class SubscriptionsR4Test extends BaseResourceProviderR4Test { subs.setStatus(SubscriptionStatus.ACTIVE); subs.setCriteria("Observation?identifier=123"); try { - ourClient.create().resource(subs).execute(); + myClient.create().resource(subs).execute(); fail(); } catch (UnprocessableEntityException e) { assertEquals("HTTP 422 Unprocessable Entity: Subscription.status must be 'off' or 'requested' on a newly created subscription", e.getMessage()); @@ -90,7 +90,7 @@ public class SubscriptionsR4Test extends BaseResourceProviderR4Test { subs.setId("ABC"); try { - ourClient.update().resource(subs).execute(); + myClient.update().resource(subs).execute(); fail(); } catch (UnprocessableEntityException e) { assertEquals("HTTP 422 Unprocessable Entity: Subscription.status must be 'off' or 'requested' on a newly created subscription", e.getMessage()); @@ -107,21 +107,21 @@ public class SubscriptionsR4Test extends BaseResourceProviderR4Test { subs.getChannel().setEndpoint("http://localhost:8888"); subs.setStatus(SubscriptionStatus.REQUESTED); subs.setCriteria("Observation?identifier=123"); - IIdType id = ourClient.create().resource(subs).execute().getId().toUnqualifiedVersionless(); + IIdType id = myClient.create().resource(subs).execute().getId().toUnqualifiedVersionless(); subs.setId(id); try { subs.setStatus(SubscriptionStatus.ACTIVE); - ourClient.update().resource(subs).execute(); + myClient.update().resource(subs).execute(); fail(); } catch (UnprocessableEntityException e) { assertEquals("HTTP 422 Unprocessable Entity: Subscription.status can not be changed from 'requested' to 'active'", e.getMessage()); } try { - subs.setStatus((SubscriptionStatus) null); - ourClient.update().resource(subs).execute(); + subs.setStatus(null); + myClient.update().resource(subs).execute(); fail(); } catch (UnprocessableEntityException e) { assertThat(e.getMessage(), containsString("Subscription.status must be populated on this server")); @@ -139,33 +139,29 @@ public class SubscriptionsR4Test extends BaseResourceProviderR4Test { subs.getChannel().setEndpoint("http://localhost:8888"); subs.setCriteria("Observation?identifier=123"); subs.setStatus(SubscriptionStatus.REQUESTED); - IIdType id = ourClient.create().resource(subs).execute().getId(); + IIdType id = myClient.create().resource(subs).execute().getId(); subs.setId(id); try { subs.setStatus(SubscriptionStatus.ACTIVE); - ourClient.update().resource(subs).execute(); + myClient.update().resource(subs).execute(); fail(); } catch (UnprocessableEntityException e) { assertEquals("HTTP 422 Unprocessable Entity: Subscription.status can not be changed from 'requested' to 'active'", e.getMessage()); } try { - subs.setStatus((SubscriptionStatus) null); - ourClient.update().resource(subs).execute(); + subs.setStatus(null); + myClient.update().resource(subs).execute(); fail(); } catch (UnprocessableEntityException e) { assertThat(e.getMessage(), containsString("Subscription.status must be populated on this server")); } subs.setStatus(SubscriptionStatus.OFF); - ourClient.update().resource(subs).execute(); + myClient.update().resource(subs).execute(); } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } public class BaseSocket { protected String myError; diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/SystemProviderR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/SystemProviderR4Test.java index 6e35a230e08..7f48fde859d 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/SystemProviderR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/SystemProviderR4Test.java @@ -1,12 +1,19 @@ package ca.uhn.fhir.jpa.provider.r4; import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.context.FhirVersionEnum; import ca.uhn.fhir.interceptor.api.Hook; import ca.uhn.fhir.interceptor.api.Pointcut; -import ca.uhn.fhir.jpa.api.config.DaoConfig; import ca.uhn.fhir.jpa.dao.r4.BaseJpaR4Test; import ca.uhn.fhir.jpa.provider.SystemProviderDstu2Test; -import ca.uhn.fhir.jpa.rp.r4.*; +import ca.uhn.fhir.jpa.rp.r4.BinaryResourceProvider; +import ca.uhn.fhir.jpa.rp.r4.DiagnosticReportResourceProvider; +import ca.uhn.fhir.jpa.rp.r4.LocationResourceProvider; +import ca.uhn.fhir.jpa.rp.r4.ObservationResourceProvider; +import ca.uhn.fhir.jpa.rp.r4.OrganizationResourceProvider; +import ca.uhn.fhir.jpa.rp.r4.PatientResourceProvider; +import ca.uhn.fhir.jpa.rp.r4.PractitionerResourceProvider; +import ca.uhn.fhir.jpa.rp.r4.ServiceRequestResourceProvider; import ca.uhn.fhir.jpa.searchparam.SearchParameterMap; import ca.uhn.fhir.rest.api.Constants; import ca.uhn.fhir.rest.api.EncodingEnum; @@ -22,7 +29,6 @@ import ca.uhn.fhir.rest.server.interceptor.RequestValidatingInterceptor; import ca.uhn.fhir.rest.server.interceptor.ResponseHighlighterInterceptor; import ca.uhn.fhir.test.utilities.JettyUtil; import ca.uhn.fhir.util.BundleUtil; -import ca.uhn.fhir.util.TestUtil; import ca.uhn.fhir.validation.ResultSeverityEnum; import com.google.common.base.Charsets; import org.apache.commons.io.IOUtils; @@ -38,13 +44,26 @@ import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletHolder; -import org.hl7.fhir.instance.model.api.IIdType; import org.hl7.fhir.common.hapi.validation.validator.FhirInstanceValidator; -import org.hl7.fhir.r4.model.*; +import org.hl7.fhir.instance.model.api.IIdType; +import org.hl7.fhir.r4.model.Bundle; import org.hl7.fhir.r4.model.Bundle.BundleType; import org.hl7.fhir.r4.model.Bundle.HTTPVerb; +import org.hl7.fhir.r4.model.DecimalType; import org.hl7.fhir.r4.model.Enumerations.AdministrativeGender; -import org.junit.*; +import org.hl7.fhir.r4.model.IdType; +import org.hl7.fhir.r4.model.Observation; +import org.hl7.fhir.r4.model.OperationDefinition; +import org.hl7.fhir.r4.model.OperationOutcome; +import org.hl7.fhir.r4.model.Organization; +import org.hl7.fhir.r4.model.Parameters; +import org.hl7.fhir.r4.model.Patient; +import org.hl7.fhir.r4.model.StringType; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; @@ -54,33 +73,33 @@ import java.nio.charset.StandardCharsets; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; -import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.not; +import static org.hamcrest.Matchers.startsWith; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; public class SystemProviderR4Test extends BaseJpaR4Test { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(SystemProviderR4Test.class); private static RestfulServer ourRestServer; - private static IGenericClient ourClient; private static FhirContext ourCtx; private static CloseableHttpClient ourHttpClient; private static Server ourServer; private static String ourServerBase; + private IGenericClient myClient; private SimpleRequestHeaderInterceptor mySimpleHeaderInterceptor; @SuppressWarnings("deprecation") - @After + @AfterEach public void after() { - ourClient.unregisterInterceptor(mySimpleHeaderInterceptor); + myClient.unregisterInterceptor(mySimpleHeaderInterceptor); } - @Before - public void before() { - mySimpleHeaderInterceptor = new SimpleRequestHeaderInterceptor(); - ourClient.registerInterceptor(mySimpleHeaderInterceptor); - } - - @Before + @BeforeEach public void beforeStartServer() throws Exception { if (ourRestServer == null) { PatientResourceProvider patientRp = new PatientResourceProvider(); @@ -122,13 +141,13 @@ public class SystemProviderR4Test extends BaseJpaR4Test { servletHolder.setServlet(restServer); proxyHandler.addServlet(servletHolder, "/fhir/context/*"); - ourCtx = FhirContext.forR4(); + ourCtx = FhirContext.forCached(FhirVersionEnum.R4); restServer.setFhirContext(ourCtx); ourServer.setHandler(proxyHandler); JettyUtil.startServer(ourServer); - int myPort = JettyUtil.getPortForStartedServer(ourServer); - ourServerBase = "http://localhost:" + myPort + "/fhir/context"; + int myPort = JettyUtil.getPortForStartedServer(ourServer); + ourServerBase = "http://localhost:" + myPort + "/fhir/context"; PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(5000, TimeUnit.MILLISECONDS); HttpClientBuilder builder = HttpClientBuilder.create(); @@ -136,11 +155,14 @@ public class SystemProviderR4Test extends BaseJpaR4Test { ourHttpClient = builder.build(); ourCtx.getRestfulClientFactory().setSocketTimeout(600 * 1000); - ourClient = ourCtx.newRestfulGenericClient(ourServerBase); - ourClient.setLogRequestAndResponse(true); ourRestServer = restServer; } + myClient = ourCtx.newRestfulGenericClient(ourServerBase); + myClient.setLogRequestAndResponse(true); + mySimpleHeaderInterceptor = new SimpleRequestHeaderInterceptor(); + myClient.registerInterceptor(mySimpleHeaderInterceptor); + ourRestServer.setDefaultResponseEncoding(EncodingEnum.XML); ourRestServer.setPagingProvider(myPagingProvider); } @@ -155,7 +177,7 @@ public class SystemProviderR4Test extends BaseJpaR4Test { for (int i = 0; i < 11; i++) { Patient p = new Patient(); p.addName().setFamily("Name" + i); - ourClient.create().resource(p).execute(); + myClient.create().resource(p).execute(); } HttpGet get = new HttpGet(ourServerBase + "/Patient/$everything"); @@ -187,7 +209,7 @@ public class SystemProviderR4Test extends BaseJpaR4Test { for (int i = 0; i < 11; i++) { Patient p = new Patient(); p.addName().setFamily("Name" + i); - ourClient.create().resource(p).execute(); + myClient.create().resource(p).execute(); } HttpGet get = new HttpGet(ourServerBase + "/Patient/$everything"); @@ -219,7 +241,7 @@ public class SystemProviderR4Test extends BaseJpaR4Test { @Test public void testGetOperationDefinition() { - OperationDefinition op = ourClient.read(OperationDefinition.class, "-s-get-resource-counts"); + OperationDefinition op = myClient.read(OperationDefinition.class, "-s-get-resource-counts"); assertEquals("get-resource-counts", op.getCode()); } @@ -304,7 +326,7 @@ public class SystemProviderR4Test extends BaseJpaR4Test { myObservationDao.update(obs, mySrd); // Try to wait for the indexing to complete - waitForSize(2, ()-> fetchSuggestionCount(ptId)); + waitForSize(2, () -> fetchSuggestionCount(ptId)); HttpGet get = new HttpGet(ourServerBase + "/$suggest-keywords?context=Patient/" + ptId.getIdPart() + "/$everything&searchParam=_content&text=zxc&_pretty=true&_format=xml"); CloseableHttpResponse http = ourHttpClient.execute(get); @@ -392,7 +414,7 @@ public class SystemProviderR4Test extends BaseJpaR4Test { Bundle req = new Bundle(); req.setType(BundleType.TRANSACTION); req.addEntry().getRequest().setMethod(HTTPVerb.GET).setUrl("Patient?_summary=count"); - Bundle resp = ourClient.transaction().withBundle(req).execute(); + Bundle resp = myClient.transaction().withBundle(req).execute(); ourLog.info(ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(resp)); assertEquals(1, resp.getEntry().size()); @@ -406,10 +428,10 @@ public class SystemProviderR4Test extends BaseJpaR4Test { Patient patient = new Patient(); patient.addName().setFamily("Unique762"); myPatientDao.create(patient, mySrd); - Bundle resp1 = (Bundle) ourClient.search().byUrl("Patient?name=Unique762&_summary=count").execute(); + Bundle resp1 = (Bundle) myClient.search().byUrl("Patient?name=Unique762&_summary=count").execute(); ourLog.info(ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(resp1)); assertEquals(1, resp1.getTotal()); - Bundle resp2 = (Bundle) ourClient.search().byUrl("Patient?name=Unique762&_summary=count").execute(); + Bundle resp2 = (Bundle) myClient.search().byUrl("Patient?name=Unique762&_summary=count").execute(); assertEquals(1, resp2.getTotal()); ourLog.info(ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(resp2)); } @@ -427,7 +449,7 @@ public class SystemProviderR4Test extends BaseJpaR4Test { req = new Bundle(); req.setType(BundleType.TRANSACTION); req.addEntry().setResource(p).getRequest().setMethod(HTTPVerb.POST).setUrl("Patient"); - resp = ourClient.transaction().withBundle(req).execute(); + resp = myClient.transaction().withBundle(req).execute(); assertEquals(null, resp.getEntry().get(0).getResource()); assertEquals("201 Created", resp.getEntry().get(0).getResponse().getStatus()); @@ -437,7 +459,7 @@ public class SystemProviderR4Test extends BaseJpaR4Test { req = new Bundle(); req.setType(BundleType.TRANSACTION); req.addEntry().setResource(p).getRequest().setMethod(HTTPVerb.POST).setUrl("Patient"); - resp = ourClient.transaction().withBundle(req).execute(); + resp = myClient.transaction().withBundle(req).execute(); assertEquals(null, resp.getEntry().get(0).getResource()); assertEquals("201 Created", resp.getEntry().get(0).getResponse().getStatus()); @@ -447,7 +469,7 @@ public class SystemProviderR4Test extends BaseJpaR4Test { req = new Bundle(); req.setType(BundleType.TRANSACTION); req.addEntry().setResource(p).getRequest().setMethod(HTTPVerb.POST).setUrl("Patient"); - resp = ourClient.transaction().withBundle(req).execute(); + resp = myClient.transaction().withBundle(req).execute(); assertEquals(Patient.class, resp.getEntry().get(0).getResource().getClass()); assertEquals("201 Created", resp.getEntry().get(0).getResponse().getStatus()); } @@ -460,7 +482,7 @@ public class SystemProviderR4Test extends BaseJpaR4Test { ourLog.info("** Beginning pass {}", i); Bundle input = myFhirCtx.newJsonParser().parseResource(Bundle.class, IOUtils.toString(getClass().getResourceAsStream("/r4/createdeletebundle.json"), Charsets.UTF_8)); - ourClient.transaction().withBundle(input).execute(); + myClient.transaction().withBundle(input).execute(); myPatientDao.read(new IdType("Patient/Patient1063259")); @@ -495,9 +517,9 @@ public class SystemProviderR4Test extends BaseJpaR4Test { } private void deleteAllOfType(String theType) { - BundleUtil.toListOfResources(myFhirCtx, ourClient.search().forResource(theType).execute()) + BundleUtil.toListOfResources(myFhirCtx, myClient.search().forResource(theType).execute()) .forEach(t -> { - ourClient.delete().resourceById(t.getIdElement()).execute(); + myClient.delete().resourceById(t.getIdElement()).execute(); }); } @@ -509,7 +531,7 @@ public class SystemProviderR4Test extends BaseJpaR4Test { p.addName().setFamily("van de Heuvelcx85ioqWJbI").addGiven("Pietercx85ioqWJbI"); IIdType id = myPatientDao.create(p, mySrd).getId().toUnqualifiedVersionless(); - ourClient.read().resource(Patient.class).withId(id); + myClient.read().resource(Patient.class).withId(id); Bundle inputBundle = new Bundle(); inputBundle.setType(BundleType.TRANSACTION); @@ -536,7 +558,7 @@ public class SystemProviderR4Test extends BaseJpaR4Test { } try { - ourClient.read().resource(Patient.class).withId(id).execute(); + myClient.read().resource(Patient.class).withId(id).execute(); fail(); } catch (ResourceGoneException e) { // good @@ -548,7 +570,7 @@ public class SystemProviderR4Test extends BaseJpaR4Test { public void testTransactionFromBundle() throws Exception { InputStream bundleRes = SystemProviderR4Test.class.getResourceAsStream("/transaction_link_patient_eve.xml"); String bundle = IOUtils.toString(bundleRes, StandardCharsets.UTF_8); - String response = ourClient.transaction().withBundle(bundle).prettyPrint().execute(); + String response = myClient.transaction().withBundle(bundle).prettyPrint().execute(); ourLog.info(response); } @@ -557,7 +579,7 @@ public class SystemProviderR4Test extends BaseJpaR4Test { InputStream bundleRes = SystemProviderR4Test.class.getResourceAsStream("/transaction_link_patient_eve_temp.xml"); String bundle = IOUtils.toString(bundleRes, StandardCharsets.UTF_8); - String response = ourClient.transaction().withBundle(bundle).prettyPrint().execute(); + String response = myClient.transaction().withBundle(bundle).prettyPrint().execute(); ourLog.info(response); Bundle resp = ourCtx.newXmlParser().parseResource(Bundle.class, response); @@ -573,7 +595,7 @@ public class SystemProviderR4Test extends BaseJpaR4Test { bundleRes = SystemProviderR4Test.class.getResourceAsStream("/transaction_link_patient_eve_temp.xml"); bundle = IOUtils.toString(bundleRes, StandardCharsets.UTF_8); - response = ourClient.transaction().withBundle(bundle).prettyPrint().execute(); + response = myClient.transaction().withBundle(bundle).prettyPrint().execute(); ourLog.info(response); resp = ourCtx.newXmlParser().parseResource(Bundle.class, response); @@ -593,12 +615,12 @@ public class SystemProviderR4Test extends BaseJpaR4Test { * This is Gramahe's test transaction - it requires some set up in order to work */ @Test - @Ignore + @Disabled public void testTransactionFromBundle3() throws Exception { InputStream bundleRes = SystemProviderR4Test.class.getResourceAsStream("/grahame-transaction.xml"); String bundle = IOUtils.toString(bundleRes, StandardCharsets.UTF_8); - String response = ourClient.transaction().withBundle(bundle).prettyPrint().execute(); + String response = myClient.transaction().withBundle(bundle).prettyPrint().execute(); ourLog.info(response); } @@ -606,7 +628,7 @@ public class SystemProviderR4Test extends BaseJpaR4Test { public void testTransactionFromBundle4() throws Exception { InputStream bundleRes = SystemProviderR4Test.class.getResourceAsStream("/simone_bundle.xml"); String bundle = IOUtils.toString(bundleRes, StandardCharsets.UTF_8); - String response = ourClient.transaction().withBundle(bundle).prettyPrint().execute(); + String response = myClient.transaction().withBundle(bundle).prettyPrint().execute(); ourLog.info(response); Bundle bundleResp = ourCtx.newXmlParser().parseResource(Bundle.class, response); IdType id = new IdType(bundleResp.getEntry().get(0).getResponse().getLocation()); @@ -622,7 +644,7 @@ public class SystemProviderR4Test extends BaseJpaR4Test { InputStream bundleRes = SystemProviderR4Test.class.getResourceAsStream("/simone_bundle2.xml"); String bundle = IOUtils.toString(bundleRes, StandardCharsets.UTF_8); try { - ourClient.transaction().withBundle(bundle).prettyPrint().execute(); + myClient.transaction().withBundle(bundle).prettyPrint().execute(); fail(); } catch (InvalidRequestException e) { OperationOutcome oo = (OperationOutcome) e.getOperationOutcome(); @@ -635,7 +657,7 @@ public class SystemProviderR4Test extends BaseJpaR4Test { public void testTransactionFromBundle6() throws Exception { InputStream bundleRes = SystemProviderR4Test.class.getResourceAsStream("/simone_bundle3.xml"); String bundle = IOUtils.toString(bundleRes, StandardCharsets.UTF_8); - ourClient.transaction().withBundle(bundle).prettyPrint().execute(); + myClient.transaction().withBundle(bundle).prettyPrint().execute(); // try { // fail(); // } catch (InvalidRequestException e) { @@ -656,7 +678,7 @@ public class SystemProviderR4Test extends BaseJpaR4Test { Bundle req = new Bundle(); req.setType(BundleType.TRANSACTION); req.addEntry().getRequest().setMethod(HTTPVerb.GET).setUrl("Patient?"); - Bundle resp = ourClient.transaction().withBundle(req).execute(); + Bundle resp = myClient.transaction().withBundle(req).execute(); ourLog.info(ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(resp)); assertEquals(1, resp.getEntry().size()); @@ -679,7 +701,7 @@ public class SystemProviderR4Test extends BaseJpaR4Test { bundle.addEntry().setResource(patient); try { - ourClient.transaction().withBundle(bundle).prettyPrint().execute(); + myClient.transaction().withBundle(bundle).prettyPrint().execute(); fail(); } catch (InvalidRequestException e) { assertThat(e.toString(), containsString("missing or invalid HTTP Verb")); @@ -748,7 +770,7 @@ public class SystemProviderR4Test extends BaseJpaR4Test { * FOrmat has changed, source is no longer valid */ @Test - @Ignore + @Disabled public void testValidateUsingIncomingResources() throws Exception { FhirInstanceValidator val = new FhirInstanceValidator(myValidationSupport); RequestValidatingInterceptor interceptor = new RequestValidatingInterceptor(); @@ -787,7 +809,7 @@ public class SystemProviderR4Test extends BaseJpaR4Test { @Test() public void testEndpointInterceptorIsCalledForTransaction() { // Just to get this out of the way - ourClient.forceConformanceCheck(); + myClient.forceConformanceCheck(); // Register an interceptor on the response AtomicBoolean called = new AtomicBoolean(false); @@ -812,7 +834,7 @@ public class SystemProviderR4Test extends BaseJpaR4Test { .setMethod(Bundle.HTTPVerb.POST) .setUrl("Patient"); - ourClient.transaction().withBundle(b).execute(); + myClient.transaction().withBundle(b).execute(); assertTrue(called.get()); @@ -823,11 +845,9 @@ public class SystemProviderR4Test extends BaseJpaR4Test { } - - @AfterClass + @AfterAll public static void afterClassClearContext() throws Exception { JettyUtil.closeServer(ourServer); - TestUtil.clearAllStaticFieldsForUnitTest(); } } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/SystemProviderTransactionSearchR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/SystemProviderTransactionSearchR4Test.java index 910d03324e4..df65b4de7d0 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/SystemProviderTransactionSearchR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/SystemProviderTransactionSearchR4Test.java @@ -1,6 +1,7 @@ package ca.uhn.fhir.jpa.provider.r4; import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.context.FhirVersionEnum; import ca.uhn.fhir.jpa.api.config.DaoConfig; import ca.uhn.fhir.jpa.dao.r4.BaseJpaR4Test; import ca.uhn.fhir.jpa.rp.r4.MedicationRequestResourceProvider; @@ -33,20 +34,20 @@ import org.hl7.fhir.r4.model.Medication; import org.hl7.fhir.r4.model.MedicationRequest; import org.hl7.fhir.r4.model.Patient; import org.hl7.fhir.r4.model.Reference; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.util.ArrayList; import java.util.List; import java.util.concurrent.TimeUnit; -import static org.hamcrest.Matchers.contains; -import static org.hamcrest.Matchers.not; -import static org.hamcrest.Matchers.nullValue; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.*; +import static org.junit.jupiter.api.Assertions.*; + +import ca.uhn.fhir.test.utilities.JettyUtil; public class SystemProviderTransactionSearchR4Test extends BaseJpaR4Test { @@ -61,19 +62,13 @@ public class SystemProviderTransactionSearchR4Test extends BaseJpaR4Test { @SuppressWarnings("deprecation") - @After + @AfterEach public void after() { ourClient.unregisterInterceptor(mySimpleHeaderInterceptor); myDaoConfig.setMaximumSearchResultCountInTransaction(new DaoConfig().getMaximumSearchResultCountInTransaction()); } - @Before - public void before() { - mySimpleHeaderInterceptor = new SimpleRequestHeaderInterceptor(); - ourClient.registerInterceptor(mySimpleHeaderInterceptor); - } - - @Before + @BeforeEach public void beforeStartServer() throws Exception { if (myRestServer == null) { PatientResourceProvider patientRp = new PatientResourceProvider(); @@ -108,7 +103,7 @@ public class SystemProviderTransactionSearchR4Test extends BaseJpaR4Test { servletHolder.setServlet(restServer); proxyHandler.addServlet(servletHolder, "/fhir/context/*"); - ourCtx = FhirContext.forR4(); + ourCtx = FhirContext.forCached(FhirVersionEnum.R4); restServer.setFhirContext(ourCtx); ourServer.setHandler(proxyHandler); @@ -127,6 +122,9 @@ public class SystemProviderTransactionSearchR4Test extends BaseJpaR4Test { myRestServer = restServer; } + mySimpleHeaderInterceptor = new SimpleRequestHeaderInterceptor(); + ourClient.registerInterceptor(mySimpleHeaderInterceptor); + myRestServer.setDefaultResponseEncoding(EncodingEnum.XML); myRestServer.setPagingProvider(myPagingProvider); } @@ -386,10 +384,9 @@ public class SystemProviderTransactionSearchR4Test extends BaseJpaR4Test { return retVal; } - @AfterClass + @AfterAll public static void afterClassClearContext() throws Exception { JettyUtil.closeServer(ourServer); - TestUtil.clearAllStaticFieldsForUnitTest(); } } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/TerminologyUploaderProviderR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/TerminologyUploaderProviderR4Test.java index e53eeb26014..5dc82c5fbc1 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/TerminologyUploaderProviderR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r4/TerminologyUploaderProviderR4Test.java @@ -6,36 +6,54 @@ import ca.uhn.fhir.jpa.entity.TermConcept; import ca.uhn.fhir.jpa.model.util.JpaConstants; import ca.uhn.fhir.jpa.provider.TerminologyUploaderProvider; import ca.uhn.fhir.jpa.term.api.ITermLoaderSvc; -import ca.uhn.fhir.model.api.annotation.SimpleSetter; import ca.uhn.fhir.rest.client.interceptor.LoggingInterceptor; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; -import ca.uhn.fhir.util.TestUtil; import com.google.common.base.Charsets; import org.apache.commons.io.IOUtils; -import org.hl7.fhir.r4.model.*; -import org.junit.AfterClass; -import org.junit.Test; -import org.mockito.ArgumentCaptor; -import org.mockito.Captor; +import org.hl7.fhir.r4.model.Attachment; +import org.hl7.fhir.r4.model.CodeSystem; +import org.hl7.fhir.r4.model.IntegerType; +import org.hl7.fhir.r4.model.Parameters; +import org.hl7.fhir.r4.model.Reference; +import org.hl7.fhir.r4.model.UriType; +import org.junit.jupiter.api.Test; -import javax.lang.model.util.Types; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.util.Arrays; import java.util.List; -import java.util.Optional; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; -import static ca.uhn.fhir.jpa.term.loinc.LoincUploadPropertiesEnum.*; +import static ca.uhn.fhir.jpa.term.loinc.LoincUploadPropertiesEnum.LOINC_ANSWERLIST_FILE_DEFAULT; +import static ca.uhn.fhir.jpa.term.loinc.LoincUploadPropertiesEnum.LOINC_ANSWERLIST_LINK_FILE_DEFAULT; +import static ca.uhn.fhir.jpa.term.loinc.LoincUploadPropertiesEnum.LOINC_DOCUMENT_ONTOLOGY_FILE_DEFAULT; +import static ca.uhn.fhir.jpa.term.loinc.LoincUploadPropertiesEnum.LOINC_FILE_DEFAULT; +import static ca.uhn.fhir.jpa.term.loinc.LoincUploadPropertiesEnum.LOINC_GROUP_FILE_DEFAULT; +import static ca.uhn.fhir.jpa.term.loinc.LoincUploadPropertiesEnum.LOINC_GROUP_TERMS_FILE_DEFAULT; +import static ca.uhn.fhir.jpa.term.loinc.LoincUploadPropertiesEnum.LOINC_HIERARCHY_FILE_DEFAULT; +import static ca.uhn.fhir.jpa.term.loinc.LoincUploadPropertiesEnum.LOINC_IEEE_MEDICAL_DEVICE_CODE_MAPPING_TABLE_FILE_DEFAULT; +import static ca.uhn.fhir.jpa.term.loinc.LoincUploadPropertiesEnum.LOINC_IMAGING_DOCUMENT_CODES_FILE_DEFAULT; +import static ca.uhn.fhir.jpa.term.loinc.LoincUploadPropertiesEnum.LOINC_PARENT_GROUP_FILE_DEFAULT; +import static ca.uhn.fhir.jpa.term.loinc.LoincUploadPropertiesEnum.LOINC_PART_FILE_DEFAULT; +import static ca.uhn.fhir.jpa.term.loinc.LoincUploadPropertiesEnum.LOINC_PART_LINK_FILE_PRIMARY_DEFAULT; +import static ca.uhn.fhir.jpa.term.loinc.LoincUploadPropertiesEnum.LOINC_PART_LINK_FILE_SUPPLEMENTARY_DEFAULT; +import static ca.uhn.fhir.jpa.term.loinc.LoincUploadPropertiesEnum.LOINC_PART_RELATED_CODE_MAPPING_FILE_DEFAULT; +import static ca.uhn.fhir.jpa.term.loinc.LoincUploadPropertiesEnum.LOINC_RSNA_PLAYBOOK_FILE_DEFAULT; +import static ca.uhn.fhir.jpa.term.loinc.LoincUploadPropertiesEnum.LOINC_TOP2000_COMMON_LAB_RESULTS_SI_FILE_DEFAULT; +import static ca.uhn.fhir.jpa.term.loinc.LoincUploadPropertiesEnum.LOINC_TOP2000_COMMON_LAB_RESULTS_US_FILE_DEFAULT; +import static ca.uhn.fhir.jpa.term.loinc.LoincUploadPropertiesEnum.LOINC_UNIVERSAL_LAB_ORDER_VALUESET_FILE_DEFAULT; +import static ca.uhn.fhir.jpa.term.loinc.LoincUploadPropertiesEnum.LOINC_UPLOAD_PROPERTIES_FILE; import static org.apache.commons.lang3.StringUtils.leftPad; import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.greaterThan; +import static org.hamcrest.Matchers.matchesPattern; +import static org.hamcrest.Matchers.stringContainsInOrder; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; public class TerminologyUploaderProviderR4Test extends BaseResourceProviderR4Test { @@ -59,7 +77,7 @@ public class TerminologyUploaderProviderR4Test extends BaseResourceProviderR4Tes byte[] packageBytes = createSctZip(); try { - ourClient + myClient .operation() .onType(CodeSystem.class) .named("upload-external-code-system") @@ -76,7 +94,7 @@ public class TerminologyUploaderProviderR4Test extends BaseResourceProviderR4Tes public void testUploadLoinc() throws Exception { byte[] packageBytes = createLoincZip(); - Parameters respParam = ourClient + Parameters respParam = myClient .operation() .onType(CodeSystem.class) .named("upload-external-code-system") @@ -94,7 +112,7 @@ public class TerminologyUploaderProviderR4Test extends BaseResourceProviderR4Tes * Try uploading a second time */ - respParam = ourClient + respParam = myClient .operation() .onType(CodeSystem.class) .named("upload-external-code-system") @@ -110,7 +128,7 @@ public class TerminologyUploaderProviderR4Test extends BaseResourceProviderR4Tes @Test public void testUploadMissingPackage() { try { - ourClient + myClient .operation() .onType(CodeSystem.class) .named("upload-external-code-system") @@ -127,7 +145,7 @@ public class TerminologyUploaderProviderR4Test extends BaseResourceProviderR4Tes byte[] packageBytes = createSctZip(); try { - ourClient + myClient .operation() .onType(CodeSystem.class) .named("upload-external-code-system") @@ -144,7 +162,7 @@ public class TerminologyUploaderProviderR4Test extends BaseResourceProviderR4Tes public void testUploadSct() throws Exception { byte[] packageBytes = createSctZip(); - Parameters respParam = ourClient + Parameters respParam = myClient .operation() .onType(CodeSystem.class) .named("upload-external-code-system") @@ -168,12 +186,12 @@ public class TerminologyUploaderProviderR4Test extends BaseResourceProviderR4Tes fos.write(packageBytes); fos.close(); - Parameters respParam = ourClient + Parameters respParam = myClient .operation() .onType(CodeSystem.class) .named("upload-external-code-system") .withParameter(Parameters.class, TerminologyUploaderProvider.PARAM_SYSTEM, new UriType(ITermLoaderSvc.SCT_URI)) - .andParameter(TerminologyUploaderProvider.PARAM_FILE, new Attachment().setUrl("localfile:"+tempFile.getAbsolutePath())) + .andParameter(TerminologyUploaderProvider.PARAM_FILE, new Attachment().setUrl("localfile:" + tempFile.getAbsolutePath())) .execute(); String resp = myFhirCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(respParam); @@ -196,8 +214,8 @@ public class TerminologyUploaderProviderR4Test extends BaseResourceProviderR4Tes .setUrl("file:/foo/hierarchy.csv"); LoggingInterceptor interceptor = new LoggingInterceptor(true); - ourClient.registerInterceptor(interceptor); - Parameters outcome = ourClient + myClient.registerInterceptor(interceptor); + Parameters outcome = myClient .operation() .onType(CodeSystem.class) .named(JpaConstants.OPERATION_APPLY_CODESYSTEM_DELTA_ADD) @@ -206,7 +224,7 @@ public class TerminologyUploaderProviderR4Test extends BaseResourceProviderR4Tes .andParameter(TerminologyUploaderProvider.PARAM_FILE, hierarchyAttachment) .prettyPrint() .execute(); - ourClient.unregisterInterceptor(interceptor); + myClient.unregisterInterceptor(interceptor); String encoded = myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(outcome); ourLog.info(encoded); @@ -229,8 +247,8 @@ public class TerminologyUploaderProviderR4Test extends BaseResourceProviderR4Tes micro.addConcept().setCode("C&S").setDisplay("Culture And Sensitivity"); LoggingInterceptor interceptor = new LoggingInterceptor(true); - ourClient.registerInterceptor(interceptor); - Parameters outcome = ourClient + myClient.registerInterceptor(interceptor); + Parameters outcome = myClient .operation() .onType(CodeSystem.class) .named(JpaConstants.OPERATION_APPLY_CODESYSTEM_DELTA_ADD) @@ -238,7 +256,7 @@ public class TerminologyUploaderProviderR4Test extends BaseResourceProviderR4Tes .andParameter(TerminologyUploaderProvider.PARAM_CODESYSTEM, codeSystem) .prettyPrint() .execute(); - ourClient.unregisterInterceptor(interceptor); + myClient.unregisterInterceptor(interceptor); String encoded = myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(outcome); ourLog.info(encoded); @@ -251,10 +269,10 @@ public class TerminologyUploaderProviderR4Test extends BaseResourceProviderR4Tes assertHierarchyContains( "CHEM seq=0", - " HB seq=0", - " NEUT seq=1", - "MICRO seq=0", - " C&S seq=0" + " HB seq=0", + " NEUT seq=1", + "MICRO seq=0", + " C&S seq=0" ); } @@ -268,12 +286,12 @@ public class TerminologyUploaderProviderR4Test extends BaseResourceProviderR4Tes codeSystem.setUrl("https://good.health"); LoggingInterceptor interceptor = new LoggingInterceptor(true); - ourClient.registerInterceptor(interceptor); - ourClient + myClient.registerInterceptor(interceptor); + myClient .create() .resource(codeSystem) .execute(); - ourClient.unregisterInterceptor(interceptor); + myClient.unregisterInterceptor(interceptor); } // Add a child with a really long description @@ -282,14 +300,14 @@ public class TerminologyUploaderProviderR4Test extends BaseResourceProviderR4Tes Parameters inputBundle = loadResourceFromClasspath(Parameters.class, "/term-delta-json.json"); LoggingInterceptor interceptor = new LoggingInterceptor(true); - ourClient.registerInterceptor(interceptor); - outcome = ourClient + myClient.registerInterceptor(interceptor); + outcome = myClient .operation() .onType(CodeSystem.class) .named(JpaConstants.OPERATION_APPLY_CODESYSTEM_DELTA_ADD) .withParameters(inputBundle) .execute(); - ourClient.unregisterInterceptor(interceptor); + myClient.unregisterInterceptor(interceptor); } String encoded = myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(outcome); @@ -306,7 +324,7 @@ public class TerminologyUploaderProviderR4Test extends BaseResourceProviderR4Tes " 1111222234 seq=0" ); - runInTransaction(()->{ + runInTransaction(() -> { TermCodeSystem codeSystem = myTermCodeSystemDao.findByCodeSystemUri("https://good.health"); TermCodeSystemVersion version = codeSystem.getCurrentVersion(); TermConcept code = myTermConceptDao.findByCodeSystemAndCode(version, "1111222233").get(); @@ -318,7 +336,6 @@ public class TerminologyUploaderProviderR4Test extends BaseResourceProviderR4Tes } - @Test public void testApplyDeltaAdd_UsingCodeSystemWithVeryLongDescription() { @@ -330,8 +347,8 @@ public class TerminologyUploaderProviderR4Test extends BaseResourceProviderR4Tes chem.addConcept().setCode("HB").setDisplay("Hemoglobin"); LoggingInterceptor interceptor = new LoggingInterceptor(true); - ourClient.registerInterceptor(interceptor); - Parameters outcome = ourClient + myClient.registerInterceptor(interceptor); + Parameters outcome = myClient .operation() .onType(CodeSystem.class) .named(JpaConstants.OPERATION_APPLY_CODESYSTEM_DELTA_ADD) @@ -339,7 +356,7 @@ public class TerminologyUploaderProviderR4Test extends BaseResourceProviderR4Tes .andParameter(TerminologyUploaderProvider.PARAM_CODESYSTEM, codeSystem) .prettyPrint() .execute(); - ourClient.unregisterInterceptor(interceptor); + myClient.unregisterInterceptor(interceptor); } // Add a child with a really long description @@ -351,8 +368,8 @@ public class TerminologyUploaderProviderR4Test extends BaseResourceProviderR4Tes .addConcept().setCode("HBA").setDisplay(leftPad("", 500, 'Z')); LoggingInterceptor interceptor = new LoggingInterceptor(true); - ourClient.registerInterceptor(interceptor); - outcome = ourClient + myClient.registerInterceptor(interceptor); + outcome = myClient .operation() .onType(CodeSystem.class) .named(JpaConstants.OPERATION_APPLY_CODESYSTEM_DELTA_ADD) @@ -360,7 +377,7 @@ public class TerminologyUploaderProviderR4Test extends BaseResourceProviderR4Tes .andParameter(TerminologyUploaderProvider.PARAM_CODESYSTEM, codeSystem) .prettyPrint() .execute(); - ourClient.unregisterInterceptor(interceptor); + myClient.unregisterInterceptor(interceptor); } String encoded = myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(outcome); @@ -388,10 +405,10 @@ public class TerminologyUploaderProviderR4Test extends BaseResourceProviderR4Tes .setUrl("file:/foo/concepts.csv"); LoggingInterceptor interceptor = new LoggingInterceptor(true); - ourClient.registerInterceptor(interceptor); + myClient.registerInterceptor(interceptor); try { - ourClient + myClient .operation() .onType(CodeSystem.class) .named(JpaConstants.OPERATION_APPLY_CODESYSTEM_DELTA_ADD) @@ -402,17 +419,17 @@ public class TerminologyUploaderProviderR4Test extends BaseResourceProviderR4Tes } catch (InvalidRequestException e) { assertThat(e.getMessage(), containsString("Missing mandatory parameter: system")); } - ourClient.unregisterInterceptor(interceptor); + myClient.unregisterInterceptor(interceptor); } @Test public void testApplyDeltaAdd_MissingFile() { LoggingInterceptor interceptor = new LoggingInterceptor(true); - ourClient.registerInterceptor(interceptor); + myClient.registerInterceptor(interceptor); try { - ourClient + myClient .operation() .onType(CodeSystem.class) .named(JpaConstants.OPERATION_APPLY_CODESYSTEM_DELTA_ADD) @@ -423,7 +440,7 @@ public class TerminologyUploaderProviderR4Test extends BaseResourceProviderR4Tes } catch (InvalidRequestException e) { assertThat(e.getMessage(), containsString("Missing mandatory parameter: file")); } - ourClient.unregisterInterceptor(interceptor); + myClient.unregisterInterceptor(interceptor); } @Test @@ -440,7 +457,7 @@ public class TerminologyUploaderProviderR4Test extends BaseResourceProviderR4Tes .setUrl("file:/foo/hierarchy.csv"); // Add the codes - ourClient + myClient .operation() .onType(CodeSystem.class) .named(JpaConstants.OPERATION_APPLY_CODESYSTEM_DELTA_ADD) @@ -452,8 +469,8 @@ public class TerminologyUploaderProviderR4Test extends BaseResourceProviderR4Tes // And remove them LoggingInterceptor interceptor = new LoggingInterceptor(true); - ourClient.registerInterceptor(interceptor); - Parameters outcome = ourClient + myClient.registerInterceptor(interceptor); + Parameters outcome = myClient .operation() .onType(CodeSystem.class) .named(JpaConstants.OPERATION_APPLY_CODESYSTEM_DELTA_REMOVE) @@ -462,17 +479,13 @@ public class TerminologyUploaderProviderR4Test extends BaseResourceProviderR4Tes .andParameter(TerminologyUploaderProvider.PARAM_FILE, hierarchyAttachment) .prettyPrint() .execute(); - ourClient.unregisterInterceptor(interceptor); + myClient.unregisterInterceptor(interceptor); String encoded = myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(outcome); ourLog.info(encoded); assertThat(encoded, containsString("\"valueInteger\": 5")); } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } private static void addFile(ZipOutputStream theZos, String theFileName) throws IOException { theZos.putNextEntry(new ZipEntry(theFileName)); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r5/BaseResourceProviderR5Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r5/BaseResourceProviderR5Test.java index a112314f98d..a991d221e60 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r5/BaseResourceProviderR5Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r5/BaseResourceProviderR5Test.java @@ -34,9 +34,9 @@ import org.hl7.fhir.r5.model.Bundle.BundleEntryComponent; import org.hl7.fhir.r5.model.Parameters; import org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent; import org.hl7.fhir.r5.model.Patient; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.context.ContextLoader; import org.springframework.web.context.WebApplicationContext; @@ -52,7 +52,7 @@ import java.util.List; import java.util.concurrent.TimeUnit; import static org.apache.commons.lang3.StringUtils.isNotBlank; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.fail; public abstract class BaseResourceProviderR5Test extends BaseJpaR5Test { @@ -67,7 +67,7 @@ public abstract class BaseResourceProviderR5Test extends BaseJpaR5Test { private static GenericWebApplicationContext ourWebApplicationContext; private static SubscriptionMatcherInterceptor ourSubscriptionMatcherInterceptor; protected static Server ourServer; - protected IGenericClient ourClient; + protected IGenericClient myClient; ResourceCountCache ourResourceCountsCache; private Object ourGraphQLProvider; private boolean ourRestHookSubscriptionInterceptorRequested; @@ -82,14 +82,16 @@ public abstract class BaseResourceProviderR5Test extends BaseJpaR5Test { super(); } - @After + @AfterEach public void after() throws Exception { myFhirCtx.getRestfulClientFactory().setServerValidationMode(ServerValidationModeEnum.ONCE); - ourRestServer.getInterceptorService().unregisterAllInterceptors(); + if (ourRestServer != null) { + ourRestServer.getInterceptorService().unregisterAllInterceptors(); + } } @SuppressWarnings({"unchecked", "rawtypes"}) - @Before + @BeforeEach public void before() throws Exception { myFhirCtx.getRestfulClientFactory().setServerValidationMode(ServerValidationModeEnum.NEVER); myFhirCtx.getRestfulClientFactory().setSocketTimeout(1200 * 1000); @@ -181,9 +183,9 @@ public abstract class BaseResourceProviderR5Test extends BaseJpaR5Test { ourRestServer.setPagingProvider(ourPagingProvider); - ourClient = myFhirCtx.newRestfulGenericClient(ourServerBase); + myClient = myFhirCtx.newRestfulGenericClient(ourServerBase); if (shouldLogClient()) { - ourClient.registerInterceptor(new LoggingInterceptor()); + myClient.registerInterceptor(new LoggingInterceptor()); } } @@ -220,7 +222,7 @@ public abstract class BaseResourceProviderR5Test extends BaseJpaR5Test { Thread.sleep(500); } - @AfterClass + @AfterAll public static void afterClassClearContextBaseResourceProviderR5Test() throws Exception { JettyUtil.closeServer(ourServer); ourHttpClient.close(); @@ -230,7 +232,6 @@ public abstract class BaseResourceProviderR5Test extends BaseJpaR5Test { myValidationSupport = null; ourWebApplicationContext.close(); ourWebApplicationContext = null; - TestUtil.clearAllStaticFieldsForUnitTest(); } public static int getNumberOfParametersByName(Parameters theParameters, String theName) { diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r5/ResourceProviderR5Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r5/ResourceProviderR5Test.java index 198eaffa900..2aa2640e264 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r5/ResourceProviderR5Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r5/ResourceProviderR5Test.java @@ -3,7 +3,6 @@ package ca.uhn.fhir.jpa.provider.r5; import ca.uhn.fhir.jpa.api.config.DaoConfig; import ca.uhn.fhir.jpa.entity.Search; import ca.uhn.fhir.jpa.model.search.SearchStatusEnum; -import ca.uhn.fhir.jpa.util.TestUtil; import ca.uhn.fhir.parser.StrictErrorHandler; import ca.uhn.fhir.rest.client.interceptor.CapturingInterceptor; import ca.uhn.fhir.rest.server.exceptions.NotImplementedOperationException; @@ -20,9 +19,9 @@ import org.hl7.fhir.r5.model.Bundle; import org.hl7.fhir.r5.model.DateTimeType; import org.hl7.fhir.r5.model.Observation; import org.hl7.fhir.r5.model.Patient; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -32,9 +31,9 @@ import java.util.stream.Collectors; import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.containsString; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.hamcrest.MatcherAssert.assertThat; @SuppressWarnings("Duplicates") public class ResourceProviderR5Test extends BaseResourceProviderR5Test { @@ -43,7 +42,7 @@ public class ResourceProviderR5Test extends BaseResourceProviderR5Test { private CapturingInterceptor myCapturingInterceptor = new CapturingInterceptor(); @Override - @After + @AfterEach public void after() throws Exception { super.after(); @@ -54,16 +53,17 @@ public class ResourceProviderR5Test extends BaseResourceProviderR5Test { myDaoConfig.setSearchPreFetchThresholds(new DaoConfig().getSearchPreFetchThresholds()); myDaoConfig.setAllowContainsSearches(new DaoConfig().isAllowContainsSearches()); - ourClient.unregisterInterceptor(myCapturingInterceptor); + myClient.unregisterInterceptor(myCapturingInterceptor); } + @BeforeEach @Override public void before() throws Exception { super.before(); myFhirCtx.setParserErrorHandler(new StrictErrorHandler()); myDaoConfig.setAllowMultipleDelete(true); - ourClient.registerInterceptor(myCapturingInterceptor); + myClient.registerInterceptor(myCapturingInterceptor); myDaoConfig.setSearchPreFetchThresholds(new DaoConfig().getSearchPreFetchThresholds()); } @@ -84,7 +84,7 @@ public class ResourceProviderR5Test extends BaseResourceProviderR5Test { myPatientDao.create(pt3).getId().toUnqualifiedVersionless().getValue(); - Bundle output = ourClient + Bundle output = myClient .search() .forResource("Patient") .where(Patient.NAME.contains().value("ZAB")) @@ -93,7 +93,7 @@ public class ResourceProviderR5Test extends BaseResourceProviderR5Test { List ids = output.getEntry().stream().map(t -> t.getResource().getIdElement().toUnqualifiedVersionless().getValue()).collect(Collectors.toList()); assertThat(ids, containsInAnyOrder(pt1id)); - output = ourClient + output = myClient .search() .forResource("Patient") .where(Patient.NAME.contains().value("zab")) @@ -111,7 +111,7 @@ public class ResourceProviderR5Test extends BaseResourceProviderR5Test { myPatientDao.create(pt1); // Perform the search - Bundle response0 = ourClient.search() + Bundle response0 = myClient.search() .forResource("Patient") .where(Patient.NAME.matches().value("Hello")) .returnBundle(Bundle.class) @@ -119,7 +119,7 @@ public class ResourceProviderR5Test extends BaseResourceProviderR5Test { assertEquals(1, response0.getEntry().size()); // Perform the search again (should return the same) - Bundle response1 = ourClient.search() + Bundle response1 = myClient.search() .forResource("Patient") .where(Patient.NAME.matches().value("Hello")) .returnBundle(Bundle.class) @@ -137,7 +137,7 @@ public class ResourceProviderR5Test extends BaseResourceProviderR5Test { }); // Perform the search again (shouldn't return the errored out search) - Bundle response3 = ourClient.search() + Bundle response3 = myClient.search() .forResource("Patient") .where(Patient.NAME.matches().value("Hello")) .returnBundle(Bundle.class) @@ -158,7 +158,7 @@ public class ResourceProviderR5Test extends BaseResourceProviderR5Test { myPatientDao.create(pt2); // Perform a search for the first page - Bundle response0 = ourClient.search() + Bundle response0 = myClient.search() .forResource("Patient") .where(Patient.NAME.matches().value("Hello")) .returnBundle(Bundle.class) @@ -177,7 +177,7 @@ public class ResourceProviderR5Test extends BaseResourceProviderR5Test { // Request the second page try { - ourClient.loadPage().next(response0).execute(); + myClient.loadPage().next(response0).execute(); } catch (NotImplementedOperationException e) { assertEquals(501, e.getStatusCode()); assertThat(e.getMessage(), containsString("Some Failure Message")); @@ -213,7 +213,7 @@ public class ResourceProviderR5Test extends BaseResourceProviderR5Test { observation.setEffective(new DateTimeType("1965-08-09")); IIdType oid = myObservationDao.create(observation).getId().toUnqualified(); String nowParam = UrlUtil.escapeUrlParam("%now"); - Bundle output = ourClient + Bundle output = myClient .search() .byUrl("Observation?date=lt" + nowParam) .returnBundle(Bundle.class) @@ -233,7 +233,7 @@ public class ResourceProviderR5Test extends BaseResourceProviderR5Test { observation.setEffective(new DateTimeType("1965-08-10")); myObservationDao.create(observation).getId().toUnqualified(); - Bundle output = ourClient + Bundle output = myClient .search() .byUrl("Observation?_count=0") .returnBundle(Bundle.class) @@ -243,9 +243,5 @@ public class ResourceProviderR5Test extends BaseResourceProviderR5Test { assertEquals(0, output.getEntry().size()); } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r5/ResourceProviderR5ValueSetTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r5/ResourceProviderR5ValueSetTest.java index 58a6bf69e5d..b81d7fb8c0f 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r5/ResourceProviderR5ValueSetTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r5/ResourceProviderR5ValueSetTest.java @@ -17,7 +17,6 @@ import ca.uhn.fhir.jpa.term.api.ITermReadSvc; 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; import ca.uhn.fhir.util.UrlUtil; import com.google.common.base.Charsets; import org.apache.commons.io.IOUtils; @@ -42,9 +41,8 @@ import org.hl7.fhir.r5.model.StringType; import org.hl7.fhir.r5.model.UriType; import org.hl7.fhir.r5.model.ValueSet; import org.hl7.fhir.r5.model.ValueSet.ConceptSetComponent; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; import org.springframework.transaction.TransactionStatus; import org.springframework.transaction.support.TransactionCallbackWithoutResult; import org.springframework.transaction.support.TransactionTemplate; @@ -59,12 +57,12 @@ import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.containsStringIgnoringCase; import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.stringContainsInOrder; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; public class ResourceProviderR5ValueSetTest extends BaseResourceProviderR5Test { @@ -242,7 +240,7 @@ public class ResourceProviderR5ValueSetTest extends BaseResourceProviderR5Test { public void testExpandById() throws Exception { loadAndPersistCodeSystemAndValueSet(HTTPVerb.POST); - Parameters respParam = ourClient + Parameters respParam = myClient .operation() .onInstance(myExtensionalVsId) .named("expand") @@ -275,7 +273,7 @@ public class ResourceProviderR5ValueSetTest extends BaseResourceProviderR5Test { loadAndPersistCodeSystemAndValueSet(HTTPVerb.POST); myTermSvc.preExpandDeferredValueSetsToTerminologyTables(); - Parameters respParam = ourClient + Parameters respParam = myClient .operation() .onInstance(myExtensionalVsId) .named("expand") @@ -308,7 +306,7 @@ public class ResourceProviderR5ValueSetTest extends BaseResourceProviderR5Test { loadAndPersistCodeSystemAndValueSet(HTTPVerb.POST); myTermSvc.preExpandDeferredValueSetsToTerminologyTables(); - Parameters respParam = ourClient + Parameters respParam = myClient .operation() .onInstance(myExtensionalVsId) .named("expand") @@ -342,7 +340,7 @@ public class ResourceProviderR5ValueSetTest extends BaseResourceProviderR5Test { loadAndPersistCodeSystemAndValueSet(HTTPVerb.POST); myTermSvc.preExpandDeferredValueSetsToTerminologyTables(); - Parameters respParam = ourClient + Parameters respParam = myClient .operation() .onInstance(myExtensionalVsId) .named("expand") @@ -373,7 +371,7 @@ public class ResourceProviderR5ValueSetTest extends BaseResourceProviderR5Test { loadAndPersistCodeSystemAndValueSet(HTTPVerb.POST); myTermSvc.preExpandDeferredValueSetsToTerminologyTables(); - Parameters respParam = ourClient + Parameters respParam = myClient .operation() .onInstance(myExtensionalVsId) .named("expand") @@ -402,7 +400,7 @@ public class ResourceProviderR5ValueSetTest extends BaseResourceProviderR5Test { public void testExpandByIdWithFilter() throws Exception { loadAndPersistCodeSystemAndValueSet(HTTPVerb.POST); - Parameters respParam = ourClient + Parameters respParam = myClient .operation() .onInstance(myExtensionalVsId) .named("expand") @@ -424,7 +422,7 @@ public class ResourceProviderR5ValueSetTest extends BaseResourceProviderR5Test { loadAndPersistCodeSystemAndValueSet(HTTPVerb.POST); myTermSvc.preExpandDeferredValueSetsToTerminologyTables(); - Parameters respParam = ourClient + Parameters respParam = myClient .operation() .onInstance(myExtensionalVsId) .named("expand") @@ -443,7 +441,7 @@ public class ResourceProviderR5ValueSetTest extends BaseResourceProviderR5Test { public void testExpandByUrl() throws Exception { loadAndPersistCodeSystemAndValueSet(HTTPVerb.POST); - Parameters respParam = ourClient + Parameters respParam = myClient .operation() .onType(ValueSet.class) .named("expand") @@ -464,7 +462,7 @@ public class ResourceProviderR5ValueSetTest extends BaseResourceProviderR5Test { loadAndPersistCodeSystemAndValueSet(HTTPVerb.POST); try { - ourClient + myClient .operation() .onType(ValueSet.class) .named("expand") @@ -483,7 +481,7 @@ public class ResourceProviderR5ValueSetTest extends BaseResourceProviderR5Test { loadAndPersistCodeSystemAndValueSet(HTTPVerb.POST); myTermSvc.preExpandDeferredValueSetsToTerminologyTables(); - Parameters respParam = ourClient + Parameters respParam = myClient .operation() .onType(ValueSet.class) .named("expand") @@ -506,7 +504,7 @@ public class ResourceProviderR5ValueSetTest extends BaseResourceProviderR5Test { loadAndPersistCodeSystemAndValueSet(HTTPVerb.POST); myTermSvc.preExpandDeferredValueSetsToTerminologyTables(); - Parameters respParam = ourClient + Parameters respParam = myClient .operation() .onType(ValueSet.class) .named("expand") @@ -541,7 +539,7 @@ public class ResourceProviderR5ValueSetTest extends BaseResourceProviderR5Test { loadAndPersistCodeSystemAndValueSet(HTTPVerb.POST); myTermSvc.preExpandDeferredValueSetsToTerminologyTables(); - Parameters respParam = ourClient + Parameters respParam = myClient .operation() .onType(ValueSet.class) .named("expand") @@ -573,7 +571,7 @@ public class ResourceProviderR5ValueSetTest extends BaseResourceProviderR5Test { loadAndPersistCodeSystemAndValueSet(HTTPVerb.POST); myTermSvc.preExpandDeferredValueSetsToTerminologyTables(); - Parameters respParam = ourClient + Parameters respParam = myClient .operation() .onType(ValueSet.class) .named("expand") @@ -607,7 +605,7 @@ public class ResourceProviderR5ValueSetTest extends BaseResourceProviderR5Test { myTermSvc.preExpandDeferredValueSetsToTerminologyTables(); try { - Parameters respParam = ourClient + Parameters respParam = myClient .operation() .onType(ValueSet.class) .named("expand") @@ -625,7 +623,7 @@ public class ResourceProviderR5ValueSetTest extends BaseResourceProviderR5Test { ValueSet toExpand = loadResourceFromClasspath(ValueSet.class, "/extensional-case-3-vs.xml"); - Parameters respParam = ourClient + Parameters respParam = myClient .operation() .onType(ValueSet.class) .named("expand") @@ -650,7 +648,7 @@ public class ResourceProviderR5ValueSetTest extends BaseResourceProviderR5Test { ValueSet toExpand = loadResourceFromClasspath(ValueSet.class, "/extensional-case-3-vs.xml"); - Parameters respParam = ourClient + Parameters respParam = myClient .operation() .onType(ValueSet.class) .named("expand") @@ -675,7 +673,7 @@ public class ResourceProviderR5ValueSetTest extends BaseResourceProviderR5Test { ValueSet toExpand = loadResourceFromClasspath(ValueSet.class, "/extensional-case-3-vs.xml"); - Parameters respParam = ourClient + Parameters respParam = myClient .operation() .onType(ValueSet.class) .named("expand") @@ -712,7 +710,7 @@ public class ResourceProviderR5ValueSetTest extends BaseResourceProviderR5Test { ValueSet toExpand = loadResourceFromClasspath(ValueSet.class, "/extensional-case-3-vs.xml"); - Parameters respParam = ourClient + Parameters respParam = myClient .operation() .onType(ValueSet.class) .named("expand") @@ -746,7 +744,7 @@ public class ResourceProviderR5ValueSetTest extends BaseResourceProviderR5Test { ValueSet toExpand = loadResourceFromClasspath(ValueSet.class, "/extensional-case-3-vs.xml"); - Parameters respParam = ourClient + Parameters respParam = myClient .operation() .onType(ValueSet.class) .named("expand") @@ -777,7 +775,7 @@ public class ResourceProviderR5ValueSetTest extends BaseResourceProviderR5Test { createLocalVsPointingAtBuiltInCodeSystem(); assertNotNull(myLocalValueSetId); - Parameters respParam = ourClient + Parameters respParam = myClient .operation() .onType(ValueSet.class) .named("expand") @@ -797,7 +795,7 @@ public class ResourceProviderR5ValueSetTest extends BaseResourceProviderR5Test { assertNotNull(myLocalVs); myLocalVs.setId(""); - Parameters respParam = ourClient + Parameters respParam = myClient .operation() .onType(ValueSet.class) .named("expand") @@ -819,7 +817,7 @@ public class ResourceProviderR5ValueSetTest extends BaseResourceProviderR5Test { loadAndPersistCodeSystemAndValueSet(HTTPVerb.POST); try { - ourClient + myClient .operation() .onType(ValueSet.class) .named("expand") @@ -832,7 +830,7 @@ public class ResourceProviderR5ValueSetTest extends BaseResourceProviderR5Test { try { ValueSet toExpand = loadResourceFromClasspath(ValueSet.class, "/r4/extensional-case-r4.xml"); - ourClient + myClient .operation() .onType(ValueSet.class) .named("expand") @@ -846,7 +844,7 @@ public class ResourceProviderR5ValueSetTest extends BaseResourceProviderR5Test { try { ValueSet toExpand = loadResourceFromClasspath(ValueSet.class, "/r4/extensional-case.xml"); - ourClient + myClient .operation() .onInstance(myExtensionalVsId) .named("expand") @@ -859,7 +857,7 @@ public class ResourceProviderR5ValueSetTest extends BaseResourceProviderR5Test { } try { - ourClient + myClient .operation() .onInstance(myExtensionalVsId) .named("expand") @@ -871,7 +869,7 @@ public class ResourceProviderR5ValueSetTest extends BaseResourceProviderR5Test { } try { - ourClient + myClient .operation() .onInstance(myExtensionalVsId) .named("expand") @@ -888,7 +886,7 @@ public class ResourceProviderR5ValueSetTest extends BaseResourceProviderR5Test { createLocalVsPointingAtBuiltInCodeSystem(); assertNotNull(myLocalValueSetId); - Parameters respParam = ourClient + Parameters respParam = myClient .operation() .onInstance(myLocalValueSetId) .named("expand") @@ -907,7 +905,7 @@ public class ResourceProviderR5ValueSetTest extends BaseResourceProviderR5Test { createExternalCsAndLocalVs(); assertNotNull(myLocalValueSetId); - Parameters respParam = ourClient + Parameters respParam = myClient .operation() .onInstance(myLocalValueSetId) .named("expand") @@ -929,7 +927,7 @@ public class ResourceProviderR5ValueSetTest extends BaseResourceProviderR5Test { createExternalCsAndLocalVs(); assertNotNull(myLocalValueSetId); - Parameters respParam = ourClient + Parameters respParam = myClient .operation() .onType(ValueSet.class) .named("expand") @@ -952,7 +950,7 @@ public class ResourceProviderR5ValueSetTest extends BaseResourceProviderR5Test { assertNotNull(myLocalValueSetId); try { - ourClient + myClient .operation() .onInstance(myLocalValueSetId) .named("expand") @@ -964,22 +962,22 @@ public class ResourceProviderR5ValueSetTest extends BaseResourceProviderR5Test { } @Test - public void testExpandValueSetBasedOnCodeSystemWithChangedUrl() throws IOException { + public void testExpandValueSetBasedOnCodeSystemWithChangedUrl() { CodeSystem cs = new CodeSystem(); cs.setId("CodeSystem/CS"); cs.setContent(CodeSystemContentMode.COMPLETE); cs.setUrl("http://foo1"); cs.addConcept().setCode("foo1").setDisplay("foo1"); - ourClient.update().resource(cs).execute(); + myClient.update().resource(cs).execute(); ValueSet vs = new ValueSet(); vs.setId("ValueSet/VS179789"); vs.setUrl("http://bar"); vs.getCompose().addInclude().setSystem("http://foo1").addConcept().setCode("foo1"); - ourClient.update().resource(vs).execute(); + myClient.update().resource(vs).execute(); - ValueSet expanded = ourClient + ValueSet expanded = myClient .operation() .onInstance(new IdType("ValueSet/VS179789")) .named("$expand") @@ -995,15 +993,15 @@ public class ResourceProviderR5ValueSetTest extends BaseResourceProviderR5Test { cs.setContent(CodeSystemContentMode.COMPLETE); cs.setUrl("http://foo2"); cs.addConcept().setCode("foo2").setDisplay("foo2"); - ourClient.update().resource(cs).execute(); + myClient.update().resource(cs).execute(); vs = new ValueSet(); vs.setId("ValueSet/VS179789"); vs.setUrl("http://bar"); vs.getCompose().addInclude().setSystem("http://foo2").addConcept().setCode("foo2"); - ourClient.update().resource(vs).execute(); + myClient.update().resource(vs).execute(); - expanded = ourClient + expanded = myClient .operation() .onInstance(new IdType("ValueSet/VS179789")) .named("$expand") @@ -1087,7 +1085,7 @@ public class ResourceProviderR5ValueSetTest extends BaseResourceProviderR5Test { ValueSet updatedValueSet = valueSet; updatedValueSet.setName(valueSet.getName().concat(" - MODIFIED")); - String url = ourClient.getServerBase().concat("/").concat(myExtensionalVsId.getValueAsString()); + String url = myClient.getServerBase().concat("/").concat(myExtensionalVsId.getValueAsString()); Bundle bundle = new Bundle(); bundle.setType(Bundle.BundleType.TRANSACTION); bundle @@ -1098,7 +1096,7 @@ public class ResourceProviderR5ValueSetTest extends BaseResourceProviderR5Test { .setMethod(Bundle.HTTPVerb.PUT) .setUrl(url); ourLog.info("Transaction Bundle:\n" + myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(bundle)); - ourClient.transaction().withBundle(bundle).execute(); + myClient.transaction().withBundle(bundle).execute(); updatedValueSet = myValueSetDao.read(myExtensionalVsId); ourLog.info("Updated ValueSet:\n" + myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(updatedValueSet)); @@ -1204,7 +1202,7 @@ public class ResourceProviderR5ValueSetTest extends BaseResourceProviderR5Test { public void testValidateCodeOperationByCodeAndSystemInstance() throws Exception { loadAndPersistCodeSystemAndValueSet(HTTPVerb.POST); - Parameters respParam = ourClient + Parameters respParam = myClient .operation() .onInstance(myExtensionalVsId) .named("validate-code") @@ -1265,7 +1263,7 @@ public class ResourceProviderR5ValueSetTest extends BaseResourceProviderR5Test { public void testValidateCodeOperationByCodeAndSystemType() throws Exception { loadAndPersistCodeSystemAndValueSet(HTTPVerb.POST); - Parameters respParam = ourClient + Parameters respParam = myClient .operation() .onType(ValueSet.class) .named("validate-code") @@ -1283,7 +1281,7 @@ public class ResourceProviderR5ValueSetTest extends BaseResourceProviderR5Test { public void testValidateCodeAgainstBuiltInSystem() { // Good code and system, good valueset { - Parameters respParam = ourClient + Parameters respParam = myClient .operation() .onType(ValueSet.class) .named("validate-code") @@ -1307,7 +1305,7 @@ public class ResourceProviderR5ValueSetTest extends BaseResourceProviderR5Test { } // Good code and system, but not in specified valueset { - Parameters respParam = ourClient + Parameters respParam = myClient .operation() .onType(ValueSet.class) .named("validate-code") @@ -1374,15 +1372,11 @@ public class ResourceProviderR5ValueSetTest extends BaseResourceProviderR5Test { } - @After + @AfterEach public void afterResetPreExpansionDefault() { myDaoConfig.setPreExpandValueSets(new DaoConfig().isPreExpandValueSets()); } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } public static CodeSystem createExternalCs(IFhirResourceDao theCodeSystemDao, IResourceTableDao theResourceTableDao, ITermCodeSystemStorageSvc theTermCodeSystemStorageSvc, ServletRequestDetails theRequestDetails) { CodeSystem codeSystem = new CodeSystem(); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r5/ServerR5Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r5/ServerR5Test.java index 37ea3293d16..ddacf77ebc4 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r5/ServerR5Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/provider/r5/ServerR5Test.java @@ -5,7 +5,6 @@ import ca.uhn.fhir.rest.api.EncodingEnum; import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; import ca.uhn.fhir.rest.server.exceptions.PreconditionFailedException; import ca.uhn.fhir.util.ExtensionConstants; -import ca.uhn.fhir.util.TestUtil; import org.apache.commons.io.IOUtils; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; @@ -14,9 +13,8 @@ import org.hl7.fhir.r5.model.CapabilityStatement.CapabilityStatementRestResource import org.hl7.fhir.r5.model.CapabilityStatement.CapabilityStatementRestResourceSearchParamComponent; import org.hl7.fhir.r5.model.Extension; import org.hl7.fhir.r5.model.Patient; -import org.junit.AfterClass; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import java.io.IOException; @@ -24,9 +22,9 @@ import java.nio.charset.StandardCharsets; import java.util.HashSet; import java.util.Set; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.fail; public class ServerR5Test extends BaseResourceProviderR5Test { @@ -36,7 +34,7 @@ public class ServerR5Test extends BaseResourceProviderR5Test { private IFhirResourceDao myCapabilityStatementDao; @Test - @Ignore + @Disabled public void testCapabilityStatementValidates() throws IOException { HttpGet get = new HttpGet(ourServerBase + "/metadata?_pretty=true&_format=json"); try (CloseableHttpResponse resp = ourHttpClient.execute(get)) { @@ -96,7 +94,7 @@ public class ServerR5Test extends BaseResourceProviderR5Test { public void testMetadataIncludesResourceCounts() { Patient p = new Patient(); p.setActive(true); - ourClient.create().resource(p).execute(); + myClient.create().resource(p).execute(); /* * Initial fetch after a clear should return @@ -104,7 +102,7 @@ public class ServerR5Test extends BaseResourceProviderR5Test { */ myResourceCountsCache.clear(); - CapabilityStatement capabilityStatement = ourClient + CapabilityStatement capabilityStatement = myClient .capabilities() .ofType(CapabilityStatement.class) .execute(); @@ -126,7 +124,7 @@ public class ServerR5Test extends BaseResourceProviderR5Test { */ myResourceCountsCache.update(); - capabilityStatement = ourClient + capabilityStatement = myClient .capabilities() .ofType(CapabilityStatement.class) .execute(); @@ -145,9 +143,5 @@ public class ServerR5Test extends BaseResourceProviderR5Test { } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/sched/SchedulerServiceImplTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/sched/SchedulerServiceImplTest.java index d0b6e150c03..323b20ec1a6 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/sched/SchedulerServiceImplTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/sched/SchedulerServiceImplTest.java @@ -3,10 +3,10 @@ package ca.uhn.fhir.jpa.sched; import ca.uhn.fhir.jpa.model.sched.HapiJob; import ca.uhn.fhir.jpa.model.sched.ISchedulerService; import ca.uhn.fhir.jpa.model.sched.ScheduledJobDefinition; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.quartz.DisallowConcurrentExecution; import org.quartz.Job; import org.quartz.JobExecutionContext; @@ -22,19 +22,19 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.util.AopTestUtils; import static ca.uhn.fhir.jpa.util.TestUtil.sleepAtLeast; import static org.awaitility.Awaitility.await; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.greaterThan; import static org.hamcrest.Matchers.greaterThanOrEqualTo; import static org.hamcrest.Matchers.lessThan; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.fail; @ContextConfiguration(classes = SchedulerServiceImplTest.TestConfiguration.class) -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @DirtiesContext public class SchedulerServiceImplTest { @@ -43,7 +43,7 @@ public class SchedulerServiceImplTest { @Autowired private ISchedulerService mySvc; - @Before + @BeforeEach public void before() { ourTaskDelay = 0; } @@ -123,7 +123,7 @@ public class SchedulerServiceImplTest { assertThat(CountingIntervalJob.ourCount, lessThan(6)); } - @After + @AfterEach public void after() throws SchedulerException { CountingJob.ourCount = 0; CountingIntervalJob.ourCount = 0; diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/search/PagingMultinodeProviderDstu3Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/search/PagingMultinodeProviderDstu3Test.java index a76fde4a29c..968bb5b0193 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/search/PagingMultinodeProviderDstu3Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/search/PagingMultinodeProviderDstu3Test.java @@ -3,42 +3,42 @@ package ca.uhn.fhir.jpa.search; import ca.uhn.fhir.jpa.api.config.DaoConfig; import ca.uhn.fhir.jpa.provider.dstu3.BaseResourceProviderDstu3Test; import ca.uhn.fhir.parser.StrictErrorHandler; -import ca.uhn.fhir.util.TestUtil; import org.hl7.fhir.dstu3.model.Bundle; import org.hl7.fhir.dstu3.model.Patient; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.test.util.AopTestUtils; import static org.apache.commons.lang3.StringUtils.leftPad; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.contains; -import static org.junit.Assert.assertThat; public class PagingMultinodeProviderDstu3Test extends BaseResourceProviderDstu3Test { private SearchCoordinatorSvcImpl mySearchCoordinatorSvcRaw; @Override - @After + @AfterEach public void after() throws Exception { super.after(); myDaoConfig.setAllowMultipleDelete(new DaoConfig().isAllowMultipleDelete()); myDaoConfig.setAllowExternalReferences(new DaoConfig().isAllowExternalReferences()); - + mySearchCoordinatorSvcRaw.setLoadingThrottleForUnitTests(null); mySearchCoordinatorSvcRaw.setSyncSizeForUnitTests(SearchCoordinatorSvcImpl.DEFAULT_SYNC_SIZE); mySearchCoordinatorSvcRaw.setNeverUseLocalSearchForUnitTests(false); } @Override + @BeforeEach public void before() throws Exception { super.before(); myFhirCtx.setParserErrorHandler(new StrictErrorHandler()); myDaoConfig.setAllowMultipleDelete(true); - + mySearchCoordinatorSvcRaw = AopTestUtils.getTargetObject(ourSearchCoordinatorSvc); } @@ -62,36 +62,32 @@ public class PagingMultinodeProviderDstu3Test extends BaseResourceProviderDstu3T mySearchCoordinatorSvcRaw.setNeverUseLocalSearchForUnitTests(true); found = ourClient - .search() - .forResource(Patient.class) - .sort().ascending(Patient.SP_FAMILY) - .count(10) - .returnBundle(Bundle.class) - .execute(); + .search() + .forResource(Patient.class) + .sort().ascending(Patient.SP_FAMILY) + .count(10) + .returnBundle(Bundle.class) + .execute(); assertThat(toUnqualifiedVersionlessIdValues(found), contains("Patient/A000", "Patient/A001", "Patient/A002", "Patient/A003", "Patient/A004", "Patient/A005", "Patient/A006", "Patient/A007", "Patient/A008", "Patient/A009")); found = ourClient - .loadPage() - .next(found) - .execute(); + .loadPage() + .next(found) + .execute(); assertThat(toUnqualifiedVersionlessIdValues(found), contains("Patient/A010", "Patient/A011", "Patient/A012", "Patient/A013", "Patient/A014", "Patient/A015", "Patient/A016", "Patient/A017", "Patient/A018", "Patient/A019")); found = ourClient - .loadPage() - .next(found) - .execute(); + .loadPage() + .next(found) + .execute(); assertThat(toUnqualifiedVersionlessIdValues(found), contains("Patient/A020", "Patient/A021", "Patient/A022", "Patient/A023", "Patient/A024", "Patient/A025", "Patient/A026", "Patient/A027", "Patient/A028", "Patient/A029")); found = ourClient - .loadPage() - .next(found) - .execute(); + .loadPage() + .next(found) + .execute(); assertThat(toUnqualifiedVersionlessIdValues(found), contains("Patient/A030", "Patient/A031", "Patient/A032", "Patient/A033", "Patient/A034", "Patient/A035", "Patient/A036", "Patient/A037", "Patient/A038", "Patient/A039")); } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/search/PersistedJpaBundleProviderTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/search/PersistedJpaBundleProviderTest.java index 55b2c4dd7db..cfdd9dd852c 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/search/PersistedJpaBundleProviderTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/search/PersistedJpaBundleProviderTest.java @@ -4,21 +4,21 @@ import ca.uhn.fhir.jpa.api.dao.IDao; import ca.uhn.fhir.jpa.dao.SearchBuilderFactory; import ca.uhn.fhir.jpa.entity.Search; import ca.uhn.fhir.rest.api.server.RequestDetails; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.junit.MockitoJUnitRunner; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verifyNoInteractions; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class PersistedJpaBundleProviderTest { private PersistedJpaBundleProvider myPersistedJpaBundleProvider; private IDao myDao; private SearchBuilderFactory mySearchBuilderFactory; - @Before + @BeforeEach public void init() { RequestDetails request = mock(RequestDetails.class); String searchUuid = "this is not a hat"; diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/search/SearchCoordinatorSvcImplTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/search/SearchCoordinatorSvcImplTest.java index 914b7a5c73c..7a52bd64de6 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/search/SearchCoordinatorSvcImplTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/search/SearchCoordinatorSvcImplTest.java @@ -1,6 +1,7 @@ package ca.uhn.fhir.jpa.search; import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.context.FhirVersionEnum; import ca.uhn.fhir.interceptor.api.IInterceptorBroadcaster; import ca.uhn.fhir.interceptor.model.RequestPartitionId; import ca.uhn.fhir.jpa.api.config.DaoConfig; @@ -28,14 +29,14 @@ import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; import ca.uhn.fhir.rest.server.exceptions.ResourceGoneException; import ca.uhn.fhir.util.TestUtil; import org.hl7.fhir.instance.model.api.IBaseResource; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.ArgumentCaptor; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.stubbing.Answer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -59,11 +60,11 @@ import java.util.concurrent.atomic.AtomicInteger; import static ca.uhn.fhir.jpa.util.TestUtil.sleepAtLeast; import static org.awaitility.Awaitility.await; import static org.hamcrest.CoreMatchers.containsString; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyInt; @@ -81,11 +82,11 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @SuppressWarnings({"unchecked"}) -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class SearchCoordinatorSvcImplTest { private static final Logger ourLog = LoggerFactory.getLogger(SearchCoordinatorSvcImplTest.class); - private static FhirContext ourCtx = FhirContext.forDstu3(); + private static FhirContext ourCtx = FhirContext.forCached(FhirVersionEnum.DSTU3); @Mock private IFhirResourceDao myCallingDao; @Mock @@ -112,14 +113,14 @@ public class SearchCoordinatorSvcImplTest { @Mock private IRequestPartitionHelperSvc myPartitionHelperSvc; - @After + @AfterEach public void after() { System.clearProperty(SearchCoordinatorSvcImpl.UNIT_TEST_CAPTURE_STACK); verify(mySearchBuilderFactory, atMost(myExpectedNumberOfSearchBuildersCreated)).newSearchBuilder(any(), any(), any()); } - @Before + @BeforeEach public void before() { System.setProperty(SearchCoordinatorSvcImpl.UNIT_TEST_CAPTURE_STACK, "true"); @@ -139,21 +140,6 @@ public class SearchCoordinatorSvcImplTest { DaoConfig daoConfig = new DaoConfig(); mySvc.setDaoConfigForUnitTest(daoConfig); - when(mySearchBuilderFactory.newSearchBuilder(any(), any(), any())).thenReturn(mySearchBuilder); - - when(myTxManager.getTransaction(any())).thenReturn(mock(TransactionStatus.class)); - - when(myPersistedJpaBundleProviderFactory.newInstanceFirstPage(nullable(RequestDetails.class), nullable(Search.class), nullable(SearchCoordinatorSvcImpl.SearchTask.class), nullable(ISearchBuilder.class))).thenAnswer(t->{ - RequestDetails requestDetails = t.getArgument(0, RequestDetails.class); - Search search = t.getArgument(1, Search.class); - SearchCoordinatorSvcImpl.SearchTask searchTask = t.getArgument(2, SearchCoordinatorSvcImpl.SearchTask.class); - ISearchBuilder searchBuilder = t.getArgument(3, ISearchBuilder.class); - PersistedJpaSearchFirstPageBundleProvider retVal = new PersistedJpaSearchFirstPageBundleProvider(search, searchTask, searchBuilder, requestDetails); - retVal.setTxManagerForUnitTest(myTxManager); - retVal.setSearchCoordinatorSvcForUnitTest(mySvc); - return retVal; - }); - } private List createPidSequence(int to) { @@ -179,6 +165,8 @@ public class SearchCoordinatorSvcImplTest { @Test public void testAsyncSearchFailDuringSearchSameCoordinator() { + initSearches(); + SearchParameterMap params = new SearchParameterMap(); params.add("name", new StringParam("ANAME")); @@ -201,6 +189,8 @@ public class SearchCoordinatorSvcImplTest { @Test public void testAsyncSearchLargeResultSetBigCountSameCoordinator() { + initSearches(); + List allResults = new ArrayList<>(); doAnswer(t -> { List oldResults = t.getArgument(1, List.class); @@ -294,6 +284,8 @@ public class SearchCoordinatorSvcImplTest { @Test public void testAsyncSearchLargeResultSetSameCoordinator() { + initSearches(); + SearchParameterMap params = new SearchParameterMap(); params.add("name", new StringParam("ANAME")); @@ -316,8 +308,27 @@ public class SearchCoordinatorSvcImplTest { } + private void initSearches() { + when(mySearchBuilderFactory.newSearchBuilder(any(), any(), any())).thenReturn(mySearchBuilder); + + when(myTxManager.getTransaction(any())).thenReturn(mock(TransactionStatus.class)); + + when(myPersistedJpaBundleProviderFactory.newInstanceFirstPage(nullable(RequestDetails.class), nullable(Search.class), nullable(SearchCoordinatorSvcImpl.SearchTask.class), nullable(ISearchBuilder.class))).thenAnswer(t->{ + RequestDetails requestDetails = t.getArgument(0, RequestDetails.class); + Search search = t.getArgument(1, Search.class); + SearchCoordinatorSvcImpl.SearchTask searchTask = t.getArgument(2, SearchCoordinatorSvcImpl.SearchTask.class); + ISearchBuilder searchBuilder = t.getArgument(3, ISearchBuilder.class); + PersistedJpaSearchFirstPageBundleProvider retVal = new PersistedJpaSearchFirstPageBundleProvider(search, searchTask, searchBuilder, requestDetails); + retVal.setTxManagerForUnitTest(myTxManager); + retVal.setSearchCoordinatorSvcForUnitTest(mySvc); + return retVal; + }); + } + @Test public void testCancelActiveSearches() throws InterruptedException { + initSearches(); + SearchParameterMap params = new SearchParameterMap(); params.add("name", new StringParam("ANAME")); @@ -363,6 +374,8 @@ public class SearchCoordinatorSvcImplTest { */ @Test public void testAsyncSearchLargeResultSetSecondRequestSameCoordinator() { + initSearches(); + SearchParameterMap params = new SearchParameterMap(); params.add("name", new StringParam("ANAME")); @@ -411,6 +424,8 @@ public class SearchCoordinatorSvcImplTest { @Test public void testAsyncSearchSmallResultSetSameCoordinator() { + initSearches(); + SearchParameterMap params = new SearchParameterMap(); params.add("name", new StringParam("ANAME")); @@ -441,6 +456,9 @@ public class SearchCoordinatorSvcImplTest { @Test public void testLoadSearchResultsFromDifferentCoordinator() { + when(mySearchBuilderFactory.newSearchBuilder(any(), any(), any())).thenReturn(mySearchBuilder); + when(myTxManager.getTransaction(any())).thenReturn(mock(TransactionStatus.class)); + final String uuid = UUID.randomUUID().toString(); final Search search = new Search(); @@ -513,6 +531,9 @@ public class SearchCoordinatorSvcImplTest { @Test public void testSynchronousSearch() { + when(mySearchBuilderFactory.newSearchBuilder(any(), any(), any())).thenReturn(mySearchBuilder); + when(myTxManager.getTransaction(any())).thenReturn(mock(TransactionStatus.class)); + SearchParameterMap params = new SearchParameterMap(); params.setLoadSynchronous(true); params.add("name", new StringParam("ANAME")); @@ -534,6 +555,9 @@ public class SearchCoordinatorSvcImplTest { @Test public void testSynchronousSearchUpTo() { + when(mySearchBuilderFactory.newSearchBuilder(any(), any(), any())).thenReturn(mySearchBuilder); + when(myTxManager.getTransaction(any())).thenReturn(mock(TransactionStatus.class)); + SearchParameterMap params = new SearchParameterMap(); params.setLoadSynchronousUpTo(100); params.add("name", new StringParam("ANAME")); @@ -757,9 +781,4 @@ public class SearchCoordinatorSvcImplTest { } } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } - } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/search/cache/DatabaseSearchCacheSvcImplTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/search/cache/DatabaseSearchCacheSvcImplTest.java index 425d59701be..40a8049bc91 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/search/cache/DatabaseSearchCacheSvcImplTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/search/cache/DatabaseSearchCacheSvcImplTest.java @@ -4,20 +4,25 @@ import ca.uhn.fhir.jpa.dao.data.ISearchDao; import ca.uhn.fhir.jpa.entity.Search; import ca.uhn.fhir.jpa.model.search.SearchStatusEnum; import org.hibernate.HibernateException; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.transaction.PlatformTransactionManager; import java.util.Optional; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class DatabaseSearchCacheSvcImplTest { private DatabaseSearchCacheSvcImpl mySvc; @@ -28,7 +33,7 @@ public class DatabaseSearchCacheSvcImplTest { @Mock private PlatformTransactionManager myTxManager; - @Before + @BeforeEach public void before() { mySvc = new DatabaseSearchCacheSvcImpl(); mySvc.setSearchDaoForUnitTest(mySearchDao); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/search/lastn/LastNElasticsearchSvcMultipleObservationsIT.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/search/lastn/LastNElasticsearchSvcMultipleObservationsIT.java index d57aa01c620..667bb318d44 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/search/lastn/LastNElasticsearchSvcMultipleObservationsIT.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/search/lastn/LastNElasticsearchSvcMultipleObservationsIT.java @@ -1,6 +1,7 @@ package ca.uhn.fhir.jpa.search.lastn; import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.context.FhirVersionEnum; import ca.uhn.fhir.jpa.search.lastn.config.TestElasticsearchConfig; import ca.uhn.fhir.jpa.search.lastn.json.CodeJson; import ca.uhn.fhir.jpa.search.lastn.json.ObservationJson; @@ -21,13 +22,13 @@ import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; import org.hl7.fhir.r4.model.Observation; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import java.io.IOException; import java.util.ArrayList; @@ -39,38 +40,28 @@ import java.util.List; import java.util.Map; import java.util.UUID; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = {TestElasticsearchConfig.class}) public class LastNElasticsearchSvcMultipleObservationsIT { - @Autowired - private ElasticsearchSvcImpl elasticsearchSvc; - + static private final Calendar baseObservationDate = new GregorianCalendar(); private static ObjectMapper ourMapperNonPrettyPrint; private static boolean indexLoaded = false; private final Map>> createdPatientObservationMap = new HashMap<>(); - private final FhirContext myFhirContext = FhirContext.forR4(); + private final FhirContext myFhirContext = FhirContext.forCached(FhirVersionEnum.R4); + @Autowired + private ElasticsearchSvcImpl elasticsearchSvc; - static private final Calendar baseObservationDate = new GregorianCalendar(); - - @BeforeClass - public static void beforeClass() { - ourMapperNonPrettyPrint = new ObjectMapper(); - ourMapperNonPrettyPrint.setSerializationInclusion(JsonInclude.Include.NON_NULL); - ourMapperNonPrettyPrint.disable(SerializationFeature.INDENT_OUTPUT); - ourMapperNonPrettyPrint.disable(JsonGenerator.Feature.AUTO_CLOSE_TARGET); - } - - @Before + @BeforeEach public void before() throws IOException { if (!indexLoaded) { createMultiplePatientsAndObservations(); @@ -221,7 +212,7 @@ public class LastNElasticsearchSvcMultipleObservationsIT { searchParameterMap.add(Observation.SP_SUBJECT, buildReferenceAndListParam(subjectParam)); TokenParam categoryParam = new TokenParam(null, "test-heart-rate"); searchParameterMap.add(Observation.SP_CATEGORY, buildTokenAndListParam(categoryParam)); - TokenParam codeParam = new TokenParam(null,"test-code-1"); + TokenParam codeParam = new TokenParam(null, "test-code-1"); searchParameterMap.add(Observation.SP_CODE, buildTokenAndListParam(codeParam)); searchParameterMap.setLastNMax(100); @@ -318,9 +309,9 @@ public class LastNElasticsearchSvcMultipleObservationsIT { public void testLastNNoMatchQueries() { ReferenceParam validPatientParam = new ReferenceParam("Patient", "", "9"); - TokenParam validCategoryCodeParam = new TokenParam("http://mycodes.org/fhir/observation-category","test-heart-rate"); + TokenParam validCategoryCodeParam = new TokenParam("http://mycodes.org/fhir/observation-category", "test-heart-rate"); TokenParam validObservationCodeParam = new TokenParam("http://mycodes.org/fhir/observation-code", "test-code-1"); - DateParam validDateParam = new DateParam(ParamPrefixEnum.EQUAL, new Date(baseObservationDate.getTimeInMillis() - (9*3600*1000))); + DateParam validDateParam = new DateParam(ParamPrefixEnum.EQUAL, new Date(baseObservationDate.getTimeInMillis() - (9 * 3600 * 1000))); // Ensure that valid parameters are indeed valid SearchParameterMap searchParameterMap = new SearchParameterMap(); @@ -394,8 +385,8 @@ public class LastNElasticsearchSvcMultipleObservationsIT { @Test public void testLastNEffectiveDates() { - Date highDate = new Date(baseObservationDate.getTimeInMillis() - (3600*1000)); - Date lowDate = new Date(baseObservationDate.getTimeInMillis() - (10*3600*1000)); + Date highDate = new Date(baseObservationDate.getTimeInMillis() - (3600 * 1000)); + Date lowDate = new Date(baseObservationDate.getTimeInMillis() - (10 * 3600 * 1000)); SearchParameterMap searchParameterMap = new SearchParameterMap(); ReferenceParam subjectParam = new ReferenceParam("Patient", "", "3"); @@ -456,7 +447,7 @@ public class LastNElasticsearchSvcMultipleObservationsIT { searchParameterMap = new SearchParameterMap(); searchParameterMap.add(Observation.SP_SUBJECT, buildReferenceAndListParam(subjectParam)); - DateParam startDateParam = new DateParam(ParamPrefixEnum.GREATERTHAN, new Date(baseObservationDate.getTimeInMillis() - (4*3600*1000))); + DateParam startDateParam = new DateParam(ParamPrefixEnum.GREATERTHAN, new Date(baseObservationDate.getTimeInMillis() - (4 * 3600 * 1000))); DateAndListParam dateAndListParam = new DateAndListParam(); dateAndListParam.addAnd(new DateOrListParam().addOr(startDateParam)); dateParam = new DateParam(ParamPrefixEnum.LESSTHAN_OR_EQUALS, highDate); @@ -468,7 +459,7 @@ public class LastNElasticsearchSvcMultipleObservationsIT { searchParameterMap = new SearchParameterMap(); searchParameterMap.add(Observation.SP_SUBJECT, buildReferenceAndListParam(subjectParam)); - startDateParam = new DateParam(ParamPrefixEnum.GREATERTHAN, new Date(baseObservationDate.getTimeInMillis() - (4*3600*1000))); + startDateParam = new DateParam(ParamPrefixEnum.GREATERTHAN, new Date(baseObservationDate.getTimeInMillis() - (4 * 3600 * 1000))); searchParameterMap.add(Observation.SP_DATE, startDateParam); dateParam = new DateParam(ParamPrefixEnum.LESSTHAN, lowDate); searchParameterMap.add(Observation.SP_DATE, dateParam); @@ -533,7 +524,7 @@ public class LastNElasticsearchSvcMultipleObservationsIT { assertTrue(elasticsearchSvc.createOrUpdateObservationCodeIndex(codeableConceptId2, codeJson2)); } - Date effectiveDtm = new Date(baseObservationDate.getTimeInMillis() - ((10-entryCount)*3600*1000)); + Date effectiveDtm = new Date(baseObservationDate.getTimeInMillis() - ((10 - entryCount) * 3600 * 1000)); observationJson.setEffectiveDtm(effectiveDtm); assertTrue(elasticsearchSvc.createOrUpdateObservationIndex(identifier, observationJson)); @@ -583,5 +574,13 @@ public class LastNElasticsearchSvcMultipleObservationsIT { } + @BeforeAll + public static void beforeClass() { + ourMapperNonPrettyPrint = new ObjectMapper(); + ourMapperNonPrettyPrint.setSerializationInclusion(JsonInclude.Include.NON_NULL); + ourMapperNonPrettyPrint.disable(SerializationFeature.INDENT_OUTPUT); + ourMapperNonPrettyPrint.disable(JsonGenerator.Feature.AUTO_CLOSE_TARGET); + } + } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/search/lastn/LastNElasticsearchSvcSingleObservationIT.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/search/lastn/LastNElasticsearchSvcSingleObservationIT.java index d6835c4dec2..aba1356d20a 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/search/lastn/LastNElasticsearchSvcSingleObservationIT.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/search/lastn/LastNElasticsearchSvcSingleObservationIT.java @@ -1,6 +1,7 @@ package ca.uhn.fhir.jpa.search.lastn; import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.context.FhirVersionEnum; import ca.uhn.fhir.jpa.model.util.CodeSystemHash; import ca.uhn.fhir.jpa.search.lastn.config.TestElasticsearchConfig; import ca.uhn.fhir.jpa.search.lastn.json.CodeJson; @@ -19,13 +20,13 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; -import org.junit.After; -import org.junit.BeforeClass; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import java.io.IOException; import java.util.ArrayList; @@ -33,18 +34,14 @@ import java.util.Date; import java.util.List; import java.util.UUID; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = {TestElasticsearchConfig.class}) public class LastNElasticsearchSvcSingleObservationIT { - @Autowired - ElasticsearchSvcImpl elasticsearchSvc; - static ObjectMapper ourMapperNonPrettyPrint; - final String RESOURCEPID = "123"; final String SUBJECTID = "Patient/4567"; final Date EFFECTIVEDTM = new Date(); @@ -72,25 +69,16 @@ public class LastNElasticsearchSvcSingleObservationIT { final String THIRDCATEGORYSECONDCODINGDISPLAY = "test-alt-vitals display"; final String THIRDCATEGORYTHIRDCODINGCODE = "test-2nd-alt-vitals-panel"; final String THIRDCATEGORYTHIRDCODINGDISPLAY = "test-2nd-alt-vitals-panel display"; - final String OBSERVATIONSINGLECODEID = UUID.randomUUID().toString(); final String OBSERVATIONCODETEXT = "Test Codeable Concept Field for Code"; final String CODEFIRSTCODINGSYSTEM = "http://mycodes.org/fhir/observation-code"; final String CODEFIRSTCODINGCODE = "test-code"; final String CODEFIRSTCODINGDISPLAY = "test-code display"; + final FhirContext myFhirContext = FhirContext.forCached(FhirVersionEnum.R4); + @Autowired + ElasticsearchSvcImpl elasticsearchSvc; - final FhirContext myFhirContext = FhirContext.forR4(); - - @BeforeClass - public static void beforeClass() { - ourMapperNonPrettyPrint = new ObjectMapper(); - ourMapperNonPrettyPrint.setSerializationInclusion(JsonInclude.Include.NON_NULL); - ourMapperNonPrettyPrint.disable(SerializationFeature.INDENT_OUTPUT); - ourMapperNonPrettyPrint.disable(JsonGenerator.Feature.AUTO_CLOSE_TARGET); - - } - - @After + @AfterEach public void after() throws IOException { elasticsearchSvc.deleteAllDocumentsForTest(ElasticsearchSvcImpl.OBSERVATION_INDEX); elasticsearchSvc.deleteAllDocumentsForTest(ElasticsearchSvcImpl.OBSERVATION_CODE_INDEX); @@ -305,4 +293,13 @@ public class LastNElasticsearchSvcSingleObservationIT { elasticsearchSvc.refreshIndex(ElasticsearchSvcImpl.OBSERVATION_CODE_INDEX); } + @BeforeAll + public static void beforeClass() { + ourMapperNonPrettyPrint = new ObjectMapper(); + ourMapperNonPrettyPrint.setSerializationInclusion(JsonInclude.Include.NON_NULL); + ourMapperNonPrettyPrint.disable(SerializationFeature.INDENT_OUTPUT); + ourMapperNonPrettyPrint.disable(JsonGenerator.Feature.AUTO_CLOSE_TARGET); + + } + } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/search/r4/PagingMultinodeProviderR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/search/r4/PagingMultinodeProviderR4Test.java index afb308149aa..2facd279d15 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/search/r4/PagingMultinodeProviderR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/search/r4/PagingMultinodeProviderR4Test.java @@ -1,27 +1,25 @@ package ca.uhn.fhir.jpa.search.r4; +import static org.apache.commons.lang3.StringUtils.leftPad; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.MatcherAssert.assertThat; + +import org.hl7.fhir.r4.model.Bundle; +import org.hl7.fhir.r4.model.Patient; +import org.junit.jupiter.api.*; import static org.hamcrest.MatcherAssert.assertThat; +import org.springframework.test.util.AopTestUtils; + import ca.uhn.fhir.jpa.api.config.DaoConfig; import ca.uhn.fhir.jpa.provider.r4.BaseResourceProviderR4Test; import ca.uhn.fhir.jpa.search.SearchCoordinatorSvcImpl; import ca.uhn.fhir.parser.StrictErrorHandler; -import ca.uhn.fhir.util.TestUtil; -import org.hl7.fhir.r4.model.Bundle; -import org.hl7.fhir.r4.model.Patient; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Test; -import org.springframework.test.util.AopTestUtils; - -import static org.apache.commons.lang3.StringUtils.leftPad; -import static org.hamcrest.Matchers.contains; -import static org.junit.Assert.assertThat; public class PagingMultinodeProviderR4Test extends BaseResourceProviderR4Test { private SearchCoordinatorSvcImpl mySearchCoordinatorSvcRaw; @Override - @After + @AfterEach public void after() throws Exception { super.after(); @@ -33,6 +31,7 @@ public class PagingMultinodeProviderR4Test extends BaseResourceProviderR4Test { mySearchCoordinatorSvcRaw.setNeverUseLocalSearchForUnitTests(false); } + @BeforeEach @Override public void before() throws Exception { super.before(); @@ -62,7 +61,7 @@ public class PagingMultinodeProviderR4Test extends BaseResourceProviderR4Test { mySearchCoordinatorSvcRaw.setSyncSizeForUnitTests(10); mySearchCoordinatorSvcRaw.setNeverUseLocalSearchForUnitTests(true); - found = ourClient + found = myClient .search() .forResource(Patient.class) .sort().ascending(Patient.SP_FAMILY) @@ -71,28 +70,24 @@ public class PagingMultinodeProviderR4Test extends BaseResourceProviderR4Test { .execute(); assertThat(toUnqualifiedVersionlessIdValues(found), contains("Patient/A000", "Patient/A001", "Patient/A002", "Patient/A003", "Patient/A004", "Patient/A005", "Patient/A006", "Patient/A007", "Patient/A008", "Patient/A009")); - found = ourClient + found = myClient .loadPage() .next(found) .execute(); assertThat(toUnqualifiedVersionlessIdValues(found), contains("Patient/A010", "Patient/A011", "Patient/A012", "Patient/A013", "Patient/A014", "Patient/A015", "Patient/A016", "Patient/A017", "Patient/A018", "Patient/A019")); - found = ourClient + found = myClient .loadPage() .next(found) .execute(); assertThat(toUnqualifiedVersionlessIdValues(found), contains("Patient/A020", "Patient/A021", "Patient/A022", "Patient/A023", "Patient/A024", "Patient/A025", "Patient/A026", "Patient/A027", "Patient/A028", "Patient/A029")); - found = ourClient + found = myClient .loadPage() .next(found) .execute(); assertThat(toUnqualifiedVersionlessIdValues(found), contains("Patient/A030", "Patient/A031", "Patient/A032", "Patient/A033", "Patient/A034", "Patient/A035", "Patient/A036", "Patient/A037", "Patient/A038", "Patient/A039")); } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/search/reindex/ResourceReindexingSvcImplTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/search/reindex/ResourceReindexingSvcImplTest.java index f6c814a52d5..8768df4a18d 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/search/reindex/ResourceReindexingSvcImplTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/search/reindex/ResourceReindexingSvcImplTest.java @@ -1,6 +1,7 @@ package ca.uhn.fhir.jpa.search.reindex; import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.context.FhirVersionEnum; import ca.uhn.fhir.jpa.api.config.DaoConfig; import ca.uhn.fhir.jpa.api.dao.DaoRegistry; import ca.uhn.fhir.jpa.api.dao.IFhirResourceDao; @@ -18,8 +19,8 @@ import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IIdType; import org.hl7.fhir.r4.model.Observation; import org.hl7.fhir.r4.model.Patient; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.Mock; @@ -37,7 +38,7 @@ import java.util.Optional; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.anyBoolean; @@ -52,7 +53,7 @@ import static org.mockito.Mockito.when; public class ResourceReindexingSvcImplTest extends BaseJpaTest { - private static FhirContext ourCtx = FhirContext.forR4(); + private static FhirContext ourCtx = FhirContext.forCached(FhirVersionEnum.R4); @Mock private PlatformTransactionManager myTxManager; @@ -98,7 +99,7 @@ public class ResourceReindexingSvcImplTest extends BaseJpaTest { return myTxManager; } - @Before + @BeforeEach public void before() { myDaoConfig = new DaoConfig(); myDaoConfig.setReindexThreadCount(2); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/searchparam/MatchUrlServiceTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/searchparam/MatchUrlServiceTest.java index 6ee336af59c..a060380f371 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/searchparam/MatchUrlServiceTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/searchparam/MatchUrlServiceTest.java @@ -1,6 +1,7 @@ package ca.uhn.fhir.jpa.searchparam; import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.context.FhirVersionEnum; import ca.uhn.fhir.context.RuntimeResourceDefinition; import ca.uhn.fhir.jpa.config.TestDstu3Config; import ca.uhn.fhir.jpa.dao.BaseJpaTest; @@ -11,34 +12,31 @@ import ca.uhn.fhir.rest.param.ReferenceParam; import ca.uhn.fhir.util.TestUtil; import org.hl7.fhir.dstu3.model.Condition; import org.hl7.fhir.dstu3.model.Location; -import org.junit.AfterClass; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.transaction.PlatformTransactionManager; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = {TestDstu3Config.class}) public class MatchUrlServiceTest extends BaseJpaTest { - private static FhirContext ourCtx = FhirContext.forDstu3(); + private static FhirContext ourCtx = FhirContext.forCached(FhirVersionEnum.DSTU3); @Autowired MatchUrlService myMatchUrlService; - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } - @Test public void testTranslateMatchUrl() { RuntimeResourceDefinition resourceDef = ourCtx.getResourceDefinition(Condition.class); @@ -111,4 +109,5 @@ public class MatchUrlServiceTest extends BaseJpaTest { return null; } + } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/stresstest/StressTestParserTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/stresstest/StressTestParserTest.java index 14c443b5217..e0a8c46726c 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/stresstest/StressTestParserTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/stresstest/StressTestParserTest.java @@ -1,12 +1,13 @@ package ca.uhn.fhir.jpa.stresstest; import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.context.FhirVersionEnum; import ca.uhn.fhir.test.BaseTest; import ca.uhn.fhir.util.StopWatch; import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.r4.model.Bundle; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -21,9 +22,9 @@ public class StressTestParserTest extends BaseTest { * @throws IOException */ @Test - @Ignore + @Disabled public void test() throws IOException { - FhirContext ctx = FhirContext.forR4(); + FhirContext ctx = FhirContext.forCached(FhirVersionEnum.R4); String input = loadResource("/org/hl7/fhir/r4/model/valueset/valuesets.xml"); Bundle parsed = ctx.newXmlParser().parseResource(Bundle.class, input); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/stresstest/StressTestR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/stresstest/StressTestR4Test.java index e0ab52cae23..3ce136bf8ba 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/stresstest/StressTestR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/stresstest/StressTestR4Test.java @@ -14,7 +14,6 @@ import ca.uhn.fhir.rest.param.TokenOrListParam; import ca.uhn.fhir.rest.server.exceptions.ResourceVersionConflictException; import ca.uhn.fhir.rest.server.interceptor.RequestValidatingInterceptor; import ca.uhn.fhir.util.StopWatch; -import ca.uhn.fhir.util.TestUtil; import com.google.common.base.Charsets; import com.google.common.collect.Lists; import com.google.common.collect.Sets; @@ -38,11 +37,10 @@ import org.hl7.fhir.r4.model.Observation; import org.hl7.fhir.r4.model.Patient; import org.hl7.fhir.r4.model.Reference; import org.hl7.fhir.r4.model.Resource; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.TestPropertySource; @@ -64,14 +62,14 @@ import static org.apache.commons.lang3.StringUtils.leftPad; import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.not; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; @TestPropertySource(properties = { "max_db_connections=10" }) @DirtiesContext -@Ignore +@Disabled public class StressTestR4Test extends BaseResourceProviderR4Test { static { @@ -85,7 +83,7 @@ public class StressTestR4Test extends BaseResourceProviderR4Test { private int myPreviousMaxPageSize; @Override - @After + @AfterEach public void after() throws Exception { super.after(); @@ -101,7 +99,7 @@ public class StressTestR4Test extends BaseResourceProviderR4Test { } @Override - @Before + @BeforeEach public void before() throws Exception { super.before(); @@ -143,7 +141,7 @@ public class StressTestR4Test extends BaseResourceProviderR4Test { Map ids = new HashMap<>(); - IGenericClient fhirClient = this.ourClient; + IGenericClient fhirClient = this.myClient; String url = ourServerBase + "/Observation?date=gt2000&_sort=-_lastUpdated"; @@ -226,7 +224,7 @@ public class StressTestR4Test extends BaseResourceProviderR4Test { // Load from DAOs List ids = new ArrayList<>(); - Bundle resultBundle = ourClient.search().forResource("Observation").count(100).returnBundle(Bundle.class).execute(); + Bundle resultBundle = myClient.search().forResource("Observation").count(100).returnBundle(Bundle.class).execute(); int pageIndex = 0; while (true) { ids.addAll(resultBundle.getEntry().stream().map(t -> t.getResource().getIdElement().toUnqualifiedVersionless().getValue()).collect(Collectors.toList())); @@ -234,7 +232,7 @@ public class StressTestR4Test extends BaseResourceProviderR4Test { break; } ourLog.info("Loading page {} - Have {} results: {}", pageIndex++, ids.size(), resultBundle.getLink("next").getUrl()); - resultBundle = ourClient.loadPage().next(resultBundle).execute(); + resultBundle = myClient.loadPage().next(resultBundle).execute(); } assertEquals(count, ids.size()); assertEquals(count, Sets.newHashSet(ids).size()); @@ -287,7 +285,7 @@ public class StressTestR4Test extends BaseResourceProviderR4Test { // Load from DAOs List ids = new ArrayList<>(); - Bundle resultBundle = ourClient.search().forResource("Observation").count(300).returnBundle(Bundle.class).execute(); + Bundle resultBundle = myClient.search().forResource("Observation").count(300).returnBundle(Bundle.class).execute(); int pageIndex = 0; while (true) { ids.addAll(resultBundle.getEntry().stream().map(t -> t.getResource().getIdElement().toUnqualifiedVersionless().getValue()).collect(Collectors.toList())); @@ -295,7 +293,7 @@ public class StressTestR4Test extends BaseResourceProviderR4Test { break; } ourLog.info("Loading page {} - Have {} results: {}", pageIndex++, ids.size(), resultBundle.getLink("next").getUrl()); - resultBundle = ourClient.loadPage().next(resultBundle).execute(); + resultBundle = myClient.loadPage().next(resultBundle).execute(); } assertEquals(count, ids.size()); assertEquals(count, Sets.newHashSet(ids).size()); @@ -350,7 +348,7 @@ public class StressTestR4Test extends BaseResourceProviderR4Test { assertEquals(1202, resultsAndIncludes.size()); } - @Ignore + @Disabled @Test public void testUpdateListWithLargeNumberOfEntries() { int numPatients = 3000; @@ -399,7 +397,7 @@ public class StressTestR4Test extends BaseResourceProviderR4Test { p.addIdentifier().setSystem("http://test").setValue("BAR"); input.addEntry().setResource(p).getRequest().setMethod(HTTPVerb.POST).setUrl("Patient"); } - ourClient.transaction().withBundle(input).execute(); + myClient.transaction().withBundle(input).execute(); List tasks = Lists.newArrayList(); @@ -438,7 +436,7 @@ public class StressTestR4Test extends BaseResourceProviderR4Test { input.addEntry().setResource(p).setFullUrl("Patient/A" + finalI).getRequest().setMethod(HTTPVerb.PUT).setUrl("Patient/A" + finalI); try { - ourClient.transaction().withBundle(input).execute(); + myClient.transaction().withBundle(input).execute(); return null; } catch (ResourceVersionConflictException e) { assertThat(e.toString(), containsString("Error flushing transaction with resource types: [Patient] - The operation has failed with a client-assigned ID constraint failure")); @@ -489,7 +487,7 @@ public class StressTestR4Test extends BaseResourceProviderR4Test { input.addEntry().setResource(updatePatient).setFullUrl(updatePatient.getId()).getRequest().setMethod(HTTPVerb.PUT).setUrl(updatePatient.getId()); try { - ourClient.transaction().withBundle(input).execute(); + myClient.transaction().withBundle(input).execute(); return null; } catch (ResourceVersionConflictException e) { assertThat(e.toString(), containsString("Error flushing transaction with resource types: [Patient] - The operation has failed with a version constraint failure. This generally means that two clients/threads were trying to update the same resource at the same time, and this request was chosen as the failing request.")); @@ -535,7 +533,7 @@ public class StressTestR4Test extends BaseResourceProviderR4Test { p.addIdentifier().setSystem("http://test").setValue("BAR"); input.addEntry().setResource(p).getRequest().setMethod(HTTPVerb.POST).setUrl("Patient"); } - ourClient.transaction().withBundle(input).execute(); + myClient.transaction().withBundle(input).execute(); try (CloseableHttpResponse getMeta = ourHttpClient.execute(new HttpGet(ourServerBase + "/metadata"))) { assertEquals(200, getMeta.getStatusLine().getStatusCode()); @@ -607,7 +605,7 @@ public class StressTestR4Test extends BaseResourceProviderR4Test { getResp = ourHttpClient.execute(get); try { String respBundleString = IOUtils.toString(getResp.getEntity().getContent(), Charsets.UTF_8); - assertEquals(respBundleString, 200, getResp.getStatusLine().getStatusCode()); + assertEquals(200, getResp.getStatusLine().getStatusCode(), respBundleString); respBundle = myFhirCtx.newJsonParser().parseResource(Bundle.class, respBundleString); myTaskCount++; } finally { @@ -645,7 +643,7 @@ public class StressTestR4Test extends BaseResourceProviderR4Test { Patient p = new Patient(); p.addIdentifier().setSystem("http://test").setValue("BAR").setType(new CodeableConcept().addCoding(new Coding().setSystem("http://foo").setCode("bar"))); p.setGender(org.hl7.fhir.r4.model.Enumerations.AdministrativeGender.MALE); - ourClient.create().resource(p).execute(); + myClient.create().resource(p).execute(); ourSearchParamRegistry.forceRefresh(); @@ -658,10 +656,5 @@ public class StressTestR4Test extends BaseResourceProviderR4Test { } } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } - } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/BaseSubscriptionsR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/BaseSubscriptionsR4Test.java index 4f3f6c0b38a..f1825ef9418 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/BaseSubscriptionsR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/BaseSubscriptionsR4Test.java @@ -1,6 +1,7 @@ package ca.uhn.fhir.jpa.subscription; import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.context.FhirVersionEnum; import ca.uhn.fhir.jpa.api.config.DaoConfig; import ca.uhn.fhir.jpa.provider.r4.BaseResourceProviderR4Test; import ca.uhn.fhir.jpa.subscription.channel.impl.LinkedBlockingChannel; @@ -30,11 +31,11 @@ import org.hl7.fhir.r4.model.Coding; import org.hl7.fhir.r4.model.IdType; import org.hl7.fhir.r4.model.Observation; import org.hl7.fhir.r4.model.Subscription; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Ignore; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RequestParam; @@ -45,7 +46,6 @@ import java.util.Collections; import java.util.Enumeration; import java.util.List; -@Ignore public abstract class BaseSubscriptionsR4Test extends BaseResourceProviderR4Test { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(BaseSubscriptionsR4Test.class); protected static int ourListenerPort; @@ -66,31 +66,31 @@ public abstract class BaseSubscriptionsR4Test extends BaseResourceProviderR4Test @Autowired private SingleQueryCountHolder myCountHolder; - @After + @AfterEach public void afterUnregisterRestHookListener() { for (IIdType next : mySubscriptionIds) { IIdType nextId = next.toUnqualifiedVersionless(); ourLog.info("Deleting: {}", nextId); - ourClient.delete().resourceById(nextId).execute(); + myClient.delete().resourceById(nextId).execute(); } mySubscriptionIds.clear(); myDaoConfig.setAllowMultipleDelete(true); ourLog.info("Deleting all subscriptions"); - ourClient.delete().resourceConditionalByUrl("Subscription?status=active").execute(); - ourClient.delete().resourceConditionalByUrl("Observation?code:missing=false").execute(); + myClient.delete().resourceConditionalByUrl("Subscription?status=active").execute(); + myClient.delete().resourceConditionalByUrl("Observation?code:missing=false").execute(); ourLog.info("Done deleting all subscriptions"); myDaoConfig.setAllowMultipleDelete(new DaoConfig().isAllowMultipleDelete()); mySubscriptionTestUtil.unregisterSubscriptionInterceptor(); } - @Before + @BeforeEach public void beforeRegisterRestHookListener() { mySubscriptionTestUtil.registerRestHookInterceptor(); } - @Before + @BeforeEach public void beforeReset() throws Exception { ourCreatedObservations.clear(); ourUpdatedObservations.clear(); @@ -99,10 +99,10 @@ public abstract class BaseSubscriptionsR4Test extends BaseResourceProviderR4Test ourHeaders.clear(); // Delete all Subscriptions - if (ourClient != null) { - Bundle allSubscriptions = ourClient.search().forResource(Subscription.class).returnBundle(Bundle.class).execute(); + if (myClient != null) { + Bundle allSubscriptions = myClient.search().forResource(Subscription.class).returnBundle(Bundle.class).execute(); for (IBaseResource next : BundleUtil.toListOfResources(myFhirCtx, allSubscriptions)) { - ourClient.delete().resource(next).execute(); + myClient.delete().resource(next).execute(); } waitForActivatedSubscriptionCount(0); } @@ -121,7 +121,7 @@ public abstract class BaseSubscriptionsR4Test extends BaseResourceProviderR4Test protected Subscription createSubscription(String theCriteria, String thePayload) { Subscription subscription = newSubscription(theCriteria, thePayload); - MethodOutcome methodOutcome = ourClient.create().resource(subscription).execute(); + MethodOutcome methodOutcome = myClient.create().resource(subscription).execute(); subscription.setId(methodOutcome.getId().getIdPart()); mySubscriptionIds.add(methodOutcome.getId()); @@ -220,7 +220,7 @@ public abstract class BaseSubscriptionsR4Test extends BaseResourceProviderR4Test } - @AfterClass + @AfterAll public static void reportTotalSelects() { ourLog.info("Total database select queries: {}", getQueryCount().getSelect()); } @@ -229,7 +229,7 @@ public abstract class BaseSubscriptionsR4Test extends BaseResourceProviderR4Test return ourCountHolder.getQueryCountMap().get(""); } - @BeforeClass + @BeforeAll public static void startListenerServer() throws Exception { RestfulServer ourListenerRestServer = new RestfulServer(FhirContext.forR4()); @@ -251,7 +251,7 @@ public abstract class BaseSubscriptionsR4Test extends BaseResourceProviderR4Test ourListenerServerBase = "http://localhost:" + ourListenerPort + "/fhir/context"; } - @AfterClass + @AfterAll public static void stopListenerServer() throws Exception { JettyUtil.closeServer(ourListenerServer); } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/BaseSubscriptionsR5Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/BaseSubscriptionsR5Test.java index ae6e52d386e..92c92a4f71c 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/BaseSubscriptionsR5Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/BaseSubscriptionsR5Test.java @@ -1,6 +1,7 @@ package ca.uhn.fhir.jpa.subscription; import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.context.FhirVersionEnum; import ca.uhn.fhir.jpa.api.config.DaoConfig; import ca.uhn.fhir.jpa.provider.r5.BaseResourceProviderR5Test; import ca.uhn.fhir.jpa.subscription.channel.impl.LinkedBlockingChannel; @@ -31,11 +32,11 @@ import org.hl7.fhir.r5.model.IdType; import org.hl7.fhir.r5.model.Observation; import org.hl7.fhir.r5.model.Subscription; import org.hl7.fhir.r5.model.SubscriptionTopic; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Ignore; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; import org.springframework.beans.factory.annotation.Autowired; import javax.annotation.PostConstruct; @@ -45,57 +46,51 @@ import java.util.Collections; import java.util.Enumeration; import java.util.List; -@Ignore +@Disabled public abstract class BaseSubscriptionsR5Test extends BaseResourceProviderR5Test { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(BaseSubscriptionsR5Test.class); - - private static Server ourListenerServer; - protected static int ourListenerPort; + protected static int ourListenerPort; protected static List ourContentTypes = Collections.synchronizedList(new ArrayList<>()); protected static List ourHeaders = Collections.synchronizedList(new ArrayList<>()); + protected static List ourCreatedObservations = Collections.synchronizedList(Lists.newArrayList()); + protected static List ourUpdatedObservations = Collections.synchronizedList(Lists.newArrayList()); + private static Server ourListenerServer; private static SingleQueryCountHolder ourCountHolder; - - @Autowired - private SingleQueryCountHolder myCountHolder; + private static String ourListenerServerBase; @Autowired protected SubscriptionTestUtil mySubscriptionTestUtil; @Autowired protected SubscriptionMatcherInterceptor mySubscriptionMatcherInterceptor; - protected CountingInterceptor myCountingInterceptor; - - protected static List ourCreatedObservations = Collections.synchronizedList(Lists.newArrayList()); - protected static List ourUpdatedObservations = Collections.synchronizedList(Lists.newArrayList()); - private static String ourListenerServerBase; - protected List mySubscriptionIds = Collections.synchronizedList(new ArrayList<>()); + @Autowired + private SingleQueryCountHolder myCountHolder; - - @After + @AfterEach public void afterUnregisterRestHookListener() { for (IIdType next : mySubscriptionIds) { IIdType nextId = next.toUnqualifiedVersionless(); ourLog.info("Deleting: {}", nextId); - ourClient.delete().resourceById(nextId).execute(); + myClient.delete().resourceById(nextId).execute(); } mySubscriptionIds.clear(); myDaoConfig.setAllowMultipleDelete(true); ourLog.info("Deleting all subscriptions"); - ourClient.delete().resourceConditionalByUrl("Subscription?status=active").execute(); - ourClient.delete().resourceConditionalByUrl("Observation?code:missing=false").execute(); + myClient.delete().resourceConditionalByUrl("Subscription?status=active").execute(); + myClient.delete().resourceConditionalByUrl("Observation?code:missing=false").execute(); ourLog.info("Done deleting all subscriptions"); myDaoConfig.setAllowMultipleDelete(new DaoConfig().isAllowMultipleDelete()); mySubscriptionTestUtil.unregisterSubscriptionInterceptor(); } - @Before + @BeforeEach public void beforeRegisterRestHookListener() { mySubscriptionTestUtil.registerRestHookInterceptor(); } - @Before + @BeforeEach public void beforeReset() throws Exception { ourCreatedObservations.clear(); ourUpdatedObservations.clear(); @@ -103,10 +98,10 @@ public abstract class BaseSubscriptionsR5Test extends BaseResourceProviderR5Test ourHeaders.clear(); // Delete all Subscriptions - if (ourClient != null) { - Bundle allSubscriptions = ourClient.search().forResource(Subscription.class).returnBundle(Bundle.class).execute(); + if (myClient != null) { + Bundle allSubscriptions = myClient.search().forResource(Subscription.class).returnBundle(Bundle.class).execute(); for (IBaseResource next : BundleUtil.toListOfResources(myFhirCtx, allSubscriptions)) { - ourClient.delete().resource(next).execute(); + myClient.delete().resource(next).execute(); } waitForActivatedSubscriptionCount(0); } @@ -125,7 +120,7 @@ public abstract class BaseSubscriptionsR5Test extends BaseResourceProviderR5Test protected Subscription createSubscription(String theCriteria, String thePayload) { Subscription subscription = newSubscription(theCriteria, thePayload); - MethodOutcome methodOutcome = ourClient.create().resource(subscription).execute(); + MethodOutcome methodOutcome = myClient.create().resource(subscription).execute(); subscription.setId(methodOutcome.getId().getIdPart()); mySubscriptionIds.add(methodOutcome.getId()); @@ -178,7 +173,6 @@ public abstract class BaseSubscriptionsR5Test extends BaseResourceProviderR5Test } - public static class ObservationListener implements IResourceProvider { @Create @@ -218,7 +212,7 @@ public abstract class BaseSubscriptionsR5Test extends BaseResourceProviderR5Test } - @AfterClass + @AfterAll public static void reportTotalSelects() { ourLog.info("Total database select queries: {}", getQueryCount().getSelect()); } @@ -227,10 +221,10 @@ public abstract class BaseSubscriptionsR5Test extends BaseResourceProviderR5Test return ourCountHolder.getQueryCountMap().get(""); } - @BeforeClass + @BeforeAll public static void startListenerServer() throws Exception { - RestfulServer ourListenerRestServer = new RestfulServer(FhirContext.forR5()); - + RestfulServer ourListenerRestServer = new RestfulServer(FhirContext.forCached(FhirVersionEnum.R5)); + ObservationListener obsListener = new ObservationListener(); ourListenerRestServer.setResourceProviders(obsListener); @@ -245,11 +239,11 @@ public abstract class BaseSubscriptionsR5Test extends BaseResourceProviderR5Test ourListenerServer.setHandler(proxyHandler); JettyUtil.startServer(ourListenerServer); - ourListenerPort = JettyUtil.getPortForStartedServer(ourListenerServer); - ourListenerServerBase = "http://localhost:" + ourListenerPort + "/fhir/context"; + ourListenerPort = JettyUtil.getPortForStartedServer(ourListenerServer); + ourListenerServerBase = "http://localhost:" + ourListenerPort + "/fhir/context"; } - @AfterClass + @AfterAll public static void stopListenerServer() throws Exception { JettyUtil.closeServer(ourListenerServer); } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/FhirServiceUtil.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/FhirServiceUtil.java index ca1348586a9..c3928d03cca 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/FhirServiceUtil.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/FhirServiceUtil.java @@ -1,5 +1,6 @@ package ca.uhn.fhir.jpa.subscription; +import ca.uhn.fhir.context.FhirVersionEnum; import org.hl7.fhir.instance.model.api.IBaseResource; import ca.uhn.fhir.context.FhirContext; @@ -15,12 +16,12 @@ public class FhirServiceUtil { public static final String REST_HOOK_ENDPOINT = "http://localhost:10080/rest-hook"; public static IGenericClient getFhirDstu3Client() { - FhirContext ctx = FhirContext.forDstu3(); + FhirContext ctx = FhirContext.forCached(FhirVersionEnum.DSTU3); return ctx.newRestfulGenericClient(FHIR_DSTU3_URL); } public static IGenericClient getFhirDstu2Client() { - FhirContext ctx = FhirContext.forDstu2(); + FhirContext ctx = FhirContext.forCached(FhirVersionEnum.DSTU2); return ctx.newRestfulGenericClient(FHIR_DSTU2_URL); } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/SubscriptionValidatingInterceptorTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/SubscriptionValidatingInterceptorTest.java index bf8ee7f83c3..543546ec9ab 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/SubscriptionValidatingInterceptorTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/SubscriptionValidatingInterceptorTest.java @@ -1,35 +1,36 @@ package ca.uhn.fhir.jpa.subscription; import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.context.FhirVersionEnum; import ca.uhn.fhir.jpa.api.dao.DaoRegistry; -import ca.uhn.fhir.jpa.subscription.match.registry.SubscriptionCanonicalizer; import ca.uhn.fhir.jpa.subscription.match.matcher.matching.SubscriptionStrategyEvaluator; +import ca.uhn.fhir.jpa.subscription.match.registry.SubscriptionCanonicalizer; import ca.uhn.fhir.jpa.subscription.submit.interceptor.SubscriptionValidatingInterceptor; import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; import org.hl7.fhir.r4.model.Subscription; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.when; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class SubscriptionValidatingInterceptorTest { @Mock public DaoRegistry myDaoRegistry; private SubscriptionValidatingInterceptor mySvc; - private FhirContext myCtx = FhirContext.forR4(); + private FhirContext myCtx = FhirContext.forCached(FhirVersionEnum.R4); @Mock private SubscriptionStrategyEvaluator mySubscriptionStrategyEvaluator; - @Before + @BeforeEach public void before() { mySvc = new SubscriptionValidatingInterceptor(); mySvc.setSubscriptionCanonicalizerForUnitTest(new SubscriptionCanonicalizer(myCtx)); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/email/EmailSubscriptionDstu2Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/email/EmailSubscriptionDstu2Test.java index a83d6d87533..7e5c726baca 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/email/EmailSubscriptionDstu2Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/email/EmailSubscriptionDstu2Test.java @@ -14,7 +14,7 @@ import com.icegreen.greenmail.util.GreenMail; import com.icegreen.greenmail.util.GreenMailUtil; import com.icegreen.greenmail.util.ServerSetup; import org.hl7.fhir.instance.model.api.IIdType; -import org.junit.*; +import org.junit.jupiter.api.*; import static org.hamcrest.MatcherAssert.assertThat; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -27,7 +27,7 @@ import java.util.List; import java.util.concurrent.Callable; import static ca.uhn.fhir.jpa.subscription.resthook.RestHookTestDstu3Test.logAllInterceptors; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public class EmailSubscriptionDstu2Test extends BaseResourceProviderDstu2Test { @@ -40,7 +40,7 @@ public class EmailSubscriptionDstu2Test extends BaseResourceProviderDstu2Test { private SubscriptionTestUtil mySubscriptionTestUtil; @Override - @After + @AfterEach public void after() throws Exception { ourLog.info("** AFTER **"); super.after(); @@ -53,7 +53,7 @@ public class EmailSubscriptionDstu2Test extends BaseResourceProviderDstu2Test { } @Override - @Before + @BeforeEach public void before() throws Exception { super.before(); @@ -147,12 +147,12 @@ public class EmailSubscriptionDstu2Test extends BaseResourceProviderDstu2Test { } - @AfterClass + @AfterAll public static void afterClass() { ourTestSmtp.stop(); } - @BeforeClass + @BeforeAll public static void beforeClass() { ServerSetup smtp = new ServerSetup(0, null, ServerSetup.PROTOCOL_SMTP); smtp.setServerStartupTimeout(2000); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/email/EmailSubscriptionDstu3Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/email/EmailSubscriptionDstu3Test.java index 700514924f0..6175af37925 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/email/EmailSubscriptionDstu3Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/email/EmailSubscriptionDstu3Test.java @@ -8,9 +8,18 @@ import ca.uhn.fhir.util.HapiExtensions; import com.icegreen.greenmail.store.FolderException; import com.icegreen.greenmail.util.GreenMail; import com.icegreen.greenmail.util.ServerSetup; -import org.hl7.fhir.dstu3.model.*; +import org.hl7.fhir.dstu3.model.Bundle; +import org.hl7.fhir.dstu3.model.CodeableConcept; +import org.hl7.fhir.dstu3.model.Coding; +import org.hl7.fhir.dstu3.model.Observation; +import org.hl7.fhir.dstu3.model.StringType; +import org.hl7.fhir.dstu3.model.Subscription; import org.hl7.fhir.instance.model.api.IIdType; -import org.junit.*; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import javax.mail.internet.InternetAddress; @@ -21,7 +30,8 @@ import java.util.List; import java.util.concurrent.Callable; import static ca.uhn.fhir.jpa.subscription.resthook.RestHookTestDstu3Test.logAllInterceptors; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; /** * Test the rest-hook subscriptions @@ -37,9 +47,9 @@ public class EmailSubscriptionDstu3Test extends BaseResourceProviderDstu3Test { private static GreenMail ourTestSmtp; private List mySubscriptionIds = new ArrayList<>(); - @After + @AfterEach public void afterUnregisterEmailListener() { - ourLog.info("**** Starting @After *****"); + ourLog.info("**** Starting @AfterEach *****"); for (IIdType next : mySubscriptionIds) { ourClient.delete().resourceById(next).execute(); @@ -56,7 +66,7 @@ public class EmailSubscriptionDstu3Test extends BaseResourceProviderDstu3Test { mySubscriptionTestUtil.unregisterSubscriptionInterceptor(); } - @Before + @BeforeEach public void beforeRegisterEmailListener() throws FolderException { ourTestSmtp.purgeEmailFromAllMailboxes(); @@ -114,7 +124,6 @@ public class EmailSubscriptionDstu3Test extends BaseResourceProviderDstu3Test { /** * Tests an email subscription with payload set to XML. The email sent must include content in the body of the email that is formatted as XML. - * @throws Exception */ @Test public void testEmailSubscriptionNormal() throws Exception { @@ -131,7 +140,7 @@ public class EmailSubscriptionDstu3Test extends BaseResourceProviderDstu3Test { waitForSize(1, 60000, new Callable() { @Override - public Number call() throws Exception { + public Number call() { return ourTestSmtp.getReceivedMessages().length; } }); @@ -152,7 +161,6 @@ public class EmailSubscriptionDstu3Test extends BaseResourceProviderDstu3Test { /** * Tests an email subscription with payload set to JSON. The email sent must include content in the body of the email that is formatted as JSON. - * @throws Exception */ @Test public void testEmailSubscriptionWithCustom() throws Exception { @@ -163,7 +171,7 @@ public class EmailSubscriptionDstu3Test extends BaseResourceProviderDstu3Test { Subscription sub1 = createSubscription(criteria1, payload); Subscription subscriptionTemp = ourClient.read(Subscription.class, sub1.getId()); - Assert.assertNotNull(subscriptionTemp); + assertNotNull(subscriptionTemp); subscriptionTemp.getChannel().addExtension() .setUrl(HapiExtensions.EXT_SUBSCRIPTION_EMAIL_FROM) @@ -218,7 +226,7 @@ public class EmailSubscriptionDstu3Test extends BaseResourceProviderDstu3Test { Subscription sub1 = createSubscription(criteria1, payload); Subscription subscriptionTemp = ourClient.read(Subscription.class, sub1.getId()); - Assert.assertNotNull(subscriptionTemp); + assertNotNull(subscriptionTemp); subscriptionTemp.getChannel().addExtension() .setUrl(HapiExtensions.EXT_SUBSCRIPTION_EMAIL_FROM) .setValue(new StringType("myfrom@from.com")); @@ -265,12 +273,12 @@ public class EmailSubscriptionDstu3Test extends BaseResourceProviderDstu3Test { mySubscriptionTestUtil.waitForQueueToDrain(); } - @AfterClass + @AfterAll public static void afterClass() { ourTestSmtp.stop(); } - @BeforeClass + @BeforeAll public static void beforeClass() { ServerSetup smtp = new ServerSetup(0, null, ServerSetup.PROTOCOL_SMTP); smtp.setServerStartupTimeout(2000); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/email/JavaMailEmailSenderTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/email/JavaMailEmailSenderTest.java index e1b02a52986..4561f4b3ebc 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/email/JavaMailEmailSenderTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/email/JavaMailEmailSenderTest.java @@ -6,9 +6,9 @@ import com.icegreen.greenmail.util.GreenMail; import com.icegreen.greenmail.util.GreenMailUtil; import com.icegreen.greenmail.util.ServerSetup; import org.hl7.fhir.dstu3.model.IdType; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -16,7 +16,7 @@ import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeMessage; import java.util.Arrays; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public class JavaMailEmailSenderTest { @@ -58,12 +58,12 @@ public class JavaMailEmailSenderTest { assertEquals("foo", foundBody); } - @AfterClass + @AfterAll public static void afterClass() { ourTestSmtp.stop(); } - @BeforeClass + @BeforeAll public static void beforeClass() { ServerSetup smtp = new ServerSetup(0, null, ServerSetup.PROTOCOL_SMTP); smtp.setServerStartupTimeout(2000); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/module/matcher/InMemorySubscriptionMatcherR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/module/matcher/InMemorySubscriptionMatcherR4Test.java index 2d46f1b52c5..439f51a2a19 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/module/matcher/InMemorySubscriptionMatcherR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/module/matcher/InMemorySubscriptionMatcherR4Test.java @@ -61,23 +61,23 @@ import org.hl7.fhir.r4.model.StringType; import org.hl7.fhir.r4.model.Subscription; import org.hl7.fhir.r4.model.Task; import org.hl7.fhir.r4.model.ValueSet; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import java.math.BigDecimal; import java.util.ArrayList; import java.util.Date; import java.util.List; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = {TestR4Config.class}) public class InMemorySubscriptionMatcherR4Test { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(InMemorySubscriptionMatcherR4Test.class); @@ -95,14 +95,14 @@ public class InMemorySubscriptionMatcherR4Test { private void assertMatched(Resource resource, SearchParameterMap params) { InMemoryMatchResult result = match(resource, params); - assertTrue(result.getUnsupportedReason(), result.supported()); + assertTrue(result.supported(), result.getUnsupportedReason()); assertTrue(result.matched()); assertEquals(SubscriptionMatchingStrategy.IN_MEMORY, mySubscriptionStrategyEvaluator.determineStrategy(getCriteria(resource, params))); } private void assertNotMatched(Resource resource, SearchParameterMap params) { InMemoryMatchResult result = match(resource, params); - assertTrue(result.getUnsupportedReason(), result.supported()); + assertTrue(result.supported(), result.getUnsupportedReason()); assertFalse(result.matched()); assertEquals(SubscriptionMatchingStrategy.IN_MEMORY, mySubscriptionStrategyEvaluator.determineStrategy(getCriteria(resource, params))); } @@ -470,7 +470,7 @@ public class InMemorySubscriptionMatcherR4Test { msg.setId(new IdType("Patient/ABC")); InMemoryMatchResult result = myInMemorySubscriptionMatcher.match(subscription, msg); fail(); - } catch (AssertionError e){ + } catch (AssertionError e) { assertEquals("Reference at managingOrganization is invalid: urn:uuid:13720262-b392-465f-913e-54fb198ff954", e.getMessage()); } } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/resthook/RestHookActivatesPreExistingSubscriptionsR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/resthook/RestHookActivatesPreExistingSubscriptionsR4Test.java index 9753032bc79..e78e26d8a94 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/resthook/RestHookActivatesPreExistingSubscriptionsR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/resthook/RestHookActivatesPreExistingSubscriptionsR4Test.java @@ -1,6 +1,7 @@ package ca.uhn.fhir.jpa.subscription.resthook; import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.context.FhirVersionEnum; import ca.uhn.fhir.jpa.provider.r4.BaseResourceProviderR4Test; import ca.uhn.fhir.jpa.subscription.SubscriptionTestUtil; import ca.uhn.fhir.rest.annotation.ResourceParam; @@ -15,7 +16,7 @@ import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletHolder; import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.r4.model.*; -import org.junit.*; +import org.junit.jupiter.api.*; import static org.hamcrest.MatcherAssert.assertThat; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -26,7 +27,7 @@ import java.util.Collections; import java.util.Enumeration; import java.util.List; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import ca.uhn.fhir.test.utilities.JettyUtil; @@ -44,12 +45,12 @@ public class RestHookActivatesPreExistingSubscriptionsR4Test extends BaseResourc @Autowired private SubscriptionTestUtil mySubscriptionTestUtil; - @After + @AfterEach public void afterUnregisterRestHookListener() { mySubscriptionTestUtil.unregisterSubscriptionInterceptor(); } - @Before + @BeforeEach public void beforeSetSubscriptionActivatingInterceptor() { mySubscriptionLoader.doSyncSubscriptionsForUnitTest(); } @@ -66,7 +67,7 @@ public class RestHookActivatesPreExistingSubscriptionsR4Test extends BaseResourc channel.setPayload(thePayload); channel.setEndpoint(theEndpoint); - MethodOutcome methodOutcome = ourClient.create().resource(subscription).execute(); + MethodOutcome methodOutcome = myClient.create().resource(subscription).execute(); subscription.setId(methodOutcome.getId().getIdPart()); waitForQueueToDrain(); @@ -83,7 +84,7 @@ public class RestHookActivatesPreExistingSubscriptionsR4Test extends BaseResourc observation.setStatus(Observation.ObservationStatus.FINAL); - MethodOutcome methodOutcome = ourClient.create().resource(observation).execute(); + MethodOutcome methodOutcome = myClient.create().resource(observation).execute(); String observationId = methodOutcome.getId().getIdPart(); observation.setId(observationId); @@ -148,9 +149,9 @@ public class RestHookActivatesPreExistingSubscriptionsR4Test extends BaseResourc } - @BeforeClass + @BeforeAll public static void startListenerServer() throws Exception { - ourListenerRestServer = new RestfulServer(FhirContext.forR4()); + ourListenerRestServer = new RestfulServer(FhirContext.forCached(FhirVersionEnum.R4)); ObservationListener obsListener = new ObservationListener(); ourListenerRestServer.setResourceProviders(obsListener); @@ -170,7 +171,7 @@ public class RestHookActivatesPreExistingSubscriptionsR4Test extends BaseResourc ourListenerServerBase = "http://localhost:" + ourListenerPort + "/fhir/context"; } - @AfterClass + @AfterAll public static void stopListenerServer() throws Exception { JettyUtil.closeServer(ourListenerServer); } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/resthook/RestHookTestDstu2Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/resthook/RestHookTestDstu2Test.java index bb228a84bbf..6bb50856b2e 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/resthook/RestHookTestDstu2Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/resthook/RestHookTestDstu2Test.java @@ -1,6 +1,7 @@ package ca.uhn.fhir.jpa.subscription.resthook; import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.context.FhirVersionEnum; import ca.uhn.fhir.jpa.api.config.DaoConfig; import ca.uhn.fhir.jpa.provider.BaseResourceProviderDstu2Test; import ca.uhn.fhir.jpa.subscription.SubscriptionTestUtil; @@ -27,7 +28,7 @@ import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletHolder; import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IIdType; -import org.junit.*; +import org.junit.jupiter.api.*; import static org.hamcrest.MatcherAssert.assertThat; import org.springframework.beans.factory.annotation.Autowired; import javax.validation.constraints.NotNull; @@ -37,7 +38,7 @@ import java.util.stream.Collectors; import static ca.uhn.fhir.jpa.subscription.resthook.RestHookTestDstu3Test.logAllInterceptors; import static org.hamcrest.CoreMatchers.containsString; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; /** * Test the rest-hook subscriptions @@ -56,7 +57,7 @@ public class RestHookTestDstu2Test extends BaseResourceProviderDstu2Test { @Autowired private SubscriptionTestUtil mySubscriptionTestUtil; - @After + @AfterEach public void afterUnregisterRestHookListener() { ourLog.info("** AFTER **"); for (IIdType next : mySubscriptionIds) { @@ -74,7 +75,7 @@ public class RestHookTestDstu2Test extends BaseResourceProviderDstu2Test { mySubscriptionTestUtil.unregisterSubscriptionInterceptor(); } - @Before + @BeforeEach public void beforeRegisterRestHookListener() { ourLog.info("Before re-registering interceptors"); logAllInterceptors(myInterceptorRegistry); @@ -83,7 +84,7 @@ public class RestHookTestDstu2Test extends BaseResourceProviderDstu2Test { logAllInterceptors(myInterceptorRegistry); } - @Before + @BeforeEach public void beforeReset() { ourCreatedObservations.clear(); ourUpdatedObservations.clear(); @@ -173,7 +174,7 @@ public class RestHookTestDstu2Test extends BaseResourceProviderDstu2Test { waitForSize(1, ourUpdatedObservations); Subscription subscriptionTemp = ourClient.read(Subscription.class, subscription2.getId()); - Assert.assertNotNull(subscriptionTemp); + assertNotNull(subscriptionTemp); // Update subscription 2 to match as well subscriptionTemp.setCriteria(criteria1); @@ -224,9 +225,9 @@ public class RestHookTestDstu2Test extends BaseResourceProviderDstu2Test { waitForSize(0, ourCreatedObservations); waitForSize(5, ourUpdatedObservations); - Assert.assertFalse(subscription1.getId().equals(subscription2.getId())); - Assert.assertFalse(observation1.getId().isEmpty()); - Assert.assertFalse(observation2.getId().isEmpty()); + assertFalse(subscription1.getId().equals(subscription2.getId())); + assertFalse(observation1.getId().isEmpty()); + assertFalse(observation2.getId().isEmpty()); } @Test @@ -248,7 +249,7 @@ public class RestHookTestDstu2Test extends BaseResourceProviderDstu2Test { waitForSize(1, ourUpdatedObservations); Subscription subscriptionTemp = ourClient.read(Subscription.class, subscription2.getId()); - Assert.assertNotNull(subscriptionTemp); + assertNotNull(subscriptionTemp); subscriptionTemp.setCriteria(criteria1); ourClient.update().resource(subscriptionTemp).withId(subscriptionTemp.getIdElement()).execute(); @@ -296,9 +297,9 @@ public class RestHookTestDstu2Test extends BaseResourceProviderDstu2Test { waitForSize(0, ourCreatedObservations); waitForSize(5, ourUpdatedObservations); - Assert.assertFalse(subscription1.getId().equals(subscription2.getId())); - Assert.assertFalse(observation1.getId().isEmpty()); - Assert.assertFalse(observation2.getId().isEmpty()); + assertFalse(subscription1.getId().equals(subscription2.getId())); + assertFalse(observation1.getId().isEmpty()); + assertFalse(observation2.getId().isEmpty()); } @Test @@ -319,9 +320,9 @@ public class RestHookTestDstu2Test extends BaseResourceProviderDstu2Test { mySubscriptionTestUtil.waitForQueueToDrain(); } - @BeforeClass + @BeforeAll public static void startListenerServer() throws Exception { - ourListenerRestServer = new RestfulServer(FhirContext.forDstu2()); + ourListenerRestServer = new RestfulServer(FhirContext.forCached(FhirVersionEnum.DSTU2)); ObservationListener obsListener = new ObservationListener(); ourListenerRestServer.setResourceProviders(obsListener); @@ -341,7 +342,7 @@ public class RestHookTestDstu2Test extends BaseResourceProviderDstu2Test { ourListenerServerBase = "http://localhost:" + ourListenerPort + "/fhir/context"; } - @AfterClass + @AfterAll public static void stopListenerServer() throws Exception { JettyUtil.closeServer(ourListenerServer); } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/resthook/RestHookTestDstu3Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/resthook/RestHookTestDstu3Test.java index a9f24897338..310bbd35715 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/resthook/RestHookTestDstu3Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/resthook/RestHookTestDstu3Test.java @@ -1,6 +1,7 @@ package ca.uhn.fhir.jpa.subscription.resthook; import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.context.FhirVersionEnum; import ca.uhn.fhir.interceptor.api.IInterceptorService; import ca.uhn.fhir.jpa.api.config.DaoConfig; import ca.uhn.fhir.jpa.provider.dstu3.BaseResourceProviderDstu3Test; @@ -26,7 +27,7 @@ import org.eclipse.jetty.servlet.ServletHolder; import org.hl7.fhir.dstu3.model.*; import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IIdType; -import org.junit.*; +import org.junit.jupiter.api.*; import static org.hamcrest.MatcherAssert.assertThat; import org.springframework.beans.factory.annotation.Autowired; import javax.servlet.http.HttpServletRequest; @@ -40,7 +41,7 @@ import java.util.stream.Collectors; import static org.awaitility.Awaitility.await; import static org.hamcrest.Matchers.containsString; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; /** * Test the rest-hook subscriptions @@ -63,9 +64,9 @@ public class RestHookTestDstu3Test extends BaseResourceProviderDstu3Test { @Autowired private SubscriptionTestUtil mySubscriptionTestUtil; - @After + @AfterEach public void afterUnregisterRestHookListener() { - ourLog.info("**** Starting @After *****"); + ourLog.info("**** Starting @AfterEach *****"); for (IIdType next : mySubscriptionIds) { ourClient.delete().resourceById(next).execute(); @@ -83,7 +84,7 @@ public class RestHookTestDstu3Test extends BaseResourceProviderDstu3Test { myInterceptorRegistry.unregisterInterceptor(ourSubscriptionDebugLogInterceptor); } - @Before + @BeforeEach public void beforeRegisterRestHookListener() { ourLog.info("Before re-registering interceptors"); logAllInterceptors(myInterceptorRegistry); @@ -93,7 +94,7 @@ public class RestHookTestDstu3Test extends BaseResourceProviderDstu3Test { logAllInterceptors(myInterceptorRegistry); } - @Before + @BeforeEach public void beforeReset() { ourCreatedObservations.clear(); ourUpdatedObservations.clear(); @@ -188,24 +189,24 @@ public class RestHookTestDstu3Test extends BaseResourceProviderDstu3Test { // Should see 1 subscription notification with authorization header waitForSize(1, ourNotificationServlet.getReceivedAuthorizationHeaders()); - Assert.assertEquals(1, ourNotificationServlet.getReceivedNotificationCount()); - Assert.assertEquals("abc-def", ourNotificationServlet.getReceivedAuthorizationHeaders().get(0)); + assertEquals(1, ourNotificationServlet.getReceivedNotificationCount()); + assertEquals("abc-def", ourNotificationServlet.getReceivedAuthorizationHeaders().get(0)); ourNotificationServlet.reset(); sendObservation(code, "SNOMED-CT"); // Should see 1 subscription notification with authorization header waitForSize(1, ourNotificationServlet.getReceivedAuthorizationHeaders()); - Assert.assertEquals(1, ourNotificationServlet.getReceivedNotificationCount()); - Assert.assertEquals("abc-def", ourNotificationServlet.getReceivedAuthorizationHeaders().get(0)); + assertEquals(1, ourNotificationServlet.getReceivedNotificationCount()); + assertEquals("abc-def", ourNotificationServlet.getReceivedAuthorizationHeaders().get(0)); ourNotificationServlet.reset(); Observation observationTemp3 = sendObservation(code, "SNOMED-CT"); /// Should see 1 subscription notification with authorization header waitForSize(1, ourNotificationServlet.getReceivedAuthorizationHeaders()); - Assert.assertEquals(1, ourNotificationServlet.getReceivedNotificationCount()); - Assert.assertEquals("abc-def", ourNotificationServlet.getReceivedAuthorizationHeaders().get(0)); + assertEquals(1, ourNotificationServlet.getReceivedNotificationCount()); + assertEquals("abc-def", ourNotificationServlet.getReceivedAuthorizationHeaders().get(0)); ourNotificationServlet.reset(); Observation observation3 = ourClient.read(Observation.class, observationTemp3.getId()); @@ -218,8 +219,8 @@ public class RestHookTestDstu3Test extends BaseResourceProviderDstu3Test { // Should see 2 subscription notifications with and without authorization header waitForSize(1, ourNotificationServlet.getReceivedAuthorizationHeaders()); - Assert.assertEquals(1, ourNotificationServlet.getReceivedNotificationCount()); - Assert.assertNull(ourNotificationServlet.getReceivedAuthorizationHeaders().get(0)); + assertEquals(1, ourNotificationServlet.getReceivedNotificationCount()); + assertNull(ourNotificationServlet.getReceivedAuthorizationHeaders().get(0)); ourNotificationServlet.reset(); } @@ -291,7 +292,7 @@ public class RestHookTestDstu3Test extends BaseResourceProviderDstu3Test { // Modify subscription 2 to also match Subscription subscriptionTemp = ourClient.read(Subscription.class, subscription2.getId()); - Assert.assertNotNull(subscriptionTemp); + assertNotNull(subscriptionTemp); subscriptionTemp.setCriteria(criteria1); ourClient.update().resource(subscriptionTemp).withId(subscriptionTemp.getIdElement()).execute(); waitForQueueToDrain(); @@ -341,9 +342,9 @@ public class RestHookTestDstu3Test extends BaseResourceProviderDstu3Test { waitForSize(0, ourCreatedObservations); waitForSize(5, ourUpdatedObservations); - Assert.assertFalse(subscription1.getId().equals(subscription2.getId())); - Assert.assertFalse(observation1.getId().isEmpty()); - Assert.assertFalse(observation2.getId().isEmpty()); + assertFalse(subscription1.getId().equals(subscription2.getId())); + assertFalse(observation1.getId().isEmpty()); + assertFalse(observation2.getId().isEmpty()); } @Test @@ -368,7 +369,7 @@ public class RestHookTestDstu3Test extends BaseResourceProviderDstu3Test { // Modify subscription 2 to also match Subscription subscriptionTemp = ourClient.read(Subscription.class, subscription2.getId()); - Assert.assertNotNull(subscriptionTemp); + assertNotNull(subscriptionTemp); subscriptionTemp.setCriteria(criteria1); ourClient.update().resource(subscriptionTemp).withId(subscriptionTemp.getIdElement()).execute(); waitForQueueToDrain(); @@ -421,9 +422,9 @@ public class RestHookTestDstu3Test extends BaseResourceProviderDstu3Test { waitForSize(0, ourCreatedObservations); waitForSize(5, ourUpdatedObservations); - Assert.assertNotEquals(subscription1.getId(), subscription2.getId()); - Assert.assertFalse(observation1.getId().isEmpty()); - Assert.assertFalse(observation2.getId().isEmpty()); + assertNotEquals(subscription1.getId(), subscription2.getId()); + assertFalse(observation1.getId().isEmpty()); + assertFalse(observation2.getId().isEmpty()); } @Test @@ -562,7 +563,7 @@ public class RestHookTestDstu3Test extends BaseResourceProviderDstu3Test { cr.setOccurrence(new DateTimeType("2019-02-08T00:01:00-05:00")); communicationRequestListenerLatch = new CountDownLatch(1); ourClient.create().resource(cr).execute(); - assertTrue("Timed out waiting for subscription to match", communicationRequestListenerLatch.await(10, TimeUnit.SECONDS)); + assertTrue(communicationRequestListenerLatch.await(10, TimeUnit.SECONDS), "Timed out waiting for subscription to match"); } @Test @@ -585,7 +586,7 @@ public class RestHookTestDstu3Test extends BaseResourceProviderDstu3Test { public MethodOutcome create(@ResourceParam Observation theObservation, HttpServletRequest theRequest) { ourLog.info("Received Listener Create"); ourContentTypes.add(theRequest.getHeader(Constants.HEADER_CONTENT_TYPE).replaceAll(";.*", "")); - ourCreatedObservations.add((Observation) theObservation); + ourCreatedObservations.add(theObservation); return new MethodOutcome(new IdType("Observation/1"), true); } @@ -635,9 +636,9 @@ public class RestHookTestDstu3Test extends BaseResourceProviderDstu3Test { ourLog.info("Registered interceptors:\n * {}", interceptorList); } - @BeforeClass + @BeforeAll public static void startListenerServer() throws Exception { - ourListenerRestServer = new RestfulServer(FhirContext.forDstu3()); + ourListenerRestServer = new RestfulServer(FhirContext.forCached(FhirVersionEnum.DSTU3)); ObservationListener obsListener = new ObservationListener(); CommunicationRequestListener crListener = new CommunicationRequestListener(); @@ -663,7 +664,7 @@ public class RestHookTestDstu3Test extends BaseResourceProviderDstu3Test { ourNotificationListenerServer = "http://localhost:" + ourListenerPort + "/fhir/subscription"; } - @AfterClass + @AfterAll public static void stopListenerServer() throws Exception { JettyUtil.closeServer(ourListenerServer); } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/resthook/RestHookTestR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/resthook/RestHookTestR4Test.java index 146c8933d0d..4a547aa3eb8 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/resthook/RestHookTestR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/resthook/RestHookTestR4Test.java @@ -10,9 +10,8 @@ import ca.uhn.fhir.util.HapiExtensions; import org.hl7.fhir.instance.model.api.IBaseBundle; import org.hl7.fhir.instance.model.api.IIdType; import org.hl7.fhir.r4.model.*; -import org.junit.After; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -26,11 +25,13 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.hasItem; import static org.hamcrest.Matchers.matchesPattern; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; /** * Test the rest-hook subscriptions @@ -41,9 +42,9 @@ public class RestHookTestR4Test extends BaseSubscriptionsR4Test { @Autowired StoppableSubscriptionDeliveringRestHookSubscriber myStoppableSubscriptionDeliveringRestHookSubscriber; - @After + @AfterEach public void cleanupStoppableSubscriptionDeliveringRestHookSubscriber() { - ourLog.info("@After"); + ourLog.info("@AfterEach"); myStoppableSubscriptionDeliveringRestHookSubscriber.setCountDownLatch(null); myStoppableSubscriptionDeliveringRestHookSubscriber.unPause(); } @@ -299,7 +300,7 @@ public class RestHookTestR4Test extends BaseSubscriptionsR4Test { // Send an update with no changes obs.setId(obs.getIdElement().toUnqualifiedVersionless()); - ourClient.update().resource(obs).execute(); + myClient.update().resource(obs).execute(); // Should be no further deliveries Thread.sleep(1000); @@ -340,8 +341,8 @@ public class RestHookTestR4Test extends BaseSubscriptionsR4Test { .addExtension(HapiExtensions.EXT_SUBSCRIPTION_RESTHOOK_STRIP_VERSION_IDS, new BooleanType("true")); ourLog.info("** About to update subscription"); - int modCount = (int) myCountingInterceptor.getSentCount("Subscription"); - ourClient.update().resource(subscription1).execute(); + int modCount = myCountingInterceptor.getSentCount("Subscription"); + myClient.update().resource(subscription1).execute(); waitForSize(modCount + 2, () -> myCountingInterceptor.getSentCount("Subscription"), () -> myCountingInterceptor.toString()); ourLog.info("** About to send observation"); @@ -379,7 +380,7 @@ public class RestHookTestR4Test extends BaseSubscriptionsR4Test { assertNull(observation.getNoteFirstRep().getText()); observation.getNoteFirstRep().setText("changed"); - MethodOutcome methodOutcome = ourClient.update().resource(observation).execute(); + MethodOutcome methodOutcome = myClient.update().resource(observation).execute(); assertEquals("2", methodOutcome.getId().getVersionIdPart()); assertEquals("changed", observation.getNoteFirstRep().getText()); @@ -414,7 +415,7 @@ public class RestHookTestR4Test extends BaseSubscriptionsR4Test { subscription .getChannel() .addExtension(HapiExtensions.EXT_SUBSCRIPTION_RESTHOOK_DELIVER_LATEST_VERSION, new BooleanType("true")); - ourClient.create().resource(subscription).execute(); + myClient.create().resource(subscription).execute(); waitForActivatedSubscriptionCount(1); @@ -428,7 +429,7 @@ public class RestHookTestR4Test extends BaseSubscriptionsR4Test { assertNull(observation.getNoteFirstRep().getText()); observation.getNoteFirstRep().setText("changed"); - MethodOutcome methodOutcome = ourClient.update().resource(observation).execute(); + MethodOutcome methodOutcome = myClient.update().resource(observation).execute(); assertEquals("2", methodOutcome.getId().getVersionIdPart()); assertEquals("changed", observation.getNoteFirstRep().getText()); @@ -472,11 +473,11 @@ public class RestHookTestR4Test extends BaseSubscriptionsR4Test { assertEquals("1", ourUpdatedObservations.get(0).getIdElement().getVersionIdPart()); - Subscription subscriptionTemp = ourClient.read(Subscription.class, subscription2.getId()); - Assert.assertNotNull(subscriptionTemp); + Subscription subscriptionTemp = myClient.read(Subscription.class, subscription2.getId()); + assertNotNull(subscriptionTemp); subscriptionTemp.setCriteria(criteria1); - ourClient.update().resource(subscriptionTemp).withId(subscriptionTemp.getIdElement()).execute(); + myClient.update().resource(subscriptionTemp).withId(subscriptionTemp.getIdElement()).execute(); waitForQueueToDrain(); Observation observation2 = sendObservation(code, "SNOMED-CT"); @@ -486,7 +487,7 @@ public class RestHookTestR4Test extends BaseSubscriptionsR4Test { waitForSize(0, ourCreatedObservations); waitForSize(3, ourUpdatedObservations); - ourClient.delete().resourceById(new IdType("Subscription/" + subscription2.getId())).execute(); + myClient.delete().resourceById(new IdType("Subscription/" + subscription2.getId())).execute(); waitForActivatedSubscriptionCount(1); Observation observationTemp3 = sendObservation(code, "SNOMED-CT"); @@ -496,27 +497,27 @@ public class RestHookTestR4Test extends BaseSubscriptionsR4Test { waitForSize(0, ourCreatedObservations); waitForSize(4, ourUpdatedObservations); - Observation observation3 = ourClient.read(Observation.class, observationTemp3.getId()); + Observation observation3 = myClient.read(Observation.class, observationTemp3.getId()); CodeableConcept codeableConcept = new CodeableConcept(); observation3.setCode(codeableConcept); Coding coding = codeableConcept.addCoding(); coding.setCode(code + "111"); coding.setSystem("SNOMED-CT"); - ourClient.update().resource(observation3).withId(observation3.getIdElement()).execute(); + myClient.update().resource(observation3).withId(observation3.getIdElement()).execute(); // Should see no subscription notification waitForQueueToDrain(); waitForSize(0, ourCreatedObservations); waitForSize(4, ourUpdatedObservations); - Observation observation3a = ourClient.read(Observation.class, observationTemp3.getId()); + Observation observation3a = myClient.read(Observation.class, observationTemp3.getId()); CodeableConcept codeableConcept1 = new CodeableConcept(); observation3a.setCode(codeableConcept1); Coding coding1 = codeableConcept1.addCoding(); coding1.setCode(code); coding1.setSystem("SNOMED-CT"); - ourClient.update().resource(observation3a).withId(observation3a.getIdElement()).execute(); + myClient.update().resource(observation3a).withId(observation3a.getIdElement()).execute(); // Should see only one subscription notification waitForQueueToDrain(); @@ -552,11 +553,11 @@ public class RestHookTestR4Test extends BaseSubscriptionsR4Test { assertEquals("1", ourUpdatedObservations.get(0).getIdElement().getVersionIdPart()); - Subscription subscriptionTemp = ourClient.read(Subscription.class, subscription2.getId()); - Assert.assertNotNull(subscriptionTemp); + Subscription subscriptionTemp = myClient.read(Subscription.class, subscription2.getId()); + assertNotNull(subscriptionTemp); subscriptionTemp.setCriteria(criteria1); - ourClient.update().resource(subscriptionTemp).withId(subscriptionTemp.getIdElement()).execute(); + myClient.update().resource(subscriptionTemp).withId(subscriptionTemp.getIdElement()).execute(); waitForQueueToDrain(); Observation observation2 = sendObservation(code, "SNOMED-CT"); @@ -566,7 +567,7 @@ public class RestHookTestR4Test extends BaseSubscriptionsR4Test { waitForSize(0, ourCreatedObservations); waitForSize(3, ourUpdatedObservations); - ourClient.delete().resourceById(new IdType("Subscription/" + subscription2.getId())).execute(); + myClient.delete().resourceById(new IdType("Subscription/" + subscription2.getId())).execute(); waitForQueueToDrain(); Observation observationTemp3 = sendObservation(code, "SNOMED-CT"); @@ -576,27 +577,27 @@ public class RestHookTestR4Test extends BaseSubscriptionsR4Test { waitForSize(0, ourCreatedObservations); waitForSize(4, ourUpdatedObservations); - Observation observation3 = ourClient.read(Observation.class, observationTemp3.getId()); + Observation observation3 = myClient.read(Observation.class, observationTemp3.getId()); CodeableConcept codeableConcept = new CodeableConcept(); observation3.setCode(codeableConcept); Coding coding = codeableConcept.addCoding(); coding.setCode(code + "111"); coding.setSystem("SNOMED-CT"); - ourClient.update().resource(observation3).withId(observation3.getIdElement()).execute(); + myClient.update().resource(observation3).withId(observation3.getIdElement()).execute(); // Should see no subscription notification waitForQueueToDrain(); waitForSize(0, ourCreatedObservations); waitForSize(4, ourUpdatedObservations); - Observation observation3a = ourClient.read(Observation.class, observationTemp3.getId()); + Observation observation3a = myClient.read(Observation.class, observationTemp3.getId()); CodeableConcept codeableConcept1 = new CodeableConcept(); observation3a.setCode(codeableConcept1); Coding coding1 = codeableConcept1.addCoding(); coding1.setCode(code); coding1.setSystem("SNOMED-CT"); - ourClient.update().resource(observation3a).withId(observation3a.getIdElement()).execute(); + myClient.update().resource(observation3a).withId(observation3a.getIdElement()).execute(); // Should see only one subscription notification waitForQueueToDrain(); @@ -628,10 +629,10 @@ public class RestHookTestR4Test extends BaseSubscriptionsR4Test { waitForSize(1, ourUpdatedObservations); assertEquals(Constants.CT_FHIR_XML_NEW, ourContentTypes.get(0)); - Subscription subscriptionTemp = ourClient.read(Subscription.class, subscription2.getId()); - Assert.assertNotNull(subscriptionTemp); + Subscription subscriptionTemp = myClient.read(Subscription.class, subscription2.getId()); + assertNotNull(subscriptionTemp); subscriptionTemp.setCriteria(criteria1); - ourClient.update().resource(subscriptionTemp).withId(subscriptionTemp.getIdElement()).execute(); + myClient.update().resource(subscriptionTemp).withId(subscriptionTemp.getIdElement()).execute(); waitForQueueToDrain(); Observation observation2 = sendObservation(code, "SNOMED-CT"); @@ -641,7 +642,7 @@ public class RestHookTestR4Test extends BaseSubscriptionsR4Test { waitForSize(0, ourCreatedObservations); waitForSize(3, ourUpdatedObservations); - ourClient.delete().resourceById(new IdType("Subscription/" + subscription2.getId())).execute(); + myClient.delete().resourceById(new IdType("Subscription/" + subscription2.getId())).execute(); Observation observationTemp3 = sendObservation(code, "SNOMED-CT"); @@ -650,27 +651,27 @@ public class RestHookTestR4Test extends BaseSubscriptionsR4Test { waitForSize(0, ourCreatedObservations); waitForSize(4, ourUpdatedObservations); - Observation observation3 = ourClient.read(Observation.class, observationTemp3.getId()); + Observation observation3 = myClient.read(Observation.class, observationTemp3.getId()); CodeableConcept codeableConcept = new CodeableConcept(); observation3.setCode(codeableConcept); Coding coding = codeableConcept.addCoding(); coding.setCode(code + "111"); coding.setSystem("SNOMED-CT"); - ourClient.update().resource(observation3).withId(observation3.getIdElement()).execute(); + myClient.update().resource(observation3).withId(observation3.getIdElement()).execute(); // Should see no subscription notification waitForQueueToDrain(); waitForSize(0, ourCreatedObservations); waitForSize(4, ourUpdatedObservations); - Observation observation3a = ourClient.read(Observation.class, observationTemp3.getId()); + Observation observation3a = myClient.read(Observation.class, observationTemp3.getId()); CodeableConcept codeableConcept1 = new CodeableConcept(); observation3a.setCode(codeableConcept1); Coding coding1 = codeableConcept1.addCoding(); coding1.setCode(code); coding1.setSystem("SNOMED-CT"); - ourClient.update().resource(observation3a).withId(observation3a.getIdElement()).execute(); + myClient.update().resource(observation3a).withId(observation3a.getIdElement()).execute(); // Should see only one subscription notification waitForQueueToDrain(); @@ -722,7 +723,7 @@ public class RestHookTestR4Test extends BaseSubscriptionsR4Test { .getRequest() .setUrl("Patient?identifier=foo|bar2") .setMethod(Bundle.HTTPVerb.PUT); - ourClient.transaction().withBundle(requestBundle).execute(); + myClient.transaction().withBundle(requestBundle).execute(); // Should see 1 subscription notification waitForSize(0, ourCreatedObservations); @@ -753,12 +754,12 @@ public class RestHookTestR4Test extends BaseSubscriptionsR4Test { Thread.sleep(1000); assertEquals(0, ourUpdatedObservations.size()); - Subscription subscriptionTemp = ourClient.read().resource(Subscription.class).withId(subscription2.getId()).execute(); - Assert.assertNotNull(subscriptionTemp); + Subscription subscriptionTemp = myClient.read().resource(Subscription.class).withId(subscription2.getId()).execute(); + assertNotNull(subscriptionTemp); String criteriaGood = "Observation?code=SNOMED-CT|" + code + "&_format=xml"; subscriptionTemp.setCriteria(criteriaGood); ourLog.info("** About to update subscription"); - ourClient.update().resource(subscriptionTemp).withId(subscriptionTemp.getIdElement()).execute(); + myClient.update().resource(subscriptionTemp).withId(subscriptionTemp.getIdElement()).execute(); waitForQueueToDrain(); ourLog.info("** About to send Observation 2"); @@ -769,7 +770,7 @@ public class RestHookTestR4Test extends BaseSubscriptionsR4Test { waitForSize(0, ourCreatedObservations); waitForSize(1, ourUpdatedObservations); - ourClient.delete().resourceById(new IdType("Subscription/" + subscription2.getId())).execute(); + myClient.delete().resourceById(new IdType("Subscription/" + subscription2.getId())).execute(); Observation observationTemp3 = sendObservation(code, "SNOMED-CT"); @@ -827,7 +828,7 @@ public class RestHookTestR4Test extends BaseSubscriptionsR4Test { subscription.getChannel().addHeader("X-Foo: FOO"); subscription.getChannel().addHeader("X-Bar: BAR"); subscription.setStatus(Subscription.SubscriptionStatus.REQUESTED); - ourClient.update().resource(subscription).execute(); + myClient.update().resource(subscription).execute(); waitForQueueToDrain(); sendObservation(code, "SNOMED-CT"); @@ -860,7 +861,7 @@ public class RestHookTestR4Test extends BaseSubscriptionsR4Test { // Disable subscription.setStatus(Subscription.SubscriptionStatus.OFF); - ourClient.update().resource(subscription).execute(); + myClient.update().resource(subscription).execute(); waitForQueueToDrain(); // Send another object @@ -873,28 +874,34 @@ public class RestHookTestR4Test extends BaseSubscriptionsR4Test { } - @Test(expected = UnprocessableEntityException.class) + @Test public void testInvalidProvenanceParam() { - String payload = "application/fhir+json"; - String criteriabad = "Provenance?activity=http://hl7.org/fhir/v3/DocumentCompletion%7CAU"; - Subscription subscription = newSubscription(criteriabad, payload); - ourClient.create().resource(subscription).execute(); + assertThrows(UnprocessableEntityException.class, () -> { + String payload = "application/fhir+json"; + String criteriabad = "Provenance?activity=http://hl7.org/fhir/v3/DocumentCompletion%7CAU"; + Subscription subscription = newSubscription(criteriabad, payload); + myClient.create().resource(subscription).execute(); + }); } - @Test(expected = UnprocessableEntityException.class) + @Test public void testInvalidProcedureRequestParam() { - String payload = "application/fhir+json"; - String criteriabad = "ProcedureRequest?intent=instance-order&category=Laboratory"; - Subscription subscription = newSubscription(criteriabad, payload); - ourClient.create().resource(subscription).execute(); + assertThrows(UnprocessableEntityException.class, () -> { + String payload = "application/fhir+json"; + String criteriabad = "ProcedureRequest?intent=instance-order&category=Laboratory"; + Subscription subscription = newSubscription(criteriabad, payload); + myClient.create().resource(subscription).execute(); + }); } - @Test(expected = UnprocessableEntityException.class) + @Test public void testInvalidBodySiteParam() { - String payload = "application/fhir+json"; - String criteriabad = "BodySite?accessType=Catheter"; - Subscription subscription = newSubscription(criteriabad, payload); - ourClient.create().resource(subscription).execute(); + assertThrows(UnprocessableEntityException.class, () -> { + String payload = "application/fhir+json"; + String criteriabad = "BodySite?accessType=Catheter"; + Subscription subscription = newSubscription(criteriabad, payload); + myClient.create().resource(subscription).execute(); + }); } @Test @@ -903,7 +910,7 @@ public class RestHookTestR4Test extends BaseSubscriptionsR4Test { String payload = "application/fhir+json"; String criteriaGood = "Patient?gender=male"; Subscription subscription = newSubscription(criteriaGood, payload); - ourClient.create().resource(subscription).execute(); + myClient.create().resource(subscription).execute(); await().until(() -> subscriptionCount() == 1); } @@ -917,10 +924,10 @@ public class RestHookTestR4Test extends BaseSubscriptionsR4Test { try { Subscription subscription = newSubscription("Observation?", "application/fhir+json"); - IIdType id = ourClient.create().resource(subscription).execute().getId().toUnqualifiedVersionless(); + IIdType id = myClient.create().resource(subscription).execute().getId().toUnqualifiedVersionless(); Thread.sleep(1000); - subscription = ourClient.read().resource(Subscription.class).withId(id).execute(); + subscription = myClient.read().resource(Subscription.class).withId(id).execute(); assertEquals(Subscription.SubscriptionStatus.REQUESTED, subscription.getStatus()); } finally { @@ -930,7 +937,7 @@ public class RestHookTestR4Test extends BaseSubscriptionsR4Test { private int subscriptionCount() { - IBaseBundle found = ourClient.search().forResource(Subscription.class).cacheControl(new CacheControlDirective().setNoCache(true)).execute(); + IBaseBundle found = myClient.search().forResource(Subscription.class).cacheControl(new CacheControlDirective().setNoCache(true)).execute(); return toUnqualifiedVersionlessIdValues(found).size(); } @@ -940,7 +947,7 @@ public class RestHookTestR4Test extends BaseSubscriptionsR4Test { subscription.setStatus(null); try { - ourClient.create().resource(subscription).execute(); + myClient.create().resource(subscription).execute(); fail(); } catch (UnprocessableEntityException e) { assertThat(e.getMessage(), containsString("Can not process submitted Subscription - Subscription.status must be populated on this server")); @@ -955,7 +962,7 @@ public class RestHookTestR4Test extends BaseSubscriptionsR4Test { String criteriaBad = "BodySite?accessType=Catheter"; Subscription subscription = newSubscription(criteriaBad, payload); try { - ourClient.create().resource(subscription).execute(); + myClient.create().resource(subscription).execute(); } catch (UnprocessableEntityException e) { ourLog.info("Expected exception", e); } @@ -981,7 +988,7 @@ public class RestHookTestR4Test extends BaseSubscriptionsR4Test { { Observation bodySite = new Observation(); bodySite.addExtension().setUrl("Observation#accessType").setValue(new Coding().setCode("Catheter")); - MethodOutcome methodOutcome = ourClient.create().resource(bodySite).execute(); + MethodOutcome methodOutcome = myClient.create().resource(bodySite).execute(); assertEquals(true, methodOutcome.getCreated()); waitForQueueToDrain(); waitForSize(1, ourUpdatedObservations); @@ -989,14 +996,14 @@ public class RestHookTestR4Test extends BaseSubscriptionsR4Test { { Observation observation = new Observation(); observation.addExtension().setUrl("Observation#accessType").setValue(new Coding().setCode("PD Catheter")); - MethodOutcome methodOutcome = ourClient.create().resource(observation).execute(); + MethodOutcome methodOutcome = myClient.create().resource(observation).execute(); assertEquals(true, methodOutcome.getCreated()); waitForQueueToDrain(); waitForSize(2, ourUpdatedObservations); } { Observation observation = new Observation(); - MethodOutcome methodOutcome = ourClient.create().resource(observation).execute(); + MethodOutcome methodOutcome = myClient.create().resource(observation).execute(); assertEquals(true, methodOutcome.getCreated()); waitForQueueToDrain(); waitForSize(2, ourUpdatedObservations); @@ -1004,7 +1011,7 @@ public class RestHookTestR4Test extends BaseSubscriptionsR4Test { { Observation observation = new Observation(); observation.addExtension().setUrl("Observation#accessType").setValue(new Coding().setCode("XXX")); - MethodOutcome methodOutcome = ourClient.create().resource(observation).execute(); + MethodOutcome methodOutcome = myClient.create().resource(observation).execute(); assertEquals(true, methodOutcome.getCreated()); waitForQueueToDrain(); waitForSize(2, ourUpdatedObservations); @@ -1019,7 +1026,7 @@ public class RestHookTestR4Test extends BaseSubscriptionsR4Test { Subscription subscription = newSubscription("Observation?", "application/json"); subscription.addExtension(HapiExtensions.EXT_SUBSCRIPTION_PAYLOAD_SEARCH_CRITERIA, new StringType("Observation?_id=${matched_resource_id}&_include=*")); ourLog.info(myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(subscription)); - MethodOutcome methodOutcome = ourClient.create().resource(subscription).execute(); + MethodOutcome methodOutcome = myClient.create().resource(subscription).execute(); mySubscriptionIds.add(methodOutcome.getId()); waitForActivatedSubscriptionCount(1); } @@ -1027,12 +1034,12 @@ public class RestHookTestR4Test extends BaseSubscriptionsR4Test { { Patient patient = new Patient(); patient.setActive(true); - IIdType patientId = ourClient.create().resource(patient).execute().getId(); + IIdType patientId = myClient.create().resource(patient).execute().getId(); Observation observation = new Observation(); observation.addExtension().setUrl("Observation#accessType").setValue(new Coding().setCode("Catheter")); observation.getSubject().setReferenceElement(patientId.toUnqualifiedVersionless()); - MethodOutcome methodOutcome = ourClient.create().resource(observation).execute(); + MethodOutcome methodOutcome = myClient.create().resource(observation).execute(); assertEquals(true, methodOutcome.getCreated()); waitForQueueToDrain(); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/resthook/RestHookTestR5Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/resthook/RestHookTestR5Test.java index 018abd6a0fc..f1870a43c67 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/resthook/RestHookTestR5Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/resthook/RestHookTestR5Test.java @@ -9,9 +9,8 @@ import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; import ca.uhn.fhir.util.HapiExtensions; import org.hl7.fhir.instance.model.api.IBaseBundle; import org.hl7.fhir.r5.model.*; -import org.junit.After; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -20,8 +19,16 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.hasItem; +import static org.hamcrest.Matchers.matchesPattern; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; /** * Test the rest-hook subscriptions @@ -32,9 +39,9 @@ public class RestHookTestR5Test extends BaseSubscriptionsR5Test { @Autowired StoppableSubscriptionDeliveringRestHookSubscriber myStoppableSubscriptionDeliveringRestHookSubscriber; - @After + @AfterEach public void cleanupStoppableSubscriptionDeliveringRestHookSubscriber() { - ourLog.info("@After"); + ourLog.info("@AfterEach"); myStoppableSubscriptionDeliveringRestHookSubscriber.setCountDownLatch(null); myStoppableSubscriptionDeliveringRestHookSubscriber.unPause(); } @@ -262,7 +269,7 @@ public class RestHookTestR5Test extends BaseSubscriptionsR5Test { // Send an update with no changes obs.setId(obs.getIdElement().toUnqualifiedVersionless()); - ourClient.update().resource(obs).execute(); + myClient.update().resource(obs).execute(); // Should be no further deliveries Thread.sleep(1000); @@ -304,7 +311,7 @@ public class RestHookTestR5Test extends BaseSubscriptionsR5Test { int modCount = myCountingInterceptor.getSentCount("Subscription"); ourLog.info("** About to send another..."); - ourClient.update().resource(subscription1).execute(); + myClient.update().resource(subscription1).execute(); waitForSize(modCount + 2, () -> myCountingInterceptor.getSentCount("Subscription"), () -> myCountingInterceptor.toString()); ourLog.info("** About to send observation"); @@ -342,7 +349,7 @@ public class RestHookTestR5Test extends BaseSubscriptionsR5Test { assertNull(observation.getNoteFirstRep().getText()); observation.getNoteFirstRep().setText("changed"); - MethodOutcome methodOutcome = ourClient.update().resource(observation).execute(); + MethodOutcome methodOutcome = myClient.update().resource(observation).execute(); assertEquals("2", methodOutcome.getId().getVersionIdPart()); assertEquals("changed", observation.getNoteFirstRep().getText()); @@ -376,7 +383,7 @@ public class RestHookTestR5Test extends BaseSubscriptionsR5Test { Subscription subscription = newSubscription(criteria1, payload); subscription .addExtension(HapiExtensions.EXT_SUBSCRIPTION_RESTHOOK_DELIVER_LATEST_VERSION, new BooleanType("true")); - ourClient.create().resource(subscription).execute(); + myClient.create().resource(subscription).execute(); waitForActivatedSubscriptionCount(1); @@ -390,7 +397,7 @@ public class RestHookTestR5Test extends BaseSubscriptionsR5Test { assertNull(observation.getNoteFirstRep().getText()); observation.getNoteFirstRep().setText("changed"); - MethodOutcome methodOutcome = ourClient.update().resource(observation).execute(); + MethodOutcome methodOutcome = myClient.update().resource(observation).execute(); assertEquals("2", methodOutcome.getId().getVersionIdPart()); assertEquals("changed", observation.getNoteFirstRep().getText()); @@ -434,13 +441,13 @@ public class RestHookTestR5Test extends BaseSubscriptionsR5Test { assertEquals("1", ourUpdatedObservations.get(0).getIdElement().getVersionIdPart()); - Subscription subscriptionTemp = ourClient.read(Subscription.class, subscription2.getId()); - Assert.assertNotNull(subscriptionTemp); + Subscription subscriptionTemp = myClient.read(Subscription.class, subscription2.getId()); + assertNotNull(subscriptionTemp); SubscriptionTopic topic = (SubscriptionTopic) subscriptionTemp.getTopic().getResource(); topic.getResourceTrigger().getQueryCriteria().setCurrent(criteria1); - ourClient.update().resource(subscriptionTemp).withId(subscriptionTemp.getIdElement()).execute(); + myClient.update().resource(subscriptionTemp).withId(subscriptionTemp.getIdElement()).execute(); waitForQueueToDrain(); Observation observation2 = sendObservation(code, "SNOMED-CT"); @@ -450,7 +457,7 @@ public class RestHookTestR5Test extends BaseSubscriptionsR5Test { waitForSize(0, ourCreatedObservations); waitForSize(3, ourUpdatedObservations); - ourClient.delete().resourceById(new IdType("Subscription/" + subscription2.getId())).execute(); + myClient.delete().resourceById(new IdType("Subscription/" + subscription2.getId())).execute(); waitForQueueToDrain(); Observation observationTemp3 = sendObservation(code, "SNOMED-CT"); @@ -460,27 +467,27 @@ public class RestHookTestR5Test extends BaseSubscriptionsR5Test { waitForSize(0, ourCreatedObservations); waitForSize(4, ourUpdatedObservations); - Observation observation3 = ourClient.read(Observation.class, observationTemp3.getId()); + Observation observation3 = myClient.read(Observation.class, observationTemp3.getId()); CodeableConcept codeableConcept = new CodeableConcept(); observation3.setCode(codeableConcept); Coding coding = codeableConcept.addCoding(); coding.setCode(code + "111"); coding.setSystem("SNOMED-CT"); - ourClient.update().resource(observation3).withId(observation3.getIdElement()).execute(); + myClient.update().resource(observation3).withId(observation3.getIdElement()).execute(); // Should see no subscription notification waitForQueueToDrain(); waitForSize(0, ourCreatedObservations); waitForSize(4, ourUpdatedObservations); - Observation observation3a = ourClient.read(Observation.class, observationTemp3.getId()); + Observation observation3a = myClient.read(Observation.class, observationTemp3.getId()); CodeableConcept codeableConcept1 = new CodeableConcept(); observation3a.setCode(codeableConcept1); Coding coding1 = codeableConcept1.addCoding(); coding1.setCode(code); coding1.setSystem("SNOMED-CT"); - ourClient.update().resource(observation3a).withId(observation3a.getIdElement()).execute(); + myClient.update().resource(observation3a).withId(observation3a.getIdElement()).execute(); // Should see only one subscription notification waitForQueueToDrain(); @@ -516,13 +523,13 @@ public class RestHookTestR5Test extends BaseSubscriptionsR5Test { assertEquals("1", ourUpdatedObservations.get(0).getIdElement().getVersionIdPart()); - Subscription subscriptionTemp = ourClient.read(Subscription.class, subscription2.getId()); - Assert.assertNotNull(subscriptionTemp); + Subscription subscriptionTemp = myClient.read(Subscription.class, subscription2.getId()); + assertNotNull(subscriptionTemp); SubscriptionTopic topic = (SubscriptionTopic) subscriptionTemp.getTopic().getResource(); topic.getResourceTrigger().getQueryCriteria().setCurrent(criteria1); - ourClient.update().resource(subscriptionTemp).withId(subscriptionTemp.getIdElement()).execute(); + myClient.update().resource(subscriptionTemp).withId(subscriptionTemp.getIdElement()).execute(); waitForQueueToDrain(); Observation observation2 = sendObservation(code, "SNOMED-CT"); @@ -532,7 +539,7 @@ public class RestHookTestR5Test extends BaseSubscriptionsR5Test { waitForSize(0, ourCreatedObservations); waitForSize(3, ourUpdatedObservations); - ourClient.delete().resourceById(new IdType("Subscription/" + subscription2.getId())).execute(); + myClient.delete().resourceById(new IdType("Subscription/" + subscription2.getId())).execute(); waitForQueueToDrain(); Observation observationTemp3 = sendObservation(code, "SNOMED-CT"); @@ -542,27 +549,27 @@ public class RestHookTestR5Test extends BaseSubscriptionsR5Test { waitForSize(0, ourCreatedObservations); waitForSize(4, ourUpdatedObservations); - Observation observation3 = ourClient.read(Observation.class, observationTemp3.getId()); + Observation observation3 = myClient.read(Observation.class, observationTemp3.getId()); CodeableConcept codeableConcept = new CodeableConcept(); observation3.setCode(codeableConcept); Coding coding = codeableConcept.addCoding(); coding.setCode(code + "111"); coding.setSystem("SNOMED-CT"); - ourClient.update().resource(observation3).withId(observation3.getIdElement()).execute(); + myClient.update().resource(observation3).withId(observation3.getIdElement()).execute(); // Should see no subscription notification waitForQueueToDrain(); waitForSize(0, ourCreatedObservations); waitForSize(4, ourUpdatedObservations); - Observation observation3a = ourClient.read(Observation.class, observationTemp3.getId()); + Observation observation3a = myClient.read(Observation.class, observationTemp3.getId()); CodeableConcept codeableConcept1 = new CodeableConcept(); observation3a.setCode(codeableConcept1); Coding coding1 = codeableConcept1.addCoding(); coding1.setCode(code); coding1.setSystem("SNOMED-CT"); - ourClient.update().resource(observation3a).withId(observation3a.getIdElement()).execute(); + myClient.update().resource(observation3a).withId(observation3a.getIdElement()).execute(); // Should see only one subscription notification waitForQueueToDrain(); @@ -595,11 +602,11 @@ public class RestHookTestR5Test extends BaseSubscriptionsR5Test { waitForSize(1, ourContentTypes); assertEquals(Constants.CT_FHIR_XML_NEW, ourContentTypes.get(0)); - Subscription subscriptionTemp = ourClient.read(Subscription.class, subscription2.getId()); - Assert.assertNotNull(subscriptionTemp); + Subscription subscriptionTemp = myClient.read(Subscription.class, subscription2.getId()); + assertNotNull(subscriptionTemp); SubscriptionTopic topic = (SubscriptionTopic) subscriptionTemp.getTopic().getResource(); topic.getResourceTrigger().getQueryCriteria().setCurrent(criteria1); - ourClient.update().resource(subscriptionTemp).withId(subscriptionTemp.getIdElement()).execute(); + myClient.update().resource(subscriptionTemp).withId(subscriptionTemp.getIdElement()).execute(); waitForQueueToDrain(); Observation observation2 = sendObservation(code, "SNOMED-CT"); @@ -609,7 +616,7 @@ public class RestHookTestR5Test extends BaseSubscriptionsR5Test { waitForSize(0, ourCreatedObservations); waitForSize(3, ourUpdatedObservations); - ourClient.delete().resourceById(new IdType("Subscription/" + subscription2.getId())).execute(); + myClient.delete().resourceById(new IdType("Subscription/" + subscription2.getId())).execute(); Observation observationTemp3 = sendObservation(code, "SNOMED-CT"); @@ -618,27 +625,27 @@ public class RestHookTestR5Test extends BaseSubscriptionsR5Test { waitForSize(0, ourCreatedObservations); waitForSize(4, ourUpdatedObservations); - Observation observation3 = ourClient.read(Observation.class, observationTemp3.getId()); + Observation observation3 = myClient.read(Observation.class, observationTemp3.getId()); CodeableConcept codeableConcept = new CodeableConcept(); observation3.setCode(codeableConcept); Coding coding = codeableConcept.addCoding(); coding.setCode(code + "111"); coding.setSystem("SNOMED-CT"); - ourClient.update().resource(observation3).withId(observation3.getIdElement()).execute(); + myClient.update().resource(observation3).withId(observation3.getIdElement()).execute(); // Should see no subscription notification waitForQueueToDrain(); waitForSize(0, ourCreatedObservations); waitForSize(4, ourUpdatedObservations); - Observation observation3a = ourClient.read(Observation.class, observationTemp3.getId()); + Observation observation3a = myClient.read(Observation.class, observationTemp3.getId()); CodeableConcept codeableConcept1 = new CodeableConcept(); observation3a.setCode(codeableConcept1); Coding coding1 = codeableConcept1.addCoding(); coding1.setCode(code); coding1.setSystem("SNOMED-CT"); - ourClient.update().resource(observation3a).withId(observation3a.getIdElement()).execute(); + myClient.update().resource(observation3a).withId(observation3a.getIdElement()).execute(); // Should see only one subscription notification waitForQueueToDrain(); @@ -690,7 +697,7 @@ public class RestHookTestR5Test extends BaseSubscriptionsR5Test { .getRequest() .setUrl("Patient?identifier=foo|bar2") .setMethod(Bundle.HTTPVerb.PUT); - ourClient.transaction().withBundle(requestBundle).execute(); + myClient.transaction().withBundle(requestBundle).execute(); // Should see 1 subscription notification waitForSize(0, ourCreatedObservations); @@ -721,15 +728,15 @@ public class RestHookTestR5Test extends BaseSubscriptionsR5Test { Thread.sleep(1000); assertEquals(0, ourUpdatedObservations.size()); - Subscription subscriptionTemp = ourClient.read().resource(Subscription.class).withId(subscription2.getId()).execute(); - Assert.assertNotNull(subscriptionTemp); + Subscription subscriptionTemp = myClient.read().resource(Subscription.class).withId(subscription2.getId()).execute(); + assertNotNull(subscriptionTemp); String criteriaGood = "Observation?code=SNOMED-CT|" + code + "&_format=xml"; SubscriptionTopic topic = (SubscriptionTopic) subscriptionTemp.getTopic().getResource(); topic.getResourceTrigger().getQueryCriteria().setCurrent(criteriaGood); ourLog.info("** About to update subscription"); - ourClient.update().resource(subscriptionTemp).withId(subscriptionTemp.getIdElement()).execute(); + myClient.update().resource(subscriptionTemp).withId(subscriptionTemp.getIdElement()).execute(); waitForQueueToDrain(); ourLog.info("** About to send Observation 2"); @@ -740,7 +747,7 @@ public class RestHookTestR5Test extends BaseSubscriptionsR5Test { waitForSize(0, ourCreatedObservations); waitForSize(1, ourUpdatedObservations); - ourClient.delete().resourceById(new IdType("Subscription/" + subscription2.getId())).execute(); + myClient.delete().resourceById(new IdType("Subscription/" + subscription2.getId())).execute(); Observation observationTemp3 = sendObservation(code, "SNOMED-CT"); @@ -798,7 +805,7 @@ public class RestHookTestR5Test extends BaseSubscriptionsR5Test { subscription.addHeader("X-Foo: FOO"); subscription.addHeader("X-Bar: BAR"); subscription.setStatus(Enumerations.SubscriptionState.REQUESTED); - ourClient.update().resource(subscription).execute(); + myClient.update().resource(subscription).execute(); waitForQueueToDrain(); sendObservation(code, "SNOMED-CT"); @@ -831,7 +838,7 @@ public class RestHookTestR5Test extends BaseSubscriptionsR5Test { // Disable subscription.setStatus(Enumerations.SubscriptionState.OFF); - ourClient.update().resource(subscription).execute(); + myClient.update().resource(subscription).execute(); waitForQueueToDrain(); // Send another object @@ -844,28 +851,34 @@ public class RestHookTestR5Test extends BaseSubscriptionsR5Test { } - @Test(expected = UnprocessableEntityException.class) + @Test public void testInvalidProvenanceParam() { + assertThrows(UnprocessableEntityException.class, () -> { String payload = "application/fhir+json"; String criteriabad = "Provenance?foo=http://hl7.org/fhir/v3/DocumentCompletion%7CAU"; Subscription subscription = newSubscription(criteriabad, payload); - ourClient.create().resource(subscription).execute(); + myClient.create().resource(subscription).execute(); + }); } - @Test(expected = UnprocessableEntityException.class) + @Test public void testInvalidProcedureRequestParam() { + assertThrows(UnprocessableEntityException.class, () -> { String payload = "application/fhir+json"; String criteriabad = "ProcedureRequest?intent=instance-order&category=Laboratory"; Subscription subscription = newSubscription(criteriabad, payload); - ourClient.create().resource(subscription).execute(); + myClient.create().resource(subscription).execute(); + }); } - @Test(expected = UnprocessableEntityException.class) + @Test public void testInvalidBodySiteParam() { + assertThrows(UnprocessableEntityException.class, () -> { String payload = "application/fhir+json"; String criteriabad = "BodySite?accessType=Catheter"; Subscription subscription = newSubscription(criteriabad, payload); - ourClient.create().resource(subscription).execute(); + myClient.create().resource(subscription).execute(); + }); } @Test @@ -874,12 +887,12 @@ public class RestHookTestR5Test extends BaseSubscriptionsR5Test { String payload = "application/fhir+json"; String criteriaGood = "Patient?gender=male"; Subscription subscription = newSubscription(criteriaGood, payload); - ourClient.create().resource(subscription).execute(); + myClient.create().resource(subscription).execute(); assertEquals(1, subscriptionCount()); } private int subscriptionCount() { - IBaseBundle found = ourClient.search().forResource(Subscription.class).cacheControl(new CacheControlDirective().setNoCache(true)).execute(); + IBaseBundle found = myClient.search().forResource(Subscription.class).cacheControl(new CacheControlDirective().setNoCache(true)).execute(); return toUnqualifiedVersionlessIdValues(found).size(); } @@ -889,7 +902,7 @@ public class RestHookTestR5Test extends BaseSubscriptionsR5Test { subscription.setStatus(null); try { - ourClient.create().resource(subscription).execute(); + myClient.create().resource(subscription).execute(); fail(); } catch (UnprocessableEntityException e) { assertThat(e.getMessage(), containsString("Can not process submitted Subscription - Subscription.status must be populated on this server")); @@ -904,7 +917,7 @@ public class RestHookTestR5Test extends BaseSubscriptionsR5Test { String criteriaBad = "BodySite?accessType=Catheter"; Subscription subscription = newSubscription(criteriaBad, payload); try { - ourClient.create().resource(subscription).execute(); + myClient.create().resource(subscription).execute(); } catch (UnprocessableEntityException e) { ourLog.info("Expected exception", e); } @@ -930,7 +943,7 @@ public class RestHookTestR5Test extends BaseSubscriptionsR5Test { { Observation bodySite = new Observation(); bodySite.addExtension().setUrl("Observation#accessType").setValue(new Coding().setCode("Catheter")); - MethodOutcome methodOutcome = ourClient.create().resource(bodySite).execute(); + MethodOutcome methodOutcome = myClient.create().resource(bodySite).execute(); assertEquals(true, methodOutcome.getCreated()); waitForQueueToDrain(); waitForSize(1, ourUpdatedObservations); @@ -938,14 +951,14 @@ public class RestHookTestR5Test extends BaseSubscriptionsR5Test { { Observation observation = new Observation(); observation.addExtension().setUrl("Observation#accessType").setValue(new Coding().setCode("PD Catheter")); - MethodOutcome methodOutcome = ourClient.create().resource(observation).execute(); + MethodOutcome methodOutcome = myClient.create().resource(observation).execute(); assertEquals(true, methodOutcome.getCreated()); waitForQueueToDrain(); waitForSize(2, ourUpdatedObservations); } { Observation observation = new Observation(); - MethodOutcome methodOutcome = ourClient.create().resource(observation).execute(); + MethodOutcome methodOutcome = myClient.create().resource(observation).execute(); assertEquals(true, methodOutcome.getCreated()); waitForQueueToDrain(); waitForSize(2, ourUpdatedObservations); @@ -953,7 +966,7 @@ public class RestHookTestR5Test extends BaseSubscriptionsR5Test { { Observation observation = new Observation(); observation.addExtension().setUrl("Observation#accessType").setValue(new Coding().setCode("XXX")); - MethodOutcome methodOutcome = ourClient.create().resource(observation).execute(); + MethodOutcome methodOutcome = myClient.create().resource(observation).execute(); assertEquals(true, methodOutcome.getCreated()); waitForQueueToDrain(); waitForSize(2, ourUpdatedObservations); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/resthook/RestHookTestWithInterceptorRegisteredToDaoConfigDstu2Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/resthook/RestHookTestWithInterceptorRegisteredToDaoConfigDstu2Test.java index 8d69ee5d3d7..ac3759053f1 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/resthook/RestHookTestWithInterceptorRegisteredToDaoConfigDstu2Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/resthook/RestHookTestWithInterceptorRegisteredToDaoConfigDstu2Test.java @@ -1,6 +1,7 @@ package ca.uhn.fhir.jpa.subscription.resthook; import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.context.FhirVersionEnum; import ca.uhn.fhir.jpa.api.config.DaoConfig; import ca.uhn.fhir.jpa.provider.BaseResourceProviderDstu2Test; import ca.uhn.fhir.jpa.subscription.SubscriptionTestUtil; @@ -28,19 +29,20 @@ import org.eclipse.jetty.server.Server; import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletHolder; import org.hl7.fhir.instance.model.api.IBaseResource; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import java.util.Collections; import java.util.List; import java.util.stream.Collectors; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.fail; /** * Test the rest-hook subscriptions @@ -59,7 +61,7 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigDstu2Test extends B @Autowired private SubscriptionTestUtil mySubscriptionTestUtil; - @After + @AfterEach public void afterUnregisterRestHookListener() { ourLog.info("** AFTER **"); myDaoConfig.setAllowMultipleDelete(true); @@ -71,12 +73,12 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigDstu2Test extends B mySubscriptionTestUtil.unregisterSubscriptionInterceptor(); } - @Before + @BeforeEach public void beforeRegisterRestHookListener() { mySubscriptionTestUtil.registerRestHookInterceptor(); } - @Before + @BeforeEach public void beforeReset() { ourCreatedObservations.clear(); ourUpdatedObservations.clear(); @@ -163,7 +165,7 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigDstu2Test extends B waitForSize(1, ourUpdatedObservations); Subscription subscriptionTemp = ourClient.read(Subscription.class, subscription2.getId()); - Assert.assertNotNull(subscriptionTemp); + assertNotNull(subscriptionTemp); subscriptionTemp.setCriteria(criteria1); ourClient.update().resource(subscriptionTemp).withId(subscriptionTemp.getIdElement()).execute(); @@ -212,9 +214,9 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigDstu2Test extends B waitForSize(0, ourCreatedObservations); waitForSize(5, ourUpdatedObservations); - Assert.assertFalse(subscription1.getId().equals(subscription2.getId())); - Assert.assertFalse(observation1.getId().isEmpty()); - Assert.assertFalse(observation2.getId().isEmpty()); + assertFalse(subscription1.getId().equals(subscription2.getId())); + assertFalse(observation1.getId().isEmpty()); + assertFalse(observation2.getId().isEmpty()); } @Test @@ -248,7 +250,7 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigDstu2Test extends B waitForSize(1, ourUpdatedObservations); Subscription subscriptionTemp = ourClient.read(Subscription.class, subscription2.getId()); - Assert.assertNotNull(subscriptionTemp); + assertNotNull(subscriptionTemp); subscriptionTemp.setCriteria(criteria1); ourClient.update().resource(subscriptionTemp).withId(subscriptionTemp.getIdElement()).execute(); @@ -297,9 +299,9 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigDstu2Test extends B waitForSize(0, ourCreatedObservations); waitForSize(5, ourUpdatedObservations); - Assert.assertFalse(subscription1.getId().equals(subscription2.getId())); - Assert.assertFalse(observation1.getId().isEmpty()); - Assert.assertFalse(observation2.getId().isEmpty()); + assertFalse(subscription1.getId().equals(subscription2.getId())); + assertFalse(observation1.getId().isEmpty()); + assertFalse(observation2.getId().isEmpty()); } public static class ObservationListener implements IResourceProvider { @@ -325,9 +327,9 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigDstu2Test extends B } - @BeforeClass + @BeforeAll public static void startListenerServer() throws Exception { - ourListenerRestServer = new RestfulServer(FhirContext.forDstu2()); + ourListenerRestServer = new RestfulServer(FhirContext.forCached(FhirVersionEnum.DSTU2)); ObservationListener obsListener = new ObservationListener(); ourListenerRestServer.setResourceProviders(obsListener); @@ -347,7 +349,7 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigDstu2Test extends B ourListenerServerBase = "http://localhost:" + ourListenerPort + "/fhir/context"; } - @AfterClass + @AfterAll public static void stopListenerServer() throws Exception { JettyUtil.closeServer(ourListenerServer); } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/resthook/RestHookTestWithInterceptorRegisteredToDaoConfigDstu3Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/resthook/RestHookTestWithInterceptorRegisteredToDaoConfigDstu3Test.java index 04110bd6db6..c9bc7b33b41 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/resthook/RestHookTestWithInterceptorRegisteredToDaoConfigDstu3Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/resthook/RestHookTestWithInterceptorRegisteredToDaoConfigDstu3Test.java @@ -2,6 +2,7 @@ package ca.uhn.fhir.jpa.subscription.resthook; import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.context.FhirVersionEnum; import ca.uhn.fhir.jpa.api.config.DaoConfig; import ca.uhn.fhir.jpa.provider.dstu3.BaseResourceProviderDstu3Test; import ca.uhn.fhir.jpa.subscription.SubscriptionTestUtil; @@ -23,17 +24,19 @@ import org.hl7.fhir.dstu3.model.IdType; import org.hl7.fhir.dstu3.model.Observation; import org.hl7.fhir.dstu3.model.Subscription; import org.hl7.fhir.instance.model.api.IBaseResource; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import java.util.Collections; import java.util.List; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; + /** * Test the rest-hook subscriptions */ @@ -55,7 +58,7 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigDstu3Test extends B return false; } - @After + @AfterEach public void afterUnregisterRestHookListener() { myDaoConfig.setAllowMultipleDelete(true); ourLog.info("Deleting all subscriptions"); @@ -66,12 +69,12 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigDstu3Test extends B mySubscriptionTestUtil.unregisterSubscriptionInterceptor(); } - @Before + @BeforeEach public void beforeRegisterRestHookListener() { mySubscriptionTestUtil.registerRestHookInterceptor(); } - @Before + @BeforeEach public void beforeReset() { ourCreatedObservations.clear(); ourUpdatedObservations.clear(); @@ -137,7 +140,7 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigDstu3Test extends B waitForSize(1, ourUpdatedObservations); Subscription subscriptionTemp = ourClient.read(Subscription.class, subscription2.getId()); - Assert.assertNotNull(subscriptionTemp); + assertNotNull(subscriptionTemp); subscriptionTemp.setCriteria(criteria1); ourClient.update().resource(subscriptionTemp).withId(subscriptionTemp.getIdElement()).execute(); @@ -183,9 +186,9 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigDstu3Test extends B waitForSize(0, ourCreatedObservations); waitForSize(5, ourUpdatedObservations); - Assert.assertFalse(subscription1.getId().equals(subscription2.getId())); - Assert.assertFalse(observation1.getId().isEmpty()); - Assert.assertFalse(observation2.getId().isEmpty()); + assertFalse(subscription1.getId().equals(subscription2.getId())); + assertFalse(observation1.getId().isEmpty()); + assertFalse(observation2.getId().isEmpty()); } @Test @@ -207,7 +210,7 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigDstu3Test extends B waitForSize(1, ourUpdatedObservations); Subscription subscriptionTemp = ourClient.read(Subscription.class, subscription2.getId()); - Assert.assertNotNull(subscriptionTemp); + assertNotNull(subscriptionTemp); subscriptionTemp.setCriteria(criteria1); ourClient.update().resource(subscriptionTemp).withId(subscriptionTemp.getIdElement()).execute(); @@ -256,14 +259,14 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigDstu3Test extends B waitForSize(0, ourCreatedObservations); waitForSize(5, ourUpdatedObservations); - Assert.assertFalse(subscription1.getId().equals(subscription2.getId())); - Assert.assertFalse(observation1.getId().isEmpty()); - Assert.assertFalse(observation2.getId().isEmpty()); + assertFalse(subscription1.getId().equals(subscription2.getId())); + assertFalse(observation1.getId().isEmpty()); + assertFalse(observation2.getId().isEmpty()); } - @BeforeClass + @BeforeAll public static void startListenerServer() throws Exception { - ourListenerRestServer = new RestfulServer(FhirContext.forDstu3()); + ourListenerRestServer = new RestfulServer(FhirContext.forCached(FhirVersionEnum.DSTU3)); ObservationListener obsListener = new ObservationListener(); ourListenerRestServer.setResourceProviders(obsListener); @@ -283,7 +286,7 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigDstu3Test extends B ourListenerServerBase = "http://localhost:" + ourListenerPort + "/fhir/context"; } - @AfterClass + @AfterAll public static void stopListenerServer() throws Exception { JettyUtil.closeServer(ourListenerServer); } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/resthook/RestHookTestWithInterceptorRegisteredToDaoConfigR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/resthook/RestHookTestWithInterceptorRegisteredToDaoConfigR4Test.java index dbd1c5272ac..f1e3593c89c 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/resthook/RestHookTestWithInterceptorRegisteredToDaoConfigR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/resthook/RestHookTestWithInterceptorRegisteredToDaoConfigR4Test.java @@ -2,6 +2,7 @@ package ca.uhn.fhir.jpa.subscription.resthook; import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.context.FhirVersionEnum; import ca.uhn.fhir.jpa.api.config.DaoConfig; import ca.uhn.fhir.jpa.provider.r4.BaseResourceProviderR4Test; import ca.uhn.fhir.jpa.subscription.SubscriptionTestUtil; @@ -20,7 +21,10 @@ import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletHolder; import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.r4.model.*; -import org.junit.*; +import org.junit.jupiter.api.*; import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; + import org.springframework.beans.factory.annotation.Autowired; import java.util.Collections; @@ -47,23 +51,23 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigR4Test extends Base return false; } - @After + @AfterEach public void afterUnregisterRestHookListener() { myDaoConfig.setAllowMultipleDelete(true); ourLog.info("Deleting all subscriptions"); - ourClient.delete().resourceConditionalByUrl("Subscription?status=active").execute(); + myClient.delete().resourceConditionalByUrl("Subscription?status=active").execute(); ourLog.info("Done deleting all subscriptions"); myDaoConfig.setAllowMultipleDelete(new DaoConfig().isAllowMultipleDelete()); mySubscriptionTestUtil.unregisterSubscriptionInterceptor(); } - @Before + @BeforeEach public void beforeRegisterRestHookListener() { mySubscriptionTestUtil.registerRestHookInterceptor(); } - @Before + @BeforeEach public void beforeReset() { ourCreatedObservations.clear(); ourUpdatedObservations.clear(); @@ -81,7 +85,7 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigR4Test extends Base channel.setEndpoint(endpoint); subscription.setChannel(channel); - MethodOutcome methodOutcome = ourClient.create().resource(subscription).execute(); + MethodOutcome methodOutcome = myClient.create().resource(subscription).execute(); subscription.setId(methodOutcome.getId().getIdPart()); waitForQueueToDrain(); @@ -106,7 +110,7 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigR4Test extends Base observation.setStatus(Observation.ObservationStatus.FINAL); - MethodOutcome methodOutcome = ourClient.create().resource(observation).execute(); + MethodOutcome methodOutcome = myClient.create().resource(observation).execute(); String observationId = methodOutcome.getId().getIdPart(); observation.setId(observationId); @@ -134,11 +138,11 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigR4Test extends Base waitForSize(0, ourCreatedObservations); waitForSize(1, ourUpdatedObservations); - Subscription subscriptionTemp = ourClient.read(Subscription.class, subscription2.getId()); - Assert.assertNotNull(subscriptionTemp); + Subscription subscriptionTemp = myClient.read(Subscription.class, subscription2.getId()); + assertNotNull(subscriptionTemp); subscriptionTemp.setCriteria(criteria1); - ourClient.update().resource(subscriptionTemp).withId(subscriptionTemp.getIdElement()).execute(); + myClient.update().resource(subscriptionTemp).withId(subscriptionTemp.getIdElement()).execute(); Observation observation2 = sendObservation(code, "SNOMED-CT"); @@ -148,7 +152,7 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigR4Test extends Base waitForSize(0, ourCreatedObservations); waitForSize(3, ourUpdatedObservations); - ourClient.delete().resourceById(new IdDt(ResourceTypeEnum.SUBSCRIPTION.getCode(), subscription2.getId())).execute(); + myClient.delete().resourceById(new IdDt(ResourceTypeEnum.SUBSCRIPTION.getCode(), subscription2.getId())).execute(); Observation observationTemp3 = sendObservation(code, "SNOMED-CT"); @@ -157,36 +161,36 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigR4Test extends Base waitForSize(0, ourCreatedObservations); waitForSize(4, ourUpdatedObservations); - Observation observation3 = ourClient.read(Observation.class, observationTemp3.getId()); + Observation observation3 = myClient.read(Observation.class, observationTemp3.getId()); CodeableConcept codeableConcept = new CodeableConcept(); observation3.setCode(codeableConcept); Coding coding = codeableConcept.addCoding(); coding.setCode(code + "111"); coding.setSystem("SNOMED-CT"); - ourClient.update().resource(observation3).withId(observation3.getIdElement()).execute(); + myClient.update().resource(observation3).withId(observation3.getIdElement()).execute(); // Should see no subscription notification Thread.sleep(500); waitForSize(0, ourCreatedObservations); waitForSize(4, ourUpdatedObservations); - Observation observation3a = ourClient.read(Observation.class, observationTemp3.getId()); + Observation observation3a = myClient.read(Observation.class, observationTemp3.getId()); CodeableConcept codeableConcept1 = new CodeableConcept(); observation3a.setCode(codeableConcept1); Coding coding1 = codeableConcept1.addCoding(); coding1.setCode(code); coding1.setSystem("SNOMED-CT"); - ourClient.update().resource(observation3a).withId(observation3a.getIdElement()).execute(); + myClient.update().resource(observation3a).withId(observation3a.getIdElement()).execute(); // Should see only one subscription notification Thread.sleep(500); waitForSize(0, ourCreatedObservations); waitForSize(5, ourUpdatedObservations); - Assert.assertFalse(subscription1.getId().equals(subscription2.getId())); - Assert.assertFalse(observation1.getId().isEmpty()); - Assert.assertFalse(observation2.getId().isEmpty()); + assertFalse(subscription1.getId().equals(subscription2.getId())); + assertFalse(observation1.getId().isEmpty()); + assertFalse(observation2.getId().isEmpty()); } @Test @@ -207,11 +211,11 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigR4Test extends Base waitForSize(0, ourCreatedObservations); waitForSize(1, ourUpdatedObservations); - Subscription subscriptionTemp = ourClient.read(Subscription.class, subscription2.getId()); - Assert.assertNotNull(subscriptionTemp); + Subscription subscriptionTemp = myClient.read(Subscription.class, subscription2.getId()); + assertNotNull(subscriptionTemp); subscriptionTemp.setCriteria(criteria1); - ourClient.update().resource(subscriptionTemp).withId(subscriptionTemp.getIdElement()).execute(); + myClient.update().resource(subscriptionTemp).withId(subscriptionTemp.getIdElement()).execute(); Observation observation2 = sendObservation(code, "SNOMED-CT"); @@ -221,7 +225,7 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigR4Test extends Base waitForSize(0, ourCreatedObservations); waitForSize(3, ourUpdatedObservations); - ourClient.delete().resourceById(new IdDt("Subscription", subscription2.getId())).execute(); + myClient.delete().resourceById(new IdDt("Subscription", subscription2.getId())).execute(); Observation observationTemp3 = sendObservation(code, "SNOMED-CT"); @@ -230,27 +234,27 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigR4Test extends Base waitForSize(0, ourCreatedObservations); waitForSize(4, ourUpdatedObservations); - Observation observation3 = ourClient.read(Observation.class, observationTemp3.getId()); + Observation observation3 = myClient.read(Observation.class, observationTemp3.getId()); CodeableConcept codeableConcept = new CodeableConcept(); observation3.setCode(codeableConcept); Coding coding = codeableConcept.addCoding(); coding.setCode(code + "111"); coding.setSystem("SNOMED-CT"); - ourClient.update().resource(observation3).withId(observation3.getIdElement()).execute(); + myClient.update().resource(observation3).withId(observation3.getIdElement()).execute(); // Should see no subscription notification waitForQueueToDrain(); waitForSize(0, ourCreatedObservations); waitForSize(4, ourUpdatedObservations); - Observation observation3a = ourClient.read(Observation.class, observationTemp3.getId()); + Observation observation3a = myClient.read(Observation.class, observationTemp3.getId()); CodeableConcept codeableConcept1 = new CodeableConcept(); observation3a.setCode(codeableConcept1); Coding coding1 = codeableConcept1.addCoding(); coding1.setCode(code); coding1.setSystem("SNOMED-CT"); - ourClient.update().resource(observation3a).withId(observation3a.getIdElement()).execute(); + myClient.update().resource(observation3a).withId(observation3a.getIdElement()).execute(); // Should see only one subscription notification waitForQueueToDrain(); @@ -259,14 +263,14 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigR4Test extends Base ourLog.info("Have observations: {}", toUnqualifiedVersionlessIds(ourUpdatedObservations)); - Assert.assertFalse(subscription1.getId().equals(subscription2.getId())); - Assert.assertFalse(observation1.getId().isEmpty()); - Assert.assertFalse(observation2.getId().isEmpty()); + assertFalse(subscription1.getId().equals(subscription2.getId())); + assertFalse(observation1.getId().isEmpty()); + assertFalse(observation2.getId().isEmpty()); } - @BeforeClass + @BeforeAll public static void startListenerServer() throws Exception { - ourListenerRestServer = new RestfulServer(FhirContext.forR4()); + ourListenerRestServer = new RestfulServer(FhirContext.forCached(FhirVersionEnum.R4)); ObservationListener obsListener = new ObservationListener(); ourListenerRestServer.setResourceProviders(obsListener); @@ -286,7 +290,7 @@ public class RestHookTestWithInterceptorRegisteredToDaoConfigR4Test extends Base ourListenerServerBase = "http://localhost:" + ourListenerPort + "/fhir/context"; } - @AfterClass + @AfterAll public static void stopListenerServer() throws Exception { JettyUtil.closeServer(ourListenerServer); } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/resthook/RestHookWithEventDefinitionR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/resthook/RestHookWithEventDefinitionR4Test.java index 356705190f8..4b9822f18db 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/resthook/RestHookWithEventDefinitionR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/resthook/RestHookWithEventDefinitionR4Test.java @@ -8,10 +8,10 @@ import ca.uhn.fhir.rest.api.MethodOutcome; import com.google.common.collect.Lists; import org.hl7.fhir.instance.model.api.IIdType; import org.hl7.fhir.r4.model.*; -import org.junit.After; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.springframework.beans.factory.annotation.Autowired; @@ -36,6 +36,10 @@ import java.util.List; * 6. Execute the 'sendObservation' test * 7. Look in the 'attachWebSocket' terminal execution and wait for your ping with the subscription id */ +/** + * Ignored because this feature isn't implemented yet + */ +@Disabled public class RestHookWithEventDefinitionR4Test extends BaseResourceProviderR4Test { private static final Logger ourLog = org.slf4j.LoggerFactory.getLogger(RestHookWithEventDefinitionR4Test.class); @@ -51,22 +55,22 @@ public class RestHookWithEventDefinitionR4Test extends BaseResourceProviderR4Tes private SubscriptionTestUtil mySubscriptionTestUtil; @Override - @After + @AfterEach public void after() throws Exception { super.after(); } - @After + @AfterEach public void afterUnregisterRestHookListener() { for (IIdType next : mySubscriptionIds) { - ourClient.delete().resourceById(next).execute(); + myClient.delete().resourceById(next).execute(); } mySubscriptionIds.clear(); myDaoConfig.setAllowMultipleDelete(true); ourLog.info("Deleting all subscriptions"); - ourClient.delete().resourceConditionalByUrl("Subscription?status=active").execute(); - ourClient.delete().resourceConditionalByUrl("Observation?code:missing=false").execute(); + myClient.delete().resourceConditionalByUrl("Subscription?status=active").execute(); + myClient.delete().resourceConditionalByUrl("Observation?code:missing=false").execute(); ourLog.info("Done deleting all subscriptions"); myDaoConfig.setAllowMultipleDelete(new DaoConfig().isAllowMultipleDelete()); @@ -74,7 +78,7 @@ public class RestHookWithEventDefinitionR4Test extends BaseResourceProviderR4Tes } @Override - @Before + @BeforeEach public void before() throws Exception { super.before(); @@ -82,18 +86,14 @@ public class RestHookWithEventDefinitionR4Test extends BaseResourceProviderR4Tes } - /** - * Ignored because this feature isn't implemented yet - */ @Test - @Ignore public void testSubscriptionAddedTrigger() { /* * Create patient */ Patient patient = FhirR4Util.getPatient(); - MethodOutcome methodOutcome = ourClient.create().resource(patient).execute(); + MethodOutcome methodOutcome = myClient.create().resource(patient).execute(); myPatientId = methodOutcome.getId().getIdPart(); /* @@ -124,17 +124,17 @@ public class RestHookWithEventDefinitionR4Test extends BaseResourceProviderR4Tes channel.setPayload("application/json"); subscription.setChannel(channel); - methodOutcome = ourClient.create().resource(subscription).execute(); + methodOutcome = myClient.create().resource(subscription).execute(); mySubscriptionId = methodOutcome.getId().getIdPart(); } - @Before + @BeforeEach public void beforeRegisterRestHookListener() { mySubscriptionTestUtil.registerRestHookInterceptor(); } - @Before + @BeforeEach public void beforeReset() { ourCreatedObservations.clear(); ourUpdatedObservations.clear(); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/resthook/RestHookWithInterceptorR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/resthook/RestHookWithInterceptorR4Test.java index e1730036a88..faa775e0771 100755 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/resthook/RestHookWithInterceptorR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/resthook/RestHookWithInterceptorR4Test.java @@ -1,26 +1,26 @@ package ca.uhn.fhir.jpa.subscription.resthook; import ca.uhn.fhir.context.FhirContext; -import ca.uhn.fhir.jpa.config.StoppableSubscriptionDeliveringRestHookSubscriber; +import ca.uhn.fhir.context.FhirVersionEnum; import ca.uhn.fhir.interceptor.api.Hook; import ca.uhn.fhir.interceptor.api.IInterceptorService; import ca.uhn.fhir.interceptor.api.Interceptor; import ca.uhn.fhir.interceptor.api.Pointcut; +import ca.uhn.fhir.jpa.config.StoppableSubscriptionDeliveringRestHookSubscriber; import ca.uhn.fhir.jpa.subscription.BaseSubscriptionsR4Test; import ca.uhn.fhir.jpa.subscription.model.CanonicalSubscription; +import ca.uhn.fhir.jpa.subscription.model.ResourceDeliveryMessage; import ca.uhn.fhir.jpa.subscription.model.ResourceModifiedMessage; import ca.uhn.fhir.jpa.subscription.util.SubscriptionDebugLogInterceptor; -import ca.uhn.fhir.jpa.subscription.model.ResourceDeliveryMessage; import ca.uhn.fhir.rest.api.Constants; import ca.uhn.fhir.rest.api.MethodOutcome; import org.apache.commons.lang3.Validate; import org.hl7.fhir.r4.model.IdType; import org.hl7.fhir.r4.model.Observation; import org.hl7.fhir.r4.model.Subscription; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentMatchers; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -41,8 +41,9 @@ import java.util.stream.Collectors; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.hasItem; import static org.hamcrest.Matchers.matchesPattern; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.mock; @@ -60,19 +61,23 @@ public class RestHookWithInterceptorR4Test extends BaseSubscriptionsR4Test { private static boolean ourNextAfterRestHookDeliveryReturn; private static boolean ourHitAfterRestHookDelivery; private static boolean ourNextAddHeader; - private static FhirContext ourCtx = FhirContext.forR4(); + private static FhirContext ourCtx = FhirContext.forCached(FhirVersionEnum.R4); @Autowired StoppableSubscriptionDeliveringRestHookSubscriber myStoppableSubscriptionDeliveringRestHookSubscriber; + @Autowired + private IInterceptorService myInterceptorRegistry; + @Autowired + private MyTestInterceptor myTestInterceptor; - @After + @AfterEach public void cleanupStoppableSubscriptionDeliveringRestHookSubscriber() { myStoppableSubscriptionDeliveringRestHookSubscriber.setCountDownLatch(null); myStoppableSubscriptionDeliveringRestHookSubscriber.unPause(); } @Override - @Before + @BeforeEach public void before() throws Exception { super.before(); ourNextModifyResourceId = false; @@ -129,7 +134,6 @@ public class RestHookWithInterceptorR4Test extends BaseSubscriptionsR4Test { assertThat(ourHeaders, hasItem("X-Foo: Bar")); } - @Test public void testAttributesAreCopiedAlongPipeline() throws Exception { AttributeCarryingInterceptor interceptor = new AttributeCarryingInterceptor(); @@ -159,7 +163,6 @@ public class RestHookWithInterceptorR4Test extends BaseSubscriptionsR4Test { } } - @Test public void testBeforeRestHookDelivery_AbortDelivery() throws Exception { ourNextBeforeRestHookDeliveryReturn = false; @@ -175,7 +178,6 @@ public class RestHookWithInterceptorR4Test extends BaseSubscriptionsR4Test { assertEquals(0, ourUpdatedObservations.size()); } - @Test public void testDeliveryFailed() throws Exception { ourNextBeforeRestHookDeliveryReturn = false; @@ -185,7 +187,7 @@ public class RestHookWithInterceptorR4Test extends BaseSubscriptionsR4Test { Subscription subscription = newSubscription("Observation?status=final", "application/fhir+json"); subscription.getChannel().setEndpoint("http://localhost:" + ourListenerPort + "/this/url/does/not/exist"); // this better not succeed! - MethodOutcome methodOutcome = ourClient.create().resource(subscription).execute(); + MethodOutcome methodOutcome = myClient.create().resource(subscription).execute(); subscription.setId(methodOutcome.getId().getIdPart()); mySubscriptionIds.add(methodOutcome.getId()); @@ -201,11 +203,10 @@ public class RestHookWithInterceptorR4Test extends BaseSubscriptionsR4Test { latch.await(10, TimeUnit.SECONDS); } - protected Observation sendObservation() { Observation observation = new Observation(); observation.setStatus(Observation.ObservationStatus.FINAL); - MethodOutcome methodOutcome = ourClient.create().resource(observation).execute(); + MethodOutcome methodOutcome = myClient.create().resource(observation).execute(); observation.setId(methodOutcome.getId()); return observation; } @@ -248,11 +249,11 @@ public class RestHookWithInterceptorR4Test extends BaseSubscriptionsR4Test { assertEquals("1", ourUpdatedObservations.get(0).getIdElement().getVersionIdPart()); - Subscription subscriptionTemp = ourClient.read(Subscription.class, subscription2.getId()); - Assert.assertNotNull(subscriptionTemp); + Subscription subscriptionTemp = myClient.read(Subscription.class, subscription2.getId()); + assertNotNull(subscriptionTemp); subscriptionTemp.setCriteria(criteria1); - ourClient.update().resource(subscriptionTemp).withId(subscriptionTemp.getIdElement()).execute(); + myClient.update().resource(subscriptionTemp).withId(subscriptionTemp.getIdElement()).execute(); waitForQueueToDrain(); sendObservation(code, "SNOMED-CT"); @@ -301,12 +302,6 @@ public class RestHookWithInterceptorR4Test extends BaseSubscriptionsR4Test { } } - @Autowired - private IInterceptorService myInterceptorRegistry; - - @Autowired - private MyTestInterceptor myTestInterceptor; - @Configuration static class MyTestCtxConfig { diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/resthook/SubscriptionTriggeringDstu3Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/resthook/SubscriptionTriggeringDstu3Test.java index fbfd1b34ab5..ef2ff92b8f4 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/resthook/SubscriptionTriggeringDstu3Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/resthook/SubscriptionTriggeringDstu3Test.java @@ -1,6 +1,7 @@ package ca.uhn.fhir.jpa.subscription.resthook; import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.context.FhirVersionEnum; import ca.uhn.fhir.jpa.api.config.DaoConfig; import ca.uhn.fhir.jpa.model.sched.ISchedulerService; import ca.uhn.fhir.jpa.model.util.JpaConstants; @@ -34,11 +35,11 @@ import org.hl7.fhir.dstu3.model.Subscription; 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.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import javax.servlet.http.HttpServletRequest; @@ -48,9 +49,9 @@ import java.util.List; import static org.awaitility.Awaitility.await; import static org.hamcrest.CoreMatchers.containsString; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; /** * Test the rest-hook subscriptions @@ -77,9 +78,9 @@ public class SubscriptionTriggeringDstu3Test extends BaseResourceProviderDstu3Te @Autowired private ISchedulerService mySchedulerService; - @After + @AfterEach public void afterUnregisterRestHookListener() { - ourLog.info("**** Starting @After *****"); + ourLog.info("**** Starting @AfterEach *****"); for (IIdType next : mySubscriptionIds) { ourClient.delete().resourceById(next).execute(); @@ -102,7 +103,7 @@ public class SubscriptionTriggeringDstu3Test extends BaseResourceProviderDstu3Te myDaoConfig.setSearchPreFetchThresholds(new DaoConfig().getSearchPreFetchThresholds()); } - @Before + @BeforeEach public void beforeRegisterRestHookListener() { mySubscriptionTestUtil.registerRestHookInterceptor(); } @@ -110,7 +111,7 @@ public class SubscriptionTriggeringDstu3Test extends BaseResourceProviderDstu3Te /** * Only do counter resets here! We call this inside tests */ - @Before + @BeforeEach public void beforeReset() { ourCreatedObservations.clear(); ourUpdatedObservations.clear(); @@ -552,9 +553,9 @@ public class SubscriptionTriggeringDstu3Test extends BaseResourceProviderDstu3Te } - @BeforeClass + @BeforeAll public static void startListenerServer() throws Exception { - ourListenerRestServer = new RestfulServer(FhirContext.forDstu3()); + ourListenerRestServer = new RestfulServer(FhirContext.forCached(FhirVersionEnum.DSTU3)); ObservationListener obsListener = new ObservationListener(); PatientListener ptListener = new PatientListener(); @@ -575,7 +576,7 @@ public class SubscriptionTriggeringDstu3Test extends BaseResourceProviderDstu3Te ourListenerServerBase = "http://localhost:" + ourListenerPort + "/fhir/context"; } - @AfterClass + @AfterAll public static void stopListenerServer() throws Exception { JettyUtil.closeServer(ourListenerServer); } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/websocket/WebsocketWithCriteriaDstu2Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/websocket/WebsocketWithCriteriaDstu2Test.java index 6efb25987eb..464141c5880 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/websocket/WebsocketWithCriteriaDstu2Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/websocket/WebsocketWithCriteriaDstu2Test.java @@ -18,10 +18,10 @@ import ca.uhn.fhir.rest.api.MethodOutcome; import org.eclipse.jetty.websocket.api.Session; import org.eclipse.jetty.websocket.client.ClientUpgradeRequest; import org.eclipse.jetty.websocket.client.WebSocketClient; -import org.junit.After; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import java.net.URI; @@ -29,10 +29,10 @@ import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import static org.hamcrest.Matchers.contains; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; // This is currently disabled as the criteria mechanism was a non-standard experiment -@Ignore +@Disabled public class WebsocketWithCriteriaDstu2Test extends BaseResourceProviderDstu2Test { private static final Logger ourLog = org.slf4j.LoggerFactory.getLogger(WebsocketWithCriteriaDstu2Test.class); @@ -42,13 +42,13 @@ public class WebsocketWithCriteriaDstu2Test extends BaseResourceProviderDstu2Tes private SocketImplementation mySocketImplementation; @Override - @After + @AfterEach public void after() throws Exception { super.after(); } @Override - @Before + @BeforeEach public void before() throws Exception { super.before(); @@ -94,7 +94,7 @@ public class WebsocketWithCriteriaDstu2Test extends BaseResourceProviderDstu2Tes ourLog.info("Connected to WS: {}", session.isOpen()); } - @After + @AfterEach public void afterCloseWebsocket() throws Exception { ourLog.info("Shutting down websocket client"); myWebSocketClient.stop(); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/websocket/WebsocketWithCriteriaDstu3Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/websocket/WebsocketWithCriteriaDstu3Test.java index 5c4fa0f79f1..45f988c04d3 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/websocket/WebsocketWithCriteriaDstu3Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/websocket/WebsocketWithCriteriaDstu3Test.java @@ -9,10 +9,10 @@ import org.eclipse.jetty.websocket.api.Session; import org.eclipse.jetty.websocket.client.ClientUpgradeRequest; import org.eclipse.jetty.websocket.client.WebSocketClient; import org.hl7.fhir.dstu3.model.*; -import org.junit.After; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import java.net.URI; @@ -20,10 +20,10 @@ import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import static org.hamcrest.Matchers.contains; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; // This is currently disabled as the criteria mechanism was a non-standard experiment -@Ignore +@Disabled public class WebsocketWithCriteriaDstu3Test extends BaseResourceProviderDstu3Test { private static final Logger ourLog = org.slf4j.LoggerFactory.getLogger(WebsocketWithCriteriaDstu3Test.class); @@ -34,13 +34,13 @@ public class WebsocketWithCriteriaDstu3Test extends BaseResourceProviderDstu3Tes private SocketImplementation mySocketImplementation; @Override - @After + @AfterEach public void after() throws Exception { super.after(); } @Override - @Before + @BeforeEach public void before() throws Exception { super.before(); @@ -86,7 +86,7 @@ public class WebsocketWithCriteriaDstu3Test extends BaseResourceProviderDstu3Tes ourLog.info("Connected to WS: {}", session.isOpen()); } - @After + @AfterEach public void afterCloseWebsocket() throws Exception { ourLog.info("Shutting down websocket client"); myWebSocketClient.stop(); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/websocket/WebsocketWithCriteriaR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/websocket/WebsocketWithCriteriaR4Test.java index ad34b30e238..159983905b3 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/websocket/WebsocketWithCriteriaR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/websocket/WebsocketWithCriteriaR4Test.java @@ -9,10 +9,10 @@ import org.eclipse.jetty.websocket.api.Session; import org.eclipse.jetty.websocket.client.ClientUpgradeRequest; import org.eclipse.jetty.websocket.client.WebSocketClient; import org.hl7.fhir.r4.model.*; -import org.junit.After; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import java.net.URI; @@ -20,11 +20,11 @@ import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import static org.hamcrest.Matchers.contains; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; // This is currently disabled as the criteria mechanism was a non-standard experiment -@Ignore +@Disabled public class WebsocketWithCriteriaR4Test extends BaseResourceProviderR4Test { private static final Logger ourLog = org.slf4j.LoggerFactory.getLogger(WebsocketWithCriteriaR4Test.class); @@ -35,13 +35,13 @@ public class WebsocketWithCriteriaR4Test extends BaseResourceProviderR4Test { private SocketImplementation mySocketImplementation; @Override - @After + @AfterEach public void after() throws Exception { super.after(); } @Override - @Before + @BeforeEach public void before() throws Exception { super.before(); @@ -50,7 +50,7 @@ public class WebsocketWithCriteriaR4Test extends BaseResourceProviderR4Test { */ Patient patient = FhirR4Util.getPatient(); - MethodOutcome methodOutcome = ourClient.create().resource(patient).execute(); + MethodOutcome methodOutcome = myClient.create().resource(patient).execute(); myPatientId = methodOutcome.getId().getIdPart(); /* @@ -67,7 +67,7 @@ public class WebsocketWithCriteriaR4Test extends BaseResourceProviderR4Test { channel.setPayload("application/json"); subscription.setChannel(channel); - methodOutcome = ourClient.create().resource(subscription).execute(); + methodOutcome = myClient.create().resource(subscription).execute(); mySubscriptionId = methodOutcome.getId().getIdPart(); /* @@ -87,7 +87,7 @@ public class WebsocketWithCriteriaR4Test extends BaseResourceProviderR4Test { ourLog.info("Connected to WS: {}", session.isOpen()); } - @After + @AfterEach public void afterCloseWebsocket() throws Exception { ourLog.info("Shutting down websocket client"); myWebSocketClient.stop(); @@ -106,7 +106,7 @@ public class WebsocketWithCriteriaR4Test extends BaseResourceProviderR4Test { observation.setSubject(reference); observation.setStatus(Observation.ObservationStatus.FINAL); - MethodOutcome methodOutcome2 = ourClient.create().resource(observation).execute(); + MethodOutcome methodOutcome2 = myClient.create().resource(observation).execute(); String observationId = methodOutcome2.getId().getIdPart(); observation.setId(observationId); @@ -130,7 +130,7 @@ public class WebsocketWithCriteriaR4Test extends BaseResourceProviderR4Test { observation.setSubject(reference); observation.setStatus(Observation.ObservationStatus.FINAL); - MethodOutcome methodOutcome2 = ourClient.create().resource(observation).execute(); + MethodOutcome methodOutcome2 = myClient.create().resource(observation).execute(); String observationId = methodOutcome2.getId().getIdPart(); observation.setId(observationId); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/websocket/WebsocketWithSubscriptionIdDstu2Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/websocket/WebsocketWithSubscriptionIdDstu2Test.java index 5b292157efe..18a73efb331 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/websocket/WebsocketWithSubscriptionIdDstu2Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/websocket/WebsocketWithSubscriptionIdDstu2Test.java @@ -19,9 +19,9 @@ import ca.uhn.fhir.rest.api.MethodOutcome; import org.eclipse.jetty.websocket.api.Session; import org.eclipse.jetty.websocket.client.ClientUpgradeRequest; import org.eclipse.jetty.websocket.client.WebSocketClient; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.springframework.beans.factory.annotation.Autowired; @@ -30,7 +30,7 @@ import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import static org.hamcrest.Matchers.contains; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; /** * Adds a FHIR subscription with criteria through the rest interface. Then creates a websocket with the id of the @@ -59,20 +59,20 @@ public class WebsocketWithSubscriptionIdDstu2Test extends BaseResourceProviderDs private SubscriptionTestUtil mySubscriptionTestUtil; @Override - @After + @AfterEach public void after() throws Exception { super.after(); mySubscriptionTestUtil.unregisterSubscriptionInterceptor(); } - @After + @AfterEach public void afterCloseWebsocket() throws Exception { ourLog.info("Shutting down websocket client"); myWebSocketClient.stop(); } @Override - @Before + @BeforeEach public void before() throws Exception { super.before(); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/websocket/WebsocketWithSubscriptionIdDstu3Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/websocket/WebsocketWithSubscriptionIdDstu3Test.java index bead0e39896..85d46486957 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/websocket/WebsocketWithSubscriptionIdDstu3Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/websocket/WebsocketWithSubscriptionIdDstu3Test.java @@ -10,9 +10,9 @@ import org.eclipse.jetty.websocket.api.Session; import org.eclipse.jetty.websocket.client.ClientUpgradeRequest; import org.eclipse.jetty.websocket.client.WebSocketClient; import org.hl7.fhir.dstu3.model.*; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.springframework.beans.factory.annotation.Autowired; @@ -21,7 +21,7 @@ import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import static org.hamcrest.Matchers.contains; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; /** * Adds a FHIR subscription with criteria through the rest interface. Then creates a websocket with the id of the @@ -53,21 +53,21 @@ public class WebsocketWithSubscriptionIdDstu3Test extends BaseResourceProviderDs private SubscriptionTestUtil mySubscriptionTestUtil; @Override - @After + @AfterEach public void after() throws Exception { super.after(); mySubscriptionTestUtil.unregisterSubscriptionInterceptor(); } - @After + @AfterEach public void afterCloseWebsocket() throws Exception { ourLog.info("Shutting down websocket client"); myWebSocketClient.stop(); } @Override - @Before + @BeforeEach public void before() throws Exception { super.before(); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/websocket/WebsocketWithSubscriptionIdR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/websocket/WebsocketWithSubscriptionIdR4Test.java index 9d8af2a9d68..d1d9b1a85a1 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/websocket/WebsocketWithSubscriptionIdR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/subscription/websocket/WebsocketWithSubscriptionIdR4Test.java @@ -15,9 +15,9 @@ import org.hl7.fhir.r4.model.Observation; import org.hl7.fhir.r4.model.Patient; import org.hl7.fhir.r4.model.Reference; import org.hl7.fhir.r4.model.Subscription; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.springframework.beans.factory.annotation.Autowired; @@ -27,7 +27,7 @@ import java.util.concurrent.TimeUnit; import static org.awaitility.Awaitility.await; import static org.hamcrest.Matchers.contains; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; /** * Adds a FHIR subscription with criteria through the rest interface. Then creates a websocket with the id of the @@ -59,20 +59,20 @@ public class WebsocketWithSubscriptionIdR4Test extends BaseResourceProviderR4Tes private SubscriptionTestUtil mySubscriptionTestUtil; @Override - @After + @AfterEach public void after() throws Exception { super.after(); mySubscriptionTestUtil.unregisterSubscriptionInterceptor(); } - @After + @AfterEach public void afterCloseWebsocket() throws Exception { ourLog.info("Shutting down websocket client"); myWebSocketClient.stop(); } @Override - @Before + @BeforeEach public void before() throws Exception { super.before(); @@ -83,7 +83,7 @@ public class WebsocketWithSubscriptionIdR4Test extends BaseResourceProviderR4Tes */ Patient patient = FhirR4Util.getPatient(); - MethodOutcome methodOutcome = ourClient.create().resource(patient).execute(); + MethodOutcome methodOutcome = myClient.create().resource(patient).execute(); myPatientId = methodOutcome.getId().getIdPart(); /* @@ -100,7 +100,7 @@ public class WebsocketWithSubscriptionIdR4Test extends BaseResourceProviderR4Tes channel.setPayload("application/json"); subscription.setChannel(channel); - methodOutcome = ourClient.create().resource(subscription).execute(); + methodOutcome = myClient.create().resource(subscription).execute(); mySubscriptionId = methodOutcome.getId().getIdPart(); /* @@ -135,7 +135,7 @@ public class WebsocketWithSubscriptionIdR4Test extends BaseResourceProviderR4Tes observation.setSubject(reference); observation.setStatus(Observation.ObservationStatus.FINAL); - MethodOutcome methodOutcome2 = ourClient.create().resource(observation).execute(); + MethodOutcome methodOutcome2 = myClient.create().resource(observation).execute(); String observationId = methodOutcome2.getId().getIdPart(); observation.setId(observationId); @@ -159,7 +159,7 @@ public class WebsocketWithSubscriptionIdR4Test extends BaseResourceProviderR4Tes observation.setSubject(reference); observation.setStatus(Observation.ObservationStatus.FINAL); - MethodOutcome methodOutcome2 = ourClient.create().resource(observation).execute(); + MethodOutcome methodOutcome2 = myClient.create().resource(observation).execute(); String observationId = methodOutcome2.getId().getIdPart(); observation.setId(observationId); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/BaseLoaderTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/BaseLoaderTest.java index 7192e82d9b0..889dd09791a 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/BaseLoaderTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/BaseLoaderTest.java @@ -1,23 +1,23 @@ package ca.uhn.fhir.jpa.term; -import ca.uhn.fhir.test.BaseTest; import ca.uhn.fhir.jpa.entity.TermCodeSystemVersion; import ca.uhn.fhir.jpa.entity.TermConcept; import ca.uhn.fhir.rest.api.server.RequestDetails; +import ca.uhn.fhir.test.BaseTest; import org.hl7.fhir.r4.model.CodeSystem; import org.hl7.fhir.r4.model.ConceptMap; import org.hl7.fhir.r4.model.ValueSet; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import java.util.HashMap; import java.util.List; import java.util.Map; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) abstract class BaseLoaderTest extends BaseTest { @Mock diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/BaseTermR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/BaseTermR4Test.java index ee7415b9d80..24441003619 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/BaseTermR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/BaseTermR4Test.java @@ -11,8 +11,8 @@ import org.hl7.fhir.instance.model.api.IIdType; import org.hl7.fhir.r4.model.CodeSystem; import org.hl7.fhir.r4.model.ValueSet; import org.hl7.fhir.r4.model.codesystems.HttpVerb; -import org.junit.After; -import org.junit.Before; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.springframework.transaction.TransactionStatus; import org.springframework.transaction.support.TransactionCallbackWithoutResult; import org.springframework.transaction.support.TransactionTemplate; @@ -27,12 +27,12 @@ public abstract class BaseTermR4Test extends BaseJpaR4Test { Long myExtensionalCsIdOnResourceTable; Long myExtensionalVsIdOnResourceTable; - @Before + @BeforeEach public void before() { myDaoConfig.setAllowExternalReferences(true); } - @After + @AfterEach public void after() { myDaoConfig.setAllowExternalReferences(new DaoConfig().isAllowExternalReferences()); myDaoConfig.setPreExpandValueSets(new DaoConfig().isPreExpandValueSets()); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TermCodeSystemStorageSvcTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TermCodeSystemStorageSvcTest.java index 5fd251daa5b..8c6f1fc8805 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TermCodeSystemStorageSvcTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TermCodeSystemStorageSvcTest.java @@ -4,9 +4,9 @@ import ca.uhn.fhir.jpa.dao.r4.BaseJpaR4Test; import ca.uhn.fhir.jpa.model.entity.ResourceTable; import org.hl7.fhir.r4.model.CodeSystem; import org.hl7.fhir.r4.model.CodeType; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public class TermCodeSystemStorageSvcTest extends BaseJpaR4Test { @@ -17,7 +17,7 @@ public class TermCodeSystemStorageSvcTest extends BaseJpaR4Test { CodeSystem upload = createCodeSystemWithMoreThan100Concepts(); // Create CodeSystem resource - ResourceTable codeSystemResourceEntity = (ResourceTable)myCodeSystemDao.create(upload, mySrd).getEntity(); + ResourceTable codeSystemResourceEntity = (ResourceTable) myCodeSystemDao.create(upload, mySrd).getEntity(); // Update the CodeSystem resource runInTransaction(() -> myTermCodeSystemStorageSvc.storeNewCodeSystemVersionIfNeeded(upload, codeSystemResourceEntity)); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TermDeferredStorageSvcImplTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TermDeferredStorageSvcImplTest.java index 131065c49e5..b406a31dedd 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TermDeferredStorageSvcImplTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TermDeferredStorageSvcImplTest.java @@ -7,18 +7,22 @@ import ca.uhn.fhir.jpa.entity.TermCodeSystemVersion; import ca.uhn.fhir.jpa.entity.TermConcept; import ca.uhn.fhir.jpa.entity.TermConceptParentChildLink; import ca.uhn.fhir.jpa.term.api.ITermCodeSystemStorageSvc; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.transaction.PlatformTransactionManager; import java.util.Optional; +import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.ArgumentMatchers.same; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; +import static org.mockito.Mockito.when; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class TermDeferredStorageSvcImplTest { @Mock diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TerminologyLoaderSvcCustomTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TerminologyLoaderSvcCustomTest.java index 2dbedd188dd..072e9287e41 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TerminologyLoaderSvcCustomTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TerminologyLoaderSvcCustomTest.java @@ -8,25 +8,25 @@ import ca.uhn.fhir.rest.api.server.RequestDetails; import ca.uhn.fhir.util.TestUtil; import org.hl7.fhir.r4.model.CodeSystem; import org.hl7.fhir.r4.model.IdType; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import java.io.IOException; import java.util.Map; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertSame; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertSame; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.*; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class TerminologyLoaderSvcCustomTest extends BaseLoaderTest { private TermLoaderSvcImpl mySvc; @@ -38,7 +38,7 @@ public class TerminologyLoaderSvcCustomTest extends BaseLoaderTest { @Mock private ITermDeferredStorageSvc myTermDeferredStorageSvc; - @Before + @BeforeEach public void before() { mySvc = new TermLoaderSvcImpl(); mySvc.setTermCodeSystemStorageSvcForUnitTests(myTermCodeSystemStorageSvc); @@ -179,9 +179,5 @@ public class TerminologyLoaderSvcCustomTest extends BaseLoaderTest { } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TerminologyLoaderSvcImgthlaTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TerminologyLoaderSvcImgthlaTest.java index 21e61ab0686..1db634ed3e9 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TerminologyLoaderSvcImgthlaTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TerminologyLoaderSvcImgthlaTest.java @@ -4,17 +4,17 @@ import ca.uhn.fhir.jpa.term.api.ITermCodeSystemStorageSvc; import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; import ca.uhn.fhir.util.TestUtil; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.mockito.Mock; import java.io.IOException; import static org.hamcrest.Matchers.containsString; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.fail; public class TerminologyLoaderSvcImgthlaTest extends BaseLoaderTest { private TermLoaderSvcImpl mySvc; @@ -25,7 +25,7 @@ public class TerminologyLoaderSvcImgthlaTest extends BaseLoaderTest { private ZipCollectionBuilder myFiles; - @Before + @BeforeEach public void before() { mySvc = new TermLoaderSvcImpl(); mySvc.setTermCodeSystemStorageSvcForUnitTests(myTermStorageSvc); @@ -50,7 +50,7 @@ public class TerminologyLoaderSvcImgthlaTest extends BaseLoaderTest { } @Test - @Ignore + @Disabled public void testLoadImgthlaMandatoryFilesOnly() throws IOException { addImgthlaMandatoryFilesToZip(myFiles); @@ -83,9 +83,4 @@ public class TerminologyLoaderSvcImgthlaTest extends BaseLoaderTest { theFiles.addFileZip("/imgthla/", TermLoaderSvcImpl.IMGTHLA_HLA_XML); } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } - } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TerminologyLoaderSvcIntegrationDstu3Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TerminologyLoaderSvcIntegrationDstu3Test.java index 6a06243fde9..711bdb8f4f7 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TerminologyLoaderSvcIntegrationDstu3Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TerminologyLoaderSvcIntegrationDstu3Test.java @@ -15,10 +15,10 @@ import org.hl7.fhir.dstu3.model.StringType; import org.hl7.fhir.dstu3.model.Type; import org.hl7.fhir.dstu3.model.ValueSet; import org.hl7.fhir.instance.model.api.IPrimitiveType; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -33,10 +33,10 @@ import static org.awaitility.Awaitility.await; import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.greaterThan; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertTrue; public class TerminologyLoaderSvcIntegrationDstu3Test extends BaseJpaDstu3Test { @@ -45,12 +45,12 @@ public class TerminologyLoaderSvcIntegrationDstu3Test extends BaseJpaDstu3Test { @Autowired private ITermLoaderSvc myLoader; - @After + @AfterEach public void after() { myDaoConfig.setDeferIndexingForCodesystemsOfSize(new DaoConfig().getDeferIndexingForCodesystemsOfSize()); } - @Before + @BeforeEach public void before() { myDaoConfig.setDeferIndexingForCodesystemsOfSize(20000); } @@ -256,9 +256,5 @@ public class TerminologyLoaderSvcIntegrationDstu3Test extends BaseJpaDstu3Test { .collect(Collectors.toSet()); } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TerminologyLoaderSvcLoincTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TerminologyLoaderSvcLoincTest.java index 342c82421eb..c41a29eddb6 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TerminologyLoaderSvcLoincTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TerminologyLoaderSvcLoincTest.java @@ -1,12 +1,20 @@ package ca.uhn.fhir.jpa.term; import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.context.FhirVersionEnum; import ca.uhn.fhir.jpa.entity.TermConcept; import ca.uhn.fhir.jpa.entity.TermConceptProperty; import ca.uhn.fhir.jpa.term.api.ITermCodeSystemStorageSvc; import ca.uhn.fhir.jpa.term.api.ITermDeferredStorageSvc; import ca.uhn.fhir.jpa.term.api.ITermLoaderSvc; -import ca.uhn.fhir.jpa.term.loinc.*; +import ca.uhn.fhir.jpa.term.loinc.LoincDocumentOntologyHandler; +import ca.uhn.fhir.jpa.term.loinc.LoincIeeeMedicalDeviceCodeHandler; +import ca.uhn.fhir.jpa.term.loinc.LoincImagingDocumentCodeHandler; +import ca.uhn.fhir.jpa.term.loinc.LoincPartRelatedCodeMappingHandler; +import ca.uhn.fhir.jpa.term.loinc.LoincRsnaPlaybookHandler; +import ca.uhn.fhir.jpa.term.loinc.LoincTop2000LabResultsSiHandler; +import ca.uhn.fhir.jpa.term.loinc.LoincTop2000LabResultsUsHandler; +import ca.uhn.fhir.jpa.term.loinc.LoincUniversalOrderSetHandler; import ca.uhn.fhir.rest.api.server.RequestDetails; import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; import ca.uhn.fhir.util.TestUtil; @@ -14,10 +22,10 @@ import org.hl7.fhir.r4.model.CodeSystem; import org.hl7.fhir.r4.model.ConceptMap; import org.hl7.fhir.r4.model.Enumerations; import org.hl7.fhir.r4.model.ValueSet; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.Mock; @@ -28,8 +36,13 @@ import java.util.List; import java.util.Map; import static ca.uhn.fhir.jpa.term.loinc.LoincUploadPropertiesEnum.*; -import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.empty; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -47,7 +60,7 @@ public class TerminologyLoaderSvcLoincTest extends BaseLoaderTest { private ITermDeferredStorageSvc myTermDeferredStorageSvc; - @Before + @BeforeEach public void before() { mySvc = new TermLoaderSvcImpl(); mySvc.setTermCodeSystemStorageSvcForUnitTests(myTermCodeSystemStorageSvc); @@ -286,7 +299,7 @@ public class TerminologyLoaderSvcLoincTest extends BaseLoaderTest { // IEEE Medical Device Codes conceptMap = conceptMaps.get(LoincIeeeMedicalDeviceCodeHandler.LOINC_IEEE_CM_ID); - ourLog.debug(FhirContext.forR4().newXmlParser().setPrettyPrint(true).encodeResourceToString(conceptMap)); + ourLog.debug(FhirContext.forCached(FhirVersionEnum.R4).newXmlParser().setPrettyPrint(true).encodeResourceToString(conceptMap)); assertEquals(LoincIeeeMedicalDeviceCodeHandler.LOINC_IEEE_CM_NAME, conceptMap.getName()); assertEquals(LoincIeeeMedicalDeviceCodeHandler.LOINC_IEEE_CM_URI, conceptMap.getUrl()); assertEquals(1, conceptMap.getGroup().size()); @@ -311,7 +324,7 @@ public class TerminologyLoaderSvcLoincTest extends BaseLoaderTest { // Group - Parent vs = valueSets.get("LG100-4"); - ourLog.info(FhirContext.forR4().newXmlParser().setPrettyPrint(true).encodeResourceToString(vs)); + ourLog.info(FhirContext.forCached(FhirVersionEnum.R4).newXmlParser().setPrettyPrint(true).encodeResourceToString(vs)); assertEquals("Chem_DrugTox_Chal_Sero_Allergy", vs.getName()); assertEquals("http://loinc.org/vs/LG100-4", vs.getUrl()); assertEquals(1, vs.getCompose().getInclude().size()); @@ -320,7 +333,7 @@ public class TerminologyLoaderSvcLoincTest extends BaseLoaderTest { // Group - Child vs = valueSets.get("LG1695-8"); - ourLog.info(FhirContext.forR4().newXmlParser().setPrettyPrint(true).encodeResourceToString(vs)); + ourLog.info(FhirContext.forCached(FhirVersionEnum.R4).newXmlParser().setPrettyPrint(true).encodeResourceToString(vs)); assertEquals("1,4-Dichlorobenzene|MCnc|Pt|ANYBldSerPl", vs.getName()); assertEquals("http://loinc.org/vs/LG1695-8", vs.getUrl()); assertEquals(1, vs.getCompose().getInclude().size()); @@ -330,7 +343,7 @@ public class TerminologyLoaderSvcLoincTest extends BaseLoaderTest { } @Test - @Ignore + @Disabled public void testLoadLoincMandatoryFilesOnly() throws IOException { addLoincMandatoryFilesToZip(myFiles); @@ -500,9 +513,5 @@ public class TerminologyLoaderSvcLoincTest extends BaseLoaderTest { assertEquals("LP52960-9", doublyNestedChildCode.getChildren().get(2).getChild().getCode()); } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TerminologyLoaderSvcSnomedCtTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TerminologyLoaderSvcSnomedCtTest.java index 056b796a2a3..85dc2994ccd 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TerminologyLoaderSvcSnomedCtTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TerminologyLoaderSvcSnomedCtTest.java @@ -12,10 +12,10 @@ import ca.uhn.fhir.util.TestUtil; import org.apache.commons.io.IOUtils; import org.hl7.fhir.r4.model.CodeSystem; import org.hl7.fhir.r4.model.ConceptMap; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.Mock; @@ -31,8 +31,8 @@ import java.util.zip.ZipOutputStream; import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.Matchers.hasItem; import static org.hamcrest.Matchers.not; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.verify; @@ -48,7 +48,7 @@ public class TerminologyLoaderSvcSnomedCtTest extends BaseLoaderTest { @Mock private ITermDeferredStorageSvc myTermDeferredStorageSvc; - @Before + @BeforeEach public void before() { mySvc = new TermLoaderSvcImpl(); mySvc.setTermCodeSystemStorageSvcForUnitTests(myTermCodeSystemStorageSvc); @@ -104,7 +104,7 @@ public class TerminologyLoaderSvcSnomedCtTest extends BaseLoaderTest { * This is just for trying stuff, it won't run without * local files external to the git repo */ - @Ignore + @Disabled @Test public void testLoadSnomedCtAgainstRealFile() throws Exception { byte[] bytes = IOUtils.toByteArray(new FileInputStream("/Users/james/Downloads/SnomedCT_Release_INT_20160131_Full.zip")); @@ -146,9 +146,5 @@ public class TerminologyLoaderSvcSnomedCtTest extends BaseLoaderTest { } } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TerminologySvcDeltaR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TerminologySvcDeltaR4Test.java index a9d0b5018db..265e2064761 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TerminologySvcDeltaR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TerminologySvcDeltaR4Test.java @@ -19,10 +19,10 @@ import org.hl7.fhir.r4.model.Coding; import org.hl7.fhir.r4.model.Parameters; import org.hl7.fhir.r4.model.StringType; import org.hl7.fhir.r4.model.ValueSet; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -35,15 +35,15 @@ import java.util.stream.Collectors; import static org.apache.commons.lang3.StringUtils.leftPad; import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.Matchers.matchesPattern; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.fail; public class TerminologySvcDeltaR4Test extends BaseJpaR4Test { private static final Logger ourLog = LoggerFactory.getLogger(TerminologySvcDeltaR4Test.class); - @After + @AfterEach public void after() { myDaoConfig.setDeferIndexingForCodesystemsOfSize(new DaoConfig().getDeferIndexingForCodesystemsOfSize()); } @@ -444,7 +444,7 @@ public class TerminologySvcDeltaR4Test extends BaseJpaR4Test { } @Test - @Ignore + @Disabled public void testAddWithPropertiesAndDesignations() { // Create not-present @@ -600,8 +600,4 @@ public class TerminologySvcDeltaR4Test extends BaseJpaR4Test { myCodeSystemDao.create(cs); } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TerminologySvcImplDstu3Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TerminologySvcImplDstu3Test.java index 18ac8d005fb..c3787c589b0 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TerminologySvcImplDstu3Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TerminologySvcImplDstu3Test.java @@ -10,12 +10,11 @@ import ca.uhn.fhir.jpa.entity.TermCodeSystemVersion; import ca.uhn.fhir.jpa.entity.TermConcept; import ca.uhn.fhir.jpa.entity.TermConceptParentChildLink; import ca.uhn.fhir.jpa.entity.TermConceptParentChildLink.RelationshipTypeEnum; -import ca.uhn.fhir.rest.api.server.storage.ResourcePersistentId; import ca.uhn.fhir.jpa.model.entity.ResourceTable; +import ca.uhn.fhir.rest.api.server.storage.ResourcePersistentId; import ca.uhn.fhir.rest.api.server.storage.TransactionDetails; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; -import ca.uhn.fhir.util.TestUtil; import ca.uhn.fhir.util.VersionIndependentConcept; import com.google.common.collect.Lists; import org.apache.commons.lang3.Validate; @@ -23,12 +22,9 @@ 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.hl7.fhir.r4.model.ValueSet; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Ignore; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.transaction.TransactionStatus; @@ -42,23 +38,21 @@ import java.util.Set; import java.util.stream.Collectors; import static ca.uhn.fhir.jpa.term.api.ITermLoaderSvc.LOINC_URI; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.empty; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.fail; public class TerminologySvcImplDstu3Test extends BaseJpaDstu3Test { private static final Logger ourLog = LoggerFactory.getLogger(TerminologySvcImplDstu3Test.class); private static final String CS_URL = "http://example.com/my_code_system"; private static final String CS_URL_2 = "http://example.com/my_code_system2"; - @Rule - public final ExpectedException expectedException = ExpectedException.none(); - @After + @AfterEach public void after() { myDaoConfig.setDeferIndexingForCodesystemsOfSize(new DaoConfig().getDeferIndexingForCodesystemsOfSize()); TermReindexingSvcImpl.setForceSaveDeferredAlwaysForUnitTest(false); @@ -503,9 +497,12 @@ public class TerminologySvcImplDstu3Test extends BaseJpaDstu3Test { .setOp(ValueSet.FilterOperator.ISA) .setValue("LOINC"); - expectedException.expect(InvalidRequestException.class); - expectedException.expectMessage("Don't know how to handle op=ISA on property copyright"); - myTermSvc.expandValueSet(null, vs); + try { + myTermSvc.expandValueSet(null, vs); + fail(); + } catch (InvalidRequestException e) { + assertEquals("Don't know how to handle op=ISA on property copyright", e.getMessage()); + } } @Test @@ -526,9 +523,13 @@ public class TerminologySvcImplDstu3Test extends BaseJpaDstu3Test { .setOp(ValueSet.FilterOperator.EQUAL) .setValue("LOINC"); - expectedException.expect(InvalidRequestException.class); - expectedException.expectMessage("Invalid filter, property copyright is LOINC-specific and cannot be used with system: http://example.com/my_code_system"); - myTermSvc.expandValueSet(null, vs); + try { + myTermSvc.expandValueSet(null, vs); + fail(); + } catch (InvalidRequestException e) { + assertEquals("Invalid filter, property copyright is LOINC-specific and cannot be used with system: http://example.com/my_code_system", e.getMessage()); + } + } @Test @@ -548,9 +549,13 @@ public class TerminologySvcImplDstu3Test extends BaseJpaDstu3Test { .setOp(ValueSet.FilterOperator.EQUAL) .setValue("bogus"); - expectedException.expect(InvalidRequestException.class); - expectedException.expectMessage("Don't know how to handle value=bogus on property copyright"); - myTermSvc.expandValueSet(null, vs); + try { + myTermSvc.expandValueSet(null, vs); + fail(); + } catch (InvalidRequestException e) { + assertEquals("Don't know how to handle value=bogus on property copyright", e.getMessage()); + } + } @Test @@ -758,9 +763,13 @@ public class TerminologySvcImplDstu3Test extends BaseJpaDstu3Test { .setOp(ValueSet.FilterOperator.ISA) .setValue("50015-7"); - expectedException.expect(InvalidRequestException.class); - expectedException.expectMessage("Don't know how to handle op=ISA on property ancestor"); - myTermSvc.expandValueSet(null, vs); + try { + myTermSvc.expandValueSet(null, vs); + fail(); + } catch (InvalidRequestException e) { + assertEquals("Don't know how to handle op=ISA on property ancestor", e.getMessage()); + } + } @Test @@ -781,9 +790,13 @@ public class TerminologySvcImplDstu3Test extends BaseJpaDstu3Test { .setOp(ValueSet.FilterOperator.EQUAL) .setValue("50015-7"); - expectedException.expect(InvalidRequestException.class); - expectedException.expectMessage("Invalid filter, property ancestor is LOINC-specific and cannot be used with system: http://example.com/my_code_system"); - myTermSvc.expandValueSet(null, vs); + try { + myTermSvc.expandValueSet(null, vs); + fail(); + } catch (InvalidRequestException e) { + assertEquals("Invalid filter, property ancestor is LOINC-specific and cannot be used with system: http://example.com/my_code_system", e.getMessage()); + } + } @Test @@ -992,9 +1005,13 @@ public class TerminologySvcImplDstu3Test extends BaseJpaDstu3Test { .setOp(ValueSet.FilterOperator.ISA) .setValue("50015-7"); - expectedException.expect(InvalidRequestException.class); - expectedException.expectMessage("Don't know how to handle op=ISA on property child"); - myTermSvc.expandValueSet(null, vs); + try { + myTermSvc.expandValueSet(null, vs); + fail(); + } catch (InvalidRequestException e) { + assertEquals("Don't know how to handle op=ISA on property child", e.getMessage()); + } + } @Test @@ -1015,9 +1032,13 @@ public class TerminologySvcImplDstu3Test extends BaseJpaDstu3Test { .setOp(ValueSet.FilterOperator.EQUAL) .setValue("50015-7"); - expectedException.expect(InvalidRequestException.class); - expectedException.expectMessage("Invalid filter, property child is LOINC-specific and cannot be used with system: http://example.com/my_code_system"); - myTermSvc.expandValueSet(null, vs); + try { + myTermSvc.expandValueSet(null, vs); + fail(); + } catch (InvalidRequestException e) { + assertEquals("Invalid filter, property child is LOINC-specific and cannot be used with system: http://example.com/my_code_system", e.getMessage()); + } + } @Test @@ -1226,9 +1247,13 @@ public class TerminologySvcImplDstu3Test extends BaseJpaDstu3Test { .setOp(ValueSet.FilterOperator.ISA) .setValue("50015-7"); - expectedException.expect(InvalidRequestException.class); - expectedException.expectMessage("Don't know how to handle op=ISA on property descendant"); - myTermSvc.expandValueSet(null, vs); + try { + myTermSvc.expandValueSet(null, vs); + fail(); + } catch (InvalidRequestException e) { + assertEquals("Don't know how to handle op=ISA on property descendant", e.getMessage()); + } + } @Test @@ -1249,9 +1274,13 @@ public class TerminologySvcImplDstu3Test extends BaseJpaDstu3Test { .setOp(ValueSet.FilterOperator.EQUAL) .setValue("50015-7"); - expectedException.expect(InvalidRequestException.class); - expectedException.expectMessage("Invalid filter, property descendant is LOINC-specific and cannot be used with system: http://example.com/my_code_system"); - myTermSvc.expandValueSet(null, vs); + try { + myTermSvc.expandValueSet(null, vs); + fail(); + } catch (InvalidRequestException e) { + assertEquals("Invalid filter, property descendant is LOINC-specific and cannot be used with system: http://example.com/my_code_system", e.getMessage()); + } + } @Test @@ -1459,9 +1488,13 @@ public class TerminologySvcImplDstu3Test extends BaseJpaDstu3Test { .setOp(ValueSet.FilterOperator.ISA) .setValue("50015-7"); - expectedException.expect(InvalidRequestException.class); - expectedException.expectMessage("Don't know how to handle op=ISA on property parent"); - myTermSvc.expandValueSet(null, vs); + try { + myTermSvc.expandValueSet(null, vs); + fail(); + } catch (InvalidRequestException e) { + assertEquals("Don't know how to handle op=ISA on property parent", e.getMessage()); + } + } @Test @@ -1482,9 +1515,13 @@ public class TerminologySvcImplDstu3Test extends BaseJpaDstu3Test { .setOp(ValueSet.FilterOperator.EQUAL) .setValue("50015-7"); - expectedException.expect(InvalidRequestException.class); - expectedException.expectMessage("Invalid filter, property parent is LOINC-specific and cannot be used with system: http://example.com/my_code_system"); - myTermSvc.expandValueSet(null, vs); + try { + myTermSvc.expandValueSet(null, vs); + fail(); + } catch (InvalidRequestException e) { + assertEquals("Invalid filter, property parent is LOINC-specific and cannot be used with system: http://example.com/my_code_system", e.getMessage()); + } + } @Test @@ -1948,7 +1985,7 @@ public class TerminologySvcImplDstu3Test extends BaseJpaDstu3Test { @Test - @Ignore + @Disabled public void testValidateCodeWithProperties() { createCodeSystem(); IValidationSupport.CodeValidationResult code = myValidationSupport.validateCode(new ValidationSupportContext(myValidationSupport), new ConceptValidationOptions(), CS_URL, "childAAB", null, null); @@ -1967,8 +2004,4 @@ public class TerminologySvcImplDstu3Test extends BaseJpaDstu3Test { return retVal; } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TerminologySvcImplR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TerminologySvcImplR4Test.java index 6897dea6bba..6467dbcb19d 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TerminologySvcImplR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/TerminologySvcImplR4Test.java @@ -11,7 +11,6 @@ import ca.uhn.fhir.jpa.entity.TermConceptMapGroupElement; import ca.uhn.fhir.jpa.entity.TermConceptMapGroupElementTarget; import ca.uhn.fhir.jpa.entity.TermValueSet; import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; -import ca.uhn.fhir.util.TestUtil; import org.hl7.fhir.instance.model.api.IIdType; import org.hl7.fhir.r4.model.CanonicalType; import org.hl7.fhir.r4.model.CodeSystem; @@ -24,10 +23,7 @@ import org.hl7.fhir.r4.model.UriType; import org.hl7.fhir.r4.model.ValueSet; import org.hl7.fhir.r4.model.codesystems.HttpVerb; import org.hl7.fhir.utilities.validation.ValidationOptions; -import org.junit.AfterClass; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.transaction.TransactionStatus; @@ -38,17 +34,17 @@ import javax.annotation.Nonnull; import java.util.List; import java.util.Optional; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; public class TerminologySvcImplR4Test extends BaseTermR4Test { private static final Logger ourLog = LoggerFactory.getLogger(TerminologySvcImplR4Test.class); - @Rule - public final ExpectedException expectedException = ExpectedException.none(); + ValidationOptions optsNoGuess = new ValidationOptions(); + ValidationOptions optsGuess = new ValidationOptions().guessSystem(); private IIdType myConceptMapId; private void createAndPersistConceptMap() { @@ -81,8 +77,6 @@ public class TerminologySvcImplR4Test extends BaseTermR4Test { } } - - @Test public void testCreateConceptMapWithMissingSourceSystem() { ConceptMap conceptMap = new ConceptMap(); @@ -105,7 +99,6 @@ public class TerminologySvcImplR4Test extends BaseTermR4Test { } - @Test public void testCreateConceptMapWithVirtualSourceSystem() { ConceptMap conceptMap = createConceptMap(); @@ -253,20 +246,25 @@ public class TerminologySvcImplR4Test extends BaseTermR4Test { public void testDuplicateCodeSystemUrls() throws Exception { loadAndPersistCodeSystem(); - expectedException.expect(UnprocessableEntityException.class); - expectedException.expectMessage("Can not create multiple CodeSystem resources with CodeSystem.url \"http://acme.org\", already have one with resource ID: CodeSystem/" + myExtensionalCsId.getIdPart()); - - loadAndPersistCodeSystem(); + try { + loadAndPersistCodeSystem(); + fail(); + } catch (UnprocessableEntityException e) { + assertEquals("Can not create multiple CodeSystem resources with CodeSystem.url \"http://acme.org\", already have one with resource ID: CodeSystem/" + myExtensionalCsId.getIdPart(), e.getMessage()); + } } @Test public void testDuplicateConceptMapUrls() { createAndPersistConceptMap(); - expectedException.expect(UnprocessableEntityException.class); - expectedException.expectMessage("Can not create multiple ConceptMap resources with ConceptMap.url \"http://example.com/my_concept_map\", already have one with resource ID: ConceptMap/" + myConceptMapId.getIdPart()); + try { + createAndPersistConceptMap(); + fail(); + } catch (UnprocessableEntityException e) { + assertEquals("Can not create multiple ConceptMap resources with ConceptMap.url \"http://example.com/my_concept_map\", already have one with resource ID: ConceptMap/" + myConceptMapId.getIdPart(), e.getMessage()); + } - createAndPersistConceptMap(); } @Test @@ -276,10 +274,13 @@ public class TerminologySvcImplR4Test extends BaseTermR4Test { // DM 2019-03-05 - We pre-load our custom CodeSystem otherwise pre-expansion of the ValueSet will fail. loadAndPersistCodeSystemAndValueSet(); - expectedException.expect(UnprocessableEntityException.class); - expectedException.expectMessage("Can not create multiple ValueSet resources with ValueSet.url \"http://www.healthintersections.com.au/fhir/ValueSet/extensional-case-2\", already have one with resource ID: ValueSet/" + myExtensionalVsId.getIdPart()); + try { + loadAndPersistValueSet(HttpVerb.POST); + fail(); + } catch (UnprocessableEntityException e) { + assertEquals("Can not create multiple ValueSet resources with ValueSet.url \"http://www.healthintersections.com.au/fhir/ValueSet/extensional-case-2\", already have one with resource ID: ValueSet/" + myExtensionalVsId.getIdPart(), e.getMessage()); + } - loadAndPersistValueSet(HttpVerb.POST); } @Test @@ -634,7 +635,7 @@ public class TerminologySvcImplR4Test extends BaseTermR4Test { assertEquals(Enumerations.ConceptMapEquivalence.NARROWER, target.getEquivalence()); assertEquals(VS_URL_2, target.getValueSet()); assertEquals(CM_URL, target.getConceptMapUrl()); - } + } }); } @@ -1837,9 +1838,6 @@ public class TerminologySvcImplR4Test extends BaseTermR4Test { assertEquals("Systolic blood pressure at First encounter", result.getDisplay()); } - ValidationOptions optsNoGuess = new ValidationOptions(); - ValidationOptions optsGuess = new ValidationOptions().guessSystem(); - @Test public void testValidateCodeIsInPreExpandedValueSetWithClientAssignedId() throws Exception { myDaoConfig.setPreExpandValueSets(true); @@ -1893,9 +1891,4 @@ public class TerminologySvcImplR4Test extends BaseTermR4Test { assertEquals("Validation succeeded", result.getMessage()); assertEquals("Systolic blood pressure at First encounter", result.getDisplay()); } - - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/ValueSetConceptAccumulatorTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/ValueSetConceptAccumulatorTest.java index e29aba98053..16d3dc3d930 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/ValueSetConceptAccumulatorTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/ValueSetConceptAccumulatorTest.java @@ -6,20 +6,22 @@ import ca.uhn.fhir.jpa.dao.data.ITermValueSetDao; import ca.uhn.fhir.jpa.entity.TermValueSet; import ca.uhn.fhir.jpa.entity.TermValueSetConcept; import ca.uhn.fhir.jpa.entity.TermValueSetConceptDesignation; -import org.hl7.fhir.r4.model.ValueSet; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import java.util.Optional; -import static org.junit.Assert.*; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.eq; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoInteractions; +import static org.mockito.Mockito.when; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class ValueSetConceptAccumulatorTest { private ValueSetConceptAccumulator myAccumulator; @@ -31,7 +33,7 @@ public class ValueSetConceptAccumulatorTest { @Mock private ITermValueSetConceptDao myValueSetConceptDao; - @Before + @BeforeEach public void before() { myValueSet = new TermValueSet(); myAccumulator = new ValueSetConceptAccumulator(myValueSet, myValueSetDao, myValueSetConceptDao, myValueSetDesignationDao); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/ValueSetExpansionR4ElasticsearchIT.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/ValueSetExpansionR4ElasticsearchIT.java index c31e74a302d..84f0f663b9c 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/ValueSetExpansionR4ElasticsearchIT.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/ValueSetExpansionR4ElasticsearchIT.java @@ -28,19 +28,19 @@ import org.hl7.fhir.r4.model.CodeSystem; import org.hl7.fhir.r4.model.CodeableConcept; import org.hl7.fhir.r4.model.Coding; import org.hl7.fhir.r4.model.ValueSet; -import org.junit.After; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Answers; import org.mockito.Mock; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.transaction.PlatformTransactionManager; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.ArgumentMatchers.anyCollection; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.nullable; @@ -48,10 +48,11 @@ import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = {TestR4ConfigWithElasticSearch.class}) public class ValueSetExpansionR4ElasticsearchIT extends BaseJpaTest { + protected static final String CS_URL = "http://example.com/my_code_system"; @Autowired protected DaoConfig myDaoConfig; @Autowired @@ -68,12 +69,12 @@ public class ValueSetExpansionR4ElasticsearchIT extends BaseJpaTest { protected ITermReadSvcR4 myTermSvc; @Autowired protected ITermDeferredStorageSvc myTerminologyDeferredStorageSvc; - + @Mock(answer = Answers.RETURNS_DEEP_STUBS) + protected ServletRequestDetails mySrd; @Autowired FhirContext myFhirContext; @Autowired PlatformTransactionManager myTxManager; - @Autowired private IFhirSystemDao mySystemDao; @Autowired @@ -84,21 +85,15 @@ public class ValueSetExpansionR4ElasticsearchIT extends BaseJpaTest { private ISearchParamRegistry mySearchParamRegistry; @Autowired private IBulkDataExportSvc myBulkDataExportSvc; - @Mock private IValueSetConceptAccumulator myValueSetCodeAccumulator; - @Mock(answer = Answers.RETURNS_DEEP_STUBS) - protected ServletRequestDetails mySrd; - - protected static final String CS_URL = "http://example.com/my_code_system"; - - @After + @AfterEach public void after() { myDaoConfig.setMaximumExpansionSize(DaoConfig.DEFAULT_MAX_EXPANSION_SIZE); } - @After + @AfterEach public void afterPurgeDatabase() { purgeDatabase(myDaoConfig, mySystemDao, myResourceReindexingSvc, mySearchCoordinatorSvc, mySearchParamRegistry, myBulkDataExportSvc); } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/ValueSetExpansionR4Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/ValueSetExpansionR4Test.java index 19aff0368dc..40850b23eaf 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/ValueSetExpansionR4Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/term/ValueSetExpansionR4Test.java @@ -19,7 +19,7 @@ import org.hl7.fhir.r4.model.CodeSystem; import org.hl7.fhir.r4.model.Extension; import org.hl7.fhir.r4.model.ValueSet; import org.hl7.fhir.r4.model.codesystems.HttpVerb; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mockito.Mock; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -33,14 +33,14 @@ import java.util.List; import java.util.Optional; import static org.hamcrest.CoreMatchers.containsString; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.empty; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.ArgumentMatchers.anyCollection; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.nullable; @@ -73,13 +73,13 @@ public class ValueSetExpansionR4Test extends BaseTermR4Test { ValueSet expandedValueSet = myTermSvc.expandValueSet(null, valueSet); assertEquals(24, expandedValueSet.getExpansion().getContains().size()); - runInTransaction(()->{ + runInTransaction(() -> { assertEquals(24, myTermValueSetConceptDao.count()); }); myValueSetDao.delete(valueSet.getIdElement()); - runInTransaction(()->{ + runInTransaction(() -> { assertEquals(0, myTermValueSetConceptDao.count()); }); @@ -560,11 +560,11 @@ public class ValueSetExpansionR4Test extends BaseTermR4Test { assertEquals(codeSystem.getConcept().size(), expandedValueSet.getExpansion().getTotal()); assertEquals(myDaoConfig.getPreExpandValueSetsDefaultOffset(), expandedValueSet.getExpansion().getOffset()); - assertEquals(expanded, 2, expandedValueSet.getExpansion().getParameter().size()); - assertEquals(expanded, "offset", expandedValueSet.getExpansion().getParameter().get(0).getName()); - assertEquals(expanded, 0, expandedValueSet.getExpansion().getParameter().get(0).getValueIntegerType().getValue().intValue()); - assertEquals(expanded, "count", expandedValueSet.getExpansion().getParameter().get(1).getName()); - assertEquals(expanded, 0, expandedValueSet.getExpansion().getParameter().get(1).getValueIntegerType().getValue().intValue()); + assertEquals(2, expandedValueSet.getExpansion().getParameter().size(), expanded); + assertEquals("offset", expandedValueSet.getExpansion().getParameter().get(0).getName(), expanded); + assertEquals(0, expandedValueSet.getExpansion().getParameter().get(0).getValueIntegerType().getValue().intValue(), expanded); + assertEquals("count", expandedValueSet.getExpansion().getParameter().get(1).getName(), expanded); + assertEquals(0, expandedValueSet.getExpansion().getParameter().get(1).getValueIntegerType().getValue().intValue(), expanded); assertFalse(expandedValueSet.getExpansion().hasContains()); } 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 11a6ac336aa..1f16e0fbffb 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 @@ -1,26 +1,15 @@ package ca.uhn.fhir.jpa.testutil; -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; +import org.junit.jupiter.api.Test; 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")); // assertThat(text, not(containsString("OperationDefinition"))); } - + } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/util/CoordCalculatorTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/util/CoordCalculatorTest.java index 893ad55795b..794c53ed917 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/util/CoordCalculatorTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/util/CoordCalculatorTest.java @@ -1,11 +1,11 @@ package ca.uhn.fhir.jpa.util; import org.hibernate.search.spatial.impl.Point; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public class CoordCalculatorTest { private final Logger ourLog = LoggerFactory.getLogger(CoordCalculatorTest.class); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/util/HashFunctionTester.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/util/HashFunctionTester.java index 2de91e905bf..a26c1e06caa 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/util/HashFunctionTester.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/util/HashFunctionTester.java @@ -6,7 +6,7 @@ import com.google.common.hash.HashFunction; import com.google.common.hash.Hasher; import com.google.common.hash.Hashing; import com.helger.commons.base64.Base64; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/util/JpaClasspathTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/util/JpaClasspathTest.java index 0bb692cab7d..ae5c19e828b 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/util/JpaClasspathTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/util/JpaClasspathTest.java @@ -1,8 +1,8 @@ package ca.uhn.fhir.jpa.util; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.fail; public class JpaClasspathTest { @@ -16,7 +16,7 @@ public class JpaClasspathTest { try { Class.forName("org.apache.logging.log4j.status.StatusLogger"); fail("org.apache.logging.log4j.status.StatusLogger" + " found on classpath - Make sure log4j isn't being introduced"); - } catch (ClassNotFoundException theE) { + } catch (ClassNotFoundException e) { // good } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/util/ResourceCountCacheTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/util/ResourceCountCacheTest.java index d18606d5458..1d551f26ceb 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/util/ResourceCountCacheTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/util/ResourceCountCacheTest.java @@ -1,43 +1,40 @@ package ca.uhn.fhir.jpa.util; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import java.util.HashMap; import java.util.Map; import java.util.concurrent.Callable; import java.util.concurrent.atomic.AtomicLong; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.when; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class ResourceCountCacheTest { @Mock private Callable> myFetcher; - @After + @AfterEach public void after() { ResourceCountCache.setNowForUnitTest(null); } - @Before - public void before() throws Exception { + @Test + public void testCache() throws Exception { AtomicLong id = new AtomicLong(); when(myFetcher.call()).thenAnswer(t->{ Map retVal = new HashMap<>(); retVal.put("A", id.incrementAndGet()); return retVal; }); - } - @Test - public void testCache() { long start = System.currentTimeMillis(); ResourceCountCache.setNowForUnitTest(start); diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/util/jsonpatch/JsonPatchUtilsTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/util/jsonpatch/JsonPatchUtilsTest.java index 944ecfe8a43..059adf0234c 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/util/jsonpatch/JsonPatchUtilsTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/util/jsonpatch/JsonPatchUtilsTest.java @@ -1,24 +1,27 @@ package ca.uhn.fhir.jpa.util.jsonpatch; import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.context.FhirVersionEnum; import ca.uhn.fhir.jpa.dao.BaseJpaTest; import ca.uhn.fhir.jpa.patch.JsonPatchUtils; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; import org.hl7.fhir.r4.model.Observation; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.transaction.PlatformTransactionManager; import static org.hamcrest.CoreMatchers.containsString; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.not; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; public class JsonPatchUtilsTest extends BaseJpaTest { - private static final FhirContext ourCtx = FhirContext.forR4(); + private static final FhirContext ourCtx = FhirContext.forCached(FhirVersionEnum.R4); private static final Logger ourLog = LoggerFactory.getLogger(JsonPatchUtilsTest.class); + @SuppressWarnings("JsonStandardCompliance") @Test public void testInvalidPatchJsonError() { diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/z/ZContextCloserDstu2Test.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/z/ZContextCloserDstu2Test.java index 075a2cdb4af..1614fb2ae98 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/z/ZContextCloserDstu2Test.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/z/ZContextCloserDstu2Test.java @@ -1,6 +1,6 @@ package ca.uhn.fhir.jpa.z; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.test.annotation.DirtiesContext; import ca.uhn.fhir.jpa.dao.dstu2.BaseJpaDstu2Test; diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/validator/AttachmentUtilTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/validator/AttachmentUtilTest.java index 49ce3040de6..69b2b89b1b8 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/validator/AttachmentUtilTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/validator/AttachmentUtilTest.java @@ -1,17 +1,18 @@ package ca.uhn.fhir.validator; import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.context.FhirVersionEnum; import ca.uhn.fhir.util.AttachmentUtil; import org.hl7.fhir.instance.model.api.ICompositeType; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public class AttachmentUtilTest { @Test public void testCreateAttachmentDstu3() { - FhirContext ctx = FhirContext.forDstu3(); + FhirContext ctx = FhirContext.forCached(FhirVersionEnum.DSTU3); ICompositeType attachment = AttachmentUtil.newInstance(ctx); AttachmentUtil.setData(ctx, attachment, new byte[]{0, 1, 2, 3}); AttachmentUtil.setUrl(ctx, attachment, "http://foo"); @@ -26,7 +27,7 @@ public class AttachmentUtilTest { @Test public void testCreateAttachmentR4() { - FhirContext ctx = FhirContext.forR4(); + FhirContext ctx = FhirContext.forCached(FhirVersionEnum.R4); ICompositeType attachment = AttachmentUtil.newInstance(ctx); AttachmentUtil.setData(ctx, attachment, new byte[]{0, 1, 2, 3}); AttachmentUtil.setUrl(ctx, attachment, "http://foo"); @@ -41,7 +42,7 @@ public class AttachmentUtilTest { @Test public void testCreateAttachmentR5() { - FhirContext ctx = FhirContext.forR5(); + FhirContext ctx = FhirContext.forCached(FhirVersionEnum.R5); ICompositeType attachment = AttachmentUtil.newInstance(ctx); AttachmentUtil.setData(ctx, attachment, new byte[]{0, 1, 2, 3}); AttachmentUtil.setUrl(ctx, attachment, "http://foo"); 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 3a55268c859..347a7c70f2b 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 @@ -1,10 +1,11 @@ package ca.uhn.fhir.validator; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; +import ca.uhn.fhir.context.FhirVersionEnum; import org.hl7.fhir.common.hapi.validation.validator.FhirInstanceValidator; -import org.junit.AfterClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; import ca.uhn.fhir.context.ConfigurationException; import ca.uhn.fhir.context.FhirContext; @@ -20,14 +21,9 @@ 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 testWrongContextVersion() { - FhirContext ctxDstu2 = FhirContext.forDstu2(); + FhirContext ctxDstu2 = FhirContext.forCached(FhirVersionEnum.DSTU2); try { ctxDstu2.getResourceDefinition(org.hl7.fhir.dstu3.model.Patient.class); fail(); @@ -41,7 +37,7 @@ public class ValidatorAcrossVersionsTest { @Test public void testValidateProfileOnDstu2Resource() { - FhirContext ctxDstu2 = FhirContext.forDstu2(); + FhirContext ctxDstu2 = FhirContext.forCached(FhirVersionEnum.DSTU2); FhirValidator val = ctxDstu2.newValidator(); val.setValidateAgainstStandardSchema(false); val.setValidateAgainstStandardSchematron(false); diff --git a/hapi-fhir-jpaserver-empi/pom.xml b/hapi-fhir-jpaserver-empi/pom.xml index 7aad00751b1..7fcd22c274e 100644 --- a/hapi-fhir-jpaserver-empi/pom.xml +++ b/hapi-fhir-jpaserver-empi/pom.xml @@ -38,14 +38,30 @@ - ca.uhn.hapi.fhir - hapi-fhir-jpaserver-test-utilities - ${project.version} + org.awaitility + awaitility + test + + + org.springframework + spring-test + test + + + javax.servlet + javax.servlet-api test - org.awaitility - awaitility + ca.uhn.hapi.fhir + hapi-fhir-test-utilities + 5.1.0-SNAPSHOT + test + + + ca.uhn.hapi.fhir + hapi-fhir-jpaserver-test-utilities + 5.1.0-SNAPSHOT test diff --git a/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/BaseEmpiR4Test.java b/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/BaseEmpiR4Test.java index b025f78a6ad..876da1511f5 100644 --- a/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/BaseEmpiR4Test.java +++ b/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/BaseEmpiR4Test.java @@ -42,12 +42,12 @@ import org.hl7.fhir.r4.model.DateType; import org.hl7.fhir.r4.model.Patient; import org.hl7.fhir.r4.model.Person; import org.hl7.fhir.r4.model.Practitioner; -import org.junit.After; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.extension.ExtendWith; import org.slf4j.Logger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import javax.annotation.Nonnull; import java.util.Collections; @@ -55,20 +55,19 @@ import java.util.Date; import java.util.List; import java.util.Optional; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.slf4j.LoggerFactory.getLogger; -@RunWith(SpringRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = {EmpiSubmitterConfig.class, EmpiConsumerConfig.class, TestEmpiConfigR4.class, SubscriptionProcessorConfig.class}) abstract public class BaseEmpiR4Test extends BaseJpaR4Test { - private static final Logger ourLog = getLogger(BaseEmpiR4Test.class); - - protected static final String TEST_ID_SYSTEM = "http://a.tv/"; - protected static final String JANE_ID = "ID.JANE.123"; public static final String NAME_GIVEN_JANE = "Jane"; - protected static final String PAUL_ID = "ID.PAUL.456"; public static final String NAME_GIVEN_PAUL = "Paul"; public static final String TEST_NAME_FAMILY = "Doe"; + protected static final String TEST_ID_SYSTEM = "http://a.tv/"; + protected static final String JANE_ID = "ID.JANE.123"; + protected static final String PAUL_ID = "ID.PAUL.456"; + private static final Logger ourLog = getLogger(BaseEmpiR4Test.class); private static final ContactPoint TEST_TELECOM = new ContactPoint() .setSystem(ContactPoint.ContactPointSystem.PHONE) .setValue("555-555-5555"); @@ -103,7 +102,7 @@ abstract public class BaseEmpiR4Test extends BaseJpaR4Test { protected ServletRequestDetails myRequestDetails = new ServletRequestDetails(null); @Override - @After + @AfterEach public void after() { myEmpiLinkDao.deleteAll(); assertEquals(0, myEmpiLinkDao.count()); diff --git a/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/dao/EmpiLinkDaoSvcTest.java b/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/dao/EmpiLinkDaoSvcTest.java index 0209a4bb297..2aa081486af 100644 --- a/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/dao/EmpiLinkDaoSvcTest.java +++ b/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/dao/EmpiLinkDaoSvcTest.java @@ -5,15 +5,16 @@ import ca.uhn.fhir.jpa.dao.EmpiLinkDaoSvc; import ca.uhn.fhir.jpa.empi.BaseEmpiR4Test; import ca.uhn.fhir.jpa.entity.EmpiLink; import ca.uhn.fhir.jpa.util.TestUtil; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.nullValue; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; public class EmpiLinkDaoSvcTest extends BaseEmpiR4Test { @Autowired diff --git a/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/entity/EmpiEnumTest.java b/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/entity/EmpiEnumTest.java index 232161adcda..935375b7e74 100644 --- a/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/entity/EmpiEnumTest.java +++ b/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/entity/EmpiEnumTest.java @@ -2,9 +2,9 @@ package ca.uhn.fhir.jpa.empi.entity; import ca.uhn.fhir.empi.api.EmpiLinkSourceEnum; import ca.uhn.fhir.empi.api.EmpiMatchResultEnum; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public class EmpiEnumTest { @Test diff --git a/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/helper/BaseEmpiHelper.java b/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/helper/BaseEmpiHelper.java index 3bf98d4e006..fab4e3c4895 100644 --- a/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/helper/BaseEmpiHelper.java +++ b/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/helper/BaseEmpiHelper.java @@ -12,7 +12,9 @@ import ca.uhn.fhir.jpa.subscription.match.registry.SubscriptionRegistry; import ca.uhn.fhir.rest.server.RestfulServer; import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; import ca.uhn.test.concurrency.PointcutLatch; -import org.junit.rules.ExternalResource; +import org.junit.jupiter.api.extension.AfterEachCallback; +import org.junit.jupiter.api.extension.BeforeEachCallback; +import org.junit.jupiter.api.extension.ExtensionContext; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.springframework.beans.factory.annotation.Autowired; @@ -39,7 +41,7 @@ import static org.mockito.Mockito.when; * Note: all create/update functions take an optional isExternalHttpRequest boolean, to make it appear as though the request's * origin is an HTTP request. */ -public abstract class BaseEmpiHelper extends ExternalResource { +public abstract class BaseEmpiHelper implements BeforeEachCallback, AfterEachCallback { @Mock protected ServletRequestDetails myMockSrd; @Mock @@ -48,11 +50,7 @@ public abstract class BaseEmpiHelper extends ExternalResource { protected RestfulServer myMockRestfulServer; @Mock protected FhirContext myMockFhirContext; - @Mock - private IInterceptorBroadcaster myMockInterceptorBroadcaster; - - @Autowired - private IInterceptorService myInterceptorService; + protected PointcutLatch myAfterEmpiLatch = new PointcutLatch(Pointcut.EMPI_AFTER_PERSISTED_RESOURCE_CHECKED); @Autowired EmpiQueueConsumerLoader myEmpiQueueConsumerLoader; @Autowired @@ -61,12 +59,20 @@ public abstract class BaseEmpiHelper extends ExternalResource { SubscriptionLoader mySubscriptionLoader; @Autowired EmpiSubscriptionLoader myEmpiSubscriptionLoader; - - protected PointcutLatch myAfterEmpiLatch = new PointcutLatch(Pointcut.EMPI_AFTER_PERSISTED_RESOURCE_CHECKED); + @Mock + private IInterceptorBroadcaster myMockInterceptorBroadcaster; + @Autowired + private IInterceptorService myInterceptorService; @Override - protected void before() throws Throwable { - super.before(); + public void afterEach(ExtensionContext context) throws Exception { + myInterceptorService.unregisterInterceptor(myAfterEmpiLatch); + myAfterEmpiLatch.clear(); + waitUntilEmpiQueueIsEmpty(); + } + + @Override + public void beforeEach(ExtensionContext context) throws Exception { //This sets up mock servlet request details, which allows our DAO requests to appear as though //they are coming from an external HTTP Request. MockitoAnnotations.initMocks(this); @@ -86,17 +92,11 @@ public abstract class BaseEmpiHelper extends ExternalResource { waitForActivatedSubscriptionCount(2); } + protected void waitForActivatedSubscriptionCount(int theSize) { await("Active Subscription Count has reached " + theSize).until(() -> mySubscriptionRegistry.size() >= theSize); } - @Override - protected void after() { - myInterceptorService.unregisterInterceptor(myAfterEmpiLatch); - myAfterEmpiLatch.clear(); - waitUntilEmpiQueueIsEmpty(); - } - private void waitUntilEmpiQueueIsEmpty() { await().until(() -> getExecutorQueueSize() == 0); } diff --git a/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/interceptor/EmpiExpungeTest.java b/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/interceptor/EmpiExpungeTest.java index 4f12fdb295e..9a67b0bcb50 100644 --- a/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/interceptor/EmpiExpungeTest.java +++ b/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/interceptor/EmpiExpungeTest.java @@ -13,15 +13,15 @@ import ca.uhn.fhir.model.primitive.IdDt; import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; import org.hl7.fhir.r4.model.Patient; import org.hl7.fhir.r4.model.Person; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.StringContains.containsString; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; public class EmpiExpungeTest extends BaseEmpiR4Test { @@ -37,7 +37,7 @@ public class EmpiExpungeTest extends BaseEmpiR4Test { private ResourceTable myPersonEntity; private IdDt myTargetId; - @Before + @BeforeEach public void before() { myDaoConfig.setExpungeEnabled(true); @@ -72,7 +72,7 @@ public class EmpiExpungeTest extends BaseEmpiR4Test { assertEquals(0, myEmpiLinkDao.count()); } - @After + @AfterEach public void afterUnregisterInterceptor() { myInterceptorService.unregisterInterceptor(myEmpiStorageInterceptor); } diff --git a/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/interceptor/EmpiStorageInterceptorIT.java b/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/interceptor/EmpiStorageInterceptorIT.java index f4fad951889..038182c55b4 100644 --- a/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/interceptor/EmpiStorageInterceptorIT.java +++ b/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/interceptor/EmpiStorageInterceptorIT.java @@ -20,9 +20,9 @@ import org.hl7.fhir.r4.model.Organization; import org.hl7.fhir.r4.model.Patient; import org.hl7.fhir.r4.model.Person; import org.hl7.fhir.r4.model.Practitioner; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; import org.slf4j.Logger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.annotation.DirtiesContext; @@ -35,12 +35,12 @@ import static ca.uhn.fhir.empi.api.EmpiConstants.SYSTEM_EMPI_MANAGED; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.notNullValue; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.nullValue; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.fail; import static org.slf4j.LoggerFactory.getLogger; @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS) @@ -49,13 +49,13 @@ public class EmpiStorageInterceptorIT extends BaseEmpiR4Test { private static final Logger ourLog = getLogger(EmpiStorageInterceptorIT.class); - @Rule + @RegisterExtension @Autowired public EmpiHelperR4 myEmpiHelper; @Autowired private IdHelperService myIdHelperService; - @Before + @BeforeEach public void before() { super.loadEmpiSearchParameters(); } @@ -135,7 +135,7 @@ public class EmpiStorageInterceptorIT extends BaseEmpiR4Test { IBundleProvider search = myPersonDao.search(new SearchParameterMap().setLoadSynchronous(true)); List resources = search.getResources(0, search.size()); - for (IBaseResource person: resources) { + for (IBaseResource person : resources) { assertThat(person.getMeta().getTag(SYSTEM_EMPI_MANAGED, CODE_HAPI_EMPI_MANAGED), is(notNullValue())); } } @@ -153,7 +153,7 @@ public class EmpiStorageInterceptorIT extends BaseEmpiR4Test { myEmpiHelper.doUpdateResource(person, true); fail(); } catch (ForbiddenOperationException e) { - assertEquals("The HAPI-EMPI tag on a resource may not be changed once created.", e.getMessage() ); + assertEquals("The HAPI-EMPI tag on a resource may not be changed once created.", e.getMessage()); } } @@ -168,7 +168,7 @@ public class EmpiStorageInterceptorIT extends BaseEmpiR4Test { //Updating a Person who was created via EMPI should fail. EmpiLink empiLink = myEmpiLinkDaoSvc.getMatchedLinkForTargetPid(myIdHelperService.getPidOrNull(patient)).get(); Long personPid = empiLink.getPersonPid(); - Person empiPerson= (Person)myPersonDao.readByPid(new ResourcePersistentId(personPid)); + Person empiPerson = (Person) myPersonDao.readByPid(new ResourcePersistentId(personPid)); empiPerson.setGender(Enumerations.AdministrativeGender.MALE); try { myEmpiHelper.doUpdateResource(empiPerson, true); @@ -177,7 +177,7 @@ public class EmpiStorageInterceptorIT extends BaseEmpiR4Test { assertEquals("Cannot create or modify Resources that are managed by EMPI.", e.getMessage()); } } - + @Test public void testEmpiPointcutReceivesTransactionLogMessages() throws InterruptedException { EmpiHelperR4.OutcomeAndLogMessageWrapper wrapper = myEmpiHelper.createWithLatch(buildJanePatient()); @@ -205,6 +205,7 @@ public class EmpiStorageInterceptorIT extends BaseEmpiR4Test { assertThat(externalEids, hasSize(1)); assertThat("some_new_eid", is(equalTo(externalEids.get(0).getValue()))); } + @Test public void testWhenEidUpdatesAreDisabledForbidsUpdatesToEidsOnTargets() throws InterruptedException { setPreventEidUpdates(true); @@ -240,11 +241,11 @@ public class EmpiStorageInterceptorIT extends BaseEmpiR4Test { } private void setPreventEidUpdates(boolean thePrevent) { - ((EmpiSettings)myEmpiConfig).setPreventEidUpdates(thePrevent); + ((EmpiSettings) myEmpiConfig).setPreventEidUpdates(thePrevent); } private void setPreventMultipleEids(boolean thePrevent) { - ((EmpiSettings)myEmpiConfig).setPreventMultipleEids(thePrevent); + ((EmpiSettings) myEmpiConfig).setPreventMultipleEids(thePrevent); } } diff --git a/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/provider/BaseLinkR4Test.java b/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/provider/BaseLinkR4Test.java index 38a610678f7..2fa6191ceab 100644 --- a/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/provider/BaseLinkR4Test.java +++ b/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/provider/BaseLinkR4Test.java @@ -6,12 +6,12 @@ import ca.uhn.fhir.jpa.entity.EmpiLink; import org.hl7.fhir.r4.model.Patient; import org.hl7.fhir.r4.model.Person; import org.hl7.fhir.r4.model.StringType; -import org.junit.Before; +import org.junit.jupiter.api.BeforeEach; import javax.annotation.Nonnull; import java.util.List; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public abstract class BaseLinkR4Test extends BaseProviderR4Test { protected static final StringType NO_MATCH_RESULT = new StringType(EmpiMatchResultEnum.NO_MATCH.name()); @@ -27,7 +27,8 @@ public abstract class BaseLinkR4Test extends BaseProviderR4Test { protected StringType myVersionlessPersonId; - @Before + @Override + @BeforeEach public void before() { super.before(); diff --git a/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/provider/BaseProviderR4Test.java b/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/provider/BaseProviderR4Test.java index ef4e72d79bc..d1848efb3c8 100644 --- a/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/provider/BaseProviderR4Test.java +++ b/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/provider/BaseProviderR4Test.java @@ -7,10 +7,11 @@ import ca.uhn.fhir.empi.api.IEmpiPersonMergerSvc; import ca.uhn.fhir.empi.provider.EmpiProviderR4; import ca.uhn.fhir.jpa.empi.BaseEmpiR4Test; import ca.uhn.fhir.validation.IResourceLoader; -import org.junit.Before; +import org.junit.jupiter.api.BeforeEach; import org.springframework.beans.factory.annotation.Autowired; public abstract class BaseProviderR4Test extends BaseEmpiR4Test { + EmpiProviderR4 myEmpiProviderR4; @Autowired private IEmpiMatchFinderSvc myEmpiMatchFinderSvc; @Autowired @@ -22,9 +23,7 @@ public abstract class BaseProviderR4Test extends BaseEmpiR4Test { @Autowired private IResourceLoader myResourceLoader; - EmpiProviderR4 myEmpiProviderR4; - - @Before + @BeforeEach public void before() { myEmpiProviderR4 = new EmpiProviderR4(myFhirContext, myEmpiMatchFinderSvc, myPersonMergerSvc, myEmpiLinkUpdaterSvc, myEmpiLinkQuerySvc, myResourceLoader); } diff --git a/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/provider/EmpiProviderMergePersonsR4Test.java b/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/provider/EmpiProviderMergePersonsR4Test.java index fa9283cb998..7c3d4068e5e 100644 --- a/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/provider/EmpiProviderMergePersonsR4Test.java +++ b/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/provider/EmpiProviderMergePersonsR4Test.java @@ -9,16 +9,16 @@ import org.hl7.fhir.r4.model.Bundle; import org.hl7.fhir.r4.model.Patient; import org.hl7.fhir.r4.model.Person; import org.hl7.fhir.r4.model.StringType; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.util.List; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; public class EmpiProviderMergePersonsR4Test extends BaseProviderR4Test { @@ -27,7 +27,8 @@ public class EmpiProviderMergePersonsR4Test extends BaseProviderR4Test { private Person myToPerson; private StringType myToPersonId; - @Before + @Override + @BeforeEach public void before() { super.before(); super.loadEmpiSearchParameters(); diff --git a/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/provider/EmpiProviderQueryLinkR4Test.java b/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/provider/EmpiProviderQueryLinkR4Test.java index ba86ca7f11c..99a9181488a 100644 --- a/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/provider/EmpiProviderQueryLinkR4Test.java +++ b/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/provider/EmpiProviderQueryLinkR4Test.java @@ -11,8 +11,8 @@ import org.hl7.fhir.r4.model.Parameters; import org.hl7.fhir.r4.model.Patient; import org.hl7.fhir.r4.model.Person; import org.hl7.fhir.r4.model.StringType; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -21,9 +21,9 @@ import java.util.List; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; public class EmpiProviderQueryLinkR4Test extends BaseLinkR4Test { private static final Logger ourLog = LoggerFactory.getLogger(EmpiProviderQueryLinkR4Test.class); @@ -31,7 +31,8 @@ public class EmpiProviderQueryLinkR4Test extends BaseLinkR4Test { private StringType myPerson1Id; private StringType myPerson2Id; - @Before + @Override + @BeforeEach public void before() { super.before(); diff --git a/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/provider/EmpiProviderUpdateLinkR4Test.java b/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/provider/EmpiProviderUpdateLinkR4Test.java index 83fbc3d2456..63ed1199852 100644 --- a/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/provider/EmpiProviderUpdateLinkR4Test.java +++ b/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/provider/EmpiProviderUpdateLinkR4Test.java @@ -9,7 +9,7 @@ import ca.uhn.fhir.rest.server.exceptions.ResourceVersionConflictException; import org.hl7.fhir.r4.model.Patient; import org.hl7.fhir.r4.model.Person; import org.hl7.fhir.r4.model.StringType; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.List; @@ -17,9 +17,9 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.endsWith; import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.matchesPattern; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.fail; public class EmpiProviderUpdateLinkR4Test extends BaseLinkR4Test { @Test diff --git a/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/searchparam/SearchParameterTest.java b/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/searchparam/SearchParameterTest.java index ee404d36302..13a708594e5 100644 --- a/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/searchparam/SearchParameterTest.java +++ b/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/searchparam/SearchParameterTest.java @@ -6,21 +6,21 @@ import ca.uhn.fhir.rest.api.server.IBundleProvider; import ca.uhn.fhir.rest.param.TokenParam; import org.hl7.fhir.r4.model.Patient; import org.hl7.fhir.r4.model.Person; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.util.List; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; public class SearchParameterTest extends BaseEmpiR4Test { private static final Logger ourLog = LoggerFactory.getLogger(SearchParameterTest.class); - @Before + @BeforeEach public void before() { super.loadEmpiSearchParameters(); } @@ -30,11 +30,11 @@ public class SearchParameterTest extends BaseEmpiR4Test { // Create a possible match Patient patient = buildJanePatient(); patient.getNameFirstRep().setFamily("familyone"); - patient = createPatientAndUpdateLinks(patient); + patient = createPatientAndUpdateLinks(patient); Patient patient2 = buildJanePatient(); patient2.getNameFirstRep().setFamily("pleasedonotmatchatall"); - patient2 = createPatientAndUpdateLinks(patient2); + patient2 = createPatientAndUpdateLinks(patient2); assertThat(patient2, is(possibleMatchWith(patient))); // Now confirm we can find it using our custom search parameter diff --git a/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/svc/EmpiCandidateSearchCriteriaBuilderSvcTest.java b/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/svc/EmpiCandidateSearchCriteriaBuilderSvcTest.java index 93c34614a57..e9311c9bc33 100644 --- a/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/svc/EmpiCandidateSearchCriteriaBuilderSvcTest.java +++ b/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/svc/EmpiCandidateSearchCriteriaBuilderSvcTest.java @@ -4,7 +4,7 @@ import ca.uhn.fhir.empi.rules.json.EmpiResourceSearchParamJson; import ca.uhn.fhir.jpa.empi.BaseEmpiR4Test; import org.hl7.fhir.r4.model.HumanName; import org.hl7.fhir.r4.model.Patient; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import java.util.Collections; @@ -13,9 +13,9 @@ import java.util.Optional; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.anyOf; import static org.hamcrest.Matchers.equalTo; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; public class EmpiCandidateSearchCriteriaBuilderSvcTest extends BaseEmpiR4Test { @Autowired diff --git a/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/svc/EmpiCandidateSearchSvcTest.java b/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/svc/EmpiCandidateSearchSvcTest.java index b916bbe9300..c8b908478d2 100644 --- a/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/svc/EmpiCandidateSearchSvcTest.java +++ b/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/svc/EmpiCandidateSearchSvcTest.java @@ -5,7 +5,7 @@ import org.hl7.fhir.instance.model.api.IAnyResource; import org.hl7.fhir.r4.model.Patient; import org.hl7.fhir.r4.model.Practitioner; import org.hl7.fhir.r4.model.Reference; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import java.util.Collection; @@ -14,7 +14,7 @@ import java.util.Date; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.collection.IsCollectionWithSize.hasSize; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public class EmpiCandidateSearchSvcTest extends BaseEmpiR4Test { diff --git a/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/svc/EmpiLinkSvcTest.java b/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/svc/EmpiLinkSvcTest.java index a9047326dd5..4bb1fd922a0 100644 --- a/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/svc/EmpiLinkSvcTest.java +++ b/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/svc/EmpiLinkSvcTest.java @@ -9,24 +9,24 @@ import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; import org.hl7.fhir.r4.model.IdType; import org.hl7.fhir.r4.model.Patient; import org.hl7.fhir.r4.model.Person; -import org.junit.After; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; public class EmpiLinkSvcTest extends BaseEmpiR4Test { @Autowired IEmpiLinkSvc myEmpiLinkSvc; @Override - @After + @AfterEach public void after() { myExpungeEverythingService.expungeEverythingByType(EmpiLink.class); super.after(); diff --git a/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/svc/EmpiMatchLinkSvcMultipleEidModeTest.java b/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/svc/EmpiMatchLinkSvcMultipleEidModeTest.java index 3f8db3f40fb..efdaeb92edb 100644 --- a/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/svc/EmpiMatchLinkSvcMultipleEidModeTest.java +++ b/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/svc/EmpiMatchLinkSvcMultipleEidModeTest.java @@ -8,8 +8,8 @@ import ca.uhn.fhir.jpa.entity.EmpiLink; import org.hl7.fhir.r4.model.Identifier; import org.hl7.fhir.r4.model.Patient; import org.hl7.fhir.r4.model.Person; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.TestPropertySource; @@ -18,12 +18,12 @@ import java.util.List; import java.util.stream.Collectors; import java.util.stream.Stream; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.in; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.not; -import static org.junit.Assert.assertThat; import static org.slf4j.LoggerFactory.getLogger; @TestPropertySource(properties = { @@ -34,7 +34,7 @@ public class EmpiMatchLinkSvcMultipleEidModeTest extends BaseEmpiR4Test { @Autowired private EIDHelper myEidHelper; - @Before + @BeforeEach public void before() { super.loadEmpiSearchParameters(); } @@ -168,8 +168,8 @@ public class EmpiMatchLinkSvcMultipleEidModeTest extends BaseEmpiR4Test { patient2 = updatePatientAndUpdateLinks(patient2); assertThat(patient2, is(not(matchedToAPerson()))); - assertThat(patient2,is(possibleMatchWith(patient1))); - assertThat(patient2,is(possibleMatchWith(patient3))); + assertThat(patient2, is(possibleMatchWith(patient1))); + assertThat(patient2, is(possibleMatchWith(patient3))); List possibleDuplicates = myEmpiLinkDaoSvc.getPossibleDuplicates(); assertThat(possibleDuplicates, hasSize(1)); diff --git a/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/svc/EmpiMatchLinkSvcTest.java b/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/svc/EmpiMatchLinkSvcTest.java index b5e403d0625..636ab804be2 100644 --- a/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/svc/EmpiMatchLinkSvcTest.java +++ b/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/svc/EmpiMatchLinkSvcTest.java @@ -18,8 +18,8 @@ import org.hl7.fhir.r4.model.Identifier; import org.hl7.fhir.r4.model.Patient; import org.hl7.fhir.r4.model.Person; import org.hl7.fhir.r4.model.Practitioner; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.springframework.beans.factory.annotation.Autowired; @@ -29,6 +29,7 @@ import java.util.Optional; import java.util.stream.Collectors; import java.util.stream.Stream; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.blankOrNullString; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.equalToIgnoringCase; @@ -36,7 +37,6 @@ import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.in; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.not; -import static org.junit.Assert.assertThat; import static org.slf4j.LoggerFactory.getLogger; public class EmpiMatchLinkSvcTest extends BaseEmpiR4Test { @@ -48,7 +48,7 @@ public class EmpiMatchLinkSvcTest extends BaseEmpiR4Test { @Autowired private PersonHelper myPersonHelper; - @Before + @BeforeEach public void before() { super.loadEmpiSearchParameters(); } @@ -83,10 +83,10 @@ public class EmpiMatchLinkSvcTest extends BaseEmpiR4Test { public void testWhenMatchOccursOnPersonThatHasBeenManuallyNOMATCHedThatItIsBlocked() { Patient originalJane = createPatientAndUpdateLinks(buildJanePatient()); IBundleProvider search = myPersonDao.search(new SearchParameterMap()); - IAnyResource janePerson = (IAnyResource) search.getResources(0,1).get(0); + IAnyResource janePerson = (IAnyResource) search.getResources(0, 1).get(0); //Create a manual NO_MATCH between janePerson and unmatchedJane. - Patient unmatchedJane= createPatient(buildJanePatient()); + Patient unmatchedJane = createPatient(buildJanePatient()); myEmpiLinkSvc.updateLink(janePerson, unmatchedJane, EmpiMatchResultEnum.NO_MATCH, EmpiLinkSourceEnum.MANUAL, createContextForCreate()); //rerun EMPI rules against unmatchedJane. @@ -166,7 +166,7 @@ public class EmpiMatchLinkSvcTest extends BaseEmpiR4Test { } @Test - public void testIncomingPatientWithEIDThatMatchesPersonWithHapiEidAddsExternalEidToPerson(){ + public void testIncomingPatientWithEIDThatMatchesPersonWithHapiEidAddsExternalEidToPerson() { // Existing Person with system-assigned EID found linked from matched Patient. incoming Patient has EID. Replace Person system-assigned EID with Patient EID. Patient patient = createPatientAndUpdateLinks(buildJanePatient()); @@ -174,7 +174,7 @@ public class EmpiMatchLinkSvcTest extends BaseEmpiR4Test { List hapiEid = myEidHelper.getHapiEid(janePerson); String foundHapiEid = hapiEid.get(0).getValue(); - Patient janePatient= addExternalEID(buildJanePatient(), "12345"); + Patient janePatient = addExternalEID(buildJanePatient(), "12345"); createPatientAndUpdateLinks(janePatient); //We want to make sure the patients were linked to the same person. @@ -205,6 +205,7 @@ public class EmpiMatchLinkSvcTest extends BaseEmpiR4Test { assertThat(patient1, is(samePersonAs(patient2))); } + @Test public void testHavingMultipleEIDsOnIncomingPatientMatchesCorrectly() { @@ -275,7 +276,7 @@ public class EmpiMatchLinkSvcTest extends BaseEmpiR4Test { } @Test - public void testWhenThereAreNoMATCHOrPOSSIBLE_MATCHOutcomesThatANewPersonIsCreated(){ + public void testWhenThereAreNoMATCHOrPOSSIBLE_MATCHOutcomesThatANewPersonIsCreated() { /** * CASE 1: No MATCHED and no PROBABLE_MATCHED outcomes -> a new Person resource * is created and linked to that Pat/Prac. @@ -287,7 +288,7 @@ public class EmpiMatchLinkSvcTest extends BaseEmpiR4Test { } @Test - public void testWhenAllMATCHResultsAreToSamePersonThatTheyAreLinked(){ + public void testWhenAllMATCHResultsAreToSamePersonThatTheyAreLinked() { /** * CASE 2: All of the MATCHED Pat/Prac resources are already linked to the same Person -> * a new Link is created between the new Pat/Prac and that Person and is set to MATCHED. @@ -304,7 +305,7 @@ public class EmpiMatchLinkSvcTest extends BaseEmpiR4Test { } @Test - public void testMATCHResultWithMultipleCandidatesCreatesPOSSIBLE_DUPLICATELinksAndNoPersonIsCreated(){ + public void testMATCHResultWithMultipleCandidatesCreatesPOSSIBLE_DUPLICATELinksAndNoPersonIsCreated() { /** * CASE 3: The MATCHED Pat/Prac resources link to more than one Person -> Mark all links as POSSIBLE_MATCH. * All other Person resources are marked as POSSIBLE_DUPLICATE of this first Person. @@ -334,25 +335,25 @@ public class EmpiMatchLinkSvcTest extends BaseEmpiR4Test { } @Test - public void testWhenAllMatchResultsArePOSSIBLE_MATCHThattheyAreLinkedAndNoPersonIsCreated(){ + public void testWhenAllMatchResultsArePOSSIBLE_MATCHThattheyAreLinkedAndNoPersonIsCreated() { /** * CASE 4: Only POSSIBLE_MATCH outcomes -> In this case, empi-link records are created with POSSIBLE_MATCH * outcome and await manual assignment to either NO_MATCH or MATCHED. Person resources are not changed. */ Patient patient = buildJanePatient(); patient.getNameFirstRep().setFamily("familyone"); - patient = createPatientAndUpdateLinks(patient); + patient = createPatientAndUpdateLinks(patient); assertThat(patient, is(samePersonAs(patient))); Patient patient2 = buildJanePatient(); patient2.getNameFirstRep().setFamily("pleasedonotmatchatall"); - patient2 = createPatientAndUpdateLinks(patient2); + patient2 = createPatientAndUpdateLinks(patient2); assertThat(patient2, is(possibleMatchWith(patient))); Patient patient3 = buildJanePatient(); patient3.getNameFirstRep().setFamily("pleasedonotmatchatall"); - patient3 = createPatientAndUpdateLinks(patient3); + patient3 = createPatientAndUpdateLinks(patient3); assertThat(patient3, is(possibleMatchWith(patient2))); assertThat(patient3, is(possibleMatchWith(patient))); @@ -362,16 +363,16 @@ public class EmpiMatchLinkSvcTest extends BaseEmpiR4Test { public void testWhenAnIncomingResourceHasMatchesAndPossibleMatchesThatItLinksToMatch() { Patient patient = buildJanePatient(); patient.getNameFirstRep().setFamily("familyone"); - patient = createPatientAndUpdateLinks(patient); + patient = createPatientAndUpdateLinks(patient); assertThat(patient, is(samePersonAs(patient))); Patient patient2 = buildJanePatient(); patient2.getNameFirstRep().setFamily("pleasedonotmatchatall"); - patient2 = createPatientAndUpdateLinks(patient2); + patient2 = createPatientAndUpdateLinks(patient2); Patient patient3 = buildJanePatient(); patient3.getNameFirstRep().setFamily("familyone"); - patient3 = createPatientAndUpdateLinks(patient3); + patient3 = createPatientAndUpdateLinks(patient3); assertThat(patient2, is(not(samePersonAs(patient)))); assertThat(patient2, is(possibleMatchWith(patient))); @@ -404,7 +405,7 @@ public class EmpiMatchLinkSvcTest extends BaseEmpiR4Test { //Case #1 @Test public void testPatientUpdateOverwritesPersonDataOnChanges() { - Patient janePatient= createPatientAndUpdateLinks(buildJanePatient()); + Patient janePatient = createPatientAndUpdateLinks(buildJanePatient()); Person janePerson = getPersonFromTarget(janePatient); //Change Jane's name to paul. @@ -436,7 +437,7 @@ public class EmpiMatchLinkSvcTest extends BaseEmpiR4Test { assertThat(paul2, is(samePersonAs(paul))); //Newly matched patients aren't allowed to overwrite Person Attributes unless they are empty, so gender should still be set to male. - Person paul2Person= getPersonFromTarget(paul2); + Person paul2Person = getPersonFromTarget(paul2); assertThat(paul2Person.getGender(), is(equalTo(Enumerations.AdministrativeGender.MALE))); } diff --git a/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/svc/EmpiPersonMergerSvcTest.java b/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/svc/EmpiPersonMergerSvcTest.java index 65798826787..7bba1f537cd 100644 --- a/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/svc/EmpiPersonMergerSvcTest.java +++ b/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/svc/EmpiPersonMergerSvcTest.java @@ -19,9 +19,9 @@ import org.hl7.fhir.r4.model.IdType; import org.hl7.fhir.r4.model.Patient; import org.hl7.fhir.r4.model.Person; import org.hl7.fhir.r4.model.Reference; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import java.util.Collections; @@ -29,10 +29,10 @@ import java.util.List; import java.util.UUID; import static org.hamcrest.Matchers.hasSize; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; public class EmpiPersonMergerSvcTest extends BaseEmpiR4Test { public static final String GIVEN_NAME = "Jenn"; @@ -57,7 +57,7 @@ public class EmpiPersonMergerSvcTest extends BaseEmpiR4Test { private Patient myTargetPatient2; private Patient myTargetPatient3; - @Before + @BeforeEach public void before() { super.loadEmpiSearchParameters(); @@ -79,7 +79,7 @@ public class EmpiPersonMergerSvcTest extends BaseEmpiR4Test { } @Override - @After + @AfterEach public void after() { myInterceptorService.unregisterInterceptor(myEmpiStorageInterceptor); super.after(); diff --git a/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/svc/EmpiResourceDaoSvcTest.java b/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/svc/EmpiResourceDaoSvcTest.java index ac0ee6943fb..35ebf5723ec 100644 --- a/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/svc/EmpiResourceDaoSvcTest.java +++ b/hapi-fhir-jpaserver-empi/src/test/java/ca/uhn/fhir/jpa/empi/svc/EmpiResourceDaoSvcTest.java @@ -3,22 +3,22 @@ package ca.uhn.fhir.jpa.empi.svc; import ca.uhn.fhir.jpa.empi.BaseEmpiR4Test; import org.hl7.fhir.instance.model.api.IAnyResource; import org.hl7.fhir.r4.model.Person; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import java.util.Optional; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; public class EmpiResourceDaoSvcTest extends BaseEmpiR4Test { private static final String TEST_EID = "TEST_EID"; @Autowired EmpiResourceDaoSvc myResourceDaoSvc; - @Before + @BeforeEach public void before() { super.loadEmpiSearchParameters(); } diff --git a/hapi-fhir-jpaserver-migrate/pom.xml b/hapi-fhir-jpaserver-migrate/pom.xml index e5e55485c56..b01c017ec53 100644 --- a/hapi-fhir-jpaserver-migrate/pom.xml +++ b/hapi-fhir-jpaserver-migrate/pom.xml @@ -58,11 +58,6 @@ derbytools test - - junit - junit - test - ch.qos.logback logback-classic diff --git a/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/MigrationTaskSkipperTest.java b/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/MigrationTaskSkipperTest.java index f8b2473afda..60a86eead8b 100644 --- a/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/MigrationTaskSkipperTest.java +++ b/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/MigrationTaskSkipperTest.java @@ -2,8 +2,8 @@ package ca.uhn.fhir.jpa.migrate; import ca.uhn.fhir.jpa.migrate.taskdef.BaseTask; import ca.uhn.fhir.jpa.migrate.taskdef.DropIndexTask; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import javax.annotation.Nonnull; import java.util.ArrayList; @@ -13,7 +13,7 @@ import java.util.stream.Collectors; import java.util.stream.Stream; import static org.hamcrest.Matchers.equalTo; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; public class MigrationTaskSkipperTest { public static final String RELEASE = "4_1_0"; @@ -21,7 +21,7 @@ public class MigrationTaskSkipperTest { private static final String VERSION_PREFIX = RELEASE + "." + DATE_PREFIX; private List myTasks; - @Before + @BeforeEach public void before() { myTasks = new ArrayList<>(); myTasks.add(new DropIndexTask(RELEASE, DATE_PREFIX + 1)); diff --git a/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/SchemaMigratorTest.java b/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/SchemaMigratorTest.java index 79d296a6cf1..0b54d0c5f1d 100644 --- a/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/SchemaMigratorTest.java +++ b/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/SchemaMigratorTest.java @@ -7,7 +7,8 @@ import ca.uhn.fhir.jpa.migrate.taskdef.BaseTest; import com.google.common.collect.ImmutableList; import org.flywaydb.core.api.FlywayException; import org.hamcrest.Matchers; -import org.junit.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import javax.annotation.Nonnull; import java.sql.SQLException; @@ -17,20 +18,20 @@ import java.util.function.Supplier; import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.CoreMatchers.startsWith; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.endsWith; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; public class SchemaMigratorTest extends BaseTest { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(SchemaMigratorTest.class); - public SchemaMigratorTest(Supplier theTestDatabaseDetails) { - super(theTestDatabaseDetails); - } - @Test - public void testMigrationRequired() { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("data") + public void testMigrationRequired(Supplier theTestDatabaseDetails) { + before(theTestDatabaseDetails); + SchemaMigrator schemaMigrator = createTableMigrator(); try { @@ -47,8 +48,11 @@ public class SchemaMigratorTest extends BaseTest { } - @Test - public void testRepairFailedMigration() { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("data") + public void testRepairFailedMigration(Supplier theTestDatabaseDetails) { + before(theTestDatabaseDetails); + SchemaMigrator schemaMigrator = createSchemaMigrator("SOMETABLE", "create fable SOMETABLE (PID bigint not null, TEXTCOL varchar(255))", "1"); try { schemaMigrator.migrate(); @@ -60,12 +64,15 @@ public class SchemaMigratorTest extends BaseTest { schemaMigrator.migrate(); } - @Test - public void testOutOfOrderMigration() { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("data") + public void testOutOfOrderMigration(Supplier theTestDatabaseDetails) { + before(theTestDatabaseDetails); + SchemaMigrator schemaMigrator = createSchemaMigrator("SOMETABLE", "create table SOMETABLE (PID bigint not null, TEXTCOL varchar(255))", "2"); schemaMigrator.migrate(); - schemaMigrator = createSchemaMigrator("SOMETABLE" ,"create table SOMEOTHERTABLE (PID bigint not null, TEXTCOL varchar(255))", "1"); + schemaMigrator = createSchemaMigrator("SOMETABLE", "create table SOMEOTHERTABLE (PID bigint not null, TEXTCOL varchar(255))", "1"); try { schemaMigrator.migrate(); @@ -77,8 +84,11 @@ public class SchemaMigratorTest extends BaseTest { schemaMigrator.migrate(); } - @Test - public void testSkipSchemaVersion() throws SQLException { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("data") + public void testSkipSchemaVersion(Supplier theTestDatabaseDetails) throws SQLException { + before(theTestDatabaseDetails); + AddTableRawSqlTask taskA = new AddTableRawSqlTask("V4_1_0", "20191214.1"); taskA.setTableName("SOMETABLE_A"); taskA.addSql(getDriverType(), "create table SOMETABLE_A (PID bigint not null, TEXTCOL varchar(255))"); @@ -107,8 +117,11 @@ public class SchemaMigratorTest extends BaseTest { assertThat(tableNames, Matchers.containsInAnyOrder("SOMETABLE_A", "SOMETABLE_C")); } - @Test - public void testMigrationRequiredNoFlyway() throws SQLException { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("data") + public void testMigrationRequiredNoFlyway(Supplier theTestDatabaseDetails) throws SQLException { + before(theTestDatabaseDetails); + SchemaMigrator schemaMigrator = createTableMigrator(); schemaMigrator.setDriverType(getDriverType()); schemaMigrator.setDontUseFlyway(true); diff --git a/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/AddColumnTest.java b/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/AddColumnTest.java index 7253e51b4ea..2a30b087295 100644 --- a/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/AddColumnTest.java +++ b/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/AddColumnTest.java @@ -4,24 +4,24 @@ import ca.uhn.fhir.jpa.migrate.JdbcUtils; import ca.uhn.fhir.jpa.migrate.tasks.api.BaseMigrationTasks; import ca.uhn.fhir.util.VersionEnum; import org.flywaydb.core.internal.command.DbMigrate; -import org.junit.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import java.sql.SQLException; import java.util.function.Supplier; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsInAnyOrder; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; public class AddColumnTest extends BaseTest { - public AddColumnTest(Supplier theTestDatabaseDetails) { - super(theTestDatabaseDetails); - } + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("data") + public void testColumnDoesntAlreadyExist(Supplier theTestDatabaseDetails) throws SQLException { + before(theTestDatabaseDetails); - @Test - public void testColumnDoesntAlreadyExist() throws SQLException { executeSql("create table SOMETABLE (PID bigint not null, TEXTCOL varchar(255))"); AddColumnTask task = new AddColumnTask("1", "1"); @@ -36,8 +36,11 @@ public class AddColumnTest extends BaseTest { assertThat(JdbcUtils.getColumnNames(getConnectionProperties(), "SOMETABLE"), containsInAnyOrder("PID", "TEXTCOL", "NEWCOL")); } - @Test - public void testAddColumnInt() throws SQLException { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("data") + public void testAddColumnInt(Supplier theTestDatabaseDetails) throws SQLException { + before(theTestDatabaseDetails); + executeSql("create table SOMETABLE (PID bigint not null, TEXTCOL varchar(255))"); AddColumnTask task = new AddColumnTask("1", "1"); @@ -53,8 +56,11 @@ public class AddColumnTest extends BaseTest { assertEquals(ColumnTypeEnum.INT, type.getColumnTypeEnum()); } - @Test - public void testColumnAlreadyExists() throws SQLException { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("data") + public void testColumnAlreadyExists(Supplier theTestDatabaseDetails) throws SQLException { + before(theTestDatabaseDetails); + executeSql("create table SOMETABLE (PID bigint not null, TEXTCOL varchar(255), newcol bigint)"); AddColumnTask task = new AddColumnTask("1", "1"); @@ -68,8 +74,11 @@ public class AddColumnTest extends BaseTest { assertThat(JdbcUtils.getColumnNames(getConnectionProperties(), "SOMETABLE"), containsInAnyOrder("PID", "TEXTCOL", "NEWCOL")); } - @Test - public void testAddColumnToNonExistantTable_Failing() { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("data") + public void testAddColumnToNonExistantTable_Failing(Supplier theTestDatabaseDetails) { + before(theTestDatabaseDetails); + BaseMigrationTasks tasks = new BaseMigrationTasks<>(); tasks .forVersion(VersionEnum.V4_0_0) @@ -88,8 +97,11 @@ public class AddColumnTest extends BaseTest { } - @Test - public void testAddColumnToNonExistantTable_FailureAllowed() { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("data") + public void testAddColumnToNonExistantTable_FailureAllowed(Supplier theTestDatabaseDetails) { + before(theTestDatabaseDetails); + BaseMigrationTasks tasks = new BaseMigrationTasks<>(); tasks .forVersion(VersionEnum.V4_0_0) diff --git a/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/AddForeignKeyTaskTest.java b/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/AddForeignKeyTaskTest.java index c06f96a60d8..4cde5b886bc 100644 --- a/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/AddForeignKeyTaskTest.java +++ b/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/AddForeignKeyTaskTest.java @@ -2,22 +2,24 @@ package ca.uhn.fhir.jpa.migrate.taskdef; import ca.uhn.fhir.jpa.migrate.JdbcUtils; import org.hamcrest.Matchers; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import java.sql.SQLException; import java.util.function.Supplier; import static org.hamcrest.Matchers.empty; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; public class AddForeignKeyTaskTest extends BaseTest { - public AddForeignKeyTaskTest(Supplier theTestDatabaseDetails) { - super(theTestDatabaseDetails); - } - @Test - public void testAddForeignKey() throws SQLException { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("data") + public void testAddForeignKey(Supplier theTestDatabaseDetails) throws SQLException { + before(theTestDatabaseDetails); + executeSql("create table HOME (PID bigint not null, TEXTCOL varchar(255), primary key (PID))"); executeSql("create table FOREIGNTBL (PID bigint not null, HOMEREF bigint)"); assertThat(JdbcUtils.getForeignKeys(getConnectionProperties(), "HOME", "FOREIGNTBL"), empty()); diff --git a/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/AddIdGeneratorTaskTest.java b/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/AddIdGeneratorTaskTest.java index 5ac110a7e11..e3d8aefbf59 100644 --- a/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/AddIdGeneratorTaskTest.java +++ b/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/AddIdGeneratorTaskTest.java @@ -4,24 +4,24 @@ import ca.uhn.fhir.jpa.migrate.JdbcUtils; import ca.uhn.fhir.jpa.migrate.tasks.api.BaseMigrationTasks; import ca.uhn.fhir.jpa.migrate.tasks.api.Builder; import ca.uhn.fhir.util.VersionEnum; -import org.junit.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import java.sql.SQLException; import java.util.function.Supplier; import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.empty; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; public class AddIdGeneratorTaskTest extends BaseTest { - public AddIdGeneratorTaskTest(Supplier theTestDatabaseDetails) { - super(theTestDatabaseDetails); - } + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("data") + public void testAddIdGenerator(Supplier theTestDatabaseDetails) throws SQLException { + before(theTestDatabaseDetails); - @Test - public void testAddIdGenerator() throws SQLException { assertThat(JdbcUtils.getSequenceNames(getConnectionProperties()), empty()); MyMigrationTasks migrationTasks = new MyMigrationTasks("123456.7"); diff --git a/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/AddIndexTest.java b/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/AddIndexTest.java index d61b2eecffd..97457960566 100644 --- a/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/AddIndexTest.java +++ b/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/AddIndexTest.java @@ -1,23 +1,25 @@ package ca.uhn.fhir.jpa.migrate.taskdef; import ca.uhn.fhir.jpa.migrate.JdbcUtils; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import java.sql.SQLException; import java.util.function.Supplier; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.hasItem; -import static org.junit.Assert.assertThat; public class AddIndexTest extends BaseTest { - public AddIndexTest(Supplier theTestDatabaseDetails) { - super(theTestDatabaseDetails); - } - @Test - public void testUniqueConstraintAlreadyExists() throws SQLException { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("data") + public void testUniqueConstraintAlreadyExists(Supplier theTestDatabaseDetails) throws SQLException { + before(theTestDatabaseDetails); + executeSql("create table SOMETABLE (PID bigint not null, TEXTCOL varchar(255))"); executeSql("ALTER TABLE SOMETABLE ADD CONSTRAINT IDX_ANINDEX UNIQUE(TEXTCOL)"); @@ -37,8 +39,11 @@ public class AddIndexTest extends BaseTest { } - @Test - public void testUniqueIndexAlreadyExists() throws SQLException { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("data") + public void testUniqueIndexAlreadyExists(Supplier theTestDatabaseDetails) throws SQLException { + before(theTestDatabaseDetails); + executeSql("create table SOMETABLE (PID bigint not null, TEXTCOL varchar(255))"); executeSql("create unique index IDX_ANINDEX on SOMETABLE (PID, TEXTCOL)"); executeSql("create unique index IDX_DIFINDEX on SOMETABLE (TEXTCOL)"); @@ -58,8 +63,11 @@ public class AddIndexTest extends BaseTest { assertThat(JdbcUtils.getIndexNames(getConnectionProperties(), "SOMETABLE"), containsInAnyOrder("IDX_DIFINDEX", "IDX_ANINDEX")); } - @Test - public void testNonUniqueIndexAlreadyExists() throws SQLException { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("data") + public void testNonUniqueIndexAlreadyExists(Supplier theTestDatabaseDetails) throws SQLException { + before(theTestDatabaseDetails); + executeSql("create table SOMETABLE (PID bigint not null, TEXTCOL varchar(255))"); executeSql("create index IDX_ANINDEX on SOMETABLE (PID, TEXTCOL)"); executeSql("create index IDX_DIFINDEX on SOMETABLE (TEXTCOL)"); @@ -79,8 +87,11 @@ public class AddIndexTest extends BaseTest { assertThat(JdbcUtils.getIndexNames(getConnectionProperties(), "SOMETABLE"), containsInAnyOrder("IDX_DIFINDEX", "IDX_ANINDEX")); } - @Test - public void testIndexDoesntAlreadyExist() throws SQLException { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("data") + public void testIndexDoesntAlreadyExist(Supplier theTestDatabaseDetails) throws SQLException { + before(theTestDatabaseDetails); + executeSql("create table SOMETABLE (PID bigint not null, TEXTCOL varchar(255))"); executeSql("create unique index IDX_DIFINDEX on SOMETABLE (TEXTCOL)"); diff --git a/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/AddTableByColumnTaskTest.java b/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/AddTableByColumnTaskTest.java index 17c4ea416e4..59fb3e45e8f 100644 --- a/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/AddTableByColumnTaskTest.java +++ b/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/AddTableByColumnTaskTest.java @@ -5,7 +5,9 @@ import ca.uhn.fhir.jpa.migrate.JdbcUtils; import ca.uhn.fhir.jpa.migrate.tasks.api.BaseMigrationTasks; import ca.uhn.fhir.jpa.migrate.tasks.api.Builder; import ca.uhn.fhir.util.VersionEnum; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import java.sql.SQLException; import java.util.Set; @@ -13,15 +15,14 @@ import java.util.function.Supplier; import java.util.stream.Collectors; import static org.hamcrest.Matchers.containsInAnyOrder; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; public class AddTableByColumnTaskTest extends BaseTest { - public AddTableByColumnTaskTest(Supplier theTestDatabaseDetails) { - super(theTestDatabaseDetails); - } - @Test - public void testAddTable() throws SQLException { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("data") + public void testAddTable(Supplier theTestDatabaseDetails) throws SQLException { + before(theTestDatabaseDetails); MyMigrationTasks migrator = new MyMigrationTasks(); getMigrator().addTasks(migrator.getTasks(VersionEnum.V3_3_0, VersionEnum.V3_6_0)); diff --git a/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/AddTableTest.java b/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/AddTableTest.java index 427d9275046..36cb0256475 100644 --- a/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/AddTableTest.java +++ b/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/AddTableTest.java @@ -1,23 +1,22 @@ package ca.uhn.fhir.jpa.migrate.taskdef; -import ca.uhn.fhir.jpa.migrate.DriverTypeEnum; import ca.uhn.fhir.jpa.migrate.JdbcUtils; -import org.junit.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import java.sql.SQLException; import java.util.function.Supplier; import static org.hamcrest.Matchers.containsInAnyOrder; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; public class AddTableTest extends BaseTest { - public AddTableTest(Supplier theTestDatabaseDetails) { - super(theTestDatabaseDetails); - } - @Test - public void testTableDoesntAlreadyExist() throws SQLException { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("data") + public void testTableDoesntAlreadyExist(Supplier theTestDatabaseDetails) throws SQLException { + before(theTestDatabaseDetails); AddTableRawSqlTask task = new AddTableRawSqlTask("1", "1"); task.setTableName("SOMETABLE"); @@ -29,8 +28,11 @@ public class AddTableTest extends BaseTest { assertThat(JdbcUtils.getTableNames(getConnectionProperties()), containsInAnyOrder("SOMETABLE")); } - @Test - public void testTableAlreadyExists() throws SQLException { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("data") + public void testTableAlreadyExists(Supplier theTestDatabaseDetails) throws SQLException { + before(theTestDatabaseDetails); + executeSql("create table SOMETABLE (PID bigint not null, TEXTCOL varchar(255))"); assertThat(JdbcUtils.getTableNames(getConnectionProperties()), containsInAnyOrder("SOMETABLE")); diff --git a/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/ArbitrarySqlTaskTest.java b/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/ArbitrarySqlTaskTest.java index 24b7c007a75..69af82ef359 100644 --- a/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/ArbitrarySqlTaskTest.java +++ b/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/ArbitrarySqlTaskTest.java @@ -4,22 +4,23 @@ import ca.uhn.fhir.jpa.migrate.tasks.api.BaseMigrationTasks; import ca.uhn.fhir.jpa.model.config.PartitionSettings; import ca.uhn.fhir.jpa.model.entity.SearchParamPresent; import ca.uhn.fhir.util.VersionEnum; -import org.junit.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import java.util.List; import java.util.Map; import java.util.function.Supplier; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public class ArbitrarySqlTaskTest extends BaseTest { - public ArbitrarySqlTaskTest(Supplier theTestDatabaseDetails) { - super(theTestDatabaseDetails); - } - @Test - public void test350MigrateSearchParams() { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("data") + public void test350MigrateSearchParams(Supplier theTestDatabaseDetails) { + before(theTestDatabaseDetails); + executeSql("create table HFJ_SEARCH_PARM (PID bigint not null, RES_TYPE varchar(255), PARAM_NAME varchar(255))"); executeSql("insert into HFJ_SEARCH_PARM (PID, RES_TYPE, PARAM_NAME) values (1, 'Patient', 'identifier')"); executeSql("insert into HFJ_SEARCH_PARM (PID, RES_TYPE, PARAM_NAME) values (2, 'Patient', 'family')"); @@ -27,7 +28,7 @@ public class ArbitrarySqlTaskTest extends BaseTest { executeSql("insert into HFJ_RES_PARAM_PRESENT (PID, SP_ID, SP_PRESENT, HASH_PRESENT) values (100, 1, true, null)"); executeSql("insert into HFJ_RES_PARAM_PRESENT (PID, SP_ID, SP_PRESENT, HASH_PRESENT) values (101, 2, true, null)"); - ArbitrarySqlTask task = new ArbitrarySqlTask(VersionEnum.V3_5_0, "1", "HFJ_RES_PARAM_PRESENT", "Consolidate search parameter presence indexes"); + ArbitrarySqlTask task = new ArbitrarySqlTask(VersionEnum.V3_5_0, "1", "HFJ_RES_PARAM_PRESENT", "Consolidate search parameter presence indexes"); task.setExecuteOnlyIfTableExists("hfj_search_parm"); task.setBatchSize(1); String sql = "SELECT " + @@ -59,9 +60,12 @@ public class ArbitrarySqlTaskTest extends BaseTest { } - @Test - public void testExecuteOnlyIfTableExists() { - ArbitrarySqlTask task = new ArbitrarySqlTask(VersionEnum.V3_5_0, "1", "HFJ_RES_PARAM_PRESENT", "Consolidate search parameter presence indexes"); + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("data") + public void testExecuteOnlyIfTableExists(Supplier theTestDatabaseDetails) { + before(theTestDatabaseDetails); + + ArbitrarySqlTask task = new ArbitrarySqlTask(VersionEnum.V3_5_0, "1", "HFJ_RES_PARAM_PRESENT", "Consolidate search parameter presence indexes"); task.setBatchSize(1); String sql = "SELECT * FROM HFJ_SEARCH_PARM"; task.addQuery(sql, ArbitrarySqlTask.QueryModeEnum.BATCH_UNTIL_NO_MORE, t -> { @@ -75,8 +79,11 @@ public class ArbitrarySqlTaskTest extends BaseTest { } - @Test - public void testUpdateTask() { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("data") + public void testUpdateTask(Supplier theTestDatabaseDetails) { + before(theTestDatabaseDetails); + executeSql("create table TEST_UPDATE_TASK (PID bigint not null, RES_TYPE varchar(255), PARAM_NAME varchar(255))"); executeSql("insert into TEST_UPDATE_TASK (PID, RES_TYPE, PARAM_NAME) values (1, 'Patient', 'identifier')"); @@ -98,8 +105,11 @@ public class ArbitrarySqlTaskTest extends BaseTest { } - @Test - public void testArbitrarySql() { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("data") + public void testArbitrarySql(Supplier theTestDatabaseDetails) { + before(theTestDatabaseDetails); + executeSql("create table TEST_UPDATE_TASK (PID bigint not null, RES_TYPE varchar(255), PARAM_NAME varchar(255))"); executeSql("insert into TEST_UPDATE_TASK (PID, RES_TYPE, PARAM_NAME) values (1, 'Patient', 'identifier')"); executeSql("insert into TEST_UPDATE_TASK (PID, RES_TYPE, PARAM_NAME) values (1, 'Encounter', 'identifier')"); diff --git a/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/BaseTaskTest.java b/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/BaseTaskTest.java index 82a07ba81d6..43f41daf219 100644 --- a/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/BaseTaskTest.java +++ b/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/BaseTaskTest.java @@ -1,9 +1,9 @@ package ca.uhn.fhir.jpa.migrate.taskdef; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; public class BaseTaskTest { diff --git a/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/BaseTest.java b/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/BaseTest.java index f4faff0a52a..d6d49f427ec 100644 --- a/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/BaseTest.java +++ b/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/BaseTest.java @@ -6,43 +6,32 @@ import ca.uhn.fhir.jpa.migrate.JdbcUtils; import ca.uhn.fhir.jpa.migrate.SchemaMigrator; import org.apache.commons.dbcp2.BasicDataSource; import org.intellij.lang.annotations.Language; -import org.junit.After; -import org.junit.Before; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; +import org.junit.jupiter.api.AfterEach; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.jdbc.core.ColumnMapRowMapper; import java.sql.SQLException; import java.util.ArrayList; -import java.util.Collection; import java.util.List; import java.util.Map; import java.util.Set; import java.util.function.Supplier; +import java.util.stream.Stream; -@RunWith(Parameterized.class) public abstract class BaseTest { private static final String DATABASE_NAME = "DATABASE"; private static final Logger ourLog = LoggerFactory.getLogger(BaseTest.class); private static int ourDatabaseUrl = 0; - private final Supplier myTestDatabaseDetails; private BasicDataSource myDataSource; private String myUrl; private FlywayMigrator myMigrator; private DriverTypeEnum.ConnectionProperties myConnectionProperties; - public BaseTest(Supplier theTestDatabaseDetails) { - myTestDatabaseDetails = theTestDatabaseDetails; - } - - @Before - public void before() { - TestDatabaseDetails testDatabaseDetails = myTestDatabaseDetails.get(); - + public void before(Supplier theTestDatabaseDetails) { + TestDatabaseDetails testDatabaseDetails = theTestDatabaseDetails.get(); myUrl = testDatabaseDetails.myUrl; myConnectionProperties = testDatabaseDetails.myConnectionProperties; myDataSource = testDatabaseDetails.myDataSource; @@ -61,7 +50,7 @@ public abstract class BaseTest { return myDataSource; } - @After + @AfterEach public void resetMigrationVersion() throws SQLException { Set tableNames = JdbcUtils.getTableNames(getConnectionProperties()); if (tableNames.contains(SchemaMigrator.HAPI_FHIR_MIGRATION_TABLENAME)) { @@ -86,7 +75,7 @@ public abstract class BaseTest { return myMigrator; } - @After + @AfterEach public void after() { myConnectionProperties.close(); } @@ -111,8 +100,7 @@ public abstract class BaseTest { } - @Parameterized.Parameters(name = "{0}") - public static Collection> data() { + public static Stream> data() { ourLog.info("H2: {}", org.h2.Driver.class.toString()); ArrayList> retVal = new ArrayList<>(); @@ -159,7 +147,7 @@ public abstract class BaseTest { } }); - return retVal; + return retVal.stream(); } } diff --git a/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/CalculateHashesTest.java b/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/CalculateHashesTest.java index bac8cff0e48..83ed0bf8c40 100644 --- a/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/CalculateHashesTest.java +++ b/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/CalculateHashesTest.java @@ -4,22 +4,22 @@ import ca.uhn.fhir.jpa.model.config.PartitionSettings; import ca.uhn.fhir.jpa.model.entity.BaseResourceIndexedSearchParam; import ca.uhn.fhir.jpa.model.entity.ResourceIndexedSearchParamToken; import ca.uhn.fhir.util.VersionEnum; -import org.junit.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.springframework.jdbc.core.JdbcTemplate; import java.util.Map; import java.util.function.Supplier; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public class CalculateHashesTest extends BaseTest { - public CalculateHashesTest(Supplier theTestDatabaseDetails) { - super(theTestDatabaseDetails); - } + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("data") + public void testCreateHashes(Supplier theTestDatabaseDetails) { + before(theTestDatabaseDetails); - @Test - public void testCreateHashes() { executeSql("create table HFJ_SPIDX_TOKEN (SP_ID bigint not null, SP_MISSING boolean, SP_NAME varchar(100) not null, RES_ID bigint, RES_TYPE varchar(255) not null, SP_UPDATED timestamp, HASH_IDENTITY bigint, HASH_SYS bigint, HASH_SYS_AND_VALUE bigint, HASH_VALUE bigint, SP_SYSTEM varchar(200), SP_VALUE varchar(200), primary key (SP_ID))"); executeSql("insert into HFJ_SPIDX_TOKEN (SP_MISSING, SP_NAME, RES_ID, RES_TYPE, SP_UPDATED, SP_SYSTEM, SP_VALUE, SP_ID) values (false, 'identifier', 999, 'Patient', '2018-09-03 07:44:49.196', 'urn:oid:1.2.410.100110.10.41308301', '88888888', 1)"); executeSql("insert into HFJ_SPIDX_TOKEN (SP_MISSING, SP_NAME, RES_ID, RES_TYPE, SP_UPDATED, SP_SYSTEM, SP_VALUE, SP_ID) values (false, 'identifier', 999, 'Patient', '2018-09-03 07:44:49.196', 'urn:oid:1.2.410.100110.10.41308301', '99999999', 2)"); @@ -57,8 +57,11 @@ public class CalculateHashesTest extends BaseTest { }); } - @Test - public void testCreateHashesLargeNumber() { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("data") + public void testCreateHashesLargeNumber(Supplier theTestDatabaseDetails) { + before(theTestDatabaseDetails); + executeSql("create table HFJ_SPIDX_TOKEN (SP_ID bigint not null, SP_MISSING boolean, SP_NAME varchar(100) not null, RES_ID bigint, RES_TYPE varchar(255) not null, SP_UPDATED timestamp, HASH_IDENTITY bigint, HASH_SYS bigint, HASH_SYS_AND_VALUE bigint, HASH_VALUE bigint, SP_SYSTEM varchar(200), SP_VALUE varchar(200), primary key (SP_ID))"); for (int i = 0; i < 777; i++) { diff --git a/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/DropColumnTest.java b/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/DropColumnTest.java index b144aed0a2c..e2655fef2bc 100644 --- a/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/DropColumnTest.java +++ b/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/DropColumnTest.java @@ -1,24 +1,23 @@ package ca.uhn.fhir.jpa.migrate.taskdef; import ca.uhn.fhir.jpa.migrate.JdbcUtils; -import org.junit.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import java.sql.SQLException; import java.util.function.Supplier; import static org.hamcrest.Matchers.containsInAnyOrder; -import static org.hamcrest.Matchers.empty; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.hasSize; -import static org.junit.Assert.assertThat; public class DropColumnTest extends BaseTest { - public DropColumnTest(Supplier theTestDatabaseDetails) { - super(theTestDatabaseDetails); - } + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("data") + public void testDropColumn(Supplier theTestDatabaseDetails) throws SQLException { + before(theTestDatabaseDetails); - @Test - public void testDropColumn() throws SQLException { executeSql("create table SOMETABLE (PID bigint not null, TEXTCOL varchar(255))"); DropColumnTask task = new DropColumnTask("1", "1"); @@ -36,8 +35,11 @@ public class DropColumnTest extends BaseTest { } - @Test - public void testDropForeignKeyColumn() throws SQLException { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("data") + public void testDropForeignKeyColumn(Supplier theTestDatabaseDetails) throws SQLException { + before(theTestDatabaseDetails); + executeSql("create table PARENT (PID bigint not null, TEXTCOL varchar(255), primary key (PID))"); executeSql("create table SIBLING (PID bigint not null, TEXTCOL varchar(255), primary key (PID))"); executeSql("create table CHILD (PID bigint not null, PARENTREF bigint, SIBLINGREF bigint)"); @@ -59,10 +61,10 @@ public class DropColumnTest extends BaseTest { assertThat(JdbcUtils.getColumnNames(getConnectionProperties(), "CHILD"), containsInAnyOrder("PID", "SIBLINGREF")); - assertThat(JdbcUtils.getForeignKeys(getConnectionProperties(), "PARENT", "CHILD"), empty()); + assertThat(JdbcUtils.getForeignKeys(getConnectionProperties(), "PARENT", "CHILD"), hasSize(0)); assertThat(JdbcUtils.getForeignKeys(getConnectionProperties(), "SIBLING", "CHILD"), hasSize(1)); - assertThat(JdbcUtils.getForeignKeysForColumn(getConnectionProperties(), "PARENTREF", "CHILD"), empty()); + assertThat(JdbcUtils.getForeignKeysForColumn(getConnectionProperties(), "PARENTREF", "CHILD"), hasSize(0)); assertThat(JdbcUtils.getForeignKeysForColumn(getConnectionProperties(), "SIBLINGREF", "CHILD"), containsInAnyOrder("FK_BROTHER")); // Do it again to make sure there is no error diff --git a/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/DropForeignKeyTaskTest.java b/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/DropForeignKeyTaskTest.java index f615799d382..7b8a157a0a2 100644 --- a/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/DropForeignKeyTaskTest.java +++ b/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/DropForeignKeyTaskTest.java @@ -1,23 +1,24 @@ package ca.uhn.fhir.jpa.migrate.taskdef; import ca.uhn.fhir.jpa.migrate.JdbcUtils; -import org.junit.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import java.sql.SQLException; import java.util.function.Supplier; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.empty; import static org.hamcrest.collection.IsCollectionWithSize.hasSize; -import static org.junit.Assert.assertThat; public class DropForeignKeyTaskTest extends BaseTest { - public DropForeignKeyTaskTest(Supplier theTestDatabaseDetails) { - super(theTestDatabaseDetails); - } - @Test - public void testDropForeignKey() throws SQLException { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("data") + public void testDropForeignKey(Supplier theTestDatabaseDetails) throws SQLException { + before(theTestDatabaseDetails); + executeSql("create table PARENT (PID bigint not null, TEXTCOL varchar(255), primary key (PID))"); executeSql("create table CHILD (PID bigint not null, PARENTREF bigint)"); executeSql("alter table CHILD add constraint FK_MOM foreign key (PARENTREF) references PARENT(PID)"); diff --git a/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/DropIdGeneratorTaskTest.java b/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/DropIdGeneratorTaskTest.java index 618bbc91194..5d566b68c94 100644 --- a/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/DropIdGeneratorTaskTest.java +++ b/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/DropIdGeneratorTaskTest.java @@ -4,24 +4,24 @@ import ca.uhn.fhir.jpa.migrate.JdbcUtils; import ca.uhn.fhir.jpa.migrate.tasks.api.BaseMigrationTasks; import ca.uhn.fhir.jpa.migrate.tasks.api.Builder; import ca.uhn.fhir.util.VersionEnum; -import org.junit.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import java.sql.SQLException; import java.util.function.Supplier; import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.empty; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; public class DropIdGeneratorTaskTest extends BaseTest { - public DropIdGeneratorTaskTest(Supplier theTestDatabaseDetails) { - super(theTestDatabaseDetails); - } + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("data") + public void testAddIdGenerator(Supplier theTestDatabaseDetails) throws SQLException { + before(theTestDatabaseDetails); - @Test - public void testAddIdGenerator() throws SQLException { executeSql("create sequence SEQ_FOO start with 1 increment by 50"); assertThat(JdbcUtils.getSequenceNames(getConnectionProperties()), containsInAnyOrder("SEQ_FOO")); diff --git a/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/DropIndexTest.java b/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/DropIndexTest.java index 778c8b44165..cc51bbf25e5 100644 --- a/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/DropIndexTest.java +++ b/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/DropIndexTest.java @@ -1,27 +1,29 @@ package ca.uhn.fhir.jpa.migrate.taskdef; import ca.uhn.fhir.jpa.migrate.JdbcUtils; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import java.sql.SQLException; import java.util.function.Supplier; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.contains; -import static org.junit.Assert.assertThat; public class DropIndexTest extends BaseTest { - public DropIndexTest(Supplier theTestDatabaseDetails) { - super(theTestDatabaseDetails); - } - @Test - public void testIndexAlreadyExists() throws SQLException { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("data") + public void testIndexAlreadyExists(Supplier theTestDatabaseDetails) throws SQLException { + before(theTestDatabaseDetails); + executeSql("create table SOMETABLE (PID bigint not null, TEXTCOL varchar(255))"); executeSql("create index IDX_ANINDEX on SOMETABLE (PID, TEXTCOL)"); executeSql("create index IDX_DIFINDEX on SOMETABLE (TEXTCOL)"); - DropIndexTask task = new DropIndexTask("1", "1"); + DropIndexTask task = new DropIndexTask("1", "1"); task.setDescription("Drop an index"); task.setIndexName("IDX_ANINDEX"); task.setTableName("SOMETABLE"); @@ -32,12 +34,15 @@ public class DropIndexTest extends BaseTest { assertThat(JdbcUtils.getIndexNames(getConnectionProperties(), "SOMETABLE"), contains("IDX_DIFINDEX")); } - @Test - public void testIndexDoesntAlreadyExist() throws SQLException { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("data") + public void testIndexDoesntAlreadyExist(Supplier theTestDatabaseDetails) throws SQLException { + before(theTestDatabaseDetails); + executeSql("create table SOMETABLE (PID bigint not null, TEXTCOL varchar(255))"); executeSql("create index IDX_DIFINDEX on SOMETABLE (TEXTCOL)"); - DropIndexTask task = new DropIndexTask("1", "1"); + DropIndexTask task = new DropIndexTask("1", "1"); task.setDescription("Drop an index"); task.setIndexName("IDX_ANINDEX"); task.setTableName("SOMETABLE"); @@ -49,13 +54,16 @@ public class DropIndexTest extends BaseTest { } - @Test - public void testConstraintAlreadyExists() throws SQLException { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("data") + public void testConstraintAlreadyExists(Supplier theTestDatabaseDetails) throws SQLException { + before(theTestDatabaseDetails); + executeSql("create table SOMETABLE (PID bigint not null, TEXTCOL varchar(255))"); executeSql("create index IDX_ANINDEX on SOMETABLE (PID, TEXTCOL)"); executeSql("create index IDX_DIFINDEX on SOMETABLE (TEXTCOL)"); - DropIndexTask task = new DropIndexTask("1", "1"); + DropIndexTask task = new DropIndexTask("1", "1"); task.setDescription("Drop an index"); task.setIndexName("IDX_ANINDEX"); task.setTableName("SOMETABLE"); @@ -66,12 +74,15 @@ public class DropIndexTest extends BaseTest { assertThat(JdbcUtils.getIndexNames(getConnectionProperties(), "SOMETABLE"), contains("IDX_DIFINDEX")); } - @Test - public void testConstraintDoesntAlreadyExist() throws SQLException { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("data") + public void testConstraintDoesntAlreadyExist(Supplier theTestDatabaseDetails) throws SQLException { + before(theTestDatabaseDetails); + executeSql("create table SOMETABLE (PID bigint not null, TEXTCOL varchar(255))"); executeSql("create index IDX_DIFINDEX on SOMETABLE (TEXTCOL)"); - DropIndexTask task = new DropIndexTask("1", "1"); + DropIndexTask task = new DropIndexTask("1", "1"); task.setDescription("Drop an index"); task.setIndexName("IDX_ANINDEX"); task.setTableName("SOMETABLE"); diff --git a/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/DropTableTest.java b/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/DropTableTest.java index d81877227b9..dc80e30ca26 100644 --- a/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/DropTableTest.java +++ b/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/DropTableTest.java @@ -1,28 +1,32 @@ package ca.uhn.fhir.jpa.migrate.taskdef; import ca.uhn.fhir.jpa.migrate.JdbcUtils; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import java.sql.SQLException; import java.util.function.Supplier; -import static org.hamcrest.Matchers.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.greaterThan; +import static org.hamcrest.Matchers.hasItems; import static org.hamcrest.core.IsNot.not; -import static org.junit.Assert.assertThat; public class DropTableTest extends BaseTest { - public DropTableTest(Supplier theTestDatabaseDetails) { - super(theTestDatabaseDetails); - } - @Test - public void testDropExistingTable() throws SQLException { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("data") + public void testDropExistingTable(Supplier theTestDatabaseDetails) throws SQLException { + before(theTestDatabaseDetails); + executeSql("create table SOMETABLE (PID bigint not null, TEXTCOL varchar(255))"); executeSql("create index IDX_ANINDEX on SOMETABLE (PID, TEXTCOL)"); executeSql("create index IDX_DIFINDEX on SOMETABLE (TEXTCOL)"); - DropTableTask task = new DropTableTask("1", "1"); + DropTableTask task = new DropTableTask("1", "1"); task.setTableName("SOMETABLE"); getMigrator().addTask(task); @@ -33,13 +37,16 @@ public class DropTableTest extends BaseTest { assertThat(JdbcUtils.getTableNames(getConnectionProperties()), not(hasItems("SOMETABLE"))); } - @Test - public void testDropTableWithForeignKey() throws SQLException { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("data") + public void testDropTableWithForeignKey(Supplier theTestDatabaseDetails) throws SQLException { + before(theTestDatabaseDetails); + executeSql("create table FOREIGNTABLE (PID bigint not null, TEXTCOL varchar(255), primary key (PID))"); executeSql("create table SOMETABLE (PID bigint not null, REMOTEPID bigint not null, primary key (PID))"); executeSql("alter table SOMETABLE add constraint FK_MYFK foreign key (REMOTEPID) references FOREIGNTABLE"); - DropTableTask task = new DropTableTask("1", "1"); + DropTableTask task = new DropTableTask("1", "1"); task.setTableName("SOMETABLE"); getMigrator().addTask(task); @@ -50,10 +57,12 @@ public class DropTableTest extends BaseTest { assertThat(JdbcUtils.getTableNames(getConnectionProperties()), not(hasItems("SOMETABLE"))); } - @Test - public void testDropNonExistingTable() throws SQLException { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("data") + public void testDropNonExistingTable(Supplier theTestDatabaseDetails) throws SQLException { + before(theTestDatabaseDetails); - DropTableTask task = new DropTableTask("1", "1"); + DropTableTask task = new DropTableTask("1", "1"); task.setTableName("SOMETABLE"); getMigrator().addTask(task); @@ -62,11 +71,14 @@ public class DropTableTest extends BaseTest { assertThat(JdbcUtils.getTableNames(getConnectionProperties()), not(hasItems("SOMETABLE"))); } - @Test - public void testFlywayGetMigrationInfo() throws SQLException { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("data") + public void testFlywayGetMigrationInfo(Supplier theTestDatabaseDetails) throws SQLException { + before(theTestDatabaseDetails); + executeSql("create table SOMETABLE (PID bigint not null, TEXTCOL varchar(255))"); - DropTableTask task = new DropTableTask("1", "1"); + DropTableTask task = new DropTableTask("1", "1"); task.setTableName("SOMETABLE"); getMigrator().addTask(task); diff --git a/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/ExecuteRawSqlTaskTest.java b/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/ExecuteRawSqlTaskTest.java index b22e36ec461..18d21bc6529 100644 --- a/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/ExecuteRawSqlTaskTest.java +++ b/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/ExecuteRawSqlTaskTest.java @@ -2,22 +2,24 @@ package ca.uhn.fhir.jpa.migrate.taskdef; import ca.uhn.fhir.jpa.migrate.tasks.api.BaseMigrationTasks; import ca.uhn.fhir.util.VersionEnum; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import java.util.List; import java.util.Map; import java.util.function.Supplier; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public class ExecuteRawSqlTaskTest extends BaseTest { - public ExecuteRawSqlTaskTest(Supplier theTestDatabaseDetails) { - super(theTestDatabaseDetails); - } - @Test - public void testExecuteSql() { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("data") + public void testExecuteSql(Supplier theTestDatabaseDetails) { + before(theTestDatabaseDetails); + executeSql("create table SOMETABLE (PID bigint not null, TEXTCOL varchar(255))"); BaseMigrationTasks tasks = new BaseMigrationTasks<>(); @@ -33,8 +35,11 @@ public class ExecuteRawSqlTaskTest extends BaseTest { assertEquals(123L, output.get(0).get("PID")); } - @Test - public void testExecuteSql_AllowedToFail() { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("data") + public void testExecuteSql_AllowedToFail(Supplier theTestDatabaseDetails) { + before(theTestDatabaseDetails); + executeSql("create table SOMETABLE (PID bigint not null, TEXTCOL varchar(255))"); BaseMigrationTasks tasks = new BaseMigrationTasks<>(); diff --git a/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/HashTest.java b/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/HashTest.java index 4c25a43a1d5..0af8f2428f9 100644 --- a/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/HashTest.java +++ b/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/HashTest.java @@ -2,15 +2,15 @@ package ca.uhn.fhir.jpa.migrate.taskdef; import ca.uhn.fhir.jpa.migrate.tasks.HapiFhirJpaMigrationTasks; import ca.uhn.fhir.util.VersionEnum; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; public class HashTest { @@ -37,7 +37,7 @@ public class HashTest { Map hashesByVersion = new HashMap<>(); for (BaseTask task : tasks1) { String version = task.getFlywayVersion(); - assertNull("Duplicate flyway version " + version + " in " + HapiFhirJpaMigrationTasks.class.getName(), hashesByVersion.get(version)); + assertNull(hashesByVersion.get(version), "Duplicate flyway version " + version + " in " + HapiFhirJpaMigrationTasks.class.getName()); hashesByVersion.put(version, task.hashCode()); } @@ -45,7 +45,7 @@ public class HashTest { for (BaseTask task : tasks2) { String version = task.getFlywayVersion(); int origHash = hashesByVersion.get(version); - assertEquals("Hashes differ for task " + version, origHash, task.hashCode()); + assertEquals(origHash, task.hashCode(), "Hashes differ for task " + version); } } } diff --git a/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/InitializeSchemaTaskTest.java b/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/InitializeSchemaTaskTest.java index 59a886bf1dc..bdf2a8c2b5e 100644 --- a/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/InitializeSchemaTaskTest.java +++ b/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/InitializeSchemaTaskTest.java @@ -4,7 +4,9 @@ import ca.uhn.fhir.jpa.migrate.DriverTypeEnum; import ca.uhn.fhir.jpa.migrate.JdbcUtils; import ca.uhn.fhir.jpa.migrate.tasks.api.ISchemaInitializationProvider; import org.apache.commons.lang3.builder.HashCodeBuilder; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import java.sql.SQLException; import java.util.Collections; @@ -12,16 +14,15 @@ import java.util.List; import java.util.function.Supplier; import static org.hamcrest.Matchers.containsInAnyOrder; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; public class InitializeSchemaTaskTest extends BaseTest { - public InitializeSchemaTaskTest(Supplier theTestDatabaseDetails) { - super(theTestDatabaseDetails); - } + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("data") + public void testInitializeTwice(Supplier theTestDatabaseDetails) throws SQLException { + before(theTestDatabaseDetails); - @Test - public void testInitializeTwice() throws SQLException { InitializeSchemaTask task = new InitializeSchemaTask("1", "1", new TestProvider()); getMigrator().addTask(task); getMigrator().migrate(); diff --git a/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/ModifyColumnTest.java b/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/ModifyColumnTest.java index ad529c71228..d3ed886f6ce 100644 --- a/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/ModifyColumnTest.java +++ b/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/ModifyColumnTest.java @@ -3,21 +3,27 @@ package ca.uhn.fhir.jpa.migrate.taskdef; import ca.uhn.fhir.jpa.migrate.DriverTypeEnum; import ca.uhn.fhir.jpa.migrate.JdbcUtils; import org.flywaydb.core.internal.command.DbMigrate; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import java.sql.SQLException; import java.util.function.Supplier; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsInAnyOrder; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; public class ModifyColumnTest extends BaseTest { - public ModifyColumnTest(Supplier theTestDatabaseDetails) { - super(theTestDatabaseDetails); - } - @Test - public void testColumnWithJdbcTypeClob() throws SQLException { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("data") + public void testColumnWithJdbcTypeClob(Supplier theTestDatabaseDetails) throws SQLException { + before(theTestDatabaseDetails); + if (getDriverType() == DriverTypeEnum.DERBY_EMBEDDED) { return; } @@ -43,8 +49,11 @@ public class ModifyColumnTest extends BaseTest { } - @Test - public void testColumnAlreadyExists() throws SQLException { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("data") + public void testColumnAlreadyExists(Supplier theTestDatabaseDetails) throws SQLException { + before(theTestDatabaseDetails); + executeSql("create table SOMETABLE (PID bigint not null, TEXTCOL varchar(255), newcol bigint)"); ModifyColumnTask task = new ModifyColumnTask("1", "1"); @@ -66,8 +75,11 @@ public class ModifyColumnTest extends BaseTest { } - @Test - public void testNoShrink_SameNullable() throws SQLException { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("data") + public void testNoShrink_SameNullable(Supplier theTestDatabaseDetails) throws SQLException { + before(theTestDatabaseDetails); + executeSql("create table SOMETABLE (PID bigint not null, TEXTCOL varchar(255), newcol bigint)"); ModifyColumnTask task = new ModifyColumnTask("1", "123456.7"); @@ -90,8 +102,11 @@ public class ModifyColumnTest extends BaseTest { } - @Test - public void testColumnMakeNullable() throws SQLException { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("data") + public void testColumnMakeNullable(Supplier theTestDatabaseDetails) throws SQLException { + before(theTestDatabaseDetails); + executeSql("create table SOMETABLE (PID bigint not null, TEXTCOL varchar(255) not null)"); assertFalse(JdbcUtils.isColumnNullable(getConnectionProperties(), "SOMETABLE", "PID")); assertFalse(JdbcUtils.isColumnNullable(getConnectionProperties(), "SOMETABLE", "TEXTCOL")); @@ -130,8 +145,11 @@ public class ModifyColumnTest extends BaseTest { } - @Test - public void testNoShrink_ColumnMakeDateNullable() throws SQLException { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("data") + public void testNoShrink_ColumnMakeDateNullable(Supplier theTestDatabaseDetails) throws SQLException { + before(theTestDatabaseDetails); + executeSql("create table SOMETABLE (PID bigint not null, DATECOL timestamp not null)"); assertFalse(JdbcUtils.isColumnNullable(getConnectionProperties(), "SOMETABLE", "PID")); assertFalse(JdbcUtils.isColumnNullable(getConnectionProperties(), "SOMETABLE", "DATECOL")); @@ -169,8 +187,11 @@ public class ModifyColumnTest extends BaseTest { getMigrator().migrate(); } - @Test - public void testColumnMakeNotNullable() throws SQLException { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("data") + public void testColumnMakeNotNullable(Supplier theTestDatabaseDetails) throws SQLException { + before(theTestDatabaseDetails); + executeSql("create table SOMETABLE (PID bigint, TEXTCOL varchar(255))"); assertTrue(JdbcUtils.isColumnNullable(getConnectionProperties(), "SOMETABLE", "PID")); assertTrue(JdbcUtils.isColumnNullable(getConnectionProperties(), "SOMETABLE", "TEXTCOL")); @@ -208,8 +229,11 @@ public class ModifyColumnTest extends BaseTest { } - @Test - public void testColumnDoesntAlreadyExist() throws SQLException { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("data") + public void testColumnDoesntAlreadyExist(Supplier theTestDatabaseDetails) throws SQLException { + before(theTestDatabaseDetails); + executeSql("create table SOMETABLE (PID bigint, TEXTCOL varchar(255))"); ModifyColumnTask task = new ModifyColumnTask("1", "1"); @@ -224,8 +248,11 @@ public class ModifyColumnTest extends BaseTest { assertThat(JdbcUtils.getColumnNames(getConnectionProperties(), "SOMETABLE"), containsInAnyOrder("PID", "TEXTCOL")); } - @Test - public void testFailureAllowed() throws SQLException { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("data") + public void testFailureAllowed(Supplier theTestDatabaseDetails) throws SQLException { + before(theTestDatabaseDetails); + executeSql("create table SOMETABLE (PID bigint, TEXTCOL varchar(255))"); executeSql("insert into SOMETABLE (TEXTCOL) values ('HELLO')"); @@ -242,8 +269,11 @@ public class ModifyColumnTest extends BaseTest { } - @Test - public void testFailureNotAllowed() { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("data") + public void testFailureNotAllowed(Supplier theTestDatabaseDetails) { + before(theTestDatabaseDetails); + executeSql("create table SOMETABLE (PID bigint, TEXTCOL varchar(255))"); executeSql("insert into SOMETABLE (TEXTCOL) values ('HELLO')"); @@ -263,8 +293,11 @@ public class ModifyColumnTest extends BaseTest { } - @Test - public void dontCompareLengthIfNoneSpecifiedInTask() throws SQLException { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("data") + public void dontCompareLengthIfNoneSpecifiedInTask(Supplier theTestDatabaseDetails) throws SQLException { + before(theTestDatabaseDetails); + executeSql("create table SOMETABLE (PID bigint, TEXTCOL varchar(255))"); ModifyColumnTask task = new ModifyColumnTask("1", "1"); @@ -280,8 +313,11 @@ public class ModifyColumnTest extends BaseTest { } - @Test - public void testShrinkDoesntFailIfShrinkCannotProceed() throws SQLException { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("data") + public void testShrinkDoesntFailIfShrinkCannotProceed(Supplier theTestDatabaseDetails) throws SQLException { + before(theTestDatabaseDetails); + executeSql("create table SOMETABLE (PID bigint not null, TEXTCOL varchar(10))"); executeSql("insert into SOMETABLE (PID, TEXTCOL) values (1, '0123456789')"); diff --git a/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/RenameColumnTaskDbSpecificTest.java b/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/RenameColumnTaskDbSpecificTest.java index cd88accb134..bbd5058002d 100644 --- a/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/RenameColumnTaskDbSpecificTest.java +++ b/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/RenameColumnTaskDbSpecificTest.java @@ -1,8 +1,9 @@ package ca.uhn.fhir.jpa.migrate.taskdef; import ca.uhn.fhir.jpa.migrate.DriverTypeEnum; -import org.junit.Test; -import static org.junit.Assert.assertEquals; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; public class RenameColumnTaskDbSpecificTest { diff --git a/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/RenameColumnTaskTest.java b/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/RenameColumnTaskTest.java index 61d06e27d66..3e02111e397 100644 --- a/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/RenameColumnTaskTest.java +++ b/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/taskdef/RenameColumnTaskTest.java @@ -2,27 +2,27 @@ package ca.uhn.fhir.jpa.migrate.taskdef; import ca.uhn.fhir.jpa.migrate.JdbcUtils; import org.flywaydb.core.api.FlywayException; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import java.sql.SQLException; import java.util.Set; import java.util.function.Supplier; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsInAnyOrder; -import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.hasSize; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; public class RenameColumnTaskTest extends BaseTest { - public RenameColumnTaskTest(Supplier theTestDatabaseDetails) { - super(theTestDatabaseDetails); - } + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("data") + public void testColumnAlreadyExists(Supplier theTestDatabaseDetails) throws SQLException { + before(theTestDatabaseDetails); - @Test - public void testColumnAlreadyExists() throws SQLException { executeSql("create table SOMETABLE (PID bigint not null, TEXTCOL varchar(255))"); RenameColumnTask task = new RenameColumnTask("1", "1"); @@ -37,8 +37,11 @@ public class RenameColumnTaskTest extends BaseTest { assertThat(JdbcUtils.getColumnNames(getConnectionProperties(), "SOMETABLE"), containsInAnyOrder("PID", "TEXTCOL")); } - @Test - public void testForeignKeyColumnAlreadyExists_MySql() throws SQLException { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("data") + public void testForeignKeyColumnAlreadyExists_MySql(Supplier theTestDatabaseDetails) throws SQLException { + before(theTestDatabaseDetails); + testForeignKeyColumnAlreadyExists(true); } @@ -67,13 +70,19 @@ public class RenameColumnTaskTest extends BaseTest { assertThat(JdbcUtils.getForeignKeysForColumn(getConnectionProperties(), "PARENTREF", "CHILD"), containsInAnyOrder("FK_MOM")); } - @Test - public void testForeignKeyColumnAlreadyExists_OtherDB() throws SQLException { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("data") + public void testForeignKeyColumnAlreadyExists_OtherDB(Supplier theTestDatabaseDetails) throws SQLException { + before(theTestDatabaseDetails); + testForeignKeyColumnAlreadyExists(false); } - @Test - public void testBothExistDeleteTargetFirst() throws SQLException { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("data") + public void testBothExistDeleteTargetFirst(Supplier theTestDatabaseDetails) throws SQLException { + before(theTestDatabaseDetails); + executeSql("create table SOMETABLE (PID bigint not null, TEXTCOL varchar(255), myTextCol varchar(255))"); RenameColumnTask task = new RenameColumnTask("1", "1"); @@ -90,8 +99,11 @@ public class RenameColumnTaskTest extends BaseTest { assertThat(columnNames.toString(), columnNames, containsInAnyOrder("PID", "TEXTCOL")); } - @Test - public void testForeignKeyColumnBothExistDeleteTargetFirst_MySql() throws SQLException { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("data") + public void testForeignKeyColumnBothExistDeleteTargetFirst_MySql(Supplier theTestDatabaseDetails) throws SQLException { + before(theTestDatabaseDetails); + testForeignKeyColumnBothExistDeleteTargetFirst(true); } @@ -118,7 +130,7 @@ public class RenameColumnTaskTest extends BaseTest { getMigrator().migrate(); - assertThat(JdbcUtils.getForeignKeys(getConnectionProperties(), "RELATION", "CHILD"), empty()); + assertThat(JdbcUtils.getForeignKeys(getConnectionProperties(), "RELATION", "CHILD"), hasSize(0)); assertThat(JdbcUtils.getForeignKeys(getConnectionProperties(), "PARENT", "CHILD"), hasSize(1)); assertThat(JdbcUtils.getColumnNames(getConnectionProperties(), "CHILD"), containsInAnyOrder("PID", "NOKREF")); @@ -127,13 +139,19 @@ public class RenameColumnTaskTest extends BaseTest { } - @Test - public void testForeignKeyColumnBothExistDeleteTargetFirst_OtherDB() throws SQLException { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("data") + public void testForeignKeyColumnBothExistDeleteTargetFirst_OtherDB(Supplier theTestDatabaseDetails) throws SQLException { + before(theTestDatabaseDetails); + testForeignKeyColumnBothExistDeleteTargetFirst(false); } - @Test - public void testBothExistDeleteTargetFirstDataExistsInSourceAndTarget() { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("data") + public void testBothExistDeleteTargetFirstDataExistsInSourceAndTarget(Supplier theTestDatabaseDetails) { + before(theTestDatabaseDetails); + executeSql("create table SOMETABLE (PID bigint not null, TEXTCOL varchar(255), myTextCol varchar(255))"); executeSql("INSERT INTO SOMETABLE (PID, TEXTCOL, myTextCol) VALUES (123, 'AAA', 'BBB')"); @@ -154,8 +172,11 @@ public class RenameColumnTaskTest extends BaseTest { } - @Test - public void testColumnDoesntAlreadyExist() throws SQLException { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("data") + public void testColumnDoesntAlreadyExist(Supplier theTestDatabaseDetails) throws SQLException { + before(theTestDatabaseDetails); + executeSql("create table SOMETABLE (PID bigint not null, myTextCol varchar(255))"); RenameColumnTask task = new RenameColumnTask("1", "1"); @@ -170,8 +191,11 @@ public class RenameColumnTaskTest extends BaseTest { assertThat(JdbcUtils.getColumnNames(getConnectionProperties(), "SOMETABLE"), containsInAnyOrder("PID", "TEXTCOL")); } - @Test - public void testForeignKeyColumnDoesntAlreadyExist_MySql() throws SQLException { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("data") + public void testForeignKeyColumnDoesntAlreadyExist_MySql(Supplier theTestDatabaseDetails) throws SQLException { + before(theTestDatabaseDetails); + testForeignKeyColumnDoesntAlreadyExist(true); } @@ -201,13 +225,19 @@ public class RenameColumnTaskTest extends BaseTest { } - @Test - public void testForeignKeyColumnDoesntAlreadyExist_OtherDB() throws SQLException { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("data") + public void testForeignKeyColumnDoesntAlreadyExist_OtherDB(Supplier theTestDatabaseDetails) throws SQLException { + before(theTestDatabaseDetails); + testForeignKeyColumnDoesntAlreadyExist(false); } - @Test - public void testNeitherColumnExists() { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("data") + public void testNeitherColumnExists(Supplier theTestDatabaseDetails) { + before(theTestDatabaseDetails); + executeSql("create table SOMETABLE (PID bigint not null)"); RenameColumnTask task = new RenameColumnTask("1", "1"); @@ -226,8 +256,11 @@ public class RenameColumnTaskTest extends BaseTest { } - @Test - public void testNeitherColumnExistsButAllowed() { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("data") + public void testNeitherColumnExistsButAllowed(Supplier theTestDatabaseDetails) { + before(theTestDatabaseDetails); + executeSql("create table SOMETABLE (PID bigint not null)"); RenameColumnTask task = new RenameColumnTask("1", "1"); @@ -240,8 +273,11 @@ public class RenameColumnTaskTest extends BaseTest { getMigrator().migrate(); } - @Test - public void testBothColumnsExist() { + @ParameterizedTest(name = "{index}: {0}") + @MethodSource("data") + public void testBothColumnsExist(Supplier theTestDatabaseDetails) { + before(theTestDatabaseDetails); + executeSql("create table SOMETABLE (PID bigint not null, PID2 bigint)"); RenameColumnTask task = new RenameColumnTask("1", "1"); diff --git a/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/tasks/HapiFhirJpaMigrationTasksTest.java b/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/tasks/HapiFhirJpaMigrationTasksTest.java index ef2110c2fb1..6f6921844cc 100644 --- a/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/tasks/HapiFhirJpaMigrationTasksTest.java +++ b/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/tasks/HapiFhirJpaMigrationTasksTest.java @@ -1,6 +1,6 @@ package ca.uhn.fhir.jpa.migrate.tasks; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.Collections; diff --git a/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/tasks/api/BaseMigrationTasksTest.java b/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/tasks/api/BaseMigrationTasksTest.java index 8b263688bed..8bd1243d284 100644 --- a/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/tasks/api/BaseMigrationTasksTest.java +++ b/hapi-fhir-jpaserver-migrate/src/test/java/ca/uhn/fhir/jpa/migrate/tasks/api/BaseMigrationTasksTest.java @@ -2,13 +2,13 @@ package ca.uhn.fhir.jpa.migrate.tasks.api; import ca.uhn.fhir.jpa.migrate.taskdef.BaseTask; import ca.uhn.fhir.jpa.migrate.taskdef.DropTableTask; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.ArrayList; import java.util.List; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; public class BaseMigrationTasksTest { static class MyMigrationTasks extends BaseMigrationTasks { diff --git a/hapi-fhir-jpaserver-model/src/test/java/ca/uhn/fhir/jpa/model/entity/ResourceIndexedSearchParamCoordsTest.java b/hapi-fhir-jpaserver-model/src/test/java/ca/uhn/fhir/jpa/model/entity/ResourceIndexedSearchParamCoordsTest.java index 0e3865e2038..f7bf7a5624a 100644 --- a/hapi-fhir-jpaserver-model/src/test/java/ca/uhn/fhir/jpa/model/entity/ResourceIndexedSearchParamCoordsTest.java +++ b/hapi-fhir-jpaserver-model/src/test/java/ca/uhn/fhir/jpa/model/entity/ResourceIndexedSearchParamCoordsTest.java @@ -1,10 +1,10 @@ package ca.uhn.fhir.jpa.model.entity; import ca.uhn.fhir.jpa.model.config.PartitionSettings; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; public class ResourceIndexedSearchParamCoordsTest { diff --git a/hapi-fhir-jpaserver-model/src/test/java/ca/uhn/fhir/jpa/model/entity/ResourceIndexedSearchParamDateTest.java b/hapi-fhir-jpaserver-model/src/test/java/ca/uhn/fhir/jpa/model/entity/ResourceIndexedSearchParamDateTest.java index de12b8555f4..711682979c7 100644 --- a/hapi-fhir-jpaserver-model/src/test/java/ca/uhn/fhir/jpa/model/entity/ResourceIndexedSearchParamDateTest.java +++ b/hapi-fhir-jpaserver-model/src/test/java/ca/uhn/fhir/jpa/model/entity/ResourceIndexedSearchParamDateTest.java @@ -1,24 +1,24 @@ package ca.uhn.fhir.jpa.model.entity; import ca.uhn.fhir.jpa.model.config.PartitionSettings; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.sql.Timestamp; import java.util.Calendar; import java.util.Date; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; public class ResourceIndexedSearchParamDateTest { private Date date1A, date1B, date2A, date2B; private Timestamp timestamp1A, timestamp1B, timestamp2A, timestamp2B; - @Before + @BeforeEach public void setUp() throws Exception { Calendar cal1 = Calendar.getInstance(); cal1.set(1970, 01, 01, 10, 23, 33); @@ -40,7 +40,7 @@ public class ResourceIndexedSearchParamDateTest { @Test public void equalsIsTrueForMatchingNullDates() { ResourceIndexedSearchParamDate param = new ResourceIndexedSearchParamDate(new PartitionSettings(), "Patient", "SomeResource", null, null, null, null, "SomeValue"); - ResourceIndexedSearchParamDate param2 = new ResourceIndexedSearchParamDate(new PartitionSettings(),"Patient", "SomeResource", null, null, null, null, "SomeValue"); + ResourceIndexedSearchParamDate param2 = new ResourceIndexedSearchParamDate(new PartitionSettings(), "Patient", "SomeResource", null, null, null, null, "SomeValue"); assertTrue(param.equals(param2)); assertTrue(param2.equals(param)); @@ -49,8 +49,8 @@ public class ResourceIndexedSearchParamDateTest { @Test public void equalsIsTrueForMatchingDates() { - ResourceIndexedSearchParamDate param = new ResourceIndexedSearchParamDate(new PartitionSettings(),"Patient", "SomeResource", date1A, null, date2A, null, "SomeValue"); - ResourceIndexedSearchParamDate param2 = new ResourceIndexedSearchParamDate(new PartitionSettings(),"Patient", "SomeResource", date1B, null, date2B, null, "SomeValue"); + ResourceIndexedSearchParamDate param = new ResourceIndexedSearchParamDate(new PartitionSettings(), "Patient", "SomeResource", date1A, null, date2A, null, "SomeValue"); + ResourceIndexedSearchParamDate param2 = new ResourceIndexedSearchParamDate(new PartitionSettings(), "Patient", "SomeResource", date1B, null, date2B, null, "SomeValue"); assertTrue(param.equals(param2)); assertTrue(param2.equals(param)); @@ -59,8 +59,8 @@ public class ResourceIndexedSearchParamDateTest { @Test public void equalsIsTrueForMatchingTimeStampsThatMatch() { - ResourceIndexedSearchParamDate param = new ResourceIndexedSearchParamDate(new PartitionSettings(),"Patient", "SomeResource", timestamp1A, null, timestamp2A, null, "SomeValue"); - ResourceIndexedSearchParamDate param2 = new ResourceIndexedSearchParamDate(new PartitionSettings(),"Patient", "SomeResource", timestamp1B, null, timestamp2B, null, "SomeValue"); + ResourceIndexedSearchParamDate param = new ResourceIndexedSearchParamDate(new PartitionSettings(), "Patient", "SomeResource", timestamp1A, null, timestamp2A, null, "SomeValue"); + ResourceIndexedSearchParamDate param2 = new ResourceIndexedSearchParamDate(new PartitionSettings(), "Patient", "SomeResource", timestamp1B, null, timestamp2B, null, "SomeValue"); assertTrue(param.equals(param2)); assertTrue(param2.equals(param)); @@ -71,8 +71,8 @@ public class ResourceIndexedSearchParamDateTest { // other will be equivalent but will be a java.sql.Timestamp. Equals should work in both directions. @Test public void equalsIsTrueForMixedTimestampsAndDates() { - ResourceIndexedSearchParamDate param = new ResourceIndexedSearchParamDate(new PartitionSettings(),"Patient", "SomeResource", date1A, null, date2A, null, "SomeValue"); - ResourceIndexedSearchParamDate param2 = new ResourceIndexedSearchParamDate(new PartitionSettings(),"Patient", "SomeResource", timestamp1A, null, timestamp2A, null, "SomeValue"); + ResourceIndexedSearchParamDate param = new ResourceIndexedSearchParamDate(new PartitionSettings(), "Patient", "SomeResource", date1A, null, date2A, null, "SomeValue"); + ResourceIndexedSearchParamDate param2 = new ResourceIndexedSearchParamDate(new PartitionSettings(), "Patient", "SomeResource", timestamp1A, null, timestamp2A, null, "SomeValue"); assertTrue(param.equals(param2)); assertTrue(param2.equals(param)); @@ -81,8 +81,8 @@ public class ResourceIndexedSearchParamDateTest { @Test public void equalsIsFalseForNonMatchingDates() { - ResourceIndexedSearchParamDate param = new ResourceIndexedSearchParamDate(new PartitionSettings(),"Patient", "SomeResource", date1A, null, date2A, null, "SomeValue"); - ResourceIndexedSearchParamDate param2 = new ResourceIndexedSearchParamDate(new PartitionSettings(),"Patient", "SomeResource", date2A, null, date1A, null, "SomeValue"); + ResourceIndexedSearchParamDate param = new ResourceIndexedSearchParamDate(new PartitionSettings(), "Patient", "SomeResource", date1A, null, date2A, null, "SomeValue"); + ResourceIndexedSearchParamDate param2 = new ResourceIndexedSearchParamDate(new PartitionSettings(), "Patient", "SomeResource", date2A, null, date1A, null, "SomeValue"); assertFalse(param.equals(param2)); assertFalse(param2.equals(param)); @@ -91,8 +91,8 @@ public class ResourceIndexedSearchParamDateTest { @Test public void equalsIsFalseForNonMatchingDatesNullCase() { - ResourceIndexedSearchParamDate param = new ResourceIndexedSearchParamDate(new PartitionSettings(),"Patient", "SomeResource", date1A, null, date2A, null, "SomeValue"); - ResourceIndexedSearchParamDate param2 = new ResourceIndexedSearchParamDate(new PartitionSettings(),"Patient", "SomeResource", null, null, null, null, "SomeValue"); + ResourceIndexedSearchParamDate param = new ResourceIndexedSearchParamDate(new PartitionSettings(), "Patient", "SomeResource", date1A, null, date2A, null, "SomeValue"); + ResourceIndexedSearchParamDate param2 = new ResourceIndexedSearchParamDate(new PartitionSettings(), "Patient", "SomeResource", null, null, null, null, "SomeValue"); assertFalse(param.equals(param2)); assertFalse(param2.equals(param)); @@ -101,8 +101,8 @@ public class ResourceIndexedSearchParamDateTest { @Test public void equalsIsFalseForNonMatchingTimeStamps() { - ResourceIndexedSearchParamDate param = new ResourceIndexedSearchParamDate(new PartitionSettings(),"Patient", "SomeResource", timestamp1A, null, timestamp2A, null, "SomeValue"); - ResourceIndexedSearchParamDate param2 = new ResourceIndexedSearchParamDate(new PartitionSettings(),"Patient", "SomeResource", timestamp2A, null, timestamp1A, null, "SomeValue"); + ResourceIndexedSearchParamDate param = new ResourceIndexedSearchParamDate(new PartitionSettings(), "Patient", "SomeResource", timestamp1A, null, timestamp2A, null, "SomeValue"); + ResourceIndexedSearchParamDate param2 = new ResourceIndexedSearchParamDate(new PartitionSettings(), "Patient", "SomeResource", timestamp2A, null, timestamp1A, null, "SomeValue"); assertFalse(param.equals(param2)); assertFalse(param2.equals(param)); @@ -111,8 +111,8 @@ public class ResourceIndexedSearchParamDateTest { @Test public void equalsIsFalseForMixedTimestampsAndDatesThatDoNotMatch() { - ResourceIndexedSearchParamDate param = new ResourceIndexedSearchParamDate(new PartitionSettings(),"Patient", "SomeResource", date1A, null, date2A, null, "SomeValue"); - ResourceIndexedSearchParamDate param2 = new ResourceIndexedSearchParamDate(new PartitionSettings(),"Patient", "SomeResource", timestamp2A, null, timestamp1A, null, "SomeValue"); + ResourceIndexedSearchParamDate param = new ResourceIndexedSearchParamDate(new PartitionSettings(), "Patient", "SomeResource", date1A, null, date2A, null, "SomeValue"); + ResourceIndexedSearchParamDate param2 = new ResourceIndexedSearchParamDate(new PartitionSettings(), "Patient", "SomeResource", timestamp2A, null, timestamp1A, null, "SomeValue"); assertFalse(param.equals(param2)); assertFalse(param2.equals(param)); diff --git a/hapi-fhir-jpaserver-model/src/test/java/ca/uhn/fhir/jpa/model/entity/ResourceIndexedSearchParamQuantityTest.java b/hapi-fhir-jpaserver-model/src/test/java/ca/uhn/fhir/jpa/model/entity/ResourceIndexedSearchParamQuantityTest.java index 1e1fda3fd2c..f97fe51dc21 100644 --- a/hapi-fhir-jpaserver-model/src/test/java/ca/uhn/fhir/jpa/model/entity/ResourceIndexedSearchParamQuantityTest.java +++ b/hapi-fhir-jpaserver-model/src/test/java/ca/uhn/fhir/jpa/model/entity/ResourceIndexedSearchParamQuantityTest.java @@ -1,12 +1,12 @@ package ca.uhn.fhir.jpa.model.entity; import ca.uhn.fhir.jpa.model.config.PartitionSettings; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.math.BigDecimal; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; public class ResourceIndexedSearchParamQuantityTest { diff --git a/hapi-fhir-jpaserver-model/src/test/java/ca/uhn/fhir/jpa/model/entity/ResourceIndexedSearchParamStringTest.java b/hapi-fhir-jpaserver-model/src/test/java/ca/uhn/fhir/jpa/model/entity/ResourceIndexedSearchParamStringTest.java index 0db843825fb..3a762172e52 100644 --- a/hapi-fhir-jpaserver-model/src/test/java/ca/uhn/fhir/jpa/model/entity/ResourceIndexedSearchParamStringTest.java +++ b/hapi-fhir-jpaserver-model/src/test/java/ca/uhn/fhir/jpa/model/entity/ResourceIndexedSearchParamStringTest.java @@ -1,10 +1,10 @@ package ca.uhn.fhir.jpa.model.entity; import ca.uhn.fhir.jpa.model.config.PartitionSettings; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; @SuppressWarnings("SpellCheckingInspection") public class ResourceIndexedSearchParamStringTest { diff --git a/hapi-fhir-jpaserver-model/src/test/java/ca/uhn/fhir/jpa/model/entity/ResourceIndexedSearchParamTokenTest.java b/hapi-fhir-jpaserver-model/src/test/java/ca/uhn/fhir/jpa/model/entity/ResourceIndexedSearchParamTokenTest.java index ae5e6151a1d..0d1e0cae29c 100644 --- a/hapi-fhir-jpaserver-model/src/test/java/ca/uhn/fhir/jpa/model/entity/ResourceIndexedSearchParamTokenTest.java +++ b/hapi-fhir-jpaserver-model/src/test/java/ca/uhn/fhir/jpa/model/entity/ResourceIndexedSearchParamTokenTest.java @@ -1,10 +1,10 @@ package ca.uhn.fhir.jpa.model.entity; import ca.uhn.fhir.jpa.model.config.PartitionSettings; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; public class ResourceIndexedSearchParamTokenTest { diff --git a/hapi-fhir-jpaserver-model/src/test/java/ca/uhn/fhir/jpa/model/entity/ResourceIndexedSearchParamUriTest.java b/hapi-fhir-jpaserver-model/src/test/java/ca/uhn/fhir/jpa/model/entity/ResourceIndexedSearchParamUriTest.java index 8147135b367..81a862a5b34 100644 --- a/hapi-fhir-jpaserver-model/src/test/java/ca/uhn/fhir/jpa/model/entity/ResourceIndexedSearchParamUriTest.java +++ b/hapi-fhir-jpaserver-model/src/test/java/ca/uhn/fhir/jpa/model/entity/ResourceIndexedSearchParamUriTest.java @@ -1,10 +1,10 @@ package ca.uhn.fhir.jpa.model.entity; import ca.uhn.fhir.jpa.model.config.PartitionSettings; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; public class ResourceIndexedSearchParamUriTest { diff --git a/hapi-fhir-jpaserver-model/src/test/java/ca/uhn/fhir/jpa/model/entity/ResourceTableTest.java b/hapi-fhir-jpaserver-model/src/test/java/ca/uhn/fhir/jpa/model/entity/ResourceTableTest.java index aaec502ecd1..c9da8de81a2 100644 --- a/hapi-fhir-jpaserver-model/src/test/java/ca/uhn/fhir/jpa/model/entity/ResourceTableTest.java +++ b/hapi-fhir-jpaserver-model/src/test/java/ca/uhn/fhir/jpa/model/entity/ResourceTableTest.java @@ -1,9 +1,9 @@ package ca.uhn.fhir.jpa.model.entity; import ca.uhn.fhir.context.FhirContext; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; public class ResourceTableTest { diff --git a/hapi-fhir-jpaserver-model/src/test/java/ca/uhn/fhir/jpa/model/entity/TagDefinitionTest.java b/hapi-fhir-jpaserver-model/src/test/java/ca/uhn/fhir/jpa/model/entity/TagDefinitionTest.java index 49979e35345..d5cd0432175 100644 --- a/hapi-fhir-jpaserver-model/src/test/java/ca/uhn/fhir/jpa/model/entity/TagDefinitionTest.java +++ b/hapi-fhir-jpaserver-model/src/test/java/ca/uhn/fhir/jpa/model/entity/TagDefinitionTest.java @@ -1,9 +1,9 @@ package ca.uhn.fhir.jpa.model.entity; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; public class TagDefinitionTest { diff --git a/hapi-fhir-jpaserver-model/src/test/java/ca/uhn/fhir/jpa/model/entity/TagTypeEnumTest.java b/hapi-fhir-jpaserver-model/src/test/java/ca/uhn/fhir/jpa/model/entity/TagTypeEnumTest.java index 1c8c701b926..011b8e47c31 100644 --- a/hapi-fhir-jpaserver-model/src/test/java/ca/uhn/fhir/jpa/model/entity/TagTypeEnumTest.java +++ b/hapi-fhir-jpaserver-model/src/test/java/ca/uhn/fhir/jpa/model/entity/TagTypeEnumTest.java @@ -1,14 +1,14 @@ package ca.uhn.fhir.jpa.model.entity; import ca.uhn.fhir.util.TestUtil; -import org.junit.AfterClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public class TagTypeEnumTest { - @AfterClass + @AfterAll public static void afterClassClearContext() { TestUtil.clearAllStaticFieldsForUnitTest(); } diff --git a/hapi-fhir-jpaserver-model/src/test/java/ca/uhn/fhir/jpa/model/util/StringUtilTest.java b/hapi-fhir-jpaserver-model/src/test/java/ca/uhn/fhir/jpa/model/util/StringUtilTest.java index ee71b049e8c..aa6ad21e123 100644 --- a/hapi-fhir-jpaserver-model/src/test/java/ca/uhn/fhir/jpa/model/util/StringUtilTest.java +++ b/hapi-fhir-jpaserver-model/src/test/java/ca/uhn/fhir/jpa/model/util/StringUtilTest.java @@ -2,7 +2,7 @@ package ca.uhn.fhir.jpa.model.util; import ca.uhn.fhir.util.StringUtil; import com.google.common.base.Charsets; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.BufferedWriter; import java.io.ByteArrayOutputStream; @@ -10,7 +10,7 @@ import java.io.IOException; import java.io.OutputStreamWriter; import java.nio.charset.StandardCharsets; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public class StringUtilTest { @Test diff --git a/hapi-fhir-jpaserver-searchparam/src/test/java/ca/uhn/fhir/jpa/searchparam/IndexStressTest.java b/hapi-fhir-jpaserver-searchparam/src/test/java/ca/uhn/fhir/jpa/searchparam/IndexStressTest.java index 70d281668f8..cd6ffa86f18 100644 --- a/hapi-fhir-jpaserver-searchparam/src/test/java/ca/uhn/fhir/jpa/searchparam/IndexStressTest.java +++ b/hapi-fhir-jpaserver-searchparam/src/test/java/ca/uhn/fhir/jpa/searchparam/IndexStressTest.java @@ -13,7 +13,7 @@ import org.hl7.fhir.common.hapi.validation.support.CachingValidationSupport; import ca.uhn.fhir.context.support.DefaultProfileValidationSupport; import org.hl7.fhir.common.hapi.validation.support.ValidationSupportChain; import org.hl7.fhir.dstu3.model.Patient; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -21,7 +21,7 @@ import java.util.Map; import java.util.Set; import java.util.stream.Collectors; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.any; import static org.mockito.Mockito.mock; diff --git a/hapi-fhir-jpaserver-searchparam/src/test/java/ca/uhn/fhir/jpa/searchparam/extractor/ResourceIndexedSearchParamsTest.java b/hapi-fhir-jpaserver-searchparam/src/test/java/ca/uhn/fhir/jpa/searchparam/extractor/ResourceIndexedSearchParamsTest.java index 9ad2b47360a..3688f523317 100644 --- a/hapi-fhir-jpaserver-searchparam/src/test/java/ca/uhn/fhir/jpa/searchparam/extractor/ResourceIndexedSearchParamsTest.java +++ b/hapi-fhir-jpaserver-searchparam/src/test/java/ca/uhn/fhir/jpa/searchparam/extractor/ResourceIndexedSearchParamsTest.java @@ -5,8 +5,8 @@ import ca.uhn.fhir.jpa.model.entity.ResourceLink; import ca.uhn.fhir.jpa.model.entity.ResourceTable; import ca.uhn.fhir.rest.param.ReferenceParam; import com.google.common.collect.Lists; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.util.Date; import java.util.List; @@ -14,9 +14,9 @@ import java.util.Set; import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.empty; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertTrue; public class ResourceIndexedSearchParamsTest { @@ -26,7 +26,7 @@ public class ResourceIndexedSearchParamsTest { private ResourceTable mySource; private ModelConfig myModelConfig = new ModelConfig(); - @Before + @BeforeEach public void before() { mySource = new ResourceTable(); mySource.setResourceType("Patient"); diff --git a/hapi-fhir-jpaserver-searchparam/src/test/java/ca/uhn/fhir/jpa/searchparam/extractor/SearchParamExtractorDstu3Test.java b/hapi-fhir-jpaserver-searchparam/src/test/java/ca/uhn/fhir/jpa/searchparam/extractor/SearchParamExtractorDstu3Test.java index 13a28f162d2..92f503d3a47 100644 --- a/hapi-fhir-jpaserver-searchparam/src/test/java/ca/uhn/fhir/jpa/searchparam/extractor/SearchParamExtractorDstu3Test.java +++ b/hapi-fhir-jpaserver-searchparam/src/test/java/ca/uhn/fhir/jpa/searchparam/extractor/SearchParamExtractorDstu3Test.java @@ -30,9 +30,9 @@ import org.hl7.fhir.dstu3.model.Location; import org.hl7.fhir.dstu3.model.Observation; import org.hl7.fhir.dstu3.model.Patient; import org.hl7.fhir.dstu3.model.Questionnaire; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import java.text.Normalizer; import java.util.ArrayList; @@ -44,8 +44,8 @@ import java.util.Set; import java.util.stream.Collectors; import java.util.stream.IntStream; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; public class SearchParamExtractorDstu3Test { @@ -299,12 +299,12 @@ public class SearchParamExtractorDstu3Test { } } - @AfterClass + @AfterAll public static void afterClassClearContext() { TestUtil.clearAllStaticFieldsForUnitTest(); } - @BeforeClass + @BeforeAll public static void beforeClass() { ourValidationSupport = new DefaultProfileValidationSupport(ourCtx); } diff --git a/hapi-fhir-jpaserver-searchparam/src/test/java/ca/uhn/fhir/jpa/searchparam/extractor/SearchParamExtractorMegaTest.java b/hapi-fhir-jpaserver-searchparam/src/test/java/ca/uhn/fhir/jpa/searchparam/extractor/SearchParamExtractorMegaTest.java index ac2e2347a5b..b1a2373c26e 100644 --- a/hapi-fhir-jpaserver-searchparam/src/test/java/ca/uhn/fhir/jpa/searchparam/extractor/SearchParamExtractorMegaTest.java +++ b/hapi-fhir-jpaserver-searchparam/src/test/java/ca/uhn/fhir/jpa/searchparam/extractor/SearchParamExtractorMegaTest.java @@ -26,7 +26,7 @@ import org.hl7.fhir.instance.model.api.IBase; import org.hl7.fhir.instance.model.api.IBaseEnumeration; import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IPrimitiveType; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -38,7 +38,7 @@ import java.util.Map; import java.util.Set; import java.util.concurrent.atomic.AtomicInteger; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public class SearchParamExtractorMegaTest { @@ -214,7 +214,7 @@ public class SearchParamExtractorMegaTest { theIndexesCounter.addAndGet(set.size()); set = theExtractor.extractSearchParamQuantity(resource); - assertEquals(String.join("\n", set.getWarnings()), 0, set.getWarnings().size()); + assertEquals(0, set.getWarnings().size(), String.join("\n", set.getWarnings())); theIndexesCounter.addAndGet(set.size()); set = theExtractor.extractSearchParamTokens(resource); diff --git a/hapi-fhir-jpaserver-searchparam/src/test/java/ca/uhn/fhir/jpa/searchparam/extractor/SearchParamExtractorServiceTest.java b/hapi-fhir-jpaserver-searchparam/src/test/java/ca/uhn/fhir/jpa/searchparam/extractor/SearchParamExtractorServiceTest.java index afd7408cf36..36fe6d35eed 100644 --- a/hapi-fhir-jpaserver-searchparam/src/test/java/ca/uhn/fhir/jpa/searchparam/extractor/SearchParamExtractorServiceTest.java +++ b/hapi-fhir-jpaserver-searchparam/src/test/java/ca/uhn/fhir/jpa/searchparam/extractor/SearchParamExtractorServiceTest.java @@ -2,20 +2,20 @@ package ca.uhn.fhir.jpa.searchparam.extractor; import ca.uhn.fhir.interceptor.api.IInterceptorBroadcaster; import ca.uhn.fhir.interceptor.api.Pointcut; -import ca.uhn.fhir.rest.api.server.RequestDetails; import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; -import org.springframework.beans.factory.annotation.Autowired; +import org.mockito.junit.jupiter.MockitoExtension; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class SearchParamExtractorServiceTest { private SearchParamExtractorService mySvc; @@ -24,7 +24,7 @@ public class SearchParamExtractorServiceTest { @Mock private IInterceptorBroadcaster myJpaInterceptorBroadcaster; - @Before + @BeforeEach public void before() { mySvc = new SearchParamExtractorService(); mySvc.setInterceptorBroadcasterForUnitTest(myJpaInterceptorBroadcaster); diff --git a/hapi-fhir-jpaserver-searchparam/src/test/java/ca/uhn/fhir/jpa/searchparam/matcher/InMemoryResourceMatcherR5Test.java b/hapi-fhir-jpaserver-searchparam/src/test/java/ca/uhn/fhir/jpa/searchparam/matcher/InMemoryResourceMatcherR5Test.java index 058002f419b..3bf430cab2c 100644 --- a/hapi-fhir-jpaserver-searchparam/src/test/java/ca/uhn/fhir/jpa/searchparam/matcher/InMemoryResourceMatcherR5Test.java +++ b/hapi-fhir-jpaserver-searchparam/src/test/java/ca/uhn/fhir/jpa/searchparam/matcher/InMemoryResourceMatcherR5Test.java @@ -17,69 +17,44 @@ import org.hl7.fhir.r5.model.BaseDateTimeType; import org.hl7.fhir.r5.model.CodeableConcept; import org.hl7.fhir.r5.model.DateTimeType; import org.hl7.fhir.r5.model.Observation; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import java.time.Duration; import java.time.Instant; import java.time.ZonedDateTime; import java.util.Date; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.when; -@RunWith(SpringRunner.class) +@ExtendWith(SpringExtension.class) public class InMemoryResourceMatcherR5Test { public static final String OBSERVATION_DATE = "1970-10-17"; + public static final String OBSERVATION_CODE = "MATCH"; private static final String EARLY_DATE = "1965-08-09"; private static final String LATE_DATE = "2000-06-29"; - public static final String OBSERVATION_CODE = "MATCH"; private static final String SOURCE_URI = "urn:source:0"; private static final String REQUEST_ID = "a_request_id"; private static final String TEST_SOURCE = SOURCE_URI + "#" + REQUEST_ID; - - @Autowired - private InMemoryResourceMatcher myInMemoryResourceMatcher; - @MockBean ISearchParamRegistry mySearchParamRegistry; + @Autowired + private InMemoryResourceMatcher myInMemoryResourceMatcher; private Observation myObservation; private ResourceIndexedSearchParams mySearchParams; - @Configuration - public static class SpringConfig { - @Bean - InMemoryResourceMatcher inMemoryResourceMatcher() { - return new InMemoryResourceMatcher(); - } - - @Bean - MatchUrlService matchUrlService() { - return new MatchUrlService(); - } - - @Bean - FhirContext fhirContext() { - return FhirContext.forR5(); - } - - @Bean - ModelConfig modelConfig() { - return new ModelConfig(); - } - } - - @Before + @BeforeEach public void before() { RuntimeSearchParam dateSearchParam = new RuntimeSearchParam(null, null, null, null, "Observation.effective", RestSearchParameterTypeEnum.DATE, null, null, null, RuntimeSearchParam.RuntimeSearchParamStatusEnum.ACTIVE); when(mySearchParamRegistry.getSearchParamByName(any(), eq("date"))).thenReturn(dateSearchParam); @@ -163,17 +138,17 @@ public class InMemoryResourceMatcherR5Test { String equation = "date=" + theOperator.getValue(); { InMemoryMatchResult result = myInMemoryResourceMatcher.match(equation + EARLY_DATE, myObservation, mySearchParams); - assertTrue(result.getUnsupportedReason(), result.supported()); + assertTrue(result.supported(), result.getUnsupportedReason()); assertEquals(result.matched(), theEarly); } { InMemoryMatchResult result = myInMemoryResourceMatcher.match(equation + OBSERVATION_DATE, myObservation, mySearchParams); - assertTrue(result.getUnsupportedReason(), result.supported()); - assertEquals(theSame, result.matched()); + assertTrue(result.supported(), result.getUnsupportedReason()); + assertEquals(result.matched(), theSame); } { InMemoryMatchResult result = myInMemoryResourceMatcher.match(equation + LATE_DATE, myObservation, mySearchParams); - assertTrue(result.getUnsupportedReason(), result.supported()); + assertTrue(result.supported(), result.getUnsupportedReason()); assertEquals(result.matched(), theLater); } } @@ -181,7 +156,7 @@ public class InMemoryResourceMatcherR5Test { @Test public void testNowPast() { InMemoryMatchResult result = myInMemoryResourceMatcher.match("date=lt" + BaseDateTimeDt.NOW_DATE_CONSTANT, myObservation, mySearchParams); - assertTrue(result.getUnsupportedReason(), result.supported()); + assertTrue(result.supported(), result.getUnsupportedReason()); assertTrue(result.matched()); } @@ -193,7 +168,7 @@ public class InMemoryResourceMatcherR5Test { ResourceIndexedSearchParams searchParams = extractDateSearchParam(futureObservation); InMemoryMatchResult result = myInMemoryResourceMatcher.match("date=gt" + BaseDateTimeDt.NOW_DATE_CONSTANT, futureObservation, searchParams); - assertTrue(result.getUnsupportedReason(), result.supported()); + assertTrue(result.supported(), result.getUnsupportedReason()); assertTrue(result.matched()); } @@ -205,14 +180,14 @@ public class InMemoryResourceMatcherR5Test { ResourceIndexedSearchParams searchParams = extractDateSearchParam(futureObservation); InMemoryMatchResult result = myInMemoryResourceMatcher.match("date=gt" + BaseDateTimeDt.NOW_DATE_CONSTANT, futureObservation, searchParams); - assertTrue(result.getUnsupportedReason(), result.supported()); + assertTrue(result.supported(), result.getUnsupportedReason()); assertTrue(result.matched()); } @Test public void testTodayPast() { InMemoryMatchResult result = myInMemoryResourceMatcher.match("date=lt" + BaseDateTimeDt.TODAY_DATE_CONSTANT, myObservation, mySearchParams); - assertTrue(result.getUnsupportedReason(), result.supported()); + assertTrue(result.supported(), result.getUnsupportedReason()); assertTrue(result.matched()); } @@ -224,7 +199,7 @@ public class InMemoryResourceMatcherR5Test { ResourceIndexedSearchParams searchParams = extractDateSearchParam(futureObservation); InMemoryMatchResult result = myInMemoryResourceMatcher.match("date=gt" + BaseDateTimeDt.TODAY_DATE_CONSTANT, futureObservation, searchParams); - assertTrue(result.getUnsupportedReason(), result.supported()); + assertTrue(result.supported(), result.getUnsupportedReason()); assertTrue(result.matched()); } @@ -236,7 +211,7 @@ public class InMemoryResourceMatcherR5Test { ResourceIndexedSearchParams searchParams = extractDateSearchParam(futureObservation); InMemoryMatchResult result = myInMemoryResourceMatcher.match("date=gt" + BaseDateTimeDt.TODAY_DATE_CONSTANT, futureObservation, searchParams); - assertTrue(result.getUnsupportedReason(), result.supported()); + assertTrue(result.supported(), result.getUnsupportedReason()); assertTrue(result.matched()); } @@ -248,7 +223,7 @@ public class InMemoryResourceMatcherR5Test { ResourceIndexedSearchParams searchParams = extractDateSearchParam(futureObservation); InMemoryMatchResult result = myInMemoryResourceMatcher.match("date=gt" + BaseDateTimeDt.TODAY_DATE_CONSTANT, futureObservation, searchParams); - assertTrue(result.getUnsupportedReason(), result.supported()); + assertTrue(result.supported(), result.getUnsupportedReason()); assertFalse(result.matched()); } @@ -266,7 +241,7 @@ public class InMemoryResourceMatcherR5Test { ResourceIndexedSearchParams searchParams = extractDateSearchParam(futureObservation); InMemoryMatchResult result = myInMemoryResourceMatcher.match("date=gt" + BaseDateTimeDt.TODAY_DATE_CONSTANT, futureObservation, searchParams); - assertTrue(result.getUnsupportedReason(), result.supported()); + assertTrue(result.supported(), result.getUnsupportedReason()); assertFalse(result.matched()); } @@ -279,4 +254,27 @@ public class InMemoryResourceMatcherR5Test { return retval; } + @Configuration + public static class SpringConfig { + @Bean + InMemoryResourceMatcher inMemoryResourceMatcher() { + return new InMemoryResourceMatcher(); + } + + @Bean + MatchUrlService matchUrlService() { + return new MatchUrlService(); + } + + @Bean + FhirContext fhirContext() { + return FhirContext.forR5(); + } + + @Bean + ModelConfig modelConfig() { + return new ModelConfig(); + } + } + } diff --git a/hapi-fhir-jpaserver-searchparam/src/test/java/ca/uhn/fhir/jpa/searchparam/registry/SearchParamRegistryImplTest.java b/hapi-fhir-jpaserver-searchparam/src/test/java/ca/uhn/fhir/jpa/searchparam/registry/SearchParamRegistryImplTest.java index a7b15951a45..43eab94aa59 100644 --- a/hapi-fhir-jpaserver-searchparam/src/test/java/ca/uhn/fhir/jpa/searchparam/registry/SearchParamRegistryImplTest.java +++ b/hapi-fhir-jpaserver-searchparam/src/test/java/ca/uhn/fhir/jpa/searchparam/registry/SearchParamRegistryImplTest.java @@ -12,27 +12,29 @@ import org.hl7.fhir.instance.model.api.IPrimitiveType; import org.hl7.fhir.r4.model.Enumerations; import org.hl7.fhir.r4.model.SearchParameter; import org.hl7.fhir.r4.model.StringType; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import java.util.Map; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.Mockito.when; -@RunWith(SpringRunner.class) +@ExtendWith(SpringExtension.class) public class SearchParamRegistryImplTest { @Autowired SearchParamRegistryImpl mySearchParamRegistry; @@ -60,7 +62,7 @@ public class SearchParamRegistryImplTest { private int myAnswerCount = 0; - @Before + @BeforeEach public void before() { myAnswerCount = 0; } diff --git a/hapi-fhir-jpaserver-searchparam/src/test/java/ca/uhn/fhir/jpa/searchparam/retry/RetrierTest.java b/hapi-fhir-jpaserver-searchparam/src/test/java/ca/uhn/fhir/jpa/searchparam/retry/RetrierTest.java index edc946f09ba..51bd8ba9134 100755 --- a/hapi-fhir-jpaserver-searchparam/src/test/java/ca/uhn/fhir/jpa/searchparam/retry/RetrierTest.java +++ b/hapi-fhir-jpaserver-searchparam/src/test/java/ca/uhn/fhir/jpa/searchparam/retry/RetrierTest.java @@ -1,20 +1,16 @@ package ca.uhn.fhir.jpa.searchparam.retry; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.Test; import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Supplier; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; public class RetrierTest { - @Rule - public ExpectedException myExpectedException = ExpectedException.none(); - @Test public void happyPath() { Supplier supplier = () -> true; @@ -43,10 +39,12 @@ public class RetrierTest { }; Retrier retrier = new Retrier<>(supplier, 1); - myExpectedException.expect(RetryRuntimeException.class); - myExpectedException.expectMessage("test failure message"); - retrier.runWithRetry(); - assertEquals(5, counter.get()); + try { + retrier.runWithRetry(); + fail(); + } catch (RetryRuntimeException e) { + assertEquals("test failure message", e.getMessage()); + } } @Test @@ -56,10 +54,13 @@ public class RetrierTest { if (counter.incrementAndGet() < 10) throw new RetryRuntimeException("test"); return true; }; - myExpectedException.expect(IllegalArgumentException.class); - myExpectedException.expectMessage("maxRetries must be above zero."); - Retrier retrier = new Retrier<>(supplier, 0); - assertEquals(0, counter.get()); + + try { + new Retrier<>(supplier, 0); + fail(); + } catch (IllegalArgumentException e) { + assertEquals("maxRetries must be above zero.", e.getMessage()); + } } @Test @@ -69,10 +70,13 @@ public class RetrierTest { if (counter.incrementAndGet() < 10) throw new RetryRuntimeException("test"); return true; }; - myExpectedException.expect(IllegalArgumentException.class); - myExpectedException.expectMessage("maxRetries must be above zero."); - Retrier retrier = new Retrier<>(supplier, -1); + try { + new Retrier<>(supplier, -1); + fail(); + } catch (IllegalArgumentException e) { + assertEquals("maxRetries must be above zero.", e.getMessage()); + } assertEquals(0, counter.get()); } diff --git a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/channel/subscription/SubscriptionChannelFactoryTest.java b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/channel/subscription/SubscriptionChannelFactoryTest.java index 1e77adb5db2..4bbba1342fb 100644 --- a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/channel/subscription/SubscriptionChannelFactoryTest.java +++ b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/channel/subscription/SubscriptionChannelFactoryTest.java @@ -2,13 +2,13 @@ package ca.uhn.fhir.jpa.subscription.channel.subscription; import ca.uhn.fhir.jpa.subscription.channel.api.IChannelReceiver; import ca.uhn.fhir.jpa.subscription.channel.impl.LinkedBlockingChannelFactory; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.messaging.Message; import org.springframework.messaging.MessageDeliveryException; import org.springframework.messaging.MessageHandler; @@ -16,15 +16,15 @@ import org.springframework.messaging.MessagingException; import org.springframework.messaging.support.ChannelInterceptor; import org.springframework.messaging.support.GenericMessage; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class SubscriptionChannelFactoryTest { private SubscriptionChannelFactory mySvc; @@ -36,7 +36,7 @@ public class SubscriptionChannelFactoryTest { @Captor private ArgumentCaptor myExceptionCaptor; - @Before + @BeforeEach public void before() { when(myChannelNamer.getChannelName(any(), any())).thenReturn("CHANNEL_NAME"); mySvc = new SubscriptionChannelFactory(new LinkedBlockingChannelFactory(myChannelNamer)); diff --git a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/match/deliver/BaseSubscriptionDeliverySubscriberTest.java b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/match/deliver/BaseSubscriptionDeliverySubscriberTest.java index b4dc18f037d..512bb0a42a8 100644 --- a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/match/deliver/BaseSubscriptionDeliverySubscriberTest.java +++ b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/match/deliver/BaseSubscriptionDeliverySubscriberTest.java @@ -15,21 +15,23 @@ import ca.uhn.fhir.rest.client.api.IRestfulClientFactory; import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; import org.hl7.fhir.r4.model.IdType; import org.hl7.fhir.r4.model.Patient; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Answers; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; +import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.messaging.Message; import org.springframework.messaging.MessagingException; import org.springframework.messaging.support.GenericMessage; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class BaseSubscriptionDeliverySubscriberTest { private SubscriptionDeliveringRestHookSubscriber mySubscriber; @@ -44,7 +46,7 @@ public class BaseSubscriptionDeliverySubscriberTest { @Mock(answer = Answers.RETURNS_DEEP_STUBS) private IGenericClient myGenericClient; - @Before + @BeforeEach public void before() { mySubscriber = new SubscriptionDeliveringRestHookSubscriber(); mySubscriber.setFhirContextForUnitTest(myCtx); diff --git a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/match/matcher/matching/DaoSubscriptionMatcherTest.java b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/match/matcher/matching/DaoSubscriptionMatcherTest.java index 63cfd62b281..be4fc200af4 100644 --- a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/match/matcher/matching/DaoSubscriptionMatcherTest.java +++ b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/match/matcher/matching/DaoSubscriptionMatcherTest.java @@ -13,19 +13,19 @@ import ca.uhn.fhir.jpa.searchparam.registry.ISearchParamProvider; import ca.uhn.fhir.jpa.subscription.channel.subscription.SubscriptionChannelFactory; import ca.uhn.fhir.jpa.subscription.match.config.SubscriptionProcessorConfig; import ca.uhn.fhir.jpa.subscription.submit.config.SubscriptionSubmitterConfig; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.transaction.PlatformTransactionManager; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertNull; -@RunWith(SpringRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = { SubscriptionProcessorConfig.class, SearchParamConfig.class, diff --git a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/match/registry/ActiveSubscriptionCacheTest.java b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/match/registry/ActiveSubscriptionCacheTest.java index 7dd69d83bfa..0d8e9c82e6a 100644 --- a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/match/registry/ActiveSubscriptionCacheTest.java +++ b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/match/registry/ActiveSubscriptionCacheTest.java @@ -2,17 +2,17 @@ package ca.uhn.fhir.jpa.subscription.match.registry; import ca.uhn.fhir.jpa.subscription.model.CanonicalSubscription; import ca.uhn.fhir.model.primitive.IdDt; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.ArrayList; import java.util.List; import static org.hamcrest.Matchers.containsInAnyOrder; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertTrue; public class ActiveSubscriptionCacheTest { static final String ID1 = "id1"; diff --git a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/BaseSubscriptionDstu3Test.java b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/BaseSubscriptionDstu3Test.java index 01ba5f934d2..ef65d2a87a8 100644 --- a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/BaseSubscriptionDstu3Test.java +++ b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/BaseSubscriptionDstu3Test.java @@ -13,8 +13,8 @@ import java.util.List; import java.util.stream.Collectors; import static org.awaitility.Awaitility.await; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; @ContextConfiguration(classes = {TestSubscriptionDstu3Config.class}) public abstract class BaseSubscriptionDstu3Test extends BaseSubscriptionTest { diff --git a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/BaseSubscriptionTest.java b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/BaseSubscriptionTest.java index 0291269bb6f..b951e04afb1 100644 --- a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/BaseSubscriptionTest.java +++ b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/BaseSubscriptionTest.java @@ -12,15 +12,15 @@ import ca.uhn.fhir.jpa.subscription.match.config.SubscriptionProcessorConfig; import ca.uhn.fhir.jpa.subscription.module.config.MockFhirClientSearchParamProvider; import ca.uhn.fhir.jpa.subscription.module.config.TestSubscriptionConfig; import ca.uhn.fhir.rest.api.server.IBundleProvider; -import org.junit.After; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = { SearchParamConfig.class, SubscriptionProcessorConfig.class, @@ -38,7 +38,7 @@ public abstract class BaseSubscriptionTest { @Autowired MockFhirClientSearchParamProvider myMockFhirClientSearchParamProvider; - @After + @AfterEach public void afterClearAnonymousLambdas() { myInterceptorRegistry.unregisterAllInterceptors(); } diff --git a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/CanonicalSubscriptionTest.java b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/CanonicalSubscriptionTest.java index b0c9751cff6..254085e8d2f 100644 --- a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/CanonicalSubscriptionTest.java +++ b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/CanonicalSubscriptionTest.java @@ -9,14 +9,14 @@ import com.fasterxml.jackson.databind.ObjectMapper; import org.assertj.core.util.Lists; import org.hamcrest.Matchers; import org.hl7.fhir.r4.model.Subscription; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.IOException; import java.util.HashMap; import java.util.List; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertTrue; public class CanonicalSubscriptionTest { diff --git a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/ResourceModifiedTest.java b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/ResourceModifiedTest.java index 0d3534384eb..ebe2b40c684 100644 --- a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/ResourceModifiedTest.java +++ b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/ResourceModifiedTest.java @@ -3,10 +3,10 @@ package ca.uhn.fhir.jpa.subscription.module; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.jpa.subscription.model.ResourceModifiedMessage; import org.hl7.fhir.r4.model.Organization; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; public class ResourceModifiedTest { private FhirContext myFhirContext = FhirContext.forR4(); diff --git a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/cache/BaseSubscriptionRegistryTest.java b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/cache/BaseSubscriptionRegistryTest.java index 7931f0864dd..9575746719f 100644 --- a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/cache/BaseSubscriptionRegistryTest.java +++ b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/cache/BaseSubscriptionRegistryTest.java @@ -2,14 +2,14 @@ package ca.uhn.fhir.jpa.subscription.module.cache; import ca.uhn.fhir.jpa.subscription.module.BaseSubscriptionDstu3Test; import org.hl7.fhir.dstu3.model.Subscription; -import org.junit.After; +import org.junit.jupiter.api.AfterEach; public abstract class BaseSubscriptionRegistryTest extends BaseSubscriptionDstu3Test { public static final String SUBSCRIPTION_ID = "1"; public static final String ORIG_CRITERIA = "Patient?"; public static final String NEW_CRITERIA = "Observation?"; - @After + @AfterEach public void clearRegistryAfter() { super.clearRegistry(); } diff --git a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/cache/SubscriptionLoaderTest.java b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/cache/SubscriptionLoaderTest.java index bafc3727589..bf123afd931 100644 --- a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/cache/SubscriptionLoaderTest.java +++ b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/cache/SubscriptionLoaderTest.java @@ -2,11 +2,18 @@ package ca.uhn.fhir.jpa.subscription.module.cache; import ca.uhn.fhir.jpa.subscription.match.registry.SubscriptionLoader; import ca.uhn.fhir.jpa.subscription.module.standalone.BaseBlockingQueueSubscribableChannelDstu3Test; -import org.junit.Test; +import org.hl7.fhir.dstu3.model.Subscription; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; +import static org.junit.jupiter.api.Assertions.assertEquals; + public class SubscriptionLoaderTest extends BaseBlockingQueueSubscribableChannelDstu3Test { @Test public void testMultipleThreadsDontBlock() throws InterruptedException { diff --git a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/cache/SubscriptionRegistrySharedTest.java b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/cache/SubscriptionRegistrySharedTest.java index 884f56810e3..bec37133e26 100644 --- a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/cache/SubscriptionRegistrySharedTest.java +++ b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/cache/SubscriptionRegistrySharedTest.java @@ -3,7 +3,7 @@ package ca.uhn.fhir.jpa.subscription.module.cache; import ca.uhn.fhir.jpa.subscription.channel.subscription.ISubscriptionDeliveryChannelNamer; import ca.uhn.fhir.jpa.subscription.model.CanonicalSubscription; import org.hl7.fhir.dstu3.model.Subscription; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Primary; diff --git a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/cache/SubscriptionRegistryTest.java b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/cache/SubscriptionRegistryTest.java index 0cf1edb523f..746a6af85df 100644 --- a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/cache/SubscriptionRegistryTest.java +++ b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/cache/SubscriptionRegistryTest.java @@ -2,9 +2,9 @@ package ca.uhn.fhir.jpa.subscription.module.cache; import ca.uhn.fhir.jpa.subscription.match.registry.ActiveSubscription; import org.hl7.fhir.dstu3.model.Subscription; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; public class SubscriptionRegistryTest extends BaseSubscriptionRegistryTest { @Test diff --git a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/channel/SubscriptionChannelRegistryTest.java b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/channel/SubscriptionChannelRegistryTest.java index e45dfa473cf..7a86cd36902 100644 --- a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/channel/SubscriptionChannelRegistryTest.java +++ b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/channel/SubscriptionChannelRegistryTest.java @@ -8,21 +8,21 @@ import ca.uhn.fhir.jpa.subscription.channel.subscription.SubscriptionDeliveryHan import ca.uhn.fhir.jpa.subscription.match.registry.ActiveSubscription; import ca.uhn.fhir.jpa.subscription.model.CanonicalSubscription; import ca.uhn.fhir.model.primitive.IdDt; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -@RunWith(SpringRunner.class) +@ExtendWith(SpringExtension.class) public class SubscriptionChannelRegistryTest { private static final String TEST_CHANNEL_NAME = "TEST_CHANNEL"; @Autowired @@ -35,15 +35,6 @@ public class SubscriptionChannelRegistryTest { @MockBean ModelConfig myModelConfig; - @Configuration - static class SpringConfig { - @Bean - SubscriptionChannelRegistry subscriptionChannelRegistry() { - return new SubscriptionChannelRegistry(); - } - } - - @Test public void testAddAddRemoveRemove() { CanonicalSubscription cansubA = new CanonicalSubscription(); @@ -64,4 +55,12 @@ public class SubscriptionChannelRegistryTest { mySubscriptionChannelRegistry.remove(activeSubscriptionA); assertNull(mySubscriptionChannelRegistry.getDeliveryReceiverChannel(TEST_CHANNEL_NAME)); } + + @Configuration + static class SpringConfig { + @Bean + SubscriptionChannelRegistry subscriptionChannelRegistry() { + return new SubscriptionChannelRegistry(); + } + } } diff --git a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/matcher/InMemorySubscriptionMatcherR3Test.java b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/matcher/InMemorySubscriptionMatcherR3Test.java index dc2b5738e7c..5198c1b7236 100644 --- a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/matcher/InMemorySubscriptionMatcherR3Test.java +++ b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/matcher/InMemorySubscriptionMatcherR3Test.java @@ -14,17 +14,17 @@ import org.hl7.fhir.dstu3.model.*; import org.hl7.fhir.dstu3.model.codesystems.MedicationRequestCategory; import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IIdType; -import org.junit.After; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import java.util.Collections; import java.util.HashSet; import java.util.Set; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; public class InMemorySubscriptionMatcherR3Test extends BaseSubscriptionDstu3Test { @Autowired @@ -62,7 +62,7 @@ public class InMemorySubscriptionMatcherR3Test extends BaseSubscriptionDstu3Test assertEquals(theSubscriptionMatchingStrategy, mySubscriptionStrategyEvaluator.determineStrategy(criteria)); } - @After + @AfterEach public void after() { myModelConfig.setTreatBaseUrlsAsLocal(new ModelConfig().getTreatBaseUrlsAsLocal()); } diff --git a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/matcher/SubscriptionStrategyEvaluatorTest.java b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/matcher/SubscriptionStrategyEvaluatorTest.java index 6d01c515ac3..feb9d2a3326 100644 --- a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/matcher/SubscriptionStrategyEvaluatorTest.java +++ b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/matcher/SubscriptionStrategyEvaluatorTest.java @@ -4,21 +4,18 @@ import ca.uhn.fhir.jpa.subscription.match.matcher.matching.SubscriptionMatchingS import ca.uhn.fhir.jpa.subscription.match.matcher.matching.SubscriptionStrategyEvaluator; import ca.uhn.fhir.jpa.subscription.module.BaseSubscriptionDstu3Test; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import static org.junit.Assert.assertEquals; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; import static org.junit.matchers.JUnitMatchers.containsString; public class SubscriptionStrategyEvaluatorTest extends BaseSubscriptionDstu3Test { @Autowired SubscriptionStrategyEvaluator mySubscriptionStrategyEvaluator; - @Rule - public ExpectedException exception = ExpectedException.none(); - @Test public void testInMemory() { assertInMemory("Observation?"); @@ -39,9 +36,12 @@ public class SubscriptionStrategyEvaluatorTest extends BaseSubscriptionDstu3Test assertDatabase("Observation?code=17861-6&context.type=IHD"); assertDatabase("Observation?context.type=IHD&code=17861-6"); - exception.expect(InvalidRequestException.class); - exception.expectMessage(containsString("Resource type Observation does not have a parameter with name: codeee")); - assertInMemory("Observation?codeee=SNOMED-CT|123&_format=xml"); + try { + assertInMemory("Observation?codeee=SNOMED-CT|123&_format=xml"); + fail(); + } catch (InvalidRequestException e) { + assertThat(e.getMessage(), containsString("Resource type Observation does not have a parameter with name: codeee")); + } } private void assertDatabase(String theCriteria) { diff --git a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/standalone/BaseBlockingQueueSubscribableChannelDstu3Test.java b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/standalone/BaseBlockingQueueSubscribableChannelDstu3Test.java index 13d26edd23d..c9354c26802 100644 --- a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/standalone/BaseBlockingQueueSubscribableChannelDstu3Test.java +++ b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/standalone/BaseBlockingQueueSubscribableChannelDstu3Test.java @@ -36,10 +36,10 @@ import org.hl7.fhir.dstu3.model.IdType; import org.hl7.fhir.dstu3.model.Observation; import org.hl7.fhir.dstu3.model.Subscription; import org.hl7.fhir.instance.model.api.IBaseResource; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -96,7 +96,7 @@ public abstract class BaseBlockingQueueSubscribableChannelDstu3Test extends Base protected final PointcutLatch mySubscriptionMatchingPost = new PointcutLatch(Pointcut.SUBSCRIPTION_AFTER_PERSISTED_RESOURCE_CHECKED); protected final PointcutLatch mySubscriptionActivatedPost = new PointcutLatch(Pointcut.SUBSCRIPTION_AFTER_ACTIVE_SUBSCRIPTION_REGISTERED); - @Before + @BeforeEach public void beforeReset() { ourCreatedObservations.clear(); ourUpdatedObservations.clear(); @@ -113,7 +113,7 @@ public abstract class BaseBlockingQueueSubscribableChannelDstu3Test extends Base myInterceptorRegistry.registerAnonymousInterceptor(Pointcut.SUBSCRIPTION_AFTER_ACTIVE_SUBSCRIPTION_REGISTERED, mySubscriptionActivatedPost); } - @After + @AfterEach public void cleanup() { myInterceptorRegistry.unregisterAllInterceptors(); mySubscriptionMatchingPost.clear(); @@ -155,7 +155,7 @@ public abstract class BaseBlockingQueueSubscribableChannelDstu3Test extends Base return sendResource(observation); } - @BeforeClass + @BeforeAll public static void startListenerServer() throws Exception { ourListenerRestServer = new RestfulServer(FhirContext.forDstu3()); @@ -180,7 +180,7 @@ public abstract class BaseBlockingQueueSubscribableChannelDstu3Test extends Base context.getValidationSupport().fetchAllStructureDefinitions(); } - @AfterClass + @AfterAll public static void stopListenerServer() throws Exception { JettyUtil.closeServer(ourListenerServer); } diff --git a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/subscriber/ResourceDeliveryMessageTest.java b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/subscriber/ResourceDeliveryMessageTest.java index 73eaf13ad11..80697b5eb85 100644 --- a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/subscriber/ResourceDeliveryMessageTest.java +++ b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/subscriber/ResourceDeliveryMessageTest.java @@ -2,11 +2,11 @@ package ca.uhn.fhir.jpa.subscription.module.subscriber; import ca.uhn.fhir.jpa.subscription.model.ResourceDeliveryMessage; import com.fasterxml.jackson.databind.ObjectMapper; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.IOException; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public class ResourceDeliveryMessageTest { diff --git a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/subscriber/SubscriptionCheckingSubscriberTest.java b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/subscriber/SubscriptionCheckingSubscriberTest.java index 791d28b5c39..92e2bf58511 100644 --- a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/subscriber/SubscriptionCheckingSubscriberTest.java +++ b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/subscriber/SubscriptionCheckingSubscriberTest.java @@ -6,11 +6,11 @@ import org.hl7.fhir.dstu3.model.CodeableConcept; import org.hl7.fhir.dstu3.model.Coding; import org.hl7.fhir.dstu3.model.IdType; import org.hl7.fhir.dstu3.model.Observation; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * Tests copied from jpa.subscription.resthook.RestHookTestDstu3Test diff --git a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/subscriber/SubscriptionMatchingSubscriberTest.java b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/subscriber/SubscriptionMatchingSubscriberTest.java index b50fab8e0c2..02874aeb5dc 100644 --- a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/subscriber/SubscriptionMatchingSubscriberTest.java +++ b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/subscriber/SubscriptionMatchingSubscriberTest.java @@ -2,11 +2,11 @@ package ca.uhn.fhir.jpa.subscription.module.subscriber; import ca.uhn.fhir.jpa.subscription.module.standalone.BaseBlockingQueueSubscribableChannelDstu3Test; import ca.uhn.fhir.rest.api.Constants; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * Tests copied from jpa.subscription.resthook.RestHookTestDstu3Test diff --git a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/subscriber/websocket/WebsocketConnectionValidatorTest.java b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/subscriber/websocket/WebsocketConnectionValidatorTest.java index 9412562e481..2974f50b914 100644 --- a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/subscriber/websocket/WebsocketConnectionValidatorTest.java +++ b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/module/subscriber/websocket/WebsocketConnectionValidatorTest.java @@ -13,32 +13,32 @@ import ca.uhn.fhir.jpa.searchparam.matcher.SearchParamMatcher; import ca.uhn.fhir.jpa.searchparam.registry.ISearchParamRegistry; import ca.uhn.fhir.jpa.subscription.channel.config.SubscriptionChannelConfig; import ca.uhn.fhir.jpa.subscription.channel.subscription.SubscriptionChannelFactory; -import ca.uhn.fhir.jpa.subscription.model.CanonicalSubscription; -import ca.uhn.fhir.jpa.subscription.model.CanonicalSubscriptionChannelType; import ca.uhn.fhir.jpa.subscription.match.config.SubscriptionProcessorConfig; import ca.uhn.fhir.jpa.subscription.match.deliver.websocket.WebsocketConnectionValidator; import ca.uhn.fhir.jpa.subscription.match.deliver.websocket.WebsocketValidationResponse; import ca.uhn.fhir.jpa.subscription.match.registry.ActiveSubscription; import ca.uhn.fhir.jpa.subscription.match.registry.SubscriptionRegistry; +import ca.uhn.fhir.jpa.subscription.model.CanonicalSubscription; +import ca.uhn.fhir.jpa.subscription.model.CanonicalSubscriptionChannelType; import org.hl7.fhir.r4.model.IdType; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.task.AsyncTaskExecutor; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.transaction.PlatformTransactionManager; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -@RunWith(SpringRunner.class) +@ExtendWith(SpringExtension.class) public class WebsocketConnectionValidatorTest { public static String RESTHOOK_SUBSCRIPTION_ID = "1"; public static String WEBSOCKET_SUBSCRIPTION_ID = "2"; @@ -70,7 +70,7 @@ public class WebsocketConnectionValidatorTest { @Autowired WebsocketConnectionValidator myWebsocketConnectionValidator; - @Before + @BeforeEach public void before() { CanonicalSubscription resthookSubscription = new CanonicalSubscription(); resthookSubscription.setChannelType(CanonicalSubscriptionChannelType.RESTHOOK); @@ -117,7 +117,9 @@ public class WebsocketConnectionValidatorTest { } @Bean - public PartitionSettings partitionSettings() { return new PartitionSettings(); } + public PartitionSettings partitionSettings() { + return new PartitionSettings(); + } @Bean public ModelConfig modelConfig() { diff --git a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/submit/interceptor/SubscriptionSubmitInterceptorLoaderTest.java b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/submit/interceptor/SubscriptionSubmitInterceptorLoaderTest.java index f6d9d4c3761..0e0cd0fa30f 100644 --- a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/submit/interceptor/SubscriptionSubmitInterceptorLoaderTest.java +++ b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/submit/interceptor/SubscriptionSubmitInterceptorLoaderTest.java @@ -13,20 +13,20 @@ import ca.uhn.fhir.jpa.searchparam.registry.ISearchParamProvider; import ca.uhn.fhir.jpa.subscription.channel.subscription.SubscriptionChannelFactory; import ca.uhn.fhir.jpa.subscription.submit.config.SubscriptionSubmitterConfig; import org.hl7.fhir.dstu2.model.Subscription; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; -@RunWith(SpringRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = { SubscriptionSubmitterConfig.class, SearchParamConfig.class, diff --git a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/submit/interceptor/SubscriptionValidatingInterceptorTest.java b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/submit/interceptor/SubscriptionValidatingInterceptorTest.java index 66a4a8acb52..83c83fd2fd8 100644 --- a/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/submit/interceptor/SubscriptionValidatingInterceptorTest.java +++ b/hapi-fhir-jpaserver-subscription/src/test/java/ca/uhn/fhir/jpa/subscription/submit/interceptor/SubscriptionValidatingInterceptorTest.java @@ -6,14 +6,14 @@ import ca.uhn.fhir.jpa.subscription.match.matcher.matching.SubscriptionStrategyE import ca.uhn.fhir.jpa.subscription.match.registry.SubscriptionCanonicalizer; import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException; import org.hl7.fhir.r4.model.Subscription; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.test.context.junit4.SpringRunner; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.test.context.junit.jupiter.SpringExtension; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; @@ -21,8 +21,7 @@ import static org.junit.Assert.fail; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; -@RunWith(SpringRunner.class) - +@ExtendWith(SpringExtension.class) public class SubscriptionValidatingInterceptorTest { @Autowired private SubscriptionValidatingInterceptor mySubscriptionValidatingInterceptor; @@ -31,25 +30,7 @@ public class SubscriptionValidatingInterceptorTest { @MockBean private SubscriptionStrategyEvaluator mySubscriptionStrategyEvaluator; - @Configuration - public static class SpringConfig { - @Bean - FhirContext fhirContext() { - return FhirContext.forR4(); - } - - @Bean - SubscriptionValidatingInterceptor subscriptionValidatingInterceptor() { - return new SubscriptionValidatingInterceptor(); - } - - @Bean - SubscriptionCanonicalizer subscriptionCanonicalizer(FhirContext theFhirContext) { - return new SubscriptionCanonicalizer(theFhirContext); - } - } - - @Before + @BeforeEach public void before() { when(myDaoRegistry.isResourceTypeSupported(any())).thenReturn(true); } @@ -154,4 +135,22 @@ public class SubscriptionValidatingInterceptorTest { channel.setEndpoint("channel:my-queue-name"); mySubscriptionValidatingInterceptor.validateSubmittedSubscription(badSub); } + + @Configuration + public static class SpringConfig { + @Bean + FhirContext fhirContext() { + return FhirContext.forR4(); + } + + @Bean + SubscriptionValidatingInterceptor subscriptionValidatingInterceptor() { + return new SubscriptionValidatingInterceptor(); + } + + @Bean + SubscriptionCanonicalizer subscriptionCanonicalizer(FhirContext theFhirContext) { + return new SubscriptionCanonicalizer(theFhirContext); + } + } } diff --git a/hapi-fhir-jpaserver-test-utilities/pom.xml b/hapi-fhir-jpaserver-test-utilities/pom.xml index 2c57d9ec6dd..22d8cf83731 100644 --- a/hapi-fhir-jpaserver-test-utilities/pom.xml +++ b/hapi-fhir-jpaserver-test-utilities/pom.xml @@ -54,8 +54,19 @@ - junit - junit + org.junit.jupiter + junit-jupiter + compile + + + org.junit.jupiter + junit-jupiter-api + compile + + + org.junit.jupiter + junit-jupiter-engine + compile diff --git a/hapi-fhir-jpaserver-test-utilities/src/main/java/ca/uhn/fhir/jpa/test/BaseJpaTest.java b/hapi-fhir-jpaserver-test-utilities/src/main/java/ca/uhn/fhir/jpa/test/BaseJpaTest.java index e8d5011ec12..8efab9f3ebc 100644 --- a/hapi-fhir-jpaserver-test-utilities/src/main/java/ca/uhn/fhir/jpa/test/BaseJpaTest.java +++ b/hapi-fhir-jpaserver-test-utilities/src/main/java/ca/uhn/fhir/jpa/test/BaseJpaTest.java @@ -26,14 +26,14 @@ import ca.uhn.fhir.rest.api.Constants; import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; import ca.uhn.fhir.test.utilities.UnregisterScheduledProcessor; import ca.uhn.fhir.util.TestUtil; -import org.junit.After; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.extension.ExtendWith; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.test.context.TestPropertySource; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.TransactionDefinition; import org.springframework.transaction.TransactionStatus; @@ -47,7 +47,7 @@ import java.util.concurrent.Callable; // value returned by SearchBuilder.getLastHandlerMechanismForUnitTest() UnregisterScheduledProcessor.SCHEDULING_DISABLED_EQUALS_TRUE }) -@RunWith(SpringRunner.class) +@ExtendWith(SpringExtension.class) public abstract class BaseJpaTest { private static final Logger ourLog = LoggerFactory.getLogger(BaseJpaTest.class); @@ -70,7 +70,7 @@ public abstract class BaseJpaTest { @Autowired MemoryCacheService myMemoryCacheService; - @After + @AfterEach public void after() { ourLog.info("\n --- @After ---"); myExpungeEverythingService.expungeEverything(null); diff --git a/hapi-fhir-narrativegenerator/src/test/java/ca/uhn/fhir/narrative/template/TemplateNarrativeGeneratorTest.java b/hapi-fhir-narrativegenerator/src/test/java/ca/uhn/fhir/narrative/template/TemplateNarrativeGeneratorTest.java index b50f058e0b0..3aba17a8e5d 100644 --- a/hapi-fhir-narrativegenerator/src/test/java/ca/uhn/fhir/narrative/template/TemplateNarrativeGeneratorTest.java +++ b/hapi-fhir-narrativegenerator/src/test/java/ca/uhn/fhir/narrative/template/TemplateNarrativeGeneratorTest.java @@ -6,7 +6,7 @@ import java.nio.charset.StandardCharsets; import org.apache.commons.io.IOUtils; import org.hl7.fhir.dstu3.model.Patient; -import org.junit.Test; +import org.junit.jupiter.api.Test; import ca.uhn.fhir.context.FhirContext; diff --git a/hapi-fhir-oauth2/src/test/java/ca/uhn/fhir/rest/server/security/OpenIdConnectBearerTokenServerInterceptorIntegrationTest.java b/hapi-fhir-oauth2/src/test/java/ca/uhn/fhir/rest/server/security/OpenIdConnectBearerTokenServerInterceptorIntegrationTest.java index 998eefb19ad..515eafb3301 100644 --- a/hapi-fhir-oauth2/src/test/java/ca/uhn/fhir/rest/server/security/OpenIdConnectBearerTokenServerInterceptorIntegrationTest.java +++ b/hapi-fhir-oauth2/src/test/java/ca/uhn/fhir/rest/server/security/OpenIdConnectBearerTokenServerInterceptorIntegrationTest.java @@ -1,6 +1,6 @@ package ca.uhn.fhir.rest.server.security; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.util.HashMap; import java.util.concurrent.TimeUnit; @@ -14,10 +14,10 @@ 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.Before; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.BeforeEachClass; +import org.junit.jupiter.api.Test; import org.mitre.oauth2.model.RegisteredClient; import org.mitre.openid.connect.client.service.impl.StaticClientConfigurationService; import org.mitre.openid.connect.client.service.impl.StaticServerConfigurationService; @@ -78,17 +78,17 @@ public class OpenIdConnectBearerTokenServerInterceptorIntegrationTest { assertEquals(200, status.getStatusLine().getStatusCode()); } - @Before + @BeforeEach public void before() { myInterceptor.setTimeSkewAllowance(10 * 60); } - @AfterClass + @AfterAll public static void afterClass() throws Exception { ourServer.stop(); } - @BeforeClass + @BeforeAll public static void beforeClass() throws Exception { ourPort = PortUtil.findFreePort(); ourServer = new Server(ourPort); diff --git a/hapi-fhir-oauth2/src/test/java/ca/uhn/fhir/rest/server/security/OpenIdConnectBearerTokenServerInterceptorTest.java b/hapi-fhir-oauth2/src/test/java/ca/uhn/fhir/rest/server/security/OpenIdConnectBearerTokenServerInterceptorTest.java index 5ff04a04803..6911a77f167 100644 --- a/hapi-fhir-oauth2/src/test/java/ca/uhn/fhir/rest/server/security/OpenIdConnectBearerTokenServerInterceptorTest.java +++ b/hapi-fhir-oauth2/src/test/java/ca/uhn/fhir/rest/server/security/OpenIdConnectBearerTokenServerInterceptorTest.java @@ -1,7 +1,7 @@ package ca.uhn.fhir.rest.server.security; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -10,7 +10,7 @@ import java.util.HashMap; import javax.servlet.http.HttpServletRequest; import org.hamcrest.core.StringContains; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mitre.jose.keystore.JWKSetKeyStore; import org.mitre.jwt.signer.service.impl.DefaultJwtSigningAndValidationService; import org.mitre.jwt.signer.service.impl.JWKSetCacheService; diff --git a/hapi-fhir-server-empi/pom.xml b/hapi-fhir-server-empi/pom.xml index 9f3c70d03a6..3a00cbe9979 100644 --- a/hapi-fhir-server-empi/pom.xml +++ b/hapi-fhir-server-empi/pom.xml @@ -42,6 +42,17 @@ hapi-fhir-structures-r5 ${project.version} + + org.fhir + ucum + + + junit + junit + + + + com.fasterxml.jackson.core jackson-core diff --git a/hapi-fhir-server-empi/src/test/java/ca/uhn/fhir/empi/BaseR4Test.java b/hapi-fhir-server-empi/src/test/java/ca/uhn/fhir/empi/BaseR4Test.java index 495f3e5d107..7565982ba21 100644 --- a/hapi-fhir-server-empi/src/test/java/ca/uhn/fhir/empi/BaseR4Test.java +++ b/hapi-fhir-server-empi/src/test/java/ca/uhn/fhir/empi/BaseR4Test.java @@ -7,12 +7,13 @@ import ca.uhn.fhir.empi.rules.json.EmpiRulesJson; import ca.uhn.fhir.empi.rules.svc.EmpiResourceMatcherSvc; import ca.uhn.fhir.rest.server.util.ISearchParamRetriever; import org.hl7.fhir.r4.model.Patient; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import static org.mockito.Mockito.mock; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public abstract class BaseR4Test { protected static final FhirContext ourFhirContext = FhirContext.forR4(); protected ISearchParamRetriever mySearchParamRetriever = mock(ISearchParamRetriever.class); diff --git a/hapi-fhir-server-empi/src/test/java/ca/uhn/fhir/empi/rules/config/EmpiRuleValidatorTest.java b/hapi-fhir-server-empi/src/test/java/ca/uhn/fhir/empi/rules/config/EmpiRuleValidatorTest.java index 260f5af9dfa..b2766a6f70b 100644 --- a/hapi-fhir-server-empi/src/test/java/ca/uhn/fhir/empi/rules/config/EmpiRuleValidatorTest.java +++ b/hapi-fhir-server-empi/src/test/java/ca/uhn/fhir/empi/rules/config/EmpiRuleValidatorTest.java @@ -4,16 +4,16 @@ import ca.uhn.fhir.context.ConfigurationException; import ca.uhn.fhir.empi.BaseR4Test; import com.google.common.base.Charsets; import org.apache.commons.io.IOUtils; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.core.io.DefaultResourceLoader; import org.springframework.core.io.Resource; import java.io.IOException; import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.startsWith; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.startsWith; +import static org.junit.jupiter.api.Assertions.fail; public class EmpiRuleValidatorTest extends BaseR4Test { @Test diff --git a/hapi-fhir-server-empi/src/test/java/ca/uhn/fhir/empi/rules/json/EmpiRulesJsonR4Test.java b/hapi-fhir-server-empi/src/test/java/ca/uhn/fhir/empi/rules/json/EmpiRulesJsonR4Test.java index c4237ebf94d..f3e910c6cbd 100644 --- a/hapi-fhir-server-empi/src/test/java/ca/uhn/fhir/empi/rules/json/EmpiRulesJsonR4Test.java +++ b/hapi-fhir-server-empi/src/test/java/ca/uhn/fhir/empi/rules/json/EmpiRulesJsonR4Test.java @@ -5,22 +5,22 @@ import ca.uhn.fhir.empi.api.EmpiMatchResultEnum; import ca.uhn.fhir.empi.rules.metric.EmpiMetricEnum; import ca.uhn.fhir.empi.rules.svc.BaseEmpiRulesR4Test; import ca.uhn.fhir.util.JsonUtil; -import junit.framework.TestCase; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.IOException; -import static junit.framework.TestCase.assertEquals; -import static junit.framework.TestCase.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; public class EmpiRulesJsonR4Test extends BaseEmpiRulesR4Test { private static final Logger ourLog = LoggerFactory.getLogger(EmpiRulesJsonR4Test.class); private EmpiRulesJson myRules; - @Before + @Override + @BeforeEach public void before() { super.before(); @@ -36,7 +36,7 @@ public class EmpiRulesJsonR4Test extends BaseEmpiRulesR4Test { assertEquals(EmpiMatchResultEnum.MATCH, rulesDeser.getMatchResult(myBothNameFields)); EmpiFieldMatchJson second = rulesDeser.get(1); assertEquals("name.family", second.getResourcePath()); - TestCase.assertEquals(EmpiMetricEnum.JARO_WINKLER, second.getMetric()); + assertEquals(EmpiMetricEnum.JARO_WINKLER, second.getMetric()); } @Test diff --git a/hapi-fhir-server-empi/src/test/java/ca/uhn/fhir/empi/rules/json/VectorMatchResultMapTest.java b/hapi-fhir-server-empi/src/test/java/ca/uhn/fhir/empi/rules/json/VectorMatchResultMapTest.java index 645dd4322c9..86d1053e1a2 100644 --- a/hapi-fhir-server-empi/src/test/java/ca/uhn/fhir/empi/rules/json/VectorMatchResultMapTest.java +++ b/hapi-fhir-server-empi/src/test/java/ca/uhn/fhir/empi/rules/json/VectorMatchResultMapTest.java @@ -2,9 +2,9 @@ package ca.uhn.fhir.empi.rules.json; import ca.uhn.fhir.empi.api.EmpiMatchResultEnum; import ca.uhn.fhir.empi.rules.metric.EmpiMetricEnum; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static junit.framework.TestCase.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public class VectorMatchResultMapTest { @Test diff --git a/hapi-fhir-server-empi/src/test/java/ca/uhn/fhir/empi/rules/metric/matcher/DateMatcherR4Test.java b/hapi-fhir-server-empi/src/test/java/ca/uhn/fhir/empi/rules/metric/matcher/DateMatcherR4Test.java index 2fbfaf54c0f..6645a972781 100644 --- a/hapi-fhir-server-empi/src/test/java/ca/uhn/fhir/empi/rules/metric/matcher/DateMatcherR4Test.java +++ b/hapi-fhir-server-empi/src/test/java/ca/uhn/fhir/empi/rules/metric/matcher/DateMatcherR4Test.java @@ -4,23 +4,23 @@ import ca.uhn.fhir.empi.rules.metric.EmpiMetricEnum; import ca.uhn.fhir.model.api.TemporalPrecisionEnum; import org.hl7.fhir.r4.model.DateTimeType; import org.hl7.fhir.r4.model.DateType; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; public class DateMatcherR4Test extends BaseMatcherR4Test { @Test public void testExactDatePrecision() { - Calendar cal = new GregorianCalendar(2020,6,15); - Calendar sameMonthCal = new GregorianCalendar(2020,6,22); - Calendar sameYearCal = new GregorianCalendar(2020,11,13); - Calendar otherYearCal = new GregorianCalendar(1965,8,9); + Calendar cal = new GregorianCalendar(2020, 6, 15); + Calendar sameMonthCal = new GregorianCalendar(2020, 6, 22); + Calendar sameYearCal = new GregorianCalendar(2020, 11, 13); + Calendar otherYearCal = new GregorianCalendar(1965, 8, 9); Date date = cal.getTime(); Date sameMonth = sameMonthCal.getTime(); @@ -49,11 +49,11 @@ public class DateMatcherR4Test extends BaseMatcherR4Test { @Test public void testExactDateTimePrecision() { - Calendar cal = new GregorianCalendar(2020,6,15, 11, 12, 13); - Calendar sameSecondCal = new GregorianCalendar(2020,6,15, 11, 12, 13); + Calendar cal = new GregorianCalendar(2020, 6, 15, 11, 12, 13); + Calendar sameSecondCal = new GregorianCalendar(2020, 6, 15, 11, 12, 13); sameSecondCal.add(Calendar.MILLISECOND, 123); - Calendar sameDayCal = new GregorianCalendar(2020,6,15, 12, 34, 56); + Calendar sameDayCal = new GregorianCalendar(2020, 6, 15, 12, 34, 56); Date date = cal.getTime(); Date sameSecond = sameSecondCal.getTime(); diff --git a/hapi-fhir-server-empi/src/test/java/ca/uhn/fhir/empi/rules/metric/matcher/StringMatcherR4Test.java b/hapi-fhir-server-empi/src/test/java/ca/uhn/fhir/empi/rules/metric/matcher/StringMatcherR4Test.java index 1891426038a..00bd3d2d3ed 100644 --- a/hapi-fhir-server-empi/src/test/java/ca/uhn/fhir/empi/rules/metric/matcher/StringMatcherR4Test.java +++ b/hapi-fhir-server-empi/src/test/java/ca/uhn/fhir/empi/rules/metric/matcher/StringMatcherR4Test.java @@ -6,10 +6,10 @@ import org.hl7.fhir.r4.model.DateType; import org.hl7.fhir.r4.model.Enumeration; import org.hl7.fhir.r4.model.Enumerations; import org.hl7.fhir.r4.model.StringType; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; public class StringMatcherR4Test extends BaseMatcherR4Test { @Test diff --git a/hapi-fhir-server-empi/src/test/java/ca/uhn/fhir/empi/rules/svc/BaseEmpiRulesR4Test.java b/hapi-fhir-server-empi/src/test/java/ca/uhn/fhir/empi/rules/svc/BaseEmpiRulesR4Test.java index 08aeb421b4c..a924b8a1918 100644 --- a/hapi-fhir-server-empi/src/test/java/ca/uhn/fhir/empi/rules/svc/BaseEmpiRulesR4Test.java +++ b/hapi-fhir-server-empi/src/test/java/ca/uhn/fhir/empi/rules/svc/BaseEmpiRulesR4Test.java @@ -8,7 +8,7 @@ import ca.uhn.fhir.empi.rules.json.EmpiResourceSearchParamJson; import ca.uhn.fhir.empi.rules.json.EmpiRulesJson; import ca.uhn.fhir.empi.rules.metric.EmpiMetricEnum; import org.hl7.fhir.r4.model.Patient; -import org.junit.Before; +import org.junit.jupiter.api.BeforeEach; public abstract class BaseEmpiRulesR4Test extends BaseR4Test { public static final String PATIENT_GIVEN = "patient-given"; @@ -18,7 +18,7 @@ public abstract class BaseEmpiRulesR4Test extends BaseR4Test { protected EmpiFieldMatchJson myGivenNameMatchField; protected String myBothNameFields; - @Before + @BeforeEach public void before() { myGivenNameMatchField = new EmpiFieldMatchJson() .setName(PATIENT_GIVEN) diff --git a/hapi-fhir-server-empi/src/test/java/ca/uhn/fhir/empi/rules/svc/CustomResourceMatcherR4Test.java b/hapi-fhir-server-empi/src/test/java/ca/uhn/fhir/empi/rules/svc/CustomResourceMatcherR4Test.java index 8ba7436397f..93cd4d222b4 100644 --- a/hapi-fhir-server-empi/src/test/java/ca/uhn/fhir/empi/rules/svc/CustomResourceMatcherR4Test.java +++ b/hapi-fhir-server-empi/src/test/java/ca/uhn/fhir/empi/rules/svc/CustomResourceMatcherR4Test.java @@ -7,10 +7,10 @@ import ca.uhn.fhir.empi.rules.json.EmpiRulesJson; import ca.uhn.fhir.empi.rules.metric.EmpiMetricEnum; import org.hl7.fhir.r4.model.HumanName; import org.hl7.fhir.r4.model.Patient; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public class CustomResourceMatcherR4Test extends BaseR4Test { @@ -24,18 +24,6 @@ public class CustomResourceMatcherR4Test extends BaseR4Test { private static Patient ourHenryJohn; private static Patient ourHenryJOHN; - @BeforeClass - public static void beforeClass() { - ourJohnHenry = buildPatientWithNames("Henry", "John"); - ourJohnHENRY = buildPatientWithNames("HENRY", "John"); - ourJaneHenry = buildPatientWithNames("Henry", "Jane"); - ourJohnSmith = buildPatientWithNames("Smith", "John"); - ourJohnBillyHenry = buildPatientWithNames("Henry", "John", "Billy"); - ourBillyJohnHenry = buildPatientWithNames("Henry", "Billy", "John"); - ourHenryJohn = buildPatientWithNames("John", "Henry"); - ourHenryJOHN = buildPatientWithNames("JOHN", "Henry"); - } - @Test public void testExactNameAnyOrder() { EmpiResourceMatcherSvc nameAnyOrderMatcher = buildMatcher(buildNameRules(EmpiMetricEnum.NAME_ANY_ORDER, true)); @@ -62,7 +50,6 @@ public class CustomResourceMatcherR4Test extends BaseR4Test { assertEquals(EmpiMatchResultEnum.MATCH, nameAnyOrderMatcher.match(ourJohnHenry, ourBillyJohnHenry)); } - @Test public void testExactNameFirstAndLast() { EmpiResourceMatcherSvc nameAnyOrderMatcher = buildMatcher(buildNameRules(EmpiMetricEnum.NAME_FIRST_AND_LAST, true)); @@ -89,17 +76,6 @@ public class CustomResourceMatcherR4Test extends BaseR4Test { assertEquals(EmpiMatchResultEnum.MATCH, nameAnyOrderMatcher.match(ourJohnHenry, ourBillyJohnHenry)); } - protected static Patient buildPatientWithNames(String theFamilyName, String... theGivenNames) { - Patient patient = new Patient(); - HumanName name = patient.addName(); - name.setFamily(theFamilyName); - for (String givenName : theGivenNames) { - name.addGiven(givenName); - } - patient.setId("Patient/1"); - return patient; - } - private EmpiRulesJson buildNameRules(EmpiMetricEnum theExactNameAnyOrder, boolean theExact) { EmpiFieldMatchJson nameAnyOrderFieldMatch = new EmpiFieldMatchJson() .setName(FIELD_EXACT_MATCH_NAME) @@ -114,4 +90,27 @@ public class CustomResourceMatcherR4Test extends BaseR4Test { return retval; } + + @BeforeAll + public static void beforeClass() { + ourJohnHenry = buildPatientWithNames("Henry", "John"); + ourJohnHENRY = buildPatientWithNames("HENRY", "John"); + ourJaneHenry = buildPatientWithNames("Henry", "Jane"); + ourJohnSmith = buildPatientWithNames("Smith", "John"); + ourJohnBillyHenry = buildPatientWithNames("Henry", "John", "Billy"); + ourBillyJohnHenry = buildPatientWithNames("Henry", "Billy", "John"); + ourHenryJohn = buildPatientWithNames("John", "Henry"); + ourHenryJOHN = buildPatientWithNames("JOHN", "Henry"); + } + + protected static Patient buildPatientWithNames(String theFamilyName, String... theGivenNames) { + Patient patient = new Patient(); + HumanName name = patient.addName(); + name.setFamily(theFamilyName); + for (String givenName : theGivenNames) { + name.addGiven(givenName); + } + patient.setId("Patient/1"); + return patient; + } } diff --git a/hapi-fhir-server-empi/src/test/java/ca/uhn/fhir/empi/rules/svc/EmpiResourceFieldMatcherR4Test.java b/hapi-fhir-server-empi/src/test/java/ca/uhn/fhir/empi/rules/svc/EmpiResourceFieldMatcherR4Test.java index 72f5128ad82..40e7aaaf91d 100644 --- a/hapi-fhir-server-empi/src/test/java/ca/uhn/fhir/empi/rules/svc/EmpiResourceFieldMatcherR4Test.java +++ b/hapi-fhir-server-empi/src/test/java/ca/uhn/fhir/empi/rules/svc/EmpiResourceFieldMatcherR4Test.java @@ -5,22 +5,23 @@ import ca.uhn.fhir.empi.rules.metric.EmpiMetricEnum; import ca.uhn.fhir.parser.DataFormatException; import org.hl7.fhir.r4.model.Encounter; import org.hl7.fhir.r4.model.Patient; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -import static junit.framework.TestCase.assertEquals; -import static junit.framework.TestCase.assertFalse; -import static junit.framework.TestCase.assertTrue; -import static junit.framework.TestCase.fail; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.StringStartsWith.startsWith; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; public class EmpiResourceFieldMatcherR4Test extends BaseEmpiRulesR4Test { protected EmpiResourceFieldMatcher myComparator; private Patient myJohn; private Patient myJohny; - @Before + @Override + @BeforeEach public void before() { super.before(); diff --git a/hapi-fhir-server-empi/src/test/java/ca/uhn/fhir/empi/rules/svc/EmpiResourceMatcherSvcR4Test.java b/hapi-fhir-server-empi/src/test/java/ca/uhn/fhir/empi/rules/svc/EmpiResourceMatcherSvcR4Test.java index 8843614ed2b..89653602ec2 100644 --- a/hapi-fhir-server-empi/src/test/java/ca/uhn/fhir/empi/rules/svc/EmpiResourceMatcherSvcR4Test.java +++ b/hapi-fhir-server-empi/src/test/java/ca/uhn/fhir/empi/rules/svc/EmpiResourceMatcherSvcR4Test.java @@ -3,21 +3,21 @@ package ca.uhn.fhir.empi.rules.svc; import ca.uhn.fhir.context.RuntimeSearchParam; import ca.uhn.fhir.empi.api.EmpiMatchResultEnum; import org.hl7.fhir.r4.model.Patient; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; public class EmpiResourceMatcherSvcR4Test extends BaseEmpiRulesR4Test { - private EmpiResourceMatcherSvc myEmpiResourceMatcherSvc; public static final double NAME_DELTA = 0.0001; - + private EmpiResourceMatcherSvc myEmpiResourceMatcherSvc; private Patient myJohn; private Patient myJohny; - @Before + @Override + @BeforeEach public void before() { super.before(); diff --git a/hapi-fhir-server-empi/src/test/java/ca/uhn/fhir/empi/svc/EIDHelperR4Test.java b/hapi-fhir-server-empi/src/test/java/ca/uhn/fhir/empi/svc/EIDHelperR4Test.java index d17e10b3be5..dad0d2306c9 100644 --- a/hapi-fhir-server-empi/src/test/java/ca/uhn/fhir/empi/svc/EIDHelperR4Test.java +++ b/hapi-fhir-server-empi/src/test/java/ca/uhn/fhir/empi/svc/EIDHelperR4Test.java @@ -9,8 +9,8 @@ import ca.uhn.fhir.empi.rules.json.EmpiRulesJson; import ca.uhn.fhir.empi.util.EIDHelper; import org.hl7.fhir.r4.model.Identifier; import org.hl7.fhir.r4.model.Patient; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.util.List; @@ -18,7 +18,7 @@ import static ca.uhn.fhir.empi.api.EmpiConstants.HAPI_ENTERPRISE_IDENTIFIER_SYST import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.nullValue; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; public class EIDHelperR4Test extends BaseR4Test { @@ -34,7 +34,7 @@ public class EIDHelperR4Test extends BaseR4Test { private EIDHelper myEidHelper; - @Before + @BeforeEach public void before() { myEmpiSettings = new EmpiSettings(new EmpiRuleValidator(ourFhirContext, mySearchParamRetriever)) {{ setEmpiRules(ourRules); diff --git a/hapi-fhir-server-empi/src/test/java/ca/uhn/fhir/empi/svc/NameUtilTestDSTU3.java b/hapi-fhir-server-empi/src/test/java/ca/uhn/fhir/empi/svc/NameUtilTestDSTU3.java index 9c69b4dbde4..46529bd3b75 100644 --- a/hapi-fhir-server-empi/src/test/java/ca/uhn/fhir/empi/svc/NameUtilTestDSTU3.java +++ b/hapi-fhir-server-empi/src/test/java/ca/uhn/fhir/empi/svc/NameUtilTestDSTU3.java @@ -6,7 +6,7 @@ import ca.uhn.fhir.util.FhirTerser; import org.hl7.fhir.dstu3.model.Patient; import org.hl7.fhir.dstu3.model.StringType; import org.hl7.fhir.instance.model.api.IBase; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.List; @@ -32,7 +32,7 @@ public class NameUtilTestDSTU3 { IBase name = names.get(0); { - String familyName = NameUtil.extractFamilyName(myFhirContext, name ); + String familyName = NameUtil.extractFamilyName(myFhirContext, name); assertThat(familyName, is(equalTo("family"))); } diff --git a/hapi-fhir-server-empi/src/test/java/ca/uhn/fhir/empi/svc/NameUtilTestR4.java b/hapi-fhir-server-empi/src/test/java/ca/uhn/fhir/empi/svc/NameUtilTestR4.java index 0e4ba9e53fa..047f87f8374 100644 --- a/hapi-fhir-server-empi/src/test/java/ca/uhn/fhir/empi/svc/NameUtilTestR4.java +++ b/hapi-fhir-server-empi/src/test/java/ca/uhn/fhir/empi/svc/NameUtilTestR4.java @@ -6,7 +6,7 @@ import ca.uhn.fhir.util.FhirTerser; import org.hl7.fhir.instance.model.api.IBase; import org.hl7.fhir.r4.model.Patient; import org.hl7.fhir.r4.model.StringType; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.List; diff --git a/hapi-fhir-server-empi/src/test/java/ca/uhn/fhir/empi/svc/PersonHelperDSTU3Test.java b/hapi-fhir-server-empi/src/test/java/ca/uhn/fhir/empi/svc/PersonHelperDSTU3Test.java index 356a2d438eb..c225e1beb2d 100644 --- a/hapi-fhir-server-empi/src/test/java/ca/uhn/fhir/empi/svc/PersonHelperDSTU3Test.java +++ b/hapi-fhir-server-empi/src/test/java/ca/uhn/fhir/empi/svc/PersonHelperDSTU3Test.java @@ -7,7 +7,7 @@ import ca.uhn.fhir.model.primitive.IdDt; import org.hl7.fhir.dstu3.model.Person; import org.hl7.fhir.dstu3.model.Reference; import org.hl7.fhir.instance.model.api.IIdType; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.List; import java.util.stream.Collectors; @@ -16,9 +16,9 @@ import static ca.uhn.fhir.empi.util.TestUtils.createDummyContext; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.Is.is; import static org.hamcrest.core.IsEqual.equalTo; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; public class PersonHelperDSTU3Test { public static final FhirContext ourFhirContext = FhirContext.forDstu3(); diff --git a/hapi-fhir-server-empi/src/test/java/ca/uhn/fhir/empi/svc/PersonHelperR4Test.java b/hapi-fhir-server-empi/src/test/java/ca/uhn/fhir/empi/svc/PersonHelperR4Test.java index 1d02a88b916..a1e3b2d8675 100644 --- a/hapi-fhir-server-empi/src/test/java/ca/uhn/fhir/empi/svc/PersonHelperR4Test.java +++ b/hapi-fhir-server-empi/src/test/java/ca/uhn/fhir/empi/svc/PersonHelperR4Test.java @@ -7,7 +7,7 @@ import ca.uhn.fhir.model.primitive.IdDt; import org.hl7.fhir.instance.model.api.IIdType; import org.hl7.fhir.r4.model.Person; import org.hl7.fhir.r4.model.Reference; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.List; import java.util.stream.Collectors; @@ -16,9 +16,9 @@ import static ca.uhn.fhir.empi.util.TestUtils.createDummyContext; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.Is.is; import static org.hamcrest.core.IsEqual.equalTo; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; public class PersonHelperR4Test { public static final FhirContext ourFhirContext = FhirContext.forR4(); diff --git a/hapi-fhir-server-empi/src/test/java/ca/uhn/fhir/empi/util/AssuranceLevelUtilTest.java b/hapi-fhir-server-empi/src/test/java/ca/uhn/fhir/empi/util/AssuranceLevelUtilTest.java index 2d9d2c9830f..2ac5b507212 100644 --- a/hapi-fhir-server-empi/src/test/java/ca/uhn/fhir/empi/util/AssuranceLevelUtilTest.java +++ b/hapi-fhir-server-empi/src/test/java/ca/uhn/fhir/empi/util/AssuranceLevelUtilTest.java @@ -1,8 +1,7 @@ package ca.uhn.fhir.empi.util; import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException; -import junit.framework.TestCase; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static ca.uhn.fhir.empi.api.EmpiLinkSourceEnum.AUTO; import static ca.uhn.fhir.empi.api.EmpiLinkSourceEnum.MANUAL; @@ -13,11 +12,13 @@ import static ca.uhn.fhir.empi.api.EmpiMatchResultEnum.POSSIBLE_MATCH; import static ca.uhn.fhir.empi.model.CanonicalIdentityAssuranceLevel.LEVEL2; import static ca.uhn.fhir.empi.model.CanonicalIdentityAssuranceLevel.LEVEL3; import static ca.uhn.fhir.empi.model.CanonicalIdentityAssuranceLevel.LEVEL4; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.Is.is; import static org.hamcrest.core.IsEqual.equalTo; -import static org.junit.Assert.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; -public class AssuranceLevelUtilTest extends TestCase { +public class AssuranceLevelUtilTest { @Test public void testValidPersonLinkLevels() { diff --git a/hapi-fhir-server/pom.xml b/hapi-fhir-server/pom.xml index 581d9ab01fe..2fb5c5bfc41 100644 --- a/hapi-fhir-server/pom.xml +++ b/hapi-fhir-server/pom.xml @@ -74,7 +74,7 @@ commons-collections4 - + diff --git a/hapi-fhir-server/src/test/java/ca/uhn/fhir/rest/api/server/IBundleProviderTest.java b/hapi-fhir-server/src/test/java/ca/uhn/fhir/rest/api/server/IBundleProviderTest.java index a2d71d3bdfd..66df32cd6c7 100644 --- a/hapi-fhir-server/src/test/java/ca/uhn/fhir/rest/api/server/IBundleProviderTest.java +++ b/hapi-fhir-server/src/test/java/ca/uhn/fhir/rest/api/server/IBundleProviderTest.java @@ -3,10 +3,10 @@ package ca.uhn.fhir.rest.api.server; import ca.uhn.fhir.rest.server.SimpleBundleProvider; import com.google.common.collect.Lists; import org.hl7.fhir.instance.model.api.IBaseResource; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.mock; public class IBundleProviderTest { diff --git a/hapi-fhir-server/src/test/java/ca/uhn/fhir/rest/api/server/SimplePreResourceShowDetailsTest.java b/hapi-fhir-server/src/test/java/ca/uhn/fhir/rest/api/server/SimplePreResourceShowDetailsTest.java index 54d876115dd..a99942339f8 100644 --- a/hapi-fhir-server/src/test/java/ca/uhn/fhir/rest/api/server/SimplePreResourceShowDetailsTest.java +++ b/hapi-fhir-server/src/test/java/ca/uhn/fhir/rest/api/server/SimplePreResourceShowDetailsTest.java @@ -1,14 +1,16 @@ package ca.uhn.fhir.rest.api.server; import org.hl7.fhir.instance.model.api.IBaseResource; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.fail; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class SimplePreResourceShowDetailsTest { @Mock @@ -16,16 +18,26 @@ public class SimplePreResourceShowDetailsTest { @Mock private IBaseResource myResource2; - @Test(expected = IllegalArgumentException.class) + @Test public void testSetResource_TooLow() { - SimplePreResourceShowDetails details = new SimplePreResourceShowDetails(myResource1); - details.setResource(-1, myResource2); + try { + SimplePreResourceShowDetails details = new SimplePreResourceShowDetails(myResource1); + details.setResource(-1, myResource2); + fail(); + } catch (IllegalArgumentException e) { + assertEquals("Invalid index -1 - theIndex must not be < 0", e.getMessage()); + } } - @Test(expected = IllegalArgumentException.class) + @Test public void testSetResource_TooHigh() { - SimplePreResourceShowDetails details = new SimplePreResourceShowDetails(myResource1); - details.setResource(2, myResource2); + try { + SimplePreResourceShowDetails details = new SimplePreResourceShowDetails(myResource1); + details.setResource(2, myResource2); + fail(); + } catch (IllegalArgumentException e) { + assertEquals("Invalid index {} - theIndex must be < 2", e.getMessage()); + } } @Test diff --git a/hapi-fhir-server/src/test/java/ca/uhn/fhir/rest/server/ApacheProxyAddressStrategyTest.java b/hapi-fhir-server/src/test/java/ca/uhn/fhir/rest/server/ApacheProxyAddressStrategyTest.java index 8f5c2f3fc47..be65be2a45d 100644 --- a/hapi-fhir-server/src/test/java/ca/uhn/fhir/rest/server/ApacheProxyAddressStrategyTest.java +++ b/hapi-fhir-server/src/test/java/ca/uhn/fhir/rest/server/ApacheProxyAddressStrategyTest.java @@ -1,10 +1,10 @@ package ca.uhn.fhir.rest.server; -import static org.junit.Assert.assertEquals; - -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.mock.web.MockHttpServletRequest; +import static org.junit.jupiter.api.Assertions.assertEquals; + public class ApacheProxyAddressStrategyTest { @Test @@ -98,4 +98,4 @@ public class ApacheProxyAddressStrategyTest { request.setContextPath("/imagingstudy"); return request; } -} \ No newline at end of file +} diff --git a/hapi-fhir-server/src/test/java/ca/uhn/fhir/rest/server/CommonResourceSupertypeScannerTest.java b/hapi-fhir-server/src/test/java/ca/uhn/fhir/rest/server/CommonResourceSupertypeScannerTest.java index 5d4016611d7..dfc368ce674 100644 --- a/hapi-fhir-server/src/test/java/ca/uhn/fhir/rest/server/CommonResourceSupertypeScannerTest.java +++ b/hapi-fhir-server/src/test/java/ca/uhn/fhir/rest/server/CommonResourceSupertypeScannerTest.java @@ -6,12 +6,12 @@ import ca.uhn.fhir.model.api.annotation.ResourceDef; import org.hl7.fhir.instance.model.api.IBaseMetaType; import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IIdType; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.List; import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; public class CommonResourceSupertypeScannerTest { diff --git a/hapi-fhir-server/src/test/java/ca/uhn/fhir/rest/server/IncomingRequestAddressStrategyTest.java b/hapi-fhir-server/src/test/java/ca/uhn/fhir/rest/server/IncomingRequestAddressStrategyTest.java index 4cc9d3682ec..d80f8dcf6f3 100644 --- a/hapi-fhir-server/src/test/java/ca/uhn/fhir/rest/server/IncomingRequestAddressStrategyTest.java +++ b/hapi-fhir-server/src/test/java/ca/uhn/fhir/rest/server/IncomingRequestAddressStrategyTest.java @@ -1,8 +1,8 @@ package ca.uhn.fhir.rest.server; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; public class IncomingRequestAddressStrategyTest { diff --git a/hapi-fhir-server/src/test/java/ca/uhn/fhir/rest/server/RestfulResponseTest.java b/hapi-fhir-server/src/test/java/ca/uhn/fhir/rest/server/RestfulResponseTest.java index 009dbe3af5b..096040e770b 100644 --- a/hapi-fhir-server/src/test/java/ca/uhn/fhir/rest/server/RestfulResponseTest.java +++ b/hapi-fhir-server/src/test/java/ca/uhn/fhir/rest/server/RestfulResponseTest.java @@ -2,13 +2,10 @@ package ca.uhn.fhir.rest.server; import ca.uhn.fhir.rest.api.server.RequestDetails; import org.hamcrest.Matchers; -import org.junit.Assert; -import org.junit.Test; -import org.mockito.MockSettings; -import org.mockito.Mockito; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.CALLS_REAL_METHODS; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.withSettings; diff --git a/hapi-fhir-server/src/test/java/ca/uhn/fhir/rest/server/RestfulServerTest.java b/hapi-fhir-server/src/test/java/ca/uhn/fhir/rest/server/RestfulServerTest.java index 47527d507a8..a0ce231ff05 100644 --- a/hapi-fhir-server/src/test/java/ca/uhn/fhir/rest/server/RestfulServerTest.java +++ b/hapi-fhir-server/src/test/java/ca/uhn/fhir/rest/server/RestfulServerTest.java @@ -11,29 +11,30 @@ import ca.uhn.fhir.rest.api.server.IFhirVersionServer; import ca.uhn.fhir.rest.api.server.RequestDetails; import org.hl7.fhir.instance.model.api.IBaseConformance; import org.hl7.fhir.instance.model.api.IBaseResource; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Answers; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import java.io.Serializable; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class RestfulServerTest { @Mock(answer = Answers.RETURNS_DEEP_STUBS) private FhirContext myCtx; private RestfulServer restfulServer; - @Before + @BeforeEach public void setUp() throws ServletException { when(myCtx.getVersion().getVersion()).thenReturn(FhirVersionEnum.DSTU3); when(myCtx.getVersion().getServerVersion()).thenReturn(new MyFhirVersionServer()); @@ -63,9 +64,14 @@ public class RestfulServerTest { assertTrue(restfulServer.getResourceProviders().isEmpty()); } - @Test(expected = ConfigurationException.class) + @Test public void testFailRegisterInterfaceProviderWithoutRestfulMethod() { - restfulServer.registerProvider(new MyClassWithoutRestInterface()); + try { + restfulServer.registerProvider(new MyClassWithoutRestInterface()); + fail(); + } catch (ConfigurationException e) { + assertEquals("Did not find any annotated RESTful methods on provider class ca.uhn.fhir.rest.server.RestfulServerTest$MyClassWithoutRestInterface", e.getMessage()); + } } diff --git a/hapi-fhir-server/src/test/java/ca/uhn/fhir/rest/server/RestfulServerUtilsTest.java b/hapi-fhir-server/src/test/java/ca/uhn/fhir/rest/server/RestfulServerUtilsTest.java index c50db9cec22..b8250f2eb52 100644 --- a/hapi-fhir-server/src/test/java/ca/uhn/fhir/rest/server/RestfulServerUtilsTest.java +++ b/hapi-fhir-server/src/test/java/ca/uhn/fhir/rest/server/RestfulServerUtilsTest.java @@ -2,9 +2,9 @@ package ca.uhn.fhir.rest.server; import ca.uhn.fhir.rest.api.PreferHeader; import ca.uhn.fhir.rest.api.PreferReturnEnum; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; public class RestfulServerUtilsTest{ diff --git a/hapi-fhir-server/src/test/java/ca/uhn/fhir/rest/server/SimpleBundleProviderTest.java b/hapi-fhir-server/src/test/java/ca/uhn/fhir/rest/server/SimpleBundleProviderTest.java index 1c271b6318e..a80f58d2bba 100644 --- a/hapi-fhir-server/src/test/java/ca/uhn/fhir/rest/server/SimpleBundleProviderTest.java +++ b/hapi-fhir-server/src/test/java/ca/uhn/fhir/rest/server/SimpleBundleProviderTest.java @@ -1,8 +1,8 @@ package ca.uhn.fhir.rest.server; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; public class SimpleBundleProviderTest { diff --git a/hapi-fhir-server/src/test/java/ca/uhn/fhir/rest/server/VerdictTest.java b/hapi-fhir-server/src/test/java/ca/uhn/fhir/rest/server/VerdictTest.java index 1589dd75f82..9889487ab38 100644 --- a/hapi-fhir-server/src/test/java/ca/uhn/fhir/rest/server/VerdictTest.java +++ b/hapi-fhir-server/src/test/java/ca/uhn/fhir/rest/server/VerdictTest.java @@ -10,7 +10,7 @@ import ca.uhn.fhir.rest.server.interceptor.auth.IRuleApplier; import ca.uhn.fhir.rest.server.interceptor.auth.PolicyEnum; import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IIdType; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.Set; diff --git a/hapi-fhir-server/src/test/java/ca/uhn/fhir/rest/server/interceptor/auth/RuleBuilderTest.java b/hapi-fhir-server/src/test/java/ca/uhn/fhir/rest/server/interceptor/auth/RuleBuilderTest.java index 625214ce832..e6cfe63004e 100644 --- a/hapi-fhir-server/src/test/java/ca/uhn/fhir/rest/server/interceptor/auth/RuleBuilderTest.java +++ b/hapi-fhir-server/src/test/java/ca/uhn/fhir/rest/server/interceptor/auth/RuleBuilderTest.java @@ -2,13 +2,13 @@ package ca.uhn.fhir.rest.server.interceptor.auth; import ca.uhn.fhir.model.primitive.IdDt; import com.google.common.collect.Lists; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.List; import static org.hamcrest.Matchers.contains; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Mockito.mock; public class RuleBuilderTest { diff --git a/hapi-fhir-server/src/test/java/ca/uhn/fhir/rest/server/interceptor/auth/RuleImplOpTest.java b/hapi-fhir-server/src/test/java/ca/uhn/fhir/rest/server/interceptor/auth/RuleImplOpTest.java index 5250abf511a..0521d5bc62e 100644 --- a/hapi-fhir-server/src/test/java/ca/uhn/fhir/rest/server/interceptor/auth/RuleImplOpTest.java +++ b/hapi-fhir-server/src/test/java/ca/uhn/fhir/rest/server/interceptor/auth/RuleImplOpTest.java @@ -1,6 +1,6 @@ package ca.uhn.fhir.rest.server.interceptor.auth; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class RuleImplOpTest { diff --git a/hapi-fhir-server/src/test/java/ca/uhn/fhir/rest/server/interceptor/auth/VerdictTest.java b/hapi-fhir-server/src/test/java/ca/uhn/fhir/rest/server/interceptor/auth/VerdictTest.java index d7d16fc280e..b0d627e0c25 100644 --- a/hapi-fhir-server/src/test/java/ca/uhn/fhir/rest/server/interceptor/auth/VerdictTest.java +++ b/hapi-fhir-server/src/test/java/ca/uhn/fhir/rest/server/interceptor/auth/VerdictTest.java @@ -1,7 +1,7 @@ package ca.uhn.fhir.rest.server.interceptor.auth; import ca.uhn.fhir.rest.server.interceptor.auth.AuthorizationInterceptor.Verdict; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class VerdictTest { diff --git a/hapi-fhir-server/src/test/java/ca/uhn/fhir/rest/server/method/ConformanceMethodBindingTest.java b/hapi-fhir-server/src/test/java/ca/uhn/fhir/rest/server/method/ConformanceMethodBindingTest.java index f686ff0864f..a36e886066b 100644 --- a/hapi-fhir-server/src/test/java/ca/uhn/fhir/rest/server/method/ConformanceMethodBindingTest.java +++ b/hapi-fhir-server/src/test/java/ca/uhn/fhir/rest/server/method/ConformanceMethodBindingTest.java @@ -7,8 +7,8 @@ import ca.uhn.fhir.rest.api.server.IRestfulServer; import ca.uhn.fhir.rest.api.server.RequestDetails; import com.google.common.collect.Lists; import org.hl7.fhir.instance.model.api.IBaseConformance; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import javax.servlet.http.HttpServletRequest; import java.lang.reflect.Method; @@ -21,7 +21,7 @@ public class ConformanceMethodBindingTest { private FhirContext fhirContext; private ConformanceMethodBinding conformanceMethodBinding; - @Before + @BeforeEach public void setUp() { fhirContext = mock(FhirContext.class); } diff --git a/hapi-fhir-server/src/test/java/ca/uhn/fhir/rest/server/method/MethodMatchEnumTest.java b/hapi-fhir-server/src/test/java/ca/uhn/fhir/rest/server/method/MethodMatchEnumTest.java index d234922418c..a91acb56545 100644 --- a/hapi-fhir-server/src/test/java/ca/uhn/fhir/rest/server/method/MethodMatchEnumTest.java +++ b/hapi-fhir-server/src/test/java/ca/uhn/fhir/rest/server/method/MethodMatchEnumTest.java @@ -1,8 +1,8 @@ package ca.uhn.fhir.rest.server.method; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; public class MethodMatchEnumTest { diff --git a/hapi-fhir-server/src/test/java/ca/uhn/fhir/rest/server/method/ReadMethodBindingTest.java b/hapi-fhir-server/src/test/java/ca/uhn/fhir/rest/server/method/ReadMethodBindingTest.java index 69aceeae851..76e148336b3 100644 --- a/hapi-fhir-server/src/test/java/ca/uhn/fhir/rest/server/method/ReadMethodBindingTest.java +++ b/hapi-fhir-server/src/test/java/ca/uhn/fhir/rest/server/method/ReadMethodBindingTest.java @@ -12,22 +12,20 @@ import ca.uhn.fhir.rest.api.server.RequestDetails; import org.hl7.fhir.instance.model.api.IBaseMetaType; import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IIdType; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import java.lang.reflect.Method; import java.util.List; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; -@SuppressWarnings("unchecked") -@RunWith(MockitoJUnitRunner.class) +@SuppressWarnings(value = "unchecked") +@ExtendWith(MockitoExtension.class) public class ReadMethodBindingTest { @Mock diff --git a/hapi-fhir-server/src/test/java/ca/uhn/fhir/rest/server/method/SearchMethodBindingTest.java b/hapi-fhir-server/src/test/java/ca/uhn/fhir/rest/server/method/SearchMethodBindingTest.java index e97f416e462..c2f3add03e5 100644 --- a/hapi-fhir-server/src/test/java/ca/uhn/fhir/rest/server/method/SearchMethodBindingTest.java +++ b/hapi-fhir-server/src/test/java/ca/uhn/fhir/rest/server/method/SearchMethodBindingTest.java @@ -12,14 +12,14 @@ import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; import com.google.common.collect.ImmutableMap; import org.hamcrest.Matchers; import org.hl7.fhir.instance.model.api.IBaseResource; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.util.Map; +import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -30,7 +30,7 @@ public class SearchMethodBindingTest { private static final Logger ourLog = LoggerFactory.getLogger(SearchMethodBindingTest.class); private FhirContext fhirContext; - @Before + @BeforeEach public void setUp() { fhirContext = mock(FhirContext.class); RuntimeResourceDefinition definition = mock(RuntimeResourceDefinition.class); @@ -40,39 +40,39 @@ public class SearchMethodBindingTest { @Test // fails public void methodShouldNotMatchWhenUnderscoreQueryParameter() throws NoSuchMethodException { - Assert.assertThat(getBinding("param", String.class).incomingServerRequestMatchesMethod( + assertThat(getBinding("param", String.class).incomingServerRequestMatchesMethod( mockSearchRequest(ImmutableMap.of("param", new String[]{"value"}, "_include", new String[]{"test"}))), Matchers.is(MethodMatchEnum.NONE)); - Assert.assertThat(getBinding("paramAndTest", String.class, String.class).incomingServerRequestMatchesMethod( + assertThat(getBinding("paramAndTest", String.class, String.class).incomingServerRequestMatchesMethod( mockSearchRequest(ImmutableMap.of("param", new String[]{"value"}, "_include", new String[]{"test"}))), Matchers.is(MethodMatchEnum.NONE)); - Assert.assertThat(getBinding("paramAndUnderscoreTest", String.class, String.class).incomingServerRequestMatchesMethod( + assertThat(getBinding("paramAndUnderscoreTest", String.class, String.class).incomingServerRequestMatchesMethod( mockSearchRequest(ImmutableMap.of("param", new String[]{"value"}, "_include", new String[]{"test"}))), Matchers.is(MethodMatchEnum.NONE)); } @Test public void methodShouldNotMatchWhenExtraQueryParameter() throws NoSuchMethodException { - Assert.assertThat(getBinding("param", String.class).incomingServerRequestMatchesMethod( + assertThat(getBinding("param", String.class).incomingServerRequestMatchesMethod( mockSearchRequest(ImmutableMap.of("param", new String[]{"value"}, "extra", new String[]{"test"}))), Matchers.is(MethodMatchEnum.NONE)); - Assert.assertThat(getBinding("paramAndTest", String.class, String.class).incomingServerRequestMatchesMethod( + assertThat(getBinding("paramAndTest", String.class, String.class).incomingServerRequestMatchesMethod( mockSearchRequest(ImmutableMap.of("param", new String[]{"value"}, "extra", new String[]{"test"}))), Matchers.is(MethodMatchEnum.NONE)); - Assert.assertThat(getBinding("paramAndUnderscoreTest", String.class, String.class).incomingServerRequestMatchesMethod( + assertThat(getBinding("paramAndUnderscoreTest", String.class, String.class).incomingServerRequestMatchesMethod( mockSearchRequest(ImmutableMap.of("param", new String[]{"value"}, "extra", new String[]{"test"}))), Matchers.is(MethodMatchEnum.NONE)); } @Test public void methodMatchesOwnParams() throws NoSuchMethodException { - Assert.assertThat(getBinding("param", String.class).incomingServerRequestMatchesMethod( + assertThat(getBinding("param", String.class).incomingServerRequestMatchesMethod( mockSearchRequest(ImmutableMap.of("param", new String[]{"value"}))), Matchers.is(MethodMatchEnum.EXACT)); - Assert.assertThat(getBinding("paramAndTest", String.class, String.class).incomingServerRequestMatchesMethod( + assertThat(getBinding("paramAndTest", String.class, String.class).incomingServerRequestMatchesMethod( mockSearchRequest(ImmutableMap.of("param", new String[]{"value"}, "test", new String[]{"test"}))), Matchers.is(MethodMatchEnum.EXACT)); - Assert.assertThat(getBinding("paramAndUnderscoreTest", String.class, String.class).incomingServerRequestMatchesMethod( + assertThat(getBinding("paramAndUnderscoreTest", String.class, String.class).incomingServerRequestMatchesMethod( mockSearchRequest(ImmutableMap.of("param", new String[]{"value"}, "_test", new String[]{"test"}))), Matchers.is(MethodMatchEnum.EXACT)); } @@ -81,10 +81,10 @@ public class SearchMethodBindingTest { public void methodMatchesChainBlacklist() throws NoSuchMethodException { SearchMethodBinding binding = getBinding("withChainBlacklist", ReferenceParam.class); ourLog.info("Testing binding: {}", binding); - Assert.assertThat(binding.incomingServerRequestMatchesMethod( + assertThat(binding.incomingServerRequestMatchesMethod( mockSearchRequest(ImmutableMap.of("refChainBlacklist.badChain", new String[]{"foo"}))), Matchers.is(MethodMatchEnum.NONE)); - Assert.assertThat(binding.incomingServerRequestMatchesMethod( + assertThat(binding.incomingServerRequestMatchesMethod( mockSearchRequest(ImmutableMap.of("refChainBlacklist.goodChain", new String[]{"foo"}))), Matchers.is(MethodMatchEnum.EXACT)); } diff --git a/hapi-fhir-server/src/test/java/ca/uhn/fhir/rest/server/servlet/ServletRestfulResponseTest.java b/hapi-fhir-server/src/test/java/ca/uhn/fhir/rest/server/servlet/ServletRestfulResponseTest.java index a032c6461b4..c8a7df5b411 100644 --- a/hapi-fhir-server/src/test/java/ca/uhn/fhir/rest/server/servlet/ServletRestfulResponseTest.java +++ b/hapi-fhir-server/src/test/java/ca/uhn/fhir/rest/server/servlet/ServletRestfulResponseTest.java @@ -2,16 +2,14 @@ package ca.uhn.fhir.rest.server.servlet; import ca.uhn.fhir.interceptor.api.IInterceptorBroadcaster; import ca.uhn.fhir.rest.server.RestfulServer; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InOrder; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.junit.MockitoJUnit; -import org.mockito.junit.MockitoRule; +import org.mockito.junit.jupiter.MockitoExtension; -import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletResponse; import java.io.IOException; @@ -22,31 +20,22 @@ import static org.mockito.Mockito.verify; /** * Unit tests of {@link ServletRestfulResponse}. */ +@ExtendWith(MockitoExtension.class) public class ServletRestfulResponseTest { - @Mock - private RestfulServer server; @Mock - private ServletOutputStream servletOutputStream; + private RestfulServer server; @Mock private HttpServletResponse servletResponse; private ServletRequestDetails requestDetails; - private ServletRestfulResponse response; - - @Rule - public MockitoRule mockitoRule = MockitoJUnit.rule(); - - @Before - public void init() throws IOException { - Mockito.when(servletResponse.getOutputStream()).thenReturn(servletOutputStream); - + @BeforeEach + public void init() { requestDetails = new ServletRequestDetails(mock(IInterceptorBroadcaster.class)); requestDetails.setServer(server); requestDetails.setServletResponse(servletResponse); - response = new ServletRestfulResponse(requestDetails); } @Test diff --git a/hapi-fhir-spring-boot/hapi-fhir-spring-boot-autoconfigure/src/test/java/ca/uhn/fhir/spring/boot/autoconfigure/FhirAutoConfigurationTest.java b/hapi-fhir-spring-boot/hapi-fhir-spring-boot-autoconfigure/src/test/java/ca/uhn/fhir/spring/boot/autoconfigure/FhirAutoConfigurationTest.java index 5c8cbdf615a..883b5eb6cd6 100644 --- a/hapi-fhir-spring-boot/hapi-fhir-spring-boot-autoconfigure/src/test/java/ca/uhn/fhir/spring/boot/autoconfigure/FhirAutoConfigurationTest.java +++ b/hapi-fhir-spring-boot/hapi-fhir-spring-boot-autoconfigure/src/test/java/ca/uhn/fhir/spring/boot/autoconfigure/FhirAutoConfigurationTest.java @@ -10,11 +10,9 @@ import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor; import ca.uhn.fhir.rest.server.interceptor.RequestValidatingInterceptor; import ca.uhn.fhir.spring.boot.autoconfigure.FhirAutoConfiguration.FhirJpaServerConfiguration.Dstu3; import org.assertj.core.util.Arrays; -import org.junit.After; -import org.junit.Ignore; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.NoSuchBeanDefinitionException; import org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration; import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration; @@ -26,6 +24,7 @@ import java.net.URL; import java.net.URLClassLoader; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.Assert.fail; /** * Tests for {@link FhirAutoConfiguration}. @@ -34,12 +33,9 @@ import static org.assertj.core.api.Assertions.assertThat; */ public class FhirAutoConfigurationTest { - @Rule - public final ExpectedException thrown = ExpectedException.none(); - private AnnotationConfigApplicationContext context; - @After + @AfterEach public void close() { if (this.context != null) { this.context.close(); @@ -83,7 +79,7 @@ public class FhirAutoConfigurationTest { load(Arrays.array(EmbeddedDataSourceConfiguration.class, HibernateJpaAutoConfiguration.class, FhirAutoConfiguration.class), - "hapi.fhir.version:DSTU3", "spring.jpa.properties.hibernate.search.default.indexBase:target/lucenefiles", "spring.jpa.properties.hibernate.search.model_mapping:ca.uhn.fhir.jpa.search.LuceneSearchMappingFactory"); + "hapi.fhir.version:DSTU3", "spring.jpa.properties.hibernate.search.default.indexBase:target/lucenefiles", "spring.jpa.properties.hibernate.search.model_mapping:ca.uhn.fhir.jpa.search.LuceneSearchMappingFactory"); assertThat(this.context.getBeansOfType(DaoConfig.class)).hasSize(1); assertThat(this.context.getBeansOfType(Dstu3.class)).hasSize(1); @@ -92,26 +88,30 @@ public class FhirAutoConfigurationTest { @Test public void withNoValidation() { load("hapi.fhir.validation.enabled:false"); - this.thrown.expect(NoSuchBeanDefinitionException.class); - this.context.getBean(RequestValidatingInterceptor.class); + try { + this.context.getBean(RequestValidatingInterceptor.class); + fail(); + } catch (NoSuchBeanDefinitionException e) { + // good + } } @Test - @Ignore + @Disabled public void withValidation() { load(); assertThat(this.context.getBeansOfType(IServerInterceptor.class)).hasSize(1); } @Test - @Ignore + @Disabled public void withValidations() { load("hapi.fhir.validation.request-only:false"); assertThat(this.context.getBeansOfType(IServerInterceptor.class)).hasSize(2); } @Test - @Ignore + @Disabled public void withCustomValidationSchemaLocation() { load("hapi.fhir.validation.schema-location:custom-schema-location"); assertThat(this.context.getBeansOfType(IServerInterceptor.class)).hasSize(1); diff --git a/hapi-fhir-spring-boot/hapi-fhir-spring-boot-samples/hapi-fhir-spring-boot-sample-server-jersey/src/test/java/sample/fhir/server/jersey/SampleJerseyRestfulServerApplicationTest.java b/hapi-fhir-spring-boot/hapi-fhir-spring-boot-samples/hapi-fhir-spring-boot-sample-server-jersey/src/test/java/sample/fhir/server/jersey/SampleJerseyRestfulServerApplicationTest.java index 59f41dea74b..09e495344f6 100644 --- a/hapi-fhir-spring-boot/hapi-fhir-spring-boot-samples/hapi-fhir-spring-boot-sample-server-jersey/src/test/java/sample/fhir/server/jersey/SampleJerseyRestfulServerApplicationTest.java +++ b/hapi-fhir-spring-boot/hapi-fhir-spring-boot-samples/hapi-fhir-spring-boot-sample-server-jersey/src/test/java/sample/fhir/server/jersey/SampleJerseyRestfulServerApplicationTest.java @@ -1,41 +1,40 @@ package sample.fhir.server.jersey; -import org.junit.Test; -import org.junit.runner.RunWith; - +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import static org.assertj.core.api.Assertions.assertThat; -@RunWith(SpringRunner.class) +@ExtendWith(SpringExtension.class) @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) public class SampleJerseyRestfulServerApplicationTest { - @Autowired - private TestRestTemplate restTemplate; + @Autowired + private TestRestTemplate restTemplate; - @Test - public void metadata() { - ResponseEntity entity = this.restTemplate.getForEntity( - "/fhir/metadata", - String.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - assertThat(entity.getBody()).contains("\"status\": \"active\""); - } + @Test + public void metadata() { + ResponseEntity entity = this.restTemplate.getForEntity( + "/fhir/metadata", + String.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).contains("\"status\": \"active\""); + } - @Test - public void patientResource() { - ResponseEntity entity = this.restTemplate.getForEntity( - "/fhir/Patient/1", - String.class); - assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); - assertThat(entity.getBody()).contains("\"family\": \"Van Houte\""); - } + @Test + public void patientResource() { + ResponseEntity entity = this.restTemplate.getForEntity( + "/fhir/Patient/1", + String.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).contains("\"family\": \"Van Houte\""); + } } diff --git a/hapi-fhir-spring-boot/hapi-fhir-spring-boot-samples/hapi-fhir-spring-boot-sample-server-jpa/src/test/java/sample/fhir/server/jpa/SampleJpaRestfulServerApplicationTest.java b/hapi-fhir-spring-boot/hapi-fhir-spring-boot-samples/hapi-fhir-spring-boot-sample-server-jpa/src/test/java/sample/fhir/server/jpa/SampleJpaRestfulServerApplicationTest.java index 76060a6dc17..9db118396dc 100644 --- a/hapi-fhir-spring-boot/hapi-fhir-spring-boot-samples/hapi-fhir-spring-boot-sample-server-jpa/src/test/java/sample/fhir/server/jpa/SampleJpaRestfulServerApplicationTest.java +++ b/hapi-fhir-spring-boot/hapi-fhir-spring-boot-samples/hapi-fhir-spring-boot-sample-server-jpa/src/test/java/sample/fhir/server/jpa/SampleJpaRestfulServerApplicationTest.java @@ -4,37 +4,37 @@ import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.rest.client.api.IGenericClient; import org.hl7.fhir.dstu3.model.Patient; import org.hl7.fhir.instance.model.api.IIdType; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import org.springframework.boot.web.server.LocalServerPort; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; -@RunWith(SpringRunner.class) +@ExtendWith(SpringExtension.class) @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) public class SampleJpaRestfulServerApplicationTest { - @Autowired - FhirContext fhirContext; + @Autowired + FhirContext fhirContext; - @LocalServerPort - int port; + @LocalServerPort + int port; - @Test - public void createAndRead() { - IGenericClient client = fhirContext.newRestfulGenericClient("http://localhost:" + port + "/fhir"); + @Test + public void createAndRead() { + IGenericClient client = fhirContext.newRestfulGenericClient("http://localhost:" + port + "/fhir"); - Patient patient = new Patient(); - patient.addName().setFamily("Test"); - IIdType id = client.create().resource(patient).execute().getId(); + Patient patient = new Patient(); + patient.addName().setFamily("Test"); + IIdType id = client.create().resource(patient).execute().getId(); - System.out.println(id); + System.out.println(id); - Patient result = client.read().resource(Patient.class).withId(id).execute(); + Patient result = client.read().resource(Patient.class).withId(id).execute(); - System.out.println(result); - } + System.out.println(result); + } } diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/DuplicateExtensionTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/DuplicateExtensionTest.java index 7dbc4abc836..9ef37d7f8f3 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/DuplicateExtensionTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/DuplicateExtensionTest.java @@ -2,8 +2,8 @@ package ca.uhn.fhir.context; import junit.framework.TestCase; -import org.junit.AfterClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.model.api.annotation.Child; @@ -82,7 +82,7 @@ public class DuplicateExtensionTest extends TestCase { public static class CustomPatientProvider { } - @AfterClass + @AfterAll public static void afterClassClearContext() { TestUtil.clearAllStaticFieldsForUnitTest(); } diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/ExtensionTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/ExtensionTest.java index 498ca57ee4d..e0951782a9f 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/ExtensionTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/ExtensionTest.java @@ -1,12 +1,12 @@ package ca.uhn.fhir.context; import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.io.IOException; -import org.junit.AfterClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; import ca.uhn.fhir.model.primitive.DateTimeDt; import ca.uhn.fhir.model.primitive.StringDt; @@ -87,7 +87,7 @@ public class ExtensionTest { } - @AfterClass + @AfterAll public static void afterClassClearContext() { TestUtil.clearAllStaticFieldsForUnitTest(); } diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/FhirContextDstu1Test.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/FhirContextDstu1Test.java index 8589b682011..0169389e521 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/FhirContextDstu1Test.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/FhirContextDstu1Test.java @@ -1,10 +1,10 @@ package ca.uhn.fhir.context; import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; -import org.junit.AfterClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.model.dstu.resource.Patient; @@ -68,7 +68,7 @@ public class FhirContextDstu1Test { } - @AfterClass + @AfterAll public static void afterClassClearContext() { TestUtil.clearAllStaticFieldsForUnitTest(); } diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/FhirVersionEnumTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/FhirVersionEnumTest.java index c98547a5161..508c9ea63ef 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/FhirVersionEnumTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/FhirVersionEnumTest.java @@ -1,9 +1,9 @@ package ca.uhn.fhir.context; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; -import org.junit.AfterClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; import ca.uhn.fhir.util.TestUtil; @@ -15,7 +15,7 @@ public class FhirVersionEnumTest { } - @AfterClass + @AfterAll public static void afterClassClearContext() { TestUtil.clearAllStaticFieldsForUnitTest(); } diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/InvalidResourceTypeTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/InvalidResourceTypeTest.java index 5c1477c0c99..5bc02c6abab 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/InvalidResourceTypeTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/InvalidResourceTypeTest.java @@ -1,10 +1,10 @@ package ca.uhn.fhir.context; import static org.hamcrest.Matchers.containsString; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; -import org.junit.AfterClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; import ca.uhn.fhir.model.api.annotation.ResourceDef; import ca.uhn.fhir.model.dstu.resource.Patient; @@ -31,7 +31,7 @@ public class InvalidResourceTypeTest { } - @AfterClass + @AfterAll public static void afterClassClearContext() { TestUtil.clearAllStaticFieldsForUnitTest(); } diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/ModelExtensionTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/ModelExtensionTest.java index 1cf1a1b3fe7..e23082fb068 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/ModelExtensionTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/ModelExtensionTest.java @@ -1,9 +1,9 @@ package ca.uhn.fhir.context; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; -import org.junit.AfterClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; import ca.uhn.fhir.parser.DataFormatException; import ca.uhn.fhir.parser.IParser; @@ -38,7 +38,7 @@ public class ModelExtensionTest { } - @AfterClass + @AfterAll public static void afterClassClearContext() { TestUtil.clearAllStaticFieldsForUnitTest(); } diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/ModelScannerDstu1Test.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/ModelScannerDstu1Test.java index c9e3da34244..217228620c8 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/ModelScannerDstu1Test.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/ModelScannerDstu1Test.java @@ -1,12 +1,12 @@ package ca.uhn.fhir.context; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.fail; -import org.junit.AfterClass; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import ca.uhn.fhir.model.api.annotation.Compartment; import ca.uhn.fhir.model.api.annotation.ResourceDef; @@ -85,7 +85,7 @@ public class ModelScannerDstu1Test { * TODO: re-enable this when Claim compartments are fixed */ @Test - @Ignore + @Disabled public void testSearchParamWithCompartmentForNonReferenceParam() { try { FhirContext.forDstu1().getResourceDefinition(CompartmentForNonReferenceParam.class); @@ -132,7 +132,7 @@ public class ModelScannerDstu1Test { } - @AfterClass + @AfterAll public static void afterClassClearContext() { TestUtil.clearAllStaticFieldsForUnitTest(); } diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/NameChanges.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/NameChanges.java index f21384532a3..981616ce838 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/NameChanges.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/NameChanges.java @@ -4,8 +4,8 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; -import org.junit.AfterClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.model.dstu.resource.Patient; @@ -83,9 +83,9 @@ public class NameChanges { } - @AfterClass + @AfterAll public static void afterClassClearContext() { TestUtil.clearAllStaticFieldsForUnitTest(); } -} \ No newline at end of file +} diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/ProvidedResourceScannerTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/ProvidedResourceScannerTest.java index 0e64fe39b36..35c3ce809af 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/ProvidedResourceScannerTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/ProvidedResourceScannerTest.java @@ -5,12 +5,12 @@ import ca.uhn.fhir.model.api.annotation.ResourceDef; import ca.uhn.fhir.model.dstu.resource.Patient; import ca.uhn.fhir.util.TestUtil; import junit.framework.TestCase; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; -import org.junit.AfterClass; +import org.junit.jupiter.api.AfterAll; public class ProvidedResourceScannerTest extends TestCase { @Test @@ -37,9 +37,9 @@ public class ProvidedResourceScannerTest extends TestCase { public static class TestResourceProviderB { } - @AfterClass + @AfterAll public static void afterClassClearContext() { TestUtil.clearAllStaticFieldsForUnitTest(); } -} \ No newline at end of file +} diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/ResourceWithExtensionsA.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/ResourceWithExtensionsA.java index ea216a791b6..330e47a95e4 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/ResourceWithExtensionsA.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/ResourceWithExtensionsA.java @@ -2,7 +2,7 @@ package ca.uhn.fhir.context; import java.util.List; -import org.junit.AfterClass; +import org.junit.jupiter.api.AfterAll; import ca.uhn.fhir.model.api.BaseIdentifiableElement; import ca.uhn.fhir.model.api.IElement; @@ -215,10 +215,10 @@ public class ResourceWithExtensionsA extends BaseResource { } - @AfterClass + @AfterAll public static void afterClassClearContext() { TestUtil.clearAllStaticFieldsForUnitTest(); } -} \ No newline at end of file +} diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/RuntimeResourceDefinitionTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/RuntimeResourceDefinitionTest.java index bcb3f415e91..89b820f5b0a 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/RuntimeResourceDefinitionTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/RuntimeResourceDefinitionTest.java @@ -1,13 +1,13 @@ package ca.uhn.fhir.context; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.List; -import org.junit.AfterClass; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import ca.uhn.fhir.model.api.annotation.ResourceDef; import ca.uhn.fhir.model.dstu.resource.Patient; @@ -33,7 +33,7 @@ public class RuntimeResourceDefinitionTest { } @Test - @Ignore + @Disabled public void testToProfileExtensions() throws Exception { FhirContext ctx = new FhirContext(ResourceWithExtensionsA.class, Profile.class); RuntimeResourceDefinition def = ctx.getResourceDefinition(ResourceWithExtensionsA.class); @@ -153,7 +153,7 @@ public class RuntimeResourceDefinitionTest { } - @AfterClass + @AfterAll public static void afterClassClearContext() { TestUtil.clearAllStaticFieldsForUnitTest(); } diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/copy/DuplicateExtensionTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/copy/DuplicateExtensionTest.java index 647a5439a95..d05501b346c 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/copy/DuplicateExtensionTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/copy/DuplicateExtensionTest.java @@ -2,8 +2,8 @@ package ca.uhn.fhir.context.copy; import junit.framework.TestCase; -import org.junit.AfterClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.model.api.annotation.Child; @@ -82,7 +82,7 @@ public class DuplicateExtensionTest extends TestCase { public static class CustomPatientProvider { } - @AfterClass + @AfterAll public static void afterClassClearContext() { TestUtil.clearAllStaticFieldsForUnitTest(); } diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/copy/ExtensionTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/copy/ExtensionTest.java index 1304e3f183f..bcda9b77490 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/copy/ExtensionTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/copy/ExtensionTest.java @@ -1,12 +1,12 @@ package ca.uhn.fhir.context.copy; import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.io.IOException; -import org.junit.AfterClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; import ca.uhn.fhir.model.primitive.DateTimeDt; import ca.uhn.fhir.model.primitive.StringDt; @@ -87,7 +87,7 @@ public class ExtensionTest { } - @AfterClass + @AfterAll public static void afterClassClearContext() { TestUtil.clearAllStaticFieldsForUnitTest(); } diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/copy/FhirContextDstu1Test.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/copy/FhirContextDstu1Test.java index 55c2ce38405..a8185ccd7f1 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/copy/FhirContextDstu1Test.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/copy/FhirContextDstu1Test.java @@ -1,10 +1,10 @@ package ca.uhn.fhir.context.copy; import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; -import org.junit.AfterClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.model.dstu.resource.Patient; @@ -68,7 +68,7 @@ public class FhirContextDstu1Test { } - @AfterClass + @AfterAll public static void afterClassClearContext() { TestUtil.clearAllStaticFieldsForUnitTest(); } diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/copy/FhirVersionEnumTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/copy/FhirVersionEnumTest.java index 11fc4efab9b..20175625f67 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/copy/FhirVersionEnumTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/copy/FhirVersionEnumTest.java @@ -1,9 +1,9 @@ package ca.uhn.fhir.context.copy; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; -import org.junit.AfterClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; import ca.uhn.fhir.util.TestUtil; @@ -15,7 +15,7 @@ public class FhirVersionEnumTest { } - @AfterClass + @AfterAll public static void afterClassClearContext() { TestUtil.clearAllStaticFieldsForUnitTest(); } diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/copy/InvalidResourceTypeTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/copy/InvalidResourceTypeTest.java index f08719d5af1..e15c22df213 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/copy/InvalidResourceTypeTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/copy/InvalidResourceTypeTest.java @@ -1,10 +1,10 @@ package ca.uhn.fhir.context.copy; import static org.hamcrest.Matchers.containsString; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; -import org.junit.AfterClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; import ca.uhn.fhir.model.api.annotation.ResourceDef; import ca.uhn.fhir.model.dstu.resource.Patient; @@ -31,7 +31,7 @@ public class InvalidResourceTypeTest { } - @AfterClass + @AfterAll public static void afterClassClearContext() { TestUtil.clearAllStaticFieldsForUnitTest(); } diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/copy/ModelExtensionTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/copy/ModelExtensionTest.java index 17ee9a5ce2d..52b5badbd37 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/copy/ModelExtensionTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/copy/ModelExtensionTest.java @@ -1,9 +1,9 @@ package ca.uhn.fhir.context.copy; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; -import org.junit.AfterClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; import ca.uhn.fhir.parser.DataFormatException; import ca.uhn.fhir.parser.IParser; @@ -38,7 +38,7 @@ public class ModelExtensionTest { } - @AfterClass + @AfterAll public static void afterClassClearContext() { TestUtil.clearAllStaticFieldsForUnitTest(); } diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/copy/ModelScannerDstu1Test.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/copy/ModelScannerDstu1Test.java index 817640d646c..b9320dad185 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/copy/ModelScannerDstu1Test.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/copy/ModelScannerDstu1Test.java @@ -1,12 +1,12 @@ package ca.uhn.fhir.context.copy; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.fail; -import org.junit.AfterClass; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import ca.uhn.fhir.model.api.annotation.Compartment; import ca.uhn.fhir.model.api.annotation.ResourceDef; @@ -85,7 +85,7 @@ public class ModelScannerDstu1Test { * TODO: re-enable this when Claim compartments are fixed */ @Test - @Ignore + @Disabled public void testSearchParamWithCompartmentForNonReferenceParam() { try { FhirContext.forDstu1().getResourceDefinition(CompartmentForNonReferenceParam.class); @@ -132,7 +132,7 @@ public class ModelScannerDstu1Test { } - @AfterClass + @AfterAll public static void afterClassClearContext() { TestUtil.clearAllStaticFieldsForUnitTest(); } diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/copy/NameChanges.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/copy/NameChanges.java index 983f84512e9..d8e2ec91a98 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/copy/NameChanges.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/copy/NameChanges.java @@ -4,8 +4,8 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; -import org.junit.AfterClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.model.dstu.resource.Patient; @@ -83,9 +83,9 @@ public class NameChanges { } - @AfterClass + @AfterAll public static void afterClassClearContext() { TestUtil.clearAllStaticFieldsForUnitTest(); } -} \ No newline at end of file +} diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/copy/ProvidedResourceScannerTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/copy/ProvidedResourceScannerTest.java index f1021ffb65e..9c801c6b2cf 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/copy/ProvidedResourceScannerTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/copy/ProvidedResourceScannerTest.java @@ -5,12 +5,12 @@ import ca.uhn.fhir.model.api.annotation.ResourceDef; import ca.uhn.fhir.model.dstu.resource.Patient; import ca.uhn.fhir.util.TestUtil; import junit.framework.TestCase; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; -import org.junit.AfterClass; +import org.junit.jupiter.api.AfterAll; public class ProvidedResourceScannerTest extends TestCase { @Test @@ -37,9 +37,9 @@ public class ProvidedResourceScannerTest extends TestCase { public static class TestResourceProviderB { } - @AfterClass + @AfterAll public static void afterClassClearContext() { TestUtil.clearAllStaticFieldsForUnitTest(); } -} \ No newline at end of file +} diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/copy/ResourceWithExtensionsA.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/copy/ResourceWithExtensionsA.java index 10f3c771dac..ada8254c56a 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/copy/ResourceWithExtensionsA.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/copy/ResourceWithExtensionsA.java @@ -2,7 +2,7 @@ package ca.uhn.fhir.context.copy; import java.util.List; -import org.junit.AfterClass; +import org.junit.jupiter.api.AfterAll; import ca.uhn.fhir.model.api.BaseIdentifiableElement; import ca.uhn.fhir.model.api.IElement; @@ -215,10 +215,10 @@ public class ResourceWithExtensionsA extends BaseResource { } - @AfterClass + @AfterAll public static void afterClassClearContext() { TestUtil.clearAllStaticFieldsForUnitTest(); } -} \ No newline at end of file +} diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/copy/RuntimeResourceDefinitionTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/copy/RuntimeResourceDefinitionTest.java index c0ceace124e..a797eda833c 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/copy/RuntimeResourceDefinitionTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/context/copy/RuntimeResourceDefinitionTest.java @@ -1,13 +1,13 @@ package ca.uhn.fhir.context.copy; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.List; -import org.junit.AfterClass; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import ca.uhn.fhir.model.api.annotation.ResourceDef; import ca.uhn.fhir.model.dstu.resource.Patient; @@ -33,7 +33,7 @@ public class RuntimeResourceDefinitionTest { } @Test - @Ignore + @Disabled public void testToProfileExtensions() throws Exception { FhirContext ctx = new FhirContext(ResourceWithExtensionsA.class, Profile.class); RuntimeResourceDefinition def = ctx.getResourceDefinition(ResourceWithExtensionsA.class); @@ -153,7 +153,7 @@ public class RuntimeResourceDefinitionTest { } - @AfterClass + @AfterAll public static void afterClassClearContext() { TestUtil.clearAllStaticFieldsForUnitTest(); } diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/model/api/TagListTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/model/api/TagListTest.java index 5d07a4c2cab..c7fe6df6fd2 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/model/api/TagListTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/model/api/TagListTest.java @@ -2,12 +2,12 @@ package ca.uhn.fhir.model.api; import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.stringContainsInOrder; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.util.Arrays; -import org.junit.AfterClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.dstu.resource.Patient; @@ -81,7 +81,7 @@ public class TagListTest { } - @AfterClass + @AfterAll public static void afterClassClearContext() { TestUtil.clearAllStaticFieldsForUnitTest(); } diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/model/base/composite/BaseCodingDtTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/model/base/composite/BaseCodingDtTest.java index a9e97650f1c..951c81b1bc0 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/model/base/composite/BaseCodingDtTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/model/base/composite/BaseCodingDtTest.java @@ -1,13 +1,13 @@ package ca.uhn.fhir.model.base.composite; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; -import org.junit.AfterClass; +import org.junit.jupiter.api.AfterAll; import ca.uhn.fhir.model.dstu.composite.CodingDt; import ca.uhn.fhir.util.TestUtil; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Created by Bill de Beaubien on 12/30/2014. @@ -73,7 +73,7 @@ public class BaseCodingDtTest { assertFalse(new CodingDt("http://bar.org", "53").matchesToken(myTokenWithEmptySystem)); } - @AfterClass + @AfterAll public static void afterClassClearContext() { TestUtil.clearAllStaticFieldsForUnitTest(); } diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/model/primitive/Base64BinaryDtTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/model/primitive/Base64BinaryDtTest.java index 90b57072266..8ca75d769a3 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/model/primitive/Base64BinaryDtTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/model/primitive/Base64BinaryDtTest.java @@ -1,7 +1,7 @@ package ca.uhn.fhir.model.primitive; -import org.junit.AfterClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; import ca.uhn.fhir.util.TestUtil; @@ -14,7 +14,7 @@ public class Base64BinaryDtTest { } - @AfterClass + @AfterAll public static void afterClassClearContext() { TestUtil.clearAllStaticFieldsForUnitTest(); } diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/model/primitive/CodingDtTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/model/primitive/CodingDtTest.java index 2cec0a9de26..f708af7b8a7 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/model/primitive/CodingDtTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/model/primitive/CodingDtTest.java @@ -1,9 +1,9 @@ package ca.uhn.fhir.model.primitive; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; -import org.junit.AfterClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.dstu.composite.CodingDt; @@ -58,7 +58,7 @@ public class CodingDtTest { assertEquals("|b\\|c", dt.getValueAsQueryToken(ourCtx)); } - @AfterClass + @AfterAll public static void afterClassClearContext() { TestUtil.clearAllStaticFieldsForUnitTest(); } diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/model/primitive/DecimalDtTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/model/primitive/DecimalDtTest.java index 904f03c9b86..0e5c447203c 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/model/primitive/DecimalDtTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/model/primitive/DecimalDtTest.java @@ -1,9 +1,9 @@ package ca.uhn.fhir.model.primitive; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; -import org.junit.AfterClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; import ca.uhn.fhir.util.TestUtil; @@ -17,7 +17,7 @@ public class DecimalDtTest { } - @AfterClass + @AfterAll public static void afterClassClearContext() { TestUtil.clearAllStaticFieldsForUnitTest(); } diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/model/primitive/IdDtTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/model/primitive/IdDtTest.java index 96ba0396143..6ddf209a5d1 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/model/primitive/IdDtTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/model/primitive/IdDtTest.java @@ -1,13 +1,13 @@ package ca.uhn.fhir.model.primitive; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.math.BigDecimal; import org.apache.commons.lang3.StringUtils; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEachClass; +import org.junit.jupiter.api.Test; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.dstu.composite.ResourceReferenceDt; @@ -323,13 +323,13 @@ public class IdDtTest { return ourCtx.newXmlParser().parseResource(Patient.class, encoded); } - @BeforeClass + @BeforeAll public static void beforeClass() { ourCtx = FhirContext.forDstu1(); } - @AfterClass + @AfterAll public static void afterClassClearContext() { TestUtil.clearAllStaticFieldsForUnitTest(); } diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/model/primitive/IdentifierDtTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/model/primitive/IdentifierDtTest.java index baeb25a01f5..a2884adc311 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/model/primitive/IdentifierDtTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/model/primitive/IdentifierDtTest.java @@ -1,9 +1,9 @@ package ca.uhn.fhir.model.primitive; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; -import org.junit.AfterClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.dstu.composite.IdentifierDt; @@ -59,7 +59,7 @@ public class IdentifierDtTest { - @AfterClass + @AfterAll public static void afterClassClearContext() { TestUtil.clearAllStaticFieldsForUnitTest(); } diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/model/primitive/StringDtTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/model/primitive/StringDtTest.java index 582ab9b3fad..b08c70e5ce0 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/model/primitive/StringDtTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/model/primitive/StringDtTest.java @@ -1,9 +1,9 @@ package ca.uhn.fhir.model.primitive; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; -import org.junit.AfterClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; import ca.uhn.fhir.util.TestUtil; @@ -17,7 +17,7 @@ public class StringDtTest { } - @AfterClass + @AfterAll public static void afterClassClearContext() { TestUtil.clearAllStaticFieldsForUnitTest(); } diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/model/primitive/UriDtTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/model/primitive/UriDtTest.java index 1d752c7f317..08439dc3421 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/model/primitive/UriDtTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/model/primitive/UriDtTest.java @@ -1,9 +1,9 @@ package ca.uhn.fhir.model.primitive; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; -import org.junit.AfterClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; import ca.uhn.fhir.util.TestUtil; @@ -20,7 +20,7 @@ public class UriDtTest { } - @AfterClass + @AfterAll public static void afterClassClearContext() { TestUtil.clearAllStaticFieldsForUnitTest(); } diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/model/primitive/XhtmlDtTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/model/primitive/XhtmlDtTest.java index 00c09d0e2b3..1a085cbced2 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/model/primitive/XhtmlDtTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/model/primitive/XhtmlDtTest.java @@ -1,10 +1,10 @@ package ca.uhn.fhir.model.primitive; import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; -import org.junit.AfterClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; import ca.uhn.fhir.parser.DataFormatException; import ca.uhn.fhir.util.TestUtil; @@ -108,7 +108,7 @@ public class XhtmlDtTest { } - @AfterClass + @AfterAll public static void afterClassClearContext() { TestUtil.clearAllStaticFieldsForUnitTest(); } diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/model/view/ViewGeneratorTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/model/view/ViewGeneratorTest.java index 9e34a40cced..5bfe8c1b33a 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/model/view/ViewGeneratorTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/model/view/ViewGeneratorTest.java @@ -1,11 +1,11 @@ package ca.uhn.fhir.model.view; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.util.List; -import org.junit.AfterClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.api.ExtensionDt; @@ -110,7 +110,7 @@ public class ViewGeneratorTest { assertEquals(0, va.getAllUndeclaredExtensions().size()); } - @AfterClass + @AfterAll public static void afterClassClearContext() { TestUtil.clearAllStaticFieldsForUnitTest(); } diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/narrative/BaseThymeleafNarrativeGeneratorTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/narrative/BaseThymeleafNarrativeGeneratorTest.java index 876c3d77fbf..d428b56c095 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/narrative/BaseThymeleafNarrativeGeneratorTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/narrative/BaseThymeleafNarrativeGeneratorTest.java @@ -1,9 +1,9 @@ package ca.uhn.fhir.narrative; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; -import org.junit.AfterClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; import ca.uhn.fhir.util.TestUtil; @@ -63,7 +63,7 @@ public class BaseThymeleafNarrativeGeneratorTest { - @AfterClass + @AfterAll public static void afterClassClearContext() { TestUtil.clearAllStaticFieldsForUnitTest(); } diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/narrative/CustomThymeleafNarrativeGeneratorTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/narrative/CustomThymeleafNarrativeGeneratorTest.java index b1fde35ff2b..b903f38595e 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/narrative/CustomThymeleafNarrativeGeneratorTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/narrative/CustomThymeleafNarrativeGeneratorTest.java @@ -1,10 +1,10 @@ package ca.uhn.fhir.narrative; import static org.hamcrest.Matchers.containsString; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; -import org.junit.AfterClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.dstu.composite.NarrativeDt; @@ -38,7 +38,7 @@ public class CustomThymeleafNarrativeGeneratorTest { } - @AfterClass + @AfterAll public static void afterClassClearContext() { TestUtil.clearAllStaticFieldsForUnitTest(); } diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/narrative/DefaultThymeleafNarrativeGeneratorTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/narrative/DefaultThymeleafNarrativeGeneratorTest.java index 9f3fadba08f..5032f1e6209 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/narrative/DefaultThymeleafNarrativeGeneratorTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/narrative/DefaultThymeleafNarrativeGeneratorTest.java @@ -1,14 +1,14 @@ package ca.uhn.fhir.narrative; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.io.InputStreamReader; import java.util.Date; import org.hamcrest.core.StringContains; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.api.TemporalPrecisionEnum; @@ -41,7 +41,7 @@ public class DefaultThymeleafNarrativeGeneratorTest { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(DefaultThymeleafNarrativeGeneratorTest.class); private DefaultThymeleafNarrativeGenerator gen; - @Before + @BeforeEach public void before() { gen = new DefaultThymeleafNarrativeGenerator(); gen.setUseHapiServerConformanceNarrative(true); @@ -241,7 +241,7 @@ public class DefaultThymeleafNarrativeGeneratorTest { } - @AfterClass + @AfterAll public static void afterClassClearContext() { TestUtil.clearAllStaticFieldsForUnitTest(); } diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/parser/BaseParserTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/parser/BaseParserTest.java index 8fb8ba3a01e..338d7fc9831 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/parser/BaseParserTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/parser/BaseParserTest.java @@ -3,10 +3,10 @@ package ca.uhn.fhir.parser; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.stringContainsInOrder; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; -import org.junit.AfterClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.dstu.resource.AllergyIntolerance; @@ -159,7 +159,7 @@ public class BaseParserTest { } - @AfterClass + @AfterAll public static void afterClassClearContext() { TestUtil.clearAllStaticFieldsForUnitTest(); } diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/parser/ContainedResourceEncodingTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/parser/ContainedResourceEncodingTest.java index 2c52fa9362a..535b178d10f 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/parser/ContainedResourceEncodingTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/parser/ContainedResourceEncodingTest.java @@ -1,260 +1,260 @@ -package ca.uhn.fhir.parser; - -import static org.junit.Assert.assertEquals; - -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; - -import org.hl7.fhir.instance.model.api.IBaseResource; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import ca.uhn.fhir.context.FhirContext; -import ca.uhn.fhir.model.api.Bundle; -import ca.uhn.fhir.model.dstu.composite.CodeableConceptDt; -import ca.uhn.fhir.model.dstu.composite.HumanNameDt; -import ca.uhn.fhir.model.dstu.composite.ResourceReferenceDt; -import ca.uhn.fhir.model.dstu.resource.Composition; -import ca.uhn.fhir.model.dstu.resource.Composition.Section; -import ca.uhn.fhir.model.dstu.resource.Condition; -import ca.uhn.fhir.model.dstu.resource.DiagnosticReport; -import ca.uhn.fhir.model.dstu.resource.Observation; -import ca.uhn.fhir.model.dstu.resource.Patient; -import ca.uhn.fhir.model.dstu.resource.Practitioner; -import ca.uhn.fhir.model.dstu.valueset.AdministrativeGenderCodesEnum; -import ca.uhn.fhir.model.dstu.valueset.ConditionStatusEnum; -import ca.uhn.fhir.model.dstu.valueset.NameUseEnum; -import ca.uhn.fhir.model.dstu.valueset.PractitionerRoleEnum; -import ca.uhn.fhir.model.primitive.IdDt; -import ca.uhn.fhir.rest.server.IVersionSpecificBundleFactory; -import ca.uhn.fhir.util.TestUtil; - -/** - * Initially contributed by Alexander Kley for bug #29 - */ -public class ContainedResourceEncodingTest { - - private static Logger ourLog = LoggerFactory.getLogger(ContainedResourceEncodingTest.class); - - private FhirContext ctx; - - private Composition comp; - - private Practitioner author; - - private Patient patient; - - private final String patFamName1 = "FirstFamilyName"; - - private final String patGivName1 = "FirstGivenName"; - - @Before - public void initTest() { - ourLog.info("[initTest]"); - - initPatient(); - initAuthor(); - initComposition(); - this.ctx = FhirContext.forDstu1(); - - } - - private void initComposition() { - // new ConditionList - - final Condition c = new Condition(); - c.setId(UUID.randomUUID().toString()); - c.setNotes("This is a note"); - c.setSubject(new ResourceReferenceDt(this.patient)); - c.setCode(new CodeableConceptDt("mySystem", "theCode")); - c.setStatus(ConditionStatusEnum.CONFIRMED); - - // new General Note Section - final Section generalNoteSection = new Section(); - generalNoteSection.setElementSpecificId("Note"); - generalNoteSection.setTitle("Note"); - generalNoteSection.setContent(new ResourceReferenceDt(c)); - - // new SectionList - final List
sectionList = new ArrayList
(); - sectionList.add(generalNoteSection); - - // fill composition - this.comp = new Composition(); - this.comp.addAuthor().setResource(this.author); - this.comp.setSubject(new ResourceReferenceDt(this.patient)); - this.comp.setSection(sectionList); - } - - private void initPatient() { - this.patient = new Patient(); - this.patient.setId(new IdDt(UUID.randomUUID().toString())); - this.patient.addIdentifier().setSystem("http://example.com/fictitious-mrns").setValue("MRN001"); - this.patient.setGender(AdministrativeGenderCodesEnum.M); - this.patient.addName().setUse(NameUseEnum.OFFICIAL).addFamily(this.patFamName1).addGiven(this.patGivName1); - - } - - private void initAuthor() { - this.author = new Practitioner(); - this.author.setId(new IdDt(UUID.randomUUID().toString())); - this.author.addIdentifier().setSystem("DoctorID").setValue("4711"); - this.author.addRole(PractitionerRoleEnum.DOCTOR); - this.author.setName(new HumanNameDt().addFamily("Mueller").addGiven("Klaus").addPrefix("Prof. Dr.")); - - } - - @Test - public void testPatient() { - ourLog.debug("[xmlEncoding] encode resource to xml."); - - /** - * This works fine, although patient instance is modifing from encoder - */ - final String expectedPatientXml = this.ctx.newXmlParser().setPrettyPrint(true).encodeResourceToString(this.patient); - ourLog.debug("[xmlEncoding] first encoding: {}", expectedPatientXml); - final String actualPatientXml = this.ctx.newXmlParser().setPrettyPrint(true).encodeResourceToString(this.patient); - // second encoding - xml is corrupt - i.e.: patient content 4 times! should be the same as after first encoding! - ourLog.debug("[xmlEncoding] second encoding: {}", actualPatientXml); - - Assert.assertEquals(expectedPatientXml.length(), actualPatientXml.length()); - Assert.assertArrayEquals(expectedPatientXml.getBytes(), actualPatientXml.getBytes()); - - } - - @Test - public void testComposition() { - - IParser parser = this.ctx.newXmlParser().setPrettyPrint(true); - - assertEquals(0, this.comp.getContained().getContainedResources().size()); - - /** - * This doesn't works, secund encoding creates corrupt xml - */ - final String expectedCompXml = parser.encodeResourceToString(this.comp); - ourLog.debug("[xmlEncoding] first encoding: {}", expectedCompXml); - - assertEquals(0, this.comp.getContained().getContainedResources().size()); - - final String actualCompXml = parser.encodeResourceToString(this.comp); - - assertEquals(0, this.comp.getContained().getContainedResources().size()); - - // second encoding - xml could not be parsed back to compositon - i.e.: patient content 4 times! should be the same - // as after first encoding! - ourLog.debug("[xmlEncoding] second encoding: {}", actualCompXml); - - final String thirdCompXml = parser.encodeResourceToString(this.comp); - - assertEquals(0, this.comp.getContained().getContainedResources().size()); - - // third encoding - xml could not be parsed back to compositon i.e.: patient content 4 times! should be the same as - // afterfirst encoding! - ourLog.debug("[xmlEncoding] third encoding: {}", thirdCompXml); - - Assert.assertEquals(expectedCompXml.length(), actualCompXml.length()); - Assert.assertArrayEquals(expectedCompXml.getBytes(), actualCompXml.getBytes()); - - } - - @Test - public void testBundleWithContained() { - - DiagnosticReport dr = new DiagnosticReport(); - dr.setId(new IdDt("DiagnosticReport", "123")); - - Observation observation = new Observation(); - - CodeableConceptDt obsName = new CodeableConceptDt(); - obsName.setText("name"); - observation.setName(obsName); - - dr.addResult().setResource(observation); - - ArrayList performers = new ArrayList(); - ResourceReferenceDt performer = new ResourceReferenceDt(); - - Practitioner p = new Practitioner(); - p.setId("#" + IdDt.newRandomUuid()); - p.addIdentifier().setSystem("DoctorID").setValue("4711"); - p.addRole(PractitionerRoleEnum.DOCTOR); - p.setName(new HumanNameDt().addFamily("Mueller").addGiven("Klaus").addPrefix("Prof. Dr.")); - - performer.setResource(p); - performers.add(performer); - observation.setPerformer(performers); - - IParser parser = this.ctx.newXmlParser().setPrettyPrint(true); - String xml = parser.encodeResourceToString(dr); - ourLog.info(xml); - Assert.assertTrue(xml.contains("Mueller")); - - List list = new ArrayList(); - list.add(dr); - - IVersionSpecificBundleFactory factory = ctx.newBundleFactory(); - factory.initializeBundleFromResourceList("", list, "http://foo", "http://foo", 2, null); - Bundle bundle = factory.getDstu1Bundle(); - - parser = this.ctx.newXmlParser().setPrettyPrint(true); - xml = parser.encodeBundleToString(bundle); - ourLog.info(xml); - Assert.assertTrue(xml.contains("Mueller")); - - } - - @Test - public void testBundleWithContainedWithNoIdDt() { - - DiagnosticReport dr = new DiagnosticReport(); - dr.setId(new IdDt("DiagnosticReport", "123")); - - Observation observation = new Observation(); - - CodeableConceptDt obsName = new CodeableConceptDt(); - obsName.setText("name"); - observation.setName(obsName); - - ResourceReferenceDt result = dr.addResult(); - result.setResource(observation); - - ArrayList performers = new ArrayList(); - ResourceReferenceDt performer = new ResourceReferenceDt(); - - Practitioner p = new Practitioner(); - // no idDt on practitioner p - p.addIdentifier().setSystem("DoctorID").setValue("4711"); - p.addRole(PractitionerRoleEnum.DOCTOR); - p.setName(new HumanNameDt().addFamily("Mueller").addGiven("Klaus").addPrefix("Prof. Dr.")); - - performer.setResource(p); - performers.add(performer); - observation.setPerformer(performers); - - List list = new ArrayList(); - list.add(dr); - - IVersionSpecificBundleFactory factory = ctx.newBundleFactory(); - factory.initializeBundleFromResourceList("", list, "http://foo", "http://foo", 2, null); - Bundle bundle = factory.getDstu1Bundle(); - - IParser parser = this.ctx.newXmlParser().setPrettyPrint(true); - String xml = parser.encodeBundleToString(bundle); - ourLog.info(xml); - Assert.assertTrue(xml.contains("Mueller")); - - } - - - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } - -} +package ca.uhn.fhir.parser; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +import org.hl7.fhir.instance.model.api.IBaseResource; +import org.junit.jupiter.api.AfterAll; +import org.junit.Assert; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.model.api.Bundle; +import ca.uhn.fhir.model.dstu.composite.CodeableConceptDt; +import ca.uhn.fhir.model.dstu.composite.HumanNameDt; +import ca.uhn.fhir.model.dstu.composite.ResourceReferenceDt; +import ca.uhn.fhir.model.dstu.resource.Composition; +import ca.uhn.fhir.model.dstu.resource.Composition.Section; +import ca.uhn.fhir.model.dstu.resource.Condition; +import ca.uhn.fhir.model.dstu.resource.DiagnosticReport; +import ca.uhn.fhir.model.dstu.resource.Observation; +import ca.uhn.fhir.model.dstu.resource.Patient; +import ca.uhn.fhir.model.dstu.resource.Practitioner; +import ca.uhn.fhir.model.dstu.valueset.AdministrativeGenderCodesEnum; +import ca.uhn.fhir.model.dstu.valueset.ConditionStatusEnum; +import ca.uhn.fhir.model.dstu.valueset.NameUseEnum; +import ca.uhn.fhir.model.dstu.valueset.PractitionerRoleEnum; +import ca.uhn.fhir.model.primitive.IdDt; +import ca.uhn.fhir.rest.server.IVersionSpecificBundleFactory; +import ca.uhn.fhir.util.TestUtil; + +/** + * Initially contributed by Alexander Kley for bug #29 + */ +public class ContainedResourceEncodingTest { + + private static Logger ourLog = LoggerFactory.getLogger(ContainedResourceEncodingTest.class); + + private FhirContext ctx; + + private Composition comp; + + private Practitioner author; + + private Patient patient; + + private final String patFamName1 = "FirstFamilyName"; + + private final String patGivName1 = "FirstGivenName"; + + @BeforeEach + public void initTest() { + ourLog.info("[initTest]"); + + initPatient(); + initAuthor(); + initComposition(); + this.ctx = FhirContext.forDstu1(); + + } + + private void initComposition() { + // new ConditionList + + final Condition c = new Condition(); + c.setId(UUID.randomUUID().toString()); + c.setNotes("This is a note"); + c.setSubject(new ResourceReferenceDt(this.patient)); + c.setCode(new CodeableConceptDt("mySystem", "theCode")); + c.setStatus(ConditionStatusEnum.CONFIRMED); + + // new General Note Section + final Section generalNoteSection = new Section(); + generalNoteSection.setElementSpecificId("Note"); + generalNoteSection.setTitle("Note"); + generalNoteSection.setContent(new ResourceReferenceDt(c)); + + // new SectionList + final List
sectionList = new ArrayList
(); + sectionList.add(generalNoteSection); + + // fill composition + this.comp = new Composition(); + this.comp.addAuthor().setResource(this.author); + this.comp.setSubject(new ResourceReferenceDt(this.patient)); + this.comp.setSection(sectionList); + } + + private void initPatient() { + this.patient = new Patient(); + this.patient.setId(new IdDt(UUID.randomUUID().toString())); + this.patient.addIdentifier().setSystem("http://example.com/fictitious-mrns").setValue("MRN001"); + this.patient.setGender(AdministrativeGenderCodesEnum.M); + this.patient.addName().setUse(NameUseEnum.OFFICIAL).addFamily(this.patFamName1).addGiven(this.patGivName1); + + } + + private void initAuthor() { + this.author = new Practitioner(); + this.author.setId(new IdDt(UUID.randomUUID().toString())); + this.author.addIdentifier().setSystem("DoctorID").setValue("4711"); + this.author.addRole(PractitionerRoleEnum.DOCTOR); + this.author.setName(new HumanNameDt().addFamily("Mueller").addGiven("Klaus").addPrefix("Prof. Dr.")); + + } + + @Test + public void testPatient() { + ourLog.debug("[xmlEncoding] encode resource to xml."); + + /** + * This works fine, although patient instance is modifing from encoder + */ + final String expectedPatientXml = this.ctx.newXmlParser().setPrettyPrint(true).encodeResourceToString(this.patient); + ourLog.debug("[xmlEncoding] first encoding: {}", expectedPatientXml); + final String actualPatientXml = this.ctx.newXmlParser().setPrettyPrint(true).encodeResourceToString(this.patient); + // second encoding - xml is corrupt - i.e.: patient content 4 times! should be the same as after first encoding! + ourLog.debug("[xmlEncoding] second encoding: {}", actualPatientXml); + + assertEquals(expectedPatientXml.length(), actualPatientXml.length()); + Assert.assertArrayEquals(expectedPatientXml.getBytes(), actualPatientXml.getBytes()); + + } + + @Test + public void testComposition() { + + IParser parser = this.ctx.newXmlParser().setPrettyPrint(true); + + assertEquals(0, this.comp.getContained().getContainedResources().size()); + + /** + * This doesn't works, secund encoding creates corrupt xml + */ + final String expectedCompXml = parser.encodeResourceToString(this.comp); + ourLog.debug("[xmlEncoding] first encoding: {}", expectedCompXml); + + assertEquals(0, this.comp.getContained().getContainedResources().size()); + + final String actualCompXml = parser.encodeResourceToString(this.comp); + + assertEquals(0, this.comp.getContained().getContainedResources().size()); + + // second encoding - xml could not be parsed back to compositon - i.e.: patient content 4 times! should be the same + // as after first encoding! + ourLog.debug("[xmlEncoding] second encoding: {}", actualCompXml); + + final String thirdCompXml = parser.encodeResourceToString(this.comp); + + assertEquals(0, this.comp.getContained().getContainedResources().size()); + + // third encoding - xml could not be parsed back to compositon i.e.: patient content 4 times! should be the same as + // afterfirst encoding! + ourLog.debug("[xmlEncoding] third encoding: {}", thirdCompXml); + + assertEquals(expectedCompXml.length(), actualCompXml.length()); + Assert.assertArrayEquals(expectedCompXml.getBytes(), actualCompXml.getBytes()); + + } + + @Test + public void testBundleWithContained() { + + DiagnosticReport dr = new DiagnosticReport(); + dr.setId(new IdDt("DiagnosticReport", "123")); + + Observation observation = new Observation(); + + CodeableConceptDt obsName = new CodeableConceptDt(); + obsName.setText("name"); + observation.setName(obsName); + + dr.addResult().setResource(observation); + + ArrayList performers = new ArrayList(); + ResourceReferenceDt performer = new ResourceReferenceDt(); + + Practitioner p = new Practitioner(); + p.setId("#" + IdDt.newRandomUuid()); + p.addIdentifier().setSystem("DoctorID").setValue("4711"); + p.addRole(PractitionerRoleEnum.DOCTOR); + p.setName(new HumanNameDt().addFamily("Mueller").addGiven("Klaus").addPrefix("Prof. Dr.")); + + performer.setResource(p); + performers.add(performer); + observation.setPerformer(performers); + + IParser parser = this.ctx.newXmlParser().setPrettyPrint(true); + String xml = parser.encodeResourceToString(dr); + ourLog.info(xml); + Assert.assertTrue(xml.contains("Mueller")); + + List list = new ArrayList(); + list.add(dr); + + IVersionSpecificBundleFactory factory = ctx.newBundleFactory(); + factory.initializeBundleFromResourceList("", list, "http://foo", "http://foo", 2, null); + Bundle bundle = factory.getDstu1Bundle(); + + parser = this.ctx.newXmlParser().setPrettyPrint(true); + xml = parser.encodeBundleToString(bundle); + ourLog.info(xml); + Assert.assertTrue(xml.contains("Mueller")); + + } + + @Test + public void testBundleWithContainedWithNoIdDt() { + + DiagnosticReport dr = new DiagnosticReport(); + dr.setId(new IdDt("DiagnosticReport", "123")); + + Observation observation = new Observation(); + + CodeableConceptDt obsName = new CodeableConceptDt(); + obsName.setText("name"); + observation.setName(obsName); + + ResourceReferenceDt result = dr.addResult(); + result.setResource(observation); + + ArrayList performers = new ArrayList(); + ResourceReferenceDt performer = new ResourceReferenceDt(); + + Practitioner p = new Practitioner(); + // no idDt on practitioner p + p.addIdentifier().setSystem("DoctorID").setValue("4711"); + p.addRole(PractitionerRoleEnum.DOCTOR); + p.setName(new HumanNameDt().addFamily("Mueller").addGiven("Klaus").addPrefix("Prof. Dr.")); + + performer.setResource(p); + performers.add(performer); + observation.setPerformer(performers); + + List list = new ArrayList(); + list.add(dr); + + IVersionSpecificBundleFactory factory = ctx.newBundleFactory(); + factory.initializeBundleFromResourceList("", list, "http://foo", "http://foo", 2, null); + Bundle bundle = factory.getDstu1Bundle(); + + IParser parser = this.ctx.newXmlParser().setPrettyPrint(true); + String xml = parser.encodeBundleToString(bundle); + ourLog.info(xml); + Assert.assertTrue(xml.contains("Mueller")); + + } + + + @AfterAll + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + +} diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/parser/JsonParserTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/parser/JsonParserTest.java index 9e3d081e806..07eca474676 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/parser/JsonParserTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/parser/JsonParserTest.java @@ -3,13 +3,13 @@ package ca.uhn.fhir.parser; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.stringContainsInOrder; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.Matchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; @@ -26,11 +26,11 @@ import org.hamcrest.core.StringContains; import org.hamcrest.text.StringContainsInOrder; import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.INarrative; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.BeforeEachClass; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; import ca.uhn.fhir.context.ConfigurationException; @@ -979,7 +979,7 @@ public class JsonParserTest { assertThat(str, StringContains.containsString(",\"text\":{\"status\":\"generated\",\"div\":\"
help
\"},")); } - @Before + @BeforeEach public void before() { ourCtx.setNarrativeGenerator(null); } @@ -1262,7 +1262,7 @@ public class JsonParserTest { * HAPI FHIR < 0.6 incorrectly used "resource" instead of "reference" */ @Test - @Ignore + @Disabled public void testParseWithIncorrectReference() throws IOException { String jsonString = IOUtils.toString(JsonParser.class.getResourceAsStream("/example-patient-general.json")); jsonString = jsonString.replace("\"reference\"", "\"resource\""); @@ -1508,7 +1508,7 @@ public class JsonParserTest { } - @BeforeClass + @BeforeAll public static void beforeClass() { ourCtx = FhirContext.forDstu1(); } @@ -1548,7 +1548,7 @@ public class JsonParserTest { } - @AfterClass + @AfterAll public static void afterClassClearContext() { TestUtil.clearAllStaticFieldsForUnitTest(); } diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/parser/XmlParserTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/parser/XmlParserTest.java index 5a9b3e1df20..355574e3b40 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/parser/XmlParserTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/parser/XmlParserTest.java @@ -3,14 +3,14 @@ package ca.uhn.fhir.parser; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.stringContainsInOrder; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import java.io.IOException; import java.io.InputStreamReader; @@ -31,9 +31,9 @@ import org.hamcrest.core.StringContains; import org.hamcrest.text.StringContainsInOrder; import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.INarrative; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEachClass; +import org.junit.jupiter.api.Test; import org.xml.sax.SAXException; import ca.uhn.fhir.context.ConfigurationException; @@ -2060,7 +2060,7 @@ public class XmlParserTest { } - @BeforeClass + @BeforeAll public static void beforeClass() { XMLUnit.setIgnoreAttributeOrder(true); XMLUnit.setIgnoreComments(true); @@ -2068,13 +2068,13 @@ public class XmlParserTest { ourCtx = FhirContext.forDstu1(); } - @BeforeClass + @BeforeAll public static void beforeClass2() { System.setProperty("file.encoding", "ISO-8859-1"); } - @AfterClass + @AfterAll public static void afterClassClearContext() { TestUtil.clearAllStaticFieldsForUnitTest(); } diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/parser/jsonlike/JsonLikeParserTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/parser/jsonlike/JsonLikeParserTest.java index 393d2df0a67..7047484564f 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/parser/jsonlike/JsonLikeParserTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/parser/jsonlike/JsonLikeParserTest.java @@ -1,8 +1,8 @@ package ca.uhn.fhir.parser.jsonlike; import static org.hamcrest.Matchers.containsString; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.hamcrest.MatcherAssert.assertThat; import java.io.IOException; import java.io.StringReader; @@ -10,9 +10,9 @@ import java.io.StringWriter; import java.nio.charset.Charset; import org.apache.commons.io.IOUtils; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEachClass; +import org.junit.jupiter.api.Test; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.api.Bundle; @@ -213,12 +213,12 @@ public class JsonLikeParserTest { } - @BeforeClass + @BeforeAll public static void beforeClass() { ourCtx = FhirContext.forDstu1(); } - @AfterClass + @AfterAll public static void afterClassClearContext() { TestUtil.clearAllStaticFieldsForUnitTest(); } diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/AcceptHeaderTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/AcceptHeaderTest.java index 680ba23ed14..9e7eddd7796 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/AcceptHeaderTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/AcceptHeaderTest.java @@ -1,6 +1,6 @@ package ca.uhn.fhir.rest.server; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.util.concurrent.TimeUnit; @@ -13,9 +13,9 @@ 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.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEachClass; +import org.junit.jupiter.api.Test; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.api.IResource; @@ -83,13 +83,13 @@ public class AcceptHeaderTest { assertEquals(Constants.CT_FHIR_XML + Constants.CHARSET_UTF8_CTSUFFIX.replace(" ", "").toLowerCase(), status.getFirstHeader(Constants.HEADER_CONTENT_TYPE).getValue().replace(" ", "").replace("UTF", "utf")); } - @AfterClass + @AfterAll public static void afterClassClearContext() throws Exception { ourServer.stop(); TestUtil.clearAllStaticFieldsForUnitTest(); } - @BeforeClass + @BeforeAll public static void beforeClass() throws Exception { ourPort = PortUtil.findFreePort(); ourServer = new Server(ourPort); diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/BinaryTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/BinaryTest.java index 3ea2e52b0a5..89e07c48fa2 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/BinaryTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/BinaryTest.java @@ -1,7 +1,7 @@ package ca.uhn.fhir.rest.server; import static org.hamcrest.Matchers.startsWith; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.util.Collections; import java.util.List; @@ -20,10 +20,10 @@ 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.Before; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.BeforeEachClass; +import org.junit.jupiter.api.Test; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.api.Bundle; @@ -51,7 +51,7 @@ public class BinaryTest { private static Server ourServer; - @Before + @BeforeEach public void before() { ourLast=null; } @@ -152,13 +152,13 @@ public class BinaryTest { assertArrayEquals(new byte[] { 1, 2, 3, 4 }, bin.getContent()); } - @AfterClass + @AfterAll public static void afterClassClearContext() throws Exception { ourServer.stop(); TestUtil.clearAllStaticFieldsForUnitTest(); } - @BeforeClass + @BeforeAll public static void beforeClass() throws Exception { ourPort = PortUtil.findFreePort(); ourServer = new Server(ourPort); diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/CompositeParameterTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/CompositeParameterTest.java index 3d46074c6cb..fdab181c0e9 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/CompositeParameterTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/CompositeParameterTest.java @@ -19,15 +19,15 @@ 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.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEachClass; +import org.junit.jupiter.api.Test; import java.util.ArrayList; import java.util.List; import java.util.concurrent.TimeUnit; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; /** * Created by dsotnikov on 2/25/2014. @@ -88,13 +88,13 @@ public class CompositeParameterTest { } } - @AfterClass + @AfterAll public static void afterClassClearContext() throws Exception { ourServer.stop(); TestUtil.clearAllStaticFieldsForUnitTest(); } - @BeforeClass + @BeforeAll public static void beforeClass() throws Exception { ourPort = PortUtil.findFreePort(); ourServer = new Server(ourPort); diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/CompressionTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/CompressionTest.java index bc20d9b8a47..dfdf78af8b3 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/CompressionTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/CompressionTest.java @@ -1,6 +1,6 @@ package ca.uhn.fhir.rest.server; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.io.ByteArrayInputStream; import java.io.IOException; @@ -18,9 +18,9 @@ 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.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEachClass; +import org.junit.jupiter.api.Test; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.api.IResource; @@ -85,13 +85,13 @@ public class CompressionTest { } } - @AfterClass + @AfterAll public static void afterClassClearContext() throws Exception { ourServer.stop(); TestUtil.clearAllStaticFieldsForUnitTest(); } - @BeforeClass + @BeforeAll public static void beforeClass() throws Exception { ourPort = PortUtil.findFreePort(); ourServer = new Server(ourPort); diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/CreateTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/CreateTest.java index dcf075a013a..9375a20e966 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/CreateTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/CreateTest.java @@ -1,7 +1,7 @@ package ca.uhn.fhir.rest.server; import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.io.StringReader; import java.util.ArrayList; @@ -20,10 +20,10 @@ import org.eclipse.jetty.server.Server; import org.eclipse.jetty.servlet.ServletHandler; import org.eclipse.jetty.servlet.ServletHolder; import org.hamcrest.core.StringContains; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.BeforeEachClass; +import org.junit.jupiter.api.Test; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.api.IResource; @@ -58,7 +58,7 @@ public class CreateTest { private static Server ourServer; - @Before() + @BeforeEach() public void before() { ourLastResourceBody=null; ourLastEncoding=null; @@ -248,12 +248,12 @@ public class CreateTest { } - @AfterClass + @AfterAll public static void afterClassClearContext() throws Exception { ourServer.stop(); TestUtil.clearAllStaticFieldsForUnitTest(); } - @BeforeClass + @BeforeAll public static void beforeClass() throws Exception { ourPort = PortUtil.findFreePort(); ourServer = new Server(ourPort); diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/CustomTypeTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/CustomTypeTest.java index 517d8d4959c..60cdb30d9c5 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/CustomTypeTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/CustomTypeTest.java @@ -1,6 +1,6 @@ package ca.uhn.fhir.rest.server; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.util.ArrayList; import java.util.List; @@ -15,7 +15,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.*; +import org.junit.jupiter.api.*; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.api.AddProfileTagEnum; @@ -149,13 +149,13 @@ public class CustomTypeTest { } - @AfterClass + @AfterAll public static void afterClassClearContext() throws Exception { ourServer.stop(); TestUtil.clearAllStaticFieldsForUnitTest(); } - @BeforeClass + @BeforeAll public static void beforeClass() throws Exception { ourPort = PortUtil.findFreePort(); ourServer = new Server(ourPort); diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/DefaultEncodingTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/DefaultEncodingTest.java index b104010e93e..c8859a7d8e6 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/DefaultEncodingTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/DefaultEncodingTest.java @@ -17,15 +17,15 @@ 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.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEachClass; +import org.junit.jupiter.api.Test; import java.util.concurrent.TimeUnit; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.not; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; public class DefaultEncodingTest { @@ -164,13 +164,13 @@ public class DefaultEncodingTest { } - @AfterClass + @AfterAll public static void afterClassClearContext() throws Exception { ourServer.stop(); TestUtil.clearAllStaticFieldsForUnitTest(); } - @BeforeClass + @BeforeAll public static void beforeClass() throws Exception { ourPort = PortUtil.findFreePort(); ourServer = new Server(ourPort); diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/DestroyTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/DestroyTest.java index 0b45e3628d8..f97e1d42446 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/DestroyTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/DestroyTest.java @@ -6,9 +6,9 @@ import java.util.Arrays; import javax.servlet.ServletException; -import org.junit.AfterClass; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.runners.MockitoJUnitRunner; import ca.uhn.fhir.context.FhirContext; @@ -24,7 +24,7 @@ import ca.uhn.fhir.util.TestUtil; * Created by Bill de Beaubien on 11/10/2014. */ -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class DestroyTest { private static FhirContext ourCtx = FhirContext.forDstu1(); @@ -96,7 +96,7 @@ public class DestroyTest { } } - @AfterClass + @AfterAll public static void afterClassClearContext() { TestUtil.clearAllStaticFieldsForUnitTest(); } diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/Dstu1BundleFactoryTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/Dstu1BundleFactoryTest.java index 08ec197cb48..265b6e7abae 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/Dstu1BundleFactoryTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/Dstu1BundleFactoryTest.java @@ -1,6 +1,6 @@ package ca.uhn.fhir.rest.server; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.util.ArrayList; import java.util.Arrays; @@ -9,10 +9,10 @@ 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; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.BeforeEachClass; +import org.junit.jupiter.api.Test; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.api.Bundle; @@ -36,12 +36,12 @@ public class Dstu1BundleFactoryTest { private List myResourceList; private Dstu1BundleFactory myBundleFactory; - @BeforeClass + @BeforeAll public static void beforeClass() throws Exception { ourCtx = new FhirContext(Patient.class); } - @Before + @BeforeEach public void setUp() throws Exception { // DiagnosticReport // Performer(practitioner) @@ -191,7 +191,7 @@ public class Dstu1BundleFactoryTest { return resources; } - @AfterClass + @AfterAll public static void afterClassClearContext() { TestUtil.clearAllStaticFieldsForUnitTest(); } diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ExceptionTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ExceptionTest.java index 9febedfe94f..20b0e690e26 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ExceptionTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ExceptionTest.java @@ -1,8 +1,8 @@ package ca.uhn.fhir.rest.server; import static org.hamcrest.Matchers.not; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.hamcrest.MatcherAssert.assertThat; import java.util.List; import java.util.concurrent.TimeUnit; @@ -20,10 +20,10 @@ import org.eclipse.jetty.server.Server; import org.eclipse.jetty.servlet.ServletHandler; import org.eclipse.jetty.servlet.ServletHolder; import org.hamcrest.core.StringContains; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.BeforeEachClass; +import org.junit.jupiter.api.Test; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.api.IResource; @@ -59,7 +59,7 @@ public class ExceptionTest { private static Server ourServer; private static RestfulServer servlet; - @Before + @BeforeEach public void before() { ourGenerateOperationOutcome = false; ourExceptionType = null; @@ -222,13 +222,13 @@ public class ExceptionTest { } - @AfterClass + @AfterAll public static void afterClassClearContext() throws Exception { ourServer.stop(); TestUtil.clearAllStaticFieldsForUnitTest(); } - @BeforeClass + @BeforeAll public static void beforeClass() throws Exception { ourPort = PortUtil.findFreePort(); ourServer = new Server(ourPort); diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/IncomingRequestAddressStrategyTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/IncomingRequestAddressStrategyTest.java index 8023297d9c4..c2242c5dcfa 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/IncomingRequestAddressStrategyTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/IncomingRequestAddressStrategyTest.java @@ -1,6 +1,6 @@ package ca.uhn.fhir.rest.server; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -21,10 +21,10 @@ import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.servlet.ServletHolder; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.BeforeEachClass; +import org.junit.jupiter.api.Test; import ca.uhn.fhir.util.PortUtil; import ca.uhn.fhir.util.TestUtil; @@ -44,7 +44,7 @@ public class IncomingRequestAddressStrategyTest { } } - @Before + @BeforeEach public void before() { ourLastBase = null; ourStrategy = new IncomingRequestAddressStrategy(); @@ -212,7 +212,7 @@ public class IncomingRequestAddressStrategyTest { assertEquals("http://localhost:" + port + contextPath, ourLastBase); } - @BeforeClass + @BeforeAll public static void beforeClass() { PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(5000, TimeUnit.MILLISECONDS); HttpClientBuilder builder = HttpClientBuilder.create(); @@ -238,7 +238,7 @@ public class IncomingRequestAddressStrategyTest { } - @AfterClass + @AfterAll public static void afterClassClearContext() { TestUtil.clearAllStaticFieldsForUnitTest(); } diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/InterceptorTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/InterceptorTest.java index dac4ec41112..18c03b7e24f 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/InterceptorTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/InterceptorTest.java @@ -22,7 +22,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.*; +import org.junit.jupiter.api.*; import static org.hamcrest.MatcherAssert.assertThat; import org.mockito.InOrder; import ca.uhn.fhir.context.FhirContext; @@ -52,7 +52,7 @@ public class InterceptorTest { private IServerInterceptor myInterceptor1; private IServerInterceptor myInterceptor2; - @Before + @BeforeEach public void before() { myInterceptor1 = mock(IServerInterceptor.class); myInterceptor2 = mock(IServerInterceptor.class); @@ -92,13 +92,13 @@ public class InterceptorTest { } - @AfterClass + @AfterAll public static void afterClassClearContext() throws Exception { ourServer.stop(); TestUtil.clearAllStaticFieldsForUnitTest(); } - @BeforeClass + @BeforeAll public static void beforeClass() throws Exception { ourPort = PortUtil.findFreePort(); ourServer = new Server(ourPort); diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/MethodPriorityTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/MethodPriorityTest.java index 360f80f7ed8..5c575427a0f 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/MethodPriorityTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/MethodPriorityTest.java @@ -1,6 +1,6 @@ package ca.uhn.fhir.rest.server; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.util.ArrayList; import java.util.List; @@ -16,10 +16,10 @@ import org.eclipse.jetty.server.Server; import org.eclipse.jetty.servlet.ServletHandler; import org.eclipse.jetty.servlet.ServletHolder; import org.hamcrest.core.StringContains; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEachClass; +import org.junit.jupiter.api.Test; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.api.IResource; @@ -63,12 +63,12 @@ public class MethodPriorityTest { assertThat(responseContent, StringContains.containsString("02")); } - @After + @AfterEach public void after() throws Exception { ourServer.stop(); } - @BeforeClass + @BeforeAll public static void beforeClass() throws Exception { ourPort = PortUtil.findFreePort(); ourServer = new Server(ourPort); @@ -120,7 +120,7 @@ public class MethodPriorityTest { } - @AfterClass + @AfterAll public static void afterClassClearContext() { TestUtil.clearAllStaticFieldsForUnitTest(); } diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/PagingTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/PagingTest.java index 1507a0e1a26..0cde8845801 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/PagingTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/PagingTest.java @@ -1,9 +1,9 @@ package ca.uhn.fhir.rest.server; import static org.hamcrest.Matchers.containsString; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Matchers.any; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.mock; @@ -25,10 +25,10 @@ import org.eclipse.jetty.servlet.ServletHandler; import org.eclipse.jetty.servlet.ServletHolder; import org.hamcrest.Matchers; import org.hl7.fhir.instance.model.api.IBaseResource; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.BeforeEachClass; +import org.junit.jupiter.api.Test; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.api.Bundle; @@ -54,7 +54,7 @@ public class PagingTest { private static Server ourServer; private IPagingProvider myPagingProvider; - @Before + @BeforeEach public void before() { myPagingProvider = mock(IPagingProvider.class); myRestfulServer.setPagingProvider(myPagingProvider); @@ -265,13 +265,13 @@ public class PagingTest { } - @AfterClass + @AfterAll public static void afterClassClearContext() throws Exception { ourServer.stop(); TestUtil.clearAllStaticFieldsForUnitTest(); } - @BeforeClass + @BeforeAll public static void beforeClass() throws Exception { ourContext = FhirContext.forDstu1(); diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/PlainProviderTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/PlainProviderTest.java index d4980d49229..7d109804871 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/PlainProviderTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/PlainProviderTest.java @@ -1,6 +1,6 @@ package ca.uhn.fhir.rest.server; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.util.ArrayList; import java.util.HashMap; @@ -20,10 +20,10 @@ import org.eclipse.jetty.servlet.ServletHandler; import org.eclipse.jetty.servlet.ServletHolder; import org.hamcrest.core.IsEqual; import org.hamcrest.core.StringStartsWith; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.api.Bundle; @@ -57,12 +57,12 @@ public class PlainProviderTest { private RestfulServer myRestfulServer; private Server myServer; - @After + @AfterEach public void after() throws Exception { myServer.stop(); } - @Before + @BeforeEach public void before() throws Exception { myPort = PortUtil.findFreePort(); myServer = new Server(myPort); @@ -166,7 +166,7 @@ public class PlainProviderTest { httpGet.releaseConnection(); } - @AfterClass + @AfterAll public static void afterClassClearContext() { TestUtil.clearAllStaticFieldsForUnitTest(); } diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ReadDstu1Test.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ReadDstu1Test.java index 78626745bdd..e3724175d1e 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ReadDstu1Test.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ReadDstu1Test.java @@ -22,14 +22,14 @@ 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.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEachClass; +import org.junit.jupiter.api.Test; import java.util.concurrent.TimeUnit; import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; public class ReadDstu1Test { @@ -184,13 +184,13 @@ public class ReadDstu1Test { } } - @AfterClass + @AfterAll public static void afterClassClearContext() throws Exception { ourServer.stop(); TestUtil.clearAllStaticFieldsForUnitTest(); } - @BeforeClass + @BeforeAll public static void beforeClass() throws Exception { ourPort = PortUtil.findFreePort(); ourServer = new Server(ourPort); diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ReferenceParameterTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ReferenceParameterTest.java index 3c5aa97435e..142aa95cdb2 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ReferenceParameterTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ReferenceParameterTest.java @@ -27,10 +27,10 @@ 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.Before; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.BeforeEachClass; +import org.junit.jupiter.api.Test; import java.util.ArrayList; import java.util.List; @@ -38,7 +38,7 @@ import java.util.concurrent.TimeUnit; import static org.apache.commons.lang3.StringUtils.defaultString; import static org.hamcrest.Matchers.containsString; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; /** * Created by dsotnikov on 2/25/2014. @@ -52,7 +52,7 @@ public class ReferenceParameterTest { private static int ourPort; private static Server ourServer; - @Before + @BeforeEach public void before() { ourLastRefParam = null; } @@ -278,13 +278,13 @@ public class ReferenceParameterTest { } - @AfterClass + @AfterAll public static void afterClassClearContext() throws Exception { ourServer.stop(); TestUtil.clearAllStaticFieldsForUnitTest(); } - @BeforeClass + @BeforeAll public static void beforeClass() throws Exception { ourPort = PortUtil.findFreePort(); ourServer = new Server(ourPort); diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ResourceMethodTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ResourceMethodTest.java index de081483877..aa7812ed75f 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ResourceMethodTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ResourceMethodTest.java @@ -1,7 +1,7 @@ package ca.uhn.fhir.rest.server; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.mock; import java.util.ArrayList; @@ -13,9 +13,9 @@ import java.util.Set; import javax.servlet.http.HttpServletRequest; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.api.Bundle; @@ -34,7 +34,7 @@ public class ResourceMethodTest { private SearchMethodBinding rm; - @Before + @BeforeEach public void before() throws NoSuchMethodException, SecurityException { rm = new SearchMethodBinding(Patient.class, ResourceMethodTest.class.getMethod("foo"), FhirContext.forDstu1(), null); } @@ -142,7 +142,7 @@ public class ResourceMethodTest { assertTrue(IResource.WILDCARD_ALL_SET.contains(IResource.INCLUDE_ALL)); } - @AfterClass + @AfterAll public static void afterClassClearContext() { TestUtil.clearAllStaticFieldsForUnitTest(); } diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ResourceProviderWithNoMethodsTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ResourceProviderWithNoMethodsTest.java index 30554bec6d4..efff1671243 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ResourceProviderWithNoMethodsTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ResourceProviderWithNoMethodsTest.java @@ -1,15 +1,15 @@ package ca.uhn.fhir.rest.server; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import javax.servlet.ServletException; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.servlet.ServletHandler; import org.eclipse.jetty.servlet.ServletHolder; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; import ca.uhn.fhir.context.ConfigurationException; import ca.uhn.fhir.context.FhirContext; @@ -26,7 +26,7 @@ public class ResourceProviderWithNoMethodsTest { private Server ourServer; private static FhirContext ourCtx = FhirContext.forDstu1(); - @After + @AfterEach public void after() throws Exception { ourServer.stop(); } @@ -109,7 +109,7 @@ public class ResourceProviderWithNoMethodsTest { } - @AfterClass + @AfterAll public static void afterClassClearContext() { TestUtil.clearAllStaticFieldsForUnitTest(); } diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/RestfulServerMethodTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/RestfulServerMethodTest.java index ad9787064b0..33e46ee32ca 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/RestfulServerMethodTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/RestfulServerMethodTest.java @@ -2,10 +2,10 @@ package ca.uhn.fhir.rest.server; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.not; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -39,9 +39,9 @@ import org.eclipse.jetty.servlet.ServletHolder; import org.hamcrest.core.StringContains; import org.hamcrest.core.StringEndsWith; import org.hl7.fhir.instance.model.api.IBaseResource; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEachClass; +import org.junit.jupiter.api.Test; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.api.Bundle; @@ -1059,13 +1059,13 @@ public class RestfulServerMethodTest { } - @AfterClass + @AfterAll public static void afterClassClearContext() throws Exception { ourServer.stop(); TestUtil.clearAllStaticFieldsForUnitTest(); } - @BeforeClass + @BeforeAll public static void beforeClass() throws Exception { ourPort = PortUtil.findFreePort(); ourServer = new Server(ourPort); diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/RestfulServerSelfReferenceTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/RestfulServerSelfReferenceTest.java index 053c19e8541..fce81f922b0 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/RestfulServerSelfReferenceTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/RestfulServerSelfReferenceTest.java @@ -1,6 +1,6 @@ package ca.uhn.fhir.rest.server; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.util.HashMap; import java.util.Map; @@ -17,9 +17,9 @@ import org.eclipse.jetty.server.handler.ContextHandlerCollection; import org.eclipse.jetty.servlet.ServletContextHandler; 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.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEachClass; +import org.junit.jupiter.api.Test; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.api.Bundle; @@ -49,7 +49,7 @@ public class RestfulServerSelfReferenceTest { private static CloseableHttpClient ourClient; private static FhirContext ourCtx; - @BeforeClass + @BeforeAll public static void beforeClass() throws Exception { ourCtx = new FhirContext(Patient.class); @@ -216,7 +216,7 @@ public class RestfulServerSelfReferenceTest { } - @AfterClass + @AfterAll public static void afterClassClearContext() { TestUtil.clearAllStaticFieldsForUnitTest(); } diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/RestfulServerUtilsTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/RestfulServerUtilsTest.java index 429a0b758db..4a5d4f86c77 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/RestfulServerUtilsTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/RestfulServerUtilsTest.java @@ -1,11 +1,11 @@ package ca.uhn.fhir.rest.server; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.util.regex.Matcher; -import org.junit.AfterClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; import ca.uhn.fhir.rest.api.PreferReturnEnum; import ca.uhn.fhir.util.TestUtil; @@ -60,7 +60,7 @@ public class RestfulServerUtilsTest { } - @AfterClass + @AfterAll public static void afterClassClearContext() { TestUtil.clearAllStaticFieldsForUnitTest(); } diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/SearchBundleProviderWithNoSizeDstu1Test.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/SearchBundleProviderWithNoSizeDstu1Test.java index 38c6b2fc3a4..129e0c6c53c 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/SearchBundleProviderWithNoSizeDstu1Test.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/SearchBundleProviderWithNoSizeDstu1Test.java @@ -1,6 +1,6 @@ package ca.uhn.fhir.rest.server; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.*; import java.nio.charset.StandardCharsets; @@ -18,10 +18,10 @@ 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; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.BeforeEachClass; +import org.junit.jupiter.api.Test; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; @@ -49,7 +49,7 @@ public class SearchBundleProviderWithNoSizeDstu1Test { private static Server ourServer; - @Before + @BeforeEach public void before() { ourLastMethod = null; ourIdentifiers = null; @@ -138,13 +138,13 @@ public class SearchBundleProviderWithNoSizeDstu1Test { } - @AfterClass + @AfterAll public static void afterClassClearContext() throws Exception { ourServer.stop(); TestUtil.clearAllStaticFieldsForUnitTest(); } - @BeforeClass + @BeforeAll public static void beforeClass() throws Exception { ourPort = PortUtil.findFreePort(); ourServer = new Server(ourPort); diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ServerBaseTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ServerBaseTest.java index 6ed7573c8ab..ac2b9ef05f4 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ServerBaseTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ServerBaseTest.java @@ -1,6 +1,6 @@ package ca.uhn.fhir.rest.server; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.util.Collections; import java.util.List; @@ -14,10 +14,10 @@ import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.servlet.ServletHolder; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEachClass; +import org.junit.jupiter.api.Test; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.api.Bundle; @@ -44,7 +44,7 @@ public class ServerBaseTest { } - @After + @AfterEach public void after() throws Exception { if (myServer != null) { myServer.stop(); @@ -150,7 +150,7 @@ public class ServerBaseTest { assertEquals("http://localhost:" + port + "/Patient/123", entry.getId().getValue()); assertEquals("http://localhost:" + port + "/Patient/123/_history/456", entry.getLinkSelf().getValue()); } - @BeforeClass + @BeforeAll public static void beforeClass() { PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(5000, TimeUnit.MILLISECONDS); HttpClientBuilder builder = HttpClientBuilder.create(); @@ -179,7 +179,7 @@ public class ServerBaseTest { } - @AfterClass + @AfterAll public static void afterClassClearContext() { TestUtil.clearAllStaticFieldsForUnitTest(); } diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ServerConformanceProviderTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ServerConformanceProviderTest.java index 952ecc58e47..0b9437d5c36 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ServerConformanceProviderTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ServerConformanceProviderTest.java @@ -1,9 +1,9 @@ package ca.uhn.fhir.rest.server; import static org.hamcrest.Matchers.containsString; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -11,8 +11,8 @@ import java.util.Collection; import java.util.List; import java.util.Set; -import org.junit.AfterClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.api.Include; @@ -222,7 +222,7 @@ public class ServerConformanceProviderTest { - @AfterClass + @AfterAll public static void afterClassClearContext() { TestUtil.clearAllStaticFieldsForUnitTest(); } diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ServerExtraParametersTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ServerExtraParametersTest.java index 81db77bd119..7a267287f0a 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ServerExtraParametersTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ServerExtraParametersTest.java @@ -1,6 +1,6 @@ package ca.uhn.fhir.rest.server; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.util.Arrays; import java.util.Collections; @@ -10,10 +10,10 @@ import org.eclipse.jetty.server.Server; import org.eclipse.jetty.servlet.ServletHandler; import org.eclipse.jetty.servlet.ServletHolder; import org.hamcrest.core.StringContains; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.api.IResource; @@ -38,7 +38,7 @@ public class ServerExtraParametersTest { private RestfulServer myServlet; private static FhirContext ourCtx = FhirContext.forDstu1(); - @Before + @BeforeEach public void before() { myPort = PortUtil.findFreePort(); myServer = new Server(myPort); @@ -92,7 +92,7 @@ public class ServerExtraParametersTest { } } - @After + @AfterEach public void after() throws Exception { myServer.stop(); } @@ -136,7 +136,7 @@ public class ServerExtraParametersTest { } - @AfterClass + @AfterAll public static void afterClassClearContext() { TestUtil.clearAllStaticFieldsForUnitTest(); } diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ServerFeaturesTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ServerFeaturesTest.java index a4f343c67e2..5e8e4180e16 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ServerFeaturesTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ServerFeaturesTest.java @@ -2,8 +2,8 @@ package ca.uhn.fhir.rest.server; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.not; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.hamcrest.MatcherAssert.assertThat; import java.util.Collections; import java.util.HashMap; @@ -23,10 +23,10 @@ import org.eclipse.jetty.servlet.ServletHandler; import org.eclipse.jetty.servlet.ServletHolder; import org.hamcrest.core.IsNot; import org.hamcrest.core.StringContains; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.BeforeEachClass; +import org.junit.jupiter.api.Test; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.api.Bundle; @@ -56,7 +56,7 @@ public class ServerFeaturesTest { private static Server ourServer; private static RestfulServer servlet; - @Before + @BeforeEach public void before() { servlet.setServerAddressStrategy(new IncomingRequestAddressStrategy()); } @@ -329,13 +329,13 @@ public class ServerFeaturesTest { } - @AfterClass + @AfterAll public static void afterClassClearContext() throws Exception { ourServer.stop(); TestUtil.clearAllStaticFieldsForUnitTest(); } - @BeforeClass + @BeforeAll public static void beforeClass() throws Exception { ourPort = PortUtil.findFreePort(); ourServer = new Server(ourPort); diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ServerInvalidDefinitionTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ServerInvalidDefinitionTest.java index be2822fe03f..c18766daa04 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ServerInvalidDefinitionTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ServerInvalidDefinitionTest.java @@ -1,6 +1,6 @@ package ca.uhn.fhir.rest.server; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.util.List; @@ -10,8 +10,8 @@ import org.hamcrest.core.StringContains; import org.hl7.fhir.instance.model.api.IBaseMetaType; 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.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.FhirVersionEnum; @@ -361,7 +361,7 @@ public class ServerInvalidDefinitionTest { } - @AfterClass + @AfterAll public static void afterClassClearContext() { TestUtil.clearAllStaticFieldsForUnitTest(); } diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ServerProvidedResourceScannerTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ServerProvidedResourceScannerTest.java index 1f5e97658b1..b6b8699d2c8 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ServerProvidedResourceScannerTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ServerProvidedResourceScannerTest.java @@ -12,8 +12,8 @@ import ca.uhn.fhir.rest.annotation.Read; import ca.uhn.fhir.util.TestUtil; import junit.framework.TestCase; -import org.junit.AfterClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; import javax.servlet.ServletException; @@ -112,7 +112,7 @@ public class ServerProvidedResourceScannerTest extends TestCase { } - @AfterClass + @AfterAll public static void afterClassClearContext() { TestUtil.clearAllStaticFieldsForUnitTest(); } diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ServletContextParsingTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ServletContextParsingTest.java index bfc758a1563..07a706bb98b 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ServletContextParsingTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ServletContextParsingTest.java @@ -1,6 +1,6 @@ package ca.uhn.fhir.rest.server; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.io.IOException; import java.util.concurrent.TimeUnit; @@ -17,10 +17,10 @@ import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; import org.eclipse.jetty.server.Server; 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; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.BeforeEachClass; +import org.junit.jupiter.api.Test; import ca.uhn.fhir.model.dstu.resource.Patient; import ca.uhn.fhir.model.primitive.IdDt; @@ -43,7 +43,7 @@ public class ServletContextParsingTest { } } - @Before + @BeforeEach public void before() { ourLastId = null; } @@ -150,7 +150,7 @@ public class ServletContextParsingTest { assertEquals("Patient/123/_history/222", ourLastId.getValue()); } - @BeforeClass + @BeforeAll public static void beforeClass() { PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(5000, TimeUnit.MILLISECONDS); HttpClientBuilder builder = HttpClientBuilder.create(); @@ -188,7 +188,7 @@ public class ServletContextParsingTest { } - @AfterClass + @AfterAll public static void afterClassClearContext() { TestUtil.clearAllStaticFieldsForUnitTest(); } diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/SortTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/SortTest.java index 113eb4be981..ebeddcbbf96 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/SortTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/SortTest.java @@ -1,6 +1,6 @@ package ca.uhn.fhir.rest.server; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.util.ArrayList; import java.util.List; @@ -15,9 +15,9 @@ 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.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEachClass; +import org.junit.jupiter.api.Test; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.api.Bundle; @@ -124,13 +124,13 @@ public class SortTest { } - @AfterClass + @AfterAll public static void afterClassClearContext() throws Exception { ourServer.stop(); TestUtil.clearAllStaticFieldsForUnitTest(); } - @BeforeClass + @BeforeAll public static void beforeClass() throws Exception { ourPort = PortUtil.findFreePort(); ourServer = new Server(ourPort); diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/StringParameterTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/StringParameterTest.java index e1bd16d5d4d..66cbb3a07c7 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/StringParameterTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/StringParameterTest.java @@ -1,6 +1,6 @@ package ca.uhn.fhir.rest.server; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.nio.charset.StandardCharsets; import java.util.ArrayList; @@ -16,9 +16,9 @@ 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.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEachClass; +import org.junit.jupiter.api.Test; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.api.IResource; @@ -162,13 +162,13 @@ public class StringParameterTest { } } - @AfterClass + @AfterAll public static void afterClassClearContext() throws Exception { ourServer.stop(); TestUtil.clearAllStaticFieldsForUnitTest(); } - @BeforeClass + @BeforeAll public static void beforeClass() throws Exception { ourPort = PortUtil.findFreePort(); ourServer = new Server(ourPort); diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/TagsServerTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/TagsServerTest.java index f7c9c11b366..cad29ffa59d 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/TagsServerTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/TagsServerTest.java @@ -1,7 +1,7 @@ package ca.uhn.fhir.rest.server; import static org.apache.commons.lang.StringUtils.defaultString; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.util.concurrent.TimeUnit; @@ -18,10 +18,10 @@ 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.Before; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.BeforeEachClass; +import org.junit.jupiter.api.Test; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.api.Tag; @@ -51,7 +51,7 @@ public class TagsServerTest { private static DummyProvider ourProvider; private static Server ourServer; - @Before + @BeforeEach public void before() { ourLastOutcome = null; ourLastTagList = null; @@ -228,13 +228,13 @@ public class TagsServerTest { } - @AfterClass + @AfterAll public static void afterClassClearContext() throws Exception { ourServer.stop(); TestUtil.clearAllStaticFieldsForUnitTest(); } - @BeforeClass + @BeforeAll public static void beforeClass() throws Exception { ourPort = PortUtil.findFreePort(); ourServer = new Server(ourPort); diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/TokenParamTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/TokenParamTest.java index 4ff5cca351e..7a12c35f9b9 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/TokenParamTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/TokenParamTest.java @@ -1,6 +1,6 @@ package ca.uhn.fhir.rest.server; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.util.ArrayList; import java.util.List; @@ -15,10 +15,10 @@ 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.Before; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.BeforeEachClass; +import org.junit.jupiter.api.Test; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.api.IResource; @@ -42,7 +42,7 @@ public class TokenParamTest { private static int ourPort; private static Server ourServer; - @Before + @BeforeEach public void before() { ourLastOrList = null; } @@ -194,13 +194,13 @@ public class TokenParamTest { } - @AfterClass + @AfterAll public static void afterClassClearContext() throws Exception { ourServer.stop(); TestUtil.clearAllStaticFieldsForUnitTest(); } - @BeforeClass + @BeforeAll public static void beforeClass() throws Exception { ourPort = PortUtil.findFreePort(); ourServer = new Server(ourPort); diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/TransactionTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/TransactionTest.java index 9eb46108241..20900c43ae0 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/TransactionTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/TransactionTest.java @@ -1,6 +1,6 @@ package ca.uhn.fhir.rest.server; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.util.ArrayList; import java.util.List; @@ -16,10 +16,10 @@ import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.servlet.ServletHolder; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.BeforeEachClass; +import org.junit.jupiter.api.Test; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.api.Bundle; @@ -48,7 +48,7 @@ public class TransactionTest { private static boolean ourReturnOperationOutcome; private static Server ourServer; - @Before + @BeforeEach public void before() { ourReturnOperationOutcome = false; ourDropFirstResource = false; @@ -218,13 +218,13 @@ public class TransactionTest { assertEquals(nowInstant.getValueAsString(), entry2.getDeletedAt().getValueAsString()); } - @AfterClass + @AfterAll public static void afterClassClearContext() throws Exception { ourServer.stop(); TestUtil.clearAllStaticFieldsForUnitTest(); } - @BeforeClass + @BeforeAll public static void beforeClass() throws Exception { ourPort = PortUtil.findFreePort(); ourServer = new Server(ourPort); diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/TransactionWithBundleParamTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/TransactionWithBundleParamTest.java index 924eaa7eff4..82be5b3fbd6 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/TransactionWithBundleParamTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/TransactionWithBundleParamTest.java @@ -1,6 +1,6 @@ package ca.uhn.fhir.rest.server; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.util.ArrayList; import java.util.List; @@ -16,10 +16,10 @@ import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.servlet.ServletHolder; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.BeforeEachClass; +import org.junit.jupiter.api.Test; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.api.Bundle; @@ -50,7 +50,7 @@ public class TransactionWithBundleParamTest { - @Before + @BeforeEach public void before() { ourReturnOperationOutcome = false; } @@ -167,7 +167,7 @@ public class TransactionWithBundleParamTest { assertEquals(nowInstant.getValueAsString(), entry2.getDeletedAt().getValueAsString()); } - @AfterClass + @AfterAll public static void afterClassClearContext() throws Exception { ourServer.stop(); TestUtil.clearAllStaticFieldsForUnitTest(); @@ -175,7 +175,7 @@ public class TransactionWithBundleParamTest { - @BeforeClass + @BeforeAll public static void beforeClass() throws Exception { ourPort = PortUtil.findFreePort(); ourServer = new Server(ourPort); diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/UpdateDstu1Test.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/UpdateDstu1Test.java index 59332edb52a..81ffc843e97 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/UpdateDstu1Test.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/UpdateDstu1Test.java @@ -1,6 +1,6 @@ package ca.uhn.fhir.rest.server; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.util.concurrent.TimeUnit; @@ -16,9 +16,9 @@ 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.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEachClass; +import org.junit.jupiter.api.Test; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.api.IResource; @@ -317,13 +317,13 @@ public class UpdateDstu1Test { fail(); } - @AfterClass + @AfterAll public static void afterClassClearContext() throws Exception { ourServer.stop(); TestUtil.clearAllStaticFieldsForUnitTest(); } - @BeforeClass + @BeforeAll public static void beforeClass() throws Exception { ourPort = PortUtil.findFreePort(); ourServer = new Server(ourPort); diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ValidateDstu1Test.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ValidateDstu1Test.java index 2ef1e8ff08f..fb9330f9291 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ValidateDstu1Test.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ValidateDstu1Test.java @@ -1,7 +1,7 @@ package ca.uhn.fhir.rest.server; import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.util.concurrent.TimeUnit; @@ -17,10 +17,10 @@ import org.eclipse.jetty.server.Server; import org.eclipse.jetty.servlet.ServletHandler; import org.eclipse.jetty.servlet.ServletHolder; import org.hamcrest.core.StringContains; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.BeforeEachClass; +import org.junit.jupiter.api.Test; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.api.IResource; @@ -44,7 +44,7 @@ public class ValidateDstu1Test { private static int ourPort; private static Server ourServer; - @Before() + @BeforeEach() public void before() { ourLastResourceBody = null; ourLastEncoding = null; @@ -87,13 +87,13 @@ public class ValidateDstu1Test { } - @AfterClass + @AfterAll public static void afterClassClearContext() throws Exception { ourServer.stop(); TestUtil.clearAllStaticFieldsForUnitTest(); } - @BeforeClass + @BeforeAll public static void beforeClass() throws Exception { ourPort = PortUtil.findFreePort(); ourServer = new Server(ourPort); diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/validation/ResourceValidatorTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/validation/ResourceValidatorTest.java index 364ab4c9ba5..6d2314e8d0e 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/validation/ResourceValidatorTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/validation/ResourceValidatorTest.java @@ -1,7 +1,7 @@ package ca.uhn.fhir.validation; import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.io.IOException; import java.text.SimpleDateFormat; @@ -9,9 +9,9 @@ import java.util.Locale; import org.apache.commons.io.IOUtils; import org.hamcrest.core.StringContains; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEachClass; +import org.junit.jupiter.api.Test; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.api.Bundle; @@ -53,7 +53,7 @@ public class ResourceValidatorTest { } } - @BeforeClass + @BeforeAll public static void beforeClass() { /* * We cache the default locale, but temporarily set it to a random value during this test. This helps ensure that there are no @@ -196,7 +196,7 @@ public class ResourceValidatorTest { return val; } - @AfterClass + @AfterAll public static void afterClassClearContext() { TestUtil.clearAllStaticFieldsForUnitTest(); } diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/validation/ValidatorInstantiatorTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/validation/ValidatorInstantiatorTest.java index e66e13be4bd..56243294eb6 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/validation/ValidatorInstantiatorTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/validation/ValidatorInstantiatorTest.java @@ -1,9 +1,9 @@ package ca.uhn.fhir.validation; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; -import org.junit.AfterClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.dstu.resource.Patient; @@ -25,7 +25,7 @@ public class ValidatorInstantiatorTest { } - @AfterClass + @AfterAll public static void afterClassClearContext() { TestUtil.clearAllStaticFieldsForUnitTest(); } diff --git a/hapi-fhir-structures-dstu2.1/pom.xml b/hapi-fhir-structures-dstu2.1/pom.xml index 76c940fdbe8..50855a66acf 100644 --- a/hapi-fhir-structures-dstu2.1/pom.xml +++ b/hapi-fhir-structures-dstu2.1/pom.xml @@ -29,6 +29,12 @@ org.fhir ucum true + + + junit + junit + + \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " " + - ""; + String input = "\n" + + " \n" + + " \n" + + " \n" + + "
\n" + + "\n" + + "

Patient Donald DUCK @ Acme Healthcare, Inc. MR = 654321

\n" + + "\n" + + "
\n" + + "
\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " " + + "
"; //@formatter:off Patient res = ourCtx.newXmlParser().parseResource(Patient.class, input); @@ -2036,66 +2073,66 @@ public class XmlParserDstu2Test { assertEquals("Patient/pat1", res.getId().getValue()); assertEquals("654321", res.getIdentifier().get(0).getValue()); assertEquals(true, res.getActive()); - + assertThat(res.getIdentifier().get(0).getFormatCommentsPre(), contains("identifier comment 1", "identifier comment 2")); assertThat(res.getIdentifier().get(0).getUseElement().getFormatCommentsPre(), contains("use comment 1", "use comment 2")); - + String encoded = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(res); ourLog.info(encoded); - + //@formatter:off assertThat(encoded, stringContainsInOrder( - "\"identifier\": [", - "{", - "\"fhir_comments\":", - "[", - "\"identifier comment 1\"", - ",", - "\"identifier comment 2\"", - "]", - "\"use\": \"usual\",", - "\"_use\": {", - "\"fhir_comments\":", - "[", - "\"use comment 1\"", - ",", - "\"use comment 2\"", - "]", - "},", - "\"type\"" + "\"identifier\": [", + "{", + "\"fhir_comments\":", + "[", + "\"identifier comment 1\"", + ",", + "\"identifier comment 2\"", + "]", + "\"use\": \"usual\",", + "\"_use\": {", + "\"fhir_comments\":", + "[", + "\"use comment 1\"", + ",", + "\"use comment 2\"", + "]", + "},", + "\"type\"" )); //@formatter:off - + encoded = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(res); ourLog.info(encoded); - + //@formatter:off assertThat(encoded, stringContainsInOrder( - "", - "", - "", - "", - "
", - "

Patient Donald DUCK @ Acme Healthcare, Inc. MR = 654321

", - "
", - "
", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "
" + "", + "", + "", + "", + "
", + "

Patient Donald DUCK @ Acme Healthcare, Inc. MR = 654321

", + "
", + "
", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "
" )); //@formatter:off @@ -2104,138 +2141,138 @@ public class XmlParserDstu2Test { @Test public void testParseAndEncodeExtensionOnResourceReference() { //@formatter:off - String input = - "" + - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ - ""+ + String input = + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + ""; //@formatter:on DataElement de = ourCtx.newXmlParser().parseResource(DataElement.class, input); @@ -2272,14 +2309,14 @@ public class XmlParserDstu2Test { @Test public void testParseAndEncodeNestedExtensions() { //@formatter:off - String input = "\n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + + String input = "\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + ""; //@formatter:on @@ -2302,14 +2339,14 @@ public class XmlParserDstu2Test { //@formatter:off assertThat(encoded, stringContainsInOrder( - "", + "", "", - "", - "", + "", + "", "", "", - "", - "", + "", + "", "")); //@formatter:on @@ -2318,17 +2355,17 @@ public class XmlParserDstu2Test { @Test public void testParseBundleNewWithPlaceholderIds() { //@formatter:off - String input = "\n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - "\n"; + String input = "\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + "\n"; //@formatter:on ca.uhn.fhir.model.dstu2.resource.Bundle parsed = ourCtx.newXmlParser().parseResource(ca.uhn.fhir.model.dstu2.resource.Bundle.class, input); @@ -2339,17 +2376,17 @@ public class XmlParserDstu2Test { @Test public void testParseBundleNewWithPlaceholderIdsInBase1() { //@formatter:off - String input = "\n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - "\n"; + String input = "\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + "\n"; //@formatter:on ca.uhn.fhir.model.dstu2.resource.Bundle parsed = ourCtx.newXmlParser().parseResource(ca.uhn.fhir.model.dstu2.resource.Bundle.class, input); @@ -2359,34 +2396,34 @@ public class XmlParserDstu2Test { @Test public void testParseBundleNewWithPlaceholderIdsInBase2() { //@formatter:off - String input = "\n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - "\n"; + String input = "\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + "\n"; //@formatter:on ca.uhn.fhir.model.dstu2.resource.Bundle parsed = ourCtx.newXmlParser().parseResource(ca.uhn.fhir.model.dstu2.resource.Bundle.class, input); assertEquals("urn:uuid:0.1.2.3", parsed.getEntry().get(0).getResource().getId().getValue()); //@formatter:off - input = "\n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - "\n"; + input = "\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + "\n"; //@formatter:on parsed = ourCtx.newXmlParser().parseResource(ca.uhn.fhir.model.dstu2.resource.Bundle.class, input); @@ -2397,29 +2434,29 @@ public class XmlParserDstu2Test { @Test public void testParseBundleOldStyleWithUnknownLinks() throws Exception { //@formatter:off - String bundle = "\n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + + String bundle = "\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + " \n" + " \n" + " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + ""; //@formatter:on @@ -2455,10 +2492,10 @@ public class XmlParserDstu2Test { public void testParseBundleWithResourceId() { //@formatter:off String input = "" - + "" - + "" - + "" - + "\n"; + + "" + + "" + + "" + + "\n"; //@formatter:on ca.uhn.fhir.model.dstu2.resource.Bundle bundle = ourCtx.newXmlParser().parseResource(ca.uhn.fhir.model.dstu2.resource.Bundle.class, input); @@ -2494,7 +2531,7 @@ public class XmlParserDstu2Test { "", "", "" - )); + )); //@formatter:on o = parser.parseResource(Observation.class, enc); @@ -2510,7 +2547,7 @@ public class XmlParserDstu2Test { */ @Test public void testParseContainedBinaryResource() { - byte[] bin = new byte[] { 0, 1, 2, 3, 4 }; + byte[] bin = new byte[]{0, 1, 2, 3, 4}; final Binary binary = new Binary(); binary.setContentType("PatientConsent").setContent(bin); // binary.setId(UUID.randomUUID().toString()); @@ -2538,17 +2575,20 @@ public class XmlParserDstu2Test { /** * See #366 */ - @Test(expected = DataFormatException.class) + @Test public void testParseInvalidBoolean() { - //@formatter:off - String resource = "\n" + - " \n" + - ""; - //@formatter:on + try { + String resource = "\n" + + " \n" + + ""; - IParser parser = ourCtx.newXmlParser(); - parser.setParserErrorHandler(new StrictErrorHandler()); - parser.parseResource(resource); + IParser parser = ourCtx.newXmlParser(); + parser.setParserErrorHandler(new StrictErrorHandler()); + parser.parseResource(resource); + fail(); + } catch (DataFormatException e) { + assertEquals("DataFormatException at [[row,col {unknown-source}]: [2,4]]: [element=\"active\"] Invalid attribute value \"1\": Invalid boolean string: '1'", e.getMessage()); + } } @Test @@ -2570,13 +2610,13 @@ public class XmlParserDstu2Test { // This was changed from 0.5 to 1.0.0 //@formatter:off - String out = "\n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - ""; + String out = "\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + ""; //@formatter:on IParserErrorHandler errorHandler = mock(IParserErrorHandler.class); @@ -2596,29 +2636,29 @@ public class XmlParserDstu2Test { @Test public void testParseMetadata() throws Exception { //@formatter:off - String bundle = "\n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + + String bundle = "\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + " \n" + " \n" + " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + ""; //@formatter:on @@ -2640,9 +2680,9 @@ public class XmlParserDstu2Test { toBundle.getLinkOrCreate("self").setUrl("http://localhost:52788/Binary?_pretty=true"); toBundle - .addEntry() - .setResource(pt) - .setFullUrl("http://foo/fhirBase2/Patient/1/_history/2"); + .addEntry() + .setResource(pt) + .setFullUrl("http://foo/fhirBase2/Patient/1/_history/2"); String reEncoded = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(toBundle); @@ -2654,19 +2694,19 @@ public class XmlParserDstu2Test { @Test public void testParseMetaUpdatedDate() { //@formatter:off - String input = "\n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - ""; + String input = "\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + ""; //@formatter:on ca.uhn.fhir.model.dstu2.resource.Bundle b = ourCtx.newXmlParser().parseResource(ca.uhn.fhir.model.dstu2.resource.Bundle.class, input); @@ -2679,13 +2719,13 @@ public class XmlParserDstu2Test { public void testParseNarrative() throws Exception { //@formatter:off String htmlNoNs = "
AAABBBCCC
"; - String htmlNs = htmlNoNs.replace("
", "
"); - String res= "\n" + - " \n" + - " \n" + - " " + htmlNs + "\n" + - " \n" + - ""; + String htmlNs = htmlNoNs.replace("
", "
"); + String res = "\n" + + " \n" + + " \n" + + " " + htmlNs + "\n" + + " \n" + + ""; //@formatter:on Patient p = ourCtx.newXmlParser().parseResource(Patient.class, res); @@ -2695,15 +2735,15 @@ public class XmlParserDstu2Test { @Test public void testParseNestedExtensionsInvalid() { //@formatter:off - String input = "\n" + + String input = "\n" + " \n" + - " \n" + + " \n" + " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + ""; //@formatter:on @@ -2789,7 +2829,7 @@ public class XmlParserDstu2Test { // Check no NPE if base server not configure newPatient = ourCtx.newXmlParser().parseResource(MyPatientWithCustomUrlExtension.class, new StringReader(parsedPatient)); - assertNull("myName", newPatient.getPetName().getValue()); + assertNull(newPatient.getPetName().getValue()); assertEquals("myName", ((StringDt) newPatient.getUndeclaredExtensionsByUrl("http://www.example.com/petname").get(0).getValue()).getValue()); } @@ -2844,27 +2884,15 @@ public class XmlParserDstu2Test { fhirPat = parser.parseResource(Patient.class, output); List extlst = fhirPat.getUndeclaredExtensionsByUrl("x1"); - Assert.assertEquals(1, extlst.size()); - Assert.assertEquals(refVal, ((ResourceReferenceDt) extlst.get(0).getValue()).getReference().getValue()); - } - - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } - - - public static void main(String[] args) { - IGenericClient c = ourCtx.newRestfulGenericClient("http://fhir-dev.healthintersections.com.au/open"); - // c.registerInterceptor(new LoggingInterceptor(true)); - c.read().resource("Patient").withId("324").execute(); + assertEquals(1, extlst.size()); + assertEquals(refVal, ((ResourceReferenceDt) extlst.get(0).getValue()).getReference().getValue()); } @ResourceDef(name = "Condition", profile = "http://hl7.org/fhir/profiles/custom-condition", id = "custom-condition") public static class CustomCondition extends Condition { private static final long serialVersionUID = 1L; - @Child(name = "abatement", min = 0, max = 1, order = Child.REPLACE_PARENT, type = { DateTimeDt.class }, summary = true) + @Child(name = "abatement", min = 0, max = 1, order = Child.REPLACE_PARENT, type = {DateTimeDt.class}, summary = true) private DateTimeDt myAbatement; public DateTimeDt getOurAbatement() { @@ -2894,17 +2922,28 @@ public class XmlParserDstu2Test { } } + @AfterAll + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + public static void main(String[] args) { + IGenericClient c = ourCtx.newRestfulGenericClient("http://fhir-dev.healthintersections.com.au/open"); + // c.registerInterceptor(new LoggingInterceptor(true)); + c.read().resource("Patient").withId("324").execute(); + } + public static void compareXml(String content, String reEncoded) { Diff d = DiffBuilder.compare(Input.fromString(content)) - .withTest(Input.fromString(reEncoded)) - .withNodeMatcher(new DefaultNodeMatcher(ElementSelectors.byNameAndText)) - .checkForSimilar() - .ignoreWhitespace() - .ignoreComments() - .withComparisonController(ComparisonControllers.Default) - .build(); + .withTest(Input.fromString(reEncoded)) + .withNodeMatcher(new DefaultNodeMatcher(ElementSelectors.byNameAndText)) + .checkForSimilar() + .ignoreWhitespace() + .ignoreComments() + .withComparisonController(ComparisonControllers.Default) + .build(); - assertTrue(d.toString(), !d.hasDifferences()); + assertTrue(!d.hasDifferences(), d.toString()); } } diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/parser/i391/TestOutcomeTest.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/parser/i391/TestOutcomeTest.java index 57c63c56b26..705ce385b09 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/parser/i391/TestOutcomeTest.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/parser/i391/TestOutcomeTest.java @@ -1,16 +1,17 @@ package ca.uhn.fhir.parser.i391; -import static org.junit.Assert.*; - -import org.junit.AfterClass; -import org.junit.Test; - import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.primitive.BoundCodeDt; import ca.uhn.fhir.model.primitive.StringDt; import ca.uhn.fhir.parser.CustomTypeDstu2Test; import ca.uhn.fhir.parser.IParser; import ca.uhn.fhir.util.TestUtil; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * See #391 @@ -77,9 +78,9 @@ public class TestOutcomeTest { assertEquals(outcome.getElement(), operationOutcome.getElement()); } - @AfterClass + @AfterAll public static void afterClassClearContext() { TestUtil.clearAllStaticFieldsForUnitTest(); } -} \ No newline at end of file +} diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/parser/i423/CustomProcedureRequestTest.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/parser/i423/CustomProcedureRequestTest.java index cd3ab0b304c..08dc6b74bc9 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/parser/i423/CustomProcedureRequestTest.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/parser/i423/CustomProcedureRequestTest.java @@ -1,9 +1,9 @@ package ca.uhn.fhir.parser.i423; import static org.hamcrest.Matchers.stringContainsInOrder; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; -import org.junit.Test; +import org.junit.jupiter.api.Test; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.primitive.IntegerDt; diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/parser/jsonlike/JsonLikeParserDstu2Test.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/parser/jsonlike/JsonLikeParserDstu2Test.java index f577cc8502b..25075decef3 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/parser/jsonlike/JsonLikeParserDstu2Test.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/parser/jsonlike/JsonLikeParserDstu2Test.java @@ -6,8 +6,8 @@ import ca.uhn.fhir.parser.json.JsonLikeStructure; import ca.uhn.fhir.parser.json.jackson.JacksonStructure; import ca.uhn.fhir.util.TestUtil; import org.apache.commons.io.IOUtils; -import org.junit.AfterClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; import java.io.StringReader; @@ -36,7 +36,7 @@ public class JsonLikeParserDstu2Test { } - @AfterClass + @AfterAll public static void afterClassClearContext() { TestUtil.clearAllStaticFieldsForUnitTest(); } 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 82357761c74..3467ae4044a 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 @@ -1,29 +1,5 @@ package ca.uhn.fhir.rest.client; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.io.StringReader; -import java.nio.charset.Charset; -import java.util.Arrays; - -import org.apache.commons.io.IOUtils; -import org.apache.commons.io.input.ReaderInputStream; -import org.apache.http.HttpResponse; -import org.apache.http.ProtocolVersion; -import org.apache.http.client.HttpClient; -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.hamcrest.Matchers; -import org.hl7.fhir.instance.model.api.IBaseResource; -import org.junit.*; -import org.mockito.ArgumentCaptor; -import org.mockito.internal.stubbing.defaultanswers.ReturnsDeepStubs; - import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.dstu2.resource.Bundle; import ca.uhn.fhir.model.dstu2.resource.Patient; @@ -34,6 +10,31 @@ import ca.uhn.fhir.rest.client.api.ServerValidationModeEnum; import ca.uhn.fhir.rest.client.interceptor.BearerTokenAuthInterceptor; import ca.uhn.fhir.rest.client.interceptor.LoggingInterceptor; import ca.uhn.fhir.util.TestUtil; +import org.apache.commons.io.IOUtils; +import org.apache.commons.io.input.ReaderInputStream; +import org.apache.http.HttpResponse; +import org.apache.http.ProtocolVersion; +import org.apache.http.client.HttpClient; +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.hamcrest.Matchers; +import org.hl7.fhir.instance.model.api.IBaseResource; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; +import org.mockito.ArgumentCaptor; +import org.mockito.internal.stubbing.defaultanswers.ReturnsDeepStubs; + +import java.io.StringReader; +import java.nio.charset.Charset; +import java.util.Arrays; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; public class BundleTypeDstu2Test { @@ -43,13 +44,13 @@ public class BundleTypeDstu2Test { private HttpResponse ourHttpResponse; - @AfterClass + @AfterAll public static void afterClassClearContext() { TestUtil.clearAllStaticFieldsForUnitTest(); } - @Before + @BeforeEach public void before() { ourCtx = FhirContext.forDstu2(); @@ -78,7 +79,7 @@ public class BundleTypeDstu2Test { HttpUriRequest value = capt.getValue(); - assertTrue("Expected request of type POST on long params list", value instanceof HttpPost); + assertTrue(value instanceof HttpPost, "Expected request of type POST on long params list"); HttpPost post = (HttpPost) value; String body = IOUtils.toString(post.getEntity().getContent()); IOUtils.closeQuietly(post.getEntity().getContent()); 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 e3732e10488..b78fa0afaec 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 @@ -1,25 +1,24 @@ package ca.uhn.fhir.rest.client; -import static org.junit.Assert.assertSame; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import org.hl7.fhir.instance.model.api.IBaseBundle; -import org.junit.AfterClass; -import org.junit.Test; -import org.mockito.internal.stubbing.defaultanswers.ReturnsDeepStubs; - import ca.uhn.fhir.model.dstu2.resource.Bundle; import ca.uhn.fhir.model.dstu2.resource.Condition; import ca.uhn.fhir.rest.client.api.IGenericClient; import ca.uhn.fhir.rest.gclient.ICriterion; import ca.uhn.fhir.util.TestUtil; +import org.hl7.fhir.instance.model.api.IBaseBundle; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; +import org.mockito.internal.stubbing.defaultanswers.ReturnsDeepStubs; + +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; public class ClientMockingTest { - @AfterClass + @AfterAll public static void afterClassClearContext() { TestUtil.clearAllStaticFieldsForUnitTest(); } diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/client/ClientServerValidationDstu2Test.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/client/ClientServerValidationDstu2Test.java index 4028e8c3c1a..cdf8cbf6038 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/client/ClientServerValidationDstu2Test.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/client/ClientServerValidationDstu2Test.java @@ -1,37 +1,7 @@ package ca.uhn.fhir.rest.client; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import java.io.InputStream; -import java.io.StringReader; -import java.nio.charset.Charset; - -import ca.uhn.fhir.context.FhirVersionEnum; -import org.apache.commons.io.input.ReaderInputStream; -import org.apache.http.*; -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.*; -import org.mockito.ArgumentCaptor; -import org.mockito.Matchers; -import org.mockito.internal.stubbing.defaultanswers.ReturnsDeepStubs; -import org.mockito.invocation.InvocationOnMock; -import org.mockito.stubbing.Answer; - import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.context.FhirVersionEnum; import ca.uhn.fhir.model.dstu2.resource.Conformance; import ca.uhn.fhir.model.dstu2.resource.Patient; import ca.uhn.fhir.model.primitive.UriDt; @@ -42,6 +12,39 @@ import ca.uhn.fhir.rest.client.exceptions.FhirClientInappropriateForServerExcept import ca.uhn.fhir.rest.client.interceptor.BasicAuthInterceptor; import ca.uhn.fhir.rest.server.exceptions.AuthenticationException; import ca.uhn.fhir.util.TestUtil; +import org.apache.commons.io.input.ReaderInputStream; +import org.apache.http.Header; +import org.apache.http.HttpResponse; +import org.apache.http.ProtocolVersion; +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.jupiter.api.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; +import org.mockito.ArgumentCaptor; +import org.mockito.Matchers; +import org.mockito.internal.stubbing.defaultanswers.ReturnsDeepStubs; +import org.mockito.invocation.InvocationOnMock; +import org.mockito.stubbing.Answer; + +import java.io.InputStream; +import java.io.StringReader; +import java.nio.charset.Charset; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.is; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; public class ClientServerValidationDstu2Test { @@ -51,13 +54,13 @@ public class ClientServerValidationDstu2Test { private HttpClient myHttpClient; private HttpResponse myHttpResponse; - @AfterClass + @AfterAll public static void afterClassClearContext() { TestUtil.clearAllStaticFieldsForUnitTest(); } - @Before + @BeforeEach public void before() { myHttpClient = mock(HttpClient.class, new ReturnsDeepStubs()); myHttpResponse = mock(HttpResponse.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 fa66405cc8f..a3aa5cfd783 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 @@ -1,29 +1,5 @@ package ca.uhn.fhir.rest.client; -import static org.hamcrest.Matchers.containsString; -import static org.junit.Assert.assertThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.io.InputStream; -import java.io.StringReader; -import java.nio.charset.Charset; - -import org.apache.commons.io.IOUtils; -import org.apache.commons.io.input.ReaderInputStream; -import org.apache.http.HttpResponse; -import org.apache.http.ProtocolVersion; -import org.apache.http.client.HttpClient; -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.*; -import org.mockito.ArgumentCaptor; -import org.mockito.internal.stubbing.defaultanswers.ReturnsDeepStubs; -import org.mockito.invocation.InvocationOnMock; -import org.mockito.stubbing.Answer; - import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.api.annotation.ResourceDef; import ca.uhn.fhir.model.dstu2.resource.OperationOutcome; @@ -33,6 +9,31 @@ import ca.uhn.fhir.rest.api.Constants; import ca.uhn.fhir.rest.client.api.IGenericClient; import ca.uhn.fhir.rest.client.api.ServerValidationModeEnum; import ca.uhn.fhir.util.TestUtil; +import org.apache.commons.io.IOUtils; +import org.apache.commons.io.input.ReaderInputStream; +import org.apache.http.HttpResponse; +import org.apache.http.ProtocolVersion; +import org.apache.http.client.HttpClient; +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.jupiter.api.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; +import org.mockito.ArgumentCaptor; +import org.mockito.internal.stubbing.defaultanswers.ReturnsDeepStubs; +import org.mockito.invocation.InvocationOnMock; +import org.mockito.stubbing.Answer; + +import java.io.InputStream; +import java.io.StringReader; +import java.nio.charset.Charset; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsString; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; public class ClientWithProfileDstu2Test { @@ -41,13 +42,13 @@ public class ClientWithProfileDstu2Test { private HttpClient ourHttpClient; private HttpResponse ourHttpResponse; - @AfterClass + @AfterAll public static void afterClassClearContext() { TestUtil.clearAllStaticFieldsForUnitTest(); } - @Before + @BeforeEach 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 892d7c6821f..ee74bfa7c32 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 @@ -1,30 +1,7 @@ package ca.uhn.fhir.rest.client; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.io.StringReader; -import java.nio.charset.Charset; - -import org.apache.commons.io.input.ReaderInputStream; -import org.apache.http.*; -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.hamcrest.core.StringContains; -import org.junit.*; -import org.mockito.ArgumentCaptor; -import org.mockito.internal.stubbing.defaultanswers.ReturnsDeepStubs; - import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.api.ResourceMetadataKeyEnum; -import ca.uhn.fhir.model.api.TagList; import ca.uhn.fhir.model.dstu2.resource.Patient; import ca.uhn.fhir.model.primitive.IdDt; import ca.uhn.fhir.model.primitive.InstantDt; @@ -34,6 +11,31 @@ import ca.uhn.fhir.rest.client.api.ServerValidationModeEnum; import ca.uhn.fhir.rest.server.exceptions.NotModifiedException; import ca.uhn.fhir.rest.server.exceptions.PreconditionFailedException; import ca.uhn.fhir.util.TestUtil; +import org.apache.commons.io.input.ReaderInputStream; +import org.apache.http.Header; +import org.apache.http.HttpResponse; +import org.apache.http.ProtocolVersion; +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.hamcrest.core.StringContains; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.mockito.ArgumentCaptor; +import org.mockito.internal.stubbing.defaultanswers.ReturnsDeepStubs; + +import java.io.StringReader; +import java.nio.charset.Charset; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.fail; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; /** * Created by dsotnikov on 2/25/2014. @@ -45,12 +47,12 @@ public class ETagClientDstu2Test { private HttpResponse myHttpResponse; - @AfterClass + @AfterAll public static void afterClassClearContext() { TestUtil.clearAllStaticFieldsForUnitTest(); } - @Before + @BeforeEach public void before() { myHttpClient = mock(HttpClient.class, new ReturnsDeepStubs()); @@ -280,7 +282,7 @@ public class ETagClientDstu2Test { } - @BeforeClass + @BeforeAll public static void beforeClass() { ourCtx = FhirContext.forDstu2(); } 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 0622c981494..415e46da9c4 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 @@ -9,20 +9,40 @@ import ca.uhn.fhir.model.api.Include; import ca.uhn.fhir.model.api.ResourceMetadataKeyEnum; import ca.uhn.fhir.model.dstu2.composite.IdentifierDt; import ca.uhn.fhir.model.dstu2.composite.MetaDt; -import ca.uhn.fhir.model.dstu2.resource.*; +import ca.uhn.fhir.model.dstu2.resource.Bundle; import ca.uhn.fhir.model.dstu2.resource.Bundle.Entry; import ca.uhn.fhir.model.dstu2.resource.Bundle.Link; +import ca.uhn.fhir.model.dstu2.resource.Conformance; import ca.uhn.fhir.model.dstu2.resource.Conformance.Rest; import ca.uhn.fhir.model.dstu2.resource.Conformance.RestSecurity; +import ca.uhn.fhir.model.dstu2.resource.Encounter; +import ca.uhn.fhir.model.dstu2.resource.Observation; +import ca.uhn.fhir.model.dstu2.resource.OperationOutcome; +import ca.uhn.fhir.model.dstu2.resource.Parameters; +import ca.uhn.fhir.model.dstu2.resource.Patient; import ca.uhn.fhir.model.dstu2.valueset.BundleTypeEnum; import ca.uhn.fhir.model.dstu2.valueset.HTTPVerbEnum; -import ca.uhn.fhir.model.primitive.*; +import ca.uhn.fhir.model.primitive.CodeDt; +import ca.uhn.fhir.model.primitive.DateDt; +import ca.uhn.fhir.model.primitive.IdDt; +import ca.uhn.fhir.model.primitive.InstantDt; +import ca.uhn.fhir.model.primitive.StringDt; +import ca.uhn.fhir.model.primitive.UriDt; import ca.uhn.fhir.parser.DataFormatException; import ca.uhn.fhir.parser.IParser; import ca.uhn.fhir.parser.XmlParserDstu2Test; -import ca.uhn.fhir.rest.api.*; +import ca.uhn.fhir.rest.api.Constants; +import ca.uhn.fhir.rest.api.EncodingEnum; +import ca.uhn.fhir.rest.api.MethodOutcome; +import ca.uhn.fhir.rest.api.PreferReturnEnum; +import ca.uhn.fhir.rest.api.RequestFormatParamStyleEnum; +import ca.uhn.fhir.rest.api.SearchStyleEnum; +import ca.uhn.fhir.rest.api.SummaryEnum; import ca.uhn.fhir.rest.client.apache.ApacheRestfulClientFactory; -import ca.uhn.fhir.rest.client.api.*; +import ca.uhn.fhir.rest.client.api.IGenericClient; +import ca.uhn.fhir.rest.client.api.IHttpClient; +import ca.uhn.fhir.rest.client.api.IRestfulClient; +import ca.uhn.fhir.rest.client.api.ServerValidationModeEnum; import ca.uhn.fhir.rest.client.exceptions.InvalidResponseException; import ca.uhn.fhir.rest.client.exceptions.NonFhirResponseException; import ca.uhn.fhir.rest.client.impl.BaseClient; @@ -45,10 +65,10 @@ 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; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; import org.mockito.internal.stubbing.defaultanswers.ReturnsDeepStubs; import org.mockito.invocation.InvocationOnMock; @@ -59,10 +79,21 @@ import java.io.IOException; import java.io.InputStream; import java.io.StringReader; import java.nio.charset.Charset; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Date; +import java.util.HashMap; +import java.util.List; -import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.either; +import static org.hamcrest.Matchers.emptyString; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.not; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -75,7 +106,7 @@ public class GenericClientDstu2Test { private int myResponseCount = 0; - @Before + @BeforeEach public void before() { myHttpClient = mock(HttpClient.class, new ReturnsDeepStubs()); ourCtx.setRestfulClientFactory(new ApacheRestfulClientFactory(ourCtx)); @@ -1183,7 +1214,7 @@ public class GenericClientDstu2Test { } - @Test(expected = IllegalArgumentException.class) + @Test public void testOperationWithInvalidParam() { IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir"); @@ -1222,14 +1253,17 @@ public class GenericClientDstu2Test { } }; - //@formatter:off - client - .operation() - .onServer() - .named("$SOMEOPERATION") - .withParameter(Parameters.class, "name1", weirdBase) - .execute(); - //@formatter:on + try { + client + .operation() + .onServer() + .named("$SOMEOPERATION") + .withParameter(Parameters.class, "name1", weirdBase) + .execute(); + fail(); + } catch (IllegalArgumentException e) { + assertEquals("Don't know how to handle parameter of type class ca.uhn.fhir.rest.client.GenericClientDstu2Test$22", e.getMessage()); + } } @Test @@ -2386,7 +2420,7 @@ public class GenericClientDstu2Test { client.transaction().withBundle(bundle).execute(); fail("Should throw an exception"); } catch (NonFhirResponseException e) { - assertEquals("status", Constants.STATUS_HTTP_204_NO_CONTENT, e.getStatusCode()); + assertEquals(Constants.STATUS_HTTP_204_NO_CONTENT, e.getStatusCode()); } } @@ -2725,12 +2759,12 @@ public class GenericClientDstu2Test { } - @AfterClass + @AfterAll public static void afterClassClearContext() { TestUtil.clearAllStaticFieldsForUnitTest(); } - @BeforeClass + @BeforeAll public static void beforeClass() { ourCtx = FhirContext.forDstu2(); } diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/client/MessageClientDstu2Test.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/client/MessageClientDstu2Test.java index a9d50f3cd32..4af974c8da4 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/client/MessageClientDstu2Test.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/client/MessageClientDstu2Test.java @@ -1,33 +1,10 @@ package ca.uhn.fhir.rest.client; -import static org.junit.Assert.assertEquals; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.io.InputStream; -import java.io.StringReader; -import java.nio.charset.Charset; -import java.util.Date; -import java.util.UUID; - -import org.apache.commons.io.input.ReaderInputStream; -import org.apache.http.HttpResponse; -import org.apache.http.ProtocolVersion; -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; -import org.mockito.internal.stubbing.defaultanswers.ReturnsDeepStubs; -import org.mockito.invocation.InvocationOnMock; -import org.mockito.stubbing.Answer; - import ca.uhn.fhir.context.FhirContext; -import ca.uhn.fhir.model.dstu2.resource.*; +import ca.uhn.fhir.model.dstu2.resource.Bundle; +import ca.uhn.fhir.model.dstu2.resource.MessageHeader; +import ca.uhn.fhir.model.dstu2.resource.OperationOutcome; import ca.uhn.fhir.model.dstu2.valueset.BundleTypeEnum; import ca.uhn.fhir.model.dstu2.valueset.ResponseTypeEnum; import ca.uhn.fhir.rest.api.Constants; @@ -37,6 +14,30 @@ import ca.uhn.fhir.rest.client.api.IGenericClient; import ca.uhn.fhir.rest.client.api.ServerValidationModeEnum; import ca.uhn.fhir.rest.client.impl.BaseClient; import ca.uhn.fhir.util.TestUtil; +import org.apache.commons.io.input.ReaderInputStream; +import org.apache.http.HttpResponse; +import org.apache.http.ProtocolVersion; +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.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.ArgumentCaptor; +import org.mockito.internal.stubbing.defaultanswers.ReturnsDeepStubs; +import org.mockito.invocation.InvocationOnMock; +import org.mockito.stubbing.Answer; + +import java.io.InputStream; +import java.io.StringReader; +import java.nio.charset.Charset; +import java.util.Date; +import java.util.UUID; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; public class MessageClientDstu2Test { @@ -46,12 +47,12 @@ public class MessageClientDstu2Test { private HttpResponse myHttpResponse; - @AfterClass + @AfterAll public static void afterClassClearContext() { TestUtil.clearAllStaticFieldsForUnitTest(); } - @Before + @BeforeEach public void before() { ourCtx = FhirContext.forDstu2(); 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 55d03015dd6..fa7cac1a1a5 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 @@ -1,14 +1,18 @@ package ca.uhn.fhir.rest.client; -import static org.junit.Assert.assertEquals; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.io.InputStream; -import java.io.StringReader; -import java.nio.charset.Charset; -import java.util.*; - +import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.model.dstu2.resource.Bundle; +import ca.uhn.fhir.model.dstu2.resource.Parameters; +import ca.uhn.fhir.model.dstu2.resource.Patient; +import ca.uhn.fhir.model.primitive.IdDt; +import ca.uhn.fhir.model.primitive.StringDt; +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.api.Constants; +import ca.uhn.fhir.rest.client.api.IBasicClient; +import ca.uhn.fhir.rest.client.api.ServerValidationModeEnum; +import ca.uhn.fhir.util.TestUtil; import org.apache.commons.io.IOUtils; import org.apache.commons.io.input.ReaderInputStream; import org.apache.http.HttpResponse; @@ -18,23 +22,24 @@ 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.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; import org.mockito.internal.stubbing.defaultanswers.ReturnsDeepStubs; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; -import ca.uhn.fhir.context.FhirContext; -import ca.uhn.fhir.model.dstu2.resource.*; -import ca.uhn.fhir.model.primitive.IdDt; -import ca.uhn.fhir.model.primitive.StringDt; -import ca.uhn.fhir.rest.annotation.*; -import ca.uhn.fhir.rest.api.Constants; -import ca.uhn.fhir.rest.client.api.IBasicClient; -import ca.uhn.fhir.rest.client.api.ServerValidationModeEnum; -import ca.uhn.fhir.util.TestUtil; +import java.io.InputStream; +import java.io.StringReader; +import java.nio.charset.Charset; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; public class OperationClientDstu2Test { @@ -44,13 +49,13 @@ public class OperationClientDstu2Test { private HttpResponse ourHttpResponse; - @AfterClass + @AfterAll public static void afterClassClearContext() { TestUtil.clearAllStaticFieldsForUnitTest(); } - @Before + @BeforeEach public void before() { ourCtx = FhirContext.forDstu2(); diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/client/RestfulClientFactoryDstu2Test.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/client/RestfulClientFactoryDstu2Test.java index 16b15fcfb42..dcedf922bc9 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/client/RestfulClientFactoryDstu2Test.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/client/RestfulClientFactoryDstu2Test.java @@ -1,17 +1,5 @@ package ca.uhn.fhir.rest.client; -import static org.junit.Assert.fail; -import static org.mockito.ArgumentMatchers.nullable; -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.*; - -import java.util.List; -import java.util.Map; - -import org.junit.AfterClass; -import org.junit.Test; -import org.mockito.Mockito; - import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.FhirVersionEnum; import ca.uhn.fhir.model.dstu2.resource.Conformance; @@ -19,10 +7,27 @@ import ca.uhn.fhir.parser.DataFormatException; import ca.uhn.fhir.rest.api.EncodingEnum; import ca.uhn.fhir.rest.api.RequestTypeEnum; import ca.uhn.fhir.rest.client.apache.ApacheRestfulClientFactory; -import ca.uhn.fhir.rest.client.api.*; +import ca.uhn.fhir.rest.client.api.IHttpClient; +import ca.uhn.fhir.rest.client.api.IHttpRequest; +import ca.uhn.fhir.rest.client.api.IHttpResponse; +import ca.uhn.fhir.rest.client.api.IRestfulClientFactory; import ca.uhn.fhir.rest.client.impl.BaseClient; import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException; import ca.uhn.fhir.util.TestUtil; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; + +import java.util.List; +import java.util.Map; + +import static org.junit.jupiter.api.Assertions.fail; +import static org.mockito.ArgumentMatchers.nullable; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.RETURNS_DEEP_STUBS; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; +import static org.mockito.Mockito.withSettings; public class RestfulClientFactoryDstu2Test { @@ -67,7 +72,7 @@ public class RestfulClientFactoryDstu2Test { } - @AfterClass + @AfterAll public static void afterClassClearContext() { TestUtil.clearAllStaticFieldsForUnitTest(); } diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/client/apache/ApacheClientIntegrationTest.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/client/apache/ApacheClientIntegrationTest.java index 600b475a9b3..b4ad22b97b9 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/client/apache/ApacheClientIntegrationTest.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/client/apache/ApacheClientIntegrationTest.java @@ -1,16 +1,5 @@ package ca.uhn.fhir.rest.client.apache; -import static org.junit.Assert.assertEquals; - -import java.util.ArrayList; -import java.util.List; - -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.*; - import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.dstu2.resource.Bundle; import ca.uhn.fhir.model.dstu2.resource.Patient; @@ -23,6 +12,19 @@ import ca.uhn.fhir.rest.server.RestfulServer; import ca.uhn.fhir.rest.server.interceptor.VerboseLoggingInterceptor; import ca.uhn.fhir.test.utilities.JettyUtil; import ca.uhn.fhir.util.TestUtil; +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.jupiter.api.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; + +import java.util.ArrayList; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; public class ApacheClientIntegrationTest { @@ -33,7 +35,7 @@ public class ApacheClientIntegrationTest { private static Server ourServer; private static String ourBase; - @Before + @BeforeEach public void before() { ourLastMethod = null; ourLastName = null; @@ -52,13 +54,13 @@ public class ApacheClientIntegrationTest { assertEquals("123", response.getEntry().get(0).getResource().getIdElement().getIdPart()); } - @AfterClass + @AfterAll public static void afterClassClearContext() throws Exception { JettyUtil.closeServer(ourServer); TestUtil.clearAllStaticFieldsForUnitTest(); } - @BeforeClass + @BeforeAll public static void beforeClass() throws Exception { ourServer = new Server(0); diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/client/apache/ApacheRestfulClientFactoryTest.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/client/apache/ApacheRestfulClientFactoryTest.java index d837254815e..8502e7bc563 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/client/apache/ApacheRestfulClientFactoryTest.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/client/apache/ApacheRestfulClientFactoryTest.java @@ -1,9 +1,9 @@ package ca.uhn.fhir.rest.client.apache; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; -import org.junit.Test; +import org.junit.jupiter.api.Test; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.rest.client.exceptions.FhirClientConnectionException; diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/param/DateParamTest.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/param/DateParamTest.java index 5810b7c97e3..236ee7367a8 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/param/DateParamTest.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/param/DateParamTest.java @@ -2,21 +2,19 @@ package ca.uhn.fhir.rest.param; import ca.uhn.fhir.model.primitive.DateTimeDt; import ca.uhn.fhir.model.primitive.InstantDt; -import com.google.common.testing.EqualsTester; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.Date; import java.util.TimeZone; -import java.util.concurrent.TimeUnit; import static ca.uhn.fhir.rest.param.ParamPrefixEnum.APPROXIMATE; import static ca.uhn.fhir.rest.param.ParamPrefixEnum.EQUAL; import static ca.uhn.fhir.rest.param.ParamPrefixEnum.NOT_EQUAL; import static java.util.concurrent.TimeUnit.SECONDS; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.endsWith; import static org.hamcrest.Matchers.startsWith; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; public class DateParamTest { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(DateParamTest.class); @@ -101,7 +99,7 @@ public class DateParamTest { ourLog.info("POST: " + dt.getValue()); assertEquals("2016-06-09T16:38:00.000-04:00", dt.getValueAsString()); } - + @Test public void testParseLegacyPrefixes() { assertEquals(ParamPrefixEnum.APPROXIMATE, new DateParam("ap2012").getPrefix()); @@ -115,16 +113,9 @@ public class DateParamTest { public void testEqualsAndHashCode() { Date now = new Date(); Date later = new Date(now.getTime() + SECONDS.toMillis(666)); - new EqualsTester() - .addEqualityGroup(new DateParam(), - new DateParam(null)) - .addEqualityGroup(new DateParam(NOT_EQUAL, now), - new DateParam(NOT_EQUAL, now.getTime())) - .addEqualityGroup(new DateParam(EQUAL, now), - new DateParam(EQUAL, now.getTime())) - .addEqualityGroup(new DateParam(EQUAL, later), - new DateParam(EQUAL, later.getTime())) - .addEqualityGroup(new DateParam(APPROXIMATE, "2011-11-11T11:11:11.111-11:11")) - .testEquals(); + assertEquals(new DateParam(), new DateParam(null)); + assertEquals(new DateParam(NOT_EQUAL, now), new DateParam(NOT_EQUAL, now.getTime())); + assertEquals(new DateParam(EQUAL, now), new DateParam(EQUAL, now.getTime())); + assertEquals(new DateParam(EQUAL, later), new DateParam(EQUAL, later.getTime())); } } diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/param/TokenOrListParamDstu2Test.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/param/TokenOrListParamDstu2Test.java index 988403e51ac..d12e6f1f008 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/param/TokenOrListParamDstu2Test.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/param/TokenOrListParamDstu2Test.java @@ -1,16 +1,15 @@ package ca.uhn.fhir.rest.param; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import ca.uhn.fhir.model.dstu2.composite.CodingDt; +import ca.uhn.fhir.util.TestUtil; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; import java.util.ArrayList; import java.util.List; -import org.junit.AfterClass; -import org.junit.Test; - -import ca.uhn.fhir.model.dstu2.composite.CodingDt; -import ca.uhn.fhir.util.TestUtil; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; public class TokenOrListParamDstu2Test { @Test @@ -52,7 +51,7 @@ public class TokenOrListParamDstu2Test { assertFalse(params.doesCodingListMatch(codings)); } - @AfterClass + @AfterAll public static void afterClassClearContext() { TestUtil.clearAllStaticFieldsForUnitTest(); } 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 dea8d771cb5..4d0b77c6288 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 @@ -5,7 +5,11 @@ import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.model.dstu2.resource.Binary; import ca.uhn.fhir.model.dstu2.resource.Bundle; import ca.uhn.fhir.model.primitive.IdDt; -import ca.uhn.fhir.rest.annotation.*; +import ca.uhn.fhir.rest.annotation.Create; +import ca.uhn.fhir.rest.annotation.IdParam; +import ca.uhn.fhir.rest.annotation.Read; +import ca.uhn.fhir.rest.annotation.ResourceParam; +import ca.uhn.fhir.rest.annotation.Search; import ca.uhn.fhir.rest.api.Constants; import ca.uhn.fhir.rest.api.EncodingEnum; import ca.uhn.fhir.rest.api.MethodOutcome; @@ -25,10 +29,10 @@ 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.Before; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.io.IOException; import java.nio.charset.StandardCharsets; @@ -36,8 +40,11 @@ import java.util.Collections; import java.util.List; import java.util.concurrent.TimeUnit; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.startsWith; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; /** * Created by dsotnikov on 2/25/2014. @@ -52,7 +59,7 @@ public class BinaryDstu2Test { private static Server ourServer; - @Before + @BeforeEach public void before() { ourLast = null; } @@ -238,13 +245,13 @@ public class BinaryDstu2Test { } } - @AfterClass + @AfterAll public static void afterClassClearContext() throws Exception { JettyUtil.closeServer(ourServer); TestUtil.clearAllStaticFieldsForUnitTest(); } - @BeforeClass + @BeforeAll public static void beforeClass() throws Exception { ourServer = new Server(0); 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 fb1b773cf5e..e978f992d7a 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 @@ -1,12 +1,15 @@ package ca.uhn.fhir.rest.server; -import static org.junit.Assert.assertEquals; - -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.TimeUnit; - +import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.model.api.IResource; +import ca.uhn.fhir.model.dstu2.resource.Bundle; +import ca.uhn.fhir.model.dstu2.resource.Patient; +import ca.uhn.fhir.model.dstu2.valueset.BundleTypeEnum; +import ca.uhn.fhir.narrative.DefaultThymeleafNarrativeGenerator; +import ca.uhn.fhir.rest.annotation.Search; import ca.uhn.fhir.rest.api.EncodingEnum; +import ca.uhn.fhir.test.utilities.JettyUtil; +import ca.uhn.fhir.util.TestUtil; import org.apache.commons.io.IOUtils; import org.apache.http.HttpResponse; import org.apache.http.client.methods.HttpGet; @@ -16,17 +19,15 @@ 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.*; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; -import ca.uhn.fhir.context.FhirContext; -import ca.uhn.fhir.model.api.IResource; -import ca.uhn.fhir.model.dstu2.resource.Bundle; -import ca.uhn.fhir.model.dstu2.resource.Patient; -import ca.uhn.fhir.model.dstu2.valueset.BundleTypeEnum; -import ca.uhn.fhir.narrative.DefaultThymeleafNarrativeGenerator; -import ca.uhn.fhir.rest.annotation.Search; -import ca.uhn.fhir.test.utilities.JettyUtil; -import ca.uhn.fhir.util.TestUtil; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.TimeUnit; + +import static org.junit.jupiter.api.Assertions.assertEquals; /** * Created by dsotnikov on 2/25/2014. @@ -57,13 +58,13 @@ public class BundleTypeInResponseTest { - @AfterClass + @AfterAll public static void afterClassClearContext() throws Exception { JettyUtil.closeServer(ourServer); TestUtil.clearAllStaticFieldsForUnitTest(); } - @BeforeClass + @BeforeAll public static void beforeClass() throws Exception { ourServer = new Server(0); @@ -92,7 +93,7 @@ public class BundleTypeInResponseTest { @Search public List findPatient() { - ArrayList retVal = new ArrayList(); + ArrayList retVal = new ArrayList<>(); Patient patient = new Patient(); patient.setId("1"); 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 4acb2d14d3b..359c9a563c3 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 @@ -1,32 +1,5 @@ package ca.uhn.fhir.rest.server; -import static org.hamcrest.Matchers.contains; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.startsWith; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; - -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.TimeUnit; - -import ca.uhn.fhir.rest.api.EncodingEnum; -import org.apache.commons.io.IOUtils; -import org.apache.http.HttpResponse; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClientBuilder; -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.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Test; - import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.dstu2.composite.ResourceReferenceDt; import ca.uhn.fhir.model.dstu2.resource.Encounter; @@ -36,8 +9,31 @@ 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.rest.annotation.Search; +import ca.uhn.fhir.rest.api.EncodingEnum; import ca.uhn.fhir.test.utilities.JettyUtil; import ca.uhn.fhir.util.TestUtil; +import org.apache.commons.io.IOUtils; +import org.apache.http.HttpResponse; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClientBuilder; +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.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.TimeUnit; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.startsWith; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * Created by dsotnikov on 2/25/2014. @@ -52,13 +48,13 @@ public class CompartmentDstu2Test { private static FhirContext ourCtx = FhirContext.forDstu2(); private static IdDt ourLastId; - @AfterClass + @AfterAll public static void afterClassClearContext() { TestUtil.clearAllStaticFieldsForUnitTest(); } - @Before + @BeforeEach public void before() { ourLastMethod = null; ourLastId = null; @@ -112,7 +108,7 @@ public class CompartmentDstu2Test { assertThat(responseContent, containsString(" search(@OptionalParam(name="foo") StringDt theString) { ourLastRequestWasSearch = true; - return new ArrayList(); + 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 f9d13582ad5..946109b7600 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 @@ -1,10 +1,16 @@ package ca.uhn.fhir.rest.server; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; - -import java.util.concurrent.TimeUnit; - +import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.model.api.IResource; +import ca.uhn.fhir.model.dstu2.resource.Patient; +import ca.uhn.fhir.model.primitive.IdDt; +import ca.uhn.fhir.rest.annotation.ConditionalUrlParam; +import ca.uhn.fhir.rest.annotation.Delete; +import ca.uhn.fhir.rest.annotation.IdParam; +import ca.uhn.fhir.rest.api.Constants; +import ca.uhn.fhir.rest.api.MethodOutcome; +import ca.uhn.fhir.test.utilities.JettyUtil; +import ca.uhn.fhir.util.TestUtil; import org.apache.http.HttpResponse; import org.apache.http.client.methods.HttpDelete; import org.apache.http.impl.client.CloseableHttpClient; @@ -13,17 +19,15 @@ 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.*; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; -import ca.uhn.fhir.context.FhirContext; -import ca.uhn.fhir.model.api.IResource; -import ca.uhn.fhir.model.dstu2.resource.Patient; -import ca.uhn.fhir.model.primitive.IdDt; -import ca.uhn.fhir.rest.annotation.*; -import ca.uhn.fhir.rest.api.Constants; -import ca.uhn.fhir.rest.api.MethodOutcome; -import ca.uhn.fhir.test.utilities.JettyUtil; -import ca.uhn.fhir.util.TestUtil; +import java.util.concurrent.TimeUnit; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; public class DeleteDstu2Test { private static CloseableHttpClient ourClient; @@ -35,7 +39,7 @@ public class DeleteDstu2Test { private static Server ourServer; - @Before + @BeforeEach public void before() { ourLastConditionalUrl = null; ourLastIdParam = null; @@ -76,14 +80,14 @@ public class DeleteDstu2Test { } - @AfterClass + @AfterAll public static void afterClassClearContext() throws Exception { JettyUtil.closeServer(ourServer); TestUtil.clearAllStaticFieldsForUnitTest(); } - @BeforeClass + @BeforeAll public static void beforeClass() throws Exception { ourServer = new Server(0); 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 df4b8a3669b..e13099430d8 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 @@ -1,27 +1,5 @@ package ca.uhn.fhir.rest.server; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import java.io.IOException; -import java.util.Date; -import java.util.concurrent.TimeUnit; - -import ca.uhn.fhir.rest.api.EncodingEnum; -import org.apache.commons.io.IOUtils; -import org.apache.http.Header; -import org.apache.http.HttpResponse; -import org.apache.http.client.methods.*; -import org.apache.http.entity.ContentType; -import org.apache.http.entity.StringEntity; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClientBuilder; -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.*; - import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.model.api.ResourceMetadataKeyEnum; @@ -29,12 +7,41 @@ import ca.uhn.fhir.model.dstu2.composite.IdentifierDt; import ca.uhn.fhir.model.dstu2.resource.Patient; import ca.uhn.fhir.model.primitive.IdDt; import ca.uhn.fhir.model.primitive.InstantDt; -import ca.uhn.fhir.rest.annotation.*; +import ca.uhn.fhir.rest.annotation.IdParam; +import ca.uhn.fhir.rest.annotation.Read; +import ca.uhn.fhir.rest.annotation.ResourceParam; +import ca.uhn.fhir.rest.annotation.Update; import ca.uhn.fhir.rest.api.Constants; +import ca.uhn.fhir.rest.api.EncodingEnum; import ca.uhn.fhir.rest.api.MethodOutcome; import ca.uhn.fhir.rest.server.exceptions.PreconditionFailedException; import ca.uhn.fhir.test.utilities.JettyUtil; import ca.uhn.fhir.util.TestUtil; +import org.apache.commons.io.IOUtils; +import org.apache.http.Header; +import org.apache.http.HttpResponse; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpPut; +import org.apache.http.entity.ContentType; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClientBuilder; +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.jupiter.api.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; + +import java.io.IOException; +import java.util.Date; +import java.util.concurrent.TimeUnit; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; public class ETagServerTest { @@ -49,7 +56,7 @@ public class ETagServerTest { private static Server ourServer; - @Before + @BeforeEach public void before() throws IOException { ourLastId = null; } @@ -182,13 +189,13 @@ public class ETagServerTest { } - @AfterClass + @AfterAll public static void afterClassClearContext() throws Exception { JettyUtil.closeServer(ourServer); TestUtil.clearAllStaticFieldsForUnitTest(); } - @BeforeClass + @BeforeAll public static void beforeClass() throws Exception { ourServer = new Server(0); 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 7e837c9b621..584b2f94bf8 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 @@ -1,24 +1,5 @@ package ca.uhn.fhir.rest.server; -import static org.hamcrest.Matchers.containsInAnyOrder; -import static org.hamcrest.Matchers.hasSize; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; - -import java.util.*; -import java.util.concurrent.TimeUnit; - -import org.apache.commons.io.IOUtils; -import org.apache.http.HttpResponse; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClientBuilder; -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.*; - import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.api.BundleInclusionRule; import ca.uhn.fhir.model.api.IResource; @@ -28,6 +9,29 @@ import ca.uhn.fhir.rest.annotation.IncludeParam; import ca.uhn.fhir.rest.annotation.Search; import ca.uhn.fhir.test.utilities.JettyUtil; import ca.uhn.fhir.util.TestUtil; +import org.apache.commons.io.IOUtils; +import org.apache.http.HttpResponse; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClientBuilder; +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.jupiter.api.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; + +import java.util.ArrayList; +import java.util.List; +import java.util.Set; +import java.util.concurrent.TimeUnit; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsInAnyOrder; +import static org.hamcrest.Matchers.hasSize; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * Created by dsotnikov on 2/25/2014. @@ -42,7 +46,7 @@ public class IncludeAndRevincludeParameterTest { private static Set ourReverseIncludes; private static Server ourServer; - @Before + @BeforeEach public void before() { ourIncludes = null; ourReverseIncludes = null; @@ -76,13 +80,13 @@ public class IncludeAndRevincludeParameterTest { } - @AfterClass + @AfterAll public static void afterClassClearContext() throws Exception { JettyUtil.closeServer(ourServer); TestUtil.clearAllStaticFieldsForUnitTest(); } - @BeforeClass + @BeforeAll public static void beforeClass() throws Exception { ourCtx = FhirContext.forDstu2(); 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 d67c4468f42..6a975c8fcc2 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 @@ -8,7 +8,12 @@ import ca.uhn.fhir.model.api.annotation.Child; import ca.uhn.fhir.model.api.annotation.Extension; import ca.uhn.fhir.model.api.annotation.ResourceDef; import ca.uhn.fhir.model.dstu2.composite.ResourceReferenceDt; -import ca.uhn.fhir.model.dstu2.resource.*; +import ca.uhn.fhir.model.dstu2.resource.Bundle; +import ca.uhn.fhir.model.dstu2.resource.DiagnosticReport; +import ca.uhn.fhir.model.dstu2.resource.Observation; +import ca.uhn.fhir.model.dstu2.resource.Organization; +import ca.uhn.fhir.model.dstu2.resource.Patient; +import ca.uhn.fhir.model.dstu2.resource.Practitioner; import ca.uhn.fhir.model.dstu2.valueset.SearchEntryModeEnum; import ca.uhn.fhir.model.primitive.IdDt; import ca.uhn.fhir.model.primitive.StringDt; @@ -29,17 +34,22 @@ 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.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Set; import java.util.concurrent.TimeUnit; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsInAnyOrder; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; public class IncludeDstu2Test { @@ -165,7 +175,7 @@ public class IncludeDstu2Test { } @Test - @Ignore + @Disabled public void testMixedContainedAndNonContained() throws Exception { HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/DiagnosticReport?_query=stitchedInclude&_pretty=true"); HttpResponse status = ourClient.execute(httpGet); @@ -439,13 +449,13 @@ public class IncludeDstu2Test { } - @AfterClass + @AfterAll public static void afterClassClearContext() throws Exception { JettyUtil.closeServer(ourServer); TestUtil.clearAllStaticFieldsForUnitTest(); } - @BeforeClass + @BeforeAll public static void beforeClass() throws Exception { ourCtx = FhirContext.forDstu2(); 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 1982ec089a8..b042b34659b 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 @@ -1,24 +1,5 @@ package ca.uhn.fhir.rest.server; -import static org.junit.Assert.*; - -import java.util.concurrent.TimeUnit; - -import ca.uhn.fhir.rest.api.EncodingEnum; -import org.apache.commons.io.IOUtils; -import org.apache.http.HttpResponse; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClientBuilder; -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.hl7.fhir.instance.model.api.IBaseResource; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; - import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.dstu2.resource.Conformance; import ca.uhn.fhir.model.dstu2.resource.OperationDefinition; @@ -28,8 +9,26 @@ import ca.uhn.fhir.model.dstu2.resource.Patient; 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.rest.api.EncodingEnum; import ca.uhn.fhir.test.utilities.JettyUtil; import ca.uhn.fhir.util.TestUtil; +import org.apache.commons.io.IOUtils; +import org.apache.http.HttpResponse; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClientBuilder; +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.hl7.fhir.instance.model.api.IBaseResource; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +import java.util.concurrent.TimeUnit; + +import static org.junit.jupiter.api.Assertions.assertEquals; public class OperationDuplicateServerDstu2Test { private static CloseableHttpClient ourClient; @@ -95,13 +94,13 @@ public class OperationDuplicateServerDstu2Test { - @AfterClass + @AfterAll public static void afterClassClearContext() throws Exception { JettyUtil.closeServer(ourServer); TestUtil.clearAllStaticFieldsForUnitTest(); } - @BeforeClass + @BeforeAll public static void beforeClass() throws Exception { ourCtx = FhirContext.forDstu2(); ourServer = new Server(0); 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 f63f1d26f68..b6f51ed2243 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 @@ -1,23 +1,35 @@ package ca.uhn.fhir.rest.server; -import static org.hamcrest.Matchers.blankOrNullString; -import static org.hamcrest.Matchers.containsInRelativeOrder; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.greaterThan; -import static org.hamcrest.Matchers.not; -import static org.hamcrest.Matchers.startsWith; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThat; - -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.TimeUnit; - +import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.model.api.IResource; +import ca.uhn.fhir.model.dstu2.composite.MoneyDt; +import ca.uhn.fhir.model.dstu2.resource.Bundle; +import ca.uhn.fhir.model.dstu2.resource.Conformance; +import ca.uhn.fhir.model.dstu2.resource.Conformance.RestOperation; +import ca.uhn.fhir.model.dstu2.resource.OperationDefinition; +import ca.uhn.fhir.model.dstu2.resource.Parameters; +import ca.uhn.fhir.model.dstu2.resource.Patient; +import ca.uhn.fhir.model.dstu2.valueset.OperationParameterUseEnum; +import ca.uhn.fhir.model.primitive.IdDt; +import ca.uhn.fhir.model.primitive.IntegerDt; +import ca.uhn.fhir.model.primitive.StringDt; +import ca.uhn.fhir.model.primitive.UnsignedIntDt; +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.rest.api.Constants; import ca.uhn.fhir.rest.api.EncodingEnum; +import ca.uhn.fhir.rest.api.server.IBundleProvider; +import ca.uhn.fhir.rest.client.api.IGenericClient; +import ca.uhn.fhir.rest.client.interceptor.LoggingInterceptor; +import ca.uhn.fhir.test.utilities.JettyUtil; +import ca.uhn.fhir.util.TestUtil; import org.apache.commons.io.IOUtils; import org.apache.http.HttpResponse; -import org.apache.http.client.methods.*; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpPost; import org.apache.http.entity.ContentType; import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.CloseableHttpClient; @@ -27,23 +39,24 @@ 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.*; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -import ca.uhn.fhir.context.FhirContext; -import ca.uhn.fhir.model.api.IResource; -import ca.uhn.fhir.model.dstu2.composite.MoneyDt; -import ca.uhn.fhir.model.dstu2.resource.*; -import ca.uhn.fhir.model.dstu2.resource.Conformance.RestOperation; -import ca.uhn.fhir.model.dstu2.valueset.OperationParameterUseEnum; -import ca.uhn.fhir.model.primitive.*; -import ca.uhn.fhir.rest.annotation.*; -import ca.uhn.fhir.rest.api.Constants; -import ca.uhn.fhir.rest.api.server.IBundleProvider; -import ca.uhn.fhir.rest.client.api.IGenericClient; -import ca.uhn.fhir.rest.client.interceptor.LoggingInterceptor; -import ca.uhn.fhir.test.utilities.JettyUtil; -import ca.uhn.fhir.util.TestUtil; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.TimeUnit; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.blankOrNullString; +import static org.hamcrest.Matchers.containsInRelativeOrder; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.greaterThan; +import static org.hamcrest.Matchers.not; +import static org.hamcrest.Matchers.startsWith; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; public class OperationServerDstu2Test { private static CloseableHttpClient ourClient; @@ -61,7 +74,7 @@ public class OperationServerDstu2Test { private static Server ourServer; private IGenericClient myFhirClient; - @Before + @BeforeEach public void before() { ourLastParam1 = null; ourLastParam2 = null; @@ -528,13 +541,13 @@ public class OperationServerDstu2Test { assertEquals("read", ourLastMethod); } - @AfterClass + @AfterAll public static void afterClassClearContext() throws Exception { JettyUtil.closeServer(ourServer); TestUtil.clearAllStaticFieldsForUnitTest(); } - @BeforeClass + @BeforeAll public static void beforeClass() throws Exception { ourCtx = FhirContext.forDstu2(); ourServer = new Server(0); @@ -715,7 +728,7 @@ public class OperationServerDstu2Test { public IBundleProvider opInstanceReturnsBundleProvider() { ourLastMethod = "$OP_INSTANCE_BUNDLE_PROVIDER"; - List resources = new ArrayList(); + List resources = new ArrayList<>(); for (int i =0; i < 100;i++) { Patient p = new Patient(); p.setId("Patient/" + i); 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 7bf78ecde37..837db498fd1 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 @@ -1,22 +1,28 @@ package ca.uhn.fhir.rest.server; -import static org.hamcrest.Matchers.stringContainsInOrder; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.util.Collections; -import java.util.List; -import java.util.concurrent.TimeUnit; - -import javax.servlet.ServletConfig; -import javax.servlet.http.HttpServletRequest; - +import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.model.dstu2.resource.Conformance; +import ca.uhn.fhir.model.dstu2.resource.OperationDefinition; +import ca.uhn.fhir.model.dstu2.resource.Parameters; +import ca.uhn.fhir.model.dstu2.resource.Patient; +import ca.uhn.fhir.model.primitive.IdDt; +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.rest.api.Constants; import ca.uhn.fhir.rest.api.server.RequestDetails; +import ca.uhn.fhir.rest.param.StringAndListParam; +import ca.uhn.fhir.rest.param.StringOrListParam; +import ca.uhn.fhir.rest.param.StringParam; +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.param.TokenParamModifier; +import ca.uhn.fhir.rest.server.provider.dstu2.ServerConformanceProvider; import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; import ca.uhn.fhir.test.utilities.JettyUtil; +import ca.uhn.fhir.util.TestUtil; +import ca.uhn.fhir.util.UrlUtil; import org.apache.commons.io.IOUtils; import org.apache.http.HttpResponse; import org.apache.http.client.methods.HttpGet; @@ -30,19 +36,23 @@ 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.*; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -import ca.uhn.fhir.context.FhirContext; -import ca.uhn.fhir.model.dstu2.resource.*; -import ca.uhn.fhir.model.primitive.IdDt; -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.rest.api.Constants; -import ca.uhn.fhir.rest.param.*; -import ca.uhn.fhir.rest.server.provider.dstu2.ServerConformanceProvider; -import ca.uhn.fhir.util.*; +import javax.servlet.ServletConfig; +import javax.servlet.http.HttpServletRequest; +import java.util.Collections; +import java.util.List; +import java.util.concurrent.TimeUnit; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.stringContainsInOrder; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; public class OperationServerWithSearchParamTypesDstu2Test { private static CloseableHttpClient ourClient; @@ -55,7 +65,7 @@ public class OperationServerWithSearchParamTypesDstu2Test { private static int ourPort; private static Server ourServer; - @Before + @BeforeEach public void before() { ourLastMethod = ""; ourLastParamValStr = null; @@ -316,13 +326,13 @@ public class OperationServerWithSearchParamTypesDstu2Test { assertEquals("type $orlist", ourLastMethod); } - @AfterClass + @AfterAll public static void afterClassClearContext() throws Exception { JettyUtil.closeServer(ourServer); TestUtil.clearAllStaticFieldsForUnitTest(); } - @BeforeClass + @BeforeAll public static void beforeClass() throws Exception { ourCtx = FhirContext.forDstu2(); ourServer = new Server(0); 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 8370399ced1..d2c4b32f5da 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 @@ -25,18 +25,18 @@ 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.Before; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.util.ArrayList; import java.util.List; import java.util.concurrent.TimeUnit; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; public class ReadDstu2Test { @@ -49,7 +49,7 @@ public class ReadDstu2Test { private static Server ourServer; private static RestfulServer ourServlet; - @Before + @BeforeEach public void before() { ourCtx.setAddProfileTagWhenEncoding(AddProfileTagEnum.NEVER); ourInitializeProfileList = false; @@ -232,13 +232,13 @@ public class ReadDstu2Test { } - @AfterClass + @AfterAll public static void afterClassClearContext() throws Exception { JettyUtil.closeServer(ourServer); TestUtil.clearAllStaticFieldsForUnitTest(); } - @BeforeClass + @BeforeAll public static void beforeClass() throws Exception { ourServer = new Server(0); diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/SearchBundleProviderWithNoSizeDstu2Test.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/SearchBundleProviderWithNoSizeDstu2Test.java index ce8fba0c856..4d0b2246b08 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/SearchBundleProviderWithNoSizeDstu2Test.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/SearchBundleProviderWithNoSizeDstu2Test.java @@ -1,33 +1,5 @@ package ca.uhn.fhir.rest.server; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.TimeUnit; - -import org.apache.commons.io.IOUtils; -import org.apache.http.client.methods.CloseableHttpResponse; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClientBuilder; -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.hl7.fhir.instance.model.api.IBaseResource; -import org.junit.*; -import org.mockito.invocation.InvocationOnMock; -import org.mockito.stubbing.Answer; - -import com.google.common.collect.Lists; - import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.dstu2.resource.Bundle; import ca.uhn.fhir.model.dstu2.resource.Bundle.Link; @@ -37,6 +9,35 @@ import ca.uhn.fhir.rest.api.server.IBundleProvider; import ca.uhn.fhir.rest.param.TokenAndListParam; import ca.uhn.fhir.test.utilities.JettyUtil; import ca.uhn.fhir.util.TestUtil; +import com.google.common.collect.Lists; +import org.apache.commons.io.IOUtils; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClientBuilder; +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.hl7.fhir.instance.model.api.IBaseResource; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.mockito.invocation.InvocationOnMock; +import org.mockito.stubbing.Answer; + +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.TimeUnit; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; public class SearchBundleProviderWithNoSizeDstu2Test { @@ -50,7 +51,7 @@ public class SearchBundleProviderWithNoSizeDstu2Test { private static Server ourServer; - @Before + @BeforeEach public void before() { ourLastMethod = null; ourIdentifiers = null; @@ -139,13 +140,13 @@ public class SearchBundleProviderWithNoSizeDstu2Test { } - @AfterClass + @AfterAll public static void afterClassClearContext() throws Exception { JettyUtil.closeServer(ourServer); TestUtil.clearAllStaticFieldsForUnitTest(); } - @BeforeClass + @BeforeAll public static void beforeClass() throws Exception { ourServer = new Server(0); diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/SearchCountParamDstu2Test.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/SearchCountParamDstu2Test.java index fd15efbdab3..2f2d22a75f5 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/SearchCountParamDstu2Test.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/SearchCountParamDstu2Test.java @@ -1,14 +1,15 @@ package ca.uhn.fhir.rest.server; -import static org.hamcrest.Matchers.stringContainsInOrder; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; - -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.TimeUnit; - +import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.model.dstu2.composite.HumanNameDt; +import ca.uhn.fhir.model.dstu2.resource.Patient; +import ca.uhn.fhir.rest.annotation.Count; +import ca.uhn.fhir.rest.annotation.OptionalParam; +import ca.uhn.fhir.rest.annotation.Search; import ca.uhn.fhir.rest.api.EncodingEnum; +import ca.uhn.fhir.rest.param.TokenParam; +import ca.uhn.fhir.test.utilities.JettyUtil; +import ca.uhn.fhir.util.TestUtil; import org.apache.commons.io.IOUtils; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; @@ -19,20 +20,18 @@ 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; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -import ca.uhn.fhir.context.FhirContext; -import ca.uhn.fhir.model.dstu2.composite.HumanNameDt; -import ca.uhn.fhir.model.dstu2.resource.Patient; -import ca.uhn.fhir.rest.annotation.Count; -import ca.uhn.fhir.rest.annotation.OptionalParam; -import ca.uhn.fhir.rest.annotation.Search; -import ca.uhn.fhir.rest.param.TokenParam; -import ca.uhn.fhir.test.utilities.JettyUtil; -import ca.uhn.fhir.util.TestUtil; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.TimeUnit; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.stringContainsInOrder; +import static org.junit.jupiter.api.Assertions.assertEquals; public class SearchCountParamDstu2Test { @@ -44,7 +43,7 @@ public class SearchCountParamDstu2Test { private static String ourLastMethod; private static Integer ourLastParam; - @Before + @BeforeEach public void before() { ourLastMethod = null; ourLastParam = null; @@ -109,13 +108,13 @@ public class SearchCountParamDstu2Test { } - @AfterClass + @AfterAll public static void afterClassClearContext() throws Exception { JettyUtil.closeServer(ourServer); TestUtil.clearAllStaticFieldsForUnitTest(); } - @BeforeClass + @BeforeAll public static void beforeClass() throws Exception { ourServer = new Server(0); 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 4756f7bfa1f..df031ce4242 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 @@ -7,12 +7,21 @@ import ca.uhn.fhir.model.dstu2.resource.Bundle; import ca.uhn.fhir.model.dstu2.resource.Bundle.Link; import ca.uhn.fhir.model.dstu2.resource.Patient; import ca.uhn.fhir.model.primitive.InstantDt; -import ca.uhn.fhir.rest.annotation.*; +import ca.uhn.fhir.rest.annotation.Create; +import ca.uhn.fhir.rest.annotation.OptionalParam; +import ca.uhn.fhir.rest.annotation.RequiredParam; +import ca.uhn.fhir.rest.annotation.ResourceParam; +import ca.uhn.fhir.rest.annotation.Search; import ca.uhn.fhir.rest.api.Constants; import ca.uhn.fhir.rest.api.EncodingEnum; import ca.uhn.fhir.rest.api.MethodOutcome; import ca.uhn.fhir.rest.api.server.IBundleProvider; -import ca.uhn.fhir.rest.param.*; +import ca.uhn.fhir.rest.param.DateAndListParam; +import ca.uhn.fhir.rest.param.ParamPrefixEnum; +import ca.uhn.fhir.rest.param.QuantityParam; +import ca.uhn.fhir.rest.param.ReferenceParam; +import ca.uhn.fhir.rest.param.StringParam; +import ca.uhn.fhir.test.utilities.JettyUtil; import ca.uhn.fhir.util.TestUtil; import com.google.common.base.Charsets; import org.apache.commons.io.IOUtils; @@ -33,23 +42,26 @@ 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; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import javax.annotation.Nonnull; import java.nio.charset.Charset; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.concurrent.TimeUnit; -import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; - -import ca.uhn.fhir.test.utilities.JettyUtil; - -import javax.annotation.Nonnull; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.matchesPattern; +import static org.hamcrest.Matchers.not; +import static org.hamcrest.Matchers.startsWith; +import static org.hamcrest.Matchers.stringContainsInOrder; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; public class SearchDstu2Test { @@ -65,7 +77,7 @@ public class SearchDstu2Test { private static Server ourServer; private static RestfulServer ourServlet; - @Before + @BeforeEach public void before() { ourLastMethod = null; ourLastDateAndList = null; @@ -490,13 +502,13 @@ public class SearchDstu2Test { assertEquals("searchWhitelist01", ourLastMethod); } - @AfterClass + @AfterAll public static void afterClassClearContext() throws Exception { JettyUtil.closeServer(ourServer); TestUtil.clearAllStaticFieldsForUnitTest(); } - @BeforeClass + @BeforeAll public static void beforeClass() throws Exception { ourServer = new Server(0); diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/SearchReturningProfiledResourceDstu2Test.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/SearchReturningProfiledResourceDstu2Test.java index f7e8fa24a2a..9c5609bc26b 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/SearchReturningProfiledResourceDstu2Test.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/SearchReturningProfiledResourceDstu2Test.java @@ -2,8 +2,8 @@ package ca.uhn.fhir.rest.server; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.not; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.hamcrest.MatcherAssert.assertThat; import java.util.*; import java.util.concurrent.TimeUnit; @@ -19,7 +19,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.*; +import org.junit.jupiter.api.*; import static org.hamcrest.MatcherAssert.assertThat; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.api.ResourceMetadataKeyEnum; @@ -37,6 +37,8 @@ import ca.uhn.fhir.rest.server.interceptor.ResponseHighlighterInterceptor; import ca.uhn.fhir.test.utilities.JettyUtil; import ca.uhn.fhir.util.TestUtil; import ca.uhn.fhir.validation.PatientProfileDstu2; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; public class SearchReturningProfiledResourceDstu2Test { @@ -102,13 +104,13 @@ public class SearchReturningProfiledResourceDstu2Test { } - @AfterClass + @AfterAll public static void afterClassClearContext() throws Exception { JettyUtil.closeServer(ourServer); TestUtil.clearAllStaticFieldsForUnitTest(); } - @BeforeClass + @BeforeAll public static void beforeClass() throws Exception { ourServer = new Server(0); 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 bcb4cc8f67a..8f0235c84b9 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 @@ -1,10 +1,12 @@ package ca.uhn.fhir.rest.server; -import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; - -import java.util.concurrent.TimeUnit; - +import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.model.api.IResource; +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.test.utilities.JettyUtil; +import ca.uhn.fhir.util.TestUtil; import org.apache.commons.io.IOUtils; import org.apache.http.HttpResponse; import org.apache.http.client.methods.HttpGet; @@ -14,17 +16,15 @@ 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.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; -import ca.uhn.fhir.context.FhirContext; -import ca.uhn.fhir.model.api.IResource; -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.test.utilities.JettyUtil; -import ca.uhn.fhir.util.TestUtil; +import java.util.concurrent.TimeUnit; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.stringContainsInOrder; +import static org.junit.jupiter.api.Assertions.assertEquals; public class SearchWithDstu2BundleTest { @@ -63,13 +63,13 @@ public class SearchWithDstu2BundleTest { - @AfterClass + @AfterAll public static void afterClassClearContext() throws Exception { JettyUtil.closeServer(ourServer); TestUtil.clearAllStaticFieldsForUnitTest(); } - @BeforeClass + @BeforeAll public static void beforeClass() throws Exception { ourServer = new Server(0); 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 cd1c7d11363..5c0f0e67a30 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 @@ -1,14 +1,15 @@ package ca.uhn.fhir.rest.server; -import static org.hamcrest.Matchers.containsString; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; - -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.TimeUnit; - +import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.model.api.IResource; +import ca.uhn.fhir.model.dstu2.composite.HumanNameDt; +import ca.uhn.fhir.model.dstu2.resource.Patient; +import ca.uhn.fhir.rest.annotation.RequiredParam; +import ca.uhn.fhir.rest.annotation.Search; import ca.uhn.fhir.rest.api.EncodingEnum; +import ca.uhn.fhir.rest.param.TokenParam; +import ca.uhn.fhir.test.utilities.JettyUtil; +import ca.uhn.fhir.util.TestUtil; import org.apache.commons.io.IOUtils; import org.apache.http.HttpResponse; import org.apache.http.client.methods.HttpGet; @@ -18,20 +19,18 @@ 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.Before; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -import ca.uhn.fhir.context.FhirContext; -import ca.uhn.fhir.model.api.IResource; -import ca.uhn.fhir.model.dstu2.composite.HumanNameDt; -import ca.uhn.fhir.model.dstu2.resource.Patient; -import ca.uhn.fhir.rest.annotation.RequiredParam; -import ca.uhn.fhir.rest.annotation.Search; -import ca.uhn.fhir.rest.param.TokenParam; -import ca.uhn.fhir.test.utilities.JettyUtil; -import ca.uhn.fhir.util.TestUtil; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.TimeUnit; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsString; +import static org.junit.jupiter.api.Assertions.assertEquals; public class SearchWithGenericListDstu2Test { @@ -42,7 +41,7 @@ public class SearchWithGenericListDstu2Test { private static int ourPort; private static Server ourServer; - @Before + @BeforeEach public void before() { ourLastMethod = null; } @@ -65,13 +64,13 @@ public class SearchWithGenericListDstu2Test { - @AfterClass + @AfterAll public static void afterClassClearContext() throws Exception { JettyUtil.closeServer(ourServer); TestUtil.clearAllStaticFieldsForUnitTest(); } - @BeforeClass + @BeforeAll public static void beforeClass() throws Exception { ourServer = new Server(0); 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 d1f9264e289..a0be908d5ce 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 @@ -1,48 +1,69 @@ package ca.uhn.fhir.rest.server; -import static org.hamcrest.Matchers.containsInAnyOrder; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.not; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.util.*; - -import javax.servlet.ServletConfig; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; - -import ca.uhn.fhir.rest.api.server.RequestDetails; -import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; -import org.hl7.fhir.instance.model.api.IBaseResource; -import org.junit.AfterClass; -import org.junit.Test; - -import com.google.common.collect.Lists; - import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.api.ExtensionDt; import ca.uhn.fhir.model.api.Include; import ca.uhn.fhir.model.api.annotation.Description; import ca.uhn.fhir.model.dstu2.composite.IdentifierDt; -import ca.uhn.fhir.model.dstu2.resource.*; -import ca.uhn.fhir.model.dstu2.resource.Conformance.*; -import ca.uhn.fhir.model.dstu2.valueset.*; -import ca.uhn.fhir.model.primitive.*; +import ca.uhn.fhir.model.dstu2.resource.Conformance; +import ca.uhn.fhir.model.dstu2.resource.Conformance.Rest; +import ca.uhn.fhir.model.dstu2.resource.Conformance.RestOperation; +import ca.uhn.fhir.model.dstu2.resource.Conformance.RestResource; +import ca.uhn.fhir.model.dstu2.resource.Conformance.RestResourceSearchParam; +import ca.uhn.fhir.model.dstu2.resource.Conformance.RestSecurity; +import ca.uhn.fhir.model.dstu2.resource.DiagnosticReport; +import ca.uhn.fhir.model.dstu2.resource.Encounter; +import ca.uhn.fhir.model.dstu2.resource.OperationDefinition; +import ca.uhn.fhir.model.dstu2.resource.Patient; +import ca.uhn.fhir.model.dstu2.valueset.ConditionalDeleteStatusEnum; +import ca.uhn.fhir.model.dstu2.valueset.RestfulSecurityServiceEnum; +import ca.uhn.fhir.model.dstu2.valueset.SystemRestfulInteractionEnum; +import ca.uhn.fhir.model.dstu2.valueset.TypeRestfulInteractionEnum; +import ca.uhn.fhir.model.dstu2.valueset.UnknownContentCodeEnum; +import ca.uhn.fhir.model.primitive.CodeDt; +import ca.uhn.fhir.model.primitive.DateDt; +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.annotation.*; import ca.uhn.fhir.rest.api.MethodOutcome; import ca.uhn.fhir.rest.api.server.IBundleProvider; -import ca.uhn.fhir.rest.param.*; -import ca.uhn.fhir.rest.server.method.*; +import ca.uhn.fhir.rest.api.server.RequestDetails; +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.method.BaseMethodBinding; +import ca.uhn.fhir.rest.server.method.IParameter; +import ca.uhn.fhir.rest.server.method.SearchMethodBinding; import ca.uhn.fhir.rest.server.method.SearchParameter; import ca.uhn.fhir.rest.server.provider.dstu2.ServerConformanceProvider; +import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails; import ca.uhn.fhir.util.TestUtil; import ca.uhn.fhir.validation.FhirValidator; import ca.uhn.fhir.validation.ValidationResult; +import com.google.common.collect.Lists; +import org.hl7.fhir.instance.model.api.IBaseResource; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; + +import javax.servlet.ServletConfig; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsInAnyOrder; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.not; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; public class ServerConformanceProviderDstu2Test { @@ -65,7 +86,7 @@ public class ServerConformanceProviderDstu2Test { String outcome = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(result.toOperationOutcome()); ourLog.info("Outcome: {}", outcome); - assertTrue(outcome, result.isSuccessful()); + assertTrue(result.isSuccessful(), outcome); } private HttpServletRequest createHttpServletRequest() { @@ -673,7 +694,7 @@ public class ServerConformanceProviderDstu2Test { ourLog.info(ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(conformance)); ValidationResult result = ourCtx.newValidator().validateWithResult(conformance); - assertTrue(result.getMessages().toString(), result.isSuccessful()); + assertTrue(result.isSuccessful(), result.getMessages().toString()); } private List toOperationIdParts(List theOperation) { @@ -700,7 +721,7 @@ public class ServerConformanceProviderDstu2Test { return retVal; } - @AfterClass + @AfterAll public static void afterClassClearContext() { TestUtil.clearAllStaticFieldsForUnitTest(); } 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 7f1e1336a58..a69907b07a7 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 @@ -1,15 +1,14 @@ package ca.uhn.fhir.rest.server; -import static org.hamcrest.Matchers.containsString; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; - -import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.Collection; -import java.util.concurrent.TimeUnit; - +import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.model.api.IResource; +import ca.uhn.fhir.model.dstu2.resource.Patient; +import ca.uhn.fhir.model.primitive.IdDt; +import ca.uhn.fhir.rest.annotation.IdParam; +import ca.uhn.fhir.rest.annotation.Read; import ca.uhn.fhir.rest.api.EncodingEnum; +import ca.uhn.fhir.test.utilities.JettyUtil; +import ca.uhn.fhir.util.TestUtil; import org.apache.commons.io.IOUtils; import org.apache.http.HttpResponse; import org.apache.http.client.methods.HttpGet; @@ -21,18 +20,18 @@ 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.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; -import ca.uhn.fhir.context.FhirContext; -import ca.uhn.fhir.model.api.IResource; -import ca.uhn.fhir.model.dstu2.resource.Patient; -import ca.uhn.fhir.model.primitive.IdDt; -import ca.uhn.fhir.rest.annotation.IdParam; -import ca.uhn.fhir.rest.annotation.Read; -import ca.uhn.fhir.test.utilities.JettyUtil; -import ca.uhn.fhir.util.TestUtil; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.Collection; +import java.util.concurrent.TimeUnit; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsString; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * Created by dsotnikov on 2/25/2014. @@ -163,13 +162,13 @@ public class ServerFeaturesDstu2Test { } - @AfterClass + @AfterAll public static void afterClassClearContext() throws Exception { JettyUtil.closeServer(ourServer); TestUtil.clearAllStaticFieldsForUnitTest(); } - @BeforeClass + @BeforeAll public static void beforeClass() throws Exception { ourServer = new Server(0); 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 700221dc940..60705246a3b 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 @@ -6,6 +6,7 @@ import ca.uhn.fhir.rest.annotation.RequiredParam; import ca.uhn.fhir.rest.annotation.Search; import ca.uhn.fhir.rest.param.ReferenceParam; import ca.uhn.fhir.rest.param.StringParam; +import ca.uhn.fhir.test.utilities.JettyUtil; import ca.uhn.fhir.util.TestUtil; import ca.uhn.fhir.util.UrlUtil; import org.apache.commons.io.IOUtils; @@ -18,18 +19,16 @@ 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; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.util.ArrayList; import java.util.List; import java.util.concurrent.TimeUnit; -import static org.junit.Assert.*; - -import ca.uhn.fhir.test.utilities.JettyUtil; +import static org.junit.jupiter.api.Assertions.assertEquals; public class ServerSearchDstu2Test { @@ -42,7 +41,7 @@ public class ServerSearchDstu2Test { private static int ourPort; private static Server ourServer; - @Before + @BeforeEach public void before() { ourLastMethod = null; ourLastRef = null; @@ -125,13 +124,13 @@ public class ServerSearchDstu2Test { assertEquals(null, ourLastMethod); } - @AfterClass + @AfterAll public static void afterClassClearContext() throws Exception { JettyUtil.closeServer(ourServer); TestUtil.clearAllStaticFieldsForUnitTest(); } - @BeforeClass + @BeforeAll public static void beforeClass() throws Exception { ourServer = new Server(0); diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/SummaryParamDstu2Test.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/SummaryParamDstu2Test.java index 02bcfe8ece0..67434fe706b 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/SummaryParamDstu2Test.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/SummaryParamDstu2Test.java @@ -25,18 +25,21 @@ 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; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.util.Arrays; import java.util.List; import java.util.concurrent.TimeUnit; -import static org.hamcrest.Matchers.*; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.containsStringIgnoringCase; +import static org.hamcrest.Matchers.not; +import static org.junit.jupiter.api.Assertions.assertEquals; public class SummaryParamDstu2Test { @@ -49,7 +52,7 @@ public class SummaryParamDstu2Test { private static Server ourServer; - @Before + @BeforeEach public void before() { ourLastSummary = null; ourLastSummaryList = null; @@ -319,13 +322,13 @@ public class SummaryParamDstu2Test { } - @AfterClass + @AfterAll public static void afterClassClearContext() throws Exception { JettyUtil.closeServer(ourServer); TestUtil.clearAllStaticFieldsForUnitTest(); } - @BeforeClass + @BeforeAll public static void beforeClass() throws Exception { ourServer = new Server(0); 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 f6bffdc4d9a..073ad4bd1b2 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 @@ -1,27 +1,12 @@ package ca.uhn.fhir.rest.server; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import java.util.concurrent.TimeUnit; - -import org.apache.commons.io.IOUtils; -import org.apache.http.HttpResponse; -import org.apache.http.client.methods.HttpPost; -import org.apache.http.entity.ContentType; -import org.apache.http.entity.StringEntity; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClientBuilder; -import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; -import org.eclipse.jetty.server.Server; -import org.eclipse.jetty.servlet.ServletHolder; -import org.junit.*; -import org.junit.Test; - import ca.uhn.fhir.context.FhirContext; -import ca.uhn.fhir.model.dstu2.resource.*; +import ca.uhn.fhir.model.dstu2.resource.Bundle; import ca.uhn.fhir.model.dstu2.resource.Bundle.Entry; +import ca.uhn.fhir.model.dstu2.resource.Conformance; import ca.uhn.fhir.model.dstu2.resource.Conformance.RestInteraction; +import ca.uhn.fhir.model.dstu2.resource.OperationOutcome; +import ca.uhn.fhir.model.dstu2.resource.Patient; import ca.uhn.fhir.model.dstu2.valueset.HTTPVerbEnum; import ca.uhn.fhir.model.dstu2.valueset.SystemRestfulInteractionEnum; import ca.uhn.fhir.model.primitive.IdDt; @@ -32,6 +17,25 @@ import ca.uhn.fhir.rest.api.Constants; import ca.uhn.fhir.rest.client.api.IGenericClient; import ca.uhn.fhir.test.utilities.JettyUtil; import ca.uhn.fhir.util.TestUtil; +import org.apache.commons.io.IOUtils; +import org.apache.http.HttpResponse; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.entity.ContentType; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClientBuilder; +import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; +import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.servlet.ServletHolder; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.util.concurrent.TimeUnit; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; public class TransactionWithBundleResourceParamTest { @@ -45,7 +49,7 @@ public class TransactionWithBundleResourceParamTest { private static boolean ourReturnOperationOutcome; private static Server ourServer; - @Before + @BeforeEach public void before() { ourReturnOperationOutcome = false; } @@ -214,13 +218,13 @@ public class TransactionWithBundleResourceParamTest { } - @AfterClass + @AfterAll public static void afterClassClearContext() throws Exception { JettyUtil.closeServer(ourServer); TestUtil.clearAllStaticFieldsForUnitTest(); } - @BeforeClass + @BeforeAll public static void beforeClass() throws Exception { ourServer = new Server(0); diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/TransactionWithVersionlessBundleResourceParamTest.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/TransactionWithVersionlessBundleResourceParamTest.java index be23b590ac9..362c6a69a9c 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/TransactionWithVersionlessBundleResourceParamTest.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/TransactionWithVersionlessBundleResourceParamTest.java @@ -24,14 +24,14 @@ import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.servlet.ServletHolder; import org.hl7.fhir.instance.model.api.IBaseBundle; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.util.concurrent.TimeUnit; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public class TransactionWithVersionlessBundleResourceParamTest { @@ -45,7 +45,7 @@ public class TransactionWithVersionlessBundleResourceParamTest { private static boolean ourReturnOperationOutcome; private static Server ourServer; - @Before + @BeforeEach public void before() { ourReturnOperationOutcome = false; } @@ -82,13 +82,13 @@ public class TransactionWithVersionlessBundleResourceParamTest { } - @AfterClass + @AfterAll public static void afterClassClearContext() throws Exception { JettyUtil.closeServer(ourServer); TestUtil.clearAllStaticFieldsForUnitTest(); } - @BeforeClass + @BeforeAll public static void beforeClass() throws Exception { ourServer = new Server(0); diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/UpdateDstu2Test.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/UpdateDstu2Test.java index 79c088e318e..a6d69e5a8f9 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/UpdateDstu2Test.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/UpdateDstu2Test.java @@ -1,34 +1,5 @@ package ca.uhn.fhir.rest.server; -import static org.hamcrest.core.Is.is; -import static org.hamcrest.core.IsNot.not; -import static org.hamcrest.text.IsEmptyString.emptyString; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; - -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.TimeUnit; - -import org.apache.commons.io.IOUtils; -import org.apache.http.HttpResponse; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.client.methods.HttpPut; -import org.apache.http.entity.ContentType; -import org.apache.http.entity.StringEntity; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClientBuilder; -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.Before; -import org.junit.BeforeClass; -import org.junit.Test; - import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.model.api.ResourceMetadataKeyEnum; @@ -46,6 +17,30 @@ import ca.uhn.fhir.rest.api.Constants; import ca.uhn.fhir.rest.api.MethodOutcome; import ca.uhn.fhir.test.utilities.JettyUtil; import ca.uhn.fhir.util.TestUtil; +import org.apache.commons.io.IOUtils; +import org.apache.http.HttpResponse; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpPut; +import org.apache.http.entity.ContentType; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClientBuilder; +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.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.TimeUnit; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; public class UpdateDstu2Test { private static CloseableHttpClient ourClient; @@ -60,7 +55,7 @@ public class UpdateDstu2Test { private static InstantDt ourSetLastUpdated; - @Before + @BeforeEach public void before() { ourLastId = null; ourLastConditionalUrl = null; @@ -147,14 +142,14 @@ public class UpdateDstu2Test { } - @AfterClass + @AfterAll public static void afterClassClearContext() throws Exception { JettyUtil.closeServer(ourServer); TestUtil.clearAllStaticFieldsForUnitTest(); } - @BeforeClass + @BeforeAll public static void beforeClass() throws Exception { ourServer = new Server(0); 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 9952a1f8b07..c8e1ffd47d5 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 @@ -1,11 +1,22 @@ package ca.uhn.fhir.rest.server; -import static org.hamcrest.Matchers.stringContainsInOrder; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; - -import java.util.concurrent.TimeUnit; - +import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.model.api.IResource; +import ca.uhn.fhir.model.base.resource.BaseOperationOutcome; +import ca.uhn.fhir.model.dstu2.resource.OperationOutcome; +import ca.uhn.fhir.model.dstu2.resource.Organization; +import ca.uhn.fhir.model.dstu2.resource.Parameters; +import ca.uhn.fhir.model.dstu2.resource.Patient; +import ca.uhn.fhir.model.primitive.IdDt; +import ca.uhn.fhir.model.primitive.StringDt; +import ca.uhn.fhir.rest.annotation.ResourceParam; +import ca.uhn.fhir.rest.annotation.Validate; +import ca.uhn.fhir.rest.api.Constants; +import ca.uhn.fhir.rest.api.EncodingEnum; +import ca.uhn.fhir.rest.api.MethodOutcome; +import ca.uhn.fhir.rest.api.ValidationModeEnum; +import ca.uhn.fhir.test.utilities.JettyUtil; +import ca.uhn.fhir.util.TestUtil; import org.apache.commons.io.IOUtils; import org.apache.http.HttpResponse; import org.apache.http.client.methods.HttpPost; @@ -17,20 +28,16 @@ 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.*; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -import ca.uhn.fhir.context.FhirContext; -import ca.uhn.fhir.model.api.IResource; -import ca.uhn.fhir.model.base.resource.BaseOperationOutcome; -import ca.uhn.fhir.model.dstu2.resource.*; -import ca.uhn.fhir.model.primitive.IdDt; -import ca.uhn.fhir.model.primitive.StringDt; -import ca.uhn.fhir.rest.annotation.ResourceParam; -import ca.uhn.fhir.rest.annotation.Validate; -import ca.uhn.fhir.rest.api.*; -import ca.uhn.fhir.test.utilities.JettyUtil; -import ca.uhn.fhir.util.TestUtil; +import java.util.concurrent.TimeUnit; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.stringContainsInOrder; +import static org.junit.jupiter.api.Assertions.assertEquals; public class ValidateDstu2Test { private static CloseableHttpClient ourClient; @@ -43,7 +50,7 @@ public class ValidateDstu2Test { private static int ourPort; private static Server ourServer; - @Before() + @BeforeEach public void before() { ourLastResourceBody = null; ourLastEncoding = null; @@ -147,13 +154,13 @@ public class ValidateDstu2Test { assertThat(resp, stringContainsInOrder(" myMap; private Set myMapCheckMethods; - @Before + @BeforeEach public void before() { servlet.getInterceptorService().unregisterAllInterceptors(); servlet.getInterceptorService().registerInterceptor(new MyInterceptor()); } - @Before + @BeforeEach public void beforePurgeMap() { myMap = null; myMapCheckMethods = new LinkedHashSet<>(); @@ -257,13 +268,13 @@ public class InterceptorUserDataMapDstu2Test { } - @AfterClass + @AfterAll public static void afterClassClearContext() throws Exception { JettyUtil.closeServer(ourServer); TestUtil.clearAllStaticFieldsForUnitTest(); } - @BeforeClass + @BeforeAll public static void beforeClass() throws Exception { ourServer = new Server(0); 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 28e5d557339..5beaa0109b8 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 @@ -10,12 +10,20 @@ import ca.uhn.fhir.model.dstu2.valueset.IdentifierUseEnum; import ca.uhn.fhir.model.primitive.DateDt; import ca.uhn.fhir.model.primitive.IdDt; import ca.uhn.fhir.model.primitive.UriDt; -import ca.uhn.fhir.rest.annotation.*; +import ca.uhn.fhir.rest.annotation.Create; +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.rest.annotation.RequiredParam; +import ca.uhn.fhir.rest.annotation.ResourceParam; +import ca.uhn.fhir.rest.annotation.Search; import ca.uhn.fhir.rest.api.Constants; import ca.uhn.fhir.rest.api.MethodOutcome; 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.test.utilities.JettyUtil; import ca.uhn.fhir.util.TestUtil; import org.apache.commons.io.IOUtils; import org.apache.http.HttpResponse; @@ -30,10 +38,10 @@ import org.eclipse.jetty.server.Server; import org.eclipse.jetty.servlet.ServletHandler; import org.eclipse.jetty.servlet.ServletHolder; import org.hamcrest.core.StringContains; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; import org.slf4j.Logger; @@ -43,12 +51,14 @@ import java.util.List; import java.util.Map; import java.util.concurrent.TimeUnit; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.matchesPattern; import static org.hamcrest.Matchers.startsWith; -import static org.junit.Assert.*; -import static org.mockito.Mockito.*; - -import ca.uhn.fhir.test.utilities.JettyUtil; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.timeout; +import static org.mockito.Mockito.verify; public class LoggingInterceptorDstu2Test { @@ -60,7 +70,7 @@ public class LoggingInterceptorDstu2Test { private static int ourDelayMs; private static Exception ourThrowException; - @Before + @BeforeEach public void before() { servlet.getInterceptorService().unregisterAllInterceptors(); ourThrowException = null; @@ -377,13 +387,13 @@ public class LoggingInterceptorDstu2Test { assertThat(captor.getValue(), StringContains.containsString("search-type - Patient - ?_id=1")); } - @AfterClass + @AfterAll public static void afterClassClearContext() throws Exception { JettyUtil.closeServer(ourServer); TestUtil.clearAllStaticFieldsForUnitTest(); } - @BeforeClass + @BeforeAll public static void beforeClass() throws Exception { ourServer = new Server(0); 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 d64e7791099..65fc1b5f248 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 @@ -5,7 +5,12 @@ import ca.uhn.fhir.context.api.BundleInclusionRule; 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.rest.annotation.*; +import ca.uhn.fhir.rest.annotation.Create; +import ca.uhn.fhir.rest.annotation.History; +import ca.uhn.fhir.rest.annotation.IdParam; +import ca.uhn.fhir.rest.annotation.Read; +import ca.uhn.fhir.rest.annotation.ResourceParam; +import ca.uhn.fhir.rest.annotation.Update; import ca.uhn.fhir.rest.api.EncodingEnum; import ca.uhn.fhir.rest.api.MethodOutcome; import ca.uhn.fhir.rest.api.RestOperationTypeEnum; @@ -16,6 +21,7 @@ import ca.uhn.fhir.rest.client.api.ServerValidationModeEnum; 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.test.utilities.JettyUtil; import ca.uhn.fhir.util.TestUtil; import org.apache.commons.io.IOUtils; import org.apache.http.client.methods.CloseableHttpResponse; @@ -27,10 +33,10 @@ 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; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; import javax.servlet.http.HttpServletRequest; @@ -39,12 +45,13 @@ import java.util.Collections; import java.util.List; import java.util.concurrent.TimeUnit; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Matchers.any; import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.*; - -import ca.uhn.fhir.test.utilities.JettyUtil; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.reset; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; public class ServerActionInterceptorTest { @@ -55,7 +62,7 @@ public class ServerActionInterceptorTest { private static IServerInterceptor ourInterceptor; private static IGenericClient ourFhirClient; - @AfterClass + @AfterAll public static void afterClassClearContext() throws Exception { JettyUtil.closeServer(ourServer); TestUtil.clearAllStaticFieldsForUnitTest(); @@ -179,7 +186,7 @@ public class ServerActionInterceptorTest { assertEquals("Patient/123", detailsCapt.getValue().getId().getValue()); } - @BeforeClass + @BeforeAll public static void beforeClass() throws Exception { ourServer = new Server(0); @@ -211,7 +218,7 @@ public class ServerActionInterceptorTest { } - @Before + @BeforeEach public void before() { reset(ourInterceptor); 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 95edd3d8f0f..c887b9e6cbe 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 @@ -1,20 +1,30 @@ package ca.uhn.fhir.rest.server.provider.dstu2; -import static org.junit.Assert.assertEquals; - -import java.util.*; - -import org.hl7.fhir.instance.model.api.IBaseResource; -import org.junit.*; -import org.junit.Test; - import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.api.BundleInclusionRule; import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.model.api.Include; import ca.uhn.fhir.model.dstu2.composite.ResourceReferenceDt; -import ca.uhn.fhir.model.dstu2.resource.*; +import ca.uhn.fhir.model.dstu2.resource.Bundle; +import ca.uhn.fhir.model.dstu2.resource.DiagnosticReport; +import ca.uhn.fhir.model.dstu2.resource.Observation; +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.util.TestUtil; +import org.hl7.fhir.instance.model.api.IBaseResource; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import static org.junit.jupiter.api.Assertions.assertEquals; public class Dstu2BundleFactoryTest { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(Dstu2BundleFactoryTest.class); @@ -23,17 +33,17 @@ public class Dstu2BundleFactoryTest { private List myResourceList; private Dstu2BundleFactory myBundleFactory; - @BeforeClass + @BeforeAll public static void beforeClass() throws Exception { ourCtx = FhirContext.forDstu2(); } - @AfterClass + @AfterAll public static void afterClassClearContext() { TestUtil.clearAllStaticFieldsForUnitTest(); } - @Before + @BeforeEach public void setUp() throws Exception { // DiagnosticReport // Performer(practitioner) @@ -169,4 +179,4 @@ public class Dstu2BundleFactoryTest { } return resources; } -} \ No newline at end of file +} 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 b8886772475..97b7ce38495 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 @@ -20,16 +20,22 @@ import org.hl7.fhir.instance.model.api.IBase; import org.hl7.fhir.instance.model.api.IBaseExtension; import org.hl7.fhir.instance.model.api.IBaseReference; import org.hl7.fhir.instance.model.api.IPrimitiveType; -import org.junit.AfterClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; import java.util.List; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsInAnyOrder; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -796,7 +802,7 @@ public class FhirTerserDstu2Test { } - @AfterClass + @AfterAll public static void afterClassClearContext() { TestUtil.clearAllStaticFieldsForUnitTest(); } 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 e1fc74c458d..0931d6c8dcb 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 @@ -3,20 +3,17 @@ package ca.uhn.fhir.validation; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.dstu2.resource.Appointment; import ca.uhn.fhir.model.dstu2.resource.Bundle; -import ca.uhn.fhir.model.dstu2.resource.Patient; 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.jupiter.api.AfterAll; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; -import org.junit.Ignore; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; - -import org.junit.AfterClass; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; /** * @author Bill de Beaubien on 11/30/2015. @@ -40,14 +37,7 @@ public class BundleValidationTest { } } - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } - - - - @Ignore + @Disabled @Test public void testBundleIsInvalid() throws Exception { Appointment appointment = createAppointment(); @@ -61,7 +51,7 @@ public class BundleValidationTest { validator.setValidateAgainstStandardSchematron(true); ValidationResult result = validator.validateWithResult(bundle); - assertFalse("Validation should have failed", result.isSuccessful()); + assertFalse(result.isSuccessful(), "Validation should have failed"); assertEquals(1, result.getMessages().size()); for (SingleValidationMessage singleValidationMessage : result.getMessages()) { System.out.println(singleValidationMessage.getMessage()); @@ -72,4 +62,9 @@ public class BundleValidationTest { Appointment.Participant participant = new Appointment.Participant().setStatus(ParticipationStatusEnum.ACCEPTED).setType(ParticipantTypeEnum.PART); return new Appointment().setStatus(AppointmentStatusEnum.BOOKED).addParticipant(participant); } + + @AfterAll + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } } 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 ce1afde22af..d31db258986 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 @@ -7,7 +7,11 @@ import ca.uhn.fhir.model.api.TemporalPrecisionEnum; import ca.uhn.fhir.model.dstu2.composite.CodeableConceptDt; import ca.uhn.fhir.model.dstu2.composite.ResourceReferenceDt; import ca.uhn.fhir.model.dstu2.composite.TimingDt; -import ca.uhn.fhir.model.dstu2.resource.*; +import ca.uhn.fhir.model.dstu2.resource.Bundle; +import ca.uhn.fhir.model.dstu2.resource.Condition; +import ca.uhn.fhir.model.dstu2.resource.MedicationOrder; +import ca.uhn.fhir.model.dstu2.resource.OperationOutcome; +import ca.uhn.fhir.model.dstu2.resource.Patient; import ca.uhn.fhir.model.dstu2.valueset.ConditionVerificationStatusEnum; import ca.uhn.fhir.model.dstu2.valueset.ContactPointSystemEnum; import ca.uhn.fhir.model.dstu2.valueset.NarrativeStatusEnum; @@ -23,8 +27,8 @@ import ca.uhn.fhir.util.TestUtil; import ca.uhn.fhir.validation.schematron.SchematronBaseValidator; import org.apache.commons.io.IOUtils; import org.hamcrest.core.StringContains; -import org.junit.AfterClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; import java.io.IOException; import java.nio.charset.StandardCharsets; @@ -32,8 +36,15 @@ import java.util.ArrayList; import java.util.Date; import java.util.List; -import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.not; +import static org.hamcrest.Matchers.stringContainsInOrder; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; public class ResourceValidatorDstu2Test { @@ -153,7 +164,7 @@ public class ResourceValidatorDstu2Test { OperationOutcome operationOutcome = (OperationOutcome) result.toOperationOutcome(); - assertTrue(result.toString(), result.isSuccessful()); + assertTrue(result.isSuccessful(), result.toString()); assertNotNull(operationOutcome); assertEquals(1, operationOutcome.getIssue().size()); } @@ -367,7 +378,7 @@ public class ResourceValidatorDstu2Test { assertThat(messageString, not(containsString("valueResource"))); } - @AfterClass + @AfterAll public static void afterClassClearContext() { TestUtil.clearAllStaticFieldsForUnitTest(); } 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 87eb42fca87..a4ea342eaa4 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 @@ -1,18 +1,17 @@ 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; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertTrue; public class ValidatorInstantiatorDstu2Test { - @AfterClass + @AfterAll public static void afterClassClearContext() { TestUtil.clearAllStaticFieldsForUnitTest(); } diff --git a/hapi-fhir-structures-dstu3/pom.xml b/hapi-fhir-structures-dstu3/pom.xml index 85fd76d7f77..48a45e42d2a 100644 --- a/hapi-fhir-structures-dstu3/pom.xml +++ b/hapi-fhir-structures-dstu3/pom.xml @@ -115,6 +115,12 @@ org.fhir ucum true + + + junit + junit + + - junit - junit + org.eclipse.jetty + jetty-servlet + + + + com.google.guava + guava-testlib - org.hamcrest - hamcrest-core + junit + junit @@ -74,16 +80,22 @@ org.hamcrest hamcrest + + org.junit.jupiter + junit-jupiter + compile + + + org.junit.jupiter + junit-jupiter-api + compile + + + org.junit.jupiter + junit-jupiter-engine + compile + - - - org.eclipse.jetty - jetty-servlet - - - org.eclipse.jetty - jetty-servlet - diff --git a/hapi-fhir-test-utilities/src/main/java/ca/uhn/fhir/test/utilities/HttpClientRule.java b/hapi-fhir-test-utilities/src/main/java/ca/uhn/fhir/test/utilities/HttpClientExtension.java similarity index 68% rename from hapi-fhir-test-utilities/src/main/java/ca/uhn/fhir/test/utilities/HttpClientRule.java rename to hapi-fhir-test-utilities/src/main/java/ca/uhn/fhir/test/utilities/HttpClientExtension.java index 4c834c1eff4..a48b3f7aca2 100644 --- a/hapi-fhir-test-utilities/src/main/java/ca/uhn/fhir/test/utilities/HttpClientRule.java +++ b/hapi-fhir-test-utilities/src/main/java/ca/uhn/fhir/test/utilities/HttpClientExtension.java @@ -22,37 +22,26 @@ package ca.uhn.fhir.test.utilities; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClientBuilder; -import org.junit.rules.TestRule; -import org.junit.runner.Description; -import org.junit.runners.model.Statement; +import org.junit.jupiter.api.extension.AfterEachCallback; +import org.junit.jupiter.api.extension.BeforeEachCallback; +import org.junit.jupiter.api.extension.ExtensionContext; -public class HttpClientRule implements TestRule { +public class HttpClientExtension implements BeforeEachCallback, AfterEachCallback { private CloseableHttpClient myClient; - @Override - public Statement apply(Statement theBase, Description theDescription) { - return new Statement() { - @Override - public void evaluate() throws Throwable { - startClient(); - theBase.evaluate(); - stopClient(); - } - }; - } - - - private void stopClient() throws Exception { - myClient.close(); - } - - private void startClient() { - myClient = HttpClientBuilder - .create() - .build(); - } - public CloseableHttpClient getClient() { return myClient; } + + @Override + public void afterEach(ExtensionContext theExtensionContext) throws Exception { + myClient.close(); + } + + @Override + public void beforeEach(ExtensionContext theExtensionContext) throws Exception { + myClient = HttpClientBuilder + .create() + .build(); + } } diff --git a/hapi-fhir-test-utilities/src/main/java/ca/uhn/fhir/test/utilities/ITestDataBuilder.java b/hapi-fhir-test-utilities/src/main/java/ca/uhn/fhir/test/utilities/ITestDataBuilder.java index 7927e6feb38..ee8ecdb58c9 100644 --- a/hapi-fhir-test-utilities/src/main/java/ca/uhn/fhir/test/utilities/ITestDataBuilder.java +++ b/hapi-fhir-test-utilities/src/main/java/ca/uhn/fhir/test/utilities/ITestDataBuilder.java @@ -20,6 +20,10 @@ package ca.uhn.fhir.test.utilities; * #L% */ +import static org.apache.commons.lang3.StringUtils.isNotBlank; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.matchesPattern; + import ca.uhn.fhir.context.BaseRuntimeChildDefinition; import ca.uhn.fhir.context.BaseRuntimeElementCompositeDefinition; import ca.uhn.fhir.context.FhirContext; @@ -33,10 +37,6 @@ import org.hl7.fhir.instance.model.api.IPrimitiveType; import javax.annotation.Nullable; import java.util.function.Consumer; -import static org.apache.commons.lang3.StringUtils.isNotBlank; -import static org.hamcrest.Matchers.matchesPattern; -import static org.junit.Assert.assertThat; - /** * This is an experiment to see if we can make test data creation for storage unit tests a bit more readable. */ diff --git a/hapi-fhir-test-utilities/src/main/java/ca/uhn/fhir/test/utilities/LoggingRule.java b/hapi-fhir-test-utilities/src/main/java/ca/uhn/fhir/test/utilities/LoggingExtension.java similarity index 52% rename from hapi-fhir-test-utilities/src/main/java/ca/uhn/fhir/test/utilities/LoggingRule.java rename to hapi-fhir-test-utilities/src/main/java/ca/uhn/fhir/test/utilities/LoggingExtension.java index bd33d9a79a7..21e130130cf 100644 --- a/hapi-fhir-test-utilities/src/main/java/ca/uhn/fhir/test/utilities/LoggingRule.java +++ b/hapi-fhir-test-utilities/src/main/java/ca/uhn/fhir/test/utilities/LoggingExtension.java @@ -36,9 +36,9 @@ package ca.uhn.fhir.test.utilities; * #L% */ -import org.junit.rules.TestRule; -import org.junit.runner.Description; -import org.junit.runners.model.Statement; +import org.junit.jupiter.api.extension.AfterEachCallback; +import org.junit.jupiter.api.extension.BeforeEachCallback; +import org.junit.jupiter.api.extension.ExtensionContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -51,33 +51,17 @@ import java.text.MessageFormat; * @author Brian Matthews * @version 1.0.0 */ -public class LoggingRule implements TestRule { +public class LoggingExtension implements BeforeEachCallback, AfterEachCallback { - /** - * Apply the test rule by building a wrapper {@link Statement} that logs a messages before and after evaluating - * statement and if - * @param statement The statement to be modified. - * @param description A description of the test implemented in statement. - * @return The modified statement. - */ - @Override - public Statement apply(final Statement statement, final Description description) { - return new Statement() { - @Override - public void evaluate() throws Throwable { - final Logger logger = LoggerFactory.getLogger(description.getTestClass()); - logger.info(MessageFormat.format("Starting test case [{0}]", description.getDisplayName())); - boolean success = false; - try { - statement.evaluate(); - success = true; - } catch (final Throwable e) { - logger.error(MessageFormat.format("Exception thrown in test case [{0}]: {1}", description.getDisplayName(), e.toString()), e); - throw e; - } finally { - logger.info(MessageFormat.format("Finished test case [{0}] (success={1})", description.getDisplayName(), success)); - } - } - }; - } + @Override + public void afterEach(ExtensionContext context) { + final Logger logger = LoggerFactory.getLogger(context.getTestClass().get()); + logger.info(MessageFormat.format("Finished test case [{0}]", context.getTestMethod().get().getName())); + } + + @Override + public void beforeEach(ExtensionContext context) { + final Logger logger = LoggerFactory.getLogger(context.getTestClass().get()); + logger.info(MessageFormat.format("Starting test case [{0}]", context.getTestMethod().get().getName())); + } } diff --git a/hapi-fhir-test-utilities/src/main/java/ca/uhn/fhir/test/utilities/server/HashMapResourceProviderExtension.java b/hapi-fhir-test-utilities/src/main/java/ca/uhn/fhir/test/utilities/server/HashMapResourceProviderExtension.java new file mode 100644 index 00000000000..f0af71a7ac8 --- /dev/null +++ b/hapi-fhir-test-utilities/src/main/java/ca/uhn/fhir/test/utilities/server/HashMapResourceProviderExtension.java @@ -0,0 +1,54 @@ +package ca.uhn.fhir.test.utilities.server; + +/*- + * #%L + * HAPI FHIR Test Utilities + * %% + * Copyright (C) 2014 - 2020 University Health Network + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ + +import ca.uhn.fhir.rest.server.provider.HashMapResourceProvider; +import org.hl7.fhir.instance.model.api.IBaseResource; +import org.junit.jupiter.api.extension.AfterEachCallback; +import org.junit.jupiter.api.extension.BeforeEachCallback; +import org.junit.jupiter.api.extension.ExtensionContext; + +public class HashMapResourceProviderExtension extends HashMapResourceProvider implements BeforeEachCallback, AfterEachCallback { + + private final RestfulServerExtension myRestfulServerExtension; + + /** + * Constructor + * + * @param theResourceType The resource type to support + */ + public HashMapResourceProviderExtension(RestfulServerExtension theRestfulServerExtension, Class theResourceType) { + super(theRestfulServerExtension.getFhirContext(), theResourceType); + + myRestfulServerExtension = theRestfulServerExtension; + } + + @Override + public void afterEach(ExtensionContext context) throws Exception { + myRestfulServerExtension.getRestfulServer().unregisterProvider(HashMapResourceProviderExtension.this); + } + + @Override + public void beforeEach(ExtensionContext context) throws Exception { + clear(); + myRestfulServerExtension.getRestfulServer().registerProvider(HashMapResourceProviderExtension.this); + } +} diff --git a/hapi-fhir-test-utilities/src/main/java/ca/uhn/fhir/test/utilities/server/HashMapResourceProviderRule.java b/hapi-fhir-test-utilities/src/main/java/ca/uhn/fhir/test/utilities/server/HashMapResourceProviderRule.java deleted file mode 100644 index 26912696de4..00000000000 --- a/hapi-fhir-test-utilities/src/main/java/ca/uhn/fhir/test/utilities/server/HashMapResourceProviderRule.java +++ /dev/null @@ -1,60 +0,0 @@ -package ca.uhn.fhir.test.utilities.server; - -/*- - * #%L - * HAPI FHIR Test Utilities - * %% - * Copyright (C) 2014 - 2020 University Health Network - * %% - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * #L% - */ - -import ca.uhn.fhir.rest.server.provider.HashMapResourceProvider; -import org.hl7.fhir.instance.model.api.IBaseResource; -import org.junit.rules.TestRule; -import org.junit.runner.Description; -import org.junit.runners.model.Statement; - -public class HashMapResourceProviderRule extends HashMapResourceProvider implements TestRule { - - private final RestfulServerRule myRestfulServerRule; - - /** - * Constructor - * - * @param theResourceType The resource type to support - */ - public HashMapResourceProviderRule(RestfulServerRule theRestfulServerRule, Class theResourceType) { - super(theRestfulServerRule.getFhirContext(), theResourceType); - - myRestfulServerRule = theRestfulServerRule; - } - - @Override - public Statement apply(Statement base, Description description) { - return new Statement() { - @Override - public void evaluate() throws Throwable { - clear(); - myRestfulServerRule.getRestfulServer().registerProvider(HashMapResourceProviderRule.this); - try { - base.evaluate(); - } finally { - myRestfulServerRule.getRestfulServer().unregisterProvider(HashMapResourceProviderRule.this); - } - } - }; - } - -} diff --git a/hapi-fhir-test-utilities/src/main/java/ca/uhn/fhir/test/utilities/server/ResourceProviderRule.java b/hapi-fhir-test-utilities/src/main/java/ca/uhn/fhir/test/utilities/server/ResourceProviderExtension.java similarity index 52% rename from hapi-fhir-test-utilities/src/main/java/ca/uhn/fhir/test/utilities/server/ResourceProviderRule.java rename to hapi-fhir-test-utilities/src/main/java/ca/uhn/fhir/test/utilities/server/ResourceProviderExtension.java index dd9b1da4666..0bccaf81f34 100644 --- a/hapi-fhir-test-utilities/src/main/java/ca/uhn/fhir/test/utilities/server/ResourceProviderRule.java +++ b/hapi-fhir-test-utilities/src/main/java/ca/uhn/fhir/test/utilities/server/ResourceProviderExtension.java @@ -20,36 +20,30 @@ package ca.uhn.fhir.test.utilities.server; * #L% */ -import org.junit.rules.TestRule; -import org.junit.runner.Description; -import org.junit.runners.model.Statement; +import org.junit.jupiter.api.extension.AfterEachCallback; +import org.junit.jupiter.api.extension.BeforeEachCallback; +import org.junit.jupiter.api.extension.ExtensionContext; -public class ResourceProviderRule implements TestRule { +public class ResourceProviderExtension implements BeforeEachCallback, AfterEachCallback { - private final RestfulServerRule myRestfulServerRule; + private final RestfulServerExtension myRestfulServerExtension; private Object myProvider; /** * Constructor */ - public ResourceProviderRule(RestfulServerRule theRestfulServerRule, Object theProvider) { - myRestfulServerRule = theRestfulServerRule; + public ResourceProviderExtension(RestfulServerExtension theRestfulServerExtension, Object theProvider) { + myRestfulServerExtension = theRestfulServerExtension; myProvider = theProvider; } @Override - public Statement apply(Statement base, Description description) { - return new Statement() { - @Override - public void evaluate() throws Throwable { - myRestfulServerRule.getRestfulServer().registerProvider(myProvider); - try { - base.evaluate(); - } finally { - myRestfulServerRule.getRestfulServer().unregisterProvider(myProvider); - } - } - }; + public void afterEach(ExtensionContext context) { + myRestfulServerExtension.getRestfulServer().unregisterProvider(myProvider); } + @Override + public void beforeEach(ExtensionContext context) { + myRestfulServerExtension.getRestfulServer().registerProvider(myProvider); + } } diff --git a/hapi-fhir-test-utilities/src/main/java/ca/uhn/fhir/test/utilities/server/RestfulServerRule.java b/hapi-fhir-test-utilities/src/main/java/ca/uhn/fhir/test/utilities/server/RestfulServerExtension.java similarity index 85% rename from hapi-fhir-test-utilities/src/main/java/ca/uhn/fhir/test/utilities/server/RestfulServerRule.java rename to hapi-fhir-test-utilities/src/main/java/ca/uhn/fhir/test/utilities/server/RestfulServerExtension.java index 3922e8f0ab9..8a132f383c1 100644 --- a/hapi-fhir-test-utilities/src/main/java/ca/uhn/fhir/test/utilities/server/RestfulServerRule.java +++ b/hapi-fhir-test-utilities/src/main/java/ca/uhn/fhir/test/utilities/server/RestfulServerExtension.java @@ -34,16 +34,16 @@ 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.rules.TestRule; -import org.junit.runner.Description; -import org.junit.runners.model.Statement; +import org.junit.jupiter.api.extension.AfterEachCallback; +import org.junit.jupiter.api.extension.BeforeEachCallback; +import org.junit.jupiter.api.extension.ExtensionContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.util.concurrent.TimeUnit; -public class RestfulServerRule implements TestRule { - private static final Logger ourLog = LoggerFactory.getLogger(RestfulServerRule.class); +public class RestfulServerExtension implements BeforeEachCallback, AfterEachCallback { + private static final Logger ourLog = LoggerFactory.getLogger(RestfulServerExtension.class); private FhirContext myFhirContext; private Object[] myProviders; @@ -57,7 +57,7 @@ public class RestfulServerRule implements TestRule { /** * Constructor */ - public RestfulServerRule(FhirContext theFhirContext, Object... theProviders) { + public RestfulServerExtension(FhirContext theFhirContext, Object... theProviders) { Validate.notNull(theFhirContext); myFhirContext = theFhirContext; myProviders = theProviders; @@ -66,25 +66,11 @@ public class RestfulServerRule implements TestRule { /** * Constructor: If this is used, it will create and tear down a FhirContext which is good for memory */ - public RestfulServerRule(FhirVersionEnum theFhirVersionEnum) { + public RestfulServerExtension(FhirVersionEnum theFhirVersionEnum) { Validate.notNull(theFhirVersionEnum); myFhirVersion = theFhirVersionEnum; } - @Override - public Statement apply(Statement theBase, Description theDescription) { - return new Statement() { - @Override - public void evaluate() throws Throwable { - createContextIfNeeded(); - startServer(); - theBase.evaluate(); - stopServer(); - destroyContextIfWeCreatedIt(); - } - }; - } - private void createContextIfNeeded() { if (myFhirVersion != null) { myFhirContext = new FhirContext(myFhirVersion); @@ -149,4 +135,16 @@ public class RestfulServerRule implements TestRule { public int getPort() { return myPort; } + + @Override + public void afterEach(ExtensionContext context) throws Exception { + stopServer(); + destroyContextIfWeCreatedIt(); + } + + @Override + public void beforeEach(ExtensionContext context) throws Exception { + createContextIfNeeded(); + startServer(); + } } diff --git a/hapi-fhir-validation/pom.xml b/hapi-fhir-validation/pom.xml index 1e36c0fd38a..44818476928 100644 --- a/hapi-fhir-validation/pom.xml +++ b/hapi-fhir-validation/pom.xml @@ -59,6 +59,10 @@ io.javalin javalin + + junit + junit + diff --git a/hapi-fhir-validation/src/test/java/ca/uhn/fhir/fhirpath/FluentPathTest.java b/hapi-fhir-validation/src/test/java/ca/uhn/fhir/fhirpath/FluentPathTest.java index 6bc7da3d654..2102d1c049c 100644 --- a/hapi-fhir-validation/src/test/java/ca/uhn/fhir/fhirpath/FluentPathTest.java +++ b/hapi-fhir-validation/src/test/java/ca/uhn/fhir/fhirpath/FluentPathTest.java @@ -5,13 +5,14 @@ import ca.uhn.fhir.util.TestUtil; import org.hl7.fhir.dstu3.model.HumanName; import org.hl7.fhir.dstu3.model.Patient; import org.hl7.fhir.dstu3.model.StringType; -import org.junit.AfterClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; import java.util.List; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertEquals; public class FluentPathTest { @@ -71,7 +72,7 @@ public class FluentPathTest { private static FhirContext ourCtx = FhirContext.forDstu3(); - @AfterClass + @AfterAll public static void afterClassClearContext() { TestUtil.clearAllStaticFieldsForUnitTest(); } diff --git a/hapi-fhir-validation/src/test/java/ca/uhn/fhir/rest/server/RequestValidatingInterceptorDstu3Test.java b/hapi-fhir-validation/src/test/java/ca/uhn/fhir/rest/server/RequestValidatingInterceptorDstu3Test.java index 59c4fc2b0ca..af0ade61f0d 100644 --- a/hapi-fhir-validation/src/test/java/ca/uhn/fhir/rest/server/RequestValidatingInterceptorDstu3Test.java +++ b/hapi-fhir-validation/src/test/java/ca/uhn/fhir/rest/server/RequestValidatingInterceptorDstu3Test.java @@ -3,12 +3,18 @@ package ca.uhn.fhir.rest.server; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.api.IResource; import ca.uhn.fhir.model.primitive.IdDt; -import ca.uhn.fhir.rest.annotation.*; +import ca.uhn.fhir.rest.annotation.Create; +import ca.uhn.fhir.rest.annotation.Delete; +import ca.uhn.fhir.rest.annotation.IdParam; +import ca.uhn.fhir.rest.annotation.OptionalParam; +import ca.uhn.fhir.rest.annotation.ResourceParam; +import ca.uhn.fhir.rest.annotation.Search; import ca.uhn.fhir.rest.api.Constants; import ca.uhn.fhir.rest.api.MethodOutcome; import ca.uhn.fhir.rest.param.StringParam; import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; import ca.uhn.fhir.rest.server.interceptor.RequestValidatingInterceptor; +import ca.uhn.fhir.test.utilities.JettyUtil; import ca.uhn.fhir.util.TestUtil; import ca.uhn.fhir.validation.IValidationContext; import ca.uhn.fhir.validation.IValidatorModule; @@ -33,22 +39,20 @@ import org.hl7.fhir.dstu3.model.Enumerations.AdministrativeGender; import org.hl7.fhir.dstu3.model.IdType; 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; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import java.util.ArrayList; import java.util.List; import java.util.concurrent.TimeUnit; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.mock; -import ca.uhn.fhir.test.utilities.JettyUtil; - public class RequestValidatingInterceptorDstu3Test { private static CloseableHttpClient ourClient; @@ -63,7 +67,7 @@ public class RequestValidatingInterceptorDstu3Test { private RequestValidatingInterceptor myInterceptor; - @Before + @BeforeEach public void before() { ourLastRequestWasSearch = false; ourServlet.getInterceptorService().unregisterAllInterceptors(); @@ -459,13 +463,13 @@ public class RequestValidatingInterceptorDstu3Test { assertEquals(true, ourLastRequestWasSearch); } - @AfterClass + @AfterAll public static void afterClassClearContext() throws Exception { JettyUtil.closeServer(ourServer); TestUtil.clearAllStaticFieldsForUnitTest(); } - @BeforeClass + @BeforeAll public static void beforeClass() throws Exception { ourServer = new Server(0); diff --git a/hapi-fhir-validation/src/test/java/ca/uhn/fhir/rest/server/RequestValidatingInterceptorR4Test.java b/hapi-fhir-validation/src/test/java/ca/uhn/fhir/rest/server/RequestValidatingInterceptorR4Test.java index 5baeb2e0d85..b75ccdde935 100644 --- a/hapi-fhir-validation/src/test/java/ca/uhn/fhir/rest/server/RequestValidatingInterceptorR4Test.java +++ b/hapi-fhir-validation/src/test/java/ca/uhn/fhir/rest/server/RequestValidatingInterceptorR4Test.java @@ -34,17 +34,17 @@ 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.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.common.hapi.validation.validator.FhirInstanceValidator; +import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.r4.model.Enumerations.AdministrativeGender; import org.hl7.fhir.r4.model.IdType; import org.hl7.fhir.r4.model.Narrative; import org.hl7.fhir.r4.model.Patient; import org.hl7.fhir.utilities.xhtml.XhtmlNode; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import java.io.IOException; @@ -52,10 +52,10 @@ import java.util.ArrayList; import java.util.List; import java.util.concurrent.TimeUnit; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.not; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.mock; public class RequestValidatingInterceptorR4Test { @@ -72,7 +72,7 @@ public class RequestValidatingInterceptorR4Test { private RequestValidatingInterceptor myInterceptor; - @Before + @BeforeEach public void before() { ourLastRequestWasSearch = false; ourServlet.getInterceptorService().unregisterAllInterceptors(); @@ -508,13 +508,13 @@ public class RequestValidatingInterceptorR4Test { assertEquals(true, ourLastRequestWasSearch); } - @AfterClass + @AfterAll public static void afterClassClearContext() throws Exception { JettyUtil.closeServer(ourServer); TestUtil.clearAllStaticFieldsForUnitTest(); } - @BeforeClass + @BeforeAll public static void beforeClass() throws Exception { ourServer = new Server(0); diff --git a/hapi-fhir-validation/src/test/java/ca/uhn/fhir/rest/server/ResponseValidatingInterceptorDstu3Test.java b/hapi-fhir-validation/src/test/java/ca/uhn/fhir/rest/server/ResponseValidatingInterceptorDstu3Test.java index b5fd26aa9f8..8cb2d28a63b 100644 --- a/hapi-fhir-validation/src/test/java/ca/uhn/fhir/rest/server/ResponseValidatingInterceptorDstu3Test.java +++ b/hapi-fhir-validation/src/test/java/ca/uhn/fhir/rest/server/ResponseValidatingInterceptorDstu3Test.java @@ -28,35 +28,35 @@ import org.eclipse.jetty.server.Server; import org.eclipse.jetty.servlet.ServletHandler; import org.eclipse.jetty.servlet.ServletHolder; import org.hamcrest.Matchers; +import org.hl7.fhir.common.hapi.validation.validator.FhirInstanceValidator; import org.hl7.fhir.dstu3.model.Enumerations.AdministrativeGender; import org.hl7.fhir.dstu3.model.IdType; import org.hl7.fhir.dstu3.model.Patient; import org.hl7.fhir.instance.model.api.IBaseResource; -import org.hl7.fhir.common.hapi.validation.validator.FhirInstanceValidator; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import java.util.ArrayList; import java.util.concurrent.TimeUnit; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.mock; public class ResponseValidatingInterceptorDstu3Test { + private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ResponseValidatingInterceptorDstu3Test.class); 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; - @Before + @BeforeEach public void before() { myReturnResource = null; ourServlet.getInterceptorService().unregisterAllInterceptors(); @@ -69,7 +69,7 @@ public class ResponseValidatingInterceptorDstu3Test { ourServlet.registerInterceptor(myInterceptor); } - + @SuppressWarnings("unchecked") @Test public void testInterceptorExceptionNpeNoIgnore() throws Exception { @@ -86,7 +86,7 @@ public class ResponseValidatingInterceptorDstu3Test { myInterceptor.setIgnoreValidatorExceptions(false); Mockito.doThrow(new NullPointerException("SOME MESSAGE")).when(module).validateResource(Mockito.any(IValidationContext.class)); - + HttpGet httpPost = new HttpGet("http://localhost:" + ourPort + "/Patient?foo=bar"); HttpResponse status = ourClient.execute(httpPost); @@ -96,8 +96,8 @@ public class ResponseValidatingInterceptorDstu3Test { ourLog.info("Response was:\n{}", status); ourLog.info("Response was:\n{}", responseContent); - Assert.assertEquals(500, status.getStatusLine().getStatusCode()); - Assert.assertThat(responseContent, Matchers.containsString("")); + assertEquals(500, status.getStatusLine().getStatusCode()); + assertThat(responseContent, Matchers.containsString("")); } @SuppressWarnings("unchecked") @@ -116,7 +116,7 @@ public class ResponseValidatingInterceptorDstu3Test { myInterceptor.setIgnoreValidatorExceptions(true); Mockito.doThrow(NullPointerException.class).when(module).validateResource(Mockito.any(IValidationContext.class)); - + HttpGet httpPost = new HttpGet("http://localhost:" + ourPort + "/Patient?foo=bar"); HttpResponse status = ourClient.execute(httpPost); @@ -126,8 +126,8 @@ public class ResponseValidatingInterceptorDstu3Test { ourLog.info("Response was:\n{}", status); ourLog.info("Response was:\n{}", responseContent); - Assert.assertEquals(200, status.getStatusLine().getStatusCode()); - Assert.assertThat(status.toString(), Matchers.not(Matchers.containsString("X-FHIR-Response-Validation"))); + assertEquals(200, status.getStatusLine().getStatusCode()); + assertThat(status.toString(), Matchers.not(Matchers.containsString("X-FHIR-Response-Validation"))); } @SuppressWarnings("unchecked") @@ -146,7 +146,7 @@ public class ResponseValidatingInterceptorDstu3Test { myInterceptor.setIgnoreValidatorExceptions(false); Mockito.doThrow(new InternalErrorException("FOO")).when(module).validateResource(Mockito.any(IValidationContext.class)); - + HttpGet httpPost = new HttpGet("http://localhost:" + ourPort + "/Patient?foo=bar"); HttpResponse status = ourClient.execute(httpPost); @@ -156,8 +156,8 @@ public class ResponseValidatingInterceptorDstu3Test { ourLog.info("Response was:\n{}", status); ourLog.info("Response was:\n{}", responseContent); - Assert.assertEquals(500, status.getStatusLine().getStatusCode()); - Assert.assertThat(responseContent, Matchers.containsString("")); + assertEquals(500, status.getStatusLine().getStatusCode()); + assertThat(responseContent, Matchers.containsString("")); } @SuppressWarnings("unchecked") @@ -176,7 +176,7 @@ public class ResponseValidatingInterceptorDstu3Test { myInterceptor.setIgnoreValidatorExceptions(true); Mockito.doThrow(InternalErrorException.class).when(module).validateResource(Mockito.any(IValidationContext.class)); - + HttpGet httpPost = new HttpGet("http://localhost:" + ourPort + "/Patient?foo=bar"); HttpResponse status = ourClient.execute(httpPost); @@ -186,11 +186,11 @@ public class ResponseValidatingInterceptorDstu3Test { ourLog.info("Response was:\n{}", status); ourLog.info("Response was:\n{}", responseContent); - Assert.assertEquals(200, status.getStatusLine().getStatusCode()); - Assert.assertThat(status.toString(), Matchers.not(Matchers.containsString("X-FHIR-Response-Validation"))); + assertEquals(200, status.getStatusLine().getStatusCode()); + assertThat(status.toString(), Matchers.not(Matchers.containsString("X-FHIR-Response-Validation"))); } - + /** * Test for #345 */ @@ -205,8 +205,8 @@ public class ResponseValidatingInterceptorDstu3Test { try { ourLog.info("Response was:\n{}", status); - Assert.assertEquals(204, status.getStatusLine().getStatusCode()); - Assert.assertThat(status.toString(), Matchers.not(Matchers.containsString("X-FHIR-Response-Validation"))); + assertEquals(204, status.getStatusLine().getStatusCode()); + assertThat(status.toString(), Matchers.not(Matchers.containsString("X-FHIR-Response-Validation"))); } finally { IOUtils.closeQuietly(status); } @@ -238,9 +238,9 @@ public class ResponseValidatingInterceptorDstu3Test { ourLog.info("Response was:\n{}", status); ourLog.trace("Response was:\n{}", responseContent); - Assert.assertEquals(200, status.getStatusLine().getStatusCode()); - Assert.assertThat(status.getFirstHeader("X-FHIR-Response-Validation").getValue(), Matchers.endsWith("...")); - Assert.assertThat(status.getFirstHeader("X-FHIR-Response-Validation").getValue(), Matchers.startsWith("{\"resourceType\":\"OperationOutcome\"")); + assertEquals(200, status.getStatusLine().getStatusCode()); + assertThat(status.getFirstHeader("X-FHIR-Response-Validation").getValue(), Matchers.endsWith("...")); + assertThat(status.getFirstHeader("X-FHIR-Response-Validation").getValue(), Matchers.startsWith("{\"resourceType\":\"OperationOutcome\"")); } { myInterceptor.setMaximumHeaderLength(100); @@ -252,9 +252,9 @@ public class ResponseValidatingInterceptorDstu3Test { ourLog.info("Response was:\n{}", status); ourLog.trace("Response was:\n{}", responseContent); - Assert.assertEquals(200, status.getStatusLine().getStatusCode()); - Assert.assertThat(status.getFirstHeader("X-FHIR-Response-Validation").getValue(), Matchers.endsWith("...")); - Assert.assertThat(status.getFirstHeader("X-FHIR-Response-Validation").getValue(), Matchers.startsWith("{\"resourceType\":\"OperationOutcome\"")); + assertEquals(200, status.getStatusLine().getStatusCode()); + assertThat(status.getFirstHeader("X-FHIR-Response-Validation").getValue(), Matchers.endsWith("...")); + assertThat(status.getFirstHeader("X-FHIR-Response-Validation").getValue(), Matchers.startsWith("{\"resourceType\":\"OperationOutcome\"")); } } @@ -276,9 +276,9 @@ public class ResponseValidatingInterceptorDstu3Test { ourLog.info("Response was:\n{}", status); ourLog.trace("Response was:\n{}", responseContent); - Assert.assertEquals(200, status.getStatusLine().getStatusCode()); - Assert.assertThat(status.toString(), (Matchers.containsString( - "X-FHIR-Response-Validation: {\"resourceType\":\"OperationOutcome\",\"issue\":[{\"severity\":\"information\",\"code\":\"informational\",\"diagnostics\":\"No issues detected\"}]}"))); + assertEquals(200, status.getStatusLine().getStatusCode()); + assertThat(status.toString(), (Matchers.containsString( + "X-FHIR-Response-Validation: {\"resourceType\":\"OperationOutcome\",\"issue\":[{\"severity\":\"information\",\"code\":\"informational\",\"diagnostics\":\"No issues detected\"}]}"))); } /** @@ -302,8 +302,8 @@ public class ResponseValidatingInterceptorDstu3Test { ourLog.info("Response was:\n{}", status); ourLog.info("Response was:\n{}", responseContent); - Assert.assertEquals(422, status.getStatusLine().getStatusCode()); - Assert.assertThat(responseContent, Matchers.containsString("")); + assertEquals(422, status.getStatusLine().getStatusCode()); + assertThat(responseContent, Matchers.containsString("")); } @Test @@ -323,8 +323,8 @@ public class ResponseValidatingInterceptorDstu3Test { ourLog.info("Response was:\n{}", status); ourLog.trace("Response was:\n{}", responseContent); - Assert.assertEquals(200, status.getStatusLine().getStatusCode()); - Assert.assertThat(status.toString(), Matchers.not(Matchers.containsString("X-FHIR-Response-Validation"))); + assertEquals(200, status.getStatusLine().getStatusCode()); + assertThat(status.toString(), Matchers.not(Matchers.containsString("X-FHIR-Response-Validation"))); } @Test @@ -347,8 +347,8 @@ public class ResponseValidatingInterceptorDstu3Test { ourLog.info("Response was:\n{}", status); ourLog.trace("Response was:\n{}", responseContent); - Assert.assertEquals(200, status.getStatusLine().getStatusCode()); - Assert.assertThat(status.toString(), (Matchers.containsString("X-FHIR-Response-Validation: NO ISSUES"))); + assertEquals(200, status.getStatusLine().getStatusCode()); + assertThat(status.toString(), (Matchers.containsString("X-FHIR-Response-Validation: NO ISSUES"))); } @Test @@ -373,8 +373,8 @@ public class ResponseValidatingInterceptorDstu3Test { ourLog.info("Response was:\n{}", status); ourLog.info("Response was:\n{}", responseContent); - Assert.assertEquals(422, status.getStatusLine().getStatusCode()); - Assert.assertThat(status.toString(), Matchers.containsString("X-FHIR-Response-Validation")); + assertEquals(422, status.getStatusLine().getStatusCode()); + assertThat(status.toString(), Matchers.containsString("X-FHIR-Response-Validation")); } /** @@ -398,8 +398,8 @@ public class ResponseValidatingInterceptorDstu3Test { ourLog.info("Response was:\n{}", status); ourLog.info("Response was:\n{}", responseContent); - Assert.assertEquals(422, status.getStatusLine().getStatusCode()); - Assert.assertThat(responseContent, Matchers.containsString("")); + assertEquals(422, status.getStatusLine().getStatusCode()); + assertThat(responseContent, Matchers.containsString("")); } @Test @@ -419,8 +419,8 @@ public class ResponseValidatingInterceptorDstu3Test { ourLog.info("Response was:\n{}", status); ourLog.trace("Response was:\n{}", responseContent); - Assert.assertEquals(200, status.getStatusLine().getStatusCode()); - Assert.assertThat(status.toString(), Matchers.not(Matchers.containsString("X-FHIR-Response-Validation"))); + assertEquals(200, status.getStatusLine().getStatusCode()); + assertThat(status.toString(), Matchers.not(Matchers.containsString("X-FHIR-Response-Validation"))); } @Test @@ -439,8 +439,8 @@ public class ResponseValidatingInterceptorDstu3Test { ourLog.info("Response was:\n{}", status); ourLog.info("Response was:\n{}", responseContent); - Assert.assertEquals(200, status.getStatusLine().getStatusCode()); - Assert.assertThat(status.toString(), Matchers.not(Matchers.containsString("X-FHIR-Response-Validation"))); + assertEquals(200, status.getStatusLine().getStatusCode()); + assertThat(status.toString(), Matchers.not(Matchers.containsString("X-FHIR-Response-Validation"))); } @Test @@ -460,38 +460,8 @@ public class ResponseValidatingInterceptorDstu3Test { ourLog.info("Response was:\n{}", status); ourLog.info("Response was:\n{}", responseContent); - Assert.assertEquals(200, status.getStatusLine().getStatusCode()); - Assert.assertThat(status.toString(), (Matchers.containsString("X-FHIR-Response-Validation"))); - } - - @AfterClass - public static void afterClassClearContext() throws Exception { - JettyUtil.closeServer(ourServer); - TestUtil.clearAllStaticFieldsForUnitTest(); - } - - @BeforeClass - public static void beforeClass() throws Exception { - ourServer = new Server(0); - - PatientProvider patientProvider = new PatientProvider(); - - ServletHandler proxyHandler = new ServletHandler(); - ourServlet = new RestfulServer(ourCtx); - ourServlet.setResourceProviders(patientProvider); - ourServlet.setDefaultResponseEncoding(EncodingEnum.XML); - - ServletHolder servletHolder = new ServletHolder(ourServlet); - proxyHandler.addServletWithMapping(servletHolder, "/*"); - ourServer.setHandler(proxyHandler); - JettyUtil.startServer(ourServer); - ourPort = JettyUtil.getPortForStartedServer(ourServer); - - PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(5000, TimeUnit.MILLISECONDS); - HttpClientBuilder builder = HttpClientBuilder.create(); - builder.setConnectionManager(connectionManager); - ourClient = builder.build(); - + assertEquals(200, status.getStatusLine().getStatusCode()); + assertThat(status.toString(), (Matchers.containsString("X-FHIR-Response-Validation"))); } public static class PatientProvider implements IResourceProvider { @@ -508,7 +478,7 @@ public class ResponseValidatingInterceptorDstu3Test { @Search public ArrayList search(@OptionalParam(name = "foo") StringParam theString) { - ArrayList retVal = new ArrayList(); + ArrayList retVal = new ArrayList<>(); myReturnResource.setId("1"); retVal.add(myReturnResource); return retVal; @@ -516,4 +486,34 @@ public class ResponseValidatingInterceptorDstu3Test { } + @AfterAll + public static void afterClassClearContext() throws Exception { + JettyUtil.closeServer(ourServer); + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + @BeforeAll + public static void beforeClass() throws Exception { + ourServer = new Server(0); + + PatientProvider patientProvider = new PatientProvider(); + + ServletHandler proxyHandler = new ServletHandler(); + ourServlet = new RestfulServer(ourCtx); + ourServlet.setResourceProviders(patientProvider); + ourServlet.setDefaultResponseEncoding(EncodingEnum.XML); + + ServletHolder servletHolder = new ServletHolder(ourServlet); + proxyHandler.addServletWithMapping(servletHolder, "/*"); + ourServer.setHandler(proxyHandler); + JettyUtil.startServer(ourServer); + ourPort = JettyUtil.getPortForStartedServer(ourServer); + + PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(5000, TimeUnit.MILLISECONDS); + HttpClientBuilder builder = HttpClientBuilder.create(); + builder.setConnectionManager(connectionManager); + ourClient = builder.build(); + + } + } diff --git a/hapi-fhir-validation/src/test/java/ca/uhn/fhir/rest/server/ResponseValidatingInterceptorR4Test.java b/hapi-fhir-validation/src/test/java/ca/uhn/fhir/rest/server/ResponseValidatingInterceptorR4Test.java index c63bf8a7890..3242c094ce4 100644 --- a/hapi-fhir-validation/src/test/java/ca/uhn/fhir/rest/server/ResponseValidatingInterceptorR4Test.java +++ b/hapi-fhir-validation/src/test/java/ca/uhn/fhir/rest/server/ResponseValidatingInterceptorR4Test.java @@ -1,41 +1,11 @@ package ca.uhn.fhir.rest.server; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.endsWith; -import static org.hamcrest.Matchers.not; -import static org.hamcrest.Matchers.startsWith; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; -import static org.mockito.Mockito.mock; - -import java.util.ArrayList; -import java.util.concurrent.TimeUnit; - -import ca.uhn.fhir.rest.api.EncodingEnum; -import org.apache.commons.io.IOUtils; -import org.apache.http.HttpResponse; -import org.apache.http.client.methods.*; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClientBuilder; -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.hamcrest.Matchers; -import org.hl7.fhir.instance.model.api.IBaseResource; -import org.hl7.fhir.common.hapi.validation.validator.FhirInstanceValidator; -import org.hl7.fhir.r4.model.Enumerations.AdministrativeGender; -import org.hl7.fhir.r4.model.IdType; -import org.hl7.fhir.r4.model.Narrative; -import org.hl7.fhir.r4.model.Patient; -import org.hl7.fhir.utilities.xhtml.XhtmlNode; -import org.junit.*; -import org.mockito.Mockito; - -import com.google.common.base.Charsets; - import ca.uhn.fhir.context.FhirContext; -import ca.uhn.fhir.rest.annotation.*; +import ca.uhn.fhir.rest.annotation.Delete; +import ca.uhn.fhir.rest.annotation.IdParam; +import ca.uhn.fhir.rest.annotation.OptionalParam; +import ca.uhn.fhir.rest.annotation.Search; +import ca.uhn.fhir.rest.api.EncodingEnum; import ca.uhn.fhir.rest.api.MethodOutcome; import ca.uhn.fhir.rest.api.RestOperationTypeEnum; import ca.uhn.fhir.rest.param.StringParam; @@ -43,7 +13,45 @@ import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; import ca.uhn.fhir.rest.server.interceptor.ResponseValidatingInterceptor; import ca.uhn.fhir.test.utilities.JettyUtil; import ca.uhn.fhir.util.TestUtil; -import ca.uhn.fhir.validation.*; +import ca.uhn.fhir.validation.IValidationContext; +import ca.uhn.fhir.validation.IValidatorModule; +import ca.uhn.fhir.validation.ResultSeverityEnum; +import com.google.common.base.Charsets; +import org.apache.commons.io.IOUtils; +import org.apache.http.HttpResponse; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpDelete; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClientBuilder; +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.hamcrest.Matchers; +import org.hl7.fhir.common.hapi.validation.validator.FhirInstanceValidator; +import org.hl7.fhir.instance.model.api.IBaseResource; +import org.hl7.fhir.r4.model.Enumerations.AdministrativeGender; +import org.hl7.fhir.r4.model.IdType; +import org.hl7.fhir.r4.model.Narrative; +import org.hl7.fhir.r4.model.Patient; +import org.hl7.fhir.utilities.xhtml.XhtmlNode; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.mockito.Mockito; + +import java.util.ArrayList; +import java.util.concurrent.TimeUnit; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.endsWith; +import static org.hamcrest.Matchers.not; +import static org.hamcrest.Matchers.startsWith; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.Mockito.mock; public class ResponseValidatingInterceptorR4Test { public static IBaseResource myReturnResource; @@ -56,7 +64,7 @@ public class ResponseValidatingInterceptorR4Test { private static RestfulServer ourServlet; private ResponseValidatingInterceptor myInterceptor; - @Before + @BeforeEach public void before() { myReturnResource = null; ourServlet.getInterceptorService().unregisterAllInterceptors(); @@ -402,7 +410,7 @@ public class ResponseValidatingInterceptorR4Test { ourLog.info("Response was:\n{}", responseContent); assertEquals(422, status.getStatusLine().getStatusCode()); - Assert.assertThat(responseContent, Matchers.containsString("")); + assertThat(responseContent, Matchers.containsString("")); } @Test @@ -468,13 +476,13 @@ public class ResponseValidatingInterceptorR4Test { assertThat(status.toString(), (containsString("X-FHIR-Response-Validation"))); } - @AfterClass + @AfterAll public static void afterClassClearContext() throws Exception { JettyUtil.closeServer(ourServer); TestUtil.clearAllStaticFieldsForUnitTest(); } - @BeforeClass + @BeforeAll public static void beforeClass() throws Exception { ourServer = new Server(0); @@ -512,7 +520,7 @@ public class ResponseValidatingInterceptorR4Test { @Search public ArrayList search(@OptionalParam(name = "foo") StringParam theString) { - ArrayList retVal = new ArrayList(); + ArrayList retVal = new ArrayList<>(); myReturnResource.setId("1"); retVal.add(myReturnResource); return retVal; diff --git a/hapi-fhir-validation/src/test/java/ca/uhn/fhir/validation/ParserWithValidationDstu3Test.java b/hapi-fhir-validation/src/test/java/ca/uhn/fhir/validation/ParserWithValidationDstu3Test.java index ec1edc0711c..8064b027641 100644 --- a/hapi-fhir-validation/src/test/java/ca/uhn/fhir/validation/ParserWithValidationDstu3Test.java +++ b/hapi-fhir-validation/src/test/java/ca/uhn/fhir/validation/ParserWithValidationDstu3Test.java @@ -1,22 +1,23 @@ package ca.uhn.fhir.validation; import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.context.support.DefaultProfileValidationSupport; import ca.uhn.fhir.context.support.IValidationSupport; import ca.uhn.fhir.parser.IParser; import ca.uhn.fhir.util.TestUtil; -import ca.uhn.fhir.context.support.DefaultProfileValidationSupport; import org.hl7.fhir.common.hapi.validation.support.InMemoryTerminologyServerValidationSupport; import org.hl7.fhir.common.hapi.validation.support.ValidationSupportChain; import org.hl7.fhir.common.hapi.validation.validator.FhirInstanceValidator; import org.hl7.fhir.dstu3.model.ActivityDefinition; import org.hl7.fhir.dstu3.model.ConceptMap; import org.hl7.fhir.instance.model.api.IBaseResource; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import static org.junit.jupiter.api.Assertions.assertEquals; + public class ParserWithValidationDstu3Test { private static final Logger ourLog = LoggerFactory.getLogger(ParserWithValidationDstu3Test.class); @@ -36,7 +37,7 @@ public class ParserWithValidationDstu3Test { for (SingleValidationMessage msg : result.getMessages()) { ourLog.info("{}", msg); } - Assert.assertEquals(0, result.getMessages().size()); + assertEquals(0, result.getMessages().size()); } ActivityDefinition fhirObj = parser.parseResource(ActivityDefinition.class, origContent); @@ -51,11 +52,11 @@ public class ParserWithValidationDstu3Test { for (SingleValidationMessage msg : result.getMessages()) { ourLog.info("{}", msg); } - Assert.assertEquals(0, result.getMessages().size()); + assertEquals(0, result.getMessages().size()); } // verify that the original and newly serialized match - Assert.assertEquals(origContent, content); + assertEquals(origContent, content); } /** @@ -75,7 +76,7 @@ public class ParserWithValidationDstu3Test { for (SingleValidationMessage msg : result.getMessages()) { ourLog.info("{}", msg); } - Assert.assertEquals(0, result.getMessages().size()); + assertEquals(0, result.getMessages().size()); } ActivityDefinition fhirObj = parser.parseResource(ActivityDefinition.class, origContent); @@ -90,11 +91,11 @@ public class ParserWithValidationDstu3Test { for (SingleValidationMessage msg : result.getMessages()) { ourLog.info("{}", msg); } - Assert.assertEquals(0, result.getMessages().size()); + assertEquals(0, result.getMessages().size()); } // verify that the original and newly serialized match - Assert.assertEquals(origContent, content); + assertEquals(origContent, content); } @Test @@ -111,7 +112,7 @@ public class ParserWithValidationDstu3Test { for (SingleValidationMessage msg : result.getMessages()) { ourLog.info("{}", msg); } - Assert.assertEquals(0, result.getMessages().size()); + assertEquals(0, result.getMessages().size()); } ConceptMap fhirObj = parser.parseResource(ConceptMap.class, origContent); @@ -126,11 +127,11 @@ public class ParserWithValidationDstu3Test { for (SingleValidationMessage msg : result.getMessages()) { ourLog.info("{}", msg); } - Assert.assertEquals(0, result.getMessages().size()); + assertEquals(0, result.getMessages().size()); } // verify that the original and newly serialized match - Assert.assertEquals(origContent, content); + assertEquals(origContent, content); } private IValidationSupport getValidationSupport() { @@ -151,7 +152,7 @@ public class ParserWithValidationDstu3Test { for (SingleValidationMessage msg : result.getMessages()) { ourLog.info("{}", msg); } - Assert.assertEquals(0, result.getMessages().size()); + assertEquals(0, result.getMessages().size()); } ConceptMap fhirObj = parser.parseResource(ConceptMap.class, origContent); @@ -166,14 +167,14 @@ public class ParserWithValidationDstu3Test { for (SingleValidationMessage msg : result.getMessages()) { ourLog.info("{}", msg); } - Assert.assertEquals(0, result.getMessages().size()); + assertEquals(0, result.getMessages().size()); } // verify that the original and newly serialized match - Assert.assertEquals(origContent, content); + assertEquals(origContent, content); } - @AfterClass + @AfterAll public static void afterClassClearContext() { TestUtil.clearAllStaticFieldsForUnitTest(); } diff --git a/hapi-fhir-validation/src/test/java/ca/uhn/fhir/validation/SchemaBaseValidatorTest.java b/hapi-fhir-validation/src/test/java/ca/uhn/fhir/validation/SchemaBaseValidatorTest.java index d4cfdb3e4b4..7e8ac7e0ec8 100644 --- a/hapi-fhir-validation/src/test/java/ca/uhn/fhir/validation/SchemaBaseValidatorTest.java +++ b/hapi-fhir-validation/src/test/java/ca/uhn/fhir/validation/SchemaBaseValidatorTest.java @@ -2,14 +2,14 @@ package ca.uhn.fhir.validation; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.rest.server.exceptions.InternalErrorException; -import org.junit.Test; +import org.junit.jupiter.api.Test; import javax.xml.transform.Source; import static org.hamcrest.CoreMatchers.containsString; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.fail; public class SchemaBaseValidatorTest { diff --git a/hapi-fhir-validation/src/test/java/org/hl7/fhir/common/hapi/validation/ValidationSupportChainTest.java b/hapi-fhir-validation/src/test/java/org/hl7/fhir/common/hapi/validation/ValidationSupportChainTest.java index 4ff640e50d6..fa61cf94b31 100644 --- a/hapi-fhir-validation/src/test/java/org/hl7/fhir/common/hapi/validation/ValidationSupportChainTest.java +++ b/hapi-fhir-validation/src/test/java/org/hl7/fhir/common/hapi/validation/ValidationSupportChainTest.java @@ -5,9 +5,9 @@ import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.support.DefaultProfileValidationSupport; import ca.uhn.fhir.context.support.IValidationSupport; import org.hl7.fhir.common.hapi.validation.support.ValidationSupportChain; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.mock; public class ValidationSupportChainTest { diff --git a/hapi-fhir-validation/src/test/java/org/hl7/fhir/common/hapi/validation/support/CommonCodeSystemsTerminologyServiceTest.java b/hapi-fhir-validation/src/test/java/org/hl7/fhir/common/hapi/validation/support/CommonCodeSystemsTerminologyServiceTest.java index fb052103f5a..1a8e0c06c9d 100644 --- a/hapi-fhir-validation/src/test/java/org/hl7/fhir/common/hapi/validation/support/CommonCodeSystemsTerminologyServiceTest.java +++ b/hapi-fhir-validation/src/test/java/org/hl7/fhir/common/hapi/validation/support/CommonCodeSystemsTerminologyServiceTest.java @@ -5,18 +5,18 @@ import ca.uhn.fhir.context.support.ConceptValidationOptions; import ca.uhn.fhir.context.support.IValidationSupport; import ca.uhn.fhir.context.support.ValidationSupportContext; import org.hl7.fhir.r4.model.ValueSet; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; public class CommonCodeSystemsTerminologyServiceTest { private CommonCodeSystemsTerminologyService mySvc; private FhirContext myCtx; - @Before + @BeforeEach public void before() { myCtx = FhirContext.forR4(); mySvc = new CommonCodeSystemsTerminologyService(myCtx); diff --git a/hapi-fhir-validation/src/test/java/org/hl7/fhir/common/hapi/validation/support/RemoteTerminologyServiceValidationSupportTest.java b/hapi-fhir-validation/src/test/java/org/hl7/fhir/common/hapi/validation/support/RemoteTerminologyServiceValidationSupportTest.java index 6d14bb0a3da..7ef27d1716a 100644 --- a/hapi-fhir-validation/src/test/java/org/hl7/fhir/common/hapi/validation/support/RemoteTerminologyServiceValidationSupportTest.java +++ b/hapi-fhir-validation/src/test/java/org/hl7/fhir/common/hapi/validation/support/RemoteTerminologyServiceValidationSupportTest.java @@ -10,7 +10,7 @@ import ca.uhn.fhir.rest.annotation.Search; import ca.uhn.fhir.rest.client.interceptor.LoggingInterceptor; import ca.uhn.fhir.rest.param.UriParam; import ca.uhn.fhir.rest.server.IResourceProvider; -import ca.uhn.fhir.test.utilities.server.RestfulServerRule; +import ca.uhn.fhir.test.utilities.server.RestfulServerExtension; import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.r4.model.BooleanType; import org.hl7.fhir.r4.model.CodeSystem; @@ -20,19 +20,18 @@ import org.hl7.fhir.r4.model.Parameters; import org.hl7.fhir.r4.model.StringType; import org.hl7.fhir.r4.model.UriType; import org.hl7.fhir.r4.model.ValueSet; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; import javax.servlet.http.HttpServletRequest; - import java.util.ArrayList; import java.util.List; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.lessThan; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; public class RemoteTerminologyServiceValidationSupportTest { @@ -43,29 +42,29 @@ public class RemoteTerminologyServiceValidationSupportTest { private static final String ERROR_MESSAGE = "This is an error message"; private static FhirContext ourCtx = FhirContext.forR4(); - @Rule - public RestfulServerRule myRestfulServerRule = new RestfulServerRule(ourCtx); + @RegisterExtension + public RestfulServerExtension myRestfulServerExtension = new RestfulServerExtension(ourCtx); private MyValueSetProvider myValueSetProvider; private RemoteTerminologyServiceValidationSupport mySvc; private MyCodeSystemProvider myCodeSystemProvider; - @Before + @BeforeEach public void before() { myValueSetProvider = new MyValueSetProvider(); - myRestfulServerRule.getRestfulServer().registerProvider(myValueSetProvider); + myRestfulServerExtension.getRestfulServer().registerProvider(myValueSetProvider); myCodeSystemProvider = new MyCodeSystemProvider(); - myRestfulServerRule.getRestfulServer().registerProvider(myCodeSystemProvider); + myRestfulServerExtension.getRestfulServer().registerProvider(myCodeSystemProvider); - String baseUrl = "http://localhost:" + myRestfulServerRule.getPort(); + String baseUrl = "http://localhost:" + myRestfulServerExtension.getPort(); mySvc = new RemoteTerminologyServiceValidationSupport(ourCtx); mySvc.setBaseUrl(baseUrl); mySvc.addClientInterceptor(new LoggingInterceptor(false)); } - @After + @AfterEach public void after() { assertThat(myValueSetProvider.myInvocationCount, lessThan(2)); } @@ -233,7 +232,7 @@ public class RemoteTerminologyServiceValidationSupportTest { } @Search - public List find(@RequiredParam(name="url") UriParam theUrlParam) { + public List find(@RequiredParam(name = "url") UriParam theUrlParam) { myLastUrlParam = theUrlParam; assert myNextReturnCodeSystems != null; return myNextReturnCodeSystems; @@ -283,7 +282,7 @@ public class RemoteTerminologyServiceValidationSupportTest { } @Search - public List find(@RequiredParam(name="url") UriParam theUrlParam) { + public List find(@RequiredParam(name = "url") UriParam theUrlParam) { myLastUrlParam = theUrlParam; assert myNextReturnValueSets != null; return myNextReturnValueSets; diff --git a/hapi-fhir-validation/src/test/java/org/hl7/fhir/dstu2/hapi/validation/FhirInstanceValidatorDstu2Test.java b/hapi-fhir-validation/src/test/java/org/hl7/fhir/dstu2/hapi/validation/FhirInstanceValidatorDstu2Test.java index 64d1276511f..438cc763d83 100644 --- a/hapi-fhir-validation/src/test/java/org/hl7/fhir/dstu2/hapi/validation/FhirInstanceValidatorDstu2Test.java +++ b/hapi-fhir-validation/src/test/java/org/hl7/fhir/dstu2/hapi/validation/FhirInstanceValidatorDstu2Test.java @@ -18,26 +18,26 @@ import com.google.common.base.Charsets; import org.apache.commons.io.IOUtils; import org.hl7.fhir.common.hapi.validation.support.InMemoryTerminologyServerValidationSupport; import org.hl7.fhir.common.hapi.validation.support.ValidationSupportChain; +import org.hl7.fhir.common.hapi.validation.validator.FhirInstanceValidator; import org.hl7.fhir.dstu2.model.DateType; import org.hl7.fhir.dstu2.model.Observation; import org.hl7.fhir.dstu2.model.Observation.ObservationStatus; import org.hl7.fhir.dstu2.model.QuestionnaireResponse; import org.hl7.fhir.dstu2.model.QuestionnaireResponse.QuestionnaireResponseStatus; import org.hl7.fhir.dstu2.model.StringType; -import org.hl7.fhir.common.hapi.validation.validator.FhirInstanceValidator; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import java.io.IOException; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.lessThan; import static org.hamcrest.Matchers.not; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; public class FhirInstanceValidatorDstu2Test { @@ -46,7 +46,7 @@ public class FhirInstanceValidatorDstu2Test { private static FhirInstanceValidator ourValidator; private static FhirContext ourCtxHl7OrgDstu2 = FhirContext.forDstu2Hl7Org(); - @BeforeClass + @BeforeAll public static void beforeClass() { DefaultProfileValidationSupport defaultProfileValidationSupport = new DefaultProfileValidationSupport(ourCtxDstu2); IValidationSupport validationSupport = new ValidationSupportChain(defaultProfileValidationSupport, new InMemoryTerminologyServerValidationSupport(ourCtxDstu2)); @@ -173,7 +173,7 @@ public class FhirInstanceValidatorDstu2Test { } @Test - @Ignore + @Disabled public void testParametersWithParameterNoValue() { Parameters input = new Parameters(); input.addParameter().setName("resource"); @@ -192,7 +192,7 @@ public class FhirInstanceValidatorDstu2Test { } @Test - @Ignore + @Disabled public void testParametersWithParameterTwoValues() { Patient patient = new Patient(); patient.addName().addGiven("James"); @@ -258,7 +258,7 @@ public class FhirInstanceValidatorDstu2Test { - @AfterClass + @AfterAll public static void afterClassClearContext() { TestUtil.clearAllStaticFieldsForUnitTest(); } diff --git a/hapi-fhir-validation/src/test/java/org/hl7/fhir/dstu2016may/hapi/validation/ResourceValidatorDstu2_1Test.java b/hapi-fhir-validation/src/test/java/org/hl7/fhir/dstu2016may/hapi/validation/ResourceValidatorDstu2_1Test.java index 5e0c0ee864b..f7830dc08a7 100644 --- a/hapi-fhir-validation/src/test/java/org/hl7/fhir/dstu2016may/hapi/validation/ResourceValidatorDstu2_1Test.java +++ b/hapi-fhir-validation/src/test/java/org/hl7/fhir/dstu2016may/hapi/validation/ResourceValidatorDstu2_1Test.java @@ -11,6 +11,7 @@ import ca.uhn.fhir.validation.ValidationResult; import ca.uhn.fhir.validation.schematron.SchematronBaseValidator; import org.apache.commons.io.IOUtils; import org.hamcrest.core.StringContains; +import org.hl7.fhir.common.hapi.validation.validator.FhirInstanceValidator; import org.hl7.fhir.dstu2016may.model.CodeableConcept; import org.hl7.fhir.dstu2016may.model.Coding; import org.hl7.fhir.dstu2016may.model.DateType; @@ -18,27 +19,26 @@ import org.hl7.fhir.dstu2016may.model.OperationOutcome; import org.hl7.fhir.dstu2016may.model.Patient; import org.hl7.fhir.dstu2016may.model.Reference; import org.hl7.fhir.dstu2016may.model.StringType; -import org.hl7.fhir.common.hapi.validation.validator.FhirInstanceValidator; -import org.junit.AfterClass; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import java.io.IOException; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.stringContainsInOrder; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; public class ResourceValidatorDstu2_1Test { private static FhirContext ourCtx = FhirContext.forDstu2_1(); private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ResourceValidatorDstu2_1Test.class); - @AfterClass + @AfterAll public static void afterClassClearContext() { TestUtil.clearAllStaticFieldsForUnitTest(); @@ -131,7 +131,7 @@ public class ResourceValidatorDstu2_1Test { * Per email from Jon Zammit */ @Test - @Ignore + @Disabled public void testValidateQuestionnaire() throws IOException { String input = IOUtils.toString(getClass().getResourceAsStream("/questionnaire_jon_z_20160506.xml")); diff --git a/hapi-fhir-validation/src/test/java/org/hl7/fhir/dstu3/elementmodel/PropertyDstu3Test.java b/hapi-fhir-validation/src/test/java/org/hl7/fhir/dstu3/elementmodel/PropertyDstu3Test.java index a3c120bb395..d19e442503c 100644 --- a/hapi-fhir-validation/src/test/java/org/hl7/fhir/dstu3/elementmodel/PropertyDstu3Test.java +++ b/hapi-fhir-validation/src/test/java/org/hl7/fhir/dstu3/elementmodel/PropertyDstu3Test.java @@ -1,22 +1,23 @@ package org.hl7.fhir.dstu3.elementmodel; import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.context.support.DefaultProfileValidationSupport; import ca.uhn.fhir.parser.IParser; import org.apache.commons.io.IOUtils; -import ca.uhn.fhir.context.support.DefaultProfileValidationSupport; import org.hl7.fhir.dstu3.hapi.ctx.HapiWorkerContext; import org.hl7.fhir.dstu3.model.ElementDefinition; import org.hl7.fhir.dstu3.model.StructureDefinition; import org.hl7.fhir.exceptions.DefinitionException; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.io.IOException; import java.nio.charset.StandardCharsets; import java.util.List; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.fail; /** * Created by axemj on 14/07/2017. @@ -28,7 +29,7 @@ public class PropertyDstu3Test { private StructureDefinition sd; private HapiWorkerContext workerContext; - @Before + @BeforeEach public void setUp() throws IOException { final String sdString = IOUtils.toString(getClass().getResourceAsStream("/customPatientSd.xml"), StandardCharsets.UTF_8); final IParser parser = ourCtx.newXmlParser(); @@ -56,10 +57,15 @@ public class PropertyDstu3Test { assertEquals("date.id", result.get(0).getDefinition().getPath()); } - @Test(expected = Error.class) + @Test public void getChildPropertiesErrorTest() throws DefinitionException { - final ElementDefinition ed = sd.getSnapshot().getElement().get(7); - property = new Property(workerContext, ed, sd); - property.getChildProperties("birthdate", null); + try { + final ElementDefinition ed = sd.getSnapshot().getElement().get(7); + property = new Property(workerContext, ed, sd); + property.getChildProperties("birthdate", null); + fail(); + } catch (Error e) { + assertEquals("types == 0, and no children found", e.getMessage()); + } } } diff --git a/hapi-fhir-validation/src/test/java/org/hl7/fhir/dstu3/hapi/validation/DefaultProfileValidationSupportTest.java b/hapi-fhir-validation/src/test/java/org/hl7/fhir/dstu3/hapi/validation/DefaultProfileValidationSupportTest.java index e0ef7011fa4..a5141b3ead7 100644 --- a/hapi-fhir-validation/src/test/java/org/hl7/fhir/dstu3/hapi/validation/DefaultProfileValidationSupportTest.java +++ b/hapi-fhir-validation/src/test/java/org/hl7/fhir/dstu3/hapi/validation/DefaultProfileValidationSupportTest.java @@ -1,13 +1,13 @@ package org.hl7.fhir.dstu3.hapi.validation; import ca.uhn.fhir.context.FhirContext; -import ca.uhn.fhir.util.TestUtil; import ca.uhn.fhir.context.support.DefaultProfileValidationSupport; -import org.junit.AfterClass; -import org.junit.Test; +import ca.uhn.fhir.util.TestUtil; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; public class DefaultProfileValidationSupportTest { @@ -27,7 +27,7 @@ public class DefaultProfileValidationSupportTest { } - @AfterClass + @AfterAll public static void afterClassClearContext() { TestUtil.clearAllStaticFieldsForUnitTest(); } diff --git a/hapi-fhir-validation/src/test/java/org/hl7/fhir/dstu3/hapi/validation/FhirInstanceValidatorDstu3Test.java b/hapi-fhir-validation/src/test/java/org/hl7/fhir/dstu3/hapi/validation/FhirInstanceValidatorDstu3Test.java index 31a29620d15..2ef95f7e14b 100644 --- a/hapi-fhir-validation/src/test/java/org/hl7/fhir/dstu3/hapi/validation/FhirInstanceValidatorDstu3Test.java +++ b/hapi-fhir-validation/src/test/java/org/hl7/fhir/dstu3/hapi/validation/FhirInstanceValidatorDstu3Test.java @@ -5,6 +5,7 @@ import ca.uhn.fhir.context.support.ConceptValidationOptions; import ca.uhn.fhir.context.support.IValidationSupport; import ca.uhn.fhir.context.support.ValidationSupportContext; import ca.uhn.fhir.context.support.ValueSetExpansionOptions; +import ca.uhn.fhir.test.utilities.LoggingExtension; import ca.uhn.fhir.util.TestUtil; import ca.uhn.fhir.validation.FhirValidator; import ca.uhn.fhir.validation.ResultSeverityEnum; @@ -17,29 +18,49 @@ import org.hl7.fhir.common.hapi.validation.support.CommonCodeSystemsTerminologyS import org.hl7.fhir.common.hapi.validation.support.InMemoryTerminologyServerValidationSupport; import org.hl7.fhir.common.hapi.validation.support.SnapshotGeneratingValidationSupport; import org.hl7.fhir.common.hapi.validation.support.ValidationSupportChain; +import org.hl7.fhir.common.hapi.validation.validator.FhirInstanceValidator; import org.hl7.fhir.dstu3.hapi.ctx.HapiWorkerContext; -import org.hl7.fhir.dstu3.model.*; +import org.hl7.fhir.dstu3.model.Base; +import org.hl7.fhir.dstu3.model.BooleanType; +import org.hl7.fhir.dstu3.model.Bundle; import org.hl7.fhir.dstu3.model.Bundle.BundleEntryComponent; +import org.hl7.fhir.dstu3.model.CodeSystem; import org.hl7.fhir.dstu3.model.CodeSystem.ConceptDefinitionComponent; +import org.hl7.fhir.dstu3.model.CodeType; +import org.hl7.fhir.dstu3.model.CodeableConcept; +import org.hl7.fhir.dstu3.model.Coding; +import org.hl7.fhir.dstu3.model.ContactPoint; +import org.hl7.fhir.dstu3.model.DateTimeType; import org.hl7.fhir.dstu3.model.Enumerations.PublicationStatus; +import org.hl7.fhir.dstu3.model.Extension; +import org.hl7.fhir.dstu3.model.Goal; +import org.hl7.fhir.dstu3.model.ImagingStudy; +import org.hl7.fhir.dstu3.model.Observation; import org.hl7.fhir.dstu3.model.Observation.ObservationStatus; +import org.hl7.fhir.dstu3.model.Patient; +import org.hl7.fhir.dstu3.model.Period; +import org.hl7.fhir.dstu3.model.Procedure; +import org.hl7.fhir.dstu3.model.Questionnaire; import org.hl7.fhir.dstu3.model.Questionnaire.QuestionnaireItemComponent; import org.hl7.fhir.dstu3.model.Questionnaire.QuestionnaireItemType; +import org.hl7.fhir.dstu3.model.QuestionnaireResponse; +import org.hl7.fhir.dstu3.model.Reference; +import org.hl7.fhir.dstu3.model.RelatedPerson; +import org.hl7.fhir.dstu3.model.StringType; +import org.hl7.fhir.dstu3.model.StructureDefinition; import org.hl7.fhir.dstu3.model.StructureDefinition.StructureDefinitionKind; +import org.hl7.fhir.dstu3.model.ValueSet; import org.hl7.fhir.dstu3.model.ValueSet.ValueSetExpansionComponent; import org.hl7.fhir.dstu3.utils.FHIRPathEngine; import org.hl7.fhir.instance.model.api.IBaseResource; -import org.hl7.fhir.common.hapi.validation.validator.FhirInstanceValidator; import org.hl7.fhir.r5.utils.IResourceValidator; import org.hl7.fhir.utilities.validation.ValidationMessage; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TestRule; -import org.junit.rules.TestWatcher; -import org.junit.runner.Description; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; +import org.junit.jupiter.api.extension.TestWatcher; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; @@ -57,18 +78,18 @@ import java.util.TreeSet; import java.util.stream.Collectors; import java.util.zip.GZIPInputStream; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.greaterThan; import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.lessThan; import static org.hamcrest.Matchers.not; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.nullable; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.anyString; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; @@ -80,13 +101,8 @@ public class FhirInstanceValidatorDstu3Test { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirInstanceValidatorDstu3Test.class); private static FhirContext ourCtx = FhirContext.forDstu3(); private static IValidationSupport myDefaultValidationSupport = ourCtx.getValidationSupport(); - @Rule - public TestRule watcher = new TestWatcher() { - @Override - protected void starting(Description description) { - ourLog.info("Starting test: " + description.getMethodName()); - } - }; + @RegisterExtension + public LoggingExtension myLoggingExtension = new LoggingExtension(); private FhirInstanceValidator myInstanceVal; private Map mySupportedCodeSystemsForExpansion; private FhirValidator myVal; @@ -104,7 +120,7 @@ public class FhirInstanceValidatorDstu3Test { } @SuppressWarnings("unchecked") - @Before + @BeforeEach public void before() { myVal = ourCtx.newValidator(); myVal.setValidateAgainstStandardSchema(false); @@ -564,7 +580,7 @@ public class FhirInstanceValidatorDstu3Test { } @Test - // @Ignore + // @Disabled public void testValidateBuiltInProfiles() throws Exception { org.hl7.fhir.dstu3.model.Bundle bundle; String name = "profiles-resources"; @@ -595,7 +611,7 @@ public class FhirInstanceValidatorDstu3Test { errors = errors .stream() - .filter(t->{ + .filter(t -> { if (t.getLocationString().contains("example")) { ourLog.warn("Ignoring error in example path: {}", t); return false; @@ -603,7 +619,8 @@ public class FhirInstanceValidatorDstu3Test { return true; } }) - .collect(Collectors.toList());; + .collect(Collectors.toList()); + ; assertThat("Failed to validate " + i.getFullUrl() + " - " + errors, errors, empty()); @@ -622,7 +639,7 @@ public class FhirInstanceValidatorDstu3Test { } @Test - @Ignore + @Disabled public void testValidateBundleWithObservations() throws Exception { String name = "profiles-resources"; ourLog.info("Uploading " + name); @@ -762,7 +779,7 @@ public class FhirInstanceValidatorDstu3Test { //@formatter:on ValidationResult output = myVal.validateWithResult(input); - assertEquals(output.toString(), 0, output.getMessages().size()); + assertEquals(0, output.getMessages().size(), output.toString()); } @Test @@ -777,7 +794,7 @@ public class FhirInstanceValidatorDstu3Test { //@formatter:on ValidationResult output = myVal.validateWithResult(input); - assertEquals(output.toString(), 1, output.getMessages().size()); + assertEquals(1, output.getMessages().size(), output.toString()); ourLog.info(output.getMessages().get(0).getLocationString()); ourLog.info(output.getMessages().get(0).getMessage()); assertEquals("Patient", output.getMessages().get(0).getLocationString()); @@ -826,7 +843,7 @@ public class FhirInstanceValidatorDstu3Test { */ ValidationResult output = myVal.validateWithResult(encoded); - assertEquals(output.toString(), 1, output.getMessages().size()); + assertEquals(1, output.getMessages().size(), output.toString()); assertEquals("Unknown extension http://hl7.org/fhir/v3/ethnicity", output.getMessages().get(0).getMessage()); assertEquals(ResultSeverityEnum.INFORMATION, output.getMessages().get(0).getSeverity()); @@ -860,7 +877,7 @@ public class FhirInstanceValidatorDstu3Test { myInstanceVal.setAnyExtensionsAllowed(false); ValidationResult output = myVal.validateWithResult(encoded); - assertEquals(output.toString(), 1, output.getMessages().size()); + assertEquals(1, output.getMessages().size(), output.toString()); assertEquals("The extension http://hl7.org/fhir/v3/ethnicity is unknown, and not allowed here", output.getMessages().get(0).getMessage()); assertEquals(ResultSeverityEnum.ERROR, output.getMessages().get(0).getSeverity()); @@ -873,7 +890,7 @@ public class FhirInstanceValidatorDstu3Test { // @formatter:on ValidationResult output = myVal.validateWithResult(input); - assertEquals(output.toString(), 0, output.getMessages().size()); + assertEquals(0, output.getMessages().size(), output.toString()); } @Test @@ -884,7 +901,7 @@ public class FhirInstanceValidatorDstu3Test { //@formatter:on ValidationResult output = myVal.validateWithResult(input); - assertEquals(output.toString(), 1, output.getMessages().size()); + assertEquals(1, output.getMessages().size(), output.toString()); ourLog.info(output.getMessages().get(0).getLocationString()); ourLog.info(output.getMessages().get(0).getMessage()); assertEquals("/f:Patient", output.getMessages().get(0).getLocationString()); @@ -897,7 +914,7 @@ public class FhirInstanceValidatorDstu3Test { ValidationResult output = myVal.validateWithResult(input); ourLog.info(ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(output.toOperationOutcome())); - assertEquals(output.toString(), 3, output.getMessages().size()); + assertEquals(3, output.getMessages().size(), output.toString()); assertThat(output.getMessages().get(0).getMessage(), containsString("Element must have some content")); assertThat(output.getMessages().get(1).getMessage(), containsString("Primitive types must have a value or must have child extensions")); } @@ -929,7 +946,7 @@ public class FhirInstanceValidatorDstu3Test { ValidationResult output = myVal.validateWithResult(input); List res = logResultsAndReturnNonInformationalOnes(output); - assertEquals(output.toString(), 1, res.size()); + assertEquals(1, res.size(), output.toString()); assertEquals("A code with no system has no defined meaning. A system should be provided", output.getMessages().get(0).getMessage()); } @@ -1116,7 +1133,7 @@ public class FhirInstanceValidatorDstu3Test { ValidationResult output = myVal.validateWithResult(input); List errors = logResultsAndReturnNonInformationalOnes(output); - assertEquals(errors.toString(), 0, errors.size()); + assertEquals(0, errors.size(), errors.toString()); } @@ -1149,7 +1166,7 @@ public class FhirInstanceValidatorDstu3Test { ValidationResult output = myVal.validateWithResult(input); List errors = logResultsAndReturnNonInformationalOnes(output); - assertEquals(errors.toString(), 0, errors.size()); + assertEquals(0, errors.size(), errors.toString()); } @Test @@ -1184,7 +1201,7 @@ public class FhirInstanceValidatorDstu3Test { ValidationResult output = myVal.validateWithResult(input); List errors = logResultsAndReturnAll(output); - assertEquals(errors.toString(), 0, errors.size()); + assertEquals(0, errors.size(), errors.toString()); } @Test @@ -1215,14 +1232,14 @@ public class FhirInstanceValidatorDstu3Test { } @Test - @Ignore + @Disabled public void testValidateStructureDefinition() throws IOException { String input = loadResource("/sdc-questionnaire.profile.xml"); ValidationResult output = myVal.validateWithResult(input); logResultsAndReturnAll(output); - assertEquals(output.toString(), 3, output.getMessages().size()); + assertEquals(3, output.getMessages().size(), output.toString()); ourLog.info(output.getMessages().get(0).getLocationString()); ourLog.info(output.getMessages().get(0).getMessage()); } @@ -1252,7 +1269,7 @@ public class FhirInstanceValidatorDstu3Test { } - @AfterClass + @AfterAll public static void afterClassClearContext() { myDefaultValidationSupport = null; ourCtx = null; diff --git a/hapi-fhir-validation/src/test/java/org/hl7/fhir/dstu3/hapi/validation/QuestionnaireResponseValidatorDstu3Test.java b/hapi-fhir-validation/src/test/java/org/hl7/fhir/dstu3/hapi/validation/QuestionnaireResponseValidatorDstu3Test.java index f1229ac6283..f43eed73003 100644 --- a/hapi-fhir-validation/src/test/java/org/hl7/fhir/dstu3/hapi/validation/QuestionnaireResponseValidatorDstu3Test.java +++ b/hapi-fhir-validation/src/test/java/org/hl7/fhir/dstu3/hapi/validation/QuestionnaireResponseValidatorDstu3Test.java @@ -13,6 +13,7 @@ import org.hamcrest.Matchers; import org.hl7.fhir.common.hapi.validation.support.CommonCodeSystemsTerminologyService; import org.hl7.fhir.common.hapi.validation.support.InMemoryTerminologyServerValidationSupport; import org.hl7.fhir.common.hapi.validation.support.ValidationSupportChain; +import org.hl7.fhir.common.hapi.validation.validator.FhirInstanceValidator; import org.hl7.fhir.dstu3.model.*; import org.hl7.fhir.dstu3.model.CodeSystem.CodeSystemContentMode; import org.hl7.fhir.dstu3.model.Questionnaire.QuestionnaireItemComponent; @@ -23,27 +24,26 @@ import org.hl7.fhir.dstu3.model.QuestionnaireResponse.QuestionnaireResponseItemA import org.hl7.fhir.dstu3.model.QuestionnaireResponse.QuestionnaireResponseItemComponent; import org.hl7.fhir.dstu3.model.QuestionnaireResponse.QuestionnaireResponseStatus; import org.hl7.fhir.instance.model.api.IBaseResource; -import org.hl7.fhir.common.hapi.validation.validator.FhirInstanceValidator; import org.hl7.fhir.utilities.validation.ValidationMessage; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.util.ArrayList; import java.util.Collections; import java.util.Date; import java.util.List; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.hasSize; import static org.hl7.fhir.dstu3.model.Questionnaire.QuestionnaireItemType.BOOLEAN; import static org.hl7.fhir.dstu3.model.Questionnaire.QuestionnaireItemType.CHOICE; import static org.hl7.fhir.dstu3.model.QuestionnaireResponse.QuestionnaireResponseStatus.COMPLETED; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.anyString; @@ -65,7 +65,7 @@ public class QuestionnaireResponseValidatorDstu3Test { private FhirValidator myVal; private IValidationSupport myValSupport; - @Before + @BeforeEach public void before() { myValSupport = mock(IValidationSupport.class); when(myValSupport.getFhirContext()).thenReturn(ourCtx); @@ -243,7 +243,7 @@ public class QuestionnaireResponseValidatorDstu3Test { qa.addItem().setLinkId("link0").addAnswer().setValue(new Coding().setSystem("http://codesystems.com/system").setCode("code0")); errors = myVal.validateWithResult(qa); errors = stripBindingHasNoSourceMessage(errors); - assertEquals(errors.toString(), 0, errors.getMessages().size()); + assertEquals(0, errors.getMessages().size(), errors.toString()); // Bad code @@ -693,9 +693,9 @@ public class QuestionnaireResponseValidatorDstu3Test { ValidationResult errors = myVal.validateWithResult(qr); assertThat(errors.toString(), Matchers.not(containsString("No issues"))); - assertTrue("Must contain structural error about misplaced link1 item", + assertTrue( errors.getMessages().stream().filter(vm -> vm.getMessage().contains("Structural Error")) - .anyMatch(vm -> vm.getMessage().contains("link1"))); + .anyMatch(vm -> vm.getMessage().contains("link1")), "Must contain structural error about misplaced link1 item"); } @Test @@ -1051,7 +1051,7 @@ public class QuestionnaireResponseValidatorDstu3Test { qa.addItem().setLinkId("link0").addAnswer().setValue(new Coding().setSystem("http://codesystems.com/system").setCode("code0")); errors = myVal.validateWithResult(qa); errors = stripBindingHasNoSourceMessage(errors); - assertEquals(errors.toString(), 0, errors.getMessages().size()); + assertEquals(0, errors.getMessages().size(), errors.toString()); // Bad code @@ -1169,12 +1169,12 @@ public class QuestionnaireResponseValidatorDstu3Test { assertThat(errors.toString(), containsString("LinkId \"link1\" not found in questionnaire")); } - @BeforeClass + @BeforeAll public static void beforeClass() { ourCtx = FhirContext.forDstu3(); } - @AfterClass + @AfterAll public static void afterClassClearContext() { myDefaultValidationSupport.flush(); myDefaultValidationSupport = null; diff --git a/hapi-fhir-validation/src/test/java/org/hl7/fhir/dstu3/hapi/validation/QuestionnaireValidatorDstu3Test.java b/hapi-fhir-validation/src/test/java/org/hl7/fhir/dstu3/hapi/validation/QuestionnaireValidatorDstu3Test.java index eda9684c3ef..878bbf0ba78 100644 --- a/hapi-fhir-validation/src/test/java/org/hl7/fhir/dstu3/hapi/validation/QuestionnaireValidatorDstu3Test.java +++ b/hapi-fhir-validation/src/test/java/org/hl7/fhir/dstu3/hapi/validation/QuestionnaireValidatorDstu3Test.java @@ -17,9 +17,9 @@ import org.hl7.fhir.dstu3.model.Coding; import org.hl7.fhir.dstu3.model.Enumerations.PublicationStatus; import org.hl7.fhir.dstu3.model.Questionnaire; import org.hl7.fhir.dstu3.model.Questionnaire.QuestionnaireItemType; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -27,8 +27,8 @@ import java.util.Collections; import java.util.stream.Collectors; import static org.hamcrest.CoreMatchers.containsString; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -39,7 +39,7 @@ public class QuestionnaireValidatorDstu3Test { private FhirInstanceValidator myInstanceVal; private FhirValidator myVal; - @Before + @BeforeEach public void before() { @@ -150,7 +150,7 @@ public class QuestionnaireValidatorDstu3Test { assertThat(errors.getMessages(), Matchers.empty()); } - @AfterClass + @AfterAll public static void afterClassClearContext() { myDefaultValidationSupport.flush(); myDefaultValidationSupport = null; diff --git a/hapi-fhir-validation/src/test/java/org/hl7/fhir/dstu3/hapi/validation/ResourceValidatorDstu3Test.java b/hapi-fhir-validation/src/test/java/org/hl7/fhir/dstu3/hapi/validation/ResourceValidatorDstu3Test.java index b707c1926d0..7958259ec34 100644 --- a/hapi-fhir-validation/src/test/java/org/hl7/fhir/dstu3/hapi/validation/ResourceValidatorDstu3Test.java +++ b/hapi-fhir-validation/src/test/java/org/hl7/fhir/dstu3/hapi/validation/ResourceValidatorDstu3Test.java @@ -19,6 +19,7 @@ import org.apache.commons.lang3.Validate; import org.hamcrest.core.StringContains; import org.hl7.fhir.common.hapi.validation.support.PrePopulatedValidationSupport; import org.hl7.fhir.common.hapi.validation.support.ValidationSupportChain; +import org.hl7.fhir.common.hapi.validation.validator.FhirInstanceValidator; import org.hl7.fhir.dstu3.conformance.ProfileUtilities; import org.hl7.fhir.dstu3.context.IWorkerContext; import org.hl7.fhir.dstu3.hapi.ctx.HapiWorkerContext; @@ -28,11 +29,10 @@ import org.hl7.fhir.dstu3.model.Condition.ConditionVerificationStatus; import org.hl7.fhir.dstu3.model.EligibilityResponse.BenefitComponent; import org.hl7.fhir.dstu3.model.Narrative.NarrativeStatus; import org.hl7.fhir.exceptions.FHIRException; -import org.hl7.fhir.common.hapi.validation.validator.FhirInstanceValidator; import org.hl7.fhir.utilities.validation.ValidationMessage; -import org.junit.AfterClass; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import java.io.IOException; import java.nio.charset.StandardCharsets; @@ -40,13 +40,13 @@ import java.util.ArrayList; import java.util.Date; import java.util.List; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.stringContainsInOrder; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; public class ResourceValidatorDstu3Test { @@ -103,7 +103,7 @@ public class ResourceValidatorDstu3Test { } @Test - @Ignore + @Disabled public void testValidateCareTeamProfile() { CareTeam careTeam = new CareTeam(); @@ -186,7 +186,7 @@ public class ResourceValidatorDstu3Test { } @Test - @Ignore + @Disabled public void testValidateProfileWithExtension() throws IOException, FHIRException { PrePopulatedValidationSupport valSupport = new PrePopulatedValidationSupport(ourCtx); DefaultProfileValidationSupport defaultSupport = new DefaultProfileValidationSupport(ourCtx); @@ -223,7 +223,7 @@ public class ResourceValidatorDstu3Test { @Test - @Ignore + @Disabled public void testValidateDifferentPropertyButSameStartsWithPath() throws Exception { EligibilityResponse fhirObj = new EligibilityResponse(); @@ -280,7 +280,7 @@ public class ResourceValidatorDstu3Test { * Per email from Jon Zammit */ @Test - @Ignore + @Disabled public void testValidateQuestionnaire() throws IOException { String input = IOUtils.toString(getClass().getResourceAsStream("/questionnaire_jon_z_20160506.xml"), StandardCharsets.UTF_8); @@ -479,7 +479,7 @@ public class ResourceValidatorDstu3Test { assertThat(messageString, not(containsString("valueResource"))); } - @AfterClass + @AfterAll public static void afterClassClearContext() { TestUtil.clearAllStaticFieldsForUnitTest(); } diff --git a/hapi-fhir-validation/src/test/java/org/hl7/fhir/dstu3/hapi/validation/SchemaValidationDstu3Test.java b/hapi-fhir-validation/src/test/java/org/hl7/fhir/dstu3/hapi/validation/SchemaValidationDstu3Test.java index 3f243e8e48d..a87dd300e02 100644 --- a/hapi-fhir-validation/src/test/java/org/hl7/fhir/dstu3/hapi/validation/SchemaValidationDstu3Test.java +++ b/hapi-fhir-validation/src/test/java/org/hl7/fhir/dstu3/hapi/validation/SchemaValidationDstu3Test.java @@ -1,16 +1,15 @@ package org.hl7.fhir.dstu3.hapi.validation; -import static org.hamcrest.Matchers.containsString; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertThat; - -import ca.uhn.fhir.validation.FhirValidator; -import ca.uhn.fhir.validation.ValidationResult; -import org.junit.AfterClass; -import org.junit.Test; - import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.util.TestUtil; +import ca.uhn.fhir.validation.FhirValidator; +import ca.uhn.fhir.validation.ValidationResult; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsString; +import static org.junit.jupiter.api.Assertions.assertFalse; public class SchemaValidationDstu3Test { @@ -55,7 +54,7 @@ public class SchemaValidationDstu3Test { assertThat(encoded, containsString("accessExternalDTD")); } - @AfterClass + @AfterAll public static void afterClassClearContext() { TestUtil.clearAllStaticFieldsForUnitTest(); } diff --git a/hapi-fhir-validation/src/test/java/org/hl7/fhir/dstu3/hapi/validation/SchematronValidationDstu3QuestionnaireTest.java b/hapi-fhir-validation/src/test/java/org/hl7/fhir/dstu3/hapi/validation/SchematronValidationDstu3QuestionnaireTest.java index f8438f4e4bc..228ac642bb1 100644 --- a/hapi-fhir-validation/src/test/java/org/hl7/fhir/dstu3/hapi/validation/SchematronValidationDstu3QuestionnaireTest.java +++ b/hapi-fhir-validation/src/test/java/org/hl7/fhir/dstu3/hapi/validation/SchematronValidationDstu3QuestionnaireTest.java @@ -1,11 +1,5 @@ package org.hl7.fhir.dstu3.hapi.validation; -import static org.hamcrest.Matchers.containsString; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; - import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.util.TestUtil; import ca.uhn.fhir.validation.FhirValidator; @@ -16,12 +10,17 @@ import org.hl7.fhir.dstu3.model.Questionnaire.QuestionnaireItemComponent; import org.hl7.fhir.dstu3.model.Questionnaire.QuestionnaireItemEnableWhenComponent; import org.hl7.fhir.dstu3.model.Questionnaire.QuestionnaireItemType; import org.hl7.fhir.dstu3.model.StringType; - -import org.junit.AfterClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsString; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + public class SchematronValidationDstu3QuestionnaireTest { private static final Logger ourLog = LoggerFactory.getLogger(SchematronValidationDstu3QuestionnaireTest.class); @@ -119,7 +118,7 @@ public class SchematronValidationDstu3QuestionnaireTest { return result; } - @AfterClass + @AfterAll public static void afterClassClearContext() { TestUtil.clearAllStaticFieldsForUnitTest(); } diff --git a/hapi-fhir-validation/src/test/java/org/hl7/fhir/dstu3/hapi/validation/StructureMapTest.java b/hapi-fhir-validation/src/test/java/org/hl7/fhir/dstu3/hapi/validation/StructureMapTest.java index 8d28d47c0c3..914d9e69381 100644 --- a/hapi-fhir-validation/src/test/java/org/hl7/fhir/dstu3/hapi/validation/StructureMapTest.java +++ b/hapi-fhir-validation/src/test/java/org/hl7/fhir/dstu3/hapi/validation/StructureMapTest.java @@ -8,8 +8,8 @@ import org.hl7.fhir.dstu3.context.IWorkerContext; import org.hl7.fhir.dstu3.hapi.ctx.HapiWorkerContext; import org.hl7.fhir.dstu3.model.*; import org.hl7.fhir.dstu3.utils.StructureMapUtilities; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import javax.annotation.Nullable; import java.util.ArrayList; @@ -18,7 +18,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public class StructureMapTest { @@ -265,7 +265,7 @@ public class StructureMapTest { /** * Sets up the resource paths as well as create the contexts using a defalut validator to start with. */ - @Before + @BeforeEach public void setUp() { if (this.myCtx == null) { this.myCtx = FhirContext.forDstu3(); diff --git a/hapi-fhir-validation/src/test/java/org/hl7/fhir/dstu3/utils/FhirPathEngineTest.java b/hapi-fhir-validation/src/test/java/org/hl7/fhir/dstu3/utils/FhirPathEngineTest.java index 68c7084dc90..974eeee237f 100644 --- a/hapi-fhir-validation/src/test/java/org/hl7/fhir/dstu3/utils/FhirPathEngineTest.java +++ b/hapi-fhir-validation/src/test/java/org/hl7/fhir/dstu3/utils/FhirPathEngineTest.java @@ -1,8 +1,8 @@ package org.hl7.fhir.dstu3.utils; import ca.uhn.fhir.context.FhirContext; -import ca.uhn.fhir.util.TestUtil; import ca.uhn.fhir.context.support.DefaultProfileValidationSupport; +import ca.uhn.fhir.util.TestUtil; import org.hl7.fhir.dstu3.hapi.ctx.HapiWorkerContext; import org.hl7.fhir.dstu3.model.Base; import org.hl7.fhir.dstu3.model.BooleanType; @@ -13,15 +13,15 @@ import org.hl7.fhir.dstu3.model.Reference; import org.hl7.fhir.dstu3.model.Specimen; import org.hl7.fhir.dstu3.model.StringType; import org.hl7.fhir.exceptions.FHIRException; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import java.util.List; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; public class FhirPathEngineTest { @@ -74,12 +74,12 @@ public class FhirPathEngineTest { assertTrue(((BooleanType) eval.get(0)).getValue()); } - @AfterClass + @AfterAll public static void afterClassClearContext() { TestUtil.clearAllStaticFieldsForUnitTest(); } - @BeforeClass + @BeforeAll public static void beforeClass() { ourEngine = new FHIRPathEngine(new HapiWorkerContext(ourCtx, new DefaultProfileValidationSupport(ourCtx))); } diff --git a/hapi-fhir-validation/src/test/java/org/hl7/fhir/r4/utils/FhirPathEngineR4Test.java b/hapi-fhir-validation/src/test/java/org/hl7/fhir/r4/utils/FhirPathEngineR4Test.java index 9e7256803d6..89bc5565ba3 100644 --- a/hapi-fhir-validation/src/test/java/org/hl7/fhir/r4/utils/FhirPathEngineR4Test.java +++ b/hapi-fhir-validation/src/test/java/org/hl7/fhir/r4/utils/FhirPathEngineR4Test.java @@ -1,20 +1,22 @@ package org.hl7.fhir.r4.utils; import ca.uhn.fhir.context.FhirContext; +import ca.uhn.fhir.context.support.DefaultProfileValidationSupport; import ca.uhn.fhir.parser.IParser; import ca.uhn.fhir.util.TestUtil; import org.hl7.fhir.dstu3.utils.FhirPathEngineTest; import org.hl7.fhir.exceptions.FHIRException; -import ca.uhn.fhir.context.support.DefaultProfileValidationSupport; import org.hl7.fhir.r4.hapi.ctx.HapiWorkerContext; import org.hl7.fhir.r4.model.*; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import java.util.List; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; public class FhirPathEngineR4Test { @@ -157,12 +159,12 @@ public class FhirPathEngineR4Test { } - @AfterClass + @AfterAll public static void afterClassClearContext() throws Exception { TestUtil.clearAllStaticFieldsForUnitTest(); } - @BeforeClass + @BeforeAll public static void beforeClass() { ourEngine = new FHIRPathEngine(new HapiWorkerContext(ourCtx, new DefaultProfileValidationSupport(ourCtx))); } diff --git a/hapi-fhir-validation/src/test/java/org/hl7/fhir/r4/validation/CustomResourceGenerationTest.java b/hapi-fhir-validation/src/test/java/org/hl7/fhir/r4/validation/CustomResourceGenerationTest.java index 99b48c10d8e..08ae220db02 100644 --- a/hapi-fhir-validation/src/test/java/org/hl7/fhir/r4/validation/CustomResourceGenerationTest.java +++ b/hapi-fhir-validation/src/test/java/org/hl7/fhir/r4/validation/CustomResourceGenerationTest.java @@ -9,13 +9,13 @@ import org.hl7.fhir.common.hapi.validation.support.PrePopulatedValidationSupport import org.hl7.fhir.common.hapi.validation.support.ValidationSupportChain; import org.hl7.fhir.common.hapi.validation.validator.FhirInstanceValidator; import org.hl7.fhir.r4.model.StructureDefinition; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.IOException; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public class CustomResourceGenerationTest extends BaseTest { diff --git a/hapi-fhir-validation/src/test/java/org/hl7/fhir/r4/validation/FhirInstanceValidatorR4Test.java b/hapi-fhir-validation/src/test/java/org/hl7/fhir/r4/validation/FhirInstanceValidatorR4Test.java index 503a60d3a8e..74fe228f574 100644 --- a/hapi-fhir-validation/src/test/java/org/hl7/fhir/r4/validation/FhirInstanceValidatorR4Test.java +++ b/hapi-fhir-validation/src/test/java/org/hl7/fhir/r4/validation/FhirInstanceValidatorR4Test.java @@ -8,6 +8,7 @@ import ca.uhn.fhir.context.support.ValidationSupportContext; import ca.uhn.fhir.context.support.ValueSetExpansionOptions; import ca.uhn.fhir.rest.api.Constants; import ca.uhn.fhir.test.BaseTest; +import ca.uhn.fhir.test.utilities.LoggingExtension; import ca.uhn.fhir.util.TestUtil; import ca.uhn.fhir.validation.FhirValidator; import ca.uhn.fhir.validation.ResultSeverityEnum; @@ -62,14 +63,11 @@ import org.hl7.fhir.r4.utils.FHIRPathEngine; import org.hl7.fhir.r5.utils.IResourceValidator; import org.hl7.fhir.utilities.validation.ValidationMessage; import org.hl7.fhir.utilities.xhtml.XhtmlNode; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TestRule; -import org.junit.rules.TestWatcher; -import org.junit.runner.Description; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; @@ -83,16 +81,16 @@ import java.util.Set; import java.util.TreeSet; import java.util.stream.Collectors; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.greaterThan; import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.lessThan; import static org.hamcrest.Matchers.not; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.nullable; @@ -106,13 +104,8 @@ public class FhirInstanceValidatorR4Test extends BaseTest { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirInstanceValidatorR4Test.class); private static FhirContext ourCtx = FhirContext.forR4(); private static DefaultProfileValidationSupport myDefaultValidationSupport = new DefaultProfileValidationSupport(ourCtx); - @Rule - public TestRule watcher = new TestWatcher() { - @Override - protected void starting(Description description) { - ourLog.info("Starting test: " + description.getMethodName()); - } - }; + @RegisterExtension + public LoggingExtension myLoggingExtension = new LoggingExtension(); private FhirInstanceValidator myInstanceVal; private Map mySupportedCodeSystemsForExpansion; private FhirValidator myVal; @@ -143,7 +136,7 @@ public class FhirInstanceValidatorR4Test extends BaseTest { } @SuppressWarnings("unchecked") - @Before + @BeforeEach public void before() { myVal = ourCtx.newValidator(); myVal.setValidateAgainstStandardSchema(false); @@ -255,7 +248,7 @@ public class FhirInstanceValidatorR4Test extends BaseTest { when(mockSupport.fetchAllStructureDefinitions()).thenAnswer(new Answer>() { @Override public List answer(InvocationOnMock theInvocation) { - List retVal =new ArrayList<>(myDefaultValidationSupport.fetchAllStructureDefinitions()); + List retVal = new ArrayList<>(myDefaultValidationSupport.fetchAllStructureDefinitions()); retVal.addAll(myStructureDefinitionMap.values()); ourLog.debug("fetchAllStructureDefinitions()", new Object[]{}); return retVal; @@ -409,7 +402,6 @@ public class FhirInstanceValidatorR4Test extends BaseTest { * TODO: unignore when https://github.com/hapifhir/org.hl7.fhir.core/pull/201 is merged */ @Test - @Ignore public void testValidateFixedBindingOnQuantity() throws IOException { StructureDefinition sd = loadResource(ourCtx, StructureDefinition.class, "/r4/bbl-fixed-binding-structuredef.json"); myStructureDefinitionMap.put("http://example.org/fhir/StructureDefinition/MyObservation", sd); @@ -640,7 +632,7 @@ public class FhirInstanceValidatorR4Test extends BaseTest { } @Test - @Ignore + @Disabled public void testValidateBigRawJsonResource() throws Exception { String input = super.loadCompressedResource("/conformance.json.gz"); @@ -661,7 +653,7 @@ public class FhirInstanceValidatorR4Test extends BaseTest { } @Test - @Ignore + @Disabled public void testValidateBuiltInProfiles() throws Exception { org.hl7.fhir.r4.model.Bundle bundle; String name = "profiles-resources"; @@ -737,7 +729,7 @@ public class FhirInstanceValidatorR4Test extends BaseTest { } @Test - @Ignore + @Disabled public void testValidateBundleWithObservations() throws Exception { String name = "profiles-resources"; ourLog.info("Uploading " + name); @@ -766,7 +758,7 @@ public class FhirInstanceValidatorR4Test extends BaseTest { } @Test - @Ignore + @Disabled public void testValidateDocument() throws Exception { String vsContents = loadResource("/sample-document.xml"); @@ -805,7 +797,7 @@ public class FhirInstanceValidatorR4Test extends BaseTest { // Should pass ValidationResult output = val.validateWithResult(input); List all = logResultsAndReturnErrorOnes(output); - assertEquals(all.toString(), 0, all.size()); + assertEquals(0, all.size(), all.toString()); // Now with the wrong datatype input.getExtensionsByUrl("http://hl7.org/fhir/StructureDefinition/PruebaExtension").get(0).setValue(new CodeType("AAA")); @@ -818,7 +810,7 @@ public class FhirInstanceValidatorR4Test extends BaseTest { } @Test - @Ignore + @Disabled public void testValidateQuestionnaireResponse() throws IOException { String input = loadResource("/qr_jon.xml"); @@ -840,7 +832,7 @@ public class FhirInstanceValidatorR4Test extends BaseTest { "}"; ValidationResult output = myVal.validateWithResult(input); - assertEquals(output.toString(), 0, output.getMessages().size()); + assertEquals(0, output.getMessages().size(), output.toString()); } @Test @@ -857,7 +849,7 @@ public class FhirInstanceValidatorR4Test extends BaseTest { "}"; ValidationResult output = myVal.validateWithResult(input); - assertEquals(output.toString(), 1, output.getMessages().size()); + assertEquals(1, output.getMessages().size(), output.toString()); ourLog.info(output.getMessages().get(0).getLocationString()); ourLog.info(output.getMessages().get(0).getMessage()); assertEquals("Patient", output.getMessages().get(0).getLocationString()); @@ -871,7 +863,7 @@ public class FhirInstanceValidatorR4Test extends BaseTest { } @Test - @Ignore + @Disabled public void testValidateRawJsonResourceFromExamples() throws Exception { String input = loadResource("/testscript-search.json"); @@ -912,7 +904,7 @@ public class FhirInstanceValidatorR4Test extends BaseTest { */ ValidationResult output = myVal.validateWithResult(encoded); - assertEquals(output.toString(), 1, output.getMessages().size()); + assertEquals(1, output.getMessages().size(), output.toString()); assertEquals("Unknown extension http://hl7.org/fhir/v3/ethnicity", output.getMessages().get(0).getMessage()); assertEquals(ResultSeverityEnum.INFORMATION, output.getMessages().get(0).getSeverity()); @@ -947,7 +939,7 @@ public class FhirInstanceValidatorR4Test extends BaseTest { myInstanceVal.setAnyExtensionsAllowed(false); ValidationResult output = myVal.validateWithResult(encoded); - assertEquals(output.toString(), 1, output.getMessages().size()); + assertEquals(1, output.getMessages().size(), output.toString()); assertEquals("The extension http://hl7.org/fhir/v3/ethnicity is unknown, and not allowed here", output.getMessages().get(0).getMessage()); assertEquals(ResultSeverityEnum.ERROR, output.getMessages().get(0).getSeverity()); @@ -964,7 +956,7 @@ public class FhirInstanceValidatorR4Test extends BaseTest { ""; ValidationResult output = myVal.validateWithResult(input); - assertEquals(output.toString(), 0, output.getMessages().size()); + assertEquals(0, output.getMessages().size(), output.toString()); } @Test @@ -980,7 +972,7 @@ public class FhirInstanceValidatorR4Test extends BaseTest { ""; ValidationResult output = myVal.validateWithResult(input); - assertEquals(output.toString(), 1, output.getMessages().size()); + assertEquals(1, output.getMessages().size(), output.toString()); ourLog.info(output.getMessages().get(0).getLocationString()); ourLog.info(output.getMessages().get(0).getMessage()); assertEquals("/f:Patient", output.getMessages().get(0).getLocationString()); @@ -1001,7 +993,7 @@ public class FhirInstanceValidatorR4Test extends BaseTest { ValidationResult output = myVal.validateWithResult(input); List messages = logResultsAndReturnNonInformationalOnes(output); - assertEquals(output.toString(), 3, messages.size()); + assertEquals(3, messages.size(), output.toString()); assertThat(messages.get(0).getMessage(), containsString("Element must have some content")); assertThat(messages.get(1).getMessage(), containsString("Primitive types must have a value or must have child extensions")); assertThat(messages.get(2).getMessage(), containsString("All FHIR elements must have a @value or children [hasValue() or (children().count() > id.count())]")); @@ -1037,7 +1029,7 @@ public class FhirInstanceValidatorR4Test extends BaseTest { ValidationResult output = myVal.validateWithResult(input); List res = logResultsAndReturnNonInformationalOnes(output); - assertEquals(output.toString(), 1, res.size()); + assertEquals(1, res.size(), output.toString()); assertEquals("A code with no system has no defined meaning. A system should be provided", output.getMessages().get(0).getMessage()); } @@ -1215,7 +1207,7 @@ public class FhirInstanceValidatorR4Test extends BaseTest { } @Test - @Ignore + @Disabled public void testValidateDecimalWithTrailingDot() { String input = "{" + " \"resourceType\": \"Observation\"," + @@ -1256,7 +1248,7 @@ public class FhirInstanceValidatorR4Test extends BaseTest { ValidationResult output = myVal.validateWithResult(input); List errors = logResultsAndReturnNonInformationalOnes(output); - assertEquals(errors.toString(), 0, errors.size()); + assertEquals(0, errors.size(), errors.toString()); } @@ -1291,7 +1283,7 @@ public class FhirInstanceValidatorR4Test extends BaseTest { ValidationResult output = myVal.validateWithResult(input); List errors = logResultsAndReturnNonInformationalOnes(output); - assertEquals(errors.toString(), 0, errors.size()); + assertEquals(0, errors.size(), errors.toString()); } @Test @@ -1328,7 +1320,7 @@ public class FhirInstanceValidatorR4Test extends BaseTest { ValidationResult output = myVal.validateWithResult(input); List errors = logResultsAndReturnAll(output); - assertEquals(errors.toString(), 0, errors.size()); + assertEquals(0, errors.size(), errors.toString()); } @Test @@ -1417,14 +1409,14 @@ public class FhirInstanceValidatorR4Test extends BaseTest { } @Test - @Ignore + @Disabled public void testValidateStructureDefinition() throws IOException { String input = loadResource("/sdc-questionnaire.profile.xml"); ValidationResult output = myVal.validateWithResult(input); logResultsAndReturnAll(output); - assertEquals(output.toString(), 3, output.getMessages().size()); + assertEquals(3, output.getMessages().size(), output.toString()); ourLog.info(output.getMessages().get(0).getLocationString()); ourLog.info(output.getMessages().get(0).getMessage()); } @@ -1442,7 +1434,7 @@ public class FhirInstanceValidatorR4Test extends BaseTest { "}"; ValidationResult output = myVal.validateWithResult(input); List errors = logResultsAndReturnNonInformationalOnes(output); - assertEquals(errors.toString(), 0, errors.size()); + assertEquals(0, errors.size(), errors.toString()); } @@ -1460,7 +1452,7 @@ public class FhirInstanceValidatorR4Test extends BaseTest { "}"; ValidationResult output = myVal.validateWithResult(input); List errors = logResultsAndReturnNonInformationalOnes(output); - assertEquals(errors.toString(), 1, errors.size()); + assertEquals(1, errors.size(), errors.toString()); assertThat(errors.get(0).getMessage(), containsString("The value provided (\"BLAH\") is not in the value set http://hl7.org/fhir/ValueSet/currencies")); @@ -1480,12 +1472,12 @@ public class FhirInstanceValidatorR4Test extends BaseTest { ValidationResult output = myVal.validateWithResult(allergy); List errors = logResultsAndReturnNonInformationalOnes(output); - assertEquals(errors.toString(), 0, errors.size()); + assertEquals(0, errors.size(), errors.toString()); } @Test - @Ignore + @Disabled public void testValidateReferenceTargetType_Incorrect() { AllergyIntolerance allergy = new AllergyIntolerance(); @@ -1499,12 +1491,12 @@ public class FhirInstanceValidatorR4Test extends BaseTest { ValidationResult output = myVal.validateWithResult(allergy); List errors = logResultsAndReturnNonInformationalOnes(output); - assertEquals(errors.toString(), 0, errors.size()); + assertEquals(0, errors.size(), errors.toString()); assertThat(errors.get(0).getMessage(), containsString("The value provided (\"BLAH\") is not in the value set http://hl7.org/fhir/ValueSet/currencies")); } - @AfterClass + @AfterAll public static void afterClassClearContext() { myDefaultValidationSupport.flush(); myDefaultValidationSupport = null; diff --git a/hapi-fhir-validation/src/test/java/org/hl7/fhir/r4/validation/HapiWorkerContextTest.java b/hapi-fhir-validation/src/test/java/org/hl7/fhir/r4/validation/HapiWorkerContextTest.java index 40ee45ce4cb..7584e32693d 100644 --- a/hapi-fhir-validation/src/test/java/org/hl7/fhir/r4/validation/HapiWorkerContextTest.java +++ b/hapi-fhir-validation/src/test/java/org/hl7/fhir/r4/validation/HapiWorkerContextTest.java @@ -14,7 +14,7 @@ import org.hl7.fhir.r4.context.IWorkerContext; import org.hl7.fhir.r4.hapi.ctx.HapiWorkerContext; import org.hl7.fhir.r4.model.ValueSet; import org.hl7.fhir.utilities.validation.ValidationOptions; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.core.io.Resource; import org.springframework.core.io.support.PathMatchingResourcePatternResolver; import org.springframework.core.io.support.ResourcePatternResolver; @@ -27,7 +27,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public class HapiWorkerContextTest extends BaseTest { FhirContext myCtx = FhirContext.forR4(); @@ -59,20 +59,20 @@ public class HapiWorkerContextTest extends BaseTest { vs.setUrl("http://hl7.org/fhir/ValueSet/fm-status"); ValidationOptions options = new ValidationOptions().guessSystem(); outcome = workerCtx.validateCode(options, "active", vs); - assertEquals(outcome.getMessage(), true, outcome.isOk()); + assertEquals(true, outcome.isOk(), outcome.getMessage()); outcome = workerCtx.validateCode(options, "active2", vs); - assertEquals(outcome.getMessage(), false, outcome.isOk()); + assertEquals(false, outcome.isOk(), outcome.getMessage()); assertEquals("Unknown code[active2] in system[(none)]", outcome.getMessage()); // PrePopulated codes vs.setUrl("http://hl7.org/fhir/us/core/ValueSet/birthsex"); outcome = workerCtx.validateCode(options, "F", vs); - assertEquals(outcome.getMessage(), true, outcome.isOk()); + assertEquals(true, outcome.isOk(), outcome.getMessage()); outcome = workerCtx.validateCode(options, "F2", vs); - assertEquals(outcome.getMessage(), false, outcome.isOk()); + assertEquals(false, outcome.isOk(), outcome.getMessage()); assertEquals("Unknown code[F2] in system[(none)]", outcome.getMessage()); } diff --git a/hapi-fhir-validation/src/test/java/org/hl7/fhir/r4/validation/QuestionnaireResponseValidatorR4Test.java b/hapi-fhir-validation/src/test/java/org/hl7/fhir/r4/validation/QuestionnaireResponseValidatorR4Test.java index f6869eb01cb..b0ad4ea5281 100644 --- a/hapi-fhir-validation/src/test/java/org/hl7/fhir/r4/validation/QuestionnaireResponseValidatorR4Test.java +++ b/hapi-fhir-validation/src/test/java/org/hl7/fhir/r4/validation/QuestionnaireResponseValidatorR4Test.java @@ -19,20 +19,20 @@ import org.hl7.fhir.r4.model.Questionnaire.QuestionnaireItemType; import org.hl7.fhir.r4.model.QuestionnaireResponse.QuestionnaireResponseItemComponent; import org.hl7.fhir.r4.model.QuestionnaireResponse.QuestionnaireResponseStatus; import org.hl7.fhir.utilities.xhtml.XhtmlNode; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.util.ArrayList; import java.util.Arrays; import java.util.Date; import java.util.List; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.hasSize; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; @@ -52,7 +52,7 @@ public class QuestionnaireResponseValidatorR4Test { private FhirValidator myVal; private IValidationSupport myValSupport; - @Before + @BeforeEach public void before() { myValSupport = mock(IValidationSupport.class); when(myValSupport.getFhirContext()).thenReturn(ourCtx); @@ -233,7 +233,7 @@ public class QuestionnaireResponseValidatorR4Test { qa.addItem().setLinkId("link0").addAnswer().setValue(new Coding().setSystem("http://codesystems.com/system").setCode("code0")); errors = myVal.validateWithResult(qa); errors = stripBindingHasNoSourceMessage(errors); - assertEquals(errors.toString(), 0, errors.getMessages().size()); + assertEquals(0, errors.getMessages().size(), errors.toString()); // Bad code @@ -801,7 +801,7 @@ public class QuestionnaireResponseValidatorR4Test { } - @AfterClass + @AfterAll public static void afterClassClearContext() { myDefaultValidationSupport.flush(); myDefaultValidationSupport = null; diff --git a/hapi-fhir-validation/src/test/java/org/hl7/fhir/r4/validation/QuestionnaireValidatorR4Test.java b/hapi-fhir-validation/src/test/java/org/hl7/fhir/r4/validation/QuestionnaireValidatorR4Test.java index 7ed6efeb579..91d3c23f3af 100644 --- a/hapi-fhir-validation/src/test/java/org/hl7/fhir/r4/validation/QuestionnaireValidatorR4Test.java +++ b/hapi-fhir-validation/src/test/java/org/hl7/fhir/r4/validation/QuestionnaireValidatorR4Test.java @@ -19,16 +19,16 @@ import org.hl7.fhir.r4.model.Narrative; import org.hl7.fhir.r4.model.Narrative.NarrativeStatus; import org.hl7.fhir.r4.model.Questionnaire; import org.hl7.fhir.r4.model.Questionnaire.QuestionnaireItemType; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.util.stream.Collectors; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -39,7 +39,7 @@ public class QuestionnaireValidatorR4Test { private FhirInstanceValidator myInstanceVal; private FhirValidator myVal; - @Before + @BeforeEach public void before() { IValidationSupport myValSupport = mock(IValidationSupport.class); when(myValSupport.getFhirContext()).thenReturn(ourCtx); @@ -140,7 +140,7 @@ public class QuestionnaireValidatorR4Test { return q; } - @AfterClass + @AfterAll public static void afterClassClearContext() { myDefaultValidationSupport.flush(); myDefaultValidationSupport = null; diff --git a/hapi-fhir-validation/src/test/java/org/hl7/fhir/r4/validation/SchemaValidationR4Test.java b/hapi-fhir-validation/src/test/java/org/hl7/fhir/r4/validation/SchemaValidationR4Test.java index 917029b75b5..f3794a85181 100644 --- a/hapi-fhir-validation/src/test/java/org/hl7/fhir/r4/validation/SchemaValidationR4Test.java +++ b/hapi-fhir-validation/src/test/java/org/hl7/fhir/r4/validation/SchemaValidationR4Test.java @@ -1,16 +1,15 @@ package org.hl7.fhir.r4.validation; -import static org.hamcrest.Matchers.containsString; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertThat; - -import ca.uhn.fhir.validation.FhirValidator; -import ca.uhn.fhir.validation.ValidationResult; -import org.junit.AfterClass; -import org.junit.Test; - import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.util.TestUtil; +import ca.uhn.fhir.validation.FhirValidator; +import ca.uhn.fhir.validation.ValidationResult; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsString; +import static org.junit.jupiter.api.Assertions.assertFalse; public class SchemaValidationR4Test { @@ -55,7 +54,7 @@ public class SchemaValidationR4Test { assertThat(encoded, containsString("accessExternalDTD")); } - @AfterClass + @AfterAll public static void afterClassClearContext() { TestUtil.clearAllStaticFieldsForUnitTest(); } diff --git a/hapi-fhir-validation/src/test/java/org/hl7/fhir/r4/validation/SchematronValidationR4QuestionnaireTest.java b/hapi-fhir-validation/src/test/java/org/hl7/fhir/r4/validation/SchematronValidationR4QuestionnaireTest.java index dc25b8338cf..5007046a919 100644 --- a/hapi-fhir-validation/src/test/java/org/hl7/fhir/r4/validation/SchematronValidationR4QuestionnaireTest.java +++ b/hapi-fhir-validation/src/test/java/org/hl7/fhir/r4/validation/SchematronValidationR4QuestionnaireTest.java @@ -1,33 +1,31 @@ package org.hl7.fhir.r4.validation; -import static org.hamcrest.Matchers.containsString; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; - import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.util.TestUtil; import ca.uhn.fhir.validation.FhirValidator; import ca.uhn.fhir.validation.ValidationResult; - import org.hl7.fhir.r4.model.Enumerations; import org.hl7.fhir.r4.model.Questionnaire; import org.hl7.fhir.r4.model.Questionnaire.QuestionnaireItemComponent; import org.hl7.fhir.r4.model.Questionnaire.QuestionnaireItemEnableWhenComponent; import org.hl7.fhir.r4.model.Questionnaire.QuestionnaireItemType; import org.hl7.fhir.r4.model.StringType; - -import org.junit.AfterClass; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsString; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + /** * Added for #870 - Can be enabled when the FHIR sources are fixed */ -@Ignore("Requires a valid schematron file, e.g. bei merging pull request #869") +@Disabled("Requires a valid schematron file, e.g. bei merging pull request #869") public class SchematronValidationR4QuestionnaireTest { private static final Logger ourLog = LoggerFactory.getLogger(SchematronValidationR4QuestionnaireTest.class); @@ -125,7 +123,7 @@ public class SchematronValidationR4QuestionnaireTest { return result; } - @AfterClass + @AfterAll public static void afterClassClearContext() { TestUtil.clearAllStaticFieldsForUnitTest(); } diff --git a/hapi-fhir-validation/src/test/java/org/hl7/fhir/r4/validation/SnapshotGeneratorR4Test.java b/hapi-fhir-validation/src/test/java/org/hl7/fhir/r4/validation/SnapshotGeneratorR4Test.java index ec04c76d8ce..de4283bd9e4 100644 --- a/hapi-fhir-validation/src/test/java/org/hl7/fhir/r4/validation/SnapshotGeneratorR4Test.java +++ b/hapi-fhir-validation/src/test/java/org/hl7/fhir/r4/validation/SnapshotGeneratorR4Test.java @@ -10,7 +10,7 @@ import org.hl7.fhir.common.hapi.validation.support.SnapshotGeneratingValidationS import org.hl7.fhir.common.hapi.validation.support.ValidationSupportChain; import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.r4.model.StructureDefinition; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -18,8 +18,8 @@ import java.io.IOException; import java.io.InputStream; import java.nio.charset.StandardCharsets; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; public class SnapshotGeneratorR4Test { diff --git a/hapi-fhir-validation/src/test/java/org/hl7/fhir/r5/validation/FhirInstanceValidatorR5Test.java b/hapi-fhir-validation/src/test/java/org/hl7/fhir/r5/validation/FhirInstanceValidatorR5Test.java index dd48a36debf..42843638830 100644 --- a/hapi-fhir-validation/src/test/java/org/hl7/fhir/r5/validation/FhirInstanceValidatorR5Test.java +++ b/hapi-fhir-validation/src/test/java/org/hl7/fhir/r5/validation/FhirInstanceValidatorR5Test.java @@ -7,6 +7,7 @@ import ca.uhn.fhir.context.support.IValidationSupport; import ca.uhn.fhir.context.support.ValidationSupportContext; import ca.uhn.fhir.context.support.ValueSetExpansionOptions; import ca.uhn.fhir.rest.api.Constants; +import ca.uhn.fhir.test.utilities.LoggingExtension; import ca.uhn.fhir.util.TestUtil; import ca.uhn.fhir.validation.FhirValidator; import ca.uhn.fhir.validation.ResultSeverityEnum; @@ -18,22 +19,18 @@ import org.hl7.fhir.common.hapi.validation.support.CachingValidationSupport; import org.hl7.fhir.common.hapi.validation.support.CommonCodeSystemsTerminologyService; import org.hl7.fhir.common.hapi.validation.support.InMemoryTerminologyServerValidationSupport; import org.hl7.fhir.common.hapi.validation.support.ValidationSupportChain; -import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.common.hapi.validation.validator.FhirInstanceValidator; +import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.r5.model.*; import org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionComponent; import org.hl7.fhir.r5.terminologies.ValueSetExpander; import org.hl7.fhir.r5.utils.IResourceValidator; -import org.hl7.fhir.utilities.validation.ValidationMessage; import org.hl7.fhir.utilities.xhtml.XhtmlNode; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TestRule; -import org.junit.rules.TestWatcher; -import org.junit.runner.Description; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; @@ -45,6 +42,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.greaterThan; @@ -52,10 +50,9 @@ import static org.hamcrest.Matchers.hasItem; import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.lessThan; import static org.hamcrest.Matchers.not; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.nullable; @@ -69,13 +66,8 @@ public class FhirInstanceValidatorR5Test { private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(FhirInstanceValidatorR5Test.class); private static FhirContext ourCtx = FhirContext.forR5(); private static DefaultProfileValidationSupport myDefaultValidationSupport = new DefaultProfileValidationSupport(ourCtx); - @Rule - public TestRule watcher = new TestWatcher() { - @Override - protected void starting(Description description) { - ourLog.info("Starting test: " + description.getMethodName()); - } - }; + @RegisterExtension + public LoggingExtension myLoggingExtension = new LoggingExtension(); private FhirInstanceValidator myInstanceVal; private IValidationSupport myMockSupport; private Map mySupportedCodeSystemsForExpansion; @@ -106,7 +98,7 @@ public class FhirInstanceValidatorR5Test { } @SuppressWarnings("unchecked") - @Before + @BeforeEach public void before() { myVal = ourCtx.newValidator(); myVal.setValidateAgainstStandardSchema(false); @@ -465,7 +457,7 @@ public class FhirInstanceValidatorR5Test { "}"; ValidationResult output = myVal.validateWithResult(input); - assertEquals(output.toString(), 0, output.getMessages().size()); + assertEquals(0, output.getMessages().size(), output.toString()); } @Test @@ -482,7 +474,7 @@ public class FhirInstanceValidatorR5Test { "}"; ValidationResult output = myVal.validateWithResult(input); - assertEquals(output.toString(), 1, output.getMessages().size()); + assertEquals(1, output.getMessages().size(), output.toString()); ourLog.info(output.getMessages().get(0).getLocationString()); ourLog.info(output.getMessages().get(0).getMessage()); assertEquals("Patient", output.getMessages().get(0).getLocationString()); @@ -490,7 +482,7 @@ public class FhirInstanceValidatorR5Test { } @Test - @Ignore + @Disabled public void testValidateRawJsonResourceFromExamples() throws Exception { // @formatter:off String input = IOUtils.toString(FhirInstanceValidator.class.getResourceAsStream("/testscript-search.json"), Charsets.UTF_8); @@ -533,7 +525,7 @@ public class FhirInstanceValidatorR5Test { */ ValidationResult output = myVal.validateWithResult(encoded); - assertEquals(output.toString(), 1, output.getMessages().size()); + assertEquals(1, output.getMessages().size(), output.toString()); assertEquals("Unknown extension http://hl7.org/fhir/v3/ethnicity", output.getMessages().get(0).getMessage()); assertEquals(ResultSeverityEnum.INFORMATION, output.getMessages().get(0).getSeverity()); @@ -568,7 +560,7 @@ public class FhirInstanceValidatorR5Test { myInstanceVal.setAnyExtensionsAllowed(false); ValidationResult output = myVal.validateWithResult(encoded); - assertEquals(output.toString(), 1, output.getMessages().size()); + assertEquals( 1, output.getMessages().size(), output.toString()); assertEquals("The extension http://hl7.org/fhir/v3/ethnicity is unknown, and not allowed here", output.getMessages().get(0).getMessage()); assertEquals(ResultSeverityEnum.ERROR, output.getMessages().get(0).getSeverity()); @@ -585,7 +577,7 @@ public class FhirInstanceValidatorR5Test { ""; ValidationResult output = myVal.validateWithResult(input); - assertEquals(output.toString(), 0, output.getMessages().size()); + assertEquals(0, output.getMessages().size(), output.toString()); } @Test @@ -601,7 +593,7 @@ public class FhirInstanceValidatorR5Test { ""; ValidationResult output = myVal.validateWithResult(input); - assertEquals(output.toString(), 1, output.getMessages().size()); + assertEquals( 1, output.getMessages().size(), output.toString()); ourLog.info(output.getMessages().get(0).getLocationString()); ourLog.info(output.getMessages().get(0).getMessage()); assertEquals("/f:Patient", output.getMessages().get(0).getLocationString()); @@ -620,7 +612,7 @@ public class FhirInstanceValidatorR5Test { ValidationResult output = myVal.validateWithResult(input); List messages = logResultsAndReturnNonInformationalOnes(output); - assertEquals(output.toString(), 3, messages.size()); + assertEquals( 3, messages.size(), output.toString()); assertThat(messages.get(0).getMessage(), containsString("Element must have some content")); assertThat(messages.get(1).getMessage(), containsString("Primitive types must have a value or must have child extensions")); assertThat(messages.get(2).getMessage(), containsString("ele-1: All FHIR elements must have a @value or children [hasValue() or (children().count() > id.count())]")); @@ -658,7 +650,7 @@ public class FhirInstanceValidatorR5Test { ValidationResult output = myVal.validateWithResult(input); List res = logResultsAndReturnNonInformationalOnes(output); - assertEquals(output.toString(), 1, res.size()); + assertEquals(1, res.size(), output.toString()); assertEquals("A code with no system has no defined meaning. A system should be provided", output.getMessages().get(0).getMessage()); } @@ -680,7 +672,7 @@ public class FhirInstanceValidatorR5Test { + ""; ValidationResult output = myVal.validateWithResult(input); - assertEquals(output.toString(), 1, output.getMessages().size()); + assertEquals(1, output.getMessages().size(), output.toString()); assertEquals("This \"Patient\" cannot be parsed as a FHIR object (no namespace)", output.getMessages().get(0).getMessage()); ourLog.info(output.getMessages().get(0).getLocationString()); } @@ -867,7 +859,7 @@ public class FhirInstanceValidatorR5Test { ValidationResult output = myVal.validateWithResult(input); List errors = logResultsAndReturnNonInformationalOnes(output); - assertEquals(errors.toString(), 0, errors.size()); + assertEquals( 0, errors.size(), errors.toString()); } @@ -902,7 +894,7 @@ public class FhirInstanceValidatorR5Test { ValidationResult output = myVal.validateWithResult(input); List errors = logResultsAndReturnNonInformationalOnes(output); - assertEquals(errors.toString(), 0, errors.size()); + assertEquals( 0, errors.size(),errors.toString()); } @Test @@ -939,7 +931,7 @@ public class FhirInstanceValidatorR5Test { ValidationResult output = myVal.validateWithResult(input); List errors = logResultsAndReturnAll(output); - assertEquals(errors.toString(), 0, errors.size()); + assertEquals( 0, errors.size(), errors.toString()); } @Test @@ -999,19 +991,19 @@ public class FhirInstanceValidatorR5Test { @Test - @Ignore + @Disabled public void testValidateStructureDefinition() throws IOException { String input = IOUtils.toString(FhirInstanceValidatorR5Test.class.getResourceAsStream("/sdc-questionnaire.profile.xml")); ValidationResult output = myVal.validateWithResult(input); logResultsAndReturnAll(output); - assertEquals(output.toString(), 3, output.getMessages().size()); + assertEquals( 3, output.getMessages().size(), output.toString()); ourLog.info(output.getMessages().get(0).getLocationString()); ourLog.info(output.getMessages().get(0).getMessage()); } - @AfterClass + @AfterAll public static void afterClassClearContext() { myDefaultValidationSupport.flush(); myDefaultValidationSupport = null; diff --git a/hapi-fhir-validation/src/test/java/org/hl7/fhir/r5/validation/QuestionnaireResponseValidatorR5Test.java b/hapi-fhir-validation/src/test/java/org/hl7/fhir/r5/validation/QuestionnaireResponseValidatorR5Test.java index 930077ee240..61652d54099 100644 --- a/hapi-fhir-validation/src/test/java/org/hl7/fhir/r5/validation/QuestionnaireResponseValidatorR5Test.java +++ b/hapi-fhir-validation/src/test/java/org/hl7/fhir/r5/validation/QuestionnaireResponseValidatorR5Test.java @@ -20,20 +20,20 @@ import org.hl7.fhir.r5.model.Questionnaire.QuestionnaireItemType; import org.hl7.fhir.r5.model.QuestionnaireResponse.QuestionnaireResponseItemComponent; import org.hl7.fhir.r5.model.QuestionnaireResponse.QuestionnaireResponseStatus; import org.hl7.fhir.utilities.xhtml.XhtmlNode; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.util.ArrayList; import java.util.Arrays; import java.util.Date; import java.util.List; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.hasSize; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; @@ -54,7 +54,7 @@ public class QuestionnaireResponseValidatorR5Test { private IValidationSupport myValSupport; private HapiWorkerContext myWorkerCtx; - @Before + @BeforeEach public void before() { myValSupport = mock(IValidationSupport.class); when(myValSupport.getFhirContext()).thenReturn(ourCtx); @@ -237,7 +237,7 @@ public class QuestionnaireResponseValidatorR5Test { qa.addItem().setLinkId("link0").addAnswer().setValue(new Coding().setSystem("http://codesystems.com/system").setCode("code0")); errors = myVal.validateWithResult(qa); errors = stripBindingHasNoSourceMessage(errors); - assertEquals(errors.toString(), 0, errors.getMessages().size()); + assertEquals( 0, errors.getMessages().size(), errors.toString()); // Bad code @@ -693,7 +693,7 @@ public class QuestionnaireResponseValidatorR5Test { } - @AfterClass + @AfterAll public static void afterClassClearContext() { myDefaultValidationSupport.flush(); myDefaultValidationSupport = null; diff --git a/hapi-tinder-test/pom.xml b/hapi-tinder-test/pom.xml index 080edafbd22..05f230210af 100644 --- a/hapi-tinder-test/pom.xml +++ b/hapi-tinder-test/pom.xml @@ -57,11 +57,6 @@ hapi-fhir-validation-resources-dstu3 ${project.version} - - junit - junit - test - diff --git a/hapi-tinder-test/src/test/java/test/TestAntTask.java b/hapi-tinder-test/src/test/java/test/TestAntTask.java index fd81a49dda7..a16533cf89d 100644 --- a/hapi-tinder-test/src/test/java/test/TestAntTask.java +++ b/hapi-tinder-test/src/test/java/test/TestAntTask.java @@ -2,7 +2,7 @@ package test; import java.util.List; -import org.junit.Test; +import org.junit.jupiter.api.Test; import ca.uhn.test.ant.single.TestConfigDstu2; import ca.uhn.test.ant.multi.*; diff --git a/hapi-tinder-test/src/test/java/test/TestParticulars.java b/hapi-tinder-test/src/test/java/test/TestParticulars.java index bda2f3f2461..69b612b6917 100644 --- a/hapi-tinder-test/src/test/java/test/TestParticulars.java +++ b/hapi-tinder-test/src/test/java/test/TestParticulars.java @@ -1,6 +1,6 @@ package test; -import org.junit.Test; +import org.junit.jupiter.api.Test; import ca.uhn.test.realstructs.resource.ListResource; import ca.uhn.test.realstructs.resource.AuditEvent.ObjectElement; diff --git a/osgi/hapi-fhir-karaf-integration-tests/src/test/java/ca/uhn/fhir/tests/integration/karaf/client/FhirClientTest.java b/osgi/hapi-fhir-karaf-integration-tests/src/test/java/ca/uhn/fhir/tests/integration/karaf/client/FhirClientTest.java index 55e3a507524..bf78f283435 100644 --- a/osgi/hapi-fhir-karaf-integration-tests/src/test/java/ca/uhn/fhir/tests/integration/karaf/client/FhirClientTest.java +++ b/osgi/hapi-fhir-karaf-integration-tests/src/test/java/ca/uhn/fhir/tests/integration/karaf/client/FhirClientTest.java @@ -6,9 +6,9 @@ import ca.uhn.fhir.rest.api.MethodOutcome; import ca.uhn.fhir.rest.api.PreferReturnEnum; import ca.uhn.fhir.rest.client.api.IGenericClient; import org.hl7.fhir.dstu3.model.Patient; -import org.junit.Ignore; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.ops4j.pax.exam.Configuration; import org.ops4j.pax.exam.Option; import org.ops4j.pax.exam.junit.PaxExam; @@ -29,7 +29,7 @@ import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.debugConf */ @RunWith(PaxExam.class) @ExamReactorStrategy(PerClass.class) -@Ignore(value = "Relies on external service being up and running") +@Disabled(value = "Relies on external service being up and running") public class FhirClientTest { private FhirContext fhirContext = FhirContext.forDstu3(); diff --git a/osgi/hapi-fhir-karaf-integration-tests/src/test/java/ca/uhn/fhir/tests/integration/karaf/dstu2/Dstu2ResourceValidatorDstu2Test.java b/osgi/hapi-fhir-karaf-integration-tests/src/test/java/ca/uhn/fhir/tests/integration/karaf/dstu2/Dstu2ResourceValidatorDstu2Test.java index f97ea4efb8d..80792be4698 100644 --- a/osgi/hapi-fhir-karaf-integration-tests/src/test/java/ca/uhn/fhir/tests/integration/karaf/dstu2/Dstu2ResourceValidatorDstu2Test.java +++ b/osgi/hapi-fhir-karaf-integration-tests/src/test/java/ca/uhn/fhir/tests/integration/karaf/dstu2/Dstu2ResourceValidatorDstu2Test.java @@ -36,8 +36,8 @@ import org.apache.commons.io.IOUtils; import org.hamcrest.Matcher; import org.hamcrest.Matchers; import org.hamcrest.core.StringContains; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.ops4j.pax.exam.Configuration; import org.ops4j.pax.exam.Option; import org.ops4j.pax.exam.junit.PaxExam; @@ -49,11 +49,11 @@ import static ca.uhn.fhir.tests.integration.karaf.PaxExamOptions.KARAF; import static ca.uhn.fhir.tests.integration.karaf.PaxExamOptions.WRAP; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.not; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import static org.ops4j.pax.exam.CoreOptions.mavenBundle; import static org.ops4j.pax.exam.CoreOptions.options; import static org.ops4j.pax.exam.CoreOptions.when; diff --git a/osgi/hapi-fhir-karaf-integration-tests/src/test/java/ca/uhn/fhir/tests/integration/karaf/dstu21/JsonParserDstu2_1Test.java b/osgi/hapi-fhir-karaf-integration-tests/src/test/java/ca/uhn/fhir/tests/integration/karaf/dstu21/JsonParserDstu2_1Test.java index 751c7243c05..cee234eb160 100644 --- a/osgi/hapi-fhir-karaf-integration-tests/src/test/java/ca/uhn/fhir/tests/integration/karaf/dstu21/JsonParserDstu2_1Test.java +++ b/osgi/hapi-fhir-karaf-integration-tests/src/test/java/ca/uhn/fhir/tests/integration/karaf/dstu21/JsonParserDstu2_1Test.java @@ -19,8 +19,8 @@ import org.hl7.fhir.dstu2016may.model.Conformance; import org.hl7.fhir.dstu2016may.model.PrimitiveType; import org.hl7.fhir.instance.model.api.IIdType; import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.ops4j.pax.exam.Configuration; import org.ops4j.pax.exam.Option; import org.ops4j.pax.exam.junit.PaxExam; @@ -34,12 +34,12 @@ import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.not; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import static org.ops4j.pax.exam.CoreOptions.mavenBundle; import static org.ops4j.pax.exam.CoreOptions.options; import static org.ops4j.pax.exam.CoreOptions.when; @@ -1426,8 +1426,8 @@ public class JsonParserDstu2_1Test { fhirPat = parser.parseResource(org.hl7.fhir.dstu2016may.model.Patient.class, output); List extlst = fhirPat.getExtensionsByUrl("x1"); - Assert.assertEquals(1, extlst.size()); - Assert.assertEquals(refVal, ((org.hl7.fhir.dstu2016may.model.Reference) extlst.get(0).getValue()).getReference()); + assertEquals(1, extlst.size()); + assertEquals(refVal, ((org.hl7.fhir.dstu2016may.model.Reference) extlst.get(0).getValue()).getReference()); } diff --git a/osgi/hapi-fhir-karaf-integration-tests/src/test/java/ca/uhn/fhir/tests/integration/karaf/dstu21/XmlParserDstu2_1Test.java b/osgi/hapi-fhir-karaf-integration-tests/src/test/java/ca/uhn/fhir/tests/integration/karaf/dstu21/XmlParserDstu2_1Test.java index be69190807f..d1c3827fe2c 100644 --- a/osgi/hapi-fhir-karaf-integration-tests/src/test/java/ca/uhn/fhir/tests/integration/karaf/dstu21/XmlParserDstu2_1Test.java +++ b/osgi/hapi-fhir-karaf-integration-tests/src/test/java/ca/uhn/fhir/tests/integration/karaf/dstu21/XmlParserDstu2_1Test.java @@ -58,8 +58,8 @@ import org.hl7.fhir.dstu2016may.model.UriType; import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IIdType; import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.ops4j.pax.exam.Configuration; import org.ops4j.pax.exam.Option; import org.ops4j.pax.exam.junit.PaxExam; @@ -79,15 +79,15 @@ import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.not; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import static org.ops4j.pax.exam.CoreOptions.mavenBundle; import static org.ops4j.pax.exam.CoreOptions.options; import static org.ops4j.pax.exam.CoreOptions.when; @@ -2427,8 +2427,8 @@ public class XmlParserDstu2_1Test { fhirPat = parser.parseResource(Patient.class, output); List extlst = fhirPat.getExtensionsByUrl("x1"); - Assert.assertEquals(1, extlst.size()); - Assert.assertEquals(refVal, ((Reference) extlst.get(0).getValue()).getReference()); + assertEquals(1, extlst.size()); + assertEquals(refVal, ((Reference) extlst.get(0).getValue()).getReference()); } public static void compareXml(String content, String reEncoded) { diff --git a/osgi/hapi-fhir-karaf-integration-tests/src/test/java/ca/uhn/fhir/tests/integration/karaf/dstu2hl7org/FhirInstanceValidatorTest.java b/osgi/hapi-fhir-karaf-integration-tests/src/test/java/ca/uhn/fhir/tests/integration/karaf/dstu2hl7org/FhirInstanceValidatorTest.java index 62f24ffde09..0dadea734a5 100644 --- a/osgi/hapi-fhir-karaf-integration-tests/src/test/java/ca/uhn/fhir/tests/integration/karaf/dstu2hl7org/FhirInstanceValidatorTest.java +++ b/osgi/hapi-fhir-karaf-integration-tests/src/test/java/ca/uhn/fhir/tests/integration/karaf/dstu2hl7org/FhirInstanceValidatorTest.java @@ -9,8 +9,8 @@ import org.hl7.fhir.dstu2.model.QuestionnaireResponse; import org.hl7.fhir.dstu2.model.StringType; import org.hl7.fhir.instance.hapi.validation.DefaultProfileValidationSupport; import org.hl7.fhir.instance.hapi.validation.FhirInstanceValidator; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.ops4j.pax.exam.Configuration; import org.ops4j.pax.exam.Option; import org.ops4j.pax.exam.junit.PaxExam; @@ -22,8 +22,8 @@ import java.io.IOException; import static ca.uhn.fhir.tests.integration.karaf.PaxExamOptions.*; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.not; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.ops4j.pax.exam.CoreOptions.*; import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.debugConfiguration; diff --git a/osgi/hapi-fhir-karaf-integration-tests/src/test/java/ca/uhn/fhir/tests/integration/karaf/dstu2hl7org/JsonParserHl7OrgDstu2Test.java b/osgi/hapi-fhir-karaf-integration-tests/src/test/java/ca/uhn/fhir/tests/integration/karaf/dstu2hl7org/JsonParserHl7OrgDstu2Test.java index ea0e1e04380..32a6b40dd6f 100644 --- a/osgi/hapi-fhir-karaf-integration-tests/src/test/java/ca/uhn/fhir/tests/integration/karaf/dstu2hl7org/JsonParserHl7OrgDstu2Test.java +++ b/osgi/hapi-fhir-karaf-integration-tests/src/test/java/ca/uhn/fhir/tests/integration/karaf/dstu2hl7org/JsonParserHl7OrgDstu2Test.java @@ -53,8 +53,8 @@ import org.hl7.fhir.instance.model.api.IIdType; import org.hl7.fhir.instance.model.api.IPrimitiveType; import org.hl7.fhir.utilities.xhtml.XhtmlNode; import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.ops4j.pax.exam.Configuration; import org.ops4j.pax.exam.Option; import org.ops4j.pax.exam.junit.PaxExam; @@ -67,14 +67,14 @@ import static ca.uhn.fhir.tests.integration.karaf.PaxExamOptions.KARAF; import static ca.uhn.fhir.tests.integration.karaf.PaxExamOptions.WRAP; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.not; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.ops4j.pax.exam.CoreOptions.mavenBundle; import static org.ops4j.pax.exam.CoreOptions.options; import static org.ops4j.pax.exam.CoreOptions.when; @@ -1263,8 +1263,8 @@ public class JsonParserHl7OrgDstu2Test { fhirPat = parser.parseResource(Patient.class, output); List extlst = fhirPat.getExtension(); - Assert.assertEquals(1, extlst.size()); - Assert.assertEquals(refVal, ((Reference) extlst.get(0).getValue()).getReference()); + assertEquals(1, extlst.size()); + assertEquals(refVal, ((Reference) extlst.get(0).getValue()).getReference()); } @ResourceDef(name = "Patient") diff --git a/osgi/hapi-fhir-karaf-integration-tests/src/test/java/ca/uhn/fhir/tests/integration/karaf/dstu2hl7org/XmlParserHl7OrgDstu2Test.java b/osgi/hapi-fhir-karaf-integration-tests/src/test/java/ca/uhn/fhir/tests/integration/karaf/dstu2hl7org/XmlParserHl7OrgDstu2Test.java index 2a4b8e246d0..93f1f63aaec 100644 --- a/osgi/hapi-fhir-karaf-integration-tests/src/test/java/ca/uhn/fhir/tests/integration/karaf/dstu2hl7org/XmlParserHl7OrgDstu2Test.java +++ b/osgi/hapi-fhir-karaf-integration-tests/src/test/java/ca/uhn/fhir/tests/integration/karaf/dstu2hl7org/XmlParserHl7OrgDstu2Test.java @@ -40,8 +40,8 @@ import org.hl7.fhir.instance.model.api.IBaseResource; import org.hl7.fhir.instance.model.api.IIdType; import org.hl7.fhir.instance.model.api.IPrimitiveType; import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.ops4j.pax.exam.Configuration; import org.ops4j.pax.exam.Option; import org.ops4j.pax.exam.junit.PaxExam; @@ -60,13 +60,13 @@ import static ca.uhn.fhir.tests.integration.karaf.PaxExamOptions.KARAF; import static ca.uhn.fhir.tests.integration.karaf.PaxExamOptions.WRAP; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.not; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.ops4j.pax.exam.CoreOptions.mavenBundle; import static org.ops4j.pax.exam.CoreOptions.options; import static org.ops4j.pax.exam.CoreOptions.when; @@ -1411,8 +1411,8 @@ public class XmlParserHl7OrgDstu2Test { fhirPat = parser.parseResource(org.hl7.fhir.dstu2.model.Patient.class, output); List extlst = fhirPat.getExtension(); - Assert.assertEquals(1, extlst.size()); - Assert.assertEquals(refVal, ((org.hl7.fhir.dstu2.model.Reference) extlst.get(0).getValue()).getReference()); + assertEquals(1, extlst.size()); + assertEquals(refVal, ((org.hl7.fhir.dstu2.model.Reference) extlst.get(0).getValue()).getReference()); } @ResourceDef(name = "Patient") diff --git a/osgi/hapi-fhir-karaf-integration-tests/src/test/java/ca/uhn/fhir/tests/integration/karaf/dstu3/Dstu3JsonParserTest.java b/osgi/hapi-fhir-karaf-integration-tests/src/test/java/ca/uhn/fhir/tests/integration/karaf/dstu3/Dstu3JsonParserTest.java index f5e7b5ee526..6c1f0633bc5 100644 --- a/osgi/hapi-fhir-karaf-integration-tests/src/test/java/ca/uhn/fhir/tests/integration/karaf/dstu3/Dstu3JsonParserTest.java +++ b/osgi/hapi-fhir-karaf-integration-tests/src/test/java/ca/uhn/fhir/tests/integration/karaf/dstu3/Dstu3JsonParserTest.java @@ -49,8 +49,8 @@ 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.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.ops4j.pax.exam.Configuration; import org.ops4j.pax.exam.Option; import org.ops4j.pax.exam.junit.PaxExam; @@ -66,13 +66,13 @@ import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.not; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import static org.ops4j.pax.exam.CoreOptions.mavenBundle; import static org.ops4j.pax.exam.CoreOptions.options; import static org.ops4j.pax.exam.CoreOptions.when; @@ -120,8 +120,8 @@ public class Dstu3JsonParserTest { fhirPat = parser.parseResource(Patient.class, output); List extlst = fhirPat.getExtensionsByUrl("x1"); - Assert.assertEquals(1, extlst.size()); - Assert.assertEquals(refVal, ((Reference) extlst.get(0).getValue()).getReference()); + assertEquals(1, extlst.size()); + assertEquals(refVal, ((Reference) extlst.get(0).getValue()).getReference()); } /** diff --git a/osgi/hapi-fhir-karaf-integration-tests/src/test/java/ca/uhn/fhir/tests/integration/karaf/dstu3/Dstu3XmlParserTest.java b/osgi/hapi-fhir-karaf-integration-tests/src/test/java/ca/uhn/fhir/tests/integration/karaf/dstu3/Dstu3XmlParserTest.java index ce67997536f..298feaba1da 100644 --- a/osgi/hapi-fhir-karaf-integration-tests/src/test/java/ca/uhn/fhir/tests/integration/karaf/dstu3/Dstu3XmlParserTest.java +++ b/osgi/hapi-fhir-karaf-integration-tests/src/test/java/ca/uhn/fhir/tests/integration/karaf/dstu3/Dstu3XmlParserTest.java @@ -77,8 +77,8 @@ 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.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.ops4j.pax.exam.Configuration; import org.ops4j.pax.exam.Option; import org.ops4j.pax.exam.junit.PaxExam; @@ -99,15 +99,15 @@ import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.startsWith; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import static org.ops4j.pax.exam.CoreOptions.mavenBundle; import static org.ops4j.pax.exam.CoreOptions.options; import static org.ops4j.pax.exam.CoreOptions.when; @@ -154,8 +154,8 @@ public class Dstu3XmlParserTest { fhirPat = parser.parseResource(Patient.class, output); List extlst = fhirPat.getExtensionsByUrl("x1"); - Assert.assertEquals(1, extlst.size()); - Assert.assertEquals(refVal, ((Reference) extlst.get(0).getValue()).getReference()); + assertEquals(1, extlst.size()); + assertEquals(refVal, ((Reference) extlst.get(0).getValue()).getReference()); } /** diff --git a/osgi/hapi-fhir-karaf-integration-tests/src/test/java/ca/uhn/fhir/tests/integration/karaf/dstu3/ResourceValidatorDstu3FeatureTest.java b/osgi/hapi-fhir-karaf-integration-tests/src/test/java/ca/uhn/fhir/tests/integration/karaf/dstu3/ResourceValidatorDstu3FeatureTest.java index c2833b3395c..f6ed0fd4af2 100644 --- a/osgi/hapi-fhir-karaf-integration-tests/src/test/java/ca/uhn/fhir/tests/integration/karaf/dstu3/ResourceValidatorDstu3FeatureTest.java +++ b/osgi/hapi-fhir-karaf-integration-tests/src/test/java/ca/uhn/fhir/tests/integration/karaf/dstu3/ResourceValidatorDstu3FeatureTest.java @@ -12,8 +12,8 @@ import ca.uhn.fhir.validation.schematron.SchematronBaseValidator; import org.hamcrest.core.StringContains; import org.hl7.fhir.r5.hapi.validation.FhirInstanceValidator; import org.hl7.fhir.dstu3.model.*; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.ops4j.pax.exam.Configuration; import org.ops4j.pax.exam.Option; import org.ops4j.pax.exam.junit.PaxExam; @@ -28,7 +28,7 @@ import java.util.List; import static ca.uhn.fhir.tests.integration.karaf.PaxExamOptions.*; import static org.hamcrest.Matchers.*; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import static org.ops4j.pax.exam.CoreOptions.*; import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.debugConfiguration; diff --git a/osgi/hapi-fhir-karaf-integration-tests/src/test/java/ca/uhn/fhir/tests/integration/karaf/r4/FhirInstanceValidatorR4Test.java b/osgi/hapi-fhir-karaf-integration-tests/src/test/java/ca/uhn/fhir/tests/integration/karaf/r4/FhirInstanceValidatorR4Test.java index 1ae2468018f..03436b812bc 100644 --- a/osgi/hapi-fhir-karaf-integration-tests/src/test/java/ca/uhn/fhir/tests/integration/karaf/r4/FhirInstanceValidatorR4Test.java +++ b/osgi/hapi-fhir-karaf-integration-tests/src/test/java/ca/uhn/fhir/tests/integration/karaf/r4/FhirInstanceValidatorR4Test.java @@ -13,8 +13,8 @@ import org.hl7.fhir.r4.model.Patient; import org.hl7.fhir.r4.model.StringType; import org.hl7.fhir.r4.model.StructureDefinition; import org.hl7.fhir.r4.utils.FHIRPathEngine; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.ops4j.pax.exam.Configuration; import org.ops4j.pax.exam.Option; import org.ops4j.pax.exam.junit.PaxExam; @@ -24,9 +24,9 @@ import org.ops4j.pax.exam.spi.reactors.PerClass; import static ca.uhn.fhir.tests.integration.karaf.PaxExamOptions.HAPI_FHIR_VALIDATION_R4; import static ca.uhn.fhir.tests.integration.karaf.PaxExamOptions.KARAF; import static ca.uhn.fhir.tests.integration.karaf.PaxExamOptions.WRAP; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.ops4j.pax.exam.CoreOptions.mavenBundle; import static org.ops4j.pax.exam.CoreOptions.options; import static org.ops4j.pax.exam.CoreOptions.when; diff --git a/osgi/hapi-fhir-karaf-integration-tests/src/test/java/ca/uhn/fhir/tests/integration/karaf/r4/R4JsonParserTest.java b/osgi/hapi-fhir-karaf-integration-tests/src/test/java/ca/uhn/fhir/tests/integration/karaf/r4/R4JsonParserTest.java index 8dc714c8e6e..e04ed9b65d4 100644 --- a/osgi/hapi-fhir-karaf-integration-tests/src/test/java/ca/uhn/fhir/tests/integration/karaf/r4/R4JsonParserTest.java +++ b/osgi/hapi-fhir-karaf-integration-tests/src/test/java/ca/uhn/fhir/tests/integration/karaf/r4/R4JsonParserTest.java @@ -9,8 +9,8 @@ import com.google.common.collect.Sets; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; import org.hl7.fhir.r4.model.*; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.ops4j.pax.exam.Configuration; import org.ops4j.pax.exam.Option; import org.ops4j.pax.exam.junit.PaxExam; @@ -22,9 +22,9 @@ import static ca.uhn.fhir.tests.integration.karaf.PaxExamOptions.KARAF; import static ca.uhn.fhir.tests.integration.karaf.PaxExamOptions.WRAP; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.core.IsNot.not; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.hamcrest.MatcherAssert.assertThat; import static org.mockito.ArgumentMatchers.contains; import static org.ops4j.pax.exam.CoreOptions.mavenBundle; import static org.ops4j.pax.exam.CoreOptions.options; diff --git a/osgi/hapi-fhir-karaf-integration-tests/src/test/java/ca/uhn/fhir/tests/integration/karaf/r4/R4XmlParserTest.java b/osgi/hapi-fhir-karaf-integration-tests/src/test/java/ca/uhn/fhir/tests/integration/karaf/r4/R4XmlParserTest.java index 5744d4d3d9d..ca200b421f9 100644 --- a/osgi/hapi-fhir-karaf-integration-tests/src/test/java/ca/uhn/fhir/tests/integration/karaf/r4/R4XmlParserTest.java +++ b/osgi/hapi-fhir-karaf-integration-tests/src/test/java/ca/uhn/fhir/tests/integration/karaf/r4/R4XmlParserTest.java @@ -9,8 +9,8 @@ import com.google.common.collect.Sets; import org.hamcrest.core.IsNot; import org.hl7.fhir.r4.model.Bundle; import org.hl7.fhir.r4.model.Patient; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.ops4j.pax.exam.Configuration; import org.ops4j.pax.exam.Option; import org.ops4j.pax.exam.junit.PaxExam; @@ -21,9 +21,9 @@ import static ca.uhn.fhir.tests.integration.karaf.PaxExamOptions.HAPI_FHIR_R4; import static ca.uhn.fhir.tests.integration.karaf.PaxExamOptions.KARAF; import static ca.uhn.fhir.tests.integration.karaf.PaxExamOptions.WRAP; import static org.hamcrest.Matchers.containsString; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.hamcrest.MatcherAssert.assertThat; import static org.ops4j.pax.exam.CoreOptions.mavenBundle; import static org.ops4j.pax.exam.CoreOptions.options; import static org.ops4j.pax.exam.CoreOptions.when; diff --git a/pom.xml b/pom.xml index d08478a05a1..7f51d3c9e97 100644 --- a/pom.xml +++ b/pom.xml @@ -71,15 +71,19 @@ - junit - junit + org.junit.jupiter + junit-jupiter + test + + + org.junit.jupiter + junit-jupiter-api + test + + + org.junit.jupiter + junit-jupiter-engine test - - - org.hamcrest - hamcrest-core - - org.hamcrest @@ -91,6 +95,11 @@ mockito-core test + + org.mockito + mockito-junit-jupiter + test + @@ -692,7 +701,8 @@ 10.14.2.0 2.3.4 - 2.3.3 + 2.3.4 + 0.7.9 29.0-jre 2.8.5 2.2.11_1 @@ -999,11 +1009,6 @@ javax.ws.rs-api 2.0.1 - - junit - junit - 4.12 - io.github.devacfr.maven.skins reflow-velocity-tools @@ -1401,6 +1406,24 @@ javassist 3.22.0-GA + + org.junit.jupiter + junit-jupiter + 5.6.2 + test + + + org.junit.jupiter + junit-jupiter-api + 5.6.2 + test + + + org.junit.jupiter + junit-jupiter-engine + 5.6.2 + test + org.mariadb.jdbc mariadb-java-client @@ -1411,6 +1434,11 @@ mockito-core 3.3.3 + + org.mockito + mockito-junit-jupiter + 3.3.3 + org.postgresql postgresql @@ -1691,33 +1719,6 @@ 2000m - diff --git a/tests/hapi-fhir-base-test-jaxrsserver-kotlin/src/test/kotlin/ca/uhn/fhir/jaxrs/server/example/ExtendedOrganizationResourceTest.kt b/tests/hapi-fhir-base-test-jaxrsserver-kotlin/src/test/kotlin/ca/uhn/fhir/jaxrs/server/example/ExtendedOrganizationResourceTest.kt index edff3030942..48d87593314 100644 --- a/tests/hapi-fhir-base-test-jaxrsserver-kotlin/src/test/kotlin/ca/uhn/fhir/jaxrs/server/example/ExtendedOrganizationResourceTest.kt +++ b/tests/hapi-fhir-base-test-jaxrsserver-kotlin/src/test/kotlin/ca/uhn/fhir/jaxrs/server/example/ExtendedOrganizationResourceTest.kt @@ -7,12 +7,12 @@ import org.apache.commons.lang3.StringUtils import org.eclipse.jetty.server.Server import org.eclipse.jetty.servlet.ServletContextHandler import org.hamcrest.CoreMatchers.`is` +import org.hamcrest.MatcherAssert.assertThat import org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder import org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher -import org.junit.AfterClass -import org.junit.Assert.assertThat -import org.junit.BeforeClass -import org.junit.Test +import org.junit.jupiter.api.AfterAll +import org.junit.jupiter.api.BeforeAll +import org.junit.jupiter.api.Test import javax.ws.rs.core.Response class ExtendedOrganizationResourceTest { @@ -36,7 +36,7 @@ class ExtendedOrganizationResourceTest { private lateinit var jettyServer: Server @JvmStatic - @AfterClass + @AfterAll @Throws(Exception::class) fun afterClassClearContext() { JettyUtil.closeServer(jettyServer) @@ -44,7 +44,7 @@ class ExtendedOrganizationResourceTest { } @JvmStatic - @BeforeClass + @BeforeAll @Throws(Exception::class) fun setUpClass() { val context = ServletContextHandler(ServletContextHandler.SESSIONS).also { diff --git a/tests/hapi-fhir-base-test-mindeps-client/src/test/java/ca/uhn/fhir/rest/client/ClientTest.java b/tests/hapi-fhir-base-test-mindeps-client/src/test/java/ca/uhn/fhir/rest/client/ClientTest.java index 0277fcabf81..cabac68d204 100644 --- a/tests/hapi-fhir-base-test-mindeps-client/src/test/java/ca/uhn/fhir/rest/client/ClientTest.java +++ b/tests/hapi-fhir-base-test-mindeps-client/src/test/java/ca/uhn/fhir/rest/client/ClientTest.java @@ -1,10 +1,10 @@ package ca.uhn.fhir.rest.client; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.fail; import org.hl7.fhir.dstu3.model.Bundle; import org.hl7.fhir.dstu3.model.Patient; -import org.junit.Test; +import org.junit.jupiter.api.Test; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.rest.client.api.IGenericClient; diff --git a/tests/hapi-fhir-base-test-mindeps-server/src/test/java/ca/uhn/fhir/parser/MultiVersionJsonParserTest.java b/tests/hapi-fhir-base-test-mindeps-server/src/test/java/ca/uhn/fhir/parser/MultiVersionJsonParserTest.java index 2743ef1e9b0..c8cc75290f5 100644 --- a/tests/hapi-fhir-base-test-mindeps-server/src/test/java/ca/uhn/fhir/parser/MultiVersionJsonParserTest.java +++ b/tests/hapi-fhir-base-test-mindeps-server/src/test/java/ca/uhn/fhir/parser/MultiVersionJsonParserTest.java @@ -1,9 +1,9 @@ package ca.uhn.fhir.parser; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; -import org.junit.Test; +import org.junit.jupiter.api.Test; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.dstu2.composite.QuantityDt; diff --git a/tests/hapi-fhir-base-test-mindeps-server/src/test/java/ca/uhn/fhir/parser/MultiVersionXmlParserTest.java b/tests/hapi-fhir-base-test-mindeps-server/src/test/java/ca/uhn/fhir/parser/MultiVersionXmlParserTest.java index 59ac760b172..beee81ad933 100644 --- a/tests/hapi-fhir-base-test-mindeps-server/src/test/java/ca/uhn/fhir/parser/MultiVersionXmlParserTest.java +++ b/tests/hapi-fhir-base-test-mindeps-server/src/test/java/ca/uhn/fhir/parser/MultiVersionXmlParserTest.java @@ -1,11 +1,5 @@ package ca.uhn.fhir.parser; -import static org.junit.Assert.*; - -import org.hamcrest.Matchers; -import org.junit.AfterClass; -import org.junit.Test; - import ca.uhn.fhir.context.ConfigurationException; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.model.dstu2.composite.QuantityDt; @@ -13,18 +7,19 @@ import ca.uhn.fhir.model.dstu2.resource.Organization; import ca.uhn.fhir.model.dstu2.resource.Patient; import ca.uhn.fhir.model.dstu2.valueset.QuantityComparatorEnum; import ca.uhn.fhir.util.TestUtil; +import org.hamcrest.Matchers; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Test; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; public class MultiVersionXmlParserTest { + private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(MultiVersionXmlParserTest.class); private static FhirContext ourCtxDstu2 = FhirContext.forDstu2(); private static FhirContext ourCtxDstu3 = FhirContext.forDstu3(); - - private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(MultiVersionXmlParserTest.class); - - @AfterClass - public static void afterClassClearContext() { - TestUtil.clearAllStaticFieldsForUnitTest(); - } @Test public void testEncodeExtensionFromDifferentVersion() { @@ -36,7 +31,7 @@ public class MultiVersionXmlParserTest { str = ourCtxDstu2.newXmlParser().encodeResourceToString(p); ourLog.info(str); assertThat(str, Matchers.stringContainsInOrder("")); + "")); try { FhirContext.forDstu3().newXmlParser().encodeResourceToString(p); @@ -52,14 +47,14 @@ public class MultiVersionXmlParserTest { Organization o = new Organization(); o.getNameElement().setValue("Some Org"); o.getPartOf().setDisplay("Part Of"); - + Patient p = new Patient(); p.getText().getDiv().setValueAsString("
DIV
"); p.getManagingOrganization().setDisplay("RR Display"); p.getManagingOrganization().setResource(o); - + String res = ourCtxDstu2.newXmlParser().encodeResourceToString(p); - + try { ourCtxDstu3.newXmlParser().parseResource(ca.uhn.fhir.model.dstu2.resource.Patient.class, res); fail(); @@ -72,8 +67,13 @@ public class MultiVersionXmlParserTest { } catch (ConfigurationException e) { assertEquals("This context is for FHIR version \"DSTU3\" but the class \"ca.uhn.fhir.model.dstu2.resource.Patient\" is for version \"DSTU2\"", e.getMessage()); } - + } - - + + @AfterAll + public static void afterClassClearContext() { + TestUtil.clearAllStaticFieldsForUnitTest(); + } + + } diff --git a/tests/hapi-fhir-base-test-mindeps-server/src/test/java/ca/uhn/fhir/testmindeps/FhirContextTest.java b/tests/hapi-fhir-base-test-mindeps-server/src/test/java/ca/uhn/fhir/testmindeps/FhirContextTest.java index 7024e37b023..388bf972988 100644 --- a/tests/hapi-fhir-base-test-mindeps-server/src/test/java/ca/uhn/fhir/testmindeps/FhirContextTest.java +++ b/tests/hapi-fhir-base-test-mindeps-server/src/test/java/ca/uhn/fhir/testmindeps/FhirContextTest.java @@ -1,8 +1,8 @@ package ca.uhn.fhir.testmindeps; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -import org.junit.Test; +import org.junit.jupiter.api.Test; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.context.RuntimeResourceDefinition; diff --git a/tests/hapi-fhir-base-test-mindeps-server/src/test/java/ca/uhn/fhir/testmindeps/ReadTest.java b/tests/hapi-fhir-base-test-mindeps-server/src/test/java/ca/uhn/fhir/testmindeps/ReadTest.java index a752f0dc548..79a775daa7c 100644 --- a/tests/hapi-fhir-base-test-mindeps-server/src/test/java/ca/uhn/fhir/testmindeps/ReadTest.java +++ b/tests/hapi-fhir-base-test-mindeps-server/src/test/java/ca/uhn/fhir/testmindeps/ReadTest.java @@ -1,7 +1,7 @@ package ca.uhn.fhir.testmindeps; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; import java.util.concurrent.TimeUnit; @@ -12,7 +12,7 @@ import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; -import org.junit.*; +import org.junit.jupiter.api.*; import static org.hamcrest.MatcherAssert.assertThat; import org.mortbay.jetty.Server; import org.mortbay.jetty.servlet.ServletHandler; import org.mortbay.jetty.servlet.ServletHolder; @@ -112,12 +112,12 @@ public class ReadTest { } } - @AfterClass + @AfterAll public static void afterClass() throws Exception { ourServer.stop(); } - @BeforeClass + @BeforeAll public static void beforeClass() throws Exception { ourServer = new Server(0); diff --git a/tests/hapi-fhir-base-test-mindeps-server/src/test/java/ca/uhn/fhir/testmindeps/SetupTest.java b/tests/hapi-fhir-base-test-mindeps-server/src/test/java/ca/uhn/fhir/testmindeps/SetupTest.java index ec6851d0a94..24f829a92ea 100644 --- a/tests/hapi-fhir-base-test-mindeps-server/src/test/java/ca/uhn/fhir/testmindeps/SetupTest.java +++ b/tests/hapi-fhir-base-test-mindeps-server/src/test/java/ca/uhn/fhir/testmindeps/SetupTest.java @@ -1,6 +1,6 @@ package ca.uhn.fhir.testmindeps; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class SetupTest { diff --git a/tests/hapi-fhir-base-test-mindeps-server/src/test/java/ca/uhn/fhir/testmindeps/ValidatorTest.java b/tests/hapi-fhir-base-test-mindeps-server/src/test/java/ca/uhn/fhir/testmindeps/ValidatorTest.java index 387aac67e46..431216c894c 100644 --- a/tests/hapi-fhir-base-test-mindeps-server/src/test/java/ca/uhn/fhir/testmindeps/ValidatorTest.java +++ b/tests/hapi-fhir-base-test-mindeps-server/src/test/java/ca/uhn/fhir/testmindeps/ValidatorTest.java @@ -1,12 +1,12 @@ package ca.uhn.fhir.testmindeps; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import org.hl7.fhir.dstu3.model.Patient; -import org.junit.Test; +import org.junit.jupiter.api.Test; import ca.uhn.fhir.context.FhirContext; import ca.uhn.fhir.validation.FhirValidator;