incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r1052489 - in /sling/trunk/launchpad: installer/src/main/java/org/apache/sling/launchpad/installer/impl/ integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/ test-services/ test-services/src/main/java/org/apach...
Date Fri, 24 Dec 2010 11:45:05 GMT
Author: bdelacretaz
Date: Fri Dec 24 11:45:05 2010
New Revision: 1052489

URL: http://svn.apache.org/viewvc?rev=1052489&view=rev
Log:
SLING-1901 - integration test and bugfix for LaunchpadConfigInstaller

Added:
    sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/LaunchpadConfigInstallerTest.java
  (with props)
    sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/servlets/GetConfigServlet.java
  (with props)
    sling/trunk/launchpad/testing/src/main/config/
    sling/trunk/launchpad/testing/src/main/config/integrationTestsConfig.cfg
Modified:
    sling/trunk/launchpad/installer/src/main/java/org/apache/sling/launchpad/installer/impl/LaunchpadConfigInstaller.java
    sling/trunk/launchpad/test-services/pom.xml

Modified: sling/trunk/launchpad/installer/src/main/java/org/apache/sling/launchpad/installer/impl/LaunchpadConfigInstaller.java
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/installer/src/main/java/org/apache/sling/launchpad/installer/impl/LaunchpadConfigInstaller.java?rev=1052489&r1=1052488&r2=1052489&view=diff
==============================================================================
--- sling/trunk/launchpad/installer/src/main/java/org/apache/sling/launchpad/installer/impl/LaunchpadConfigInstaller.java
(original)
+++ sling/trunk/launchpad/installer/src/main/java/org/apache/sling/launchpad/installer/impl/LaunchpadConfigInstaller.java
Fri Dec 24 11:45:05 2010
@@ -33,8 +33,8 @@ import org.slf4j.LoggerFactory;
 @Component
 public class LaunchpadConfigInstaller {
 
-    /**
-     * 
+    /** Resources supplied under this path by 
+     *  LaunchpadContentProvider are considered for installation
      */
     private static final String ROOT_CONFIG_PATH = "resources/config";
 
@@ -47,22 +47,19 @@ public class LaunchpadConfigInstaller {
     private Logger logger = LoggerFactory.getLogger(this.getClass());
 
     protected void activate(ComponentContext componentContext) {
-        logger.info("Activating launchpad config installer.");
-
+        logger.info("Activating launchpad config installer, resources path={}", ROOT_CONFIG_PATH);
         Collection<InstallableResource> installables = new HashSet<InstallableResource>();
 
         Iterator<String> configPaths = resourceProvider.getChildren(ROOT_CONFIG_PATH);
         while (configPaths.hasNext()) {
             String path = configPaths.next();
-
-            logger.info("Installing config launchpad file: {}", path);
-
+            logger.info("Config launchpad file will be installed: {}", path);
             InputStream stream = resourceProvider.getResourceAsStream(path);
-
             installables.add(new InstallableResource(path, stream, null, null, InstallableResource.TYPE_CONFIG,
0));
-
         }
 
-        installer.registerResources("launchpad", (InstallableResource[])installables.toArray());
+        final InstallableResource [] toInstall = installables.toArray(new InstallableResource
[]{});
+        installer.registerResources("launchpad", (toInstall));
+        logger.info("{} resources registered with OsgiInstaller", toInstall.length);
     }
-}
+}
\ No newline at end of file

Added: sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/LaunchpadConfigInstallerTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/LaunchpadConfigInstallerTest.java?rev=1052489&view=auto
==============================================================================
--- sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/LaunchpadConfigInstallerTest.java
(added)
+++ sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/LaunchpadConfigInstallerTest.java
Fri Dec 24 11:45:05 2010
@@ -0,0 +1,30 @@
+/*
+ * 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.webapp.integrationtest;
+
+import org.apache.sling.commons.testing.integration.HttpTestBase;
+
+/** Verify that the test config is installed */
+public class LaunchpadConfigInstallerTest extends HttpTestBase {
+    public void testConfigPresent() throws Exception {
+        final String url = HTTP_BASE_URL + "/testing/GetConfigServlet.tidy.json/integrationTestsConfig";
+        final String json = getContent(url, CONTENT_TYPE_JSON);
+        final String expectMessage = "This test config should be loaded at startup";
+        final String code = "out.print(data.properties.message)"; 
+        assertJavascript(expectMessage, json, code);
+    }
+}

Propchange: sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/LaunchpadConfigInstallerTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/LaunchpadConfigInstallerTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Modified: sling/trunk/launchpad/test-services/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/test-services/pom.xml?rev=1052489&r1=1052488&r2=1052489&view=diff
==============================================================================
--- sling/trunk/launchpad/test-services/pom.xml (original)
+++ sling/trunk/launchpad/test-services/pom.xml Fri Dec 24 11:45:05 2010
@@ -78,6 +78,12 @@
     </build>
     <dependencies>
         <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.apache.felix.scr.annotations</artifactId>
