Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDJ Houghton2008-03-22 19:33:21 +0000
committerDJ Houghton2008-03-22 19:33:21 +0000
commite14fbcae7dc994bd67ea00366016cb6fc6d0926f (patch)
treec07eb4dd6ee6705b1e677ad51cc617f7b1765fc6 /bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/directorywatcher
parenta77ddb59237d59adf8096407d0264f15170d34c1 (diff)
downloadrt.equinox.p2-e14fbcae7dc994bd67ea00366016cb6fc6d0926f.tar.gz
rt.equinox.p2-e14fbcae7dc994bd67ea00366016cb6fc6d0926f.tar.xz
rt.equinox.p2-e14fbcae7dc994bd67ea00366016cb6fc6d0926f.zip
Bug 223506 - Need to improve reconciler tests
Diffstat (limited to 'bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/directorywatcher')
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/directorywatcher/AbstractDirectoryWatcherTest.java42
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/directorywatcher/AllTests.java3
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/directorywatcher/ProfileSynchronizerTest.java119
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/directorywatcher/RepositoryListenerTest.java131
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/directorywatcher/TestRepositoryWatcher.java82
5 files changed, 271 insertions, 106 deletions
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/directorywatcher/AbstractDirectoryWatcherTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/directorywatcher/AbstractDirectoryWatcherTest.java
new file mode 100644
index 000000000..3ee4d559e
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/directorywatcher/AbstractDirectoryWatcherTest.java
@@ -0,0 +1,42 @@
+/*******************************************************************************
+ * Copyright (c) 2008 IBM Corporation and others.
+ * 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://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.equinox.p2.tests.directorywatcher;
+
+import java.io.File;
+import java.util.*;
+import org.eclipse.equinox.p2.tests.AbstractProvisioningTest;
+
+/**
+ * @since 1.0
+ */
+public abstract class AbstractDirectoryWatcherTest extends AbstractProvisioningTest {
+
+ // list of File objects to remove later during teardown
+ protected Set toRemove = new HashSet();
+
+ /*
+ * Constructor for the class.
+ */
+ public AbstractDirectoryWatcherTest(String name) {
+ super(name);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.equinox.p2.tests.AbstractProvisioningTest#tearDown()
+ */
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ for (Iterator iter = toRemove.iterator(); iter.hasNext();)
+ delete((File) iter.next());
+ toRemove = new HashSet();
+ }
+
+}
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/directorywatcher/AllTests.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/directorywatcher/AllTests.java
index 3eadbe7b6..83638ae6c 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/directorywatcher/AllTests.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/directorywatcher/AllTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007 IBM Corporation and others.
+ * Copyright (c) 2007, 2008 IBM Corporation and others.
* 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
@@ -21,6 +21,7 @@ public class AllTests extends TestCase {
TestSuite suite = new TestSuite(AllTests.class.getName());
suite.addTestSuite(DirectoryWatcherTest.class);
suite.addTestSuite(RepositoryListenerTest.class);
+ suite.addTestSuite(ProfileSynchronizerTest.class);
return suite;
}
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/directorywatcher/ProfileSynchronizerTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/directorywatcher/ProfileSynchronizerTest.java
new file mode 100644
index 000000000..aa13bf6bf
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/directorywatcher/ProfileSynchronizerTest.java
@@ -0,0 +1,119 @@
+/*******************************************************************************
+ * Copyright (c) 2008 IBM Corporation and others.
+ * 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://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.equinox.p2.tests.directorywatcher;
+
+import java.io.File;
+import java.util.*;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import org.eclipse.equinox.internal.provisional.p2.metadata.IArtifactKey;
+import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit;
+import org.osgi.framework.Version;
+
+/**
+ * @since 1.0
+ */
+public class ProfileSynchronizerTest extends AbstractDirectoryWatcherTest {
+
+ /*
+ * Constructor for the class.
+ */
+ public ProfileSynchronizerTest(String name) {
+ super(name);
+ }
+
+ /*
+ * Run all the tests in this class.
+ */
+ public static Test suite() {
+ return new TestSuite(ProfileSynchronizerTest.class);
+ }
+
+ public void test() {
+ // empty test because the others aren't enabled yet
+ }
+
+ /*
+ * Test that we only try to install bundles with matching platform filters.
+ *
+ * TODO we don't want to test to see if the bundles are in the repo, but if
+ * the bundles are filtered when they are installed into a profile.
+ */
+ public void _testPlatformFilter() {
+ String base = "/testData/profileSynchronizer/";
+ String[] extensions = new String[] {"bbb_1.0.0.jar", "bbb.linux_1.0.0.jar", "bbb.win32_1.0.0.jar"};
+ Set jars = new HashSet();
+ for (int i = 0; i < extensions.length; i++)
+ jars.add(getTestData("0.99", base + extensions[i]));
+ File folder = getTempFolder();
+ toRemove.add(folder);
+ for (Iterator iter = jars.iterator(); iter.hasNext();) {
+ File next = (File) iter.next();
+ copy("1.0 " + next.getAbsolutePath(), next, new File(folder, next.getName()));
+ }
+
+ // We should have an empty repository because we haven't done anything yet
+ TestRepositoryWatcher watcher = TestRepositoryWatcher.createWatcher(folder);
+ assertEquals("2.0", 0, watcher.getInstallableUnits().length);
+ assertEquals("2.1", 0, watcher.getArtifactKeys().length);
+
+ watcher.poll();
+
+ // which IUs we are expecting is dependent on which OS we are running
+ Set expected = new HashSet();
+ expected.add("bbb");
+ String os = System.getProperty("osgi.os");
+ if ("win32".equals(os)) {
+ expected.add("bbb.win32");
+ } else if ("linux".equals(os)) {
+ expected.add("bbb.linux");
+ }
+
+ IInstallableUnit[] ius = watcher.getInstallableUnits();
+ assertEquals("3.0", expected.size(), ius.length);
+ for (int i = 0; i < ius.length; i++)
+ assertTrue("3.1 " + ius[i].getId(), expected.contains(ius[i].getId()));
+ assertEquals("3.2", expected.size(), watcher.getArtifactKeys().length);
+ }
+
+ /*
+ * Test to ensure that we only try to install the highest version of singleton bundles
+ * where multiple versions exist.
+ *
+ * TODO we don't want to test to see if the bundles are in the repo, but if
+ * the bundles are filtered when they are installed into a profile.
+ */
+ public void _testMultipleVersions() {
+ File one = getTestData("0.1", "/testData/profileSynchronizer/ccc_1.0.0.jar");
+ File two = getTestData("0.2", "/testData/profileSynchronizer/ccc_2.0.0.jar");
+ File folder = getTempFolder();
+ toRemove.add(folder);
+
+ copy("1.0", one, new File(folder, one.getName()));
+ copy("1.1", two, new File(folder, two.getName()));
+
+ TestRepositoryWatcher watcher = TestRepositoryWatcher.createWatcher(folder);
+
+ // We should have an empty repository because we haven't done anything yet
+ assertEquals("2.0", 0, watcher.getInstallableUnits().length);
+ assertEquals("2.1", 0, watcher.getArtifactKeys().length);
+
+ watcher.poll();
+
+ IInstallableUnit[] ius = watcher.getInstallableUnits();
+ IArtifactKey[] artifacts = watcher.getArtifactKeys();
+ assertEquals("3.0", 1, ius.length);
+ assertEquals("3.1", "ccc", ius[0].getId());
+ assertEquals("3.2", new Version("2.0.0"), ius[0].getVersion());
+ assertEquals("4.0", 1, artifacts.length);
+ }
+
+}
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/directorywatcher/RepositoryListenerTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/directorywatcher/RepositoryListenerTest.java
index 44565930c..66f57adce 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/directorywatcher/RepositoryListenerTest.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/directorywatcher/RepositoryListenerTest.java
@@ -11,85 +11,11 @@
package org.eclipse.equinox.p2.tests.directorywatcher;
import java.io.File;
-import java.io.IOException;
-import java.net.URL;
-import java.util.*;
import junit.framework.Test;
import junit.framework.TestSuite;
-import org.eclipse.core.runtime.FileLocator;
-import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IFileArtifactRepository;
-import org.eclipse.equinox.internal.provisional.p2.directorywatcher.DirectoryWatcher;
-import org.eclipse.equinox.internal.provisional.p2.directorywatcher.RepositoryListener;
import org.eclipse.equinox.internal.provisional.p2.metadata.IArtifactKey;
-import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit;
-import org.eclipse.equinox.internal.provisional.p2.metadata.query.InstallableUnitQuery;
-import org.eclipse.equinox.internal.provisional.p2.query.Collector;
-import org.eclipse.equinox.p2.tests.AbstractProvisioningTest;
-import org.eclipse.equinox.p2.tests.TestActivator;
-import org.osgi.framework.BundleContext;
-public class RepositoryListenerTest extends AbstractProvisioningTest {
-
- /*
- * Helper class for testing directory watchers with repository listeners. Allows easy access to the
- * information known by the metadata and artifact repositories.
- */
- static class TestRepositoryWatcher extends DirectoryWatcher {
-
- private RepositoryListener listener;
-
- /*
- * Create and return a new test directory watcher class which will listen on the given folder.
- */
- public static TestRepositoryWatcher createWatcher(File folder) {
- RepositoryListener listener = new RepositoryListener(TestActivator.getContext(), AbstractProvisioningTest.getUniqueString());
- Dictionary props = new Hashtable();
- props.put(DirectoryWatcher.DIR, folder.getAbsolutePath());
- props.put(DirectoryWatcher.POLL, "500");
- TestRepositoryWatcher result = new TestRepositoryWatcher(props, TestActivator.getContext());
- result.addListener(listener);
- return result;
- }
-
- /*
- * Constructor for the class.
- */
- private TestRepositoryWatcher(Dictionary props, BundleContext context) {
- super(props, context);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.equinox.internal.provisional.p2.directorywatcher.DirectoryWatcher#addListener(org.eclipse.equinox.internal.provisional.p2.directorywatcher.DirectoryChangeListener)
- */
- public synchronized void addListener(RepositoryListener repoListener) {
- super.addListener(repoListener);
- this.listener = repoListener;
- }
-
- /*
- * Return the list of all the IUs known to the metadata repository this watcher's listener.
- */
- public IInstallableUnit[] getInstallableUnits() {
- return (IInstallableUnit[]) listener.getMetadataRepository().query(InstallableUnitQuery.ANY, new Collector(), null).toArray(IInstallableUnit.class);
- }
-
- /*
- * Return the list of artifact keys known to this listener's repository.
- */
- public IArtifactKey[] getArtifactKeys() {
- return listener.getArtifactRepository().getArtifactKeys();
- }
-
- /*
- * Return the file associated with the given artifact key.
- */
- public File getArtifactFile(IArtifactKey key) {
- return ((IFileArtifactRepository) listener.getArtifactRepository()).getArtifactFile(key);
- }
- }
-
- // list of File objects to remove later during teardown
- private Set toRemove = new HashSet();
+public class RepositoryListenerTest extends AbstractDirectoryWatcherTest {
/*
* Constructor for the class.
@@ -105,16 +31,6 @@ public class RepositoryListenerTest extends AbstractProvisioningTest {
return new TestSuite(RepositoryListenerTest.class);
}
- /* (non-Javadoc)
- * @see org.eclipse.equinox.p2.tests.AbstractProvisioningTest#tearDown()
- */
- protected void tearDown() throws Exception {
- super.tearDown();
- for (Iterator iter = toRemove.iterator(); iter.hasNext();)
- delete((File) iter.next());
- toRemove = new HashSet();
- }
-
/*
* Remove the files from the target, if they exist in the source.
*/
@@ -127,20 +43,6 @@ public class RepositoryListenerTest extends AbstractProvisioningTest {
}
}
- /*
- * Look up and return a file handle to the given entry in the bundle.
- */
- private File getTestData(String message, String entry) {
- URL base = TestActivator.getContext().getBundle().getEntry(entry);
- try {
- return new File(FileLocator.toFileURL(base).getPath());
- } catch (IOException e) {
- fail(message, e);
- }
- // avoid compile error... should never reach this code
- return null;
- }
-
public void testDirectoryWatcherListener() {
File baseFolder = getTestData("0.99", "/testData/directorywatcher1");
File baseFolder2 = getTestData("0.100", "/testData/directorywatcher2");
@@ -185,13 +87,32 @@ public class RepositoryListenerTest extends AbstractProvisioningTest {
* proper OSGi manifest files so the bundle can be installed
*/
public void testPluginXMLConversion() {
- // TODO test plugin.xml in a JAR'd bundle
-
- // TODO test plugin.xml in a directory-based bundle
-
- // TODO test plugin.xml in the presence of an Ant Manifest file in a JAR'd bundle
+ // test plugin.xml in a JAR'd bundle
+ File oldBundleJAR = getTestData("0.1", "/testData/repositoryListener/oldBundleJAR.jar");
+ // test plugin.xml in a directory-based bundle
+ File oldBundleDirectory = getTestData("0.2", "/testData/repositoryListener/oldBundleDirectory");
+ // test plugin.xml in the presence of an Ant Manifest file in a JAR'd bundle
+ File oldBundleJARTwo = getTestData("0.3", "/testData/repositoryListener/oldBundleJARTwo.jar");
+ // test plugin.xml in the presence of an Ant Manifest file in a directory-based bundle
+ File oldBundleDirectoryTwo = getTestData("0.4", "/testData/repositoryListener/oldBundleDirectoryTwo");
+
+ // copy the test bundles over to where we will be watching in the repo listener
+ File folder = getTempFolder();
+ toRemove.add(folder);
+ copy("1.0", oldBundleJAR, new File(folder, oldBundleJAR.getName()));
+ copy("1.1", oldBundleJARTwo, new File(folder, oldBundleJARTwo.getName()));
+ copy("1.2", oldBundleDirectory, new File(folder, oldBundleDirectory.getName()));
+ copy("1.3", oldBundleDirectoryTwo, new File(folder, oldBundleDirectoryTwo.getName()));
- // TODO test plugin.xml in the presence of an Ant Manifest file in a directory-based bundle
+ // We should have an empty repository because we haven't done anything yet
+ TestRepositoryWatcher watcher = TestRepositoryWatcher.createWatcher(folder);
+ assertEquals("2.0", 0, watcher.getInstallableUnits().length);
+ assertEquals("2.1", 0, watcher.getArtifactKeys().length);
+ watcher.poll();
+ // the repo should have added all 4 bundles
+ assertEquals("3.0", 4, watcher.getInstallableUnits().length);
+ assertEquals("3.1", 4, watcher.getArtifactKeys().length);
}
+
}
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/directorywatcher/TestRepositoryWatcher.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/directorywatcher/TestRepositoryWatcher.java
new file mode 100644
index 000000000..189da70ed
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/directorywatcher/TestRepositoryWatcher.java
@@ -0,0 +1,82 @@
+/*******************************************************************************
+ * Copyright (c) 2008 IBM Corporation and others.
+ * 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://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.equinox.p2.tests.directorywatcher;
+
+import java.io.File;
+import java.util.Dictionary;
+import java.util.Hashtable;
+import org.eclipse.equinox.internal.provisional.p2.artifact.repository.IFileArtifactRepository;
+import org.eclipse.equinox.internal.provisional.p2.directorywatcher.DirectoryWatcher;
+import org.eclipse.equinox.internal.provisional.p2.directorywatcher.RepositoryListener;
+import org.eclipse.equinox.internal.provisional.p2.metadata.IArtifactKey;
+import org.eclipse.equinox.internal.provisional.p2.metadata.IInstallableUnit;
+import org.eclipse.equinox.internal.provisional.p2.metadata.query.InstallableUnitQuery;
+import org.eclipse.equinox.internal.provisional.p2.query.Collector;
+import org.eclipse.equinox.p2.tests.AbstractProvisioningTest;
+import org.eclipse.equinox.p2.tests.TestActivator;
+import org.osgi.framework.BundleContext;
+
+/**
+ * Helper test class which wraps a repository listener.
+ */
+class TestRepositoryWatcher extends DirectoryWatcher {
+
+ private RepositoryListener listener;
+
+ /*
+ * Create and return a new test directory watcher class which will listen on the given folder.
+ */
+ public static TestRepositoryWatcher createWatcher(File folder) {
+ RepositoryListener listener = new RepositoryListener(TestActivator.getContext(), AbstractProvisioningTest.getUniqueString());
+ Dictionary props = new Hashtable();
+ props.put(DirectoryWatcher.DIR, folder.getAbsolutePath());
+ props.put(DirectoryWatcher.POLL, "500");
+ TestRepositoryWatcher result = new TestRepositoryWatcher(props, TestActivator.getContext());
+ result.addListener(listener);
+ return result;
+ }
+
+ /*
+ * Constructor for the class.
+ */
+ private TestRepositoryWatcher(Dictionary props, BundleContext context) {
+ super(props, context);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.equinox.internal.provisional.p2.directorywatcher.DirectoryWatcher#addListener(org.eclipse.equinox.internal.provisional.p2.directorywatcher.DirectoryChangeListener)
+ */
+ public synchronized void addListener(RepositoryListener repoListener) {
+ super.addListener(repoListener);
+ this.listener = repoListener;
+ }
+
+ /*
+ * Return the list of all the IUs known to the metadata repository this watcher's listener.
+ */
+ public IInstallableUnit[] getInstallableUnits() {
+ return (IInstallableUnit[]) listener.getMetadataRepository().query(InstallableUnitQuery.ANY, new Collector(), null).toArray(IInstallableUnit.class);
+ }
+
+ /*
+ * Return the list of artifact keys known to this listener's repository.
+ */
+ public IArtifactKey[] getArtifactKeys() {
+ return listener.getArtifactRepository().getArtifactKeys();
+ }
+
+ /*
+ * Return the file associated with the given artifact key.
+ */
+ public File getArtifactFile(IArtifactKey key) {
+ return ((IFileArtifactRepository) listener.getArtifactRepository()).getArtifactFile(key);
+ }
+} \ No newline at end of file

Back to the top