You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by bd...@apache.org on 2009/08/14 14:17:29 UTC

svn commit: r804180 - in /sling/trunk/installer/osgi: installer/src/main/java/org/apache/sling/osgi/installer/ installer/src/main/java/org/apache/sling/osgi/installer/impl/ it/src/test/java/org/apache/sling/osgi/installer/it/

Author: bdelacretaz
Date: Fri Aug 14 12:17:29 2009
New Revision: 804180

URL: http://svn.apache.org/viewvc?rev=804180&view=rev
Log:
SLING-1078 - integration tests minimally adapted, still fail

Added:
    sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/OsgiInstallerTestBase.java
      - copied, changed from r804107, sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/OsgiControllerTestBase.java
Removed:
    sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/OsgiControllerTestBase.java
    sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/SimpleFileInstallableData.java
Modified:
    sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/InstallableResource.java
    sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/OsgiInstaller.java
    sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerImpl.java
    sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/BundleInstallTest.java
    sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/ConfigInstallTest.java

Modified: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/InstallableResource.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/InstallableResource.java?rev=804180&r1=804179&r2=804180&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/InstallableResource.java (original)
+++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/InstallableResource.java Fri Aug 14 12:17:29 2009
@@ -90,10 +90,6 @@
 	 * 	but the scheme must be the one used in the 
 	 * 	{@link OsgiInstaller#registerResources} call.
 	 */
-	public String getURL() {
-		return url;
-	}
-
 	public String getUrl() {
 		return url;
 	}

Modified: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/OsgiInstaller.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/OsgiInstaller.java?rev=804180&r1=804179&r2=804180&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/OsgiInstaller.java (original)
+++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/OsgiInstaller.java Fri Aug 14 12:17:29 2009
@@ -20,7 +20,6 @@
 
 import java.io.IOException;
 import java.util.Collection;
-import java.util.Map;
 
 /** OSGi Service that installs/updates/removes InstallableData
  * 	in the OSGi framework. 
@@ -33,7 +32,7 @@
  *	we might support deployment packages as well.    	
  */
 public interface OsgiInstaller {
-	
+    
 	/** Provide the installer with the complete list of installable
 	 * 	resources for a given client.
 	 * 
@@ -57,5 +56,11 @@
 	void removeResource(InstallableResource d) throws IOException;
 	
 	/** Return counters used for statistics, console display, testing, etc. */
-	Map<String, Long> getCounters();
+	long [] getCounters();
+	
+	/** Counter index: number of OSGi tasks executed */
+	int OSGI_TASKS_COUNTER = 0;
+	
+	/** Size of the counters array */
+	int COUNTERS_SIZE = 1;
 }
\ No newline at end of file

Modified: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerImpl.java?rev=804180&r1=804179&r2=804180&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerImpl.java (original)
+++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerImpl.java Fri Aug 14 12:17:29 2009
@@ -20,8 +20,6 @@
 
 import java.io.IOException;
 import java.util.Collection;
-import java.util.HashMap;
-import java.util.Map;
 
 import org.apache.sling.osgi.installer.InstallableResource;
 import org.apache.sling.osgi.installer.OsgiInstaller;
@@ -38,7 +36,7 @@
 	private final BundleContext bundleContext;
     private final PackageAdmin packageAdmin;
     private final ServiceTracker logServiceTracker;
-    private Map<String, Long> counters = new HashMap<String, Long>();
+    private long [] counters = new long[COUNTERS_SIZE];
 
     public OsgiInstallerImpl(final BundleContext bc,
                               final PackageAdmin pa,
@@ -97,7 +95,7 @@
 		return packageAdmin;
 	}
 	
-	public Map<String, Long> getCounters() {
+	public long [] getCounters() {
 		return counters;
 	}
 

Modified: sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/BundleInstallTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/BundleInstallTest.java?rev=804180&r1=804179&r2=804180&view=diff
==============================================================================
--- sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/BundleInstallTest.java (original)
+++ sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/BundleInstallTest.java Fri Aug 14 12:17:29 2009
@@ -17,14 +17,12 @@
 package org.apache.sling.osgi.installer.it;
 
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
 
-import org.apache.sling.osgi.installer.OsgiController;
-import org.apache.sling.osgi.installer.OsgiControllerStatistics;
+import org.apache.sling.osgi.installer.OsgiInstaller;
+import org.junit.AfterClass;
+import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.ops4j.pax.exam.Option;
@@ -32,13 +30,23 @@
 import org.osgi.framework.Bundle;
 
 @RunWith(JUnit4TestRunner.class)
-public class BundleInstallTest extends OsgiControllerTestBase {
+public class BundleInstallTest extends OsgiInstallerTestBase {
 
     @org.ops4j.pax.exam.junit.Configuration
     public static Option[] configuration() {
     	return defaultConfiguration();
     }
     
+    @Before
+    public void setUp() {
+        setupInstaller();
+    }
+    
+    @AfterClass
+    public void cleanup() {
+        super.cleanup();
+    }
+
 	@Test
     public void testInstallUpgradeDowngradeBundle() throws Exception {
     	final String symbolicName = "osgi-installer-testbundle";
@@ -49,24 +57,25 @@
     	
     	// Install first test bundle and check version
     	long bundleId = 0;
-    	final OsgiController c = getService(OsgiController.class);
     	{
-        	c.scheduleInstallOrUpdate(uri, new SimpleFileInstallableData(getTestBundle("org.apache.sling.osgi.installer.it-" + POM_VERSION + "-testbundle-1.1.jar")));
-        	assertNull("Test bundle must be absent right after scheduleInstallOrUpdate", findBundle(symbolicName));
-        	c.executeScheduledOperations();
-        	final Bundle b = findBundle(symbolicName);
-        	assertNotNull("Test bundle 1.1 must be found after executeScheduledOperations", b);
+            assertNull("Test bundle must be absent before installing", findBundle(symbolicName));
+    	    resetCounters();
+    	    installer.addResource(getInstallableResource(getTestBundle("org.apache.sling.osgi.installer.it-" + POM_VERSION + "-testbundle-1.1.jar")));
+    	    waitForInstallerAction(OsgiInstaller.OSGI_TASKS_COUNTER, 1);
+    	    final Bundle b = findBundle(symbolicName);
+        	assertNotNull("Test bundle 1.1 must be found after waitForInstallerAction", b);
         	bundleId = b.getBundleId();
         	assertEquals("Installed bundle must be started", Bundle.ACTIVE, b.getState());
         	assertEquals("Version must be 1.1", "1.1", b.getHeaders().get(BUNDLE_VERSION));
     	}
-    	
+
+    	/** TODO
     	// Upgrade to later version, verify
     	{
-        	c.scheduleInstallOrUpdate(uri, new SimpleFileInstallableData(getTestBundle("org.apache.sling.osgi.installer.it-" + POM_VERSION + "-testbundle-1.2.jar")));
+        	c.scheduleInstallOrUpdate(uri, new FileInstallableResource(getTestBundle("org.apache.sling.osgi.installer.it-" + POM_VERSION + "-testbundle-1.2.jar")));
         	c.executeScheduledOperations();
         	final Bundle b = findBundle(symbolicName);
-        	assertNotNull("Test bundle 1.2 must be found after executeScheduledOperations", b);
+        	assertNotNull("Test bundle 1.2 must be found after waitForInstallerAction", b);
         	assertEquals("Installed bundle must be started", Bundle.ACTIVE, b.getState());
         	assertEquals("Version must be 1.2 after upgrade", "1.2", b.getHeaders().get(BUNDLE_VERSION));
         	assertEquals("Bundle ID must not change after upgrade", bundleId, b.getBundleId());
@@ -74,10 +83,10 @@
     	
     	// Downgrade to lower version, installed bundle must not change
     	{
-        	c.scheduleInstallOrUpdate(uri, new SimpleFileInstallableData(getTestBundle("org.apache.sling.osgi.installer.it-" + POM_VERSION + "-testbundle-1.0.jar")));
-        	c.executeScheduledOperations();
+        	c.scheduleInstallOrUpdate(uri, new FileInstallableResource(getTestBundle("org.apache.sling.osgi.installer.it-" + POM_VERSION + "-testbundle-1.0.jar")));
+        	c.waitForInstallerAction();
         	final Bundle b = findBundle(symbolicName);
-        	assertNotNull("Test bundle 1.2 must be found after executeScheduledOperations", b);
+        	assertNotNull("Test bundle 1.2 must be found after waitForInstallerAction", b);
         	assertEquals("Installed bundle must be started", Bundle.ACTIVE, b.getState());
         	assertEquals("Version must be 1.2 after ignored downgrade", "1.2", b.getHeaders().get(BUNDLE_VERSION));
         	assertEquals("Bundle ID must not change after downgrade", bundleId, b.getBundleId());
@@ -86,37 +95,40 @@
     	// Uninstall
     	{
         	c.scheduleUninstall(uri);
-        	c.executeScheduledOperations();
+        	c.waitForInstallerAction();
         	final Bundle b = findBundle(symbolicName);
         	assertNull("Test bundle 1.2 must be gone", b);
     	}
     	
     	// Install lower version, must work
     	{
-        	c.scheduleInstallOrUpdate(uri, new SimpleFileInstallableData(getTestBundle("org.apache.sling.osgi.installer.it-" + POM_VERSION + "-testbundle-1.0.jar")));
-        	c.executeScheduledOperations();
+        	c.scheduleInstallOrUpdate(uri, new FileInstallableResource(getTestBundle("org.apache.sling.osgi.installer.it-" + POM_VERSION + "-testbundle-1.0.jar")));
+        	c.waitForInstallerAction();
         	final Bundle b = findBundle(symbolicName);
-        	assertNotNull("Test bundle 1.0 must be found after executeScheduledOperations", b);
+        	assertNotNull("Test bundle 1.0 must be found after waitForInstallerAction", b);
         	assertEquals("Installed bundle must be started", Bundle.ACTIVE, b.getState());
         	assertEquals("Version must be 1.0 after uninstall and downgrade", "1.0", b.getHeaders().get(BUNDLE_VERSION));
         	assertFalse("Bundle ID must have changed after uninstall and reinstall", bundleId == b.getBundleId());
     	}
+    	*/
     }
+	
+	/** TODO
     
     @Test
     public void testBundleStatePreserved() throws Exception {
-    	final OsgiController c = getService(OsgiController.class);
+    	final OsgiInstaller c = getService(OsgiInstaller.class);
     	
     	// Install two bundles, one started, one stopped
     	{
         	c.scheduleInstallOrUpdate("otherBundleA.jar", 
-        			new SimpleFileInstallableData(getTestBundle("org.apache.sling.osgi.installer.it-" + POM_VERSION + "-testA-1.0.jar")));
-        	c.executeScheduledOperations();
+        			new FileInstallableResource(getTestBundle("org.apache.sling.osgi.installer.it-" + POM_VERSION + "-testA-1.0.jar")));
+        	c.waitForInstallerAction();
     	}
     	{
         	c.scheduleInstallOrUpdate("testB.jar", 
-        			new SimpleFileInstallableData(getTestBundle("org.apache.sling.osgi.installer.it-" + POM_VERSION + "-testB-1.0.jar")));
-        	c.executeScheduledOperations();
+        			new FileInstallableResource(getTestBundle("org.apache.sling.osgi.installer.it-" + POM_VERSION + "-testB-1.0.jar")));
+        	c.waitForInstallerAction();
         	final Bundle b = findBundle("osgi-installer-testB");
         	assertNotNull("Test bundle must be found", b);
         	b.stop();
@@ -130,14 +142,14 @@
     	final String uri = symbolicName + JAR_EXT;
     	final String BUNDLE_VERSION = "Bundle-Version";
     	c.scheduleInstallOrUpdate(uri, 
-    			new SimpleFileInstallableData(getTestBundle("org.apache.sling.osgi.installer.it-" + POM_VERSION + "-testbundle-1.1.jar")));
-    	c.executeScheduledOperations();
+    			new FileInstallableResource(getTestBundle("org.apache.sling.osgi.installer.it-" + POM_VERSION + "-testbundle-1.1.jar")));
+    	c.waitForInstallerAction();
     	c.scheduleInstallOrUpdate(uri, 
-    			new SimpleFileInstallableData(getTestBundle("org.apache.sling.osgi.installer.it-" + POM_VERSION + "-testbundle-1.2.jar")));
-    	c.executeScheduledOperations();
+    			new FileInstallableResource(getTestBundle("org.apache.sling.osgi.installer.it-" + POM_VERSION + "-testbundle-1.2.jar")));
+    	c.waitForInstallerAction();
     	c.scheduleInstallOrUpdate(uri, 
-    			new SimpleFileInstallableData(getTestBundle("org.apache.sling.osgi.installer.it-" + POM_VERSION + "-testbundle-1.0.jar")));
-    	c.executeScheduledOperations();
+    			new FileInstallableResource(getTestBundle("org.apache.sling.osgi.installer.it-" + POM_VERSION + "-testbundle-1.0.jar")));
+    	c.waitForInstallerAction();
     	final Bundle b = findBundle(symbolicName);
     	assertNotNull("Installed bundle must be found", b);
     	assertEquals("Installed bundle must be started", Bundle.ACTIVE, b.getState());
@@ -152,7 +164,7 @@
 	// then testB, and verify that in the end needsB is started 	
     @Test
     public void testBundleDependencies() throws Exception {
-    	final OsgiController c = getService(OsgiController.class);
+    	final OsgiInstaller c = getService(OsgiInstaller.class);
     	
     	final String testB = "osgi-installer-testB";
     	final String needsB = "osgi-installer-needsB";
@@ -161,7 +173,7 @@
         	final Bundle b = findBundle(testB);
         	if(b != null) {
         		c.scheduleUninstall(testB + JAR_EXT);
-        		c.executeScheduledOperations();
+        		c.waitForInstallerAction();
         	}
         	assertNull(testB + " bundle must not be installed before test", findBundle(testB));
     	}
@@ -169,8 +181,8 @@
     	// without testB, needsB must not start
     	{
         	c.scheduleInstallOrUpdate(needsB + JAR_EXT,
-        			new SimpleFileInstallableData(getTestBundle("org.apache.sling.osgi.installer.it-" + POM_VERSION + "-needsB.jar")));
-        	c.executeScheduledOperations();
+        			new FileInstallableResource(getTestBundle("org.apache.sling.osgi.installer.it-" + POM_VERSION + "-needsB.jar")));
+        	c.waitForInstallerAction();
         	final Bundle b = findBundle(needsB);
         	assertNotNull(needsB + " must be installed", b);
         	assertFalse(needsB + " must not be started, testB not present", b.getState() == Bundle.ACTIVE);
@@ -182,15 +194,15 @@
     	
     	{
     	    long n = stats.getExecutedTasksCount();
-    	    c.executeScheduledOperations();
+    	    c.waitForInstallerAction();
             assertTrue("First retry must not wait for an event", stats.getExecutedTasksCount() > n);
             n = stats.getExecutedTasksCount();
-            c.executeScheduledOperations();
+            c.waitForInstallerAction();
     	    assertEquals("Retrying before a bundle event happens must not execute any OsgiControllerTask", n, stats.getExecutedTasksCount());
     	    
             n = stats.getExecutedTasksCount();
     	    generateBundleEvent();
-            c.executeScheduledOperations();
+            c.waitForInstallerAction();
             assertTrue("Retrying after a bundle event must execute at least one OsgiControllerTask", stats.getExecutedTasksCount() > n);
     	}
     	
@@ -199,7 +211,7 @@
             final long timeout = System.currentTimeMillis() + 2000L;
             while(System.currentTimeMillis() < timeout) {
                 final long n = stats.getExecutedTasksCount();
-                c.executeScheduledOperations();
+                c.waitForInstallerAction();
                 if(n == stats.getExecutedTasksCount()) {
                     break;
                 }
@@ -213,21 +225,22 @@
     	
         {
             long n = stats.getExecutedTasksCount();
-            c.executeScheduledOperations();
+            c.waitForInstallerAction();
             assertEquals("Retrying before a framework event happens must not execute any OsgiControllerTask", n, stats.getExecutedTasksCount());
             refreshPackages();
-            c.executeScheduledOperations();
+            c.waitForInstallerAction();
             assertTrue("Retrying after framework event must execute at least one OsgiControllerTask", stats.getExecutedTasksCount() > n);
         }
         
     	// now install testB -> needsB must start
     	{
         	c.scheduleInstallOrUpdate(testB + JAR_EXT,
-        			new SimpleFileInstallableData(getTestBundle("org.apache.sling.osgi.installer.it-" + POM_VERSION + "-testB-1.0.jar")));
-        	c.executeScheduledOperations();
+        			new FileInstallableResource(getTestBundle("org.apache.sling.osgi.installer.it-" + POM_VERSION + "-testB-1.0.jar")));
+        	c.waitForInstallerAction();
         	final Bundle b = findBundle(needsB);
         	assertNotNull(needsB + " must be installed", b);
         	assertTrue(needsB + " must be started now that testB is installed", b.getState() == Bundle.ACTIVE);
     	}
     }
+    */
 }

Modified: sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/ConfigInstallTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/ConfigInstallTest.java?rev=804180&r1=804179&r2=804180&view=diff
==============================================================================
--- sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/ConfigInstallTest.java (original)
+++ sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/ConfigInstallTest.java Fri Aug 14 12:17:29 2009
@@ -16,32 +16,26 @@
  */
 package org.apache.sling.osgi.installer.it;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-
-import java.util.Dictionary;
-import java.util.Hashtable;
-
-import org.apache.sling.osgi.installer.DictionaryInstallableData;
-import org.apache.sling.osgi.installer.OsgiController;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.ops4j.pax.exam.Option;
 import org.ops4j.pax.exam.junit.JUnit4TestRunner;
-import org.osgi.framework.Bundle;
-import org.osgi.service.cm.Configuration;
 
 @RunWith(JUnit4TestRunner.class)
-public class ConfigInstallTest extends OsgiControllerTestBase {
+public class ConfigInstallTest extends OsgiInstallerTestBase {
     @org.ops4j.pax.exam.junit.Configuration
     public static Option[] configuration() {
     	return defaultConfiguration();
     }
     
     @Test
+    public void TODOReactivateTests() {
+    }
+    
+    /**
+    @Test
     public void testInstallAndRemoveConfig() throws Exception {
-    	final OsgiController c = getService(OsgiController.class);
+    	final OsgiInstaller c = getService(OsgiInstaller.class);
     	final Dictionary<String, Object> cfgData = new Hashtable<String, Object>();
     	cfgData.put("foo", "bar");
     	final String cfgPid = getClass().getName() + "." + System.currentTimeMillis();
@@ -77,7 +71,7 @@
     	assertNotNull(cfgName + " bundle must be found", configAdmin);
     	waitForConfigAdmin(true);
     	
-    	final OsgiController c = getService(OsgiController.class);
+    	final OsgiInstaller c = getService(OsgiInstaller.class);
     	final Dictionary<String, Object> cfgData = new Hashtable<String, Object>();
     	cfgData.put("foo", "bar");
     	final String cfgPid = getClass().getName() + ".deferred." + System.currentTimeMillis();
@@ -99,5 +93,6 @@
     	assertNotNull("Config " + cfgPid + " must be installed after restarting ConfigAdmin", findConfiguration(cfgPid));
     	findConfiguration(cfgPid).delete();
     	assertNull("Config " + cfgPid + " must be gone after test", findConfiguration(cfgPid));
-    }    
+    }
+    */    
 }

Copied: sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/OsgiInstallerTestBase.java (from r804107, sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/OsgiControllerTestBase.java)
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/OsgiInstallerTestBase.java?p2=sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/OsgiInstallerTestBase.java&p1=sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/OsgiControllerTestBase.java&r1=804107&r2=804180&rev=804180&view=diff
==============================================================================
--- sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/OsgiControllerTestBase.java (original)
+++ sling/trunk/installer/osgi/it/src/test/java/org/apache/sling/osgi/installer/it/OsgiInstallerTestBase.java Fri Aug 14 12:17:29 2009
@@ -27,9 +27,13 @@
 
 import java.io.File;
 import java.io.FileInputStream;
+import java.io.IOException;
 import java.io.InputStream;
 
-import org.apache.sling.osgi.installer.OsgiControllerServices;
+import org.apache.sling.osgi.installer.InstallableResource;
+import org.apache.sling.osgi.installer.OsgiInstaller;
+import org.junit.Before;
+import org.junit.AfterClass;
 import org.ops4j.pax.exam.Inject;
 import org.ops4j.pax.exam.Option;
 import org.osgi.framework.Bundle;
@@ -40,16 +44,23 @@
 import org.osgi.service.cm.Configuration;
 import org.osgi.service.cm.ConfigurationAdmin;
 import org.osgi.service.packageadmin.PackageAdmin;
+import org.osgi.util.tracker.ServiceTracker;
 
-/** Base class for OsgiController testing */
-class OsgiControllerTestBase implements FrameworkListener {
+/** Base class for OsgiInstaller testing */
+class OsgiInstallerTestBase implements FrameworkListener {
 	public final static String POM_VERSION = System.getProperty("osgi.installer.pom.version");
 	public final static String JAR_EXT = ".jar";
 	private int packageRefreshEventsCount;
+	private ServiceTracker configAdminTracker;
+	protected OsgiInstaller installer;
+	private long [] counters;
+	public static final long WAIT_FOR_ACTION_TIMEOUT_MSEC = 5000;
 	
     @Inject
     protected BundleContext bundleContext;
     
+    public static final String URL_SCHEME = "OsgiInstallerTestBase://";
+    
     @SuppressWarnings("unchecked")
 	protected <T> T getService(Class<T> clazz) {
     	final ServiceReference ref = bundleContext.getServiceReference(clazz.getName());
@@ -59,6 +70,18 @@
     	return result;
     }
     
+    public void setupInstaller() {
+        installer = getService(OsgiInstaller.class);
+        resetCounters();
+    }
+    
+    public void cleanup() {
+        if(configAdminTracker != null) {
+            configAdminTracker.close();
+            configAdminTracker = null;
+        }
+    }
+    
     protected void generateBundleEvent() throws Exception {
         // install a bundle manually to generate a bundle event
         final File f = getTestBundle("org.apache.sling.osgi.installer.it-" + POM_VERSION + "-testbundle-1.0.jar");
@@ -142,12 +165,24 @@
     	return new File(System.getProperty("osgi.installer.base.dir"), bundleName);
     }
     
+    protected InstallableResource getInstallableResource(File testBundle) throws IOException {
+        final String url = URL_SCHEME + testBundle.getAbsolutePath();
+        final String digest = testBundle.getAbsolutePath() + testBundle.lastModified();
+        return new InstallableResource(url, new FileInputStream(testBundle), digest);
+    }
+    
     protected void waitForConfigAdmin(boolean shouldBePresent) throws InterruptedException {
-    	final OsgiControllerServices svc = getService(OsgiControllerServices.class);
+        if(configAdminTracker == null) {
+            synchronized (this) {
+                configAdminTracker = new ServiceTracker(bundleContext, ConfigurationAdmin.class.getName(), null);
+                configAdminTracker.open();
+            }
+        }
+        
     	final int timeout = 5;
     	final long waitUntil = System.currentTimeMillis() + (timeout * 1000L);
     	do {
-    		boolean isPresent = svc.getConfigurationAdmin() != null;
+    		boolean isPresent = configAdminTracker.getService() != null;
     		if(isPresent == shouldBePresent) {
     			return;
     		}
@@ -156,6 +191,35 @@
     	fail("ConfigurationAdmin service not available after waiting " + timeout + " seconds");
     }
     
+    protected void resetCounters() {
+        final long [] src = installer.getCounters();
+        counters = new long[src.length];
+        System.arraycopy(installer.getCounters(), 0, counters, 0, src.length);
+    }
+    
+    protected void sleep(long msec) {
+        try {
+            Thread.sleep(msec);
+        } catch(InterruptedException ignored) {
+        }
+    }
+    
+    protected void waitForInstallerAction(int counterType, long howMany) {
+        final long targetValue = counters[counterType] + howMany;
+        final long endTime = System.currentTimeMillis() + WAIT_FOR_ACTION_TIMEOUT_MSEC;
+        long lastValue = 0;
+        while(System.currentTimeMillis() < endTime) {
+            lastValue = installer.getCounters()[counterType]; 
+            if(lastValue >= targetValue) {
+                return;
+            }
+            sleep(10);
+        }
+        fail("waitForInstallerAction(" + counterType + "," + howMany 
+                + ") fails after " + WAIT_FOR_ACTION_TIMEOUT_MSEC + " msec"
+                + ", expected value " + targetValue + ", actual " + lastValue);
+    }
+    
     public static Option[] defaultConfiguration() {
     	String vmOpt = "-Dosgi.installer.testing";