cancel
Showing results for 
Search instead for 
Did you mean: 

Help with signalEvent

pitagoras
Champ in-the-making
Champ in-the-making
Hi.
I m working with activiti 5.9 from eclipse indigo.
I´m trying to make work the following process:

<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test">
  <signal id="emailReceived" name="email received"></signal>
  <process id="venta-offline" name="Proceso de ventas offline">
    <startEvent id="startevent1" name="Start"></startEvent>
    <userTask id="usertask1" name="Cotizar">
      <extensionElements>
        <activiti:formProperty id="destino" name="Destino" type="string"></activiti:formProperty>
        <activiti:taskListener event="create" class="ventas.offline.assign.SaleAssignment"></activiti:taskListener>
      </extensionElements>
    </userTask>
    <serviceTask id="mailtask1" name="Enviar Cotizacion" activiti:type="mail">
      <extensionElements>
        <activiti:field name="to" expression="bub_at_xcom"></activiti:field>
        <activiti:field name="from" expression="bub_at_xcom"></activiti:field>
        <activiti:field name="subject" expression="Tu cotizacion"></activiti:field>
        <activiti:field name="html">
          <activiti:expression><![CDATA[aca esta]]></activiti:expression>
        </activiti:field>
      </extensionElements>
    </serviceTask>
    <intermediateCatchEvent id="signalintermediatecatchevent1" name="SignalCatchEvent">
      <signalEventDefinition signalRef="emailReceived"></signalEventDefinition>
    </intermediateCatchEvent>
    <serviceTask id="mailtask2" name="Gracias" activiti:type="mail">
      <extensionElements>
        <activiti:field name="to" expression="bub_at_xcom"></activiti:field>
        <activiti:field name="from" expression="bub_at_xcom"></activiti:field>
        <activiti:field name="subject" expression="Gracias!"></activiti:field>
        <activiti:field name="html">
          <activiti:expression><![CDATA[vuelva!]]></activiti:expression>
        </activiti:field>
      </extensionElements>
    </serviceTask>
    <endEvent id="endevent1" name="End"></endEvent>
    <sequenceFlow id="flow3" name="" sourceRef="usertask1" targetRef="mailtask1"></sequenceFlow>
    <sequenceFlow id="flow4" name="" sourceRef="mailtask1" targetRef="signalintermediatecatchevent1"></sequenceFlow>
    <sequenceFlow id="flow5" name="" sourceRef="signalintermediatecatchevent1" targetRef="mailtask2"></sequenceFlow>
    <sequenceFlow id="flow6" name="" sourceRef="mailtask2" targetRef="endevent1"></sequenceFlow>
    <sequenceFlow id="flow7" name="" sourceRef="startevent1" targetRef="usertask1"></sequenceFlow>
  </process>
</definitions>

with the following test case (junit 4).

package ventas.offline.assign;

import static org.junit.Assert.assertEquals;

import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.activiti.engine.ManagementService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.impl.ProcessEngineImpl;
import org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl;
import org.activiti.engine.impl.test.TestHelper;
import org.activiti.engine.impl.util.ClockUtil;
import org.activiti.engine.runtime.Execution;
import org.activiti.engine.runtime.Job;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.activiti.engine.test.ActivitiRule;
import org.activiti.engine.test.Deployment;
import org.apache.commons.lang.time.DateUtils;
import org.junit.Rule;
import org.junit.Test;

public class VentasOfflineTest {

   @Rule
   public ActivitiRule activitiRule = new ActivitiRule();

   @Test
   @Deployment
   public void testSignal() {
      ManagementService managementService = activitiRule
            .getManagementService();
      ProcessEngineImpl processEngineImpl = (ProcessEngineImpl) activitiRule
            .getProcessEngine();
      ProcessEngineConfigurationImpl processEngineConfiguration = processEngineImpl
            .getProcessEngineConfiguration();
      // TestHelper.assertAndEnsureCleanDb(processEngineImpl);

      RuntimeService runtimeService = activitiRule.getRuntimeService();
      TaskService taskService = activitiRule.getTaskService();

      Map<String, Object> form = new HashMap<String, Object>();
      form.put("destino", "Brasil");
      form.put("_reminders", 0);

      ProcessInstance processInstance = runtimeService
            .startProcessInstanceByKey("venta-offline", form);

      Task task = taskService.createTaskQuery().singleResult();
      assertEquals("Cotizar", task.getName());
      assertEquals("gonzo", task.getAssignee());
      taskService.complete(task.getId());

      System.out.println("1->"
            + runtimeService.getActiveActivityIds(processInstance.getId()));

       List<Execution> executions = runtimeService.createExecutionQuery()
               .signalEventSubscription("emailReceived")
               .list();

       System.out.println("Executions:" + executions);
      
      runtimeService.signalEventReceived("emailReceived");// (processInstance.getId());

      System.out.println("2->"
            + runtimeService.getActiveActivityIds(processInstance.getId()));

   }


}


and the output is

1->[signalintermediatecatchevent1]
Executions:[]
2->[signalintermediatecatchevent1]

Which seems to show that signalEventReceived is not acting because no executions waiting for emailReceived event are found.
Am I missing something?
1 REPLY 1

pitagoras
Champ in-the-making
Champ in-the-making
I answer myself, just in case anyone hits the same problem…
The thing is that runtimeService.signalEventReceived() should be called by signal *name*, not the id.
in my case runtimeService.signalEventReceived("email received"); does the trick. Same applies for the query.