Update AOPTestDelegate to better integrate into eclipse
starksm64 Jan 1, 2007 2:04 AMCurrently you cannot run the tests easily from within eclise using the run as junit... capability because the test harness does not locate the jboss-aop.xml based on the classpath. Something like this does this:
package org.jboss.test.aop; import java.net.URL; import java.util.Properties; import org.jboss.aop.AspectXmlLoader; import org.jboss.test.AbstractTestDelegate; /** * * @author <a href="kabir.khan@jboss.com">Kabir Khan</a> * @version $Revision: 45977 $ */ public class AOPTestDelegate extends AbstractTestDelegate { /** The AOP URL used */ private URL aopURL; Properties systemProps; public AOPTestDelegate(Class clazz) { // FIXME AOPTestDelegate constructor super(clazz); systemProps = (Properties)System.getProperties().clone(); } public Properties getSystemProperties() { return systemProps; } /** * Look for a test specific aop descriptor based on the ctor * class first, and if none is found, the ManagedTest.class. */ public void setUp() throws Exception { super.setUp(); deployAOP(clazz); } /** * Undeployment any test specific aop descriptor deployed in setUp. */ public void tearDown() throws Exception { super.tearDown(); undeployAOP(); } /** * Look for a test specific resource name by appending "-aop.xml" * to the referenceClass name as a resource. For example, a.b.SomeTest * would produce a a/b/SomeTest-aop.xml resource that is queried * for using clazz.getClassLoader().getResource("a/b/SomeTest-aop.xml"); * * @param referenceClass - the class to use as the aop descriptor base name. * @return true if the aop descriptor was found and deployed, * false otherwise. * @throws Exception on failure to deploy the aop descriptor. */ protected boolean deployAOP(Class referenceClass) throws Exception { String testName = referenceClass.getName(); String pkg = referenceClass.getPackage().getName(); int dot = pkg.lastIndexOf('.'); if( dot > 0 ) pkg = pkg.substring(dot+1); testName = pkg + "/jboss-aop.xml"; URL url = clazz.getClassLoader().getResource(testName); if (url != null) { log.debug("Deploying " + url); aopURL = url; try { AspectXmlLoader.deployXML(aopURL); } catch (Throwable t) { throw new RuntimeException("Error deploying: " + url, t); } return true; } else { log.debug("No test specific deployment " + testName); return false; } } /** * Undeploy the aop descriptor deployed in deployAOP if * one was found. * */ protected void undeployAOP() { if (aopURL == null) return; try { log.debug("Undeploying " + aopURL); AspectXmlLoader.undeployXML(aopURL); } catch (Exception e) { log.warn("Ignored error undeploying " + aopURL, e); } } }
Although this does deploy the aspects, the test I tried this with (org.jboss.test.aop.precedence.PrecedenceTester) is still failing. Can you look into getting this working Kabir?