Search in sources :

Example 11 with EventSubscriptionEntity

use of org.activiti.engine.impl.persistence.entity.EventSubscriptionEntity in project Activiti by Activiti.

the class EventSubscriptionQueryTest method testQueryByEventType.

public void testQueryByEventType() {
    processEngineConfiguration.getCommandExecutor().execute(new Command<Void>() {

        public Void execute(CommandContext commandContext) {
            MessageEventSubscriptionEntity messageEventSubscriptionEntity1 = new MessageEventSubscriptionEntity();
            messageEventSubscriptionEntity1.setEventName("messageName");
            messageEventSubscriptionEntity1.insert();
            MessageEventSubscriptionEntity messageEventSubscriptionEntity2 = new MessageEventSubscriptionEntity();
            messageEventSubscriptionEntity2.setEventName("messageName");
            messageEventSubscriptionEntity2.insert();
            SignalEventSubscriptionEntity signalEventSubscriptionEntity3 = new SignalEventSubscriptionEntity();
            signalEventSubscriptionEntity3.setEventName("messageName2");
            signalEventSubscriptionEntity3.insert();
            return null;
        }
    });
    List<EventSubscriptionEntity> list = newEventSubscriptionQuery().eventType("signal").list();
    assertEquals(1, list.size());
    list = newEventSubscriptionQuery().eventType("message").list();
    assertEquals(2, list.size());
    cleanDb();
}
Also used : CommandContext(org.activiti.engine.impl.interceptor.CommandContext) MessageEventSubscriptionEntity(org.activiti.engine.impl.persistence.entity.MessageEventSubscriptionEntity) SignalEventSubscriptionEntity(org.activiti.engine.impl.persistence.entity.SignalEventSubscriptionEntity) MessageEventSubscriptionEntity(org.activiti.engine.impl.persistence.entity.MessageEventSubscriptionEntity) SignalEventSubscriptionEntity(org.activiti.engine.impl.persistence.entity.SignalEventSubscriptionEntity) EventSubscriptionEntity(org.activiti.engine.impl.persistence.entity.EventSubscriptionEntity)

Example 12 with EventSubscriptionEntity

use of org.activiti.engine.impl.persistence.entity.EventSubscriptionEntity in project Activiti by Activiti.

the class EventSubscriptionQueryTest method testQueryByEventName.

public void testQueryByEventName() {
    processEngineConfiguration.getCommandExecutor().execute(new Command<Void>() {

        public Void execute(CommandContext commandContext) {
            MessageEventSubscriptionEntity messageEventSubscriptionEntity1 = new MessageEventSubscriptionEntity();
            messageEventSubscriptionEntity1.setEventName("messageName");
            messageEventSubscriptionEntity1.insert();
            MessageEventSubscriptionEntity messageEventSubscriptionEntity2 = new MessageEventSubscriptionEntity();
            messageEventSubscriptionEntity2.setEventName("messageName");
            messageEventSubscriptionEntity2.insert();
            MessageEventSubscriptionEntity messageEventSubscriptionEntity3 = new MessageEventSubscriptionEntity();
            messageEventSubscriptionEntity3.setEventName("messageName2");
            messageEventSubscriptionEntity3.insert();
            return null;
        }
    });
    List<EventSubscriptionEntity> list = newEventSubscriptionQuery().eventName("messageName").list();
    assertEquals(2, list.size());
    list = newEventSubscriptionQuery().eventName("messageName2").list();
    assertEquals(1, list.size());
    cleanDb();
}
Also used : CommandContext(org.activiti.engine.impl.interceptor.CommandContext) MessageEventSubscriptionEntity(org.activiti.engine.impl.persistence.entity.MessageEventSubscriptionEntity) MessageEventSubscriptionEntity(org.activiti.engine.impl.persistence.entity.MessageEventSubscriptionEntity) SignalEventSubscriptionEntity(org.activiti.engine.impl.persistence.entity.SignalEventSubscriptionEntity) EventSubscriptionEntity(org.activiti.engine.impl.persistence.entity.EventSubscriptionEntity)

Example 13 with EventSubscriptionEntity

