[jboss-cvs] JBossAS SVN: r92988 - in projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/java/org/jboss/test/osgi: service/support and 1 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Sat Aug 29 08:15:32 EDT 2009
Author: thomas.diesler at jboss.com
Date: 2009-08-29 08:15:32 -0400 (Sat, 29 Aug 2009)
New Revision: 92988
Added:
projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/java/org/jboss/test/osgi/service/support/SimpleService.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/java/org/jboss/test/osgi/service/support/SimpleServiceFactory.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/java/org/jboss/test/osgi/service/support/SimpleServiceImpl.java
Removed:
projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/java/org/jboss/test/osgi/service/support/SimpleServiceFactory.java
Modified:
projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/java/org/jboss/test/osgi/OSGiTestCase.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/java/org/jboss/test/osgi/service/test/GetUnGetServiceUnitTestCase.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/java/org/jboss/test/osgi/service/test/RegisterServiceUnitTestCase.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/java/org/jboss/test/osgi/service/test/ServiceRegistrationUnitTestCase.java
Log:
SimpleServiceFactory creates new SimpleService objects on behalf of the caller
Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/java/org/jboss/test/osgi/OSGiTestCase.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/java/org/jboss/test/osgi/OSGiTestCase.java 2009-08-29 02:30:18 UTC (rev 92987)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/java/org/jboss/test/osgi/OSGiTestCase.java 2009-08-29 12:15:32 UTC (rev 92988)
@@ -21,6 +21,7 @@
*/
package org.jboss.test.osgi;
+import java.lang.reflect.Method;
import java.net.URL;
import java.util.Arrays;
import java.util.Collection;
@@ -37,6 +38,7 @@
import org.jboss.osgi.plugins.facade.bundle.OSGiBundleManager;
import org.jboss.test.AbstractTestDelegate;
import org.jboss.test.kernel.junit.MicrocontainerTest;
+import org.jboss.test.osgi.service.support.SimpleServiceFactory;
import org.jboss.virtual.AssembledDirectory;
import org.jboss.virtual.VirtualFile;
import org.osgi.framework.Bundle;
@@ -47,6 +49,7 @@
import org.osgi.framework.FrameworkEvent;
import org.osgi.framework.FrameworkListener;
import org.osgi.framework.ServiceEvent;
+import org.osgi.framework.ServiceFactory;
import org.osgi.framework.ServiceListener;
import org.osgi.framework.ServiceReference;
import org.osgi.framework.SynchronousBundleListener;
@@ -509,4 +512,29 @@
assertEquals(reference, event.getSource());
assertEquals(reference, event.getServiceReference());
}
+
+ protected ServiceFactory createServiceFactory(Bundle bundle) throws Exception
+ {
+ Class<?> factoryClazz = bundle.loadClass(SimpleServiceFactory.class.getName());
+ Object serviceFactory = factoryClazz.newInstance();
+ return (ServiceFactory)serviceFactory;
+ }
+
+ protected void assertServiceInstanceOf(Class<?> expClazz, Object wasObj)
+ {
+ assertNotNull("Not null object", wasObj);
+ Class<?>[] interfaces = wasObj.getClass().getInterfaces();
+ for (Class<?> interf : interfaces)
+ {
+ if (expClazz.getName().equals(interf.getName()))
+ return;
+ }
+ fail(wasObj.getClass().getName() + " is not an instance of " + expClazz.getName());
+ }
+
+ protected Object callServiceMethod(Object service, String methodName) throws Exception
+ {
+ Method method = service.getClass().getDeclaredMethod(methodName, (Class[])null);
+ return method.invoke(service, (Object[])null);
+ }
}
Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/java/org/jboss/test/osgi/service/support/SimpleService.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/java/org/jboss/test/osgi/service/support/SimpleService.java (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/java/org/jboss/test/osgi/service/support/SimpleService.java 2009-08-29 12:15:32 UTC (rev 92988)
@@ -0,0 +1,35 @@
+/*
+* 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.service.support;
+
+
+/**
+ * A simple service that returns the symbolic name of the
+ * creator bundle
+ *
+ * @author Thomas.Diesler at jboss.com
+ * @version $Revision$
+ */
+public interface SimpleService
+{
+ String getSymbolicName();
+}
Property changes on: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/java/org/jboss/test/osgi/service/support/SimpleService.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Deleted: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/java/org/jboss/test/osgi/service/support/SimpleServiceFactory.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/java/org/jboss/test/osgi/service/support/SimpleServiceFactory.java 2009-08-29 02:30:18 UTC (rev 92987)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/java/org/jboss/test/osgi/service/support/SimpleServiceFactory.java 2009-08-29 12:15:32 UTC (rev 92988)
@@ -1,59 +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.service.support;
-
-import org.osgi.framework.Bundle;
-import org.osgi.framework.ServiceFactory;
-import org.osgi.framework.ServiceRegistration;
-
-/**
- * SimpleServiceFactory.
- *
- * @author <a href="adrian at jboss.com">Adrian Brock</a>
- * @version $Revision: 1.1 $
- */
-public class SimpleServiceFactory implements ServiceFactory
-{
- public Object service;
-
- public Bundle ungetBundle;
- public ServiceRegistration ungetRegisation;
- public Object ungetService;
-
- public SimpleServiceFactory(Object service)
- {
- this.service = service;
- }
-
- public Object getService(Bundle bundle, ServiceRegistration registration)
- {
- return service;
- }
-
- public void ungetService(Bundle bundle, ServiceRegistration registration, Object service)
- {
- ungetBundle = bundle;
- ungetRegisation = registration;
- ungetService = service;
- }
-
-}
Copied: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/java/org/jboss/test/osgi/service/support/SimpleServiceFactory.java (from rev 92987, projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/java/org/jboss/test/osgi/service/support/SimpleServiceFactory.java)
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/java/org/jboss/test/osgi/service/support/SimpleServiceFactory.java (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/java/org/jboss/test/osgi/service/support/SimpleServiceFactory.java 2009-08-29 12:15:32 UTC (rev 92988)
@@ -0,0 +1,44 @@
+/*
+* 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.service.support;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.ServiceFactory;
+import org.osgi.framework.ServiceRegistration;
+
+/**
+ * SimpleServiceFactory.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class SimpleServiceFactory implements ServiceFactory
+{
+ public Object getService(Bundle bundle, ServiceRegistration registration)
+ {
+ return new SimpleServiceImpl(bundle);
+ }
+
+ public void ungetService(Bundle bundle, ServiceRegistration registration, Object service)
+ {
+ }
+}
Added: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/java/org/jboss/test/osgi/service/support/SimpleServiceImpl.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/java/org/jboss/test/osgi/service/support/SimpleServiceImpl.java (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/java/org/jboss/test/osgi/service/support/SimpleServiceImpl.java 2009-08-29 12:15:32 UTC (rev 92988)
@@ -0,0 +1,46 @@
+/*
+* 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.service.support;
+
+import org.osgi.framework.Bundle;
+
+/**
+ * A simple service that returns the symbolic name of the
+ * creator bundle
+ *
+ * @author Thomas.Diesler at jboss.com
+ * @version $Revision$
+ */
+public class SimpleServiceImpl implements SimpleService
+{
+ public Bundle bundle;
+
+ public SimpleServiceImpl(Bundle bundle)
+ {
+ this.bundle = bundle;
+ }
+
+ public String getSymbolicName()
+ {
+ return bundle.getSymbolicName();
+ }
+}
Property changes on: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/java/org/jboss/test/osgi/service/support/SimpleServiceImpl.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/java/org/jboss/test/osgi/service/test/GetUnGetServiceUnitTestCase.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/java/org/jboss/test/osgi/service/test/GetUnGetServiceUnitTestCase.java 2009-08-29 02:30:18 UTC (rev 92987)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/java/org/jboss/test/osgi/service/test/GetUnGetServiceUnitTestCase.java 2009-08-29 12:15:32 UTC (rev 92988)
@@ -21,14 +21,17 @@
*/
package org.jboss.test.osgi.service.test;
+
import junit.framework.Test;
import org.jboss.test.osgi.OSGiTestCase;
import org.jboss.test.osgi.service.support.BrokenServiceFactory;
+import org.jboss.test.osgi.service.support.SimpleService;
import org.jboss.test.osgi.service.support.SimpleServiceFactory;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.FrameworkEvent;
+import org.osgi.framework.ServiceFactory;
import org.osgi.framework.ServiceReference;
import org.osgi.framework.ServiceRegistration;
@@ -51,11 +54,11 @@
{
return suite(GetUnGetServiceUnitTestCase.class);
}
-
+
public void testGetUnServiceErrors() throws Exception
{
String OBJCLASS = BundleContext.class.getName();
-
+
Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
try
{
@@ -64,7 +67,7 @@
assertNotNull(bundleContext);
bundleContext.registerService(OBJCLASS, bundleContext, null);
-
+
try
{
bundleContext.getService(null);
@@ -74,7 +77,7 @@
{
checkThrowable(IllegalArgumentException.class, t);
}
-
+
try
{
bundleContext.ungetService(null);
@@ -90,11 +93,11 @@
uninstall(bundle);
}
}
-
+
public void testGetService() throws Exception
{
String OBJCLASS = BundleContext.class.getName();
-
+
Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
try
{
@@ -107,7 +110,7 @@
Object actual = bundleContext.getService(reference);
assertEquals(bundleContext, actual);
-
+
registration.unregister();
actual = bundleContext.getService(reference);
assertNull("" + actual, actual);
@@ -117,11 +120,11 @@
uninstall(bundle);
}
}
-
+
public void testGetServiceAfterStop() throws Exception
{
String OBJCLASS = BundleContext.class.getName();
-
+
Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
try
{
@@ -134,7 +137,7 @@
Object actual = bundleContext.getService(reference);
assertEquals(bundleContext, actual);
-
+
bundle.stop();
try
{
@@ -151,54 +154,55 @@
uninstall(bundle);
}
}
-
+
public void testGetServiceFactory() throws Exception
{
- String OBJCLASS = BundleContext.class.getName();
-
- Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ Bundle bundle = assembleBundle("bundle", "/bundles/simple/simple-bundle1", SimpleService.class);
+
try
{
bundle.start();
BundleContext bundleContext = bundle.getBundleContext();
assertNotNull(bundleContext);
- ServiceRegistration registration = bundleContext.registerService(OBJCLASS, new SimpleServiceFactory(bundleContext), null);
+ ServiceFactory serviceFactory = createServiceFactory(bundle);
+ ServiceRegistration registration = bundleContext.registerService(SimpleService.class.getName(), serviceFactory, null);
ServiceReference reference = registration.getReference();
- Object actual = bundleContext.getService(reference);
- assertEquals(bundleContext, actual);
+ Object actualFirst = bundleContext.getService(reference);
+ assertServiceInstanceOf(SimpleService.class, actualFirst);
+ assertEquals(bundle.getSymbolicName(), callServiceMethod(actualFirst, "getSymbolicName"));
- actual = bundleContext.getService(reference);
- assertEquals(bundleContext, actual);
-
+ Object actualSecond = bundleContext.getService(reference);
+ assertSame(actualFirst, actualSecond);
+
registration.unregister();
- actual = bundleContext.getService(reference);
- assertNull("" + actual, actual);
+ Object actualThird = bundleContext.getService(reference);
+ assertNull("" + actualThird, actualThird);
}
finally
{
uninstall(bundle);
}
}
-
+
public void testGetServiceFactoryAfterStop() throws Exception
{
- String OBJCLASS = BundleContext.class.getName();
-
- Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ Bundle bundle = assembleBundle("bundle", "/bundles/simple/simple-bundle1", SimpleService.class);
try
{
bundle.start();
BundleContext bundleContext = bundle.getBundleContext();
assertNotNull(bundleContext);
- ServiceRegistration registration = bundleContext.registerService(OBJCLASS, new SimpleServiceFactory(bundleContext), null);
+ ServiceFactory serviceFactory = createServiceFactory(bundle);
+ ServiceRegistration registration = bundleContext.registerService(SimpleService.class.getName(), serviceFactory, null);
ServiceReference reference = registration.getReference();
Object actual = bundleContext.getService(reference);
- assertEquals(bundleContext, actual);
-
+ assertServiceInstanceOf(SimpleService.class, actual);
+ assertEquals(bundle.getSymbolicName(), callServiceMethod(actual, "getSymbolicName"));
+
bundle.stop();
try
{
@@ -215,11 +219,11 @@
uninstall(bundle);
}
}
-
+
public void testGetWrongInterfacesForServiceFactory() throws Exception
{
- String[] OBJCLASSES = {String.class.getName(), BundleContext.class.getName()};
-
+ String[] OBJCLASSES = { String.class.getName(), BundleContext.class.getName() };
+
Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
try
{
@@ -228,19 +232,19 @@
assertNotNull(bundleContext);
bundleContext.addFrameworkListener(this);
-
- ServiceRegistration registration = bundleContext.registerService(String.class.getName(), new SimpleServiceFactory(bundleContext), null);
+
+ ServiceRegistration registration = bundleContext.registerService(String.class.getName(), new SimpleServiceFactory(), null);
ServiceReference reference = registration.getReference();
Object actual = bundleContext.getService(reference);
assertNull("" + actual, actual);
-
+
assertFrameworkEvent(FrameworkEvent.ERROR, bundle, IllegalArgumentException.class);
-
- registration = bundleContext.registerService(OBJCLASSES, new SimpleServiceFactory(bundleContext), null);
+
+ registration = bundleContext.registerService(OBJCLASSES, new SimpleServiceFactory(), null);
reference = registration.getReference();
actual = bundleContext.getService(reference);
assertNull("" + actual, actual);
-
+
assertFrameworkEvent(FrameworkEvent.ERROR, bundle, IllegalArgumentException.class);
}
finally
@@ -248,7 +252,7 @@
uninstall(bundle);
}
}
-
+
public void testErrorInGetService() throws Exception
{
Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
@@ -259,12 +263,12 @@
assertNotNull(bundleContext);
bundleContext.addFrameworkListener(this);
-
+
ServiceRegistration registration = bundleContext.registerService(BundleContext.class.getName(), new BrokenServiceFactory(bundleContext, true), null);
ServiceReference reference = registration.getReference();
Object actual = bundleContext.getService(reference);
assertNull("" + actual, actual);
-
+
assertFrameworkEvent(FrameworkEvent.ERROR, bundle, RuntimeException.class);
}
finally
@@ -272,7 +276,7 @@
uninstall(bundle);
}
}
-
+
public void testErrorInUnGetService() throws Exception
{
Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
@@ -283,7 +287,7 @@
assertNotNull(bundleContext);
bundleContext.addFrameworkListener(this);
-
+
ServiceRegistration registration = bundleContext.registerService(BundleContext.class.getName(), new BrokenServiceFactory(bundleContext, false), null);
ServiceReference reference = registration.getReference();
Object actual = bundleContext.getService(reference);
@@ -291,7 +295,7 @@
assertNoFrameworkEvent();
registration.unregister();
-
+
assertFrameworkEvent(FrameworkEvent.WARNING, bundle, RuntimeException.class);
}
finally
Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/java/org/jboss/test/osgi/service/test/RegisterServiceUnitTestCase.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/java/org/jboss/test/osgi/service/test/RegisterServiceUnitTestCase.java 2009-08-29 02:30:18 UTC (rev 92987)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/java/org/jboss/test/osgi/service/test/RegisterServiceUnitTestCase.java 2009-08-29 12:15:32 UTC (rev 92988)
@@ -27,10 +27,12 @@
import junit.framework.Test;
import org.jboss.test.osgi.OSGiTestCase;
+import org.jboss.test.osgi.service.support.SimpleService;
import org.jboss.test.osgi.service.support.SimpleServiceFactory;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceFactory;
import org.osgi.framework.ServiceReference;
import org.osgi.framework.ServiceRegistration;
@@ -248,26 +250,25 @@
public void testRegisterServiceFactory() throws Exception
{
- Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ Bundle bundleA = assembleBundle("bundleA", "/bundles/simple/simple-bundle1", SimpleService.class);
+
try
{
- bundle.start();
- BundleContext bundleContext = bundle.getBundleContext();
- assertNotNull(bundleContext);
+ bundleA.start();
+ BundleContext contextA = bundleA.getBundleContext();
+ assertNotNull(contextA);
- ServiceRegistration registration = bundleContext.registerService(OBJCLASS, new SimpleServiceFactory(bundleContext), null);
- ServiceReference reference = registration.getReference();
- Object actual = bundleContext.getService(reference);
- assertEquals(bundleContext, actual);
+ ServiceFactory serviceFactory = createServiceFactory(bundleA);
+ ServiceRegistration sreg = contextA.registerService(SimpleService.class.getName(), serviceFactory, null);
+ ServiceReference sref = sreg.getReference();
+ Object service = contextA.getService(sref);
+ assertServiceInstanceOf(SimpleService.class, service);
+ assertEquals(bundleA.getSymbolicName(), callServiceMethod(service, "getSymbolicName"));
- registration = bundleContext.registerService(OBJCLASSES, new SimpleServiceFactory(bundleContext), null);
- reference = registration.getReference();
- actual = bundleContext.getService(reference);
- assertEquals(bundleContext, actual);
}
finally
{
- uninstall(bundle);
+ uninstall(bundleA);
}
}
}
Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/java/org/jboss/test/osgi/service/test/ServiceRegistrationUnitTestCase.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/java/org/jboss/test/osgi/service/test/ServiceRegistrationUnitTestCase.java 2009-08-29 02:30:18 UTC (rev 92987)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/java/org/jboss/test/osgi/service/test/ServiceRegistrationUnitTestCase.java 2009-08-29 12:15:32 UTC (rev 92988)
@@ -26,11 +26,12 @@
import junit.framework.Test;
import org.jboss.test.osgi.OSGiTestCase;
-import org.jboss.test.osgi.service.support.SimpleServiceFactory;
+import org.jboss.test.osgi.service.support.SimpleService;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
import org.osgi.framework.ServiceEvent;
+import org.osgi.framework.ServiceFactory;
import org.osgi.framework.ServiceReference;
import org.osgi.framework.ServiceRegistration;
@@ -252,21 +253,21 @@
public void testUnregister() throws Exception
{
- Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ Bundle bundle = assembleBundle("bundleA", "/bundles/simple/simple-bundle1", SimpleService.class);
try
{
bundle.start();
BundleContext bundleContext = bundle.getBundleContext();
assertNotNull(bundleContext);
- SimpleServiceFactory factory = new SimpleServiceFactory(bundleContext);
- ServiceRegistration registration = bundleContext.registerService(BundleContext.class.getName(), factory, null);
+ ServiceFactory serviceFactory = createServiceFactory(bundle);
+ ServiceRegistration registration = bundleContext.registerService(SimpleService.class.getName(), serviceFactory, null);
assertNotNull(registration);
ServiceReference reference = registration.getReference();
assertNotNull(reference);
- ServiceReference reference2 = bundleContext.getServiceReference(BundleContext.class.getName());
+ ServiceReference reference2 = bundleContext.getServiceReference(SimpleService.class.getName());
assertEquals(reference, reference2);
ServiceReference[] inUse = bundle.getServicesInUse();
@@ -286,10 +287,6 @@
inUse = bundle2.getServicesInUse();
assertEquals(new ServiceReference[] { reference }, inUse);
- assertNull(factory.ungetBundle);
- assertNull(factory.ungetRegisation);
- assertNull(factory.ungetService);
-
bundleContext.addServiceListener(this);
registration.unregister();
@@ -305,10 +302,6 @@
assertNull(inUse);
inUse = bundle2.getServicesInUse();
assertNull(inUse);
-
- assertEquals(bundle, factory.ungetBundle);
- assertEquals(registration, factory.ungetRegisation);
- assertEquals(bundleContext, factory.ungetService);
}
finally
{
More information about the jboss-cvs-commits
mailing list