1 18 package org.apache.activemq.transport; 19 20 import java.net.URI ; 21 import java.net.URISyntaxException ; 22 import java.util.ArrayList ; 23 import java.util.Iterator ; 24 25 import org.apache.activemq.broker.BrokerService; 26 import org.apache.activemq.broker.BrokerTest; 27 import org.apache.activemq.broker.StubConnection; 28 import org.apache.activemq.broker.TransportConnector; 29 import org.apache.activemq.transport.Transport; 30 import org.apache.activemq.transport.TransportFactory; 31 32 abstract public class TransportBrokerTestSupport extends BrokerTest { 33 34 private TransportConnector connector; 35 ArrayList connections = new ArrayList (); 36 37 protected void setUp() throws Exception { 38 super.setUp(); 39 } 40 41 protected BrokerService createBroker() throws Exception { 42 BrokerService service = super.createBroker(); 43 connector = service.addConnector(getBindLocation()); 44 return service; 45 } 46 47 protected abstract String getBindLocation(); 48 49 protected void tearDown() throws Exception { 50 for (Iterator iter = connections.iterator(); iter.hasNext();) { 51 StubConnection connection = (StubConnection) iter.next(); 52 connection.stop(); 53 iter.remove(); 54 } 55 connector.stop(); 56 super.tearDown(); 57 } 58 59 protected URI getBindURI() throws URISyntaxException { 60 return new URI (getBindLocation()); 61 } 62 63 protected StubConnection createConnection() throws Exception { 64 URI bindURI = getBindURI(); 65 66 69 URI actualURI = connector.getServer().getConnectURI(); 70 URI connectURI = new URI (actualURI.getScheme(), actualURI.getUserInfo(), bindURI.getHost(), actualURI.getPort(), actualURI.getPath(), actualURI 71 .getQuery(), actualURI.getFragment()); 72 73 Transport transport = TransportFactory.connect(connectURI); 74 StubConnection connection = new StubConnection(transport); 75 connections.add(connection); 76 return connection; 77 } 78 79 } 80 | Popular Tags |