Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPascal Rapicault2008-10-30 16:45:13 +0000
committerPascal Rapicault2008-10-30 16:45:13 +0000
commita6dfcf2badcc0ef5b9a777bd2b4bf0092ee47792 (patch)
treed4d38ca1581a41dff9a37afd5ca2919bf9e9fec8 /bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/simpleconfigurator
parentd880852167bfca9b5095443806d4bdc8701f1151 (diff)
downloadrt.equinox.p2-a6dfcf2badcc0ef5b9a777bd2b4bf0092ee47792.tar.gz
rt.equinox.p2-a6dfcf2badcc0ef5b9a777bd2b4bf0092ee47792.tar.xz
rt.equinox.p2-a6dfcf2badcc0ef5b9a777bd2b4bf0092ee47792.zip
Add simpleconfigurator test on nonexclusive mode
Diffstat (limited to 'bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/simpleconfigurator')
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/simpleconfigurator/BundlesTxtTest.java109
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/simpleconfigurator/NonExclusiveMode.java175
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/simpleconfigurator/SimpleConfiguratorTests.java1
3 files changed, 215 insertions, 70 deletions
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/simpleconfigurator/BundlesTxtTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/simpleconfigurator/BundlesTxtTest.java
index dc2b043dc..dcea4fff2 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/simpleconfigurator/BundlesTxtTest.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/simpleconfigurator/BundlesTxtTest.java
@@ -22,13 +22,9 @@ import org.eclipse.equinox.p2.tests.embeddedequinox.EmbeddedEquinox;
import org.osgi.framework.*;
public class BundlesTxtTest extends AbstractProvisioningTest {
-
- static String BUNDLE_JAR_DIRECTORY = "bundlesTxt";
- int numBundles = -1;
+ static String BUNDLE_JAR_DIRECTORY = "simpleConfiguratorTest/bundlesTxt";
EmbeddedEquinox equinox = null;
BundleContext equinoxContext = null;
- File[] bundleJars = null;
- File bundlesTxt = null;
protected void setUp() throws Exception {
super.setUp();
@@ -39,22 +35,33 @@ public class BundlesTxtTest extends AbstractProvisioningTest {
equinox.shutdown();
}
- public void testBundlesTxt() throws Exception {
- File simpleconfiguratorDataDir = TestData.getFile(BUNDLE_JAR_DIRECTORY, "");
- bundleJars = getBundleJars(simpleconfiguratorDataDir);
+ //Assert that all files are in the bundles
+ private void assertJarsInstalled(File[] jars, Bundle[] bundles) {
+ for (int i = 0; i < jars.length; i++) {
+ boolean found = false;
+ String jarName = getManifestEntry(jars[i], Constants.BUNDLE_SYMBOLICNAME);
+ for (int j = 0; j < bundles.length; j++) {
+ String bundleName = bundles[j].getSymbolicName();
+ if (bundleName.equalsIgnoreCase(jarName))
+ found = true;
+ }
+ if (!found)
+ fail("Bundle should not be present: " + jarName);
+ }
+ }
- numBundles = bundleJars.length;
+ public void testBundlesTxt() throws Exception {
+ File[] jars = getBundleJars(TestData.getFile(BUNDLE_JAR_DIRECTORY, ""));
- // Create a test bundles.info
- createBundlesTxt();
+ // Create a bundles.info containing all the jars passed
+ File bundlesTxt = createBundlesTxt(jars);
- // for demonstration purposes this is just using an install.area and configuration.area located
- // in the local bundle data area. For p2 testing you will want to point this to your own properties
- File installarea = TestActivator.context.getDataFile("eclipse");
+ // for test purposes create an install.area and configuration.area located in the local bundle data area.
+ File installarea = TestActivator.context.getDataFile(getName() + "/eclipse");
File configarea = new File(installarea, "configuration");
- File simpleConfiguratorBundle = getSimpleConfiguratorBundle();
- URL osgiBundle = getFrameworkBundle();
+ File simpleConfiguratorBundle = getSimpleConfiguratorBundle(jars);
+ URL osgiBundle = getFrameworkBundle(jars);
Map frameworkProperties = new HashMap();
// note that any properties you do not want to be inherited from the hosting Equinox will need
@@ -64,81 +71,44 @@ public class BundlesTxtTest extends AbstractProvisioningTest {
frameworkProperties.put("osgi.configuration.area", configarea.toURL().toExternalForm());
frameworkProperties.put("osgi.bundles", "reference:" + simpleConfiguratorBundle.toURL().toExternalForm() + "@1:start"); // should point to simple configurator
frameworkProperties.put("org.eclipse.equinox.simpleconfigurator.configUrl", bundlesTxt.toURL().toExternalForm());
+
try {
equinox = new EmbeddedEquinox(frameworkProperties, new String[] {}, new URL[] {osgiBundle});
equinoxContext = equinox.startFramework();
- // verify that loaded bundles should be
- Bundle[] bundlesInContext = equinoxContext.getBundles();
- // are all bundles in list of expected bundles?
- for (int i = 0; i < bundlesInContext.length; i++) {
- Bundle bundle = bundlesInContext[i];
- boolean found = false;
- Bundle notFoundBundle = bundle;
- for (int j = 0; j < bundleJars.length; j++) {
- File expectedBundleFile = bundleJars[j];
- String name = getManifestEntry(expectedBundleFile, Constants.BUNDLE_SYMBOLICNAME);
- String bundleName = bundle.getSymbolicName();
- if (bundleName.equalsIgnoreCase(name))
- found = true;
- }
- if (!found)
- fail("Bundle should not be present: " + notFoundBundle);
- }
-
- // TODO: should we check start levels?
-
- // verify that all bundles expected to be loaded are in fact loaded
- for (int i = 0; i < bundleJars.length; i++) {
- File bundle = bundleJars[i];
- String name = getManifestEntry(bundle, Constants.BUNDLE_SYMBOLICNAME);
- boolean loaded = false;
- for (int j = 0; j < bundlesInContext.length; j++) {
- Bundle loadedBundle = bundlesInContext[j];
- if (loadedBundle.getSymbolicName().equalsIgnoreCase(name))
- loaded = true;
- }
- if (!loaded)
- fail("Bundle expected to be loaded but is not: " + name);
- }
-
- assertEquals("Too many/too few bundles!!", numBundles, bundlesInContext.length);
+ assertJarsInstalled(jars, equinoxContext.getBundles());
+ assertEquals(jars.length, equinoxContext.getBundles().length);
} finally {
equinox.shutdown();
}
}
- private File getSimpleConfiguratorBundle() {
- for (int i = 0; i < bundleJars.length; i++) {
- File bundleJar = bundleJars[i];
+ private File getSimpleConfiguratorBundle(File[] jars) {
+ for (int i = 0; i < jars.length; i++) {
+ File bundleJar = jars[i];
if (bundleJar.getName().startsWith("org.eclipse.equinox.simpleconfigurator"))
return bundleJar;
}
return null;
}
- private void createBundlesTxt() throws IOException {
- bundlesTxt = File.createTempFile("bundles", ".txt");
+ private File createBundlesTxt(File[] jars) throws IOException {
+ File bundlesTxt = File.createTempFile("bundles", ".txt");
bundlesTxt.deleteOnExit();
BufferedWriter bundlesTxtOut = new BufferedWriter(new FileWriter(bundlesTxt));
- for (int i = 0; i < bundleJars.length; i++) {
- File bundleJar = bundleJars[i];
+ for (int i = 0; i < jars.length; i++) {
+ File bundleJar = jars[i];
bundlesTxtOut.write(getBundlesTxtEntry(bundleJar) + "\n");
}
bundlesTxtOut.close();
- // FileInputStream f = new FileInputStream(bundlesTxt);
- // BufferedInputStream b = new BufferedInputStream(f);
- // DataInputStream d = new DataInputStream(b);
- // while (d.available() != 0) {
- // System.out.println(d.readLine());
- // }
+ return bundlesTxt;
}
- private String getBundlesTxtEntry(File bundleJar) throws IOException {
+ private String getBundlesTxtEntry(File bundleJar) {
String name = getManifestEntry(bundleJar, Constants.BUNDLE_SYMBOLICNAME);
String version = getManifestEntry(bundleJar, Constants.BUNDLE_VERSION);
// <name>,<version>,file:<file>,<startlevel>,true
@@ -152,8 +122,8 @@ public class BundlesTxtTest extends AbstractProvisioningTest {
if (value.indexOf(";") > -1) {
String[] valueElements = value.split(";");
return valueElements[0];
- } else
- return value;
+ }
+ return value;
} catch (IOException e) {
e.printStackTrace();
return null;
@@ -161,15 +131,14 @@ public class BundlesTxtTest extends AbstractProvisioningTest {
}
- private URL getFrameworkBundle() {
+ private URL getFrameworkBundle(File[] bundleJars) {
for (int i = 0; i < bundleJars.length; i++) {
File bundleJar = bundleJars[i];
if (bundleJar.getName().startsWith("org.eclipse.osgi"))
try {
return bundleJar.toURL();
} catch (MalformedURLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ fail("Can't find the osgi bundle");
}
}
return null;
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/simpleconfigurator/NonExclusiveMode.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/simpleconfigurator/NonExclusiveMode.java
new file mode 100644
index 000000000..5df09358d
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/simpleconfigurator/NonExclusiveMode.java
@@ -0,0 +1,175 @@
+/*******************************************************************************
+ * 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ * Red Hat, Inc. - tests
+ *******************************************************************************/
+package org.eclipse.equinox.p2.tests.simpleconfigurator;
+
+import java.io.*;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.jar.JarFile;
+import org.eclipse.equinox.internal.simpleconfigurator.utils.SimpleConfiguratorConstants;
+import org.eclipse.equinox.p2.tests.*;
+import org.eclipse.equinox.p2.tests.embeddedequinox.EmbeddedEquinox;
+import org.osgi.framework.*;
+
+public class NonExclusiveMode extends AbstractProvisioningTest {
+
+ static String BUNDLE_JAR_DIRECTORY = "simpleConfiguratorTest/bundlesTxt";
+ EmbeddedEquinox equinox = null;
+ BundleContext equinoxContext = null;
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ equinox.shutdown();
+ }
+
+ //Assert that all files are in the bundles
+ private void assertJarsInstalled(File[] jars, Bundle[] bundles) {
+ for (int i = 0; i < jars.length; i++) {
+ boolean found = false;
+ String jarName = getManifestEntry(jars[i], Constants.BUNDLE_SYMBOLICNAME);
+ for (int j = 0; j < bundles.length; j++) {
+ String bundleName = bundles[j].getSymbolicName();
+ if (bundleName.equalsIgnoreCase(jarName))
+ found = true;
+ }
+ if (!found)
+ fail("Bundle should not be present: " + jarName);
+ }
+ }
+
+ public void testBundlesTxt() throws Exception {
+ File[] jars = getBundleJars(TestData.getFile(BUNDLE_JAR_DIRECTORY, ""));
+
+ // Create a bundles.info containing all the jars passed
+ File bundlesTxt = createBundlesTxt(jars);
+
+ // for test purposes create an install.area and configuration.area located in the local bundle data area.
+ File installarea = TestActivator.context.getDataFile(getName() + "/eclipse");
+ File configarea = new File(installarea, "configuration");
+
+ File simpleConfiguratorBundle = getSimpleConfiguratorBundle(jars);
+ URL osgiBundle = getFrameworkBundle(jars);
+
+ File otherBundle = getTestData("myBundle", "testData/simpleConfiguratorTest/myBundle_1.0.0.jar");
+
+ Map frameworkProperties = new HashMap();
+ // note that any properties you do not want to be inherited from the hosting Equinox will need
+ // to be nulled out. Otherwise you will pick them up from the hosting env.
+ frameworkProperties.put("osgi.framework", null);
+ frameworkProperties.put("osgi.install.area", installarea.toURL().toExternalForm());
+ frameworkProperties.put("osgi.configuration.area", configarea.toURL().toExternalForm());
+ frameworkProperties.put("osgi.bundles", "reference:" + otherBundle.toURL().toExternalForm() + ",reference:" + simpleConfiguratorBundle.toURL().toExternalForm() + "@1:start"); // should point to simple configurator
+ frameworkProperties.put("org.eclipse.equinox.simpleconfigurator.configUrl", bundlesTxt.toURL().toExternalForm());
+ frameworkProperties.put(SimpleConfiguratorConstants.PROP_KEY_EXCLUSIVE_INSTALLATION, "false");
+
+ try {
+ equinox = new EmbeddedEquinox(frameworkProperties, new String[] {}, new URL[] {osgiBundle});
+ equinoxContext = equinox.startFramework();
+
+ assertJarsInstalled(jars, equinoxContext.getBundles());
+ assertJarsInstalled(new File[] {otherBundle}, equinoxContext.getBundles());
+ assertEquals(4, equinoxContext.getBundles().length);
+ } finally {
+ equinox.shutdown();
+ }
+ }
+
+ private File getSimpleConfiguratorBundle(File[] jars) {
+ for (int i = 0; i < jars.length; i++) {
+ File bundleJar = jars[i];
+ if (bundleJar.getName().startsWith("org.eclipse.equinox.simpleconfigurator"))
+ return bundleJar;
+ }
+ return null;
+ }
+
+ private File createBundlesTxt(File[] jars) throws IOException {
+ File bundlesTxt = File.createTempFile("bundles", ".txt");
+ bundlesTxt.deleteOnExit();
+
+ BufferedWriter bundlesTxtOut = new BufferedWriter(new FileWriter(bundlesTxt));
+
+ for (int i = 0; i < jars.length; i++) {
+ File bundleJar = jars[i];
+ bundlesTxtOut.write(getBundlesTxtEntry(bundleJar) + "\n");
+ }
+
+ bundlesTxtOut.close();
+
+ return bundlesTxt;
+ }
+
+ private String getBundlesTxtEntry(File bundleJar) {
+ String name = getManifestEntry(bundleJar, Constants.BUNDLE_SYMBOLICNAME);
+ String version = getManifestEntry(bundleJar, Constants.BUNDLE_VERSION);
+ // <name>,<version>,file:<file>,<startlevel>,true
+ return name + "," + version + "," + "file:" + bundleJar.getAbsolutePath() + "," + getStartLevel(name) + ",true";
+ }
+
+ private String getManifestEntry(File bundleFile, String entry) {
+ try {
+ JarFile bundleJar = new JarFile(bundleFile);
+ String value = bundleJar.getManifest().getMainAttributes().getValue(entry);
+ if (value.indexOf(";") > -1) {
+ String[] valueElements = value.split(";");
+ return valueElements[0];
+ }
+ return value;
+ } catch (IOException e) {
+ e.printStackTrace();
+ return null;
+ }
+
+ }
+
+ private URL getFrameworkBundle(File[] bundleJars) {
+ for (int i = 0; i < bundleJars.length; i++) {
+ File bundleJar = bundleJars[i];
+ if (bundleJar.getName().startsWith("org.eclipse.osgi"))
+ try {
+ return bundleJar.toURL();
+ } catch (MalformedURLException e) {
+ fail("Can't find the osgi bundle");
+ }
+ }
+ return null;
+ }
+
+ private int getStartLevel(String bundleName) {
+ int startLevel = 4;
+ // some special case start levels
+ if (bundleName.matches("org.eclipse.osgi")) {
+ startLevel = -1;
+ } else if (bundleName.matches("org.eclipse.equinox.common")) {
+ startLevel = 2;
+ } else if (bundleName.matches("org.eclipse.equinox.simpleconfigurator")) {
+ startLevel = 1;
+ }
+ return startLevel;
+ }
+
+ private File[] getBundleJars(File directory) {
+ FilenameFilter bundleFilter = new FilenameFilter() {
+ public boolean accept(File directoryName, String filename) {
+ return !filename.startsWith(".") && !filename.equals("CVS");
+ }
+ };
+ return directory.listFiles(bundleFilter);
+ }
+
+}
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/simpleconfigurator/SimpleConfiguratorTests.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/simpleconfigurator/SimpleConfiguratorTests.java
index 01ffc7bdb..8d50c5015 100644
--- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/simpleconfigurator/SimpleConfiguratorTests.java
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/simpleconfigurator/SimpleConfiguratorTests.java
@@ -17,6 +17,7 @@ public class SimpleConfiguratorTests {
TestSuite suite = new TestSuite("Tests for org.eclipse.equinox.simpleconfigurator");
//$JUnit-BEGIN$
suite.addTestSuite(BundlesTxtTest.class);
+ suite.addTestSuite(NonExclusiveMode.class);
//$JUnit-END$
return suite;
}

Back to the top