1 10 11 package org.mule.tck.functional; 12 13 import java.util.HashMap ; 14 15 import org.mule.MuleManager; 16 import org.mule.config.PoolingProfile; 17 import org.mule.impl.DefaultExceptionStrategy; 18 import org.mule.impl.MuleDescriptor; 19 import org.mule.impl.endpoint.MuleEndpoint; 20 import org.mule.impl.model.seda.SedaModel; 21 import org.mule.tck.AbstractMuleTestCase; 22 import org.mule.umo.UMOComponent; 23 import org.mule.umo.UMODescriptor; 24 import org.mule.umo.UMOEventContext; 25 import org.mule.umo.endpoint.UMOEndpoint; 26 import org.mule.umo.endpoint.UMOEndpointURI; 27 import org.mule.umo.manager.UMOManager; 28 import org.mule.umo.provider.UMOConnector; 29 30 public abstract class AbstractProviderFunctionalTestCase extends AbstractMuleTestCase 31 { 32 protected static final int NUM_MESSAGES_TO_SEND = 100; 33 34 protected UMOConnector connector; 35 protected static UMOManager manager; 36 protected boolean callbackCalled = false; 37 protected int callbackCount = 0; 38 protected boolean transacted = false; 39 40 private final Object lock = new Object (); 41 42 protected MuleDescriptor descriptor; 43 44 protected void doSetUp() throws Exception 45 { 46 manager = MuleManager.getInstance(); 47 MuleManager.getConfiguration().setSynchronous(true); 49 MuleManager.getConfiguration().getPoolingProfile().setInitialisationPolicy( 50 PoolingProfile.POOL_INITIALISE_ONE_COMPONENT); 51 52 manager.setModel(new SedaModel()); 53 callbackCalled = false; 54 callbackCount = 0; 55 connector = createConnector(); 56 MuleManager.getConfiguration().setServerUrl(""); 58 manager.start(); 59 } 60 61 protected void doTearDown() throws Exception 62 { 63 if (connector != null) 64 { 65 connector.dispose(); 66 } 67 } 68 69 public void testSend() throws Exception 70 { 71 if (!isPrereqsMet("org.mule.tck.functional.AbstractProviderFunctionalTestCase.testSend()")) 72 { 73 return; 74 } 75 76 descriptor = getTestDescriptor("testComponent", FunctionalTestComponent.class.getName()); 77 78 initialiseComponent(descriptor, this.createEventCallback()); 79 80 sendTestData(NUM_MESSAGES_TO_SEND); 81 82 afterInitialise(); 83 84 receiveAndTestResults(); 85 86 assertTrue(callbackCalled); 87 } 88 89 public UMOComponent initialiseComponent(UMODescriptor descriptor, EventCallback callback) 90 throws Exception 91 { 92 descriptor.setOutboundEndpoint(createOutboundEndpoint()); 93 descriptor.setInboundEndpoint(createInboundEndpoint()); 94 HashMap props = new HashMap (); 95 props.put("eventCallback", callback); 96 descriptor.setProperties(props); 97 MuleManager.getInstance().registerConnector(connector); 98 UMOComponent component = MuleManager.getInstance().getModel().registerComponent(descriptor); 99 descriptor.initialise(); 100 return component; 101 } 102 103 109 protected UMOEndpoint createOutboundEndpoint() 110 { 111 if (getOutDest() != null) 112 { 113 return new MuleEndpoint("testOut", getOutDest(), connector, null, 114 UMOEndpoint.ENDPOINT_TYPE_SENDER, 0, null, null); 115 } 116 else 117 { 118 return null; 119 } 120 } 121 122 128 protected UMOEndpoint createInboundEndpoint() 129 { 130 UMOEndpoint ep = new MuleEndpoint("testIn", getInDest(), connector, null, 131 UMOEndpoint.ENDPOINT_TYPE_RECEIVER, 0, null, null); 132 ep.setSynchronous(true); 133 return ep; 134 } 135 136 public static MuleDescriptor getTestDescriptor(String name, String implementation) 137 { 138 MuleDescriptor descriptor = new MuleDescriptor(); 139 descriptor.setExceptionListener(new DefaultExceptionStrategy()); 140 descriptor.setName(name); 141 descriptor.setImplementation(implementation); 142 return descriptor; 143 } 144 145 public void afterInitialise() throws Exception 146 { 147 } 149 150 public EventCallback createEventCallback() 151 { 152 EventCallback callback = new EventCallback() 153 { 154 public void eventReceived(UMOEventContext context, Object Component) 155 { 156 synchronized (lock) 157 { 158 callbackCalled = true; 159 callbackCount++; 160 } 161 if (!transacted) 162 { 163 assertNull(context.getCurrentTransaction()); 164 } 165 else 166 { 167 assertNotNull(context.getCurrentTransaction()); 168 } 169 } 170 }; 171 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 } 185 | Popular Tags |