[jboss-osgi-commits] JBoss-OSGI SVN: r97297 - in projects/jboss-osgi/trunk/reactor/framework/src: main/java/org/jboss/osgi/framework/bundle and 8 other directories.

jboss-osgi-commits at lists.jboss.org jboss-osgi-commits at lists.jboss.org
Wed Dec 2 10:38:02 EST 2009


Author: alesj
Date: 2009-12-02 10:38:01 -0500 (Wed, 02 Dec 2009)
New Revision: 97297

Added:
   projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/deployers/AbstractOSGiBundleStateDeployer.java
   projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/deployers/OSGiBundleStateAddDeployer.java
   projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/deployers/OSGiBundleStateRemoveDeployer.java
   projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/support/LazyBundle.java
   projects/jboss-osgi/trunk/reactor/framework/src/test/resources/bundles/service/service-bundle4/
   projects/jboss-osgi/trunk/reactor/framework/src/test/resources/bundles/service/service-bundle4/META-INF/
   projects/jboss-osgi/trunk/reactor/framework/src/test/resources/bundles/service/service-bundle4/META-INF/MANIFEST.MF
Removed:
   projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/deployers/OSGiBundleStateDeployer.java
Modified:
   projects/jboss-osgi/trunk/reactor/framework/src/etc/osgitck/jboss-osgi-bootstrap.xml
   projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java
   projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/DeployersTest.java
   projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/DeployersTestDelegate.java
   projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/FrameworkTest.java
   projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/ServiceMixUnitTestCase.java
   projects/jboss-osgi/trunk/reactor/framework/src/test/resources/bootstrap/jboss-osgi-bootstrap.xml
Log:
More service-mix tests.

Modified: projects/jboss-osgi/trunk/reactor/framework/src/etc/osgitck/jboss-osgi-bootstrap.xml
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/etc/osgitck/jboss-osgi-bootstrap.xml	2009-12-02 14:57:34 UTC (rev 97296)
+++ projects/jboss-osgi/trunk/reactor/framework/src/etc/osgitck/jboss-osgi-bootstrap.xml	2009-12-02 15:38:01 UTC (rev 97297)
@@ -136,9 +136,12 @@
 
   <!-- OSGI Deployment -->
   <bean name="OSGiManifestParsingDeployer" class="org.jboss.osgi.framework.deployers.OSGiManifestParsingDeployer" />
-  <bean name="OSGiBundleStateDeployer" class="org.jboss.osgi.framework.deployers.OSGiBundleStateDeployer">
+  <bean name="OSGiBundleStateAddDeployer" class="org.jboss.osgi.framework.deployers.OSGiBundleStateAddDeployer">
     <constructor><parameter><inject bean="OSGiBundleManager" /></parameter></constructor>
   </bean>
+  <bean name="OSGiBundleStateRemoveDeployer" class="org.jboss.osgi.framework.deployers.OSGiBundleStateRemoveDeployer">
+    <constructor><parameter><inject bean="OSGiBundleManager" /></parameter></constructor>
+  </bean>
   <bean name="OSGiBundleActivatorDeployer" class="org.jboss.osgi.framework.deployers.OSGiBundleActivatorDeployer" />
   <bean name="OSGiContextTrackerDeployer" class="org.jboss.osgi.framework.deployers.OSGiContextTrackerDeployer" />
 

Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java	2009-12-02 14:57:34 UTC (rev 97296)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java	2009-12-02 15:38:01 UTC (rev 97297)
@@ -151,7 +151,7 @@
    private MainDeployerStructure deployerStructure;
 
    /** The deployment registry */
-   private DeploymentRegistry registry;
+   private final DeploymentRegistry registry;
 
    /** The instance metadata factory */
    private MetaDataRetrievalFactory factory;
