Search in sources :

Example 1 with PropertiesDTO

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

the class AdminAPIPropertiesTests method testRetrieveProperties.

@Test
@Order(1)
public void testRetrieveProperties() throws Exception {
    Map<String, Object> propertyMap = new HashMap<>() {

        {
            put(PCP_CORE_POOL_SIZE, 10);
            put(PCP_MAX_POOL_SIZE, 150);
            put(PCP_SCALE_TO_MAX_TIME, 900);
            put(MAINTENANCE_MODE, "false");
            put(ZIP_SUPPORT_ON, "false");
            put(WORKER_ENGAGEMENT, "engaged");
            put(HPMS_INGESTION_ENGAGEMENT, "engaged");
            put(COVERAGE_SEARCH_DISCOVERY, "idle");
            put(COVERAGE_SEARCH_QUEUEING, "idle");
            put(COVERAGE_SEARCH_UPDATE_MONTHS, 1);
            put(COVERAGE_SEARCH_STUCK_HOURS, 24);
            put(COVERAGE_SEARCH_OVERRIDE, "false");
        }
    };
    MvcResult mvcResult = this.mockMvc.perform(get(API_PREFIX_V1 + ADMIN_PREFIX + PROPERTIES_URL).contentType(MediaType.APPLICATION_JSON).header("Authorization", "Bearer " + token)).andReturn();
    assertEquals(200, mvcResult.getResponse().getStatus());
    String result = mvcResult.getResponse().getContentAsString();
    ObjectMapper mapper = new ObjectMapper();
    List<PropertiesDTO> propertiesDTOs = mapper.readValue(result, new TypeReference<>() {
    });
    assertEquals(12, propertiesDTOs.size());
    for (PropertiesDTO propertiesDTO : propertiesDTOs) {
        Object value = propertyMap.get(propertiesDTO.getKey());
        assertNotNull(value);
        assertEquals(value.toString(), propertiesDTO.getValue());
    }
}
Also used : HashMap(java.util.HashMap) MvcResult(org.springframework.test.web.servlet.MvcResult) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) PropertiesDTO(gov.cms.ab2d.common.dto.PropertiesDTO) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with PropertiesDTO

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

the class MaintenanceModeAPITests method testMaintenanceModeOn.

@Test
@Order(2)
public void testMaintenanceModeOn() throws Exception {
    PropertiesDTO propertiesDTO = new PropertiesDTO();
    propertiesDTO.setKey(MAINTENANCE_MODE);
    propertiesDTO.setValue("true");
    propertiesService.updateProperties(List.of(propertiesDTO));
    this.mockMvc.perform(get(STATUS_ENDPOINT).contentType(MediaType.APPLICATION_JSON)).andExpect(status().is(200)).andExpect(jsonPath("$.maintenanceMode", Is.is("true")));
}
Also used : PropertiesDTO(gov.cms.ab2d.common.dto.PropertiesDTO) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 3 with PropertiesDTO

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

the class TestUtil method turnMaintenanceModeOff.

public void turnMaintenanceModeOff() {
    PropertiesDTO propertiesDTO = new PropertiesDTO();
    propertiesDTO.setKey(MAINTENANCE_MODE);
    propertiesDTO.setValue("false");
    List<PropertiesDTO> propertiesDTOs = new ArrayList<>();
    propertiesDTOs.add(propertiesDTO);
    propertiesService.updateProperties(propertiesDTOs);
}
Also used : PropertiesDTO(gov.cms.ab2d.common.dto.PropertiesDTO)

Example 4 with PropertiesDTO

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

the class AdminAPIMaintenanceModeTests method testSwitchMaintenanceModeOnAndOff.

