This is an automated email from the ASF dual-hosted git repository. rombert pushed a commit to annotated tag sling-servlet-archetype-1.0.2 in repository https://gitbox.apache.org/repos/asf/sling-servlet-archetype.git
commit 7c17edf92d2650003e82efe79ad0668746694854 Author: Justin Edelson <[email protected]> AuthorDate: Wed Dec 21 01:04:07 2011 +0000 SLING-2338 - adding integration test for servlet archetype git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/maven/archetypes/servlet@1221548 13f79535-47bb-0310-9956-ffa450edef68 --- pom.xml | 57 +++++---- src/main/resources/META-INF/maven/archetype.xml | 23 ---- .../src/test/java/ByPathServletTest.java | 16 +++ .../resources/projects/normal/archetype.properties | 4 + src/test/resources/projects/normal/goal.txt | 1 + .../resources/projects/normal/reference/pom.xml | 134 +++++++++++++++++++++ .../archetype/servlet/testing/ByPathServlet.java | 79 ++++++++++++ .../servlet/testing/ByResourceTypeServlet.java | 85 +++++++++++++ .../archetype/servlet/testing/SimpleFilter.java | 71 +++++++++++ .../servlet/testing/ByPathServletTest.java | 33 +++++ 10 files changed, 458 insertions(+), 45 deletions(-) diff --git a/pom.xml b/pom.xml index b6a1369..fe0cb80 100644 --- a/pom.xml +++ b/pom.xml @@ -17,7 +17,8 @@ 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"> +<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> @@ -41,39 +42,51 @@ </scm> <build> + <testResources> + <testResource> + <directory>src/test/resources</directory> + <excludes> + <exclude>**/.settings</exclude> + <exclude>**/.settings/**</exclude> + <exclude>**/.project</exclude> + <exclude>**/.classpath</exclude> + <exclude>**/target/**</exclude> + </excludes> + </testResource> + </testResources> <extensions> <extension> <groupId>org.apache.maven.archetype</groupId> <artifactId>archetype-packaging</artifactId> - <version>2.0-alpha-4</version> + <version>2.2</version> </extension> </extensions> <plugins> <plugin> <artifactId>maven-archetype-plugin</artifactId> - <version>2.0-alpha-4</version> + <version>2.2</version> <extensions>true</extensions> </plugin> </plugins> </build> - <reporting> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-plugin-plugin</artifactId> - <version>2.5.1</version> - </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-javadoc-plugin</artifactId> - <configuration> - <!-- No javadocs --> - <excludePackageNames> - org.apache.sling - </excludePackageNames> - </configuration> - </plugin> - </plugins> - </reporting> + <reporting> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-plugin-plugin</artifactId> + <version>2.5.1</version> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-javadoc-plugin</artifactId> + <configuration> + <!-- No javadocs --> + <excludePackageNames> + org.apache.sling + </excludePackageNames> + </configuration> + </plugin> + </plugins> + </reporting> </project> diff --git a/src/main/resources/META-INF/maven/archetype.xml b/src/main/resources/META-INF/maven/archetype.xml deleted file mode 100644 index ada4b67..0000000 --- a/src/main/resources/META-INF/maven/archetype.xml +++ /dev/null @@ -1,23 +0,0 @@ -<?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. ---> -<archetype> - <id>sling-servlet</id> - <sources> - <source>src/main/java/ByPathServlet.java</source> - <source>src/main/java/ByResourceTypeServlet.java</source> - </sources> - <testSources> - <source>src/test/java/ByPathServletTest.java</source> - </testSources> -</archetype> diff --git a/src/main/resources/archetype-resources/src/test/java/ByPathServletTest.java b/src/main/resources/archetype-resources/src/test/java/ByPathServletTest.java index da2ff06..4614a24 100644 --- a/src/main/resources/archetype-resources/src/test/java/ByPathServletTest.java +++ b/src/main/resources/archetype-resources/src/test/java/ByPathServletTest.java @@ -1,3 +1,19 @@ +/* + * 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 ${package}; import junit.framework.TestCase; diff --git a/src/test/resources/projects/normal/archetype.properties b/src/test/resources/projects/normal/archetype.properties new file mode 100644 index 0000000..d6fe58d --- /dev/null +++ b/src/test/resources/projects/normal/archetype.properties @@ -0,0 +1,4 @@ +groupId=org.apache.sling +artifactId=test-servlet-archetype-project +version=0.0.1-SNAPSHOT +package=org.apache.sling.archetype.servlet.testing \ No newline at end of file diff --git a/src/test/resources/projects/normal/goal.txt b/src/test/resources/projects/normal/goal.txt new file mode 100644 index 0000000..597acc7 --- /dev/null +++ b/src/test/resources/projects/normal/goal.txt @@ -0,0 +1 @@ +package \ No newline at end of file diff --git a/src/test/resources/projects/normal/reference/pom.xml b/src/test/resources/projects/normal/reference/pom.xml new file mode 100644 index 0000000..f35f9e8 --- /dev/null +++ b/src/test/resources/projects/normal/reference/pom.xml @@ -0,0 +1,134 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + 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> + <groupId>org.apache.sling</groupId> + <artifactId>test-servlet-archetype-project</artifactId> + <packaging>bundle</packaging> + <version>0.0.1-SNAPSHOT</version> + <name>test-servlet-archetype-project</name> + <description>org.apache.sling - test-servlet-archetype-project</description> + <build> + <plugins> + <plugin> + <groupId>org.apache.felix</groupId> + <artifactId>maven-scr-plugin</artifactId> + <version>1.7.2</version> + <executions> + <execution> + <id>generate-scr-descriptor</id> + <goals> + <goal>scr</goal> + </goals> + </execution> + </executions> + </plugin> + <plugin> + <groupId>org.apache.felix</groupId> + <artifactId>maven-bundle-plugin</artifactId> + <extensions>true</extensions> + <version>2.0.1</version> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <!-- use version 2.3.2 to have java 1.5 as the default --> + <version>2.3.2</version> + </plugin> + </plugins> + </build> + <dependencies> + <dependency> + <groupId>javax.servlet</groupId> + <artifactId>servlet-api</artifactId> + <version>2.5</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.osgi</groupId> + <artifactId>org.osgi.compendium</artifactId> + <version>4.2.0</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.osgi</groupId> + <artifactId>org.osgi.core</artifactId> + <version>4.2.0</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>javax.jcr</groupId> + <artifactId>jcr</artifactId> + <version>2.0</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.apache.sling</groupId> + <artifactId>org.apache.sling.api</artifactId> + <version>2.2.0</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-api</artifactId> + <version>1.5.10</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.apache.felix</groupId> + <artifactId>org.apache.felix.scr.annotations</artifactId> + <version>1.6.0</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>3.8.1</version> + <scope>test</scope> + </dependency> + </dependencies> + <profiles> + <profile> + <id>autoInstallBundle</id> + <build> + <plugins> + <plugin> + <groupId>org.apache.sling</groupId> + <artifactId>maven-sling-plugin</artifactId> + <version>2.0.4-incubator</version> + <executions> + <execution> + <id>install-bundle</id> + <goals> + <goal>install</goal> + </goals> + <configuration> + <slingUrl>http://localhost:8888/system/console</slingUrl> + <user>admin</user> + <password>admin</password> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> + </profile> + </profiles> +</project> diff --git a/src/test/resources/projects/normal/reference/src/main/java/org/apache/sling/archetype/servlet/testing/ByPathServlet.java b/src/test/resources/projects/normal/reference/src/main/java/org/apache/sling/archetype/servlet/testing/ByPathServlet.java new file mode 100644 index 0000000..56d11d4 --- /dev/null +++ b/src/test/resources/projects/normal/reference/src/main/java/org/apache/sling/archetype/servlet/testing/ByPathServlet.java @@ -0,0 +1,79 @@ +/* + * 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.archetype.servlet.testing; + +import java.io.IOException; +import java.io.Writer; + +import javax.servlet.ServletException; + +import org.apache.felix.scr.annotations.Properties; +import org.apache.felix.scr.annotations.Property; +import org.apache.felix.scr.annotations.sling.SlingServlet; +import org.apache.sling.api.SlingHttpServletRequest; +import org.apache.sling.api.SlingHttpServletResponse; +import org.apache.sling.api.servlets.SlingSafeMethodsServlet; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Hello World Servlet registered by path + * + * Annotations below are short version of: + * + * @Component + * @Service(Servlet.class) + * @Properties({ + * @Property(name="service.description", value="Hello World Path Servlet"), + * @Property(name="service.vendor", value="The Apache Software Foundation"), + * @Property(name="sling.servlet.paths", value="/hello-world-servlet") + * }) + */ +@SlingServlet(paths="/hello-world-servlet") +@Properties({ + @Property(name="service.description", value="Hello World Path Servlet"), + @Property(name="service.vendor", value="The Apache Software Foundation") +}) +@SuppressWarnings("serial") +public class ByPathServlet extends SlingSafeMethodsServlet { + + private final Logger log = LoggerFactory.getLogger(ByPathServlet.class); + + @Override + protected void doGet(SlingHttpServletRequest request, + SlingHttpServletResponse response) throws ServletException, + IOException { + + Writer w = response.getWriter(); + w.write("<!DOCTYPE html PUBLIC \"-//IETF//DTD HTML 2.0//EN\">"); + w.write("<html>"); + w.write("<head>"); + w.write("<title>Hello World Servlet</title>"); + w.write("</head>"); + w.write("<body>"); + w.write("<h1>Hello World!</h1>"); + w.write("</body>"); + w.write("</html>"); + + log.info("Hello World Servlet"); + + } + +} + diff --git a/src/test/resources/projects/normal/reference/src/main/java/org/apache/sling/archetype/servlet/testing/ByResourceTypeServlet.java b/src/test/resources/projects/normal/reference/src/main/java/org/apache/sling/archetype/servlet/testing/ByResourceTypeServlet.java new file mode 100644 index 0000000..6ae820e --- /dev/null +++ b/src/test/resources/projects/normal/reference/src/main/java/org/apache/sling/archetype/servlet/testing/ByResourceTypeServlet.java @@ -0,0 +1,85 @@ +/* + * 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.archetype.servlet.testing; + +import java.io.IOException; +import java.io.Writer; + +import javax.servlet.ServletException; + +import org.apache.felix.scr.annotations.Properties; +import org.apache.felix.scr.annotations.Property; +import org.apache.felix.scr.annotations.sling.SlingServlet; +import org.apache.sling.api.SlingHttpServletRequest; +import org.apache.sling.api.SlingHttpServletResponse; +import org.apache.sling.api.resource.Resource; +import org.apache.sling.api.servlets.SlingSafeMethodsServlet; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Hello World Servlet registered by resource type + * + * Annotations below are short version of: + * + * @Component + * @Service(Servlet.class) + * @Properties({ + * @Property(name="service.description", value="Hello World Type Servlet"), + * @Property(name="service.vendor", value="The Apache Software Foundation"), + * @Property(name="sling.servlet.resourceTypes", value="sling/servlet/default"), + * @Property(name="sling.servlet.selectors", value="hello"), + * @Property(name="sling.servlet.extensions", value="html") + * }) + */ +@SlingServlet(resourceTypes="sling/servlet/default", selectors="hello", extensions="html") +@Properties({ + @Property(name="service.description", value="Hello World Type Servlet"), + @Property(name="service.vendor", value="The Apache Software Foundation") +}) +@SuppressWarnings("serial") +public class ByResourceTypeServlet extends SlingSafeMethodsServlet { + + private final Logger log = LoggerFactory.getLogger(ByResourceTypeServlet.class); + + @Override + protected void doGet(SlingHttpServletRequest request, + SlingHttpServletResponse response) throws ServletException, + IOException { + Resource resource = request.getResource(); + + Writer w = response.getWriter(); + w.write("<!DOCTYPE html PUBLIC \"-//IETF//DTD HTML 2.0//EN\">"); + w.write("<html>"); + w.write("<head>"); + w.write("<title>Hello World Servlet</title>"); + w.write("</head>"); + w.write("<body>"); + w.write("<h1>Hello "); + w.write(resource.getPath()); + w.write("</h1>"); + w.write("</body>"); + w.write("</html>"); + + log.info("Hello World Servlet"); + + } + +} + diff --git a/src/test/resources/projects/normal/reference/src/main/java/org/apache/sling/archetype/servlet/testing/SimpleFilter.java b/src/test/resources/projects/normal/reference/src/main/java/org/apache/sling/archetype/servlet/testing/SimpleFilter.java new file mode 100644 index 0000000..635f500 --- /dev/null +++ b/src/test/resources/projects/normal/reference/src/main/java/org/apache/sling/archetype/servlet/testing/SimpleFilter.java @@ -0,0 +1,71 @@ +/* + * 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.archetype.servlet.testing; + +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.felix.scr.annotations.Component; +import org.apache.felix.scr.annotations.Properties; +import org.apache.felix.scr.annotations.Property; +import org.apache.felix.scr.annotations.Service; +import org.apache.felix.scr.annotations.sling.SlingFilter; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * A Simple Filter + * + * Annotations below are short version of: + * + * @Component + * @Service(Filter.class) + * @Properties({ + * @Property(name="service.description", value="A Simple Filter"), + * @Property(name="service.vendor", value="The Apache Software Foundation"), + * @Property(name="sling.filter.scope", value="REQUEST"), + * @Property(name="service.ranking", intValue=1) + * }) + */ +@SlingFilter(order=1, description="A Simple Filter") +@Property(name="service.vendor", value="The Apache Software Foundation") +public class SimpleFilter implements Filter { + + private final Logger log = LoggerFactory.getLogger(SimpleFilter.class); + + public void init(FilterConfig filterConfig) throws ServletException { + } + + public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, + ServletException { + log.info("filter invoked - start"); + chain.doFilter(request, response); + log.info("filter invoked - end"); + } + + public void destroy() { + } + +} diff --git a/src/test/resources/projects/normal/reference/src/test/java/org/apache/sling/archetype/servlet/testing/ByPathServletTest.java b/src/test/resources/projects/normal/reference/src/test/java/org/apache/sling/archetype/servlet/testing/ByPathServletTest.java new file mode 100644 index 0000000..5448d57 --- /dev/null +++ b/src/test/resources/projects/normal/reference/src/test/java/org/apache/sling/archetype/servlet/testing/ByPathServletTest.java @@ -0,0 +1,33 @@ +/* + * 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.archetype.servlet.testing; + +import junit.framework.TestCase; + +/** + * Unit test for By Path Servlet. + */ +public class ByPathServletTest extends TestCase { + + /** + * Rigourous Test :-) + */ + public void testByPathServlet() { + assertTrue(true); + } + +} -- To stop receiving notification emails like this one, please contact "[email protected]" <[email protected]>.
