changeset 564:23f2ec2942c6

Tests for OSGiRegistry and friends. Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2012-August/002880.html Reviewed-by: sgehwolf
author Jon VanAlten <jon.vanalten@redhat.com>
date Wed, 22 Aug 2012 16:29:35 -0400
parents 51f768003f10
children 706785db6c08
files bundles/pom.xml bundles/src/main/java/com/redhat/thermostat/bundles/OSGiRegistry.java bundles/src/main/java/com/redhat/thermostat/bundles/OSGiRegistryService.java bundles/src/main/java/com/redhat/thermostat/bundles/impl/Activator.java bundles/src/main/java/com/redhat/thermostat/bundles/impl/OSGiRegistry.java bundles/src/main/java/com/redhat/thermostat/bundles/impl/OSGiRegistryImpl.java bundles/src/test/java/com/redhat/thermostat/bundles/OSGiRegistryTest.java bundles/src/test/java/com/redhat/thermostat/bundles/impl/OSGiRegistryImplTest.java launcher/src/main/java/com/redhat/thermostat/launcher/internal/Activator.java launcher/src/main/java/com/redhat/thermostat/launcher/internal/LauncherImpl.java launcher/src/test/java/com/redhat/thermostat/launcher/LauncherTest.java launcher/src/test/java/com/redhat/thermostat/launcher/internal/ActivatorTest.java main/src/main/java/com/redhat/thermostat/main/impl/FrameworkProvider.java main/src/test/java/com/redhat/thermostat/main/ThermostatTest.java
diffstat 14 files changed, 383 insertions(+), 199 deletions(-) [+]
line wrap: on
line diff
--- a/bundles/pom.xml	Wed Aug 22 16:28:44 2012 -0400
+++ b/bundles/pom.xml	Wed Aug 22 16:29:35 2012 -0400
@@ -114,4 +114,7 @@
     </plugins>
   </build>
 
