Author: bdelacretaz
Date: Tue May 19 13:53:32 2015
New Revision: 1680292
URL: http://svn.apache.org/r1680292
Log:
More extensive configs tests
Added:
sling/trunk/contrib/crankstart/test-services/src/main/java/org/apache/sling/crankstart/testservices/ConfigDumpServlet.java
Modified:
sling/trunk/contrib/crankstart/launcher/src/test/java/org/apache/sling/crankstart/launcher/CrankstartBootstrapTest.java
sling/trunk/contrib/crankstart/test-services/pom.xml
Modified:
sling/trunk/contrib/crankstart/launcher/src/test/java/org/apache/sling/crankstart/launcher/CrankstartBootstrapTest.java
URL:
http://svn.apache.org/viewvc/sling/trunk/contrib/crankstart/launcher/src/test/java/org/apache/sling/crankstart/launcher/CrankstartBootstrapTest.java?rev=1680292&r1=1680291&r2=1680292&view=diff
==============================================================================
---
sling/trunk/contrib/crankstart/launcher/src/test/java/org/apache/sling/crankstart/launcher/CrankstartBootstrapTest.java
(original)
+++
sling/trunk/contrib/crankstart/launcher/src/test/java/org/apache/sling/crankstart/launcher/CrankstartBootstrapTest.java
Tue May 19 13:53:32 2015
@@ -218,34 +218,6 @@ public class CrankstartBootstrapTest {
@Test
@Retry(timeoutMsec=10000, intervalMsec=250)
- public void testFelixFormatConfig() throws Exception {
- setAdminCredentials();
- final String path =
"/system/console/config/configuration-status-20140606-1347+0200.txt";
- final HttpUriRequest get = new HttpGet(baseUrl + path);
- HttpResponse response = null;
- try {
- response = client.execute(get);
- assertEquals("Expecting config dump to be available at " +
get.getURI(), 200, response.getStatusLine().getStatusCode());
- assertNotNull("Expecting response entity", response.getEntity());
- String encoding = "UTF-8";
- if(response.getEntity().getContentEncoding() != null) {
- encoding =
response.getEntity().getContentEncoding().getValue();
- }
- final String content =
IOUtils.toString(response.getEntity().getContent(), encoding);
- final String [] expected = new String[] {
- "array = [foo, bar.from.launcher.test]",
- "service.ranking.launcher.test = 54321"
- };
- for(String exp : expected) {
- assertTrue("Expecting config content to contain " + exp,
content.contains(exp));
- }
- } finally {
- closeConnection(response);
- }
- }
-
- @Test
- @Retry(timeoutMsec=10000, intervalMsec=250)
public void testSpecificStartLevel() throws Exception {
// Verify that this bundle is only installed, as it's set to start
level 99
setAdminCredentials();
@@ -279,6 +251,42 @@ public class CrankstartBootstrapTest {
} finally {
closeConnection(response);
}
+ }
+
+ @Test
+ @Retry(timeoutMsec=10000, intervalMsec=250)
+ public void testEmptyConfig() throws Exception {
+ setAdminCredentials();
+ assertHttpGet(
+ "/test/config/empty.config.should.work",
+
"empty.config.should.work#service.pid=(String)empty.config.should.work##EOC#");
+ }
+
+ @Test
+ @Retry(timeoutMsec=10000, intervalMsec=250)
+ public void testFelixFormatConfig() throws Exception {
+ setAdminCredentials();
+ assertHttpGet(
+ "/test/config/felix.format.test",
+ "felix.format.test#array=(String[])[foo,
bar.from.launcher.test]#mongouri=(String)mongodb://localhost:27017#service.pid=(String)felix.format.test#service.ranking.launcher.test=(Integer)54321##EOC#");
+ }
+
+ private void assertHttpGet(String path, String expectedContent) throws
Exception {
+ final HttpUriRequest get = new HttpGet(baseUrl + path);
+ HttpResponse response = null;
+ try {
+ response = client.execute(get);
+ assertEquals("Expecting 200 response at " + path, 200,
response.getStatusLine().getStatusCode());
+ assertNotNull("Expecting response entity", response.getEntity());
+ String encoding = "UTF-8";
+ if(response.getEntity().getContentEncoding() != null) {
+ encoding =
response.getEntity().getContentEncoding().getValue();
+ }
+ final String content =
IOUtils.toString(response.getEntity().getContent(), encoding);
+ assertEquals(expectedContent, content);
+ } finally {
+ closeConnection(response);
+ }
}
private static String getOsgiStoragePath() {
Modified: sling/trunk/contrib/crankstart/test-services/pom.xml
URL:
http://svn.apache.org/viewvc/sling/trunk/contrib/crankstart/test-services/pom.xml?rev=1680292&r1=1680291&r2=1680292&view=diff
==============================================================================
--- sling/trunk/contrib/crankstart/test-services/pom.xml (original)
+++ sling/trunk/contrib/crankstart/test-services/pom.xml Tue May 19 13:53:32
2015
@@ -34,6 +34,7 @@
<configuration>
<instructions>
<Private-Package>org.apache.sling.crankstart.testservices.*</Private-Package>
+ <Export-Package></Export-Package>
</instructions>
</configuration>
</plugin>
Added:
sling/trunk/contrib/crankstart/test-services/src/main/java/org/apache/sling/crankstart/testservices/ConfigDumpServlet.java
URL:
http://svn.apache.org/viewvc/sling/trunk/contrib/crankstart/test-services/src/main/java/org/apache/sling/crankstart/testservices/ConfigDumpServlet.java?rev=1680292&view=auto
==============================================================================
---
sling/trunk/contrib/crankstart/test-services/src/main/java/org/apache/sling/crankstart/testservices/ConfigDumpServlet.java
(added)
+++
sling/trunk/contrib/crankstart/test-services/src/main/java/org/apache/sling/crankstart/testservices/ConfigDumpServlet.java
Tue May 19 13:53:32 2015
@@ -0,0 +1,95 @@
+/*
+ * 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.crankstart.testservices;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Enumeration;
+import java.util.Map;
+import java.util.SortedSet;
+import java.util.TreeSet;
+
+import javax.servlet.Servlet;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.Service;
+import org.osgi.service.cm.Configuration;
+import org.osgi.service.cm.ConfigurationAdmin;
+import org.osgi.service.http.HttpService;
+import org.osgi.service.http.NamespaceException;
+
+/** Dump configs, for testing
+ */
+@Component(immediate=true,metatype=true)
+@Service(value=Servlet.class)
+@Reference(name="httpService",referenceInterface=HttpService.class)
+public class ConfigDumpServlet extends TestServlet {
+ private static final long serialVersionUID = -6918378772515948581L;
+
+ @Reference
+ private ConfigurationAdmin configAdmin;
+
+ @Activate
+ protected void activate(Map<String, Object> config) throws
ServletException, NamespaceException {
+ message = "no message yet";
+ path = "/test/config";
+ register();
+ }
+
+ @Override
+ protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
+ final String configPid = req.getPathInfo().substring(1);
+ final Configuration cfg = configAdmin.getConfiguration(configPid);
+
+ final SortedSet<String> keys = new TreeSet<String>();
+ final Enumeration<?> e = cfg.getProperties().keys();
+ while(e.hasMoreElements()) {
+ keys.add(e.nextElement().toString());
+ }
+ final StringBuilder b = new StringBuilder();
+ b.append(configPid).append("#");
+ for(String key : keys) {
+ final Object value = cfg.getProperties().get(key);
+ b.append(key)
+ .append("=(")
+ .append(value.getClass().getSimpleName())
+ .append(")")
+ .append(prettyprint(value))
+ .append("#")
+ ;
+ }
+ b.append("#EOC#");
+
+ resp.setContentType("text/plain");
+ resp.setCharacterEncoding("UTF-8");
+ resp.getWriter().write(b.toString());
+ resp.getWriter().flush();
+ }
+
+ private static String prettyprint(Object value) {
+ if(value instanceof String []) {
+ return Arrays.asList((String[])value).toString();
+ } else {
+ return value.toString();
+ }
+ }
+}