Search in sources :

Example 1 with PdpClientDTO

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

the class AdminAPI method udpateClient.

@ResponseStatus(value = HttpStatus.OK)
@PutMapping("/client")
public ResponseEntity<PdpClientDTO> udpateClient(@RequestBody PdpClientDTO pdpClientDTO) {
    PdpClientDTO client = pdpClientService.updateClient(pdpClientDTO);
    log.info("client {} updated", pdpClientDTO.getOrganization());
    return new ResponseEntity<>(client, null, HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) PdpClientDTO(gov.cms.ab2d.common.dto.PdpClientDTO) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) PutMapping(org.springframework.web.bind.annotation.PutMapping)

Example 2 with PdpClientDTO

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

the class AdminAPIPdpClientTests method testCreateDuplicateClient.

@Test
public void testCreateDuplicateClient() throws Exception {
    PdpClientDTO pdpClientDTO = new PdpClientDTO();
    pdpClientDTO.setClientId(TEST_CLIENT);
    pdpClientDTO.setEnabled(true);
    pdpClientDTO.setContract(buildContractDTO());
    pdpClientDTO.setRole(ADMIN_ROLE);
    Role role = roleService.findRoleByName(ADMIN_ROLE);
    pdpClientDTO.setRole(role.getName());
    ObjectMapper mapper = getMapper();
    this.mockMvc.perform(post(API_PREFIX_V1 + ADMIN_PREFIX + CLIENT_URL).contentType(MediaType.APPLICATION_JSON).content(mapper.writeValueAsString(pdpClientDTO)).header("Authorization", "Bearer " + token));
    this.mockMvc.perform(post(API_PREFIX_V1 + ADMIN_PREFIX + CLIENT_URL).contentType(MediaType.APPLICATION_JSON).content(mapper.writeValueAsString(pdpClientDTO)).header("Authorization", "Bearer " + token)).andExpect(status().is(500)).andExpect(jsonPath("$.resourceType", Is.is("OperationOutcome"))).andExpect(jsonPath("$.issue[0].severity", Is.is("error"))).andExpect(jsonPath("$.issue[0].code", Is.is("invalid"))).andExpect(jsonPath("$.issue[0].details.text", Is.is("An internal error occurred")));
    PdpClient anotherPdpClient = pdpClientRepository.findByClientId(("anotherEmail@test.com"));
    dataSetup.queueForCleanup(anotherPdpClient);
}
Also used : Role(gov.cms.ab2d.common.model.Role) PdpClientDTO(gov.cms.ab2d.common.dto.PdpClientDTO) PdpClient(gov.cms.ab2d.common.model.PdpClient) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 3 with PdpClientDTO

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

the class AdminAPIPdpClientTests method testCreateClientAttestor.

@Test
public void testCreateClientAttestor() throws Exception {
    PdpClientDTO pdpClientDTO = new PdpClientDTO();
    pdpClientDTO.setClientId(TEST_CLIENT);
    pdpClientDTO.setOrganization(TEST_ORG);
    pdpClientDTO.setEnabled(true);
    pdpClientDTO.setContract(buildContractDTO());
    Role role = roleService.findRoleByName(ATTESTOR_ROLE);
    pdpClientDTO.setRole(role.getName());
    ObjectMapper mapper = getMapper();
    MvcResult mvcResult = this.mockMvc.perform(post(API_PREFIX_V1 + ADMIN_PREFIX + CLIENT_URL).contentType(MediaType.APPLICATION_JSON).content(mapper.writeValueAsString(pdpClientDTO)).header("Authorization", "Bearer " + token)).andReturn();
    assertEquals(201, mvcResult.getResponse().getStatus());
    String result = mvcResult.getResponse().getContentAsString();
    PdpClientDTO createdPdpClientDTO = mapper.readValue(result, PdpClientDTO.class);
    assertEquals(createdPdpClientDTO.getClientId(), pdpClientDTO.getClientId());
    assertEquals(createdPdpClientDTO.getEnabled(), pdpClientDTO.getEnabled());
    assertEquals(createdPdpClientDTO.getContract().getContractNumber(), pdpClientDTO.getContract().getContractNumber());
    assertEquals(createdPdpClientDTO.getContract().getContractName(), pdpClientDTO.getContract().getContractName());
    assertEquals(createdPdpClientDTO.getRole(), pdpClientDTO.getRole());
}
Also used : Role(gov.cms.ab2d.common.model.Role) PdpClientDTO(gov.cms.ab2d.common.dto.PdpClientDTO) MvcResult(org.springframework.test.web.servlet.MvcResult) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 4 with PdpClientDTO

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

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

