Search in sources :

Example 1 with PropertiesService

use of gov.cms.ab2d.common.service.PropertiesService in project ab2d by CMSgov.

the class CoverageCheckQuartzJobTest method whenVerificationException_alertWithIssues.

@DisplayName("Report issues when verification detects issues")
@Test
void whenVerificationException_alertWithIssues() {
    when(propertiesService.isInMaintenanceMode()).thenReturn(false);
    doThrow(new CoverageVerificationException("testing123", List.of("alertalert"))).when(coverageDriver).verifyCoverage();
    CoverageCheckQuartzJob job = new CoverageCheckQuartzJob(logManager, coverageDriver, propertiesService);
    JobExecutionException exception = assertThrows(JobExecutionException.class, () -> job.executeInternal(null));
    assertTrue(exception.getMessage().contains("testing123"));
    verify(propertiesService, times(1)).isInMaintenanceMode();
    verify(coverageDriver, times(1)).verifyCoverage();
    verify(logManager, times(1)).alert(argThat(alert -> alert.contains("alertalert") && alert.contains("Coverage verification failed")), anyList());
}
Also used : MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) LogManager(gov.cms.ab2d.eventlogger.LogManager) CoverageDriver(gov.cms.ab2d.worker.processor.coverage.CoverageDriver) Mock(org.mockito.Mock) CoverageVerificationException(gov.cms.ab2d.worker.processor.coverage.CoverageVerificationException) DisplayName(org.junit.jupiter.api.DisplayName) Test(org.junit.jupiter.api.Test) JobExecutionException(org.quartz.JobExecutionException) Mockito(org.mockito.Mockito) AfterEach(org.junit.jupiter.api.AfterEach) List(java.util.List) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) PropertiesService(gov.cms.ab2d.common.service.PropertiesService) Assertions(org.junit.jupiter.api.Assertions) JobExecutionException(org.quartz.JobExecutionException) CoverageVerificationException(gov.cms.ab2d.worker.processor.coverage.CoverageVerificationException) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 2 with PropertiesService

use of gov.cms.ab2d.common.service.PropertiesService in project ab2d by CMSgov.

the class CoveragePeriodQuartzJobTest method engageSearchWorks.

@DisplayName("Engaging coverage search works")
@Test
void engageSearchWorks() {
    PropertiesService propertiesService = mock(PropertiesService.class);
    when(propertiesService.getPropertiesByKey(eq(Constants.COVERAGE_SEARCH_DISCOVERY))).thenAnswer((arg) -> {
        Properties engaged = new Properties();
        engaged.setKey(Constants.COVERAGE_SEARCH_DISCOVERY);
        engaged.setValue("engaged");
        return engaged;
    });
    when(propertiesService.getPropertiesByKey(eq(Constants.COVERAGE_SEARCH_QUEUEING))).thenAnswer((arg) -> {
        Properties engaged = new Properties();
        engaged.setKey(Constants.COVERAGE_SEARCH_QUEUEING);
        engaged.setValue("engaged");
        return engaged;
    });
    when(propertiesService.getPropertiesByKey(eq(COVERAGE_SEARCH_OVERRIDE))).thenAnswer((arg) -> {
        Properties override = new Properties();
        override.setKey(COVERAGE_SEARCH_OVERRIDE);
        override.setValue("true");
        return override;
    });
    CoverageDriverStub coverageDriverStub = new CoverageDriverStub();
    CoveragePeriodQuartzJob quartzJob = new CoveragePeriodQuartzJob(coverageDriverStub, propertiesService, logManager);
    try {
        quartzJob.executeInternal(null);
        assertTrue(coverageDriverStub.discoveryCalled);
        assertTrue(coverageDriverStub.queueingCalled);
    } catch (JobExecutionException jobExecutionException) {
        fail("could not execute normally", jobExecutionException);
    }
}
Also used : CoverageDriverStub(gov.cms.ab2d.worker.processor.coverage.CoverageDriverStub) JobExecutionException(org.quartz.JobExecutionException) PropertiesService(gov.cms.ab2d.common.service.PropertiesService) Properties(gov.cms.ab2d.common.model.Properties) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 3 with PropertiesService

use of gov.cms.ab2d.common.service.PropertiesService in project ab2d by CMSgov.

the class CoveragePeriodQuartzJobTest method failingSearchesTriggerAlerts.

