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 32fe5a6 SLING-7786 : Use R7 configuration admin supporting named
factory configurations
32fe5a6 is described below
commit 32fe5a698db2aec8132f994901cf6e202f271ffd
Author: Carsten Ziegeler <[email protected]>
AuthorDate: Mon Aug 13 18:30:26 2018 +0200
SLING-7786 : Use R7 configuration admin supporting named factory
configurations
---
.../sling/installer/it/ConfigUpdateTest.java | 77 +++++++++++++++---
.../sling/installer/it/ConfigUpdateTestUtil.java | 94 ++++++++++++++++++----
2 files changed, 145 insertions(+), 26 deletions(-)
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 6666a39..a16f9fa 100644
--- a/src/test/java/org/apache/sling/installer/it/ConfigUpdateTest.java
+++ b/src/test/java/org/apache/sling/installer/it/ConfigUpdateTest.java
@@ -69,7 +69,10 @@ public class ConfigUpdateTest extends OsgiInstallerTestBase {
}
/**
- * Simply updating the bundle should not change anything
+ * - Install test factory config
+ * - verify property installation in configadmin and proper state in
installer
+ * - update installer config factory (update->convert)
+ * - verify updated factory config and proper state in installer
*/
@Test public void testBundleUpdate() throws Exception {
this.util.installTestConfigs();
@@ -80,12 +83,17 @@ public class ConfigUpdateTest extends OsgiInstallerTestBase
{
this.util.updateConfigFactoryBundle();
- this.util.assertTestConfig(ConfigUpdateTestUtil.NAME_1, false);
- this.util.assertInstallerState(ConfigUpdateTestUtil.NAME_1, false,
ResourceState.INSTALLED);
+ this.util.assertTestConfig(ConfigUpdateTestUtil.NAME_1, true, false);
+ this.util.assertInstallerState(ConfigUpdateTestUtil.NAME_1, true,
ResourceState.INSTALLED);
}
/**
- * Simply updating the bundle and then updating the config with the same
contents should not change anything
+ * - Install test factory config
+ * - verify property installation in configadmin and proper state in
installer
+ * - update installer config factory (update->convert)
+ * - verify updated factory config and proper state in installer
+ * - update factory config with same contents (no changes)
+ * - verify property installation in configadmin and proper state in
installer
*/
@Test public void testBundleAndConfigRegisterWithoutChange() throws
Exception {
this.testBundleUpdate();
@@ -94,12 +102,17 @@ public class ConfigUpdateTest extends
OsgiInstallerTestBase {
this.util.installTestConfigs();
// check for configuration
- this.util.assertTestConfig(ConfigUpdateTestUtil.NAME_1, false);
- this.util.assertInstallerState(ConfigUpdateTestUtil.NAME_1, false,
ResourceState.INSTALLED);
+ this.util.assertTestConfig(ConfigUpdateTestUtil.NAME_1, true, false);
+ this.util.assertInstallerState(ConfigUpdateTestUtil.NAME_1, true,
ResourceState.INSTALLED);
}
/**
- * Updating the bundle and then updating the config with a new config
should convert the configurations
+ * - Install test factory config
+ * - verify property installation in configadmin and proper state in
installer
+ * - update installer config factory (update->convert)
+ * - verify updated factory config and proper state in installer
+ * - update factory config with new contents using register method
+ * - verify property installation in configadmin and proper state in
installer
*/
@Test public void testBundleAndConfigRegisterWithChange() throws Exception
{
this.testBundleUpdate();
@@ -113,7 +126,12 @@ public class ConfigUpdateTest extends
OsgiInstallerTestBase {
}
/**
- * Updating the bundle and then updating the config with a new config
should convert the configurations
+ * - Install test factory config
+ * - verify property installation in configadmin and proper state in
installer
+ * - update installer config factory (update->convert)
+ * - verify updated factory config and proper state in installer
+ * - update factory config with new contents using update metho
+ * - verify property installation in configadmin and proper state in
installer
*/
@Test public void testBundleAndConfigUpdateWithChange() throws Exception {
this.testBundleUpdate();
@@ -127,10 +145,10 @@ public class ConfigUpdateTest extends
OsgiInstallerTestBase {
}
/**
- * This test does
- * - install a factory configuration
- * - update the configuration factory bundle
- * - manual update of that configuration through config admin
+ * This test
+ * - installs a factory configuration
+ * - updates the configuration factory bundle
+ * - manual updates of that configuration through config admin
*/
@Test public void testManualUpdateWithoutConversion() throws Exception {
this.testBundleUpdate();
@@ -333,4 +351,39 @@ public class ConfigUpdateTest extends
OsgiInstallerTestBase {
// and no installer state
this.util.assertInstallerState(ConfigUpdateTestUtil.MANUAL_FACTORY_PID, 0);
}
+
+ /**
+ * This test does
+ * - install a factory configuration and an overlay
+ * - update the configuration factory bundle
+ * - update the factory configuration (no change)
+ * - update the overlay factory configuration (change)
+ * - delete the overlay factory configuration (change)
+ */
+ @Test public void testConfigurationOverlays() throws Exception {
+ // install factory configuration and overlay
+ this.util.installTestConfigs();
+ this.util.installOverlayTestConfigs();
+
+ // check for overlay configuration being active
+ final Configuration c1 =
this.util.assertTestConfig(ConfigUpdateTestUtil.NAME_1, false);
+ assertEquals(Boolean.TRUE, c1.getProperties().get("overlay"));
+ this.util.assertOverlayInstallerState(ConfigUpdateTestUtil.NAME_1,
false, ResourceState.INSTALLED);
+
+ // update factory configuration bundle
+ this.util.updateConfigFactoryBundle();
+
+ // check for overlay configuration being active - using named factories
+ final Configuration c2 =
this.util.assertTestConfig(ConfigUpdateTestUtil.NAME_1, true, false);
+ assertEquals(Boolean.TRUE, c2.getProperties().get("overlay"));
+ this.util.assertOverlayInstallerState(ConfigUpdateTestUtil.NAME_1,
true, ResourceState.INSTALLED);
+
+ // update the factory configuration (no change!)
+ this.util.installModifiedTestConfigs(false);
+
+ // check for overlay configuration being active - using named factories
+ final Configuration c3 =
this.util.assertTestConfig(ConfigUpdateTestUtil.NAME_1, true, false);
+ assertEquals(Boolean.TRUE, c3.getProperties().get("overlay"));
+ this.util.assertOverlayInstallerState(ConfigUpdateTestUtil.NAME_1,
true, ResourceState.INSTALLED);
+ }
}
diff --git
a/src/test/java/org/apache/sling/installer/it/ConfigUpdateTestUtil.java
b/src/test/java/org/apache/sling/installer/it/ConfigUpdateTestUtil.java
index 29374c1..7608dff 100644
--- a/src/test/java/org/apache/sling/installer/it/ConfigUpdateTestUtil.java
+++ b/src/test/java/org/apache/sling/installer/it/ConfigUpdateTestUtil.java
@@ -16,8 +16,6 @@
*/
package org.apache.sling.installer.it;
-import static org.junit.Assert.*;
-
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
@@ -25,7 +23,7 @@ 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.OsgiInstaller;
import org.apache.sling.installer.api.event.InstallationEvent;
@@ -35,6 +33,7 @@ import org.apache.sling.installer.api.info.InstallationState;
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.ResourceTransformer;
import org.apache.sling.installer.api.tasks.TaskResource;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
@@ -44,6 +43,7 @@ import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceRegistration;
import org.osgi.service.cm.Configuration;
import org.osgi.service.cm.ConfigurationAdmin;
+import org.osgi.util.tracker.ServiceTracker;
/**
* Utility methods for {@link ConfigUpdateTest}.
@@ -61,6 +61,8 @@ public class ConfigUpdateTestUtil {
public static final String SCHEME = "myscheme";
+ public static final String OVERLAY_SCHEME = "overlay";
+
private final BundleContext bundleContext;
private ConfigurationAdmin configAdmin;
@@ -68,7 +70,7 @@ public class ConfigUpdateTestUtil {
private InfoProvider infoProvider;
private OsgiInstaller installer;
-
+
public ConfigUpdateTestUtil(final BundleContext ctx) throws Exception {
this.bundleContext = ctx;
// we need the old config factory first
@@ -82,8 +84,8 @@ public class ConfigUpdateTestUtil {
b.start();
}
- public void init(final ConfigurationAdmin configAdmin,
- final OsgiInstaller installer,
+ public void init(final ConfigurationAdmin configAdmin,
+ final OsgiInstaller installer,
final InfoProvider infoProvider) {
this.configAdmin = configAdmin;
this.installer = installer;
@@ -118,16 +120,28 @@ public class ConfigUpdateTestUtil {
b.update(is);
}
b.start();
+ // wait for resource transformer to be registered
+ final ServiceTracker<ResourceTransformer, ResourceTransformer> tracker
= new ServiceTracker<>(bundleContext,
+ bundleContext.createFilter("(&(" + Constants.OBJECTCLASS + "="
+ ResourceTransformer.class.getName() + ")" +
+ "(" + ResourceTransformer.NAME +
"=org.osgi.service.cm))"),
+ null);
+ tracker.open();
+ tracker.waitForService(10000);
+ tracker.close();
}
public InstallableResource[] createTestConfigResources() {
+ return createTestConfigResources(null);
+ }
+
+ public InstallableResource[] createTestConfigResources(final Integer prio)
{
final Dictionary<String, Object> props = new Hashtable<>();
props.put("key", "value");
props.put("id", NAME_1);
// we need to specify a path as config factory < 1.2.0 has a bug in
handling the id if a path is missing
final InstallableResource rsrc = new InstallableResource("configs/" +
FACTORY_PID + "-" + NAME_1 + ".cfg",
- null, props, "1", InstallableResource.TYPE_CONFIG, null);
+ null, props, "1", InstallableResource.TYPE_CONFIG, prio);
return new InstallableResource[] {rsrc};
}
@@ -145,6 +159,22 @@ public class ConfigUpdateTestUtil {
}
}
+ public void installOverlayTestConfigs() {
+ final InstallableResource[] resources = createTestConfigResources(200);
+ for(final InstallableResource rsrc : resources) {
+ rsrc.getDictionary().put("overlay", Boolean.TRUE);
+ }
+ final ResourceInstallationListener listener = new
ResourceInstallationListener(OVERLAY_SCHEME, resources.length);
+ final ServiceRegistration<InstallationListener> reg =
this.bundleContext.registerService(InstallationListener.class, listener, null);
+ try {
+ installer.registerResources(OVERLAY_SCHEME, resources);
+
+ listener.waitForInstall();
+ } finally {
+ reg.unregister();
+ }
+ }
+
public void installModifiedTestConfigs(final boolean useRegister) {
final InstallableResource[] resources = createTestConfigResources();
for(final InstallableResource rsrc : resources) {
@@ -161,9 +191,9 @@ public class ConfigUpdateTestUtil {
listener.waitForInstall();
} finally {
reg.unregister();
- }
+ }
}
-
+
public Configuration assertTestConfig(final String name, final boolean
checkNew) throws Exception {
return assertTestConfig(name, checkNew, checkNew);
}
@@ -200,7 +230,37 @@ public class ConfigUpdateTestUtil {
return c;
}
- public void assertInstallerState(final String name, final boolean
checkNew, final ResourceState expectedState) throws Exception {
+ public void assertOverlayInstallerState(final String name,
+ final boolean checkNew,
+ final ResourceState expectedState) throws Exception {
+ ResourceGroup found = null;
+ final InstallationState state =
this.infoProvider.getInstallationState();
+ for(final ResourceGroup group : state.getInstalledResources()) {
+ for(final Resource rsrc : group.getResources()) {
+ if ( rsrc.getScheme().equals(SCHEME) &&
rsrc.getURL().equals(SCHEME + ":" + "configs/" + FACTORY_PID + "-" + name +
".cfg")) {
+ found = group;
+ break;
+ }
+ }
+ if ( found != null ) {
+ break;
+ }
+ }
+ assertNotNull(found);
+ assertEquals(2, found.getResources().size());
+ final Resource r = found.getResources().get(0);
+ if ( checkNew ) {
+ assertEquals("config:" + FACTORY_PID + "~" + name,
r.getEntityId());
+ } else {
+ assertEquals("config:" + FACTORY_PID + "." + name,
r.getEntityId());
+ }
+ assertEquals(expectedState, r.getState());
+ assertEquals(OVERLAY_SCHEME, r.getScheme());
+ }
+
+ public void assertInstallerState(final String name,
+ final boolean checkNew,
+ final ResourceState expectedState) throws Exception {
// make sure there is only one state in the OSGi installer
ResourceGroup found = null;
final InstallationState state =
this.infoProvider.getInstallationState();
@@ -227,7 +287,6 @@ public class ConfigUpdateTestUtil {
}
public void assertInstallerState(final String factoryPID, final int count)
throws Exception {
- ResourceGroup found = null;
int c = 0;
final InstallationState state =
this.infoProvider.getInstallationState();
for(final ResourceGroup group : state.getInstalledResources()) {
@@ -266,7 +325,14 @@ public class ConfigUpdateTestUtil {
private final int count;
+ private final String scheme;
+
public ResourceInstallationListener(final int count) {
+ this(SCHEME, count);
+ }
+
+ public ResourceInstallationListener(final String scheme, final int
count) {
+ this.scheme = scheme;
this.count = count;
}
@@ -274,7 +340,7 @@ public class ConfigUpdateTestUtil {
public void onEvent(final InstallationEvent event) {
if ( event.getType() == InstallationEvent.TYPE.PROCESSED ) {
final TaskResource rsrc = (TaskResource) event.getSource();
- if ( rsrc.getScheme().equals(SCHEME) ) {
+ if ( rsrc.getScheme().equals(this.scheme) ) {
if ( rsrc.getState() == ResourceState.IGNORED ||
rsrc.getState() == ResourceState.INSTALLED ) {
processedBundles.incrementAndGet();
}
@@ -297,14 +363,14 @@ public class ConfigUpdateTestUtil {
final InstallationState state =
infoProvider.getInstallationState();
for(final ResourceGroup group :
state.getInstalledResources()) {
for(final Resource rsrc : group.getResources()) {
- if ( rsrc.getScheme().equals(SCHEME) ) {
+ if ( rsrc.getScheme().equals(this.scheme) ) {
bundlesCount++;
}
}
}
for(final ResourceGroup group :
state.getActiveResources()) {
for(final Resource rsrc : group.getResources()) {
- if ( rsrc.getScheme().equals(SCHEME) ) {
+ if ( rsrc.getScheme().equals(this.scheme) ) {
bundlesCount++;
}
}