Search in sources :

Example 11 with Job

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

Example 12 with Job

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

the class CoverageUpdateAndProcessorTest method coverageAvailabilityLimitsRetries.

@DisplayName("Coverage availability throws exception after max attempts retries")
@Test
void coverageAvailabilityLimitsRetries() {
    Job job = new Job();
    job.setCreatedAt(OffsetDateTime.now());
    job.setContractNumber(contract.getContractNumber());
    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {
        fail("could not complete test");
    }
    january.setStatus(CoverageJobStatus.FAILED);
    coveragePeriodRepo.saveAndFlush(january);
    february.setStatus(CoverageJobStatus.FAILED);
    coveragePeriodRepo.saveAndFlush(february);
    try {
        driver.isCoverageAvailable(job, contract.toDTO());
    } catch (CoverageDriverException coverageDriverException) {
    // passed
    } catch (InterruptedException interruptedException) {
        fail("could not complete test");
    }
}
Also used : 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 13 with Job

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

the class JobPreProcessorUnitTest method testDownloadedAll.

@Test
void testDownloadedAll() {
    Job job = new Job();
    // Error file that was downloaded
    JobOutput jo1 = createJobOutput(job, true, true);
    // Error file that was not downloaded
    JobOutput jo2 = createJobOutput(job, true, false);
    // Data file that was downloaded
    JobOutput jo3 = createJobOutput(job, false, true);
    // Data file that was not downloaded - anything that includes this should return false
    JobOutput jo4 = createJobOutput(job, false, false);
    JobPreProcessorImpl impl = (JobPreProcessorImpl) cut;
    // Start with null or empty results
    assertTrue(impl.downloadedAll(null));
    assertTrue(impl.downloadedAll(Collections.emptyList()));
    // Try each individual
    assertTrue(impl.downloadedAll(List.of(jo1)));
    assertTrue(impl.downloadedAll(List.of(jo2)));
    assertTrue(impl.downloadedAll(List.of(jo3)));
    assertFalse(impl.downloadedAll(List.of(jo4)));
    // Try combinations
    assertTrue(impl.downloadedAll(List.of(jo1, jo2, jo3)));
    assertFalse(impl.downloadedAll(List.of(jo1, jo2, jo3, jo4)));
    assertFalse(impl.downloadedAll(List.of(jo1, jo4)));
    assertFalse(impl.downloadedAll(List.of(jo2, jo3, jo4)));
}
Also used : Job(gov.cms.ab2d.common.model.Job) JobOutput(gov.cms.ab2d.common.model.JobOutput) Test(org.junit.jupiter.api.Test)

Example 14 with Job

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

the class JobPreProcessorUnitTest method createJob.

// Not first run, since supplied
private Job createJob() {
    Job job = new Job();
    job.setJobUuid(JOB_UUID);
    job.setStatusMessage("0%");
    job.setFhirVersion(STU3);
    job.setContractNumber(contract.getContractNumber());
    return job;
}
Also used : Job(gov.cms.ab2d.common.model.Job)

Example 15 with Job

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

the class JobProcessorIntegrationTest method setUp.

@BeforeEach
void setUp() {
    MockitoAnnotations.openMocks(this);
    LogManager logManager = new LogManager(sqlEventLogger, kinesisEventLogger, slackLogger);
    PdpClient pdpClient = createClient();
    contract = createContract();
    contractForCoverageDTO = mapping.map(contract);
    fail = new RuntimeException("TEST EXCEPTION");
    job = createJob(pdpClient);
    job.setContractNumber(contract.getContractNumber());
    job.setStatus(JobStatus.IN_PROGRESS);
    jobRepository.saveAndFlush(job);
    when(mockBfdClient.requestEOBFromServer(eq(STU3), anyLong())).thenAnswer((args) -> {
        ExplanationOfBenefit copy = EOB.copy();
        copy.getPatient().setReference("Patient/" + args.getArgument(1));
        return EobTestDataUtil.createBundle(copy);
    });
    when(mockBfdClient.requestEOBFromServer(eq(STU3), anyLong(), any())).thenAnswer((args) -> {
        ExplanationOfBenefit copy = EOB.copy();
        copy.getPatient().setReference("Patient/" + args.getArgument(1));
        return EobTestDataUtil.createBundle(copy);
    });
    when(mockCoverageDriver.numberOfBeneficiariesToProcess(any(Job.class), any(ContractDTO.class))).thenReturn(100);
    when(mockCoverageDriver.pageCoverage(any(CoveragePagingRequest.class))).thenReturn(new CoveragePagingResult(loadFauxMetadata(contractForCoverageDTO, 99), null));
    SearchConfig searchConfig = new SearchConfig(tmpEfsMountDir.getAbsolutePath(), STREAMING_DIR, FINISHED_DIR, 0, 0, MULTIPLIER, NUMBER_PATIENT_REQUESTS_PER_THREAD);
    PatientClaimsProcessor patientClaimsProcessor = new PatientClaimsProcessorImpl(mockBfdClient, logManager, searchConfig);
    ReflectionTestUtils.setField(patientClaimsProcessor, "earliestDataDate", "01/01/1900");
    ThreadPoolTaskExecutor pool = new ThreadPoolTaskExecutor();
    pool.initialize();
    ContractProcessor contractProcessor = new ContractProcessorImpl(contractWorkerClient, jobRepository, mockCoverageDriver, patientClaimsProcessor, logManager, eobClaimRequestsQueue, jobChannelService, jobProgressService, mapping, pool, searchConfig);
    cut = new JobProcessorImpl(fileService, jobChannelService, jobProgressService, jobProgressUpdateService, jobRepository, jobOutputRepository, contractProcessor, logManager);
    ReflectionTestUtils.setField(cut, "efsMount", tmpEfsMountDir.toString());
    ReflectionTestUtils.setField(cut, "failureThreshold", 10);
}
Also used : SearchConfig(gov.cms.ab2d.worker.config.SearchConfig) ExplanationOfBenefit(org.hl7.fhir.dstu3.model.ExplanationOfBenefit) PdpClient(gov.cms.ab2d.common.model.PdpClient) CoveragePagingRequest(gov.cms.ab2d.coverage.model.CoveragePagingRequest) CoveragePagingResult(gov.cms.ab2d.coverage.model.CoveragePagingResult) ContractDTO(gov.cms.ab2d.common.dto.ContractDTO) ThreadPoolTaskExecutor(org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor) Job(gov.cms.ab2d.common.model.Job) LogManager(gov.cms.ab2d.eventlogger.LogManager) BeforeEach(org.junit.jupiter.api.BeforeEach)

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