cancel
Showing results for 
Search instead for 
Did you mean: 

unit testing and service task expressions

robmckinnon
Champ on-the-rise
Champ on-the-rise
Activiti: 5.9

I am having trouble with unit testing an activiti process that contains an expression.

Consider the following task:
<serviceTask id="getAlfrescoGuid" name="Get Alfresco Guid" activiti:expression="#{alfrescoGuid.execute(execution)}"></serviceTask>

I have the bean defined in my src/main/test/resources/activiti.cfg.xml  file
<bean id="alfrescoGuid" class="com.myco.activiti.pos.GetAlfrescoGuid">
      <property name="user" value="ldapuser-rex"/>
</bean>

I get the following error when running the test case:
Caused by: org.activiti.engine.impl.javax.el.PropertyNotFoundException: Cannot resolve identifier 'alfrescoGuid'
   at org.activiti.engine.impl.juel.AstIdentifier.eval(AstIdentifier.java:83)
   at org.activiti.engine.impl.juel.AstMethod.invoke(AstMethod.java:79)
   at org.activiti.engine.impl.juel.AstMethod.eval(AstMethod.java:75)
   at org.activiti.engine.impl.juel.AstEval.eval(AstEval.java:50)
   at org.activiti.engine.impl.juel.AstNode.getValue(AstNode.java:26)
   at org.activiti.engine.impl.juel.TreeValueExpression.getValue(TreeValueExpression.java:114)
   at org.activiti.engine.impl.delegate.ExpressionGetInvocation.invoke(ExpressionGetInvocation.java:33)
   at org.activiti.engine.impl.delegate.DelegateInvocation.proceed(DelegateInvocation.java:37)
   at org.activiti.engine.impl.delegate.DefaultDelegateInterceptor.handleInvocation(DefaultDelegateInterceptor.java:25)
   at org.activiti.engine.impl.el.JuelExpression.getValue(JuelExpression.java:50)
   … 111 more

Has anybody seen this before? Am I missing something? Is it a bug with activiti? Any response would be appreciated.

Thanks
3 REPLIES 3

robmckinnon
Champ on-the-rise
Champ on-the-rise
If any one is interested I figured this one out.  In your unit test you will need to include the following in the processEngineConfiguration:

<property name="beans">
    <map>
         <entry key="alfrescoGuid" value-ref="alfrescoGuid" />
    </map>
</property>

I found the answer in the user guide.

shukla_raghav
Champ in-the-making
Champ in-the-making
I did the same thing but its not working for me. Can you help me out. Here are the details

1. I am using the demo setup (ant demo.start)
2. I created a .bpmn.xml file which is as follows. This test process is pretty simple.
    a. process starts (Start)
    b. Customer enters name and salary and submit (User task)
    c. An exclusive gateway decides if salary > 2000 or salary <=2000 (exclusive gateway)
    d. if Salary > 2000, then it is Platinum member, execute Java Service Task (service task)
    e. else it is Gold Member

   .bpmn.xml

<?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:smileysurprised:mgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:smileysurprised:mgdi="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">
  <process id="my_test_process" name="MyTestProcess">
    <startEvent id="startevent1" name="Start" activiti:initiator="kermit"></startEvent>
    <exclusiveGateway id="exclusivegateway1" name="Exclusive Gateway"></exclusiveGateway>
    <userTask id="details" name="Enter Details" activiti:assignee="kermit" activiti:candidateUsers="fozzie">
      <documentation>This is a Test Form Documentation 2</documentation>
      <extensionElements>
        <activiti:formProperty id="user_name" name="Name" type="string"></activiti:formProperty>
        <activiti:formProperty id="salary" name="salary" type="long"></activiti:formProperty>
      </extensionElements>
    </userTask>
    <userTask id="usertask4" name="Gold Member" activiti:assignee="kermit" activiti:candidateUsers="fozzie">
      <documentation>This is documentation for Gold Member</documentation>
    </userTask>
    <exclusiveGateway id="exclusivegateway2" name="Exclusive Gateway"></exclusiveGateway>
    <endEvent id="endevent1" name="End"></endEvent>
    <serviceTask id="servicetask1" name="Platinum Member" activiti:expression="#{platinum.doSomething()}"></serviceTask>
    <sequenceFlow id="flow2" name="" sourceRef="details" targetRef="exclusivegateway1"></sequenceFlow>
    <sequenceFlow id="flow3" name="salary_flow_a" sourceRef="exclusivegateway1" targetRef="servicetask1">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${salary > 2000}]]></conditionExpression>
    </sequenceFlow>
    <sequenceFlow id="flow4" name="" sourceRef="startevent1" targetRef="details"></sequenceFlow>
    <sequenceFlow id="flow5" name="salary_flow_b" sourceRef="exclusivegateway1" targetRef="usertask4">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${salary <= 2000}]]></conditionExpression>
    </sequenceFlow>
    <sequenceFlow id="flow6" name="" sourceRef="usertask4" targetRef="exclusivegateway2"></sequenceFlow>
    <sequenceFlow id="flow7" name="" sourceRef="servicetask1" targetRef="exclusivegateway2"></sequenceFlow>
    <sequenceFlow id="flow8" name="" sourceRef="exclusivegateway2" targetRef="endevent1"></sequenceFlow>
  </process>

3. activiti.cfg.xml

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans   http://www.springframework.org/schema/beans/spring-beans.xsd">
  [color=#FF0040]<bean id="platinum" class="com.osr.test.PlatinumService" />[/color]
  <bean id="processEngineConfiguration" class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration">
  
    
     <!– Database configurations  –>
    <property name="databaseSchemaUpdate" value="true" />
    <property name="jdbcUrl" value="jdbc:h2:tcp://localhost/activiti" />
    <property name="jdbcDriver" value="org.h2.Driver" />
    <property name="jdbcUsername" value="sa" />
    <property name="jdbcPassword" value="" />
   
    <property name="jobExecutorActivate" value="true" />

  </bean>
  [color=#FF0040]<property name="beans">
    <map>
      <entry key="platinum" value-ref="platinum" />
    </map>
  </property>[/color]
 

</beans>

4. MyFirstProcessDiagram.jar is the JAR file containing a classfile of  osr.test.PlatinumService.java.

Now here is how i deploy

- Deployed the .bar file using activiti explorer
- Placed the JAR file in activiti-5.9\apps\apache-tomcat-6.0.32\webapps\activiti-rest\WEB-INF\lib
- start Tomcat using ant demo.start

When i start my process from within the activiti-explorer (Process > start) i see a form where user enters the Name and Salary and Submit.

Problem : as soon as i submit i get an exception

Exception

Caused by: org.activiti.engine.impl.javax.el.PropertyNotFoundException: Cannot resolve identifier 'platinum'
        at org.activiti.engine.impl.juel.AstIdentifier.eval(AstIdentifier.java:83)
        at org.activiti.engine.impl.juel.AstMethod.invoke(AstMethod.java:79)
        at org.activiti.engine.impl.juel.AstMethod.eval(AstMethod.java:75)
        at org.activiti.engine.impl.juel.AstEval.eval(AstEval.java:50)
        .
        .
        .

What am i missing ?

frederikherema1
Star Contributor
Star Contributor
activiti.cfg.xml is not used in activiti-explorer. Rather, use a applicationContext.xml to wire in any service you want to use, instead of the cfg.xml-file:


/activiti-webapp-explorer2/src/main/webapp/WEB-INF/applicationContext.xml