super.resetRestTemplate();
}
@Test
public void createWithApproval() {
JdbcTemplate jdbcTemplate = new JdbcTemplate(testDataSource);
UserTO userTO = getSampleTO("createWithApproval@syncope.apache.org");
userTO.addResource("resource-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 = restTemplate.postForObject(BASE_URL + "user/create", userTO, UserTO.class);
assertNotNull(userTO);
assertEquals(1, userTO.getMemberships().size());
assertEquals(9, userTO.getMemberships().get(0).getRoleId());
assertEquals("createApproval", userTO.getStatus());
assertEquals(Collections.singleton("resource-testdb"), userTO.getResources());
assertTrue(userTO.getPropagationTOs().isEmpty());
Exception exception = null;
try {
jdbcTemplate.queryForInt("SELECT id FROM test WHERE id=?", userTO.getUsername());
} catch (EmptyResultDataAccessException e) {
exception = e;
}
assertNotNull(exception);
// 2. request if there is any pending task for user just created
WorkflowFormTO form = restTemplate.getForObject(BASE_URL + "user/workflow/form/{userId}", WorkflowFormTO.class,
userTO.getId());
assertNotNull(form);
assertNotNull(form.getTaskId());
assertNull(form.getOwner());
// 4. claim task (from admin)
form = restTemplate.getForObject(BASE_URL + "user/workflow/form/claim/{taskId}", WorkflowFormTO.class, 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 = restTemplate.postForObject(BASE_URL + "user/workflow/form/submit", form, UserTO.class);
assertNotNull(userTO);
assertEquals("active", userTO.getStatus());
assertEquals(Collections.singleton("resource-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;
}