public class PolicyTestCase extends AbstractMuleTestCase
{
public void testSinglePolicy() throws Exception
{
AroundPolicy ap = new TestPolicy("test around policy");
// this is our regular chain that should get a policy applied
MessageProcessorChain chain = DefaultMessageProcessorChain.from(
new StringAppendTransformer("first"),
new StringAppendTransformer(" second"));
initialiseObject(chain);
// test registration
assertEquals("No policies should have been registered.", 0, chain.getPolicies().list().size());
chain.getPolicies().add(ap);
assertSame("Policy has not been registered.", ap, chain.getPolicies().list().iterator().next());
System.out.println(chain);
// invoke
final MuleEvent result = chain.process(getTestEvent("payload "));
assertNotNull(result);
final MuleMessage message = result.getMessage();
assertNotNull(message);
assertEquals("payload {before} first second {after}", message.getPayload());
// test cleanup
final AroundPolicy policy = chain.getPolicies().remove(ap.getName());
assertSame("Wrong policy returned?", ap, policy);
assertEquals("No policies should have been registered.", 0, chain.getPolicies().list().size());
}