[jboss-osgi-commits] JBoss-OSGI SVN: r92991 - in projects/jboss-osgi/projects/runtime/microcontainer/trunk/src: test/java/org/jboss/test/osgi and 2 other directories.

jboss-osgi-commits at lists.jboss.org jboss-osgi-commits at lists.jboss.org
Sat Aug 29 16:09:23 EDT 2009


Author: thomas.diesler at jboss.com
Date: 2009-08-29 16:09:23 -0400 (Sat, 29 Aug 2009)
New Revision: 92991

Removed:
   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/SimpleServiceImpl.java
Modified:
   projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleManager.java
   projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiServiceState.java
   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/support/SimpleServiceFactory.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:
[JBOSGI-144] Framework does not handle ServiceFactory provided services properly


Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleManager.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleManager.java	2009-08-29 17:28:02 UTC (rev 92990)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleManager.java	2009-08-29 20:09:23 UTC (rev 92991)
@@ -781,7 +781,7 @@
    {
       OSGiServiceReferenceWrapper serviceReference = (OSGiServiceReferenceWrapper)reference;
       OSGiServiceState serviceState = serviceReference.getServiceState();
-      Object result = serviceState.getService();
+      Object result = serviceState.getService(bundleState);
       if (result != null)
          bundleState.addServiceInUse(serviceState);
       return result;

Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiServiceState.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiServiceState.java	2009-08-29 17:28:02 UTC (rev 92990)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiServiceState.java	2009-08-29 20:09:23 UTC (rev 92991)
@@ -161,13 +161,15 @@
    /**
     * Get the service.
     * 
+    * @param bundleState the bundle that requested the service
     * @return the service.
     */
-   public Object getService()
+   public Object getService(AbstractBundleState bundleState)
    {
       // [TODO] fix race condition with unregistration
       if (isUnregistered())
          return null;
+      
       checkPermission("get", false);
 
       if (service != null)
@@ -177,7 +179,7 @@
       {
          try
          {
-            service = checkObjClass(serviceFactory.getService(getBundle(), getRegistration()));
+            service = checkObjClass(serviceFactory.getService(bundleState.getBundle(), getRegistration()));
          }
          catch (Throwable t)
          {

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 17:28:02 UTC (rev 92990)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/java/org/jboss/test/osgi/OSGiTestCase.java	2009-08-29 20:09:23 UTC (rev 92991)
@@ -21,7 +21,6 @@
 */
 package org.jboss.test.osgi;
 
-import java.lang.reflect.Method;
 import java.net.URL;
 import java.util.Arrays;
 import java.util.Collection;
@@ -38,7 +37,6 @@
 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;
@@ -49,7 +47,6 @@
 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;
@@ -512,29 +509,4 @@
       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);
-   }
 }

Deleted: 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	2009-08-29 17:28:02 UTC (rev 92990)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/java/org/jboss/test/osgi/service/support/SimpleService.java	2009-08-29 20:09:23 UTC (rev 92991)
@@ -1,35 +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;
-
-
-/**
- * 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();
-}

Modified: 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 17:28:02 UTC (rev 92990)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/java/org/jboss/test/osgi/service/support/SimpleServiceFactory.java	2009-08-29 20:09:23 UTC (rev 92991)
@@ -33,12 +33,34 @@
  */
 public class SimpleServiceFactory implements ServiceFactory
 {
+   public Object service;
+   
+   public Bundle getBundle;
+   public int getCount;
+   
+   public Bundle ungetBundle;
+   public ServiceRegistration ungetRegisation;
+   public Object ungetService;
+   public int ungetCount;
+   
+   public SimpleServiceFactory(Object service)
+   {
+      this.service = service;
+   }
+
    public Object getService(Bundle bundle, ServiceRegistration registration)
    {
-      return new SimpleServiceImpl(bundle);
+      getBundle = bundle;
+      getCount++;
+      return service;
    }
 
    public void ungetService(Bundle bundle, ServiceRegistration registration, Object service)
    {
+      ungetBundle = bundle;
+      ungetRegisation = registration;
+      ungetService = service;
+      ungetCount++;
    }
+
 }

Deleted: 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	2009-08-29 17:28:02 UTC (rev 92990)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/java/org/jboss/test/osgi/service/support/SimpleServiceImpl.java	2009-08-29 20:09:23 UTC (rev 92991)
@@ -1,46 +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;
-
-/**
- * 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();
-   }
-}

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 17:28:02 UTC (rev 92990)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/java/org/jboss/test/osgi/service/test/GetUnGetServiceUnitTestCase.java	2009-08-29 20:09:23 UTC (rev 92991)
@@ -21,17 +21,14 @@
 */
 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;
 
@@ -54,11 +51,11 @@
    {
       return suite(GetUnGetServiceUnitTestCase.class);
    }
-
+   
    public void testGetUnServiceErrors() throws Exception
    {
       String OBJCLASS = BundleContext.class.getName();
-
+      
       Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
       try
       {
@@ -67,7 +64,7 @@
          assertNotNull(bundleContext);
 
          bundleContext.registerService(OBJCLASS, bundleContext, null);
-
+         
          try
          {
             bundleContext.getService(null);
@@ -77,7 +74,7 @@
          {
             checkThrowable(IllegalArgumentException.class, t);
          }
-
+         
          try
          {
             bundleContext.ungetService(null);
@@ -93,11 +90,11 @@
          uninstall(bundle);
       }
    }
-
+   
    public void testGetService() throws Exception
    {
       String OBJCLASS = BundleContext.class.getName();
-
+      
       Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
       try
       {
@@ -110,7 +107,7 @@
 
          Object actual = bundleContext.getService(reference);
          assertEquals(bundleContext, actual);
-
+         
          registration.unregister();
          actual = bundleContext.getService(reference);
          assertNull("" + actual, actual);
@@ -120,11 +117,11 @@
          uninstall(bundle);
       }
    }
-
+   
    public void testGetServiceAfterStop() throws Exception
    {
       String OBJCLASS = BundleContext.class.getName();
-
+      
       Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
       try
       {
@@ -137,7 +134,7 @@
 
          Object actual = bundleContext.getService(reference);
          assertEquals(bundleContext, actual);
-
+         
          bundle.stop();
          try
          {
@@ -154,55 +151,54 @@
          uninstall(bundle);
       }
    }
-
+   
    public void testGetServiceFactory() throws Exception
    {
-      Bundle bundle = assembleBundle("bundle", "/bundles/simple/simple-bundle1", SimpleService.class);
-
+      String OBJCLASS = BundleContext.class.getName();
+      
+      Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
       try
       {
          bundle.start();
          BundleContext bundleContext = bundle.getBundleContext();
          assertNotNull(bundleContext);
 
-         ServiceFactory serviceFactory = createServiceFactory(bundle);
-         ServiceRegistration registration = bundleContext.registerService(SimpleService.class.getName(), serviceFactory, null);
+         ServiceRegistration registration = bundleContext.registerService(OBJCLASS, new SimpleServiceFactory(bundleContext), null);
          ServiceReference reference = registration.getReference();
 
-         Object actualFirst = bundleContext.getService(reference);
-         assertServiceInstanceOf(SimpleService.class, actualFirst);
-         assertEquals(bundle.getSymbolicName(), callServiceMethod(actualFirst, "getSymbolicName"));
+         Object actual = bundleContext.getService(reference);
+         assertEquals(bundleContext, actual);
 
-         Object actualSecond = bundleContext.getService(reference);
-         assertSame(actualFirst, actualSecond);
-
+         actual = bundleContext.getService(reference);
+         assertEquals(bundleContext, actual);
+         
          registration.unregister();
-         Object actualThird = bundleContext.getService(reference);
-         assertNull("" + actualThird, actualThird);
+         actual = bundleContext.getService(reference);
+         assertNull("" + actual, actual);
       }
       finally
       {
          uninstall(bundle);
       }
    }
-
+   
    public void testGetServiceFactoryAfterStop() throws Exception
    {
-      Bundle bundle = assembleBundle("bundle", "/bundles/simple/simple-bundle1", SimpleService.class);
+      String OBJCLASS = BundleContext.class.getName();
+      
+      Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
       try
       {
          bundle.start();
          BundleContext bundleContext = bundle.getBundleContext();
          assertNotNull(bundleContext);
 
-         ServiceFactory serviceFactory = createServiceFactory(bundle);
-         ServiceRegistration registration = bundleContext.registerService(SimpleService.class.getName(), serviceFactory, null);
+         ServiceRegistration registration = bundleContext.registerService(OBJCLASS, new SimpleServiceFactory(bundleContext), null);
          ServiceReference reference = registration.getReference();
 
          Object actual = bundleContext.getService(reference);
-         assertServiceInstanceOf(SimpleService.class, actual);
-         assertEquals(bundle.getSymbolicName(), callServiceMethod(actual, "getSymbolicName"));
-
+         assertEquals(bundleContext, actual);
+         
          bundle.stop();
          try
          {
@@ -219,11 +215,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
       {
@@ -232,19 +228,19 @@
          assertNotNull(bundleContext);
 
          bundleContext.addFrameworkListener(this);
-
-         ServiceRegistration registration = bundleContext.registerService(String.class.getName(), new SimpleServiceFactory(), null);
+         
+         ServiceRegistration registration = bundleContext.registerService(String.class.getName(), new SimpleServiceFactory(bundleContext), 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(), null);
+         
+         registration = bundleContext.registerService(OBJCLASSES, new SimpleServiceFactory(bundleContext), null);
          reference = registration.getReference();
          actual = bundleContext.getService(reference);
          assertNull("" + actual, actual);
-
+         
          assertFrameworkEvent(FrameworkEvent.ERROR, bundle, IllegalArgumentException.class);
       }
       finally
@@ -252,7 +248,7 @@
          uninstall(bundle);
       }
    }
-
+   
    public void testErrorInGetService() throws Exception
    {
       Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
@@ -263,12 +259,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
@@ -276,7 +272,7 @@
          uninstall(bundle);
       }
    }
-
+   
    public void testErrorInUnGetService() throws Exception
    {
       Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
@@ -287,7 +283,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);
@@ -295,7 +291,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 17:28:02 UTC (rev 92990)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/java/org/jboss/test/osgi/service/test/RegisterServiceUnitTestCase.java	2009-08-29 20:09:23 UTC (rev 92991)
@@ -26,13 +26,12 @@
 
 import junit.framework.Test;
 
+import org.jboss.osgi.plugins.facade.bundle.OSGiBundleWrapper;
 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;
 
@@ -250,21 +249,60 @@
    
    public void testRegisterServiceFactory() throws Exception
    {
-      Bundle bundleA = assembleBundle("bundleA", "/bundles/simple/simple-bundle1", SimpleService.class);
-      
+      Bundle bundleA = addBundle("/bundles/simple/", "simple-bundle1");
       try
       {
          bundleA.start();
          BundleContext contextA = bundleA.getBundleContext();
          assertNotNull(contextA);
 
-         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"));
+         SimpleServiceFactory serviceFactory = new SimpleServiceFactory(contextA);
+         ServiceRegistration sregA = contextA.registerService(OBJCLASS, serviceFactory, null);
+         
+         ServiceReference srefA = sregA.getReference();
+         Object actual = contextA.getService(srefA);
+         assertEquals(contextA, actual);
+         assertInstanceOf(serviceFactory.getBundle, OSGiBundleWrapper.class);
+         assertEquals(bundleA.getSymbolicName(), serviceFactory.getBundle.getSymbolicName());
+         assertEquals(1, serviceFactory.getCount);
+         
+         srefA = contextA.getServiceReference(OBJCLASS);
+         actual = contextA.getService(srefA);
+         assertEquals(contextA, actual);
+         assertInstanceOf(serviceFactory.getBundle, OSGiBundleWrapper.class);
+         assertEquals(bundleA.getSymbolicName(), serviceFactory.getBundle.getSymbolicName());
+         assertEquals(1, serviceFactory.getCount);
 
+         sregA = contextA.registerService(OBJCLASSES, serviceFactory, null);
+         srefA = sregA.getReference();
+         actual = contextA.getService(srefA);
+         assertEquals(contextA, actual);
+         assertInstanceOf(serviceFactory.getBundle, OSGiBundleWrapper.class);
+         assertEquals(bundleA.getSymbolicName(), serviceFactory.getBundle.getSymbolicName());
+         
+         System.out.println("[JBOSGI-144] Framework does not handle ServiceFactory provided services properly");
+         //assertEquals(1, serviceFactory.getCount);
+         
+         Bundle bundleB = addBundle("/bundles/simple/", "simple-bundle2");
+         try
+         {
+            bundleB.start();
+            BundleContext contextB = bundleB.getBundleContext();
+            assertNotNull(contextB);
+
+            ServiceReference srefB = contextB.getServiceReference(OBJCLASS);
+            actual = contextB.getService(srefB);
+            assertEquals(contextA, actual);
+            assertInstanceOf(serviceFactory.getBundle, OSGiBundleWrapper.class);
+            
+            System.out.println("[JBOSGI-144] Framework does not handle ServiceFactory provided services properly");
+            //assertEquals(bundleB.getSymbolicName(), serviceFactory.getBundle.getSymbolicName());
+            //assertEquals(2, serviceFactory.getCount);
+         }
+         finally
+         {
+            uninstall(bundleB);
+         }
       }
       finally
       {

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 17:28:02 UTC (rev 92990)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/java/org/jboss/test/osgi/service/test/ServiceRegistrationUnitTestCase.java	2009-08-29 20:09:23 UTC (rev 92991)
@@ -26,12 +26,11 @@
 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.ServiceEvent;
-import org.osgi.framework.ServiceFactory;
 import org.osgi.framework.ServiceReference;
 import org.osgi.framework.ServiceRegistration;
 
@@ -253,21 +252,21 @@
    
    public void testUnregister() throws Exception
    {
-      Bundle bundle = assembleBundle("bundleA", "/bundles/simple/simple-bundle1", SimpleService.class);
+      Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
       try
       {
          bundle.start();
          BundleContext bundleContext = bundle.getBundleContext();
          assertNotNull(bundleContext);
 
-         ServiceFactory serviceFactory = createServiceFactory(bundle);
-         ServiceRegistration registration = bundleContext.registerService(SimpleService.class.getName(), serviceFactory, null);
+         SimpleServiceFactory factory = new SimpleServiceFactory(bundleContext);
+         ServiceRegistration registration = bundleContext.registerService(BundleContext.class.getName(), factory, null);
          assertNotNull(registration);
          
          ServiceReference reference = registration.getReference();
          assertNotNull(reference);
 
-         ServiceReference reference2 = bundleContext.getServiceReference(SimpleService.class.getName());
+         ServiceReference reference2 = bundleContext.getServiceReference(BundleContext.class.getName());
          assertEquals(reference, reference2);
 
          ServiceReference[] inUse = bundle.getServicesInUse();
@@ -287,6 +286,10 @@
             inUse = bundle2.getServicesInUse();
             assertEquals(new ServiceReference[] { reference }, inUse);
 
+            assertNull(factory.ungetBundle);
+            assertNull(factory.ungetRegisation);
+            assertNull(factory.ungetService);
+            
             bundleContext.addServiceListener(this);
             registration.unregister();
 
@@ -302,6 +305,10 @@
             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-osgi-commits mailing list