Return-Path: Delivered-To: apmail-sling-commits-archive@www.apache.org Received: (qmail 44759 invoked from network); 24 Dec 2010 11:45:30 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 24 Dec 2010 11:45:30 -0000 Received: (qmail 81557 invoked by uid 500); 24 Dec 2010 11:45:29 -0000 Delivered-To: apmail-sling-commits-archive@sling.apache.org Received: (qmail 81495 invoked by uid 500); 24 Dec 2010 11:45:28 -0000 Mailing-List: contact commits-help@sling.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@sling.apache.org Delivered-To: mailing list commits@sling.apache.org Received: (qmail 81482 invoked by uid 99); 24 Dec 2010 11:45:27 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 24 Dec 2010 11:45:27 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 24 Dec 2010 11:45:25 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 9488D2388A33; Fri, 24 Dec 2010 11:45:05 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@sling.apache.org From: bdelacretaz@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20101224114505.9488D2388A33@eris.apache.org> 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 installables = new HashSet(); Iterator 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 @@ + org.apache.felix + org.apache.felix.scr.annotations + 1.4.0 + provided + + javax.servlet servlet-api @@ -102,6 +108,11 @@ 2.1.0 + org.apache.sling + org.apache.sling.commons.json + 2.0.6 + + org.osgi org.osgi.core 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