Search in sources :

Example 1 with Properties

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

Example 2 with Properties

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

the class PropertiesChangeDetectionTest method testChangeInProperties.

@Test
public void testChangeInProperties() {
    assertEquals(autoScalingService.getCorePoolSize(), 10);
    assertEquals(autoScalingService.getMaxPoolSize(), 150);
    assertEquals(autoScalingService.getScaleToMaxTime(), 900.0, 0);
    Properties propertiesCorePoolSize = propertiesRepository.findByKey(PCP_CORE_POOL_SIZE).get();
    propertiesCorePoolSize.setValue("8");
    propertiesRepository.save(propertiesCorePoolSize);
    Properties propertiesMaxPoolSize = propertiesRepository.findByKey(PCP_MAX_POOL_SIZE).get();
    propertiesMaxPoolSize.setValue("300");
    propertiesRepository.save(propertiesMaxPoolSize);
    Properties propertiesScaleToMaxTime = propertiesRepository.findByKey(PCP_SCALE_TO_MAX_TIME).get();
    propertiesScaleToMaxTime.setValue("1500");
    propertiesRepository.save(propertiesScaleToMaxTime);
    propertiesChangeDetection.detectChanges();
    assertEquals(autoScalingService.getCorePoolSize(), 8);
    assertEquals(autoScalingService.getMaxPoolSize(), 300);
    assertEquals(autoScalingService.getScaleToMaxTime(), 1500.0, 0);
    Object valuePCPCorePoolSize = configurableEnvironment.getPropertySources().get("application").getProperty(PCP_CORE_POOL_SIZE);
    assertEquals(valuePCPCorePoolSize, "8");
    Object valuePCPMaxPoolSize = configurableEnvironment.getPropertySources().get("application").getProperty(PCP_MAX_POOL_SIZE);
    assertEquals(valuePCPMaxPoolSize, "300");
    Object valuePCPScaleToMaxTime = configurableEnvironment.getPropertySources().get("application").getProperty(PCP_SCALE_TO_MAX_TIME);
    assertEquals(valuePCPScaleToMaxTime, "1500");
    // Cleanup
    propertiesCorePoolSize.setValue("10");
    propertiesRepository.save(propertiesCorePoolSize);
    propertiesMaxPoolSize.setValue("150");
    propertiesRepository.save(propertiesMaxPoolSize);
    propertiesScaleToMaxTime.setValue("900");
    propertiesRepository.save(propertiesScaleToMaxTime);
}
Also used : Properties(gov.cms.ab2d.common.model.Properties) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 3 with Properties

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

the class CoveragePeriodQuartzJobTest method engageSearchWorks.

@DisplayName("Engaging coverage search works")
@Test
void engageSearchWorks() {
    PropertiesService propertiesService = mock(PropertiesService.class);
    when(propertiesService.getPropertiesByKey(eq(Constants.COVERAGE_SEARCH_DISCOVERY))).thenAnswer((arg) -> {
        Properties engaged = new Properties();
        engaged.setKey(Constants.COVERAGE_SEARCH_DISCOVERY);
        engaged.setValue("engaged");
        return engaged;
    });
    when(propertiesService.getPropertiesByKey(eq(Constants.COVERAGE_SEARCH_QUEUEING))).thenAnswer((arg) -> {
        Properties engaged = new Properties();
        engaged.setKey(Constants.COVERAGE_SEARCH_QUEUEING);
        engaged.setValue("engaged");
        return engaged;
    });
    when(propertiesService.getPropertiesByKey(eq(COVERAGE_SEARCH_OVERRIDE))).thenAnswer((arg) -> {
        Properties override = new Properties();
        override.setKey(COVERAGE_SEARCH_OVERRIDE);
        override.setValue("true");
        return override;
    });
    CoverageDriverStub coverageDriverStub = new CoverageDriverStub();
    CoveragePeriodQuartzJob quartzJob = new CoveragePeriodQuartzJob(coverageDriverStub, propertiesService, logManager);
    try {
        quartzJob.executeInternal(null);
        assertTrue(coverageDriverStub.discoveryCalled);
        assertTrue(coverageDriverStub.queueingCalled);
    } catch (JobExecutionException jobExecutionException) {
        fail("could not execute normally", jobExecutionException);
    }
}
Also used : CoverageDriverStub(gov.cms.ab2d.worker.processor.coverage.CoverageDriverStub) JobExecutionException(org.quartz.JobExecutionException) PropertiesService(gov.cms.ab2d.common.service.PropertiesService) Properties(gov.cms.ab2d.common.model.Properties) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 4 with Properties

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

