1   /*
2    * $Id: AbstractMessageReceiverTestCase.java 10961 2008-02-22 19:01:02Z 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.transport;
12  
13  import org.mule.api.endpoint.InboundEndpoint;
14  import org.mule.api.service.Service;
15  import org.mule.api.transport.MessageReceiver;
16  import org.mule.tck.AbstractMuleTestCase;
17  import org.mule.tck.testmodels.fruit.Orange;
18  
19  public abstract class AbstractMessageReceiverTestCase extends AbstractMuleTestCase
20  {
21      protected Service service;
22      protected InboundEndpoint endpoint;
23  
24      protected void doSetUp() throws Exception
25      {
26          service = getTestService("orange", Orange.class);
27          endpoint = getEndpoint();
28      }
29  
30      public void testCreate() throws Exception
31      {
32          Service service = getTestService("orange", Orange.class);
33          InboundEndpoint endpoint = getTestInboundEndpoint("Test");
34          MessageReceiver receiver = getMessageReceiver();
35  
36          assertNotNull(receiver.getEndpoint());
37          assertNotNull(receiver.getConnector());
38  
39          try
40          {
41              receiver.setEndpoint(null);
42              fail("Provider cannot be set to null");
43          }
44          catch (IllegalArgumentException e)
45          {
46              // expected
47          }
48  
49          try
50          {
51              receiver.setService(null);
52              fail("service cannot be set to null");
53          }
54          catch (IllegalArgumentException e)
55          {
56              // expected
57          }
58  
59          receiver.setService(service);
60          assertNotNull(receiver.getService());
61          receiver.setEndpoint(endpoint);
62          assertNotNull(receiver.getEndpoint());
63  
64          receiver.dispose();
65      }
66  
67      public abstract MessageReceiver getMessageReceiver() throws Exception;
68  
69      /**
70       * Implementations of this method should ensure that the correct connector is set
71       * on the endpoint
72       * 
73       * @return
74       * @throws Exception
75       */
76      public abstract InboundEndpoint getEndpoint() throws Exception;
77  }