diff --git a/src/main/java/org/ilgcc/jobs/TransmissionsRecurringJob.java b/src/main/java/org/ilgcc/jobs/TransmissionsRecurringJob.java index b3ce136dd..da1f1bf4a 100644 --- a/src/main/java/org/ilgcc/jobs/TransmissionsRecurringJob.java +++ b/src/main/java/org/ilgcc/jobs/TransmissionsRecurringJob.java @@ -20,9 +20,11 @@ import org.jobrunr.jobs.annotations.Recurring; import org.jobrunr.scheduling.JobScheduler; import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.stereotype.Service; @Slf4j +@ConditionalOnProperty(name="il-gcc.dts.expand-existing-provider-flow", havingValue = "true") @Service public class TransmissionsRecurringJob { @@ -32,7 +34,6 @@ public class TransmissionsRecurringJob { private final UploadedDocumentTransmissionJob uploadedDocumentTransmissionJob; private final PdfService pdfService; private final CloudFileRepository cloudFileRepository; - private Boolean expandExistingProviderFlow; private final PdfTransmissionJob pdfTransmissionJob; private final EnqueueDocumentTransfer enqueueDocumentTransfer; @@ -40,7 +41,6 @@ public TransmissionsRecurringJob(S3PresignService s3PresignService, TransmissionRepositoryService transmissionRepositoryService, UserFileRepositoryService userFileRepositoryService, UploadedDocumentTransmissionJob uploadedDocumentTransmissionJob, PdfService pdfService, CloudFileRepository cloudFileRepository, PdfTransmissionJob pdfTransmissionJob, - @Value("${il-gcc.dts.expand-existing-provider-flow}") Boolean expandExistingProviderFlow, EnqueueDocumentTransfer enqueueDocumentTransfer) { this.s3PresignService = s3PresignService; this.transmissionRepositoryService = transmissionRepositoryService; @@ -49,11 +49,10 @@ public TransmissionsRecurringJob(S3PresignService s3PresignService, this.pdfService = pdfService; this.cloudFileRepository = cloudFileRepository; this.pdfTransmissionJob = pdfTransmissionJob; - this.expandExistingProviderFlow = expandExistingProviderFlow; this.enqueueDocumentTransfer = enqueueDocumentTransfer; } - @Recurring(id = "no-provider-response-job", cron = "* * * * *") + @Recurring(id = "no-provider-response-job", cron = "0 * * * *") @Job(name = "No provider response job") public void noProviderResponseJob() { List submissionsWithoutTransmissions = transmissionRepositoryService.findSubmissionsWithoutTransmission(); @@ -63,7 +62,7 @@ public void noProviderResponseJob() { List expiredSubmissionsWithNoTransmission = submissionsWithoutTransmissions.stream() .filter(submission -> providerApplicationHasExpired(submission, todaysDate)).toList(); - if (expiredSubmissionsWithNoTransmission.isEmpty() || !expandExistingProviderFlow) { + if (expiredSubmissionsWithNoTransmission.isEmpty()) { return; } else { log.info(String.format("Running the 'No provider response job' for %s expired submissions", diff --git a/src/test/java/org/ilgcc/jobs/TransmissionsRecurringJobFlagOffTest.java b/src/test/java/org/ilgcc/jobs/TransmissionsRecurringJobFlagOffTest.java new file mode 100644 index 000000000..18840db29 --- /dev/null +++ b/src/test/java/org/ilgcc/jobs/TransmissionsRecurringJobFlagOffTest.java @@ -0,0 +1,26 @@ +package org.ilgcc.jobs; + +import org.ilgcc.app.IlGCCApplication; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.ApplicationContext; +import org.springframework.test.context.ActiveProfiles; + +import static org.junit.jupiter.api.Assertions.assertFalse; + +@SpringBootTest( + classes = IlGCCApplication.class, + properties = "il-gcc.dts.expand-existing-provider-flow=false" +) +@ActiveProfiles("test") +public class TransmissionsRecurringJobFlagOffTest { + + @Autowired + private ApplicationContext context; + + @Test + public void transmissionRecurringJobDisabledWhenFlagIsOff() { + assertFalse(context.containsBean("transmissionsRecurringJob")); + } +} diff --git a/src/test/java/org/ilgcc/jobs/TransmissionsRecurringJobTest.java b/src/test/java/org/ilgcc/jobs/TransmissionsRecurringJobFlagOnTest.java similarity index 87% rename from src/test/java/org/ilgcc/jobs/TransmissionsRecurringJobTest.java rename to src/test/java/org/ilgcc/jobs/TransmissionsRecurringJobFlagOnTest.java index fe3ccca48..d5b4673ad 100644 --- a/src/test/java/org/ilgcc/jobs/TransmissionsRecurringJobTest.java +++ b/src/test/java/org/ilgcc/jobs/TransmissionsRecurringJobFlagOnTest.java @@ -1,10 +1,17 @@ package org.ilgcc.jobs; +import static org.ilgcc.app.utils.enums.TransmissionStatus.Queued; +import static org.ilgcc.app.utils.enums.TransmissionType.APPLICATION_PDF; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.*; + import formflow.library.data.Submission; import formflow.library.data.SubmissionRepository; import formflow.library.data.UserFileRepositoryService; import formflow.library.file.CloudFileRepository; import formflow.library.pdf.PdfService; +import java.time.OffsetDateTime; import java.util.Date; import org.ilgcc.app.IlGCCApplication; import org.ilgcc.app.data.Transmission; @@ -18,20 +25,17 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; - -import java.time.OffsetDateTime; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.ApplicationContext; import org.springframework.test.context.ActiveProfiles; -import static org.ilgcc.app.utils.enums.TransmissionStatus.Queued; -import static org.ilgcc.app.utils.enums.TransmissionType.APPLICATION_PDF; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.*; - -@SpringBootTest(classes = IlGCCApplication.class) +@SpringBootTest( + classes = IlGCCApplication.class, + properties = "il-gcc.dts.expand-existing-provider-flow=true" +) @ActiveProfiles("test") -public class TransmissionsRecurringJobTest { +public class TransmissionsRecurringJobFlagOnTest { @Autowired private SubmissionRepository submissionRepository; @@ -59,6 +63,9 @@ public class TransmissionsRecurringJobTest { @Mock private PdfTransmissionJob pdfTransmissionJob; + @Autowired + private ApplicationContext context; + @Mock private EnqueueDocumentTransfer enqueueDocumentTransfer; @@ -82,7 +89,6 @@ void setUp() { pdfService, cloudFileRepository, pdfTransmissionJob, - true, enqueueDocumentTransfer ); } @@ -94,30 +100,10 @@ protected void clearSubmissions() { } @Test - void enqueueDocumentTransferWillNotRunIfFlagIsOff() { - expiredSubmission = new SubmissionTestBuilder() - .withParentDetails() - .withSubmittedAtDate(OffsetDateTime.now().minusDays(7)) - .withFlow("gcc") - .build(); - submissionRepository.save(expiredSubmission); - - transmissionsRecurringJob = new TransmissionsRecurringJob( - s3PresignService, - transmissionRepositoryService, - userFileRepositoryService, - uploadedDocumentTransmissionJob, - pdfService, - cloudFileRepository, - pdfTransmissionJob, - false, - enqueueDocumentTransfer - ); - - transmissionsRecurringJob.noProviderResponseJob(); - - verifyNoInteractions(enqueueDocumentTransfer); + public void transmissionRecurringJobEnabledWhenFlagIsOn() { + assertTrue(context.containsBean("transmissionsRecurringJob")); } + @Test void enqueueDocumentTransferIsOnlyCalledOnExpiredSubmissions() { unexpiredSubmission = new SubmissionTestBuilder()