}
}
@Test
public void bulkActions() {
final BulkAction bulkAction = new BulkAction();
for (int i = 0; i < 10; i++) {
UserTO userTO = getUniqueSampleTO("bulk_" + i + "@apache.org");
bulkAction.addTarget(String.valueOf(createUser(userTO).getId()));
}
// check for a fail
bulkAction.addTarget(String.valueOf(Long.MAX_VALUE));
assertEquals(11, bulkAction.size());
bulkAction.setOperation(BulkAction.Type.SUSPEND);
BulkActionRes res = userService.bulkAction(bulkAction);
assertEquals(10, res.getResultByStatus(Status.SUCCESS).size());
assertEquals(1, res.getResultByStatus(Status.FAILURE).size());
assertEquals("suspended", userService.read(
Long.parseLong(res.getResultByStatus(Status.SUCCESS).get(3).toString())).getStatus());
bulkAction.setOperation(BulkAction.Type.REACTIVATE);
res = userService.bulkAction(bulkAction);
assertEquals(10, res.getResultByStatus(Status.SUCCESS).size());
assertEquals(1, res.getResultByStatus(Status.FAILURE).size());
assertEquals("active", userService.read(
Long.parseLong(res.getResultByStatus(Status.SUCCESS).get(3).toString())).getStatus());
bulkAction.setOperation(BulkAction.Type.DELETE);
res = userService.bulkAction(bulkAction);
assertEquals(10, res.getResultByStatus(Status.SUCCESS).size());
assertEquals(1, res.getResultByStatus(Status.FAILURE).size());
}