incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
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 GMT
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 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.apache.sling</groupId>
+        <artifactId>org.apache.sling.jcr.jcrinstall.parent</artifactId>
+        <version>2.0.3-incubator-SNAPSHOT</version>
+        <relativePath>../</relativePath>
+    </parent>
+
+    <artifactId>org.apache.sling.jcr.jcrinstall.it</artifactId>
+    <version>2.0.3-incubator-SNAPSHOT</version>
+    <packaging>jar</packaging>
+
+    <name>Apache Sling JCR OSGi Installer Integration Tests</name>
+    <description> 
+    Test the jcrinstall bundles in the OSGi framework.
+  </description>
+  
+  <properties>
+    <!-- This can be set to activate remote debugging of the Pax Exam tests -->
+    <pax.exam.debug.port></pax.exam.debug.port>
+  </properties>
+
+    <scm>
+        <connection>scm:svn:http://svn.apache.org/repos/asf/incubator/sling/trunk/contrib/extensions/jcrinstall/it</connection>
+        <developerConnection>scm:svn:https://svn.apache.org/repos/asf/incubator/sling/trunk/contrib/extensions/jcrinstall/it</developerConnection>
+        <url>http://svn.apache.org/viewvc/incubator/sling/whiteboard/jcrinstall</url>
+    </scm>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-surefire-plugin</artifactId>
+                <configuration>
+                    <systemProperties>
+                        <property>
+                            <name>maven.pom.version</name>
+                            <value>${pom.version}</value>
+                        </property>
+                        <property>
+                            <name>pax.exam.debug.port</name>
+                            <value>${pax.exam.debug.port}</value>
+                        </property>
+                        <property>
+                            <name>testbundles.base.dir</name>
+                            <value>${project.build.directory}/testbundles</value>
+                        </property>
+                    </systemProperties>
+                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-dependency-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <id>copy-test-bundles</id>
+                        <goals>
+                            <goal>copy-dependencies</goal>
+                        </goals>
+                        <configuration>
+                            <outputDirectory>${project.build.directory}/testbundles</outputDirectory>
+                            <excludeTransitive>true</excludeTransitive>
+                            <includeArtifactIds>org.apache.felix.webconsole</includeArtifactIds>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.jcr.jcrinstall.osgiworker</artifactId>
+            <version>${pom.version}</version>
+            <scope>provided</scope>
+        </dependency>          
+        <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.osgi.core</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.osgi.compendium</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.ops4j.pax.exam</groupId>
+            <artifactId>pax-exam</artifactId>
+            <version>0.5.0</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.ops4j.pax.exam</groupId>
+            <artifactId>pax-exam-junit</artifactId>
+            <version>0.5.0</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.ops4j.pax.exam</groupId>
+            <artifactId>pax-exam-container-default</artifactId>
+            <version>0.5.0</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.apache.felix.webconsole</artifactId>
+            <version>1.2.8</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <version>4.5</version>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+</project>

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> T getService(Class<T> 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<String, Object> cfgData = new Hashtable<String, Object>();
+    	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> AdapterType adaptTo(Class<AdapterType> 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 @@
 		<module>servlet</module>
 		<module>osgiworker</module>
 		<module>testbundles/observer</module>
+		<module>it</module>
 	</modules>
 </project>



Mime
View raw message