aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dav...@apache.org
Subject svn commit: r1291374 - in /aries/trunk/spi-fly/spi-fly-core/src: main/java/org/apache/aries/spifly/ProviderBundleTrackerCustomizer.java test/java/org/apache/aries/spifly/ProviderBundleTrackerCustomizerGenericCapabilityTest.java
Date Mon, 20 Feb 2012 17:05:56 GMT
Author: davidb
Date: Mon Feb 20 17:05:56 2012
New Revision: 1291374

URL: http://svn.apache.org/viewvc?rev=1291374&view=rev
Log:
Added extra functionality and testing for provided-spi directive.

Modified:
    aries/trunk/spi-fly/spi-fly-core/src/main/java/org/apache/aries/spifly/ProviderBundleTrackerCustomizer.java
    aries/trunk/spi-fly/spi-fly-core/src/test/java/org/apache/aries/spifly/ProviderBundleTrackerCustomizerGenericCapabilityTest.java

Modified: aries/trunk/spi-fly/spi-fly-core/src/main/java/org/apache/aries/spifly/ProviderBundleTrackerCustomizer.java
URL: http://svn.apache.org/viewvc/aries/trunk/spi-fly/spi-fly-core/src/main/java/org/apache/aries/spifly/ProviderBundleTrackerCustomizer.java?rev=1291374&r1=1291373&r2=1291374&view=diff
==============================================================================
--- aries/trunk/spi-fly/spi-fly-core/src/main/java/org/apache/aries/spifly/ProviderBundleTrackerCustomizer.java
(original)
+++ aries/trunk/spi-fly/spi-fly-core/src/main/java/org/apache/aries/spifly/ProviderBundleTrackerCustomizer.java
Mon Feb 20 17:05:56 2012
@@ -205,15 +205,15 @@ public class ProviderBundleTrackerCustom
 
                 if (SpiFlyConstants.PROVIDED_SPI_DIRECTIVE.equals(entry.getKey())) {
                     if (entry.getValue() != null) {
-                        serviceNames.add(entry.getValue());
-                        // TODO split string
+                        for (String s : entry.getValue().split(",")) {
+                            serviceNames.add(s.trim());
+                        }
                     }
                 } else {
                     directives.put(entry.getKey(), entry.getValue());
                 }
             }
 
-            // directives.putAll(cap.getDirectives());
             return serviceNames;
         }
         return null;

Modified: aries/trunk/spi-fly/spi-fly-core/src/test/java/org/apache/aries/spifly/ProviderBundleTrackerCustomizerGenericCapabilityTest.java
URL: http://svn.apache.org/viewvc/aries/trunk/spi-fly/spi-fly-core/src/test/java/org/apache/aries/spifly/ProviderBundleTrackerCustomizerGenericCapabilityTest.java?rev=1291374&r1=1291373&r2=1291374&view=diff
==============================================================================
--- aries/trunk/spi-fly/spi-fly-core/src/test/java/org/apache/aries/spifly/ProviderBundleTrackerCustomizerGenericCapabilityTest.java
(original)
+++ aries/trunk/spi-fly/spi-fly-core/src/test/java/org/apache/aries/spifly/ProviderBundleTrackerCustomizerGenericCapabilityTest.java
Mon Feb 20 17:05:56 2012
@@ -30,9 +30,11 @@ import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Dictionary;
+import java.util.HashSet;
 import java.util.Hashtable;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 import org.apache.aries.spifly.api.SpiFlyConstants;
 import org.apache.aries.spifly.impl1.MySPIImpl1;
@@ -103,7 +105,7 @@ public class ProviderBundleTrackerCustom
 
         BundleContext implBC = mockSPIBundleContext(sreg);
         Bundle implBundle = mockSPIBundle(implBC, SpiFlyConstants.PROVIDER_REQUIREMENT +
-                "; service-registry:=true; approval=global");
+                "; " + SpiFlyConstants.SERVICE_REGISTRY_DIRECTIVE + ":=true; approval=global");
 
         List<ServiceRegistration> registrations = customizer.addingBundle(implBundle,
null);
         assertEquals(1, registrations.size());
@@ -140,6 +142,34 @@ public class ProviderBundleTrackerCustom
     }
 
     @Test
+    public void testProvidedSPIDirective() throws Exception {
+        Bundle spiBundle = EasyMock.createMock(Bundle.class);
+        EasyMock.replay(spiBundle);
+
+        BaseActivator activator = new BaseActivator() {
+            @Override
+            public void start(BundleContext context) throws Exception {}
+        };
+
+        ProviderBundleTrackerCustomizer customizer = new ProviderBundleTrackerCustomizer(activator,
spiBundle);
+
+        BundleContext implBC = mockSPIBundleContext4();
+        Bundle implBundle =
+            mockSPIBundle4(implBC, SpiFlyConstants.PROVIDER_REQUIREMENT + "; " + SpiFlyConstants.PROVIDED_SPI_DIRECTIVE
+ ":=\"org.apache.aries.mytest.MySPI,org.apache.aries.mytest.MySPI2\"; approval=global");
+
+        List<ServiceRegistration> registrations = customizer.addingBundle(implBundle,
null);
+        assertEquals("Expected 3 registrations, one for MySPI and 2 for MySPI2", 3, registrations.size());
+        Set<String> expectedObjectClasses = new HashSet<String>(Arrays.asList("org.apache.aries.mytest.MySPI",
"org.apache.aries.mytest.MySPI2"));
+        Set<String> actualObjectClasses = new HashSet<String>();
+        for (ServiceRegistration sr : registrations) {
+            actualObjectClasses.add((String) sr.getReference().getProperty(Constants.OBJECTCLASS));
+            assertNotNull(sr.getReference().getProperty(SpiFlyConstants.SPI_PROVIDER_URL_PROPERTY));
+            assertEquals("global", sr.getReference().getProperty("approval"));
+        }
+        assertEquals(expectedObjectClasses, actualObjectClasses);
+    }
+
+    @Test
     public void testMultipleServiceInstancesAndTypes() throws Exception {
         Bundle spiBundle = EasyMock.createMock(Bundle.class);
         EasyMock.replay(spiBundle);
@@ -195,7 +225,8 @@ public class ProviderBundleTrackerCustom
         EasyMock.replay(sreg);
 
         BundleContext implBC = mockSPIBundleContext(sreg);
-        Bundle implBundle = mockSPIBundle(implBC, SpiFlyConstants.PROVIDER_REQUIREMENT +
"; service-registry:=false");
+        Bundle implBundle = mockSPIBundle(implBC, SpiFlyConstants.PROVIDER_REQUIREMENT +
+                "; " + SpiFlyConstants.SERVICE_REGISTRY_DIRECTIVE + ":=false");
 
         List<ServiceRegistration> registrations = customizer.addingBundle(implBundle,
null);
         assertEquals(0, registrations.size());



Mime
View raw message