コード例 #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);
      }
    }
  }
コード例 #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());
  }
コード例 #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);
 }
コード例 #4
0
 @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());
 }
コード例 #5
0
  @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());
  }
コード例 #6
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());
 }
コード例 #7
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;
  }
コード例 #8
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());
  }
コード例 #9
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);
  }
コード例 #10
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);
  }
コード例 #11
0
 @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"));
 }
コード例 #12
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"));
 }
コード例 #13
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"));
 }
コード例 #14
0
  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());
  }
コード例 #15
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());
  }
コード例 #16
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());
  }
コード例 #17
0
  @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"));
  }
コード例 #18
0
 @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"));
 }
コード例 #19
0
  @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());
  }
コード例 #20
0
 @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]);
 }
コード例 #21
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);
  }
コード例 #22
0
  @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();
  }
コード例 #23
0
  @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]);
  }
コード例 #24
0
 public void testSyncResponse() throws Exception {
   MuleClient client = new MuleClient();
   MuleMessage message = client.send("http://localhost:28081", "request", null);
   assertNotNull(message);
   assertEquals("Received: request", new String(message.getPayloadAsBytes()));
 }
コード例 #25
0
 @Test
 public void testTemporaryReplyDisabledSync() throws MuleException {
   MuleClient muleClient = new MuleClient(muleContext);
   MuleMessage response = muleClient.send("vm://in2Sync", TEST_MESSAGE, null);
   assertEquals(TEST_MESSAGE, response.getPayload());
 }