[jboss-cvs] JBossAS SVN: r97290 - in projects/jboss-osgi/trunk/reactor/framework/src: test/java/org/jboss/test/osgi and 6 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Dec 2 09:12:58 EST 2009


Author: alesj
Date: 2009-12-02 09:12:58 -0500 (Wed, 02 Dec 2009)
New Revision: 97290

Added:
   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/service/ServiceMixUnitTestCase.java
   projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/support/c/
   projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/support/c/C.java
   projects/jboss-osgi/trunk/reactor/framework/src/test/resources/bundles/service/service-bundle3/
   projects/jboss-osgi/trunk/reactor/framework/src/test/resources/bundles/service/service-bundle3/META-INF/
   projects/jboss-osgi/trunk/reactor/framework/src/test/resources/bundles/service/service-bundle3/META-INF/MANIFEST.MF
Modified:
   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/FrameworkTest.java
   projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/FrameworkTestDelegate.java
Log:
Add initial service-mix tests.

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 13:20:12 UTC (rev 97289)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java	2009-12-02 14:12:58 UTC (rev 97290)
@@ -367,8 +367,13 @@
       if (unit != null)
       {
          OSGiBundleState bundleState = unit.getAttachment(OSGiBundleState.class);
-         if (bundleState != null)
-            return bundleState;
+         if (bundleState == null)
+         {
+            bundleState = addDeployment(unit);
+            bundleState.changeState(Bundle.ACTIVE);
+            unit.addAttachment(OSGiBundleState.class, bundleState);
+         }
+         return bundleState;
       }
 
       return systemBundle;

Copied: projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/DeployersTest.java (from rev 97282, 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/DeployersTest.java	                        (rev 0)
+++ projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/DeployersTest.java	2009-12-02 14:12:58 UTC (rev 97290)
@@ -0,0 +1,94 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.osgi;
+
+import org.jboss.beans.metadata.spi.BeanMetaData;
+import org.jboss.beans.metadata.spi.builder.BeanMetaDataBuilder;
+import org.jboss.deployers.client.spi.Deployment;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.virtual.AssembledDirectory;
+import org.jboss.virtual.VirtualFile;
+import org.jboss.osgi.framework.bundle.OSGiBundleState;
+import org.osgi.framework.Bundle;
+
+/**
+ * Deployers test - generic deployment test.
+ *
+ * @author <a href="ales.justin at jboss.org">Ales Justin</a>
+ */
+public abstract class DeployersTest extends FrameworkTest
+{
+   protected DeployersTest(String name)
+   {
+      super(name);
+   }
+
+   public static DeployersTestDelegate getDelegate(Class<?> clazz) throws Exception
+   {
+      return new DeployersTestDelegate(clazz);
+   }
+
+   protected DeployersTestDelegate getDelegate()
+   {
+      return (DeployersTestDelegate)super.getDelegate();
+   }
+
+   protected Deployment assertDeploy(VirtualFile file) throws Exception
+   {
+      return getDelegate().assertDeploy(file);
+   }
+
+   protected <T> Deployment assertDeploy(VirtualFile file, T metadata, Class<T> expectedType) throws Exception
+   {
+      return getDelegate().assertDeploy(file, metadata, expectedType);
+   }
+
+   protected DeploymentUnit getDeploymentUnit(Deployment deployment) throws Exception
+   {
+      return getDelegate().getDeploymentUnit(deployment);
+   }
+
+   protected void undeploy(Deployment deployment) throws Exception
+   {
+      getDelegate().undeploy(deployment);
+   }
+
+   protected Deployment assertBean(String name, Class<?> beanClass) throws Exception
+   {
+      AssembledDirectory dir = createAssembledDirectory(name, "");
+      addPackage(dir, beanClass);
+      BeanMetaDataBuilder builder = BeanMetaDataBuilder.createBuilder(beanClass.getSimpleName(), beanClass.getName());
+      return assertDeploy(dir, builder.getBeanMetaData(), BeanMetaData.class);
+   }
+
+   protected Bundle getBundle(Deployment deployment) throws Exception
+   {
+      return getBundle(getDeploymentUnit(deployment));
+   }
+
+   protected Bundle getBundle(DeploymentUnit unit) throws Exception
+   {
+      OSGiBundleState bundle = unit.getAttachment(OSGiBundleState.class);
+      assertNotNull(bundle);
+      return bundle;
+   }
+}
\ No newline at end of file

Added: 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	                        (rev 0)
+++ projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/DeployersTestDelegate.java	2009-12-02 14:12:58 UTC (rev 97290)
@@ -0,0 +1,67 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.osgi;
+
+import org.jboss.deployers.client.spi.Deployment;
+import org.jboss.deployers.client.spi.DeployerClient;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.deployers.structure.spi.main.MainDeployerStructure;
+import org.jboss.virtual.VirtualFile;
+
+/**
+ * Deployers test - generic deployment test delegate.
+ *
+ * @author <a href="ales.justin at jboss.org">Ales Justin</a>
+ */
+public class DeployersTestDelegate extends FrameworkTestDelegate
+{
+   public DeployersTestDelegate(Class<?> clazz) throws Exception
+   {
+      super(clazz);
+   }
+
+   public Deployment assertDeploy(VirtualFile file) throws Exception
+   {
+      return assertDeploy(file, null, null);
+   }
+
+   public <T> Deployment assertDeploy(VirtualFile file, T metadata, Class<T> expectedType) throws Exception
+   {
+      Deployment deployment = createDeployment(file, metadata, expectedType);
+      DeployerClient deployerClient = getDeployerClient();
+      deployerClient.deploy(deployment);
+      return deployment; 
+   }
+
+   public DeploymentUnit getDeploymentUnit(Deployment deployment) throws Exception
+   {
+      DeployerClient deployerClient = getDeployerClient();
+      MainDeployerStructure deployerStructure = (MainDeployerStructure) deployerClient;
+      return deployerStructure.getDeploymentUnit(deployment.getName());
+   }
+
+   public void undeploy(Deployment deployment) throws Exception
+   {
+      DeployerClient deployerClient = getDeployerClient();
+      deployerClient.undeploy(deployment);
+   }
+}
\ No newline at end of file

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 13:20:12 UTC (rev 97289)
+++ projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/FrameworkTest.java	2009-12-02 14:12:58 UTC (rev 97290)
@@ -426,6 +426,13 @@
       assertEquals(expected, actual);
    }
 
