4 Replies Latest reply on Feb 25, 2010 11:19 AM by tamisier laure

    Test workflow with JUnit

    tamisier laure Newbie

      Hy,

       

      I try to write Junit test in order to test a workflow jBpm.

       

      I have the following file, but when i run the test, i have an error when it reads the cfg file

      ---the process


      <process name="test" xmlns="http://jbpm.org/4.3/jpdl">
         <start name="start" g="98,157,48,48">
            <transition name="to ok" to="ok" g="-29,-18"/>
         </start>
         <state name="ok" g="210,178,92,52">
            <transition name="to end" to="end" g="-9,-19"/>
         </state>
         <end name="end" g="366,210,48,48"/>
      </process>

       

      -----------The Test class


      import org.jbpm.graph.def.ProcessDefinition;
      import org.jbpm.graph.exe.ProcessInstance;

       

      import junit.framework.TestCase;
      public class StateTest extends TestCase {

       

          public void testMainScenario() {

       


              // parse the process definition
              ProcessDefinition testProcess = ProcessDefinition.
                      parseXmlResource("fr/ucanss/workflow/test.jpdl.xml");

       

              // create a new process instance for the given process definition
              ProcessInstance processInstance = new ProcessInstance(testProcess);

       

              assertNotNull("definition should be not null", testProcess);
             
              assertNotNull("instance should be not null", processInstance);
             
              assertNotNull("root token should be not null", processInstance.getRootToken());
             
              assertNotNull("start node should be not null", processInstance.getRootToken()
                      .getNode());  

       

          }
      }

       

      ------ I have a file jbpm.cfg.xml

       

      <jbpm-configuration>

       

        <import resource="jbpm.default.cfg.xml" />
        <import resource="jbpm.businesscalendar.cfg.xml" />
        <import resource="jbpm.tx.hibernate.cfg.xml" />
        <import resource="jbpm.jpdl.cfg.xml" />
        <import resource="jbpm.bpmn.cfg.xml" />
        <import resource="jbpm.identity.cfg.xml" />

       

      </jbpm-configuration>

       

       

      ---- my error

       

      org.jbpm.JbpmException: couldn't parse jbpm configuration from resource 'jbpm.cfg.xml'
          at org.jbpm.JbpmConfiguration.getInstance(JbpmConfiguration.java:320)
          at org.jbpm.JbpmConfiguration.getInstance(JbpmConfiguration.java:272)
          at org.jbpm.JbpmConfiguration$Configs.getObjectFactory(JbpmConfiguration.java:488)
          at org.jbpm.JbpmConfiguration$Configs.hasObject(JbpmConfiguration.java:500)
          at org.jbpm.util.ClassLoaderUtil.getClassLoader(ClassLoaderUtil.java:65)
          at org.jbpm.graph.def.ProcessDefinition.parseXmlResource(ProcessDefinition.java:160)
          at fr.ucanss.test.StateTest.testMainScenario(StateTest.java:21)
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
          at java.lang.reflect.Method.invoke(Unknown Source)
          at junit.framework.TestCase.runTest(TestCase.java:168)
          at junit.framework.TestCase.runBare(TestCase.java:134)
          at junit.framework.TestResult$1.protect(TestResult.java:110)
          at junit.framework.TestResult.runProtected(TestResult.java:128)
          at junit.framework.TestResult.run(TestResult.java:113)
          at junit.framework.TestCase.run(TestCase.java:124)
          at junit.framework.TestSuite.runTest(TestSuite.java:232)
          at junit.framework.TestSuite.run(TestSuite.java:227)
          at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:79)
          at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)
          at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
          at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
          at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
          at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
          at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
      Caused by: org.jbpm.JbpmException: no ObjectInfo class specified for element 'import'
          at org.jbpm.configuration.ObjectFactoryParser.parse(ObjectFactoryParser.java:139)
          at org.jbpm.configuration.ObjectFactoryParser.parseElements(ObjectFactoryParser.java:117)
          at org.jbpm.configuration.ObjectFactoryParser.parseElementsStream(ObjectFactoryParser.java:110)
          at org.jbpm.JbpmConfiguration.parseObjectFactory(JbpmConfiguration.java:355)
          at org.jbpm.JbpmConfiguration.getInstance(JbpmConfiguration.java:314)
          ... 25 more

       

      Thanks to help me

       

      Laure

        • 1. Re: Test workflow with JUnit
          tamisier laure Newbie
          here he test which runs !!!! t
          import org.jbpm.api.ProcessInstance;
          import org.jbpm.test.JbpmTestCase;

          public class StateTest extends JbpmTestCase {

              String deploymentId;

              protected void setUp() throws Exception {
                  super.setUp();

                  deploymentId = repositoryService.createDeployment()
                          .addResourceFromClasspath("fr/ucanss/workflow/test.jpdl.xml")
                          .deploy();
              }

              protected void tearDown() throws Exception {
                  repositoryService.deleteDeploymentCascade(deploymentId);

                  super.tearDown();
              }

              public void testMainScenario() {

                  ProcessInstance processInstance =
                      executionService.startProcessInstanceByKey("test");

                  assertNotNull("instance should be not null", processInstance);
                 
                 
                  for (String act:processInstance.findActiveActivityNames()){
                      System.out.println("Activity " + act);
                  }
                 
                  assertActivityActive(processInstance.getId(), "ok");
                 
                  executionService.signalExecutionById(processInstance.getId(), "to end");
                 
                  assertProcessInstanceEnded(processInstance);       
                 
              }
          }
          • 2. Re: Test workflow with JUnit
            tamisier laure Newbie

            the problem with this solution is :

             

            i can't run a process with rule node ... i don't understand how i can execute a rule

            • 3. Re: Test workflow with JUnit
              tamisier laure Newbie

              i will think that i am only to do some test on my process :-(

              • 4. Re: Test workflow with JUnit
                tamisier laure Newbie

                I have found my problem... i have forgotten to deploy my drl file.

                 

                find here the code to deploy and delete the deploy

                 

                    NewDeployment deploy

                 


                    protected void setUp() throws Exception {
                        super.setUp();

                 

                        deploy = repositoryService.createDeployment().addResourceFromClasspath("process.jpdl.xml");
                        deploy.addResourceFromClasspath("test.drl");
                   
                        deploymentId = deploy.deploy();
                    }

                 


                    protected void tearDown() throws Exception {

                 

                        repositoryService.deleteDeploymentCascade(deploymentId);
                        super.tearDown();
                    }

                 

                thanks for your help .. and i hope this will help you

                 

                Laure