@Test
public void doStartSyncC_Unlinked_doLinkAndUpdateAccount() {

	// We have to do unlink first
	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));
	// Set sync config
	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);
	// Change account on resource
	getBean().changeResourceData();
	// Check state before sync
	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());
	// Start synchronization
	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());
	// Check state after sync
	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());
	// Delete log
	syncLogService.delete(log);
}