Search in sources :

Example 1 with BFDClient

use of gov.cms.ab2d.bfd.client.BFDClient in project ab2d by CMSgov.

the class CoverageDriverTest method before.

@BeforeEach
void before() {
    mapping = new ContractToContractCoverageMapping();
    // Set properties values in database
    addPropertiesTableValues();
    contract = dataSetup.setupContract("TST-12", AB2D_EPOCH.toOffsetDateTime());
    contract1 = dataSetup.setupContract("TST-45", AB2D_EPOCH.toOffsetDateTime());
    contractForCoverageDTO = new ContractForCoverageDTO("TST-12", AB2D_EPOCH.toOffsetDateTime(), ContractForCoverageDTO.ContractType.NORMAL);
    contractForCoverageDTO1 = new ContractForCoverageDTO("TST-45", AB2D_EPOCH.toOffsetDateTime(), ContractForCoverageDTO.ContractType.NORMAL);
    contractRepo.saveAndFlush(contract);
    january = coverageDataSetup.createCoveragePeriod(contract.getContractNumber(), 1, 2020);
    february = coverageDataSetup.createCoveragePeriod(contract.getContractNumber(), 2, 2020);
    march = coverageDataSetup.createCoveragePeriod(contract.getContractNumber(), 3, 2020);
    PdpClientDTO contractPdpClient = createClient(contract, "TST-12", SPONSOR_ROLE);
    pdpClientService.createClient(contractPdpClient);
    dataSetup.queueForCleanup(pdpClientService.getClientById("TST-12"));
    PdpClient pdpClient = dataSetup.setupPdpClient(List.of());
    job = new Job();
    job.setContractNumber(contract.getContractNumber());
    job.setJobUuid("unique");
    job.setOrganization(pdpClient.getOrganization());
    job.setStatus(gov.cms.ab2d.common.model.JobStatus.SUBMITTED);
    job.setCreatedAt(OffsetDateTime.now());
    job.setFhirVersion(STU3);
    jobRepo.saveAndFlush(job);
    dataSetup.queueForCleanup(job);
    bfdClient = mock(BFDClient.class);
    ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
    taskExecutor.setMaxPoolSize(6);
    taskExecutor.setCorePoolSize(3);
    taskExecutor.initialize();
    processor = new CoverageProcessorImpl(coverageService, bfdClient, taskExecutor, MAX_ATTEMPTS, contractWorkerClient);
    driver = new CoverageDriverImpl(coverageSearchRepo, pdpClientService, coverageService, propertiesService, processor, searchLock, contractToContractCoverageMapping);
}
Also used : ContractForCoverageDTO(gov.cms.ab2d.coverage.model.ContractForCoverageDTO) PdpClientDTO(gov.cms.ab2d.common.dto.PdpClientDTO) ContractToContractCoverageMapping(gov.cms.ab2d.worker.config.ContractToContractCoverageMapping) ThreadPoolTaskExecutor(org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor) Job(gov.cms.ab2d.common.model.Job) PdpClient(gov.cms.ab2d.common.model.PdpClient) BFDClient(gov.cms.ab2d.bfd.client.BFDClient) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with BFDClient

use of gov.cms.ab2d.bfd.client.BFDClient in project ab2d by CMSgov.

the class CoverageUpdateAndProcessorTest method mappingRetried.

