Exemple #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);
      }
    }
  }
Exemple #2
0
  public void testRequestResponseComplex2() throws Exception {
    MuleClient client = new MuleClient();

    String[] args = new String[] {"Betty", "Rubble"};
    MuleMessage result =
        client.send(
            getSoapProvider()
                + ":http://localhost:38104/mule/services/mycomponent3?method=addPerson",
            args,
            null);
    assertNotNull(result);
    assertTrue(result.getPayload() instanceof Person);
    assertEquals("Betty", ((Person) result.getPayload()).getFirstName());
    assertEquals("Rubble", ((Person) result.getPayload()).getLastName());

    // do a receive
    result =
        client.send(
            getSoapProvider()
                + ":http://localhost:38104/mule/services/mycomponent3?method=getPerson",
            "Betty",
            null);
    assertNotNull(result);
    assertTrue(result.getPayload() instanceof Person);
    assertEquals("Betty", ((Person) result.getPayload()).getFirstName());
    assertEquals("Rubble", ((Person) result.getPayload()).getLastName());
  }
Exemple #3
0
 public void testServerWithEcho() throws Exception {
   MuleClient client = new MuleClient();
   MuleMessage result = client.send("http://localhost:63081/services/Echo", msg, null);
   String resString = result.getPayloadAsString();
   //        System.out.println(resString);
   assertTrue(resString.indexOf("<test xmlns=\"http://foo\"> foo </test>") != -1);
 }
Exemple #4
0
  public void testDispatchReceiveSimple() throws Exception {
    MuleClient client = new MuleClient();
    client.dispatch("endpoint1", TEST_MESSAGE, null);

    MuleMessage result = client.request("vm://middle", 5000L);
    assertEquals(TEST_MESSAGE + " Received", result.getPayloadAsString());
  }
 @Test
 public void testExplicitReplyToAsyncSet() throws MuleException {
   MuleClient muleClient = new MuleClient(muleContext);
   MuleMessage response = muleClient.send("vm://in4", TEST_MESSAGE, null);
   // We get the original message back, not the result from the remote component
   assertEquals(TEST_MESSAGE + " TestService1", response.getPayload());
 }
  @Test
  public void testDisableTemporaryReplyOnTheConnector() throws MuleException {
    MuleClient muleClient = new MuleClient(muleContext);
    MuleMessage response = muleClient.send("vm://in3", TEST_MESSAGE, null);

    assertEquals(NullPayload.getInstance(), response.getPayload());
  }
Exemple #7
0
 public void testDelegateClass() throws Exception {
   MuleClient client = new MuleClient();
   client.dispatch(INPUT_DC_QUEUE_NAME, "test", null);
   MuleMessage message = client.request(OUTPUT_DC_QUEUE_NAME, TIMEOUT);
   assertNotNull(message);
   assertEquals(message.getPayload(), DEFUALT_OUTPUT_MESSAGE);
   client.dispose();
 }
Exemple #8
0
 public void testInvokeBinding() throws Exception {
   MuleClient client = new MuleClient();
   MuleMessage response = client.send("vm://invoker.in", TEST_MESSAGE, null);
   assertNotNull(response);
   assertNull(response.getExceptionPayload());
   assertTrue(response.getBooleanProperty(PROCESSED, false));
   String expected = "Hello " + TEST_MESSAGE + " " + MAGIC_NUMBER;
   assertEquals(expected, response.getPayload());
 }
Exemple #9
0
 public void testWithInjectedDelegate() throws Exception {
   MuleClient client = new MuleClient();
   client.dispatch(INPUT_DI_QUEUE_NAME, DEFAULT_INPUT_MESSAGE, null);
   MuleMessage reply = client.request(OUTPUT_DI_QUEUE_NAME, TIMEOUT);
   assertNotNull(reply);
   assertNull(reply.getExceptionPayload());
   // same as original input
   assertEquals(DEFAULT_INPUT_MESSAGE, reply.getPayload());
 }
  @Test
  public void testEndpointAuthenticated() throws Exception {
    MuleClient client = new MuleClient(muleContext);

    client.dispatch("jms:/messages.in", DECRYPTED_MESSAGE, null);
    MuleMessage result = client.request("jms:/messages.out", 15000);
    assertThat(result.getPayload(), is(not(instanceOf(ExceptionPayload.class))));
    assertThat(result.getPayloadAsString(), equalTo(DECRYPTED_MESSAGE));
  }
