This is an automated email from the ASF dual-hosted git repository. rombert pushed a commit to annotated tag org.apache.sling.testing.paxexam-0.0.2 in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-paxexam.git
commit c12e8ad01537acda7a89d2b5a5165c79f1928466 Author: Oliver Lietz <[email protected]> AuthorDate: Fri Jul 22 17:27:00 2016 +0000 SLING-5894 Provide test support with common functions for use with Pax Exam git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/testing/org.apache.sling.testing.paxexam@1753815 13f79535-47bb-0310-9956-ffa450edef68 --- pom.xml | 15 +++++ .../apache/sling/testing/paxexam/TestSupport.java | 70 ++++++++++++++++++++++ 2 files changed, 85 insertions(+) diff --git a/pom.xml b/pom.xml index bc83ffb..725b31c 100644 --- a/pom.xml +++ b/pom.xml @@ -54,11 +54,26 @@ <groupId>org.apache.felix</groupId> <artifactId>maven-bundle-plugin</artifactId> <extensions>true</extensions> + <configuration> + <instructions> + <Import-Package> + org.ops4j.pax.exam.cm;resolution:=optional, + * + </Import-Package> + </instructions> + </configuration> </plugin> </plugins> </build> <dependencies> + <!-- javax --> + <dependency> + <groupId>javax.inject</groupId> + <artifactId>javax.inject</artifactId> + <version>1</version> + <scope>provided</scope> + </dependency> <!-- OSGi --> <dependency> <groupId>org.osgi</groupId> diff --git a/src/main/java/org/apache/sling/testing/paxexam/TestSupport.java b/src/main/java/org/apache/sling/testing/paxexam/TestSupport.java new file mode 100644 index 0000000..c9d1511 --- /dev/null +++ b/src/main/java/org/apache/sling/testing/paxexam/TestSupport.java @@ -0,0 +1,70 @@ +/* + * 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.paxexam; + +import java.io.IOException; +import java.net.ServerSocket; +import java.util.Dictionary; + +import javax.inject.Inject; + +import org.ops4j.pax.exam.CoreOptions; +import org.ops4j.pax.exam.Option; +import org.osgi.service.cm.ConfigurationAdmin; + +import static org.ops4j.pax.exam.CoreOptions.composite; +import static org.ops4j.pax.exam.CoreOptions.keepCaches; +import static org.ops4j.pax.exam.CoreOptions.mavenBundle; + +public abstract class TestSupport { + + private final String workingDirectory = String.format("target/paxexam/%s", getClass().getSimpleName()); + + @Inject + protected ConfigurationAdmin configurationAdmin; + + protected String workingDirectory() { + return workingDirectory; + } + + protected synchronized int findFreePort() { + try { + final ServerSocket serverSocket = new ServerSocket(0); + final int port = serverSocket.getLocalPort(); + serverSocket.close(); + return port; + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + protected int httpPort() throws IOException { + final Dictionary<String, Object> properties = configurationAdmin.getConfiguration("org.apache.felix.http").getProperties(); + return Integer.parseInt(properties.get("org.osgi.service.http.port").toString()); + } + + protected Option baseConfiguration() { + return composite( + keepCaches(), + CoreOptions.workingDirectory(workingDirectory()), + mavenBundle().groupId("org.apache.sling").artifactId("org.apache.sling.testing.paxexam").versionAsInProject() + ); + } + +} -- To stop receiving notification emails like this one, please contact "[email protected]" <[email protected]>.
