assertEquals("syncope458@syncope.apache.org",
userTO.getMemberships().get(0).getVirAttrMap().get("mvirtualdata").getValues().get(0));
// -------------------------------------------
// 2. update membership virtual attribute
MembershipMod membershipMod = new MembershipMod();
membershipMod.setRole(roleTO.getId());
membershipMod.getVirAttrsToUpdate().add(attributeMod("mvirtualdata", "syncope458_NEW@syncope.apache.org"));
UserMod userMod = new UserMod();
userMod.setId(userTO.getId());
userMod.getMembershipsToAdd().add(membershipMod);
userMod.getMembershipsToRemove().add(userTO.getMemberships().iterator().next().getId());
userTO = updateUser(userMod);
assertNotNull(userTO);
// 3. check again after update if membership has virtual attribute populated with new value
assertNotNull(userTO.getMemberships().get(0).getVirAttrMap().get("mvirtualdata"));
assertEquals("syncope458_NEW@syncope.apache.org", userTO.getMemberships().get(0).getVirAttrMap().get(
"mvirtualdata").getValues().get(0));
// ----------------------------------------
// force cache expiring without any modification
// ----------------------------------------
String jdbcURL = null;
ConnInstanceTO connInstanceBean = connectorService.readByResource(RESOURCE_NAME_DBVIRATTR);
for (ConnConfProperty prop : connInstanceBean.getConfiguration()) {
if ("jdbcUrlTemplate".equals(prop.getSchema().getName())) {
jdbcURL = prop.getValues().iterator().next().toString();
prop.getValues().clear();
prop.getValues().add("jdbc:h2:tcp://localhost:9092/xxx");
}
}
connectorService.update(connInstanceBean.getId(), connInstanceBean);
membershipMod = new MembershipMod();
membershipMod.setRole(roleTO.getId());
membershipMod.getVirAttrsToUpdate().add(attributeMod("mvirtualdata", "syncope458_updated@syncope.apache.org"));
userMod = new UserMod();
userMod.setId(userTO.getId());
userMod.getMembershipsToAdd().add(membershipMod);
userMod.getMembershipsToRemove().add(userTO.getMemberships().iterator().next().getId());
userTO = updateUser(userMod);
assertNotNull(userTO);
// ----------------------------------
// change attribute value directly on resource
final JdbcTemplate jdbcTemplate = new JdbcTemplate(testDataSource);
String value = jdbcTemplate.queryForObject(
"SELECT EMAIL FROM testsync WHERE ID=?", String.class, userTO.getId());
assertEquals("syncope458_NEW@syncope.apache.org", value);
jdbcTemplate.update("UPDATE testsync set EMAIL='syncope458_NEW_TWO@syncope.apache.org' WHERE ID=?", userTO.
getId());
value = jdbcTemplate.queryForObject("SELECT EMAIL FROM testsync WHERE ID=?", String.class, userTO.getId());
assertEquals("syncope458_NEW_TWO@syncope.apache.org", value);
// ----------------------------------------
// ----------------------------------------
// restore connector
// ----------------------------------------
for (ConnConfProperty prop : connInstanceBean.getConfiguration()) {
if ("jdbcUrlTemplate".equals(prop.getSchema().getName())) {
prop.getValues().clear();
prop.getValues().add(jdbcURL);
}
}
connectorService.update(connInstanceBean.getId(), connInstanceBean);
// ----------------------------------------
userTO = userService.read(userTO.getId());
assertNotNull(userTO);
// 4. check virtual attribute synchronization after direct update on resource
assertEquals("syncope458_NEW_TWO@syncope.apache.org", userTO.getMemberships().get(0).getVirAttrMap().get(
"mvirtualdata").getValues().get(0));
// 5. remove membership virtual attribute
membershipMod = new MembershipMod();
membershipMod.setRole(roleTO.getId());
membershipMod.getVirAttrsToRemove().add("mvirtualdata");
userMod = new UserMod();
userMod.setId(userTO.getId());
userMod.getMembershipsToAdd().add(membershipMod);
userMod.getMembershipsToRemove().add(userTO.getMemberships().iterator().next().getId());