diff options
author | wisberg <wisberg> | 2006-07-20 22:30:36 +0000 |
---|---|---|
committer | wisberg <wisberg> | 2006-07-20 22:30:36 +0000 |
commit | f847cc59e7af417d57ad8db052680b91642badd2 (patch) | |
tree | c2dcb3cb11d424d45e2bf0a390afb863660c694b /build | |
parent | da99c638d3fd59b8348c26f5509a565dec2a8564 (diff) | |
download | aspectj-f847cc59e7af417d57ad8db052680b91642badd2.tar.gz aspectj-f847cc59e7af417d57ad8db052680b91642badd2.zip |
initial OSGI module tests
Diffstat (limited to 'build')
6 files changed, 266 insertions, 5 deletions
diff --git a/build/testsrc/BuildModuleTests.java b/build/testsrc/BuildModuleTests.java index 3ca6f78f6..d5a88c91e 100644 --- a/build/testsrc/BuildModuleTests.java +++ b/build/testsrc/BuildModuleTests.java @@ -17,6 +17,7 @@ import org.aspectj.internal.tools.ant.taskdefs.Checklics; import org.aspectj.internal.tools.build.Builder; import org.aspectj.internal.tools.build.Util; +import org.aspectj.internal.tools.build.UtilsTest; import org.aspectj.internal.build.BuildModuleTest; import org.aspectj.internal.build.ModulesTest; @@ -51,6 +52,7 @@ public class BuildModuleTests extends TestCase { suite.addTestSuite(BuildModuleTests.class); suite.addTestSuite(BuildModuleTest.class); suite.addTestSuite(ModulesTest.class); + suite.addTestSuite(UtilsTest.class); return suite; } diff --git a/build/testsrc/org/aspectj/internal/build/ModulesTest.java b/build/testsrc/org/aspectj/internal/build/ModulesTest.java index 0802c7803..4aa68e502 100644 --- a/build/testsrc/org/aspectj/internal/build/ModulesTest.java +++ b/build/testsrc/org/aspectj/internal/build/ModulesTest.java @@ -1,7 +1,7 @@ /* ******************************************************************* * Copyright (c) 1999-2001 Xerox Corporation, * 2002 Palo Alto Research Center, Incorporated (PARC), - * 2005 Contributors. + * 2005-2006 Contributors. * All rights reserved. * This program and the accompanying materials are made available * under the terms of the Eclipse Public License v1.0 @@ -145,10 +145,7 @@ public class ModulesTest extends TestCase { assertTrue(ajdt.valid); Project project = new Project(); - project.setBaseDir(new File(".")); - project.setName("testClasspathCreation"); - File tempDir = new File("."); - AntBuilder builder = (AntBuilder) AntBuilder.getBuilder("", project, tempDir); + AntBuilder builder = getBuilder(project); Path classpath = new Path(project); Kind kind = Result.kind(Result.NORMAL, !Result.ASSEMBLE); Result result = ajdt.getResult(kind); @@ -158,7 +155,44 @@ public class ModulesTest extends TestCase { assertTrue(classpath.toString(), false); } } + + /** + * This test requires two OSGI modules: + * org.aspectj.util, which optionally depends on tempaspectjrt. + * Currently, the Ant builder does not handle linked source folders, + * and the OSGI support does not work around optional plugins. + */ + public void skip_testOSGIModuleCreation() { + final String MODULE = "org.aspectj.util"; + final String USES_MODULE = "tempaspectjrt"; + + Modules modules = getModules(null); + Module newutil = modules.getModule(MODULE); + assertTrue(newutil.valid); + + Project project = new Project(); + AntBuilder builder = getBuilder(project); + Path classpath = new Path(project); + Kind kind = Result.kind(Result.NORMAL, !Result.ASSEMBLE); + Result result = newutil.getResult(kind); + builder.setupClasspath(result, classpath); + System.out.println(newutil + " classpath: " + classpath); + if ((null == classpath) || (1 != classpath.size())) { + assertTrue(classpath.toString(), false); + } + String cpEntry = classpath.list()[0]; + if (!cpEntry.endsWith(USES_MODULE + ".jar")) { + fail("expected " + classpath + " to end with " + USES_MODULE + ".jar"); + } + } + private AntBuilder getBuilder(Project project) { + project.setBaseDir(new File(".")); + project.setName("testOSGIModuleCreation"); + File tempDir = new File("."); + return (AntBuilder) AntBuilder.getBuilder("", project, tempDir); + } + /********************************************************************* * The following tests/code enable you to run the entire build in JUnit diff --git a/build/testsrc/org/aspectj/internal/tools/build/UtilsTest.01.MF b/build/testsrc/org/aspectj/internal/tools/build/UtilsTest.01.MF new file mode 100644 index 000000000..e3ba88396 --- /dev/null +++ b/build/testsrc/org/aspectj/internal/tools/build/UtilsTest.01.MF @@ -0,0 +1,8 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Client Plug-in +Bundle-SymbolicName: org.aspectj.testing.client +Bundle-Version: 1.0.0 +Bundle-Localization: plugin +Bundle-ClassPath: lib/commons/commons.jar + diff --git a/build/testsrc/org/aspectj/internal/tools/build/UtilsTest.02.MF b/build/testsrc/org/aspectj/internal/tools/build/UtilsTest.02.MF new file mode 100644 index 000000000..5888ab3c0 --- /dev/null +++ b/build/testsrc/org/aspectj/internal/tools/build/UtilsTest.02.MF @@ -0,0 +1,9 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Client Plug-in +Bundle-SymbolicName: org.aspectj.testing.client +Bundle-Version: 1.0.0 +Bundle-Localization: plugin +Bundle-ClassPath: lib/commons/commons.jar, lib/ant/lib/ant.jar +Require-Bundle: util, org.aspectj.runtime + diff --git a/build/testsrc/org/aspectj/internal/tools/build/UtilsTest.03.MF b/build/testsrc/org/aspectj/internal/tools/build/UtilsTest.03.MF new file mode 100644 index 000000000..b9717c5f2 --- /dev/null +++ b/build/testsrc/org/aspectj/internal/tools/build/UtilsTest.03.MF @@ -0,0 +1,9 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Client Plug-in +Bundle-SymbolicName: org.aspectj.testing.client +Bundle-Version: 1.0.0 +Bundle-Localization: plugin +Bundle-ClassPath: lib/commons/commons.jar, lib/ant/lib/ant.jar +Require-Bundle: util, aspectjrt;bundle-version="[1.5.0,1.5.5]";resolution:=optional + diff --git a/build/testsrc/org/aspectj/internal/tools/build/UtilsTest.java b/build/testsrc/org/aspectj/internal/tools/build/UtilsTest.java new file mode 100644 index 000000000..084875a57 --- /dev/null +++ b/build/testsrc/org/aspectj/internal/tools/build/UtilsTest.java @@ -0,0 +1,199 @@ +/* ******************************************************************* + * Copyright (c) 2006 Contributors. + * All rights reserved. + * This program and the accompanying materials are made available + * under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution and is available at + * http://eclipse.org/legal/epl-v10.html + * + * Contributors: + * Wes Isberg initial implementation + * ******************************************************************/ + +package org.aspectj.internal.tools.build; + +import java.io.IOException; +import java.util.jar.Attributes.Name; + +import junit.framework.TestCase; + +import org.aspectj.internal.tools.build.Util.OSGIBundle; +import org.aspectj.internal.tools.build.Util.OSGIBundle.RequiredBundle; + +public class UtilsTest extends TestCase { + private static final String PREFIX = UtilsTest.class.getName().replace('.', + '/'); + + private static final ClassLoader LOADER = UtilsTest.class.getClassLoader(); + + private static final ManifestTest[] TESTS = { + new ManifestTest("01", + new Name[] { OSGIBundle.BUNDLE_CLASSPATH, + OSGIBundle.BUNDLE_SYMBOLIC_NAME, + OSGIBundle.BUNDLE_VERSION }, new String[] { + "lib/commons/commons.jar", + "org.aspectj.testing.client", "1.0.0" }), + new ManifestTest("02", + new Name[] { OSGIBundle.BUNDLE_SYMBOLIC_NAME, + OSGIBundle.BUNDLE_VERSION }, new String[] { + "org.aspectj.testing.client", "1.0.0" }, + new String[] { "lib/commons/commons.jar", + "lib/ant/lib/ant.jar" }, new String[] { "util", + "org.aspectj.runtime" }), + new ManifestTest("03", + new Name[] { OSGIBundle.BUNDLE_SYMBOLIC_NAME, + OSGIBundle.BUNDLE_VERSION }, new String[] { + "org.aspectj.testing.client", "1.0.0" }, + new String[] { "lib/commons/commons.jar", + "lib/ant/lib/ant.jar" }, new String[] { "util", + "aspectjrt" }) { + void checkOthers(OSGIBundle osgiBundle, StringBuffer sb) { + RequiredBundle[] bundles = osgiBundle.getRequiredBundles(); + for (int i = 0; i < bundles.length; i++) { + RequiredBundle bundle = bundles[i]; + if ("aspectjrt".equals(bundle.name)) { + if (!bundle.optional) { + sb + .append("expected required bundle aspectjrt to be optional"); + } + String version = "[1.5.0,1.5.5]"; + if (!(version.equals(bundle.versions))) { + sb.append("expected version " + version + + " got " + bundle.versions + + " for required bundle aspectjrt"); + } + } + } + + } + } }; + + private static class ManifestTest { + final String name; + + final Name[] expectedNames; + + final String[] expectedValues; + + final String[] classpathEntries; + + final String[] requiredBundleNames; + + ManifestTest(String name, Name[] expectedNames, String[] expectedValues) { + this(name, expectedNames, expectedValues, null, null); + } + + ManifestTest(String name, Name[] expectedNames, + String[] expectedValues, String[] classpathEntries, + String[] requiredBundleNames) { + this.name = name; + this.expectedNames = expectedNames; + this.expectedValues = expectedValues; + this.classpathEntries = classpathEntries; + this.requiredBundleNames = requiredBundleNames; + } + + void run(StringBuffer sb) throws IOException { + String path = PREFIX + "." + name + ".MF"; + OSGIBundle bundle = new OSGIBundle(LOADER.getResourceAsStream(path)); + int len = sb.length(); + checkNamesAndValues(bundle, sb); + checkOthers(bundle, sb); + if (sb.length() != len) { + sb.append("failure was in test " + name); + } + } + + void checkOthers(OSGIBundle bundle, StringBuffer sb) { + } + + void checkNamesAndValues(OSGIBundle bundle, StringBuffer sb) { + for (int i = 0; i < expectedNames.length; i++) { + Name name = expectedNames[i]; + String expected = expectedValues[i]; + String actual = bundle.getAttribute(expectedNames[i]); + if (!((expected == actual) || expected.equals(actual))) { + sb.append(name); + sb.append(" "); + sb.append("expected "); + sb.append(expected); + sb.append("actual "); + sb.append(actual); + sb.append("\n"); + } + } + if (null != classpathEntries) { + String[] cp = bundle.getClasspath(); + Util.reportMemberDiffs(classpathEntries, cp, sb); + } + if (null != requiredBundleNames) { + RequiredBundle[] bundles = bundle.getRequiredBundles(); + String[] names = new String[bundles.length]; + for (int i = 0; i < names.length; i++) { + names[i] = bundles[i].name; + } + Util.reportMemberDiffs(requiredBundleNames, names, sb); + } + } + } + + public void testOSGIManifests() throws Exception { + StringBuffer sb = new StringBuffer(); + for (int i = 0; i < TESTS.length; i++) { + TESTS[i].run(sb); + } + if (0 < sb.length()) { + fail(sb.toString()); + } + } + + public void testReportMemberDiffs() { + StringBuffer sb = new StringBuffer(); + String[] exp = null; + String[] act = null; + assertFalse(Util.reportMemberDiffs(exp, act, sb)); + assertEquals("", sb.toString()); + + sb.setLength(0); + exp = new String[] { "" }; + act = null; + assertTrue(Util.reportMemberDiffs(exp, act, sb)); + assertEquals("unexpected [] missing [\"\"]", sb.toString()); + + sb.setLength(0); + exp = null; + act = new String[] { "" }; + assertTrue(Util.reportMemberDiffs(exp, act, sb)); + assertEquals("unexpected [\"\"] missing []", sb.toString()); + + sb.setLength(0); + exp = new String[] { "1", "2", "3" }; + act = new String[] { "2", "4" }; + assertTrue(Util.reportMemberDiffs(exp, act, sb)); + assertEquals("unexpected [\"4\"] missing [\"1\", \"3\"]", sb.toString()); + + } + // public void testResourceStream() throws Exception { + // String path = PREFIX + ".one.mf"; + // System.out.println(path); + // InputStream in = LOADER.getResourceAsStream(path); + // int i; + // while (-1 != (i = in.read())) { + // System.out.print((char) i); + // } + // System.out.println(); + // } + // Map map = bundle.manifest.getEntries(); + // for (Iterator iter = map.entrySet().iterator(); iter.hasNext();) { + // MapEntry entry = (MapEntry) iter.next(); + // System.out.println("entry: " + entry); + // } + // System.out.println("main attributes"); + // Attributes attributes = bundle.manifest.getMainAttributes(); + // Set keys = attributes.keySet(); + // for (Iterator iter = keys.iterator(); iter.hasNext();) { + // Object key = iter.next(); + // System.out.println(" key " + key); + // System.out.println(" value " + attributes.getValue(key.toString())); + // } +} |