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());
}
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());
}
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");
}
}
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);
}
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());
}
Aggregations