the class CoveragePeriodQuartzJobTest method failingSearchesTriggerAlerts.

@DisplayName("Failing searches trigger alerts")
@Test
void failingSearchesTriggerAlerts() {
    PropertiesService propertiesService = mock(PropertiesService.class);
    when(propertiesService.getPropertiesByKey(eq(Constants.COVERAGE_SEARCH_DISCOVERY))).thenAnswer((arg) -> {
        Properties engaged = new Properties();
        engaged.setKey(Constants.COVERAGE_SEARCH_DISCOVERY);
        engaged.setValue("engaged");
        return engaged;
    });
    when(propertiesService.getPropertiesByKey(eq(COVERAGE_SEARCH_OVERRIDE))).thenAnswer((arg) -> {
        Properties override = new Properties();
        override.setKey(COVERAGE_SEARCH_OVERRIDE);
        override.setValue("true");
        return override;
    });
    try {
        doThrow(new RuntimeException("testing123")).when(coverageDriverMock).discoverCoveragePeriods();
        CoveragePeriodQuartzJob quartzJob = new CoveragePeriodQuartzJob(coverageDriverMock, propertiesService, logManager);
        JobExecutionException exception = assertThrows(JobExecutionException.class, () -> quartzJob.executeInternal(null));
        assertTrue(exception.getMessage().contains("testing123"));
        verify(logManager, times(1)).alert(contains("coverage period updates could not be conducted"), anyList());
    } catch (Exception ex) {
        fail("could not execute test due to interruption", ex);
    }
}
Also used : JobExecutionException(org.quartz.JobExecutionException) PropertiesService(gov.cms.ab2d.common.service.PropertiesService) Properties(gov.cms.ab2d.common.model.Properties) JobExecutionException(org.quartz.JobExecutionException) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 5 with Properties

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

the class BFDHealthCheckTest method testBfdComingBackUp.

@Test
public void testBfdComingBackUp() throws IOException {
    // First take down, since BFD starts as up
    MockBfdServiceUtils.createMockServerMetaExpectation(TEST_DIR + "meta-unknown-status.xml", MOCK_SERVER_PORT);
    for (int i = 0; i < consecutiveFailuresToTakeDown; i++) {
        bfdHealthCheck.checkBFDHealth();
    }
    MockBfdServiceUtils.reset(MOCK_SERVER_PORT);
    MockBfdServiceUtils.createMockServerMetaExpectation(TEST_DIR + "meta.xml", MOCK_SERVER_PORT);
    Properties maintenanceProperties = propertiesService.getPropertiesByKey(MAINTENANCE_MODE);
    assertEquals("true", maintenanceProperties.getValue());
    for (int i = 0; i < consecutiveSuccessesToBringUp; i++) {
        bfdHealthCheck.checkBFDHealth();
    }
    maintenanceProperties = propertiesService.getPropertiesByKey(MAINTENANCE_MODE);
    assertEquals("false", maintenanceProperties.getValue());
}
Also used : Properties(gov.cms.ab2d.common.model.Properties) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

Properties (gov.cms.ab2d.common.model.Properties)13 Test (org.junit.jupiter.api.Test)12 DisplayName (org.junit.jupiter.api.DisplayName)6 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)6 JobExecutionException (org.quartz.JobExecutionException)4 PropertiesService (gov.cms.ab2d.common.service.PropertiesService)3 CoverageDriverStub (gov.cms.ab2d.worker.processor.coverage.CoverageDriverStub)3 ContractDTO (gov.cms.ab2d.common.dto.ContractDTO)1 PropertiesDTO (gov.cms.ab2d.common.dto.PropertiesDTO)1 Job (gov.cms.ab2d.common.model.Job)1 OffsetDateTime (java.time.OffsetDateTime)1 HashMap (java.util.HashMap)1