@Override
 public void testDispatchToOneWayInboundTxOnly() throws Exception {
   MuleClient client = muleContext.getClient();
   client.dispatch("vm://oneway-inboundtx-in", "a", null);
   MuleMessage result = client.request("vm://dead-letter-queue", RECEIVE_TIMEOUT);
   assertNotNull(result);
 }
 public void doTestXml(String endpoint, String xml) throws Exception {
   MuleClient client = muleContext.getClient();
   client.dispatch("in", xml, null);
   MuleMessage response = client.request(endpoint, TIMEOUT * 2);
   assertNotNull(response);
   assertNotNull(response.getPayload());
   assertEquals(xml, response.getPayloadAsString());
 }
  @Test
  public void testEncryptDecrypt() throws Exception {
    String payload = "this is a super simple test. Hope it works!!!";
    MuleClient client = muleContext.getClient();

    client.send("vm://in", new DefaultMuleMessage(payload, muleContext));
    MuleMessage message = client.request("vm://out", 5000);
    assertEquals(payload, message.getPayloadAsString());
  }
 @Test
 public void testThrough() throws Exception {
   MuleClient client = muleContext.getClient();
   MuleMessage message = client.send("vm://chained", OUTBOUND_MESSAGE, null);
   assertNotNull(message);
   assertEquals(
       StringAppendTestTransformer.appendDefault(OUTBOUND_MESSAGE) + " Received",
       message.getPayloadAsString());
 }
 @Override
 public void testSendRequestResponseInbound() throws Exception {
   MuleClient client = muleContext.getClient();
   try {
     client.send("vm://requestresponse-in", "a", null);
     fail("Exception expected");
   } catch (Exception e) {
   }
 }
  @Override
  public void testDispatchToOneWayTx() throws Exception {
    MuleClient client = muleContext.getClient();
    client.dispatch("vm://onewaytx-in", "a", null);

    assertNull(client.request("vm://onewaytx-out", RECEIVE_TIMEOUT));

    // TODO Assert exception strategy was called

  }
 @Test
 public void testNotXml() throws Exception {
   logger.debug("not xml");
   MuleClient client = muleContext.getClient();
   client.dispatch("in", STRING_MESSAGE, null);
   MuleMessage response = client.request("notxml", TIMEOUT);
   assertNotNull(response);
   assertNotNull(response.getPayload());
   assertEquals(STRING_MESSAGE, response.getPayloadAsString());
 }
 @Test
 public void testGetOther() throws Exception {
   MuleClient client = muleContext.getClient();
   boolean hadError = false;
   try {
     client.request("http://127.0.0.1:8081/blah", 1000);
   } catch (ReceiveException e) {
     hadError = true;
   }
   assertTrue(hadError);
 }
Ejemplo n.º 9
0
  @Test
  public void testSyncResponse() throws Exception {
    MuleClient client = muleContext.getClient();
    String payload = "payload";

    client.send("tcp://localhost:4444", payload, null);

    MuleMessage msg = client.request("file://temp/tests/mule", 10000);
    assertNotNull(msg);
    assertEquals(payload, msg.getPayloadAsString());
  }
  @Override
  public void testSendToOneWayTx() throws Exception {
    MuleClient client = muleContext.getClient();

    try {
      client.send("vm://oneway-tx-in", "a", null);
      fail("Exception expected");
    } catch (Exception e) {
      TransactionCoordination.getInstance().getTransaction().rollback();
    }
  }
  @Override
  public void testDispatchToRequestResponseInboundOneWayOutbound() throws Exception {
    MuleClient client = muleContext.getClient();

    client.dispatch("vm://requestresponse-oneway-in", "a", null);

    // Message never gets to reciever as receiver is not polling the queue
    assertNull(client.request("vm://requestresponse-oneway-out", RECEIVE_TIMEOUT));

    // TODO Assert exception strategy was called

  }
 @Test
 public void testGetTest2() throws Exception {
   MuleClient client = muleContext.getClient();
   MuleMessage result = client.request("http://127.0.0.1:8081/test2", 1000);
   assertThat(result, is(notNullValue()));
   Object parsedJson = JSON.parse(result.getPayloadAsString());
   assertTrue(parsedJson instanceof Object[]);
   Object[] array = (Object[]) parsedJson;
   assertEquals(1, array.length);
   assertTrue(array[0] instanceof Map);
   @SuppressWarnings("unchecked")
   Map<String, Object> map = (Map<String, Object>) array[0];
   assertEquals("hello2", map.get("var1"));
   assertEquals("goodbye2", map.get("var2"));
 }
Ejemplo n.º 13
0
  @Test
  public void tcpTest() throws Exception {
    MuleClient client = muleContext.getClient();
    MuleMessage result = client.send("tcpendpoint", new DataObject(1234), null);

    assertNotNull(result);
    assertNull(result.getExceptionPayload());
    assertFalse(result.getPayload() instanceof NullPayload);

    // Assert that the expected payload has been received.
    assertTrue(result.getPayload() instanceof DataObject);

    DataObject dataObject = (DataObject) result.getPayload();

    // Assert id returned as expected (note: Echo increments id by 1)
    assertEquals(1235, (int) dataObject.getId());
  }
Ejemplo n.º 14
0
  @Test
  public void testTcpTcpRemoteSync() throws Exception {
    MuleClient client = muleContext.getClient();
    Map<String, Object> props = new HashMap<String, Object>();

    // must notify the client to wait for a response from the server
    props.put(MuleProperties.MULE_REMOTE_SYNC_PROPERTY, Boolean.TRUE);
    MuleMessage reply =
        client.send(
            ((InboundEndpoint) muleContext.getRegistry().lookupObject("echoInTcp")).getAddress(),
            new DefaultMuleMessage(message, muleContext),
            props);

    assertNotNull(reply);
    assertNotNull(reply.getPayload());
    assertEquals("Received: " + message, reply.getPayloadAsString());
  }
  @Override
  public Object onCall(MuleEventContext eventContext) throws Exception {
    logger.info("Entering onCall .....");
    MuleMessage message = eventContext.getMessage();
    List messageList = (List) message.getPayload();
    logger.info("message.getPayload() => {}", messageList);
    MuleClient client = context.getClient();
    StringBuilder aggregated = new StringBuilder("AGGREGATED [");
    for (int i = 0; i < messageList.size(); i++) {
      String messageType = (String) messageList.get(i);
      MuleMessage muleMessage = new DefaultMuleMessage(messageType, context);
      StringBuilder muleURL = new StringBuilder();
      muleMessage.setOutboundProperty("X", messageType);
      client.dispatch("jms://queue1", muleMessage);

      MuleMessage muleMessage2 = new DefaultMuleMessage(messageType, context);
      muleMessage2.setOutboundProperty("X", messageType);
      MuleMessage result = client.send("jms://queue2", muleMessage2);
      aggregated.append(result.getPayload()).append(",");
    }
    aggregated.append("]");
    logger.info("Aggregated response {}", aggregated);
    return eventContext;
  }
  private void sendMessage(String endpoint) throws Exception {
    MuleClient client = muleContext.getClient();

    client.dispatch(endpoint, "Part 1;Part 2", null);
  }
Ejemplo n.º 17
0
 public Object send(String url, Object payload) throws MuleException {
   return muleClient.send(url, payload, null).getPayload();
 }