Ejemplo n.º 1
1
  public void doTestRegisterListener(
      String component, String endpoint, boolean canSendWithoutReceiver) throws Exception {
    MuleClient client = new MuleClient();

    if (!canSendWithoutReceiver) {
      try {
        client.send(endpoint, "Test Client Send message", null);
        fail("There is no receiver for this endpointUri");
      } catch (Exception e) {
        assertTrue(e.getCause() instanceof NoReceiverForEndpointException);
      }
    }

    Service c = muleContext.getRegistry().lookupService(component);
    c.start();

    MuleMessage message = client.send(endpoint, "Test Client Send message", null);
    assertNotNull(message);
    assertEquals("Received: Test Client Send message", message.getPayloadAsString());

    // The SpringRegistry is read-only so we can't unregister the service!
    // muleContext.getRegistry().unregisterComponent("vmComponent");
    c.stop();

    if (!canSendWithoutReceiver) {
      try {
        message = client.send(endpoint, "Test Client Send message", null);
        fail("There is no receiver for this endpointUri");
      } catch (Exception e) {
        assertTrue(e.getCause() instanceof NoReceiverForEndpointException);
      }
    }
  }
Ejemplo n.º 2
0
  public void testReceiversServiceLifecycle() throws Exception {
    Service service = getTestService();
    service.setInboundRouter(new DefaultInboundRouterCollection());
    InboundEndpoint endpoint = getTestInboundEndpoint("in", "test://in");
    service.getInboundRouter().addEndpoint(endpoint);
    connector = (TestConnector) endpoint.getConnector();

    assertEquals(0, connector.receivers.size());

    connector.start();
    assertEquals(0, connector.receivers.size());

    service.start();
    assertEquals(1, connector.receivers.size());
    assertTrue(((AbstractMessageReceiver) connector.receivers.get("in")).isConnected());
    assertTrue(((AbstractMessageReceiver) connector.receivers.get("in")).isStarted());

    connector.stop();
    assertEquals(1, connector.receivers.size());
    assertFalse(((AbstractMessageReceiver) connector.receivers.get("in")).isConnected());
    assertFalse(((AbstractMessageReceiver) connector.receivers.get("in")).isStarted());

    connector.start();
    assertEquals(1, connector.receivers.size());
    assertTrue(((AbstractMessageReceiver) connector.receivers.get("in")).isConnected());
    assertTrue(((AbstractMessageReceiver) connector.receivers.get("in")).isStarted());

    service.stop();
    assertEquals(0, connector.receivers.size());

    connector.stop();
    assertEquals(0, connector.receivers.size());
  }
 protected void stopService(Service service) throws Exception {
   service.stop();
   // Give connector and jms broker some time to process all pending messages
   Thread.sleep(WAIT_TIME_MILLIS);
 }