Move Sling to new TLP location
git-svn-id: https://svn.eu.apache.org/repos/asf/sling/tags/org.apache.sling.commons.testing-2.0.2-incubator@785979 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..d645695
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,202 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed 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.
diff --git a/NOTICE b/NOTICE
new file mode 100644
index 0000000..14dc85c
--- /dev/null
+++ b/NOTICE
@@ -0,0 +1,8 @@
+Apache Sling Testing Utilities
+Copyright 2008 The Apache Software Foundation
+
+Apache Sling is based on source code originally developed
+by Day Software (http://www.day.com/).
+
+This product includes software developed at
+The Apache Software Foundation (http://www.apache.org/).
diff --git a/README.txt b/README.txt
new file mode 100644
index 0000000..012245f
--- /dev/null
+++ b/README.txt
@@ -0,0 +1,36 @@
+Apache Sling Testing Utilities
+
+Tools and utilities for automated testing of Sling modules
+
+Disclaimer
+==========
+Apache Sling is an effort undergoing incubation at The Apache Software Foundation (ASF),
+sponsored by the Apache Jackrabbit PMC. Incubation is required of all newly accepted
+projects until a further review indicates that the infrastructure, communications,
+and decision making process have stabilized in a manner consistent with other
+successful ASF projects. While incubation status is not necessarily a reflection of
+the completeness or stability of the code, it does indicate that the project has yet
+to be fully endorsed by the ASF.
+
+Getting Started
+===============
+
+This component uses a Maven 2 (http://maven.apache.org/) build
+environment. It requires a Java 5 JDK (or higher) and Maven (http://maven.apache.org/)
+2.0.7 or later. We recommend to use the latest Maven version.
+
+If you have Maven 2 installed, you can compile and
+package the jar using the following command:
+
+ mvn package
+
+See the Maven 2 documentation for other build features.
+
+The latest source code for this component is available in the
+Subversion (http://subversion.tigris.org/) source repository of
+the Apache Software Foundation. If you have Subversion installed,
+you can checkout the latest source using the following command:
+
+ svn checkout http://svn.apache.org/repos/asf/incubator/sling/trunk/commons/testing
+
+See the Subversion documentation for other source control features.
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..65d95ab
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,105 @@
+<?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>
+ <parent>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>sling</artifactId>
+ <version>3-incubator</version>
+ <relativePath>../../parent/pom.xml</relativePath>
+ </parent>
+
+ <artifactId>org.apache.sling.commons.testing</artifactId>
+ <packaging>jar</packaging>
+ <version>2.0.2-incubator</version>
+
+ <name>Sling - testing utilities</name>
+ <description>
+ Tools and utilities for automated testing of Sling modules
+ </description>
+
+ <scm>
+ <connection>scm:svn:http://svn.apache.org/repos/asf/incubator/sling/tags/org.apache.sling.commons.testing-2.0.2-incubator</connection>
+ <developerConnection>scm:svn:https://svn.apache.org/repos/asf/incubator/sling/tags/org.apache.sling.commons.testing-2.0.2-incubator</developerConnection>
+ <url>http://svn.apache.org/viewvc/incubator/sling/tags/org.apache.sling.commons.testing-2.0.2-incubator</url>
+ </scm>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.api</artifactId>
+ <version>2.0.2-incubator</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.jcr.api</artifactId>
+ <version>2.0.2-incubator</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.jackrabbit</groupId>
+ <artifactId>jackrabbit-core</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>rhino</groupId>
+ <artifactId>js</artifactId>
+ <scope>compile</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>commons-httpclient</groupId>
+ <artifactId>commons-httpclient</artifactId>
+ <scope>compile</scope>
+ <exclusions>
+ <!--
+ Same problem as JCR-683: commons-httpclient depends on commons-logging. Since
+ this webapp uses log4j (see the slf4j-log4j12 dependency below), we need to
+ override this dependency with jcl-over-sflf4j, found below
+ -->
+ <exclusion>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.osgi.compendium</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ </dependencies>
+</project>
diff --git a/src/main/java/org/apache/sling/commons/testing/integration/HttpAnyMethod.java b/src/main/java/org/apache/sling/commons/testing/integration/HttpAnyMethod.java
new file mode 100644
index 0000000..7403806
--- /dev/null
+++ b/src/main/java/org/apache/sling/commons/testing/integration/HttpAnyMethod.java
@@ -0,0 +1,34 @@
+/*
+ * 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.commons.testing.integration;
+
+import org.apache.commons.httpclient.HttpMethodBase;
+
+/** Allows any HTTP method for HtttpClient */
+public class HttpAnyMethod extends HttpMethodBase {
+ private final String methodName;
+
+ public HttpAnyMethod(String methodName, String uri) {
+ super(uri);
+ this.methodName = methodName;
+ }
+
+ @Override
+ public String getName() {
+ return methodName;
+ }
+}
diff --git a/src/main/java/org/apache/sling/commons/testing/integration/HttpStatusCodeException.java b/src/main/java/org/apache/sling/commons/testing/integration/HttpStatusCodeException.java
new file mode 100644
index 0000000..5fedd3d
--- /dev/null
+++ b/src/main/java/org/apache/sling/commons/testing/integration/HttpStatusCodeException.java
@@ -0,0 +1,47 @@
+/*
+ * 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.commons.testing.integration;
+
+import java.io.IOException;
+
+@SuppressWarnings("serial")
+public class HttpStatusCodeException extends IOException {
+
+ private final int expectedStatus;
+
+ private final int actualStatus;
+
+ public HttpStatusCodeException(int expectedStatus, int actualStatus,
+ String method, String url) {
+
+ super("Expected status code " + expectedStatus + " for " + method
+ + ", got " + actualStatus + ", URL=" + url);
+
+ this.expectedStatus = expectedStatus;
+ this.actualStatus = actualStatus;
+ }
+
+ public int getExpectedStatus() {
+ return expectedStatus;
+ }
+
+ public int getActualStatus() {
+ return actualStatus;
+ }
+}
diff --git a/src/main/java/org/apache/sling/commons/testing/integration/HttpTestBase.java b/src/main/java/org/apache/sling/commons/testing/integration/HttpTestBase.java
new file mode 100644
index 0000000..d85ef98
--- /dev/null
+++ b/src/main/java/org/apache/sling/commons/testing/integration/HttpTestBase.java
@@ -0,0 +1,371 @@
+/*
+ * 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.commons.testing.integration;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.httpclient.Credentials;
+import org.apache.commons.httpclient.Header;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpException;
+import org.apache.commons.httpclient.NameValuePair;
+import org.apache.commons.httpclient.UsernamePasswordCredentials;
+import org.apache.commons.httpclient.auth.AuthScope;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.mozilla.javascript.Context;
+import org.mozilla.javascript.ScriptableObject;
+
+/** Base class for HTTP-based Sling Launchpad integration tests */
+public class HttpTestBase extends TestCase {
+ public static final String HTTP_BASE_URL = removeEndingSlash(System.getProperty("launchpad.http.server.url", "http://localhost:8888"));
+ public static final String WEBDAV_BASE_URL = removeEndingSlash(System.getProperty("launchpad.webdav.server.url", "http://localhost:8888"));
+
+ /** base path for test files */
+ public static final String TEST_PATH = "/launchpad-integration-tests";
+
+ public static final String CONTENT_TYPE_HTML = "text/html";
+ public static final String CONTENT_TYPE_XML = "text/xml";
+ public static final String CONTENT_TYPE_PLAIN = "text/plain";
+ public static final String CONTENT_TYPE_JSON = "application/json";
+ public static final String CONTENT_TYPE_JS = "application/x-javascript";
+ public static final String CONTENT_TYPE_CSS = "text/css";
+
+ public static final String SLING_RESOURCE_TYPE = "sling:resourceType";
+
+ public static final String SLING_POST_SERVLET_CREATE_SUFFIX = "/";
+
+ protected SlingIntegrationTestClient testClient;
+ protected HttpClient httpClient;
+
+ private static Boolean slingStartupOk;
+
+ /** Means "don't care about Content-Type" in getContent(...) methods */
+ public static final String CONTENT_TYPE_DONTCARE = "*";
+
+ /** URLs stored here are deleted in tearDown */
+ protected final List<String> urlsToDelete = new LinkedList<String>();
+
+ /** Class that creates a test node under the given parentPath, and
+ * stores useful values for testing. Created for JspScriptingTest,
+ * older test classes do not use it, but it might simplify them.
+ */
+ protected class TestNode {
+ public final String testText;
+ public final String nodeUrl;
+ public final String resourceType;
+ public final String scriptPath;
+
+ public TestNode(String parentPath, Map<String, String> properties) throws IOException {
+ if(properties == null) {
+ properties = new HashMap<String, String>();
+ }
+ testText = "This is a test node " + System.currentTimeMillis();
+ properties.put("text", testText);
+ nodeUrl = testClient.createNode(parentPath + SLING_POST_SERVLET_CREATE_SUFFIX, properties);
+ resourceType = properties.get(SLING_RESOURCE_TYPE);
+ scriptPath = "/apps/" + (resourceType == null ? "nt/unstructured" : resourceType);
+ testClient.mkdirs(WEBDAV_BASE_URL, scriptPath);
+ }
+
+ public void delete() throws IOException {
+ testClient.delete(nodeUrl);
+ }
+ };
+
+ protected static String removeEndingSlash(String str) {
+ if(str != null && str.endsWith("/")) {
+ return str.substring(0, str.length() - 1);
+ }
+ return str;
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ // assume http and webdav are on the same host + port
+ URL url = null;
+ try {
+ url = new URL(HTTP_BASE_URL);
+ } catch(MalformedURLException mfe) {
+ // MalformedURLException doesn't tell us the URL by default
+ throw new IOException("MalformedURLException: " + HTTP_BASE_URL);
+ }
+
+ // setup HTTP client, with authentication (using default Jackrabbit credentials)
+ httpClient = new HttpClient();
+ httpClient.getParams().setAuthenticationPreemptive(true);
+ Credentials defaultcreds = new UsernamePasswordCredentials("admin", "admin");
+ httpClient.getState().setCredentials(new AuthScope(url.getHost(), url.getPort(), AuthScope.ANY_REALM), defaultcreds);
+
+ testClient = new SlingIntegrationTestClient(httpClient);
+
+ waitForSlingStartup();
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+
+ for(String url : urlsToDelete) {
+ testClient.delete(url);
+ }
+ }
+
+ /** On the server side, initialization of Sling bundles is done
+ * asynchronously once the webapp is started. This method checks
+ * that everything's ready on the server side, by calling an URL
+ * that requires the SlingPostServlet and the JCR repository to
+ * work correctly.
+ */
+ protected void waitForSlingStartup() throws Exception {
+ // Use a static flag to make sure this runs only once in our test suite
+ if (slingStartupOk != null) {
+ if(slingStartupOk) {
+ return;
+ }
+ fail("Sling services not available. Already checked in earlier tests.");
+ }
+ slingStartupOk = false;
+
+ System.err.println("Checking if the required Sling services are started...");
+ System.err.println("(base URLs=" + HTTP_BASE_URL + " and " + WEBDAV_BASE_URL + ")");
+
+ // Try creating a node on server, every 500msec, until ok, with timeout
+ final List<String> exceptionMessages = new LinkedList<String>();
+ final long maxMsecToWait = 60 * 1000L;
+ final long startupTime = System.currentTimeMillis();
+
+ while(!slingStartupOk && (System.currentTimeMillis() < startupTime + maxMsecToWait) ) {
+ try {
+ slingStartupOk = slingServerReady();
+ } catch(Exception e) {
+ exceptionMessages.add(e.toString());
+ Thread.sleep(500L);
+ }
+ }
+
+ if(!slingStartupOk) {
+ StringBuffer msg = new StringBuffer("Server does not seem to be ready, after ");
+ msg.append(maxMsecToWait).append(" msec, got the following ").append(exceptionMessages.size()).append(" Exceptions:");
+ for (String e: exceptionMessages) {
+ msg.append(e).append("\n");
+ }
+ System.err.println(msg);
+ fail(msg.toString());
+ }
+
+ System.err.println("Sling services seem to be started, continuing with integration tests.");
+ }
+
+ /** Return true if able to create and retrieve a node on server */
+ protected boolean slingServerReady() throws Exception {
+ // create a node on the server
+ final String time = String.valueOf(System.currentTimeMillis());
+ final String url = HTTP_BASE_URL + "/WaitForSlingStartup/" + time;
+
+ // add some properties to the node
+ final Map<String,String> props = new HashMap<String,String>();
+ props.put("time", time);
+
+ // POST, get URL of created node and get content
+ {
+ final String urlOfNewNode = testClient.createNode(url, props, null, true);
+ final GetMethod get = new GetMethod(urlOfNewNode);
+ final int status = httpClient.executeMethod(get);
+ if(status!=200) {
+ throw new HttpStatusCodeException(200, status, "GET", urlOfNewNode);
+ }
+
+ final Header h = get.getResponseHeader("Content-Type");
+ final String contentType = h==null ? "" : h.getValue();
+ if(!contentType.startsWith("text/plain")) {
+ throw new IOException("Expected Content-Type=text/plain but got '" + contentType + "' for URL=" + urlOfNewNode);
+ }
+
+ final String content = get.getResponseBodyAsString();
+ if(!content.contains(time)) {
+ throw new IOException("Content does not contain '" + time + "' (" + content + ") at URL=" + urlOfNewNode);
+ }
+ }
+
+ // Also check that the WebDAV root is ready
+ {
+ // need the trailing slash in case the base URL is the context root
+ final String webDavUrl = WEBDAV_BASE_URL + "/";
+ final HttpAnyMethod options = new HttpAnyMethod("OPTIONS",webDavUrl);
+ final int status = httpClient.executeMethod(options);
+ if(status!=200) {
+ throw new HttpStatusCodeException(200, status, "OPTIONS", webDavUrl);
+ }
+
+ // The Allow header tells us that we're talking to a WebDAV server
+ final Header h = options.getResponseHeader("Allow");
+ if(h == null) {
+ throw new IOException("Response does not contain Allow header, at URL=" + webDavUrl);
+ } else if(h.getValue() == null) {
+ throw new IOException("Allow header has null value at URL=" + webDavUrl);
+ } else if(!h.getValue().contains("PROPFIND")) {
+ throw new IOException("Allow header (" + h.getValue() + " does not contain PROPFIND, at URL=" + webDavUrl);
+ }
+ }
+
+
+ return true;
+ }
+
+ /** Verify that given URL returns expectedStatusCode
+ * @throws IOException */
+ protected void assertHttpStatus(String urlString, int expectedStatusCode, String assertMessage) throws IOException {
+ final int status = httpClient.executeMethod(new GetMethod(urlString));
+ if(assertMessage == null) {
+ assertEquals(urlString,expectedStatusCode, status);
+ } else {
+ assertEquals(assertMessage, expectedStatusCode, status);
+ }
+ }
+
+ /** Verify that given URL returns expectedStatusCode
+ * @throws IOException */
+ protected void assertHttpStatus(String urlString, int expectedStatusCode) throws IOException {
+ assertHttpStatus(urlString, expectedStatusCode, null);
+ }
+
+ /** Execute a POST request and check status */
+ protected void assertPostStatus(String url, int expectedStatusCode, List<NameValuePair> postParams, String assertMessage)
+ throws IOException {
+ final PostMethod post = new PostMethod(url);
+ post.setFollowRedirects(false);
+
+ if(postParams!=null) {
+ final NameValuePair [] nvp = {};
+ post.setRequestBody(postParams.toArray(nvp));
+ }
+
+ final int status = httpClient.executeMethod(post);
+ if(assertMessage == null) {
+ assertEquals(expectedStatusCode, status);
+ } else {
+ assertEquals(assertMessage, expectedStatusCode, status);
+ }
+ }
+
+ /** retrieve the contents of given URL and assert its content type */
+ protected String getContent(String url, String expectedContentType) throws IOException {
+ return getContent(url, expectedContentType, null);
+ }
+
+ /** retrieve the contents of given URL and assert its content type
+ * @param expectedContentType use CONTENT_TYPE_DONTCARE if must not be checked
+ * @throws IOException
+ * @throws HttpException */
+ protected String getContent(String url, String expectedContentType, List<NameValuePair> params) throws IOException {
+ final GetMethod get = new GetMethod(url);
+ if(params != null) {
+ final NameValuePair [] nvp = new NameValuePair[0];
+ get.setQueryString(params.toArray(nvp));
+ }
+ final int status = httpClient.executeMethod(get);
+ final String content = get.getResponseBodyAsString();
+ assertEquals("Expected status 200 for " + url + " (content=" + content + ")",200,status);
+ final Header h = get.getResponseHeader("Content-Type");
+ if(expectedContentType == null) {
+ if(h!=null) {
+ fail("Expected null Content-Type, got " + h.getValue());
+ }
+ } else if(CONTENT_TYPE_DONTCARE.equals(expectedContentType)) {
+ // no check
+ } else if(h==null) {
+ fail(
+ "Expected Content-Type that starts with '" + expectedContentType
+ +" but got no Content-Type header at " + url
+ );
+ } else {
+ assertTrue(
+ "Expected Content-Type that starts with '" + expectedContentType
+ + "' for " + url + ", got '" + h.getValue() + "'",
+ h.getValue().startsWith(expectedContentType)
+ );
+ }
+ return content;
+ }
+
+ /** upload rendering test script, and return its URL for future deletion */
+ protected String uploadTestScript(String scriptPath, String localFilename,String filenameOnServer) throws IOException {
+ final String url = WEBDAV_BASE_URL + scriptPath + "/" + filenameOnServer;
+ final String testFile = "/integration-test/" + localFilename;
+ final InputStream data = getClass().getResourceAsStream(testFile);
+ if(data==null) {
+ fail("Test file not found:" + testFile);
+ }
+ try {
+ testClient.upload(url, data);
+ } finally {
+ if(data!=null) {
+ data.close();
+ }
+ }
+ return url;
+ }
+
+ protected void assertJavascript(String expectedOutput, String jsonData, String code) throws IOException {
+ assertJavascript(expectedOutput, jsonData, code, null);
+ }
+
+ /** Evaluate given code using given jsonData as the "data" object */
+ protected void assertJavascript(String expectedOutput, String jsonData, String code, String testInfo) throws IOException {
+ // build the code, something like
+ // data = <jsonData> ;
+ // <code>
+ final String jsCode = "data=" + jsonData + ";\n" + code;
+ final Context rhinoContext = Context.enter();
+ final ScriptableObject scope = rhinoContext.initStandardObjects();
+
+ // execute the script, out script variable maps to sw
+ final StringWriter sw = new StringWriter();
+ final PrintWriter pw = new PrintWriter(sw, true);
+ ScriptableObject.putProperty(scope, "out", Context.javaToJS(pw, scope));
+ final int lineNumber = 1;
+ final Object securityDomain = null;
+ rhinoContext.evaluateString(scope, jsCode, getClass().getSimpleName(),
+ lineNumber, securityDomain);
+
+ // check script output
+ pw.flush();
+ final String result = sw.toString().trim();
+ if(!result.equals(expectedOutput)) {
+ fail(
+ "Expected '" + expectedOutput
+ + "' but got '" + result
+ + "' for script='" + jsCode + "'"
+ + (testInfo==null ? "" : ", test info=" + testInfo)
+ );
+ }
+ }
+}
diff --git a/src/main/java/org/apache/sling/commons/testing/integration/SlingIntegrationTestClient.java b/src/main/java/org/apache/sling/commons/testing/integration/SlingIntegrationTestClient.java
new file mode 100644
index 0000000..ff37357
--- /dev/null
+++ b/src/main/java/org/apache/sling/commons/testing/integration/SlingIntegrationTestClient.java
@@ -0,0 +1,193 @@
+/*
+ * 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.commons.testing.integration;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.methods.DeleteMethod;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.commons.httpclient.methods.InputStreamRequestEntity;
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.commons.httpclient.methods.PutMethod;
+import org.apache.commons.httpclient.methods.multipart.FilePart;
+import org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity;
+import org.apache.commons.httpclient.methods.multipart.Part;
+import org.apache.commons.httpclient.methods.multipart.StringPart;
+
+/** Client functions to interact with Sling in integration tests */
+public class SlingIntegrationTestClient {
+ private final HttpClient httpClient;
+
+ public SlingIntegrationTestClient(HttpClient client) {
+ this.httpClient = client;
+ }
+
+ /** Upload a file to the Sling repository
+ * @return the HTTP status code
+ */
+ public int upload(String toUrl, InputStream is) throws IOException {
+ final PutMethod put = new PutMethod(toUrl);
+ put.setRequestEntity(new InputStreamRequestEntity(is));
+ return httpClient.executeMethod(put);
+ }
+
+ /** Delete a file from the Sling repository
+ * @return the HTTP status code
+ */
+ public int delete(String url) throws IOException {
+ final DeleteMethod delete = new DeleteMethod(url);
+ return httpClient.executeMethod(delete);
+ }
+
+ /** Create the given directory via WebDAV, if needed, under given URL */
+ public void mkdir(String url) throws IOException {
+ int status = 0;
+ status = httpClient.executeMethod(new GetMethod(url));
+ if(status != 200) {
+ status = httpClient.executeMethod(new HttpAnyMethod("MKCOL",url));
+ if(status!=201) {
+ throw new IOException("mkdir(" + url + ") failed, status code=" + status);
+ }
+ }
+ }
+
+ /** Create the given directory via WebDAV, including parent directories */
+ public void mkdirs(String baseUrl,String path) throws IOException {
+ final String [] paths = path.split("/");
+ if(baseUrl.endsWith("/")) {
+ baseUrl = baseUrl.substring(0,baseUrl.length() - 1);
+ }
+
+ String currentPath = baseUrl;
+ for(String pathElement : paths) {
+ if(pathElement.length() == 0) {
+ continue;
+ }
+ currentPath += "/" + pathElement;
+ mkdir(currentPath);
+ }
+
+ final String url = baseUrl + path;
+ final int status = httpClient.executeMethod(new GetMethod(url));
+ if(status!=200) {
+ throw new HttpStatusCodeException(200, status, "GET", url);
+ }
+ }
+
+ /** Call the other createNode method with headers==null */
+ public String createNode(String url, Map<String,String> nodeProperties) throws IOException {
+ return createNode(url, nodeProperties, null, false);
+ }
+
+ /** Create a node under given path, using a POST to Sling
+ * @param url under which node is created
+ * @param multiPart if true, does a multipart POST
+ * @return the URL that Sling provides to display the node
+ */
+ public String createNode(String url, Map<String,String> clientNodeProperties, Map<String,String> requestHeaders,boolean multiPart)
+ throws IOException {
+ final PostMethod post = new PostMethod(url);
+ post.setFollowRedirects(false);
+
+ // create a private copy of the properties to not tamper with
+ // the properties of the client
+ Map<String, String> nodeProperties = new HashMap<String, String>();
+
+ // add sling specific properties
+ nodeProperties.put(":redirect", url);
+ nodeProperties.put(":displayExtension", "");
+ nodeProperties.put(":status", "browser");
+
+ // take over any client provided properties
+ if (clientNodeProperties != null) {
+ nodeProperties.putAll(clientNodeProperties);
+ } else {
+ // add fake property - otherwise the node is not created
+ nodeProperties.put("jcr:created", "");
+ }
+
+ // force form encoding to UTF-8, which is what we use to convert the
+ // string parts into stream data
+ nodeProperties.put("_charset_", "UTF-8");
+
+ if( nodeProperties.size() > 0) {
+ if(multiPart) {
+ final List<Part> partList = new ArrayList<Part>();
+ for(Map.Entry<String,String> e : nodeProperties.entrySet()) {
+ if (e.getValue() != null) {
+ partList.add(new StringPart(e.getKey().toString(), e.getValue().toString(), "UTF-8"));
+ }
+ }
+ final Part [] parts = partList.toArray(new Part[partList.size()]);
+ post.setRequestEntity(new MultipartRequestEntity(parts, post.getParams()));
+ } else {
+ for(Map.Entry<String,String> e : nodeProperties.entrySet()) {
+ post.addParameter(e.getKey(),e.getValue());
+ }
+ }
+ }
+
+ if(requestHeaders != null) {
+ for(Map.Entry<String,String> e : requestHeaders.entrySet()) {
+ post.addRequestHeader(e.getKey(), e.getValue());
+ }
+ }
+
+ final int status = httpClient.executeMethod(post);
+ if(status!=302) {
+ throw new HttpStatusCodeException(302, status, "POST", url);
+ }
+ String location = post.getResponseHeader("Location").getValue();
+ post.releaseConnection();
+ // simple check if host is missing
+ if (!location.startsWith("http://")) {
+ String host = HttpTestBase.HTTP_BASE_URL;
+ int idx = host.indexOf('/', 8);
+ if (idx > 0) {
+ host = host.substring(0, idx);
+ }
+ location = host + location;
+ }
+ return location;
+ }
+
+ /** Upload to an file node structure, see SLING-168 */
+ public void uploadToFileNode(String url, File localFile, String fieldName, String typeHint)
+ throws IOException {
+
+ final Part[] parts = new Part[typeHint == null ? 1 : 2];
+ parts[0] = new FilePart(fieldName, localFile);
+ if (typeHint != null) {
+ parts[1] = new StringPart(fieldName + "@TypeHint", typeHint);
+ }
+ final PostMethod post = new PostMethod(url);
+ post.setFollowRedirects(false);
+ post.setRequestEntity(new MultipartRequestEntity(parts, post.getParams()));
+
+ final int status = httpClient.executeMethod(post);
+ if(status!=200) { // fmeschbe: The default sling status is 200, not 302
+ throw new HttpStatusCodeException(200, status, "POST", url);
+ }
+ }
+}
diff --git a/src/main/java/org/apache/sling/commons/testing/jcr/MockNode.java b/src/main/java/org/apache/sling/commons/testing/jcr/MockNode.java
new file mode 100644
index 0000000..51463c4
--- /dev/null
+++ b/src/main/java/org/apache/sling/commons/testing/jcr/MockNode.java
@@ -0,0 +1,358 @@
+/*
+ * 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.commons.testing.jcr;
+
+import java.io.InputStream;
+import java.util.Calendar;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.jcr.Item;
+import javax.jcr.ItemVisitor;
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import javax.jcr.Property;
+import javax.jcr.PropertyIterator;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.Value;
+import javax.jcr.ValueFormatException;
+import javax.jcr.lock.Lock;
+import javax.jcr.lock.LockException;
+import javax.jcr.nodetype.ConstraintViolationException;
+import javax.jcr.nodetype.NodeDefinition;
+import javax.jcr.nodetype.NodeType;
+import javax.jcr.version.Version;
+import javax.jcr.version.VersionException;
+import javax.jcr.version.VersionHistory;
+
+// simple mock implementation of a node
+public class MockNode implements Node {
+
+ private String path;
+ private Map <String, Property> properties = new HashMap <String, Property>();
+
+ private NodeType nodeType;
+
+ public MockNode(String path) {
+ this(path, null);
+ }
+
+ public MockNode(String path, String type) {
+ this.path = path;
+ this.nodeType = new MockNodeType(type);
+ }
+
+ public String getName() {
+ return path.substring(path.lastIndexOf('/') + 1);
+ }
+
+ public Node getParent() {
+ return new MockNode(path.substring(0, path.lastIndexOf('/')));
+ }
+
+ public String getPath() {
+ return path;
+ }
+
+ public NodeType getPrimaryNodeType() {
+ return nodeType;
+ }
+
+ public boolean isSame(Item otherItem) {
+ return equals(otherItem);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == this) {
+ return true;
+ } else if (!(obj instanceof MockNode)) {
+ return false;
+ }
+
+ return ((MockNode) obj).getPath().equals(getPath());
+ }
+
+ @Override
+ public int hashCode() {
+ return super.hashCode();
+ }
+
+ @Override
+ public String toString() {
+ return "MockNode: path=" + getPath();
+ }
+
+ public void addMixin(String mixinName) {
+ }
+
+ public Node addNode(String relPath) {
+ return null;
+ }
+
+ public Node addNode(String relPath, String primaryNodeTypeName) {
+ return null;
+ }
+
+ public boolean canAddMixin(String mixinName) {
+ return false;
+ }
+
+ public void cancelMerge(Version version) {
+
+ }
+
+ public Version checkin() {
+ return null;
+ }
+
+ public void checkout() {
+ }
+
+ public void doneMerge(Version version) {
+ }
+
+ public Version getBaseVersion() {
+ return null;
+ }
+
+ public String getCorrespondingNodePath(String workspaceName) {
+ return null;
+ }
+
+ public NodeDefinition getDefinition() {
+ return null;
+ }
+
+ public int getIndex() {
+ return 0;
+ }
+
+ public Lock getLock() {
+ return null;
+ }
+
+ public NodeType[] getMixinNodeTypes() {
+ return null;
+ }
+
+ public Node getNode(String relPath) {
+ return new MockNode(path + "/" + relPath);
+ }
+
+ public NodeIterator getNodes() {
+ return null;
+ }
+
+ public NodeIterator getNodes(String namePattern) {
+ return null;
+ }
+
+ public Item getPrimaryItem() {
+ return null;
+ }
+
+ public PropertyIterator getProperties() {
+ return new MockPropertyIterator(properties.values().iterator());
+ }
+
+ public PropertyIterator getProperties(String namePattern) {
+ return null;
+ }
+
+ public Property getProperty(String relPath) {
+ return null;
+ }
+
+ public PropertyIterator getReferences() {
+ return null;
+ }
+
+ public String getUUID() {
+ return null;
+ }
+
+ public VersionHistory getVersionHistory() {
+ return null;
+ }
+
+ public boolean hasNode(String relPath) {
+ return false;
+ }
+
+ public boolean hasNodes() {
+ return false;
+ }
+
+ public boolean hasProperties() {
+ return false;
+ }
+
+ public boolean hasProperty(String relPath) {
+ return false;
+ }
+
+ public boolean holdsLock() {
+ return false;
+ }
+
+ public boolean isCheckedOut() {
+ return false;
+ }
+
+ public boolean isLocked() {
+ return false;
+ }
+
+ public boolean isNodeType(String nodeTypeName) {
+ return false;
+ }
+
+ public Lock lock(boolean isDeep, boolean isSessionScoped) {
+ return null;
+ }
+
+ public NodeIterator merge(String srcWorkspace, boolean bestEffort) {
+ return null;
+ }
+
+ public void orderBefore(String srcChildRelPath, String destChildRelPath) {
+ }
+
+ public void removeMixin(String mixinName) {
+ }
+
+ public void restore(String versionName, boolean removeExisting) {
+ }
+
+ public void restore(Version version, boolean removeExisting) {
+ }
+
+ public void restore(Version version, String relPath, boolean removeExisting) {
+ }
+
+ public void restoreByLabel(String versionLabel, boolean removeExisting) {
+ }
+
+ public Property setProperty(String name, Value value) {
+ return null;
+ }
+
+ public Property setProperty(String name, Value[] values) {
+ return null;
+ }
+
+ public Property setProperty(String name, String[] values) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException {
+ MockProperty p = new MockProperty(name);
+ p.setValue(values);
+ properties.put(name, p);
+ return p;
+ }
+
+ public Property setProperty(String name, String value) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException {
+ MockProperty p = new MockProperty(name);
+ p.setValue(value);
+ properties.put(name, p);
+ return p;
+ }
+
+ public Property setProperty(String name, InputStream value) {
+ return null;
+ }
+
+ public Property setProperty(String name, boolean value) {
+ return null;
+ }
+
+ public Property setProperty(String name, double value) {
+ return null;
+ }
+
+ public Property setProperty(String name, long value) {
+ return null;
+ }
+
+ public Property setProperty(String name, Calendar value) {
+ return null;
+ }
+
+ public Property setProperty(String name, Node value) {
+ return null;
+ }
+
+ public Property setProperty(String name, Value value, int type) {
+ return null;
+ }
+
+ public Property setProperty(String name, Value[] values, int type) {
+ return null;
+ }
+
+ public Property setProperty(String name, String[] values, int type) {
+ return null;
+ }
+
+ public Property setProperty(String name, String value, int type) {
+ return null;
+ }
+
+ public void unlock() {
+ }
+
+ public void update(String srcWorkspaceName) {
+ }
+
+ public void accept(ItemVisitor visitor) {
+ }
+
+ public Item getAncestor(int depth) {
+ return null;
+ }
+
+ public int getDepth() {
+ return 0;
+ }
+
+ public Session getSession() {
+ return null;
+ }
+
+ public boolean isModified() {
+ return false;
+ }
+
+ public boolean isNew() {
+ return false;
+ }
+
+ public boolean isNode() {
+ return true;
+ }
+
+ public void refresh(boolean keepChanges) {
+ }
+
+ public void remove() {
+ }
+
+ public void save() {
+ }
+
+}
diff --git a/src/main/java/org/apache/sling/commons/testing/jcr/MockNodeIterator.java b/src/main/java/org/apache/sling/commons/testing/jcr/MockNodeIterator.java
new file mode 100644
index 0000000..8256c4a
--- /dev/null
+++ b/src/main/java/org/apache/sling/commons/testing/jcr/MockNodeIterator.java
@@ -0,0 +1,68 @@
+/*
+ * 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.commons.testing.jcr;
+
+import java.util.NoSuchElementException;
+
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+
+public class MockNodeIterator implements NodeIterator {
+
+ private Node[] nodes;
+ private int idx;
+
+ public MockNodeIterator(Node[] nodes) {
+ this.nodes = (nodes != null) ? nodes : new Node[0];
+ this.idx = 0;
+ }
+
+ public Node nextNode() {
+ if (!hasNext()) {
+ throw new NoSuchElementException();
+ }
+
+ return nodes[idx++];
+ }
+
+ public long getPosition() {
+ return idx-1;
+ }
+
+ public long getSize() {
+ return nodes.length;
+ }
+
+ public void skip(long skipNum) {
+ idx += skipNum;
+ }
+
+ public boolean hasNext() {
+ return idx < nodes.length;
+ }
+
+ public Object next() {
+ return nextNode();
+ }
+
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+
+}
diff --git a/src/main/java/org/apache/sling/commons/testing/jcr/MockNodeType.java b/src/main/java/org/apache/sling/commons/testing/jcr/MockNodeType.java
new file mode 100644
index 0000000..94b5c57
--- /dev/null
+++ b/src/main/java/org/apache/sling/commons/testing/jcr/MockNodeType.java
@@ -0,0 +1,98 @@
+/*
+ * 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.commons.testing.jcr;
+
+import javax.jcr.Value;
+import javax.jcr.nodetype.NodeDefinition;
+import javax.jcr.nodetype.NodeType;
+import javax.jcr.nodetype.PropertyDefinition;
+
+public class MockNodeType implements NodeType {
+
+ private String name;
+
+ public MockNodeType(String name) {
+ this.name = (name == null) ? "nt:unstructured" : name;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public boolean canAddChildNode(String childNodeName) {
+ return false;
+ }
+
+ public boolean canAddChildNode(String childNodeName, String nodeTypeName) {
+ return false;
+ }
+
+ public boolean canRemoveItem(String itemName) {
+ return false;
+ }
+
+ public boolean canSetProperty(String propertyName, Value value) {
+ return false;
+ }
+
+ public boolean canSetProperty(String propertyName, Value[] values) {
+ return false;
+ }
+
+ public NodeDefinition[] getChildNodeDefinitions() {
+ return null;
+ }
+
+ public NodeDefinition[] getDeclaredChildNodeDefinitions() {
+ return null;
+ }
+
+ public PropertyDefinition[] getDeclaredPropertyDefinitions() {
+ return null;
+ }
+
+ public NodeType[] getDeclaredSupertypes() {
+ return null;
+ }
+
+ public String getPrimaryItemName() {
+ return null;
+ }
+
+ public PropertyDefinition[] getPropertyDefinitions() {
+ return null;
+ }
+
+ public NodeType[] getSupertypes() {
+ return null;
+ }
+
+ public boolean hasOrderableChildNodes() {
+ return false;
+ }
+
+ public boolean isMixin() {
+ return false;
+ }
+
+ public boolean isNodeType(String nodeTypeName) {
+ return false;
+ }
+
+}
diff --git a/src/main/java/org/apache/sling/commons/testing/jcr/MockProperty.java b/src/main/java/org/apache/sling/commons/testing/jcr/MockProperty.java
new file mode 100644
index 0000000..b6d1035
--- /dev/null
+++ b/src/main/java/org/apache/sling/commons/testing/jcr/MockProperty.java
@@ -0,0 +1,207 @@
+/*
+ * 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.commons.testing.jcr;
+
+import java.io.InputStream;
+import java.util.Calendar;
+
+import javax.jcr.AccessDeniedException;
+import javax.jcr.InvalidItemStateException;
+import javax.jcr.Item;
+import javax.jcr.ItemExistsException;
+import javax.jcr.ItemNotFoundException;
+import javax.jcr.ItemVisitor;
+import javax.jcr.Node;
+import javax.jcr.Property;
+import javax.jcr.PropertyType;
+import javax.jcr.ReferentialIntegrityException;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.Value;
+import javax.jcr.ValueFormatException;
+import javax.jcr.lock.LockException;
+import javax.jcr.nodetype.ConstraintViolationException;
+import javax.jcr.nodetype.NoSuchNodeTypeException;
+import javax.jcr.nodetype.PropertyDefinition;
+import javax.jcr.version.VersionException;
+
+public class MockProperty implements Property {
+
+ private Value [] values = {};
+ private final String name;
+
+ public MockProperty(String name) {
+ this.name = name;
+ }
+
+ public boolean getBoolean() throws ValueFormatException, RepositoryException {
+ return false;
+ }
+
+ public Calendar getDate() throws ValueFormatException, RepositoryException {
+ return null;
+ }
+
+ public PropertyDefinition getDefinition() throws RepositoryException {
+ return new MockPropertyDefinition(values.length > 1);
+ }
+
+ public double getDouble() throws ValueFormatException, RepositoryException {
+ return 0;
+ }
+
+ public long getLength() throws ValueFormatException, RepositoryException {
+ return 0;
+ }
+
+ public long[] getLengths() throws ValueFormatException, RepositoryException {
+ return null;
+ }
+
+ public long getLong() throws ValueFormatException, RepositoryException {
+ return 0;
+ }
+
+ public Node getNode() throws ValueFormatException, RepositoryException {
+ return null;
+ }
+
+ public InputStream getStream() throws ValueFormatException, RepositoryException {
+ return null;
+ }
+
+ public String getString() throws ValueFormatException, RepositoryException {
+ if(values.length > 0) return values[0].getString();
+ return null;
+ }
+
+ public int getType() throws RepositoryException {
+ return PropertyType.STRING;
+ }
+
+ public Value getValue() throws ValueFormatException, RepositoryException {
+ return new MockValue(getString());
+ }
+
+ public Value[] getValues() throws ValueFormatException, RepositoryException {
+ return values;
+ }
+
+ public void setValue(boolean value) throws ValueFormatException, VersionException, LockException,
+ ConstraintViolationException, RepositoryException {
+ }
+
+ public void setValue(Calendar value) throws ValueFormatException, VersionException, LockException,
+ ConstraintViolationException, RepositoryException {
+ }
+
+ public void setValue(double value) throws ValueFormatException, VersionException, LockException,
+ ConstraintViolationException, RepositoryException {
+ }
+
+ public void setValue(InputStream value) throws ValueFormatException, VersionException, LockException,
+ ConstraintViolationException, RepositoryException {
+ }
+
+ public void setValue(long value) throws ValueFormatException, VersionException, LockException,
+ ConstraintViolationException, RepositoryException {
+ }
+
+ public void setValue(Node value) throws ValueFormatException, VersionException, LockException,
+ ConstraintViolationException, RepositoryException {
+ }
+
+ public void setValue(String value) throws ValueFormatException, VersionException, LockException,
+ ConstraintViolationException, RepositoryException {
+ values =new Value[1];
+ values[0] = new MockValue(value);
+ }
+
+ public void setValue(String[] inputValues) throws ValueFormatException, VersionException, LockException,
+ ConstraintViolationException, RepositoryException {
+ this.values = new Value[inputValues.length];
+ int i = 0;
+ for(String str : inputValues) {
+ values[i++] = new MockValue(str);
+ }
+ }
+
+ public void setValue(Value value) throws ValueFormatException, VersionException, LockException,
+ ConstraintViolationException, RepositoryException {
+ }
+
+ public void setValue(Value[] values) throws ValueFormatException, VersionException, LockException,
+ ConstraintViolationException, RepositoryException {
+ }
+
+ public void accept(ItemVisitor visitor) throws RepositoryException {
+ }
+
+ public Item getAncestor(int depth) throws ItemNotFoundException, AccessDeniedException, RepositoryException {
+ return null;
+ }
+
+ public int getDepth() throws RepositoryException {
+ return 0;
+ }
+
+ public String getName() throws RepositoryException {
+ return name;
+ }
+
+ public Node getParent() throws ItemNotFoundException, AccessDeniedException, RepositoryException {
+ return null;
+ }
+
+ public String getPath() throws RepositoryException {
+ return null;
+ }
+
+ public Session getSession() throws RepositoryException {
+ return null;
+ }
+
+ public boolean isModified() {
+ return false;
+ }
+
+ public boolean isNew() {
+ return false;
+ }
+
+ public boolean isNode() {
+ return false;
+ }
+
+ public boolean isSame(Item otherItem) throws RepositoryException {
+ return false;
+ }
+
+ public void refresh(boolean keepChanges) throws InvalidItemStateException, RepositoryException {
+ }
+
+ public void remove() throws VersionException, LockException, ConstraintViolationException, RepositoryException {
+ }
+
+ public void save() throws AccessDeniedException, ItemExistsException, ConstraintViolationException,
+ InvalidItemStateException, ReferentialIntegrityException, VersionException, LockException,
+ NoSuchNodeTypeException, RepositoryException {
+ }
+
+}
diff --git a/src/main/java/org/apache/sling/commons/testing/jcr/MockPropertyDefinition.java b/src/main/java/org/apache/sling/commons/testing/jcr/MockPropertyDefinition.java
new file mode 100644
index 0000000..c9a9733
--- /dev/null
+++ b/src/main/java/org/apache/sling/commons/testing/jcr/MockPropertyDefinition.java
@@ -0,0 +1,73 @@
+/*
+ * 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.commons.testing.jcr;
+
+import javax.jcr.Value;
+import javax.jcr.nodetype.NodeType;
+import javax.jcr.nodetype.PropertyDefinition;
+
+public class MockPropertyDefinition implements PropertyDefinition {
+
+ private boolean multiple;
+
+ public MockPropertyDefinition(boolean multiple) {
+ this.multiple = multiple;
+
+ }
+ public Value[] getDefaultValues() {
+ return null;
+ }
+
+ public int getRequiredType() {
+ return 0;
+ }
+
+ public String[] getValueConstraints() {
+ return null;
+ }
+
+ public boolean isMultiple() {
+ return multiple;
+ }
+
+ public NodeType getDeclaringNodeType() {
+ return null;
+ }
+
+ public String getName() {
+ return null;
+ }
+
+ public int getOnParentVersion() {
+ return 0;
+ }
+
+ public boolean isAutoCreated() {
+ return false;
+ }
+
+ public boolean isMandatory() {
+ return false;
+ }
+
+ public boolean isProtected() {
+ return false;
+ }
+
+}
diff --git a/src/main/java/org/apache/sling/commons/testing/jcr/MockPropertyIterator.java b/src/main/java/org/apache/sling/commons/testing/jcr/MockPropertyIterator.java
new file mode 100644
index 0000000..c141af4
--- /dev/null
+++ b/src/main/java/org/apache/sling/commons/testing/jcr/MockPropertyIterator.java
@@ -0,0 +1,61 @@
+/*
+ * 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.commons.testing.jcr;
+
+import java.util.Iterator;
+
+import javax.jcr.Property;
+import javax.jcr.PropertyIterator;
+
+public class MockPropertyIterator implements PropertyIterator {
+
+ private final Iterator<Property> iterator;
+ int index = 0;
+
+ public MockPropertyIterator(Iterator <Property> it) {
+ iterator = it;
+ }
+
+ public Property nextProperty() {
+ return iterator.next();
+ }
+
+ public long getPosition() {
+ return -1;
+ }
+
+ public long getSize() {
+ return -1;
+ }
+
+ public void skip(long skipNum) {
+ }
+
+ public boolean hasNext() {
+ return iterator.hasNext();
+ }
+
+ public Object next() {
+ return nextProperty();
+ }
+
+ public void remove() {
+ throw new Error("Not implemented: remove");
+ }
+}
diff --git a/src/main/java/org/apache/sling/commons/testing/jcr/MockValue.java b/src/main/java/org/apache/sling/commons/testing/jcr/MockValue.java
new file mode 100644
index 0000000..9d30cce
--- /dev/null
+++ b/src/main/java/org/apache/sling/commons/testing/jcr/MockValue.java
@@ -0,0 +1,65 @@
+/*
+ * 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.commons.testing.jcr;
+
+import java.io.InputStream;
+import java.util.Calendar;
+
+import javax.jcr.PropertyType;
+import javax.jcr.RepositoryException;
+import javax.jcr.Value;
+import javax.jcr.ValueFormatException;
+
+public class MockValue implements Value {
+
+ private final String value;
+
+ public MockValue(String str) {
+ value = str;
+ }
+
+ public boolean getBoolean() throws ValueFormatException, IllegalStateException, RepositoryException {
+ return false;
+ }
+
+ public Calendar getDate() throws ValueFormatException, IllegalStateException, RepositoryException {
+ return null;
+ }
+
+ public double getDouble() throws ValueFormatException, IllegalStateException, RepositoryException {
+ return 0;
+ }
+
+ public long getLong() throws ValueFormatException, IllegalStateException, RepositoryException {
+ return 0;
+ }
+
+ public InputStream getStream() throws IllegalStateException, RepositoryException {
+ return null;
+ }
+
+ public String getString() throws ValueFormatException, IllegalStateException, RepositoryException {
+ return value;
+ }
+
+ public int getType() {
+ return PropertyType.STRING;
+ }
+
+}
diff --git a/src/main/java/org/apache/sling/commons/testing/jcr/RepositoryTestBase.java b/src/main/java/org/apache/sling/commons/testing/jcr/RepositoryTestBase.java
new file mode 100644
index 0000000..fd7de67
--- /dev/null
+++ b/src/main/java/org/apache/sling/commons/testing/jcr/RepositoryTestBase.java
@@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.commons.testing.jcr;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.naming.NamingException;
+
+import junit.framework.TestCase;
+
+import org.apache.sling.jcr.api.SlingRepository;
+
+/** Base class for tests which need a Repository. Uses static
+ * variables to initialize it only once per test run.
+ */
+public class RepositoryTestBase extends TestCase {
+ private static SlingRepository repository;
+ protected Node testRoot;
+ protected Session session;
+ private int counter;
+
+ private static class ShutdownThread extends Thread {
+ @Override
+ public void run() {
+ try {
+ RepositoryUtil.stopRepository();
+ } catch(Exception e) {
+ System.out.println("Exception in ShutdownThread:" + e);
+ }
+ }
+
+ };
+
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ if(session != null) {
+ session.logout();
+ }
+ }
+
+ /** Return a JCR Session, initialized on demand */
+ protected Session getSession() throws RepositoryException, NamingException {
+ if(session == null) {
+ session = getRepository().loginAdministrative(null);
+ }
+ return session;
+ }
+
+ /** Return a test root node, created on demand, with a unique path */
+ protected Node getTestRootNode() throws RepositoryException, NamingException {
+ if(testRoot==null) {
+ final Node root = getSession().getRootNode();
+ final Node classRoot = root.addNode(getClass().getSimpleName());
+ testRoot = classRoot.addNode(System.currentTimeMillis() + "_" + (++counter));
+ }
+ return testRoot;
+ }
+
+ /** Return a Repository - first call initializes it, and a JVM
+ * shutdown hook is registered to stop it
+ */
+ protected SlingRepository getRepository() throws RepositoryException, NamingException {
+ if(repository != null) {
+ return repository;
+ }
+
+ synchronized (RepositoryTestBase.class) {
+ if(repository == null) {
+ RepositoryUtil.startRepository();
+ repository = RepositoryUtil.getRepository();
+ Runtime.getRuntime().addShutdownHook(new ShutdownThread());
+ }
+ return repository;
+ }
+ }
+}
diff --git a/src/main/java/org/apache/sling/commons/testing/jcr/RepositoryUtil.java b/src/main/java/org/apache/sling/commons/testing/jcr/RepositoryUtil.java
new file mode 100644
index 0000000..2df47a2
--- /dev/null
+++ b/src/main/java/org/apache/sling/commons/testing/jcr/RepositoryUtil.java
@@ -0,0 +1,207 @@
+/*
+ * 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.commons.testing.jcr;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Hashtable;
+
+import javax.jcr.Credentials;
+import javax.jcr.LoginException;
+import javax.jcr.NoSuchWorkspaceException;
+import javax.jcr.Repository;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.SimpleCredentials;
+import javax.jcr.Workspace;
+import javax.jcr.nodetype.NodeTypeManager;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+import org.apache.jackrabbit.api.JackrabbitNodeTypeManager;
+import org.apache.jackrabbit.core.jndi.RegistryHelper;
+import org.apache.sling.jcr.api.SlingRepository;
+
+/**
+ * Utility class for managing JCR repositories, used to
+ * initialize temporary Jackrabbit repositories for testing.
+ */
+public class RepositoryUtil {
+
+ public static final String REPOSITORY_NAME = "repositoryTest";
+
+ public static final String ADMIN_NAME = "admin";
+
+ public static final String ADMIN_PASSWORD = "admin";
+
+ public static final String CONTEXT_FACTORY = "org.apache.jackrabbit.core.jndi.provider.DummyInitialContextFactory";
+
+ public static final String PROVIDER_URL = "localhost";
+
+ public static final String CONFIG_FILE = "src/test/test-config/jackrabbit-test-config.xml";
+
+ public static final String HOME_DIR = "target/repository";
+
+ protected static InitialContext getInitialContext() throws NamingException {
+ final Hashtable<String, String> env = new Hashtable<String, String>();
+ env.put(Context.INITIAL_CONTEXT_FACTORY, CONTEXT_FACTORY);
+ env.put(Context.PROVIDER_URL, PROVIDER_URL);
+ return new InitialContext(env);
+ }
+
+ /**
+ * Start a new repository
+ *
+ * @throws RepositoryException when it is not possible to start the
+ * repository.
+ * @throws NamingException
+ */
+ public static void startRepository() throws RepositoryException,
+ NamingException {
+ RegistryHelper.registerRepository(getInitialContext(), REPOSITORY_NAME,
+ CONFIG_FILE, HOME_DIR, true);
+ }
+
+ /**
+ * Stop a repository.
+ *
+ * @throws NamingException when it is not possible to stop the
+ * repository
+ * @throws NamingException
+ */
+ public static void stopRepository() throws NamingException {
+ RegistryHelper.unregisterRepository(getInitialContext(),
+ REPOSITORY_NAME);
+ }
+
+ /**
+ * Get a repository
+ *
+ * @return a JCR repository reference
+ * @throws NamingException when it is not possible to get the
+ * repository. Before calling this method, the repository has to
+ * be registered (@see RepositoryUtil#registerRepository(String,
+ * String, String)
+ * @throws NamingException
+ */
+ public static SlingRepository getRepository() throws NamingException {
+ return new RepositoryWrapper((Repository) getInitialContext().lookup(
+ REPOSITORY_NAME));
+ }
+
+ /**
+ * Registers node types from the CND file read from the <code>source</code>
+ * with the node type manager available from the given <code>session</code>.
+ * <p>
+ * The <code>NodeTypeManager</code> returned by the <code>session</code>'s
+ * workspace is expected to be of type
+ * <code>org.apache.jackrabbit.api.JackrabbitNodeTypeManager</code> for
+ * the node type registration to succeed.
+ * <p>
+ * This method is not synchronized. It is up to the calling method to
+ * prevent paralell execution.
+ *
+ * @param session The <code>Session</code> providing the node type manager
+ * through which the node type is to be registered.
+ * @param source The <code>InputStream</code> from which the CND file is
+ * read.
+ * @return <code>true</code> if registration of all node types succeeded.
+ */
+ public static boolean registerNodeType(Session session, InputStream source)
+ throws IOException, RepositoryException {
+
+ Workspace workspace = session.getWorkspace();
+ NodeTypeManager ntm = workspace.getNodeTypeManager();
+ if (ntm instanceof JackrabbitNodeTypeManager) {
+ JackrabbitNodeTypeManager jntm = (JackrabbitNodeTypeManager) ntm;
+ try {
+ jntm.registerNodeTypes(source,
+ JackrabbitNodeTypeManager.TEXT_X_JCR_CND);
+ return true;
+ } catch (RepositoryException re) {
+ Throwable t = re.getCause();
+ if (t != null
+ && t.getClass().getName().endsWith(
+ ".InvalidNodeTypeDefException")) {
+ // hacky wacky: interpret message to check whether it is for
+ // duplicate node type -> very bad, that this is the only
+ // way to check !!!
+ if (re.getCause().getMessage().indexOf("already exists") >= 0) {
+ // alright, node types are already registered, ignore
+ // this
+ return true;
+ }
+ }
+
+ // get here to rethrow the RepositoryException
+ throw re;
+ }
+ }
+
+ return false;
+ }
+
+ public static final class RepositoryWrapper implements SlingRepository {
+
+ protected final Repository wrapped;
+
+ public RepositoryWrapper(Repository r) {
+ wrapped = r;
+ }
+
+ public String getDescriptor(String key) {
+ return wrapped.getDescriptor(key);
+ }
+
+ public String[] getDescriptorKeys() {
+ return wrapped.getDescriptorKeys();
+ }
+
+ public Session login() throws LoginException, RepositoryException {
+ return wrapped.login();
+ }
+
+ public Session login(Credentials credentials, String workspaceName)
+ throws LoginException, NoSuchWorkspaceException,
+ RepositoryException {
+ return wrapped.login(credentials, workspaceName);
+ }
+
+ public Session login(Credentials credentials) throws LoginException,
+ RepositoryException {
+ return wrapped.login(credentials);
+ }
+
+ public Session login(String workspaceName) throws LoginException,
+ NoSuchWorkspaceException, RepositoryException {
+ return wrapped.login(workspaceName);
+ }
+
+ public String getDefaultWorkspace() {
+ return "default";
+ }
+
+ public Session loginAdministrative(String workspace)
+ throws RepositoryException {
+ final Credentials credentials = new SimpleCredentials(ADMIN_NAME,
+ ADMIN_PASSWORD.toCharArray());
+ return this.login(credentials, workspace);
+ }
+
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/org/apache/sling/commons/testing/osgi/MockBundle.java b/src/main/java/org/apache/sling/commons/testing/osgi/MockBundle.java
new file mode 100644
index 0000000..f0e8a20
--- /dev/null
+++ b/src/main/java/org/apache/sling/commons/testing/osgi/MockBundle.java
@@ -0,0 +1,127 @@
+/*
+ * 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.commons.testing.osgi;
+
+import java.io.InputStream;
+import java.net.URL;
+import java.util.Dictionary;
+import java.util.Enumeration;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+
+public class MockBundle implements Bundle {
+
+ private long bundleId;
+
+ public MockBundle(long bundleId) {
+ this.bundleId = bundleId;
+ }
+
+ public long getBundleId() {
+ return bundleId;
+ }
+
+ public Enumeration<?> findEntries(String path, String filePattern,
+ boolean recurse) {
+ return null;
+ }
+
+ public URL getEntry(String name) {
+ return null;
+ }
+
+ public Enumeration<?> getEntryPaths(String path) {
+ return null;
+ }
+
+ public Dictionary<?, ?> getHeaders() {
+ return null;
+ }
+
+ public Dictionary<?, ?> getHeaders(String locale) {
+ return null;
+ }
+
+ public long getLastModified() {
+ return 0;
+ }
+
+ public String getLocation() {
+ return null;
+ }
+
+ public ServiceReference[] getRegisteredServices() {
+ return null;
+ }
+
+ public URL getResource(String name) {
+ return null;
+ }
+
+ public Enumeration<?> getResources(String name) {
+ return null;
+ }
+
+ public ServiceReference[] getServicesInUse() {
+ return null;
+ }
+
+ public int getState() {
+ return 0;
+ }
+
+ public String getSymbolicName() {
+ return null;
+ }
+
+ public boolean hasPermission(Object permission) {
+ return false;
+ }
+
+ public Class<?> loadClass(String name) throws ClassNotFoundException {
+ throw new ClassNotFoundException(name);
+ }
+
+ public void start() {
+
+ }
+
+ public void stop() {
+
+ }
+
+ public void uninstall() {
+
+ }
+
+ public void update() {
+
+ }
+
+ public void update(InputStream in) {
+
+ }
+
+ public BundleContext getBundleContext() {
+ return null;
+ }
+
+}
\ No newline at end of file
diff --git a/src/main/java/org/apache/sling/commons/testing/osgi/MockBundleContext.java b/src/main/java/org/apache/sling/commons/testing/osgi/MockBundleContext.java
new file mode 100644
index 0000000..185be5e
--- /dev/null
+++ b/src/main/java/org/apache/sling/commons/testing/osgi/MockBundleContext.java
@@ -0,0 +1,157 @@
+/*
+ * 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.commons.testing.osgi;
+
+import java.io.File;
+import java.io.InputStream;
+import java.util.Dictionary;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleException;
+import org.osgi.framework.BundleListener;
+import org.osgi.framework.Filter;
+import org.osgi.framework.FrameworkListener;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceListener;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
+
+class MockBundleContext implements BundleContext {
+ private MockBundle bundle;
+
+ public MockBundleContext(MockBundle bundle) {
+ this.bundle = bundle;
+ }
+
+ public String getProperty(String s) {
+ throw new UnsupportedOperationException("Not implemented");
+
+ }
+
+ public Bundle getBundle() {
+ return bundle;
+
+ }
+
+ public Bundle installBundle(String s) throws BundleException {
+ throw new UnsupportedOperationException("Not implemented");
+
+ }
+
+ public Bundle installBundle(String s, InputStream inputStream)
+ throws BundleException {
+ throw new UnsupportedOperationException("Not implemented");
+
+ }
+
+ public Bundle getBundle(long l) {
+ throw new UnsupportedOperationException("Not implemented");
+
+ }
+
+ public Bundle[] getBundles() {
+ throw new UnsupportedOperationException("Not implemented");
+
+ }
+
+ public void addServiceListener(ServiceListener serviceListener, String s)
+ throws InvalidSyntaxException {
+ throw new UnsupportedOperationException("Not implemented");
+
+ }
+
+ public void addServiceListener(ServiceListener serviceListener) {
+ throw new UnsupportedOperationException("Not implemented");
+
+ }
+
+ public void removeServiceListener(ServiceListener serviceListener) {
+ throw new UnsupportedOperationException("Not implemented");
+
+ }
+
+ public void addBundleListener(BundleListener bundleListener) {
+ throw new UnsupportedOperationException("Not implemented");
+
+ }
+
+ public void removeBundleListener(BundleListener bundleListener) {
+ throw new UnsupportedOperationException("Not implemented");
+
+ }
+
+ public void addFrameworkListener(FrameworkListener frameworkListener) {
+ throw new UnsupportedOperationException("Not implemented");
+
+ }
+
+ public void removeFrameworkListener(FrameworkListener frameworkListener) {
+ throw new UnsupportedOperationException("Not implemented");
+
+ }
+
+ public ServiceRegistration registerService(String[] strings, Object o,
+ Dictionary dictionary) {
+ throw new UnsupportedOperationException("Not implemented");
+
+ }
+
+ public ServiceRegistration registerService(String s, Object o,
+ Dictionary dictionary) {
+ return new MockServiceRegistration();
+ }
+
+ public ServiceReference[] getServiceReferences(String s, String s1)
+ throws InvalidSyntaxException {
+ throw new UnsupportedOperationException("Not implemented");
+
+ }
+
+ public ServiceReference[] getAllServiceReferences(String s, String s1)
+ throws InvalidSyntaxException {
+ throw new UnsupportedOperationException("Not implemented");
+
+ }
+
+ public ServiceReference getServiceReference(String s) {
+ throw new UnsupportedOperationException("Not implemented");
+
+ }
+
+ public Object getService(ServiceReference serviceReference) {
+ throw new UnsupportedOperationException("Not implemented");
+
+ }
+
+ public boolean ungetService(ServiceReference serviceReference) {
+ throw new UnsupportedOperationException("Not implemented");
+
+ }
+
+ public File getDataFile(String s) {
+ throw new UnsupportedOperationException("Not implemented");
+
+ }
+
+ public Filter createFilter(String s) throws InvalidSyntaxException {
+ throw new UnsupportedOperationException("Not implemented");
+
+ }
+}
diff --git a/src/main/java/org/apache/sling/commons/testing/osgi/MockComponentContext.java b/src/main/java/org/apache/sling/commons/testing/osgi/MockComponentContext.java
new file mode 100644
index 0000000..ee2a8e7
--- /dev/null
+++ b/src/main/java/org/apache/sling/commons/testing/osgi/MockComponentContext.java
@@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.commons.testing.osgi;
+
+import java.util.Dictionary;
+import java.util.Properties;
+
+import javax.servlet.Servlet;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.component.ComponentContext;
+import org.osgi.service.component.ComponentInstance;
+
+public class MockComponentContext implements ComponentContext {
+
+ private Dictionary properties = new Properties();
+
+ private MockBundleContext mockBundleContext;
+
+ private Servlet servlet;
+
+ public MockComponentContext(MockBundle bundle, Servlet servlet) {
+ mockBundleContext = new MockBundleContext(bundle);
+ this.servlet = servlet;
+ }
+
+ public void setProperty(Object key, Object value) {
+ // noinspection unchecked
+ this.properties.put(key, value);
+ }
+
+ public Dictionary getProperties() {
+ // noinspection ReturnOfCollectionOrArrayField
+ return this.properties;
+ }
+
+ public Object locateService(String name, ServiceReference reference) {
+ // the constant is from Sling Core, but we don't want to have a dep just because of this
+ String referenceName = (String) reference.getProperty("sling.core.servletName");
+ if (referenceName != null && referenceName.equals(name)) {
+ return this.servlet;
+ }
+
+ return null;
+ }
+
+ public BundleContext getBundleContext() {
+ return mockBundleContext;
+ }
+
+ public void disableComponent(String name) {
+ }
+
+ public void enableComponent(String name) {
+ }
+
+ public ComponentInstance getComponentInstance() {
+ return null;
+ }
+
+ public ServiceReference getServiceReference() {
+ return null;
+ }
+
+ public Bundle getUsingBundle() {
+ return null;
+ }
+
+ public Object locateService(String name) {
+ return null;
+ }
+
+ public Object[] locateServices(String name) {
+ return null;
+ }
+}
diff --git a/src/main/java/org/apache/sling/commons/testing/osgi/MockServiceReference.java b/src/main/java/org/apache/sling/commons/testing/osgi/MockServiceReference.java
new file mode 100644
index 0000000..29347c8
--- /dev/null
+++ b/src/main/java/org/apache/sling/commons/testing/osgi/MockServiceReference.java
@@ -0,0 +1,69 @@
+/*
+ * 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.commons.testing.osgi;
+
+import java.util.Collections;
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceReference;
+
+public class MockServiceReference implements ServiceReference {
+
+ private static long serviceIdCounter = 0;
+
+ private Bundle bundle;
+
+ private Dictionary<String, Object> props;
+
+ public MockServiceReference(Bundle bundle) {
+ this.bundle = bundle;
+ this.props = new Hashtable<String, Object>();
+
+ // mockup a service id
+ props.put(Constants.SERVICE_ID, serviceIdCounter++);
+ }
+
+ public Bundle getBundle() {
+ return bundle;
+ }
+
+ public void setProperty(String key, Object value) {
+ props.put(key, value);
+ }
+
+ public Object getProperty(String key) {
+ return props.get(key);
+ }
+
+ public String[] getPropertyKeys() {
+ return Collections.list(props.keys()).toArray(new String[props.size()]);
+ }
+
+ public Bundle[] getUsingBundles() {
+ return null;
+ }
+
+ public boolean isAssignableTo(Bundle bundle, String className) {
+ return false;
+ }
+
+}
\ No newline at end of file
diff --git a/src/main/java/org/apache/sling/commons/testing/osgi/MockServiceRegistration.java b/src/main/java/org/apache/sling/commons/testing/osgi/MockServiceRegistration.java
new file mode 100644
index 0000000..70557f1
--- /dev/null
+++ b/src/main/java/org/apache/sling/commons/testing/osgi/MockServiceRegistration.java
@@ -0,0 +1,39 @@
+/*
+ * 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.commons.testing.osgi;
+
+import java.util.Dictionary;
+
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
+
+class MockServiceRegistration implements ServiceRegistration {
+
+ public ServiceReference getReference() {
+ throw new UnsupportedOperationException("Not implemented");
+ }
+
+ public void setProperties(Dictionary dictionary) {
+ throw new UnsupportedOperationException("Not implemented");
+ }
+
+ public void unregister() {
+ throw new UnsupportedOperationException("Not implemented");
+ }
+}
diff --git a/src/main/java/org/apache/sling/commons/testing/sling/MockRequestPathInfo.java b/src/main/java/org/apache/sling/commons/testing/sling/MockRequestPathInfo.java
new file mode 100644
index 0000000..4f6e076
--- /dev/null
+++ b/src/main/java/org/apache/sling/commons/testing/sling/MockRequestPathInfo.java
@@ -0,0 +1,58 @@
+/*
+ * 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.commons.testing.sling;
+
+import org.apache.sling.api.request.RequestPathInfo;
+
+class MockRequestPathInfo implements RequestPathInfo {
+
+ private final String selectors;
+
+ private final String extension;
+
+ private final String suffix;
+
+ public MockRequestPathInfo(String selectors, String extension, String suffix) {
+ this.selectors = selectors;
+ this.extension = extension;
+ this.suffix = suffix;
+ }
+
+ public String getExtension() {
+ return extension;
+ }
+
+ public String getResourcePath() {
+ return null;
+ }
+
+ public String getSelectorString() {
+ return selectors;
+ }
+
+ public String[] getSelectors() {
+ return (getSelectorString() != null)
+ ? getSelectorString().split("\\.")
+ : new String[0];
+ }
+
+ public String getSuffix() {
+ return suffix;
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/org/apache/sling/commons/testing/sling/MockRequestProgressTracker.java b/src/main/java/org/apache/sling/commons/testing/sling/MockRequestProgressTracker.java
new file mode 100644
index 0000000..41c43e2
--- /dev/null
+++ b/src/main/java/org/apache/sling/commons/testing/sling/MockRequestProgressTracker.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.commons.testing.sling;
+
+import java.io.PrintWriter;
+import java.util.Collections;
+import java.util.Iterator;
+
+import org.apache.sling.api.request.RequestProgressTracker;
+
+public class MockRequestProgressTracker implements RequestProgressTracker {
+
+ public void dump(PrintWriter writer) {
+ }
+
+ public Iterator<String> getMessages() {
+ return Collections.<String> emptyList().iterator();
+ }
+
+ public void log(String message) {
+ }
+
+ public void log(String format, Object... args) {
+ }
+
+ public void logTimer(String timerName) {
+ }
+
+ public void logTimer(String timerName, String format, Object... args) {
+ }
+
+ public void startTimer(String timerName) {
+ }
+
+ public void done() {
+ }
+}
diff --git a/src/main/java/org/apache/sling/commons/testing/sling/MockResource.java b/src/main/java/org/apache/sling/commons/testing/sling/MockResource.java
new file mode 100644
index 0000000..ee3d39b
--- /dev/null
+++ b/src/main/java/org/apache/sling/commons/testing/sling/MockResource.java
@@ -0,0 +1,60 @@
+/*
+ * 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.commons.testing.sling;
+
+import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.api.resource.SyntheticResource;
+
+public class MockResource extends SyntheticResource {
+
+ private String resourceType;
+ private String resourceSuperType;
+
+ public MockResource(ResourceResolver resourceResolver, String path,
+ String resourceType) {
+ this(resourceResolver, path, resourceType, null);
+ }
+
+ public MockResource(ResourceResolver resourceResolver, String path,
+ String resourceType, String resourceSuperType) {
+ super(resourceResolver, path, resourceType);
+
+ setResourceType(resourceType);
+ setResourceSuperType(resourceSuperType);
+ }
+
+ @Override
+ public String getResourceType() {
+ return resourceType;
+ }
+
+ @Override
+ public void setResourceType(String resourceType) {
+ this.resourceType = resourceType;
+ }
+
+ @Override
+ public String getResourceSuperType() {
+ return resourceSuperType;
+ }
+
+ public void setResourceSuperType(String resourceSuperType) {
+ this.resourceSuperType = resourceSuperType;
+ }
+}
diff --git a/src/main/java/org/apache/sling/commons/testing/sling/MockResourceResolver.java b/src/main/java/org/apache/sling/commons/testing/sling/MockResourceResolver.java
new file mode 100644
index 0000000..22ba04c
--- /dev/null
+++ b/src/main/java/org/apache/sling/commons/testing/sling/MockResourceResolver.java
@@ -0,0 +1,154 @@
+/*
+ * 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.commons.testing.sling;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.NoSuchElementException;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.resource.ResourceResolver;
+
+public class MockResourceResolver implements ResourceResolver {
+
+ private String[] searchPath;
+
+ private Map<String, Resource> resources = new LinkedHashMap<String, Resource>();
+
+ private Map<String, Collection<Resource>> children = new LinkedHashMap<String, Collection<Resource>>();
+
+ public void addResource(Resource resource) {
+ this.resources.put(resource.getPath(), resource);
+ }
+
+ public void addChildren(Resource parent, Collection<Resource> children) {
+ this.children.put(parent.getPath(), children);
+ }
+
+ public Resource resolve(HttpServletRequest request) {
+ throw new UnsupportedOperationException("Not implemented");
+
+ }
+
+ public Resource resolve(String absPath) {
+ throw new UnsupportedOperationException("Not implemented");
+
+ }
+
+ public String map(String resourcePath) {
+ return null;
+
+ }
+
+ public Resource getResource(String path) {
+ return resources.get(path);
+ }
+
+ public Resource getResource(Resource base, String path) {
+ if (!path.startsWith("/")) {
+ path = base.getPath() + "/" + path;
+ }
+ return getResource(path);
+ }
+
+ public String[] getSearchPath() {
+ return searchPath.clone();
+
+ }
+
+ public Iterator<Resource> listChildren(final Resource parent) {
+ Collection<Resource> childCollection = children.get(parent.getPath());
+ if (childCollection != null) {
+ return childCollection.iterator();
+ }
+
+ return new Iterator<Resource>() {
+ final String parentPath = parent.getPath() + "/";
+
+ final Iterator<Resource> elements = resources.values().iterator();
+
+ Resource nextResource = seek();
+
+ public boolean hasNext() {
+ return nextResource != null;
+ }
+
+ public Resource next() {
+ if (!hasNext()) {
+ throw new NoSuchElementException();
+ }
+
+ Resource result = nextResource;
+ nextResource = seek();
+ return result;
+ }
+
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+
+ private Resource seek() {
+ while (elements.hasNext()) {
+ Resource next = elements.next();
+ String path = next.getPath();
+ if (path.startsWith(parentPath)
+ && path.indexOf('/', parentPath.length()) < 0) {
+ return next;
+ }
+ }
+ return null;
+ }
+ };
+ }
+
+ public Iterator<Resource> findResources(String query, String language) {
+ throw new UnsupportedOperationException("Not implemented");
+
+ }
+
+ public Iterator<Map<String, Object>> queryResources(String query,
+ String language) {
+ throw new UnsupportedOperationException("Not implemented");
+
+ }
+
+ public <AdapterType> AdapterType adaptTo(Class<AdapterType> type) {
+ throw new UnsupportedOperationException("Not implemented");
+
+ }
+
+ public void setSearchPath(String... searchPath) {
+ if (searchPath == null) {
+ this.searchPath = new String[0];
+ } else {
+ this.searchPath = new String[searchPath.length];
+ for (int i=0; i < searchPath.length; i++) {
+ String entry = searchPath[i];
+ if (!entry.endsWith("/")) {
+ entry = entry.concat("/");
+ }
+ this.searchPath[i] = entry;
+ }
+ }
+ }
+}
diff --git a/src/main/java/org/apache/sling/commons/testing/sling/MockSlingHttpServletRequest.java b/src/main/java/org/apache/sling/commons/testing/sling/MockSlingHttpServletRequest.java
new file mode 100644
index 0000000..0e5b016
--- /dev/null
+++ b/src/main/java/org/apache/sling/commons/testing/sling/MockSlingHttpServletRequest.java
@@ -0,0 +1,382 @@
+/*
+ * 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.commons.testing.sling;
+
+import java.io.BufferedReader;
+import java.security.Principal;
+import java.util.Enumeration;
+import java.util.Locale;
+import java.util.Map;
+import java.util.ResourceBundle;
+
+import javax.servlet.RequestDispatcher;
+import javax.servlet.ServletInputStream;
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpSession;
+
+import org.apache.sling.api.SlingHttpServletRequest;
+import org.apache.sling.api.request.RequestDispatcherOptions;
+import org.apache.sling.api.request.RequestParameter;
+import org.apache.sling.api.request.RequestParameterMap;
+import org.apache.sling.api.request.RequestPathInfo;
+import org.apache.sling.api.request.RequestProgressTracker;
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.api.resource.SyntheticResource;
+
+/**
+ * Mock request object. This does not do anything useful, it just returns the
+ * constructor parameter <code>secure</code> in the <code>isSecure</code>
+ * method.
+ */
+public class MockSlingHttpServletRequest implements SlingHttpServletRequest {
+
+ private Resource resource;
+
+ private String method;
+
+ private final RequestPathInfo requestPathInfo;
+
+ private final String queryString;
+
+ private boolean secure = false;
+
+ private MockResourceResolver mockResourceResolver;
+
+ private RequestProgressTracker mockRequestProgressTracker;
+
+ public static final String RESOURCE_TYPE = "foo/bar";
+
+ MockSlingHttpServletRequest() {
+ this(null, null, null, null, null);
+ }
+
+ public MockSlingHttpServletRequest(String resourcePath, String selectors,
+ String extension, String suffix, String queryString) {
+ this.resource = new SyntheticResource(null, resourcePath, RESOURCE_TYPE);
+ this.requestPathInfo = new MockRequestPathInfo(selectors, extension,
+ suffix);
+ this.queryString = queryString;
+
+ setMethod(null);
+ }
+
+ public void setResourceResolver(MockResourceResolver resolver) {
+ this.mockResourceResolver = resolver;
+
+ // recreate request resource with the new resolver
+ if (resource.getResourceResolver() == null) {
+ this.resource = new SyntheticResource(resolver, resource.getPath(),
+ resource.getResourceType());
+ }
+ }
+
+ public void setResource(Resource resource) {
+ this.resource = resource;
+ }
+
+ public void setSecure(boolean secure) {
+ this.secure = secure;
+ }
+
+ public void setMethod(String method) {
+ this.method = (method == null) ? "GET" : method.toUpperCase();
+ }
+
+ public Cookie getCookie(String name) {
+ return null;
+ }
+
+ public RequestDispatcher getRequestDispatcher(String path,
+ RequestDispatcherOptions options) {
+ return null;
+ }
+
+ public RequestDispatcher getRequestDispatcher(Resource resource,
+ RequestDispatcherOptions options) {
+ return null;
+ }
+
+ public RequestDispatcher getRequestDispatcher(Resource resource) {
+ return null;
+ }
+
+ public RequestParameter getRequestParameter(String name) {
+ return null;
+ }
+
+ public RequestParameterMap getRequestParameterMap() {
+ return null;
+ }
+
+ public RequestParameter[] getRequestParameters(String name) {
+ return null;
+ }
+
+ public RequestPathInfo getRequestPathInfo() {
+ return requestPathInfo;
+ }
+
+ public RequestProgressTracker getRequestProgressTracker() {
+ if (mockRequestProgressTracker == null) {
+ mockRequestProgressTracker = new MockRequestProgressTracker();
+ }
+ return mockRequestProgressTracker;
+ }
+
+ public Resource getResource() {
+ return resource;
+ }
+
+ public ResourceBundle getResourceBundle(Locale locale) {
+ return null;
+ }
+
+ public ResourceBundle getResourceBundle(String baseName, Locale locale) {
+ return null;
+ }
+
+ public ResourceResolver getResourceResolver() {
+ return mockResourceResolver;
+ }
+
+ public String getResponseContentType() {
+ return null;
+ }
+
+ public Enumeration<String> getResponseContentTypes() {
+ return null;
+ }
+
+ public String getAuthType() {
+ return null;
+ }
+
+ public String getContextPath() {
+ return null;
+ }
+
+ public Cookie[] getCookies() {
+ return null;
+ }
+
+ public long getDateHeader(String name) {
+ return 0;
+ }
+
+ public String getHeader(String name) {
+ return null;
+ }
+
+ public Enumeration<?> getHeaderNames() {
+ return null;
+ }
+
+ public Enumeration<?> getHeaders(String name) {
+ return null;
+ }
+
+ public int getIntHeader(String name) {
+ return 0;
+ }
+
+ public String getMethod() {
+ return method;
+ }
+
+ public String getPathInfo() {
+ return null;
+ }
+
+ public String getPathTranslated() {
+ return null;
+ }
+
+ public String getQueryString() {
+ return queryString;
+ }
+
+ public String getRemoteUser() {
+ return null;
+ }
+
+ public String getRequestURI() {
+ return null;
+ }
+
+ public StringBuffer getRequestURL() {
+ return null;
+ }
+
+ public String getRequestedSessionId() {
+ return null;
+ }
+
+ public String getServletPath() {
+ return null;
+ }
+
+ public HttpSession getSession() {
+ return null;
+ }
+
+ public HttpSession getSession(boolean create) {
+ return null;
+ }
+
+ public Principal getUserPrincipal() {
+ return null;
+ }
+
+ public boolean isRequestedSessionIdFromCookie() {
+ return false;
+ }
+
+ public boolean isRequestedSessionIdFromURL() {
+ return false;
+ }
+
+ public boolean isRequestedSessionIdFromUrl() {
+ return false;
+ }
+
+ public boolean isRequestedSessionIdValid() {
+ return false;
+ }
+
+ public boolean isUserInRole(String role) {
+ return false;
+ }
+
+ public Object getAttribute(String name) {
+ return null;
+ }
+
+ public Enumeration<?> getAttributeNames() {
+ return null;
+ }
+
+ public String getCharacterEncoding() {
+ return null;
+ }
+
+ public int getContentLength() {
+ return 0;
+ }
+
+ public String getContentType() {
+ return null;
+ }
+
+ public ServletInputStream getInputStream() {
+ return null;
+ }
+
+ public String getLocalAddr() {
+ return null;
+ }
+
+ public String getLocalName() {
+ return null;
+ }
+
+ public int getLocalPort() {
+ return 0;
+ }
+
+ public Locale getLocale() {
+ return null;
+ }
+
+ public Enumeration<?> getLocales() {
+ return null;
+ }
+
+ public String getParameter(String name) {
+ return null;
+ }
+
+ public Map<?, ?> getParameterMap() {
+ return null;
+ }
+
+ public Enumeration<?> getParameterNames() {
+ return null;
+ }
+
+ public String[] getParameterValues(String name) {
+ return null;
+ }
+
+ public String getProtocol() {
+ return null;
+ }
+
+ public BufferedReader getReader() {
+ return null;
+ }
+
+ public String getRealPath(String path) {
+ return null;
+ }
+
+ public String getRemoteAddr() {
+ return null;
+ }
+
+ public String getRemoteHost() {
+ return null;
+ }
+
+ public int getRemotePort() {
+ return 0;
+ }
+
+ public RequestDispatcher getRequestDispatcher(String path) {
+ return null;
+ }
+
+ public String getScheme() {
+ return null;
+ }
+
+ public String getServerName() {
+ return null;
+ }
+
+ public int getServerPort() {
+ return 0;
+ }
+
+ public boolean isSecure() {
+ return this.secure;
+ }
+
+ public void removeAttribute(String name) {
+
+ }
+
+ public void setAttribute(String name, Object o) {
+
+ }
+
+ public void setCharacterEncoding(String env) {
+
+ }
+}
diff --git a/src/main/resources/META-INF/DISCLAIMER b/src/main/resources/META-INF/DISCLAIMER
new file mode 100644
index 0000000..90850c2
--- /dev/null
+++ b/src/main/resources/META-INF/DISCLAIMER
@@ -0,0 +1,7 @@
+Apache Sling is an effort undergoing incubation at The Apache Software Foundation (ASF),
+sponsored by the Apache Jackrabbit PMC. Incubation is required of all newly accepted
+projects until a further review indicates that the infrastructure, communications,
+and decision making process have stabilized in a manner consistent with other
+successful ASF projects. While incubation status is not necessarily a reflection of
+the completeness or stability of the code, it does indicate that the project has yet
+to be fully endorsed by the ASF.
\ No newline at end of file
diff --git a/src/main/resources/META-INF/LICENSE b/src/main/resources/META-INF/LICENSE
new file mode 100644
index 0000000..d645695
--- /dev/null
+++ b/src/main/resources/META-INF/LICENSE
@@ -0,0 +1,202 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed 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.
diff --git a/src/main/resources/META-INF/NOTICE b/src/main/resources/META-INF/NOTICE
new file mode 100644
index 0000000..14dc85c
--- /dev/null
+++ b/src/main/resources/META-INF/NOTICE
@@ -0,0 +1,8 @@
+Apache Sling Testing Utilities
+Copyright 2008 The Apache Software Foundation
+
+Apache Sling is based on source code originally developed
+by Day Software (http://www.day.com/).
+
+This product includes software developed at
+The Apache Software Foundation (http://www.apache.org/).