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 2019/12/20 16:26:10 UTC

[sling-org-apache-sling-servlets-resolver] branch issue/SLING-8936 updated (b2f5309 -> 7b54e56)

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

bdelacretaz pushed a change to branch issue/SLING-8936
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-servlets-resolver.git.


    from b2f5309  SLING-8936 - refactor tests to get a reusable base class
     new 2b3dc83  SLING-8936 - pax exam testing setup
     new 7b54e56  SLING-8936 - setup for executing requests

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 pom.xml                                            | 93 +++++++++++++++++++++-
 .../servlets/resolver/it/DefaultServletIT.java     | 88 ++++++++++++++++++++
 .../resolver/it/ServletResolverTestSupport.java    | 43 ++++++++++
 3 files changed, 223 insertions(+), 1 deletion(-)
 create mode 100644 src/test/java/org/apache/sling/servlets/resolver/it/DefaultServletIT.java
 create mode 100644 src/test/java/org/apache/sling/servlets/resolver/it/ServletResolverTestSupport.java


[sling-org-apache-sling-servlets-resolver] 01/02: SLING-8936 - pax exam testing setup

Posted by bd...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

bdelacretaz pushed a commit to branch issue/SLING-8936
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-servlets-resolver.git

commit 2b3dc835169afc09770219b6eed9017c3fc050f9
Author: Bertrand Delacretaz <bd...@apache.org>
AuthorDate: Fri Dec 20 15:50:19 2019 +0100

    SLING-8936 - pax exam testing setup
---
 pom.xml                                            | 81 +++++++++++++++++++++-
 .../servlets/resolver/it/DefaultServletIT.java     | 49 +++++++++++++
 .../resolver/it/ServletResolverTestSupport.java    | 40 +++++++++++
 3 files changed, 169 insertions(+), 1 deletion(-)

diff --git a/pom.xml b/pom.xml
index d9f4507..81c06ac 100644
--- a/pom.xml
+++ b/pom.xml
@@ -69,6 +69,10 @@
                         <Provide-Capability>
                             osgi.extender;osgi.extender="org.apache.sling.servlets.resolver";version:Version="1.0"
                         </Provide-Capability>
+                        <Include-Resource>
+                            <!-- for SLING-7351 -->
+                            META-INF/maven/dependencies.properties=-${project.build.outputDirectory}/META-INF/maven/dependencies.properties,{maven-resources}
+                        </Include-Resource>
                     </instructions>
                 </configuration>
             </plugin>
@@ -104,6 +108,39 @@
                     </execution>
                 </executions>
             </plugin>
+            <plugin>
+                <groupId>org.apache.servicemix.tooling</groupId>
+                <artifactId>depends-maven-plugin</artifactId>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-failsafe-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <id>integration-test</id>
+                        <phase>integration-test</phase>
+                        <goals>
+                            <goal>integration-test</goal>
+                        </goals>
+                    </execution>
+                    <execution>
+                        <id>verify</id>
+                        <phase>integration-test</phase>
+                        <goals>
+                            <goal>verify</goal>
+                        </goals>
+                    </execution>
+                </executions>
+                <configuration>
+                    <redirectTestOutputToFile>true</redirectTestOutputToFile>
+                    <systemProperties>
+                        <property>
+                        <name>bundle.filename</name>
+                        <value>${basedir}/target/${project.build.finalName}.jar</value>
+                        </property>
+                    </systemProperties>
+                </configuration>
+            </plugin>
         </plugins>
     </build>
     <dependencies>
@@ -132,7 +169,7 @@
         <dependency>
             <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.api</artifactId>
-            <version>2.21.0</version>
+            <version>2.20.0</version>
             <scope>provided</scope>
         </dependency>
         <!-- for ServiceUserMapped (SLING-4312) -->
@@ -219,5 +256,47 @@
             <version>16.0.2</version>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.ops4j.pax.exam</groupId>
