View Javadoc

1   /*
2    * $Id: AbstractMessageReceiverTestCase.java 22387 2011-07-12 03:53:36Z dirk.olmes $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.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.junit4.AbstractMuleContextTestCase;
17  import org.mule.tck.testmodels.fruit.Orange;
18  
19  import org.junit.Test;
20  
21  import static org.junit.Assert.assertNotNull;
22  import static org.junit.Assert.fail;
23  
24  public abstract class AbstractMessageReceiverTestCase extends AbstractMuleContextTestCase
25  {
26      protected Service service;
27      protected InboundEndpoint endpoint;
28  
29      protected void doSetUp() throws Exception
30      {
31          service = getTestService("orange", Orange.class);
32          endpoint = getEndpoint();
33      }
34  
35      @Test
36      public void testCreate() throws Exception
37      {
38          Service service = getTestService("orange", Orange.class);
39          InboundEndpoint endpoint = getTestInboundEndpoint("Test");
40          MessageReceiver receiver = getMessageReceiver();
41  
42          assertNotNull(receiver.getEndpoint());
43  
44          try
45          {
46              receiver.setEndpoint(null);
47              fail("Provider cannot be set to null");
48          }
49          catch (IllegalArgumentException e)
50          {
51              // expected
52          }
53  
54          receiver.setEndpoint(endpoint);
55          assertNotNull(receiver.getEndpoint());
56  
57          receiver.dispose();
58      }
59  
60      public abstract MessageReceiver getMessageReceiver() throws Exception;
61  
62      /**
63       * Implementations of this method should ensure that the correct connector is set
64       * on the endpoint
65       * 
66       * @throws Exception
67       */
68      public abstract InboundEndpoint getEndpoint() throws Exception;
69  }