use of org.jbpm.process.instance.impl.humantask.HumanTaskTransition in project kogito-runtimes by kiegroup.
the class UserTaskIT method testBasicUserTaskProcessClaimAndCompletePhasesWithIdentity.
@Test
public void testBasicUserTaskProcessClaimAndCompletePhasesWithIdentity() throws Exception {
Application app = generateCodeProcessesOnly("usertask/UserTasksProcess.bpmn2");
assertThat(app).isNotNull();
final List<String> workItemTransitionEvents = new ArrayList<>();
app.config().get(ProcessConfig.class).processEventListeners().listeners().add(new DefaultKogitoProcessEventListener() {
@Override
public void beforeWorkItemTransition(ProcessWorkItemTransitionEvent event) {
workItemTransitionEvents.add("BEFORE:: " + event);
}
@Override
public void afterWorkItemTransition(ProcessWorkItemTransitionEvent event) {
workItemTransitionEvents.add("AFTER:: " + event);
}
});
Process<? extends Model> p = app.get(Processes.class).processById("UserTasksProcess");
Model m = p.createModel();
Map<String, Object> parameters = new HashMap<>();
m.fromMap(parameters);
ProcessInstance<?> processInstance = p.createInstance(m);
processInstance.start();
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
List<WorkItem> workItems = processInstance.workItems(securityPolicy);
assertEquals(1, workItems.size());
WorkItem wi = workItems.get(0);
assertEquals("FirstTask", wi.getName());
assertEquals(Active.ID, wi.getPhase());
assertEquals(Active.STATUS, wi.getPhaseStatus());
assertEquals(0, wi.getResults().size());
processInstance.transitionWorkItem(workItems.get(0).getId(), new HumanTaskTransition(Claim.ID, Collections.singletonMap("test", "value"), securityPolicy));
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
workItems = processInstance.workItems(securityPolicy);
assertEquals(1, workItems.size());
wi = workItems.get(0);
assertEquals("FirstTask", wi.getName());
assertEquals(Claim.ID, wi.getPhase());
assertEquals(Claim.STATUS, wi.getPhaseStatus());
assertEquals(2, wi.getResults().size());
assertEquals("value", wi.getResults().get("test"));
assertEquals("john", wi.getResults().get("ActorId"));
processInstance.transitionWorkItem(workItems.get(0).getId(), new HumanTaskTransition(Complete.ID, null, securityPolicy));
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
workItems = processInstance.workItems(securityPolicy);
assertEquals(1, workItems.size());
wi = workItems.get(0);
assertEquals("SecondTask", wi.getName());
assertEquals(Active.ID, wi.getPhase());
assertEquals(Active.STATUS, wi.getPhaseStatus());
assertEquals(0, wi.getResults().size());
processInstance.abort();
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ABORTED);
assertThat(workItemTransitionEvents).hasSize(10);
}
use of org.jbpm.process.instance.impl.humantask.HumanTaskTransition in project kogito-runtimes by kiegroup.
the class UserTaskIT method testBasicUserTaskProcessClaimReleaseClaimAndCompletePhases.
@Test
public void testBasicUserTaskProcessClaimReleaseClaimAndCompletePhases() throws Exception {
Application app = generateCodeProcessesOnly("usertask/UserTasksProcess.bpmn2");
assertThat(app).isNotNull();
Process<? extends Model> p = app.get(Processes.class).processById("UserTasksProcess");
Model m = p.createModel();
Map<String, Object> parameters = new HashMap<>();
m.fromMap(parameters);
ProcessInstance<?> processInstance = p.createInstance(m);
processInstance.start();
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
List<WorkItem> workItems = processInstance.workItems(securityPolicy);
assertEquals(1, workItems.size());
WorkItem wi = workItems.get(0);
assertEquals("FirstTask", wi.getName());
assertEquals(Active.ID, wi.getPhase());
assertEquals(Active.STATUS, wi.getPhaseStatus());
assertEquals(0, wi.getResults().size());
processInstance.transitionWorkItem(workItems.get(0).getId(), new HumanTaskTransition(Claim.ID, Collections.singletonMap("test", "value"), securityPolicy));
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
workItems = processInstance.workItems(securityPolicy);
assertEquals(1, workItems.size());
wi = workItems.get(0);
assertEquals("FirstTask", wi.getName());
assertEquals(Claim.ID, wi.getPhase());
assertEquals(Claim.STATUS, wi.getPhaseStatus());
assertEquals(2, wi.getResults().size());
assertEquals("value", wi.getResults().get("test"));
assertEquals("john", wi.getResults().get("ActorId"));
processInstance.transitionWorkItem(workItems.get(0).getId(), new HumanTaskTransition(Release.ID, null, securityPolicy));
workItems = processInstance.workItems(securityPolicy);
assertEquals(1, workItems.size());
wi = workItems.get(0);
assertEquals("FirstTask", wi.getName());
assertEquals(Release.ID, wi.getPhase());
assertEquals(Release.STATUS, wi.getPhaseStatus());
assertEquals(2, wi.getResults().size());
assertEquals("value", wi.getResults().get("test"));
assertEquals("john", wi.getResults().get("ActorId"));
processInstance.transitionWorkItem(workItems.get(0).getId(), new HumanTaskTransition(Claim.ID, Collections.singletonMap("test", "value"), securityPolicy));
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
workItems = processInstance.workItems(securityPolicy);
assertEquals(1, workItems.size());
wi = workItems.get(0);
assertEquals("FirstTask", wi.getName());
assertEquals(Claim.ID, wi.getPhase());
assertEquals(Claim.STATUS, wi.getPhaseStatus());
assertEquals(2, wi.getResults().size());
assertEquals("value", wi.getResults().get("test"));
assertEquals("john", wi.getResults().get("ActorId"));
processInstance.transitionWorkItem(workItems.get(0).getId(), new HumanTaskTransition(Complete.ID, null, securityPolicy));
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
workItems = processInstance.workItems(securityPolicy);
assertEquals(1, workItems.size());
wi = workItems.get(0);
assertEquals("SecondTask", wi.getName());
assertEquals(Active.ID, wi.getPhase());
assertEquals(Active.STATUS, wi.getPhaseStatus());
assertEquals(0, wi.getResults().size());
processInstance.abort();
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ABORTED);
}
use of org.jbpm.process.instance.impl.humantask.HumanTaskTransition in project kogito-runtimes by kiegroup.
the class UserTaskIT method testBasicUserTaskProcessReleaseAndCompletePhases.
@Test
public void testBasicUserTaskProcessReleaseAndCompletePhases() throws Exception {
Application app = generateCodeProcessesOnly("usertask/UserTasksProcess.bpmn2");
assertThat(app).isNotNull();
Process<? extends Model> p = app.get(Processes.class).processById("UserTasksProcess");
Model m = p.createModel();
Map<String, Object> parameters = new HashMap<>();
m.fromMap(parameters);
ProcessInstance<?> processInstance = p.createInstance(m);
processInstance.start();
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
List<WorkItem> workItems = processInstance.workItems(securityPolicy);
assertEquals(1, workItems.size());
WorkItem wi = workItems.get(0);
assertEquals("FirstTask", wi.getName());
assertEquals(Active.ID, wi.getPhase());
assertEquals(Active.STATUS, wi.getPhaseStatus());
assertEquals(0, wi.getResults().size());
final String wiId = wi.getId();
assertThrows(InvalidTransitionException.class, () -> processInstance.transitionWorkItem(wiId, new HumanTaskTransition(Release.ID, null, securityPolicy)));
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
workItems = processInstance.workItems(securityPolicy);
assertEquals(1, workItems.size());
wi = workItems.get(0);
assertEquals("FirstTask", wi.getName());
assertEquals(Active.ID, wi.getPhase());
assertEquals(Active.STATUS, wi.getPhaseStatus());
assertEquals(0, wi.getResults().size());
processInstance.transitionWorkItem(workItems.get(0).getId(), new HumanTaskTransition(Complete.ID, null, securityPolicy));
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
workItems = processInstance.workItems(securityPolicy);
assertEquals(1, workItems.size());
wi = workItems.get(0);
assertEquals("SecondTask", wi.getName());
assertEquals(Active.ID, wi.getPhase());
assertEquals(Active.STATUS, wi.getPhaseStatus());
assertEquals(0, wi.getResults().size());
processInstance.abort();
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ABORTED);
}
use of org.jbpm.process.instance.impl.humantask.HumanTaskTransition in project kogito-runtimes by kiegroup.
the class UserTaskIT method testBasicUserTaskProcessPhases.
@Test
public void testBasicUserTaskProcessPhases() throws Exception {
Application app = generateCodeProcessesOnly("usertask/UserTasksProcess.bpmn2");
assertThat(app).isNotNull();
Process<? extends Model> p = app.get(Processes.class).processById("UserTasksProcess");
Model m = p.createModel();
Map<String, Object> parameters = new HashMap<>();
m.fromMap(parameters);
ProcessInstance<?> processInstance = p.createInstance(m);
processInstance.start();
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
List<WorkItem> workItems = processInstance.workItems(securityPolicy);
assertEquals(1, workItems.size());
WorkItem wi = workItems.get(0);
assertEquals("FirstTask", wi.getName());
assertEquals(Active.ID, wi.getPhase());
assertEquals(Active.STATUS, wi.getPhaseStatus());
String workItemId = workItems.get(0).getId();
processInstance.transitionWorkItem(workItemId, new HumanTaskTransition(Complete.ID, null, securityPolicy));
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
workItems = processInstance.workItems(securityPolicy);
assertEquals(1, workItems.size());
wi = workItems.get(0);
assertEquals("SecondTask", wi.getName());
assertEquals(Active.ID, wi.getPhase());
assertEquals(Active.STATUS, wi.getPhaseStatus());
processInstance.transitionWorkItem(workItems.get(0).getId(), new HumanTaskTransition(Complete.ID, null, securityPolicy));
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
}
use of org.jbpm.process.instance.impl.humantask.HumanTaskTransition in project kogito-runtimes by kiegroup.
the class UserTaskIT method testBasicUserTaskProcessClaimAndCompleteWrongUser.
@Test
public void testBasicUserTaskProcessClaimAndCompleteWrongUser() throws Exception {
Application app = generateCodeProcessesOnly("usertask/UserTasksProcess.bpmn2");
assertThat(app).isNotNull();
Process<? extends Model> p = app.get(Processes.class).processById("UserTasksProcess");
Model m = p.createModel();
Map<String, Object> parameters = new HashMap<>();
m.fromMap(parameters);
ProcessInstance<?> processInstance = p.createInstance(m);
processInstance.start();
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
List<WorkItem> workItems = processInstance.workItems(securityPolicy);
assertEquals(1, workItems.size());
WorkItem wi = workItems.get(0);
assertEquals("FirstTask", wi.getName());
assertEquals(Active.ID, wi.getPhase());
assertEquals(Active.STATUS, wi.getPhaseStatus());
assertEquals(0, wi.getResults().size());
final String wiId = wi.getId();
IdentityProvider identity = new StaticIdentityProvider("kelly");
// if user that is not authorized to work on work item both listing and getting by id should apply it
List<WorkItem> securedWorkItems = processInstance.workItems(SecurityPolicy.of(identity));
assertEquals(0, securedWorkItems.size());
assertThrows(WorkItemNotFoundException.class, () -> processInstance.workItem(wiId, SecurityPolicy.of(identity)));
assertThrows(NotAuthorizedException.class, () -> processInstance.transitionWorkItem(wiId, new HumanTaskTransition(Claim.ID, null, identity)));
assertThrows(NotAuthorizedException.class, () -> processInstance.completeWorkItem(wiId, null, SecurityPolicy.of(identity)));
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
workItems = processInstance.workItems(securityPolicy);
assertEquals(1, workItems.size());
wi = workItems.get(0);
assertEquals("FirstTask", wi.getName());
assertEquals(Active.ID, wi.getPhase());
assertEquals(Active.STATUS, wi.getPhaseStatus());
assertEquals(0, wi.getResults().size());
IdentityProvider identityCorrect = new StaticIdentityProvider("john");
processInstance.transitionWorkItem(workItems.get(0).getId(), new HumanTaskTransition(Complete.ID, null, identityCorrect));
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
workItems = processInstance.workItems(securityPolicy);
assertEquals(1, workItems.size());
wi = workItems.get(0);
assertEquals("SecondTask", wi.getName());
assertEquals(Active.ID, wi.getPhase());
assertEquals(Active.STATUS, wi.getPhaseStatus());
assertEquals(0, wi.getResults().size());
processInstance.abort();
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ABORTED);
}
Aggregations