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 2015/12/08 10:00:50 UTC

svn commit: r1718538 - in /sling/trunk/testing/samples/bundle-with-it: ./ src/ src/test/ src/test/java/ src/test/java/org/ src/test/java/org/apache/ src/test/java/org/apache/sling/ src/test/java/org/apache/sling/junit/ src/test/java/org/apache/sling/ju...

Author: bdelacretaz
Date: Tue Dec  8 09:00:50 2015
New Revision: 1718538

URL: http://svn.apache.org/viewvc?rev=1718538&view=rev
Log:
Sample bundle with integration tests, work in progress

Added:
    sling/trunk/testing/samples/bundle-with-it/   (with props)
    sling/trunk/testing/samples/bundle-with-it/pom.xml
    sling/trunk/testing/samples/bundle-with-it/src/
    sling/trunk/testing/samples/bundle-with-it/src/test/
    sling/trunk/testing/samples/bundle-with-it/src/test/java/
    sling/trunk/testing/samples/bundle-with-it/src/test/java/org/
    sling/trunk/testing/samples/bundle-with-it/src/test/java/org/apache/
    sling/trunk/testing/samples/bundle-with-it/src/test/java/org/apache/sling/
    sling/trunk/testing/samples/bundle-with-it/src/test/java/org/apache/sling/junit/
    sling/trunk/testing/samples/bundle-with-it/src/test/java/org/apache/sling/junit/teleporter/
    sling/trunk/testing/samples/bundle-with-it/src/test/java/org/apache/sling/junit/teleporter/customizers/
    sling/trunk/testing/samples/bundle-with-it/src/test/java/org/apache/sling/junit/teleporter/customizers/BWIT_TeleporterCustomizer.java
    sling/trunk/testing/samples/bundle-with-it/src/test/java/org/apache/sling/testing/
    sling/trunk/testing/samples/bundle-with-it/src/test/java/org/apache/sling/testing/samples/
    sling/trunk/testing/samples/bundle-with-it/src/test/java/org/apache/sling/testing/samples/bundlewit/
    sling/trunk/testing/samples/bundle-with-it/src/test/java/org/apache/sling/testing/samples/bundlewit/BasicTeleportedIT.java
    sling/trunk/testing/samples/bundle-with-it/src/test/java/org/apache/sling/testing/samples/bundlewit/OsgiConsoleHttpIT.java

Propchange: sling/trunk/testing/samples/bundle-with-it/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Tue Dec  8 09:00:50 2015
@@ -0,0 +1,12 @@
+target
+bin
+derby.log
+*.iml
+*.ipr
+*.iws
+.settings
+.project
+.classpath
+.externalToolBuilders
+maven-eclipse.xml
+sling

