Search in sources :

Example 6 with Job

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

the class CoverageDriverTest method availableCoverageWhenPeriodInProgress.

@DisplayName("Do not start an eob job if any relevant coverage period is being updated")
@Test
void availableCoverageWhenPeriodInProgress() {
    Job job = new Job();
    job.setContractNumber(contract.getContractNumber());
    job.setCreatedAt(OffsetDateTime.now());
    try {
        changeStatus(contractForCoverageDTO, AB2D_EPOCH.toOffsetDateTime(), CoverageJobStatus.IN_PROGRESS);
        // Make sure that there is a lastSuccessfulJob
        ZonedDateTime now = ZonedDateTime.now(AB2D_ZONE);
        CoveragePeriod currentMonth = coverageService.getCoveragePeriod(contractForCoverageDTO, now.getMonthValue(), now.getYear());
        currentMonth.setLastSuccessfulJob(OffsetDateTime.now().plusHours(2));
        currentMonth.setStatus(CoverageJobStatus.SUCCESSFUL);
        coveragePeriodRepo.saveAndFlush(currentMonth);
        boolean inProgressCoverageStatus = driver.isCoverageAvailable(job, contract.toDTO());
        assertFalse(inProgressCoverageStatus, "eob searches should not run when a coverage period is in progress");
    } catch (InterruptedException | CoverageDriverException exception) {
        fail("could not check for available coverage", exception);
    }
}
Also used : ZonedDateTime(java.time.ZonedDateTime) CoveragePeriod(gov.cms.ab2d.coverage.model.CoveragePeriod) Job(gov.cms.ab2d.common.model.Job) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) DisplayName(org.junit.jupiter.api.DisplayName)

Example 7 with Job

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

the class CoverageDriverTest method availableCoverageWhenPeriodSubmitted.

@DisplayName("Do not start an eob job if any relevant coverage period is queued for an update")
@Test
void availableCoverageWhenPeriodSubmitted() {
    Job job = new Job();
    job.setContractNumber(contractForCoverageDTO.getContractNumber());
    job.setCreatedAt(OffsetDateTime.now());
    try {
        changeStatus(contractForCoverageDTO, AB2D_EPOCH.toOffsetDateTime(), CoverageJobStatus.SUBMITTED);
        // Make sure that there is a lastSuccessfulJob
        ZonedDateTime now = ZonedDateTime.now(AB2D_ZONE);
        CoveragePeriod currentMonth = coverageService.getCoveragePeriod(contractForCoverageDTO, now.getMonthValue(), now.getYear());
        currentMonth.setLastSuccessfulJob(OffsetDateTime.now().plusHours(2));
        currentMonth.setStatus(CoverageJobStatus.SUCCESSFUL);
        coveragePeriodRepo.saveAndFlush(currentMonth);
        boolean submittedCoverageStatus = driver.isCoverageAvailable(job, contract.toDTO());
        assertFalse(submittedCoverageStatus, "eob searches should not run if a " + "coverage period is submitted");
    } catch (InterruptedException | CoverageDriverException exception) {
        fail("could not check for available coverage", exception);
    }
}
Also used : ZonedDateTime(java.time.ZonedDateTime) CoveragePeriod(gov.cms.ab2d.coverage.model.CoveragePeriod) Job(gov.cms.ab2d.common.model.Job) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) DisplayName(org.junit.jupiter.api.DisplayName)

Example 8 with Job

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

the class CoverageDriverUnitTest method failPagingRequestWhenStartDateAfterNow.

@DisplayName("Paging coverage fails when start date is in future")
@Test
void failPagingRequestWhenStartDateAfterNow() {
    Job job = new Job();
    ContractDTO contract = new ContractDTO(null, null, OffsetDateTime.now().plusHours(1), null);
    CoverageDriverException startDateInFuture = assertThrows(CoverageDriverException.class, () -> driver.pageCoverage(job, contract));
    assertEquals("contract attestation time is after current time," + " cannot find metadata for coverage periods in the future", startDateInFuture.getMessage());
}
Also used : ContractDTO(gov.cms.ab2d.common.dto.ContractDTO) Job(gov.cms.ab2d.common.model.Job) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 9 with Job

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

the class CoverageDriverUnitTest method beginPagingWhenCoveragePeriodsPresent.

