diff --git a/service/src/test/java/org/databiosphere/workspacedataservice/dataimport/pfb/PfbQuartzJobE2ETest.java b/service/src/test/java/org/databiosphere/workspacedataservice/dataimport/pfb/PfbQuartzJobE2ETest.java index f0392eca43..d58f584d15 100644 --- a/service/src/test/java/org/databiosphere/workspacedataservice/dataimport/pfb/PfbQuartzJobE2ETest.java +++ b/service/src/test/java/org/databiosphere/workspacedataservice/dataimport/pfb/PfbQuartzJobE2ETest.java @@ -2,7 +2,6 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.databiosphere.workspacedataservice.TestTags.SLOW; -import static org.databiosphere.workspacedataservice.dataimport.pfb.PfbTestUtils.buildPfbQuartzJob; import static org.databiosphere.workspacedataservice.dataimport.pfb.PfbTestUtils.stubJobContext; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.ArgumentMatchers.any; @@ -19,13 +18,9 @@ import java.util.Optional; import java.util.UUID; import java.util.stream.Collectors; -import org.databiosphere.workspacedataservice.activitylog.ActivityLogger; -import org.databiosphere.workspacedataservice.dao.JobDao; import org.databiosphere.workspacedataservice.dao.SchedulerDao; import org.databiosphere.workspacedataservice.generated.GenericJobServerModel; import org.databiosphere.workspacedataservice.generated.ImportRequestServerModel; -import org.databiosphere.workspacedataservice.retry.RestClientRetry; -import org.databiosphere.workspacedataservice.service.BatchWriteService; import org.databiosphere.workspacedataservice.service.ImportService; import org.databiosphere.workspacedataservice.service.InstanceService; import org.databiosphere.workspacedataservice.service.RecordOrchestratorService; @@ -63,14 +58,10 @@ @TestInstance(TestInstance.Lifecycle.PER_CLASS) class PfbQuartzJobE2ETest { - @Autowired JobDao jobDao; - @Autowired RestClientRetry restClientRetry; - @Autowired BatchWriteService batchWriteService; - @Autowired ActivityLogger activityLogger; @Autowired RecordOrchestratorService recordOrchestratorService; @Autowired ImportService importService; @Autowired InstanceService instanceService; - + @Autowired private PfbTestSupport testSupport; @MockBean SchedulerDao schedulerDao; @MockBean WorkspaceManagerDao wsmDao; @@ -127,8 +118,7 @@ void importTestResource() throws IOException, JobExecutionException { when(wsmDao.enumerateDataRepoSnapshotReferences(any(), anyInt(), anyInt())) .thenReturn(new ResourceList()); - buildPfbQuartzJob(jobDao, wsmDao, restClientRetry, batchWriteService, activityLogger) - .execute(mockContext); + testSupport.buildPfbQuartzJob().execute(mockContext); /* the testAvroResource should insert: - 3202 record(s) of type activities @@ -184,8 +174,7 @@ void importFourRowsResource() throws IOException, JobExecutionException { when(wsmDao.enumerateDataRepoSnapshotReferences(any(), anyInt(), anyInt())) .thenReturn(new ResourceList()); - buildPfbQuartzJob(jobDao, wsmDao, restClientRetry, batchWriteService, activityLogger) - .execute(mockContext); + testSupport.buildPfbQuartzJob().execute(mockContext); /* the fourRowsAvroResource should insert: - 3 record(s) of type data_release @@ -231,8 +220,7 @@ void numberPrecision() throws IOException, JobExecutionException { when(wsmDao.enumerateDataRepoSnapshotReferences(any(), anyInt(), anyInt())) .thenReturn(new ResourceList()); - buildPfbQuartzJob(jobDao, wsmDao, restClientRetry, batchWriteService, activityLogger) - .execute(mockContext); + testSupport.buildPfbQuartzJob().execute(mockContext); // this record, within the precision.avro file, is known to have numbers with high decimal // precision. Retrieve some of them and check for the expected high-precision values. @@ -271,8 +259,7 @@ void importWithForwardRelations() throws IOException, JobExecutionException { when(wsmDao.enumerateDataRepoSnapshotReferences(any(), anyInt(), anyInt())) .thenReturn(new ResourceList()); - buildPfbQuartzJob(jobDao, wsmDao, restClientRetry, batchWriteService, activityLogger) - .execute(mockContext); + testSupport.buildPfbQuartzJob().execute(mockContext); /* the forwardRelationsAvroResource should insert: - 1 record of type submitted_aligned_reads @@ -321,8 +308,7 @@ void importCyclicalRelations() throws IOException, JobExecutionException { when(wsmDao.enumerateDataRepoSnapshotReferences(any(), anyInt(), anyInt())) .thenReturn(new ResourceList()); - buildPfbQuartzJob(jobDao, wsmDao, restClientRetry, batchWriteService, activityLogger) - .execute(mockContext); + testSupport.buildPfbQuartzJob().execute(mockContext); RecordTypeSchema dataReleaseSchema = recordOrchestratorService.describeRecordType( diff --git a/service/src/test/java/org/databiosphere/workspacedataservice/dataimport/pfb/PfbQuartzJobTest.java b/service/src/test/java/org/databiosphere/workspacedataservice/dataimport/pfb/PfbQuartzJobTest.java index 2f794826f4..936cfd4059 100644 --- a/service/src/test/java/org/databiosphere/workspacedataservice/dataimport/pfb/PfbQuartzJobTest.java +++ b/service/src/test/java/org/databiosphere/workspacedataservice/dataimport/pfb/PfbQuartzJobTest.java @@ -1,6 +1,5 @@ package org.databiosphere.workspacedataservice.dataimport.pfb; -import static org.databiosphere.workspacedataservice.dataimport.pfb.PfbTestUtils.buildPfbQuartzJob; import static org.databiosphere.workspacedataservice.dataimport.pfb.PfbTestUtils.stubJobContext; import static org.databiosphere.workspacedataservice.recordstream.TwoPassStreamingWriteHandler.ImportMode.BASE_ATTRIBUTES; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -26,7 +25,6 @@ import java.util.stream.IntStream; import org.databiosphere.workspacedataservice.activitylog.ActivityLogger; import org.databiosphere.workspacedataservice.dao.JobDao; -import org.databiosphere.workspacedataservice.retry.RestClientRetry; import org.databiosphere.workspacedataservice.service.BatchWriteService; import org.databiosphere.workspacedataservice.service.model.BatchWriteResult; import org.databiosphere.workspacedataservice.workspacemanager.WorkspaceManagerDao; @@ -50,7 +48,7 @@ class PfbQuartzJobTest { @MockBean WorkspaceManagerDao wsmDao; @MockBean BatchWriteService batchWriteService; @MockBean ActivityLogger activityLogger; - @Autowired RestClientRetry restClientRetry; + @Autowired PfbTestSupport testSupport; // test resources used below @Value("classpath:avro/minimal_data.avro") @@ -71,8 +69,7 @@ void linkAllNewSnapshots() { .thenReturn(new ResourceList()); // call linkSnapshots - PfbQuartzJob pfbQuartzJob = - buildPfbQuartzJob(jobDao, wsmDao, restClientRetry, batchWriteService, activityLogger); + PfbQuartzJob pfbQuartzJob = testSupport.buildPfbQuartzJob(); pfbQuartzJob.linkSnapshots(input); // capture calls ArgumentCaptor argumentCaptor = ArgumentCaptor.forClass(SnapshotModel.class); @@ -100,8 +97,7 @@ void linkNothingWhenAllExist() { .thenReturn(resourceList); // call linkSnapshots - PfbQuartzJob pfbQuartzJob = - buildPfbQuartzJob(jobDao, wsmDao, restClientRetry, batchWriteService, activityLogger); + PfbQuartzJob pfbQuartzJob = testSupport.buildPfbQuartzJob(); pfbQuartzJob.linkSnapshots(input); // should not call WSM's create-snapshot-reference at all verify(wsmDao, times(0)).linkSnapshotForPolicy(any()); @@ -129,8 +125,7 @@ void linkSomeWhenSomeExist() { .thenReturn(resourceList); // call linkSnapshots - PfbQuartzJob pfbQuartzJob = - buildPfbQuartzJob(jobDao, wsmDao, restClientRetry, batchWriteService, activityLogger); + PfbQuartzJob pfbQuartzJob = testSupport.buildPfbQuartzJob(); pfbQuartzJob.linkSnapshots(input); // should call WSM's create-snapshot-reference only for the references that didn't already exist @@ -158,8 +153,7 @@ void doNotFailOnMissingSnapshotId() throws JobExecutionException, IOException { when(batchWriteService.batchWritePfbStream(any(), any(), any(), eq(BASE_ATTRIBUTES))) .thenReturn(BatchWriteResult.empty()); - buildPfbQuartzJob(jobDao, wsmDao, restClientRetry, batchWriteService, activityLogger) - .execute(mockContext); + testSupport.buildPfbQuartzJob().execute(mockContext); // Should not call wsm dao verify(wsmDao, times(0)).linkSnapshotForPolicy(any()); @@ -179,8 +173,7 @@ void snapshotIdsAreParsed() throws JobExecutionException, IOException { when(batchWriteService.batchWritePfbStream(any(), any(), any(), eq(BASE_ATTRIBUTES))) .thenReturn(BatchWriteResult.empty()); - buildPfbQuartzJob(jobDao, wsmDao, restClientRetry, batchWriteService, activityLogger) - .execute(mockContext); + testSupport.buildPfbQuartzJob().execute(mockContext); // The "790795c4..." UUID below is the snapshotId found in the "test.avro" resource used // by this unit test diff --git a/service/src/test/java/org/databiosphere/workspacedataservice/dataimport/pfb/PfbTestSupport.java b/service/src/test/java/org/databiosphere/workspacedataservice/dataimport/pfb/PfbTestSupport.java new file mode 100644 index 0000000000..b98ede6b38 --- /dev/null +++ b/service/src/test/java/org/databiosphere/workspacedataservice/dataimport/pfb/PfbTestSupport.java @@ -0,0 +1,30 @@ +package org.databiosphere.workspacedataservice.dataimport.pfb; + +import com.fasterxml.jackson.databind.ObjectMapper; +import java.util.UUID; +import org.databiosphere.workspacedataservice.activitylog.ActivityLogger; +import org.databiosphere.workspacedataservice.dao.JobDao; +import org.databiosphere.workspacedataservice.retry.RestClientRetry; +import org.databiosphere.workspacedataservice.service.BatchWriteService; +import org.databiosphere.workspacedataservice.workspacemanager.WorkspaceManagerDao; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Component +class PfbTestSupport { + @Autowired private JobDao jobDao; + @Autowired private WorkspaceManagerDao wsmDao; + @Autowired private RestClientRetry restClientRetry; + @Autowired private BatchWriteService batchWriteService; + @Autowired private ActivityLogger activityLogger; + @Autowired private ObjectMapper objectMapper; + + PfbQuartzJob buildPfbQuartzJob(UUID workspaceId) { + return new PfbQuartzJob( + jobDao, wsmDao, restClientRetry, batchWriteService, activityLogger, workspaceId); + } + + PfbQuartzJob buildPfbQuartzJob() { + return buildPfbQuartzJob(UUID.randomUUID()); + } +} diff --git a/service/src/test/java/org/databiosphere/workspacedataservice/dataimport/pfb/PfbTestUtils.java b/service/src/test/java/org/databiosphere/workspacedataservice/dataimport/pfb/PfbTestUtils.java index b2a22da036..24a3090ea6 100644 --- a/service/src/test/java/org/databiosphere/workspacedataservice/dataimport/pfb/PfbTestUtils.java +++ b/service/src/test/java/org/databiosphere/workspacedataservice/dataimport/pfb/PfbTestUtils.java @@ -20,11 +20,6 @@ import org.apache.avro.generic.GenericData; import org.apache.avro.generic.GenericRecord; import org.apache.avro.generic.GenericRecordBuilder; -import org.databiosphere.workspacedataservice.activitylog.ActivityLogger; -import org.databiosphere.workspacedataservice.dao.JobDao; -import org.databiosphere.workspacedataservice.retry.RestClientRetry; -import org.databiosphere.workspacedataservice.service.BatchWriteService; -import org.databiosphere.workspacedataservice.workspacemanager.WorkspaceManagerDao; import org.mockito.Mockito; import org.quartz.JobDataMap; import org.quartz.JobExecutionContext; @@ -173,14 +168,4 @@ public static JobExecutionContext stubJobContext(UUID jobId, Resource resource, return mockContext; } - - public static PfbQuartzJob buildPfbQuartzJob( - JobDao jobDao, - WorkspaceManagerDao wsmDao, - RestClientRetry restClientRetry, - BatchWriteService batchWriteService, - ActivityLogger activityLogger) { - return new PfbQuartzJob( - jobDao, wsmDao, restClientRetry, batchWriteService, activityLogger, UUID.randomUUID()); - } }