Added: sling/trunk/testing/samples/bundle-with-it/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/testing/samples/bundle-with-it/pom.xml?rev=1718538&view=auto
==============================================================================
--- sling/trunk/testing/samples/bundle-with-it/pom.xml (added)
+++ sling/trunk/testing/samples/bundle-with-it/pom.xml Tue Dec  8 09:00:50 2015
@@ -0,0 +1,293 @@
+<?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>sling</artifactId>
+        <version>25</version>
+        <relativePath/>
+    </parent>
+
+    <artifactId>org.apache.sling.testing.samples.bundle-with-it</artifactId>
+    <version>0.0.9-SNAPSHOT</version>
+    <packaging>bundle</packaging>
+
+    <name>Apache Sling Testing - sample bundle with integration tests</name>
+    <description>
+        Sample project that demonstrates a bundle with integration tests
+		in the same Maven module. Uses both HTTP-based and teleported 
+		server-side tests.
+    </description>
+    
+    <!-- 
+        To keep the instance under test running and run individual tests
+        against it, use:
+        
+            mvn clean verify -DkeepJarRunning=true -Dhttp.port=8080
+            
+        optionally using jar.executor.vm.options to enable remote debugging,
+        and in another console:
+        
+            mvn -o verify -Dtest.server.url=http://localhost:8080
+            
+        optionally using -Dmaven.surefire.debug to enable debugging.            
+     -->
+    <properties>
+        <!-- Set this to run the server on a specific port
+        <http.port></http.port>
+         -->
+         
+        <!-- Set this to run tests against an existing server instance -->
+        <keepJarRunning>false</keepJarRunning>
+        
+        <!-- URL of a server against which to run tests -->
+        <test.server.url />
+        
+         <!-- Set this to run tests against a specific hostname, if test.server.url is not set-->
+         <test.server.hostname />
+
+        <!-- Set this to use a different username for remote execution of sling junit tests -->
+        <test.server.username />
+
+        <!-- Set this to use a different password for remote execution of sling junit tests -->
+        <test.server.password />
+        
+        <!-- Options for the VM that executes our runnable jar -->
+        <jar.executor.vm.options>-Xmx512m</jar.executor.vm.options>
+        
+        <!-- Change this to use longer or shorter timeouts for testing -->
+        <sling.testing.timeout.multiplier>1.0</sling.testing.timeout.multiplier>
+        
+        <!-- Set this to run the executable jar in a specified filesystem folder -->
+        <jar.executor.work.folder />
+        
+        <!-- Options for the jar to execute. $JAREXEC_SERVER_PORT$ is replaced by the
+            selected port number -->
+        <jar.executor.jar.options>-p $JAREXEC_SERVER_PORT$</jar.executor.jar.options>
+    </properties>
+    
+    <scm>
+        <connection>scm:svn:http://svn.apache.org/repos/asf/sling/trunk/testing/samples/bundle-with-tests</connection>
+        <developerConnection> scm:svn:https://svn.apache.org/repos/asf/sling/trunk/testing/samples/bundle-with-tests</developerConnection>
+        <url>http://svn.apache.org/viewvc/sling/trunk/testing/samples/bundle-with-tests</url>
+    </scm>
+
+    <build>
+        <plugins>
+           <plugin>
+                <artifactId>maven-clean-plugin</artifactId>
+                <configuration>
+                    <filesets>
+                        <fileset>
+                            <directory>${basedir}</directory>
+                            <includes>
+                                <!-- sling folder is the workdir of the executable jar that we test -->
+                                <include>sling/**</include>
+                            </includes>
+                        </fileset>
+                    </filesets>
+                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <extensions>true</extensions>
+             </plugin>
+            <plugin>
+                <groupId>org.apache.rat</groupId>
+                <artifactId>apache-rat-plugin</artifactId>
+                <configuration>
+                    <excludes>
+                        <exclude>derby.log</exclude>
+                        <exclude>sling/**</exclude>
+                    </excludes>
+                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-dependency-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <id>copy-runnable-jar</id>
+                        <goals>
+                            <goal>copy-dependencies</goal>
+                        </goals>
+                            <phase>process-resources</phase>
+                        <configuration>
+                            <includeArtifactIds>org.apache.sling.launchpad</includeArtifactIds>
+                            <excludeTransitive>true</excludeTransitive>
+                            <overWriteReleases>false</overWriteReleases>
+                            <overWriteSnapshots>false</overWriteSnapshots>
+                        </configuration>
+                    </execution>
+                    <execution>
+                        <!-- 
+                            Consider all dependencies as candidates to be installed
+                            as additional bundles. We use system properties to define
+                            which bundles to install in which order.  
+                        -->
+                        <id>copy-additional-bundles</id>
+                        <goals>
+                            <goal>copy-dependencies</goal>
+                        </goals>
+                            <phase>process-resources</phase>
+                        <configuration>
+                            <outputDirectory>${project.build.directory}/sling/additional-bundles</outputDirectory>
+                            <excludeTransitive>true</excludeTransitive>
+                            <overWriteReleases>false</overWriteReleases>
+                            <overWriteSnapshots>false</overWriteSnapshots>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+            <plugin>
+                <!-- Find free ports to run our server -->
+                <groupId>org.codehaus.mojo</groupId>
+                <artifactId>build-helper-maven-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <id>reserve-server-port</id>
+                        <goals>
+                            <goal>reserve-network-port</goal>
+                        </goals>
+                        <phase>process-resources</phase>
+                        <configuration>
+                            <portNames>
+                                <portName>http.port</portName>
+                            </portNames>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-failsafe-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <id>integration-test</id>
+                        <goals>
+                            <goal>integration-test</goal>
+                        </goals>
+                    </execution>
+                    <execution>
+                        <id>verify</id>
+                        <goals>
+                            <goal>verify</goal>
+                        </goals>
+                    </execution>
+                </executions>
+                <configuration>
+                    <debugForkedProcess>${maven.surefire.debug}</debugForkedProcess>
+                    <systemPropertyVariables>
+                        <!-- 
+                            TODO this is a fairly complicated setup, we might
+                            switch to a Maven plugin using a Sling provisioning
+                            model to start the server under test. The slingstart
+                            plugin does this but currently requires a launchpad jar,
+                            using a pure provisioning model startup would be more
+                            flexible.  
+                        -->
+                        
+                        <!-- if set, this prevents jar executor from starting Sling?? 
+                        <test.server.url>${test.server.url}</test.server.url>
+                         -->
+                        <test.server.hostname>${test.server.hostname}</test.server.hostname>
+                        <test.server.username>${test.server.username}</test.server.username>
+                        <test.server.password>${test.server.password}</test.server.password>
+                        <jar.executor.server.port>${http.port}</jar.executor.server.port>
+                        <jar.executor.vm.options>${jar.executor.vm.options}</jar.executor.vm.options>
+                        <jar.executor.jar.folder>${project.basedir}/target/dependency</jar.executor.jar.folder>
+                        <jar.executor.jar.name.regexp>org.apache.sling.launchpad.*jar$</jar.executor.jar.name.regexp>
+                        <jar.executor.work.folder>${jar.executor.work.folder}</jar.executor.work.folder>
+                        <jar.executor.jar.options>${jar.executor.jar.options}</jar.executor.jar.options>
+                        <additional.bundles.path>${project.basedir}/target/sling/additional-bundles</additional.bundles.path>
+                        <keepJarRunning>${keepJarRunning}</keepJarRunning>
+                        <server.ready.timeout.seconds>60</server.ready.timeout.seconds>
+                        <sling.testing.timeout.multiplier>${sling.testing.timeout.multiplier}</sling.testing.timeout.multiplier>
+                        <server.ready.path.1>/:script src="system/sling.js"</server.ready.path.1>
+                        <server.ready.path.2>/.explorer.html:href="/libs/sling/explorer/css/explorer.css"</server.ready.path.2>
+                        <server.ready.path.3>/sling-test/sling/sling-test.html:Sling client library tests</server.ready.path.3>
+                        <start.bundles.timeout.seconds>30</start.bundles.timeout.seconds>
+                        <bundle.install.timeout.seconds>20</bundle.install.timeout.seconds>
+                        
+                        <!-- 
+                            Define additional bundles to install by specifying the beginning of their artifact name.
+                            The bundles are installed in lexical order of these property names.
+                            All bundles must be listed as dependencies in this pom, or they won't be installed. 
+                        -->
+                        <sling.additional.bundle.1>org.apache.sling.junit.core</sling.additional.bundle.1>
+                    </systemPropertyVariables>
+                </configuration>
+            </plugin>
+         </plugins>
+    </build>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.core</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.compendium</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.junit.core</artifactId>
+            <version>1.0.14</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.testing.tools</artifactId>
+            <version>1.0.10</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.junit.teleporter</artifactId>
+            <version>1.0.2</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.launchpad</artifactId>
+            <version>8</version>
+			<scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-api</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-simple</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <version>4.12</version>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+</project>

Added: sling/trunk/testing/samples/bundle-with-it/src/test/java/org/apache/sling/junit/teleporter/customizers/BWIT_TeleporterCustomizer.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/samples/bundle-with-it/src/test/java/org/apache/sling/junit/teleporter/customizers/BWIT_TeleporterCustomizer.java?rev=1718538&view=auto
==============================================================================
--- sling/trunk/testing/samples/bundle-with-it/src/test/java/org/apache/sling/junit/teleporter/customizers/BWIT_TeleporterCustomizer.java (added)
+++ sling/trunk/testing/samples/bundle-with-it/src/test/java/org/apache/sling/junit/teleporter/customizers/BWIT_TeleporterCustomizer.java Tue Dec  8 09:00:50 2015
@@ -0,0 +1,38 @@
+/*
+ * 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.junit.teleporter.customizers;
+
+import org.apache.sling.junit.rules.TeleporterRule;
+import org.apache.sling.testing.teleporter.client.ClientSideTeleporter;
+import org.apache.sling.testing.tools.sling.SlingTestBase;
+import org.apache.sling.testing.tools.sling.TimeoutsProvider;
+
+/** This is required by the TeleporterRule, to setup the client-side
+ *  teleporter with (at least) the test server URL.
+ */
+public class BWIT_TeleporterCustomizer implements TeleporterRule.Customizer {
+
+    private final static SlingTestBase S = new SlingTestBase();
+    
+    @Override
+    public void customize(TeleporterRule t, String options) {
+        final ClientSideTeleporter cst = (ClientSideTeleporter)t;
+        cst.setBaseUrl(S.getServerBaseUrl());
+        cst.setServerCredentials(S.getServerUsername(), S.getServerPassword());
+        cst.setTestReadyTimeoutSeconds(TimeoutsProvider.getInstance().getTimeout(5));
+    }
+}
\ No newline at end of file