@DisplayName("Mapping failure leads to retry but still can succeed on retry")
@Test
void mappingRetried() {
    when(bfdClient.requestPartDEnrolleesFromServer(eq(STU3), anyString(), anyInt())).thenThrow(new RuntimeException("oops"));
    processor.queueCoveragePeriod(january, false);
    CoverageJobStatus status = coverageService.getSearchStatus(january.getId());
    assertEquals(CoverageJobStatus.SUBMITTED, status);
    driver.loadMappingJob();
    status = coverageService.getSearchStatus(january.getId());
    assertEquals(CoverageJobStatus.IN_PROGRESS, status);
    sleep(1000);
    processor.monitorMappingJobs();
    assertTrue(coverageSearchEventRepo.findAll().stream().anyMatch(event -> event.getNewStatus() == CoverageJobStatus.FAILED));
    status = coverageService.getSearchStatus(january.getId());
    assertEquals(CoverageJobStatus.SUBMITTED, status);
    reset(bfdClient);
    org.hl7.fhir.dstu3.model.Bundle bundle1 = buildBundle(0, 10);
    bundle1.setLink(Collections.singletonList(new org.hl7.fhir.dstu3.model.Bundle.BundleLinkComponent().setRelation(org.hl7.fhir.dstu3.model.Bundle.LINK_NEXT)));
    org.hl7.fhir.dstu3.model.Bundle bundle2 = buildBundle(10, 20);
    Mockito.clearInvocations();
    when(bfdClient.requestPartDEnrolleesFromServer(eq(STU3), anyString(), anyInt(), anyInt())).thenReturn(bundle1);
    when(bfdClient.requestNextBundleFromServer(eq(STU3), any(org.hl7.fhir.dstu3.model.Bundle.class))).thenReturn(bundle2);
    driver.loadMappingJob();
    sleep(1000);
    processor.monitorMappingJobs();
    sleep(1000);
    processor.insertJobResults();
    status = coverageService.getSearchStatus(january.getId());
    assertEquals(CoverageJobStatus.SUCCESSFUL, status);
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) WorkerDataSetup(gov.cms.ab2d.worker.util.WorkerDataSetup) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Autowired(org.springframework.beans.factory.annotation.Autowired) STU3(gov.cms.ab2d.fhir.FhirVersion.STU3) Constants(gov.cms.ab2d.common.util.Constants) ContractRepository(gov.cms.ab2d.common.repository.ContractRepository) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) PdpClientDTO(gov.cms.ab2d.common.dto.PdpClientDTO) PropertiesDTO(gov.cms.ab2d.common.dto.PropertiesDTO) ContractDTO(gov.cms.ab2d.common.dto.ContractDTO) ThreadPoolTaskExecutor(org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor) DateUtil(gov.cms.ab2d.common.util.DateUtil) Contract(gov.cms.ab2d.common.model.Contract) CoverageSearchRepository(gov.cms.ab2d.coverage.repository.CoverageSearchRepository) CoverageSearchEvent(gov.cms.ab2d.coverage.model.CoverageSearchEvent) CoverageService(gov.cms.ab2d.coverage.service.CoverageService) Test(org.junit.jupiter.api.Test) AB2D_EPOCH(gov.cms.ab2d.common.util.DateUtil.AB2D_EPOCH) List(java.util.List) OffsetDateTime(java.time.OffsetDateTime) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) CoveragePeriodRepository(gov.cms.ab2d.coverage.repository.CoveragePeriodRepository) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) PropertiesService(gov.cms.ab2d.common.service.PropertiesService) PdpClientService(gov.cms.ab2d.common.service.PdpClientService) CoveragePeriod(gov.cms.ab2d.coverage.model.CoveragePeriod) TemporalAdjusters(java.time.temporal.TemporalAdjusters) CoverageDataSetup(gov.cms.ab2d.coverage.util.CoverageDataSetup) BFDClient(gov.cms.ab2d.bfd.client.BFDClient) Mockito.mock(org.mockito.Mockito.mock) Assertions.fail(org.junit.jupiter.api.Assertions.fail) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) AB2DPostgresqlContainer(gov.cms.ab2d.common.util.AB2DPostgresqlContainer) PostgreSQLContainer(org.testcontainers.containers.PostgreSQLContainer) CoverageJobStatus(gov.cms.ab2d.coverage.model.CoverageJobStatus) ArrayList(java.util.ArrayList) Value(org.springframework.beans.factory.annotation.Value) ContractToContractCoverageMapping(gov.cms.ab2d.worker.config.ContractToContractCoverageMapping) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ArgumentMatchers.anyInt(org.mockito.ArgumentMatchers.anyInt) Nullable(javax.annotation.Nullable) Container(org.testcontainers.junit.jupiter.Container) ContractWorkerClient(gov.cms.ab2d.worker.service.ContractWorkerClient) SPONSOR_ROLE(gov.cms.ab2d.common.model.Role.SPONSOR_ROLE) Testcontainers(org.testcontainers.junit.jupiter.Testcontainers) Job(gov.cms.ab2d.common.model.Job) ReflectionTestUtils(org.springframework.test.util.ReflectionTestUtils) Mockito.when(org.mockito.Mockito.when) BENEFICIARY_ID(gov.cms.ab2d.fhir.IdentifierUtils.BENEFICIARY_ID) DisplayName(org.junit.jupiter.api.DisplayName) Mockito(org.mockito.Mockito) AfterEach(org.junit.jupiter.api.AfterEach) Collectors.toList(java.util.stream.Collectors.toList) ChronoUnit(java.time.temporal.ChronoUnit) DayOfWeek(java.time.DayOfWeek) Properties(gov.cms.ab2d.common.model.Properties) CoverageSearchEventRepository(gov.cms.ab2d.coverage.repository.CoverageSearchEventRepository) Collections(java.util.Collections) Mockito.reset(org.mockito.Mockito.reset) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) CoverageJobStatus(gov.cms.ab2d.coverage.model.CoverageJobStatus) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) DisplayName(org.junit.jupiter.api.DisplayName)