@@ -366,14 +366,17 @@
       DeploymentUnit unit = registry.getDeployment(context);
       if (unit != null)
       {
-         OSGiBundleState bundleState = unit.getAttachment(OSGiBundleState.class);
-         if (bundleState == null)
+         synchronized (registry)
          {
-            bundleState = addDeployment(unit);
-            bundleState.changeState(Bundle.ACTIVE);
-            unit.addAttachment(OSGiBundleState.class, bundleState);
+            OSGiBundleState bundleState = unit.getAttachment(OSGiBundleState.class);
+            if (bundleState == null)
+            {
+               bundleState = addDeployment(unit);
+               bundleState.changeState(Bundle.ACTIVE);
+               unit.addAttachment(OSGiBundleState.class, bundleState);
+            }
+            return bundleState;
          }
-         return bundleState;
       }
 
       return systemBundle;

Added: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/deployers/AbstractOSGiBundleStateDeployer.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/deployers/AbstractOSGiBundleStateDeployer.java	                        (rev 0)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/deployers/AbstractOSGiBundleStateDeployer.java	2009-12-02 15:38:01 UTC (rev 97297)
@@ -0,0 +1,65 @@
+/*
+* 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.osgi.framework.deployers;
+
+import org.jboss.deployers.spi.deployer.DeploymentStages;
+import org.jboss.deployers.spi.deployer.helpers.AbstractRealDeployer;
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.osgi.framework.bundle.OSGiBundleManager;
+import org.jboss.osgi.framework.bundle.OSGiBundleState;
+import org.jboss.osgi.framework.metadata.OSGiMetaData;
+
+/**
+ * AbstractOSGiBundleStateDeployer.<p>
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @author <a href="ales.justin at jboss.org">Ales Justin</a>
+ */
+public abstract class AbstractOSGiBundleStateDeployer extends AbstractRealDeployer
+{
+   /** The bundle manager */
+   protected OSGiBundleManager bundleManager;
+
+   /**
+    * Create a new BundleStateDeployer.
+    *
+    * @param bundleManager the bundleManager
+    * @throws IllegalArgumentException for a null bundle manager
+    */
+   protected AbstractOSGiBundleStateDeployer(OSGiBundleManager bundleManager)
+   {
+      if (bundleManager == null)
+         throw new IllegalArgumentException("Null bundle manager");
+
+      setOutput(OSGiBundleState.class);
+      setStage(DeploymentStages.POST_PARSE);
+      setTopLevelOnly(true);
+
+      this.bundleManager = bundleManager;
+   }
+
+   protected void internalDeploy(DeploymentUnit unit) throws DeploymentException
+   {
+      // do nothing
+   }
+}
\ No newline at end of file

Copied: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/deployers/OSGiBundleStateAddDeployer.java (from rev 97282, projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/deployers/OSGiBundleStateDeployer.java)
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/deployers/OSGiBundleStateAddDeployer.java	                        (rev 0)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/deployers/OSGiBundleStateAddDeployer.java	2009-12-02 15:38:01 UTC (rev 97297)
@@ -0,0 +1,81 @@
+/*
+* 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.osgi.framework.deployers;
+
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.deployer.DeploymentStage;
+import org.jboss.deployers.spi.deployer.DeploymentStages;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.osgi.framework.bundle.OSGiBundleManager;
+import org.jboss.osgi.framework.bundle.OSGiBundleState;
+import org.jboss.osgi.framework.metadata.OSGiMetaData;
+
+/**
+ * OSGiBundleStateDeployer.<p>
+ * 
+ * This deployer creates a bundle state object for all top level deployments
+ * regardless of whether they are OSGi deployments or not. TODO - this is not true!
+ *
+ * Note: undeploy/remove part is in a separate deployer.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @author <a href="ales.justin at jboss.org">Ales Justin</a>
+ * @version $Revision: 1.1 $
+ */
+public class OSGiBundleStateAddDeployer extends AbstractOSGiBundleStateDeployer
+{
+   /** The required stage */
+   private DeploymentStage requiredStage;
+   
+   /**
+    * Create a new BundleStateDeployer.
+    * 
+    * @param bundleManager the bundleManager
+    * @throws IllegalArgumentException for a null bundle manager
+    */
+   public OSGiBundleStateAddDeployer(OSGiBundleManager bundleManager)
+   {
+      super(bundleManager);
+      setInput(OSGiMetaData.class);
+      this.requiredStage = DeploymentStages.DESCRIBE;
+   }
+
+   @Override
+   protected void internalDeploy(DeploymentUnit unit) throws DeploymentException
+   {
+      // [TODO] look at manifest headers and persistent state for this
+      unit.setRequiredStage(requiredStage);
+      
+      OSGiBundleState bundleState = bundleManager.addDeployment(unit);
+      unit.addAttachment(OSGiBundleState.class, bundleState);
+   }
+
+   /**
+    * Set required stage.
+    *
+    * @param stage the required stage
+    */
+   public void setRequiredStage(String stage)
+   {
+      requiredStage = new DeploymentStage(stage);
+   }
+}

