Search in sources :

Example 1 with ContractDTO

use of gov.cms.ab2d.common.dto.ContractDTO 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 2 with ContractDTO

use of gov.cms.ab2d.common.dto.ContractDTO 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 3 with ContractDTO

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

Example 4 with ContractDTO

use of gov.cms.ab2d.common.dto.ContractDTO in project ab2d by CMSgov.

the class CoverageDriverUnitTest method startDateForcedToMinAB2DEpoch.

@DisplayName("Coverage period update fails then throw exception")
@Test
void startDateForcedToMinAB2DEpoch() {
    ContractDTO contract = new ContractDTO("contractNum", null, OffsetDateTime.of(2000, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC), null);
    CoveragePeriod coveragePeriod = new CoveragePeriod();
    coveragePeriod.setId(100);
    coveragePeriod.setMonth(1);
    coveragePeriod.setYear(2021);
    coveragePeriod.setContractNumber(contract.getContractNumber());
    ZonedDateTime dateTime = driver.getStartDateTime(contract);
    assertEquals(AB2D_EPOCH, dateTime);
}
Also used : ContractDTO(gov.cms.ab2d.common.dto.ContractDTO) ZonedDateTime(java.time.ZonedDateTime) CoveragePeriod(gov.cms.ab2d.coverage.model.CoveragePeriod) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 5 with ContractDTO

use of gov.cms.ab2d.common.dto.ContractDTO in project ab2d by CMSgov.

the class CoverageDriverUnitTest method failPagingWhenCoveragePeriodMissing.

@DisplayName("Paging coverage fails when coverage periods are missing")
@Test
void failPagingWhenCoveragePeriodMissing() {
    when(coverageService.getCoveragePeriod(any(), anyInt(), anyInt())).thenThrow(new EntityNotFoundException());
    Job job = new Job();
    ContractDTO contract = new ContractDTO(null, null, AB2D_EPOCH.toOffsetDateTime(), null);
    CoverageDriverException startDateInFuture = assertThrows(CoverageDriverException.class, () -> driver.pageCoverage(job, contract));
    assertEquals(EntityNotFoundException.class, startDateInFuture.getCause().getClass());
}
Also used : ContractDTO(gov.cms.ab2d.common.dto.ContractDTO) EntityNotFoundException(javax.persistence.EntityNotFoundException) Job(gov.cms.ab2d.common.model.Job) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

ContractDTO (gov.cms.ab2d.common.dto.ContractDTO)43 Test (org.junit.jupiter.api.Test)31 DisplayName (org.junit.jupiter.api.DisplayName)27 CoveragePeriod (gov.cms.ab2d.coverage.model.CoveragePeriod)18 ArrayList (java.util.ArrayList)13 CoverageMapping (gov.cms.ab2d.coverage.model.CoverageMapping)12 CoverageSearch (gov.cms.ab2d.coverage.model.CoverageSearch)12 CoverageSearchEvent (gov.cms.ab2d.coverage.model.CoverageSearchEvent)12 ContractToContractCoverageMapping (gov.cms.ab2d.worker.config.ContractToContractCoverageMapping)12 Job (gov.cms.ab2d.common.model.Job)11 CoverageCount (gov.cms.ab2d.coverage.model.CoverageCount)10 List (java.util.List)10 HashMap (java.util.HashMap)8 ContractForCoverageDTO (gov.cms.ab2d.coverage.model.ContractForCoverageDTO)7 CoveragePagingRequest (gov.cms.ab2d.coverage.model.CoveragePagingRequest)5 CoveragePagingResult (gov.cms.ab2d.coverage.model.CoveragePagingResult)5 Contract (gov.cms.ab2d.common.model.Contract)4 OffsetDateTime (java.time.OffsetDateTime)4 ZonedDateTime (java.time.ZonedDateTime)4 PdpClientDTO (gov.cms.ab2d.common.dto.PdpClientDTO)3