{
final int[] count1 = new int[]{0};
final int[] count2 = new int[]{0};
final int[] catchAllCount = new int[]{0};
DefaultOutboundRouterCollection messageRouter = new DefaultOutboundRouterCollection();
FilteringOutboundRouter filterRouter1 = new FilteringOutboundRouter()
{
@Override
public MuleEvent route(MuleEvent event)
{
count1[0]++;
return event;
}
};
FilteringOutboundRouter filterRouter2 = new FilteringOutboundRouter()
{
@Override
public MuleEvent route(MuleEvent event)
{
count2[0]++;
return event;
}
};
filterRouter1.setFilter(new PayloadTypeFilter(Exception.class));
filterRouter2.setFilter(new PayloadTypeFilter(StringBuffer.class));
messageRouter.addRoute(filterRouter1);
messageRouter.addRoute(filterRouter2);
AbstractCatchAllStrategy strategy = new AbstractCatchAllStrategy()
{
@Override
public MuleEvent doCatchMessage(MuleEvent event)
{
catchAllCount[0]++;
return null;
}
};
messageRouter.setCatchAllStrategy(strategy);
MuleSession session = getTestSession(getTestService(), muleContext);
messageRouter.process(getTestEvent("hello"));
assertEquals(1, catchAllCount[0]);
assertEquals(0, count1[0]);
assertEquals(0, count2[0]);
messageRouter.process(getTestEvent(new StringBuffer()));
assertEquals(1, catchAllCount[0]);
assertEquals(0, count1[0]);
assertEquals(1, count2[0]);
messageRouter.process(getTestEvent(new Exception()));
assertEquals(1, catchAllCount[0]);
assertEquals(1, count1[0]);
assertEquals(1, count2[0]);
}