From: Julien V. <ju...@jb...> - 2006-03-11 18:05:00
|
User: julien Date: 06/03/11 13:04:57 Modified: wsrp/src/main/org/jboss/portal/test/wsrp WSRPBaseTest.java Log: make wsrp use the test framework Revision Changes Path 1.5 +100 -33 jboss-portal/wsrp/src/main/org/jboss/portal/test/wsrp/WSRPBaseTest.java (In the diff below, changes in quantity of whitespace are not shown.) Index: WSRPBaseTest.java =================================================================== RCS file: /cvsroot/jboss/jboss-portal/wsrp/src/main/org/jboss/portal/test/wsrp/WSRPBaseTest.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -b -r1.4 -r1.5 --- WSRPBaseTest.java 11 Mar 2006 06:48:01 -0000 1.4 +++ WSRPBaseTest.java 11 Mar 2006 18:04:57 -0000 1.5 @@ -7,13 +7,14 @@ package org.jboss.portal.test.wsrp; import junit.framework.TestCase; -import org.jboss.portal.test.PortalTestSetup; - -import javax.management.MBeanServerConnection; -import javax.naming.Context; -import javax.naming.InitialContext; -import javax.naming.NamingException; -import java.util.Properties; +import org.jboss.portal.test.framework.TestRuntimeContext; +import org.jboss.portal.test.framework.JNDIServiceLookup; +import org.jboss.portal.test.framework.JBossServiceLookup; +import org.jboss.portal.test.framework.deployment.Deployer; + +import java.net.URL; +import java.net.MalformedURLException; +import java.io.File; /** * Base Class for all WSRP Test Cases @@ -24,63 +25,129 @@ */ public abstract class WSRPBaseTest extends TestCase { - PortalTestSetup ts = new PortalTestSetup(); - public void deploy(String archive) throws Exception + private TestRuntimeContext runtimeContext; + + private Deployer deployer; + + private JBossServiceLookup producer; + + private JNDIServiceLookup serviceDescriptionService; + + protected WSRPBaseTest() throws Exception { - ts.deploy(archive); + runtimeContext = new TestRuntimeContext("org/jboss/portal/test/wsrp/jboss-beans.xml", this); } - /** - * Undeploy the given archive - */ - public void undeploy(String archive) throws Exception + protected WSRPBaseTest(String name) throws Exception + { + super(name); + runtimeContext = new TestRuntimeContext("org/jboss/portal/test/wsrp/jboss-beans.xml", this); + } + + public Deployer getDeployer() + { + return deployer; + } + + public JBossServiceLookup getProducer() + { + return producer; + } + + public void setProducer(JBossServiceLookup producer) + { + this.producer = producer; + } + + public void setDeployer(Deployer deployer) + { + this.deployer = deployer; + } + + public JNDIServiceLookup getServiceDescriptionService() + { + return serviceDescriptionService; + } + + public void setServiceDescriptionService(JNDIServiceLookup serviceDescriptionService) + { + this.serviceDescriptionService = serviceDescriptionService; + } + + public void deploy(String archive) throws Exception { - ts.undeploy(archive); + deployer.deploy(getArchiveURL(archive)); } /** - * Get the MBeanServerConnection from JNDI + * Undeploy the given archive */ - public MBeanServerConnection getServer() throws NamingException + public void undeploy(String archive) throws Exception { - return ts.getServer(); + deployer.undeploy(getArchiveURL(archive)); } protected void setUp() throws Exception { - unDeployArchives(); + runtimeContext.start(); deployArchives(); } protected void tearDown() throws Exception { - unDeployArchives(); + undeployArchives(); + runtimeContext.stop(); } private void deployArchives() throws Exception { + undeploy("jboss-wsrp.sar"); deploy("jboss-wsrp.sar"); - deploy("jboss-wsrp-client.jar"); } - private void unDeployArchives() throws Exception + private void undeployArchives() throws Exception { - undeploy("jboss-wsrp.war"); - undeploy("jboss-wsrp-client.jar"); + undeploy("jboss-wsrp.sar"); } /** - * Get the client's env context + * Try to discover the URL for the deployment archive */ - protected static InitialContext getInitialContext(String clientName) - throws NamingException + private URL getArchiveURL(String archive) throws MalformedURLException + { + URL url = null; + try + { + url = new URL(archive); + } + catch (MalformedURLException ignore) + { + // ignore + } + + String locs[] = {archive, "output/libs/" + archive, + "test/outputs/libs/" + archive, + "output/lib/" + archive, + "test/output/lib/" + archive, + "../output/lib/" + archive, + "../test/output/lib/" + archive}; + + for (int i = 0; i < locs.length && url == null; i++) + { + File file = new File(locs[i]); + if (file.exists()) { - Properties env = new Properties(); - env.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory"); - env.setProperty(Context.URL_PKG_PREFIXES, "org.jboss.naming.client"); - env.setProperty(Context.PROVIDER_URL, "jnp://localhost:1099"); - env.setProperty("j2ee.clientName", clientName); - return new InitialContext(env); + url = file.toURL(); + } + } + + // + if (url == null) + { + throw new IllegalArgumentException("Cannot obtain URL for: " + archive); + } + + return url; } } |