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());
}
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;
}
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);
}
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;
}
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));
}
Aggregations