Author: thomas.diesler(a)jboss.com
Date: 2010-03-21 02:41:41 -0400 (Sun, 21 Mar 2010)
New Revision: 102680
Added:
projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/testing/OSGiFrameworkTest.java
Modified:
projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/AbstractFrameworkTest.java
projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/service/ServiceFactoryTestCase.java
projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/bootstrap/BootstrapTestCase.java
projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/framework/FrameworkTestCase.java
projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi142/OSGi142TestCase.java
projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi143/OSGi143TestCase.java
projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi151/OSGi151TestCase.java
projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/services/ServiceRegistrationTestCase.java
Log:
Add OSGiFrameworkTest to SPI
Modified:
projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/AbstractFrameworkTest.java
===================================================================
---
projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/AbstractFrameworkTest.java 2010-03-21
06:21:27 UTC (rev 102679)
+++
projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/AbstractFrameworkTest.java 2010-03-21
06:41:41 UTC (rev 102680)
@@ -23,40 +23,9 @@
// $Id: $
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-import java.util.concurrent.CopyOnWriteArrayList;
-
-import org.jboss.logging.Logger;
-import org.jboss.osgi.framework.bundle.AbstractBundleState;
import org.jboss.osgi.framework.bundle.OSGiBundleManager;
import org.jboss.osgi.framework.launch.OSGiFramework;
-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.jboss.osgi.vfs.VirtualFile;
-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;
-import org.osgi.service.packageadmin.PackageAdmin;
+import org.jboss.osgi.testing.OSGiFrameworkTest;
/**
* Parent for native framework tests.
@@ -64,353 +33,10 @@
* @author Thomas.Diesler(a)jboss.com
* @since 10-Mar-2010
*/
-public abstract class AbstractFrameworkTest extends OSGiTest implements ServiceListener,
SynchronousBundleListener, FrameworkListener
+public abstract class AbstractFrameworkTest extends OSGiFrameworkTest
{
- // Provide logging
- private static final Logger log = Logger.getLogger(AbstractFrameworkTest.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 PackageAdmin getPackageAdmin()
- {
- ServiceReference sref = context.getServiceReference(PackageAdmin.class.getName());
- return (PackageAdmin)context.getService(sref);
- }
-
protected OSGiBundleManager getBundleManager()
{
return ((OSGiFramework)framework).getBundleManager();
}
-
- protected Bundle installBundle(VirtualFile archive) throws Exception
- {
- String location = archive.toURL().toExternalForm();
- return context.installBundle(location, archive.openStream());
- }
-
- protected void assertLoadClass(Bundle bundle, String className, Bundle exporter)
- {
- Class<?> clazz = assertLoadClass(bundle, className);
- Bundle actual = getPackageAdmin().getBundle(clazz);
- assertEquals(exporter, actual);
- }
-
- @Override
- public void frameworkEvent(FrameworkEvent event)
- {
- synchronized (frameworkEvents)
- {
- log.debug("FrameworkEvent type=" +
ConstantsHelper.frameworkEvent(event.getType()) + " for " + event);
- frameworkEvents.add(event);
- frameworkEvents.notifyAll();
- }
- }
-
- protected void assertNoFrameworkEvent() throws Exception
- {
- log.debug("frameworkEvents=" + frameworkEvents);
- assertEquals(0, frameworkEvents.size());
- }
-
- protected void assertFrameworkEvent(int type, Bundle bundle, Class<? extends
Throwable> expectedThrowable) throws Exception
- {
- waitForEvent(frameworkEvents, type);
- log.debug("frameworkEvents=" + frameworkEvents);
- int size = frameworkEvents.size();
- assertTrue("" + size, size > 0);
- FrameworkEvent event = frameworkEvents.remove(0);
- assertEquals(ConstantsHelper.frameworkEvent(type),
ConstantsHelper.frameworkEvent(event.getType()));
- Throwable t = event.getThrowable();
- if (expectedThrowable == null)
- {
- if (t != null)
- {
- log.error("Unexpected error in Framework event: ", t);
- fail("Unexpected throwable: " + t);
- }
- }
- else
- {
- String message = expectedThrowable.getSimpleName() + " is assignable from
" + t.getClass().getSimpleName();
- assertTrue(message, expectedThrowable.isAssignableFrom(t.getClass()));
- }
- assertEquals(bundle, event.getSource());
- assertEquals(bundle, event.getBundle());
- }
-
- @Override
- public void bundleChanged(BundleEvent event)
- {
- synchronized (bundleEvents)
- {
- log.debug("BundleChanged type=" +
ConstantsHelper.bundleEvent(event.getType()) + " for " + event);
- bundleEvents.add(event);
- bundleEvents.notifyAll();
- }
- }
-
- 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 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());
- }
-
- protected void assertNoAllReferences(BundleContext bundleContext, String clazz) throws
Exception
- {
- assertNoAllReferences(bundleContext, clazz, null);
- }
-
- protected void assertNoAllReferences(BundleContext bundleContext, String clazz, String
filter) throws Exception
- {
- ServiceReference[] actual = bundleContext.getAllServiceReferences(clazz, filter);
- if (actual != null)
- log.debug(bundleContext + " got " + Arrays.asList(actual) + " for
clazz=" + clazz + " filter=" + filter);
- else
- log.debug(bundleContext + " got nothing for clazz=" + clazz + "
filter=" + filter);
- assertNull("Expected no references for clazz=" + clazz + "
filter=" + filter, actual);
- }
-
- protected void assertAllReferences(BundleContext bundleContext, String clazz,
ServiceReference... expected) throws Exception
- {
- assertAllReferences(bundleContext, clazz, null, expected);
- }
-
- protected void assertAllReferences(BundleContext bundleContext, String clazz, String
filter, ServiceReference... expected) throws Exception
- {
- ServiceReference[] actual = bundleContext.getAllServiceReferences(clazz, filter);
- if (actual != null)
- log.debug(bundleContext + " got " + Arrays.asList(actual) + " for
clazz=" + clazz + " filter=" + filter);
- else
- log.debug(bundleContext + " got nothing for clazz=" + clazz + "
filter=" + filter);
- assertArrayEquals(bundleContext + " with clazz=" + clazz + "
filter=" + filter, expected, actual);
- }
-
- protected void assertNoReferences(BundleContext bundleContext, String clazz) throws
Exception
- {
- assertNoReferences(bundleContext, clazz, null);
- }
-
- protected void assertNoReferences(BundleContext bundleContext, String clazz, String
filter) throws Exception
- {
- ServiceReference[] actual = bundleContext.getServiceReferences(clazz, filter);
- if (actual != null)
- log.debug(bundleContext + " got " + Arrays.asList(actual) + " for
clazz=" + clazz + " filter=" + filter);
- else
- log.debug(bundleContext + " got nothing for clazz=" + clazz + "
filter=" + filter);
- assertNull("Expected no references for clazz=" + clazz + "
filter=" + filter, actual);
- }
-
- protected void assertReferences(BundleContext bundleContext, String clazz,
ServiceReference... expected) throws Exception
- {
- assertReferences(bundleContext, clazz, null, expected);
- }
-
- protected void assertReferences(BundleContext bundleContext, String clazz, String
filter, ServiceReference... expected) throws Exception
- {
- ServiceReference[] actual = bundleContext.getServiceReferences(clazz, filter);
- if (actual != null)
- log.debug(bundleContext + " got " + Arrays.asList(actual) + " for
clazz=" + clazz + " filter=" + filter);
- else
- log.debug(bundleContext + " got nothing for clazz=" + clazz + "
filter=" + filter);
- assertArrayEquals(bundleContext + " with clazz=" + clazz + "
filter=" + filter, expected, actual);
- }
-
- protected void assertNoGetReference(BundleContext bundleContext, String clazz) throws
Exception
- {
- ServiceReference actual = bundleContext.getServiceReference(clazz);
- if (actual != null)
- log.debug(bundleContext + " got " + actual + " for clazz=" +
clazz);
- else
- log.debug(bundleContext + " got nothing for clazz=" + clazz);
- assertNull("Expected no references for clazz=" + clazz, actual);
- }
-
- protected void assertGetReference(BundleContext bundleContext, String clazz,
ServiceReference expected) throws Exception
- {
- ServiceReference actual = bundleContext.getServiceReference(clazz);
- if (actual != null)
- log.debug(bundleContext + " got " + Arrays.asList(actual) + " for
clazz=" + clazz);
- else
- log.debug(bundleContext + " got nothing for clazz=" + clazz);
- assertEquals(bundleContext + " with clazz=" + clazz, expected, actual);
- }
-
- protected void assertUsingBundles(ServiceReference reference, Bundle... bundles)
- {
- Set<Bundle> actual = new HashSet<Bundle>();
- Bundle[] users = reference.getUsingBundles();
- if (users != null)
- actual.addAll(Arrays.asList(users));
-
- Set<Bundle> expected = new HashSet<Bundle>();
- expected.addAll(Arrays.asList(bundles));
-
- log.debug(reference + " users=" + actual);
-
- // switch - check expected on actual, since actual might be proxy
- assertEquals(actual, expected);
- }
-
- protected <T> T assertInstanceOf(Object o, Class<T> expectedType)
- {
- return assertInstanceOf(o, expectedType, false);
- }
-
- protected <T> T assertInstanceOf(Object o, Class<T> expectedType, boolean
allowNull)
- {
- if (expectedType == null)
- fail("Null expectedType");
-
- if (o == null)
- {
- if (allowNull == false)
- fail("Null object not allowed.");
- else
- return null;
- }
-
- try
- {
- return expectedType.cast(o);
- }
- catch (ClassCastException e)
- {
- fail("Object " + o + " of class " + o.getClass().getName() +
" is not an instanceof " + expectedType.getName());
- // should not reach this
- return null;
- }
- }
-
- @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/service/ServiceFactoryTestCase.java
===================================================================
---
projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/service/ServiceFactoryTestCase.java 2010-03-21
06:21:27 UTC (rev 102679)
+++
projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/service/ServiceFactoryTestCase.java 2010-03-21
06:41:41 UTC (rev 102680)
@@ -215,7 +215,6 @@
public void testServiceFactoryUsingBundles() throws Exception
{
final boolean[] allGood = new boolean[2];
-
ServiceFactory factory = new ServiceFactory()
{
@Override
Added:
projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/testing/OSGiFrameworkTest.java
===================================================================
---
projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/testing/OSGiFrameworkTest.java
(rev 0)
+++
projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/testing/OSGiFrameworkTest.java 2010-03-21
06:41:41 UTC (rev 102680)
@@ -0,0 +1,404 @@
+/*
+ * 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.osgi.testing;
+
+// $Id: $
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+import org.jboss.logging.Logger;
+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.vfs.VirtualFile;
+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;
+import org.osgi.service.packageadmin.PackageAdmin;
+
+/**
+ * Parent for native framework tests.
+ *
+ * @author Thomas.Diesler(a)jboss.com
+ * @since 10-Mar-2010
+ */
+public abstract class OSGiFrameworkTest extends OSGiTest implements ServiceListener,
SynchronousBundleListener, FrameworkListener
+{
+ // Provide logging
+ private static final Logger log = Logger.getLogger(OSGiFrameworkTest.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 PackageAdmin getPackageAdmin()
+ {
+ ServiceReference sref = context.getServiceReference(PackageAdmin.class.getName());
+ return (PackageAdmin)context.getService(sref);
+ }
+
+ protected Bundle installBundle(VirtualFile archive) throws Exception
+ {
+ String location = archive.toURL().toExternalForm();
+ return context.installBundle(location, archive.openStream());
+ }
+
+ protected void assertLoadClass(Bundle bundle, String className, Bundle exporter)
+ {
+ Class<?> clazz = assertLoadClass(bundle, className);
+ Bundle actual = getPackageAdmin().getBundle(clazz);
+ assertEquals(exporter, actual);
+ }
+
+ @Override
+ public void frameworkEvent(FrameworkEvent event)
+ {
+ synchronized (frameworkEvents)
+ {
+ log.debug("FrameworkEvent type=" +
ConstantsHelper.frameworkEvent(event.getType()) + " for " + event);
+ frameworkEvents.add(event);
+ frameworkEvents.notifyAll();
+ }
+ }
+
+ protected void assertNoFrameworkEvent() throws Exception
+ {
+ log.debug("frameworkEvents=" + frameworkEvents);
+ assertEquals(0, frameworkEvents.size());
+ }
+
+ protected void assertFrameworkEvent(int type, Bundle bundle, Class<? extends
Throwable> expectedThrowable) throws Exception
+ {
+ waitForEvent(frameworkEvents, type);
+ log.debug("frameworkEvents=" + frameworkEvents);
+ int size = frameworkEvents.size();
+ assertTrue("" + size, size > 0);
+ FrameworkEvent event = frameworkEvents.remove(0);
+ assertEquals(ConstantsHelper.frameworkEvent(type),
ConstantsHelper.frameworkEvent(event.getType()));
+ Throwable t = event.getThrowable();
+ if (expectedThrowable == null)
+ {
+ if (t != null)
+ {
+ log.error("Unexpected error in Framework event: ", t);
+ fail("Unexpected throwable: " + t);
+ }
+ }
+ else
+ {
+ String message = expectedThrowable.getSimpleName() + " is assignable from
" + t.getClass().getSimpleName();
+ assertTrue(message, expectedThrowable.isAssignableFrom(t.getClass()));
+ }
+ assertEquals(bundle, event.getSource());
+ assertEquals(bundle, event.getBundle());
+ }
+
+ @Override
+ public void bundleChanged(BundleEvent event)
+ {
+ synchronized (bundleEvents)
+ {
+ log.debug("BundleChanged type=" +
ConstantsHelper.bundleEvent(event.getType()) + " for " + event);
+ bundleEvents.add(event);
+ bundleEvents.notifyAll();
+ }
+ }
+
+ 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);
+
+ 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 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());
+ }
+
+ protected void assertNoAllReferences(BundleContext bundleContext, String clazz) throws
Exception
+ {
+ assertNoAllReferences(bundleContext, clazz, null);
+ }
+
+ protected void assertNoAllReferences(BundleContext bundleContext, String clazz, String
filter) throws Exception
+ {
+ ServiceReference[] actual = bundleContext.getAllServiceReferences(clazz, filter);
+ if (actual != null)
+ log.debug(bundleContext + " got " + Arrays.asList(actual) + " for
clazz=" + clazz + " filter=" + filter);
+ else
+ log.debug(bundleContext + " got nothing for clazz=" + clazz + "
filter=" + filter);
+ assertNull("Expected no references for clazz=" + clazz + "
filter=" + filter, actual);
+ }
+
+ protected void assertAllReferences(BundleContext bundleContext, String clazz,
ServiceReference... expected) throws Exception
+ {
+ assertAllReferences(bundleContext, clazz, null, expected);
+ }
+
+ protected void assertAllReferences(BundleContext bundleContext, String clazz, String
filter, ServiceReference... expected) throws Exception
+ {
+ ServiceReference[] actual = bundleContext.getAllServiceReferences(clazz, filter);
+ if (actual != null)
+ log.debug(bundleContext + " got " + Arrays.asList(actual) + " for
clazz=" + clazz + " filter=" + filter);
+ else
+ log.debug(bundleContext + " got nothing for clazz=" + clazz + "
filter=" + filter);
+ assertArrayEquals(bundleContext + " with clazz=" + clazz + "
filter=" + filter, expected, actual);
+ }
+
+ protected void assertNoReferences(BundleContext bundleContext, String clazz) throws
Exception
+ {
+ assertNoReferences(bundleContext, clazz, null);
+ }
+
+ protected void assertNoReferences(BundleContext bundleContext, String clazz, String
filter) throws Exception
+ {
+ ServiceReference[] actual = bundleContext.getServiceReferences(clazz, filter);
+ if (actual != null)
+ log.debug(bundleContext + " got " + Arrays.asList(actual) + " for
clazz=" + clazz + " filter=" + filter);
+ else
+ log.debug(bundleContext + " got nothing for clazz=" + clazz + "
filter=" + filter);
+ assertNull("Expected no references for clazz=" + clazz + "
filter=" + filter, actual);
+ }
+
+ protected void assertReferences(BundleContext bundleContext, String clazz,
ServiceReference... expected) throws Exception
+ {
+ assertReferences(bundleContext, clazz, null, expected);
+ }
+
+ protected void assertReferences(BundleContext bundleContext, String clazz, String
filter, ServiceReference... expected) throws Exception
+ {
+ ServiceReference[] actual = bundleContext.getServiceReferences(clazz, filter);
+ if (actual != null)
+ log.debug(bundleContext + " got " + Arrays.asList(actual) + " for
clazz=" + clazz + " filter=" + filter);
+ else
+ log.debug(bundleContext + " got nothing for clazz=" + clazz + "
filter=" + filter);
+ assertArrayEquals(bundleContext + " with clazz=" + clazz + "
filter=" + filter, expected, actual);
+ }
+
+ protected void assertNoGetReference(BundleContext bundleContext, String clazz) throws
Exception
+ {
+ ServiceReference actual = bundleContext.getServiceReference(clazz);
+ if (actual != null)
+ log.debug(bundleContext + " got " + actual + " for clazz=" +
clazz);
+ else
+ log.debug(bundleContext + " got nothing for clazz=" + clazz);
+ assertNull("Expected no references for clazz=" + clazz, actual);
+ }
+
+ protected void assertGetReference(BundleContext bundleContext, String clazz,
ServiceReference expected) throws Exception
+ {
+ ServiceReference actual = bundleContext.getServiceReference(clazz);
+ if (actual != null)
+ log.debug(bundleContext + " got " + Arrays.asList(actual) + " for
clazz=" + clazz);
+ else
+ log.debug(bundleContext + " got nothing for clazz=" + clazz);
+ assertEquals(bundleContext + " with clazz=" + clazz, expected, actual);
+ }
+
+ protected void assertUsingBundles(ServiceReference reference, Bundle... bundles)
+ {
+ Set<Bundle> actual = new HashSet<Bundle>();
+ Bundle[] users = reference.getUsingBundles();
+ if (users != null)
+ actual.addAll(Arrays.asList(users));
+
+ Set<Bundle> expected = new HashSet<Bundle>();
+ expected.addAll(Arrays.asList(bundles));
+
+ log.debug(reference + " users=" + actual);
+
+ // switch - check expected on actual, since actual might be proxy
+ assertEquals(actual, expected);
+ }
+
+ protected <T> T assertInstanceOf(Object o, Class<T> expectedType)
+ {
+ return assertInstanceOf(o, expectedType, false);
+ }
+
+ protected <T> T assertInstanceOf(Object o, Class<T> expectedType, boolean
allowNull)
+ {
+ if (expectedType == null)
+ fail("Null expectedType");
+
+ if (o == null)
+ {
+ if (allowNull == false)
+ fail("Null object not allowed.");
+ else
+ return null;
+ }
+
+ try
+ {
+ return expectedType.cast(o);
+ }
+ catch (ClassCastException e)
+ {
+ fail("Object " + o + " of class " + o.getClass().getName() +
" is not an instanceof " + expectedType.getName());
+ // should not reach this
+ return null;
+ }
+ }
+
+ @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/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/bootstrap/BootstrapTestCase.java
===================================================================
---
projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/bootstrap/BootstrapTestCase.java 2010-03-21
06:21:27 UTC (rev 102679)
+++
projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/bootstrap/BootstrapTestCase.java 2010-03-21
06:41:41 UTC (rev 102680)
@@ -29,7 +29,7 @@
import org.jboss.osgi.spi.framework.OSGiBootstrap;
import org.jboss.osgi.spi.framework.OSGiBootstrapProvider;
-import org.jboss.osgi.testing.OSGiRuntimeTest;
+import org.jboss.osgi.testing.OSGiTest;
import org.junit.Test;
import org.osgi.framework.launch.Framework;
@@ -39,7 +39,7 @@
* @author thomas.diesler(a)jboss.com
* @since 25-Feb-2009
*/
-public class BootstrapTestCase extends OSGiRuntimeTest
+public class BootstrapTestCase extends OSGiTest
{
@Test
public void testFrameworkBootstrap() throws Exception
Modified:
projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/framework/FrameworkTestCase.java
===================================================================
---
projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/framework/FrameworkTestCase.java 2010-03-21
06:21:27 UTC (rev 102679)
+++
projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/framework/FrameworkTestCase.java 2010-03-21
06:41:41 UTC (rev 102680)
@@ -27,14 +27,10 @@
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
-import org.jboss.osgi.spi.framework.OSGiBootstrap;
-import org.jboss.osgi.spi.framework.OSGiBootstrapProvider;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
+import org.jboss.osgi.testing.OSGiFrameworkTest;
import org.junit.Ignore;
import org.junit.Test;
import org.osgi.framework.BundleException;
-import org.osgi.framework.launch.Framework;
/**
* Test the Framework functionality
@@ -42,29 +38,8 @@
* @author thomas.diesler(a)jboss.com
* @since 29-Jul-2009
*/
-public class FrameworkTestCase
+public class FrameworkTestCase extends OSGiFrameworkTest
{
- public static Framework framework;
-
- @BeforeClass
- public static void beforeClass() throws BundleException
- {
- OSGiBootstrapProvider bootProvider = OSGiBootstrap.getBootstrapProvider();
- framework = bootProvider.getFramework();
- framework.start();
- }
-
- @AfterClass
- public static void afterClass() throws Exception
- {
- if (framework != null)
- {
- framework.stop();
- framework.waitForStop(2000);
- framework = null;
- }
- }
-
@Test
public void testGetBundleId()
{
Modified:
projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi142/OSGi142TestCase.java
===================================================================
---
projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi142/OSGi142TestCase.java 2010-03-21
06:21:27 UTC (rev 102679)
+++
projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi142/OSGi142TestCase.java 2010-03-21
06:41:41 UTC (rev 102680)
@@ -23,9 +23,9 @@
//$Id: OSGI142TestCase.java 87103 2009-04-09 22:18:31Z thomas.diesler(a)jboss.com $
-
import org.jboss.osgi.spi.framework.OSGiBootstrap;
import org.jboss.osgi.spi.framework.OSGiBootstrapProvider;
+import org.jboss.osgi.testing.OSGiFrameworkTest;
import org.jboss.osgi.testing.OSGiRuntimeTest;
import org.jboss.test.osgi.jbosgi142.bundleA.BeanA;
import org.jboss.test.osgi.jbosgi142.bundleB.BeanB;
@@ -49,46 +49,34 @@
* @author thomas.diesler(a)jboss.com
* @since 28-Aug-2009
*/
-public class OSGi142TestCase extends OSGiRuntimeTest
+public class OSGi142TestCase extends OSGiFrameworkTest
{
@Test
public void testLoadClass() throws Exception
{
- OSGiBootstrapProvider bootProvider = OSGiBootstrap.getBootstrapProvider();
- Framework framework = bootProvider.getFramework();
- try
- {
- framework.start();
-
- BundleContext sysContext = framework.getBundleContext();
- Bundle bundleX =
sysContext.installBundle(getTestArchiveURL("jbosgi142-bundleX.jar").toExternalForm());
- bundleX.start();
-
- assertLoadClass(bundleX, BeanX.class.getName());
-
- Bundle bundleA =
sysContext.installBundle(getTestArchiveURL("jbosgi142-bundleA.jar").toExternalForm());
- bundleA.start();
-
- assertLoadClass(bundleA, BeanA.class.getName());
-
- Bundle bundleB =
sysContext.installBundle(getTestArchiveURL("jbosgi142-bundleB.jar").toExternalForm());
- bundleB.start();
-
- assertLoadClass(bundleB, BeanB.class.getName());
-
- assertLoadClass(bundleA, BeanX.class.getName());
- assertLoadClass(bundleB, BeanX.class.getName());
-
- assertLoadClassFail(bundleX, BeanA.class.getName());
- assertLoadClassFail(bundleX, BeanB.class.getName());
-
- assertLoadClassFail(bundleA, BeanB.class.getName());
- assertLoadClassFail(bundleB, BeanA.class.getName());
- }
- finally
- {
- framework.stop();
- framework.waitForStop(2000);
- }
+ BundleContext sysContext = framework.getBundleContext();
+ Bundle bundleX =
sysContext.installBundle(getTestArchiveURL("jbosgi142-bundleX.jar").toExternalForm());
+ bundleX.start();
+
+ assertLoadClass(bundleX, BeanX.class.getName());
+
+ Bundle bundleA =
sysContext.installBundle(getTestArchiveURL("jbosgi142-bundleA.jar").toExternalForm());
+ bundleA.start();
+
+ assertLoadClass(bundleA, BeanA.class.getName());
+
+ Bundle bundleB =
sysContext.installBundle(getTestArchiveURL("jbosgi142-bundleB.jar").toExternalForm());
+ bundleB.start();
+
+ assertLoadClass(bundleB, BeanB.class.getName());
+
+ assertLoadClass(bundleA, BeanX.class.getName());
+ assertLoadClass(bundleB, BeanX.class.getName());
+
+ assertLoadClassFail(bundleX, BeanA.class.getName());
+ assertLoadClassFail(bundleX, BeanB.class.getName());
+
+ assertLoadClassFail(bundleA, BeanB.class.getName());
+ assertLoadClassFail(bundleB, BeanA.class.getName());
}
}
\ No newline at end of file
Modified:
projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi143/OSGi143TestCase.java
===================================================================
---
projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi143/OSGi143TestCase.java 2010-03-21
06:21:27 UTC (rev 102679)
+++
projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi143/OSGi143TestCase.java 2010-03-21
06:41:41 UTC (rev 102680)
@@ -28,6 +28,7 @@
import org.jboss.osgi.spi.framework.OSGiBootstrap;
import org.jboss.osgi.spi.framework.OSGiBootstrapProvider;
+import org.jboss.osgi.testing.OSGiFrameworkTest;
import org.jboss.osgi.testing.OSGiRuntimeTest;
import org.jboss.test.osgi.jbosgi143.bundleA.BeanA;
import org.jboss.test.osgi.jbosgi143.bundleX.BeanX;
@@ -49,42 +50,30 @@
* @author thomas.diesler(a)jboss.com
* @since 28-Aug-2009
*/
-public class OSGi143TestCase extends OSGiRuntimeTest
+public class OSGi143TestCase extends OSGiFrameworkTest
{
@Test
public void testLoadClass() throws Exception
{
- OSGiBootstrapProvider bootProvider = OSGiBootstrap.getBootstrapProvider();
- Framework framework = bootProvider.getFramework();
- try
- {
- framework.start();
-
- BundleContext sysContext = framework.getBundleContext();
- Bundle bundleX =
sysContext.installBundle(getTestArchiveURL("jbosgi143-bundleX.jar").toExternalForm());
- bundleX.start();
-
- assertBundleLoadClass(bundleX, BeanX.class, true);
-
- Bundle bundleA =
sysContext.installBundle(getTestArchiveURL("jbosgi143-bundleA.jar").toExternalForm());
- bundleA.start();
-
- assertBundleLoadClass(bundleA, BeanA.class, true);
-
- assertBundleLoadClass(bundleA, BeanX.class, true);
- assertBundleLoadClass(bundleX, BeanA.class, true);
- }
- finally
- {
- framework.stop();
- framework.waitForStop(2000);
- }
+ BundleContext sysContext = framework.getBundleContext();
+ Bundle bundleX =
sysContext.installBundle(getTestArchiveURL("jbosgi143-bundleX.jar").toExternalForm());
+ bundleX.start();
+
+ assertBundleLoadClass(bundleX, BeanX.class, true);
+
+ Bundle bundleA =
sysContext.installBundle(getTestArchiveURL("jbosgi143-bundleA.jar").toExternalForm());
+ bundleA.start();
+
+ assertBundleLoadClass(bundleA, BeanA.class, true);
+
+ assertBundleLoadClass(bundleA, BeanX.class, true);
+ assertBundleLoadClass(bundleX, BeanA.class, true);
}
- private void assertBundleLoadClass(Bundle bundle, Class<?> expClazz, boolean
success)
+ private void assertBundleLoadClass(Bundle bundle, Class<?> expClazz, boolean
success)
{
String message = bundle.getSymbolicName() + " loads " +
expClazz.getName();
-
+
Class<?> wasClass;
try
{
Modified:
projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi151/OSGi151TestCase.java
===================================================================
---
projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi151/OSGi151TestCase.java 2010-03-21
06:21:27 UTC (rev 102679)
+++
projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi151/OSGi151TestCase.java 2010-03-21
06:41:41 UTC (rev 102680)
@@ -23,18 +23,13 @@
import static org.junit.Assert.assertEquals;
-import org.jboss.osgi.spi.framework.OSGiBootstrap;
-import org.jboss.osgi.spi.framework.OSGiBootstrapProvider;
-import org.jboss.osgi.testing.OSGiRuntimeTest;
+import org.jboss.osgi.testing.OSGiFrameworkTest;
import org.jboss.test.osgi.jbosgi151.bundleA.BeanA;
import org.jboss.test.osgi.jbosgi151.bundleB.BeanB;
-import org.junit.After;
-import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
-import org.osgi.framework.launch.Framework;
/**
* [JBOSGI-151] Cannot resolve circular dependencies
@@ -60,29 +55,8 @@
* @author thomas.diesler(a)jboss.com
* @since 07-Sep-2009
*/
-public class OSGi151TestCase extends OSGiRuntimeTest
+public class OSGi151TestCase extends OSGiFrameworkTest
{
- private Framework framework;
-
- @Before
- public void setUp() throws Exception
- {
- OSGiBootstrapProvider bootProvider = OSGiBootstrap.getBootstrapProvider();
- framework = bootProvider.getFramework();
- framework.start();
- }
-
- @After
- public void tearDown() throws Exception
- {
- if (framework != null)
- {
- framework.stop();
- framework.waitForStop(2000);
- framework = null;
- }
- }
-
@Test
public void testCircularNoSelfDependency() throws Exception
{
Modified:
projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/services/ServiceRegistrationTestCase.java
===================================================================
---
projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/services/ServiceRegistrationTestCase.java 2010-03-21
06:21:27 UTC (rev 102679)
+++
projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/services/ServiceRegistrationTestCase.java 2010-03-21
06:41:41 UTC (rev 102680)
@@ -27,20 +27,15 @@
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
-import org.jboss.osgi.spi.framework.OSGiBootstrap;
-import org.jboss.osgi.spi.framework.OSGiBootstrapProvider;
-import org.jboss.osgi.testing.OSGiTest;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
+import org.jboss.osgi.testing.OSGiFrameworkTest;
import org.junit.Test;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
-import org.osgi.framework.BundleException;
import org.osgi.framework.ServiceFactory;
import org.osgi.framework.ServiceReference;
import org.osgi.framework.ServiceRegistration;
-import org.osgi.framework.launch.Framework;
/**
* Test service related functionality.
@@ -48,29 +43,8 @@
* @author thomas.diesler(a)jboss.com
* @since 20-Mar-2010
*/
-public class ServiceRegistrationTestCase extends OSGiTest
+public class ServiceRegistrationTestCase extends OSGiFrameworkTest
{
- public static Framework framework;
-
- @BeforeClass
- public static void beforeClass() throws BundleException
- {
- OSGiBootstrapProvider bootProvider = OSGiBootstrap.getBootstrapProvider();
- framework = bootProvider.getFramework();
- framework.start();
- }
-
- @AfterClass
- public static void afterClass() throws Exception
- {
- if (framework != null)
- {
- framework.stop();
- framework.waitForStop(2000);
- framework = null;
- }
- }
-
@Test
public void testUsingBundles() throws Exception
{
@@ -104,6 +78,7 @@
@Test
public void testServiceFactoryUsingBundles() throws Exception
{
+ final boolean[] allGood = new boolean[2];
ServiceFactory factory = new ServiceFactory()
{
@Override
@@ -111,9 +86,10 @@
{
ServiceReference sref = sreg.getReference();
Bundle[] users = sref.getUsingBundles();
+ assertNotNull("Users not null", users);
assertEquals(1, users.length);
assertEquals(bundle, users[0]);
-
+ allGood[0] = true;
return new Runnable()
{
public void run()
@@ -123,9 +99,14 @@
}
@Override
- public void ungetService(Bundle bundle, ServiceRegistration registration, Object
service)
+ public void ungetService(Bundle bundle, ServiceRegistration sreg, Object
service)
{
- // nothing to do
+ ServiceReference sref = sreg.getReference();
+ Bundle[] users = sref.getUsingBundles();
+ assertNotNull("Users not null", users);
+ assertEquals(1, users.length);
+ assertEquals(bundle, users[0]);
+ allGood[1] = true;
}
};
BundleContext context = framework.getBundleContext();
@@ -135,16 +116,18 @@
Bundle[] users = sref.getUsingBundles();
assertNull("Null users", users);
- Runnable was1 = (Runnable)context.getService(sref);
+ Runnable was = (Runnable)context.getService(sref);
+ assertNotNull("Service not null", was);
users = sref.getUsingBundles();
- assertNotNull("Service not null", was1);
+ assertNotNull("Users not null", users);
assertEquals(1, users.length);
assertEquals(context.getBundle(), users[0]);
-
- Runnable was2 = (Runnable)context.getService(sref);
- users = sref.getUsingBundles();
- assertSame(was1, was2);
- assertEquals(1, users.length);
- assertEquals(context.getBundle(), users[0]);
+ assertTrue("getService good", allGood[0]);
+
+ sreg.unregister();
+
+ was = (Runnable)context.getService(sref);
+ assertNull("Service null", was);
+ assertTrue("ungetService good", allGood[1]);
}
}
\ No newline at end of file