[jboss-cvs] JBossAS SVN: r102218 - in projects/jboss-osgi/projects/runtime/framework/trunk: bundle/src/test/java/org/jboss/test/osgi and 4 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Mar 10 05:29:13 EST 2010
Author: thomas.diesler at jboss.com
Date: 2010-03-10 05:29:13 -0500 (Wed, 10 Mar 2010)
New Revision: 102218
Added:
projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/NativeFrameworkTest.java
Modified:
projects/jboss-osgi/projects/runtime/framework/trunk/bundle/pom.xml
projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/FrameworkTest.java
projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/bundle/BundleContextUnitTestCase.java
projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/bundle/BundleEntriesUnitTestCase.java
projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/bundle/BundleLifecycleTestCase.java
projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/bundle/BundleUnitTestCase.java
projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/bundle/SystemBundleUnitTestCase.java
projects/jboss-osgi/projects/runtime/framework/trunk/core/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleWrapper.java
projects/jboss-osgi/projects/runtime/framework/trunk/core/src/main/java/org/jboss/osgi/framework/launch/OSGiFramework.java
projects/jboss-osgi/projects/runtime/framework/trunk/core/src/main/java/org/jboss/osgi/framework/plugins/internal/FrameworkEventsPluginImpl.java
Log:
Migrate bundle tests to OSGiTest
Modified: projects/jboss-osgi/projects/runtime/framework/trunk/bundle/pom.xml
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/bundle/pom.xml 2010-03-10 10:27:55 UTC (rev 102217)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/bundle/pom.xml 2010-03-10 10:29:13 UTC (rev 102218)
@@ -13,6 +13,7 @@
<!--
Set these VM properties in your IDE debugger
+
-Dlog4j.output.dir=${workspace_loc:jboss-osgi-framework/target}
-Dlog4j.configuration=log4j-console.xml
-->
Modified: projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/FrameworkTest.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/FrameworkTest.java 2010-03-10 10:27:55 UTC (rev 102217)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/FrameworkTest.java 2010-03-10 10:29:13 UTC (rev 102218)
@@ -59,6 +59,7 @@
* @author <a href="baileyje at gmail.com">John Bailey</a>
* @version $Revision: 87848 $
*/
+ at Deprecated // This has a dependency on VFS21 - use OSGiTest.
public abstract class FrameworkTest extends MicrocontainerTest implements FrameworkListener, SynchronousBundleListener, ServiceListener
{
private final List<FrameworkEvent> frameworkEvents = new CopyOnWriteArrayList<FrameworkEvent>();
Added: projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/NativeFrameworkTest.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/NativeFrameworkTest.java (rev 0)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/NativeFrameworkTest.java 2010-03-10 10:29:13 UTC (rev 102218)
@@ -0,0 +1,225 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.osgi;
+
+// $Id: $
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+import org.jboss.logging.Logger;
+import org.jboss.osgi.framework.bundle.AbstractBundleState;
+import org.jboss.osgi.spi.framework.OSGiBootstrap;
+import org.jboss.osgi.spi.framework.OSGiBootstrapProvider;
+import org.jboss.osgi.spi.util.ConstantsHelper;
+import org.jboss.osgi.testing.OSGiTest;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleEvent;
+import org.osgi.framework.FrameworkEvent;
+import org.osgi.framework.FrameworkListener;
+import org.osgi.framework.ServiceEvent;
+import org.osgi.framework.ServiceListener;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.SynchronousBundleListener;
+import org.osgi.framework.launch.Framework;
+
+/**
+ * Parent for native framework tests.
+ *
+ * @author Thomas.Diesler at jboss.com
+ * @since 10-Mar-2010
+ */
+public abstract class NativeFrameworkTest extends OSGiTest implements ServiceListener, SynchronousBundleListener, FrameworkListener
+{
+ // Provide logging
+ private static final Logger log = Logger.getLogger(NativeFrameworkTest.class);
+
+ protected static Framework framework;
+ protected static BundleContext context;
+
+ private final List<FrameworkEvent> frameworkEvents = new CopyOnWriteArrayList<FrameworkEvent>();
+ private final List<BundleEvent> bundleEvents = new CopyOnWriteArrayList<BundleEvent>();
+ private final List<ServiceEvent> serviceEvents = new CopyOnWriteArrayList<ServiceEvent>();
+
+ @BeforeClass
+ public static void beforeClass() throws Exception
+ {
+ OSGiBootstrapProvider bootProvider = OSGiBootstrap.getBootstrapProvider();
+ framework = bootProvider.getFramework();
+ framework.start();
+
+ // Get the system context
+ context = framework.getBundleContext();
+ }
+
+ @AfterClass
+ public static void afterClass() throws Exception
+ {
+ if (framework != null)
+ {
+ framework.stop();
+ framework.waitForStop(2000);
+ framework = null;
+ }
+ }
+
+ protected void assertNoBundleEvent() throws Exception
+ {
+ log.debug("bundleEvents=" + bundleEvents);
+ assertEquals(0, bundleEvents.size());
+ }
+
+ protected void assertBundleEvent(int type, Bundle bundle) throws Exception
+ {
+ waitForEvent(bundleEvents, type);
+
+ log.debug("bundleEvents=" + bundleEvents);
+ int size = bundleEvents.size();
+ assertTrue("" + size, size > 0);
+
+ if (bundle instanceof AbstractBundleState)
+ bundle = ((AbstractBundleState)bundle).getBundle();
+
+ BundleEvent foundEvent = null;
+ for (int i = 0; i < bundleEvents.size(); i++)
+ {
+ BundleEvent aux = bundleEvents.get(i);
+ if (type == aux.getType())
+ {
+ if (bundle.equals(aux.getSource()) && bundle.equals(aux.getBundle()))
+ {
+ bundleEvents.remove(aux);
+ foundEvent = aux;
+ break;
+ }
+ }
+ }
+
+ if (foundEvent == null)
+ fail("Cannot find event " + ConstantsHelper.bundleEvent(type) + " from " + bundle);
+ }
+
+ @Override
+ public void frameworkEvent(FrameworkEvent event)
+ {
+ synchronized (frameworkEvents)
+ {
+ log.debug("FrameworkEvent type=" + ConstantsHelper.frameworkEvent(event.getType()) + " for " + event);
+ frameworkEvents.add(event);
+ frameworkEvents.notifyAll();
+ }
+ }
+
+ @Override
+ public void bundleChanged(BundleEvent event)
+ {
+ synchronized (bundleEvents)
+ {
+ log.debug("BundleChanged type=" + ConstantsHelper.bundleEvent(event.getType()) + " for " + event);
+ bundleEvents.add(event);
+ bundleEvents.notifyAll();
+ }
+ }
+
+ @Override
+ public void serviceChanged(ServiceEvent event)
+ {
+ synchronized (serviceEvents)
+ {
+ log.debug("ServiceChanged type=" + ConstantsHelper.serviceEvent(event.getType()) + " for " + event);
+ serviceEvents.add(event);
+ serviceEvents.notifyAll();
+ }
+ }
+
+ protected void assertNoServiceEvent() throws Exception
+ {
+ log.debug("serviceEvents=" + serviceEvents);
+ assertEquals(0, serviceEvents.size());
+ }
+
+ protected void assertServiceEvent(int type, ServiceReference reference) throws Exception
+ {
+ waitForEvent(serviceEvents, type);
+ log.debug("serviceEvents=" + serviceEvents);
+ int size = serviceEvents.size();
+ assertTrue("" + size, size > 0);
+ ServiceEvent event = serviceEvents.remove(0);
+ assertEquals(ConstantsHelper.serviceEvent(type), ConstantsHelper.serviceEvent(event.getType()));
+ assertEquals(reference, event.getSource());
+ assertEquals(reference, event.getServiceReference());
+ }
+
+ @SuppressWarnings("rawtypes")
+ private void waitForEvent(List events, int type) throws InterruptedException
+ {
+ // Timeout for event delivery: 3 sec
+ int timeout = 30;
+
+ boolean eventFound = false;
+ while (eventFound == false && 0 < timeout)
+ {
+ synchronized (events)
+ {
+ events.wait(100);
+ for (Object aux : events)
+ {
+ if (aux instanceof BundleEvent)
+ {
+ BundleEvent event = (BundleEvent)aux;
+ if (type == event.getType())
+ {
+ eventFound = true;
+ break;
+ }
+ }
+ else if (aux instanceof ServiceEvent)
+ {
+ ServiceEvent event = (ServiceEvent)aux;
+ if (type == event.getType())
+ {
+ eventFound = true;
+ break;
+ }
+ }
+ else if (aux instanceof FrameworkEvent)
+ {
+ FrameworkEvent event = (FrameworkEvent)aux;
+ if (type == event.getType())
+ {
+ eventFound = true;
+ break;
+ }
+ }
+ }
+ }
+ timeout--;
+ }
+ }
+}
Modified: projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/bundle/BundleContextUnitTestCase.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/bundle/BundleContextUnitTestCase.java 2010-03-10 10:27:55 UTC (rev 102217)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/bundle/BundleContextUnitTestCase.java 2010-03-10 10:29:13 UTC (rev 102218)
@@ -21,6 +21,14 @@
*/
package org.jboss.test.osgi.bundle;
+// $Id: $
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
import java.io.File;
import java.net.URL;
import java.util.Arrays;
@@ -30,10 +38,9 @@
import java.util.Locale;
import java.util.Set;
-import junit.framework.Test;
-
-import org.jboss.osgi.testing.OSGiTestHelper;
-import org.jboss.test.osgi.FrameworkTest;
+import org.jboss.osgi.vfs.VirtualFile;
+import org.jboss.test.osgi.NativeFrameworkTest;
+import org.junit.Test;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleEvent;
@@ -50,21 +57,13 @@
* @author Thomas.Diesler at jboss.com
* @version $Revision: 1.1 $
*/
-public class BundleContextUnitTestCase extends FrameworkTest
+public class BundleContextUnitTestCase extends NativeFrameworkTest
{
- public static Test suite()
- {
- return suite(BundleContextUnitTestCase.class);
- }
-
- public BundleContextUnitTestCase(String name)
- {
- super(name);
- }
-
+ @Test
public void testGetBundle() throws Exception
{
- Bundle bundle1 = addBundle("/bundles/simple/", "simple-bundle1");
+ VirtualFile assembly1 = assembleBundle("simple-bundle1", "/bundles/simple/simple-bundle1", new Class[0]);
+ Bundle bundle1 = context.installBundle(assembly1.toURL().toExternalForm());
BundleContext context1 = null;
try
{
@@ -75,11 +74,11 @@
Bundle[] bundles = context1.getBundles();
Set<Bundle> actual = new HashSet<Bundle>(Arrays.asList(bundles));
- Set<Bundle> expected = new HashSet<Bundle>(Arrays.asList(bundle1));
- addBaseBundles(expected);
+ Set<Bundle> expected = new HashSet<Bundle>(Arrays.asList(framework, bundle1));
assertEquals(expected, actual);
- Bundle bundle2 = addBundle("/bundles/simple/", "simple-bundle2");
+ VirtualFile assembly2 = assembleBundle("simple-bundle2", "/bundles/simple/simple-bundle2", new Class[0]);
+ Bundle bundle2 = context.installBundle(assembly2.toURL().toExternalForm());
BundleContext context2 = null;
try
{
@@ -89,8 +88,7 @@
bundles = context1.getBundles();
actual = new HashSet<Bundle>(Arrays.asList(bundles));
- expected = new HashSet<Bundle>(Arrays.asList(bundle1, bundle2));
- addBaseBundles(expected);
+ expected = new HashSet<Bundle>(Arrays.asList(framework, bundle1, bundle2));
assertEquals(expected, actual);
assertEquals(bundle1, context2.getBundle(bundle1.getBundleId()));
@@ -98,7 +96,7 @@
}
finally
{
- uninstall(bundle2);
+ bundle2.uninstall();
}
assertEquals(bundle1, context1.getBundle(bundle1.getBundleId()));
@@ -106,8 +104,7 @@
bundles = context1.getBundles();
actual = new HashSet<Bundle>(Arrays.asList(bundles));
- expected = new HashSet<Bundle>(Arrays.asList(bundle1));
- addBaseBundles(expected);
+ expected = new HashSet<Bundle>(Arrays.asList(framework, bundle1));
assertEquals(expected, actual);
try
@@ -115,9 +112,9 @@
context2.getBundle();
fail("Should not be here!");
}
- catch (Throwable t)
+ catch (IllegalStateException t)
{
- checkThrowable(IllegalStateException.class, t);
+ // expected
}
try
@@ -125,9 +122,9 @@
context2.getBundle(bundle1.getBundleId());
fail("Should not be here!");
}
- catch (Throwable t)
+ catch (IllegalStateException t)
{
- checkThrowable(IllegalStateException.class, t);
+ // expected
}
try
@@ -135,14 +132,14 @@
context2.getBundles();
fail("Should not be here!");
}
- catch (Throwable t)
+ catch (IllegalStateException t)
{
- checkThrowable(IllegalStateException.class, t);
+ // expected
}
}
finally
{
- uninstall(bundle1);
+ bundle1.uninstall();
}
try
@@ -150,9 +147,9 @@
context1.getBundle();
fail("Should not be here!");
}
- catch (Throwable t)
+ catch (IllegalStateException t)
{
- checkThrowable(IllegalStateException.class, t);
+ // expected
}
try
@@ -160,9 +157,9 @@
context1.getBundle(bundle1.getBundleId());
fail("Should not be here!");
}
- catch (Throwable t)
+ catch (IllegalStateException t)
{
- checkThrowable(IllegalStateException.class, t);
+ // expected
}
try
@@ -170,15 +167,17 @@
context1.getBundles();
fail("Should not be here!");
}
- catch (Throwable t)
+ catch (IllegalStateException t)
{
- checkThrowable(IllegalStateException.class, t);
+ // expected
}
}
-
+
+ @Test
public void testProperties() throws Exception
{
- Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ VirtualFile assembly = assembleBundle("simple-bundle1", "/bundles/simple/simple-bundle1", new Class[0]);
+ Bundle bundle = context.installBundle(assembly.toURL().toExternalForm());
try
{
bundle.start();
@@ -201,24 +200,22 @@
bundleContext.getProperty(getClass().getName());
fail("Should not be here!");
}
- catch (Throwable t)
+ catch (IllegalStateException t)
{
- checkThrowable(IllegalStateException.class, t);
+ // expected
}
}
finally
{
- uninstall(bundle);
+ bundle.uninstall();
}
}
+ @Test
public void testInstallBundle() throws Exception
{
- OSGiTestHelper helper = new OSGiTestHelper();
-
- // Test URL location
- URL url = helper.getTestArchiveURL("bundles/jboss-osgi-common.jar");
- Bundle bundle = installBundle(url.toExternalForm());
+ URL url = getTestArchiveURL("bundles/jboss-osgi-common.jar");
+ Bundle bundle = context.installBundle(url.toExternalForm());
try
{
assertBundleState(Bundle.INSTALLED, bundle.getState());
@@ -231,8 +228,8 @@
}
// Test file location
- String location = helper.getTestArchivePath("bundles/jboss-osgi-common.jar");
- bundle = installBundle(location);
+ String location = getTestArchivePath("bundles/jboss-osgi-common.jar");
+ bundle = context.installBundle(location);
try
{
assertBundleState(Bundle.INSTALLED, bundle.getState());
@@ -245,7 +242,7 @@
}
// Test symbolic location
- bundle = installBundle("/symbolic/location", url.openStream());
+ bundle = context.installBundle("/symbolic/location", url.openStream());
try
{
assertBundleState(Bundle.INSTALLED, bundle.getState());
@@ -258,9 +255,11 @@
}
}
+ @Test
public void testServiceListener() throws Exception
{
- Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ VirtualFile assembly = assembleBundle("simple-bundle1", "/bundles/simple/simple-bundle1", new Class[0]);
+ Bundle bundle = context.installBundle(assembly.toURL().toExternalForm());
try
{
bundle.start();
@@ -272,9 +271,9 @@
bundleContext.addServiceListener(null);
fail("Should not be here!");
}
- catch (Throwable t)
+ catch (IllegalArgumentException t)
{
- checkThrowable(IllegalArgumentException.class, t);
+ // expected
}
try
@@ -282,9 +281,9 @@
bundleContext.addServiceListener(null, "(a=b)");
fail("Should not be here!");
}
- catch (Throwable t)
+ catch (IllegalArgumentException t)
{
- checkThrowable(IllegalArgumentException.class, t);
+ // expected
}
try
@@ -292,9 +291,9 @@
bundleContext.removeServiceListener(null);
fail("Should not be here!");
}
- catch (Throwable t)
+ catch (IllegalArgumentException t)
{
- checkThrowable(IllegalArgumentException.class, t);
+ // expected
}
bundleContext.addServiceListener(this);
@@ -345,74 +344,15 @@
}
finally
{
- uninstall(bundle);
+ bundle.uninstall();
}
}
- protected BundleContext assertServiceLifecycle(Bundle bundle, boolean events) throws Exception
- {
- return assertServiceLifecycle(bundle, null, events);
- }
-
- protected BundleContext assertServiceLifecycle(Bundle bundle, Dictionary<String, Object> properties, boolean events) throws Exception
- {
- assertNoServiceEvent();
-
- BundleContext bundleContext = bundle.getBundleContext();
- ServiceRegistration registration = bundleContext.registerService(BundleContext.class.getName(), bundleContext, properties);
- ServiceReference reference = registration.getReference();
-
- if (events)
- assertServiceEvent(ServiceEvent.REGISTERED, reference);
- else
- assertNoServiceEvent();
-
- registration.setProperties(properties);
- if (events)
- assertServiceEvent(ServiceEvent.MODIFIED, reference);
- else
- assertNoServiceEvent();
-
- registration.unregister();
- if (events)
- assertServiceEvent(ServiceEvent.UNREGISTERING, reference);
- else
- assertNoServiceEvent();
-
- registration = bundleContext.registerService(BundleContext.class.getName(), bundleContext, properties);
- reference = registration.getReference();
- if (events)
- assertServiceEvent(ServiceEvent.REGISTERED, reference);
- else
- assertNoServiceEvent();
-
- bundle.stop();
- if (events)
- assertServiceEvent(ServiceEvent.UNREGISTERING, reference);
- else
- assertNoServiceEvent();
-
- try
- {
- bundleContext.addServiceListener(this);
- fail("Should not be here!");
- }
- catch (Throwable t)
- {
- checkThrowable(IllegalStateException.class, t);
- }
-
- bundle.start();
- bundleContext = bundle.getBundleContext();
- assertNotNull(bundleContext);
-
- return bundleContext;
- }
-
+ @Test
public void testBundleListener() throws Exception
{
- // todo how to test INSTALLED/RESOLVED?
- Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ VirtualFile assembly = assembleBundle("simple-bundle1", "/bundles/simple/simple-bundle1", new Class[0]);
+ Bundle bundle = context.installBundle(assembly.toURL().toExternalForm());
try
{
bundle.start();
@@ -424,9 +364,9 @@
bundleContext.addBundleListener(null);
fail("Should not be here!");
}
- catch (Throwable t)
+ catch (IllegalArgumentException t)
{
- checkThrowable(IllegalArgumentException.class, t);
+ // expected
}
try
@@ -434,9 +374,9 @@
bundleContext.removeBundleListener(null);
fail("Should not be here!");
}
- catch (Throwable t)
+ catch (IllegalArgumentException t)
{
- checkThrowable(IllegalArgumentException.class, t);
+ // expected
}
bundleContext.addBundleListener(this);
@@ -458,7 +398,7 @@
}
finally
{
- uninstall(bundle);
+ bundle.uninstall();
}
assertBundleEvent(BundleEvent.STOPPING, bundle);
assertBundleEvent(BundleEvent.STOPPED, bundle);
@@ -466,38 +406,11 @@
assertBundleEvent(BundleEvent.UNINSTALLED, bundle);
}
- protected BundleContext assertBundleLifecycle(Bundle bundle, boolean events) throws Exception
- {
- assertNoBundleEvent();
-
- bundle.stop();
- if (events)
- {
- assertBundleEvent(BundleEvent.STOPPING, bundle);
- assertBundleEvent(BundleEvent.STOPPED, bundle);
- }
- else
- {
- assertNoBundleEvent();
- }
-
- bundle.start();
- if (events)
- {
- assertBundleEvent(BundleEvent.STARTING, bundle);
- assertBundleEvent(BundleEvent.STARTED, bundle);
- }
- else
- {
- assertNoBundleEvent();
- }
-
- return bundle.getBundleContext();
- }
-
+ @Test
public void testFrameworkListener() throws Exception
{
- Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ VirtualFile assembly = assembleBundle("simple-bundle1", "/bundles/simple/simple-bundle1", new Class[0]);
+ Bundle bundle = context.installBundle(assembly.toURL().toExternalForm());
try
{
bundle.start();
@@ -509,9 +422,9 @@
bundleContext.addFrameworkListener(null);
fail("Should not be here!");
}
- catch (Throwable t)
+ catch (IllegalArgumentException t)
{
- checkThrowable(IllegalArgumentException.class, t);
+ // expected
}
try
@@ -519,22 +432,24 @@
bundleContext.removeFrameworkListener(null);
fail("Should not be here!");
}
- catch (Throwable t)
+ catch (IllegalArgumentException t)
{
- checkThrowable(IllegalArgumentException.class, t);
+ // expected
}
// todo test events
}
finally
{
- uninstall(bundle);
+ bundle.uninstall();
}
}
+ @Test
public void testGetDataFile() throws Exception
{
- Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ VirtualFile assembly = assembleBundle("simple-bundle1", "/bundles/simple/simple-bundle1", new Class[0]);
+ Bundle bundle = context.installBundle(assembly.toURL().toExternalForm());
try
{
bundle.start();
@@ -547,13 +462,15 @@
}
finally
{
- uninstall(bundle);
+ bundle.uninstall();
}
}
+ @Test
public void testStopedBundleContext() throws Exception
{
- Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ VirtualFile assembly = assembleBundle("simple-bundle1", "/bundles/simple/simple-bundle1", new Class[0]);
+ Bundle bundle = context.installBundle(assembly.toURL().toExternalForm());
try
{
bundle.start();
@@ -567,9 +484,9 @@
bundleContext.getProperty(getClass().getName());
fail("Should not be here!");
}
- catch (Throwable t)
+ catch (IllegalStateException t)
{
- checkThrowable(IllegalStateException.class, t);
+ // expected
}
// The context should not become reusable after we restart the bundle
@@ -579,21 +496,110 @@
bundleContext.getProperty(getClass().getName());
fail("Should not be here!");
}
- catch (Throwable t)
+ catch (IllegalStateException t)
{
- checkThrowable(IllegalStateException.class, t);
+ // expected
}
}
finally
{
- uninstall(bundle);
+ bundle.uninstall();
}
}
- protected void assertSystemProperty(BundleContext bundleContext, String property, String osgiProperty)
+ private BundleContext assertBundleLifecycle(Bundle bundle, boolean events) throws Exception
{
+ assertNoBundleEvent();
+
+ bundle.stop();
+ if (events)
+ {
+ assertBundleEvent(BundleEvent.STOPPING, bundle);
+ assertBundleEvent(BundleEvent.STOPPED, bundle);
+ }
+ else
+ {
+ assertNoBundleEvent();
+ }
+
+ bundle.start();
+ if (events)
+ {
+ assertBundleEvent(BundleEvent.STARTING, bundle);
+ assertBundleEvent(BundleEvent.STARTED, bundle);
+ }
+ else
+ {
+ assertNoBundleEvent();
+ }
+
+ return bundle.getBundleContext();
+ }
+
+ private void assertSystemProperty(BundleContext bundleContext, String property, String osgiProperty)
+ {
String expected = System.getProperty(property);
assertNotNull(expected);
assertEquals(expected, bundleContext.getProperty(osgiProperty));
}
+
+ private BundleContext assertServiceLifecycle(Bundle bundle, boolean events) throws Exception
+ {
+ return assertServiceLifecycle(bundle, null, events);
+ }
+
+ private BundleContext assertServiceLifecycle(Bundle bundle, Dictionary<String, Object> properties, boolean events) throws Exception
+ {
+ assertNoServiceEvent();
+
+ BundleContext bundleContext = bundle.getBundleContext();
+ ServiceRegistration registration = bundleContext.registerService(BundleContext.class.getName(), bundleContext, properties);
+ ServiceReference reference = registration.getReference();
+
+ if (events)
+ assertServiceEvent(ServiceEvent.REGISTERED, reference);
+ else
+ assertNoServiceEvent();
+
+ registration.setProperties(properties);
+ if (events)
+ assertServiceEvent(ServiceEvent.MODIFIED, reference);
+ else
+ assertNoServiceEvent();
+
+ registration.unregister();
+ if (events)
+ assertServiceEvent(ServiceEvent.UNREGISTERING, reference);
+ else
+ assertNoServiceEvent();
+
+ registration = bundleContext.registerService(BundleContext.class.getName(), bundleContext, properties);
+ reference = registration.getReference();
+ if (events)
+ assertServiceEvent(ServiceEvent.REGISTERED, reference);
+ else
+ assertNoServiceEvent();
+
+ bundle.stop();
+ if (events)
+ assertServiceEvent(ServiceEvent.UNREGISTERING, reference);
+ else
+ assertNoServiceEvent();
+
+ try
+ {
+ bundleContext.addServiceListener(this);
+ fail("Should not be here!");
+ }
+ catch (IllegalStateException t)
+ {
+ // expected
+ }
+
+ bundle.start();
+ bundleContext = bundle.getBundleContext();
+ assertNotNull(bundleContext);
+
+ return bundleContext;
+ }
}
Modified: projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/bundle/BundleEntriesUnitTestCase.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/bundle/BundleEntriesUnitTestCase.java 2010-03-10 10:27:55 UTC (rev 102217)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/bundle/BundleEntriesUnitTestCase.java 2010-03-10 10:29:13 UTC (rev 102218)
@@ -21,6 +21,10 @@
*/
package org.jboss.test.osgi.bundle;
+// $Id: $
+
+import static org.junit.Assert.*;
+
import java.net.URL;
import java.util.Arrays;
import java.util.Collections;
@@ -28,9 +32,9 @@
import java.util.HashSet;
import java.util.Set;
-import junit.framework.Test;
-
-import org.jboss.test.osgi.FrameworkTest;
+import org.jboss.osgi.vfs.VirtualFile;
+import org.jboss.test.osgi.NativeFrameworkTest;
+import org.junit.Test;
import org.osgi.framework.Bundle;
/**
@@ -39,65 +43,62 @@
* TODO test security
* TODO test fragments
* @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @author Thomas.Diesler at jboss.com
* @version $Revision: 1.1 $
*/
-public class BundleEntriesUnitTestCase extends FrameworkTest
+public class BundleEntriesUnitTestCase extends NativeFrameworkTest
{
- public static Test suite()
- {
- return suite(BundleEntriesUnitTestCase.class);
- }
-
- public BundleEntriesUnitTestCase(String name)
- {
- super(name);
- }
-
+ @Test
public void testEntriesNotInstalled() throws Exception
{
- Bundle bundle = addBundle("/bundles/entries/", "entries-simple");
- uninstall(bundle);
+ VirtualFile assembly = assembleBundle("entries-simple", "/bundles/entries/entries-simple", new Class[0]);
+ Bundle bundle = context.installBundle(assembly.toURL().toExternalForm());
+ bundle.uninstall();
try
{
bundle.getEntry("root.xml");
fail("Should not be here!");
}
- catch (Throwable t)
+ catch (IllegalStateException t)
{
- checkThrowable(IllegalStateException.class, t);
+ // expected
}
try
{
bundle.findEntries("", "root.xml", false);
fail("Should not be here!");
}
- catch (Throwable t)
+ catch (IllegalStateException t)
{
- checkThrowable(IllegalStateException.class, t);
+ // expected
}
}
+ @Test
public void testFindEntriesNoPath() throws Exception
{
- Bundle bundle = addBundle("/bundles/entries/", "entries-simple");
+ VirtualFile assembly = assembleBundle("entries-simple", "/bundles/entries/entries-simple", new Class[0]);
+ Bundle bundle = context.installBundle(assembly.toURL().toExternalForm());
try
{
bundle.findEntries(null, "root.xml", false);
fail("Should not be here!");
}
- catch (Throwable t)
+ catch (IllegalArgumentException t)
{
- checkThrowable(IllegalArgumentException.class, t);
+ // expected
}
finally
{
- uninstall(bundle);
+ bundle.uninstall();
}
}
+ @Test
public void testEntries() throws Exception
{
- Bundle bundle = addBundle("/bundles/entries/", "entries-simple");
+ VirtualFile assembly = assembleBundle("entries-simple", "/bundles/entries/entries-simple", new Class[0]);
+ Bundle bundle = context.installBundle(assembly.toURL().toExternalForm());
try
{
assertEntry(bundle, "");
@@ -367,24 +368,14 @@
}
finally
{
- uninstall(bundle);
+ bundle.uninstall();
}
}
- protected void assertEntry(Bundle bundle, String path) throws Exception
+ private void assertEntry(Bundle bundle, String path) throws Exception
{
- URL expected = getBundleResource(bundle, path);
- if (expected == null)
- fail("Expected resource not found: " + path);
-
- assertEntry(bundle, path, expected);
- assertEntry(bundle, "/" + path, expected);
- }
-
- protected void assertEntry(Bundle bundle, String path, URL expected) throws Exception
- {
URL actual = bundle.getEntry(path);
- assertEquals(expected, actual);
+ assertNotNull("Entry expected for: " + path, actual);
}
protected void assertNoEntry(Bundle bundle, String path) throws Exception
@@ -393,30 +384,19 @@
assertNull("Did not expect entry: " + actual + " for path: " + path, actual);
}
+ @SuppressWarnings("unchecked")
protected void assertEntries(Bundle bundle, String path, String filePattern, boolean recurse, String... entries) throws Exception
{
- Set<URL> expected = new HashSet<URL>();
- for (String entry : entries)
- {
- Enumeration<URL> urls = getBundleResources(bundle, entry);
- if (urls == null || urls.hasMoreElements() == false)
- fail("Expected resource not found: " + entry);
- while (urls.hasMoreElements())
- expected.add(urls.nextElement());
- }
-
- assertEntries(bundle, path, filePattern, recurse, expected);
- assertEntries(bundle, "/" + path, filePattern, recurse, expected);
- }
-
- @SuppressWarnings("unchecked")
- protected void assertEntries(Bundle bundle, String path, String filePattern, boolean recurse, Set<URL> expected) throws Exception
- {
Set<URL> actual = new HashSet<URL>();
Enumeration<URL> enumeration = bundle.findEntries(path, filePattern, recurse);
while (enumeration != null && enumeration.hasMoreElements())
actual.add(enumeration.nextElement());
+ URL baseurl = bundle.getEntry("/");
+ Set<URL> expected = new HashSet<URL>();
+ for (String entry : entries)
+ expected.add(new URL(baseurl + entry));
+
assertEquals(expected, actual);
}
Modified: projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/bundle/BundleLifecycleTestCase.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/bundle/BundleLifecycleTestCase.java 2010-03-10 10:27:55 UTC (rev 102217)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/bundle/BundleLifecycleTestCase.java 2010-03-10 10:29:13 UTC (rev 102218)
@@ -21,13 +21,17 @@
*/
package org.jboss.test.osgi.bundle;
-import junit.framework.Test;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.fail;
-import org.jboss.test.osgi.FrameworkTest;
+import org.jboss.osgi.vfs.VirtualFile;
+import org.jboss.test.osgi.NativeFrameworkTest;
import org.jboss.test.osgi.bundle.support.a.FailOnStartActivator;
import org.jboss.test.osgi.bundle.support.b.LifecycleService;
+import org.junit.Test;
import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
import org.osgi.framework.ServiceReference;
import org.osgi.service.packageadmin.PackageAdmin;
@@ -38,24 +42,17 @@
* @author thomas.Diesler at jboss.com
* @since 15-Dec-2009
*/
-public class BundleLifecycleTestCase extends FrameworkTest
+public class BundleLifecycleTestCase extends NativeFrameworkTest
{
- public static Test suite()
- {
- return suite(BundleLifecycleTestCase.class);
- }
- public BundleLifecycleTestCase(String name)
- {
- super(name);
- }
-
/**
* Verifies that the service bundle can get started
*/
+ @Test
public void testSimpleStart() throws Exception
{
- Bundle bundleA = installBundle(assembleBundle("lifecycle-service", "/bundles/lifecycle/simple-service", LifecycleService.class));
+ VirtualFile assemblyA = assembleBundle("lifecycle-service", "/bundles/lifecycle/simple-service", LifecycleService.class);
+ Bundle bundleA = context.installBundle(assemblyA.toURL().toExternalForm());
try
{
assertBundleState(Bundle.INSTALLED, bundleA.getState());
@@ -76,18 +73,21 @@
/**
* Verifies that the bundle state is RESOLVED after a failure in BundleActivator.start()
*/
+ @Test
public void testDependencyNotAvailable() throws Exception
{
- Bundle bundleA = installBundle(assembleBundle("lifecycle-service", "/bundles/lifecycle/simple-service", LifecycleService.class));
+ VirtualFile assemblyA = assembleBundle("lifecycle-service", "/bundles/lifecycle/simple-service", LifecycleService.class);
+ Bundle bundleA = context.installBundle(assemblyA.toURL().toExternalForm());
try
{
assertBundleState(Bundle.INSTALLED, bundleA.getState());
// BundleA not started - service not available
- ServiceReference sref = getSystemBundle().getBundleContext().getServiceReference(LifecycleService.class.getName());
+ ServiceReference sref = context.getServiceReference(LifecycleService.class.getName());
assertNull("Service not available", sref);
- Bundle bundleB = installBundle(assembleBundle("lifecycle-failstart", "/bundles/lifecycle/fail-on-start", FailOnStartActivator.class));
+ VirtualFile assemblyB = assembleBundle("lifecycle-failstart", "/bundles/lifecycle/fail-on-start", FailOnStartActivator.class);
+ Bundle bundleB = context.installBundle(assemblyB.toURL().toExternalForm());
try
{
assertBundleState(Bundle.INSTALLED, bundleB.getState());
@@ -115,15 +115,18 @@
/**
* Verifies that BundleB can get started when the service is available
*/
+ @Test
public void testDependencyAvailable() throws Exception
{
- Bundle bundleA = installBundle(assembleBundle("lifecycle-service", "/bundles/lifecycle/simple-service", LifecycleService.class));
+ VirtualFile assemblyA = assembleBundle("lifecycle-service", "/bundles/lifecycle/simple-service", LifecycleService.class);
+ Bundle bundleA = context.installBundle(assemblyA.toURL().toExternalForm());
try
{
bundleA.start();
assertBundleState(Bundle.ACTIVE, bundleA.getState());
- Bundle bundleB = installBundle(assembleBundle("lifecycle-failstart", "/bundles/lifecycle/fail-on-start", FailOnStartActivator.class));
+ VirtualFile assemblyB = assembleBundle("lifecycle-failstart", "/bundles/lifecycle/fail-on-start", FailOnStartActivator.class);
+ Bundle bundleB = context.installBundle(assemblyB.toURL().toExternalForm());
try
{
bundleB.start();
@@ -145,14 +148,17 @@
/**
* Verifies that BundleB can get started when the service is made available
*/
+ @Test
public void testStartRetry() throws Exception
{
- Bundle bundleA = installBundle(assembleBundle("lifecycle-service", "/bundles/lifecycle/simple-service", LifecycleService.class));
+ VirtualFile assemblyA = assembleBundle("lifecycle-service", "/bundles/lifecycle/simple-service", LifecycleService.class);
+ Bundle bundleA = context.installBundle(assemblyA.toURL().toExternalForm());
try
{
assertBundleState(Bundle.INSTALLED, bundleA.getState());
- Bundle bundleB = installBundle(assembleBundle("lifecycle-failstart", "/bundles/lifecycle/fail-on-start", FailOnStartActivator.class));
+ VirtualFile assemblyB = assembleBundle("lifecycle-failstart", "/bundles/lifecycle/fail-on-start", FailOnStartActivator.class);
+ Bundle bundleB = context.installBundle(assemblyB.toURL().toExternalForm());
try
{
assertBundleState(Bundle.INSTALLED, bundleB.getState());
@@ -191,17 +197,18 @@
/**
* Verifies that BundleB is still INSTALLED after a failure in PackageAdmin.resolve()
*/
+ @Test
public void testFailToResolve() throws Exception
{
- Bundle bundleB = installBundle(assembleBundle("lifecycle-failstart", "/bundles/lifecycle/fail-on-start", FailOnStartActivator.class));
+ VirtualFile assemblyA = assembleBundle("lifecycle-failstart", "/bundles/lifecycle/fail-on-start", FailOnStartActivator.class);
+ Bundle bundleB = context.installBundle(assemblyA.toURL().toExternalForm());
try
{
assertBundleState(Bundle.INSTALLED, bundleB.getState());
// Get the PackageAdmin service
- BundleContext sysContext = getSystemBundle().getBundleContext();
- ServiceReference sref = sysContext.getServiceReference(PackageAdmin.class.getName());
- PackageAdmin packageAdmin = (PackageAdmin)sysContext.getService(sref);
+ ServiceReference sref = context.getServiceReference(PackageAdmin.class.getName());
+ PackageAdmin packageAdmin = (PackageAdmin)context.getService(sref);
// Attempt to explicitly resolve a bundle with missing dependency
boolean allResolved = packageAdmin.resolveBundles(new Bundle[] { bundleB });
@@ -220,11 +227,13 @@
/**
* Verifies that we get a BundleException when an invalid bundle is installed
*/
+ @Test
public void testInstallInvalid() throws Exception
{
try
{
- installBundle(assembleBundle("missing-symbolic-name", "/bundles/lifecycle/invalid01"));
+ VirtualFile assembly = assembleBundle("missing-symbolic-name", "/bundles/lifecycle/invalid01");
+ context.installBundle(assembly.toURL().toExternalForm());
fail("BundleException expected");
}
catch (BundleException ex)
@@ -234,7 +243,8 @@
try
{
- installBundle(assembleBundle("invalid-export", "/bundles/lifecycle/invalid02"));
+ VirtualFile assembly = assembleBundle("invalid-export", "/bundles/lifecycle/invalid02");
+ context.installBundle(assembly.toURL().toExternalForm());
fail("BundleException expected");
}
catch (BundleException ex)
Modified: projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/bundle/BundleUnitTestCase.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/bundle/BundleUnitTestCase.java 2010-03-10 10:27:55 UTC (rev 102217)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/bundle/BundleUnitTestCase.java 2010-03-10 10:29:13 UTC (rev 102218)
@@ -21,6 +21,12 @@
*/
package org.jboss.test.osgi.bundle;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.util.Dictionary;
@@ -29,11 +35,10 @@
import java.util.jar.JarOutputStream;
import java.util.jar.Manifest;
-import junit.framework.Test;
-
-import org.jboss.test.osgi.FrameworkTest;
-import org.jboss.virtual.VFSUtils;
-import org.jboss.virtual.VirtualFile;
+import org.jboss.osgi.vfs.VFSUtils;
+import org.jboss.osgi.vfs.VirtualFile;
+import org.jboss.test.osgi.NativeFrameworkTest;
+import org.junit.Test;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
@@ -47,63 +52,59 @@
* @author Thomas.Diesler at jboss.com
* @version $Revision: 1.1 $
*/
-public class BundleUnitTestCase extends FrameworkTest
+public class BundleUnitTestCase extends NativeFrameworkTest
{
- public static Test suite()
- {
- return suite(BundleUnitTestCase.class);
- }
-
- public BundleUnitTestCase(String name)
- {
- super(name);
- }
-
+ @Test
public void testBundleId() throws Exception
{
long id1 = -1;
- Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ VirtualFile assembly = assembleBundle("simple-bundle1", "/bundles/simple/simple-bundle1", new Class[0]);
+ Bundle bundle = context.installBundle(assembly.toURL().toExternalForm());
try
{
id1 = bundle.getBundleId();
}
finally
{
- uninstall(bundle);
+ bundle.uninstall();
}
assertEquals(id1, bundle.getBundleId());
long id2 = -1;
- bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ bundle = context.installBundle(assembly.toURL().toExternalForm());
try
{
id2 = bundle.getBundleId();
}
finally
{
- uninstall(bundle);
+ bundle.uninstall();
}
assertEquals(id2, bundle.getBundleId());
assertTrue("Ids should be different" + id1 + "," + id2, id1 != id2);
}
+ @Test
public void testSymbolicName() throws Exception
{
- Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ VirtualFile assembly = assembleBundle("simple-bundle1", "/bundles/simple/simple-bundle1", new Class[0]);
+ Bundle bundle = context.installBundle(assembly.toURL().toExternalForm());
try
{
assertEquals("org.jboss.test.osgi.simple1", bundle.getSymbolicName());
}
finally
{
- uninstall(bundle);
+ bundle.uninstall();
}
assertEquals("org.jboss.test.osgi.simple1", bundle.getSymbolicName());
}
+ @Test
public void testState() throws Exception
{
- Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ VirtualFile assembly = assembleBundle("simple-bundle1", "/bundles/simple/simple-bundle1", new Class[0]);
+ Bundle bundle = context.installBundle(assembly.toURL().toExternalForm());
try
{
assertEquals(Bundle.INSTALLED, bundle.getState());
@@ -116,14 +117,16 @@
}
finally
{
- uninstall(bundle);
+ bundle.uninstall();
}
assertEquals(Bundle.UNINSTALLED, bundle.getState());
}
+ @Test
public void testGetBundleContext() throws Exception
{
- Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ VirtualFile assembly = assembleBundle("simple-bundle1", "/bundles/simple/simple-bundle1", new Class[0]);
+ Bundle bundle = context.installBundle(assembly.toURL().toExternalForm());
try
{
BundleContext bundleContext = bundle.getBundleContext();
@@ -139,20 +142,23 @@
}
finally
{
- uninstall(bundle);
+ bundle.uninstall();
}
}
+ @Test
public void testLastModified() throws Exception
{
// TODO testLastModified
}
+ @Test
public void testStartStop() throws Exception
{
// TODO testStartStop
}
+ @Test
public void testUpdate() throws Exception
{
VirtualFile assemble1 = assembleBundle("bundle1", "/bundles/update/update-bundle1");
@@ -163,13 +169,10 @@
new JarOutputStream(baos, manifest).close();
ByteArrayInputStream updateStream = new ByteArrayInputStream(baos.toByteArray());
- // [JBVFS-130] VFSUtils.temp(assembledDirectory) cannot create tmp dir
- // assemble2 = VFSUtils.temp(assemble2);
-
- Bundle bundle = installBundle(assemble1);
+ Bundle bundle = context.installBundle(assemble1.toURL().toExternalForm());
try
{
- int beforeCount = getBundleManager().getBundles().size();
+ int beforeCount = context.getBundles().length;
bundle.start();
assertBundleState(Bundle.ACTIVE, bundle.getState());
@@ -179,7 +182,7 @@
assertBundleState(Bundle.ACTIVE, bundle.getState());
assertEquals("Bundle-Version", "1.0.1", bundle.getHeaders().get(Constants.BUNDLE_VERSION));
- int afterCount = getBundleManager().getBundles().size();
+ int afterCount = context.getBundles().length;
assertEquals("Bundle count", beforeCount, afterCount);
}
finally
@@ -188,56 +191,64 @@
}
}
+ @Test
public void testUninstall() throws Exception
{
// TODO testUninstall
}
+ @Test
public void testSingleton() throws Exception
{
- Bundle bundle1 = installBundle(assembleBundle("bundle10", "/bundles/singleton/singleton1"));
+ VirtualFile assemblyA = assembleBundle("bundle10", "/bundles/singleton/singleton1");
+ Bundle bundleA = context.installBundle(assemblyA.toURL().toExternalForm());
try
{
- Bundle bundle2 = installBundle(assembleBundle("bundle20", "/bundles/singleton/singleton2"));
- uninstall(bundle2);
+ VirtualFile assemblyB = assembleBundle("bundle20", "/bundles/singleton/singleton2");
+ Bundle bundleB = context.installBundle(assemblyB.toURL().toExternalForm());
+ bundleB.uninstall();
fail("Should not be here!");
}
- catch (Throwable t)
+ catch (BundleException t)
{
- checkThrowable(BundleException.class, t);
+ // expected
}
finally
{
- uninstall(bundle1);
+ bundleA.uninstall();
}
}
+ @Test
public void testNotSingleton() throws Exception
{
- Bundle bundle1 = installBundle(assembleBundle("bundle1", "/bundles/singleton/singleton1"));
+ VirtualFile assemblyA = assembleBundle("bundle1", "/bundles/singleton/singleton1");
+ Bundle bundleA = context.installBundle(assemblyA.toURL().toExternalForm());
try
{
- Bundle bundle2 = installBundle(assembleBundle("not-singleton", "/bundles/singleton/not-singleton"));
+ VirtualFile assemblyB = assembleBundle("not-singleton", "/bundles/singleton/not-singleton");
+ Bundle bundleB = context.installBundle(assemblyB.toURL().toExternalForm());
try
{
- assertEquals(bundle1.getSymbolicName(), bundle2.getSymbolicName());
+ assertEquals(bundleA.getSymbolicName(), bundleB.getSymbolicName());
}
finally
{
- uninstall(bundle2);
+ bundleB.uninstall();
}
}
finally
{
- uninstall(bundle1);
+ bundleA.uninstall();
}
}
+ @Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void testGetHeaders() throws Exception
{
- // TODO case insensistive
- Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ VirtualFile assembly = assembleBundle("simple-bundle1", "/bundles/simple/simple-bundle1", new Class[0]);
+ Bundle bundle = context.installBundle(assembly.toURL().toExternalForm());
try
{
Dictionary expected = new Hashtable();
@@ -254,35 +265,41 @@
}
finally
{
- uninstall(bundle);
+ bundle.uninstall();
}
}
+ @Test
public void testLocation() throws Exception
{
// TODO testGetLocation
}
+ @Test
public void testGetRegisteredServices() throws Exception
{
// TODO testGetRegisteredServices
}
+ @Test
public void testServicesInUse() throws Exception
{
// TODO testServicesInUse
}
+ @Test
public void testHasPermission() throws Exception
{
// TODO testHasPermission
}
+ @Test
public void testGetResources() throws Exception
{
// TODO testGetResource(s)
}
+ @Test
public void testLoadClass() throws Exception
{
// TODO testLoadClass
Modified: projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/bundle/SystemBundleUnitTestCase.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/bundle/SystemBundleUnitTestCase.java 2010-03-10 10:27:55 UTC (rev 102217)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/bundle/SystemBundleUnitTestCase.java 2010-03-10 10:29:13 UTC (rev 102218)
@@ -21,12 +21,15 @@
*/
package org.jboss.test.osgi.bundle;
+// $Id: $
+
+import static org.junit.Assert.*;
+
import java.util.Dictionary;
import java.util.Hashtable;
-import junit.framework.Test;
-
-import org.jboss.test.osgi.FrameworkTest;
+import org.jboss.test.osgi.NativeFrameworkTest;
+import org.junit.Test;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleException;
import org.osgi.framework.Constants;
@@ -36,58 +39,56 @@
*
* TODO test security
* @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @author thomas.Diesler at jboss.com
* @version $Revision: 1.1 $
*/
-public class SystemBundleUnitTestCase extends FrameworkTest
+public class SystemBundleUnitTestCase extends NativeFrameworkTest
{
- public SystemBundleUnitTestCase(String name)
- {
- super(name);
- }
-
- public static Test suite()
- {
- return suite(SystemBundleUnitTestCase.class);
- }
-
+ @Test
public void testBundleId() throws Exception
{
- assertEquals(0, getSystemBundle().getBundleId());
+ assertEquals(0, framework.getBundleId());
}
+ @Test
public void testSymbolicName() throws Exception
{
- assertEquals(Constants.SYSTEM_BUNDLE_SYMBOLICNAME, getSystemBundle().getSymbolicName());
+ assertEquals(Constants.SYSTEM_BUNDLE_SYMBOLICNAME, framework.getSymbolicName());
}
+ @Test
public void testState() throws Exception
{
- assertEquals(Bundle.ACTIVE, getSystemBundle().getState());
+ assertEquals(Bundle.ACTIVE, framework.getState());
}
+ @Test
public void testStartStop() throws Exception
{
System.out.println("FIXME [JBOSGI-138] Proper system BundleContext implementation");
}
+ @Test
public void testUpdate() throws Exception
{
System.out.println("FIXME [JBOSGI-138] Proper system BundleContext implementation");
}
+ @Test
public void testUninstall() throws Exception
{
try
{
- getSystemBundle().uninstall();
+ framework.uninstall();
fail("Should not be here!");
}
- catch (Throwable t)
+ catch (BundleException t)
{
- checkThrowable(BundleException.class, t);
+ // expected
}
}
+ @Test
@SuppressWarnings({ "unchecked", "rawtypes" })
public void testGetHeaders() throws Exception
{
@@ -97,40 +98,47 @@
// todo expected.put(Attributes.Name.IMPLEMENTATION_VENDOR.toString(), "jboss.org");
// todo expected.put(Attributes.Name.IMPLEMENTATION_VERSION.toString(), "r4v41");
- Dictionary dictionary = getSystemBundle().getHeaders();
+ Dictionary dictionary = framework.getHeaders();
assertEquals(expected, dictionary);
}
+ @Test
public void testLocation() throws Exception
{
- assertEquals(Constants.SYSTEM_BUNDLE_LOCATION, getSystemBundle().getLocation());
+ assertEquals(Constants.SYSTEM_BUNDLE_LOCATION, framework.getLocation());
}
+ @Test
public void testGetEntry()
{
System.out.println("FIXME [JBOSGI-138] Proper system BundleContext implementation");
}
+ @Test
public void testGetEntryPath()
{
System.out.println("FIXME [JBOSGI-138] Proper system BundleContext implementation");
}
+ @Test
public void testFindEntries()
{
System.out.println("FIXME [JBOSGI-138] Proper system BundleContext implementation");
}
+ @Test
public void testLoadClass()
{
System.out.println("FIXME [JBOSGI-138] Proper system BundleContext implementation");
}
+ @Test
public void testGetResource()
{
System.out.println("FIXME [JBOSGI-138] Proper system BundleContext implementation");
}
+ @Test
public void testGetResources()
{
System.out.println("FIXME [JBOSGI-138] Proper system BundleContext implementation");
Modified: projects/jboss-osgi/projects/runtime/framework/trunk/core/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleWrapper.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/core/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleWrapper.java 2010-03-10 10:27:55 UTC (rev 102217)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/core/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleWrapper.java 2010-03-10 10:29:13 UTC (rev 102218)
@@ -191,12 +191,6 @@
bundleState.stop(options);
}
- @Override
- public String toString()
- {
- return bundleState.toString();
- }
-
public void uninstall() throws BundleException
{
bundleState.uninstall();
@@ -211,4 +205,26 @@
{
bundleState.update(in);
}
+
+ @Override
+ public int hashCode()
+ {
+ return bundleState.hashCode();
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (!(obj instanceof OSGiBundleWrapper))
+ return false;
+
+ OSGiBundleWrapper other = (OSGiBundleWrapper)obj;
+ return bundleState.equals(other.getBundleState());
+ }
+
+ @Override
+ public String toString()
+ {
+ return bundleState.toString();
+ }
}
Modified: projects/jboss-osgi/projects/runtime/framework/trunk/core/src/main/java/org/jboss/osgi/framework/launch/OSGiFramework.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/core/src/main/java/org/jboss/osgi/framework/launch/OSGiFramework.java 2010-03-10 10:27:55 UTC (rev 102217)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/core/src/main/java/org/jboss/osgi/framework/launch/OSGiFramework.java 2010-03-10 10:29:13 UTC (rev 102218)
@@ -41,7 +41,7 @@
* @author thomas.diesler at jboss.com
* @since 21-Aug-2009
*/
-public class OSGiFramework extends OSGiBundleWrapper implements Framework
+public final class OSGiFramework extends OSGiBundleWrapper implements Framework
{
// Provide logging
final Logger log = Logger.getLogger(OSGiFramework.class);
Modified: projects/jboss-osgi/projects/runtime/framework/trunk/core/src/main/java/org/jboss/osgi/framework/plugins/internal/FrameworkEventsPluginImpl.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/core/src/main/java/org/jboss/osgi/framework/plugins/internal/FrameworkEventsPluginImpl.java 2010-03-10 10:27:55 UTC (rev 102217)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/core/src/main/java/org/jboss/osgi/framework/plugins/internal/FrameworkEventsPluginImpl.java 2010-03-10 10:29:13 UTC (rev 102218)
@@ -78,17 +78,20 @@
private ExecutorService executorService;
/** True for synchronous event delivery */
private boolean synchronous;
- /** The set of bundle events taht cause an info log */
- private Set<Integer> infoEvents = new HashSet<Integer>();
+ /** The set of bundle events that are delivered to an (asynchronous) BundleListener */
+ private Set<Integer> asyncBundleEvents = new HashSet<Integer>();
public FrameworkEventsPluginImpl(OSGiBundleManager bundleManager)
{
super(bundleManager);
executorService = Executors.newCachedThreadPool();
- infoEvents.add(new Integer(BundleEvent.INSTALLED));
- infoEvents.add(new Integer(BundleEvent.STARTED));
- infoEvents.add(new Integer(BundleEvent.STOPPED));
- infoEvents.add(new Integer(BundleEvent.UNINSTALLED));
+ asyncBundleEvents.add(new Integer(BundleEvent.INSTALLED));
+ asyncBundleEvents.add(new Integer(BundleEvent.RESOLVED));
+ asyncBundleEvents.add(new Integer(BundleEvent.STARTED));
+ asyncBundleEvents.add(new Integer(BundleEvent.STOPPED));
+ asyncBundleEvents.add(new Integer(BundleEvent.UPDATED));
+ asyncBundleEvents.add(new Integer(BundleEvent.UNRESOLVED));
+ asyncBundleEvents.add(new Integer(BundleEvent.UNINSTALLED));
}
public void setSynchronous(boolean synchronous)
@@ -274,7 +277,7 @@
final BundleEvent event = new OSGiBundleEvent(type, assertBundle(bundle));
final String typeName = ConstantsHelper.bundleEvent(event.getType());
- if (infoEvents.contains(event.getType()))
+ if (asyncBundleEvents.contains(event.getType()))
log.info("Bundle " + typeName + ": " + bundle);
else
log.debug("Bundle " + typeName + ": " + bundle);
@@ -305,8 +308,9 @@
}
}
- // Normal listeners after, if required
- if (type != BundleEvent.STARTING && type != BundleEvent.STOPPING && type != BundleEvent.LAZY_ACTIVATION)
+ // BundleListeners are called with a BundleEvent object when a bundle has been
+ // installed, resolved, started, stopped, updated, unresolved, or uninstalled
+ if (asyncBundleEvents.contains(type))
{
for (BundleListener listener : listeners)
{
More information about the jboss-cvs-commits
mailing list