use of org.activiti.engine.impl.persistence.entity.EventSubscriptionEntity in project Activiti by Activiti.

the class TransactionSubProcessTest method testMultiInstanceTx.

/*
   * The cancel end event cancels all instances, compensation is performed for all instances
   * 
   * see spec page 470:
   * "If the cancelActivity attribute is set, the Activity the Event is attached to is then 
   * cancelled (in case of a multi-instance, all its instances are cancelled);"
   */
@Deployment
public void testMultiInstanceTx() {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("transactionProcess");
    // there are now 5 instances of the transaction:
    List<EventSubscriptionEntity> EventSubscriptionEntitys = createEventSubscriptionQuery().eventType("compensate").list();
    // there are 10 compensation event subscriptions
    assertEquals(10, EventSubscriptionEntitys.size());
    // the event subscriptions are all under the same execution (the execution of the multi-instance wrapper)
    String executionId = EventSubscriptionEntitys.get(0).getExecutionId();
    for (EventSubscriptionEntity EventSubscriptionEntity : EventSubscriptionEntitys) {
        if (!executionId.equals(EventSubscriptionEntity.getExecutionId())) {
            fail("subscriptions not under same execution");
        }
    }
    Task task = taskService.createTaskQuery().listPage(0, 1).get(0);
    // canceling one instance triggers compensation for all other instances:    
    taskService.setVariable(task.getId(), "confirmed", false);
    taskService.complete(task.getId());
    assertEquals(0, createEventSubscriptionQuery().count());
    assertEquals(5, runtimeService.getVariable(processInstance.getId(), "undoBookHotel"));
    assertEquals(5, runtimeService.getVariable(processInstance.getId(), "undoBookFlight"));
    runtimeService.signal(runtimeService.createExecutionQuery().activityId("afterCancellation").singleResult().getId());
    assertProcessEnded(processInstance.getId());
}
Also used : Task(org.activiti.engine.task.Task) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) EventSubscriptionEntity(org.activiti.engine.impl.persistence.entity.EventSubscriptionEntity) Deployment(org.activiti.engine.test.Deployment)

Example 14 with EventSubscriptionEntity

use of org.activiti.engine.impl.persistence.entity.EventSubscriptionEntity in project Activiti by Activiti.

the class TransactionSubProcessTest method testMultiInstanceTxSuccessful.

@Deployment(resources = { "org/activiti/engine/test/bpmn/subprocess/transaction/TransactionSubProcessTest.testMultiInstanceTx.bpmn20.xml" })
public void testMultiInstanceTxSuccessful() {
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("transactionProcess");
    // there are now 5 instances of the transaction:
    List<EventSubscriptionEntity> EventSubscriptionEntitys = createEventSubscriptionQuery().eventType("compensate").list();
    // there are 10 compensation event subscriptions
    assertEquals(10, EventSubscriptionEntitys.size());
    // the event subscriptions are all under the same execution (the execution of the multi-instance wrapper)
    String executionId = EventSubscriptionEntitys.get(0).getExecutionId();
    for (EventSubscriptionEntity EventSubscriptionEntity : EventSubscriptionEntitys) {
        if (!executionId.equals(EventSubscriptionEntity.getExecutionId())) {
            fail("subscriptions not under same execution");
        }
    }
    // first complete the inner user-tasks
    List<Task> tasks = taskService.createTaskQuery().list();
    for (Task task : tasks) {
        taskService.setVariable(task.getId(), "confirmed", true);
        taskService.complete(task.getId());
    }
    // now complete the inner receive tasks    
    List<Execution> executions = runtimeService.createExecutionQuery().activityId("receive").list();
    for (Execution execution : executions) {
        runtimeService.signal(execution.getId());
    }
    runtimeService.signal(runtimeService.createExecutionQuery().activityId("afterSuccess").singleResult().getId());
    assertEquals(0, createEventSubscriptionQuery().count());
    assertProcessEnded(processInstance.getId());
}
Also used : Task(org.activiti.engine.task.Task) Execution(org.activiti.engine.runtime.Execution) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) EventSubscriptionEntity(org.activiti.engine.impl.persistence.entity.EventSubscriptionEntity) Deployment(org.activiti.engine.test.Deployment)

