use of eu.bcvsolutions.idm.core.monitoring.api.dto.IdmMonitoringDto in project CzechIdMng by bcvsolutions.
the class DefaultMonitoringManagerIntegrationTest method testRegisterMonitoringEvaluator.
@Test
public void testRegisterMonitoringEvaluator() {
IdmMonitoringDto monitoring = new IdmMonitoringDto();
monitoring.setCheckPeriod(0L);
monitoring.setEvaluatorType(AutowireHelper.getTargetType(h2DatabaseMonitoringEvaluator));
monitoring.setInstanceId(configurationService.getInstanceId());
monitoring = monitoringService.save(monitoring);
try {
//
manager.scheduleExecute();
manager.scheduleExecute();
manager.scheduleExecute();
//
IdmMonitoringResultFilter filter = new IdmMonitoringResultFilter();
filter.setMonitoring(monitoring.getId());
//
List<IdmMonitoringResultDto> results = monitoringResultService.find(filter, null).getContent();
// executed only once => 0 check period
Assert.assertEquals(1, results.size());
//
List<IdmMonitoringResultDto> lastResults = manager.getLastResults(filter, null).getContent();
//
Assert.assertEquals(1, lastResults.size());
Assert.assertEquals(results.get(0).getId(), lastResults.get(0).getId());
//
manager.init();
//
lastResults = manager.getLastResults(filter, null).getContent();
//
Assert.assertEquals(1, lastResults.size());
Assert.assertEquals(results.get(0).getId(), lastResults.get(0).getId());
} finally {
monitoringService.delete(monitoring);
}
}
use of eu.bcvsolutions.idm.core.monitoring.api.dto.IdmMonitoringDto in project CzechIdMng by bcvsolutions.
the class DefaultMonitoringManagerIntegrationTest method testRegisterMonitoringEvaluatorWithoutCheckPeriod.
@Test
public void testRegisterMonitoringEvaluatorWithoutCheckPeriod() {
IdmMonitoringDto monitoring = new IdmMonitoringDto();
// ~ 0
monitoring.setCheckPeriod(null);
monitoring.setEvaluatorType(AutowireHelper.getTargetType(h2DatabaseMonitoringEvaluator));
monitoring.setInstanceId(configurationService.getInstanceId());
monitoring = monitoringService.save(monitoring);
try {
//
manager.scheduleExecute();
manager.scheduleExecute();
manager.scheduleExecute();
//
IdmMonitoringResultFilter filter = new IdmMonitoringResultFilter();
filter.setMonitoring(monitoring.getId());
//
List<IdmMonitoringResultDto> results = monitoringResultService.find(filter, null).getContent();
// executed only once => 0 check period
Assert.assertEquals(1, results.size());
//
List<IdmMonitoringResultDto> lastResults = manager.getLastResults(filter, null).getContent();
//
Assert.assertEquals(1, lastResults.size());
Assert.assertEquals(results.get(0).getId(), lastResults.get(0).getId());
//
manager.init();
//
lastResults = manager.getLastResults(filter, null).getContent();
//
Assert.assertEquals(1, lastResults.size());
Assert.assertEquals(results.get(0).getId(), lastResults.get(0).getId());
//
// evict and load cache again
cacheManager.evictCache(MonitoringManager.LAST_RESULT_CACHE_NAME);
lastResults = manager.getLastResults(filter, null).getContent();
//
Assert.assertEquals(1, lastResults.size());
Assert.assertEquals(results.get(0).getId(), lastResults.get(0).getId());
} finally {
monitoringService.delete(monitoring);
}
}
use of eu.bcvsolutions.idm.core.monitoring.api.dto.IdmMonitoringDto in project CzechIdMng by bcvsolutions.
the class EntityEventMonitoringEvaluatorUnitTest method testErrorWithNumberOfDays.
@Test
public void testErrorWithNumberOfDays() {
Mockito.when(entityEventService.count(ArgumentMatchers.any())).thenReturn(10L);
//
IdmMonitoringDto monitoring = new IdmMonitoringDto();
monitoring.setInstanceId("mock");
monitoring.getEvaluatorProperties().put(AbstractDailyMonitoringEvaluator.PARAMETER_NUMBER_OF_DAYS, 2);
IdmMonitoringResultDto result = evaluator.evaluate(monitoring);
//
Assert.assertEquals(CoreResultCode.MONITORING_ENTITY_EVENT_ERROR.getCode(), result.getResult().getCode());
Assert.assertNull(result.getLevel());
}
use of eu.bcvsolutions.idm.core.monitoring.api.dto.IdmMonitoringDto in project CzechIdMng by bcvsolutions.
the class EntityEventMonitoringEvaluatorUnitTest method testError.
@Test
public void testError() {
Mockito.when(entityEventService.count(ArgumentMatchers.any())).thenReturn(10L);
//
IdmMonitoringDto monitoring = new IdmMonitoringDto();
monitoring.setInstanceId("mock");
IdmMonitoringResultDto result = evaluator.evaluate(monitoring);
//
Assert.assertEquals(CoreResultCode.MONITORING_ENTITY_EVENT_ERROR.getCode(), result.getResult().getCode());
Assert.assertNull(result.getLevel());
}
use of eu.bcvsolutions.idm.core.monitoring.api.dto.IdmMonitoringDto in project CzechIdMng by bcvsolutions.
the class IdmMonitoringResultControllerRestTest method testFindLastResults.
@Test
public void testFindLastResults() {
// evaluate monitoring
IdmMonitoringDto monitoring = new IdmMonitoringDto();
// ~ hour
monitoring.setCheckPeriod(3600L);
monitoring.setEvaluatorType(AutowireHelper.getTargetType(h2DatabaseMonitoringEvaluator));
monitoring.setInstanceId(configurationService.getInstanceId());
monitoring = monitoringService.save(monitoring);
//
monitoringManager.execute(monitoring);
monitoringManager.execute(monitoring);
monitoringManager.execute(monitoring);
//
IdmMonitoringResultFilter filter = new IdmMonitoringResultFilter();
filter.setMonitoring(monitoring.getId());
// workaround: result model cannot be deserialized automatically from json
monitoringResultService.find(filter, null).forEach(result -> {
result.setResult(new OperationResultDto(OperationState.EXECUTED));
monitoringResultService.save(result);
});
cacheManager.evictCache(MonitoringManager.LAST_RESULT_CACHE_NAME);
//
filter.setLastResult(true);
List<IdmMonitoringResultDto> lastResults = find(filter);
List<IdmMonitoringResultDto> results = find("last-results", filter);
//
Assert.assertEquals(1, results.size());
Assert.assertEquals(1, lastResults.size());
Assert.assertEquals(lastResults.get(0).getId(), results.get(0).getId());
}
Aggregations