fail("Expected constrant violation becaus of doupliate entry");
} catch (Exception e) {
// success, this is what we expected
}
//changedAttrMap empty since already synchronized
Attributes attrs = ldapManager.bindUser(uid, pwd, errors);
Identity identitys = securityManager.findIdentityByName(uid);
Map<String, String> changedAttrMap = ldapManager.prepareUserPropertyForSync(attrs, identitys);
// map is empty - no attributes to sync
assertNull(changedAttrMap);
} else {
//create user but with different attributes - must fail since user already exists
User user = UserManager.getInstance().createUser("klaus", "Meier", "klaus@meier.ch");
Identity identity = securityManager.createAndPersistIdentityAndUser("kmeier", user, "LDAP", "kmeier", null);
SecurityGroup secGroup = securityManager.findSecurityGroupByName(LDAPConstants.SECURITY_GROUP_LDAP);
securityManager.addIdentityToSecurityGroup(identity, secGroup);
// simulate closed session (user adding from startup job)
DBFactory.getInstance().intermediateCommit();
//changedAttrMap has 2 changes and uid as entrys (Klaus!=klaus, klaus@olat.org!=klaus@meier.ch)
Attributes attrs = ldapManager.bindUser(uid, pwd, errors);
Identity identitys = securityManager.findIdentityByName(uid);
Map<String, String> changedAttrMap = ldapManager.prepareUserPropertyForSync(attrs, identitys);
// result must be 3: 2 changed plus the user ID which is always in the map
assertEquals(3, changedAttrMap.keySet().size());
}
//nothing to change for this user
uid= "mrohrer";
Attributes attrs = ldapManager.bindUser(uid, pwd, errors);
Identity identitys = securityManager.findIdentityByName(uid);
Map<String, String> changedAttrMap = ldapManager.prepareUserPropertyForSync(attrs, identitys);
assertEquals(true, (changedAttrMap==null));
}