@Test public void testAddGroupAdminRoleToUser() throws Exception { String userId = USER_ID; PersonPE user = createUserInDB(userId); AssertJUnit.assertEquals( 0, daoFactory.getPersonDAO().tryFindPersonByUserId(userId).getRoleAssignments().size()); AssertJUnit.assertEquals( 0, daoFactory.getRoleAssignmentDAO().listRoleAssignmentsByPerson(user).size()); GroupPE group = daoFactory.getGroupDAO().listGroups().get(0); RoleAssignmentPE roleAssignment = new RoleAssignmentPE(); roleAssignment.setRole(RoleCode.ADMIN); roleAssignment.setGroup(group); roleAssignment.setRegistrator(getSystemPerson()); user.addRoleAssignment(roleAssignment); AssertJUnit.assertEquals( 1, daoFactory.getPersonDAO().tryFindPersonByUserId(userId).getRoleAssignments().size()); AssertJUnit.assertEquals( 1, daoFactory.getRoleAssignmentDAO().listRoleAssignmentsByPerson(user).size()); }
private PersonPE createUserInDB(String userId) { PersonPE person = new PersonPE(); person.setDatabaseInstance(daoFactory.getHomeDatabaseInstance()); person.setRegistrator(getSystemPerson()); person.setUserId(userId); person.setEmail("*****@*****.**"); person.setFirstName("Geralt"); person.setLastName("Of Rivia"); daoFactory.getPersonDAO().createPerson(person); return daoFactory.getPersonDAO().tryFindPersonByUserId(userId); }