Exemple #11
0
  public void testTransformersOnProtocol() throws Exception {
    MuleClient client = new MuleClient();
    client.dispatch("protocolTransformerClient", msg, null);

    MuleMessage result = client.request("vm://in", 3000);
    assertNotNull(result);
    String resString = result.getPayloadAsString();
    System.out.println(resString);
    assertTrue(resString.indexOf("<transformed xmlns=\"http://foo\"><soap:Envelope") != -1);
  }
Exemple #12
0
  private AbstractLifecycleTracker exerciseComponent(final String serviceName) throws Exception {
    MuleClient muleClient = new MuleClient();
    final AbstractLifecycleTracker ltc =
        (AbstractLifecycleTracker)
            muleClient.send("vm://" + serviceName + ".In", null, null).getPayload();

    assertNotNull(ltc);

    return ltc;
  }
Exemple #13
0
  public void testRequestResponse() throws Throwable {
    MuleClient client = new MuleClient();

    MuleMessage result =
        client.send(
            getSoapProvider() + ":http://localhost:38104/mule/services/mycomponent2?method=echo",
            "test",
            null);
    assertNotNull(result);
    assertEquals("test", result.getPayloadAsString());
  }
 @Test
 public void testHttpResponseMove() throws Exception {
   MuleClient client = new MuleClient(muleContext);
   DefaultMuleMessage muleMessage = new DefaultMuleMessage(HTTP_BODY, muleContext);
   MuleMessage response =
       client.send("http://localhost:" + dynamicPort.getNumber() + "/resources/move", muleMessage);
   assertEquals(HTTP_BODY, response.getPayloadAsString());
   assertEquals(
       "" + HttpConstants.SC_MOVED_PERMANENTLY, response.getInboundProperty("http.status"));
   assertEquals(
       "http://localhost:9090/resources/moved", response.<Object>getInboundProperty("Location"));
 }
Exemple #15
0
  public void testDispatchReceiveComplexObjects() throws Exception {
    MuleClient client = new MuleClient();
    FruitBowl bowl = new FruitBowl(new Apple(), new Banana());
    bowl.getApple().setWashed(true);
    client.dispatch("endpoint2", bowl, null);

    MuleMessage result = client.request("vm://middle2", 5000L);
    assertTrue(result.getPayload() instanceof FruitBowl);
    assertTrue(((FruitBowl) result.getPayload()).hasApple());
    assertTrue(((FruitBowl) result.getPayload()).getApple().isWashed());
    assertTrue(((FruitBowl) result.getPayload()).hasBanana());
  }
Exemple #16
0
  public void testProxyWithDatabinding() throws Exception {
    String msg =
        "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"
            + "<soap:Body><greetMe xmlns=\"http://apache.org/hello_world_soap_http/types\"><requestType>Dan</requestType></greetMe>"
            + "</soap:Body>"
            + "</soap:Envelope>";

    MuleClient client = new MuleClient();
    MuleMessage result = client.send("http://localhost:63081/services/greeterProxy", msg, null);
    String resString = result.getPayloadAsString();
    assertTrue(resString.indexOf("greetMeResponse") != -1);
  }
Exemple #17
0
 private void doSelectOnOutbound(String endpoint) throws Exception {
   MuleClient client = new MuleClient();
   MuleMessage reply = client.send(endpoint, new DefaultMuleMessage(NullPayload.getInstance()));
   assertNotNull(reply.getPayload());
   assertTrue(reply.getPayload() instanceof List);
   List resultList = (List) reply.getPayload();
   assertTrue(resultList.size() == 1);
   assertTrue(resultList.get(0) instanceof Map);
   Map resultMap = (Map) resultList.get(0);
   assertEquals(new Integer(1), resultMap.get("TYPE"));
   assertEquals(TEST_VALUES[0], resultMap.get("DATA"));
 }
