Beispiel #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);
      }
    }
  }
Beispiel #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());
  }
Beispiel #3
0
 /**
  * The method determines the key used to store the receiver against.
  *
  * @param service the service for which the endpoint is being registered
  * @param endpoint the endpoint being registered for the service
  * @return the key to store the newly created receiver against. In this case it is the service
  *     name, which is equivilent to the Axis service name.
  */
 @Override
 protected Object getReceiverKey(Service service, InboundEndpoint endpoint) {
   if (service.getName().startsWith(CXF_SERVICE_COMPONENT_NAME)) {
     return service.getName();
   } else {
     return endpoint.getEndpointURI().getAddress();
   }
 }
Beispiel #4
0
 protected Router lookupInboundRouterFromService(String serviceName) throws Exception {
   Service c = muleContext.getRegistry().lookupService(serviceName);
   assertNotNull(c);
   List routers = c.getInboundRouter().getRouters();
   assertEquals(1, routers.size());
   assertTrue(routers.get(0) instanceof Router);
   return (Router) routers.get(0);
 }
Beispiel #5
0
 public void testPropertyExtractorResponseRouterConfig() throws Exception {
   Service d =
       muleContext.getRegistry().lookupService("propertyExtractorResponseRouterTestComponent");
   assertNotNull(d);
   ResponseRouterCollection router = d.getResponseRouter();
   assertNotNull(router);
   List routers = router.getRouters();
   assertNotNull(routers);
   assertEquals(1, routers.size());
   AbstractResponseRouter theRouter = (AbstractResponseRouter) routers.get(0);
   // the one we put in the config
   assertTrue(theRouter.getPropertyExtractor() instanceof FunctionExpressionEvaluator);
 }
  protected MuleEvent createTestOutboundEvent(MessagingExceptionHandler exceptionListener)
      throws Exception {
    Map<String, Object> props = new HashMap<String, Object>();
    props.put("prop1", "value1");
    props.put("port", 12345);

    Service svc = getTestService();
    if (exceptionListener != null) {
      svc.setExceptionListener(exceptionListener);
    }
    return new DefaultMuleEvent(
        new DefaultMuleMessage(TEST_MESSAGE, props, muleContext),
        getTestInboundEndpoint(MessageExchangePattern.REQUEST_RESPONSE),
        svc,
        getTestSession(null, muleContext));
  }
Beispiel #7
0
 public void testEndpointURIParamsConfig() {
   Service d = muleContext.getRegistry().lookupService("testPropertiesComponent");
   assertNotNull(d);
   final InboundRouterCollection router = d.getInboundRouter();
   assertNotNull(router);
   final List endpoints = router.getEndpoints();
   assertNotNull(endpoints);
   assertFalse(endpoints.isEmpty());
   final ImmutableEndpoint inboundEndpoint = (ImmutableEndpoint) endpoints.get(0);
   assertNotNull(inboundEndpoint);
   final List transformers = inboundEndpoint.getTransformers();
   assertFalse(transformers.isEmpty());
   assertNotNull(transformers.get(0));
   final List responseTransformers = inboundEndpoint.getResponseTransformers();
   assertFalse(responseTransformers.isEmpty());
   assertNotNull(responseTransformers.get(0));
 }
 protected void startService(Service service) throws Exception {
   service.start();
 }
 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);
 }