@Test
public void testThreeAutomaticAndThreeManually() {

	String automaticRoleValue = "test" + System.currentTimeMillis();
	IdmIdentityDto identity = getHelper().createIdentity(new GuardedString());
	identity.setDescription(automaticRoleValue);
	identity.setTitleAfter(automaticRoleValue);
	identity.setTitleBefore(automaticRoleValue);
	identity = identityService.save(identity);
	IdmRoleDto role = getHelper().createRole();
	
	IdmIdentityRoleDto identityRoleOne = getHelper().createIdentityRole(identity, role);
	IdmIdentityRoleDto identityRoleTwo = getHelper().createIdentityRole(identity, role);
	IdmIdentityRoleDto identityRoleThree = getHelper().createIdentityRole(identity, role);
	IdmAutomaticRoleAttributeDto automaticRoleOne = getHelper().createAutomaticRole(role.getId());
	getHelper().createAutomaticRoleRule(
			automaticRoleOne.getId(),
			AutomaticRoleAttributeRuleComparison.EQUALS,
			AutomaticRoleAttributeRuleType.IDENTITY,
			IdmIdentity_.description.getName(), null, automaticRoleValue);
	
	IdmAutomaticRoleAttributeDto automaticRoleTwo = getHelper().createAutomaticRole(role.getId());
	getHelper().createAutomaticRoleRule(
			automaticRoleTwo.getId(),
			AutomaticRoleAttributeRuleComparison.EQUALS,
			AutomaticRoleAttributeRuleType.IDENTITY,
			IdmIdentity_.titleAfter.getName(), null, automaticRoleValue);
	
	IdmAutomaticRoleAttributeDto automaticRoleThree = getHelper().createAutomaticRole(role.getId());
	getHelper().createAutomaticRoleRule(
			automaticRoleThree.getId(),
			AutomaticRoleAttributeRuleComparison.EQUALS,
			AutomaticRoleAttributeRuleType.IDENTITY,
			IdmIdentity_.titleBefore.getName(), null, automaticRoleValue);
	getHelper().recalculateAutomaticRoleByAttribute(automaticRoleOne.getId());
	getHelper().recalculateAutomaticRoleByAttribute(automaticRoleTwo.getId());
	getHelper().recalculateAutomaticRoleByAttribute(automaticRoleThree.getId());
	List<IdmIdentityRoleDto> roles = identityRoleService.findAllByIdentity(identity.getId());
	assertEquals(6, roles.size());
	IdmBulkActionDto bulkAction = this.findBulkAction(IdmIdentity.class, IdentityRoleByIdentityDeduplicationBulkAction.NAME);
	bulkAction.setIdentifiers(Sets.newHashSet(identity.getId()));
	
	IdmBulkActionDto processAction = bulkActionManager.processAction(bulkAction);
	checkResultLrt(processAction, 1l, null, null);
	roles = identityRoleService.findAllByIdentity(identity.getId());
	assertEquals(3, roles.size());
	
	for (IdmIdentityRoleDto identityRole : roles) {
		assertNotEquals(identityRoleOne.getId(), identityRole.getId());
		assertNotEquals(identityRoleTwo.getId(), identityRole.getId());
		assertNotEquals(identityRoleThree.getId(), identityRole.getId());
	}
}