You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by re...@apache.org on 2018/01/02 15:34:55 UTC

svn commit: r1819849 - in /jackrabbit/trunk/jackrabbit-core/src/test: java/org/apache/jackrabbit/core/query/lucene/ resources/org/apache/tika/ resources/org/apache/tika/mime/

Author: reschke
Date: Tue Jan  2 15:34:55 2018
New Revision: 1819849

URL: http://svn.apache.org/viewvc?rev=1819849&view=rev
Log:
JCR-4240: IndexingQueueTest relies on Tika behavior that is changed in Tika 1.17

Changed test to use an actual payload (and parse that), adding tika config to detect the custom type. (Thanks to tallison@apache.org for the proposed fix!)

Added:
    jackrabbit/trunk/jackrabbit-core/src/test/resources/org/apache/tika/
    jackrabbit/trunk/jackrabbit-core/src/test/resources/org/apache/tika/mime/
    jackrabbit/trunk/jackrabbit-core/src/test/resources/org/apache/tika/mime/custom-mimetypes.xml   (with props)
Modified:
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/lucene/BlockingParser.java
    jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/lucene/IndexingQueueTest.java

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/lucene/BlockingParser.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/lucene/BlockingParser.java?rev=1819849&r1=1819848&r2=1819849&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/lucene/BlockingParser.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/lucene/BlockingParser.java Tue Jan  2 15:34:55 2018
@@ -16,16 +16,22 @@
  */
 package org.apache.jackrabbit.core.query.lucene;
 
+import java.io.IOException;
 import java.io.InputStream;
 import java.util.Collections;
 import java.util.Set;
 
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
 import org.apache.tika.metadata.Metadata;
 import org.apache.tika.mime.MediaType;
 import org.apache.tika.parser.EmptyParser;
 import org.apache.tika.parser.ParseContext;
 import org.apache.tika.sax.XHTMLContentHandler;
+import org.w3c.dom.Document;
 import org.xml.sax.ContentHandler;
+import org.xml.sax.InputSource;
 import org.xml.sax.SAXException;
 
 public class BlockingParser extends EmptyParser {
@@ -76,10 +82,19 @@ public class BlockingParser extends Empt
             Metadata metadata, ParseContext context)
             throws SAXException {
         waitIfBlocked();
-        XHTMLContentHandler xhtml = new XHTMLContentHandler(handler, metadata);
-        xhtml.startDocument();
-        xhtml.element("p", "The quick brown fox jumped over the lazy dog.");
-        xhtml.endDocument();
+        try {
+            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+            Document doc = dbf.newDocumentBuilder().parse(new InputSource(stream));
+            String contents = doc.getDocumentElement().getTextContent();
+            XHTMLContentHandler xhtml = new XHTMLContentHandler(handler, metadata);
+            xhtml.startDocument();
+            xhtml.element("p", contents);
+            xhtml.endDocument();
+        } catch (ParserConfigurationException ex) {
+            throw new SAXException(ex);
+        } catch (IOException ex) {
+            throw new SAXException(ex);
+        }
     }
 
 }

Modified: jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/lucene/IndexingQueueTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/lucene/IndexingQueueTest.java?rev=1819849&r1=1819848&r2=1819849&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/lucene/IndexingQueueTest.java (original)
+++ jackrabbit/trunk/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/lucene/IndexingQueueTest.java Tue Jan  2 15:34:55 2018
@@ -42,6 +42,8 @@ public class IndexingQueueTest extends A
     private static final File TEMP_DIR =
         new File(System.getProperty("java.io.tmpdir"));
 
+    private static final String TESTCONTENT = "<?xml version='1.0'?>\n<blocked>The quick brown fox jumps over the lazy dog.</blocked>";
+    
     public void testQueue() throws Exception {
         SearchIndex index = getSearchIndex();
         IndexingQueue queue = index.getIndex().getIndexingQueue();
@@ -50,7 +52,7 @@ public class IndexingQueueTest extends A
         assertEquals(0, queue.getNumPendingDocuments());
 
         Node resource = testRootNode.addNode(nodeName1, "nt:resource");
-        resource.setProperty("jcr:data", "", PropertyType.BINARY);
+        resource.setProperty("jcr:data", TESTCONTENT, PropertyType.BINARY);
         resource.setProperty("jcr:lastModified", Calendar.getInstance());
         resource.setProperty("jcr:mimeType", BlockingParser.TYPE.toString());
         session.save();
@@ -169,7 +171,7 @@ public class IndexingQueueTest extends A
             // create files
             Node file = folder.addNode("file" + i, "nt:file");
             Node resource = file.addNode("jcr:content", "nt:resource");
-            resource.setProperty("jcr:data", "", PropertyType.BINARY);
+            resource.setProperty("jcr:data", TESTCONTENT, PropertyType.BINARY);
             resource.setProperty("jcr:lastModified", Calendar.getInstance());
             resource.setProperty("jcr:mimeType", BlockingParser.TYPE.toString());
             count++;

Added: jackrabbit/trunk/jackrabbit-core/src/test/resources/org/apache/tika/mime/custom-mimetypes.xml
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/test/resources/org/apache/tika/mime/custom-mimetypes.xml?rev=1819849&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/test/resources/org/apache/tika/mime/custom-mimetypes.xml (added)
+++ jackrabbit/trunk/jackrabbit-core/src/test/resources/org/apache/tika/mime/custom-mimetypes.xml Tue Jan  2 15:34:55 2018
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to You under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+-->
+
+<mime-info>
+    <!-- add this for detection to trigger the BlockingParser -->
+    <mime-type type="application/x-blocked">
+        <root-XML localName="blocked"/>
+        <sub-class-of type="application/xml"/>
+    </mime-type>
+</mime-info>

Propchange: jackrabbit/trunk/jackrabbit-core/src/test/resources/org/apache/tika/mime/custom-mimetypes.xml
------------------------------------------------------------------------------
    svn:eol-style = native