setStartContext(true);
}
public void testOutboundMessageRouter() throws Exception
{
Mock session = MuleTestUtils.getMockSession();
session.matchAndReturn("getFlowConstruct", getTestService());
DefaultOutboundRouterCollection messageRouter = createObject(DefaultOutboundRouterCollection.class);
messageRouter.setCatchAllStrategy(new LoggingCatchAllStrategy());
assertNotNull(messageRouter.getCatchAllStrategy());
OutboundEndpoint endpoint1 = getTestOutboundEndpoint("Test1Provider",
"test://Test1Provider?exchangePattern=one-way");
assertNotNull(endpoint1);
OutboundEndpoint endpoint2 = getTestOutboundEndpoint("Test2Provider");
assertNotNull(endpoint2);
Mock mockendpoint1 = RouterTestUtils.getMockEndpoint(endpoint1);
Mock mockendpoint2 = RouterTestUtils.getMockEndpoint(endpoint2);
FilteringOutboundRouter router1 = new FilteringOutboundRouter();
PayloadTypeFilter filter = new PayloadTypeFilter(String.class);
router1.setFilter(filter);
List<MessageProcessor> endpoints = new ArrayList<MessageProcessor>();
endpoints.add((OutboundEndpoint) mockendpoint1.proxy());
router1.setRoutes(endpoints);
FilteringOutboundRouter router2 = new FilteringOutboundRouter();
PayloadTypeFilter filter2 = new PayloadTypeFilter();
filter2.setExpectedType(Exception.class);
router2.setFilter(filter2);
endpoints = new ArrayList<MessageProcessor>();
endpoints.add((OutboundEndpoint) mockendpoint2.proxy());
router2.setRoutes(endpoints);
messageRouter.addRoute(router1);
assertEquals(1, messageRouter.getRoutes().size());
messageRouter.removeRoute(router1);
assertEquals(0, messageRouter.getRoutes().size());
List<MatchableMessageProcessor> list = new ArrayList<MatchableMessageProcessor>();
list.add(router1);
list.add(router2);
messageRouter.setMessageProcessors(list);
MuleEvent event = getTestEvent("test event", (MuleSession) session.proxy());
mockendpoint1.expect("process",RouterTestUtils.getArgListCheckerMuleEvent());
messageRouter.process(event);
mockendpoint1.verify();
event = getTestEvent(new IllegalArgumentException(), (MuleSession) session.proxy());
session.expectAndReturn("getFlowConstruct", getTestService());
mockendpoint2.expect("process", RouterTestUtils.getArgListCheckerMuleEvent());
messageRouter.process(event);
mockendpoint2.verify();
FilteringOutboundRouter router3 = new FilteringOutboundRouter();
router3.setFilter(new PayloadTypeFilter(Object.class));
endpoints = new ArrayList<MessageProcessor>();
endpoints.add((OutboundEndpoint) mockendpoint2.proxy());
router3.setRoutes(endpoints);
messageRouter.addRoute(router3);
// now the message should be routed twice to different targets
event = getTestEvent("testing multiple routing", (MuleSession) session.proxy());
session.expectAndReturn("getFlowConstruct", getTestService());
session.expectAndReturn("getFlowConstruct", getTestService());
mockendpoint1.expect("process", RouterTestUtils.getArgListCheckerMuleEvent());
mockendpoint2.expect("process", RouterTestUtils.getArgListCheckerMuleEvent());
messageRouter.setMatchAll(true);
messageRouter.process(event);
mockendpoint1.verify();
mockendpoint2.verify();
}