@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));
	// Create new identity THREE, with account
	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);
	// Set sync config
	syncConfigCustom.setLinkedAction(SynchronizationLinkedActionType.IGNORE);
	syncConfigCustom.setUnlinkedAction(SynchronizationUnlinkedActionType.IGNORE);
	syncConfigCustom.setMissingEntityAction(SynchronizationMissingEntityActionType.IGNORE);
	syncConfigCustom.setMissingAccountAction(ReconciliationMissingAccountActionType.CREATE_ACCOUNT);
	syncConfigCustom.setReconciliation(true);
	syncConfigService.save(syncConfigCustom);
	// Check state before sync
	Assert.assertNull(entityManager.find(TestResource.class, "x" + IDENTITY_USERNAME_THREE));
	// 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(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());
	// Check state after sync
	Assert.assertNotNull(entityManager.find(TestResource.class, "x" + IDENTITY_USERNAME_THREE));
	// Delete log
	syncLogService.delete(log);
}