use of org.apache.syncope.core.persistence.api.entity.user.UPlainAttr in project syncope by apache.
the class PlainAttrTest method saveWithEnum.
@Test
public void saveWithEnum() throws ClassNotFoundException {
User user = userDAO.find("1417acbe-cbf6-4277-9372-e75e04f97000");
assertNotNull(user);
PlainSchema gender = plainSchemaDAO.find("gender");
assertNotNull(gender);
assertNotNull(gender.getType());
assertNotNull(gender.getEnumerationValues());
UPlainAttr attribute = entityFactory.newEntity(UPlainAttr.class);
attribute.setOwner(user);
attribute.setSchema(gender);
user.add(attribute);
Exception thrown = null;
try {
attribute.add("A", anyUtilsFactory.getInstance(AnyTypeKind.USER));
} catch (ValidationException e) {
thrown = e;
}
assertNotNull(thrown);
attribute.add("M", anyUtilsFactory.getInstance(AnyTypeKind.USER));
InvalidEntityException iee = null;
try {
userDAO.save(user);
} catch (InvalidEntityException e) {
iee = e;
}
assertNull(iee);
}
use of org.apache.syncope.core.persistence.api.entity.user.UPlainAttr in project syncope by apache.
the class PlainAttrTest method delete.
@Test
public void delete() {
UPlainAttr attribute = plainAttrDAO.find("9d0d9e40-1b18-488e-9482-37dab82163c9", UPlainAttr.class);
String attrSchemaName = attribute.getSchema().getKey();
plainAttrDAO.delete(attribute.getKey(), UPlainAttr.class);
PlainSchema schema = plainSchemaDAO.find(attrSchemaName);
assertNotNull(schema);
}
use of org.apache.syncope.core.persistence.api.entity.user.UPlainAttr in project syncope by apache.
the class RoleTest method dynMembership.
@Test
public void dynMembership() {
// 0. create user matching the condition below
User user = entityFactory.newEntity(User.class);
user.setUsername("username");
user.setRealm(realmDAO.findByFullPath("/even/two"));
user.add(anyTypeClassDAO.find("other"));
UPlainAttr attr = entityFactory.newEntity(UPlainAttr.class);
attr.setOwner(user);
attr.setSchema(plainSchemaDAO.find("cool"));
attr.add("true", anyUtilsFactory.getInstance(AnyTypeKind.USER));
user.add(attr);
user = userDAO.save(user);
String newUserKey = user.getKey();
assertNotNull(newUserKey);
// 1. create role with dynamic membership
Role role = entityFactory.newEntity(Role.class);
role.setKey("new");
role.add(realmDAO.getRoot());
role.add(realmDAO.findByFullPath("/even/two"));
role.getEntitlements().add(StandardEntitlement.LOG_LIST);
role.getEntitlements().add(StandardEntitlement.LOG_SET_LEVEL);
DynRoleMembership dynMembership = entityFactory.newEntity(DynRoleMembership.class);
dynMembership.setFIQLCond("cool==true");
dynMembership.setRole(role);
role.setDynMembership(dynMembership);
Role actual = roleDAO.save(role);
assertNotNull(actual);
roleDAO.flush();
// 2. verify that dynamic membership is there
actual = roleDAO.find(actual.getKey());
assertNotNull(actual);
assertNotNull(actual.getDynMembership());
assertNotNull(actual.getDynMembership().getKey());
assertEquals(actual, actual.getDynMembership().getRole());
// 3. verify that expected users have the created role dynamically assigned
List<String> members = roleDAO.findDynMembers(actual);
assertEquals(2, members.size());
assertEquals(new HashSet<>(Arrays.asList("c9b2dec2-00a7-4855-97c0-d854842b4b24", newUserKey)), new HashSet<>(members));
user = userDAO.find("c9b2dec2-00a7-4855-97c0-d854842b4b24");
assertNotNull(user);
Collection<Role> dynRoleMemberships = findDynRoles(user);
assertEquals(1, dynRoleMemberships.size());
assertTrue(dynRoleMemberships.contains(actual.getDynMembership().getRole()));
// 4. delete the new user and verify that dynamic membership was updated
userDAO.delete(newUserKey);
userDAO.flush();
actual = roleDAO.find(actual.getKey());
members = roleDAO.findDynMembers(actual);
assertEquals(1, members.size());
assertEquals("c9b2dec2-00a7-4855-97c0-d854842b4b24", members.get(0));
// 5. delete role and verify that dynamic membership was also removed
String dynMembershipKey = actual.getDynMembership().getKey();
roleDAO.delete(actual);
roleDAO.flush();
assertNull(entityManager().find(JPADynRoleMembership.class, dynMembershipKey));
dynRoleMemberships = findDynRoles(user);
assertTrue(dynRoleMemberships.isEmpty());
}
Aggregations