@DisplayName("Failing searches trigger alerts")
@Test
void failingSearchesTriggerAlerts() {
    PropertiesService propertiesService = mock(PropertiesService.class);
    when(propertiesService.getPropertiesByKey(eq(Constants.COVERAGE_SEARCH_DISCOVERY))).thenAnswer((arg) -> {
        Properties engaged = new Properties();
        engaged.setKey(Constants.COVERAGE_SEARCH_DISCOVERY);
        engaged.setValue("engaged");
        return engaged;
    });
    when(propertiesService.getPropertiesByKey(eq(COVERAGE_SEARCH_OVERRIDE))).thenAnswer((arg) -> {
        Properties override = new Properties();
        override.setKey(COVERAGE_SEARCH_OVERRIDE);
        override.setValue("true");
        return override;
    });
    try {
        doThrow(new RuntimeException("testing123")).when(coverageDriverMock).discoverCoveragePeriods();
        CoveragePeriodQuartzJob quartzJob = new CoveragePeriodQuartzJob(coverageDriverMock, propertiesService, logManager);
        JobExecutionException exception = assertThrows(JobExecutionException.class, () -> quartzJob.executeInternal(null));
        assertTrue(exception.getMessage().contains("testing123"));
        verify(logManager, times(1)).alert(contains("coverage period updates could not be conducted"), anyList());
    } catch (Exception ex) {
        fail("could not execute test due to interruption", ex);
    }
}
Also used : JobExecutionException(org.quartz.JobExecutionException) PropertiesService(gov.cms.ab2d.common.service.PropertiesService) Properties(gov.cms.ab2d.common.model.Properties) JobExecutionException(org.quartz.JobExecutionException) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 4 with PropertiesService

use of gov.cms.ab2d.common.service.PropertiesService in project ab2d by CMSgov.

the class CoveragePeriodQuartzJobTest method engagedSearchNotTuesdayAtMidnightDoesNotFire.

@DisplayName("Engaging coverage search works")
@Test
void engagedSearchNotTuesdayAtMidnightDoesNotFire() {
    PropertiesService propertiesService = mock(PropertiesService.class);
    when(propertiesService.getPropertiesByKey(eq(Constants.COVERAGE_SEARCH_DISCOVERY))).thenAnswer((arg) -> {
        Properties engaged = new Properties();
        engaged.setKey(Constants.COVERAGE_SEARCH_DISCOVERY);
        engaged.setValue("engaged");
        return engaged;
    });
    when(propertiesService.getPropertiesByKey(eq(Constants.COVERAGE_SEARCH_QUEUEING))).thenAnswer((arg) -> {
        Properties engaged = new Properties();
        engaged.setKey(Constants.COVERAGE_SEARCH_QUEUEING);
        engaged.setValue("engaged");
        return engaged;
    });
    when(propertiesService.getPropertiesByKey(eq(COVERAGE_SEARCH_OVERRIDE))).thenAnswer((arg) -> {
        Properties override = new Properties();
        override.setKey(COVERAGE_SEARCH_OVERRIDE);
        override.setValue("false");
        return override;
    });
    CoverageDriverStub coverageDriverStub = new CoverageDriverStub();
    CoveragePeriodQuartzJob quartzJob = new CoveragePeriodQuartzJob(coverageDriverStub, propertiesService, logManager);
    try {
        quartzJob.executeInternal(null);
        assertTrue(coverageDriverStub.discoveryCalled);
        OffsetDateTime date = OffsetDateTime.now(AB2D_ZONE);
        if (date.getDayOfWeek() == DayOfWeek.TUESDAY && date.getHour() == 0) {
            assertTrue(coverageDriverStub.queueingCalled);
        } else {
            assertFalse(coverageDriverStub.queueingCalled);
        }
    } catch (JobExecutionException jobExecutionException) {
        fail("could not execute normally", jobExecutionException);
    }
}
Also used : CoverageDriverStub(gov.cms.ab2d.worker.processor.coverage.CoverageDriverStub) JobExecutionException(org.quartz.JobExecutionException) PropertiesService(gov.cms.ab2d.common.service.PropertiesService) OffsetDateTime(java.time.OffsetDateTime) Properties(gov.cms.ab2d.common.model.Properties) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

PropertiesService (gov.cms.ab2d.common.service.PropertiesService)4 DisplayName (org.junit.jupiter.api.DisplayName)4 Test (org.junit.jupiter.api.Test)4 JobExecutionException (org.quartz.JobExecutionException)4 Properties (gov.cms.ab2d.common.model.Properties)3 CoverageDriverStub (gov.cms.ab2d.worker.processor.coverage.CoverageDriverStub)2 LogManager (gov.cms.ab2d.eventlogger.LogManager)1 CoverageDriver (gov.cms.ab2d.worker.processor.coverage.CoverageDriver)1 CoverageVerificationException (gov.cms.ab2d.worker.processor.coverage.CoverageVerificationException)1 OffsetDateTime (java.time.OffsetDateTime)1 List (java.util.List)1 AfterEach (org.junit.jupiter.api.AfterEach)1 Assertions (org.junit.jupiter.api.Assertions)1 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)1 Mock (org.mockito.Mock)1 Mockito (org.mockito.Mockito)1 MockitoExtension (org.mockito.junit.jupiter.MockitoExtension)1