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