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