Search in sources :

Example 1 with GlobalSchedulingConfigEntity

use of com.blackducksoftware.integration.hub.alert.scheduling.repository.global.GlobalSchedulingConfigEntity in project hub-alert by blackducksoftware.

the class GlobalSchedulingConfigControllerTestIT method testTestConfig.

@Test
@Override
@WithMockUser(roles = "ADMIN")
public void testTestConfig() throws Exception {
    globalEntityRepository.deleteAll();
    final GlobalSchedulingConfigEntity savedEntity = globalEntityRepository.save(entity);
    final String testRestUrl = restUrl + "/test";
    final MockHttpServletRequestBuilder request = MockMvcRequestBuilders.post(testRestUrl).with(SecurityMockMvcRequestPostProcessors.user("admin").roles("ADMIN"));
    restModel.setId(String.valueOf(savedEntity.getId()));
    request.content(gson.toJson(restModel));
    request.contentType(contentType);
    mockMvc.perform(request).andExpect(MockMvcResultMatchers.status().isMethodNotAllowed());
}
Also used : GlobalSchedulingConfigEntity(com.blackducksoftware.integration.hub.alert.scheduling.repository.global.GlobalSchedulingConfigEntity) MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) WithMockUser(org.springframework.security.test.context.support.WithMockUser) GlobalControllerTest(com.blackducksoftware.integration.hub.alert.web.controller.GlobalControllerTest) Test(org.junit.Test)

Example 2 with GlobalSchedulingConfigEntity

use of com.blackducksoftware.integration.hub.alert.scheduling.repository.global.GlobalSchedulingConfigEntity in project hub-alert by blackducksoftware.

the class MockGlobalSchedulingEntity method createGlobalEntity.

@Override
public GlobalSchedulingConfigEntity createGlobalEntity() {
    final GlobalSchedulingConfigEntity entity = new GlobalSchedulingConfigEntity(dailyDigestHourOfDay, purgeDataFrequencyDays);
    entity.setId(id);
    return entity;
}
Also used : GlobalSchedulingConfigEntity(com.blackducksoftware.integration.hub.alert.scheduling.repository.global.GlobalSchedulingConfigEntity)

Example 3 with GlobalSchedulingConfigEntity

use of com.blackducksoftware.integration.hub.alert.scheduling.repository.global.GlobalSchedulingConfigEntity in project hub-alert by blackducksoftware.

the class StartupManager method initializeCronJobs.

public void initializeCronJobs() {
    final List<GlobalSchedulingConfigEntity> globalSchedulingConfigs = globalSchedulingRepository.findAll();
    String dailyDigestHourOfDay = null;
    String purgeDataFrequencyDays = null;
    if (!globalSchedulingConfigs.isEmpty() && globalSchedulingConfigs.get(0) != null) {
        final GlobalSchedulingConfigEntity globalSchedulingConfig = globalSchedulingConfigs.get(0);
        dailyDigestHourOfDay = globalSchedulingConfig.getDailyDigestHourOfDay();
        purgeDataFrequencyDays = globalSchedulingConfig.getPurgeDataFrequencyDays();
    } else {
        dailyDigestHourOfDay = "0";
        purgeDataFrequencyDays = "3";
        final GlobalSchedulingConfigEntity globalSchedulingConfig = new GlobalSchedulingConfigEntity(dailyDigestHourOfDay, purgeDataFrequencyDays);
        final GlobalSchedulingConfigEntity savedGlobalSchedulingConfig = globalSchedulingRepository.save(globalSchedulingConfig);
        logger.info(savedGlobalSchedulingConfig.toString());
    }
    scheduleCronJobs(dailyDigestHourOfDay, purgeDataFrequencyDays);
}
Also used : GlobalSchedulingConfigEntity(com.blackducksoftware.integration.hub.alert.scheduling.repository.global.GlobalSchedulingConfigEntity)

Example 4 with GlobalSchedulingConfigEntity

use of com.blackducksoftware.integration.hub.alert.scheduling.repository.global.GlobalSchedulingConfigEntity in project hub-alert by blackducksoftware.

the class GlobalSchedulingConfigActions method getConfig.

