diff options
Diffstat (limited to 'bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles')
4 files changed, 115 insertions, 3 deletions
diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/BundleExceptionTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/BundleExceptionTests.java new file mode 100644 index 000000000..813ee7131 --- /dev/null +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/BundleExceptionTests.java @@ -0,0 +1,97 @@ +/******************************************************************************* + * 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.osgi.tests.bundles; + +import java.io.IOException; +import java.net.URL; +import junit.framework.Test; +import junit.framework.TestSuite; +import org.eclipse.osgi.tests.OSGiTestsActivator; +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleException; + +public class BundleExceptionTests extends AbstractBundleTests { + public static Test suite() { + return new TestSuite(BundleExceptionTests.class); + } + + // test throwing exception from activator constructor + public void testInvalidBundleActivator01() throws BundleException { + Bundle error1 = installer.installBundle("activator.error1"); //$NON-NLS-1$ + try { + error1.start(); + fail("Expected a start failure on invalid activator"); //$NON-NLS-1$ + } catch (BundleException e) { + assertEquals("Expected activator error", BundleException.ACTIVATOR_ERROR, e.getType()); //$NON-NLS-1$ + } + } + + // test throwing exception from activator start + public void testInvalidBundleActivator02() throws BundleException { + Bundle error1 = installer.installBundle("activator.error2"); //$NON-NLS-1$ + try { + error1.start(); + fail("Expected a start failure on invalid activator"); //$NON-NLS-1$ + } catch (BundleException e) { + assertEquals("Expected activator error", BundleException.ACTIVATOR_ERROR, e.getType()); //$NON-NLS-1$ + } + } + + // test throwing exception from activator stop + public void testInvalidBundleActivator03() throws BundleException { + Bundle error1 = installer.installBundle("activator.error3"); //$NON-NLS-1$ + error1.start(); + try { + error1.stop(); + fail("Expected a stop failure on invalid activator"); //$NON-NLS-1$ + } catch (BundleException e) { + assertEquals("Expected activator error", BundleException.ACTIVATOR_ERROR, e.getType()); //$NON-NLS-1$ + } + } + + // test throwing exception when installing duplicate bundles + public void testDuplicateError01() throws BundleException { + installer.installBundle("activator.error1"); //$NON-NLS-1$ + try { + installer.installBundle("activator.error4"); //$NON-NLS-1$; + fail("Expected an install failure on duplicate bundle"); //$NON-NLS-1$ + } catch (BundleException e) { + assertEquals("Expected duplicate error", BundleException.DUPLICATE_BUNDLE_ERROR, e.getType()); //$NON-NLS-1$ + } + } + + // test throwing exception when updating to a duplicate bundle + public void testDuplicateError02() throws BundleException { + installer.installBundle("activator.error1"); //$NON-NLS-1$ + Bundle error2 = installer.installBundle("activator.error2"); //$NON-NLS-1$ + try { + URL updateURL = new URL(installer.getBundleLocation("activator.error4")); //$NON-NLS-1$ + error2.update(updateURL.openStream()); + fail("Expected an update failure on duplicate bundle"); //$NON-NLS-1$ + } catch (BundleException e) { + assertEquals("Expected duplicate error", BundleException.DUPLICATE_BUNDLE_ERROR, e.getType()); //$NON-NLS-1$ + } catch (IOException e) { + fail("Unexpected io exception updating", e); //$NON-NLS-1$ + } + } + + // test uninstalling the system bundle + public void testUninstallSystemBundle() throws BundleException { + Bundle systemBundle = OSGiTestsActivator.getContext().getBundle(0); + assertNotNull("System Bundle is null!!", systemBundle); //$NON-NLS-1$ + try { + systemBundle.uninstall(); + fail("Expected error on uninstall of system bundle"); //$NON-NLS-1$ + } catch (BundleException e) { + assertEquals("Expected invalid error", BundleException.INVALID_OPERATION, e.getType()); //$NON-NLS-1$ + } + } +} diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/BundleTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/BundleTests.java index 8f4e75d11..24d7b9cdf 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/BundleTests.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/BundleTests.java @@ -18,6 +18,7 @@ public class BundleTests { TestSuite suite = new TestSuite(BundleTests.class.getName()); suite.addTest(SystemBundleTests.suite()); suite.addTest(ServiceRegistryBundleTests.suite()); + suite.addTest(BundleExceptionTests.suite()); suite.addTest(SubstituteExportsBundleTests.suite()); suite.addTest(PackageAdminBundleTests.suite()); suite.addTest(PlatformAdminBundleTests.suite()); diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/ClassLoadingBundleTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/ClassLoadingBundleTests.java index d327d4372..6e8f0a9df 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/ClassLoadingBundleTests.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/ClassLoadingBundleTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. + * Copyright (c) 2006, 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 @@ -356,7 +356,7 @@ public class ClassLoadingBundleTests extends AbstractBundleTests { osgiA.start(Bundle.START_TRANSIENT); assertFalse("Bundle is started!!", osgiA.getState() == Bundle.ACTIVE); //$NON-NLS-1$ } catch (BundleException e) { - // expected + assertEquals("Expected invalid operation", BundleException.INVALID_OPERATION, e.getType()); //$NON-NLS-1$ } expectedEvents = new Object[0]; actualEvents = simpleResults.getResults(0); diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/NativeCodeBundleTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/NativeCodeBundleTests.java index d829ac151..863efa891 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/NativeCodeBundleTests.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/NativeCodeBundleTests.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 @@ -14,6 +14,7 @@ import java.io.*; import junit.framework.Test; import junit.framework.TestSuite; import org.osgi.framework.Bundle; +import org.osgi.framework.BundleException; public class NativeCodeBundleTests extends AbstractBundleTests { public static Test suite() { @@ -108,6 +109,19 @@ public class NativeCodeBundleTests extends AbstractBundleTests { assertNull("1.1", results[0]); } + public void testNativeCode08() throws Exception { + System.setProperty("nativecodetest", "4"); + setPlatformProperties(); + Bundle nativetestC = installer.installBundle("nativetest.c"); + try { + nativetestC.start(); + fail("Should not be able to start bundle with missing native code path"); + } catch (BundleException e) { + // expected + assertEquals("Wrong exception type", BundleException.NATIVECODE_ERROR, e.getType()); + } + } + private String getContent(String file) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file))); try { |