Search in sources :

Example 41 with ContractDTO

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

the class CoverageCheckPredicatesUnitTest method whenCoverageDuplicated_failCoverageDuplicationCheck.

@DisplayName("Duplicate enrollment counts cause a failure")
@Test
void whenCoverageDuplicated_failCoverageDuplicationCheck() {
    Map<String, List<CoverageCount>> coverageCounts = new HashMap<>();
    List<String> issues = new ArrayList<>();
    CoverageNoDuplicatesCheck duplicatesCheck = new CoverageNoDuplicatesCheck(coverageService, coverageCounts, issues);
    ContractDTO contract = getContractDTO();
    List<CoverageCount> fakeCounts = List.of(new CoverageCount("TEST", ATTESTATION_TIME.plusMonths(0).getYear(), ATTESTATION_TIME.plusMonths(0).getMonthValue(), 1, 1, 1), new CoverageCount("TEST", ATTESTATION_TIME.plusMonths(1).getYear(), ATTESTATION_TIME.plusMonths(1).getMonthValue(), 2, 1, 1), new CoverageCount("TEST", ATTESTATION_TIME.plusMonths(1).getYear(), ATTESTATION_TIME.plusMonths(1).getMonthValue(), 2, 1, 1), new CoverageCount("TEST", ATTESTATION_TIME.plusMonths(1).getYear(), ATTESTATION_TIME.plusMonths(1).getMonthValue(), 2, 1, 1), new CoverageCount("TEST", ATTESTATION_TIME.plusMonths(2).getYear(), ATTESTATION_TIME.plusMonths(2).getMonthValue(), 3, 1, 1), new CoverageCount("TEST", ATTESTATION_TIME.plusMonths(2).getYear(), ATTESTATION_TIME.plusMonths(2).getMonthValue(), 3, 1, 1));
    coverageCounts.put("TEST", fakeCounts);
    assertFalse(duplicatesCheck.test(contract));
    assertEquals(2, issues.size());
    issues.forEach(issue -> assertTrue(issue.contains("sets of enrollment")));
}
Also used : HashMap(java.util.HashMap) ContractDTO(gov.cms.ab2d.common.dto.ContractDTO) CoverageCount(gov.cms.ab2d.coverage.model.CoverageCount) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 42 with ContractDTO

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

the class AdminAPIPdpClientTests method getClient.

@Test
public void getClient() throws Exception {
    // Ensure client is in right state first
    setupClient(ENABLE_DISABLE_CLIENT, true);
    MvcResult mvcResult = this.mockMvc.perform(get(API_PREFIX_V1 + ADMIN_PREFIX + CLIENT_URL + "/" + ENABLE_DISABLE_CONTRACT).contentType(MediaType.APPLICATION_JSON).header("Authorization", "Bearer " + token)).andReturn();
    assertEquals(200, mvcResult.getResponse().getStatus());
    ObjectMapper mapper = getMapper();
    String getResult = mvcResult.getResponse().getContentAsString();
    PdpClientDTO pdpClientDTO = mapper.readValue(getResult, PdpClientDTO.class);
    assertEquals(ENABLE_DISABLE_CLIENT, pdpClientDTO.getClientId());
    assertEquals(true, pdpClientDTO.getEnabled());
    ContractDTO contractDTO = pdpClientDTO.getContract();
    assertEquals(ENABLE_DISABLE_CONTRACT, contractDTO.getContractNumber());
    assertEquals("Test Contract Z0000", contractDTO.getContractName());
    assertNotNull(contractDTO.getAttestedOn());
}
Also used : ContractDTO(gov.cms.ab2d.common.dto.ContractDTO) 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 43 with ContractDTO

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

the class Mapping method init.

@PostConstruct
public void init() {
    modelMapper = new ModelMapper();
    modelMapper.getConfiguration().setSkipNullEnabled(true);
    Converter<String, Role> roleDTOToRoleConverter = context -> {
        if (context.getSource() == null) {
            return null;
        } else {
            return roleService.findRoleByName(context.getSource());
        }
    };
    Converter<Set<Role>, String> roleToRoleDTOConverter = context -> {
        if (context.getSource() == null || context.getSource().isEmpty()) {
            return null;
        } else {
            return context.getSource().iterator().next().getName();
        }
    };
    Converter<ContractDTO, Contract> sponsorDTOSponsorConverter = new AbstractConverter<>() {

        protected Contract convert(ContractDTO source) {
            // NOSONAR
            return contractService.getContractByContractNumber(source.getContractNumber()).get();
        }
    };
    modelMapper.addConverter(sponsorDTOSponsorConverter);
    modelMapper.createTypeMap(PdpClient.class, PdpClientDTO.class).addMappings(mapper -> mapper.map(pdpClient -> pdpClient.getContract().toDTO(), PdpClientDTO::setContract)).addMappings(mapper -> mapper.using(roleToRoleDTOConverter).map(PdpClient::getRoles, PdpClientDTO::setRole)).addMappings(mapper -> mapper.map(PdpClient::getContract, PdpClientDTO::setContract));
    modelMapper.createTypeMap(PdpClientDTO.class, PdpClient.class).addMappings(mapper -> mapper.using(roleDTOToRoleConverter).map(PdpClientDTO::getRole, PdpClient::addRole)).addMappings(mapper -> mapper.map(PdpClientDTO::getClientId, PdpClient::setClientId));
}
Also used : PdpClient(gov.cms.ab2d.common.model.PdpClient) Contract(gov.cms.ab2d.common.model.Contract) ContractService(gov.cms.ab2d.common.service.ContractService) Set(java.util.Set) AbstractConverter(org.modelmapper.AbstractConverter) Role(gov.cms.ab2d.common.model.Role) ModelMapper(org.modelmapper.ModelMapper) Component(org.springframework.stereotype.Component) RoleService(gov.cms.ab2d.common.service.RoleService) Converter(org.modelmapper.Converter) PdpClientDTO(gov.cms.ab2d.common.dto.PdpClientDTO) PostConstruct(javax.annotation.PostConstruct) ContractDTO(gov.cms.ab2d.common.dto.ContractDTO) Set(java.util.Set) PdpClient(gov.cms.ab2d.common.model.PdpClient) ModelMapper(org.modelmapper.ModelMapper) Role(gov.cms.ab2d.common.model.Role) ContractDTO(gov.cms.ab2d.common.dto.ContractDTO) PdpClientDTO(gov.cms.ab2d.common.dto.PdpClientDTO) AbstractConverter(org.modelmapper.AbstractConverter) Contract(gov.cms.ab2d.common.model.Contract) PostConstruct(javax.annotation.PostConstruct)

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