[jboss-cvs] JBossAS SVN: r90247 - in projects/jboss-osgi/trunk: blueprint/impl/src/main/java/org/jboss/osgi/blueprint/context and 5 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Jun 16 06:48:37 EDT 2009


Author: thomas.diesler at jboss.com
Date: 2009-06-16 06:48:36 -0400 (Tue, 16 Jun 2009)
New Revision: 90247

Modified:
   projects/jboss-osgi/trunk/blueprint/impl/src/main/java/org/jboss/osgi/blueprint/context/BlueprintContextImpl.java
   projects/jboss-osgi/trunk/blueprint/impl/src/main/java/org/jboss/osgi/blueprint/extender/BlueprintExtender.java
   projects/jboss-osgi/trunk/blueprint/testsuite/src/test/java/org/jboss/test/osgi/blueprint/context/BlueprintContextTestCase.java
   projects/jboss-osgi/trunk/blueprint/testsuite/src/test/resources/context/OSGI-INF/blueprint/basic-service.xml
   projects/jboss-osgi/trunk/blueprint/testsuite/src/test/resources/context/context-basic.bnd
   projects/jboss-osgi/trunk/husky/testsuite/pom.xml
   projects/jboss-osgi/trunk/pom.xml
Log:
[JBOSGI-103] - Add support for BlueprintContext API

Modified: projects/jboss-osgi/trunk/blueprint/impl/src/main/java/org/jboss/osgi/blueprint/context/BlueprintContextImpl.java
===================================================================
--- projects/jboss-osgi/trunk/blueprint/impl/src/main/java/org/jboss/osgi/blueprint/context/BlueprintContextImpl.java	2009-06-16 10:43:20 UTC (rev 90246)
+++ projects/jboss-osgi/trunk/blueprint/impl/src/main/java/org/jboss/osgi/blueprint/context/BlueprintContextImpl.java	2009-06-16 10:48:36 UTC (rev 90247)
@@ -23,13 +23,19 @@
 
 //$Id$
 
+import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Collections;
+import java.util.LinkedHashSet;
+import java.util.List;
 import java.util.Set;
 
 import org.jboss.osgi.blueprint.reflect.Blueprint;
 import org.jboss.osgi.spi.NotImplementedException;
+import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.service.blueprint.context.BlueprintContext;
+import org.osgi.service.blueprint.context.NoSuchComponentException;
 import org.osgi.service.blueprint.reflect.BeanMetadata;
 import org.osgi.service.blueprint.reflect.ComponentMetadata;
 import org.osgi.service.blueprint.reflect.ServiceMetadata;
