Return-Path: Delivered-To: apmail-incubator-sling-commits-archive@minotaur.apache.org Received: (qmail 23345 invoked from network); 14 May 2009 16:09:36 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 14 May 2009 16:09:36 -0000 Received: (qmail 62611 invoked by uid 500); 14 May 2009 16:09:36 -0000 Delivered-To: apmail-incubator-sling-commits-archive@incubator.apache.org Received: (qmail 62572 invoked by uid 500); 14 May 2009 16:09:36 -0000 Mailing-List: contact sling-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: sling-dev@incubator.apache.org Delivered-To: mailing list sling-commits@incubator.apache.org Received: (qmail 62563 invoked by uid 99); 14 May 2009 16:09:36 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 14 May 2009 16:09:36 +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; Thu, 14 May 2009 16:09:31 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 5348E238888D; Thu, 14 May 2009 16:09:10 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r774834 - in /incubator/sling/trunk/contrib/extensions/jcrinstall: ./ it/ it/src/ it/src/test/ it/src/test/java/ it/src/test/java/org/ it/src/test/java/org/apache/ it/src/test/java/org/apache/sling/ it/src/test/java/org/apache/sling/jcr/ it... Date: Thu, 14 May 2009 16:09:10 -0000 To: sling-commits@incubator.apache.org From: bdelacretaz@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090514160910.5348E238888D@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: bdelacretaz Date: Thu May 14 16:09:09 2009 New Revision: 774834 URL: http://svn.apache.org/viewvc?rev=774834&view=rev Log: SLING-904 - integration tests using Pax Exam Added: incubator/sling/trunk/contrib/extensions/jcrinstall/it/ (with props) incubator/sling/trunk/contrib/extensions/jcrinstall/it/pom.xml (with props) incubator/sling/trunk/contrib/extensions/jcrinstall/it/src/ incubator/sling/trunk/contrib/extensions/jcrinstall/it/src/test/ incubator/sling/trunk/contrib/extensions/jcrinstall/it/src/test/java/ incubator/sling/trunk/contrib/extensions/jcrinstall/it/src/test/java/org/ incubator/sling/trunk/contrib/extensions/jcrinstall/it/src/test/java/org/apache/ incubator/sling/trunk/contrib/extensions/jcrinstall/it/src/test/java/org/apache/sling/ incubator/sling/trunk/contrib/extensions/jcrinstall/it/src/test/java/org/apache/sling/jcr/ incubator/sling/trunk/contrib/extensions/jcrinstall/it/src/test/java/org/apache/sling/jcr/jcrinstall/ incubator/sling/trunk/contrib/extensions/jcrinstall/it/src/test/java/org/apache/sling/jcr/jcrinstall/it/ incubator/sling/trunk/contrib/extensions/jcrinstall/it/src/test/java/org/apache/sling/jcr/jcrinstall/it/OsgiControllerTest.java (with props) incubator/sling/trunk/contrib/extensions/jcrinstall/it/src/test/java/org/apache/sling/jcr/jcrinstall/it/SimpleFileInstallableData.java (with props) Modified: incubator/sling/trunk/contrib/extensions/jcrinstall/pom.xml Propchange: incubator/sling/trunk/contrib/extensions/jcrinstall/it/ ------------------------------------------------------------------------------ --- svn:ignore (added) +++ svn:ignore Thu May 14 16:09:09 2009 @@ -0,0 +1,14 @@ +target +bin +derby.log +*.iml +*.ipr +*.iws +.settings +.project +.classpath +.externalToolBuilders +maven-eclipse.xml + + + Added: incubator/sling/trunk/contrib/extensions/jcrinstall/it/pom.xml URL: http://svn.apache.org/viewvc/incubator/sling/trunk/contrib/extensions/jcrinstall/it/pom.xml?rev=774834&view=auto ============================================================================== --- incubator/sling/trunk/contrib/extensions/jcrinstall/it/pom.xml (added) +++ incubator/sling/trunk/contrib/extensions/jcrinstall/it/pom.xml Thu May 14 16:09:09 2009 @@ -0,0 +1,137 @@ + + + + + 4.0.0 + + org.apache.sling + org.apache.sling.jcr.jcrinstall.parent + 2.0.3-incubator-SNAPSHOT + ../ + + + org.apache.sling.jcr.jcrinstall.it + 2.0.3-incubator-SNAPSHOT + jar + + Apache Sling JCR OSGi Installer Integration Tests + + Test the jcrinstall bundles in the OSGi framework. + + + + + + + + + scm:svn:http://svn.apache.org/repos/asf/incubator/sling/trunk/contrib/extensions/jcrinstall/it + scm:svn:https://svn.apache.org/repos/asf/incubator/sling/trunk/contrib/extensions/jcrinstall/it + http://svn.apache.org/viewvc/incubator/sling/whiteboard/jcrinstall + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + + + maven.pom.version + ${pom.version} + + + pax.exam.debug.port + ${pax.exam.debug.port} + + + testbundles.base.dir + ${project.build.directory}/testbundles + + + + + + org.apache.maven.plugins + maven-dependency-plugin + + + copy-test-bundles + + copy-dependencies + + + ${project.build.directory}/testbundles + true + org.apache.felix.webconsole + + + + + + + + + + org.apache.sling + org.apache.sling.jcr.jcrinstall.osgiworker + ${pom.version} + provided + + + org.apache.felix + org.osgi.core + + + org.apache.felix + org.osgi.compendium + + + org.ops4j.pax.exam + pax-exam + 0.5.0 + test + + + org.ops4j.pax.exam + pax-exam-junit + 0.5.0 + test + + + org.ops4j.pax.exam + pax-exam-container-default + 0.5.0 + test + + + org.apache.felix + org.apache.felix.webconsole + 1.2.8 + provided + + + junit + junit + 4.5 + test + + + Propchange: incubator/sling/trunk/contrib/extensions/jcrinstall/it/pom.xml ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/sling/trunk/contrib/extensions/jcrinstall/it/src/test/java/org/apache/sling/jcr/jcrinstall/it/OsgiControllerTest.java URL: http://svn.apache.org/viewvc/incubator/sling/trunk/contrib/extensions/jcrinstall/it/src/test/java/org/apache/sling/jcr/jcrinstall/it/OsgiControllerTest.java?rev=774834&view=auto ============================================================================== --- incubator/sling/trunk/contrib/extensions/jcrinstall/it/src/test/java/org/apache/sling/jcr/jcrinstall/it/OsgiControllerTest.java (added) +++ incubator/sling/trunk/contrib/extensions/jcrinstall/it/src/test/java/org/apache/sling/jcr/jcrinstall/it/OsgiControllerTest.java Thu May 14 16:09:09 2009 @@ -0,0 +1,156 @@ +/* + * 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.it; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.ops4j.pax.exam.CoreOptions.felix; +import static org.ops4j.pax.exam.CoreOptions.mavenBundle; +import static org.ops4j.pax.exam.CoreOptions.options; +import static org.ops4j.pax.exam.CoreOptions.waitForFrameworkStartup; +import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.vmOption; + +import java.io.File; +import java.net.URL; +import java.util.Dictionary; +import java.util.Hashtable; + +import org.apache.sling.jcr.jcrinstall.osgiworker.DictionaryInstallableData; +import org.apache.sling.jcr.jcrinstall.osgiworker.InstallableData; +import org.apache.sling.jcr.jcrinstall.osgiworker.OsgiController; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.ops4j.pax.exam.Inject; +import org.ops4j.pax.exam.Option; +import org.ops4j.pax.exam.junit.JUnit4TestRunner; +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceReference; +import org.osgi.service.cm.Configuration; +import org.osgi.service.cm.ConfigurationAdmin; + +/** Test the OsgiController running in the OSGi framework */ +@RunWith(JUnit4TestRunner.class) +public class OsgiControllerTest { + // TODO System properties don't work as this runs in a separate process + public final static String POM_VERSION = System.getProperty("maven.pom.version"); + + @Inject + protected BundleContext bundleContext; + + @SuppressWarnings("unchecked") + protected T getService(Class clazz) { + final ServiceReference ref = bundleContext.getServiceReference(clazz.getName()); + assertNotNull("getService(" + clazz.getName() + ") must find ServiceReference", ref); + final T result = (T)(bundleContext.getService(ref)); + assertNotNull("getService(" + clazz.getName() + ") must find service", result); + return result; + } + + protected Configuration findConfiguration(String pid) throws Exception { + final Configuration[] cfgs = getService(ConfigurationAdmin.class).listConfigurations(null); + if(cfgs != null) { + for(Configuration cfg : cfgs) { + if(cfg.getPid().equals(pid)) { + return cfg; + } + } + } + return null; + } + + protected Bundle findBundle(String symbolicName) { + for(Bundle b : bundleContext.getBundles()) { + if(symbolicName.equals(b.getSymbolicName())) { + return b; + } + } + return null; + } + + protected File getTestBundle(String bundleName) { + // TODO there must be a better way...but tests don't run in the project folder + // codebase returns a path like "...sling/contrib/extensions/jcrinstall/it/.$tail..." + final URL codebase = getClass().getProtectionDomain().getCodeSource().getLocation(); + String path = codebase.getFile(); + path = path.substring(0, path.indexOf(".$")); + return new File(path, "/target/testbundles/" + bundleName); + } + + @Test + public void testInstallAndRemoveConfig() throws Exception { + final OsgiController c = getService(OsgiController.class); + final Dictionary cfgData = new Hashtable(); + cfgData.put("foo", "bar"); + final String cfgPid = getClass().getName() + "." + System.currentTimeMillis(); + + assertNull("Config " + cfgPid + " must not be found before test", findConfiguration(cfgPid)); + + c.scheduleInstallOrUpdate(cfgPid, new DictionaryInstallableData(cfgData)); + assertNull("Config " + cfgPid + " must not be found right after scheduleInstall", findConfiguration(cfgPid)); + c.executeScheduledOperations(); + + final Configuration cfg = findConfiguration(cfgPid); + assertNotNull("Config " + cfgPid + " must be found right after executeScheduledOperations()", cfg); + final String value = (String)cfg.getProperties().get("foo"); + assertEquals("Config value must match", "bar", value); + + c.scheduleUninstall(cfgPid); + assertNotNull("Config " + cfgPid + " must still be found right after scheduleUninstall", cfg); + c.executeScheduledOperations(); + assertNull("Config " + cfgPid + " must be gone after executeScheduledOperations", findConfiguration(cfgPid)); + } + + @Test + public void testInstallAndRemoveBundle() throws Exception { + final File testBundle = getTestBundle("org.apache.felix.webconsole-1.2.8.jar"); + + final String symbolicName = "org.apache.felix.webconsole"; + final String uri = symbolicName + ".jar"; + assertNull("Console bundle must not be present before test", findBundle(symbolicName)); + + final OsgiController c = getService(OsgiController.class); + final InstallableData d = new SimpleFileInstallableData(testBundle); + c.scheduleInstallOrUpdate(uri, d); + assertNull("Console bundle must still be absent right after scheduleInstallOrUpdate", findBundle(symbolicName)); + c.executeScheduledOperations(); + assertNotNull("Console bundle must be present after executeScheduledOperations", findBundle(symbolicName)); + + c.scheduleUninstall(uri); + assertNotNull("Console bundle must still be present after scheduleUninstall", findBundle(symbolicName)); + c.executeScheduledOperations(); + assertNull("Console bundle must be gone after executeScheduledOperations", findBundle(symbolicName)); + } + + + @org.ops4j.pax.exam.junit.Configuration + public static Option[] configuration() { + final String paxDebugPort = System.getProperty("pax.exam.debug.port"); + final String debugOptions = "-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=" + paxDebugPort; + + return options( + mavenBundle("org.apache.felix", "org.apache.felix.scr", "1.0.6"), + mavenBundle("org.apache.felix", "org.apache.felix.configadmin", "1.0.10"), + mavenBundle("org.apache.sling", "org.apache.sling.commons.log", "2.0.2-incubator"), + mavenBundle("org.apache.sling", "org.apache.sling.jcr.jcrinstall.osgiworker", POM_VERSION), + felix(), + vmOption(paxDebugPort != null && paxDebugPort.length() > 0 ? debugOptions : "-Dno.pax.debugging"), + waitForFrameworkStartup() + ); + } +} \ No newline at end of file Propchange: incubator/sling/trunk/contrib/extensions/jcrinstall/it/src/test/java/org/apache/sling/jcr/jcrinstall/it/OsgiControllerTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: incubator/sling/trunk/contrib/extensions/jcrinstall/it/src/test/java/org/apache/sling/jcr/jcrinstall/it/OsgiControllerTest.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Rev URL Added: incubator/sling/trunk/contrib/extensions/jcrinstall/it/src/test/java/org/apache/sling/jcr/jcrinstall/it/SimpleFileInstallableData.java URL: http://svn.apache.org/viewvc/incubator/sling/trunk/contrib/extensions/jcrinstall/it/src/test/java/org/apache/sling/jcr/jcrinstall/it/SimpleFileInstallableData.java?rev=774834&view=auto ============================================================================== --- incubator/sling/trunk/contrib/extensions/jcrinstall/it/src/test/java/org/apache/sling/jcr/jcrinstall/it/SimpleFileInstallableData.java (added) +++ incubator/sling/trunk/contrib/extensions/jcrinstall/it/src/test/java/org/apache/sling/jcr/jcrinstall/it/SimpleFileInstallableData.java Thu May 14 16:09:09 2009 @@ -0,0 +1,56 @@ +/* + * 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.it; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; + +import org.apache.sling.jcr.jcrinstall.osgiworker.InstallableData; + +class SimpleFileInstallableData implements InstallableData { + + private final File testBundle; + private final String digest; + + SimpleFileInstallableData(File testBundle) { + this.testBundle = testBundle; + digest = testBundle.getAbsolutePath() + System.currentTimeMillis(); + } + + @SuppressWarnings("unchecked") + public AdapterType adaptTo(Class type) { + if(type.equals(InputStream.class)) { + try { + return (AdapterType) new FileInputStream(testBundle); + } catch(IOException ioe) { + throw new Error("IOException in adaptTo", ioe); + } + } + return null; + } + + + public int getBundleStartLevel() { + return 0; + } + + public String getDigest() { + return digest; + } +} Propchange: incubator/sling/trunk/contrib/extensions/jcrinstall/it/src/test/java/org/apache/sling/jcr/jcrinstall/it/SimpleFileInstallableData.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: incubator/sling/trunk/contrib/extensions/jcrinstall/it/src/test/java/org/apache/sling/jcr/jcrinstall/it/SimpleFileInstallableData.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Rev URL Modified: incubator/sling/trunk/contrib/extensions/jcrinstall/pom.xml URL: http://svn.apache.org/viewvc/incubator/sling/trunk/contrib/extensions/jcrinstall/pom.xml?rev=774834&r1=774833&r2=774834&view=diff ============================================================================== --- incubator/sling/trunk/contrib/extensions/jcrinstall/pom.xml (original) +++ incubator/sling/trunk/contrib/extensions/jcrinstall/pom.xml Thu May 14 16:09:09 2009 @@ -41,5 +41,6 @@ servlet osgiworker testbundles/observer + it