@Test
public void addUserRolesTest() {

    // Setup:
    Map<String, Role> roles = IntStream.range(1, 3)
            .mapToObj(Integer::toString)
            .collect(Collectors.toMap(s -> s, s -> roleFactory.createNew(vf.createIRI("http://mobi.com/roles/" + s))));
    User newUser = userFactory.createNew(vf.createIRI("http://mobi.com/users/" + UsernameTestFilter.USERNAME));
    newUser.setHasUserRole(Collections.singleton(role));
    when(engineManager.getRole( anyString())).thenAnswer(i -> Optional.of(roles.get(i.getArgumentAt(0, String.class))));
    when(engineManager.retrieveUser(anyString())).thenReturn(Optional.of(newUser));
    Response response = target().path("users/" + UsernameTestFilter.USERNAME + "/roles").queryParam("roles", roles.keySet().toArray())
            .request().put(Entity.entity("", MediaType.MULTIPART_FORM_DATA));
    assertEquals(response.getStatus(), 200);
    verify(engineManager).retrieveUser(UsernameTestFilter.USERNAME);
    roles.keySet().forEach(s -> verify(engineManager).getRole(s));
    ArgumentCaptor<User> captor = ArgumentCaptor.forClass(User.class);
    verify(engineManager).updateUser(captor.capture());
    User updatedUser = captor.getValue();
    assertEquals(user.getResource(), updatedUser.getResource());
    Set<Resource> updatedRoles = updatedUser.getHasUserRole_resource();
    assertEquals(roles.size() + 1, updatedRoles.size());
    assertTrue(updatedRoles.contains(role.getResource()));
    roles.values().forEach(role -> assertTrue(updatedRoles.contains(role.getResource())));
}