Camunda JUnit 4 tests in a springboot application with spring cloud and other JUnit4 tests

I have a spring-boot application which makes use of camunda process and facing challenges in running JUnit Tests for camunda processes. Appreciate any help in fixing this.

The tests fail with below exception
java.lang.IllegalStateException: Failed to load ApplicationContext
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘testController’: Unsatisfied dependency expressed through field ‘testService’; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘testService’: Unsatisfied dependency expressed through field ‘processEngine’; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘processEngineFactoryBean’: FactoryBean threw exception on object creation; nested exception is org.camunda.bpm.engine.ProcessEngineException: The deployment contains definitions with the same key ‘HelloWorld’ (id attribute), this is not allowed
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘testService’: Unsatisfied dependency expressed through field ‘processEngine’; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘processEngineFactoryBean’: FactoryBean threw exception on object creation; nested exception is org.camunda.bpm.engine.ProcessEngineException: The deployment contains definitions with the same key ‘HelloWorld’ (id attribute), this is not allowed
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘processEngineFactoryBean’: FactoryBean threw exception on object creation; nested exception is org.camunda.bpm.engine.ProcessEngineException: The deployment contains definitions with the same key ‘HelloWorld’ (id attribute), this is not allowed
Caused by: org.camunda.bpm.engine.ProcessEngineException: The deployment contains definitions with the same key ‘HelloWorld’ (id attribute), this is not allowed

I do not have multiple definitions of the HelloWorld bpmn in the workspace. I also do not have @EnableProcessApplication annotation on the spring boot application class (as adding it causes unlreated JUnit 5 tests to fail with “unable to load process engine” exception). I am assuming the ProcessEngine will be autowired in the absence of this annotation.

The junit test
@RunWith(SpringJUnit4ClassRunner.class)
@ActiveProfiles(“test”)
@SpringBootTest(webEnvironment = WebEnvironment.MOCK, //
properties = {
“camunda.bpm.job-execution.enabled=false”,
“camunda.bpm.generate-unique-process-engine-name=true”,
“spring.datasource.generate-unique-name=true”,
“camunda.bpm.enabled=true” })
@Deployment(resources = “bpmn/HelloWorld.bpmn”)
public class HelloWorldProcessTest {

	private static final String PROCESS_DEFINITION_KEY = "HelloWorld";

	@Autowired
	private ProcessEngine processEngine;

	@Rule
	@ClassRule
	public static ProcessEngineRule processEngineRule;

	Map processVariables = new HashMap<String, Object>();

	@PostConstruct
	void initRule() {
		processEngineRule = TestCoverageProcessEngineRuleBuilder.create(processEngine).build();

	}

	@org.junit.Before // JUnit 4 annotation
	public void setup() {
		init(processEngine);
    //populate processVariables
	}

	@org.junit.After // Junit4 annotation
	public void tearDown() {
		processVariables.clear();
	}

	@org.junit.Test // JUnit 4 annotation
	public void testHappyPath() {
		ProcessInstance processInstance = processEngineRule.getRuntimeService()
				.startProcessInstanceByKey(PROCESS_DEFINITION_KEY, processVariables);
		assertThat(processInstance).isNotNull();
		assertThat(processInstance).isStarted();
		assertThat(processInstance).isEnded();
	}
}

The bpmn process is a simple process with a single service task, which calls a javadelegate to print helloworld.

Hi @Rajeshwari,

Have you tried removing the following line:

It seems like your process is already deployed.

Best,
Nikola

I get “no process deployed” error if i remove the line.

Adding Bean definition for ProcessEngineRule in config class solved the problem

	@Bean
public ProcessEngineRule processEngineRule(ProcessEngine processEngine) {
	return new ProcessEngineRule(processEngine);
}