@@ -46,21 +52,29 @@
  */
 public class BlueprintContextImpl implements BlueprintContext
 {
-   //private Blueprint blueprintMetadata;
-   
-   public BlueprintContextImpl(Blueprint blueprintMetadata)
+   private Bundle bundle;
+   private Blueprint bpMetadata;
+
+   public BlueprintContextImpl(Bundle bundle, Blueprint bpMetadata)
    {
-      //this.blueprintMetadata = blueprintMetadata;
+      this.bundle = bundle;
+      this.bpMetadata = bpMetadata;
    }
-   
+
    public Collection<BeanMetadata> getBeanComponentsMetadata()
    {
-      throw new NotImplementedException();
+      List<BeanMetadata> beanMetadata = new ArrayList<BeanMetadata>();
+      for (ComponentMetadata comp : bpMetadata.getComponents())
+      {
+         if (comp instanceof BeanMetadata)
+            beanMetadata.add((BeanMetadata)comp);
+      }
+      return Collections.unmodifiableList(beanMetadata);
    }
 
    public BundleContext getBundleContext()
    {
-      throw new NotImplementedException();
+      return bundle.getBundleContext();
    }
 
    public Object getComponent(String name)
@@ -70,17 +84,40 @@
 
    public ComponentMetadata getComponentMetadata(String name)
    {
-      throw new NotImplementedException();
+      ComponentMetadata compMetadata = null;
+      for (ComponentMetadata aux : bpMetadata.getComponents())
+      {
+         if (aux.getId().equals(name))
+         {
+            compMetadata = aux;
+            break;
+         }
+      }
+
+      if (compMetadata == null)
+         throw new NoSuchComponentException("Cannot get component metadata for: " + name);
+
+      return compMetadata;
    }
 
    public Set<String> getComponentNames()
    {
-      throw new NotImplementedException();
+      Set<String> compNames = new LinkedHashSet<String>();
+      for (ComponentMetadata comp : bpMetadata.getComponents())
+         compNames.add(comp.getId());
+
+      return Collections.unmodifiableSet(compNames);
    }
 
    public Collection<ServiceMetadata> getExportedServicesMetadata()
    {
-      throw new NotImplementedException();
+      List<ServiceMetadata> servMetadata = new ArrayList<ServiceMetadata>();
+      for (ComponentMetadata comp : bpMetadata.getComponents())
+      {
+         if (comp instanceof ServiceMetadata)
+            servMetadata.add((ServiceMetadata)comp);
+      }
+      return Collections.unmodifiableList(servMetadata);
    }
 
    public Collection<ServiceReferenceMetadata> getReferencedServicesMetadata()

Modified: projects/jboss-osgi/trunk/blueprint/impl/src/main/java/org/jboss/osgi/blueprint/extender/BlueprintExtender.java
===================================================================
--- projects/jboss-osgi/trunk/blueprint/impl/src/main/java/org/jboss/osgi/blueprint/extender/BlueprintExtender.java	2009-06-16 10:43:20 UTC (rev 90246)
+++ projects/jboss-osgi/trunk/blueprint/impl/src/main/java/org/jboss/osgi/blueprint/extender/BlueprintExtender.java	2009-06-16 10:48:36 UTC (rev 90247)
@@ -60,6 +60,7 @@
    public void bundleChanged(BundleEvent event)
    {
       Bundle bundle = event.getBundle();
+      
       Blueprint bpMetadata = null;
       
       if (event.getType() == BundleEvent.STARTING)
@@ -97,7 +98,7 @@
       // Register the BlueprintContext
       if (bpMetadata != null)
       {
-         BlueprintContext bpContext = new BlueprintContextImpl(bpMetadata);
+         BlueprintContext bpContext = new BlueprintContextImpl(bundle, bpMetadata);
          context.registerService(BlueprintContext.class.getName(), bpContext, null);
       }
    }

Modified: projects/jboss-osgi/trunk/blueprint/testsuite/src/test/java/org/jboss/test/osgi/blueprint/context/BlueprintContextTestCase.java
===================================================================
--- projects/jboss-osgi/trunk/blueprint/testsuite/src/test/java/org/jboss/test/osgi/blueprint/context/BlueprintContextTestCase.java	2009-06-16 10:43:20 UTC (rev 90246)
+++ projects/jboss-osgi/trunk/blueprint/testsuite/src/test/java/org/jboss/test/osgi/blueprint/context/BlueprintContextTestCase.java	2009-06-16 10:48:36 UTC (rev 90247)
@@ -25,8 +25,15 @@
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
 import static org.junit.Assume.assumeNotNull;
 
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import org.jboss.osgi.husky.Bridge;
 import org.jboss.osgi.husky.BridgeFactory;
 import org.jboss.osgi.husky.annotation.ProvideContext;
 import org.jboss.osgi.spi.capability.BlueprintCapability;
@@ -35,16 +42,23 @@
 import org.jboss.osgi.spi.testing.OSGiBundle;
 import org.jboss.osgi.spi.testing.OSGiRuntime;
 import org.jboss.osgi.spi.testing.OSGiTestHelper;
+import org.jboss.test.osgi.blueprint.context.bundle.BeanA;
+import org.jboss.test.osgi.blueprint.context.bundle.ServiceA;
+import org.jboss.test.osgi.blueprint.context.bundle.ServiceB;
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
+import org.junit.Ignore;
 import org.junit.Test;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceReference;
 import org.osgi.service.blueprint.context.BlueprintContext;
+import org.osgi.service.blueprint.reflect.BeanMetadata;
+import org.osgi.service.blueprint.reflect.ComponentMetadata;
+import org.osgi.service.blueprint.reflect.ServiceMetadata;
 
 /**
- * Blueprint parser tests
+ * BlueprintContext API tests
  * 
  * @author thomas.diesler at jboss.com
  * @since 13-May-2009
@@ -55,6 +69,7 @@
    public static BundleContext context;
 
    private static OSGiRuntime runtime;
+   private static Bridge huskyBridge;
 
    @BeforeClass
    public static void beforeClass() throws Exception
@@ -66,6 +81,8 @@
          runtime.addCapability(new MicrocontainerCapability());
          runtime.addCapability(new BlueprintCapability());
          
+         huskyBridge = BridgeFactory.getBridge();
+         
          OSGiBundle bundle = runtime.installBundle("context-basic.jar");
          bundle.start();
       }
@@ -82,7 +99,7 @@
    public void testBlueprintBundleInstall() throws Exception
    {
       if (context == null)
-         BridgeFactory.getBridge().run();
+         huskyBridge.run();
       
       assumeNotNull(context);
       
@@ -91,17 +108,148 @@
    }
 
    @Test
-   public void testBlueprintContext() throws Exception
+   public void testBlueprintContextAvailable() throws Exception
    {
       if (context == null)
-         BridgeFactory.getBridge().run();
+         huskyBridge.run();
       
       assumeNotNull(context);
       
-      ServiceReference sref = context.getServiceReference(BlueprintContext.class.getName());
-      assertNotNull("BlueprintContext registered", sref);
+      BlueprintContext bpContext = getBlueprintContext();
+      assertNotNull("BlueprintContext available", bpContext);
+   }
+
+
+   @Test
+   public void getBeanComponentsMetadata() throws Exception
+   {
+      if (context == null)
+         huskyBridge.run();
       
-      BlueprintContext bpContext = (BlueprintContext)context.getService(sref);
+      assumeNotNull(context);
       
+      BlueprintContext bpContext = getBlueprintContext();
+      Collection<BeanMetadata> bcMetadata = bpContext.getBeanComponentsMetadata();
+      
+      assertNotNull("BeanComponentsMetadata not null", bcMetadata);
+      assertEquals("BeanComponentsMetadata size", 1, bcMetadata.size());
+      
+      BeanMetadata bmd = bcMetadata.iterator().next();
+      assertEquals("beanA", bmd.getId());
+      assertEquals(BeanA.class.getName(), bmd.getClassName());
    }
+
+   @Test
+   public void getBundleContext() throws Exception
+   {
+      if (context == null)
+         huskyBridge.run();
+      
+      assumeNotNull(context);
+      
+      BlueprintContext bpContext = getBlueprintContext();
+      BundleContext bndContext = bpContext.getBundleContext();
+      
+      assertNotNull("BundleContext not null", bndContext);
+      assertEquals("BundleContext equals", context, bndContext);
+   }
+
+
+   @Test
+   @Ignore
+   public void getComponent() throws Exception
+   {
+      if (context == null)
+         huskyBridge.run();
+      
+      assumeNotNull(context);
+      
+      BlueprintContext bpContext = getBlueprintContext();
+      BeanA beanA = (BeanA)bpContext.getComponent("beanA");
+   }
+
+   @Test
+   public void getComponentMetadata() throws Exception
+   {
+      if (context == null)
+         huskyBridge.run();
+      
+      assumeNotNull(context);
+      
+      BlueprintContext bpContext = getBlueprintContext();
+      ComponentMetadata compMetadata = bpContext.getComponentMetadata("beanA");
+      
+      assertNotNull("ComponentMetadata not null", compMetadata);
+      assertEquals("beanA", compMetadata.getId());
+   }
+
+   @Test
+   public void getComponentNames() throws Exception
+   {
+      if (context == null)
+         huskyBridge.run();
+      
+      assumeNotNull(context);
+      
+      BlueprintContext bpContext = getBlueprintContext();
+      Set<String> compNames = bpContext.getComponentNames();
+
+      assertNotNull("ComponentNames not null", compNames);
+      assertEquals("ComponentNames size", 3, compNames.size());
+      assertTrue("ComponentNames contains beanA", compNames.contains("beanA"));
+      assertTrue("ComponentNames contains serviceA", compNames.contains("serviceA"));
+      assertTrue("ComponentNames contains serviceB", compNames.contains("serviceB"));
+   }
+
+   @Test
+   public void getExportedServicesMetadata() throws Exception
+   {
+      if (context == null)
+         huskyBridge.run();
+      
+      assumeNotNull(context);
+      
+      BlueprintContext bpContext = getBlueprintContext();
+      Collection<ServiceMetadata> servicesMetadata = bpContext.getExportedServicesMetadata();
+
+      assertNotNull("ServiceMetadata not null", servicesMetadata);
+      assertEquals("ServiceMetadata size", 2, servicesMetadata.size());
+      
+      Iterator<ServiceMetadata> itServices = servicesMetadata.iterator();
+      ServiceMetadata serviceA = itServices.next();
+      assertEquals("serviceA", serviceA.getId());
+      
+      List<String> interfaceNamesA = serviceA.getInterfaceNames();
+      assertNotNull("InterfaceNames not null", interfaceNamesA);
+      assertEquals("InterfaceNames size", 1, interfaceNamesA.size());
+      assertEquals("InterfaceName", ServiceA.class.getName(), interfaceNamesA.get(0));
+      
+      ServiceMetadata serviceB = itServices.next();
+      assertEquals("serviceB", serviceB.getId());
+      
+      List<String> interfaceNamesB = serviceB.getInterfaceNames();
+      assertNotNull("InterfaceNames not null", interfaceNamesB);
+      assertEquals("InterfaceNames size", 1, interfaceNamesB.size());
+      assertEquals("InterfaceName", ServiceB.class.getName(), interfaceNamesB.get(0));
+   }
+
+   @Test
+   @Ignore
+   public void getReferencedServicesMetadata() throws Exception
+   {
+      if (context == null)
+         huskyBridge.run();
+      
+      assumeNotNull(context);
+      
+      BlueprintContext bpContext = getBlueprintContext();
+      bpContext.getReferencedServicesMetadata();
+   }
+
+   private BlueprintContext getBlueprintContext()
+   {
+      ServiceReference sref = context.getServiceReference(BlueprintContext.class.getName());
+      BlueprintContext bpContext = (BlueprintContext)context.getService(sref);
+      return bpContext;
+   }
 }
\ No newline at end of file

Modified: projects/jboss-osgi/trunk/blueprint/testsuite/src/test/resources/context/OSGI-INF/blueprint/basic-service.xml
===================================================================
--- projects/jboss-osgi/trunk/blueprint/testsuite/src/test/resources/context/OSGI-INF/blueprint/basic-service.xml	2009-06-16 10:43:20 UTC (rev 90246)
+++ projects/jboss-osgi/trunk/blueprint/testsuite/src/test/resources/context/OSGI-INF/blueprint/basic-service.xml	2009-06-16 10:48:36 UTC (rev 90247)
@@ -1,14 +1,14 @@
 <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
   xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd schema/blueprint.xsd">
   
-  <bean id="beanA" class="org.jboss.test.osgi.blueprint.context.BeanA">
+  <bean id="beanA" class="org.jboss.test.osgi.blueprint.context.bundle.BeanA">
   </bean>
   
-  <service id="serviceA" ref="beanA" interface="org.jboss.test.osgi.blueprint.context.ServiceA">
+  <service id="serviceA" ref="beanA" interface="org.jboss.test.osgi.blueprint.context.bundle.ServiceA">
   </service>
   
-  <service id="serviceB" interface="org.jboss.test.osgi.blueprint.context.ServiceB">
-    <bean class="org.jboss.test.osgi.blueprint.context.BeanB"/>
+  <service id="serviceB" interface="org.jboss.test.osgi.blueprint.context.bundle.ServiceB">
+    <bean class="org.jboss.test.osgi.blueprint.context.bundle.BeanB"/>
   </service>
   
 </blueprint>
\ No newline at end of file

Modified: projects/jboss-osgi/trunk/blueprint/testsuite/src/test/resources/context/context-basic.bnd
===================================================================
--- projects/jboss-osgi/trunk/blueprint/testsuite/src/test/resources/context/context-basic.bnd	2009-06-16 10:43:20 UTC (rev 90246)
+++ projects/jboss-osgi/trunk/blueprint/testsuite/src/test/resources/context/context-basic.bnd	2009-06-16 10:48:36 UTC (rev 90247)
@@ -4,6 +4,8 @@
 
 Export-Package: org.jboss.test.osgi.blueprint.context
 
+Private-Package: org.jboss.test.osgi.blueprint.context.bundle
+
 Import-Package: \
 	org.jboss.osgi.husky, \
 	org.jboss.osgi.husky.annotation, \

Modified: projects/jboss-osgi/trunk/husky/testsuite/pom.xml
===================================================================
--- projects/jboss-osgi/trunk/husky/testsuite/pom.xml	2009-06-16 10:43:20 UTC (rev 90246)
+++ projects/jboss-osgi/trunk/husky/testsuite/pom.xml	2009-06-16 10:48:36 UTC (rev 90247)
@@ -121,6 +121,55 @@
   
   <!-- Profiles -->
   <profiles>
+
+    <!--
+      Name: framework-equinox
+      Descr: Setup for Equinox framework integration testing
+    -->
+    <profile>
+      <id>framework-equinox</id>
+      <activation>
+        <property>
+          <name>framework</name>
+          <value>equinox</value>
+        </property>
+      </activation>
+      <build>
+        <plugins>
+          <plugin>
+            <artifactId>maven-surefire-plugin</artifactId>
+            <configuration>
+              <skipTests>true</skipTests>
+            </configuration>
+          </plugin>
+        </plugins>
+      </build>
+    </profile>
+
+    <!--
+      Name: framework-knopflerfish
+      Descr: Setup for Knopflerfish framework integration testing
+    -->
+    <profile>
+      <id>framework-knopflerfish</id>
+      <activation>
+        <property>
+          <name>framework</name>
+          <value>knopflerfish</value>
+        </property>
+      </activation>
+      <build>
+        <plugins>
+          <plugin>
+            <artifactId>maven-surefire-plugin</artifactId>
+            <configuration>
+              <skipTests>true</skipTests>
+            </configuration>
+          </plugin>
+        </plugins>
+      </build>
+    </profile>
+    
   </profiles>
   
 </project>

Modified: projects/jboss-osgi/trunk/pom.xml
===================================================================
--- projects/jboss-osgi/trunk/pom.xml	2009-06-16 10:43:20 UTC (rev 90246)
+++ projects/jboss-osgi/trunk/pom.xml	2009-06-16 10:48:36 UTC (rev 90247)
@@ -401,7 +401,7 @@
 
     <!--
       Name: framework-knopflerfish
-      Descr: Setup for Equinox framework integration testing
+      Descr: Setup for Knopflerfish framework integration testing
     -->
     <profile>
       <id>framework-knopflerfish</id>




More information about the jboss-cvs-commits mailing list