Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPascal Rapicault2008-02-08 21:19:12 +0000
committerPascal Rapicault2008-02-08 21:19:12 +0000
commit7829bf04ba84abb878e308d4ee67a366f394ee33 (patch)
treef8db4de6655845e22ec5ec37ab9dc5230a63cc4e /bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/simpleconfigurator
parent1530132495aacd97b93dcd2b080259b8b6e14e05 (diff)
downloadrt.equinox.p2-7829bf04ba84abb878e308d4ee67a366f394ee33.tar.gz
rt.equinox.p2-7829bf04ba84abb878e308d4ee67a366f394ee33.tar.xz
rt.equinox.p2-7829bf04ba84abb878e308d4ee67a366f394ee33.zip
bug 212774 - [prov] tests for simpleconfigurator
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.java200
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/simpleconfigurator/SimpleConfiguratorTests.java24
2 files changed, 224 insertions, 0 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
new file mode 100644
index 000000000..20035167c
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/simpleconfigurator/BundlesTxtTest.java
@@ -0,0 +1,200 @@
+/*******************************************************************************
+ * 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.p2.tests.*;
+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;
+ EmbeddedEquinox equinox = null;
+ BundleContext equinoxContext = null;
+ File[] bundleJars = null;
+ File bundlesTxt = null;
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ equinox.shutdown();
+ }
+
+ public void testBundlesTxt() throws Exception {
+ File simpleconfiguratorDataDir = TestData.getFile(BUNDLE_JAR_DIRECTORY, "");
+ bundleJars = getBundleJars(simpleconfiguratorDataDir);
+
+ numBundles = bundleJars.length;
+
+ // Create a test bundles.txt
+ createBundlesTxt();
+
+ // 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");
+ File configarea = new File(installarea, "configuration");
+
+ File simpleConfiguratorBundle = getSimpleConfiguratorBundle();
+ URL osgiBundle = getFrameworkBundle();
+
+ 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:" + 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);
+ } finally {
+ equinox.shutdown();
+ }
+ }
+
+ private File getSimpleConfiguratorBundle() {
+ for (int i = 0; i < bundleJars.length; i++) {
+ File bundleJar = bundleJars[i];
+ if (bundleJar.getName().startsWith("org.eclipse.equinox.simpleconfigurator"))
+ return bundleJar;
+ }
+ return null;
+ }
+
+ private void createBundlesTxt() throws IOException {
+ 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];
+ 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());
+ // }
+ }
+
+ private String getBundlesTxtEntry(File bundleJar) throws IOException {
+ 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];
+ } else
+ return value;
+ } catch (IOException e) {
+ e.printStackTrace();
+ return null;
+ }
+
+ }
+
+ private URL getFrameworkBundle() {
+ 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();
+ }
+ }
+ 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(".");
+ }
+ };
+ 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
new file mode 100644
index 000000000..01ffc7bdb
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/simpleconfigurator/SimpleConfiguratorTests.java
@@ -0,0 +1,24 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Red Hat, Inc. 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: Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.equinox.p2.tests.simpleconfigurator;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+public class SimpleConfiguratorTests {
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite("Tests for org.eclipse.equinox.simpleconfigurator");
+ //$JUnit-BEGIN$
+ suite.addTestSuite(BundlesTxtTest.class);
+ //$JUnit-END$
+ return suite;
+ }
+
+}

Back to the top