the class CoverageDriverTest method discoverCoveragePeriods.

@DisplayName("Loading coverage periods")
@Test
void discoverCoveragePeriods() {
    Contract attestedAfterEpoch = dataSetup.setupContract("TST-AFTER-EPOCH", AB2D_EPOCH.toOffsetDateTime().plusMonths(3));
    contractRepo.saveAndFlush(attestedAfterEpoch);
    PdpClientDTO attestedAfterClient = createClient(attestedAfterEpoch, "TST-AFTER-EPOCH", SPONSOR_ROLE);
    pdpClientService.createClient(attestedAfterClient);
    dataSetup.queueForCleanup(pdpClientService.getClientById("TST-AFTER-EPOCH"));
    Contract attestedBeforeEpoch = dataSetup.setupContract("TST-BEFORE-EPOCH", AB2D_EPOCH.toOffsetDateTime().minusNanos(1));
    contractRepo.saveAndFlush(attestedBeforeEpoch);
    PdpClientDTO attestedBeforeClient = createClient(attestedBeforeEpoch, "TST-BEFORE-EPOCH", SPONSOR_ROLE);
    pdpClientService.createClient(attestedBeforeClient);
    dataSetup.queueForCleanup(pdpClientService.getClientById("TST-BEFORE-EPOCH"));
    long months = ChronoUnit.MONTHS.between(AB2D_EPOCH.toOffsetDateTime(), OffsetDateTime.now());
    long expectedNumPeriods = months + 1;
    try {
        driver.discoverCoveragePeriods();
    } catch (CoverageDriverException | InterruptedException exception) {
        fail("could not queue periods due to driver exception", exception);
    }
    List<CoveragePeriod> periods = coveragePeriodRepo.findAllByContractNumber(contract.getContractNumber());
    assertFalse(periods.isEmpty());
    assertEquals(expectedNumPeriods, periods.size());
    periods = coveragePeriodRepo.findAllByContractNumber(attestedAfterEpoch.getContractNumber());
    assertFalse(periods.isEmpty());
    assertEquals(expectedNumPeriods - 3, periods.size());
    periods = coveragePeriodRepo.findAllByContractNumber(attestedBeforeEpoch.getContractNumber());
    assertFalse(periods.isEmpty());
    assertEquals(expectedNumPeriods, periods.size());
}
Also used : PdpClientDTO(gov.cms.ab2d.common.dto.PdpClientDTO) CoveragePeriod(gov.cms.ab2d.coverage.model.CoveragePeriod) Contract(gov.cms.ab2d.common.model.Contract) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

PdpClientDTO (gov.cms.ab2d.common.dto.PdpClientDTO)18 Test (org.junit.jupiter.api.Test)10 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)10 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)8 MvcResult (org.springframework.test.web.servlet.MvcResult)6 Role (gov.cms.ab2d.common.model.Role)4 ContractDTO (gov.cms.ab2d.common.dto.ContractDTO)3 Contract (gov.cms.ab2d.common.model.Contract)3 PdpClient (gov.cms.ab2d.common.model.PdpClient)3 BFDClient (gov.cms.ab2d.bfd.client.BFDClient)2 CoveragePeriod (gov.cms.ab2d.coverage.model.CoveragePeriod)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 DisplayName (org.junit.jupiter.api.DisplayName)2 ResponseEntity (org.springframework.http.ResponseEntity)2 ThreadPoolTaskExecutor (org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor)2 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)2 Job (gov.cms.ab2d.common.model.Job)1 ContractService (gov.cms.ab2d.common.service.ContractService)1 RoleService (gov.cms.ab2d.common.service.RoleService)1 ContractForCoverageDTO (gov.cms.ab2d.coverage.model.ContractForCoverageDTO)1