Exemplo n.º 1
0
  public void testFailingRouterRouter() throws Exception {
    UMOSession session =
        getTestSession(getTestComponent(getTestDescriptor("test", EchoComponent.class.getName())));
    OutboundMessageRouter messageRouter = new OutboundMessageRouter();
    messageRouter.setCatchAllStrategy(new LoggingCatchAllStrategy());

    UMOEndpoint endpoint1 = new MuleEndpoint("test://AlwaysFail", false);
    UMOEndpoint endpoint2 = new MuleEndpoint("test://AlwaysFail", false);

    ExceptionBasedRouter router = new ExceptionBasedRouter();
    RegExFilter filter = new RegExFilter("(.*) event");
    router.setFilter(filter);
    List endpoints = new ArrayList();
    endpoints.add(endpoint1);
    endpoints.add(endpoint2);
    router.setEndpoints(endpoints);

    assertEquals(filter, router.getFilter());

    UMOMessage message = new MuleMessage("test event", null);

    assertTrue(router.isMatch(message));

    try {
      router.route(message, session, false);
      fail("Should have thrown exception as both endpoints would have failed");
    } catch (CouldNotRouteOutboundMessageException e) {
      // expected
    }
    message = new MuleMessage("test event", null);

    UMOMessage result = null;
    try {
      result = router.route(message, session, true);
      fail("Should have thrown exception as both endpoints would have failed");
    } catch (CouldNotRouteOutboundMessageException e) {
      // expected
    }
    assertNull(result);
  }
Exemplo n.º 2
0
  public void testSuccessfulExceptionRouter() throws Exception {
    Mock session = getMockSession();
    OutboundMessageRouter messageRouter = new OutboundMessageRouter();
    messageRouter.setCatchAllStrategy(new LoggingCatchAllStrategy());

    UMOEndpoint endpoint1 = new MuleEndpoint("test://AlwaysFail", false);
    UMOEndpoint endpoint2 = new MuleEndpoint("test://AlwaysFail", false);

    UMOEndpoint endpoint3 = new MuleEndpoint("test://Dummy", false);

    ExceptionBasedRouter router = new ExceptionBasedRouter();
    RegExFilter filter = new RegExFilter("(.*) event");
    router.setFilter(filter);
    List endpoints = new ArrayList();
    endpoints.add(endpoint1);
    endpoints.add(endpoint2);
    endpoints.add(endpoint3);
    router.setEndpoints(endpoints);

    assertEquals(filter, router.getFilter());

    UMOMessage message = new MuleMessage("test event", null);

    assertTrue(router.isMatch(message));

    // Only one dispatch should be called as the others should fail
    session.expect("dispatchEvent", C.eq(message, endpoint1));
    router.route(message, (UMOSession) session.proxy(), false);
    session.verify();

    message = new MuleMessage("test event", null);

    // Only one send should be called as the others should fail
    session.expectAndReturn("sendEvent", C.eq(message, endpoint1), message);
    UMOMessage result = router.route(message, (UMOSession) session.proxy(), true);
    assertNotNull(result);
    assertEquals(message, result);
    session.verify();
  }