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 2009/05/05 17:38:05 UTC

svn commit: r771821 - in /incubator/sling/trunk/contrib: extensions/jcrinstall/osgiworker/src/main/java/org/apache/sling/jcr/jcrinstall/osgiworker/impl/ extensions/jcrinstall/osgiworker/src/test/java/org/apache/sling/jcr/jcrinstall/osgiworker/impl/ lau...

Author: bdelacretaz
Date: Tue May  5 15:38:04 2009
New Revision: 771821

URL: http://svn.apache.org/viewvc?rev=771821&view=rev
Log:
SLING-904 - make ConfigurationAdmin an optional dependency of the osgiworker bundle

Added:
    incubator/sling/trunk/contrib/extensions/jcrinstall/osgiworker/src/main/java/org/apache/sling/jcr/jcrinstall/osgiworker/impl/MissingServiceException.java   (with props)
    incubator/sling/trunk/contrib/extensions/jcrinstall/osgiworker/src/main/java/org/apache/sling/jcr/jcrinstall/osgiworker/impl/ServiceProxy.java   (with props)
    incubator/sling/trunk/contrib/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/jcrinstall/SimpleConfigTest.java   (with props)
Modified:
    incubator/sling/trunk/contrib/extensions/jcrinstall/osgiworker/src/main/java/org/apache/sling/jcr/jcrinstall/osgiworker/impl/ConfigResourceProcessor.java
    incubator/sling/trunk/contrib/extensions/jcrinstall/osgiworker/src/main/java/org/apache/sling/jcr/jcrinstall/osgiworker/impl/OsgiControllerImpl.java
    incubator/sling/trunk/contrib/extensions/jcrinstall/osgiworker/src/main/java/org/apache/sling/jcr/jcrinstall/osgiworker/impl/OsgiControllerTaskExecutor.java
    incubator/sling/trunk/contrib/extensions/jcrinstall/osgiworker/src/main/java/org/apache/sling/jcr/jcrinstall/osgiworker/impl/OsgiResourceProcessorList.java
    incubator/sling/trunk/contrib/extensions/jcrinstall/osgiworker/src/test/java/org/apache/sling/jcr/jcrinstall/osgiworker/impl/ConfigResourceProcessorTest.java
    incubator/sling/trunk/contrib/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/jcrinstall/JcrinstallTestBase.java

Modified: incubator/sling/trunk/contrib/extensions/jcrinstall/osgiworker/src/main/java/org/apache/sling/jcr/jcrinstall/osgiworker/impl/ConfigResourceProcessor.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/contrib/extensions/jcrinstall/osgiworker/src/main/java/org/apache/sling/jcr/jcrinstall/osgiworker/impl/ConfigResourceProcessor.java?rev=771821&r1=771820&r2=771821&view=diff
==============================================================================
--- incubator/sling/trunk/contrib/extensions/jcrinstall/osgiworker/src/main/java/org/apache/sling/jcr/jcrinstall/osgiworker/impl/ConfigResourceProcessor.java (original)
+++ incubator/sling/trunk/contrib/extensions/jcrinstall/osgiworker/src/main/java/org/apache/sling/jcr/jcrinstall/osgiworker/impl/ConfigResourceProcessor.java Tue May  5 15:38:04 2009
@@ -41,12 +41,12 @@
     private static final String ALIAS_KEY = "_alias_factory_pid";
     public static final String CONFIG_PATH_KEY = "_jcr_config_path";
     public static final String CONFIG_EXTENSION = ".cfg";
-    private final ConfigurationAdmin configurationAdmin;
     private final Logger log = LoggerFactory.getLogger(this.getClass());
     private final DictionaryReader reader = new DictionaryReader();
+    private final ServiceProxy serviceProxy;
     
