incubator-aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dav...@apache.org
Subject svn commit: r900421 - in /incubator/aries/trunk/spi-fly: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/aries/ src/main/java/org/apache/aries/spifly/ src/test/ src/test/java/ src/test/java/org/ sr...
Date Mon, 18 Jan 2010 15:21:56 GMT
Author: davidb
Date: Mon Jan 18 15:21:55 2010
New Revision: 900421

URL: http://svn.apache.org/viewvc?rev=900421&view=rev
Log:
Initial code & tests for the SPI Fly component. 

For more information see: http://cwiki.apache.org/confluence/display/ARIES/SPI+Fly
and http://mail-archives.apache.org/mod_mbox/incubator-aries-dev/201001.mbox/%3Ca1e060231001180620q899672ay40a310aa5e9dea3a@mail.gmail.com%3E

Added:
    incubator/aries/trunk/spi-fly/
    incubator/aries/trunk/spi-fly/pom.xml   (with props)
    incubator/aries/trunk/spi-fly/src/
    incubator/aries/trunk/spi-fly/src/main/
    incubator/aries/trunk/spi-fly/src/main/java/
    incubator/aries/trunk/spi-fly/src/main/java/org/
    incubator/aries/trunk/spi-fly/src/main/java/org/apache/
    incubator/aries/trunk/spi-fly/src/main/java/org/apache/aries/
    incubator/aries/trunk/spi-fly/src/main/java/org/apache/aries/spifly/
    incubator/aries/trunk/spi-fly/src/main/java/org/apache/aries/spifly/Activator.java   (with
props)
    incubator/aries/trunk/spi-fly/src/main/java/org/apache/aries/spifly/SPIBundleTracker.java
  (with props)
    incubator/aries/trunk/spi-fly/src/test/
    incubator/aries/trunk/spi-fly/src/test/java/
    incubator/aries/trunk/spi-fly/src/test/java/org/
    incubator/aries/trunk/spi-fly/src/test/java/org/apache/
    incubator/aries/trunk/spi-fly/src/test/java/org/apache/aries/
    incubator/aries/trunk/spi-fly/src/test/java/org/apache/aries/spifly/
    incubator/aries/trunk/spi-fly/src/test/java/org/apache/aries/spifly/ActivatorTest.java
  (with props)
    incubator/aries/trunk/spi-fly/src/test/java/org/apache/aries/spifly/SPIBundleTrackerTest.java
  (with props)
    incubator/aries/trunk/spi-fly/src/test/resources/
    incubator/aries/trunk/spi-fly/src/test/resources/org/
    incubator/aries/trunk/spi-fly/src/test/resources/org/apache/
    incubator/aries/trunk/spi-fly/src/test/resources/org/apache/aries/
    incubator/aries/trunk/spi-fly/src/test/resources/org/apache/aries/spifly/
    incubator/aries/trunk/spi-fly/src/test/resources/org/apache/aries/spifly/TestSPIBundle_1.0.0.jar
  (with props)
    incubator/aries/trunk/spi-fly/src/test/resources/org/apache/aries/spifly/TestSPIBundle_src.zip
  (with props)

Added: incubator/aries/trunk/spi-fly/pom.xml
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/spi-fly/pom.xml?rev=900421&view=auto
==============================================================================
--- incubator/aries/trunk/spi-fly/pom.xml (added)
+++ incubator/aries/trunk/spi-fly/pom.xml Mon Jan 18 15:21:55 2010
@@ -0,0 +1,97 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied.  See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.apache.aries</groupId>
+        <artifactId>java5-parent</artifactId>
+        <version>1.0.0-incubating-SNAPSHOT</version>
+    </parent>
+
+    <groupId>org.apache.aries.spifly</groupId>
+    <artifactId>org.apache.aries.spifly</artifactId>
+    <packaging>bundle</packaging>
+    <name>Apache Aries SPI Fly</name> 
+    <description>
+This bundle contains an extender that facilitates the use
+of JRE SPI providers (components typically plugged in to the 
+JRE through META-INF/services resources).
+    </description>
+    
+    <dependencies>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.core</artifactId>
+            <version>4.2.0</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.compendium</artifactId>
+            <version>4.2.0</version>
+            <scope>provided</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <version>4.5</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.easymock</groupId>
+            <artifactId>easymock</artifactId>
+            <version>2.5.2</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.easymock</groupId>
+            <artifactId>easymockclassextension</artifactId>
+            <version>2.5.2</version>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <version>2.0.1</version>
+                <extensions>true</extensions>
+                <configuration>
+                    <instructions>
+                        <Import-Package>
+                            *
+                        </Import-Package>
+                        <Export-Package></Export-Package>
+                        <Private-Package>
+                            org.apache.aries.spifly
+                        </Private-Package>
+                        <Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName>
+                        <Bundle-Activator>org.apache.aries.spifly.Activator</Bundle-Activator>
+                    </instructions>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+</project>
+
+