+            <artifactId>pax-exam</artifactId>
+            <version>4.13.1</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.ops4j.pax.exam</groupId>
+            <artifactId>pax-exam-cm</artifactId>
+            <version>4.13.1</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.ops4j.pax.exam</groupId>
+            <artifactId>pax-exam-container-forked</artifactId>
+            <version>4.13.1</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.ops4j.pax.exam</groupId>
+            <artifactId>pax-exam-junit4</artifactId>
+            <version>4.13.1</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.ops4j.pax.exam</groupId>
+            <artifactId>pax-exam-link-mvn</artifactId>
+            <version>4.13.1</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.testing.paxexam</artifactId>
+            <version>3.0.0</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.apache.felix.framework</artifactId>
+            <version>6.0.3</version>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 </project>
diff --git a/src/test/java/org/apache/sling/servlets/resolver/it/DefaultServletIT.java b/src/test/java/org/apache/sling/servlets/resolver/it/DefaultServletIT.java
new file mode 100644
index 0000000..accf90e
--- /dev/null
+++ b/src/test/java/org/apache/sling/servlets/resolver/it/DefaultServletIT.java
@@ -0,0 +1,49 @@
+/*
+ * 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.servlets.resolver.it;
+
+import static org.junit.Assert.assertTrue;
+
+import javax.inject.Inject;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.junit.PaxExam;
+import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
+import org.ops4j.pax.exam.spi.reactors.PerClass;
+import org.osgi.framework.BundleContext;
+
+/** Using the SlingRequestProcessor for testing requests would be
+ *  better, but this module has a number of specific settings
+ *  in its pom for the sling.engine module that I prefer not touching
+ *  now as I'm just adding these tests.
+ */
+@RunWith(PaxExam.class)
+@ExamReactorStrategy(PerClass.class)
+public class DefaultServletIT extends ServletResolverTestSupport {
+    @Inject
+    private BundleContext bundleContext;
+
+    @Test
+    public void testDefaultServlet() {
+        // TODO for now this just tests the pax exam setup
+        assertTrue(bundleContext.getBundles().length > 0);
+    }
+
+}
\ No newline at end of file
diff --git a/src/test/java/org/apache/sling/servlets/resolver/it/ServletResolverTestSupport.java b/src/test/java/org/apache/sling/servlets/resolver/it/ServletResolverTestSupport.java
new file mode 100644
index 0000000..9cd7084
--- /dev/null
+++ b/src/test/java/org/apache/sling/servlets/resolver/it/ServletResolverTestSupport.java
@@ -0,0 +1,40 @@
+/*
+ * 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.servlets.resolver.it;
+
+import org.apache.sling.testing.paxexam.TestSupport;
+import org.ops4j.pax.exam.Configuration;
+import org.ops4j.pax.exam.Option;
+
+import static org.ops4j.pax.exam.CoreOptions.junitBundles;
+import static org.apache.sling.testing.paxexam.SlingOptions.slingQuickstartOakTar;
+
+public class ServletResolverTestSupport extends TestSupport {
+    protected final int httpPort = findFreePort();
+
+    @Configuration
+    public Option[] configuration() {
+        return new Option[]{
+            baseConfiguration(),
+            slingQuickstartOakTar(workingDirectory(), httpPort),
+            testBundle("bundle.filename"),
+            junitBundles()
+        };
+    }
+}


[sling-org-apache-sling-servlets-resolver] 02/02: SLING-8936 - setup for executing requests

Posted by bd...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

bdelacretaz pushed a commit to branch issue/SLING-8936
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-servlets-resolver.git

commit 7b54e566353bae9032f971aadc5fbe4a34edcd71
Author: Bertrand Delacretaz <bd...@apache.org>
AuthorDate: Fri Dec 20 17:25:51 2019 +0100

    SLING-8936 - setup for executing requests
---
 pom.xml                                            | 12 +++++
 .../servlets/resolver/it/DefaultServletIT.java     | 55 ++++++++++++++++++----
 .../resolver/it/ServletResolverTestSupport.java    |  3 ++
 3 files changed, 62 insertions(+), 8 deletions(-)

diff --git a/pom.xml b/pom.xml
index 81c06ac..a15c604 100644
--- a/pom.xml
+++ b/pom.xml
@@ -287,6 +287,12 @@
             <scope>test</scope>
         </dependency>
         <dependency>
+            <groupId>org.ops4j.pax.url</groupId>
+            <artifactId>pax-url-wrap</artifactId>
+            <version>2.6.2</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
             <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.testing.paxexam</artifactId>
             <version>3.0.0</version>
@@ -298,5 +304,11 @@
             <version>6.0.3</version>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.servlet-helpers</artifactId>
+            <version>1.3.0</version>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 </project>
diff --git a/src/test/java/org/apache/sling/servlets/resolver/it/DefaultServletIT.java b/src/test/java/org/apache/sling/servlets/resolver/it/DefaultServletIT.java
index accf90e..b289dbd 100644
--- a/src/test/java/org/apache/sling/servlets/resolver/it/DefaultServletIT.java
+++ b/src/test/java/org/apache/sling/servlets/resolver/it/DefaultServletIT.java
@@ -18,32 +18,71 @@
  */
 package org.apache.sling.servlets.resolver.it;
 
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.lang.reflect.Method;
 
 import javax.inject.Inject;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
 
