@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));
	
	// Find email attribute and change strategy on WRITE_IF_NULL
	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);
	//
	// Set email on identity ONE to null
	IdmIdentityDto one = identityService.getByUsername("x" + IDENTITY_USERNAME_ONE);
	one.setEmail(null);
	identityService.save(one);
	
	// Prepare resource data
	this.getBean().deleteAllResourceData();
	this.getBean().initResourceData();
	this.getBean().changeResourceData();
	
	// Set sync config
	syncConfigCustom.setLinkedAction(SynchronizationLinkedActionType.UPDATE_ENTITY);
	syncConfigCustom.setUnlinkedAction(SynchronizationUnlinkedActionType.IGNORE);
	syncConfigCustom.setMissingEntityAction(SynchronizationMissingEntityActionType.CREATE_ENTITY);
	syncConfigCustom.setMissingAccountAction(ReconciliationMissingAccountActionType.IGNORE);
	syncConfigCustom.setReconciliation(true);
	syncConfigService.save(syncConfigCustom);
	// Check state before sync
	Assert.assertEquals(null, identityService.getByUsername("x" + IDENTITY_USERNAME_ONE).getEmail());
	Assert.assertEquals(IDENTITY_EMAIL_CORRECT, identityService.getByUsername("x" + IDENTITY_USERNAME_TWO).getEmail());
	
	// 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.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());
	// Check state after sync
	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());
	
	// Delete log
	syncLogService.delete(log);
}