use of eu.bcvsolutions.idm.core.model.entity.IdmRole_ in project CzechIdMng by bcvsolutions.
the class DefaultIdmRoleServiceIntegrationTest method testCorrelableFilter.
/**
* Test find role by all string fields
*/
@Test
public void testCorrelableFilter() {
IdmRoleDto role = getHelper().createRole();
role.setExternalId(getHelper().createName());
role.setCode(getHelper().createName());
role.setDescription(getHelper().createName());
IdmRoleDto roleFull = roleService.save(role);
ArrayList<Field> fields = Lists.newArrayList(IdmRole_.class.getFields());
IdmRoleFilter filter = new IdmRoleFilter();
fields.forEach(field -> {
if (Modifier.isStatic(field.getModifiers())) {
// static filter properties cannot be used by simple correlable filter
} else {
filter.setProperty(field.getName());
try {
Object value = EntityUtils.getEntityValue(roleFull, field.getName());
if (value == null || !(value instanceof String)) {
return;
}
filter.setValue(value.toString());
List<IdmRoleDto> identities = roleService.find(filter, null).getContent();
Assert.assertTrue(identities.contains(roleFull));
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | IntrospectionException e) {
e.printStackTrace();
}
}
});
}
use of eu.bcvsolutions.idm.core.model.entity.IdmRole_ in project CzechIdMng by bcvsolutions.
the class DefaultRoleSynchronizationServiceTest method doStartSyncC_filterByToken.
@Test
public void doStartSyncC_filterByToken() {
SysSyncConfigFilter configFilter = new SysSyncConfigFilter();
configFilter.setName(SYNC_CONFIG_NAME);
List<AbstractSysSyncConfigDto> syncConfigs = syncConfigService.find(configFilter, null).getContent();
Assert.assertEquals(1, syncConfigs.size());
AbstractSysSyncConfigDto syncConfigCustom = syncConfigs.get(0);
Assert.assertFalse(syncConfigService.isRunning(syncConfigCustom));
IdmRoleFilter roleFilter = new IdmRoleFilter();
roleFilter.setProperty(IdmRole_.code.getName());
roleFilter.setValue("3");
IdmRoleDto roleThree = roleService.find(roleFilter, null).getContent().get(0);
Assert.assertNotNull(roleThree);
IdmFormValueDto changedRole = (IdmFormValueDto) formService.getValues(roleThree.getId(), IdmRole.class, "changed").get(0);
Assert.assertNotNull(changedRole);
// Set sync config
syncConfigCustom.setReconciliation(false);
syncConfigCustom.setCustomFilter(true);
syncConfigCustom.setFilterOperation(IcFilterOperationType.GREATER_THAN);
syncConfigCustom.setFilterAttribute(syncConfigCustom.getTokenAttribute());
syncConfigCustom.setToken((String) changedRole.getValue());
syncConfigCustom.setLinkedAction(SynchronizationLinkedActionType.UPDATE_ENTITY);
syncConfigCustom.setUnlinkedAction(SynchronizationUnlinkedActionType.IGNORE);
syncConfigCustom.setMissingEntityAction(SynchronizationMissingEntityActionType.IGNORE);
syncConfigCustom.setMissingAccountAction(ReconciliationMissingAccountActionType.IGNORE);
syncConfigService.save(syncConfigCustom);
//
helper.startSynchronization(syncConfigCustom);
//
SysSyncLogFilter logFilter = new SysSyncLogFilter();
logFilter.setSynchronizationConfigId(syncConfigCustom.getId());
List<SysSyncLogDto> logs = syncLogService.find(logFilter, null).getContent();
Assert.assertEquals(1, logs.size());
SysSyncLogDto log = logs.get(0);
Assert.assertFalse(log.isRunning());
Assert.assertFalse(log.isContainsError());
SysSyncActionLogFilter actionLogFilter = new SysSyncActionLogFilter();
actionLogFilter.setSynchronizationLogId(log.getId());
List<SysSyncActionLogDto> actions = syncActionLogService.find(actionLogFilter, null).getContent();
Assert.assertEquals(1, actions.size());
SysSyncActionLogDto createEntityActionLog = actions.stream().filter(action -> {
return SynchronizationActionType.UPDATE_ENTITY == action.getSyncAction();
}).findFirst().get();
SysSyncItemLogFilter itemLogFilter = new SysSyncItemLogFilter();
itemLogFilter.setSyncActionLogId(createEntityActionLog.getId());
List<SysSyncItemLogDto> items = syncItemLogService.find(itemLogFilter, null).getContent();
Assert.assertEquals(2, items.size());
SysSyncItemLogDto item = items.stream().filter(logitem -> {
return "4".equals(logitem.getIdentification());
}).findFirst().orElse(null);
Assert.assertNotNull("Log for role 4 must exist!", item);
item = items.stream().filter(logitem -> {
return "5".equals(logitem.getIdentification());
}).findFirst().orElse(null);
Assert.assertNotNull("Log for role 5 must exist!", item);
// Delete log
syncLogService.delete(log);
}
Aggregations