How can I initial ProcessEngineRule with different configuration

Hi,

I want to use different configuration file for testing consisting of h2 DB.

My main application has camunda.cfg.xml which uses real DB viz. MySQL.

when I run my test class, I see

17:39:15.901 [main] ERROR o.c.b.e.context -
                ENGINE-16004 Exception while closing command context: no processes deployed with key 'my-process': processDefinition is null
org.camunda.bpm.engine.exception.NullValueException: no processes deployed with key 'my-process': processDefinition is null
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_112]
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_112]
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_112]
        at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_112]
        at org.camunda.bpm.engine.impl.util.EnsureUtil.generateException(EnsureUtil.java:334) ~[oracle-camunda-engine-7.5.0.jar:7.5.0]
        at org.camunda.bpm.engine.impl.util.EnsureUtil.ensureNotNull(EnsureUtil.java:49) ~[oracle-camunda-engine-7.5.0.jar:7.5.0]

When I check the log, I see Process Engine is getting initiated twice.

7:39:13.152 [main] INFO  o.c.b.engine -
                ENGINE-00003 Initializing process engine for resource file:/D:/Project/LoanApproval/target/classes/camunda.cfg.xml

 ENGINE-00004 Initializing process engine default
17:39:14.927 [main] INFO  o.c.b.engine -
                ENGINE-00003 Initializing process engine for resource file:/D:/Project/LoanApproval/target/test-classes/camunda.cfg.xml

I tried

public ProcessEngineRule processEngineRule = new ProcessEngineRule("test.camunda.cfg.xml");

But no luck. Is there a way to load specific configuration file by ProcessEngineRule?

Any example will be a great help.

Thanks,
Suhas Madap.

Hi @revsmadap,

you can adapt the configuration for your test using the ProcessEngineBootstrapRule. Here is an example on how you could do that:


protected ProcessEngineBootstrapRule bootstrapRule = new ProcessEngineBootstrapRule() {
    @Override
    public ProcessEngineConfiguration configureEngine(ProcessEngineConfigurationImpl configuration) {
      // apply your desired changes in the configuration here
      return configuration;
    }
  };
  protected ProcessEngineRule engineRule = new ProvidedProcessEngineRule(bootstrapRule);

  protected ProcessEngineTestRule testRule = new ProcessEngineTestRule(engineRule);

  @Rule
  public RuleChain ruleChain = RuleChain.outerRule(bootstrapRule).around(engineRule).around(testRule);

Probably you could also load a configuration from a file by using ProcessEngineConfiguration.createProcessEngineConfigurationFromResource(String resource); in the ProcessEngineBootstrapRule.

Does that help?

Best
Johannes

Hi @revsmadap,

ignore my previous post, as the ProcessEngineBootstrapRule ist part of the test-sources of the engine and, thus, it’s not that easy to access it. Could you maybe provide a failing test case? This would help to a lot to guide you with this problem.

Best,
Johannes