2 Replies Latest reply on Jul 6, 2015 11:13 AM by abhijithumbe

    JBPM Unit Test: Unable to get LastModified for ClasspathResource

    samamer

      I am unable to get past this error when creating and running jUnit tests in JBoss Developer Studio:

      Unable to get LastModified for ClasspathResource

      Caused by: java.io.FileNotFoundException: 'sample.bpmn' cannot be opened because it does not exist.

       

      I tried several paths but nothing worked and I am reaching out to the group for guidance. Here are the steps and the references:

      1. I am using JBoss Developer Studio Version: 8.1.0.GA configured with BRMS and BPM Suites from this url: https://devstudio.jboss.com/updates/8.0/integration-stack/

      2. Create a new sample project as jBPM project (Maven). This auto generates a process "sample.bpmn" that has two human tasks.

      3. Right click on this process and select "Generate jBPM JUnit Tests". This creates a new package "org.jbpm" under src/main/java with an auto generated public class Hello_WorldJUnitTest extends JbpmJUnitTestCase.

      4. If you run this test without change, you will get the above referenced error.


      I know that JbpmJUnitTestCase has been deprecated and replaced by JbpmJUnitBaseTestCase, but this had no effect on this error. I also tried moving the test class to different locations within the project structure. And I tried to use the absolute path of the "sample.bpmn". Here is the sample @Test code that I am trying to get to pass:

       

          @Test

          public void testImplicit() {

              KieSession ksession = createKnowledgeSession("sample2.bpmn");

              TaskService taskService = getTaskService();

              ProcessInstance processInstance = ksession.startProcess("com.sample.bpmn");

              assertProcessInstanceActive(processInstance.getId(), ksession);

          }

       

      Changing it to the code shown in the Development_Guide still gives the same error:

        public void testProcess() {

              createRuntimeManager("sample2.bpmn");

              RuntimeEngine runtimeEngine = getRuntimeEngine();

              KieSession ksession = runtimeEngine.getKieSession();

              ProcessInstance processInstance = ksession.startProcess("com.sample.bpmn");

              assertProcessInstanceActive(processInstance.getId(), ksession);

        }

       

      The full error trace is attached.

        • 1. Re: JBPM Unit Test: Unable to get LastModified for ClasspathResource
          samamer

          I am answering my own question to help others:

          1. The JBPM (Maven) project template described above creates a process "sample.bpmn" within a com.sample package under src/main/resources. This makes the process invisible to the generated jUnit test.

          2. Moving the process outside the package makes it visible. Basically putting it directly under src/main/resources resolved the issue described here.

          3. I am still trying to figure out how to reference a *.bpmn file using its path.

          • 2. Re: JBPM Unit Test: Unable to get LastModified for ClasspathResource
            abhijithumbe

            Hi,

            To load BPMN file using its path, try following approach:

             

            File ruleflowFile = new File("/valid/path/to/Sample.bpmn");

            Resource resourceRuleflow = kieServices.getResources().newFileSystemResource(ruleflowFile).setResourceType(ResourceType.BPMN2);

            kfs.write( resourceRuleflow);        

            KieBuilder kb = kieServices.newKieBuilder(kfs);

            kb.buildAll();

             

            Hope it helps..