DefaultSynchronizationService implements SynchronizationService { @Override public AbstractSysSyncConfigDto startSynchronization(AbstractSysSyncConfigDto config) { Assert.notNull(config, "Configuration is required."); Assert.notNull(config.getId(), "Id of sync config is required!"); SynchronizationSchedulableTaskExecutor lrt = new SynchronizationSchedulableTaskExecutor(config.getId()); longRunningTaskManager.execute(lrt); return config; } @Autowired  DefaultSynchronizationService(SysSystemAttributeMappingService attributeHandlingService,
			SysSyncConfigService synchronizationConfigService, SysSyncLogService synchronizationLogService,
			AccAccountService accountService, SysSystemEntityService systemEntityService, LongRunningTaskManager longRunningTaskManager,
			List<SynchronizationEntityExecutor> executors, SysSystemMappingService systemMappingService,
			SysSystemService systemService, SysSchemaObjectClassService schemaObjectClassService); @Override @Transactional void init(); @Override AbstractSysSyncConfigDto startSynchronization(AbstractSysSyncConfigDto config); @Override void startSynchronization(AbstractSysSyncConfigDto config,
			AbstractSchedulableTaskExecutor<Boolean> longRunningTaskExecutor); @Override AbstractSysSyncConfigDto stopSynchronization(AbstractSysSyncConfigDto config); @Override @Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class) boolean doItemSynchronization(SynchronizationContext context); @Override SysSyncItemLogDto resolveMissingEntitySituation(String uid, SystemEntityType entityType,
			List<IcAttribute> icAttributes, UUID configId, String actionType); @Override SysSyncItemLogDto resolveLinkedSituation(String uid, SystemEntityType entityType,
			List<IcAttribute> icAttributes, UUID accountId, UUID configId, String actionType); @Override SysSyncItemLogDto resolveUnlinkedSituation(String uid, SystemEntityType entityType, UUID entityId,
			UUID configId, String actionType, List<IcAttribute> icAttributes); @Override SysSyncItemLogDto resolveMissingAccountSituation(String uid, SystemEntityType entityType, UUID accountId,
			UUID configId, String actionType); @Override SynchronizationEntityExecutor getSyncExecutor(SystemEntityType entityType, UUID syncConfigId);  }
