You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by da...@apache.org on 2010/12/07 12:48:35 UTC

svn commit: r1042985 - in /incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFlyTests: META-INF/ src/org/apache/aries/mytest/ src/org/apache/aries/spifly/

Author: davidb
Date: Tue Dec  7 11:48:34 2010
New Revision: 1042985

URL: http://svn.apache.org/viewvc?rev=1042985&view=rev
Log:
New Bundle Tracker customizer test.

Added:
    incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFlyTests/src/org/apache/aries/mytest/
    incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFlyTests/src/org/apache/aries/mytest/MySPI.java
    incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFlyTests/src/org/apache/aries/spifly/MySPIImpl.java
    incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFlyTests/src/org/apache/aries/spifly/ProviderBundleTrackerCustomizerTest.java
    incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFlyTests/src/org/apache/aries/spifly/org.apache.aries.mytest.MySPI
Modified:
    incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFlyTests/META-INF/MANIFEST.MF

Modified: incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFlyTests/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFlyTests/META-INF/MANIFEST.MF?rev=1042985&r1=1042984&r2=1042985&view=diff
==============================================================================
--- incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFlyTests/META-INF/MANIFEST.MF (original)
+++ incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFlyTests/META-INF/MANIFEST.MF Tue Dec  7 11:48:34 2010
@@ -4,5 +4,6 @@ Bundle-Name: SpiFlyTests
 Bundle-SymbolicName: SpiFlyTests
 Bundle-Version: 1.0.0.qualifier
 Fragment-Host: SpiFly
-Import-Package: org.junit;version="[4.8.1,5.0.0)",
+Import-Package: org.easymock;version="[3.0.0,3.1.0)",
+ org.junit;version="[4.8.1,5.0.0)",
  org.osgi.framework;version="[1.3.0,2.0.0)"

Added: incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFlyTests/src/org/apache/aries/mytest/MySPI.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFlyTests/src/org/apache/aries/mytest/MySPI.java?rev=1042985&view=auto
==============================================================================
--- incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFlyTests/src/org/apache/aries/mytest/MySPI.java (added)
+++ incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFlyTests/src/org/apache/aries/mytest/MySPI.java Tue Dec  7 11:48:34 2010
@@ -0,0 +1,5 @@
+package org.apache.aries.mytest;
+
+public interface MySPI {
+    String someMethod(String s);
+}

Added: incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFlyTests/src/org/apache/aries/spifly/MySPIImpl.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFlyTests/src/org/apache/aries/spifly/MySPIImpl.java?rev=1042985&view=auto
==============================================================================
--- incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFlyTests/src/org/apache/aries/spifly/MySPIImpl.java (added)
+++ incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFlyTests/src/org/apache/aries/spifly/MySPIImpl.java Tue Dec  7 11:48:34 2010
@@ -0,0 +1,10 @@
+package org.apache.aries.spifly;
+
+import org.apache.aries.mytest.MySPI;
+
+public class MySPIImpl implements MySPI {
+    @Override
+    public String someMethod(String s) {
+        return new StringBuilder(s).reverse().toString();
+    }
+}

