1   /*
2    * $Id: MuleClientListenerTestCase.java 10789 2008-02-12 20:04:43Z dfeist $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
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          // The SpringRegistry is read-only so we can't unregister the service!
53          //muleContext.getRegistry().unregisterComponent("vmComponent");
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  }