Guys:
I coding integration tests, starting a tomcat at integration-test phase in Maven. This is a small sample of my config:
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<version>1.6.0</version>
<configuration>
<skip>${skipTests}</skip>
...
...
</configuration>
<executions>
<execution>
<id>start-container</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start</goal>
<goal>deploy</goal>
</goals>
<configuration>
<wait>false</wait>
</configuration>
</execution>
<execution>
<id>stop-container</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<skip>true</skip>
</configuration>
<executions>
<execution>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<skip>false</skip>
<includes>
<include>**/*.java</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
By the other side, I have this test:
import com.credicuotas.enginecredito.config.EngineConstants;
/**
* Test case starting an in-memory database-backed Process Engine.
*/
public class InMemoryH2Test {
private static Logger logger = Logger.getLogger(InMemoryH2Test.class.getName());
@Rule
public ProcessEngineRule rule = new ProcessEngineRule();
private static final String PROCESS_DEFINITION_KEY = "credicuotas-engine-credito";
@Before
public void setup() {
init(rule.getProcessEngine());
}
/**
* Just tests if the process definition is deployable.
*/
@Test
@Deployment(resources = "process.bpmn")
@RequiredHistoryLevel(ProcessEngineConfiguration.HISTORY_ACTIVITY)
public void test1() {
logger.info("----------------------------------------------");
Map<String, Object> varDniOK = new HashMap<String, Object>();
varDniOK.put(EngineConstants.ENG_DNI, "31042469");
varDniOK.put(EngineConstants.ENG_CORREO, "jgomez@gmail.com");
varDniOK.put(EngineConstants.ENG_CLAVE, "1234");
ProcessInstance dniOK = processEngine().getRuntimeService().startProcessInstanceByKey(PROCESS_DEFINITION_KEY, varDniOK);
Integer cantidad = (Integer) rule.getHistoryService().createHistoricVariableInstanceQuery().variableName(EngineConstants.ENG_CANTIDAD_DNI).singleResult().getValue();
}
@Test
@Deployment(resources = "process.bpmn")
@RequiredHistoryLevel(ProcessEngineConfiguration.HISTORY_ACTIVITY)
public void test2() {
logger.info("----------------------------------------------");
Map<String, Object> varDniOK = new HashMap<String, Object>();
varDniOK.put(EngineConstants.ENG_DNI, "31042469");
varDniOK.put(EngineConstants.ENG_CORREO, "jgomez@gmail.com");
varDniOK.put(EngineConstants.ENG_CLAVE, "1234");
ProcessInstance dniOK = processEngine().getRuntimeService().startProcessInstanceByKey(PROCESS_DEFINITION_KEY, varDniOK);
Integer cantidad = (Integer) rule.getHistoryService().createHistoricVariableInstanceQuery().variableName(EngineConstants.ENG_CANTIDAD_DNI).singleResult().getValue();
}
@After
public void calculateCoverageForAllTests() throws Exception {
ProcessTestCoverage.calculate(rule.getProcessEngine());
}
}
So far so good !!
The problem is … Adding JUnit @Rule annotation in the test and using it causes cargo maven plugin to stop Tomcat prematurely. If I execute 10 tests with JUnit commenting this lines:
@Rule
public ProcessEngineRule rule = new ProcessEngineRule();
Tomcat starts, all tests run, and Tomcat stops. Adding above line causes to Tomcat stop after finishing first test. I read a LOT about cargo maven plugin, I’ve checked all your example tests to use JUnit 3 and … it happens the same thing. It seems to be a relation between process engine process and a servlet container process…
Any ideas ?