@Test
public void testSwitchMaintenanceModeOnAndOff() throws Exception {
    List<PropertiesDTO> propertiesDTOs = new ArrayList<>();
    PropertiesDTO maintenanceModeDTO = new PropertiesDTO();
    maintenanceModeDTO.setKey(MAINTENANCE_MODE);
    maintenanceModeDTO.setValue("true");
    propertiesDTOs.add(maintenanceModeDTO);
    ObjectMapper mapper = new ObjectMapper();
    this.mockMvc.perform(put(API_PREFIX_V1 + ADMIN_PREFIX + PROPERTIES_URL).contentType(MediaType.APPLICATION_JSON).content(mapper.writeValueAsString(propertiesDTOs)).header("Authorization", "Bearer " + token)).andExpect(status().is(200));
    this.mockMvc.perform(get(API_PREFIX_V1 + FHIR_PREFIX + PATIENT_EXPORT_PATH).contentType(MediaType.APPLICATION_JSON).header("Authorization", "Bearer " + token)).andExpect(status().is(HttpStatus.SERVICE_UNAVAILABLE.value()));
    List<LoggableEvent> apiReqEvents = loggerEventRepository.load(ApiRequestEvent.class);
    assertEquals(2, apiReqEvents.size());
    List<LoggableEvent> apiResEvents = loggerEventRepository.load(ApiResponseEvent.class);
    assertEquals(1, apiResEvents.size());
    ApiResponseEvent responseEvent = (ApiResponseEvent) apiResEvents.get(0);
    assertEquals(HttpStatus.SERVICE_UNAVAILABLE.value(), responseEvent.getResponseCode());
    List<LoggableEvent> reloadEvents = loggerEventRepository.load(ReloadEvent.class);
    assertEquals(1, reloadEvents.size());
    ReloadEvent reloadEvent = (ReloadEvent) reloadEvents.get(0);
    assertEquals(ReloadEvent.FileType.PROPERTIES, reloadEvent.getFileType());
    assertTrue(UtilMethods.allEmpty(loggerEventRepository.load(ContractSearchEvent.class), loggerEventRepository.load(ErrorEvent.class), loggerEventRepository.load(FileEvent.class), loggerEventRepository.load(JobStatusChangeEvent.class)));
    propertiesDTOs.clear();
    maintenanceModeDTO.setValue("false");
    propertiesDTOs.add(maintenanceModeDTO);
    this.mockMvc.perform(put(API_PREFIX_V1 + ADMIN_PREFIX + PROPERTIES_URL).contentType(MediaType.APPLICATION_JSON).content(mapper.writeValueAsString(propertiesDTOs)).header("Authorization", "Bearer " + token)).andExpect(status().is(200));
    this.mockMvc.perform(get(API_PREFIX_V1 + FHIR_PREFIX + PATIENT_EXPORT_PATH).contentType(MediaType.APPLICATION_JSON).header("Authorization", "Bearer " + token)).andExpect(status().is(202));
}
Also used : LoggableEvent(gov.cms.ab2d.eventlogger.LoggableEvent) ArrayList(java.util.ArrayList) PropertiesDTO(gov.cms.ab2d.common.dto.PropertiesDTO) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 5 with PropertiesDTO

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

the class PropertiesServiceImpl method addUpdatedPropertiesToList.

private void addUpdatedPropertiesToList(List<PropertiesDTO> propertiesDTOsReturn, PropertiesDTO propertiesDTO) {
    Properties properties = getPropertiesByKey(propertiesDTO.getKey());
    Properties mappedProperties = mapping.getModelMapper().map(propertiesDTO, Properties.class);
    mappedProperties.setId(properties.getId());
    Properties updatedProperties = propertiesRepository.save(mappedProperties);
    log.info("Updated property {} with value {}", updatedProperties.getKey(), updatedProperties.getValue());
    propertiesDTOsReturn.add(mapping.getModelMapper().map(updatedProperties, PropertiesDTO.class));
}
Also used : Properties(gov.cms.ab2d.common.model.Properties) PropertiesDTO(gov.cms.ab2d.common.dto.PropertiesDTO)

Aggregations

PropertiesDTO (gov.cms.ab2d.common.dto.PropertiesDTO)25 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)12 ArrayList (java.util.ArrayList)11 Test (org.junit.jupiter.api.Test)6 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 HashMap (java.util.HashMap)3 AfterEach (org.junit.jupiter.api.AfterEach)3 MvcResult (org.springframework.test.web.servlet.MvcResult)3 Properties (gov.cms.ab2d.common.model.Properties)2 OffsetDateTime (java.time.OffsetDateTime)2 DisplayName (org.junit.jupiter.api.DisplayName)2 SpringBootApp (gov.cms.ab2d.common.SpringBootApp)1 JobOutput (gov.cms.ab2d.common.model.JobOutput)1 PropertiesRepository (gov.cms.ab2d.common.repository.PropertiesRepository)1 FeatureEngagement (gov.cms.ab2d.common.service.FeatureEngagement)1 JobServiceImpl (gov.cms.ab2d.common.service.JobServiceImpl)1 AB2DPostgresqlContainer (gov.cms.ab2d.common.util.AB2DPostgresqlContainer)1 Constants (gov.cms.ab2d.common.util.Constants)1 CoveragePeriod (gov.cms.ab2d.coverage.model.CoveragePeriod)1 LoggableEvent (gov.cms.ab2d.eventlogger.LoggableEvent)1