Exemple #18
0
  public void testServerClientProxy() throws Exception {
    String msg =
        "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"
            + "<soap:Body> <test xmlns=\"http://foo\"></test>"
            + "</soap:Body>"
            + "</soap:Envelope>";

    MuleClient client = new MuleClient();
    MuleMessage result = client.send("http://localhost:63081/services/proxy", msg, null);
    String resString = result.getPayloadAsString();
    assertTrue(resString.indexOf("<test xmlns=\"http://foo\"") != -1);
  }
  public void testGetEcho() throws Exception {
    // CXF has built in support for understanding GET requests. They are of the form:
    // http://host/service/OPERATION/PARAM_NAME/PARAM_VALUE

    MuleClient client = new MuleClient();
    Map<String, String> props = new HashMap<String, String>();
    props.put("http.method", "GET");
    MuleMessage result =
        client.send("http://localhost:65082/services/EchoUMO/echo/text/hello", "", props);
    assertNotNull(result);
    assertFalse(result.getPayload() instanceof NullPayload);
    XMLAssert.assertXMLEqual(expectedGetResponse, result.getPayloadAsString());
  }
Exemple #20
0
  public void testSendAndRequest() throws Exception {
    MuleClient client = new MuleClient();
    MuleMessage message =
        client.send(
            "tcp://localhost:65432",
            new DefaultMuleMessage(
                new DefaultMessageAdapter(new ByteArrayInputStream(TEST_MESSAGE.getBytes()))));
    assertNotNull(message);

    Object payload = message.getPayload();
    assertTrue(payload instanceof InputStream);
    assertEquals("Some value - set to make test ok", message.getPayloadAsString());
  }
Exemple #21
0
 public void testSelectOnOutboundByExpression() throws Exception {
   MuleClient client = new MuleClient();
   MyMessage payload = new MyMessage(2);
   MuleMessage reply = client.send("vm://terra", new DefaultMuleMessage(payload));
   assertNotNull(reply.getPayload());
   assertTrue(reply.getPayload() instanceof List);
   List resultList = (List) reply.getPayload();
   assertTrue(resultList.size() == 1);
   assertTrue(resultList.get(0) instanceof Map);
   Map resultMap = (Map) resultList.get(0);
   assertEquals(new Integer(2), resultMap.get("TYPE"));
   assertEquals(TEST_VALUES[1], resultMap.get("DATA"));
 }
  @Test
  public void testSyncMulticast() throws Exception {
    MuleClient client = new MuleClient(muleContext);
    MuleMessage result = client.send("vm://distributor.queue", new Apple(), null);

    assertNotNull(result);
    assertTrue(result instanceof MuleMessageCollection);
    MuleMessageCollection coll = (MuleMessageCollection) result;
    assertEquals(3, coll.size());
    List<?> results = (List<?>) coll.getPayload();

    assertTrue(results.contains("Apple Received in ServiceOne"));
    assertTrue(results.contains("Apple Received in ServiceTwo"));
    assertTrue(results.contains("Apple Received in ServiceThree"));
  }
 @Test
 public void testHttpResponseError() throws Exception {
   MuleClient client = new MuleClient(muleContext);
   Map<String, Object> properties = new HashMap<String, Object>();
   properties.put("errorMessage", "ERROR !!!! ");
   DefaultMuleMessage muleMessage = new DefaultMuleMessage(HTTP_BODY, properties, muleContext);
   MuleMessage response =
       client.send(
           "http://localhost:" + dynamicPort.getNumber() + "/resources/error",
           muleMessage,
           properties);
   assertTrue(response.getPayloadAsString().contains("ERROR !!!!"));
   assertEquals(
       "" + HttpConstants.SC_INTERNAL_SERVER_ERROR, response.getInboundProperty("http.status"));
 }
