Author: olli
Date: Fri Jul 22 17:27:00 2016
New Revision: 1753815
URL: http://svn.apache.org/viewvc?rev=1753815&view=rev
Log:
SLING-5894 Provide test support with common functions for use with Pax Exam
Added:
sling/trunk/testing/org.apache.sling.testing.paxexam/src/main/java/org/apache/sling/testing/paxexam/TestSupport.java
Modified:
sling/trunk/testing/org.apache.sling.testing.paxexam/pom.xml
Modified: sling/trunk/testing/org.apache.sling.testing.paxexam/pom.xml
URL:
http://svn.apache.org/viewvc/sling/trunk/testing/org.apache.sling.testing.paxexam/pom.xml?rev=1753815&r1=1753814&r2=1753815&view=diff
==============================================================================
--- sling/trunk/testing/org.apache.sling.testing.paxexam/pom.xml (original)
+++ sling/trunk/testing/org.apache.sling.testing.paxexam/pom.xml Fri Jul 22
17:27:00 2016
@@ -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>
Added:
sling/trunk/testing/org.apache.sling.testing.paxexam/src/main/java/org/apache/sling/testing/paxexam/TestSupport.java
URL:
http://svn.apache.org/viewvc/sling/trunk/testing/org.apache.sling.testing.paxexam/src/main/java/org/apache/sling/testing/paxexam/TestSupport.java?rev=1753815&view=auto
==============================================================================
---
sling/trunk/testing/org.apache.sling.testing.paxexam/src/main/java/org/apache/sling/testing/paxexam/TestSupport.java
(added)
+++
sling/trunk/testing/org.apache.sling.testing.paxexam/src/main/java/org/apache/sling/testing/paxexam/TestSupport.java
Fri Jul 22 17:27:00 2016
@@ -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()
+ );
+ }
+
+}