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 2020/11/24 11:00:18 UTC
[sling-org-apache-sling-servlets-annotations] branch master
updated: SLING-9930 move tests here from the sling-servlets-annotations-it
module
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-servlets-annotations.git
The following commit(s) were added to refs/heads/master by this push:
new 8c5fb2b SLING-9930 move tests here from the sling-servlets-annotations-it module
8c5fb2b is described below
commit 8c5fb2becdb6cd79ff1798a041400829af3e5229
Author: Bertrand Delacretaz <bd...@apache.org>
AuthorDate: Tue Nov 24 11:59:42 2020 +0100
SLING-9930 move tests here from the sling-servlets-annotations-it module
---
pom.xml | 62 +++++++
src/it/annotations-it/README.md | 9 +
src/it/annotations-it/bnd.bnd | 6 +
src/it/annotations-it/invoker.properties | 17 ++
src/it/annotations-it/pom.xml | 204 +++++++++++++++++++++
.../annotations/services/PathBoundService.java | 25 +++
.../services/PathBoundStrictAllOptionsService.java | 30 +++
.../services/PathBoundStrictJustPathService.java | 25 +++
.../testservletfilters/SimpleServletFilter.java | 63 +++++++
.../BaseResourceTypeBoundServletWithSelectors.java | 45 +++++
.../InheritingResourceTypeBoundServlet.java | 45 +++++
.../annotations/testservlets/PathBoundServlet.java | 53 ++++++
.../testservlets/PathBoundServletWithPrefix.java | 45 +++++
.../testservlets/ResourceTypeBoundServlet.java | 48 +++++
.../ResourceTypeBoundServletWithExtension.java | 48 +++++
.../ResourceTypeBoundServletWithMethods.java | 53 ++++++
.../ResourceTypeBoundServletWithPrefix.java | 50 +++++
.../ResourceTypeBoundServletWithSelectors.java | 48 +++++
.../SLING-CONTENT/content/servlettest.json | 3 +
.../baseResourceTypeBoundServletWithSelectors.json | 4 +
.../inheritingResourceTypeBoundServlet.json | 4 +
.../servlettest/resourceTypeBoundServlet.json | 4 +
.../resourceTypeBoundServletWithExtension.json | 4 +
.../resourceTypeBoundServletWithMethods.json | 4 +
.../resourceTypeBoundServletWithPrefix.json | 4 +
.../resourceTypeBoundServletWithSelectors.json | 4 +
.../annotations/AnnotationsTestSupport.java | 103 +++++++++++
.../servlets/annotations/ServicePropertiesIT.java | 116 ++++++++++++
.../annotations/ServletRegistrationIT.java | 115 ++++++++++++
.../annotations-it/src/test/resources/logback.xml | 32 ++++
src/it/settings.xml | 59 ++++++
31 files changed, 1332 insertions(+)
diff --git a/pom.xml b/pom.xml
index f1366a4..26a4df4 100644
--- a/pom.xml
+++ b/pom.xml
@@ -39,6 +39,68 @@
<sling.java.version>7</sling.java.version>
</properties>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-invoker-plugin</artifactId>
+ <version>3.2.1</version>
+ <configuration>
+ <debug>false</debug>
+ <projectsDirectory>src/it</projectsDirectory>
+ <cloneProjectsTo>${project.build.directory}/it</cloneProjectsTo>
+ <pomIncludes>
+ <pomInclude>*/pom.xml</pomInclude>
+ </pomIncludes>
+ <postBuildHookScript>verify</postBuildHookScript>
+ <localRepositoryPath>${project.build.directory}/it-repo</localRepositoryPath>
+ <settingsFile>src/it/settings.xml</settingsFile>
+ <!-- this causes verbose output, probably good to have for CI builds? -->
+ <streamLogs>true</streamLogs>
+ </configuration>
+ <dependencies>
+ <dependency>
+ <groupId>org.codehaus.groovy</groupId>
+ <artifactId>groovy</artifactId>
+ <version>3.0.6</version>
+ </dependency>
+ </dependencies>
+ <executions>
+ <execution>
+ <id>integration-test</id>
+ <goals>
+ <goal>install</goal>
+ <goal>integration-test</goal>
+ <goal>verify</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.rat</groupId>
+ <artifactId>apache-rat-plugin</artifactId>
+ <configuration>
+ <excludes>
+ <exclude>src/it/annotations-it/target/**</exclude>
+ <exclude>src/it/annotations-it/README.md</exclude>
+ <exclude>src/it/annotations-it/bnd.bnd</exclude>
+ <exclude>src/it/annotations-it/build.log</exclude>
+ </excludes>
+ </configuration>
+ </plugin>
+ <plugin>
+ <artifactId>maven-clean-plugin</artifactId>
+ <configuration>
+ <filesets>
+ <fileset>
+ <directory>src/it/annotations-it/target</directory>
+ </fileset>
+ </filesets>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
<dependencies>
<!-- all transitive dependencies should have scope "provided" to prevent classpath
pollution of referencing projects -->
diff --git a/src/it/annotations-it/README.md b/src/it/annotations-it/README.md
new file mode 100644
index 0000000..1fc2d1d
--- /dev/null
+++ b/src/it/annotations-it/README.md
@@ -0,0 +1,9 @@
+Integration tests for the servlets annotations module.
+
+These could be simplified using a verify script for the
+generated annotations, as in the sling-org-apache-sling-adapter-annotations
+module.
+
+Also, the ServletRegistrationIT should move to the servlets
+resolver module, as it's really testing it and not just
+our annotations.
\ No newline at end of file
diff --git a/src/it/annotations-it/bnd.bnd b/src/it/annotations-it/bnd.bnd
new file mode 100644
index 0000000..539b4ad
--- /dev/null
+++ b/src/it/annotations-it/bnd.bnd
@@ -0,0 +1,6 @@
+Sling-Initial-Content: SLING-CONTENT/content/servlettest;overwrite:=true;path:=/content/servlettest
+
+# This simulates using the right version of the servlets resolver bundle,
+# for the SlingServletPathsStrict annotation
+Provide-Capability:\
+ osgi.extender;osgi.extender="org.apache.sling.servlets.resolver";version:Version="1.1"
\ No newline at end of file
diff --git a/src/it/annotations-it/invoker.properties b/src/it/annotations-it/invoker.properties
new file mode 100644
index 0000000..b9bcb58
--- /dev/null
+++ b/src/it/annotations-it/invoker.properties
@@ -0,0 +1,17 @@
+# 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.
+
+invoker.goals = clean verify -Dannotations.bundle.version=${project.version} -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=WARN
+invoker.debug = false
\ No newline at end of file
diff --git a/src/it/annotations-it/pom.xml b/src/it/annotations-it/pom.xml
new file mode 100644
index 0000000..22bc895
--- /dev/null
+++ b/src/it/annotations-it/pom.xml
@@ -0,0 +1,204 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- 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. -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>sling</artifactId>
+ <version>33</version>
+ <relativePath/>
+ </parent>
+
+ <artifactId>org.apache.sling.servlets.annotations.it</artifactId>
+ <version>3.0.0</version>
+
+ <name>Apache Sling Servlets Annotations IT</name>
+ <description>
+ Integration tests for OSGi DS 1.4 component property type annotations for Sling servlets and filters
+ </description>
+
+ <!-- compile with java 7 -->
+ <properties>
+ <sling.java.version>8</sling.java.version>
+ <org.ops4j.pax.exam.version>4.13.3</org.ops4j.pax.exam.version>
+ <!-- additional options that can be passed to Pax before executing the tests -->
+ <pax.vm.options />
+ <bundle.filename>${basedir}/target/${project.build.finalName}.jar</bundle.filename>
+ <annotations.bundle.version>MUST_BE_SET_BY_INVOKER</annotations.bundle.version>
+ </properties>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ <version>3.0.0-M5</version>
+ </plugin>
+ <plugin>
+ <groupId>biz.aQute.bnd</groupId>
+ <artifactId>bnd-maven-plugin</artifactId>
+ <version>5.0.0</version>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ <executions>
+ <execution>
+ <goals>
+ <goal>integration-test</goal>
+ <goal>verify</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <systemPropertyVariables>
+ <bundle.filename>${bundle.filename}</bundle.filename>
+ <pax.vm.options>${pax.vm.options}</pax.vm.options>
+ </systemPropertyVariables>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.servicemix.tooling</groupId>
+ <artifactId>depends-maven-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.rat</groupId>
+ <artifactId>apache-rat-plugin</artifactId>
+ <configuration>
+ <excludes>
+ <exclude>build.log</exclude>
+ </excludes>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <dependencies>
+ <!-- dependency under test -->
+ <dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.servlets.annotations</artifactId>
+ <version>${annotations.bundle.version}</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.service.component.annotations</artifactId>
+ <version>1.3.0</version><!-- to be compliant with DS 1.3 -->
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.api</artifactId>
+ <version>2.20.0</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>javax.servlet-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
+ <!-- testing dependencies -->
+ <dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.servlets.resolver</artifactId>
+ <version>2.5.2</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.testing.clients</artifactId>
+ <!-- for https://issues.apache.org/jira/browse/SLING-7680 -->
+ <version>1.2.1-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.testing.rules</artifactId>
+ <version>1.0.8</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-simple</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>osgi.core</artifactId>
+ <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>
+ <dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.testing.paxexam</artifactId>
+ <version>3.1.0</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.ops4j.pax.exam</groupId>
+ <artifactId>pax-exam</artifactId>
+ <version>${org.ops4j.pax.exam.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.ops4j.pax.exam</groupId>
+ <artifactId>pax-exam-cm</artifactId>
+ <version>${org.ops4j.pax.exam.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.ops4j.pax.exam</groupId>
+ <artifactId>pax-exam-container-forked</artifactId>
+ <version>${org.ops4j.pax.exam.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.ops4j.pax.exam</groupId>
+ <artifactId>pax-exam-junit4</artifactId>
+ <version>${org.ops4j.pax.exam.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.ops4j.pax.exam</groupId>
+ <artifactId>pax-exam-link-mvn</artifactId>
+ <version>${org.ops4j.pax.exam.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.ops4j.pax.url</groupId>
+ <artifactId>pax-url-wrap</artifactId>
+ <version>2.3.0</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+</project>
diff --git a/src/it/annotations-it/src/main/java/org/apache/sling/servlets/annotations/services/PathBoundService.java b/src/it/annotations-it/src/main/java/org/apache/sling/servlets/annotations/services/PathBoundService.java
new file mode 100644
index 0000000..3e37c06
--- /dev/null
+++ b/src/it/annotations-it/src/main/java/org/apache/sling/servlets/annotations/services/PathBoundService.java
@@ -0,0 +1,25 @@
+/*
+ * 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.annotations.services;
+
+import org.apache.sling.servlets.annotations.SlingServletPaths;
+import org.osgi.service.component.annotations.Component;
+
+@Component(service=Object.class)
+@SlingServletPaths("PathBoundServicePath")
+public class PathBoundService {
+}
diff --git a/src/it/annotations-it/src/main/java/org/apache/sling/servlets/annotations/services/PathBoundStrictAllOptionsService.java b/src/it/annotations-it/src/main/java/org/apache/sling/servlets/annotations/services/PathBoundStrictAllOptionsService.java
new file mode 100644
index 0000000..93aa9c6
--- /dev/null
+++ b/src/it/annotations-it/src/main/java/org/apache/sling/servlets/annotations/services/PathBoundStrictAllOptionsService.java
@@ -0,0 +1,30 @@
+/*
+ * 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.annotations.services;
+
+import org.apache.sling.servlets.annotations.SlingServletPathsStrict;
+import org.osgi.service.component.annotations.Component;
+
+@Component(service=Object.class)
+@SlingServletPathsStrict(
+ paths = {"P1","P2"},
+ selectors = { "S1", "S2"},
+ extensions = { "E1", "E2"},
+ methods = { "M1", "M2"}
+)
+public class PathBoundStrictAllOptionsService {
+}
diff --git a/src/it/annotations-it/src/main/java/org/apache/sling/servlets/annotations/services/PathBoundStrictJustPathService.java b/src/it/annotations-it/src/main/java/org/apache/sling/servlets/annotations/services/PathBoundStrictJustPathService.java
new file mode 100644
index 0000000..c32f5ca
--- /dev/null
+++ b/src/it/annotations-it/src/main/java/org/apache/sling/servlets/annotations/services/PathBoundStrictJustPathService.java
@@ -0,0 +1,25 @@
+/*
+ * 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.annotations.services;
+
+import org.apache.sling.servlets.annotations.SlingServletPathsStrict;
+import org.osgi.service.component.annotations.Component;
+
+@Component(service=Object.class)
+@SlingServletPathsStrict(paths = "JustThePath")
+public class PathBoundStrictJustPathService {
+}
diff --git a/src/it/annotations-it/src/main/java/org/apache/sling/servlets/annotations/testservletfilters/SimpleServletFilter.java b/src/it/annotations-it/src/main/java/org/apache/sling/servlets/annotations/testservletfilters/SimpleServletFilter.java
new file mode 100644
index 0000000..b7c653a
--- /dev/null
+++ b/src/it/annotations-it/src/main/java/org/apache/sling/servlets/annotations/testservletfilters/SimpleServletFilter.java
@@ -0,0 +1,63 @@
+/*
+ * 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.annotations.testservletfilters;
+
+import java.io.IOException;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+
+import org.apache.sling.api.SlingHttpServletRequest;
+import org.apache.sling.api.SlingHttpServletResponse;
+import org.apache.sling.servlets.annotations.SlingServletFilter;
+import org.apache.sling.servlets.annotations.SlingServletFilterScope;
+import org.osgi.service.component.annotations.Component;
+
+@Component
+@SlingServletFilter(scope=SlingServletFilterScope.REQUEST)
+public class SimpleServletFilter implements Filter {
+
+ @Override
+ public void init(FilterConfig filterConfig) throws ServletException {
+ }
+
+ @Override
+ public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
+ chain.doFilter(request, response);
+ if ((request instanceof SlingHttpServletRequest) && (response instanceof SlingHttpServletResponse)) {
+ afterDoFilter((SlingHttpServletRequest) request, (SlingHttpServletResponse) response, chain);
+ } else {
+ throw new ServletException("Not a Sling HTTP request/response");
+ }
+ }
+
+ private void afterDoFilter(SlingHttpServletRequest request, SlingHttpServletResponse response, FilterChain chain) {
+ if (request.getRequestURI().endsWith("simplefilter")) {
+ // increase status by 1
+ response.setStatus(response.getStatus()+1);
+ }
+ }
+
+ @Override
+ public void destroy() {
+ }
+
+}
diff --git a/src/it/annotations-it/src/main/java/org/apache/sling/servlets/annotations/testservlets/BaseResourceTypeBoundServletWithSelectors.java b/src/it/annotations-it/src/main/java/org/apache/sling/servlets/annotations/testservlets/BaseResourceTypeBoundServletWithSelectors.java
new file mode 100644
index 0000000..331360b
--- /dev/null
+++ b/src/it/annotations-it/src/main/java/org/apache/sling/servlets/annotations/testservlets/BaseResourceTypeBoundServletWithSelectors.java
@@ -0,0 +1,45 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ~ 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.annotations.testservlets;
+
+import java.io.IOException;
+
+import javax.servlet.Servlet;
+import javax.servlet.ServletException;
+
+import org.apache.sling.api.SlingHttpServletRequest;
+import org.apache.sling.api.SlingHttpServletResponse;
+import org.apache.sling.api.servlets.SlingSafeMethodsServlet;
+import org.apache.sling.servlets.annotations.SlingServletResourceTypes;
+import org.osgi.service.component.annotations.Component;
+
+@Component(
+ service = Servlet.class
+)
+@SlingServletResourceTypes(
+ resourceTypes = "sling/testservlets/BaseResourceTypeBoundServletWithSelectors",
+ selectors = {"sel1", "sel2"}
+)
+public class BaseResourceTypeBoundServletWithSelectors extends SlingSafeMethodsServlet {
+
+ @Override
+ protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) {
+ response.setStatus(610);
+ }
+}
diff --git a/src/it/annotations-it/src/main/java/org/apache/sling/servlets/annotations/testservlets/InheritingResourceTypeBoundServlet.java b/src/it/annotations-it/src/main/java/org/apache/sling/servlets/annotations/testservlets/InheritingResourceTypeBoundServlet.java
new file mode 100644
index 0000000..93e69f7
--- /dev/null
+++ b/src/it/annotations-it/src/main/java/org/apache/sling/servlets/annotations/testservlets/InheritingResourceTypeBoundServlet.java
@@ -0,0 +1,45 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ~ 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.annotations.testservlets;
+
+import java.io.IOException;
+
+import javax.servlet.Servlet;
+import javax.servlet.ServletException;
+
+import org.apache.sling.api.SlingHttpServletRequest;
+import org.apache.sling.api.SlingHttpServletResponse;
+import org.apache.sling.api.servlets.SlingSafeMethodsServlet;
+import org.apache.sling.servlets.annotations.SlingServletResourceTypes;
+import org.osgi.service.component.annotations.Component;
+
+@Component(
+ service = Servlet.class
+)
+@SlingServletResourceTypes(
+ resourceTypes = "sling/testservlets/InheritingResourceTypeBoundServlet",
+ resourceSuperType = "sling/testservlets/BaseResourceTypeBoundServletWithSelectors"
+)
+public class InheritingResourceTypeBoundServlet extends SlingSafeMethodsServlet {
+
+ @Override
+ protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {
+ response.setStatus(620);
+ }
+}
diff --git a/src/it/annotations-it/src/main/java/org/apache/sling/servlets/annotations/testservlets/PathBoundServlet.java b/src/it/annotations-it/src/main/java/org/apache/sling/servlets/annotations/testservlets/PathBoundServlet.java
new file mode 100644
index 0000000..baf7e28
--- /dev/null
+++ b/src/it/annotations-it/src/main/java/org/apache/sling/servlets/annotations/testservlets/PathBoundServlet.java
@@ -0,0 +1,53 @@
+/*
+ * 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.annotations.testservlets;
+
+import java.io.IOException;
+
+import javax.servlet.Servlet;
+import javax.servlet.ServletException;
+
+import org.apache.sling.api.SlingHttpServletRequest;
+import org.apache.sling.api.SlingHttpServletResponse;
+import org.apache.sling.api.servlets.SlingAllMethodsServlet;
+import org.apache.sling.servlets.annotations.SlingServletPaths;
+import org.osgi.service.component.annotations.Component;
+
+@Component(service=Servlet.class)
+@SlingServletPaths("/bin/PathBoundServlet")
+public class PathBoundServlet extends SlingAllMethodsServlet {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {
+ response.setStatus(555);
+ }
+
+ @Override
+ protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {
+ response.setStatus(556);
+ }
+
+ @Override
+ protected void doPut(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {
+ response.setStatus(557);
+ }
+}
diff --git a/src/it/annotations-it/src/main/java/org/apache/sling/servlets/annotations/testservlets/PathBoundServletWithPrefix.java b/src/it/annotations-it/src/main/java/org/apache/sling/servlets/annotations/testservlets/PathBoundServletWithPrefix.java
new file mode 100644
index 0000000..91d5b23
--- /dev/null
+++ b/src/it/annotations-it/src/main/java/org/apache/sling/servlets/annotations/testservlets/PathBoundServletWithPrefix.java
@@ -0,0 +1,45 @@
+/*
+ * 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.annotations.testservlets;
+
+import java.io.IOException;
+
+import javax.servlet.Servlet;
+import javax.servlet.ServletException;
+
+import org.apache.sling.api.SlingHttpServletRequest;
+import org.apache.sling.api.SlingHttpServletResponse;
+import org.apache.sling.api.servlets.SlingSafeMethodsServlet;
+import org.apache.sling.servlets.annotations.SlingServletPaths;
+import org.apache.sling.servlets.annotations.SlingServletPrefix;
+import org.osgi.service.component.annotations.Component;
+
+@Component(service=Servlet.class)
+@SlingServletPrefix("/bin/")
+@SlingServletPaths("PathBoundServletWithPrefix")
+public class PathBoundServletWithPrefix extends SlingSafeMethodsServlet {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {
+ response.setStatus(610);
+ }
+}
diff --git a/src/it/annotations-it/src/main/java/org/apache/sling/servlets/annotations/testservlets/ResourceTypeBoundServlet.java b/src/it/annotations-it/src/main/java/org/apache/sling/servlets/annotations/testservlets/ResourceTypeBoundServlet.java
new file mode 100644
index 0000000..f6774b5
--- /dev/null
+++ b/src/it/annotations-it/src/main/java/org/apache/sling/servlets/annotations/testservlets/ResourceTypeBoundServlet.java
@@ -0,0 +1,48 @@
+/*
+ * 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.annotations.testservlets;
+
+import java.io.IOException;
+
+import javax.servlet.Servlet;
+import javax.servlet.ServletException;
+
+import org.apache.sling.api.SlingHttpServletRequest;
+import org.apache.sling.api.SlingHttpServletResponse;
+import org.apache.sling.api.servlets.SlingAllMethodsServlet;
+import org.apache.sling.servlets.annotations.SlingServletResourceTypes;
+import org.osgi.service.component.annotations.Component;
+
+@Component(service=Servlet.class)
+@SlingServletResourceTypes(resourceTypes="/apps/sling/testservlets/ResourceTypeBoundServlet")
+public class ResourceTypeBoundServlet extends SlingAllMethodsServlet {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {
+ response.setStatus(560);
+ }
+
+ @Override
+ protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {
+ response.setStatus(561);
+ }
+}
diff --git a/src/it/annotations-it/src/main/java/org/apache/sling/servlets/annotations/testservlets/ResourceTypeBoundServletWithExtension.java b/src/it/annotations-it/src/main/java/org/apache/sling/servlets/annotations/testservlets/ResourceTypeBoundServletWithExtension.java
new file mode 100644
index 0000000..2efc6fe
--- /dev/null
+++ b/src/it/annotations-it/src/main/java/org/apache/sling/servlets/annotations/testservlets/ResourceTypeBoundServletWithExtension.java
@@ -0,0 +1,48 @@
+/*
+ * 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.annotations.testservlets;
+
+import java.io.IOException;
+
+import javax.servlet.Servlet;
+import javax.servlet.ServletException;
+
+import org.apache.sling.api.SlingHttpServletRequest;
+import org.apache.sling.api.SlingHttpServletResponse;
+import org.apache.sling.api.servlets.SlingAllMethodsServlet;
+import org.apache.sling.servlets.annotations.SlingServletResourceTypes;
+import org.osgi.service.component.annotations.Component;
+
+@Component(service=Servlet.class)
+@SlingServletResourceTypes(resourceTypes="/apps/sling/testservlets/ResourceTypeBoundServletWithExtension", extensions= {"ext1", "ext2"}, methods= {"PUT", "GET"})
+public class ResourceTypeBoundServletWithExtension extends SlingAllMethodsServlet {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {
+ response.setStatus(570);
+ }
+
+ @Override
+ protected void doPut(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {
+ response.setStatus(571);
+ }
+}
diff --git a/src/it/annotations-it/src/main/java/org/apache/sling/servlets/annotations/testservlets/ResourceTypeBoundServletWithMethods.java b/src/it/annotations-it/src/main/java/org/apache/sling/servlets/annotations/testservlets/ResourceTypeBoundServletWithMethods.java
new file mode 100644
index 0000000..7cb5d5e
--- /dev/null
+++ b/src/it/annotations-it/src/main/java/org/apache/sling/servlets/annotations/testservlets/ResourceTypeBoundServletWithMethods.java
@@ -0,0 +1,53 @@
+/*
+ * 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.annotations.testservlets;
+
+import java.io.IOException;
+
+import javax.servlet.Servlet;
+import javax.servlet.ServletException;
+
+import org.apache.sling.api.SlingHttpServletRequest;
+import org.apache.sling.api.SlingHttpServletResponse;
+import org.apache.sling.api.servlets.SlingAllMethodsServlet;
+import org.apache.sling.servlets.annotations.SlingServletResourceTypes;
+import org.osgi.service.component.annotations.Component;
+
+@Component(service=Servlet.class)
+@SlingServletResourceTypes(resourceTypes="/apps/sling/testservlets/ResourceTypeBoundServletWithMethods", methods= {"PUT", "POST"})
+public class ResourceTypeBoundServletWithMethods extends SlingAllMethodsServlet {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {
+ response.setStatus(580);
+ }
+
+ @Override
+ protected void doPut(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {
+ response.setStatus(581);
+ }
+
+ @Override
+ protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {
+ response.setStatus(582);
+ }
+}
diff --git a/src/it/annotations-it/src/main/java/org/apache/sling/servlets/annotations/testservlets/ResourceTypeBoundServletWithPrefix.java b/src/it/annotations-it/src/main/java/org/apache/sling/servlets/annotations/testservlets/ResourceTypeBoundServletWithPrefix.java
new file mode 100644
index 0000000..fe57258
--- /dev/null
+++ b/src/it/annotations-it/src/main/java/org/apache/sling/servlets/annotations/testservlets/ResourceTypeBoundServletWithPrefix.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.servlets.annotations.testservlets;
+
+import java.io.IOException;
+
+import javax.servlet.Servlet;
+import javax.servlet.ServletException;
+
+import org.apache.sling.api.SlingHttpServletRequest;
+import org.apache.sling.api.SlingHttpServletResponse;
+import org.apache.sling.api.servlets.SlingAllMethodsServlet;
+import org.apache.sling.servlets.annotations.SlingServletPrefix;
+import org.apache.sling.servlets.annotations.SlingServletResourceTypes;
+import org.osgi.service.component.annotations.Component;
+
+@Component(service=Servlet.class)
+@SlingServletPrefix("/apps/sling/testservlets/")
+@SlingServletResourceTypes(resourceTypes="ResourceTypeBoundServletWithPrefix")
+public class ResourceTypeBoundServletWithPrefix extends SlingAllMethodsServlet {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {
+ response.setStatus(590);
+ }
+
+ @Override
+ protected void doPut(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {
+ response.setStatus(591);
+ }
+}
diff --git a/src/it/annotations-it/src/main/java/org/apache/sling/servlets/annotations/testservlets/ResourceTypeBoundServletWithSelectors.java b/src/it/annotations-it/src/main/java/org/apache/sling/servlets/annotations/testservlets/ResourceTypeBoundServletWithSelectors.java
new file mode 100644
index 0000000..74d3051
--- /dev/null
+++ b/src/it/annotations-it/src/main/java/org/apache/sling/servlets/annotations/testservlets/ResourceTypeBoundServletWithSelectors.java
@@ -0,0 +1,48 @@
+/*
+ * 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.annotations.testservlets;
+
+import java.io.IOException;
+
+import javax.servlet.Servlet;
+import javax.servlet.ServletException;
+
+import org.apache.sling.api.SlingHttpServletRequest;
+import org.apache.sling.api.SlingHttpServletResponse;
+import org.apache.sling.api.servlets.SlingAllMethodsServlet;
+import org.apache.sling.servlets.annotations.SlingServletResourceTypes;
+import org.osgi.service.component.annotations.Component;
+
+@Component(service=Servlet.class)
+@SlingServletResourceTypes(resourceTypes="/apps/sling/testservlets/ResourceTypeBoundServletWithSelectors", selectors= {"selector1.selector2", "selector3"})
+public class ResourceTypeBoundServletWithSelectors extends SlingAllMethodsServlet {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {
+ response.setStatus(600);
+ }
+
+ @Override
+ protected void doPut(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {
+ response.setStatus(601);
+ }
+}
diff --git a/src/it/annotations-it/src/main/resources/SLING-CONTENT/content/servlettest.json b/src/it/annotations-it/src/main/resources/SLING-CONTENT/content/servlettest.json
new file mode 100644
index 0000000..225e5ce
--- /dev/null
+++ b/src/it/annotations-it/src/main/resources/SLING-CONTENT/content/servlettest.json
@@ -0,0 +1,3 @@
+{
+ "jcr:primaryType" : "sling:Folder"
+}
diff --git a/src/it/annotations-it/src/main/resources/SLING-CONTENT/content/servlettest/baseResourceTypeBoundServletWithSelectors.json b/src/it/annotations-it/src/main/resources/SLING-CONTENT/content/servlettest/baseResourceTypeBoundServletWithSelectors.json
new file mode 100644
index 0000000..777b7ff
--- /dev/null
+++ b/src/it/annotations-it/src/main/resources/SLING-CONTENT/content/servlettest/baseResourceTypeBoundServletWithSelectors.json
@@ -0,0 +1,4 @@
+{
+ "jcr:primaryType": "nt:unstructured",
+ "sling:resourceType": "sling/testservlets/BaseResourceTypeBoundServletWithSelectors"
+}
diff --git a/src/it/annotations-it/src/main/resources/SLING-CONTENT/content/servlettest/inheritingResourceTypeBoundServlet.json b/src/it/annotations-it/src/main/resources/SLING-CONTENT/content/servlettest/inheritingResourceTypeBoundServlet.json
new file mode 100644
index 0000000..7ed030d
--- /dev/null
+++ b/src/it/annotations-it/src/main/resources/SLING-CONTENT/content/servlettest/inheritingResourceTypeBoundServlet.json
@@ -0,0 +1,4 @@
+{
+ "jcr:primaryType": "nt:unstructured",
+ "sling:resourceType": "sling/testservlets/InheritingResourceTypeBoundServlet"
+}
diff --git a/src/it/annotations-it/src/main/resources/SLING-CONTENT/content/servlettest/resourceTypeBoundServlet.json b/src/it/annotations-it/src/main/resources/SLING-CONTENT/content/servlettest/resourceTypeBoundServlet.json
new file mode 100644
index 0000000..49c8187
--- /dev/null
+++ b/src/it/annotations-it/src/main/resources/SLING-CONTENT/content/servlettest/resourceTypeBoundServlet.json
@@ -0,0 +1,4 @@
+{
+ "jcr:primaryType": "nt:unstructured",
+ "sling:resourceType": "/apps/sling/testservlets/ResourceTypeBoundServlet"
+}
diff --git a/src/it/annotations-it/src/main/resources/SLING-CONTENT/content/servlettest/resourceTypeBoundServletWithExtension.json b/src/it/annotations-it/src/main/resources/SLING-CONTENT/content/servlettest/resourceTypeBoundServletWithExtension.json
new file mode 100644
index 0000000..98562bb
--- /dev/null
+++ b/src/it/annotations-it/src/main/resources/SLING-CONTENT/content/servlettest/resourceTypeBoundServletWithExtension.json
@@ -0,0 +1,4 @@
+{
+ "jcr:primaryType": "nt:unstructured",
+ "sling:resourceType": "/apps/sling/testservlets/ResourceTypeBoundServletWithExtension"
+}
diff --git a/src/it/annotations-it/src/main/resources/SLING-CONTENT/content/servlettest/resourceTypeBoundServletWithMethods.json b/src/it/annotations-it/src/main/resources/SLING-CONTENT/content/servlettest/resourceTypeBoundServletWithMethods.json
new file mode 100644
index 0000000..2d7bf22
--- /dev/null
+++ b/src/it/annotations-it/src/main/resources/SLING-CONTENT/content/servlettest/resourceTypeBoundServletWithMethods.json
@@ -0,0 +1,4 @@
+{
+ "jcr:primaryType": "nt:unstructured",
+ "sling:resourceType": "/apps/sling/testservlets/ResourceTypeBoundServletWithMethods"
+}
diff --git a/src/it/annotations-it/src/main/resources/SLING-CONTENT/content/servlettest/resourceTypeBoundServletWithPrefix.json b/src/it/annotations-it/src/main/resources/SLING-CONTENT/content/servlettest/resourceTypeBoundServletWithPrefix.json
new file mode 100644
index 0000000..d77f7ed
--- /dev/null
+++ b/src/it/annotations-it/src/main/resources/SLING-CONTENT/content/servlettest/resourceTypeBoundServletWithPrefix.json
@@ -0,0 +1,4 @@
+{
+ "jcr:primaryType": "nt:unstructured",
+ "sling:resourceType": "/apps/sling/testservlets/ResourceTypeBoundServletWithPrefix"
+}
diff --git a/src/it/annotations-it/src/main/resources/SLING-CONTENT/content/servlettest/resourceTypeBoundServletWithSelectors.json b/src/it/annotations-it/src/main/resources/SLING-CONTENT/content/servlettest/resourceTypeBoundServletWithSelectors.json
new file mode 100644
index 0000000..9853c98
--- /dev/null
+++ b/src/it/annotations-it/src/main/resources/SLING-CONTENT/content/servlettest/resourceTypeBoundServletWithSelectors.json
@@ -0,0 +1,4 @@
+{
+ "jcr:primaryType": "nt:unstructured",
+ "sling:resourceType": "/apps/sling/testservlets/ResourceTypeBoundServletWithSelectors"
+}
diff --git a/src/it/annotations-it/src/test/java/org/apache/sling/servlets/annotations/AnnotationsTestSupport.java b/src/it/annotations-it/src/test/java/org/apache/sling/servlets/annotations/AnnotationsTestSupport.java
new file mode 100644
index 0000000..f1efd80
--- /dev/null
+++ b/src/it/annotations-it/src/test/java/org/apache/sling/servlets/annotations/AnnotationsTestSupport.java
@@ -0,0 +1,103 @@
+/*
+ * 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.annotations;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.sling.servlets.annotations.services.PathBoundService;
+import org.apache.sling.testing.clients.osgi.OsgiConsoleClient;
+import org.apache.sling.testing.paxexam.TestSupport;
+import org.junit.Before;
+import org.junit.ClassRule;
+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.extra.VMOption;
+
+import static org.apache.sling.testing.paxexam.SlingOptions.logback;
+import static org.apache.sling.testing.paxexam.SlingOptions.slingQuickstartOakTar;
+import static org.ops4j.pax.exam.CoreOptions.composite;
+import static org.ops4j.pax.exam.CoreOptions.when;
+import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
+import static org.ops4j.pax.exam.CoreOptions.systemProperty;
+
+import java.net.URI;
+
+public class AnnotationsTestSupport extends TestSupport {
+
+ private final static int STARTUP_WAIT_SECONDS = 30;
+
+ protected OsgiConsoleClient CLIENT;
+ protected static int httpPort;
+
+ @ClassRule
+ public static PaxExamServer serverRule = new PaxExamServer();
+
+ public AnnotationsTestSupport() {
+ if(httpPort == 0) {
+ // findFreePort should probably be a static method
+ httpPort = findFreePort();
+ }
+ }
+
+ @Configuration
+ public Option[] configuration() throws Exception {
+
+ final String vmOpt = System.getProperty("pax.vm.options");
+ VMOption vmOption = null;
+ if (StringUtils.isNotEmpty(vmOpt)) {
+ vmOption = new VMOption(vmOpt);
+ }
+
+ final String jacocoOpt = System.getProperty("jacoco.command");
+ VMOption jacocoCommand = null;
+ if (StringUtils.isNotEmpty(jacocoOpt)) {
+ jacocoCommand = new VMOption(jacocoOpt);
+ }
+
+ final String workingDirectory = workingDirectory();
+
+ return composite(
+ // TODO not sure why the below list of bundles is different from
+ // running tests with PaxExam.class - but this setup works
+ //super.baseConfiguration(),
+
+ when(vmOption != null).useOptions(vmOption),
+ when(jacocoCommand != null).useOptions(jacocoCommand),
+
+ // For some reason, Jetty starts first on port 8080 without this
+ systemProperty("org.osgi.service.http.port").value(String.valueOf(httpPort)),
+
+ slingQuickstartOakTar(workingDirectory, httpPort),
+ testBundle("bundle.filename"),
+
+ logback(),
+ mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.log").version("1.2.4"),
+ mavenBundle().groupId("log4j").artifactId("log4j").version("1.2.17"),
+ mavenBundle().groupId("org.apache.aries.spifly").artifactId("org.apache.aries.spifly.dynamic.framework.extension").version("1.3.2"),
+ mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.webconsole.plugins.ds").version("2.1.0")
+
+ ).getOptions();
+ }
+
+ @Before
+ public void waitForSling() throws Exception {
+ final URI url = new URI(String.format("http://localhost:%d", httpPort));
+ CLIENT = new OsgiConsoleClient(url, "admin", "admin");
+ CLIENT.waitExists("/", STARTUP_WAIT_SECONDS * 1000, 500);
+ CLIENT.waitComponentRegistered(PathBoundService.class.getName(), 10 * 1000, 500);
+ }
+}
diff --git a/src/it/annotations-it/src/test/java/org/apache/sling/servlets/annotations/ServicePropertiesIT.java b/src/it/annotations-it/src/test/java/org/apache/sling/servlets/annotations/ServicePropertiesIT.java
new file mode 100644
index 0000000..70171a1
--- /dev/null
+++ b/src/it/annotations-it/src/test/java/org/apache/sling/servlets/annotations/ServicePropertiesIT.java
@@ -0,0 +1,116 @@
+/*
+ * 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.annotations;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertFalse;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.sling.servlets.annotations.services.PathBoundService;
+import org.apache.sling.servlets.annotations.services.PathBoundStrictAllOptionsService;
+import org.apache.sling.servlets.annotations.services.PathBoundStrictJustPathService;
+import org.apache.sling.testing.clients.ClientException;
+import org.apache.sling.testing.clients.util.JsonUtils;
+import org.codehaus.jackson.JsonNode;
+import org.junit.Test;
+
+/** Assuming servlet selection is tested in the servlets resolver module,
+ * it's good enough to verify that the expected OSGi service properties
+ * are set by our annotations - this is what this class does for some of
+ * our test services.
+ */
+public class ServicePropertiesIT extends AnnotationsTestSupport {
+
+ private static String componentPath(Object nameOrId) {
+ return "/system/console/components/" + nameOrId + ".json";
+ }
+
+ /** Getting service properties is not directly supported by the OsgiConsoleClient */
+ private List<String> getServiceProperties(String serviceName) throws ClientException {
+ // Need to get the component ID first, then its details
+ final List<String> result = new ArrayList<>();
+ final JsonNode idInfo = JsonUtils.getJsonNodeFromString(CLIENT.doGet(componentPath(serviceName)).getContent());
+ final String id = idInfo.get("data").get(0).get("id").getTextValue();
+ assertTrue("Expecting non-null component ID", !id.equals("null"));
+ final JsonNode details = JsonUtils.getJsonNodeFromString(CLIENT.doGet(componentPath(id)).getContent());
+ final JsonNode data = details.get("data").get(0);
+ final JsonNode props = data.get("props");
+ for(JsonNode prop : props) {
+ if("Properties".equals(prop.get("key").getTextValue())) {
+ for(JsonNode value : prop.get("value")) {
+ result.add(value.getTextValue().replaceAll(" ", "").trim());
+ }
+ }
+ }
+ return result;
+ }
+
+ private void assertProperty(List<String> props, String key, String value) {
+ final String pattern = key + "=" + value;
+ assertTrue(
+ "Expecting " + pattern + " in " + props,
+ props.stream().anyMatch(line -> line.equals(pattern))
+ );
+ }
+
+ private void assertAbsentProperties(List<String> props, String ... keys) {
+ for(String key : keys) {
+ assertFalse(
+ "Expecting " + key + " to be absent in " + props,
+ props.stream().anyMatch(line -> line.startsWith(key))
+ );
+ }
+ }
+
+ @Test
+ public void testPathBoundService() throws ClientException {
+ final List<String> props = getServiceProperties(PathBoundService.class.getName());
+ assertProperty(props, "sling.servlet.paths", "[PathBoundServicePath]");
+ assertAbsentProperties(
+ props,
+ "sling.servlet.extensions",
+ "sling.servlet.selectors",
+ "sling.servlet.methods",
+ "sling.servlet.paths.strict"
+ );
+ }
+
+ @Test
+ public void testPathBoundStrictAllOptionsService() throws ClientException {
+ final List<String> props = getServiceProperties(PathBoundStrictAllOptionsService.class.getName());
+ assertProperty(props, "sling.servlet.paths.strict", "true");
+ assertProperty(props, "sling.servlet.paths", "[P1,P2]");
+ assertProperty(props, "sling.servlet.extensions", "[E1,E2]");
+ assertProperty(props, "sling.servlet.selectors", "[S1,S2]");
+ assertProperty(props, "sling.servlet.methods", "[M1,M2]");
+ }
+
+ @Test
+ public void testPathBoundStrictJustPathService() throws ClientException {
+ final List<String> props = getServiceProperties(PathBoundStrictJustPathService.class.getName());
+ assertProperty(props, "sling.servlet.paths.strict", "true");
+ assertProperty(props, "sling.servlet.paths", "[JustThePath]");
+ assertAbsentProperties(
+ props,
+ "sling.servlet.extensions",
+ "sling.servlet.selectors",
+ "sling.servlet.methods"
+ );
+ }
+}
diff --git a/src/it/annotations-it/src/test/java/org/apache/sling/servlets/annotations/ServletRegistrationIT.java b/src/it/annotations-it/src/test/java/org/apache/sling/servlets/annotations/ServletRegistrationIT.java
new file mode 100644
index 0000000..ccdf406
--- /dev/null
+++ b/src/it/annotations-it/src/test/java/org/apache/sling/servlets/annotations/ServletRegistrationIT.java
@@ -0,0 +1,115 @@
+/*
+ * 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.annotations;
+
+import java.io.UnsupportedEncodingException;
+import java.util.Collections;
+
+import org.apache.http.entity.StringEntity;
+import org.apache.sling.testing.clients.ClientException;
+import org.junit.Test;
+
+/** Verify servlet selection based on our annotations. This duplicates
+ * some of the servlet resolver tests, see also {@link ServicePropertiesIT}
+ * for another testing method.
+ */
+public class ServletRegistrationIT extends AnnotationsTestSupport {
+
+ @Test
+ public void testPathBoundServlet() throws ClientException, UnsupportedEncodingException {
+ CLIENT.doGet("/bin/PathBoundServlet", 555);
+ CLIENT.doGet("/bin/PathBoundServlet.with.some.selector.and.extension", 555);
+ CLIENT.doGet("/bin/PathBoundServlet.with.some.selector.and.extension/suffix", 555);
+ // other methods should work as well
+ CLIENT.doPut("/bin/PathBoundServlet", new StringEntity("some text"), Collections.emptyList(), 557);
+ }
+
+ @Test
+ public void testPathBoundServletWithFilter() throws ClientException {
+ CLIENT.doGet("/bin/PathBoundServlet.html/simplefilter", 556);
+ CLIENT.doGet("/bin/PathBoundServlet.with.some.selector.and.extension/simplefilter", 556);
+ }
+
+ @Test
+ public void testPathBoundServletWithPrefix() throws ClientException {
+ CLIENT.doGet("/bin/PathBoundServletWithPrefix", 610);
+ CLIENT.doGet("/bin/PathBoundServletWithPrefix.with.some.selector.and.extension", 610);
+ }
+
+ @Test
+ public void testResourceTypeBoundServlet() throws ClientException, UnsupportedEncodingException {
+ CLIENT.doGet("/content/servlettest/resourceTypeBoundServlet", 560);
+ CLIENT.doGet("/content/servlettest/resourceTypeBoundServlet.html", 560);
+ CLIENT.doGet("/content/servlettest/resourceTypeBoundServlet.json", 560);
+ // only GET and HEAD are supposed to be working
+ CLIENT.doPut("/content/servlettest/resourceTypeBoundServlet.json", new StringEntity("some text"), Collections.emptyList(), 405);
+ }
+
+ @Test
+ public void testResourceTypeBoundServletWithPrefix() throws ClientException, UnsupportedEncodingException {
+ CLIENT.doGet("/content/servlettest/resourceTypeBoundServletWithPrefix", 590);
+ CLIENT.doGet("/content/servlettest/resourceTypeBoundServletWithPrefix.html", 590);
+ CLIENT.doGet("/content/servlettest/resourceTypeBoundServletWithPrefix.json", 590);
+ // only GET and HEAD are supposed to be working
+ CLIENT.doPut("/content/servlettest/resourceTypeBoundServletWithPrefix.json", new StringEntity("some text"), Collections.emptyList(), 405);
+ }
+
+ @Test
+ public void testResourceTypeBoundServletWithExtension() throws ClientException, UnsupportedEncodingException {
+ CLIENT.doGet("/content/servlettest/resourceTypeBoundServletWithExtension", 403); // without extension is a index listing, which is forbidden by default
+ CLIENT.doGet("/content/servlettest/resourceTypeBoundServletWithExtension.html", 200); // DEFAULT GET Servlet
+ CLIENT.doGet("/content/servlettest/resourceTypeBoundServletWithExtension.ext1", 570);
+ CLIENT.doGet("/content/servlettest/resourceTypeBoundServletWithExtension.ext2", 570);
+ CLIENT.doPut("/content/servlettest/resourceTypeBoundServletWithExtension.ext2", new StringEntity("some text"), Collections.emptyList(), 571);
+ // extension is considered for all methods!
+ CLIENT.doPut("/content/servlettest/resourceTypeBoundServletWithExtension.someotherext", new StringEntity("some text"), Collections.emptyList(), 405); // DEFAULT servlet
+ }
+
+ @Test
+ public void testResourceTypeBoundServletWithSelectors() throws ClientException, UnsupportedEncodingException {
+ CLIENT.doGet("/content/servlettest/resourceTypeBoundServletWithSelectors.someext", 404);
+ CLIENT.doGet("/content/servlettest/resourceTypeBoundServletWithSelectors.selector1.someext", 404);
+ CLIENT.doGet("/content/servlettest/resourceTypeBoundServletWithSelectors.selector3.someext", 600);
+ CLIENT.doGet("/content/servlettest/resourceTypeBoundServletWithSelectors.selector1.selector2.someext", 600);
+ // some non-registered selector as first selector
+ CLIENT.doGet("/content/servlettest/resourceTypeBoundServletWithSelectors.someotherselector.selector1.selector2.someext", 404);
+ // some non-registered selector as last selector
+ CLIENT.doGet("/content/servlettest/resourceTypeBoundServletWithSelectors.selector1.selector2.someotherselector.someext", 600);
+ // only GET and HEAD are supposed to be working
+ CLIENT.doPut("/content/servlettest/resourceTypeBoundServletWithSelectors.selector3.someext", new StringEntity("some text"), Collections.emptyList(), 405);
+ }
+
+ @Test
+ public void testResourceTypeBoundServletWithMethods() throws ClientException, UnsupportedEncodingException {
+ CLIENT.doGet("/content/servlettest/resourceTypeBoundServletWithMethods.someext", 404); // DEFAULT Get not triggered due to weird extension
+ CLIENT.doPut("/content/servlettest/resourceTypeBoundServletWithMethods.someext", new StringEntity("some text"), Collections.emptyList(), 581);
+ CLIENT.doPost("/content/servlettest/resourceTypeBoundServletWithMethods.someext", new StringEntity("some text"), Collections.emptyList(), 582);
+ }
+
+ @Test
+ public void testInheritingServlets() throws ClientException {
+ CLIENT.doGet("/content/servlettest/baseResourceTypeBoundServletWithSelectors", 403); // no selectors passed
+ CLIENT.doGet("/content/servlettest/baseResourceTypeBoundServletWithSelectors.someext", 404); // no selectors passed
+ CLIENT.doGet("/content/servlettest/baseResourceTypeBoundServletWithSelectors.sel1.someext", 610); // matches
+ CLIENT.doGet("/content/servlettest/baseResourceTypeBoundServletWithSelectors.sel2.someext", 610); // matches
+ CLIENT.doGet("/content/servlettest/inheritingResourceTypeBoundServlet", 620); // matches
+ CLIENT.doGet("/content/servlettest/inheritingResourceTypeBoundServlet.someext", 620); // matches
+ CLIENT.doGet("/content/servlettest/inheritingResourceTypeBoundServlet.sel.someext", 620); // matches
+ CLIENT.doGet("/content/servlettest/inheritingResourceTypeBoundServlet.sel1.someext", 610); // delegated to Base
+ CLIENT.doGet("/content/servlettest/inheritingResourceTypeBoundServlet.sel2.someext", 610); // delegated to Base
+ }
+}
\ No newline at end of file
diff --git a/src/it/annotations-it/src/test/resources/logback.xml b/src/it/annotations-it/src/test/resources/logback.xml
new file mode 100644
index 0000000..a603c15
--- /dev/null
+++ b/src/it/annotations-it/src/test/resources/logback.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<configuration>
+ <appender name="file" class="ch.qos.logback.core.FileAppender">
+ <file>target/test.log</file>
+ <append>true</append>
+ <encoder>
+ <pattern>%date level=%level thread=%thread logger=%logger sourcefile=%file line=%line %mdc message=%msg%n</pattern>
+ </encoder>
+ </appender>
+
+ <root level="info">
+ <appender-ref ref="file"/>
+ </root>
+</configuration>
diff --git a/src/it/settings.xml b/src/it/settings.xml
new file mode 100644
index 0000000..3404fda
--- /dev/null
+++ b/src/it/settings.xml
@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+
+<!--
+ As per https://maven.apache.org/plugins/maven-invoker-plugin/examples/fast-use.html
+ this lets invoked builds grab artifacts from the local repository instead of
+ downloading all of them.
+-->
+<settings>
+ <profiles>
+ <profile>
+ <id>it-repo</id>
+ <activation>
+ <activeByDefault>true</activeByDefault>
+ </activation>
+ <repositories>
+ <repository>
+ <id>local.central</id>
+ <url>@localRepositoryUrl@</url>
+ <releases>
+ <enabled>true</enabled>
+ </releases>
+ <snapshots>
+ <enabled>true</enabled>
+ </snapshots>
+ </repository>
+ </repositories>
+ <pluginRepositories>
+ <pluginRepository>
+ <id>local.central</id>
+ <url>@localRepositoryUrl@</url>
+ <releases>
+ <enabled>true</enabled>
+ </releases>
+ <snapshots>
+ <enabled>true</enabled>
+ </snapshots>
+ </pluginRepository>
+ </pluginRepositories>
+ </profile>
+ </profiles>
+</settings>
\ No newline at end of file