Search in sources :

Example 1 with ProcessInstance

use of org.kie.kogito.process.ProcessInstance in project kogito-runtimes by kiegroup.

the class EventImplTest method setup.

@BeforeEach
void setup() {
    application = mock(Application.class);
    when(application.unitOfWorkManager()).thenReturn(new DefaultUnitOfWorkManager(new CollectingUnitOfWorkFactory()));
    process = mock(Process.class);
    processInstances = mock(ProcessInstances.class);
    processInstance = mock(ProcessInstance.class);
    when(process.instances()).thenReturn(processInstances);
    when(processInstances.findById(Mockito.anyString())).thenReturn(Optional.of(processInstance));
    when(process.createInstance(Mockito.any(DummyModel.class))).thenReturn(processInstance);
    processService = mock(ProcessService.class);
    executor = Executors.newSingleThreadExecutor();
}
Also used : ProcessInstances(org.kie.kogito.process.ProcessInstances) CollectingUnitOfWorkFactory(org.kie.kogito.services.uow.CollectingUnitOfWorkFactory) Process(org.kie.kogito.process.Process) ProcessInstance(org.kie.kogito.process.ProcessInstance) ProcessService(org.kie.kogito.process.ProcessService) Application(org.kie.kogito.Application) DefaultUnitOfWorkManager(org.kie.kogito.services.uow.DefaultUnitOfWorkManager) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with ProcessInstance

use of org.kie.kogito.process.ProcessInstance in project kogito-runtimes by kiegroup.

the class ProcessInstanceMarshallerService method unmarshallProcessInstance.

