use of org.apache.syncope.common.rest.api.service.UserWorkflowService in project syncope by apache.
the class UserWorkflowITCase method createWithReject.
@Test
public void createWithReject() {
assumeTrue(FlowableDetector.isFlowableEnabledForUsers(syncopeService));
UserTO userTO = UserITCase.getUniqueSampleTO("createWithReject@syncope.apache.org");
userTO.getResources().add(RESOURCE_NAME_TESTDB);
// User with group 9 are defined in workflow as subject to approval
userTO.getMemberships().add(new MembershipTO.Builder().group("0cbcabd2-4410-4b6b-8f05-a052b451d18f").build());
// 1. create user with group 9
userTO = createUser(userTO).getEntity();
assertNotNull(userTO);
assertEquals(1, userTO.getMemberships().size());
assertEquals("0cbcabd2-4410-4b6b-8f05-a052b451d18f", userTO.getMemberships().get(0).getGroupKey());
assertEquals("createApproval", userTO.getStatus());
// 2. request if there is any pending task for user just created
WorkflowFormTO form = userWorkflowService.getFormForUser(userTO.getKey());
assertNotNull(form);
assertNotNull(form.getUsername());
assertEquals(userTO.getUsername(), form.getUsername());
assertNotNull(form.getTaskId());
assertNull(form.getOwner());
// 3. claim task as rossini, with role "User manager" granting entitlement to claim forms but not in group 7,
// designated for approval in workflow definition: fail
UserTO rossini = userService.read("1417acbe-cbf6-4277-9372-e75e04f97000");
if (!rossini.getRoles().contains("User manager")) {
UserPatch userPatch = new UserPatch();
userPatch.setKey("1417acbe-cbf6-4277-9372-e75e04f97000");
userPatch.getRoles().add(new StringPatchItem.Builder().operation(PatchOperation.ADD_REPLACE).value("User manager").build());
rossini = updateUser(userPatch).getEntity();
}
assertTrue(rossini.getRoles().contains("User manager"));
UserWorkflowService userService2 = clientFactory.create("rossini", ADMIN_PWD).getService(UserWorkflowService.class);
try {
userService2.claimForm(form.getTaskId());
fail("This should not happen");
} catch (SyncopeClientException e) {
assertEquals(ClientExceptionType.Workflow, e.getType());
}
// 4. claim task from bellini, with role "User manager" and in group 7
UserWorkflowService userService3 = clientFactory.create("bellini", ADMIN_PWD).getService(UserWorkflowService.class);
form = userService3.claimForm(form.getTaskId());
assertNotNull(form);
assertNotNull(form.getTaskId());
assertNotNull(form.getOwner());
// 5. reject user
form.getProperty("approveCreate").get().setValue(Boolean.FALSE.toString());
form.getProperty("rejectReason").get().setValue("I don't like him.");
userTO = userService3.submitForm(form);
assertNotNull(userTO);
assertEquals("rejected", userTO.getStatus());
// 6. check that rejected user was not propagated to external resource (SYNCOPE-364)
JdbcTemplate jdbcTemplate = new JdbcTemplate(testDataSource);
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);
}
use of org.apache.syncope.common.rest.api.service.UserWorkflowService in project syncope by apache.
the class UserWorkflowITCase method issueSYNCOPE15.
@Test
public void issueSYNCOPE15() {
assumeTrue(FlowableDetector.isFlowableEnabledForUsers(syncopeService));
// read forms *before* any operation
List<WorkflowFormTO> forms = userWorkflowService.getForms();
assertNotNull(forms);
int preForms = forms.size();
UserTO userTO = UserITCase.getUniqueSampleTO("issueSYNCOPE15@syncope.apache.org");
userTO.getResources().clear();
userTO.getVirAttrs().clear();
userTO.getDerAttrs().clear();
userTO.getMemberships().clear();
// Users with group 0cbcabd2-4410-4b6b-8f05-a052b451d18f are defined in workflow as subject to approval
userTO.getMemberships().add(new MembershipTO.Builder().group("0cbcabd2-4410-4b6b-8f05-a052b451d18f").build());
// 1. create user with group 9 (and verify that no propagation occurred)
userTO = createUser(userTO).getEntity();
assertNotNull(userTO);
assertNotEquals(0L, userTO.getKey());
assertNotNull(userTO.getCreationDate());
assertNotNull(userTO.getCreator());
assertNotNull(userTO.getLastChangeDate());
assertNotNull(userTO.getLastModifier());
assertEquals(userTO.getCreationDate(), userTO.getLastChangeDate());
// 2. request if there is any pending form for user just created
forms = userWorkflowService.getForms();
assertEquals(preForms + 1, forms.size());
WorkflowFormTO form = userWorkflowService.getFormForUser(userTO.getKey());
assertNotNull(form);
// 3. first claim by bellini ....
UserWorkflowService userService3 = clientFactory.create("bellini", ADMIN_PWD).getService(UserWorkflowService.class);
form = userService3.claimForm(form.getTaskId());
assertNotNull(form);
assertNotNull(form.getTaskId());
assertNotNull(form.getOwner());
// 4. second claim task by admin
form = userWorkflowService.claimForm(form.getTaskId());
assertNotNull(form);
// 5. approve user
form.getProperty("approveCreate").get().setValue(Boolean.TRUE.toString());
// 6. submit approve
userTO = userWorkflowService.submitForm(form);
assertNotNull(userTO);
assertEquals(preForms, userWorkflowService.getForms().size());
assertNull(userWorkflowService.getFormForUser(userTO.getKey()));
// 7.check that no more forms are still to be processed
forms = userWorkflowService.getForms();
assertEquals(preForms, forms.size());
}
Aggregations