GitLab Mirror pushed to branch 2.16 at cms-community / hippo-jackrabbit

Commits:
9796c276 by Julian Reschke at 2018-02-02T15:02:07+00:00
CR-4240: IndexingQueueTest relies on Tika behavior that is changed in Tika 1.17 
(ported to 2.16)

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

git-svn-id: https://svn.apache.org/repos/asf/jackrabbit/branches/2.16@1822970 
13f79535-47bb-0310-9956-ffa450edef68

- - - - -


3 changed files:

- 
jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/lucene/BlockingParser.java
- 
jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/lucene/IndexingQueueTest.java
- + jackrabbit-core/src/test/resources/org/apache/tika/mime/custom-mimetypes.xml


Changes:

=====================================
jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/lucene/BlockingParser.java
=====================================
--- 
a/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/lucene/BlockingParser.java
+++ 
b/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/lucene/BlockingParser.java
@@ -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 EmptyParser {
             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);
+        }
     }
 
 }


=====================================
jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/lucene/IndexingQueueTest.java
=====================================
--- 
a/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/lucene/IndexingQueueTest.java
+++ 
b/jackrabbit-core/src/test/java/org/apache/jackrabbit/core/query/lucene/IndexingQueueTest.java
@@ -42,6 +42,8 @@ public class IndexingQueueTest extends AbstractIndexingTest {
     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 AbstractIndexingTest {
         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 AbstractIndexingTest 
{
             // 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++;


=====================================
jackrabbit-core/src/test/resources/org/apache/tika/mime/custom-mimetypes.xml
=====================================
--- /dev/null
+++ 
b/jackrabbit-core/src/test/resources/org/apache/tika/mime/custom-mimetypes.xml
@@ -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>



View it on GitLab: 
https://code.onehippo.org/cms-community/hippo-jackrabbit/commit/9796c2763fc88ec4b4e01a0b3baae318009f7eab

---
View it on GitLab: 
https://code.onehippo.org/cms-community/hippo-jackrabbit/commit/9796c2763fc88ec4b4e01a0b3baae318009f7eab
You're receiving this email because of your account on code.onehippo.org.
_______________________________________________
Hippocms-svn mailing list
Hippocms-svn@lists.onehippo.org
https://lists.onehippo.org/mailman/listinfo/hippocms-svn

Reply via email to