}
public void testRecipientListRouterSync() throws Exception
{
Mock session = MuleTestUtils.getMockSession();
session.matchAndReturn("getFlowConstruct", getTestService());
session.matchAndReturn("setFlowConstruct", RouterTestUtils.getArgListCheckerFlowConstruct(), null);
OutboundEndpoint endpoint1 = getTestOutboundEndpoint("Test1Provider");
assertNotNull(endpoint1);
List<String> recipients = new ArrayList<String>();
recipients.add("test://recipient1?exchangePattern=request-response");
recipients.add("test://recipient2?exchangePattern=request-response");
MockingStaticRecipientList router = createObject(MockingStaticRecipientList.class);
router.setRecipients(recipients);
List<MessageProcessor> endpoints = new ArrayList<MessageProcessor>();
endpoints.add(endpoint1);
router.setRoutes(endpoints);
router.setMuleContext(muleContext);
assertEquals(2, router.getRecipients().size());
MuleMessage message = new DefaultMuleMessage("test event", muleContext);
assertTrue(router.isMatch(message));
// note this router clones targets so that the endpointUri can be
// changed
// The static recipient list router duplicates the message for each endpoint
// so we can't
// check for equality on the arguments passed to the dispatch / send methods
message = new DefaultMuleMessage("test event", muleContext);
final MuleEvent event = new OutboundRoutingTestEvent(message, null, muleContext);
// Set up the mock targets as we discover them
final List<Mock> mockEndpoints = new ArrayList<Mock>();
router.setMockEndpointListener(new MockEndpointListener()
{
public void mockEndpointAdded(Mock recipient)
{
mockEndpoints.add(recipient);
recipient.expectAndReturn("process", RouterTestUtils.getArgListCheckerMuleEvent(), event);
}
});
router.getRecipients().add("test://recipient3?exchangePattern=request-response");
MuleEvent result = router.route(new OutboundRoutingTestEvent(message, (MuleSession)session.proxy(), muleContext));
assertNotNull(result);
MuleMessage resultMessage = result.getMessage();
assertNotNull(resultMessage);
assertTrue(resultMessage.getPayload() instanceof List);
assertEquals(3, ((List)resultMessage.getPayload()).size());
session.verify();
}