From jboss-osgi-commits at lists.jboss.org Wed Mar 10 05:29:14 2010
Content-Type: multipart/mixed; boundary="===============2196857488909202088=="
MIME-Version: 1.0
From: jboss-osgi-commits at lists.jboss.org
To: jboss-osgi-commits at lists.jboss.org
Subject: [jboss-osgi-commits] JBoss-OSGI SVN: r102218 - in
projects/jboss-osgi/projects/runtime/framework/trunk:
bundle/src/test/java/org/jboss/test/osgi and 4 other directories.
Date: Wed, 10 Mar 2010 05:29:14 -0500
Message-ID: <201003101029.o2AATE5l009472@svn01.web.mwc.hst.phx2.redhat.com>
--===============2196857488909202088==
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: quoted-printable
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/jav=
a/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/jav=
a/org/jboss/test/osgi/FrameworkTest.java
projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/jav=
a/org/jboss/test/osgi/bundle/BundleContextUnitTestCase.java
projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/jav=
a/org/jboss/test/osgi/bundle/BundleEntriesUnitTestCase.java
projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/jav=
a/org/jboss/test/osgi/bundle/BundleLifecycleTestCase.java
projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/jav=
a/org/jboss/test/osgi/bundle/BundleUnitTestCase.java
projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/jav=
a/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.x=
ml
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- projects/jboss-osgi/projects/runtime/framework/trunk/bundle/pom.xml 201=
0-03-10 10:27:55 UTC (rev 102217)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/bundle/pom.xml 201=
0-03-10 10:29:13 UTC (rev 102218)
@@ -13,6 +13,7 @@
=
Modified: projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/t=
est/java/org/jboss/test/osgi/FrameworkTest.java
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/ja=
va/org/jboss/test/osgi/FrameworkTest.java 2010-03-10 10:27:55 UTC (rev 1022=
17)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/ja=
va/org/jboss/test/osgi/FrameworkTest.java 2010-03-10 10:29:13 UTC (rev 1022=
18)
@@ -59,6 +59,7 @@
* @author John Bailey
* @version $Revision: 87848 $
*/
+(a)Deprecated // This has a dependency on VFS21 - use OSGiTest.
public abstract class FrameworkTest extends MicrocontainerTest implements =
FrameworkListener, SynchronousBundleListener, ServiceListener
{
private final List frameworkEvents =3D new CopyOnWriteA=
rrayList();
Added: projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test=
/java/org/jboss/test/osgi/NativeFrameworkTest.java
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/ja=
va/org/jboss/test/osgi/NativeFrameworkTest.java (re=
v 0)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/ja=
va/org/jboss/test/osgi/NativeFrameworkTest.java 2010-03-10 10:29:13 UTC (re=
v 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 Serv=
iceListener, SynchronousBundleListener, FrameworkListener
+{
+ // Provide logging
+ private static final Logger log =3D Logger.getLogger(NativeFrameworkTes=
t.class);
+
+ protected static Framework framework;
+ protected static BundleContext context;
+
+ private final List frameworkEvents =3D new CopyOnWriteA=
rrayList();
+ private final List bundleEvents =3D new CopyOnWriteArrayLi=
st();
+ private final List serviceEvents =3D new CopyOnWriteArray=
List();
+
+ @BeforeClass
+ public static void beforeClass() throws Exception
+ {
+ OSGiBootstrapProvider bootProvider =3D OSGiBootstrap.getBootstrapPro=
vider();
+ framework =3D bootProvider.getFramework();
+ framework.start();
+
+ // Get the system context
+ context =3D framework.getBundleContext();
+ }
+
+ @AfterClass
+ public static void afterClass() throws Exception
+ {
+ if (framework !=3D null)
+ {
+ framework.stop();
+ framework.waitForStop(2000);
+ framework =3D null;
+ }
+ }
+
+ protected void assertNoBundleEvent() throws Exception
+ {
+ log.debug("bundleEvents=3D" + bundleEvents);
+ assertEquals(0, bundleEvents.size());
+ }
+
+ protected void assertBundleEvent(int type, Bundle bundle) throws Except=
ion
+ {
+ waitForEvent(bundleEvents, type);
+
+ log.debug("bundleEvents=3D" + bundleEvents);
+ int size =3D bundleEvents.size();
+ assertTrue("" + size, size > 0);
+
+ if (bundle instanceof AbstractBundleState)
+ bundle =3D ((AbstractBundleState)bundle).getBundle();
+
+ BundleEvent foundEvent =3D null;
+ for (int i =3D 0; i < bundleEvents.size(); i++)
+ {
+ BundleEvent aux =3D bundleEvents.get(i);
+ if (type =3D=3D aux.getType())
+ {
+ if (bundle.equals(aux.getSource()) && bundle.equals(aux.getBun=
dle()))
+ {
+ bundleEvents.remove(aux);
+ foundEvent =3D aux;
+ break;
+ }
+ }
+ }
+
+ if (foundEvent =3D=3D null)
+ fail("Cannot find event " + ConstantsHelper.bundleEvent(type) + "=
from " + bundle);
+ }
+
+ @Override
+ public void frameworkEvent(FrameworkEvent event)
+ {
+ synchronized (frameworkEvents)
+ {
+ log.debug("FrameworkEvent type=3D" + ConstantsHelper.frameworkEve=
nt(event.getType()) + " for " + event);
+ frameworkEvents.add(event);
+ frameworkEvents.notifyAll();
+ }
+ }
+
+ @Override
+ public void bundleChanged(BundleEvent event)
+ {
+ synchronized (bundleEvents)
+ {
+ log.debug("BundleChanged type=3D" + ConstantsHelper.bundleEvent(e=
vent.getType()) + " for " + event);
+ bundleEvents.add(event);
+ bundleEvents.notifyAll();
+ }
+ }
+
+ @Override
+ public void serviceChanged(ServiceEvent event)
+ {
+ synchronized (serviceEvents)
+ {
+ log.debug("ServiceChanged type=3D" + ConstantsHelper.serviceEvent=
(event.getType()) + " for " + event);
+ serviceEvents.add(event);
+ serviceEvents.notifyAll();
+ }
+ }
+
+ protected void assertNoServiceEvent() throws Exception
+ {
+ log.debug("serviceEvents=3D" + serviceEvents);
+ assertEquals(0, serviceEvents.size());
+ }
+
+ protected void assertServiceEvent(int type, ServiceReference reference)=
throws Exception
+ {
+ waitForEvent(serviceEvents, type);
+ log.debug("serviceEvents=3D" + serviceEvents);
+ int size =3D serviceEvents.size();
+ assertTrue("" + size, size > 0);
+ ServiceEvent event =3D serviceEvents.remove(0);
+ assertEquals(ConstantsHelper.serviceEvent(type), ConstantsHelper.ser=
viceEvent(event.getType()));
+ assertEquals(reference, event.getSource());
+ assertEquals(reference, event.getServiceReference());
+ }
+
+ @SuppressWarnings("rawtypes")
+ private void waitForEvent(List events, int type) throws InterruptedExce=
ption
+ {
+ // Timeout for event delivery: 3 sec =
+ int timeout =3D 30;
+
+ boolean eventFound =3D false;
+ while (eventFound =3D=3D false && 0 < timeout)
+ {
+ synchronized (events)
+ {
+ events.wait(100);
+ for (Object aux : events)
+ {
+ if (aux instanceof BundleEvent)
+ {
+ BundleEvent event =3D (BundleEvent)aux;
+ if (type =3D=3D event.getType())
+ {
+ eventFound =3D true;
+ break;
+ }
+ }
+ else if (aux instanceof ServiceEvent)
+ {
+ ServiceEvent event =3D (ServiceEvent)aux;
+ if (type =3D=3D event.getType())
+ {
+ eventFound =3D true;
+ break;
+ }
+ }
+ else if (aux instanceof FrameworkEvent)
+ {
+ FrameworkEvent event =3D (FrameworkEvent)aux;
+ if (type =3D=3D event.getType())
+ {
+ eventFound =3D true;
+ break;
+ }
+ }
+ }
+ }
+ timeout--;
+ }
+ }
+}
Modified: projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/t=
est/java/org/jboss/test/osgi/bundle/BundleContextUnitTestCase.java
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/ja=
va/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/ja=
va/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 =3D addBundle("/bundles/simple/", "simple-bundle1");
+ VirtualFile assembly1 =3D assembleBundle("simple-bundle1", "/bundles=
/simple/simple-bundle1", new Class[0]);
+ Bundle bundle1 =3D context.installBundle(assembly1.toURL().toExterna=
lForm());
BundleContext context1 =3D null;
try
{
@@ -75,11 +74,11 @@
=
Bundle[] bundles =3D context1.getBundles();
Set actual =3D new HashSet(Arrays.asList(bundles)=
);
- Set expected =3D new HashSet(Arrays.asList(bundle=
1));
- addBaseBundles(expected);
+ Set expected =3D new HashSet(Arrays.asList(framew=
ork, bundle1));
assertEquals(expected, actual);
=
- Bundle bundle2 =3D addBundle("/bundles/simple/", "simple-bundle2"=
);
+ VirtualFile assembly2 =3D assembleBundle("simple-bundle2", "/bund=
les/simple/simple-bundle2", new Class[0]);
+ Bundle bundle2 =3D context.installBundle(assembly2.toURL().toExte=
rnalForm());
BundleContext context2 =3D null;
try
{
@@ -89,8 +88,7 @@
=
bundles =3D context1.getBundles();
actual =3D new HashSet(Arrays.asList(bundles));
- expected =3D new HashSet(Arrays.asList(bundle1, bundle=
2));
- addBaseBundles(expected);
+ expected =3D new HashSet(Arrays.asList(framework, bund=
le1, 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 =3D context1.getBundles();
actual =3D new HashSet(Arrays.asList(bundles));
- expected =3D new HashSet(Arrays.asList(bundle1));
- addBaseBundles(expected);
+ expected =3D new HashSet(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 =3D addBundle("/bundles/simple/", "simple-bundle1");
+ VirtualFile assembly =3D assembleBundle("simple-bundle1", "/bundles/=
simple/simple-bundle1", new Class[0]);
+ Bundle bundle =3D context.installBundle(assembly.toURL().toExternalF=
orm());
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 =3D new OSGiTestHelper();
- =
- // Test URL location
- URL url =3D helper.getTestArchiveURL("bundles/jboss-osgi-common.jar"=
);
- Bundle bundle =3D installBundle(url.toExternalForm());
+ URL url =3D getTestArchiveURL("bundles/jboss-osgi-common.jar");
+ Bundle bundle =3D context.installBundle(url.toExternalForm());
try
{
assertBundleState(Bundle.INSTALLED, bundle.getState());
@@ -231,8 +228,8 @@
}
=
// Test file location
- String location =3D helper.getTestArchivePath("bundles/jboss-osgi-co=
mmon.jar");
- bundle =3D installBundle(location);
+ String location =3D getTestArchivePath("bundles/jboss-osgi-common.ja=
r");
+ bundle =3D context.installBundle(location);
try
{
assertBundleState(Bundle.INSTALLED, bundle.getState());
@@ -245,7 +242,7 @@
}
=
// Test symbolic location
- bundle =3D installBundle("/symbolic/location", url.openStream());
+ bundle =3D context.installBundle("/symbolic/location", url.openStrea=
m());
try
{
assertBundleState(Bundle.INSTALLED, bundle.getState());
@@ -258,9 +255,11 @@
}
}
=
+ @Test
public void testServiceListener() throws Exception
{
- Bundle bundle =3D addBundle("/bundles/simple/", "simple-bundle1");
+ VirtualFile assembly =3D assembleBundle("simple-bundle1", "/bundles/=
simple/simple-bundle1", new Class[0]);
+ Bundle bundle =3D context.installBundle(assembly.toURL().toExternalF=
orm());
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=3Db)");
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 e=
vents) throws Exception
- {
- return assertServiceLifecycle(bundle, null, events);
- }
- =
- protected BundleContext assertServiceLifecycle(Bundle bundle, Dictionar=
y properties, boolean events) throws Exception
- {
- assertNoServiceEvent();
- =
- BundleContext bundleContext =3D bundle.getBundleContext();
- ServiceRegistration registration =3D bundleContext.registerService(B=
undleContext.class.getName(), bundleContext, properties);
- ServiceReference reference =3D 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 =3D bundleContext.registerService(BundleContext.class.g=
etName(), bundleContext, properties);
- reference =3D 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 =3D bundle.getBundleContext();
- assertNotNull(bundleContext);
- =
- return bundleContext;
- }
- =
+ @Test
public void testBundleListener() throws Exception
{
- // todo how to test INSTALLED/RESOLVED?
- Bundle bundle =3D addBundle("/bundles/simple/", "simple-bundle1");
+ VirtualFile assembly =3D assembleBundle("simple-bundle1", "/bundles/=
simple/simple-bundle1", new Class[0]);
+ Bundle bundle =3D context.installBundle(assembly.toURL().toExternalF=
orm());
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 ev=
ents) 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 =3D addBundle("/bundles/simple/", "simple-bundle1");
+ VirtualFile assembly =3D assembleBundle("simple-bundle1", "/bundles/=
simple/simple-bundle1", new Class[0]);
+ Bundle bundle =3D context.installBundle(assembly.toURL().toExternalF=
orm());
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 =3D addBundle("/bundles/simple/", "simple-bundle1");
+ VirtualFile assembly =3D assembleBundle("simple-bundle1", "/bundles/=
simple/simple-bundle1", new Class[0]);
+ Bundle bundle =3D context.installBundle(assembly.toURL().toExternalF=
orm());
try
{
bundle.start();
@@ -547,13 +462,15 @@
}
finally
{
- uninstall(bundle);
+ bundle.uninstall();
}
}
=
+ @Test
public void testStopedBundleContext() throws Exception
{
- Bundle bundle =3D addBundle("/bundles/simple/", "simple-bundle1");
+ VirtualFile assembly =3D assembleBundle("simple-bundle1", "/bundles/=
simple/simple-bundle1", new Class[0]);
+ Bundle bundle =3D context.installBundle(assembly.toURL().toExternalF=
orm());
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 bu=
ndle
@@ -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 even=
ts) 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 p=
roperty, String osgiProperty)
+ {
String expected =3D System.getProperty(property);
assertNotNull(expected);
assertEquals(expected, bundleContext.getProperty(osgiProperty));
}
+
+ private BundleContext assertServiceLifecycle(Bundle bundle, boolean eve=
nts) throws Exception
+ {
+ return assertServiceLifecycle(bundle, null, events);
+ }
+ =
+ private BundleContext assertServiceLifecycle(Bundle bundle, Dictionary<=
String, Object> properties, boolean events) throws Exception
+ {
+ assertNoServiceEvent();
+ =
+ BundleContext bundleContext =3D bundle.getBundleContext();
+ ServiceRegistration registration =3D bundleContext.registerService(B=
undleContext.class.getName(), bundleContext, properties);
+ ServiceReference reference =3D 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 =3D bundleContext.registerService(BundleContext.class.g=
etName(), bundleContext, properties);
+ reference =3D 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 =3D bundle.getBundleContext();
+ assertNotNull(bundleContext);
+ =
+ return bundleContext;
+ }
}
Modified: projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/t=
est/java/org/jboss/test/osgi/bundle/BundleEntriesUnitTestCase.java
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/ja=
va/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/ja=
va/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 Adrian Brock
+ * @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 =3D addBundle("/bundles/entries/", "entries-simple");
- uninstall(bundle);
+ VirtualFile assembly =3D assembleBundle("entries-simple", "/bundles/=
entries/entries-simple", new Class[0]);
+ Bundle bundle =3D context.installBundle(assembly.toURL().toExternalF=
orm());
+ 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 =3D addBundle("/bundles/entries/", "entries-simple");
+ VirtualFile assembly =3D assembleBundle("entries-simple", "/bundles/=
entries/entries-simple", new Class[0]);
+ Bundle bundle =3D context.installBundle(assembly.toURL().toExternalF=
orm());
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 =3D addBundle("/bundles/entries/", "entries-simple");
+ VirtualFile assembly =3D assembleBundle("entries-simple", "/bundles/=
entries/entries-simple", new Class[0]);
+ Bundle bundle =3D context.installBundle(assembly.toURL().toExternalF=
orm());
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 =3D getBundleResource(bundle, path);
- if (expected =3D=3D null)
- fail("Expected resource not found: " + path);
-
- assertEntry(bundle, path, expected);
- assertEntry(bundle, "/" + path, expected);
- }
-
- protected void assertEntry(Bundle bundle, String path, URL expected) th=
rows Exception
- {
URL actual =3D bundle.getEntry(path);
- assertEquals(expected, actual);
+ assertNotNull("Entry expected for: " + path, actual);
}
=
protected void assertNoEntry(Bundle bundle, String path) throws Excepti=
on
@@ -393,30 +384,19 @@
assertNull("Did not expect entry: " + actual + " for path: " + path,=
actual);
}
=
+ @SuppressWarnings("unchecked")
protected void assertEntries(Bundle bundle, String path, String filePat=
tern, boolean recurse, String... entries) throws Exception
{
- Set expected =3D new HashSet();
- for (String entry : entries)
- {
- Enumeration urls =3D getBundleResources(bundle, entry);
- if (urls =3D=3D null || urls.hasMoreElements() =3D=3D 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 filePat=
tern, boolean recurse, Set expected) throws Exception
- {
Set actual =3D new HashSet();
Enumeration enumeration =3D bundle.findEntries(path, filePatter=
n, recurse);
while (enumeration !=3D null && enumeration.hasMoreElements())
actual.add(enumeration.nextElement());
=
+ URL baseurl =3D bundle.getEntry("/");
+ Set expected =3D new HashSet();
+ for (String entry : entries)
+ expected.add(new URL(baseurl + entry));
+
assertEquals(expected, actual);
}
=
Modified: projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/t=
est/java/org/jboss/test/osgi/bundle/BundleLifecycleTestCase.java
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/ja=
va/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/ja=
va/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 =3D installBundle(assembleBundle("lifecycle-service",=
"/bundles/lifecycle/simple-service", LifecycleService.class));
+ VirtualFile assemblyA =3D assembleBundle("lifecycle-service", "/bund=
les/lifecycle/simple-service", LifecycleService.class);
+ Bundle bundleA =3D context.installBundle(assemblyA.toURL().toExterna=
lForm());
try
{
assertBundleState(Bundle.INSTALLED, bundleA.getState());
@@ -76,18 +73,21 @@
/**
* Verifies that the bundle state is RESOLVED after a failure in Bundle=
Activator.start()
*/
+ @Test
public void testDependencyNotAvailable() throws Exception
{
- Bundle bundleA =3D installBundle(assembleBundle("lifecycle-service",=
"/bundles/lifecycle/simple-service", LifecycleService.class));
+ VirtualFile assemblyA =3D assembleBundle("lifecycle-service", "/bund=
les/lifecycle/simple-service", LifecycleService.class);
+ Bundle bundleA =3D context.installBundle(assemblyA.toURL().toExterna=
lForm());
try
{
assertBundleState(Bundle.INSTALLED, bundleA.getState());
=
// BundleA not started - service not available =
- ServiceReference sref =3D getSystemBundle().getBundleContext().ge=
tServiceReference(LifecycleService.class.getName());
+ ServiceReference sref =3D context.getServiceReference(LifecycleSe=
rvice.class.getName());
assertNull("Service not available", sref);
=
- Bundle bundleB =3D installBundle(assembleBundle("lifecycle-failst=
art", "/bundles/lifecycle/fail-on-start", FailOnStartActivator.class));
+ VirtualFile assemblyB =3D assembleBundle("lifecycle-failstart", "=
/bundles/lifecycle/fail-on-start", FailOnStartActivator.class);
+ Bundle bundleB =3D context.installBundle(assemblyB.toURL().toExte=
rnalForm());
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 =3D installBundle(assembleBundle("lifecycle-service",=
"/bundles/lifecycle/simple-service", LifecycleService.class));
+ VirtualFile assemblyA =3D assembleBundle("lifecycle-service", "/bund=
les/lifecycle/simple-service", LifecycleService.class);
+ Bundle bundleA =3D context.installBundle(assemblyA.toURL().toExterna=
lForm());
try
{
bundleA.start();
assertBundleState(Bundle.ACTIVE, bundleA.getState());
=
- Bundle bundleB =3D installBundle(assembleBundle("lifecycle-failst=
art", "/bundles/lifecycle/fail-on-start", FailOnStartActivator.class));
+ VirtualFile assemblyB =3D assembleBundle("lifecycle-failstart", "=
/bundles/lifecycle/fail-on-start", FailOnStartActivator.class);
+ Bundle bundleB =3D context.installBundle(assemblyB.toURL().toExte=
rnalForm());
try
{
bundleB.start();
@@ -145,14 +148,17 @@
/**
* Verifies that BundleB can get started when the service is made avail=
able =
*/
+ @Test
public void testStartRetry() throws Exception
{
- Bundle bundleA =3D installBundle(assembleBundle("lifecycle-service",=
"/bundles/lifecycle/simple-service", LifecycleService.class));
+ VirtualFile assemblyA =3D assembleBundle("lifecycle-service", "/bund=
les/lifecycle/simple-service", LifecycleService.class);
+ Bundle bundleA =3D context.installBundle(assemblyA.toURL().toExterna=
lForm());
try
{
assertBundleState(Bundle.INSTALLED, bundleA.getState());
=
- Bundle bundleB =3D installBundle(assembleBundle("lifecycle-failst=
art", "/bundles/lifecycle/fail-on-start", FailOnStartActivator.class));
+ VirtualFile assemblyB =3D assembleBundle("lifecycle-failstart", "=
/bundles/lifecycle/fail-on-start", FailOnStartActivator.class);
+ Bundle bundleB =3D context.installBundle(assemblyB.toURL().toExte=
rnalForm());
try
{
assertBundleState(Bundle.INSTALLED, bundleB.getState());
@@ -191,17 +197,18 @@
/**
* Verifies that BundleB is still INSTALLED after a failure in PackageA=
dmin.resolve()
*/
+ @Test
public void testFailToResolve() throws Exception
{
- Bundle bundleB =3D installBundle(assembleBundle("lifecycle-failstart=
", "/bundles/lifecycle/fail-on-start", FailOnStartActivator.class));
+ VirtualFile assemblyA =3D assembleBundle("lifecycle-failstart", "/bu=
ndles/lifecycle/fail-on-start", FailOnStartActivator.class);
+ Bundle bundleB =3D context.installBundle(assemblyA.toURL().toExterna=
lForm());
try
{
assertBundleState(Bundle.INSTALLED, bundleB.getState());
=
// Get the PackageAdmin service
- BundleContext sysContext =3D getSystemBundle().getBundleContext();
- ServiceReference sref =3D sysContext.getServiceReference(PackageA=
dmin.class.getName());
- PackageAdmin packageAdmin =3D (PackageAdmin)sysContext.getService=
(sref);
+ ServiceReference sref =3D context.getServiceReference(PackageAdmi=
n.class.getName());
+ PackageAdmin packageAdmin =3D (PackageAdmin)context.getService(sr=
ef);
=
// Attempt to explicitly resolve a bundle with missing dependency =
boolean allResolved =3D packageAdmin.resolveBundles(new Bundle[] =
{ bundleB });
@@ -220,11 +227,13 @@
/**
* Verifies that we get a BundleException when an invalid bundle is ins=
talled
*/
+ @Test
public void testInstallInvalid() throws Exception
{
try
{
- installBundle(assembleBundle("missing-symbolic-name", "/bundles/l=
ifecycle/invalid01"));
+ VirtualFile assembly =3D 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/lifecycl=
e/invalid02"));
+ VirtualFile assembly =3D assembleBundle("invalid-export", "/bundl=
es/lifecycle/invalid02");
+ context.installBundle(assembly.toURL().toExternalForm());
fail("BundleException expected");
}
catch (BundleException ex)
Modified: projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/t=
est/java/org/jboss/test/osgi/bundle/BundleUnitTestCase.java
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/ja=
va/org/jboss/test/osgi/bundle/BundleUnitTestCase.java 2010-03-10 10:27:55 U=
TC (rev 102217)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/ja=
va/org/jboss/test/osgi/bundle/BundleUnitTestCase.java 2010-03-10 10:29:13 U=
TC (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 =3D -1;
- Bundle bundle =3D addBundle("/bundles/simple/", "simple-bundle1");
+ VirtualFile assembly =3D assembleBundle("simple-bundle1", "/bundles/=
simple/simple-bundle1", new Class[0]);
+ Bundle bundle =3D context.installBundle(assembly.toURL().toExternalF=
orm());
try
{
id1 =3D bundle.getBundleId();
}
finally
{
- uninstall(bundle);
+ bundle.uninstall();
}
assertEquals(id1, bundle.getBundleId());
=
long id2 =3D -1;
- bundle =3D addBundle("/bundles/simple/", "simple-bundle1");
+ bundle =3D context.installBundle(assembly.toURL().toExternalForm());
try
{
id2 =3D bundle.getBundleId();
}
finally
{
- uninstall(bundle);
+ bundle.uninstall();
}
assertEquals(id2, bundle.getBundleId());
assertTrue("Ids should be different" + id1 + "," + id2, id1 !=3D id2=
);
}
=
+ @Test
public void testSymbolicName() throws Exception
{
- Bundle bundle =3D addBundle("/bundles/simple/", "simple-bundle1");
+ VirtualFile assembly =3D assembleBundle("simple-bundle1", "/bundles/=
simple/simple-bundle1", new Class[0]);
+ Bundle bundle =3D context.installBundle(assembly.toURL().toExternalF=
orm());
try
{
assertEquals("org.jboss.test.osgi.simple1", bundle.getSymbolicNam=
e());
}
finally
{
- uninstall(bundle);
+ bundle.uninstall();
}
assertEquals("org.jboss.test.osgi.simple1", bundle.getSymbolicName()=
);
}
=
+ @Test
public void testState() throws Exception
{
- Bundle bundle =3D addBundle("/bundles/simple/", "simple-bundle1");
+ VirtualFile assembly =3D assembleBundle("simple-bundle1", "/bundles/=
simple/simple-bundle1", new Class[0]);
+ Bundle bundle =3D context.installBundle(assembly.toURL().toExternalF=
orm());
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 =3D addBundle("/bundles/simple/", "simple-bundle1");
+ VirtualFile assembly =3D assembleBundle("simple-bundle1", "/bundles/=
simple/simple-bundle1", new Class[0]);
+ Bundle bundle =3D context.installBundle(assembly.toURL().toExternalF=
orm());
try
{
BundleContext bundleContext =3D 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 =3D assembleBundle("bundle1", "/bundles/update=
/update-bundle1");
@@ -163,13 +169,10 @@
new JarOutputStream(baos, manifest).close();
ByteArrayInputStream updateStream =3D new ByteArrayInputStream(baos.=
toByteArray());
=
- // [JBVFS-130] VFSUtils.temp(assembledDirectory) cannot create tmp d=
ir
- // assemble2 =3D VFSUtils.temp(assemble2);
- =
- Bundle bundle =3D installBundle(assemble1);
+ Bundle bundle =3D context.installBundle(assemble1.toURL().toExternal=
Form());
try
{
- int beforeCount =3D getBundleManager().getBundles().size();
+ int beforeCount =3D 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(C=
onstants.BUNDLE_VERSION));
=
- int afterCount =3D getBundleManager().getBundles().size();
+ int afterCount =3D 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 =3D installBundle(assembleBundle("bundle10", "/bundle=
s/singleton/singleton1"));
+ VirtualFile assemblyA =3D assembleBundle("bundle10", "/bundles/singl=
eton/singleton1");
+ Bundle bundleA =3D context.installBundle(assemblyA.toURL().toExterna=
lForm());
try
{
- Bundle bundle2 =3D installBundle(assembleBundle("bundle20", "/bun=
dles/singleton/singleton2"));
- uninstall(bundle2);
+ VirtualFile assemblyB =3D assembleBundle("bundle20", "/bundles/si=
ngleton/singleton2");
+ Bundle bundleB =3D context.installBundle(assemblyB.toURL().toExte=
rnalForm());
+ 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 =3D installBundle(assembleBundle("bundle1", "/bundles=
/singleton/singleton1"));
+ VirtualFile assemblyA =3D assembleBundle("bundle1", "/bundles/single=
ton/singleton1");
+ Bundle bundleA =3D context.installBundle(assemblyA.toURL().toExterna=
lForm());
try
{
- Bundle bundle2 =3D installBundle(assembleBundle("not-singleton", =
"/bundles/singleton/not-singleton"));
+ VirtualFile assemblyB =3D assembleBundle("not-singleton", "/bundl=
es/singleton/not-singleton");
+ Bundle bundleB =3D context.installBundle(assemblyB.toURL().toExte=
rnalForm());
try
{
- assertEquals(bundle1.getSymbolicName(), bundle2.getSymbolicNam=
e());
+ assertEquals(bundleA.getSymbolicName(), bundleB.getSymbolicNam=
e());
}
finally
{
- uninstall(bundle2);
+ bundleB.uninstall();
}
}
finally
{
- uninstall(bundle1);
+ bundleA.uninstall();
}
}
=
+ @Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void testGetHeaders() throws Exception
{
- // TODO case insensistive
- Bundle bundle =3D addBundle("/bundles/simple/", "simple-bundle1");
+ VirtualFile assembly =3D assembleBundle("simple-bundle1", "/bundles/=
simple/simple-bundle1", new Class[0]);
+ Bundle bundle =3D context.installBundle(assembly.toURL().toExternalF=
orm());
try
{
Dictionary expected =3D 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/t=
est/java/org/jboss/test/osgi/bundle/SystemBundleUnitTestCase.java
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/ja=
va/org/jboss/test/osgi/bundle/SystemBundleUnitTestCase.java 2010-03-10 10:2=
7:55 UTC (rev 102217)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/bundle/src/test/ja=
va/org/jboss/test/osgi/bundle/SystemBundleUnitTestCase.java 2010-03-10 10:2=
9: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 Adrian Brock
+ * @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.getSymb=
olicName());
}
=
+ @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 i=
mplementation");
}
=
+ @Test
public void testUpdate() throws Exception
{
System.out.println("FIXME [JBOSGI-138] Proper system BundleContext i=
mplementation");
}
=
+ @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 =3D getSystemBundle().getHeaders();
+ Dictionary dictionary =3D framework.getHeaders();
assertEquals(expected, dictionary);
}
=
+ @Test
public void testLocation() throws Exception
{
- assertEquals(Constants.SYSTEM_BUNDLE_LOCATION, getSystemBundle().get=
Location());
+ assertEquals(Constants.SYSTEM_BUNDLE_LOCATION, framework.getLocation=
());
}
=
+ @Test
public void testGetEntry()
{
System.out.println("FIXME [JBOSGI-138] Proper system BundleContext i=
mplementation");
}
=
+ @Test
public void testGetEntryPath()
{
System.out.println("FIXME [JBOSGI-138] Proper system BundleContext i=
mplementation");
}
=
+ @Test
public void testFindEntries()
{
System.out.println("FIXME [JBOSGI-138] Proper system BundleContext i=
mplementation");
}
=
+ @Test
public void testLoadClass()
{
System.out.println("FIXME [JBOSGI-138] Proper system BundleContext i=
mplementation");
}
=
+ @Test
public void testGetResource()
{
System.out.println("FIXME [JBOSGI-138] Proper system BundleContext i=
mplementation");
}
=
+ @Test
public void testGetResources()
{
System.out.println("FIXME [JBOSGI-138] Proper system BundleContext i=
mplementation");
Modified: projects/jboss-osgi/projects/runtime/framework/trunk/core/src/mai=
n/java/org/jboss/osgi/framework/bundle/OSGiBundleWrapper.java
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- 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 =3D (OSGiBundleWrapper)obj;
+ return bundleState.equals(other.getBundleState());
+ }
+
+ @Override
+ public String toString()
+ {
+ return bundleState.toString();
+ }
}
Modified: projects/jboss-osgi/projects/runtime/framework/trunk/core/src/mai=
n/java/org/jboss/osgi/framework/launch/OSGiFramework.java
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- 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 Fram=
ework
{
// Provide logging
final Logger log =3D Logger.getLogger(OSGiFramework.class);
Modified: projects/jboss-osgi/projects/runtime/framework/trunk/core/src/mai=
n/java/org/jboss/osgi/framework/plugins/internal/FrameworkEventsPluginImpl.=
java
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- projects/jboss-osgi/projects/runtime/framework/trunk/core/src/main/java=
/org/jboss/osgi/framework/plugins/internal/FrameworkEventsPluginImpl.java 2=
010-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 2=
010-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 infoEvents =3D new HashSet();
+ /** The set of bundle events that are delivered to an (asynchronous) Bu=
ndleListener */
+ private Set asyncBundleEvents =3D new HashSet();
=
public FrameworkEventsPluginImpl(OSGiBundleManager bundleManager)
{
super(bundleManager);
executorService =3D 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 =3D new OSGiBundleEvent(type, assertBundle(b=
undle));
final String typeName =3D 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 !=3D BundleEvent.STARTING && type !=3D BundleEvent.ST=
OPPING && type !=3D 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)
{
--===============2196857488909202088==--