use of org.kie.kogito.services.identity.StaticIdentityProvider in project kogito-runtimes by kiegroup.
the class PublishEventIT method testBasicUserTaskProcessAbort.
@Test
public void testBasicUserTaskProcessAbort() 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);
TestEventPublisher publisher = new TestEventPublisher();
app.unitOfWorkManager().eventManager().setService("http://myhost");
app.unitOfWorkManager().eventManager().addPublisher(publisher);
UnitOfWork uow = app.unitOfWorkManager().newUnitOfWork();
uow.start();
ProcessInstance<?> processInstance = p.createInstance(m);
processInstance.start();
uow.end();
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
List<DataEvent<?>> events = publisher.extract();
assertThat(events).isNotNull().hasSize(2);
ProcessInstanceEventBody body = assertProcessInstanceEvent(events.get(0), "UserTasksProcess", "UserTasksProcess", 1);
assertThat(body.getNodeInstances()).hasSize(2).extractingResultOf("getNodeType").contains("StartNode", "HumanTaskNode");
assertThat(body.getNodeInstances()).extractingResultOf("getTriggerTime").allMatch(v -> v != null);
// human task is active thus null for leave time
assertThat(body.getNodeInstances()).extractingResultOf("getLeaveTime").containsNull();
assertUserTaskInstanceEvent(events.get(1), "FirstTask", null, "1", "Ready", "UserTasksProcess", "First Task");
List<WorkItem> workItems = processInstance.workItems(SecurityPolicy.of(new StaticIdentityProvider("john")));
assertEquals(1, workItems.size());
assertEquals("FirstTask", workItems.get(0).getName());
uow = app.unitOfWorkManager().newUnitOfWork();
uow.start();
processInstance.abort();
uow.end();
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ABORTED);
events = publisher.extract();
assertThat(events).isNotNull().hasSize(2);
body = assertProcessInstanceEvent(events.get(0), "UserTasksProcess", "UserTasksProcess", ProcessInstance.STATE_ABORTED);
assertThat(body.getNodeInstances()).hasSize(1).extractingResultOf("getNodeType").contains("HumanTaskNode");
assertThat(body.getNodeInstances()).extractingResultOf("getTriggerTime").allMatch(v -> v != null);
assertThat(body.getNodeInstances()).extractingResultOf("getLeaveTime").allMatch(v -> v != null);
assertUserTaskInstanceEvent(events.get(1), "FirstTask", null, "1", "Aborted", "UserTasksProcess", "First Task");
}
use of org.kie.kogito.services.identity.StaticIdentityProvider 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);
}
use of org.kie.kogito.services.identity.StaticIdentityProvider in project kogito-runtimes by kiegroup.
the class MockCacheProcessInstancesTest method testBasicFlowWithError.
private void testBasicFlowWithError(Consumer<ProcessInstance<BpmnVariables>> op) {
BpmnProcess process = BpmnProcess.from(new ClassPathResource("BPMN2-UserTask-Script.bpmn2")).get(0);
// workaround as BpmnProcess does not compile the scripts but just reads the xml
for (Node node : ((WorkflowProcess) process.get()).getNodes()) {
if (node instanceof ActionNode) {
DroolsAction a = ((ActionNode) node).getAction();
a.setMetaData("Action", (Action) kcontext -> {
System.out.println("The variable value is " + kcontext.getVariable("s") + " about to call toString on it");
kcontext.getVariable("s").toString();
});
}
}
process.setProcessInstancesFactory(new CacheProcessInstancesFactory(cacheManager));
process.configure();
ProcessInstance<BpmnVariables> processInstance = process.createInstance(BpmnVariables.create());
processInstance.start();
assertThat(processInstance.status()).isEqualTo(STATE_ERROR);
Optional<ProcessError> errorOp = processInstance.error();
assertThat(errorOp).isPresent();
assertThat(errorOp.get().failedNodeId()).isEqualTo("ScriptTask_1");
assertThat(errorOp.get().errorMessage()).isNotNull().contains("java.lang.NullPointerException");
op.accept(processInstance);
assertThat(processInstance.error()).isNotPresent();
WorkItem workItem = processInstance.workItems(SecurityPolicy.of(new StaticIdentityProvider("john"))).get(0);
assertThat(workItem).isNotNull();
assertThat(workItem.getParameters().get("ActorId")).isEqualTo("john");
processInstance.completeWorkItem(workItem.getId(), null, SecurityPolicy.of(new StaticIdentityProvider("john")));
assertThat(processInstance.status()).isEqualTo(STATE_COMPLETED);
}
use of org.kie.kogito.services.identity.StaticIdentityProvider in project kogito-runtimes by kiegroup.
the class MockCacheProcessInstancesTest method testBasicFlow.
@Test
public void testBasicFlow() {
BpmnProcess process = BpmnProcess.from(new ClassPathResource("BPMN2-UserTask.bpmn2")).get(0);
process.setProcessInstancesFactory(new CacheProcessInstancesFactory(cacheManager));
process.configure();
ProcessInstance<BpmnVariables> processInstance = process.createInstance(BpmnVariables.create(Collections.singletonMap("test", "test")));
processInstance.start();
assertThat(processInstance.status()).isEqualTo(STATE_ACTIVE);
WorkItem workItem = processInstance.workItems(SecurityPolicy.of(new StaticIdentityProvider("john"))).get(0);
assertThat(workItem).isNotNull();
assertThat(workItem.getParameters().get("ActorId")).isEqualTo("john");
processInstance.completeWorkItem(workItem.getId(), null, SecurityPolicy.of(new StaticIdentityProvider("john")));
assertThat(processInstance.status()).isEqualTo(STATE_COMPLETED);
}
use of org.kie.kogito.services.identity.StaticIdentityProvider in project kogito-runtimes by kiegroup.
the class ActivityGenerationModelTest method testUserTaskProcess.
@Test
public void testUserTaskProcess() throws Exception {
BpmnProcess process = BpmnProcess.from(new ClassPathResource("BPMN2-UserTask.bpmn2")).get(0);
ProcessMetaData metaData = ProcessToExecModelGenerator.INSTANCE.generate((WorkflowProcess) process.get());
String content = metaData.getGeneratedClassModel().toString();
assertThat(content).isNotNull();
log(content);
Map<String, String> classData = new HashMap<>();
classData.put("org.drools.bpmn2.UserTaskProcess", content);
TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
Map<String, BpmnProcess> processes = createProcesses(classData, Collections.singletonMap("Human Task", workItemHandler));
ProcessInstance<BpmnVariables> processInstance = processes.get("UserTask").createInstance();
processInstance.start();
assertEquals(STATE_ACTIVE, processInstance.status());
KogitoWorkItem workItem = workItemHandler.getWorkItem();
assertNotNull(workItem);
assertEquals("john", workItem.getParameter("ActorId"));
processInstance.completeWorkItem(workItem.getStringId(), null, SecurityPolicy.of(new StaticIdentityProvider("john")));
assertEquals(STATE_COMPLETED, processInstance.status());
}
Aggregations