Author: catholicon
Date: Wed Aug 7 18:58:22 2019
New Revision: 1864667
URL: http://svn.apache.org/viewvc?rev=1864667&view=rev
Log:
OAK-8532: Osgi based test to verify tika setup is working
Useful versions are referred from versions.properties resource.
Some bundles are hard-coded to their version in the test itself as they seem
to be only useful for poi and any OSGi setup that would use poi would
anyway need to wrap poi into a bundle and hence would most likely inline
these hard-coded ones as well (where OSGi resolution would help catch
errors in those cases).
Added:
jackrabbit/oak/trunk/oak-it-osgi/src/test/java/org/apache/jackrabbit/oak/osgi/TikaExtractionOsgiIT.java
(with props)
jackrabbit/oak/trunk/oak-it-osgi/src/test/resources/org/
jackrabbit/oak/trunk/oak-it-osgi/src/test/resources/org/apache/
jackrabbit/oak/trunk/oak-it-osgi/src/test/resources/org/apache/jackrabbit/
jackrabbit/oak/trunk/oak-it-osgi/src/test/resources/org/apache/jackrabbit/oak/
jackrabbit/oak/trunk/oak-it-osgi/src/test/resources/org/apache/jackrabbit/oak/osgi/
jackrabbit/oak/trunk/oak-it-osgi/src/test/resources/org/apache/jackrabbit/oak/osgi/test.doc
(with props)
jackrabbit/oak/trunk/oak-it-osgi/src/test/resources/org/apache/jackrabbit/oak/osgi/test.docx
jackrabbit/oak/trunk/oak-it-osgi/src/test/resources/org/apache/jackrabbit/oak/osgi/test.rtf
jackrabbit/oak/trunk/oak-it-osgi/src/test/resources/org/apache/jackrabbit/oak/osgi/test.txt
(with props)
jackrabbit/oak/trunk/oak-it-osgi/src/test/resources/versions.properties
(with props)
Modified:
jackrabbit/oak/trunk/oak-it-osgi/pom.xml
Modified: jackrabbit/oak/trunk/oak-it-osgi/pom.xml
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-it-osgi/pom.xml?rev=1864667&r1=1864666&r2=1864667&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-it-osgi/pom.xml (original)
+++ jackrabbit/oak/trunk/oak-it-osgi/pom.xml Wed Aug 7 18:58:22 2019
@@ -65,7 +65,35 @@
</systemPropertyVariables>
</configuration>
</plugin>
+ <!-- Inspired from
+
https://stackoverflow.com/questions/26281322/mavenfailed-to-execute-goal-org-apache-maven-pluginsmaven-resources-plugin2-7
+ -->
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-resources-plugin</artifactId>
+ <configuration>
+ <nonFilteredFileExtensions>
+ <nonFilteredFileExtension>txt</nonFilteredFileExtension>
+ <nonFilteredFileExtension>rtf</nonFilteredFileExtension>
+ <nonFilteredFileExtension>doc</nonFilteredFileExtension>
+ <nonFilteredFileExtension>docx</nonFilteredFileExtension>
+ </nonFilteredFileExtensions>
+ </configuration>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven.shared</groupId>
+ <artifactId>maven-filtering</artifactId>
+ <version>1.3</version>
+ </dependency>
+ </dependencies>
+ </plugin>
</plugins>
+ <testResources>
+ <testResource>
+ <directory>src/test/resources</directory>
+ <filtering>true</filtering>
+ </testResource>
+ </testResources>
</build>
<dependencies>
@@ -179,6 +207,12 @@
<scope>test</scope>
</dependency>
<dependency>
+ <groupId>org.ops4j.pax.url</groupId>
+ <artifactId>pax-url-wrap</artifactId>
+ <version>2.6.1</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<scope>test</scope>
Added:
jackrabbit/oak/trunk/oak-it-osgi/src/test/java/org/apache/jackrabbit/oak/osgi/TikaExtractionOsgiIT.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-it-osgi/src/test/java/org/apache/jackrabbit/oak/osgi/TikaExtractionOsgiIT.java?rev=1864667&view=auto
==============================================================================
---
jackrabbit/oak/trunk/oak-it-osgi/src/test/java/org/apache/jackrabbit/oak/osgi/TikaExtractionOsgiIT.java
(added)
+++
jackrabbit/oak/trunk/oak-it-osgi/src/test/java/org/apache/jackrabbit/oak/osgi/TikaExtractionOsgiIT.java
Wed Aug 7 18:58:22 2019
@@ -0,0 +1,219 @@
+/*
+ * 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.jackrabbit.oak.osgi;
+
+import com.google.common.collect.Maps;
+import org.apache.tika.metadata.Metadata;
+import org.apache.tika.parser.AutoDetectParser;
+import org.apache.tika.parser.Parser;
+import org.apache.tika.sax.WriteOutContentHandler;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.Configuration;
+import org.ops4j.pax.exam.CoreOptions;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.PaxExam;
+import org.ops4j.pax.exam.options.DefaultCompositeOption;
+import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
+import org.ops4j.pax.exam.spi.reactors.PerClass;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Version;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.xml.sax.ContentHandler;
+
+import javax.inject.Inject;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.stream.Collectors;
+
+import static java.util.Arrays.stream;
+import static org.junit.Assert.*;
+import static org.ops4j.pax.exam.CoreOptions.*;
+
+@RunWith(PaxExam.class)
+@ExamReactorStrategy(PerClass.class)
+public class TikaExtractionOsgiIT {
+ private static final Logger LOG =
LoggerFactory.getLogger(TikaExtractionOsgiIT.class);
+
+ private static final String VERSION_PROP_RESOURCE_NAME =
"versions.properties";
+ private static final String TIKA_VERSION = "tika";
+ private static final String POI_VERSION = "poi";
+ private static final String COLLECTIONS4_VERSION = "commons-collections4";
+ private static final String COMPRESS_VERSION = "commons-compress";
+ private static final String LANG3_VERSION = "commons-lang3";
+ private static final String MATH3_VERSION = "commons-math3";
+ private static final String[] VERSION_KEYS = new String[]{TIKA_VERSION,
POI_VERSION
+ , COLLECTIONS4_VERSION, COMPRESS_VERSION
+ , LANG3_VERSION, MATH3_VERSION};
+
+ private static final String EXPECTED_TEXT_FRAGMENT = "A sample document";
+
+ @Configuration
+ public Option[] configuration() throws IOException {
+ return CoreOptions.options(
+ junitBundles(),
+ mavenBundle( "org.ops4j.pax.logging", "pax-logging-api",
"1.7.2" ),
+ frameworkProperty("repository.home").value("target"),
+ setupTikaAndPoi(),
+ jpmsOptions()
+ // to debug a test, un-comment this and "run" the test which
would block due to suspend="y"
+ // then run debugger on a remote app with specified port
+// , vmOption(
"-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005" )
+ );
+ }
+
+ private Option jpmsOptions(){
+ DefaultCompositeOption composite = new DefaultCompositeOption();
+ if
(Version.parseVersion(System.getProperty("java.specification.version")).getMajor()
> 1){
+ if
(java.nio.file.Files.exists(java.nio.file.FileSystems.getFileSystem(URI.create("jrt:/")).getPath("modules",
"java.se.ee"))){
+ composite.add(vmOption("--add-modules=java.se.ee"));
+ }
+
composite.add(vmOption("--add-opens=java.base/jdk.internal.loader=ALL-UNNAMED"));
+
composite.add(vmOption("--add-opens=java.base/java.lang=ALL-UNNAMED"));
+
composite.add(vmOption("--add-opens=java.base/java.lang.invoke=ALL-UNNAMED"));
+
composite.add(vmOption("--add-opens=java.base/java.io=ALL-UNNAMED"));
+
composite.add(vmOption("--add-opens=java.base/java.net=ALL-UNNAMED"));
+
composite.add(vmOption("--add-opens=java.base/java.nio=ALL-UNNAMED"));
+
composite.add(vmOption("--add-opens=java.base/java.util=ALL-UNNAMED"));
+
composite.add(vmOption("--add-opens=java.base/java.util.jar=ALL-UNNAMED"));
+
composite.add(vmOption("--add-opens=java.base/java.util.regex=ALL-UNNAMED"));
+
composite.add(vmOption("--add-opens=java.base/java.util.zip=ALL-UNNAMED"));
+
composite.add(vmOption("--add-opens=java.base/sun.nio.ch=ALL-UNNAMED"));
+ }
+ return composite;
+ }
+
+ private Option setupTikaAndPoi() throws IOException {
+ Map<String, String> versions = setupVersions();
+ return composite(
+ composite(
+ mavenBundle("org.apache.tika", "tika-core",
versions.get(TIKA_VERSION))
+ , mavenBundle("org.apache.tika", "tika-parsers",
versions.get(TIKA_VERSION))
+
+ // poi dependency start
+ , wrappedBundle(mavenBundle("org.apache.poi", "poi",
versions.get(POI_VERSION)))
+ , wrappedBundle(mavenBundle("org.apache.poi",
"poi-scratchpad", versions.get(POI_VERSION)))
+ , wrappedBundle(mavenBundle("org.apache.poi",
"poi-ooxml", versions.get(POI_VERSION)))
+ , wrappedBundle(mavenBundle("org.apache.poi",
"poi-ooxml-schemas", versions.get(POI_VERSION)))
+ .instructions("DynamicImport-Package=*")
+ , wrappedBundle(mavenBundle("org.apache.poi",
"ooxml-security", "1.0"))
+ , wrappedBundle(mavenBundle("org.apache.xmlbeans",
"xmlbeans", "3.1.0"))
+ , wrappedBundle(mavenBundle("com.drewnoakes",
"metadata-extractor", "2.6.2"))
+ , mavenBundle("org.apache.commons",
"commons-collections4", versions.get(COLLECTIONS4_VERSION))
+ , mavenBundle("org.apache.commons",
"commons-compress", versions.get(COMPRESS_VERSION))
+ , mavenBundle("org.apache.commons", "commons-lang3",
versions.get(LANG3_VERSION))
+ , mavenBundle("org.apache.commons", "commons-math3",
versions.get(MATH3_VERSION))
+ // poi dependency end
+ )
+ , jarBundles()
+ );
+ }
+
+ private Option jarBundles() throws MalformedURLException {
+ String[] jarNames = new String[]{"commons-io.jar",
"commons-codec.jar"};
+ File jarDir = new File("target", "test-bundles");
+
+ DefaultCompositeOption composite = new DefaultCompositeOption();
+
+ List<File> jarFiles = stream(jarNames).map(jarName -> new File(jarDir,
jarName)).collect(Collectors.toList());
+ for (File jar : jarFiles) {
+ composite.add(bundle(jar.toURI().toURL().toString()));
+ }
+
+ return composite;
+ }
+
+ private static Map<String, String> setupVersions() throws IOException {
+ Properties props = new Properties();
+
props.load(TikaExtractionOsgiIT.class.getClassLoader().getResourceAsStream(VERSION_PROP_RESOURCE_NAME));
+
+ assertEquals("Unexpected number of properties found in " +
VERSION_PROP_RESOURCE_NAME,
+ VERSION_KEYS.length, props.size());
+
+ Map<String, String> versions = Maps.newHashMap();
+ for (String versionKey : VERSION_KEYS) {
+ String version = props.getProperty(versionKey);
+
+ assertNotNull("Version value not found for " + versionKey,
version);
+ assertFalse("Version (key: " + versionKey + ", value: " + version
+ ") didn't get filtered by maven",
+ version.contains("{"));
+
+ versions.put(versionKey, version);
+ }
+
+ return versions;
+ }
+
+ @Inject
+ private BundleContext context;
+
+ @Inject
+ private Parser registeredParser;
+
+ @Test
+ public void listBundles() {
+ for (Bundle bundle : context.getBundles()) {
+ LOG.info("Bundle listing :: {} - {}", bundle, bundle.getVersion());
+ }
+ }
+
+ @Test
+ public void doc() throws Exception {
+ assertFileContains("test.doc");
+ }
+
+ @Test
+ public void docx() throws Exception {
+ assertFileContains("test.docx");
+ }
+
+ @Test
+ public void rtf() throws Exception {
+ assertFileContains("test.rtf");
+ }
+
+ @Test
+ public void text() throws Exception {
+ assertFileContains("test.txt");
+ }
+
+ private void assertFileContains(String resName) throws Exception {
+ AutoDetectParser parser = new AutoDetectParser(registeredParser);
+ ContentHandler handler = new WriteOutContentHandler();
+ Metadata metadata = new Metadata();
+
+ InputStream stream = getClass().getResourceAsStream(resName);
+ assertNotNull("Input stream must not be null", stream);
+ try {
+ parser.parse(stream, handler, metadata);
+
+ String actual = handler.toString().trim();
+ assertEquals(EXPECTED_TEXT_FRAGMENT, actual);
+ } finally {
+ stream.close();
+ }
+
+ }
+}
Propchange:
jackrabbit/oak/trunk/oak-it-osgi/src/test/java/org/apache/jackrabbit/oak/osgi/TikaExtractionOsgiIT.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
jackrabbit/oak/trunk/oak-it-osgi/src/test/resources/org/apache/jackrabbit/oak/osgi/test.doc
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-it-osgi/src/test/resources/org/apache/jackrabbit/oak/osgi/test.doc?rev=1864667&view=auto
==============================================================================
Binary file - no diff available.
Propchange:
jackrabbit/oak/trunk/oak-it-osgi/src/test/resources/org/apache/jackrabbit/oak/osgi/test.doc
------------------------------------------------------------------------------
svn:mime-type = application/msword
Added:
jackrabbit/oak/trunk/oak-it-osgi/src/test/resources/org/apache/jackrabbit/oak/osgi/test.docx
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-it-osgi/src/test/resources/org/apache/jackrabbit/oak/osgi/test.docx?rev=1864667&view=auto
==============================================================================
Binary files
jackrabbit/oak/trunk/oak-it-osgi/src/test/resources/org/apache/jackrabbit/oak/osgi/test.docx
(added) and
jackrabbit/oak/trunk/oak-it-osgi/src/test/resources/org/apache/jackrabbit/oak/osgi/test.docx
Wed Aug 7 18:58:22 2019 differ
Added:
jackrabbit/oak/trunk/oak-it-osgi/src/test/resources/org/apache/jackrabbit/oak/osgi/test.rtf
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-it-osgi/src/test/resources/org/apache/jackrabbit/oak/osgi/test.rtf?rev=1864667&view=auto
==============================================================================
---
jackrabbit/oak/trunk/oak-it-osgi/src/test/resources/org/apache/jackrabbit/oak/osgi/test.rtf
(added)
+++
jackrabbit/oak/trunk/oak-it-osgi/src/test/resources/org/apache/jackrabbit/oak/osgi/test.rtf
Wed Aug 7 18:58:22 2019
@@ -0,0 +1,19 @@
+{\rtf1\ansi\deff3\adeflang1025
+{\fonttbl{\f0\froman\fprq2\fcharset0 Times New
Roman;}{\f1\froman\fprq2\fcharset2 Symbol;}{\f2\fswiss\fprq2\fcharset0
Arial;}{\f3\froman\fprq2\fcharset0 Liberation Serif{\*\falt Times New
Roman};}{\f4\fswiss\fprq2\fcharset0 Liberation Sans{\*\falt
Arial};}{\f5\froman\fprq2\fcharset0 Calibri;}{\f6\fnil\fprq2\fcharset0 Noto
Sans CJK SC Regular;}{\f7\fnil\fprq2\fcharset0
Calibri;}{\f8\fnil\fprq2\fcharset0 Lohit
Devanagari;}{\f9\fnil\fprq0\fcharset128 Lohit
Devanagari;}{\f10\fnil\fprq2\fcharset0 Times New Roman;}}
+{\colortbl;\red0\green0\blue0;\red0\green0\blue255;\red0\green255\blue255;\red0\green255\blue0;\red255\green0\blue255;\red255\green0\blue0;\red255\green255\blue0;\red255\green255\blue255;\red0\green0\blue128;\red0\green128\blue128;\red0\green128\blue0;\red128\green0\blue128;\red128\green0\blue0;\red128\green128\blue0;\red128\green128\blue128;\red192\green192\blue192;}
+{\stylesheet{\s0\snext0\sl276\slmult1\ql\widctlpar\faauto\sb0\sa200\ltrpar\hyphpar0\dbch\af7\langfe1033\dbch\af10\afs22\alang1025\cf0\kerning1\loch\f5\fs22\lang2055
Normal;}
+{\*\cs15\snext15 Default Paragraph Font;}
+{\s16\sbasedon0\snext17\sl276\slmult1\ql\widctlpar\faauto\sb240\sa120\keepn\ltrpar\dbch\af6\langfe1033\dbch\af8\afs28\alang1025\loch\f4\fs28\lang2055
Heading;}
+{\s17\sbasedon0\snext17\sl276\slmult1\ql\widctlpar\faauto\sb0\sa140\ltrpar\dbch\af7\langfe1033\dbch\af10\afs22\alang1025\loch\f5\fs22\lang2055
Text Body;}
+{\s18\sbasedon17\snext18\sl276\slmult1\ql\widctlpar\faauto\sb0\sa140\ltrpar\dbch\af7\langfe1033\dbch\af9\afs22\alang1025\loch\f5\fs22\lang2055
List;}
+{\s19\sbasedon0\snext19\sl276\slmult1\ql\widctlpar\faauto\sb120\sa120\noline\ltrpar\i\dbch\af7\langfe1033\dbch\af9\afs24\alang1025\ai\loch\f5\fs24\lang2055
Caption;}
+{\s20\sbasedon0\snext20\sl276\slmult1\ql\widctlpar\faauto\sb0\sa200\noline\ltrpar\dbch\af7\langfe1033\dbch\af9\afs22\alang1025\loch\f5\fs22\lang2055
Index;}
+{\s21\snext21\sl276\slmult1\ql\widctlpar\faauto\sb0\sa200\ltrpar\hyphpar0\dbch\af7\langfe1033\dbch\af10\afs22\alang1025\cf0\kerning1\loch\f5\fs22\lang2055
DocumentMap;}
+}{\*\generator LibreOffice/6.1.6.3$Linux_X86_64
LibreOffice_project/10$Build-3}{\info{\*\company Day Software AG}{\author
mreutegg}{\creatim\yr2008\mo10\dy23\hr10\min7}{\author Vikas
Saurabh}{\revtim\yr2019\mo8\dy7\hr11\min21}{\printim\yr0\mo0\dy0\hr0\min0}}{\*\userprops{\propname
Operator}\proptype30{\staticval mreutegg}}\deftab708\deftab708
+\viewscale140
+{\*\pgdsctbl
+{\pgdsc0\pgdscuse451\pgwsxn11906\pghsxn16838\marglsxn1417\margrsxn1417\margtsxn1417\margbsxn1134\pgdscnxt0
Default Style;}}
+\formshade{\*\pgdscno0}\paperh16838\paperw11906\margl1417\margr1417\margt1417\margb1134\sectd\sbknone\sectunlocked1\pgndec\pgwsxn11906\pghsxn16838\marglsxn1417\margrsxn1417\margtsxn1417\margbsxn1134\ftnbj\ftnstart1\ftnrstcont\ftnnar\aenddoc\aftnrstcont\aftnstart1\aftnnrlc\htmautsp
+{\*\ftnsep\chftnsep}\pgndec\pard\plain
\s0\sl276\slmult1\ql\widctlpar\faauto\sb0\sa200\ltrpar\hyphpar0\dbch\af7\langfe1033\dbch\af10\afs22\alang1025\cf0\kerning1\loch\f5\fs22\lang2055\sl276\slmult1\li0\ri0\lin0\rin0\fi0\sb0\sa200\ltrpar{\rtlch
\ltrch\loch\lang1033
+A sample document}
+\par }
\ No newline at end of file
Added:
jackrabbit/oak/trunk/oak-it-osgi/src/test/resources/org/apache/jackrabbit/oak/osgi/test.txt
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-it-osgi/src/test/resources/org/apache/jackrabbit/oak/osgi/test.txt?rev=1864667&view=auto
==============================================================================
---
jackrabbit/oak/trunk/oak-it-osgi/src/test/resources/org/apache/jackrabbit/oak/osgi/test.txt
(added)
+++
jackrabbit/oak/trunk/oak-it-osgi/src/test/resources/org/apache/jackrabbit/oak/osgi/test.txt
Wed Aug 7 18:58:22 2019
@@ -0,0 +1 @@
+A sample document
\ No newline at end of file
Propchange:
jackrabbit/oak/trunk/oak-it-osgi/src/test/resources/org/apache/jackrabbit/oak/osgi/test.txt
------------------------------------------------------------------------------
svn:eol-style = native
Added: jackrabbit/oak/trunk/oak-it-osgi/src/test/resources/versions.properties
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-it-osgi/src/test/resources/versions.properties?rev=1864667&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-it-osgi/src/test/resources/versions.properties
(added)
+++ jackrabbit/oak/trunk/oak-it-osgi/src/test/resources/versions.properties Wed
Aug 7 18:58:22 2019
@@ -0,0 +1,22 @@
+#
+# 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.
+#
+tika=${tika.version}
+poi=4.0.1
+commons-collections4=4.1
+commons-compress=1.18
+commons-lang3=3.9
+commons-math3=3.6.1
\ No newline at end of file
Propchange:
jackrabbit/oak/trunk/oak-it-osgi/src/test/resources/versions.properties
------------------------------------------------------------------------------
svn:eol-style = native