Added: sling/trunk/testing/samples/bundle-with-it/src/test/java/org/apache/sling/testing/samples/bundlewit/BasicTeleportedIT.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/samples/bundle-with-it/src/test/java/org/apache/sling/testing/samples/bundlewit/BasicTeleportedIT.java?rev=1718538&view=auto
==============================================================================
--- sling/trunk/testing/samples/bundle-with-it/src/test/java/org/apache/sling/testing/samples/bundlewit/BasicTeleportedIT.java (added)
+++ sling/trunk/testing/samples/bundle-with-it/src/test/java/org/apache/sling/testing/samples/bundlewit/BasicTeleportedIT.java Tue Dec  8 09:00:50 2015
@@ -0,0 +1,50 @@
+/*
+ * 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.testing.samples.bundlewit;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import java.io.IOException;
+import java.util.UUID;
+
+import org.apache.sling.junit.rules.TeleporterRule;
+import org.junit.Rule;
+import org.junit.Test;
+import org.osgi.service.cm.Configuration;
+import org.osgi.service.cm.ConfigurationAdmin;
+
+/** Basic teleported server-side test, demonstrates how
+ *  these work.
+ */
+public class BasicTeleportedIT {
+    @Rule
+    public final TeleporterRule teleporter = TeleporterRule.forClass(getClass(), "BWIT_Teleporter");
+
+    @Test
+    public void testConfigAdmin() throws IOException {
+        final String pid = "TEST_" + getClass().getName() + UUID.randomUUID();
+
+        // demonstrate that we can access OSGi services from such 
+        // teleported tests
+        final ConfigurationAdmin ca = teleporter.getService(ConfigurationAdmin.class);
+        assertNotNull("Teleporter should provide a ConfigurationAdmin", ca);
+
+        final Configuration cfg = ca.getConfiguration(pid);
+        assertNotNull("Expecting to get a Configuration", cfg);
+        assertEquals("Expecting the correct pid", pid, cfg.getPid());
+    }    
+}
\ No newline at end of file