Propchange: incubator/aries/trunk/spi-fly/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/aries/trunk/spi-fly/pom.xml
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: incubator/aries/trunk/spi-fly/pom.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Added: incubator/aries/trunk/spi-fly/src/main/java/org/apache/aries/spifly/Activator.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/spi-fly/src/main/java/org/apache/aries/spifly/Activator.java?rev=900421&view=auto
==============================================================================
--- incubator/aries/trunk/spi-fly/src/main/java/org/apache/aries/spifly/Activator.java (added)
+++ incubator/aries/trunk/spi-fly/src/main/java/org/apache/aries/spifly/Activator.java Mon
Jan 18 15:21:55 2010
@@ -0,0 +1,73 @@
+package org.apache.aries.spifly;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.log.LogService;
+import org.osgi.util.tracker.BundleTracker;
+import org.osgi.util.tracker.ServiceTracker;
+import org.osgi.util.tracker.ServiceTrackerCustomizer;
+
+public class Activator implements BundleActivator {
+    BundleTracker bt;
+    ServiceTracker lst;
+    List<LogService> logServices = new ArrayList<LogService>();
+
+    public synchronized void start(final BundleContext context) throws Exception {
+        lst = new LogServiceTracker(context, LogService.class.getName(), null);
+        lst.open();
+        
+	    bt = new SPIBundleTracker(context, this);
+	    bt.open();
+	}
+
+	public synchronized void stop(BundleContext context) throws Exception {
+	    bt.close();
+	    lst.close();	    
+	}
+	
+	void log(int level, String message) {
+	    synchronized (logServices) {
+	        for (LogService log : logServices) {
+	            log.log(level, message);
+	        }
+        }
+	}
+
+	void log(int level, String message, Throwable th) {
+        synchronized (logServices) {
+            for (LogService log : logServices) {
+                log.log(level, message, th);
+            }
+        }
+    }
+    
+	private final class LogServiceTracker extends ServiceTracker {
+        private LogServiceTracker(BundleContext context, String clazz,
+                ServiceTrackerCustomizer customizer) {
+            super(context, clazz, customizer);
+        }
+
+        @Override
+        public Object addingService(ServiceReference reference) {
+            Object svc = super.addingService(reference);
+            if (svc instanceof LogService) {
+                synchronized (logServices) {
+                    logServices.add((LogService) svc);
+                }
+            }
+            return svc;
+        }
+
+        @Override
+        public void removedService(ServiceReference reference, Object service) {
+            synchronized (logServices) {
+                logServices.remove(service);
+            }
+            super.removedService(reference, service);
+        }
+    }
+}

