incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r1530576 - in /sling/trunk/launchpad/installer: ./ src/test/ src/test/java/ src/test/java/org/ src/test/java/org/apache/ src/test/java/org/apache/sling/ src/test/java/org/apache/sling/launchpad/ src/test/java/org/apache/sling/launchpad/inst...
Date Wed, 09 Oct 2013 11:55:11 GMT
Author: bdelacretaz
Date: Wed Oct  9 11:55:10 2013
New Revision: 1530576

URL: http://svn.apache.org/r1530576
Log:
SLING-3156 - add tests before making changes (which we might not make in the end but that's
another story ;-)

Added:
    sling/trunk/launchpad/installer/src/test/
    sling/trunk/launchpad/installer/src/test/java/
    sling/trunk/launchpad/installer/src/test/java/org/
    sling/trunk/launchpad/installer/src/test/java/org/apache/
    sling/trunk/launchpad/installer/src/test/java/org/apache/sling/
    sling/trunk/launchpad/installer/src/test/java/org/apache/sling/launchpad/
    sling/trunk/launchpad/installer/src/test/java/org/apache/sling/launchpad/installer/
    sling/trunk/launchpad/installer/src/test/java/org/apache/sling/launchpad/installer/impl/
    sling/trunk/launchpad/installer/src/test/java/org/apache/sling/launchpad/installer/impl/LaunchpadConfigInstallerTest.java
  (with props)
Modified:
    sling/trunk/launchpad/installer/pom.xml

Modified: sling/trunk/launchpad/installer/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/installer/pom.xml?rev=1530576&r1=1530575&r2=1530576&view=diff
==============================================================================
--- sling/trunk/launchpad/installer/pom.xml (original)
+++ sling/trunk/launchpad/installer/pom.xml Wed Oct  9 11:55:10 2013
@@ -74,10 +74,25 @@
             <artifactId>slf4j-api</artifactId>
         </dependency>
         <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-simple</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
             <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.settings</artifactId>
             <version>1.1.0</version>
             <scope>provided</scope>
         </dependency>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.mockito</groupId>
+            <artifactId>mockito-core</artifactId>
+            <version>1.9.5</version>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 </project>