+import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.servlethelpers.MockSlingHttpServletRequest;
+import org.apache.sling.servlethelpers.MockSlingHttpServletResponse;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.ops4j.pax.exam.junit.PaxExam;
 import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
 import org.ops4j.pax.exam.spi.reactors.PerClass;
 import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
 
-/** Using the SlingRequestProcessor for testing requests would be
- *  better, but this module has a number of specific settings
- *  in its pom for the sling.engine module that I prefer not touching
- *  now as I'm just adding these tests.
+/**
+ * Using the SlingRequestProcessor for testing requests would be better, but
+ * this module is using an older version of the sling.engine module that does not
+ * have that, along with a number of specific settings for that module, so I prefer
+ * not touching those now as I'm just adding these tests.
  */
 @RunWith(PaxExam.class)
 @ExamReactorStrategy(PerClass.class)
 public class DefaultServletIT extends ServletResolverTestSupport {
+
     @Inject
     private BundleContext bundleContext;
 
+    private String getContent(String path) throws Exception {
+        final ResourceResolver TODO_NEED_ONE = null;
+        final MockSlingHttpServletRequest request = new MockSlingHttpServletRequest(TODO_NEED_ONE);
+        final MockSlingHttpServletResponse response = new MockSlingHttpServletResponse();
+
+        // Get SlingRequestProcessor.processRequest method and execute request
+        // This module depends on an older version of the sling.engine module and I don't want
+        // to change it just for these tests, so using reflection to get the processor, as we're
+        // running with a more recent version of sling.engine in the pax exam environment
+        final String slingRequestProcessorClassName = "org.apache.sling.engine.SlingRequestProcessor";
+        final ServiceReference<?> ref = bundleContext.getServiceReference(slingRequestProcessorClassName);
+        assertNotNull("Expecting service:" + slingRequestProcessorClassName, ref);
+
+        final Object processor = bundleContext.getService(ref);
+        try {
+            // void processRequest(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse resource, ResourceResolver resourceResolver)
+            final Method processMethod = processor.getClass().getMethod(
+                "processRequest", 
+                HttpServletRequest.class, HttpServletResponse.class, ResourceResolver.class);
+            assertNotNull("Expecting processRequest method", processMethod);
+            processMethod.invoke(processor, request, response, null);
+        } finally {
+            bundleContext.ungetService(ref);
+        }
+
+        return response.getOutputAsString();
+    }
+
     @Test
-    public void testDefaultServlet() {
-        // TODO for now this just tests the pax exam setup
-        assertTrue(bundleContext.getBundles().length > 0);
+    public void testDefaultServlet() throws Exception {
+        final String TODO_SHOULD_NOT_BE_EMPTY = "";
+        assertEquals(TODO_SHOULD_NOT_BE_EMPTY, getContent("/.json"));
     }
 
 }
\ No newline at end of file
diff --git a/src/test/java/org/apache/sling/servlets/resolver/it/ServletResolverTestSupport.java b/src/test/java/org/apache/sling/servlets/resolver/it/ServletResolverTestSupport.java
index 9cd7084..bc4e480 100644
--- a/src/test/java/org/apache/sling/servlets/resolver/it/ServletResolverTestSupport.java
+++ b/src/test/java/org/apache/sling/servlets/resolver/it/ServletResolverTestSupport.java
@@ -23,6 +23,8 @@ import org.ops4j.pax.exam.Configuration;
 import org.ops4j.pax.exam.Option;
 
 import static org.ops4j.pax.exam.CoreOptions.junitBundles;
+import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
+import static org.ops4j.pax.exam.CoreOptions.wrappedBundle;
 import static org.apache.sling.testing.paxexam.SlingOptions.slingQuickstartOakTar;
 
 public class ServletResolverTestSupport extends TestSupport {
@@ -34,6 +36,7 @@ public class ServletResolverTestSupport extends TestSupport {
             baseConfiguration(),
             slingQuickstartOakTar(workingDirectory(), httpPort),
             testBundle("bundle.filename"),
+            wrappedBundle(mavenBundle().groupId("org.apache.sling").artifactId("org.apache.sling.servlet-helpers").versionAsInProject()),
             junitBundles()
         };
     }