Deleted: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/deployers/OSGiBundleStateDeployer.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/deployers/OSGiBundleStateDeployer.java	2009-12-02 14:57:34 UTC (rev 97296)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/deployers/OSGiBundleStateDeployer.java	2009-12-02 15:38:01 UTC (rev 97297)
@@ -1,90 +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.osgi.framework.deployers;
-
-import org.jboss.deployers.spi.DeploymentException;
-import org.jboss.deployers.spi.deployer.DeploymentStage;
-import org.jboss.deployers.spi.deployer.DeploymentStages;
-import org.jboss.deployers.spi.deployer.helpers.AbstractRealDeployer;
-import org.jboss.deployers.structure.spi.DeploymentUnit;
-import org.jboss.osgi.framework.bundle.OSGiBundleManager;
-import org.jboss.osgi.framework.bundle.OSGiBundleState;
-import org.jboss.osgi.framework.metadata.OSGiMetaData;
-
-/**
- * OSGiBundleStateDeployer.<p>
- * 
- * This deployer creates a bundle state object for all top level deployments
- * regardless of whether they are OSGi deployments or not.
- * 
- * @author <a href="adrian at jboss.com">Adrian Brock</a>
- * @version $Revision: 1.1 $
- */
-public class OSGiBundleStateDeployer extends AbstractRealDeployer
-{
-   /** The bundle manager */
-   private OSGiBundleManager bundleManager;
-   private DeploymentStage requiredStage;
-   
-   /**
-    * Create a new BundleStateDeployer.
-    * 
-    * @param bundleManager the bundleManager
-    * @throws IllegalArgumentException for a null bundle manager
-    */
-   public OSGiBundleStateDeployer(OSGiBundleManager bundleManager)
-   {
-      if (bundleManager == null)
-         throw new IllegalArgumentException("Null bundle manager");
-      
-      this.bundleManager = bundleManager;
-      this.requiredStage = DeploymentStages.DESCRIBE;
-
-      setInput(OSGiMetaData.class);
-      setOutput(OSGiBundleState.class);
-      setStage(DeploymentStages.POST_PARSE);
-      setTopLevelOnly(true);
-   }
-   
-   public void setRequiredStage(String stage)
-   {
-      requiredStage = new DeploymentStage(stage);
-   }
-
-   @Override
-   protected void internalDeploy(DeploymentUnit unit) throws DeploymentException
-   {
-      // [TODO] look at manifest headers and persistent state for this
-      unit.setRequiredStage(requiredStage);
-      
-      OSGiBundleState bundleState = bundleManager.addDeployment(unit);
-      unit.addAttachment(OSGiBundleState.class, bundleState);
-   }
-
-   @Override
-   protected void internalUndeploy(DeploymentUnit unit)
-   {
-      OSGiBundleState bundleState = unit.getAttachment(OSGiBundleState.class);
-      if (bundleState != null)
-         bundleManager.removeBundle(bundleState);
-   }
-}

