Coverage Report - org.mule.tck.functional.AbstractProviderFunctionalTestCase
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractProviderFunctionalTestCase
0%
0/50
0%
0/3
1.267
AbstractProviderFunctionalTestCase$1
0%
0/9
0%
0/1
1.267
 
 1  
 /*
 2  
  * $Id: AbstractProviderFunctionalTestCase.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.functional;
 12  
 
 13  
 import org.mule.MuleManager;
 14  
 import org.mule.config.PoolingProfile;
 15  
 import org.mule.impl.DefaultExceptionStrategy;
 16  
 import org.mule.impl.MuleDescriptor;
 17  
 import org.mule.impl.endpoint.MuleEndpoint;
 18  
 import org.mule.impl.model.seda.SedaModel;
 19  
 import org.mule.tck.AbstractMuleTestCase;
 20  
 import org.mule.umo.UMOComponent;
 21  
 import org.mule.umo.UMODescriptor;
 22  
 import org.mule.umo.UMOEventContext;
 23  
 import org.mule.umo.endpoint.UMOEndpoint;
 24  
 import org.mule.umo.endpoint.UMOEndpointURI;
 25  
 import org.mule.umo.manager.UMOManager;
 26  
 import org.mule.umo.model.UMOModel;
 27  
 import org.mule.umo.provider.UMOConnector;
 28  
 
 29  
 import java.util.HashMap;
 30  
 /**
 31  
  * @deprecated use Xml configuration instead
 32  
  */
 33  0
 public abstract class AbstractProviderFunctionalTestCase extends AbstractMuleTestCase
 34  
 {
 35  
     protected static final int NUM_MESSAGES_TO_SEND = 100;
 36  
 
 37  
     protected UMOConnector connector;
 38  
     protected static UMOManager manager;
 39  0
     protected boolean callbackCalled = false;
 40  0
     protected int callbackCount = 0;
 41  0
     protected boolean transacted = false;
 42  
 
 43  0
     private final Object callbackLock = new Object();
 44  
 
 45  
     protected MuleDescriptor descriptor;
 46  
 
 47  
     protected void doSetUp() throws Exception
 48  
     {
 49  0
         manager = MuleManager.getInstance();
 50  
         // Make sure we are running synchronously
 51  0
         MuleManager.getConfiguration().setSynchronous(true);
 52  0
         MuleManager.getConfiguration().getPoolingProfile().setInitialisationPolicy(
 53  
             PoolingProfile.INITIALISE_ONE);
 54  
 
 55  0
         UMOModel model = new SedaModel();
 56  0
         model.setName("main");
 57  0
         manager.registerModel(model);
 58  0
         callbackCalled = false;
 59  0
         callbackCount = 0;
 60  0
         connector = createConnector();
 61  
         // Start the server
 62  0
         MuleManager.getConfiguration().setServerUrl("");
 63  0
         manager.start();
 64  0
     }
 65  
 
 66  
     protected void doTearDown() throws Exception
 67  
     {
 68  0
         if (connector != null)
 69  
         {
 70  0
             connector.dispose();
 71  
         }
 72  0
     }
 73  
 
 74  
     public void testSend() throws Exception
 75  
     {
 76  0
         descriptor = getTestDescriptor("testComponent", FunctionalTestComponent.class.getName());
 77  
 
 78  0
         initialiseComponent(descriptor, this.createEventCallback());
 79  
 
 80  0
         sendTestData(NUM_MESSAGES_TO_SEND);
 81  
 
 82  0
         afterInitialise();
 83  
 
 84  0
         receiveAndTestResults();
 85  
 
 86  0
         assertTrue(callbackCalled);
 87  0
     }
 88  
 
 89  
     public UMOComponent initialiseComponent(UMODescriptor descriptor, EventCallback callback)
 90  
         throws Exception
 91  
     {
 92  0
         descriptor.setOutboundEndpoint(createOutboundEndpoint());
 93  0
         descriptor.setInboundEndpoint(createInboundEndpoint());
 94  0
         HashMap props = new HashMap();
 95  0
         props.put("eventCallback", callback);
 96  0
         descriptor.setProperties(props);
 97  0
         MuleManager.getInstance().registerConnector(connector);
 98  0
         UMOComponent component = MuleManager.getInstance().lookupModel("main").registerComponent(descriptor);
 99  0
         descriptor.initialise();
 100  0
         return component;
 101  
     }
 102  
 
 103  
     /**
 104  
      * Implementing tests can overide this to add further configuration to the
 105  
      * outbound endpoint
 106  
      * 
 107  
      * @return
 108  
      */
 109  
     protected UMOEndpoint createOutboundEndpoint()
 110  
     {
 111  0
         if (getOutDest() != null)
 112  
         {
 113  0
             return new MuleEndpoint("testOut", getOutDest(), connector, null,
 114  
                 UMOEndpoint.ENDPOINT_TYPE_SENDER, 0, null, null);
 115  
         }
 116  
         else
 117  
         {
 118  0
             return null;
 119  
         }
 120  
     }
 121  
 
 122  
     /**
 123  
      * Implementing tests can overide this to add further configuration to the
 124  
      * inbound endpoint
 125  
      * 
 126  
      * @return
 127  
      */
 128  
     protected UMOEndpoint createInboundEndpoint()
 129  
     {
 130  0
         UMOEndpoint ep = new MuleEndpoint("testIn", getInDest(), connector, null,
 131  
             UMOEndpoint.ENDPOINT_TYPE_RECEIVER, 0, null, null);
 132  0
         ep.setSynchronous(true);
 133  0
         return ep;
 134  
     }
 135  
 
 136  
     public static MuleDescriptor getTestDescriptor(String name, String implementation)
 137  
     {
 138  0
         MuleDescriptor descriptor = new MuleDescriptor();
 139  0
         descriptor.setExceptionListener(new DefaultExceptionStrategy());
 140  0
         descriptor.setName(name);
 141  0
         descriptor.setImplementation(implementation);
 142  0
         return descriptor;
 143  
     }
 144  
 
 145  
     public void afterInitialise() throws Exception
 146  
     {
 147  
         // nothing to do
 148  0
     }
 149  
 
 150  
     public EventCallback createEventCallback()
 151  
     {
 152  0
         EventCallback callback = new EventCallback()
 153  
         {
 154  0
             public void eventReceived(UMOEventContext context, Object component)
 155  
             {
 156  0
                 synchronized (callbackLock)
 157  
                 {
 158  0
                     callbackCalled = true;
 159  0
                     callbackCount++;
 160  0
                 }
 161  0
                 if (!transacted)
 162  
                 {
 163  0
                     assertNull(context.getCurrentTransaction());
 164  
                 }
 165  
                 else
 166  
                 {
 167  0
                     assertNotNull(context.getCurrentTransaction());
 168  
                 }
 169  0
             }
 170  
         };
 171  0
         return callback;
 172  
     }
 173  
 
 174  
     protected abstract void sendTestData(int iterations) throws Exception;
 175  
 
 176  
     protected abstract void receiveAndTestResults() throws Exception;
 177  
 
 178  
     protected abstract UMOEndpointURI getInDest();
 179  
 
 180  
     protected abstract UMOEndpointURI getOutDest();
 181  
 
 182  
     protected abstract UMOConnector createConnector() throws Exception;
 183  
 
 184  
 }