1
2
3
4
5
6
7
8
9
10
11 package org.mule.test.integration.client;
12
13
14 import org.mule.api.MuleMessage;
15 import org.mule.api.service.Service;
16 import org.mule.api.transport.NoReceiverForEndpointException;
17 import org.mule.module.client.MuleClient;
18 import org.mule.tck.FunctionalTestCase;
19
20
21 public class MuleClientListenerTestCase extends FunctionalTestCase
22 {
23 protected String getConfigResources()
24 {
25 return "org/mule/test/integration/client/mule-client-listener-config.xml";
26 }
27
28 public void doTestRegisterListener(String component, String endpoint, boolean canSendWithoutReceiver) throws Exception
29 {
30 MuleClient client = new MuleClient();
31
32 if (!canSendWithoutReceiver)
33 {
34 try
35 {
36 client.send(endpoint, "Test Client Send message", null);
37 fail("There is no receiver for this endpointUri");
38 }
39 catch (Exception e)
40 {
41 assertTrue(e.getCause() instanceof NoReceiverForEndpointException);
42 }
43 }
44
45 Service c = muleContext.getRegistry().lookupService(component);
46 c.start();
47
48 MuleMessage message = client.send(endpoint, "Test Client Send message", null);
49 assertNotNull(message);
50 assertEquals("Received: Test Client Send message", message.getPayloadAsString());
51
52
53
54 c.stop();
55
56 if (!canSendWithoutReceiver)
57 {
58 try
59 {
60 message = client.send(endpoint, "Test Client Send message", null);
61 fail("There is no receiver for this endpointUri");
62 }
63 catch (Exception e)
64 {
65 assertTrue(e.getCause() instanceof NoReceiverForEndpointException);
66 }
67 }
68 }
69
70 public void testRegisterListenerVm() throws Exception
71 {
72 doTestRegisterListener("vmComponent", "vm://test.queue", false);
73 }
74
75 public void testRegisterListenerTcp() throws Exception
76 {
77 doTestRegisterListener("tcpComponent", "tcp://localhost:56324", true);
78 }
79
80 }