Coverage Report - org.mule.tck.providers.AbstractConnectorTestCase
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractConnectorTestCase
0%
0/103
0%
0/13
2
 
 1  
 /*
 2  
  * $Id: AbstractConnectorTestCase.java 7976 2007-08-21 14:26:13Z dirk.olmes $
 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.tck.providers;
 12  
 
 13  
 import org.mule.MuleException;
 14  
 import org.mule.MuleManager;
 15  
 import org.mule.config.i18n.MessageFactory;
 16  
 import org.mule.impl.MuleDescriptor;
 17  
 import org.mule.impl.endpoint.MuleEndpoint;
 18  
 import org.mule.impl.endpoint.MuleEndpointURI;
 19  
 import org.mule.impl.model.seda.SedaModel;
 20  
 import org.mule.providers.AbstractConnector;
 21  
 import org.mule.tck.AbstractMuleTestCase;
 22  
 import org.mule.tck.testmodels.fruit.Apple;
 23  
 import org.mule.umo.UMOComponent;
 24  
 import org.mule.umo.endpoint.UMOEndpoint;
 25  
 import org.mule.umo.manager.UMOManager;
 26  
 import org.mule.umo.model.UMOModel;
 27  
 import org.mule.umo.provider.UMOConnector;
 28  
 import org.mule.umo.provider.UMOMessageAdapter;
 29  
 import org.mule.umo.provider.UMOMessageDispatcherFactory;
 30  
 
 31  
 import com.mockobjects.dynamic.C;
 32  
 import com.mockobjects.dynamic.Mock;
 33  
 
 34  
 import java.beans.ExceptionListener;
 35  
 import java.util.HashMap;
 36  
 
 37  
 /**
 38  
  * <code>AbstractConnectorTestCase</code> tests common behaviour of all endpoints
 39  
  * and provides 'reminder' methods for implementation specific interface methods
 40  
  */
 41  0
 public abstract class AbstractConnectorTestCase extends AbstractMuleTestCase
 42  
 {
 43  
     protected MuleDescriptor descriptor;
 44  
 
 45  
     protected UMOConnector connector;
 46  
 
 47  
     protected UMOModel model;
 48  
 
 49  
     /*
 50  
      * (non-Javadoc)
 51  
      * 
 52  
      * @see junit.framework.TestCase#setUp()
 53  
      */
 54  
     protected void doSetUp() throws Exception
 55  
     {
 56  0
         UMOManager manager = getManager(true);
 57  0
         model = new SedaModel();
 58  0
         model.setName("default");
 59  0
         manager.registerModel(model);
 60  0
         descriptor = getTestDescriptor("apple", Apple.class.getName());
 61  0
         MuleManager.getInstance().start();
 62  0
         connector = getConnector();
 63  0
     }
 64  
 
 65  
     protected void doTearDown() throws Exception
 66  
     {
 67  0
         if (!connector.isDisposed())
 68  
         {
 69  0
             connector.dispose();
 70  
         }
 71  0
     }
 72  
 
 73  
     public void testConnectorExceptionHandling() throws Exception
 74  
     {
 75  0
         assertNotNull(connector);
 76  
 
 77  
         // Text exception handler
 78  0
         Mock ehandlerMock = new Mock(ExceptionListener.class, "exceptionHandler");
 79  
 
 80  0
         ehandlerMock.expect("exceptionThrown", C.isA(Exception.class));
 81  
 
 82  0
         assertNotNull(connector.getExceptionListener());
 83  0
         connector.setExceptionListener((ExceptionListener) ehandlerMock.proxy());
 84  0
         connector.handleException(new MuleException(MessageFactory.createStaticMessage("Dummy")));
 85  
 
 86  0
         if (connector instanceof AbstractConnector)
 87  
         {
 88  0
             ehandlerMock.expect("exceptionThrown", C.isA(Exception.class));
 89  0
             ((AbstractConnector) connector).exceptionThrown(new MuleException(
 90  
                 MessageFactory.createStaticMessage("Dummy")));
 91  
         }
 92  
 
 93  0
         ehandlerMock.verify();
 94  
 
 95  0
         connector.setExceptionListener(null);
 96  
         try
 97  
         {
 98  0
             connector.handleException(new MuleException(MessageFactory.createStaticMessage("Dummy")));
 99  0
             fail("Should have thrown exception as no strategy is set");
 100  
         }
 101  0
         catch (RuntimeException e)
 102  
         {
 103  
             // expected
 104  0
         }
 105  0
     }
 106  
 
 107  
     public void testConnectorLifecycle() throws Exception
 108  
     {
 109  0
         assertNotNull(connector);
 110  
 
 111  0
         assertTrue(!connector.isStarted());
 112  0
         assertTrue(!connector.isDisposed());
 113  0
         connector.startConnector();
 114  0
         assertTrue(connector.isStarted());
 115  0
         assertTrue(!connector.isDisposed());
 116  0
         connector.stopConnector();
 117  0
         assertTrue(!connector.isStarted());
 118  0
         assertTrue(!connector.isDisposed());
 119  0
         connector.dispose();
 120  0
         assertTrue(!connector.isStarted());
 121  0
         assertTrue(connector.isDisposed());
 122  
 
 123  
         try
 124  
         {
 125  0
             connector.startConnector();
 126  0
             fail("Connector cannot be restarted after being disposing");
 127  
         }
 128  0
         catch (Exception e)
 129  
         {
 130  
             // expected
 131  0
         }
 132  0
     }
 133  
 
 134  
     public void testConnectorListenerSupport() throws Exception
 135  
     {
 136  0
         assertNotNull(connector);
 137  
 
 138  0
         MuleDescriptor d = getTestDescriptor("anApple", Apple.class.getName());
 139  
 
 140  0
         UMOComponent component = model.registerComponent(d);
 141  0
         UMOEndpoint endpoint = new MuleEndpoint("test", new MuleEndpointURI(getTestEndpointURI()), connector,
 142  
             null, UMOEndpoint.ENDPOINT_TYPE_SENDER, 0, null, new HashMap());
 143  
 
 144  
         try
 145  
         {
 146  0
             connector.registerListener(null, null);
 147  0
             fail("cannot register null");
 148  
         }
 149  0
         catch (Exception e)
 150  
         { /* expected */
 151  0
         }
 152  
 
 153  
         try
 154  
         {
 155  0
             connector.registerListener(null, endpoint);
 156  0
             fail("cannot register null");
 157  
         }
 158  0
         catch (Exception e)
 159  
         { /* expected */
 160  0
         }
 161  
 
 162  
         try
 163  
         {
 164  0
             connector.registerListener(component, null);
 165  0
             fail("cannot register null");
 166  
         }
 167  0
         catch (Exception e)
 168  
         { /* expected */
 169  0
         }
 170  
 
 171  0
         connector.registerListener(component, endpoint);
 172  
 
 173  
         // this should work
 174  0
         connector.unregisterListener(component, endpoint);
 175  
         // so should this
 176  
         try
 177  
         {
 178  0
             connector.unregisterListener(null, null);
 179  0
             fail("cannot unregister null");
 180  
         }
 181  0
         catch (Exception e)
 182  
         {
 183  
             // expected
 184  0
         }
 185  
         try
 186  
         {
 187  0
             connector.unregisterListener(component, null);
 188  0
             fail("cannot unregister null");
 189  
         }
 190  0
         catch (Exception e)
 191  
         {
 192  
             // expected
 193  0
         }
 194  
 
 195  
         try
 196  
         {
 197  0
             connector.unregisterListener(null, endpoint);
 198  0
             fail("cannot unregister null");
 199  
         }
 200  0
         catch (Exception e)
 201  
         {
 202  
             // expected
 203  0
         }
 204  0
         connector.unregisterListener(component, endpoint);
 205  0
         model.unregisterComponent(d);
 206  0
     }
 207  
 
 208  
     public void testConnectorBeanProps() throws Exception
 209  
     {
 210  0
         assertNotNull(connector);
 211  
 
 212  
         try
 213  
         {
 214  0
             connector.setName(null);
 215  0
             fail("Should throw IllegalArgumentException if name set to null");
 216  
         }
 217  0
         catch (IllegalArgumentException e)
 218  
         { /* expected */
 219  0
         }
 220  
 
 221  0
         connector.setName("Test");
 222  0
         assertEquals("Test", connector.getName());
 223  
 
 224  0
         assertNotNull("Protocol must be set as a constant", connector.getProtocol());
 225  
 
 226  0
     }
 227  
 
 228  
     public void testConnectorMessageAdapter() throws Exception
 229  
     {
 230  0
         UMOConnector connector = getConnector();
 231  0
         assertNotNull(connector);
 232  0
         UMOMessageAdapter adapter = connector.getMessageAdapter(getValidMessage());
 233  0
         assertNotNull(adapter);
 234  0
     }
 235  
 
 236  
     public void testConnectorMessageDispatcherFactory() throws Exception
 237  
     {
 238  0
         UMOConnector connector = getConnector();
 239  0
         assertNotNull(connector);
 240  
         
 241  0
         UMOMessageDispatcherFactory factory = connector.getDispatcherFactory();
 242  0
         assertNotNull(factory);
 243  0
     }
 244  
 
 245  
     public void testConnectorInitialise() throws Exception
 246  
     {
 247  0
         UMOConnector connector = getConnector();
 248  
 
 249  
         try
 250  
         {
 251  0
             connector.initialise();
 252  0
             fail("A connector cannot be initialised more than once");
 253  
         }
 254  0
         catch (Exception e)
 255  
         {
 256  
             // expected
 257  0
         }
 258  0
     }
 259  
 
 260  
     public abstract UMOConnector getConnector() throws Exception;
 261  
 
 262  
     public abstract Object getValidMessage() throws Exception;
 263  
 
 264  
     public abstract String getTestEndpointURI();
 265  
 }