Search in sources :

Example 16 with ProcessInstance

use of org.activiti.api.process.model.ProcessInstance in project Activiti by Activiti.

the class DemoApplication method processText.

@Scheduled(initialDelay = 1000, fixedDelay = 1000)
public void processText() {
    securityUtil.logInAs("system");
    String content = pickRandomString();
    SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yy HH:mm:ss");
    logger.info("> Processing content: " + content + " at " + formatter.format(new Date()));
    ProcessInstance processInstance = processRuntime.start(ProcessPayloadBuilder.start().withProcessDefinitionKey("categorizeProcess").withName("Processing Content: " + content).withVariable("content", content).build());
    logger.info(">>> Created Process Instance: " + processInstance);
}
Also used : ProcessInstance(org.activiti.api.process.model.ProcessInstance) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) Scheduled(org.springframework.scheduling.annotation.Scheduled)

Example 17 with ProcessInstance

use of org.activiti.api.process.model.ProcessInstance in project Activiti by Activiti.

the class ProcessRuntimeBPMNMessageIT method shouldTestCatchMessageExpressionWithVariableMappingExtensions.

@Test
public void shouldTestCatchMessageExpressionWithVariableMappingExtensions() {
    // when
    ProcessInstance process = processRuntime.start(ProcessPayloadBuilder.start().withBusinessKey("businessKey").withProcessDefinitionKey("testCatchMessageExpression").build());
    // then
    List<VariableInstance> variables = processRuntime.variables(ProcessPayloadBuilder.variables().withProcessInstance(process).build());
    assertThat(variables).extracting(VariableInstance::getName, VariableInstance::getValue).containsOnly(tuple("intermediate_var", ""), tuple("inter_message_var", "check2"));
    // when
    Page<Task> tasks = taskRuntime.tasks(Pageable.of(0, 2), TaskPayloadBuilder.tasks().withProcessInstanceId(process.getId()).build());
    // then
    assertThat(tasks.getContent()).hasSize(1);
    String taskId = tasks.getContent().get(0).getId();
    // when
    taskRuntime.complete(TaskPayloadBuilder.complete().withTaskId(taskId).withVariable("Text0739ze", "foo").build());
    // then
    variables = processRuntime.variables(ProcessPayloadBuilder.variables().withProcessInstance(process).build());
    assertThat(variables).extracting(VariableInstance::getName, VariableInstance::getValue).containsOnly(tuple("intermediate_var", "foo"), tuple("inter_message_var", "check2"));
    // when
    processRuntime.receive(MessagePayloadBuilder.receive("intermediate-catch-message-check2").withCorrelationKey("foo").build());
    // then
    tasks = taskRuntime.tasks(Pageable.of(0, 2), TaskPayloadBuilder.tasks().withProcessInstanceId(process.getId()).build());
    assertThat(tasks.getContent()).hasSize(1);
    taskId = tasks.getContent().get(0).getId();
    // then
    taskRuntime.complete(TaskPayloadBuilder.complete().withTaskId(taskId).build());
    // then
    assertThat(MessageTestConfiguration.messageEvents).isNotEmpty().extracting(BPMNMessageEvent::getEventType, BPMNMessageEvent::getProcessDefinitionId, BPMNMessageEvent::getProcessInstanceId, event -> event.getEntity().getProcessDefinitionId(), event -> event.getEntity().getProcessInstanceId(), event -> event.getEntity().getMessagePayload().getName(), event -> event.getEntity().getMessagePayload().getCorrelationKey(), event -> event.getEntity().getMessagePayload().getBusinessKey(), event -> event.getEntity().getMessagePayload().getVariables()).contains(Tuple.tuple(BPMNMessageEvent.MessageEvents.MESSAGE_WAITING, process.getProcessDefinitionId(), process.getId(), process.getProcessDefinitionId(), process.getId(), "intermediate-catch-message-check2", "foo", process.getBusinessKey(), null), Tuple.tuple(BPMNMessageEvent.MessageEvents.MESSAGE_RECEIVED, process.getProcessDefinitionId(), process.getId(), process.getProcessDefinitionId(), process.getId(), "intermediate-catch-message-check2", "foo", process.getBusinessKey(), null));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) Pageable(org.activiti.api.runtime.shared.query.Pageable) TaskBaseRuntime(org.activiti.spring.boot.tasks.TaskBaseRuntime) ProcessRuntimeEvent(org.activiti.api.process.model.events.ProcessRuntimeEvent) Task(org.activiti.api.task.model.Task) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) SecurityUtil(org.activiti.spring.boot.security.util.SecurityUtil) Autowired(org.springframework.beans.factory.annotation.Autowired) MessagePayloadBuilder(org.activiti.api.process.model.builders.MessagePayloadBuilder) ProcessPayloadBuilder(org.activiti.api.process.model.builders.ProcessPayloadBuilder) ProcessRuntimeEventListener(org.activiti.api.process.runtime.events.listener.ProcessRuntimeEventListener) ArrayList(java.util.ArrayList) ProcessRuntime(org.activiti.api.process.runtime.ProcessRuntime) LocalEventSource(org.activiti.test.LocalEventSource) Collections.singletonMap(java.util.Collections.singletonMap) Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) MessageSubscriptionEvent(org.activiti.api.process.model.events.MessageSubscriptionEvent) TaskRuntimeEvent(org.activiti.api.task.model.events.TaskRuntimeEvent) StartMessageDeploymentDefinition(org.activiti.api.process.model.StartMessageDeploymentDefinition) TaskRuntime(org.activiti.api.task.runtime.TaskRuntime) ProcessInstance(org.activiti.api.process.model.ProcessInstance) Tuple(org.assertj.core.groups.Tuple) Assertions.tuple(org.assertj.core.api.Assertions.tuple) TaskPayloadBuilder(org.activiti.api.task.model.builders.TaskPayloadBuilder) TestComponent(org.springframework.boot.test.context.TestComponent) RuntimeEvent(org.activiti.api.model.shared.event.RuntimeEvent) StartMessageDeployedEvents(org.activiti.api.runtime.event.impl.StartMessageDeployedEvents) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) MessageTestConfiguration(org.activiti.spring.boot.MessageTestConfiguration) Import(org.springframework.context.annotation.Import) EventListener(org.springframework.context.event.EventListener) Page(org.activiti.api.runtime.shared.query.Page) MessageSubscriptionCancelledEvent(org.activiti.api.process.model.events.MessageSubscriptionCancelledEvent) Test(org.junit.jupiter.api.Test) StartMessageSubscription(org.activiti.api.process.model.StartMessageSubscription) List(java.util.List) AfterEach(org.junit.jupiter.api.AfterEach) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) ProcessCleanUpUtil(org.activiti.spring.boot.test.util.ProcessCleanUpUtil) VariableInstance(org.activiti.api.model.shared.model.VariableInstance) StartMessageDeployedEvent(org.activiti.api.process.model.events.StartMessageDeployedEvent) BPMNMessageEvent(org.activiti.api.process.model.events.BPMNMessageEvent) Task(org.activiti.api.task.model.Task) ProcessInstance(org.activiti.api.process.model.ProcessInstance) VariableInstance(org.activiti.api.model.shared.model.VariableInstance) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 18 with ProcessInstance

