Пример #1
0
  public void testFilteringOutboundRouterWithTemplates() throws Exception {
    OutboundRouterCollection messageRouter = new OutboundRouterCollection();
    messageRouter.setCatchAllStrategy(new LoggingCatchAllStrategy());

    UMOEndpoint endpoint1 = getTestEndpoint("Test1Provider", UMOEndpoint.ENDPOINT_TYPE_SENDER);
    assertNotNull(endpoint1);
    endpoint1.setEndpointURI(new MuleEndpointURI("test://foo?[barValue]"));

    FilteringOutboundRouter router = new FilteringOutboundRouter();
    PayloadTypeFilter filter = new PayloadTypeFilter(String.class);
    router.setFilter(filter);
    List endpoints = new ArrayList();
    endpoints.add(endpoint1);
    router.setEndpoints(endpoints);

    assertTrue(router.isUseTemplates());
    assertEquals(filter, router.getFilter());

    Map m = new HashMap();
    m.put("barValue", "bar");
    UMOMessage message = new MuleMessage("test event", m);

    assertTrue(router.isMatch(message));
    UMOEndpoint ep = router.getEndpoint(0, message);
    assertEquals("test://foo?bar", ep.getEndpointURI().toString());
  }
Пример #2
0
  public void testFilteringOutboundRouter() throws Exception {
    Mock session = MuleTestUtils.getMockSession();
    OutboundRouterCollection messageRouter = new OutboundRouterCollection();
    messageRouter.setCatchAllStrategy(new LoggingCatchAllStrategy());

    UMOEndpoint endpoint1 = getTestEndpoint("Test1Provider", UMOEndpoint.ENDPOINT_TYPE_SENDER);
    assertNotNull(endpoint1);

    FilteringOutboundRouter router = new FilteringOutboundRouter();
    PayloadTypeFilter filter = new PayloadTypeFilter(String.class);
    router.setFilter(filter);
    List endpoints = new ArrayList();
    endpoints.add(endpoint1);
    router.setEndpoints(endpoints);

    assertFalse(router.isUseTemplates());
    assertEquals(filter, router.getFilter());

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

    assertTrue(router.isMatch(message));

    session.expect("dispatchEvent", C.eq(message, endpoint1));
    router.route(message, (UMOSession) session.proxy(), false);
    session.verify();

    message = new MuleMessage("test event");

    session.expectAndReturn("sendEvent", C.eq(message, endpoint1), message);
    UMOMessage result = router.route(message, (UMOSession) session.proxy(), true);
    assertNotNull(result);
    assertEquals(message, result);
    session.verify();

    message = new MuleMessage(new Exception("test event"));

    assertTrue(!router.isMatch(message));

    router.setTransformer(
        new AbstractTransformer() {
          public Object doTransform(Object src, String encoding) throws TransformerException {
            return ((Exception) src).getMessage();
          }
        });

    assertTrue(router.isMatch(message));
  }