예제 #1
0
 public void run() {
   int i = 0;
   try {
     Thread.sleep(2000);
     MuleClient client = new MuleClient();
     MuleMessage result = null;
     for (i = 0; i < numberOfRequests; i++) {
       try {
         result = client.request("CustomerResponses", getDelay());
       } catch (MuleException e) {
         exListener.exceptionThrown(e);
         break;
       }
       // System.out.println("Received: " + i);
       assertNotNull("Result is null", result);
       assertFalse("Result is null", result.getPayload() instanceof NullPayload);
       assertTrue(
           "Result should be LoanQuote but is " + result.getPayload().getClass().getName(),
           result.getPayload() instanceof LoanQuote);
       LoanQuote quote = (LoanQuote) result.getPayload();
       assertTrue(quote.getInterestRate() > 0);
     }
   } catch (Throwable e) {
     // e.printStackTrace();
     System.out.println(StringMessageUtils.getBoilerPlate("Processed Messages=" + i));
     if (e instanceof Error) {
       // throw (Error)e;
       exListener.exceptionThrown(new Exception(e));
     } else {
       exListener.exceptionThrown((Exception) e);
     }
   } finally {
     latch.countDown();
   }
 }
예제 #2
0
  public void testReceivesWithTemplates() throws Exception {
    if (!isPrereqsMet("org.mule.providers.gs.GSFunctionalTestCase.testReceivesWithTemplates()")) {
      return;
    }

    MuleClient client = new MuleClient();
    Order order = new Order();
    order.setProcessed(Boolean.FALSE);
    client.send("gs:java://localhost/mule-space_container/mule-space?schema=cache", order, null);
    Thread.sleep(2000L);

    assertEquals(1, unprocessedCount);
    assertEquals(0, processedCount);
    client.send("gs:java://localhost/mule-space_container/mule-space?schema=cache", order, null);
    Thread.sleep(1000L);
    assertEquals(2, unprocessedCount);
    assertEquals(0, processedCount);

    order.setProcessed(Boolean.TRUE);
    client.send("gs:java://localhost/mule-space_container/mule-space?schema=cache", order, null);
    Thread.sleep(1000L);
    assertEquals(1, processedCount);
    assertEquals(2, unprocessedCount);
    client.send("gs:java://localhost/mule-space_container/mule-space?schema=cache", order, null);
    Thread.sleep(1000L);
    assertEquals(2, processedCount);
    assertEquals(2, unprocessedCount);
  }