Added: incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFlyTests/src/org/apache/aries/spifly/ProviderBundleTrackerCustomizerTest.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFlyTests/src/org/apache/aries/spifly/ProviderBundleTrackerCustomizerTest.java?rev=1042985&view=auto
==============================================================================
--- incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFlyTests/src/org/apache/aries/spifly/ProviderBundleTrackerCustomizerTest.java (added)
+++ incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFlyTests/src/org/apache/aries/spifly/ProviderBundleTrackerCustomizerTest.java Tue Dec  7 11:48:34 2010
@@ -0,0 +1,76 @@
+package org.apache.aries.spifly;
+
+import java.net.URL;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Dictionary;
+import java.util.Hashtable;
+import java.util.List;
+
+import org.apache.aries.spifly.api.SpiFlyConstants;
+import org.easymock.EasyMock;
+import org.junit.Assert;
+import org.junit.Test;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+
+public class ProviderBundleTrackerCustomizerTest {
+    @Test
+    @SuppressWarnings("unchecked")
+    public void testAddingRemovedBundle() throws Exception {        
+        Bundle spiBundle = EasyMock.createMock(Bundle.class);
+        EasyMock.replay(spiBundle);
+        Activator a = new Activator();        
+        
+        ProviderBundleTrackerCustomizer customizer = new ProviderBundleTrackerCustomizer(a, spiBundle);
+        
+        ServiceRegistration<Object> sreg = EasyMock.createMock(ServiceRegistration.class);
+        sreg.unregister();
+        EasyMock.expectLastCall();
+        EasyMock.replay(sreg);
+
+        // The bundle context for the test SPI bundle
+        BundleContext implBC = EasyMock.createMock(BundleContext.class);
+        EasyMock.<Object>expect(implBC.registerService(
+                EasyMock.eq("org.apache.aries.mytest.MySPI"), 
+                EasyMock.isA(MySPIImpl.class), 
+                (Dictionary<String,?>) EasyMock.anyObject())).andReturn(sreg);
+        EasyMock.replay(implBC);
+
+        // The test impl bundle
+        Bundle implBundle = EasyMock.createNiceMock(Bundle.class);
+        EasyMock.expect(implBundle.getBundleContext()).andReturn(implBC);
+        
+        Dictionary<String, String> headers = new Hashtable<String, String>();
+        // Specify the headers for the test bundle
+        headers.put(SpiFlyConstants.SPI_PROVIDER_HEADER, "true");
+        EasyMock.expect(implBundle.getHeaders()).andReturn(headers);
+        
+        // List the resources found at META-INF/services in the test bundle
+        URL res = getClass().getResource("org.apache.aries.mytest.MySPI");
+        Assert.assertNotNull("precondition", res);
+        EasyMock.expect(implBundle.findEntries("META-INF/services", "*", false)).andReturn(
+                Collections.enumeration(Collections.singleton(res)));
+        
+        Class<?> cls = getClass().getClassLoader().loadClass("org.apache.aries.spifly.MySPIImpl");
+        EasyMock.<Object>expect(implBundle.loadClass("org.apache.aries.spifly.MySPIImpl")).andReturn(cls);
+        
+        EasyMock.replay(implBundle);
+        
+        Assert.assertEquals("Precondition", 0, a.findSPIProviderBundles("org.apache.aries.mytest.MySPI").size());
+        // Call addingBundle();
+        List<ServiceRegistration<?>> registrations = customizer.addingBundle(implBundle, null);
+        Collection<Bundle> bundles = a.findSPIProviderBundles("org.apache.aries.mytest.MySPI");
+        Assert.assertEquals(1, bundles.size());
+        Assert.assertSame(implBundle, bundles.iterator().next());
+        
+        // The bc.registerService() call should now have been made
+        EasyMock.verify(implBC);
+        
+        // Call removedBundle();
+        customizer.removedBundle(implBundle, null, registrations);
+        // sreg.unregister() should have been called.
+        EasyMock.verify(sreg);
+    }
+}

Added: incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFlyTests/src/org/apache/aries/spifly/org.apache.aries.mytest.MySPI
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFlyTests/src/org/apache/aries/spifly/org.apache.aries.mytest.MySPI?rev=1042985&view=auto
==============================================================================
--- incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFlyTests/src/org/apache/aries/spifly/org.apache.aries.mytest.MySPI (added)
+++ incubator/aries/trunk/spi-fly/contrib/pilot_using_weavinghook/SpiFlyTests/src/org/apache/aries/spifly/org.apache.aries.mytest.MySPI Tue Dec  7 11:48:34 2010
@@ -0,0 +1 @@
+org.apache.aries.spifly.MySPIImpl