Unit Test with two classes throws error when running via Maven

Hi,

I’m writing a jUnit test and have to java classes. One for all tests belonging to my BPMN and one for my tests belonging to my DMN-Table. If I run the tests in Eclipse via “RunAs -> jUnit Test” everything is fine. If I run them via Maven I get the following error:

Tests run: 7, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 3.122 sec
Running com.generali.bpm.infraservices.prophet.bpmn.DMNTest
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 1.193 sec <<< FAILURE!
com.generali.bpm.infraservices.prophet.bpmn.DMNTest  Time elapsed: 1.193 sec  <<< ERROR!
org.camunda.bpm.engine.ProcessEngineException: ENGINE-03017 Could not perform operation 'create' on database schema for SQL Statement: 'create table ACT_HI_PROCINST ( 
ID_ varchar(64) not null, 
PROC_INST_ID_ varchar(64) not null, 
BUSINESS_KEY_ varchar(255), 
PROC_DEF_KEY_ varchar(255), 
PROC_DEF_ID_ varchar(64) not null, 
START_TIME_ timestamp not null, 
END_TIME_ timestamp, 
DURATION_ bigint, 
START_USER_ID_ varchar(255), 
START_ACT_ID_ varchar(255), 
END_ACT_ID_ varchar(255), 
SUPER_PROCESS_INSTANCE_ID_ varchar(64), 
SUPER_CASE_INSTANCE_ID_ varchar(64), 
CASE_INST_ID_ varchar(64), 
DELETE_REASON_ varchar(4000), 
TENANT_ID_ varchar(64), 
primary key (ID_), 
unique (PROC_INST_ID_) 
)'.
    at org.camunda.bpm.engine.impl.db.EnginePersistenceLogger.performDatabaseOperationException(EnginePersistenceLogger.java:221)
    at org.camunda.bpm.engine.impl.db.sql.DbSqlSession.executeSchemaResource(DbSqlSession.java:650)
    at org.camunda.bpm.engine.impl.db.sql.DbSqlSession.executeSchemaResource(DbSqlSession.java:577)
    at org.camunda.bpm.engine.impl.db.sql.DbSqlSession.executeMandatorySchemaResource(DbSqlSession.java:393)
    at org.camunda.bpm.engine.impl.db.sql.DbSqlSession.dbSchemaCreateHistory(DbSqlSession.java:328)
    at org.camunda.bpm.engine.impl.db.AbstractPersistenceSession.dbSchemaCreate(AbstractPersistenceSession.java:93)
    at org.camunda.bpm.engine.impl.SchemaOperationsProcessEngineBuild.execute(SchemaOperationsProcessEngineBuild.java:52)
    at org.camunda.bpm.engine.impl.SchemaOperationsProcessEngineBuild.execute(SchemaOperationsProcessEngineBuild.java:34)
    at org.camunda.bpm.engine.impl.interceptor.CommandExecutorImpl.execute(CommandExecutorImpl.java:24)
    at org.camunda.bpm.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:104)
    at org.camunda.bpm.engine.impl.interceptor.ProcessApplicationContextInterceptor.execute(ProcessApplicationContextInterceptor.java:66)
    at org.camunda.bpm.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:30)
    at org.camunda.bpm.engine.impl.ProcessEngineImpl.executeSchemaOperations(ProcessEngineImpl.java:126)
    at org.camunda.bpm.engine.impl.ProcessEngineImpl.<init>(ProcessEngineImpl.java:98)
    at org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl.buildProcessEngine(ProcessEngineConfigurationImpl.java:613)
    at org.camunda.bpm.engine.impl.test.TestHelper.getProcessEngine(TestHelper.java:524)
    at org.camunda.bpm.engine.test.ProcessEngineRule.initializeProcessEngine(ProcessEngineRule.java:172)
    at org.camunda.bpm.engine.test.ProcessEngineRule.apply(ProcessEngineRule.java:154)
    at org.junit.rules.RunRules.applyAll(RunRules.java:26)
    at org.junit.rules.RunRules.<init>(RunRules.java:15)
    at org.junit.runners.BlockJUnit4ClassRunner.withTestRules(BlockJUnit4ClassRunner.java:400)
    at org.junit.runners.BlockJUnit4ClassRunner.withRules(BlockJUnit4ClassRunner.java:356)
    at org.junit.runners.BlockJUnit4ClassRunner.methodBlock(BlockJUnit4ClassRunner.java:278)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252)
    at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141)
    at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
    at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
    at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
    at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)
