This is an automated email from the ASF dual-hosted git repository.
cziegeler pushed a commit to branch master
in repository
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-installer-it.git
The following commit(s) were added to refs/heads/master by this push:
new 5055dd0 SLING-7786 : Use R7 configuration admin supporting named
factory configurations. Add more tests
5055dd0 is described below
commit 5055dd0d610759b8b2b3df064f3154a4c14911c4
Author: Carsten Ziegeler <[email protected]>
AuthorDate: Wed Aug 8 13:13:24 2018 +0200
SLING-7786 : Use R7 configuration admin supporting named factory
configurations. Add more tests
---
pom.xml | 8 +-
.../sling/installer/it/ConfigUpdateTest.java | 190 ++++++++++++++++++++-
.../sling/installer/it/OsgiInstallerTestBase.java | 2 +-
3 files changed, 188 insertions(+), 12 deletions(-)
diff --git a/pom.xml b/pom.xml
index 81b4ef0..6be1e6d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -475,6 +475,10 @@
<scope>provided</scope>
</dependency>
<dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+ <dependency>
<groupId>org.ops4j.pax.exam</groupId>
<artifactId>pax-exam-container-native</artifactId>
<version>${exam.version}</version>
@@ -509,9 +513,5 @@
<version>5.6.1</version>
<scope>test</scope>
</dependency>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- </dependency>
</dependencies>
</project>
diff --git a/src/test/java/org/apache/sling/installer/it/ConfigUpdateTest.java
b/src/test/java/org/apache/sling/installer/it/ConfigUpdateTest.java
index 60452a3..9b43dfd 100644
--- a/src/test/java/org/apache/sling/installer/it/ConfigUpdateTest.java
+++ b/src/test/java/org/apache/sling/installer/it/ConfigUpdateTest.java
@@ -23,7 +23,6 @@ import java.util.Dictionary;
import java.util.Hashtable;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
-import static org.junit.Assert.*;
import org.apache.sling.installer.api.InstallableResource;
import org.apache.sling.installer.api.event.InstallationEvent;
@@ -34,6 +33,7 @@ import org.apache.sling.installer.api.info.Resource;
import org.apache.sling.installer.api.info.ResourceGroup;
import org.apache.sling.installer.api.tasks.ResourceState;
import org.apache.sling.installer.api.tasks.TaskResource;
+import static org.junit.Assert.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -46,7 +46,7 @@ import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceRegistration;
import org.osgi.service.cm.Configuration;
import org.osgi.service.cm.ConfigurationAdmin;
-
+
/**
* This test tests updating the configuration factory bundle from a pre 1.2.0
version to a 1.2.0+
* version which is using the support for named factory configurations of
Configuration Admin 1.6.0+.
@@ -115,7 +115,11 @@ public class ConfigUpdateTest extends
OsgiInstallerTestBase {
return new InstallableResource[] {rsrc};
}
- private void assertConfig(final String name, final boolean checkNew)
throws Exception {
+ private Configuration assertConfig(final String name, final boolean
checkNew) throws Exception {
+ return assertConfig(name, checkNew, checkNew);
+ }
+
+ private Configuration assertConfig(final String name, final boolean
checkNew, final boolean modifiedExists) throws Exception {
final ConfigurationAdmin ca =
this.getService(ConfigurationAdmin.class);
final Configuration[] cfgs = ca.listConfigurations("(&(" +
ConfigurationAdmin.SERVICE_FACTORYPID + "=" + FACTORY_PID + ")" +
"(id=" + name + "))");
@@ -129,7 +133,6 @@ public class ConfigUpdateTest extends OsgiInstallerTestBase
{
assertFalse(c.getPid().equals(FACTORY_PID + "~" + name));
final Configuration[] cfgs1 = ca.listConfigurations("(" +
Constants.SERVICE_PID + "=" + FACTORY_PID + "~" + name + ")");
assertTrue(cfgs1 == null || cfgs1.length == 0);
- assertNull(c.getProperties().get("modified"));
}
if ( checkNew) {
final Configuration[] cfgs1 = ca.listConfigurations("(" +
Constants.SERVICE_PID + "=" + FACTORY_PID + "~" + name + ")");
@@ -139,9 +142,17 @@ public class ConfigUpdateTest extends
OsgiInstallerTestBase {
assertEquals("value", c1.getProperties().get("key"));
assertEquals(name, c1.getProperties().get("id"));
assertEquals(FACTORY_PID, c1.getFactoryPid());
- assertEquals(Boolean.TRUE, c.getProperties().get("modified"));
+ assertEquals(c.getPid(), c1.getPid());
}
-
+ if ( modifiedExists ) {
+ assertEquals(Boolean.TRUE, c.getProperties().get("modified"));
+ } else {
+ assertNull(c.getProperties().get("modified"));
+ }
+ return c;
+ }
+
+ private void assertInstallerState(final String name, final boolean
checkNew, final ResourceState expectedState) throws Exception {
// make sure there is only one state in the OSGi installer
final InfoProvider infoProvider = getService(InfoProvider.class);
ResourceGroup found = null;
@@ -156,7 +167,7 @@ public class ConfigUpdateTest extends OsgiInstallerTestBase
{
if ( found != null ) {
break;
}
- }
+ }
assertNotNull(found);
assertEquals(1, found.getResources().size());
final Resource r = found.getResources().get(0);
@@ -165,6 +176,7 @@ public class ConfigUpdateTest extends OsgiInstallerTestBase
{
} else {
assertEquals("config:" + FACTORY_PID + "." + name,
r.getEntityId());
}
+ assertEquals(expectedState, r.getState());
}
@Override
@@ -199,10 +211,12 @@ public class ConfigUpdateTest extends
OsgiInstallerTestBase {
}
// check for configuration
assertConfig(NAME_1, false);
+ assertInstallerState(NAME_1, false, ResourceState.INSTALLED);
updateConfigFactoryBundle();
assertConfig(NAME_1, false);
+ assertInstallerState(NAME_1, false, ResourceState.INSTALLED);
}
/**
@@ -223,6 +237,7 @@ public class ConfigUpdateTest extends OsgiInstallerTestBase
{
}
// check for configuration
assertConfig(NAME_1, false);
+ assertInstallerState(NAME_1, false, ResourceState.INSTALLED);
}
/**
@@ -246,6 +261,7 @@ public class ConfigUpdateTest extends OsgiInstallerTestBase
{
}
// check for configuration
assertConfig(NAME_1, true);
+ assertInstallerState(NAME_1, true, ResourceState.INSTALLED);
}
/**
@@ -269,6 +285,166 @@ public class ConfigUpdateTest extends
OsgiInstallerTestBase {
}
// check for configuration
assertConfig(NAME_1, true);
+ assertInstallerState(NAME_1, true, ResourceState.INSTALLED);
+ }
+
+ /**
+ * This test does
+ * - install a factory configuration
+ * - update the configuration factory bundle
+ * - manual update of that configuration through config admin
+ */
+ @Test public void testManualUpdateWithoutConversion() throws Exception {
+ testBundleUpdate();
+
+ final ConfigurationAdmin ca = this.waitForConfigAdmin(true);
+ final Configuration[] cfgs = ca.listConfigurations("(&(" +
ConfigurationAdmin.SERVICE_FACTORYPID + "=" + FACTORY_PID + ")" +
+ "(id=" + NAME_1 + "))");
+ // we know it's just one config
+ final Configuration c = cfgs[0];
+ final Dictionary<String, Object> props = c.getProperties();
+ props.put("another", "helloworld");
+ c.update(props);
+
+ // the update is processed async, so we should give the installer
parts some time to process
+ this.sleep(5000); // TODO - Can we wait for an event instead?
+
+ final Configuration cUp = assertConfig(NAME_1, true, false);
+ assertEquals("helloworld", cUp.getProperties().get("another"));
+ assertInstallerState(NAME_1, true, ResourceState.IGNORED);
+ }
+
+ /**
+ * This test does
+ * - install a factory configuration
+ * - update the configuration factory bundle
+ * - manual delete of that configuration through config admin
+ */
+ /*@Test*/ public void testManualDeleteWithoutConversion() throws Exception
{
+ testBundleUpdate();
+
+ final ConfigurationAdmin ca = this.waitForConfigAdmin(true);
+ final Configuration[] cfgs = ca.listConfigurations("(&(" +
ConfigurationAdmin.SERVICE_FACTORYPID + "=" + FACTORY_PID + ")" +
+ "(id=" + NAME_1 + "))");
+ // we know it's just one config
+ final Configuration c = cfgs[0];
+ c.delete();
+
+ // the update is processed async, so we should give the installer
parts some time to process
+ this.sleep(5000); // TODO - Can we wait for an event instead?
+
+ // config should be deleted
+ final Configuration[] cfgs2 = ca.listConfigurations("(&(" +
ConfigurationAdmin.SERVICE_FACTORYPID + "=" + FACTORY_PID + ")" +
+ "(id=" + NAME_1 + "))");
+ assertTrue(cfgs2 == null || cfgs2.length == 0);
+ // state should be ignored
+ assertInstallerState(NAME_1, true, ResourceState.IGNORED);
+ }
+
+ /**
+ * This test does
+ * - install a factory configuration
+ * - update the configuration factory bundle
+ * - manual update of that configuration through config admin
+ * - manual delete of that configuration through config admin
+ */
+ /*@Test*/ public void testManualUpdateAndDeleteWithoutConversion() throws
Exception {
+ testManualUpdateWithoutConversion();
+
+ final ConfigurationAdmin ca = this.waitForConfigAdmin(true);
+ final Configuration[] cfgs = ca.listConfigurations("(&(" +
ConfigurationAdmin.SERVICE_FACTORYPID + "=" + FACTORY_PID + ")" +
+ "(id=" + NAME_1 + "))");
+ // we know it's just one config
+ final Configuration c = cfgs[0];
+ c.delete();
+
+ // the update is processed async, so we should give the installer
parts some time to process
+ this.sleep(5000); // TODO - Can we wait for an event instead?
+
+ // config should be reverted
+ assertConfig(NAME_1, true);
+ assertInstallerState(NAME_1, true, ResourceState.INSTALLED);
+ }
+
+ /**
+ * This test does
+ * - install a factory configuration
+ * - update the configuration factory bundle
+ * - update the configuration through the installer (convert)
+ * - manual update of that configuration through config admin
+ */
+ @Test public void testManualUpdateAfterConversion() throws Exception {
+ testBundleAndConfigUpdateWithChange();
+
+ final ConfigurationAdmin ca = this.waitForConfigAdmin(true);
+ final Configuration[] cfgs = ca.listConfigurations("(&(" +
ConfigurationAdmin.SERVICE_FACTORYPID + "=" + FACTORY_PID + ")" +
+ "(id=" + NAME_1 + "))");
+ // we know it's just one config
+ final Configuration c = cfgs[0];
+ final Dictionary<String, Object> props = c.getProperties();
+ props.put("another", "helloworld");
+ c.update(props);
+
+ // the update is processed async, so we should give the installer
parts some time to process
+ this.sleep(5000); // TODO - Can we wait for an event instead?
+
+ final Configuration cUp = assertConfig(NAME_1, true);
+ assertEquals("helloworld", cUp.getProperties().get("another"));
+ assertInstallerState(NAME_1, true, ResourceState.IGNORED);
+ }
+
+ /**
+ * This test does
+ * - install a factory configuration
+ * - update the configuration factory bundle
+ * - update the configuration through the installer (convert)
+ * - manual delete of that configuration through config admin
+ */
+ @Test public void testManualDeleteAfterConversion() throws Exception {
+ testBundleAndConfigUpdateWithChange();
+
+ final ConfigurationAdmin ca = this.waitForConfigAdmin(true);
+ final Configuration[] cfgs = ca.listConfigurations("(&(" +
ConfigurationAdmin.SERVICE_FACTORYPID + "=" + FACTORY_PID + ")" +
+ "(id=" + NAME_1 + "))");
+ // we know it's just one config
+ final Configuration c = cfgs[0];
+ c.delete();
+
+ // the update is processed async, so we should give the installer
parts some time to process
+ this.sleep(5000); // TODO - Can we wait for an event instead?
+
+ // config should be deleted
+ final Configuration[] cfgs2 = ca.listConfigurations("(&(" +
ConfigurationAdmin.SERVICE_FACTORYPID + "=" + FACTORY_PID + ")" +
+ "(id=" + NAME_1 + "))");
+ assertTrue(cfgs2 == null || cfgs2.length == 0);
+ // state should be ignored
+ assertInstallerState(NAME_1, true, ResourceState.IGNORED);
+ }
+
+ /**
+ * This test does
+ * - install a factory configuration
+ * - update the configuration factory bundle
+ * - update the configuration through the installer (convert)
+ * - manual update of that configuration through config admin
+ * - manual delete of that configuration through config admin
+ */
+ @Test public void testManualUpdateAndDeleteAfterConversion() throws
Exception {
+ testManualUpdateAfterConversion();
+
+ final ConfigurationAdmin ca = this.waitForConfigAdmin(true);
+ final Configuration[] cfgs = ca.listConfigurations("(&(" +
ConfigurationAdmin.SERVICE_FACTORYPID + "=" + FACTORY_PID + ")" +
+ "(id=" + NAME_1 + "))");
+ // we know it's just one config
+ final Configuration c = cfgs[0];
+ c.delete();
+
+ // the update is processed async, so we should give the installer
parts some time to process
+ this.sleep(5000); // TODO - Can we wait for an event instead?
+
+ // config should be reverted
+ assertConfig(NAME_1, true);
+ assertInstallerState(NAME_1, true, ResourceState.INSTALLED);
}
private class ResourceInstallationListener implements InstallationListener
{
diff --git
a/src/test/java/org/apache/sling/installer/it/OsgiInstallerTestBase.java
b/src/test/java/org/apache/sling/installer/it/OsgiInstallerTestBase.java
index da6eaec..eea82a0 100644
--- a/src/test/java/org/apache/sling/installer/it/OsgiInstallerTestBase.java
+++ b/src/test/java/org/apache/sling/installer/it/OsgiInstallerTestBase.java
@@ -505,7 +505,7 @@ public class OsgiInstallerTestBase implements
FrameworkListener {
mavenBundle("org.slf4j", "log4j-over-slf4j", "1.7.5"),
mavenBundle("org.apache.felix",
"org.apache.felix.scr", "2.1.0"),
- mavenBundle("org.apache.felix",
"org.apache.felix.configadmin", "1.9.2"),
+ mavenBundle("org.apache.felix",
"org.apache.felix.configadmin", "1.9.4"),
mavenBundle("org.apache.felix",
"org.apache.felix.metatype", "1.2.0"),
mavenBundle("org.apache.sling",
"org.apache.sling.installer.core", POM_VERSION).startLevel(5),
mavenBundle("org.apache.sling",
"org.apache.sling.installer.factory.configuration",
CONFIG_VERSION).startLevel(5)