This is an automated email from the ASF dual-hosted git repository.
bdelacretaz pushed a commit to branch master
in repository
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-paxexam.git
The following commit(s) were added to refs/heads/master by this push:
new a5d3b29 SLING-9929 - add HTTP-based test
a5d3b29 is described below
commit a5d3b29e580dd7927755a056c20c83453793332c
Author: Bertrand Delacretaz <[email protected]>
AuthorDate: Tue Mar 16 16:40:16 2021 +0100
SLING-9929 - add HTTP-based test
---
pom.xml | 22 +++++
.../it/tests/SlingOptionsPaxExamServerIT.java | 94 ++++++++++++++++++++++
2 files changed, 116 insertions(+)
diff --git a/pom.xml b/pom.xml
index e226722..6fbc3dd 100644
--- a/pom.xml
+++ b/pom.xml
@@ -39,6 +39,7 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<sling.java.version>8</sling.java.version>
<org.ops4j.pax.exam.version>4.13.3</org.ops4j.pax.exam.version>
+ <pax.vm.options/>
</properties>
<scm>
@@ -76,9 +77,18 @@
<name>bundle.filename</name>
<value>${basedir}/target/${project.build.finalName}.jar</value>
</property>
+ <property>
+ <name>pax.vm.options</name>
+ <value>${pax.vm.options}</value>
+ </property>
</systemProperties>
</configuration>
</plugin>
+ <plugin>
+ <!-- Needed for mavenBundle..versionAsInProject() -->
+ <groupId>org.apache.servicemix.tooling</groupId>
+ <artifactId>depends-maven-plugin</artifactId>
+ </plugin>
</plugins>
</build>
@@ -164,6 +174,18 @@
<version>2.6.2</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.ops4j.pax.logging</groupId>
+ <artifactId>pax-logging-api</artifactId>
+ <version>2.0.6</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.ops4j.pax.logging</groupId>
+ <artifactId>pax-logging-logback</artifactId>
+ <version>2.0.6</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project>
diff --git
a/src/test/java/org/apache/sling/testing/paxexam/it/tests/SlingOptionsPaxExamServerIT.java
b/src/test/java/org/apache/sling/testing/paxexam/it/tests/SlingOptionsPaxExamServerIT.java
new file mode 100644
index 0000000..2027560
--- /dev/null
+++
b/src/test/java/org/apache/sling/testing/paxexam/it/tests/SlingOptionsPaxExamServerIT.java
@@ -0,0 +1,94 @@
+/*
+ * 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.it.tests;
+
+import org.apache.sling.testing.paxexam.TestSupport;
+import org.junit.ClassRule;
+import org.junit.Test;
+import org.ops4j.pax.exam.Configuration;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.PaxExamServer;
+import org.ops4j.pax.exam.options.ModifiableCompositeOption;
+import org.ops4j.pax.exam.options.extra.VMOption;
+
+import static org.junit.Assert.assertEquals;
+import static org.ops4j.pax.exam.CoreOptions.composite;
+import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
+import static org.ops4j.pax.exam.CoreOptions.options;
+import static org.ops4j.pax.exam.CoreOptions.when;
+import static org.ops4j.pax.exam.CoreOptions.systemProperty;
+
+import static org.apache.sling.testing.paxexam.SlingOptions.http;
+import static org.apache.sling.testing.paxexam.SlingOptions.webconsole;
+
+import java.io.IOException;
+import java.net.HttpURLConnection;
+import java.net.URL;
+
+/** Demonstrate HTTP-based integration testing with Pax Exam.
+ *
+ * The PaxExamServer rule starts an OSGi framework instance that
+ * our tests access via HTTP.
+ *
+ * For debugging, note that our tests run in the maven-failsafe-plugin
+ * JVM process, that can be setup for debugging with Dmaven.failsafe.debug
+ * and the OSGi framework in a different JVM process, that can be setup for
+ * debugging using the pax.vm.options system property.
+ */
+public class SlingOptionsPaxExamServerIT extends TestSupport {
+
+ private static final int httpPort = findFreePort();
+
+ @ClassRule
+ public static PaxExamServer serverRule = new PaxExamServer();
+
+ @Configuration
+ public Option[] configuration() {
+ final String vmOptStr = System.getProperty("pax.vm.options");
+ final VMOption vmOption = ( vmOptStr == null ||
vmOptStr.trim().length() == 0 ) ? null : new VMOption(vmOptStr);
+
+ return options(
+ when(vmOption != null).useOptions(vmOption),
+ serverBaseConfiguration(),
+ http(),
+ webconsole(),
+ paxLogging(),
+
+ // For some reason, Jetty starts first on port 8080 without this
+
systemProperty("org.osgi.service.http.port").value(String.valueOf(httpPort))
+ );
+ }
+
+ public static ModifiableCompositeOption paxLogging() {
+ return composite(
+
mavenBundle().groupId("org.ops4j.pax.logging").artifactId("pax-logging-api").versionAsInProject(),
+
mavenBundle().groupId("org.ops4j.pax.logging").artifactId("pax-logging-logback").versionAsInProject()
+ );
+ }
+
+ @Test
+ public void testHttpAccess() throws IOException {
+ final URL url = new
URL(String.format("http://localhost:%d/system/console", httpPort));
+ final HttpURLConnection c = (HttpURLConnection)url.openConnection();
+ final String base64EncodedAdminAdmin = "YWRtaW46YWRtaW4=";
+ c.setRequestProperty ("Authorization", "Basic " +
base64EncodedAdminAdmin);
+ assertEquals(200, c.getResponseCode());
+ }
+
+}
\ No newline at end of file