You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by bd...@apache.org on 2015/12/08 11:59:49 UTC
svn commit: r1718557 - in /sling/trunk/testing/samples/bundle-with-it: ./
src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/
src/main/java/org/apache/sling/ src/main/java/org/apache/sling/testing/
src/main/java/org/apache/sling/testi...
Author: bdelacretaz
Date: Tue Dec 8 10:59:49 2015
New Revision: 1718557
URL: http://svn.apache.org/viewvc?rev=1718557&view=rev
Log:
Integration tests of this bundle pass, both server-side teleported tests and HTTP-based tests
Added:
sling/trunk/testing/samples/bundle-with-it/src/main/
sling/trunk/testing/samples/bundle-with-it/src/main/java/
sling/trunk/testing/samples/bundle-with-it/src/main/java/org/
sling/trunk/testing/samples/bundle-with-it/src/main/java/org/apache/
sling/trunk/testing/samples/bundle-with-it/src/main/java/org/apache/sling/
sling/trunk/testing/samples/bundle-with-it/src/main/java/org/apache/sling/testing/
sling/trunk/testing/samples/bundle-with-it/src/main/java/org/apache/sling/testing/samples/
sling/trunk/testing/samples/bundle-with-it/src/main/java/org/apache/sling/testing/samples/bundlewit/
sling/trunk/testing/samples/bundle-with-it/src/main/java/org/apache/sling/testing/samples/bundlewit/api/
sling/trunk/testing/samples/bundle-with-it/src/main/java/org/apache/sling/testing/samples/bundlewit/api/ResourceMimeTypeDetector.java
sling/trunk/testing/samples/bundle-with-it/src/main/java/org/apache/sling/testing/samples/bundlewit/api/package-info.java
sling/trunk/testing/samples/bundle-with-it/src/main/java/org/apache/sling/testing/samples/bundlewit/impl/
sling/trunk/testing/samples/bundle-with-it/src/main/java/org/apache/sling/testing/samples/bundlewit/impl/MimeTypeServlet.java
sling/trunk/testing/samples/bundle-with-it/src/main/java/org/apache/sling/testing/samples/bundlewit/impl/ResourceMimeTypeDetectorImpl.java
sling/trunk/testing/samples/bundle-with-it/src/test/java/org/apache/sling/testing/samples/bundlewit/MimeTypeServletHttpIT.java
sling/trunk/testing/samples/bundle-with-it/src/test/java/org/apache/sling/testing/samples/bundlewit/MockResource.java
sling/trunk/testing/samples/bundle-with-it/src/test/java/org/apache/sling/testing/samples/bundlewit/ResourceMimeTypeDetectorIT.java
sling/trunk/testing/samples/bundle-with-it/src/test/java/org/apache/sling/testing/samples/bundlewit/SampleUnitTest.java
Modified:
sling/trunk/testing/samples/bundle-with-it/pom.xml
sling/trunk/testing/samples/bundle-with-it/src/test/java/org/apache/sling/junit/teleporter/customizers/BWIT_TeleporterCustomizer.java
sling/trunk/testing/samples/bundle-with-it/src/test/java/org/apache/sling/testing/samples/bundlewit/BasicTeleportedIT.java
sling/trunk/testing/samples/bundle-with-it/src/test/java/org/apache/sling/testing/samples/bundlewit/OsgiConsoleHttpIT.java
Modified: sling/trunk/testing/samples/bundle-with-it/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/testing/samples/bundle-with-it/pom.xml?rev=1718557&r1=1718556&r2=1718557&view=diff
==============================================================================
--- sling/trunk/testing/samples/bundle-with-it/pom.xml (original)
+++ sling/trunk/testing/samples/bundle-with-it/pom.xml Tue Dec 8 10:59:49 2015
@@ -33,24 +33,11 @@
<name>Apache Sling Testing - sample bundle with integration tests</name>
<description>
- Sample project that demonstrates a bundle with integration tests
- in the same Maven module. Uses both HTTP-based and teleported
- server-side tests.
+ Sample project that demonstrates a bundle with unit and integration
+ tests in the same Maven module, running against a full Sling instance.
+ Uses both HTTP-based and teleported server-side tests.
</description>
- <!--
- To keep the instance under test running and run individual tests
- against it, use:
-
- mvn clean verify -DkeepJarRunning=true -Dhttp.port=8080
-
- optionally using jar.executor.vm.options to enable remote debugging,
- and in another console:
-
- mvn -o verify -Dtest.server.url=http://localhost:8080
-
- optionally using -Dmaven.surefire.debug to enable debugging.
- -->
<properties>
<!-- Set this to run the server on a specific port
<http.port></http.port>
@@ -113,6 +100,10 @@
<extensions>true</extensions>
</plugin>
<plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-scr-plugin</artifactId>
+ </plugin>
+ <plugin>
<groupId>org.apache.rat</groupId>
<artifactId>apache-rat-plugin</artifactId>
<configuration>
@@ -151,7 +142,7 @@
</goals>
<phase>process-resources</phase>
<configuration>
- <outputDirectory>${project.build.directory}/sling/additional-bundles</outputDirectory>
+ <outputDirectory>${project.build.directory}</outputDirectory>
<excludeTransitive>true</excludeTransitive>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
@@ -196,7 +187,6 @@
</execution>
</executions>
<configuration>
- <debugForkedProcess>${maven.surefire.debug}</debugForkedProcess>
<systemPropertyVariables>
<!--
TODO this is a fairly complicated setup, we might
@@ -219,7 +209,7 @@
<jar.executor.jar.name.regexp>org.apache.sling.launchpad.*jar$</jar.executor.jar.name.regexp>
<jar.executor.work.folder>${jar.executor.work.folder}</jar.executor.work.folder>
<jar.executor.jar.options>${jar.executor.jar.options}</jar.executor.jar.options>
- <additional.bundles.path>${project.basedir}/target/sling/additional-bundles</additional.bundles.path>
+ <additional.bundles.path>${project.build.directory}</additional.bundles.path>
<keepJarRunning>${keepJarRunning}</keepJarRunning>
<server.ready.timeout.seconds>60</server.ready.timeout.seconds>
<sling.testing.timeout.multiplier>${sling.testing.timeout.multiplier}</sling.testing.timeout.multiplier>
@@ -235,6 +225,9 @@
All bundles must be listed as dependencies in this pom, or they won't be installed.
-->
<sling.additional.bundle.1>org.apache.sling.junit.core</sling.additional.bundle.1>
+
+ <!-- Install this bundle for integration tests (TODO what's the Maven property for this name??) -->
+ <sling.additional.bundle.2>org.apache.sling.testing.samples.bundle-with-it-${project.version}.jar</sling.additional.bundle.2>
</systemPropertyVariables>
</configuration>
</plugin>
@@ -252,6 +245,27 @@
</dependency>
<dependency>
<groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.api</artifactId>
+ <version>2.4.2</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.commons.mime</artifactId>
+ <version>2.1.2</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>org.apache.felix.scr.annotations</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.junit.core</artifactId>
<version>1.0.14</version>
<scope>provided</scope>
@@ -265,7 +279,8 @@
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.junit.teleporter</artifactId>
- <version>1.0.2</version>
+ <!-- SNAPSHOT required due to SLING-5365 -->
+ <version>1.0.5-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency>
Added: sling/trunk/testing/samples/bundle-with-it/src/main/java/org/apache/sling/testing/samples/bundlewit/api/ResourceMimeTypeDetector.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/samples/bundle-with-it/src/main/java/org/apache/sling/testing/samples/bundlewit/api/ResourceMimeTypeDetector.java?rev=1718557&view=auto
==============================================================================
--- sling/trunk/testing/samples/bundle-with-it/src/main/java/org/apache/sling/testing/samples/bundlewit/api/ResourceMimeTypeDetector.java (added)
+++ sling/trunk/testing/samples/bundle-with-it/src/main/java/org/apache/sling/testing/samples/bundlewit/api/ResourceMimeTypeDetector.java Tue Dec 8 10:59:49 2015
@@ -0,0 +1,26 @@
+/*
+ * 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.testing.samples.bundlewit.api;
+
+import org.apache.sling.api.resource.Resource;
+
+/** A simplistic service that computes the mime-type of
+ * a Resource based on its path.
+ */
+public interface ResourceMimeTypeDetector {
+ String getMimeType(Resource r);
+}
Added: sling/trunk/testing/samples/bundle-with-it/src/main/java/org/apache/sling/testing/samples/bundlewit/api/package-info.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/samples/bundle-with-it/src/main/java/org/apache/sling/testing/samples/bundlewit/api/package-info.java?rev=1718557&view=auto
==============================================================================
--- sling/trunk/testing/samples/bundle-with-it/src/main/java/org/apache/sling/testing/samples/bundlewit/api/package-info.java (added)
+++ sling/trunk/testing/samples/bundle-with-it/src/main/java/org/apache/sling/testing/samples/bundlewit/api/package-info.java Tue Dec 8 10:59:49 2015
@@ -0,0 +1,24 @@
+/*
+ * 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.
+ */
+
+@Version("1.0.0")
+package org.apache.sling.testing.samples.bundlewit.api;
+
+import aQute.bnd.annotation.Version;
+
Added: sling/trunk/testing/samples/bundle-with-it/src/main/java/org/apache/sling/testing/samples/bundlewit/impl/MimeTypeServlet.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/samples/bundle-with-it/src/main/java/org/apache/sling/testing/samples/bundlewit/impl/MimeTypeServlet.java?rev=1718557&view=auto
==============================================================================
--- sling/trunk/testing/samples/bundle-with-it/src/main/java/org/apache/sling/testing/samples/bundlewit/impl/MimeTypeServlet.java (added)
+++ sling/trunk/testing/samples/bundle-with-it/src/main/java/org/apache/sling/testing/samples/bundlewit/impl/MimeTypeServlet.java Tue Dec 8 10:59:49 2015
@@ -0,0 +1,55 @@
+/*
+ * 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.testing.samples.bundlewit.impl;
+
+import java.io.IOException;
+
+import javax.servlet.ServletException;
+
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.sling.SlingServlet;
+import org.apache.sling.api.SlingHttpServletRequest;
+import org.apache.sling.api.SlingHttpServletResponse;
+import org.apache.sling.api.servlets.SlingSafeMethodsServlet;
+import org.apache.sling.testing.samples.bundlewit.api.ResourceMimeTypeDetector;
+
+/** Servlet that uses the ResourceMimeTypeDetector to output
+ * the mime-type of the current Resource.
+ */
+@SlingServlet(
+ resourceTypes="sling/servlet/default",
+ selectors="mimetype",
+ extensions="txt",
+ methods="GET")
+public class MimeTypeServlet extends SlingSafeMethodsServlet {
+ private static final long serialVersionUID = 7373752152329079226L;
+
+ public static final String PREFIX = MimeTypeServlet.class.getSimpleName() + " mime-type is ";
+
+ @Reference
+ ResourceMimeTypeDetector detector;
+
+ @Override
+ protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response)
+ throws ServletException, IOException {
+ response.setContentType("text/plain");
+ response.setCharacterEncoding("UTF-8");
+ final String mimeType = detector.getMimeType(request.getResource());
+ response.getWriter().write(PREFIX);
+ response.getWriter().write(String.valueOf(mimeType));
+ }
+}
\ No newline at end of file
Added: sling/trunk/testing/samples/bundle-with-it/src/main/java/org/apache/sling/testing/samples/bundlewit/impl/ResourceMimeTypeDetectorImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/samples/bundle-with-it/src/main/java/org/apache/sling/testing/samples/bundlewit/impl/ResourceMimeTypeDetectorImpl.java?rev=1718557&view=auto
==============================================================================
--- sling/trunk/testing/samples/bundle-with-it/src/main/java/org/apache/sling/testing/samples/bundlewit/impl/ResourceMimeTypeDetectorImpl.java (added)
+++ sling/trunk/testing/samples/bundle-with-it/src/main/java/org/apache/sling/testing/samples/bundlewit/impl/ResourceMimeTypeDetectorImpl.java Tue Dec 8 10:59:49 2015
@@ -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.testing.samples.bundlewit.impl;
+
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.Service;
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.commons.mime.MimeTypeService;
+import org.apache.sling.testing.samples.bundlewit.api.ResourceMimeTypeDetector;
+
+/** ResourceMimeTypeDetector that uses the Sling
+ * MimeTypeService.
+ */
+@Component
+@Service(value=ResourceMimeTypeDetector.class)
+public class ResourceMimeTypeDetectorImpl implements ResourceMimeTypeDetector {
+
+ @Reference
+ MimeTypeService mimeTypeService;
+
+ public String getMimeType(Resource r) {
+ return mimeTypeService.getMimeType(r.getPath());
+ }
+}
\ No newline at end of file
Modified: sling/trunk/testing/samples/bundle-with-it/src/test/java/org/apache/sling/junit/teleporter/customizers/BWIT_TeleporterCustomizer.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/samples/bundle-with-it/src/test/java/org/apache/sling/junit/teleporter/customizers/BWIT_TeleporterCustomizer.java?rev=1718557&r1=1718556&r2=1718557&view=diff
==============================================================================
--- sling/trunk/testing/samples/bundle-with-it/src/test/java/org/apache/sling/junit/teleporter/customizers/BWIT_TeleporterCustomizer.java (original)
+++ sling/trunk/testing/samples/bundle-with-it/src/test/java/org/apache/sling/junit/teleporter/customizers/BWIT_TeleporterCustomizer.java Tue Dec 8 10:59:49 2015
@@ -21,6 +21,8 @@ import org.apache.sling.testing.teleport
import org.apache.sling.testing.tools.sling.SlingTestBase;
import org.apache.sling.testing.tools.sling.TimeoutsProvider;
+import aQute.bnd.osgi.Constants;
+
/** This is required by the TeleporterRule, to setup the client-side
* teleporter with (at least) the test server URL.
*/
@@ -34,5 +36,11 @@ public class BWIT_TeleporterCustomizer i
cst.setBaseUrl(S.getServerBaseUrl());
cst.setServerCredentials(S.getServerUsername(), S.getServerPassword());
cst.setTestReadyTimeoutSeconds(TimeoutsProvider.getInstance().getTimeout(5));
+
+ // Make sure our bundle API is imported instead of embedded
+ final String apiPackage = "org.apache.sling.testing.samples.bundlewit.api";
+ cst.includeDependencyPrefix("org.apache.sling.testing.samples.bundlewit");
+ cst.excludeDependencyPrefix(apiPackage);
+ cst.getAdditionalBundleHeaders().put(Constants.IMPORT_PACKAGE, apiPackage);
}
}
\ No newline at end of file
Modified: sling/trunk/testing/samples/bundle-with-it/src/test/java/org/apache/sling/testing/samples/bundlewit/BasicTeleportedIT.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/samples/bundle-with-it/src/test/java/org/apache/sling/testing/samples/bundlewit/BasicTeleportedIT.java?rev=1718557&r1=1718556&r2=1718557&view=diff
==============================================================================
--- sling/trunk/testing/samples/bundle-with-it/src/test/java/org/apache/sling/testing/samples/bundlewit/BasicTeleportedIT.java (original)
+++ sling/trunk/testing/samples/bundle-with-it/src/test/java/org/apache/sling/testing/samples/bundlewit/BasicTeleportedIT.java Tue Dec 8 10:59:49 2015
@@ -29,6 +29,8 @@ import org.osgi.service.cm.Configuration
/** Basic teleported server-side test, demonstrates how
* these work.
+ * This is a general Sling test, it does not test anything
+ * from this bundle.
*/
public class BasicTeleportedIT {
@Rule
Added: sling/trunk/testing/samples/bundle-with-it/src/test/java/org/apache/sling/testing/samples/bundlewit/MimeTypeServletHttpIT.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/samples/bundle-with-it/src/test/java/org/apache/sling/testing/samples/bundlewit/MimeTypeServletHttpIT.java?rev=1718557&view=auto
==============================================================================
--- sling/trunk/testing/samples/bundle-with-it/src/test/java/org/apache/sling/testing/samples/bundlewit/MimeTypeServletHttpIT.java (added)
+++ sling/trunk/testing/samples/bundle-with-it/src/test/java/org/apache/sling/testing/samples/bundlewit/MimeTypeServletHttpIT.java Tue Dec 8 10:59:49 2015
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.testing.samples.bundlewit;
+
+import org.apache.sling.testing.samples.bundlewit.impl.MimeTypeServlet;
+import org.apache.sling.testing.tools.sling.SlingTestBase;
+import org.junit.Test;
+
+/** HTTP test of the MimeTypeServlet provided
+ * by this bundle.
+ */
+public class MimeTypeServletHttpIT {
+
+ private static final SlingTestBase S = new SlingTestBase();
+
+ private void assertMimeType(String path, String expected) throws Exception {
+ S.getRequestExecutor().execute(
+ S.getRequestBuilder().buildGetRequest(path + ".mimetype.txt")
+ .withCredentials(S.getServerUsername(), S.getServerPassword())
+ )
+ .assertStatus(200)
+ .assertContentContains(expected);
+ }
+
+ @Test
+ public void htmlResource() throws Exception {
+ assertMimeType("/index.html", MimeTypeServlet.PREFIX + "text/html");
+ }
+
+ @Test
+ public void noMimeTypeResource() throws Exception {
+ assertMimeType("/tmp", MimeTypeServlet.PREFIX + "text/plain");
+ }
+}
\ No newline at end of file
Added: sling/trunk/testing/samples/bundle-with-it/src/test/java/org/apache/sling/testing/samples/bundlewit/MockResource.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/samples/bundle-with-it/src/test/java/org/apache/sling/testing/samples/bundlewit/MockResource.java?rev=1718557&view=auto
==============================================================================
--- sling/trunk/testing/samples/bundle-with-it/src/test/java/org/apache/sling/testing/samples/bundlewit/MockResource.java (added)
+++ sling/trunk/testing/samples/bundle-with-it/src/test/java/org/apache/sling/testing/samples/bundlewit/MockResource.java Tue Dec 8 10:59:49 2015
@@ -0,0 +1,93 @@
+/*
+ * 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.testing.samples.bundlewit;
+
+import java.util.Iterator;
+
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.resource.ResourceMetadata;
+import org.apache.sling.api.resource.ResourceResolver;
+
+/** TODO use a mock library - requires making it available server-side. */
+class MockResource implements Resource {
+
+ private final String path;
+
+ MockResource(String path) {
+ this.path = path;
+ }
+
+ @Override
+ public <AdapterType> AdapterType adaptTo(Class<AdapterType> type) {
+ return null;
+ }
+
+ @Override
+ public String getPath() {
+ return path;
+ }
+
+ @Override
+ public String getName() {
+ return null;
+ }
+
+ @Override
+ public Resource getParent() {
+ return null;
+ }
+
+ @Override
+ public Iterator<Resource> listChildren() {
+ return null;
+ }
+
+ @Override
+ public Iterable<Resource> getChildren() {
+ return null;
+ }
+
+ @Override
+ public Resource getChild(String relPath) {
+ return null;
+ }
+
+ @Override
+ public String getResourceType() {
+ return null;
+ }
+
+ @Override
+ public String getResourceSuperType() {
+ return null;
+ }
+
+ @Override
+ public boolean isResourceType(String resourceType) {
+ return false;
+ }
+
+ @Override
+ public ResourceMetadata getResourceMetadata() {
+ return null;
+ }
+
+ @Override
+ public ResourceResolver getResourceResolver() {
+ return null;
+ }
+}
\ No newline at end of file
Modified: sling/trunk/testing/samples/bundle-with-it/src/test/java/org/apache/sling/testing/samples/bundlewit/OsgiConsoleHttpIT.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/samples/bundle-with-it/src/test/java/org/apache/sling/testing/samples/bundlewit/OsgiConsoleHttpIT.java?rev=1718557&r1=1718556&r2=1718557&view=diff
==============================================================================
--- sling/trunk/testing/samples/bundle-with-it/src/test/java/org/apache/sling/testing/samples/bundlewit/OsgiConsoleHttpIT.java (original)
+++ sling/trunk/testing/samples/bundle-with-it/src/test/java/org/apache/sling/testing/samples/bundlewit/OsgiConsoleHttpIT.java Tue Dec 8 10:59:49 2015
@@ -21,7 +21,10 @@ import org.junit.Test;
/** Simple HTTP test example, checks the validity of some
* OSGi webconsole URLs by GETting them and checking
- * status code 200.
+ * status code 200.
+ *
+ * This is a general Sling test, it does not test anything
+ * from this bundle.
*/
public class OsgiConsoleHttpIT {
Added: sling/trunk/testing/samples/bundle-with-it/src/test/java/org/apache/sling/testing/samples/bundlewit/ResourceMimeTypeDetectorIT.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/samples/bundle-with-it/src/test/java/org/apache/sling/testing/samples/bundlewit/ResourceMimeTypeDetectorIT.java?rev=1718557&view=auto
==============================================================================
--- sling/trunk/testing/samples/bundle-with-it/src/test/java/org/apache/sling/testing/samples/bundlewit/ResourceMimeTypeDetectorIT.java (added)
+++ sling/trunk/testing/samples/bundle-with-it/src/test/java/org/apache/sling/testing/samples/bundlewit/ResourceMimeTypeDetectorIT.java Tue Dec 8 10:59:49 2015
@@ -0,0 +1,52 @@
+/*
+ * 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.testing.samples.bundlewit;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.IOException;
+
+import org.apache.sling.junit.rules.TeleporterRule;
+import org.apache.sling.testing.samples.bundlewit.api.ResourceMimeTypeDetector;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+/** Server-side test of the ResourceMimeTypeDetector
+ * provided by this bundle */
+public class ResourceMimeTypeDetectorIT {
+
+ private ResourceMimeTypeDetector detector;
+
+ @Rule
+ public final TeleporterRule teleporter = TeleporterRule.forClass(getClass(), "BWIT_Teleporter");
+
+ @Before
+ public void setup() {
+ detector = teleporter.getService(ResourceMimeTypeDetector.class);
+ }
+
+ @Test
+ public void textHtml() throws IOException {
+ assertEquals("text/html", detector.getMimeType(new MockResource("/someResource.html")));
+ }
+
+ @Test
+ public void nullMimeType() throws IOException {
+ assertEquals(null, detector.getMimeType(new MockResource("/someResourceWithNoExtension")));
+ }
+}
\ No newline at end of file
Added: sling/trunk/testing/samples/bundle-with-it/src/test/java/org/apache/sling/testing/samples/bundlewit/SampleUnitTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/samples/bundle-with-it/src/test/java/org/apache/sling/testing/samples/bundlewit/SampleUnitTest.java?rev=1718557&view=auto
==============================================================================
--- sling/trunk/testing/samples/bundle-with-it/src/test/java/org/apache/sling/testing/samples/bundlewit/SampleUnitTest.java (added)
+++ sling/trunk/testing/samples/bundle-with-it/src/test/java/org/apache/sling/testing/samples/bundlewit/SampleUnitTest.java Tue Dec 8 10:59:49 2015
@@ -0,0 +1,32 @@
+/*
+ * 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.testing.samples.bundlewit;
+
+import static org.junit.Assert.assertNotNull;
+
+import org.apache.sling.testing.samples.bundlewit.impl.ResourceMimeTypeDetectorImpl;
+import org.junit.Test;
+
+/** Unit tests can coexist with integration tests, even in
+ * the same package if that makes sense.
+ */
+public class SampleUnitTest {
+ @Test
+ public void testNotMuch() {
+ assertNotNull(new ResourceMimeTypeDetectorImpl());
+ }
+}
\ No newline at end of file