You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2018/11/08 21:35:43 UTC
[sling-org-apache-sling-servlets-get] 01/01: SLING-7936 - Execute
module integration tests in the launchpad-testing module
This is an automated email from the ASF dual-hosted git repository.
rombert pushed a commit to branch feature/SLING-7936
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-servlets-get.git
commit b19a9fac4bcfe659ac8c2e91c48e426215eca9cd
Author: Robert Munteanu <ro...@apache.org>
AuthorDate: Thu Nov 8 22:04:44 2018 +0100
SLING-7936 - Execute module integration tests in the launchpad-testing module
Transplant HeadServletTest from the launchpad.tests module. Some initial notes:
- the slingstart-maven-plugin configuration is overly verbose and easy to get
wrong
- we deploy the test.services bundle since we rely on some initial content from
it, but each project should provide its own test content
---
pom.xml | 65 +++++++++++
.../sling/servlets/get/impl/HeadServletIT.java | 120 +++++++++++++++++++++
src/test/provisioning/model.txt | 31 ++++++
3 files changed, 216 insertions(+)
diff --git a/pom.xml b/pom.xml
index bae405c..dee4e96 100644
--- a/pom.xml
+++ b/pom.xml
@@ -76,6 +76,65 @@
</excludePackageNames>
</configuration>
</plugin>
+ <plugin>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>slingstart-maven-plugin</artifactId>
+ <version>1.8.2</version>
+ <extensions>true</extensions>
+ <executions>
+ <execution>
+ <id>prepare-launchpad-package</id>
+ <goals>
+ <goal>prepare-package</goal>
+ </goals>
+ <phase>pre-integration-test</phase>
+ </execution>
+ <execution>
+ <id>build-launchpad-package</id>
+ <goals>
+ <goal>package</goal>
+ </goals>
+ <phase>pre-integration-test</phase>
+ <configuration>
+ <attachArtifact>false</attachArtifact>
+ </configuration>
+ </execution>
+ <execution>
+ <id>start-container</id>
+ <goals>
+ <goal>start</goal>
+ </goals>
+ </execution>
+ <execution>
+ <id>stop-container</id>
+ <goals>
+ <goal>stop</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <!-- this configuration only applies to 'prepare-package' and 'package' -->
+ <disableExtendingMavenClasspath>true</disableExtendingMavenClasspath>
+ <usePomDependencies>true</usePomDependencies>
+ <servers>
+ <server>
+ <port>8080</port>
+ </server>
+ </servers>
+ </configuration>
+ </plugin>
+ <plugin>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ <version>2.21.0</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>integration-test</goal>
+ <goal>verify</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
</plugins>
</build>
<dependencies>
@@ -163,5 +222,11 @@
<type>bundle</type>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.commons.testing</artifactId>
+ <version>2.1.2</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project>
diff --git a/src/test/java/org/apache/sling/servlets/get/impl/HeadServletIT.java b/src/test/java/org/apache/sling/servlets/get/impl/HeadServletIT.java
new file mode 100644
index 0000000..91767d5
--- /dev/null
+++ b/src/test/java/org/apache/sling/servlets/get/impl/HeadServletIT.java
@@ -0,0 +1,120 @@
+/*
+ * 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.launchpad.webapp.integrationtest.servlets;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+import java.util.UUID;
+import java.util.regex.Pattern;
+
+import org.apache.commons.httpclient.Header;
+import org.apache.commons.httpclient.HttpMethod;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.commons.httpclient.methods.HeadMethod;
+import org.apache.sling.commons.testing.integration.HttpTest;
+import org.apache.sling.commons.testing.integration.HttpTestBase;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+/** Test HEAD requests */
+public class HeadServletIT {
+
+ private final HttpTest H = new HttpTest();
+
+ /** Test content provided by the test-services bundle */
+ public static final String HTML_URL = HttpTestBase.HTTP_BASE_URL + "/sling-test/some.html";
+
+ /** Test content provided by the test-services bundle */
+ public static final String PNG_URL = HttpTestBase.HTTP_BASE_URL + "/sling-test/sling-logo.png";
+
+ public static final String NONEXISTENT_URL = HttpTestBase.HTTP_BASE_URL + "/notfound-" + UUID.randomUUID().toString();
+
+ private void assertResponseHeader(HttpMethod m, String name, String expectedRegex) {
+ final Header h = m.getResponseHeader(name);
+ assertNotNull("Expecting header " + name, h);
+ final String value = h.getValue();
+ assertTrue("Expected regexp " + expectedRegex + " for header " + name + ", header value is " + value,
+ Pattern.matches(expectedRegex, value));
+ }
+
+ private void assertCommonHeaders(HttpMethod m, String expectedContentType) {
+ assertResponseHeader(m, "Content-Length", "[0-9][0-9][0-9]+");
+ assertResponseHeader(m, "Content-Type", expectedContentType);
+ assertResponseHeader(m, "Last-Modified", ".*[a-zA-Z0-9]+.*");
+ }
+
+ @Before
+ public void setup() throws Exception {
+ H.setUp();
+ }
+
+ @After
+ public void cleanup() throws Exception {
+ H.tearDown();
+ }
+
+ @Test
+ public void htmlGet() throws IOException {
+ final String content = H.getContent(HTML_URL, HttpTest.CONTENT_TYPE_HTML);
+ HttpTest.assertContains(content, "This is some HTML for testing Sling.");
+ }
+
+ @Test
+ public void htmlHead() throws IOException {
+ final HeadMethod head = new HeadMethod(HTML_URL);
+ final int status = H.getHttpClient().executeMethod(head);
+ assertEquals(200, status);
+ assertNull("Expecting null body", head.getResponseBody());
+ assertCommonHeaders(head, "text/html");
+ }
+
+ @Test
+ public void pngGet() throws IOException {
+ final GetMethod get = new GetMethod(PNG_URL);
+ final int status = H.getHttpClient().executeMethod(get);
+ assertEquals(200, status);
+ assertNotNull(get.getResponseBody());
+ assertTrue("Expecting non-empty body", get.getResponseBody().length > 500);
+ assertCommonHeaders(get, "image/png");
+ }
+
+ @Test
+ public void pngHead() throws IOException {
+ final HeadMethod head = new HeadMethod(PNG_URL);
+ final int status = H.getHttpClient().executeMethod(head);
+ assertEquals(200, status);
+ assertNull("Expecting null body", head.getResponseBody());
+ assertCommonHeaders(head, "image/png");
+ }
+
+ @Test
+ public void nonexistentGet() throws IOException {
+ final GetMethod get = new GetMethod(NONEXISTENT_URL);
+ assertEquals(404, H.getHttpClient().executeMethod(get));
+ }
+
+ @Test
+ public void nonexistentHead() throws IOException {
+ final HeadMethod head = new HeadMethod(NONEXISTENT_URL);
+ assertEquals(404, H.getHttpClient().executeMethod(head));
+ }
+}
diff --git a/src/test/provisioning/model.txt b/src/test/provisioning/model.txt
new file mode 100644
index 0000000..445b577
--- /dev/null
+++ b/src/test/provisioning/model.txt
@@ -0,0 +1,31 @@
+#
+# 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.
+#
+
+# must be the same feature name as the feature defined in slingstart to allow merging
+[feature name=sling]
+# Dependencies
+[artifacts]
+ org.apache.sling/org.apache.sling.starter/12-SNAPSHOT/slingstart
+ org.apache.sling/org.apache.sling.launchpad.test-services/12-SNAPSHOT
+ org.apache.sling/org.apache.sling.launchpad.test-bundles/12-SNAPSHOT/slingfeature
+ org.apache.sling/org.apache.sling.servlets.get
+
+[configurations]
+ org.apache.sling.jcr.base.internal.LoginAdminWhitelist [mode=merge]
+ whitelist.bundles.regexp="org.apache.sling.(launchpad|junit).*"