Added: sling/trunk/testing/samples/bundle-with-it/src/test/java/org/apache/sling/testing/samples/bundlewit/OsgiConsoleHttpIT.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/samples/bundle-with-it/src/test/java/org/apache/sling/testing/samples/bundlewit/OsgiConsoleHttpIT.java?rev=1718538&view=auto
==============================================================================
--- sling/trunk/testing/samples/bundle-with-it/src/test/java/org/apache/sling/testing/samples/bundlewit/OsgiConsoleHttpIT.java (added)
+++ sling/trunk/testing/samples/bundle-with-it/src/test/java/org/apache/sling/testing/samples/bundlewit/OsgiConsoleHttpIT.java Tue Dec  8 09:00:50 2015
@@ -0,0 +1,57 @@
+/*
+ * 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.testing.samples.bundlewit;
+
+import org.apache.sling.testing.tools.sling.SlingTestBase;
+import org.junit.Test;
+
+/** Simple HTTP test example, checks the validity of some
+ *  OSGi webconsole URLs by GETting them and checking
+ *  status code 200.
+ */
+public class OsgiConsoleHttpIT {
+
+    /** This provides access to the server under test, after
+     *  setting it up with the required test bundles and 
+     *  waiting for them to be ready. It was designed as
+     *  a base class for tests but using it in this way is
+     *  more decoupled.
+     */
+    private static final SlingTestBase S = new SlingTestBase();
+    
+    @Test
+    public void testSomeConsolePaths() throws Exception {
+        final String [] subpaths = {
+                "bundles",
+                "components",
+                "configMgr",
+                "config",
+                "licenses",
+                "logs",
+                "memoryusage",
+                "services"
+        };
+        
+        for(String subpath : subpaths) {
+            final String path = "/system/console/" + subpath;
+            S.getRequestExecutor().execute(
+                    S.getRequestBuilder().buildGetRequest(path)
+                    .withCredentials(S.getServerUsername(), S.getServerPassword())
+            ).assertStatus(200);
+        }
+    }
+}