-    ConfigResourceProcessor(ConfigurationAdmin ca) {
-        configurationAdmin = ca;
+    ConfigResourceProcessor(ServiceProxy sp) {
+        serviceProxy = sp;
     }
     
     public void dispose() {
@@ -125,7 +125,14 @@
     }
 
     /** Get or create configuration */
-    Configuration getConfiguration(ConfigurationPid cp, boolean createIfNeeded) throws IOException, InvalidSyntaxException {
+    Configuration getConfiguration(ConfigurationPid cp, boolean createIfNeeded) 
+    throws IOException, InvalidSyntaxException, MissingServiceException 
+    {
+    	final ConfigurationAdmin configurationAdmin = serviceProxy.getConfigurationAdmin();
+    	if(configurationAdmin == null) {
+    		throw new MissingServiceException(ConfigurationAdmin.class);
+    	}
+    	
         Configuration result = null;
         
         if (cp.getFactoryPid() == null) {

Added: incubator/sling/trunk/contrib/extensions/jcrinstall/osgiworker/src/main/java/org/apache/sling/jcr/jcrinstall/osgiworker/impl/MissingServiceException.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/contrib/extensions/jcrinstall/osgiworker/src/main/java/org/apache/sling/jcr/jcrinstall/osgiworker/impl/MissingServiceException.java?rev=771821&view=auto
==============================================================================
--- incubator/sling/trunk/contrib/extensions/jcrinstall/osgiworker/src/main/java/org/apache/sling/jcr/jcrinstall/osgiworker/impl/MissingServiceException.java (added)
+++ incubator/sling/trunk/contrib/extensions/jcrinstall/osgiworker/src/main/java/org/apache/sling/jcr/jcrinstall/osgiworker/impl/MissingServiceException.java Tue May  5 15:38:04 2009
@@ -0,0 +1,29 @@
+/*
+ * 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.jcr.jcrinstall.osgiworker.impl;
+
+/** Thrown when a required service is missing to execute a task,
+ * 	in which case the task can be retried later
+ */
+@SuppressWarnings("serial")
+class MissingServiceException extends Exception {
+	MissingServiceException(Class<?> serviceClass) {
+		super(serviceClass.getName());
+	}
+}

Propchange: incubator/sling/trunk/contrib/extensions/jcrinstall/osgiworker/src/main/java/org/apache/sling/jcr/jcrinstall/osgiworker/impl/MissingServiceException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/sling/trunk/contrib/extensions/jcrinstall/osgiworker/src/main/java/org/apache/sling/jcr/jcrinstall/osgiworker/impl/MissingServiceException.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Modified: incubator/sling/trunk/contrib/extensions/jcrinstall/osgiworker/src/main/java/org/apache/sling/jcr/jcrinstall/osgiworker/impl/OsgiControllerImpl.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/contrib/extensions/jcrinstall/osgiworker/src/main/java/org/apache/sling/jcr/jcrinstall/osgiworker/impl/OsgiControllerImpl.java?rev=771821&r1=771820&r2=771821&view=diff
==============================================================================
--- incubator/sling/trunk/contrib/extensions/jcrinstall/osgiworker/src/main/java/org/apache/sling/jcr/jcrinstall/osgiworker/impl/OsgiControllerImpl.java (original)
+++ incubator/sling/trunk/contrib/extensions/jcrinstall/osgiworker/src/main/java/org/apache/sling/jcr/jcrinstall/osgiworker/impl/OsgiControllerImpl.java Tue May  5 15:38:04 2009
@@ -35,10 +35,9 @@
 import org.osgi.framework.SynchronousBundleListener;
 import org.osgi.service.cm.ConfigurationAdmin;
 import org.osgi.service.component.ComponentContext;
+import org.osgi.service.log.LogService;
 import org.osgi.service.packageadmin.PackageAdmin;
 import org.osgi.service.startlevel.StartLevel;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 /** OsgiController service
  *
@@ -53,12 +52,11 @@
  *      name="service.vendor"
  *      value="The Apache Software Foundation"
 */
-public class OsgiControllerImpl implements OsgiController, SynchronousBundleListener {
+public class OsgiControllerImpl implements OsgiController, SynchronousBundleListener, ServiceProxy {
 
 	private BundleContext bundleContext;
     private Storage storage;
     private OsgiResourceProcessorList processors;
-    private final Logger log = LoggerFactory.getLogger(this.getClass());
     private ResourceOverrideRules roRules;
     private final List<Callable<Object>> tasks = new LinkedList<Callable<Object>>();
     private final OsgiControllerTaskExecutor executor = new OsgiControllerTaskExecutor();
@@ -68,7 +66,7 @@
     /** Storage key: digest of an InstallableData */
     public static final String KEY_DIGEST = "data.digest";
 
-    /** @scr.reference */
+    /** @scr.reference cardinality="0..1" policy="dynamic" */
     private ConfigurationAdmin configAdmin;
 
     /** @scr.reference */
@@ -77,22 +75,33 @@
     /** @scr.reference */
     protected StartLevel startLevel;
     
+    /** @scr.reference */
+    protected LogService logService;
+    
     /** Default value for getLastModified() */
     public static final long LAST_MODIFIED_NOT_FOUND = -1;
 
     protected void activate(ComponentContext context) throws IOException {
     	bundleContext = context.getBundleContext();
-        processors = new OsgiResourceProcessorList(context.getBundleContext(), packageAdmin, startLevel, configAdmin);
+        processors = new OsgiResourceProcessorList(context.getBundleContext(), packageAdmin, startLevel, this);
         storage = new Storage(context.getBundleContext().getDataFile(STORAGE_FILENAME));
     }
 
     protected void deactivate(ComponentContext oldContext) {
+    	if(logService != null) {
+    		logService.log(LogService.LOG_WARNING, 
+    				OsgiController.class.getName() 
+    				+ " service deactivated - this warning can be ignored if system is shutting down");
+    	}
+    	
     	bundleContext = null;
         if(storage != null) {
             try {
                 storage.saveToFile();
             } catch(IOException ioe) {
-                log.warn("IOException in Storage.saveToFile()", ioe);
+            	if(logService != null) {
+            		logService.log(LogService.LOG_WARNING, "IOException in Storage.saveToFile()", ioe);
+            	}
             }
         }
         
@@ -149,7 +158,9 @@
     	
     	// Ready to work?
         if(processors == null) {
-            log.info("Not activated yet, cannot executeScheduledOperations");
+        	if(logService != null) {
+                logService.log(LogService.LOG_INFO, "Not activated yet, cannot executeScheduledOperations");
+        	}
             return;
         }
         
@@ -166,14 +177,27 @@
             }
             
             // Now execute all our tasks in a separate thread
-            log.debug("Executing {} queued tasks", tasks.size());
+        	if(logService != null) {
+                logService.log(LogService.LOG_DEBUG, "Executing " + tasks.size() + " queued tasks");
+        	}
             final long start = System.currentTimeMillis();
-            executor.execute(tasks);
-            log.debug("Done executing queued tasks ({} msec)", System.currentTimeMillis() - start);
+            
+            // execute returns the list of tasks that could not be executed but should be retried later
+            // and those have been removed from the tasks list
+            tasks.addAll(executor.execute(tasks));
+            
+        	if(logService != null) {
+                logService.log(LogService.LOG_DEBUG, 
+                		"Done executing queued tasks (" + (System.currentTimeMillis() - start) + " msec)");
+        	}
 		}
 	}
 
 	public void setResourceOverrideRules(ResourceOverrideRules r) {
         roRules = r;
     }
+
+	public ConfigurationAdmin getConfigurationAdmin() {
+		return configAdmin;
+	}
 }
\ No newline at end of file

Modified: incubator/sling/trunk/contrib/extensions/jcrinstall/osgiworker/src/main/java/org/apache/sling/jcr/jcrinstall/osgiworker/impl/OsgiControllerTaskExecutor.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/contrib/extensions/jcrinstall/osgiworker/src/main/java/org/apache/sling/jcr/jcrinstall/osgiworker/impl/OsgiControllerTaskExecutor.java?rev=771821&r1=771820&r2=771821&view=diff
==============================================================================
--- incubator/sling/trunk/contrib/extensions/jcrinstall/osgiworker/src/main/java/org/apache/sling/jcr/jcrinstall/osgiworker/impl/OsgiControllerTaskExecutor.java (original)
+++ incubator/sling/trunk/contrib/extensions/jcrinstall/osgiworker/src/main/java/org/apache/sling/jcr/jcrinstall/osgiworker/impl/OsgiControllerTaskExecutor.java Tue May  5 15:38:04 2009
@@ -18,6 +18,7 @@
  */
 package org.apache.sling.jcr.jcrinstall.osgiworker.impl;
 
+import java.util.LinkedList;
 import java.util.List;
 import java.util.concurrent.Callable;
 
@@ -29,9 +30,10 @@
 class OsgiControllerTaskExecutor {
     private final Logger log = LoggerFactory.getLogger(this.getClass());
     static int counter;
-
+    
 	/** Execute the given tasks in a new thread, return when done */
-	void execute(final List<Callable<Object>> tasks) throws InterruptedException {
+    List<Callable<Object>> execute(final List<Callable<Object>> tasks) throws InterruptedException {
+    	final List<Callable<Object>> remainingTasks = new LinkedList<Callable<Object>>();
 		final String threadName = getClass().getSimpleName() + " #" + (++counter);
 		final Thread t = new Thread(threadName) {
 			@Override
@@ -41,6 +43,9 @@
 					try {
 						c.call();
 						log.debug("Task execution successful: " + c);
+					} catch(MissingServiceException mse) {
+						log.info("Task execution deferred due to " + mse + ", task=" + c);
+						remainingTasks.add(c);
 					} catch(Exception e) {
 						log.warn("Task execution failed: " + c, e);
 					}
@@ -50,5 +55,6 @@
 		t.setDaemon(true);
 		t.start();
 		t.join();
+		return remainingTasks;
 	}
 }

Modified: incubator/sling/trunk/contrib/extensions/jcrinstall/osgiworker/src/main/java/org/apache/sling/jcr/jcrinstall/osgiworker/impl/OsgiResourceProcessorList.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/contrib/extensions/jcrinstall/osgiworker/src/main/java/org/apache/sling/jcr/jcrinstall/osgiworker/impl/OsgiResourceProcessorList.java?rev=771821&r1=771820&r2=771821&view=diff
==============================================================================
--- incubator/sling/trunk/contrib/extensions/jcrinstall/osgiworker/src/main/java/org/apache/sling/jcr/jcrinstall/osgiworker/impl/OsgiResourceProcessorList.java (original)
+++ incubator/sling/trunk/contrib/extensions/jcrinstall/osgiworker/src/main/java/org/apache/sling/jcr/jcrinstall/osgiworker/impl/OsgiResourceProcessorList.java Tue May  5 15:38:04 2009
@@ -23,7 +23,6 @@
 import org.apache.sling.jcr.jcrinstall.osgiworker.InstallableData;
 import org.apache.sling.jcr.jcrinstall.osgiworker.OsgiResourceProcessor;
 import org.osgi.framework.BundleContext;
-import org.osgi.service.cm.ConfigurationAdmin;
 import org.osgi.service.packageadmin.PackageAdmin;
 import org.osgi.service.startlevel.StartLevel;
 import org.slf4j.Logger;
@@ -36,9 +35,9 @@
 class OsgiResourceProcessorList extends LinkedList<OsgiResourceProcessor> {
     private final Logger log = LoggerFactory.getLogger(getClass());
     
-	OsgiResourceProcessorList(BundleContext ctx, PackageAdmin pa, StartLevel sa, ConfigurationAdmin ca) {
+	OsgiResourceProcessorList(BundleContext ctx, PackageAdmin pa, StartLevel sa, ServiceProxy sp) {
         add(new BundleResourceProcessor(ctx, pa, sa));
-        add(new ConfigResourceProcessor(ca));
+        add(new ConfigResourceProcessor(sp));
 	}
 	
 	OsgiResourceProcessor getProcessor(String uri, InstallableData data) {

Added: incubator/sling/trunk/contrib/extensions/jcrinstall/osgiworker/src/main/java/org/apache/sling/jcr/jcrinstall/osgiworker/impl/ServiceProxy.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/contrib/extensions/jcrinstall/osgiworker/src/main/java/org/apache/sling/jcr/jcrinstall/osgiworker/impl/ServiceProxy.java?rev=771821&view=auto
==============================================================================
--- incubator/sling/trunk/contrib/extensions/jcrinstall/osgiworker/src/main/java/org/apache/sling/jcr/jcrinstall/osgiworker/impl/ServiceProxy.java (added)
+++ incubator/sling/trunk/contrib/extensions/jcrinstall/osgiworker/src/main/java/org/apache/sling/jcr/jcrinstall/osgiworker/impl/ServiceProxy.java Tue May  5 15:38:04 2009
@@ -0,0 +1,28 @@
+/*
+ * 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.jcr.jcrinstall.osgiworker.impl;
+
+import org.osgi.service.cm.ConfigurationAdmin;
+
+/** Proxy for services that might not be always available, allows
+ * 	classes which are not OSGi services to access such services easily
+ */
+interface ServiceProxy {
+	ConfigurationAdmin getConfigurationAdmin();
+}

Propchange: incubator/sling/trunk/contrib/extensions/jcrinstall/osgiworker/src/main/java/org/apache/sling/jcr/jcrinstall/osgiworker/impl/ServiceProxy.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/sling/trunk/contrib/extensions/jcrinstall/osgiworker/src/main/java/org/apache/sling/jcr/jcrinstall/osgiworker/impl/ServiceProxy.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Modified: incubator/sling/trunk/contrib/extensions/jcrinstall/osgiworker/src/test/java/org/apache/sling/jcr/jcrinstall/osgiworker/impl/ConfigResourceProcessorTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/contrib/extensions/jcrinstall/osgiworker/src/test/java/org/apache/sling/jcr/jcrinstall/osgiworker/impl/ConfigResourceProcessorTest.java?rev=771821&r1=771820&r2=771821&view=diff
==============================================================================
--- incubator/sling/trunk/contrib/extensions/jcrinstall/osgiworker/src/test/java/org/apache/sling/jcr/jcrinstall/osgiworker/impl/ConfigResourceProcessorTest.java (original)
+++ incubator/sling/trunk/contrib/extensions/jcrinstall/osgiworker/src/test/java/org/apache/sling/jcr/jcrinstall/osgiworker/impl/ConfigResourceProcessorTest.java Tue May  5 15:38:04 2009
@@ -41,7 +41,12 @@
         final String data = "foo = bar";
         final MockInstallableData id = new MockInstallableData(path, data);
         final ConfigurationAdmin ca = mockery.mock(ConfigurationAdmin.class);
-        final ConfigResourceProcessor p = new ConfigResourceProcessor(ca);
+        final ServiceProxy sp = new ServiceProxy() {
+			public ConfigurationAdmin getConfigurationAdmin() {
+				return ca;
+			}
+        };
+        final ConfigResourceProcessor p = new ConfigResourceProcessor(sp);
         final Configuration c = mockery.mock(Configuration.class);
         final String pid = "dummyConfigPid";
         

Modified: incubator/sling/trunk/contrib/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/jcrinstall/JcrinstallTestBase.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/contrib/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/jcrinstall/JcrinstallTestBase.java?rev=771821&r1=771820&r2=771821&view=diff
==============================================================================
--- incubator/sling/trunk/contrib/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/jcrinstall/JcrinstallTestBase.java (original)
+++ incubator/sling/trunk/contrib/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/jcrinstall/JcrinstallTestBase.java Tue May  5 15:38:04 2009
@@ -42,6 +42,10 @@
 	protected int scaleFactor;
 	protected int defaultBundlesTimeout;
 	
+	static interface StringCondition {
+		boolean eval(String input);
+	}
+	
     private class ShutdownThread extends Thread {
         @Override
         public void run() {
@@ -106,6 +110,23 @@
     			+ " after waiting " + delta / 1000.0 + " seconds");
     }
     
+    protected void assertContentWithTimeout(String message, String contentUrl, String expectedContentType, 
+    		StringCondition condition, int timeoutSeconds) throws IOException 
+    {
+    	final long start = System.currentTimeMillis();
+    	final long timeout = start + timeoutSeconds * 1000L;
+    	while(System.currentTimeMillis() < timeout) {
+    		final String content = getContent(contentUrl, expectedContentType);
+    		if(condition.eval(content)) {
+    			return;
+    		}
+    		sleep(200);
+    	}
+    	final long delta = System.currentTimeMillis() - start;
+    	fail(message + ": StringCondition did not return true" 
+    			+ " after waiting " + delta / 1000.0 + " seconds");
+    }
+    
     protected void sleep(long millis) {
     	try {
     		Thread.sleep(millis);

Added: incubator/sling/trunk/contrib/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/jcrinstall/SimpleConfigTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/contrib/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/jcrinstall/SimpleConfigTest.java?rev=771821&view=auto
==============================================================================
--- incubator/sling/trunk/contrib/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/jcrinstall/SimpleConfigTest.java (added)
+++ incubator/sling/trunk/contrib/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/jcrinstall/SimpleConfigTest.java Tue May  5 15:38:04 2009
@@ -0,0 +1,84 @@
+/*
+ * 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.jcrinstall;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+/** Simple test of the jcrinstall configuration feature: create 
+ * 	sling:OsgiConfig nodes and check that the corresponding configs
+ *  are available at /system/console/config
+ *
+ */
+public class SimpleConfigTest extends JcrinstallTestBase {
+	
+	static class ConfigCondition implements JcrinstallTestBase.StringCondition {
+		private final String expectedValue;
+		private final boolean expectValueInContent;
+		
+		ConfigCondition(String expectedValue, boolean expectValueInContent) {
+			this.expectedValue = expectedValue;
+			this.expectValueInContent = expectValueInContent;
+		}
+		public boolean eval(String input) {
+			final boolean contains = input.contains(expectedValue);
+			return expectValueInContent ? contains : !contains;
+		}
+	};
+	
+	public void testSimpleConfig() throws IOException {
+		final String uniqueId = getClass().getName() + System.currentTimeMillis(); 
+		final String key = getClass().getName() + ".key";
+		final String value = getClass().getName() + "." + uniqueId;
+		final String keyValue = key + "=" + value;
+		
+		final String configUrl = HTTP_BASE_URL + "/system/console/config";
+		final String contentType = CONTENT_TYPE_HTML;
+		final int timeoutSeconds = 4;
+		
+		assertContentWithTimeout("Before test, config must not exist", configUrl, 
+				contentType, new ConfigCondition(keyValue, false), timeoutSeconds);
+		
+		// Create an OSGi config using a sling:OsgiConfig node
+		final String configPath = "/apps/" + getClass().getSimpleName() + "/install";
+		testClient.mkdirs(HTTP_BASE_URL, configPath);
+		final Map<String, String> nodeProperties = new HashMap<String, String>();
+		nodeProperties.put("jcr:primaryType", "sling:OsgiConfig");
+		nodeProperties.put(key, value);
+		final String toDelete = testClient.createNode(HTTP_BASE_URL + configPath + "/" + uniqueId, nodeProperties);
+		assertContentWithTimeout("Config must be present after creating config node", configUrl, 
+				contentType, new ConfigCondition(keyValue, true), timeoutSeconds);
+		
+		// Update config node, verify that config is updated
+		final String newValue = getClass().getName() + ".NEW." + System.currentTimeMillis();
+		final String newKeyValue = key + "=" + newValue;
+		nodeProperties.put(key, newValue);
+		testClient.createNode(HTTP_BASE_URL + configPath + "/" + uniqueId, nodeProperties);
+		assertContentWithTimeout("Config must be modified after node update", configUrl, 
+				contentType, new ConfigCondition(newKeyValue, true), timeoutSeconds);
+		assertContentWithTimeout("Old value must be gone after update", configUrl, 
+				contentType, new ConfigCondition(keyValue, false), timeoutSeconds);
+		
+		// Delete and verify that the config is gone
+		testClient.delete(toDelete);
+		assertContentWithTimeout("Old config must be gone after removing config node", configUrl, 
+				contentType, new ConfigCondition(keyValue, false), timeoutSeconds);
+		assertContentWithTimeout("New config must be gone after removing config node", configUrl, 
+				contentType, new ConfigCondition(newKeyValue, false), timeoutSeconds);
+	}
+}

Propchange: incubator/sling/trunk/contrib/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/jcrinstall/SimpleConfigTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/sling/trunk/contrib/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/jcrinstall/SimpleConfigTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL