use of eu.bcvsolutions.idm.core.monitoring.api.dto.filter.IdmMonitoringResultFilter in project CzechIdMng by bcvsolutions.
the class IdmMonitoringResultControllerRestTest method testFindByLevel.
@Test
public void testFindByLevel() {
String instanceId = getHelper().createName();
IdmMonitoringResultDto result = prepareDto();
result.setInstanceId(instanceId);
result.setLevel(NotificationLevel.ERROR);
IdmMonitoringResultDto resultOne = createDto(result);
result = prepareDto();
result.setInstanceId(instanceId);
result.setLevel(NotificationLevel.WARNING);
IdmMonitoringResultDto resultTwo = createDto(result);
result = prepareDto();
result.setInstanceId(instanceId);
result.setLevel(NotificationLevel.INFO);
// other
createDto(result);
//
IdmMonitoringResultFilter filter = new IdmMonitoringResultFilter();
filter.setInstanceId(instanceId);
filter.setLevels(Lists.newArrayList(NotificationLevel.ERROR, NotificationLevel.WARNING));
List<IdmMonitoringResultDto> results = find(filter);
//
Assert.assertEquals(2, results.size());
Assert.assertTrue(results.stream().anyMatch(r -> r.getId().equals(resultOne.getId())));
Assert.assertTrue(results.stream().anyMatch(r -> r.getId().equals(resultTwo.getId())));
}
use of eu.bcvsolutions.idm.core.monitoring.api.dto.filter.IdmMonitoringResultFilter in project CzechIdMng by bcvsolutions.
the class IdmMonitoringController method getLastResult.
/**
* Get last monitoring result.
*
* @since 11.2.0
*/
@ResponseBody
@RequestMapping(method = RequestMethod.GET, value = "/{backendId}/last-result")
@PreAuthorize("hasAuthority('" + MonitoringGroupPermission.MONITORING_READ + "') " + "and hasAuthority('" + MonitoringGroupPermission.MONITORINGRESULT_READ + "')")
@ApiOperation(value = "Get last monitoring result", nickname = "getLastMonitoringResult", tags = { IdmMonitoringController.TAG }, authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = MonitoringGroupPermission.MONITORING_READ, description = ""), @AuthorizationScope(scope = MonitoringGroupPermission.MONITORINGRESULT_READ, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = MonitoringGroupPermission.MONITORING_READ, description = ""), @AuthorizationScope(scope = MonitoringGroupPermission.MONITORINGRESULT_READ, description = "") }) }, notes = "Get last monitoring result.")
public ResponseEntity<?> getLastResult(@ApiParam(value = "Monitoring codeable identifier.", required = true) @PathVariable @NotNull String backendId) {
IdmMonitoringDto monitoring = getDto(backendId);
if (monitoring == null) {
throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("entity", backendId));
}
IdmMonitoringResultFilter filter = new IdmMonitoringResultFilter();
filter.setMonitoring(monitoring.getId());
List<IdmMonitoringResultDto> lastResults = monitoringManager.getLastResults(filter, PageRequest.of(0, 1), IdmBasePermission.READ).getContent();
// without result
if (lastResults.isEmpty()) {
new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
// return last result
return new ResponseEntity<>(monitoringResultController.toResource(lastResults.get(0)), HttpStatus.OK);
}
use of eu.bcvsolutions.idm.core.monitoring.api.dto.filter.IdmMonitoringResultFilter in project CzechIdMng by bcvsolutions.
the class DefaultMonitoringManagerIntegrationTest method testReferentiralIntegrity.
@Test
public void testReferentiralIntegrity() {
IdmMonitoringDto monitoring = new IdmMonitoringDto();
monitoring.setCheckPeriod(0L);
monitoring.setEvaluatorType(AutowireHelper.getTargetType(h2DatabaseMonitoringEvaluator));
monitoring.setInstanceId(configurationService.getInstanceId());
monitoring = monitoringService.save(monitoring);
//
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());
//
monitoringService.delete(monitoring);
//
results = monitoringResultService.find(filter, null).getContent();
Assert.assertTrue(results.isEmpty());
}
use of eu.bcvsolutions.idm.core.monitoring.api.dto.filter.IdmMonitoringResultFilter in project CzechIdMng by bcvsolutions.
the class DefaultMonitoringManagerIntegrationTest method testNotExecuteBeforeExecuteDate.
@Test
public void testNotExecuteBeforeExecuteDate() {
IdmMonitoringDto monitoring = new IdmMonitoringDto();
monitoring.setCheckPeriod(0L);
monitoring.setEvaluatorType(AutowireHelper.getTargetType(h2DatabaseMonitoringEvaluator));
monitoring.setInstanceId(configurationService.getInstanceId());
monitoring.setExecuteDate(ZonedDateTime.now().plusHours(1));
monitoring = monitoringService.save(monitoring);
try {
//
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.assertTrue(results.isEmpty());
} finally {
monitoringService.delete(monitoring);
}
}
use of eu.bcvsolutions.idm.core.monitoring.api.dto.filter.IdmMonitoringResultFilter in project CzechIdMng by bcvsolutions.
the class DefaultMonitoringManagerIntegrationTest method testNotExecuteDisabledMonitoring.
@Test
public void testNotExecuteDisabledMonitoring() {
IdmMonitoringDto monitoring = new IdmMonitoringDto();
monitoring.setCheckPeriod(0L);
monitoring.setEvaluatorType(AutowireHelper.getTargetType(h2DatabaseMonitoringEvaluator));
monitoring.setInstanceId(configurationService.getInstanceId());
monitoring.setDisabled(true);
monitoring = monitoringService.save(monitoring);
try {
//
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.assertTrue(results.isEmpty());
} finally {
monitoringService.delete(monitoring);
}
}
Aggregations