@DisplayName("Paging coverage periods")
@Test
void beginPagingWhenCoveragePeriodsPresent() {
    when(coverageService.getCoveragePeriod(any(ContractForCoverageDTO.class), anyInt(), anyInt())).thenAnswer((invocationOnMock) -> {
        CoveragePeriod period = new CoveragePeriod();
        period.setContractNumber((invocationOnMock.getArgument(0).toString()));
        period.setMonth(invocationOnMock.getArgument(1));
        period.setYear(invocationOnMock.getArgument(2));
        return period;
    });
    int pagingSize = (int) ReflectionTestUtils.getField(driver, "PAGING_SIZE");
    when(coverageService.pageCoverage(any(CoveragePagingRequest.class))).thenAnswer((invocationMock) -> {
        CoveragePagingRequest request = invocationMock.getArgument(0);
        Optional<Long> cursor = request.getCursor();
        CoveragePagingRequest nextRequest = null;
        if (cursor.isPresent()) {
            long cursorValue = cursor.get();
            nextRequest = new CoveragePagingRequest(pagingSize, (cursorValue + pagingSize), request.getContract(), request.getJobStartTime());
        } else {
            nextRequest = new CoveragePagingRequest(pagingSize, (long) pagingSize, request.getContract(), request.getJobStartTime());
        }
        return new CoveragePagingResult(List.of(), nextRequest);
    });
    Job job = new Job();
    ContractDTO contract = new ContractDTO("Contract-0", null, AB2D_EPOCH.toOffsetDateTime(), null);
    when(mapping.map(any(ContractDTO.class))).thenReturn(new ContractForCoverageDTO("Contract-0", contract.getAttestedOn(), ContractForCoverageDTO.ContractType.NORMAL));
    CoveragePagingResult firstCall = driver.pageCoverage(job, contract);
    assertNotNull(firstCall);
    assertTrue(firstCall.getNextRequest().isPresent());
    CoveragePagingRequest firstNextRequest = firstCall.getNextRequest().get();
    assertTrue(firstNextRequest.getCursor().isPresent());
    assertEquals(pagingSize, firstNextRequest.getCursor().get());
    CoveragePagingResult secondCall = driver.pageCoverage(firstNextRequest);
    assertNotNull(secondCall);
    assertTrue(secondCall.getNextRequest().isPresent());
    CoveragePagingRequest secondNextRequest = secondCall.getNextRequest().get();
    assertTrue(secondNextRequest.getCursor().isPresent());
    assertEquals((2L * pagingSize), secondNextRequest.getCursor().get());
}
Also used : CoveragePagingRequest(gov.cms.ab2d.coverage.model.CoveragePagingRequest) CoveragePagingResult(gov.cms.ab2d.coverage.model.CoveragePagingResult) ContractForCoverageDTO(gov.cms.ab2d.coverage.model.ContractForCoverageDTO) ContractDTO(gov.cms.ab2d.common.dto.ContractDTO) CoveragePeriod(gov.cms.ab2d.coverage.model.CoveragePeriod) Job(gov.cms.ab2d.common.model.Job) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 10 with Job

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

the class CoverageDriverUnitTest method failureToLockCoverageAvailableFailsQuietly.

@DisplayName("When locking fails return false for coverage available")
@Test
void failureToLockCoverageAvailableFailsQuietly() {
    when(lockWrapper.getCoverageLock()).thenReturn(tryLockFalse);
    doReturn(Collections.emptyList()).when(coverageService).coveragePeriodNeverSearchedSuccessfully();
    when(coverageService.coveragePeriodStuckJobs(any())).thenReturn(Collections.emptyList());
    when(coverageService.coveragePeriodNotUpdatedSince(anyInt(), anyInt(), any())).thenReturn(Collections.emptyList());
    CoverageDriver driver = new CoverageDriverImpl(null, null, coverageService, null, null, lockWrapper, null);
    ContractDTO contract = new ContractDTO("contractNum", null, null, null);
    Job job = new Job();
    job.setContractNumber(contract.getContractNumber());
    try {
        assertFalse(driver.isCoverageAvailable(job, contract));
    } catch (InterruptedException interruptedException) {
        fail("test interrupted during execution");
    }
}
Also used : ContractDTO(gov.cms.ab2d.common.dto.ContractDTO) Job(gov.cms.ab2d.common.model.Job) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

Job (gov.cms.ab2d.common.model.Job)67 Test (org.junit.jupiter.api.Test)39 DisplayName (org.junit.jupiter.api.DisplayName)31 ContractDTO (gov.cms.ab2d.common.dto.ContractDTO)21 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)18 OffsetDateTime (java.time.OffsetDateTime)15 JobOutput (gov.cms.ab2d.common.model.JobOutput)9 CoveragePagingRequest (gov.cms.ab2d.coverage.model.CoveragePagingRequest)9 CoveragePagingResult (gov.cms.ab2d.coverage.model.CoveragePagingResult)9 CoveragePeriod (gov.cms.ab2d.coverage.model.CoveragePeriod)8 ContractForCoverageDTO (gov.cms.ab2d.coverage.model.ContractForCoverageDTO)6 Map (java.util.Map)5 Contract (gov.cms.ab2d.common.model.Contract)4 PdpClient (gov.cms.ab2d.common.model.PdpClient)4 ZonedDateTime (java.time.ZonedDateTime)4 Transactional (org.springframework.transaction.annotation.Transactional)4 ContractToContractCoverageMapping (gov.cms.ab2d.worker.config.ContractToContractCoverageMapping)3 List (java.util.List)3 Trace (com.newrelic.api.agent.Trace)2 PdpClientService (gov.cms.ab2d.common.service.PdpClientService)2