public ProcessInstance<?> unmarshallProcessInstance(byte[] data, Process<?> process, boolean readOnly) {
    try (ByteArrayInputStream bais = new ByteArrayInputStream(data)) {
        MarshallerReaderContext context = processInstanceMarshallerFactory.newReaderContext(bais);
        context.set(MarshallerContextName.MARSHALLER_PROCESS, process);
        context.set(MarshallerContextName.MARSHALLER_INSTANCE_READ_ONLY, readOnly);
        setupEnvironment(context);
        org.kie.kogito.serialization.process.ProcessInstanceMarshaller marshaller = processInstanceMarshallerFactory.newKogitoProcessInstanceMarshaller();
        return (ProcessInstance<?>) marshaller.readProcessInstance(context);
    } catch (Exception e) {
        throw new ProcessInstanceMarshallerException("Error while unmarshalling process instance", e);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) AbstractProcessInstance(org.kie.kogito.process.impl.AbstractProcessInstance) ProcessInstance(org.kie.kogito.process.ProcessInstance)

Example 3 with ProcessInstance

use of org.kie.kogito.process.ProcessInstance in project kogito-runtimes by kiegroup.

the class PublishEventIT method testProcessWithMilestoneEvents.

@Test
public void testProcessWithMilestoneEvents() throws Exception {
    Application app = generateCodeProcessesOnly("cases/milestones/SimpleMilestone.bpmn");
    assertThat(app).isNotNull();
    TestEventPublisher publisher = new TestEventPublisher();
    app.unitOfWorkManager().eventManager().setService("http://myhost");
    app.unitOfWorkManager().eventManager().addPublisher(publisher);
    UnitOfWork uow = app.unitOfWorkManager().newUnitOfWork();
    uow.start();
    Process<? extends Model> p = app.get(Processes.class).processById("TestCase.SimpleMilestone");
    ProcessInstance<?> processInstance = p.createInstance(p.createModel());
    processInstance.start();
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
    uow.end();
    List<DataEvent<?>> events = publisher.extract();
    assertThat(events).isNotNull().hasSize(1);
    DataEvent<?> event = events.get(0);
    assertThat(event).isInstanceOf(ProcessInstanceDataEvent.class);
    ProcessInstanceDataEvent processDataEvent = (ProcessInstanceDataEvent) event;
    assertThat(processDataEvent.getKogitoProcessinstanceId()).isNotNull();
    assertThat(processDataEvent.getKogitoParentProcessinstanceId()).isNull();
    assertThat(processDataEvent.getKogitoRootProcessinstanceId()).isNull();
    assertThat(processDataEvent.getKogitoProcessId()).isEqualTo("TestCase.SimpleMilestone");
    assertThat(processDataEvent.getKogitoProcessinstanceState()).isEqualTo("2");
    assertThat(processDataEvent.getSource().toString()).isEqualTo("http://myhost/SimpleMilestone");
    Set<MilestoneEventBody> milestones = ((ProcessInstanceDataEvent) event).getData().getMilestones();
    assertThat(milestones).hasSize(2).extracting(e -> e.getName(), e -> e.getStatus()).containsExactlyInAnyOrder(tuple("AutoStartMilestone", Status.COMPLETED.name()), tuple("SimpleMilestone", Status.COMPLETED.name()));
}
Also used : UnitOfWork(org.kie.kogito.uow.UnitOfWork) ZonedDateTime(java.time.ZonedDateTime) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) UserTaskInstanceEventBody(org.kie.kogito.services.event.impl.UserTaskInstanceEventBody) HashMap(java.util.HashMap) Status(org.kie.kogito.process.flexible.ItemDescription.Status) Person(org.kie.kogito.codegen.data.Person) ArrayList(java.util.ArrayList) AbstractCodegenIT(org.kie.kogito.codegen.AbstractCodegenIT) VariableInstanceEventBody(org.kie.kogito.services.event.impl.VariableInstanceEventBody) Map(java.util.Map) UserTaskInstanceDataEvent(org.kie.kogito.services.event.UserTaskInstanceDataEvent) Process(org.kie.kogito.process.Process) ProcessInstanceDataEvent(org.kie.kogito.services.event.ProcessInstanceDataEvent) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Assertions.tuple(org.assertj.core.api.Assertions.tuple) StaticIdentityProvider(org.kie.kogito.services.identity.StaticIdentityProvider) Collection(java.util.Collection) Set(java.util.Set) MilestoneEventBody(org.kie.kogito.services.event.impl.MilestoneEventBody) ProcessInstanceEventBody(org.kie.kogito.services.event.impl.ProcessInstanceEventBody) SecurityPolicy(org.kie.kogito.auth.SecurityPolicy) Application(org.kie.kogito.Application) Test(org.junit.jupiter.api.Test) List(java.util.List) ProcessInstance(org.kie.kogito.process.ProcessInstance) Model(org.kie.kogito.Model) EventPublisher(org.kie.kogito.event.EventPublisher) ProcessError(org.kie.kogito.process.ProcessError) DataEvent(org.kie.kogito.event.DataEvent) VariableInstanceDataEvent(org.kie.kogito.services.event.VariableInstanceDataEvent) Processes(org.kie.kogito.process.Processes) Collections(java.util.Collections) WorkItem(org.kie.kogito.process.WorkItem) UnitOfWork(org.kie.kogito.uow.UnitOfWork) UserTaskInstanceDataEvent(org.kie.kogito.services.event.UserTaskInstanceDataEvent) ProcessInstanceDataEvent(org.kie.kogito.services.event.ProcessInstanceDataEvent) DataEvent(org.kie.kogito.event.DataEvent) VariableInstanceDataEvent(org.kie.kogito.services.event.VariableInstanceDataEvent) Processes(org.kie.kogito.process.Processes) MilestoneEventBody(org.kie.kogito.services.event.impl.MilestoneEventBody) ProcessInstanceDataEvent(org.kie.kogito.services.event.ProcessInstanceDataEvent) Application(org.kie.kogito.Application) Test(org.junit.jupiter.api.Test)

Example 4 with ProcessInstance

use of org.kie.kogito.process.ProcessInstance in project kogito-runtimes by kiegroup.

the class TimerEventIT method testStartTimerEventTimeCycle.

