Search in sources :

Example 16 with IdmMonitoringResultDto

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

Example 17 with IdmMonitoringResultDto

use of eu.bcvsolutions.idm.core.monitoring.api.dto.IdmMonitoringResultDto in project CzechIdMng by bcvsolutions.

the class IdmMonitoringResultControllerRestTest method testExecute.

@Test
public void testExecute() throws Exception {
    IdmMonitoringDto monitoring = new IdmMonitoringDto();
    monitoring.setCheckPeriod(0L);
    monitoring.setEvaluatorType(AutowireHelper.getTargetType(h2DatabaseMonitoringEvaluator));
    monitoring.setInstanceId(configurationService.getInstanceId());
    monitoring = monitoringService.save(monitoring);
    // 
    IdmMonitoringResultDto dto = new IdmMonitoringResultDto();
    dto.setMonitoring(monitoring.getId());
    dto.setEvaluatorType(AutowireHelper.getTargetType(h2DatabaseMonitoringEvaluator));
    dto.setInstanceId(configurationService.getInstanceId());
    dto.setResult(new OperationResultDto(OperationState.BLOCKED));
    dto = monitoringResultService.save(dto);
    // 
    String response = getMockMvc().perform(put(String.format("%s/execute", getDetailUrl(dto.getId()))).with(authentication(getAdminAuthentication())).contentType(TestHelper.HAL_CONTENT_TYPE)).andExpect(status().isCreated()).andReturn().getResponse().getContentAsString();
    Assert.assertNotNull(response);
    // 
    getMockMvc().perform(put(String.format("%s/execute", getDetailUrl(UUID.randomUUID()))).with(authentication(getAdminAuthentication())).contentType(TestHelper.HAL_CONTENT_TYPE)).andExpect(status().isNotFound());
}
Also used : IdmMonitoringDto(eu.bcvsolutions.idm.core.monitoring.api.dto.IdmMonitoringDto) OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) 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 18 with IdmMonitoringResultDto

use of eu.bcvsolutions.idm.core.monitoring.api.dto.IdmMonitoringResultDto in project CzechIdMng by bcvsolutions.

the class IdmMonitoringResultControllerRestTest method testFindByLastResult.

@Test
public void testFindByLastResult() {
    String instanceId = getHelper().createName();
    IdmMonitoringResultDto result = prepareDto();
    result.setInstanceId(instanceId);
    result.setLastResult(true);
    IdmMonitoringResultDto resultOne = createDto(result);
    result = prepareDto();
    result.setInstanceId(instanceId);
    // other
    createDto(result);
    // 
    IdmMonitoringResultFilter filter = new IdmMonitoringResultFilter();
    filter.setInstanceId(instanceId);
    filter.setLastResult(true);
    List<IdmMonitoringResultDto> results = find(filter);
    // 
    Assert.assertEquals(1, results.size());
    Assert.assertTrue(results.stream().anyMatch(r -> r.getId().equals(resultOne.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 19 with IdmMonitoringResultDto

use of eu.bcvsolutions.idm.core.monitoring.api.dto.IdmMonitoringResultDto in project CzechIdMng by bcvsolutions.

the class IdmMonitoringResultControllerRestTest method testFindByText.

@Test
public void testFindByText() {
    IdmMonitoringResultDto result = prepareDto();
    IdmMonitoringDto monitoringOne = new IdmMonitoringDto();
    monitoringOne.setEvaluatorType(getHelper().createName());
    monitoringOne.setInstanceId("mock");
    monitoringOne = monitoringService.save(monitoringOne);
    result.setMonitoring(monitoringOne.getId());
    IdmIdentityDto owner = getHelper().createIdentity((GuardedString) null);
    result.setOwnerId(owner.getId());
    result.setOwnerType(IdmIdentity.class.getCanonicalName());
    IdmMonitoringResultDto resultOne = createDto(result);
    // 
    result = prepareDto();
    IdmMonitoringDto monitoringTwo = new IdmMonitoringDto();
    monitoringTwo.setEvaluatorType(TestMonitoringEvaluator.class.getCanonicalName());
    monitoringTwo.setDescription(monitoringOne.getEvaluatorType());
    monitoringTwo.setInstanceId("mock");
    monitoringTwo = monitoringService.save(monitoringTwo);
    result.setMonitoring(monitoringTwo.getId());
    result.setEvaluatorType(TestMonitoringEvaluator.class.getCanonicalName());
    IdmMonitoringResultDto resultTwo = createDto(result);
    // 
    // other
    createDto();
    // 
    IdmMonitoringResultFilter filter = new IdmMonitoringResultFilter();
    filter.setText(monitoringOne.getEvaluatorType());
    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) IdmMonitoringDto(eu.bcvsolutions.idm.core.monitoring.api.dto.IdmMonitoringDto) TestMonitoringEvaluator(eu.bcvsolutions.idm.core.monitoring.service.impl.TestMonitoringEvaluator) IdmMonitoringResultFilter(eu.bcvsolutions.idm.core.monitoring.api.dto.filter.IdmMonitoringResultFilter) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) IdmMonitoringResultDto(eu.bcvsolutions.idm.core.monitoring.api.dto.IdmMonitoringResultDto) AbstractReadWriteDtoControllerRestTest(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoControllerRestTest) Test(org.junit.Test)

Example 20 with IdmMonitoringResultDto

use of eu.bcvsolutions.idm.core.monitoring.api.dto.IdmMonitoringResultDto 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)

Aggregations

IdmMonitoringResultDto (eu.bcvsolutions.idm.core.monitoring.api.dto.IdmMonitoringResultDto)63 IdmMonitoringDto (eu.bcvsolutions.idm.core.monitoring.api.dto.IdmMonitoringDto)47 Test (org.junit.Test)39 AbstractUnitTest (eu.bcvsolutions.idm.test.api.AbstractUnitTest)21 OperationResultDto (eu.bcvsolutions.idm.core.api.dto.OperationResultDto)18 IdmMonitoringResultFilter (eu.bcvsolutions.idm.core.monitoring.api.dto.filter.IdmMonitoringResultFilter)13 UUID (java.util.UUID)13 ResultModel (eu.bcvsolutions.idm.core.api.dto.ResultModel)12 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)12 DefaultResultModel (eu.bcvsolutions.idm.core.api.dto.DefaultResultModel)10 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)7 SysSchemaObjectClassDto (eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto)6 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)6 SysSystemMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto)6 SysSyncConfigFilter (eu.bcvsolutions.idm.acc.dto.filter.SysSyncConfigFilter)6 SysSyncConfigDto (eu.bcvsolutions.idm.acc.dto.SysSyncConfigDto)5 AbstractReadWriteDtoControllerRestTest (eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoControllerRestTest)5 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)5 SysSyncActionLogDto (eu.bcvsolutions.idm.acc.dto.SysSyncActionLogDto)4 SysSyncLogDto (eu.bcvsolutions.idm.acc.dto.SysSyncLogDto)4