RoleDTO extends TimestampedCandlepinDTO<RoleDTO> implements RoleInfo { public boolean addUser(UserDTO user) { if (user == null) { throw new IllegalArgumentException("user is null"); } if (user.getUsername() == null) { throw new IllegalArgumentException("user does not have a valid username"); } if (this.users == null) { this.users = new HashMap<>(); } UserDTO previous = this.users.put(user.getUsername(), user); return previous != user; } RoleDTO();  RoleDTO(RoleDTO source); String getId(); RoleDTO setId(String id); String getName(); RoleDTO setName(String name); boolean addUser(UserDTO user); boolean removeUser(UserDTO user); boolean removeUser(String username); Collection<UserDTO> getUsers(); RoleDTO setUsers(Collection<UserDTO> users); boolean addPermission(PermissionBlueprintDTO permission); boolean removePermission(PermissionBlueprintDTO permission); boolean removePermission(String permissionId); Collection<PermissionBlueprintDTO> getPermissions(); RoleDTO setPermissions(Collection<PermissionBlueprintDTO> permissions); @Override String toString(); @Override boolean equals(Object obj); @Override int hashCode(); @Override RoleDTO populate(RoleDTO source); static final long serialVersionUID; }
@Test public void testAddUser() { RoleDTO dto = this.getDTOInstance(); UserDTO user1 = new UserDTO(); user1.setId("test-user-1"); user1.setUsername(user1.getId()); UserDTO user2 = new UserDTO(); user2.setId("test-user-2"); user2.setUsername(user2.getId()); Collection<UserDTO> users = dto.getUsers(); assertNull(users); boolean added = dto.addUser(user1); assertTrue(added); users = dto.getUsers(); assertNotNull(users); assertEquals(1, users.size()); assertTrue(users.contains(user1)); assertFalse(users.contains(user2)); added = dto.addUser(user2); assertTrue(added); users = dto.getUsers(); assertNotNull(users); assertEquals(2, users.size()); assertTrue(users.contains(user1)); assertTrue(users.contains(user2)); }
@Test(expected = IllegalArgumentException.class) public void testAddUserNullUser() { RoleDTO dto = this.getDTOInstance(); dto.addUser(null); }
@Test(expected = IllegalArgumentException.class) public void testAddUserIncompleteUser() { RoleDTO dto = this.getDTOInstance(); UserDTO user = new UserDTO(); dto.addUser(user); }