+  <properties>
+    <argLine>-XX:-UseSplitVerifier</argLine>
+  </properties>
 </project>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bundles/src/main/java/com/redhat/thermostat/bundles/OSGiRegistry.java	Wed Aug 22 16:29:35 2012 -0400
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2012 Red Hat, Inc.
+ *
+ * This file is part of Thermostat.
+ *
+ * Thermostat is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published
+ * by the Free Software Foundation; either version 2, or (at your
+ * option) any later version.
+ *
+ * Thermostat is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Thermostat; see the file COPYING.  If not see
+ * <http://www.gnu.org/licenses/>.
+ *
+ * Linking this code with other modules is making a combined work
+ * based on this code.  Thus, the terms and conditions of the GNU
+ * General Public License cover the whole combination.
+ *
+ * As a special exception, the copyright holders of this code give
+ * you permission to link this code with independent modules to
+ * produce an executable, regardless of the license terms of these
+ * independent modules, and to copy and distribute the resulting
+ * executable under terms of your choice, provided that you also
+ * meet, for each linked independent module, the terms and conditions
+ * of the license of that module.  An independent module is a module
+ * which is not derived from or based on this code.  If you modify
+ * this code, you may extend this exception to your version of the
+ * library, but you are not obligated to do so.  If you do not wish
+ * to do so, delete this exception statement from your version.
+ */
+
+package com.redhat.thermostat.bundles;
+
+import java.io.IOException;
+import java.util.List;
+
+import org.osgi.framework.BundleException;
+import org.osgi.framework.launch.Framework;
+
+import com.redhat.thermostat.bundles.impl.BundleLoader;
+
+
+public abstract class OSGiRegistry {
+
+    public abstract void setPrintOSGiInfo(boolean printOSGiInfo);
+
+    public abstract void addBundlesFor(String commandName) throws BundleException, IOException;
+
+    public static void preLoadBundles(Framework framework, List<String> bundleLocations,
+            boolean printOSGiInfo) throws BundleException {
+        BundleLoader loader = new BundleLoader(printOSGiInfo);
+        loader.installAndStartBundles(framework, bundleLocations);
+    }
+
+}
--- a/bundles/src/main/java/com/redhat/thermostat/bundles/OSGiRegistryService.java	Wed Aug 22 16:28:44 2012 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,60 +0,0 @@
-/*
- * Copyright 2012 Red Hat, Inc.
- *
- * This file is part of Thermostat.
- *
- * Thermostat is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published
- * by the Free Software Foundation; either version 2, or (at your
- * option) any later version.
- *
- * Thermostat is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Thermostat; see the file COPYING.  If not see
- * <http://www.gnu.org/licenses/>.
- *
- * Linking this code with other modules is making a combined work
- * based on this code.  Thus, the terms and conditions of the GNU
- * General Public License cover the whole combination.
- *
- * As a special exception, the copyright holders of this code give
- * you permission to link this code with independent modules to
- * produce an executable, regardless of the license terms of these
- * independent modules, and to copy and distribute the resulting
- * executable under terms of your choice, provided that you also
- * meet, for each linked independent module, the terms and conditions
- * of the license of that module.  An independent module is a module
- * which is not derived from or based on this code.  If you modify
- * this code, you may extend this exception to your version of the
- * library, but you are not obligated to do so.  If you do not wish
- * to do so, delete this exception statement from your version.
- */
-
-package com.redhat.thermostat.bundles;
-
-import java.io.IOException;
-import java.util.List;
-
-import org.osgi.framework.BundleException;
-import org.osgi.framework.launch.Framework;
-
-import com.redhat.thermostat.bundles.impl.BundleLoader;
-
-
-public abstract class OSGiRegistryService {
-
-    public abstract void setPrintOSGiInfo(boolean printOSGiInfo);
-
-    public abstract void addBundlesFor(String commandName) throws BundleException, IOException;
-
-    public static void preLoadBundles(Framework framework, List<String> bundleLocations,
-            boolean printOSGiInfo) throws BundleException {
-        BundleLoader loader = new BundleLoader(printOSGiInfo);
-        loader.installAndStartBundles(framework, bundleLocations);
-    }
-
-}
--- a/bundles/src/main/java/com/redhat/thermostat/bundles/impl/Activator.java	Wed Aug 22 16:28:44 2012 -0400
+++ b/bundles/src/main/java/com/redhat/thermostat/bundles/impl/Activator.java	Wed Aug 22 16:29:35 2012 -0400
@@ -40,7 +40,7 @@
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceRegistration;
 