Copied: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/deployers/OSGiBundleStateRemoveDeployer.java (from rev 97282, projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/deployers/OSGiBundleStateDeployer.java)
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/deployers/OSGiBundleStateRemoveDeployer.java	                        (rev 0)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/deployers/OSGiBundleStateRemoveDeployer.java	2009-12-02 15:38:01 UTC (rev 97297)
@@ -0,0 +1,57 @@
+/*
+* 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.osgi.framework.deployers;
+
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.osgi.framework.bundle.OSGiBundleManager;
+import org.jboss.osgi.framework.bundle.OSGiBundleState;
+import org.jboss.osgi.framework.metadata.OSGiMetaData;
+
+/**
+ * This deployer removes any osgi state bundle from manager.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @author <a href="ales.justin at jboss.org">Ales Justin</a>
+ */
+public class OSGiBundleStateRemoveDeployer extends AbstractOSGiBundleStateDeployer
+{
+   /**
+    * Create a new BundleStateDeployer.
+    *
+    * @param bundleManager the bundleManager
+    * @throws IllegalArgumentException for a null bundle manager
+    */
+   public OSGiBundleStateRemoveDeployer(OSGiBundleManager bundleManager)
+   {
+      super(bundleManager);
+      addInput(OSGiMetaData.class);
+   }
+
+   @Override
+   protected void internalUndeploy(DeploymentUnit unit)
+   {
+      OSGiBundleState bundleState = unit.getAttachment(OSGiBundleState.class);
+      if (bundleState != null)
+         bundleManager.removeBundle(bundleState);
+   }
+}
\ No newline at end of file

Modified: projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/DeployersTest.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/DeployersTest.java	2009-12-02 14:57:34 UTC (rev 97296)
+++ projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/DeployersTest.java	2009-12-02 15:38:01 UTC (rev 97297)
@@ -52,6 +52,21 @@
       return (DeployersTestDelegate)super.getDelegate();
    }
 
+   protected void checkComplete() throws Exception
+   {
+      getDelegate().checkComplete();
+   }
+
+   protected Deployment addDeployment(VirtualFile file) throws Exception
+   {
+      return getDelegate().addDeployment(file);
+   }
+
+   protected <T> Deployment addDeployment(VirtualFile file, T metadata, Class<T> expectedType) throws Exception
+   {
+      return getDelegate().addDeployment(file, metadata, expectedType);
+   }
+
    protected Deployment assertDeploy(VirtualFile file) throws Exception
    {
       return getDelegate().assertDeploy(file);
@@ -72,14 +87,50 @@
       getDelegate().undeploy(deployment);
    }
 
-   protected Deployment assertBean(String name, Class<?> beanClass) throws Exception
+   protected Deployment addBean(String name, Class<?> beanClass, Class<?> ... references) throws Exception
    {
+      return addBean(name, beanClass, null, references);
+   }
+
+   protected Deployment addBean(String name, Class<?> beanClass, BeanMetaData bmd, Class<?> ... references) throws Exception
+   {
       AssembledDirectory dir = createAssembledDirectory(name, "");
       addPackage(dir, beanClass);
-      BeanMetaDataBuilder builder = BeanMetaDataBuilder.createBuilder(beanClass.getSimpleName(), beanClass.getName());
-      return assertDeploy(dir, builder.getBeanMetaData(), BeanMetaData.class);
+      if (references != null)
+      {
+         for (Class<?> reference : references)
+            addPackage(dir, reference);
+      }
+      if (bmd == null)
+      {
+         BeanMetaDataBuilder builder = BeanMetaDataBuilder.createBuilder(beanClass.getSimpleName(), beanClass.getName());
+         bmd = builder.getBeanMetaData();
+      }
+      return addDeployment(dir, bmd, BeanMetaData.class);
    }
 