예제 #3
0
  public void testRequestResponseComplex2() throws Exception {
    MuleClient client = new MuleClient();
    RemoteDispatcher dispatcher = client.getRemoteDispatcher("tcp://localhost:38100");
    try {
      String[] args = new String[] {"Betty", "Rubble"};
      UMOMessage result =
          dispatcher.sendRemote(
              "axis: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(
              "axis: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());
    } finally {
      client.dispose();
    }
  }
예제 #4
0
  public void testReceivingASubscriptionEvent() throws Exception {
    OrderManagerBean subscriptionBean = (OrderManagerBean) context.getBean("orderManager");
    assertNotNull(subscriptionBean);
    // when an event is received by 'testEventBean1' this callback will be invoked
    EventCallback callback =
        new EventCallback() {
          public void eventReceived(UMOEventContext context, Object o) throws Exception {
            eventCount++;
          }
        };
    subscriptionBean.setEventCallback(callback);

    MuleManager.getConfiguration().setSynchronous(true);
    MuleClient client = new MuleClient();
    Order order = new Order("Sausage and Mash");
    client.send("jms://orders.queue", order, null);
    Thread.sleep(1000);
    assertTrue(eventCount == 1);

    UMOMessage result = client.receive("jms://processed.queue", 10000);
    assertEquals(1, eventCount);
    assertNotNull(result);
    assertEquals(
        "Order 'Sausage and Mash' Processed", ((TextMessage) result.getPayload()).getText());
  }
예제 #5
0
  public void testClientDispatchAndReceiveOnReplyTo() throws Exception {
    MuleClient client = new MuleClient();
    MuleManager.getConfiguration().setSynchronous(false);

    Map props = new HashMap();
    props.put(JmsConstants.JMS_REPLY_TO, "replyTo.queue");

    long start = System.currentTimeMillis();
    int i = 0;
    for (i = 0; i < INTERATIONS; i++) {
      System.out.println("Sending message " + i);
      client.dispatch(getDispatchUrl(), "Test Client Dispatch message " + i, props);
    }
    long time = System.currentTimeMillis() - start;
    System.out.println("It took " + time + " ms to send " + i + " messages");

    Thread.sleep(5000);
    start = System.currentTimeMillis();
    for (i = 0; i < INTERATIONS; i++) {
      UMOMessage message = client.receive("jms://replyTo.queue", 5000);
      assertNotNull("message should not be null from Reply queue", message);
      System.out.println("Count is " + i);
      System.out.println("ReplyTo Message is: " + message.getPayloadAsString());
      assertTrue(message.getPayloadAsString().startsWith("Received"));
    }
    time = System.currentTimeMillis() - start;
    System.out.println("It took " + time + "ms to receive " + i + " messages");
  }
예제 #6
0
  public void testRemovingListeners() throws Exception {
    TestSubscriptionEventBean subscriptionBean =
        (TestSubscriptionEventBean) context.getBean("testSubscribingEventBean1");
    assertNotNull(subscriptionBean);
    MuleEventMulticaster multicaster =
        (MuleEventMulticaster)
            context.getBean(AbstractApplicationContext.APPLICATION_EVENT_MULTICASTER_BEAN_NAME);
    assertNotNull(multicaster);

    Latch whenFinished = new Latch();
    subscriptionBean.setEventCallback(new CountingEventCallback(eventCounter1, 1, whenFinished));

    multicaster.removeApplicationListener(subscriptionBean);
    MuleClient client = new MuleClient();
    client.send("vm://event.multicaster", "Test Spring Event", null);

    assertEquals(0, eventCounter1.get());

    multicaster.addApplicationListener(subscriptionBean);
    client.send("vm://event.multicaster", "Test Spring Event", null);

    assertTrue(whenFinished.await(3000, TimeUnit.MILLISECONDS));
    assertEquals(1, eventCounter1.get());
    eventCounter1.set(0);

    multicaster.removeAllListeners();
    client.send("vm://event.multicaster", "Test Spring Event", null);

    assertEquals(0, eventCounter1.get());
    multicaster.addApplicationListener(subscriptionBean);
    context.refresh();
    subscriptionBean.setEventCallback(null);
  }
예제 #7
0
 public void testTransactionSyncEndpoint() throws Exception {
   success = true;
   MuleClient client = new MuleClient();
   MuleMessage message = client.send("vm://sync?connector=vm", "TEST", null);
   assertNotNull(message);
   assertTrue(success);
 }
예제 #8
0
 public void testFunctionBehaviour() throws Exception {
   MuleClient client = new MuleClient();
   UMOMessage m = client.send("vm://localhost/groovy.1", "Groovy Test: ", null);
   assertNotNull(m);
   assertEquals(
       "Groovy Test: Received by component 1: Received by component 2:", m.getPayloadAsString());
 }
예제 #9
0
 public void testNoArgsCallWrapper() throws Exception {
   MuleClient client = new MuleClient();
   client.dispatch("vm://invoke", "test", null);
   UMOMessage reply = client.receive("vm://out", RECEIVE_TIMEOUT);
   assertNotNull(reply);
   assertNull(reply.getExceptionPayload());
   assertEquals("Just an apple.", reply.getPayload());
 }
예제 #10
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();
 }
예제 #11
0
 public void testTransactionQueueEventsFalse() throws Exception {
   success = true;
   MuleClient client = new MuleClient();
   client.dispatch("vm://int3?connector=vmOnFly", "TEST", null);
   MuleMessage message = client.request("vm://outt3?connector=vm", 10000);
   assertNotNull(message);
   assertTrue(success);
 }
예제 #12
0
 public void testAuthenticationNotAuthorised() throws Exception {
   try {
     MuleClient client = new MuleClient();
     client.send("vm://localhost/echo", new String("An unsigned message"), null);
     fail("The request is not signed");
   } catch (UnauthorisedException e) {
     // ignore
   }
 }
예제 #13
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());
 }
예제 #14
0
 public void testAuthenticationFailureNoContext() throws Exception {
   MuleClient client = new MuleClient();
   UMOMessage m = client.send("vm://my.queue", "foo", null);
   assertNotNull(m);
   assertNotNull(m.getExceptionPayload());
   assertEquals(
       ExceptionHelper.getErrorCode(CredentialsNotSetException.class),
       m.getExceptionPayload().getCode());
 }
예제 #15
0
 public void testWithInjectedDelegate() throws Exception {
   MuleClient client = new MuleClient();
   client.dispatch("vm://invokeWithInjected", "test", null);
   UMOMessage reply = client.receive("vm://outWithInjected", RECEIVE_TIMEOUT);
   assertNotNull(reply);
   assertNull(reply.getExceptionPayload());
   // same as original input
   assertEquals("test", reply.getPayload());
 }