Caused by: org.h2.jdbc.JdbcSQLException: Tabelle "ACT_HI_PROCINST" besteht bereits
Table "ACT_HI_PROCINST" already exists; SQL statement:
create table ACT_HI_PROCINST ( 
ID_ varchar(64) not null, 
PROC_INST_ID_ varchar(64) not null, 
BUSINESS_KEY_ varchar(255), 
PROC_DEF_KEY_ varchar(255), 
PROC_DEF_ID_ varchar(64) not null, 
START_TIME_ timestamp not null, 
END_TIME_ timestamp, 
DURATION_ bigint, 
START_USER_ID_ varchar(255), 
START_ACT_ID_ varchar(255), 
END_ACT_ID_ varchar(255), 
SUPER_PROCESS_INSTANCE_ID_ varchar(64), 
SUPER_CASE_INSTANCE_ID_ varchar(64), 
CASE_INST_ID_ varchar(64), 
DELETE_REASON_ varchar(4000), 
TENANT_ID_ varchar(64), 
primary key (ID_), 
unique (PROC_INST_ID_) 
) [42101-192]
    at org.h2.message.DbException.getJdbcSQLException(DbException.java:345)
    at org.h2.message.DbException.get(DbException.java:179)
    at org.h2.message.DbException.get(DbException.java:155)
    at org.h2.command.ddl.CreateTable.update(CreateTable.java:115)
    at org.h2.command.CommandContainer.update(CommandContainer.java:98)
    at org.h2.command.Command.executeUpdate(Command.java:258)
    at org.h2.jdbc.JdbcStatement.executeInternal(JdbcStatement.java:184)
    at org.h2.jdbc.JdbcStatement.execute(JdbcStatement.java:158)
    at org.camunda.bpm.engine.impl.db.sql.DbSqlSession.executeSchemaResource(DbSqlSession.java:623)
    ... 41 more

I think it is because the Process Engine isn’t cleared correctly.
My @Before Method looks like:

    @Rule
    public ProcessEngineRule rule = new ProcessEngineRule();

    @Before
    public void setup() {
        init(rule.getProcessEngine());

    }

My @After Method looks like:

    @After
    public void clear() throws Exception {
        reset();
    }

Does anyone have an idea, what will correct my tests?

Best wishes from Germany

Tobi

1 Like

Hi @T.Knisch,

you are right, that can happen due to dirty state of the database. You have to make sure all resources are deleted in your @After method. How are you handling deployments of processes for your test cases?

Are you using org.camunda.bpm.engine.test.util.ProcessEngineTestRule?

Cheers,
Askar.

Is there a difference in the user executing the code between running it in Eclipse versus Maven?

Are you using the same version of Maven inside Eclipse that you are running outside of Eclipse?

Are there dependencies or other factors that Eclipse is providing that a standalone version of Maven are not, such as classpath?

It almost seems like it thinks the back end database isn’t set up and so it is attempting to do that. The only time I’ve seen that be an issue is when running it with the “isAutoUpdate” set to true in the container configuration.

I am not a Java expert in any way, but those are the things that occurred to me.

Hi @aakhmerov,

We are using org.camunda.bpm.engine.test.ProcessEngineRule not
org.camunda.bpm.engine.test.**util.**ProcessEngineRule

How can I delete the resources in my @After method?

Cheers

Hi @T.Knisch,

if you use deploy method from the class that I’ve mentioned cleanup will happen automatically. Would you be still so kind to tell me how exactly business processes are deployed right now?

Cheers,
Askar

Hi @aakhmerov,

thanks for your very fast answers!

I’m not sure, what you exactly mean with our deploy process.

In our jUnit Test we have at each method:

@Deployment(resources = { "workflow.bpmn", "decision.dmn" }) 

If I want to import your mentioned Class it gives me an import error. Maybe there is a dependency missing?

Best wishes

Tobi

HI @T.Knisch,

ok, yes sorry this class is in our test packages and does not get published. But deployment annotation should be enough. Would you mind publishing your code somewhere so that I can take a look? otherwise you have to check what kind of entities remain in the database. To do that you can change h2 to be not in memory, but on filesystem and browse database content after test crash.

Cheers,
Askar

Hi @aakhmerov,

I wanted to simplify the tests and simulate the error with the simplified test classes.
At that point I noticed that there was an error in one of my test-classes.

I had

    static ProcessEngine engine = ProcessEngines.getDefaultProcessEngine();

    @Rule
    public ProcessEngineRule rule = new ProcessEngineRule(); 

instead of

@Rule
public ProcessEngineRule rule = new ProcessEngineRule(engine); 

With the parameter at new ProcessEngineRule at works with move than one class…

Sorry for that and thank you very much for your time and helpfulness!!!

Best wishes

Tobi

1 Like