aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dav...@apache.org
Subject svn commit: r1207036 - in /aries/trunk/spi-fly/spi-fly-core/src: main/java/org/apache/aries/spifly/ test/java/org/apache/aries/spifly/ test/resources/org/apache/aries/spifly/impl4/META-INF/services/
Date Mon, 28 Nov 2011 09:38:42 GMT
Author: davidb
Date: Mon Nov 28 09:38:41 2011
New Revision: 1207036

URL: http://svn.apache.org/viewvc?rev=1207036&view=rev
Log:
Add custom properties to service registrations.

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
    aries/trunk/spi-fly/spi-fly-core/src/test/resources/org/apache/aries/spifly/impl4/META-INF/services/org.apache.aries.mytest.MySPI2

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=1207036&r1=1207035&r2=1207036&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 Nov 28 09:38:41 2011
@@ -140,6 +140,7 @@ public class ProviderBundleTrackerCustom
 
                         Hashtable<String, Object> props = new Hashtable<String,
Object>();
                         props.put(SpiFlyConstants.SPI_PROVIDER_URL, serviceFile);
+                        props.putAll(customAttributes);
 
                         ServiceRegistration reg = bundle.getBundleContext()
                                 .registerService(registrationClassName, o, props);

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=1207036&r1=1207035&r2=1207036&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 Nov 28 09:38:41 2011
@@ -33,6 +33,7 @@ import java.util.Hashtable;
 import java.util.List;
 import java.util.Map;
 
+import org.apache.aries.spifly.api.SpiFlyConstants;
 import org.apache.aries.spifly.impl1.MySPIImpl1;
 import org.apache.aries.spifly.impl2.MySPIImpl2a;
 import org.apache.aries.spifly.impl2.MySPIImpl2b;
@@ -111,7 +112,7 @@ public class ProviderBundleTrackerCustom
     }
 
     @Test
-    public void testServiceSubsetSelection() throws Exception {
+    public void testServiceSubsetSelectionAndRegistrationProperties() throws Exception {
         Bundle spiBundle = EasyMock.createMock(Bundle.class);
         EasyMock.replay(spiBundle);
 
@@ -132,6 +133,8 @@ public class ProviderBundleTrackerCustom
         List<ServiceRegistration> registrations = customizer.addingBundle(implBundle,
null);
         assertEquals(1, registrations.size());
         assertEquals("org.apache.aries.mytest.MySPI", registrations.iterator().next().getReference().getProperty(Constants.OBJECTCLASS));
+        assertNotNull(registrations.iterator().next().getReference().getProperty(SpiFlyConstants.SPI_PROVIDER_URL));
+        assertEquals("global", registrations.iterator().next().getReference().getProperty("approval"));
     }
 
     @Test
@@ -273,13 +276,27 @@ public class ProviderBundleTrackerCustom
         BundleContext implBC = EasyMock.createNiceMock(BundleContext.class);
 
         EasyMock.expect(implBC.
-            registerService((String) EasyMock.anyObject(), EasyMock.anyObject(), (Dictionary<?,?>)EasyMock.anyObject())).
+            registerService((String) EasyMock.anyObject(), EasyMock.anyObject(), (Dictionary<String,?>)EasyMock.anyObject())).
             andAnswer(new IAnswer<ServiceRegistration>() {
                 @Override
+                @SuppressWarnings("unchecked")
                 public ServiceRegistration answer() throws Throwable {
+                    final String className = (String) EasyMock.getCurrentArguments()[0];
+                    final Dictionary<String,?> registrationProps =
+                            (Dictionary<String, ?>) EasyMock.getCurrentArguments()[2];
+
                     ServiceReference sref = EasyMock.createMock(ServiceReference.class);
-                    EasyMock.expect(sref.getProperty(Constants.OBJECTCLASS)).andReturn(
-                        EasyMock.getCurrentArguments()[0]);
+                    EasyMock.expect(sref.getProperty(EasyMock.anyObject(String.class))).andAnswer(new
IAnswer<Object>() {
+                        @Override
+                        public Object answer() throws Throwable {
+                            Object prop = EasyMock.getCurrentArguments()[0];
+                            if (Constants.OBJECTCLASS.equals(prop)) {
+                                return className;
+                            } else {
+                                return registrationProps.get(prop);
+                        }
+                        }
+                    }).anyTimes();
                     EasyMock.replay(sref);
 
                     ServiceRegistration sreg = EasyMock.createMock(ServiceRegistration.class);

Modified: aries/trunk/spi-fly/spi-fly-core/src/test/resources/org/apache/aries/spifly/impl4/META-INF/services/org.apache.aries.mytest.MySPI2
URL: http://svn.apache.org/viewvc/aries/trunk/spi-fly/spi-fly-core/src/test/resources/org/apache/aries/spifly/impl4/META-INF/services/org.apache.aries.mytest.MySPI2?rev=1207036&r1=1207035&r2=1207036&view=diff
==============================================================================
--- aries/trunk/spi-fly/spi-fly-core/src/test/resources/org/apache/aries/spifly/impl4/META-INF/services/org.apache.aries.mytest.MySPI2
(original)
+++ aries/trunk/spi-fly/spi-fly-core/src/test/resources/org/apache/aries/spifly/impl4/META-INF/services/org.apache.aries.mytest.MySPI2
Mon Nov 28 09:38:41 2011
@@ -1,2 +1,5 @@
+# A comment
 org.apache.aries.spifly.impl4.MySPIImpl4b
-org.apache.aries.spifly.impl4.MySPIImpl4c
\ No newline at end of file
+# Another comment
+org.apache.aries.spifly.impl4.MySPIImpl4c
+# A final comment
\ No newline at end of file



Mime
View raw message