You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ol...@apache.org on 2017/12/22 15:21:17 UTC

[sling-org-apache-sling-testing-paxexam] 04/11: refactor option test support to allow testing without configuration admin

This is an automated email from the ASF dual-hosted git repository.

olli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-paxexam.git

commit 4d357e1aeba533712e2152becdf98c8a8146b029
Author: Oliver Lietz <ol...@apache.org>
AuthorDate: Fri Dec 22 12:11:51 2017 +0100

    refactor option test support to allow testing without configuration admin
---
 .../paxexam/SlingOptionsHttpTestSupport.java       | 50 ++++++++++++++++++++++
 .../testing/paxexam/SlingOptionsTestSupport.java   | 32 +++++++++++++-
 2 files changed, 80 insertions(+), 2 deletions(-)

diff --git a/src/test/java/org/apache/sling/testing/paxexam/SlingOptionsHttpTestSupport.java b/src/test/java/org/apache/sling/testing/paxexam/SlingOptionsHttpTestSupport.java
new file mode 100644
index 0000000..c581914
--- /dev/null
+++ b/src/test/java/org/apache/sling/testing/paxexam/SlingOptionsHttpTestSupport.java
@@ -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.paxexam;
+
+import java.io.IOException;
+import java.net.ServerSocket;
+import java.util.Dictionary;
+
+import javax.inject.Inject;
+
+import org.osgi.service.cm.ConfigurationAdmin;
+
+public abstract class SlingOptionsHttpTestSupport extends SlingOptionsTestSupport {
+
+    @Inject
+    protected ConfigurationAdmin configurationAdmin;
+
+    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());
+    }
+
+}
diff --git a/src/test/java/org/apache/sling/testing/paxexam/SlingOptionsTestSupport.java b/src/test/java/org/apache/sling/testing/paxexam/SlingOptionsTestSupport.java
index f3dcff2..00e73af 100644
--- a/src/test/java/org/apache/sling/testing/paxexam/SlingOptionsTestSupport.java
+++ b/src/test/java/org/apache/sling/testing/paxexam/SlingOptionsTestSupport.java
@@ -18,15 +18,26 @@
  */
 package org.apache.sling.testing.paxexam;
 
+import java.io.File;
+
 import org.ops4j.pax.exam.CoreOptions;
 import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.util.PathUtils;
 
+import static org.ops4j.pax.exam.CoreOptions.bundle;
 import static org.ops4j.pax.exam.CoreOptions.composite;
 import static org.ops4j.pax.exam.CoreOptions.keepCaches;
+import static org.ops4j.pax.exam.CoreOptions.systemProperty;
+import static org.ops4j.pax.exam.CoreOptions.when;
+
+public abstract class SlingOptionsTestSupport {
+
+    private final String workingDirectory = String.format("%s/target/paxexam/%s", PathUtils.getBaseDir(), getClass().getSimpleName());
 
-public abstract class SlingOptionsTestSupport extends TestSupport {
+    protected String workingDirectory() {
+        return workingDirectory;
+    }
 
-    @Override
     protected Option baseConfiguration() {
         return composite(
             failOnUnresolvedBundles(),
@@ -37,4 +48,21 @@ public abstract class SlingOptionsTestSupport extends TestSupport {
         );
     }
 
+    protected Option failOnUnresolvedBundles() {
+        return systemProperty("pax.exam.osgi.unresolved.fail").value("true");
+    }
+
+    protected Option localMavenRepo() {
+        final String localRepository = System.getProperty("maven.repo.local", ""); // PAXEXAM-543
+        return when(localRepository.length() > 0).useOptions(
+            systemProperty("org.ops4j.pax.url.mvn.localRepository").value(localRepository)
+        );
+    }
+
+    protected Option testBundle(final String systemProperty) {
+        final String filename = System.getProperty(systemProperty);
+        final File file = new File(filename);
+        return bundle(file.toURI().toString());
+    }
+
 }

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.