You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2013/02/22 14:21:06 UTC
svn commit: r1449026 - in
/sling/trunk/installer/it/src/test/java/org/apache/sling/installer/it:
ConfigInstallTest.java OsgiInstallerTestBase.java
Author: cziegeler
Date: Fri Feb 22 13:21:06 2013
New Revision: 1449026
URL: http://svn.apache.org/r1449026
Log:
Rewrite test to be sure to use the correct config admin bundle
Modified:
sling/trunk/installer/it/src/test/java/org/apache/sling/installer/it/ConfigInstallTest.java
sling/trunk/installer/it/src/test/java/org/apache/sling/installer/it/OsgiInstallerTestBase.java
Modified: sling/trunk/installer/it/src/test/java/org/apache/sling/installer/it/ConfigInstallTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/it/src/test/java/org/apache/sling/installer/it/ConfigInstallTest.java?rev=1449026&r1=1449025&r2=1449026&view=diff
==============================================================================
--- sling/trunk/installer/it/src/test/java/org/apache/sling/installer/it/ConfigInstallTest.java (original)
+++ sling/trunk/installer/it/src/test/java/org/apache/sling/installer/it/ConfigInstallTest.java Fri Feb 22 13:21:06 2013
@@ -59,6 +59,7 @@ public class ConfigInstallTest extends O
serviceRegistration = bundleContext.registerService(ConfigurationListener.class.getName(), this, null);
}
+ @Override
@After
public void tearDown() {
super.tearDown();
@@ -108,43 +109,37 @@ public class ConfigInstallTest extends O
@Test
public void testDeferredConfigInstall() throws Exception {
-
- final String cfgName = "org.apache.felix.configadmin";
- Bundle configAdmin = null;
- // in some cases more than one config admin is installed!
- // therefore we just stopp all of them and restart the first one
- for(Bundle b : bundleContext.getBundles()) {
- if (b.getSymbolicName().equals(cfgName)) {
- configAdmin = b;
- break;
- }
- }
- assertNotNull(cfgName + " bundle must be found", configAdmin);
+ // get config admin bundle and wait for service
+ final Bundle configAdmin = this.getConfigAdminBundle();
+ assertNotNull("ConfigAdmin bundle must be found", configAdmin);
waitForConfigAdmin(true);
+ // check that configuration is not available
+ final String cfgPid = getClass().getSimpleName() + ".deferred." + System.currentTimeMillis();
+ assertNull("Config " + cfgPid + " must not be found before test", findConfiguration(cfgPid));
+ // create new configuration object
final Dictionary<String, Object> cfgData = new Hashtable<String, Object>();
cfgData.put("foo", "bar");
- final String cfgPid = getClass().getSimpleName() + ".deferred." + System.currentTimeMillis();
- assertNull("Config " + cfgPid + " must not be found before test", findConfiguration(cfgPid));
- // Config installs must be deferred if ConfigAdmin service is stopped
- for(Bundle b : bundleContext.getBundles()) {
- if (b.getSymbolicName().equals(cfgName)) {
- b.stop();
- }
- }
+ // Configuration installs must be deferred if ConfigAdmin service is stopped
+ configAdmin.stop();
waitForConfigAdmin(false);
+ // add new configuration
final InstallableResource[] rsrc = getInstallableResource(cfgPid, cfgData);
installer.updateResources(URL_SCHEME, rsrc, null);
+ // let's wait a little bit and restart configuration admin
sleep(1000L);
configAdmin.start();
waitForConfigAdmin(true);
waitForConfiguration("Config must be installed once ConfigurationAdmin restarts",
cfgPid, TIMEOUT, true);
+ // Configuration uninstalls must be deferred if ConfigAdmin service is stopped
configAdmin.stop();
waitForConfigAdmin(false);
+ // remove configuration
installer.updateResources(URL_SCHEME, null, new String[] {rsrc[0].getId()});
+ // let's wait a little bit and restart configuration admin
sleep(1000L);
configAdmin.start();
waitForConfigAdmin(true);
Modified: sling/trunk/installer/it/src/test/java/org/apache/sling/installer/it/OsgiInstallerTestBase.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/it/src/test/java/org/apache/sling/installer/it/OsgiInstallerTestBase.java?rev=1449026&r1=1449025&r2=1449026&view=diff
==============================================================================
--- sling/trunk/installer/it/src/test/java/org/apache/sling/installer/it/OsgiInstallerTestBase.java (original)
+++ sling/trunk/installer/it/src/test/java/org/apache/sling/installer/it/OsgiInstallerTestBase.java Fri Feb 22 13:21:06 2013
@@ -222,7 +222,7 @@ class OsgiInstallerTestBase implements F
}
protected Configuration waitForConfiguration(String info, String pid, long timeoutMsec, boolean shouldBePresent) throws Exception {
- if(info == null) {
+ if (info == null) {
info = "";
} else {
info += ": ";
@@ -242,9 +242,9 @@ class OsgiInstallerTestBase implements F
sleep(25);
} while(System.currentTimeMillis() < end);
- if(shouldBePresent && result == null) {
+ if (shouldBePresent && result == null) {
fail(info + "Configuration not found (" + pid + ")");
- } else if(!shouldBePresent && result != null) {
+ } else if (!shouldBePresent && result != null) {
fail(info + "Configuration is still present (" + pid + ")");
}
return result;
@@ -339,6 +339,11 @@ class OsgiInstallerTestBase implements F
return result;
}
+ protected Bundle getConfigAdminBundle() {
+ this.waitForConfigAdmin(true);
+ return this.configAdminTracker.getServiceReference().getBundle();
+ }
+
/**
* Helper method for sleeping.
*/