diff options
author | avasseur <avasseur> | 2005-04-26 10:52:36 +0000 |
---|---|---|
committer | avasseur <avasseur> | 2005-04-26 10:52:36 +0000 |
commit | 4cf9913a74c804176c04e9cc5effcbea24289418 (patch) | |
tree | 91ec70d29752f5561f8afca1941ae69caf83f058 /testing | |
parent | 3e1783bc03e372ad8957e5e24e41b5c7d0e7dd26 (diff) | |
download | aspectj-4cf9913a74c804176c04e9cc5effcbea24289418.tar.gz aspectj-4cf9913a74c804176c04e9cc5effcbea24289418.zip |
fix some build. Move AspectJrt5 test to AllTest15. Add weaver checks for @AJ annotations + tests from Andy H
Diffstat (limited to 'testing')
-rw-r--r-- | testing/newsrc/org/aspectj/testing/AutowiredXMLBasedAjcTestCase.java | 139 | ||||
-rw-r--r-- | testing/newsrc/org/aspectj/testing/XMLBasedAjcTestCase.java | 7 |
2 files changed, 143 insertions, 3 deletions
diff --git a/testing/newsrc/org/aspectj/testing/AutowiredXMLBasedAjcTestCase.java b/testing/newsrc/org/aspectj/testing/AutowiredXMLBasedAjcTestCase.java new file mode 100644 index 000000000..f77e289d7 --- /dev/null +++ b/testing/newsrc/org/aspectj/testing/AutowiredXMLBasedAjcTestCase.java @@ -0,0 +1,139 @@ +/******************************************************************************* + * Copyright (c) 2005 Contributors + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * initial implementation Alexandre Vasseur + *******************************************************************************/ +package org.aspectj.testing; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; +import junit.extensions.TestSetup; + +import java.lang.reflect.Method; +import java.util.Iterator; +import java.util.Map; +import java.util.HashMap; +import java.io.InputStreamReader; +import java.io.FileInputStream; + +import org.apache.commons.digester.Digester; +import org.aspectj.tools.ajc.Ajc; + +/** + * Autowiring of XML test spec file as JUnit tests. + * <p/> + * Extend this class and implement the getSpecFile and the static suite() method. + * All tests described in the XML spec file will be auto-registered as JUnit tests. + * Any regular test() method will be registered as well. + * + * @author <a href="mailto:alex AT gnilux DOT com">Alexandre Vasseur</a> + */ +public abstract class AutowiredXMLBasedAjcTestCase extends XMLBasedAjcTestCase { + + private Map testMap = new HashMap(); + + public void addTest(AjcTest test) { + testMap.put(test.getTitle(), test); + } + + /* + * Return a map from (String) test title -> AjcTest + */ + protected Map getSuiteTests() { + return testMap; + } + + public static Test loadSuite(Class testCaseClass) { + TestSuite suite = new TestSuite(testCaseClass.getName()); + //suite.addTestSuite(testCaseClass); + + // wire the spec file + try { + final AutowiredXMLBasedAjcTestCase wired = (AutowiredXMLBasedAjcTestCase) testCaseClass.newInstance(); + System.out.println("LOADING SUITE: " + wired.getSpecFile().getPath()); + Digester d = wired.getDigester(); + try { + InputStreamReader isr = new InputStreamReader(new FileInputStream(wired.getSpecFile())); + d.parse(isr); + } catch (Exception ex) { + fail("Unable to load suite " + wired.getSpecFile().getPath() + " : " + ex); + } + wired.ajc = new Ajc(); + + Map ajTests = wired.getSuiteTests(); + + for (Iterator iterator = ajTests.entrySet().iterator(); iterator.hasNext();) { + final Map.Entry entry = (Map.Entry) iterator.next(); + + suite.addTest( + new TestCase(entry.getKey().toString()) { + + protected void runTest() { + ((AjcTest) entry.getValue()).runTest(wired); + } + + public String getName() { + return (String) entry.getKey(); + } + } + ); + } + } catch (Throwable t) { + final String message = t.toString(); + suite.addTest( + new TestCase("error") { + protected void runTest() { + fail(message); + } + } + ); + } + + // wire the test methods as well if any + // this simple check avoids failure when no test.. method is found. + // it could be refined to lookup in the hierarchy as well, and excluding private method as JUnit does. + Method[] testMethods = testCaseClass.getDeclaredMethods(); + for (int i = 0; i < testMethods.length; i++) { + Method testMethod = testMethods[i]; + if (testMethod.getName().startsWith("test")) { + suite.addTestSuite(testCaseClass); + break; + } + } + + TestSetup wrapper = new TestSetup(suite) { + /* (non-Javadoc) + * @see junit.extensions.TestSetup#setUp() + */ + protected void setUp() throws Exception { + super.setUp(); + //suiteLoaded = false; + } + /* (non-Javadoc) + * @see junit.extensions.TestSetup#tearDown() + */ + protected void tearDown() throws Exception { + super.tearDown(); + //suiteLoaded = false; + } + }; + return wrapper; + + //return suite; + } + + /* (non-Javadoc) + * @see org.aspectj.tools.ajc.AjcTestCase#setUp() + */ + protected void setUp() throws Exception { + super.setUp(); + } + + +} diff --git a/testing/newsrc/org/aspectj/testing/XMLBasedAjcTestCase.java b/testing/newsrc/org/aspectj/testing/XMLBasedAjcTestCase.java index 32379c775..91ded4c1a 100644 --- a/testing/newsrc/org/aspectj/testing/XMLBasedAjcTestCase.java +++ b/testing/newsrc/org/aspectj/testing/XMLBasedAjcTestCase.java @@ -16,10 +16,12 @@ import java.io.FileInputStream; import java.io.InputStreamReader; import java.util.HashMap; import java.util.Map; +import java.util.Iterator; import junit.extensions.TestSetup; import junit.framework.Test; import junit.framework.TestSuite; +import junit.framework.TestCase; import org.apache.commons.digester.Digester; import org.aspectj.tools.ajc.AjcTestCase; @@ -85,7 +87,7 @@ public abstract class XMLBasedAjcTestCase extends AjcTestCase { /* * Return a map from (String) test title -> AjcTest */ - private Map getSuiteTests() { + protected Map getSuiteTests() { return testMap; } @@ -125,7 +127,7 @@ public abstract class XMLBasedAjcTestCase extends AjcTestCase { * in the XML document to properties in the associated classes, so this simple implementation should * be very easy to maintain and extend should you ever need to. */ - private Digester getDigester() { + protected Digester getDigester() { Digester digester = new Digester(); digester.push(this); digester.addObjectCreate("suite/ajc-test",AjcTest.class); @@ -173,7 +175,6 @@ public abstract class XMLBasedAjcTestCase extends AjcTestCase { suiteLoaded = true; } } - protected long nextIncrement(boolean doWait) { long time = System.currentTimeMillis(); |