예제 #16
0
  public void testSendAndReceive() throws Exception {
    if (true) {
      throw new Exception("This test hangs - remove this exception when a fix has been added");
    }
    MuleClient client = new MuleClient();

    UMOMessage message = client.send("tcp://localhost:65432", TEST_MESSAGE, new HashMap());

    assertNotNull(message);
  }
예제 #17
0
  public void testMuleXaTopic() throws Exception {
    UMOMessage result = null;
    MuleClient client = new MuleClient();
    client.dispatch("vm://in", DEFAULT_INPUT_MESSAGE, null);
    result = client.request("vm://out", TIMEOUT);
    assertNotNull(result);
    result = client.request("vm://out", TIMEOUT);
    assertNotNull(result);
    result = client.request("vm://out", SMALL_TIMEOUT);
    assertNull(result);

    managementContext.getRegistry().lookupConnector(CONNECTOR1_NAME).stop();
    assertEquals(
        managementContext.getRegistry().lookupConnector(CONNECTOR1_NAME).isStarted(), false);
    logger.info(CONNECTOR1_NAME + " is stopped");
    client.dispatch("vm://in", DEFAULT_INPUT_MESSAGE, null);
    Thread.sleep(1000);
    managementContext.getRegistry().lookupConnector(CONNECTOR1_NAME).start();
    Thread.sleep(1000);
    logger.info(CONNECTOR1_NAME + " is started");
    result = client.request("vm://out", TIMEOUT);
    assertNotNull(result);
    result = client.request("vm://out", TIMEOUT);
    assertNotNull(result);
    result = client.request("vm://out", SMALL_TIMEOUT);
    assertNull(result);
  }
예제 #18
0
  public void testAuthenticationAuthorised() throws Exception {
    URL url = Thread.currentThread().getContextClassLoader().getResource("./encrypted-signed.asc");

    int length = (int) new File(url.getFile()).length();
    byte[] msg = new byte[length];

    FileInputStream in = new FileInputStream(url.getFile());
    in.read(msg);
    in.close();

    MuleClient client = new MuleClient();
    client.send("vm://localhost/echo", new String(msg), null);
  }
예제 #19
0
 public void testRequestResponse() throws Throwable {
   MuleClient client = new MuleClient();
   RemoteDispatcher dispatcher = client.getRemoteDispatcher("tcp://localhost:38100");
   try {
     UMOMessage result =
         dispatcher.sendRemote(
             "axis:http://localhost:38104/mule/services/mycomponent2?method=echo", "test", null);
     assertNotNull(result);
     assertEquals("test", result.getPayloadAsString());
   } finally {
     client.dispose();
   }
 }
예제 #20
0
  public void testCaseBadPassword() throws Exception {
    MuleClient client = new MuleClient();
    Map props = new HashMap();
    UMOEncryptionStrategy strategy =
        MuleManager.getInstance().getSecurityManager().getEncryptionStrategy("PBE");
    String header = MuleCredentials.createHeader("Marie.Rizzo", "evil", "PBE", strategy);
    props.put(MuleProperties.MULE_USER_PROPERTY, header);
    UMOMessage m = client.send("vm://test", "Test", props);

    assertNotNull(m);
    assertTrue(m.getPayload() instanceof String);
    assertFalse(m.getPayloadAsString().equals("Test Received"));
  }
예제 #21
0
  public void testAuthenticationAuthorised() throws Exception {
    MuleClient client = new MuleClient();

    Map props = new HashMap();
    UMOEncryptionStrategy strategy =
        MuleManager.getInstance().getSecurityManager().getEncryptionStrategy("PBE");
    String header = MuleCredentials.createHeader("anon", "anon", "PBE", strategy);
    props.put(MuleProperties.MULE_USER_PROPERTY, header);

    UMOMessage m = client.send("vm://my.queue", "foo", props);
    assertNotNull(m);
    assertNull(m.getExceptionPayload());
  }
예제 #22
0
  public void testAuthenticationAuthorisedHttp() throws Exception {
    MuleClient client = new MuleClient();

    Map props = new HashMap();
    UMOEncryptionStrategy strategy =
        MuleManager.getInstance().getSecurityManager().getEncryptionStrategy("PBE");
    String header = MuleCredentials.createHeader("anon", "anon", "PBE", strategy);
    props.put(MuleProperties.MULE_USER_PROPERTY, header);

    UMOMessage m = client.send("http://localhost:4567/index.html", "", props);
    assertNotNull(m);
    int status = m.getIntProperty(HttpConnector.HTTP_STATUS_PROPERTY, -1);
    assertEquals(HttpConstants.SC_OK, status);
  }
