How to disable deploying process for test purposes?

I try to use @DataJpaTest for my application test cases, but I’ve got problems, In some reason, @DataJpaTest wants to deploy process, I have mocked ProcessEngine bean. Now when I run test, I have:

Caused by: java.lang.RuntimeException: org.camunda.bpm.engine.ProcessEngineException: ENGINE-08043 Exception while performing 'Deployment of Process Application animalProductionApplication' => 'Deployment of process archive 'null': Cannot deploy process archive 'null' to default process: no such process engine exists: processEngine is null
	at org.camunda.bpm.engine.spring.application.SpringProcessApplication.onApplicationEvent(SpringProcessApplication.java:99)
	at org.camunda.bpm.engine.spring.application.SpringProcessApplication.onApplicationEvent(SpringProcessApplication.java:48)
	at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
	at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
	at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
	at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:400)
	at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:354)
	at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:888)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:553)
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759)
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:395)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:327)
	at org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:139)
	at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:99)
	at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:117)
	... 25 more
Caused by: org.camunda.bpm.engine.ProcessEngineException: ENGINE-08043 Exception while performing 'Deployment of Process Application animalProductionApplication' => 'Deployment of process archive 'null': Cannot deploy process archive 'null' to default process: no such process engine exists: processEngine is null
	at org.camunda.bpm.container.impl.ContainerIntegrationLogger.exceptionWhilePerformingOperationStep(ContainerIntegrationLogger.java:312)
	at org.camunda.bpm.container.impl.spi.DeploymentOperation.execute(DeploymentOperation.java:132)
	at org.camunda.bpm.container.impl.jmx.MBeanServiceContainer.executeDeploymentOperation(MBeanServiceContainer.java:156)
	at org.camunda.bpm.container.impl.spi.DeploymentOperation$DeploymentOperationBuilder.execute(DeploymentOperation.java:212)
	at org.camunda.bpm.container.impl.RuntimeContainerDelegateImpl.deployProcessApplication(RuntimeContainerDelegateImpl.java:95)
	at org.camunda.bpm.application.AbstractProcessApplication.deploy(AbstractProcessApplication.java:59)
	at org.camunda.bpm.engine.spring.application.SpringProcessApplication.start(SpringProcessApplication.java:104)
	at org.camunda.bpm.engine.spring.application.SpringProcessApplication.afterPropertiesSet(SpringProcessApplication.java:113)
	at org.camunda.bpm.spring.boot.starter.SpringBootProcessApplication.afterPropertiesSet(SpringBootProcessApplication.java:74)
	at org.camunda.bpm.engine.spring.application.SpringProcessApplication.onApplicationEvent(SpringProcessApplication.java:90)
	... 39 more
Caused by: org.camunda.bpm.engine.exception.NullValueException: Cannot deploy process archive 'null' to default process: no such process engine exists: processEngine is null
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
	at org.camunda.bpm.engine.impl.util.EnsureUtil.generateException(EnsureUtil.java:344)
	at org.camunda.bpm.engine.impl.util.EnsureUtil.ensureNotNull(EnsureUtil.java:49)
	at org.camunda.bpm.engine.impl.util.EnsureUtil.ensureNotNull(EnsureUtil.java:44)
	at org.camunda.bpm.container.impl.deployment.DeployProcessArchiveStep.getProcessEngine(DeployProcessArchiveStep.java:214)
	at org.camunda.bpm.container.impl.deployment.DeployProcessArchiveStep.performOperationStep(DeployProcessArchiveStep.java:78)
	at org.camunda.bpm.container.impl.spi.DeploymentOperation.execute(DeploymentOperation.java:116)
	... 47 more

I want to know: Can I disable deploying process in my tests?

If you do not want to setup the spring-camunda engine in a data test, it should be enough to disable it via property:

camunda.bpm.enabled=false

see https://docs.camunda.org/manual/7.10/user-guide/spring-boot-integration/configuration/#camunda-engine-properties

which will look something like this:

@SpringBootTest(
  classes = {CamundaAutoConfigurationDisabledIT.NoCamundaApplication.class},
  webEnvironment = WebEnvironment.NONE,
  properties = {"camunda.bpm.enabled=false"}
)

(taken from https://github.com/camunda/camunda-bpm-spring-boot-starter/blob/master/starter/src/test/java/org/camunda/bpm/spring/boot/starter/disabled/CamundaAutoConfigurationDisabledIT.java)

1 Like

Hello @jangalinski!
I tried to add this property to application-test.properties, but I didn’t work.

In my case I don’t want to use @SpringBootTest, I want to use @DataJpaTest.

Hm. Haven’t tried this for some time now, but the test I mentioned proves that it has some effect … Maybe try to configure @TestPropertySource?

The solution was found!

my case: I wanted to test my Repositories in an application. I know, that Spring already has a good annotation for this purpose @DataJpaTest. This annotation loads application context with beans, which are needed for repository testing.

I added it to test class, with @DataJpaTest and @RunWith(SpringRunner.class) annotations. I had failed running tests because of the Camunda, which wanted to run ProcessEngine…

Next, I found, that If I remove @EnableProcessApplication annotation from my Application class, all worked as expected.

That’s why the solution is to provided TestApplication class without @EnableProcessApplication annotation.

if someone has any questions, don’t hesitate, write me

1 Like

Hello,

I encountered the same issue while I was trying to run Spring Boot’s @WebMvcTest tests.

The solution I came up with is instead of annotating the main application class with @EnableProcessApplication just add an additional config class alongside the main application class that is enabled only when property camunda.bpm.enabled is true or missing.

Please find below the code.

/**
 * This class makes it possible to completely disable Camunda via a corresponding property.
 *
 * <p>To disable this configuration, set property {@code camunda.bpm.enabled} to {@code false}.</p>
 */
@Configuration
@EnableProcessApplication
@ConditionalOnProperty(name = "camunda.bpm.enabled", havingValue = "true", matchIfMissing = true)
public class CamundaProcessApplicationConfig {

}

Having this code in place, unit tests and Spring Boot test slices don’t see this additional config class by default, and for full-blown integration tests it’s possible to disable Camunda by providing
@TestPropertySource("camunda.bpm.enabled=false").

I hope this will be helpful.

1 Like

I had the same problem and finally the solution from @symbicator worked for me. But I needed to adjust the @TestPropertySource annotation to @TestPropertySource(properties = {"camunda.bpm.enabled=false"}). The full set of annotations to my test class looks like this:

@RunWith(SpringRunner.class)
@DataJpaTest
@TestPropertySource(
  properties = {"camunda.bpm.enabled=false"}
)
public class JpaTests {...}