Hi All,
When doing integration testing, one usually wants to start with a
fresh deployment in order to ensure zero interference between tests,
especially if the integration tests purposefully break the environment
(or leave it in an inconsistent state).
If you want a *different* environment or deployment for the different
tests, rio seems to support multiple completely different opstring
deployments, by running multiple executions of the Failsafe plugin,
each one selecting specific tests (by class name).
If, however, you want to test multiple "scenarios" in the same
deployment, the following has been working for me (if there is a
better way, please let me know):
As example, I refer to the well-known "Workflow" example in Rio. In
the test-config.groovy, I disable automatic deployment:
ITWorkflowDeployTest
{
groups = System.getProperty('
user.name') + ".test.Workflow"
numCybernodes = 1
numMonitors = 1
opstring = 'src/test/conf/deployment.groovy'
autoDeploy = false
}
And in my integration test, I then manually deploy/undeploy the
opstring around each test case like so:
package org.rioproject.examples.workflow;
import org.junit.*;
import org.junit.runner.*;
import org.rioproject.opstring.*;
import org.rioproject.test.*;
/**
* Runs multiple integration tests, with each test being run after a
fresh deployment
* of the opstring.
*/
@RunWith(RioTestRunner.class)
public class ITWorkflowDeployTest
{
@SetTestManager
static TestManager testManager;
OperationalStringManager opStringManager;
Master master;
@Before
public void deploy() throws Exception
{
opStringManager = testManager.deploy();
master = (Master) testManager.waitForService(Master.class);
}
@After
public void undeploy() throws Exception
{
testManager.undeploy(opStringManager.getOperationalString().getName());
}
@Test
public void testBean() throws Exception
{
Assert.assertNotNull(master);
Exception thrown = null;
try
{
System.out.println("Submitting Order ...");
WorkflowEntry result = master.process();
System.out.println("Order result is : " + result.value);
} catch (Exception e)
{
e.printStackTrace();
thrown = e;
}
Assert.assertNull(thrown);
}
@Test
public void testBeanAgain() throws Exception
{
Assert.assertNotNull(master);
Exception thrown = null;
try
{
System.out.println("Submitting Order (again) ...");
WorkflowEntry result = master.process();
System.out.println("Order result is : " + result.value);
} catch (Exception e)
{
e.printStackTrace();
thrown = e;
}
Assert.assertNull(thrown);
}
}
Just thought I'd share and get some comments if I am doing it wrong.
What I do like, is that (re)deployments for each test case is nice and
fast after the initial Rio environment setup, yet one is guaranteed a
fresh environment.