Added: sling/trunk/launchpad/installer/src/test/java/org/apache/sling/launchpad/installer/impl/LaunchpadConfigInstallerTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/installer/src/test/java/org/apache/sling/launchpad/installer/impl/LaunchpadConfigInstallerTest.java?rev=1530576&view=auto
==============================================================================
--- sling/trunk/launchpad/installer/src/test/java/org/apache/sling/launchpad/installer/impl/LaunchpadConfigInstallerTest.java
(added)
+++ sling/trunk/launchpad/installer/src/test/java/org/apache/sling/launchpad/installer/impl/LaunchpadConfigInstallerTest.java
Wed Oct  9 11:55:10 2013
@@ -0,0 +1,203 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.apache.sling.launchpad.installer.impl;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.sling.installer.api.InstallableResource;
+import org.apache.sling.installer.api.OsgiInstaller;
+import org.apache.sling.launchpad.api.LaunchpadContentProvider;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Matchers;
+import org.mockito.Mockito;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
+
+public class LaunchpadConfigInstallerTest {
+    
+    private OsgiInstaller installer;
+    private Set<String> registered;
+    private boolean getChildrenReturnsNull;
+    private boolean checkResourceTypes;
+    
+    final Set<String> NO_RUN_MODES = new HashSet<String>();
+    
+    final LaunchpadContentProvider provider = new LaunchpadContentProvider() {
+        
+        private final Map<String, String> CHILDREN = new HashMap<String, String>();
+        
+        {
+            CHILDREN.put("resources", 
+                    "config,bundles,install/,install.dev,install.dev.test,install.test.dev,install.dev.test.another,install.another");
+            CHILDREN.put("config", "A.cfg,B.config,C.somefile,D.properties,dev,cfgModeB");
+            CHILDREN.put("dev", "cfgDev.properties");
+            CHILDREN.put("cfgModeB", "cfgB.properties");
+            CHILDREN.put("install", "install.cfg,install/5/");
+            CHILDREN.put("install/5", "fiveA.cfg,fiveB.properties");
+            CHILDREN.put("install.dev", "mars.config,april.properties");
+            CHILDREN.put("install.dev.test", "devtest.cfg/");
+            CHILDREN.put("install.test.dev", "testdev.cfg");
+            CHILDREN.put("install.dev.test.another", "anotherNo.cfg");
+            CHILDREN.put("install.another", "anotherYes.cfg");
+            CHILDREN.put("bundles", "foo.jar,bar.jar,wii.jar");
+        }
+        
+        public Iterator<String> getChildren(String path) {
+            if(getChildrenReturnsNull) {
+                // simulate old-style provider
+                return null;
+            }
+            final List<String> result = new ArrayList<String>();
+            final String kids = CHILDREN.get(path);
+            if(kids != null) {
+                for(String r : kids.split(",")) {
+                    result.add(r);
+                }
+            }
+            return result.iterator();
+        }
+
+        public URL getResource(String path) {
+            try {
+                return new URL("file://" + path);
+            } catch(MalformedURLException mfe) {
+                fail("Invalid URL " + mfe);
+            }
+            return null;
+        }
+
+        public InputStream getResourceAsStream(String path) {
+            return new ByteArrayInputStream(path.getBytes());
+        }
+    };
+    
+    private void assertRegistered(String ...resources) {
+        final List<String> expected = Arrays.asList(resources);
+        for(String r : expected) {
+            assertTrue("Expecting " + r + " to be registered (" + registered + ")", registered.contains(r));
+        }
+        final int delta = registered.size() - resources.length; 
+        if(delta != 0) {
+            final List<String> unexpected = new ArrayList<String>();
+            for(String r : registered) {
+                if(!expected.contains(r)) {
+                    unexpected.add(r);
+                }
+                
+            }
+            fail("Expected resources don't match registered, unexpected=" + unexpected);
+        }
+    }
+    
+    @Before
+    public void setup() {
+        installer = Mockito.mock(OsgiInstaller.class);
+        registered = new HashSet<String>();
+        getChildrenReturnsNull = false;
+        checkResourceTypes = false;
+        
+        final Answer<Void> rCollector = new Answer<Void>() {
+            public Void answer(InvocationOnMock invocation) throws Throwable {
+                assertEquals("launchpad", invocation.getArguments()[0]);
+                final InstallableResource [] resources = (InstallableResource[])invocation.getArguments()[1];
+                for(InstallableResource r : resources) {
+                    String value = r.getId();
+                    final Object hint = r.getDictionary() == null ? null : r.getDictionary().get(InstallableResource.INSTALLATION_HINT);
+                    if(hint != null) {
+                        value += "-H" + hint;
+                    }
+                    value += "-P" + r.getPriority();
+                    if(checkResourceTypes) {
+                        value += "-T" + r.getType();
+                    }
+                    registered.add(value);
+                }
+                return null;
+            }
+        };
+        Mockito.doAnswer(rCollector).when(installer).registerResources(Matchers.anyString(),
Matchers.any(InstallableResource[].class));
+    }
+    
+    @Test
+    public void testNoRunModes() {
+        LaunchpadConfigInstaller.install(installer, provider, NO_RUN_MODES);
+        assertRegistered("A.cfg-P50", "B.config-P50", "C.somefile-P50", "D.properties-P50","install.cfg-P50",
+                "fiveA.cfg-H5-P50","fiveB.properties-H5-P50");
+    }
+    
+    @Test
+    public void testAnotherMode() {
+        final Set<String> runModes = new HashSet<String>();
+        runModes.add("another");
+        LaunchpadConfigInstaller.install(installer, provider, runModes);
+        assertRegistered(
+                "A.cfg-P50", "B.config-P50", "C.somefile-P50", "D.properties-P50","install.cfg-P50",
+                "fiveA.cfg-H5-P50","fiveB.properties-H5-P50",
+                "anotherYes.cfg-P55"); 
+    }
+    
+    @Test
+    public void testDevRunMode() {
+        checkResourceTypes = true;
+        final Set<String> runModes = new HashSet<String>();
+        runModes.add("dev");
+        LaunchpadConfigInstaller.install(installer, provider, runModes);
+        assertRegistered(
+                "A.cfg-P50-Tproperties", "B.config-P50-Tproperties", "C.somefile-P50-Tproperties",

+                "D.properties-P50-Tproperties","install.cfg-P50-Tfile",
+                "fiveA.cfg-H5-P50-Tfile","fiveB.properties-H5-P50-Tfile",
+                "cfgDev.properties-P55-Tproperties",
+                "mars.config-P55-Tfile", "april.properties-P55-Tfile");
+    }
+    
+    @Test
+    public void testDevTestRunModes() {
+        final Set<String> runModes = new HashSet<String>();
+        runModes.add("dev");
+        runModes.add("test");
+        LaunchpadConfigInstaller.install(installer, provider, runModes);
+        assertRegistered(
+                "A.cfg-P50", "B.config-P50", "C.somefile-P50", "D.properties-P50","install.cfg-P50",
+                "cfgDev.properties-P55",
+                "fiveA.cfg-H5-P50","fiveB.properties-H5-P50",
+                "mars.config-P55", "april.properties-P55",
+                "devtest.cfg-P60", "testdev.cfg-P60");
+    }
+    
+    @Test
+    public void testOldStyle() {
+        getChildrenReturnsNull = true;
+        LaunchpadConfigInstaller.install(installer, provider, NO_RUN_MODES);
+        assertRegistered();
+    }
+}
\ No newline at end of file

Propchange: sling/trunk/launchpad/installer/src/test/java/org/apache/sling/launchpad/installer/impl/LaunchpadConfigInstallerTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/launchpad/installer/src/test/java/org/apache/sling/launchpad/installer/impl/LaunchpadConfigInstallerTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL



Mime
View raw message