@Test
void testStartTimerEventTimeCycle() throws Exception {
    Application app = generateCodeProcessesOnly("timer/StartTimerCycle.bpmn2");
    assertThat(app).isNotNull();
    NodeLeftCountDownProcessEventListener listener = new NodeLeftCountDownProcessEventListener("timer fired", 2);
    app.config().get(ProcessConfig.class).processEventListeners().listeners().add(listener);
    Process<? extends Model> p = app.get(Processes.class).processById("defaultPackage.TimerProcess");
    // activate to schedule timers
    p.activate();
    boolean completed = listener.waitTillCompleted(5000);
    assertThat(completed).isTrue();
    Collection<?> instances = p.instances().values(ProcessInstanceReadMode.MUTABLE);
    assertThat(instances).hasSize(2);
    ProcessInstance<?> processInstance = (ProcessInstance<?>) instances.iterator().next();
    assertThat(processInstance).isNotNull();
    assertThat(processInstance.status()).isEqualTo(KogitoProcessInstance.STATE_ACTIVE);
    // deactivate to cancel timer, so there should be no more timers fired
    p.deactivate();
    // reset the listener to make sure nothing more is triggered
    listener.reset(1);
    completed = listener.waitTillCompleted(3000);
    assertThat(completed).isFalse();
    // same amount of instances should be active as before deactivation
    instances = p.instances().values(ProcessInstanceReadMode.MUTABLE);
    assertThat(instances).hasSize(2);
    // clean up by aborting all instances
    instances.forEach(i -> ((ProcessInstance<?>) i).abort());
    assertThat(p.instances().size()).isZero();
}
Also used : NodeLeftCountDownProcessEventListener(org.jbpm.test.util.NodeLeftCountDownProcessEventListener) ProcessConfig(org.kie.kogito.process.ProcessConfig) KogitoProcessInstance(org.kie.kogito.internal.process.runtime.KogitoProcessInstance) ProcessInstance(org.kie.kogito.process.ProcessInstance) Processes(org.kie.kogito.process.Processes) Application(org.kie.kogito.Application) Test(org.junit.jupiter.api.Test)

Example 5 with ProcessInstance

use of org.kie.kogito.process.ProcessInstance in project kogito-runtimes by kiegroup.

the class TimerEventIT method testStartTimerEvent.

@Test
void testStartTimerEvent() throws Exception {
    Application app = generateCodeProcessesOnly("timer/StartTimerDuration.bpmn2");
    assertThat(app).isNotNull();
    NodeLeftCountDownProcessEventListener listener = new NodeLeftCountDownProcessEventListener("timer fired", 1);
    app.config().get(ProcessConfig.class).processEventListeners().listeners().add(listener);
    Process<? extends Model> p = app.get(Processes.class).processById("defaultPackage.TimerProcess");
    // activate to schedule timers
    p.activate();
    boolean completed = listener.waitTillCompleted(5000);
    assertThat(completed).isTrue();
    Collection<?> instances = p.instances().values(ProcessInstanceReadMode.MUTABLE);
    assertThat(instances).hasSize(1);
    ProcessInstance<?> processInstance = (ProcessInstance<?>) instances.iterator().next();
    assertThat(processInstance).isNotNull();
    assertThat(processInstance.status()).isEqualTo(KogitoProcessInstance.STATE_ACTIVE);
    processInstance.abort();
    assertThat(processInstance.status()).isEqualTo(KogitoProcessInstance.STATE_ABORTED);
    assertThat(p.instances().size()).isZero();
}
Also used : NodeLeftCountDownProcessEventListener(org.jbpm.test.util.NodeLeftCountDownProcessEventListener) ProcessConfig(org.kie.kogito.process.ProcessConfig) KogitoProcessInstance(org.kie.kogito.internal.process.runtime.KogitoProcessInstance) ProcessInstance(org.kie.kogito.process.ProcessInstance) Processes(org.kie.kogito.process.Processes) Application(org.kie.kogito.Application) Test(org.junit.jupiter.api.Test)

Aggregations

ProcessInstance (org.kie.kogito.process.ProcessInstance)19 Test (org.junit.jupiter.api.Test)15 Application (org.kie.kogito.Application)10 Processes (org.kie.kogito.process.Processes)10 List (java.util.List)8 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)8 WorkItem (org.kie.kogito.process.WorkItem)8 HashMap (java.util.HashMap)7 ProcessInstances (org.kie.kogito.process.ProcessInstances)7 BpmnVariables (org.kie.kogito.process.bpmn2.BpmnVariables)7 Collections (java.util.Collections)6 ClassPathResource (org.drools.core.io.impl.ClassPathResource)6 ActionNode (org.jbpm.workflow.core.node.ActionNode)6 Model (org.kie.kogito.Model)6 SecurityPolicy (org.kie.kogito.auth.SecurityPolicy)6 KogitoProcessInstance (org.kie.kogito.internal.process.runtime.KogitoProcessInstance)6 Process (org.kie.kogito.process.Process)6 BpmnProcess (org.kie.kogito.process.bpmn2.BpmnProcess)6 StaticIdentityProvider (org.kie.kogito.services.identity.StaticIdentityProvider)6 ArrayList (java.util.ArrayList)5