diff --git a/pipelines/batch/src/main/java/com/google/fhir/analytics/FhirEtl.java b/pipelines/batch/src/main/java/com/google/fhir/analytics/FhirEtl.java index bfc23d1ff..759cdde11 100644 --- a/pipelines/batch/src/main/java/com/google/fhir/analytics/FhirEtl.java +++ b/pipelines/batch/src/main/java/com/google/fhir/analytics/FhirEtl.java @@ -514,8 +514,12 @@ static List setupAndBuildPipelines( } public static void main(String[] args) - throws IOException, SQLException, ViewDefinitionException, ProfileException, - ExecutionException, InterruptedException { + throws IOException, + SQLException, + ViewDefinitionException, + ProfileException, + ExecutionException, + InterruptedException { AvroConversionUtil.initializeAvroConverters(); diff --git a/pipelines/batch/src/test/java/com/google/fhir/analytics/ConvertResourceFnTest.java b/pipelines/batch/src/test/java/com/google/fhir/analytics/ConvertResourceFnTest.java index 2bc8c4ba0..dd99ad6d0 100644 --- a/pipelines/batch/src/test/java/com/google/fhir/analytics/ConvertResourceFnTest.java +++ b/pipelines/batch/src/test/java/com/google/fhir/analytics/ConvertResourceFnTest.java @@ -71,8 +71,12 @@ public void setup() throws SQLException, ProfileException { @Test public void testProcessPatientResource_withoutForcedId() - throws IOException, java.text.ParseException, SQLException, PropertyVetoException, - ViewApplicationException, ProfileException { + throws IOException, + java.text.ParseException, + SQLException, + PropertyVetoException, + ViewApplicationException, + ProfileException { String[] args = {"--outputParquetPath=SOME_PATH"}; setUp(args); String patientResourceStr = @@ -96,8 +100,12 @@ public void testProcessPatientResource_withoutForcedId() @Test public void testProcessPatientResource_withForcedId() - throws IOException, java.text.ParseException, SQLException, PropertyVetoException, - ViewApplicationException, ProfileException { + throws IOException, + java.text.ParseException, + SQLException, + PropertyVetoException, + ViewApplicationException, + ProfileException { String[] args = {"--outputParquetPath=SOME_PATH"}; setUp(args); String patientResourceStr = @@ -127,8 +135,12 @@ public void testProcessPatientResource_withForcedId() @Test public void testProcessDeletedPatientResourceFullMode() - throws SQLException, IOException, ParseException, PropertyVetoException, - ViewApplicationException, ProfileException { + throws SQLException, + IOException, + ParseException, + PropertyVetoException, + ViewApplicationException, + ProfileException { String[] args = {"--outputParquetPath=SOME_PATH", "--since="}; setUp(args); // Deleted Patient resource @@ -142,8 +154,12 @@ public void testProcessDeletedPatientResourceFullMode() @Test public void testProcessDeletedPatientResourceIncrementalMode() - throws SQLException, IOException, ParseException, PropertyVetoException, - ViewApplicationException, ProfileException { + throws SQLException, + IOException, + ParseException, + PropertyVetoException, + ViewApplicationException, + ProfileException { String[] args = {"--outputParquetPath=SOME_PATH", "--since=NON-EMPTY"}; setUp(args); // Deleted Patient resource @@ -170,8 +186,12 @@ public void testProcessDeletedPatientResourceIncrementalMode() @Test public void testResourceMetaTags() - throws IOException, java.text.ParseException, SQLException, PropertyVetoException, - ViewApplicationException, ProfileException { + throws IOException, + java.text.ParseException, + SQLException, + PropertyVetoException, + ViewApplicationException, + ProfileException { String[] args = {"--outputParquetPath=SOME_PATH", "--since="}; setUp(args); String patientResourceStr = diff --git a/pipelines/common/pom.xml b/pipelines/common/pom.xml index 7f585088c..ba491a225 100644 --- a/pipelines/common/pom.xml +++ b/pipelines/common/pom.xml @@ -251,6 +251,19 @@ beam-sdks-java-io-google-cloud-platform ${beam.version} + + org.junit.jupiter + junit-jupiter-api + 5.11.0 + test + + + org.mockito + mockito-junit-jupiter + 5.13.0 + test + + diff --git a/pipelines/common/src/test/java/com/google/fhir/analytics/AvroConversionUtilTest.java b/pipelines/common/src/test/java/com/google/fhir/analytics/AvroConversionUtilTest.java index 46702e78c..d7b5007fc 100644 --- a/pipelines/common/src/test/java/com/google/fhir/analytics/AvroConversionUtilTest.java +++ b/pipelines/common/src/test/java/com/google/fhir/analytics/AvroConversionUtilTest.java @@ -45,19 +45,19 @@ import org.hl7.fhir.r4.model.Observation; import org.hl7.fhir.r4.model.Patient; import org.hl7.fhir.r4.model.Resource; -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; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class AvroConversionUtilTest { private String patientBundle; private String observationBundle; private String usCoreProfilesStructureDefinitionsPath; public static final String BASE_PATIENT = "http://hl7.org/fhir/StructureDefinition/Patient"; - @Before + @BeforeEach public void setup() throws IOException, ClassNotFoundException, URISyntaxException, ProfileException { AvroConversionUtil.initializeAvroConverters(); diff --git a/pipelines/common/src/test/java/com/google/fhir/analytics/FetchUtilTest.java b/pipelines/common/src/test/java/com/google/fhir/analytics/FetchUtilTest.java index 56885f9ae..e04aa5c77 100644 --- a/pipelines/common/src/test/java/com/google/fhir/analytics/FetchUtilTest.java +++ b/pipelines/common/src/test/java/com/google/fhir/analytics/FetchUtilTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2020-2023 Google LLC + * Copyright 2020-2024 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,14 +26,14 @@ import ca.uhn.fhir.rest.client.api.IGenericClient; import ca.uhn.fhir.rest.client.impl.RestfulClientFactory; 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.mockito.Answers; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class FetchUtilTest { private static final String SOURCE_FHIR_URL = "someurl"; @@ -49,7 +49,7 @@ public class FetchUtilTest { FetchUtil fetchUtil; - @Before + @BeforeEach public void setUp() throws Exception { fetchUtil = new FetchUtil( diff --git a/pipelines/common/src/test/java/com/google/fhir/analytics/FhirStoreUtilTest.java b/pipelines/common/src/test/java/com/google/fhir/analytics/FhirStoreUtilTest.java index e095c4ab0..edada81bd 100644 --- a/pipelines/common/src/test/java/com/google/fhir/analytics/FhirStoreUtilTest.java +++ b/pipelines/common/src/test/java/com/google/fhir/analytics/FhirStoreUtilTest.java @@ -32,15 +32,15 @@ import org.hamcrest.Matchers; import org.hl7.fhir.r4.model.Bundle; 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.mockito.Answers; import org.mockito.ArgumentMatchers; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class FhirStoreUtilTest { @Mock(answer = Answers.RETURNS_DEEP_STUBS) @@ -61,7 +61,7 @@ public class FhirStoreUtilTest { private Bundle patientResponseBundle; - @Before + @BeforeEach public void setup() throws IOException { IParser jsonParser = FhirContext.forR4().newJsonParser(); @@ -82,10 +82,13 @@ public void setup() throws IOException { patient = (Patient) patientBundle.getEntryFirstRep().getResource(); when(clientFactory.newGenericClient(sinkUrl)).thenReturn(client); - when(client.update().resource(patient).withId(patient.getId()).encodedJson()).thenReturn(iexec); - when(client.transaction().withBundle(ArgumentMatchers.any(Bundle.class)).execute()) + lenient() + .when(client.update().resource(patient).withId(patient.getId()).encodedJson()) + .thenReturn(iexec); + lenient() + .when(client.transaction().withBundle(ArgumentMatchers.any(Bundle.class)).execute()) .thenReturn(patientResponseBundle); - doReturn(outcome).when(iexec).execute(); + lenient().doReturn(outcome).when(iexec).execute(); fhirStoreUtil = FhirStoreUtil.createFhirStoreUtil(sinkUrl, clientFactory); } diff --git a/pipelines/common/src/test/java/com/google/fhir/analytics/GZipUtilTest.java b/pipelines/common/src/test/java/com/google/fhir/analytics/GZipUtilTest.java index ebb04f3a3..25e58ef5c 100644 --- a/pipelines/common/src/test/java/com/google/fhir/analytics/GZipUtilTest.java +++ b/pipelines/common/src/test/java/com/google/fhir/analytics/GZipUtilTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2020-2023 Google LLC + * Copyright 2020-2024 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,11 +24,11 @@ import java.nio.charset.StandardCharsets; import java.util.zip.GZIPOutputStream; import org.apache.commons.io.IOUtils; -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; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class GZipUtilTest { @Test diff --git a/pipelines/common/src/test/java/com/google/fhir/analytics/GcsDwhFilesTest.java b/pipelines/common/src/test/java/com/google/fhir/analytics/GcsDwhFilesTest.java index 8e260197b..8fdb91601 100644 --- a/pipelines/common/src/test/java/com/google/fhir/analytics/GcsDwhFilesTest.java +++ b/pipelines/common/src/test/java/com/google/fhir/analytics/GcsDwhFilesTest.java @@ -50,10 +50,10 @@ import org.apache.beam.sdk.options.PipelineOptionsFactory; import org.apache.beam.sdk.util.MimeTypes; import org.checkerframework.checker.nullness.qual.Nullable; -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.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; @@ -64,7 +64,7 @@ public class GcsDwhFilesTest { @Mock private GcsUtil mockGcsUtil; private AutoCloseable closeable; - @Before + @BeforeEach public void setUp() { closeable = MockitoAnnotations.openMocks(this); GcsOptions gcsOptions = PipelineOptionsFactory.as(GcsOptions.class); @@ -72,7 +72,7 @@ public void setUp() { FileSystems.setDefaultPipelineOptions(gcsOptions); } - @After + @AfterEach public void closeService() throws Exception { closeable.close(); } @@ -176,7 +176,7 @@ public void writeTimestampFile_FileAlreadyExists_ThrowsError() throws IOExceptio Mockito.when(mockGcsUtil.getObjects(List.of(GcsPath.fromUri(gcsFileName)))).thenReturn(items); DwhFiles dwhFiles = new DwhFiles("gs://testbucket/testdirectory", FhirContext.forR4Cached()); - Assert.assertThrows( + Assertions.assertThrows( FileAlreadyExistsException.class, () -> dwhFiles.writeTimestampFile(DwhFiles.TIMESTAMP_FILE_START)); } @@ -215,14 +215,14 @@ public void readTimestampFile() throws IOException { DwhFiles dwhFiles = new DwhFiles("gs://testbucket/testdirectory", FhirContext.forR4Cached()); Instant actualInstant = dwhFiles.readTimestampFile(DwhFiles.TIMESTAMP_FILE_START); - Assert.assertEquals(currentInstant.getEpochSecond(), actualInstant.getEpochSecond()); + Assertions.assertEquals(currentInstant.getEpochSecond(), actualInstant.getEpochSecond()); Mockito.verify(mockGcsUtil, Mockito.times(1)).open(GcsPath.fromUri(gcsFileName)); } @Test public void dwhRootPrefixForGCSPath_returnsFileSeparator() { String fileSeparator = DwhFiles.getFileSeparatorForDwhFiles("gs://testbucket/testdirectory"); - Assert.assertEquals("/", fileSeparator); + Assertions.assertEquals("/", fileSeparator); } private void mockFileRead(String gcsFileName, Instant instant) throws IOException { diff --git a/pipelines/common/src/test/java/com/google/fhir/analytics/LocalDwhFilesTest.java b/pipelines/common/src/test/java/com/google/fhir/analytics/LocalDwhFilesTest.java index 5268d8d78..72bea7ece 100644 --- a/pipelines/common/src/test/java/com/google/fhir/analytics/LocalDwhFilesTest.java +++ b/pipelines/common/src/test/java/com/google/fhir/analytics/LocalDwhFilesTest.java @@ -38,21 +38,21 @@ import org.apache.beam.sdk.io.fs.ResolveOptions.StandardResolveOptions; import org.apache.beam.sdk.io.fs.ResourceId; import org.apache.commons.lang3.SystemUtils; -import org.junit.Assert; -import org.junit.Assume; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Assumptions; +import org.junit.jupiter.api.Test; public class LocalDwhFilesTest { @Test public void getResourcePathTestNonWindows() { - Assume.assumeFalse(SystemUtils.IS_OS_WINDOWS); + Assumptions.assumeFalse(SystemUtils.IS_OS_WINDOWS); DwhFiles dwhFiles = new DwhFiles("/tmp", FhirContext.forR4Cached()); assertThat(dwhFiles.getResourcePath("Patient").toString(), equalTo("/tmp/Patient/")); } @Test public void getResourcePathTestWindows() { - Assume.assumeTrue(SystemUtils.IS_OS_WINDOWS); + Assumptions.assumeTrue(SystemUtils.IS_OS_WINDOWS); DwhFiles dwhFiles = new DwhFiles("C:\\tmp", FhirContext.forR4Cached()); assertThat(dwhFiles.getResourcePath("Patient").toString(), equalTo("C:\\tmp\\Patient\\")); } @@ -76,7 +76,7 @@ public void getIncrementalRunPathTest() throws IOException { @Test public void newIncrementalRunPathTestNonWindows() throws IOException { - Assume.assumeFalse(SystemUtils.IS_OS_WINDOWS); + Assumptions.assumeFalse(SystemUtils.IS_OS_WINDOWS); DwhFiles instance = new DwhFiles("/tmp", FhirContext.forR4Cached()); ResourceId incrementalRunPath = instance.newIncrementalRunPath(); assertThat( @@ -86,7 +86,7 @@ public void newIncrementalRunPathTestNonWindows() throws IOException { @Test public void newIncrementalRunPathTesWindows() throws IOException { - Assume.assumeTrue(SystemUtils.IS_OS_WINDOWS); + Assumptions.assumeTrue(SystemUtils.IS_OS_WINDOWS); DwhFiles instance = new DwhFiles("C:\\tmp", FhirContext.forR4Cached()); ResourceId incrementalRunPath = instance.newIncrementalRunPath(); assertThat(incrementalRunPath.toString(), equalTo("C:\\tmp\\incremental_run\\")); @@ -197,7 +197,7 @@ public void writeTimestampFile_FileAlreadyExists_ThrowsError() throws IOExceptio createFile(timestampPath, Instant.now().toString().getBytes(StandardCharsets.UTF_8)); DwhFiles dwhFiles = new DwhFiles(root.toString(), FhirContext.forR4Cached()); - Assert.assertThrows( + Assertions.assertThrows( FileAlreadyExistsException.class, () -> dwhFiles.writeTimestampFile(DwhFiles.TIMESTAMP_FILE_START)); @@ -231,7 +231,7 @@ public void readTimestampFile() throws IOException { Instant actualInstant = dwhFiles.readTimestampFile(DwhFiles.TIMESTAMP_FILE_START); - Assert.assertEquals(currentInstant.getEpochSecond(), actualInstant.getEpochSecond()); + Assertions.assertEquals(currentInstant.getEpochSecond(), actualInstant.getEpochSecond()); Files.delete(timestampPath); Files.delete(root); @@ -239,26 +239,26 @@ public void readTimestampFile() throws IOException { @Test public void passNonWindowsLocalPathDwhRootPrefix_returnsFileSeparator() { - Assume.assumeFalse(SystemUtils.IS_OS_WINDOWS); + Assumptions.assumeFalse(SystemUtils.IS_OS_WINDOWS); // Absolute Path String fs1 = DwhFiles.getFileSeparatorForDwhFiles("/rootDir/prefix"); - Assert.assertEquals(File.separator, fs1); + Assertions.assertEquals(File.separator, fs1); // Relative Path String fs2 = DwhFiles.getFileSeparatorForDwhFiles("baseDir/prefix"); - Assert.assertEquals(File.separator, fs2); + Assertions.assertEquals(File.separator, fs2); } @Test public void passWindowsLocalPathDwhRootPrefix_returnsFileSeparator() { - Assume.assumeTrue(SystemUtils.IS_OS_WINDOWS); + Assumptions.assumeTrue(SystemUtils.IS_OS_WINDOWS); // Absolute Path String fs1 = DwhFiles.getFileSeparatorForDwhFiles("C:\\prefix"); - Assert.assertEquals(File.separator, fs1); + Assertions.assertEquals(File.separator, fs1); String fs2 = DwhFiles.getFileSeparatorForDwhFiles("C:\\rootDir\\prefix"); - Assert.assertEquals(File.separator, fs2); + Assertions.assertEquals(File.separator, fs2); // Relative Path String fs3 = DwhFiles.getFileSeparatorForDwhFiles("baseDir\\prefix"); - Assert.assertEquals(File.separator, fs3); + Assertions.assertEquals(File.separator, fs3); } private void createFile(Path path, byte[] bytes) throws IOException { diff --git a/pipelines/common/src/test/java/com/google/fhir/analytics/ParquetUtilTest.java b/pipelines/common/src/test/java/com/google/fhir/analytics/ParquetUtilTest.java index 005a7535f..12b421952 100644 --- a/pipelines/common/src/test/java/com/google/fhir/analytics/ParquetUtilTest.java +++ b/pipelines/common/src/test/java/com/google/fhir/analytics/ParquetUtilTest.java @@ -36,22 +36,19 @@ import org.hl7.fhir.r4.model.Bundle; import org.hl7.fhir.r4.model.Observation; import org.hl7.fhir.r4.model.QuestionnaireResponse; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; -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.junit.jupiter.api.io.TempDir; +import org.mockito.junit.jupiter.MockitoExtension; // TODO add testes for DSTU3 resources too. -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class ParquetUtilTest { private static final String PARQUET_ROOT = "parquet_root"; - private String patientBundle; - private String observationBundle; private ParquetUtil parquetUtil; @@ -60,16 +57,15 @@ public class ParquetUtilTest { private Path rootPath; - @Rule public TemporaryFolder testFolder = new TemporaryFolder(); + @TempDir File temporaryFolder; - @Before + @BeforeEach public void setup() throws IOException, ProfileException { - File rootFolder = testFolder.newFolder(PARQUET_ROOT); + File rootFolder = new File(temporaryFolder, PARQUET_ROOT); rootPath = Paths.get(rootFolder.getPath()); Files.createDirectories(rootPath); AvroConversionUtil.initializeAvroConverters(); - patientBundle = - Resources.toString(Resources.getResource("patient_bundle.json"), StandardCharsets.UTF_8); + observationBundle = Resources.toString( Resources.getResource("observation_bundle.json"), StandardCharsets.UTF_8); diff --git a/pipelines/controller/src/main/java/com/google/fhir/analytics/PipelineManager.java b/pipelines/controller/src/main/java/com/google/fhir/analytics/PipelineManager.java index f4ad85241..326ae7bb0 100644 --- a/pipelines/controller/src/main/java/com/google/fhir/analytics/PipelineManager.java +++ b/pipelines/controller/src/main/java/com/google/fhir/analytics/PipelineManager.java @@ -369,7 +369,10 @@ DwhRunDetails getLastRunDetails() { // Every 30 seconds, check for pipeline status and incremental pipeline schedule. @Scheduled(fixedDelay = 30000) private void checkSchedule() - throws IOException, PropertyVetoException, SQLException, ViewDefinitionException, + throws IOException, + PropertyVetoException, + SQLException, + ViewDefinitionException, ProfileException { LocalDateTime next = getNextIncrementalTime(); if (next == null) { diff --git a/pom.xml b/pom.xml index 180dee551..bc3bfc428 100644 --- a/pom.xml +++ b/pom.xml @@ -131,7 +131,7 @@ - 1.15.0 + 1.17.0 true