Exemple #24
0
  public void testRequestResponseComplex() throws Exception {
    MuleClient client = new MuleClient();

    MuleMessage result =
        client.send(
            getSoapProvider()
                + ":http://localhost:38104/mule/services/mycomponent3?method=getPerson",
            "Fred",
            null);
    assertNotNull(result);
    logger.debug(result.getPayload());
    assertTrue(result.getPayload() instanceof Person);
    assertEquals("Fred", ((Person) result.getPayload()).getFirstName());
    assertEquals("Flintstone", ((Person) result.getPayload()).getLastName());
  }
  @Test
  public void testTransformer() throws Exception {
    InputStream in = getClass().getResourceAsStream("/transformer-input-message.xml");

    MuleClient client = new MuleClient(muleContext);
    MuleMessage reply =
        client.send("vm://messageInput", new DefaultMuleMessage(in, client.getMuleContext()));

    assertNotNull(reply);
    assertNotNull(reply.getPayload());
    assertFalse(
        "The payload is a NullPayload",
        "<org.mule.transport.NullPayload></org.mule.transport.NullPayload>"
            .equals(reply.getPayload()));

    assertTrue(reportFile.exists());
  }
 @Test
 public void testHttpResponseAll() throws Exception {
   MuleClient client = new MuleClient(muleContext);
   DefaultMuleMessage muleMessage = new DefaultMuleMessage(HTTP_BODY, muleContext);
   MuleMessage response =
       client.send("http://localhost:" + dynamicPort.getNumber() + "/resources/all", muleMessage);
   assertEquals("Custom body", response.getPayloadAsString());
   assertEquals("" + HttpConstants.SC_NOT_FOUND, response.getInboundProperty("http.status"));
   assertEquals(
       "public,no-cache,must-revalidate,max-age=3600,no-transform",
       response.getInboundProperty("Cache-Control"));
   assertEquals("Thu, 01 Dec 2014 16:00:00 GMT", response.getInboundProperty("Expires"));
   assertEquals("http://localhost:9090", response.getInboundProperty("Location"));
   assertEquals("value1", response.getInboundProperty("header1"));
   Cookie[] cookies = (Cookie[]) response.getInboundProperty("Set-Cookie");
   assertEquals(2, cookies.length);
   validateCookie(cookies[0]);
   validateCookie(cookies[1]);
 }
 protected Object request(MuleClient client, String endpoint, Class<?> clazz)
     throws MuleException {
   MuleMessage message = client.request(endpoint, TIMEOUT);
   assertNotNull(message);
   assertNotNull(message.getPayload());
   assertTrue(
       message.getPayload().getClass().getName(),
       clazz.isAssignableFrom(message.getPayload().getClass()));
   return message.getPayload();
 }
Exemple #28
0
  public void testSoapActionRouting() throws Exception {
    String msg =
        "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"
            + "<soap:Body> <test xmlns=\"http://foo\"></test>"
            + "</soap:Body>"
            + "</soap:Envelope>";

    Map<String, Object> httpHeaders = new HashMap<String, Object>();

    Map<String, Object> props = new HashMap<String, Object>();
    props.put(HttpConnector.HTTP_CUSTOM_HEADERS_MAP_PROPERTY, httpHeaders);
    props.put("SOAPAction", "http://acme.com/transform");

    MuleClient client = new MuleClient();
    MuleMessage result =
        client.send("http://localhost:63081/services/routeBasedOnSoapAction", msg, props);
    String resString = result.getPayloadAsString();
    System.out.println(resString);
    assertTrue(resString.indexOf("<transformed xmlns=\"http://foo\">") != -1);
  }
  @Test
  public void vmDemoTest() throws Exception {

    MuleClient client = new MuleClient(muleContext);

    final String content = "Hi_JeeConf";

    MuleMessage receivedMessage =
        client.send(
            "vm://process.message.outbound",
            "/ftp/myFile/Hi_JeeConf",
            new HashMap<String, Object>());

    Thread.sleep(5000);

    Assert.assertNotNull(receivedMessage);

    Assert.assertEquals(content, receivedMessage.getPayloadAsString());

    client.dispose();
  }
  @Test
  public void testHttpResponseAllWithExpressions() throws Exception {
    MuleClient client = new MuleClient(muleContext);
    Map<String, Object> properties = populateProperties();

    DefaultMuleMessage muleMessage = new DefaultMuleMessage(HTTP_BODY, properties, muleContext);
    MuleMessage response =
        client.send(
            "http://localhost:" + dynamicPort.getNumber() + "/resources/allExpressions",
            muleMessage,
            properties);
    assertEquals("" + HttpConstants.SC_NOT_FOUND, response.getInboundProperty("http.status"));
    assertEquals("max-age=3600", response.getInboundProperty("Cache-Control"));
    assertEquals("Thu, 01 Dec 2014 16:00:00 GMT", response.getInboundProperty("Expires"));
    assertEquals("http://localhost:9090", response.getInboundProperty("Location"));
    assertEquals("value1", response.getInboundProperty("header1"));
    Cookie[] cookies = (Cookie[]) response.getInboundProperty("Set-Cookie");
    assertEquals(2, cookies.length);
    validateCookie(cookies[0]);
    validateCookie(cookies[1]);
  }