-import com.redhat.thermostat.bundles.OSGiRegistryService;
+import com.redhat.thermostat.bundles.OSGiRegistry;
 import com.redhat.thermostat.common.Configuration;
 
 public class Activator implements BundleActivator {
@@ -49,8 +49,8 @@
 
     @Override
     public void start(BundleContext context) throws Exception {
-        OSGiRegistry bundleRegistry = new OSGiRegistry(new Configuration());
-        reg = context.registerService(OSGiRegistryService.class.getName(), bundleRegistry, null);
+        OSGiRegistryImpl bundleRegistry = new OSGiRegistryImpl(new Configuration());
+        reg = context.registerService(OSGiRegistry.class.getName(), bundleRegistry, null);
     }
 
     @Override
--- a/bundles/src/main/java/com/redhat/thermostat/bundles/impl/OSGiRegistry.java	Wed Aug 22 16:28:44 2012 -0400
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,112 +0,0 @@
-/*
- * Copyright 2012 Red Hat, Inc.
- *
- * This file is part of Thermostat.
- *
- * Thermostat is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published
- * by the Free Software Foundation; either version 2, or (at your
- * option) any later version.
- *
- * Thermostat is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Thermostat; see the file COPYING.  If not see
- * <http://www.gnu.org/licenses/>.
- *
- * Linking this code with other modules is making a combined work
- * based on this code.  Thus, the terms and conditions of the GNU
- * General Public License cover the whole combination.
- *
- * As a special exception, the copyright holders of this code give
- * you permission to link this code with independent modules to
- * produce an executable, regardless of the license terms of these
- * independent modules, and to copy and distribute the resulting
- * executable under terms of your choice, provided that you also
- * meet, for each linked independent module, the terms and conditions
- * of the license of that module.  An independent module is a module
- * which is not derived from or based on this code.  If you modify
- * this code, you may extend this exception to your version of the
- * library, but you are not obligated to do so.  If you do not wish
- * to do so, delete this exception statement from your version.
- */
-
-package com.redhat.thermostat.bundles.impl;
-
-import com.redhat.thermostat.bundles.OSGiRegistryService;
-import com.redhat.thermostat.common.Configuration;
-import com.redhat.thermostat.common.ConfigurationException;
-
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleException;
-import org.osgi.framework.FrameworkUtil;
-import org.osgi.framework.launch.Framework;
-
-public class OSGiRegistry extends OSGiRegistryService {
-
-    private Map<String, Bundle> loaded;
-    private Configuration configuration;
-    private String thermostatHome;
-    private BundleProperties bundleProperties;
-    private BundleLoader loader;
-
-    OSGiRegistry(Configuration configuration) throws ConfigurationException, FileNotFoundException, IOException {
-        initLoadedBundles();
-        thermostatHome = configuration.getThermostatHome();
-        bundleProperties = new BundleProperties(thermostatHome);
-        this.configuration = configuration;
-        loader = new BundleLoader();
-    }
-
-    private void initLoadedBundles() {
-        loaded = new HashMap<>();
-        Framework framework = getFramework(this.getClass());
-        for (Bundle bundle: framework.getBundleContext().getBundles()) {
-            loaded.put(bundle.getLocation(), bundle);
-        }
-    }
-
-    @Override
-    public void setPrintOSGiInfo(boolean printOSGiInfo) {
-        configuration.setPrintOSGiInfo(printOSGiInfo);
-        loader.setPrintOSGiInfo(printOSGiInfo);
-    }
-
-    @Override
-    public void addBundlesFor(String commandName) throws BundleException, IOException {
-        Framework framework = getFramework(this.getClass());
-        if (configuration.getPrintOSGiInfo()) {
-            System.out.println("Loading additional bundles for: " + commandName);
-        }
-        List<String> requiredBundles = bundleProperties.getDependencyResourceNamesFor(commandName);
-        List<String> bundlesToLoad = new ArrayList<>();
-        for (String resource : requiredBundles) {
-            if (!isBundleActive(framework, resource)) {
-                bundlesToLoad.add(resource);
-            }
-        }
-        List<Bundle> successBundles = loader.installAndStartBundles(framework, bundlesToLoad);
-        for (Bundle bundle : successBundles) {
-            loaded.put(bundle.getLocation(), bundle);
-        }
-    }
-
-    private boolean isBundleActive(Framework framework, String location) {
-        Bundle bundle = loaded.get(location);
-        return (bundle != null) && bundle.getState() == Bundle.ACTIVE;
-    }
-
-    private Framework getFramework(Class<?> cls) {
-        return (Framework) FrameworkUtil.getBundle(cls).getBundleContext().getBundle(0);
-    }
-}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bundles/src/main/java/com/redhat/thermostat/bundles/impl/OSGiRegistryImpl.java	Wed Aug 22 16:29:35 2012 -0400
@@ -0,0 +1,112 @@
+/*
+ * Copyright 2012 Red Hat, Inc.
+ *
+ * This file is part of Thermostat.
+ *
+ * Thermostat is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published
+ * by the Free Software Foundation; either version 2, or (at your
+ * option) any later version.
+ *
+ * Thermostat is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Thermostat; see the file COPYING.  If not see
+ * <http://www.gnu.org/licenses/>.
+ *
+ * Linking this code with other modules is making a combined work
+ * based on this code.  Thus, the terms and conditions of the GNU
+ * General Public License cover the whole combination.
+ *
+ * As a special exception, the copyright holders of this code give
+ * you permission to link this code with independent modules to
+ * produce an executable, regardless of the license terms of these
+ * independent modules, and to copy and distribute the resulting
+ * executable under terms of your choice, provided that you also
+ * meet, for each linked independent module, the terms and conditions
+ * of the license of that module.  An independent module is a module
+ * which is not derived from or based on this code.  If you modify
+ * this code, you may extend this exception to your version of the
+ * library, but you are not obligated to do so.  If you do not wish
+ * to do so, delete this exception statement from your version.
+ */
+
+package com.redhat.thermostat.bundles.impl;
+
+import com.redhat.thermostat.bundles.OSGiRegistry;
+import com.redhat.thermostat.common.Configuration;
+import com.redhat.thermostat.common.ConfigurationException;
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.FrameworkUtil;
+import org.osgi.framework.launch.Framework;
+
+public class OSGiRegistryImpl extends OSGiRegistry {
+
+    private Map<String, Bundle> loaded;
+    private Configuration configuration;
+    private String thermostatHome;
+    private BundleProperties bundleProperties;
+    private BundleLoader loader;
+
+    OSGiRegistryImpl(Configuration configuration) throws ConfigurationException, FileNotFoundException, IOException {
+        initLoadedBundles();
+        thermostatHome = configuration.getThermostatHome();
+        bundleProperties = new BundleProperties(thermostatHome);
+        this.configuration = configuration;
+        loader = new BundleLoader(configuration.getPrintOSGiInfo());
+    }
+
+    private void initLoadedBundles() {
+        loaded = new HashMap<>();
+        Framework framework = getFramework(this.getClass());
+        for (Bundle bundle: framework.getBundleContext().getBundles()) {
+            loaded.put(bundle.getLocation(), bundle);
+        }
+    }
+
+    @Override
+    public void setPrintOSGiInfo(boolean printOSGiInfo) {
+        configuration.setPrintOSGiInfo(printOSGiInfo);
+        loader.setPrintOSGiInfo(printOSGiInfo);
+    }
+
+    @Override
+    public void addBundlesFor(String commandName) throws BundleException, IOException {
+        if (configuration.getPrintOSGiInfo()) {
+            System.out.println("Loading additional bundles for: " + commandName);
+        }
+        List<String> requiredBundles = bundleProperties.getDependencyResourceNamesFor(commandName);
+        List<String> bundlesToLoad = new ArrayList<>();
+        for (String resource : requiredBundles) {
+            if (!isBundleActive(resource)) {
+                bundlesToLoad.add(resource);
+            }
+        }
+        Framework framework = getFramework(this.getClass());
+        List<Bundle> successBundles = loader.installAndStartBundles(framework, bundlesToLoad);
+        for (Bundle bundle : successBundles) {
+            loaded.put(bundle.getLocation(), bundle);
+        }
+    }
+
+    private boolean isBundleActive(String location) {
+        Bundle bundle = loaded.get(location);
+        return (bundle != null) && (bundle.getState() == Bundle.ACTIVE);
+    }
+
+    private Framework getFramework(Class<?> cls) {
+        return (Framework) FrameworkUtil.getBundle(cls).getBundleContext().getBundle(0);
+    }
+}
--- a/bundles/src/test/java/com/redhat/thermostat/bundles/OSGiRegistryTest.java	Wed Aug 22 16:28:44 2012 -0400
+++ b/bundles/src/test/java/com/redhat/thermostat/bundles/OSGiRegistryTest.java	Wed Aug 22 16:29:35 2012 -0400
@@ -36,9 +36,34 @@
 
 package com.redhat.thermostat.bundles;
 
+import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.powermock.api.mockito.PowerMockito.whenNew;
+
+import java.util.ArrayList;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.osgi.framework.launch.Framework;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+import com.redhat.thermostat.bundles.impl.BundleLoader;
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest(OSGiRegistry.class)
 public class OSGiRegistryTest {
 
-    // TODO find a test for the new registry.
-    // Most of what this used to test is now in BundlePropertiesTest.
+    @Test
+    public void testPreLoadBundles() throws Exception {
+        Framework framework = mock(Framework.class);
+        ArrayList<String> bundleLocations = new ArrayList<>();
+        BundleLoader loader = mock(BundleLoader.class);
+        whenNew(BundleLoader.class).withParameterTypes(Boolean.TYPE).
+                withArguments(any()).thenReturn(loader);
 
+        OSGiRegistry.preLoadBundles(framework, bundleLocations, true);
+        verify(loader).installAndStartBundles(framework, bundleLocations);
+    }
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bundles/src/test/java/com/redhat/thermostat/bundles/impl/OSGiRegistryImplTest.java	Wed Aug 22 16:29:35 2012 -0400
@@ -0,0 +1,156 @@
+/*
+ * Copyright 2012 Red Hat, Inc.
+ *
+ * This file is part of Thermostat.
+ *
+ * Thermostat is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published
+ * by the Free Software Foundation; either version 2, or (at your
+ * option) any later version.
+ *
+ * Thermostat is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Thermostat; see the file COPYING.  If not see
+ * <http://www.gnu.org/licenses/>.
+ *
+ * Linking this code with other modules is making a combined work
+ * based on this code.  Thus, the terms and conditions of the GNU
+ * General Public License cover the whole combination.
+ *
+ * As a special exception, the copyright holders of this code give
+ * you permission to link this code with independent modules to
+ * produce an executable, regardless of the license terms of these
+ * independent modules, and to copy and distribute the resulting
+ * executable under terms of your choice, provided that you also
+ * meet, for each linked independent module, the terms and conditions
+ * of the license of that module.  An independent module is a module
+ * which is not derived from or based on this code.  If you modify
+ * this code, you may extend this exception to your version of the
+ * library, but you are not obligated to do so.  If you do not wish
+ * to do so, delete this exception statement from your version.
+ */
+
+package com.redhat.thermostat.bundles.impl;
+
+import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.anyString;
+import static org.mockito.Mockito.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.verify;
+import static org.powermock.api.mockito.PowerMockito.mockStatic;
+import static org.powermock.api.mockito.PowerMockito.whenNew;
+
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.FrameworkUtil;
+import org.osgi.framework.launch.Framework;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+import com.redhat.thermostat.common.Configuration;
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({OSGiRegistryImpl.class, FrameworkUtil.class})
+public class OSGiRegistryImplTest {
+
+    private static final String cmdName = "one";
+
+    private static final String jar1Name = "/one.jar";
+    private static final String jar2Name = "/two.jar";
+    private static final String jar3Name = "/three.jar";
+
+    private Bundle b1, b2, b3;
+    private List<String> bundleLocs;
+
+    private BundleLoader loader;
+    private BundleProperties bundleProps;
+    private Configuration conf;
+    
+    @Before
+    public void setUp() throws Exception {
+        conf = mock(Configuration.class);
+        when(conf.getThermostatHome()).thenReturn("no_matter");
+        bundleLocs = Arrays.asList(jar1Name, jar2Name, jar3Name);
+        b1 = mock(Bundle.class);
+        when(b1.getLocation()).thenReturn(jar1Name);
+        when(b1.getState()).thenReturn(Bundle.ACTIVE);
+        b2 = mock(Bundle.class);
+        when(b2.getLocation()).thenReturn(jar2Name);
+        when(b2.getState()).thenReturn(Bundle.ACTIVE);
+        b3 = mock(Bundle.class);
+        when(b3.getLocation()).thenReturn(jar3Name);
+        when(b3.getState()).thenReturn(Bundle.ACTIVE);
+        List<Bundle> installed = Arrays.asList(b1, b2, b3);
+        
+        bundleProps = mock(BundleProperties.class);
+        when(bundleProps.getDependencyResourceNamesFor(eq(cmdName))).
+                thenReturn(bundleLocs);
+        whenNew(BundleProperties.class).withParameterTypes(String.class).
+                withArguments(anyString()).thenReturn(bundleProps);
+        loader = mock(BundleLoader.class);
+        when(loader.installAndStartBundles(any(Framework.class), eq(bundleLocs))).
+                thenReturn(installed);
+        whenNew(BundleLoader.class).withParameterTypes(Boolean.TYPE).
+                withArguments(any()).thenReturn(loader);
+    }
+
+    @Test
+    public void testLoadBundlesFor() throws Exception {
+        verifyBundlesLoaded(new Bundle[] {}, bundleLocs);
+    }
+
+    @Test
+    public void verifyAlreadyLoadedBundlesNotReloaded() throws Exception {
+        verifyBundlesLoaded(new Bundle[] {b1, b2}, Arrays.asList(jar3Name));
+    }
+
+    private void verifyBundlesLoaded(Bundle[] preloaded, List<String> locationsNeeded) throws Exception {
+        Bundle theBundle = b2;
+        BundleContext theContext = mock(BundleContext.class);
+        when(theContext.getBundles()).thenReturn(preloaded);
+        Framework theFramework = mock(Framework.class);
+        when(theFramework.getBundleContext()).thenReturn(theContext);
+        when(theContext.getBundle(0)).thenReturn(theFramework);
+        when(theBundle.getBundleContext()).thenReturn(theContext);
+        mockStatic(FrameworkUtil.class);
+        when(FrameworkUtil.getBundle(any(Class.class))).thenReturn(theBundle);
+
+        OSGiRegistryImpl registry = new OSGiRegistryImpl(conf);
+        registry.addBundlesFor(cmdName);
+        verify(loader).installAndStartBundles(any(Framework.class), eq(locationsNeeded));
+    }
+
+    @Test
+    public void verifySetOSGiVerbosityByReflection() throws Exception {
+
+        // All this fluff is just so constructor doesn't NPE.
+        Bundle theBundle = b2;
+        BundleContext theContext = mock(BundleContext.class);
+        when(theContext.getBundles()).thenReturn(new Bundle[]{});
+        Framework theFramework = mock(Framework.class);
+        when(theFramework.getBundleContext()).thenReturn(theContext);
+        when(theContext.getBundle(0)).thenReturn(theFramework);
+        when(theBundle.getBundleContext()).thenReturn(theContext);
+        mockStatic(FrameworkUtil.class);
+        when(FrameworkUtil.getBundle(any(Class.class))).thenReturn(theBundle);
+
+        Object registry = new OSGiRegistryImpl(conf);
+        Class clazz = registry.getClass();
+        Method m = clazz.getMethod("setPrintOSGiInfo", Boolean.TYPE);
+        m.invoke(registry, true); // If this fails, then API has changed in ways that break FrameworkProvider.
+    }
+
+}
--- a/launcher/src/main/java/com/redhat/thermostat/launcher/internal/Activator.java	Wed Aug 22 16:28:44 2012 -0400
+++ b/launcher/src/main/java/com/redhat/thermostat/launcher/internal/Activator.java	Wed Aug 22 16:29:35 2012 -0400
@@ -42,7 +42,7 @@
 import org.osgi.framework.ServiceReference;
 import org.osgi.framework.ServiceRegistration;
 
-import com.redhat.thermostat.bundles.OSGiRegistryService;
+import com.redhat.thermostat.bundles.OSGiRegistry;
 import com.redhat.thermostat.common.CommandLoadingBundleActivator;
 import com.redhat.thermostat.common.MultipleServiceTracker;
 import com.redhat.thermostat.common.MultipleServiceTracker.Action;
@@ -62,8 +62,8 @@
         @Override
         public void doIt(Map<String, Object> services) {
             
-            ServiceReference reference = context.getServiceReference(OSGiRegistryService.class);
-            OSGiRegistryService bundleService = (OSGiRegistryService) context.getService(reference);
+            ServiceReference reference = context.getServiceReference(OSGiRegistry.class);
+            OSGiRegistry bundleService = (OSGiRegistry) context.getService(reference);
             LauncherImpl launcher = new LauncherImpl(context,
                     new CommandContextFactory(context), bundleService);
             launcherServiceRegistration = context.registerService(Launcher.class.getName(), launcher, null);
@@ -78,7 +78,7 @@
     @Override
     public void start(final BundleContext context) throws Exception {
         super.start(context);
-        tracker = new MultipleServiceTracker(context, new Class[] {OSGiRegistryService.class, Keyring.class}, new RegisterLauncherAction(context));
+        tracker = new MultipleServiceTracker(context, new Class[] {OSGiRegistry.class, Keyring.class}, new RegisterLauncherAction(context));
         tracker.open();
     }
 
--- a/launcher/src/main/java/com/redhat/thermostat/launcher/internal/LauncherImpl.java	Wed Aug 22 16:28:44 2012 -0400
+++ b/launcher/src/main/java/com/redhat/thermostat/launcher/internal/LauncherImpl.java	Wed Aug 22 16:29:35 2012 -0400
@@ -46,7 +46,7 @@
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.BundleException;
 
-import com.redhat.thermostat.bundles.OSGiRegistryService;
+import com.redhat.thermostat.bundles.OSGiRegistry;
 import com.redhat.thermostat.common.ActionListener;
 import com.redhat.thermostat.common.ActionNotifier;
 import com.redhat.thermostat.common.TimerFactory;
@@ -84,10 +84,10 @@
     private final Semaphore argsBarrier = new Semaphore(0);
 
     private BundleContext context;
-    private OSGiRegistryService registry;
+    private OSGiRegistry registry;
     
     public LauncherImpl(BundleContext context, CommandContextFactory cmdCtxFactory,
-            OSGiRegistryService registry) {
+            OSGiRegistry registry) {
         this.context = context;
         this.cmdCtxFactory = cmdCtxFactory;
         this.registry = registry;
--- a/launcher/src/test/java/com/redhat/thermostat/launcher/LauncherTest.java	Wed Aug 22 16:28:44 2012 -0400
+++ b/launcher/src/test/java/com/redhat/thermostat/launcher/LauncherTest.java	Wed Aug 22 16:29:35 2012 -0400
@@ -62,7 +62,7 @@
 import org.powermock.core.classloader.annotations.PrepareForTest;
 import org.powermock.modules.junit4.PowerMockRunner;
 
-import com.redhat.thermostat.bundles.OSGiRegistryService;
+import com.redhat.thermostat.bundles.OSGiRegistry;
 import com.redhat.thermostat.common.ActionListener;
 import com.redhat.thermostat.common.ActionNotifier;
 import com.redhat.thermostat.common.ApplicationInfo;
@@ -126,7 +126,7 @@
     private AppContextSetup appContextSetup;
     private BundleContext bundleContext;
     private TestTimerFactory timerFactory;
-    private OSGiRegistryService registry;
+    private OSGiRegistry registry;
     private ActionNotifier<ApplicationState> notifier;
 
     @Before
@@ -165,7 +165,7 @@
 
         ctxFactory.getCommandRegistry().registerCommands(Arrays.asList(new HelpCommand(), cmd1, cmd2, cmd3, basicCmd));
 
-        registry = mock(OSGiRegistryService.class);
+        registry = mock(OSGiRegistry.class);
     }
 
     private void setupCommandContextFactory() {
--- a/launcher/src/test/java/com/redhat/thermostat/launcher/internal/ActivatorTest.java	Wed Aug 22 16:28:44 2012 -0400
+++ b/launcher/src/test/java/com/redhat/thermostat/launcher/internal/ActivatorTest.java	Wed Aug 22 16:29:35 2012 -0400
@@ -60,7 +60,7 @@
 import org.powermock.core.classloader.annotations.PrepareForTest;
 import org.powermock.modules.junit4.PowerMockRunner;
 
-import com.redhat.thermostat.bundles.OSGiRegistryService;
+import com.redhat.thermostat.bundles.OSGiRegistry;
 import com.redhat.thermostat.common.MultipleServiceTracker;
 import com.redhat.thermostat.common.MultipleServiceTracker.Action;
 import com.redhat.thermostat.common.cli.Command;
@@ -76,7 +76,7 @@
     private MultipleServiceTracker tracker;
     private ServiceReference registryServiceReference, helpCommandReference;
     private ServiceRegistration launcherServiceRegistration, helpCommandRegistration;
-    private OSGiRegistryService registryService;
+    private OSGiRegistry registryService;
     private Command helpCommand;
 
     @Before
@@ -85,8 +85,8 @@
 
         registryServiceReference = mock(ServiceReference.class);
         launcherServiceRegistration = mock(ServiceRegistration.class);
-        registryService = mock(OSGiRegistryService.class);
-        when(context.getServiceReference(eq(OSGiRegistryService.class))).thenReturn(registryServiceReference);
+        registryService = mock(OSGiRegistry.class);
+        when(context.getServiceReference(eq(OSGiRegistry.class))).thenReturn(registryServiceReference);
         when(context.getService(eq(registryServiceReference))).thenReturn(registryService);
         when(context.registerService(eq(Launcher.class.getName()), any(), (Dictionary) isNull())).
                 thenReturn(launcherServiceRegistration);
@@ -103,7 +103,7 @@
         tracker = mock(MultipleServiceTracker.class);
         whenNew(MultipleServiceTracker.class).
                 withParameterTypes(BundleContext.class, Class[].class, Action.class).
-                withArguments(eq(context), eq(new Class[] {OSGiRegistryService.class, Keyring.class}),
+                withArguments(eq(context), eq(new Class[] {OSGiRegistry.class, Keyring.class}),
                         isA(Action.class)).thenReturn(tracker);
     }
 
@@ -119,7 +119,7 @@
 
         ArgumentCaptor<Action> actionCaptor = ArgumentCaptor.forClass(Action.class);
         verifyNew(MultipleServiceTracker.class).withArguments(eq(context),
-                eq(new Class[] {OSGiRegistryService.class, Keyring.class}),
+                eq(new Class[] {OSGiRegistry.class, Keyring.class}),
                 actionCaptor.capture());
         Action action = actionCaptor.getValue();
 
--- a/main/src/main/java/com/redhat/thermostat/main/impl/FrameworkProvider.java	Wed Aug 22 16:28:44 2012 -0400
+++ b/main/src/main/java/com/redhat/thermostat/main/impl/FrameworkProvider.java	Wed Aug 22 16:29:35 2012 -0400
@@ -59,7 +59,7 @@
 import org.osgi.framework.launch.FrameworkFactory;
 import org.osgi.util.tracker.ServiceTracker;
 
-import com.redhat.thermostat.bundles.OSGiRegistryService;
+import com.redhat.thermostat.bundles.OSGiRegistry;
 import com.redhat.thermostat.common.Configuration;
 import com.redhat.thermostat.common.ConfigurationException;
 import com.redhat.thermostat.launcher.Launcher;
@@ -221,11 +221,11 @@
                 locations.add(location);
             }
         }
-        OSGiRegistryService.preLoadBundles(framework, locations, printOSGiInfo);
+        OSGiRegistry.preLoadBundles(framework, locations, printOSGiInfo);
     }
 
     private void setLoaderVerbosity(Framework framework) throws InterruptedException {
-        Object loader = getService(framework, OSGiRegistryService.class.getName());
+        Object loader = getService(framework, OSGiRegistry.class.getName());
         callVoidReflectedMethod(loader, "setPrintOSGiInfo", printOSGiInfo, Boolean.TYPE);
     }
 
--- a/main/src/test/java/com/redhat/thermostat/main/ThermostatTest.java	Wed Aug 22 16:28:44 2012 -0400
+++ b/main/src/test/java/com/redhat/thermostat/main/ThermostatTest.java	Wed Aug 22 16:29:35 2012 -0400
@@ -58,7 +58,7 @@
 import org.powermock.core.classloader.annotations.PrepareForTest;
 import org.powermock.modules.junit4.PowerMockRunner;
 
-import com.redhat.thermostat.bundles.impl.OSGiRegistry;
+import com.redhat.thermostat.bundles.impl.OSGiRegistryImpl;
 import com.redhat.thermostat.common.Configuration;
 import com.redhat.thermostat.launcher.Launcher;
 import com.redhat.thermostat.launcher.internal.LauncherImpl;
@@ -76,8 +76,8 @@
     @Before
     public void setUp() throws Exception {
 
-        final OSGiRegistry osgiRegistry = mock(OSGiRegistry.class);
-        PowerMockito.whenNew(OSGiRegistry.class).withArguments(any(Configuration.class)).thenReturn(osgiRegistry);
+        final OSGiRegistryImpl osgiRegistry = mock(OSGiRegistryImpl.class);
+        PowerMockito.whenNew(OSGiRegistryImpl.class).withArguments(any(Configuration.class)).thenReturn(osgiRegistry);
 
         tempDir = Files.createTempDirectory("test");
         tempDir.toFile().deleteOnExit();