Example 3 with BFDClient

use of gov.cms.ab2d.bfd.client.BFDClient in project ab2d by CMSgov.

the class CoverageUpdateAndProcessorTest method before.

@BeforeEach
void before() {
    // Set values used to find jobs to update
    addPropertiesTableValues();
    originalValues.clear();
    contract = dataSetup.setupContract("TST-12", AB2D_EPOCH.toOffsetDateTime());
    contractRepo.saveAndFlush(contract);
    january = coverageDataSetup.createCoveragePeriod("TST-12", 1, 2020);
    february = coverageDataSetup.createCoveragePeriod("TST-12", 2, 2020);
    march = coverageDataSetup.createCoveragePeriod("TST-12", 3, 2020);
    PdpClientDTO contractPdpClient = createClient(contract.toDTO(), "TST-12", SPONSOR_ROLE);
    pdpClientService.createClient(contractPdpClient);
    dataSetup.queueForCleanup(pdpClientService.getClientById("TST-12"));
    bfdClient = mock(BFDClient.class);
    ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
    taskExecutor.setMaxPoolSize(6);
    taskExecutor.setCorePoolSize(3);
    taskExecutor.initialize();
    processor = new CoverageProcessorImpl(coverageService, bfdClient, taskExecutor, MAX_ATTEMPTS, contractWorkerClient);
    driver = new CoverageDriverImpl(coverageSearchRepo, pdpClientService, coverageService, propertiesService, processor, searchLock, mapping);
}
Also used : PdpClientDTO(gov.cms.ab2d.common.dto.PdpClientDTO) ThreadPoolTaskExecutor(org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor) BFDClient(gov.cms.ab2d.bfd.client.BFDClient) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

BFDClient (gov.cms.ab2d.bfd.client.BFDClient)3 PdpClientDTO (gov.cms.ab2d.common.dto.PdpClientDTO)3 BeforeEach (org.junit.jupiter.api.BeforeEach)3 ThreadPoolTaskExecutor (org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor)3 Job (gov.cms.ab2d.common.model.Job)2 ContractToContractCoverageMapping (gov.cms.ab2d.worker.config.ContractToContractCoverageMapping)2 ContractDTO (gov.cms.ab2d.common.dto.ContractDTO)1 PropertiesDTO (gov.cms.ab2d.common.dto.PropertiesDTO)1 Contract (gov.cms.ab2d.common.model.Contract)1 PdpClient (gov.cms.ab2d.common.model.PdpClient)1 Properties (gov.cms.ab2d.common.model.Properties)1 SPONSOR_ROLE (gov.cms.ab2d.common.model.Role.SPONSOR_ROLE)1 ContractRepository (gov.cms.ab2d.common.repository.ContractRepository)1 PdpClientService (gov.cms.ab2d.common.service.PdpClientService)1 PropertiesService (gov.cms.ab2d.common.service.PropertiesService)1 AB2DPostgresqlContainer (gov.cms.ab2d.common.util.AB2DPostgresqlContainer)1 Constants (gov.cms.ab2d.common.util.Constants)1 DateUtil (gov.cms.ab2d.common.util.DateUtil)1 AB2D_EPOCH (gov.cms.ab2d.common.util.DateUtil.AB2D_EPOCH)1 ContractForCoverageDTO (gov.cms.ab2d.coverage.model.ContractForCoverageDTO)1