+   protected Deployment deployBean(String name, Class<?> beanClass, Class<?> ... references) throws Exception
+   {
+      return deployBean(name, beanClass, null, references);
+   }
+
+   protected Deployment deployBean(String name, Class<?> beanClass, BeanMetaData bmd, Class<?> ... references) throws Exception
+   {
+      AssembledDirectory dir = createAssembledDirectory(name, "");
+      addPackage(dir, beanClass);
+      if (references != null)
+      {
+         for (Class<?> reference : references)
+            addPackage(dir, reference);
+      }
+      if (bmd == null)
+      {
+         BeanMetaDataBuilder builder = BeanMetaDataBuilder.createBuilder(beanClass.getSimpleName(), beanClass.getName());
+         bmd = builder.getBeanMetaData();
+      }
+      return assertDeploy(dir, bmd, BeanMetaData.class);
+   }
+
    protected Bundle getBundle(Deployment deployment) throws Exception
    {
       return getBundle(getDeploymentUnit(deployment));
@@ -89,6 +140,6 @@
    {
       OSGiBundleState bundle = unit.getAttachment(OSGiBundleState.class);
       assertNotNull(bundle);
-      return bundle;
+      return bundle.getBundleInternal();
    }
 }
\ No newline at end of file

Modified: projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/DeployersTestDelegate.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/DeployersTestDelegate.java	2009-12-02 14:57:34 UTC (rev 97296)
+++ projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/DeployersTestDelegate.java	2009-12-02 15:38:01 UTC (rev 97297)
@@ -39,6 +39,25 @@
       super(clazz);
    }
 
+   public void checkComplete() throws Exception
+   {
+      getDeployerClient().checkComplete();
+   }
+
+   public Deployment addDeployment(VirtualFile file) throws Exception
+   {
+      return addDeployment(file, null, null);
+   }
+
+   public <T> Deployment addDeployment(VirtualFile file, T metadata, Class<T> expectedType) throws Exception
+   {
+      Deployment deployment = createDeployment(file, metadata, expectedType);
+      DeployerClient deployerClient = getDeployerClient();
+      deployerClient.addDeployment(deployment);
+      deployerClient.process();
+      return deployment; 
+   }
+
    public Deployment assertDeploy(VirtualFile file) throws Exception
    {
       return assertDeploy(file, null, null);
@@ -49,7 +68,7 @@
       Deployment deployment = createDeployment(file, metadata, expectedType);
       DeployerClient deployerClient = getDeployerClient();
       deployerClient.deploy(deployment);
-      return deployment; 
+      return deployment;
    }
 
    public DeploymentUnit getDeploymentUnit(Deployment deployment) throws Exception

Modified: projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/FrameworkTest.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/FrameworkTest.java	2009-12-02 14:57:34 UTC (rev 97296)
+++ projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/FrameworkTest.java	2009-12-02 15:38:01 UTC (rev 97297)
@@ -413,17 +413,18 @@
 
    protected void assertUsingBundles(ServiceReference reference, Bundle... bundles)
    {
-      Set<Bundle> expected = new HashSet<Bundle>();
-      expected.addAll(Arrays.asList(bundles));
-
       Set<Bundle> actual = new HashSet<Bundle>();
       Bundle[] users = reference.getUsingBundles();
       if (users != null)
          actual.addAll(Arrays.asList(users));
 
+      Set<Bundle> expected = new HashSet<Bundle>();
+      expected.addAll(Arrays.asList(bundles));
+
       getLog().debug(reference + " users=" + actual);
 
-      assertEquals(expected, actual);
+      // switch - check expected on actual, since actual might be proxy
+      assertEquals(actual, expected);
    }
 
    protected void assertBundle(Bundle b1, Bundle b2)

Modified: projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/ServiceMixUnitTestCase.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/ServiceMixUnitTestCase.java	2009-12-02 14:57:34 UTC (rev 97296)
+++ projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/ServiceMixUnitTestCase.java	2009-12-02 15:38:01 UTC (rev 97297)
@@ -21,16 +21,23 @@
  */
 package org.jboss.test.osgi.service;
 
