SLING-7786 : Use R7 configuration admin supporting named factory configurations
authorCarsten Ziegeler <cziegele@adobe.com>
Wed, 1 Aug 2018 08:58:55 +0000 (10:58 +0200)
committerCarsten Ziegeler <cziegele@adobe.com>
Wed, 1 Aug 2018 08:58:55 +0000 (10:58 +0200)
src/test/java/org/apache/sling/installer/it/BundleInstallUpgradeDowngradeTest.java
src/test/java/org/apache/sling/installer/it/BundleInstallUpgradeExceptionRetryTest.java
src/test/java/org/apache/sling/installer/it/ConfigUpdateTest.java

index 70d93c9..f95caf0 100644 (file)
@@ -20,7 +20,6 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNull;
 
 import org.apache.sling.installer.api.InstallableResource;
-import org.apache.sling.installer.it.OsgiInstallerTestBase.BundleEvent;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -36,12 +35,13 @@ public class BundleInstallUpgradeDowngradeTest extends OsgiInstallerTestBase {
     public Option[] config() {
         return defaultConfiguration();
     }
-    
+
     @Before
     public void setUp() {
         setupInstaller();
     }
 
+    @Override
     @After
     public void tearDown() {
         super.tearDown();
@@ -211,7 +211,7 @@ public class BundleInstallUpgradeDowngradeTest extends OsgiInstallerTestBase {
     }
 
     /**
-     * This test class assures that whenever a new bundle is 
+     * This test class assures that whenever a new bundle is
      * provided with the same url as an already installed bundle,
      * the already installed bundle is uninstalled and the new one installed.
      * @see <a href="https://issues.apache.org/jira/browse/SLING-6392">SLING-6392</a>
@@ -221,7 +221,7 @@ public class BundleInstallUpgradeDowngradeTest extends OsgiInstallerTestBase {
         final String symbolicName = "osgi-installer-testbundle";
         final String symbolicName2 = "osgi-installer-testA";
         final String installableResourceId = "stable-id";
-        
+
         assertNull("Test bundle must not be present before test", findBundle(symbolicName));
         assertNull("Test A bundle must not be present before test", findBundle(symbolicName2));
         {
index d5aaf35..0fbb122 100644 (file)
@@ -73,8 +73,8 @@ public class BundleInstallUpgradeExceptionRetryTest extends OsgiInstallerTestBas
        @Test
        public void testUpdateFailsWithMoreThanMaxRetrys() throws Exception {
                // install version 1.1 and fail activation with exception all attempts
-               final Object listener = this.startObservingBundleEvents();
-               final AtomicReference<ServiceRegistration<AtomicInteger>> ref = new AtomicReference<ServiceRegistration<AtomicInteger>>(
+               this.startObservingBundleEvents();
+               final AtomicReference<ServiceRegistration<AtomicInteger>> ref = new AtomicReference<>(
                                null);
                final AtomicInteger counter = new AtomicInteger(5);
                bundleContext.addBundleListener(new SynchronousBundleListener() {
@@ -124,8 +124,8 @@ public class BundleInstallUpgradeExceptionRetryTest extends OsgiInstallerTestBas
        @Test
        public void testUpdateSuccedsWithLessThanMaxRetrys() throws Exception {
                // install version 1.1 and fail activation with exception all attempts
-               final Object listener = this.startObservingBundleEvents();
-               final AtomicReference<ServiceRegistration<AtomicInteger>> ref = new AtomicReference<ServiceRegistration<AtomicInteger>>(
+               this.startObservingBundleEvents();
+               final AtomicReference<ServiceRegistration<AtomicInteger>> ref = new AtomicReference<>(
                                null);
                final AtomicInteger counter = new AtomicInteger(3);
                bundleContext.addBundleListener(new SynchronousBundleListener() {
@@ -175,14 +175,14 @@ public class BundleInstallUpgradeExceptionRetryTest extends OsgiInstallerTestBas
                return createBundle("testbundle", manifest, ThrowingActivator.class);
        }
 
-       private static File createBundle(String name, String manifest, Class... classes) throws IOException {
+       private static File createBundle(String name, String manifest, Class<?>... classes) throws IOException {
                File f = File.createTempFile(name, ".jar");
                f.deleteOnExit();
 
                Manifest mf = new Manifest(new ByteArrayInputStream(manifest.getBytes("utf-8")));
                JarOutputStream os = new JarOutputStream(new FileOutputStream(f), mf);
 
-               for (Class clazz : classes) {
+               for (Class<?> clazz : classes) {
                        String path = clazz.getName().replace('.', '/') + ".class";
                        os.putNextEntry(new ZipEntry(path));
 
index 6074c0e..60452a3 100644 (file)
@@ -141,6 +141,30 @@ public class ConfigUpdateTest extends OsgiInstallerTestBase {
             assertEquals(FACTORY_PID, c1.getFactoryPid());
             assertEquals(Boolean.TRUE, c.getProperties().get("modified"));
         }
+        
+        // make sure there is only one state in the OSGi installer
+        final InfoProvider infoProvider = getService(InfoProvider.class);
+        ResourceGroup found = null;
+        final InstallationState state = 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(1, 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());
+        }
     }
 
     @Override