SLING-3463 - Config files cannot be installed via FileProvider on Windows
authorChetan Mehrotra <chetanm@apache.org>
Thu, 20 Mar 2014 04:10:55 +0000 (04:10 +0000)
committerChetan Mehrotra <chetanm@apache.org>
Thu, 20 Mar 2014 04:10:55 +0000 (04:10 +0000)
Adding testcase

git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1579536 13f79535-47bb-0310-9956-ffa450edef68

src/test/java/org/apache/sling/installer/it/ConfigInstallTest.java

index d886df5..2da875e 100644 (file)
  */
 package org.apache.sling.installer.it;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-
 import java.util.ArrayList;
 import java.util.Dictionary;
 import java.util.Hashtable;
@@ -43,12 +39,16 @@ import org.osgi.service.cm.ConfigurationAdmin;
 import org.osgi.service.cm.ConfigurationEvent;
 import org.osgi.service.cm.ConfigurationListener;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
 @RunWith(PaxExam.class)
 
 public class ConfigInstallTest extends OsgiInstallerTestBase implements ConfigurationListener {
 
     private final static long TIMEOUT = 5000L;
-    private List<ConfigurationEvent> events = new LinkedList<ConfigurationEvent>();
+    private final List<ConfigurationEvent> events = new LinkedList<ConfigurationEvent>();
     private List<ServiceRegistration<?>> serviceRegistrations = new ArrayList<ServiceRegistration<?>>();
     private int installationEvents = 0;
     private static final AtomicInteger counter = new AtomicInteger();
@@ -97,6 +97,30 @@ public class ConfigInstallTest extends OsgiInstallerTestBase implements Configur
         }
        }
 
+    @Test
+    public void testInstallConfigWindowsPath() throws Exception {
+        final Dictionary<String, Object> cfgData = new Hashtable<String, Object>();
+        cfgData.put("foo", "bar");
+        final String cfgPid = getClass().getSimpleName() + "." + uniqueID();
+        assertNull("Config " + cfgPid + " must not be found before test", findConfiguration(cfgPid));
+
+        // install configs
+        //Following patterns work fine. Problem occurs one with windows seprator
+        // - "c:/foo/bar/"
+        // - "/foo/bar/"
+        final String uri = "c:\\foo\bar\\";
+        final InstallableResource result = new MockInstallableResource(uri + cfgPid, copy(cfgData), null, null, 100);
+        final InstallableResource[] rsrc = new InstallableResource[] {result};
+        installer.updateResources(URL_SCHEME, rsrc, null);
+
+        Configuration cfg = waitForConfiguration("After installing", cfgPid, TIMEOUT, true);
+        assertEquals("Config value must match", "bar", cfg.getProperties().get("foo"));
+
+        // remove again
+        installer.updateResources(URL_SCHEME, null, new String[] {rsrc[0].getId()});
+        waitForConfiguration("After removing for the second time", cfgPid, TIMEOUT, false);
+    }
+
        @Test
     public void testInstallAndRemoveConfig() throws Exception {
         final Dictionary<String, Object> cfgData = new Hashtable<String, Object>();