Propchange: incubator/aries/trunk/spi-fly/src/main/java/org/apache/aries/spifly/Activator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/aries/trunk/spi-fly/src/main/java/org/apache/aries/spifly/Activator.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/aries/trunk/spi-fly/src/main/java/org/apache/aries/spifly/SPIBundleTracker.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/spi-fly/src/main/java/org/apache/aries/spifly/SPIBundleTracker.java?rev=900421&view=auto
==============================================================================
--- incubator/aries/trunk/spi-fly/src/main/java/org/apache/aries/spifly/SPIBundleTracker.java
(added)
+++ incubator/aries/trunk/spi-fly/src/main/java/org/apache/aries/spifly/SPIBundleTracker.java
Mon Jan 18 15:21:55 2010
@@ -0,0 +1,110 @@
+package org.apache.aries.spifly;
+
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.List;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleEvent;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.log.LogService;
+import org.osgi.util.tracker.BundleTracker;
+
+public class SPIBundleTracker extends BundleTracker {
+    public static final String SPI_PROVIDER_URL = "spi.provider.url";
+    
+    final Activator activator;
+    List<ServiceRegistration> registrations = new ArrayList<ServiceRegistration>();
+    
+    public SPIBundleTracker(BundleContext context, Activator a) {
+        super(context, Bundle.ACTIVE, null);
+        activator = a;
+    }
+    
+    @Override
+    public Object addingBundle(Bundle bundle, BundleEvent event) {
+        Object rv = super.addingBundle(bundle, event);
+        log(LogService.LOG_INFO, "Bundle Considered for SPI providers: " + bundle.getSymbolicName());
+        if (bundle.equals(context.getBundle())) {
+            return rv;
+        }
+        
+        Enumeration<?> entries = bundle.findEntries("META-INF/services", "*", false);
+        if (entries == null) {
+            return rv;
+        }
+        
+        while(entries.hasMoreElements()) {
+            URL url = (URL) entries.nextElement();
+            log(LogService.LOG_INFO, "Found SPI resource: " + url);
+            
+            try {
+                BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
+                String className = reader.readLine(); 
+                // do we need to read more than one class name?
+                
+                Class<?> cls = bundle.loadClass(className);
+                Object o = cls.newInstance();
+                log(LogService.LOG_INFO, "Instantiated SPI provider: " + o);
+                
+                Hashtable<String, Object> props = new Hashtable<String, Object>();
+                props.put(SPI_PROVIDER_URL, url);
+                
+                String s = url.toExternalForm();
+                int idx = s.lastIndexOf('/');
+                String registrationClassName = className;
+                if (s.length() > idx) {
+                    registrationClassName = s.substring(idx + 1);
+                }
+                                
+                synchronized (this) {
+                    registrations.add(bundle.getBundleContext().registerService(registrationClassName,
o, props));
+                }
+            } catch (Exception e) {
+                log(LogService.LOG_INFO, "Could not load SPI implementation referred from
" + url, e);
+                e.printStackTrace();
+            }
+        }
+        
+        return rv;
+    }
+
+    @Override
+    public void removedBundle(Bundle bundle, BundleEvent event, Object object) {
+        synchronized (this) {
+            for (Iterator<ServiceRegistration> it = registrations.iterator(); it.hasNext();
) {
+                ServiceRegistration sr = it.next();
+                if (bundle.equals(sr.getReference().getBundle())) {
+                    sr.unregister();
+                    it.remove();
+                }
+            }
+        }
+        
+        super.removedBundle(bundle, event, object);
+    }        
+
+    @Override
+    public void close() {
+        super.close();
+        
+        for (ServiceRegistration sr : registrations) {
+            sr.unregister();
+        }
+        registrations.clear();        
+    }
+
+    private void log(int level, String message) {
+        activator.log(level, message);
+    }
+    
+    private void log(int level, String message, Throwable th) {
+        activator.log(level, message, th);
+    }
+}

Propchange: incubator/aries/trunk/spi-fly/src/main/java/org/apache/aries/spifly/SPIBundleTracker.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/aries/trunk/spi-fly/src/main/java/org/apache/aries/spifly/SPIBundleTracker.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/aries/trunk/spi-fly/src/test/java/org/apache/aries/spifly/ActivatorTest.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/spi-fly/src/test/java/org/apache/aries/spifly/ActivatorTest.java?rev=900421&view=auto
==============================================================================
--- incubator/aries/trunk/spi-fly/src/test/java/org/apache/aries/spifly/ActivatorTest.java
(added)
+++ incubator/aries/trunk/spi-fly/src/test/java/org/apache/aries/spifly/ActivatorTest.java
Mon Jan 18 15:21:55 2010
@@ -0,0 +1,78 @@
+package org.apache.aries.spifly;
+
+import junit.framework.TestCase;
+
+import org.apache.aries.spifly.Activator;
+import org.apache.aries.spifly.SPIBundleTracker;
+import org.easymock.IAnswer;
+import org.easymock.classextension.EasyMock;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Filter;
+import org.osgi.framework.FrameworkUtil;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.log.LogService;
+import org.osgi.util.tracker.BundleTracker;
+import org.osgi.util.tracker.ServiceTracker;
+
+public class ActivatorTest extends TestCase {
+    public void testActivatorAndLogFunctionality() throws Exception {
+        LogService ls = EasyMock.createMock(LogService.class);
+        EasyMock.replay(ls);
+        ServiceReference sr = EasyMock.createMock(ServiceReference.class);
+        EasyMock.replay(sr);
+        
+        BundleContext bc = EasyMock.createNiceMock(BundleContext.class);
+        EasyMock.expect(bc.createFilter((String) EasyMock.anyObject())).andAnswer(new IAnswer<Filter>()
{
+            public Filter answer() throws Throwable {
+                return FrameworkUtil.createFilter((String) EasyMock.getCurrentArguments()[0]);
+            }
+        });
+        EasyMock.expect(bc.getService(sr)).andReturn(ls);
+        EasyMock.replay(bc);
+        
+        Activator a = new Activator();
+        a.start(bc);
+        
+        assertTrue(a.bt instanceof SPIBundleTracker);
+        assertNotNull(a.lst);
+        assertEquals(0, a.logServices.size());
+        
+        a.log(LogService.LOG_ERROR, "yo");
+        a.log(LogService.LOG_WARNING, "help", new Throwable());
+        EasyMock.verify(ls);
+        
+        a.lst.addingService(sr);
+        assertEquals(1, a.logServices.size());
+        
+        EasyMock.reset(ls);
+        ls.log(EasyMock.anyInt(), (String) EasyMock.anyObject());
+        ls.log(EasyMock.anyInt(), (String) EasyMock.anyObject(), (Throwable) EasyMock.anyObject());
+        EasyMock.replay(ls);
+        
+        a.log(LogService.LOG_ERROR, "ha");
+        a.log(LogService.LOG_WARNING, "hey", new Throwable());
+        EasyMock.verify(ls);
+        
+        a.lst.removedService(EasyMock.createMock(ServiceReference.class), new Object());
+        assertEquals(1, a.logServices.size());
+        
+        a.lst.removedService(sr, ls);
+        assertEquals(0, a.logServices.size());
+    }
+    
+    public void testActivatorStop() throws Exception {
+        Activator a = new Activator();
+        
+        a.bt = EasyMock.createMock(BundleTracker.class);
+        a.bt.close();
+        EasyMock.replay(a.bt);
+        
+        a.lst = EasyMock.createMock(ServiceTracker.class);
+        a.lst.close();
+        EasyMock.replay(a.lst);
+
+        a.stop(null);
+        EasyMock.verify(a.bt);
+        EasyMock.verify(a.lst);
+    }
+}

Propchange: incubator/aries/trunk/spi-fly/src/test/java/org/apache/aries/spifly/ActivatorTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/aries/trunk/spi-fly/src/test/java/org/apache/aries/spifly/ActivatorTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/aries/trunk/spi-fly/src/test/java/org/apache/aries/spifly/SPIBundleTrackerTest.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/spi-fly/src/test/java/org/apache/aries/spifly/SPIBundleTrackerTest.java?rev=900421&view=auto
==============================================================================
--- incubator/aries/trunk/spi-fly/src/test/java/org/apache/aries/spifly/SPIBundleTrackerTest.java
(added)
+++ incubator/aries/trunk/spi-fly/src/test/java/org/apache/aries/spifly/SPIBundleTrackerTest.java
Mon Jan 18 15:21:55 2010
@@ -0,0 +1,166 @@
+package org.apache.aries.spifly;
+
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.Collections;
+import java.util.Dictionary;
+
+import junit.framework.TestCase;
+
+import org.apache.aries.spifly.Activator;
+import org.apache.aries.spifly.SPIBundleTracker;
+import org.easymock.EasyMock;
+import org.easymock.IAnswer;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
+
+public class SPIBundleTrackerTest extends TestCase {
+    public void testSPIBundleTrackerClose() {
+        BundleContext bc = EasyMock.createMock(BundleContext.class);
+        EasyMock.replay(bc);
+        
+        ServiceRegistration sr = EasyMock.createMock(ServiceRegistration.class);
+        sr.unregister();
+        EasyMock.replay(sr);
+        
+        SPIBundleTracker sbt = new SPIBundleTracker(bc, new Activator());
+        sbt.registrations.add(sr);
+        
+        sbt.close();        
+        EasyMock.verify(sr);
+    }
+    
+    @SuppressWarnings("unchecked")
+    public void testAddingBundle() throws Exception {
+        BundleContext bc = EasyMock.createMock(BundleContext.class);
+        EasyMock.expect(bc.getBundle()).andReturn(EasyMock.createMock(Bundle.class));
+        EasyMock.replay(bc);
+        
+        SPIBundleTracker sbt = new SPIBundleTracker(bc, new Activator());
+
+        URL jarURL = getClass().getResource("TestSPIBundle_1.0.0.jar");
+        URL url = new URL("jar:" + jarURL + "!/META-INF/services/javax.xml.parsers.DocumentBuilderFactory");
+        final ClassLoader mockBundleLoader = new URLClassLoader(new URL[] {jarURL});  
+        
+        Bundle b = EasyMock.createMock(Bundle.class);
+        EasyMock.expect(b.getSymbolicName()).andReturn("x.y.z");
+        EasyMock.expect(b.findEntries("META-INF/services", "*", false))
+            .andReturn(Collections.enumeration(Collections.singleton(url)));
+        EasyMock.expect(b.loadClass((String) EasyMock.anyObject())).andAnswer(new IAnswer<Class<?>>()
{
+            public Class<?> answer() throws Throwable {
+                return mockBundleLoader.loadClass((String) EasyMock.getCurrentArguments()[0]);
+            }
+        });
+
+        BundleContext bc2 = EasyMock.createMock(BundleContext.class);
+        EasyMock.expect(bc2.registerService(EasyMock.eq("javax.xml.parsers.DocumentBuilderFactory"),

+            EasyMock.anyObject(), (Dictionary) EasyMock.anyObject())).andAnswer(new IAnswer<ServiceRegistration>()
{
+                public ServiceRegistration answer() throws Throwable {
+                    Object impl = EasyMock.getCurrentArguments()[1];
+                    assertEquals("org.example.test.TestDomBuilderFactory", impl.getClass().getName());
+                    assertNotNull(((Dictionary) EasyMock.getCurrentArguments()[2]).get(SPIBundleTracker.SPI_PROVIDER_URL));

+                    return EasyMock.createMock(ServiceRegistration.class);
+                }
+            });
+        EasyMock.replay(bc2);
+
+        EasyMock.expect(b.getBundleContext()).andReturn(bc2);
+        EasyMock.replay(b);
+        
+        assertEquals("Precondition failed", 0, sbt.registrations.size());
+        sbt.addingBundle(b, null);
+        assertEquals(1, sbt.registrations.size());
+        
+        EasyMock.verify(bc2);
+    }
+    
+    public void testAddingUnrelatedBundle() {
+        BundleContext bc = EasyMock.createMock(BundleContext.class);
+        EasyMock.expect(bc.getBundle()).andReturn(EasyMock.createMock(Bundle.class));
+        EasyMock.replay(bc);
+        
+        SPIBundleTracker sbt = new SPIBundleTracker(bc, new Activator());
+        
+        Bundle b = EasyMock.createMock(Bundle.class);
+        EasyMock.expect(b.getSymbolicName()).andReturn("x.y.z");
+        EasyMock.expect(b.findEntries("META-INF/services", "*", false)).andReturn(null);
+        EasyMock.replay(b);
+
+        assertEquals("Precondition failed", 0, sbt.registrations.size());
+        sbt.addingBundle(b, null);
+        assertEquals(0, sbt.registrations.size());
+    }
+
+    public void testRemovedBundle() {
+        BundleContext bc = EasyMock.createMock(BundleContext.class);
+        EasyMock.replay(bc);
+        
+        SPIBundleTracker sbt = new SPIBundleTracker(bc, new Activator());
+        
+        Bundle b = EasyMock.createMock(Bundle.class);
+        EasyMock.replay(b);
+        ServiceReference sref = EasyMock.createMock(ServiceReference.class);
+        EasyMock.expect(sref.getBundle()).andReturn(b);
+        EasyMock.replay(sref);
+        
+        ServiceRegistration sreg = EasyMock.createMock(ServiceRegistration.class);
+        EasyMock.expect(sreg.getReference()).andReturn(sref);
+        sreg.unregister();
+        EasyMock.replay(sreg);        
+        
+        sbt.registrations.add(sreg);
+        
+        assertEquals("Precondition failed", 1, sbt.registrations.size());
+        sbt.removedBundle(b, null, null);
+        assertEquals(0, sbt.registrations.size());
+        
+        EasyMock.verify(sreg);
+        EasyMock.verify(sref);
+    }
+    
+    public void testRemoveUnrelatedBundle() {
+        BundleContext bc = EasyMock.createMock(BundleContext.class);
+        EasyMock.replay(bc);
+        
+        SPIBundleTracker sbt = new SPIBundleTracker(bc, new Activator());
+        
+        Bundle b = EasyMock.createMock(Bundle.class);
+        EasyMock.replay(b);
+        ServiceReference sref = EasyMock.createMock(ServiceReference.class);
+        EasyMock.expect(sref.getBundle()).andReturn(b);
+        EasyMock.replay(sref);
+        
+        ServiceRegistration sreg = EasyMock.createMock(ServiceRegistration.class);
+        EasyMock.expect(sreg.getReference()).andReturn(sref);
+        sreg.unregister();
+        EasyMock.replay(sreg);        
+        
+        sbt.registrations.add(sreg);
+        
+        Bundle b2 = EasyMock.createMock(Bundle.class);
+        EasyMock.replay(b2);
+        
+        assertEquals("Precondition failed", 1, sbt.registrations.size());
+        sbt.removedBundle(b2, null, null);
+        assertEquals(1, sbt.registrations.size());
+    }
+    
+    public void testAddingSelf() {
+        Bundle b = EasyMock.createMock(Bundle.class);
+        EasyMock.expect(b.getSymbolicName()).andReturn("x.y.z");
+        EasyMock.replay(b);
+
+        BundleContext bc = EasyMock.createMock(BundleContext.class);
+        EasyMock.expect(bc.getBundle()).andReturn(b);
+        EasyMock.replay(bc);
+        
+        SPIBundleTracker sbt = new SPIBundleTracker(bc, new Activator());        
+
+        // This should not have any effect. Adding myself as a bundle.
+        sbt.addingBundle(b, null);
+        
+        EasyMock.verify(bc);
+    }
+}

Propchange: incubator/aries/trunk/spi-fly/src/test/java/org/apache/aries/spifly/SPIBundleTrackerTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/aries/trunk/spi-fly/src/test/java/org/apache/aries/spifly/SPIBundleTrackerTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/aries/trunk/spi-fly/src/test/resources/org/apache/aries/spifly/TestSPIBundle_1.0.0.jar
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/spi-fly/src/test/resources/org/apache/aries/spifly/TestSPIBundle_1.0.0.jar?rev=900421&view=auto
==============================================================================
Binary file - no diff available.

Propchange: incubator/aries/trunk/spi-fly/src/test/resources/org/apache/aries/spifly/TestSPIBundle_1.0.0.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: incubator/aries/trunk/spi-fly/src/test/resources/org/apache/aries/spifly/TestSPIBundle_src.zip
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/spi-fly/src/test/resources/org/apache/aries/spifly/TestSPIBundle_src.zip?rev=900421&view=auto
==============================================================================
Binary file - no diff available.

Propchange: incubator/aries/trunk/spi-fly/src/test/resources/org/apache/aries/spifly/TestSPIBundle_src.zip
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream



Mime
View raw message