I am not able to solve the below exception whenever I try to run the below JUnit test for Activiti with Spring Boot.
Exception:
2015-05-07 20:15:00 org.springframework.test.context.TestContext.<init>(93@main) INFO @ContextConfiguration not found for class [class ProcessXTest].
2015-05-07 20:15:00 org.springframework.test.context.TestContextManager.retrieveTestExecutionListeners(143@main) INFO @TestExecutionListeners is not present for class [class ProcessXTest]: using defaults.
2015-05-07 20:15:00 org.springframework.test.context.TestContextManager.prepareTestInstance(234@main) ERROR Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionListener@232023ff] to prepare test instance [ProcessXTest@131b4c5d]
java.lang.IllegalArgumentException: Can not build an ApplicationContext with a NULL 'contextLoader'. Consider annotating your test class with @ContextConfiguration.
JUnit test:
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = { Application.class })
public class ProcessXTest {
private static final Logger LOGGER = LoggerFactory.getLogger(ProcessXTest.class);
private static final String BPMN_LOCATION = "./src/main/resources/processes/processx.bpmn";
private static final String BPMN_NAME = "processx.bpmn";
private static final String PROCESS_KEY = "processx";
@Rule
public ActivitiRule activitiRule = new ActivitiRule();
@Before
public void loadProces() throws FileNotFoundException {
LOGGER.debug("Loading the model for unit testing.");
RepositoryService repositoryService = activitiRule.getRepositoryService();
Deployment deployment = repositoryService.createDeployment().addInputStream(BPMN_NAME, new FileInputStream(BPMN_LOCATION)).deploy();
assertNotNull(deployment.getId());
assertTrue(repositoryService.getDeploymentResourceNames(deployment.getId()).contains(bpmnName));
}
@Test
public void testProces() {
LOGGER.debug("Unit testing the process.");
TaskService taskService = activitiRule.getTaskService();
List<Task> tasks = taskService.createTaskQuery().list();
assertEquals(tasks.size(), 0);
ProcessInstance processInstance = activitiRule.getRuntimeService().startProcessInstanceByKey(PROCESS_KEY, new HashMap<String, Object>());
assertNotNull(processInstance.getId());
tasks = taskService.createTaskQuery().list();
assertEquals(tasks.size(), 1);
}
}
Main application class (all beans are defined in this class and for this reason no external XML context configuration file is used):
@SpringBootApplication
@EnableConfigurationProperties
public class Application {
public static void main(final String[] args) {
SpringApplication.run(Application.class, args);
}
@Bean
public CommandLineRunner init() {
return new CommandLineRunner() {
@Override
public void run(final String... strings) throws Exception {
// initialization on start-up
}
};
}
...more beans
}
I am using the below dependencies:
compile 'org.activiti:activiti-engine:5.17.0'
compile 'org.activiti:spring-boot-starter-basic:5.17.0'
compile 'org.activiti:spring-boot-starter-rest-api:5.17.0'
compile 'junit:junit:4.12'
compile 'org.springframework.boot:spring-boot-starter-web:1.2.3.RELEASE'
compile 'org.springframework.boot:spring-boot-starter-test:1.2.3.RELEASE'