예제 #23
0
  public void testReceivingANonSubscriptionMuleEvent() throws Exception {
    TestMuleEventBean bean = (TestMuleEventBean) context.getBean("testNonSubscribingMuleEventBean");
    assertNotNull(bean);

    // register a callback
    Latch whenFinished = new Latch();
    bean.setEventCallback(new CountingEventCallback(eventCounter1, 1, whenFinished));

    MuleClient client = new MuleClient();
    client.send("vm://event.multicaster", "Test Spring Event", null);

    whenFinished.await(3000, TimeUnit.MILLISECONDS);
    assertEquals(1, eventCounter1.get());
  }
예제 #24
0
  public void testReceivingAllEvents() throws Exception {
    TestAllEventBean bean = (TestAllEventBean) context.getBean("testAllEventBean");
    assertNotNull(bean);

    Latch whenFinished = new Latch();
    bean.setEventCallback(new CountingEventCallback(eventCounter1, 2, whenFinished));

    MuleClient client = new MuleClient();
    client.send("vm://event.multicaster", "Test Spring Event", null);
    context.publishEvent(new TestApplicationEvent(context));

    whenFinished.await(3000, TimeUnit.MILLISECONDS);
    assertEquals(2, eventCounter1.get());
  }
예제 #25
0
  public void testEchoService() throws Exception {
    String msg =
        "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"
            + "<soap:Body>"
            + "<test> foo </test>"
            + "</soap:Body>"
            + "</soap:Envelope>";

    MuleClient client = new MuleClient();
    MuleMessage result = client.send("http://localhost:63081/services/Echo", msg, null);
    String resString = result.getPayloadAsString();

    assertTrue(resString.indexOf("<test> foo </test>") != -1);
  }
예제 #26
0
  public void testExceptionStrategyForTransformerExceptionAsync() throws Exception {
    MuleClient client = new MuleClient();

    UMOMessage message = client.receive("vm://error.queue", 2000);
    assertNull(message);

    client.dispatch("vm://component.in", "test", null);

    message = client.receive("vm://component.out", 2000);
    assertNull(message);

    message = client.receive("vm://error.queue", 2000);
    assertNotNull(message);
    Object payload = message.getPayload();
    assertTrue(payload instanceof ExceptionMessage);
  }
예제 #27
0
 public void request(LoanRequest request, boolean sync) throws Exception {
   if (!sync) {
     client.dispatch("vm://LoanBrokerRequests", request, null);
     System.out.println("Sent Async request");
     // let the request catch up
     Thread.sleep(1500);
   } else {
     UMOMessage result = client.send("vm://LoanBrokerRequests", request, null);
     if (result == null) {
       System.out.println(
           "A result was not received, an error must have occurred. Check the logs.");
     } else {
       System.out.println("Loan Consumer received a Quote: " + result.getPayload());
     }
   }
 }
예제 #28
0
  public void testSingleLoanRequest() throws Exception {
    MuleClient client = new MuleClient();
    Customer c = new Customer("Ross Mason", 1234);
    CustomerQuoteRequest request = new CustomerQuoteRequest(c, 100000, 48);
    // Send asynchronous request
    client.dispatch("CustomerRequests", request, null);

    // Wait for asynchronous response
    MuleMessage result = client.request("CustomerResponses", getDelay());
    assertNotNull("Result is null", result);
    assertFalse("Result is null", result.getPayload() instanceof NullPayload);
    assertTrue(
        "Result should be LoanQuote but is " + result.getPayload().getClass().getName(),
        result.getPayload() instanceof LoanQuote);
    LoanQuote quote = (LoanQuote) result.getPayload();
    assertTrue(quote.getInterestRate() > 0);
  }
예제 #29
0
 protected MuleMessage receiveMessage() throws Exception {
   MuleMessage result = client.request(DEFAULT_OUTPUT_MULE_QUEUE_NAME, TIMEOUT);
   assertNotNull(result);
   assertNotNull(result.getPayload());
   assertNull(result.getExceptionPayload());
   assertEquals(DEFAULT_OUTPUT_MESSAGE, result.getPayload());
   return result;
 }
예제 #30
0
  public void testRequestResponse() throws Throwable {
    MuleClient client = new MuleClient();

    List results = new ArrayList();
    int number = 100;
    for (int i = 0; i < number; i++) {
      results.add(
          client
              .send(getProtocol() + ":" + getRequestResponseEndpoint(), "Message " + i, null)
              .getPayload());
    }

    assertEquals(number, results.size());
    for (int i = 0; i < number; i++) {
      assertEquals("Message " + i, results.get(i).toString());
    }
  }