+   protected void assertBundle(Bundle b1, Bundle b2)
+   {
+      assertNotNull(b1);
+      assertNotNull(b2);
+      assertEquals(b1.getBundleId(), b2.getBundleId());
+   }
+
    protected void assertObjectClass(String expected, ServiceReference reference)
    {
       assertObjectClass(new String[] { expected }, reference);

Modified: projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/FrameworkTestDelegate.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/FrameworkTestDelegate.java	2009-12-02 13:20:12 UTC (rev 97289)
+++ projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/FrameworkTestDelegate.java	2009-12-02 14:12:58 UTC (rev 97290)
@@ -65,6 +65,8 @@
 
    /**
     * Create a new OSGiTestDelegate.
+    * @param clazz test class
+    * @throws Exception for any error
     */
    FrameworkTestDelegate(Class<?> clazz) throws Exception
    {
@@ -107,7 +109,7 @@
    {
       try
       {
-         Method method = clazz.getMethod("deployBundles", new Class[] { FrameworkTestDelegate.class });
+         Method method = clazz.getMethod("deployBundles", FrameworkTestDelegate.class);
          log.debug("Deploying Bundles...");
          method.invoke(null, this);
       }
@@ -295,12 +297,28 @@
       }
    }
 
+   public Deployment createDeployment(VirtualFile virtualFile) throws Exception
+   {
+      return createDeployment(virtualFile, null);
+   }
+
    public Deployment createDeployment(VirtualFile virtualFile, OSGiMetaData metaData) throws Exception
    {
+      return createDeployment(virtualFile, metaData, OSGiMetaData.class);
+   }
+
+   @SuppressWarnings({"unchecked"})
+   public <T> Deployment createDeployment(VirtualFile virtualFile, T metaData, Class<T> expectedType) throws Exception
+   {
       VFSDeployment deployment = VFSDeploymentFactory.getInstance().createVFSDeployment(virtualFile);
-      MutableAttachments att = (MutableAttachments)deployment.getPredeterminedManagedObjects();
       if (metaData != null)
-         att.addAttachment(OSGiMetaData.class, metaData);
+      {
+         if (expectedType == null)
+            expectedType = (Class<T>)metaData.getClass();
+
+         MutableAttachments att = (MutableAttachments)deployment.getPredeterminedManagedObjects();
+         att.addAttachment(expectedType, metaData);
+      }
       return deployment;
    }
 

Added: 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	                        (rev 0)
+++ projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/ServiceMixUnitTestCase.java	2009-12-02 14:12:58 UTC (rev 97290)
@@ -0,0 +1,94 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.osgi.service;
+
+import junit.framework.Test;
+
+import org.jboss.deployers.client.spi.Deployment;
+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.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+
+/**
+ * Test MC's service mixture.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class ServiceMixUnitTestCase extends DeployersTest
+{
+   public ServiceMixUnitTestCase(String name)
+   {
+      super(name);
+   }
+
+   public static Test suite()
+   {
+      return suite(ServiceMixUnitTestCase.class);
+   }
+
+   public void testGetServiceReferenceFromMC() throws Throwable
+   {
+      Deployment bean = assertBean("beanA", A.class);
+      try
+      {
+         Bundle bundle1 = assembleBundle("simple1", "/bundles/service/service-bundle1", A.class);
+         try
+         {
+            bundle1.start();
+            BundleContext bundleContext1 = bundle1.getBundleContext();
+            assertNotNull(bundleContext1);
+
+            ServiceReference ref1 = bundleContext1.getServiceReference(A.class.getName());
+            assertNotNull(ref1);
+            try
+            {
+               Bundle refsBundle = ref1.getBundle();
+               assertBundle(refsBundle, getBundle(bean));
+
+               assertNotNull(bundleContext1.getService(ref1));
+               assertUsingBundles(ref1, bundle1);
+            }
+            finally
+            {
+               bundleContext1.ungetService(ref1);
+            }
+
+            KernelControllerContext beanKCC = getControllerContext("A");
+            change(beanKCC, ControllerState.DESCRIBED);
+
+            assertNull(bundleContext1.getServiceReference(A.class.getName()));
+         }
+         finally
+         {
+            uninstall(bundle1);
+         }
+      }
+      finally
+      {
+         undeploy(bean);
+      }
+   }
+}

Added: projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/support/c/C.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/support/c/C.java	                        (rev 0)
+++ projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/support/c/C.java	2009-12-02 14:12:58 UTC (rev 97290)
@@ -0,0 +1,51 @@
+/*
+ * 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.c;
+
+import org.jboss.test.osgi.service.support.a.A;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class C
+{
+   private A a;
+
+   public C()
+   {
+   }
+
+   public C(A a)
+   {
+      this.a = a;
+   }
+
+   public A getA()
+   {
+      return a;
+   }
+
+   public void setA(A a)
+   {
+      this.a = a;
+   }
+}

Copied: projects/jboss-osgi/trunk/reactor/framework/src/test/resources/bundles/service/service-bundle3/META-INF/MANIFEST.MF (from rev 97282, projects/jboss-osgi/trunk/reactor/framework/src/test/resources/bundles/service/service-bundle1/META-INF/MANIFEST.MF)
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/test/resources/bundles/service/service-bundle3/META-INF/MANIFEST.MF	                        (rev 0)
+++ projects/jboss-osgi/trunk/reactor/framework/src/test/resources/bundles/service/service-bundle3/META-INF/MANIFEST.MF	2009-12-02 14:12:58 UTC (rev 97290)
@@ -0,0 +1,7 @@
+Manifest-Version: 1.0
+Implementation-Title: JBoss OSGi tests
+Implementation-Version: test
+Implementation-Vendor: jboss.org
+Bundle-Name: Service3
+Bundle-SymbolicName: org.jboss.test.osgi.service3
+Import-Package: org.jboss.test.osgi.service.support.a;org.jboss.test.osgi.service.support.c




More information about the jboss-cvs-commits mailing list