Search in sources :

Example 6 with IdmMonitoringResultFilter

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())));
}
Also used : MonitoringManager(eu.bcvsolutions.idm.core.monitoring.api.service.MonitoringManager) Lists(org.testng.collections.Lists) IdmMonitoringService(eu.bcvsolutions.idm.core.monitoring.api.service.IdmMonitoringService) H2DatabaseMonitoringEvaluator(eu.bcvsolutions.idm.core.monitoring.service.impl.H2DatabaseMonitoringEvaluator) Autowired(org.springframework.beans.factory.annotation.Autowired) ConfigurationService(eu.bcvsolutions.idm.core.api.service.ConfigurationService) AbstractReadWriteDtoControllerRestTest(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoControllerRestTest) AutowireHelper(eu.bcvsolutions.idm.core.api.utils.AutowireHelper) AbstractReadWriteDtoController(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoController) SecurityMockMvcRequestPostProcessors.authentication(org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.authentication) MockMvcResultMatchers.status(org.springframework.test.web.servlet.result.MockMvcResultMatchers.status) OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) TestHelper(eu.bcvsolutions.idm.test.api.TestHelper) IdmMonitoringResultService(eu.bcvsolutions.idm.core.monitoring.api.service.IdmMonitoringResultService) MockMvcRequestBuilders.put(org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put) NotificationLevel(eu.bcvsolutions.idm.core.notification.api.domain.NotificationLevel) IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) IdmMonitoringDto(eu.bcvsolutions.idm.core.monitoring.api.dto.IdmMonitoringDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmCacheManager(eu.bcvsolutions.idm.core.api.service.IdmCacheManager) OperationState(eu.bcvsolutions.idm.core.api.domain.OperationState) Test(org.junit.Test) UUID(java.util.UUID) TestMonitoringEvaluator(eu.bcvsolutions.idm.core.monitoring.service.impl.TestMonitoringEvaluator) IdmMonitoringResultFilter(eu.bcvsolutions.idm.core.monitoring.api.dto.filter.IdmMonitoringResultFilter) List(java.util.List) IdmMonitoringResultDto(eu.bcvsolutions.idm.core.monitoring.api.dto.IdmMonitoringResultDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) Assert(org.junit.Assert) IdmMonitoringResultFilter(eu.bcvsolutions.idm.core.monitoring.api.dto.filter.IdmMonitoringResultFilter) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmMonitoringResultDto(eu.bcvsolutions.idm.core.monitoring.api.dto.IdmMonitoringResultDto) AbstractReadWriteDtoControllerRestTest(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoControllerRestTest) Test(org.junit.Test)

Example 7 with IdmMonitoringResultFilter

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);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) IdmMonitoringDto(eu.bcvsolutions.idm.core.monitoring.api.dto.IdmMonitoringDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IdmMonitoringResultFilter(eu.bcvsolutions.idm.core.monitoring.api.dto.filter.IdmMonitoringResultFilter) IdmMonitoringResultDto(eu.bcvsolutions.idm.core.monitoring.api.dto.IdmMonitoringResultDto) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 8 with IdmMonitoringResultFilter

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());
}
Also used : IdmMonitoringDto(eu.bcvsolutions.idm.core.monitoring.api.dto.IdmMonitoringDto) IdmMonitoringResultFilter(eu.bcvsolutions.idm.core.monitoring.api.dto.filter.IdmMonitoringResultFilter) IdmMonitoringResultDto(eu.bcvsolutions.idm.core.monitoring.api.dto.IdmMonitoringResultDto) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)

Example 9 with IdmMonitoringResultFilter

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);
    }
}
Also used : IdmMonitoringDto(eu.bcvsolutions.idm.core.monitoring.api.dto.IdmMonitoringDto) IdmMonitoringResultFilter(eu.bcvsolutions.idm.core.monitoring.api.dto.filter.IdmMonitoringResultFilter) IdmMonitoringResultDto(eu.bcvsolutions.idm.core.monitoring.api.dto.IdmMonitoringResultDto) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)

Example 10 with IdmMonitoringResultFilter

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);
    }
}
Also used : IdmMonitoringDto(eu.bcvsolutions.idm.core.monitoring.api.dto.IdmMonitoringDto) IdmMonitoringResultFilter(eu.bcvsolutions.idm.core.monitoring.api.dto.filter.IdmMonitoringResultFilter) IdmMonitoringResultDto(eu.bcvsolutions.idm.core.monitoring.api.dto.IdmMonitoringResultDto) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)

Aggregations

IdmMonitoringResultFilter (eu.bcvsolutions.idm.core.monitoring.api.dto.filter.IdmMonitoringResultFilter)14 IdmMonitoringDto (eu.bcvsolutions.idm.core.monitoring.api.dto.IdmMonitoringDto)13 IdmMonitoringResultDto (eu.bcvsolutions.idm.core.monitoring.api.dto.IdmMonitoringResultDto)13 Test (org.junit.Test)11 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)7 OperationResultDto (eu.bcvsolutions.idm.core.api.dto.OperationResultDto)4 AbstractReadWriteDtoControllerRestTest (eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoControllerRestTest)4 OperationState (eu.bcvsolutions.idm.core.api.domain.OperationState)3 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)3 AbstractReadWriteDtoController (eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoController)3 ConfigurationService (eu.bcvsolutions.idm.core.api.service.ConfigurationService)3 IdmCacheManager (eu.bcvsolutions.idm.core.api.service.IdmCacheManager)3 AutowireHelper (eu.bcvsolutions.idm.core.api.utils.AutowireHelper)3 IdmIdentity (eu.bcvsolutions.idm.core.model.entity.IdmIdentity)3 IdmMonitoringResultService (eu.bcvsolutions.idm.core.monitoring.api.service.IdmMonitoringResultService)3 IdmMonitoringService (eu.bcvsolutions.idm.core.monitoring.api.service.IdmMonitoringService)3 MonitoringManager (eu.bcvsolutions.idm.core.monitoring.api.service.MonitoringManager)3 H2DatabaseMonitoringEvaluator (eu.bcvsolutions.idm.core.monitoring.service.impl.H2DatabaseMonitoringEvaluator)3 TestMonitoringEvaluator (eu.bcvsolutions.idm.core.monitoring.service.impl.TestMonitoringEvaluator)3 NotificationLevel (eu.bcvsolutions.idm.core.notification.api.domain.NotificationLevel)3