You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by bd...@apache.org on 2014/07/21 17:08:58 UTC
svn commit: r1612304 - in /sling/trunk/contrib/crankstart/core: ./
src/main/java/org/apache/sling/crankstart/core/
src/test/java/org/apache/sling/crankstart/core/
src/test/java/org/apache/sling/crankstart/core/commands/ src/test/resources/
Author: bdelacretaz
Date: Mon Jul 21 15:08:57 2014
New Revision: 1612304
URL: http://svn.apache.org/r1612304
Log:
ConfigFactoryTest added, with one disabled assertion that currently fails
Added:
sling/trunk/contrib/crankstart/core/src/test/java/org/apache/sling/crankstart/core/
sling/trunk/contrib/crankstart/core/src/test/java/org/apache/sling/crankstart/core/commands/
sling/trunk/contrib/crankstart/core/src/test/java/org/apache/sling/crankstart/core/commands/ConfigFactoryTest.java
sling/trunk/contrib/crankstart/core/src/test/resources/configfactory-test.txt
Modified:
sling/trunk/contrib/crankstart/core/pom.xml
sling/trunk/contrib/crankstart/core/src/main/java/org/apache/sling/crankstart/core/CrankstartFileProcessor.java
Modified: sling/trunk/contrib/crankstart/core/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/crankstart/core/pom.xml?rev=1612304&r1=1612303&r2=1612304&view=diff
==============================================================================
--- sling/trunk/contrib/crankstart/core/pom.xml (original)
+++ sling/trunk/contrib/crankstart/core/pom.xml Mon Jul 21 15:08:57 2014
@@ -24,6 +24,7 @@
<properties>
<pax.url.version>1.6.0</pax.url.version>
+ <test.storage.base>${project.build.directory}</test.storage.base>
</properties>
<build>
@@ -38,6 +39,15 @@
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <systemProperties>
+ <test.storage.base>${test.storage.base}</test.storage.base>
+ </systemProperties>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.3</version>
<executions>
Modified: sling/trunk/contrib/crankstart/core/src/main/java/org/apache/sling/crankstart/core/CrankstartFileProcessor.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/crankstart/core/src/main/java/org/apache/sling/crankstart/core/CrankstartFileProcessor.java?rev=1612304&r1=1612303&r2=1612304&view=diff
==============================================================================
--- sling/trunk/contrib/crankstart/core/src/main/java/org/apache/sling/crankstart/core/CrankstartFileProcessor.java (original)
+++ sling/trunk/contrib/crankstart/core/src/main/java/org/apache/sling/crankstart/core/CrankstartFileProcessor.java Mon Jul 21 15:08:57 2014
@@ -19,8 +19,6 @@ package org.apache.sling.crankstart.core
import java.io.File;
import java.io.FileReader;
import java.io.Reader;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
@@ -50,14 +48,19 @@ import org.slf4j.LoggerFactory;
/** Process a crankstart file */
public class CrankstartFileProcessor implements Callable<Object> {
- private final CrankstartContext crankstartContext = new CrankstartContext();
+ private final CrankstartContext crankstartContext;
private final Logger log = LoggerFactory.getLogger(getClass());
private Map<String, String> defaults = new HashMap<String, String>();
private List<CrankstartCommand> builtinCommands = new ArrayList<CrankstartCommand>();
private List<CrankstartCommand> extensionCommands = new ArrayList<CrankstartCommand>();
- public CrankstartFileProcessor() {
+ CrankstartFileProcessor() {
+ this(new CrankstartContext());
+ }
+
+ public CrankstartFileProcessor(CrankstartContext ctx) {
+ this.crankstartContext = ctx;
builtinCommands.add(new InstallBundle());
builtinCommands.add(new Log());
builtinCommands.add(new SetOsgiFrameworkProperty());
Added: sling/trunk/contrib/crankstart/core/src/test/java/org/apache/sling/crankstart/core/commands/ConfigFactoryTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/crankstart/core/src/test/java/org/apache/sling/crankstart/core/commands/ConfigFactoryTest.java?rev=1612304&view=auto
==============================================================================
--- sling/trunk/contrib/crankstart/core/src/test/java/org/apache/sling/crankstart/core/commands/ConfigFactoryTest.java (added)
+++ sling/trunk/contrib/crankstart/core/src/test/java/org/apache/sling/crankstart/core/commands/ConfigFactoryTest.java Mon Jul 21 15:08:57 2014
@@ -0,0 +1,106 @@
+/*
+ * 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.core.commands;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.util.Dictionary;
+import java.util.Hashtable;
+import java.util.UUID;
+
+import org.apache.sling.crankstart.api.CrankstartCommandLine;
+import org.apache.sling.crankstart.api.CrankstartContext;
+import org.apache.sling.crankstart.core.CrankstartFileProcessor;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.cm.ConfigurationAdmin;
+
+/** Verify that factory configs are handled properly
+ * when starting the OSGi framework multiple times
+ * with Crankstart.
+ */
+public class ConfigFactoryTest {
+
+ private CrankstartContext ctx;
+ private BundleContext bundleContext;
+ private Object configAdmin;
+ public static final String TEST_PATH = "/configfactory-test.txt";
+
+ @SuppressWarnings("unchecked")
+ @Before
+ public void setup() throws Exception {
+ System.setProperty("java.protocol.handler.pkgs", "org.ops4j.pax.url");
+
+ ctx = new CrankstartContext();
+ final String osgiStoragePath = System.getProperty("test.storage.base") + "/" + UUID.randomUUID();
+ System.setProperty("osgi.storage.path", osgiStoragePath);
+
+ final InputStream is = getClass().getResourceAsStream(TEST_PATH);
+ assertNotNull("Expecting test resource to be found:" + TEST_PATH, is);
+ final Reader input = new InputStreamReader(is);
+ try {
+ new CrankstartFileProcessor(ctx).process(input);
+ } finally {
+ input.close();
+ }
+
+ bundleContext = ctx.getOsgiFramework().getBundleContext();
+ @SuppressWarnings("rawtypes")
+ final ServiceReference configAdminRef = bundleContext.getServiceReference(ConfigurationAdmin.class.getName());
+ assertNotNull("Expecting ConfigurationAdmin service to be present", configAdminRef);
+ configAdmin = bundleContext.getService(configAdminRef);
+ }
+
+ @After
+ public void cleanup() throws BundleException {
+ ctx.getOsgiFramework().stop();
+ }
+
+ @Test
+ public void testMultipleConfigureExecutions() throws Exception {
+ final Configure cmd = new Configure();
+
+ final String verb = "config.factory";
+ final String factoryName = UUID.randomUUID().toString();
+ final Dictionary<String, Object> properties = new Hashtable<String, Object>();
+
+ assertEquals("Expecting no configs initially", 0, count(factoryName));
+
+ final CrankstartCommandLine commandLine = new CrankstartCommandLine(verb, factoryName, properties);
+ cmd.execute(ctx, commandLine);
+ assertEquals("Expecting one config after first excute call", 1, count(factoryName));
+ cmd.execute(ctx, commandLine);
+ //TODO this currently fails - two configs are created
+ //assertEquals("Expecting one config after second excute call", 1, count(factoryName));
+ }
+
+ private int count(String factoryPid) throws Exception {
+ final String filter = "(service.factoryPid=" + factoryPid + ")";
+ final Object [] c = (Object [])configAdmin.getClass()
+ .getMethod("listConfigurations", String.class)
+ .invoke(configAdmin, filter);
+ return c == null ? 0 : c.length;
+ }
+}
Added: sling/trunk/contrib/crankstart/core/src/test/resources/configfactory-test.txt
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/crankstart/core/src/test/resources/configfactory-test.txt?rev=1612304&view=auto
==============================================================================
--- sling/trunk/contrib/crankstart/core/src/test/resources/configfactory-test.txt (added)
+++ sling/trunk/contrib/crankstart/core/src/test/resources/configfactory-test.txt Mon Jul 21 15:08:57 2014
@@ -0,0 +1,5 @@
+# Minimal setup to test factory configs
+osgi.property org.osgi.framework.storage ${osgi.storage.path}
+start.framework
+bundle mvn:org.apache.felix/org.apache.felix.configadmin/1.6.0
+start.all.bundles
\ No newline at end of file