public void createWithApproval() {
Assume.assumeTrue(ActivitiDetector.isActivitiEnabledForUsers());
JdbcTemplate jdbcTemplate = new JdbcTemplate(testDataSource);
UserTO userTO = getUniqueSampleTO("createWithApproval@syncope.apache.org");
userTO.addResource(RESOURCE_NAME_TESTDB);
// User with role 9 are defined in workflow as subject to approval
MembershipTO membershipTO = new MembershipTO();
membershipTO.setRoleId(9L);
userTO.addMembership(membershipTO);
// 1. create user with role 9 (and verify that no propagation occurred)
userTO = createUser(userTO);
assertNotNull(userTO);
assertEquals(1, userTO.getMemberships().size());
assertEquals(9, userTO.getMemberships().get(0).getRoleId());
assertEquals("createApproval", userTO.getStatus());
assertEquals(Collections.singleton(RESOURCE_NAME_TESTDB), userTO.getResources());
assertTrue(userTO.getPropagationStatusTOs().isEmpty());
Exception exception = null;
try {
jdbcTemplate.queryForObject("SELECT id FROM test WHERE id=?",
new String[]{userTO.getUsername()}, Integer.class);
} catch (EmptyResultDataAccessException e) {
exception = e;
}
assertNotNull(exception);
// 2. request if there is any pending form for user just created
List<WorkflowFormTO> forms = userWorkflowService.getForms();
assertNotNull(forms);
assertEquals(1, forms.size());
WorkflowFormTO form = userWorkflowService.getFormForUser(userTO.getId());
assertNotNull(form);
assertNotNull(form.getTaskId());
assertNull(form.getOwner());
// 4. claim task (from admin)
form = userWorkflowService.claimForm(form.getTaskId());
assertNotNull(form);
assertNotNull(form.getTaskId());
assertNotNull(form.getOwner());
// 5. approve user (and verify that propagation occurred)
Map<String, WorkflowFormPropertyTO> props = form.getPropertyMap();
props.get("approve").setValue(Boolean.TRUE.toString());
form.setProperties(props.values());
userTO = userWorkflowService.submitForm(form);
assertNotNull(userTO);
assertEquals("active", userTO.getStatus());
assertEquals(Collections.singleton(RESOURCE_NAME_TESTDB), userTO.getResources());
exception = null;
try {
final String username = jdbcTemplate.queryForObject("SELECT id FROM test WHERE id=?", String.class,
userTO.getUsername());
assertEquals(userTO.getUsername(), username);
} catch (EmptyResultDataAccessException e) {
exception = e;
}
assertNull(exception);
// 6. update user
UserMod userMod = new UserMod();
userMod.setId(userTO.getId());
userMod.setPassword("anotherPassword123");
userTO = userService.update(userMod.getId(), userMod);
assertNotNull(userTO);
}