+import java.lang.reflect.Method;
+
 import junit.framework.Test;
 
+import org.jboss.beans.metadata.spi.BeanMetaData;
+import org.jboss.beans.metadata.spi.builder.BeanMetaDataBuilder;
+import org.jboss.dependency.spi.ControllerState;
 import org.jboss.deployers.client.spi.Deployment;
+import org.jboss.kernel.spi.dependency.KernelControllerContext;
 import org.jboss.test.osgi.DeployersTest;
 import org.jboss.test.osgi.service.support.a.A;
-import org.jboss.kernel.spi.dependency.KernelControllerContext;
-import org.jboss.dependency.spi.ControllerState;
+import org.jboss.test.osgi.service.support.c.C;
+import org.jboss.test.osgi.service.support.LazyBundle;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
 
 /**
  * Test MC's service mixture.
@@ -51,10 +58,10 @@
 
    public void testGetServiceReferenceFromMC() throws Throwable
    {
-      Deployment bean = assertBean("beanA", A.class);
+      Deployment bean = deployBean("beanA", A.class);
       try
       {
-         Bundle bundle1 = assembleBundle("simple1", "/bundles/service/service-bundle1", A.class);
+         Bundle bundle1 = assembleBundle("simple1", "/bundles/service/service-bundle1");
          try
          {
             bundle1.start();
@@ -70,6 +77,9 @@
 
                assertNotNull(bundleContext1.getService(ref1));
                assertUsingBundles(ref1, bundle1);
+
+               ServiceReference[] inUse = bundle1.getServicesInUse();
+               assertEquals(new ServiceReference[]{ref1}, inUse);
             }
             finally
             {
@@ -91,4 +101,61 @@
          undeploy(bean);
       }
    }
+
+   private static Object invoke(Object target, String getter) throws Throwable
+   {
+      Class<?> clazz = target.getClass();
+      Method m = clazz.getDeclaredMethod(getter);
+      return m.invoke(target);
+   }
+
+   public void testInjectionToMC() throws Throwable
+   {
+      BeanMetaDataBuilder builder = BeanMetaDataBuilder.createBuilder("C", C.class.getName());
+      builder.addPropertyMetaData("a", builder.createContextualInject());
+      BeanMetaData bmd = builder.getBeanMetaData();
+      Deployment bean = addBean("beanA", C.class, bmd, A.class);
+      try
+      {
+         Bundle bundle1 = assembleBundle("simple2", "/bundles/service/service-bundle3");
+         try
+         {
+            bundle1.start();
+            BundleContext bundleContext1 = bundle1.getBundleContext();
+            assertNotNull(bundleContext1);
+
+            Class<?> aClass = bundle1.loadClass(A.class.getName());
+            Object a = aClass.newInstance();
+            ServiceRegistration reg1 = bundleContext1.registerService(A.class.getName(), a, null);
+            assertNotNull(reg1);
+            try
+            {
+               checkComplete();
+
+               Object c = getBean("C");
+               assertSame(a, invoke(c, "getA"));
+
+               ServiceReference ref1 = bundleContext1.getServiceReference(A.class.getName());
+               assertUsingBundles(ref1, LazyBundle.getBundle(getDeploymentUnit(bean)));
+
+               KernelControllerContext kcc = getControllerContext("C");
+               change(kcc, ControllerState.DESCRIBED);
+               // we did un-injection, should be removed now
+               assertUsingBundles(ref1);
+            }
+            finally
+            {
+               reg1.unregister();
+            }
+         }
+         finally
+         {
+            uninstall(bundle1);
+         }
+      }
+      finally
+      {
+         undeploy(bean);
+      }
+   }
 }

Added: projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/support/LazyBundle.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/support/LazyBundle.java	                        (rev 0)
+++ projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/support/LazyBundle.java	2009-12-02 15:38:01 UTC (rev 97297)
@@ -0,0 +1,71 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.osgi.service.support;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.osgi.framework.bundle.OSGiBundleState;
+import org.osgi.framework.Bundle;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class LazyBundle
+{
+   public static Bundle getBundle(DeploymentUnit unit) throws Exception
+   {
+      return (Bundle)Proxy.newProxyInstance(Bundle.class.getClassLoader(),
+            new Class<?>[]{Bundle.class},
+            new LazyBundleHandler(unit));
+   }
+
+   private static class LazyBundleHandler implements InvocationHandler
+   {
+      private DeploymentUnit unit;
+      private Bundle bundle;
+
+      private LazyBundleHandler(DeploymentUnit unit)
+      {
+         this.unit = unit;
+      }
+
+      public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
+      {
+         return method.invoke(getBundle(), args);
+      }
+
+      private Bundle getBundle()
+      {
+         if (bundle == null)
+         {
+            OSGiBundleState bundle = unit.getAttachment(OSGiBundleState.class);
+            if (bundle == null)
+               throw new IllegalArgumentException("No such OSGiBundleState attachment: " + unit);
+            this.bundle = bundle.getBundleInternal();                        
+         }
+         return bundle;
+      }
+   }
+}

Modified: projects/jboss-osgi/trunk/reactor/framework/src/test/resources/bootstrap/jboss-osgi-bootstrap.xml
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/test/resources/bootstrap/jboss-osgi-bootstrap.xml	2009-12-02 14:57:34 UTC (rev 97296)
+++ projects/jboss-osgi/trunk/reactor/framework/src/test/resources/bootstrap/jboss-osgi-bootstrap.xml	2009-12-02 15:38:01 UTC (rev 97297)
@@ -136,9 +136,12 @@
 
   <!-- OSGI Deployment -->
   <bean name="OSGiManifestParsingDeployer" class="org.jboss.osgi.framework.deployers.OSGiManifestParsingDeployer" />
-  <bean name="OSGiBundleStateDeployer" class="org.jboss.osgi.framework.deployers.OSGiBundleStateDeployer">
+  <bean name="OSGiBundleStateAddDeployer" class="org.jboss.osgi.framework.deployers.OSGiBundleStateAddDeployer">
     <constructor><parameter><inject bean="OSGiBundleManager" /></parameter></constructor>
   </bean>
+  <bean name="OSGiBundleStateRemoveDeployer" class="org.jboss.osgi.framework.deployers.OSGiBundleStateRemoveDeployer">
+    <constructor><parameter><inject bean="OSGiBundleManager" /></parameter></constructor>
+  </bean>
   <bean name="OSGiBundleActivatorDeployer" class="org.jboss.osgi.framework.deployers.OSGiBundleActivatorDeployer" />
   <bean name="OSGiContextTrackerDeployer" class="org.jboss.osgi.framework.deployers.OSGiContextTrackerDeployer" />
 

Copied: projects/jboss-osgi/trunk/reactor/framework/src/test/resources/bundles/service/service-bundle4/META-INF/MANIFEST.MF (from rev 97290, projects/jboss-osgi/trunk/reactor/framework/src/test/resources/bundles/service/service-bundle3/META-INF/MANIFEST.MF)
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/test/resources/bundles/service/service-bundle4/META-INF/MANIFEST.MF	                        (rev 0)
+++ projects/jboss-osgi/trunk/reactor/framework/src/test/resources/bundles/service/service-bundle4/META-INF/MANIFEST.MF	2009-12-02 15:38:01 UTC (rev 97297)
@@ -0,0 +1,7 @@
+Manifest-Version: 1.0
+Implementation-Title: JBoss OSGi tests
+Implementation-Version: test
+Implementation-Vendor: jboss.org
+Bundle-Name: Service4
+Bundle-SymbolicName: org.jboss.test.osgi.service4
+Export-Package: org.jboss.test.osgi.service.support.a;org.jboss.test.osgi.service.support.c



More information about the jboss-osgi-commits mailing list