+            <version>1.4.0</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
             <groupId>javax.servlet</groupId>
             <artifactId>servlet-api</artifactId>
         </dependency>
@@ -102,6 +108,11 @@
             <version>2.1.0</version>
         </dependency>
         <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.commons.json</artifactId>
+            <version>2.0.6</version>
+        </dependency>
+        <dependency>
             <groupId>org.osgi</groupId>
             <artifactId>org.osgi.core</artifactId>
         </dependency>

Added: sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/servlets/GetConfigServlet.java
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/servlets/GetConfigServlet.java?rev=1052489&view=auto
==============================================================================
--- sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/servlets/GetConfigServlet.java
(added)
+++ sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/servlets/GetConfigServlet.java
Fri Dec 24 11:45:05 2010
@@ -0,0 +1,100 @@
+/*
+ * 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.testservices.servlets;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Dictionary;
+import java.util.Enumeration;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.sling.commons.json.JSONException;
+import org.apache.sling.commons.json.io.JSONWriter;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Properties;
+import org.apache.felix.scr.annotations.Property;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.Service;
+import org.apache.sling.api.SlingHttpServletRequest;
+import org.apache.sling.api.SlingHttpServletResponse;
+import org.apache.sling.api.servlets.SlingSafeMethodsServlet;
+import org.osgi.service.cm.Configuration;
+import org.osgi.service.cm.ConfigurationAdmin;
+
+/** GET returns the contents of an OSGi config by PID */
+@Component
+@Service
+@Properties({
+    @Property(name="sling.servlet.paths",value="/testing/GetConfigServlet"),
+    @Property(name="sling.servlet.extensions",value="json")
+})
+public class GetConfigServlet extends SlingSafeMethodsServlet {
+    
+    @Reference
+    private ConfigurationAdmin configAdmin;
+    
+    @Override
+    protected void doGet(SlingHttpServletRequest request,SlingHttpServletResponse response)

+    throws ServletException,IOException {
+
+        // PID comes from request suffix, like /testing/GetConfigServlet.tidy.json/integrationTestsConfig
+        String pid = request.getRequestPathInfo().getSuffix();
+        if(pid == null || pid.length() == 0) {
+            throw new ServletException("Configuration PID must be provided in request suffix");
+        }
+        if(pid.startsWith("/")) {
+            pid = pid.substring(1);
+        }
+        
+        // Get config and properties
+        final Configuration cfg = configAdmin.getConfiguration(pid);
+        if(cfg == null) {
+            response.sendError(HttpServletResponse.SC_NOT_FOUND, "Config with pid=" + pid
+ " not found");
+        }
+        final Dictionary<?, ?> props = cfg.getProperties();
+        if(props == null) {
+            response.sendError(HttpServletResponse.SC_NOT_FOUND, "Properties of config with
pid=" + pid + " not found");
+        }
+
+        // Dump config in JSON
+        response.setContentType("application/json");
+        response.setCharacterEncoding("UTF-8");
+        final Enumeration<?> keys = props.keys();
+        try {
+            final JSONWriter w = new JSONWriter(response.getWriter());
+            w.setTidy(Arrays.asList(request.getRequestPathInfo().getSelectors()).contains("tidy"));
+            w.object();
+            w.key("source").value(getClass().getName());
+            w.key("pid").value(pid);
+            w.key("properties");
+            w.object();
+            while(keys.hasMoreElements()) {
+                final Object key = keys.nextElement();
+                final Object value = props.get(key);
+                if(value != null) {
+                    w.key(key.toString()).value(value.toString());
+                }
+            }
+            w.endObject();
+            w.endObject();
+        } catch(JSONException je) {
+            throw new IOException("JSONException in doGet", je);
+        }
+    }
+}

Propchange: sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/servlets/GetConfigServlet.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/servlets/GetConfigServlet.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: sling/trunk/launchpad/testing/src/main/config/integrationTestsConfig.cfg
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/testing/src/main/config/integrationTestsConfig.cfg?rev=1052489&view=auto
==============================================================================
--- sling/trunk/launchpad/testing/src/main/config/integrationTestsConfig.cfg (added)
+++ sling/trunk/launchpad/testing/src/main/config/integrationTestsConfig.cfg Fri Dec 24 11:45:05
2010
@@ -0,0 +1,2 @@
+# Config used to test LaunchpadConfigInstaller
+message=This test config should be loaded at startup
\ No newline at end of file



Mime
View raw message