use of org.activiti.api.process.model.ProcessInstance in project Activiti by Activiti.

the class ProcessRuntimeBPMNMessageIT method shouldReceiveSubprocessMessageWithCorrelationKey.

@Test
public void shouldReceiveSubprocessMessageWithCorrelationKey() {
    ProcessInstance process = processRuntime.start(ProcessPayloadBuilder.start().withBusinessKey("businessKey").withVariable("correlationKey", "foo").withProcessDefinitionKey(SUBPROCESS_MESSAGE).build());
    // when
    processRuntime.receive(MessagePayloadBuilder.receive(TEST_MESSAGE).withVariable("key", "value").withCorrelationKey("foo").build());
    // then
    assertThat(MessageTestConfiguration.messageEvents).isNotEmpty().extracting(BPMNMessageEvent::getEventType, BPMNMessageEvent::getProcessDefinitionId, BPMNMessageEvent::getProcessInstanceId, event -> event.getEntity().getProcessDefinitionId(), event -> event.getEntity().getProcessInstanceId(), event -> event.getEntity().getMessagePayload().getName(), event -> event.getEntity().getMessagePayload().getCorrelationKey(), event -> event.getEntity().getMessagePayload().getBusinessKey(), event -> event.getEntity().getMessagePayload().getVariables()).contains(Tuple.tuple(BPMNMessageEvent.MessageEvents.MESSAGE_WAITING, process.getProcessDefinitionId(), process.getId(), process.getProcessDefinitionId(), process.getId(), "testMessage", "foo", process.getBusinessKey(), null), Tuple.tuple(BPMNMessageEvent.MessageEvents.MESSAGE_RECEIVED, process.getProcessDefinitionId(), process.getId(), process.getProcessDefinitionId(), process.getId(), "testMessage", "foo", process.getBusinessKey(), singletonMap("key", "value")));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) Pageable(org.activiti.api.runtime.shared.query.Pageable) TaskBaseRuntime(org.activiti.spring.boot.tasks.TaskBaseRuntime) ProcessRuntimeEvent(org.activiti.api.process.model.events.ProcessRuntimeEvent) Task(org.activiti.api.task.model.Task) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) SecurityUtil(org.activiti.spring.boot.security.util.SecurityUtil) Autowired(org.springframework.beans.factory.annotation.Autowired) MessagePayloadBuilder(org.activiti.api.process.model.builders.MessagePayloadBuilder) ProcessPayloadBuilder(org.activiti.api.process.model.builders.ProcessPayloadBuilder) ProcessRuntimeEventListener(org.activiti.api.process.runtime.events.listener.ProcessRuntimeEventListener) ArrayList(java.util.ArrayList) ProcessRuntime(org.activiti.api.process.runtime.ProcessRuntime) LocalEventSource(org.activiti.test.LocalEventSource) Collections.singletonMap(java.util.Collections.singletonMap) Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) MessageSubscriptionEvent(org.activiti.api.process.model.events.MessageSubscriptionEvent) TaskRuntimeEvent(org.activiti.api.task.model.events.TaskRuntimeEvent) StartMessageDeploymentDefinition(org.activiti.api.process.model.StartMessageDeploymentDefinition) TaskRuntime(org.activiti.api.task.runtime.TaskRuntime) ProcessInstance(org.activiti.api.process.model.ProcessInstance) Tuple(org.assertj.core.groups.Tuple) Assertions.tuple(org.assertj.core.api.Assertions.tuple) TaskPayloadBuilder(org.activiti.api.task.model.builders.TaskPayloadBuilder) TestComponent(org.springframework.boot.test.context.TestComponent) RuntimeEvent(org.activiti.api.model.shared.event.RuntimeEvent) StartMessageDeployedEvents(org.activiti.api.runtime.event.impl.StartMessageDeployedEvents) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) MessageTestConfiguration(org.activiti.spring.boot.MessageTestConfiguration) Import(org.springframework.context.annotation.Import) EventListener(org.springframework.context.event.EventListener) Page(org.activiti.api.runtime.shared.query.Page) MessageSubscriptionCancelledEvent(org.activiti.api.process.model.events.MessageSubscriptionCancelledEvent) Test(org.junit.jupiter.api.Test) StartMessageSubscription(org.activiti.api.process.model.StartMessageSubscription) List(java.util.List) AfterEach(org.junit.jupiter.api.AfterEach) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) ProcessCleanUpUtil(org.activiti.spring.boot.test.util.ProcessCleanUpUtil) VariableInstance(org.activiti.api.model.shared.model.VariableInstance) StartMessageDeployedEvent(org.activiti.api.process.model.events.StartMessageDeployedEvent) BPMNMessageEvent(org.activiti.api.process.model.events.BPMNMessageEvent) ProcessInstance(org.activiti.api.process.model.ProcessInstance) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 19 with ProcessInstance