@Override
public List<GlobalSchedulingConfigRestModel> getConfig(final Long id) throws AlertException {
    GlobalSchedulingConfigEntity databaseEntity = null;
    if (id != null) {
        databaseEntity = getRepository().findOne(id);
    } else {
        final List<GlobalSchedulingConfigEntity> databaseEntities = getRepository().findAll();
        if (databaseEntities != null && !databaseEntities.isEmpty()) {
            databaseEntity = databaseEntities.get(0);
        }
    }
    GlobalSchedulingConfigRestModel restModel = null;
    if (databaseEntity != null) {
        restModel = getObjectTransformer().databaseEntityToConfigRestModel(databaseEntity, getConfigRestModelClass());
        restModel.setDailyDigestNextRun(dailyDigestBatchConfig.getFormatedNextRunTime());
        restModel.setPurgeDataNextRun(purgeConfig.getFormatedNextRunTime());
    } else {
        restModel = new GlobalSchedulingConfigRestModel();
    }
    final Long accumulatorNextRun = accumulatorConfig.getMillisecondsToNextRun();
    if (accumulatorNextRun != null) {
        final Long seconds = TimeUnit.MILLISECONDS.toSeconds(accumulatorConfig.getMillisecondsToNextRun());
        restModel.setAccumulatorNextRun(String.valueOf(seconds));
    }
    final List<GlobalSchedulingConfigRestModel> restModels = new ArrayList<>();
    restModels.add(restModel);
    return restModels;
}
Also used : GlobalSchedulingConfigEntity(com.blackducksoftware.integration.hub.alert.scheduling.repository.global.GlobalSchedulingConfigEntity) ArrayList(java.util.ArrayList)

Example 5 with GlobalSchedulingConfigEntity

use of com.blackducksoftware.integration.hub.alert.scheduling.repository.global.GlobalSchedulingConfigEntity in project hub-alert by blackducksoftware.

the class StartupManagerTest method testInitializeCronJobs.

@Test
public void testInitializeCronJobs() throws IOException {
    final AccumulatorConfig accumulatorConfig = Mockito.mock(AccumulatorConfig.class);
    Mockito.doNothing().when(accumulatorConfig).scheduleJobExecution(Mockito.anyString());
    Mockito.doReturn(1L).when(accumulatorConfig).getMillisecondsToNextRun();
    final DailyDigestBatchConfig dailyDigestBatchConfig = Mockito.mock(DailyDigestBatchConfig.class);
    Mockito.doNothing().when(dailyDigestBatchConfig).scheduleJobExecution(Mockito.anyString());
    Mockito.doReturn("time").when(dailyDigestBatchConfig).getFormatedNextRunTime();
    final PurgeConfig purgeConfig = Mockito.mock(PurgeConfig.class);
    Mockito.doNothing().when(purgeConfig).scheduleJobExecution(Mockito.anyString());
    Mockito.doReturn("time").when(purgeConfig).getFormatedNextRunTime();
    final GlobalSchedulingRepositoryWrapper globalSchedulingRepositoryWrapper = Mockito.mock(GlobalSchedulingRepositoryWrapper.class);
    final MockGlobalSchedulingEntity mockGlobalSchedulingEntity = new MockGlobalSchedulingEntity();
    final GlobalSchedulingConfigEntity entity = mockGlobalSchedulingEntity.createGlobalEntity();
    Mockito.when(globalSchedulingRepositoryWrapper.save(Mockito.any(GlobalSchedulingConfigEntity.class))).thenReturn(entity);
    final StartupManager startupManager = new StartupManager(globalSchedulingRepositoryWrapper, null, accumulatorConfig, dailyDigestBatchConfig, purgeConfig);
    startupManager.initializeCronJobs();
    final String expectedLog = entity.toString();
    assertTrue(outputLogger.isLineContainingText(expectedLog));
}
Also used : AccumulatorConfig(com.blackducksoftware.integration.hub.alert.config.AccumulatorConfig) MockGlobalSchedulingEntity(com.blackducksoftware.integration.hub.alert.scheduling.mock.MockGlobalSchedulingEntity) GlobalSchedulingRepositoryWrapper(com.blackducksoftware.integration.hub.alert.scheduling.repository.global.GlobalSchedulingRepositoryWrapper) GlobalSchedulingConfigEntity(com.blackducksoftware.integration.hub.alert.scheduling.repository.global.GlobalSchedulingConfigEntity) PurgeConfig(com.blackducksoftware.integration.hub.alert.config.PurgeConfig) DailyDigestBatchConfig(com.blackducksoftware.integration.hub.alert.config.DailyDigestBatchConfig) Test(org.junit.Test)

Aggregations

GlobalSchedulingConfigEntity (com.blackducksoftware.integration.hub.alert.scheduling.repository.global.GlobalSchedulingConfigEntity)5 Test (org.junit.Test)2 AccumulatorConfig (com.blackducksoftware.integration.hub.alert.config.AccumulatorConfig)1 DailyDigestBatchConfig (com.blackducksoftware.integration.hub.alert.config.DailyDigestBatchConfig)1 PurgeConfig (com.blackducksoftware.integration.hub.alert.config.PurgeConfig)1 MockGlobalSchedulingEntity (com.blackducksoftware.integration.hub.alert.scheduling.mock.MockGlobalSchedulingEntity)1 GlobalSchedulingRepositoryWrapper (com.blackducksoftware.integration.hub.alert.scheduling.repository.global.GlobalSchedulingRepositoryWrapper)1 GlobalControllerTest (com.blackducksoftware.integration.hub.alert.web.controller.GlobalControllerTest)1 ArrayList (java.util.ArrayList)1 WithMockUser (org.springframework.security.test.context.support.WithMockUser)1 MockHttpServletRequestBuilder (org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder)1