JBoss-OSGI SVN: r102229 - in projects/jboss-osgi/projects/runtime/framework/trunk/bundle: src/test/java/org/jboss/test/osgi and 10 other directories.
by jboss-osgi-commits@lists.jboss.org
Author: thomas.diesler(a)jboss.com
Date: 2010-03-10 11:12:51 -0500 (Wed, 10 Mar 2010)
New Revision: 102229
Added:
projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/AbstractDeploymentTest.java
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/AbstractServiceMixTest.java
projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/service/support/e/
projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/service/support/e/E.java
projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/resources/service/
projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/resources/service/JMXServicesUnitTestCase#testAtJmx.xml
projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/resources/service/jmx-services.xml
Removed:
projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/DeployersTest.java
projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/DeployersTestDelegate.java
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/FrameworkTestDelegate.java
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/service/ServicesTest.java
projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/smoke/
projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/resources/org/
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/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/bundle/src/test/java/org/jboss/test/osgi/classloader/RequireBundleUnitTestCase.java
projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/compendium/PackageAdminTestCase.java
projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/fragments/FragmentTestCase.java
projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/resolver/AbstractImportExportTest.java
projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/resolver/ResolverMetadataTest.java
projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/service/GetServiceReferencesUnitTestCase.java
projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/service/GetUnGetServiceUnitTestCase.java
projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/service/JMXServicesUnitTestCase.java
projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/service/RegisterServiceUnitTestCase.java
projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/service/ServiceFactoryUnitTestCase.java
projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/service/ServiceMixUnitTestCase.java
projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/service/ServiceReferenceUnitTestCase.java
projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/service/ServiceRegistrationUnitTestCase.java
Log:
Migrate all framework tests to OSGiTest.
This removes all dependencies on jboss-vfs
Modified: projects/jboss-osgi/projects/runtime/framework/trunk/bundle/pom.xml
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/bundle/pom.xml 2010-03-10 16:06:33 UTC (rev 102228)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/bundle/pom.xml 2010-03-10 16:12:51 UTC (rev 102229)
@@ -289,9 +289,8 @@
</property>
</systemProperties>
<excludes>
- <!-- excludes listed here need to have a jira issue associated
+ <!-- excludes listed here need to have a jira issue associated -->
<exclude>org/jboss/test/osgi/service/ServiceMixUnitTestCase.class</exclude>
- -->
</excludes>
</configuration>
</plugin>
Added: projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/AbstractDeploymentTest.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/AbstractDeploymentTest.java (rev 0)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/AbstractDeploymentTest.java 2010-03-10 16:12:51 UTC (rev 102229)
@@ -0,0 +1,165 @@
+/*
+ * 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 java.net.URL;
+
+import org.jboss.beans.metadata.spi.BeanMetaData;
+import org.jboss.beans.metadata.spi.builder.BeanMetaDataBuilder;
+import org.jboss.dependency.spi.Controller;
+import org.jboss.dependency.spi.ControllerState;
+import org.jboss.deployers.client.spi.DeployerClient;
+import org.jboss.deployers.client.spi.Deployment;
+import org.jboss.deployers.spi.attachments.MutableAttachments;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.deployers.structure.spi.main.MainDeployerStructure;
+import org.jboss.kernel.Kernel;
+import org.jboss.kernel.plugins.deployment.xml.BasicXMLDeployer;
+import org.jboss.kernel.spi.dependency.KernelController;
+import org.jboss.kernel.spi.dependency.KernelControllerContext;
+import org.jboss.kernel.spi.deployment.KernelDeployment;
+import org.jboss.osgi.framework.deployers.AbstractDeployment;
+import org.jboss.osgi.vfs.VirtualFile;
+
+/**
+ * Parent for deployment tests.
+ *
+ * @author Thomas.Diesler(a)jboss.com
+ * @since 10-Mar-2010
+ */
+public abstract class AbstractDeploymentTest extends AbstractFrameworkTest
+{
+ protected BasicXMLDeployer deployer;
+
+ protected Kernel getKernel()
+ {
+ return getBundleManager().getKernel();
+ }
+
+ protected Object getBean(Object beanName)
+ {
+ return getBean(beanName, ControllerState.INSTALLED);
+ }
+
+ protected Object getBean(Object name, ControllerState state)
+ {
+ KernelControllerContext context = getControllerContext(name, state);
+ return context.getTarget();
+ }
+
+ protected KernelControllerContext getControllerContext(Object name)
+ {
+ return getControllerContext(name, ControllerState.INSTALLED);
+ }
+
+ protected KernelControllerContext getControllerContext(Object name, ControllerState state)
+ {
+ KernelController controller = getKernel().getController();
+ KernelControllerContext context = (KernelControllerContext)controller.getContext(name, state);
+ if (context == null)
+ throw new IllegalStateException("Bean not found " + name + " at state " + state);
+ return context;
+ }
+
+ protected ControllerState change(KernelControllerContext context, ControllerState required) throws Throwable
+ {
+ Controller controller = getKernel().getController();
+ controller.change(context, required);
+ return context.getState();
+ }
+
+ protected void checkComplete() throws Exception
+ {
+ getDeployerClient().checkComplete();
+ }
+
+ public DeploymentUnit getDeploymentUnit(Deployment deployment) throws Exception
+ {
+ DeployerClient deployerClient = getDeployerClient();
+ MainDeployerStructure deployerStructure = (MainDeployerStructure)deployerClient;
+ return deployerStructure.getDeploymentUnit(deployment.getName());
+ }
+
+ public void undeploy(Deployment deployment) throws Exception
+ {
+ DeployerClient deployerClient = getDeployerClient();
+ deployerClient.undeploy(deployment);
+ }
+
+ protected DeployerClient getDeployerClient()
+ {
+ return getBundleManager().getDeployerClient();
+ }
+
+ protected KernelDeployment deploy(URL urlDeployment) throws Throwable
+ {
+ return getDeployer().deploy(urlDeployment);
+ }
+
+ protected void undeploy(URL urlDeployment) throws Throwable
+ {
+ getDeployer().undeploy(urlDeployment);
+ }
+
+ protected BasicXMLDeployer getDeployer()
+ {
+ if (deployer == null)
+ {
+ deployer = new BasicXMLDeployer(getKernel());
+ }
+ return deployer;
+ }
+
+ protected Deployment deployBeans(String name, Class<?> beanClass) throws Exception
+ {
+ return deployBeans(name, null, new Class<?>[] { beanClass });
+ }
+
+ protected Deployment deployBeans(String name, BeanMetaData bmd, Class<?>... packages) throws Exception
+ {
+ Deployment deployment = addBeans(name, bmd, packages);
+ getDeployerClient().checkComplete();
+ return deployment;
+ }
+
+ protected Deployment addBeans(String name, BeanMetaData bmd, Class<?>... packages) throws Exception
+ {
+ VirtualFile assembly = assembleArchive(name, new String[0], packages);
+
+ if (bmd == null)
+ {
+ Class<?> beanClass = packages[0];
+ BeanMetaDataBuilder builder = BeanMetaDataBuilder.createBuilder(beanClass.getSimpleName(), beanClass.getName());
+ bmd = builder.getBeanMetaData();
+ }
+
+ Deployment deployment = AbstractDeployment.createDeployment(assembly);
+ MutableAttachments att = (MutableAttachments)deployment.getPredeterminedManagedObjects();
+ att.addAttachment(BeanMetaData.class, bmd);
+
+ getDeployerClient().addDeployment(deployment);
+ getDeployerClient().process();
+ return deployment;
+ }
+}
Copied: projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/AbstractFrameworkTest.java (from rev 102224, 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/AbstractFrameworkTest.java (rev 0)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/AbstractFrameworkTest.java 2010-03-10 16:12:51 UTC (rev 102229)
@@ -0,0 +1,409 @@
+/*
+ * 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.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.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 AbstractFrameworkTest extends OSGiTest implements ServiceListener, SynchronousBundleListener, FrameworkListener
+{
+ // 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 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--;
+ }
+ }
+}
Deleted: projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/DeployersTest.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/DeployersTest.java 2010-03-10 16:06:33 UTC (rev 102228)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/DeployersTest.java 2010-03-10 16:12:51 UTC (rev 102229)
@@ -1,146 +0,0 @@
-/*
- * 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;
-
-import org.jboss.beans.metadata.spi.BeanMetaData;
-import org.jboss.beans.metadata.spi.builder.BeanMetaDataBuilder;
-import org.jboss.deployers.client.spi.Deployment;
-import org.jboss.deployers.structure.spi.DeploymentUnit;
-import org.jboss.osgi.framework.bundle.AbstractBundleState;
-import org.jboss.virtual.AssembledDirectory;
-import org.jboss.virtual.VirtualFile;
-import org.osgi.framework.Bundle;
-
-/**
- * Deployers test - generic deployment test.
- *
- * @author <a href="ales.justin(a)jboss.org">Ales Justin</a>
- */
-public abstract class DeployersTest extends FrameworkTest
-{
- protected DeployersTest(String name)
- {
- super(name);
- }
-
- public static DeployersTestDelegate getDelegate(Class<?> clazz) throws Exception
- {
- return new DeployersTestDelegate(clazz);
- }
-
- protected DeployersTestDelegate getDelegate()
- {
- return (DeployersTestDelegate)super.getDelegate();
- }
-
- protected void checkComplete() throws Exception
- {
- getDelegate().checkComplete();
- }
-
- protected Deployment addDeployment(VirtualFile file) throws Exception
- {
- return getDelegate().addDeployment(file);
- }
-
- protected <T> Deployment addDeployment(VirtualFile file, T metadata, Class<T> expectedType) throws Exception
- {
- return getDelegate().addDeployment(file, metadata, expectedType);
- }
-
- protected Deployment assertDeploy(VirtualFile file) throws Exception
- {
- return getDelegate().assertDeploy(file);
- }
-
- protected <T> Deployment assertDeploy(VirtualFile file, T metadata, Class<T> expectedType) throws Exception
- {
- return getDelegate().assertDeploy(file, metadata, expectedType);
- }
-
- protected DeploymentUnit getDeploymentUnit(Deployment deployment) throws Exception
- {
- return getDelegate().getDeploymentUnit(deployment);
- }
-
- protected void undeploy(Deployment deployment) throws Exception
- {
- getDelegate().undeploy(deployment);
- }
-
- protected Deployment addBean(String name, Class<?> beanClass, Class<?> ... references) throws Exception
- {
- return addBean(name, beanClass, null, references);
- }
-
- protected Deployment addBean(String name, Class<?> beanClass, BeanMetaData bmd, Class<?> ... references) throws Exception
- {
- AssembledDirectory dir = createAssembledDirectory(name, "");
- if (beanClass != null)
- addPackage(dir, beanClass);
- if (references != null)
- {
- for (Class<?> reference : references)
- addPackage(dir, reference);
- }
- if (bmd == null)
- {
- BeanMetaDataBuilder builder = BeanMetaDataBuilder.createBuilder(beanClass.getSimpleName(), beanClass.getName());
- bmd = builder.getBeanMetaData();
- }
- return addDeployment(dir, bmd, BeanMetaData.class);
- }
-
- protected Deployment deployBean(String name, Class<?> beanClass, Class<?> ... references) throws Exception
- {
- return deployBean(name, beanClass, null, references);
- }
-
- protected Deployment deployBean(String name, Class<?> beanClass, BeanMetaData bmd, Class<?> ... references) throws Exception
- {
- AssembledDirectory dir = createAssembledDirectory(name, "");
- addPackage(dir, beanClass);
- if (references != null)
- {
- for (Class<?> reference : references)
- addPackage(dir, reference);
- }
- if (bmd == null)
- {
- BeanMetaDataBuilder builder = BeanMetaDataBuilder.createBuilder(beanClass.getSimpleName(), beanClass.getName());
- bmd = builder.getBeanMetaData();
- }
- return assertDeploy(dir, bmd, BeanMetaData.class);
- }
-
- protected Bundle getBundle(Deployment deployment) throws Exception
- {
- return getBundle(getDeploymentUnit(deployment));
- }
-
- protected Bundle getBundle(DeploymentUnit unit) throws Exception
- {
- AbstractBundleState bundle = unit.getAttachment(AbstractBundleState.class);
- assertNotNull(bundle);
- return bundle.getBundleInternal();
- }
-}
\ No newline at end of file
Deleted: projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/DeployersTestDelegate.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/DeployersTestDelegate.java 2010-03-10 16:06:33 UTC (rev 102228)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/DeployersTestDelegate.java 2010-03-10 16:12:51 UTC (rev 102229)
@@ -1,86 +0,0 @@
-/*
- * 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;
-
-import org.jboss.deployers.client.spi.Deployment;
-import org.jboss.deployers.client.spi.DeployerClient;
-import org.jboss.deployers.structure.spi.DeploymentUnit;
-import org.jboss.deployers.structure.spi.main.MainDeployerStructure;
-import org.jboss.virtual.VirtualFile;
-
-/**
- * Deployers test - generic deployment test delegate.
- *
- * @author <a href="ales.justin(a)jboss.org">Ales Justin</a>
- */
-public class DeployersTestDelegate extends FrameworkTestDelegate
-{
- public DeployersTestDelegate(Class<?> clazz) throws Exception
- {
- super(clazz);
- }
-
- public void checkComplete() throws Exception
- {
- getDeployerClient().checkComplete();
- }
-
- public Deployment addDeployment(VirtualFile file) throws Exception
- {
- return addDeployment(file, null, null);
- }
-
- public <T> Deployment addDeployment(VirtualFile file, T metadata, Class<T> expectedType) throws Exception
- {
- Deployment deployment = createDeployment(file, metadata, expectedType);
- DeployerClient deployerClient = getDeployerClient();
- deployerClient.addDeployment(deployment);
- deployerClient.process();
- return deployment;
- }
-
- public Deployment assertDeploy(VirtualFile file) throws Exception
- {
- return assertDeploy(file, null, null);
- }
-
- public <T> Deployment assertDeploy(VirtualFile file, T metadata, Class<T> expectedType) throws Exception
- {
- Deployment deployment = createDeployment(file, metadata, expectedType);
- DeployerClient deployerClient = getDeployerClient();
- deployerClient.deploy(deployment);
- return deployment;
- }
-
- public DeploymentUnit getDeploymentUnit(Deployment deployment) throws Exception
- {
- DeployerClient deployerClient = getDeployerClient();
- MainDeployerStructure deployerStructure = (MainDeployerStructure) deployerClient;
- return deployerStructure.getDeploymentUnit(deployment.getName());
- }
-
- public void undeploy(Deployment deployment) throws Exception
- {
- DeployerClient deployerClient = getDeployerClient();
- deployerClient.undeploy(deployment);
- }
-}
\ No newline at end of file
Deleted: 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 16:06:33 UTC (rev 102228)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/FrameworkTest.java 2010-03-10 16:12:51 UTC (rev 102229)
@@ -1,649 +0,0 @@
-/*
- * 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;
-
-import java.io.InputStream;
-import java.net.URL;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Enumeration;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-import java.util.concurrent.CopyOnWriteArrayList;
-
-import org.jboss.classloader.plugins.ClassLoaderUtils;
-import org.jboss.deployers.structure.spi.DeploymentUnit;
-import org.jboss.osgi.framework.bundle.AbstractBundleState;
-import org.jboss.osgi.framework.bundle.OSGiBundleManager;
-import org.jboss.osgi.framework.metadata.OSGiMetaData;
-import org.jboss.osgi.spi.util.ConstantsHelper;
-import org.jboss.osgi.vfs.AbstractVFS;
-import org.jboss.test.kernel.junit.MicrocontainerTest;
-import org.jboss.virtual.AssembledDirectory;
-import org.jboss.virtual.VirtualFile;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.BundleEvent;
-import org.osgi.framework.BundleException;
-import org.osgi.framework.Constants;
-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;
-
-/**
- * OSGiTestCase - Parent Test Case for OSGi tests.
- *
- * @author <a href="baileyje(a)gmail.com">John Bailey</a>
- * @version $Revision: 87848 $
- */
-@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>();
- private final List<BundleEvent> bundleEvents = new CopyOnWriteArrayList<BundleEvent>();
- private final List<ServiceEvent> serviceEvents = new CopyOnWriteArrayList<ServiceEvent>();
-
- /**
- * Create a new OSGiTestCase.
- *
- * @param name the test name
- */
- public FrameworkTest(String name)
- {
- super(name);
- }
-
- public static FrameworkTestDelegate getDelegate(Class<?> clazz) throws Exception
- {
- return new FrameworkTestDelegate(clazz);
- }
-
- /**
- * Get OSGiTestDelegate
- */
- protected FrameworkTestDelegate getDelegate()
- {
- return (FrameworkTestDelegate)super.getDelegate();
- }
-
- /**
- * Get BundleManager from Delegate
- *
- * @return The BundleManager
- */
- protected OSGiBundleManager getBundleManager()
- {
- return getDelegate().getBundleManager();
- }
-
- /**
- * Get the system bundle
- *
- * @return the system bundle
- */
- protected Bundle getSystemBundle()
- {
- return getBundleManager().getBundleById(0).getBundleInternal();
- }
-
- /**
- * Add the base bundles
- *
- * @param expected the collection to add to
- */
- protected void addBaseBundles(Collection<Bundle> expected)
- {
- expected.add(getSystemBundle());
- }
-
- /**
- * Create a bundle
- *
- * @param root the location of the location to deploy
- * @param child the child to deploy
- * @return Bundle for the deployment
- * @throws Exception for any error
- */
- protected Bundle addBundle(String root, String child) throws Exception
- {
- return getDelegate().addBundle(root, child);
- }
-
- /**
- * Create a bundle
- *
- * @param file the virtual file
- * @return Bundle for the deployment
- * @throws Exception for any error
- */
- protected Bundle addBundle(VirtualFile file) throws Exception
- {
- return getDelegate().addBundle(file);
- }
-
- /**
- * Create a bundle
- *
- * @param root the location of the location to deploy
- * @param child the child to deploy
- * @return Bundle for the deployment
- * @throws Exception for any error
- */
- protected Bundle deployBundle(String root, String child) throws Exception
- {
- return getDelegate().deployBundle(root, child);
- }
-
- /**
- * Create a bundle
- *
- * @param file the virtual file
- * @return Bundle for the deployment
- * @throws Exception for any error
- */
- protected Bundle deployBundle(VirtualFile file) throws Exception
- {
- return getDelegate().deployBundle(file);
- }
-
- protected Bundle installBundle(String location) throws BundleException
- {
- return getBundleManager().installBundle(location, null).getBundleInternal();
- }
-
- protected Bundle installBundle(String location, InputStream instream) throws BundleException
- {
- return getBundleManager().installBundle(location, instream).getBundleInternal();
- }
-
- protected Bundle installBundle(VirtualFile bundleFile) throws BundleException
- {
- return getBundleManager().installBundle(AbstractVFS.adapt(bundleFile)).getBundleInternal();
- }
-
- /**
- * Remove a bundle
- *
- * @param bundle the bundle to remove
- * @throws Exception for any error
- */
- protected void uninstall(Bundle bundle) throws Exception
- {
- getDelegate().uninstall(bundle);
- }
-
- protected DeploymentUnit getDeploymentUnit(Bundle bundle)
- {
- return getDelegate().getDeploymentUnit(bundle);
- }
-
- protected VirtualFile assembleBundle(String name, String resources, Class<?>... packages) throws Exception
- {
- return getDelegate().assembleBundle(name, new String[] { resources }, packages);
- }
-
- protected VirtualFile assembleBundle(String name, String[] resourcePaths, Class<?>... packages) throws Exception
- {
- return getDelegate().assembleBundle(name, resourcePaths, packages);
- }
-
- protected Bundle deployBundle(String name, Class<?>... packages) throws Exception
- {
- return getDelegate().deployBundle(name, null, (String[]) null, packages);
- }
-
- protected Bundle deployBundle(String name, String resourcePath, Class<?>... packages) throws Exception
- {
- return getDelegate().deployBundle(name, null, resourcePath, packages);
- }
-
- protected Bundle deployBundle(String name, String[] resourcePaths, Class<?>... packages) throws Exception
- {
- return getDelegate().deployBundle(name, null, resourcePaths, packages);
- }
-
- protected Bundle deployBundle(String name, OSGiMetaData metaData, Class<?>... packages) throws Exception
- {
- return getDelegate().deployBundle(name, metaData, (String[]) null, packages);
- }
-
- protected Bundle deployBundle(String name, OSGiMetaData metaData, String resourcePath, Class<?>... packages) throws Exception
- {
- return getDelegate().deployBundle(name, metaData, resourcePath, packages);
- }
-
- protected Bundle deployBundle(String name, OSGiMetaData metaData, String[] resourcePaths, Class<?>... packages) throws Exception
- {
- return getDelegate().deployBundle(name, metaData, resourcePaths, packages);
- }
-
- protected AssembledDirectory createAssembledDirectory(String name) throws Exception
- {
- return getDelegate().createAssembledDirectory(name, "");
- }
-
- protected AssembledDirectory createAssembledDirectory(String name, String rootName) throws Exception
- {
- return getDelegate().createAssembledDirectory(name, rootName);
- }
-
- protected void addPackage(AssembledDirectory dir, Class<?> reference) throws Exception
- {
- getDelegate().addPackage(dir, reference);
- }
-
- protected void addPath(final AssembledDirectory dir, String path, String name) throws Exception
- {
- getDelegate().addPath(dir, path, name);
- }
-
- protected void assertBundleState(int expState, int wasState)
- {
- String expstr = ConstantsHelper.bundleState(expState);
- String wasstr = ConstantsHelper.bundleState(wasState);
- assertEquals("Bundle " + expstr, expstr, wasstr);
- }
-
- protected void assertClassEquality(Class<?> expected, Class<?> actual)
- {
- assertTrue("Should be the same " + ClassLoaderUtils.classToString(expected) + " and " + ClassLoaderUtils.classToString(actual), expected == actual);
- }
-
- protected void assertNoClassEquality(Class<?> expected, Class<?> actual)
- {
- assertTrue("Should NOT be the same " + ClassLoaderUtils.classToString(expected) + " and " + ClassLoaderUtils.classToString(actual), expected != actual);
- }
-
- protected void assertClassLoader(Class<?> clazz, Bundle expected)
- {
- if (expected == null)
- return;
- ClassLoader cl = clazz.getClassLoader();
- ClassLoader bundleClassLoader = getBundleClassLoader(expected);
- boolean result = bundleClassLoader.equals(cl);
- assertTrue(ClassLoaderUtils.classToString(clazz) + " should have expected classloader=" + expected, result);
- }
-
- protected ClassLoader getBundleClassLoader(Bundle expected)
- {
- return getDeploymentUnit(expected).getClassLoader();
- }
-
- protected Class<?> assertLoadClass(Bundle start, Class<?> reference) throws Exception
- {
- return assertLoadClass(start, reference, start);
- }
-
- protected Class<?> assertLoadClass(Bundle start, Class<?> reference, Bundle expected) throws Exception
- {
- return assertLoadClass(start, reference, expected, false);
- }
-
- protected Class<?> assertLoadClass(Bundle start, Class<?> reference, Bundle expected, boolean isReference) throws Exception
- {
- Class<?> result = assertLoadClass(reference.getName(), start, expected);
- if (isReference)
- assertClassEquality(reference, result);
- else
- assertNoClassEquality(reference, result);
- return result;
- }
-
- protected Class<?> assertLoadClass(String name, Bundle bundle, Bundle expected)
- {
- Class<?> result = null;
- try
- {
- result = bundle.loadClass(name);
- getLog().debug("Got class: " + ClassLoaderUtils.classToString(result) + " for " + name + " from " + bundle);
- }
- catch (ClassNotFoundException e)
- {
- failure("Did not expect CNFE for " + name + " from " + bundle, e);
- }
- assertClassLoader(result, expected);
- return result;
- }
-
- protected void assertLoadClassFail(Bundle start, Class<?> reference)
- {
- assertLoadClassFail(start, reference.getName());
- }
-
- protected void assertLoadClassFail(Bundle start, String name)
- {
- try
- {
- start.loadClass(name);
- fail("Should not be here!");
- }
- catch (Exception expected)
- {
- checkThrowable(ClassNotFoundException.class, expected);
- }
- }
-
- protected URL getBundleResource(Bundle bundle, String path)
- {
- return getDelegate().getBundleResource(bundle, path);
- }
-
- protected Enumeration<URL> getBundleResources(Bundle bundle, String path) throws Exception
- {
- return getDelegate().getBundleResources(bundle, path);
- }
-
- 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)
- getLog().debug(bundleContext + " got " + Arrays.asList(actual) + " for clazz=" + clazz + " filter=" + filter);
- else
- getLog().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)
- getLog().debug(bundleContext + " got " + Arrays.asList(actual) + " for clazz=" + clazz + " filter=" + filter);
- else
- getLog().debug(bundleContext + " got nothing for clazz=" + clazz + " filter=" + filter);
- assertEquals(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)
- getLog().debug(bundleContext + " got " + Arrays.asList(actual) + " for clazz=" + clazz + " filter=" + filter);
- else
- getLog().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)
- getLog().debug(bundleContext + " got " + Arrays.asList(actual) + " for clazz=" + clazz + " filter=" + filter);
- else
- getLog().debug(bundleContext + " got nothing for clazz=" + clazz + " filter=" + filter);
- assertEquals(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)
- getLog().debug(bundleContext + " got " + actual + " for clazz=" + clazz);
- else
- getLog().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)
- getLog().debug(bundleContext + " got " + Arrays.asList(actual) + " for clazz=" + clazz);
- else
- getLog().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));
-
- getLog().debug(reference + " users=" + actual);
-
- // switch - check expected on actual, since actual might be proxy
- assertEquals(actual, expected);
- }
-
- protected void assertBundle(Bundle b1, Bundle b2)
- {
- assertNotNull(b1);
- assertNotNull(b2);
- assertEquals(b1.getBundleId(), b2.getBundleId());
- }
-
- protected void assertObjectClass(String expected, ServiceReference reference)
- {
- assertObjectClass(new String[] { expected }, reference);
- }
-
- protected void assertObjectClass(String[] expected, ServiceReference reference)
- {
- Object actual = reference.getProperty(Constants.OBJECTCLASS);
- if (actual == null)
- fail("no object class???");
- if (actual instanceof String[] == false)
- fail(actual + " is not a string array??? " + actual.getClass().getName());
- assertEquals(expected, (String[])actual);
- }
-
- public void frameworkEvent(FrameworkEvent event)
- {
- synchronized (frameworkEvents)
- {
- getLog().debug("FrameworkEvent type=" + ConstantsHelper.frameworkEvent(event.getType()) + " for " + event);
- frameworkEvents.add(event);
- frameworkEvents.notifyAll();
- }
- }
-
- protected void assertNoFrameworkEvent() throws Exception
- {
- getLog().debug("frameworkEvents=" + frameworkEvents);
- assertEquals(0, frameworkEvents.size());
- }
-
- protected void assertFrameworkEvent(int type) throws Exception
- {
- assertFrameworkEvent(type, getSystemBundle(), null);
- }
-
- protected void assertFrameworkEvent(int type, Class<? extends Throwable> expectedThrowable) throws Exception
- {
- assertFrameworkEvent(type, getSystemBundle(), expectedThrowable);
- }
-
- protected void assertFrameworkEvent(int type, Bundle bundle, Class<? extends Throwable> expectedThrowable) throws Exception
- {
- waitForEvent(frameworkEvents, type);
- getLog().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)
- {
- getLog().error("Unexpected error in Framework event: ", t);
- fail("Unexpected throwable: " + t);
- }
- }
- else
- {
- checkThrowable(BundleException.class, t);
- checkDeepThrowable(expectedThrowable, t);
- }
- assertEquals(bundle, event.getSource());
- assertEquals(bundle, event.getBundle());
- }
-
- public void bundleChanged(BundleEvent event)
- {
- synchronized (bundleEvents)
- {
- getLog().debug("BundleChanged type=" + ConstantsHelper.bundleEvent(event.getType()) + " for " + event);
- bundleEvents.add(event);
- bundleEvents.notifyAll();
- }
- }
-
- protected void assertNoBundleEvent() throws Exception
- {
- getLog().debug("bundleEvents=" + bundleEvents);
- assertEquals(0, bundleEvents.size());
- }
-
- protected void assertBundleEvent(int type, Bundle bundle) throws Exception
- {
- waitForEvent(bundleEvents, type);
-
- getLog().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);
- }
-
- public void serviceChanged(ServiceEvent event)
- {
- synchronized (serviceEvents)
- {
- getLog().debug("ServiceChanged type=" + ConstantsHelper.serviceEvent(event.getType()) + " for " + event);
- serviceEvents.add(event);
- serviceEvents.notifyAll();
- }
- }
-
- protected void assertNoServiceEvent() throws Exception
- {
- getLog().debug("serviceEvents=" + serviceEvents);
- assertEquals(0, serviceEvents.size());
- }
-
- protected void assertServiceEvent(int type, ServiceReference reference) throws Exception
- {
- waitForEvent(serviceEvents, type);
- getLog().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--;
- }
- }
-}
Deleted: projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/FrameworkTestDelegate.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/FrameworkTestDelegate.java 2010-03-10 16:06:33 UTC (rev 102228)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/FrameworkTestDelegate.java 2010-03-10 16:12:51 UTC (rev 102229)
@@ -1,381 +0,0 @@
-/*
- * 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 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 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 java.io.IOException;
-import java.lang.reflect.Method;
-import java.net.URL;
-import java.util.Collection;
-import java.util.Enumeration;
-
-import junit.framework.AssertionFailedError;
-
-import org.jboss.classloader.plugins.ClassLoaderUtils;
-import org.jboss.dependency.spi.ControllerState;
-import org.jboss.deployers.client.spi.DeployerClient;
-import org.jboss.deployers.client.spi.Deployment;
-import org.jboss.deployers.spi.attachments.MutableAttachments;
-import org.jboss.deployers.structure.spi.DeploymentUnit;
-import org.jboss.deployers.structure.spi.main.MainDeployerStructure;
-import org.jboss.deployers.vfs.spi.client.VFSDeployment;
-import org.jboss.deployers.vfs.spi.client.VFSDeploymentFactory;
-import org.jboss.osgi.framework.bundle.AbstractBundleState;
-import org.jboss.osgi.framework.bundle.AbstractDeployedBundleState;
-import org.jboss.osgi.framework.bundle.OSGiBundleManager;
-import org.jboss.osgi.framework.bundle.OSGiBundleState;
-import org.jboss.osgi.framework.metadata.OSGiMetaData;
-import org.jboss.osgi.vfs.AbstractVFS;
-import org.jboss.test.kernel.junit.MicrocontainerTestDelegate;
-import org.jboss.virtual.AssembledDirectory;
-import org.jboss.virtual.VFS;
-import org.jboss.virtual.VirtualFile;
-import org.jboss.virtual.plugins.context.jar.JarUtils;
-import org.jboss.virtual.plugins.vfs.helpers.SuffixesExcludeFilter;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleException;
-
-/**
- * A OSGiTestDelegate
- *
- * @author <a href="baileyje(a)gmail.com">John Bailey</a>
- * @author Thomas.Diesler(a)jboss.com
- */
-public class FrameworkTestDelegate extends MicrocontainerTestDelegate
-{
- private OSGiBundleManager bundleManager;
-
- /**
- * Create a new OSGiTestDelegate.
- * @param clazz test class
- * @throws Exception for any error
- */
- FrameworkTestDelegate(Class<?> clazz) throws Exception
- {
- super(clazz);
- }
-
- /**
- * Deploys the jboss-osgi-bootstrap.xml bean descriptor to setup OSGi deployers
- */
- protected void deploy() throws Exception
- {
- String common = "/bootstrap/jboss-osgi-bootstrap.xml";
- URL url = getClass().getResource(common);
- if (url == null)
- throw new IllegalStateException(common + " not found");
- deploy(url);
- try
- {
- super.deploy();
- deployBundles();
- }
- catch (Throwable t)
- {
- undeploy();
- if (t instanceof Exception)
- throw (Exception)t;
- if (t instanceof Error)
- throw (Error)t;
- throw new RuntimeException("Error during deploy", t);
- }
- }
-
- protected void undeploy()
- {
- undeployBundles();
- super.undeploy();
- }
-
- @SuppressWarnings("unchecked")
- protected void deployBundles() throws Exception
- {
- try
- {
- Method method = clazz.getMethod("deployBundles", FrameworkTestDelegate.class);
- log.debug("Deploying Bundles...");
- method.invoke(null, this);
- }
- catch (NoSuchMethodException e)
- {
- log.debug("No deployBundles() in " + clazz.getName());
- }
- }
-
- protected void undeployBundles()
- {
- OSGiBundleManager bundleManager = getBundleManager();
- Collection<AbstractBundleState> bundles = bundleManager.getBundles();
- for (AbstractBundleState aux : bundles)
- {
- try
- {
- if (aux.getBundleId() != 0)
- {
- AbstractDeployedBundleState bundleState = (AbstractDeployedBundleState)aux;
- bundleManager.uninstallBundle(bundleState);
- }
- }
- catch (Throwable t)
- {
- getLog().warn("Error undeploying bundle: " + aux, t);
- }
- }
- }
-
- public OSGiBundleManager getBundleManager()
- {
- if (bundleManager == null)
- {
- bundleManager = getBean("OSGiBundleManager", ControllerState.INSTALLED, OSGiBundleManager.class);
- try
- {
- if (bundleManager.isFrameworkActive() == false)
- bundleManager.startFramework();
- }
- catch (BundleException ex)
- {
- throw new IllegalStateException("Cannot start bundle manager", ex);
- }
- }
- return bundleManager;
- }
-
- public DeployerClient getDeployerClient()
- {
- return getBundleManager().getDeployerClient();
- }
-
- /**
- * Create a bundle
- *
- * @param root the location to deploy
- * @param child the child to deploy
- * @return Bundle for the deployment
- * @throws Exception for any error
- */
- public Bundle addBundle(String root, String child) throws Exception
- {
- URL resourceRoot = getClass().getResource(root);
- if (resourceRoot == null)
- throw new AssertionFailedError("Resource not found: " + root);
- URL childResource = new URL(resourceRoot, child);
- AbstractBundleState bundleState = getBundleManager().installBundle(childResource);
- return bundleState.getBundleInternal();
- }
-
- /**
- * Create a bundle
- *
- * @param file the virtual file
- * @return Bundle for the deployment
- * @throws Exception for any error
- */
- public Bundle addBundle(VirtualFile file) throws Exception
- {
- AbstractBundleState bundleState = getBundleManager().installBundle(AbstractVFS.adapt(file));
- return bundleState.getBundleInternal();
- }
-
- /**
- * Remove a bundle
- *
- * @param bundle the bundle to remove
- * @throws Exception for any error
- */
- public void uninstall(Bundle bundle) throws Exception
- {
- if (bundle.getState() != Bundle.UNINSTALLED)
- {
- AbstractDeployedBundleState bundleState = OSGiBundleState.assertBundleState(bundle);
- getBundleManager().uninstallBundle(bundleState);
- }
- }
-
- public DeploymentUnit getDeploymentUnit(Bundle bundle)
- {
- DeploymentUnit deploymentUnit = getBundleManager().getDeployment(bundle.getBundleId());
- if (deploymentUnit == null)
- throw new AssertionFailedError("Bundle not installed: " + bundle);
- return deploymentUnit;
- }
-
- public VirtualFile assembleBundle(String name, String resources, Class<?>... packages) throws Exception
- {
- return assembleBundle(name, new String[] { resources }, packages);
- }
-
- public VirtualFile assembleBundle(String name, String[] resourcePaths, Class<?>... packages) throws Exception
- {
- AssembledDirectory assembledDirectory = createAssembledDirectory(name, "", resourcePaths, packages);
- return assembledDirectory;
- }
-
- public Bundle deployBundle(String name, OSGiMetaData metaData, String resourcePath, Class<?>... packages) throws Exception
- {
- AssembledDirectory assembledDirectory = createAssembledDirectory(name, "", new String[] { resourcePath }, packages);
- return deployBundle(assembledDirectory, metaData);
- }
-
- public Bundle deployBundle(String name, OSGiMetaData metaData, String[] resourcePaths, Class<?>... packages) throws Exception
- {
- AssembledDirectory assembledDirectory = createAssembledDirectory(name, "", resourcePaths, packages);
- return deployBundle(assembledDirectory, metaData);
- }
-
- public Bundle deployBundle(VirtualFile virtualFile, OSGiMetaData metaData) throws Exception
- {
- Deployment deployment = createDeployment(virtualFile, metaData);
- return deployBundle(deployment);
- }
-
- public Bundle deployBundle(String root, String child) throws Exception
- {
- URL resourceRoot = getClass().getResource(root);
- if (resourceRoot == null)
- throw new AssertionFailedError("Resource not found: " + root);
- URL childResource = new URL(resourceRoot, child);
- return deployBundle(childResource);
- }
-
- public Bundle deployBundle(URL url) throws Exception
- {
- // Get the root file
- VirtualFile root;
- try
- {
- root = VFS.getRoot(url);
- }
- catch (IOException e)
- {
- throw new BundleException("Invalid url=" + url, e);
- }
-
- return deployBundle(root);
- }
-
- public Bundle deployBundle(VirtualFile file) throws Exception
- {
- return deployBundle(file, null);
- }
-
- public Bundle deployBundle(Deployment deployment) throws Exception
- {
- DeployerClient deployerClient = getDeployerClient();
- MainDeployerStructure deployerStructure = (MainDeployerStructure) deployerClient;
- deployerClient.deploy(deployment);
- try
- {
- DeploymentUnit unit = deployerStructure.getDeploymentUnit(deployment.getName());
- AbstractBundleState bundleState = unit.getAttachment(AbstractBundleState.class);
- if (bundleState == null)
- throw new IllegalStateException("Unable to determine bundle state for " + deployment.getName());
-
- return bundleState.getBundleInternal();
- }
- catch (Exception e)
- {
- deployerClient.undeploy(deployment);
- throw e;
- }
- }
-
- public Deployment createDeployment(VirtualFile virtualFile) throws Exception
- {
- return createDeployment(virtualFile, null);
- }
-
- public Deployment createDeployment(VirtualFile virtualFile, OSGiMetaData metaData) throws Exception
- {
- return createDeployment(virtualFile, metaData, OSGiMetaData.class);
- }
-
- @SuppressWarnings({"unchecked"})
- public <T> Deployment createDeployment(VirtualFile virtualFile, T metaData, Class<T> expectedType) throws Exception
- {
- VFSDeployment deployment = VFSDeploymentFactory.getInstance().createVFSDeployment(virtualFile);
- if (metaData != null)
- {
- if (expectedType == null)
- expectedType = (Class<T>)metaData.getClass();
-
- MutableAttachments att = (MutableAttachments)deployment.getPredeterminedManagedObjects();
- att.addAttachment(expectedType, metaData);
- }
- return deployment;
- }
-
- public AssembledDirectory createAssembledDirectory(String name, String rootName, String[] resourcePaths, Class<?>... packages) throws Exception
- {
- AssembledDirectory assembledDirectory = createAssembledDirectory(name, rootName);
- if (resourcePaths != null)
- {
- for (String path : resourcePaths)
- addPath(assembledDirectory, path, "");
- }
- if (packages != null)
- {
- for (Class<?> reference : packages)
- addPackage(assembledDirectory, reference);
- }
- return assembledDirectory;
- }
-
- public AssembledDirectory createAssembledDirectory(String name) throws Exception
- {
- return createAssembledDirectory(name, "");
- }
-
- public AssembledDirectory createAssembledDirectory(String name, String rootName) throws Exception
- {
- return AssembledDirectory.createAssembledDirectory(name, rootName);
- }
-
- public void addPackage(AssembledDirectory dir, Class<?> reference) throws Exception
- {
- String packagePath = ClassLoaderUtils.packageNameToPath(reference.getName());
- dir.addResources(reference, new String[] { packagePath + "/*.class" }, new String[0]);
- }
-
- public void addPath(final AssembledDirectory dir, String path, String name) throws Exception
- {
- URL url = getClass().getResource(path);
- if (url == null)
- throw new AssertionFailedError(path + " not found");
-
- VirtualFile file = VFS.getVirtualFile(url, name);
- // TODO - remove this filter after new VFS relase
- SuffixesExcludeFilter noJars = new SuffixesExcludeFilter(JarUtils.getSuffixes());
- dir.addPath(file, noJars);
- }
-
- public URL getBundleResource(Bundle bundle, String path)
- {
- return getDeploymentUnit(bundle).getResourceLoader().getResource(path);
- }
-
- public Enumeration<URL> getBundleResources(Bundle bundle, String path) throws Exception
- {
- return getDeploymentUnit(bundle).getResourceLoader().getResources(path);
- }
-}
Deleted: 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 2010-03-10 16:06:33 UTC (rev 102228)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/NativeFrameworkTest.java 2010-03-10 16:12:51 UTC (rev 102229)
@@ -1,402 +0,0 @@
-/*
- * 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.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.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;
-import org.osgi.service.packageadmin.PackageAdmin;
-
-/**
- * Parent for native framework tests.
- *
- * @author Thomas.Diesler(a)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 PackageAdmin getPackageAdmin()
- {
- ServiceReference sref = context.getServiceReference(PackageAdmin.class.getName());
- return (PackageAdmin)context.getService(sref);
- }
-
- 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/bundle/BundleContextUnitTestCase.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/bundle/BundleContextUnitTestCase.java 2010-03-10 16:06:33 UTC (rev 102228)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/bundle/BundleContextUnitTestCase.java 2010-03-10 16:12:51 UTC (rev 102229)
@@ -39,7 +39,7 @@
import java.util.Set;
import org.jboss.osgi.vfs.VirtualFile;
-import org.jboss.test.osgi.NativeFrameworkTest;
+import org.jboss.test.osgi.AbstractFrameworkTest;
import org.junit.Test;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
@@ -57,12 +57,12 @@
* @author Thomas.Diesler(a)jboss.com
* @version $Revision: 1.1 $
*/
-public class BundleContextUnitTestCase extends NativeFrameworkTest
+public class BundleContextUnitTestCase extends AbstractFrameworkTest
{
@Test
public void testGetBundle() throws Exception
{
- VirtualFile assembly1 = assembleBundle("simple-bundle1", "/bundles/simple/simple-bundle1", new Class[0]);
+ VirtualFile assembly1 = assembleArchive("simple-bundle1", "/bundles/simple/simple-bundle1", new Class[0]);
Bundle bundle1 = context.installBundle(assembly1.toURL().toExternalForm());
BundleContext context1 = null;
try
@@ -77,7 +77,7 @@
Set<Bundle> expected = new HashSet<Bundle>(Arrays.asList(framework, bundle1));
assertEquals(expected, actual);
- VirtualFile assembly2 = assembleBundle("simple-bundle2", "/bundles/simple/simple-bundle2", new Class[0]);
+ VirtualFile assembly2 = assembleArchive("simple-bundle2", "/bundles/simple/simple-bundle2", new Class[0]);
Bundle bundle2 = context.installBundle(assembly2.toURL().toExternalForm());
BundleContext context2 = null;
try
@@ -176,7 +176,7 @@
@Test
public void testProperties() throws Exception
{
- VirtualFile assembly = assembleBundle("simple-bundle1", "/bundles/simple/simple-bundle1", new Class[0]);
+ VirtualFile assembly = assembleArchive("simple-bundle1", "/bundles/simple/simple-bundle1", new Class[0]);
Bundle bundle = context.installBundle(assembly.toURL().toExternalForm());
try
{
@@ -258,7 +258,7 @@
@Test
public void testServiceListener() throws Exception
{
- VirtualFile assembly = assembleBundle("simple-bundle1", "/bundles/simple/simple-bundle1", new Class[0]);
+ VirtualFile assembly = assembleArchive("simple-bundle1", "/bundles/simple/simple-bundle1", new Class[0]);
Bundle bundle = context.installBundle(assembly.toURL().toExternalForm());
try
{
@@ -351,7 +351,7 @@
@Test
public void testBundleListener() throws Exception
{
- VirtualFile assembly = assembleBundle("simple-bundle1", "/bundles/simple/simple-bundle1", new Class[0]);
+ VirtualFile assembly = assembleArchive("simple-bundle1", "/bundles/simple/simple-bundle1", new Class[0]);
Bundle bundle = context.installBundle(assembly.toURL().toExternalForm());
try
{
@@ -409,7 +409,7 @@
@Test
public void testFrameworkListener() throws Exception
{
- VirtualFile assembly = assembleBundle("simple-bundle1", "/bundles/simple/simple-bundle1", new Class[0]);
+ VirtualFile assembly = assembleArchive("simple-bundle1", "/bundles/simple/simple-bundle1", new Class[0]);
Bundle bundle = context.installBundle(assembly.toURL().toExternalForm());
try
{
@@ -448,7 +448,7 @@
@Test
public void testGetDataFile() throws Exception
{
- VirtualFile assembly = assembleBundle("simple-bundle1", "/bundles/simple/simple-bundle1", new Class[0]);
+ VirtualFile assembly = assembleArchive("simple-bundle1", "/bundles/simple/simple-bundle1", new Class[0]);
Bundle bundle = context.installBundle(assembly.toURL().toExternalForm());
try
{
@@ -469,7 +469,7 @@
@Test
public void testStopedBundleContext() throws Exception
{
- VirtualFile assembly = assembleBundle("simple-bundle1", "/bundles/simple/simple-bundle1", new Class[0]);
+ VirtualFile assembly = assembleArchive("simple-bundle1", "/bundles/simple/simple-bundle1", new Class[0]);
Bundle bundle = context.installBundle(assembly.toURL().toExternalForm());
try
{
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 16:06:33 UTC (rev 102228)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/bundle/BundleEntriesUnitTestCase.java 2010-03-10 16:12:51 UTC (rev 102229)
@@ -33,7 +33,7 @@
import java.util.Set;
import org.jboss.osgi.vfs.VirtualFile;
-import org.jboss.test.osgi.NativeFrameworkTest;
+import org.jboss.test.osgi.AbstractFrameworkTest;
import org.junit.Test;
import org.osgi.framework.Bundle;
@@ -46,12 +46,12 @@
* @author Thomas.Diesler(a)jboss.com
* @version $Revision: 1.1 $
*/
-public class BundleEntriesUnitTestCase extends NativeFrameworkTest
+public class BundleEntriesUnitTestCase extends AbstractFrameworkTest
{
@Test
public void testEntriesNotInstalled() throws Exception
{
- VirtualFile assembly = assembleBundle("entries-simple", "/bundles/entries/entries-simple", new Class[0]);
+ VirtualFile assembly = assembleArchive("entries-simple", "/bundles/entries/entries-simple", new Class[0]);
Bundle bundle = context.installBundle(assembly.toURL().toExternalForm());
bundle.uninstall();
try
@@ -77,7 +77,7 @@
@Test
public void testFindEntriesNoPath() throws Exception
{
- VirtualFile assembly = assembleBundle("entries-simple", "/bundles/entries/entries-simple", new Class[0]);
+ VirtualFile assembly = assembleArchive("entries-simple", "/bundles/entries/entries-simple", new Class[0]);
Bundle bundle = context.installBundle(assembly.toURL().toExternalForm());
try
{
@@ -97,7 +97,7 @@
@Test
public void testEntries() throws Exception
{
- VirtualFile assembly = assembleBundle("entries-simple", "/bundles/entries/entries-simple", new Class[0]);
+ VirtualFile assembly = assembleArchive("entries-simple", "/bundles/entries/entries-simple", new Class[0]);
Bundle bundle = context.installBundle(assembly.toURL().toExternalForm());
try
{
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 16:06:33 UTC (rev 102228)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/bundle/BundleLifecycleTestCase.java 2010-03-10 16:12:51 UTC (rev 102229)
@@ -27,7 +27,7 @@
import static org.junit.Assert.fail;
import org.jboss.osgi.vfs.VirtualFile;
-import org.jboss.test.osgi.NativeFrameworkTest;
+import org.jboss.test.osgi.AbstractFrameworkTest;
import org.jboss.test.osgi.bundle.support.a.FailOnStartActivator;
import org.jboss.test.osgi.bundle.support.b.LifecycleService;
import org.junit.Test;
@@ -42,7 +42,7 @@
* @author thomas.Diesler(a)jboss.com
* @since 15-Dec-2009
*/
-public class BundleLifecycleTestCase extends NativeFrameworkTest
+public class BundleLifecycleTestCase extends AbstractFrameworkTest
{
/**
@@ -51,7 +51,7 @@
@Test
public void testSimpleStart() throws Exception
{
- VirtualFile assemblyA = assembleBundle("lifecycle-service", "/bundles/lifecycle/simple-service", LifecycleService.class);
+ VirtualFile assemblyA = assembleArchive("lifecycle-service", "/bundles/lifecycle/simple-service", LifecycleService.class);
Bundle bundleA = context.installBundle(assemblyA.toURL().toExternalForm());
try
{
@@ -76,7 +76,7 @@
@Test
public void testDependencyNotAvailable() throws Exception
{
- VirtualFile assemblyA = assembleBundle("lifecycle-service", "/bundles/lifecycle/simple-service", LifecycleService.class);
+ VirtualFile assemblyA = assembleArchive("lifecycle-service", "/bundles/lifecycle/simple-service", LifecycleService.class);
Bundle bundleA = context.installBundle(assemblyA.toURL().toExternalForm());
try
{
@@ -86,7 +86,7 @@
ServiceReference sref = context.getServiceReference(LifecycleService.class.getName());
assertNull("Service not available", sref);
- VirtualFile assemblyB = assembleBundle("lifecycle-failstart", "/bundles/lifecycle/fail-on-start", FailOnStartActivator.class);
+ VirtualFile assemblyB = assembleArchive("lifecycle-failstart", "/bundles/lifecycle/fail-on-start", FailOnStartActivator.class);
Bundle bundleB = context.installBundle(assemblyB.toURL().toExternalForm());
try
{
@@ -118,14 +118,14 @@
@Test
public void testDependencyAvailable() throws Exception
{
- VirtualFile assemblyA = assembleBundle("lifecycle-service", "/bundles/lifecycle/simple-service", LifecycleService.class);
+ VirtualFile assemblyA = assembleArchive("lifecycle-service", "/bundles/lifecycle/simple-service", LifecycleService.class);
Bundle bundleA = context.installBundle(assemblyA.toURL().toExternalForm());
try
{
bundleA.start();
assertBundleState(Bundle.ACTIVE, bundleA.getState());
- VirtualFile assemblyB = assembleBundle("lifecycle-failstart", "/bundles/lifecycle/fail-on-start", FailOnStartActivator.class);
+ VirtualFile assemblyB = assembleArchive("lifecycle-failstart", "/bundles/lifecycle/fail-on-start", FailOnStartActivator.class);
Bundle bundleB = context.installBundle(assemblyB.toURL().toExternalForm());
try
{
@@ -151,13 +151,13 @@
@Test
public void testStartRetry() throws Exception
{
- VirtualFile assemblyA = assembleBundle("lifecycle-service", "/bundles/lifecycle/simple-service", LifecycleService.class);
+ VirtualFile assemblyA = assembleArchive("lifecycle-service", "/bundles/lifecycle/simple-service", LifecycleService.class);
Bundle bundleA = context.installBundle(assemblyA.toURL().toExternalForm());
try
{
assertBundleState(Bundle.INSTALLED, bundleA.getState());
- VirtualFile assemblyB = assembleBundle("lifecycle-failstart", "/bundles/lifecycle/fail-on-start", FailOnStartActivator.class);
+ VirtualFile assemblyB = assembleArchive("lifecycle-failstart", "/bundles/lifecycle/fail-on-start", FailOnStartActivator.class);
Bundle bundleB = context.installBundle(assemblyB.toURL().toExternalForm());
try
{
@@ -200,7 +200,7 @@
@Test
public void testFailToResolve() throws Exception
{
- VirtualFile assemblyA = assembleBundle("lifecycle-failstart", "/bundles/lifecycle/fail-on-start", FailOnStartActivator.class);
+ VirtualFile assemblyA = assembleArchive("lifecycle-failstart", "/bundles/lifecycle/fail-on-start", FailOnStartActivator.class);
Bundle bundleB = context.installBundle(assemblyA.toURL().toExternalForm());
try
{
@@ -232,7 +232,7 @@
{
try
{
- VirtualFile assembly = assembleBundle("missing-symbolic-name", "/bundles/lifecycle/invalid01");
+ VirtualFile assembly = assembleArchive("missing-symbolic-name", "/bundles/lifecycle/invalid01");
context.installBundle(assembly.toURL().toExternalForm());
fail("BundleException expected");
}
@@ -243,7 +243,7 @@
try
{
- VirtualFile assembly = assembleBundle("invalid-export", "/bundles/lifecycle/invalid02");
+ VirtualFile assembly = assembleArchive("invalid-export", "/bundles/lifecycle/invalid02");
context.installBundle(assembly.toURL().toExternalForm());
fail("BundleException expected");
}
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 16:06:33 UTC (rev 102228)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/bundle/BundleUnitTestCase.java 2010-03-10 16:12:51 UTC (rev 102229)
@@ -37,7 +37,7 @@
import org.jboss.osgi.vfs.VFSUtils;
import org.jboss.osgi.vfs.VirtualFile;
-import org.jboss.test.osgi.NativeFrameworkTest;
+import org.jboss.test.osgi.AbstractFrameworkTest;
import org.junit.Test;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
@@ -52,13 +52,13 @@
* @author Thomas.Diesler(a)jboss.com
* @version $Revision: 1.1 $
*/
-public class BundleUnitTestCase extends NativeFrameworkTest
+public class BundleUnitTestCase extends AbstractFrameworkTest
{
@Test
public void testBundleId() throws Exception
{
long id1 = -1;
- VirtualFile assembly = assembleBundle("simple-bundle1", "/bundles/simple/simple-bundle1", new Class[0]);
+ VirtualFile assembly = assembleArchive("simple-bundle1", "/bundles/simple/simple-bundle1", new Class[0]);
Bundle bundle = context.installBundle(assembly.toURL().toExternalForm());
try
{
@@ -87,7 +87,7 @@
@Test
public void testSymbolicName() throws Exception
{
- VirtualFile assembly = assembleBundle("simple-bundle1", "/bundles/simple/simple-bundle1", new Class[0]);
+ VirtualFile assembly = assembleArchive("simple-bundle1", "/bundles/simple/simple-bundle1", new Class[0]);
Bundle bundle = context.installBundle(assembly.toURL().toExternalForm());
try
{
@@ -103,7 +103,7 @@
@Test
public void testState() throws Exception
{
- VirtualFile assembly = assembleBundle("simple-bundle1", "/bundles/simple/simple-bundle1", new Class[0]);
+ VirtualFile assembly = assembleArchive("simple-bundle1", "/bundles/simple/simple-bundle1", new Class[0]);
Bundle bundle = context.installBundle(assembly.toURL().toExternalForm());
try
{
@@ -125,7 +125,7 @@
@Test
public void testGetBundleContext() throws Exception
{
- VirtualFile assembly = assembleBundle("simple-bundle1", "/bundles/simple/simple-bundle1", new Class[0]);
+ VirtualFile assembly = assembleArchive("simple-bundle1", "/bundles/simple/simple-bundle1", new Class[0]);
Bundle bundle = context.installBundle(assembly.toURL().toExternalForm());
try
{
@@ -161,8 +161,8 @@
@Test
public void testUpdate() throws Exception
{
- VirtualFile assemble1 = assembleBundle("bundle1", "/bundles/update/update-bundle1");
- VirtualFile assemble2 = assembleBundle("bundle2", "/bundles/update/update-bundle2");
+ VirtualFile assemble1 = assembleArchive("bundle1", "/bundles/update/update-bundle1");
+ VirtualFile assemble2 = assembleArchive("bundle2", "/bundles/update/update-bundle2");
Manifest manifest = VFSUtils.getManifest(assemble2);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
@@ -200,11 +200,11 @@
@Test
public void testSingleton() throws Exception
{
- VirtualFile assemblyA = assembleBundle("bundle10", "/bundles/singleton/singleton1");
+ VirtualFile assemblyA = assembleArchive("bundle10", "/bundles/singleton/singleton1");
Bundle bundleA = context.installBundle(assemblyA.toURL().toExternalForm());
try
{
- VirtualFile assemblyB = assembleBundle("bundle20", "/bundles/singleton/singleton2");
+ VirtualFile assemblyB = assembleArchive("bundle20", "/bundles/singleton/singleton2");
Bundle bundleB = context.installBundle(assemblyB.toURL().toExternalForm());
bundleB.uninstall();
fail("Should not be here!");
@@ -222,11 +222,11 @@
@Test
public void testNotSingleton() throws Exception
{
- VirtualFile assemblyA = assembleBundle("bundle1", "/bundles/singleton/singleton1");
+ VirtualFile assemblyA = assembleArchive("bundle1", "/bundles/singleton/singleton1");
Bundle bundleA = context.installBundle(assemblyA.toURL().toExternalForm());
try
{
- VirtualFile assemblyB = assembleBundle("not-singleton", "/bundles/singleton/not-singleton");
+ VirtualFile assemblyB = assembleArchive("not-singleton", "/bundles/singleton/not-singleton");
Bundle bundleB = context.installBundle(assemblyB.toURL().toExternalForm());
try
{
@@ -247,7 +247,7 @@
@SuppressWarnings({ "rawtypes", "unchecked" })
public void testGetHeaders() throws Exception
{
- VirtualFile assembly = assembleBundle("simple-bundle1", "/bundles/simple/simple-bundle1", new Class[0]);
+ VirtualFile assembly = assembleArchive("simple-bundle1", "/bundles/simple/simple-bundle1", new Class[0]);
Bundle bundle = context.installBundle(assembly.toURL().toExternalForm());
try
{
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 16:06:33 UTC (rev 102228)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/bundle/SystemBundleUnitTestCase.java 2010-03-10 16:12:51 UTC (rev 102229)
@@ -28,7 +28,7 @@
import java.util.Dictionary;
import java.util.Hashtable;
-import org.jboss.test.osgi.NativeFrameworkTest;
+import org.jboss.test.osgi.AbstractFrameworkTest;
import org.junit.Test;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleException;
@@ -42,7 +42,7 @@
* @author thomas.Diesler(a)jboss.com
* @version $Revision: 1.1 $
*/
-public class SystemBundleUnitTestCase extends NativeFrameworkTest
+public class SystemBundleUnitTestCase extends AbstractFrameworkTest
{
@Test
public void testBundleId() throws Exception
Modified: projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/classloader/RequireBundleUnitTestCase.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/classloader/RequireBundleUnitTestCase.java 2010-03-10 16:06:33 UTC (rev 102228)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/classloader/RequireBundleUnitTestCase.java 2010-03-10 16:12:51 UTC (rev 102229)
@@ -26,7 +26,7 @@
import static org.junit.Assert.fail;
import org.jboss.osgi.vfs.VirtualFile;
-import org.jboss.test.osgi.NativeFrameworkTest;
+import org.jboss.test.osgi.AbstractFrameworkTest;
import org.jboss.test.osgi.classloader.support.a.A;
import org.jboss.test.osgi.classloader.support.b.B;
import org.junit.Test;
@@ -41,18 +41,18 @@
* @author thomas.diesler(a)jboss.com
* @version $Revision: 1.1 $
*/
-public class RequireBundleUnitTestCase extends NativeFrameworkTest
+public class RequireBundleUnitTestCase extends AbstractFrameworkTest
{
@Test
public void testSimpleRequireBundle() throws Exception
{
- VirtualFile assemblyA = assembleBundle("bundleA", "/bundles/classloader/bundleA", A.class);
+ VirtualFile assemblyA = assembleArchive("bundleA", "/bundles/classloader/bundleA", A.class);
Bundle bundleA = context.installBundle(assemblyA.toURL().toExternalForm());
try
{
bundleA.start();
assertLoadClass(bundleA, A.class.getName());
- VirtualFile assemblyB = assembleBundle("simplerequirebundleA", "/bundles/classloader/simplerequirebundleA", B.class);
+ VirtualFile assemblyB = assembleArchive("simplerequirebundleA", "/bundles/classloader/simplerequirebundleA", B.class);
Bundle bundleB = context.installBundle(assemblyB.toURL().toExternalForm());
try
{
@@ -74,13 +74,13 @@
@Test
public void testSimpleRequireBundleFails() throws Exception
{
- VirtualFile assemblyA = assembleBundle("bundleA", "/bundles/classloader/bundleA", A.class);
+ VirtualFile assemblyA = assembleArchive("bundleA", "/bundles/classloader/bundleA", A.class);
Bundle bundleA = context.installBundle(assemblyA.toURL().toExternalForm());
try
{
bundleA.start();
assertLoadClass(bundleA, A.class.getName());
- VirtualFile assemblyB = assembleBundle("simplerequirebundlefails", "/bundles/classloader/simplerequirebundlefails", B.class);
+ VirtualFile assemblyB = assembleArchive("simplerequirebundlefails", "/bundles/classloader/simplerequirebundlefails", B.class);
Bundle bundleB = context.installBundle(assemblyB.toURL().toExternalForm());
try
{
@@ -105,13 +105,13 @@
@Test
public void testVersionRequireBundle() throws Exception
{
- VirtualFile assemblyA = assembleBundle("bundleA", "/bundles/classloader/bundleA", A.class);
+ VirtualFile assemblyA = assembleArchive("bundleA", "/bundles/classloader/bundleA", A.class);
Bundle bundleA = context.installBundle(assemblyA.toURL().toExternalForm());
try
{
bundleA.start();
assertLoadClass(bundleA, A.class.getName());
- VirtualFile assemblyB = assembleBundle("versionrequirebundleA", "/bundles/classloader/versionrequirebundleA", B.class);
+ VirtualFile assemblyB = assembleArchive("versionrequirebundleA", "/bundles/classloader/versionrequirebundleA", B.class);
Bundle bundleB = context.installBundle(assemblyB.toURL().toExternalForm());
try
{
@@ -133,13 +133,13 @@
@Test
public void testVersionRequireBundleFails() throws Exception
{
- VirtualFile assemblyA = assembleBundle("bundleA", "/bundles/classloader/bundleA", A.class);
+ VirtualFile assemblyA = assembleArchive("bundleA", "/bundles/classloader/bundleA", A.class);
Bundle bundleA = context.installBundle(assemblyA.toURL().toExternalForm());
try
{
bundleA.start();
assertLoadClass(bundleA, A.class.getName());
- VirtualFile assemblyB = assembleBundle("versionrequirebundlefails", "/bundles/classloader/versionrequirebundlefails", B.class);
+ VirtualFile assemblyB = assembleArchive("versionrequirebundlefails", "/bundles/classloader/versionrequirebundlefails", B.class);
Bundle bundleB = context.installBundle(assemblyB.toURL().toExternalForm());
try
{
@@ -164,13 +164,13 @@
@Test
public void testOptionalRequireBundle() throws Exception
{
- VirtualFile assemblyA = assembleBundle("bundleA", "/bundles/classloader/bundleA", A.class);
+ VirtualFile assemblyA = assembleArchive("bundleA", "/bundles/classloader/bundleA", A.class);
Bundle bundleA = context.installBundle(assemblyA.toURL().toExternalForm());
try
{
bundleA.start();
assertLoadClass(bundleA, A.class.getName());
- VirtualFile assemblyB = assembleBundle("optionalrequirebundleA", "/bundles/classloader/optionalrequirebundleA", B.class);
+ VirtualFile assemblyB = assembleArchive("optionalrequirebundleA", "/bundles/classloader/optionalrequirebundleA", B.class);
Bundle bundleB = context.installBundle(assemblyB.toURL().toExternalForm());
try
{
@@ -192,13 +192,13 @@
@Test
public void testOptionalRequireBundleFails() throws Exception
{
- VirtualFile assemblyA = assembleBundle("bundleA", "/bundles/classloader/bundleA", A.class);
+ VirtualFile assemblyA = assembleArchive("bundleA", "/bundles/classloader/bundleA", A.class);
Bundle bundleA = context.installBundle(assemblyA.toURL().toExternalForm());
try
{
bundleA.start();
assertLoadClass(bundleA, A.class.getName());
- VirtualFile assemblyB = assembleBundle("optionalrequirebundlefails", "/bundles/classloader/optionalrequirebundlefails", B.class);
+ VirtualFile assemblyB = assembleArchive("optionalrequirebundlefails", "/bundles/classloader/optionalrequirebundlefails", B.class);
Bundle bundleB = context.installBundle(assemblyB.toURL().toExternalForm());
try
{
@@ -224,7 +224,7 @@
//Bundle-Version: 1.0.0
//Bundle-SymbolicName: org.jboss.test.osgi.classloader.bundleA;test=x
//Export-Package: org.jboss.test.osgi.classloader.support.a;version=1.0.0;test=x
- VirtualFile assemblyA = assembleBundle("bundleA", "/bundles/classloader/bundleA", A.class);
+ VirtualFile assemblyA = assembleArchive("bundleA", "/bundles/classloader/bundleA", A.class);
Bundle bundleA = context.installBundle(assemblyA.toURL().toExternalForm());
try
@@ -236,7 +236,7 @@
//Bundle-SymbolicName: org.jboss.test.osgi.classloader.bundleB
//Require-Bundle: org.jboss.test.osgi.classloader.bundleA;visibility:=reexport
//Export-Package: org.jboss.test.osgi.classloader.support.b
- VirtualFile assemblyB = assembleBundle("reexportrequirebundleA", "/bundles/classloader/reexportrequirebundleA", B.class);
+ VirtualFile assemblyB = assembleArchive("reexportrequirebundleA", "/bundles/classloader/reexportrequirebundleA", B.class);
Bundle bundleB = context.installBundle(assemblyB.toURL().toExternalForm());
try
@@ -248,7 +248,7 @@
//Bundle-Name: BundleC
//Bundle-SymbolicName: org.jboss.test.osgi.classloader.bundleC
//Require-Bundle: org.jboss.test.osgi.classloader.bundleB
- VirtualFile assemblyC = assembleBundle("reexportrequirebundleB", "/bundles/classloader/reexportrequirebundleB");
+ VirtualFile assemblyC = assembleArchive("reexportrequirebundleB", "/bundles/classloader/reexportrequirebundleB");
Bundle bundleC = context.installBundle(assemblyC.toURL().toExternalForm());
try
@@ -275,20 +275,20 @@
@Test
public void testNoReExportRequireBundle() throws Exception
{
- VirtualFile assemblyA = assembleBundle("bundleA", "/bundles/classloader/bundleA", A.class);
+ VirtualFile assemblyA = assembleArchive("bundleA", "/bundles/classloader/bundleA", A.class);
Bundle bundleA = context.installBundle(assemblyA.toURL().toExternalForm());
try
{
bundleA.start();
assertLoadClass(bundleA, A.class.getName());
- VirtualFile assemblyB = assembleBundle("noreexportrequirebundleA", "/bundles/classloader/noreexportrequirebundleA", B.class);
+ VirtualFile assemblyB = assembleArchive("noreexportrequirebundleA", "/bundles/classloader/noreexportrequirebundleA", B.class);
Bundle bundleB = context.installBundle(assemblyB.toURL().toExternalForm());
try
{
bundleB.start();
assertLoadClass(bundleB, A.class.getName(), bundleA);
assertLoadClass(bundleB, B.class.getName(), bundleB);
- VirtualFile assemblyC = assembleBundle("reexportrequirebundleB", "/bundles/classloader/reexportrequirebundleB");
+ VirtualFile assemblyC = assembleArchive("reexportrequirebundleB", "/bundles/classloader/reexportrequirebundleB");
Bundle bundleC = context.installBundle(assemblyC.toURL().toExternalForm());
try
{
@@ -314,13 +314,13 @@
@Test
public void testAttributeRequireBundle() throws Exception
{
- VirtualFile assemblyA = assembleBundle("bundleA", "/bundles/classloader/bundleA", A.class);
+ VirtualFile assemblyA = assembleArchive("bundleA", "/bundles/classloader/bundleA", A.class);
Bundle bundleA = context.installBundle(assemblyA.toURL().toExternalForm());
try
{
bundleA.start();
assertLoadClass(bundleA, A.class.getName());
- VirtualFile assemblyB = assembleBundle("attributerequirebundleA", "/bundles/classloader/attributerequirebundleA", B.class);
+ VirtualFile assemblyB = assembleArchive("attributerequirebundleA", "/bundles/classloader/attributerequirebundleA", B.class);
Bundle bundleB = context.installBundle(assemblyB.toURL().toExternalForm());
try
{
@@ -345,7 +345,7 @@
// Bundle-SymbolicName: org.jboss.test.osgi.classloader.bundleA;test=x
// Export-Package: org.jboss.test.osgi.classloader.support.a;version=1.0.0;test=x
// Bundle-Version: 1.0.0
- VirtualFile assemblyA = assembleBundle("bundleA", "/bundles/classloader/bundleA", A.class);
+ VirtualFile assemblyA = assembleArchive("bundleA", "/bundles/classloader/bundleA", A.class);
Bundle bundleA = context.installBundle(assemblyA.toURL().toExternalForm());
try
{
@@ -354,7 +354,7 @@
// Bundle-SymbolicName: org.jboss.test.osgi.classloader.bundleB
// Require-Bundle: org.jboss.test.osgi.classloader.bundleA;doesnotexist=true;test=y
- VirtualFile assemblyB = assembleBundle("attributerequirebundlefails", "/bundles/classloader/attributerequirebundlefails", B.class);
+ VirtualFile assemblyB = assembleArchive("attributerequirebundlefails", "/bundles/classloader/attributerequirebundlefails", B.class);
Bundle bundleB = context.installBundle(assemblyB.toURL().toExternalForm());
try
{
Modified: projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/compendium/PackageAdminTestCase.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/compendium/PackageAdminTestCase.java 2010-03-10 16:06:33 UTC (rev 102228)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/compendium/PackageAdminTestCase.java 2010-03-10 16:12:51 UTC (rev 102229)
@@ -27,7 +27,7 @@
import static org.junit.Assert.assertSame;
import org.jboss.osgi.vfs.VirtualFile;
-import org.jboss.test.osgi.NativeFrameworkTest;
+import org.jboss.test.osgi.AbstractFrameworkTest;
import org.jboss.test.osgi.compendium.support.a.PA;
import org.jboss.test.osgi.compendium.support.b.Other;
import org.junit.Test;
@@ -40,12 +40,12 @@
* @author <a href="mailto:ales.justin@jboss.org">Ales Justin</a>
* @author thomas.diesler(a)jboss.com
*/
-public class PackageAdminTestCase extends NativeFrameworkTest
+public class PackageAdminTestCase extends AbstractFrameworkTest
{
@Test
public void testGetBudleFromClass() throws Exception
{
- VirtualFile assemblyA = assembleBundle("smoke-assembled", "/bundles/smoke/smoke-assembled", PA.class);
+ VirtualFile assemblyA = assembleArchive("smoke-assembled", "/bundles/smoke/smoke-assembled", PA.class);
Bundle bundleA = context.installBundle(assemblyA.toURL().toExternalForm());
try
{
@@ -60,7 +60,7 @@
Bundle notFound = pa.getBundle(getClass());
assertNull(notFound);
- VirtualFile assemblyB = assembleBundle("simple", "/bundles/simple/simple-bundle1", Other.class);
+ VirtualFile assemblyB = assembleArchive("simple", "/bundles/simple/simple-bundle1", Other.class);
Bundle bundleB = context.installBundle(assemblyB.toURL().toExternalForm());
try
{
Modified: projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/fragments/FragmentTestCase.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/fragments/FragmentTestCase.java 2010-03-10 16:06:33 UTC (rev 102228)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/fragments/FragmentTestCase.java 2010-03-10 16:12:51 UTC (rev 102229)
@@ -31,7 +31,7 @@
import org.jboss.osgi.spi.framework.OSGiBootstrap;
import org.jboss.osgi.spi.framework.OSGiBootstrapProvider;
-import org.jboss.test.osgi.NativeFrameworkTest;
+import org.jboss.test.osgi.AbstractFrameworkTest;
import org.jboss.test.osgi.fragments.fragA.FragBeanA;
import org.jboss.test.osgi.fragments.subA.SubBeanA;
import org.junit.After;
@@ -50,7 +50,7 @@
* @author thomas.diesler(a)jboss.com
* @since 07-Jan-2010
*/
-public class FragmentTestCase extends NativeFrameworkTest
+public class FragmentTestCase extends AbstractFrameworkTest
{
private Framework framework;
private BundleContext context;
Modified: projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/resolver/AbstractImportExportTest.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/resolver/AbstractImportExportTest.java 2010-03-10 16:06:33 UTC (rev 102228)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/resolver/AbstractImportExportTest.java 2010-03-10 16:12:51 UTC (rev 102229)
@@ -46,13 +46,13 @@
{
// Bundle-SymbolicName: simpleimport
// Import-Package: org.jboss.test.osgi.classloader.support.a
- VirtualFile fileA = assembleBundle("bundleA", "/bundles/resolver/simpleimport");
+ VirtualFile fileA = assembleArchive("bundleA", "/bundles/resolver/simpleimport");
Bundle bundleA = framework.installBundle(fileA);
try
{
// Bundle-SymbolicName: simpleexport
// Export-Package: org.jboss.test.osgi.classloader.support.a
- VirtualFile fileB = assembleBundle("bundleB", "/bundles/resolver/simpleexport", A.class);
+ VirtualFile fileB = assembleArchive("bundleB", "/bundles/resolver/simpleexport", A.class);
Bundle bundleB = framework.installBundle(fileB);
try
{
@@ -85,7 +85,7 @@
{
// Bundle-SymbolicName: simpleimport
// Import-Package: org.jboss.test.osgi.classloader.support.a
- VirtualFile fileA = assembleBundle("bundleA", "/bundles/resolver/simpleimport");
+ VirtualFile fileA = assembleArchive("bundleA", "/bundles/resolver/simpleimport");
Bundle bundleA = framework.installBundle(fileA);
try
{
@@ -111,13 +111,13 @@
{
// Bundle-SymbolicName: simpleimport
// Import-Package: org.jboss.test.osgi.classloader.support.a
- VirtualFile fileA = assembleBundle("bundleA", "/bundles/resolver/simpleimport");
+ VirtualFile fileA = assembleArchive("bundleA", "/bundles/resolver/simpleimport");
Bundle bundleA = framework.installBundle(fileA);
try
{
// Bundle-SymbolicName: simpleexport
// Export-Package: org.jboss.test.osgi.classloader.support.a
- VirtualFile fileB = assembleBundle("bundleB", "/bundles/resolver/simpleexport", A.class);
+ VirtualFile fileB = assembleArchive("bundleB", "/bundles/resolver/simpleexport", A.class);
Bundle bundleB = framework.installBundle(fileB);
try
{
@@ -154,7 +154,7 @@
// Bundle-SymbolicName: selfimport
// Export-Package: org.jboss.test.osgi.classloader.support.a
// Import-Package: org.jboss.test.osgi.classloader.support.a
- VirtualFile fileA = assembleBundle("bundleA", "/bundles/resolver/selfimport", A.class);
+ VirtualFile fileA = assembleArchive("bundleA", "/bundles/resolver/selfimport", A.class);
Bundle bundleA = framework.installBundle(fileA);
try
{
@@ -180,13 +180,13 @@
{
//Bundle-SymbolicName: packageimportversion
//Import-Package: org.jboss.test.osgi.classloader.support.a;version="[0.0.0,1.0.0]"
- VirtualFile fileA = assembleBundle("bundleA", "/bundles/resolver/packageimportversion");
+ VirtualFile fileA = assembleArchive("bundleA", "/bundles/resolver/packageimportversion");
Bundle bundleA = framework.installBundle(fileA);
try
{
//Bundle-SymbolicName: packageexportversion100
//Export-Package: org.jboss.test.osgi.classloader.support.a;version=1.0.0
- VirtualFile fileB = assembleBundle("bundleB", "/bundles/resolver/packageexportversion100", A.class);
+ VirtualFile fileB = assembleArchive("bundleB", "/bundles/resolver/packageexportversion100", A.class);
Bundle bundleB = framework.installBundle(fileB);
try
{
@@ -219,13 +219,13 @@
{
//Bundle-SymbolicName: packageimportversionfails
//Import-Package: org.jboss.test.osgi.classloader.support.a;version="[3.0,4.0)"
- VirtualFile fileA = assembleBundle("bundleA", "/bundles/resolver/packageimportversionfails");
+ VirtualFile fileA = assembleArchive("bundleA", "/bundles/resolver/packageimportversionfails");
Bundle bundleA = framework.installBundle(fileA);
try
{
//Bundle-SymbolicName: packageexportversion100
//Export-Package: org.jboss.test.osgi.classloader.support.a;version=1.0.0
- VirtualFile fileB = assembleBundle("bundleB", "/bundles/resolver/packageexportversion100", A.class);
+ VirtualFile fileB = assembleArchive("bundleB", "/bundles/resolver/packageexportversion100", A.class);
Bundle bundleB = framework.installBundle(fileB);
try
{
@@ -258,7 +258,7 @@
{
//Bundle-SymbolicName: packageimportoptional
//Import-Package: org.jboss.test.osgi.classloader.support.a;resolution:=optional
- VirtualFile fileA = assembleBundle("bundleA", "/bundles/resolver/packageimportoptional");
+ VirtualFile fileA = assembleArchive("bundleA", "/bundles/resolver/packageimportoptional");
Bundle bundleA = framework.installBundle(fileA);
try
{
@@ -284,13 +284,13 @@
{
//Bundle-SymbolicName: packageimportoptional
//Import-Package: org.jboss.test.osgi.classloader.support.a;resolution:=optional
- VirtualFile fileA = assembleBundle("bundleA", "/bundles/resolver/packageimportoptional");
+ VirtualFile fileA = assembleArchive("bundleA", "/bundles/resolver/packageimportoptional");
Bundle bundleA = framework.installBundle(fileA);
try
{
// Bundle-SymbolicName: simpleexport
// Export-Package: org.jboss.test.osgi.classloader.support.a
- VirtualFile fileB = assembleBundle("bundleB", "/bundles/resolver/simpleexport", A.class);
+ VirtualFile fileB = assembleArchive("bundleB", "/bundles/resolver/simpleexport", A.class);
Bundle bundleB = framework.installBundle(fileB);
try
{
@@ -323,7 +323,7 @@
{
//Bundle-SymbolicName: packageimportoptional
//Import-Package: org.jboss.test.osgi.classloader.support.a;resolution:=optional
- VirtualFile fileA = assembleBundle("bundleA", "/bundles/resolver/packageimportoptional");
+ VirtualFile fileA = assembleArchive("bundleA", "/bundles/resolver/packageimportoptional");
Bundle bundleA = framework.installBundle(fileA);
try
{
@@ -334,7 +334,7 @@
// Bundle-SymbolicName: simpleexport
// Export-Package: org.jboss.test.osgi.classloader.support.a
- VirtualFile fileB = assembleBundle("bundleB", "/bundles/resolver/simpleexport", A.class);
+ VirtualFile fileB = assembleArchive("bundleB", "/bundles/resolver/simpleexport", A.class);
Bundle bundleB = framework.installBundle(fileB);
try
{
@@ -367,13 +367,13 @@
{
//Bundle-SymbolicName: bundlenameimport
//Import-Package: org.jboss.test.osgi.classloader.support.a;bundle-symbolic-name=simpleexport
- VirtualFile fileA = assembleBundle("bundleA", "/bundles/resolver/bundlenameimport");
+ VirtualFile fileA = assembleArchive("bundleA", "/bundles/resolver/bundlenameimport");
Bundle bundleA = framework.installBundle(fileA);
try
{
//Bundle-SymbolicName: simpleexport
//Export-Package: org.jboss.test.osgi.classloader.support.a
- VirtualFile fileB = assembleBundle("bundleB", "/bundles/resolver/simpleexport", A.class);
+ VirtualFile fileB = assembleArchive("bundleB", "/bundles/resolver/simpleexport", A.class);
Bundle bundleB = framework.installBundle(fileB);
try
{
@@ -406,13 +406,13 @@
{
//Bundle-SymbolicName: bundlenameimport
//Import-Package: org.jboss.test.osgi.classloader.support.a;bundle-symbolic-name=simpleexport
- VirtualFile fileA = assembleBundle("bundleA", "/bundles/resolver/bundlenameimport");
+ VirtualFile fileA = assembleArchive("bundleA", "/bundles/resolver/bundlenameimport");
Bundle bundleA = framework.installBundle(fileA);
try
{
//Bundle-SymbolicName: sigleton;singleton:=true
//Export-Package: org.jboss.test.osgi.classloader.support.a
- VirtualFile fileB = assembleBundle("bundleB", "/bundles/resolver/singleton", A.class);
+ VirtualFile fileB = assembleArchive("bundleB", "/bundles/resolver/singleton", A.class);
Bundle bundleB = framework.installBundle(fileB);
try
{
@@ -445,13 +445,13 @@
{
//Bundle-SymbolicName: bundleversionimport
//Import-Package: org.jboss.test.osgi.classloader.support.a;bundle-version="[0.0.0,1.0.0)"
- VirtualFile fileA = assembleBundle("bundleA", "/bundles/resolver/bundleversionimport");
+ VirtualFile fileA = assembleArchive("bundleA", "/bundles/resolver/bundleversionimport");
Bundle bundleA = framework.installBundle(fileA);
try
{
// Bundle-SymbolicName: simpleexport
// Export-Package: org.jboss.test.osgi.classloader.support.a
- VirtualFile fileB = assembleBundle("bundleB", "/bundles/resolver/simpleexport", A.class);
+ VirtualFile fileB = assembleArchive("bundleB", "/bundles/resolver/simpleexport", A.class);
Bundle bundleB = framework.installBundle(fileB);
try
{
@@ -484,13 +484,13 @@
{
//Bundle-SymbolicName: bundleversionimportfails
//Import-Package: org.jboss.test.osgi.classloader.support.a;bundle-version="[1.0.0,2.0.0)"
- VirtualFile fileA = assembleBundle("bundleA", "/bundles/resolver/bundleversionimportfails");
+ VirtualFile fileA = assembleArchive("bundleA", "/bundles/resolver/bundleversionimportfails");
Bundle bundleA = framework.installBundle(fileA);
try
{
// Bundle-SymbolicName: simpleexport
// Export-Package: org.jboss.test.osgi.classloader.support.a
- VirtualFile fileB = assembleBundle("bundleB", "/bundles/resolver/simpleexport", A.class);
+ VirtualFile fileB = assembleArchive("bundleB", "/bundles/resolver/simpleexport", A.class);
Bundle bundleB = framework.installBundle(fileB);
try
{
@@ -524,13 +524,13 @@
{
//Bundle-SymbolicName: requirebundle
//Require-Bundle: simpleexport
- VirtualFile fileA = assembleBundle("bundleA", "/bundles/resolver/requirebundle");
+ VirtualFile fileA = assembleArchive("bundleA", "/bundles/resolver/requirebundle");
Bundle bundleA = framework.installBundle(fileA);
try
{
// Bundle-SymbolicName: simpleexport
// Export-Package: org.jboss.test.osgi.classloader.support.a
- VirtualFile fileB = assembleBundle("bundleB", "/bundles/resolver/simpleexport", A.class);
+ VirtualFile fileB = assembleArchive("bundleB", "/bundles/resolver/simpleexport", A.class);
Bundle bundleB = framework.installBundle(fileB);
try
{
@@ -563,7 +563,7 @@
{
//Bundle-SymbolicName: requirebundle
//Require-Bundle: simpleexport
- VirtualFile fileA = assembleBundle("bundleA", "/bundles/resolver/requirebundle");
+ VirtualFile fileA = assembleArchive("bundleA", "/bundles/resolver/requirebundle");
Bundle bundleA = framework.installBundle(fileA);
try
{
@@ -589,7 +589,7 @@
{
//Bundle-SymbolicName: requirebundleoptional
//Require-Bundle: simpleexport;resolution:=optional
- VirtualFile fileA = assembleBundle("bundleA", "/bundles/resolver/requirebundleoptional");
+ VirtualFile fileA = assembleArchive("bundleA", "/bundles/resolver/requirebundleoptional");
Bundle bundleA = framework.installBundle(fileA);
try
{
@@ -612,13 +612,13 @@
{
//Bundle-SymbolicName: requirebundleversion
//Require-Bundle: simpleexport;bundle-version="[0.0.0,1.0.0]"
- VirtualFile fileA = assembleBundle("bundleA", "/bundles/resolver/requirebundleversion");
+ VirtualFile fileA = assembleArchive("bundleA", "/bundles/resolver/requirebundleversion");
Bundle bundleA = framework.installBundle(fileA);
try
{
// Bundle-SymbolicName: simpleexport
// Export-Package: org.jboss.test.osgi.classloader.support.a
- VirtualFile fileB = assembleBundle("bundleB", "/bundles/resolver/simpleexport", A.class);
+ VirtualFile fileB = assembleArchive("bundleB", "/bundles/resolver/simpleexport", A.class);
Bundle bundleB = framework.installBundle(fileB);
try
{
@@ -651,13 +651,13 @@
{
//Bundle-SymbolicName: versionrequirebundlefails
//Require-Bundle: simpleexport;bundle-version="[1.0.0,2.0.0)"
- VirtualFile fileA = assembleBundle("bundleA", "/bundles/resolver/requirebundleversionfails");
+ VirtualFile fileA = assembleArchive("bundleA", "/bundles/resolver/requirebundleversionfails");
Bundle bundleA = framework.installBundle(fileA);
try
{
// Bundle-SymbolicName: simpleexport
// Export-Package: org.jboss.test.osgi.classloader.support.a
- VirtualFile fileB = assembleBundle("bundleB", "/bundles/resolver/simpleexport", A.class);
+ VirtualFile fileB = assembleArchive("bundleB", "/bundles/resolver/simpleexport", A.class);
Bundle bundleB = framework.installBundle(fileB);
try
{
@@ -690,15 +690,15 @@
{
// Bundle-SymbolicName: simpleexport
// Export-Package: org.jboss.test.osgi.classloader.support.a
- VirtualFile fileA = assembleBundle("bundleA", "/bundles/resolver/simpleexport", A.class);
+ VirtualFile fileA = assembleArchive("bundleA", "/bundles/resolver/simpleexport", A.class);
// Bundle-SymbolicName: simpleexportother
// Export-Package: org.jboss.test.osgi.classloader.support.a
- VirtualFile fileB = assembleBundle("bundleB", "/bundles/resolver/simpleexportother", A.class);
+ VirtualFile fileB = assembleArchive("bundleB", "/bundles/resolver/simpleexportother", A.class);
// Bundle-SymbolicName: simpleimport
// Import-Package: org.jboss.test.osgi.classloader.support.a
- VirtualFile fileC = assembleBundle("bundleC", "/bundles/resolver/simpleimport");
+ VirtualFile fileC = assembleArchive("bundleC", "/bundles/resolver/simpleimport");
Bundle bundleA = framework.installBundle(fileA);
try
@@ -750,15 +750,15 @@
{
// Bundle-SymbolicName: simpleexport
// Export-Package: org.jboss.test.osgi.classloader.support.a
- VirtualFile fileA = assembleBundle("bundleA", "/bundles/resolver/simpleexport", A.class);
+ VirtualFile fileA = assembleArchive("bundleA", "/bundles/resolver/simpleexport", A.class);
// Bundle-SymbolicName: simpleexportother
// Export-Package: org.jboss.test.osgi.classloader.support.a
- VirtualFile fileB = assembleBundle("bundleB", "/bundles/resolver/simpleexportother", A.class);
+ VirtualFile fileB = assembleArchive("bundleB", "/bundles/resolver/simpleexportother", A.class);
// Bundle-SymbolicName: simpleimport
// Import-Package: org.jboss.test.osgi.classloader.support.a
- VirtualFile fileC = assembleBundle("bundleC", "/bundles/resolver/simpleimport");
+ VirtualFile fileC = assembleArchive("bundleC", "/bundles/resolver/simpleimport");
Bundle bundleB = framework.installBundle(fileB);
try
@@ -810,15 +810,15 @@
{
//Bundle-SymbolicName: packageexportversion100
//Export-Package: org.jboss.test.osgi.classloader.support.a;version=1.0.0
- VirtualFile fileA = assembleBundle("bundleA", "/bundles/resolver/packageexportversion100", A.class);
+ VirtualFile fileA = assembleArchive("bundleA", "/bundles/resolver/packageexportversion100", A.class);
//Bundle-SymbolicName: packageexportversion200
//Export-Package: org.jboss.test.osgi.classloader.support.a;version=2.0.0
- VirtualFile fileB = assembleBundle("bundleB", "/bundles/resolver/packageexportversion200", A.class);
+ VirtualFile fileB = assembleArchive("bundleB", "/bundles/resolver/packageexportversion200", A.class);
// Bundle-SymbolicName: simpleimport
// Import-Package: org.jboss.test.osgi.classloader.support.a
- VirtualFile fileC = assembleBundle("bundleC", "/bundles/resolver/simpleimport");
+ VirtualFile fileC = assembleArchive("bundleC", "/bundles/resolver/simpleimport");
Bundle bundleA = framework.installBundle(fileA);
try
@@ -865,15 +865,15 @@
{
//Bundle-SymbolicName: packageexportversion200
//Export-Package: org.jboss.test.osgi.classloader.support.a;version=2.0.0
- VirtualFile fileA = assembleBundle("bundleA", "/bundles/resolver/packageexportversion200", A.class);
+ VirtualFile fileA = assembleArchive("bundleA", "/bundles/resolver/packageexportversion200", A.class);
//Bundle-SymbolicName: packageexportversion100
//Export-Package: org.jboss.test.osgi.classloader.support.a;version=1.0.0
- VirtualFile fileB = assembleBundle("bundleB", "/bundles/resolver/packageexportversion100", A.class);
+ VirtualFile fileB = assembleArchive("bundleB", "/bundles/resolver/packageexportversion100", A.class);
// Bundle-SymbolicName: simpleimport
// Import-Package: org.jboss.test.osgi.classloader.support.a
- VirtualFile fileC = assembleBundle("bundleC", "/bundles/resolver/simpleimport");
+ VirtualFile fileC = assembleArchive("bundleC", "/bundles/resolver/simpleimport");
Bundle bundleA = framework.installBundle(fileA);
try
@@ -920,15 +920,15 @@
{
// Bundle-SymbolicName: simpleexport
// Export-Package: org.jboss.test.osgi.classloader.support.a
- VirtualFile fileA = assembleBundle("bundleA", "/bundles/resolver/simpleexport", A.class);
+ VirtualFile fileA = assembleArchive("bundleA", "/bundles/resolver/simpleexport", A.class);
// Bundle-SymbolicName: simpleexportother
// Export-Package: org.jboss.test.osgi.classloader.support.a
- VirtualFile fileB = assembleBundle("bundleB", "/bundles/resolver/simpleexportother", A.class);
+ VirtualFile fileB = assembleArchive("bundleB", "/bundles/resolver/simpleexportother", A.class);
// Bundle-SymbolicName: simpleimport
// Import-Package: org.jboss.test.osgi.classloader.support.a
- VirtualFile fileC = assembleBundle("bundleC", "/bundles/resolver/simpleimport");
+ VirtualFile fileC = assembleArchive("bundleC", "/bundles/resolver/simpleimport");
Bundle bundleA = framework.installBundle(fileA);
try
@@ -980,15 +980,15 @@
{
// Bundle-SymbolicName: simpleexportother
// Export-Package: org.jboss.test.osgi.classloader.support.a
- VirtualFile fileA = assembleBundle("bundleA", "/bundles/resolver/simpleexportother", A.class);
+ VirtualFile fileA = assembleArchive("bundleA", "/bundles/resolver/simpleexportother", A.class);
// Bundle-SymbolicName: simpleexport
// Export-Package: org.jboss.test.osgi.classloader.support.a
- VirtualFile fileB = assembleBundle("bundleB", "/bundles/resolver/simpleexport", A.class);
+ VirtualFile fileB = assembleArchive("bundleB", "/bundles/resolver/simpleexport", A.class);
// Bundle-SymbolicName: simpleimport
// Import-Package: org.jboss.test.osgi.classloader.support.a
- VirtualFile fileC = assembleBundle("bundleC", "/bundles/resolver/simpleimport");
+ VirtualFile fileC = assembleArchive("bundleC", "/bundles/resolver/simpleimport");
Bundle bundleA = framework.installBundle(fileA);
try
@@ -1040,13 +1040,13 @@
{
//Bundle-SymbolicName: packageexportattribute
//Export-Package: org.jboss.test.osgi.classloader.support.a;test=x
- VirtualFile fileA = assembleBundle("bundleA", "/bundles/resolver/packageexportattribute", A.class);
+ VirtualFile fileA = assembleArchive("bundleA", "/bundles/resolver/packageexportattribute", A.class);
Bundle bundleA = framework.installBundle(fileA);
try
{
//Bundle-SymbolicName: simpleimport
//Import-Package: org.jboss.test.osgi.classloader.support.a
- VirtualFile fileB = assembleBundle("bundleB", "/bundles/resolver/simpleimport");
+ VirtualFile fileB = assembleArchive("bundleB", "/bundles/resolver/simpleimport");
Bundle bundleB = framework.installBundle(fileB);
try
{
@@ -1070,7 +1070,7 @@
//Bundle-SymbolicName: packageimportattribute
//Import-Package: org.jboss.test.osgi.classloader.support.a;test=x
- fileB = assembleBundle("bundleB", "/bundles/resolver/packageimportattribute");
+ fileB = assembleArchive("bundleB", "/bundles/resolver/packageimportattribute");
bundleB = framework.installBundle(fileB);
try
{
@@ -1103,13 +1103,13 @@
{
//Bundle-SymbolicName: packageexportattribute
//Export-Package: org.jboss.test.osgi.classloader.support.a;test=x
- VirtualFile fileA = assembleBundle("bundleA", "/bundles/resolver/packageexportattribute", A.class);
+ VirtualFile fileA = assembleArchive("bundleA", "/bundles/resolver/packageexportattribute", A.class);
Bundle bundleA = framework.installBundle(fileA);
try
{
//Bundle-SymbolicName: packageimportattributefails
//Import-Package: org.jboss.test.osgi.classloader.support.a;test=y
- VirtualFile fileB = assembleBundle("bundleB", "/bundles/resolver/packageimportattributefails");
+ VirtualFile fileB = assembleArchive("bundleB", "/bundles/resolver/packageimportattributefails");
Bundle bundleB = framework.installBundle(fileB);
try
{
@@ -1142,13 +1142,13 @@
{
//Bundle-SymbolicName: packageexportattributemandatory
//Export-Package: org.jboss.test.osgi.classloader.support.a;test=x;mandatory:=test
- VirtualFile fileA = assembleBundle("bundleA", "/bundles/resolver/packageexportattributemandatory", A.class);
+ VirtualFile fileA = assembleArchive("bundleA", "/bundles/resolver/packageexportattributemandatory", A.class);
Bundle bundleA = framework.installBundle(fileA);
try
{
//Bundle-SymbolicName: packageimportattribute
//Import-Package: org.jboss.test.osgi.classloader.support.a;test=x
- VirtualFile fileB = assembleBundle("bundleB", "/bundles/resolver/packageimportattribute");
+ VirtualFile fileB = assembleArchive("bundleB", "/bundles/resolver/packageimportattribute");
Bundle bundleB = framework.installBundle(fileB);
try
{
@@ -1181,13 +1181,13 @@
{
//Bundle-SymbolicName: packageexportattributemandatory
//Export-Package: org.jboss.test.osgi.classloader.support.a;test=x;mandatory:=test
- VirtualFile fileA = assembleBundle("bundleA", "/bundles/resolver/packageexportattributemandatory", A.class);
+ VirtualFile fileA = assembleArchive("bundleA", "/bundles/resolver/packageexportattributemandatory", A.class);
Bundle bundleA = framework.installBundle(fileA);
try
{
//Bundle-SymbolicName: simpleimport
//Import-Package: org.jboss.test.osgi.classloader.support.a
- VirtualFile fileB = assembleBundle("bundleB", "/bundles/resolver/simpleimport");
+ VirtualFile fileB = assembleArchive("bundleB", "/bundles/resolver/simpleimport");
Bundle bundleB = framework.installBundle(fileB);
try
{
@@ -1220,7 +1220,7 @@
{
//Bundle-SymbolicName: systempackageimport
//Import-Package: org.osgi.framework;version=1.4
- VirtualFile fileA = assembleBundle("bundleA", "/bundles/resolver/systempackageimport");
+ VirtualFile fileA = assembleArchive("bundleA", "/bundles/resolver/systempackageimport");
Bundle bundleA = framework.installBundle(fileA);
try
{
Modified: projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/resolver/ResolverMetadataTest.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/resolver/ResolverMetadataTest.java 2010-03-10 16:06:33 UTC (rev 102228)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/resolver/ResolverMetadataTest.java 2010-03-10 16:12:51 UTC (rev 102229)
@@ -60,7 +60,7 @@
// Bundle-SymbolicName: simpleexport
// Export-Package: org.jboss.test.osgi.classloader.support.a
- VirtualFile fileA = assembleBundle("bundleA", "/bundles/resolver/simpleexport", A.class);
+ VirtualFile fileA = assembleArchive("bundleA", "/bundles/resolver/simpleexport", A.class);
Bundle bundleA = framework.installBundle(fileA);
try
{
@@ -115,7 +115,7 @@
// Bundle-SymbolicName: simpleimport
// Import-Package: org.jboss.test.osgi.classloader.support.a
- VirtualFile fileA = assembleBundle("bundleA", "/bundles/resolver/simpleimport");
+ VirtualFile fileA = assembleArchive("bundleA", "/bundles/resolver/simpleimport");
Bundle bundleA = framework.installBundle(fileA);
try
{
@@ -148,7 +148,7 @@
// Bundle-SymbolicName: singleton;singleton:=true
// Export-Package: org.jboss.test.osgi.classloader.support.a
- VirtualFile fileA = assembleBundle("bundleA", "/bundles/resolver/singleton", A.class);
+ VirtualFile fileA = assembleArchive("bundleA", "/bundles/resolver/singleton", A.class);
Bundle bundleA = framework.installBundle(fileA);
try
{
@@ -170,7 +170,7 @@
//Bundle-SymbolicName: requirebundle
//Require-Bundle: simpleexport
- VirtualFile fileA = assembleBundle("bundleA", "/bundles/resolver/requirebundle");
+ VirtualFile fileA = assembleArchive("bundleA", "/bundles/resolver/requirebundle");
Bundle bundleA = framework.installBundle(fileA);
try
{
@@ -197,7 +197,7 @@
//Bundle-SymbolicName: requirebundle
//Require-Bundle: simpleexport;resolution:=optional
- VirtualFile fileA = assembleBundle("bundleA", "/bundles/resolver/requirebundleoptional");
+ VirtualFile fileA = assembleArchive("bundleA", "/bundles/resolver/requirebundleoptional");
Bundle bundleA = framework.installBundle(fileA);
try
{
@@ -224,7 +224,7 @@
//Bundle-SymbolicName: requirebundle
//Require-Bundle: simpleexport;bundle-version="[0.0.0,1.0.0]"
- VirtualFile fileA = assembleBundle("bundleA", "/bundles/resolver/requirebundleversion");
+ VirtualFile fileA = assembleArchive("bundleA", "/bundles/resolver/requirebundleversion");
Bundle bundleA = framework.installBundle(fileA);
try
{
@@ -251,7 +251,7 @@
//Bundle-SymbolicName: packageexportattribute
//Export-Package: org.jboss.test.osgi.classloader.support.a;test=x
- VirtualFile fileA = assembleBundle("bundleA", "/bundles/resolver/packageexportattribute");
+ VirtualFile fileA = assembleArchive("bundleA", "/bundles/resolver/packageexportattribute");
Bundle bundleA = framework.installBundle(fileA);
try
{
@@ -263,7 +263,7 @@
//Bundle-SymbolicName: simpleimport
//Import-Package: org.jboss.test.osgi.classloader.support.a
- VirtualFile fileB = assembleBundle("bundleB", "/bundles/resolver/simpleimport");
+ VirtualFile fileB = assembleArchive("bundleB", "/bundles/resolver/simpleimport");
Bundle bundleB = framework.installBundle(fileB);
try
{
@@ -278,7 +278,7 @@
//Bundle-SymbolicName: packageimportattribute
//Import-Package: org.jboss.test.osgi.classloader.support.a;test=x
- fileB = assembleBundle("bundleB", "/bundles/resolver/packageimportattribute");
+ fileB = assembleArchive("bundleB", "/bundles/resolver/packageimportattribute");
bundleB = framework.installBundle(fileB);
try
{
@@ -309,7 +309,7 @@
//Bundle-SymbolicName: packageexportattribute
//Export-Package: org.jboss.test.osgi.classloader.support.a;test=x
- VirtualFile fileA = assembleBundle("bundleA", "/bundles/resolver/packageexportattribute");
+ VirtualFile fileA = assembleArchive("bundleA", "/bundles/resolver/packageexportattribute");
Bundle bundleA = framework.installBundle(fileA);
try
{
@@ -321,7 +321,7 @@
//Bundle-SymbolicName: packageimportattributefails
//Import-Package: org.jboss.test.osgi.classloader.support.a;test=y
- VirtualFile fileB = assembleBundle("bundleB", "/bundles/resolver/packageimportattributefails");
+ VirtualFile fileB = assembleArchive("bundleB", "/bundles/resolver/packageimportattributefails");
Bundle bundleB = framework.installBundle(fileB);
try
{
@@ -352,7 +352,7 @@
//Bundle-SymbolicName: packageexportattributemandatory
//Export-Package: org.jboss.test.osgi.classloader.support.a;test=x;mandatory:=test
- VirtualFile fileA = assembleBundle("bundleA", "/bundles/resolver/packageexportattributemandatory");
+ VirtualFile fileA = assembleArchive("bundleA", "/bundles/resolver/packageexportattributemandatory");
Bundle bundleA = framework.installBundle(fileA);
try
{
@@ -366,7 +366,7 @@
//Bundle-SymbolicName: packageimportattribute
//Import-Package: org.jboss.test.osgi.classloader.support.a;test=x
- VirtualFile fileB = assembleBundle("bundleB", "/bundles/resolver/packageimportattribute");
+ VirtualFile fileB = assembleArchive("bundleB", "/bundles/resolver/packageimportattribute");
Bundle bundleB = framework.installBundle(fileB);
try
{
@@ -397,7 +397,7 @@
//Bundle-SymbolicName: packageexportattributemandatory
//Export-Package: org.jboss.test.osgi.classloader.support.a;test=x;mandatory:=test
- VirtualFile fileA = assembleBundle("bundleA", "/bundles/resolver/packageexportattributemandatory");
+ VirtualFile fileA = assembleArchive("bundleA", "/bundles/resolver/packageexportattributemandatory");
Bundle bundleA = framework.installBundle(fileA);
try
{
@@ -411,7 +411,7 @@
//Bundle-SymbolicName: simpleimport
//Import-Package: org.jboss.test.osgi.classloader.support.a
- VirtualFile fileB = assembleBundle("bundleB", "/bundles/resolver/simpleimport");
+ VirtualFile fileB = assembleArchive("bundleB", "/bundles/resolver/simpleimport");
Bundle bundleB = framework.installBundle(fileB);
try
{
@@ -426,7 +426,7 @@
//Bundle-SymbolicName: packageimportattributefails
//Import-Package: org.jboss.test.osgi.classloader.support.a;test=y
- fileB = assembleBundle("bundleB", "/bundles/resolver/packageimportattributefails");
+ fileB = assembleArchive("bundleB", "/bundles/resolver/packageimportattributefails");
bundleB = framework.installBundle(fileB);
try
{
Added: projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/service/AbstractServiceMixTest.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/service/AbstractServiceMixTest.java (rev 0)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/service/AbstractServiceMixTest.java 2010-03-10 16:12:51 UTC (rev 102229)
@@ -0,0 +1,69 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.service;
+
+import static org.junit.Assert.assertNotNull;
+
+import java.lang.reflect.Method;
+
+import org.jboss.deployers.client.spi.Deployment;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.osgi.framework.bundle.AbstractBundleState;
+import org.jboss.test.osgi.AbstractDeploymentTest;
+import org.osgi.framework.Bundle;
+
+/**
+ * Test MC's services.
+ *
+ * @author <a href="mailto:ales.justin@jboss.org">Ales Justin</a>
+ */
+public abstract class AbstractServiceMixTest extends AbstractDeploymentTest
+{
+ protected static Object getter(Object target, String getter, String name) throws Throwable
+ {
+ assertNotNull("Target " + name + " is not null", target);
+ Class<?> clazz = target.getClass();
+ Method m = clazz.getDeclaredMethod(getter);
+ return m.invoke(target);
+ }
+
+ protected static Object setter(Object target, String setter, Object value, String name) throws Throwable
+ {
+ assertNotNull("Target " + name + " is not null", target);
+ assertNotNull("Value is not null", value);
+ Class<?> clazz = target.getClass();
+ Method m = clazz.getDeclaredMethod(setter, value.getClass());
+ return m.invoke(target, value);
+ }
+
+ protected Bundle getBundle(Deployment deployment) throws Exception
+ {
+ return getBundle(getDeploymentUnit(deployment));
+ }
+
+ protected Bundle getBundle(DeploymentUnit unit) throws Exception
+ {
+ AbstractBundleState bundle = unit.getAttachment(AbstractBundleState.class);
+ assertNotNull(bundle);
+ return bundle.getBundleInternal();
+ }
+}
\ No newline at end of file
Modified: projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/service/GetServiceReferencesUnitTestCase.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/service/GetServiceReferencesUnitTestCase.java 2010-03-10 16:06:33 UTC (rev 102228)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/service/GetServiceReferencesUnitTestCase.java 2010-03-10 16:12:51 UTC (rev 102229)
@@ -29,7 +29,7 @@
import java.util.Hashtable;
import org.jboss.osgi.vfs.VirtualFile;
-import org.jboss.test.osgi.NativeFrameworkTest;
+import org.jboss.test.osgi.AbstractFrameworkTest;
import org.jboss.test.osgi.service.support.a.A;
import org.jboss.test.osgi.service.support.b.B;
import org.junit.Test;
@@ -48,13 +48,13 @@
* @author thomas.diesler(a)jboss.com
* @version $Revision: 1.1 $
*/
-public class GetServiceReferencesUnitTestCase extends NativeFrameworkTest
+public class GetServiceReferencesUnitTestCase extends AbstractFrameworkTest
{
@Test
public void testGetServiceReferences() throws Exception
{
- VirtualFile assembly = assembleBundle("simple1", "/bundles/simple/simple-bundle1", A.class);
+ VirtualFile assembly = assembleArchive("simple1", "/bundles/simple/simple-bundle1", A.class);
Bundle bundle = context.installBundle(assembly.toURL().toExternalForm());
try
{
@@ -174,7 +174,7 @@
private void assertGetServiceReferencesNotAssignable(String className) throws Exception
{
- VirtualFile assemblyA = assembleBundle("simple1", "/bundles/simple/simple-bundle1", A.class);
+ VirtualFile assemblyA = assembleArchive("simple1", "/bundles/simple/simple-bundle1", A.class);
Bundle bundleA = context.installBundle(assemblyA.toURL().toExternalForm());
try
{
@@ -192,7 +192,7 @@
ServiceReference reference1 = registration1.getReference();
assertNotNull(reference1);
- VirtualFile assemblyB = assembleBundle("simple2", "/bundles/simple/simple-bundle2", A.class);
+ VirtualFile assemblyB = assembleArchive("simple2", "/bundles/simple/simple-bundle2", A.class);
Bundle bundleB = context.installBundle(assemblyB.toURL().toExternalForm());
try
{
@@ -276,7 +276,7 @@
private void assertGetServiceReferencesAssignable(String className) throws Exception
{
- VirtualFile assemblyA = assembleBundle("service2", "/bundles/service/service-bundle2", A.class);
+ VirtualFile assemblyA = assembleArchive("service2", "/bundles/service/service-bundle2", A.class);
Bundle bundleA = context.installBundle(assemblyA.toURL().toExternalForm());
try
{
@@ -294,7 +294,7 @@
ServiceReference reference1 = registration1.getReference();
assertNotNull(reference1);
- VirtualFile assemblyB = assembleBundle("service1", "/bundles/service/service-bundle1");
+ VirtualFile assemblyB = assembleArchive("service1", "/bundles/service/service-bundle1");
Bundle bundleB = context.installBundle(assemblyB.toURL().toExternalForm());
try
{
@@ -369,7 +369,7 @@
{
String className = A.class.getName();
- VirtualFile assemblyA = assembleBundle("service2", "/bundles/service/service-bundle2", A.class);
+ VirtualFile assemblyA = assembleArchive("service2", "/bundles/service/service-bundle2", A.class);
Bundle bundleA = context.installBundle(assemblyA.toURL().toExternalForm());
try
{
@@ -390,7 +390,7 @@
ServiceReference reference1 = registration1.getReference();
assertNotNull(reference1);
- VirtualFile assemblyB = assembleBundle("service1", "/bundles/service/service-bundle1");
+ VirtualFile assemblyB = assembleArchive("service1", "/bundles/service/service-bundle1");
Bundle bundleB = context.installBundle(assemblyB.toURL().toExternalForm());
try
{
@@ -480,7 +480,7 @@
String className = A.class.getName();
String wrongClassName = B.class.getName();
- VirtualFile assembly = assembleBundle("simple1", "/bundles/simple/simple-bundle1", A.class);
+ VirtualFile assembly = assembleArchive("simple1", "/bundles/simple/simple-bundle1", A.class);
Bundle bundle = context.installBundle(assembly.toURL().toExternalForm());
try
{
Modified: projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/service/GetUnGetServiceUnitTestCase.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/service/GetUnGetServiceUnitTestCase.java 2010-03-10 16:06:33 UTC (rev 102228)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/service/GetUnGetServiceUnitTestCase.java 2010-03-10 16:12:51 UTC (rev 102229)
@@ -24,7 +24,7 @@
import static org.junit.Assert.*;
import org.jboss.osgi.vfs.VirtualFile;
-import org.jboss.test.osgi.NativeFrameworkTest;
+import org.jboss.test.osgi.AbstractFrameworkTest;
import org.jboss.test.osgi.service.support.BrokenServiceFactory;
import org.junit.Test;
import org.osgi.framework.Bundle;
@@ -41,14 +41,14 @@
* @author <a href="ales.justin(a)jboss.org">Ales Justin</a>
* @version $Revision: 1.1 $
*/
-public class GetUnGetServiceUnitTestCase extends NativeFrameworkTest
+public class GetUnGetServiceUnitTestCase extends AbstractFrameworkTest
{
static String OBJCLASS = BundleContext.class.getName();
@Test
public void testGetUnServiceErrors() throws Exception
{
- VirtualFile assembly = assembleBundle("simple-bundle1", "/bundles/simple/simple-bundle1", new Class[0]);
+ VirtualFile assembly = assembleArchive("simple-bundle1", "/bundles/simple/simple-bundle1", new Class[0]);
Bundle bundle = context.installBundle(assembly.toURL().toExternalForm());
try
{
@@ -87,7 +87,7 @@
@Test
public void testGetService() throws Exception
{
- VirtualFile assembly = assembleBundle("simple-bundle1", "/bundles/simple/simple-bundle1", new Class[0]);
+ VirtualFile assembly = assembleArchive("simple-bundle1", "/bundles/simple/simple-bundle1", new Class[0]);
Bundle bundle = context.installBundle(assembly.toURL().toExternalForm());
try
{
@@ -114,7 +114,7 @@
@Test
public void testGetServiceAfterStop() throws Exception
{
- VirtualFile assembly = assembleBundle("simple-bundle1", "/bundles/simple/simple-bundle1", new Class[0]);
+ VirtualFile assembly = assembleArchive("simple-bundle1", "/bundles/simple/simple-bundle1", new Class[0]);
Bundle bundle = context.installBundle(assembly.toURL().toExternalForm());
try
{
@@ -148,7 +148,7 @@
@Test
public void testErrorInGetService() throws Exception
{
- VirtualFile assembly = assembleBundle("simple-bundle1", "/bundles/simple/simple-bundle1", new Class[0]);
+ VirtualFile assembly = assembleArchive("simple-bundle1", "/bundles/simple/simple-bundle1", new Class[0]);
Bundle bundle = context.installBundle(assembly.toURL().toExternalForm());
try
{
@@ -174,7 +174,7 @@
@Test
public void testErrorInUnGetService() throws Exception
{
- VirtualFile assembly = assembleBundle("simple-bundle1", "/bundles/simple/simple-bundle1", new Class[0]);
+ VirtualFile assembly = assembleArchive("simple-bundle1", "/bundles/simple/simple-bundle1", new Class[0]);
Bundle bundle = context.installBundle(assembly.toURL().toExternalForm());
try
{
@@ -203,7 +203,7 @@
@Test
public void testUnGetServiceResult() throws Exception
{
- VirtualFile assembly1 = assembleBundle("simple-bundle1", "/bundles/simple/simple-bundle1", new Class[0]);
+ VirtualFile assembly1 = assembleArchive("simple-bundle1", "/bundles/simple/simple-bundle1", new Class[0]);
Bundle bundle1 = context.installBundle(assembly1.toURL().toExternalForm());
try
{
@@ -222,7 +222,7 @@
assertTrue(bundleContext.ungetService(reference));
assertFalse(bundleContext.ungetService(reference));
- VirtualFile assembly2 = assembleBundle("simple-bundle2", "/bundles/simple/simple-bundle2", new Class[0]);
+ VirtualFile assembly2 = assembleArchive("simple-bundle2", "/bundles/simple/simple-bundle2", new Class[0]);
Bundle bundle2 = context.installBundle(assembly2.toURL().toExternalForm());
try
{
Modified: projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/service/JMXServicesUnitTestCase.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/service/JMXServicesUnitTestCase.java 2010-03-10 16:06:33 UTC (rev 102228)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/service/JMXServicesUnitTestCase.java 2010-03-10 16:12:51 UTC (rev 102229)
@@ -21,35 +21,44 @@
*/
package org.jboss.test.osgi.service;
-import junit.framework.Test;
-import org.jboss.test.osgi.service.support.MockInvokerMBean;
+// $Id: $
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.net.URL;
+
import javax.management.ObjectName;
+import org.jboss.test.osgi.AbstractDeploymentTest;
+import org.jboss.test.osgi.service.support.MockInvokerMBean;
+import org.junit.Test;
+
/**
* Test MC's jmx support.
*
* @author <a href="mailto:ales.justin@jboss.org">Ales Justin</a>
+ * @author Thomas.Diesler(a)jboss.com
*/
-public class JMXServicesUnitTestCase extends ServicesTest
+public class JMXServicesUnitTestCase extends AbstractDeploymentTest
{
- public JMXServicesUnitTestCase(String name)
- {
- super(name);
- }
-
- public static Test suite()
- {
- return suite(JMXServicesUnitTestCase.class);
- }
-
+ @Test
public void testAtJmx() throws Throwable
{
- MockInvokerMBean invoker = (MockInvokerMBean) getBean("Invoker");
- assertNotNull(invoker.getServer());
- ObjectName name = invoker.getServiceName();
- assertNotNull(name);
- assertEquals("jboss:service=invoker,type=unified", name.getCanonicalName());
+ URL beans = getResourceURL("service/jmx-services.xml");
+ deploy(beans);
+ try
+ {
+ MockInvokerMBean invoker = (MockInvokerMBean)getBean("Invoker");
+ assertNotNull(invoker.getServer());
+ ObjectName name = invoker.getServiceName();
+ assertNotNull(name);
+ assertEquals("jboss:service=invoker,type=unified", name.getCanonicalName());
+ }
+ finally
+ {
+ undeploy(beans);
+ }
}
public void testMBeans() throws Throwable
Modified: projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/service/RegisterServiceUnitTestCase.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/service/RegisterServiceUnitTestCase.java 2010-03-10 16:06:33 UTC (rev 102228)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/service/RegisterServiceUnitTestCase.java 2010-03-10 16:12:51 UTC (rev 102229)
@@ -27,7 +27,7 @@
import java.util.Hashtable;
import org.jboss.osgi.vfs.VirtualFile;
-import org.jboss.test.osgi.NativeFrameworkTest;
+import org.jboss.test.osgi.AbstractFrameworkTest;
import org.junit.Test;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
@@ -43,7 +43,7 @@
* @author <a href="ales.justin(a)jboss.org">Ales Justin</a>
* @version $Revision: 1.1 $
*/
-public class RegisterServiceUnitTestCase extends NativeFrameworkTest
+public class RegisterServiceUnitTestCase extends AbstractFrameworkTest
{
static String OBJCLASS = BundleContext.class.getName();
static String[] OBJCLASSES = new String[] { OBJCLASS };
@@ -54,7 +54,7 @@
String OBJCLASS = BundleContext.class.getName();
String[] OBJCLASSES = new String[] { OBJCLASS };
- VirtualFile assembly = assembleBundle("simple-bundle1", "/bundles/simple/simple-bundle1", new Class[0]);
+ VirtualFile assembly = assembleArchive("simple-bundle1", "/bundles/simple/simple-bundle1", new Class[0]);
Bundle bundle = context.installBundle(assembly.toURL().toExternalForm());
try
{
@@ -189,7 +189,7 @@
Dictionary<String, Object> properties = new Hashtable<String, Object>();
properties.put(Constants.OBJECTCLASS, new String[] { "rubbish" });
- VirtualFile assembly = assembleBundle("simple-bundle1", "/bundles/simple/simple-bundle1", new Class[0]);
+ VirtualFile assembly = assembleArchive("simple-bundle1", "/bundles/simple/simple-bundle1", new Class[0]);
Bundle bundle = context.installBundle(assembly.toURL().toExternalForm());
try
{
@@ -220,7 +220,7 @@
@Test
public void testRegisterService() throws Exception
{
- VirtualFile assembly = assembleBundle("simple-bundle1", "/bundles/simple/simple-bundle1", new Class[0]);
+ VirtualFile assembly = assembleArchive("simple-bundle1", "/bundles/simple/simple-bundle1", new Class[0]);
Bundle bundle = context.installBundle(assembly.toURL().toExternalForm());
try
{
@@ -247,7 +247,7 @@
@Test
public void testBundleUninstall() throws Exception
{
- VirtualFile assembly1 = assembleBundle("simple-bundle1", "/bundles/simple/simple-bundle1", new Class[0]);
+ VirtualFile assembly1 = assembleArchive("simple-bundle1", "/bundles/simple/simple-bundle1", new Class[0]);
Bundle bundle1 = context.installBundle(assembly1.toURL().toExternalForm());
try
{
@@ -260,7 +260,7 @@
Object actual = bundleContext.getService(reference);
assertEquals(bundleContext, actual);
- VirtualFile assembly2 = assembleBundle("simple-bundle2", "/bundles/simple/simple-bundle2", new Class[0]);
+ VirtualFile assembly2 = assembleArchive("simple-bundle2", "/bundles/simple/simple-bundle2", new Class[0]);
Bundle bundle2 = context.installBundle(assembly2.toURL().toExternalForm());
try
{
@@ -288,7 +288,7 @@
@Test
public void testRegisteredServices() throws Exception
{
- VirtualFile assembly1 = assembleBundle("simple-bundle1", "/bundles/simple/simple-bundle1", new Class[0]);
+ VirtualFile assembly1 = assembleArchive("simple-bundle1", "/bundles/simple/simple-bundle1", new Class[0]);
Bundle bundle1 = context.installBundle(assembly1.toURL().toExternalForm());
try
{
@@ -301,7 +301,7 @@
Object actual = bundleContext.getService(reference);
assertEquals(bundleContext, actual);
- VirtualFile assembly2 = assembleBundle("simple-bundle2", "/bundles/simple/simple-bundle2", new Class[0]);
+ VirtualFile assembly2 = assembleArchive("simple-bundle2", "/bundles/simple/simple-bundle2", new Class[0]);
Bundle bundle2 = context.installBundle(assembly2.toURL().toExternalForm());
try
{
Modified: projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/service/ServiceFactoryUnitTestCase.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/service/ServiceFactoryUnitTestCase.java 2010-03-10 16:06:33 UTC (rev 102228)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/service/ServiceFactoryUnitTestCase.java 2010-03-10 16:12:51 UTC (rev 102229)
@@ -26,7 +26,7 @@
import org.jboss.osgi.framework.bundle.OSGiBundleWrapper;
import org.jboss.osgi.vfs.VirtualFile;
-import org.jboss.test.osgi.NativeFrameworkTest;
+import org.jboss.test.osgi.AbstractFrameworkTest;
import org.jboss.test.osgi.service.support.SimpleServiceFactory;
import org.jboss.test.osgi.service.support.a.A;
import org.junit.Test;
@@ -43,7 +43,7 @@
* @author Thomas.Diesler(a)jboss.com
* @version $Revision$
*/
-public class ServiceFactoryUnitTestCase extends NativeFrameworkTest
+public class ServiceFactoryUnitTestCase extends AbstractFrameworkTest
{
static String OBJCLASS = BundleContext.class.getName();
static String[] OBJCLASSES = new String[] { OBJCLASS };
@@ -52,7 +52,7 @@
@Test
public void testRegisterServiceFactory() throws Exception
{
- VirtualFile assemblyA = assembleBundle("simple1", "/bundles/simple/simple-bundle1", A.class);
+ VirtualFile assemblyA = assembleArchive("simple1", "/bundles/simple/simple-bundle1", A.class);
Bundle bundleA = context.installBundle(assemblyA.toURL().toExternalForm());
try
{
@@ -77,7 +77,7 @@
assertEquals(bundleA.getSymbolicName(), serviceFactory.getBundle.getSymbolicName());
assertEquals(1, serviceFactory.getCount);
- VirtualFile assemblyB = assembleBundle("simple2", "/bundles/simple/simple-bundle2");
+ VirtualFile assemblyB = assembleArchive("simple2", "/bundles/simple/simple-bundle2");
Bundle bundleB = context.installBundle(assemblyB.toURL().toExternalForm());
try
{
@@ -108,7 +108,7 @@
{
String OBJCLASS = BundleContext.class.getName();
- VirtualFile assembly = assembleBundle("simple1", "/bundles/simple/simple-bundle1");
+ VirtualFile assembly = assembleArchive("simple1", "/bundles/simple/simple-bundle1");
Bundle bundle = context.installBundle(assembly.toURL().toExternalForm());
try
{
@@ -139,7 +139,7 @@
{
String OBJCLASS = BundleContext.class.getName();
- VirtualFile assembly = assembleBundle("simple1", "/bundles/simple/simple-bundle1");
+ VirtualFile assembly = assembleArchive("simple1", "/bundles/simple/simple-bundle1");
Bundle bundle = context.installBundle(assembly.toURL().toExternalForm());
try
{
@@ -174,7 +174,7 @@
{
String[] OBJCLASSES = {String.class.getName(), BundleContext.class.getName()};
- VirtualFile assembly = assembleBundle("simple1", "/bundles/simple/simple-bundle1");
+ VirtualFile assembly = assembleArchive("simple1", "/bundles/simple/simple-bundle1");
Bundle bundle = context.installBundle(assembly.toURL().toExternalForm());
try
{
Modified: projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/service/ServiceMixUnitTestCase.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/service/ServiceMixUnitTestCase.java 2010-03-10 16:06:33 UTC (rev 102228)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/service/ServiceMixUnitTestCase.java 2010-03-10 16:12:51 UTC (rev 102229)
@@ -21,22 +21,29 @@
*/
package org.jboss.test.osgi.service;
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+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 java.util.Dictionary;
import java.util.Hashtable;
import java.util.List;
-import junit.framework.Test;
-
import org.jboss.beans.metadata.spi.BeanMetaData;
import org.jboss.beans.metadata.spi.builder.BeanMetaDataBuilder;
import org.jboss.dependency.spi.ControllerState;
import org.jboss.deployers.client.spi.Deployment;
import org.jboss.kernel.spi.dependency.KernelControllerContext;
+import org.jboss.osgi.vfs.VirtualFile;
import org.jboss.test.osgi.service.support.LazyBundle;
import org.jboss.test.osgi.service.support.a.A;
import org.jboss.test.osgi.service.support.c.C;
import org.jboss.test.osgi.service.support.d.D;
-import org.jboss.virtual.AssembledDirectory;
+import org.jboss.test.osgi.service.support.e.E;
+import org.junit.Test;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
@@ -47,24 +54,16 @@
*
* @author <a href="mailto:ales.justin@jboss.org">Ales Justin</a>
*/
-public class ServiceMixUnitTestCase extends ServicesTest
+public class ServiceMixUnitTestCase extends AbstractServiceMixTest
{
- public ServiceMixUnitTestCase(String name)
- {
- super(name);
- }
-
- public static Test suite()
- {
- return suite(ServiceMixUnitTestCase.class);
- }
-
+ @Test
public void testGetServiceReferenceFromMC() throws Throwable
{
- Deployment bean = deployBean("beanA", A.class);
+ Deployment bean = deployBeans("beanA", A.class);
try
{
- Bundle bundle1 = installBundle(assembleBundle("simple1", "/bundles/service/service-bundle1"));
+ VirtualFile assembly1 = assembleArchive("simple1", "/bundles/service/service-bundle1");
+ Bundle bundle1 = context.installBundle(assembly1.toURL().toExternalForm());
try
{
bundle1.start();
@@ -76,13 +75,13 @@
try
{
Bundle refsBundle = ref1.getBundle();
- assertBundle(refsBundle, getBundle(bean));
+ assertEquals(refsBundle, getBundle(bean));
assertNotNull(bundleContext1.getService(ref1));
assertUsingBundles(ref1, bundle1);
ServiceReference[] inUse = bundle1.getServicesInUse();
- assertEquals(new ServiceReference[]{ref1}, inUse);
+ assertArrayEquals(new ServiceReference[] { ref1 }, inUse);
}
finally
{
@@ -96,7 +95,7 @@
}
finally
{
- uninstall(bundle1);
+ bundle1.uninstall();
}
}
finally
@@ -105,17 +104,19 @@
}
}
+ @Test
public void testInjectionToMC() throws Throwable
{
BeanMetaDataBuilder builder = BeanMetaDataBuilder.createBuilder("C", C.class.getName());
builder.addPropertyMetaData("a", builder.createContextualInject());
BeanMetaData bmd = builder.getBeanMetaData();
- Deployment bean = addBean("beanA", C.class, bmd, A.class);
+ Deployment bean = addBeans("beanA", bmd, A.class, C.class);
try
{
KernelControllerContext kcc = getControllerContext("C", null);
- Bundle bundle1 = installBundle(assembleBundle("simple2", "/bundles/service/service-bundle3"));
+ VirtualFile assembly1 = assembleArchive("simple2", "/bundles/service/service-bundle3");
+ Bundle bundle1 = context.installBundle(assembly1.toURL().toExternalForm());
try
{
bundle1.start();
@@ -153,7 +154,7 @@
}
finally
{
- uninstall(bundle1);
+ bundle1.uninstall();
}
}
finally
@@ -162,17 +163,19 @@
}
}
+ @Test
public void testInjectionToMCNamedService() throws Throwable
{
BeanMetaDataBuilder builder = BeanMetaDataBuilder.createBuilder("C", C.class.getName());
builder.addPropertyMetaData("a", builder.createInject("A"));
BeanMetaData bmd = builder.getBeanMetaData();
- Deployment bean = addBean("beanA", C.class, bmd, A.class);
+ Deployment bean = addBeans("beanA", bmd, C.class, A.class);
try
{
KernelControllerContext kcc = getControllerContext("C", null);
- Bundle bundle1 = installBundle(assembleBundle("simple2", "/bundles/service/service-bundle3"));
+ VirtualFile assembly1 = assembleArchive("simple2", "/bundles/service/service-bundle3");
+ Bundle bundle1 = context.installBundle(assembly1.toURL().toExternalForm());
try
{
bundle1.start();
@@ -212,7 +215,7 @@
}
finally
{
- uninstall(bundle1);
+ bundle1.uninstall();
}
}
finally
@@ -221,16 +224,18 @@
}
}
+ @Test
public void testInvokeDispatch() throws Throwable
{
BeanMetaDataBuilder builder = BeanMetaDataBuilder.createBuilder("C", C.class.getName());
builder.addPropertyMetaData("msg", builder.createInject("A", "msg"));
builder.addInstall("calc", "A", int.class.getName(), 123);
BeanMetaData bmd = builder.getBeanMetaData();
- Deployment bean = addBean("beanA", C.class, bmd, A.class);
+ Deployment bean = addBeans("beanA", bmd, C.class, A.class);
try
{
- Bundle bundle1 = installBundle(assembleBundle("simple2", "/bundles/service/service-bundle3"));
+ VirtualFile assembly1 = assembleArchive("simple2", "/bundles/service/service-bundle3");
+ Bundle bundle1 = context.installBundle(assembly1.toURL().toExternalForm());
try
{
bundle1.start();
@@ -259,7 +264,7 @@
}
finally
{
- uninstall(bundle1);
+ bundle1.uninstall();
}
}
finally
@@ -268,22 +273,24 @@
}
}
+ @Test
@SuppressWarnings("rawtypes")
public void testServiceFactoryInjection() throws Throwable
{
BeanMetaDataBuilder builder = BeanMetaDataBuilder.createBuilder("C1", C.class.getName());
builder.addPropertyMetaData("a", builder.createInject("A"));
BeanMetaData bmd = builder.getBeanMetaData();
- Deployment bean1 = addBean("beanA1", C.class, bmd, A.class, D.class);
+ Deployment bean1 = addBeans("beanA1", bmd, C.class, A.class, D.class);
try
{
builder = BeanMetaDataBuilder.createBuilder("C2", C.class.getName());
builder.addPropertyMetaData("a", builder.createInject("A"));
bmd = builder.getBeanMetaData();
- Deployment bean2 = addBean("beanA2", null, bmd);
+ Deployment bean2 = addBeans("beanA2", bmd, E.class);
try
{
- Bundle bundle1 = installBundle(assembleBundle("simple2", "/bundles/service/service-bundle4"));
+ VirtualFile assembly1 = assembleArchive("simple2", "/bundles/service/service-bundle4");
+ Bundle bundle1 = context.installBundle(assembly1.toURL().toExternalForm());
try
{
bundle1.start();
@@ -326,7 +333,7 @@
}
finally
{
- uninstall(bundle1);
+ bundle1.uninstall();
}
}
finally
@@ -340,68 +347,70 @@
}
}
+ @Test
@SuppressWarnings("rawtypes")
public void testServiceFactoryMix() throws Throwable
{
BeanMetaDataBuilder builder = BeanMetaDataBuilder.createBuilder("C1", C.class.getName());
builder.addPropertyMetaData("a", builder.createInject("A"));
BeanMetaData bmd = builder.getBeanMetaData();
- Deployment bean1 = addBean("beanA1", C.class, bmd, A.class, D.class);
+ Deployment bean1 = addBeans("beanA1", bmd, C.class, A.class, D.class);
try
{
- Bundle bundle1 = installBundle(assembleBundle("simple2", "/bundles/service/service-bundle4"));
+ VirtualFile assembly1 = assembleArchive("simple2", "/bundles/service/service-bundle4");
+ Bundle bundle1 = context.installBundle(assembly1.toURL().toExternalForm());
+ try
+ {
+ bundle1.start();
+ BundleContext bundleContext1 = bundle1.getBundleContext();
+ assertNotNull(bundleContext1);
+
+ Class<?> dClass = bundle1.loadClass(D.class.getName());
+ Object d = dClass.newInstance();
+ Hashtable<String, Object> table = new Hashtable<String, Object>();
+ table.put("service.alias.1", "A");
+ ServiceRegistration reg1 = bundleContext1.registerService(A.class.getName(), d, table);
+ assertNotNull(reg1);
+ ServiceReference refA = reg1.getReference();
+ assertNotNull(refA);
+
+ Object a = null;
try
{
- bundle1.start();
- BundleContext bundleContext1 = bundle1.getBundleContext();
- assertNotNull(bundleContext1);
+ checkComplete();
- Class<?> dClass = bundle1.loadClass(D.class.getName());
- Object d = dClass.newInstance();
- Hashtable<String, Object> table = new Hashtable<String, Object>();
- table.put("service.alias.1", "A");
- ServiceRegistration reg1 = bundleContext1.registerService(A.class.getName(), d, table);
- assertNotNull(reg1);
- ServiceReference refA = reg1.getReference();
- assertNotNull(refA);
+ Object c1 = getBean("C1");
+ a = getter(c1, "getA", "C1");
- Object a = null;
- try
- {
- checkComplete();
+ ServiceReference refD = bundleContext1.getServiceReference(C.class.getName());
+ Bundle beanBundle = refD.getBundle();
+ assertNotNull(beanBundle);
+ BundleContext beanBC = beanBundle.getBundleContext();
+ assertNotNull(beanBC);
+ Object service = beanBC.getService(refA);
+ assertSame(a, service);
- Object c1 = getBean("C1");
- a = getter(c1, "getA", "C1");
+ KernelControllerContext cCC = getControllerContext("C1", null);
+ change(cCC, ControllerState.INSTANTIATED);
- ServiceReference refD = bundleContext1.getServiceReference(C.class.getName());
- Bundle beanBundle = refD.getBundle();
- assertNotNull(beanBundle);
- BundleContext beanBC = beanBundle.getBundleContext();
- assertNotNull(beanBC);
- Object service = beanBC.getService(refA);
- assertSame(a, service);
-
- KernelControllerContext cCC = getControllerContext("C1", null);
- change(cCC, ControllerState.INSTANTIATED);
-
- List as = assertInstanceOf(getter(d, "getAs", "A"), List.class);
- assertNotNull(as);
- assertEmpty(as); // SF is still in use
- }
- finally
- {
- reg1.unregister();
- }
-
List as = assertInstanceOf(getter(d, "getAs", "A"), List.class);
assertNotNull(as);
- assertEquals(1, as.size());
- assertTrue(as.contains(a));
+ assertTrue(as.isEmpty()); // SF is still in use
}
finally
{
- uninstall(bundle1);
+ reg1.unregister();
}
+
+ List as = assertInstanceOf(getter(d, "getAs", "A"), List.class);
+ assertNotNull(as);
+ assertEquals(1, as.size());
+ assertTrue(as.contains(a));
+ }
+ finally
+ {
+ bundle1.uninstall();
+ }
}
finally
{
@@ -409,6 +418,70 @@
}
}
+ @Test
+ public void testFiltering() throws Throwable
+ {
+ Deployment bean = deployBeans("beanA", A.class);
+ try
+ {
+ VirtualFile assembly1 = assembleArchive("simple2", "/bundles/service/service-bundle1");
+ Bundle bundle1 = context.installBundle(assembly1.toURL().toExternalForm());
+ try
+ {
+ bundle1.start();
+ BundleContext bundleContext1 = bundle1.getBundleContext();
+ assertNotNull(bundleContext1);
+
+ Class<?> aClass = bundle1.loadClass(A.class.getName());
+ Object a = aClass.newInstance();
+ Dictionary<String, Object> dictionary = new Hashtable<String, Object>();
+ dictionary.put("a", "b");
+ ServiceRegistration reg1 = bundleContext1.registerService(A.class.getName(), a, dictionary);
+ assertNotNull(reg1);
+ try
+ {
+ ServiceReference[] refs = bundleContext1.getServiceReferences(A.class.getName(), "(a=b)");
+ assertNotNull(refs);
+ assertEquals(1, refs.length);
+ ServiceReference osgiRef = refs[0];
+
+ refs = bundleContext1.getServiceReferences(A.class.getName(), "(bean.name=A)");
+ assertNotNull(refs);
+ assertEquals(1, refs.length);
+ ServiceReference mcRef = refs[0];
+
+ // OSGi service should bubble on top
+ assertEquals("OSGi service has not bubbled on top", osgiRef, bundleContext1.getServiceReference(A.class.getName()));
+
+ // compare
+ assertTrue(osgiRef.compareTo(mcRef) < 0);
+ assertTrue(0 < mcRef.compareTo(osgiRef));
+
+ // ranking order first
+ refs = bundleContext1.getServiceReferences(A.class.getName(), null);
+ assertNotNull(refs);
+ assertEquals(2, refs.length);
+ assertEquals(osgiRef, refs[0]);
+ assertEquals(mcRef, refs[1]);
+ }
+ finally
+ {
+ reg1.unregister();
+ }
+ }
+ finally
+ {
+ bundle1.uninstall();
+ }
+ }
+ finally
+ {
+ undeploy(bean);
+ }
+ }
+
+ /*
+ @Test
public void testBeansMix() throws Throwable
{
AssembledDirectory mix = createAssembledDirectory("beans1", "");
@@ -441,9 +514,11 @@
}
}
+ @Test
public void testServiceInjection() throws Throwable
{
- Bundle bundle = installBundle(assembleBundle("simple2", "/bundles/service/service-bundle2", A.class));
+ VirtualFile assembly1 = assembleArchive("simple2", "/bundles/service/service-bundle2", A.class);
+ Bundle bundle = context.installBundle(assembly1.toURL().toExternalForm());
try
{
bundle.start();
@@ -478,67 +553,8 @@
}
finally
{
- uninstall(bundle);
+ bundle.uninstall();
}
}
-
- public void testFiltering() throws Throwable
- {
- Deployment bean = addBean("beanA", A.class);
- try
- {
- Bundle bundle1 = installBundle(assembleBundle("simple2", "/bundles/service/service-bundle1"));
- try
- {
- bundle1.start();
- BundleContext bundleContext1 = bundle1.getBundleContext();
- assertNotNull(bundleContext1);
-
- Class<?> aClass = bundle1.loadClass(A.class.getName());
- Object a = aClass.newInstance();
- Dictionary<String, Object> dictionary = new Hashtable<String, Object>();
- dictionary.put("a", "b");
- ServiceRegistration reg1 = bundleContext1.registerService(A.class.getName(), a, dictionary);
- assertNotNull(reg1);
- try
- {
- ServiceReference[] refs = bundleContext1.getServiceReferences(A.class.getName(), "(a=b)");
- assertNotNull(refs);
- assertEquals(1, refs.length);
- ServiceReference osgiRef = refs[0];
-
- refs = bundleContext1.getServiceReferences(A.class.getName(), "(bean.name=A)");
- assertNotNull(refs);
- assertEquals(1, refs.length);
- ServiceReference mcRef = refs[0];
-
- // OSGi service should bubble on top
- assertEquals("OSGi service has not bubbled on top", osgiRef, bundleContext1.getServiceReference(A.class.getName()));
-
- // compare
- assertTrue(osgiRef.compareTo(mcRef) < 0);
- assertTrue(0 < mcRef.compareTo(osgiRef));
-
- // ranking order first
- refs = bundleContext1.getServiceReferences(A.class.getName(), null);
- assertNotNull(refs);
- assertEquals(2, refs.length);
- assertEquals(osgiRef, refs[0]);
- assertEquals(mcRef, refs[1]);
- }
- finally
- {
- reg1.unregister();
- }
- }
- finally
- {
- uninstall(bundle1);
- }
- }
- finally
- {
- undeploy(bean);
- }
- }
+ */
}
Modified: projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/service/ServiceReferenceUnitTestCase.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/service/ServiceReferenceUnitTestCase.java 2010-03-10 16:06:33 UTC (rev 102228)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/service/ServiceReferenceUnitTestCase.java 2010-03-10 16:12:51 UTC (rev 102229)
@@ -31,7 +31,7 @@
import java.util.TreeSet;
import org.jboss.osgi.vfs.VirtualFile;
-import org.jboss.test.osgi.NativeFrameworkTest;
+import org.jboss.test.osgi.AbstractFrameworkTest;
import org.jboss.test.osgi.service.support.a.A;
import org.junit.Test;
import org.osgi.framework.Bundle;
@@ -47,7 +47,7 @@
* @author <a href="adrian(a)jboss.com">Adrian Brock</a>
* @version $Revision: 1.1 $
*/
-public class ServiceReferenceUnitTestCase extends NativeFrameworkTest
+public class ServiceReferenceUnitTestCase extends AbstractFrameworkTest
{
@Test
public void testGetProperty() throws Exception
@@ -56,7 +56,7 @@
String[] clazzes = new String[] { BundleContext.class.getName() };
Object serviceID = null;
- VirtualFile assembly = assembleBundle("simple1", "/bundles/simple/simple-bundle1");
+ VirtualFile assembly = assembleArchive("simple1", "/bundles/simple/simple-bundle1");
Bundle bundle = context.installBundle(assembly.toURL().toExternalForm());
try
{
@@ -155,7 +155,7 @@
{
ServiceReference reference = null;
- VirtualFile assembly = assembleBundle("simple1", "/bundles/simple/simple-bundle1");
+ VirtualFile assembly = assembleArchive("simple1", "/bundles/simple/simple-bundle1");
Bundle bundle = context.installBundle(assembly.toURL().toExternalForm());
try
{
@@ -215,7 +215,7 @@
@Test
public void testGetBundle() throws Exception
{
- VirtualFile assembly = assembleBundle("simple1", "/bundles/simple/simple-bundle1");
+ VirtualFile assembly = assembleArchive("simple1", "/bundles/simple/simple-bundle1");
Bundle bundle = context.installBundle(assembly.toURL().toExternalForm());
try
{
@@ -246,7 +246,7 @@
@Test
public void testGetBundleAfterStop() throws Exception
{
- VirtualFile assembly = assembleBundle("simple1", "/bundles/simple/simple-bundle1");
+ VirtualFile assembly = assembleArchive("simple1", "/bundles/simple/simple-bundle1");
Bundle bundle = context.installBundle(assembly.toURL().toExternalForm());
try
{
@@ -277,7 +277,7 @@
@Test
public void testUsingBundles() throws Exception
{
- VirtualFile assembly1 = assembleBundle("simple1", "/bundles/simple/simple-bundle1");
+ VirtualFile assembly1 = assembleArchive("simple1", "/bundles/simple/simple-bundle1");
Bundle bundle1 = context.installBundle(assembly1.toURL().toExternalForm());
try
{
@@ -293,7 +293,7 @@
assertUsingBundles(reference);
- VirtualFile assembly2 = assembleBundle("simple2", "/bundles/simple/simple-bundle2");
+ VirtualFile assembly2 = assembleArchive("simple2", "/bundles/simple/simple-bundle2");
Bundle bundle2 = context.installBundle(assembly2.toURL().toExternalForm());
try
{
@@ -336,7 +336,7 @@
@Test
public void testUsingBundlesAfterStop() throws Exception
{
- VirtualFile assembly1 = assembleBundle("simple1", "/bundles/simple/simple-bundle1");
+ VirtualFile assembly1 = assembleArchive("simple1", "/bundles/simple/simple-bundle1");
Bundle bundle1 = context.installBundle(assembly1.toURL().toExternalForm());
try
{
@@ -352,7 +352,7 @@
assertUsingBundles(reference);
- VirtualFile assembly2 = assembleBundle("simple2", "/bundles/simple/simple-bundle2");
+ VirtualFile assembly2 = assembleArchive("simple2", "/bundles/simple/simple-bundle2");
Bundle bundle2 = context.installBundle(assembly2.toURL().toExternalForm());
try
{
@@ -381,7 +381,7 @@
@Test
public void testIsAssignableToErrors() throws Exception
{
- VirtualFile assembly = assembleBundle("simple1", "/bundles/simple/simple-bundle1", A.class);
+ VirtualFile assembly = assembleArchive("simple1", "/bundles/simple/simple-bundle1", A.class);
Bundle bundle = context.installBundle(assembly.toURL().toExternalForm());
try
{
@@ -424,7 +424,7 @@
@Test
public void testNotAssignableTo() throws Exception
{
- VirtualFile assembly1 = assembleBundle("simple1", "/bundles/simple/simple-bundle1", A.class);
+ VirtualFile assembly1 = assembleArchive("simple1", "/bundles/simple/simple-bundle1", A.class);
Bundle bundle1 = context.installBundle(assembly1.toURL().toExternalForm());
try
{
@@ -438,7 +438,7 @@
ServiceReference reference = registration.getReference();
assertNotNull(reference);
- VirtualFile assembly2 = assembleBundle("simple2", "/bundles/simple/simple-bundle2", A.class);
+ VirtualFile assembly2 = assembleArchive("simple2", "/bundles/simple/simple-bundle2", A.class);
Bundle bundle2 = context.installBundle(assembly2.toURL().toExternalForm());
try
{
@@ -466,7 +466,7 @@
//Bundle-Name: Service2
//Bundle-SymbolicName: org.jboss.test.osgi.service2
//Export-Package: org.jboss.test.osgi.service.support.a
- VirtualFile assembly2 = assembleBundle("service2", "/bundles/service/service-bundle2", A.class);
+ VirtualFile assembly2 = assembleArchive("service2", "/bundles/service/service-bundle2", A.class);
Bundle bundle2 = context.installBundle(assembly2.toURL().toExternalForm());
try
@@ -478,7 +478,7 @@
//Bundle-Name: Service1
//Bundle-SymbolicName: org.jboss.test.osgi.service1
//Import-Package: org.jboss.test.osgi.service.support.a
- VirtualFile assembly1 = assembleBundle("service1", "/bundles/service/service-bundle1");
+ VirtualFile assembly1 = assembleArchive("service1", "/bundles/service/service-bundle1");
Bundle bundle1 = context.installBundle(assembly1.toURL().toExternalForm());
try
@@ -515,7 +515,7 @@
@Test
public void testCompareTo() throws Exception
{
- VirtualFile assembly = assembleBundle("simple1", "/bundles/simple/simple-bundle1");
+ VirtualFile assembly = assembleArchive("simple1", "/bundles/simple/simple-bundle1");
Bundle bundle = context.installBundle(assembly.toURL().toExternalForm());
try
{
Modified: projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/service/ServiceRegistrationUnitTestCase.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/service/ServiceRegistrationUnitTestCase.java 2010-03-10 16:06:33 UTC (rev 102228)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/service/ServiceRegistrationUnitTestCase.java 2010-03-10 16:12:51 UTC (rev 102229)
@@ -31,7 +31,7 @@
import java.util.Hashtable;
import org.jboss.osgi.vfs.VirtualFile;
-import org.jboss.test.osgi.NativeFrameworkTest;
+import org.jboss.test.osgi.AbstractFrameworkTest;
import org.jboss.test.osgi.service.support.SimpleServiceFactory;
import org.junit.Test;
import org.osgi.framework.Bundle;
@@ -47,13 +47,13 @@
* @author <a href="adrian(a)jboss.com">Adrian Brock</a>
* @version $Revision: 1.1 $
*/
-public class ServiceRegistrationUnitTestCase extends NativeFrameworkTest
+public class ServiceRegistrationUnitTestCase extends AbstractFrameworkTest
{
@Test
public void testGetReference() throws Exception
{
- VirtualFile assembly = assembleBundle("simple1", "/bundles/simple/simple-bundle1");
+ VirtualFile assembly = assembleArchive("simple1", "/bundles/simple/simple-bundle1");
Bundle bundle = context.installBundle(assembly.toURL().toExternalForm());
try
{
@@ -115,7 +115,7 @@
@Test
public void testSetProperties() throws Exception
{
- VirtualFile assembly = assembleBundle("simple1", "/bundles/simple/simple-bundle1");
+ VirtualFile assembly = assembleArchive("simple1", "/bundles/simple/simple-bundle1");
Bundle bundle = context.installBundle(assembly.toURL().toExternalForm());
try
{
@@ -224,7 +224,7 @@
@Test
public void testSetPropertiesAfterStop() throws Exception
{
- VirtualFile assembly = assembleBundle("simple1", "/bundles/simple/simple-bundle1");
+ VirtualFile assembly = assembleArchive("simple1", "/bundles/simple/simple-bundle1");
Bundle bundle = context.installBundle(assembly.toURL().toExternalForm());
try
{
@@ -257,7 +257,7 @@
@Test
public void testUnregister() throws Exception
{
- VirtualFile assembly1 = assembleBundle("simple1", "/bundles/simple/simple-bundle1");
+ VirtualFile assembly1 = assembleArchive("simple1", "/bundles/simple/simple-bundle1");
Bundle bundle1 = context.installBundle(assembly1.toURL().toExternalForm());
try
{
@@ -282,7 +282,7 @@
inUse = bundle1.getServicesInUse();
assertArrayEquals(new ServiceReference[] { reference }, inUse);
- VirtualFile assembly2 = assembleBundle("simple2", "/bundles/simple/simple-bundle2");
+ VirtualFile assembly2 = assembleArchive("simple2", "/bundles/simple/simple-bundle2");
Bundle bundle2 = context.installBundle(assembly2.toURL().toExternalForm());
try
{
@@ -340,7 +340,7 @@
@Test
public void testUnregisterAfterStop() throws Exception
{
- VirtualFile assembly = assembleBundle("simple1", "/bundles/simple/simple-bundle1");
+ VirtualFile assembly = assembleArchive("simple1", "/bundles/simple/simple-bundle1");
Bundle bundle = context.installBundle(assembly.toURL().toExternalForm());
try
{
Deleted: projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/service/ServicesTest.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/service/ServicesTest.java 2010-03-10 16:06:33 UTC (rev 102228)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/service/ServicesTest.java 2010-03-10 16:12:51 UTC (rev 102229)
@@ -1,56 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file 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.service;
-
-import java.lang.reflect.Method;
-
-import org.jboss.test.osgi.DeployersTest;
-
-/**
- * Test MC's services.
- *
- * @author <a href="mailto:ales.justin@jboss.org">Ales Justin</a>
- */
-public abstract class ServicesTest extends DeployersTest
-{
- public ServicesTest(String name)
- {
- super(name);
- }
-
- protected static Object getter(Object target, String getter, String name) throws Throwable
- {
- assertNotNull("Target " + name + " is not null", target);
- Class<?> clazz = target.getClass();
- Method m = clazz.getDeclaredMethod(getter);
- return m.invoke(target);
- }
-
- protected static Object setter(Object target, String setter, Object value, String name) throws Throwable
- {
- assertNotNull("Target " + name + " is not null", target);
- assertNotNull("Value is not null", value);
- Class<?> clazz = target.getClass();
- Method m = clazz.getDeclaredMethod(setter, value.getClass());
- return m.invoke(target, value);
- }
-}
\ No newline at end of file
Added: projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/service/support/e/E.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/service/support/e/E.java (rev 0)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/service/support/e/E.java 2010-03-10 16:12:51 UTC (rev 102229)
@@ -0,0 +1,26 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.service.support.e;
+
+public class E
+{
+}
Added: projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/resources/service/JMXServicesUnitTestCase#testAtJmx.xml
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/resources/service/JMXServicesUnitTestCase#testAtJmx.xml (rev 0)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/resources/service/JMXServicesUnitTestCase#testAtJmx.xml 2010-03-10 16:12:51 UTC (rev 102229)
@@ -0,0 +1,7 @@
+<deployment xmlns="urn:jboss:bean-deployer:2.0">
+
+ <bean name="Invoker" class="org.jboss.test.osgi.service.support.MockInvoker">
+ <annotation>@org.jboss.aop.microcontainer.aspects.jmx.JMX(name="jboss:service=invoker,type=unified",exposedInterface=org.jboss.test.osgi.service.support.MockInvokerMBean.class,registerDirectly=true)</annotation>
+ </bean>
+
+</deployment>
\ No newline at end of file
Added: projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/resources/service/jmx-services.xml
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/resources/service/jmx-services.xml (rev 0)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/resources/service/jmx-services.xml 2010-03-10 16:12:51 UTC (rev 102229)
@@ -0,0 +1,61 @@
+<deployment xmlns="urn:jboss:bean-deployer:2.0">
+
+ <!-- JMX Deployment -->
+
+ <bean name="JMXKernel" class="org.jboss.test.osgi.service.support.JBossJMXKernel" />
+
+ <bean name="ServiceMetaDataICF" class="org.jboss.system.deployers.managed.ServiceMetaDataICF">
+ <property name="mbeanServer">
+ <inject bean="JMXKernel" property="mbeanServer" />
+ </property>
+ </bean>
+ <bean name="SARDeployer" class="org.jboss.system.deployers.SARDeployer" />
+ <bean name="ServiceClassLoaderDeployer" class="org.jboss.system.deployers.ServiceClassLoaderDeployer" />
+ <bean name="ServiceDeploymentDeployer" class="org.jboss.system.deployers.ServiceDeploymentDeployer" />
+ <bean name="ServiceDeployer" class="org.jboss.system.deployers.ServiceDeployer">
+ <constructor>
+ <parameter>
+ <inject bean="JMXKernel" property="serviceController" />
+ </parameter>
+ </constructor>
+ </bean>
+
+ <!-- Intercept all annotation plugings -->
+
+ <bean name="BeanAnnotationAdapterFactory" class="org.jboss.kernel.plugins.annotations.BeanAnnotationAdapterFactory">
+ <constructor factoryMethod="getInstance" />
+ </bean>
+
+ <bean name="BeanAnnotationAdapter">
+ <constructor factoryMethod="getBeanAnnotationAdapter">
+ <factory bean="BeanAnnotationAdapterFactory" />
+ </constructor>
+ <incallback method="addAnnotationPlugin" />
+ <uncallback method="removeAnnotationPlugin" />
+ </bean>
+
+ <!-- Support for @JMX -->
+ <lifecycle-configure xmlns="urn:jboss:aop-beans:1.0" name="JMXRegistrationAdvice" class="org.jboss.system.microcontainer.jmx.ServiceControllerRegistrationLifecycleCallback"
+ classes="@org.jboss.aop.microcontainer.aspects.jmx.JMX">
+ <property name="serviceController">
+ <inject bean="JMXKernel" property="serviceController" />
+ </property>
+ </lifecycle-configure>
+ <lifecycle-create xmlns="urn:jboss:aop-beans:1.0" name="JMXCreateDestroyAdvice" class="org.jboss.system.microcontainer.jmx.ServiceControllerCreateDestroyLifecycleCallback"
+ classes="@org.jboss.aop.microcontainer.aspects.jmx.JMX">
+ <property name="serviceController">
+ <inject bean="JMXKernel" property="serviceController" />
+ </property>
+ </lifecycle-create>
+ <lifecycle-install xmlns="urn:jboss:aop-beans:1.0" name="JMXStartStopAdvice" class="org.jboss.system.microcontainer.jmx.ServiceControllerStartStopLifecycleCallback"
+ classes="@org.jboss.aop.microcontainer.aspects.jmx.JMX">
+ <property name="serviceController">
+ <inject bean="JMXKernel" property="serviceController" />
+ </property>
+ </lifecycle-install>
+
+ <bean name="Invoker" class="org.jboss.test.osgi.service.support.MockInvoker">
+ <annotation>@org.jboss.aop.microcontainer.aspects.jmx.JMX(name="jboss:service=invoker,type=unified",exposedInterface=org.jboss.test.osgi.service.support.MockInvokerMBean.class,registerDirectly=true)</annotation>
+ </bean>
+
+</deployment>
\ No newline at end of file
14 years, 3 months
JBoss-OSGI SVN: r102228 - in projects/jboss-osgi/projects/testing/trunk/src: test/java/org/jboss/test/osgi/testing and 1 other directory.
by jboss-osgi-commits@lists.jboss.org
Author: thomas.diesler(a)jboss.com
Date: 2010-03-10 11:06:33 -0500 (Wed, 10 Mar 2010)
New Revision: 102228
Modified:
projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/OSGiTest.java
projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/OSGiTestHelper.java
projects/jboss-osgi/projects/testing/trunk/src/test/java/org/jboss/test/osgi/testing/SimpleAssemblyTestCase.java
Log:
Use assembleArchive instead of assembleBundle
Modified: projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/OSGiTest.java
===================================================================
--- projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/OSGiTest.java 2010-03-10 15:53:48 UTC (rev 102227)
+++ projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/OSGiTest.java 2010-03-10 16:06:33 UTC (rev 102228)
@@ -199,19 +199,19 @@
}
/**
- * Delegates to {@link OSGiTestHelper#assembleBundle(String, String, Class...)}
+ * Delegates to {@link OSGiTestHelper#assembleArchive(String, String, Class...)}
*/
- public VirtualFile assembleBundle(String name, String resource, Class<?>... packages) throws Exception
+ public VirtualFile assembleArchive(String name, String resource, Class<?>... packages) throws Exception
{
- return getTestHelper().assembleBundle(name, resource, packages);
+ return getTestHelper().assembleArchive(name, resource, packages);
}
/**
- * Delegates to {@link OSGiTestHelper#assembleBundle(String, String[], Class...)}
+ * Delegates to {@link OSGiTestHelper#assembleArchive(String, String[], Class...)}
*/
- public VirtualFile assembleBundle(String name, String[] resources, Class<?>... packages) throws Exception
+ public VirtualFile assembleArchive(String name, String[] resources, Class<?>... packages) throws Exception
{
- return getTestHelper().assembleBundle(name, resources, packages);
+ return getTestHelper().assembleArchive(name, resources, packages);
}
/**
Modified: projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/OSGiTestHelper.java
===================================================================
--- projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/OSGiTestHelper.java 2010-03-10 15:53:48 UTC (rev 102227)
+++ projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/OSGiTestHelper.java 2010-03-10 16:06:33 UTC (rev 102228)
@@ -216,12 +216,12 @@
return framework;
}
- public VirtualFile assembleBundle(String name, String resource, Class<?>... packages) throws Exception
+ public VirtualFile assembleArchive(String name, String resource, Class<?>... packages) throws Exception
{
- return assembleBundle(name, new String[] { resource }, packages);
+ return assembleArchive(name, new String[] { resource }, packages);
}
- public VirtualFile assembleBundle(String name, String[] resources, Class<?>... packages) throws IOException
+ public VirtualFile assembleArchive(String name, String[] resources, Class<?>... packages) throws IOException
{
JavaArchive archive = Archives.create(name + ".jar", JavaArchive.class);
if (resources != null)
Modified: projects/jboss-osgi/projects/testing/trunk/src/test/java/org/jboss/test/osgi/testing/SimpleAssemblyTestCase.java
===================================================================
--- projects/jboss-osgi/projects/testing/trunk/src/test/java/org/jboss/test/osgi/testing/SimpleAssemblyTestCase.java 2010-03-10 15:53:48 UTC (rev 102227)
+++ projects/jboss-osgi/projects/testing/trunk/src/test/java/org/jboss/test/osgi/testing/SimpleAssemblyTestCase.java 2010-03-10 16:06:33 UTC (rev 102228)
@@ -73,7 +73,7 @@
OSGiRuntime runtime = getDefaultRuntime();
try
{
- VirtualFile virtualFile = assembleBundle("example-simple", "/simple", SimpleActivator.class);
+ VirtualFile virtualFile = assembleArchive("example-simple", "/simple", SimpleActivator.class);
OSGiBundle bundle = runtime.installBundle(virtualFile);
assertBundleState(Bundle.INSTALLED, bundle.getState());
}
14 years, 3 months
JBoss-OSGI SVN: r102224 - in projects/jboss-osgi: projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/classloader and 7 other directories.
by jboss-osgi-commits@lists.jboss.org
Author: thomas.diesler(a)jboss.com
Date: 2010-03-10 08:28:11 -0500 (Wed, 10 Mar 2010)
New Revision: 102224
Removed:
projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/smoke/OSGiSmokeTestCase.java
projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/smoke/support/a/A.java
projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/smoke/support/a/b/
projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/smoke/support/c/
Modified:
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/classloader/RequireBundleUnitTestCase.java
projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/compendium/PackageAdminTestCase.java
projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/fragments/FragmentTestCase.java
projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/service/GetServiceReferencesUnitTestCase.java
projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/service/GetUnGetServiceUnitTestCase.java
projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/service/RegisterServiceUnitTestCase.java
projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/service/ServiceFactoryUnitTestCase.java
projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/service/ServiceReferenceUnitTestCase.java
projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/service/ServiceRegistrationUnitTestCase.java
projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi142/OSGi142TestCase.java
Log:
Migrate more framework tests to OSGiTest
Modified: 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 2010-03-10 13:24:47 UTC (rev 102223)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/NativeFrameworkTest.java 2010-03-10 13:28:11 UTC (rev 102224)
@@ -23,11 +23,16 @@
// $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;
@@ -48,6 +53,7 @@
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.
@@ -89,6 +95,73 @@
}
}
+ protected PackageAdmin getPackageAdmin()
+ {
+ ServiceReference sref = context.getServiceReference(PackageAdmin.class.getName());
+ return (PackageAdmin)context.getService(sref);
+ }
+
+ 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);
@@ -126,28 +199,6 @@
}
@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)
@@ -176,6 +227,132 @@
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
{
Modified: projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/classloader/RequireBundleUnitTestCase.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/classloader/RequireBundleUnitTestCase.java 2010-03-10 13:24:47 UTC (rev 102223)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/classloader/RequireBundleUnitTestCase.java 2010-03-10 13:28:11 UTC (rev 102224)
@@ -21,11 +21,15 @@
*/
package org.jboss.test.osgi.classloader;
-import junit.framework.Test;
+// $Id: $
-import org.jboss.test.osgi.FrameworkTest;
+import static org.junit.Assert.fail;
+
+import org.jboss.osgi.vfs.VirtualFile;
+import org.jboss.test.osgi.NativeFrameworkTest;
import org.jboss.test.osgi.classloader.support.a.A;
import org.jboss.test.osgi.classloader.support.b.B;
+import org.junit.Test;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleException;
@@ -34,56 +38,53 @@
*
* TODO test security
* @author <a href="adrian(a)jboss.com">Adrian Brock</a>
+ * @author thomas.diesler(a)jboss.com
* @version $Revision: 1.1 $
*/
-public class RequireBundleUnitTestCase extends FrameworkTest
+public class RequireBundleUnitTestCase extends NativeFrameworkTest
{
- public RequireBundleUnitTestCase(String name)
- {
- super(name);
- }
-
- public static Test suite()
- {
- return suite(RequireBundleUnitTestCase.class);
- }
-
+ @Test
public void testSimpleRequireBundle() throws Exception
{
- Bundle bundle1 = installBundle(assembleBundle("bundleA", "/bundles/classloader/bundleA", A.class));
+ VirtualFile assemblyA = assembleBundle("bundleA", "/bundles/classloader/bundleA", A.class);
+ Bundle bundleA = context.installBundle(assemblyA.toURL().toExternalForm());
try
{
- bundle1.start();
- assertLoadClass(bundle1, A.class);
- Bundle bundle2 = installBundle(assembleBundle("simplerequirebundleA", "/bundles/classloader/simplerequirebundleA", B.class));
+ bundleA.start();
+ assertLoadClass(bundleA, A.class.getName());
+ VirtualFile assemblyB = assembleBundle("simplerequirebundleA", "/bundles/classloader/simplerequirebundleA", B.class);
+ Bundle bundleB = context.installBundle(assemblyB.toURL().toExternalForm());
try
{
- bundle2.start();
- assertLoadClass(bundle2, A.class, bundle1);
- assertLoadClass(bundle2, B.class, bundle2);
+ bundleB.start();
+ assertLoadClass(bundleB, A.class.getName(), bundleA);
+ assertLoadClass(bundleB, B.class.getName(), bundleB);
}
finally
{
- uninstall(bundle2);
+ bundleB.uninstall();
}
}
finally
{
- uninstall(bundle1);
+ bundleA.uninstall();
}
}
+ @Test
public void testSimpleRequireBundleFails() throws Exception
{
- Bundle bundle1 = installBundle(assembleBundle("bundleA", "/bundles/classloader/bundleA", A.class));
+ VirtualFile assemblyA = assembleBundle("bundleA", "/bundles/classloader/bundleA", A.class);
+ Bundle bundleA = context.installBundle(assemblyA.toURL().toExternalForm());
try
{
- bundle1.start();
- assertLoadClass(bundle1, A.class);
- Bundle bundle2 = installBundle(assembleBundle("simplerequirebundlefails", "/bundles/classloader/simplerequirebundlefails", B.class));
+ bundleA.start();
+ assertLoadClass(bundleA, A.class.getName());
+ VirtualFile assemblyB = assembleBundle("simplerequirebundlefails", "/bundles/classloader/simplerequirebundlefails", B.class);
+ Bundle bundleB = context.installBundle(assemblyB.toURL().toExternalForm());
try
{
- bundle2.start();
+ bundleB.start();
fail("Should not be here!");
}
catch (BundleException ex)
@@ -92,51 +93,57 @@
}
finally
{
- uninstall(bundle2);
+ bundleB.uninstall();
}
}
finally
{
- uninstall(bundle1);
+ bundleA.uninstall();
}
}
+ @Test
public void testVersionRequireBundle() throws Exception
{
- Bundle bundle1 = installBundle(assembleBundle("bundleA", "/bundles/classloader/bundleA", A.class));
+ VirtualFile assemblyA = assembleBundle("bundleA", "/bundles/classloader/bundleA", A.class);
+ Bundle bundleA = context.installBundle(assemblyA.toURL().toExternalForm());
try
{
- bundle1.start();
- assertLoadClass(bundle1, A.class);
- Bundle bundle2 = installBundle(assembleBundle("versionrequirebundleA", "/bundles/classloader/versionrequirebundleA", B.class));
+ bundleA.start();
+ assertLoadClass(bundleA, A.class.getName());
+ VirtualFile assemblyB = assembleBundle("versionrequirebundleA", "/bundles/classloader/versionrequirebundleA", B.class);
+ Bundle bundleB = context.installBundle(assemblyB.toURL().toExternalForm());
try
{
- bundle2.start();
- assertLoadClass(bundle2, A.class, bundle1);
- assertLoadClass(bundle2, B.class, bundle2);
+ bundleB.start();
+ assertLoadClass(bundleB, A.class.getName(), bundleA);
+ assertLoadClass(bundleB, B.class.getName(), bundleB);
}
finally
{
- uninstall(bundle2);
+ bundleB.uninstall();
}
}
finally
{
- uninstall(bundle1);
+ bundleA.uninstall();
}
}
+ @Test
public void testVersionRequireBundleFails() throws Exception
{
- Bundle bundle1 = installBundle(assembleBundle("bundleA", "/bundles/classloader/bundleA", A.class));
+ VirtualFile assemblyA = assembleBundle("bundleA", "/bundles/classloader/bundleA", A.class);
+ Bundle bundleA = context.installBundle(assemblyA.toURL().toExternalForm());
try
{
- bundle1.start();
- assertLoadClass(bundle1, A.class);
- Bundle bundle2 = installBundle(assembleBundle("versionrequirebundlefails", "/bundles/classloader/versionrequirebundlefails", B.class));
+ bundleA.start();
+ assertLoadClass(bundleA, A.class.getName());
+ VirtualFile assemblyB = assembleBundle("versionrequirebundlefails", "/bundles/classloader/versionrequirebundlefails", B.class);
+ Bundle bundleB = context.installBundle(assemblyB.toURL().toExternalForm());
try
{
- bundle2.start();
+ bundleB.start();
fail("Should not be here!");
}
catch (BundleException rte)
@@ -145,193 +152,213 @@
}
finally
{
- uninstall(bundle2);
+ bundleB.uninstall();
}
}
finally
{
- uninstall(bundle1);
+ bundleA.uninstall();
}
}
+ @Test
public void testOptionalRequireBundle() throws Exception
{
- Bundle bundle1 = installBundle(assembleBundle("bundleA", "/bundles/classloader/bundleA", A.class));
+ VirtualFile assemblyA = assembleBundle("bundleA", "/bundles/classloader/bundleA", A.class);
+ Bundle bundleA = context.installBundle(assemblyA.toURL().toExternalForm());
try
{
- bundle1.start();
- assertLoadClass(bundle1, A.class);
- Bundle bundle2 = installBundle(assembleBundle("optionalrequirebundleA", "/bundles/classloader/optionalrequirebundleA", B.class));
+ bundleA.start();
+ assertLoadClass(bundleA, A.class.getName());
+ VirtualFile assemblyB = assembleBundle("optionalrequirebundleA", "/bundles/classloader/optionalrequirebundleA", B.class);
+ Bundle bundleB = context.installBundle(assemblyB.toURL().toExternalForm());
try
{
- bundle2.start();
- assertLoadClass(bundle2, A.class, bundle1);
- assertLoadClass(bundle2, B.class, bundle2);
+ bundleB.start();
+ assertLoadClass(bundleB, A.class.getName(), bundleA);
+ assertLoadClass(bundleB, B.class.getName(), bundleB);
}
finally
{
- uninstall(bundle2);
+ bundleB.uninstall();
}
}
finally
{
- uninstall(bundle1);
+ bundleA.uninstall();
}
}
+ @Test
public void testOptionalRequireBundleFails() throws Exception
{
- Bundle bundle1 = installBundle(assembleBundle("bundleA", "/bundles/classloader/bundleA", A.class));
+ VirtualFile assemblyA = assembleBundle("bundleA", "/bundles/classloader/bundleA", A.class);
+ Bundle bundleA = context.installBundle(assemblyA.toURL().toExternalForm());
try
{
- bundle1.start();
- assertLoadClass(bundle1, A.class);
- Bundle bundle2 = installBundle(assembleBundle("optionalrequirebundlefails", "/bundles/classloader/optionalrequirebundlefails", B.class));
+ bundleA.start();
+ assertLoadClass(bundleA, A.class.getName());
+ VirtualFile assemblyB = assembleBundle("optionalrequirebundlefails", "/bundles/classloader/optionalrequirebundlefails", B.class);
+ Bundle bundleB = context.installBundle(assemblyB.toURL().toExternalForm());
try
{
- bundle2.start();
- assertLoadClassFail(bundle2, A.class);
- assertLoadClass(bundle2, B.class);
+ bundleB.start();
+ assertLoadClassFail(bundleB, A.class.getName());
+ assertLoadClass(bundleB, B.class.getName());
}
finally
{
- uninstall(bundle2);
+ bundleB.uninstall();
}
}
finally
{
- uninstall(bundle1);
+ bundleA.uninstall();
}
}
+ @Test
public void testReExportRequireBundle() throws Exception
{
//Bundle-Name: BundleA
//Bundle-Version: 1.0.0
//Bundle-SymbolicName: org.jboss.test.osgi.classloader.bundleA;test=x
//Export-Package: org.jboss.test.osgi.classloader.support.a;version=1.0.0;test=x
- Bundle bundle1 = installBundle(assembleBundle("bundleA", "/bundles/classloader/bundleA", A.class));
+ VirtualFile assemblyA = assembleBundle("bundleA", "/bundles/classloader/bundleA", A.class);
+ Bundle bundleA = context.installBundle(assemblyA.toURL().toExternalForm());
try
{
- bundle1.start();
- assertLoadClass(bundle1, A.class);
+ bundleA.start();
+ assertLoadClass(bundleA, A.class.getName());
//Bundle-Name: BundleB
//Bundle-SymbolicName: org.jboss.test.osgi.classloader.bundleB
//Require-Bundle: org.jboss.test.osgi.classloader.bundleA;visibility:=reexport
//Export-Package: org.jboss.test.osgi.classloader.support.b
- Bundle bundle2 = installBundle(assembleBundle("reexportrequirebundleA", "/bundles/classloader/reexportrequirebundleA", B.class));
+ VirtualFile assemblyB = assembleBundle("reexportrequirebundleA", "/bundles/classloader/reexportrequirebundleA", B.class);
+ Bundle bundleB = context.installBundle(assemblyB.toURL().toExternalForm());
try
{
- bundle2.start();
- assertLoadClass(bundle2, A.class, bundle1);
- assertLoadClass(bundle2, B.class, bundle2);
+ bundleB.start();
+ assertLoadClass(bundleB, A.class.getName(), bundleA);
+ assertLoadClass(bundleB, B.class.getName(), bundleB);
//Bundle-Name: BundleC
//Bundle-SymbolicName: org.jboss.test.osgi.classloader.bundleC
//Require-Bundle: org.jboss.test.osgi.classloader.bundleB
- Bundle bundle3 = installBundle(assembleBundle("reexportrequirebundleB", "/bundles/classloader/reexportrequirebundleB"));
+ VirtualFile assemblyC = assembleBundle("reexportrequirebundleB", "/bundles/classloader/reexportrequirebundleB");
+ Bundle bundleC = context.installBundle(assemblyC.toURL().toExternalForm());
try
{
- assertLoadClass(bundle3, A.class, bundle1);
- assertLoadClass(bundle3, B.class, bundle2);
+ assertLoadClass(bundleC, A.class.getName(), bundleA);
+ assertLoadClass(bundleC, B.class.getName(), bundleB);
}
finally
{
- uninstall(bundle3);
+ bundleC.uninstall();
}
}
finally
{
- uninstall(bundle2);
+ bundleB.uninstall();
}
}
finally
{
- uninstall(bundle1);
+ bundleA.uninstall();
}
}
+ @Test
public void testNoReExportRequireBundle() throws Exception
{
- Bundle bundle1 = installBundle(assembleBundle("bundleA", "/bundles/classloader/bundleA", A.class));
+ VirtualFile assemblyA = assembleBundle("bundleA", "/bundles/classloader/bundleA", A.class);
+ Bundle bundleA = context.installBundle(assemblyA.toURL().toExternalForm());
try
{
- bundle1.start();
- assertLoadClass(bundle1, A.class);
- Bundle bundle2 = installBundle(assembleBundle("noreexportrequirebundleA", "/bundles/classloader/noreexportrequirebundleA", B.class));
+ bundleA.start();
+ assertLoadClass(bundleA, A.class.getName());
+ VirtualFile assemblyB = assembleBundle("noreexportrequirebundleA", "/bundles/classloader/noreexportrequirebundleA", B.class);
+ Bundle bundleB = context.installBundle(assemblyB.toURL().toExternalForm());
try
{
- bundle2.start();
- assertLoadClass(bundle2, A.class, bundle1);
- assertLoadClass(bundle2, B.class, bundle2);
- Bundle bundle3 = installBundle(assembleBundle("reexportrequirebundleB", "/bundles/classloader/reexportrequirebundleB"));
+ bundleB.start();
+ assertLoadClass(bundleB, A.class.getName(), bundleA);
+ assertLoadClass(bundleB, B.class.getName(), bundleB);
+ VirtualFile assemblyC = assembleBundle("reexportrequirebundleB", "/bundles/classloader/reexportrequirebundleB");
+ Bundle bundleC = context.installBundle(assemblyC.toURL().toExternalForm());
try
{
- assertLoadClassFail(bundle3, A.class);
- assertLoadClass(bundle3, B.class, bundle2);
+ assertLoadClassFail(bundleC, A.class.getName());
+ assertLoadClass(bundleC, B.class.getName(), bundleB);
}
finally
{
- uninstall(bundle3);
+ bundleC.uninstall();
}
}
finally
{
- uninstall(bundle2);
+ bundleB.uninstall();
}
}
finally
{
- uninstall(bundle1);
+ bundleA.uninstall();
}
}
+ @Test
public void testAttributeRequireBundle() throws Exception
{
- Bundle bundle1 = installBundle(assembleBundle("bundleA", "/bundles/classloader/bundleA", A.class));
+ VirtualFile assemblyA = assembleBundle("bundleA", "/bundles/classloader/bundleA", A.class);
+ Bundle bundleA = context.installBundle(assemblyA.toURL().toExternalForm());
try
{
- bundle1.start();
- assertLoadClass(bundle1, A.class);
- Bundle bundle2 = installBundle(assembleBundle("attributerequirebundleA", "/bundles/classloader/attributerequirebundleA", B.class));
+ bundleA.start();
+ assertLoadClass(bundleA, A.class.getName());
+ VirtualFile assemblyB = assembleBundle("attributerequirebundleA", "/bundles/classloader/attributerequirebundleA", B.class);
+ Bundle bundleB = context.installBundle(assemblyB.toURL().toExternalForm());
try
{
- bundle2.start();
- assertLoadClass(bundle2, A.class, bundle1);
- assertLoadClass(bundle2, B.class, bundle2);
+ bundleB.start();
+ assertLoadClass(bundleB, A.class.getName(), bundleA);
+ assertLoadClass(bundleB, B.class.getName(), bundleB);
}
finally
{
- uninstall(bundle2);
+ bundleB.uninstall();
}
}
finally
{
- uninstall(bundle1);
+ bundleA.uninstall();
}
}
+ @Test
public void testAttributeRequireBundleFails() throws Exception
{
// Bundle-SymbolicName: org.jboss.test.osgi.classloader.bundleA;test=x
// Export-Package: org.jboss.test.osgi.classloader.support.a;version=1.0.0;test=x
// Bundle-Version: 1.0.0
- Bundle bundle1 = installBundle(assembleBundle("bundleA", "/bundles/classloader/bundleA", A.class));
+ VirtualFile assemblyA = assembleBundle("bundleA", "/bundles/classloader/bundleA", A.class);
+ Bundle bundleA = context.installBundle(assemblyA.toURL().toExternalForm());
try
{
- bundle1.start();
- assertLoadClass(bundle1, A.class);
+ bundleA.start();
+ assertLoadClass(bundleA, A.class.getName());
// Bundle-SymbolicName: org.jboss.test.osgi.classloader.bundleB
// Require-Bundle: org.jboss.test.osgi.classloader.bundleA;doesnotexist=true;test=y
- Bundle bundle2 = installBundle(assembleBundle("attributerequirebundlefails", "/bundles/classloader/attributerequirebundlefails", B.class));
+ VirtualFile assemblyB = assembleBundle("attributerequirebundlefails", "/bundles/classloader/attributerequirebundlefails", B.class);
+ Bundle bundleB = context.installBundle(assemblyB.toURL().toExternalForm());
try
{
- bundle2.start();
+ bundleB.start();
fail("Should not be here!");
}
catch (BundleException rte)
@@ -340,12 +367,12 @@
}
finally
{
- uninstall(bundle2);
+ bundleB.uninstall();
}
}
finally
{
- uninstall(bundle1);
+ bundleA.uninstall();
}
}
}
Modified: projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/compendium/PackageAdminTestCase.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/compendium/PackageAdminTestCase.java 2010-03-10 13:24:47 UTC (rev 102223)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/compendium/PackageAdminTestCase.java 2010-03-10 13:28:11 UTC (rev 102224)
@@ -21,12 +21,16 @@
*/
package org.jboss.test.osgi.compendium;
-import junit.framework.Test;
+// $Id: $
-import org.jboss.osgi.framework.packageadmin.PackageAdminImpl;
-import org.jboss.test.osgi.FrameworkTest;
-import org.jboss.test.osgi.compendium.support.b.Other;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
+
+import org.jboss.osgi.vfs.VirtualFile;
+import org.jboss.test.osgi.NativeFrameworkTest;
import org.jboss.test.osgi.compendium.support.a.PA;
+import org.jboss.test.osgi.compendium.support.b.Other;
+import org.junit.Test;
import org.osgi.framework.Bundle;
import org.osgi.service.packageadmin.PackageAdmin;
@@ -34,57 +38,46 @@
* Test PackageAdmin service.
*
* @author <a href="mailto:ales.justin@jboss.org">Ales Justin</a>
+ * @author thomas.diesler(a)jboss.com
*/
-public class PackageAdminTestCase extends FrameworkTest
+public class PackageAdminTestCase extends NativeFrameworkTest
{
- public PackageAdminTestCase(String name)
- {
- super(name);
- }
-
- public static Test suite()
- {
- return suite(PackageAdminTestCase.class);
- }
-
- protected PackageAdmin createPackageAdmin()
- {
- return new PackageAdminImpl(getBundleManager());
- }
-
+ @Test
public void testGetBudleFromClass() throws Exception
{
- Bundle bundle = installBundle(assembleBundle("smoke-assembled", "/bundles/smoke/smoke-assembled", PA.class));
+ VirtualFile assemblyA = assembleBundle("smoke-assembled", "/bundles/smoke/smoke-assembled", PA.class);
+ Bundle bundleA = context.installBundle(assemblyA.toURL().toExternalForm());
try
{
- bundle.start();
- Class<?> paClass = assertLoadClass(bundle, PA.class);
+ bundleA.start();
+ Class<?> paClass = assertLoadClass(bundleA, PA.class.getName());
- PackageAdmin pa = createPackageAdmin();
+ PackageAdmin pa = getPackageAdmin();
Bundle found = pa.getBundle(paClass);
- assertSame(bundle, found);
+ assertSame(bundleA, found);
Bundle notFound = pa.getBundle(getClass());
assertNull(notFound);
- Bundle other = installBundle(assembleBundle("simple", "/bundles/simple/simple-bundle1", Other.class));
+ VirtualFile assemblyB = assembleBundle("simple", "/bundles/simple/simple-bundle1", Other.class);
+ Bundle bundleB = context.installBundle(assemblyB.toURL().toExternalForm());
try
{
- other.start();
- Class<?> otherClass = assertLoadClass(other, Other.class);
+ bundleB.start();
+ Class<?> otherClass = assertLoadClass(bundleB, Other.class.getName());
found = pa.getBundle(otherClass);
- assertSame(other, found);
+ assertSame(bundleB, found);
}
finally
{
- other.uninstall();
+ bundleB.uninstall();
}
}
finally
{
- bundle.uninstall();
+ bundleA.uninstall();
}
}
}
Modified: projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/fragments/FragmentTestCase.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/fragments/FragmentTestCase.java 2010-03-10 13:24:47 UTC (rev 102223)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/fragments/FragmentTestCase.java 2010-03-10 13:28:11 UTC (rev 102224)
@@ -31,7 +31,7 @@
import org.jboss.osgi.spi.framework.OSGiBootstrap;
import org.jboss.osgi.spi.framework.OSGiBootstrapProvider;
-import org.jboss.osgi.testing.OSGiTest;
+import org.jboss.test.osgi.NativeFrameworkTest;
import org.jboss.test.osgi.fragments.fragA.FragBeanA;
import org.jboss.test.osgi.fragments.subA.SubBeanA;
import org.junit.After;
@@ -50,7 +50,7 @@
* @author thomas.diesler(a)jboss.com
* @since 07-Jan-2010
*/
-public class FragmentTestCase extends OSGiTest
+public class FragmentTestCase extends NativeFrameworkTest
{
private Framework framework;
private BundleContext context;
@@ -93,7 +93,7 @@
assertNull("Resource URL null", resourceURL);
// Load a private class
- assertBundleLoadClass(hostA, SubBeanA.class.getName(), true);
+ assertLoadClass(hostA, SubBeanA.class.getName());
hostA.uninstall();
assertBundleState(Bundle.UNINSTALLED, hostA.getState());
@@ -155,10 +155,10 @@
assertNotNull("Resource URL not null", resourceURL);
// Load class provided by the fragment
- assertBundleLoadClass(hostA, FragBeanA.class.getName(), true);
+ assertLoadClass(hostA, FragBeanA.class.getName());
// Load a private class
- assertBundleLoadClass(hostA, SubBeanA.class.getName(), true);
+ assertLoadClass(hostA, SubBeanA.class.getName());
hostA.uninstall();
assertBundleState(Bundle.UNINSTALLED, hostA.getState());
@@ -200,7 +200,7 @@
// The fragment contains an overwrites Private-Package with Import-Package
// The SubBeanA is expected to come from HostB, which exports that package
- assertBundleLoadClass(hostB, SubBeanA.class.getName(), true);
+ assertLoadClass(hostB, SubBeanA.class.getName());
hostA.uninstall();
assertBundleState(Bundle.UNINSTALLED, hostA.getState());
Modified: projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/service/GetServiceReferencesUnitTestCase.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/service/GetServiceReferencesUnitTestCase.java 2010-03-10 13:24:47 UTC (rev 102223)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/service/GetServiceReferencesUnitTestCase.java 2010-03-10 13:28:11 UTC (rev 102224)
@@ -21,14 +21,18 @@
*/
package org.jboss.test.osgi.service;
+// $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.osgi.vfs.VirtualFile;
+import org.jboss.test.osgi.NativeFrameworkTest;
import org.jboss.test.osgi.service.support.a.A;
import org.jboss.test.osgi.service.support.b.B;
+import org.junit.Test;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
@@ -41,27 +45,21 @@
*
* todo test service permissions
* @author <a href="adrian(a)jboss.com">Adrian Brock</a>
+ * @author thomas.diesler(a)jboss.com
* @version $Revision: 1.1 $
*/
-public class GetServiceReferencesUnitTestCase extends FrameworkTest
+public class GetServiceReferencesUnitTestCase extends NativeFrameworkTest
{
- public static Test suite()
- {
- return suite(GetServiceReferencesUnitTestCase.class);
- }
- public GetServiceReferencesUnitTestCase(String name)
- {
- super(name);
- }
-
+ @Test
public void testGetServiceReferences() throws Exception
{
- Bundle bundle1 = installBundle(assembleBundle("simple1", "/bundles/simple/simple-bundle1", A.class));
+ VirtualFile assembly = assembleBundle("simple1", "/bundles/simple/simple-bundle1", A.class);
+ Bundle bundle = context.installBundle(assembly.toURL().toExternalForm());
try
{
- bundle1.start();
- BundleContext bundleContext1 = bundle1.getBundleContext();
+ bundle.start();
+ BundleContext bundleContext1 = bundle.getBundleContext();
assertNotNull(bundleContext1);
assertNoGetReference(bundleContext1, A.class.getName());
@@ -71,7 +69,7 @@
assertNoReferences(bundleContext1, B.class.getName());
assertNoAllReferences(bundleContext1, B.class.getName());
- Class<?> clazz = bundle1.loadClass(A.class.getName());
+ Class<?> clazz = bundle.loadClass(A.class.getName());
Object service1 = clazz.newInstance();
ServiceRegistration registration1 = bundleContext1.registerService(A.class.getName(), service1, null);
assertNotNull(registration1);
@@ -99,9 +97,9 @@
bundleContext1.getServiceReference(null);
fail("Should not be here!");
}
- catch (Throwable t)
+ catch (IllegalArgumentException t)
{
- checkThrowable(IllegalArgumentException.class, t);
+ // expected
}
try
@@ -109,9 +107,9 @@
bundleContext1.getServiceReferences(null, "invalid");
fail("Should not be here!");
}
- catch (Throwable t)
+ catch (InvalidSyntaxException t)
{
- checkThrowable(InvalidSyntaxException.class, t);
+ // expected
}
try
@@ -119,21 +117,21 @@
bundleContext1.getAllServiceReferences(null, "invalid");
fail("Should not be here!");
}
- catch (Throwable t)
+ catch (InvalidSyntaxException t)
{
- checkThrowable(InvalidSyntaxException.class, t);
+ // expected
}
- bundle1.stop();
+ bundle.stop();
try
{
bundleContext1.getServiceReference(A.class.getName());
fail("Should not be here!");
}
- catch (Throwable t)
+ catch (IllegalStateException t)
{
- checkThrowable(IllegalStateException.class, t);
+ // expected
}
try
@@ -141,9 +139,9 @@
bundleContext1.getServiceReferences(null, null);
fail("Should not be here!");
}
- catch (Throwable t)
+ catch (IllegalStateException t)
{
- checkThrowable(IllegalStateException.class, t);
+ // expected
}
try
@@ -151,57 +149,61 @@
bundleContext1.getAllServiceReferences(null, null);
fail("Should not be here!");
}
- catch (Throwable t)
+ catch (IllegalStateException t)
{
- checkThrowable(IllegalStateException.class, t);
+ // expected
}
}
finally
{
- uninstall(bundle1);
+ bundle.uninstall();
}
}
+ @Test
public void testGetServiceReferencesNoClassNotAssignable() throws Exception
{
assertGetServiceReferencesNotAssignable(null);
}
+ @Test
public void testGetServiceReferencesNotAssignable() throws Exception
{
assertGetServiceReferencesNotAssignable(A.class.getName());
}
- public void assertGetServiceReferencesNotAssignable(String className) throws Exception
+ private void assertGetServiceReferencesNotAssignable(String className) throws Exception
{
- Bundle bundle1 = installBundle(assembleBundle("simple1", "/bundles/simple/simple-bundle1", A.class));
+ VirtualFile assemblyA = assembleBundle("simple1", "/bundles/simple/simple-bundle1", A.class);
+ Bundle bundleA = context.installBundle(assemblyA.toURL().toExternalForm());
try
{
- bundle1.start();
- BundleContext bundleContext1 = bundle1.getBundleContext();
+ bundleA.start();
+ BundleContext bundleContext1 = bundleA.getBundleContext();
assertNotNull(bundleContext1);
if (className != null)
assertNoGetReference(bundleContext1, className);
- Class<?> clazz = bundle1.loadClass(A.class.getName());
+ Class<?> clazz = bundleA.loadClass(A.class.getName());
Object service1 = clazz.newInstance();
ServiceRegistration registration1 = bundleContext1.registerService(A.class.getName(), service1, null);
assertNotNull(registration1);
ServiceReference reference1 = registration1.getReference();
assertNotNull(reference1);
- Bundle bundle2 = installBundle(assembleBundle("simple2", "/bundles/simple/simple-bundle2", A.class));
+ VirtualFile assemblyB = assembleBundle("simple2", "/bundles/simple/simple-bundle2", A.class);
+ Bundle bundleB = context.installBundle(assemblyB.toURL().toExternalForm());
try
{
- bundle2.start();
- BundleContext bundleContext2 = bundle2.getBundleContext();
+ bundleB.start();
+ BundleContext bundleContext2 = bundleB.getBundleContext();
assertNotNull(bundleContext2);
if (className != null)
assertNoGetReference(bundleContext2, className);
- clazz = bundle2.loadClass(A.class.getName());
+ clazz = bundleB.loadClass(A.class.getName());
Object service2 = clazz.newInstance();
ServiceRegistration registration2 = bundleContext2.registerService(A.class.getName(), service2, null);
assertNotNull(registration2);
@@ -251,55 +253,59 @@
}
finally
{
- uninstall(bundle2);
+ bundleB.uninstall();
}
}
finally
{
- uninstall(bundle1);
+ bundleA.uninstall();
}
}
+ @Test
public void testGetServiceReferencesNoClassAssignable() throws Exception
{
assertGetServiceReferencesAssignable(null);
}
+ @Test
public void testGetServiceReferencesClassAssignable() throws Exception
{
assertGetServiceReferencesAssignable(A.class.getName());
}
- public void assertGetServiceReferencesAssignable(String className) throws Exception
+ private void assertGetServiceReferencesAssignable(String className) throws Exception
{
- Bundle bundle1 = installBundle(assembleBundle("service2", "/bundles/service/service-bundle2", A.class));
+ VirtualFile assemblyA = assembleBundle("service2", "/bundles/service/service-bundle2", A.class);
+ Bundle bundleA = context.installBundle(assemblyA.toURL().toExternalForm());
try
{
- bundle1.start();
- BundleContext bundleContext1 = bundle1.getBundleContext();
+ bundleA.start();
+ BundleContext bundleContext1 = bundleA.getBundleContext();
assertNotNull(bundleContext1);
if (className != null)
assertNoGetReference(bundleContext1, className);
- Class<?> clazz = bundle1.loadClass(A.class.getName());
+ Class<?> clazz = bundleA.loadClass(A.class.getName());
Object service1 = clazz.newInstance();
ServiceRegistration registration1 = bundleContext1.registerService(A.class.getName(), service1, null);
assertNotNull(registration1);
ServiceReference reference1 = registration1.getReference();
assertNotNull(reference1);
- Bundle bundle2 = installBundle(assembleBundle("service1", "/bundles/service/service-bundle1"));
+ VirtualFile assemblyB = assembleBundle("service1", "/bundles/service/service-bundle1");
+ Bundle bundleB = context.installBundle(assemblyB.toURL().toExternalForm());
try
{
- bundle2.start();
- BundleContext bundleContext2 = bundle2.getBundleContext();
+ bundleB.start();
+ BundleContext bundleContext2 = bundleB.getBundleContext();
assertNotNull(bundleContext2);
if (className != null)
assertGetReference(bundleContext2, className, reference1);
- clazz = bundle2.loadClass(A.class.getName());
+ clazz = bundleB.loadClass(A.class.getName());
Object service2 = clazz.newInstance();
ServiceRegistration registration2 = bundleContext2.registerService(A.class.getName(), service2, null);
assertNotNull(registration2);
@@ -349,24 +355,26 @@
}
finally
{
- uninstall(bundle2);
+ bundleB.uninstall();
}
}
finally
{
- uninstall(bundle1);
+ bundleA.uninstall();
}
}
+ @Test
public void testGetServiceReferencesRankings() throws Exception
{
String className = A.class.getName();
- Bundle bundle1 = installBundle(assembleBundle("service2", "/bundles/service/service-bundle2", A.class));
+ VirtualFile assemblyA = assembleBundle("service2", "/bundles/service/service-bundle2", A.class);
+ Bundle bundleA = context.installBundle(assemblyA.toURL().toExternalForm());
try
{
- bundle1.start();
- BundleContext bundleContext1 = bundle1.getBundleContext();
+ bundleA.start();
+ BundleContext bundleContext1 = bundleA.getBundleContext();
assertNotNull(bundleContext1);
assertNoGetReference(bundleContext1, className);
@@ -375,18 +383,19 @@
Dictionary<String, Object> properties1 = new Hashtable<String, Object>();
properties1.put(Constants.SERVICE_RANKING, 1);
- Class<?> clazz = bundle1.loadClass(className);
+ Class<?> clazz = bundleA.loadClass(className);
Object service1 = clazz.newInstance();
ServiceRegistration registration1 = bundleContext1.registerService(className, service1, properties1);
assertNotNull(registration1);
ServiceReference reference1 = registration1.getReference();
assertNotNull(reference1);
- Bundle bundle2 = installBundle(assembleBundle("service1", "/bundles/service/service-bundle1"));
+ VirtualFile assemblyB = assembleBundle("service1", "/bundles/service/service-bundle1");
+ Bundle bundleB = context.installBundle(assemblyB.toURL().toExternalForm());
try
{
- bundle2.start();
- BundleContext bundleContext2 = bundle2.getBundleContext();
+ bundleB.start();
+ BundleContext bundleContext2 = bundleB.getBundleContext();
assertNotNull(bundleContext2);
assertGetReference(bundleContext2, className, reference1);
@@ -395,7 +404,7 @@
Dictionary<String, Object> properties2 = new Hashtable<String, Object>();
properties2.put(Constants.SERVICE_RANKING, 2);
- clazz = bundle2.loadClass(className);
+ clazz = bundleB.loadClass(className);
Object service2 = clazz.newInstance();
ServiceRegistration registration2 = bundleContext2.registerService(className, service2, properties2);
assertNotNull(registration2);
@@ -456,25 +465,27 @@
}
finally
{
- uninstall(bundle2);
+ bundleB.uninstall();
}
}
finally
{
- uninstall(bundle1);
+ bundleA.uninstall();
}
}
+ @Test
public void testGetServiceReferencesFilterted() throws Exception
{
String className = A.class.getName();
String wrongClassName = B.class.getName();
- Bundle bundle1 = installBundle(assembleBundle("simple1", "/bundles/simple/simple-bundle1", A.class));
+ VirtualFile assembly = assembleBundle("simple1", "/bundles/simple/simple-bundle1", A.class);
+ Bundle bundle = context.installBundle(assembly.toURL().toExternalForm());
try
{
- bundle1.start();
- BundleContext bundleContext1 = bundle1.getBundleContext();
+ bundle.start();
+ BundleContext bundleContext1 = bundle.getBundleContext();
assertNotNull(bundleContext1);
assertNoGetReference(bundleContext1, A.class.getName());
@@ -507,7 +518,7 @@
properties.put("a", "b");
properties.put("c", "d");
- Class<?> clazz = bundle1.loadClass(A.class.getName());
+ Class<?> clazz = bundle.loadClass(A.class.getName());
Object service1 = clazz.newInstance();
ServiceRegistration registration1 = bundleContext1.registerService(A.class.getName(), service1, properties);
assertNotNull(registration1);
@@ -570,7 +581,7 @@
}
finally
{
- uninstall(bundle1);
+ bundle.uninstall();
}
}
}
Modified: projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/service/GetUnGetServiceUnitTestCase.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/service/GetUnGetServiceUnitTestCase.java 2010-03-10 13:24:47 UTC (rev 102223)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/service/GetUnGetServiceUnitTestCase.java 2010-03-10 13:28:11 UTC (rev 102224)
@@ -21,12 +21,15 @@
*/
package org.jboss.test.osgi.service;
-import junit.framework.Test;
+import static org.junit.Assert.*;
-import org.jboss.test.osgi.FrameworkTest;
+import org.jboss.osgi.vfs.VirtualFile;
+import org.jboss.test.osgi.NativeFrameworkTest;
import org.jboss.test.osgi.service.support.BrokenServiceFactory;
+import org.junit.Test;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
import org.osgi.framework.FrameworkEvent;
import org.osgi.framework.ServiceReference;
import org.osgi.framework.ServiceRegistration;
@@ -38,23 +41,15 @@
* @author <a href="ales.justin(a)jboss.org">Ales Justin</a>
* @version $Revision: 1.1 $
*/
-public class GetUnGetServiceUnitTestCase extends FrameworkTest
+public class GetUnGetServiceUnitTestCase extends NativeFrameworkTest
{
static String OBJCLASS = BundleContext.class.getName();
- public static Test suite()
- {
- return suite(GetUnGetServiceUnitTestCase.class);
- }
-
- public GetUnGetServiceUnitTestCase(String name)
- {
- super(name);
- }
-
+ @Test
public void testGetUnServiceErrors() 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();
@@ -68,9 +63,9 @@
bundleContext.getService(null);
fail("Should not be here!");
}
- catch (Throwable t)
+ catch (IllegalArgumentException t)
{
- checkThrowable(IllegalArgumentException.class, t);
+ // expected
}
try
@@ -78,20 +73,22 @@
bundleContext.ungetService(null);
fail("Should not be here!");
}
- catch (Throwable t)
+ catch (IllegalArgumentException t)
{
- checkThrowable(IllegalArgumentException.class, t);
+ // expected
}
}
finally
{
- uninstall(bundle);
+ bundle.uninstall();
}
}
+ @Test
public void testGetService() 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();
@@ -110,13 +107,15 @@
}
finally
{
- uninstall(bundle);
+ bundle.uninstall();
}
}
+ @Test
public void testGetServiceAfterStop() 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();
@@ -135,20 +134,22 @@
bundleContext.getService(reference);
fail("Should not be here!");
}
- catch (Throwable t)
+ catch (IllegalStateException t)
{
- checkThrowable(IllegalStateException.class, t);
+ // expected
}
}
finally
{
- uninstall(bundle);
+ bundle.uninstall();
}
}
+ @Test
public void testErrorInGetService() 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();
@@ -162,17 +163,19 @@
Object actual = bundleContext.getService(reference);
assertNull("" + actual, actual);
- assertFrameworkEvent(FrameworkEvent.ERROR, bundle, RuntimeException.class);
+ assertFrameworkEvent(FrameworkEvent.ERROR, bundle, BundleException.class);
}
finally
{
- uninstall(bundle);
+ bundle.uninstall();
}
}
+ @Test
public void testErrorInUnGetService() 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();
@@ -189,21 +192,23 @@
registration.unregister();
- assertFrameworkEvent(FrameworkEvent.WARNING, bundle, RuntimeException.class);
+ assertFrameworkEvent(FrameworkEvent.WARNING, bundle, BundleException.class);
}
finally
{
- uninstall(bundle);
+ bundle.uninstall();
}
}
+ @Test
public void testUnGetServiceResult() throws Exception
{
- Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ VirtualFile assembly1 = assembleBundle("simple-bundle1", "/bundles/simple/simple-bundle1", new Class[0]);
+ Bundle bundle1 = context.installBundle(assembly1.toURL().toExternalForm());
try
{
- bundle.start();
- BundleContext bundleContext = bundle.getBundleContext();
+ bundle1.start();
+ BundleContext bundleContext = bundle1.getBundleContext();
assertNotNull(bundleContext);
ServiceRegistration registration = bundleContext.registerService(OBJCLASS, bundleContext, null);
@@ -217,7 +222,8 @@
assertTrue(bundleContext.ungetService(reference));
assertFalse(bundleContext.ungetService(reference));
- 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());
try
{
bundle2.start();
@@ -233,12 +239,12 @@
}
finally
{
- uninstall(bundle2);
+ bundle2.uninstall();
}
}
finally
{
- uninstall(bundle);
+ bundle1.uninstall();
}
}
}
Modified: projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/service/RegisterServiceUnitTestCase.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/service/RegisterServiceUnitTestCase.java 2010-03-10 13:24:47 UTC (rev 102223)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/service/RegisterServiceUnitTestCase.java 2010-03-10 13:28:11 UTC (rev 102224)
@@ -21,12 +21,14 @@
*/
package org.jboss.test.osgi.service;
+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.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.Constants;
@@ -41,27 +43,19 @@
* @author <a href="ales.justin(a)jboss.org">Ales Justin</a>
* @version $Revision: 1.1 $
*/
-public class RegisterServiceUnitTestCase extends FrameworkTest
+public class RegisterServiceUnitTestCase extends NativeFrameworkTest
{
static String OBJCLASS = BundleContext.class.getName();
static String[] OBJCLASSES = new String[] { OBJCLASS };
- public static Test suite()
- {
- return suite(RegisterServiceUnitTestCase.class);
- }
-
- public RegisterServiceUnitTestCase(String name)
- {
- super(name);
- }
-
+ @Test
public void testRegisterServiceErrors() throws Exception
{
String OBJCLASS = BundleContext.class.getName();
String[] OBJCLASSES = new String[] { OBJCLASS };
- 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();
@@ -73,9 +67,9 @@
bundleContext.registerService((String) null, new Object(), null);
fail("Should not be here!");
}
- catch (Throwable t)
+ catch (IllegalArgumentException t)
{
- checkThrowable(IllegalArgumentException.class, t);
+ // expected
}
try
@@ -83,9 +77,9 @@
bundleContext.registerService((String[]) null, new Object(), null);
fail("Should not be here!");
}
- catch (Throwable t)
+ catch (IllegalArgumentException t)
{
- checkThrowable(IllegalArgumentException.class, t);
+ // expected
}
try
@@ -93,9 +87,9 @@
bundleContext.registerService(new String[0], new Object(), null);
fail("Should not be here!");
}
- catch (Throwable t)
+ catch (IllegalArgumentException t)
{
- checkThrowable(IllegalArgumentException.class, t);
+ // expected
}
try
@@ -103,9 +97,9 @@
bundleContext.registerService(OBJCLASS, null, null);
fail("Should not be here!");
}
- catch (Throwable t)
+ catch (IllegalArgumentException t)
{
- checkThrowable(IllegalArgumentException.class, t);
+ // expected
}
try
@@ -113,9 +107,9 @@
bundleContext.registerService(OBJCLASSES, null, null);
fail("Should not be here!");
}
- catch (Throwable t)
+ catch (IllegalArgumentException t)
{
- checkThrowable(IllegalArgumentException.class, t);
+ // expected
}
try
@@ -123,9 +117,9 @@
bundleContext.registerService(OBJCLASS, new Object(), null);
fail("Should not be here!");
}
- catch (Throwable t)
+ catch (IllegalArgumentException t)
{
- checkThrowable(IllegalArgumentException.class, t);
+ // expected
}
try
@@ -133,9 +127,9 @@
bundleContext.registerService(OBJCLASSES, new Object(), null);
fail("Should not be here!");
}
- catch (Throwable t)
+ catch (IllegalArgumentException t)
{
- checkThrowable(IllegalArgumentException.class, t);
+ // expected
}
Dictionary<String, Object> properties = new Hashtable<String, Object>();
@@ -146,9 +140,9 @@
bundleContext.registerService(OBJCLASS, bundleContext, properties);
fail("Should not be here!");
}
- catch (Throwable t)
+ catch (IllegalArgumentException t)
{
- checkThrowable(IllegalArgumentException.class, t);
+ // expected
}
try
@@ -156,9 +150,9 @@
bundleContext.registerService(OBJCLASSES, bundleContext, properties);
fail("Should not be here!");
}
- catch (Throwable t)
+ catch (IllegalArgumentException t)
{
- checkThrowable(IllegalArgumentException.class, t);
+ // expected
}
bundle.stop();
@@ -168,9 +162,9 @@
bundleContext.registerService(OBJCLASS, bundleContext, null);
fail("Should not be here!");
}
- catch (Throwable t)
+ catch (IllegalStateException t)
{
- checkThrowable(IllegalStateException.class, t);
+ // expected
}
try
@@ -178,23 +172,25 @@
bundleContext.registerService(OBJCLASSES, bundleContext, null);
fail("Should not be here!");
}
- catch (Throwable t)
+ catch (IllegalStateException t)
{
- checkThrowable(IllegalStateException.class, t);
+ // expected
}
}
finally
{
- uninstall(bundle);
+ bundle.uninstall();
}
}
+ @Test
public void testRegisterServiceOBJCLASS() throws Exception
{
Dictionary<String, Object> properties = new Hashtable<String, Object>();
properties.put(Constants.OBJECTCLASS, new String[] { "rubbish" });
- 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();
@@ -217,13 +213,15 @@
}
finally
{
- uninstall(bundle);
+ bundle.uninstall();
}
}
+ @Test
public void testRegisterService() 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();
@@ -242,13 +240,15 @@
}
finally
{
- uninstall(bundle);
+ bundle.uninstall();
}
}
+ @Test
public void testBundleUninstall() 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());
try
{
bundle1.start();
@@ -260,7 +260,8 @@
Object actual = bundleContext.getService(reference);
assertEquals(bundleContext, 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());
try
{
bundle2.start();
@@ -272,7 +273,7 @@
}
finally
{
- uninstall(bundle2);
+ bundle2.uninstall();
}
actual = bundleContext.getService(reference);
@@ -280,13 +281,15 @@
}
finally
{
- uninstall(bundle1);
+ bundle1.uninstall();
}
}
+ @Test
public void testRegisteredServices() 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());
try
{
bundle1.start();
@@ -298,7 +301,8 @@
Object actual = bundleContext.getService(reference);
assertEquals(bundleContext, 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());
try
{
bundle2.start();
@@ -312,11 +316,11 @@
assertNull(registered);
registered = bundle1.getRegisteredServices();
- assertEquals(new ServiceReference[]{reference}, registered);
+ assertArrayEquals(new ServiceReference[]{reference}, registered);
}
finally
{
- uninstall(bundle2);
+ bundle2.uninstall();
}
actual = bundleContext.getService(reference);
@@ -324,7 +328,22 @@
}
finally
{
- uninstall(bundle1);
+ bundle1.uninstall();
}
}
+
+ protected void assertObjectClass(String expected, ServiceReference reference)
+ {
+ assertObjectClass(new String[] { expected }, reference);
+ }
+
+ protected void assertObjectClass(String[] expected, ServiceReference reference)
+ {
+ Object actual = reference.getProperty(Constants.OBJECTCLASS);
+ if (actual == null)
+ fail("no object class???");
+ if (actual instanceof String[] == false)
+ fail(actual + " is not a string array??? " + actual.getClass().getName());
+ assertArrayEquals(expected, (String[])actual);
+ }
}
Modified: projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/service/ServiceFactoryUnitTestCase.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/service/ServiceFactoryUnitTestCase.java 2010-03-10 13:24:47 UTC (rev 102223)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/service/ServiceFactoryUnitTestCase.java 2010-03-10 13:28:11 UTC (rev 102224)
@@ -21,11 +21,15 @@
*/
package org.jboss.test.osgi.service;
-import junit.framework.Test;
+import static org.junit.Assert.*;
+
import org.jboss.osgi.framework.bundle.OSGiBundleWrapper;
-import org.jboss.test.osgi.FrameworkTest;
+import org.jboss.osgi.vfs.VirtualFile;
+import org.jboss.test.osgi.NativeFrameworkTest;
import org.jboss.test.osgi.service.support.SimpleServiceFactory;
+import org.jboss.test.osgi.service.support.a.A;
+import org.junit.Test;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.FrameworkEvent;
@@ -39,24 +43,17 @@
* @author Thomas.Diesler(a)jboss.com
* @version $Revision$
*/
-public class ServiceFactoryUnitTestCase extends FrameworkTest
+public class ServiceFactoryUnitTestCase extends NativeFrameworkTest
{
static String OBJCLASS = BundleContext.class.getName();
static String[] OBJCLASSES = new String[] { OBJCLASS };
- public static Test suite()
- {
- return suite(ServiceFactoryUnitTestCase.class);
- }
- public ServiceFactoryUnitTestCase(String name)
- {
- super(name);
- }
-
+ @Test
public void testRegisterServiceFactory() throws Exception
{
- Bundle bundleA = addBundle("/bundles/simple/", "simple-bundle1");
+ VirtualFile assemblyA = assembleBundle("simple1", "/bundles/simple/simple-bundle1", A.class);
+ Bundle bundleA = context.installBundle(assemblyA.toURL().toExternalForm());
try
{
bundleA.start();
@@ -80,7 +77,8 @@
assertEquals(bundleA.getSymbolicName(), serviceFactory.getBundle.getSymbolicName());
assertEquals(1, serviceFactory.getCount);
- Bundle bundleB = addBundle("/bundles/simple/", "simple-bundle2");
+ VirtualFile assemblyB = assembleBundle("simple2", "/bundles/simple/simple-bundle2");
+ Bundle bundleB = context.installBundle(assemblyB.toURL().toExternalForm());
try
{
bundleB.start();
@@ -97,12 +95,12 @@
}
finally
{
- uninstall(bundleB);
+ bundleB.uninstall();
}
}
finally
{
- uninstall(bundleA);
+ bundleA.uninstall();
}
}
@@ -110,7 +108,8 @@
{
String OBJCLASS = BundleContext.class.getName();
- Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ VirtualFile assembly = assembleBundle("simple1", "/bundles/simple/simple-bundle1");
+ Bundle bundle = context.installBundle(assembly.toURL().toExternalForm());
try
{
bundle.start();
@@ -132,7 +131,7 @@
}
finally
{
- uninstall(bundle);
+ bundle.uninstall();
}
}
@@ -140,7 +139,8 @@
{
String OBJCLASS = BundleContext.class.getName();
- Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ VirtualFile assembly = assembleBundle("simple1", "/bundles/simple/simple-bundle1");
+ Bundle bundle = context.installBundle(assembly.toURL().toExternalForm());
try
{
bundle.start();
@@ -159,14 +159,14 @@
bundleContext.getService(reference);
fail("Should not be here!");
}
- catch (Throwable t)
+ catch (IllegalStateException t)
{
- checkThrowable(IllegalStateException.class, t);
+ // expected
}
}
finally
{
- uninstall(bundle);
+ bundle.uninstall();
}
}
@@ -174,7 +174,8 @@
{
String[] OBJCLASSES = {String.class.getName(), BundleContext.class.getName()};
- Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ VirtualFile assembly = assembleBundle("simple1", "/bundles/simple/simple-bundle1");
+ Bundle bundle = context.installBundle(assembly.toURL().toExternalForm());
try
{
bundle.start();
@@ -199,7 +200,7 @@
}
finally
{
- uninstall(bundle);
+ bundle.uninstall();
}
}
}
Modified: projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/service/ServiceReferenceUnitTestCase.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/service/ServiceReferenceUnitTestCase.java 2010-03-10 13:24:47 UTC (rev 102223)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/service/ServiceReferenceUnitTestCase.java 2010-03-10 13:28:11 UTC (rev 102224)
@@ -21,6 +21,8 @@
*/
package org.jboss.test.osgi.service;
+import static org.junit.Assert.*;
+
import java.util.Dictionary;
import java.util.HashSet;
import java.util.Hashtable;
@@ -28,10 +30,10 @@
import java.util.Set;
import java.util.TreeSet;
-import junit.framework.Test;
-
-import org.jboss.test.osgi.FrameworkTest;
+import org.jboss.osgi.vfs.VirtualFile;
+import org.jboss.test.osgi.NativeFrameworkTest;
import org.jboss.test.osgi.service.support.a.A;
+import org.junit.Test;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
@@ -45,25 +47,17 @@
* @author <a href="adrian(a)jboss.com">Adrian Brock</a>
* @version $Revision: 1.1 $
*/
-public class ServiceReferenceUnitTestCase extends FrameworkTest
+public class ServiceReferenceUnitTestCase extends NativeFrameworkTest
{
- public ServiceReferenceUnitTestCase(String name)
- {
- super(name);
- }
-
- public static Test suite()
- {
- return suite(ServiceReferenceUnitTestCase.class);
- }
-
+ @Test
public void testGetProperty() throws Exception
{
ServiceReference reference = null;
String[] clazzes = new String[] { BundleContext.class.getName() };
Object serviceID = null;
- Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ VirtualFile assembly = assembleBundle("simple1", "/bundles/simple/simple-bundle1");
+ Bundle bundle = context.installBundle(assembly.toURL().toExternalForm());
try
{
bundle.start();
@@ -84,9 +78,9 @@
assertNotNull(serviceID);
assertEquals(serviceID, reference.getProperty(Constants.SERVICE_ID.toLowerCase()));
assertEquals(serviceID, reference.getProperty(Constants.SERVICE_ID.toUpperCase()));
- assertEquals(clazzes, (String[]) reference.getProperty(Constants.OBJECTCLASS));
- assertEquals(clazzes, (String[]) reference.getProperty(Constants.OBJECTCLASS.toLowerCase()));
- assertEquals(clazzes, (String[]) reference.getProperty(Constants.OBJECTCLASS.toUpperCase()));
+ assertArrayEquals(clazzes, (String[]) reference.getProperty(Constants.OBJECTCLASS));
+ assertArrayEquals(clazzes, (String[]) reference.getProperty(Constants.OBJECTCLASS.toLowerCase()));
+ assertArrayEquals(clazzes, (String[]) reference.getProperty(Constants.OBJECTCLASS.toUpperCase()));
assertEquals("a", reference.getProperty("testA"));
assertEquals("b", reference.getProperty("testB"));
assertEquals("Case", reference.getProperty("MiXeD"));
@@ -143,7 +137,7 @@
}
finally
{
- uninstall(bundle);
+ bundle.uninstall();
}
assertEquals(serviceID, reference.getProperty(Constants.SERVICE_ID));
@@ -156,11 +150,13 @@
assertNull(reference.getProperty(null));
}
+ @Test
public void testGetPropertyKeys() throws Exception
{
ServiceReference reference = null;
- Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ VirtualFile assembly = assembleBundle("simple1", "/bundles/simple/simple-bundle1");
+ Bundle bundle = context.installBundle(assembly.toURL().toExternalForm());
try
{
bundle.start();
@@ -196,12 +192,12 @@
}
finally
{
- uninstall(bundle);
+ bundle.uninstall();
}
assertPropertyKeys(reference, "testA", "testB", "testC", "MiXeD");
}
- protected void assertPropertyKeys(ServiceReference reference, String... expectedKeys)
+ private void assertPropertyKeys(ServiceReference reference, String... expectedKeys)
{
Set<String> expected = new HashSet<String>();
expected.add(Constants.SERVICE_ID);
@@ -216,9 +212,11 @@
assertEquals(expected, actual);
}
+ @Test
public void testGetBundle() throws Exception
{
- Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ VirtualFile assembly = assembleBundle("simple1", "/bundles/simple/simple-bundle1");
+ Bundle bundle = context.installBundle(assembly.toURL().toExternalForm());
try
{
bundle.start();
@@ -241,13 +239,15 @@
}
finally
{
- uninstall(bundle);
+ bundle.uninstall();
}
}
+ @Test
public void testGetBundleAfterStop() throws Exception
{
- Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ VirtualFile assembly = assembleBundle("simple1", "/bundles/simple/simple-bundle1");
+ Bundle bundle = context.installBundle(assembly.toURL().toExternalForm());
try
{
bundle.start();
@@ -270,17 +270,19 @@
}
finally
{
- uninstall(bundle);
+ bundle.uninstall();
}
}
+ @Test
public void testUsingBundles() throws Exception
{
- Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ VirtualFile assembly1 = assembleBundle("simple1", "/bundles/simple/simple-bundle1");
+ Bundle bundle1 = context.installBundle(assembly1.toURL().toExternalForm());
try
{
- bundle.start();
- BundleContext bundleContext = bundle.getBundleContext();
+ bundle1.start();
+ BundleContext bundleContext = bundle1.getBundleContext();
assertNotNull(bundleContext);
ServiceRegistration registration = bundleContext.registerService(BundleContext.class.getName(), bundleContext, null);
@@ -291,7 +293,8 @@
assertUsingBundles(reference);
- Bundle bundle2 = addBundle("/bundles/simple/", "simple-bundle2");
+ VirtualFile assembly2 = assembleBundle("simple2", "/bundles/simple/simple-bundle2");
+ Bundle bundle2 = context.installBundle(assembly2.toURL().toExternalForm());
try
{
bundle2.start();
@@ -314,29 +317,31 @@
bundleContext.getService(reference);
bundleContext2.getService(reference);
- assertUsingBundles(reference, bundle, bundle2);
+ assertUsingBundles(reference, bundle1, bundle2);
registration.unregister();
assertUsingBundles(reference);
}
finally
{
- uninstall(bundle2);
+ bundle2.uninstall();
}
}
finally
{
- uninstall(bundle);
+ bundle1.uninstall();
}
}
+ @Test
public void testUsingBundlesAfterStop() throws Exception
{
- Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ VirtualFile assembly1 = assembleBundle("simple1", "/bundles/simple/simple-bundle1");
+ Bundle bundle1 = context.installBundle(assembly1.toURL().toExternalForm());
try
{
- bundle.start();
- BundleContext bundleContext = bundle.getBundleContext();
+ bundle1.start();
+ BundleContext bundleContext = bundle1.getBundleContext();
assertNotNull(bundleContext);
ServiceRegistration registration = bundleContext.registerService(BundleContext.class.getName(), bundleContext, null);
@@ -347,7 +352,8 @@
assertUsingBundles(reference);
- Bundle bundle2 = addBundle("/bundles/simple/", "simple-bundle2");
+ VirtualFile assembly2 = assembleBundle("simple2", "/bundles/simple/simple-bundle2");
+ Bundle bundle2 = context.installBundle(assembly2.toURL().toExternalForm());
try
{
bundle2.start();
@@ -356,25 +362,27 @@
bundleContext.getService(reference);
bundleContext2.getService(reference);
- assertUsingBundles(reference, bundle, bundle2);
+ assertUsingBundles(reference, bundle1, bundle2);
- bundle.stop();
+ bundle1.stop();
assertUsingBundles(reference);
}
finally
{
- uninstall(bundle2);
+ bundle2.uninstall();
}
}
finally
{
- uninstall(bundle);
+ bundle1.uninstall();
}
}
+ @Test
public void testIsAssignableToErrors() throws Exception
{
- Bundle bundle = installBundle(assembleBundle("simple1", "/bundles/simple/simple-bundle1", A.class));
+ VirtualFile assembly = assembleBundle("simple1", "/bundles/simple/simple-bundle1", A.class);
+ Bundle bundle = context.installBundle(assembly.toURL().toExternalForm());
try
{
bundle.start();
@@ -392,9 +400,9 @@
reference.isAssignableTo(null, A.class.getName());
fail("Should not be here!");
}
- catch (Throwable t)
+ catch (IllegalArgumentException t)
{
- checkThrowable(IllegalArgumentException.class, t);
+ // expected
}
try
@@ -402,24 +410,26 @@
reference.isAssignableTo(bundle, null);
fail("Should not be here!");
}
- catch (Throwable t)
+ catch (IllegalArgumentException t)
{
- checkThrowable(IllegalArgumentException.class, t);
+ // expected
}
}
finally
{
- uninstall(bundle);
+ bundle.uninstall();
}
}
+ @Test
public void testNotAssignableTo() throws Exception
{
- Bundle bundle = installBundle(assembleBundle("simple1", "/bundles/simple/simple-bundle1", A.class));
+ VirtualFile assembly1 = assembleBundle("simple1", "/bundles/simple/simple-bundle1", A.class);
+ Bundle bundle1 = context.installBundle(assembly1.toURL().toExternalForm());
try
{
- bundle.start();
- BundleContext bundleContext = bundle.getBundleContext();
+ bundle1.start();
+ BundleContext bundleContext = bundle1.getBundleContext();
assertNotNull(bundleContext);
ServiceRegistration registration = bundleContext.registerService(BundleContext.class.getName(), bundleContext, null);
@@ -428,7 +438,8 @@
ServiceReference reference = registration.getReference();
assertNotNull(reference);
- Bundle bundle2 = installBundle(assembleBundle("simple2", "/bundles/simple/simple-bundle2", A.class));
+ VirtualFile assembly2 = assembleBundle("simple2", "/bundles/simple/simple-bundle2", A.class);
+ Bundle bundle2 = context.installBundle(assembly2.toURL().toExternalForm());
try
{
assertFalse(reference.isAssignableTo(bundle2, A.class.getName()));
@@ -440,21 +451,23 @@
}
finally
{
- uninstall(bundle2);
+ bundle2.uninstall();
}
}
finally
{
- uninstall(bundle);
+ bundle1.uninstall();
}
}
+ @Test
public void testIsAssignableTo() throws Exception
{
//Bundle-Name: Service2
//Bundle-SymbolicName: org.jboss.test.osgi.service2
//Export-Package: org.jboss.test.osgi.service.support.a
- Bundle bundle2 = installBundle(assembleBundle("service2", "/bundles/service/service-bundle2", A.class));
+ VirtualFile assembly2 = assembleBundle("service2", "/bundles/service/service-bundle2", A.class);
+ Bundle bundle2 = context.installBundle(assembly2.toURL().toExternalForm());
try
{
@@ -465,7 +478,8 @@
//Bundle-Name: Service1
//Bundle-SymbolicName: org.jboss.test.osgi.service1
//Import-Package: org.jboss.test.osgi.service.support.a
- Bundle bundle1 = installBundle(assembleBundle("service1", "/bundles/service/service-bundle1"));
+ VirtualFile assembly1 = assembleBundle("service1", "/bundles/service/service-bundle1");
+ Bundle bundle1 = context.installBundle(assembly1.toURL().toExternalForm());
try
{
@@ -489,18 +503,20 @@
}
finally
{
- uninstall(bundle1);
+ bundle1.uninstall();
}
}
finally
{
- uninstall(bundle2);
+ bundle2.uninstall();
}
}
+ @Test
public void testCompareTo() throws Exception
{
- Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ VirtualFile assembly = assembleBundle("simple1", "/bundles/simple/simple-bundle1");
+ Bundle bundle = context.installBundle(assembly.toURL().toExternalForm());
try
{
bundle.start();
@@ -547,9 +563,9 @@
reference1.compareTo(null);
fail("Should not be here!");
}
- catch (Throwable t)
+ catch (IllegalArgumentException t)
{
- checkThrowable(IllegalArgumentException.class, t);
+ // expected
}
try
@@ -557,9 +573,9 @@
reference1.compareTo(new Object());
fail("Should not be here!");
}
- catch (Throwable t)
+ catch (IllegalArgumentException t)
{
- checkThrowable(IllegalArgumentException.class, t);
+ // expected
}
properties = new Hashtable<String, Object>();
@@ -600,7 +616,7 @@
}
finally
{
- uninstall(bundle);
+ bundle.uninstall();
}
}
Modified: projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/service/ServiceRegistrationUnitTestCase.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/service/ServiceRegistrationUnitTestCase.java 2010-03-10 13:24:47 UTC (rev 102223)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/service/ServiceRegistrationUnitTestCase.java 2010-03-10 13:28:11 UTC (rev 102224)
@@ -21,12 +21,19 @@
*/
package org.jboss.test.osgi.service;
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNotSame;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.fail;
+
import java.util.Hashtable;
-import junit.framework.Test;
-
-import org.jboss.test.osgi.FrameworkTest;
+import org.jboss.osgi.vfs.VirtualFile;
+import org.jboss.test.osgi.NativeFrameworkTest;
import org.jboss.test.osgi.service.support.SimpleServiceFactory;
+import org.junit.Test;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
@@ -40,21 +47,14 @@
* @author <a href="adrian(a)jboss.com">Adrian Brock</a>
* @version $Revision: 1.1 $
*/
-public class ServiceRegistrationUnitTestCase extends FrameworkTest
+public class ServiceRegistrationUnitTestCase extends NativeFrameworkTest
{
- public ServiceRegistrationUnitTestCase(String name)
- {
- super(name);
- }
- public static Test suite()
- {
- return suite(ServiceRegistrationUnitTestCase.class);
- }
-
+ @Test
public void testGetReference() throws Exception
{
- Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ VirtualFile assembly = assembleBundle("simple1", "/bundles/simple/simple-bundle1");
+ Bundle bundle = context.installBundle(assembly.toURL().toExternalForm());
try
{
bundle.start();
@@ -82,9 +82,9 @@
registration.getReference();
fail("Should not be here!");
}
- catch (Throwable t)
+ catch (IllegalStateException t)
{
- checkThrowable(IllegalStateException.class, t);
+ // expected
}
ServiceRegistration registration2 = bundleContext.registerService(BundleContext.class.getName(), bundleContext, null);
@@ -101,20 +101,22 @@
registration2.getReference();
fail("Should not be here!");
}
- catch (Throwable t)
+ catch (IllegalStateException t)
{
- checkThrowable(IllegalStateException.class, t);
+ // expected
}
}
finally
{
- uninstall(bundle);
+ bundle.uninstall();
}
}
+ @Test
public void testSetProperties() throws Exception
{
- Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ VirtualFile assembly = assembleBundle("simple1", "/bundles/simple/simple-bundle1");
+ Bundle bundle = context.installBundle(assembly.toURL().toExternalForm());
try
{
bundle.start();
@@ -193,9 +195,9 @@
registration.setProperties(properties);
fail("Should not be here!");
}
- catch (Throwable t)
+ catch (IllegalArgumentException t)
{
- checkThrowable(IllegalArgumentException.class, t);
+ // expected
}
assertNoServiceEvent();
@@ -207,21 +209,23 @@
registration.setProperties(new Hashtable<String, Object>());
fail("Should not be here!");
}
- catch (Throwable t)
+ catch (IllegalStateException t)
{
- checkThrowable(IllegalStateException.class, t);
+ // expected
}
assertNoServiceEvent();
}
finally
{
- uninstall(bundle);
+ bundle.uninstall();
}
}
+ @Test
public void testSetPropertiesAfterStop() throws Exception
{
- Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ VirtualFile assembly = assembleBundle("simple1", "/bundles/simple/simple-bundle1");
+ Bundle bundle = context.installBundle(assembly.toURL().toExternalForm());
try
{
bundle.start();
@@ -238,25 +242,27 @@
registration.setProperties(new Hashtable<String, Object>());
fail("Should not be here!");
}
- catch (Throwable t)
+ catch (IllegalStateException t)
{
- checkThrowable(IllegalStateException.class, t);
+ // expected
}
assertNoServiceEvent();
}
finally
{
- uninstall(bundle);
+ bundle.uninstall();
}
}
+ @Test
public void testUnregister() throws Exception
{
- Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ VirtualFile assembly1 = assembleBundle("simple1", "/bundles/simple/simple-bundle1");
+ Bundle bundle1 = context.installBundle(assembly1.toURL().toExternalForm());
try
{
- bundle.start();
- BundleContext bundleContext = bundle.getBundleContext();
+ bundle1.start();
+ BundleContext bundleContext = bundle1.getBundleContext();
assertNotNull(bundleContext);
SimpleServiceFactory factory = new SimpleServiceFactory(bundleContext);
@@ -269,14 +275,15 @@
ServiceReference reference2 = bundleContext.getServiceReference(BundleContext.class.getName());
assertEquals(reference, reference2);
- ServiceReference[] inUse = bundle.getServicesInUse();
+ ServiceReference[] inUse = bundle1.getServicesInUse();
assertNull(inUse);
bundleContext.getService(reference);
- inUse = bundle.getServicesInUse();
- assertEquals(new ServiceReference[] { reference }, inUse);
+ inUse = bundle1.getServicesInUse();
+ assertArrayEquals(new ServiceReference[] { reference }, inUse);
- Bundle bundle2 = addBundle("/bundles/simple/", "simple-bundle2");
+ VirtualFile assembly2 = assembleBundle("simple2", "/bundles/simple/simple-bundle2");
+ Bundle bundle2 = context.installBundle(assembly2.toURL().toExternalForm());
try
{
bundle2.start();
@@ -284,7 +291,7 @@
assertNotNull(bundleContext2);
bundleContext2.getService(reference);
inUse = bundle2.getServicesInUse();
- assertEquals(new ServiceReference[] { reference }, inUse);
+ assertArrayEquals(new ServiceReference[] { reference }, inUse);
assertNull(factory.ungetBundle);
assertNull(factory.ungetRegistration);
@@ -301,7 +308,7 @@
assertServiceEvent(ServiceEvent.UNREGISTERING, reference);
- inUse = bundle.getServicesInUse();
+ inUse = bundle1.getServicesInUse();
assertNull(inUse);
inUse = bundle2.getServicesInUse();
assertNull(inUse);
@@ -311,7 +318,7 @@
}
finally
{
- uninstall(bundle2);
+ bundle2.uninstall();
}
try
@@ -319,20 +326,22 @@
registration.unregister();
fail("Should not be here!");
}
- catch (Throwable t)
+ catch (IllegalStateException t)
{
- checkThrowable(IllegalStateException.class, t);
+ // expected
}
}
finally
{
- uninstall(bundle);
+ bundle1.uninstall();
}
}
+ @Test
public void testUnregisterAfterStop() throws Exception
{
- Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ VirtualFile assembly = assembleBundle("simple1", "/bundles/simple/simple-bundle1");
+ Bundle bundle = context.installBundle(assembly.toURL().toExternalForm());
try
{
bundle.start();
@@ -349,14 +358,14 @@
registration.unregister();
fail("Should not be here!");
}
- catch (Throwable t)
+ catch (IllegalStateException t)
{
- checkThrowable(IllegalStateException.class, t);
+ // expected
}
}
finally
{
- uninstall(bundle);
+ bundle.uninstall();
}
}
}
Deleted: projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/smoke/OSGiSmokeTestCase.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/smoke/OSGiSmokeTestCase.java 2010-03-10 13:24:47 UTC (rev 102223)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/smoke/OSGiSmokeTestCase.java 2010-03-10 13:28:11 UTC (rev 102224)
@@ -1,193 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2009, Red Hat Middleware LLC, and individual contributors
-* as indicated by the @author tags. See the copyright.txt file 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.smoke;
-
-import java.io.InputStream;
-import java.net.URL;
-import java.util.jar.Attributes;
-import java.util.jar.Manifest;
-
-import junit.framework.Test;
-
-import org.jboss.osgi.framework.metadata.OSGiMetaData;
-import org.jboss.osgi.framework.metadata.internal.AbstractOSGiMetaData;
-import org.jboss.test.osgi.FrameworkTest;
-import org.jboss.test.osgi.smoke.support.a.A;
-import org.jboss.test.osgi.smoke.support.a.b.B;
-import org.jboss.test.osgi.smoke.support.c.C;
-import org.osgi.framework.Bundle;
-
-/**
- * OSGiSmokeTestCase.
- *
- * @author <a href="adrian(a)jboss.com">Adrian Brock</a>
- * @version $Revision: 1.1 $
- */
-public class OSGiSmokeTestCase extends FrameworkTest
-{
- public static Test suite()
- {
- return suite(OSGiSmokeTestCase.class);
- }
-
- public OSGiSmokeTestCase(String name)
- {
- super(name);
- }
-
- public void testNoManifest() throws Exception
- {
- System.out.println("FIXME [JBOSGI-203] Define non OSGi bundle handling by the Framework");
- // testBundle("smoke-no-manifest", Bundle.ACTIVE);
- }
-
- public void testNonOSGiManifest() throws Exception
- {
- System.out.println("FIXME [JBOSGI-203] Define non OSGi bundle handling by the Framework");
- // testBundle("smoke-non-osgi-manifest", Bundle.ACTIVE);
- }
-
- public void testOSGiManifest() throws Exception
- {
- testBundle("smoke-osgi-manifest", Bundle.INSTALLED);
- }
-
- public void testAssembled() throws Exception
- {
- Bundle bundle = installBundle(assembleBundle("smoke-assembled", "/bundles/smoke/smoke-assembled", A.class));
- try
- {
- testBundle(bundle, "smoke-assembled", Bundle.INSTALLED);
- bundle.start();
- assertLoadClass(bundle, A.class);
- assertLoadClassFail(bundle, B.class);
- assertLoadClassFail(bundle, C.class);
- }
- finally
- {
- bundle.uninstall();
- }
- }
-
- public void testDeployedNoManifest() throws Exception
- {
- System.out.println("FIXME [JBOSGI-203] Define non OSGi bundle handling by the Framework");
- // testDeployedBundle("smoke-no-manifest", Bundle.ACTIVE);
- }
-
- public void testDeployedNonOSGiManifest() throws Exception
- {
- System.out.println("FIXME [JBOSGI-203] Define non OSGi bundle handling by the Framework");
- // testDeployedBundle("smoke-non-osgi-manifest", Bundle.ACTIVE);
- }
-
- public void testDeployedOSGiManifest() throws Exception
- {
- testDeployedBundle("smoke-osgi-manifest", Bundle.INSTALLED);
- }
-
- public void testAssembledDeployment() throws Exception
- {
- Manifest manifest = new Manifest();
- Attributes attributes = manifest.getMainAttributes();
- attributes.putValue("Bundle-SymbolicName", "org.jboss.test.osgi.smoke.deployment");
- OSGiMetaData metaData = new AbstractOSGiMetaData(manifest);
- Bundle bundle = deployBundle("smoke-deployment", metaData, A.class);
- try
- {
- assertEquals(Bundle.INSTALLED, bundle.getState());
- bundle.start();
- assertLoadClass(bundle, A.class);
- assertLoadClassFail(bundle, B.class);
- assertLoadClassFail(bundle, C.class);
- }
- finally
- {
- bundle.uninstall();
- }
- }
-
- public void testAssembledNonOSGiDeployment() throws Exception
- {
- System.out.println("FIXME [JBOSGI-203] Define non OSGi bundle handling by the Framework");
- /*
- Bundle bundle = deployBundle("smoke-non-osgi-deployment", A.class);
- try
- {
- assertEquals(Bundle.ACTIVE, bundle.getState());
- assertLoadClass(bundle, A.class);
- assertLoadClassFail(bundle, B.class);
- assertLoadClassFail(bundle, C.class);
- }
- finally
- {
- bundle.uninstall();
- }
- */
- }
-
- protected void testBundle(String name, int expectedState) throws Exception
- {
- Bundle bundle = addBundle("/bundles/smoke/", name);
- try
- {
- testBundle(bundle, name, expectedState);
- }
- finally
- {
- bundle.uninstall();
- }
- }
-
- protected void testDeployedBundle(String name, int expectedState) throws Exception
- {
- Bundle bundle = deployBundle("/bundles/smoke/", name);
- try
- {
- testBundle(bundle, name, expectedState);
- }
- finally
- {
- bundle.uninstall();
- }
- }
-
- protected void testBundle(Bundle bundle, String name, int expectedState) throws Exception
- {
- assertEquals(expectedState, bundle.getState());
- checkId(bundle, name);
- bundle.start();
- bundle.stop();
- }
-
- protected void checkId(Bundle bundle, String name) throws Exception
- {
- URL url = bundle.getEntry("id");
- if (url == null)
- fail("id entry not found for " + bundle);
- InputStream is = url.openStream();
- byte[] bytes = new byte[100];
- is.read(bytes);
- String value = new String(bytes);
- assertTrue("Expected=" + name + " was " + value, value.startsWith(name));
- }
-}
Deleted: projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/smoke/support/a/A.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/smoke/support/a/A.java 2010-03-10 13:24:47 UTC (rev 102223)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/java/org/jboss/test/osgi/smoke/support/a/A.java 2010-03-10 13:28:11 UTC (rev 102224)
@@ -1,32 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2009, Red Hat Middleware LLC, and individual contributors
-* as indicated by the @author tags. See the copyright.txt file 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.smoke.support.a;
-
-/**
- * A.
- *
- * @author <a href="adrian(a)jboss.com">Adrian Brock</a>
- * @version $Revision: 1.1 $
- */
-public class A
-{
-}
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-10 13:24:47 UTC (rev 102223)
+++ projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi142/OSGi142TestCase.java 2010-03-10 13:28:11 UTC (rev 102224)
@@ -64,26 +64,26 @@
Bundle bundleX = sysContext.installBundle(getTestArchiveURL("jbosgi142-bundleX.jar").toExternalForm());
bundleX.start();
- assertBundleLoadClass(bundleX, BeanX.class.getName(), true);
+ assertLoadClass(bundleX, BeanX.class.getName());
Bundle bundleA = sysContext.installBundle(getTestArchiveURL("jbosgi142-bundleA.jar").toExternalForm());
bundleA.start();
- assertBundleLoadClass(bundleA, BeanA.class.getName(), true);
+ assertLoadClass(bundleA, BeanA.class.getName());
Bundle bundleB = sysContext.installBundle(getTestArchiveURL("jbosgi142-bundleB.jar").toExternalForm());
bundleB.start();
- assertBundleLoadClass(bundleB, BeanB.class.getName(), true);
+ assertLoadClass(bundleB, BeanB.class.getName());
- assertBundleLoadClass(bundleA, BeanX.class.getName(), true);
- assertBundleLoadClass(bundleB, BeanX.class.getName(), true);
+ assertLoadClass(bundleA, BeanX.class.getName());
+ assertLoadClass(bundleB, BeanX.class.getName());
- assertBundleLoadClass(bundleX, BeanA.class.getName(), false);
- assertBundleLoadClass(bundleX, BeanB.class.getName(), false);
+ assertLoadClassFail(bundleX, BeanA.class.getName());
+ assertLoadClassFail(bundleX, BeanB.class.getName());
- assertBundleLoadClass(bundleA, BeanB.class.getName(), false);
- assertBundleLoadClass(bundleB, BeanA.class.getName(), false);
+ assertLoadClassFail(bundleA, BeanB.class.getName());
+ assertLoadClassFail(bundleB, BeanA.class.getName());
}
finally
{
14 years, 3 months
JBoss-OSGI SVN: r102223 - projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing.
by jboss-osgi-commits@lists.jboss.org
Author: thomas.diesler(a)jboss.com
Date: 2010-03-10 08:24:47 -0500 (Wed, 10 Mar 2010)
New Revision: 102223
Modified:
projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/OSGiTest.java
projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/OSGiTestHelper.java
Log:
Add more osgi test helper methods
Modified: projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/OSGiTest.java
===================================================================
--- projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/OSGiTest.java 2010-03-10 13:00:44 UTC (rev 102222)
+++ projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/OSGiTest.java 2010-03-10 13:24:47 UTC (rev 102223)
@@ -223,10 +223,18 @@
}
/**
- * Delegates to {@link OSGiTestHelper#assertBundleLoadClass(Bundle, String, boolean)}
+ * Delegates to {@link OSGiTestHelper#assertLoadClass(Bundle, String)}
*/
- public void assertBundleLoadClass(Bundle bundle, String className, boolean success)
+ public Class<?> assertLoadClass(Bundle bundle, String className)
{
- getTestHelper().assertBundleLoadClass(bundle, className, success);
+ return getTestHelper().assertLoadClass(bundle, className);
}
+
+ /**
+ * Delegates to {@link OSGiTestHelper#assertLoadClassFail(Bundle, String)}
+ */
+ public void assertLoadClassFail(Bundle bundle, String className)
+ {
+ getTestHelper().assertLoadClassFail(bundle, className);
+ }
}
Modified: projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/OSGiTestHelper.java
===================================================================
--- projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/OSGiTestHelper.java 2010-03-10 13:00:44 UTC (rev 102222)
+++ projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/OSGiTestHelper.java 2010-03-10 13:24:47 UTC (rev 102223)
@@ -187,7 +187,7 @@
{
String port = System.getProperty("jndi.server.port", "1099");
Integer jndiPort = new Integer(port);
-
+
Hashtable env = new Hashtable();
env.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
env.put("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");
@@ -212,7 +212,7 @@
String framework = System.getProperty("framework");
if (framework == null || framework.length() == 0 || framework.equals("${framework}"))
framework = "jbossmc";
-
+
return framework;
}
@@ -231,7 +231,7 @@
URL url = getClass().getResource(res);
if (url == null)
throw new IllegalArgumentException("Cannot load resource: " + res);
-
+
final VirtualFile file = AbstractVFS.getRoot(url);
if (file.isDirectory())
{
@@ -245,25 +245,25 @@
}
if (packages != null)
{
- for(Class<?> clazz : packages)
+ for (Class<?> clazz : packages)
{
URL url = clazz.getResource("/");
VirtualFile base = AbstractVFS.getRoot(url);
-
+
String path = clazz.getName().replace('.', '/');
path = path.substring(0, path.lastIndexOf("/"));
-
+
VirtualFile classes = base.getChild(path);
addResources(archive, base, classes);
}
}
-
+
// Convert archive to file URL
ZipExporter exporter = archive.as(ZipExporter.class);
File target = File.createTempFile("archive_", ".jar");
exporter.exportZip(target, true);
target.deleteOnExit();
-
+
return AbstractVFS.getRoot(target.toURI().toURL());
}
@@ -274,10 +274,10 @@
{
if (child.isDirectory())
continue;
-
+
String path = child.getPathName();
path = path.substring(basepath.length());
-
+
addResource(archive, path, child);
}
}
@@ -307,28 +307,32 @@
String wasstr = ConstantsHelper.bundleState(wasState);
assertEquals("Bundle " + expstr, expstr, wasstr);
}
-
- public void assertBundleLoadClass(Bundle bundle, String className, boolean success)
+
+ public Class<?> assertLoadClass(Bundle bundle, String className)
{
- String message = bundle.getSymbolicName() + " loads " + className;
-
- Class<?> clazz;
try
{
- clazz = bundle.loadClass(className);
- if (success)
- {
- assertEquals(message, className, clazz.getName());
- }
- else
- {
- fail("ClassNotFoundException expected for: " + message + "\nLoaded from " + clazz.getClassLoader());
- }
+ return bundle.loadClass(className);
}
catch (ClassNotFoundException ex)
{
- if (success)
- fail("Unexpected ClassNotFoundException for: " + message);
+ String message = bundle.getSymbolicName() + " loads " + className;
+ fail("Unexpected ClassNotFoundException for: " + message);
+ return null;
}
}
+
+ public void assertLoadClassFail(Bundle bundle, String className)
+ {
+ try
+ {
+ Class<?> clazz = bundle.loadClass(className);
+ String message = bundle.getSymbolicName() + " loads " + className;
+ fail("ClassNotFoundException expected for: " + message + "\nLoaded from " + clazz.getClassLoader());
+ }
+ catch (ClassNotFoundException ex)
+ {
+ // expected
+ }
+ }
}
14 years, 3 months
JBoss-OSGI SVN: r102218 - in projects/jboss-osgi/projects/runtime/framework/trunk: bundle/src/test/java/org/jboss/test/osgi and 4 other directories.
by jboss-osgi-commits@lists.jboss.org
Author: thomas.diesler(a)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(a)gmail.com">John Bailey</a>
* @version $Revision: 87848 $
*/
+@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(a)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(a)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(a)jboss.com">Adrian Brock</a>
+ * @author Thomas.Diesler(a)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(a)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(a)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(a)jboss.com">Adrian Brock</a>
+ * @author thomas.Diesler(a)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(a)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)
{
14 years, 3 months
JBoss-OSGI SVN: r102217 - in projects/jboss-osgi/projects/testing/trunk: src/main/java/org/jboss/osgi/testing and 1 other directory.
by jboss-osgi-commits@lists.jboss.org
Author: thomas.diesler(a)jboss.com
Date: 2010-03-10 05:27:55 -0500 (Wed, 10 Mar 2010)
New Revision: 102217
Modified:
projects/jboss-osgi/projects/testing/trunk/pom.xml
projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/OSGiTest.java
Log:
Compile dependency on shrinkwrap. Better javadoc
Modified: projects/jboss-osgi/projects/testing/trunk/pom.xml
===================================================================
--- projects/jboss-osgi/projects/testing/trunk/pom.xml 2010-03-10 07:14:35 UTC (rev 102216)
+++ projects/jboss-osgi/projects/testing/trunk/pom.xml 2010-03-10 10:27:55 UTC (rev 102217)
@@ -82,11 +82,6 @@
</dependency>
<dependency>
<groupId>org.jboss.shrinkwrap</groupId>
- <artifactId>shrinkwrap-api</artifactId>
- <version>${version.jboss.shrinkwrap}</version>
- </dependency>
- <dependency>
- <groupId>org.jboss.shrinkwrap</groupId>
<artifactId>shrinkwrap-impl-base</artifactId>
<version>${version.jboss.shrinkwrap}</version>
</dependency>
Modified: projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/OSGiTest.java
===================================================================
--- projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/OSGiTest.java 2010-03-10 07:14:35 UTC (rev 102216)
+++ projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/OSGiTest.java 2010-03-10 10:27:55 UTC (rev 102217)
@@ -36,8 +36,7 @@
/**
* An abstract OSGi Test.
*
- * {@link OSGiTest} is a convenience wrapper for the functionality provided
- * by {@link OSGiTestHelper}.
+ * A convenience wrapper for the functionality provided by {@link OSGiTestHelper}.
*
* @author Thomas.Diesler(a)jboss.org
* @since 25-Sep-2008
@@ -199,21 +198,33 @@
return getTestHelper().getFrameworkName();
}
+ /**
+ * Delegates to {@link OSGiTestHelper#assembleBundle(String, String, Class...)}
+ */
public VirtualFile assembleBundle(String name, String resource, Class<?>... packages) throws Exception
{
return getTestHelper().assembleBundle(name, resource, packages);
}
+ /**
+ * Delegates to {@link OSGiTestHelper#assembleBundle(String, String[], Class...)}
+ */
public VirtualFile assembleBundle(String name, String[] resources, Class<?>... packages) throws Exception
{
return getTestHelper().assembleBundle(name, resources, packages);
}
+ /**
+ * Delegates to {@link OSGiTestHelper#assertBundleState(int, int)}
+ */
public void assertBundleState(int expState, int wasState)
{
getTestHelper().assertBundleState(expState, wasState);
}
+ /**
+ * Delegates to {@link OSGiTestHelper#assertBundleLoadClass(Bundle, String, boolean)}
+ */
public void assertBundleLoadClass(Bundle bundle, String className, boolean success)
{
getTestHelper().assertBundleLoadClass(bundle, className, success);
14 years, 3 months
JBoss-OSGI SVN: r102216 - projects/jboss-osgi/projects/runtime/framework/trunk/core/src/main/java/org/jboss/osgi/framework/bundle.
by jboss-osgi-commits@lists.jboss.org
Author: thomas.diesler(a)jboss.com
Date: 2010-03-10 02:14:35 -0500 (Wed, 10 Mar 2010)
New Revision: 102216
Modified:
projects/jboss-osgi/projects/runtime/framework/trunk/core/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java
Log:
Use getRoot() instead of getChild()
Modified: projects/jboss-osgi/projects/runtime/framework/trunk/core/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/core/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java 2010-03-10 06:37:55 UTC (rev 102215)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/core/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java 2010-03-10 07:14:35 UTC (rev 102216)
@@ -450,7 +450,7 @@
VirtualFile root;
try
{
- root = AbstractVFS.getChild(locationURL);
+ root = AbstractVFS.getRoot(locationURL);
}
catch (IOException e)
{
@@ -682,7 +682,7 @@
try
{
URL storageLocation = getBundleStorageLocation(in);
- VirtualFile root = AbstractVFS.getChild(storageLocation);
+ VirtualFile root = AbstractVFS.getRoot(storageLocation);
BundleInfo info = BundleInfo.createBundleInfo(root, location);
Deployment dep = DeploymentFactory.createDeployment(info);
14 years, 3 months
JBoss-OSGI SVN: r102173 - in projects/jboss-osgi/projects: testing/trunk and 5 other directories.
by jboss-osgi-commits@lists.jboss.org
Author: thomas.diesler(a)jboss.com
Date: 2010-03-09 16:16:59 -0500 (Tue, 09 Mar 2010)
New Revision: 102173
Modified:
projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/util/BundleInfo.java
projects/jboss-osgi/projects/testing/trunk/pom.xml
projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/OSGiTestHelper.java
projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/internal/EmbeddedRuntime.java
projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/internal/OSGiRuntimeImpl.java
projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/internal/RemoteRuntime.java
projects/jboss-osgi/projects/testing/trunk/src/test/java/org/jboss/test/osgi/testing/SimpleTestCase.java
projects/jboss-osgi/projects/vfs/trunk/vfs21/src/main/java/org/jboss/osgi/vfs21/VFSAdaptor21.java
projects/jboss-osgi/projects/vfs/trunk/vfs30/src/main/java/org/jboss/osgi/vfs30/VFSAdaptor30.java
projects/jboss-osgi/projects/vfs/trunk/vfs30/src/main/java/org/jboss/osgi/vfs30/VirtualFileAdaptor30.java
Log:
Use getRoot() instead of getChild()
Modified: projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/util/BundleInfo.java
===================================================================
--- projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/util/BundleInfo.java 2010-03-09 21:14:14 UTC (rev 102172)
+++ projects/jboss-osgi/projects/spi/trunk/src/main/java/org/jboss/osgi/spi/util/BundleInfo.java 2010-03-09 21:16:59 UTC (rev 102173)
@@ -263,7 +263,7 @@
{
try
{
- return AbstractVFS.getChild(url);
+ return AbstractVFS.getRoot(url);
}
catch (IOException e)
{
Modified: projects/jboss-osgi/projects/testing/trunk/pom.xml
===================================================================
--- projects/jboss-osgi/projects/testing/trunk/pom.xml 2010-03-09 21:14:14 UTC (rev 102172)
+++ projects/jboss-osgi/projects/testing/trunk/pom.xml 2010-03-09 21:16:59 UTC (rev 102173)
@@ -86,6 +86,11 @@
<version>${version.jboss.shrinkwrap}</version>
</dependency>
<dependency>
+ <groupId>org.jboss.shrinkwrap</groupId>
+ <artifactId>shrinkwrap-impl-base</artifactId>
+ <version>${version.jboss.shrinkwrap}</version>
+ </dependency>
+ <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
@@ -153,12 +158,6 @@
<version>${version.jboss.osgi.vfs}</version>
<scope>test</scope>
</dependency>
- <dependency>
- <groupId>org.jboss.shrinkwrap</groupId>
- <artifactId>shrinkwrap-impl-base</artifactId>
- <version>${version.jboss.shrinkwrap}</version>
- <scope>test</scope>
- </dependency>
</dependencies>
<build>
Modified: projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/OSGiTestHelper.java
===================================================================
--- projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/OSGiTestHelper.java 2010-03-09 21:14:14 UTC (rev 102172)
+++ projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/OSGiTestHelper.java 2010-03-09 21:16:59 UTC (rev 102173)
@@ -232,7 +232,7 @@
if (url == null)
throw new IllegalArgumentException("Cannot load resource: " + res);
- final VirtualFile file = AbstractVFS.getChild(url);
+ final VirtualFile file = AbstractVFS.getRoot(url);
if (file.isDirectory())
{
addResources(archive, file, file);
@@ -248,7 +248,7 @@
for(Class<?> clazz : packages)
{
URL url = clazz.getResource("/");
- VirtualFile base = AbstractVFS.getChild(url);
+ VirtualFile base = AbstractVFS.getRoot(url);
String path = clazz.getName().replace('.', '/');
path = path.substring(0, path.lastIndexOf("/"));
@@ -264,7 +264,7 @@
exporter.exportZip(target, true);
target.deleteOnExit();
- return AbstractVFS.getChild(target.toURI().toURL());
+ return AbstractVFS.getRoot(target.toURI().toURL());
}
private void addResources(JavaArchive archive, VirtualFile basedir, VirtualFile resdir) throws IOException
Modified: projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/internal/EmbeddedRuntime.java
===================================================================
--- projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/internal/EmbeddedRuntime.java 2010-03-09 21:14:14 UTC (rev 102172)
+++ projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/internal/EmbeddedRuntime.java 2010-03-09 21:16:59 UTC (rev 102173)
@@ -68,7 +68,7 @@
OSGiBundle installBundle(BundleInfo info) throws BundleException
{
BundleContext context = getSystemContext();
- String location = fixVirtualFileURL(info.getRootURL()).toExternalForm();
+ String location = toFileURL(info.getRootURL()).toExternalForm();
Bundle auxBundle = context.installBundle(location);
OSGiBundle bundle = new EmbeddedBundle(this, auxBundle);
return registerBundle(bundle.getLocation(), bundle);
Modified: projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/internal/OSGiRuntimeImpl.java
===================================================================
--- projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/internal/OSGiRuntimeImpl.java 2010-03-09 21:14:14 UTC (rev 102172)
+++ projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/internal/OSGiRuntimeImpl.java 2010-03-09 21:16:59 UTC (rev 102173)
@@ -186,27 +186,6 @@
abstract OSGiBundle installBundle(BundleInfo info) throws BundleException;
- // [JBVFS-147] Cannot read from vfs: protocol URL
- URL fixVirtualFileURL(URL url)
- {
- if (url.getProtocol().equals("vfs"))
- {
- File file = new File(url.getPath());
- if (file.exists())
- {
- try
- {
- url = file.toURI().toURL();
- }
- catch (MalformedURLException e)
- {
- // ignore
- }
- }
- }
- return url;
- }
-
public void shutdown()
{
log.debug("Start Shutdown");
@@ -421,6 +400,27 @@
}
}
+ // [JBVFS-147] Cannot read from vfs: protocol URL
+ URL toFileURL(URL url)
+ {
+ if (url.getProtocol().equals("vfs"))
+ {
+ File file = new File(url.getPath());
+ if (file.exists())
+ {
+ try
+ {
+ url = file.toURI().toURL();
+ }
+ catch (MalformedURLException e)
+ {
+ // ignore
+ }
+ }
+ }
+ return url;
+ }
+
VirtualFile toVirtualFile(Archive<?> archive) throws IOException, MalformedURLException
{
ZipExporter exporter = archive.as(ZipExporter.class);
@@ -428,7 +428,7 @@
exporter.exportZip(target, true);
target.deleteOnExit();
- return AbstractVFS.getChild(target.toURI().toURL());
+ return AbstractVFS.getRoot(target.toURI().toURL());
}
private void failsafeUninstall(OSGiBundle bundle)
Modified: projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/internal/RemoteRuntime.java
===================================================================
--- projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/internal/RemoteRuntime.java 2010-03-09 21:14:14 UTC (rev 102172)
+++ projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/internal/RemoteRuntime.java 2010-03-09 21:16:59 UTC (rev 102173)
@@ -74,7 +74,7 @@
{
try
{
- String location = fixVirtualFileURL(info.getRootURL()).toExternalForm();
+ String location = toFileURL(info.getRootURL()).toExternalForm();
long bundleId = getFrameworkMBean().installBundle(location);
RemoteBundle bundle = new RemoteBundle(this, bundleId);
return registerBundle(bundle.getLocation(), bundle);
Modified: projects/jboss-osgi/projects/testing/trunk/src/test/java/org/jboss/test/osgi/testing/SimpleTestCase.java
===================================================================
--- projects/jboss-osgi/projects/testing/trunk/src/test/java/org/jboss/test/osgi/testing/SimpleTestCase.java 2010-03-09 21:14:14 UTC (rev 102172)
+++ projects/jboss-osgi/projects/testing/trunk/src/test/java/org/jboss/test/osgi/testing/SimpleTestCase.java 2010-03-09 21:16:59 UTC (rev 102173)
@@ -107,7 +107,7 @@
OSGiRuntime runtime = getDefaultRuntime();
try
{
- VirtualFile archive = AbstractVFS.getChild(getTestArchiveURL("example-simple.jar"));
+ VirtualFile archive = AbstractVFS.getRoot(getTestArchiveURL("example-simple.jar"));
OSGiBundle bundle = runtime.installBundle(archive);
assertBundleState(Bundle.INSTALLED, bundle.getState());
}
Modified: projects/jboss-osgi/projects/vfs/trunk/vfs21/src/main/java/org/jboss/osgi/vfs21/VFSAdaptor21.java
===================================================================
--- projects/jboss-osgi/projects/vfs/trunk/vfs21/src/main/java/org/jboss/osgi/vfs21/VFSAdaptor21.java 2010-03-09 21:14:14 UTC (rev 102172)
+++ projects/jboss-osgi/projects/vfs/trunk/vfs21/src/main/java/org/jboss/osgi/vfs21/VFSAdaptor21.java 2010-03-09 21:16:59 UTC (rev 102173)
@@ -35,7 +35,7 @@
*/
public class VFSAdaptor21 implements VFSAdaptor
{
- public VirtualFile getChild(URL url) throws IOException
+ public VirtualFile getRoot(URL url) throws IOException
{
org.jboss.virtual.VirtualFile root = org.jboss.virtual.VFS.getRoot(url);
return new VirtualFileAdaptor21(root, root);
Modified: projects/jboss-osgi/projects/vfs/trunk/vfs30/src/main/java/org/jboss/osgi/vfs30/VFSAdaptor30.java
===================================================================
--- projects/jboss-osgi/projects/vfs/trunk/vfs30/src/main/java/org/jboss/osgi/vfs30/VFSAdaptor30.java 2010-03-09 21:14:14 UTC (rev 102172)
+++ projects/jboss-osgi/projects/vfs/trunk/vfs30/src/main/java/org/jboss/osgi/vfs30/VFSAdaptor30.java 2010-03-09 21:16:59 UTC (rev 102173)
@@ -37,7 +37,7 @@
*/
public class VFSAdaptor30 implements VFSAdaptor
{
- public VirtualFile getChild(URL url) throws IOException
+ public VirtualFile getRoot(URL url) throws IOException
{
org.jboss.vfs.VirtualFile root;
try
Modified: projects/jboss-osgi/projects/vfs/trunk/vfs30/src/main/java/org/jboss/osgi/vfs30/VirtualFileAdaptor30.java
===================================================================
--- projects/jboss-osgi/projects/vfs/trunk/vfs30/src/main/java/org/jboss/osgi/vfs30/VirtualFileAdaptor30.java 2010-03-09 21:14:14 UTC (rev 102172)
+++ projects/jboss-osgi/projects/vfs/trunk/vfs30/src/main/java/org/jboss/osgi/vfs30/VirtualFileAdaptor30.java 2010-03-09 21:16:59 UTC (rev 102173)
@@ -109,7 +109,7 @@
{
if (path == null)
throw new IllegalArgumentException("Null path");
-
+
if (pattern == null)
pattern = "*";
@@ -119,7 +119,7 @@
org.jboss.vfs.VirtualFile child = delegate.getChild(path);
if (child.exists() == false)
return null;
-
+
return new VFSFindEntriesEnumeration(delegate, child, pattern, recurse);
}
@@ -127,14 +127,14 @@
{
if (path == null)
throw new IllegalArgumentException("Null path");
-
+
if (path.startsWith("/"))
path = path.substring(1);
-
+
org.jboss.vfs.VirtualFile child = delegate.getChild(path);
if (child.exists() == false)
return null;
-
+
return new VFSEntryPathsEnumeration(delegate, child);
}
14 years, 3 months
JBoss-OSGI SVN: r102172 - projects/jboss-osgi/projects/vfs/trunk/api/src/main/java/org/jboss/osgi/vfs.
by jboss-osgi-commits@lists.jboss.org
Author: thomas.diesler(a)jboss.com
Date: 2010-03-09 16:14:14 -0500 (Tue, 09 Mar 2010)
New Revision: 102172
Modified:
projects/jboss-osgi/projects/vfs/trunk/api/src/main/java/org/jboss/osgi/vfs/AbstractVFS.java
projects/jboss-osgi/projects/vfs/trunk/api/src/main/java/org/jboss/osgi/vfs/VFSAdaptor.java
Log:
Use getRoot() instead of getChild()
Modified: projects/jboss-osgi/projects/vfs/trunk/api/src/main/java/org/jboss/osgi/vfs/AbstractVFS.java
===================================================================
--- projects/jboss-osgi/projects/vfs/trunk/api/src/main/java/org/jboss/osgi/vfs/AbstractVFS.java 2010-03-09 21:13:19 UTC (rev 102171)
+++ projects/jboss-osgi/projects/vfs/trunk/api/src/main/java/org/jboss/osgi/vfs/AbstractVFS.java 2010-03-09 21:14:14 UTC (rev 102172)
@@ -36,9 +36,9 @@
{
private static VFSAdaptor adaptor;
- public static VirtualFile getChild(URL url) throws IOException
+ public static VirtualFile getRoot(URL url) throws IOException
{
- return getVFSAdaptor().getChild(url);
+ return getVFSAdaptor().getRoot(url);
}
public static VirtualFile adapt(Object virtualFile)
Modified: projects/jboss-osgi/projects/vfs/trunk/api/src/main/java/org/jboss/osgi/vfs/VFSAdaptor.java
===================================================================
--- projects/jboss-osgi/projects/vfs/trunk/api/src/main/java/org/jboss/osgi/vfs/VFSAdaptor.java 2010-03-09 21:13:19 UTC (rev 102171)
+++ projects/jboss-osgi/projects/vfs/trunk/api/src/main/java/org/jboss/osgi/vfs/VFSAdaptor.java 2010-03-09 21:14:14 UTC (rev 102172)
@@ -36,13 +36,12 @@
{
/**
* Get the root virtual file
- *
* @param rootURL the root url
* @return the virtual file
* @throws IOException if there is a problem accessing the VFS
* @throws IllegalArgumentException if the rootURL
*/
- VirtualFile getChild(URL url) throws IOException;
+ VirtualFile getRoot(URL url) throws IOException;
/**
* Adapt a concrete instance of a jboss-vfs VirtualFile.
14 years, 3 months
JBoss-OSGI SVN: r102132 - in projects/jboss-osgi/projects/testing/trunk: src/main/java/org/jboss/osgi/testing and 4 other directories.
by jboss-osgi-commits@lists.jboss.org
Author: thomas.diesler(a)jboss.com
Date: 2010-03-09 09:59:26 -0500 (Tue, 09 Mar 2010)
New Revision: 102132
Added:
projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/ManifestBuilder.java
projects/jboss-osgi/projects/testing/trunk/src/test/resources/simple/META-INF/
projects/jboss-osgi/projects/testing/trunk/src/test/resources/simple/META-INF/MANIFEST.MF
Modified:
projects/jboss-osgi/projects/testing/trunk/pom.xml
projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/OSGiRuntime.java
projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/OSGiTestHelper.java
projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/internal/EmbeddedRuntime.java
projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/internal/OSGiRuntimeImpl.java
projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/internal/RemoteRuntime.java
projects/jboss-osgi/projects/testing/trunk/src/test/java/org/jboss/test/osgi/testing/SimpleAssemblyTestCase.java
projects/jboss-osgi/projects/testing/trunk/src/test/java/org/jboss/test/osgi/testing/SimpleTestCase.java
Log:
Add support for shrinkwrap
Modified: projects/jboss-osgi/projects/testing/trunk/pom.xml
===================================================================
--- projects/jboss-osgi/projects/testing/trunk/pom.xml 2010-03-09 14:57:53 UTC (rev 102131)
+++ projects/jboss-osgi/projects/testing/trunk/pom.xml 2010-03-09 14:59:26 UTC (rev 102132)
@@ -10,6 +10,14 @@
<!-- ====================================================================== -->
<!-- $Id$ -->
+
+ <!--
+ Set these VM properties in your IDE debugger
+
+ -Djava.protocol.handler.pkgs=org.jboss.net.protocol|org.jboss.virtual.protocol|org.jboss.vfs.protocol
+ -Dlog4j.output.dir=${workspace_loc:jboss-osgi-testing/target}
+ -Dtest.archive.directory=${workspace_loc:jboss-osgi-testing/target}/test-libs
+ -->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
@@ -42,7 +50,7 @@
<properties>
<version.apache.aries.jmx>1.0.0-incubating-SNAPSHOT</version.apache.aries.jmx>
<version.apache.felix.log>1.0.0</version.apache.felix.log>
- <version.jboss.shrinkwrap>1.0.0-alpha-6</version.jboss.shrinkwrap>
+ <version.jboss.shrinkwrap>1.0.0-SNAPSHOT</version.jboss.shrinkwrap>
<version.jboss.osgi.common>1.0.4-SNAPSHOT</version.jboss.osgi.common>
<version.jboss.osgi.felix>2.0.2.SP1-SNAPSHOT</version.jboss.osgi.felix>
<version.jboss.osgi.jmx>1.0.4-SNAPSHOT</version.jboss.osgi.jmx>
@@ -75,7 +83,7 @@
<dependency>
<groupId>org.jboss.shrinkwrap</groupId>
<artifactId>shrinkwrap-api</artifactId>
- <version>${version.jboss.shrinkwrap}</version>
+ <version>${version.jboss.shrinkwrap}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
@@ -141,10 +149,16 @@
</dependency>
<dependency>
<groupId>org.jboss.osgi.vfs</groupId>
- <artifactId>jboss-osgi-vfs21</artifactId>
+ <artifactId>jboss-osgi-vfs30</artifactId>
<version>${version.jboss.osgi.vfs}</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.jboss.shrinkwrap</groupId>
+ <artifactId>shrinkwrap-impl-base</artifactId>
+ <version>${version.jboss.shrinkwrap}</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
@@ -211,7 +225,7 @@
<systemProperties>
<property>
<name>java.protocol.handler.pkgs</name>
- <value>org.jboss.net.protocol|org.jboss.virtual.protocol</value>
+ <value>org.jboss.net.protocol|org.jboss.virtual.protocol|org.jboss.vfs.protocol</value>
</property>
<property>
<name>log4j.output.dir</name>
Copied: projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/ManifestBuilder.java (from rev 102117, projects/jboss-osgi/projects/vfs/trunk/api/src/main/java/org/jboss/osgi/vfs/ManifestBuilder.java)
===================================================================
--- projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/ManifestBuilder.java (rev 0)
+++ projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/ManifestBuilder.java 2010-03-09 14:59:26 UTC (rev 102132)
@@ -0,0 +1,157 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, 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;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.jar.Attributes;
+import java.util.jar.Manifest;
+
+import org.jboss.shrinkwrap.api.Asset;
+import org.osgi.framework.Constants;
+
+/**
+ * A simple OSGi manifest builder.
+ *
+ * @author thomas.diesler(a)jboss.com
+ * @since 08-Mar-2010
+ */
+public final class ManifestBuilder implements Asset
+{
+ private StringWriter sw;
+ private PrintWriter pw;
+ private List<String> importPackages = new ArrayList<String>();
+ private List<String> exportPackages = new ArrayList<String>();
+
+ public static ManifestBuilder newInstance()
+ {
+ return new ManifestBuilder();
+ }
+
+ private ManifestBuilder()
+ {
+ sw = new StringWriter();
+ pw = new PrintWriter(sw);
+ pw.println(Attributes.Name.MANIFEST_VERSION + ": 1.0");
+ }
+
+ public ManifestBuilder addBundleManifestVersion(int version)
+ {
+ pw.println(Constants.BUNDLE_MANIFESTVERSION + ": " + version);
+ return this;
+ }
+
+ public ManifestBuilder addBundleSymbolicName(String symbolicName)
+ {
+ pw.println(Constants.BUNDLE_SYMBOLICNAME + ": " + symbolicName);
+ return this;
+ }
+
+ public ManifestBuilder addBundleActivator(String bundleActivator)
+ {
+ pw.println(Constants.BUNDLE_ACTIVATOR + ": " + bundleActivator);
+ return this;
+ }
+
+ public ManifestBuilder addImportPackages(String... packages)
+ {
+ for (String aux : packages)
+ importPackages.add(aux);
+
+ return this;
+ }
+
+ public ManifestBuilder addExportPackages(String... packages)
+ {
+ for (String aux : packages)
+ exportPackages.add(aux);
+
+ return this;
+ }
+
+ public ManifestBuilder addManifestHeader(String key, String value)
+ {
+ pw.println(key + ": " + value);
+ return this;
+ }
+
+ public Manifest getManifest()
+ {
+ if (exportPackages.size() > 0)
+ {
+ pw.print(Constants.EXPORT_PACKAGE + ": ");
+ for (int i = 0; i < exportPackages.size(); i++)
+ {
+ if (i > 0)
+ pw.print(",");
+
+ pw.print(exportPackages.get(i));
+ }
+ pw.println();
+ }
+
+ if (importPackages.size() > 0)
+ {
+ pw.print(Constants.IMPORT_PACKAGE + ": ");
+ for (int i = 0; i < importPackages.size(); i++)
+ {
+ if (i > 0)
+ pw.print(",");
+
+ pw.print(importPackages.get(i));
+ }
+ pw.println();
+ }
+
+ try
+ {
+ Manifest manifest = new Manifest(new ByteArrayInputStream(sw.toString().getBytes()));
+ return manifest;
+ }
+ catch (IOException ex)
+ {
+ throw new IllegalStateException("Cannot create manifest", ex);
+ }
+ }
+
+ @Override
+ public InputStream openStream()
+ {
+ Manifest manifest = getManifest();
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ try
+ {
+ manifest.write(baos);
+ return new ByteArrayInputStream(baos.toByteArray());
+ }
+ catch (IOException ex)
+ {
+ throw new IllegalStateException("Cannot provide manifest InputStream", ex);
+ }
+ }
+}
Modified: projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/OSGiRuntime.java
===================================================================
--- projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/OSGiRuntime.java 2010-03-09 14:57:53 UTC (rev 102131)
+++ projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/OSGiRuntime.java 2010-03-09 14:59:26 UTC (rev 102132)
@@ -29,6 +29,7 @@
import org.jboss.osgi.spi.capability.Capability;
import org.jboss.osgi.vfs.VirtualFile;
+import org.jboss.shrinkwrap.api.Archive;
import org.osgi.framework.BundleException;
import org.osgi.framework.Version;
import org.osgi.jmx.framework.BundleStateMBean;
@@ -60,6 +61,11 @@
void removeCapability(Capability capability);
/**
+ * Install an {@link OSGiBundle} from the given archive.
+ */
+ OSGiBundle installBundle(Archive<?> archive) throws BundleException, IOException;
+
+ /**
* Install an {@link OSGiBundle} from the given virtual file.
*/
OSGiBundle installBundle(VirtualFile vfsfile) throws BundleException, IOException;
Modified: projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/OSGiTestHelper.java
===================================================================
--- projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/OSGiTestHelper.java 2010-03-09 14:57:53 UTC (rev 102131)
+++ projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/OSGiTestHelper.java 2010-03-09 14:59:26 UTC (rev 102132)
@@ -25,6 +25,8 @@
import static org.junit.Assert.fail;
import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Hashtable;
@@ -32,8 +34,6 @@
import javax.naming.InitialContext;
import javax.naming.NamingException;
-import junit.framework.AssertionFailedError;
-
import org.jboss.osgi.spi.framework.OSGiBootstrap;
import org.jboss.osgi.spi.framework.OSGiBootstrapProvider;
import org.jboss.osgi.spi.util.ConstantsHelper;
@@ -41,7 +41,10 @@
import org.jboss.osgi.testing.internal.RemoteRuntime;
import org.jboss.osgi.vfs.AbstractVFS;
import org.jboss.osgi.vfs.VirtualFile;
-import org.jboss.osgi.vfs.VirtualFileAssembly;
+import org.jboss.shrinkwrap.api.Archives;
+import org.jboss.shrinkwrap.api.Asset;
+import org.jboss.shrinkwrap.api.exporter.ZipExporter;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.osgi.framework.Bundle;
/**
@@ -218,16 +221,86 @@
return assembleBundle(name, new String[] { resource }, packages);
}
- public VirtualFile assembleBundle(String name, String[] resources, Class<?>... packages) throws Exception
+ public VirtualFile assembleBundle(String name, String[] resources, Class<?>... packages) throws IOException
{
- VirtualFileAssembly assembly = AbstractVFS.createVirtualFileAssembly(name);
- for (String path : resources)
- addPath(assembly, path, "");
- for (Class<?> reference : packages)
- addPackage(assembly, reference);
- return assembly;
+ JavaArchive archive = Archives.create(name + ".jar", JavaArchive.class);
+ if (resources != null)
+ {
+ for (String res : resources)
+ {
+ URL url = getClass().getResource(res);
+ if (url == null)
+ throw new IllegalArgumentException("Cannot load resource: " + res);
+
+ final VirtualFile file = AbstractVFS.getChild(url);
+ if (file.isDirectory())
+ {
+ addResources(archive, file, file);
+ }
+ else
+ {
+ addResource(archive, res, file);
+ }
+ }
+ }
+ if (packages != null)
+ {
+ for(Class<?> clazz : packages)
+ {
+ URL url = clazz.getResource("/");
+ VirtualFile base = AbstractVFS.getChild(url);
+
+ String path = clazz.getName().replace('.', '/');
+ path = path.substring(0, path.lastIndexOf("/"));
+
+ VirtualFile classes = base.getChild(path);
+ addResources(archive, base, classes);
+ }
+ }
+
+ // Convert archive to file URL
+ ZipExporter exporter = archive.as(ZipExporter.class);
+ File target = File.createTempFile("archive_", ".jar");
+ exporter.exportZip(target, true);
+ target.deleteOnExit();
+
+ return AbstractVFS.getChild(target.toURI().toURL());
}
+ private void addResources(JavaArchive archive, VirtualFile basedir, VirtualFile resdir) throws IOException
+ {
+ String basepath = basedir.getPathName();
+ for (final VirtualFile child : resdir.getChildrenRecursively())
+ {
+ if (child.isDirectory())
+ continue;
+
+ String path = child.getPathName();
+ path = path.substring(basepath.length());
+
+ addResource(archive, path, child);
+ }
+ }
+
+ private void addResource(JavaArchive archive, String path, final VirtualFile file)
+ {
+ Asset asset = new Asset()
+ {
+ public InputStream openStream()
+ {
+ try
+ {
+ return file.openStream();
+ }
+ catch (IOException ex)
+ {
+ throw new IllegalStateException("Cannot open stream for: " + file, ex);
+ }
+ }
+ };
+ archive.add(asset, path);
+ }
+
public void assertBundleState(int expState, int wasState)
{
String expstr = ConstantsHelper.bundleState(expState);
@@ -258,32 +331,4 @@
fail("Unexpected ClassNotFoundException for: " + message);
}
}
-
- private void addPath(VirtualFileAssembly dir, String path, String name) throws Exception
- {
- URL url = getClass().getResource(path);
- if (url == null)
- throw new AssertionFailedError(path + " not found");
-
- VirtualFile root = AbstractVFS.getChild(url);
- VirtualFile file = root.getChild(name);
- dir.addPath(file);
- }
-
- private void addPackage(VirtualFileAssembly dir, Class<?> reference) throws Exception
- {
- String packagePath = packageNameToPath(reference.getName());
- dir.addResources(reference, new String[] { packagePath + "/*.class" }, new String[0]);
- }
-
- // Convert a class's package name into a path
- private String packageNameToPath(final String className)
- {
- int end = className.lastIndexOf('.');
- if (end == -1)
- return "";
-
- String packageName = className.substring(0, end);
- return packageName.replace('.', '/');
- }
}
Modified: projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/internal/EmbeddedRuntime.java
===================================================================
--- projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/internal/EmbeddedRuntime.java 2010-03-09 14:57:53 UTC (rev 102131)
+++ projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/internal/EmbeddedRuntime.java 2010-03-09 14:59:26 UTC (rev 102132)
@@ -23,7 +23,6 @@
// $Id$
-import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -41,7 +40,6 @@
import org.jboss.osgi.testing.OSGiRuntime;
import org.jboss.osgi.testing.OSGiServiceReference;
import org.jboss.osgi.testing.OSGiTestHelper;
-import org.jboss.osgi.vfs.VirtualFile;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
@@ -67,28 +65,15 @@
super(helper);
}
- public OSGiBundle installBundle(VirtualFile file) throws BundleException, IOException
+ OSGiBundle installBundle(BundleInfo info) throws BundleException
{
- BundleInfo info = BundleInfo.createBundleInfo(file);
-
BundleContext context = getSystemContext();
- Bundle auxBundle = context.installBundle(info.getLocation(), file.openStream());
+ String location = fixVirtualFileURL(info.getRootURL()).toExternalForm();
+ Bundle auxBundle = context.installBundle(location);
OSGiBundle bundle = new EmbeddedBundle(this, auxBundle);
-
return registerBundle(bundle.getLocation(), bundle);
}
- public OSGiBundle installBundle(String location) throws BundleException
- {
- BundleInfo info = BundleInfo.createBundleInfo(location);
-
- BundleContext context = getSystemContext();
- Bundle auxBundle = context.installBundle(info.getLocation());
- OSGiBundle bundle = new EmbeddedBundle(this, auxBundle);
-
- return registerBundle(bundle.getLocation(), bundle);
- }
-
public OSGiBundle[] getBundles()
{
List<OSGiBundle> absBundles = new ArrayList<OSGiBundle>();
Modified: projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/internal/OSGiRuntimeImpl.java
===================================================================
--- projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/internal/OSGiRuntimeImpl.java 2010-03-09 14:57:53 UTC (rev 102131)
+++ projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/internal/OSGiRuntimeImpl.java 2010-03-09 14:59:26 UTC (rev 102132)
@@ -23,6 +23,8 @@
import java.io.File;
import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@@ -53,6 +55,10 @@
import org.jboss.osgi.testing.OSGiRuntime;
import org.jboss.osgi.testing.OSGiServiceReference;
import org.jboss.osgi.testing.OSGiTestHelper;
+import org.jboss.osgi.vfs.AbstractVFS;
+import org.jboss.osgi.vfs.VirtualFile;
+import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.shrinkwrap.api.exporter.ZipExporter;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleException;
import org.osgi.framework.Version;
@@ -160,6 +166,47 @@
removeCapability(dependency);
}
+ public OSGiBundle installBundle(String location) throws BundleException
+ {
+ BundleInfo info = BundleInfo.createBundleInfo(location);
+ return installBundle(info);
+ }
+
+ public OSGiBundle installBundle(Archive<?> archive) throws BundleException, IOException
+ {
+ VirtualFile file = toVirtualFile(archive);
+ return installBundle(file);
+ }
+
+ public OSGiBundle installBundle(VirtualFile virtualFile) throws BundleException
+ {
+ BundleInfo info = BundleInfo.createBundleInfo(virtualFile);
+ return installBundle(info);
+ }
+
+ abstract OSGiBundle installBundle(BundleInfo info) throws BundleException;
+
+ // [JBVFS-147] Cannot read from vfs: protocol URL
+ URL fixVirtualFileURL(URL url)
+ {
+ if (url.getProtocol().equals("vfs"))
+ {
+ File file = new File(url.getPath());
+ if (file.exists())
+ {
+ try
+ {
+ url = file.toURI().toURL();
+ }
+ catch (MalformedURLException e)
+ {
+ // ignore
+ }
+ }
+ }
+ return url;
+ }
+
public void shutdown()
{
log.debug("Start Shutdown");
@@ -327,7 +374,7 @@
return value;
}
- private Manifest getManifest(String location)
+ Manifest getManifest(String location)
{
Manifest manifest;
try
@@ -374,6 +421,16 @@
}
}
+ VirtualFile toVirtualFile(Archive<?> archive) throws IOException, MalformedURLException
+ {
+ ZipExporter exporter = archive.as(ZipExporter.class);
+ File target = File.createTempFile("archive_", ".jar");
+ exporter.exportZip(target, true);
+ target.deleteOnExit();
+
+ return AbstractVFS.getChild(target.toURI().toURL());
+ }
+
private void failsafeUninstall(OSGiBundle bundle)
{
if (bundle != null)
Modified: projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/internal/RemoteRuntime.java
===================================================================
--- projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/internal/RemoteRuntime.java 2010-03-09 14:57:53 UTC (rev 102131)
+++ projects/jboss-osgi/projects/testing/trunk/src/main/java/org/jboss/osgi/testing/internal/RemoteRuntime.java 2010-03-09 14:59:26 UTC (rev 102132)
@@ -43,13 +43,11 @@
import org.jboss.osgi.jmx.MBeanProxy;
import org.jboss.osgi.jmx.ObjectNameFactory;
import org.jboss.osgi.jmx.ServiceStateMBeanExt;
-import org.jboss.osgi.spi.NotImplementedException;
import org.jboss.osgi.spi.util.BundleInfo;
import org.jboss.osgi.testing.OSGiBundle;
import org.jboss.osgi.testing.OSGiRuntime;
import org.jboss.osgi.testing.OSGiServiceReference;
import org.jboss.osgi.testing.OSGiTestHelper;
-import org.jboss.osgi.vfs.VirtualFile;
import org.osgi.framework.BundleException;
import org.osgi.jmx.framework.BundleStateMBean;
import org.osgi.jmx.framework.ServiceStateMBean;
@@ -72,21 +70,12 @@
super(helper);
}
- public OSGiBundle installBundle(VirtualFile file) throws BundleException, IOException
+ OSGiBundle installBundle(BundleInfo info) throws BundleException
{
- throw new NotImplementedException();
- }
-
- public OSGiBundle installBundle(String location) throws BundleException
- {
try
{
- // Get the bundle info from the location
- BundleInfo info = BundleInfo.createBundleInfo(location);
- String rootURL = info.getRootURL().toExternalForm();
-
- long bundleId = getFrameworkMBean().installBundle(rootURL);
-
+ String location = fixVirtualFileURL(info.getRootURL()).toExternalForm();
+ long bundleId = getFrameworkMBean().installBundle(location);
RemoteBundle bundle = new RemoteBundle(this, bundleId);
return registerBundle(bundle.getLocation(), bundle);
}
@@ -94,13 +83,9 @@
{
throw rte;
}
- catch (BundleException ex)
- {
- throw ex;
- }
catch (Exception ex)
{
- throw new BundleException("Cannot install: " + location, ex);
+ throw new BundleException("Cannot install: " + info, ex);
}
}
Modified: projects/jboss-osgi/projects/testing/trunk/src/test/java/org/jboss/test/osgi/testing/SimpleAssemblyTestCase.java
===================================================================
--- projects/jboss-osgi/projects/testing/trunk/src/test/java/org/jboss/test/osgi/testing/SimpleAssemblyTestCase.java 2010-03-09 14:57:53 UTC (rev 102131)
+++ projects/jboss-osgi/projects/testing/trunk/src/test/java/org/jboss/test/osgi/testing/SimpleAssemblyTestCase.java 2010-03-09 14:59:26 UTC (rev 102132)
@@ -23,24 +23,13 @@
//$Id: SimpleTestCase.java 101150 2010-02-19 10:50:46Z thomas.diesler(a)jboss.com $
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.Closeable;
-import java.io.PrintWriter;
-import java.io.StringWriter;
-import java.net.URISyntaxException;
-import java.net.URL;
-import java.util.List;
-import java.util.jar.JarFile;
-import java.util.jar.Manifest;
-
+import org.jboss.osgi.testing.ManifestBuilder;
import org.jboss.osgi.testing.OSGiBundle;
import org.jboss.osgi.testing.OSGiRuntime;
import org.jboss.osgi.testing.OSGiTest;
-import org.jboss.osgi.vfs.AbstractVFS;
-import org.jboss.osgi.vfs.ManifestBuilder;
import org.jboss.osgi.vfs.VirtualFile;
-import org.jboss.osgi.vfs.VirtualFileAssembly;
+import org.jboss.shrinkwrap.api.Archives;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.jboss.test.osgi.testing.bundle.SimpleActivator;
import org.junit.Test;
import org.osgi.framework.Bundle;
@@ -54,24 +43,22 @@
public class SimpleAssemblyTestCase extends OSGiTest
{
@Test
- public void testSimpleAssembly() throws Exception
+ public void testAssembleArchive() throws Exception
{
OSGiRuntime runtime = getDefaultRuntime();
try
{
- VirtualFileAssembly assembly = AbstractVFS.createVirtualFileAssembly("example-simple.jar");
- assembly.addClass(SimpleActivator.class);
+ JavaArchive archive = Archives.create("example-simple.jar", JavaArchive.class);
+ archive.addClass(SimpleActivator.class);
ManifestBuilder mb = ManifestBuilder.newInstance();
mb.addBundleManifestVersion(2);
mb.addBundleSymbolicName("example-simple");
mb.addBundleActivator(SimpleActivator.class.getName());
mb.addImportPackages("org.jboss.osgi.common.log", "org.osgi.framework", "org.osgi.service.log");
+ archive.setManifest(mb);
- Manifest manifest = mb.getManifest();
- assembly.addManifest(manifest);
-
- OSGiBundle bundle = runtime.installBundle(assembly);
+ OSGiBundle bundle = runtime.installBundle(archive);
assertBundleState(Bundle.INSTALLED, bundle.getState());
}
finally
@@ -79,4 +66,20 @@
runtime.shutdown();
}
}
+
+ @Test
+ public void testAssembleBundle() throws Exception
+ {
+ OSGiRuntime runtime = getDefaultRuntime();
+ try
+ {
+ VirtualFile virtualFile = assembleBundle("example-simple", "/simple", SimpleActivator.class);
+ OSGiBundle bundle = runtime.installBundle(virtualFile);
+ assertBundleState(Bundle.INSTALLED, bundle.getState());
+ }
+ finally
+ {
+ runtime.shutdown();
+ }
+ }
}
\ No newline at end of file
Modified: projects/jboss-osgi/projects/testing/trunk/src/test/java/org/jboss/test/osgi/testing/SimpleTestCase.java
===================================================================
--- projects/jboss-osgi/projects/testing/trunk/src/test/java/org/jboss/test/osgi/testing/SimpleTestCase.java 2010-03-09 14:57:53 UTC (rev 102131)
+++ projects/jboss-osgi/projects/testing/trunk/src/test/java/org/jboss/test/osgi/testing/SimpleTestCase.java 2010-03-09 14:59:26 UTC (rev 102132)
@@ -23,13 +23,19 @@
//$Id$
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import java.net.URL;
+
import org.jboss.osgi.testing.OSGiBundle;
import org.jboss.osgi.testing.OSGiRuntime;
import org.jboss.osgi.testing.OSGiServiceReference;
import org.jboss.osgi.testing.OSGiTest;
+import org.jboss.osgi.vfs.AbstractVFS;
+import org.jboss.osgi.vfs.VirtualFile;
import org.jboss.test.osgi.testing.bundle.SimpleService;
+import org.junit.Ignore;
import org.junit.Test;
import org.osgi.framework.Bundle;
@@ -78,4 +84,36 @@
runtime.shutdown();
}
}
+
+ @Test
+ public void testSimpleArchiveURL() throws Exception
+ {
+ OSGiRuntime runtime = getDefaultRuntime();
+ try
+ {
+ URL archiveURL = getTestArchiveURL("example-simple.jar");
+ OSGiBundle bundle = runtime.installBundle(archiveURL.toExternalForm());
+ assertBundleState(Bundle.INSTALLED, bundle.getState());
+ }
+ finally
+ {
+ runtime.shutdown();
+ }
+ }
+
+ @Ignore // https://jira.jboss.org/jira/browse/JBVFS-147
+ public void testSimpleVirtualFile() throws Exception
+ {
+ OSGiRuntime runtime = getDefaultRuntime();
+ try
+ {
+ VirtualFile archive = AbstractVFS.getChild(getTestArchiveURL("example-simple.jar"));
+ OSGiBundle bundle = runtime.installBundle(archive);
+ assertBundleState(Bundle.INSTALLED, bundle.getState());
+ }
+ finally
+ {
+ runtime.shutdown();
+ }
+ }
}
\ No newline at end of file
Added: projects/jboss-osgi/projects/testing/trunk/src/test/resources/simple/META-INF/MANIFEST.MF
===================================================================
--- projects/jboss-osgi/projects/testing/trunk/src/test/resources/simple/META-INF/MANIFEST.MF (rev 0)
+++ projects/jboss-osgi/projects/testing/trunk/src/test/resources/simple/META-INF/MANIFEST.MF 2010-03-09 14:59:26 UTC (rev 102132)
@@ -0,0 +1,5 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-SymbolicName: example-simple
+Bundle-Activator: org.jboss.test.osgi.testing.bundle.SimpleActivator
+Import-Package: org.jboss.osgi.common.log,org.osgi.framework,org.osgi.service.log
14 years, 3 months