use of org.activiti.api.process.model.ProcessInstance in project Activiti by Activiti.

the class ProcessRuntimeBPMNMessageIT method should_not_cancelTask_when_nonInterruptedMessageReceived.

@Test
public void should_not_cancelTask_when_nonInterruptedMessageReceived() {
    ProcessInstance processInstance = processRuntime.start(ProcessPayloadBuilder.start().withBusinessKey("businessKey").withVariable("correlationKey", "correlationKey").withProcessDefinitionKey("messageNonInterruptingSubProcess").build());
    List<Task> allTasks = taskRuntime.tasks(Pageable.of(0, 2), TaskPayloadBuilder.tasks().withProcessInstanceId(processInstance.getId()).build()).getContent();
    assertThat(allTasks.size()).isEqualTo(1);
    assertThat(MessageTestConfiguration.messageEvents).isNotEmpty().extracting(BPMNMessageEvent::getEventType, BPMNMessageEvent::getProcessDefinitionId, BPMNMessageEvent::getProcessInstanceId, event -> event.getEntity().getProcessDefinitionId(), event -> event.getEntity().getProcessInstanceId(), event -> event.getEntity().getMessagePayload().getName(), event -> event.getEntity().getMessagePayload().getCorrelationKey(), event -> event.getEntity().getMessagePayload().getBusinessKey(), event -> event.getEntity().getMessagePayload().getVariables()).contains(Tuple.tuple(BPMNMessageEvent.MessageEvents.MESSAGE_WAITING, processInstance.getProcessDefinitionId(), processInstance.getId(), processInstance.getProcessDefinitionId(), processInstance.getId(), "nonInterruptedMessage", "correlationKey", processInstance.getBusinessKey(), null));
    assertThat(localEventSource.getEvents()).filteredOn(event -> event.getEventType().equals(TaskRuntimeEvent.TaskEvents.TASK_ASSIGNED)).extracting(RuntimeEvent::getEventType, event -> ((Task) event.getEntity()).getName()).containsExactly(tuple(TaskRuntimeEvent.TaskEvents.TASK_ASSIGNED, allTasks.get(0).getName()));
    // sending the Non Interrupted Start Message to process
    processRuntime.receive(MessagePayloadBuilder.receive("nonInterruptedMessage").withCorrelationKey("correlationKey").build());
    // then
    assertThat(MessageTestConfiguration.messageEvents).isNotEmpty().extracting(BPMNMessageEvent::getEventType, BPMNMessageEvent::getProcessDefinitionId, BPMNMessageEvent::getProcessInstanceId, event -> event.getEntity().getProcessDefinitionId(), event -> event.getEntity().getProcessInstanceId(), event -> event.getEntity().getMessagePayload().getName(), event -> event.getEntity().getMessagePayload().getCorrelationKey(), event -> event.getEntity().getMessagePayload().getBusinessKey(), event -> event.getEntity().getMessagePayload().getVariables()).contains(Tuple.tuple(BPMNMessageEvent.MessageEvents.MESSAGE_WAITING, processInstance.getProcessDefinitionId(), processInstance.getId(), processInstance.getProcessDefinitionId(), processInstance.getId(), "nonInterruptedMessage", "correlationKey", processInstance.getBusinessKey(), null), Tuple.tuple(BPMNMessageEvent.MessageEvents.MESSAGE_RECEIVED, processInstance.getProcessDefinitionId(), processInstance.getId(), processInstance.getProcessDefinitionId(), processInstance.getId(), "nonInterruptedMessage", "correlationKey", processInstance.getBusinessKey(), null));
    assertThat(taskBaseRuntime.getTasksByProcessInstanceId(processInstance.getId()).size()).isEqualTo(1);
    assertThat(localEventSource.getEvents()).filteredOn(event -> event.getEventType().equals(TaskRuntimeEvent.TaskEvents.TASK_ASSIGNED)).extracting(RuntimeEvent::getEventType, event -> ((Task) event.getEntity()).getName()).containsExactly(tuple(TaskRuntimeEvent.TaskEvents.TASK_ASSIGNED, allTasks.get(0).getName()));
    localEventSource.clearEvents();
    taskBaseRuntime.completeTask(allTasks.get(0).getId());
    assertThat(localEventSource.getEvents()).filteredOn(event -> event.getEventType().equals(TaskRuntimeEvent.TaskEvents.TASK_COMPLETED)).extracting(RuntimeEvent::getEventType, event -> ((Task) event.getEntity()).getName()).containsExactly(tuple(TaskRuntimeEvent.TaskEvents.TASK_COMPLETED, allTasks.get(0).getName()));
    assertThat(localEventSource.getEvents()).extracting(RuntimeEvent::getEventType, RuntimeEvent::getProcessInstanceId).contains(tuple(ProcessRuntimeEvent.ProcessEvents.PROCESS_COMPLETED, processInstance.getId()));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) Pageable(org.activiti.api.runtime.shared.query.Pageable) TaskBaseRuntime(org.activiti.spring.boot.tasks.TaskBaseRuntime) ProcessRuntimeEvent(org.activiti.api.process.model.events.ProcessRuntimeEvent) Task(org.activiti.api.task.model.Task) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) SecurityUtil(org.activiti.spring.boot.security.util.SecurityUtil) Autowired(org.springframework.beans.factory.annotation.Autowired) MessagePayloadBuilder(org.activiti.api.process.model.builders.MessagePayloadBuilder) ProcessPayloadBuilder(org.activiti.api.process.model.builders.ProcessPayloadBuilder) ProcessRuntimeEventListener(org.activiti.api.process.runtime.events.listener.ProcessRuntimeEventListener) ArrayList(java.util.ArrayList) ProcessRuntime(org.activiti.api.process.runtime.ProcessRuntime) LocalEventSource(org.activiti.test.LocalEventSource) Collections.singletonMap(java.util.Collections.singletonMap) Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) MessageSubscriptionEvent(org.activiti.api.process.model.events.MessageSubscriptionEvent) TaskRuntimeEvent(org.activiti.api.task.model.events.TaskRuntimeEvent) StartMessageDeploymentDefinition(org.activiti.api.process.model.StartMessageDeploymentDefinition) TaskRuntime(org.activiti.api.task.runtime.TaskRuntime) ProcessInstance(org.activiti.api.process.model.ProcessInstance) Tuple(org.assertj.core.groups.Tuple) Assertions.tuple(org.assertj.core.api.Assertions.tuple) TaskPayloadBuilder(org.activiti.api.task.model.builders.TaskPayloadBuilder) TestComponent(org.springframework.boot.test.context.TestComponent) RuntimeEvent(org.activiti.api.model.shared.event.RuntimeEvent) StartMessageDeployedEvents(org.activiti.api.runtime.event.impl.StartMessageDeployedEvents) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) MessageTestConfiguration(org.activiti.spring.boot.MessageTestConfiguration) Import(org.springframework.context.annotation.Import) EventListener(org.springframework.context.event.EventListener) Page(org.activiti.api.runtime.shared.query.Page) MessageSubscriptionCancelledEvent(org.activiti.api.process.model.events.MessageSubscriptionCancelledEvent) Test(org.junit.jupiter.api.Test) StartMessageSubscription(org.activiti.api.process.model.StartMessageSubscription) List(java.util.List) AfterEach(org.junit.jupiter.api.AfterEach) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) ProcessCleanUpUtil(org.activiti.spring.boot.test.util.ProcessCleanUpUtil) VariableInstance(org.activiti.api.model.shared.model.VariableInstance) StartMessageDeployedEvent(org.activiti.api.process.model.events.StartMessageDeployedEvent) BPMNMessageEvent(org.activiti.api.process.model.events.BPMNMessageEvent) Task(org.activiti.api.task.model.Task) ProcessInstance(org.activiti.api.process.model.ProcessInstance) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 20 with ProcessInstance

