예제 #1
0
 public Object getValidConvertedType() {
   try {
     return MuleTestUtils.getTestEndpoint("test://Test", UMOEndpoint.ENDPOINT_TYPE_SENDER);
   } catch (Exception e) {
     e.printStackTrace();
     fail(e.getMessage());
     return null;
   }
 }
예제 #2
0
  public void testSpiWorkThrowableHandling() throws Exception {
    try {
      // getTestComponent() currently already returns a SedaComponent, but
      // here we are safe-guarding for any future changes
      MuleDescriptor descriptor = MuleTestUtils.getTestDescriptor("test", "java.lang.Object");
      SedaComponent component = new SedaComponent(descriptor, new SedaModel());

      component.handleWorkException(getTestWorkEvent(), "workRejected");
    } catch (MuleRuntimeException mrex) {
      assertNotNull(mrex);
      assertTrue(mrex.getCause().getClass() == Throwable.class);
      assertEquals("testThrowable", mrex.getCause().getMessage());
    }
  }
예제 #3
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));
  }
예제 #4
0
  public void testMessageResequencer() throws Exception {
    Mock session = MuleTestUtils.getMockSession();
    UMOComponent testComponent = getTestComponent(getTestDescriptor("test", Apple.class.getName()));
    assertNotNull(testComponent);

    UMOInboundRouterCollection messageRouter = new InboundRouterCollection();
    SimpleEventResequencer router = new SimpleEventResequencer(3);
    messageRouter.addRouter(router);
    messageRouter.setCatchAllStrategy(new LoggingCatchAllStrategy());

    UMOMessage message1 = new MuleMessage("test event A");
    UMOMessage message2 = new MuleMessage("test event B");
    UMOMessage message3 = new MuleMessage("test event C");

    UMOEndpoint endpoint = getTestEndpoint("Test1Provider", UMOEndpoint.ENDPOINT_TYPE_SENDER);
    UMOEvent event1 = new MuleEvent(message1, endpoint, (UMOSession) session.proxy(), false);
    UMOEvent event2 = new MuleEvent(message2, endpoint, (UMOSession) session.proxy(), false);
    UMOEvent event3 = new MuleEvent(message3, endpoint, (UMOSession) session.proxy(), false);
    assertTrue(router.isMatch(event1));
    assertTrue(router.isMatch(event2));
    assertTrue(router.isMatch(event3));

    assertNull(router.process(event2));
    assertNull(router.process(event3));

    UMOEvent[] results = router.process(event1);
    assertNotNull(results);
    assertEquals(3, results.length);

    assertEquals("test event B", results[0].getMessageAsString());
    assertEquals("test event C", results[1].getMessageAsString());
    assertEquals("test event A", results[2].getMessageAsString());

    // set a resequencing comparator
    router.setComparator(new EventPayloadComparator());

    assertNull(router.process(event2));
    assertNull(router.process(event3));

    results = router.process(event1);
    assertNotNull(results);
    assertEquals(3, results.length);

    assertEquals("test event A", results[0].getMessageAsString());
    assertEquals("test event B", results[1].getMessageAsString());
    assertEquals("test event C", results[2].getMessageAsString());
  }
  @Test
  public void oneWayWithAsyncNotificationListener() throws Exception {
    CountDownLatch notificationLatch = new CountDownLatch(2);
    AsynMessageFiringNotificationListener listener =
        new AsynMessageFiringNotificationListener(notificationLatch);
    muleContext.registerListener(listener);

    MuleEvent event =
        MuleTestUtils.getTestEventUsingFlow(
            TEST_MESSAGE, MessageExchangePattern.ONE_WAY, muleContext);
    assertAsync(messageProcessor, event);
    notificationLatch.await(RECEIVE_TIMEOUT, TimeUnit.MILLISECONDS);

    // ASYNC_SCHEDULED receives same event instance as is queued
    assertThat(listener.asyncScheduledEvent, is(notNullValue()));
    assertThat(listener.asyncScheduledEvent, is(sameInstance(event)));
    assertThat(listener.asyncScheduledEvent, is(not(sameInstance(target.sensedEvent))));

    // ASYNC_COMPLETE receives same event passed to target processor
    assertThat(listener.asyncCompleteEvent, is(notNullValue()));
    assertThat(listener.asyncCompleteEvent, is(not(sameInstance(event))));
    assertThat(listener.asyncCompleteEvent, is(sameInstance(target.sensedEvent)));
  }
예제 #6
0
  public void testOutboundMessageRouter() throws Exception {
    Mock session = MuleTestUtils.getMockSession();
    session.expectAndReturn("getComponent", getTestComponent(getTestDescriptor("test", "blah")));
    OutboundRouterCollection messageRouter = new OutboundRouterCollection();
    messageRouter.setCatchAllStrategy(new LoggingCatchAllStrategy());
    assertNotNull(messageRouter.getCatchAllStrategy());

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

    UMOEndpoint endpoint2 = getTestEndpoint("Test2Provider", UMOEndpoint.ENDPOINT_TYPE_SENDER);
    assertNotNull(endpoint2);

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

    FilteringOutboundRouter router2 = new FilteringOutboundRouter();
    PayloadTypeFilter filter2 = new PayloadTypeFilter();
    filter2.setExpectedType(Exception.class);
    router2.setFilter(filter2);
    endpoints = new ArrayList();
    endpoints.add(endpoint2);
    router2.setEndpoints(endpoints);

    messageRouter.addRouter(router1);
    assertEquals(1, messageRouter.getRouters().size());
    assertNotNull(messageRouter.removeRouter(router1));
    assertEquals(0, messageRouter.getRouters().size());
    List list = new ArrayList();
    list.add(router1);
    list.add(router2);
    messageRouter.setRouters(list);

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

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

    message = new MuleMessage(new IllegalArgumentException());

    session.expectAndReturn("getComponent", getTestComponent(getTestDescriptor("test", "blah")));
    session.expect("dispatchEvent", C.eq(message, endpoint2));
    messageRouter.route(message, (UMOSession) session.proxy(), false);
    session.verify();

    FilteringOutboundRouter router3 = new FilteringOutboundRouter();
    router3.setFilter(new PayloadTypeFilter(Object.class));
    endpoints = new ArrayList();
    endpoints.add(endpoint2);
    router3.setEndpoints(endpoints);
    messageRouter.addRouter(router3);

    // now the message should be routed twice to different endpoints
    message = new MuleMessage("testing multiple routing");
    session.expectAndReturn("getComponent", getTestComponent(getTestDescriptor("test", "blah")));
    session.expectAndReturn("getComponent", getTestComponent(getTestDescriptor("test", "blah")));

    session.expect("dispatchEvent", C.eq(message, endpoint1));
    session.expect("dispatchEvent", C.eq(message, endpoint2));
    messageRouter.setMatchAll(true);
    messageRouter.route(message, (UMOSession) session.proxy(), false);
    session.verify();
  }