Search in sources :

Example 11 with Properties

use of gov.cms.ab2d.common.model.Properties in project ab2d by CMSgov.

the class CoverageDriverUnitTest method whenLockInterruptedPropagateException.

@DisplayName("When locking is interrupted propagate exception")
@Test
void whenLockInterruptedPropagateException() {
    when(lockWrapper.getCoverageLock()).thenReturn(tryLockInterrupt);
    Properties monthsProp = new Properties();
    monthsProp.setValue("3");
    when(propertiesService.getPropertiesByKey(eq(Constants.COVERAGE_SEARCH_UPDATE_MONTHS))).thenReturn(monthsProp);
    Properties stuckProp = new Properties();
    stuckProp.setValue("72");
    when(propertiesService.getPropertiesByKey(eq(Constants.COVERAGE_SEARCH_STUCK_HOURS))).thenReturn(stuckProp);
    Properties overrideProp = new Properties();
    overrideProp.setValue("false");
    when(propertiesService.getPropertiesByKey(eq(Constants.COVERAGE_SEARCH_OVERRIDE))).thenReturn(overrideProp);
    ContractDTO contract = new ContractDTO("contractNum", null, null, null);
    Job job = new Job();
    job.setContractNumber(contract.getContractNumber());
    CoverageDriver driver = new CoverageDriverImpl(null, null, coverageService, propertiesService, null, lockWrapper, null);
    assertThrows(InterruptedException.class, driver::discoverCoveragePeriods);
    assertThrows(InterruptedException.class, driver::queueStaleCoveragePeriods);
    assertThrows(InterruptedException.class, () -> driver.isCoverageAvailable(job, contract));
}
Also used : ContractDTO(gov.cms.ab2d.common.dto.ContractDTO) Properties(gov.cms.ab2d.common.model.Properties) Job(gov.cms.ab2d.common.model.Job) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 12 with Properties

use of gov.cms.ab2d.common.model.Properties 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)

Example 13 with Properties

use of gov.cms.ab2d.common.model.Properties in project ab2d by CMSgov.

the class CoveragePeriodQuartzJobTest method disengageSearchWorks.

@DisplayName("Disengaging coverage search works")
@Test
void disengageSearchWorks() {
    when(propertiesService.getPropertiesByKey(eq(Constants.COVERAGE_SEARCH_DISCOVERY))).thenAnswer((arg) -> {
        Properties engaged = new Properties();
        engaged.setKey(Constants.COVERAGE_SEARCH_DISCOVERY);
        engaged.setValue("idle");
        return engaged;
    });
    when(propertiesService.getPropertiesByKey(eq(Constants.COVERAGE_SEARCH_QUEUEING))).thenAnswer((arg) -> {
        Properties engaged = new Properties();
        engaged.setKey(Constants.COVERAGE_SEARCH_QUEUEING);
        engaged.setValue("idle");
        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);
        assertFalse(coverageDriverStub.discoveryCalled);
        assertFalse(coverageDriverStub.queueingCalled);
    } catch (JobExecutionException jobExecutionException) {
    // Exception never thrown by stubbed method
    }
}
Also used : CoverageDriverStub(gov.cms.ab2d.worker.processor.coverage.CoverageDriverStub) JobExecutionException(org.quartz.JobExecutionException) Properties(gov.cms.ab2d.common.model.Properties) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

Properties (gov.cms.ab2d.common.model.Properties)13 Test (org.junit.jupiter.api.Test)12 DisplayName (org.junit.jupiter.api.DisplayName)6 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)6 JobExecutionException (org.quartz.JobExecutionException)4 PropertiesService (gov.cms.ab2d.common.service.PropertiesService)3 CoverageDriverStub (gov.cms.ab2d.worker.processor.coverage.CoverageDriverStub)3 ContractDTO (gov.cms.ab2d.common.dto.ContractDTO)1 PropertiesDTO (gov.cms.ab2d.common.dto.PropertiesDTO)1 Job (gov.cms.ab2d.common.model.Job)1 OffsetDateTime (java.time.OffsetDateTime)1 HashMap (java.util.HashMap)1