use of org.activiti.api.process.model.ProcessInstance in project Activiti by Activiti.

the class ProcessRuntimeBPMNSignalReceivedIT method shouldGetSignalReceivedEventWithVariables.

@Test
public void shouldGetSignalReceivedEventWithVariables() {
    // given
    securityUtil.logInAs("user");
    // when
    ProcessInstance process = processRuntime.start(ProcessPayloadBuilder.start().withProcessDefinitionKey(PROCESS_WITH_BOUNDARY_SIGNAL).withVariable("name", "peter").build());
    SignalPayload signalPayload = ProcessPayloadBuilder.signal().withName("go").withVariable("signal_variable", "test").build();
    processRuntime.signal(signalPayload);
    // then
    assertThat(listener.getSignalReceivedEvents()).isNotEmpty().hasSize(1);
    BPMNSignalReceivedEvent event = listener.getSignalReceivedEvents().iterator().next();
    assertThat(event.getEntity()).isNotNull();
    assertThat(event.getProcessInstanceId()).isEqualTo(process.getId());
    assertThat(event.getEntity().getSignalPayload()).isNotNull();
    assertThat(event.getEntity().getSignalPayload().getName()).isEqualTo("go");
    assertThat(event.getEntity().getSignalPayload().getVariables().size()).isEqualTo(1);
    assertThat(event.getEntity().getSignalPayload().getVariables().get("signal_variable")).isEqualTo("test");
}
Also used : BPMNSignalReceivedEvent(org.activiti.api.process.model.events.BPMNSignalReceivedEvent) ProcessInstance(org.activiti.api.process.model.ProcessInstance) SignalPayload(org.activiti.api.process.model.payloads.SignalPayload) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