Example 15 with EventSubscriptionEntity

use of org.activiti.engine.impl.persistence.entity.EventSubscriptionEntity in project Activiti by Activiti.

the class MessageStartEventTest method testUpdateProcessVersionCancelsSubscriptions.

public void testUpdateProcessVersionCancelsSubscriptions() {
    String deploymentId = repositoryService.createDeployment().addClasspathResource("org/activiti/engine/test/bpmn/event/message/MessageStartEventTest.testSingleMessageStartEvent.bpmn20.xml").deploy().getId();
    List<EventSubscriptionEntity> eventSubscriptions = new EventSubscriptionQueryImpl(processEngineConfiguration.getCommandExecutor()).list();
    List<ProcessDefinition> processDefinitions = repositoryService.createProcessDefinitionQuery().list();
    assertEquals(1, eventSubscriptions.size());
    assertEquals(1, processDefinitions.size());
    String newDeploymentId = repositoryService.createDeployment().addClasspathResource("org/activiti/engine/test/bpmn/event/message/MessageStartEventTest.testSingleMessageStartEvent.bpmn20.xml").deploy().getId();
    List<EventSubscriptionEntity> newEventSubscriptions = new EventSubscriptionQueryImpl(processEngineConfiguration.getCommandExecutor()).list();
    List<ProcessDefinition> newProcessDefinitions = repositoryService.createProcessDefinitionQuery().list();
    assertEquals(1, newEventSubscriptions.size());
    assertEquals(2, newProcessDefinitions.size());
    int version1Count = 0;
    int version2Count = 0;
    for (ProcessDefinition processDefinition : newProcessDefinitions) {
        if (processDefinition.getVersion() == 1) {
            for (EventSubscriptionEntity subscription : newEventSubscriptions) {
                if (subscription.getConfiguration().equals(processDefinition.getId())) {
                    version1Count++;
                }
            }
        } else {
            for (EventSubscriptionEntity subscription : newEventSubscriptions) {
                if (subscription.getConfiguration().equals(processDefinition.getId())) {
                    version2Count++;
                }
            }
        }
    }
    assertEquals(0, version1Count);
    assertEquals(1, version2Count);
    assertFalse(eventSubscriptions.equals(newEventSubscriptions));
    repositoryService.deleteDeployment(deploymentId);
    repositoryService.deleteDeployment(newDeploymentId);
}
Also used : EventSubscriptionQueryImpl(org.activiti.engine.impl.EventSubscriptionQueryImpl) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) EventSubscriptionEntity(org.activiti.engine.impl.persistence.entity.EventSubscriptionEntity)

Aggregations

EventSubscriptionEntity (org.activiti.engine.impl.persistence.entity.EventSubscriptionEntity)17 MessageEventSubscriptionEntity (org.activiti.engine.impl.persistence.entity.MessageEventSubscriptionEntity)8 SignalEventSubscriptionEntity (org.activiti.engine.impl.persistence.entity.SignalEventSubscriptionEntity)8 CommandContext (org.activiti.engine.impl.interceptor.CommandContext)7 Deployment (org.activiti.engine.test.Deployment)5 Execution (org.activiti.engine.runtime.Execution)4 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)4 Task (org.activiti.engine.task.Task)4 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)3 EventSubscriptionQueryImpl (org.activiti.engine.impl.EventSubscriptionQueryImpl)3 ActivitiException (org.activiti.engine.ActivitiException)2 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1 List (java.util.List)1 EventSubscriptionDeclaration (org.activiti.engine.impl.bpmn.parser.EventSubscriptionDeclaration)1 CompensateEventSubscriptionEntity (org.activiti.engine.impl.persistence.entity.CompensateEventSubscriptionEntity)1 ExecutionEntity (org.activiti.engine.impl.persistence.entity.ExecutionEntity)1 ActivityImpl (org.activiti.engine.impl.pvm.process.ActivityImpl)1 ProcessDefinition (org.activiti.engine.repository.ProcessDefinition)1