This is an automated email from the ASF dual-hosted git repository. rombert pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-commons-contentdetection.git
commit d76b4d7ec68df8307a477eef3d1cfb73e0377176 Author: Oliver Lietz <[email protected]> AuthorDate: Sat Mar 18 19:31:46 2017 +0000 switch to OSGi annotations and Testing PaxExam (fixes build) git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1787588 13f79535-47bb-0310-9956-ffa450edef68 --- pom.xml | 154 +++++++++------------ .../internal/ContentAwareMimeTypeServiceImpl.java | 17 ++- .../internal/FileNameExtractorImpl.java | 17 +-- .../ContentAwareMimeTypeServiceImplTest.java | 11 +- .../it/ContentAwareMimeTypeServiceImplIT.java | 24 ++-- .../internal/it/ContentdetectionTestSupport.java | 52 +++++++ .../internal/it/FileNameExtractorImplIT.java | 10 +- .../commons/contentdetection/internal/it/U.java | 42 ------ 8 files changed, 153 insertions(+), 174 deletions(-) diff --git a/pom.xml b/pom.xml index 2d14f3a..25299a3 100644 --- a/pom.xml +++ b/pom.xml @@ -36,15 +36,9 @@ <description>Content-based MIME type detection</description> <properties> - <exam.version>3.5.0</exam.version> - <url.version>1.5.2</url.version> - <bundle.file.name>${basedir}/target/${project.build.finalName}.jar</bundle.file.name> - <sling.launchpad.version>7</sling.launchpad.version> - <powermock.version>1.6.2</powermock.version> - <pax.vm.options>-Xmx256M -XX:MaxPermSize=256m</pax.vm.options> - - <!-- argLine needs to be here so that jacoco plugin adds its own stuff to it --> - <argLine>${pax.vm.options}</argLine> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> + <org.ops4j.pax.exam.version>4.10.0</org.ops4j.pax.exam.version> </properties> <scm> @@ -54,14 +48,24 @@ </scm> <dependencies> - - <!-- OSGi Dependencies--> + <!-- javax --> + <dependency> + <groupId>javax.inject</groupId> + <artifactId>javax.inject</artifactId> + <scope>test</scope> + </dependency> + <!-- OSGi --> <dependency> <groupId>org.osgi</groupId> <artifactId>osgi.core</artifactId> <scope>provided</scope> </dependency> <dependency> + <groupId>org.osgi</groupId> + <artifactId>osgi.cmpn</artifactId> + <scope>test</scope> + </dependency> + <dependency> <groupId>org.apache.felix</groupId> <artifactId>org.apache.felix.scr.annotations</artifactId> <scope>provided</scope> @@ -71,78 +75,74 @@ <artifactId>biz.aQute.bndlib</artifactId> <scope>provided</scope> </dependency> - <!-- Sling Dependencies--> + <!-- Apache Commons --> + <dependency> + <groupId>commons-io</groupId> + <artifactId>commons-io</artifactId> + <version>2.5</version> + <scope>test</scope> + </dependency> + <!-- Apache Sling --> <dependency> <version>2.1.8</version> <groupId>org.apache.sling</groupId> <artifactId>org.apache.sling.commons.mime</artifactId> <scope>provided</scope> </dependency> - - <!-- Other Dependencies--> + <dependency> + <groupId>org.apache.sling</groupId> + <artifactId>org.apache.sling.testing.paxexam</artifactId> + <version>0.0.5-SNAPSHOT</version> + <scope>test</scope> + </dependency> + <!-- Apache Tika--> <dependency> <version>1.2</version> <groupId>org.apache.tika</groupId> <artifactId>tika-core</artifactId> <scope>provided</scope> </dependency> - - <!-- Test Dependencies--> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - </dependency> + <!-- Apache Felix --> <dependency> - <groupId>org.apache.sling</groupId> - <artifactId>org.apache.sling.junit.core</artifactId> - <version>1.0.10</version> + <groupId>org.apache.felix</groupId> + <artifactId>org.apache.felix.framework</artifactId> + <version>5.6.2</version> <scope>test</scope> </dependency> + <!-- testing --> <dependency> - <groupId>junit-addons</groupId> - <artifactId>junit-addons</artifactId> - <version>1.4</version> + <groupId>junit</groupId> + <artifactId>junit</artifactId> <scope>test</scope> </dependency> <dependency> - <groupId>org.apache.sling</groupId> - <artifactId>org.apache.sling.launchpad</artifactId> - <version>${sling.launchpad.version}</version> - <type>xml</type> - <classifier>bundlelist</classifier> + <groupId>org.ops4j.pax.exam</groupId> + <artifactId>pax-exam</artifactId> + <version>${org.ops4j.pax.exam.version}</version> <scope>test</scope> </dependency> <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-api</artifactId> + <groupId>org.ops4j.pax.exam</groupId> + <artifactId>pax-exam-cm</artifactId> + <version>${org.ops4j.pax.exam.version}</version> <scope>test</scope> </dependency> <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-simple</artifactId> - </dependency> - <dependency> - <groupId>org.apache.sling</groupId> - <artifactId>org.apache.sling.paxexam.util</artifactId> - <version>1.0.2</version> + <groupId>org.ops4j.pax.exam</groupId> + <artifactId>pax-exam-container-forked</artifactId> + <version>${org.ops4j.pax.exam.version}</version> <scope>test</scope> </dependency> <dependency> <groupId>org.ops4j.pax.exam</groupId> - <artifactId>pax-exam-container-native</artifactId> - <version>${exam.version}</version> + <artifactId>pax-exam-junit4</artifactId> + <version>${org.ops4j.pax.exam.version}</version> <scope>test</scope> </dependency> <dependency> <groupId>org.ops4j.pax.exam</groupId> <artifactId>pax-exam-link-mvn</artifactId> - <version>${exam.version}</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.apache.felix</groupId> - <artifactId>org.apache.felix.framework</artifactId> - <version>5.6.0</version> + <version>${org.ops4j.pax.exam.version}</version> <scope>test</scope> </dependency> </dependencies> @@ -151,26 +151,9 @@ <plugins> <plugin> <groupId>org.apache.felix</groupId> - <artifactId>maven-scr-plugin</artifactId> - </plugin> - - <plugin> - <groupId>org.apache.felix</groupId> <artifactId>maven-bundle-plugin</artifactId> <extensions>true</extensions> </plugin> - - <plugin> - <groupId>org.apache.rat</groupId> - <artifactId>apache-rat-plugin</artifactId> - <configuration> - <excludes> - <exclude>derby.log</exclude> - <exclude>jackrabbit/**</exclude> - </excludes> - </configuration> - </plugin> - <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-failsafe-plugin</artifactId> @@ -183,32 +166,25 @@ </execution> </executions> <configuration> - <systemPropertyVariables> - <java.protocol.handler.pkgs>org.ops4j.pax.url</java.protocol.handler.pkgs> - <bundle.file.name>${bundle.file.name}</bundle.file.name> - <sling.launchpad.version>${sling.launchpad.version}</sling.launchpad.version> - </systemPropertyVariables> - <classpathDependencyExcludes> - <!-- The osgi.org dependencies cause trouble with pax exam --> - <classpathDependencyExcludes>org.osgi:org.osgi.core</classpathDependencyExcludes> - <classpathDependencyExcludes>org.osgi:org.osgi.compendium</classpathDependencyExcludes> - </classpathDependencyExcludes> + <redirectTestOutputToFile>true</redirectTestOutputToFile> + <systemProperties> + <property> + <name>bundle.filename</name> + <value>${basedir}/target/${project.build.finalName}.jar</value> + </property> + </systemProperties> </configuration> </plugin> <plugin> - <artifactId>maven-clean-plugin</artifactId> - <configuration> - <filesets> - <fileset> - <directory>${basedir}</directory> - <includes> - <include>oak/**</include> - <include>jackrabbit/**</include> - <include>derby.log</include> - </includes> - </fileset> - </filesets> - </configuration> + <groupId>org.apache.servicemix.tooling</groupId> + <artifactId>depends-maven-plugin</artifactId> + <executions> + <execution> + <goals> + <goal>generate-depends-file</goal> + </goals> + </execution> + </executions> </plugin> </plugins> </build> diff --git a/src/main/java/org/apache/sling/commons/contentdetection/internal/ContentAwareMimeTypeServiceImpl.java b/src/main/java/org/apache/sling/commons/contentdetection/internal/ContentAwareMimeTypeServiceImpl.java index 5264296..8641678 100644 --- a/src/main/java/org/apache/sling/commons/contentdetection/internal/ContentAwareMimeTypeServiceImpl.java +++ b/src/main/java/org/apache/sling/commons/contentdetection/internal/ContentAwareMimeTypeServiceImpl.java @@ -15,11 +15,8 @@ * limitations under the License. */ - package org.apache.sling.commons.contentdetection.internal; - -import org.apache.felix.scr.annotations.*; import org.apache.sling.commons.contentdetection.ContentAwareMimeTypeService; import org.apache.sling.commons.mime.MimeTypeService; import org.apache.tika.detect.Detector; @@ -27,16 +24,18 @@ import org.apache.tika.io.TikaInputStream; import org.apache.tika.metadata.Metadata; import org.apache.tika.mime.MediaType; import org.osgi.framework.Constants; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Reference; import java.io.IOException; import java.io.InputStream; -@Component -@Service(value = {ContentAwareMimeTypeService.class}) -@Properties({ - @Property(name = Constants.SERVICE_DESCRIPTION, value = "Apache Sling Content Aware MIME Type Service"), - @Property(name = Constants.SERVICE_VENDOR, value = "The Apache Software Foundation"), - @Property(name = "detection.mode", value = "tika") } +@Component( + property = { + Constants.SERVICE_DESCRIPTION + "=Apache Sling Content Aware MIME Type Service", + Constants.SERVICE_VENDOR + "=The Apache Software Foundation", + "detection.mode=tika" + } ) public class ContentAwareMimeTypeServiceImpl implements ContentAwareMimeTypeService { diff --git a/src/main/java/org/apache/sling/commons/contentdetection/internal/FileNameExtractorImpl.java b/src/main/java/org/apache/sling/commons/contentdetection/internal/FileNameExtractorImpl.java index 23d9c78..071bee3 100644 --- a/src/main/java/org/apache/sling/commons/contentdetection/internal/FileNameExtractorImpl.java +++ b/src/main/java/org/apache/sling/commons/contentdetection/internal/FileNameExtractorImpl.java @@ -19,19 +19,16 @@ package org.apache.sling.commons.contentdetection.internal; import java.io.UnsupportedEncodingException; import java.net.URLDecoder; -import org.apache.felix.scr.annotations.Component; -import org.apache.felix.scr.annotations.Properties; -import org.apache.felix.scr.annotations.Property; -import org.apache.felix.scr.annotations.Service; import org.apache.sling.commons.contentdetection.FileNameExtractor; import org.osgi.framework.Constants; +import org.osgi.service.component.annotations.Component; -@Component -@Service(FileNameExtractor.class) -@Properties({ - @Property(name = Constants.SERVICE_DESCRIPTION, value = "Apache Sling Filename Extractor Service"), - @Property(name = Constants.SERVICE_VENDOR, value = "The Apache Software Foundation"), -}) +@Component( + property = { + Constants.SERVICE_DESCRIPTION + "=Apache Sling Filename Extractor Service", + Constants.SERVICE_VENDOR + "=The Apache Software Foundation" + } +) public class FileNameExtractorImpl implements FileNameExtractor { public String extract(String name) { // If the name is a URL, skip the trailing query and fragment parts diff --git a/src/test/java/org/apache/sling/commons/contentdetection/internal/ContentAwareMimeTypeServiceImplTest.java b/src/test/java/org/apache/sling/commons/contentdetection/internal/ContentAwareMimeTypeServiceImplTest.java index b00194b..8672c33 100644 --- a/src/test/java/org/apache/sling/commons/contentdetection/internal/ContentAwareMimeTypeServiceImplTest.java +++ b/src/test/java/org/apache/sling/commons/contentdetection/internal/ContentAwareMimeTypeServiceImplTest.java @@ -20,8 +20,7 @@ package org.apache.sling.commons.contentdetection.internal; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; - -import junitx.util.PrivateAccessor; +import java.lang.reflect.Field; import org.apache.sling.commons.mime.MimeTypeService; import org.junit.Assert; @@ -58,9 +57,11 @@ public class ContentAwareMimeTypeServiceImplTest { }; @Before - public void setup() throws NoSuchFieldException { + public void setup() throws NoSuchFieldException, IllegalAccessException { contentAwareMimeTypeService = new ContentAwareMimeTypeServiceImpl(); - PrivateAccessor.setField(contentAwareMimeTypeService, "mimeTypeService", mimeTypeService); + final Field field = contentAwareMimeTypeService.getClass().getDeclaredField("mimeTypeService"); + field.setAccessible(true); + field.set(contentAwareMimeTypeService, mimeTypeService); } @Test @@ -101,4 +102,4 @@ public class ContentAwareMimeTypeServiceImplTest { } Assert.assertEquals("Expecting 1 call to registerMimeType(B)", before + 1, counterB); } -} \ No newline at end of file +} diff --git a/src/test/java/org/apache/sling/commons/contentdetection/internal/it/ContentAwareMimeTypeServiceImplIT.java b/src/test/java/org/apache/sling/commons/contentdetection/internal/it/ContentAwareMimeTypeServiceImplIT.java index 64269f5..81a74e2 100644 --- a/src/test/java/org/apache/sling/commons/contentdetection/internal/it/ContentAwareMimeTypeServiceImplIT.java +++ b/src/test/java/org/apache/sling/commons/contentdetection/internal/it/ContentAwareMimeTypeServiceImplIT.java @@ -32,14 +32,16 @@ import org.apache.commons.io.IOUtils; import org.apache.sling.commons.contentdetection.ContentAwareMimeTypeService; import org.junit.Test; import org.junit.runner.RunWith; -import org.ops4j.pax.exam.Option; import org.ops4j.pax.exam.junit.PaxExam; +import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy; +import org.ops4j.pax.exam.spi.reactors.PerClass; @RunWith(PaxExam.class) -public class ContentAwareMimeTypeServiceImplIT { +@ExamReactorStrategy(PerClass.class) +public class ContentAwareMimeTypeServiceImplIT extends ContentdetectionTestSupport { @Inject - private ContentAwareMimeTypeService contentAwaremimeTypeService; + private ContentAwareMimeTypeService contentAwareMimeTypeService; class NonMarkableStream extends BufferedInputStream { NonMarkableStream(InputStream is) { @@ -65,9 +67,9 @@ public class ContentAwareMimeTypeServiceImplIT { String mimeTypeName = "test.mp3"; String mimeType = "audio/mpeg"; assertEquals("Expecting mp3 type without InputStream parameter", - mimeType, contentAwaremimeTypeService.getMimeType(mimeTypeName)); + mimeType, contentAwareMimeTypeService.getMimeType(mimeTypeName)); assertEquals("Expecting mp3 type with null InputStream parameter", - mimeType, contentAwaremimeTypeService.getMimeType(mimeTypeName, null)); + mimeType, contentAwareMimeTypeService.getMimeType(mimeTypeName, null)); } @Test @@ -78,7 +80,7 @@ public class ContentAwareMimeTypeServiceImplIT { assertNotNull("Expecting stream to be found:" + filename, s); InputStream originalStream = null; try { - assertEquals("audio/x-wav", contentAwaremimeTypeService.getMimeType(filename, s)); + assertEquals("audio/x-wav", contentAwareMimeTypeService.getMimeType(filename, s)); originalStream = getClass().getResourceAsStream(path); assertNotNull("Expecting stream to be found:" + filename, originalStream); assertTrue("Expecting content to be unchanged", IOUtils.contentEquals(s, originalStream)); @@ -92,14 +94,10 @@ public class ContentAwareMimeTypeServiceImplIT { public void nonMarkableStreamDetectionShouldFail() throws IOException{ final InputStream nms = new NonMarkableStream(new ByteArrayInputStream("1234567890".getBytes())); try { - contentAwaremimeTypeService.getMimeType("foo.txt", nms); + contentAwareMimeTypeService.getMimeType("foo.txt", nms); } finally { IOUtils.closeQuietly(nms); } } - - @org.ops4j.pax.exam.Configuration - public Option[] config() { - return U.paxConfig(); - } -} \ No newline at end of file + +} diff --git a/src/test/java/org/apache/sling/commons/contentdetection/internal/it/ContentdetectionTestSupport.java b/src/test/java/org/apache/sling/commons/contentdetection/internal/it/ContentdetectionTestSupport.java new file mode 100644 index 0000000..cfb28a9 --- /dev/null +++ b/src/test/java/org/apache/sling/commons/contentdetection/internal/it/ContentdetectionTestSupport.java @@ -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.commons.contentdetection.internal.it; + +import org.apache.sling.testing.paxexam.TestSupport; +import org.ops4j.pax.exam.Configuration; +import org.ops4j.pax.exam.Option; + +import static org.apache.sling.testing.paxexam.SlingOptions.slingLaunchpadOakTar; +import static org.apache.sling.testing.paxexam.SlingOptions.versionResolver; +import static org.ops4j.pax.exam.CoreOptions.composite; +import static org.ops4j.pax.exam.CoreOptions.junitBundles; + +public abstract class ContentdetectionTestSupport extends TestSupport { + + @Configuration + public Option[] configuration() { + versionResolver.setVersion("org.apache.felix", "org.apache.felix.http.jetty", "3.1.6"); // Java 7 + versionResolver.setVersion("org.apache.felix", "org.apache.felix.http.whiteboard", "2.3.2"); // Java 7 + return new Option[]{ + baseConfiguration(), + launchpad(), + // Sling Content Detection + testBundle("bundle.filename"), + // testing + junitBundles() + }; + } + + protected Option launchpad() { + final int httpPort = findFreePort(); + final String workingDirectory = workingDirectory(); + return composite( + slingLaunchpadOakTar(workingDirectory, httpPort) + ); + } + +} diff --git a/src/test/java/org/apache/sling/commons/contentdetection/internal/it/FileNameExtractorImplIT.java b/src/test/java/org/apache/sling/commons/contentdetection/internal/it/FileNameExtractorImplIT.java index bc2aaaf..ccc3539 100644 --- a/src/test/java/org/apache/sling/commons/contentdetection/internal/it/FileNameExtractorImplIT.java +++ b/src/test/java/org/apache/sling/commons/contentdetection/internal/it/FileNameExtractorImplIT.java @@ -24,11 +24,13 @@ import javax.inject.Inject; import org.apache.sling.commons.contentdetection.FileNameExtractor; import org.junit.Test; import org.junit.runner.RunWith; -import org.ops4j.pax.exam.Option; import org.ops4j.pax.exam.junit.PaxExam; +import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy; +import org.ops4j.pax.exam.spi.reactors.PerClass; @RunWith(PaxExam.class) -public class FileNameExtractorImplIT { +@ExamReactorStrategy(PerClass.class) +public class FileNameExtractorImplIT extends ContentdetectionTestSupport{ @Inject private FileNameExtractor fileNameExtractor; @@ -40,8 +42,4 @@ public class FileNameExtractorImplIT { assertEquals(expectedFileName, fileNameExtractor.extract(rawPath)); } - @org.ops4j.pax.exam.Configuration - public Option[] config() { - return U.paxConfig(); - } } diff --git a/src/test/java/org/apache/sling/commons/contentdetection/internal/it/U.java b/src/test/java/org/apache/sling/commons/contentdetection/internal/it/U.java deleted file mode 100644 index d92cb46..0000000 --- a/src/test/java/org/apache/sling/commons/contentdetection/internal/it/U.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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.contentdetection.internal.it; - -import java.io.File; - -import org.apache.sling.paxexam.util.SlingPaxOptions; -import org.ops4j.pax.exam.CoreOptions; -import org.ops4j.pax.exam.Option; -import org.ops4j.pax.exam.options.DefaultCompositeOption; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class U { - private static final Logger log = LoggerFactory.getLogger(U.class); - - public static Option[] paxConfig() { - final File thisProjectsBundle = new File(System.getProperty( "bundle.file.name", "BUNDLE_FILE_NOT_SET" )); - final String launchpadVersion = System.getProperty("sling.launchpad.version", "LAUNCHPAD_VERSION_NOT_SET"); - log.info("Sling launchpad version: {}", launchpadVersion); - return new DefaultCompositeOption( - SlingPaxOptions.defaultLaunchpadOptions(launchpadVersion), - CoreOptions.provision(CoreOptions.bundle(thisProjectsBundle.toURI().toString())) - - ).getOptions(); - } -} -- To stop receiving notification emails like this one, please contact "[email protected]" <[email protected]>.
