View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.transport;
8   
9   import org.mule.api.endpoint.InboundEndpoint;
10  import org.mule.api.service.Service;
11  import org.mule.api.transport.MessageReceiver;
12  import org.mule.tck.junit4.AbstractMuleContextTestCase;
13  import org.mule.tck.testmodels.fruit.Orange;
14  
15  import org.junit.Test;
16  
17  import static org.junit.Assert.assertNotNull;
18  import static org.junit.Assert.fail;
19  
20  public abstract class AbstractMessageReceiverTestCase extends AbstractMuleContextTestCase
21  {
22      protected Service service;
23      protected InboundEndpoint endpoint;
24  
25      protected void doSetUp() throws Exception
26      {
27          service = getTestService("orange", Orange.class);
28          endpoint = getEndpoint();
29      }
30  
31      @Test
32      public void testCreate() throws Exception
33      {
34          Service service = getTestService("orange", Orange.class);
35          InboundEndpoint endpoint = getTestInboundEndpoint("Test");
36          MessageReceiver receiver = getMessageReceiver();
37  
38          assertNotNull(receiver.getEndpoint());
39  
40          try
41          {
42              receiver.setEndpoint(null);
43              fail("Provider cannot be set to null");
44          }
45          catch (IllegalArgumentException e)
46          {
47              // expected
48          }
49  
50          receiver.setEndpoint(endpoint);
51          assertNotNull(receiver.getEndpoint());
52  
53          receiver.dispose();
54      }
55  
56      public abstract MessageReceiver getMessageReceiver() throws Exception;
57  
58      /**
59       * Implementations of this method should ensure that the correct connector is set
60       * on the endpoint
61       * 
62       * @throws Exception
63       */
64      public abstract InboundEndpoint getEndpoint() throws Exception;
65  }