@Override
public void execute() throws Exception {
Subject subject = SessionTestHelper.createNewSubject(em, "fake subject");
Set<Permission> originalPermissions = new HashSet<Permission>();
originalPermissions.addAll(EnumSet.allOf(Permission.class));
Role originalRole = SessionTestHelper.createNewRoleForSubject(em, subject, "fake role",
originalPermissions.toArray(new Permission[originalPermissions.size()]));
ResourceGroup resourceGroup = SessionTestHelper.createNewCompatibleGroupForRole(em, originalRole,
"fake group");
Role role = new Role();
role.setId(originalRole.getId());
role.setName("fake role name modified");
role.setDescription("fake role description modified");
Set<Permission> permissions = new HashSet<Permission>(originalRole.getPermissions());
permissions.remove(Permission.MANAGE_SECURITY);
permissions.remove(Permission.MANAGE_INVENTORY);
permissions.remove(Permission.MANAGE_DRIFT);
role.setPermissions(permissions);
Subject subject1 = SessionTestHelper.createNewSubject(em, "fake subject 1");
role.getSubjects().add(subject1);
Subject subject2 = SessionTestHelper.createNewSubject(em, "fake subject 2");
role.getSubjects().add(subject2);
role.getSubjects().remove(subject);
ResourceGroup resourceGroup1 = SessionTestHelper.createNewCompatibleGroupForRole(em, originalRole,
"fake group 1");
role.getResourceGroups().add(resourceGroup1);
ResourceGroup resourceGroup2 = SessionTestHelper.createNewCompatibleGroupForRole(em, originalRole,
"fake group 2");
role.getResourceGroups().add(resourceGroup2);
role.getResourceGroups().remove(resourceGroup);
role = roleManager.updateRole(subjectManager.getOverlord(), role);
assertEquals("fake role name modified", role.getName());
assertEquals("fake role description modified", role.getDescription());
assertEquals(permissions, role.getPermissions());
List<Subject> expectedSubjects = Arrays.asList(subject1, subject2);
assertTrue(role.getSubjects().containsAll(expectedSubjects)
&& expectedSubjects.containsAll(role.getSubjects()));
List<ResourceGroup> expectedResourceGroups = Arrays.asList(resourceGroup1, resourceGroup2);
assertTrue(role.getResourceGroups().containsAll(expectedResourceGroups)
&& expectedResourceGroups.containsAll(role.getResourceGroups()));
}
});
}