ProcessInstance (org.activiti.api.process.model.ProcessInstance)154 Test (org.junit.jupiter.api.Test)123 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)116 Task (org.activiti.api.task.model.Task)73 AfterEach (org.junit.jupiter.api.AfterEach)57 VariableInstance (org.activiti.api.model.shared.model.VariableInstance)54 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)39 Autowired (org.springframework.beans.factory.annotation.Autowired)39 BeforeEach (org.junit.jupiter.api.BeforeEach)38 Page (org.activiti.api.runtime.shared.query.Page)37 SecurityUtil (org.activiti.spring.boot.security.util.SecurityUtil)37 ProcessCleanUpUtil (org.activiti.spring.boot.test.util.ProcessCleanUpUtil)37 Import (org.springframework.context.annotation.Import)35 List (java.util.List)33 Assertions.tuple (org.assertj.core.api.Assertions.tuple)33 Assertions.catchThrowable (org.assertj.core.api.Assertions.catchThrowable)31 LocalEventSource (org.activiti.test.LocalEventSource)30 RuntimeEvent (org.activiti.api.model.shared.event.RuntimeEvent)29 ProcessRuntimeEvent (org.activiti.api.process.model.events.ProcessRuntimeEvent)29 TaskRuntimeEvent (org.activiti.api.task.model.events.TaskRuntimeEvent)29