@Test public void doStartSyncB_Linked_doUnLinked() { 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)); syncConfigCustom.setLinkedAction(SynchronizationLinkedActionType.UNLINK); syncConfigCustom.setUnlinkedAction(SynchronizationUnlinkedActionType.IGNORE); syncConfigCustom.setMissingEntityAction(SynchronizationMissingEntityActionType.IGNORE); syncConfigCustom.setMissingAccountAction(ReconciliationMissingAccountActionType.IGNORE); syncConfigCustom.setReconciliation(true); syncConfigService.save(syncConfigCustom); AccIdentityAccountFilter identityAccountFilterOne = new AccIdentityAccountFilter(); identityAccountFilterOne.setIdentityId(identityService.getByUsername("x" + IDENTITY_USERNAME_ONE).getId()); Assert.assertEquals(1, identityAccoutnService.find(identityAccountFilterOne, null).getTotalElements()); AccIdentityAccountFilter identityAccountFilterTwo = new AccIdentityAccountFilter(); identityAccountFilterTwo.setIdentityId(identityService.getByUsername("x" + IDENTITY_USERNAME_ONE).getId()); Assert.assertEquals(1, identityAccoutnService.find(identityAccountFilterTwo, null).getTotalElements()); 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 actionLog = actions.stream().filter(action -> { return SynchronizationActionType.UNLINK == action.getSyncAction(); }).findFirst().get(); SysSyncItemLogFilter itemLogFilter = new SysSyncItemLogFilter(); itemLogFilter.setSyncActionLogId(actionLog.getId()); List<SysSyncItemLogDto> items = syncItemLogService.find(itemLogFilter, null).getContent(); Assert.assertEquals(2, items.size()); Assert.assertEquals(0, identityAccoutnService.find(identityAccountFilterOne, null).getTotalElements()); Assert.assertEquals(0, identityAccoutnService.find(identityAccountFilterTwo, null).getTotalElements()); syncLogService.delete(log); }
@Test public void doStartSyncC_Unlinked_doLink() { 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)); syncConfigCustom.setLinkedAction(SynchronizationLinkedActionType.IGNORE); syncConfigCustom.setUnlinkedAction(SynchronizationUnlinkedActionType.LINK); syncConfigCustom.setMissingEntityAction(SynchronizationMissingEntityActionType.IGNORE); syncConfigCustom.setMissingAccountAction(ReconciliationMissingAccountActionType.IGNORE); syncConfigCustom.setReconciliation(true); syncConfigService.save(syncConfigCustom); IdmIdentityDto identityOne = identityService.getByUsername("x" + IDENTITY_USERNAME_ONE); IdmIdentityDto identityTwo = identityService.getByUsername("x" + IDENTITY_USERNAME_TWO); AccIdentityAccountFilter identityAccountFilterOne = new AccIdentityAccountFilter(); identityAccountFilterOne.setIdentityId(identityOne.getId()); Assert.assertEquals(0, identityAccoutnService.find(identityAccountFilterOne, null).getTotalElements()); AccIdentityAccountFilter identityAccountFilterTwo = new AccIdentityAccountFilter(); identityAccountFilterTwo.setIdentityId(identityTwo.getId()); Assert.assertEquals(0, identityAccoutnService.find(identityAccountFilterTwo, null).getTotalElements()); 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 actionLog = actions.stream().filter(action -> { return SynchronizationActionType.LINK == action.getSyncAction(); }).findFirst().get(); SysSyncItemLogFilter itemLogFilter = new SysSyncItemLogFilter(); itemLogFilter.setSyncActionLogId(actionLog.getId()); List<SysSyncItemLogDto> items = syncItemLogService.find(itemLogFilter, null).getContent(); Assert.assertEquals(2, items.size()); Assert.assertEquals(1, identityAccoutnService.find(identityAccountFilterOne, null).getTotalElements()); Assert.assertEquals(1, identityAccoutnService.find(identityAccountFilterTwo, null).getTotalElements()); syncLogService.delete(log); }
@Test public void doStartSyncC_Unlinked_doLinkAndUpdateAccount() { this.doStartSyncB_Linked_doUnLinked(); 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)); syncConfigCustom.setLinkedAction(SynchronizationLinkedActionType.IGNORE); syncConfigCustom.setUnlinkedAction(SynchronizationUnlinkedActionType.LINK_AND_UPDATE_ACCOUNT); syncConfigCustom.setMissingEntityAction(SynchronizationMissingEntityActionType.IGNORE); syncConfigCustom.setMissingAccountAction(ReconciliationMissingAccountActionType.IGNORE); syncConfigCustom.setReconciliation(true); syncConfigService.save(syncConfigCustom); IdmIdentityDto identityOne = identityService.getByUsername("x" + IDENTITY_USERNAME_ONE); IdmIdentityDto identityTwo = identityService.getByUsername("x" + IDENTITY_USERNAME_TWO); identityOne.setFirstName(IDENTITY_USERNAME_ONE); identityTwo.setLastName(IDENTITY_USERNAME_TWO); identityService.save(identityOne); identityService.save(identityTwo); getBean().changeResourceData(); AccIdentityAccountFilter identityAccountFilterOne = new AccIdentityAccountFilter(); identityAccountFilterOne.setIdentityId(identityOne.getId()); Assert.assertEquals(0, identityAccoutnService.find(identityAccountFilterOne, null).getTotalElements()); AccIdentityAccountFilter identityAccountFilterTwo = new AccIdentityAccountFilter(); identityAccountFilterTwo.setIdentityId(identityTwo.getId()); Assert.assertEquals(0, identityAccoutnService.find(identityAccountFilterTwo, null).getTotalElements()); Assert.assertEquals(IDENTITY_USERNAME_ONE, identityOne.getFirstName()); Assert.assertEquals(IDENTITY_USERNAME_TWO, identityTwo.getLastName()); Assert.assertNotEquals(IDENTITY_USERNAME_ONE, entityManager.find(TestResource.class, "x" + IDENTITY_USERNAME_ONE).getFirstname()); Assert.assertNotEquals(IDENTITY_USERNAME_TWO, entityManager.find(TestResource.class, "x" + IDENTITY_USERNAME_TWO).getLastname()); 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 actionLog = actions.stream().filter(action -> { return SynchronizationActionType.LINK_AND_UPDATE_ACCOUNT == action.getSyncAction(); }).findFirst().get(); SysSyncItemLogFilter itemLogFilter = new SysSyncItemLogFilter(); itemLogFilter.setSyncActionLogId(actionLog.getId()); List<SysSyncItemLogDto> items = syncItemLogService.find(itemLogFilter, null).getContent(); Assert.assertEquals(2, items.size()); Assert.assertEquals(IDENTITY_USERNAME_ONE, entityManager.find(TestResource.class, "x" + IDENTITY_USERNAME_ONE).getFirstname()); Assert.assertEquals(IDENTITY_USERNAME_TWO, entityManager.find(TestResource.class, "x" + IDENTITY_USERNAME_TWO).getLastname()); syncLogService.delete(log); }
@Test public void doStartSyncD_Missing_Account_doCreateAccount() { 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)); IdmIdentityDto identity = new IdmIdentityDto(); identity.setUsername("x" + IDENTITY_USERNAME_THREE); identity.setFirstName(IDENTITY_USERNAME_THREE); identity.setLastName(IDENTITY_USERNAME_THREE); identity = identityService.save(identity); AccAccountDto accountOne = new AccAccountDto(); SysSystemMappingDto systemMapping = systemMappingService.get(syncConfigCustom.getSystemMapping()); SysSystemDto system = systemService.get(schemaObjectClassService.get(systemMapping.getObjectClass()).getSystem()); accountOne.setSystem(system.getId()); accountOne.setUid("x" + IDENTITY_USERNAME_THREE); accountOne.setAccountType(AccountType.PERSONAL); accountOne.setEntityType(SystemEntityType.IDENTITY); accountOne = accountService.save(accountOne); AccIdentityAccountDto accountIdentityOne = new AccIdentityAccountDto(); accountIdentityOne.setIdentity(identity.getId()); accountIdentityOne.setOwnership(true); accountIdentityOne.setAccount(accountOne.getId()); accountIdentityOne = identityAccoutnService.save(accountIdentityOne); syncConfigCustom.setLinkedAction(SynchronizationLinkedActionType.IGNORE); syncConfigCustom.setUnlinkedAction(SynchronizationUnlinkedActionType.IGNORE); syncConfigCustom.setMissingEntityAction(SynchronizationMissingEntityActionType.IGNORE); syncConfigCustom.setMissingAccountAction(ReconciliationMissingAccountActionType.CREATE_ACCOUNT); syncConfigCustom.setReconciliation(true); syncConfigService.save(syncConfigCustom); Assert.assertNull(entityManager.find(TestResource.class, "x" + IDENTITY_USERNAME_THREE)); 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(2, actions.size()); SysSyncActionLogDto actionLog = actions.stream().filter(action -> { return SynchronizationActionType.CREATE_ACCOUNT == action.getSyncAction(); }).findFirst().get(); SysSyncItemLogFilter itemLogFilter = new SysSyncItemLogFilter(); itemLogFilter.setSyncActionLogId(actionLog.getId()); List<SysSyncItemLogDto> items = syncItemLogService.find(itemLogFilter, null).getContent(); Assert.assertEquals(1, items.size()); Assert.assertNotNull(entityManager.find(TestResource.class, "x" + IDENTITY_USERNAME_THREE)); syncLogService.delete(log); }
@Test public void doStartSyncD_Missing_Account_doDeleteEntity() { 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)); this.getBean().deleteAllResourceData(); syncConfigCustom.setLinkedAction(SynchronizationLinkedActionType.IGNORE); syncConfigCustom.setUnlinkedAction(SynchronizationUnlinkedActionType.IGNORE); syncConfigCustom.setMissingEntityAction(SynchronizationMissingEntityActionType.IGNORE); syncConfigCustom.setMissingAccountAction(ReconciliationMissingAccountActionType.DELETE_ENTITY); syncConfigCustom.setReconciliation(true); syncConfigService.save(syncConfigCustom); Assert.assertNotNull(identityService.getByUsername("x" + IDENTITY_USERNAME_ONE)); Assert.assertNotNull(identityService.getByUsername("x" + IDENTITY_USERNAME_TWO)); Assert.assertNotNull(identityService.getByUsername("x" + IDENTITY_USERNAME_THREE)); 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 actionLog = actions.stream().filter(action -> { return SynchronizationActionType.DELETE_ENTITY == action.getSyncAction(); }).findFirst().get(); SysSyncItemLogFilter itemLogFilter = new SysSyncItemLogFilter(); itemLogFilter.setSyncActionLogId(actionLog.getId()); List<SysSyncItemLogDto> items = syncItemLogService.find(itemLogFilter, null).getContent(); Assert.assertEquals(3, items.size()); Assert.assertNull(identityService.getByUsername("x" + IDENTITY_USERNAME_ONE)); Assert.assertNull(identityService.getByUsername("x" + IDENTITY_USERNAME_TWO)); Assert.assertNull(identityService.getByUsername("x" + IDENTITY_USERNAME_THREE)); syncLogService.delete(log); }
@Test public void doStartSyncE_StrategyCreate() { 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)); this.getBean().deleteAllResourceData(); this.getBean().initResourceData(); SysSystemMappingFilter mappingFilter = new SysSystemMappingFilter(); mappingFilter.setEntityType(SystemEntityType.IDENTITY); SysSystemMappingDto systemMapping = systemMappingService.get(syncConfigCustom.getSystemMapping()); SysSystemDto system = systemService.get(schemaObjectClassService.get(systemMapping.getObjectClass()).getSystem()); mappingFilter.setSystemId(system.getId()); mappingFilter.setOperationType(SystemOperationType.SYNCHRONIZATION); List<SysSystemMappingDto> mappings = systemMappingService.find(mappingFilter, null).getContent(); Assert.assertEquals(1, mappings.size()); SysSystemMappingDto mapping = mappings.get(0); SysSystemAttributeMappingFilter attributeMappingFilter = new SysSystemAttributeMappingFilter(); attributeMappingFilter.setSystemMappingId(mapping.getId()); List<SysSystemAttributeMappingDto> attributes = schemaAttributeMappingService.find(attributeMappingFilter, null) .getContent(); SysSystemAttributeMappingDto emailAttribute = attributes.stream().filter(attribute -> { return attribute.getName().equalsIgnoreCase(ATTRIBUTE_EMAIL); }).findFirst().get(); emailAttribute.setStrategyType(AttributeMappingStrategyType.CREATE); schemaAttributeMappingService.save(emailAttribute); syncConfigCustom.setLinkedAction(SynchronizationLinkedActionType.UPDATE_ENTITY); syncConfigCustom.setUnlinkedAction(SynchronizationUnlinkedActionType.IGNORE); syncConfigCustom.setMissingEntityAction(SynchronizationMissingEntityActionType.CREATE_ENTITY); syncConfigCustom.setMissingAccountAction(ReconciliationMissingAccountActionType.IGNORE); syncConfigCustom.setReconciliation(true); syncConfigService.save(syncConfigCustom); Assert.assertNull(identityService.getByUsername("x" + IDENTITY_USERNAME_ONE)); Assert.assertNull(identityService.getByUsername("x" + IDENTITY_USERNAME_TWO)); 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 actionLog = actions.stream().filter(action -> { return SynchronizationActionType.CREATE_ENTITY == action.getSyncAction(); }).findFirst().get(); SysSyncItemLogFilter itemLogFilter = new SysSyncItemLogFilter(); itemLogFilter.setSyncActionLogId(actionLog.getId()); List<SysSyncItemLogDto> items = syncItemLogService.find(itemLogFilter, null).getContent(); Assert.assertEquals(2, items.size()); Assert.assertEquals(IDENTITY_USERNAME_ONE, identityService.getByUsername("x" + IDENTITY_USERNAME_ONE).getFirstName()); Assert.assertEquals(IDENTITY_USERNAME_TWO, identityService.getByUsername("x" + IDENTITY_USERNAME_TWO).getLastName()); Assert.assertEquals(IDENTITY_EMAIL_CORRECT, identityService.getByUsername("x" + IDENTITY_USERNAME_ONE).getEmail()); Assert.assertEquals(IDENTITY_EMAIL_CORRECT, identityService.getByUsername("x" + IDENTITY_USERNAME_TWO).getEmail()); syncLogService.delete(log); this.getBean().changeResourceData(); helper.startSynchronization(syncConfigCustom); logFilter = new SysSyncLogFilter(); logFilter.setSynchronizationConfigId(syncConfigCustom.getId()); logs = syncLogService.find(logFilter, null).getContent(); Assert.assertEquals(1, logs.size()); log = logs.get(0); Assert.assertFalse(log.isRunning()); Assert.assertFalse(log.isContainsError()); actionLogFilter = new SysSyncActionLogFilter(); actionLogFilter.setSynchronizationLogId(log.getId()); actions = syncActionLogService.find(actionLogFilter, null).getContent(); Assert.assertEquals(1, actions.size()); actionLog = actions.stream().filter(action -> { return SynchronizationActionType.UPDATE_ENTITY == action.getSyncAction(); }).findFirst().get(); itemLogFilter = new SysSyncItemLogFilter(); itemLogFilter.setSyncActionLogId(actionLog.getId()); items = syncItemLogService.find(itemLogFilter, null).getContent(); Assert.assertEquals(2, items.size()); Assert.assertEquals(ATTRIBUTE_VALUE_CHANGED, identityService.getByUsername("x" + IDENTITY_USERNAME_ONE).getFirstName()); Assert.assertEquals(ATTRIBUTE_VALUE_CHANGED, identityService.getByUsername("x" + IDENTITY_USERNAME_TWO).getLastName()); Assert.assertEquals(IDENTITY_EMAIL_CORRECT, identityService.getByUsername("x" + IDENTITY_USERNAME_ONE).getEmail()); Assert.assertEquals(IDENTITY_EMAIL_CORRECT, identityService.getByUsername("x" + IDENTITY_USERNAME_TWO).getEmail()); syncLogService.delete(log); }
@Test public void doStartSyncE_StrategyWriteIfNull() { 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)); SysSystemMappingFilter mappingFilter = new SysSystemMappingFilter(); mappingFilter.setEntityType(SystemEntityType.IDENTITY); SysSystemMappingDto systemMapping = systemMappingService.get(syncConfigCustom.getSystemMapping()); SysSystemDto system = systemService.get(schemaObjectClassService.get(systemMapping.getObjectClass()).getSystem()); mappingFilter.setSystemId(system.getId()); mappingFilter.setOperationType(SystemOperationType.SYNCHRONIZATION); List<SysSystemMappingDto> mappings = systemMappingService.find(mappingFilter, null).getContent(); Assert.assertEquals(1, mappings.size()); SysSystemMappingDto mapping = mappings.get(0); SysSystemAttributeMappingFilter attributeMappingFilter = new SysSystemAttributeMappingFilter(); attributeMappingFilter.setSystemMappingId(mapping.getId()); List<SysSystemAttributeMappingDto> attributes = schemaAttributeMappingService.find(attributeMappingFilter, null) .getContent(); SysSystemAttributeMappingDto emailAttribute = attributes.stream().filter(attribute -> { return attribute.getName().equalsIgnoreCase(ATTRIBUTE_EMAIL); }).findFirst().get(); emailAttribute.setStrategyType(AttributeMappingStrategyType.WRITE_IF_NULL); schemaAttributeMappingService.save(emailAttribute); IdmIdentityDto one = identityService.getByUsername("x" + IDENTITY_USERNAME_ONE); one.setEmail(null); identityService.save(one); this.getBean().deleteAllResourceData(); this.getBean().initResourceData(); this.getBean().changeResourceData(); syncConfigCustom.setLinkedAction(SynchronizationLinkedActionType.UPDATE_ENTITY); syncConfigCustom.setUnlinkedAction(SynchronizationUnlinkedActionType.IGNORE); syncConfigCustom.setMissingEntityAction(SynchronizationMissingEntityActionType.CREATE_ENTITY); syncConfigCustom.setMissingAccountAction(ReconciliationMissingAccountActionType.IGNORE); syncConfigCustom.setReconciliation(true); syncConfigService.save(syncConfigCustom); Assert.assertEquals(null, identityService.getByUsername("x" + IDENTITY_USERNAME_ONE).getEmail()); Assert.assertEquals(IDENTITY_EMAIL_CORRECT, identityService.getByUsername("x" + IDENTITY_USERNAME_TWO).getEmail()); 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 actionLog = actions.stream().filter(action -> { return SynchronizationActionType.UPDATE_ENTITY == action.getSyncAction(); }).findFirst().get(); SysSyncItemLogFilter itemLogFilter = new SysSyncItemLogFilter(); itemLogFilter.setSyncActionLogId(actionLog.getId()); List<SysSyncItemLogDto> items = syncItemLogService.find(itemLogFilter, null).getContent(); Assert.assertEquals(2, items.size()); Assert.assertEquals(IDENTITY_EMAIL_CORRECT_CHANGED, identityService.getByUsername("x" + IDENTITY_USERNAME_ONE).getEmail()); Assert.assertEquals(IDENTITY_EMAIL_CORRECT, identityService.getByUsername("x" + IDENTITY_USERNAME_TWO).getEmail()); syncLogService.delete(log); }
@Test public void doStartSyncE_StrategyWriteIfNull_EAV() { 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)); SysSystemMappingFilter mappingFilter = new SysSystemMappingFilter(); mappingFilter.setEntityType(SystemEntityType.IDENTITY); SysSystemMappingDto systemMapping = systemMappingService.get(syncConfigCustom.getSystemMapping()); SysSystemDto system = systemService.get(schemaObjectClassService.get(systemMapping.getObjectClass()).getSystem()); mappingFilter.setSystemId(system.getId()); mappingFilter.setOperationType(SystemOperationType.SYNCHRONIZATION); List<SysSystemMappingDto> mappings = systemMappingService.find(mappingFilter, null).getContent(); Assert.assertEquals(1, mappings.size()); SysSystemMappingDto mapping = mappings.get(0); SysSystemAttributeMappingFilter attributeMappingFilter = new SysSystemAttributeMappingFilter(); attributeMappingFilter.setSystemMappingId(mapping.getId()); List<SysSystemAttributeMappingDto> attributes = schemaAttributeMappingService.find(attributeMappingFilter, null) .getContent(); SysSystemAttributeMappingDto eavAttribute = attributes.stream().filter(attribute -> { return attribute.getName().equalsIgnoreCase(EAV_ATTRIBUTE); }).findFirst().get(); eavAttribute.setStrategyType(AttributeMappingStrategyType.WRITE_IF_NULL); schemaAttributeMappingService.save(eavAttribute); IdmIdentityDto one = identityService.getByUsername("x" + IDENTITY_USERNAME_ONE); formService.saveValues(one.getId(), IdmIdentity.class, eavAttribute.getIdmPropertyName(), null); IdmIdentityDto two = identityService.getByUsername("x" + IDENTITY_USERNAME_TWO); formService.saveValues(two.getId(), IdmIdentity.class, eavAttribute.getIdmPropertyName(), ImmutableList.of(ATTRIBUTE_EMAIL)); this.getBean().deleteAllResourceData(); this.getBean().initResourceData(); this.getBean().changeResourceData(); syncConfigCustom.setLinkedAction(SynchronizationLinkedActionType.UPDATE_ENTITY); syncConfigCustom.setUnlinkedAction(SynchronizationUnlinkedActionType.IGNORE); syncConfigCustom.setMissingEntityAction(SynchronizationMissingEntityActionType.CREATE_ENTITY); syncConfigCustom.setMissingAccountAction(ReconciliationMissingAccountActionType.IGNORE); syncConfigCustom.setReconciliation(true); 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 actionLog = actions.stream().filter(action -> { return SynchronizationActionType.UPDATE_ENTITY == action.getSyncAction(); }).findFirst().get(); SysSyncItemLogFilter itemLogFilter = new SysSyncItemLogFilter(); itemLogFilter.setSyncActionLogId(actionLog.getId()); List<SysSyncItemLogDto> items = syncItemLogService.find(itemLogFilter, null).getContent(); Assert.assertEquals(2, items.size()); one = identityService.getByUsername("x" + IDENTITY_USERNAME_ONE); Assert.assertEquals(ATTRIBUTE_VALUE_CHANGED, formService.getValues(one.getId(), IdmIdentity.class, eavAttribute.getIdmPropertyName()).get(0).getValue()); two = identityService.getByUsername("x" + IDENTITY_USERNAME_TWO); Assert.assertEquals(ATTRIBUTE_EMAIL, formService.getValues(two.getId(), IdmIdentity.class, eavAttribute.getIdmPropertyName()).get(0).getValue()); eavAttribute.setStrategyType(AttributeMappingStrategyType.SET); schemaAttributeMappingService.save(eavAttribute); formService.saveValues(one.getId(), IdmIdentity.class, eavAttribute.getIdmPropertyName(), ImmutableList.of("1")); formService.saveValues(two.getId(), IdmIdentity.class, eavAttribute.getIdmPropertyName(), ImmutableList.of("2")); syncLogService.delete(log); }
@Test public void doStartSyncF_Unlinked_doLinkByEavAttribute() { this.getBean().deleteAllResourceData(); this.getBean().initResourceData(); this.doStartSyncB_Linked_doUnLinked(); AbstractSysSyncConfigDto syncConfigCustom = setSyncConfigForEav(SYNC_CONFIG_NAME); IdmIdentityDto identityOne = identityService.getByUsername("x" + IDENTITY_USERNAME_ONE); IdmIdentityDto identityTwo = identityService.getByUsername("x" + IDENTITY_USERNAME_TWO); AccIdentityAccountFilter identityAccountFilterOne = new AccIdentityAccountFilter(); identityAccountFilterOne.setIdentityId(identityOne.getId()); Assert.assertEquals(0, identityAccoutnService.find(identityAccountFilterOne, null).getTotalElements()); AccIdentityAccountFilter identityAccountFilterTwo = new AccIdentityAccountFilter(); identityAccountFilterTwo.setIdentityId(identityTwo.getId()); Assert.assertEquals(0, identityAccoutnService.find(identityAccountFilterTwo, null).getTotalElements()); 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 actionLog = actions.stream().filter(action -> { return SynchronizationActionType.LINK == action.getSyncAction(); }).findFirst().get(); SysSyncItemLogFilter itemLogFilter = new SysSyncItemLogFilter(); itemLogFilter.setSyncActionLogId(actionLog.getId()); List<SysSyncItemLogDto> items = syncItemLogService.find(itemLogFilter, null).getContent(); Assert.assertEquals(2, items.size()); Assert.assertEquals(1, identityAccoutnService.find(identityAccountFilterOne, null).getTotalElements()); Assert.assertEquals(1, identityAccoutnService.find(identityAccountFilterTwo, null).getTotalElements()); syncLogService.delete(log); }
@Test public void doStartSyncF_Unlinked_doLinkByEavAttribute_ChangeValue() { this.doStartSyncB_Linked_doUnLinked(); AbstractSysSyncConfigDto syncConfigCustom = setSyncConfigForEav(SYNC_CONFIG_NAME); Assert.assertFalse(syncConfigService.isRunning(syncConfigCustom)); IdmIdentityDto identityOne = identityService.getByUsername("x" + IDENTITY_USERNAME_ONE); IdmIdentityDto identityTwo = identityService.getByUsername("x" + IDENTITY_USERNAME_TWO); AccIdentityAccountFilter identityAccountFilterOne = new AccIdentityAccountFilter(); identityAccountFilterOne.setIdentityId(identityOne.getId()); Assert.assertEquals(0, identityAccoutnService.find(identityAccountFilterOne, null).getTotalElements()); AccIdentityAccountFilter identityAccountFilterTwo = new AccIdentityAccountFilter(); identityAccountFilterTwo.setIdentityId(identityTwo.getId()); Assert.assertEquals(0, identityAccoutnService.find(identityAccountFilterTwo, null).getTotalElements()); List<Serializable> list = new ArrayList<>(); list.add("5"); formService.saveValues(identityOne.getId(), IdmIdentity.class, EAV_ATTRIBUTE, list); 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(2, actions.size()); SysSyncActionLogDto actionLog = actions.stream().filter(action -> { return SynchronizationActionType.MISSING_ENTITY == action.getSyncAction(); }).findFirst().get(); SysSyncItemLogFilter itemLogFilter = new SysSyncItemLogFilter(); itemLogFilter.setSyncActionLogId(actionLog.getId()); List<SysSyncItemLogDto> items = syncItemLogService.find(itemLogFilter, null).getContent(); Assert.assertEquals(1, items.size()); Assert.assertEquals(0, identityAccoutnService.find(identityAccountFilterOne, null).getTotalElements()); Assert.assertEquals(1, identityAccoutnService.find(identityAccountFilterTwo, null).getTotalElements()); syncLogService.delete(log); }
@Test public void doStartSyncA_MissingEntity() { 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)); 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.CREATE_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()); syncLogService.delete(log); }
@Test public void doStartSyncB_Linked_doEntityUpdate() { SysSyncConfigFilter configFilter = new SysSyncConfigFilter(); configFilter.setName(SYNC_CONFIG_NAME); List<AbstractSysSyncConfigDto> syncConfigs = syncConfigService.find(configFilter, null).getContent(); this.getBean().changeResourceData(); Assert.assertEquals(1, syncConfigs.size()); AbstractSysSyncConfigDto syncConfigCustom = syncConfigs.get(0); Assert.assertFalse(syncConfigService.isRunning(syncConfigCustom)); syncConfigCustom.setLinkedAction(SynchronizationLinkedActionType.UPDATE_ENTITY); syncConfigCustom.setUnlinkedAction(SynchronizationUnlinkedActionType.IGNORE); syncConfigCustom.setMissingEntityAction(SynchronizationMissingEntityActionType.IGNORE); syncConfigCustom.setMissingAccountAction(ReconciliationMissingAccountActionType.IGNORE); syncConfigService.save(syncConfigCustom); Assert.assertEquals(IDENTITY_USERNAME_ONE, identityService.getByUsername("x" + IDENTITY_USERNAME_ONE).getFirstName()); Assert.assertEquals(IDENTITY_USERNAME_TWO, identityService.getByUsername("x" + IDENTITY_USERNAME_TWO).getLastName()); 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 actionLog = actions.stream().filter(action -> { return SynchronizationActionType.UPDATE_ENTITY == action.getSyncAction(); }).findFirst().get(); SysSyncItemLogFilter itemLogFilter = new SysSyncItemLogFilter(); itemLogFilter.setSyncActionLogId(actionLog.getId()); List<SysSyncItemLogDto> items = syncItemLogService.find(itemLogFilter, null).getContent(); Assert.assertEquals(2, items.size()); Assert.assertEquals(ATTRIBUTE_VALUE_CHANGED, identityService.getByUsername("x" + IDENTITY_USERNAME_ONE).getFirstName()); Assert.assertEquals(ATTRIBUTE_VALUE_CHANGED, identityService.getByUsername("x" + IDENTITY_USERNAME_TWO).getLastName()); syncLogService.delete(log); }
@Test public void doStartSyncB_Linked_doEntityUpdate_Filtered() { SysSyncConfigFilter configFilter = new SysSyncConfigFilter(); configFilter.setName(SYNC_CONFIG_NAME); List<AbstractSysSyncConfigDto> syncConfigs = syncConfigService.find(configFilter, null).getContent(); this.getBean().changeResourceData(); Assert.assertEquals(1, syncConfigs.size()); AbstractSysSyncConfigDto syncConfigCustom = syncConfigs.get(0); Assert.assertFalse(syncConfigService.isRunning(syncConfigCustom)); SysSystemMappingDto systemMapping = systemMappingService.get(syncConfigCustom.getSystemMapping()); SysSystemDto system = systemService.get(schemaObjectClassService.get(systemMapping.getObjectClass()).getSystem()); IdmFormDefinitionDto savedFormDefinition = systemService.getConnectorFormDefinition(system.getConnectorInstance()); IdmFormAttributeDto changeLogColumn = savedFormDefinition.getMappedAttributeByCode("changeLogColumn"); formService.saveValues(system, changeLogColumn, ImmutableList.of("modified")); syncConfigCustom.setLinkedAction(SynchronizationLinkedActionType.UPDATE_ENTITY); syncConfigCustom.setUnlinkedAction(SynchronizationUnlinkedActionType.IGNORE); syncConfigCustom.setMissingEntityAction(SynchronizationMissingEntityActionType.IGNORE); syncConfigCustom.setMissingAccountAction(ReconciliationMissingAccountActionType.IGNORE); syncConfigCustom.setCustomFilter(false); syncConfigCustom.setReconciliation(false); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); syncConfigCustom.setToken(ZonedDateTime.now().format(formatter)); syncConfigCustom.setFilterOperation(IcFilterOperationType.ENDS_WITH); 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 actionLog = actions.stream().filter(action -> { return SynchronizationActionType.UPDATE_ENTITY == action.getSyncAction(); }).findFirst().get(); SysSyncItemLogFilter itemLogFilter = new SysSyncItemLogFilter(); itemLogFilter.setSyncActionLogId(actionLog.getId()); List<SysSyncItemLogDto> items = syncItemLogService.find(itemLogFilter, null).getContent(); Assert.assertEquals(1, items.size()); Assert.assertEquals("x"+IDENTITY_USERNAME_TWO, items.get(0).getIdentification()); syncLogService.delete(log); formService.saveValues(system, changeLogColumn, ImmutableList.of("")); }
@Test public void doStartSyncB_Linked_doEntityUpdate_Filtered_Custom() { SysSyncConfigFilter configFilter = new SysSyncConfigFilter(); configFilter.setName(SYNC_CONFIG_NAME); List<AbstractSysSyncConfigDto> syncConfigs = syncConfigService.find(configFilter, null).getContent(); this.getBean().changeResourceData(); Assert.assertEquals(1, syncConfigs.size()); AbstractSysSyncConfigDto syncConfigCustom = syncConfigs.get(0); Assert.assertFalse(syncConfigService.isRunning(syncConfigCustom)); syncConfigCustom.setLinkedAction(SynchronizationLinkedActionType.UPDATE_ENTITY); syncConfigCustom.setUnlinkedAction(SynchronizationUnlinkedActionType.IGNORE); syncConfigCustom.setMissingEntityAction(SynchronizationMissingEntityActionType.IGNORE); syncConfigCustom.setMissingAccountAction(ReconciliationMissingAccountActionType.IGNORE); syncConfigCustom.setCustomFilter(true); syncConfigCustom.setReconciliation(false); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); syncConfigCustom.setToken(ZonedDateTime.now().format(formatter)); syncConfigCustom.setFilterOperation(IcFilterOperationType.LESS_THAN); 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 actionLog = actions.stream().filter(action -> { return SynchronizationActionType.UPDATE_ENTITY == action.getSyncAction(); }).findFirst().get(); SysSyncItemLogFilter itemLogFilter = new SysSyncItemLogFilter(); itemLogFilter.setSyncActionLogId(actionLog.getId()); List<SysSyncItemLogDto> items = syncItemLogService.find(itemLogFilter, null).getContent(); Assert.assertEquals(1, items.size()); Assert.assertEquals("x"+IDENTITY_USERNAME_ONE, items.get(0).getIdentification()); syncLogService.delete(log); }
@Test public void doStartSyncB_Linked_doEntityUpdate_WrongEmail() { SysSyncConfigFilter configFilter = new SysSyncConfigFilter(); configFilter.setName(SYNC_CONFIG_NAME); List<AbstractSysSyncConfigDto> syncConfigs = syncConfigService.find(configFilter, null).getContent(); this.getBean().changeResourceDataWrongEmail(); Assert.assertEquals(1, syncConfigs.size()); AbstractSysSyncConfigDto syncConfigCustom = syncConfigs.get(0); Assert.assertFalse(syncConfigService.isRunning(syncConfigCustom)); syncConfigCustom.setLinkedAction(SynchronizationLinkedActionType.UPDATE_ENTITY); syncConfigCustom.setUnlinkedAction(SynchronizationUnlinkedActionType.IGNORE); syncConfigCustom.setMissingEntityAction(SynchronizationMissingEntityActionType.IGNORE); syncConfigCustom.setMissingAccountAction(ReconciliationMissingAccountActionType.IGNORE); syncConfigCustom.setReconciliation(true); 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.assertTrue(log.isContainsError()); SysSyncActionLogFilter actionLogFilter = new SysSyncActionLogFilter(); actionLogFilter.setSynchronizationLogId(log.getId()); List<SysSyncActionLogDto> actions = syncActionLogService.find(actionLogFilter, null).getContent(); Assert.assertEquals(1, actions.size()); SysSyncActionLogDto actionLog = actions.stream().filter(action -> { return SynchronizationActionType.UPDATE_ENTITY == action.getSyncAction() && OperationResultType.ERROR == action.getOperationResult(); }).findFirst().get(); SysSyncItemLogFilter itemLogFilter = new SysSyncItemLogFilter(); itemLogFilter.setSyncActionLogId(actionLog.getId()); List<SysSyncItemLogDto> items = syncItemLogService.find(itemLogFilter, null).getContent(); Assert.assertEquals(2, items.size()); syncLogService.delete(log); }