Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate FhirStoreUtilTest to Junit5 #1135

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -514,8 +514,12 @@ static List<Pipeline> setupAndBuildPipelines(
}

public static void main(String[] args)
throws IOException, SQLException, ViewDefinitionException, ProfileException,
ExecutionException, InterruptedException {
throws IOException,
meetmehta1198 marked this conversation as resolved.
Show resolved Hide resolved
SQLException,
ViewDefinitionException,
ProfileException,
ExecutionException,
InterruptedException {

AvroConversionUtil.initializeAvroConverters();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -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 =
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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 =
Expand Down
13 changes: 13 additions & 0 deletions pipelines/common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,19 @@
<artifactId>beam-sdks-java-io-google-cloud-platform</artifactId>
<version>${beam.version}</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.11.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>5.13.0</version>
<scope>test</scope>
</dependency>
</dependencies>


</project>
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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";
Expand All @@ -49,7 +49,7 @@ public class FetchUtilTest {

FetchUtil fetchUtil;

@Before
@BeforeEach
public void setUp() throws Exception {
fetchUtil =
new FetchUtil(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
meetmehta1198 marked this conversation as resolved.
Show resolved Hide resolved
public class FhirStoreUtilTest {

@Mock(answer = Answers.RETURNS_DEEP_STUBS)
Expand All @@ -61,7 +61,7 @@ public class FhirStoreUtilTest {

private Bundle patientResponseBundle;

@Before
@BeforeEach
public void setup() throws IOException {
IParser jsonParser = FhirContext.forR4().newJsonParser();

Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -64,15 +64,15 @@ 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);
gcsOptions.setGcsUtil(mockGcsUtil);
FileSystems.setDefaultPipelineOptions(gcsOptions);
}

@After
@AfterEach
public void closeService() throws Exception {
closeable.close();
}
Expand Down Expand Up @@ -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));
}
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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\\"));
}
Expand All @@ -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(
Expand All @@ -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\\"));
Expand Down Expand Up @@ -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));

Expand Down Expand Up @@ -231,34 +231,34 @@ 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);
}

@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 {
Expand Down
Loading
Loading